Source Code
Overview
MNT Balance
MNT 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.
Contract Name:
InitCore
Compiler Version
v0.8.19+commit.7dd6d404
Optimization Enabled:
Yes with 200 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: None
pragma solidity ^0.8.19;
import {Multicall} from '../common/Multicall.sol';
import '../common/library/InitErrors.sol';
import '../common/library/ArrayLib.sol';
import {UnderACM} from '../common/UnderACM.sol';
import {IInitCore} from '../interfaces/core/IInitCore.sol';
import {IPosManager} from '../interfaces/core/IPosManager.sol';
import {PoolConfig, TokenFactors, ModeStatus, IConfig} from '../interfaces/core/IConfig.sol';
import {ILendingPool} from '../interfaces/lending_pool/ILendingPool.sol';
import {IBaseWrapLp} from '../interfaces/wrapper/IBaseWrapLp.sol';
import {IInitOracle} from '../interfaces/oracle/IInitOracle.sol';
import {ILiqIncentiveCalculator} from '../interfaces/core/ILiqIncentiveCalculator.sol';
import {ICallbackReceiver} from '../interfaces/receiver/ICallbackReceiver.sol';
import {IFlashReceiver} from '../interfaces/receiver/IFlashReceiver.sol';
import {IRiskManager} from '../interfaces/risk_manager/IRiskManager.sol';
import {ReentrancyGuardUpgradeable} from '@openzeppelin-contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol';
import {SafeCast} from '@openzeppelin-contracts/utils/math/SafeCast.sol';
import {SafeERC20} from '@openzeppelin-contracts/token/ERC20/utils/SafeERC20.sol';
import {MathUpgradeable} from '@openzeppelin-contracts-upgradeable/utils/math/MathUpgradeable.sol';
import {IERC20} from '@openzeppelin-contracts/token/ERC20/IERC20.sol';
import {EnumerableSet} from '@openzeppelin-contracts/utils/structs/EnumerableSet.sol';
contract InitCore is IInitCore, Multicall, ReentrancyGuardUpgradeable, UnderACM {
using SafeCast for uint;
using SafeERC20 for IERC20;
using EnumerableSet for EnumerableSet.UintSet;
using MathUpgradeable for uint;
using UncheckedIncrement for uint;
// constants
uint private constant ONE_E18 = 1e18;
bytes32 private constant GUARDIAN = keccak256('guardian');
bytes32 private constant GOVERNOR = keccak256('governor');
// immutables
address public immutable POS_MANAGER;
// storages
address public config; // @inheritdoc IInitCore
address public oracle; // @inheritdoc IInitCore
address public liqIncentiveCalculator; // @inheritdoc IInitCore
address public riskManager; // @inheritdoc IInitCore
bool internal isMulticallTx;
EnumerableSet.UintSet internal uncheckedPosIds; // posIds that need to be checked after multicall
// modifiers
modifier onlyGuardian() {
ACM.checkRole(GUARDIAN, msg.sender);
_;
}
modifier onlyGovernor() {
ACM.checkRole(GOVERNOR, msg.sender);
_;
}
modifier onlyAuthorized(uint _posId) {
_require(IPosManager(POS_MANAGER).isAuthorized(msg.sender, _posId), Errors.NOT_AUTHORIZED);
_;
}
/// @dev keep track of the position and ensure that the position is healthy at the very end
/// @param _posId pos id to ensure health
modifier ensurePositionHealth(uint _posId) {
if (isMulticallTx) uncheckedPosIds.add(_posId);
_;
if (!isMulticallTx) _require(_isPosHealthy(_posId), Errors.POSITION_NOT_HEALTHY);
}
// constructor
constructor(address _posManager, address _acm) UnderACM(_acm) {
POS_MANAGER = _posManager;
_disableInitializers();
}
// initalize
/// @dev initialize contract and setup config, oracle, incentive calculator and risk manager addresses
/// @param _config config address
/// @param _oracle oracle address
/// @param _liqIncentiveCalculator liquidation incentive calculator address
/// @param _riskManager risk manager address
function initialize(address _config, address _oracle, address _liqIncentiveCalculator, address _riskManager)
external
initializer
{
__ReentrancyGuard_init();
_setConfig(_config);
_setOracle(_oracle);
_setLiqIncentiveCalculator(_liqIncentiveCalculator);
_setRiskManager(_riskManager);
}
// functions
/// @inheritdoc IInitCore
function mintTo(address _pool, address _to) public virtual nonReentrant returns (uint shares) {
// check pool status
PoolConfig memory poolConfig = IConfig(config).getPoolConfig(_pool);
_require(poolConfig.canMint, Errors.MINT_PAUSED);
// call mint at pool using _to
shares = ILendingPool(_pool).mint(_to);
// check supply cap after mint
_require(ILendingPool(_pool).totalAssets() <= poolConfig.supplyCap, Errors.SUPPLY_CAP_REACHED);
}
/// @inheritdoc IInitCore
function burnTo(address _pool, address _to) public virtual nonReentrant returns (uint amt) {
// check pool status
PoolConfig memory poolConfig = IConfig(config).getPoolConfig(_pool);
_require(poolConfig.canBurn, Errors.REDEEM_PAUSED);
// call burn at pool using _to
amt = ILendingPool(_pool).burn(_to);
}
/// @inheritdoc IInitCore
function borrow(address _pool, uint _amt, uint _posId, address _to)
public
virtual
onlyAuthorized(_posId)
ensurePositionHealth(_posId)
nonReentrant
returns (uint shares)
{
IConfig _config = IConfig(config);
// check pool and mode status
PoolConfig memory poolConfig = _config.getPoolConfig(_pool);
uint16 mode = _getPosMode(_posId);
// check if the mode is allow to borrow
_require(poolConfig.canBorrow && _config.getModeStatus(mode).canBorrow, Errors.BORROW_PAUSED);
// check if the position mode supports _pool
_require(_config.isAllowedForBorrow(mode, _pool), Errors.INVALID_MODE);
// get borrow shares (accrue interest)
shares = ILendingPool(_pool).debtAmtToShareCurrent(_amt);
// check shares != 0
_require(shares != 0, Errors.ZERO_VALUE);
// check borrow cap after borrow
_require(ILendingPool(_pool).totalDebt() + _amt <= poolConfig.borrowCap, Errors.BORROW_CAP_REACHED);
// update debt on the position
IPosManager(POS_MANAGER).updatePosDebtShares(_posId, _pool, shares.toInt256());
// call borrow from the pool with target _to
ILendingPool(_pool).borrow(_to, _amt);
// update debt on mode
IRiskManager(riskManager).updateModeDebtShares(mode, _pool, shares.toInt256());
emit Borrow(_pool, _posId, _to, _amt, shares);
}
/// @inheritdoc IInitCore
function repay(address _pool, uint _shares, uint _posId)
public
virtual
onlyAuthorized(_posId)
nonReentrant
returns (uint amt)
{
(, amt) = _repay(IConfig(config), _getPosMode(_posId), _posId, _pool, _shares);
}
/// @inheritdoc IInitCore
function createPos(uint16 _mode, address _viewer) public virtual nonReentrant returns (uint posId) {
_require(_mode != 0, Errors.INVALID_MODE);
posId = IPosManager(POS_MANAGER).createPos(msg.sender, _mode, _viewer);
emit CreatePosition(msg.sender, posId, _mode, _viewer);
}
/// @inheritdoc IInitCore
function setPosMode(uint _posId, uint16 _mode)
public
virtual
onlyAuthorized(_posId)
ensurePositionHealth(_posId)
nonReentrant
{
IConfig _config = IConfig(config);
// get current collaterals in the position
(address[] memory pools,, address[] memory wLps, uint[][] memory ids,) =
IPosManager(POS_MANAGER).getPosCollInfo(_posId);
uint16 currentMode = _getPosMode(_posId);
ModeStatus memory currentModeStatus = _config.getModeStatus(currentMode);
ModeStatus memory newModeStatus = _config.getModeStatus(_mode);
if (pools.length != 0 || wLps.length != 0) {
_require(newModeStatus.canCollateralize, Errors.COLLATERALIZE_PAUSED);
_require(currentModeStatus.canDecollateralize, Errors.DECOLLATERALIZE_PAUSED);
}
// check that each position collateral belongs to the _mode
for (uint i; i < pools.length; i = i.uinc()) {
_require(_config.isAllowedForCollateral(_mode, pools[i]), Errors.INVALID_MODE);
}
for (uint i; i < wLps.length; i = i.uinc()) {
// check if the wLp is whitelisted
_require(_config.whitelistedWLps(wLps[i]), Errors.TOKEN_NOT_WHITELISTED);
for (uint j; j < ids[i].length; j = j.uinc()) {
_require(_config.isAllowedForCollateral(_mode, IBaseWrapLp(wLps[i]).lp(ids[i][j])), Errors.INVALID_MODE);
}
}
// get current debts in the position
uint[] memory shares;
(pools, shares) = IPosManager(POS_MANAGER).getPosBorrInfo(_posId);
IRiskManager _riskManager = IRiskManager(riskManager);
_require(newModeStatus.canBorrow, Errors.BORROW_PAUSED);
_require(currentModeStatus.canRepay && newModeStatus.canRepay, Errors.REPAY_PAUSED);
// check that each position debt belongs to the _mode
for (uint i; i < pools.length; i = i.uinc()) {
_require(_config.isAllowedForBorrow(_mode, pools[i]), Errors.INVALID_MODE);
// update debt on current mode
_riskManager.updateModeDebtShares(currentMode, pools[i], -shares[i].toInt256());
// update debt on new mode
_riskManager.updateModeDebtShares(_mode, pools[i], shares[i].toInt256());
}
// update position mode
IPosManager(POS_MANAGER).updatePosMode(_posId, _mode);
emit SetPositionMode(_posId, _mode);
}
/// @inheritdoc IInitCore
function collateralize(uint _posId, address _pool) public virtual onlyAuthorized(_posId) nonReentrant {
IConfig _config = IConfig(config);
// check mode status
uint16 mode = _getPosMode(_posId);
_require(_config.getModeStatus(mode).canCollateralize, Errors.COLLATERALIZE_PAUSED);
// check if the position mode supports _pool
_require(_config.isAllowedForCollateral(mode, _pool), Errors.INVALID_MODE);
// update collateral on the position
uint amtColl = IPosManager(POS_MANAGER).addCollateral(_posId, _pool);
emit Collateralize(_posId, _pool, amtColl);
}
/// @inheritdoc IInitCore
function decollateralize(uint _posId, address _pool, uint _shares, address _to)
public
virtual
onlyAuthorized(_posId)
ensurePositionHealth(_posId)
nonReentrant
{
// check mode status
_require(IConfig(config).getModeStatus(_getPosMode(_posId)).canDecollateralize, Errors.DECOLLATERALIZE_PAUSED);
// take _pool from position to _to
uint amtDecoll = IPosManager(POS_MANAGER).removeCollateralTo(_posId, _pool, _shares, _to);
emit Decollateralize(_posId, _pool, _to, amtDecoll);
}
/// @inheritdoc IInitCore
function collateralizeWLp(uint _posId, address _wLp, uint _tokenId)
public
virtual
onlyAuthorized(_posId)
nonReentrant
{
IConfig _config = IConfig(config);
uint16 mode = _getPosMode(_posId);
// check mode status
_require(_config.getModeStatus(mode).canCollateralize, Errors.COLLATERALIZE_PAUSED);
// check if the wLp is whitelisted
_require(_config.whitelistedWLps(_wLp), Errors.TOKEN_NOT_WHITELISTED);
// check if the position mode supports _wLp
_require(_config.isAllowedForCollateral(mode, IBaseWrapLp(_wLp).lp(_tokenId)), Errors.INVALID_MODE);
// update collateral on the position
uint amtColl = IPosManager(POS_MANAGER).addCollateralWLp(_posId, _wLp, _tokenId);
emit CollateralizeWLp(_wLp, _tokenId, _posId, amtColl);
}
/// @inheritdoc IInitCore
function decollateralizeWLp(uint _posId, address _wLp, uint _tokenId, uint _amt, address _to)
public
virtual
onlyAuthorized(_posId)
ensurePositionHealth(_posId)
nonReentrant
{
IConfig _config = IConfig(config);
// check mode status
_require(_config.getModeStatus(_getPosMode(_posId)).canDecollateralize, Errors.DECOLLATERALIZE_PAUSED);
// check wLp is whitelisted
_require(_config.whitelistedWLps(_wLp), Errors.TOKEN_NOT_WHITELISTED);
// update and take _wLp from position to _to
uint amtDecoll = IPosManager(POS_MANAGER).removeCollateralWLpTo(_posId, _wLp, _tokenId, _amt, _to);
emit Decollateralize(_wLp, _posId, _to, amtDecoll);
}
/// @inheritdoc IInitCore
function liquidate(uint _posId, address _poolToRepay, uint _repayShares, address _poolOut, uint _minShares)
public
virtual
nonReentrant
returns (uint shares)
{
LiquidateLocalVars memory vars = _liquidateInternal(_posId, _poolToRepay, _repayShares);
_require(vars.config.isAllowedForCollateral(vars.mode, _poolOut), Errors.TOKEN_NOT_WHITELISTED); // config and mode are already stored
vars.collToken = ILendingPool(_poolOut).underlyingToken();
vars.liqIncentive_e18 = ILiqIncentiveCalculator(liqIncentiveCalculator).getLiqIncentiveMultiplier_e18(
vars.mode, vars.health_e18, vars.repayToken, vars.collToken
);
vars.repayAmtWithLiqIncentive = (vars.repayAmt * vars.liqIncentive_e18) / ONE_E18;
{
uint[] memory prices_e36; // prices = [repayTokenPrice, collToken]
address[] memory tokens = new address[](2);
(tokens[0], tokens[1]) = (vars.repayToken, vars.collToken);
prices_e36 = IInitOracle(oracle).getPrices_e36(tokens);
// calculate _tokenOut amt to return to liquidator
shares = ILendingPool(_poolOut).toShares((vars.repayAmtWithLiqIncentive * prices_e36[0]) / prices_e36[1]);
// take min of what's available (for bad debt repayment)
shares = shares.min(IPosManager(POS_MANAGER).getCollAmt(_posId, _poolOut)); // take min of what's available
_require(shares >= _minShares, Errors.SLIPPAGE_CONTROL);
}
// take _tokenOut from position to msg.sender
if (shares > 0) IPosManager(POS_MANAGER).removeCollateralTo(_posId, _poolOut, shares, msg.sender);
// check that position's health <= maxHealth
// NOTE: bypass this for underwater position
if (vars.health_e18 != 0) _ensurePosHealthAfterLiq(vars.config, _posId, vars.mode);
emit Liquidate(_posId, msg.sender, _poolOut, shares);
}
/// @inheritdoc IInitCore
function liquidateWLp(
uint _posId,
address _poolToRepay,
uint _repayShares,
address _wLp,
uint _tokenId,
uint _minlpOut
) external virtual nonReentrant returns (uint lpAmtOut) {
LiquidateLocalVars memory vars = _liquidateInternal(_posId, _poolToRepay, _repayShares);
_require(vars.config.whitelistedWLps(_wLp), Errors.TOKEN_NOT_WHITELISTED); // config is already stored
vars.collToken = IBaseWrapLp(_wLp).lp(_tokenId);
vars.liqIncentive_e18 = ILiqIncentiveCalculator(liqIncentiveCalculator).getLiqIncentiveMultiplier_e18(
vars.mode, vars.health_e18, vars.repayToken, vars.collToken
);
vars.repayAmtWithLiqIncentive = (vars.repayAmt * vars.liqIncentive_e18) / ONE_E18;
uint wLpAmtToBurn;
{
address _oracle = oracle;
uint wLpAmt = IPosManager(POS_MANAGER).getCollWLpAmt(_posId, _wLp, _tokenId);
wLpAmtToBurn = IInitOracle(_oracle).getPrice_e36(vars.repayToken).mulDiv(
vars.repayAmtWithLiqIncentive, IBaseWrapLp(_wLp).calculatePrice_e36(_tokenId, _oracle)
);
// take min of what's available (for bad debt repayment)
wLpAmtToBurn = wLpAmtToBurn.min(wLpAmt);
}
// reduce and burn wLp to underlying for liquidator
if (wLpAmtToBurn > 0) {
lpAmtOut = IPosManager(POS_MANAGER).removeCollateralWLpTo(_posId, _wLp, _tokenId, wLpAmtToBurn, msg.sender);
}
_require(lpAmtOut >= _minlpOut, Errors.SLIPPAGE_CONTROL);
// check that position's health <= maxHealth
// NOTE: bypass this for underwater position
if (vars.health_e18 != 0) _ensurePosHealthAfterLiq(vars.config, _posId, vars.mode);
emit LiquidateWLp(_posId, msg.sender, _wLp, _tokenId, wLpAmtToBurn);
}
/// @inheritdoc IInitCore
function flash(address[] calldata _pools, uint[] calldata _amts, bytes calldata _data)
public
virtual
nonReentrant
{
// validate _pools and _amts length & validate _pools contain distinct addresses to avoid paying less flash fees
_require(_validateFlash(_pools, _amts), Errors.INVALID_FLASHLOAN);
// check that is not multicall tx
_require(!isMulticallTx, Errors.LOCKED_MULTICALL);
uint[] memory balanceBefores = new uint[](_pools.length);
address[] memory tokens = new address[](_pools.length);
IConfig _config = IConfig(config);
for (uint i; i < _pools.length; i = i.uinc()) {
PoolConfig memory poolConfig = _config.getPoolConfig(_pools[i]);
// check that flash is enabled
_require(poolConfig.canFlash, Errors.FLASH_PAUSED);
address token = ILendingPool(_pools[i]).underlyingToken();
tokens[i] = token;
// calculate return amt
balanceBefores[i] = IERC20(token).balanceOf(_pools[i]);
// take _amts[i] of _pools[i] to msg.sender
IERC20(token).safeTransferFrom(_pools[i], msg.sender, _amts[i]);
}
// execute callback
IFlashReceiver(msg.sender).flashCallback(_pools, _amts, _data);
// check pool balance after callback
for (uint i; i < _pools.length; i = i.uinc()) {
_require(IERC20(tokens[i]).balanceOf(_pools[i]) >= balanceBefores[i], Errors.INVALID_AMOUNT_TO_REPAY);
}
}
/// @dev multicall function with health check after all call
function multicall(bytes[] calldata data) public payable virtual override returns (bytes[] memory results) {
_require(!isMulticallTx, Errors.LOCKED_MULTICALL);
isMulticallTx = true;
// multicall
results = super.multicall(data);
// === loop uncheckedPosIds ===
uint[] memory posIds = uncheckedPosIds.values();
for (uint i; i < posIds.length; i = i.uinc()) {
// check position health
_require(_isPosHealthy(posIds[i]), Errors.POSITION_NOT_HEALTHY);
uncheckedPosIds.remove(posIds[i]);
}
// clear uncheckedPosIds
isMulticallTx = false;
}
/// @inheritdoc IInitCore
function setConfig(address _config) external onlyGovernor {
_setConfig(_config);
}
/// @inheritdoc IInitCore
function setOracle(address _oracle) external onlyGovernor {
_setOracle(_oracle);
}
/// @inheritdoc IInitCore
function setLiqIncentiveCalculator(address _liqIncentiveCalculator) external onlyGuardian {
_setLiqIncentiveCalculator(_liqIncentiveCalculator);
}
/// @inheritdoc IInitCore
function setRiskManager(address _riskManager) external onlyGuardian {
_setRiskManager(_riskManager);
}
/// @dev set config
function _setConfig(address _config) internal {
config = _config;
emit SetConfig(_config);
}
/// @dev set oracle
function _setOracle(address _oracle) internal {
oracle = _oracle;
emit SetOracle(_oracle);
}
/// @dev set liquidation incentive calculator
function _setLiqIncentiveCalculator(address _liqIncentiveCalculator) internal {
liqIncentiveCalculator = _liqIncentiveCalculator;
emit SetIncentiveCalculator(_liqIncentiveCalculator);
}
/// @dev set risk manager
function _setRiskManager(address _riskManager) internal {
riskManager = _riskManager;
emit SetRiskManager(_riskManager);
}
/// @inheritdoc IInitCore
function getCollateralCreditCurrent_e36(uint _posId) public virtual returns (uint collCredit_e36) {
address _oracle = oracle;
IConfig _config = IConfig(config);
uint16 mode = _getPosMode(_posId);
// get position collateral
(address[] memory pools, uint[] memory shares, address[] memory wLps, uint[][] memory ids, uint[][] memory amts)
= IPosManager(POS_MANAGER).getPosCollInfo(_posId);
// calculate collateralCredit
uint collCredit_e54;
for (uint i; i < pools.length; i = i.uinc()) {
address token = ILendingPool(pools[i]).underlyingToken();
uint tokenPrice_e36 = IInitOracle(_oracle).getPrice_e36(token);
uint tokenValue_e36 = ILendingPool(pools[i]).toAmtCurrent(shares[i]) * tokenPrice_e36;
TokenFactors memory factors = _config.getTokenFactors(mode, pools[i]);
collCredit_e54 += tokenValue_e36 * factors.collFactor_e18;
}
for (uint i; i < wLps.length; i = i.uinc()) {
for (uint j; j < ids[i].length; j = j.uinc()) {
uint wLpPrice_e36 = IBaseWrapLp(wLps[i]).calculatePrice_e36(ids[i][j], _oracle);
uint wLpValue_e36 = amts[i][j] * wLpPrice_e36;
TokenFactors memory factors = _config.getTokenFactors(mode, IBaseWrapLp(wLps[i]).lp(ids[i][j]));
collCredit_e54 += wLpValue_e36 * factors.collFactor_e18;
}
}
collCredit_e36 = collCredit_e54 / ONE_E18;
}
/// @inheritdoc IInitCore
function getBorrowCreditCurrent_e36(uint _posId) public virtual returns (uint borrowCredit_e36) {
IConfig _config = IConfig(config);
uint16 mode = _getPosMode(_posId);
// get position debtShares
(address[] memory pools, uint[] memory debtShares) = IPosManager(POS_MANAGER).getPosBorrInfo(_posId);
uint borrowCredit_e54;
address _oracle = oracle;
for (uint i; i < pools.length; i = i.uinc()) {
address token = ILendingPool(pools[i]).underlyingToken();
uint tokenPrice_e36 = IInitOracle(_oracle).getPrice_e36(token);
// calculate position debt
uint tokenValue_e36 = tokenPrice_e36 * ILendingPool(pools[i]).debtShareToAmtCurrent(debtShares[i]);
TokenFactors memory factors = _config.getTokenFactors(mode, pools[i]);
borrowCredit_e54 += (tokenValue_e36 * factors.borrFactor_e18);
}
borrowCredit_e36 = borrowCredit_e54.ceilDiv(ONE_E18);
}
/// @inheritdoc IInitCore
function getPosHealthCurrent_e18(uint _posId) public virtual returns (uint health_e18) {
uint borrowCredit_e36 = getBorrowCreditCurrent_e36(_posId);
health_e18 = borrowCredit_e36 > 0
? (getCollateralCreditCurrent_e36(_posId) * ONE_E18) / borrowCredit_e36
: type(uint).max;
}
/// @inheritdoc IInitCore
function callback(address _to, uint _value, bytes memory _data)
public
payable
virtual
returns (bytes memory result)
{
_require(_to != address(this), Errors.INVALID_CALLBACK_ADDRESS);
// call _to with _data
return ICallbackReceiver(_to).coreCallback{value: _value}(msg.sender, _data);
}
/// @inheritdoc IInitCore
function transferToken(address _token, address _to, uint _amt) public virtual nonReentrant {
// transfer _amt of token to _to from msg.sender
IERC20(_token).safeTransferFrom(msg.sender, _to, _amt);
}
/// @dev repay borrowed tokens
/// @param _config config
/// @param _mode position mode
/// @param _posId position id
/// @param _pool pool address to repay
/// @param _shares amount of shares to repay
/// @return tokenToRepay token address to repay
/// amt amt of token to repay
function _repay(IConfig _config, uint16 _mode, uint _posId, address _pool, uint _shares)
internal
returns (address tokenToRepay, uint amt)
{
// check status
_require(_config.getPoolConfig(_pool).canRepay && _config.getModeStatus(_mode).canRepay, Errors.REPAY_PAUSED);
// get position debt share
uint positionDebtShares = IPosManager(POS_MANAGER).getPosDebtShares(_posId, _pool);
uint sharesToRepay = _shares < positionDebtShares ? _shares : positionDebtShares;
// get amtToRepay (accrue interest)
uint amtToRepay = ILendingPool(_pool).debtShareToAmtCurrent(sharesToRepay);
// take token from msg.sender to pool
tokenToRepay = ILendingPool(_pool).underlyingToken();
IERC20(tokenToRepay).safeTransferFrom(msg.sender, _pool, amtToRepay);
// update debt on the position
IPosManager(POS_MANAGER).updatePosDebtShares(_posId, _pool, -sharesToRepay.toInt256());
// call repay on the pool
amt = ILendingPool(_pool).repay(sharesToRepay);
// update debt on mode
IRiskManager(riskManager).updateModeDebtShares(_mode, _pool, -sharesToRepay.toInt256());
emit Repay(_pool, _posId, msg.sender, sharesToRepay, amt);
}
/// @dev get position mode
function _getPosMode(uint _posId) internal view returns (uint16 mode) {
mode = IPosManager(POS_MANAGER).getPosMode(_posId);
}
/// @dev get whether the position is healthy
function _isPosHealthy(uint _posId) internal returns (bool isHealthy) {
isHealthy = getPosHealthCurrent_e18(_posId) >= ONE_E18;
}
/// @dev validate flash data
function _validateFlash(address[] calldata _pools, uint[] calldata _amts) internal pure returns (bool) {
if (_pools.length != _amts.length) return false;
return AddressArrayLib.isSortedAndNotDuplicate(_pools);
}
/// @dev check that the position health after liquidation does not exceed the threshold
function _ensurePosHealthAfterLiq(IConfig _config, uint _posId, uint16 _mode) internal {
uint healthAfterLiquidation_e18 = _config.getMaxHealthAfterLiq_e18(_mode);
// if healthAfterLiquidation_e18 == uint64.max, then no need to check
if (healthAfterLiquidation_e18 != type(uint64).max) {
_require(
getPosHealthCurrent_e18(_posId) <= healthAfterLiquidation_e18, Errors.INVALID_HEALTH_AFTER_LIQUIDATION
);
}
}
/// @dev liquidation internal logic
function _liquidateInternal(uint _posId, address _poolToRepay, uint _repayShares)
internal
returns (LiquidateLocalVars memory vars)
{
vars.config = IConfig(config);
vars.mode = _getPosMode(_posId);
// check position must be unhealthy
vars.health_e18 = getPosHealthCurrent_e18(_posId);
_require(vars.health_e18 < ONE_E18, Errors.POSITION_HEALTHY);
(vars.repayToken, vars.repayAmt) = _repay(vars.config, vars.mode, _posId, _poolToRepay, _repayShares);
}
}// SPDX-License-Identifier: None
pragma solidity ^0.8.19;
/// @title Access Control Manager Interface
interface IAccessControlManager {
/// @dev check the role of the user, revert against an unauthorized user.
/// @param _role keccak256 hash of role name
/// @param _user user address to check for the role
function checkRole(bytes32 _role, address _user) external;
}pragma solidity ^0.8.19;
/// @title Multicall Interface
/// @notice Enables calling multiple methods in a single call to the contract
interface IMulticall {
/// @notice Call multiple functions in the current contract and return the data from all of them if they all succeed
/// @dev The `msg.value` should not be trusted for any method callable from multicall.
/// @param data The encoded function data for each of the calls to make to this contract
/// @return results The results from each of the calls passed in via data
function multicall(bytes[] calldata data) external payable returns (bytes[] memory results);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
/**
* @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 Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 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 functions marked with `initializer` can be nested in the context of a
* constructor.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_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 255 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_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() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @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 {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized != type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuardUpgradeable is Initializable {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
function __ReentrancyGuard_init() internal onlyInitializing {
__ReentrancyGuard_init_unchained();
}
function __ReentrancyGuard_init_unchained() internal onlyInitializing {
_status = _NOT_ENTERED;
}
/**
* @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 _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @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 _status == _ENTERED;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @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.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @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, it is bubbled up by this
* function (like regular Solidity function calls).
*
* 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.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @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`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) 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
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library MathUpgradeable {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return 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 up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev 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 {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// 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 prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1, "Math: mulDiv overflow");
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates 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) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice 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 + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @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 + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* 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 + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* 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 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @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 + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
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 amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` 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 amount) 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 `amount` 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 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` 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 amount) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 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.
*/
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].
*/
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 v4.9.3) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 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 {
using Address for address;
/**
* @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.encodeWithSelector(token.transfer.selector, 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.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 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.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
/**
* @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.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @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).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
/**
* @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 silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @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.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @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, it is bubbled up by this
* function (like regular Solidity function calls).
*
* 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.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @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`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) 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
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* 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[EIP 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 v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.0;
/**
* @dev Wrappers over Solidity's uintXX/intXX 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.
*
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/
library SafeCast {
/**
* @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
*
* _Available since v4.7._
*/
function toUint248(uint256 value) internal pure returns (uint248) {
require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
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
*
* _Available since v4.7._
*/
function toUint240(uint256 value) internal pure returns (uint240) {
require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
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
*
* _Available since v4.7._
*/
function toUint232(uint256 value) internal pure returns (uint232) {
require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
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
*
* _Available since v4.2._
*/
function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
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
*
* _Available since v4.7._
*/
function toUint216(uint256 value) internal pure returns (uint216) {
require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
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
*
* _Available since v4.7._
*/
function toUint208(uint256 value) internal pure returns (uint208) {
require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
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
*
* _Available since v4.7._
*/
function toUint200(uint256 value) internal pure returns (uint200) {
require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
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
*
* _Available since v4.7._
*/
function toUint192(uint256 value) internal pure returns (uint192) {
require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
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
*
* _Available since v4.7._
*/
function toUint184(uint256 value) internal pure returns (uint184) {
require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
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
*
* _Available since v4.7._
*/
function toUint176(uint256 value) internal pure returns (uint176) {
require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
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
*
* _Available since v4.7._
*/
function toUint168(uint256 value) internal pure returns (uint168) {
require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
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
*
* _Available since v4.7._
*/
function toUint160(uint256 value) internal pure returns (uint160) {
require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
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
*
* _Available since v4.7._
*/
function toUint152(uint256 value) internal pure returns (uint152) {
require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
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
*
* _Available since v4.7._
*/
function toUint144(uint256 value) internal pure returns (uint144) {
require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
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
*
* _Available since v4.7._
*/
function toUint136(uint256 value) internal pure returns (uint136) {
require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
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
*
* _Available since v2.5._
*/
function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
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
*
* _Available since v4.7._
*/
function toUint120(uint256 value) internal pure returns (uint120) {
require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
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
*
* _Available since v4.7._
*/
function toUint112(uint256 value) internal pure returns (uint112) {
require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
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
*
* _Available since v4.7._
*/
function toUint104(uint256 value) internal pure returns (uint104) {
require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
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
*
* _Available since v4.2._
*/
function toUint96(uint256 value) internal pure returns (uint96) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
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
*
* _Available since v4.7._
*/
function toUint88(uint256 value) internal pure returns (uint88) {
require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
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
*
* _Available since v4.7._
*/
function toUint80(uint256 value) internal pure returns (uint80) {
require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
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
*
* _Available since v4.7._
*/
function toUint72(uint256 value) internal pure returns (uint72) {
require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
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
*
* _Available since v2.5._
*/
function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
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
*
* _Available since v4.7._
*/
function toUint56(uint256 value) internal pure returns (uint56) {
require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
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
*
* _Available since v4.7._
*/
function toUint48(uint256 value) internal pure returns (uint48) {
require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
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
*
* _Available since v4.7._
*/
function toUint40(uint256 value) internal pure returns (uint40) {
require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
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
*
* _Available since v2.5._
*/
function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
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
*
* _Available since v4.7._
*/
function toUint24(uint256 value) internal pure returns (uint24) {
require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
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
*
* _Available since v2.5._
*/
function toUint16(uint256 value) internal pure returns (uint16) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
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
*
* _Available since v2.5._
*/
function toUint8(uint256 value) internal pure returns (uint8) {
require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*
* _Available since v3.0._
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
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
*
* _Available since v4.7._
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
}
/**
* @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
*
* _Available since v3.1._
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
}
/**
* @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
*
* _Available since v3.1._
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
}
/**
* @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
*
* _Available since v3.1._
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
}
/**
* @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
*
* _Available since v3.1._
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
}
/**
* @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
*
* _Available since v3.1._
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*
* _Available since v3.0._
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
return int256(value);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.0;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```solidity
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping(bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
if (lastIndex != toDeleteIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastValue;
// Update the index for the moved value
set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.19;
import '../interfaces/common/IMulticall.sol';
import '../common/library/UncheckedIncrement.sol';
/// NOTE: from https://github.com/Uniswap/v3-periphery/blob/main/contracts/base/Multicall.sol
/// @title Multicall
/// @notice Enables calling multiple methods in a single call to the contract
abstract contract Multicall is IMulticall {
using UncheckedIncrement for uint;
/// @inheritdoc IMulticall
function multicall(bytes[] calldata data) public payable virtual override returns (bytes[] memory results) {
results = new bytes[](data.length);
for (uint i; i < data.length; i = i.uinc()) {
(bool success, bytes memory result) = address(this).delegatecall(data[i]);
if (!success) {
// Next 5 lines from https://ethereum.stackexchange.com/a/83577
if (result.length < 68) revert();
assembly {
result := add(result, 0x04)
}
revert(abi.decode(result, (string)));
}
results[i] = result;
}
}
}// SPDX-License-Identifier: None
pragma solidity ^0.8.19;
import {IAccessControlManager} from '../interfaces/common/IAccessControlManager.sol';
abstract contract UnderACM {
// immutables
IAccessControlManager public immutable ACM; // access control manager
// constructor
constructor(address _acm) {
ACM = IAccessControlManager(_acm);
}
}// SPDX-License-Identifier: None
pragma solidity ^0.8.19;
import './UncheckedIncrement.sol';
library AddressArrayLib {
using UncheckedIncrement for uint;
/// @dev check that the array is sorted and has no duplicate
/// @param _arr the array to be checked
function isSortedAndNotDuplicate(address[] calldata _arr) internal pure returns (bool) {
uint poolLen = _arr.length;
for (uint i = 1; i < poolLen; i = i.uinc()) {
if (_arr[i - 1] >= _arr[i]) return false;
}
return true;
}
}// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.1 <0.9.0;
// solhint-disable
/**
* @dev Reverts if `condition` is false, with a revert reason containing `errorCode`. Only codes up to 999 are
* supported.
* Uses the default 'INC' prefix for the error code
*/
function _require(bool condition, uint errorCode) pure {
if (!condition) _revert(errorCode);
}
/**
* @dev Reverts if `condition` is false, with a revert reason containing `errorCode`. Only codes up to 999 are
* supported.
*/
function _require(bool condition, uint errorCode, bytes3 prefix) pure {
if (!condition) _revert(errorCode, prefix);
}
/**
* @dev Reverts with a revert reason containing `errorCode`. Only codes up to 999 are supported.
* Uses the default 'INC' prefix for the error code
*/
function _revert(uint errorCode) pure {
_revert(errorCode, 0x494e43); // This is the raw byte representation of "INC"
}
/**
* @dev Reverts with a revert reason containing `errorCode`. Only codes up to 999 are supported.
*/
function _revert(uint errorCode, bytes3 prefix) pure {
uint prefixUint = uint(uint24(prefix));
// We're going to dynamically create a revert string based on the error code, with the following format:
// 'INC#{errorCode}'
// where the code is left-padded with zeroes to three digits (so they range from 000 to 999).
//
// We don't have revert strings embedded in the contract to save bytecode size: it takes much less space to store a
// number (8 to 16 bits) than the individual string characters.
//
// The dynamic string creation algorithm that follows could be implemented in Solidity, but assembly allows for a
// much denser implementation, again saving bytecode size. Given this function unconditionally reverts, this is a
// safe place to rely on it without worrying about how its usage might affect e.g. memory contents.
assembly {
// First, we need to compute the ASCII representation of the error code. We assume that it is in the 0-999
// range, so we only need to convert three digits. To convert the digits to ASCII, we add 0x30, the value for
// the '0' character.
let units := add(mod(errorCode, 10), 0x30)
errorCode := div(errorCode, 10)
let tenths := add(mod(errorCode, 10), 0x30)
errorCode := div(errorCode, 10)
let hundreds := add(mod(errorCode, 10), 0x30)
// With the individual characters, we can now construct the full string.
// We first append the '#' character (0x23) to the prefix. In the case of 'INC', it results in 0x42414c23 ('INC#')
// Then, we shift this by 24 (to provide space for the 3 bytes of the error code), and add the
// characters to it, each shifted by a multiple of 8.
// The revert reason is then shifted left by 200 bits (256 minus the length of the string, 7 characters * 8 bits
// per character = 56) to locate it in the most significant part of the 256 slot (the beginning of a byte
// array).
let formattedPrefix := shl(24, add(0x23, shl(8, prefixUint)))
let revertReason := shl(200, add(formattedPrefix, add(add(units, shl(8, tenths)), shl(16, hundreds))))
// We can now encode the reason in memory, which can be safely overwritten as we're about to revert. The encoded
// message will have the following layout:
// [ revert reason identifier ] [ string location offset ] [ string length ] [ string contents ]
// The Solidity revert reason identifier is 0x08c739a0, the function selector of the Error(string) function. We
// also write zeroes to the next 28 bytes of memory, but those are about to be overwritten.
mstore(0x0, 0x08c379a000000000000000000000000000000000000000000000000000000000)
// Next is the offset to the location of the string, which will be placed immediately after (20 bytes away).
mstore(0x04, 0x0000000000000000000000000000000000000000000000000000000000000020)
// The string length is fixed: 7 characters.
mstore(0x24, 7)
// Finally, the string itself is stored.
mstore(0x44, revertReason)
// Even if the string is only 7 bytes long, we need to return a full 32 byte slot containing it. The length of
// the encoded message is therefore 4 + 32 + 32 + 32 = 100.
revert(0, 100)
}
}
library Errors {
// Common
uint internal constant ZERO_VALUE = 100;
uint internal constant NOT_INIT_CORE = 101;
uint internal constant SLIPPAGE_CONTROL = 102;
uint internal constant CALL_FAILED = 103;
uint internal constant NOT_OWNER = 104;
uint internal constant NOT_WNATIVE = 105;
uint internal constant ALREADY_SET = 106;
uint internal constant NOT_WHITELISTED = 107;
// Input
uint internal constant ARRAY_LENGTH_MISMATCHED = 200;
uint internal constant INPUT_TOO_LOW = 201;
uint internal constant INPUT_TOO_HIGH = 202;
uint internal constant INVALID_INPUT = 203;
uint internal constant INVALID_TOKEN_IN = 204;
uint internal constant INVALID_TOKEN_OUT = 205;
uint internal constant NOT_SORTED_OR_DUPLICATED_INPUT = 206;
// Core
uint internal constant POSITION_NOT_HEALTHY = 300;
uint internal constant POSITION_NOT_FOUND = 301;
uint internal constant LOCKED_MULTICALL = 302;
uint internal constant POSITION_HEALTHY = 303;
uint internal constant INVALID_HEALTH_AFTER_LIQUIDATION = 304;
uint internal constant FLASH_PAUSED = 305;
uint internal constant INVALID_FLASHLOAN = 306;
uint internal constant NOT_AUTHORIZED = 307;
uint internal constant INVALID_CALLBACK_ADDRESS = 308;
// Lending Pool
uint internal constant MINT_PAUSED = 400;
uint internal constant REDEEM_PAUSED = 401;
uint internal constant BORROW_PAUSED = 402;
uint internal constant REPAY_PAUSED = 403;
uint internal constant NOT_ENOUGH_CASH = 404;
uint internal constant INVALID_AMOUNT_TO_REPAY = 405;
uint internal constant SUPPLY_CAP_REACHED = 406;
uint internal constant BORROW_CAP_REACHED = 407;
// Config
uint internal constant INVALID_MODE = 500;
uint internal constant TOKEN_NOT_WHITELISTED = 501;
uint internal constant INVALID_FACTOR = 502;
// Position Manager
uint internal constant COLLATERALIZE_PAUSED = 600;
uint internal constant DECOLLATERALIZE_PAUSED = 601;
uint internal constant MAX_COLLATERAL_COUNT_REACHED = 602;
uint internal constant NOT_CONTAIN = 603;
uint internal constant ALREADY_COLLATERALIZED = 604;
// Oracle
uint internal constant NO_VALID_SOURCE = 700;
uint internal constant TOO_MUCH_DEVIATION = 701;
uint internal constant MAX_PRICE_DEVIATION_TOO_LOW = 702;
uint internal constant NO_PRICE_ID = 703;
uint internal constant PYTH_CONFIG_NOT_SET = 704;
uint internal constant DATAFEED_ID_NOT_SET = 705;
uint internal constant MAX_STALETIME_NOT_SET = 706;
uint internal constant MAX_STALETIME_EXCEEDED = 707;
uint internal constant PRIMARY_SOURCE_NOT_SET = 708;
// Risk Manager
uint internal constant DEBT_CEILING_EXCEEDED = 800;
// Misc
uint internal constant UNIMPLEMENTED = 999;
}// SPDX-License-Identifier: None
pragma solidity ^0.8.19;
library UncheckedIncrement {
function uinc(uint self) internal pure returns (uint) {
unchecked {
return self + 1;
}
}
}// SPDX-License-Identifier: None
pragma solidity ^0.8.19;
import {EnumerableSet} from '@openzeppelin-contracts/utils/structs/EnumerableSet.sol';
// structs
struct TokenFactors {
uint128 collFactor_e18; // collateral factor in 1e18 (1e18 = 100%)
uint128 borrFactor_e18; // borrow factor in 1e18 (1e18 = 100%)
}
struct ModeConfig {
EnumerableSet.AddressSet collTokens; // enumerable set of collateral tokens
EnumerableSet.AddressSet borrTokens; // enumerable set of borrow tokens
uint64 maxHealthAfterLiq_e18; // max health factor allowed after liquidation
mapping(address => TokenFactors) factors; // token factors mapping
ModeStatus status; // mode status
}
struct PoolConfig {
uint128 supplyCap; // pool supply cap
uint128 borrowCap; // pool borrow cap
bool canMint; // pool mint status
bool canBurn; // pool burn status
bool canBorrow; // pool borrow status
bool canRepay; // pool repay status
bool canFlash; // pool flash status
}
struct ModeStatus {
bool canCollateralize; // mode collateralize status
bool canDecollateralize; // mode decollateralize status
bool canBorrow; // mode borrow status
bool canRepay; // mode repay status
}
/// @title Config Interface
/// @notice Configuration parameters for the protocol.
interface IConfig {
event SetPoolConfig(address indexed pool, PoolConfig config);
event SetCollFactors_e18(uint16 indexed mode, address[] tokens, uint128[] _factors);
event SetBorrFactors_e18(uint16 indexed mode, address[] tokens, uint128[] factors);
event SetMaxHealthAfterLiq_e18(uint16 indexed mode, uint64 maxHealthAfterLiq_e18);
event SetWhitelistedWLps(address[] wLps, bool status);
event SetModeStatus(uint16 mode, ModeStatus status);
/// @dev check if the wrapped lp is whitelisted.
/// @param _wlp wrapped lp address
/// @return whether the wrapped lp is whitelisted.
function whitelistedWLps(address _wlp) external view returns (bool);
/// @dev get mode config
/// @param _mode mode id
/// @return collTokens collateral token list
/// borrTokens borrow token list
/// maxHealthAfterLiq_e18 max health factor allowed after liquidation
function getModeConfig(uint16 _mode)
external
view
returns (address[] memory collTokens, address[] memory borrTokens, uint maxHealthAfterLiq_e18);
/// @dev get pool config
/// @param _pool pool address
/// @return poolConfig pool config
function getPoolConfig(address _pool) external view returns (PoolConfig memory poolConfig);
/// @dev check if the pool within the specified mode is allowed for borrowing.
/// @param _mode mode id
/// @param _pool lending pool address
/// @return whether the pool within the mode is allowed for borrowing.
function isAllowedForBorrow(uint16 _mode, address _pool) external view returns (bool);
/// @dev check if the pool within the specified mode is allowed for collateralizing.
/// @param _mode mode id
/// @param _pool lending pool address
/// @return whether the pool within the mode is allowed for collateralizing.
function isAllowedForCollateral(uint16 _mode, address _pool) external view returns (bool);
/// @dev get the token factors (collateral and borrow factors)
/// @param _mode mode id
/// @param _pool lending pool address
/// @return tokenFactors token factors
function getTokenFactors(uint16 _mode, address _pool) external view returns (TokenFactors memory tokenFactors);
/// @notice if return the value of type(uint64).max, skip the health check after liquidation
/// @dev get the mode max health allowed after liquidation
/// @param _mode mode id
/// @param maxHealthAfterLiq_e18 max allowed health factor after liquidation
function getMaxHealthAfterLiq_e18(uint16 _mode) external view returns (uint maxHealthAfterLiq_e18);
/// @dev get the current mode status
/// @param _mode mode id
/// @return modeStatus mode status (collateralize, decollateralize, borrow or repay)
function getModeStatus(uint16 _mode) external view returns (ModeStatus memory modeStatus);
/// @dev set pool config
/// @param _pool lending pool address
/// @param _config new pool config
function setPoolConfig(address _pool, PoolConfig calldata _config) external;
/// @dev set pool collateral factors
/// @param _pools lending pool address list
/// @param _factors new collateral factor list in 1e18 (1e18 = 100%)
function setCollFactors_e18(uint16 _mode, address[] calldata _pools, uint128[] calldata _factors) external;
/// @dev set pool borrow factors
/// @param _pools lending pool address list
/// @param _factors new borrow factor list in 1e18 (1e18 = 100%)
function setBorrFactors_e18(uint16 _mode, address[] calldata _pools, uint128[] calldata _factors) external;
/// @dev set mode status
/// @param _status new mode status to set to (collateralize, decollateralize, borrow and repay)
function setModeStatus(uint16 _mode, ModeStatus calldata _status) external;
/// @notice only governor role can call
/// @dev set whitelisted wrapped lp statuses
/// @param _wLps wrapped lp list
/// @param _status whitelisted status to set to
function setWhitelistedWLps(address[] calldata _wLps, bool _status) external;
/// @dev set max health after liquidation (type(uint64).max means infinite, or no check)
/// @param _mode mode id
/// @param _maxHealthAfterLiq_e18 new max allowed health factor after liquidation
function setMaxHealthAfterLiq_e18(uint16 _mode, uint64 _maxHealthAfterLiq_e18) external;
}// SPDX-License-Identifier: None
pragma solidity ^0.8.19;
import './IConfig.sol';
/// @title InitCore Interface
interface IInitCore {
event SetConfig(address indexed newConfig);
event SetOracle(address indexed newOracle);
event SetIncentiveCalculator(address indexed newIncentiveCalculator);
event SetRiskManager(address indexed newRiskManager);
event Borrow(address indexed pool, uint indexed posId, address indexed to, uint borrowAmt, uint shares);
event Repay(address indexed pool, uint indexed posId, address indexed repayer, uint shares, uint amtToRepay);
event CreatePosition(address indexed owner, uint indexed posId, uint16 mode, address viewer);
event SetPositionMode(uint indexed posId, uint16 mode);
event Collateralize(uint indexed posId, address indexed pool, uint amt);
event Decollateralize(uint indexed posId, address indexed pool, address indexed to, uint amt);
event CollateralizeWLp(address indexed wLp, uint indexed tokenId, uint indexed posId, uint amt);
event Decollateralize(address indexed wLp, uint indexed posId, address indexed to, uint amt);
event Liquidate(uint indexed posId, address indexed liquidator, address poolOut, uint shares);
event LiquidateWLp(uint indexed posId, address indexed liquidator, address wLpOut, uint tokenId, uint amt);
struct LiquidateLocalVars {
IConfig config;
uint16 mode;
uint health_e18;
uint liqIncentive_e18;
address collToken;
address repayToken;
uint repayAmt;
uint repayAmtWithLiqIncentive;
}
/// @dev get position manager address
function POS_MANAGER() external view returns (address);
/// @dev get config address
function config() external view returns (address);
/// @dev get oracle address
function oracle() external view returns (address);
/// @dev get risk manager address
function riskManager() external view returns (address);
/// @dev get liquidation incentive calculator address
function liqIncentiveCalculator() external view returns (address);
/// @dev mint lending pool shares (using ∆balance in lending pool)
/// @param _pool lending pool address
/// @param _to address to receive share token
/// @return shares amount of share tokens minted
function mintTo(address _pool, address _to) external returns (uint shares);
/// @dev burn lending pool share tokens to receive underlying (using ∆balance in lending pool)
/// @param _pool lending pool address
/// @param _to address to receive underlying
/// @return amt amount of underlying to receive
function burnTo(address _pool, address _to) external returns (uint amt);
/// @dev borrow underlying from lending pool
/// @param _pool lending pool address
/// @param _amt amount of underlying to borrow
/// @param _posId position id to account for the borrowing
/// @param _to address to receive borrow underlying
/// @return shares the amount of debt shares for the borrowing
function borrow(address _pool, uint _amt, uint _posId, address _to) external returns (uint shares);
/// @dev repay debt to the lending pool
/// @param _pool address of lending pool
/// @param _shares debt shares to repay
/// @param _posId position id to repay debt
/// @return amt amount of underlying to repaid
function repay(address _pool, uint _shares, uint _posId) external returns (uint amt);
/// @dev create a new position
/// @param _mode position mode
/// @param _viewer position viewer address
function createPos(uint16 _mode, address _viewer) external returns (uint posId);
/// @dev change a position's mode
/// @param _posId position id to change mode
/// @param _mode position mode to change to
function setPosMode(uint _posId, uint16 _mode) external;
/// @dev collateralize lending pool share tokens to position
/// @param _posId position id to collateralize to
/// @param _pool lending pool address
function collateralize(uint _posId, address _pool) external;
/// @notice need to check the position's health after decollateralization
/// @dev decollateralize lending pool share tokens from the position
/// @param _posId position id to decollateral
/// @param _pool lending pool address
/// @param _shares amount of share tokens to decollateralize
/// @param _to address to receive token
function decollateralize(uint _posId, address _pool, uint _shares, address _to) external;
/// @dev collateralize wlp to position
/// @param _posId position id to collateralize to
/// @param _wLp wlp token address
/// @param _tokenId token id of wlp token to collateralize
function collateralizeWLp(uint _posId, address _wLp, uint _tokenId) external;
/// @notice need to check position's health after decollateralization
/// @dev decollateralize wlp from the position
/// @param _posId position id to decollateralize
/// @param _wLp wlp token address
/// @param _tokenId token id of wlp token to decollateralize
/// @param _amt amount of wlp token to decollateralize
function decollateralizeWLp(uint _posId, address _wLp, uint _tokenId, uint _amt, address _to) external;
/// @notice need to check position's health before liquidate & limit health after liqudate
/// @dev (partial) liquidate the position
/// @param _posId position id to liquidate
/// @param _poolToRepay address of lending pool to liquidate
/// @param _repayShares debt shares to repay
/// @param _tokenOut pool token to receive for the liquidation
/// @param _minShares min amount of pool token to receive after liquidate (slippage control)
/// @return amt the token amount out actually transferred out
function liquidate(uint _posId, address _poolToRepay, uint _repayShares, address _tokenOut, uint _minShares)
external
returns (uint amt);
/// @notice need to check position's health before liquidate & limit health after liqudate
/// @dev (partial) liquidate the position
/// @param _posId position id to liquidate
/// @param _poolToRepay address of lending pool to liquidate
/// @param _repayShares debt shares to liquidate
/// @param _wLp wlp to unwrap for liquidation
/// @param _tokenId wlp token id to burn for liquidation
/// @param _minLpOut min amount of lp to receive for liquidation
/// @return amt the token amount out actually transferred out
function liquidateWLp(
uint _posId,
address _poolToRepay,
uint _repayShares,
address _wLp,
uint _tokenId,
uint _minLpOut
) external returns (uint amt);
/// @notice caller must implement `flashCallback` function
/// @dev flashloan underlying tokens from lending pool
/// @param _pools lending pool address list to flashloan from
/// @param _amts token amount list to flashloan
/// @param _data data to execute in the callback function
function flash(address[] calldata _pools, uint[] calldata _amts, bytes calldata _data) external;
/// @dev make a callback to the target contract
/// @param _to target address to receive callback
/// @param _value msg.value to pass on to the callback
/// @param _data data to execute callback function
/// @return result callback result
function callback(address _to, uint _value, bytes calldata _data) external payable returns (bytes memory result);
/// @notice this is NOT a view function
/// @dev get current position's collateral credit in 1e36 (interest accrued up to current timestamp)
/// @param _posId position id to get collateral credit for
/// @return credit current position collateral credit
function getCollateralCreditCurrent_e36(uint _posId) external returns (uint credit);
/// @dev get current position's borrow credit in 1e36 (interest accrued up to current timestamp)
/// @param _posId position id to get borrow credit for
/// @return credit current position borrow credit
function getBorrowCreditCurrent_e36(uint _posId) external returns (uint credit);
/// @dev get current position's health factor in 1e18 (interest accrued up to current timestamp)
/// @param _posId position id to get health factor
/// @return health current position health factor
function getPosHealthCurrent_e18(uint _posId) external returns (uint health);
/// @dev set new config
function setConfig(address _config) external;
/// @dev set new oracle
function setOracle(address _oracle) external;
/// @dev set new liquidation incentve calculator
function setLiqIncentiveCalculator(address _liqIncentiveCalculator) external;
/// @dev set new risk manager
function setRiskManager(address _riskManager) external;
/// @dev transfer token from msg.sender to the target address
/// @param _token token address to transfer
/// @param _to address to receive token
/// @param _amt amount of token to transfer
function transferToken(address _token, address _to, uint _amt) external;
}// SPDX-License-Identifier: None
pragma solidity ^0.8.19;
/// @title Liquidation Incentive Calculator Interface
interface ILiqIncentiveCalculator {
event SetModeLiqIncentiveMultiplier_e18(uint16[] modes, uint[] multipliers_e18);
event SetTokenLiqIncentiveMultiplier_e18(address[] tokens, uint[] multipliers_e18);
event SetMaxLiqIncentiveMultiplier_e18(uint maxIncentiveMultiplier_e18);
event SetMinLiqIncentiveMultiplier_e18(uint16[] modes, uint[] minIncentiveMultipliers_e18);
/// @notice the minimum capped value for the liquidation incentive multiplier
/// @dev get the min incentive multiplier
/// @dev _mode position mode
/// @return minLiqIncentiveMultiplier_e18 min incentive multiplier in 1e18
function minLiqIncentiveMultiplier_e18(uint16 _mode) external returns (uint minLiqIncentiveMultiplier_e18);
/// @notice the maximum capped value for the liquidation incentive multiplier
/// @dev get the max incentive multiplier
/// @return maxLiqIncentiveMultiplier_e18 max incentive multiplier in 1e18
function maxLiqIncentiveMultiplier_e18() external returns (uint maxLiqIncentiveMultiplier_e18);
/// @dev get the mode liquidation incentive multiplier
/// @param _mode position mode
/// @return modeLiqIncentiveMultiplier_e18 mode incentive multiplier in 1e18
function modeLiqIncentiveMultiplier_e18(uint16 _mode) external returns (uint modeLiqIncentiveMultiplier_e18);
/// @dev get the liquidation incentive multiplier for the token
/// @param _token token address
/// @return tokenLiqIncentiveMultiplier_e18 token incentive multiplier in 1e18
function tokenLiqIncentiveMultiplier_e18(address _token) external returns (uint tokenLiqIncentiveMultiplier_e18);
/// @dev calculate the liquidation incentive multiplier, given the position's mode, health factor and repay and collateral tokens
/// @param _mode position mode
/// @param _healthFactor_e18 position current health factor in 1e18
/// @param _repayToken repay token's underlying
/// @param _collToken receive token's underlying
/// @return multiplier_e18 liquidation incentive multiplier in 1e18
function getLiqIncentiveMultiplier_e18(
uint16 _mode,
uint _healthFactor_e18,
address _repayToken,
address _collToken
) external view returns (uint multiplier_e18);
/// @dev set the liquidation incentive multipliers for position modes
/// @param _modes position mode id list
/// @param _multipliers_e18 new mode liquidation incentive multiplier list in 1e18 to set to
function setModeLiqIncentiveMultiplier_e18(uint16[] calldata _modes, uint[] calldata _multipliers_e18) external;
/// @dev set the liquidation incentive multipliers for tokens
/// @param _tokens token list
/// @param _multipliers_e18 new token liquidation incentive multiplier list in 1e18 to set to
function setTokenLiqIncentiveMultiplier_e18(address[] calldata _tokens, uint[] calldata _multipliers_e18)
external;
/// @dev set the max liquidation incentive multiplier
/// @param _maxLiqIncentiveMultiplier_e18 new max liquidation incentive multiplier in 1e18
function setMaxLiqIncentiveMultiplier_e18(uint _maxLiqIncentiveMultiplier_e18) external;
/// @dev set the min liquidation incentive multiplier
/// @param _modes position mode id list
/// @param _minMultipliers_e18 new min liquidation incentive multiplier in 1e18
function setMinLiqIncentiveMultiplier_e18(uint16[] calldata _modes, uint[] calldata _minMultipliers_e18) external;
}// SPDX-License-Identifier: None
pragma solidity ^0.8.19;
import {EnumerableSet} from '@openzeppelin-contracts/utils/structs/EnumerableSet.sol';
/// @title Position Interface
interface IPosManager {
event SetMaxCollCount(uint maxCollCount);
struct PosInfo {
address viewer; // viewer address
uint16 mode; // position mode
}
// NOTE: extra info for hooks (not used in core)
struct PosBorrExtraInfo {
uint128 totalInterest; // total accrued interest since the position is created
uint128 lastDebtAmt; // position's debt amount after the last interaction
}
struct PosCollInfo {
EnumerableSet.AddressSet collTokens; // enumerable set of collateral tokens
mapping(address => uint) collAmts; // collateral token to collateral amts mapping
EnumerableSet.AddressSet wLps; // enumerable set of collateral wlps
mapping(address => EnumerableSet.UintSet) ids; // wlp address to enumerable set of ids mapping
uint8 collCount; // current collateral count
}
struct PosBorrInfo {
EnumerableSet.AddressSet pools; // enumerable set of borrow tokens
mapping(address => uint) debtShares; // debt token to debt shares mapping
mapping(address => PosBorrExtraInfo) borrExtraInfos; // debt token to extra info mapping
}
/// @dev get the next nonce of the owner for calculating the next position id
/// @param _owner the position owner
/// @return nextNonce the next nonce of the position owner
function nextNonces(address _owner) external view returns (uint nextNonce);
/// @dev get core address
function core() external view returns (address core);
/// @dev get pending reward token amts for the pos id
/// @param _posId pos id
/// @param _rewardToken reward token
/// @return amt reward token amt
function pendingRewards(uint _posId, address _rewardToken) external view returns (uint amt);
/// @dev get whether the wlp is already collateralized to a position
/// @param _wLp wlp address
/// @param _tokenId wlp token id
/// @return whether the wlp is already collateralized to a position
function isCollateralized(address _wLp, uint _tokenId) external view returns (bool);
/// @dev get the position borrowed info (excluding the extra info)
/// @param _posId position id
/// @return pools the borrowed pool list
/// debtShares the debt shares list of the borrowed pools
function getPosBorrInfo(uint _posId) external view returns (address[] memory pools, uint[] memory debtShares);
/// @dev get the position borrowed extra info
/// @param _posId position id
/// @param _pool borrowed pool address
/// @return totalInterest total accrued interest since the position is created
/// lastDebtAmt position's debt amount after the last interaction
function getPosBorrExtraInfo(uint _posId, address _pool)
external
view
returns (uint totalInterest, uint lastDebtAmt);
/// @dev get the position collateral info
/// @param _posId position id
/// @return pools the collateral pool adddres list
/// amts collateral amts of the collateral pools
/// wLps the collateral wlp list
/// ids the ids of the collateral wlp list
/// wLpAmts the amounts of the collateral wlp list
function getPosCollInfo(uint _posId)
external
view
returns (
address[] memory pools,
uint[] memory amts,
address[] memory wLps,
uint[][] memory ids,
uint[][] memory wLpAmts
);
/// @dev get pool's collateral amount for the position
/// @param _posId position id
/// @param _pool collateral pool address
/// @return amt collateral amount
function getCollAmt(uint _posId, address _pool) external view returns (uint amt);
/// @dev get wrapped lp collateral amount for the position
/// @param _posId position id
/// @param _wLp collateral wlp address
/// @param _tokenId collateral wlp token id
/// @return amt collateral amount
function getCollWLpAmt(uint _posId, address _wLp, uint _tokenId) external view returns (uint amt);
/// @dev get position info
/// @param _posId position id
/// @return viewerAddress position's viewer address
/// mode position's mode
function getPosInfo(uint _posId) external view returns (address viewerAddress, uint16 mode);
/// @dev get position mode
/// @param _posId position id
/// @return mode position's mode
function getPosMode(uint _posId) external view returns (uint16 mode);
/// @dev get pool's debt shares for the position
/// @param _posId position id
/// @param _pool lending pool address
/// @return debtShares debt shares
function getPosDebtShares(uint _posId, address _pool) external view returns (uint debtShares);
/// @dev get pos id at index corresponding to the viewer address (reverse mapping)
/// @param _viewer viewer address
/// @param _index index
/// @return posId pos id
function getViewerPosIdsAt(address _viewer, uint _index) external view returns (uint posId);
/// @dev get pos id length corresponding to the viewer address (reverse mapping)
/// @param _viewer viewer address
/// @return length pos ids length
function getViewerPosIdsLength(address _viewer) external view returns (uint length);
/// @notice only core can call this function
/// @dev update pool's debt share
/// @param _posId position id
/// @param _pool lending pool address
/// @param _debtShares new debt shares
function updatePosDebtShares(uint _posId, address _pool, int _debtShares) external;
/// @notice only core can call this function
/// @dev update position mode
/// @param _posId position id
/// @param _mode new position mode to set to
function updatePosMode(uint _posId, uint16 _mode) external;
/// @notice only core can call this function
/// @dev add lending pool share as collateral to the position
/// @param _posId position id
/// @param _pool lending pool address
/// @return amtIn pool's share collateral amount added to the position
function addCollateral(uint _posId, address _pool) external returns (uint amtIn);
/// @notice only core can call this function
/// @dev add wrapped lp share as collateral to the position
/// @param _posId position id
/// @param _wLp wlp address
/// @param _tokenId wlp token id
/// @return amtIn wlp collateral amount added to the position
function addCollateralWLp(uint _posId, address _wLp, uint _tokenId) external returns (uint amtIn);
/// @notice only core can call this function
/// @dev remove lending pool share from the position
/// @param _posId position id
/// @param _pool lending pool address
/// @param _receiver address to receive the shares
/// @return amtOut pool's share collateral amount removed from the position
function removeCollateralTo(uint _posId, address _pool, uint _shares, address _receiver)
external
returns (uint amtOut);
/// @notice only core can call this function
/// @dev remove wlp from the position
/// @param _posId position id
/// @param _wLp wlp address
/// @param _tokenId wlp token id
/// @param _amt wlp token amount to remove
/// @return amtOut wlp collateral amount removed from the position
function removeCollateralWLpTo(uint _posId, address _wLp, uint _tokenId, uint _amt, address _receiver)
external
returns (uint amtOut);
/// @notice only core can call this function
/// @dev create a new position
/// @param _owner position owner
/// @param _mode position mode
/// @param _viewer position viewer
/// @return posId position id
function createPos(address _owner, uint16 _mode, address _viewer) external returns (uint posId);
/// @dev harvest rewards from the wlp token
/// @param _posId position id
/// @param _wlp wlp address
/// @param _tokenId id of the wlp token
/// @param _to address to receive the rewards
/// @return tokens token address list harvested
/// amts token amt list harvested
function harvestTo(uint _posId, address _wlp, uint _tokenId, address _to)
external
returns (address[] memory tokens, uint[] memory amts);
/// @notice When removing the wrapped LP collateral, the rewards are harvested to the position manager
/// before unwrapping the LP and sending it to the user
/// @dev claim pending reward pending in the position manager
/// @param _posId position id
/// @param _tokens token address list to claim pending reward
/// @param _to address to receive the pending rewards
/// @return amts amount of each reward tokens claimed
function claimPendingRewards(uint _posId, address[] calldata _tokens, address _to)
external
returns (uint[] memory amts);
/// @notice authorized account could be the owner or approved addresses
/// @dev check if the accoount is authorized for the position
/// @param _account account address to check
/// @param _posId position id
/// @return whether the account is authorized to manage the position
function isAuthorized(address _account, uint _posId) external view returns (bool);
/// @notice only guardian can call this function
/// @dev set the max number of the different collateral count (to avoid out-of-gas error)
/// @param _maxCollCount new max collateral count
function setMaxCollCount(uint8 _maxCollCount) external;
/// @notice only position owner can call this function
/// @dev set new position viewer for pos id
/// @param _posId pos id
/// @param _viewer new viewer address
function setPosViewer(uint _posId, address _viewer) external;
}// SPDX-License-Identifier: None
pragma solidity ^0.8.19;
/// @title Lending Pool Interface
/// @notice rebase token is not supported
interface ILendingPool {
event SetIrm(address _irm);
event SetReserveFactor_e18(uint _reserveFactor_e18);
event SetTreasury(address _treasury);
/// @dev get core address
function core() external view returns (address core);
/// @dev get the interest rate model address
function irm() external view returns (address model);
/// @dev get the reserve factor in 1e18 (1e18 = 100%)
function reserveFactor_e18() external view returns (uint factor_e18);
/// @dev get the pool's underlying token
function underlyingToken() external view returns (address token);
/// @notice total assets = cash + total debts
function totalAssets() external view returns (uint amt);
/// @dev get the pool total debt (underlying token)
function totalDebt() external view returns (uint debt);
/// @dev get the pool total debt shares
function totalDebtShares() external view returns (uint shares);
/// @dev calaculate the debt share from debt amount (without interest accrual)
/// @param _amt the amount of debt
/// @return shares amount of debt shares (rounded up)
function debtAmtToShareStored(uint _amt) external view returns (uint shares);
/// @dev calaculate the debt share from debt amount (with interest accrual)
/// @param _amt the amount of debt
/// @return shares current amount of debt shares (rounded up)
function debtAmtToShareCurrent(uint _amt) external returns (uint shares);
/// @dev calculate the corresponding debt amount from debt share (without interest accrual)
/// @param _shares the amount of debt shares
/// @return amt corresponding debt amount (rounded up)
function debtShareToAmtStored(uint _shares) external view returns (uint amt);
/// @notice this is NOT a view function
/// @dev calculate the corresponding debt amount from debt share (with interest accrual)
/// @param _shares the amount of debt shares
/// @return amt corresponding current debt amount (rounded up)
function debtShareToAmtCurrent(uint _shares) external returns (uint amt);
/// @dev get current supply rate per sec in 1e18
function getSupplyRate_e18() external view returns (uint supplyRate_e18);
/// @dev get current borrow rate per sec in 1e18
function getBorrowRate_e18() external view returns (uint borrowRate_e18);
/// @dev get the pool total cash (underlying token)
function cash() external view returns (uint amt);
/// @dev get the latest timestamp of interest accrual
/// @return lastAccruedTime last accrued time unix timestamp
function lastAccruedTime() external view returns (uint lastAccruedTime);
/// @dev get the treasury address
function treasury() external view returns (address treasury);
/// @notice only core can call this function
/// @dev mint shares to the receiver from the transfered assets
/// @param _receiver address to receive shares
/// @return mintShares amount of shares minted
function mint(address _receiver) external returns (uint mintShares);
/// @notice only core can call this function
/// @dev burn shares and send the underlying assets to the receiver
/// @param _receiver address to receive the underlying tokens
/// @return amt amount of underlying assets transferred
function burn(address _receiver) external returns (uint amt);
/// @notice only core can call this function
/// @dev borrow the asset from the lending pool
/// @param _receiver address to receive the borrowed asset
/// @param _amt amount of asset to borrow
/// @return debtShares debt shares amount recorded from borrowing
function borrow(address _receiver, uint _amt) external returns (uint debtShares);
/// @notice only core can call this function
/// @dev repay the borrowed assets
/// @param _shares the amount of debt shares to repay
/// @return amt assets amount used for repay
function repay(uint _shares) external returns (uint amt);
/// @dev accrue interest from the last accrual
function accrueInterest() external;
/// @dev get the share amounts from underlying asset amt
/// @param _amt the amount of asset to convert to shares
/// @return shares amount of shares (rounded down)
function toShares(uint _amt) external view returns (uint shares);
/// @dev get the asset amount from shares
/// @param _shares the amount of shares to convert to underlying asset amt
/// @return amt amount of underlying asset (rounded down)
function toAmt(uint _shares) external view returns (uint amt);
/// @dev get the share amounts from underlying asset amt (with interest accrual)
/// @param _amt the amount of asset to convert to shares
/// @return shares current amount of shares (rounded down)
function toSharesCurrent(uint _amt) external returns (uint shares);
/// @dev get the asset amount from shares (with interest accrual)
/// @param _shares the amount of shares to convert to underlying asset amt
/// @return amt current amount of underlying asset (rounded down)
function toAmtCurrent(uint _shares) external returns (uint amt);
/// @dev set the interest rate model
/// @param _irm new interest rate model address
function setIrm(address _irm) external;
/// @dev set the pool's reserve factor in 1e18
/// @param _reserveFactor_e18 new reserver factor in 1e18
function setReserveFactor_e18(uint _reserveFactor_e18) external;
/// @dev set the pool's treasury address
/// @param _treasury new treasury address
function setTreasury(address _treasury) external;
}// SPDX-License-Identifier: None
pragma solidity ^0.8.19;
/// @title Base Oracle Interface
interface IBaseOracle {
/// @dev return the value of the token as USD, multiplied by 1e36.
/// @param _token token address
/// @return price_e36 token price in 1e36
function getPrice_e36(address _token) external view returns (uint price_e36);
}// SPDX-License-Identifier: None
pragma solidity ^0.8.19;
import {IBaseOracle} from './IBaseOracle.sol';
/// @title Init Oracle Interface
interface IInitOracle is IBaseOracle {
event SetPrimarySource(address indexed token, address oracle);
event SetSecondarySource(address indexed token, address oracle);
event SetMaxPriceDeviation_e18(address indexed token, uint maxPriceDeviation_e18);
/// @dev return the oracle token's primary source
/// @param _token token address
/// @return primarySource primary oracle address
function primarySources(address _token) external view returns (address primarySource);
/// @dev return the oracle token's secondary source
/// @param _token token address
/// @return secondarySource secoundary oracle address
function secondarySources(address _token) external view returns (address secondarySource);
/// @dev return the max price deviation between the primary and secondary sources
/// @param _token token address
/// @return maxPriceDeviation_e18 max price deviation in 1e18
function maxPriceDeviations_e18(address _token) external view returns (uint maxPriceDeviation_e18);
/// @dev return the price of the tokens in USD, multiplied by 1e36.
/// @param _tokens token address list
/// @return prices_e36 the token prices for each tokens
function getPrices_e36(address[] calldata _tokens) external view returns (uint[] memory prices_e36);
/// @dev set primary source for tokens
/// @param _tokens token address list
/// @param _sources the primary source address for each tokens
function setPrimarySources(address[] calldata _tokens, address[] calldata _sources) external;
/// @dev set secondary source for tokens
/// @param _tokens token address list
/// @param _sources the secondary source address for each tokens
function setSecondarySources(address[] calldata _tokens, address[] calldata _sources) external;
/// @dev set max price deviation between the primary and sercondary sources
/// @param _tokens token address list
/// @param _maxPriceDeviations_e18 the max price deviation in 1e18 for each tokens
function setMaxPriceDeviations_e18(address[] calldata _tokens, uint[] calldata _maxPriceDeviations_e18) external;
}// SPDX-License-Identifier: None
pragma solidity ^0.8.19;
/// @title Callback Receiver Interface
interface ICallbackReceiver {
/// @dev handle the callback from core
/// @param _sender the sender address
/// @param _data the data payload to execute on the callback
/// @return result the encoded result of the callback
function coreCallback(address _sender, bytes calldata _data) external payable returns (bytes memory result);
}// SPDX-License-Identifier: None
pragma solidity ^0.8.0;
/// @title Flash Receiver Interface
interface IFlashReceiver {
/// @dev handle flash callback from core
/// @param _pools borrowed pool list
/// @param _amts pool borrow amounts
/// @param _data the data payload to execute on the callback
function flashCallback(address[] calldata _pools, uint[] calldata _amts, bytes calldata _data) external;
}// SPDX-License-Identifier: None
pragma solidity ^0.8.19;
/// @title Risk Manager Interface
interface IRiskManager {
event SetModeDebtCeilingInfo(uint16 indexed mode, address indexed pool, uint amt);
struct DebtCeilingInfo {
uint128 ceilAmt; // debt celing amount
uint128 debtShares; // current total token debt shares of the mode
}
/// @notice only core can call this function
/// @dev update debt shares
/// @param _mode mode id
/// @param _pool pool address
/// @param _shares debt shares (can be negative)
function updateModeDebtShares(uint16 _mode, address _pool, int _shares) external;
/// @dev set mode's borrow cap amount
/// @param _mode mode id
/// @param _pools borrow token pool ist
/// @param _amts debt ceiling amount list
function setModeDebtCeilingInfo(uint16 _mode, address[] calldata _pools, uint128[] calldata _amts) external;
/// @dev get mode's debt ceiling amount
/// @param _mode mode id
/// @param _pool pool address
/// @return debt ceiling amt
function getModeDebtCeilingAmt(uint16 _mode, address _pool) external view returns (uint);
/// @dev get debt shares
/// @param _mode mode id
/// @param _pool pool address
/// @return debt shares
function getModeDebtShares(uint16 _mode, address _pool) external view returns (uint);
/// @notice this is NOT a view function
/// @dev get current debt amount (with interest accrual)
/// @param _mode mode id
/// @param _pool pool address
/// @return current debt amount
function getModeDebtAmtCurrent(uint16 _mode, address _pool) external returns (uint);
/// @dev get stored debt amount (without interest accrual)
/// @param _mode mode id
/// @param _pool pool address
/// @return debt amount
function getModeDebtAmtStored(uint16 _mode, address _pool) external view returns (uint);
}// SPDX-License-Identifier: None
pragma solidity ^0.8.19;
import {IERC721} from '@openzeppelin-contracts/token/ERC721/IERC721.sol';
/// @title Base Wrapped Lp Interface
interface IBaseWrapLp is IERC721 {
/// @dev unwrap the wrapped token to get the lp token (burn token if unwrapping all)
/// @param _id wlp token id
/// @param _amt amount of the wrapped token to unwrap
/// @param _to address to receive the lp token
function unwrap(uint _id, uint _amt, address _to) external returns (bytes memory);
/// @dev harvest rewards from the wlp
/// @param _id id of the wlp token
/// @param _to address to receive the rewards
function harvest(uint _id, address _to) external returns (address[] memory tokens, uint[] memory amounts);
/// @dev get the amount of lp token with for a specific token id (using internal balance)
/// @param _id wlp token id
/// @return amt amount of lp underliyng the specific token id
function balanceOfLp(uint _id) external view returns (uint amt);
/// @dev get lp token address
/// @param _id id of the wlp
/// @return lp lp address
function lp(uint _id) external view returns (address lp);
/// @dev get underlying tokens of the wlp
/// @param _id wlp token id
/// @return tokens list of underlying tokens
function underlyingTokens(uint _id) external view returns (address[] memory tokens);
/// @dev get reward token addresses of the wlp
/// @param _id wlp token id
/// @return tokens reward token list (may be empty)
function rewardTokens(uint _id) external view returns (address[] memory tokens);
/// @dev get lp price of the wlp
/// @param _id wlp token id
/// @param _oracle oracle address
/// @return price lp price
function calculatePrice_e36(uint _id, address _oracle) external view returns (uint price);
}{
"evmVersion": "paris",
"libraries": {},
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"remappings": [
"@forge-std/=lib/forge-std/src/",
"@openzeppelin-contracts/=contracts/.cache/OpenZeppelin/v4.9.3/",
"@openzeppelin-contracts-upgradeable/=contracts/.cache/OpenZeppelin-Upgradeable/v4.9.3/",
"ds-test/=lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"hardhat/=node_modules/hardhat/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"openzeppelin/=lib/openzeppelin-contracts-upgradeable/contracts/"
]
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"_posManager","type":"address"},{"internalType":"address","name":"_acm","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pool","type":"address"},{"indexed":true,"internalType":"uint256","name":"posId","type":"uint256"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"borrowAmt","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Borrow","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"posId","type":"uint256"},{"indexed":true,"internalType":"address","name":"pool","type":"address"},{"indexed":false,"internalType":"uint256","name":"amt","type":"uint256"}],"name":"Collateralize","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"wLp","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"posId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amt","type":"uint256"}],"name":"CollateralizeWLp","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"uint256","name":"posId","type":"uint256"},{"indexed":false,"internalType":"uint16","name":"mode","type":"uint16"},{"indexed":false,"internalType":"address","name":"viewer","type":"address"}],"name":"CreatePosition","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"posId","type":"uint256"},{"indexed":true,"internalType":"address","name":"pool","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amt","type":"uint256"}],"name":"Decollateralize","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"wLp","type":"address"},{"indexed":true,"internalType":"uint256","name":"posId","type":"uint256"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amt","type":"uint256"}],"name":"Decollateralize","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"posId","type":"uint256"},{"indexed":true,"internalType":"address","name":"liquidator","type":"address"},{"indexed":false,"internalType":"address","name":"poolOut","type":"address"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Liquidate","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"posId","type":"uint256"},{"indexed":true,"internalType":"address","name":"liquidator","type":"address"},{"indexed":false,"internalType":"address","name":"wLpOut","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amt","type":"uint256"}],"name":"LiquidateWLp","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pool","type":"address"},{"indexed":true,"internalType":"uint256","name":"posId","type":"uint256"},{"indexed":true,"internalType":"address","name":"repayer","type":"address"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amtToRepay","type":"uint256"}],"name":"Repay","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newConfig","type":"address"}],"name":"SetConfig","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newIncentiveCalculator","type":"address"}],"name":"SetIncentiveCalculator","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newOracle","type":"address"}],"name":"SetOracle","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"posId","type":"uint256"},{"indexed":false,"internalType":"uint16","name":"mode","type":"uint16"}],"name":"SetPositionMode","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newRiskManager","type":"address"}],"name":"SetRiskManager","type":"event"},{"inputs":[],"name":"ACM","outputs":[{"internalType":"contract IAccessControlManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"POS_MANAGER","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_pool","type":"address"},{"internalType":"uint256","name":"_amt","type":"uint256"},{"internalType":"uint256","name":"_posId","type":"uint256"},{"internalType":"address","name":"_to","type":"address"}],"name":"borrow","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_pool","type":"address"},{"internalType":"address","name":"_to","type":"address"}],"name":"burnTo","outputs":[{"internalType":"uint256","name":"amt","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"callback","outputs":[{"internalType":"bytes","name":"result","type":"bytes"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_posId","type":"uint256"},{"internalType":"address","name":"_pool","type":"address"}],"name":"collateralize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_posId","type":"uint256"},{"internalType":"address","name":"_wLp","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"collateralizeWLp","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"config","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"_mode","type":"uint16"},{"internalType":"address","name":"_viewer","type":"address"}],"name":"createPos","outputs":[{"internalType":"uint256","name":"posId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_posId","type":"uint256"},{"internalType":"address","name":"_pool","type":"address"},{"internalType":"uint256","name":"_shares","type":"uint256"},{"internalType":"address","name":"_to","type":"address"}],"name":"decollateralize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_posId","type":"uint256"},{"internalType":"address","name":"_wLp","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"uint256","name":"_amt","type":"uint256"},{"internalType":"address","name":"_to","type":"address"}],"name":"decollateralizeWLp","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_pools","type":"address[]"},{"internalType":"uint256[]","name":"_amts","type":"uint256[]"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"flash","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_posId","type":"uint256"}],"name":"getBorrowCreditCurrent_e36","outputs":[{"internalType":"uint256","name":"borrowCredit_e36","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_posId","type":"uint256"}],"name":"getCollateralCreditCurrent_e36","outputs":[{"internalType":"uint256","name":"collCredit_e36","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_posId","type":"uint256"}],"name":"getPosHealthCurrent_e18","outputs":[{"internalType":"uint256","name":"health_e18","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_config","type":"address"},{"internalType":"address","name":"_oracle","type":"address"},{"internalType":"address","name":"_liqIncentiveCalculator","type":"address"},{"internalType":"address","name":"_riskManager","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"liqIncentiveCalculator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_posId","type":"uint256"},{"internalType":"address","name":"_poolToRepay","type":"address"},{"internalType":"uint256","name":"_repayShares","type":"uint256"},{"internalType":"address","name":"_poolOut","type":"address"},{"internalType":"uint256","name":"_minShares","type":"uint256"}],"name":"liquidate","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_posId","type":"uint256"},{"internalType":"address","name":"_poolToRepay","type":"address"},{"internalType":"uint256","name":"_repayShares","type":"uint256"},{"internalType":"address","name":"_wLp","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"uint256","name":"_minlpOut","type":"uint256"}],"name":"liquidateWLp","outputs":[{"internalType":"uint256","name":"lpAmtOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_pool","type":"address"},{"internalType":"address","name":"_to","type":"address"}],"name":"mintTo","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"oracle","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_pool","type":"address"},{"internalType":"uint256","name":"_shares","type":"uint256"},{"internalType":"uint256","name":"_posId","type":"uint256"}],"name":"repay","outputs":[{"internalType":"uint256","name":"amt","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"riskManager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_config","type":"address"}],"name":"setConfig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_liqIncentiveCalculator","type":"address"}],"name":"setLiqIncentiveCalculator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_oracle","type":"address"}],"name":"setOracle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_posId","type":"uint256"},{"internalType":"uint16","name":"_mode","type":"uint16"}],"name":"setPosMode","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_riskManager","type":"address"}],"name":"setRiskManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_amt","type":"uint256"}],"name":"transferToken","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
60c06040523480156200001157600080fd5b5060405162005ed238038062005ed2833981016040819052620000349162000137565b6001600160a01b03808216608052821660a0526200005162000059565b50506200016f565b600054610100900460ff1615620000c65760405162461bcd60e51b815260206004820152602760248201527f496e697469616c697a61626c653a20636f6e747261637420697320696e697469604482015266616c697a696e6760c81b606482015260840160405180910390fd5b60005460ff9081161462000118576000805460ff191660ff9081179091556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b565b80516001600160a01b03811681146200013257600080fd5b919050565b600080604083850312156200014b57600080fd5b62000156836200011a565b915062000166602084016200011a565b90509250929050565b60805160a051615c7262000260600039600081816101e401528181610611015281816107f201528181610dd0015281816111dc015281816114bd01528181611710015281816117fc015281816118aa01528181611ce001528181611d9d0152818161219a0152818161221e015281816125b80152818161280f0152818161290601528181612cf401528181612ea401528181612fcc015281816130f2015281816132aa015281816138af015281816139d801528181613d360152818161424d01526143bb0152600081816105c50152818161113f01528181611ebd01528181611f650152613ad50152615c726000f3fe6080604052600436106101cd5760003560e01c80637fe6bc3d116100f7578063abf4dd3911610095578063eed478dd11610064578063eed478dd14610553578063f5537ede14610573578063f8c8765e14610593578063f9b80da1146105b357600080fd5b8063abf4dd39146104d3578063ac9650d8146104f3578063b26ec9af14610513578063df9e68fd1461053357600080fd5b8063951b6c02116100d1578063951b6c0214610453578063a6d35d7914610473578063a72ca39b14610493578063a75b025f146104b357600080fd5b80637fe6bc3d146103f357806388029441146104135780638cd2e0c71461043357600080fd5b806342d91bc31161016f57806379502c551161013e57806379502c55146103735780637adbf973146103935780637d60c2fe146103b35780637dc0d1d0146103d357600080fd5b806342d91bc3146102f357806347842663146103135780635a1b8ac11461033357806362ca84601461035357600080fd5b8063147fce8c116101ab578063147fce8c1461026557806320e3dbd41461029357806322e953ac146102b35780632fb4bf64146102d357600080fd5b80630278b670146101d2578063058452b4146102235780630bd9648214610245575b600080fd5b3480156101de57600080fd5b506102067f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020015b60405180910390f35b34801561022f57600080fd5b5061024361023e366004614d4d565b6105e7565b005b34801561025157600080fd5b50610243610260366004614dee565b6108ea565b34801561027157600080fd5b50610285610280366004614eb3565b610db0565b60405190815260200161021a565b34801561029f57600080fd5b506102436102ae366004614ecc565b611104565b3480156102bf57600080fd5b506102856102ce366004614ee9565b6111af565b3480156102df57600080fd5b506102856102ee366004614f43565b6116c5565b3480156102ff57600080fd5b5061024361030e366004614f7c565b6117d2565b34801561031f57600080fd5b50603654610206906001600160a01b031681565b34801561033f57600080fd5b5061028561034e366004614fbb565b611990565b34801561035f57600080fd5b5061024361036e366004614ecc565b611e82565b34801561037f57600080fd5b50603354610206906001600160a01b031681565b34801561039f57600080fd5b506102436103ae366004614ecc565b611f2a565b6103c66103c136600461507a565b611fd2565b60405161021a9190615165565b3480156103df57600080fd5b50603454610206906001600160a01b031681565b3480156103ff57600080fd5b5061028561040e366004615178565b61206d565b34801561041f57600080fd5b5061024361042e366004615196565b612170565b34801561043f57600080fd5b5061028561044e3660046151bb565b6128d9565b34801561045f57600080fd5b5061028561046e366004615178565b612973565b34801561047f57600080fd5b50603554610206906001600160a01b031681565b34801561049f57600080fd5b506102856104ae366004614eb3565b612af3565b3480156104bf57600080fd5b506102856104ce3660046151f0565b612b38565b3480156104df57600080fd5b506102436104ee36600461524c565b612fa2565b610506610501366004615271565b6131b8565b60405161021a91906152b2565b34801561051f57600080fd5b5061028561052e366004614eb3565b61327e565b34801561053f57600080fd5b5061024361054e366004615314565b613885565b34801561055f57600080fd5b5061024361056e366004614ecc565b613a9a565b34801561057f57600080fd5b5061024361058e36600461534c565b613b42565b34801561059f57600080fd5b506102436105ae36600461537c565b613b68565b3480156105bf57600080fd5b506102067f000000000000000000000000000000000000000000000000000000000000000081565b6040516302972b0f60e41b8152336004820152602481018690528590610685906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690632972b0f0906044015b602060405180830381865afa158015610659573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061067d91906153e2565b610133613ca6565b6036548690600160a01b900460ff16156106a6576106a4603782613cb8565b505b6106ae613cc4565b6033546001600160a01b031661073b81638309d5756106cc8b613d1d565b6040516001600160e01b031960e084901b16815261ffff9091166004820152602401608060405180830381865afa15801561070b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061072f91906153fd565b60200151610259613ca6565b6040516357fa4b4d60e11b81526001600160a01b0388811660048301526107b3919083169063aff4969a906024015b602060405180830381865afa158015610787573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107ab91906153e2565b6101f5613ca6565b604051633d349aa960e01b8152600481018990526001600160a01b038881166024830152604482018890526064820187905285811660848301526000917f000000000000000000000000000000000000000000000000000000000000000090911690633d349aa99060a4016020604051808303816000875af115801561083d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108619190615479565b9050846001600160a01b031689896001600160a01b03167f2e445c5e867d021ae91660cb57f389fbd22f9ebd055a06c29486c7819594ea71846040516108a991815260200190565b60405180910390a450506108bc60018055565b603654600160a01b900460ff166108e1576108e16108d982613daf565b61012c613ca6565b50505050505050565b6108f2613cc4565b61090961090187878787613dcb565b610132613ca6565b60365461092390600160a01b900460ff161561012e613ca6565b6000856001600160401b0381111561093d5761093d61500d565b604051908082528060200260200182016040528015610966578160200160208202803683370190505b5090506000866001600160401b038111156109835761098361500d565b6040519080825280602002602001820160405280156109ac578160200160208202803683370190505b506033549091506001600160a01b031660005b88811015610c4a576000826001600160a01b031663f29486a18c8c858181106109ea576109ea615492565b90506020020160208101906109ff9190614ecc565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260240160e060405180830381865afa158015610a43573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a6791906154bf565b9050610a798160c00151610131613ca6565b60008b8b84818110610a8d57610a8d615492565b9050602002016020810190610aa29190614ecc565b6001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa158015610adf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b03919061556e565b905080858481518110610b1857610b18615492565b6001600160a01b03928316602091820292909201015281166370a082318d8d86818110610b4757610b47615492565b9050602002016020810190610b5c9190614ecc565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa158015610ba0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bc49190615479565b868481518110610bd657610bd6615492565b602002602001018181525050610c408c8c85818110610bf757610bf7615492565b9050602002016020810190610c0c9190614ecc565b338c8c87818110610c1f57610c1f615492565b90506020020135846001600160a01b0316613df1909392919063ffffffff16565b50506001016109bf565b50604051630a1c6d4d60e21b81523390632871b53490610c78908c908c908c908c908c908c906004016155b4565b600060405180830381600087803b158015610c9257600080fd5b505af1158015610ca6573d6000803e3d6000fd5b5050505060005b88811015610d9b57610d93848281518110610cca57610cca615492565b6020026020010151848381518110610ce457610ce4615492565b60200260200101516001600160a01b03166370a082318d8d86818110610d0c57610d0c615492565b9050602002016020810190610d219190614ecc565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa158015610d65573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d899190615479565b1015610195613ca6565b600101610cad565b50505050610da860018055565b505050505050565b6033546000906001600160a01b031681610dc984613d1d565b90506000807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663947557b3876040518263ffffffff1660e01b8152600401610e1c91815260200190565b600060405180830381865afa158015610e39573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610e619190810190615739565b60345491935091506000906001600160a01b0316815b84518110156110e5576000858281518110610e9457610e94615492565b60200260200101516001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa158015610ed9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610efd919061556e565b6040516339fa57cb60e11b81526001600160a01b0380831660048301529192506000918516906373f4af9690602401602060405180830381865afa158015610f49573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f6d9190615479565b90506000878481518110610f8357610f83615492565b60200260200101516001600160a01b03166331a86fe1888681518110610fab57610fab615492565b60200260200101516040518263ffffffff1660e01b8152600401610fd191815260200190565b6020604051808303816000875af1158015610ff0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110149190615479565b61101e90836157b2565b905060008a6001600160a01b031663fea1a64f8b8b888151811061104457611044615492565b60200260200101516040518363ffffffff1660e01b81526004016110699291906157c9565b6040805180830381865afa158015611085573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110a991906157e6565b905080602001516001600160801b0316826110c491906157b2565b6110ce9088615840565b9650505050506110de8160010190565b9050610e77565b506110f882670de0b6b3a7640000613e4b565b98975050505050505050565b6040516312d9a6ad60e01b81527f1e46cebd6689d8c64011118478db0c61a89aa2646c860df401de476fbf37898360048201523360248201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906312d9a6ad90604401600060405180830381600087803b15801561118b57600080fd5b505af115801561119f573d6000803e3d6000fd5b505050506111ac81613e82565b50565b6040516302972b0f60e41b815233600482015260248101839052600090839061120b906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690632972b0f09060440161063c565b6036548490600160a01b900460ff161561122c5761122a603782613cb8565b505b611234613cc4565b60335460405163f29486a160e01b81526001600160a01b03898116600483015290911690600090829063f29486a19060240160e060405180830381865afa158015611283573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112a791906154bf565b905060006112b488613d1d565b905061133e826080015180156113365750604051638309d57560e01b815261ffff831660048201526001600160a01b03851690638309d57590602401608060405180830381865afa15801561130d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061133191906153fd565b604001515b610192613ca6565b604051631919143760e01b81526113b9906001600160a01b038516906319191437906113709085908f906004016157c9565b602060405180830381865afa15801561138d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113b191906153e2565b6101f4613ca6565b604051633a2aa63360e11b8152600481018a90526001600160a01b038b16906374554c66906024016020604051808303816000875af1158015611400573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114249190615479565b95506114338615156064613ca6565b6114bb82602001516001600160801b03168a8c6001600160a01b031663fc7b9c186040518163ffffffff1660e01b8152600401602060405180830381865afa158015611483573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114a79190615479565b6114b19190615840565b1115610197613ca6565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663232d5dfb898c6114f58a613ecc565b6040516001600160e01b031960e086901b16815260048101939093526001600160a01b0390911660248301526044820152606401600060405180830381600087803b15801561154357600080fd5b505af1158015611557573d6000803e3d6000fd5b5050604051634b8a352960e01b81526001600160a01b038a81166004830152602482018d90528d169250634b8a352991506044016020604051808303816000875af11580156115aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115ce9190615479565b506036546001600160a01b031663d314e28f828c6115eb8a613ecc565b6040518463ffffffff1660e01b815260040161160993929190615853565b600060405180830381600087803b15801561162357600080fd5b505af1158015611637573d6000803e3d6000fd5b50505050866001600160a01b0316888b6001600160a01b03167f49dd87b26edb1c92c93f83b092bd5a425c6bf7a562c0fed02f2576c49f477ba48c8a60405161168a929190918252602082015260400190565b60405180910390a450505061169e60018055565b603654600160a01b900460ff166116bb576116bb6108d982613daf565b5050949350505050565b60006116cf613cc4565b6116e161ffff841615156101f4613ca6565b60405163a0c849a160e01b815233600482015261ffff841660248201526001600160a01b0383811660448301527f0000000000000000000000000000000000000000000000000000000000000000169063a0c849a1906064016020604051808303816000875af1158015611759573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061177d9190615479565b905080336001600160a01b03167fe6a96441ecc85d0943a914f4750f067a912798ec2543bc68c00e18291da88d1485856040516117bb9291906157c9565b60405180910390a36117cc60018055565b92915050565b6040516302972b0f60e41b815233600482015260248101859052849061182b906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690632972b0f09060440161063c565b6036548590600160a01b900460ff161561184c5761184a603782613cb8565b505b611854613cc4565b603354611872906001600160a01b0316638309d5756106cc89613d1d565b60405163529eb03160e01b8152600481018790526001600160a01b0386811660248301526044820186905284811660648301526000917f00000000000000000000000000000000000000000000000000000000000000009091169063529eb031906084016020604051808303816000875af11580156118f5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119199190615479565b9050836001600160a01b0316866001600160a01b0316887f09c2e7b3728acfd99b3f71e4c1a55bcd48019bcc0e45c741f7c2f3393f49ea918460405161196191815260200190565b60405180910390a45061197360018055565b603654600160a01b900460ff16610da857610da86108d982613daf565b600061199a613cc4565b60006119a7878787613f3a565b805160208201516040516372d0bb1160e11b81529293506119e2926001600160a01b039092169163e5a176229161076a9189906004016157c9565b836001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa158015611a20573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a44919061556e565b6001600160a01b0390811660808301819052603554602084015160408086015160a08701519151632d3f252560e21b815261ffff909316600484015260248301528416604482015260648101929092529091169063b4fc949490608401602060405180830381865afa158015611abe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ae29190615479565b6060820181905260c0820151670de0b6b3a764000091611b01916157b2565b611b0b919061588e565b60e0820152604080516002808252606080830184529260009291906020830190803683370190505090508260a00151836080015182600081518110611b5257611b52615492565b6020026020010183600181518110611b6c57611b6c615492565b6001600160a01b0393841660209182029290920101529181169091526034546040516308f114af60e21b81529116906323c452bc90611baf9084906004016158b0565b600060405180830381865afa158015611bcc573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611bf491908101906158fd565b9150856001600160a01b0316639e57c97583600181518110611c1857611c18615492565b602002602001015184600081518110611c3357611c33615492565b60200260200101518660e00151611c4a91906157b2565b611c54919061588e565b6040518263ffffffff1660e01b8152600401611c7291815260200190565b602060405180830381865afa158015611c8f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cb39190615479565b60405163402414b360e01b8152600481018b90526001600160a01b038881166024830152919550611d52917f0000000000000000000000000000000000000000000000000000000000000000169063402414b390604401602060405180830381865afa158015611d27573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d4b9190615479565b8590613fed565b9350611d62858510156066613ca6565b50508115611e0c5760405163529eb03160e01b8152600481018890526001600160a01b038581166024830152604482018490523360648301527f0000000000000000000000000000000000000000000000000000000000000000169063529eb031906084016020604051808303816000875af1158015611de6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e0a9190615479565b505b604081015115611e2957611e298160000151888360200151614003565b604080516001600160a01b038616815260208101849052339189917f6df71caf4cddb1620bcf376243248e0077da98913d65a7e9315bc9984e5fff72910160405180910390a350611e7960018055565b95945050505050565b6040516312d9a6ad60e01b81527f8fbcb4375b910093bcf636b6b2f26b26eda2a29ef5a8ee7de44b5743c3bf9a2860048201523360248201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906312d9a6ad90604401600060405180830381600087803b158015611f0957600080fd5b505af1158015611f1d573d6000803e3d6000fd5b505050506111ac81614099565b6040516312d9a6ad60e01b81527f1e46cebd6689d8c64011118478db0c61a89aa2646c860df401de476fbf37898360048201523360248201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906312d9a6ad90604401600060405180830381600087803b158015611fb157600080fd5b505af1158015611fc5573d6000803e3d6000fd5b505050506111ac816140e3565b6060611fec6001600160a01b038516301415610134613ca6565b604051634541cfef60e11b81526001600160a01b03851690638a839fde90859061201c9033908790600401615931565b60006040518083038185885af115801561203a573d6000803e3d6000fd5b50505050506040513d6000823e601f3d908101601f191682016040526120639190810190615985565b90505b9392505050565b6000612077613cc4565b60335460405163f29486a160e01b81526001600160a01b038581166004830152600092169063f29486a19060240160e060405180830381865afa1580156120c2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120e691906154bf565b90506120f88160600151610191613ca6565b60405163226bf2d160e21b81526001600160a01b0384811660048301528516906389afcb44906024016020604051808303816000875af1158015612140573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121649190615479565b9150506117cc60018055565b6040516302972b0f60e41b81523360048201526024810183905282906121c9906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690632972b0f09060440161063c565b6036548390600160a01b900460ff16156121ea576121e8603782613cb8565b505b6121f2613cc4565b60335460405163056b0ac760e01b8152600481018690526001600160a01b0391821691600091829182917f00000000000000000000000000000000000000000000000000000000000000009091169063056b0ac790602401600060405180830381865afa158015612267573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261228f9190810190615a4c565b509350935050925060006122a289613d1d565b604051638309d57560e01b815261ffff821660048201529091506000906001600160a01b03871690638309d57590602401608060405180830381865afa1580156122f0573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061231491906153fd565b604051638309d57560e01b815261ffff8b1660048201529091506000906001600160a01b03881690638309d57590602401608060405180830381865afa158015612362573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061238691906153fd565b9050855160001415806123995750845115155b156123bc5780516123ac90610258613ca6565b6123bc8260200151610259613ca6565b60005b865181101561241a57612412886001600160a01b031663e5a176228d8a85815181106123ed576123ed615492565b60200260200101516040518363ffffffff1660e01b81526004016113709291906157c9565b6001016123bf565b5060005b855181101561259e5761247e886001600160a01b031663aff4969a88848151811061244b5761244b615492565b60200260200101516040518263ffffffff1660e01b815260040161076a91906001600160a01b0391909116815260200190565b60005b85828151811061249357612493615492565b6020026020010151518110156125955761258d896001600160a01b031663e5a176228e8a86815181106124c8576124c8615492565b60200260200101516001600160a01b031663da7a21628b88815181106124f0576124f0615492565b6020026020010151878151811061250957612509615492565b60200260200101516040518263ffffffff1660e01b815260040161252f91815260200190565b602060405180830381865afa15801561254c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612570919061556e565b6040518363ffffffff1660e01b81526004016113709291906157c9565b600101612481565b5060010161241e565b5060405163947557b360e01b8152600481018c90526060907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063947557b390602401600060405180830381865afa158015612607573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261262f9190810190615739565b60365460408501519299509092506001600160a01b03169061265390610192613ca6565b61267084606001518015612668575083606001515b610193613ca6565b60005b88518110156127e6576126a18a6001600160a01b031663191914378f8c85815181106123ed576123ed615492565b816001600160a01b031663d314e28f878b84815181106126c3576126c3615492565b60200260200101516126ed8786815181106126e0576126e0615492565b6020026020010151613ecc565b6126f690615b1d565b6040518463ffffffff1660e01b815260040161271493929190615853565b600060405180830381600087803b15801561272e57600080fd5b505af1158015612742573d6000803e3d6000fd5b50505050816001600160a01b031663d314e28f8e8b848151811061276857612768615492565b60200260200101516127858786815181106126e0576126e0615492565b6040518463ffffffff1660e01b81526004016127a393929190615853565b600060405180830381600087803b1580156127bd57600080fd5b505af11580156127d1573d6000803e3d6000fd5b505050506127df8160010190565b9050612673565b5060405163f5c3238360e01b8152600481018e905261ffff8d1660248201526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063f5c3238390604401600060405180830381600087803b15801561285357600080fd5b505af1158015612867573d6000803e3d6000fd5b505060405161ffff8f1681528f92507fc9c7178d1eaafa7bc0854884a7d43500eb012fcfa2ee4d812462f89aeec77f82915060200160405180910390a25050505050505050506128b660018055565b603654600160a01b900460ff166128d3576128d36108d982613daf565b50505050565b6040516302972b0f60e41b8152336004820152602481018290526000908290612935906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690632972b0f09060440161063c565b61293d613cc4565b60335461295e906001600160a01b031661295685613d1d565b85888861412d565b925061296b905060018055565b509392505050565b600061297d613cc4565b60335460405163f29486a160e01b81526001600160a01b038581166004830152600092169063f29486a19060240160e060405180830381865afa1580156129c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129ec91906154bf565b90506129fe8160400151610190613ca6565b6040516335313c2160e11b81526001600160a01b038481166004830152851690636a627842906024016020604051808303816000875af1158015612a46573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a6a9190615479565b9150612ae981600001516001600160801b0316856001600160a01b03166301e1d1146040518163ffffffff1660e01b8152600401602060405180830381865afa158015612abb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612adf9190615479565b1115610196613ca6565b506117cc60018055565b600080612aff83610db0565b905060008111612b1157600019612066565b80670de0b6b3a7640000612b248561327e565b612b2e91906157b2565b612066919061588e565b6000612b42613cc4565b6000612b4f888888613f3a565b80516040516357fa4b4d60e11b81526001600160a01b038881166004830152929350612b87929091169063aff4969a9060240161076a565b604051636d3d10b160e11b8152600481018590526001600160a01b0386169063da7a216290602401602060405180830381865afa158015612bcc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bf0919061556e565b6001600160a01b0390811660808301819052603554602084015160408086015160a08701519151632d3f252560e21b815261ffff909316600484015260248301528416604482015260648101929092529091169063b4fc949490608401602060405180830381865afa158015612c6a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c8e9190615479565b6060820181905260c0820151670de0b6b3a764000091612cad916157b2565b612cb7919061588e565b60e0820152603454604051631e2f5ac960e01b8152600481018a90526001600160a01b0387811660248301526044820187905260009281169183917f00000000000000000000000000000000000000000000000000000000000000001690631e2f5ac990606401602060405180830381865afa158015612d3b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d5f9190615479565b60e085015160405163327ebdd760e21b8152600481018a90526001600160a01b038581166024830152929350612e53928b169063c9faf75c90604401602060405180830381865afa158015612db8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ddc9190615479565b60a08701516040516339fa57cb60e11b81526001600160a01b039182166004820152908616906373f4af9690602401602060405180830381865afa158015612e28573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e4c9190615479565b919061459a565b9250612e5f8382613fed565b92505081159050612f1457604051633d349aa960e01b8152600481018a90526001600160a01b03878116602483015260448201879052606482018390523360848301527f00000000000000000000000000000000000000000000000000000000000000001690633d349aa99060a4016020604051808303816000875af1158015612eed573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f119190615479565b92505b612f22848410156066613ca6565b604082015115612f3f57612f3f82600001518a8460200151614003565b604080516001600160a01b03881681526020810187905290810182905233908a907f6447867865c82ba3db42d69a6fa3e6248603d6a9392ab7a3d444d8378c6810209060600160405180910390a35050612f9860018055565b9695505050505050565b6040516302972b0f60e41b8152336004820152602481018390528290612ffb906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690632972b0f09060440161063c565b613003613cc4565b6033546001600160a01b0316600061301a85613d1d565b604051638309d57560e01b815261ffff82166004820152909150613097906001600160a01b03841690638309d575906024015b608060405180830381865afa15801561306a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061308e91906153fd565b51610258613ca6565b6040516372d0bb1160e11b81526130c9906001600160a01b0384169063e5a176229061137090859089906004016157c9565b60405163cadac47960e01b8152600481018690526001600160a01b0385811660248301526000917f00000000000000000000000000000000000000000000000000000000000000009091169063cadac479906044016020604051808303816000875af115801561313d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131619190615479565b9050846001600160a01b0316867f722732c12c1c1ba3942aef8ee6e0357b01908558e142501c5f85b356c4dcadf88360405161319f91815260200190565b60405180910390a35050506131b360018055565b505050565b6036546060906131d590600160a01b900460ff161561012e613ca6565b6036805460ff60a01b1916600160a01b1790556131f28383614684565b9050600061320060376147d9565b905060005b8151811015613269576132336108d983838151811061322657613226615492565b6020026020010151613daf565b61326082828151811061324857613248615492565b602002602001015160376147e690919063ffffffff16565b50600101613205565b50506036805460ff60a01b1916905592915050565b6034546033546000916001600160a01b0390811691168261329e85613d1d565b905060008060008060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663056b0ac78b6040518263ffffffff1660e01b81526004016132f691815260200190565b600060405180830381865afa158015613313573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261333b9190810190615a4c565b945094509450945094506000805b86518110156135b557600087828151811061336657613366615492565b60200260200101516001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa1580156133ab573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133cf919061556e565b6040516339fa57cb60e11b81526001600160a01b0380831660048301529192506000918d16906373f4af9690602401602060405180830381865afa15801561341b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061343f9190615479565b90506000818a858151811061345657613456615492565b60200260200101516001600160a01b03166398e8c7ec8b878151811061347e5761347e615492565b60200260200101516040518263ffffffff1660e01b81526004016134a491815260200190565b6020604051808303816000875af11580156134c3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134e79190615479565b6134f191906157b2565b905060008c6001600160a01b031663fea1a64f8d8d888151811061351757613517615492565b60200260200101516040518363ffffffff1660e01b815260040161353c9291906157c9565b6040805180830381865afa158015613558573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061357c91906157e6565b8051909150613594906001600160801b0316836157b2565b61359e9087615840565b9550505050506135ae8160010190565b9050613349565b5060005b84518110156138635760005b8482815181106135d7576135d7615492565b60200260200101515181101561385a5760008683815181106135fb576135fb615492565b60200260200101516001600160a01b031663c9faf75c87858151811061362357613623615492565b6020026020010151848151811061363c5761363c615492565b60200260200101518e6040518363ffffffff1660e01b81526004016136749291909182526001600160a01b0316602082015260400190565b602060405180830381865afa158015613691573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136b59190615479565b90506000818685815181106136cc576136cc615492565b602002602001015184815181106136e5576136e5615492565b60200260200101516136f791906157b2565b905060008c6001600160a01b031663fea1a64f8d8b888151811061371d5761371d615492565b60200260200101516001600160a01b031663da7a21628c8a8151811061374557613745615492565b6020026020010151898151811061375e5761375e615492565b60200260200101516040518263ffffffff1660e01b815260040161378491815260200190565b602060405180830381865afa1580156137a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137c5919061556e565b6040518363ffffffff1660e01b81526004016137e29291906157c9565b6040805180830381865afa1580156137fe573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061382291906157e6565b805190915061383a906001600160801b0316836157b2565b6138449087615840565b95505050506138538160010190565b90506135c5565b506001016135b9565b50613876670de0b6b3a76400008261588e565b9b9a5050505050505050505050565b6040516302972b0f60e41b81523360048201526024810184905283906138de906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690632972b0f09060440161063c565b6138e6613cc4565b6033546001600160a01b031660006138fd86613d1d565b604051638309d57560e01b815261ffff82166004820152909150613934906001600160a01b03841690638309d5759060240161304d565b6040516357fa4b4d60e11b81526001600160a01b038681166004830152613967919084169063aff4969a9060240161076a565b6139a8826001600160a01b031663e5a1762283886001600160a01b031663da7a2162896040518263ffffffff1660e01b815260040161252f91815260200190565b60405163076b5ca960e01b8152600481018790526001600160a01b038681166024830152604482018690526000917f00000000000000000000000000000000000000000000000000000000000000009091169063076b5ca9906064016020604051808303816000875af1158015613a23573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a479190615479565b90508685876001600160a01b03167f2f16955bcd4bb63a3a1898bab1ebf3279b81b3c6018c2f27f20a9be9e352068884604051613a8691815260200190565b60405180910390a45050506128d360018055565b6040516312d9a6ad60e01b81527f8fbcb4375b910093bcf636b6b2f26b26eda2a29ef5a8ee7de44b5743c3bf9a2860048201523360248201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906312d9a6ad90604401600060405180830381600087803b158015613b2157600080fd5b505af1158015613b35573d6000803e3d6000fd5b505050506111ac816147f2565b613b4a613cc4565b613b5f6001600160a01b038416338484613df1565b6131b360018055565b600054610100900460ff1615808015613b885750600054600160ff909116105b80613ba25750303b158015613ba2575060005460ff166001145b613c0a5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084015b60405180910390fd5b6000805460ff191660011790558015613c2d576000805461ff0019166101001790555b613c3561483c565b613c3e85613e82565b613c47846140e3565b613c50836147f2565b613c5982614099565b8015613c9f576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b5050505050565b81613cb457613cb48161486d565b5050565b6000612066838361487d565b600260015403613d165760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401613c01565b6002600155565b604051633e4b135360e21b8152600481018290526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063f92c4d4c90602401602060405180830381865afa158015613d85573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117cc9190615b39565b60018055565b6000670de0b6b3a7640000613dc383612af3565b101592915050565b6000838214613ddc57506000613de9565b613de685856148cc565b90505b949350505050565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b1790526128d3908590614967565b60008215613e795781613e5f600185615b56565b613e69919061588e565b613e74906001615840565b612066565b50600092915050565b603380546001600160a01b0319166001600160a01b0383169081179091556040517fc5618716db99966ac0bedb011a55472827d54343d73b50c3118c0b03cdf1c75f90600090a250565b60006001600160ff1b03821115613f365760405162461bcd60e51b815260206004820152602860248201527f53616665436173743a2076616c756520646f65736e27742066697420696e2061604482015267371034b73a191a9b60c11b6064820152608401613c01565b5090565b6040805161010081018252600060208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101919091526033546001600160a01b03168152613f8f84613d1d565b61ffff166020820152613fa184612af3565b60408201819052613fbe90670de0b6b3a76400001161012f613ca6565b613fd38160000151826020015186868661412d565b60c08301526001600160a01b031660a08201529392505050565b6000818310613ffc5781612066565b5090919050565b6040516369fc8a8560e01b815261ffff821660048201526000906001600160a01b038516906369fc8a8590602401602060405180830381865afa15801561404e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906140729190615479565b90506001600160401b0381146128d3576128d38161408f85612af3565b1115610130613ca6565b603680546001600160a01b0319166001600160a01b0383169081179091556040517f37c8df85a2ef04aeabf9919c082769d2532b8301fb54f6c54fdf858fdef2f68890600090a250565b603480546001600160a01b0319166001600160a01b0383169081179091556040517fd3b5d1e0ffaeff528910f3663f0adace7694ab8241d58e17a91351ced2e0803190600090a250565b60405163f29486a160e01b81526001600160a01b0383811660048301526000918291614224919089169063f29486a19060240160e060405180830381865afa15801561417d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141a191906154bf565b60a0015180156126685750604051638309d57560e01b815261ffff881660048201526001600160a01b03891690638309d57590602401608060405180830381865afa1580156141f4573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061421891906153fd565b60600151610193613ca6565b6040516310e28e7160e01b8152600481018690526001600160a01b0385811660248301526000917f0000000000000000000000000000000000000000000000000000000000000000909116906310e28e7190604401602060405180830381865afa158015614296573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142ba9190615479565b905060008185106142cb57816142cd565b845b6040516331a86fe160e01b8152600481018290529091506000906001600160a01b038816906331a86fe1906024016020604051808303816000875af115801561431a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061433e9190615479565b9050866001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa15801561437e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906143a2919061556e565b94506143b96001600160a01b038616338984613df1565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663232d5dfb89896143f386613ecc565b6143fc90615b1d565b6040516001600160e01b031960e086901b16815260048101939093526001600160a01b0390911660248301526044820152606401600060405180830381600087803b15801561444a57600080fd5b505af115801561445e573d6000803e3d6000fd5b5050604051631b8fec7360e11b8152600481018590526001600160a01b038a16925063371fd8e691506024016020604051808303816000875af11580156144a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144cd9190615479565b6036549094506001600160a01b031663d314e28f8a896144ec86613ecc565b6144f590615b1d565b6040518463ffffffff1660e01b815260040161451393929190615853565b600060405180830381600087803b15801561452d57600080fd5b505af1158015614541573d6000803e3d6000fd5b505060408051858152602081018890523393508b92506001600160a01b038b16917f77673b670822baca14a7caf6f8038f811649ab73e4c06083b0e58a53389bece7910160405180910390a45050509550959350505050565b60008080600019858709858702925082811083820303915050806000036145d4578382816145ca576145ca615878565b0492505050612066565b80841161461b5760405162461bcd60e51b81526020600482015260156024820152744d6174683a206d756c446976206f766572666c6f7760581b6044820152606401613c01565b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b6060816001600160401b0381111561469e5761469e61500d565b6040519080825280602002602001820160405280156146d157816020015b60608152602001906001900390816146bc5790505b50905060005b828110156147d257600080308686858181106146f5576146f5615492565b90506020028101906147079190615b69565b604051614715929190615baf565b600060405180830381855af49150503d8060008114614750576040519150601f19603f3d011682016040523d82523d6000602084013e614755565b606091505b5091509150816147a15760448151101561476e57600080fd5b600481019050808060200190518101906147889190615985565b60405162461bcd60e51b8152600401613c019190615165565b808484815181106147b4576147b4615492565b602002602001018190525050506147cb8160010190565b90506146d7565b5092915050565b6060600061206683614a3c565b60006120668383614a98565b603580546001600160a01b0319166001600160a01b0383169081179091556040517f8127fdde601cb3b351f356d36a00783ff7328d3e8e54e7e1d58bc3b759a9170990600090a250565b600054610100900460ff166148635760405162461bcd60e51b8152600401613c0190615bbf565b61486b614b8b565b565b6111ac8162494e4360e81b614bb2565b60008181526001830160205260408120546148c4575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556117cc565b5060006117cc565b60008160015b8181101561495c578484828181106148ec576148ec615492565b90506020020160208101906149019190614ecc565b6001600160a01b03168585614917600185615b56565b81811061492657614926615492565b905060200201602081019061493b9190614ecc565b6001600160a01b031610614954576000925050506117cc565b6001016148d2565b506001949350505050565b60006149bc826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316614c159092919063ffffffff16565b90508051600014806149dd5750808060200190518101906149dd91906153e2565b6131b35760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401613c01565b606081600001805480602002602001604051908101604052809291908181526020018280548015614a8c57602002820191906000526020600020905b815481526020019060010190808311614a78575b50505050509050919050565b60008181526001830160205260408120548015614b81576000614abc600183615b56565b8554909150600090614ad090600190615b56565b9050818114614b35576000866000018281548110614af057614af0615492565b9060005260206000200154905080876000018481548110614b1357614b13615492565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080614b4657614b46615c0a565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506117cc565b60009150506117cc565b600054610100900460ff16613da95760405162461bcd60e51b8152600401613c0190615bbf565b62461bcd60e51b600090815260206004526007602452600a808404818106603090810160081b958390069590950190829004918206850160101b01602363ffffff0060e086901c160160181b0190930160c81b604481905260e883901c91606490fd5b6060612063848460008585600080866001600160a01b03168587604051614c3c9190615c20565b60006040518083038185875af1925050503d8060008114614c79576040519150601f19603f3d011682016040523d82523d6000602084013e614c7e565b606091505b5091509150614c8f87838387614c9a565b979650505050505050565b60608315614d09578251600003614d02576001600160a01b0385163b614d025760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401613c01565b5081613de9565b613de98383815115614d1e5781518083602001fd5b8060405162461bcd60e51b8152600401613c019190615165565b6001600160a01b03811681146111ac57600080fd5b600080600080600060a08688031215614d6557600080fd5b853594506020860135614d7781614d38565b935060408601359250606086013591506080860135614d9581614d38565b809150509295509295909350565b60008083601f840112614db557600080fd5b5081356001600160401b03811115614dcc57600080fd5b6020830191508360208260051b8501011115614de757600080fd5b9250929050565b60008060008060008060608789031215614e0757600080fd5b86356001600160401b0380821115614e1e57600080fd5b614e2a8a838b01614da3565b90985096506020890135915080821115614e4357600080fd5b614e4f8a838b01614da3565b90965094506040890135915080821115614e6857600080fd5b818901915089601f830112614e7c57600080fd5b813581811115614e8b57600080fd5b8a6020828501011115614e9d57600080fd5b6020830194508093505050509295509295509295565b600060208284031215614ec557600080fd5b5035919050565b600060208284031215614ede57600080fd5b813561206681614d38565b60008060008060808587031215614eff57600080fd5b8435614f0a81614d38565b935060208501359250604085013591506060850135614f2881614d38565b939692955090935050565b61ffff811681146111ac57600080fd5b60008060408385031215614f5657600080fd5b8235614f6181614f33565b91506020830135614f7181614d38565b809150509250929050565b60008060008060808587031215614f9257600080fd5b843593506020850135614fa481614d38565b9250604085013591506060850135614f2881614d38565b600080600080600060a08688031215614fd357600080fd5b853594506020860135614fe581614d38565b9350604086013592506060860135614ffc81614d38565b949793965091946080013592915050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171561504b5761504b61500d565b604052919050565b60006001600160401b0382111561506c5761506c61500d565b50601f01601f191660200190565b60008060006060848603121561508f57600080fd5b833561509a81614d38565b92506020840135915060408401356001600160401b038111156150bc57600080fd5b8401601f810186136150cd57600080fd5b80356150e06150db82615053565b615023565b8181528760208385010111156150f557600080fd5b816020840160208301376000602083830101528093505050509250925092565b60005b83811015615130578181015183820152602001615118565b50506000910152565b60008151808452615151816020860160208601615115565b601f01601f19169290920160200192915050565b6020815260006120666020830184615139565b6000806040838503121561518b57600080fd5b8235614f6181614d38565b600080604083850312156151a957600080fd5b823591506020830135614f7181614f33565b6000806000606084860312156151d057600080fd5b83356151db81614d38565b95602085013595506040909401359392505050565b60008060008060008060c0878903121561520957600080fd5b86359550602087013561521b81614d38565b945060408701359350606087013561523281614d38565b9598949750929560808101359460a0909101359350915050565b6000806040838503121561525f57600080fd5b823591506020830135614f7181614d38565b6000806020838503121561528457600080fd5b82356001600160401b0381111561529a57600080fd5b6152a685828601614da3565b90969095509350505050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b8281101561530757603f198886030184526152f5858351615139565b945092850192908501906001016152d9565b5092979650505050505050565b60008060006060848603121561532957600080fd5b83359250602084013561533b81614d38565b929592945050506040919091013590565b60008060006060848603121561536157600080fd5b833561536c81614d38565b9250602084013561533b81614d38565b6000806000806080858703121561539257600080fd5b843561539d81614d38565b935060208501356153ad81614d38565b925060408501356153bd81614d38565b91506060850135614f2881614d38565b805180151581146153dd57600080fd5b919050565b6000602082840312156153f457600080fd5b612066826153cd565b60006080828403121561540f57600080fd5b604051608081018181106001600160401b03821117156154315761543161500d565b60405261543d836153cd565b815261544b602084016153cd565b602082015261545c604084016153cd565b604082015261546d606084016153cd565b60608201529392505050565b60006020828403121561548b57600080fd5b5051919050565b634e487b7160e01b600052603260045260246000fd5b80516001600160801b03811681146153dd57600080fd5b600060e082840312156154d157600080fd5b60405160e081018181106001600160401b03821117156154f3576154f361500d565b6040526154ff836154a8565b815261550d602084016154a8565b602082015261551e604084016153cd565b604082015261552f606084016153cd565b6060820152615540608084016153cd565b608082015261555160a084016153cd565b60a082015261556260c084016153cd565b60c08201529392505050565b60006020828403121561558057600080fd5b815161206681614d38565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b6060808252810186905260008760808301825b898110156155f75782356155da81614d38565b6001600160a01b03168252602092830192909101906001016155c7565b5083810360208501528681526001600160fb1b0387111561561757600080fd5b8660051b915081886020830137018281036020908101604085015261563f908201858761558b565b9998505050505050505050565b60006001600160401b038211156156655761566561500d565b5060051b60200190565b600082601f83011261568057600080fd5b815160206156906150db8361564c565b82815260059290921b840181019181810190868411156156af57600080fd5b8286015b848110156156d35780516156c681614d38565b83529183019183016156b3565b509695505050505050565b600082601f8301126156ef57600080fd5b815160206156ff6150db8361564c565b82815260059290921b8401810191818101908684111561571e57600080fd5b8286015b848110156156d35780518352918301918301615722565b6000806040838503121561574c57600080fd5b82516001600160401b038082111561576357600080fd5b61576f8683870161566f565b9350602085015191508082111561578557600080fd5b50615792858286016156de565b9150509250929050565b634e487b7160e01b600052601160045260246000fd5b80820281158282048414176117cc576117cc61579c565b61ffff9290921682526001600160a01b0316602082015260400190565b6000604082840312156157f857600080fd5b604051604081018181106001600160401b038211171561581a5761581a61500d565b604052615826836154a8565b8152615834602084016154a8565b60208201529392505050565b808201808211156117cc576117cc61579c565b61ffff9390931683526001600160a01b03919091166020830152604082015260600190565b634e487b7160e01b600052601260045260246000fd5b6000826158ab57634e487b7160e01b600052601260045260246000fd5b500490565b6020808252825182820181905260009190848201906040850190845b818110156158f15783516001600160a01b0316835292840192918401916001016158cc565b50909695505050505050565b60006020828403121561590f57600080fd5b81516001600160401b0381111561592557600080fd5b613de9848285016156de565b6001600160a01b038316815260406020820181905260009061206390830184615139565b60006159636150db84615053565b905082815283838301111561597757600080fd5b612066836020830184615115565b60006020828403121561599757600080fd5b81516001600160401b038111156159ad57600080fd5b8201601f810184136159be57600080fd5b613de984825160208401615955565b600082601f8301126159de57600080fd5b815160206159ee6150db8361564c565b82815260059290921b84018101918181019086841115615a0d57600080fd5b8286015b848110156156d35780516001600160401b03811115615a305760008081fd5b615a3e8986838b01016156de565b845250918301918301615a11565b600080600080600060a08688031215615a6457600080fd5b85516001600160401b0380821115615a7b57600080fd5b615a8789838a0161566f565b96506020880151915080821115615a9d57600080fd5b615aa989838a016156de565b95506040880151915080821115615abf57600080fd5b615acb89838a0161566f565b94506060880151915080821115615ae157600080fd5b615aed89838a016159cd565b93506080880151915080821115615b0357600080fd5b50615b10888289016159cd565b9150509295509295909350565b6000600160ff1b8201615b3257615b3261579c565b5060000390565b600060208284031215615b4b57600080fd5b815161206681614f33565b818103818111156117cc576117cc61579c565b6000808335601e19843603018112615b8057600080fd5b8301803591506001600160401b03821115615b9a57600080fd5b602001915036819003821315614de757600080fd5b8183823760009101908152919050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b634e487b7160e01b600052603160045260246000fd5b60008251615c32818460208701615115565b919091019291505056fea26469706673582212202f1dbd60cf95561e9c2149aa4f98310e6e180163544140d0c7ffd06b7596372e64736f6c634300081300330000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba92000000000000000000000000ce3292ca5abbdfa1db02142a67cffc708530675a
Deployed Bytecode
0x6080604052600436106101cd5760003560e01c80637fe6bc3d116100f7578063abf4dd3911610095578063eed478dd11610064578063eed478dd14610553578063f5537ede14610573578063f8c8765e14610593578063f9b80da1146105b357600080fd5b8063abf4dd39146104d3578063ac9650d8146104f3578063b26ec9af14610513578063df9e68fd1461053357600080fd5b8063951b6c02116100d1578063951b6c0214610453578063a6d35d7914610473578063a72ca39b14610493578063a75b025f146104b357600080fd5b80637fe6bc3d146103f357806388029441146104135780638cd2e0c71461043357600080fd5b806342d91bc31161016f57806379502c551161013e57806379502c55146103735780637adbf973146103935780637d60c2fe146103b35780637dc0d1d0146103d357600080fd5b806342d91bc3146102f357806347842663146103135780635a1b8ac11461033357806362ca84601461035357600080fd5b8063147fce8c116101ab578063147fce8c1461026557806320e3dbd41461029357806322e953ac146102b35780632fb4bf64146102d357600080fd5b80630278b670146101d2578063058452b4146102235780630bd9648214610245575b600080fd5b3480156101de57600080fd5b506102067f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba9281565b6040516001600160a01b0390911681526020015b60405180910390f35b34801561022f57600080fd5b5061024361023e366004614d4d565b6105e7565b005b34801561025157600080fd5b50610243610260366004614dee565b6108ea565b34801561027157600080fd5b50610285610280366004614eb3565b610db0565b60405190815260200161021a565b34801561029f57600080fd5b506102436102ae366004614ecc565b611104565b3480156102bf57600080fd5b506102856102ce366004614ee9565b6111af565b3480156102df57600080fd5b506102856102ee366004614f43565b6116c5565b3480156102ff57600080fd5b5061024361030e366004614f7c565b6117d2565b34801561031f57600080fd5b50603654610206906001600160a01b031681565b34801561033f57600080fd5b5061028561034e366004614fbb565b611990565b34801561035f57600080fd5b5061024361036e366004614ecc565b611e82565b34801561037f57600080fd5b50603354610206906001600160a01b031681565b34801561039f57600080fd5b506102436103ae366004614ecc565b611f2a565b6103c66103c136600461507a565b611fd2565b60405161021a9190615165565b3480156103df57600080fd5b50603454610206906001600160a01b031681565b3480156103ff57600080fd5b5061028561040e366004615178565b61206d565b34801561041f57600080fd5b5061024361042e366004615196565b612170565b34801561043f57600080fd5b5061028561044e3660046151bb565b6128d9565b34801561045f57600080fd5b5061028561046e366004615178565b612973565b34801561047f57600080fd5b50603554610206906001600160a01b031681565b34801561049f57600080fd5b506102856104ae366004614eb3565b612af3565b3480156104bf57600080fd5b506102856104ce3660046151f0565b612b38565b3480156104df57600080fd5b506102436104ee36600461524c565b612fa2565b610506610501366004615271565b6131b8565b60405161021a91906152b2565b34801561051f57600080fd5b5061028561052e366004614eb3565b61327e565b34801561053f57600080fd5b5061024361054e366004615314565b613885565b34801561055f57600080fd5b5061024361056e366004614ecc565b613a9a565b34801561057f57600080fd5b5061024361058e36600461534c565b613b42565b34801561059f57600080fd5b506102436105ae36600461537c565b613b68565b3480156105bf57600080fd5b506102067f000000000000000000000000ce3292ca5abbdfa1db02142a67cffc708530675a81565b6040516302972b0f60e41b8152336004820152602481018690528590610685906001600160a01b037f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba921690632972b0f0906044015b602060405180830381865afa158015610659573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061067d91906153e2565b610133613ca6565b6036548690600160a01b900460ff16156106a6576106a4603782613cb8565b505b6106ae613cc4565b6033546001600160a01b031661073b81638309d5756106cc8b613d1d565b6040516001600160e01b031960e084901b16815261ffff9091166004820152602401608060405180830381865afa15801561070b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061072f91906153fd565b60200151610259613ca6565b6040516357fa4b4d60e11b81526001600160a01b0388811660048301526107b3919083169063aff4969a906024015b602060405180830381865afa158015610787573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107ab91906153e2565b6101f5613ca6565b604051633d349aa960e01b8152600481018990526001600160a01b038881166024830152604482018890526064820187905285811660848301526000917f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba9290911690633d349aa99060a4016020604051808303816000875af115801561083d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108619190615479565b9050846001600160a01b031689896001600160a01b03167f2e445c5e867d021ae91660cb57f389fbd22f9ebd055a06c29486c7819594ea71846040516108a991815260200190565b60405180910390a450506108bc60018055565b603654600160a01b900460ff166108e1576108e16108d982613daf565b61012c613ca6565b50505050505050565b6108f2613cc4565b61090961090187878787613dcb565b610132613ca6565b60365461092390600160a01b900460ff161561012e613ca6565b6000856001600160401b0381111561093d5761093d61500d565b604051908082528060200260200182016040528015610966578160200160208202803683370190505b5090506000866001600160401b038111156109835761098361500d565b6040519080825280602002602001820160405280156109ac578160200160208202803683370190505b506033549091506001600160a01b031660005b88811015610c4a576000826001600160a01b031663f29486a18c8c858181106109ea576109ea615492565b90506020020160208101906109ff9190614ecc565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260240160e060405180830381865afa158015610a43573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a6791906154bf565b9050610a798160c00151610131613ca6565b60008b8b84818110610a8d57610a8d615492565b9050602002016020810190610aa29190614ecc565b6001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa158015610adf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b03919061556e565b905080858481518110610b1857610b18615492565b6001600160a01b03928316602091820292909201015281166370a082318d8d86818110610b4757610b47615492565b9050602002016020810190610b5c9190614ecc565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa158015610ba0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bc49190615479565b868481518110610bd657610bd6615492565b602002602001018181525050610c408c8c85818110610bf757610bf7615492565b9050602002016020810190610c0c9190614ecc565b338c8c87818110610c1f57610c1f615492565b90506020020135846001600160a01b0316613df1909392919063ffffffff16565b50506001016109bf565b50604051630a1c6d4d60e21b81523390632871b53490610c78908c908c908c908c908c908c906004016155b4565b600060405180830381600087803b158015610c9257600080fd5b505af1158015610ca6573d6000803e3d6000fd5b5050505060005b88811015610d9b57610d93848281518110610cca57610cca615492565b6020026020010151848381518110610ce457610ce4615492565b60200260200101516001600160a01b03166370a082318d8d86818110610d0c57610d0c615492565b9050602002016020810190610d219190614ecc565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa158015610d65573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d899190615479565b1015610195613ca6565b600101610cad565b50505050610da860018055565b505050505050565b6033546000906001600160a01b031681610dc984613d1d565b90506000807f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba926001600160a01b031663947557b3876040518263ffffffff1660e01b8152600401610e1c91815260200190565b600060405180830381865afa158015610e39573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610e619190810190615739565b60345491935091506000906001600160a01b0316815b84518110156110e5576000858281518110610e9457610e94615492565b60200260200101516001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa158015610ed9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610efd919061556e565b6040516339fa57cb60e11b81526001600160a01b0380831660048301529192506000918516906373f4af9690602401602060405180830381865afa158015610f49573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f6d9190615479565b90506000878481518110610f8357610f83615492565b60200260200101516001600160a01b03166331a86fe1888681518110610fab57610fab615492565b60200260200101516040518263ffffffff1660e01b8152600401610fd191815260200190565b6020604051808303816000875af1158015610ff0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110149190615479565b61101e90836157b2565b905060008a6001600160a01b031663fea1a64f8b8b888151811061104457611044615492565b60200260200101516040518363ffffffff1660e01b81526004016110699291906157c9565b6040805180830381865afa158015611085573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110a991906157e6565b905080602001516001600160801b0316826110c491906157b2565b6110ce9088615840565b9650505050506110de8160010190565b9050610e77565b506110f882670de0b6b3a7640000613e4b565b98975050505050505050565b6040516312d9a6ad60e01b81527f1e46cebd6689d8c64011118478db0c61a89aa2646c860df401de476fbf37898360048201523360248201527f000000000000000000000000ce3292ca5abbdfa1db02142a67cffc708530675a6001600160a01b0316906312d9a6ad90604401600060405180830381600087803b15801561118b57600080fd5b505af115801561119f573d6000803e3d6000fd5b505050506111ac81613e82565b50565b6040516302972b0f60e41b815233600482015260248101839052600090839061120b906001600160a01b037f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba921690632972b0f09060440161063c565b6036548490600160a01b900460ff161561122c5761122a603782613cb8565b505b611234613cc4565b60335460405163f29486a160e01b81526001600160a01b03898116600483015290911690600090829063f29486a19060240160e060405180830381865afa158015611283573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112a791906154bf565b905060006112b488613d1d565b905061133e826080015180156113365750604051638309d57560e01b815261ffff831660048201526001600160a01b03851690638309d57590602401608060405180830381865afa15801561130d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061133191906153fd565b604001515b610192613ca6565b604051631919143760e01b81526113b9906001600160a01b038516906319191437906113709085908f906004016157c9565b602060405180830381865afa15801561138d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113b191906153e2565b6101f4613ca6565b604051633a2aa63360e11b8152600481018a90526001600160a01b038b16906374554c66906024016020604051808303816000875af1158015611400573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114249190615479565b95506114338615156064613ca6565b6114bb82602001516001600160801b03168a8c6001600160a01b031663fc7b9c186040518163ffffffff1660e01b8152600401602060405180830381865afa158015611483573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114a79190615479565b6114b19190615840565b1115610197613ca6565b7f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba926001600160a01b031663232d5dfb898c6114f58a613ecc565b6040516001600160e01b031960e086901b16815260048101939093526001600160a01b0390911660248301526044820152606401600060405180830381600087803b15801561154357600080fd5b505af1158015611557573d6000803e3d6000fd5b5050604051634b8a352960e01b81526001600160a01b038a81166004830152602482018d90528d169250634b8a352991506044016020604051808303816000875af11580156115aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115ce9190615479565b506036546001600160a01b031663d314e28f828c6115eb8a613ecc565b6040518463ffffffff1660e01b815260040161160993929190615853565b600060405180830381600087803b15801561162357600080fd5b505af1158015611637573d6000803e3d6000fd5b50505050866001600160a01b0316888b6001600160a01b03167f49dd87b26edb1c92c93f83b092bd5a425c6bf7a562c0fed02f2576c49f477ba48c8a60405161168a929190918252602082015260400190565b60405180910390a450505061169e60018055565b603654600160a01b900460ff166116bb576116bb6108d982613daf565b5050949350505050565b60006116cf613cc4565b6116e161ffff841615156101f4613ca6565b60405163a0c849a160e01b815233600482015261ffff841660248201526001600160a01b0383811660448301527f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba92169063a0c849a1906064016020604051808303816000875af1158015611759573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061177d9190615479565b905080336001600160a01b03167fe6a96441ecc85d0943a914f4750f067a912798ec2543bc68c00e18291da88d1485856040516117bb9291906157c9565b60405180910390a36117cc60018055565b92915050565b6040516302972b0f60e41b815233600482015260248101859052849061182b906001600160a01b037f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba921690632972b0f09060440161063c565b6036548590600160a01b900460ff161561184c5761184a603782613cb8565b505b611854613cc4565b603354611872906001600160a01b0316638309d5756106cc89613d1d565b60405163529eb03160e01b8152600481018790526001600160a01b0386811660248301526044820186905284811660648301526000917f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba929091169063529eb031906084016020604051808303816000875af11580156118f5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119199190615479565b9050836001600160a01b0316866001600160a01b0316887f09c2e7b3728acfd99b3f71e4c1a55bcd48019bcc0e45c741f7c2f3393f49ea918460405161196191815260200190565b60405180910390a45061197360018055565b603654600160a01b900460ff16610da857610da86108d982613daf565b600061199a613cc4565b60006119a7878787613f3a565b805160208201516040516372d0bb1160e11b81529293506119e2926001600160a01b039092169163e5a176229161076a9189906004016157c9565b836001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa158015611a20573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a44919061556e565b6001600160a01b0390811660808301819052603554602084015160408086015160a08701519151632d3f252560e21b815261ffff909316600484015260248301528416604482015260648101929092529091169063b4fc949490608401602060405180830381865afa158015611abe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ae29190615479565b6060820181905260c0820151670de0b6b3a764000091611b01916157b2565b611b0b919061588e565b60e0820152604080516002808252606080830184529260009291906020830190803683370190505090508260a00151836080015182600081518110611b5257611b52615492565b6020026020010183600181518110611b6c57611b6c615492565b6001600160a01b0393841660209182029290920101529181169091526034546040516308f114af60e21b81529116906323c452bc90611baf9084906004016158b0565b600060405180830381865afa158015611bcc573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611bf491908101906158fd565b9150856001600160a01b0316639e57c97583600181518110611c1857611c18615492565b602002602001015184600081518110611c3357611c33615492565b60200260200101518660e00151611c4a91906157b2565b611c54919061588e565b6040518263ffffffff1660e01b8152600401611c7291815260200190565b602060405180830381865afa158015611c8f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cb39190615479565b60405163402414b360e01b8152600481018b90526001600160a01b038881166024830152919550611d52917f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba92169063402414b390604401602060405180830381865afa158015611d27573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d4b9190615479565b8590613fed565b9350611d62858510156066613ca6565b50508115611e0c5760405163529eb03160e01b8152600481018890526001600160a01b038581166024830152604482018490523360648301527f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba92169063529eb031906084016020604051808303816000875af1158015611de6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e0a9190615479565b505b604081015115611e2957611e298160000151888360200151614003565b604080516001600160a01b038616815260208101849052339189917f6df71caf4cddb1620bcf376243248e0077da98913d65a7e9315bc9984e5fff72910160405180910390a350611e7960018055565b95945050505050565b6040516312d9a6ad60e01b81527f8fbcb4375b910093bcf636b6b2f26b26eda2a29ef5a8ee7de44b5743c3bf9a2860048201523360248201527f000000000000000000000000ce3292ca5abbdfa1db02142a67cffc708530675a6001600160a01b0316906312d9a6ad90604401600060405180830381600087803b158015611f0957600080fd5b505af1158015611f1d573d6000803e3d6000fd5b505050506111ac81614099565b6040516312d9a6ad60e01b81527f1e46cebd6689d8c64011118478db0c61a89aa2646c860df401de476fbf37898360048201523360248201527f000000000000000000000000ce3292ca5abbdfa1db02142a67cffc708530675a6001600160a01b0316906312d9a6ad90604401600060405180830381600087803b158015611fb157600080fd5b505af1158015611fc5573d6000803e3d6000fd5b505050506111ac816140e3565b6060611fec6001600160a01b038516301415610134613ca6565b604051634541cfef60e11b81526001600160a01b03851690638a839fde90859061201c9033908790600401615931565b60006040518083038185885af115801561203a573d6000803e3d6000fd5b50505050506040513d6000823e601f3d908101601f191682016040526120639190810190615985565b90505b9392505050565b6000612077613cc4565b60335460405163f29486a160e01b81526001600160a01b038581166004830152600092169063f29486a19060240160e060405180830381865afa1580156120c2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120e691906154bf565b90506120f88160600151610191613ca6565b60405163226bf2d160e21b81526001600160a01b0384811660048301528516906389afcb44906024016020604051808303816000875af1158015612140573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121649190615479565b9150506117cc60018055565b6040516302972b0f60e41b81523360048201526024810183905282906121c9906001600160a01b037f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba921690632972b0f09060440161063c565b6036548390600160a01b900460ff16156121ea576121e8603782613cb8565b505b6121f2613cc4565b60335460405163056b0ac760e01b8152600481018690526001600160a01b0391821691600091829182917f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba929091169063056b0ac790602401600060405180830381865afa158015612267573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261228f9190810190615a4c565b509350935050925060006122a289613d1d565b604051638309d57560e01b815261ffff821660048201529091506000906001600160a01b03871690638309d57590602401608060405180830381865afa1580156122f0573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061231491906153fd565b604051638309d57560e01b815261ffff8b1660048201529091506000906001600160a01b03881690638309d57590602401608060405180830381865afa158015612362573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061238691906153fd565b9050855160001415806123995750845115155b156123bc5780516123ac90610258613ca6565b6123bc8260200151610259613ca6565b60005b865181101561241a57612412886001600160a01b031663e5a176228d8a85815181106123ed576123ed615492565b60200260200101516040518363ffffffff1660e01b81526004016113709291906157c9565b6001016123bf565b5060005b855181101561259e5761247e886001600160a01b031663aff4969a88848151811061244b5761244b615492565b60200260200101516040518263ffffffff1660e01b815260040161076a91906001600160a01b0391909116815260200190565b60005b85828151811061249357612493615492565b6020026020010151518110156125955761258d896001600160a01b031663e5a176228e8a86815181106124c8576124c8615492565b60200260200101516001600160a01b031663da7a21628b88815181106124f0576124f0615492565b6020026020010151878151811061250957612509615492565b60200260200101516040518263ffffffff1660e01b815260040161252f91815260200190565b602060405180830381865afa15801561254c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612570919061556e565b6040518363ffffffff1660e01b81526004016113709291906157c9565b600101612481565b5060010161241e565b5060405163947557b360e01b8152600481018c90526060907f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba926001600160a01b03169063947557b390602401600060405180830381865afa158015612607573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261262f9190810190615739565b60365460408501519299509092506001600160a01b03169061265390610192613ca6565b61267084606001518015612668575083606001515b610193613ca6565b60005b88518110156127e6576126a18a6001600160a01b031663191914378f8c85815181106123ed576123ed615492565b816001600160a01b031663d314e28f878b84815181106126c3576126c3615492565b60200260200101516126ed8786815181106126e0576126e0615492565b6020026020010151613ecc565b6126f690615b1d565b6040518463ffffffff1660e01b815260040161271493929190615853565b600060405180830381600087803b15801561272e57600080fd5b505af1158015612742573d6000803e3d6000fd5b50505050816001600160a01b031663d314e28f8e8b848151811061276857612768615492565b60200260200101516127858786815181106126e0576126e0615492565b6040518463ffffffff1660e01b81526004016127a393929190615853565b600060405180830381600087803b1580156127bd57600080fd5b505af11580156127d1573d6000803e3d6000fd5b505050506127df8160010190565b9050612673565b5060405163f5c3238360e01b8152600481018e905261ffff8d1660248201526001600160a01b037f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba92169063f5c3238390604401600060405180830381600087803b15801561285357600080fd5b505af1158015612867573d6000803e3d6000fd5b505060405161ffff8f1681528f92507fc9c7178d1eaafa7bc0854884a7d43500eb012fcfa2ee4d812462f89aeec77f82915060200160405180910390a25050505050505050506128b660018055565b603654600160a01b900460ff166128d3576128d36108d982613daf565b50505050565b6040516302972b0f60e41b8152336004820152602481018290526000908290612935906001600160a01b037f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba921690632972b0f09060440161063c565b61293d613cc4565b60335461295e906001600160a01b031661295685613d1d565b85888861412d565b925061296b905060018055565b509392505050565b600061297d613cc4565b60335460405163f29486a160e01b81526001600160a01b038581166004830152600092169063f29486a19060240160e060405180830381865afa1580156129c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129ec91906154bf565b90506129fe8160400151610190613ca6565b6040516335313c2160e11b81526001600160a01b038481166004830152851690636a627842906024016020604051808303816000875af1158015612a46573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a6a9190615479565b9150612ae981600001516001600160801b0316856001600160a01b03166301e1d1146040518163ffffffff1660e01b8152600401602060405180830381865afa158015612abb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612adf9190615479565b1115610196613ca6565b506117cc60018055565b600080612aff83610db0565b905060008111612b1157600019612066565b80670de0b6b3a7640000612b248561327e565b612b2e91906157b2565b612066919061588e565b6000612b42613cc4565b6000612b4f888888613f3a565b80516040516357fa4b4d60e11b81526001600160a01b038881166004830152929350612b87929091169063aff4969a9060240161076a565b604051636d3d10b160e11b8152600481018590526001600160a01b0386169063da7a216290602401602060405180830381865afa158015612bcc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bf0919061556e565b6001600160a01b0390811660808301819052603554602084015160408086015160a08701519151632d3f252560e21b815261ffff909316600484015260248301528416604482015260648101929092529091169063b4fc949490608401602060405180830381865afa158015612c6a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c8e9190615479565b6060820181905260c0820151670de0b6b3a764000091612cad916157b2565b612cb7919061588e565b60e0820152603454604051631e2f5ac960e01b8152600481018a90526001600160a01b0387811660248301526044820187905260009281169183917f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba921690631e2f5ac990606401602060405180830381865afa158015612d3b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d5f9190615479565b60e085015160405163327ebdd760e21b8152600481018a90526001600160a01b038581166024830152929350612e53928b169063c9faf75c90604401602060405180830381865afa158015612db8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ddc9190615479565b60a08701516040516339fa57cb60e11b81526001600160a01b039182166004820152908616906373f4af9690602401602060405180830381865afa158015612e28573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e4c9190615479565b919061459a565b9250612e5f8382613fed565b92505081159050612f1457604051633d349aa960e01b8152600481018a90526001600160a01b03878116602483015260448201879052606482018390523360848301527f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba921690633d349aa99060a4016020604051808303816000875af1158015612eed573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f119190615479565b92505b612f22848410156066613ca6565b604082015115612f3f57612f3f82600001518a8460200151614003565b604080516001600160a01b03881681526020810187905290810182905233908a907f6447867865c82ba3db42d69a6fa3e6248603d6a9392ab7a3d444d8378c6810209060600160405180910390a35050612f9860018055565b9695505050505050565b6040516302972b0f60e41b8152336004820152602481018390528290612ffb906001600160a01b037f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba921690632972b0f09060440161063c565b613003613cc4565b6033546001600160a01b0316600061301a85613d1d565b604051638309d57560e01b815261ffff82166004820152909150613097906001600160a01b03841690638309d575906024015b608060405180830381865afa15801561306a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061308e91906153fd565b51610258613ca6565b6040516372d0bb1160e11b81526130c9906001600160a01b0384169063e5a176229061137090859089906004016157c9565b60405163cadac47960e01b8152600481018690526001600160a01b0385811660248301526000917f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba929091169063cadac479906044016020604051808303816000875af115801561313d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131619190615479565b9050846001600160a01b0316867f722732c12c1c1ba3942aef8ee6e0357b01908558e142501c5f85b356c4dcadf88360405161319f91815260200190565b60405180910390a35050506131b360018055565b505050565b6036546060906131d590600160a01b900460ff161561012e613ca6565b6036805460ff60a01b1916600160a01b1790556131f28383614684565b9050600061320060376147d9565b905060005b8151811015613269576132336108d983838151811061322657613226615492565b6020026020010151613daf565b61326082828151811061324857613248615492565b602002602001015160376147e690919063ffffffff16565b50600101613205565b50506036805460ff60a01b1916905592915050565b6034546033546000916001600160a01b0390811691168261329e85613d1d565b905060008060008060007f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba926001600160a01b031663056b0ac78b6040518263ffffffff1660e01b81526004016132f691815260200190565b600060405180830381865afa158015613313573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261333b9190810190615a4c565b945094509450945094506000805b86518110156135b557600087828151811061336657613366615492565b60200260200101516001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa1580156133ab573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133cf919061556e565b6040516339fa57cb60e11b81526001600160a01b0380831660048301529192506000918d16906373f4af9690602401602060405180830381865afa15801561341b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061343f9190615479565b90506000818a858151811061345657613456615492565b60200260200101516001600160a01b03166398e8c7ec8b878151811061347e5761347e615492565b60200260200101516040518263ffffffff1660e01b81526004016134a491815260200190565b6020604051808303816000875af11580156134c3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134e79190615479565b6134f191906157b2565b905060008c6001600160a01b031663fea1a64f8d8d888151811061351757613517615492565b60200260200101516040518363ffffffff1660e01b815260040161353c9291906157c9565b6040805180830381865afa158015613558573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061357c91906157e6565b8051909150613594906001600160801b0316836157b2565b61359e9087615840565b9550505050506135ae8160010190565b9050613349565b5060005b84518110156138635760005b8482815181106135d7576135d7615492565b60200260200101515181101561385a5760008683815181106135fb576135fb615492565b60200260200101516001600160a01b031663c9faf75c87858151811061362357613623615492565b6020026020010151848151811061363c5761363c615492565b60200260200101518e6040518363ffffffff1660e01b81526004016136749291909182526001600160a01b0316602082015260400190565b602060405180830381865afa158015613691573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136b59190615479565b90506000818685815181106136cc576136cc615492565b602002602001015184815181106136e5576136e5615492565b60200260200101516136f791906157b2565b905060008c6001600160a01b031663fea1a64f8d8b888151811061371d5761371d615492565b60200260200101516001600160a01b031663da7a21628c8a8151811061374557613745615492565b6020026020010151898151811061375e5761375e615492565b60200260200101516040518263ffffffff1660e01b815260040161378491815260200190565b602060405180830381865afa1580156137a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137c5919061556e565b6040518363ffffffff1660e01b81526004016137e29291906157c9565b6040805180830381865afa1580156137fe573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061382291906157e6565b805190915061383a906001600160801b0316836157b2565b6138449087615840565b95505050506138538160010190565b90506135c5565b506001016135b9565b50613876670de0b6b3a76400008261588e565b9b9a5050505050505050505050565b6040516302972b0f60e41b81523360048201526024810184905283906138de906001600160a01b037f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba921690632972b0f09060440161063c565b6138e6613cc4565b6033546001600160a01b031660006138fd86613d1d565b604051638309d57560e01b815261ffff82166004820152909150613934906001600160a01b03841690638309d5759060240161304d565b6040516357fa4b4d60e11b81526001600160a01b038681166004830152613967919084169063aff4969a9060240161076a565b6139a8826001600160a01b031663e5a1762283886001600160a01b031663da7a2162896040518263ffffffff1660e01b815260040161252f91815260200190565b60405163076b5ca960e01b8152600481018790526001600160a01b038681166024830152604482018690526000917f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba929091169063076b5ca9906064016020604051808303816000875af1158015613a23573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a479190615479565b90508685876001600160a01b03167f2f16955bcd4bb63a3a1898bab1ebf3279b81b3c6018c2f27f20a9be9e352068884604051613a8691815260200190565b60405180910390a45050506128d360018055565b6040516312d9a6ad60e01b81527f8fbcb4375b910093bcf636b6b2f26b26eda2a29ef5a8ee7de44b5743c3bf9a2860048201523360248201527f000000000000000000000000ce3292ca5abbdfa1db02142a67cffc708530675a6001600160a01b0316906312d9a6ad90604401600060405180830381600087803b158015613b2157600080fd5b505af1158015613b35573d6000803e3d6000fd5b505050506111ac816147f2565b613b4a613cc4565b613b5f6001600160a01b038416338484613df1565b6131b360018055565b600054610100900460ff1615808015613b885750600054600160ff909116105b80613ba25750303b158015613ba2575060005460ff166001145b613c0a5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084015b60405180910390fd5b6000805460ff191660011790558015613c2d576000805461ff0019166101001790555b613c3561483c565b613c3e85613e82565b613c47846140e3565b613c50836147f2565b613c5982614099565b8015613c9f576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b5050505050565b81613cb457613cb48161486d565b5050565b6000612066838361487d565b600260015403613d165760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401613c01565b6002600155565b604051633e4b135360e21b8152600481018290526000907f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba926001600160a01b03169063f92c4d4c90602401602060405180830381865afa158015613d85573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117cc9190615b39565b60018055565b6000670de0b6b3a7640000613dc383612af3565b101592915050565b6000838214613ddc57506000613de9565b613de685856148cc565b90505b949350505050565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b1790526128d3908590614967565b60008215613e795781613e5f600185615b56565b613e69919061588e565b613e74906001615840565b612066565b50600092915050565b603380546001600160a01b0319166001600160a01b0383169081179091556040517fc5618716db99966ac0bedb011a55472827d54343d73b50c3118c0b03cdf1c75f90600090a250565b60006001600160ff1b03821115613f365760405162461bcd60e51b815260206004820152602860248201527f53616665436173743a2076616c756520646f65736e27742066697420696e2061604482015267371034b73a191a9b60c11b6064820152608401613c01565b5090565b6040805161010081018252600060208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101919091526033546001600160a01b03168152613f8f84613d1d565b61ffff166020820152613fa184612af3565b60408201819052613fbe90670de0b6b3a76400001161012f613ca6565b613fd38160000151826020015186868661412d565b60c08301526001600160a01b031660a08201529392505050565b6000818310613ffc5781612066565b5090919050565b6040516369fc8a8560e01b815261ffff821660048201526000906001600160a01b038516906369fc8a8590602401602060405180830381865afa15801561404e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906140729190615479565b90506001600160401b0381146128d3576128d38161408f85612af3565b1115610130613ca6565b603680546001600160a01b0319166001600160a01b0383169081179091556040517f37c8df85a2ef04aeabf9919c082769d2532b8301fb54f6c54fdf858fdef2f68890600090a250565b603480546001600160a01b0319166001600160a01b0383169081179091556040517fd3b5d1e0ffaeff528910f3663f0adace7694ab8241d58e17a91351ced2e0803190600090a250565b60405163f29486a160e01b81526001600160a01b0383811660048301526000918291614224919089169063f29486a19060240160e060405180830381865afa15801561417d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141a191906154bf565b60a0015180156126685750604051638309d57560e01b815261ffff881660048201526001600160a01b03891690638309d57590602401608060405180830381865afa1580156141f4573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061421891906153fd565b60600151610193613ca6565b6040516310e28e7160e01b8152600481018690526001600160a01b0385811660248301526000917f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba92909116906310e28e7190604401602060405180830381865afa158015614296573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142ba9190615479565b905060008185106142cb57816142cd565b845b6040516331a86fe160e01b8152600481018290529091506000906001600160a01b038816906331a86fe1906024016020604051808303816000875af115801561431a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061433e9190615479565b9050866001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa15801561437e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906143a2919061556e565b94506143b96001600160a01b038616338984613df1565b7f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba926001600160a01b031663232d5dfb89896143f386613ecc565b6143fc90615b1d565b6040516001600160e01b031960e086901b16815260048101939093526001600160a01b0390911660248301526044820152606401600060405180830381600087803b15801561444a57600080fd5b505af115801561445e573d6000803e3d6000fd5b5050604051631b8fec7360e11b8152600481018590526001600160a01b038a16925063371fd8e691506024016020604051808303816000875af11580156144a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144cd9190615479565b6036549094506001600160a01b031663d314e28f8a896144ec86613ecc565b6144f590615b1d565b6040518463ffffffff1660e01b815260040161451393929190615853565b600060405180830381600087803b15801561452d57600080fd5b505af1158015614541573d6000803e3d6000fd5b505060408051858152602081018890523393508b92506001600160a01b038b16917f77673b670822baca14a7caf6f8038f811649ab73e4c06083b0e58a53389bece7910160405180910390a45050509550959350505050565b60008080600019858709858702925082811083820303915050806000036145d4578382816145ca576145ca615878565b0492505050612066565b80841161461b5760405162461bcd60e51b81526020600482015260156024820152744d6174683a206d756c446976206f766572666c6f7760581b6044820152606401613c01565b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b6060816001600160401b0381111561469e5761469e61500d565b6040519080825280602002602001820160405280156146d157816020015b60608152602001906001900390816146bc5790505b50905060005b828110156147d257600080308686858181106146f5576146f5615492565b90506020028101906147079190615b69565b604051614715929190615baf565b600060405180830381855af49150503d8060008114614750576040519150601f19603f3d011682016040523d82523d6000602084013e614755565b606091505b5091509150816147a15760448151101561476e57600080fd5b600481019050808060200190518101906147889190615985565b60405162461bcd60e51b8152600401613c019190615165565b808484815181106147b4576147b4615492565b602002602001018190525050506147cb8160010190565b90506146d7565b5092915050565b6060600061206683614a3c565b60006120668383614a98565b603580546001600160a01b0319166001600160a01b0383169081179091556040517f8127fdde601cb3b351f356d36a00783ff7328d3e8e54e7e1d58bc3b759a9170990600090a250565b600054610100900460ff166148635760405162461bcd60e51b8152600401613c0190615bbf565b61486b614b8b565b565b6111ac8162494e4360e81b614bb2565b60008181526001830160205260408120546148c4575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556117cc565b5060006117cc565b60008160015b8181101561495c578484828181106148ec576148ec615492565b90506020020160208101906149019190614ecc565b6001600160a01b03168585614917600185615b56565b81811061492657614926615492565b905060200201602081019061493b9190614ecc565b6001600160a01b031610614954576000925050506117cc565b6001016148d2565b506001949350505050565b60006149bc826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316614c159092919063ffffffff16565b90508051600014806149dd5750808060200190518101906149dd91906153e2565b6131b35760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401613c01565b606081600001805480602002602001604051908101604052809291908181526020018280548015614a8c57602002820191906000526020600020905b815481526020019060010190808311614a78575b50505050509050919050565b60008181526001830160205260408120548015614b81576000614abc600183615b56565b8554909150600090614ad090600190615b56565b9050818114614b35576000866000018281548110614af057614af0615492565b9060005260206000200154905080876000018481548110614b1357614b13615492565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080614b4657614b46615c0a565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506117cc565b60009150506117cc565b600054610100900460ff16613da95760405162461bcd60e51b8152600401613c0190615bbf565b62461bcd60e51b600090815260206004526007602452600a808404818106603090810160081b958390069590950190829004918206850160101b01602363ffffff0060e086901c160160181b0190930160c81b604481905260e883901c91606490fd5b6060612063848460008585600080866001600160a01b03168587604051614c3c9190615c20565b60006040518083038185875af1925050503d8060008114614c79576040519150601f19603f3d011682016040523d82523d6000602084013e614c7e565b606091505b5091509150614c8f87838387614c9a565b979650505050505050565b60608315614d09578251600003614d02576001600160a01b0385163b614d025760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401613c01565b5081613de9565b613de98383815115614d1e5781518083602001fd5b8060405162461bcd60e51b8152600401613c019190615165565b6001600160a01b03811681146111ac57600080fd5b600080600080600060a08688031215614d6557600080fd5b853594506020860135614d7781614d38565b935060408601359250606086013591506080860135614d9581614d38565b809150509295509295909350565b60008083601f840112614db557600080fd5b5081356001600160401b03811115614dcc57600080fd5b6020830191508360208260051b8501011115614de757600080fd5b9250929050565b60008060008060008060608789031215614e0757600080fd5b86356001600160401b0380821115614e1e57600080fd5b614e2a8a838b01614da3565b90985096506020890135915080821115614e4357600080fd5b614e4f8a838b01614da3565b90965094506040890135915080821115614e6857600080fd5b818901915089601f830112614e7c57600080fd5b813581811115614e8b57600080fd5b8a6020828501011115614e9d57600080fd5b6020830194508093505050509295509295509295565b600060208284031215614ec557600080fd5b5035919050565b600060208284031215614ede57600080fd5b813561206681614d38565b60008060008060808587031215614eff57600080fd5b8435614f0a81614d38565b935060208501359250604085013591506060850135614f2881614d38565b939692955090935050565b61ffff811681146111ac57600080fd5b60008060408385031215614f5657600080fd5b8235614f6181614f33565b91506020830135614f7181614d38565b809150509250929050565b60008060008060808587031215614f9257600080fd5b843593506020850135614fa481614d38565b9250604085013591506060850135614f2881614d38565b600080600080600060a08688031215614fd357600080fd5b853594506020860135614fe581614d38565b9350604086013592506060860135614ffc81614d38565b949793965091946080013592915050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171561504b5761504b61500d565b604052919050565b60006001600160401b0382111561506c5761506c61500d565b50601f01601f191660200190565b60008060006060848603121561508f57600080fd5b833561509a81614d38565b92506020840135915060408401356001600160401b038111156150bc57600080fd5b8401601f810186136150cd57600080fd5b80356150e06150db82615053565b615023565b8181528760208385010111156150f557600080fd5b816020840160208301376000602083830101528093505050509250925092565b60005b83811015615130578181015183820152602001615118565b50506000910152565b60008151808452615151816020860160208601615115565b601f01601f19169290920160200192915050565b6020815260006120666020830184615139565b6000806040838503121561518b57600080fd5b8235614f6181614d38565b600080604083850312156151a957600080fd5b823591506020830135614f7181614f33565b6000806000606084860312156151d057600080fd5b83356151db81614d38565b95602085013595506040909401359392505050565b60008060008060008060c0878903121561520957600080fd5b86359550602087013561521b81614d38565b945060408701359350606087013561523281614d38565b9598949750929560808101359460a0909101359350915050565b6000806040838503121561525f57600080fd5b823591506020830135614f7181614d38565b6000806020838503121561528457600080fd5b82356001600160401b0381111561529a57600080fd5b6152a685828601614da3565b90969095509350505050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b8281101561530757603f198886030184526152f5858351615139565b945092850192908501906001016152d9565b5092979650505050505050565b60008060006060848603121561532957600080fd5b83359250602084013561533b81614d38565b929592945050506040919091013590565b60008060006060848603121561536157600080fd5b833561536c81614d38565b9250602084013561533b81614d38565b6000806000806080858703121561539257600080fd5b843561539d81614d38565b935060208501356153ad81614d38565b925060408501356153bd81614d38565b91506060850135614f2881614d38565b805180151581146153dd57600080fd5b919050565b6000602082840312156153f457600080fd5b612066826153cd565b60006080828403121561540f57600080fd5b604051608081018181106001600160401b03821117156154315761543161500d565b60405261543d836153cd565b815261544b602084016153cd565b602082015261545c604084016153cd565b604082015261546d606084016153cd565b60608201529392505050565b60006020828403121561548b57600080fd5b5051919050565b634e487b7160e01b600052603260045260246000fd5b80516001600160801b03811681146153dd57600080fd5b600060e082840312156154d157600080fd5b60405160e081018181106001600160401b03821117156154f3576154f361500d565b6040526154ff836154a8565b815261550d602084016154a8565b602082015261551e604084016153cd565b604082015261552f606084016153cd565b6060820152615540608084016153cd565b608082015261555160a084016153cd565b60a082015261556260c084016153cd565b60c08201529392505050565b60006020828403121561558057600080fd5b815161206681614d38565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b6060808252810186905260008760808301825b898110156155f75782356155da81614d38565b6001600160a01b03168252602092830192909101906001016155c7565b5083810360208501528681526001600160fb1b0387111561561757600080fd5b8660051b915081886020830137018281036020908101604085015261563f908201858761558b565b9998505050505050505050565b60006001600160401b038211156156655761566561500d565b5060051b60200190565b600082601f83011261568057600080fd5b815160206156906150db8361564c565b82815260059290921b840181019181810190868411156156af57600080fd5b8286015b848110156156d35780516156c681614d38565b83529183019183016156b3565b509695505050505050565b600082601f8301126156ef57600080fd5b815160206156ff6150db8361564c565b82815260059290921b8401810191818101908684111561571e57600080fd5b8286015b848110156156d35780518352918301918301615722565b6000806040838503121561574c57600080fd5b82516001600160401b038082111561576357600080fd5b61576f8683870161566f565b9350602085015191508082111561578557600080fd5b50615792858286016156de565b9150509250929050565b634e487b7160e01b600052601160045260246000fd5b80820281158282048414176117cc576117cc61579c565b61ffff9290921682526001600160a01b0316602082015260400190565b6000604082840312156157f857600080fd5b604051604081018181106001600160401b038211171561581a5761581a61500d565b604052615826836154a8565b8152615834602084016154a8565b60208201529392505050565b808201808211156117cc576117cc61579c565b61ffff9390931683526001600160a01b03919091166020830152604082015260600190565b634e487b7160e01b600052601260045260246000fd5b6000826158ab57634e487b7160e01b600052601260045260246000fd5b500490565b6020808252825182820181905260009190848201906040850190845b818110156158f15783516001600160a01b0316835292840192918401916001016158cc565b50909695505050505050565b60006020828403121561590f57600080fd5b81516001600160401b0381111561592557600080fd5b613de9848285016156de565b6001600160a01b038316815260406020820181905260009061206390830184615139565b60006159636150db84615053565b905082815283838301111561597757600080fd5b612066836020830184615115565b60006020828403121561599757600080fd5b81516001600160401b038111156159ad57600080fd5b8201601f810184136159be57600080fd5b613de984825160208401615955565b600082601f8301126159de57600080fd5b815160206159ee6150db8361564c565b82815260059290921b84018101918181019086841115615a0d57600080fd5b8286015b848110156156d35780516001600160401b03811115615a305760008081fd5b615a3e8986838b01016156de565b845250918301918301615a11565b600080600080600060a08688031215615a6457600080fd5b85516001600160401b0380821115615a7b57600080fd5b615a8789838a0161566f565b96506020880151915080821115615a9d57600080fd5b615aa989838a016156de565b95506040880151915080821115615abf57600080fd5b615acb89838a0161566f565b94506060880151915080821115615ae157600080fd5b615aed89838a016159cd565b93506080880151915080821115615b0357600080fd5b50615b10888289016159cd565b9150509295509295909350565b6000600160ff1b8201615b3257615b3261579c565b5060000390565b600060208284031215615b4b57600080fd5b815161206681614f33565b818103818111156117cc576117cc61579c565b6000808335601e19843603018112615b8057600080fd5b8301803591506001600160401b03821115615b9a57600080fd5b602001915036819003821315614de757600080fd5b8183823760009101908152919050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b634e487b7160e01b600052603160045260246000fd5b60008251615c32818460208701615115565b919091019291505056fea26469706673582212202f1dbd60cf95561e9c2149aa4f98310e6e180163544140d0c7ffd06b7596372e64736f6c63430008130033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba92000000000000000000000000ce3292ca5abbdfa1db02142a67cffc708530675a
-----Decoded View---------------
Arg [0] : _posManager (address): 0x0e7401707CD08c03CDb53DAEF3295DDFb68BBa92
Arg [1] : _acm (address): 0xCE3292cA5AbbdFA1Db02142A67CFFc708530675a
-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba92
Arg [1] : 000000000000000000000000ce3292ca5abbdfa1db02142a67cffc708530675a
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in MNT
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.