- Contract name:
- TokenValidator
- Optimization enabled
- true
- Compiler version
- v0.7.6+commit.7338295f
- Optimization runs
- 10
- EVM Version
- default
- Verified at
- 2024-07-20T04:29:57.585827Z
contracts/lens/TokenValidator.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
pragma abicoder v2;
import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '@pancakeswap/v3-periphery/contracts/base/PeripheryImmutableState.sol';
import '@uniswap/v2-core/contracts/interfaces/IUniswapV2Callee.sol';
import '@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol';
import '../libraries/SmartRouterHelper.sol';
import '../interfaces/ITokenValidator.sol';
import '../base/ImmutableState.sol';
/// @notice Validates tokens by flash borrowing from the token/<base token> pool on V2.
/// @notice Returns
/// Status.FOT if we detected a fee is taken on transfer.
/// Status.STF if transfer failed for the token.
/// Status.UNKN if we did not detect any issues with the token.
/// @notice A return value of Status.UNKN does not mean the token is definitely not a fee on transfer token
/// or definitely has no problems with its transfer. It just means we cant say for sure that it has any
/// issues.
/// @dev We can not guarantee the result of this lens is correct for a few reasons:
/// @dev 1/ Some tokens take fees or allow transfers under specific conditions, for example some have an allowlist
/// @dev of addresses that do/dont require fees. Therefore the result is not guaranteed to be correct
/// @dev in all circumstances.
/// @dev 2/ It is possible that the token does not have any pools on V2 therefore we are not able to perform
/// @dev a flashloan to test the token.
contract TokenValidator is ITokenValidator, IUniswapV2Callee, ImmutableState {
string internal constant FOT_REVERT_STRING = 'FOT';
// https://github.com/Uniswap/v2-core/blob/1136544ac842ff48ae0b1b939701436598d74075/contracts/UniswapV2Pair.sol#L46
string internal constant STF_REVERT_STRING_SUFFIX = 'TRANSFER_FAILED';
constructor(address _factoryV2, address _positionManager) ImmutableState(_factoryV2, _positionManager) {}
function batchValidate(
address[] calldata tokens,
address[] calldata baseTokens,
uint256 amountToBorrow
) public override returns (Status[] memory isFotResults) {
isFotResults = new Status[](tokens.length);
for (uint256 i = 0; i < tokens.length; i++) {
isFotResults[i] = validate(tokens[i], baseTokens, amountToBorrow);
}
}
function validate(
address token,
address[] calldata baseTokens,
uint256 amountToBorrow
) public override returns (Status) {
for (uint256 i = 0; i < baseTokens.length; i++) {
Status result = _validate(token, baseTokens[i], amountToBorrow);
if (result == Status.FOT || result == Status.STF) {
return result;
}
}
return Status.UNKN;
}
function _validate(
address token,
address baseToken,
uint256 amountToBorrow
) internal returns (Status) {
if (token == baseToken) {
return Status.UNKN;
}
address pairAddress = SmartRouterHelper.pairFor(this.factoryV2(), token, baseToken);
// If the token/baseToken pair exists, get token0.
// Must do low level call as try/catch does not support case where contract does not exist.
(, bytes memory returnData) = address(pairAddress).call(abi.encodeWithSelector(IUniswapV2Pair.token0.selector));
if (returnData.length == 0) {
return Status.UNKN;
}
address token0Address = abi.decode(returnData, (address));
// Flash loan {amountToBorrow}
(uint256 amount0Out, uint256 amount1Out) =
token == token0Address ? (amountToBorrow, uint256(0)) : (uint256(0), amountToBorrow);
uint256 balanceBeforeLoan = IERC20(token).balanceOf(address(this));
IUniswapV2Pair pair = IUniswapV2Pair(pairAddress);
try
pair.swap(amount0Out, amount1Out, address(this), abi.encode(balanceBeforeLoan, amountToBorrow))
{} catch Error(string memory reason) {
if (isFotFailed(reason)) {
return Status.FOT;
}
if (isTransferFailed(reason)) {
return Status.STF;
}
return Status.UNKN;
}
// Swap always reverts so should never reach.
revert('Unexpected error');
}
function isFotFailed(string memory reason) internal pure returns (bool) {
return keccak256(bytes(reason)) == keccak256(bytes(FOT_REVERT_STRING));
}
function isTransferFailed(string memory reason) internal pure returns (bool) {
// We check the suffix of the revert string so we can support forks that
// may have modified the prefix.
string memory stf = STF_REVERT_STRING_SUFFIX;
uint256 reasonLength = bytes(reason).length;
uint256 suffixLength = bytes(stf).length;
if (reasonLength < suffixLength) {
return false;
}
uint256 ptr;
uint256 offset = 32 + reasonLength - suffixLength;
bool transferFailed;
assembly {
ptr := add(reason, offset)
let suffixPtr := add(stf, 32)
transferFailed := eq(keccak256(ptr, suffixLength), keccak256(suffixPtr, suffixLength))
}
return transferFailed;
}
function uniswapV2Call(
address,
uint256 amount0,
uint256,
bytes calldata data
) external view override {
IUniswapV2Pair pair = IUniswapV2Pair(msg.sender);
(address token0, address token1) = (pair.token0(), pair.token1());
IERC20 tokenBorrowed = IERC20(amount0 > 0 ? token0 : token1);
(uint256 balanceBeforeLoan, uint256 amountRequestedToBorrow) = abi.decode(data, (uint256, uint256));
uint256 amountBorrowed = tokenBorrowed.balanceOf(address(this)) - balanceBeforeLoan;
// If we received less token than we requested when we called swap, then a fee must have been taken
// by the token during transfer.
if (amountBorrowed != amountRequestedToBorrow) {
revert(FOT_REVERT_STRING);
}
// Note: If we do not revert here, we would end up reverting in the pair's swap method anyway
// since for a flash borrow we need to transfer back the amount we borrowed + 0.3% fee, and we don't
// have funds to cover the fee. Revert early here to save gas/time.
revert('Unknown');
}
}
@pancakeswap/v3-periphery/contracts/interfaces/IPeripheryImmutableState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Immutable state
/// @notice Functions that return immutable state of the router
interface IPeripheryImmutableState {
/// @return Returns the address of the PancakeSwap V3 deployer
function deployer() external view returns (address);
/// @return Returns the address of the PancakeSwap V3 factory
function factory() external view returns (address);
/// @return Returns the address of WETH9
function WETH9() external view returns (address);
}
@uniswap/v2-core/contracts/interfaces/IUniswapV2Callee.sol
pragma solidity >=0.5.0;
interface IUniswapV2Callee {
function uniswapV2Call(address sender, uint amount0, uint amount1, bytes calldata data) external;
}
@openzeppelin/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @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 `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool);
/**
* @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);
}
@pancakeswap/v3-core/contracts/interfaces/IPancakeV3Pool.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
import './pool/IPancakeV3PoolImmutables.sol';
import './pool/IPancakeV3PoolState.sol';
import './pool/IPancakeV3PoolDerivedState.sol';
import './pool/IPancakeV3PoolActions.sol';
import './pool/IPancakeV3PoolOwnerActions.sol';
import './pool/IPancakeV3PoolEvents.sol';
/// @title The interface for a PancakeSwap V3 Pool
/// @notice A PancakeSwap pool facilitates swapping and automated market making between any two assets that strictly conform
/// to the ERC20 specification
/// @dev The pool interface is broken up into many smaller pieces
interface IPancakeV3Pool is
IPancakeV3PoolImmutables,
IPancakeV3PoolState,
IPancakeV3PoolDerivedState,
IPancakeV3PoolActions,
IPancakeV3PoolOwnerActions,
IPancakeV3PoolEvents
{
}
@pancakeswap/v3-core/contracts/interfaces/pool/IPancakeV3PoolActions.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Permissionless pool actions
/// @notice Contains pool methods that can be called by anyone
interface IPancakeV3PoolActions {
/// @notice Sets the initial price for the pool
/// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
/// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96
function initialize(uint160 sqrtPriceX96) external;
/// @notice Adds liquidity for the given recipient/tickLower/tickUpper position
/// @dev The caller of this method receives a callback in the form of IPancakeV3MintCallback#pancakeV3MintCallback
/// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
/// on tickLower, tickUpper, the amount of liquidity, and the current price.
/// @param recipient The address for which the liquidity will be created
/// @param tickLower The lower tick of the position in which to add liquidity
/// @param tickUpper The upper tick of the position in which to add liquidity
/// @param amount The amount of liquidity to mint
/// @param data Any data that should be passed through to the callback
/// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback
/// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback
function mint(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount,
bytes calldata data
) external returns (uint256 amount0, uint256 amount1);
/// @notice Collects tokens owed to a position
/// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.
/// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or
/// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the
/// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
/// @param recipient The address which should receive the fees collected
/// @param tickLower The lower tick of the position for which to collect fees
/// @param tickUpper The upper tick of the position for which to collect fees
/// @param amount0Requested How much token0 should be withdrawn from the fees owed
/// @param amount1Requested How much token1 should be withdrawn from the fees owed
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1
function collect(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);
/// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position
/// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0
/// @dev Fees must be collected separately via a call to #collect
/// @param tickLower The lower tick of the position for which to burn liquidity
/// @param tickUpper The upper tick of the position for which to burn liquidity
/// @param amount How much liquidity to burn
/// @return amount0 The amount of token0 sent to the recipient
/// @return amount1 The amount of token1 sent to the recipient
function burn(
int24 tickLower,
int24 tickUpper,
uint128 amount
) external returns (uint256 amount0, uint256 amount1);
/// @notice Swap token0 for token1, or token1 for token0
/// @dev The caller of this method receives a callback in the form of IPancakeV3SwapCallback#pancakeV3SwapCallback
/// @param recipient The address to receive the output of the swap
/// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
/// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
/// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
/// value after the swap. If one for zero, the price cannot be greater than this value after the swap
/// @param data Any data to be passed through to the callback
/// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
/// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
function swap(
address recipient,
bool zeroForOne,
int256 amountSpecified,
uint160 sqrtPriceLimitX96,
bytes calldata data
) external returns (int256 amount0, int256 amount1);
/// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
/// @dev The caller of this method receives a callback in the form of IPancakeV3FlashCallback#pancakeV3FlashCallback
/// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling
/// with 0 amount{0,1} and sending the donation amount(s) from the callback
/// @param recipient The address which will receive the token0 and token1 amounts
/// @param amount0 The amount of token0 to send
/// @param amount1 The amount of token1 to send
/// @param data Any data to be passed through to the callback
function flash(
address recipient,
uint256 amount0,
uint256 amount1,
bytes calldata data
) external;
/// @notice Increase the maximum number of price and liquidity observations that this pool will store
/// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to
/// the input observationCardinalityNext.
/// @param observationCardinalityNext The desired minimum number of observations for the pool to store
function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;
}
@pancakeswap/v3-core/contracts/interfaces/pool/IPancakeV3PoolDerivedState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Pool state that is not stored
/// @notice Contains view functions to provide information about the pool that is computed rather than stored on the
/// blockchain. The functions here may have variable gas costs.
interface IPancakeV3PoolDerivedState {
/// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp
/// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing
/// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick,
/// you must call it with secondsAgos = [3600, 0].
/// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in
/// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.
/// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned
/// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp
/// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block
/// timestamp
function observe(uint32[] calldata secondsAgos)
external
view
returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);
/// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range
/// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed.
/// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first
/// snapshot is taken and the second snapshot is taken.
/// @param tickLower The lower tick of the range
/// @param tickUpper The upper tick of the range
/// @return tickCumulativeInside The snapshot of the tick accumulator for the range
/// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range
/// @return secondsInside The snapshot of seconds per liquidity for the range
function snapshotCumulativesInside(int24 tickLower, int24 tickUpper)
external
view
returns (
int56 tickCumulativeInside,
uint160 secondsPerLiquidityInsideX128,
uint32 secondsInside
);
}
@pancakeswap/v3-core/contracts/interfaces/pool/IPancakeV3PoolEvents.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Events emitted by a pool
/// @notice Contains all events emitted by the pool
interface IPancakeV3PoolEvents {
/// @notice Emitted exactly once by a pool when #initialize is first called on the pool
/// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize
/// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96
/// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool
event Initialize(uint160 sqrtPriceX96, int24 tick);
/// @notice Emitted when liquidity is minted for a given position
/// @param sender The address that minted the liquidity
/// @param owner The owner of the position and recipient of any minted liquidity
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @param amount The amount of liquidity minted to the position range
/// @param amount0 How much token0 was required for the minted liquidity
/// @param amount1 How much token1 was required for the minted liquidity
event Mint(
address sender,
address indexed owner,
int24 indexed tickLower,
int24 indexed tickUpper,
uint128 amount,
uint256 amount0,
uint256 amount1
);
/// @notice Emitted when fees are collected by the owner of a position
/// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees
/// @param owner The owner of the position for which fees are collected
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @param amount0 The amount of token0 fees collected
/// @param amount1 The amount of token1 fees collected
event Collect(
address indexed owner,
address recipient,
int24 indexed tickLower,
int24 indexed tickUpper,
uint128 amount0,
uint128 amount1
);
/// @notice Emitted when a position's liquidity is removed
/// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect
/// @param owner The owner of the position for which liquidity is removed
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @param amount The amount of liquidity to remove
/// @param amount0 The amount of token0 withdrawn
/// @param amount1 The amount of token1 withdrawn
event Burn(
address indexed owner,
int24 indexed tickLower,
int24 indexed tickUpper,
uint128 amount,
uint256 amount0,
uint256 amount1
);
/// @notice Emitted by the pool for any swaps between token0 and token1
/// @param sender The address that initiated the swap call, and that received the callback
/// @param recipient The address that received the output of the swap
/// @param amount0 The delta of the token0 balance of the pool
/// @param amount1 The delta of the token1 balance of the pool
/// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96
/// @param liquidity The liquidity of the pool after the swap
/// @param tick The log base 1.0001 of price of the pool after the swap
/// @param protocolFeesToken0 The protocol fee of token0 in the swap
/// @param protocolFeesToken1 The protocol fee of token1 in the swap
event Swap(
address indexed sender,
address indexed recipient,
int256 amount0,
int256 amount1,
uint160 sqrtPriceX96,
uint128 liquidity,
int24 tick,
uint128 protocolFeesToken0,
uint128 protocolFeesToken1
);
/// @notice Emitted by the pool for any flashes of token0/token1
/// @param sender The address that initiated the swap call, and that received the callback
/// @param recipient The address that received the tokens from flash
/// @param amount0 The amount of token0 that was flashed
/// @param amount1 The amount of token1 that was flashed
/// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee
/// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee
event Flash(
address indexed sender,
address indexed recipient,
uint256 amount0,
uint256 amount1,
uint256 paid0,
uint256 paid1
);
/// @notice Emitted by the pool for increases to the number of observations that can be stored
/// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index
/// just before a mint/swap/burn.
/// @param observationCardinalityNextOld The previous value of the next observation cardinality
/// @param observationCardinalityNextNew The updated value of the next observation cardinality
event IncreaseObservationCardinalityNext(
uint16 observationCardinalityNextOld,
uint16 observationCardinalityNextNew
);
/// @notice Emitted when the protocol fee is changed by the pool
/// @param feeProtocol0Old The previous value of the token0 protocol fee
/// @param feeProtocol1Old The previous value of the token1 protocol fee
/// @param feeProtocol0New The updated value of the token0 protocol fee
/// @param feeProtocol1New The updated value of the token1 protocol fee
event SetFeeProtocol(
uint32 feeProtocol0Old,
uint32 feeProtocol1Old,
uint32 feeProtocol0New,
uint32 feeProtocol1New
);
/// @notice Emitted when the collected protocol fees are withdrawn by the factory owner
/// @param sender The address that collects the protocol fees
/// @param recipient The address that receives the collected protocol fees
/// @param amount0 The amount of token0 protocol fees that is withdrawn
/// @param amount0 The amount of token1 protocol fees that is withdrawn
event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1);
}
@pancakeswap/v3-core/contracts/interfaces/pool/IPancakeV3PoolImmutables.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Pool state that never changes
/// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values
interface IPancakeV3PoolImmutables {
/// @notice The contract that deployed the pool, which must adhere to the IPancakeV3Factory interface
/// @return The contract address
function factory() external view returns (address);
/// @notice The first of the two tokens of the pool, sorted by address
/// @return The token contract address
function token0() external view returns (address);
/// @notice The second of the two tokens of the pool, sorted by address
/// @return The token contract address
function token1() external view returns (address);
/// @notice The pool's fee in hundredths of a bip, i.e. 1e-6
/// @return The fee
function fee() external view returns (uint24);
/// @notice The pool tick spacing
/// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive
/// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ...
/// This value is an int24 to avoid casting even though it is always positive.
/// @return The tick spacing
function tickSpacing() external view returns (int24);
/// @notice The maximum amount of position liquidity that can use any tick in the range
/// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and
/// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool
/// @return The max amount of liquidity per tick
function maxLiquidityPerTick() external view returns (uint128);
}
@pancakeswap/v3-core/contracts/interfaces/pool/IPancakeV3PoolOwnerActions.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Permissioned pool actions
/// @notice Contains pool methods that may only be called by the factory owner
interface IPancakeV3PoolOwnerActions {
/// @notice Set the denominator of the protocol's % share of the fees
/// @param feeProtocol0 new protocol fee for token0 of the pool
/// @param feeProtocol1 new protocol fee for token1 of the pool
function setFeeProtocol(uint32 feeProtocol0, uint32 feeProtocol1) external;
/// @notice Collect the protocol fee accrued to the pool
/// @param recipient The address to which collected protocol fees should be sent
/// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1
/// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0
/// @return amount0 The protocol fee collected in token0
/// @return amount1 The protocol fee collected in token1
function collectProtocol(
address recipient,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);
/// @notice Set the LM pool to enable liquidity mining
function setLmPool(address lmPool) external;
}
@pancakeswap/v3-core/contracts/interfaces/pool/IPancakeV3PoolState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Pool state that can change
/// @notice These methods compose the pool's state, and can change with any frequency including multiple times
/// per transaction
interface IPancakeV3PoolState {
/// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas
/// when accessed externally.
/// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value
/// tick The current tick of the pool, i.e. according to the last tick transition that was run.
/// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick
/// boundary.
/// observationIndex The index of the last oracle observation that was written,
/// observationCardinality The current maximum number of observations stored in the pool,
/// observationCardinalityNext The next maximum number of observations, to be updated when the observation.
/// feeProtocol The protocol fee for both tokens of the pool.
/// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0
/// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee.
/// unlocked Whether the pool is currently locked to reentrancy
function slot0()
external
view
returns (
uint160 sqrtPriceX96,
int24 tick,
uint16 observationIndex,
uint16 observationCardinality,
uint16 observationCardinalityNext,
uint32 feeProtocol,
bool unlocked
);
/// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool
/// @dev This value can overflow the uint256
function feeGrowthGlobal0X128() external view returns (uint256);
/// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool
/// @dev This value can overflow the uint256
function feeGrowthGlobal1X128() external view returns (uint256);
/// @notice The amounts of token0 and token1 that are owed to the protocol
/// @dev Protocol fees will never exceed uint128 max in either token
function protocolFees() external view returns (uint128 token0, uint128 token1);
/// @notice The currently in range liquidity available to the pool
/// @dev This value has no relationship to the total liquidity across all ticks
function liquidity() external view returns (uint128);
/// @notice Look up information about a specific tick in the pool
/// @param tick The tick to look up
/// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or
/// tick upper,
/// liquidityNet how much liquidity changes when the pool price crosses the tick,
/// feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0,
/// feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1,
/// tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick
/// secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick,
/// secondsOutside the seconds spent on the other side of the tick from the current tick,
/// initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false.
/// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0.
/// In addition, these values are only relative and must be used only in comparison to previous snapshots for
/// a specific position.
function ticks(int24 tick)
external
view
returns (
uint128 liquidityGross,
int128 liquidityNet,
uint256 feeGrowthOutside0X128,
uint256 feeGrowthOutside1X128,
int56 tickCumulativeOutside,
uint160 secondsPerLiquidityOutsideX128,
uint32 secondsOutside,
bool initialized
);
/// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information
function tickBitmap(int16 wordPosition) external view returns (uint256);
/// @notice Returns the information about a position by the position's key
/// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper
/// @return _liquidity The amount of liquidity in the position,
/// Returns feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke,
/// Returns feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke,
/// Returns tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke,
/// Returns tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke
function positions(bytes32 key)
external
view
returns (
uint128 _liquidity,
uint256 feeGrowthInside0LastX128,
uint256 feeGrowthInside1LastX128,
uint128 tokensOwed0,
uint128 tokensOwed1
);
/// @notice Returns data about a specific observation index
/// @param index The element of the observations array to fetch
/// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time
/// ago, rather than at a specific index in the array.
/// @return blockTimestamp The timestamp of the observation,
/// Returns tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp,
/// Returns secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp,
/// Returns initialized whether the observation has been initialized and the values are safe to use
function observations(uint256 index)
external
view
returns (
uint32 blockTimestamp,
int56 tickCumulative,
uint160 secondsPerLiquidityCumulativeX128,
bool initialized
);
}
@pancakeswap/v3-core/contracts/libraries/LowGasSafeMath.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.0;
/// @title Optimized overflow and underflow safe math operations
/// @notice Contains methods for doing math operations that revert on overflow or underflow for minimal gas cost
library LowGasSafeMath {
/// @notice Returns x + y, reverts if sum overflows uint256
/// @param x The augend
/// @param y The addend
/// @return z The sum of x and y
function add(uint256 x, uint256 y) internal pure returns (uint256 z) {
require((z = x + y) >= x);
}
/// @notice Returns x - y, reverts if underflows
/// @param x The minuend
/// @param y The subtrahend
/// @return z The difference of x and y
function sub(uint256 x, uint256 y) internal pure returns (uint256 z) {
require((z = x - y) <= x);
}
/// @notice Returns x * y, reverts if overflows
/// @param x The multiplicand
/// @param y The multiplier
/// @return z The product of x and y
function mul(uint256 x, uint256 y) internal pure returns (uint256 z) {
require(x == 0 || (z = x * y) / x == y);
}
/// @notice Returns x + y, reverts if overflows or underflows
/// @param x The augend
/// @param y The addend
/// @return z The sum of x and y
function add(int256 x, int256 y) internal pure returns (int256 z) {
require((z = x + y) >= x == (y >= 0));
}
/// @notice Returns x - y, reverts if overflows or underflows
/// @param x The minuend
/// @param y The subtrahend
/// @return z The difference of x and y
function sub(int256 x, int256 y) internal pure returns (int256 z) {
require((z = x - y) <= x == (y >= 0));
}
}
@pancakeswap/v3-periphery/contracts/base/PeripheryImmutableState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
import '../interfaces/IPeripheryImmutableState.sol';
/// @title Immutable state
/// @notice Immutable state used by periphery contracts
abstract contract PeripheryImmutableState is IPeripheryImmutableState {
/// @inheritdoc IPeripheryImmutableState
address public immutable override deployer;
/// @inheritdoc IPeripheryImmutableState
address public immutable override factory;
/// @inheritdoc IPeripheryImmutableState
address public immutable override WETH9;
constructor(address _deployer, address _factory, address _WETH9) {
deployer = _deployer;
factory = _factory;
WETH9 = _WETH9;
}
}
@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol
pragma solidity >=0.5.0;
interface IUniswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
function mint(address to) external returns (uint liquidity);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}
contracts/base/ImmutableState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
import '../interfaces/IImmutableState.sol';
/// @title Immutable state
/// @notice Immutable state used by the swap router
abstract contract ImmutableState is IImmutableState {
/// @inheritdoc IImmutableState
address public immutable override factoryV2;
/// @inheritdoc IImmutableState
address public immutable override positionManager;
constructor(address _factoryV2, address _positionManager) {
factoryV2 = _factoryV2;
positionManager = _positionManager;
}
}
contracts/interfaces/IImmutableState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Immutable state
/// @notice Functions that return immutable state of the router
interface IImmutableState {
/// @return Returns the address of the PancakeSwap V2 factory
function factoryV2() external view returns (address);
/// @return Returns the address of PancakeSwap V3 NFT position manager
function positionManager() external view returns (address);
}
contracts/interfaces/IStableSwapFactory.sol
// SPDX-License-Identifier: MIT
pragma solidity =0.7.6;
pragma abicoder v2;
interface IStableSwapFactory {
struct StableSwapPairInfo {
address swapContract;
address token0;
address token1;
address LPContract;
}
struct StableSwapThreePoolPairInfo {
address swapContract;
address token0;
address token1;
address token2;
address LPContract;
}
// solium-disable-next-line mixedcase
function pairLength() external view returns (uint256);
function getPairInfo(address _tokenA, address _tokenB)
external
view
returns (StableSwapPairInfo memory info);
function getThreePoolPairInfo(address _tokenA, address _tokenB)
external
view
returns (StableSwapThreePoolPairInfo memory info);
}
contracts/interfaces/IStableSwapInfo.sol
// SPDX-License-Identifier: MIT
pragma solidity =0.7.6;
pragma abicoder v2;
interface IStableSwapInfo {
function get_dx(
address _swap,
uint256 i,
uint256 j,
uint256 dy,
uint256 max_dx
) external view returns (uint256);
}
contracts/interfaces/ITokenValidator.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;
/// @notice Validates tokens by flash borrowing from the token/<base token> pool on V2.
/// @notice Returns
/// Status.FOT if we detected a fee is taken on transfer.
/// Status.STF if transfer failed for the token.
/// Status.UNKN if we did not detect any issues with the token.
/// @notice A return value of Status.UNKN does not mean the token is definitely not a fee on transfer token
/// or definitely has no problems with its transfer. It just means we cant say for sure that it has any
/// issues.
/// @dev We can not guarantee the result of this lens is correct for a few reasons:
/// @dev 1/ Some tokens take fees or allow transfers under specific conditions, for example some have an allowlist
/// @dev of addresses that do/dont require fees. Therefore the result is not guaranteed to be correct
/// @dev in all circumstances.
/// @dev 2/ It is possible that the token does not have any pools on V2 therefore we are not able to perform
/// @dev a flashloan to test the token.
/// @dev These functions are not marked view because they rely on calling non-view functions and reverting
/// to compute the result.
interface ITokenValidator {
// Status.FOT: detected a fee is taken on transfer.
// Status.STF: transfer failed for the token.
// Status.UNKN: no issues found with the token.
enum Status {UNKN, FOT, STF}
/// @notice Validates a token by detecting if its transferable or takes a fee on transfer
/// @param token The address of the token to check for fee on transfer
/// @param baseTokens The addresses of the tokens to try pairing with
/// token when looking for a pool to flash loan from.
/// @param amountToBorrow The amount to try flash borrowing from the pools
/// @return The status of the token
function validate(
address token,
address[] calldata baseTokens,
uint256 amountToBorrow
) external returns (Status);
/// @notice Validates each token by detecting if its transferable or takes a fee on transfer
/// @param tokens The addresses of the tokens to check for fee on transfer
/// @param baseTokens The addresses of the tokens to try pairing with
/// token when looking for a pool to flash loan from.
/// @param amountToBorrow The amount to try flash borrowing from the pools
/// @return The status of the token
function batchValidate(
address[] calldata tokens,
address[] calldata baseTokens,
uint256 amountToBorrow
) external returns (Status[] memory);
}
contracts/libraries/SmartRouterHelper.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
pragma abicoder v2;
import '../interfaces/IStableSwapFactory.sol';
import '../interfaces/IStableSwapInfo.sol';
import '@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol';
import '@pancakeswap/v3-core/contracts/libraries/LowGasSafeMath.sol';
import '@pancakeswap/v3-core/contracts/interfaces/IPancakeV3Pool.sol';
library SmartRouterHelper {
using LowGasSafeMath for uint256;
/************************************************** Stable **************************************************/
// get the pool info in stable swap
function getStableInfo(
address stableSwapFactory,
address input,
address output,
uint256 flag
) public view returns (uint256 i, uint256 j, address swapContract) {
if (flag == 2) {
IStableSwapFactory.StableSwapPairInfo memory info = IStableSwapFactory(stableSwapFactory).getPairInfo(input, output);
i = input == info.token0 ? 0 : 1;
j = (i == 0) ? 1 : 0;
swapContract = info.swapContract;
} else if (flag == 3) {
IStableSwapFactory.StableSwapThreePoolPairInfo memory info = IStableSwapFactory(stableSwapFactory).getThreePoolPairInfo(input, output);
if (input == info.token0) i = 0;
else if (input == info.token1) i = 1;
else if (input == info.token2) i = 2;
if (output == info.token0) j = 0;
else if (output == info.token1) j = 1;
else if (output == info.token2) j = 2;
swapContract = info.swapContract;
}
require(swapContract != address(0), "getStableInfo: invalid pool address");
}
function getStableAmountsIn(
address stableSwapFactory,
address stableSwapInfo,
address[] memory path,
uint256[] memory flag,
uint256 amountOut
) public view returns (uint256[] memory amounts) {
uint256 length = path.length;
require(length >= 2, "getStableAmountsIn: incorrect length");
amounts = new uint256[](length);
amounts[length - 1] = amountOut;
for (uint256 i = length - 1; i > 0; i--) {
uint256 last = i - 1;
(uint256 k, uint256 j, address swapContract) = getStableInfo(stableSwapFactory, path[last], path[i], flag[last]);
amounts[last] = IStableSwapInfo(stableSwapInfo).get_dx(swapContract, k, j, amounts[i], type(uint256).max);
}
}
/************************************************** V2 **************************************************/
// bytes32 internal constant V2_INIT_CODE_HASH = 0xd0d4c4cd0848c93cb4fd1f498d7013ee6bfb25783ea21593d5834f5d250ece66; // BSC TESTNET
// bytes32 internal constant V2_INIT_CODE_HASH = 0x00fb7f630766e6a796048ea87d01acd3068e8ff67d078148a3fa3f4a84f69bd5; // BSC
// bytes32 internal constant V2_INIT_CODE_HASH = 0x57224589c67f3f30a6b0d7a1b54cf3153ab84563bc609ef41dfb34f8b2974d2d; // ETH, GOERLI
bytes32 internal constant V2_INIT_CODE_HASH = 0x8663912fb6cd88082d5a92853ef1d3bdf3ddab106803e2bf19b3e7ae5a9ec1d7;
// returns sorted token addresses, used to handle return values from pairs sorted in this order
function sortTokens(address tokenA, address tokenB) public pure returns (address token0, address token1) {
require(tokenA != tokenB);
(token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0));
}
// calculates the CREATE2 address for a pair without making any external calls
function pairFor(
address factory,
address tokenA,
address tokenB
) public pure returns (address pair) {
(address token0, address token1) = sortTokens(tokenA, tokenB);
pair = address(
uint256(
keccak256(
abi.encodePacked(
hex'ff',
factory,
keccak256(abi.encodePacked(token0, token1)),
V2_INIT_CODE_HASH
)
)
)
);
}
// fetches and sorts the reserves for a pair
function getReserves(
address factory,
address tokenA,
address tokenB
) public view returns (uint256 reserveA, uint256 reserveB) {
(address token0, ) = sortTokens(tokenA, tokenB);
(uint256 reserve0, uint256 reserve1, ) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves();
(reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
}
// given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
function getAmountOut(
uint256 amountIn,
uint256 reserveIn,
uint256 reserveOut
) public pure returns (uint256 amountOut) {
require(amountIn > 0, 'INSUFFICIENT_INPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0);
uint256 amountInWithFee = amountIn.mul(9975);
uint256 numerator = amountInWithFee.mul(reserveOut);
uint256 denominator = reserveIn.mul(10000).add(amountInWithFee);
amountOut = numerator / denominator;
}
// given an output amount of an asset and pair reserves, returns a required input amount of the other asset
function getAmountIn(
uint256 amountOut,
uint256 reserveIn,
uint256 reserveOut
) public pure returns (uint256 amountIn) {
require(amountOut > 0, 'INSUFFICIENT_OUTPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0);
uint256 numerator = reserveIn.mul(amountOut).mul(10000);
uint256 denominator = reserveOut.sub(amountOut).mul(9975);
amountIn = (numerator / denominator).add(1);
}
// performs chained getAmountIn calculations on any number of pairs
function getAmountsIn(
address factory,
uint256 amountOut,
address[] memory path
) public view returns (uint256[] memory amounts) {
require(path.length >= 2);
amounts = new uint256[](path.length);
amounts[amounts.length - 1] = amountOut;
for (uint256 i = path.length - 1; i > 0; i--) {
(uint256 reserveIn, uint256 reserveOut) = getReserves(factory, path[i - 1], path[i]);
amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);
}
}
/************************************************** V3 **************************************************/
bytes32 internal constant V3_INIT_CODE_HASH = 0x6ce8eb472fa82df5469c6ab6d485f17c3ad13c8cd7af59b3d4a8026c5ce0f7e2;
/// @notice The identifying key of the pool
struct PoolKey {
address token0;
address token1;
uint24 fee;
}
/// @notice Returns PoolKey: the ordered tokens with the matched fee levels
/// @param tokenA The first token of a pool, unsorted
/// @param tokenB The second token of a pool, unsorted
/// @param fee The fee level of the pool
/// @return Poolkey The pool details with ordered token0 and token1 assignments
function getPoolKey(
address tokenA,
address tokenB,
uint24 fee
) public pure returns (PoolKey memory) {
if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA);
return PoolKey({token0: tokenA, token1: tokenB, fee: fee});
}
/// @notice Deterministically computes the pool address given the deployer and PoolKey
/// @param deployer The PancakeSwap V3 deployer contract address
/// @param key The PoolKey
/// @return pool The contract address of the V3 pool
function computeAddress(address deployer, PoolKey memory key) public pure returns (address pool) {
require(key.token0 < key.token1);
pool = address(
uint256(
keccak256(
abi.encodePacked(
hex'ff',
deployer,
keccak256(abi.encode(key.token0, key.token1, key.fee)),
V3_INIT_CODE_HASH
)
)
)
);
}
/// @dev Returns the pool for the given token pair and fee. The pool contract may or may not exist.
function getPool(
address deployer,
address tokenA,
address tokenB,
uint24 fee
) public pure returns (IPancakeV3Pool) {
return IPancakeV3Pool(computeAddress(deployer, getPoolKey(tokenA, tokenB, fee)));
}
/// @notice Returns the address of a valid PancakeSwap V3 Pool
/// @param deployer The contract address of the PancakeSwap V3 deployer
/// @param tokenA The contract address of either token0 or token1
/// @param tokenB The contract address of the other token
/// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
/// @return pool The V3 pool contract address
function verifyCallback(
address deployer,
address tokenA,
address tokenB,
uint24 fee
) public view returns (IPancakeV3Pool pool) {
return verifyCallback(deployer, getPoolKey(tokenA, tokenB, fee));
}
/// @notice Returns the address of a valid PancakeSwap V3 Pool
/// @param deployer The contract address of the PancakeSwap V3 deployer
/// @param poolKey The identifying key of the V3 pool
/// @return pool The V3 pool contract address
function verifyCallback(address deployer, PoolKey memory poolKey)
public
view
returns (IPancakeV3Pool pool)
{
pool = IPancakeV3Pool(computeAddress(deployer, poolKey));
require(msg.sender == address(pool));
}
}
Compiler Settings
{"outputSelection":{"*":{"*":["abi","evm.bytecode","evm.deployedBytecode","evm.methodIdentifiers","metadata"],"":["ast"]}},"optimizer":{"runs":10,"enabled":true},"libraries":{"contracts/libraries/SmartRouterHelper.sol":{"SmartRouterHelper":"0x28ffa46cbe1c37ca28092c7b7e6c742aba1c4c69"}}}
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"_factoryV2","internalType":"address"},{"type":"address","name":"_positionManager","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint8[]","name":"isFotResults","internalType":"enum ITokenValidator.Status[]"}],"name":"batchValidate","inputs":[{"type":"address[]","name":"tokens","internalType":"address[]"},{"type":"address[]","name":"baseTokens","internalType":"address[]"},{"type":"uint256","name":"amountToBorrow","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"factoryV2","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"positionManager","inputs":[]},{"type":"function","stateMutability":"view","outputs":[],"name":"uniswapV2Call","inputs":[{"type":"address","name":"","internalType":"address"},{"type":"uint256","name":"amount0","internalType":"uint256"},{"type":"uint256","name":"","internalType":"uint256"},{"type":"bytes","name":"data","internalType":"bytes"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint8","name":"","internalType":"enum ITokenValidator.Status"}],"name":"validate","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"address[]","name":"baseTokens","internalType":"address[]"},{"type":"uint256","name":"amountToBorrow","internalType":"uint256"}]}]
0x60c060405234801561001057600080fd5b50604051610e1b380380610e1b83398101604081905261002f91610069565b6001600160601b0319606092831b8116608052911b1660a05261009b565b80516001600160a01b038116811461006457600080fd5b919050565b6000806040838503121561007b578182fd5b6100848361004d565b91506100926020840161004d565b90509250929050565b60805160601c60a05160601c610d576100c46000398061037152508061034d5250610d576000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c80630143aace1461005c57806310d1e85c1461008557806368e0d4e11461009a578063791b98bc146100af578063be7672e5146100b7575b600080fd5b61006f61006a36600461090d565b6100d7565b60405161007c9190610b77565b60405180910390f35b610098610093366004610966565b61015c565b005b6100a261034b565b60405161007c9190610af5565b6100a261036f565b6100ca6100c53660046109f6565b610393565b60405161007c9190610b2c565b6000805b8381101561014e576000610110878787858181106100f557fe5b905060200201602081019061010a91906108d5565b86610450565b9050600181600281111561012057fe5b14806101375750600281600281111561013557fe5b145b156101455791506101549050565b506001016100db565b50600090505b949350505050565b6000339050600080826001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561019d57600080fd5b505afa1580156101b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101d591906108f1565b836001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b15801561020e57600080fd5b505afa158015610222573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061024691906108f1565b915091506000808811610259578161025b565b825b905060008061026c87890189610a7e565b91509150600082846001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161029f9190610af5565b60206040518083038186803b1580156102b757600080fd5b505afa1580156102cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102ef9190610a66565b0390508181146103335760408051808201825260038152621193d560ea1b6020820152905162461bcd60e51b815261032a9190600401610b8b565b60405180910390fd5b60405162461bcd60e51b815260040161032a90610b9e565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b6060846001600160401b03811180156103ab57600080fd5b506040519080825280602002602001820160405280156103d5578160200160208202803683370190505b50905060005b858110156104465761040f8787838181106103f257fe5b905060200201602081019061040791906108d5565b8686866100d7565b82828151811061041b57fe5b6020026020010190600281111561042e57fe5b9081600281111561043b57fe5b9052506001016103db565b5095945050505050565b6000826001600160a01b0316846001600160a01b03161415610474575060006107df565b60007328ffa46cbe1c37ca28092c7b7e6c742aba1c4c69636d91c0e2306001600160a01b03166368e0d4e16040518163ffffffff1660e01b815260040160206040518083038186803b1580156104c957600080fd5b505afa1580156104dd573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061050191906108f1565b87876040518463ffffffff1660e01b815260040161052193929190610b09565b60206040518083038186803b15801561053957600080fd5b505af415801561054d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061057191906108f1565b60408051600481526024810182526020810180516001600160e01b0316630dfe168160e01b17905290519192506000916001600160a01b038416916105b591610ad9565b6000604051808303816000865af19150503d80600081146105f2576040519150601f19603f3d011682016040523d82523d6000602084013e6105f7565b606091505b50915050805160001415610610576000925050506107df565b60008180602001905181019061062691906108f1565b9050600080826001600160a01b0316896001600160a01b03161461064c57600087610650565b8660005b915091506000896001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016106829190610af5565b60206040518083038186803b15801561069a57600080fd5b505afa1580156106ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106d29190610a66565b90506000869050806001600160a01b031663022c0d9f858530868e6040516020016106fe929190610be9565b6040516020818303038152906040526040518563ffffffff1660e01b815260040161072c9493929190610bf7565b600060405180830381600087803b15801561074657600080fd5b505af1925050508015610757575060015b6107c757610763610c64565b8061076e57506107bd565b610777816107e6565b1561078d576001985050505050505050506107df565b6107968161082f565b156107ac576002985050505050505050506107df565b6000985050505050505050506107df565b3d6000803e3d6000fd5b60405162461bcd60e51b815260040161032a90610bbf565b9392505050565b6040805180820190915260038152621193d560ea1b6020918201528151908201207f0d441c7cb74abc94cc606c98870ca9174ef5b167b2f7ffed505658cf4574b003145b919050565b60408051808201909152600f8082526e1514905394d1915497d19052531151608a1b602083015282516000929180821015610870576000935050505061082a565b602092830181902091819003850190920191909120149050919050565b60008083601f84011261089e578182fd5b5081356001600160401b038111156108b4578182fd5b60208301915083602080830285010111156108ce57600080fd5b9250929050565b6000602082840312156108e6578081fd5b81356107df81610d09565b600060208284031215610902578081fd5b81516107df81610d09565b60008060008060608587031215610922578283fd5b843561092d81610d09565b935060208501356001600160401b03811115610947578384fd5b6109538782880161088d565b9598909750949560400135949350505050565b60008060008060006080868803121561097d578081fd5b853561098881610d09565b9450602086013593506040860135925060608601356001600160401b03808211156109b1578283fd5b818801915088601f8301126109c4578283fd5b8135818111156109d2578384fd5b8960208285010111156109e3578384fd5b9699959850939650602001949392505050565b600080600080600060608688031215610a0d578081fd5b85356001600160401b0380821115610a23578283fd5b610a2f89838a0161088d565b90975095506020880135915080821115610a47578283fd5b50610a548882890161088d565b96999598509660400135949350505050565b600060208284031215610a77578081fd5b5051919050565b60008060408385031215610a90578182fd5b50508035926020909101359150565b60008151808452610ab7816020860160208601610c2e565b601f01601f19169290920160200192915050565b60038110610ad557fe5b9052565b60008251610aeb818460208701610c2e565b9190910192915050565b6001600160a01b0391909116815260200190565b6001600160a01b0393841681529183166020830152909116604082015260600190565b6020808252825182820181905260009190848201906040850190845b81811015610b6b57610b5b838551610acb565b9284019291840191600101610b48565b50909695505050505050565b60208101610b858284610acb565b92915050565b6000602082526107df6020830184610a9f565b6020808252600790820152662ab735b737bbb760c91b604082015260600190565b60208082526010908201526f2ab732bc3832b1ba32b21032b93937b960811b604082015260600190565b918252602082015260400190565b600085825284602083015260018060a01b038416604083015260806060830152610c246080830184610a9f565b9695505050505050565b60005b83811015610c49578181015183820152602001610c31565b83811115610c58576000848401525b50505050565b60e01c90565b600060443d1015610c7457610d06565b600481823e6308c379a0610c888251610c5e565b14610c9257610d06565b6040513d600319016004823e80513d6001600160401b038083116024840183101715610cc15750505050610d06565b82840192508251915080821115610cdb5750505050610d06565b503d83016020828401011115610cf357505050610d06565b601f01601f191681016020016040529150505b90565b6001600160a01b0381168114610d1e57600080fd5b5056fea26469706673582212204c5c09a6cc29ff5fd04d7715865fd80a155ee4d95269ea9629de62475eea3ea864736f6c63430007060033000000000000000000000000f06749acdc842d0ebaca8d169d3e60a5602ad1210000000000000000000000001b308c3d8a3f015eff686ab6fde241c7fbad7b6f
Deployed ByteCode
0x608060405234801561001057600080fd5b50600436106100575760003560e01c80630143aace1461005c57806310d1e85c1461008557806368e0d4e11461009a578063791b98bc146100af578063be7672e5146100b7575b600080fd5b61006f61006a36600461090d565b6100d7565b60405161007c9190610b77565b60405180910390f35b610098610093366004610966565b61015c565b005b6100a261034b565b60405161007c9190610af5565b6100a261036f565b6100ca6100c53660046109f6565b610393565b60405161007c9190610b2c565b6000805b8381101561014e576000610110878787858181106100f557fe5b905060200201602081019061010a91906108d5565b86610450565b9050600181600281111561012057fe5b14806101375750600281600281111561013557fe5b145b156101455791506101549050565b506001016100db565b50600090505b949350505050565b6000339050600080826001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561019d57600080fd5b505afa1580156101b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101d591906108f1565b836001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b15801561020e57600080fd5b505afa158015610222573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061024691906108f1565b915091506000808811610259578161025b565b825b905060008061026c87890189610a7e565b91509150600082846001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161029f9190610af5565b60206040518083038186803b1580156102b757600080fd5b505afa1580156102cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102ef9190610a66565b0390508181146103335760408051808201825260038152621193d560ea1b6020820152905162461bcd60e51b815261032a9190600401610b8b565b60405180910390fd5b60405162461bcd60e51b815260040161032a90610b9e565b7f000000000000000000000000f06749acdc842d0ebaca8d169d3e60a5602ad12181565b7f0000000000000000000000001b308c3d8a3f015eff686ab6fde241c7fbad7b6f81565b6060846001600160401b03811180156103ab57600080fd5b506040519080825280602002602001820160405280156103d5578160200160208202803683370190505b50905060005b858110156104465761040f8787838181106103f257fe5b905060200201602081019061040791906108d5565b8686866100d7565b82828151811061041b57fe5b6020026020010190600281111561042e57fe5b9081600281111561043b57fe5b9052506001016103db565b5095945050505050565b6000826001600160a01b0316846001600160a01b03161415610474575060006107df565b60007328ffa46cbe1c37ca28092c7b7e6c742aba1c4c69636d91c0e2306001600160a01b03166368e0d4e16040518163ffffffff1660e01b815260040160206040518083038186803b1580156104c957600080fd5b505afa1580156104dd573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061050191906108f1565b87876040518463ffffffff1660e01b815260040161052193929190610b09565b60206040518083038186803b15801561053957600080fd5b505af415801561054d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061057191906108f1565b60408051600481526024810182526020810180516001600160e01b0316630dfe168160e01b17905290519192506000916001600160a01b038416916105b591610ad9565b6000604051808303816000865af19150503d80600081146105f2576040519150601f19603f3d011682016040523d82523d6000602084013e6105f7565b606091505b50915050805160001415610610576000925050506107df565b60008180602001905181019061062691906108f1565b9050600080826001600160a01b0316896001600160a01b03161461064c57600087610650565b8660005b915091506000896001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016106829190610af5565b60206040518083038186803b15801561069a57600080fd5b505afa1580156106ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106d29190610a66565b90506000869050806001600160a01b031663022c0d9f858530868e6040516020016106fe929190610be9565b6040516020818303038152906040526040518563ffffffff1660e01b815260040161072c9493929190610bf7565b600060405180830381600087803b15801561074657600080fd5b505af1925050508015610757575060015b6107c757610763610c64565b8061076e57506107bd565b610777816107e6565b1561078d576001985050505050505050506107df565b6107968161082f565b156107ac576002985050505050505050506107df565b6000985050505050505050506107df565b3d6000803e3d6000fd5b60405162461bcd60e51b815260040161032a90610bbf565b9392505050565b6040805180820190915260038152621193d560ea1b6020918201528151908201207f0d441c7cb74abc94cc606c98870ca9174ef5b167b2f7ffed505658cf4574b003145b919050565b60408051808201909152600f8082526e1514905394d1915497d19052531151608a1b602083015282516000929180821015610870576000935050505061082a565b602092830181902091819003850190920191909120149050919050565b60008083601f84011261089e578182fd5b5081356001600160401b038111156108b4578182fd5b60208301915083602080830285010111156108ce57600080fd5b9250929050565b6000602082840312156108e6578081fd5b81356107df81610d09565b600060208284031215610902578081fd5b81516107df81610d09565b60008060008060608587031215610922578283fd5b843561092d81610d09565b935060208501356001600160401b03811115610947578384fd5b6109538782880161088d565b9598909750949560400135949350505050565b60008060008060006080868803121561097d578081fd5b853561098881610d09565b9450602086013593506040860135925060608601356001600160401b03808211156109b1578283fd5b818801915088601f8301126109c4578283fd5b8135818111156109d2578384fd5b8960208285010111156109e3578384fd5b9699959850939650602001949392505050565b600080600080600060608688031215610a0d578081fd5b85356001600160401b0380821115610a23578283fd5b610a2f89838a0161088d565b90975095506020880135915080821115610a47578283fd5b50610a548882890161088d565b96999598509660400135949350505050565b600060208284031215610a77578081fd5b5051919050565b60008060408385031215610a90578182fd5b50508035926020909101359150565b60008151808452610ab7816020860160208601610c2e565b601f01601f19169290920160200192915050565b60038110610ad557fe5b9052565b60008251610aeb818460208701610c2e565b9190910192915050565b6001600160a01b0391909116815260200190565b6001600160a01b0393841681529183166020830152909116604082015260600190565b6020808252825182820181905260009190848201906040850190845b81811015610b6b57610b5b838551610acb565b9284019291840191600101610b48565b50909695505050505050565b60208101610b858284610acb565b92915050565b6000602082526107df6020830184610a9f565b6020808252600790820152662ab735b737bbb760c91b604082015260600190565b60208082526010908201526f2ab732bc3832b1ba32b21032b93937b960811b604082015260600190565b918252602082015260400190565b600085825284602083015260018060a01b038416604083015260806060830152610c246080830184610a9f565b9695505050505050565b60005b83811015610c49578181015183820152602001610c31565b83811115610c58576000848401525b50505050565b60e01c90565b600060443d1015610c7457610d06565b600481823e6308c379a0610c888251610c5e565b14610c9257610d06565b6040513d600319016004823e80513d6001600160401b038083116024840183101715610cc15750505050610d06565b82840192508251915080821115610cdb5750505050610d06565b503d83016020828401011115610cf357505050610d06565b601f01601f191681016020016040529150505b90565b6001600160a01b0381168114610d1e57600080fd5b5056fea26469706673582212204c5c09a6cc29ff5fd04d7715865fd80a155ee4d95269ea9629de62475eea3ea864736f6c63430007060033