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
Contract Name:
MoneyMarketHook
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 '../common/library/InitErrors.sol';
import '../common/library/UncheckedIncrement.sol';
import {UnderACM} from '../common/UnderACM.sol';
import {IInitCore} from '../interfaces/core/IInitCore.sol';
import {IMulticall} from '../interfaces/common/IMulticall.sol';
import {IPosManager} from '../interfaces/core/IPosManager.sol';
import {ILendingPool} from '../interfaces/lending_pool/ILendingPool.sol';
import {IWNative} from '../interfaces/common/IWNative.sol';
import {IRebaseHelper} from '../interfaces/helper/rebase_helper/IRebaseHelper.sol';
import {IMoneyMarketHook} from '../interfaces/hook/IMoneyMarketHook.sol';
import {IERC20} from '@openzeppelin-contracts/token/ERC20/IERC20.sol';
import {IERC721} from '@openzeppelin-contracts/token/ERC721/IERC721.sol';
import {SafeERC20} from '@openzeppelin-contracts/token/ERC20/utils/SafeERC20.sol';
import {ERC721HolderUpgradeable} from
'@openzeppelin-contracts-upgradeable/token/ERC721/utils/ERC721HolderUpgradeable.sol';
import {ReentrancyGuardUpgradeable} from '@openzeppelin-contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol';
// NOTE: only support normal money market actions (deposit, withdraw, borrow, repay, change position mode)
// doesn't support wLp
contract MoneyMarketHook is IMoneyMarketHook, ERC721HolderUpgradeable, ReentrancyGuardUpgradeable, UnderACM {
using UncheckedIncrement for uint;
using SafeERC20 for IERC20;
// constants
bytes32 private constant GUARDIAN = keccak256('guardian');
// immutables
/// @inheritdoc IMoneyMarketHook
address public immutable CORE;
/// @inheritdoc IMoneyMarketHook
address public immutable POS_MANAGER;
/// @inheritdoc IMoneyMarketHook
address public immutable WNATIVE;
// storages
/// @inheritdoc IMoneyMarketHook
mapping(address => uint) public lastPosIds;
/// @inheritdoc IMoneyMarketHook
mapping(address => mapping(uint => uint)) public initPosIds;
/// @inheritdoc IMoneyMarketHook
mapping(address => bool) public whitelistedHelpers;
// modifiers
modifier onlyGuardian() {
ACM.checkRole(GUARDIAN, msg.sender);
_;
}
// constructor
constructor(address _initCore, address _wNative, address _acm) UnderACM(_acm) {
CORE = _initCore;
POS_MANAGER = IInitCore(_initCore).POS_MANAGER();
WNATIVE = _wNative;
_disableInitializers();
}
// initialize
/// @dev initialize the contract
function initialize() external initializer {
__ReentrancyGuard_init();
}
// functions
/// @inheritdoc IMoneyMarketHook
function execute(OperationParams calldata _params)
external
payable
nonReentrant
returns (uint posId, uint initPosId, bytes[] memory results)
{
// create position if not exist
if (_params.posId == 0) {
(posId, initPosId) = createPos(_params.mode, _params.viewer);
} else {
// for existing position, only owner can execute
posId = _params.posId;
initPosId = initPosIds[msg.sender][posId];
_require(IERC721(POS_MANAGER).ownerOf(initPosId) == address(this), Errors.NOT_OWNER);
}
// NOTE: msg.value should be used for 1 operation only
results = _handleMulticall(initPosId, _params);
// check slippage
_require(_params.minHealth_e18 <= IInitCore(CORE).getPosHealthCurrent_e18(initPosId), Errors.SLIPPAGE_CONTROL);
// unwrap token if needed
for (uint i; i < _params.withdrawParams.length; i = i.uinc()) {
address helper = _params.withdrawParams[i].rebaseHelperParams.helper;
if (helper != address(0)) IRebaseHelper(helper).unwrap(_params.withdrawParams[i].to);
}
// return native token
if (_params.returnNative) {
uint wNativeBal = IERC20(WNATIVE).balanceOf(address(this));
// NOTE: no need receive function since we will use TransparentUpgradeableProxyReceiveETH
if (wNativeBal != 0) IWNative(WNATIVE).withdraw(wNativeBal);
uint nativeBal = address(this).balance;
if (nativeBal != 0) {
(bool success,) = payable(msg.sender).call{value: address(this).balance}('');
_require(success, Errors.CALL_FAILED);
}
}
}
/// @inheritdoc IMoneyMarketHook
function createPos(uint16 _mode, address _viewer) public returns (uint posId, uint initPosId) {
posId = ++lastPosIds[msg.sender];
initPosId = IInitCore(CORE).createPos(_mode, _viewer);
initPosIds[msg.sender][posId] = initPosId;
}
/// @inheritdoc IMoneyMarketHook
function setWhitelistedHelpers(address[] calldata _helpers, bool _status) external onlyGuardian {
for (uint i; i < _helpers.length; i = i.uinc()) {
whitelistedHelpers[_helpers[i]] = _status;
}
emit SetWhitelistedHelpers(_helpers, _status);
}
/// @dev approve token for init core if needed
/// @param _token token address
/// @param _amt token amount to spend
function _ensureApprove(address _token, uint _amt) internal {
if (IERC20(_token).allowance(address(this), CORE) < _amt) {
IERC20(_token).safeApprove(CORE, type(uint).max);
}
}
// @dev prepare and execute multicall
// @param _initPosId init position id (nft id)
// @param _params operation parameters
// @return results results of multicall
function _handleMulticall(uint _initPosId, OperationParams calldata _params)
internal
returns (bytes[] memory results)
{
// prepare data for multicall
// 1. repay (if needed)
// 2. withdraw (if needed)
// 3. change position mode (if needed)
// 4. borrow (if needed)
// 5. deposit (if needed)
bool changeMode = _params.mode != 0 && _params.mode != IPosManager(POS_MANAGER).getPosMode(_initPosId);
bytes[] memory data;
{
uint dataLength = _params.repayParams.length + (2 * _params.withdrawParams.length) + (changeMode ? 1 : 0)
+ _params.borrowParams.length + (2 * _params.depositParams.length);
data = new bytes[](dataLength);
}
uint offset;
// 1. repay
(offset, data) = _handleRepay(offset, data, _initPosId, _params.repayParams);
// 2. withdraw
(offset, data) = _handleWithdraw(offset, data, _initPosId, _params.withdrawParams, _params.returnNative);
// 3. change position mode
if (changeMode) {
data[offset] = abi.encodeWithSelector(IInitCore.setPosMode.selector, _initPosId, _params.mode);
offset = offset.uinc();
}
// 4. borrow
(offset, data) = _handleBorrow(offset, data, _initPosId, _params.borrowParams);
// 5. deposit
(offset, data) = _handleDeposit(offset, data, _initPosId, _params.depositParams);
// execute multicall
results = IMulticall(CORE).multicall(data);
}
/// @dev generate repay data for multicall
/// @param _offset offset of data
/// @param _data multicall data
/// @param _initPosId init position id (nft id)
/// @param _params repay params
/// @return offset new offset
/// @return data new data
function _handleRepay(uint _offset, bytes[] memory _data, uint _initPosId, RepayParams[] memory _params)
internal
returns (uint, bytes[] memory)
{
for (uint i; i < _params.length; i = i.uinc()) {
address uToken = ILendingPool(_params[i].pool).underlyingToken();
uint posDebtShares = IPosManager(POS_MANAGER).getPosDebtShares(_initPosId, _params[i].pool);
uint repayShares = _params[i].shares <= posDebtShares ? _params[i].shares : posDebtShares;
uint repayAmt = ILendingPool(_params[i].pool).debtShareToAmtCurrent(repayShares);
_ensureApprove(uToken, repayAmt);
if (uToken == WNATIVE) {
if (msg.value != 0) IWNative(WNATIVE).deposit{value: msg.value}();
repayAmt = repayAmt > msg.value ? repayAmt - msg.value : 0;
}
if (repayAmt != 0) IERC20(uToken).safeTransferFrom(msg.sender, address(this), repayAmt);
_data[_offset] =
abi.encodeWithSelector(IInitCore.repay.selector, _params[i].pool, _params[i].shares, _initPosId);
_offset = _offset.uinc();
}
return (_offset, _data);
}
/// @dev generate withdraw data for multicall
/// @param _offset offset of data
/// @param _data multicall data
/// @param _initPosId init position id (nft id)
/// @param _params withdraw params
/// @return offset new offset
/// @return data new data
function _handleWithdraw(
uint _offset,
bytes[] memory _data,
uint _initPosId,
WithdrawParams[] calldata _params,
bool _returnNative
) internal view returns (uint, bytes[] memory) {
for (uint i; i < _params.length; i = i.uinc()) {
// decollateralize to pool
_data[_offset] = abi.encodeWithSelector(
IInitCore.decollateralize.selector, _initPosId, _params[i].pool, _params[i].shares, _params[i].pool
);
_offset = _offset.uinc();
// burn collateral to underlying token
address helper = _params[i].rebaseHelperParams.helper;
address uToken = ILendingPool(_params[i].pool).underlyingToken();
address uTokenReceiver = _params[i].to;
if (uToken == WNATIVE && _returnNative) uTokenReceiver = address(this);
// if need to unwrap to rebase token
if (helper != address(0)) {
// check if the helper is whitelisted
_require(whitelistedHelpers[helper], Errors.NOT_WHITELISTED);
_require(
_params[i].rebaseHelperParams.tokenIn == uToken
&& IRebaseHelper(helper).YIELD_BEARING_TOKEN() == uToken,
Errors.INVALID_TOKEN_IN
);
uTokenReceiver = helper;
}
_data[_offset] = abi.encodeWithSelector(IInitCore.burnTo.selector, _params[i].pool, uTokenReceiver);
_offset = _offset.uinc();
}
return (_offset, _data);
}
/// @dev generate borrow data for multicall
/// @param _offset offset of data
/// @param _data multicall data
/// @param _initPosId init position id (nft id)
/// @param _params borrow params
/// @return offset new offset
/// @return data new data
function _handleBorrow(uint _offset, bytes[] memory _data, uint _initPosId, BorrowParams[] calldata _params)
internal
pure
returns (uint, bytes[] memory)
{
for (uint i; i < _params.length; i = i.uinc()) {
_data[_offset] = abi.encodeWithSelector(
IInitCore.borrow.selector, _params[i].pool, _params[i].amt, _initPosId, _params[i].to
);
_offset = _offset.uinc();
}
return (_offset, _data);
}
/// @dev generate deposit data for multicall
/// @param _offset offset of data
/// @param _data multicall data
/// @param _initPosId init position id (nft id)
/// @param _params deposit params
/// @return offset new offset
/// @return data new data
function _handleDeposit(uint _offset, bytes[] memory _data, uint _initPosId, DepositParams[] calldata _params)
internal
returns (uint, bytes[] memory)
{
for (uint i; i < _params.length; i = i.uinc()) {
address pool = _params[i].pool;
uint amt = _params[i].amt;
address uToken = ILendingPool(pool).underlyingToken();
address helper = _params[i].rebaseHelperParams.helper;
// 1. deposit native token
// NOTE: use msg.value for native token
// amt > 0 mean user want to use wNative too
if (uToken == WNATIVE) {
if (msg.value != 0) {
IWNative(WNATIVE).deposit{value: msg.value}();
IERC20(WNATIVE).safeTransfer(pool, msg.value);
}
// transfer wNative to pool will user want to use wNative
if (amt != 0) {
IERC20(WNATIVE).safeTransferFrom(msg.sender, pool, amt);
}
}
// 2. wrap rebase token to non-rebase token and deposit
else if (helper != address(0)) {
address tokenIn = _params[i].rebaseHelperParams.tokenIn;
// check if the helper is whitelisted
_require(whitelistedHelpers[helper], Errors.NOT_WHITELISTED);
_require(IRebaseHelper(helper).REBASE_TOKEN() == tokenIn, Errors.INVALID_TOKEN_IN);
_require(IRebaseHelper(helper).YIELD_BEARING_TOKEN() == uToken, Errors.INVALID_TOKEN_OUT);
IERC20(tokenIn).safeTransferFrom(msg.sender, helper, amt);
IRebaseHelper(helper).wrap(pool);
}
// 3. deposit normal erc20 token
else {
IERC20(uToken).safeTransferFrom(msg.sender, pool, amt);
}
// mint to position
_data[_offset] = abi.encodeWithSelector(IInitCore.mintTo.selector, pool, POS_MANAGER);
_offset = _offset.uinc();
// collateralize
_data[_offset] = abi.encodeWithSelector(IInitCore.collateralize.selector, _initPosId, pool);
_offset = _offset.uinc();
}
return (_offset, _data);
}
receive() external payable {
_require(msg.sender == WNATIVE, Errors.NOT_WNATIVE);
}
}// 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: 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;
/// @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: None
pragma solidity ^0.8.19;
import {IERC20} from '@openzeppelin-contracts/token/ERC20/IERC20.sol';
/// @title Wrapped Native Interface
interface IWNative is IERC20 {
/// @dev wrap the native token to wrapped token using `msg.value` as the amount
function deposit() external payable;
/// @dev unwrap the wrapped token to native token
/// @param amount token amount to unwrap
function withdraw(uint amount) external;
}// 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;
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;
interface IRebaseHelper {
/// @dev non-rebase token (ex. wsteth)
function YIELD_BEARING_TOKEN() external view returns (address);
/// @dev rebase token (ex. steth)
function REBASE_TOKEN() external view returns (address);
/// @dev wrap the rebase token to yield bearing token then send to _to (ex. steth->wsteth)
/// @param _to address to receive the wrapped token
/// @return amtOut amount of token out
function wrap(address _to) external returns (uint amtOut);
/// @dev unwrap the yield bearing token to rebase token then send to _to (ex. wsteth->steth)
/// @param _to address to receive the unwrapped token
/// @return amtOut amount of token out
function unwrap(address _to) external returns (uint amtOut);
}// SPDX-License-Identifier: None
pragma solidity ^0.8.19;
interface IMoneyMarketHook {
event SetWhitelistedHelpers(address[] _helpers, bool status);
// struct
struct RebaseHelperParams {
address helper; // wrap helper address if address(0) then not wrap
address tokenIn; // token to use in rebase helper
}
// NOTE: there is 3 types of deposit
// 1. deposit native token use msg.value for native token
// if amt > 0 mean user want to use wNative too
// 2. wrap rebase token to non-rebase token and deposit (using rebase helper)
// 3. deposit normal erc20 token
struct DepositParams {
address pool; // lending pool to deposit
uint amt; // token amount to deposit
RebaseHelperParams rebaseHelperParams; // wrap params
}
struct WithdrawParams {
address pool; // lending pool to withdraw
uint shares; // shares to withdraw
RebaseHelperParams rebaseHelperParams; // wrap params
address to; // receiver to receive withdraw tokens
}
struct RepayParams {
address pool; // lending pool to repay
uint shares; // shares to repay
}
struct BorrowParams {
address pool; // lending pool to borrow
uint amt; // token amount to borrow
address to; // receiver to receive borrow tokens
}
struct OperationParams {
uint posId; // position id to execute (0 to create new position)
address viewer; // address to view position
uint16 mode; // position mode to be used
DepositParams[] depositParams; // deposit parameters
WithdrawParams[] withdrawParams; // withdraw parameters
BorrowParams[] borrowParams; // borrow parameters
RepayParams[] repayParams; // repay parameters
uint minHealth_e18; // minimum health to maintain after execute
bool returnNative; // return native token or not (using balanceOf(address(this)))
}
// function
/// @dev get the core address
function CORE() external view returns (address);
/// @dev get the position manager address
function POS_MANAGER() external view returns (address);
/// @dev get the wNative address
function WNATIVE() external view returns (address);
/// @dev get last user's position id
/// @param _user user address
/// @return posId last user's position id
function lastPosIds(address _user) external view returns (uint posId);
/// @dev get the init position id (nft id)
/// @param _user user address
/// @param _posId position id
/// @return initPosId init position id (nft id)
function initPosIds(address _user, uint _posId) external view returns (uint initPosId);
/// @dev check if the helper is whitelisted.
/// @param _helper helper address
/// @return whether the helper is whitelisted.
function whitelistedHelpers(address _helper) external view returns (bool);
/// @dev execute all position actions in one transaction via multicall (to avoid multiple health check)
/// @param _params operation parameters
/// @return posId hook position id
/// @return initPosId init position id (nft id)
/// @return results results of multicall
function execute(OperationParams calldata _params)
external
payable
returns (uint posId, uint initPosId, bytes[] memory results);
/// @dev create new position
/// @param _mode position mode to be used
/// @param _viewer address to view position
/// @return posId hook position id
/// @return initPosId init position id (nft id)
function createPos(uint16 _mode, address _viewer) external returns (uint posId, uint initPosId);
/// @notice only guardian role can call
/// @dev set whitelisted helper statuses
/// @param _helpers helper list
/// @param _status whitelisted status to set to
function setWhitelistedHelpers(address[] calldata _helpers, bool _status) 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: 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.6.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721ReceiverUpgradeable {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/utils/ERC721Holder.sol)
pragma solidity ^0.8.0;
import "../IERC721ReceiverUpgradeable.sol";
import "../../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the {IERC721Receiver} interface.
*
* Accepts all token transfers.
* Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or {IERC721-setApprovalForAll}.
*/
contract ERC721HolderUpgradeable is Initializable, IERC721ReceiverUpgradeable {
function __ERC721Holder_init() internal onlyInitializing {
}
function __ERC721Holder_init_unchained() internal onlyInitializing {
}
/**
* @dev See {IERC721Receiver-onERC721Received}.
*
* Always returns `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(address, address, uint256, bytes memory) public virtual override returns (bytes4) {
return this.onERC721Received.selector;
}
/**
* @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[50] 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) (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.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;
}
}{
"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/=lib/openzeppelin-contracts/contracts/",
"@openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"ds-test/=lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"openzeppelin-contracts copy/=lib/openzeppelin-contracts copy/",
"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":"_initCore","type":"address"},{"internalType":"address","name":"_wNative","type":"address"},{"internalType":"address","name":"_acm","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address[]","name":"_helpers","type":"address[]"},{"indexed":false,"internalType":"bool","name":"status","type":"bool"}],"name":"SetWhitelistedHelpers","type":"event"},{"inputs":[],"name":"ACM","outputs":[{"internalType":"contract IAccessControlManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"CORE","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"POS_MANAGER","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WNATIVE","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"},{"internalType":"uint256","name":"initPosId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"posId","type":"uint256"},{"internalType":"address","name":"viewer","type":"address"},{"internalType":"uint16","name":"mode","type":"uint16"},{"components":[{"internalType":"address","name":"pool","type":"address"},{"internalType":"uint256","name":"amt","type":"uint256"},{"components":[{"internalType":"address","name":"helper","type":"address"},{"internalType":"address","name":"tokenIn","type":"address"}],"internalType":"struct IMoneyMarketHook.RebaseHelperParams","name":"rebaseHelperParams","type":"tuple"}],"internalType":"struct IMoneyMarketHook.DepositParams[]","name":"depositParams","type":"tuple[]"},{"components":[{"internalType":"address","name":"pool","type":"address"},{"internalType":"uint256","name":"shares","type":"uint256"},{"components":[{"internalType":"address","name":"helper","type":"address"},{"internalType":"address","name":"tokenIn","type":"address"}],"internalType":"struct IMoneyMarketHook.RebaseHelperParams","name":"rebaseHelperParams","type":"tuple"},{"internalType":"address","name":"to","type":"address"}],"internalType":"struct IMoneyMarketHook.WithdrawParams[]","name":"withdrawParams","type":"tuple[]"},{"components":[{"internalType":"address","name":"pool","type":"address"},{"internalType":"uint256","name":"amt","type":"uint256"},{"internalType":"address","name":"to","type":"address"}],"internalType":"struct IMoneyMarketHook.BorrowParams[]","name":"borrowParams","type":"tuple[]"},{"components":[{"internalType":"address","name":"pool","type":"address"},{"internalType":"uint256","name":"shares","type":"uint256"}],"internalType":"struct IMoneyMarketHook.RepayParams[]","name":"repayParams","type":"tuple[]"},{"internalType":"uint256","name":"minHealth_e18","type":"uint256"},{"internalType":"bool","name":"returnNative","type":"bool"}],"internalType":"struct IMoneyMarketHook.OperationParams","name":"_params","type":"tuple"}],"name":"execute","outputs":[{"internalType":"uint256","name":"posId","type":"uint256"},{"internalType":"uint256","name":"initPosId","type":"uint256"},{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"initPosIds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"lastPosIds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_helpers","type":"address[]"},{"internalType":"bool","name":"_status","type":"bool"}],"name":"setWhitelistedHelpers","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"whitelistedHelpers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]Contract Creation Code
6101006040523480156200001257600080fd5b5060405162002dd538038062002dd58339810160408190526200003591620001af565b6001600160a01b03808216608052831660a08190526040805162278b6760e41b81529051630278b670916004808201926020929091908290030181865afa15801562000085573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620000ab9190620001f9565b6001600160a01b0390811660c052821660e052620000c8620000d1565b5050506200021e565b600054610100900460ff16156200013e5760405162461bcd60e51b815260206004820152602760248201527f496e697469616c697a61626c653a20636f6e747261637420697320696e697469604482015266616c697a696e6760c81b606482015260840160405180910390fd5b60005460ff9081161462000190576000805460ff191660ff9081179091556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b565b80516001600160a01b0381168114620001aa57600080fd5b919050565b600080600060608486031215620001c557600080fd5b620001d08462000192565b9250620001e06020850162000192565b9150620001f06040850162000192565b90509250925092565b6000602082840312156200020c57600080fd5b620002178262000192565b9392505050565b60805160a05160c05160e051612af3620002e26000396000818160be015281816102fc01528181610670015281816107010152818161120e0152818161124d015281816115d2015281816119f701528181611a3601528181611ab40152611af201526000818160ff015281816103ff01528181610bbc015281816110640152611d000152600081816102b3015281816104aa0152818161082901528181610eac01528181611e500152611edb01526000818161033001526108fb0152612af36000f3fe6080604052600436106100ab5760003560e01c80632fb4bf64116100645780632fb4bf641461024c5780634f327fd8146102815780636b6c0774146102a15780638129fc1c146102d5578063b381cf40146102ea578063f9b80da11461031e57600080fd5b80630278b670146100ed57806309be26381461013e5780630a2f0bbd14610179578063127e12eb146101b9578063150b7a02146101f1578063247d49811461022a57600080fd5b366100e8576100e6336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146069610352565b005b600080fd5b3480156100f957600080fd5b506101217f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020015b60405180910390f35b34801561014a57600080fd5b5061016b6101593660046122ca565b60656020526000908152604090205481565b604051908152602001610135565b34801561018557600080fd5b506101a96101943660046122ca565b60676020526000908152604090205460ff1681565b6040519015158152602001610135565b3480156101c557600080fd5b5061016b6101d43660046122ee565b606660209081526000928352604080842090915290825290205481565b3480156101fd57600080fd5b5061021161020c366004612389565b610364565b6040516001600160e01b03199091168152602001610135565b61023d610238366004612438565b610375565b6040516101359392919061251c565b34801561025857600080fd5b5061026c610267366004612554565b6107d9565b60408051928352602083019190915201610135565b34801561028d57600080fd5b506100e661029c36600461259b565b6108c0565b3480156102ad57600080fd5b506101217f000000000000000000000000000000000000000000000000000000000000000081565b3480156102e157600080fd5b506100e6610a07565b3480156102f657600080fd5b506101217f000000000000000000000000000000000000000000000000000000000000000081565b34801561032a57600080fd5b506101217f000000000000000000000000000000000000000000000000000000000000000081565b816103605761036081610b1d565b5050565b630a85bd0160e11b5b949350505050565b6000806060610382610b2d565b83356000036103b8576103ae61039e6060860160408701612621565b61026760408701602088016122ca565b909350915061047b565b33600090815260666020908152604080832087358085529252918290205491516331a9108f60e11b81526004810183905290945090925061047b9030906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690636352211e90602401602060405180830381865afa158015610446573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061046a919061263e565b6001600160a01b0316146068610352565b6104858285610b86565b60405163a72ca39b60e01b815260048101849052909150610525906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063a72ca39b906024016020604051808303816000875af11580156104f3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610517919061265b565b8560e0013511156066610352565b60005b6105356080860186612674565b905081101561064057600061054d6080870187612674565b8381811061055d5761055d6126c4565b61057692606060a09092020190810191506040016122ca565b90506001600160a01b03811615610637576001600160a01b0381166375f26e636105a36080890189612674565b858181106105b3576105b36126c4565b905060a0020160800160208101906105cb91906122ca565b6040516001600160e01b031960e084901b1681526001600160a01b0390911660048201526024016020604051808303816000875af1158015610611573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610635919061265b565b505b50600101610528565b50610653610120850161010086016126da565b156107c8576040516370a0823160e01b81523060048201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906370a0823190602401602060405180830381865afa1580156106bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106e3919061265b565b9050801561076657604051632e1a7d4d60e01b8152600481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690632e1a7d4d90602401600060405180830381600087803b15801561074d57600080fd5b505af1158015610761573d6000803e3d6000fd5b505050505b4780156107c557604051600090339047908381818185875af1925050503d80600081146107af576040519150601f19603f3d011682016040523d82523d6000602084013e6107b4565b606091505b505090506107c3816067610352565b505b50505b6107d26001603355565b9193909250565b336000908152606560205260408120805482919082906107f89061270d565b9182905550604051630bed2fd960e21b815261ffff861660048201526001600160a01b0385811660248301529193507f000000000000000000000000000000000000000000000000000000000000000090911690632fb4bf64906044016020604051808303816000875af1158015610874573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610898919061265b565b3360009081526066602090815260408083208684529091529020819055919491935090915050565b6040516312d9a6ad60e01b81527f8fbcb4375b910093bcf636b6b2f26b26eda2a29ef5a8ee7de44b5743c3bf9a2860048201523360248201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906312d9a6ad90604401600060405180830381600087803b15801561094757600080fd5b505af115801561095b573d6000803e3d6000fd5b5050505060005b828110156109c6578160676000868685818110610981576109816126c4565b905060200201602081019061099691906122ca565b6001600160a01b031681526020810191909152604001600020805460ff1916911515919091179055600101610962565b507f3a6fcf102feea447bad9bc18ed415c630a66c2a24498ba6c15e06e26a6fb8afa8383836040516109fa93929190612726565b60405180910390a1505050565b600054610100900460ff1615808015610a275750600054600160ff909116105b80610a415750303b158015610a41575060005460ff166001145b610aa95760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084015b60405180910390fd5b6000805460ff191660011790558015610acc576000805461ff0019166101001790555b610ad4610f39565b8015610b1a576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b50565b610b1a8162494e4360e81b610f6a565b600260335403610b7f5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610aa0565b6002603355565b60606000610b9983830160408501612621565b61ffff1615801590610c4a5750604051633e4b135360e21b8152600481018590527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063f92c4d4c90602401602060405180830381865afa158015610c0b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c2f919061277f565b61ffff16610c436060850160408601612621565b61ffff1614155b905060606000610c5c8583018661279c565b610c68915060026127e6565b610c7560a0870187612803565b905084610c83576000610c86565b60015b60ff16610c966080890189612674565b610ca2915060026127e6565b610caf60c08a018a61284c565b610cba929150612896565b610cc49190612896565b610cce9190612896565b610cd89190612896565b90508067ffffffffffffffff811115610cf357610cf361231a565b604051908082528060200260200182016040528015610d2657816020015b6060815260200190600190039081610d115790505b50915060009050610d96818388610d4060c08a018a61284c565b808060200260200160405190810160405280939291908181526020016000905b82821015610d8c57610d7d604083028601368190038101906128a9565b81526020019060010190610d60565b5050505050610fcd565b92509050610dc4818388610dad60808a018a612674565b610dbf6101208c016101008d016126da565b6113da565b925090508215610e5b57638802944160e01b86610de76060880160408901612621565b604051602481019290925261ffff166044820152606401604051602081830303815290604052906001600160e01b0319166020820180516001600160e01b038381831617835250505050828281518110610e4357610e436126c4565b6020026020010181905250610e588160010190565b90505b610e73818388610e6e60a08a018a612803565b6117e1565b92509050610e8f818388610e8a60608a018a61279c565b611905565b604051631592ca1b60e31b81529093509091506001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063ac9650d890610ee1908590600401612901565b6000604051808303816000875af1158015610f00573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610f289190810190612914565b9695505050505050565b6001603355565b600054610100900460ff16610f605760405162461bcd60e51b8152600401610aa090612a13565b610f68611e0c565b565b62461bcd60e51b600090815260206004526007602452600a808404818106603090810160081b958390069590950190829004918206850160101b01602363ffffff0060e086901c160160181b0190930160c81b604481905260e883901c91606490fd5b6000606060005b83518110156113cf576000848281518110610ff157610ff16126c4565b6020026020010151600001516001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa15801561103a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061105e919061263e565b905060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166310e28e71888886815181106110a4576110a46126c4565b6020026020010151600001516040518363ffffffff1660e01b81526004016110df9291909182526001600160a01b0316602082015260400190565b602060405180830381865afa1580156110fc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611120919061265b565b9050600081878581518110611137576111376126c4565b602002602001015160200151111561114f578161116e565b868481518110611161576111616126c4565b6020026020010151602001515b90506000878581518110611184576111846126c4565b6020026020010151600001516001600160a01b03166331a86fe1836040518263ffffffff1660e01b81526004016111bd91815260200190565b6020604051808303816000875af11580156111dc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611200919061265b565b905061120c8482611e33565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316846001600160a01b0316036112db5734156112c0577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b1580156112a657600080fd5b505af11580156112ba573d6000803e3d6000fd5b50505050505b3481116112ce5760006112d8565b6112d83482612a5e565b90505b80156112f6576112f66001600160a01b038516333084611f02565b638cd2e0c760e01b888681518110611310576113106126c4565b60200260200101516000015189878151811061132e5761132e6126c4565b60209081029190910181015101516040516001600160a01b0390921660248301526044820152606481018b9052608401604051602081830303815290604052906001600160e01b0319166020820180516001600160e01b0383818316178352505050508a8c815181106113a3576113a36126c4565b60200260200101819052506113b88b60010190565b9a50505050506113c88160010190565b9050610fd4565b509495939450505050565b6000606060005b848110156117d4576342d91bc360e01b87878784818110611404576114046126c4565b61141a92602060a09092020190810191506122ca565b88888581811061142c5761142c6126c4565b905060a0020160200135898986818110611448576114486126c4565b61145e92602060a09092020190810191506122ca565b60405160248101949094526001600160a01b039283166044850152606484019190915216608482015260a401604051602081830303815290604052906001600160e01b0319166020820180516001600160e01b038381831617835250505050888a815181106114cf576114cf6126c4565b60200260200101819052506114e48960010190565b985060008686838181106114fa576114fa6126c4565b61151392606060a09092020190810191506040016122ca565b90506000878784818110611529576115296126c4565b61153f92602060a09092020190810191506122ca565b6001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa15801561157c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115a0919061263e565b905060008888858181106115b6576115b66126c4565b905060a0020160800160208101906115ce91906122ca565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b031614801561160e5750865b156116165750305b6001600160a01b03831615611716576001600160a01b03831660009081526067602052604090205461164c9060ff16606b610352565b611713826001600160a01b03168a8a8781811061166b5761166b6126c4565b61168492608060a09092020190810191506060016122ca565b6001600160a01b031614801561170c5750826001600160a01b0316846001600160a01b0316638812805d6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156116dd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611701919061263e565b6001600160a01b0316145b60cc610352565b50815b637fe6bc3d60e01b898986818110611730576117306126c4565b61174692602060a09092020190810191506122ca565b6040516001600160a01b0391821660248201529083166044820152606401604051602081830303815290604052906001600160e01b0319166020820180516001600160e01b0383818316178352505050508b8d815181106117a9576117a96126c4565b60200260200101819052506117be8c60010190565b9b505050506117cd8160010190565b90506113e1565b5096979596505050505050565b6000606060005b838110156118f9576308ba54eb60e21b85858381811061180a5761180a6126c4565b61182092602060609092020190810191506122ca565b868684818110611832576118326126c4565b905060600201602001358888888681811061184f5761184f6126c4565b905060600201604001602081019061186791906122ca565b6040516001600160a01b03948516602482015260448101939093526064830191909152909116608482015260a401604051602081830303815290604052906001600160e01b0319166020820180516001600160e01b0383818316178352505050508789815181106118da576118da6126c4565b60200260200101819052506118ef8860010190565b97506001016117e8565b50959694955050505050565b6000606060005b838110156118f9576000858583818110611928576119286126c4565b61193e92602060809092020190810191506122ca565b90506000868684818110611954576119546126c4565b9050608002016020013590506000826001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa1580156119a0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119c4919061263e565b905060008888868181106119da576119da6126c4565b6119f392606060809092020190810191506040016122ca565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b031603611b1f573415611adf577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b158015611a8f57600080fd5b505af1158015611aa3573d6000803e3d6000fd5b50611adf9350506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016915086905034611f73565b8215611b1a57611b1a6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016338686611f02565b611cea565b6001600160a01b03811615611cd5576000898987818110611b4257611b426126c4565b611b599260809182020190810191506060016122ca565b6001600160a01b038316600090815260676020526040902054909150611b839060ff16606b610352565b611bce816001600160a01b0316836001600160a01b0316634abaf9216040518163ffffffff1660e01b8152600401602060405180830381865afa1580156116dd573d6000803e3d6000fd5b611c4e836001600160a01b0316836001600160a01b0316638812805d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611c19573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c3d919061263e565b6001600160a01b03161460cd610352565b611c636001600160a01b038216338487611f02565b6040516223276f60e41b81526001600160a01b03868116600483015283169063023276f0906024016020604051808303816000875af1158015611caa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cce919061265b565b5050611cea565b611cea6001600160a01b038316338686611f02565b604080516001600160a01b0386811660248301527f0000000000000000000000000000000000000000000000000000000000000000166044808301919091528251808303909101815260649091019091526020810180516001600160e01b0316634a8db60160e11b1790528b518c908e908110611d6957611d696126c4565b6020026020010181905250611d7e8c60010190565b60408051602481018d90526001600160a01b0387166044808301919091528251808303909101815260649091019091526020810180516001600160e01b031663abf4dd3960e01b1790528c51919d50908c908e908110611de057611de06126c4565b6020026020010181905250611df58c60010190565b9b5050505050611e058160010190565b905061190c565b600054610100900460ff16610f325760405162461bcd60e51b8152600401610aa090612a13565b604051636eb1769f60e11b81523060048201526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116602483015282919084169063dd62ed3e90604401602060405180830381865afa158015611ea2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ec6919061265b565b1015610360576103606001600160a01b0383167f0000000000000000000000000000000000000000000000000000000000000000600019611fa8565b6040516001600160a01b0380851660248301528316604482015260648101829052611f6d9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526120bd565b50505050565b6040516001600160a01b038316602482015260448101829052611fa390849063a9059cbb60e01b90606401611f36565b505050565b8015806120225750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa158015611ffc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612020919061265b565b155b61208d5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610aa0565b6040516001600160a01b038316602482015260448101829052611fa390849063095ea7b360e01b90606401611f36565b6000612112826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166121929092919063ffffffff16565b90508051600014806121335750808060200190518101906121339190612a71565b611fa35760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610aa0565b606061036d848460008585600080866001600160a01b031685876040516121b99190612a8e565b60006040518083038185875af1925050503d80600081146121f6576040519150601f19603f3d011682016040523d82523d6000602084013e6121fb565b606091505b509150915061220c87838387612217565b979650505050505050565b6060831561228657825160000361227f576001600160a01b0385163b61227f5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610aa0565b508161036d565b61036d838381511561229b5781518083602001fd5b8060405162461bcd60e51b8152600401610aa09190612aaa565b6001600160a01b0381168114610b1a57600080fd5b6000602082840312156122dc57600080fd5b81356122e7816122b5565b9392505050565b6000806040838503121561230157600080fd5b823561230c816122b5565b946020939093013593505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156123595761235961231a565b604052919050565b600067ffffffffffffffff82111561237b5761237b61231a565b50601f01601f191660200190565b6000806000806080858703121561239f57600080fd5b84356123aa816122b5565b935060208501356123ba816122b5565b925060408501359150606085013567ffffffffffffffff8111156123dd57600080fd5b8501601f810187136123ee57600080fd5b80356124016123fc82612361565b612330565b81815288602083850101111561241657600080fd5b8160208401602083013760006020838301015280935050505092959194509250565b60006020828403121561244a57600080fd5b813567ffffffffffffffff81111561246157600080fd5b820161012081850312156122e757600080fd5b60005b8381101561248f578181015183820152602001612477565b50506000910152565b600081518084526124b0816020860160208601612474565b601f01601f19169290920160200192915050565b600082825180855260208086019550808260051b84010181860160005b8481101561250f57601f198684030189526124fd838351612498565b988401989250908301906001016124e1565b5090979650505050505050565b83815282602082015260606040820152600061253b60608301846124c4565b95945050505050565b61ffff81168114610b1a57600080fd5b6000806040838503121561256757600080fd5b823561257281612544565b91506020830135612582816122b5565b809150509250929050565b8015158114610b1a57600080fd5b6000806000604084860312156125b057600080fd5b833567ffffffffffffffff808211156125c857600080fd5b818601915086601f8301126125dc57600080fd5b8135818111156125eb57600080fd5b8760208260051b850101111561260057600080fd5b602092830195509350508401356126168161258d565b809150509250925092565b60006020828403121561263357600080fd5b81356122e781612544565b60006020828403121561265057600080fd5b81516122e7816122b5565b60006020828403121561266d57600080fd5b5051919050565b6000808335601e1984360301811261268b57600080fd5b83018035915067ffffffffffffffff8211156126a657600080fd5b602001915060a0810236038213156126bd57600080fd5b9250929050565b634e487b7160e01b600052603260045260246000fd5b6000602082840312156126ec57600080fd5b81356122e78161258d565b634e487b7160e01b600052601160045260246000fd5b60006001820161271f5761271f6126f7565b5060010190565b6040808252810183905260008460608301825b8681101561276957823561274c816122b5565b6001600160a01b0316825260209283019290910190600101612739565b5080925050508215156020830152949350505050565b60006020828403121561279157600080fd5b81516122e781612544565b6000808335601e198436030181126127b357600080fd5b83018035915067ffffffffffffffff8211156127ce57600080fd5b6020019150600781901b36038213156126bd57600080fd5b80820281158282048414176127fd576127fd6126f7565b92915050565b6000808335601e1984360301811261281a57600080fd5b83018035915067ffffffffffffffff82111561283557600080fd5b60200191506060810236038213156126bd57600080fd5b6000808335601e1984360301811261286357600080fd5b83018035915067ffffffffffffffff82111561287e57600080fd5b6020019150600681901b36038213156126bd57600080fd5b808201808211156127fd576127fd6126f7565b6000604082840312156128bb57600080fd5b6040516040810181811067ffffffffffffffff821117156128de576128de61231a565b60405282356128ec816122b5565b81526020928301359281019290925250919050565b6020815260006122e760208301846124c4565b6000602080838503121561292757600080fd5b825167ffffffffffffffff8082111561293f57600080fd5b818501915085601f83011261295357600080fd5b8151818111156129655761296561231a565b8060051b612974858201612330565b918252838101850191858101908984111561298e57600080fd5b86860192505b83831015612a06578251858111156129ac5760008081fd5b8601603f81018b136129be5760008081fd5b8781015160406129d06123fc83612361565b8281528d828486010111156129e55760008081fd5b6129f4838c8301848701612474565b85525050509186019190860190612994565b9998505050505050505050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b818103818111156127fd576127fd6126f7565b600060208284031215612a8357600080fd5b81516122e78161258d565b60008251612aa0818460208701612474565b9190910192915050565b6020815260006122e7602083018461249856fea2646970667358221220b25097e195849ae9881303d90053f1089d7a2c70f36e9b3747ec5e4471f5959164736f6c63430008130033000000000000000000000000972bcb0284cca0152527c4f70f8f689852bcafc500000000000000000000000078c1b0c915c4faa5fffa6cabf0219da63d7f4cb8000000000000000000000000ce3292ca5abbdfa1db02142a67cffc708530675a
Deployed Bytecode
0x6080604052600436106100ab5760003560e01c80632fb4bf64116100645780632fb4bf641461024c5780634f327fd8146102815780636b6c0774146102a15780638129fc1c146102d5578063b381cf40146102ea578063f9b80da11461031e57600080fd5b80630278b670146100ed57806309be26381461013e5780630a2f0bbd14610179578063127e12eb146101b9578063150b7a02146101f1578063247d49811461022a57600080fd5b366100e8576100e6336001600160a01b037f00000000000000000000000078c1b0c915c4faa5fffa6cabf0219da63d7f4cb816146069610352565b005b600080fd5b3480156100f957600080fd5b506101217f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba9281565b6040516001600160a01b0390911681526020015b60405180910390f35b34801561014a57600080fd5b5061016b6101593660046122ca565b60656020526000908152604090205481565b604051908152602001610135565b34801561018557600080fd5b506101a96101943660046122ca565b60676020526000908152604090205460ff1681565b6040519015158152602001610135565b3480156101c557600080fd5b5061016b6101d43660046122ee565b606660209081526000928352604080842090915290825290205481565b3480156101fd57600080fd5b5061021161020c366004612389565b610364565b6040516001600160e01b03199091168152602001610135565b61023d610238366004612438565b610375565b6040516101359392919061251c565b34801561025857600080fd5b5061026c610267366004612554565b6107d9565b60408051928352602083019190915201610135565b34801561028d57600080fd5b506100e661029c36600461259b565b6108c0565b3480156102ad57600080fd5b506101217f000000000000000000000000972bcb0284cca0152527c4f70f8f689852bcafc581565b3480156102e157600080fd5b506100e6610a07565b3480156102f657600080fd5b506101217f00000000000000000000000078c1b0c915c4faa5fffa6cabf0219da63d7f4cb881565b34801561032a57600080fd5b506101217f000000000000000000000000ce3292ca5abbdfa1db02142a67cffc708530675a81565b816103605761036081610b1d565b5050565b630a85bd0160e11b5b949350505050565b6000806060610382610b2d565b83356000036103b8576103ae61039e6060860160408701612621565b61026760408701602088016122ca565b909350915061047b565b33600090815260666020908152604080832087358085529252918290205491516331a9108f60e11b81526004810183905290945090925061047b9030906001600160a01b037f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba921690636352211e90602401602060405180830381865afa158015610446573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061046a919061263e565b6001600160a01b0316146068610352565b6104858285610b86565b60405163a72ca39b60e01b815260048101849052909150610525906001600160a01b037f000000000000000000000000972bcb0284cca0152527c4f70f8f689852bcafc5169063a72ca39b906024016020604051808303816000875af11580156104f3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610517919061265b565b8560e0013511156066610352565b60005b6105356080860186612674565b905081101561064057600061054d6080870187612674565b8381811061055d5761055d6126c4565b61057692606060a09092020190810191506040016122ca565b90506001600160a01b03811615610637576001600160a01b0381166375f26e636105a36080890189612674565b858181106105b3576105b36126c4565b905060a0020160800160208101906105cb91906122ca565b6040516001600160e01b031960e084901b1681526001600160a01b0390911660048201526024016020604051808303816000875af1158015610611573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610635919061265b565b505b50600101610528565b50610653610120850161010086016126da565b156107c8576040516370a0823160e01b81523060048201526000907f00000000000000000000000078c1b0c915c4faa5fffa6cabf0219da63d7f4cb86001600160a01b0316906370a0823190602401602060405180830381865afa1580156106bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106e3919061265b565b9050801561076657604051632e1a7d4d60e01b8152600481018290527f00000000000000000000000078c1b0c915c4faa5fffa6cabf0219da63d7f4cb86001600160a01b031690632e1a7d4d90602401600060405180830381600087803b15801561074d57600080fd5b505af1158015610761573d6000803e3d6000fd5b505050505b4780156107c557604051600090339047908381818185875af1925050503d80600081146107af576040519150601f19603f3d011682016040523d82523d6000602084013e6107b4565b606091505b505090506107c3816067610352565b505b50505b6107d26001603355565b9193909250565b336000908152606560205260408120805482919082906107f89061270d565b9182905550604051630bed2fd960e21b815261ffff861660048201526001600160a01b0385811660248301529193507f000000000000000000000000972bcb0284cca0152527c4f70f8f689852bcafc590911690632fb4bf64906044016020604051808303816000875af1158015610874573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610898919061265b565b3360009081526066602090815260408083208684529091529020819055919491935090915050565b6040516312d9a6ad60e01b81527f8fbcb4375b910093bcf636b6b2f26b26eda2a29ef5a8ee7de44b5743c3bf9a2860048201523360248201527f000000000000000000000000ce3292ca5abbdfa1db02142a67cffc708530675a6001600160a01b0316906312d9a6ad90604401600060405180830381600087803b15801561094757600080fd5b505af115801561095b573d6000803e3d6000fd5b5050505060005b828110156109c6578160676000868685818110610981576109816126c4565b905060200201602081019061099691906122ca565b6001600160a01b031681526020810191909152604001600020805460ff1916911515919091179055600101610962565b507f3a6fcf102feea447bad9bc18ed415c630a66c2a24498ba6c15e06e26a6fb8afa8383836040516109fa93929190612726565b60405180910390a1505050565b600054610100900460ff1615808015610a275750600054600160ff909116105b80610a415750303b158015610a41575060005460ff166001145b610aa95760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084015b60405180910390fd5b6000805460ff191660011790558015610acc576000805461ff0019166101001790555b610ad4610f39565b8015610b1a576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b50565b610b1a8162494e4360e81b610f6a565b600260335403610b7f5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610aa0565b6002603355565b60606000610b9983830160408501612621565b61ffff1615801590610c4a5750604051633e4b135360e21b8152600481018590527f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba926001600160a01b03169063f92c4d4c90602401602060405180830381865afa158015610c0b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c2f919061277f565b61ffff16610c436060850160408601612621565b61ffff1614155b905060606000610c5c8583018661279c565b610c68915060026127e6565b610c7560a0870187612803565b905084610c83576000610c86565b60015b60ff16610c966080890189612674565b610ca2915060026127e6565b610caf60c08a018a61284c565b610cba929150612896565b610cc49190612896565b610cce9190612896565b610cd89190612896565b90508067ffffffffffffffff811115610cf357610cf361231a565b604051908082528060200260200182016040528015610d2657816020015b6060815260200190600190039081610d115790505b50915060009050610d96818388610d4060c08a018a61284c565b808060200260200160405190810160405280939291908181526020016000905b82821015610d8c57610d7d604083028601368190038101906128a9565b81526020019060010190610d60565b5050505050610fcd565b92509050610dc4818388610dad60808a018a612674565b610dbf6101208c016101008d016126da565b6113da565b925090508215610e5b57638802944160e01b86610de76060880160408901612621565b604051602481019290925261ffff166044820152606401604051602081830303815290604052906001600160e01b0319166020820180516001600160e01b038381831617835250505050828281518110610e4357610e436126c4565b6020026020010181905250610e588160010190565b90505b610e73818388610e6e60a08a018a612803565b6117e1565b92509050610e8f818388610e8a60608a018a61279c565b611905565b604051631592ca1b60e31b81529093509091506001600160a01b037f000000000000000000000000972bcb0284cca0152527c4f70f8f689852bcafc5169063ac9650d890610ee1908590600401612901565b6000604051808303816000875af1158015610f00573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610f289190810190612914565b9695505050505050565b6001603355565b600054610100900460ff16610f605760405162461bcd60e51b8152600401610aa090612a13565b610f68611e0c565b565b62461bcd60e51b600090815260206004526007602452600a808404818106603090810160081b958390069590950190829004918206850160101b01602363ffffff0060e086901c160160181b0190930160c81b604481905260e883901c91606490fd5b6000606060005b83518110156113cf576000848281518110610ff157610ff16126c4565b6020026020010151600001516001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa15801561103a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061105e919061263e565b905060007f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba926001600160a01b03166310e28e71888886815181106110a4576110a46126c4565b6020026020010151600001516040518363ffffffff1660e01b81526004016110df9291909182526001600160a01b0316602082015260400190565b602060405180830381865afa1580156110fc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611120919061265b565b9050600081878581518110611137576111376126c4565b602002602001015160200151111561114f578161116e565b868481518110611161576111616126c4565b6020026020010151602001515b90506000878581518110611184576111846126c4565b6020026020010151600001516001600160a01b03166331a86fe1836040518263ffffffff1660e01b81526004016111bd91815260200190565b6020604051808303816000875af11580156111dc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611200919061265b565b905061120c8482611e33565b7f00000000000000000000000078c1b0c915c4faa5fffa6cabf0219da63d7f4cb86001600160a01b0316846001600160a01b0316036112db5734156112c0577f00000000000000000000000078c1b0c915c4faa5fffa6cabf0219da63d7f4cb86001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b1580156112a657600080fd5b505af11580156112ba573d6000803e3d6000fd5b50505050505b3481116112ce5760006112d8565b6112d83482612a5e565b90505b80156112f6576112f66001600160a01b038516333084611f02565b638cd2e0c760e01b888681518110611310576113106126c4565b60200260200101516000015189878151811061132e5761132e6126c4565b60209081029190910181015101516040516001600160a01b0390921660248301526044820152606481018b9052608401604051602081830303815290604052906001600160e01b0319166020820180516001600160e01b0383818316178352505050508a8c815181106113a3576113a36126c4565b60200260200101819052506113b88b60010190565b9a50505050506113c88160010190565b9050610fd4565b509495939450505050565b6000606060005b848110156117d4576342d91bc360e01b87878784818110611404576114046126c4565b61141a92602060a09092020190810191506122ca565b88888581811061142c5761142c6126c4565b905060a0020160200135898986818110611448576114486126c4565b61145e92602060a09092020190810191506122ca565b60405160248101949094526001600160a01b039283166044850152606484019190915216608482015260a401604051602081830303815290604052906001600160e01b0319166020820180516001600160e01b038381831617835250505050888a815181106114cf576114cf6126c4565b60200260200101819052506114e48960010190565b985060008686838181106114fa576114fa6126c4565b61151392606060a09092020190810191506040016122ca565b90506000878784818110611529576115296126c4565b61153f92602060a09092020190810191506122ca565b6001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa15801561157c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115a0919061263e565b905060008888858181106115b6576115b66126c4565b905060a0020160800160208101906115ce91906122ca565b90507f00000000000000000000000078c1b0c915c4faa5fffa6cabf0219da63d7f4cb86001600160a01b0316826001600160a01b031614801561160e5750865b156116165750305b6001600160a01b03831615611716576001600160a01b03831660009081526067602052604090205461164c9060ff16606b610352565b611713826001600160a01b03168a8a8781811061166b5761166b6126c4565b61168492608060a09092020190810191506060016122ca565b6001600160a01b031614801561170c5750826001600160a01b0316846001600160a01b0316638812805d6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156116dd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611701919061263e565b6001600160a01b0316145b60cc610352565b50815b637fe6bc3d60e01b898986818110611730576117306126c4565b61174692602060a09092020190810191506122ca565b6040516001600160a01b0391821660248201529083166044820152606401604051602081830303815290604052906001600160e01b0319166020820180516001600160e01b0383818316178352505050508b8d815181106117a9576117a96126c4565b60200260200101819052506117be8c60010190565b9b505050506117cd8160010190565b90506113e1565b5096979596505050505050565b6000606060005b838110156118f9576308ba54eb60e21b85858381811061180a5761180a6126c4565b61182092602060609092020190810191506122ca565b868684818110611832576118326126c4565b905060600201602001358888888681811061184f5761184f6126c4565b905060600201604001602081019061186791906122ca565b6040516001600160a01b03948516602482015260448101939093526064830191909152909116608482015260a401604051602081830303815290604052906001600160e01b0319166020820180516001600160e01b0383818316178352505050508789815181106118da576118da6126c4565b60200260200101819052506118ef8860010190565b97506001016117e8565b50959694955050505050565b6000606060005b838110156118f9576000858583818110611928576119286126c4565b61193e92602060809092020190810191506122ca565b90506000868684818110611954576119546126c4565b9050608002016020013590506000826001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa1580156119a0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119c4919061263e565b905060008888868181106119da576119da6126c4565b6119f392606060809092020190810191506040016122ca565b90507f00000000000000000000000078c1b0c915c4faa5fffa6cabf0219da63d7f4cb86001600160a01b0316826001600160a01b031603611b1f573415611adf577f00000000000000000000000078c1b0c915c4faa5fffa6cabf0219da63d7f4cb86001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b158015611a8f57600080fd5b505af1158015611aa3573d6000803e3d6000fd5b50611adf9350506001600160a01b037f00000000000000000000000078c1b0c915c4faa5fffa6cabf0219da63d7f4cb816915086905034611f73565b8215611b1a57611b1a6001600160a01b037f00000000000000000000000078c1b0c915c4faa5fffa6cabf0219da63d7f4cb816338686611f02565b611cea565b6001600160a01b03811615611cd5576000898987818110611b4257611b426126c4565b611b599260809182020190810191506060016122ca565b6001600160a01b038316600090815260676020526040902054909150611b839060ff16606b610352565b611bce816001600160a01b0316836001600160a01b0316634abaf9216040518163ffffffff1660e01b8152600401602060405180830381865afa1580156116dd573d6000803e3d6000fd5b611c4e836001600160a01b0316836001600160a01b0316638812805d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611c19573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c3d919061263e565b6001600160a01b03161460cd610352565b611c636001600160a01b038216338487611f02565b6040516223276f60e41b81526001600160a01b03868116600483015283169063023276f0906024016020604051808303816000875af1158015611caa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cce919061265b565b5050611cea565b611cea6001600160a01b038316338686611f02565b604080516001600160a01b0386811660248301527f0000000000000000000000000e7401707cd08c03cdb53daef3295ddfb68bba92166044808301919091528251808303909101815260649091019091526020810180516001600160e01b0316634a8db60160e11b1790528b518c908e908110611d6957611d696126c4565b6020026020010181905250611d7e8c60010190565b60408051602481018d90526001600160a01b0387166044808301919091528251808303909101815260649091019091526020810180516001600160e01b031663abf4dd3960e01b1790528c51919d50908c908e908110611de057611de06126c4565b6020026020010181905250611df58c60010190565b9b5050505050611e058160010190565b905061190c565b600054610100900460ff16610f325760405162461bcd60e51b8152600401610aa090612a13565b604051636eb1769f60e11b81523060048201526001600160a01b037f000000000000000000000000972bcb0284cca0152527c4f70f8f689852bcafc58116602483015282919084169063dd62ed3e90604401602060405180830381865afa158015611ea2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ec6919061265b565b1015610360576103606001600160a01b0383167f000000000000000000000000972bcb0284cca0152527c4f70f8f689852bcafc5600019611fa8565b6040516001600160a01b0380851660248301528316604482015260648101829052611f6d9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526120bd565b50505050565b6040516001600160a01b038316602482015260448101829052611fa390849063a9059cbb60e01b90606401611f36565b505050565b8015806120225750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa158015611ffc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612020919061265b565b155b61208d5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610aa0565b6040516001600160a01b038316602482015260448101829052611fa390849063095ea7b360e01b90606401611f36565b6000612112826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166121929092919063ffffffff16565b90508051600014806121335750808060200190518101906121339190612a71565b611fa35760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610aa0565b606061036d848460008585600080866001600160a01b031685876040516121b99190612a8e565b60006040518083038185875af1925050503d80600081146121f6576040519150601f19603f3d011682016040523d82523d6000602084013e6121fb565b606091505b509150915061220c87838387612217565b979650505050505050565b6060831561228657825160000361227f576001600160a01b0385163b61227f5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610aa0565b508161036d565b61036d838381511561229b5781518083602001fd5b8060405162461bcd60e51b8152600401610aa09190612aaa565b6001600160a01b0381168114610b1a57600080fd5b6000602082840312156122dc57600080fd5b81356122e7816122b5565b9392505050565b6000806040838503121561230157600080fd5b823561230c816122b5565b946020939093013593505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156123595761235961231a565b604052919050565b600067ffffffffffffffff82111561237b5761237b61231a565b50601f01601f191660200190565b6000806000806080858703121561239f57600080fd5b84356123aa816122b5565b935060208501356123ba816122b5565b925060408501359150606085013567ffffffffffffffff8111156123dd57600080fd5b8501601f810187136123ee57600080fd5b80356124016123fc82612361565b612330565b81815288602083850101111561241657600080fd5b8160208401602083013760006020838301015280935050505092959194509250565b60006020828403121561244a57600080fd5b813567ffffffffffffffff81111561246157600080fd5b820161012081850312156122e757600080fd5b60005b8381101561248f578181015183820152602001612477565b50506000910152565b600081518084526124b0816020860160208601612474565b601f01601f19169290920160200192915050565b600082825180855260208086019550808260051b84010181860160005b8481101561250f57601f198684030189526124fd838351612498565b988401989250908301906001016124e1565b5090979650505050505050565b83815282602082015260606040820152600061253b60608301846124c4565b95945050505050565b61ffff81168114610b1a57600080fd5b6000806040838503121561256757600080fd5b823561257281612544565b91506020830135612582816122b5565b809150509250929050565b8015158114610b1a57600080fd5b6000806000604084860312156125b057600080fd5b833567ffffffffffffffff808211156125c857600080fd5b818601915086601f8301126125dc57600080fd5b8135818111156125eb57600080fd5b8760208260051b850101111561260057600080fd5b602092830195509350508401356126168161258d565b809150509250925092565b60006020828403121561263357600080fd5b81356122e781612544565b60006020828403121561265057600080fd5b81516122e7816122b5565b60006020828403121561266d57600080fd5b5051919050565b6000808335601e1984360301811261268b57600080fd5b83018035915067ffffffffffffffff8211156126a657600080fd5b602001915060a0810236038213156126bd57600080fd5b9250929050565b634e487b7160e01b600052603260045260246000fd5b6000602082840312156126ec57600080fd5b81356122e78161258d565b634e487b7160e01b600052601160045260246000fd5b60006001820161271f5761271f6126f7565b5060010190565b6040808252810183905260008460608301825b8681101561276957823561274c816122b5565b6001600160a01b0316825260209283019290910190600101612739565b5080925050508215156020830152949350505050565b60006020828403121561279157600080fd5b81516122e781612544565b6000808335601e198436030181126127b357600080fd5b83018035915067ffffffffffffffff8211156127ce57600080fd5b6020019150600781901b36038213156126bd57600080fd5b80820281158282048414176127fd576127fd6126f7565b92915050565b6000808335601e1984360301811261281a57600080fd5b83018035915067ffffffffffffffff82111561283557600080fd5b60200191506060810236038213156126bd57600080fd5b6000808335601e1984360301811261286357600080fd5b83018035915067ffffffffffffffff82111561287e57600080fd5b6020019150600681901b36038213156126bd57600080fd5b808201808211156127fd576127fd6126f7565b6000604082840312156128bb57600080fd5b6040516040810181811067ffffffffffffffff821117156128de576128de61231a565b60405282356128ec816122b5565b81526020928301359281019290925250919050565b6020815260006122e760208301846124c4565b6000602080838503121561292757600080fd5b825167ffffffffffffffff8082111561293f57600080fd5b818501915085601f83011261295357600080fd5b8151818111156129655761296561231a565b8060051b612974858201612330565b918252838101850191858101908984111561298e57600080fd5b86860192505b83831015612a06578251858111156129ac5760008081fd5b8601603f81018b136129be5760008081fd5b8781015160406129d06123fc83612361565b8281528d828486010111156129e55760008081fd5b6129f4838c8301848701612474565b85525050509186019190860190612994565b9998505050505050505050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b818103818111156127fd576127fd6126f7565b600060208284031215612a8357600080fd5b81516122e78161258d565b60008251612aa0818460208701612474565b9190910192915050565b6020815260006122e7602083018461249856fea2646970667358221220b25097e195849ae9881303d90053f1089d7a2c70f36e9b3747ec5e4471f5959164736f6c63430008130033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000972bcb0284cca0152527c4f70f8f689852bcafc500000000000000000000000078c1b0c915c4faa5fffa6cabf0219da63d7f4cb8000000000000000000000000ce3292ca5abbdfa1db02142a67cffc708530675a
-----Decoded View---------------
Arg [0] : _initCore (address): 0x972BcB0284cca0152527c4f70f8F689852bCAFc5
Arg [1] : _wNative (address): 0x78c1b0C915c4FAA5FffA6CAbf0219DA63d7f4cb8
Arg [2] : _acm (address): 0xCE3292cA5AbbdFA1Db02142A67CFFc708530675a
-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 000000000000000000000000972bcb0284cca0152527c4f70f8f689852bcafc5
Arg [1] : 00000000000000000000000078c1b0c915c4faa5fffa6cabf0219da63d7f4cb8
Arg [2] : 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.