Source Code
Overview
ETH Balance
0 ETH
ETH Value
$0.00View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Cross-Chain Transactions
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0xd9b810a1...8E5895329 The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
Pool
Compiler Version
v0.8.28+commit.7893614a
Optimization Enabled:
Yes with 400 runs
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {ERC20PermitUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PermitUpgradeable.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import {ReentrancyGuardTransientUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardTransientUpgradeable.sol";
import {ITokiErrors} from "./interfaces/ITokiErrors.sol";
import {IPool} from "./interfaces/IPool.sol";
import {ITransferPoolFeeCalculator} from "./interfaces/ITransferPoolFeeCalculator.sol";
import {DecimalConvertibleUpgradeable} from "./DecimalConvertibleUpgradeable.sol";
import {StaticFlowRateLimiter} from "./StaticFlowRateLimiter.sol";
contract Pool is
ITokiErrors,
IPool,
ERC20PermitUpgradeable,
UUPSUpgradeable,
AccessControlUpgradeable,
DecimalConvertibleUpgradeable,
ReentrancyGuardTransientUpgradeable,
StaticFlowRateLimiter
{
using SafeERC20 for IERC20;
struct InitializeParam {
string name;
string symbol;
uint256 poolId;
address token;
uint8 globalDecimals;
uint8 localDecimals;
address feeCalculator;
address admin;
address router;
uint256 maxTotalDeposits; // The maximum deposits that each pool will hold in LD-unit
}
/// @custom:storage-location erc7201:toki.storage.Pool
struct PoolStorage {
address _feeCalculator;
// Delta algorithm parameters
PeerPoolInfo[] _peerPoolInfos; // list of connected chains pool.
// seek for peerPools by chainId => poolId => index
mapping(uint256 => mapping(uint256 => uint256)) _peerPoolInfoIndexSeek;
uint256 _totalLiquidity; // assets deposited.
// total weight for pools. When calculate proportion of weight, peerPoolInfos[i].weight / totalWeight.
uint256 _totalWeight;
uint256 _deltaCredit; // Needs optimization
bool _batched; // flag indicates whether or not batch processing is performed.
bool _defaultSwapMode; // flag indicates whether or not the default mode for swap
bool _defaultLPMode; // flag indicates whether or not the default mode for lp
uint256 _feeBalance; // fee balance in Global Decimal format.
uint256 _eqFeePool; // pool rewards in Global Decimal format.
uint256 _swapDeltaBP; // activate the delta of the swap at the basis point of the pool credit.
uint256 _lpDeltaBP; // basis points of pooled credit to allow for delta in liquidity events
uint256 _poolId; // shared id between chains to represent same pool.
address _token; // the local token for the pool
// Tip about decimals
// - amountLP: liquidity provider token (that means this contract) in global decimals units.
// - amountGD: decimals of shared asset token. eg) 6 decimals, lcm(USDT_eth.decimals(), USDT_bsc.decimals(), ...)
// - amountLD: decimals of local asset token. eg) 18 decimals(USDT_eth)
bool _transferStop; // flag to stop transfer in extreme cases
uint256 _maxTotalDeposits; // The maximum deposits that each pool will hold by LD-unit
}
// The maximum number of peer pool.
// This limitation prevents _deltaSourceUpdate from exceeding the block gas limit.
// The amount of gas for _deltaSourceUpdate increases by about 20k as peer increases.
uint256 public constant MAX_PEERS = 100;
// keccak256(abi.encode(uint256(keccak256("toki.storage.Pool")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant POOL_LOCATION =
0x98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea00;
bytes32 public constant DEFAULT_ROUTER_ROLE =
keccak256("DEFAULT_ROUTER_ROLE");
uint256 public constant BPS_DENOMINATOR = 10000; // basic point denominator
event SetDstFlowRateLimiter(address dstFlowRateLimiter);
modifier checkMaxTotalDeposits(uint256 amountAssetLD) {
PoolStorage storage $ = _getPoolStorage();
uint256 totalDepositsLD = _GDToLD($._totalLiquidity) + amountAssetLD;
// Check that the total liquidity does not exceed the maximum total deposits
if (totalDepositsLD > $._maxTotalDeposits) {
revert TokiExceed(
"maxTotalDeposits",
totalDepositsLD,
$._maxTotalDeposits
);
}
_;
}
/// @custom:oz-upgrades-unsafe-allow constructor
constructor(
uint256 period,
uint256 lockPeriod,
uint256 limit,
uint256 threshold
) StaticFlowRateLimiter(period, lockPeriod, limit, threshold) {}
// ========================== public functions ===============================
function initialize(InitializeParam calldata p) public initializer {
__ERC20_init(p.name, p.symbol);
__ERC20Permit_init(p.name);
__UUPSUpgradeable_init();
__AccessControl_init();
__DecimalConvertible_init(p.globalDecimals, p.localDecimals);
__ReentrancyGuardTransient_init();
__StaticFlowRateLimiter_init_unchained();
_grantRole(DEFAULT_ADMIN_ROLE, p.admin);
_grantRole(DEFAULT_ROUTER_ROLE, p.router);
PoolStorage storage $ = _getPoolStorage();
$._poolId = p.poolId;
if (p.token == address(0x0)) {
revert TokiZeroAddress("token");
}
if (p.feeCalculator == address(0x0)) {
revert TokiZeroAddress("feeCalculator");
}
$._token = p.token;
$._feeCalculator = p.feeCalculator;
$._maxTotalDeposits = p.maxTotalDeposits;
}
// ========================== external functions ===================================
// for deposit
function mint(
address to,
uint256 amountLD
) external nonReentrant onlyRole(DEFAULT_ROUTER_ROLE) returns (uint256) {
return _mintLPbyLDWithLimitCheck(to, amountLD, true);
}
function callDelta(bool fullMode) external onlyRole(DEFAULT_ROUTER_ROLE) {
_deltaSourceUpdate(fullMode);
}
//-----------------------------------------------------------------------------------
// Admin functions
//-----------------------------------------------------------------------------------
function setTransferStop(
bool transferStop_
) external onlyRole(DEFAULT_ADMIN_ROLE) {
PoolStorage storage $ = _getPoolStorage();
$._transferStop = transferStop_;
emit IPool.UpdateStopTransfer($._transferStop);
}
function registerPeerPool(
uint256 peerChainId,
uint256 peerPoolId,
uint256 weight
) external onlyRole(DEFAULT_ADMIN_ROLE) {
PoolStorage storage $ = _getPoolStorage();
uint256 length = $._peerPoolInfos.length;
if (MAX_PEERS <= length) {
revert TokiExceed("PeerPool", length + 1, MAX_PEERS);
}
for (uint256 i = 0; i < length; ++i) {
PeerPoolInfo memory peerPoolInfo = $._peerPoolInfos[i];
bool exists = peerPoolInfo.chainId == peerChainId &&
peerPoolInfo.id == peerPoolId;
if (exists) {
revert TokiPeerPoolIsRegistered(peerChainId, peerPoolId);
}
}
$._totalWeight = $._totalWeight + weight;
$._peerPoolInfoIndexSeek[peerChainId][peerPoolId] = $
._peerPoolInfos
.length;
$._peerPoolInfos.push(
PeerPoolInfo(peerChainId, peerPoolId, weight, 0, 0, 0, 0, false)
);
emit PeerPoolInfoUpdate(peerChainId, peerPoolId, weight);
}
function activatePeerPool(
uint256 peerChainId,
uint256 peerPoolId
) external onlyRole(DEFAULT_ADMIN_ROLE) {
PeerPoolInfo storage p = _getAndCheckPeerPoolInfo(
peerChainId,
peerPoolId
);
if (p.ready) {
revert TokiPeerPoolIsAlreadyActive(peerChainId, peerPoolId);
}
p.ready = true;
}
function setFeeCalculator(
address _feeCalculator
) external onlyRole(DEFAULT_ADMIN_ROLE) {
PoolStorage storage $ = _getPoolStorage();
$._feeCalculator = _feeCalculator;
}
function setPeerPoolWeight(
uint256 peerChainId,
uint256 peerPoolId,
uint256 weight
) external onlyRole(DEFAULT_ADMIN_ROLE) {
PoolStorage storage $ = _getPoolStorage();
PeerPoolInfo storage p = _getAndCheckPeerPoolInfo(
peerChainId,
peerPoolId
);
$._totalWeight = $._totalWeight - p.weight + weight;
p.weight = weight;
emit PeerPoolInfoUpdate(peerChainId, peerPoolId, weight);
}
function setDeltaParam(
bool batched_,
uint256 swapDeltaBP_,
uint256 lpDeltaBP_,
bool defaultSwapMode_,
bool defaultLPMode_
) external onlyRole(DEFAULT_ADMIN_ROLE) {
PoolStorage storage $ = _getPoolStorage();
if (swapDeltaBP_ > BPS_DENOMINATOR) {
revert TokiExceed("swapDeltaBP", swapDeltaBP_, BPS_DENOMINATOR);
}
if (lpDeltaBP_ > BPS_DENOMINATOR) {
revert TokiExceed("lpDeltaBP", lpDeltaBP_, BPS_DENOMINATOR);
}
$._batched = batched_;
$._swapDeltaBP = swapDeltaBP_;
$._lpDeltaBP = lpDeltaBP_;
$._defaultSwapMode = defaultSwapMode_;
$._defaultLPMode = defaultLPMode_;
emit UpdateDeltaParam(
batched_,
swapDeltaBP_,
lpDeltaBP_,
defaultSwapMode_,
defaultLPMode_
);
}
function drawFee(address to) external onlyRole(DEFAULT_ADMIN_ROLE) {
PoolStorage storage $ = _getPoolStorage();
if (to == address(0x0)) {
revert TokiZeroAddress("to");
}
if ($._feeBalance == 0) {
revert TokiNoFee();
}
uint256 amountLD = _GDToLD($._feeBalance);
$._feeBalance = 0;
emit DrawFee(to, amountLD);
_safeTransferWithRevert($._token, to, amountLD);
}
function setMaxTotalDeposits(
uint256 newMaxTotalDeposits
) external onlyRole(DEFAULT_ADMIN_ROLE) {
PoolStorage storage $ = _getPoolStorage();
emit SetMaxTotalDeposits(newMaxTotalDeposits);
$._maxTotalDeposits = newMaxTotalDeposits;
}
// solhint-disable-next-line func-name-mixedcase
function LPToLD(uint256 amountLP) external view returns (uint256) {
return _GDToLD(_LPToGD(amountLP));
}
// solhint-disable-next-line func-name-mixedcase
function LDToLP(uint256 _amountLD) external view returns (uint256) {
return _GDToLP(_LDToGD(_amountLD));
}
function getPeerPoolInfo(
uint256 peerChainId,
uint256 peerPoolId
) external view returns (PeerPoolInfo memory) {
return _getAndCheckPeerPoolInfo(peerChainId, peerPoolId);
}
function calcFee(
uint256 peerChainId,
uint256 peerPoolId,
address from,
uint256 amountLD
)
external
view
returns (ITransferPoolFeeCalculator.FeeInfo memory feeInfo)
{
PoolStorage storage $ = _getPoolStorage();
PeerPoolInfo storage peerPoolInfo = _getAndCheckPeerPoolInfo(
peerChainId,
peerPoolId
);
uint256 amountGD = _LDToGD(amountLD);
ITransferPoolFeeCalculator.SrcPoolInfo
memory myPoolInfo = ITransferPoolFeeCalculator.SrcPoolInfo({
addr: address(this),
id: $._poolId,
globalDecimals: globalDecimals(),
balance: tokenBalanceOfThisPoolInGD(),
totalLiquidity: $._totalLiquidity,
eqFeePool: $._eqFeePool
});
// fee calculate
return
ITransferPoolFeeCalculator($._feeCalculator).calcFee(
myPoolInfo,
peerPoolInfo,
from,
amountGD
);
}
function transfer(
uint256 peerChainId,
uint256 peerPoolId,
address from,
uint256 amountLD,
uint256 minAmountLD,
bool newLiquidity
)
public
nonReentrant
onlyRole(DEFAULT_ROUTER_ROLE)
returns (ITransferPoolFeeCalculator.FeeInfo memory feeInfo)
{
PoolStorage storage $ = _getPoolStorage();
if ($._transferStop) {
revert TokiTransferIsStop();
}
if (from == address(0x0)) {
revert TokiZeroAddress("from");
}
PeerPoolInfo storage peerPoolInfo = _getAndCheckPeerPoolInfo(
peerChainId,
peerPoolId
);
if (peerPoolInfo.ready != true) {
revert TokiPeerPoolIsNotReady(peerChainId, peerPoolId);
}
uint256 amountGD = _LDToGD(amountLD);
uint256 minAmountGD = _LDToGD(minAmountLD);
ITransferPoolFeeCalculator.SrcPoolInfo
memory myPoolInfo = ITransferPoolFeeCalculator.SrcPoolInfo({
addr: address(this),
id: $._poolId,
globalDecimals: globalDecimals(),
balance: tokenBalanceOfThisPoolInGD(),
totalLiquidity: $._totalLiquidity,
eqFeePool: $._eqFeePool
});
// fee calculate
feeInfo = ITransferPoolFeeCalculator($._feeCalculator).calcFee(
myPoolInfo,
peerPoolInfo,
from,
amountGD
);
// Note about slither-disable:
// no need to check amountGD is less than 0 because it is unsigned.
// slither-disable-next-line incorrect-equality
if (0 == feeInfo.amountGD) {
// Although the calculation of 'needed' is somewhat specific,
// it remains stable as long as the fee structure doesn't change.
revert TokiInsufficientAmount(
"amountLD",
amountLD,
feeInfo.eqFee + feeInfo.protocolFee + feeInfo.lpFee + 1
);
}
//Slippage check uses eq fee and eq reward. We don't use predictable protocol fee and LP fee.
if (amountGD + feeInfo.eqReward - feeInfo.eqFee < minAmountGD) {
revert TokiSlippageTooHigh(
amountGD,
feeInfo.eqReward,
feeInfo.eqFee,
minAmountGD
);
}
if (feeInfo.eqReward > 0) {
$._eqFeePool -= feeInfo.eqReward;
}
feeInfo.balanceDecrease = amountGD - feeInfo.lpFee + feeInfo.eqReward;
// delta algorithm 1-5 lines
if (peerPoolInfo.balance < feeInfo.balanceDecrease) {
revert TokiInsufficientPoolLiquidity(
peerPoolInfo.balance,
feeInfo.balanceDecrease
);
}
peerPoolInfo.balance = peerPoolInfo.balance - feeInfo.balanceDecrease;
if (newLiquidity) {
$._deltaCredit = $._deltaCredit + amountGD + feeInfo.eqReward;
} else if (feeInfo.eqReward > 0) {
$._deltaCredit = $._deltaCredit + feeInfo.eqReward;
}
// delta algportm 6-16 lines
if (
!$._batched ||
$._deltaCredit >=
($._totalLiquidity * $._swapDeltaBP) / BPS_DENOMINATOR
) {
_deltaSourceUpdate($._defaultSwapMode);
}
// delta algorithm 17-20 lines -> sendCredit
emit Transfer(
peerChainId,
peerPoolId,
from,
feeInfo.amountGD,
feeInfo.eqReward,
feeInfo.eqFee,
feeInfo.protocolFee,
feeInfo.lpFee
);
}
function recv(
uint256 peerChainId,
uint256 peerPoolId,
address to,
ITransferPoolFeeCalculator.FeeInfo memory feeInfo,
bool updateDelta
)
public
nonReentrant
onlyRole(DEFAULT_ROUTER_ROLE)
returns (uint256 amountLD, bool isTransferred)
{
PoolStorage storage $ = _getPoolStorage();
if (updateDelta) {
_recvFees($, feeInfo);
// delta algorithm 21-24 lines -> updateCredit
_decreaseLastKnownBalance(
peerChainId,
peerPoolId,
feeInfo.balanceDecrease
);
}
// user receives the amount + the srcReward
amountLD = _GDToLD(feeInfo.amountGD + feeInfo.eqReward);
bool passed = true;
if (peerChainId != block.chainid) {
passed = _checkAndUpdateFlowRateLimit(amountLD);
}
if (passed && _safeTransfer($._token, to, amountLD)) {
isTransferred = true;
emit Recv(
to,
feeInfo.amountGD + feeInfo.eqReward,
feeInfo.protocolFee,
feeInfo.eqFee
);
} else {
_cancelFlowRateLimit();
}
}
function withdrawRemote(
uint256 peerChainId,
uint256 peerPoolId,
address from,
uint256 amountLP
) public nonReentrant onlyRole(DEFAULT_ROUTER_ROLE) {
PoolStorage storage $ = _getPoolStorage();
if (from == address(0x0)) {
revert TokiZeroAddress("from");
}
// 1. burn lp token on local
uint256 amountGD = _burnLP(from, amountLP);
// 2. run delta common function
if (
!$._batched ||
$._deltaCredit >
($._totalLiquidity * $._lpDeltaBP) / BPS_DENOMINATOR
) {
_deltaSourceUpdate($._defaultLPMode);
}
uint256 amountLD = _GDToLD(amountGD);
// 3. emit withdrawRemote event
emit WithdrawRemote(peerChainId, peerPoolId, from, amountLP, amountLD);
}
function withdrawLocal(
uint256 peerChainId,
uint256 peerPoolId,
address from,
uint256 amountLP,
bytes calldata to
)
public
nonReentrant
onlyRole(DEFAULT_ROUTER_ROLE)
returns (uint256 amountGD)
{
PoolStorage storage $ = _getPoolStorage();
if (from == address(0x0)) {
revert TokiZeroAddress("from");
}
// 1. burn lp token on local
if (_getAndCheckPeerPoolInfo(peerChainId, peerPoolId).ready != true) {
revert TokiPeerPoolIsNotReady(peerChainId, peerPoolId);
}
amountGD = _burnLP(from, amountLP);
// 2. run delta common function
if (
!$._batched ||
$._deltaCredit >
($._totalLiquidity * $._lpDeltaBP) / BPS_DENOMINATOR
) {
_deltaSourceUpdate(false);
}
// 3. emit withdrawLocal event
emit WithdrawLocal(
peerChainId,
peerPoolId,
from,
amountLP,
amountGD,
to
);
}
function withdrawCheck(
uint256 peerChainId,
uint256 peerPoolId,
uint256 amountGD
)
public
nonReentrant
onlyRole(DEFAULT_ROUTER_ROLE)
returns (uint256 amountSwap, uint256 amountMint)
{
PeerPoolInfo storage peerPoolInfo = _getAndCheckPeerPoolInfo(
peerChainId,
peerPoolId
);
if (amountGD > peerPoolInfo.balance) {
amountMint = amountGD - peerPoolInfo.balance;
amountSwap = peerPoolInfo.balance;
peerPoolInfo.balance = 0;
} else {
peerPoolInfo.balance = peerPoolInfo.balance - amountGD;
amountSwap = amountGD;
amountMint = 0;
}
emit WithdrawCheck(peerChainId, peerPoolId, amountSwap, amountMint);
}
/**
* @dev even when updateDelta is true, lp token will not be re-minted if to is zero address.
*/
function withdrawConfirm(
uint256 peerChainId,
uint256 peerPoolId,
address to,
uint256 amountGD,
uint256 amountToMintGD,
bool updateDelta
)
public
nonReentrant
onlyRole(DEFAULT_ROUTER_ROLE)
returns (bool isTransferred)
{
if (updateDelta) {
// 1. mint lp token on local if possible
if (amountToMintGD > 0 && to != address(0x0)) {
_mintLPbyLD(to, _GDToLD(amountToMintGD), false);
}
// 2. update last known balance
_decreaseLastKnownBalance(peerChainId, peerPoolId, amountGD);
}
// 3. transfer asset token to _to
uint256 amountLD = _GDToLD(amountGD);
bool passed = true;
if (peerChainId != block.chainid) {
passed = _checkAndUpdateFlowRateLimit(amountLD);
}
PoolStorage storage $ = _getPoolStorage();
if (passed && _safeTransfer($._token, to, amountLD)) {
isTransferred = true;
emit WithdrawConfirm(
peerChainId,
peerPoolId,
to,
amountGD,
amountToMintGD
);
} else {
_cancelFlowRateLimit();
}
}
function sendCredit(
uint256 peerChainId,
uint256 peerPoolId
)
public
nonReentrant
onlyRole(DEFAULT_ROUTER_ROLE)
returns (CreditInfo memory creditInfo)
{
PoolStorage storage $ = _getPoolStorage();
PeerPoolInfo storage peerPoolInfo = _getAndCheckPeerPoolInfo(
peerChainId,
peerPoolId
);
if (peerPoolInfo.ready != true) {
revert TokiPeerPoolIsNotReady(peerChainId, peerPoolId);
}
creditInfo.targetBalance =
($._totalLiquidity * peerPoolInfo.weight) /
$._totalWeight;
creditInfo.credits = peerPoolInfo.credits;
// delta algorithm 17-20 lines
peerPoolInfo.lastKnownBalance =
peerPoolInfo.lastKnownBalance +
peerPoolInfo.credits;
peerPoolInfo.credits = 0;
emit SendCredit(
peerPoolId,
creditInfo.credits,
creditInfo.targetBalance
);
}
function updateCredit(
uint256 peerChainId,
uint256 peerPoolId,
CreditInfo memory creditInfo
) public nonReentrant onlyRole(DEFAULT_ROUTER_ROLE) {
PeerPoolInfo storage peerPoolInfo = _getAndCheckPeerPoolInfo(
peerChainId,
peerPoolId
);
peerPoolInfo.balance = peerPoolInfo.balance + creditInfo.credits;
if (peerPoolInfo.targetBalance != creditInfo.targetBalance) {
peerPoolInfo.targetBalance = creditInfo.targetBalance;
}
emit UpdateCredit(
peerChainId,
peerPoolId,
creditInfo.credits,
creditInfo.targetBalance
);
}
function withdrawInstant(
address from,
uint256 amountLP,
address to
)
public
nonReentrant
onlyRole(DEFAULT_ROUTER_ROLE)
returns (uint256 amountGD)
{
PoolStorage storage $ = _getPoolStorage();
if (from == address(0x0)) {
revert TokiZeroAddress("from");
}
uint256 deltaCredit_ = $._deltaCredit; // sload optimization.
uint256 capAmountLP = _GDToLP(deltaCredit_);
if (amountLP > capAmountLP) amountLP = capAmountLP;
amountGD = _burnLP(from, amountLP);
$._deltaCredit = deltaCredit_ - amountGD;
uint256 amountLD = _GDToLD(amountGD);
_safeTransferWithRevert($._token, to, amountLD);
emit WithdrawInstant(from, amountLP, amountGD, to);
}
/**
* @dev Receives delta info and fees from the peer pool to keep the delta consistent.
*/
function handleRecvFailure(
uint256 peerChainId,
uint256 peerPoolId,
address /* to */,
ITransferPoolFeeCalculator.FeeInfo memory feeInfo
) public nonReentrant onlyRole(DEFAULT_ROUTER_ROLE) {
PoolStorage storage $ = _getPoolStorage();
_recvFees($, feeInfo);
_decreaseLastKnownBalance(
peerChainId,
peerPoolId,
feeInfo.balanceDecrease
);
}
/**
* @dev Receive delta info ( and re-mint lp token ) to keep the delta consistent.
*/
function handleWithdrawConfirmFailure(
uint256 peerChainId,
uint256 peerPoolId,
address to,
uint256 amountGD,
uint256 amountToMintGD
) public nonReentrant onlyRole(DEFAULT_ROUTER_ROLE) {
// 1. mint lp token on local if possible
if (amountToMintGD > 0 && to != address(0x0)) {
_mintLPbyLD(to, _GDToLD(amountToMintGD), false);
}
// 2. update last known balance
_decreaseLastKnownBalance(peerChainId, peerPoolId, amountGD);
}
// ========================== view functions ===================================
function feeCalculator() public view returns (address) {
return _getPoolStorage()._feeCalculator;
}
function peerPoolInfos(
uint256 index
) public view returns (PeerPoolInfo memory) {
return _getPoolStorage()._peerPoolInfos[index];
}
function peerPoolInfoIndexSeek(
uint256 peerChainId,
uint256 peerPoolId
) public view returns (uint256) {
return
_getPoolStorage()._peerPoolInfoIndexSeek[peerChainId][peerPoolId];
}
function totalLiquidity() public view returns (uint256) {
return _getPoolStorage()._totalLiquidity;
}
function totalWeight() public view returns (uint256) {
return _getPoolStorage()._totalWeight;
}
function deltaCredit() public view returns (uint256) {
return _getPoolStorage()._deltaCredit;
}
function batched() public view returns (bool) {
return _getPoolStorage()._batched;
}
function defaultSwapMode() public view returns (bool) {
return _getPoolStorage()._defaultSwapMode;
}
function defaultLPMode() public view returns (bool) {
return _getPoolStorage()._defaultLPMode;
}
function feeBalance() public view returns (uint256) {
return _getPoolStorage()._feeBalance;
}
function eqFeePool() public view returns (uint256) {
return _getPoolStorage()._eqFeePool;
}
function swapDeltaBP() public view returns (uint256) {
return _getPoolStorage()._swapDeltaBP;
}
function lpDeltaBP() public view returns (uint256) {
return _getPoolStorage()._lpDeltaBP;
}
function poolId() public view returns (uint256) {
return _getPoolStorage()._poolId;
}
function token() public view returns (address) {
return _getPoolStorage()._token;
}
function transferStop() public view returns (bool) {
return _getPoolStorage()._transferStop;
}
function maxTotalDeposits() public view returns (uint256) {
return _getPoolStorage()._maxTotalDeposits;
}
// ========================== override functions ===============================
function decimals() public view virtual override returns (uint8) {
return globalDecimals();
}
// ========================== internal functions ===============================
//-----------------------------------------------------------------------------------
// heavily used functions
//-----------------------------------------------------------------------------------
function _safeTransferWithRevert(
address token_,
address to,
uint256 value
) internal {
if (!_safeTransfer(token_, to, value)) {
revert TokiTransferIsFailed(token_, to, value);
}
}
function _safeTransfer(
address token_,
address to,
uint256 value
) internal returns (bool) {
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = token_.call(
abi.encodeCall(IERC20(token_).transfer, (to, value))
);
if (success && returndata.length != 0) {
return abi.decode(returndata, (bool));
}
return success;
}
function _mintLPbyLD(
address to,
uint256 amountLD,
bool creditDelta
) internal returns (uint256 amountAssetGD) {
PoolStorage storage $ = _getPoolStorage();
if ($._totalWeight == 0) {
revert TokiZeroValue("totalWeight");
}
amountAssetGD = _LDToGD(amountLD);
if (creditDelta) {
$._deltaCredit = $._deltaCredit + amountAssetGD;
}
uint256 amountLPTokens = amountAssetGD;
if (totalSupply() != 0) {
amountLPTokens =
(amountAssetGD * totalSupply()) /
$._totalLiquidity;
}
$._totalLiquidity = $._totalLiquidity + amountAssetGD;
_mint(to, amountLPTokens);
emit Mint(to, amountLPTokens, amountAssetGD);
if (
!$._batched ||
$._deltaCredit >
($._totalLiquidity * $._lpDeltaBP) / BPS_DENOMINATOR
) {
_deltaSourceUpdate($._defaultLPMode);
}
}
function _mintLPbyLDWithLimitCheck(
address to,
uint256 amountLD,
bool creditDelta
) internal checkMaxTotalDeposits(amountLD) returns (uint256 amountAssetGD) {
return _mintLPbyLD(to, amountLD, creditDelta);
}
function _burnLP(
address from,
uint256 amountLP
) internal returns (uint256) {
PoolStorage storage $ = _getPoolStorage();
if (totalSupply() == 0) {
revert TokiZeroValue("totalSupply");
}
uint256 balance = balanceOf(from);
if (balance < amountLP) {
revert TokiExceed("Pool._burnLP.amountLP", amountLP, balance);
}
uint256 amountGD = (amountLP * $._totalLiquidity) / totalSupply();
$._totalLiquidity = $._totalLiquidity - amountGD;
_burn(from, amountLP);
emit Burn(from, amountLP, amountGD);
return amountGD;
}
/**
* @dev _deltaSourceUpdate implements the delta algorithm, and balances liquidity across peer pools on different chains is only done
* if there's positive deltaCredit and totalWeight.
*
* The following steps are done when deltaSourceUpdate is done:
* 1: Difference Calculation
* The difference between the ideal balance (balLiq) and current balance (currLiq) for each peer pool is calculated.
* The sum of the total difference (totalDiff) is also calculated.
* 2 : Credit Distribution
* Handles three scenarios based on the relationship between totalDiff and deltaCredit:
* - Scenario 1: If totalDiff is 0:
* In fullMode, distributes excess credits proportionally based on weights. Otherwise, nothing is done.
* - Scenario 2: If deltaCredit is lesser than totalDiff:
* Calculates the differences based on available deltaCredit, and distributes credits proportionally to the normalized differences.
* Updates the credits for each peer pool based on the calculated distribution.
* - Scenario 3: If deltaCredit is greater than or equal to totalDiff:
* In fullMode, distributes all differences plus excess credits proportionally. Otherwise, it distributes only the calculated differences.
* Updates the credits for each peer pool based on the calculated distribution.
* 3. Delta Credit Update:
* Reduces deltaCredit by the total amount spent.
*/
function _deltaSourceUpdate(bool fullMode) internal {
PoolStorage storage $ = _getPoolStorage();
if ($._deltaCredit > 0 && $._totalWeight > 0) {
uint256 peerPoolInfosLength = $._peerPoolInfos.length;
uint256[] memory diff = new uint256[](peerPoolInfosLength);
uint256 totalDiff = 0;
// delta algorithm 6-9 lines
for (uint256 i = 0; i < peerPoolInfosLength; ++i) {
PeerPoolInfo storage peerPoolInfo = $._peerPoolInfos[i];
// (totalLiquidity * (weight/totalWeight)) - (lastKnownBalance+credits)
uint256 balLiq = ($._totalLiquidity * peerPoolInfo.weight) /
$._totalWeight;
uint256 currLiq = peerPoolInfo.lastKnownBalance +
peerPoolInfo.credits;
// max(0, lp_s * w_{s,x} − (lkb_{x,s} + c_{s,x}))
if (balLiq > currLiq) {
diff[i] = balLiq - currLiq;
totalDiff = totalDiff + diff[i];
}
}
// Indicates how much deltacredit is spent.
uint256 spent = 0;
if (totalDiff == 0) {
// If fullMode delta will use excess credits
if (fullMode && $._deltaCredit > 0) {
for (uint256 i = 0; i < peerPoolInfosLength; ++i) {
PeerPoolInfo storage peerPoolInfo = $._peerPoolInfos[i];
// same as delta algorithm 10-12 lines: diff_{s,x} <- min(Total,t) * diff_{s,x} / totalDiff
uint256 amtToCredit = ($._deltaCredit *
peerPoolInfo.weight) / $._totalWeight;
spent = spent + amtToCredit;
peerPoolInfo.credits =
peerPoolInfo.credits +
amtToCredit;
}
} // else do nth
} else if ($._deltaCredit < totalDiff) {
// deltaCredit < totalDiff , fullMode or not, normalize the diff by deltaCredit
for (uint256 i = 0; i < peerPoolInfosLength; ++i) {
if (diff[i] > 0) {
PeerPoolInfo storage peerPoolInfo = $._peerPoolInfos[i];
// delta algorithm 10-12 lines: diff_{s,x} <- min(Total,t) * diff_{s,x} / totalDiff
diff[i] = (diff[i] * $._deltaCredit) / totalDiff;
// delta algorithm 13-16 lines:
spent = spent + diff[i];
peerPoolInfo.credits = peerPoolInfo.credits + diff[i];
}
}
} else {
// totalDiff <= deltaCredit
// delta algorithm 13-16 lines:
if (fullMode) {
uint256 excessCredit = $._deltaCredit - totalDiff;
for (uint256 i = 0; i < peerPoolInfosLength; ++i) {
PeerPoolInfo storage peerPoolInfo = $._peerPoolInfos[i];
// credits = credits + diff[i] + exceedCredit * (weight / totalWeight)
uint256 amtToCredit = diff[i] +
(excessCredit * peerPoolInfo.weight) /
$._totalWeight;
spent = spent + amtToCredit;
peerPoolInfo.credits =
peerPoolInfo.credits +
amtToCredit;
}
} else {
// totaldiff <= deltaCredit but not running fullMode
// A diff in peerPool, credit it as is and do not use all deltaCredit.
for (uint256 i = 0; i < peerPoolInfosLength; ++i) {
if (diff[i] > 0) {
PeerPoolInfo storage peerPoolInfo = $
._peerPoolInfos[i];
spent = spent + diff[i];
peerPoolInfo.credits =
peerPoolInfo.credits +
diff[i];
}
}
}
}
// deltaCredit spent.
$._deltaCredit = $._deltaCredit - spent;
}
}
function _decreaseLastKnownBalance(
uint256 peerChainId,
uint256 peerPoolId,
uint256 amountGD
) internal {
PeerPoolInfo storage peerPoolInfo = _getAndCheckPeerPoolInfo(
peerChainId,
peerPoolId
);
peerPoolInfo.lastKnownBalance =
peerPoolInfo.lastKnownBalance -
amountGD;
}
function _recvFees(
PoolStorage storage $,
ITransferPoolFeeCalculator.FeeInfo memory feeInfo
) internal {
$._totalLiquidity += feeInfo.lpFee;
$._eqFeePool += feeInfo.eqFee;
$._feeBalance += feeInfo.protocolFee;
}
function _authorizeUpgrade(
address
) internal override onlyRole(DEFAULT_ADMIN_ROLE) {}
//-----------------------------------------------------------------------------------
// Helper functions
//-----------------------------------------------------------------------------------
function _getAndCheckPeerPoolInfo(
uint256 peerChainId,
uint256 peerPoolId
) internal view returns (PeerPoolInfo storage peerPoolInfo) {
PoolStorage storage $ = _getPoolStorage();
if ($._peerPoolInfos.length == 0) {
revert TokiNoPeerPoolInfo();
}
peerPoolInfo = $._peerPoolInfos[
$._peerPoolInfoIndexSeek[peerChainId][peerPoolId]
];
if (
peerPoolInfo.chainId != peerChainId || peerPoolInfo.id != peerPoolId
) {
revert TokiPeerPoolInfoNotFound(peerChainId, peerPoolId);
}
}
// solhint-disable-next-line func-name-mixedcase
function _LPToGD(uint256 amountLP) internal view returns (uint256) {
PoolStorage storage $ = _getPoolStorage();
if (totalSupply() == 0) {
revert TokiZeroValue("totalSupply");
}
return (amountLP * $._totalLiquidity) / totalSupply();
}
// solhint-disable-next-line func-name-mixedcase
function _GDToLP(uint256 amountGD) internal view returns (uint256) {
PoolStorage storage $ = _getPoolStorage();
if ($._totalLiquidity == 0) {
revert TokiZeroValue("totalLiquidity");
}
return (amountGD * totalSupply()) / $._totalLiquidity;
}
function tokenBalanceOfThisPoolInGD() internal view returns (uint256) {
PoolStorage storage $ = _getPoolStorage();
return _LDToGD(IERC20($._token).balanceOf(address(this)));
}
function _getPoolStorage() private pure returns (PoolStorage storage $) {
// solhint-disable-next-line no-inline-assembly
assembly {
$.slot := POOL_LOCATION
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (access/AccessControl.sol)
pragma solidity ^0.8.20;
import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {ERC165Upgradeable} from "../utils/introspection/ERC165Upgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```solidity
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```solidity
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
* to enforce additional security measures for this role.
*/
abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControl, ERC165Upgradeable {
struct RoleData {
mapping(address account => bool) hasRole;
bytes32 adminRole;
}
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/// @custom:storage-location erc7201:openzeppelin.storage.AccessControl
struct AccessControlStorage {
mapping(bytes32 role => RoleData) _roles;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.AccessControl")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant AccessControlStorageLocation = 0x02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800;
function _getAccessControlStorage() private pure returns (AccessControlStorage storage $) {
assembly {
$.slot := AccessControlStorageLocation
}
}
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with an {AccessControlUnauthorizedAccount} error including the required role.
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
function __AccessControl_init() internal onlyInitializing {
}
function __AccessControl_init_unchained() internal onlyInitializing {
}
/// @inheritdoc IERC165
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual returns (bool) {
AccessControlStorage storage $ = _getAccessControlStorage();
return $._roles[role].hasRole[account];
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
* is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
* is missing `role`.
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert AccessControlUnauthorizedAccount(account, role);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
AccessControlStorage storage $ = _getAccessControlStorage();
return $._roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleGranted} event.
*/
function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleRevoked} event.
*/
function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `callerConfirmation`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address callerConfirmation) public virtual {
if (callerConfirmation != _msgSender()) {
revert AccessControlBadConfirmation();
}
_revokeRole(role, callerConfirmation);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
AccessControlStorage storage $ = _getAccessControlStorage();
bytes32 previousAdminRole = getRoleAdmin(role);
$._roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
AccessControlStorage storage $ = _getAccessControlStorage();
if (!hasRole(role, account)) {
$._roles[role].hasRole[account] = true;
emit RoleGranted(role, account, _msgSender());
return true;
} else {
return false;
}
}
/**
* @dev Attempts to revoke `role` from `account` and returns a boolean indicating if `role` was revoked.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
AccessControlStorage storage $ = _getAccessControlStorage();
if (hasRole(role, account)) {
$._roles[role].hasRole[account] = false;
emit RoleRevoked(role, account, _msgSender());
return true;
} else {
return false;
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.20;
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Storage of the initializable contract.
*
* It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
* when using with upgradeable contracts.
*
* @custom:storage-location erc7201:openzeppelin.storage.Initializable
*/
struct InitializableStorage {
/**
* @dev Indicates that the contract has been initialized.
*/
uint64 _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool _initializing;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;
/**
* @dev The contract is already initialized.
*/
error InvalidInitialization();
/**
* @dev The contract is not initializing.
*/
error NotInitializing();
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint64 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
* number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
* production.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
// Cache values to avoid duplicated sloads
bool isTopLevelCall = !$._initializing;
uint64 initialized = $._initialized;
// Allowed calls:
// - initialSetup: the contract is not in the initializing state and no previous version was
// initialized
// - construction: the contract is initialized at version 1 (no reinitialization) and the
// current contract is just being deployed
bool initialSetup = initialized == 0 && isTopLevelCall;
bool construction = initialized == 1 && address(this).code.length == 0;
if (!initialSetup && !construction) {
revert InvalidInitialization();
}
$._initialized = 1;
if (isTopLevelCall) {
$._initializing = true;
}
_;
if (isTopLevelCall) {
$._initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint64 version) {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing || $._initialized >= version) {
revert InvalidInitialization();
}
$._initialized = version;
$._initializing = true;
_;
$._initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
_checkInitializing();
_;
}
/**
* @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
*/
function _checkInitializing() internal view virtual {
if (!_isInitializing()) {
revert NotInitializing();
}
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing) {
revert InvalidInitialization();
}
if ($._initialized != type(uint64).max) {
$._initialized = type(uint64).max;
emit Initialized(type(uint64).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint64) {
return _getInitializableStorage()._initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _getInitializableStorage()._initializing;
}
/**
* @dev Pointer to storage slot. Allows integrators to override it with a custom storage location.
*
* NOTE: Consider following the ERC-7201 formula to derive storage locations.
*/
function _initializableStorageSlot() internal pure virtual returns (bytes32) {
return INITIALIZABLE_STORAGE;
}
/**
* @dev Returns a pointer to the storage namespace.
*/
// solhint-disable-next-line var-name-mixedcase
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
bytes32 slot = _initializableStorageSlot();
assembly {
$.slot := slot
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/utils/UUPSUpgradeable.sol)
pragma solidity ^0.8.22;
import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
import {Initializable} from "./Initializable.sol";
/**
* @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
* {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
*
* A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
* reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
* `UUPSUpgradeable` with a custom implementation of upgrades.
*
* The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
*/
abstract contract UUPSUpgradeable is Initializable, IERC1822Proxiable {
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address private immutable __self = address(this);
/**
* @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)`
* and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,
* while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string.
* If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must
* be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
* during an upgrade.
*/
string public constant UPGRADE_INTERFACE_VERSION = "5.0.0";
/**
* @dev The call is from an unauthorized context.
*/
error UUPSUnauthorizedCallContext();
/**
* @dev The storage `slot` is unsupported as a UUID.
*/
error UUPSUnsupportedProxiableUUID(bytes32 slot);
/**
* @dev Check that the execution is being performed through a delegatecall call and that the execution context is
* a proxy contract with an implementation (as defined in ERC-1967) pointing to self. This should only be the case
* for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
* function through ERC-1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
* fail.
*/
modifier onlyProxy() {
_checkProxy();
_;
}
/**
* @dev Check that the execution is not being performed through a delegate call. This allows a function to be
* callable on the implementing contract but not through proxies.
*/
modifier notDelegated() {
_checkNotDelegated();
_;
}
function __UUPSUpgradeable_init() internal onlyInitializing {
}
function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
}
/**
* @dev Implementation of the ERC-1822 {proxiableUUID} function. This returns the storage slot used by the
* implementation. It is used to validate the implementation's compatibility when performing an upgrade.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
*/
function proxiableUUID() external view virtual notDelegated returns (bytes32) {
return ERC1967Utils.IMPLEMENTATION_SLOT;
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
* encoded in `data`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*
* @custom:oz-upgrades-unsafe-allow-reachable delegatecall
*/
function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, data);
}
/**
* @dev Reverts if the execution is not performed via delegatecall or the execution
* context is not of a proxy with an ERC-1967 compliant implementation pointing to self.
*/
function _checkProxy() internal view virtual {
if (
address(this) == __self || // Must be called through delegatecall
ERC1967Utils.getImplementation() != __self // Must be called through an active proxy
) {
revert UUPSUnauthorizedCallContext();
}
}
/**
* @dev Reverts if the execution is performed via delegatecall.
* See {notDelegated}.
*/
function _checkNotDelegated() internal view virtual {
if (address(this) != __self) {
// Must not be called through delegatecall
revert UUPSUnauthorizedCallContext();
}
}
/**
* @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
* {upgradeToAndCall}.
*
* Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
*
* ```solidity
* function _authorizeUpgrade(address) internal onlyOwner {}
* ```
*/
function _authorizeUpgrade(address newImplementation) internal virtual;
/**
* @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call.
*
* As a security check, {proxiableUUID} is invoked in the new implementation, and the return value
* is expected to be the implementation slot in ERC-1967.
*
* Emits an {IERC1967-Upgraded} event.
*/
function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private {
try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) {
revert UUPSUnsupportedProxiableUUID(slot);
}
ERC1967Utils.upgradeToAndCall(newImplementation, data);
} catch {
// The implementation is not UUPS
revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {ContextUpgradeable} from "../../utils/ContextUpgradeable.sol";
import {IERC20Errors} from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
import {Initializable} from "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC-20
* applications.
*/
abstract contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20, IERC20Metadata, IERC20Errors {
/// @custom:storage-location erc7201:openzeppelin.storage.ERC20
struct ERC20Storage {
mapping(address account => uint256) _balances;
mapping(address account => mapping(address spender => uint256)) _allowances;
uint256 _totalSupply;
string _name;
string _symbol;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ERC20")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant ERC20StorageLocation = 0x52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace00;
function _getERC20Storage() private pure returns (ERC20Storage storage $) {
assembly {
$.slot := ERC20StorageLocation
}
}
/**
* @dev Sets the values for {name} and {symbol}.
*
* Both values are immutable: they can only be set once during construction.
*/
function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing {
__ERC20_init_unchained(name_, symbol_);
}
function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing {
ERC20Storage storage $ = _getERC20Storage();
$._name = name_;
$._symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
ERC20Storage storage $ = _getERC20Storage();
return $._name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
ERC20Storage storage $ = _getERC20Storage();
return $._symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
return 18;
}
/// @inheritdoc IERC20
function totalSupply() public view virtual returns (uint256) {
ERC20Storage storage $ = _getERC20Storage();
return $._totalSupply;
}
/// @inheritdoc IERC20
function balanceOf(address account) public view virtual returns (uint256) {
ERC20Storage storage $ = _getERC20Storage();
return $._balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
*/
function transfer(address to, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_transfer(owner, to, value);
return true;
}
/// @inheritdoc IERC20
function allowance(address owner, address spender) public view virtual returns (uint256) {
ERC20Storage storage $ = _getERC20Storage();
return $._allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Skips emitting an {Approval} event indicating an allowance update. This is not
* required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `value`.
* - the caller must have allowance for ``from``'s tokens of at least
* `value`.
*/
function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, value);
_transfer(from, to, value);
return true;
}
/**
* @dev Moves a `value` amount of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _transfer(address from, address to, uint256 value) internal {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(from, to, value);
}
/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
* this function.
*
* Emits a {Transfer} event.
*/
function _update(address from, address to, uint256 value) internal virtual {
ERC20Storage storage $ = _getERC20Storage();
if (from == address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
$._totalSupply += value;
} else {
uint256 fromBalance = $._balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
$._balances[from] = fromBalance - value;
}
}
if (to == address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
$._totalSupply -= value;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
$._balances[to] += value;
}
}
emit Transfer(from, to, value);
}
/**
* @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
* Relies on the `_update` mechanism
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _mint(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
* Relies on the `_update` mechanism.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead
*/
function _burn(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidSender(address(0));
}
_update(account, address(0), value);
}
/**
* @dev Sets `value` as the allowance of `spender` over the `owner`'s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address owner, address spender, uint256 value) internal {
_approve(owner, spender, value, true);
}
/**
* @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
*
* By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
* `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
* `Approval` event during `transferFrom` operations.
*
* Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
* true using the following override:
*
* ```solidity
* function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
* super._approve(owner, spender, value, true);
* }
* ```
*
* Requirements are the same as {_approve}.
*/
function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
ERC20Storage storage $ = _getERC20Storage();
if (owner == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
$._allowances[owner][spender] = value;
if (emitEvent) {
emit Approval(owner, spender, value);
}
}
/**
* @dev Updates `owner`'s allowance for `spender` based on spent `value`.
*
* Does not update the allowance value in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Does not emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance < type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner, spender, currentAllowance - value, false);
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/extensions/ERC20Permit.sol)
pragma solidity ^0.8.20;
import {IERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol";
import {ERC20Upgradeable} from "../ERC20Upgradeable.sol";
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import {EIP712Upgradeable} from "../../../utils/cryptography/EIP712Upgradeable.sol";
import {NoncesUpgradeable} from "../../../utils/NoncesUpgradeable.sol";
import {Initializable} from "../../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the ERC-20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[ERC-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC-20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
abstract contract ERC20PermitUpgradeable is Initializable, ERC20Upgradeable, IERC20Permit, EIP712Upgradeable, NoncesUpgradeable {
bytes32 private constant PERMIT_TYPEHASH =
keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
/**
* @dev Permit deadline has expired.
*/
error ERC2612ExpiredSignature(uint256 deadline);
/**
* @dev Mismatched signature.
*/
error ERC2612InvalidSigner(address signer, address owner);
/**
* @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`.
*
* It's a good idea to use the same `name` that is defined as the ERC-20 token name.
*/
function __ERC20Permit_init(string memory name) internal onlyInitializing {
__EIP712_init_unchained(name, "1");
}
function __ERC20Permit_init_unchained(string memory) internal onlyInitializing {}
/// @inheritdoc IERC20Permit
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
if (block.timestamp > deadline) {
revert ERC2612ExpiredSignature(deadline);
}
bytes32 structHash = keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline));
bytes32 hash = _hashTypedDataV4(structHash);
address signer = ECDSA.recover(hash, v, r, s);
if (signer != owner) {
revert ERC2612InvalidSigner(signer, owner);
}
_approve(owner, spender, value);
}
/// @inheritdoc IERC20Permit
function nonces(address owner) public view virtual override(IERC20Permit, NoncesUpgradeable) returns (uint256) {
return super.nonces(owner);
}
/// @inheritdoc IERC20Permit
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view virtual returns (bytes32) {
return _domainSeparatorV4();
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/cryptography/EIP712.sol)
pragma solidity ^0.8.20;
import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import {IERC5267} from "@openzeppelin/contracts/interfaces/IERC5267.sol";
import {Initializable} from "../../proxy/utils/Initializable.sol";
/**
* @dev https://eips.ethereum.org/EIPS/eip-712[EIP-712] is a standard for hashing and signing of typed structured data.
*
* The encoding scheme specified in the EIP requires a domain separator and a hash of the typed structured data, whose
* encoding is very generic and therefore its implementation in Solidity is not feasible, thus this contract
* does not implement the encoding itself. Protocols need to implement the type-specific encoding they need in order to
* produce the hash of their typed data using a combination of `abi.encode` and `keccak256`.
*
* This contract implements the EIP-712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
* scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
* ({_hashTypedDataV4}).
*
* The implementation of the domain separator was designed to be as efficient as possible while still properly updating
* the chain id to protect against replay attacks on an eventual fork of the chain.
*
* NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
* https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
*
* NOTE: The upgradeable version of this contract does not use an immutable cache and recomputes the domain separator
* each time {_domainSeparatorV4} is called. That is cheaper than accessing a cached version in cold storage.
*/
abstract contract EIP712Upgradeable is Initializable, IERC5267 {
bytes32 private constant TYPE_HASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
/// @custom:storage-location erc7201:openzeppelin.storage.EIP712
struct EIP712Storage {
/// @custom:oz-renamed-from _HASHED_NAME
bytes32 _hashedName;
/// @custom:oz-renamed-from _HASHED_VERSION
bytes32 _hashedVersion;
string _name;
string _version;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.EIP712")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant EIP712StorageLocation = 0xa16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d100;
function _getEIP712Storage() private pure returns (EIP712Storage storage $) {
assembly {
$.slot := EIP712StorageLocation
}
}
/**
* @dev Initializes the domain separator and parameter caches.
*
* The meaning of `name` and `version` is specified in
* https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP-712]:
*
* - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
* - `version`: the current major version of the signing domain.
*
* NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
* contract upgrade].
*/
function __EIP712_init(string memory name, string memory version) internal onlyInitializing {
__EIP712_init_unchained(name, version);
}
function __EIP712_init_unchained(string memory name, string memory version) internal onlyInitializing {
EIP712Storage storage $ = _getEIP712Storage();
$._name = name;
$._version = version;
// Reset prior values in storage if upgrading
$._hashedName = 0;
$._hashedVersion = 0;
}
/**
* @dev Returns the domain separator for the current chain.
*/
function _domainSeparatorV4() internal view returns (bytes32) {
return _buildDomainSeparator();
}
function _buildDomainSeparator() private view returns (bytes32) {
return keccak256(abi.encode(TYPE_HASH, _EIP712NameHash(), _EIP712VersionHash(), block.chainid, address(this)));
}
/**
* @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
* function returns the hash of the fully encoded EIP712 message for this domain.
*
* This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
*
* ```solidity
* bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
* keccak256("Mail(address to,string contents)"),
* mailTo,
* keccak256(bytes(mailContents))
* )));
* address signer = ECDSA.recover(digest, signature);
* ```
*/
function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
return MessageHashUtils.toTypedDataHash(_domainSeparatorV4(), structHash);
}
/// @inheritdoc IERC5267
function eip712Domain()
public
view
virtual
returns (
bytes1 fields,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
)
{
EIP712Storage storage $ = _getEIP712Storage();
// If the hashed name and version in storage are non-zero, the contract hasn't been properly initialized
// and the EIP712 domain is not reliable, as it will be missing name and version.
require($._hashedName == 0 && $._hashedVersion == 0, "EIP712: Uninitialized");
return (
hex"0f", // 01111
_EIP712Name(),
_EIP712Version(),
block.chainid,
address(this),
bytes32(0),
new uint256[](0)
);
}
/**
* @dev The name parameter for the EIP712 domain.
*
* NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs
* are a concern.
*/
function _EIP712Name() internal view virtual returns (string memory) {
EIP712Storage storage $ = _getEIP712Storage();
return $._name;
}
/**
* @dev The version parameter for the EIP712 domain.
*
* NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs
* are a concern.
*/
function _EIP712Version() internal view virtual returns (string memory) {
EIP712Storage storage $ = _getEIP712Storage();
return $._version;
}
/**
* @dev The hash of the name parameter for the EIP712 domain.
*
* NOTE: In previous versions this function was virtual. In this version you should override `_EIP712Name` instead.
*/
function _EIP712NameHash() internal view returns (bytes32) {
EIP712Storage storage $ = _getEIP712Storage();
string memory name = _EIP712Name();
if (bytes(name).length > 0) {
return keccak256(bytes(name));
} else {
// If the name is empty, the contract may have been upgraded without initializing the new storage.
// We return the name hash in storage if non-zero, otherwise we assume the name is empty by design.
bytes32 hashedName = $._hashedName;
if (hashedName != 0) {
return hashedName;
} else {
return keccak256("");
}
}
}
/**
* @dev The hash of the version parameter for the EIP712 domain.
*
* NOTE: In previous versions this function was virtual. In this version you should override `_EIP712Version` instead.
*/
function _EIP712VersionHash() internal view returns (bytes32) {
EIP712Storage storage $ = _getEIP712Storage();
string memory version = _EIP712Version();
if (bytes(version).length > 0) {
return keccak256(bytes(version));
} else {
// If the version is empty, the contract may have been upgraded without initializing the new storage.
// We return the version hash in storage if non-zero, otherwise we assume the version is empty by design.
bytes32 hashedVersion = $._hashedVersion;
if (hashedVersion != 0) {
return hashedVersion;
} else {
return keccak256("");
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {Initializable} from "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*/
abstract contract ERC165Upgradeable is Initializable, IERC165 {
function __ERC165_init() internal onlyInitializing {
}
function __ERC165_init_unchained() internal onlyInitializing {
}
/// @inheritdoc IERC165
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Nonces.sol)
pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Provides tracking nonces for addresses. Nonces will only increment.
*/
abstract contract NoncesUpgradeable is Initializable {
/**
* @dev The nonce used for an `account` is not the expected current nonce.
*/
error InvalidAccountNonce(address account, uint256 currentNonce);
/// @custom:storage-location erc7201:openzeppelin.storage.Nonces
struct NoncesStorage {
mapping(address account => uint256) _nonces;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Nonces")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant NoncesStorageLocation = 0x5ab42ced628888259c08ac98db1eb0cf702fc1501344311d8b100cd1bfe4bb00;
function _getNoncesStorage() private pure returns (NoncesStorage storage $) {
assembly {
$.slot := NoncesStorageLocation
}
}
function __Nonces_init() internal onlyInitializing {
}
function __Nonces_init_unchained() internal onlyInitializing {
}
/**
* @dev Returns the next unused nonce for an address.
*/
function nonces(address owner) public view virtual returns (uint256) {
NoncesStorage storage $ = _getNoncesStorage();
return $._nonces[owner];
}
/**
* @dev Consumes a nonce.
*
* Returns the current value and increments nonce.
*/
function _useNonce(address owner) internal virtual returns (uint256) {
NoncesStorage storage $ = _getNoncesStorage();
// For each account, the nonce has an initial value of 0, can only be incremented by one, and cannot be
// decremented or reset. This guarantees that the nonce never overflows.
unchecked {
// It is important to do x++ and not ++x here.
return $._nonces[owner]++;
}
}
/**
* @dev Same as {_useNonce} but checking that `nonce` is the next valid for `owner`.
*/
function _useCheckedNonce(address owner, uint256 nonce) internal virtual {
uint256 current = _useNonce(owner);
if (nonce != current) {
revert InvalidAccountNonce(owner, current);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/ReentrancyGuardTransient.sol)
pragma solidity ^0.8.24;
import {TransientSlot} from "@openzeppelin/contracts/utils/TransientSlot.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Variant of {ReentrancyGuard} that uses transient storage.
*
* NOTE: This variant only works on networks where EIP-1153 is available.
*
* _Available since v5.1._
*/
abstract contract ReentrancyGuardTransientUpgradeable is Initializable {
using TransientSlot for *;
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant REENTRANCY_GUARD_STORAGE =
0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function __ReentrancyGuardTransient_init() internal onlyInitializing {
}
function __ReentrancyGuardTransient_init_unchained() internal onlyInitializing {
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, REENTRANCY_GUARD_STORAGE.asBoolean().tload() will be false
if (_reentrancyGuardEntered()) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
REENTRANCY_GUARD_STORAGE.asBoolean().tstore(true);
}
function _nonReentrantAfter() private {
REENTRANCY_GUARD_STORAGE.asBoolean().tstore(false);
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return REENTRANCY_GUARD_STORAGE.asBoolean().tload();
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (access/IAccessControl.sol)
pragma solidity >=0.8.4;
/**
* @dev External interface of AccessControl declared to support ERC-165 detection.
*/
interface IAccessControl {
/**
* @dev The `account` is missing a role.
*/
error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);
/**
* @dev The caller of a function is not the expected one.
*
* NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
*/
error AccessControlBadConfirmation();
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted to signal this.
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call. This account bears the admin role (for the granted role).
* Expected in cases where the role was granted using the internal {AccessControl-_grantRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `callerConfirmation`.
*/
function renounceRole(bytes32 role, address callerConfirmation) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/draft-IERC1822.sol)
pragma solidity >=0.4.16;
/**
* @dev ERC-1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
* proxy whose upgrades are fully controlled by the current implementation.
*/
interface IERC1822Proxiable {
/**
* @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
* address.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy.
*/
function proxiableUUID() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/draft-IERC6093.sol)
pragma solidity >=0.8.4;
/**
* @dev Standard ERC-20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC-721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC-1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)
pragma solidity >=0.6.2;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)
pragma solidity >=0.4.16;
import {IERC165} from "../utils/introspection/IERC165.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1967.sol)
pragma solidity >=0.4.11;
/**
* @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.
*/
interface IERC1967 {
/**
* @dev Emitted when the implementation is upgraded.
*/
event Upgraded(address indexed implementation);
/**
* @dev Emitted when the admin account has changed.
*/
event AdminChanged(address previousAdmin, address newAdmin);
/**
* @dev Emitted when the beacon is changed.
*/
event BeaconUpgraded(address indexed beacon);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)
pragma solidity >=0.4.16;
import {IERC20} from "../token/ERC20/IERC20.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC5267.sol)
pragma solidity >=0.4.16;
interface IERC5267 {
/**
* @dev MAY be emitted to signal that the domain could have changed.
*/
event EIP712DomainChanged();
/**
* @dev returns the fields and values that describe the domain separator used by this contract for EIP-712
* signature.
*/
function eip712Domain()
external
view
returns (
bytes1 fields,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (proxy/beacon/IBeacon.sol)
pragma solidity >=0.4.16;
/**
* @dev This is the interface that {BeaconProxy} expects of its beacon.
*/
interface IBeacon {
/**
* @dev Must return an address that can be used as a delegate call target.
*
* {UpgradeableBeacon} will check that this address is a contract.
*/
function implementation() external view returns (address);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (proxy/ERC1967/ERC1967Utils.sol)
pragma solidity ^0.8.21;
import {IBeacon} from "../beacon/IBeacon.sol";
import {IERC1967} from "../../interfaces/IERC1967.sol";
import {Address} from "../../utils/Address.sol";
import {StorageSlot} from "../../utils/StorageSlot.sol";
/**
* @dev This library provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[ERC-1967] slots.
*/
library ERC1967Utils {
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev The `implementation` of the proxy is invalid.
*/
error ERC1967InvalidImplementation(address implementation);
/**
* @dev The `admin` of the proxy is invalid.
*/
error ERC1967InvalidAdmin(address admin);
/**
* @dev The `beacon` of the proxy is invalid.
*/
error ERC1967InvalidBeacon(address beacon);
/**
* @dev An upgrade function sees `msg.value > 0` that may be lost.
*/
error ERC1967NonPayable();
/**
* @dev Returns the current implementation address.
*/
function getImplementation() internal view returns (address) {
return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the ERC-1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
if (newImplementation.code.length == 0) {
revert ERC1967InvalidImplementation(newImplementation);
}
StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Performs implementation upgrade with additional setup call if data is nonempty.
* This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
* to avoid stuck value in the contract.
*
* Emits an {IERC1967-Upgraded} event.
*/
function upgradeToAndCall(address newImplementation, bytes memory data) internal {
_setImplementation(newImplementation);
emit IERC1967.Upgraded(newImplementation);
if (data.length > 0) {
Address.functionDelegateCall(newImplementation, data);
} else {
_checkNonPayable();
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Returns the current admin.
*
* TIP: To get this value clients can read directly from the storage slot shown below (specified by ERC-1967) using
* the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
* `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
*/
function getAdmin() internal view returns (address) {
return StorageSlot.getAddressSlot(ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the ERC-1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
if (newAdmin == address(0)) {
revert ERC1967InvalidAdmin(address(0));
}
StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {IERC1967-AdminChanged} event.
*/
function changeAdmin(address newAdmin) internal {
emit IERC1967.AdminChanged(getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Returns the current beacon.
*/
function getBeacon() internal view returns (address) {
return StorageSlot.getAddressSlot(BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the ERC-1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
if (newBeacon.code.length == 0) {
revert ERC1967InvalidBeacon(newBeacon);
}
StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;
address beaconImplementation = IBeacon(newBeacon).implementation();
if (beaconImplementation.code.length == 0) {
revert ERC1967InvalidImplementation(beaconImplementation);
}
}
/**
* @dev Change the beacon and trigger a setup call if data is nonempty.
* This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
* to avoid stuck value in the contract.
*
* Emits an {IERC1967-BeaconUpgraded} event.
*
* CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since
* it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for
* efficiency.
*/
function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal {
_setBeacon(newBeacon);
emit IERC1967.BeaconUpgraded(newBeacon);
if (data.length > 0) {
Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
} else {
_checkNonPayable();
}
}
/**
* @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract
* if an upgrade doesn't perform an initialization call.
*/
function _checkNonPayable() private {
if (msg.value > 0) {
revert ERC1967NonPayable();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity >=0.6.2;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC-20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[ERC-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC-20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/Address.sol)
pragma solidity ^0.8.20;
import {Errors} from "./Errors.sol";
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert Errors.InsufficientBalance(address(this).balance, amount);
}
(bool success, bytes memory returndata) = recipient.call{value: amount}("");
if (!success) {
_revert(returndata);
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {Errors.FailedCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case
* of an unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {Errors.FailedCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly ("memory-safe") {
revert(add(returndata, 0x20), mload(returndata))
}
} else {
revert Errors.FailedCall();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.20;
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS
}
/**
* @dev The signature derives the `address(0)`.
*/
error ECDSAInvalidSignature();
/**
* @dev The signature has an invalid length.
*/
error ECDSAInvalidSignatureLength(uint256 length);
/**
* @dev The signature has an S value that is in the upper half order.
*/
error ECDSAInvalidSignatureS(bytes32 s);
/**
* @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not
* return address(0) without also returning an error description. Errors are documented using an enum (error type)
* and a bytes32 providing additional information about the error.
*
* If no error is returned, then the address can be used for verification purposes.
*
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*/
function tryRecover(
bytes32 hash,
bytes memory signature
) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
assembly ("memory-safe") {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[ERC-2098 short signatures]
*/
function tryRecover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {
unchecked {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
// We do not check for an overflow here since the shift operation results in 0 or 1.
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*/
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS, s);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature, bytes32(0));
}
return (signer, RecoverError.NoError, bytes32(0));
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.
*/
function _throwError(RecoverError error, bytes32 errorArg) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert ECDSAInvalidSignature();
} else if (error == RecoverError.InvalidSignatureLength) {
revert ECDSAInvalidSignatureLength(uint256(errorArg));
} else if (error == RecoverError.InvalidSignatureS) {
revert ECDSAInvalidSignatureS(errorArg);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/cryptography/MessageHashUtils.sol)
pragma solidity ^0.8.20;
import {Strings} from "../Strings.sol";
/**
* @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.
*
* The library provides methods for generating a hash of a message that conforms to the
* https://eips.ethereum.org/EIPS/eip-191[ERC-191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]
* specifications.
*/
library MessageHashUtils {
/**
* @dev Returns the keccak256 digest of an ERC-191 signed data with version
* `0x45` (`personal_sign` messages).
*
* The digest is calculated by prefixing a bytes32 `messageHash` with
* `"\x19Ethereum Signed Message:\n32"` and hashing the result. It corresponds with the
* hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[`eth_sign`] JSON-RPC method.
*
* NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with
* keccak256, although any bytes32 value can be safely used because the final digest will
* be re-hashed.
*
* See {ECDSA-recover}.
*/
function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {
assembly ("memory-safe") {
mstore(0x00, "\x19Ethereum Signed Message:\n32") // 32 is the bytes-length of messageHash
mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix
digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)
}
}
/**
* @dev Returns the keccak256 digest of an ERC-191 signed data with version
* `0x45` (`personal_sign` messages).
*
* The digest is calculated by prefixing an arbitrary `message` with
* `"\x19Ethereum Signed Message:\n" + len(message)` and hashing the result. It corresponds with the
* hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[`eth_sign`] JSON-RPC method.
*
* See {ECDSA-recover}.
*/
function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {
return
keccak256(bytes.concat("\x19Ethereum Signed Message:\n", bytes(Strings.toString(message.length)), message));
}
/**
* @dev Returns the keccak256 digest of an ERC-191 signed data with version
* `0x00` (data with intended validator).
*
* The digest is calculated by prefixing an arbitrary `data` with `"\x19\x00"` and the intended
* `validator` address. Then hashing the result.
*
* See {ECDSA-recover}.
*/
function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(hex"19_00", validator, data));
}
/**
* @dev Variant of {toDataWithIntendedValidatorHash-address-bytes} optimized for cases where `data` is a bytes32.
*/
function toDataWithIntendedValidatorHash(
address validator,
bytes32 messageHash
) internal pure returns (bytes32 digest) {
assembly ("memory-safe") {
mstore(0x00, hex"19_00")
mstore(0x02, shl(96, validator))
mstore(0x16, messageHash)
digest := keccak256(0x00, 0x36)
}
}
/**
* @dev Returns the keccak256 digest of an EIP-712 typed data (ERC-191 version `0x01`).
*
* The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with
* `\x19\x01` and hashing the result. It corresponds to the hash signed by the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.
*
* See {ECDSA-recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {
assembly ("memory-safe") {
let ptr := mload(0x40)
mstore(ptr, hex"19_01")
mstore(add(ptr, 0x02), domainSeparator)
mstore(add(ptr, 0x22), structHash)
digest := keccak256(ptr, 0x42)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of common custom errors used in multiple contracts
*
* IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
* It is recommended to avoid relying on the error API for critical functionality.
*
* _Available since v5.1._
*/
library Errors {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error InsufficientBalance(uint256 balance, uint256 needed);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedCall();
/**
* @dev The deployment failed.
*/
error FailedDeployment();
/**
* @dev A necessary precompile is missing.
*/
error MissingPrecompile(address);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
import {Panic} from "../Panic.sol";
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Return the 512-bit addition of two uint256.
*
* The result is stored in two 256 variables such that sum = high * 2²⁵⁶ + low.
*/
function add512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {
assembly ("memory-safe") {
low := add(a, b)
high := lt(low, a)
}
}
/**
* @dev Return the 512-bit multiplication of two uint256.
*
* The result is stored in two 256 variables such that product = high * 2²⁵⁶ + low.
*/
function mul512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {
// 512-bit multiply [high low] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use
// the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = high * 2²⁵⁶ + low.
assembly ("memory-safe") {
let mm := mulmod(a, b, not(0))
low := mul(a, b)
high := sub(sub(mm, low), lt(mm, low))
}
}
/**
* @dev Returns the addition of two unsigned integers, with a success flag (no overflow).
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a + b;
success = c >= a;
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with a success flag (no overflow).
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a - b;
success = c <= a;
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with a success flag (no overflow).
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a * b;
assembly ("memory-safe") {
// Only true when the multiplication doesn't overflow
// (c / a == b) || (a == 0)
success := or(eq(div(c, a), b), iszero(a))
}
// equivalent to: success ? c : 0
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the division of two unsigned integers, with a success flag (no division by zero).
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
success = b > 0;
assembly ("memory-safe") {
// The `DIV` opcode returns zero when the denominator is 0.
result := div(a, b)
}
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
success = b > 0;
assembly ("memory-safe") {
// The `MOD` opcode returns zero when the denominator is 0.
result := mod(a, b)
}
}
}
/**
* @dev Unsigned saturating addition, bounds to `2²⁵⁶ - 1` instead of overflowing.
*/
function saturatingAdd(uint256 a, uint256 b) internal pure returns (uint256) {
(bool success, uint256 result) = tryAdd(a, b);
return ternary(success, result, type(uint256).max);
}
/**
* @dev Unsigned saturating subtraction, bounds to zero instead of overflowing.
*/
function saturatingSub(uint256 a, uint256 b) internal pure returns (uint256) {
(, uint256 result) = trySub(a, b);
return result;
}
/**
* @dev Unsigned saturating multiplication, bounds to `2²⁵⁶ - 1` instead of overflowing.
*/
function saturatingMul(uint256 a, uint256 b) internal pure returns (uint256) {
(bool success, uint256 result) = tryMul(a, b);
return ternary(success, result, type(uint256).max);
}
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * SafeCast.toUint(condition));
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a < b, a, b);
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
Panic.panic(Panic.DIVISION_BY_ZERO);
}
// The following calculation ensures accurate ceiling division without overflow.
// Since a is non-zero, (a - 1) / b will not overflow.
// The largest possible result occurs when (a - 1) / b is type(uint256).max,
// but the largest value we can obtain is type(uint256).max - 1, which happens
// when a = type(uint256).max and b = 1.
unchecked {
return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);
}
}
/**
* @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
*
* Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
(uint256 high, uint256 low) = mul512(x, y);
// Handle non-overflow cases, 256 by 256 division.
if (high == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return low / denominator;
}
// Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.
if (denominator <= high) {
Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [high low].
uint256 remainder;
assembly ("memory-safe") {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
high := sub(high, gt(remainder, low))
low := sub(low, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly ("memory-safe") {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [high low] by twos.
low := div(low, twos)
// Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from high into low.
low |= high * twos;
// Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such
// that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv ≡ 1 mod 2⁴.
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⁸
inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶
inverse *= 2 - denominator * inverse; // inverse mod 2³²
inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴
inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸
inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶
// 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²⁵⁶. Since the preconditions guarantee that the outcome is
// less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and high
// is no longer required.
result = low * inverse;
return result;
}
}
/**
* @dev Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);
}
/**
* @dev Calculates floor(x * y >> n) with full precision. Throws if result overflows a uint256.
*/
function mulShr(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 result) {
unchecked {
(uint256 high, uint256 low) = mul512(x, y);
if (high >= 1 << n) {
Panic.panic(Panic.UNDER_OVERFLOW);
}
return (high << (256 - n)) | (low >> n);
}
}
/**
* @dev Calculates x * y >> n with full precision, following the selected rounding direction.
*/
function mulShr(uint256 x, uint256 y, uint8 n, Rounding rounding) internal pure returns (uint256) {
return mulShr(x, y, n) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, 1 << n) > 0);
}
/**
* @dev Calculate the modular multiplicative inverse of a number in Z/nZ.
*
* If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.
* If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.
*
* If the input value is not inversible, 0 is returned.
*
* NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the
* inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.
*/
function invMod(uint256 a, uint256 n) internal pure returns (uint256) {
unchecked {
if (n == 0) return 0;
// The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)
// Used to compute integers x and y such that: ax + ny = gcd(a, n).
// When the gcd is 1, then the inverse of a modulo n exists and it's x.
// ax + ny = 1
// ax = 1 + (-y)n
// ax ≡ 1 (mod n) # x is the inverse of a modulo n
// If the remainder is 0 the gcd is n right away.
uint256 remainder = a % n;
uint256 gcd = n;
// Therefore the initial coefficients are:
// ax + ny = gcd(a, n) = n
// 0a + 1n = n
int256 x = 0;
int256 y = 1;
while (remainder != 0) {
uint256 quotient = gcd / remainder;
(gcd, remainder) = (
// The old remainder is the next gcd to try.
remainder,
// Compute the next remainder.
// Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd
// where gcd is at most n (capped to type(uint256).max)
gcd - remainder * quotient
);
(x, y) = (
// Increment the coefficient of a.
y,
// Decrement the coefficient of n.
// Can overflow, but the result is casted to uint256 so that the
// next value of y is "wrapped around" to a value between 0 and n - 1.
x - y * int256(quotient)
);
}
if (gcd != 1) return 0; // No inverse exists.
return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.
}
}
/**
* @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.
*
* From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is
* prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that
* `a**(p-2)` is the modular multiplicative inverse of a in Fp.
*
* NOTE: this function does NOT check that `p` is a prime greater than `2`.
*/
function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {
unchecked {
return Math.modExp(a, p - 2, p);
}
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)
*
* Requirements:
* - modulus can't be zero
* - underlying staticcall to precompile must succeed
*
* IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make
* sure the chain you're using it on supports the precompiled contract for modular exponentiation
* at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,
* the underlying function will succeed given the lack of a revert, but the result may be incorrectly
* interpreted as 0.
*/
function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {
(bool success, uint256 result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).
* It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying
* to operate modulo 0 or if the underlying precompile reverted.
*
* IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain
* you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in
* https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack
* of a revert, but the result may be incorrectly interpreted as 0.
*/
function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {
if (m == 0) return (false, 0);
assembly ("memory-safe") {
let ptr := mload(0x40)
// | Offset | Content | Content (Hex) |
// |-----------|------------|--------------------------------------------------------------------|
// | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x60:0x7f | value of b | 0x<.............................................................b> |
// | 0x80:0x9f | value of e | 0x<.............................................................e> |
// | 0xa0:0xbf | value of m | 0x<.............................................................m> |
mstore(ptr, 0x20)
mstore(add(ptr, 0x20), 0x20)
mstore(add(ptr, 0x40), 0x20)
mstore(add(ptr, 0x60), b)
mstore(add(ptr, 0x80), e)
mstore(add(ptr, 0xa0), m)
// Given the result < m, it's guaranteed to fit in 32 bytes,
// so we can use the memory scratch space located at offset 0.
success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
result := mload(0x00)
}
}
/**
* @dev Variant of {modExp} that supports inputs of arbitrary length.
*/
function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {
(bool success, bytes memory result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Variant of {tryModExp} that supports inputs of arbitrary length.
*/
function tryModExp(
bytes memory b,
bytes memory e,
bytes memory m
) internal view returns (bool success, bytes memory result) {
if (_zeroBytes(m)) return (false, new bytes(0));
uint256 mLen = m.length;
// Encode call args in result and move the free memory pointer
result = abi.encodePacked(b.length, e.length, mLen, b, e, m);
assembly ("memory-safe") {
let dataPtr := add(result, 0x20)
// Write result on top of args to avoid allocating extra memory.
success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)
// Overwrite the length.
// result.length > returndatasize() is guaranteed because returndatasize() == m.length
mstore(result, mLen)
// Set the memory pointer after the returned data.
mstore(0x40, add(dataPtr, mLen))
}
}
/**
* @dev Returns whether the provided byte array is zero.
*/
function _zeroBytes(bytes memory byteArray) private pure returns (bool) {
for (uint256 i = 0; i < byteArray.length; ++i) {
if (byteArray[i] != 0) {
return false;
}
}
return true;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* This method is based on Newton's method for computing square roots; the algorithm is restricted to only
* using integer operations.
*/
function sqrt(uint256 a) internal pure returns (uint256) {
unchecked {
// Take care of easy edge cases when a == 0 or a == 1
if (a <= 1) {
return a;
}
// In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a
// sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between
// the current value as `ε_n = | x_n - sqrt(a) |`.
//
// For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root
// of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is
// bigger than any uint256.
//
// By noticing that
// `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`
// we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar
// to the msb function.
uint256 aa = a;
uint256 xn = 1;
if (aa >= (1 << 128)) {
aa >>= 128;
xn <<= 64;
}
if (aa >= (1 << 64)) {
aa >>= 64;
xn <<= 32;
}
if (aa >= (1 << 32)) {
aa >>= 32;
xn <<= 16;
}
if (aa >= (1 << 16)) {
aa >>= 16;
xn <<= 8;
}
if (aa >= (1 << 8)) {
aa >>= 8;
xn <<= 4;
}
if (aa >= (1 << 4)) {
aa >>= 4;
xn <<= 2;
}
if (aa >= (1 << 2)) {
xn <<= 1;
}
// We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).
//
// We can refine our estimation by noticing that the middle of that interval minimizes the error.
// If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).
// This is going to be our x_0 (and ε_0)
xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)
// From here, Newton's method give us:
// x_{n+1} = (x_n + a / x_n) / 2
//
// One should note that:
// x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a
// = ((x_n² + a) / (2 * x_n))² - a
// = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a
// = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)
// = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)
// = (x_n² - a)² / (2 * x_n)²
// = ((x_n² - a) / (2 * x_n))²
// ≥ 0
// Which proves that for all n ≥ 1, sqrt(a) ≤ x_n
//
// This gives us the proof of quadratic convergence of the sequence:
// ε_{n+1} = | x_{n+1} - sqrt(a) |
// = | (x_n + a / x_n) / 2 - sqrt(a) |
// = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |
// = | (x_n - sqrt(a))² / (2 * x_n) |
// = | ε_n² / (2 * x_n) |
// = ε_n² / | (2 * x_n) |
//
// For the first iteration, we have a special case where x_0 is known:
// ε_1 = ε_0² / | (2 * x_0) |
// ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))
// ≤ 2**(2*e-4) / (3 * 2**(e-1))
// ≤ 2**(e-3) / 3
// ≤ 2**(e-3-log2(3))
// ≤ 2**(e-4.5)
//
// For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:
// ε_{n+1} = ε_n² / | (2 * x_n) |
// ≤ (2**(e-k))² / (2 * 2**(e-1))
// ≤ 2**(2*e-2*k) / 2**e
// ≤ 2**(e-2*k)
xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above
xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5
xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9
xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18
xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36
xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72
// Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision
// ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either
// sqrt(a) or sqrt(a) + 1.
return xn - SafeCast.toUint(xn > a / xn);
}
}
/**
* @dev Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 x) internal pure returns (uint256 r) {
// If value has upper 128 bits set, log2 result is at least 128
r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
// If upper 64 bits of 128-bit half set, add 64 to result
r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
// If upper 32 bits of 64-bit half set, add 32 to result
r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
// If upper 16 bits of 32-bit half set, add 16 to result
r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
// If upper 8 bits of 16-bit half set, add 8 to result
r |= SafeCast.toUint((x >> r) > 0xff) << 3;
// If upper 4 bits of 8-bit half set, add 4 to result
r |= SafeCast.toUint((x >> r) > 0xf) << 2;
// Shifts value right by the current result and use it as an index into this lookup table:
//
// | x (4 bits) | index | table[index] = MSB position |
// |------------|---------|-----------------------------|
// | 0000 | 0 | table[0] = 0 |
// | 0001 | 1 | table[1] = 0 |
// | 0010 | 2 | table[2] = 1 |
// | 0011 | 3 | table[3] = 1 |
// | 0100 | 4 | table[4] = 2 |
// | 0101 | 5 | table[5] = 2 |
// | 0110 | 6 | table[6] = 2 |
// | 0111 | 7 | table[7] = 2 |
// | 1000 | 8 | table[8] = 3 |
// | 1001 | 9 | table[9] = 3 |
// | 1010 | 10 | table[10] = 3 |
// | 1011 | 11 | table[11] = 3 |
// | 1100 | 12 | table[12] = 3 |
// | 1101 | 13 | table[13] = 3 |
// | 1110 | 14 | table[14] = 3 |
// | 1111 | 15 | table[15] = 3 |
//
// The lookup table is represented as a 32-byte value with the MSB positions for 0-15 in the last 16 bytes.
assembly ("memory-safe") {
r := or(r, byte(shr(r, x), 0x0000010102020202030303030303030300000000000000000000000000000000))
}
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 x) internal pure returns (uint256 r) {
// If value has upper 128 bits set, log2 result is at least 128
r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
// If upper 64 bits of 128-bit half set, add 64 to result
r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
// If upper 32 bits of 64-bit half set, add 32 to result
r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
// If upper 16 bits of 32-bit half set, add 16 to result
r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
// Add 1 if upper 8 bits of 16-bit half set, and divide accumulated result by 8
return (r >> 3) | SafeCast.toUint((x >> r) > 0xff);
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
/**
* @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
*/
function toUint(bool b) internal pure returns (uint256 u) {
assembly ("memory-safe") {
u := iszero(iszero(b))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.20;
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, int256 a, int256 b) internal pure returns (int256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * int256(SafeCast.toUint(condition)));
}
}
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return ternary(a < b, a, b);
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// Formula from the "Bit Twiddling Hacks" by Sean Eron Anderson.
// Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift,
// taking advantage of the most significant (or "sign" bit) in two's complement representation.
// This opcode adds new most significant bits set to the value of the previous most significant bit. As a result,
// the mask will either be `bytes32(0)` (if n is positive) or `~bytes32(0)` (if n is negative).
int256 mask = n >> 255;
// A `bytes32(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it.
return uint256((n + mask) ^ mask);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)
pragma solidity ^0.8.20;
/**
* @dev Helper library for emitting standardized panic codes.
*
* ```solidity
* contract Example {
* using Panic for uint256;
*
* // Use any of the declared internal constants
* function foo() { Panic.GENERIC.panic(); }
*
* // Alternatively
* function foo() { Panic.panic(Panic.GENERIC); }
* }
* ```
*
* Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].
*
* _Available since v5.1._
*/
// slither-disable-next-line unused-state
library Panic {
/// @dev generic / unspecified error
uint256 internal constant GENERIC = 0x00;
/// @dev used by the assert() builtin
uint256 internal constant ASSERT = 0x01;
/// @dev arithmetic underflow or overflow
uint256 internal constant UNDER_OVERFLOW = 0x11;
/// @dev division or modulo by zero
uint256 internal constant DIVISION_BY_ZERO = 0x12;
/// @dev enum conversion error
uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
/// @dev invalid encoding in storage
uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
/// @dev empty array pop
uint256 internal constant EMPTY_ARRAY_POP = 0x31;
/// @dev array out of bounds access
uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
/// @dev resource error (too large allocation or too large array)
uint256 internal constant RESOURCE_ERROR = 0x41;
/// @dev calling invalid internal function
uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;
/// @dev Reverts with a panic code. Recommended to use with
/// the internal constants with predefined codes.
function panic(uint256 code) internal pure {
assembly ("memory-safe") {
mstore(0x00, 0x4e487b71)
mstore(0x20, code)
revert(0x1c, 0x24)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.20;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC-1967 implementation slot:
* ```solidity
* contract ERC1967 {
* // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(newImplementation.code.length > 0);
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* TIP: Consider using this library along with {SlotDerivation}.
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct Int256Slot {
int256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Int256Slot` with member `value` located at `slot`.
*/
function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
/**
* @dev Returns a `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/Strings.sol)
pragma solidity ^0.8.20;
import {Math} from "./math/Math.sol";
import {SafeCast} from "./math/SafeCast.sol";
import {SignedMath} from "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
using SafeCast for *;
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
uint8 private constant ADDRESS_LENGTH = 20;
uint256 private constant SPECIAL_CHARS_LOOKUP =
(1 << 0x08) | // backspace
(1 << 0x09) | // tab
(1 << 0x0a) | // newline
(1 << 0x0c) | // form feed
(1 << 0x0d) | // carriage return
(1 << 0x22) | // double quote
(1 << 0x5c); // backslash
/**
* @dev The `value` string doesn't fit in the specified `length`.
*/
error StringsInsufficientHexLength(uint256 value, uint256 length);
/**
* @dev The string being parsed contains characters that are not in scope of the given base.
*/
error StringsInvalidChar();
/**
* @dev The string being parsed is not a properly formatted address.
*/
error StringsInvalidAddressFormat();
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
assembly ("memory-safe") {
ptr := add(add(buffer, 0x20), length)
}
while (true) {
ptr--;
assembly ("memory-safe") {
mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toStringSigned(int256 value) internal pure returns (string memory) {
return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
uint256 localValue = value;
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = HEX_DIGITS[localValue & 0xf];
localValue >>= 4;
}
if (localValue != 0) {
revert StringsInsufficientHexLength(value, length);
}
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
* representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal
* representation, according to EIP-55.
*/
function toChecksumHexString(address addr) internal pure returns (string memory) {
bytes memory buffer = bytes(toHexString(addr));
// hash the hex part of buffer (skip length + 2 bytes, length 40)
uint256 hashValue;
assembly ("memory-safe") {
hashValue := shr(96, keccak256(add(buffer, 0x22), 40))
}
for (uint256 i = 41; i > 1; --i) {
// possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f)
if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) {
// case shift by xoring with 0x20
buffer[i] ^= 0x20;
}
hashValue >>= 4;
}
return string(buffer);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
}
/**
* @dev Parse a decimal string and returns the value as a `uint256`.
*
* Requirements:
* - The string must be formatted as `[0-9]*`
* - The result must fit into an `uint256` type
*/
function parseUint(string memory input) internal pure returns (uint256) {
return parseUint(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseUint-string} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `[0-9]*`
* - The result must fit into an `uint256` type
*/
function parseUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {
(bool success, uint256 value) = tryParseUint(input, begin, end);
if (!success) revert StringsInvalidChar();
return value;
}
/**
* @dev Variant of {parseUint-string} that returns false if the parsing fails because of an invalid character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseUint(string memory input) internal pure returns (bool success, uint256 value) {
return _tryParseUintUncheckedBounds(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseUint-string-uint256-uint256} that returns false if the parsing fails because of an invalid
* character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseUint(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, uint256 value) {
if (end > bytes(input).length || begin > end) return (false, 0);
return _tryParseUintUncheckedBounds(input, begin, end);
}
/**
* @dev Implementation of {tryParseUint-string-uint256-uint256} that does not check bounds. Caller should make sure that
* `begin <= end <= input.length`. Other inputs would result in undefined behavior.
*/
function _tryParseUintUncheckedBounds(
string memory input,
uint256 begin,
uint256 end
) private pure returns (bool success, uint256 value) {
bytes memory buffer = bytes(input);
uint256 result = 0;
for (uint256 i = begin; i < end; ++i) {
uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));
if (chr > 9) return (false, 0);
result *= 10;
result += chr;
}
return (true, result);
}
/**
* @dev Parse a decimal string and returns the value as a `int256`.
*
* Requirements:
* - The string must be formatted as `[-+]?[0-9]*`
* - The result must fit in an `int256` type.
*/
function parseInt(string memory input) internal pure returns (int256) {
return parseInt(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseInt-string} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `[-+]?[0-9]*`
* - The result must fit in an `int256` type.
*/
function parseInt(string memory input, uint256 begin, uint256 end) internal pure returns (int256) {
(bool success, int256 value) = tryParseInt(input, begin, end);
if (!success) revert StringsInvalidChar();
return value;
}
/**
* @dev Variant of {parseInt-string} that returns false if the parsing fails because of an invalid character or if
* the result does not fit in a `int256`.
*
* NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.
*/
function tryParseInt(string memory input) internal pure returns (bool success, int256 value) {
return _tryParseIntUncheckedBounds(input, 0, bytes(input).length);
}
uint256 private constant ABS_MIN_INT256 = 2 ** 255;
/**
* @dev Variant of {parseInt-string-uint256-uint256} that returns false if the parsing fails because of an invalid
* character or if the result does not fit in a `int256`.
*
* NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.
*/
function tryParseInt(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, int256 value) {
if (end > bytes(input).length || begin > end) return (false, 0);
return _tryParseIntUncheckedBounds(input, begin, end);
}
/**
* @dev Implementation of {tryParseInt-string-uint256-uint256} that does not check bounds. Caller should make sure that
* `begin <= end <= input.length`. Other inputs would result in undefined behavior.
*/
function _tryParseIntUncheckedBounds(
string memory input,
uint256 begin,
uint256 end
) private pure returns (bool success, int256 value) {
bytes memory buffer = bytes(input);
// Check presence of a negative sign.
bytes1 sign = begin == end ? bytes1(0) : bytes1(_unsafeReadBytesOffset(buffer, begin)); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
bool positiveSign = sign == bytes1("+");
bool negativeSign = sign == bytes1("-");
uint256 offset = (positiveSign || negativeSign).toUint();
(bool absSuccess, uint256 absValue) = tryParseUint(input, begin + offset, end);
if (absSuccess && absValue < ABS_MIN_INT256) {
return (true, negativeSign ? -int256(absValue) : int256(absValue));
} else if (absSuccess && negativeSign && absValue == ABS_MIN_INT256) {
return (true, type(int256).min);
} else return (false, 0);
}
/**
* @dev Parse a hexadecimal string (with or without "0x" prefix), and returns the value as a `uint256`.
*
* Requirements:
* - The string must be formatted as `(0x)?[0-9a-fA-F]*`
* - The result must fit in an `uint256` type.
*/
function parseHexUint(string memory input) internal pure returns (uint256) {
return parseHexUint(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseHexUint-string} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `(0x)?[0-9a-fA-F]*`
* - The result must fit in an `uint256` type.
*/
function parseHexUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {
(bool success, uint256 value) = tryParseHexUint(input, begin, end);
if (!success) revert StringsInvalidChar();
return value;
}
/**
* @dev Variant of {parseHexUint-string} that returns false if the parsing fails because of an invalid character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseHexUint(string memory input) internal pure returns (bool success, uint256 value) {
return _tryParseHexUintUncheckedBounds(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseHexUint-string-uint256-uint256} that returns false if the parsing fails because of an
* invalid character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseHexUint(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, uint256 value) {
if (end > bytes(input).length || begin > end) return (false, 0);
return _tryParseHexUintUncheckedBounds(input, begin, end);
}
/**
* @dev Implementation of {tryParseHexUint-string-uint256-uint256} that does not check bounds. Caller should make sure that
* `begin <= end <= input.length`. Other inputs would result in undefined behavior.
*/
function _tryParseHexUintUncheckedBounds(
string memory input,
uint256 begin,
uint256 end
) private pure returns (bool success, uint256 value) {
bytes memory buffer = bytes(input);
// skip 0x prefix if present
bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(buffer, begin)) == bytes2("0x"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
uint256 offset = hasPrefix.toUint() * 2;
uint256 result = 0;
for (uint256 i = begin + offset; i < end; ++i) {
uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));
if (chr > 15) return (false, 0);
result *= 16;
unchecked {
// Multiplying by 16 is equivalent to a shift of 4 bits (with additional overflow check).
// This guarantees that adding a value < 16 will not cause an overflow, hence the unchecked.
result += chr;
}
}
return (true, result);
}
/**
* @dev Parse a hexadecimal string (with or without "0x" prefix), and returns the value as an `address`.
*
* Requirements:
* - The string must be formatted as `(0x)?[0-9a-fA-F]{40}`
*/
function parseAddress(string memory input) internal pure returns (address) {
return parseAddress(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseAddress-string} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `(0x)?[0-9a-fA-F]{40}`
*/
function parseAddress(string memory input, uint256 begin, uint256 end) internal pure returns (address) {
(bool success, address value) = tryParseAddress(input, begin, end);
if (!success) revert StringsInvalidAddressFormat();
return value;
}
/**
* @dev Variant of {parseAddress-string} that returns false if the parsing fails because the input is not a properly
* formatted address. See {parseAddress-string} requirements.
*/
function tryParseAddress(string memory input) internal pure returns (bool success, address value) {
return tryParseAddress(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseAddress-string-uint256-uint256} that returns false if the parsing fails because input is not a properly
* formatted address. See {parseAddress-string-uint256-uint256} requirements.
*/
function tryParseAddress(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, address value) {
if (end > bytes(input).length || begin > end) return (false, address(0));
bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(bytes(input), begin)) == bytes2("0x"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
uint256 expectedLength = 40 + hasPrefix.toUint() * 2;
// check that input is the correct length
if (end - begin == expectedLength) {
// length guarantees that this does not overflow, and value is at most type(uint160).max
(bool s, uint256 v) = _tryParseHexUintUncheckedBounds(input, begin, end);
return (s, address(uint160(v)));
} else {
return (false, address(0));
}
}
function _tryParseChr(bytes1 chr) private pure returns (uint8) {
uint8 value = uint8(chr);
// Try to parse `chr`:
// - Case 1: [0-9]
// - Case 2: [a-f]
// - Case 3: [A-F]
// - otherwise not supported
unchecked {
if (value > 47 && value < 58) value -= 48;
else if (value > 96 && value < 103) value -= 87;
else if (value > 64 && value < 71) value -= 55;
else return type(uint8).max;
}
return value;
}
/**
* @dev Escape special characters in JSON strings. This can be useful to prevent JSON injection in NFT metadata.
*
* WARNING: This function should only be used in double quoted JSON strings. Single quotes are not escaped.
*
* NOTE: This function escapes all unicode characters, and not just the ones in ranges defined in section 2.5 of
* RFC-4627 (U+0000 to U+001F, U+0022 and U+005C). ECMAScript's `JSON.parse` does recover escaped unicode
* characters that are not in this range, but other tooling may provide different results.
*/
function escapeJSON(string memory input) internal pure returns (string memory) {
bytes memory buffer = bytes(input);
bytes memory output = new bytes(2 * buffer.length); // worst case scenario
uint256 outputLength = 0;
for (uint256 i; i < buffer.length; ++i) {
bytes1 char = bytes1(_unsafeReadBytesOffset(buffer, i));
if (((SPECIAL_CHARS_LOOKUP & (1 << uint8(char))) != 0)) {
output[outputLength++] = "\\";
if (char == 0x08) output[outputLength++] = "b";
else if (char == 0x09) output[outputLength++] = "t";
else if (char == 0x0a) output[outputLength++] = "n";
else if (char == 0x0c) output[outputLength++] = "f";
else if (char == 0x0d) output[outputLength++] = "r";
else if (char == 0x5c) output[outputLength++] = "\\";
else if (char == 0x22) {
// solhint-disable-next-line quotes
output[outputLength++] = '"';
}
} else {
output[outputLength++] = char;
}
}
// write the actual length and deallocate unused memory
assembly ("memory-safe") {
mstore(output, outputLength)
mstore(0x40, add(output, shl(5, shr(5, add(outputLength, 63)))))
}
return string(output);
}
/**
* @dev Reads a bytes32 from a bytes array without bounds checking.
*
* NOTE: making this function internal would mean it could be used with memory unsafe offset, and marking the
* assembly block as such would prevent some optimizations.
*/
function _unsafeReadBytesOffset(bytes memory buffer, uint256 offset) private pure returns (bytes32 value) {
// This is not memory safe in the general case, but all calls to this private function are within bounds.
assembly ("memory-safe") {
value := mload(add(add(buffer, 0x20), offset))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/TransientSlot.sol)
// This file was procedurally generated from scripts/generate/templates/TransientSlot.js.
pragma solidity ^0.8.24;
/**
* @dev Library for reading and writing value-types to specific transient storage slots.
*
* Transient slots are often used to store temporary values that are removed after the current transaction.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* * Example reading and writing values using transient storage:
* ```solidity
* contract Lock {
* using TransientSlot for *;
*
* // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
* bytes32 internal constant _LOCK_SLOT = 0xf4678858b2b588224636b8522b729e7722d32fc491da849ed75b3fdf3c84f542;
*
* modifier locked() {
* require(!_LOCK_SLOT.asBoolean().tload());
*
* _LOCK_SLOT.asBoolean().tstore(true);
* _;
* _LOCK_SLOT.asBoolean().tstore(false);
* }
* }
* ```
*
* TIP: Consider using this library along with {SlotDerivation}.
*/
library TransientSlot {
/**
* @dev UDVT that represents a slot holding an address.
*/
type AddressSlot is bytes32;
/**
* @dev Cast an arbitrary slot to a AddressSlot.
*/
function asAddress(bytes32 slot) internal pure returns (AddressSlot) {
return AddressSlot.wrap(slot);
}
/**
* @dev UDVT that represents a slot holding a bool.
*/
type BooleanSlot is bytes32;
/**
* @dev Cast an arbitrary slot to a BooleanSlot.
*/
function asBoolean(bytes32 slot) internal pure returns (BooleanSlot) {
return BooleanSlot.wrap(slot);
}
/**
* @dev UDVT that represents a slot holding a bytes32.
*/
type Bytes32Slot is bytes32;
/**
* @dev Cast an arbitrary slot to a Bytes32Slot.
*/
function asBytes32(bytes32 slot) internal pure returns (Bytes32Slot) {
return Bytes32Slot.wrap(slot);
}
/**
* @dev UDVT that represents a slot holding a uint256.
*/
type Uint256Slot is bytes32;
/**
* @dev Cast an arbitrary slot to a Uint256Slot.
*/
function asUint256(bytes32 slot) internal pure returns (Uint256Slot) {
return Uint256Slot.wrap(slot);
}
/**
* @dev UDVT that represents a slot holding a int256.
*/
type Int256Slot is bytes32;
/**
* @dev Cast an arbitrary slot to a Int256Slot.
*/
function asInt256(bytes32 slot) internal pure returns (Int256Slot) {
return Int256Slot.wrap(slot);
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(AddressSlot slot) internal view returns (address value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(AddressSlot slot, address value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(BooleanSlot slot) internal view returns (bool value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(BooleanSlot slot, bool value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(Bytes32Slot slot) internal view returns (bytes32 value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(Bytes32Slot slot, bytes32 value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(Uint256Slot slot) internal view returns (uint256 value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(Uint256Slot slot, uint256 value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(Int256Slot slot) internal view returns (int256 value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(Int256Slot slot, int256 value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {IDecimalConvertible} from "./interfaces/IDecimalConvertible.sol";
abstract contract DecimalConvertibleUpgradeable is
IDecimalConvertible,
Initializable
{
/// @custom:storage-location erc7201:toki.storage.DecimalConvertibleUpgradeable
struct DecimalConvertibleUpgradeableStorage {
uint8 _globalDecimals; // the global decimals (lowest common decimals between chains).
uint8 _localDecimals; // the local decimals for the token (eg. USDT: 6 decimals)
uint256 _convertRate; // the decimals for the token (eg. USDT->globalDecimals: 12 decimals)
}
// keccak256(abi.encode(uint256(keccak256("toki.storage.DecimalConvertibleUpgradeable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant DECIMAL_CONVERTIBLE_UPGRADEABLE_STORAGE_LOCATION =
0x363bd9d3ac01b05edede66fbb9c4f73d99f1481666c51eee8df34d23a61f4800;
function globalDecimals() public view override returns (uint8) {
return _getDecimalConvertibleUpgradeableStorage()._globalDecimals;
}
function localDecimals() public view override returns (uint8) {
return _getDecimalConvertibleUpgradeableStorage()._localDecimals;
}
function convertRate() public view override returns (uint256) {
return _getDecimalConvertibleUpgradeableStorage()._convertRate;
}
/* solhint-disable func-name-mixedcase */
function __DecimalConvertible_init(
uint8 globalDecimals_,
uint8 localDecimals_
) internal onlyInitializing {
__DecimalConvertible_init_unchained(globalDecimals_, localDecimals_);
}
function __DecimalConvertible_init_unchained(
uint8 globalDecimals_,
uint8 localDecimals_
) internal onlyInitializing {
DecimalConvertibleUpgradeableStorage
storage $ = _getDecimalConvertibleUpgradeableStorage();
$._globalDecimals = globalDecimals_;
$._localDecimals = localDecimals_;
$._convertRate =
10 ** ((uint256($._localDecimals) - uint256($._globalDecimals)));
}
function _GDToLD(uint256 _amountGD) internal view returns (uint256) {
return
_amountGD * _getDecimalConvertibleUpgradeableStorage()._convertRate;
}
function _LDToGD(uint256 _amountLD) internal view returns (uint256) {
return
_amountLD / _getDecimalConvertibleUpgradeableStorage()._convertRate;
}
function _getDecimalConvertibleUpgradeableStorage()
private
pure
returns (DecimalConvertibleUpgradeableStorage storage $)
{
// solhint-disable-next-line no-inline-assembly
assembly {
$.slot := DECIMAL_CONVERTIBLE_UPGRADEABLE_STORAGE_LOCATION
}
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
/**
* @title IDecimalConvertible
* @dev Interface for converting decimals between global and local.
* For more details on globalDecimals and localDecimals, refer to IPool.
*/
interface IDecimalConvertible {
/**
* @dev Returns the global decimals, which is the smallest decimal value among connected pools.
* @return The global decimals.
*/
function globalDecimals() external returns (uint8);
/**
* @dev Returns the local decimals for the token
* @return The local decimals for the token.
*/
function localDecimals() external returns (uint8);
/**
* @dev Returns the conversion rate for the token
* @return The conversion rate for the token.
*/
function convertRate() external returns (uint256);
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import {ITransferPoolFeeCalculator} from "./ITransferPoolFeeCalculator.sol";
import {IDecimalConvertible} from "./IDecimalConvertible.sol";
import {IStaticFlowRateLimiter} from "./IStaticFlowRateLimiter.sol";
/**
* @title IPool
* @dev Interface for the Pool contract. Represents the liquidity pool, implemented using a mechanism called the Delta Algorithm.
* The Delta Algorithm allows for efficient cross-chain transactions and liquidity management.
* When a function that could unbalance pools is called, such as minting liquidity, transferring tokens, and withdrawing liquidity,
* delta calculation can be triggered. It can also be forcefully triggered using callDelta.
* Refer to the white paper for more details on the Delta Algorithm: https://www.dropbox.com/s/gf3606jedromp61/Delta-Solving.The.Bridging-Trilemma.pdf?dl=0
*
* IPool serves as an liquidity pool contract which mints and burns ERC20 LP tokens when liquidity is added and removed from the pool.
* A pool ID is assigned to each pool contract, which is shared between chains.
* Majority of the cross-chain and liquidity related functions will be called by the Bridge.
*
*
* Some functions in the Pool execute cross-chain transactions.
* In cross-chain transactions, it's important to understand the context in which the function is executed and the perspective from which it is viewed.
* The following terms are related to cross-chain transactions:
* - Local pool: The pool where the function is being executed.
* - Peer pool: The pool that is connected to the local pool.
* - Initiator: The pool that initiates the cross-chain transaction.
* - Counterparty: The pool that receives the cross-chain transaction.
* Local pool and Peer pool represent a first-person view, whereas Initiator and Counterparty represent an objective view.
*
* The Pool uses two types of units:
* - GD (Global Decimals): Lowest common decimals units used across the unified liquidity pool. GD can not be greater than LD.
* - LD (Local Decimals): Decimal units specific to a particular asset token.
*
* The Pool uses two types of tokens:
* - Liquidity provider token (LP token): This token represents the share of liquidity provided by users and is in GD units.
* - Asset token: This token represents the actual token associated with the Pool, such as USDC or USDT.
* When simply referred to as 'token' it means the asset token.
*
*/
interface IPool is IDecimalConvertible, IStaticFlowRateLimiter {
/**
* @dev Struct for the peer pool.
* In the Delta Algorithm, there is a pool for each token, and these are referred to as a unified liquidity pool.
* Within the unified liquidity pool, each pool is connected to multiple peer pools. Each pool refers to other connected pools as peer pools.
* For example, the USDC on ETH pool may connect to peer pools like the USDT on ETH pool or the USDC on BSC pool, among others.
* @param chainId The chain ID of the peer pool.
* @param id The ID of the peer pool that is unique within the chain.
* @param weight The weight that determines the allocation amount of liquidity.
* The larger the weight, the more balance is allocated.
* @param balance The balance available for transfer to the peer pool in GD units.
* @param targetBalance The target balance, representing the ideal balance in GD units.
* If the balance is less than the targetBalance, an additional eqFee will be charged.
* @param lastKnownBalance The last known balance of the peer pool in GD units.
* Unlike balance, it represents the amount that can be transferred from the peer pool to this pool.
* @param credits The amount of tokens in GD units that can be transferred to the peer pool next time,
* reducing the cost of cross-chain transactions.
* @param ready Indicates if the peer pool is ready for transfer.
*/
struct PeerPoolInfo {
uint256 chainId;
uint256 id;
uint256 weight;
uint256 balance;
uint256 targetBalance;
uint256 lastKnownBalance;
uint256 credits;
bool ready;
}
/**
* @dev Struct for the credit information.
* @param credits The amount of tokens in GD units that can be transferred to the peer pool next time.
* @param targetBalance The target balance in GD units.
*/
struct CreditInfo {
uint256 credits;
uint256 targetBalance;
}
/**
* @dev Emitted by transfer.
* @param peerChainId The chain ID of the peer pool.
* @param peerPoolId The ID of the peer pool.
* @param from The address from which the tokens are transferred.
* @param amountGD The amount of tokens transferred in GD units.
* @param eqReward The equilibrium reward for the transfer.
* @param eqFee The equilibrium fee for the transfer.
* @param protocolFee The protocol fee for the transfer.
* @param lpFee The liquidity provider fee for the transfer.
*/
event Transfer(
uint256 peerChainId,
uint256 peerPoolId,
address from,
uint256 amountGD,
uint256 eqReward,
uint256 eqFee,
uint256 protocolFee,
uint256 lpFee
);
/**
* @dev Emitted when tokens are received.
* @param to The address that receives the tokens.
* @param amountGD The amount of tokens received in GD units.
* @param protocolFee The protocol fee for the transfer.
* @param eqFee The equilibrium fee for the transfer.
*/
event Recv(
address to,
uint256 amountGD,
uint256 protocolFee,
uint256 eqFee
);
/**
* @dev Emitted by withdrawRemote.
* @param peerChainId The chain ID of the peer pool.
* @param peerPoolId The ID of the peer pool.
* @param from The address from which the tokens are withdrawn.
* @param amountLP The amount of LP tokens withdrawn in GD units.
* @param amountLD The amount of asset tokens withdrawn in LD units.
*/
event WithdrawRemote(
uint256 peerChainId,
uint256 peerPoolId,
address from,
uint256 amountLP,
uint256 amountLD
);
/**
* @dev Emitted by withdrawLocal.
*
* @param peerChainId The chain ID of the peer pool.
* @param peerPoolId The ID of the peer pool.
* @param from The address from which the tokens are withdrawn.
* @param amountLP The amount of LP tokens withdrawn in GD units.
* @param amountGD The amount of asset tokens withdrawn in GD units.
* @param to The address that receives the tokens.
*/
event WithdrawLocal(
uint256 peerChainId,
uint256 peerPoolId,
address from,
uint256 amountLP,
uint256 amountGD,
bytes to
);
/**
* @dev Emitted by withdrawCheck.
* @param peerChainId The chain ID of the peer pool.
* @param peerPoolId The ID of the peer pool.
* @param amountLP The amount of LP tokens withdrawn in GD units.
* @param amountGD The amount of asset tokens withdrawn in GD units.
*/
event WithdrawCheck(
uint256 peerChainId,
uint256 peerPoolId,
uint256 amountLP,
uint256 amountGD
);
/**
* @dev Emitted by withdrawConfirm.
* @param peerChainId The chain ID of the peer pool.
* @param peerPoolId The ID of the peer pool.
* @param to The address that receives the tokens.
* @param amountGD The amount of tokens withdrawn in GD units.
* @param amountMintGD The amount of tokens minted in GD units.
*/
event WithdrawConfirm(
uint256 peerChainId,
uint256 peerPoolId,
address to,
uint256 amountGD,
uint256 amountMintGD
);
/**
* @dev Emitted by sendCredit.
* @param peerPoolId The ID of the peer pool.
* @param credits The amount of tokens in GD units that can be transferred to the peer pool next time.
* @param targetBalance The target balance in GD units.
*/
event SendCredit(
uint256 peerPoolId,
uint256 credits,
uint256 targetBalance
);
/**
* @dev Emitted by updateCredit.
* @param peerChainId The chain ID of the peer pool.
* @param peerPoolId The ID of the peer pool.
* @param credits The amount of tokens in GD units that can be transferred to the peer pool next time.
* @param targetBalance The target balance in GD units.
*/
event UpdateCredit(
uint256 peerChainId,
uint256 peerPoolId,
uint256 credits,
uint256 targetBalance
);
/**
* @dev Emitted by withdrawInstant.
* @param from The address from which the tokens are withdrawn.
* @param amountLP The amount of LP tokens withdrawn in GD units.
* @param amountGD The amount of asset tokens withdrawn in GD units.
* @param to The address that receives the tokens.
*/
event WithdrawInstant(
address from,
uint256 amountLP,
uint256 amountGD,
address to
);
/**
* @dev Emitted when LP tokens are minted.
* @param to The address to which the tokens are minted.
* @param amountLP The amount of LP tokens minted in GD units.
* @param amountGD The amount of asset tokens minted in GD units.
*/
event Mint(address to, uint256 amountLP, uint256 amountGD);
/**
* @dev Emitted when LP tokens are burned.
* @param from The address from which the tokens are burned.
* @param amountLP The amount of LP tokens burned in GD units.
* @param amountGD The amount of asset tokens burned in GD units.
*/
event Burn(address from, uint256 amountLP, uint256 amountGD);
// ============= for admin functions =================
/**
* @dev Emitted by setTransferStop.
* @param stopTransfer The stop transfer status.
*/
event UpdateStopTransfer(bool stopTransfer);
/**
* @dev Emitted when a peer pool is updated.
* @param peerChainId The chain ID of the peer pool.
* @param peerPoolId The ID of the peer pool.
* @param weight The weight that determines the allocation amount of liquidity.
*/
event PeerPoolInfoUpdate(
uint256 peerChainId,
uint256 peerPoolId,
uint256 weight
);
/**
* @dev Emitted by setDeltaParam.
* @param batched Indicates if the delta updates are batched. If true, the updates are processed in batch mode.
* @param swapDeltaBP The basis points for the swap delta.
* @param lpDeltaBP The basis points for the liquidity provider delta.
* @param defaultSwapMode The default mode for swaps.
* @param defaultLPMode The default mode for LP tokens.
*/
event UpdateDeltaParam(
bool batched,
uint256 swapDeltaBP,
uint256 lpDeltaBP,
bool defaultSwapMode,
bool defaultLPMode
);
/**
* @dev Emitted by drawFee.
* @param to The address to which the fee is transferred.
* @param amountLD The amount of the fee drawn in LD units.
*/
event DrawFee(address to, uint256 amountLD);
/**
* @dev Emitted when the maximum total deposits are set.
* @param maxTotalDepositsLD The maximum total deposits allowed in LD units.
*/
event SetMaxTotalDeposits(uint256 maxTotalDepositsLD);
/**
* @dev Mints LP tokens in exchange for depositing assert tokens.
* Note that asset tokens are transferred by the Bridge contract, not by the Pool contract.
* @param to The address to which the tokens are minted.
* @param amountLD The amount of asset tokens to mint in LD units.
* @return amountGD The amount of asset tokens minted in GD units.
*/
function mint(
address to,
uint256 amountLD
) external returns (uint256 amountGD);
/**
* @dev Transfers tokens to a peer pool.
* Note that the Bridge contract performs the transfer token. The Pool only performs delta calculations and updates its internal state.
*
* [Flow of a cross-chain transaction]
* 1. transfer on the initiator <- this function
* 2. recv on the counterparty
*
* @param peerChainId The chain ID of the peer pool.
* @param peerPoolId The ID of the peer pool.
* @param from The address from which the tokens are transferred.
* @param amountLD The amount of tokens to transfer in LD units.
* @param minAmountLD The minimum amount of tokens to transfer in LD units.
* Slippage check is done to ensure that the amount after adding the reward and
* subtracting the fee is greater than or equal to the minimum amount in GD units.
* @param newLiquidity Indicates if the transfer is new liquidity.
* @return feeInfo The fee information for the transfer.
*/
function transfer(
uint256 peerChainId,
uint256 peerPoolId,
address from,
uint256 amountLD,
uint256 minAmountLD,
bool newLiquidity
) external returns (ITransferPoolFeeCalculator.FeeInfo memory);
/**
* @dev Receives tokens from the peer pool.
* The delta calculation is performed, and the peer pool info of the local pool is updated.
*
* [Flow of a cross-chain transaction]
* 1. transfer on the initiator
* 2. recv on the counterparty <- this function
*
* 1. withdrawRemote on the initiator
* 2. recv on the counterparty <- this function
*
* @param peerChainId The chain id of the peer pool
* @param peerPoolId The pool id of the peer pool
* @param to The address to receive the tokens
* @param feeInfo The fee information
* @param updateDelta Whether to update the delta like totalLiquidity
* @return amountLD The amount of tokens received, including rewards
* @return isTransferred Whether the tokens are transferred
*/
function recv(
uint256 peerChainId,
uint256 peerPoolId,
address to,
ITransferPoolFeeCalculator.FeeInfo memory feeInfo,
bool updateDelta
) external returns (uint256 amountLD, bool isTransferred);
/**
* @dev Withdraws asset tokens from the peer pool, and in exchange, burn LP tokens locally.
*
* [Flow of a cross-chain transaction]
* 1. withdrawRemote on the initiator <- this function
* 2. recv on the counterparty
*
* @param peerChainId The chain ID of the peer pool.
* @param peerPoolId The ID of the peer pool.
* @param from The address from which the tokens are withdrawn.
* @param amount The amount of LP tokens.
*/
function withdrawRemote(
uint256 peerChainId,
uint256 peerPoolId,
address from,
uint256 amount
) external;
/**
* @dev Withdraws tokens from a peer pool locally.
* withdrawLocal burns local LP tokens and uses the balance that the peer pool can send to the local pool to withdraw tokens in the local pool.
*
* [Flow of a cross-chain transaction]
* 1. withdrawLocal on the initiator <- this function
* 2. withdrawCheck on the counterparty
* 3. withdrawConfirm on the initiator
*
* @param peerChainId The chain ID of the peer pool.
* @param peerPoolId The ID of the peer pool.
* @param from The address from which the tokens are withdrawn.
* @param amount The amount of LP tokens.
* @param to The address to receive the tokens.
* @return amountGD The amount of asset tokens withdrawn in GD units.
*/
function withdrawLocal(
uint256 peerChainId,
uint256 peerPoolId,
address from,
uint256 amount,
bytes calldata to
) external returns (uint256 amountGD);
/**
* @dev This is the second step in withdrawLocal which executed on the peer pool for withdrawLocal.
* It checks the balance, and if the balance is insufficient, it transfers tokens up to the balance.
*
* [Flow of a cross-chain transaction]
* 1. withdrawLocal on the initiator
* 2. withdrawCheck on the counterparty <- this function
* 3. withdrawConfirm on the initiator
*
* @param peerChainId The chain ID of the peer pool (the initiator pool).
* @param peerPoolId The ID of the peer pool (the initiator pool).
* @param amountGD The amount of tokens to withdraw in GD units.
*/
function withdrawCheck(
uint256 peerChainId,
uint256 peerPoolId,
uint256 amountGD
) external returns (uint256 amountSwap, uint256 amountMint);
/**
* @dev This is the final step in withdrawLocal which executed on the local pool for withdrawLocal.
* If the full amount cannot be withdrawn, mint LP tokens to refund the excess burned tokens.
*
* [Flow of a cross-chain transaction]
* 1. withdrawLocal on the initiator
* 2. withdrawCheck on the counterparty
* 3. withdrawConfirm on the initiator <- this function
*
* @param peerChainId The chain ID of the peer pool (the counterparty pool).
* @param peerPoolId The ID of the peer pool (the counterparty pool).
* @param to The address to receive the tokens
* @param amountGD The amount of tokens to withdraw, capped by `peerPoolInfo.balance`.
* @param amountToMintGD The amount of tokens to mint when `peerPoolInfo.balance` is insufficient
* @param updateDelta Whether to update the delta like `totalLiquidity`
* @return isTransferred Whether the tokens are transferred
*/
function withdrawConfirm(
uint256 peerChainId,
uint256 peerPoolId,
address to,
uint256 amountGD,
uint256 amountToMintGD,
bool updateDelta
) external returns (bool isTransferred);
/**
* @dev Sends credit to a peer pool.
* Credits aims to reduce the processing costs of cross-chain transactions. It can be transferred to the peer pool next time.
* Updates the local Peer pool info and generates a IBC packet.
*
* [Flow of a cross-chain transaction]
* 1. sendCredit on the initiator <- this function
* 2. updateCredit on the counterparty
*
* @param peerChainId The chain ID of the peer pool.
* @param peerPoolId The ID of the peer pool.
* @return creditInfo The credit information.
*/
function sendCredit(
uint256 peerChainId,
uint256 peerPoolId
) external returns (CreditInfo memory);
/**
* @dev This is the 2nd step in sendCredit which executed on the peer pool for sendCredit.
* Updates the peer pool info of the local pool (the counterparty pool) based on the received credit.
*
* [Flow of a cross-chain transaction]
* 1. sendCredit on the initiator
* 2. updateCredit on the counterparty <- this function
*
* @param peerChainId The chain ID of the peer pool (the initiator pool).
* @param peerPoolId The ID of the peer pool (the initiator pool).
* @param creditInfo The credit information.
*/
function updateCredit(
uint256 peerChainId,
uint256 peerPoolId,
CreditInfo memory creditInfo
) external;
/**
* @dev Withdraws tokens instantly.
* Instead of using a cross-chain transaction, withdraw instantly from deltaCredit.
* If deltaCredit is insufficient, withdraw up to deltaCredit.
* @param from The address from which the tokens are withdrawn.
* @param amountLP The amount of LP tokens to withdraw in GD units.
* @param to The address to receive the tokens.
* @return amountGD The amount of tokens withdrawn in GD units.
*/
function withdrawInstant(
address from,
uint256 amountLP,
address to
) external returns (uint256 amountGD);
/**
* @dev Handles failure of recv
*/
function handleRecvFailure(
uint256 peerChainId,
uint256 peerPoolId,
address to,
ITransferPoolFeeCalculator.FeeInfo memory feeInfo
) external;
/**
* @dev Handles failure of withdrawConfirm
*/
function handleWithdrawConfirmFailure(
uint256 peerChainId,
uint256 peerPoolId,
address to,
uint256 amountGD,
uint256 amountToMintGD
) external;
/**
* @dev Calculates the delta.
* @param fullMode Indicates if the full mode should be used.
* If true, even if each pool has an ideal balance, all deltaCredit will be consumed and proportionally distributed to each pool.
*/
function callDelta(bool fullMode) external;
/**
* @dev Sets the transfer stop status.
* @param transferStop If true, transfer operations are restricted. However, withdrawals are not restricted.
*/
function setTransferStop(bool transferStop) external;
/**
* @dev Registers a peer pool.
* @param peerChainId The chain ID of the peer pool.
* @param peerPoolId The ID of the peer pool.
* @param weight The weight of the peer pool.
*/
function registerPeerPool(
uint256 peerChainId,
uint256 peerPoolId,
uint256 weight
) external;
/**
* @dev Activates a peer pool.
* @param peerChainId The chain ID of the peer pool.
* @param peerPoolId The ID of the peer pool.
*/
function activatePeerPool(uint256 peerChainId, uint256 peerPoolId) external;
/**
* @dev Sets the weight of a peer pool.
* When the peer pool is activated, it becomes available for transfer.
* @param peerChainId The chain ID of the peer pool.
* @param peerPoolId The ID of the peer pool.
* @param weight The weight of the peer pool.
*/
function setPeerPoolWeight(
uint256 peerChainId,
uint256 peerPoolId,
uint256 weight
) external;
/**
* @dev Sets the delta parameters.
* @param batched Indicates if the delta updates are batched.
* @param swapDeltaBP The basis points for the swap delta.
* @param lpDeltaBP The basis points for the liquidity provider delta.
* @param defaultSwapMode The default mode for swaps.
* @param defaultLPMode The default mode for LP tokens.
*/
function setDeltaParam(
bool batched,
uint256 swapDeltaBP,
uint256 lpDeltaBP,
bool defaultSwapMode,
bool defaultLPMode
) external;
/**
* @dev Draws a fee from the pool.
* @param to The address to receive the fee.
*/
function drawFee(address to) external;
// ============== for helper ===================
/**
* @dev Returns the total liquidity.
* @return The total liquidity in GD units.
*/
function totalLiquidity() external view returns (uint256);
/**
* @dev Returns the asset token address.
* @return The asset token address.
*/
function token() external view returns (address);
/**
* @dev Returns the equilibrium fee pool.
* @return The equilibrium fee pool in GD units.
*/
function eqFeePool() external view returns (uint256);
/**
* @dev Returns the peer pool information.
* @param peerChainId The chain ID of the peer pool.
* @param peerPoolId The ID of the peer pool.
* @return The peer pool information.
*/
function getPeerPoolInfo(
uint256 peerChainId,
uint256 peerPoolId
) external view returns (PeerPoolInfo memory);
/**
* @dev Calculates the fee for a transfer.
* @param peerChainId The chain ID of the peer pool.
* @param peerPoolId The ID of the peer pool.
* @param from The address from which the tokens are transferred.
* @param amountLD The amount of tokens to transfer in LD units.
* @return feeInfo The fee information.
*/
function calcFee(
uint256 peerChainId,
uint256 peerPoolId,
address from,
uint256 amountLD
) external view returns (ITransferPoolFeeCalculator.FeeInfo memory);
/**
* @dev Converts LP tokens in GD units to asset tokens in LD units.
* @param amountLP The amount of LP tokens in GD units.
* @return The amount of asset tokens in LD units.
*/
// solhint-disable-next-line func-name-mixedcase
function LPToLD(uint256 amountLP) external view returns (uint256);
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
/**
* @dev StaticFlowRateLimiter limits the flow within a certain period.
* For example, it can be used to limit the amount of ERC20 token transfers.
*/
interface IStaticFlowRateLimiter {
/**
* @dev Resets the flow rate limit with a privilege.
*/
function resetFlowRateLimit() external;
/**
* @dev Returns the end of the current period.
* @return The block number when the current period ends.
*/
function currentPeriodEnd() external view returns (uint256);
/**
* @dev Returns the amount accumulated in the current period.
* @return The amount accumulated in the current period.
*/
function currentPeriodAmount() external view returns (uint256);
/**
* @dev Returns whether the lock period is applied.
* @return `true` if the lock period is applied, `false` otherwise.
*/
function appliedLockPeriod() external view returns (bool);
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
interface ITokiErrors {
error TokiZeroAddress(string message);
error TokiZeroAmount(string message);
error TokiZeroValue(string message);
// user error
error TokiInsufficientAmount(string name, uint256 value, uint256 needed);
// pool does not have enough liquidity
error TokiInsufficientPoolLiquidity(uint256 value, uint256 needed);
// insufficient allowance for transfer
error TokiInsufficientAllowance(
string name,
uint256 allowance,
uint256 needed
);
error TokiExceed(string name, uint256 value, uint256 limit);
error TokiExceedAdd(
string name,
uint256 current,
uint256 add,
uint256 limit
);
// only used in PseudoToken, which is just for Testnet
error TokiContractNotAllowed(string name, address addr);
error TokiCannotCloseChannel();
error TokiCannotTimeoutPacket();
error TokiRequireOrderedChannel();
error TokiDstOuterGasShouldBeZero();
error TokiInvalidPacketType(uint8);
error TokiInvalidRetryType(uint8);
error TokiInvalidRecipientBytes();
error TokiNoRevertReceive();
error TokiRetryExpired(uint256 expiryBlock);
error TokiInvalidAppVersion(uint256 expected, uint256 actual);
error TokiNotEnoughNativeFee(uint256 value, uint256 limit);
error TokiFailToRefund();
error TokiNoFee();
error TokiInvalidBalanceDeficitFeeZone();
error TokiInvalidSafeZoneRange(uint256 min, uint256 max);
error TokiDepeg(uint256 poolId);
error TokiUnregisteredChainId(string channel);
error TokiUnregisteredPoolId(uint256 poolId);
error TokiSamePool(uint256 poolId, address pool);
error TokiNoPool(uint256 poolId);
error TokiPoolRecvIsFailed(uint256 poolId);
error TokiPoolWithdrawConfirmIsFailed(uint256 poolId);
error TokiPriceIsNotPositive(int256 value);
error TokiPriceIsExpired(uint256 updatedAt);
error TokiDstChainIdNotAccepted(uint256 dstChainId);
error TokiTransferIsStop();
error TokiTransferIsFailed(address token, address to, uint256 value);
error TokiNativeTransferIsFailed(address to, uint256 value);
error TokiPeerPoolIsNotReady(uint256 peerChainId, uint256 peerPoolId);
error TokiSlippageTooHigh(
uint256 amountGD,
uint256 eqReward,
uint256 eqFee,
uint256 minAmountGD
);
error TokiPeerPoolIsRegistered(uint256 chainId, uint256 poolId);
error TokiPeerPoolIsAlreadyActive(uint256 chainId, uint256 poolId);
error TokiNoPeerPoolInfo();
error TokiPeerPoolInfoNotFound(uint256 chainId, uint256 poolId);
error TokiFlowRateLimitExceed(uint256 current, uint256 add, uint256 limit);
error TokiFallbackUnauthorized(address caller);
// used in mocks
error TokiMock(string message);
// channel upgrade
error TokiInvalidProposedVersion(string version);
error TokiChannelNotFound(string portId, string channelId);
// dex relation errors
error TokiIllegalSender(address caller);
error TokiInvalidPoolId(uint256 poolId);
// Uniswap route errors
error TokiPathRequired();
error TokiDiscontinuousPath();
error TokiUnsupportedCommand();
error TokiNotFoundPendingAsset(string dstChannel, uint64 sequence);
error TokiInvalidSwapParams();
error TokiInvalidCountParams();
error TokiEmptySwapParams();
// TokiToken specific errors
error TokiNotPrimaryChain();
// merkle proof verification
error TokiSaleEnded();
error TokiInvalidRound(uint256 currentRoundId);
error TokiInvalidMerkleProof();
error TokiAlreadyClaimed(uint256 windowIndex, address account);
error TokiInvalidSignature();
error TokiNonceAlreadyUsed();
error TokiUnauthorizedAccess(string message, address caller);
error TokiCooldownActive(uint256 endTime);
error TokiNotUnlocked();
error TokiNotReleased();
error TokiAlreadyUnlocked();
error TokiInvalidRecipient(string message);
error TokiInvalidRole(string message);
error TokiNotMatch(string message, uint256 actual, uint256 expected);
error TokiNotStarted();
error TokiAlreadyStarted();
error TokiInvalidCliff();
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import {IPool} from "../interfaces/IPool.sol";
/**
* @title ITransferPoolFeeCalculator
* @dev Interface for calculating fees for transferring between pools.
*/
interface ITransferPoolFeeCalculator {
/**
* @dev Struct for the source pool.
* @param addr The address of the source pool.
* @param id The ID of the source pool.
* @param globalDecimals The global decimals used by the source pool.
* @param balance The current balance of the source pool in GD (global decimals) units.
* @param totalLiquidity The total liquidity of the source pool in GD units.
* @param eqFeePool The equilibrium fee pool of the source pool in GD units.
*/
struct SrcPoolInfo {
address addr;
uint256 id;
uint8 globalDecimals;
uint256 balance;
uint256 totalLiquidity;
uint256 eqFeePool;
}
/**
* @dev Struct for the calculated fees.
* @param amountGD The transferring token amount converted to global decimals, from which eqFee and protocolFee are subtracted.
* @param protocolFee The protocol fee.
* @param lpFee The liquidity provider fee.
* @param eqFee The equilibrium fee.
* @param eqReward The equilibrium reward.
* @param balanceDecrease Balance reduction in source pool that will update destination pool's last known balance
*/
struct FeeInfo {
uint256 amountGD;
uint256 protocolFee;
uint256 lpFee;
uint256 eqFee;
uint256 eqReward;
uint256 balanceDecrease;
}
/**
* @dev Calculates the fees for transferring between pools.
* @param srcPoolInfo The struct of source pool.
* @param dstPoolInfo The struct of destination pool.
* @param from The address that transfers the token.
* @param amountGD The amount of the token in GD units.
* GD stands for Global Decimals. For more details, please refer to IPool.
* @return FeeInfo The calculated fees.
*/
function calcFee(
SrcPoolInfo calldata srcPoolInfo,
IPool.PeerPoolInfo calldata dstPoolInfo,
address from,
uint256 amountGD
) external view returns (FeeInfo memory);
/**
* @dev Returns the version of the fee calculator.
* @return The version string.
*/
function version() external pure returns (string memory);
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import {ITokiErrors} from "./interfaces/ITokiErrors.sol";
import {IStaticFlowRateLimiter} from "./interfaces/IStaticFlowRateLimiter.sol";
abstract contract StaticFlowRateLimiter is
IStaticFlowRateLimiter,
ITokiErrors,
Initializable,
AccessControlUpgradeable
{
/// @custom:storage-location erc7201:toki.storage.StaticFlowRateLimiter
struct StaticFlowRateLimiterStorage {
uint256 _currentPeriodEnd; // The block height at which the current period ends.
uint256 _currentPeriodAmount; // The amount of flow accumulated in the current period.
bool _appliedLockPeriod; // The flag to lock the flow rate limiting.
// TODO: Replace to transient storage when we update evm version to cancun or later.
uint256 _cancellableAmount; // The amount of flow that can be cancelled.
}
// keccak256(abi.encode(uint256(keccak256("toki.storage.StaticFlowRateLimiter")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant STATIC_FLOW_RATE_LIMITER_LOCATION =
0x0ee2d9de8392a8f17ff2bb7a24b72fd27e2cf4ac5cd7fd56e5bf7bdb439eb000;
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
uint256 public immutable PERIOD; // The period over which the flow is accumulated.
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
uint256 public immutable LOCK_PERIOD; // Rate limiting will be applied during LOCK_PERIOD after exceeding LIMIT.
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
uint256 public immutable LIMIT; // The maximum flow limit within the period.
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
uint256 public immutable THRESHOLD; // The threshold for accumulating flow.
/// @custom:oz-upgrades-unsafe-allow constructor
constructor(
uint256 period,
uint256 lockPeriod,
uint256 limit,
uint256 threshold
) {
PERIOD = period;
LOCK_PERIOD = lockPeriod;
LIMIT = limit;
THRESHOLD = threshold;
_disableInitializers();
}
function resetFlowRateLimit() public onlyRole(DEFAULT_ADMIN_ROLE) {
StaticFlowRateLimiterStorage
storage $ = _getStaticFlowRateLimiterStorage();
_resetFlowRateLimit($);
}
function currentPeriodEnd() public view returns (uint256) {
return _getStaticFlowRateLimiterStorage()._currentPeriodEnd;
}
function currentPeriodAmount() public view returns (uint256) {
return _getStaticFlowRateLimiterStorage()._currentPeriodAmount;
}
function appliedLockPeriod() public view returns (bool) {
return _getStaticFlowRateLimiterStorage()._appliedLockPeriod;
}
function _checkAndUpdateFlowRateLimit(
uint256 amount
) internal returns (bool) {
StaticFlowRateLimiterStorage
storage $ = _getStaticFlowRateLimiterStorage();
_updatePeriod();
// Disallow transfers that exceed current rate limit
if ($._currentPeriodAmount + amount > LIMIT) {
$._cancellableAmount = 0;
if (!$._appliedLockPeriod) {
$._appliedLockPeriod = true;
$._currentPeriodEnd += LOCK_PERIOD;
}
return false;
}
if (THRESHOLD < amount) {
// solhint-disable-next-line no-inline-assembly
$._cancellableAmount = amount;
$._currentPeriodAmount += amount;
} else {
$._cancellableAmount = 0;
}
return true;
}
function _cancelFlowRateLimit() internal {
StaticFlowRateLimiterStorage
storage $ = _getStaticFlowRateLimiterStorage();
if ($._currentPeriodAmount < $._cancellableAmount) {
$._currentPeriodAmount = 0;
} else {
$._currentPeriodAmount -= $._cancellableAmount;
}
$._cancellableAmount = 0;
}
// solhint-disable-next-line func-name-mixedcase
function __StaticFlowRateLimiter_init(
address admin
) internal onlyInitializing {
__AccessControl_init();
_grantRole(DEFAULT_ADMIN_ROLE, admin);
__StaticFlowRateLimiter_init_unchained();
}
// solhint-disable-next-line func-name-mixedcase
function __StaticFlowRateLimiter_init_unchained()
internal
onlyInitializing
{
StaticFlowRateLimiterStorage
storage $ = _getStaticFlowRateLimiterStorage();
$._currentPeriodEnd = block.number + PERIOD;
}
function _updatePeriod() private {
StaticFlowRateLimiterStorage
storage $ = _getStaticFlowRateLimiterStorage();
if ($._currentPeriodEnd < block.number) {
_resetFlowRateLimit($);
}
}
function _resetFlowRateLimit(
StaticFlowRateLimiterStorage storage $
) private {
$._currentPeriodEnd = block.number + PERIOD;
$._currentPeriodAmount = 0;
$._appliedLockPeriod = false;
}
function _getStaticFlowRateLimiterStorage()
private
pure
returns (StaticFlowRateLimiterStorage storage $)
{
// solhint-disable-next-line no-inline-assembly
assembly {
$.slot := STATIC_FLOW_RATE_LIMITER_LOCATION
}
}
}{
"evmVersion": "cancun",
"viaIR": true,
"optimizer": {
"enabled": true,
"runs": 400
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"uint256","name":"period","type":"uint256"},{"internalType":"uint256","name":"lockPeriod","type":"uint256"},{"internalType":"uint256","name":"limit","type":"uint256"},{"internalType":"uint256","name":"threshold","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AccessControlBadConfirmation","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"neededRole","type":"bytes32"}],"name":"AccessControlUnauthorizedAccount","type":"error"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[],"name":"ECDSAInvalidSignature","type":"error"},{"inputs":[{"internalType":"uint256","name":"length","type":"uint256"}],"name":"ECDSAInvalidSignatureLength","type":"error"},{"inputs":[{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"ECDSAInvalidSignatureS","type":"error"},{"inputs":[{"internalType":"address","name":"implementation","type":"address"}],"name":"ERC1967InvalidImplementation","type":"error"},{"inputs":[],"name":"ERC1967NonPayable","type":"error"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"allowance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"ERC20InsufficientAllowance","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"ERC20InsufficientBalance","type":"error"},{"inputs":[{"internalType":"address","name":"approver","type":"address"}],"name":"ERC20InvalidApprover","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"ERC20InvalidReceiver","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"ERC20InvalidSender","type":"error"},{"inputs":[{"internalType":"address","name":"spender","type":"address"}],"name":"ERC20InvalidSpender","type":"error"},{"inputs":[{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"ERC2612ExpiredSignature","type":"error"},{"inputs":[{"internalType":"address","name":"signer","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"ERC2612InvalidSigner","type":"error"},{"inputs":[],"name":"FailedCall","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"currentNonce","type":"uint256"}],"name":"InvalidAccountNonce","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"uint256","name":"windowIndex","type":"uint256"},{"internalType":"address","name":"account","type":"address"}],"name":"TokiAlreadyClaimed","type":"error"},{"inputs":[],"name":"TokiAlreadyStarted","type":"error"},{"inputs":[],"name":"TokiAlreadyUnlocked","type":"error"},{"inputs":[],"name":"TokiCannotCloseChannel","type":"error"},{"inputs":[],"name":"TokiCannotTimeoutPacket","type":"error"},{"inputs":[{"internalType":"string","name":"portId","type":"string"},{"internalType":"string","name":"channelId","type":"string"}],"name":"TokiChannelNotFound","type":"error"},{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"address","name":"addr","type":"address"}],"name":"TokiContractNotAllowed","type":"error"},{"inputs":[{"internalType":"uint256","name":"endTime","type":"uint256"}],"name":"TokiCooldownActive","type":"error"},{"inputs":[{"internalType":"uint256","name":"poolId","type":"uint256"}],"name":"TokiDepeg","type":"error"},{"inputs":[],"name":"TokiDiscontinuousPath","type":"error"},{"inputs":[{"internalType":"uint256","name":"dstChainId","type":"uint256"}],"name":"TokiDstChainIdNotAccepted","type":"error"},{"inputs":[],"name":"TokiDstOuterGasShouldBeZero","type":"error"},{"inputs":[],"name":"TokiEmptySwapParams","type":"error"},{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"limit","type":"uint256"}],"name":"TokiExceed","type":"error"},{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"uint256","name":"current","type":"uint256"},{"internalType":"uint256","name":"add","type":"uint256"},{"internalType":"uint256","name":"limit","type":"uint256"}],"name":"TokiExceedAdd","type":"error"},{"inputs":[],"name":"TokiFailToRefund","type":"error"},{"inputs":[{"internalType":"address","name":"caller","type":"address"}],"name":"TokiFallbackUnauthorized","type":"error"},{"inputs":[{"internalType":"uint256","name":"current","type":"uint256"},{"internalType":"uint256","name":"add","type":"uint256"},{"internalType":"uint256","name":"limit","type":"uint256"}],"name":"TokiFlowRateLimitExceed","type":"error"},{"inputs":[{"internalType":"address","name":"caller","type":"address"}],"name":"TokiIllegalSender","type":"error"},{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"uint256","name":"allowance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"TokiInsufficientAllowance","type":"error"},{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"TokiInsufficientAmount","type":"error"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"TokiInsufficientPoolLiquidity","type":"error"},{"inputs":[{"internalType":"uint256","name":"expected","type":"uint256"},{"internalType":"uint256","name":"actual","type":"uint256"}],"name":"TokiInvalidAppVersion","type":"error"},{"inputs":[],"name":"TokiInvalidBalanceDeficitFeeZone","type":"error"},{"inputs":[],"name":"TokiInvalidCliff","type":"error"},{"inputs":[],"name":"TokiInvalidCountParams","type":"error"},{"inputs":[],"name":"TokiInvalidMerkleProof","type":"error"},{"inputs":[{"internalType":"uint8","name":"","type":"uint8"}],"name":"TokiInvalidPacketType","type":"error"},{"inputs":[{"internalType":"uint256","name":"poolId","type":"uint256"}],"name":"TokiInvalidPoolId","type":"error"},{"inputs":[{"internalType":"string","name":"version","type":"string"}],"name":"TokiInvalidProposedVersion","type":"error"},{"inputs":[{"internalType":"string","name":"message","type":"string"}],"name":"TokiInvalidRecipient","type":"error"},{"inputs":[],"name":"TokiInvalidRecipientBytes","type":"error"},{"inputs":[{"internalType":"uint8","name":"","type":"uint8"}],"name":"TokiInvalidRetryType","type":"error"},{"inputs":[{"internalType":"string","name":"message","type":"string"}],"name":"TokiInvalidRole","type":"error"},{"inputs":[{"internalType":"uint256","name":"currentRoundId","type":"uint256"}],"name":"TokiInvalidRound","type":"error"},{"inputs":[{"internalType":"uint256","name":"min","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"TokiInvalidSafeZoneRange","type":"error"},{"inputs":[],"name":"TokiInvalidSignature","type":"error"},{"inputs":[],"name":"TokiInvalidSwapParams","type":"error"},{"inputs":[{"internalType":"string","name":"message","type":"string"}],"name":"TokiMock","type":"error"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"TokiNativeTransferIsFailed","type":"error"},{"inputs":[],"name":"TokiNoFee","type":"error"},{"inputs":[],"name":"TokiNoPeerPoolInfo","type":"error"},{"inputs":[{"internalType":"uint256","name":"poolId","type":"uint256"}],"name":"TokiNoPool","type":"error"},{"inputs":[],"name":"TokiNoRevertReceive","type":"error"},{"inputs":[],"name":"TokiNonceAlreadyUsed","type":"error"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"limit","type":"uint256"}],"name":"TokiNotEnoughNativeFee","type":"error"},{"inputs":[{"internalType":"string","name":"dstChannel","type":"string"},{"internalType":"uint64","name":"sequence","type":"uint64"}],"name":"TokiNotFoundPendingAsset","type":"error"},{"inputs":[{"internalType":"string","name":"message","type":"string"},{"internalType":"uint256","name":"actual","type":"uint256"},{"internalType":"uint256","name":"expected","type":"uint256"}],"name":"TokiNotMatch","type":"error"},{"inputs":[],"name":"TokiNotPrimaryChain","type":"error"},{"inputs":[],"name":"TokiNotReleased","type":"error"},{"inputs":[],"name":"TokiNotStarted","type":"error"},{"inputs":[],"name":"TokiNotUnlocked","type":"error"},{"inputs":[],"name":"TokiPathRequired","type":"error"},{"inputs":[{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"uint256","name":"poolId","type":"uint256"}],"name":"TokiPeerPoolInfoNotFound","type":"error"},{"inputs":[{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"uint256","name":"poolId","type":"uint256"}],"name":"TokiPeerPoolIsAlreadyActive","type":"error"},{"inputs":[{"internalType":"uint256","name":"peerChainId","type":"uint256"},{"internalType":"uint256","name":"peerPoolId","type":"uint256"}],"name":"TokiPeerPoolIsNotReady","type":"error"},{"inputs":[{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"uint256","name":"poolId","type":"uint256"}],"name":"TokiPeerPoolIsRegistered","type":"error"},{"inputs":[{"internalType":"uint256","name":"poolId","type":"uint256"}],"name":"TokiPoolRecvIsFailed","type":"error"},{"inputs":[{"internalType":"uint256","name":"poolId","type":"uint256"}],"name":"TokiPoolWithdrawConfirmIsFailed","type":"error"},{"inputs":[{"internalType":"uint256","name":"updatedAt","type":"uint256"}],"name":"TokiPriceIsExpired","type":"error"},{"inputs":[{"internalType":"int256","name":"value","type":"int256"}],"name":"TokiPriceIsNotPositive","type":"error"},{"inputs":[],"name":"TokiRequireOrderedChannel","type":"error"},{"inputs":[{"internalType":"uint256","name":"expiryBlock","type":"uint256"}],"name":"TokiRetryExpired","type":"error"},{"inputs":[],"name":"TokiSaleEnded","type":"error"},{"inputs":[{"internalType":"uint256","name":"poolId","type":"uint256"},{"internalType":"address","name":"pool","type":"address"}],"name":"TokiSamePool","type":"error"},{"inputs":[{"internalType":"uint256","name":"amountGD","type":"uint256"},{"internalType":"uint256","name":"eqReward","type":"uint256"},{"internalType":"uint256","name":"eqFee","type":"uint256"},{"internalType":"uint256","name":"minAmountGD","type":"uint256"}],"name":"TokiSlippageTooHigh","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"TokiTransferIsFailed","type":"error"},{"inputs":[],"name":"TokiTransferIsStop","type":"error"},{"inputs":[{"internalType":"string","name":"message","type":"string"},{"internalType":"address","name":"caller","type":"address"}],"name":"TokiUnauthorizedAccess","type":"error"},{"inputs":[{"internalType":"string","name":"channel","type":"string"}],"name":"TokiUnregisteredChainId","type":"error"},{"inputs":[{"internalType":"uint256","name":"poolId","type":"uint256"}],"name":"TokiUnregisteredPoolId","type":"error"},{"inputs":[],"name":"TokiUnsupportedCommand","type":"error"},{"inputs":[{"internalType":"string","name":"message","type":"string"}],"name":"TokiZeroAddress","type":"error"},{"inputs":[{"internalType":"string","name":"message","type":"string"}],"name":"TokiZeroAmount","type":"error"},{"inputs":[{"internalType":"string","name":"message","type":"string"}],"name":"TokiZeroValue","type":"error"},{"inputs":[],"name":"UUPSUnauthorizedCallContext","type":"error"},{"inputs":[{"internalType":"bytes32","name":"slot","type":"bytes32"}],"name":"UUPSUnsupportedProxiableUUID","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountLP","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountGD","type":"uint256"}],"name":"Burn","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountLD","type":"uint256"}],"name":"DrawFee","type":"event"},{"anonymous":false,"inputs":[],"name":"EIP712DomainChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountLP","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountGD","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"peerChainId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"peerPoolId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"weight","type":"uint256"}],"name":"PeerPoolInfoUpdate","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountGD","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"protocolFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"eqFee","type":"uint256"}],"name":"Recv","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"peerPoolId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"credits","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"targetBalance","type":"uint256"}],"name":"SendCredit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"dstFlowRateLimiter","type":"address"}],"name":"SetDstFlowRateLimiter","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"maxTotalDepositsLD","type":"uint256"}],"name":"SetMaxTotalDeposits","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":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"peerChainId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"peerPoolId","type":"uint256"},{"indexed":false,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountGD","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"eqReward","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"eqFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"protocolFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"lpFee","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"peerChainId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"peerPoolId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"credits","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"targetBalance","type":"uint256"}],"name":"UpdateCredit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"batched","type":"bool"},{"indexed":false,"internalType":"uint256","name":"swapDeltaBP","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"lpDeltaBP","type":"uint256"},{"indexed":false,"internalType":"bool","name":"defaultSwapMode","type":"bool"},{"indexed":false,"internalType":"bool","name":"defaultLPMode","type":"bool"}],"name":"UpdateDeltaParam","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"stopTransfer","type":"bool"}],"name":"UpdateStopTransfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"peerChainId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"peerPoolId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountLP","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountGD","type":"uint256"}],"name":"WithdrawCheck","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"peerChainId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"peerPoolId","type":"uint256"},{"indexed":false,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountGD","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountMintGD","type":"uint256"}],"name":"WithdrawConfirm","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountLP","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountGD","type":"uint256"},{"indexed":false,"internalType":"address","name":"to","type":"address"}],"name":"WithdrawInstant","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"peerChainId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"peerPoolId","type":"uint256"},{"indexed":false,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountLP","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountGD","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"to","type":"bytes"}],"name":"WithdrawLocal","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"peerChainId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"peerPoolId","type":"uint256"},{"indexed":false,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountLP","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountLD","type":"uint256"}],"name":"WithdrawRemote","type":"event"},{"inputs":[],"name":"BPS_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ROUTER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amountLD","type":"uint256"}],"name":"LDToLP","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LIMIT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LOCK_PERIOD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountLP","type":"uint256"}],"name":"LPToLD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_PEERS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PERIOD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"THRESHOLD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UPGRADE_INTERFACE_VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"peerChainId","type":"uint256"},{"internalType":"uint256","name":"peerPoolId","type":"uint256"}],"name":"activatePeerPool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"appliedLockPeriod","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"batched","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"peerChainId","type":"uint256"},{"internalType":"uint256","name":"peerPoolId","type":"uint256"},{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"amountLD","type":"uint256"}],"name":"calcFee","outputs":[{"components":[{"internalType":"uint256","name":"amountGD","type":"uint256"},{"internalType":"uint256","name":"protocolFee","type":"uint256"},{"internalType":"uint256","name":"lpFee","type":"uint256"},{"internalType":"uint256","name":"eqFee","type":"uint256"},{"internalType":"uint256","name":"eqReward","type":"uint256"},{"internalType":"uint256","name":"balanceDecrease","type":"uint256"}],"internalType":"struct ITransferPoolFeeCalculator.FeeInfo","name":"feeInfo","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"fullMode","type":"bool"}],"name":"callDelta","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"convertRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentPeriodAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentPeriodEnd","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultLPMode","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultSwapMode","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"deltaCredit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"drawFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"eip712Domain","outputs":[{"internalType":"bytes1","name":"fields","type":"bytes1"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"version","type":"string"},{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"address","name":"verifyingContract","type":"address"},{"internalType":"bytes32","name":"salt","type":"bytes32"},{"internalType":"uint256[]","name":"extensions","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"eqFeePool","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeCalculator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"peerChainId","type":"uint256"},{"internalType":"uint256","name":"peerPoolId","type":"uint256"}],"name":"getPeerPoolInfo","outputs":[{"components":[{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"weight","type":"uint256"},{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"targetBalance","type":"uint256"},{"internalType":"uint256","name":"lastKnownBalance","type":"uint256"},{"internalType":"uint256","name":"credits","type":"uint256"},{"internalType":"bool","name":"ready","type":"bool"}],"internalType":"struct IPool.PeerPoolInfo","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"globalDecimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"peerChainId","type":"uint256"},{"internalType":"uint256","name":"peerPoolId","type":"uint256"},{"internalType":"address","name":"","type":"address"},{"components":[{"internalType":"uint256","name":"amountGD","type":"uint256"},{"internalType":"uint256","name":"protocolFee","type":"uint256"},{"internalType":"uint256","name":"lpFee","type":"uint256"},{"internalType":"uint256","name":"eqFee","type":"uint256"},{"internalType":"uint256","name":"eqReward","type":"uint256"},{"internalType":"uint256","name":"balanceDecrease","type":"uint256"}],"internalType":"struct ITransferPoolFeeCalculator.FeeInfo","name":"feeInfo","type":"tuple"}],"name":"handleRecvFailure","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"peerChainId","type":"uint256"},{"internalType":"uint256","name":"peerPoolId","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amountGD","type":"uint256"},{"internalType":"uint256","name":"amountToMintGD","type":"uint256"}],"name":"handleWithdrawConfirmFailure","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"uint256","name":"poolId","type":"uint256"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint8","name":"globalDecimals","type":"uint8"},{"internalType":"uint8","name":"localDecimals","type":"uint8"},{"internalType":"address","name":"feeCalculator","type":"address"},{"internalType":"address","name":"admin","type":"address"},{"internalType":"address","name":"router","type":"address"},{"internalType":"uint256","name":"maxTotalDeposits","type":"uint256"}],"internalType":"struct Pool.InitializeParam","name":"p","type":"tuple"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"localDecimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lpDeltaBP","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxTotalDeposits","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amountLD","type":"uint256"}],"name":"mint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"peerChainId","type":"uint256"},{"internalType":"uint256","name":"peerPoolId","type":"uint256"}],"name":"peerPoolInfoIndexSeek","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"peerPoolInfos","outputs":[{"components":[{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"weight","type":"uint256"},{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"targetBalance","type":"uint256"},{"internalType":"uint256","name":"lastKnownBalance","type":"uint256"},{"internalType":"uint256","name":"credits","type":"uint256"},{"internalType":"bool","name":"ready","type":"bool"}],"internalType":"struct IPool.PeerPoolInfo","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"poolId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"peerChainId","type":"uint256"},{"internalType":"uint256","name":"peerPoolId","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"components":[{"internalType":"uint256","name":"amountGD","type":"uint256"},{"internalType":"uint256","name":"protocolFee","type":"uint256"},{"internalType":"uint256","name":"lpFee","type":"uint256"},{"internalType":"uint256","name":"eqFee","type":"uint256"},{"internalType":"uint256","name":"eqReward","type":"uint256"},{"internalType":"uint256","name":"balanceDecrease","type":"uint256"}],"internalType":"struct ITransferPoolFeeCalculator.FeeInfo","name":"feeInfo","type":"tuple"},{"internalType":"bool","name":"updateDelta","type":"bool"}],"name":"recv","outputs":[{"internalType":"uint256","name":"amountLD","type":"uint256"},{"internalType":"bool","name":"isTransferred","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"peerChainId","type":"uint256"},{"internalType":"uint256","name":"peerPoolId","type":"uint256"},{"internalType":"uint256","name":"weight","type":"uint256"}],"name":"registerPeerPool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"callerConfirmation","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"resetFlowRateLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"peerChainId","type":"uint256"},{"internalType":"uint256","name":"peerPoolId","type":"uint256"}],"name":"sendCredit","outputs":[{"components":[{"internalType":"uint256","name":"credits","type":"uint256"},{"internalType":"uint256","name":"targetBalance","type":"uint256"}],"internalType":"struct IPool.CreditInfo","name":"creditInfo","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"batched_","type":"bool"},{"internalType":"uint256","name":"swapDeltaBP_","type":"uint256"},{"internalType":"uint256","name":"lpDeltaBP_","type":"uint256"},{"internalType":"bool","name":"defaultSwapMode_","type":"bool"},{"internalType":"bool","name":"defaultLPMode_","type":"bool"}],"name":"setDeltaParam","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_feeCalculator","type":"address"}],"name":"setFeeCalculator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newMaxTotalDeposits","type":"uint256"}],"name":"setMaxTotalDeposits","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"peerChainId","type":"uint256"},{"internalType":"uint256","name":"peerPoolId","type":"uint256"},{"internalType":"uint256","name":"weight","type":"uint256"}],"name":"setPeerPoolWeight","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"transferStop_","type":"bool"}],"name":"setTransferStop","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapDeltaBP","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalLiquidity","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalWeight","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"peerChainId","type":"uint256"},{"internalType":"uint256","name":"peerPoolId","type":"uint256"},{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"amountLD","type":"uint256"},{"internalType":"uint256","name":"minAmountLD","type":"uint256"},{"internalType":"bool","name":"newLiquidity","type":"bool"}],"name":"transfer","outputs":[{"components":[{"internalType":"uint256","name":"amountGD","type":"uint256"},{"internalType":"uint256","name":"protocolFee","type":"uint256"},{"internalType":"uint256","name":"lpFee","type":"uint256"},{"internalType":"uint256","name":"eqFee","type":"uint256"},{"internalType":"uint256","name":"eqReward","type":"uint256"},{"internalType":"uint256","name":"balanceDecrease","type":"uint256"}],"internalType":"struct ITransferPoolFeeCalculator.FeeInfo","name":"feeInfo","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"transferStop","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"peerChainId","type":"uint256"},{"internalType":"uint256","name":"peerPoolId","type":"uint256"},{"components":[{"internalType":"uint256","name":"credits","type":"uint256"},{"internalType":"uint256","name":"targetBalance","type":"uint256"}],"internalType":"struct IPool.CreditInfo","name":"creditInfo","type":"tuple"}],"name":"updateCredit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"peerChainId","type":"uint256"},{"internalType":"uint256","name":"peerPoolId","type":"uint256"},{"internalType":"uint256","name":"amountGD","type":"uint256"}],"name":"withdrawCheck","outputs":[{"internalType":"uint256","name":"amountSwap","type":"uint256"},{"internalType":"uint256","name":"amountMint","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"peerChainId","type":"uint256"},{"internalType":"uint256","name":"peerPoolId","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amountGD","type":"uint256"},{"internalType":"uint256","name":"amountToMintGD","type":"uint256"},{"internalType":"bool","name":"updateDelta","type":"bool"}],"name":"withdrawConfirm","outputs":[{"internalType":"bool","name":"isTransferred","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"amountLP","type":"uint256"},{"internalType":"address","name":"to","type":"address"}],"name":"withdrawInstant","outputs":[{"internalType":"uint256","name":"amountGD","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"peerChainId","type":"uint256"},{"internalType":"uint256","name":"peerPoolId","type":"uint256"},{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"amountLP","type":"uint256"},{"internalType":"bytes","name":"to","type":"bytes"}],"name":"withdrawLocal","outputs":[{"internalType":"uint256","name":"amountGD","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"peerChainId","type":"uint256"},{"internalType":"uint256","name":"peerPoolId","type":"uint256"},{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"amountLP","type":"uint256"}],"name":"withdrawRemote","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
0x6101203461016257601f615f6d38819003918201601f19168301916001600160401b038311848410176101665780849260809460405283398101031261016257805190602081015160606040830151920151923060805260a05260c05260e052610100525f516020615f4d5f395f51905f525460ff8160401c16610153576002600160401b03196001600160401b038216016100fd575b604051615dd2908161017b8239608051818181611ca50152611d75015260a051818181610daf0152818161392a01526154c9015260c051818181612eb30152615355015260e051818181610e1b015261526c01526101005181818161181c01526152930152f35b6001600160401b0319166001600160401b039081175f516020615f4d5f395f51905f52556040519081527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d290602090a15f610096565b63f92ee8a960e01b5f5260045ffd5b5f80fd5b634e487b7160e01b5f52604160045260245ffdfe60806040526004361015610011575f80fd5b5f3560e01c80630130c4d21461356457806301ffc9a71461350e57806306fdde0314613451578063095ea7b31461342b5780630f45684a14612725578063106e846b1461340057806310a470ab14612f43578063113ac8f614612f2857806315770f9214612eff57806318160ddd14612ed65780631820cabb14612e9c5780631e8e51da14612e7357806323b872dd14612d34578063248a9ca314612cfd57806327f9237614612ccf57806328f079c214612c9e5780632b3afdb01461279b5780632f2ff15d14612751578063313ce5671461272557806336448777146126fc5780633644e515146126e257806336568abe1461269e57806338898ca21461264a5780633dc69f2c146123d75780633e0dc34e1461239b5780633f668d6f1461234d5780633fc03c261461222857806340c10f1914611f6257806343469f3214611f115780634f1ef28614611d2657806351fe0e1814611cf157806352d1902d14611c8b5780635879445614611c62578063601c186114611b7f57806360b71d4e14611b5657806361b01b5d14611b1a578063641ffaa1146119c75780636780a3111461199657806370a082311461195257806372e30f6a1461186d578063754f56e21461183f578063785ffb37146118055780637ecebe00146117ae5780637fb652651461178557806384b0196e1461163357806388cb0df7146115175780638c66d04f146114c05780638cdc1f24146113b95780638d55de631461132f57806390c83e94146112c557806391d148541461126f57806392c883fb146110e957806395d89b4114610ff357806396c82e5714610fca57806399a22d6814610f995780639bb8111914610f705780639c3701a014610f505780639d3c38c514610ed0578063a217fddf14610eb6578063a9059cbb14610e85578063ad3cb1cc14610e3e578063af8214ef14610e04578063b00eb9fe14610dd2578063b4d1d79514610d98578063b6192d0b14610c09578063b81d85f014610b60578063c0dca06e146109d3578063c646b16614610931578063ca981909146108f7578063cdfed0ab146108bb578063d505accf14610765578063d547741f14610714578063dd62ed3e1461069b578063e065608b146104e7578063e1a45218146104cb578063e465eb9e146104a2578063e46e705814610473578063e5b15b52146103e8578063fc0c546a146103b65763feb56b1514610389575f80fd5b346103b2575f3660031901126103b25760205f516020615cdd5f395f51905f5254604051908152f35b5f80fd5b346103b2575f3660031901126103b25760206001600160a01b035f516020615d1d5f395f51905f525416604051908152f35b346103b25761046f61041361040e6103ff36614112565b906104086143b1565b506149bd565b614435565b6040519182918291909160e080610100830194805184526020810151602085015260408101516040850152606081015160608501526080810151608085015260a081015160a085015260c081015160c085015201511515910152565b0390f35b346103b2575f3660031901126103b257602060ff5f516020615afd5f395f51905f525460081c16604051908152f35b346103b2575f3660031901126103b25760205f516020615b3d5f395f51905f5254604051908152f35b346103b2575f3660031901126103b25760206040516127108152f35b346103b25760a03660031901126103b257610500613fea565b602435604435916064358015158091036103b257608435918215158093036103b25761052a614921565b612710841161065857612710851161061757907fdef0a5f359f70f4feaf27bbd47c7e476348ea79108e46990d5b73efbc885f0379460a094939215159360ff195f516020615c9d5f395f51905f52541660ff8616175f516020615c9d5f395f51905f5255807f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0955815f516020615c1d5f395f51905f52555f516020615c9d5f395f51905f525462ff00008560101b169061ff008560081b169062ffff00191617175f516020615c9d5f395f51905f52556040519485526020850152604084015260608301526080820152a1005b6040516338d06e1d60e01b815260606004820152600960648201526806c7044656c746142560bc1b608482015260248101869052612710604482015260a490fd5b6040516338d06e1d60e01b815260606004820152600b60648201526a07377617044656c746142560ac1b608482015260248101859052612710604482015260a490fd5b346103b25760403660031901126103b2576106b4613fa8565b6001600160a01b036106fe6106c7613fbe565b926001600160a01b03165f527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0160205260405f2090565b91165f52602052602060405f2054604051908152f35b346103b25760403660031901126103b257610763600435610733613fbe565b9061075e610759825f525f516020615c5d5f395f51905f52602052600160405f20015490565b614970565b61507a565b005b346103b25760e03660031901126103b25761077e613fa8565b610786613fbe565b604435906064359260843560ff811681036103b2578442116108a85761087e6108756001600160a01b039283851697885f527f5ab42ced628888259c08ac98db1eb0cf702fc1501344311d8b100cd1bfe4bb0060205260405f20908154916001830190556040519060208201927f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c984528b6040840152878a1660608401528a608084015260a083015260c082015260c0815261084360e08261408d565b51902061084e6157f6565b906040519161190160f01b83526002830152602282015260c43591604260a435922061585d565b909291926158df565b16848103610891575061076393506156b8565b84906325c0072360e11b5f5260045260245260445ffd5b8463313c898160e11b5f5260045260245ffd5b346103b2575f3660031901126103b25760207f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0954604051908152f35b346103b2575f3660031901126103b25760206040517f66d05ae646b1ee24e48a8708b8c0f6eade385a89cd689a1ed9121cb3ec9e21028152f35b346103b2577f5b1ee307451dd65aa45d1657a66752bab8925be9aad7c827865655c8c2fdac246109ce610963366140f8565b61096e939193614921565b8061097985856149bd565b6109a18261099c60025f516020615b9d5f395f51905f52549401938454906145d3565b6145c6565b5f516020615b9d5f395f51905f525555604051938493846040919493926060820195825260208201520152565b0390a1005b346103b25760206109e336613ff9565b6109f29592919594939461487d565b6109fa6148b2565b5f90610afa575b610a195f516020615cdd5f395f51905f5254836145e0565b600190468503610ae9575b81610ac0575b5015610aad57507fcf0b8bea497be617351b2c1a4243bd9e92167fdf778a43ebb66fb37160594a0f9394610a8f9160019660405195869586916080936001600160a01b0391979695929760a08501988552602085015216604083015260608201520152565b0390a15b5f5f516020615cfd5f395f51905f525d6040519015158152f35b945050505050610abb61545c565b610a93565b610ae39150866001600160a01b035f516020615d1d5f395f51905f5254166153d7565b88610a2a565b9050610af48161523c565b90610a24565b85151580610b4e575b610b27575b6005610b1485856149bd565b01610b208382546145d3565b9055610a01565b610b48610b425f516020615cdd5f395f51905f5254886145e0565b86615531565b50610b08565b506001600160a01b0385161515610b03565b346103b25760a03660031901126103b257610b79613fd4565b60843590610b8561487d565b610b8d6148b2565b81151580610bf7575b610bcd575b6005610bab6024356004356149bd565b01610bb960643582546145d3565b90555f5f516020615cfd5f395f51905f525d005b610be9610bef925f516020615cdd5f395f51905f5254906145e0565b90615531565b508080610b9b565b506001600160a01b0381161515610b96565b346103b257610c4360c0610c2d610c1f3661417a565b959261040894929194614494565b935f516020615cdd5f395f51905f5254906145f3565b927f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0b549060ff5f516020615afd5f395f51905f525416610c81614a5f565b5f516020615a7d5f395f51905f5254905f516020615cbd5f395f51905f52549260405195610cae87614038565b308752602087015260408601526060850152608084015260a08301526001600160a01b035f516020615bbd5f395f51905f52541691610d036040519687958694859463143273dd60e21b865260048601614514565b03915afa8015610d8d5761046f915f91610d5e575b506040519182918291909160a08060c083019480518452602081015160208501526040810151604085015260608101516060850152608081015160808501520151910152565b610d80915060c03d60c011610d86575b610d78818361408d565b8101906144c4565b82610d18565b503d610d6e565b6040513d5f823e3d90fd5b346103b2575f3660031901126103b25760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b346103b2575f3660031901126103b25760206001600160a01b035f516020615bbd5f395f51905f525416604051908152f35b346103b2575f3660031901126103b25760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b346103b2575f3660031901126103b25761046f604051610e5f60408261408d565b60058152640352e302e360dc1b6020820152604051918291602083526020830190613f84565b346103b25760403660031901126103b257610eab610ea1613fa8565b6024359033614de4565b602060405160018152f35b346103b2575f3660031901126103b25760206040515f8152f35b346103b25760203660031901126103b2577fc0aea4cb7421bc8d3cf83582abe451bd1705682eb83b02b88889940492aef5ca6020610f0c613fea565b610f14614921565b5f516020615d1d5f395f51905f52805460ff60a01b191691151560a090811b60ff60a01b169290921790819055604051911c60ff1615158152a1005b346103b2575f3660031901126103b257610f68614921565b6107636154c4565b346103b2575f3660031901126103b25760205f516020615cbd5f395f51905f5254604051908152f35b346103b2575f3660031901126103b257602060ff5f516020615c9d5f395f51905f525460081c166040519015158152f35b346103b2575f3660031901126103b25760205f516020615b9d5f395f51905f5254604051908152f35b346103b2575f3660031901126103b2576040515f5f516020615b1d5f395f51905f525461101f816141fd565b80845290600181169081156110c5575060011461105b575b61046f836110478185038261408d565b604051918291602083526020830190613f84565b5f516020615b1d5f395f51905f525f9081527f46a2803e59a4de4e7a4c574b1243f25977ac4c77d5a1a4a609b5394cebb4a2aa939250905b8082106110ab57509091508101602001611047611037565b919260018160209254838588010152019101909291611093565b60ff191660208086019190915291151560051b840190910191506110479050611037565b346103b2576101403660031901126103b257600435611106613fd4565b90611110366140af565b91610124359081151582036103b25760409361112a61487d565b6111326148b2565b5f92611240575b80519261116461114f60808401958651906145c6565b5f516020615cdd5f395f51905f5254906145e0565b946001904603611231575b80611209575b156111f857507f82f23eb0ffa46ea98b1a7134447f74561cec3e194d0f1d06ffc35ce71ae80336916080916111b060019582519051906145c6565b9060606020820151910151916001600160a01b038951941684526020840152878301526060820152a15b5f5f516020615cfd5f395f51905f525d825191825215156020820152f35b9250505061120461545c565b6111da565b5061122c85846001600160a01b035f516020615d1d5f395f51905f5254166153d7565b611175565b5061123b8561523c565b61116f565b61124981615117565b60a0810151611268600561125f602435886149bd565b019182546145d3565b9055611139565b346103b25760403660031901126103b257611288613fbe565b6004355f525f516020615c5d5f395f51905f526020526001600160a01b0360405f2091165f52602052602060ff60405f2054166040519015158152f35b346103b25760203660031901126103b2576004356112e1614921565b7f0320c21101a3b92f1a57a1daef0827408be5f6cb7bb44fb426cc4152663e611d6020604051838152a17f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0d55005b346103b25760203660031901126103b2575f516020615b5d5f395f51905f525480156113855761137d61114f6020926113785f516020615a7d5f395f51905f52546004356145e0565b6145f3565b604051908152f35b604051634612b38f60e01b815260206004820152600b60248201526a746f74616c537570706c7960a81b6044820152606490fd5b346103b25760203660031901126103b2576113d2613fa8565b6113da614921565b6001600160a01b03811615611495575f516020615d5d5f395f51905f52549081156114865761141b610763925f516020615cdd5f395f51905f5254906145e0565b5f5f516020615d5d5f395f51905f5255604080516001600160a01b0384168152602081018390529192917f0a7a10dab02ee70c589a87e2b0d57484d85d029e381c3ca52387e25486a4c5389190a16001600160a01b035f516020615d1d5f395f51905f525416615202565b636e63c7c360e01b5f5260045ffd5b604051636bc37c5f60e11b8152602060048201526002602482015261746f60f01b6044820152606490fd5b346103b25760203660031901126103b2576001600160a01b036114e1613fa8565b6114e9614921565b166001600160a01b03195f516020615bbd5f395f51905f525416175f516020615bbd5f395f51905f52555f80f35b346103b25761152536614112565b906040519061153382614071565b5f825260208201905f825261154661487d565b61154e6148b2565b61155884826149bd565b90600160ff60078401541615150361161c57506040935f7f0aeafd14584f8a6bfe6b3846da893395e218188cb3ba5586a705848f7fbcb1ad926115c66115b15f516020615a7d5f395f51905f52546002840154906145e0565b5f516020615b9d5f395f51905f5254906145f3565b855260068101906115e16005835492838a52019182546145c6565b90555583518351865192835260208301919091526040820152606090a15f5f516020615cfd5f395f51905f525d825191518252516020820152f35b8490631c6768ad60e21b5f5260045260245260445ffd5b346103b2575f3660031901126103b2577fa16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d10054158061175c575b15611717576116bb61167c614235565b611684614304565b60206116c960405192611697838561408d565b5f84525f368137604051958695600f60f81b875260e08588015260e0870190613f84565b908582036040870152613f84565b4660608501523060808501525f60a085015283810360c08501528180845192838152019301915f5b82811061170057505050500390f35b8351855286955093810193928101926001016116f1565b60405162461bcd60e51b815260206004820152601560248201527f4549503731323a20556e696e697469616c697a656400000000000000000000006044820152606490fd5b507fa16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d101541561166c565b346103b25760203660031901126103b2576107636117a1613fea565b6117a96148b2565b614b06565b346103b25760203660031901126103b2576001600160a01b036117cf613fa8565b165f527f5ab42ced628888259c08ac98db1eb0cf702fc1501344311d8b100cd1bfe4bb00602052602060405f2054604051908152f35b346103b2575f3660031901126103b25760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b346103b2575f3660031901126103b257602060ff5f516020615bfd5f395f51905f5254166040519015158152f35b346103b25760803660031901126103b25760043560243560403660431901126103b2577fdbbc76676cb73b8d1c33378e0cdc88f364e4203cfa5b1e4c7d15b66b5cb97f0c916119356040516118c181614071565b6044358152602081019060643582526118d861487d565b6118e06148b2565b60046118ec86866149bd565b600381016118fd81548551906145c6565b9055019182549051928380920361194a575b505051604051948594859094939260609260808301968352602083015260408201520152565b0390a15f5f516020615cfd5f395f51905f525d005b55818761190f565b346103b25760203660031901126103b2576001600160a01b03611973613fa8565b165f525f516020615abd5f395f51905f52602052602060405f2054604051908152f35b346103b2575f3660031901126103b257602060ff5f516020615d1d5f395f51905f525460a01c166040519015158152f35b346103b2576119d53661417a565b6119e093919361487d565b6119e86148b2565b6001600160a01b03841615611aeb578381611a60611a2a611935947f5f8ecf683e1923224ca1e9b396be6a7a13e480a011e7645d641e7a7d3a2d0f0398614eb5565b5f516020615c9d5f395f51905f525460ff8116158015611aaa575b611a95575b505f516020615cdd5f395f51905f5254906145e0565b9160405195869586916080936001600160a01b0391979695929760a08501988552602085015216604083015260608201520152565b60ff611aa49160101c16614b06565b88611a4a565b505f516020615c7d5f395f51905f5254612710611ae45f516020615a7d5f395f51905f52545f516020615c1d5f395f51905f5254906145e0565b0410611a45565b604051636bc37c5f60e11b8152602060048083019190915260248201526366726f6d60e01b6044820152606490fd5b346103b2575f3660031901126103b25760207f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0d54604051908152f35b346103b2575f3660031901126103b25760205f516020615d5d5f395f51905f5254604051908152f35b346103b2576040611b8f366140f8565b611b9761487d565b611b9f6148b2565b6003611bab83856149bd565b01918254938483115f14611c2a578394505f611beb7f9d8bfb8a1a799d9f6f5e207b8c00c13b549b7f20c8421d1f94bc9bfe23a9019894955480966145d3565b9495555b855190815260208101919091526040810184905260608101839052608090a15f5f516020615cfd5f395f51905f525d82519182526020820152f35b92611c58837f9d8bfb8a1a799d9f6f5e207b8c00c13b549b7f20c8421d1f94bc9bfe23a901989493966145d3565b9055925f92611bef565b346103b2575f3660031901126103b25760205f516020615d3d5f395f51905f5254604051908152f35b346103b2575f3660031901126103b2576001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163003611ce25760206040515f516020615bdd5f395f51905f528152f35b63703e46dd60e11b5f5260045ffd5b346103b25760203660031901126103b257602061137d611d215f516020615cdd5f395f51905f52546004356145f3565b61519a565b60403660031901126103b257611d3a613fa8565b60243567ffffffffffffffff81116103b257366023820112156103b257611d6b903690602481600401359101614144565b6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016803014908115611eef575b50611ce257611dad614921565b6040516352d1902d60e01b81526001600160a01b0383169290602081600481875afa5f9181611ebb575b50611def5783634c9c8ce360e01b5f5260045260245ffd5b805f516020615bdd5f395f51905f52859203611ea95750813b15611e9757806001600160a01b03195f516020615bdd5f395f51905f525416175f516020615bdd5f395f51905f52557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b5f80a2815115611e7f575f8083602061076395519101845af4611e796153a8565b91615a02565b505034611e8857005b63b398979f60e01b5f5260045ffd5b634c9c8ce360e01b5f5260045260245ffd5b632a87526960e21b5f5260045260245ffd5b9091506020813d602011611ee7575b81611ed76020938361408d565b810103126103b257519085611dd7565b3d9150611eca565b90506001600160a01b035f516020615bdd5f395f51905f525416141583611da0565b346103b257611f1f36614112565b90611f28614921565b6007611f3483836149bd565b019182549160ff8316611f4d5760ff1983166001178455005b634e06b75f60e11b5f5260045260245260445ffd5b346103b25760403660031901126103b257611f7b613fa8565b602435611f8661487d565b611f8e6148b2565b611fb98161099c5f516020615a7d5f395f51905f52545f516020615cdd5f395f51905f5254906145e0565b7f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0d548082116121e35750505f516020615b9d5f395f51905f5254156121af575f516020615cdd5f395f51905f5254612010916145f3565b612028815f516020615c7d5f395f51905f52546145c6565b5f516020615c7d5f395f51905f525580915f516020615b5d5f395f51905f525480612183575b50612067825f516020615a7d5f395f51905f52546145c6565b5f516020615a7d5f395f51905f52556001600160a01b038116156121705782816120b46020957f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f9461574c565b6120de84604051938493846040919493926001600160a01b03606083019616825260208201520152565b0390a15f516020615c9d5f395f51905f525460ff811615801561212f575b61211a575b505f5f516020615cfd5f395f51905f525d604051908152f35b60ff6121299160101c16614b06565b82612101565b505f516020615c7d5f395f51905f52546127106121695f516020615a7d5f395f51905f52545f516020615c1d5f395f51905f5254906145e0565b04106120fc565b63ec442f0560e01b5f525f60045260245ffd5b6121a891935061219390836145e0565b5f516020615a7d5f395f51905f5254906145f3565b918361204e565b604051634612b38f60e01b815260206004820152600b60248201526a1d1bdd185b15d95a59da1d60aa1b6044820152606490fd5b60a49250604051916338d06e1d60e01b835260606004840152601060648401526f6d6178546f74616c4465706f7369747360801b608484015260248301526044820152fd5b346103b25760603660031901126103b257612241613fa8565b60243561224c613fd4565b61225461487d565b61225c6148b2565b816001600160a01b0384168015611aeb576001600160a01b037f285a08d85aaeb56c8b9d22b6877dffaed0cb5d07c1c14494aff61d9524746a12936080936020975f516020615c7d5f395f51905f5254976122b68961519a565b809111612343575b506122cc826122d392614eb5565b80986145d3565b5f516020615c7d5f395f51905f52556123146122fd5f516020615cdd5f395f51905f5254896145e0565b83855f516020615d1d5f395f51905f525416615202565b60405193845287840152856040840152166060820152a15f5f516020615cfd5f395f51905f525d604051908152f35b91506122cc6122be565b346103b25761235b36614112565b905f527f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0260205260405f20905f52602052602060405f2054604051908152f35b346103b2575f3660031901126103b25760207f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0b54604051908152f35b346103b2576123e5366140f8565b916123ee614921565b5f516020615c3d5f395f51905f525480606411156125ed575f5b81811061259c5750612428845f516020615b9d5f395f51905f52546145c6565b5f516020615b9d5f395f51905f5255815f527f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0260205260405f20835f5260205260405f20556040519261247a84614054565b8184526020840190838252604085019481865260608101905f825260808101915f835260a082015f815260c08301905f825260e08401945f86525f516020615c3d5f395f51905f525468010000000000000000811015612588578060016124f092015f516020615c3d5f395f51905f52556143ed565b949094612575577f5b1ee307451dd65aa45d1657a66752bab8925be9aad7c827865655c8c2fdac249b6109ce99600797518755516001870155516002860155516003850155516004840155516005830155516006820155019051151560ff80198354169116179055604051938493846040919493926060820195825260208201520152565b634e487b7160e01b5f525f60045260245ffd5b634e487b7160e01b5f52604160045260245ffd5b6125ae6125a8826143ed565b50614435565b848482511491826125df575b50506125c857600101612408565b505063b020eb6360e01b5f5260045260245260445ffd5b6020015114905084876125ba565b600181018091116126365760a490604051906338d06e1d60e01b82526060600483015260086064830152671419595c941bdbdb60c21b6084830152602482015260646044820152fd5b634e487b7160e01b5f52601160045260245ffd5b346103b2576101203660031901126103b257612664613fd4565b5060a0612670366140af565b61267861487d565b6126806148b2565b61268981615117565b0151610bb9600561125f6024356004356149bd565b346103b25760403660031901126103b2576126b7613fbe565b336001600160a01b038216036126d3576107639060043561507a565b63334bd91960e11b5f5260045ffd5b346103b2575f3660031901126103b257602061137d6157f6565b346103b2575f3660031901126103b25760205f516020615c1d5f395f51905f5254604051908152f35b346103b2575f3660031901126103b257602060ff5f516020615afd5f395f51905f525416604051908152f35b346103b25760403660031901126103b257610763600435612770613fbe565b90612796610759825f525f516020615c5d5f395f51905f52602052600160405f20015490565b6147d6565b346103b25760a03660031901126103b2576024356004356127ba613fd4565b916064359160843567ffffffffffffffff81116103b257366023820112156103b25780600401359067ffffffffffffffff82116103b25736602483830101116103b25761280561487d565b61280d6148b2565b6001600160a01b038616958615611aeb57600160ff600761282e88886149bd565b015416151503612c86578561284291614eb5565b9460ff5f516020615c9d5f395f51905f525416158015612c45575b6128ea575b918060247fc184e55db14c3f814948da0d3295ebf968287d110e7ebb55ea0f30a773fc1d3c96959360e09560209a60405198899788528c8801526040870152606086015288608086015260c060a08601528260c086015201848401375f828201840152601f01601f19168101030190a15f5f516020615cfd5f395f51905f525d604051908152f35b5f516020615c7d5f395f51905f5254965f88151580612c2e575b612911575b509650612862565b5f516020615c3d5f395f51905f52549061292a82614629565b5f5f5f516020615a7d5f395f51905f52545f516020615b9d5f395f51905f5254915b868110612bbd575050505f9b81155f14612a5a575050508080612a43575b6129d5575b50509260247fc184e55db14c3f814948da0d3295ebf968287d110e7ebb55ea0f30a773fc1d3c969593829360e0966129b860209c5b5f516020615c7d5f395f51905f52546145d3565b5f516020615c7d5f395f51905f5255935093955093959650612909565b8181101561296f576129e6816143ed565b50995f516020615c7d5f395f51905f525460028c0154612a05916145e0565b5f516020615b9d5f395f51905f5254612a1d916145f3565b9081612a28916145c6565b9a60060190815490612a39916145c6565b90556001016129d5565b505f516020615c7d5f395f51905f5254151561296a565b9080929391105f14612b2d575b838110612aa957505050509260247fc184e55db14c3f814948da0d3295ebf968287d110e7ebb55ea0f30a773fc1d3c969593829360e0966129b860209c6129a4565b80612ab660019285614af2565b51612ac2575b01612a67565b6006612b15612ad0836143ed565b509e612af986611378612ae3878b614af2565b515f516020615c7d5f395f51905f5254906145e0565b612b038589614af2565b52612b0e8488614af2565b51906145c6565b9d01612b268154612b0e8488614af2565b9055612abc565b50505f5b828110612b72575050509260247fc184e55db14c3f814948da0d3295ebf968287d110e7ebb55ea0f30a773fc1d3c969593829360e0966129b860209c6129a4565b80612b7f60019284614af2565b51612b8b575b01612b31565b6006612ba5612b99836143ed565b509d612b0e8487614af2565b9c01612bb68154612b0e8487614af2565b9055612b85565b612bc6816143ed565b50612bed612bdc856113786002850154876145e0565b9160066005820154910154906145c6565b90818111612c00575b505060010161294c565b94612c11612c2692600194976145d3565b612c1b8789614af2565b52612b0e8688614af2565b93905f612bf6565b505f516020615b9d5f395f51905f52541515612904565b505f516020615c7d5f395f51905f5254612710612c7f5f516020615a7d5f395f51905f52545f516020615c1d5f395f51905f5254906145e0565b041061285d565b505050631c6768ad60e21b5f5260045260245260445ffd5b346103b2575f3660031901126103b257602060ff5f516020615c9d5f395f51905f525460101c166040519015158152f35b346103b2575f3660031901126103b257602060ff5f516020615c9d5f395f51905f5254166040519015158152f35b346103b25760203660031901126103b257602061137d6004355f525f516020615c5d5f395f51905f52602052600160405f20015490565b346103b25760603660031901126103b257612d4d613fa8565b612d55613fbe565b60443590612d93836001600160a01b03165f527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0160205260405f2090565b6001600160a01b0333165f5260205260405f2054925f198410612dbb575b610eab9350614de4565b828410612e58576001600160a01b03811615612e45573315612e3257610eab93612e15826001600160a01b03165f527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0160205260405f2090565b6001600160a01b0333165f526020528360405f2091039055612db1565b634a1406b160e11b5f525f60045260245ffd5b63e602df0560e01b5f525f60045260245ffd5b8284637dc7a0d960e11b5f523360045260245260445260645ffd5b346103b2575f3660031901126103b25760205f516020615c7d5f395f51905f5254604051908152f35b346103b2575f3660031901126103b25760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b346103b2575f3660031901126103b25760205f516020615b5d5f395f51905f5254604051908152f35b346103b2575f3660031901126103b25760205f516020615a7d5f395f51905f5254604051908152f35b346103b2575f3660031901126103b257602060405160648152f35b346103b257612f5136613ff9565b93929091612f5d614494565b50612f6661487d565b612f6e6148b2565b60ff5f516020615d1d5f395f51905f525460a01c166133f1576001600160a01b038216918215611aeb57612fa285886149bd565b93600160ff6007870154161515036133da575f516020615cdd5f395f51905f525496612fd9612fd189866145f3565b9889936145f3565b9360c07f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0b549460ff5f516020615afd5f395f51905f5254169561301a614a5f565b5f516020615a7d5f395f51905f5254905f516020615cbd5f395f51905f5254986040519361304785614038565b30855260208501526040840152606083015260808201528660a0820152896001600160a01b035f516020615bbd5f395f51905f5254169161309e6040519e8f958694859463143273dd60e21b865260048601614514565b03915afa988915610d8d575f996133b9575b5088511561334f575060808801926130c98451846145c6565b94806130db60608c01978851906145d3565b1061331d57508351806132fe575b505060408801956131066130fe8851856145d3565b8551906145c6565b600360a08b019282845201918254918083106132e857509261010098959261315961046f9d9996937f9c7519dcf6aef530f7209189ddd559038a69f8bb53f818b7fa76c67379aa6b2c9c999651906145d3565b9055156132ac5761317b613183915f516020615c7d5f395f51905f52546145c6565b8251906145c6565b5f516020615c7d5f395f51905f52555b5f516020615c9d5f395f51905f525460ff8116158015613257575b613242575b508851905191519260208a0151945195604051978852602088015260408701526060860152608085015260a084015260c083015260e0820152a15f5f516020615cfd5f395f51905f525d6040519182918291909160a08060c083019480518452602081015160208501526040810151604085015260608101516060850152608081015160808501520151910152565b60ff6132519160081c16614b06565b8a6131b3565b505f516020615c7d5f395f51905f52546127106132a45f516020615a7d5f395f51905f52547f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0954906145e0565b0411156131ae565b508051806132bb575b50613193565b6132d3905f516020615c7d5f395f51905f52546145c6565b5f516020615c7d5f395f51905f52558a6132b5565b8263c8a198d960e01b5f5260045260245260445ffd5b613307916145d3565b5f516020615cbd5f395f51905f525589806130e9565b8451865160405163463fc77f60e11b815260048101879052602481019290925260448201526064810191909152608490fd5b61337189604061336860608301516020840151906145c6565b910151906145c6565b90600182018092116126365760a49160405191631606f63960e21b8352606060048401526008606484015267185b5bdd5b9d131160c21b608484015260248301526044820152fd5b6133d391995060c03d60c011610d8657610d78818361408d565b978a6130b0565b8588631c6768ad60e21b5f5260045260245260445ffd5b6331ad2c0f60e11b5f5260045ffd5b346103b25760203660031901126103b2576134196143b1565b5061046f6104136125a86004356143ed565b346103b25760403660031901126103b257610eab613447613fa8565b60243590336156b8565b346103b2575f3660031901126103b2576040515f5f516020615a9d5f395f51905f525461347d816141fd565b80845290600181169081156110c557506001146134a45761046f836110478185038261408d565b5f516020615a9d5f395f51905f525f9081527f2ae08a8e29253f69ac5d979a101956ab8f8d9d7ded63fa7a83b16fc47648eab0939250905b8082106134f457509091508101602001611047611037565b9192600181602092548385880101520191019092916134dc565b346103b25760203660031901126103b25760043563ffffffff60e01b81168091036103b257602090637965db0b60e01b8114908115613553575b506040519015158152f35b6301ffc9a760e01b14905082613548565b346103b25760203660031901126103b25760043567ffffffffffffffff81116103b257806004019061014060031982360301126103b2575f516020615d7d5f395f51905f52549160ff8360401c16159267ffffffffffffffff811680159081613f7c575b6001149081613f72575b159081613f69575b50613f5a5767ffffffffffffffff1981166001175f516020615d7d5f395f51905f525583613f2e575b5061363661361182806141a8565b61362e61362460248795949501866141a8565b9490923691614144565b923691614144565b9061363f61568d565b61364761568d565b80519067ffffffffffffffff82116125885781906136725f516020615a9d5f395f51905f52546141fd565b601f8111613eb4575b50602090601f8311600114613e36575f92613e2b575b50508160011b915f199060031b1c1916175f516020615a9d5f395f51905f52555b80519067ffffffffffffffff8211612588576136db5f516020615b1d5f395f51905f52546141fd565b601f8111613dbc575b50602090601f8311600114613d38579180613733949261372c945f92613d2d575b50508160011b915f199060031b1c1916175f516020615b1d5f395f51905f52555b806141a8565b3691614144565b9161373c61568d565b60409182519361374c848661408d565b60018552603160f81b602086015261376261568d565b80519067ffffffffffffffff821161258857819061378d5f516020615add5f395f51905f52546141fd565b601f8111613cb3575b50602090601f8311600114613c35575f92613c2a575b50508160011b915f199060031b1c1916175f516020615add5f395f51905f52555b835167ffffffffffffffff8111612588576137f55f516020615b7d5f395f51905f52546141fd565b601f8111613bbb575b50602094601f8211600114613b40579481929394955f92613b35575b50508160011b915f199060031b1c1916175f516020615b7d5f395f51905f52555b5f7fa16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d100555f7fa16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d1015561388961568d565b61389161568d565b6138fb6138a0608483016141db565b60ff806138af60a486016141db565b926138b861568d565b6138c061568d565b16918261ff005f516020615afd5f395f51905f52549260081b169161ffff19161717805f516020615afd5f395f51905f525560081c166145d3565b604d811161263657600a0a5f516020615cdd5f395f51905f525561391d61568d565b61392561568d565b61394f7f0000000000000000000000000000000000000000000000000000000000000000436145c6565b5f516020615d3d5f395f51905f525561397261396d60e483016141e9565b61465b565b5061398861398361010483016141e9565b61470a565b5060448101357f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0b55606481016001600160a01b036139c5826141e9565b1615613b085760c48201906001600160a01b036139e1836141e9565b1615613ad357613a2961012493926001600160a01b03613a0181946141e9565b1683195f516020615d1d5f395f51905f525416175f516020615d1d5f395f51905f52556141e9565b166001600160a01b03195f516020615bbd5f395f51905f525416175f516020615bbd5f395f51905f525501357f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0d55613a7d57005b60207fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29168ff0000000000000000195f516020615d7d5f395f51905f5254165f516020615d7d5f395f51905f52555160018152a1005b8451636bc37c5f60e11b815260206004820152600d60248201526c3332b2a1b0b631bab630ba37b960991b6044820152606490fd5b8351636bc37c5f60e11b81526020600482015260056024820152643a37b5b2b760d91b6044820152606490fd5b01519050858061381a565b601f198216955f516020615b7d5f395f51905f525f52805f20915f5b888110613ba357508360019596979810613b8b575b505050811b015f516020615b7d5f395f51905f525561383b565b01515f1960f88460031b161c19169055858080613b71565b91926020600181928685015181550194019201613b5c565b5f516020615b7d5f395f51905f525f527f5f9ce34815f8e11431c7bb75a8e6886a91478f7ffc1dbb0a98dc240fddd76b75601f830160051c81019160208410613c20575b601f0160051c01905b818110613c1557506137fe565b5f8155600101613c08565b9091508190613bff565b0151905086806137ac565b5f516020615add5f395f51905f525f9081528281209350601f198516905b818110613c9b5750908460019594939210613c83575b505050811b015f516020615add5f395f51905f52556137cd565b01515f1960f88460031b161c19169055868080613c69565b92936020600181928786015181550195019301613c53565b5f516020615add5f395f51905f525f529091507f42ad5d3e1f2e6e70edcf6d991b8a3023d3fca8047a131592f9edb9fd9b89d57d601f840160051c81019160208510613d23575b90601f859493920160051c01905b818110613d155750613796565b5f8155849350600101613d08565b9091508190613cfa565b015190508780613705565b90601f198316915f516020615b1d5f395f51905f525f52815f20925f5b818110613da4575092600192859261372c96613733989610613d8c575b505050811b015f516020615b1d5f395f51905f5255613726565b01515f1960f88460031b161c19169055878080613d72565b92936020600181928786015181550195019301613d55565b5f516020615b1d5f395f51905f525f527f46a2803e59a4de4e7a4c574b1243f25977ac4c77d5a1a4a609b5394cebb4a2aa601f840160051c81019160208510613e21575b601f0160051c01905b818110613e1657506136e4565b5f8155600101613e09565b9091508190613e00565b015190508680613691565b5f516020615a9d5f395f51905f525f9081528281209350601f198516905b818110613e9c5750908460019594939210613e84575b505050811b015f516020615a9d5f395f51905f52556136b2565b01515f1960f88460031b161c19169055868080613e6a565b92936020600181928786015181550195019301613e54565b5f516020615a9d5f395f51905f525f529091507f2ae08a8e29253f69ac5d979a101956ab8f8d9d7ded63fa7a83b16fc47648eab0601f840160051c81019160208510613f24575b90601f859493920160051c01905b818110613f16575061367b565b5f8155849350600101613f09565b9091508190613efb565b68ffffffffffffffffff191668010000000000000001175f516020615d7d5f395f51905f525583613603565b63f92ee8a960e01b5f5260045ffd5b905015856135da565b303b1591506135d2565b8591506135c8565b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b600435906001600160a01b03821682036103b257565b602435906001600160a01b03821682036103b257565b604435906001600160a01b03821682036103b257565b6004359081151582036103b257565b60c09060031901126103b25760043590602435906044356001600160a01b03811681036103b25790606435906084359060a43580151581036103b25790565b60c0810190811067ffffffffffffffff82111761258857604052565b610100810190811067ffffffffffffffff82111761258857604052565b6040810190811067ffffffffffffffff82111761258857604052565b90601f8019910116810190811067ffffffffffffffff82111761258857604052565b60c09060631901126103b257604051906140c882614038565b6064358252608435602083015260a435604083015260c435606083015260e43560808301526101043560a0830152565b60609060031901126103b257600435906024359060443590565b60409060031901126103b2576004359060243590565b67ffffffffffffffff811161258857601f01601f191660200190565b92919261415082614128565b9161415e604051938461408d565b8294818452818301116103b2578281602093845f960137010152565b60809060031901126103b25760043590602435906044356001600160a01b03811681036103b2579060643590565b903590601e19813603018212156103b2570180359067ffffffffffffffff82116103b2576020019181360383136103b257565b3560ff811681036103b25790565b356001600160a01b03811681036103b25790565b90600182811c9216801561422b575b602083101461421757565b634e487b7160e01b5f52602260045260245ffd5b91607f169161420c565b604051905f825f516020615add5f395f51905f525491614254836141fd565b80835292600181169081156142e5575060011461427a575b6142789250038361408d565b565b505f516020615add5f395f51905f525f90815290917f42ad5d3e1f2e6e70edcf6d991b8a3023d3fca8047a131592f9edb9fd9b89d57d5b8183106142c95750509060206142789282010161426c565b60209193508060019154838589010152019101909184926142b1565b6020925061427894915060ff191682840152151560051b82010161426c565b604051905f825f516020615b7d5f395f51905f525491614323836141fd565b80835292600181169081156142e55750600114614346576142789250038361408d565b505f516020615b7d5f395f51905f525f90815290917f5f9ce34815f8e11431c7bb75a8e6886a91478f7ffc1dbb0a98dc240fddd76b755b8183106143955750509060206142789282010161426c565b602091935080600191548385890101520191019091849261437d565b604051906143be82614054565b5f60e0838281528260208201528260408201528260608201528260808201528260a08201528260c08201520152565b5f516020615c3d5f395f51905f5254811015614421575f516020615c3d5f395f51905f525f5260205f209060031b01905f90565b634e487b7160e01b5f52603260045260245ffd5b9060405161444281614054565b60e060ff600783958054855260018101546020860152600281015460408601526003810154606086015260048101546080860152600581015460a0860152600681015460c08601520154161515910152565b604051906144a182614038565b5f60a0838281528260208201528260408201528260608201528260808201520152565b908160c09103126103b25760a0604051916144de83614038565b8051835260208101516020840152604081015160408401526060810151606084015260808101516080840152015160a082015290565b909493926001600160a01b039060ff60076101e09560a061020087019a868151168852602081015160208901528460408201511660408901526060810151606089015260808101516080890152015160a0870152805460c0870152600181015460e08701526002810154610100870152600381015461012087015260048101546101408701526005810154610160870152600681015461018087015201541615156101a0840152166101c08201520152565b9190820180921161263657565b9190820391821161263657565b8181029291811591840414171561263657565b81156145fd570490565b634e487b7160e01b5f52601260045260245ffd5b67ffffffffffffffff81116125885760051b60200190565b9061463382614611565b614640604051918261408d565b8281528092614651601f1991614611565b0190602036910137565b6001600160a01b0381165f9081527fb7db2dd08fcb62d0c9e08c51941cae53c267786a0b75803fb7960902fc8ef97d602052604090205460ff16614705576001600160a01b03165f8181527fb7db2dd08fcb62d0c9e08c51941cae53c267786a0b75803fb7960902fc8ef97d60205260408120805460ff191660011790553391907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d8180a4600190565b505f90565b6001600160a01b0381165f9081527fb99f74ed0a18e51a0abeabf20177563f97170d9a304aaf2f87e619c498908538602052604090205460ff16614705576001600160a01b03165f8181527fb99f74ed0a18e51a0abeabf20177563f97170d9a304aaf2f87e619c49890853860205260408120805460ff191660011790553391907f66d05ae646b1ee24e48a8708b8c0f6eade385a89cd689a1ed9121cb3ec9e2102907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9080a4600190565b805f525f516020615c5d5f395f51905f5260205260405f206001600160a01b0383165f5260205260ff60405f205416155f1461487757805f525f516020615c5d5f395f51905f5260205260405f206001600160a01b0383165f5260205260405f20600160ff198254161790556001600160a01b03339216907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d5f80a4600190565b50505f90565b5f516020615cfd5f395f51905f525c6148a35760015f516020615cfd5f395f51905f525d565b633ee5aeb560e01b5f5260045ffd5b335f9081527fb99f74ed0a18e51a0abeabf20177563f97170d9a304aaf2f87e619c498908538602052604090205460ff16156148ea57565b63e2517d3f60e01b5f52336004527f66d05ae646b1ee24e48a8708b8c0f6eade385a89cd689a1ed9121cb3ec9e210260245260445ffd5b335f9081527fb7db2dd08fcb62d0c9e08c51941cae53c267786a0b75803fb7960902fc8ef97d602052604090205460ff161561495957565b63e2517d3f60e01b5f52336004525f60245260445ffd5b805f525f516020615c5d5f395f51905f5260205260405f206001600160a01b0333165f5260205260ff60405f205416156149a75750565b63e2517d3f60e01b5f523360045260245260445ffd5b91905f516020615c3d5f395f51905f525415614a5057825f527f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0260205260405f20815f52602052614a1160405f20546143ed565b509283828282541491821592614a41575b5050614a2c575050565b6310de8c5160e31b5f5260045260245260445ffd5b6001015414159050825f614a22565b634d6af2e760e11b5f5260045ffd5b602460206001600160a01b035f516020615d1d5f395f51905f525416604051928380926370a0823160e01b82523060048301525afa8015610d8d575f90614abe575b614abb91505f516020615cdd5f395f51905f5254906145f3565b90565b506020813d602011614aea575b81614ad86020938361408d565b810103126103b257614abb9051614aa1565b3d9150614acb565b80518210156144215760209160051b010190565b5f516020615c7d5f395f51905f52549081151580614dcd575b614b27575050565b5f516020615c3d5f395f51905f525490614b4082614629565b5f5f5f516020615a7d5f395f51905f52545f516020615b9d5f395f51905f5254915b868110614d82575050505f9481155f14614c235750505080614c0c575b614bae575b50614b9d905f516020615c7d5f395f51905f52546145d3565b5f516020615c7d5f395f51905f5255565b5f5b818110614bbd5750614b84565b80614bc96001926143ed565b5093614c046006614bfa614bf36115b15f516020615c7d5f395f51905f525460028b0154906145e0565b80946145c6565b96019182546145c6565b905501614bb0565b505f516020615c7d5f395f51905f52541515614b7f565b9080929391105f14614c9857505f5b838110614c465750505050614b9d906129a4565b80614c5360019285614af2565b51614c5f575b01614c32565b6006614c80614c6d836143ed565b5097612af986611378612ae3878b614af2565b9601614c918154612b0e8488614af2565b9055614c59565b9294939215614d1d57614cb9905f516020615c7d5f395f51905f52546145d3565b5f5b858110614cd057505050614b9d9192506129a4565b80614cdc6001926143ed565b5094614d156006614d0b614bf3614cf3868a614af2565b51614d056115b160028d01548b6145e0565b906145c6565b97019182546145c6565b905501614cbb565b505f939192935b828110614d3757505050614b9d906129a4565b80614d4460019284614af2565b51614d50575b01614d24565b6006614d6a614d5e836143ed565b5096612b0e8487614af2565b9501614d7b8154612b0e8487614af2565b9055614d4a565b614d8b816143ed565b50614da1612bdc856113786002850154876145e0565b90818111614db4575b5050600101614b62565b94612c11614dc592600194976145d3565b93905f614daa565b505f516020615b9d5f395f51905f52541515614b1f565b6001600160a01b0316908115614ea2576001600160a01b031691821561217057815f525f516020615abd5f395f51905f5260205260405f2054818110614e8957817fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92602092855f525f516020615abd5f395f51905f5284520360405f2055845f525f516020615abd5f395f51905f52825260405f20818154019055604051908152a3565b8263391434e360e21b5f5260045260245260445260645ffd5b634b637e8f60e11b5f525f60045260245ffd5b905f516020615b5d5f395f51905f5254918215611385576001600160a01b038116805f525f516020615abd5f395f51905f5260205260405f20548381106150285750614f1e614f175f516020615a7d5f395f51905f52549561137887876145e0565b80956145d3565b5f516020615a7d5f395f51905f52558015614ea257805f525f516020615abd5f395f51905f5260205260405f205483811061500e5781845f927f49995e5dd6158cf69ad3e9777c46755a1a826a446c6416992167462dad033b2a96959484525f516020615abd5f395f51905f52602052036040832055835f516020615b5d5f395f51905f5254035f516020615b5d5f395f51905f52557fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef6020604051868152a361500884604051938493846040919493926001600160a01b03606083019616825260208201520152565b0390a190565b915063391434e360e21b5f5260045260245260445260645ffd5b8360a491604051916338d06e1d60e01b835260606004840152601560648401527f506f6f6c2e5f6275726e4c502e616d6f756e744c500000000000000000000000608484015260248301526044820152fd5b805f525f516020615c5d5f395f51905f5260205260405f206001600160a01b0383165f5260205260ff60405f2054165f1461487757805f525f516020615c5d5f395f51905f5260205260405f206001600160a01b0383165f5260205260405f2060ff1981541690556001600160a01b03339216907ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b5f80a4600190565b60206151899161513960408201515f516020615a7d5f395f51905f52546145c6565b5f516020615a7d5f395f51905f525561516460608201515f516020615cbd5f395f51905f52546145c6565b5f516020615cbd5f395f51905f525501515f516020615d5d5f395f51905f52546145c6565b5f516020615d5d5f395f51905f5255565b5f516020615a7d5f395f51905f525480156151cb57611378614abb925f516020615b5d5f395f51905f5254906145e0565b604051634612b38f60e01b815260206004820152600e60248201526d746f74616c4c697175696469747960901b6044820152606490fd5b61520d8383836153d7565b1561521757505050565b906001600160a01b0380926387abb3dd60e01b5f52166004521660245260445260645ffd5b5f516020615d3d5f395f51905f5254431161539b575b61526a815f516020615b3d5f395f51905f52546145c6565b7f00000000000000000000000000000000000000000000000000000000000000001061530b57807f0000000000000000000000000000000000000000000000000000000000000000105f146152f557806152e1915f516020615a5d5f395f51905f52555f516020615b3d5f395f51905f52546145c6565b5f516020615b3d5f395f51905f5255600190565b505f5f516020615a5d5f395f51905f5255600190565b505f5f516020615a5d5f395f51905f52555f516020615bfd5f395f51905f525460ff81161561533957505f90565b60019060ff1916175f516020615bfd5f395f51905f52556153887f00000000000000000000000000000000000000000000000000000000000000005f516020615d3d5f395f51905f52546145c6565b5f516020615d3d5f395f51905f52555f90565b6153a36154c4565b615252565b3d156153d2573d906153b982614128565b916153c7604051938461408d565b82523d5f602084013e565b606090565b60405163a9059cbb60e01b602082019081526001600160a01b039390931660248201526044808201949094529283525f92839290839061541860648261408d565b51925af16154246153a8565b8180615452575b615433575090565b90506020818051810103126103b2576020015180151581036103b25790565b508051151561542b565b5f516020615b3d5f395f51905f52545f516020615a5d5f395f51905f5254808210156154a75750505f5f516020615b3d5f395f51905f52555b5f5f516020615a5d5f395f51905f5255565b6154b0916145d3565b5f516020615b3d5f395f51905f5255615495565b6154ee7f0000000000000000000000000000000000000000000000000000000000000000436145c6565b5f516020615d3d5f395f51905f52555f5f516020615b3d5f395f51905f525560ff195f516020615bfd5f395f51905f5254165f516020615bfd5f395f51905f5255565b91905f516020615b9d5f395f51905f5254156121af575f516020615cdd5f395f51905f525461555f916145f3565b91825f516020615b5d5f395f51905f525480615678575b5061558f845f516020615a7d5f395f51905f52546145c6565b5f516020615a7d5f395f51905f52556001600160a01b0382161561217057816155d9827f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f9461574c565b61560385604051938493846040919493926001600160a01b03606083019616825260208201520152565b0390a15f516020615c9d5f395f51905f525460ff8116158015615637575b6156285750565b60ff6142789160101c16614b06565b505f516020615c7d5f395f51905f52546127106156715f516020615a7d5f395f51905f52545f516020615c1d5f395f51905f5254906145e0565b0410615621565b615687915061219390856145e0565b5f615576565b60ff5f516020615d7d5f395f51905f525460401c16156156a957565b631afcd79f60e31b5f5260045ffd5b916001600160a01b038316918215612e45576001600160a01b0316928315612e32577f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925916157386020926001600160a01b03165f527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0160205260405f2090565b855f5282528060405f2055604051908152a3565b7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60206001600160a01b035f93615791865f516020615b5d5f395f51905f52546145c6565b5f516020615b5d5f395f51905f52551693841584146157d457805f516020615b5d5f395f51905f5254035f516020615b5d5f395f51905f52555b604051908152a3565b8484525f516020615abd5f395f51905f528252604084208181540190556157cb565b6157fe615953565b6158066159bd565b6040519060208201927f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f8452604083015260608201524660808201523060a082015260a0815261585760c08261408d565b51902090565b91907f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a084116158d4579160209360809260ff5f9560405194855216868401526040830152606082015282805260015afa15610d8d575f516001600160a01b038116156158ca57905f905f90565b505f906001905f90565b5050505f9160039190565b600481101561593f57806158f1575050565b600181036159085763f645eedf60e01b5f5260045ffd5b60028103615923575063fce698f760e01b5f5260045260245ffd5b60031461592d5750565b6335e2f38360e21b5f5260045260245ffd5b634e487b7160e01b5f52602160045260245ffd5b61595b614235565b805190811561596b576020012090565b50507fa16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d1005480156159985790565b507fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a47090565b6159c5614304565b80519081156159d5576020012090565b50507fa16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d1015480156159985790565b90615a265750805115615a1757602081519101fd5b63d6bda27560e01b5f5260045ffd5b81511580615a53575b615a37575090565b6001600160a01b0390639996b31560e01b5f521660045260245ffd5b50803b15615a2f56fe0ee2d9de8392a8f17ff2bb7a24b72fd27e2cf4ac5cd7fd56e5bf7bdb439eb00398b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0352c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0352c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace00a16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d102363bd9d3ac01b05edede66fbb9c4f73d99f1481666c51eee8df34d23a61f480052c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace040ee2d9de8392a8f17ff2bb7a24b72fd27e2cf4ac5cd7fd56e5bf7bdb439eb00152c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace02a16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d10398b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0498b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea00360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc0ee2d9de8392a8f17ff2bb7a24b72fd27e2cf4ac5cd7fd56e5bf7bdb439eb00298b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0a98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0102dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b62680098b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0598b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0698b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea08363bd9d3ac01b05edede66fbb9c4f73d99f1481666c51eee8df34d23a61f48019b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f0098b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0c0ee2d9de8392a8f17ff2bb7a24b72fd27e2cf4ac5cd7fd56e5bf7bdb439eb00098b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea07f0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00a26469706673582212209951471a36050e92bdd094236f1837ccda0b9fbebb6a4cd3e36a4fe115df3f7b64736f6c634300081c0033f0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a000000000000000000000000000000000000000000000000000000000000015180000000000000000000000000000000000000000000000000000000000003f480000000000000000000000000000000000000000000000002b5e3af16b18800000000000000000000000000000000000000000000000000022b1c8c1227a00000
Deployed Bytecode
0x60806040526004361015610011575f80fd5b5f3560e01c80630130c4d21461356457806301ffc9a71461350e57806306fdde0314613451578063095ea7b31461342b5780630f45684a14612725578063106e846b1461340057806310a470ab14612f43578063113ac8f614612f2857806315770f9214612eff57806318160ddd14612ed65780631820cabb14612e9c5780631e8e51da14612e7357806323b872dd14612d34578063248a9ca314612cfd57806327f9237614612ccf57806328f079c214612c9e5780632b3afdb01461279b5780632f2ff15d14612751578063313ce5671461272557806336448777146126fc5780633644e515146126e257806336568abe1461269e57806338898ca21461264a5780633dc69f2c146123d75780633e0dc34e1461239b5780633f668d6f1461234d5780633fc03c261461222857806340c10f1914611f6257806343469f3214611f115780634f1ef28614611d2657806351fe0e1814611cf157806352d1902d14611c8b5780635879445614611c62578063601c186114611b7f57806360b71d4e14611b5657806361b01b5d14611b1a578063641ffaa1146119c75780636780a3111461199657806370a082311461195257806372e30f6a1461186d578063754f56e21461183f578063785ffb37146118055780637ecebe00146117ae5780637fb652651461178557806384b0196e1461163357806388cb0df7146115175780638c66d04f146114c05780638cdc1f24146113b95780638d55de631461132f57806390c83e94146112c557806391d148541461126f57806392c883fb146110e957806395d89b4114610ff357806396c82e5714610fca57806399a22d6814610f995780639bb8111914610f705780639c3701a014610f505780639d3c38c514610ed0578063a217fddf14610eb6578063a9059cbb14610e85578063ad3cb1cc14610e3e578063af8214ef14610e04578063b00eb9fe14610dd2578063b4d1d79514610d98578063b6192d0b14610c09578063b81d85f014610b60578063c0dca06e146109d3578063c646b16614610931578063ca981909146108f7578063cdfed0ab146108bb578063d505accf14610765578063d547741f14610714578063dd62ed3e1461069b578063e065608b146104e7578063e1a45218146104cb578063e465eb9e146104a2578063e46e705814610473578063e5b15b52146103e8578063fc0c546a146103b65763feb56b1514610389575f80fd5b346103b2575f3660031901126103b25760205f516020615cdd5f395f51905f5254604051908152f35b5f80fd5b346103b2575f3660031901126103b25760206001600160a01b035f516020615d1d5f395f51905f525416604051908152f35b346103b25761046f61041361040e6103ff36614112565b906104086143b1565b506149bd565b614435565b6040519182918291909160e080610100830194805184526020810151602085015260408101516040850152606081015160608501526080810151608085015260a081015160a085015260c081015160c085015201511515910152565b0390f35b346103b2575f3660031901126103b257602060ff5f516020615afd5f395f51905f525460081c16604051908152f35b346103b2575f3660031901126103b25760205f516020615b3d5f395f51905f5254604051908152f35b346103b2575f3660031901126103b25760206040516127108152f35b346103b25760a03660031901126103b257610500613fea565b602435604435916064358015158091036103b257608435918215158093036103b25761052a614921565b612710841161065857612710851161061757907fdef0a5f359f70f4feaf27bbd47c7e476348ea79108e46990d5b73efbc885f0379460a094939215159360ff195f516020615c9d5f395f51905f52541660ff8616175f516020615c9d5f395f51905f5255807f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0955815f516020615c1d5f395f51905f52555f516020615c9d5f395f51905f525462ff00008560101b169061ff008560081b169062ffff00191617175f516020615c9d5f395f51905f52556040519485526020850152604084015260608301526080820152a1005b6040516338d06e1d60e01b815260606004820152600960648201526806c7044656c746142560bc1b608482015260248101869052612710604482015260a490fd5b6040516338d06e1d60e01b815260606004820152600b60648201526a07377617044656c746142560ac1b608482015260248101859052612710604482015260a490fd5b346103b25760403660031901126103b2576106b4613fa8565b6001600160a01b036106fe6106c7613fbe565b926001600160a01b03165f527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0160205260405f2090565b91165f52602052602060405f2054604051908152f35b346103b25760403660031901126103b257610763600435610733613fbe565b9061075e610759825f525f516020615c5d5f395f51905f52602052600160405f20015490565b614970565b61507a565b005b346103b25760e03660031901126103b25761077e613fa8565b610786613fbe565b604435906064359260843560ff811681036103b2578442116108a85761087e6108756001600160a01b039283851697885f527f5ab42ced628888259c08ac98db1eb0cf702fc1501344311d8b100cd1bfe4bb0060205260405f20908154916001830190556040519060208201927f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c984528b6040840152878a1660608401528a608084015260a083015260c082015260c0815261084360e08261408d565b51902061084e6157f6565b906040519161190160f01b83526002830152602282015260c43591604260a435922061585d565b909291926158df565b16848103610891575061076393506156b8565b84906325c0072360e11b5f5260045260245260445ffd5b8463313c898160e11b5f5260045260245ffd5b346103b2575f3660031901126103b25760207f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0954604051908152f35b346103b2575f3660031901126103b25760206040517f66d05ae646b1ee24e48a8708b8c0f6eade385a89cd689a1ed9121cb3ec9e21028152f35b346103b2577f5b1ee307451dd65aa45d1657a66752bab8925be9aad7c827865655c8c2fdac246109ce610963366140f8565b61096e939193614921565b8061097985856149bd565b6109a18261099c60025f516020615b9d5f395f51905f52549401938454906145d3565b6145c6565b5f516020615b9d5f395f51905f525555604051938493846040919493926060820195825260208201520152565b0390a1005b346103b25760206109e336613ff9565b6109f29592919594939461487d565b6109fa6148b2565b5f90610afa575b610a195f516020615cdd5f395f51905f5254836145e0565b600190468503610ae9575b81610ac0575b5015610aad57507fcf0b8bea497be617351b2c1a4243bd9e92167fdf778a43ebb66fb37160594a0f9394610a8f9160019660405195869586916080936001600160a01b0391979695929760a08501988552602085015216604083015260608201520152565b0390a15b5f5f516020615cfd5f395f51905f525d6040519015158152f35b945050505050610abb61545c565b610a93565b610ae39150866001600160a01b035f516020615d1d5f395f51905f5254166153d7565b88610a2a565b9050610af48161523c565b90610a24565b85151580610b4e575b610b27575b6005610b1485856149bd565b01610b208382546145d3565b9055610a01565b610b48610b425f516020615cdd5f395f51905f5254886145e0565b86615531565b50610b08565b506001600160a01b0385161515610b03565b346103b25760a03660031901126103b257610b79613fd4565b60843590610b8561487d565b610b8d6148b2565b81151580610bf7575b610bcd575b6005610bab6024356004356149bd565b01610bb960643582546145d3565b90555f5f516020615cfd5f395f51905f525d005b610be9610bef925f516020615cdd5f395f51905f5254906145e0565b90615531565b508080610b9b565b506001600160a01b0381161515610b96565b346103b257610c4360c0610c2d610c1f3661417a565b959261040894929194614494565b935f516020615cdd5f395f51905f5254906145f3565b927f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0b549060ff5f516020615afd5f395f51905f525416610c81614a5f565b5f516020615a7d5f395f51905f5254905f516020615cbd5f395f51905f52549260405195610cae87614038565b308752602087015260408601526060850152608084015260a08301526001600160a01b035f516020615bbd5f395f51905f52541691610d036040519687958694859463143273dd60e21b865260048601614514565b03915afa8015610d8d5761046f915f91610d5e575b506040519182918291909160a08060c083019480518452602081015160208501526040810151604085015260608101516060850152608081015160808501520151910152565b610d80915060c03d60c011610d86575b610d78818361408d565b8101906144c4565b82610d18565b503d610d6e565b6040513d5f823e3d90fd5b346103b2575f3660031901126103b25760206040517f00000000000000000000000000000000000000000000000000000000000151808152f35b346103b2575f3660031901126103b25760206001600160a01b035f516020615bbd5f395f51905f525416604051908152f35b346103b2575f3660031901126103b25760206040517f000000000000000000000000000000000000000000000002b5e3af16b18800008152f35b346103b2575f3660031901126103b25761046f604051610e5f60408261408d565b60058152640352e302e360dc1b6020820152604051918291602083526020830190613f84565b346103b25760403660031901126103b257610eab610ea1613fa8565b6024359033614de4565b602060405160018152f35b346103b2575f3660031901126103b25760206040515f8152f35b346103b25760203660031901126103b2577fc0aea4cb7421bc8d3cf83582abe451bd1705682eb83b02b88889940492aef5ca6020610f0c613fea565b610f14614921565b5f516020615d1d5f395f51905f52805460ff60a01b191691151560a090811b60ff60a01b169290921790819055604051911c60ff1615158152a1005b346103b2575f3660031901126103b257610f68614921565b6107636154c4565b346103b2575f3660031901126103b25760205f516020615cbd5f395f51905f5254604051908152f35b346103b2575f3660031901126103b257602060ff5f516020615c9d5f395f51905f525460081c166040519015158152f35b346103b2575f3660031901126103b25760205f516020615b9d5f395f51905f5254604051908152f35b346103b2575f3660031901126103b2576040515f5f516020615b1d5f395f51905f525461101f816141fd565b80845290600181169081156110c5575060011461105b575b61046f836110478185038261408d565b604051918291602083526020830190613f84565b5f516020615b1d5f395f51905f525f9081527f46a2803e59a4de4e7a4c574b1243f25977ac4c77d5a1a4a609b5394cebb4a2aa939250905b8082106110ab57509091508101602001611047611037565b919260018160209254838588010152019101909291611093565b60ff191660208086019190915291151560051b840190910191506110479050611037565b346103b2576101403660031901126103b257600435611106613fd4565b90611110366140af565b91610124359081151582036103b25760409361112a61487d565b6111326148b2565b5f92611240575b80519261116461114f60808401958651906145c6565b5f516020615cdd5f395f51905f5254906145e0565b946001904603611231575b80611209575b156111f857507f82f23eb0ffa46ea98b1a7134447f74561cec3e194d0f1d06ffc35ce71ae80336916080916111b060019582519051906145c6565b9060606020820151910151916001600160a01b038951941684526020840152878301526060820152a15b5f5f516020615cfd5f395f51905f525d825191825215156020820152f35b9250505061120461545c565b6111da565b5061122c85846001600160a01b035f516020615d1d5f395f51905f5254166153d7565b611175565b5061123b8561523c565b61116f565b61124981615117565b60a0810151611268600561125f602435886149bd565b019182546145d3565b9055611139565b346103b25760403660031901126103b257611288613fbe565b6004355f525f516020615c5d5f395f51905f526020526001600160a01b0360405f2091165f52602052602060ff60405f2054166040519015158152f35b346103b25760203660031901126103b2576004356112e1614921565b7f0320c21101a3b92f1a57a1daef0827408be5f6cb7bb44fb426cc4152663e611d6020604051838152a17f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0d55005b346103b25760203660031901126103b2575f516020615b5d5f395f51905f525480156113855761137d61114f6020926113785f516020615a7d5f395f51905f52546004356145e0565b6145f3565b604051908152f35b604051634612b38f60e01b815260206004820152600b60248201526a746f74616c537570706c7960a81b6044820152606490fd5b346103b25760203660031901126103b2576113d2613fa8565b6113da614921565b6001600160a01b03811615611495575f516020615d5d5f395f51905f52549081156114865761141b610763925f516020615cdd5f395f51905f5254906145e0565b5f5f516020615d5d5f395f51905f5255604080516001600160a01b0384168152602081018390529192917f0a7a10dab02ee70c589a87e2b0d57484d85d029e381c3ca52387e25486a4c5389190a16001600160a01b035f516020615d1d5f395f51905f525416615202565b636e63c7c360e01b5f5260045ffd5b604051636bc37c5f60e11b8152602060048201526002602482015261746f60f01b6044820152606490fd5b346103b25760203660031901126103b2576001600160a01b036114e1613fa8565b6114e9614921565b166001600160a01b03195f516020615bbd5f395f51905f525416175f516020615bbd5f395f51905f52555f80f35b346103b25761152536614112565b906040519061153382614071565b5f825260208201905f825261154661487d565b61154e6148b2565b61155884826149bd565b90600160ff60078401541615150361161c57506040935f7f0aeafd14584f8a6bfe6b3846da893395e218188cb3ba5586a705848f7fbcb1ad926115c66115b15f516020615a7d5f395f51905f52546002840154906145e0565b5f516020615b9d5f395f51905f5254906145f3565b855260068101906115e16005835492838a52019182546145c6565b90555583518351865192835260208301919091526040820152606090a15f5f516020615cfd5f395f51905f525d825191518252516020820152f35b8490631c6768ad60e21b5f5260045260245260445ffd5b346103b2575f3660031901126103b2577fa16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d10054158061175c575b15611717576116bb61167c614235565b611684614304565b60206116c960405192611697838561408d565b5f84525f368137604051958695600f60f81b875260e08588015260e0870190613f84565b908582036040870152613f84565b4660608501523060808501525f60a085015283810360c08501528180845192838152019301915f5b82811061170057505050500390f35b8351855286955093810193928101926001016116f1565b60405162461bcd60e51b815260206004820152601560248201527f4549503731323a20556e696e697469616c697a656400000000000000000000006044820152606490fd5b507fa16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d101541561166c565b346103b25760203660031901126103b2576107636117a1613fea565b6117a96148b2565b614b06565b346103b25760203660031901126103b2576001600160a01b036117cf613fa8565b165f527f5ab42ced628888259c08ac98db1eb0cf702fc1501344311d8b100cd1bfe4bb00602052602060405f2054604051908152f35b346103b2575f3660031901126103b25760206040517f0000000000000000000000000000000000000000000000022b1c8c1227a000008152f35b346103b2575f3660031901126103b257602060ff5f516020615bfd5f395f51905f5254166040519015158152f35b346103b25760803660031901126103b25760043560243560403660431901126103b2577fdbbc76676cb73b8d1c33378e0cdc88f364e4203cfa5b1e4c7d15b66b5cb97f0c916119356040516118c181614071565b6044358152602081019060643582526118d861487d565b6118e06148b2565b60046118ec86866149bd565b600381016118fd81548551906145c6565b9055019182549051928380920361194a575b505051604051948594859094939260609260808301968352602083015260408201520152565b0390a15f5f516020615cfd5f395f51905f525d005b55818761190f565b346103b25760203660031901126103b2576001600160a01b03611973613fa8565b165f525f516020615abd5f395f51905f52602052602060405f2054604051908152f35b346103b2575f3660031901126103b257602060ff5f516020615d1d5f395f51905f525460a01c166040519015158152f35b346103b2576119d53661417a565b6119e093919361487d565b6119e86148b2565b6001600160a01b03841615611aeb578381611a60611a2a611935947f5f8ecf683e1923224ca1e9b396be6a7a13e480a011e7645d641e7a7d3a2d0f0398614eb5565b5f516020615c9d5f395f51905f525460ff8116158015611aaa575b611a95575b505f516020615cdd5f395f51905f5254906145e0565b9160405195869586916080936001600160a01b0391979695929760a08501988552602085015216604083015260608201520152565b60ff611aa49160101c16614b06565b88611a4a565b505f516020615c7d5f395f51905f5254612710611ae45f516020615a7d5f395f51905f52545f516020615c1d5f395f51905f5254906145e0565b0410611a45565b604051636bc37c5f60e11b8152602060048083019190915260248201526366726f6d60e01b6044820152606490fd5b346103b2575f3660031901126103b25760207f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0d54604051908152f35b346103b2575f3660031901126103b25760205f516020615d5d5f395f51905f5254604051908152f35b346103b2576040611b8f366140f8565b611b9761487d565b611b9f6148b2565b6003611bab83856149bd565b01918254938483115f14611c2a578394505f611beb7f9d8bfb8a1a799d9f6f5e207b8c00c13b549b7f20c8421d1f94bc9bfe23a9019894955480966145d3565b9495555b855190815260208101919091526040810184905260608101839052608090a15f5f516020615cfd5f395f51905f525d82519182526020820152f35b92611c58837f9d8bfb8a1a799d9f6f5e207b8c00c13b549b7f20c8421d1f94bc9bfe23a901989493966145d3565b9055925f92611bef565b346103b2575f3660031901126103b25760205f516020615d3d5f395f51905f5254604051908152f35b346103b2575f3660031901126103b2576001600160a01b037f0000000000000000000000005b1142a82d155854532603dbc7158a44f3932e79163003611ce25760206040515f516020615bdd5f395f51905f528152f35b63703e46dd60e11b5f5260045ffd5b346103b25760203660031901126103b257602061137d611d215f516020615cdd5f395f51905f52546004356145f3565b61519a565b60403660031901126103b257611d3a613fa8565b60243567ffffffffffffffff81116103b257366023820112156103b257611d6b903690602481600401359101614144565b6001600160a01b037f0000000000000000000000005b1142a82d155854532603dbc7158a44f3932e7916803014908115611eef575b50611ce257611dad614921565b6040516352d1902d60e01b81526001600160a01b0383169290602081600481875afa5f9181611ebb575b50611def5783634c9c8ce360e01b5f5260045260245ffd5b805f516020615bdd5f395f51905f52859203611ea95750813b15611e9757806001600160a01b03195f516020615bdd5f395f51905f525416175f516020615bdd5f395f51905f52557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b5f80a2815115611e7f575f8083602061076395519101845af4611e796153a8565b91615a02565b505034611e8857005b63b398979f60e01b5f5260045ffd5b634c9c8ce360e01b5f5260045260245ffd5b632a87526960e21b5f5260045260245ffd5b9091506020813d602011611ee7575b81611ed76020938361408d565b810103126103b257519085611dd7565b3d9150611eca565b90506001600160a01b035f516020615bdd5f395f51905f525416141583611da0565b346103b257611f1f36614112565b90611f28614921565b6007611f3483836149bd565b019182549160ff8316611f4d5760ff1983166001178455005b634e06b75f60e11b5f5260045260245260445ffd5b346103b25760403660031901126103b257611f7b613fa8565b602435611f8661487d565b611f8e6148b2565b611fb98161099c5f516020615a7d5f395f51905f52545f516020615cdd5f395f51905f5254906145e0565b7f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0d548082116121e35750505f516020615b9d5f395f51905f5254156121af575f516020615cdd5f395f51905f5254612010916145f3565b612028815f516020615c7d5f395f51905f52546145c6565b5f516020615c7d5f395f51905f525580915f516020615b5d5f395f51905f525480612183575b50612067825f516020615a7d5f395f51905f52546145c6565b5f516020615a7d5f395f51905f52556001600160a01b038116156121705782816120b46020957f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f9461574c565b6120de84604051938493846040919493926001600160a01b03606083019616825260208201520152565b0390a15f516020615c9d5f395f51905f525460ff811615801561212f575b61211a575b505f5f516020615cfd5f395f51905f525d604051908152f35b60ff6121299160101c16614b06565b82612101565b505f516020615c7d5f395f51905f52546127106121695f516020615a7d5f395f51905f52545f516020615c1d5f395f51905f5254906145e0565b04106120fc565b63ec442f0560e01b5f525f60045260245ffd5b6121a891935061219390836145e0565b5f516020615a7d5f395f51905f5254906145f3565b918361204e565b604051634612b38f60e01b815260206004820152600b60248201526a1d1bdd185b15d95a59da1d60aa1b6044820152606490fd5b60a49250604051916338d06e1d60e01b835260606004840152601060648401526f6d6178546f74616c4465706f7369747360801b608484015260248301526044820152fd5b346103b25760603660031901126103b257612241613fa8565b60243561224c613fd4565b61225461487d565b61225c6148b2565b816001600160a01b0384168015611aeb576001600160a01b037f285a08d85aaeb56c8b9d22b6877dffaed0cb5d07c1c14494aff61d9524746a12936080936020975f516020615c7d5f395f51905f5254976122b68961519a565b809111612343575b506122cc826122d392614eb5565b80986145d3565b5f516020615c7d5f395f51905f52556123146122fd5f516020615cdd5f395f51905f5254896145e0565b83855f516020615d1d5f395f51905f525416615202565b60405193845287840152856040840152166060820152a15f5f516020615cfd5f395f51905f525d604051908152f35b91506122cc6122be565b346103b25761235b36614112565b905f527f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0260205260405f20905f52602052602060405f2054604051908152f35b346103b2575f3660031901126103b25760207f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0b54604051908152f35b346103b2576123e5366140f8565b916123ee614921565b5f516020615c3d5f395f51905f525480606411156125ed575f5b81811061259c5750612428845f516020615b9d5f395f51905f52546145c6565b5f516020615b9d5f395f51905f5255815f527f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0260205260405f20835f5260205260405f20556040519261247a84614054565b8184526020840190838252604085019481865260608101905f825260808101915f835260a082015f815260c08301905f825260e08401945f86525f516020615c3d5f395f51905f525468010000000000000000811015612588578060016124f092015f516020615c3d5f395f51905f52556143ed565b949094612575577f5b1ee307451dd65aa45d1657a66752bab8925be9aad7c827865655c8c2fdac249b6109ce99600797518755516001870155516002860155516003850155516004840155516005830155516006820155019051151560ff80198354169116179055604051938493846040919493926060820195825260208201520152565b634e487b7160e01b5f525f60045260245ffd5b634e487b7160e01b5f52604160045260245ffd5b6125ae6125a8826143ed565b50614435565b848482511491826125df575b50506125c857600101612408565b505063b020eb6360e01b5f5260045260245260445ffd5b6020015114905084876125ba565b600181018091116126365760a490604051906338d06e1d60e01b82526060600483015260086064830152671419595c941bdbdb60c21b6084830152602482015260646044820152fd5b634e487b7160e01b5f52601160045260245ffd5b346103b2576101203660031901126103b257612664613fd4565b5060a0612670366140af565b61267861487d565b6126806148b2565b61268981615117565b0151610bb9600561125f6024356004356149bd565b346103b25760403660031901126103b2576126b7613fbe565b336001600160a01b038216036126d3576107639060043561507a565b63334bd91960e11b5f5260045ffd5b346103b2575f3660031901126103b257602061137d6157f6565b346103b2575f3660031901126103b25760205f516020615c1d5f395f51905f5254604051908152f35b346103b2575f3660031901126103b257602060ff5f516020615afd5f395f51905f525416604051908152f35b346103b25760403660031901126103b257610763600435612770613fbe565b90612796610759825f525f516020615c5d5f395f51905f52602052600160405f20015490565b6147d6565b346103b25760a03660031901126103b2576024356004356127ba613fd4565b916064359160843567ffffffffffffffff81116103b257366023820112156103b25780600401359067ffffffffffffffff82116103b25736602483830101116103b25761280561487d565b61280d6148b2565b6001600160a01b038616958615611aeb57600160ff600761282e88886149bd565b015416151503612c86578561284291614eb5565b9460ff5f516020615c9d5f395f51905f525416158015612c45575b6128ea575b918060247fc184e55db14c3f814948da0d3295ebf968287d110e7ebb55ea0f30a773fc1d3c96959360e09560209a60405198899788528c8801526040870152606086015288608086015260c060a08601528260c086015201848401375f828201840152601f01601f19168101030190a15f5f516020615cfd5f395f51905f525d604051908152f35b5f516020615c7d5f395f51905f5254965f88151580612c2e575b612911575b509650612862565b5f516020615c3d5f395f51905f52549061292a82614629565b5f5f5f516020615a7d5f395f51905f52545f516020615b9d5f395f51905f5254915b868110612bbd575050505f9b81155f14612a5a575050508080612a43575b6129d5575b50509260247fc184e55db14c3f814948da0d3295ebf968287d110e7ebb55ea0f30a773fc1d3c969593829360e0966129b860209c5b5f516020615c7d5f395f51905f52546145d3565b5f516020615c7d5f395f51905f5255935093955093959650612909565b8181101561296f576129e6816143ed565b50995f516020615c7d5f395f51905f525460028c0154612a05916145e0565b5f516020615b9d5f395f51905f5254612a1d916145f3565b9081612a28916145c6565b9a60060190815490612a39916145c6565b90556001016129d5565b505f516020615c7d5f395f51905f5254151561296a565b9080929391105f14612b2d575b838110612aa957505050509260247fc184e55db14c3f814948da0d3295ebf968287d110e7ebb55ea0f30a773fc1d3c969593829360e0966129b860209c6129a4565b80612ab660019285614af2565b51612ac2575b01612a67565b6006612b15612ad0836143ed565b509e612af986611378612ae3878b614af2565b515f516020615c7d5f395f51905f5254906145e0565b612b038589614af2565b52612b0e8488614af2565b51906145c6565b9d01612b268154612b0e8488614af2565b9055612abc565b50505f5b828110612b72575050509260247fc184e55db14c3f814948da0d3295ebf968287d110e7ebb55ea0f30a773fc1d3c969593829360e0966129b860209c6129a4565b80612b7f60019284614af2565b51612b8b575b01612b31565b6006612ba5612b99836143ed565b509d612b0e8487614af2565b9c01612bb68154612b0e8487614af2565b9055612b85565b612bc6816143ed565b50612bed612bdc856113786002850154876145e0565b9160066005820154910154906145c6565b90818111612c00575b505060010161294c565b94612c11612c2692600194976145d3565b612c1b8789614af2565b52612b0e8688614af2565b93905f612bf6565b505f516020615b9d5f395f51905f52541515612904565b505f516020615c7d5f395f51905f5254612710612c7f5f516020615a7d5f395f51905f52545f516020615c1d5f395f51905f5254906145e0565b041061285d565b505050631c6768ad60e21b5f5260045260245260445ffd5b346103b2575f3660031901126103b257602060ff5f516020615c9d5f395f51905f525460101c166040519015158152f35b346103b2575f3660031901126103b257602060ff5f516020615c9d5f395f51905f5254166040519015158152f35b346103b25760203660031901126103b257602061137d6004355f525f516020615c5d5f395f51905f52602052600160405f20015490565b346103b25760603660031901126103b257612d4d613fa8565b612d55613fbe565b60443590612d93836001600160a01b03165f527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0160205260405f2090565b6001600160a01b0333165f5260205260405f2054925f198410612dbb575b610eab9350614de4565b828410612e58576001600160a01b03811615612e45573315612e3257610eab93612e15826001600160a01b03165f527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0160205260405f2090565b6001600160a01b0333165f526020528360405f2091039055612db1565b634a1406b160e11b5f525f60045260245ffd5b63e602df0560e01b5f525f60045260245ffd5b8284637dc7a0d960e11b5f523360045260245260445260645ffd5b346103b2575f3660031901126103b25760205f516020615c7d5f395f51905f5254604051908152f35b346103b2575f3660031901126103b25760206040517f000000000000000000000000000000000000000000000000000000000003f4808152f35b346103b2575f3660031901126103b25760205f516020615b5d5f395f51905f5254604051908152f35b346103b2575f3660031901126103b25760205f516020615a7d5f395f51905f5254604051908152f35b346103b2575f3660031901126103b257602060405160648152f35b346103b257612f5136613ff9565b93929091612f5d614494565b50612f6661487d565b612f6e6148b2565b60ff5f516020615d1d5f395f51905f525460a01c166133f1576001600160a01b038216918215611aeb57612fa285886149bd565b93600160ff6007870154161515036133da575f516020615cdd5f395f51905f525496612fd9612fd189866145f3565b9889936145f3565b9360c07f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0b549460ff5f516020615afd5f395f51905f5254169561301a614a5f565b5f516020615a7d5f395f51905f5254905f516020615cbd5f395f51905f5254986040519361304785614038565b30855260208501526040840152606083015260808201528660a0820152896001600160a01b035f516020615bbd5f395f51905f5254169161309e6040519e8f958694859463143273dd60e21b865260048601614514565b03915afa988915610d8d575f996133b9575b5088511561334f575060808801926130c98451846145c6565b94806130db60608c01978851906145d3565b1061331d57508351806132fe575b505060408801956131066130fe8851856145d3565b8551906145c6565b600360a08b019282845201918254918083106132e857509261010098959261315961046f9d9996937f9c7519dcf6aef530f7209189ddd559038a69f8bb53f818b7fa76c67379aa6b2c9c999651906145d3565b9055156132ac5761317b613183915f516020615c7d5f395f51905f52546145c6565b8251906145c6565b5f516020615c7d5f395f51905f52555b5f516020615c9d5f395f51905f525460ff8116158015613257575b613242575b508851905191519260208a0151945195604051978852602088015260408701526060860152608085015260a084015260c083015260e0820152a15f5f516020615cfd5f395f51905f525d6040519182918291909160a08060c083019480518452602081015160208501526040810151604085015260608101516060850152608081015160808501520151910152565b60ff6132519160081c16614b06565b8a6131b3565b505f516020615c7d5f395f51905f52546127106132a45f516020615a7d5f395f51905f52547f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0954906145e0565b0411156131ae565b508051806132bb575b50613193565b6132d3905f516020615c7d5f395f51905f52546145c6565b5f516020615c7d5f395f51905f52558a6132b5565b8263c8a198d960e01b5f5260045260245260445ffd5b613307916145d3565b5f516020615cbd5f395f51905f525589806130e9565b8451865160405163463fc77f60e11b815260048101879052602481019290925260448201526064810191909152608490fd5b61337189604061336860608301516020840151906145c6565b910151906145c6565b90600182018092116126365760a49160405191631606f63960e21b8352606060048401526008606484015267185b5bdd5b9d131160c21b608484015260248301526044820152fd5b6133d391995060c03d60c011610d8657610d78818361408d565b978a6130b0565b8588631c6768ad60e21b5f5260045260245260445ffd5b6331ad2c0f60e11b5f5260045ffd5b346103b25760203660031901126103b2576134196143b1565b5061046f6104136125a86004356143ed565b346103b25760403660031901126103b257610eab613447613fa8565b60243590336156b8565b346103b2575f3660031901126103b2576040515f5f516020615a9d5f395f51905f525461347d816141fd565b80845290600181169081156110c557506001146134a45761046f836110478185038261408d565b5f516020615a9d5f395f51905f525f9081527f2ae08a8e29253f69ac5d979a101956ab8f8d9d7ded63fa7a83b16fc47648eab0939250905b8082106134f457509091508101602001611047611037565b9192600181602092548385880101520191019092916134dc565b346103b25760203660031901126103b25760043563ffffffff60e01b81168091036103b257602090637965db0b60e01b8114908115613553575b506040519015158152f35b6301ffc9a760e01b14905082613548565b346103b25760203660031901126103b25760043567ffffffffffffffff81116103b257806004019061014060031982360301126103b2575f516020615d7d5f395f51905f52549160ff8360401c16159267ffffffffffffffff811680159081613f7c575b6001149081613f72575b159081613f69575b50613f5a5767ffffffffffffffff1981166001175f516020615d7d5f395f51905f525583613f2e575b5061363661361182806141a8565b61362e61362460248795949501866141a8565b9490923691614144565b923691614144565b9061363f61568d565b61364761568d565b80519067ffffffffffffffff82116125885781906136725f516020615a9d5f395f51905f52546141fd565b601f8111613eb4575b50602090601f8311600114613e36575f92613e2b575b50508160011b915f199060031b1c1916175f516020615a9d5f395f51905f52555b80519067ffffffffffffffff8211612588576136db5f516020615b1d5f395f51905f52546141fd565b601f8111613dbc575b50602090601f8311600114613d38579180613733949261372c945f92613d2d575b50508160011b915f199060031b1c1916175f516020615b1d5f395f51905f52555b806141a8565b3691614144565b9161373c61568d565b60409182519361374c848661408d565b60018552603160f81b602086015261376261568d565b80519067ffffffffffffffff821161258857819061378d5f516020615add5f395f51905f52546141fd565b601f8111613cb3575b50602090601f8311600114613c35575f92613c2a575b50508160011b915f199060031b1c1916175f516020615add5f395f51905f52555b835167ffffffffffffffff8111612588576137f55f516020615b7d5f395f51905f52546141fd565b601f8111613bbb575b50602094601f8211600114613b40579481929394955f92613b35575b50508160011b915f199060031b1c1916175f516020615b7d5f395f51905f52555b5f7fa16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d100555f7fa16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d1015561388961568d565b61389161568d565b6138fb6138a0608483016141db565b60ff806138af60a486016141db565b926138b861568d565b6138c061568d565b16918261ff005f516020615afd5f395f51905f52549260081b169161ffff19161717805f516020615afd5f395f51905f525560081c166145d3565b604d811161263657600a0a5f516020615cdd5f395f51905f525561391d61568d565b61392561568d565b61394f7f0000000000000000000000000000000000000000000000000000000000015180436145c6565b5f516020615d3d5f395f51905f525561397261396d60e483016141e9565b61465b565b5061398861398361010483016141e9565b61470a565b5060448101357f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0b55606481016001600160a01b036139c5826141e9565b1615613b085760c48201906001600160a01b036139e1836141e9565b1615613ad357613a2961012493926001600160a01b03613a0181946141e9565b1683195f516020615d1d5f395f51905f525416175f516020615d1d5f395f51905f52556141e9565b166001600160a01b03195f516020615bbd5f395f51905f525416175f516020615bbd5f395f51905f525501357f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0d55613a7d57005b60207fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29168ff0000000000000000195f516020615d7d5f395f51905f5254165f516020615d7d5f395f51905f52555160018152a1005b8451636bc37c5f60e11b815260206004820152600d60248201526c3332b2a1b0b631bab630ba37b960991b6044820152606490fd5b8351636bc37c5f60e11b81526020600482015260056024820152643a37b5b2b760d91b6044820152606490fd5b01519050858061381a565b601f198216955f516020615b7d5f395f51905f525f52805f20915f5b888110613ba357508360019596979810613b8b575b505050811b015f516020615b7d5f395f51905f525561383b565b01515f1960f88460031b161c19169055858080613b71565b91926020600181928685015181550194019201613b5c565b5f516020615b7d5f395f51905f525f527f5f9ce34815f8e11431c7bb75a8e6886a91478f7ffc1dbb0a98dc240fddd76b75601f830160051c81019160208410613c20575b601f0160051c01905b818110613c1557506137fe565b5f8155600101613c08565b9091508190613bff565b0151905086806137ac565b5f516020615add5f395f51905f525f9081528281209350601f198516905b818110613c9b5750908460019594939210613c83575b505050811b015f516020615add5f395f51905f52556137cd565b01515f1960f88460031b161c19169055868080613c69565b92936020600181928786015181550195019301613c53565b5f516020615add5f395f51905f525f529091507f42ad5d3e1f2e6e70edcf6d991b8a3023d3fca8047a131592f9edb9fd9b89d57d601f840160051c81019160208510613d23575b90601f859493920160051c01905b818110613d155750613796565b5f8155849350600101613d08565b9091508190613cfa565b015190508780613705565b90601f198316915f516020615b1d5f395f51905f525f52815f20925f5b818110613da4575092600192859261372c96613733989610613d8c575b505050811b015f516020615b1d5f395f51905f5255613726565b01515f1960f88460031b161c19169055878080613d72565b92936020600181928786015181550195019301613d55565b5f516020615b1d5f395f51905f525f527f46a2803e59a4de4e7a4c574b1243f25977ac4c77d5a1a4a609b5394cebb4a2aa601f840160051c81019160208510613e21575b601f0160051c01905b818110613e1657506136e4565b5f8155600101613e09565b9091508190613e00565b015190508680613691565b5f516020615a9d5f395f51905f525f9081528281209350601f198516905b818110613e9c5750908460019594939210613e84575b505050811b015f516020615a9d5f395f51905f52556136b2565b01515f1960f88460031b161c19169055868080613e6a565b92936020600181928786015181550195019301613e54565b5f516020615a9d5f395f51905f525f529091507f2ae08a8e29253f69ac5d979a101956ab8f8d9d7ded63fa7a83b16fc47648eab0601f840160051c81019160208510613f24575b90601f859493920160051c01905b818110613f16575061367b565b5f8155849350600101613f09565b9091508190613efb565b68ffffffffffffffffff191668010000000000000001175f516020615d7d5f395f51905f525583613603565b63f92ee8a960e01b5f5260045ffd5b905015856135da565b303b1591506135d2565b8591506135c8565b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b600435906001600160a01b03821682036103b257565b602435906001600160a01b03821682036103b257565b604435906001600160a01b03821682036103b257565b6004359081151582036103b257565b60c09060031901126103b25760043590602435906044356001600160a01b03811681036103b25790606435906084359060a43580151581036103b25790565b60c0810190811067ffffffffffffffff82111761258857604052565b610100810190811067ffffffffffffffff82111761258857604052565b6040810190811067ffffffffffffffff82111761258857604052565b90601f8019910116810190811067ffffffffffffffff82111761258857604052565b60c09060631901126103b257604051906140c882614038565b6064358252608435602083015260a435604083015260c435606083015260e43560808301526101043560a0830152565b60609060031901126103b257600435906024359060443590565b60409060031901126103b2576004359060243590565b67ffffffffffffffff811161258857601f01601f191660200190565b92919261415082614128565b9161415e604051938461408d565b8294818452818301116103b2578281602093845f960137010152565b60809060031901126103b25760043590602435906044356001600160a01b03811681036103b2579060643590565b903590601e19813603018212156103b2570180359067ffffffffffffffff82116103b2576020019181360383136103b257565b3560ff811681036103b25790565b356001600160a01b03811681036103b25790565b90600182811c9216801561422b575b602083101461421757565b634e487b7160e01b5f52602260045260245ffd5b91607f169161420c565b604051905f825f516020615add5f395f51905f525491614254836141fd565b80835292600181169081156142e5575060011461427a575b6142789250038361408d565b565b505f516020615add5f395f51905f525f90815290917f42ad5d3e1f2e6e70edcf6d991b8a3023d3fca8047a131592f9edb9fd9b89d57d5b8183106142c95750509060206142789282010161426c565b60209193508060019154838589010152019101909184926142b1565b6020925061427894915060ff191682840152151560051b82010161426c565b604051905f825f516020615b7d5f395f51905f525491614323836141fd565b80835292600181169081156142e55750600114614346576142789250038361408d565b505f516020615b7d5f395f51905f525f90815290917f5f9ce34815f8e11431c7bb75a8e6886a91478f7ffc1dbb0a98dc240fddd76b755b8183106143955750509060206142789282010161426c565b602091935080600191548385890101520191019091849261437d565b604051906143be82614054565b5f60e0838281528260208201528260408201528260608201528260808201528260a08201528260c08201520152565b5f516020615c3d5f395f51905f5254811015614421575f516020615c3d5f395f51905f525f5260205f209060031b01905f90565b634e487b7160e01b5f52603260045260245ffd5b9060405161444281614054565b60e060ff600783958054855260018101546020860152600281015460408601526003810154606086015260048101546080860152600581015460a0860152600681015460c08601520154161515910152565b604051906144a182614038565b5f60a0838281528260208201528260408201528260608201528260808201520152565b908160c09103126103b25760a0604051916144de83614038565b8051835260208101516020840152604081015160408401526060810151606084015260808101516080840152015160a082015290565b909493926001600160a01b039060ff60076101e09560a061020087019a868151168852602081015160208901528460408201511660408901526060810151606089015260808101516080890152015160a0870152805460c0870152600181015460e08701526002810154610100870152600381015461012087015260048101546101408701526005810154610160870152600681015461018087015201541615156101a0840152166101c08201520152565b9190820180921161263657565b9190820391821161263657565b8181029291811591840414171561263657565b81156145fd570490565b634e487b7160e01b5f52601260045260245ffd5b67ffffffffffffffff81116125885760051b60200190565b9061463382614611565b614640604051918261408d565b8281528092614651601f1991614611565b0190602036910137565b6001600160a01b0381165f9081527fb7db2dd08fcb62d0c9e08c51941cae53c267786a0b75803fb7960902fc8ef97d602052604090205460ff16614705576001600160a01b03165f8181527fb7db2dd08fcb62d0c9e08c51941cae53c267786a0b75803fb7960902fc8ef97d60205260408120805460ff191660011790553391907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d8180a4600190565b505f90565b6001600160a01b0381165f9081527fb99f74ed0a18e51a0abeabf20177563f97170d9a304aaf2f87e619c498908538602052604090205460ff16614705576001600160a01b03165f8181527fb99f74ed0a18e51a0abeabf20177563f97170d9a304aaf2f87e619c49890853860205260408120805460ff191660011790553391907f66d05ae646b1ee24e48a8708b8c0f6eade385a89cd689a1ed9121cb3ec9e2102907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9080a4600190565b805f525f516020615c5d5f395f51905f5260205260405f206001600160a01b0383165f5260205260ff60405f205416155f1461487757805f525f516020615c5d5f395f51905f5260205260405f206001600160a01b0383165f5260205260405f20600160ff198254161790556001600160a01b03339216907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d5f80a4600190565b50505f90565b5f516020615cfd5f395f51905f525c6148a35760015f516020615cfd5f395f51905f525d565b633ee5aeb560e01b5f5260045ffd5b335f9081527fb99f74ed0a18e51a0abeabf20177563f97170d9a304aaf2f87e619c498908538602052604090205460ff16156148ea57565b63e2517d3f60e01b5f52336004527f66d05ae646b1ee24e48a8708b8c0f6eade385a89cd689a1ed9121cb3ec9e210260245260445ffd5b335f9081527fb7db2dd08fcb62d0c9e08c51941cae53c267786a0b75803fb7960902fc8ef97d602052604090205460ff161561495957565b63e2517d3f60e01b5f52336004525f60245260445ffd5b805f525f516020615c5d5f395f51905f5260205260405f206001600160a01b0333165f5260205260ff60405f205416156149a75750565b63e2517d3f60e01b5f523360045260245260445ffd5b91905f516020615c3d5f395f51905f525415614a5057825f527f98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0260205260405f20815f52602052614a1160405f20546143ed565b509283828282541491821592614a41575b5050614a2c575050565b6310de8c5160e31b5f5260045260245260445ffd5b6001015414159050825f614a22565b634d6af2e760e11b5f5260045ffd5b602460206001600160a01b035f516020615d1d5f395f51905f525416604051928380926370a0823160e01b82523060048301525afa8015610d8d575f90614abe575b614abb91505f516020615cdd5f395f51905f5254906145f3565b90565b506020813d602011614aea575b81614ad86020938361408d565b810103126103b257614abb9051614aa1565b3d9150614acb565b80518210156144215760209160051b010190565b5f516020615c7d5f395f51905f52549081151580614dcd575b614b27575050565b5f516020615c3d5f395f51905f525490614b4082614629565b5f5f5f516020615a7d5f395f51905f52545f516020615b9d5f395f51905f5254915b868110614d82575050505f9481155f14614c235750505080614c0c575b614bae575b50614b9d905f516020615c7d5f395f51905f52546145d3565b5f516020615c7d5f395f51905f5255565b5f5b818110614bbd5750614b84565b80614bc96001926143ed565b5093614c046006614bfa614bf36115b15f516020615c7d5f395f51905f525460028b0154906145e0565b80946145c6565b96019182546145c6565b905501614bb0565b505f516020615c7d5f395f51905f52541515614b7f565b9080929391105f14614c9857505f5b838110614c465750505050614b9d906129a4565b80614c5360019285614af2565b51614c5f575b01614c32565b6006614c80614c6d836143ed565b5097612af986611378612ae3878b614af2565b9601614c918154612b0e8488614af2565b9055614c59565b9294939215614d1d57614cb9905f516020615c7d5f395f51905f52546145d3565b5f5b858110614cd057505050614b9d9192506129a4565b80614cdc6001926143ed565b5094614d156006614d0b614bf3614cf3868a614af2565b51614d056115b160028d01548b6145e0565b906145c6565b97019182546145c6565b905501614cbb565b505f939192935b828110614d3757505050614b9d906129a4565b80614d4460019284614af2565b51614d50575b01614d24565b6006614d6a614d5e836143ed565b5096612b0e8487614af2565b9501614d7b8154612b0e8487614af2565b9055614d4a565b614d8b816143ed565b50614da1612bdc856113786002850154876145e0565b90818111614db4575b5050600101614b62565b94612c11614dc592600194976145d3565b93905f614daa565b505f516020615b9d5f395f51905f52541515614b1f565b6001600160a01b0316908115614ea2576001600160a01b031691821561217057815f525f516020615abd5f395f51905f5260205260405f2054818110614e8957817fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92602092855f525f516020615abd5f395f51905f5284520360405f2055845f525f516020615abd5f395f51905f52825260405f20818154019055604051908152a3565b8263391434e360e21b5f5260045260245260445260645ffd5b634b637e8f60e11b5f525f60045260245ffd5b905f516020615b5d5f395f51905f5254918215611385576001600160a01b038116805f525f516020615abd5f395f51905f5260205260405f20548381106150285750614f1e614f175f516020615a7d5f395f51905f52549561137887876145e0565b80956145d3565b5f516020615a7d5f395f51905f52558015614ea257805f525f516020615abd5f395f51905f5260205260405f205483811061500e5781845f927f49995e5dd6158cf69ad3e9777c46755a1a826a446c6416992167462dad033b2a96959484525f516020615abd5f395f51905f52602052036040832055835f516020615b5d5f395f51905f5254035f516020615b5d5f395f51905f52557fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef6020604051868152a361500884604051938493846040919493926001600160a01b03606083019616825260208201520152565b0390a190565b915063391434e360e21b5f5260045260245260445260645ffd5b8360a491604051916338d06e1d60e01b835260606004840152601560648401527f506f6f6c2e5f6275726e4c502e616d6f756e744c500000000000000000000000608484015260248301526044820152fd5b805f525f516020615c5d5f395f51905f5260205260405f206001600160a01b0383165f5260205260ff60405f2054165f1461487757805f525f516020615c5d5f395f51905f5260205260405f206001600160a01b0383165f5260205260405f2060ff1981541690556001600160a01b03339216907ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b5f80a4600190565b60206151899161513960408201515f516020615a7d5f395f51905f52546145c6565b5f516020615a7d5f395f51905f525561516460608201515f516020615cbd5f395f51905f52546145c6565b5f516020615cbd5f395f51905f525501515f516020615d5d5f395f51905f52546145c6565b5f516020615d5d5f395f51905f5255565b5f516020615a7d5f395f51905f525480156151cb57611378614abb925f516020615b5d5f395f51905f5254906145e0565b604051634612b38f60e01b815260206004820152600e60248201526d746f74616c4c697175696469747960901b6044820152606490fd5b61520d8383836153d7565b1561521757505050565b906001600160a01b0380926387abb3dd60e01b5f52166004521660245260445260645ffd5b5f516020615d3d5f395f51905f5254431161539b575b61526a815f516020615b3d5f395f51905f52546145c6565b7f000000000000000000000000000000000000000000000002b5e3af16b18800001061530b57807f0000000000000000000000000000000000000000000000022b1c8c1227a00000105f146152f557806152e1915f516020615a5d5f395f51905f52555f516020615b3d5f395f51905f52546145c6565b5f516020615b3d5f395f51905f5255600190565b505f5f516020615a5d5f395f51905f5255600190565b505f5f516020615a5d5f395f51905f52555f516020615bfd5f395f51905f525460ff81161561533957505f90565b60019060ff1916175f516020615bfd5f395f51905f52556153887f000000000000000000000000000000000000000000000000000000000003f4805f516020615d3d5f395f51905f52546145c6565b5f516020615d3d5f395f51905f52555f90565b6153a36154c4565b615252565b3d156153d2573d906153b982614128565b916153c7604051938461408d565b82523d5f602084013e565b606090565b60405163a9059cbb60e01b602082019081526001600160a01b039390931660248201526044808201949094529283525f92839290839061541860648261408d565b51925af16154246153a8565b8180615452575b615433575090565b90506020818051810103126103b2576020015180151581036103b25790565b508051151561542b565b5f516020615b3d5f395f51905f52545f516020615a5d5f395f51905f5254808210156154a75750505f5f516020615b3d5f395f51905f52555b5f5f516020615a5d5f395f51905f5255565b6154b0916145d3565b5f516020615b3d5f395f51905f5255615495565b6154ee7f0000000000000000000000000000000000000000000000000000000000015180436145c6565b5f516020615d3d5f395f51905f52555f5f516020615b3d5f395f51905f525560ff195f516020615bfd5f395f51905f5254165f516020615bfd5f395f51905f5255565b91905f516020615b9d5f395f51905f5254156121af575f516020615cdd5f395f51905f525461555f916145f3565b91825f516020615b5d5f395f51905f525480615678575b5061558f845f516020615a7d5f395f51905f52546145c6565b5f516020615a7d5f395f51905f52556001600160a01b0382161561217057816155d9827f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f9461574c565b61560385604051938493846040919493926001600160a01b03606083019616825260208201520152565b0390a15f516020615c9d5f395f51905f525460ff8116158015615637575b6156285750565b60ff6142789160101c16614b06565b505f516020615c7d5f395f51905f52546127106156715f516020615a7d5f395f51905f52545f516020615c1d5f395f51905f5254906145e0565b0410615621565b615687915061219390856145e0565b5f615576565b60ff5f516020615d7d5f395f51905f525460401c16156156a957565b631afcd79f60e31b5f5260045ffd5b916001600160a01b038316918215612e45576001600160a01b0316928315612e32577f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925916157386020926001600160a01b03165f527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0160205260405f2090565b855f5282528060405f2055604051908152a3565b7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60206001600160a01b035f93615791865f516020615b5d5f395f51905f52546145c6565b5f516020615b5d5f395f51905f52551693841584146157d457805f516020615b5d5f395f51905f5254035f516020615b5d5f395f51905f52555b604051908152a3565b8484525f516020615abd5f395f51905f528252604084208181540190556157cb565b6157fe615953565b6158066159bd565b6040519060208201927f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f8452604083015260608201524660808201523060a082015260a0815261585760c08261408d565b51902090565b91907f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a084116158d4579160209360809260ff5f9560405194855216868401526040830152606082015282805260015afa15610d8d575f516001600160a01b038116156158ca57905f905f90565b505f906001905f90565b5050505f9160039190565b600481101561593f57806158f1575050565b600181036159085763f645eedf60e01b5f5260045ffd5b60028103615923575063fce698f760e01b5f5260045260245ffd5b60031461592d5750565b6335e2f38360e21b5f5260045260245ffd5b634e487b7160e01b5f52602160045260245ffd5b61595b614235565b805190811561596b576020012090565b50507fa16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d1005480156159985790565b507fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a47090565b6159c5614304565b80519081156159d5576020012090565b50507fa16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d1015480156159985790565b90615a265750805115615a1757602081519101fd5b63d6bda27560e01b5f5260045ffd5b81511580615a53575b615a37575090565b6001600160a01b0390639996b31560e01b5f521660045260245ffd5b50803b15615a2f56fe0ee2d9de8392a8f17ff2bb7a24b72fd27e2cf4ac5cd7fd56e5bf7bdb439eb00398b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0352c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0352c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace00a16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d102363bd9d3ac01b05edede66fbb9c4f73d99f1481666c51eee8df34d23a61f480052c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace040ee2d9de8392a8f17ff2bb7a24b72fd27e2cf4ac5cd7fd56e5bf7bdb439eb00152c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace02a16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d10398b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0498b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea00360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc0ee2d9de8392a8f17ff2bb7a24b72fd27e2cf4ac5cd7fd56e5bf7bdb439eb00298b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0a98b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0102dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b62680098b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0598b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0698b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea08363bd9d3ac01b05edede66fbb9c4f73d99f1481666c51eee8df34d23a61f48019b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f0098b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea0c0ee2d9de8392a8f17ff2bb7a24b72fd27e2cf4ac5cd7fd56e5bf7bdb439eb00098b6721f87b10fba9510649effb5cccfd7d04ba1bf6c44593ef8229732a7ea07f0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00a26469706673582212209951471a36050e92bdd094236f1837ccda0b9fbebb6a4cd3e36a4fe115df3f7b64736f6c634300081c0033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.