BEP-20
Source Code
Overview
Max Total Supply
43,226,646.844143LAXU
Holders
35,847
Market
Price
$0.00 @ 0.000000 BNB
Onchain Market Cap
-
Circulating Supply Market Cap
-
Other Info
Token Contract (WITH 18 Decimals)
Balance
8,180.9454711663709325 LAXUValue
$0.00Loading...
Loading
Loading...
Loading
Loading...
Loading
Contract Name:
Staking
Compiler Version
v0.8.20+commit.a1b79de6
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {UD60x18, ud} from "@prb/math/src/UD60x18.sol";
import {IUniswapV2Router02} from "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
import {IUniswapV2Pair} from "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";
import {ILAXToken} from "./interface/ILAXToken.sol";
import {ILAXOToken} from "./interface/ILAXOToken.sol";
import {IReferral} from "./interface/IReferral.sol";
import {IProject} from "./interface/IProject.sol";
import {Owned} from "solmate/src/auth/Owned.sol";
import {_USDT, _ROUTER} from "./Const.sol";
import {IStaking} from "./interface/IStaking.sol";
contract Staking is Owned, IStaking {
// ============ Constants ============
uint256 public constant MIN_STAKE_AMOUNT = 1 ether;
IUniswapV2Router02 constant ROUTER = IUniswapV2Router02(_ROUTER);
IERC20 constant USDT = IERC20(_USDT);
uint8 immutable maxD = 100;
// ============ State Variables ============
ILAXToken public LAX;
ILAXOToken public LAXO;
IReferral public REFERRAL;
IProject public PROJECT;
address public QUEUE;
address public lpAddress;
Config[3] public configs;
// ERC20-like properties for display
uint8 public constant decimals = 18;
string public constant name = "LAXU";
string public constant symbol = "LAXU";
uint256 public totalSupply;
mapping(address => uint256) public balances;
mapping(address => Record[]) public userStakeRecord;
mapping(address => uint256) public teamTotalInvestValue;
mapping(address => uint256) public teamVirtuallyInvestValue;
mapping(address => bool) public userOneDayStaked;
// ============ Modifiers ============
modifier onlyQueue() {
require(
msg.sender == QUEUE,
"only queue or owner"
);
_;
}
// ============ Constructor ============
constructor(
address referral_,
address project_,
address lpAddress_
) Owned(msg.sender) {
require(referral_ != address(0), "zero referral");
require(project_ != address(0), "zero project");
require(lpAddress_ != address(0), "zero lp address");
REFERRAL = IReferral(referral_);
PROJECT = IProject(project_);
lpAddress = lpAddress_;
USDT.approve(address(ROUTER), type(uint256).max);
configs[0] = Config(1000000034670200000, 1 days, 48 hours);
configs[1] = Config(1000000069236900000, 15 days, 48 hours);
configs[2] = Config(1000000138062200000, 30 days, 48 hours);
}
function marketingAddress() public view returns (address) {
return PROJECT.marketingAddress();
}
function dividendAddress() public view returns (address) {
return PROJECT.dividendWallet();
}
function ecosystemAddress() public view returns (address) {
return PROJECT.ecosystemAddress();
}
// ============ Admin Functions ============
function setLAX(address _lax) external onlyOwner {
LAX = ILAXToken(_lax);
LAX.approve(address(ROUTER), type(uint256).max);
}
function setLAXO(address _laxo) external onlyOwner {
LAXO = ILAXOToken(_laxo);
}
function setQueue(address _queue) external onlyOwner {
QUEUE = _queue;
}
function setTeamVirtuallyInvestValue(
address _user,
uint256 _value
) external onlyOwner {
teamVirtuallyInvestValue[_user] = _value;
}
function setProject(address _project) external onlyOwner {
require(_project != address(0), "zero address");
PROJECT = IProject(_project);
}
function setLpAddress(address _lpAddress) external onlyOwner {
require(_lpAddress != address(0), "zero address");
lpAddress = _lpAddress;
}
// ============ Core Staking Functions (Called by Queue) ============
function stakeFor(address user, uint160 amount, uint8 stakeIndex) external onlyQueue {
require(amount >= MIN_STAKE_AMOUNT, ">=MIN_STAKE_AMOUNT");
require(stakeIndex < configs.length, "index out of range");
require(REFERRAL.isBindReferral(user), "!!bind");
if (stakeIndex == 0) {
require(!userOneDayStaked[user], "1day already staked");
userOneDayStaked[user] = true;
}
_swapAndAddLiquidity(amount);
_mint(user, amount, stakeIndex);
}
function unstakeFor(
address user,
uint256 index
) external onlyQueue returns (uint256 actualAmount) {
uint256 amount;
(, amount, actualAmount) = _burn(user, index);
address[] memory referrals = REFERRAL.getReferrals(user, maxD);
for (uint8 i = 0; i < referrals.length; i++) {
teamTotalInvestValue[referrals[i]] -= amount;
}
if (actualAmount == 0) {
return 0;
}
(uint256 amount_usdt, uint256 amount_lax) = _swapLAXForExactUSDT(
actualAmount
);
USDT.transfer(user, amount_usdt);
LAX.recycle(amount_lax);
}
function restakeFor(address user, uint256 _index, uint160 _amount, uint8 _stakeIndex) external onlyQueue {
require(_amount >= MIN_STAKE_AMOUNT, ">=MIN_STAKE_AMOUNT");
require(_stakeIndex < configs.length, "index out of range");
require(_stakeIndex > 0, "restake cannot be 1day");
Record storage user_record = userStakeRecord[user][_index];
require(user_record.unstakeTime > 0, "not unstaked");
require(user_record.restakeTime == 0, "already restaked");
require(_amount >= user_record.amount, "amount too small");
require(_stakeIndex >= user_record.stakeIndex, "stake index too small");
_swapAndAddLiquidity(_amount);
user_record.restakeTime = uint40(block.timestamp);
_mint(user, _amount, _stakeIndex);
emit Restaked(user, uint40(block.timestamp), _index);
}
function claimFor(address user, uint256 _index) external onlyQueue {
Record storage user_record = userStakeRecord[user][_index];
require(user_record.reward > 0, "no reward");
Config memory config = configs[user_record.stakeIndex];
require(
user_record.restakeTime > 0 &&
user_record.restakeTime <= user_record.unstakeTime + config.ttl,
"not restaked in time"
);
uint160 claimReward = user_record.reward;
user_record.reward = 0;
_distributeReward(user, claimReward);
emit RewardPaid(
user,
claimReward,
uint40(block.timestamp),
_index
);
}
// ============ View Functions ============
function balanceOf(
address account
) external view returns (uint256 balance) {
Record[] storage cord = userStakeRecord[account];
if (cord.length > 0) {
for (uint256 i = cord.length - 1; i >= 0; i--) {
Record storage user_record = cord[i];
if (user_record.unstakeTime == 0) {
balance += _caclItem(user_record);
}
if (i == 0) break;
}
}
}
function rewardOfSlot(
address user,
uint8 index
) public view returns (uint256 reward) {
Record storage user_record = userStakeRecord[user][index];
return _caclItem(user_record);
}
function stakeCount(address user) external view returns (uint256 count) {
count = userStakeRecord[user].length;
}
function getTeamKpi(address _user) public view returns (uint256) {
return teamTotalInvestValue[_user] + teamVirtuallyInvestValue[_user];
}
function isPreacher(address user) public view returns (bool) {
return balances[user] >= 199 ether;
}
function getStakeRecord(
address user,
uint256 index
) external view returns (Record memory) {
return userStakeRecord[user][index];
}
// ============ Internal Functions ============
function _mint(address sender, uint160 _amount, uint8 _stakeIndex) private {
Record memory order;
order.stakeTime = uint40(block.timestamp);
order.amount = _amount;
order.stakeIndex = _stakeIndex;
totalSupply += _amount;
balances[sender] += _amount;
Record[] storage cord = userStakeRecord[sender];
uint256 stake_index = cord.length;
cord.push(order);
address[] memory referrals = REFERRAL.getReferrals(sender, maxD);
for (uint8 i = 0; i < referrals.length; i++) {
teamTotalInvestValue[referrals[i]] += _amount;
}
emit Transfer(address(0), sender, _amount);
emit Staked(
sender,
_amount,
uint40(block.timestamp),
stake_index,
configs[_stakeIndex].day
);
}
function _burn(
address sender,
uint256 index
) private returns (uint256 reward, uint256 amount, uint256 actualAmount) {
Record[] storage cord = userStakeRecord[sender];
Record storage user_record = cord[index];
uint256 stakeTime = user_record.stakeTime;
Config memory config = configs[user_record.stakeIndex];
uint256 maturityTime = stakeTime + config.day;
require(block.timestamp >= maturityTime, "The time is not right");
require(user_record.unstakeTime == 0, "alw");
amount = user_record.amount;
uint256 penaltyRate = _calcPenaltyRate(maturityTime);
actualAmount = (amount * (100 - penaltyRate)) / 100;
totalSupply -= amount;
balances[sender] -= amount;
emit Transfer(sender, address(0), amount);
reward = _caclItem(user_record);
user_record.unstakeTime = uint40(block.timestamp);
if (reward > amount) {
user_record.reward = uint160(reward - amount);
}
emit Unstaked(
sender,
uint160(actualAmount),
uint40(block.timestamp),
index,
user_record.reward,
config.ttl
);
}
function _calcPenaltyRate(uint256 maturityTime) private view returns (uint256 penaltyRate) {
if (block.timestamp <= maturityTime) {
return 0;
}
uint256 delayTime = block.timestamp - maturityTime;
uint256 penaltyPeriods = delayTime / 24 hours;
penaltyRate = penaltyPeriods * 5;
if (penaltyRate > 100) {
penaltyRate = 100;
}
}
function _caclItem(
Record storage user_record
) private view returns (uint256 reward) {
UD60x18 stake_amount = ud(user_record.amount);
uint40 stake_time = user_record.stakeTime;
uint40 stake_period = (uint40(block.timestamp) - stake_time);
stake_period = Math.min(
stake_period,
configs[user_record.stakeIndex].day
);
if (stake_period == 0) reward = UD60x18.unwrap(stake_amount);
else
reward = UD60x18.unwrap(
stake_amount.mul(
ud(configs[user_record.stakeIndex].rate).powu(stake_period)
)
);
}
function _distributeReward(address _user, uint160 _reward) private {
(uint256 amount_usdt, uint256 swapped_lax) = _swapLAXForExactUSDT(
_reward
);
uint256 laxo_amount = (amount_usdt * 50) / 1000;
_buyLaxoToTarget(laxo_amount);
uint256 team_reward_amount = (amount_usdt * 350) / 1000;
_teamReward(_user, team_reward_amount);
uint256 user_amount = amount_usdt - laxo_amount - team_reward_amount;
USDT.transfer(_user, user_amount);
LAX.recycle(swapped_lax);
}
function _buyLaxoToTarget(uint256 _usdtAmount) private {
if (_usdtAmount == 0) return;
if (address(LAXO) != address(0) && LAXO.isReachedMaxBurn()) {
USDT.transfer(ecosystemAddress(), _usdtAmount);
} else {
_swapExactUSDTForLAXO(_usdtAmount,dividendAddress());
}
}
function _teamReward(
address _user,
uint256 _totalReward
) private returns (uint256 spentAmount) {
address[] memory referrals = REFERRAL.getReferrals(_user, maxD);
address top_team;
uint256 team_kpi;
uint256 maxTeamRate = 35;
uint256 spendRate = 0;
for (uint256 i = 0; i < referrals.length; i++) {
top_team = referrals[i];
team_kpi = getTeamKpi(top_team);
if (
team_kpi >= 30000000 * 10 ** 18 &&
maxTeamRate > spendRate &&
isPreacher(top_team)
) {
USDT.transfer(
top_team,
(_totalReward * (maxTeamRate - spendRate)) / maxTeamRate
);
spendRate = 35;
}
if (
team_kpi >= 10000000 * 10 ** 18 &&
team_kpi < 30000000 * 10 ** 18 &&
spendRate < 32 &&
isPreacher(top_team)
) {
USDT.transfer(top_team, (_totalReward * (32 - spendRate)) / maxTeamRate);
spendRate = 32;
}
if (
team_kpi >= 5000000 * 10 ** 18 &&
team_kpi < 10000000 * 10 ** 18 &&
spendRate < 29 &&
isPreacher(top_team)
) {
USDT.transfer(top_team, (_totalReward * (29 - spendRate)) / maxTeamRate);
spendRate = 29;
}
if (
team_kpi >= 1000000 * 10 ** 18 &&
team_kpi < 5000000 * 10 ** 18 &&
spendRate < 26 &&
isPreacher(top_team)
) {
USDT.transfer(top_team, (_totalReward * (26 - spendRate)) / maxTeamRate);
spendRate = 26;
}
if (
team_kpi >= 500000 * 10 ** 18 &&
team_kpi < 1000000 * 10 ** 18 &&
spendRate < 22 &&
isPreacher(top_team)
) {
USDT.transfer(top_team, (_totalReward * (22 - spendRate)) / maxTeamRate);
spendRate = 22;
}
if (
team_kpi >= 100000 * 10 ** 18 &&
team_kpi < 500000 * 10 ** 18 &&
spendRate < 18 &&
isPreacher(top_team)
) {
USDT.transfer(top_team, (_totalReward * (18 - spendRate)) / maxTeamRate);
spendRate = 18;
}
if (
team_kpi >= 50000 * 10 ** 18 &&
team_kpi < 100000 * 10 ** 18 &&
spendRate < 13 &&
isPreacher(top_team)
) {
USDT.transfer(top_team, (_totalReward * (13 - spendRate)) / maxTeamRate);
spendRate = 13;
}
if (
team_kpi >= 10000 * 10 ** 18 &&
team_kpi < 50000 * 10 ** 18 &&
spendRate < 7 &&
isPreacher(top_team)
) {
USDT.transfer(top_team, (_totalReward * (7 - spendRate)) / maxTeamRate);
spendRate = 7;
}
}
spentAmount = (_totalReward * spendRate) / maxTeamRate;
if (maxTeamRate > spendRate) {
USDT.transfer(
marketingAddress(),
_totalReward - spentAmount
);
}
}
// ============ Swap Functions ============
function _swapAndAddLiquidity(uint160 _amount) private {
USDT.transferFrom(msg.sender, address(this), _amount);
uint256 amount_lax = _swapExactUSDTForLAX(_amount / 2);
ROUTER.addLiquidity(
address(USDT),
address(LAX),
_amount / 2,
amount_lax,
0,
0,
lpAddress,
block.timestamp
);
}
function _swapLAXForExactUSDT(
uint256 _usdtAmount
) private returns (uint256 amount_usdt, uint256 amount_lax) {
uint256 bal_this = LAX.balanceOf(address(this));
uint256 usdt_this = USDT.balanceOf(address(this));
address[] memory path = new address[](2);
path[0] = address(LAX);
path[1] = address(USDT);
ROUTER.swapTokensForExactTokens(
_usdtAmount,
bal_this,
path,
address(this),
block.timestamp
);
uint256 bal_now = LAX.balanceOf(address(this));
uint256 usdt_now = USDT.balanceOf(address(this));
amount_lax = bal_this - bal_now;
amount_usdt = usdt_now - usdt_this;
}
function _swapExactUSDTForLAX(
uint256 _usdtAmount
) private returns (uint256 amount_lax) {
address[] memory path = new address[](2);
path[0] = address(USDT);
path[1] = address(LAX);
uint256 balb = LAX.balanceOf(address(this));
ROUTER.swapExactTokensForTokensSupportingFeeOnTransferTokens(
_usdtAmount,
0,
path,
address(this),
block.timestamp
);
uint256 bala = LAX.balanceOf(address(this));
amount_lax = bala - balb;
}
function _swapExactUSDTForLAXO(
uint256 _usdtAmount,
address _to
) private {
address[] memory path = new address[](2);
path[0] = address(USDT);
path[1] = address(LAXO);
ROUTER.swapExactTokensForTokensSupportingFeeOnTransferTokens(
_usdtAmount,
0,
path,
_to,
block.timestamp
);
}
// ============ Emergency Functions ============
function sync() external {
require(msg.sender == owner || msg.sender == marketingAddress(), "!owner or marketing");
uint256 w_bal = IERC20(USDT).balanceOf(address(this));
address pair = LAX.uniswapV2Pair();
IERC20(USDT).transfer(pair, w_bal);
IUniswapV2Pair(pair).sync();
}
function emergencyWithdrawLAX(
address to,
uint256 _amount
) external onlyOwner {
LAX.transfer(to, _amount);
}
}
library Math {
function min(uint40 a, uint40 b) internal pure returns (uint40) {
return a < b ? a : b;
}
function min256(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
interface IStaking {
// ============ Structs ============
struct Record {
uint40 stakeTime;
uint160 amount;
uint8 stakeIndex;
uint40 unstakeTime;
uint160 reward;
uint40 restakeTime;
}
struct Config {
uint256 rate;
uint40 day;
uint40 ttl;
}
// ============ Events ============
event Staked(
address indexed user,
uint160 amount,
uint40 timestamp,
uint256 index,
uint40 stakeTime
);
event RewardPaid(
address indexed user,
uint160 reward,
uint40 timestamp,
uint256 index
);
event Unstaked(
address indexed user,
uint160 amount,
uint40 timestamp,
uint256 index,
uint160 reward,
uint40 ttl
);
event Restaked(address indexed user, uint40 timestamp, uint256 index);
event Transfer(address indexed from, address indexed to, uint256 amount);
// ============ View Functions ============
function userOneDayStaked(address user) external view returns (bool);
function getStakeRecord(address user, uint256 index) external view returns (Record memory);
// ============ Core Functions (Called by Queue) ============
function stakeFor(address user, uint160 amount, uint8 stakeIndex) external;
function unstakeFor(address user, uint256 index) external returns (uint256 actualAmount);
function restakeFor(address user, uint256 _index, uint160 _amount, uint8 _stakeIndex) external;
function claimFor(address user, uint256 _index) external;
}// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.20; address constant _USDT = 0x55d398326f99059fF775485246999027B3197955; address constant _ROUTER = 0x10ED43C718714eb63d5aA57B78B54704E256024E;
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Simple single owner authorization mixin.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Owned.sol)
abstract contract Owned {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event OwnershipTransferred(address indexed user, address indexed newOwner);
/*//////////////////////////////////////////////////////////////
OWNERSHIP STORAGE
//////////////////////////////////////////////////////////////*/
address public owner;
modifier onlyOwner() virtual {
require(msg.sender == owner, "UNAUTHORIZED");
_;
}
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor(address _owner) {
owner = _owner;
emit OwnershipTransferred(address(0), _owner);
}
/*//////////////////////////////////////////////////////////////
OWNERSHIP LOGIC
//////////////////////////////////////////////////////////////*/
function transferOwnership(address newOwner) public virtual onlyOwner {
owner = newOwner;
emit OwnershipTransferred(msg.sender, newOwner);
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
interface IProject {
function dividendWallet() external view returns (address);
function marketingAddress() external view returns (address);
function ecosystemAddress() external view returns (address);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IReferral{
event BindReferral(address indexed user,address parent);
function getReferral(address _address)external view returns(address);
function isBindReferral(address _address) external view returns(bool);
function getReferralCount(address _address) external view returns(uint256);
function bindReferral(address _referral,address _user) external;
function getReferrals(address _address,uint256 _num) external view returns(address[] memory);
function getRootAddress()external view returns(address);
function batchImportReferrals(address[] calldata users,address[] calldata referrals) external;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
interface ILAXOToken {
function isReachedMaxBurn() external view returns (bool);
function addUserQuota(address user, uint256 amount) external;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/**
* @title ILAXToken
* @notice LAX Token 接口,继承 IERC20 并添加特有函数
*/
interface ILAXToken is IERC20 {
function getYesterdayCloseReserveU() external view returns (uint112);
function getCurrentReserveU() external view returns (uint112);
function uniswapV2Pair() external view returns (address);
function recycle(uint256 amount) external;
}pragma solidity >=0.5.0;
interface IUniswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
function mint(address to) external returns (uint liquidity);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}pragma solidity >=0.6.2;
import './IUniswapV2Router01.sol';
interface IUniswapV2Router02 is IUniswapV2Router01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
}// SPDX-License-Identifier: MIT pragma solidity >=0.8.19; /* ██████╗ ██████╗ ██████╗ ███╗ ███╗ █████╗ ████████╗██╗ ██╗ ██╔══██╗██╔══██╗██╔══██╗████╗ ████║██╔══██╗╚══██╔══╝██║ ██║ ██████╔╝██████╔╝██████╔╝██╔████╔██║███████║ ██║ ███████║ ██╔═══╝ ██╔══██╗██╔══██╗██║╚██╔╝██║██╔══██║ ██║ ██╔══██║ ██║ ██║ ██║██████╔╝██║ ╚═╝ ██║██║ ██║ ██║ ██║ ██║ ╚═╝ ╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ██╗ ██╗██████╗ ██████╗ ██████╗ ██╗ ██╗ ██╗ █████╗ ██║ ██║██╔══██╗██╔════╝ ██╔═████╗╚██╗██╔╝███║██╔══██╗ ██║ ██║██║ ██║███████╗ ██║██╔██║ ╚███╔╝ ╚██║╚█████╔╝ ██║ ██║██║ ██║██╔═══██╗████╔╝██║ ██╔██╗ ██║██╔══██╗ ╚██████╔╝██████╔╝╚██████╔╝╚██████╔╝██╔╝ ██╗ ██║╚█████╔╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚════╝ */ import "./ud60x18/Casting.sol"; import "./ud60x18/Constants.sol"; import "./ud60x18/Conversions.sol"; import "./ud60x18/Errors.sol"; import "./ud60x18/Helpers.sol"; import "./ud60x18/Math.sol"; import "./ud60x18/ValueType.sol";
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}pragma solidity >=0.6.2;
interface IUniswapV2Router01 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
function removeLiquidityETH(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
function removeLiquidityETHWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Casting.sol" as Casting;
import "./Helpers.sol" as Helpers;
import "./Math.sol" as Math;
/// @notice The unsigned 60.18-decimal fixed-point number representation, which can have up to 60 digits and up to 18
/// decimals. The values of this are bound by the minimum and the maximum values permitted by the Solidity type uint256.
/// @dev The value type is defined here so it can be imported in all other files.
type UD60x18 is uint256;
/*//////////////////////////////////////////////////////////////////////////
CASTING
//////////////////////////////////////////////////////////////////////////*/
using {
Casting.intoSD1x18,
Casting.intoSD21x18,
Casting.intoSD59x18,
Casting.intoUD2x18,
Casting.intoUD21x18,
Casting.intoUint128,
Casting.intoUint256,
Casting.intoUint40,
Casting.unwrap
} for UD60x18 global;
/*//////////////////////////////////////////////////////////////////////////
MATHEMATICAL FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
// The global "using for" directive makes the functions in this library callable on the UD60x18 type.
using {
Math.avg,
Math.ceil,
Math.div,
Math.exp,
Math.exp2,
Math.floor,
Math.frac,
Math.gm,
Math.inv,
Math.ln,
Math.log10,
Math.log2,
Math.mul,
Math.pow,
Math.powu,
Math.sqrt
} for UD60x18 global;
/*//////////////////////////////////////////////////////////////////////////
HELPER FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
// The global "using for" directive makes the functions in this library callable on the UD60x18 type.
using {
Helpers.add,
Helpers.and,
Helpers.eq,
Helpers.gt,
Helpers.gte,
Helpers.isZero,
Helpers.lshift,
Helpers.lt,
Helpers.lte,
Helpers.mod,
Helpers.neq,
Helpers.not,
Helpers.or,
Helpers.rshift,
Helpers.sub,
Helpers.uncheckedAdd,
Helpers.uncheckedSub,
Helpers.xor
} for UD60x18 global;
/*//////////////////////////////////////////////////////////////////////////
OPERATORS
//////////////////////////////////////////////////////////////////////////*/
// The global "using for" directive makes it possible to use these operators on the UD60x18 type.
using {
Helpers.add as +,
Helpers.and2 as &,
Math.div as /,
Helpers.eq as ==,
Helpers.gt as >,
Helpers.gte as >=,
Helpers.lt as <,
Helpers.lte as <=,
Helpers.or as |,
Helpers.mod as %,
Math.mul as *,
Helpers.neq as !=,
Helpers.not as ~,
Helpers.sub as -,
Helpers.xor as ^
} for UD60x18 global;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "../Common.sol" as Common;
import "./Errors.sol" as Errors;
import { wrap } from "./Casting.sol";
import {
uEXP_MAX_INPUT,
uEXP2_MAX_INPUT,
uHALF_UNIT,
uLOG2_10,
uLOG2_E,
uMAX_UD60x18,
uMAX_WHOLE_UD60x18,
UNIT,
uUNIT,
uUNIT_SQUARED,
ZERO
} from "./Constants.sol";
import { UD60x18 } from "./ValueType.sol";
/*//////////////////////////////////////////////////////////////////////////
MATHEMATICAL FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Calculates the arithmetic average of x and y using the following formula:
///
/// $$
/// avg(x, y) = (x & y) + ((xUint ^ yUint) / 2)
/// $$
///
/// In English, this is what this formula does:
///
/// 1. AND x and y.
/// 2. Calculate half of XOR x and y.
/// 3. Add the two results together.
///
/// This technique is known as SWAR, which stands for "SIMD within a register". You can read more about it here:
/// https://devblogs.microsoft.com/oldnewthing/20220207-00/?p=106223
///
/// @dev Notes:
/// - The result is rounded toward zero.
///
/// @param x The first operand as a UD60x18 number.
/// @param y The second operand as a UD60x18 number.
/// @return result The arithmetic average as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function avg(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
uint256 yUint = y.unwrap();
unchecked {
result = wrap((xUint & yUint) + ((xUint ^ yUint) >> 1));
}
}
/// @notice Yields the smallest whole number greater than or equal to x.
///
/// @dev This is optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional
/// counterparts. See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
///
/// Requirements:
/// - x ≤ MAX_WHOLE_UD60x18
///
/// @param x The UD60x18 number to ceil.
/// @return result The smallest whole number greater than or equal to x, as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function ceil(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
if (xUint > uMAX_WHOLE_UD60x18) {
revert Errors.PRBMath_UD60x18_Ceil_Overflow(x);
}
assembly ("memory-safe") {
// Equivalent to `x % UNIT`.
let remainder := mod(x, uUNIT)
// Equivalent to `UNIT - remainder`.
let delta := sub(uUNIT, remainder)
// Equivalent to `x + remainder > 0 ? delta : 0`.
result := add(x, mul(delta, gt(remainder, 0)))
}
}
/// @notice Divides two UD60x18 numbers, returning a new UD60x18 number.
///
/// @dev Uses {Common.mulDiv} to enable overflow-safe multiplication and division.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv}.
///
/// Requirements:
/// - Refer to the requirements in {Common.mulDiv}.
///
/// @param x The numerator as a UD60x18 number.
/// @param y The denominator as a UD60x18 number.
/// @return result The quotient as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function div(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(Common.mulDiv(x.unwrap(), uUNIT, y.unwrap()));
}
/// @notice Calculates the natural exponent of x using the following formula:
///
/// $$
/// e^x = 2^{x * log_2{e}}
/// $$
///
/// @dev Requirements:
/// - x ≤ 133_084258667509499440
///
/// @param x The exponent as a UD60x18 number.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function exp(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
// This check prevents values greater than 192e18 from being passed to {exp2}.
if (xUint > uEXP_MAX_INPUT) {
revert Errors.PRBMath_UD60x18_Exp_InputTooBig(x);
}
unchecked {
// Inline the fixed-point multiplication to save gas.
uint256 doubleUnitProduct = xUint * uLOG2_E;
result = exp2(wrap(doubleUnitProduct / uUNIT));
}
}
/// @notice Calculates the binary exponent of x using the binary fraction method.
///
/// @dev See https://ethereum.stackexchange.com/q/79903/24693
///
/// Requirements:
/// - x < 192e18
/// - The result must fit in UD60x18.
///
/// @param x The exponent as a UD60x18 number.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function exp2(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
// Numbers greater than or equal to 192e18 don't fit in the 192.64-bit format.
if (xUint > uEXP2_MAX_INPUT) {
revert Errors.PRBMath_UD60x18_Exp2_InputTooBig(x);
}
// Convert x to the 192.64-bit fixed-point format.
uint256 x_192x64 = (xUint << 64) / uUNIT;
// Pass x to the {Common.exp2} function, which uses the 192.64-bit fixed-point number representation.
result = wrap(Common.exp2(x_192x64));
}
/// @notice Yields the greatest whole number less than or equal to x.
/// @dev Optimized for fractional value inputs, because every whole value has (1e18 - 1) fractional counterparts.
/// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
/// @param x The UD60x18 number to floor.
/// @return result The greatest whole number less than or equal to x, as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function floor(UD60x18 x) pure returns (UD60x18 result) {
assembly ("memory-safe") {
// Equivalent to `x % UNIT`.
let remainder := mod(x, uUNIT)
// Equivalent to `x - remainder > 0 ? remainder : 0)`.
result := sub(x, mul(remainder, gt(remainder, 0)))
}
}
/// @notice Yields the excess beyond the floor of x using the odd function definition.
/// @dev See https://en.wikipedia.org/wiki/Fractional_part.
/// @param x The UD60x18 number to get the fractional part of.
/// @return result The fractional part of x as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function frac(UD60x18 x) pure returns (UD60x18 result) {
assembly ("memory-safe") {
result := mod(x, uUNIT)
}
}
/// @notice Calculates the geometric mean of x and y, i.e. $\sqrt{x * y}$, rounding down.
///
/// @dev Requirements:
/// - x * y must fit in UD60x18.
///
/// @param x The first operand as a UD60x18 number.
/// @param y The second operand as a UD60x18 number.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function gm(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
uint256 yUint = y.unwrap();
if (xUint == 0 || yUint == 0) {
return ZERO;
}
unchecked {
// Checking for overflow this way is faster than letting Solidity do it.
uint256 xyUint = xUint * yUint;
if (xyUint / xUint != yUint) {
revert Errors.PRBMath_UD60x18_Gm_Overflow(x, y);
}
// We don't need to multiply the result by `UNIT` here because the x*y product picked up a factor of `UNIT`
// during multiplication. See the comments in {Common.sqrt}.
result = wrap(Common.sqrt(xyUint));
}
}
/// @notice Calculates the inverse of x.
///
/// @dev Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - x must not be zero.
///
/// @param x The UD60x18 number for which to calculate the inverse.
/// @return result The inverse as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function inv(UD60x18 x) pure returns (UD60x18 result) {
unchecked {
result = wrap(uUNIT_SQUARED / x.unwrap());
}
}
/// @notice Calculates the natural logarithm of x using the following formula:
///
/// $$
/// ln{x} = log_2{x} / log_2{e}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {log2}.
/// - The precision isn't sufficiently fine-grained to return exactly `UNIT` when the input is `E`.
///
/// Requirements:
/// - Refer to the requirements in {log2}.
///
/// @param x The UD60x18 number for which to calculate the natural logarithm.
/// @return result The natural logarithm as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function ln(UD60x18 x) pure returns (UD60x18 result) {
unchecked {
// Inline the fixed-point multiplication to save gas. This is overflow-safe because the maximum value that
// {log2} can return is ~196_205294292027477728.
result = wrap(log2(x).unwrap() * uUNIT / uLOG2_E);
}
}
/// @notice Calculates the common logarithm of x using the following formula:
///
/// $$
/// log_{10}{x} = log_2{x} / log_2{10}
/// $$
///
/// However, if x is an exact power of ten, a hard coded value is returned.
///
/// @dev Notes:
/// - Refer to the notes in {log2}.
///
/// Requirements:
/// - Refer to the requirements in {log2}.
///
/// @param x The UD60x18 number for which to calculate the common logarithm.
/// @return result The common logarithm as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function log10(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
if (xUint < uUNIT) {
revert Errors.PRBMath_UD60x18_Log_InputTooSmall(x);
}
// Note that the `mul` in this assembly block is the standard multiplication operation, not {UD60x18.mul}.
// prettier-ignore
assembly ("memory-safe") {
switch x
case 1 { result := mul(uUNIT, sub(0, 18)) }
case 10 { result := mul(uUNIT, sub(1, 18)) }
case 100 { result := mul(uUNIT, sub(2, 18)) }
case 1000 { result := mul(uUNIT, sub(3, 18)) }
case 10000 { result := mul(uUNIT, sub(4, 18)) }
case 100000 { result := mul(uUNIT, sub(5, 18)) }
case 1000000 { result := mul(uUNIT, sub(6, 18)) }
case 10000000 { result := mul(uUNIT, sub(7, 18)) }
case 100000000 { result := mul(uUNIT, sub(8, 18)) }
case 1000000000 { result := mul(uUNIT, sub(9, 18)) }
case 10000000000 { result := mul(uUNIT, sub(10, 18)) }
case 100000000000 { result := mul(uUNIT, sub(11, 18)) }
case 1000000000000 { result := mul(uUNIT, sub(12, 18)) }
case 10000000000000 { result := mul(uUNIT, sub(13, 18)) }
case 100000000000000 { result := mul(uUNIT, sub(14, 18)) }
case 1000000000000000 { result := mul(uUNIT, sub(15, 18)) }
case 10000000000000000 { result := mul(uUNIT, sub(16, 18)) }
case 100000000000000000 { result := mul(uUNIT, sub(17, 18)) }
case 1000000000000000000 { result := 0 }
case 10000000000000000000 { result := uUNIT }
case 100000000000000000000 { result := mul(uUNIT, 2) }
case 1000000000000000000000 { result := mul(uUNIT, 3) }
case 10000000000000000000000 { result := mul(uUNIT, 4) }
case 100000000000000000000000 { result := mul(uUNIT, 5) }
case 1000000000000000000000000 { result := mul(uUNIT, 6) }
case 10000000000000000000000000 { result := mul(uUNIT, 7) }
case 100000000000000000000000000 { result := mul(uUNIT, 8) }
case 1000000000000000000000000000 { result := mul(uUNIT, 9) }
case 10000000000000000000000000000 { result := mul(uUNIT, 10) }
case 100000000000000000000000000000 { result := mul(uUNIT, 11) }
case 1000000000000000000000000000000 { result := mul(uUNIT, 12) }
case 10000000000000000000000000000000 { result := mul(uUNIT, 13) }
case 100000000000000000000000000000000 { result := mul(uUNIT, 14) }
case 1000000000000000000000000000000000 { result := mul(uUNIT, 15) }
case 10000000000000000000000000000000000 { result := mul(uUNIT, 16) }
case 100000000000000000000000000000000000 { result := mul(uUNIT, 17) }
case 1000000000000000000000000000000000000 { result := mul(uUNIT, 18) }
case 10000000000000000000000000000000000000 { result := mul(uUNIT, 19) }
case 100000000000000000000000000000000000000 { result := mul(uUNIT, 20) }
case 1000000000000000000000000000000000000000 { result := mul(uUNIT, 21) }
case 10000000000000000000000000000000000000000 { result := mul(uUNIT, 22) }
case 100000000000000000000000000000000000000000 { result := mul(uUNIT, 23) }
case 1000000000000000000000000000000000000000000 { result := mul(uUNIT, 24) }
case 10000000000000000000000000000000000000000000 { result := mul(uUNIT, 25) }
case 100000000000000000000000000000000000000000000 { result := mul(uUNIT, 26) }
case 1000000000000000000000000000000000000000000000 { result := mul(uUNIT, 27) }
case 10000000000000000000000000000000000000000000000 { result := mul(uUNIT, 28) }
case 100000000000000000000000000000000000000000000000 { result := mul(uUNIT, 29) }
case 1000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 30) }
case 10000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 31) }
case 100000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 32) }
case 1000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 33) }
case 10000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 34) }
case 100000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 35) }
case 1000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 36) }
case 10000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 37) }
case 100000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 38) }
case 1000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 39) }
case 10000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 40) }
case 100000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 41) }
case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 42) }
case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 43) }
case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 44) }
case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 45) }
case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 46) }
case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 47) }
case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 48) }
case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 49) }
case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 50) }
case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 51) }
case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 52) }
case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 53) }
case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 54) }
case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 55) }
case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 56) }
case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 57) }
case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 58) }
case 100000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 59) }
default { result := uMAX_UD60x18 }
}
if (result.unwrap() == uMAX_UD60x18) {
unchecked {
// Inline the fixed-point division to save gas.
result = wrap(log2(x).unwrap() * uUNIT / uLOG2_10);
}
}
}
/// @notice Calculates the binary logarithm of x using the iterative approximation algorithm:
///
/// $$
/// log_2{x} = n + log_2{y}, \text{ where } y = x*2^{-n}, \ y \in [1, 2)
/// $$
///
/// For $0 \leq x \lt 1$, the input is inverted:
///
/// $$
/// log_2{x} = -log_2{\frac{1}{x}}
/// $$
///
/// @dev See https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation
///
/// Notes:
/// - Due to the lossy precision of the iterative approximation, the results are not perfectly accurate to the last decimal.
///
/// Requirements:
/// - x ≥ UNIT
///
/// @param x The UD60x18 number for which to calculate the binary logarithm.
/// @return result The binary logarithm as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function log2(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
if (xUint < uUNIT) {
revert Errors.PRBMath_UD60x18_Log_InputTooSmall(x);
}
unchecked {
// Calculate the integer part of the logarithm.
uint256 n = Common.msb(xUint / uUNIT);
// This is the integer part of the logarithm as a UD60x18 number. The operation can't overflow because n
// n is at most 255 and UNIT is 1e18.
uint256 resultUint = n * uUNIT;
// Calculate $y = x * 2^{-n}$.
uint256 y = xUint >> n;
// If y is the unit number, the fractional part is zero.
if (y == uUNIT) {
return wrap(resultUint);
}
// Calculate the fractional part via the iterative approximation.
// The `delta >>= 1` part is equivalent to `delta /= 2`, but shifting bits is more gas efficient.
uint256 DOUBLE_UNIT = 2e18;
for (uint256 delta = uHALF_UNIT; delta > 0; delta >>= 1) {
y = (y * y) / uUNIT;
// Is y^2 >= 2e18 and so in the range [2e18, 4e18)?
if (y >= DOUBLE_UNIT) {
// Add the 2^{-m} factor to the logarithm.
resultUint += delta;
// Halve y, which corresponds to z/2 in the Wikipedia article.
y >>= 1;
}
}
result = wrap(resultUint);
}
}
/// @notice Multiplies two UD60x18 numbers together, returning a new UD60x18 number.
///
/// @dev Uses {Common.mulDiv} to enable overflow-safe multiplication and division.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv}.
///
/// Requirements:
/// - Refer to the requirements in {Common.mulDiv}.
///
/// @dev See the documentation in {Common.mulDiv18}.
/// @param x The multiplicand as a UD60x18 number.
/// @param y The multiplier as a UD60x18 number.
/// @return result The product as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function mul(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(Common.mulDiv18(x.unwrap(), y.unwrap()));
}
/// @notice Raises x to the power of y.
///
/// For $1 \leq x \leq \infty$, the following standard formula is used:
///
/// $$
/// x^y = 2^{log_2{x} * y}
/// $$
///
/// For $0 \leq x \lt 1$, since the unsigned {log2} is undefined, an equivalent formula is used:
///
/// $$
/// i = \frac{1}{x}
/// w = 2^{log_2{i} * y}
/// x^y = \frac{1}{w}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {log2} and {mul}.
/// - Returns `UNIT` for 0^0.
/// - It may not perform well with very small values of x. Consider using SD59x18 as an alternative.
///
/// Requirements:
/// - Refer to the requirements in {exp2}, {log2}, and {mul}.
///
/// @param x The base as a UD60x18 number.
/// @param y The exponent as a UD60x18 number.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function pow(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
uint256 yUint = y.unwrap();
// If both x and y are zero, the result is `UNIT`. If just x is zero, the result is always zero.
if (xUint == 0) {
return yUint == 0 ? UNIT : ZERO;
}
// If x is `UNIT`, the result is always `UNIT`.
else if (xUint == uUNIT) {
return UNIT;
}
// If y is zero, the result is always `UNIT`.
if (yUint == 0) {
return UNIT;
}
// If y is `UNIT`, the result is always x.
else if (yUint == uUNIT) {
return x;
}
// If x is > UNIT, use the standard formula.
if (xUint > uUNIT) {
result = exp2(mul(log2(x), y));
}
// Conversely, if x < UNIT, use the equivalent formula.
else {
UD60x18 i = wrap(uUNIT_SQUARED / xUint);
UD60x18 w = exp2(mul(log2(i), y));
result = wrap(uUNIT_SQUARED / w.unwrap());
}
}
/// @notice Raises x (a UD60x18 number) to the power y (an unsigned basic integer) using the well-known
/// algorithm "exponentiation by squaring".
///
/// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv18}.
/// - Returns `UNIT` for 0^0.
///
/// Requirements:
/// - The result must fit in UD60x18.
///
/// @param x The base as a UD60x18 number.
/// @param y The exponent as a uint256.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function powu(UD60x18 x, uint256 y) pure returns (UD60x18 result) {
// Calculate the first iteration of the loop in advance.
uint256 xUint = x.unwrap();
uint256 resultUint = y & 1 > 0 ? xUint : uUNIT;
// Equivalent to `for(y /= 2; y > 0; y /= 2)`.
for (y >>= 1; y > 0; y >>= 1) {
xUint = Common.mulDiv18(xUint, xUint);
// Equivalent to `y % 2 == 1`.
if (y & 1 > 0) {
resultUint = Common.mulDiv18(resultUint, xUint);
}
}
result = wrap(resultUint);
}
/// @notice Calculates the square root of x using the Babylonian method.
///
/// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
///
/// Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - x ≤ MAX_UD60x18 / UNIT
///
/// @param x The UD60x18 number for which to calculate the square root.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function sqrt(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
unchecked {
if (xUint > uMAX_UD60x18 / uUNIT) {
revert Errors.PRBMath_UD60x18_Sqrt_Overflow(x);
}
// Multiply x by `UNIT` to account for the factor of `UNIT` picked up when multiplying two UD60x18 numbers.
// In this case, the two numbers are both the square root.
result = wrap(Common.sqrt(xUint * uUNIT));
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { wrap } from "./Casting.sol";
import { UD60x18 } from "./ValueType.sol";
/// @notice Implements the checked addition operation (+) in the UD60x18 type.
function add(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() + y.unwrap());
}
/// @notice Implements the AND (&) bitwise operation in the UD60x18 type.
function and(UD60x18 x, uint256 bits) pure returns (UD60x18 result) {
result = wrap(x.unwrap() & bits);
}
/// @notice Implements the AND (&) bitwise operation in the UD60x18 type.
function and2(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() & y.unwrap());
}
/// @notice Implements the equal operation (==) in the UD60x18 type.
function eq(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() == y.unwrap();
}
/// @notice Implements the greater than operation (>) in the UD60x18 type.
function gt(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() > y.unwrap();
}
/// @notice Implements the greater than or equal to operation (>=) in the UD60x18 type.
function gte(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() >= y.unwrap();
}
/// @notice Implements a zero comparison check function in the UD60x18 type.
function isZero(UD60x18 x) pure returns (bool result) {
// This wouldn't work if x could be negative.
result = x.unwrap() == 0;
}
/// @notice Implements the left shift operation (<<) in the UD60x18 type.
function lshift(UD60x18 x, uint256 bits) pure returns (UD60x18 result) {
result = wrap(x.unwrap() << bits);
}
/// @notice Implements the lower than operation (<) in the UD60x18 type.
function lt(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() < y.unwrap();
}
/// @notice Implements the lower than or equal to operation (<=) in the UD60x18 type.
function lte(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() <= y.unwrap();
}
/// @notice Implements the checked modulo operation (%) in the UD60x18 type.
function mod(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() % y.unwrap());
}
/// @notice Implements the not equal operation (!=) in the UD60x18 type.
function neq(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() != y.unwrap();
}
/// @notice Implements the NOT (~) bitwise operation in the UD60x18 type.
function not(UD60x18 x) pure returns (UD60x18 result) {
result = wrap(~x.unwrap());
}
/// @notice Implements the OR (|) bitwise operation in the UD60x18 type.
function or(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() | y.unwrap());
}
/// @notice Implements the right shift operation (>>) in the UD60x18 type.
function rshift(UD60x18 x, uint256 bits) pure returns (UD60x18 result) {
result = wrap(x.unwrap() >> bits);
}
/// @notice Implements the checked subtraction operation (-) in the UD60x18 type.
function sub(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() - y.unwrap());
}
/// @notice Implements the unchecked addition operation (+) in the UD60x18 type.
function uncheckedAdd(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
unchecked {
result = wrap(x.unwrap() + y.unwrap());
}
}
/// @notice Implements the unchecked subtraction operation (-) in the UD60x18 type.
function uncheckedSub(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
unchecked {
result = wrap(x.unwrap() - y.unwrap());
}
}
/// @notice Implements the XOR (^) bitwise operation in the UD60x18 type.
function xor(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() ^ y.unwrap());
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { UD60x18 } from "./ValueType.sol";
/// @notice Thrown when ceiling a number overflows UD60x18.
error PRBMath_UD60x18_Ceil_Overflow(UD60x18 x);
/// @notice Thrown when converting a basic integer to the fixed-point format overflows UD60x18.
error PRBMath_UD60x18_Convert_Overflow(uint256 x);
/// @notice Thrown when taking the natural exponent of a base greater than 133_084258667509499441.
error PRBMath_UD60x18_Exp_InputTooBig(UD60x18 x);
/// @notice Thrown when taking the binary exponent of a base greater than 192e18.
error PRBMath_UD60x18_Exp2_InputTooBig(UD60x18 x);
/// @notice Thrown when taking the geometric mean of two numbers and multiplying them overflows UD60x18.
error PRBMath_UD60x18_Gm_Overflow(UD60x18 x, UD60x18 y);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD1x18.
error PRBMath_UD60x18_IntoSD1x18_Overflow(UD60x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD21x18.
error PRBMath_UD60x18_IntoSD21x18_Overflow(UD60x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD59x18.
error PRBMath_UD60x18_IntoSD59x18_Overflow(UD60x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in UD2x18.
error PRBMath_UD60x18_IntoUD2x18_Overflow(UD60x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in UD21x18.
error PRBMath_UD60x18_IntoUD21x18_Overflow(UD60x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint128.
error PRBMath_UD60x18_IntoUint128_Overflow(UD60x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint40.
error PRBMath_UD60x18_IntoUint40_Overflow(UD60x18 x);
/// @notice Thrown when taking the logarithm of a number less than UNIT.
error PRBMath_UD60x18_Log_InputTooSmall(UD60x18 x);
/// @notice Thrown when calculating the square root overflows UD60x18.
error PRBMath_UD60x18_Sqrt_Overflow(UD60x18 x);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { uMAX_UD60x18, uUNIT } from "./Constants.sol";
import { PRBMath_UD60x18_Convert_Overflow } from "./Errors.sol";
import { UD60x18 } from "./ValueType.sol";
/// @notice Converts a UD60x18 number to a simple integer by dividing it by `UNIT`.
/// @dev The result is rounded toward zero.
/// @param x The UD60x18 number to convert.
/// @return result The same number in basic integer form.
function convert(UD60x18 x) pure returns (uint256 result) {
result = UD60x18.unwrap(x) / uUNIT;
}
/// @notice Converts a simple integer to UD60x18 by multiplying it by `UNIT`.
///
/// @dev Requirements:
/// - x ≤ MAX_UD60x18 / UNIT
///
/// @param x The basic integer to convert.
/// @return result The same number converted to UD60x18.
function convert(uint256 x) pure returns (UD60x18 result) {
if (x > uMAX_UD60x18 / uUNIT) {
revert PRBMath_UD60x18_Convert_Overflow(x);
}
unchecked {
result = UD60x18.wrap(x * uUNIT);
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { UD60x18 } from "./ValueType.sol";
// NOTICE: the "u" prefix stands for "unwrapped".
/// @dev Euler's number as a UD60x18 number.
UD60x18 constant E = UD60x18.wrap(2_718281828459045235);
/// @dev The maximum input permitted in {exp}.
uint256 constant uEXP_MAX_INPUT = 133_084258667509499440;
UD60x18 constant EXP_MAX_INPUT = UD60x18.wrap(uEXP_MAX_INPUT);
/// @dev The maximum input permitted in {exp2}.
uint256 constant uEXP2_MAX_INPUT = 192e18 - 1;
UD60x18 constant EXP2_MAX_INPUT = UD60x18.wrap(uEXP2_MAX_INPUT);
/// @dev Half the UNIT number.
uint256 constant uHALF_UNIT = 0.5e18;
UD60x18 constant HALF_UNIT = UD60x18.wrap(uHALF_UNIT);
/// @dev $log_2(10)$ as a UD60x18 number.
uint256 constant uLOG2_10 = 3_321928094887362347;
UD60x18 constant LOG2_10 = UD60x18.wrap(uLOG2_10);
/// @dev $log_2(e)$ as a UD60x18 number.
uint256 constant uLOG2_E = 1_442695040888963407;
UD60x18 constant LOG2_E = UD60x18.wrap(uLOG2_E);
/// @dev The maximum value a UD60x18 number can have.
uint256 constant uMAX_UD60x18 = 115792089237316195423570985008687907853269984665640564039457_584007913129639935;
UD60x18 constant MAX_UD60x18 = UD60x18.wrap(uMAX_UD60x18);
/// @dev The maximum whole value a UD60x18 number can have.
uint256 constant uMAX_WHOLE_UD60x18 = 115792089237316195423570985008687907853269984665640564039457_000000000000000000;
UD60x18 constant MAX_WHOLE_UD60x18 = UD60x18.wrap(uMAX_WHOLE_UD60x18);
/// @dev PI as a UD60x18 number.
UD60x18 constant PI = UD60x18.wrap(3_141592653589793238);
/// @dev The unit number, which gives the decimal precision of UD60x18.
uint256 constant uUNIT = 1e18;
UD60x18 constant UNIT = UD60x18.wrap(uUNIT);
/// @dev The unit number squared.
uint256 constant uUNIT_SQUARED = 1e36;
UD60x18 constant UNIT_SQUARED = UD60x18.wrap(uUNIT_SQUARED);
/// @dev Zero as a UD60x18 number.
UD60x18 constant ZERO = UD60x18.wrap(0);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Errors.sol" as CastingErrors;
import { MAX_UINT128, MAX_UINT40 } from "../Common.sol";
import { uMAX_SD1x18 } from "../sd1x18/Constants.sol";
import { SD1x18 } from "../sd1x18/ValueType.sol";
import { uMAX_SD21x18 } from "../sd21x18/Constants.sol";
import { SD21x18 } from "../sd21x18/ValueType.sol";
import { uMAX_SD59x18 } from "../sd59x18/Constants.sol";
import { SD59x18 } from "../sd59x18/ValueType.sol";
import { uMAX_UD2x18 } from "../ud2x18/Constants.sol";
import { uMAX_UD21x18 } from "../ud21x18/Constants.sol";
import { UD2x18 } from "../ud2x18/ValueType.sol";
import { UD21x18 } from "../ud21x18/ValueType.sol";
import { UD60x18 } from "./ValueType.sol";
/// @notice Casts a UD60x18 number into SD1x18.
/// @dev Requirements:
/// - x ≤ uMAX_SD1x18
function intoSD1x18(UD60x18 x) pure returns (SD1x18 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > uint256(int256(uMAX_SD1x18))) {
revert CastingErrors.PRBMath_UD60x18_IntoSD1x18_Overflow(x);
}
result = SD1x18.wrap(int64(uint64(xUint)));
}
/// @notice Casts a UD60x18 number into SD21x18.
/// @dev Requirements:
/// - x ≤ uMAX_SD21x18
function intoSD21x18(UD60x18 x) pure returns (SD21x18 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > uint256(int256(uMAX_SD21x18))) {
revert CastingErrors.PRBMath_UD60x18_IntoSD21x18_Overflow(x);
}
result = SD21x18.wrap(int128(uint128(xUint)));
}
/// @notice Casts a UD60x18 number into UD2x18.
/// @dev Requirements:
/// - x ≤ uMAX_UD2x18
function intoUD2x18(UD60x18 x) pure returns (UD2x18 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > uMAX_UD2x18) {
revert CastingErrors.PRBMath_UD60x18_IntoUD2x18_Overflow(x);
}
result = UD2x18.wrap(uint64(xUint));
}
/// @notice Casts a UD60x18 number into UD21x18.
/// @dev Requirements:
/// - x ≤ uMAX_UD21x18
function intoUD21x18(UD60x18 x) pure returns (UD21x18 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > uMAX_UD21x18) {
revert CastingErrors.PRBMath_UD60x18_IntoUD21x18_Overflow(x);
}
result = UD21x18.wrap(uint128(xUint));
}
/// @notice Casts a UD60x18 number into SD59x18.
/// @dev Requirements:
/// - x ≤ uMAX_SD59x18
function intoSD59x18(UD60x18 x) pure returns (SD59x18 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > uint256(uMAX_SD59x18)) {
revert CastingErrors.PRBMath_UD60x18_IntoSD59x18_Overflow(x);
}
result = SD59x18.wrap(int256(xUint));
}
/// @notice Casts a UD60x18 number into uint128.
/// @dev This is basically an alias for {unwrap}.
function intoUint256(UD60x18 x) pure returns (uint256 result) {
result = UD60x18.unwrap(x);
}
/// @notice Casts a UD60x18 number into uint128.
/// @dev Requirements:
/// - x ≤ MAX_UINT128
function intoUint128(UD60x18 x) pure returns (uint128 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > MAX_UINT128) {
revert CastingErrors.PRBMath_UD60x18_IntoUint128_Overflow(x);
}
result = uint128(xUint);
}
/// @notice Casts a UD60x18 number into uint40.
/// @dev Requirements:
/// - x ≤ MAX_UINT40
function intoUint40(UD60x18 x) pure returns (uint40 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > MAX_UINT40) {
revert CastingErrors.PRBMath_UD60x18_IntoUint40_Overflow(x);
}
result = uint40(xUint);
}
/// @notice Alias for {wrap}.
function ud(uint256 x) pure returns (UD60x18 result) {
result = UD60x18.wrap(x);
}
/// @notice Alias for {wrap}.
function ud60x18(uint256 x) pure returns (UD60x18 result) {
result = UD60x18.wrap(x);
}
/// @notice Unwraps a UD60x18 number into uint256.
function unwrap(UD60x18 x) pure returns (uint256 result) {
result = UD60x18.unwrap(x);
}
/// @notice Wraps a uint256 number into the UD60x18 value type.
function wrap(uint256 x) pure returns (UD60x18 result) {
result = UD60x18.wrap(x);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
// Common.sol
//
// Common mathematical functions used in both SD59x18 and UD60x18. Note that these global functions do not
// always operate with SD59x18 and UD60x18 numbers.
/*//////////////////////////////////////////////////////////////////////////
CUSTOM ERRORS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Thrown when the resultant value in {mulDiv} overflows uint256.
error PRBMath_MulDiv_Overflow(uint256 x, uint256 y, uint256 denominator);
/// @notice Thrown when the resultant value in {mulDiv18} overflows uint256.
error PRBMath_MulDiv18_Overflow(uint256 x, uint256 y);
/// @notice Thrown when one of the inputs passed to {mulDivSigned} is `type(int256).min`.
error PRBMath_MulDivSigned_InputTooSmall();
/// @notice Thrown when the resultant value in {mulDivSigned} overflows int256.
error PRBMath_MulDivSigned_Overflow(int256 x, int256 y);
/*//////////////////////////////////////////////////////////////////////////
CONSTANTS
//////////////////////////////////////////////////////////////////////////*/
/// @dev The maximum value a uint128 number can have.
uint128 constant MAX_UINT128 = type(uint128).max;
/// @dev The maximum value a uint40 number can have.
uint40 constant MAX_UINT40 = type(uint40).max;
/// @dev The maximum value a uint64 number can have.
uint64 constant MAX_UINT64 = type(uint64).max;
/// @dev The unit number, which the decimal precision of the fixed-point types.
uint256 constant UNIT = 1e18;
/// @dev The unit number inverted mod 2^256.
uint256 constant UNIT_INVERSE = 78156646155174841979727994598816262306175212592076161876661_508869554232690281;
/// @dev The the largest power of two that divides the decimal value of `UNIT`. The logarithm of this value is the least significant
/// bit in the binary representation of `UNIT`.
uint256 constant UNIT_LPOTD = 262144;
/*//////////////////////////////////////////////////////////////////////////
FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Calculates the binary exponent of x using the binary fraction method.
/// @dev Has to use 192.64-bit fixed-point numbers. See https://ethereum.stackexchange.com/a/96594/24693.
/// @param x The exponent as an unsigned 192.64-bit fixed-point number.
/// @return result The result as an unsigned 60.18-decimal fixed-point number.
/// @custom:smtchecker abstract-function-nondet
function exp2(uint256 x) pure returns (uint256 result) {
unchecked {
// Start from 0.5 in the 192.64-bit fixed-point format.
result = 0x800000000000000000000000000000000000000000000000;
// The following logic multiplies the result by $\sqrt{2^{-i}}$ when the bit at position i is 1. Key points:
//
// 1. Intermediate results will not overflow, as the starting point is 2^191 and all magic factors are under 2^65.
// 2. The rationale for organizing the if statements into groups of 8 is gas savings. If the result of performing
// a bitwise AND operation between x and any value in the array [0x80; 0x40; 0x20; 0x10; 0x08; 0x04; 0x02; 0x01] is 1,
// we know that `x & 0xFF` is also 1.
if (x & 0xFF00000000000000 > 0) {
if (x & 0x8000000000000000 > 0) {
result = (result * 0x16A09E667F3BCC909) >> 64;
}
if (x & 0x4000000000000000 > 0) {
result = (result * 0x1306FE0A31B7152DF) >> 64;
}
if (x & 0x2000000000000000 > 0) {
result = (result * 0x1172B83C7D517ADCE) >> 64;
}
if (x & 0x1000000000000000 > 0) {
result = (result * 0x10B5586CF9890F62A) >> 64;
}
if (x & 0x800000000000000 > 0) {
result = (result * 0x1059B0D31585743AE) >> 64;
}
if (x & 0x400000000000000 > 0) {
result = (result * 0x102C9A3E778060EE7) >> 64;
}
if (x & 0x200000000000000 > 0) {
result = (result * 0x10163DA9FB33356D8) >> 64;
}
if (x & 0x100000000000000 > 0) {
result = (result * 0x100B1AFA5ABCBED61) >> 64;
}
}
if (x & 0xFF000000000000 > 0) {
if (x & 0x80000000000000 > 0) {
result = (result * 0x10058C86DA1C09EA2) >> 64;
}
if (x & 0x40000000000000 > 0) {
result = (result * 0x1002C605E2E8CEC50) >> 64;
}
if (x & 0x20000000000000 > 0) {
result = (result * 0x100162F3904051FA1) >> 64;
}
if (x & 0x10000000000000 > 0) {
result = (result * 0x1000B175EFFDC76BA) >> 64;
}
if (x & 0x8000000000000 > 0) {
result = (result * 0x100058BA01FB9F96D) >> 64;
}
if (x & 0x4000000000000 > 0) {
result = (result * 0x10002C5CC37DA9492) >> 64;
}
if (x & 0x2000000000000 > 0) {
result = (result * 0x1000162E525EE0547) >> 64;
}
if (x & 0x1000000000000 > 0) {
result = (result * 0x10000B17255775C04) >> 64;
}
}
if (x & 0xFF0000000000 > 0) {
if (x & 0x800000000000 > 0) {
result = (result * 0x1000058B91B5BC9AE) >> 64;
}
if (x & 0x400000000000 > 0) {
result = (result * 0x100002C5C89D5EC6D) >> 64;
}
if (x & 0x200000000000 > 0) {
result = (result * 0x10000162E43F4F831) >> 64;
}
if (x & 0x100000000000 > 0) {
result = (result * 0x100000B1721BCFC9A) >> 64;
}
if (x & 0x80000000000 > 0) {
result = (result * 0x10000058B90CF1E6E) >> 64;
}
if (x & 0x40000000000 > 0) {
result = (result * 0x1000002C5C863B73F) >> 64;
}
if (x & 0x20000000000 > 0) {
result = (result * 0x100000162E430E5A2) >> 64;
}
if (x & 0x10000000000 > 0) {
result = (result * 0x1000000B172183551) >> 64;
}
}
if (x & 0xFF00000000 > 0) {
if (x & 0x8000000000 > 0) {
result = (result * 0x100000058B90C0B49) >> 64;
}
if (x & 0x4000000000 > 0) {
result = (result * 0x10000002C5C8601CC) >> 64;
}
if (x & 0x2000000000 > 0) {
result = (result * 0x1000000162E42FFF0) >> 64;
}
if (x & 0x1000000000 > 0) {
result = (result * 0x10000000B17217FBB) >> 64;
}
if (x & 0x800000000 > 0) {
result = (result * 0x1000000058B90BFCE) >> 64;
}
if (x & 0x400000000 > 0) {
result = (result * 0x100000002C5C85FE3) >> 64;
}
if (x & 0x200000000 > 0) {
result = (result * 0x10000000162E42FF1) >> 64;
}
if (x & 0x100000000 > 0) {
result = (result * 0x100000000B17217F8) >> 64;
}
}
if (x & 0xFF000000 > 0) {
if (x & 0x80000000 > 0) {
result = (result * 0x10000000058B90BFC) >> 64;
}
if (x & 0x40000000 > 0) {
result = (result * 0x1000000002C5C85FE) >> 64;
}
if (x & 0x20000000 > 0) {
result = (result * 0x100000000162E42FF) >> 64;
}
if (x & 0x10000000 > 0) {
result = (result * 0x1000000000B17217F) >> 64;
}
if (x & 0x8000000 > 0) {
result = (result * 0x100000000058B90C0) >> 64;
}
if (x & 0x4000000 > 0) {
result = (result * 0x10000000002C5C860) >> 64;
}
if (x & 0x2000000 > 0) {
result = (result * 0x1000000000162E430) >> 64;
}
if (x & 0x1000000 > 0) {
result = (result * 0x10000000000B17218) >> 64;
}
}
if (x & 0xFF0000 > 0) {
if (x & 0x800000 > 0) {
result = (result * 0x1000000000058B90C) >> 64;
}
if (x & 0x400000 > 0) {
result = (result * 0x100000000002C5C86) >> 64;
}
if (x & 0x200000 > 0) {
result = (result * 0x10000000000162E43) >> 64;
}
if (x & 0x100000 > 0) {
result = (result * 0x100000000000B1721) >> 64;
}
if (x & 0x80000 > 0) {
result = (result * 0x10000000000058B91) >> 64;
}
if (x & 0x40000 > 0) {
result = (result * 0x1000000000002C5C8) >> 64;
}
if (x & 0x20000 > 0) {
result = (result * 0x100000000000162E4) >> 64;
}
if (x & 0x10000 > 0) {
result = (result * 0x1000000000000B172) >> 64;
}
}
if (x & 0xFF00 > 0) {
if (x & 0x8000 > 0) {
result = (result * 0x100000000000058B9) >> 64;
}
if (x & 0x4000 > 0) {
result = (result * 0x10000000000002C5D) >> 64;
}
if (x & 0x2000 > 0) {
result = (result * 0x1000000000000162E) >> 64;
}
if (x & 0x1000 > 0) {
result = (result * 0x10000000000000B17) >> 64;
}
if (x & 0x800 > 0) {
result = (result * 0x1000000000000058C) >> 64;
}
if (x & 0x400 > 0) {
result = (result * 0x100000000000002C6) >> 64;
}
if (x & 0x200 > 0) {
result = (result * 0x10000000000000163) >> 64;
}
if (x & 0x100 > 0) {
result = (result * 0x100000000000000B1) >> 64;
}
}
if (x & 0xFF > 0) {
if (x & 0x80 > 0) {
result = (result * 0x10000000000000059) >> 64;
}
if (x & 0x40 > 0) {
result = (result * 0x1000000000000002C) >> 64;
}
if (x & 0x20 > 0) {
result = (result * 0x10000000000000016) >> 64;
}
if (x & 0x10 > 0) {
result = (result * 0x1000000000000000B) >> 64;
}
if (x & 0x8 > 0) {
result = (result * 0x10000000000000006) >> 64;
}
if (x & 0x4 > 0) {
result = (result * 0x10000000000000003) >> 64;
}
if (x & 0x2 > 0) {
result = (result * 0x10000000000000001) >> 64;
}
if (x & 0x1 > 0) {
result = (result * 0x10000000000000001) >> 64;
}
}
// In the code snippet below, two operations are executed simultaneously:
//
// 1. The result is multiplied by $(2^n + 1)$, where $2^n$ represents the integer part, and the additional 1
// accounts for the initial guess of 0.5. This is achieved by subtracting from 191 instead of 192.
// 2. The result is then converted to an unsigned 60.18-decimal fixed-point format.
//
// The underlying logic is based on the relationship $2^{191-ip} = 2^{ip} / 2^{191}$, where $ip$ denotes the,
// integer part, $2^n$.
result *= UNIT;
result >>= (191 - (x >> 64));
}
}
/// @notice Finds the zero-based index of the first 1 in the binary representation of x.
///
/// @dev See the note on "msb" in this Wikipedia article: https://en.wikipedia.org/wiki/Find_first_set
///
/// Each step in this implementation is equivalent to this high-level code:
///
/// ```solidity
/// if (x >= 2 ** 128) {
/// x >>= 128;
/// result += 128;
/// }
/// ```
///
/// Where 128 is replaced with each respective power of two factor. See the full high-level implementation here:
/// https://gist.github.com/PaulRBerg/f932f8693f2733e30c4d479e8e980948
///
/// The Yul instructions used below are:
///
/// - "gt" is "greater than"
/// - "or" is the OR bitwise operator
/// - "shl" is "shift left"
/// - "shr" is "shift right"
///
/// @param x The uint256 number for which to find the index of the most significant bit.
/// @return result The index of the most significant bit as a uint256.
/// @custom:smtchecker abstract-function-nondet
function msb(uint256 x) pure returns (uint256 result) {
// 2^128
assembly ("memory-safe") {
let factor := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^64
assembly ("memory-safe") {
let factor := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^32
assembly ("memory-safe") {
let factor := shl(5, gt(x, 0xFFFFFFFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^16
assembly ("memory-safe") {
let factor := shl(4, gt(x, 0xFFFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^8
assembly ("memory-safe") {
let factor := shl(3, gt(x, 0xFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^4
assembly ("memory-safe") {
let factor := shl(2, gt(x, 0xF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^2
assembly ("memory-safe") {
let factor := shl(1, gt(x, 0x3))
x := shr(factor, x)
result := or(result, factor)
}
// 2^1
// No need to shift x any more.
assembly ("memory-safe") {
let factor := gt(x, 0x1)
result := or(result, factor)
}
}
/// @notice Calculates x*y÷denominator with 512-bit precision.
///
/// @dev Credits to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv.
///
/// Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - The denominator must not be zero.
/// - The result must fit in uint256.
///
/// @param x The multiplicand as a uint256.
/// @param y The multiplier as a uint256.
/// @param denominator The divisor as a uint256.
/// @return result The result as a uint256.
/// @custom:smtchecker abstract-function-nondet
function mulDiv(uint256 x, uint256 y, uint256 denominator) pure returns (uint256 result) {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512-bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly ("memory-safe") {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
unchecked {
return prod0 / denominator;
}
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
if (prod1 >= denominator) {
revert PRBMath_MulDiv_Overflow(x, y, denominator);
}
////////////////////////////////////////////////////////////////////////////
// 512 by 256 division
////////////////////////////////////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly ("memory-safe") {
// Compute remainder using the mulmod Yul instruction.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512-bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
unchecked {
// Calculate the largest power of two divisor of the denominator using the unary operator ~. This operation cannot overflow
// because the denominator cannot be zero at this point in the function execution. The result is always >= 1.
// For more detail, see https://cs.stackexchange.com/q/138556/92363.
uint256 lpotdod = denominator & (~denominator + 1);
uint256 flippedLpotdod;
assembly ("memory-safe") {
// Factor powers of two out of denominator.
denominator := div(denominator, lpotdod)
// Divide [prod1 prod0] by lpotdod.
prod0 := div(prod0, lpotdod)
// Get the flipped value `2^256 / lpotdod`. If the `lpotdod` is zero, the flipped value is one.
// `sub(0, lpotdod)` produces the two's complement version of `lpotdod`, which is equivalent to flipping all the bits.
// However, `div` interprets this value as an unsigned value: https://ethereum.stackexchange.com/q/147168/24693
flippedLpotdod := add(div(sub(0, lpotdod), lpotdod), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * flippedLpotdod;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
}
}
/// @notice Calculates x*y÷1e18 with 512-bit precision.
///
/// @dev A variant of {mulDiv} with constant folding, i.e. in which the denominator is hard coded to 1e18.
///
/// Notes:
/// - The body is purposely left uncommented; to understand how this works, see the documentation in {mulDiv}.
/// - The result is rounded toward zero.
/// - We take as an axiom that the result cannot be `MAX_UINT256` when x and y solve the following system of equations:
///
/// $$
/// \begin{cases}
/// x * y = MAX\_UINT256 * UNIT \\
/// (x * y) \% UNIT \geq \frac{UNIT}{2}
/// \end{cases}
/// $$
///
/// Requirements:
/// - Refer to the requirements in {mulDiv}.
/// - The result must fit in uint256.
///
/// @param x The multiplicand as an unsigned 60.18-decimal fixed-point number.
/// @param y The multiplier as an unsigned 60.18-decimal fixed-point number.
/// @return result The result as an unsigned 60.18-decimal fixed-point number.
/// @custom:smtchecker abstract-function-nondet
function mulDiv18(uint256 x, uint256 y) pure returns (uint256 result) {
uint256 prod0;
uint256 prod1;
assembly ("memory-safe") {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
if (prod1 == 0) {
unchecked {
return prod0 / UNIT;
}
}
if (prod1 >= UNIT) {
revert PRBMath_MulDiv18_Overflow(x, y);
}
uint256 remainder;
assembly ("memory-safe") {
remainder := mulmod(x, y, UNIT)
result :=
mul(
or(
div(sub(prod0, remainder), UNIT_LPOTD),
mul(sub(prod1, gt(remainder, prod0)), add(div(sub(0, UNIT_LPOTD), UNIT_LPOTD), 1))
),
UNIT_INVERSE
)
}
}
/// @notice Calculates x*y÷denominator with 512-bit precision.
///
/// @dev This is an extension of {mulDiv} for signed numbers, which works by computing the signs and the absolute values separately.
///
/// Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - Refer to the requirements in {mulDiv}.
/// - None of the inputs can be `type(int256).min`.
/// - The result must fit in int256.
///
/// @param x The multiplicand as an int256.
/// @param y The multiplier as an int256.
/// @param denominator The divisor as an int256.
/// @return result The result as an int256.
/// @custom:smtchecker abstract-function-nondet
function mulDivSigned(int256 x, int256 y, int256 denominator) pure returns (int256 result) {
if (x == type(int256).min || y == type(int256).min || denominator == type(int256).min) {
revert PRBMath_MulDivSigned_InputTooSmall();
}
// Get hold of the absolute values of x, y and the denominator.
uint256 xAbs;
uint256 yAbs;
uint256 dAbs;
unchecked {
xAbs = x < 0 ? uint256(-x) : uint256(x);
yAbs = y < 0 ? uint256(-y) : uint256(y);
dAbs = denominator < 0 ? uint256(-denominator) : uint256(denominator);
}
// Compute the absolute value of x*y÷denominator. The result must fit in int256.
uint256 resultAbs = mulDiv(xAbs, yAbs, dAbs);
if (resultAbs > uint256(type(int256).max)) {
revert PRBMath_MulDivSigned_Overflow(x, y);
}
// Get the signs of x, y and the denominator.
uint256 sx;
uint256 sy;
uint256 sd;
assembly ("memory-safe") {
// "sgt" is the "signed greater than" assembly instruction and "sub(0,1)" is -1 in two's complement.
sx := sgt(x, sub(0, 1))
sy := sgt(y, sub(0, 1))
sd := sgt(denominator, sub(0, 1))
}
// XOR over sx, sy and sd. What this does is to check whether there are 1 or 3 negative signs in the inputs.
// If there are, the result should be negative. Otherwise, it should be positive.
unchecked {
result = sx ^ sy ^ sd == 0 ? -int256(resultAbs) : int256(resultAbs);
}
}
/// @notice Calculates the square root of x using the Babylonian method.
///
/// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
///
/// Notes:
/// - If x is not a perfect square, the result is rounded down.
/// - Credits to OpenZeppelin for the explanations in comments below.
///
/// @param x The uint256 number for which to calculate the square root.
/// @return result The result as a uint256.
/// @custom:smtchecker abstract-function-nondet
function sqrt(uint256 x) pure returns (uint256 result) {
if (x == 0) {
return 0;
}
// For our first guess, we calculate the biggest power of 2 which is smaller than the square root of x.
//
// We know that the "msb" (most significant bit) of x is a power of 2 such that we have:
//
// $$
// msb(x) <= x <= 2*msb(x)$
// $$
//
// We write $msb(x)$ as $2^k$, and we get:
//
// $$
// k = log_2(x)
// $$
//
// Thus, we can write the initial inequality as:
//
// $$
// 2^{log_2(x)} <= x <= 2*2^{log_2(x)+1} \\
// sqrt(2^k) <= sqrt(x) < sqrt(2^{k+1}) \\
// 2^{k/2} <= sqrt(x) < 2^{(k+1)/2} <= 2^{(k/2)+1}
// $$
//
// Consequently, $2^{log_2(x) /2} is a good first approximation of sqrt(x) with at least one correct bit.
uint256 xAux = uint256(x);
result = 1;
if (xAux >= 2 ** 128) {
xAux >>= 128;
result <<= 64;
}
if (xAux >= 2 ** 64) {
xAux >>= 64;
result <<= 32;
}
if (xAux >= 2 ** 32) {
xAux >>= 32;
result <<= 16;
}
if (xAux >= 2 ** 16) {
xAux >>= 16;
result <<= 8;
}
if (xAux >= 2 ** 8) {
xAux >>= 8;
result <<= 4;
}
if (xAux >= 2 ** 4) {
xAux >>= 4;
result <<= 2;
}
if (xAux >= 2 ** 2) {
result <<= 1;
}
// At this point, `result` is an estimation with at least one bit of precision. We know the true value has at
// most 128 bits, since it is the square root of a uint256. Newton's method converges quadratically (precision
// doubles at every iteration). We thus need at most 7 iteration to turn our partial result with one bit of
// precision into the expected uint128 result.
unchecked {
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
// If x is not a perfect square, round the result toward zero.
uint256 roundedResult = x / result;
if (result >= roundedResult) {
result = roundedResult;
}
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Casting.sol" as Casting;
/// @notice The unsigned 21.18-decimal fixed-point number representation, which can have up to 21 digits and up to 18
/// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
/// type uint128. This is useful when end users want to use uint128 to save gas, e.g. with tight variable packing in contract
/// storage.
type UD21x18 is uint128;
/*//////////////////////////////////////////////////////////////////////////
CASTING
//////////////////////////////////////////////////////////////////////////*/
using {
Casting.intoSD59x18,
Casting.intoUD60x18,
Casting.intoUint128,
Casting.intoUint256,
Casting.intoUint40,
Casting.unwrap
} for UD21x18 global;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Casting.sol" as Casting;
/// @notice The unsigned 2.18-decimal fixed-point number representation, which can have up to 2 digits and up to 18
/// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
/// type uint64. This is useful when end users want to use uint64 to save gas, e.g. with tight variable packing in contract
/// storage.
type UD2x18 is uint64;
/*//////////////////////////////////////////////////////////////////////////
CASTING
//////////////////////////////////////////////////////////////////////////*/
using {
Casting.intoSD59x18,
Casting.intoUD60x18,
Casting.intoUint128,
Casting.intoUint256,
Casting.intoUint40,
Casting.unwrap
} for UD2x18 global;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { UD21x18 } from "./ValueType.sol";
/// @dev Euler's number as a UD21x18 number.
UD21x18 constant E = UD21x18.wrap(2_718281828459045235);
/// @dev The maximum value a UD21x18 number can have.
uint128 constant uMAX_UD21x18 = 340282366920938463463_374607431768211455;
UD21x18 constant MAX_UD21x18 = UD21x18.wrap(uMAX_UD21x18);
/// @dev PI as a UD21x18 number.
UD21x18 constant PI = UD21x18.wrap(3_141592653589793238);
/// @dev The unit number, which gives the decimal precision of UD21x18.
uint256 constant uUNIT = 1e18;
UD21x18 constant UNIT = UD21x18.wrap(1e18);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { UD2x18 } from "./ValueType.sol";
/// @dev Euler's number as a UD2x18 number.
UD2x18 constant E = UD2x18.wrap(2_718281828459045235);
/// @dev The maximum value a UD2x18 number can have.
uint64 constant uMAX_UD2x18 = 18_446744073709551615;
UD2x18 constant MAX_UD2x18 = UD2x18.wrap(uMAX_UD2x18);
/// @dev PI as a UD2x18 number.
UD2x18 constant PI = UD2x18.wrap(3_141592653589793238);
/// @dev The unit number, which gives the decimal precision of UD2x18.
UD2x18 constant UNIT = UD2x18.wrap(1e18);
uint64 constant uUNIT = 1e18;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Casting.sol" as Casting;
import "./Helpers.sol" as Helpers;
import "./Math.sol" as Math;
/// @notice The signed 59.18-decimal fixed-point number representation, which can have up to 59 digits and up to 18
/// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
/// type int256.
type SD59x18 is int256;
/*//////////////////////////////////////////////////////////////////////////
CASTING
//////////////////////////////////////////////////////////////////////////*/
using {
Casting.intoInt256,
Casting.intoSD1x18,
Casting.intoSD21x18,
Casting.intoUD2x18,
Casting.intoUD21x18,
Casting.intoUD60x18,
Casting.intoUint256,
Casting.intoUint128,
Casting.intoUint40,
Casting.unwrap
} for SD59x18 global;
/*//////////////////////////////////////////////////////////////////////////
MATHEMATICAL FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
using {
Math.abs,
Math.avg,
Math.ceil,
Math.div,
Math.exp,
Math.exp2,
Math.floor,
Math.frac,
Math.gm,
Math.inv,
Math.log10,
Math.log2,
Math.ln,
Math.mul,
Math.pow,
Math.powu,
Math.sqrt
} for SD59x18 global;
/*//////////////////////////////////////////////////////////////////////////
HELPER FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
using {
Helpers.add,
Helpers.and,
Helpers.eq,
Helpers.gt,
Helpers.gte,
Helpers.isZero,
Helpers.lshift,
Helpers.lt,
Helpers.lte,
Helpers.mod,
Helpers.neq,
Helpers.not,
Helpers.or,
Helpers.rshift,
Helpers.sub,
Helpers.uncheckedAdd,
Helpers.uncheckedSub,
Helpers.uncheckedUnary,
Helpers.xor
} for SD59x18 global;
/*//////////////////////////////////////////////////////////////////////////
OPERATORS
//////////////////////////////////////////////////////////////////////////*/
// The global "using for" directive makes it possible to use these operators on the SD59x18 type.
using {
Helpers.add as +,
Helpers.and2 as &,
Math.div as /,
Helpers.eq as ==,
Helpers.gt as >,
Helpers.gte as >=,
Helpers.lt as <,
Helpers.lte as <=,
Helpers.mod as %,
Math.mul as *,
Helpers.neq as !=,
Helpers.not as ~,
Helpers.or as |,
Helpers.sub as -,
Helpers.unary as -,
Helpers.xor as ^
} for SD59x18 global;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { SD59x18 } from "./ValueType.sol";
// NOTICE: the "u" prefix stands for "unwrapped".
/// @dev Euler's number as an SD59x18 number.
SD59x18 constant E = SD59x18.wrap(2_718281828459045235);
/// @dev The maximum input permitted in {exp}.
int256 constant uEXP_MAX_INPUT = 133_084258667509499440;
SD59x18 constant EXP_MAX_INPUT = SD59x18.wrap(uEXP_MAX_INPUT);
/// @dev Any value less than this returns 0 in {exp}.
int256 constant uEXP_MIN_THRESHOLD = -41_446531673892822322;
SD59x18 constant EXP_MIN_THRESHOLD = SD59x18.wrap(uEXP_MIN_THRESHOLD);
/// @dev The maximum input permitted in {exp2}.
int256 constant uEXP2_MAX_INPUT = 192e18 - 1;
SD59x18 constant EXP2_MAX_INPUT = SD59x18.wrap(uEXP2_MAX_INPUT);
/// @dev Any value less than this returns 0 in {exp2}.
int256 constant uEXP2_MIN_THRESHOLD = -59_794705707972522261;
SD59x18 constant EXP2_MIN_THRESHOLD = SD59x18.wrap(uEXP2_MIN_THRESHOLD);
/// @dev Half the UNIT number.
int256 constant uHALF_UNIT = 0.5e18;
SD59x18 constant HALF_UNIT = SD59x18.wrap(uHALF_UNIT);
/// @dev $log_2(10)$ as an SD59x18 number.
int256 constant uLOG2_10 = 3_321928094887362347;
SD59x18 constant LOG2_10 = SD59x18.wrap(uLOG2_10);
/// @dev $log_2(e)$ as an SD59x18 number.
int256 constant uLOG2_E = 1_442695040888963407;
SD59x18 constant LOG2_E = SD59x18.wrap(uLOG2_E);
/// @dev The maximum value an SD59x18 number can have.
int256 constant uMAX_SD59x18 = 57896044618658097711785492504343953926634992332820282019728_792003956564819967;
SD59x18 constant MAX_SD59x18 = SD59x18.wrap(uMAX_SD59x18);
/// @dev The maximum whole value an SD59x18 number can have.
int256 constant uMAX_WHOLE_SD59x18 = 57896044618658097711785492504343953926634992332820282019728_000000000000000000;
SD59x18 constant MAX_WHOLE_SD59x18 = SD59x18.wrap(uMAX_WHOLE_SD59x18);
/// @dev The minimum value an SD59x18 number can have.
int256 constant uMIN_SD59x18 = -57896044618658097711785492504343953926634992332820282019728_792003956564819968;
SD59x18 constant MIN_SD59x18 = SD59x18.wrap(uMIN_SD59x18);
/// @dev The minimum whole value an SD59x18 number can have.
int256 constant uMIN_WHOLE_SD59x18 = -57896044618658097711785492504343953926634992332820282019728_000000000000000000;
SD59x18 constant MIN_WHOLE_SD59x18 = SD59x18.wrap(uMIN_WHOLE_SD59x18);
/// @dev PI as an SD59x18 number.
SD59x18 constant PI = SD59x18.wrap(3_141592653589793238);
/// @dev The unit number, which gives the decimal precision of SD59x18.
int256 constant uUNIT = 1e18;
SD59x18 constant UNIT = SD59x18.wrap(1e18);
/// @dev The unit number squared.
int256 constant uUNIT_SQUARED = 1e36;
SD59x18 constant UNIT_SQUARED = SD59x18.wrap(uUNIT_SQUARED);
/// @dev Zero as an SD59x18 number.
SD59x18 constant ZERO = SD59x18.wrap(0);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Casting.sol" as Casting;
/// @notice The signed 21.18-decimal fixed-point number representation, which can have up to 21 digits and up to 18
/// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
/// type int128. This is useful when end users want to use int128 to save gas, e.g. with tight variable packing in contract
/// storage.
type SD21x18 is int128;
/*//////////////////////////////////////////////////////////////////////////
CASTING
//////////////////////////////////////////////////////////////////////////*/
using {
Casting.intoSD59x18,
Casting.intoUD60x18,
Casting.intoUint128,
Casting.intoUint256,
Casting.intoUint40,
Casting.unwrap
} for SD21x18 global;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { SD21x18 } from "./ValueType.sol";
/// @dev Euler's number as an SD21x18 number.
SD21x18 constant E = SD21x18.wrap(2_718281828459045235);
/// @dev The maximum value an SD21x18 number can have.
int128 constant uMAX_SD21x18 = 170141183460469231731_687303715884105727;
SD21x18 constant MAX_SD21x18 = SD21x18.wrap(uMAX_SD21x18);
/// @dev The minimum value an SD21x18 number can have.
int128 constant uMIN_SD21x18 = -170141183460469231731_687303715884105728;
SD21x18 constant MIN_SD21x18 = SD21x18.wrap(uMIN_SD21x18);
/// @dev PI as an SD21x18 number.
SD21x18 constant PI = SD21x18.wrap(3_141592653589793238);
/// @dev The unit number, which gives the decimal precision of SD21x18.
SD21x18 constant UNIT = SD21x18.wrap(1e18);
int128 constant uUNIT = 1e18;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Casting.sol" as Casting;
/// @notice The signed 1.18-decimal fixed-point number representation, which can have up to 1 digit and up to 18
/// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
/// type int64. This is useful when end users want to use int64 to save gas, e.g. with tight variable packing in contract
/// storage.
type SD1x18 is int64;
/*//////////////////////////////////////////////////////////////////////////
CASTING
//////////////////////////////////////////////////////////////////////////*/
using {
Casting.intoSD59x18,
Casting.intoUD60x18,
Casting.intoUint128,
Casting.intoUint256,
Casting.intoUint40,
Casting.unwrap
} for SD1x18 global;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { SD1x18 } from "./ValueType.sol";
/// @dev Euler's number as an SD1x18 number.
SD1x18 constant E = SD1x18.wrap(2_718281828459045235);
/// @dev The maximum value an SD1x18 number can have.
int64 constant uMAX_SD1x18 = 9_223372036854775807;
SD1x18 constant MAX_SD1x18 = SD1x18.wrap(uMAX_SD1x18);
/// @dev The minimum value an SD1x18 number can have.
int64 constant uMIN_SD1x18 = -9_223372036854775808;
SD1x18 constant MIN_SD1x18 = SD1x18.wrap(uMIN_SD1x18);
/// @dev PI as an SD1x18 number.
SD1x18 constant PI = SD1x18.wrap(3_141592653589793238);
/// @dev The unit number, which gives the decimal precision of SD1x18.
SD1x18 constant UNIT = SD1x18.wrap(1e18);
int64 constant uUNIT = 1e18;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "../Common.sol" as Common;
import "./Errors.sol" as Errors;
import { SD59x18 } from "../sd59x18/ValueType.sol";
import { UD60x18 } from "../ud60x18/ValueType.sol";
import { UD2x18 } from "./ValueType.sol";
/// @notice Casts a UD2x18 number into SD59x18.
/// @dev There is no overflow check because UD2x18 ⊆ SD59x18.
function intoSD59x18(UD2x18 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(int256(uint256(UD2x18.unwrap(x))));
}
/// @notice Casts a UD2x18 number into UD60x18.
/// @dev There is no overflow check because UD2x18 ⊆ UD60x18.
function intoUD60x18(UD2x18 x) pure returns (UD60x18 result) {
result = UD60x18.wrap(UD2x18.unwrap(x));
}
/// @notice Casts a UD2x18 number into uint128.
/// @dev There is no overflow check because UD2x18 ⊆ uint128.
function intoUint128(UD2x18 x) pure returns (uint128 result) {
result = uint128(UD2x18.unwrap(x));
}
/// @notice Casts a UD2x18 number into uint256.
/// @dev There is no overflow check because UD2x18 ⊆ uint256.
function intoUint256(UD2x18 x) pure returns (uint256 result) {
result = uint256(UD2x18.unwrap(x));
}
/// @notice Casts a UD2x18 number into uint40.
/// @dev Requirements:
/// - x ≤ MAX_UINT40
function intoUint40(UD2x18 x) pure returns (uint40 result) {
uint64 xUint = UD2x18.unwrap(x);
if (xUint > uint64(Common.MAX_UINT40)) {
revert Errors.PRBMath_UD2x18_IntoUint40_Overflow(x);
}
result = uint40(xUint);
}
/// @notice Alias for {wrap}.
function ud2x18(uint64 x) pure returns (UD2x18 result) {
result = UD2x18.wrap(x);
}
/// @notice Unwrap a UD2x18 number into uint64.
function unwrap(UD2x18 x) pure returns (uint64 result) {
result = UD2x18.unwrap(x);
}
/// @notice Wraps a uint64 number into UD2x18.
function wrap(uint64 x) pure returns (UD2x18 result) {
result = UD2x18.wrap(x);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "../Common.sol" as Common;
import "./Errors.sol" as Errors;
import { SD59x18 } from "../sd59x18/ValueType.sol";
import { UD60x18 } from "../ud60x18/ValueType.sol";
import { UD21x18 } from "./ValueType.sol";
/// @notice Casts a UD21x18 number into SD59x18.
/// @dev There is no overflow check because UD21x18 ⊆ SD59x18.
function intoSD59x18(UD21x18 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(int256(uint256(UD21x18.unwrap(x))));
}
/// @notice Casts a UD21x18 number into UD60x18.
/// @dev There is no overflow check because UD21x18 ⊆ UD60x18.
function intoUD60x18(UD21x18 x) pure returns (UD60x18 result) {
result = UD60x18.wrap(UD21x18.unwrap(x));
}
/// @notice Casts a UD21x18 number into uint128.
/// @dev This is basically an alias for {unwrap}.
function intoUint128(UD21x18 x) pure returns (uint128 result) {
result = UD21x18.unwrap(x);
}
/// @notice Casts a UD21x18 number into uint256.
/// @dev There is no overflow check because UD21x18 ⊆ uint256.
function intoUint256(UD21x18 x) pure returns (uint256 result) {
result = uint256(UD21x18.unwrap(x));
}
/// @notice Casts a UD21x18 number into uint40.
/// @dev Requirements:
/// - x ≤ MAX_UINT40
function intoUint40(UD21x18 x) pure returns (uint40 result) {
uint128 xUint = UD21x18.unwrap(x);
if (xUint > uint128(Common.MAX_UINT40)) {
revert Errors.PRBMath_UD21x18_IntoUint40_Overflow(x);
}
result = uint40(xUint);
}
/// @notice Alias for {wrap}.
function ud21x18(uint128 x) pure returns (UD21x18 result) {
result = UD21x18.wrap(x);
}
/// @notice Unwrap a UD21x18 number into uint128.
function unwrap(UD21x18 x) pure returns (uint128 result) {
result = UD21x18.unwrap(x);
}
/// @notice Wraps a uint128 number into UD21x18.
function wrap(uint128 x) pure returns (UD21x18 result) {
result = UD21x18.wrap(x);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "../Common.sol" as Common;
import "./Errors.sol" as Errors;
import {
uEXP_MAX_INPUT,
uEXP2_MAX_INPUT,
uEXP_MIN_THRESHOLD,
uEXP2_MIN_THRESHOLD,
uHALF_UNIT,
uLOG2_10,
uLOG2_E,
uMAX_SD59x18,
uMAX_WHOLE_SD59x18,
uMIN_SD59x18,
uMIN_WHOLE_SD59x18,
UNIT,
uUNIT,
uUNIT_SQUARED,
ZERO
} from "./Constants.sol";
import { wrap } from "./Helpers.sol";
import { SD59x18 } from "./ValueType.sol";
/// @notice Calculates the absolute value of x.
///
/// @dev Requirements:
/// - x > MIN_SD59x18.
///
/// @param x The SD59x18 number for which to calculate the absolute value.
/// @return result The absolute value of x as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function abs(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt == uMIN_SD59x18) {
revert Errors.PRBMath_SD59x18_Abs_MinSD59x18();
}
result = xInt < 0 ? wrap(-xInt) : x;
}
/// @notice Calculates the arithmetic average of x and y.
///
/// @dev Notes:
/// - The result is rounded toward zero.
///
/// @param x The first operand as an SD59x18 number.
/// @param y The second operand as an SD59x18 number.
/// @return result The arithmetic average as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function avg(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
unchecked {
// This operation is equivalent to `x / 2 + y / 2`, and it can never overflow.
int256 sum = (xInt >> 1) + (yInt >> 1);
if (sum < 0) {
// If at least one of x and y is odd, add 1 to the result, because shifting negative numbers to the right
// rounds toward negative infinity. The right part is equivalent to `sum + (x % 2 == 1 || y % 2 == 1)`.
assembly ("memory-safe") {
result := add(sum, and(or(xInt, yInt), 1))
}
} else {
// Add 1 if both x and y are odd to account for the double 0.5 remainder truncated after shifting.
result = wrap(sum + (xInt & yInt & 1));
}
}
}
/// @notice Yields the smallest whole number greater than or equal to x.
///
/// @dev Optimized for fractional value inputs, because every whole value has (1e18 - 1) fractional counterparts.
/// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
///
/// Requirements:
/// - x ≤ MAX_WHOLE_SD59x18
///
/// @param x The SD59x18 number to ceil.
/// @return result The smallest whole number greater than or equal to x, as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function ceil(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt > uMAX_WHOLE_SD59x18) {
revert Errors.PRBMath_SD59x18_Ceil_Overflow(x);
}
int256 remainder = xInt % uUNIT;
if (remainder == 0) {
result = x;
} else {
unchecked {
// Solidity uses C fmod style, which returns a modulus with the same sign as x.
int256 resultInt = xInt - remainder;
if (xInt > 0) {
resultInt += uUNIT;
}
result = wrap(resultInt);
}
}
}
/// @notice Divides two SD59x18 numbers, returning a new SD59x18 number.
///
/// @dev This is an extension of {Common.mulDiv} for signed numbers, which works by computing the signs and the absolute
/// values separately.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv}.
/// - The result is rounded toward zero.
///
/// Requirements:
/// - Refer to the requirements in {Common.mulDiv}.
/// - None of the inputs can be `MIN_SD59x18`.
/// - The denominator must not be zero.
/// - The result must fit in SD59x18.
///
/// @param x The numerator as an SD59x18 number.
/// @param y The denominator as an SD59x18 number.
/// @return result The quotient as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function div(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
if (xInt == uMIN_SD59x18 || yInt == uMIN_SD59x18) {
revert Errors.PRBMath_SD59x18_Div_InputTooSmall();
}
// Get hold of the absolute values of x and y.
uint256 xAbs;
uint256 yAbs;
unchecked {
xAbs = xInt < 0 ? uint256(-xInt) : uint256(xInt);
yAbs = yInt < 0 ? uint256(-yInt) : uint256(yInt);
}
// Compute the absolute value (x*UNIT÷y). The resulting value must fit in SD59x18.
uint256 resultAbs = Common.mulDiv(xAbs, uint256(uUNIT), yAbs);
if (resultAbs > uint256(uMAX_SD59x18)) {
revert Errors.PRBMath_SD59x18_Div_Overflow(x, y);
}
// Check if x and y have the same sign using two's complement representation. The left-most bit represents the sign (1 for
// negative, 0 for positive or zero).
bool sameSign = (xInt ^ yInt) > -1;
// If the inputs have the same sign, the result should be positive. Otherwise, it should be negative.
unchecked {
result = wrap(sameSign ? int256(resultAbs) : -int256(resultAbs));
}
}
/// @notice Calculates the natural exponent of x using the following formula:
///
/// $$
/// e^x = 2^{x * log_2{e}}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {exp2}.
///
/// Requirements:
/// - Refer to the requirements in {exp2}.
/// - x < 133_084258667509499441.
///
/// @param x The exponent as an SD59x18 number.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function exp(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
// Any input less than the threshold returns zero.
// This check also prevents an overflow for very small numbers.
if (xInt < uEXP_MIN_THRESHOLD) {
return ZERO;
}
// This check prevents values greater than 192e18 from being passed to {exp2}.
if (xInt > uEXP_MAX_INPUT) {
revert Errors.PRBMath_SD59x18_Exp_InputTooBig(x);
}
unchecked {
// Inline the fixed-point multiplication to save gas.
int256 doubleUnitProduct = xInt * uLOG2_E;
result = exp2(wrap(doubleUnitProduct / uUNIT));
}
}
/// @notice Calculates the binary exponent of x using the binary fraction method using the following formula:
///
/// $$
/// 2^{-x} = \frac{1}{2^x}
/// $$
///
/// @dev See https://ethereum.stackexchange.com/q/79903/24693.
///
/// Notes:
/// - If x < -59_794705707972522261, the result is zero.
///
/// Requirements:
/// - x < 192e18.
/// - The result must fit in SD59x18.
///
/// @param x The exponent as an SD59x18 number.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function exp2(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt < 0) {
// The inverse of any number less than the threshold is truncated to zero.
if (xInt < uEXP2_MIN_THRESHOLD) {
return ZERO;
}
unchecked {
// Inline the fixed-point inversion to save gas.
result = wrap(uUNIT_SQUARED / exp2(wrap(-xInt)).unwrap());
}
} else {
// Numbers greater than or equal to 192e18 don't fit in the 192.64-bit format.
if (xInt > uEXP2_MAX_INPUT) {
revert Errors.PRBMath_SD59x18_Exp2_InputTooBig(x);
}
unchecked {
// Convert x to the 192.64-bit fixed-point format.
uint256 x_192x64 = uint256((xInt << 64) / uUNIT);
// It is safe to cast the result to int256 due to the checks above.
result = wrap(int256(Common.exp2(x_192x64)));
}
}
}
/// @notice Yields the greatest whole number less than or equal to x.
///
/// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional
/// counterparts. See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
///
/// Requirements:
/// - x ≥ MIN_WHOLE_SD59x18
///
/// @param x The SD59x18 number to floor.
/// @return result The greatest whole number less than or equal to x, as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function floor(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt < uMIN_WHOLE_SD59x18) {
revert Errors.PRBMath_SD59x18_Floor_Underflow(x);
}
int256 remainder = xInt % uUNIT;
if (remainder == 0) {
result = x;
} else {
unchecked {
// Solidity uses C fmod style, which returns a modulus with the same sign as x.
int256 resultInt = xInt - remainder;
if (xInt < 0) {
resultInt -= uUNIT;
}
result = wrap(resultInt);
}
}
}
/// @notice Yields the excess beyond the floor of x for positive numbers and the part of the number to the right.
/// of the radix point for negative numbers.
/// @dev Based on the odd function definition. https://en.wikipedia.org/wiki/Fractional_part
/// @param x The SD59x18 number to get the fractional part of.
/// @return result The fractional part of x as an SD59x18 number.
function frac(SD59x18 x) pure returns (SD59x18 result) {
result = wrap(x.unwrap() % uUNIT);
}
/// @notice Calculates the geometric mean of x and y, i.e. $\sqrt{x * y}$.
///
/// @dev Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - x * y must fit in SD59x18.
/// - x * y must not be negative, since complex numbers are not supported.
///
/// @param x The first operand as an SD59x18 number.
/// @param y The second operand as an SD59x18 number.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function gm(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
if (xInt == 0 || yInt == 0) {
return ZERO;
}
unchecked {
// Equivalent to `xy / x != y`. Checking for overflow this way is faster than letting Solidity do it.
int256 xyInt = xInt * yInt;
if (xyInt / xInt != yInt) {
revert Errors.PRBMath_SD59x18_Gm_Overflow(x, y);
}
// The product must not be negative, since complex numbers are not supported.
if (xyInt < 0) {
revert Errors.PRBMath_SD59x18_Gm_NegativeProduct(x, y);
}
// We don't need to multiply the result by `UNIT` here because the x*y product picked up a factor of `UNIT`
// during multiplication. See the comments in {Common.sqrt}.
uint256 resultUint = Common.sqrt(uint256(xyInt));
result = wrap(int256(resultUint));
}
}
/// @notice Calculates the inverse of x.
///
/// @dev Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - x must not be zero.
///
/// @param x The SD59x18 number for which to calculate the inverse.
/// @return result The inverse as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function inv(SD59x18 x) pure returns (SD59x18 result) {
result = wrap(uUNIT_SQUARED / x.unwrap());
}
/// @notice Calculates the natural logarithm of x using the following formula:
///
/// $$
/// ln{x} = log_2{x} / log_2{e}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {log2}.
/// - The precision isn't sufficiently fine-grained to return exactly `UNIT` when the input is `E`.
///
/// Requirements:
/// - Refer to the requirements in {log2}.
///
/// @param x The SD59x18 number for which to calculate the natural logarithm.
/// @return result The natural logarithm as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function ln(SD59x18 x) pure returns (SD59x18 result) {
// Inline the fixed-point multiplication to save gas. This is overflow-safe because the maximum value that
// {log2} can return is ~195_205294292027477728.
result = wrap(log2(x).unwrap() * uUNIT / uLOG2_E);
}
/// @notice Calculates the common logarithm of x using the following formula:
///
/// $$
/// log_{10}{x} = log_2{x} / log_2{10}
/// $$
///
/// However, if x is an exact power of ten, a hard coded value is returned.
///
/// @dev Notes:
/// - Refer to the notes in {log2}.
///
/// Requirements:
/// - Refer to the requirements in {log2}.
///
/// @param x The SD59x18 number for which to calculate the common logarithm.
/// @return result The common logarithm as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function log10(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt < 0) {
revert Errors.PRBMath_SD59x18_Log_InputTooSmall(x);
}
// Note that the `mul` in this block is the standard multiplication operation, not {SD59x18.mul}.
// prettier-ignore
assembly ("memory-safe") {
switch x
case 1 { result := mul(uUNIT, sub(0, 18)) }
case 10 { result := mul(uUNIT, sub(1, 18)) }
case 100 { result := mul(uUNIT, sub(2, 18)) }
case 1000 { result := mul(uUNIT, sub(3, 18)) }
case 10000 { result := mul(uUNIT, sub(4, 18)) }
case 100000 { result := mul(uUNIT, sub(5, 18)) }
case 1000000 { result := mul(uUNIT, sub(6, 18)) }
case 10000000 { result := mul(uUNIT, sub(7, 18)) }
case 100000000 { result := mul(uUNIT, sub(8, 18)) }
case 1000000000 { result := mul(uUNIT, sub(9, 18)) }
case 10000000000 { result := mul(uUNIT, sub(10, 18)) }
case 100000000000 { result := mul(uUNIT, sub(11, 18)) }
case 1000000000000 { result := mul(uUNIT, sub(12, 18)) }
case 10000000000000 { result := mul(uUNIT, sub(13, 18)) }
case 100000000000000 { result := mul(uUNIT, sub(14, 18)) }
case 1000000000000000 { result := mul(uUNIT, sub(15, 18)) }
case 10000000000000000 { result := mul(uUNIT, sub(16, 18)) }
case 100000000000000000 { result := mul(uUNIT, sub(17, 18)) }
case 1000000000000000000 { result := 0 }
case 10000000000000000000 { result := uUNIT }
case 100000000000000000000 { result := mul(uUNIT, 2) }
case 1000000000000000000000 { result := mul(uUNIT, 3) }
case 10000000000000000000000 { result := mul(uUNIT, 4) }
case 100000000000000000000000 { result := mul(uUNIT, 5) }
case 1000000000000000000000000 { result := mul(uUNIT, 6) }
case 10000000000000000000000000 { result := mul(uUNIT, 7) }
case 100000000000000000000000000 { result := mul(uUNIT, 8) }
case 1000000000000000000000000000 { result := mul(uUNIT, 9) }
case 10000000000000000000000000000 { result := mul(uUNIT, 10) }
case 100000000000000000000000000000 { result := mul(uUNIT, 11) }
case 1000000000000000000000000000000 { result := mul(uUNIT, 12) }
case 10000000000000000000000000000000 { result := mul(uUNIT, 13) }
case 100000000000000000000000000000000 { result := mul(uUNIT, 14) }
case 1000000000000000000000000000000000 { result := mul(uUNIT, 15) }
case 10000000000000000000000000000000000 { result := mul(uUNIT, 16) }
case 100000000000000000000000000000000000 { result := mul(uUNIT, 17) }
case 1000000000000000000000000000000000000 { result := mul(uUNIT, 18) }
case 10000000000000000000000000000000000000 { result := mul(uUNIT, 19) }
case 100000000000000000000000000000000000000 { result := mul(uUNIT, 20) }
case 1000000000000000000000000000000000000000 { result := mul(uUNIT, 21) }
case 10000000000000000000000000000000000000000 { result := mul(uUNIT, 22) }
case 100000000000000000000000000000000000000000 { result := mul(uUNIT, 23) }
case 1000000000000000000000000000000000000000000 { result := mul(uUNIT, 24) }
case 10000000000000000000000000000000000000000000 { result := mul(uUNIT, 25) }
case 100000000000000000000000000000000000000000000 { result := mul(uUNIT, 26) }
case 1000000000000000000000000000000000000000000000 { result := mul(uUNIT, 27) }
case 10000000000000000000000000000000000000000000000 { result := mul(uUNIT, 28) }
case 100000000000000000000000000000000000000000000000 { result := mul(uUNIT, 29) }
case 1000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 30) }
case 10000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 31) }
case 100000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 32) }
case 1000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 33) }
case 10000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 34) }
case 100000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 35) }
case 1000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 36) }
case 10000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 37) }
case 100000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 38) }
case 1000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 39) }
case 10000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 40) }
case 100000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 41) }
case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 42) }
case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 43) }
case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 44) }
case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 45) }
case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 46) }
case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 47) }
case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 48) }
case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 49) }
case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 50) }
case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 51) }
case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 52) }
case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 53) }
case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 54) }
case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 55) }
case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 56) }
case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 57) }
case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 58) }
default { result := uMAX_SD59x18 }
}
if (result.unwrap() == uMAX_SD59x18) {
unchecked {
// Inline the fixed-point division to save gas.
result = wrap(log2(x).unwrap() * uUNIT / uLOG2_10);
}
}
}
/// @notice Calculates the binary logarithm of x using the iterative approximation algorithm:
///
/// $$
/// log_2{x} = n + log_2{y}, \text{ where } y = x*2^{-n}, \ y \in [1, 2)
/// $$
///
/// For $0 \leq x \lt 1$, the input is inverted:
///
/// $$
/// log_2{x} = -log_2{\frac{1}{x}}
/// $$
///
/// @dev See https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation.
///
/// Notes:
/// - Due to the lossy precision of the iterative approximation, the results are not perfectly accurate to the last decimal.
///
/// Requirements:
/// - x > 0
///
/// @param x The SD59x18 number for which to calculate the binary logarithm.
/// @return result The binary logarithm as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function log2(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt <= 0) {
revert Errors.PRBMath_SD59x18_Log_InputTooSmall(x);
}
unchecked {
int256 sign;
if (xInt >= uUNIT) {
sign = 1;
} else {
sign = -1;
// Inline the fixed-point inversion to save gas.
xInt = uUNIT_SQUARED / xInt;
}
// Calculate the integer part of the logarithm.
uint256 n = Common.msb(uint256(xInt / uUNIT));
// This is the integer part of the logarithm as an SD59x18 number. The operation can't overflow
// because n is at most 255, `UNIT` is 1e18, and the sign is either 1 or -1.
int256 resultInt = int256(n) * uUNIT;
// Calculate $y = x * 2^{-n}$.
int256 y = xInt >> n;
// If y is the unit number, the fractional part is zero.
if (y == uUNIT) {
return wrap(resultInt * sign);
}
// Calculate the fractional part via the iterative approximation.
// The `delta >>= 1` part is equivalent to `delta /= 2`, but shifting bits is more gas efficient.
int256 DOUBLE_UNIT = 2e18;
for (int256 delta = uHALF_UNIT; delta > 0; delta >>= 1) {
y = (y * y) / uUNIT;
// Is y^2 >= 2e18 and so in the range [2e18, 4e18)?
if (y >= DOUBLE_UNIT) {
// Add the 2^{-m} factor to the logarithm.
resultInt = resultInt + delta;
// Halve y, which corresponds to z/2 in the Wikipedia article.
y >>= 1;
}
}
resultInt *= sign;
result = wrap(resultInt);
}
}
/// @notice Multiplies two SD59x18 numbers together, returning a new SD59x18 number.
///
/// @dev Notes:
/// - Refer to the notes in {Common.mulDiv18}.
///
/// Requirements:
/// - Refer to the requirements in {Common.mulDiv18}.
/// - None of the inputs can be `MIN_SD59x18`.
/// - The result must fit in SD59x18.
///
/// @param x The multiplicand as an SD59x18 number.
/// @param y The multiplier as an SD59x18 number.
/// @return result The product as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function mul(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
if (xInt == uMIN_SD59x18 || yInt == uMIN_SD59x18) {
revert Errors.PRBMath_SD59x18_Mul_InputTooSmall();
}
// Get hold of the absolute values of x and y.
uint256 xAbs;
uint256 yAbs;
unchecked {
xAbs = xInt < 0 ? uint256(-xInt) : uint256(xInt);
yAbs = yInt < 0 ? uint256(-yInt) : uint256(yInt);
}
// Compute the absolute value (x*y÷UNIT). The resulting value must fit in SD59x18.
uint256 resultAbs = Common.mulDiv18(xAbs, yAbs);
if (resultAbs > uint256(uMAX_SD59x18)) {
revert Errors.PRBMath_SD59x18_Mul_Overflow(x, y);
}
// Check if x and y have the same sign using two's complement representation. The left-most bit represents the sign (1 for
// negative, 0 for positive or zero).
bool sameSign = (xInt ^ yInt) > -1;
// If the inputs have the same sign, the result should be positive. Otherwise, it should be negative.
unchecked {
result = wrap(sameSign ? int256(resultAbs) : -int256(resultAbs));
}
}
/// @notice Raises x to the power of y using the following formula:
///
/// $$
/// x^y = 2^{log_2{x} * y}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {exp2}, {log2}, and {mul}.
/// - Returns `UNIT` for 0^0.
///
/// Requirements:
/// - Refer to the requirements in {exp2}, {log2}, and {mul}.
///
/// @param x The base as an SD59x18 number.
/// @param y Exponent to raise x to, as an SD59x18 number
/// @return result x raised to power y, as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function pow(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
// If both x and y are zero, the result is `UNIT`. If just x is zero, the result is always zero.
if (xInt == 0) {
return yInt == 0 ? UNIT : ZERO;
}
// If x is `UNIT`, the result is always `UNIT`.
else if (xInt == uUNIT) {
return UNIT;
}
// If y is zero, the result is always `UNIT`.
if (yInt == 0) {
return UNIT;
}
// If y is `UNIT`, the result is always x.
else if (yInt == uUNIT) {
return x;
}
// Calculate the result using the formula.
result = exp2(mul(log2(x), y));
}
/// @notice Raises x (an SD59x18 number) to the power y (an unsigned basic integer) using the well-known
/// algorithm "exponentiation by squaring".
///
/// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv18}.
/// - Returns `UNIT` for 0^0.
///
/// Requirements:
/// - Refer to the requirements in {abs} and {Common.mulDiv18}.
/// - The result must fit in SD59x18.
///
/// @param x The base as an SD59x18 number.
/// @param y The exponent as a uint256.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function powu(SD59x18 x, uint256 y) pure returns (SD59x18 result) {
uint256 xAbs = uint256(abs(x).unwrap());
// Calculate the first iteration of the loop in advance.
uint256 resultAbs = y & 1 > 0 ? xAbs : uint256(uUNIT);
// Equivalent to `for(y /= 2; y > 0; y /= 2)`.
uint256 yAux = y;
for (yAux >>= 1; yAux > 0; yAux >>= 1) {
xAbs = Common.mulDiv18(xAbs, xAbs);
// Equivalent to `y % 2 == 1`.
if (yAux & 1 > 0) {
resultAbs = Common.mulDiv18(resultAbs, xAbs);
}
}
// The result must fit in SD59x18.
if (resultAbs > uint256(uMAX_SD59x18)) {
revert Errors.PRBMath_SD59x18_Powu_Overflow(x, y);
}
unchecked {
// Is the base negative and the exponent odd? If yes, the result should be negative.
int256 resultInt = int256(resultAbs);
bool isNegative = x.unwrap() < 0 && y & 1 == 1;
if (isNegative) {
resultInt = -resultInt;
}
result = wrap(resultInt);
}
}
/// @notice Calculates the square root of x using the Babylonian method.
///
/// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
///
/// Notes:
/// - Only the positive root is returned.
/// - The result is rounded toward zero.
///
/// Requirements:
/// - x ≥ 0, since complex numbers are not supported.
/// - x ≤ MAX_SD59x18 / UNIT
///
/// @param x The SD59x18 number for which to calculate the square root.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function sqrt(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt < 0) {
revert Errors.PRBMath_SD59x18_Sqrt_NegativeInput(x);
}
if (xInt > uMAX_SD59x18 / uUNIT) {
revert Errors.PRBMath_SD59x18_Sqrt_Overflow(x);
}
unchecked {
// Multiply x by `UNIT` to account for the factor of `UNIT` picked up when multiplying two SD59x18 numbers.
// In this case, the two numbers are both the square root.
uint256 resultUint = Common.sqrt(uint256(xInt * uUNIT));
result = wrap(int256(resultUint));
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { wrap } from "./Casting.sol";
import { SD59x18 } from "./ValueType.sol";
/// @notice Implements the checked addition operation (+) in the SD59x18 type.
function add(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
return wrap(x.unwrap() + y.unwrap());
}
/// @notice Implements the AND (&) bitwise operation in the SD59x18 type.
function and(SD59x18 x, int256 bits) pure returns (SD59x18 result) {
return wrap(x.unwrap() & bits);
}
/// @notice Implements the AND (&) bitwise operation in the SD59x18 type.
function and2(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
return wrap(x.unwrap() & y.unwrap());
}
/// @notice Implements the equal (=) operation in the SD59x18 type.
function eq(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() == y.unwrap();
}
/// @notice Implements the greater than operation (>) in the SD59x18 type.
function gt(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() > y.unwrap();
}
/// @notice Implements the greater than or equal to operation (>=) in the SD59x18 type.
function gte(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() >= y.unwrap();
}
/// @notice Implements a zero comparison check function in the SD59x18 type.
function isZero(SD59x18 x) pure returns (bool result) {
result = x.unwrap() == 0;
}
/// @notice Implements the left shift operation (<<) in the SD59x18 type.
function lshift(SD59x18 x, uint256 bits) pure returns (SD59x18 result) {
result = wrap(x.unwrap() << bits);
}
/// @notice Implements the lower than operation (<) in the SD59x18 type.
function lt(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() < y.unwrap();
}
/// @notice Implements the lower than or equal to operation (<=) in the SD59x18 type.
function lte(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() <= y.unwrap();
}
/// @notice Implements the unchecked modulo operation (%) in the SD59x18 type.
function mod(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
result = wrap(x.unwrap() % y.unwrap());
}
/// @notice Implements the not equal operation (!=) in the SD59x18 type.
function neq(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() != y.unwrap();
}
/// @notice Implements the NOT (~) bitwise operation in the SD59x18 type.
function not(SD59x18 x) pure returns (SD59x18 result) {
result = wrap(~x.unwrap());
}
/// @notice Implements the OR (|) bitwise operation in the SD59x18 type.
function or(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
result = wrap(x.unwrap() | y.unwrap());
}
/// @notice Implements the right shift operation (>>) in the SD59x18 type.
function rshift(SD59x18 x, uint256 bits) pure returns (SD59x18 result) {
result = wrap(x.unwrap() >> bits);
}
/// @notice Implements the checked subtraction operation (-) in the SD59x18 type.
function sub(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
result = wrap(x.unwrap() - y.unwrap());
}
/// @notice Implements the checked unary minus operation (-) in the SD59x18 type.
function unary(SD59x18 x) pure returns (SD59x18 result) {
result = wrap(-x.unwrap());
}
/// @notice Implements the unchecked addition operation (+) in the SD59x18 type.
function uncheckedAdd(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
unchecked {
result = wrap(x.unwrap() + y.unwrap());
}
}
/// @notice Implements the unchecked subtraction operation (-) in the SD59x18 type.
function uncheckedSub(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
unchecked {
result = wrap(x.unwrap() - y.unwrap());
}
}
/// @notice Implements the unchecked unary minus operation (-) in the SD59x18 type.
function uncheckedUnary(SD59x18 x) pure returns (SD59x18 result) {
unchecked {
result = wrap(-x.unwrap());
}
}
/// @notice Implements the XOR (^) bitwise operation in the SD59x18 type.
function xor(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
result = wrap(x.unwrap() ^ y.unwrap());
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Errors.sol" as CastingErrors;
import { MAX_UINT128, MAX_UINT40 } from "../Common.sol";
import { uMAX_SD1x18, uMIN_SD1x18 } from "../sd1x18/Constants.sol";
import { SD1x18 } from "../sd1x18/ValueType.sol";
import { uMAX_SD21x18, uMIN_SD21x18 } from "../sd21x18/Constants.sol";
import { SD21x18 } from "../sd21x18/ValueType.sol";
import { uMAX_UD2x18 } from "../ud2x18/Constants.sol";
import { UD2x18 } from "../ud2x18/ValueType.sol";
import { uMAX_UD21x18 } from "../ud21x18/Constants.sol";
import { UD21x18 } from "../ud21x18/ValueType.sol";
import { UD60x18 } from "../ud60x18/ValueType.sol";
import { SD59x18 } from "./ValueType.sol";
/// @notice Casts an SD59x18 number into int256.
/// @dev This is basically a functional alias for {unwrap}.
function intoInt256(SD59x18 x) pure returns (int256 result) {
result = SD59x18.unwrap(x);
}
/// @notice Casts an SD59x18 number into SD1x18.
/// @dev Requirements:
/// - x ≥ uMIN_SD1x18
/// - x ≤ uMAX_SD1x18
function intoSD1x18(SD59x18 x) pure returns (SD1x18 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < uMIN_SD1x18) {
revert CastingErrors.PRBMath_SD59x18_IntoSD1x18_Underflow(x);
}
if (xInt > uMAX_SD1x18) {
revert CastingErrors.PRBMath_SD59x18_IntoSD1x18_Overflow(x);
}
result = SD1x18.wrap(int64(xInt));
}
/// @notice Casts an SD59x18 number into SD21x18.
/// @dev Requirements:
/// - x ≥ uMIN_SD21x18
/// - x ≤ uMAX_SD21x18
function intoSD21x18(SD59x18 x) pure returns (SD21x18 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < uMIN_SD21x18) {
revert CastingErrors.PRBMath_SD59x18_IntoSD21x18_Underflow(x);
}
if (xInt > uMAX_SD21x18) {
revert CastingErrors.PRBMath_SD59x18_IntoSD21x18_Overflow(x);
}
result = SD21x18.wrap(int128(xInt));
}
/// @notice Casts an SD59x18 number into UD2x18.
/// @dev Requirements:
/// - x ≥ 0
/// - x ≤ uMAX_UD2x18
function intoUD2x18(SD59x18 x) pure returns (UD2x18 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUD2x18_Underflow(x);
}
if (xInt > int256(uint256(uMAX_UD2x18))) {
revert CastingErrors.PRBMath_SD59x18_IntoUD2x18_Overflow(x);
}
result = UD2x18.wrap(uint64(uint256(xInt)));
}
/// @notice Casts an SD59x18 number into UD21x18.
/// @dev Requirements:
/// - x ≥ 0
/// - x ≤ uMAX_UD21x18
function intoUD21x18(SD59x18 x) pure returns (UD21x18 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUD21x18_Underflow(x);
}
if (xInt > int256(uint256(uMAX_UD21x18))) {
revert CastingErrors.PRBMath_SD59x18_IntoUD21x18_Overflow(x);
}
result = UD21x18.wrap(uint128(uint256(xInt)));
}
/// @notice Casts an SD59x18 number into UD60x18.
/// @dev Requirements:
/// - x ≥ 0
function intoUD60x18(SD59x18 x) pure returns (UD60x18 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUD60x18_Underflow(x);
}
result = UD60x18.wrap(uint256(xInt));
}
/// @notice Casts an SD59x18 number into uint256.
/// @dev Requirements:
/// - x ≥ 0
function intoUint256(SD59x18 x) pure returns (uint256 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUint256_Underflow(x);
}
result = uint256(xInt);
}
/// @notice Casts an SD59x18 number into uint128.
/// @dev Requirements:
/// - x ≥ 0
/// - x ≤ uMAX_UINT128
function intoUint128(SD59x18 x) pure returns (uint128 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUint128_Underflow(x);
}
if (xInt > int256(uint256(MAX_UINT128))) {
revert CastingErrors.PRBMath_SD59x18_IntoUint128_Overflow(x);
}
result = uint128(uint256(xInt));
}
/// @notice Casts an SD59x18 number into uint40.
/// @dev Requirements:
/// - x ≥ 0
/// - x ≤ MAX_UINT40
function intoUint40(SD59x18 x) pure returns (uint40 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUint40_Underflow(x);
}
if (xInt > int256(uint256(MAX_UINT40))) {
revert CastingErrors.PRBMath_SD59x18_IntoUint40_Overflow(x);
}
result = uint40(uint256(xInt));
}
/// @notice Alias for {wrap}.
function sd(int256 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(x);
}
/// @notice Alias for {wrap}.
function sd59x18(int256 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(x);
}
/// @notice Unwraps an SD59x18 number into int256.
function unwrap(SD59x18 x) pure returns (int256 result) {
result = SD59x18.unwrap(x);
}
/// @notice Wraps an int256 number into SD59x18.
function wrap(int256 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(x);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "../Common.sol" as Common;
import "./Errors.sol" as CastingErrors;
import { SD59x18 } from "../sd59x18/ValueType.sol";
import { UD60x18 } from "../ud60x18/ValueType.sol";
import { SD21x18 } from "./ValueType.sol";
/// @notice Casts an SD21x18 number into SD59x18.
/// @dev There is no overflow check because SD21x18 ⊆ SD59x18.
function intoSD59x18(SD21x18 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(int256(SD21x18.unwrap(x)));
}
/// @notice Casts an SD21x18 number into UD60x18.
/// @dev Requirements:
/// - x ≥ 0
function intoUD60x18(SD21x18 x) pure returns (UD60x18 result) {
int128 xInt = SD21x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD21x18_ToUD60x18_Underflow(x);
}
result = UD60x18.wrap(uint128(xInt));
}
/// @notice Casts an SD21x18 number into uint128.
/// @dev Requirements:
/// - x ≥ 0
function intoUint128(SD21x18 x) pure returns (uint128 result) {
int128 xInt = SD21x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD21x18_ToUint128_Underflow(x);
}
result = uint128(xInt);
}
/// @notice Casts an SD21x18 number into uint256.
/// @dev Requirements:
/// - x ≥ 0
function intoUint256(SD21x18 x) pure returns (uint256 result) {
int128 xInt = SD21x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD21x18_ToUint256_Underflow(x);
}
result = uint256(uint128(xInt));
}
/// @notice Casts an SD21x18 number into uint40.
/// @dev Requirements:
/// - x ≥ 0
/// - x ≤ MAX_UINT40
function intoUint40(SD21x18 x) pure returns (uint40 result) {
int128 xInt = SD21x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD21x18_ToUint40_Underflow(x);
}
if (xInt > int128(uint128(Common.MAX_UINT40))) {
revert CastingErrors.PRBMath_SD21x18_ToUint40_Overflow(x);
}
result = uint40(uint128(xInt));
}
/// @notice Alias for {wrap}.
function sd21x18(int128 x) pure returns (SD21x18 result) {
result = SD21x18.wrap(x);
}
/// @notice Unwraps an SD21x18 number into int128.
function unwrap(SD21x18 x) pure returns (int128 result) {
result = SD21x18.unwrap(x);
}
/// @notice Wraps an int128 number into SD21x18.
function wrap(int128 x) pure returns (SD21x18 result) {
result = SD21x18.wrap(x);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "../Common.sol" as Common;
import "./Errors.sol" as CastingErrors;
import { SD59x18 } from "../sd59x18/ValueType.sol";
import { UD60x18 } from "../ud60x18/ValueType.sol";
import { SD1x18 } from "./ValueType.sol";
/// @notice Casts an SD1x18 number into SD59x18.
/// @dev There is no overflow check because SD1x18 ⊆ SD59x18.
function intoSD59x18(SD1x18 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(int256(SD1x18.unwrap(x)));
}
/// @notice Casts an SD1x18 number into UD60x18.
/// @dev Requirements:
/// - x ≥ 0
function intoUD60x18(SD1x18 x) pure returns (UD60x18 result) {
int64 xInt = SD1x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD1x18_ToUD60x18_Underflow(x);
}
result = UD60x18.wrap(uint64(xInt));
}
/// @notice Casts an SD1x18 number into uint128.
/// @dev Requirements:
/// - x ≥ 0
function intoUint128(SD1x18 x) pure returns (uint128 result) {
int64 xInt = SD1x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD1x18_ToUint128_Underflow(x);
}
result = uint128(uint64(xInt));
}
/// @notice Casts an SD1x18 number into uint256.
/// @dev Requirements:
/// - x ≥ 0
function intoUint256(SD1x18 x) pure returns (uint256 result) {
int64 xInt = SD1x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD1x18_ToUint256_Underflow(x);
}
result = uint256(uint64(xInt));
}
/// @notice Casts an SD1x18 number into uint40.
/// @dev Requirements:
/// - x ≥ 0
/// - x ≤ MAX_UINT40
function intoUint40(SD1x18 x) pure returns (uint40 result) {
int64 xInt = SD1x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD1x18_ToUint40_Underflow(x);
}
if (xInt > int64(uint64(Common.MAX_UINT40))) {
revert CastingErrors.PRBMath_SD1x18_ToUint40_Overflow(x);
}
result = uint40(uint64(xInt));
}
/// @notice Alias for {wrap}.
function sd1x18(int64 x) pure returns (SD1x18 result) {
result = SD1x18.wrap(x);
}
/// @notice Unwraps an SD1x18 number into int64.
function unwrap(SD1x18 x) pure returns (int64 result) {
result = SD1x18.unwrap(x);
}
/// @notice Wraps an int64 number into SD1x18.
function wrap(int64 x) pure returns (SD1x18 result) {
result = SD1x18.wrap(x);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { UD2x18 } from "./ValueType.sol";
/// @notice Thrown when trying to cast a UD2x18 number that doesn't fit in uint40.
error PRBMath_UD2x18_IntoUint40_Overflow(UD2x18 x);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { UD21x18 } from "./ValueType.sol";
/// @notice Thrown when trying to cast a UD21x18 number that doesn't fit in uint40.
error PRBMath_UD21x18_IntoUint40_Overflow(UD21x18 x);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { SD59x18 } from "./ValueType.sol";
/// @notice Thrown when taking the absolute value of `MIN_SD59x18`.
error PRBMath_SD59x18_Abs_MinSD59x18();
/// @notice Thrown when ceiling a number overflows SD59x18.
error PRBMath_SD59x18_Ceil_Overflow(SD59x18 x);
/// @notice Thrown when converting a basic integer to the fixed-point format overflows SD59x18.
error PRBMath_SD59x18_Convert_Overflow(int256 x);
/// @notice Thrown when converting a basic integer to the fixed-point format underflows SD59x18.
error PRBMath_SD59x18_Convert_Underflow(int256 x);
/// @notice Thrown when dividing two numbers and one of them is `MIN_SD59x18`.
error PRBMath_SD59x18_Div_InputTooSmall();
/// @notice Thrown when dividing two numbers and one of the intermediary unsigned results overflows SD59x18.
error PRBMath_SD59x18_Div_Overflow(SD59x18 x, SD59x18 y);
/// @notice Thrown when taking the natural exponent of a base greater than 133_084258667509499441.
error PRBMath_SD59x18_Exp_InputTooBig(SD59x18 x);
/// @notice Thrown when taking the binary exponent of a base greater than 192e18.
error PRBMath_SD59x18_Exp2_InputTooBig(SD59x18 x);
/// @notice Thrown when flooring a number underflows SD59x18.
error PRBMath_SD59x18_Floor_Underflow(SD59x18 x);
/// @notice Thrown when taking the geometric mean of two numbers and their product is negative.
error PRBMath_SD59x18_Gm_NegativeProduct(SD59x18 x, SD59x18 y);
/// @notice Thrown when taking the geometric mean of two numbers and multiplying them overflows SD59x18.
error PRBMath_SD59x18_Gm_Overflow(SD59x18 x, SD59x18 y);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in SD1x18.
error PRBMath_SD59x18_IntoSD1x18_Overflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in SD1x18.
error PRBMath_SD59x18_IntoSD1x18_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in SD21x18.
error PRBMath_SD59x18_IntoSD21x18_Overflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in SD21x18.
error PRBMath_SD59x18_IntoSD21x18_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in UD2x18.
error PRBMath_SD59x18_IntoUD2x18_Overflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in UD2x18.
error PRBMath_SD59x18_IntoUD2x18_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in UD21x18.
error PRBMath_SD59x18_IntoUD21x18_Overflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in UD21x18.
error PRBMath_SD59x18_IntoUD21x18_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in UD60x18.
error PRBMath_SD59x18_IntoUD60x18_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in uint128.
error PRBMath_SD59x18_IntoUint128_Overflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in uint128.
error PRBMath_SD59x18_IntoUint128_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in uint256.
error PRBMath_SD59x18_IntoUint256_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in uint40.
error PRBMath_SD59x18_IntoUint40_Overflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in uint40.
error PRBMath_SD59x18_IntoUint40_Underflow(SD59x18 x);
/// @notice Thrown when taking the logarithm of a number less than or equal to zero.
error PRBMath_SD59x18_Log_InputTooSmall(SD59x18 x);
/// @notice Thrown when multiplying two numbers and one of the inputs is `MIN_SD59x18`.
error PRBMath_SD59x18_Mul_InputTooSmall();
/// @notice Thrown when multiplying two numbers and the intermediary absolute result overflows SD59x18.
error PRBMath_SD59x18_Mul_Overflow(SD59x18 x, SD59x18 y);
/// @notice Thrown when raising a number to a power and the intermediary absolute result overflows SD59x18.
error PRBMath_SD59x18_Powu_Overflow(SD59x18 x, uint256 y);
/// @notice Thrown when taking the square root of a negative number.
error PRBMath_SD59x18_Sqrt_NegativeInput(SD59x18 x);
/// @notice Thrown when the calculating the square root overflows SD59x18.
error PRBMath_SD59x18_Sqrt_Overflow(SD59x18 x);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { SD21x18 } from "./ValueType.sol";
/// @notice Thrown when trying to cast an SD21x18 number that doesn't fit in uint128.
error PRBMath_SD21x18_ToUint128_Underflow(SD21x18 x);
/// @notice Thrown when trying to cast an SD21x18 number that doesn't fit in UD60x18.
error PRBMath_SD21x18_ToUD60x18_Underflow(SD21x18 x);
/// @notice Thrown when trying to cast an SD21x18 number that doesn't fit in uint256.
error PRBMath_SD21x18_ToUint256_Underflow(SD21x18 x);
/// @notice Thrown when trying to cast an SD21x18 number that doesn't fit in uint40.
error PRBMath_SD21x18_ToUint40_Overflow(SD21x18 x);
/// @notice Thrown when trying to cast an SD21x18 number that doesn't fit in uint40.
error PRBMath_SD21x18_ToUint40_Underflow(SD21x18 x);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { SD1x18 } from "./ValueType.sol";
/// @notice Thrown when trying to cast an SD1x18 number that doesn't fit in UD60x18.
error PRBMath_SD1x18_ToUD60x18_Underflow(SD1x18 x);
/// @notice Thrown when trying to cast an SD1x18 number that doesn't fit in uint128.
error PRBMath_SD1x18_ToUint128_Underflow(SD1x18 x);
/// @notice Thrown when trying to cast an SD1x18 number that doesn't fit in uint256.
error PRBMath_SD1x18_ToUint256_Underflow(SD1x18 x);
/// @notice Thrown when trying to cast an SD1x18 number that doesn't fit in uint40.
error PRBMath_SD1x18_ToUint40_Overflow(SD1x18 x);
/// @notice Thrown when trying to cast an SD1x18 number that doesn't fit in uint40.
error PRBMath_SD1x18_ToUint40_Underflow(SD1x18 x);{
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"remappings": []
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"referral_","type":"address"},{"internalType":"address","name":"project_","type":"address"},{"internalType":"address","name":"lpAddress_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"},{"internalType":"uint256","name":"y","type":"uint256"}],"name":"PRBMath_MulDiv18_Overflow","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint40","name":"timestamp","type":"uint40"},{"indexed":false,"internalType":"uint256","name":"index","type":"uint256"}],"name":"Restaked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint160","name":"reward","type":"uint160"},{"indexed":false,"internalType":"uint40","name":"timestamp","type":"uint40"},{"indexed":false,"internalType":"uint256","name":"index","type":"uint256"}],"name":"RewardPaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint160","name":"amount","type":"uint160"},{"indexed":false,"internalType":"uint40","name":"timestamp","type":"uint40"},{"indexed":false,"internalType":"uint256","name":"index","type":"uint256"},{"indexed":false,"internalType":"uint40","name":"stakeTime","type":"uint40"}],"name":"Staked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint160","name":"amount","type":"uint160"},{"indexed":false,"internalType":"uint40","name":"timestamp","type":"uint40"},{"indexed":false,"internalType":"uint256","name":"index","type":"uint256"},{"indexed":false,"internalType":"uint160","name":"reward","type":"uint160"},{"indexed":false,"internalType":"uint40","name":"ttl","type":"uint40"}],"name":"Unstaked","type":"event"},{"inputs":[],"name":"LAX","outputs":[{"internalType":"contract ILAXToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LAXO","outputs":[{"internalType":"contract ILAXOToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MIN_STAKE_AMOUNT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PROJECT","outputs":[{"internalType":"contract IProject","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"QUEUE","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REFERRAL","outputs":[{"internalType":"contract IReferral","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balances","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"_index","type":"uint256"}],"name":"claimFor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"configs","outputs":[{"internalType":"uint256","name":"rate","type":"uint256"},{"internalType":"uint40","name":"day","type":"uint40"},{"internalType":"uint40","name":"ttl","type":"uint40"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"dividendAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ecosystemAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"emergencyWithdrawLAX","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getStakeRecord","outputs":[{"components":[{"internalType":"uint40","name":"stakeTime","type":"uint40"},{"internalType":"uint160","name":"amount","type":"uint160"},{"internalType":"uint8","name":"stakeIndex","type":"uint8"},{"internalType":"uint40","name":"unstakeTime","type":"uint40"},{"internalType":"uint160","name":"reward","type":"uint160"},{"internalType":"uint40","name":"restakeTime","type":"uint40"}],"internalType":"struct IStaking.Record","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"}],"name":"getTeamKpi","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"isPreacher","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lpAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"marketingAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"_index","type":"uint256"},{"internalType":"uint160","name":"_amount","type":"uint160"},{"internalType":"uint8","name":"_stakeIndex","type":"uint8"}],"name":"restakeFor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint8","name":"index","type":"uint8"}],"name":"rewardOfSlot","outputs":[{"internalType":"uint256","name":"reward","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_lax","type":"address"}],"name":"setLAX","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_laxo","type":"address"}],"name":"setLAXO","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_lpAddress","type":"address"}],"name":"setLpAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_project","type":"address"}],"name":"setProject","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_queue","type":"address"}],"name":"setQueue","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"setTeamVirtuallyInvestValue","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"stakeCount","outputs":[{"internalType":"uint256","name":"count","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint160","name":"amount","type":"uint160"},{"internalType":"uint8","name":"stakeIndex","type":"uint8"}],"name":"stakeFor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"sync","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"teamTotalInvestValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"teamVirtuallyInvestValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"unstakeFor","outputs":[{"internalType":"uint256","name":"actualAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userOneDayStaked","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"userStakeRecord","outputs":[{"internalType":"uint40","name":"stakeTime","type":"uint40"},{"internalType":"uint160","name":"amount","type":"uint160"},{"internalType":"uint8","name":"stakeIndex","type":"uint8"},{"internalType":"uint40","name":"unstakeTime","type":"uint40"},{"internalType":"uint160","name":"reward","type":"uint160"},{"internalType":"uint40","name":"restakeTime","type":"uint40"}],"stateMutability":"view","type":"function"}]Contract Creation Code
60a0604052606460805234801562000015575f80fd5b5060405162003ddf38038062003ddf833981016040819052620000389162000311565b5f80546001600160a01b031916339081178255604051909182917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3506001600160a01b038316620000c45760405162461bcd60e51b815260206004820152600d60248201526c1e995c9bc81c9959995c9c985b609a1b60448201526064015b60405180910390fd5b6001600160a01b0382166200010b5760405162461bcd60e51b815260206004820152600c60248201526b1e995c9bc81c1c9bda9958dd60a21b6044820152606401620000bb565b6001600160a01b038116620001555760405162461bcd60e51b815260206004820152600f60248201526e7a65726f206c70206164647265737360881b6044820152606401620000bb565b600380546001600160a01b038581166001600160a01b03199283161790925560048054858416908316178155600680549385169390921692909217905560405163095ea7b360e01b81527310ed43c718714eb63d5aa57b78b54704e256024e918101919091525f1960248201527355d398326f99059ff775485246999027b31979559063095ea7b3906044016020604051808303815f875af1158015620001fe573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019062000224919062000358565b50506040805160608082018352670de0b6bbb9e544c0808352620151806020808501919091526202a300938501849052600791909155600880546001600160501b03199081166702a30000000151801790915584518084018652670de0b6c3c63b40a08082526213c68082850152908601859052600955600a805482166702a300000013c68017905584519283018552670de0b6d3cc89fcc080845262278d00928401929092529190930191909152600b91909155600c80549091166702a3000000278d0017905550620003809050565b80516001600160a01b03811681146200030c575f80fd5b919050565b5f805f6060848603121562000324575f80fd5b6200032f84620002f5565b92506200033f60208501620002f5565b91506200034f60408501620002f5565b90509250925092565b5f6020828403121562000369575f80fd5b8151801515811462000379575f80fd5b9392505050565b608051613a38620003a75f395f8181610aa1015281816124bd01526128210152613a385ff3fe608060405234801561000f575f80fd5b506004361061023e575f3560e01c80636a72a75311610135578063ad567450116100b4578063f3ee7e2c11610079578063f3ee7e2c14610613578063f4fdf73214610626578063fb108ea614610639578063ffe58f091461064c578063fff6cae91461065f575f80fd5b8063ad56745014610541578063b108b4cb14610554578063c63568c714610573578063e8b2b0e014610586578063f2fde38b14610600575f80fd5b806395d89b41116100fa57806395d89b41146102be57806396e256bf146105005780639b4dc8cc14610513578063a5ece94114610526578063aca2b9621461052e575f80fd5b80636a72a753146104a25780636f5e0212146104b557806370a08231146104c857806386eb0e7f146104db5780638da5cb5b146104ee575f80fd5b8063274d3b7f116101c157806336ef088c1161018657806336ef088c146104425780634b413c2a14610455578063546d08fe14610474578063553ecc061461047c57806359f0c0e71461048f575f80fd5b8063274d3b7f146103a057806327e235e3146103d257806327ed7188146103f1578063313ce5671461040057806333060d901461041a575f80fd5b80630de05659116102075780630de0565914610349578063119b99f21461035e5780631714d7f31461037157806318160ddd146103845780631a3d203d1461038d575f80fd5b806298fa2214610242578063069a8f2d1461027d57806306a5cb3a1461029e57806306fdde03146102be57806308adb4be146102ee575b5f80fd5b610255610250366004613426565b610667565b6040805193845264ffffffffff92831660208501529116908201526060015b60405180910390f35b61029061028b366004613466565b61069a565b604051908152602001610274565b6102a66106ea565b6040516001600160a01b039091168152602001610274565b6102e1604051806040016040528060048152602001634c41585560e01b81525081565b6040516102749190613499565b6103016102fc3660046134e4565b610764565b6040805164ffffffffff97881681526001600160a01b03968716602082015260ff909516908501529185166060840152929092166080820152911660a082015260c001610274565b61035c6103573660046134e4565b6107d7565b005b61035c61036c3660046134e4565b610a02565b6004546102a6906001600160a01b031681565b610290600d5481565b6005546102a6906001600160a01b031681565b6103c26103ae36600461350e565b60126020525f908152604090205460ff1681565b6040519015158152602001610274565b6102906103e036600461350e565b600e6020525f908152604090205481565b610290670de0b6b3a764000081565b610408601281565b60405160ff9091168152602001610274565b61029061042836600461350e565b6001600160a01b03165f908152600f602052604090205490565b6102906104503660046134e4565b610a46565b61029061046336600461350e565b60116020525f908152604090205481565b6102a6610c89565b6001546102a6906001600160a01b031681565b6103c261049d36600461350e565b610cda565b61035c6104b036600461350e565b610d00565b61035c6104c336600461350e565b610d4b565b6102906104d636600461350e565b610ddb565b61035c6104e9366004613529565b610e85565b5f546102a6906001600160a01b031681565b6002546102a6906001600160a01b031681565b6006546102a6906001600160a01b031681565b6102a661119e565b61035c61053c3660046134e4565b6111ef565b61035c61054f366004613577565b61128f565b61029061056236600461350e565b60106020525f908152604090205481565b6003546102a6906001600160a01b031681565b6105996105943660046134e4565b611497565b6040516102749190815164ffffffffff90811682526020808401516001600160a01b039081169184019190915260408085015160ff16908401526060808501518316908401526080808501519091169083015260a092830151169181019190915260c00190565b61035c61060e36600461350e565b611572565b61035c61062136600461350e565b6115e5565b61029061063436600461350e565b611630565b61035c61064736600461350e565b61165d565b61035c61065a36600461350e565b6116ed565b61035c6117b0565b60078160038110610676575f80fd5b60020201805460019091015490915064ffffffffff80821691600160281b90041683565b6001600160a01b0382165f908152600f60205260408120805482919060ff85169081106106c9576106c96135bb565b905f5260205f20906002020190506106e0816119cd565b9150505b92915050565b5f60045f9054906101000a90046001600160a01b03166001600160a01b03166306a5cb3a6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561073b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061075f91906135cf565b905090565b600f602052815f5260405f20818154811061077d575f80fd5b5f9182526020909120600290910201805460019091015464ffffffffff80831694506001600160a01b03600160281b84048116945060ff600160c81b85041693600160d01b900482169290811691600160a01b9091041686565b6005546001600160a01b0316331461080a5760405162461bcd60e51b8152600401610801906135ea565b60405180910390fd5b6001600160a01b0382165f908152600f60205260408120805483908110610833576108336135bb565b5f918252602090912060029091020160018101549091506001600160a01b031661088b5760405162461bcd60e51b81526020600482015260096024820152681b9bc81c995dd85c9960ba1b6044820152606401610801565b80545f90600790600160c81b900460ff16600381106108ac576108ac6135bb565b60408051606081018252600292909202929092018054825260019081015464ffffffffff8082166020850152600160281b909104811693830193909352840154909250600160a01b9004161580159061093b57506040810151825461091f9190600160d01b900464ffffffffff1661362b565b600183015464ffffffffff918216600160a01b90910490911611155b61097e5760405162461bcd60e51b81526020600482015260146024820152736e6f742072657374616b656420696e2074696d6560601b6044820152606401610801565b6001820180546001600160a01b031981169091556001600160a01b03166109a58582611a9c565b604080516001600160a01b03838116825264ffffffffff42166020830152918101869052908616907f2b3ca68148d94d2c4f4e619c0125be1a33866e18aa56e0195aa4793107950f11906060015b60405180910390a25050505050565b5f546001600160a01b03163314610a2b5760405162461bcd60e51b815260040161080190613650565b6001600160a01b039091165f90815260116020526040902055565b6005545f906001600160a01b03163314610a725760405162461bcd60e51b8152600401610801906135ea565b5f610a7d8484611bee565b60035460405163195006c760e11b81526001600160a01b03898116600483015260ff7f00000000000000000000000000000000000000000000000000000000000000001660248301529296509294505f935016906332a00d8e906044015f60405180830381865afa158015610af4573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052610b1b91908101906136de565b90505f5b81518160ff161015610b91578260105f848460ff1681518110610b4457610b446135bb565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020015f205f828254610b799190613778565b90915550819050610b898161378b565b915050610b1f565b50825f03610ba3575f925050506106e4565b5f80610bae85611ece565b60405163a9059cbb60e01b815291935091505f805160206139e38339815191529063a9059cbb90610be5908a9086906004016137a9565b6020604051808303815f875af1158015610c01573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c2591906137c2565b506001546040516337470d6f60e21b8152600481018390526001600160a01b039091169063dd1c35bc906024015f604051808303815f87803b158015610c69575f80fd5b505af1158015610c7b573d5f803e3d5ffd5b505050505050505092915050565b5f60045f9054906101000a90046001600160a01b03166001600160a01b031663b0e011646040518163ffffffff1660e01b8152600401602060405180830381865afa15801561073b573d5f803e3d5ffd5b6001600160a01b03165f908152600e6020526040902054680ac9ae05a71ebc0000111590565b5f546001600160a01b03163314610d295760405162461bcd60e51b815260040161080190613650565b600280546001600160a01b0319166001600160a01b0392909216919091179055565b5f546001600160a01b03163314610d745760405162461bcd60e51b815260040161080190613650565b6001600160a01b038116610db95760405162461bcd60e51b815260206004820152600c60248201526b7a65726f206164647265737360a01b6044820152606401610801565b600680546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b0381165f908152600f60205260408120805415610e7f5780545f90610e0990600190613778565b90505b5f828281548110610e1f57610e1f6135bb565b5f91825260208220600290910201805490925064ffffffffff600160d01b909104169003610e5d57610e50816119cd565b610e5a90856137e1565b93505b815f03610e6a5750610e7d565b5080610e75816137f4565b915050610e0c565b505b50919050565b6005546001600160a01b03163314610eaf5760405162461bcd60e51b8152600401610801906135ea565b670de0b6b3a7640000826001600160a01b03161015610f055760405162461bcd60e51b81526020600482015260126024820152710f8f53525397d4d51052d157d05353d5539560721b6044820152606401610801565b60038160ff1610610f4d5760405162461bcd60e51b8152602060048201526012602482015271696e646578206f7574206f662072616e676560701b6044820152606401610801565b5f8160ff1611610f985760405162461bcd60e51b815260206004820152601660248201527572657374616b652063616e6e6f74206265203164617960501b6044820152606401610801565b6001600160a01b0384165f908152600f60205260408120805485908110610fc157610fc16135bb565b5f91825260209091206002909102018054909150600160d01b900464ffffffffff1661101e5760405162461bcd60e51b815260206004820152600c60248201526b1b9bdd081d5b9cdd185ad95960a21b6044820152606401610801565b6001810154600160a01b900464ffffffffff16156110715760405162461bcd60e51b815260206004820152601060248201526f185b1c9958591e481c995cdd185ad95960821b6044820152606401610801565b80546001600160a01b03600160281b909104811690841610156110c95760405162461bcd60e51b815260206004820152601060248201526f185b5bdd5b9d081d1bdbc81cdb585b1b60821b6044820152606401610801565b805460ff600160c81b909104811690831610156111205760405162461bcd60e51b81526020600482015260156024820152741cdd185ad9481a5b99195e081d1bdbc81cdb585b1b605a1b6044820152606401610801565b611129836121c7565b60018101805464ffffffffff60a01b1916600160a01b4264ffffffffff160217905561115685848461234f565b6040805164ffffffffff42168152602081018690526001600160a01b038716917f22ea4d12074016dab9862b37c4e634b11084494dbeb71ef9af7c5b33b5511c1f91016109f3565b5f60045f9054906101000a90046001600160a01b03166001600160a01b031663a5ece9416040518163ffffffff1660e01b8152600401602060405180830381865afa15801561073b573d5f803e3d5ffd5b5f546001600160a01b031633146112185760405162461bcd60e51b815260040161080190613650565b60015460405163a9059cbb60e01b81526001600160a01b039091169063a9059cbb9061124a90859085906004016137a9565b6020604051808303815f875af1158015611266573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061128a91906137c2565b505050565b6005546001600160a01b031633146112b95760405162461bcd60e51b8152600401610801906135ea565b670de0b6b3a7640000826001600160a01b0316101561130f5760405162461bcd60e51b81526020600482015260126024820152710f8f53525397d4d51052d157d05353d5539560721b6044820152606401610801565b60038160ff16106113575760405162461bcd60e51b8152602060048201526012602482015271696e646578206f7574206f662072616e676560701b6044820152606401610801565b600354604051633bb1db8160e21b81526001600160a01b0385811660048301529091169063eec76e0490602401602060405180830381865afa15801561139f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906113c391906137c2565b6113f85760405162461bcd60e51b81526020600482015260066024820152650848589a5b9960d21b6044820152606401610801565b8060ff165f03611483576001600160a01b0383165f9081526012602052604090205460ff16156114605760405162461bcd60e51b81526020600482015260136024820152720c59185e48185b1c9958591e481cdd185ad959606a1b6044820152606401610801565b6001600160a01b0383165f908152601260205260409020805460ff191660011790555b61148c826121c7565b61128a83838361234f565b6040805160c0810182525f8082526020808301829052828401829052606083018290526080830182905260a083018290526001600160a01b0386168252600f9052919091208054839081106114ee576114ee6135bb565b5f9182526020918290206040805160c0810182526002909302909101805464ffffffffff80821685526001600160a01b03600160281b830481169686019690965260ff600160c81b83041693850193909352600160d01b900482166060840152600101549283166080830152600160a01b90920490911660a0820152905092915050565b5f546001600160a01b0316331461159b5760405162461bcd60e51b815260040161080190613650565b5f80546001600160a01b0319166001600160a01b0383169081178255604051909133917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a350565b5f546001600160a01b0316331461160e5760405162461bcd60e51b815260040161080190613650565b600580546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b0381165f9081526011602090815260408083205460109092528220546106e491906137e1565b5f546001600160a01b031633146116865760405162461bcd60e51b815260040161080190613650565b6001600160a01b0381166116cb5760405162461bcd60e51b815260206004820152600c60248201526b7a65726f206164647265737360a01b6044820152606401610801565b600480546001600160a01b0319166001600160a01b0392909216919091179055565b5f546001600160a01b031633146117165760405162461bcd60e51b815260040161080190613650565b600180546001600160a01b0319166001600160a01b03831690811790915560405163095ea7b360e01b815263095ea7b39061176c907310ed43c718714eb63d5aa57b78b54704e256024e905f19906004016137a9565b6020604051808303815f875af1158015611788573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117ac91906137c2565b5050565b5f546001600160a01b03163314806117e057506117cb61119e565b6001600160a01b0316336001600160a01b0316145b6118225760405162461bcd60e51b8152602060048201526013602482015272216f776e6572206f72206d61726b6574696e6760681b6044820152606401610801565b6040516370a0823160e01b81523060048201525f905f805160206139e3833981519152906370a0823190602401602060405180830381865afa15801561186a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061188e9190613809565b90505f60015f9054906101000a90046001600160a01b03166001600160a01b03166349bd5a5e6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156118e1573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061190591906135cf565b60405163a9059cbb60e01b81529091505f805160206139e38339815191529063a9059cbb9061193a90849086906004016137a9565b6020604051808303815f875af1158015611956573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061197a91906137c2565b50806001600160a01b031663fff6cae96040518163ffffffff1660e01b81526004015f604051808303815f87803b1580156119b3575f80fd5b505af11580156119c5573d5f803e3d5ffd5b505050505050565b80545f906001600160a01b03600160281b8204169064ffffffffff16826119f48242613820565b8554909150611a30908290600790600160c81b900460ff1660038110611a1c57611a1c6135bb565b600202016001015464ffffffffff16612681565b90508064ffffffffff165f03611a4857829350611a94565b8454611a9190611a8a9064ffffffffff841690611a8490600790600160c81b900460ff1660038110611a7c57611a7c6135bb565b600202015490565b906126a6565b8490612707565b93505b505050919050565b5f80611ab0836001600160a01b0316611ece565b90925090505f6103e8611ac484603261383e565b611ace9190613869565b9050611ad981612718565b5f6103e8611ae98561015e61383e565b611af39190613869565b9050611aff86826127fd565b505f81611b0c8487613778565b611b169190613778565b60405163a9059cbb60e01b81529091505f805160206139e38339815191529063a9059cbb90611b4b908a9085906004016137a9565b6020604051808303815f875af1158015611b67573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b8b91906137c2565b506001546040516337470d6f60e21b8152600481018690526001600160a01b039091169063dd1c35bc906024015f604051808303815f87803b158015611bcf575f80fd5b505af1158015611be1573d5f803e3d5ffd5b5050505050505050505050565b6001600160a01b0382165f908152600f602052604081208054829182918290829087908110611c1f57611c1f6135bb565b5f91825260208220600290910201805490925064ffffffffff8116919060079060ff600160c81b9091041660038110611c5a57611c5a6135bb565b6040805160608101825260029290920292909201805482526001015464ffffffffff80821660208401819052600160281b909204169282019290925291505f90611ca490846137e1565b905080421015611cee5760405162461bcd60e51b8152602060048201526015602482015274151a19481d1a5b59481a5cc81b9bdd081c9a59da1d605a1b6044820152606401610801565b8354600160d01b900464ffffffffff1615611d315760405162461bcd60e51b8152602060048201526003602482015262616c7760e81b6044820152606401610801565b8354600160281b90046001600160a01b031696505f611d4f82613058565b90506064611d5d8282613778565b611d67908a61383e565b611d719190613869565b965087600d5f828254611d849190613778565b90915550506001600160a01b038b165f908152600e6020526040812080548a9290611db0908490613778565b90915550506040518881525f906001600160a01b038d16907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3611dfe856119cd565b855464ffffffffff60d01b1916600160d01b4264ffffffffff1602178655985087891115611e5357611e30888a613778565b6001860180546001600160a01b0319166001600160a01b03929092169190911790555b600185015460408085015181516001600160a01b038b8116825264ffffffffff42811660208401529382018f9052938416606082015291166080820152908c16907fb0b25333efd643d6b20b95dfa2e50b21744cf2810221c85dc17334d32e35802b9060a00160405180910390a25050505050509250925092565b6001546040516370a0823160e01b81523060048201525f91829182916001600160a01b0316906370a0823190602401602060405180830381865afa158015611f18573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f3c9190613809565b6040516370a0823160e01b81523060048201529091505f905f805160206139e3833981519152906370a0823190602401602060405180830381865afa158015611f87573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611fab9190613809565b6040805160028082526060820183529293505f929091602083019080368337505060015482519293506001600160a01b0316918391505f90611fef57611fef6135bb565b60200260200101906001600160a01b031690816001600160a01b0316815250505f805160206139e383398151915281600181518110612030576120306135bb565b6001600160a01b0390921660209283029190910190910152604051634401edf760e11b81527310ed43c718714eb63d5aa57b78b54704e256024e90638803dbee9061208790899087908690309042906004016138be565b5f604051808303815f875af11580156120a2573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526120c991908101906138f9565b506001546040516370a0823160e01b81523060048201525f916001600160a01b0316906370a0823190602401602060405180830381865afa158015612110573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906121349190613809565b6040516370a0823160e01b81523060048201529091505f905f805160206139e3833981519152906370a0823190602401602060405180830381865afa15801561217f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906121a39190613809565b90506121af8286613778565b95506121bb8482613778565b96505050505050915091565b6040516323b872dd60e01b81523360048201523060248201526001600160a01b03821660448201525f805160206139e3833981519152906323b872dd906064016020604051808303815f875af1158015612223573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061224791906137c2565b505f61226561225760028461397a565b6001600160a01b03166130a4565b6001549091507310ed43c718714eb63d5aa57b78b54704e256024e9063e8e33700905f805160206139e3833981519152906001600160a01b03166122aa60028761397a565b60065460405160e086901b6001600160e01b03191681526001600160a01b03948516600482015292841660248401529083166044830152606482018690525f6084830181905260a48301529190911660c48201524260e4820152610104016060604051808303815f875af1158015612324573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612348919061399f565b5050505050565b6040805160c0810182525f606082018190526080820181905260a082018190524264ffffffffff1682526001600160a01b0385166020830181905260ff851693830193909352600d80549293929091906123aa9084906137e1565b90915550506001600160a01b038481165f908152600e602052604081208054928616929091906123db9084906137e1565b90915550506001600160a01b038481165f818152600f602090815260408083208054600180820183558286528486208951600284029091018054968b01518b87015160608d015164ffffffffff9485166001600160c81b03199a8b1617600160281b938e16939093029290921765ffffffffffff60c81b1916600160c81b60ff9283160264ffffffffff60d01b191617600160d01b9285169290920291909117825560808c015191909301805460a08d0151928c16981697909717600160a01b919092160217909455600354925163195006c760e11b815260048101969096527f000000000000000000000000000000000000000000000000000000000000000090931660248601529491939116906332a00d8e906044015f60405180830381865afa15801561250d573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405261253491908101906136de565b90505f5b81518160ff1610156125b357866001600160a01b031660105f848460ff1681518110612566576125666135bb565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020015f205f82825461259b91906137e1565b909155508190506125ab8161378b565b915050612538565b506040516001600160a01b0387811682528816905f907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3866001600160a01b03167f3a9398000906a7b3c6ab07ec3d849739a537132436f8db617248c858f632c56d87428560078a60ff166003811061263a5761263a6135bb565b6002020160010154604080516001600160a01b03909516855264ffffffffff938416602086015284019190915216606082015260800160405180910390a250505050505050565b5f8164ffffffffff168364ffffffffff161061269d578161269f565b825b9392505050565b5f8281600184166126bf57670de0b6b3a76400006126c1565b815b9050600184901c93505b83156126ff576126db828361327a565b915060018416156126f3576126f0818361327a565b90505b600184901c93506126cb565b949350505050565b5f61269f612715848461327a565b90565b805f036127225750565b6002546001600160a01b0316158015906127ab575060025f9054906101000a90046001600160a01b03166001600160a01b031663462383266040518163ffffffff1660e01b8152600401602060405180830381865afa158015612787573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906127ab91906137c2565b156127e9575f805160206139e383398151915263a9059cbb6127cb6106ea565b836040518363ffffffff1660e01b815260040161176c9291906137a9565b6127fa816127f5610c89565b61332c565b50565b60035460405163195006c760e11b81526001600160a01b03848116600483015260ff7f00000000000000000000000000000000000000000000000000000000000000001660248301525f9283929116906332a00d8e906044015f60405180830381865afa158015612870573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405261289791908101906136de565b90505f80602381805b8551811015612fa9578581815181106128bb576128bb6135bb565b602002602001015194506128ce85611630565b93506a18d0bf423c03d8de00000084101580156128ea57508183115b80156128fa57506128fa85610cda565b15612995575f805160206139e383398151915263a9059cbb868561291e8682613778565b612928908d61383e565b6129329190613869565b6040518363ffffffff1660e01b815260040161294f9291906137a9565b6020604051808303815f875af115801561296b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061298f91906137c2565b50602391505b6a084595161401484a00000084101580156129ba57506a18d0bf423c03d8de00000084105b80156129c65750602082105b80156129d657506129d685610cda565b15612a72575f805160206139e383398151915263a9059cbb86856129fb866020613778565b612a05908d61383e565b612a0f9190613869565b6040518363ffffffff1660e01b8152600401612a2c9291906137a9565b6020604051808303815f875af1158015612a48573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612a6c91906137c2565b50602091505b6a0422ca8b0a00a4250000008410158015612a9757506a084595161401484a00000084105b8015612aa35750601d82105b8015612ab35750612ab385610cda565b15612b4f575f805160206139e383398151915263a9059cbb8685612ad886601d613778565b612ae2908d61383e565b612aec9190613869565b6040518363ffffffff1660e01b8152600401612b099291906137a9565b6020604051808303815f875af1158015612b25573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612b4991906137c2565b50601d91505b69d3c21bcecceda10000008410158015612b7357506a0422ca8b0a00a42500000084105b8015612b7f5750601a82105b8015612b8f5750612b8f85610cda565b15612c2b575f805160206139e383398151915263a9059cbb8685612bb486601a613778565b612bbe908d61383e565b612bc89190613869565b6040518363ffffffff1660e01b8152600401612be59291906137a9565b6020604051808303815f875af1158015612c01573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612c2591906137c2565b50601a91505b6969e10de76676d08000008410158015612c4e575069d3c21bcecceda100000084105b8015612c5a5750601682105b8015612c6a5750612c6a85610cda565b15612d06575f805160206139e383398151915263a9059cbb8685612c8f866016613778565b612c99908d61383e565b612ca39190613869565b6040518363ffffffff1660e01b8152600401612cc09291906137a9565b6020604051808303815f875af1158015612cdc573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612d0091906137c2565b50601691505b69152d02c7e14af68000008410158015612d2957506969e10de76676d080000084105b8015612d355750601282105b8015612d455750612d4585610cda565b15612de1575f805160206139e383398151915263a9059cbb8685612d6a866012613778565b612d74908d61383e565b612d7e9190613869565b6040518363ffffffff1660e01b8152600401612d9b9291906137a9565b6020604051808303815f875af1158015612db7573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612ddb91906137c2565b50601291505b690a968163f0a57b4000008410158015612e04575069152d02c7e14af680000084105b8015612e105750600d82105b8015612e205750612e2085610cda565b15612ebc575f805160206139e383398151915263a9059cbb8685612e4586600d613778565b612e4f908d61383e565b612e599190613869565b6040518363ffffffff1660e01b8152600401612e769291906137a9565b6020604051808303815f875af1158015612e92573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612eb691906137c2565b50600d91505b69021e19e0c9bab24000008410158015612edf5750690a968163f0a57b40000084105b8015612eeb5750600782105b8015612efb5750612efb85610cda565b15612f97575f805160206139e383398151915263a9059cbb8685612f20866007613778565b612f2a908d61383e565b612f349190613869565b6040518363ffffffff1660e01b8152600401612f519291906137a9565b6020604051808303815f875af1158015612f6d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612f9191906137c2565b50600791505b80612fa1816139ca565b9150506128a0565b5081612fb5828961383e565b612fbf9190613869565b95508082111561304d575f805160206139e383398151915263a9059cbb612fe461119e565b612fee898b613778565b6040518363ffffffff1660e01b815260040161300b9291906137a9565b6020604051808303815f875af1158015613027573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061304b91906137c2565b505b505050505092915050565b5f81421161306757505f919050565b5f6130728342613778565b90505f6130826201518083613869565b905061308f81600561383e565b92506064831115610e7d575060649392505050565b6040805160028082526060820183525f92839291906020830190803683370190505090505f805160206139e3833981519152815f815181106130e8576130e86135bb565b6001600160a01b0392831660209182029290920101526001805483519216918391908110613118576131186135bb565b6001600160a01b0392831660209182029290920101526001546040516370a0823160e01b81523060048201525f9291909116906370a0823190602401602060405180830381865afa15801561316f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906131939190613809565b604051635c11d79560e01b81529091507310ed43c718714eb63d5aa57b78b54704e256024e90635c11d795906131d59087905f908790309042906004016138be565b5f604051808303815f87803b1580156131ec575f80fd5b505af11580156131fe573d5f803e3d5ffd5b50506001546040516370a0823160e01b81523060048201525f93506001600160a01b0390911691506370a0823190602401602060405180830381865afa15801561324a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061326e9190613809565b9050611a918282613778565b5f80805f19848609848602925082811083820303915050805f036132ab5750670de0b6b3a7640000900490506106e4565b670de0b6b3a764000081106132dd57604051635173648d60e01b81526004810186905260248101859052604401610801565b5f670de0b6b3a764000085870962040000818503049310909103600160ee1b02919091177faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106690291505092915050565b6040805160028082526060820183525f926020830190803683370190505090505f805160206139e3833981519152815f8151811061336c5761336c6135bb565b6001600160a01b03928316602091820292909201015260025482519116908290600190811061339d5761339d6135bb565b6001600160a01b0390921660209283029190910190910152604051635c11d79560e01b81527310ed43c718714eb63d5aa57b78b54704e256024e90635c11d795906133f49086905f908690889042906004016138be565b5f604051808303815f87803b15801561340b575f80fd5b505af115801561341d573d5f803e3d5ffd5b50505050505050565b5f60208284031215613436575f80fd5b5035919050565b6001600160a01b03811681146127fa575f80fd5b803560ff81168114613461575f80fd5b919050565b5f8060408385031215613477575f80fd5b82356134828161343d565b915061349060208401613451565b90509250929050565b5f6020808352835180828501525f5b818110156134c4578581018301518582016040015282016134a8565b505f604082860101526040601f19601f8301168501019250505092915050565b5f80604083850312156134f5575f80fd5b82356135008161343d565b946020939093013593505050565b5f6020828403121561351e575f80fd5b813561269f8161343d565b5f805f806080858703121561353c575f80fd5b84356135478161343d565b935060208501359250604085013561355e8161343d565b915061356c60608601613451565b905092959194509250565b5f805f60608486031215613589575f80fd5b83356135948161343d565b925060208401356135a48161343d565b91506135b260408501613451565b90509250925092565b634e487b7160e01b5f52603260045260245ffd5b5f602082840312156135df575f80fd5b815161269f8161343d565b60208082526013908201527237b7363c9038bab2bab29037b91037bbb732b960691b604082015260600190565b634e487b7160e01b5f52601160045260245ffd5b64ffffffffff81811683821601908082111561364957613649613617565b5092915050565b6020808252600c908201526b15539055551213d49256915160a21b604082015260600190565b634e487b7160e01b5f52604160045260245ffd5b604051601f8201601f1916810167ffffffffffffffff811182821017156136b3576136b3613676565b604052919050565b5f67ffffffffffffffff8211156136d4576136d4613676565b5060051b60200190565b5f60208083850312156136ef575f80fd5b825167ffffffffffffffff811115613705575f80fd5b8301601f81018513613715575f80fd5b8051613728613723826136bb565b61368a565b81815260059190911b82018301908381019087831115613746575f80fd5b928401925b8284101561376d57835161375e8161343d565b8252928401929084019061374b565b979650505050505050565b818103818111156106e4576106e4613617565b5f60ff821660ff81036137a0576137a0613617565b60010192915050565b6001600160a01b03929092168252602082015260400190565b5f602082840312156137d2575f80fd5b8151801515811461269f575f80fd5b808201808211156106e4576106e4613617565b5f8161380257613802613617565b505f190190565b5f60208284031215613819575f80fd5b5051919050565b64ffffffffff82811682821603908082111561364957613649613617565b80820281158282048414176106e4576106e4613617565b634e487b7160e01b5f52601260045260245ffd5b5f8261387757613877613855565b500490565b5f8151808452602080850194508084015f5b838110156138b35781516001600160a01b03168752958201959082019060010161388e565b509495945050505050565b85815284602082015260a060408201525f6138dc60a083018661387c565b6001600160a01b0394909416606083015250608001529392505050565b5f602080838503121561390a575f80fd5b825167ffffffffffffffff811115613920575f80fd5b8301601f81018513613930575f80fd5b805161393e613723826136bb565b81815260059190911b8201830190838101908783111561395c575f80fd5b928401925b8284101561376d57835182529284019290840190613961565b5f6001600160a01b038381168061399357613993613855565b92169190910492915050565b5f805f606084860312156139b1575f80fd5b8351925060208401519150604084015190509250925092565b5f600182016139db576139db613617565b506001019056fe00000000000000000000000055d398326f99059ff775485246999027b3197955a2646970667358221220bd9281e5486618a39810c402977d39edcf9d8cff13e072694d374c903206b77964736f6c634300081400330000000000000000000000001d0b57f8fdcfc237a979ff6855ac93f8462fac14000000000000000000000000171336fc55d8c0644e56a71119c8590f5cb5e2a4000000000000000000000000c4eaec128ea04f34a4c128b35112227d99b7796a
Deployed Bytecode
0x608060405234801561000f575f80fd5b506004361061023e575f3560e01c80636a72a75311610135578063ad567450116100b4578063f3ee7e2c11610079578063f3ee7e2c14610613578063f4fdf73214610626578063fb108ea614610639578063ffe58f091461064c578063fff6cae91461065f575f80fd5b8063ad56745014610541578063b108b4cb14610554578063c63568c714610573578063e8b2b0e014610586578063f2fde38b14610600575f80fd5b806395d89b41116100fa57806395d89b41146102be57806396e256bf146105005780639b4dc8cc14610513578063a5ece94114610526578063aca2b9621461052e575f80fd5b80636a72a753146104a25780636f5e0212146104b557806370a08231146104c857806386eb0e7f146104db5780638da5cb5b146104ee575f80fd5b8063274d3b7f116101c157806336ef088c1161018657806336ef088c146104425780634b413c2a14610455578063546d08fe14610474578063553ecc061461047c57806359f0c0e71461048f575f80fd5b8063274d3b7f146103a057806327e235e3146103d257806327ed7188146103f1578063313ce5671461040057806333060d901461041a575f80fd5b80630de05659116102075780630de0565914610349578063119b99f21461035e5780631714d7f31461037157806318160ddd146103845780631a3d203d1461038d575f80fd5b806298fa2214610242578063069a8f2d1461027d57806306a5cb3a1461029e57806306fdde03146102be57806308adb4be146102ee575b5f80fd5b610255610250366004613426565b610667565b6040805193845264ffffffffff92831660208501529116908201526060015b60405180910390f35b61029061028b366004613466565b61069a565b604051908152602001610274565b6102a66106ea565b6040516001600160a01b039091168152602001610274565b6102e1604051806040016040528060048152602001634c41585560e01b81525081565b6040516102749190613499565b6103016102fc3660046134e4565b610764565b6040805164ffffffffff97881681526001600160a01b03968716602082015260ff909516908501529185166060840152929092166080820152911660a082015260c001610274565b61035c6103573660046134e4565b6107d7565b005b61035c61036c3660046134e4565b610a02565b6004546102a6906001600160a01b031681565b610290600d5481565b6005546102a6906001600160a01b031681565b6103c26103ae36600461350e565b60126020525f908152604090205460ff1681565b6040519015158152602001610274565b6102906103e036600461350e565b600e6020525f908152604090205481565b610290670de0b6b3a764000081565b610408601281565b60405160ff9091168152602001610274565b61029061042836600461350e565b6001600160a01b03165f908152600f602052604090205490565b6102906104503660046134e4565b610a46565b61029061046336600461350e565b60116020525f908152604090205481565b6102a6610c89565b6001546102a6906001600160a01b031681565b6103c261049d36600461350e565b610cda565b61035c6104b036600461350e565b610d00565b61035c6104c336600461350e565b610d4b565b6102906104d636600461350e565b610ddb565b61035c6104e9366004613529565b610e85565b5f546102a6906001600160a01b031681565b6002546102a6906001600160a01b031681565b6006546102a6906001600160a01b031681565b6102a661119e565b61035c61053c3660046134e4565b6111ef565b61035c61054f366004613577565b61128f565b61029061056236600461350e565b60106020525f908152604090205481565b6003546102a6906001600160a01b031681565b6105996105943660046134e4565b611497565b6040516102749190815164ffffffffff90811682526020808401516001600160a01b039081169184019190915260408085015160ff16908401526060808501518316908401526080808501519091169083015260a092830151169181019190915260c00190565b61035c61060e36600461350e565b611572565b61035c61062136600461350e565b6115e5565b61029061063436600461350e565b611630565b61035c61064736600461350e565b61165d565b61035c61065a36600461350e565b6116ed565b61035c6117b0565b60078160038110610676575f80fd5b60020201805460019091015490915064ffffffffff80821691600160281b90041683565b6001600160a01b0382165f908152600f60205260408120805482919060ff85169081106106c9576106c96135bb565b905f5260205f20906002020190506106e0816119cd565b9150505b92915050565b5f60045f9054906101000a90046001600160a01b03166001600160a01b03166306a5cb3a6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561073b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061075f91906135cf565b905090565b600f602052815f5260405f20818154811061077d575f80fd5b5f9182526020909120600290910201805460019091015464ffffffffff80831694506001600160a01b03600160281b84048116945060ff600160c81b85041693600160d01b900482169290811691600160a01b9091041686565b6005546001600160a01b0316331461080a5760405162461bcd60e51b8152600401610801906135ea565b60405180910390fd5b6001600160a01b0382165f908152600f60205260408120805483908110610833576108336135bb565b5f918252602090912060029091020160018101549091506001600160a01b031661088b5760405162461bcd60e51b81526020600482015260096024820152681b9bc81c995dd85c9960ba1b6044820152606401610801565b80545f90600790600160c81b900460ff16600381106108ac576108ac6135bb565b60408051606081018252600292909202929092018054825260019081015464ffffffffff8082166020850152600160281b909104811693830193909352840154909250600160a01b9004161580159061093b57506040810151825461091f9190600160d01b900464ffffffffff1661362b565b600183015464ffffffffff918216600160a01b90910490911611155b61097e5760405162461bcd60e51b81526020600482015260146024820152736e6f742072657374616b656420696e2074696d6560601b6044820152606401610801565b6001820180546001600160a01b031981169091556001600160a01b03166109a58582611a9c565b604080516001600160a01b03838116825264ffffffffff42166020830152918101869052908616907f2b3ca68148d94d2c4f4e619c0125be1a33866e18aa56e0195aa4793107950f11906060015b60405180910390a25050505050565b5f546001600160a01b03163314610a2b5760405162461bcd60e51b815260040161080190613650565b6001600160a01b039091165f90815260116020526040902055565b6005545f906001600160a01b03163314610a725760405162461bcd60e51b8152600401610801906135ea565b5f610a7d8484611bee565b60035460405163195006c760e11b81526001600160a01b03898116600483015260ff7f00000000000000000000000000000000000000000000000000000000000000641660248301529296509294505f935016906332a00d8e906044015f60405180830381865afa158015610af4573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052610b1b91908101906136de565b90505f5b81518160ff161015610b91578260105f848460ff1681518110610b4457610b446135bb565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020015f205f828254610b799190613778565b90915550819050610b898161378b565b915050610b1f565b50825f03610ba3575f925050506106e4565b5f80610bae85611ece565b60405163a9059cbb60e01b815291935091505f805160206139e38339815191529063a9059cbb90610be5908a9086906004016137a9565b6020604051808303815f875af1158015610c01573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c2591906137c2565b506001546040516337470d6f60e21b8152600481018390526001600160a01b039091169063dd1c35bc906024015f604051808303815f87803b158015610c69575f80fd5b505af1158015610c7b573d5f803e3d5ffd5b505050505050505092915050565b5f60045f9054906101000a90046001600160a01b03166001600160a01b031663b0e011646040518163ffffffff1660e01b8152600401602060405180830381865afa15801561073b573d5f803e3d5ffd5b6001600160a01b03165f908152600e6020526040902054680ac9ae05a71ebc0000111590565b5f546001600160a01b03163314610d295760405162461bcd60e51b815260040161080190613650565b600280546001600160a01b0319166001600160a01b0392909216919091179055565b5f546001600160a01b03163314610d745760405162461bcd60e51b815260040161080190613650565b6001600160a01b038116610db95760405162461bcd60e51b815260206004820152600c60248201526b7a65726f206164647265737360a01b6044820152606401610801565b600680546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b0381165f908152600f60205260408120805415610e7f5780545f90610e0990600190613778565b90505b5f828281548110610e1f57610e1f6135bb565b5f91825260208220600290910201805490925064ffffffffff600160d01b909104169003610e5d57610e50816119cd565b610e5a90856137e1565b93505b815f03610e6a5750610e7d565b5080610e75816137f4565b915050610e0c565b505b50919050565b6005546001600160a01b03163314610eaf5760405162461bcd60e51b8152600401610801906135ea565b670de0b6b3a7640000826001600160a01b03161015610f055760405162461bcd60e51b81526020600482015260126024820152710f8f53525397d4d51052d157d05353d5539560721b6044820152606401610801565b60038160ff1610610f4d5760405162461bcd60e51b8152602060048201526012602482015271696e646578206f7574206f662072616e676560701b6044820152606401610801565b5f8160ff1611610f985760405162461bcd60e51b815260206004820152601660248201527572657374616b652063616e6e6f74206265203164617960501b6044820152606401610801565b6001600160a01b0384165f908152600f60205260408120805485908110610fc157610fc16135bb565b5f91825260209091206002909102018054909150600160d01b900464ffffffffff1661101e5760405162461bcd60e51b815260206004820152600c60248201526b1b9bdd081d5b9cdd185ad95960a21b6044820152606401610801565b6001810154600160a01b900464ffffffffff16156110715760405162461bcd60e51b815260206004820152601060248201526f185b1c9958591e481c995cdd185ad95960821b6044820152606401610801565b80546001600160a01b03600160281b909104811690841610156110c95760405162461bcd60e51b815260206004820152601060248201526f185b5bdd5b9d081d1bdbc81cdb585b1b60821b6044820152606401610801565b805460ff600160c81b909104811690831610156111205760405162461bcd60e51b81526020600482015260156024820152741cdd185ad9481a5b99195e081d1bdbc81cdb585b1b605a1b6044820152606401610801565b611129836121c7565b60018101805464ffffffffff60a01b1916600160a01b4264ffffffffff160217905561115685848461234f565b6040805164ffffffffff42168152602081018690526001600160a01b038716917f22ea4d12074016dab9862b37c4e634b11084494dbeb71ef9af7c5b33b5511c1f91016109f3565b5f60045f9054906101000a90046001600160a01b03166001600160a01b031663a5ece9416040518163ffffffff1660e01b8152600401602060405180830381865afa15801561073b573d5f803e3d5ffd5b5f546001600160a01b031633146112185760405162461bcd60e51b815260040161080190613650565b60015460405163a9059cbb60e01b81526001600160a01b039091169063a9059cbb9061124a90859085906004016137a9565b6020604051808303815f875af1158015611266573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061128a91906137c2565b505050565b6005546001600160a01b031633146112b95760405162461bcd60e51b8152600401610801906135ea565b670de0b6b3a7640000826001600160a01b0316101561130f5760405162461bcd60e51b81526020600482015260126024820152710f8f53525397d4d51052d157d05353d5539560721b6044820152606401610801565b60038160ff16106113575760405162461bcd60e51b8152602060048201526012602482015271696e646578206f7574206f662072616e676560701b6044820152606401610801565b600354604051633bb1db8160e21b81526001600160a01b0385811660048301529091169063eec76e0490602401602060405180830381865afa15801561139f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906113c391906137c2565b6113f85760405162461bcd60e51b81526020600482015260066024820152650848589a5b9960d21b6044820152606401610801565b8060ff165f03611483576001600160a01b0383165f9081526012602052604090205460ff16156114605760405162461bcd60e51b81526020600482015260136024820152720c59185e48185b1c9958591e481cdd185ad959606a1b6044820152606401610801565b6001600160a01b0383165f908152601260205260409020805460ff191660011790555b61148c826121c7565b61128a83838361234f565b6040805160c0810182525f8082526020808301829052828401829052606083018290526080830182905260a083018290526001600160a01b0386168252600f9052919091208054839081106114ee576114ee6135bb565b5f9182526020918290206040805160c0810182526002909302909101805464ffffffffff80821685526001600160a01b03600160281b830481169686019690965260ff600160c81b83041693850193909352600160d01b900482166060840152600101549283166080830152600160a01b90920490911660a0820152905092915050565b5f546001600160a01b0316331461159b5760405162461bcd60e51b815260040161080190613650565b5f80546001600160a01b0319166001600160a01b0383169081178255604051909133917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a350565b5f546001600160a01b0316331461160e5760405162461bcd60e51b815260040161080190613650565b600580546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b0381165f9081526011602090815260408083205460109092528220546106e491906137e1565b5f546001600160a01b031633146116865760405162461bcd60e51b815260040161080190613650565b6001600160a01b0381166116cb5760405162461bcd60e51b815260206004820152600c60248201526b7a65726f206164647265737360a01b6044820152606401610801565b600480546001600160a01b0319166001600160a01b0392909216919091179055565b5f546001600160a01b031633146117165760405162461bcd60e51b815260040161080190613650565b600180546001600160a01b0319166001600160a01b03831690811790915560405163095ea7b360e01b815263095ea7b39061176c907310ed43c718714eb63d5aa57b78b54704e256024e905f19906004016137a9565b6020604051808303815f875af1158015611788573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117ac91906137c2565b5050565b5f546001600160a01b03163314806117e057506117cb61119e565b6001600160a01b0316336001600160a01b0316145b6118225760405162461bcd60e51b8152602060048201526013602482015272216f776e6572206f72206d61726b6574696e6760681b6044820152606401610801565b6040516370a0823160e01b81523060048201525f905f805160206139e3833981519152906370a0823190602401602060405180830381865afa15801561186a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061188e9190613809565b90505f60015f9054906101000a90046001600160a01b03166001600160a01b03166349bd5a5e6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156118e1573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061190591906135cf565b60405163a9059cbb60e01b81529091505f805160206139e38339815191529063a9059cbb9061193a90849086906004016137a9565b6020604051808303815f875af1158015611956573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061197a91906137c2565b50806001600160a01b031663fff6cae96040518163ffffffff1660e01b81526004015f604051808303815f87803b1580156119b3575f80fd5b505af11580156119c5573d5f803e3d5ffd5b505050505050565b80545f906001600160a01b03600160281b8204169064ffffffffff16826119f48242613820565b8554909150611a30908290600790600160c81b900460ff1660038110611a1c57611a1c6135bb565b600202016001015464ffffffffff16612681565b90508064ffffffffff165f03611a4857829350611a94565b8454611a9190611a8a9064ffffffffff841690611a8490600790600160c81b900460ff1660038110611a7c57611a7c6135bb565b600202015490565b906126a6565b8490612707565b93505b505050919050565b5f80611ab0836001600160a01b0316611ece565b90925090505f6103e8611ac484603261383e565b611ace9190613869565b9050611ad981612718565b5f6103e8611ae98561015e61383e565b611af39190613869565b9050611aff86826127fd565b505f81611b0c8487613778565b611b169190613778565b60405163a9059cbb60e01b81529091505f805160206139e38339815191529063a9059cbb90611b4b908a9085906004016137a9565b6020604051808303815f875af1158015611b67573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b8b91906137c2565b506001546040516337470d6f60e21b8152600481018690526001600160a01b039091169063dd1c35bc906024015f604051808303815f87803b158015611bcf575f80fd5b505af1158015611be1573d5f803e3d5ffd5b5050505050505050505050565b6001600160a01b0382165f908152600f602052604081208054829182918290829087908110611c1f57611c1f6135bb565b5f91825260208220600290910201805490925064ffffffffff8116919060079060ff600160c81b9091041660038110611c5a57611c5a6135bb565b6040805160608101825260029290920292909201805482526001015464ffffffffff80821660208401819052600160281b909204169282019290925291505f90611ca490846137e1565b905080421015611cee5760405162461bcd60e51b8152602060048201526015602482015274151a19481d1a5b59481a5cc81b9bdd081c9a59da1d605a1b6044820152606401610801565b8354600160d01b900464ffffffffff1615611d315760405162461bcd60e51b8152602060048201526003602482015262616c7760e81b6044820152606401610801565b8354600160281b90046001600160a01b031696505f611d4f82613058565b90506064611d5d8282613778565b611d67908a61383e565b611d719190613869565b965087600d5f828254611d849190613778565b90915550506001600160a01b038b165f908152600e6020526040812080548a9290611db0908490613778565b90915550506040518881525f906001600160a01b038d16907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3611dfe856119cd565b855464ffffffffff60d01b1916600160d01b4264ffffffffff1602178655985087891115611e5357611e30888a613778565b6001860180546001600160a01b0319166001600160a01b03929092169190911790555b600185015460408085015181516001600160a01b038b8116825264ffffffffff42811660208401529382018f9052938416606082015291166080820152908c16907fb0b25333efd643d6b20b95dfa2e50b21744cf2810221c85dc17334d32e35802b9060a00160405180910390a25050505050509250925092565b6001546040516370a0823160e01b81523060048201525f91829182916001600160a01b0316906370a0823190602401602060405180830381865afa158015611f18573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f3c9190613809565b6040516370a0823160e01b81523060048201529091505f905f805160206139e3833981519152906370a0823190602401602060405180830381865afa158015611f87573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611fab9190613809565b6040805160028082526060820183529293505f929091602083019080368337505060015482519293506001600160a01b0316918391505f90611fef57611fef6135bb565b60200260200101906001600160a01b031690816001600160a01b0316815250505f805160206139e383398151915281600181518110612030576120306135bb565b6001600160a01b0390921660209283029190910190910152604051634401edf760e11b81527310ed43c718714eb63d5aa57b78b54704e256024e90638803dbee9061208790899087908690309042906004016138be565b5f604051808303815f875af11580156120a2573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526120c991908101906138f9565b506001546040516370a0823160e01b81523060048201525f916001600160a01b0316906370a0823190602401602060405180830381865afa158015612110573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906121349190613809565b6040516370a0823160e01b81523060048201529091505f905f805160206139e3833981519152906370a0823190602401602060405180830381865afa15801561217f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906121a39190613809565b90506121af8286613778565b95506121bb8482613778565b96505050505050915091565b6040516323b872dd60e01b81523360048201523060248201526001600160a01b03821660448201525f805160206139e3833981519152906323b872dd906064016020604051808303815f875af1158015612223573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061224791906137c2565b505f61226561225760028461397a565b6001600160a01b03166130a4565b6001549091507310ed43c718714eb63d5aa57b78b54704e256024e9063e8e33700905f805160206139e3833981519152906001600160a01b03166122aa60028761397a565b60065460405160e086901b6001600160e01b03191681526001600160a01b03948516600482015292841660248401529083166044830152606482018690525f6084830181905260a48301529190911660c48201524260e4820152610104016060604051808303815f875af1158015612324573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612348919061399f565b5050505050565b6040805160c0810182525f606082018190526080820181905260a082018190524264ffffffffff1682526001600160a01b0385166020830181905260ff851693830193909352600d80549293929091906123aa9084906137e1565b90915550506001600160a01b038481165f908152600e602052604081208054928616929091906123db9084906137e1565b90915550506001600160a01b038481165f818152600f602090815260408083208054600180820183558286528486208951600284029091018054968b01518b87015160608d015164ffffffffff9485166001600160c81b03199a8b1617600160281b938e16939093029290921765ffffffffffff60c81b1916600160c81b60ff9283160264ffffffffff60d01b191617600160d01b9285169290920291909117825560808c015191909301805460a08d0151928c16981697909717600160a01b919092160217909455600354925163195006c760e11b815260048101969096527f000000000000000000000000000000000000000000000000000000000000006490931660248601529491939116906332a00d8e906044015f60405180830381865afa15801561250d573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405261253491908101906136de565b90505f5b81518160ff1610156125b357866001600160a01b031660105f848460ff1681518110612566576125666135bb565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020015f205f82825461259b91906137e1565b909155508190506125ab8161378b565b915050612538565b506040516001600160a01b0387811682528816905f907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3866001600160a01b03167f3a9398000906a7b3c6ab07ec3d849739a537132436f8db617248c858f632c56d87428560078a60ff166003811061263a5761263a6135bb565b6002020160010154604080516001600160a01b03909516855264ffffffffff938416602086015284019190915216606082015260800160405180910390a250505050505050565b5f8164ffffffffff168364ffffffffff161061269d578161269f565b825b9392505050565b5f8281600184166126bf57670de0b6b3a76400006126c1565b815b9050600184901c93505b83156126ff576126db828361327a565b915060018416156126f3576126f0818361327a565b90505b600184901c93506126cb565b949350505050565b5f61269f612715848461327a565b90565b805f036127225750565b6002546001600160a01b0316158015906127ab575060025f9054906101000a90046001600160a01b03166001600160a01b031663462383266040518163ffffffff1660e01b8152600401602060405180830381865afa158015612787573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906127ab91906137c2565b156127e9575f805160206139e383398151915263a9059cbb6127cb6106ea565b836040518363ffffffff1660e01b815260040161176c9291906137a9565b6127fa816127f5610c89565b61332c565b50565b60035460405163195006c760e11b81526001600160a01b03848116600483015260ff7f00000000000000000000000000000000000000000000000000000000000000641660248301525f9283929116906332a00d8e906044015f60405180830381865afa158015612870573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405261289791908101906136de565b90505f80602381805b8551811015612fa9578581815181106128bb576128bb6135bb565b602002602001015194506128ce85611630565b93506a18d0bf423c03d8de00000084101580156128ea57508183115b80156128fa57506128fa85610cda565b15612995575f805160206139e383398151915263a9059cbb868561291e8682613778565b612928908d61383e565b6129329190613869565b6040518363ffffffff1660e01b815260040161294f9291906137a9565b6020604051808303815f875af115801561296b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061298f91906137c2565b50602391505b6a084595161401484a00000084101580156129ba57506a18d0bf423c03d8de00000084105b80156129c65750602082105b80156129d657506129d685610cda565b15612a72575f805160206139e383398151915263a9059cbb86856129fb866020613778565b612a05908d61383e565b612a0f9190613869565b6040518363ffffffff1660e01b8152600401612a2c9291906137a9565b6020604051808303815f875af1158015612a48573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612a6c91906137c2565b50602091505b6a0422ca8b0a00a4250000008410158015612a9757506a084595161401484a00000084105b8015612aa35750601d82105b8015612ab35750612ab385610cda565b15612b4f575f805160206139e383398151915263a9059cbb8685612ad886601d613778565b612ae2908d61383e565b612aec9190613869565b6040518363ffffffff1660e01b8152600401612b099291906137a9565b6020604051808303815f875af1158015612b25573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612b4991906137c2565b50601d91505b69d3c21bcecceda10000008410158015612b7357506a0422ca8b0a00a42500000084105b8015612b7f5750601a82105b8015612b8f5750612b8f85610cda565b15612c2b575f805160206139e383398151915263a9059cbb8685612bb486601a613778565b612bbe908d61383e565b612bc89190613869565b6040518363ffffffff1660e01b8152600401612be59291906137a9565b6020604051808303815f875af1158015612c01573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612c2591906137c2565b50601a91505b6969e10de76676d08000008410158015612c4e575069d3c21bcecceda100000084105b8015612c5a5750601682105b8015612c6a5750612c6a85610cda565b15612d06575f805160206139e383398151915263a9059cbb8685612c8f866016613778565b612c99908d61383e565b612ca39190613869565b6040518363ffffffff1660e01b8152600401612cc09291906137a9565b6020604051808303815f875af1158015612cdc573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612d0091906137c2565b50601691505b69152d02c7e14af68000008410158015612d2957506969e10de76676d080000084105b8015612d355750601282105b8015612d455750612d4585610cda565b15612de1575f805160206139e383398151915263a9059cbb8685612d6a866012613778565b612d74908d61383e565b612d7e9190613869565b6040518363ffffffff1660e01b8152600401612d9b9291906137a9565b6020604051808303815f875af1158015612db7573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612ddb91906137c2565b50601291505b690a968163f0a57b4000008410158015612e04575069152d02c7e14af680000084105b8015612e105750600d82105b8015612e205750612e2085610cda565b15612ebc575f805160206139e383398151915263a9059cbb8685612e4586600d613778565b612e4f908d61383e565b612e599190613869565b6040518363ffffffff1660e01b8152600401612e769291906137a9565b6020604051808303815f875af1158015612e92573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612eb691906137c2565b50600d91505b69021e19e0c9bab24000008410158015612edf5750690a968163f0a57b40000084105b8015612eeb5750600782105b8015612efb5750612efb85610cda565b15612f97575f805160206139e383398151915263a9059cbb8685612f20866007613778565b612f2a908d61383e565b612f349190613869565b6040518363ffffffff1660e01b8152600401612f519291906137a9565b6020604051808303815f875af1158015612f6d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612f9191906137c2565b50600791505b80612fa1816139ca565b9150506128a0565b5081612fb5828961383e565b612fbf9190613869565b95508082111561304d575f805160206139e383398151915263a9059cbb612fe461119e565b612fee898b613778565b6040518363ffffffff1660e01b815260040161300b9291906137a9565b6020604051808303815f875af1158015613027573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061304b91906137c2565b505b505050505092915050565b5f81421161306757505f919050565b5f6130728342613778565b90505f6130826201518083613869565b905061308f81600561383e565b92506064831115610e7d575060649392505050565b6040805160028082526060820183525f92839291906020830190803683370190505090505f805160206139e3833981519152815f815181106130e8576130e86135bb565b6001600160a01b0392831660209182029290920101526001805483519216918391908110613118576131186135bb565b6001600160a01b0392831660209182029290920101526001546040516370a0823160e01b81523060048201525f9291909116906370a0823190602401602060405180830381865afa15801561316f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906131939190613809565b604051635c11d79560e01b81529091507310ed43c718714eb63d5aa57b78b54704e256024e90635c11d795906131d59087905f908790309042906004016138be565b5f604051808303815f87803b1580156131ec575f80fd5b505af11580156131fe573d5f803e3d5ffd5b50506001546040516370a0823160e01b81523060048201525f93506001600160a01b0390911691506370a0823190602401602060405180830381865afa15801561324a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061326e9190613809565b9050611a918282613778565b5f80805f19848609848602925082811083820303915050805f036132ab5750670de0b6b3a7640000900490506106e4565b670de0b6b3a764000081106132dd57604051635173648d60e01b81526004810186905260248101859052604401610801565b5f670de0b6b3a764000085870962040000818503049310909103600160ee1b02919091177faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106690291505092915050565b6040805160028082526060820183525f926020830190803683370190505090505f805160206139e3833981519152815f8151811061336c5761336c6135bb565b6001600160a01b03928316602091820292909201015260025482519116908290600190811061339d5761339d6135bb565b6001600160a01b0390921660209283029190910190910152604051635c11d79560e01b81527310ed43c718714eb63d5aa57b78b54704e256024e90635c11d795906133f49086905f908690889042906004016138be565b5f604051808303815f87803b15801561340b575f80fd5b505af115801561341d573d5f803e3d5ffd5b50505050505050565b5f60208284031215613436575f80fd5b5035919050565b6001600160a01b03811681146127fa575f80fd5b803560ff81168114613461575f80fd5b919050565b5f8060408385031215613477575f80fd5b82356134828161343d565b915061349060208401613451565b90509250929050565b5f6020808352835180828501525f5b818110156134c4578581018301518582016040015282016134a8565b505f604082860101526040601f19601f8301168501019250505092915050565b5f80604083850312156134f5575f80fd5b82356135008161343d565b946020939093013593505050565b5f6020828403121561351e575f80fd5b813561269f8161343d565b5f805f806080858703121561353c575f80fd5b84356135478161343d565b935060208501359250604085013561355e8161343d565b915061356c60608601613451565b905092959194509250565b5f805f60608486031215613589575f80fd5b83356135948161343d565b925060208401356135a48161343d565b91506135b260408501613451565b90509250925092565b634e487b7160e01b5f52603260045260245ffd5b5f602082840312156135df575f80fd5b815161269f8161343d565b60208082526013908201527237b7363c9038bab2bab29037b91037bbb732b960691b604082015260600190565b634e487b7160e01b5f52601160045260245ffd5b64ffffffffff81811683821601908082111561364957613649613617565b5092915050565b6020808252600c908201526b15539055551213d49256915160a21b604082015260600190565b634e487b7160e01b5f52604160045260245ffd5b604051601f8201601f1916810167ffffffffffffffff811182821017156136b3576136b3613676565b604052919050565b5f67ffffffffffffffff8211156136d4576136d4613676565b5060051b60200190565b5f60208083850312156136ef575f80fd5b825167ffffffffffffffff811115613705575f80fd5b8301601f81018513613715575f80fd5b8051613728613723826136bb565b61368a565b81815260059190911b82018301908381019087831115613746575f80fd5b928401925b8284101561376d57835161375e8161343d565b8252928401929084019061374b565b979650505050505050565b818103818111156106e4576106e4613617565b5f60ff821660ff81036137a0576137a0613617565b60010192915050565b6001600160a01b03929092168252602082015260400190565b5f602082840312156137d2575f80fd5b8151801515811461269f575f80fd5b808201808211156106e4576106e4613617565b5f8161380257613802613617565b505f190190565b5f60208284031215613819575f80fd5b5051919050565b64ffffffffff82811682821603908082111561364957613649613617565b80820281158282048414176106e4576106e4613617565b634e487b7160e01b5f52601260045260245ffd5b5f8261387757613877613855565b500490565b5f8151808452602080850194508084015f5b838110156138b35781516001600160a01b03168752958201959082019060010161388e565b509495945050505050565b85815284602082015260a060408201525f6138dc60a083018661387c565b6001600160a01b0394909416606083015250608001529392505050565b5f602080838503121561390a575f80fd5b825167ffffffffffffffff811115613920575f80fd5b8301601f81018513613930575f80fd5b805161393e613723826136bb565b81815260059190911b8201830190838101908783111561395c575f80fd5b928401925b8284101561376d57835182529284019290840190613961565b5f6001600160a01b038381168061399357613993613855565b92169190910492915050565b5f805f606084860312156139b1575f80fd5b8351925060208401519150604084015190509250925092565b5f600182016139db576139db613617565b506001019056fe00000000000000000000000055d398326f99059ff775485246999027b3197955a2646970667358221220bd9281e5486618a39810c402977d39edcf9d8cff13e072694d374c903206b77964736f6c63430008140033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000001d0b57f8fdcfc237a979ff6855ac93f8462fac14000000000000000000000000171336fc55d8c0644e56a71119c8590f5cb5e2a4000000000000000000000000c4eaec128ea04f34a4c128b35112227d99b7796a
-----Decoded View---------------
Arg [0] : referral_ (address): 0x1d0B57F8fDCFc237a979ff6855AC93f8462fAC14
Arg [1] : project_ (address): 0x171336FC55D8c0644e56A71119c8590F5CB5E2a4
Arg [2] : lpAddress_ (address): 0xc4eaEC128eA04f34A4C128b35112227D99B7796A
-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 0000000000000000000000001d0b57f8fdcfc237a979ff6855ac93f8462fac14
Arg [1] : 000000000000000000000000171336fc55d8c0644e56a71119c8590f5cb5e2a4
Arg [2] : 000000000000000000000000c4eaec128ea04f34a4c128b35112227d99b7796a
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A token is a representation of an on-chain or off-chain asset. The token page shows information such as price, total supply, holders, transfers and social links. Learn more about this page in our Knowledge Base.
Add Token to MetaMask (Web3)