Source Code
| Transaction Hash |
Method
|
Block
|
From
|
|
To
|
||||
|---|---|---|---|---|---|---|---|---|---|
| 0x8040a5efa41388b80a33db77eec3d84058c2b1062e1a33f5f203a7328306c12a | Dag Swap By Orde... | (pending) | 2 secs ago | IN | 0.3693083086 ETH | (Pending) | |||
| Dag Swap By Orde... | 23737131 | 15 secs ago | IN | 0 ETH | 0.00012239 | ||||
| Uniswap V3Swap T... | 23737131 | 15 secs ago | IN | 0.00240209 ETH | 0.00006222 | ||||
| Dag Swap By Orde... | 23737130 | 27 secs ago | IN | 0 ETH | 0.0001312 | ||||
| Uniswap V3Swap T... | 23737127 | 1 min ago | IN | 0 ETH | 0.00007115 | ||||
| Dag Swap By Orde... | 23737124 | 1 min ago | IN | 0 ETH | 0.00012746 | ||||
| Dag Swap By Orde... | 23737124 | 1 min ago | IN | 0 ETH | 0.00013082 | ||||
| Dag Swap By Orde... | 23737122 | 2 mins ago | IN | 0 ETH | 0.00011971 | ||||
| Dag Swap By Orde... | 23737122 | 2 mins ago | IN | 0 ETH | 0.00012286 | ||||
| Dag Swap By Orde... | 23737119 | 2 mins ago | IN | 0 ETH | 0.00016769 | ||||
| Uniswap V3Swap T... | 23737115 | 3 mins ago | IN | 0 ETH | 0.00006919 | ||||
| Uniswap V3Swap T... | 23737115 | 3 mins ago | IN | 0 ETH | 0.00007449 | ||||
| Dag Swap By Orde... | 23737113 | 3 mins ago | IN | 0.00046088 ETH | 0.00006192 | ||||
| Uniswap V3Swap T... | 23737111 | 4 mins ago | IN | 0 ETH | 0.00007116 | ||||
| Dag Swap By Orde... | 23737107 | 5 mins ago | IN | 0 ETH | 0.00008071 | ||||
| Dag Swap To | 23737105 | 5 mins ago | IN | 0 ETH | 0.00010343 | ||||
| Dag Swap By Orde... | 23737104 | 5 mins ago | IN | 0.00020409 ETH | 0.00006116 | ||||
| Uniswap V3Swap T... | 23737103 | 5 mins ago | IN | 0.00013155 ETH | 0.00011144 | ||||
| Uniswap V3Swap T... | 23737101 | 6 mins ago | IN | 0 ETH | 0.0000818 | ||||
| Uniswap V3Swap T... | 23737100 | 6 mins ago | IN | 0.00635883 ETH | 0.0000652 | ||||
| Dag Swap By Orde... | 23737098 | 6 mins ago | IN | 0 ETH | 0.00010661 | ||||
| Dag Swap By Orde... | 23737094 | 7 mins ago | IN | 0 ETH | 0.00013087 | ||||
| Dag Swap By Orde... | 23737093 | 7 mins ago | IN | 0 ETH | 0.00016745 | ||||
| Uniswap V3Swap T... | 23737093 | 7 mins ago | IN | 0 ETH | 0.00007936 | ||||
| Uniswap V3Swap T... | 23737092 | 8 mins ago | IN | 0 ETH | 0.00008901 |
Latest 25 internal transactions (View All)
Advanced mode:
| Parent Transaction Hash | Method | Block |
From
|
|
To
|
||
|---|---|---|---|---|---|---|---|
| Transfer | 23737130 | 27 secs ago | 0.14558441 ETH | ||||
| Transfer | 23737130 | 27 secs ago | 0.14558441 ETH | ||||
| Deposit | 23737130 | 27 secs ago | 0.00299229 ETH | ||||
| Transfer | 23737130 | 27 secs ago | 0.00000002 ETH | ||||
| Transfer | 23737130 | 27 secs ago | 0 ETH | ||||
| Dag Swap To | 23737130 | 27 secs ago | 0.00299232 ETH | ||||
| Deposit | 23737128 | 51 secs ago | 0.0029923 ETH | ||||
| Transfer | 23737128 | 51 secs ago | 0.00000002 ETH | ||||
| Transfer | 23737128 | 51 secs ago | 0 ETH | ||||
| Dag Swap To | 23737128 | 51 secs ago | 0.00299233 ETH | ||||
| Deposit | 23737126 | 1 min ago | 0.00299229 ETH | ||||
| Transfer | 23737126 | 1 min ago | 0.00000002 ETH | ||||
| Transfer | 23737126 | 1 min ago | 0 ETH | ||||
| Dag Swap To | 23737126 | 1 min ago | 0.00299232 ETH | ||||
| Deposit | 23737124 | 1 min ago | 0.0029923 ETH | ||||
| Transfer | 23737124 | 1 min ago | 0.00000002 ETH | ||||
| Transfer | 23737124 | 1 min ago | 0 ETH | ||||
| Dag Swap To | 23737124 | 1 min ago | 0.00299233 ETH | ||||
| Deposit | 23737122 | 2 mins ago | 0.0029923 ETH | ||||
| Transfer | 23737122 | 2 mins ago | 0.00000002 ETH | ||||
| Transfer | 23737122 | 2 mins ago | 0 ETH | ||||
| Dag Swap To | 23737122 | 2 mins ago | 0.00299233 ETH | ||||
| Deposit | 23737120 | 2 mins ago | 0.0029923 ETH | ||||
| Transfer | 23737120 | 2 mins ago | 0.00000002 ETH | ||||
| Transfer | 23737120 | 2 mins ago | 0 ETH |
Loading...
Loading
Cross-Chain Transactions
Loading...
Loading
Contract Name:
DexRouter
Compiler Version
v0.8.17+commit.8df45f5f
Optimization Enabled:
Yes with 1 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
import "./UnxswapRouter.sol";
import "./UnxswapV3Router.sol";
import "./interfaces/IWETH.sol";
import "./interfaces/IApproveProxy.sol";
import "./interfaces/IWNativeRelayer.sol";
import "./libraries/PMMLib.sol";
import "./libraries/CommissionLib.sol";
import "./libraries/EthReceiver.sol";
import "./libraries/UniswapTokenInfoHelper.sol";
import "./libraries/CommonLib.sol";
import "./DagRouter.sol";
/// @title DexRouterV1
/// @notice Entrance of Split trading in Dex platform
/// @dev Entrance of Split trading in Dex platform
contract DexRouter is
EthReceiver,
UnxswapRouter,
UnxswapV3Router,
CommissionLib,
UniswapTokenInfoHelper,
DagRouter
{
string public constant version = "v1.0.6-dag";
using UniversalERC20 for IERC20;
//-------------------------------
//------- Modifier --------------
//-------------------------------
/// @notice Ensures a function is called before a specified deadline.
/// @param deadLine The UNIX timestamp deadline.
modifier isExpired(uint256 deadLine) {
require(deadLine >= block.timestamp, "Route: expired");
_;
}
//-------------------------------
//------- Internal Functions ----
//-------------------------------
/// @notice Executes multiple adapters for a transaction pair.
/// @param payer The address of the payer.
/// @param to The address of the receiver.
/// @param batchAmount The amount to be transferred in each batch.
/// @param path The routing path for the swap.
/// @param noTransfer A flag to indicate whether the token transfer should be skipped.
/// @dev It includes checks for the total weight of the paths and executes the swapping through the adapters.
function _exeForks(
address payer,
address refundTo,
address to,
uint256 batchAmount,
RouterPath memory path,
bool noTransfer
) private {
uint256 totalWeight;
for (uint256 i = 0; i < path.mixAdapters.length; i++) {
bytes32 rawData = bytes32(path.rawData[i]);
address poolAddress;
bool reverse;
{
uint256 weight;
assembly {
poolAddress := and(rawData, _ADDRESS_MASK)
reverse := and(rawData, _REVERSE_MASK)
weight := shr(160, and(rawData, _WEIGHT_MASK))
}
totalWeight += weight;
if (i == path.mixAdapters.length - 1) {
require(
totalWeight <= 10_000,
"totalWeight can not exceed 10000 limit"
);
}
if (!noTransfer) {
uint256 _fromTokenAmount = weight == 10_000
? batchAmount
: (batchAmount * weight) / 10_000;
_transferInternal(
payer,
path.assetTo[i],
path.fromToken,
_fromTokenAmount
);
}
}
_exeAdapter(
reverse,
path.mixAdapters[i],
to,
poolAddress,
path.extraData[i],
refundTo
);
}
}
/// @notice Executes a series of swaps or operations defined by a set of routing paths, potentially across different protocols or pools.
/// @param payer The address providing the tokens for the swap.
/// @param receiver The address receiving the output tokens.
/// @param isToNative Indicates whether the final asset should be converted to the native blockchain asset (e.g., ETH).
/// @param batchAmount The total amount of the input token to be swapped.
/// @param hops An array of RouterPath structures, each defining a segment of the swap route.
/// @dev This function manages complex swap routes that might involve multiple hops through different liquidity pools or swapping protocols.
/// It iterates through the provided `hops`, executing each segment of the route in sequence.
function _exeHop(
address payer,
address refundTo,
address receiver,
bool isToNative,
uint256 batchAmount,
RouterPath[] memory hops
) private {
address fromToken = _bytes32ToAddress(hops[0].fromToken);
bool toNext;
bool noTransfer;
// execute hop
uint256 hopLength = hops.length;
for (uint256 i = 0; i < hopLength; ) {
if (i > 0) {
fromToken = _bytes32ToAddress(hops[i].fromToken);
batchAmount = _getBalanceOf(fromToken, address(this));
payer = address(this);
}
address to = address(this);
if (i == hopLength - 1 && !isToNative) {
to = receiver;
} else if (i < hopLength - 1 && hops[i + 1].assetTo.length == 1) {
to = hops[i + 1].assetTo[0];
toNext = true;
} else {
toNext = false;
}
// 3.2 execute forks
_exeForks(payer, refundTo, to, batchAmount, hops[i], noTransfer);
noTransfer = toNext;
unchecked {
++i;
}
}
}
/// @notice Executes a complex swap based on provided parameters and paths.
/// @param baseRequest Basic swap details including tokens, amounts, and deadline.
/// @param batchesAmount Amounts for each swap batch.
/// @param batches Detailed swap paths for execution.
/// @param payer Address providing the tokens.
/// @param receiver Address receiving the swapped tokens.
function _smartSwapInternal(
BaseRequest memory baseRequest,
uint256[] memory batchesAmount,
RouterPath[][] memory batches,
address payer,
address refundTo,
address receiver
) private {
// 1. transfer from token in
BaseRequest memory _baseRequest = baseRequest;
address fromToken = _bytes32ToAddress(_baseRequest.fromToken);
// In order to deal with ETH/WETH transfer rules in a unified manner,
// we do not need to judge according to fromToken.
if (UniversalERC20.isETH(IERC20(fromToken))) {
IWETH(_WETH).deposit{
value: _baseRequest.fromTokenAmount
}();
require(_bytes32ToAddress(batches[0][0].fromToken) == _WETH, "firstToken mismatch");
payer = address(this);
} else {
require(_bytes32ToAddress(batches[0][0].fromToken) == fromToken, "firstToken mismatch");
}
// 2. check total batch amount
{
// avoid stack too deep
uint256 totalBatchAmount;
for (uint256 i = 0; i < batchesAmount.length; ) {
totalBatchAmount += batchesAmount[i];
unchecked {
++i;
}
}
require(
totalBatchAmount <= _baseRequest.fromTokenAmount,
"Route: number of batches should be <= fromTokenAmount"
);
}
// 4. execute batch
// check length, fix DRW-02: LACK OF LENGTH CHECK ON BATATCHES
require(batchesAmount.length == batches.length, "length mismatch");
for (uint256 i = 0; i < batches.length; ) {
if (i > 0) {
require(batches[i][0].fromToken == batches[0][0].fromToken, "Inconsistent fromToken across batches");
}
// execute hop, if the whole swap replacing by pmm fails, the funds will return to dexRouter
_exeHop(
payer,
refundTo,
receiver,
IERC20(_baseRequest.toToken).isETH(),
batchesAmount[i],
batches[i]
);
unchecked {
++i;
}
}
// 5. transfer tokens to user
_transferTokenToUser(_baseRequest.toToken, receiver);
}
//-------------------------------
//------- Users Functions -------
//-------------------------------
/// @notice Executes a smart swap based on the given order ID, supporting complex multi-path swaps. For smartSwap, if fromToken or toToken is ETH, the address needs to be 0xEeee.
/// @param orderId The unique identifier for the swap order, facilitating tracking and reference.
/// @param baseRequest Struct containing the base parameters for the swap, including the source and destination tokens, amount, minimum return, and deadline.
/// @param batchesAmount An array specifying the amount to be swapped in each batch, allowing for split operations.
/// @param batches An array of RouterPath structs defining the routing paths for each batch, enabling swaps through multiple protocols or liquidity pools.
/// @return returnAmount The total amount of destination tokens received from executing the swap.
/// @dev This function orchestrates a swap operation that may involve multiple steps, routes, or protocols based on the provided parameters.
/// It's designed to ensure flexibility and efficiency in finding the best swap paths.
function smartSwapByOrderId(
uint256 orderId,
BaseRequest calldata baseRequest,
uint256[] calldata batchesAmount,
RouterPath[][] calldata batches,
PMMLib.PMMSwapRequest[] calldata // extraData
)
external
payable
isExpired(baseRequest.deadLine)
returns (uint256 returnAmount)
{
emit SwapOrderId(orderId);
return
_smartSwapTo(
msg.sender,
msg.sender,
msg.sender,
baseRequest,
batchesAmount,
batches
);
}
/// @notice Executes a token swap using the Unxswap protocol based on a specified order ID.
/// @param srcToken The source token involved in the swap.
/// @param amount The amount of the source token to be swapped.
/// @param minReturn The minimum amount of tokens expected to be received to ensure the swap does not proceed under unfavorable conditions.
/// @param pools An array of pool identifiers specifying the pools to use for the swap, allowing for optimized routing.
/// @return returnAmount The amount of destination tokens received from the swap.
/// @dev This function allows users to perform token swaps based on predefined orders, leveraging the Unxswap protocol's liquidity pools. It ensures that the swap meets the user's specified minimum return criteria, enhancing trade efficiency and security.
function unxswapByOrderId(
uint256 srcToken,
uint256 amount,
uint256 minReturn,
// solhint-disable-next-line no-unused-vars
bytes32[] calldata pools
) external payable returns (uint256 returnAmount) {
return unxswapTo(
srcToken,
amount,
minReturn,
msg.sender,
pools
);
}
/// @notice Executes a swap tailored for investment purposes, adjusting swap amounts based on the contract's balance. For smartSwap, if fromToken or toToken is ETH, the address needs to be 0xEeee.
/// @param baseRequest Struct containing essential swap parameters like source and destination tokens, amounts, and deadline.
/// @param batchesAmount Array indicating how much of the source token to swap in each batch, facilitating diversified investments.
/// @param batches Detailed routing information for executing the swap across different paths or protocols.
/// @param extraData Additional data for swaps, supporting protocol-specific requirements.
/// @param to The address where the swapped tokens will be sent, typically an investment contract or pool.
/// @return returnAmount The total amount of destination tokens received, ready for investment.
/// @dev This function is designed for scenarios where investments are made in batches or through complex paths to optimize returns. Adjustments are made based on the contract's current token balance to ensure precise allocation.
function smartSwapByInvest( // change function name
BaseRequest memory baseRequest,
uint256[] memory batchesAmount,
RouterPath[][] memory batches,
PMMLib.PMMSwapRequest[] memory extraData,
address to
) external payable returns (uint256 returnAmount) {
return
smartSwapByInvestWithRefund(
baseRequest,
batchesAmount,
batches,
extraData,
to,
to
);
}
function smartSwapByInvestWithRefund(
BaseRequest memory baseRequest,
uint256[] memory batchesAmount,
RouterPath[][] memory batches,
PMMLib.PMMSwapRequest[] memory, // extraData
address to,
address refundTo
)
public
payable
isExpired(baseRequest.deadLine)
returns (uint256 returnAmount)
{
address fromToken = _bytes32ToAddress(baseRequest.fromToken);
require(fromToken != _ETH, "Invalid source token");
require(refundTo != address(0), "refundTo is address(0)");
require(to != address(0), "to is address(0)");
require(baseRequest.fromTokenAmount > 0, "fromTokenAmount is 0");
uint256 amount = IERC20(fromToken).balanceOf(address(this));
for (uint256 i = 0; i < batchesAmount.length; ) {
batchesAmount[i] =
(batchesAmount[i] * amount) /
baseRequest.fromTokenAmount;
unchecked {
++i;
}
}
baseRequest.fromTokenAmount = amount;
returnAmount = _getBalanceOf(baseRequest.toToken, to);
_smartSwapInternal(
baseRequest,
batchesAmount,
batches,
address(this), // payer
refundTo, // refundTo
to // receiver
);
// check minReturnAmount
returnAmount =
_getBalanceOf(baseRequest.toToken, to) -
returnAmount;
require(
returnAmount >= baseRequest.minReturnAmount,
"Min return not reached"
);
emit OrderRecord(
fromToken,
baseRequest.toToken,
tx.origin,
baseRequest.fromTokenAmount,
returnAmount
);
}
/// @notice Executes a swap using the Uniswap V3 protocol.
/// @param receiver The address that will receive the swap funds.
/// @param amount The amount of the source token to be swapped.
/// @param minReturn The minimum acceptable amount of tokens to receive from the swap, guarding against excessive slippage.
/// @param pools An array of pool identifiers used to define the swap route within Uniswap V3.
/// @return returnAmount The amount of tokens received after the completion of the swap.
/// @dev This function wraps and unwraps ETH as required, ensuring the transaction only accepts non-zero `msg.value` for ETH swaps. It invokes `_uniswapV3Swap` to execute the actual swap and handles commission post-swap.
function uniswapV3SwapTo(
uint256 receiver,
uint256 amount,
uint256 minReturn,
uint256[] calldata pools
) external payable returns (uint256 returnAmount) {
emit SwapOrderId((receiver & _ORDER_ID_MASK) >> 160);
(address srcToken, address toToken) = _getUniswapV3TokenInfo(msg.value > 0, pools);
return
_uniswapV3SwapTo(
msg.sender,
receiver,
srcToken,
toToken,
amount,
minReturn,
pools
);
}
/// @notice If srcToken or toToken is ETH, the address needs to be 0xEeee. And for commission validation, ETH needs to be 0xEeee.
function _uniswapV3SwapTo(
address payer,
uint256 receiver,
address srcToken,
address toToken,
uint256 amount,
uint256 minReturn,
uint256[] calldata pools
) internal returns (uint256 returnAmount) {
address receiverAddr = (receiver & _ADDRESS_MASK) == 0 ? msg.sender : _bytes32ToAddress(receiver);
(CommissionInfo memory commissionInfo, TrimInfo memory trimInfo) = _getCommissionAndTrimInfo();
// add permit2
_validateCommissionInfo(commissionInfo, srcToken, toToken, _MODE_LEGACY);
returnAmount = _getBalanceOf(toToken, receiverAddr);
_doUniswapV3Swap(
payer,
receiverAddr,
amount,
minReturn,
toToken,
pools,
commissionInfo,
trimInfo
);
// check minReturnAmount
returnAmount = _getBalanceOf(toToken, receiverAddr) - returnAmount;
require(
returnAmount >= minReturn,
"Min return not reached"
);
emit OrderRecord(
srcToken,
toToken,
tx.origin,
amount,
returnAmount
);
}
function _doUniswapV3Swap(
address payer,
address receiver,
uint256 amount,
uint256 minReturn,
address toToken,
uint256[] calldata pools,
CommissionInfo memory commissionInfo,
TrimInfo memory trimInfo
) private {
(
address middleReceiver,
uint256 balanceBefore
) = _doCommissionFromToken(
commissionInfo,
payer,
receiver,
amount,
trimInfo.hasTrim,
toToken
);
_uniswapV3Swap(
payer,
payable(middleReceiver),
amount,
minReturn,
pools
);
_doCommissionAndTrimToToken(
commissionInfo,
receiver,
balanceBefore,
toToken,
trimInfo
);
}
/// @notice Executes a smart swap directly to a specified receiver address.
/// @param orderId Unique identifier for the swap order, facilitating tracking.
/// @param receiver Address to receive the output tokens from the swap.
/// @param baseRequest Contains essential parameters for the swap such as source and destination tokens, amounts, and deadline.
/// @param batchesAmount Array indicating amounts for each batch in the swap, allowing for split operations.
/// @param batches Detailed routing information for executing the swap across different paths or protocols.
/// @return returnAmount The total amount of destination tokens received from the swap.
/// @dev This function enables users to perform token swaps with complex routing directly to a specified address,
/// optimizing for best returns and accommodating specific trading strategies.
function smartSwapTo(
uint256 orderId,
address receiver,
BaseRequest calldata baseRequest,
uint256[] calldata batchesAmount,
RouterPath[][] calldata batches,
PMMLib.PMMSwapRequest[] calldata // extraData
)
external
payable
isExpired(baseRequest.deadLine)
returns (uint256 returnAmount)
{
emit SwapOrderId(orderId);
return
_smartSwapTo(
msg.sender,
msg.sender,
receiver,
baseRequest,
batchesAmount,
batches
);
}
/// @notice If fromToken or toToken is ETH, the address needs to be 0xEeee. And for commission validation, ETH needs to be 0xEeee.
function _smartSwapTo(
address payer,
address refundTo,
address receiver,
BaseRequest memory baseRequest,
uint256[] memory batchesAmount,
RouterPath[][] memory batches
) internal returns (uint256 returnAmount) {
receiver = receiver == address(0) ? msg.sender : receiver;
(CommissionInfo memory commissionInfo, TrimInfo memory trimInfo) = _getCommissionAndTrimInfo();
uint256 mode = batches[0][0].fromToken & _TRANSFER_MODE_MASK;
_validateCommissionInfo(commissionInfo, _bytes32ToAddress(baseRequest.fromToken), baseRequest.toToken, mode);
returnAmount = _getBalanceOf(baseRequest.toToken, receiver);
{
(
address middleReceiver,
uint256 balanceBefore
) = _doCommissionFromToken(
commissionInfo,
payer,
receiver,
baseRequest.fromTokenAmount,
trimInfo.hasTrim,
baseRequest.toToken
);
_smartSwapInternal(
baseRequest,
batchesAmount,
batches,
payer,
refundTo,
middleReceiver
);
_doCommissionAndTrimToToken(
commissionInfo,
receiver,
balanceBefore,
baseRequest.toToken,
trimInfo
);
}
// check minReturnAmount
returnAmount =
_getBalanceOf(baseRequest.toToken, receiver) -
returnAmount;
require(
returnAmount >= baseRequest.minReturnAmount,
"Min return not reached"
);
emit OrderRecord(
_bytes32ToAddress(baseRequest.fromToken),
baseRequest.toToken,
tx.origin,
baseRequest.fromTokenAmount,
returnAmount
);
}
/// @notice Executes a token swap using the Unxswap protocol, sending the output directly to a specified receiver.
/// The srcToken can be 0xEeee or address(0) for temporary use, the address(0) usage will removed in the future.
/// @param srcToken The source token to be swapped.
/// @param amount The amount of the source token to be swapped.
/// @param minReturn The minimum amount of destination tokens expected from the swap, ensuring the trade does not proceed under unfavorable conditions.
/// @param receiver The address where the swapped tokens will be sent.
/// @param pools An array of pool identifiers to specify the swap route, optimizing for best rates.
/// @return returnAmount The total amount of destination tokens received from the swap.
/// @dev This function facilitates direct swaps using Unxswap, allowing users to specify custom swap routes and ensuring that the output is sent to a predetermined address. It is designed for scenarios where the user wants to directly receive the tokens in their wallet or another contract.
function unxswapTo(
uint256 srcToken,
uint256 amount,
uint256 minReturn,
address receiver,
// solhint-disable-next-line no-unused-vars
bytes32[] calldata pools
) public payable returns (uint256 returnAmount) {
emit SwapOrderId((srcToken & _ORDER_ID_MASK) >> 160);
// validate token info
(address fromToken, address toToken) = _getUnxswapTokenInfo(msg.value > 0, pools);
address srcTokenAddr = _bytes32ToAddress(srcToken);
srcTokenAddr = srcTokenAddr == address(0) ? _ETH : srcTokenAddr;
require(
srcTokenAddr == fromToken,
"unxswap: token mismatch"
);
return
_unxswapTo(
fromToken,
toToken,
amount,
minReturn,
msg.sender,
receiver,
pools
);
}
/// @notice If srcToken is ETH, srcToken needs to be 0xEeee for commission validation and _unxswapInternal.
function _unxswapTo(
address srcToken,
address toToken,
uint256 amount,
uint256 minReturn,
address payer,
address receiver,
// solhint-disable-next-line no-unused-vars
bytes32[] calldata pools
) internal returns (uint256 returnAmount) {
receiver = receiver == address(0) ? msg.sender : receiver;
(CommissionInfo memory commissionInfo, TrimInfo memory trimInfo) = _getCommissionAndTrimInfo();
_validateCommissionInfo(commissionInfo, srcToken, toToken, _MODE_LEGACY);
returnAmount = _getBalanceOf(toToken, receiver);
_doUnxswap(payer, receiver, srcToken, toToken, amount, minReturn, pools, commissionInfo, trimInfo);
// check minReturnAmount
returnAmount = _getBalanceOf(toToken, receiver) - returnAmount;
require(
returnAmount >= minReturn,
"Min return not reached"
);
emit OrderRecord(
srcToken,
toToken,
tx.origin,
amount,
returnAmount
);
return returnAmount;
}
function _doUnxswap(
address payer,
address receiver,
address srcToken,
address toToken,
uint256 amount,
uint256 minReturn,
bytes32[] calldata pools,
CommissionInfo memory commissionInfo,
TrimInfo memory trimInfo
) private {
(
address middleReceiver,
uint256 balanceBefore
) = _doCommissionFromToken(
commissionInfo,
payer,
receiver,
amount,
trimInfo.hasTrim,
toToken
);
address _payer = payer;
_unxswapInternal(
IERC20(srcToken),
amount,
minReturn,
pools,
_payer,
middleReceiver
);
_doCommissionAndTrimToToken(
commissionInfo,
receiver,
balanceBefore,
toToken,
trimInfo
);
}
/// @notice Executes a Uniswap V3 token swap to a specified receiver using structured base request parameters. For uniswapV3, if fromToken or toToken is ETH, the address needs to be 0xEeee.
/// @param orderId Unique identifier for the swap order, facilitating tracking and reference.
/// @param receiver The address that will receive the swapped tokens.
/// @param baseRequest Struct containing essential swap parameters including source token, destination token, amount, minimum return, and deadline.
/// @param pools An array of pool identifiers defining the Uniswap V3 swap route, with encoded swap direction and unwrap flags.
/// @return returnAmount The total amount of destination tokens received from the swap.
/// @dev This function validates token compatibility with the provided pool route and ensures proper swap execution.
/// It supports both ETH and ERC20 token swaps, with automatic WETH wrapping/unwrapping as needed.
/// The function verifies that fromToken matches the first pool and toToken matches the last pool in the route.
function uniswapV3SwapToWithBaseRequest(
uint256 orderId,
address receiver,
BaseRequest calldata baseRequest,
uint256[] calldata pools
)
external
payable
isExpired(baseRequest.deadLine)
returns (uint256 returnAmount)
{
emit SwapOrderId(orderId);
(address srcToken, address toToken) = _getUniswapV3TokenInfo(msg.value > 0, pools);
// validate fromToken and toToken from baseRequest
require(
_bytes32ToAddress(baseRequest.fromToken) == srcToken && baseRequest.toToken == toToken,
"uniswapV3: token mismatch"
);
return
_uniswapV3SwapTo(
msg.sender,
uint256(uint160(receiver)),
srcToken,
toToken,
baseRequest.fromTokenAmount,
baseRequest.minReturnAmount,
pools
);
}
/// @notice Executes a Unxswap token swap to a specified receiver using structured base request parameters. For unxswap, if fromToken or toToken is ETH, the address can be 0xEeee or address(0) for temporary use, the address(0) usage will removed in the future.
/// @param orderId Unique identifier for the swap order, facilitating tracking and reference.
/// @param receiver The address that will receive the swapped tokens.
/// @param baseRequest Struct containing essential swap parameters including source token, destination token, amount, minimum return, and deadline.
/// @param pools An array of pool identifiers defining the Unxswap route, with encoded swap direction and WETH unwrap flags.
/// @return returnAmount The total amount of destination tokens received from the swap.
/// @dev This function validates token compatibility with the provided pool route and ensures proper swap execution.
/// It supports both ETH and ERC20 token swaps, with automatic WETH wrapping/unwrapping as needed.
/// The function verifies that toToken matches the expected output token from the last pool in the route.
function unxswapToWithBaseRequest(
uint256 orderId,
address receiver,
BaseRequest calldata baseRequest,
bytes32[] calldata pools
)
external
payable
isExpired(baseRequest.deadLine)
returns (uint256 returnAmount)
{
emit SwapOrderId(orderId);
(address fromToken, address toToken) = _getUnxswapTokenInfo(msg.value > 0, pools);
// validate fromToken and toToken from baseRequest
address fromTokenAddr = _bytes32ToAddress(baseRequest.fromToken);
require((fromTokenAddr == fromToken) || (fromTokenAddr == address(0) && fromToken == _ETH), "unxswap: fromToken mismatch");
require((baseRequest.toToken == toToken) || (baseRequest.toToken == address(0) && toToken == _ETH), "unxswap: toToken mismatch");
return
_unxswapTo(
fromToken,
toToken,
baseRequest.fromTokenAmount,
baseRequest.minReturnAmount,
msg.sender,
receiver,
pools
);
}
/// @notice For commission validation, ETH needs to be 0xEeee.
function _swapWrap(
uint256 orderId,
address receiver,
bool reversed,
uint256 amount
) internal {
emit SwapOrderId(orderId);
require(amount > 0, "amount must be > 0");
receiver = receiver == address(0) ? msg.sender : receiver;
(CommissionInfo memory commissionInfo, TrimInfo memory trimInfo) = _getCommissionAndTrimInfo();
address srcToken = reversed ? _WETH : _ETH;
address toToken = reversed ? _ETH : _WETH;
_validateCommissionInfo(commissionInfo, srcToken, toToken, _MODE_LEGACY);
(
address middleReceiver,
uint256 balanceBefore
) = _doCommissionFromToken(
commissionInfo,
msg.sender,
receiver,
amount,
trimInfo.hasTrim,
toToken
);
if (reversed) {
IApproveProxy(_APPROVE_PROXY).claimTokens(
_WETH,
msg.sender,
_WNATIVE_RELAY,
amount
);
IWNativeRelayer(_WNATIVE_RELAY).withdraw(amount);
if (middleReceiver != address(this)) {
(bool success, ) = payable(middleReceiver).call{
value: address(this).balance
}("");
require(success, "transfer native token failed");
}
} else {
if (!commissionInfo.isFromTokenCommission) {
require(msg.value == amount, "value not equal amount");
}
IWETH(_WETH).deposit{value: amount}();
if (middleReceiver != address(this)) {
SafeERC20.safeTransfer(IERC20(_WETH), middleReceiver, amount);
}
}
// emit return amount should be the amount after commission
uint256 toTokenCommissionAndTrimAmount = _doCommissionAndTrimToToken(
commissionInfo,
receiver,
balanceBefore,
toToken,
trimInfo
);
emit OrderRecord(
srcToken,
toToken,
tx.origin,
amount,
amount - toTokenCommissionAndTrimAmount
);
}
/// @notice Executes a simple swap between ETH and WETH using encoded parameters.
/// @param orderId Unique identifier for the swap order, facilitating tracking and reference.
/// @param rawdata Encoded data containing swap direction and amount information using bit masks.
/// @dev This function supports bidirectional swaps between ETH and WETH with minimal gas overhead.
/// The rawdata parameter encodes both the direction (reversed flag) and amount using bit operations.
/// When reversed=false: ETH -> WETH, when reversed=true: WETH -> ETH.
function swapWrap(uint256 orderId, uint256 rawdata) external payable {
bool reversed;
uint128 amount;
assembly {
reversed := and(rawdata, _REVERSE_MASK)
amount := and(rawdata, SWAP_AMOUNT)
}
_swapWrap(orderId, msg.sender, reversed, amount);
}
/// @notice Executes a swap between ETH and WETH using structured base request parameters to a specified receiver.
/// @param orderId Unique identifier for the swap order, facilitating tracking and reference.
/// @param receiver The address that will receive the swapped tokens.
/// @param baseRequest Struct containing essential swap parameters including source token, destination token, amount, minimum return, and deadline.
/// @dev This function validates that the token pair is either ETH->WETH or WETH->ETH and executes the swap accordingly.
/// It extracts the amount from the baseRequest and determines the swap direction based on the token addresses.
function swapWrapToWithBaseRequest(
uint256 orderId,
address receiver,
BaseRequest calldata baseRequest
)
external
payable
isExpired(baseRequest.deadLine)
{
bool reversed;
address fromTokenAddr = _bytes32ToAddress(baseRequest.fromToken);
if (fromTokenAddr == _ETH && baseRequest.toToken == _WETH) {
reversed = false;
} else if (fromTokenAddr == _WETH && baseRequest.toToken == _ETH) {
reversed = true;
} else {
revert("SwapWrap: invalid token pair");
}
_swapWrap(orderId, receiver, reversed, baseRequest.fromTokenAmount);
}
function dagSwapByOrderId(
uint256 orderId,
BaseRequest calldata baseRequest,
RouterPath[] calldata paths
) external payable returns (uint256 returnAmount) {
return dagSwapTo(orderId, msg.sender, baseRequest, paths);
}
/// @notice Executes a DAG swap to a specified receiver using structured base request parameters.
/// @param orderId Unique identifier for the swap order, facilitating tracking and reference.
/// @param receiver The address that will receive the swapped tokens.
/// @param baseRequest Struct containing essential swap parameters including source token, destination token, amount, minimum return, and deadline.
/// @param paths An array of RouterPath structs defining the DAG swap route.
/// @return returnAmount The total amount of destination tokens received from the swap.
/// @dev This function validates token compatibility with the provided pool route and ensures proper swap execution.
function dagSwapTo(
uint256 orderId,
address receiver,
BaseRequest calldata baseRequest,
RouterPath[] calldata paths
)
public
payable
isExpired(baseRequest.deadLine)
returns (uint256 returnAmount)
{
require(paths.length > 0, "paths must be > 0");
emit SwapOrderId(orderId);
receiver = receiver == address(0) ? msg.sender : receiver;
(CommissionInfo memory commissionInfo, TrimInfo memory trimInfo) = _getCommissionAndTrimInfo();
uint256 mode = paths[0].fromToken & _TRANSFER_MODE_MASK;
_validateCommissionInfo(commissionInfo, _bytes32ToAddress(baseRequest.fromToken), baseRequest.toToken, mode);
returnAmount = _getBalanceOf(baseRequest.toToken, receiver);
(
address middleReceiver,
uint256 balanceBefore
) = _doCommissionFromToken(
commissionInfo,
msg.sender,
receiver,
baseRequest.fromTokenAmount,
trimInfo.hasTrim,
baseRequest.toToken
);
_dagSwapInternal(
baseRequest,
paths,
msg.sender,
msg.sender,
middleReceiver
);
_doCommissionAndTrimToToken(
commissionInfo,
receiver,
balanceBefore,
baseRequest.toToken,
trimInfo
);
// check minReturnAmount
returnAmount =
_getBalanceOf(baseRequest.toToken, receiver) -
returnAmount;
require(
returnAmount >= baseRequest.minReturnAmount,
"Min return not reached"
);
emit OrderRecord(
_bytes32ToAddress(baseRequest.fromToken),
baseRequest.toToken,
tx.origin,
baseRequest.fromTokenAmount,
returnAmount
);
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
import "./libraries/CommonLib.sol";
import "./libraries/UniversalERC20.sol";
import "./interfaces/IERC20.sol";
abstract contract DagRouter is CommonLib {
using UniversalERC20 for IERC20;
/// @notice Core DAG algorithm data structure
/// @dev Maintains the state of the DAG during execution
struct SwapState {
/// @notice the number of nodes need to be processed
uint256 nodeNum;
/// @notice the refundTo address of the DAG
address refundTo;
}
/// @notice The fromTokenAmount will not must be greater than 0, cause for some protocols the fromTokenAmount needs to be 0 to skip token transfer like fourmeme.
function _dagSwapInternal(
BaseRequest calldata baseRequest,
RouterPath[] calldata paths,
address payer,
address refundTo,
address receiver
) internal {
// 1. check and process ETH
BaseRequest memory _baseRequest = baseRequest;
address fromToken = _bytes32ToAddress(_baseRequest.fromToken);
address firstNodeToken = _bytes32ToAddress(paths[0].fromToken);
// In order to deal with ETH/WETH transfer rules in a unified manner,
// we do not need to judge according to fromToken.
if (IERC20(fromToken).isETH()) {
require(firstNodeToken == _WETH, "firstToken mismatch");
IWETH(_WETH).deposit{
value: _baseRequest.fromTokenAmount
}();
payer = address(this);
} else {
require(firstNodeToken == fromToken, "firstToken mismatch");
require(msg.value == 0, "value must be 0");
}
// 2. execute dag swap
_exeDagSwap(payer, receiver, refundTo, _baseRequest.fromTokenAmount, IERC20(_baseRequest.toToken).isETH(), paths);
// 3. transfer tokens to receiver
_transferTokenToUser(_baseRequest.toToken, receiver);
}
/// @notice The core logic to execute the DAG swap. For the first node, the payer should use passed value.
/// For the non-first node, the payer should always be address(this) cause the to address of the middle swap is address(this).
function _exeDagSwap(
address payer,
address receiver,
address refundTo,
uint256 firstNodeBalance,
bool isToNative,
RouterPath[] calldata paths
) private {
uint256 nodeNum = paths.length;
SwapState memory swapState = _initSwapState(nodeNum, refundTo);
// execute nodes
for (uint256 i = 0; i < nodeNum;) {
if (i != 0) { // reset payer for non-first node
payer = address(this);
}
_exeNode(payer, receiver, firstNodeBalance, i, isToNative, paths[i], swapState);
unchecked {
++i;
}
}
}
/// @notice Initialize the swap state for the DAG execution
function _initSwapState(
uint256 _nodeNum,
address _refundTo
) private pure returns (SwapState memory state) {
state.nodeNum = _nodeNum;
state.refundTo = _refundTo;
}
/// @notice The core logic to execute the each node
function _exeNode(
address payer,
address receiver,
uint256 nodeBalance,
uint256 nodeIndex,
bool isToNative,
RouterPath calldata path,
SwapState memory swapState
) private {
uint256 totalWeight;
uint256 accAmount;
address fromToken = _bytes32ToAddress(path.fromToken);
require(path.mixAdapters.length > 0, "edge length must be > 0");
require(
path.mixAdapters.length == path.rawData.length &&
path.mixAdapters.length == path.extraData.length &&
path.mixAdapters.length == path.assetTo.length,
"path length mismatch"
);
// to get the nodeBalance for non-first node, the balance of the first node is the original passed value
if (nodeIndex != 0) {
nodeBalance = IERC20(fromToken).balanceOf(address(this));
require(nodeBalance > 0, "node balance must be > 0");
}
// execute edges
for (uint256 i = 0; i < path.mixAdapters.length;) {
uint256 inputIndex;
uint256 outputIndex;
uint256 weight;
// 1. get inputIndex, outputIndex, weight and verify
{
bytes32 rawData = bytes32(path.rawData[i]);
assembly {
weight := shr(160, and(rawData, _WEIGHT_MASK))
inputIndex := shr(184, and(rawData, _INPUT_INDEX_MASK))
outputIndex := shr(176, and(rawData, _OUTPUT_INDEX_MASK))
}
require(inputIndex == nodeIndex, "node inputIndex inconsistent");
require(inputIndex < outputIndex && outputIndex <= swapState.nodeNum, "node index out of range");
totalWeight += weight;
if (i == path.mixAdapters.length - 1) {
require(
totalWeight == 10_000,
"totalWeight must be 10000"
);
}
}
// 2. transfer fromToken from payer to assetTo of edge
{
uint256 _fromTokenAmount;
if (i == path.mixAdapters.length - 1) {
_fromTokenAmount = nodeBalance - accAmount;
} else {
_fromTokenAmount = (nodeBalance * weight) / 10_000;
accAmount += _fromTokenAmount;
}
if (_fromTokenAmount > 0) {
_transferInternal(
payer,
path.assetTo[i],
path.fromToken,
_fromTokenAmount
);
}
}
// 3. execute single swap
{
address to = address(this);
if (outputIndex == swapState.nodeNum && !isToNative) {
to = receiver;
}
_exeEdge(
path.rawData[i],
path.mixAdapters[i],
path.extraData[i],
to,
swapState.refundTo
);
}
unchecked {
++i;
}
}
}
function _exeEdge(
uint256 rawData,
address mixAdapter,
bytes memory extraData,
address to,
address refundTo
) private {
bool reverse;
address poolAddress;
assembly {
poolAddress := and(rawData, _ADDRESS_MASK)
reverse := and(rawData, _REVERSE_MASK)
}
_exeAdapter(
reverse,
mixAdapter,
to,
poolAddress,
extraData,
refundTo
);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title Abstract base contract with virtual functions
abstract contract AbstractCommissionLib {
struct CommissionInfo {
bool isFromTokenCommission; //0x00
bool isToTokenCommission; //0x20
uint256 commissionRate; //0x40
address refererAddress; //0x60
address token; //0x80
uint256 commissionRate2; //0xa0
address refererAddress2; //0xc0
bool isToBCommission; //0xe0
}
struct TrimInfo {
bool hasTrim; // 0x00
uint256 trimRate; // 0x20
address trimAddress; // 0x40
uint256 expectAmountOut; // 0x60
uint256 chargeRate; // 0x80
address chargeAddress; // 0xa0
}
function _getCommissionAndTrimInfo()
internal
virtual
returns (CommissionInfo memory commissionInfo, TrimInfo memory trimInfo);
// function _getBalanceOf(address token, address user)
// internal
// virtual
// returns (uint256);
function _doCommissionFromToken(
CommissionInfo memory commissionInfo,
address payer,
address receiver,
uint256 inputAmount,
bool hasTrim,
address toToken
) internal virtual returns (address, uint256);
function _doCommissionAndTrimToToken(
CommissionInfo memory commissionInfo,
address receiver,
uint256 balanceBefore,
address toToken,
TrimInfo memory trimInfo
) internal virtual returns (uint256);
function _validateCommissionInfo(
CommissionInfo memory commissionInfo,
address fromToken,
address toToken,
uint256 mode
) internal pure virtual;
}/// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma abicoder v2;
interface IAdapter {
function sellBase(
address to,
address pool,
bytes memory data
) external;
function sellQuote(
address to,
address pool,
bytes memory data
) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IApproveProxy {
function isAllowedProxy(address _proxy) external view returns (bool);
function claimTokens(
address token,
address who,
address dest,
uint256 amount
) external;
function tokenApprove() external view returns (address);
function addProxy(address) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title Interface for DAI-style permits
interface IDaiLikePermit {
function permit(
address holder,
address spender,
uint256 nonce,
uint256 expiry,
bool allowed,
uint8 v,
bytes32 r,
bytes32 s
) external;
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.17;
interface IDexRouter {
struct BaseRequest {
uint256 fromToken;
address toToken;
uint256 fromTokenAmount;
uint256 minReturnAmount;
uint256 deadLine;
}
struct RouterPath {
address[] mixAdapters;
address[] assetTo;
uint256[] rawData;
bytes[] extraData;
uint256 fromToken;
}
event OrderRecord(
address fromToken,
address toToken,
address sender,
uint256 fromAmount,
uint256 returnAmount
);
event SwapOrderId(uint256 id);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IERC20 {
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
event Transfer(address indexed from, address indexed to, uint256 value);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint256);
function balanceOf(address owner) external view returns (uint256);
function allowance(address owner, address spender)
external
view
returns (uint256);
function approve(address spender, uint256 value) external returns (bool);
function transfer(address to, uint256 value) external returns (bool);
function transferFrom(
address from,
address to,
uint256 value
) external returns (bool);
}// SPDX-License-Identifier: MIT
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
pragma solidity ^0.8.0;
pragma abicoder v2;
interface IUni {
function swapExactTokensForTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swap(
uint256 amount0Out,
uint256 amount1Out,
address to,
bytes calldata data
) external;
function getReserves()
external
view
returns (
uint112 reserve0,
uint112 reserve1,
uint32 blockTimestampLast
);
function token0() external view returns (address);
function token1() external view returns (address);
function sync() external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title Callback for IUniswapV3PoolActions#swap
/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface
interface IUniswapV3SwapCallback {
/// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap.
/// @dev In the implementation you must pay the pool tokens owed for the swap.
/// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.
/// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.
/// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by
/// the end of the swap. If positive, the callback must send that amount of token0 to the pool.
/// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by
/// the end of the swap. If positive, the callback must send that amount of token1 to the pool.
/// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call
function uniswapV3SwapCallback(
int256 amount0Delta,
int256 amount1Delta,
bytes calldata data
) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma abicoder v2;
interface IUniV3 {
function swap(
address recipient,
bool zeroForOne,
int256 amountSpecified,
uint160 sqrtPriceLimitX96,
bytes calldata data
) external returns (int256 amount0, int256 amount1);
function slot0()
external
view
returns (
uint160 sqrtPriceX96,
int24 tick,
uint16 observationIndex,
uint16 observationCardinality,
uint16 observationCardinalityNext,
uint8 feeProtocol,
bool unlocked
);
function token0() external view returns (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);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma abicoder v2;
interface IWETH {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount)
external
returns (bool);
function allowance(address owner, address spender)
external
view
returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address src,
address dst,
uint256 wad
) external returns (bool);
function deposit() external payable;
function withdraw(uint256 wad) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma abicoder v2;
interface IWNativeRelayer {
function withdraw(uint256 _amount) external;
}/// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @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
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly {
codehash := extcodehash(account)
}
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Converts an `address` into `address payable`. Note that this is
* simply a type cast: the actual underlying value is not changed.
*
* _Available since v2.4.0._
*/
function toPayable(address account)
internal
pure
returns (address payable)
{
return payable(account);
}
/**
* @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://diligence.consensys.net/posts/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.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*
* _Available since v2.4.0._
*/
function sendValue(address recipient, uint256 amount) internal {
require(
address(this).balance >= amount,
"Address: insufficient balance"
);
// solhint-disable-next-line avoid-call-value
(bool success, ) = recipient.call{value: amount}("");
require(
success,
"Address: unable to send value, recipient may have reverted"
);
}
}/// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./CommonUtils.sol";
import "../interfaces/AbstractCommissionLib.sol";
/// @title Base contract with common permit handling logics
abstract contract CommissionLib is AbstractCommissionLib, CommonUtils {
uint256 internal constant _COMMISSION_RATE_MASK =
0x000000000000ffffffffffff0000000000000000000000000000000000000000;
uint256 internal constant _COMMISSION_FLAG_MASK =
0xffffffffffff0000000000000000000000000000000000000000000000000000;
uint256 internal constant FROM_TOKEN_COMMISSION =
0x3ca20afc2aaa0000000000000000000000000000000000000000000000000000;
uint256 internal constant TO_TOKEN_COMMISSION =
0x3ca20afc2bbb0000000000000000000000000000000000000000000000000000;
uint256 internal constant FROM_TOKEN_COMMISSION_DUAL =
0x22220afc2aaa0000000000000000000000000000000000000000000000000000;
uint256 internal constant TO_TOKEN_COMMISSION_DUAL =
0x22220afc2bbb0000000000000000000000000000000000000000000000000000;
uint256 internal constant _TO_B_COMMISSION_MASK =
0x8000000000000000000000000000000000000000000000000000000000000000;
uint256 internal constant _TRIM_FLAG_MASK =
0xffffffffffff0000000000000000000000000000000000000000000000000000;
uint256 internal constant _TRIM_EXPECT_AMOUNT_OUT_OR_ADDRESS_MASK =
0x000000000000000000000000ffffffffffffffffffffffffffffffffffffffff;
uint256 internal constant _TRIM_RATE_MASK =
0x000000000000ffffffffffff0000000000000000000000000000000000000000;
uint256 internal constant TRIM_FLAG =
0x7777777711110000000000000000000000000000000000000000000000000000;
uint256 internal constant TRIM_DUAL_FLAG =
0x7777777722220000000000000000000000000000000000000000000000000000;
event CommissionAndTrimInfo(
uint256 commissionRate1,
uint256 commissionRate2,
bool isToBCommission,
uint256 trimRate,
uint256 chargeRate
);
// @notice CommissionFromTokenRecord is emitted in assembly, commentted out for contract size saving
// event CommissionFromTokenRecord(
// address fromTokenAddress,
// uint256 commissionAmount,
// address referrerAddress
// );
// @notice CommissionToTokenRecord is emitted in assembly, commentted out for contract size saving
// event CommissionToTokenRecord(
// address toTokenAddress,
// uint256 commissionAmount,
// address referrerAddress
// );
// @notice PositiveSlippageTrimRecord is emitted in assembly, commentted out for contract size saving
// event PositiveSlippageTrimRecord(
// address toTokenAddress,
// uint256 trimAmount,
// address trimAddress
// );
// @notice PositiveSlippageChargeRecord is emitted in assembly, commentted out for contract size saving
// event PositiveSlippageChargeRecord(
// address toTokenAddress,
// uint256 chargeAmount,
// address chargeAddress
// );
// set default value can change when need.
uint256 internal constant commissionRateLimit = 30000000;
uint256 internal constant DENOMINATOR = 10 ** 9;
uint256 internal constant WAD = 1 ether;
uint256 internal constant TRIM_RATE_LIMIT = 100;
uint256 internal constant TRIM_DENOMINATOR = 1000;
function _getCommissionAndTrimInfo()
internal
override
returns (CommissionInfo memory commissionInfo, TrimInfo memory trimInfo)
{
assembly ("memory-safe") {
// let freePtr := mload(0x40)
// mstore(0x40, add(freePtr, 0x100))
let commissionData := calldataload(sub(calldatasize(), 0x20))
let flag := and(commissionData, _COMMISSION_FLAG_MASK)
let isDualreferrers := or(
eq(flag, FROM_TOKEN_COMMISSION_DUAL),
eq(flag, TO_TOKEN_COMMISSION_DUAL)
)
mstore(
commissionInfo,
or(
eq(flag, FROM_TOKEN_COMMISSION),
eq(flag, FROM_TOKEN_COMMISSION_DUAL)
)
) // isFromTokenCommission
mstore(
add(0x20, commissionInfo),
or(
eq(flag, TO_TOKEN_COMMISSION),
eq(flag, TO_TOKEN_COMMISSION_DUAL)
)
) // isToTokenCommission
mstore(
add(0x40, commissionInfo),
shr(160, and(commissionData, _COMMISSION_RATE_MASK))
) //commissionRate1
mstore(
add(0x60, commissionInfo),
and(commissionData, _ADDRESS_MASK)
) //referrerAddress1
commissionData := calldataload(sub(calldatasize(), 0x40))
mstore(
add(0xe0, commissionInfo),
gt(and(commissionData, _TO_B_COMMISSION_MASK), 0) //isToBCommission
)
mstore(
add(0x80, commissionInfo),
and(commissionData, _ADDRESS_MASK) //token
)
switch eq(isDualreferrers, 1)
case 1 {
let commissionData2 := calldataload(sub(calldatasize(), 0x60))
mstore(
add(0xa0, commissionInfo),
shr(160, and(commissionData2, _COMMISSION_RATE_MASK))
) //commissionRate2
mstore(
add(0xc0, commissionInfo),
and(commissionData2, _ADDRESS_MASK)
) //referrerAddress2
}
default {
mstore(add(0xa0, commissionInfo), 0) //commissionRate2
mstore(add(0xc0, commissionInfo), 0) //referrerAddress2
}
// calculate offset based on commission flag
let offset := 0x00
if eq(isDualreferrers, 1) {
offset := 0x60 // 96 bytes for dual commission
}
if or(
eq(flag, FROM_TOKEN_COMMISSION),
eq(flag, TO_TOKEN_COMMISSION)
) {
offset := 0x40 // 64 bytes for single commission
}
// get first bytes32 of trim data
let trimData := calldataload(sub(calldatasize(), add(offset, 32)))
flag := and(trimData, _TRIM_FLAG_MASK)
mstore(
trimInfo,
or(
eq(flag, TRIM_FLAG),
eq(flag, TRIM_DUAL_FLAG)
)
) // hasTrim
mstore(
add(0x20, trimInfo),
shr(160, and(trimData, _TRIM_RATE_MASK))
) // trimRate
mstore(
add(0x40, trimInfo),
and(trimData, _TRIM_EXPECT_AMOUNT_OUT_OR_ADDRESS_MASK)
) // trimAddress
// get second bytes32 of trim data
trimData := calldataload(sub(calldatasize(), add(offset, 64)))
mstore(
add(0x60, trimInfo),
and(trimData, _TRIM_EXPECT_AMOUNT_OUT_OR_ADDRESS_MASK)
) // expectAmountOut
switch eq(flag, TRIM_DUAL_FLAG)
case 1 {
// get third bytes32 of trim data
trimData := calldataload(sub(calldatasize(), add(offset, 96)))
mstore(
add(0x80, trimInfo),
shr(160, and(trimData, _TRIM_RATE_MASK))
) // chargeRate
mstore(
add(0xa0, trimInfo),
and(trimData, _TRIM_EXPECT_AMOUNT_OUT_OR_ADDRESS_MASK)
) // chargeAddress
}
default {
mstore(add(0x80, trimInfo), 0) // chargeRate
mstore(add(0xa0, trimInfo), 0) // chargeAddress
}
}
if (commissionInfo.isFromTokenCommission || commissionInfo.isToTokenCommission || trimInfo.hasTrim) {
emit CommissionAndTrimInfo(commissionInfo.commissionRate, commissionInfo.commissionRate2, commissionInfo.isToBCommission, trimInfo.trimRate, trimInfo.chargeRate);
}
}
function _getBalanceOf(
address token,
address user
) internal returns (uint256 amount) {
assembly {
function _revertWithReason(m, len) {
mstore(
0,
0x08c379a000000000000000000000000000000000000000000000000000000000
)
mstore(
0x20,
0x0000002000000000000000000000000000000000000000000000000000000000
)
mstore(0x40, m)
revert(0, len)
}
switch eq(token, _ETH)
case 1 {
amount := balance(user)
}
default {
let freePtr := mload(0x40)
mstore(0x40, add(freePtr, 0x24))
mstore(
freePtr,
0x70a0823100000000000000000000000000000000000000000000000000000000
) //balanceOf
mstore(add(freePtr, 0x04), user)
let success := staticcall(gas(), token, freePtr, 0x24, 0, 0x20)
if eq(success, 0) {
_revertWithReason(
0x000000146765742062616c616e63654f66206661696c65640000000000000000,
0x58
)
}
amount := mload(0x00)
}
}
}
function _doCommissionFromToken(
CommissionInfo memory commissionInfo,
address payer,
address receiver,
uint256 inputAmount,
bool hasTrim,
address toToken
) internal override returns (address middleReceiver, uint256 balanceBefore) {
if (commissionInfo.isToTokenCommission || hasTrim) {
middleReceiver = address(this);
balanceBefore = _getBalanceOf(toToken, address(this));
} else {
middleReceiver = receiver;
}
if (commissionInfo.isFromTokenCommission) {
_doCommissionFromTokenInternal(commissionInfo, payer, inputAmount);
}
}
function _doCommissionFromTokenInternal(
CommissionInfo memory commissionInfo,
address payer,
uint256 inputAmount
) private {
assembly ("memory-safe") {
// https://github.com/Vectorized/solady/blob/701406e8126cfed931645727b274df303fbcd94d/src/utils/FixedPointMathLib.sol#L595
function _mulDiv(x, y, d) -> z {
z := mul(x, y)
// Equivalent to `require(d != 0 && (y == 0 || x <= type(uint256).max / y))`.
if iszero(mul(or(iszero(x), eq(div(z, x), y)), d)) {
mstore(0x00, 0xad251c27) // `MulDivFailed()`.
revert(0x1c, 0x04)
}
z := div(z, d)
}
function _safeSub(x, y) -> z {
if lt(x, y) {
mstore(0x00, 0x46e72d03) // `SafeSubFailed()`.
revert(0x1c, 0x04)
}
z := sub(x, y)
}
// a << 8 | b << 4 | c => 0xabc
function _getStatus(token, isToB, hasNextRefer) -> d {
let a := mul(eq(token, _ETH), 256)
let b := mul(isToB, 16)
let c := hasNextRefer
d := add(a, add(b, c))
}
function _revertWithReason(m, len) {
mstore(
0,
0x08c379a000000000000000000000000000000000000000000000000000000000
)
mstore(
0x20,
0x0000002000000000000000000000000000000000000000000000000000000000
)
mstore(0x40, m)
revert(0, len)
}
function _sendETH(to, amount) {
let success := call(gas(), to, amount, 0, 0, 0, 0)
if eq(success, 0) {
_revertWithReason(
0x0000001c20636f6d6d697373696f6e2077697468206574686572206572726f72, //commission with ether error
0x60
)
}
}
function _claimToken(token, _payer, to, amount) {
let freePtr := mload(0x40)
mstore(0x40, add(freePtr, 0x84))
mstore(
freePtr,
0x0a5ea46600000000000000000000000000000000000000000000000000000000
) // claimTokens
mstore(add(freePtr, 0x04), token)
mstore(add(freePtr, 0x24), _payer)
mstore(add(freePtr, 0x44), to)
mstore(add(freePtr, 0x64), amount)
let success := call(
gas(),
_APPROVE_PROXY,
0,
freePtr,
0x84,
0,
0
)
if eq(success, 0) {
_revertWithReason(
0x00000013636c61696d20746f6b656e73206661696c6564000000000000000000,
0x57
)
}
}
// get balance, then scale amount1, amount2 according to balance
function _sendTokenWithinBalance(token, to1, rate1, to2, rate2)
-> amount1Scaled, amount2Scaled
{
let freePtr := mload(0x40)
mstore(0x40, add(freePtr, 0x48))
mstore(
freePtr,
0xa9059cbba9059cbb70a082310000000000000000000000000000000000000000
) // transfer transfer balanceOf
// balanceOf
mstore(add(freePtr, 0x0c), address())
let success := staticcall(
gas(),
token,
add(freePtr, 0x08),
0x24,
0,
0x20
)
if eq(success, 0) {
_revertWithReason(
0x000000146765742062616c616e63654f66206661696c65640000000000000000,
0x58
)
}
let balanceAfter := mload(0x00)
let rateTotal := add(rate1, rate2) // amount = 0.0000001
amount1Scaled := _mulDiv(
_mulDiv(rate1, WAD, rateTotal),
balanceAfter,
WAD
) // WARNING: Precision issues may also exist!!
if gt(amount1Scaled, balanceAfter) {
_revertWithReason(
0x00000015696e76616c696420616d6f756e74315363616c656400000000000000,
0x59
) //invalid amount1Scaled
}
mstore(add(freePtr, 0x08), to1)
mstore(add(freePtr, 0x28), amount1Scaled)
success := call(
gas(),
token,
0,
add(freePtr, 0x4),
0x44,
0,
0x20
)
// https://github.com/transmissions11/solmate/blob/e5e0ed64c75e74974151780884e59071d026d84e/src/utils/SafeTransferLib.sol#L54
if and(
iszero(and(eq(mload(0), 1), gt(returndatasize(), 31))),
success
) {
success := iszero(
or(iszero(extcodesize(token)), returndatasize())
)
}
if eq(success, 0) {
_revertWithReason(
0x0000001b7472616e7366657220746f6b656e2072656665726572206661696c00,
0x5f
) //transfer token referrer fail
}
if gt(to2, 0) {
amount2Scaled := _safeSub(balanceAfter, amount1Scaled)
mstore(add(freePtr, 0x04), to2)
mstore(add(freePtr, 0x24), amount2Scaled)
success := call(gas(), token, 0, freePtr, 0x44, 0, 0x20)
// https://github.com/transmissions11/solmate/blob/e5e0ed64c75e74974151780884e59071d026d84e/src/utils/SafeTransferLib.sol#L54
if and(
iszero(and(eq(mload(0), 1), gt(returndatasize(), 31))),
success
) {
success := iszero(
or(iszero(extcodesize(token)), returndatasize())
)
}
if eq(success, 0) {
_revertWithReason(
0x0000001b7472616e7366657220746f6b656e2072656665726572206661696c00,
0x5f
) //transfer token referrer fail
}
}
}
function _emitCommissionFromToken(token, amount, referrer) {
let freePtr := mload(0x40)
mstore(0x40, add(freePtr, 0x60))
mstore(freePtr, token)
mstore(add(freePtr, 0x20), amount)
mstore(add(freePtr, 0x40), referrer)
log1(
freePtr,
0x60,
0x0d3b1268ca3dbb6d3d8a0ea35f44f8f9d58cf578d732680b71b6904fb2733e0d
) //emit CommissionFromTokenRecord(address,uint256,address)
}
let token, status
{
token := mload(add(commissionInfo, 0x80))
let isToB := mload(add(commissionInfo, 0xe0))
let hasNextRefer := gt(mload(add(commissionInfo, 0xa0)), 0)
status := _getStatus(token, isToB, hasNextRefer)
}
let referrer1, referrer2, amount1, amount2, rate1, rate2
rate1 := mload(add(commissionInfo, 0x40))
rate2 := mload(add(commissionInfo, 0xa0))
{
// let totalRate := add(rate, rate2)
if gt(add(rate1, rate2), commissionRateLimit) {
_revertWithReason(
0x0000001b6572726f7220636f6d6d697373696f6e2072617465206c696d697400,
0x5f
) //"error commission rate limit"
}
referrer1 := mload(add(commissionInfo, 0x60))
amount1 := div(
mul(inputAmount, rate1),
sub(DENOMINATOR, add(rate1, rate2))
)
referrer2 := mload(add(commissionInfo, 0xc0))
amount2 := div(
mul(inputAmount, rate2),
sub(DENOMINATOR, add(rate1, rate2))
)
}
switch status
case 0x100 {
_sendETH(referrer1, amount1)
_emitCommissionFromToken(_ETH, amount1, referrer1)
}
case 0x101 {
_sendETH(referrer1, amount1)
_emitCommissionFromToken(_ETH, amount1, referrer1)
_sendETH(referrer2, amount2)
_emitCommissionFromToken(_ETH, amount2, referrer2)
}
case 0x110 {
_sendETH(referrer1, amount1)
_emitCommissionFromToken(_ETH, amount1, referrer1)
}
case 0x111 {
_sendETH(referrer1, amount1)
_emitCommissionFromToken(_ETH, amount1, referrer1)
_sendETH(referrer2, amount2)
_emitCommissionFromToken(_ETH, amount2, referrer2)
}
case 0x000 {
_claimToken(token, payer, referrer1, amount1)
_emitCommissionFromToken(token, amount1, referrer1)
}
case 0x001 {
_claimToken(token, payer, referrer1, amount1)
_emitCommissionFromToken(token, amount1, referrer1)
_claimToken(token, payer, referrer2, amount2)
_emitCommissionFromToken(token, amount2, referrer2)
}
case 0x010 {
_claimToken(token, payer, address(), amount1)
// considering the tax token, we first transfer it into dexrouter, then check balance, after that
// scaled amount accordingly
let amount1Scaled, amount2Scaled := _sendTokenWithinBalance(
token,
referrer1,
rate1,
0,
0
)
_emitCommissionFromToken(token, amount1Scaled, referrer1)
}
case 0x011 {
_claimToken(token, payer, address(), add(amount1, amount2))
// considering the tax token, we first transfer it into dexrouter, then check balance, after that
// scaled amount accordingly
let amount1Scaled, amount2Scaled := _sendTokenWithinBalance(
token,
referrer1,
rate1,
referrer2,
rate2
)
_emitCommissionFromToken(token, amount1Scaled, referrer1)
_emitCommissionFromToken(token, amount2Scaled, referrer2)
}
default {
_revertWithReason(
0x0000000e696e76616c6964207374617475730000000000000000000000000000,
0x52
) // invalid status
}
}
}
function _doCommissionAndTrimToToken(
CommissionInfo memory commissionInfo,
address receiver,
uint256 balanceBefore,
address toToken,
TrimInfo memory trimInfo
) internal override returns (uint256 totalAmount) {
if (!commissionInfo.isToTokenCommission && !trimInfo.hasTrim) {
return 0;
}
uint256 balanceAfter = _getBalanceOf(toToken, address(this));
require(balanceAfter >= balanceBefore, "invalid balance after");
uint256 inputAmount = balanceAfter - balanceBefore;
// process commission
if (commissionInfo.isToTokenCommission) {
require(commissionInfo.commissionRate + commissionInfo.commissionRate2 <= commissionRateLimit, "error commission rate limit");
uint256 commissionAmount = inputAmount * (commissionInfo.commissionRate + commissionInfo.commissionRate2) / DENOMINATOR;
_doCommissionOrTrimToTokenInternal(
true,
toToken,
commissionAmount,
commissionInfo.commissionRate,
commissionInfo.refererAddress,
commissionInfo.commissionRate2,
commissionInfo.refererAddress2
);
totalAmount = commissionAmount;
inputAmount -= commissionAmount;
}
// process trim
if (trimInfo.hasTrim && inputAmount > trimInfo.expectAmountOut) {
require(trimInfo.trimRate <= TRIM_RATE_LIMIT, "error trim rate limit");
require(trimInfo.chargeRate <= TRIM_DENOMINATOR, "error charge rate");
uint256 trimAmount = inputAmount - trimInfo.expectAmountOut;
uint256 allowedMaxTrimAmount = inputAmount * trimInfo.trimRate / TRIM_DENOMINATOR;
if (trimAmount > allowedMaxTrimAmount) {
trimAmount = allowedMaxTrimAmount;
}
_doCommissionOrTrimToTokenInternal(
false,
toToken,
trimAmount,
(TRIM_DENOMINATOR - trimInfo.chargeRate),
trimInfo.trimAddress,
trimInfo.chargeRate,
trimInfo.chargeAddress
);
totalAmount += trimAmount;
inputAmount -= trimAmount;
}
// transfer toToken to receiver
_sendETHOrToken(toToken, receiver, inputAmount);
}
// Process commission or trim to token
function _doCommissionOrTrimToTokenInternal(
bool isCommission,
address toToken,
uint256 totalAmount,
uint256 rate1,
address address1,
uint256 rate2,
address address2
) private {
assembly ("memory-safe") {
// a << 4 | b => 0xab
function _getStatus(flag, token) -> c {
let a := mul(gt(flag, 0), 16)
let b := eq(token, _ETH)
c := add(a, b)
}
function _revertWithReason(m, len) {
mstore(
0,
0x08c379a000000000000000000000000000000000000000000000000000000000
)
mstore(
0x20,
0x0000002000000000000000000000000000000000000000000000000000000000
)
mstore(0x40, m)
revert(0, len)
}
function _sendETH(to, amount) {
let success := call(gas(), to, amount, 0, 0, 0, 0)
if eq(success, 0) {
_revertWithReason(
0x0000001173656e64206574686572206661696c65640000000000000000000000,
0x55
) // "send ether failed"
}
}
function _sendToken(token, to, amount) {
let freePtr := mload(0x40)
mstore(0x40, add(freePtr, 0x44))
mstore(
freePtr,
0xa9059cbb00000000000000000000000000000000000000000000000000000000
) // transfer
mstore(add(freePtr, 0x04), to)
mstore(add(freePtr, 0x24), amount)
let success := call(
gas(),
token,
0,
freePtr,
0x44,
0,
0x20
)
if and(
iszero(and(eq(mload(0), 1), gt(returndatasize(), 31))),
success
) {
success := iszero(
or(iszero(extcodesize(token)), returndatasize())
)
}
if eq(success, 0) {
_revertWithReason(
0x000000157472616e7366657220746f6b656e206661696c656400000000000000,
0x59
) // "transfer token failed"
}
}
function _emitCommissionToToken(token, amount, referrer) {
let freePtr := mload(0x40)
mstore(0x40, add(freePtr, 0x60))
mstore(freePtr, token)
mstore(add(freePtr, 0x20), amount)
mstore(add(freePtr, 0x40), referrer)
log1(
freePtr,
0x60,
0xf171268de859ec269c52bbfac94dcb7715e784de194342abb284bf34fd30b32d
) //emit CommissionToTokenRecord(address,uint256,address)
}
function _emitPositiveSlippageTrimRecord(token, trimAmount, trimAddress) {
let freePtr := mload(0x40)
mstore(0x40, add(freePtr, 0x60))
mstore(freePtr, token)
mstore(add(freePtr, 0x20), trimAmount)
mstore(add(freePtr, 0x40), trimAddress)
log1(
freePtr,
0x60,
0x7bec7d55a62a7a7b8068f1533e2a3bbf727b3e2e57f30c576fe159da60e09a65
) // emit PositiveSlippageTrimRecord(address,uint256,address)
}
function _emitPositiveSlippageChargeRecord(token, chargeAmount, chargeAddress) {
let freePtr := mload(0x40)
mstore(0x40, add(freePtr, 0x60))
mstore(freePtr, token)
mstore(add(freePtr, 0x20), chargeAmount)
mstore(add(freePtr, 0x40), chargeAddress)
log1(
freePtr,
0x60,
0xfd08115c8e43d2a49d95ee18d7f69b8bbac60bd368c73cf22d30664a22a0626d
) // emit PositiveSlippageChargeRecord(address,uint256,address)
}
let amount1 := div(mul(totalAmount, rate1), add(rate1, rate2))
let amount2 := sub(totalAmount, amount1)
address1 := shr(96, shl(96, address1))
address2 := shr(96, shl(96, address2))
let status := _getStatus(isCommission, toToken)
switch status
case 0x11 { // commission with ETH
if gt(rate1, 0) {
_sendETH(address1, amount1)
_emitCommissionToToken(_ETH, amount1, address1)
}
if gt(rate2, 0) {
_sendETH(address2, amount2)
_emitCommissionToToken(_ETH, amount2, address2)
}
}
case 0x10 { // commission with token
if gt(rate1, 0) {
_sendToken(toToken, address1, amount1)
_emitCommissionToToken(toToken, amount1, address1)
}
if gt(rate2, 0) {
_sendToken(toToken, address2, amount2)
_emitCommissionToToken(toToken, amount2, address2)
}
}
case 0x01 { // trim with ETH
if gt(rate1, 0) {
_sendETH(address1, amount1)
_emitPositiveSlippageTrimRecord(_ETH, amount1, address1)
}
if gt(rate2, 0) {
_sendETH(address2, amount2)
_emitPositiveSlippageChargeRecord(_ETH, amount2, address2)
}
}
case 0x00 { // trim with token
if gt(rate1, 0) {
_sendToken(toToken, address1, amount1)
_emitPositiveSlippageTrimRecord(toToken, amount1, address1)
}
if gt(rate2, 0) {
_sendToken(toToken, address2, amount2)
_emitPositiveSlippageChargeRecord(toToken, amount2, address2)
}
}
default {
_revertWithReason(
0x0000000e696e76616c6964207374617475730000000000000000000000000000,
0x52
) // invalid status
}
}
}
function _sendETHOrToken(
address token,
address to,
uint256 amount
) private {
assembly ("memory-safe") {
function _revertWithReason(m, len) {
mstore(
0,
0x08c379a000000000000000000000000000000000000000000000000000000000
)
mstore(
0x20,
0x0000002000000000000000000000000000000000000000000000000000000000
)
mstore(0x40, m)
revert(0, len)
}
function _sendETH(_to, _amount) {
let success := call(gas(), _to, _amount, 0, 0, 0, 0)
if eq(success, 0) {
_revertWithReason(
0x0000001173656e64206574686572206661696c65640000000000000000000000,
0x55
) // "send ether failed"
}
}
function _sendToken(_token, _to, _amount) {
let freePtr := mload(0x40)
mstore(0x40, add(freePtr, 0x44))
mstore(
freePtr,
0xa9059cbb00000000000000000000000000000000000000000000000000000000
) // transfer
mstore(add(freePtr, 0x04), _to)
mstore(add(freePtr, 0x24), _amount)
let success := call(
gas(),
_token,
0,
freePtr,
0x44,
0,
0x20
)
if and(
iszero(and(eq(mload(0), 1), gt(returndatasize(), 31))),
success
) {
success := iszero(
or(iszero(extcodesize(_token)), returndatasize())
)
}
if eq(success, 0) {
_revertWithReason(
0x000000157472616e7366657220746f6b656e206661696c656400000000000000,
0x59
) // "transfer token failed"
}
}
switch eq(token, _ETH)
case 1 {
_sendETH(shr(96, shl(96, to)), amount)
}
default {
_sendToken(token, shr(96, shl(96, to)), amount)
}
}
}
function _validateCommissionInfo(
CommissionInfo memory commissionInfo,
address fromToken,
address toToken,
uint256 mode
) internal pure override {
if ((
(mode & _MODE_NO_TRANSFER) != 0
|| (mode & _MODE_BY_INVEST) != 0
|| (mode & _MODE_PERMIT2) != 0
)
&& commissionInfo.isFromTokenCommission) {
revert("From token commission not supported");
}
if(fromToken == toToken) {
revert("Invalid tokens");
}
if (commissionInfo.isFromTokenCommission && commissionInfo.isToTokenCommission) {
revert("Invalid commission direction");
}
require(
(commissionInfo.isFromTokenCommission && commissionInfo.token == fromToken)
|| (commissionInfo.isToTokenCommission && commissionInfo.token == toToken)
|| (!commissionInfo.isFromTokenCommission && !commissionInfo.isToTokenCommission),
"Invalid commission info"
);
}
}/// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./CommonUtils.sol";
import "./SafeERC20.sol";
import "./UniversalERC20.sol";
import "../interfaces/IAdapter.sol";
import "../interfaces/IApproveProxy.sol";
import "../interfaces/IWNativeRelayer.sol";
import "../interfaces/IWETH.sol";
import "../interfaces/IERC20.sol";
/// @title Base contract with common permit handling logics
abstract contract CommonLib is CommonUtils {
using UniversalERC20 for IERC20;
function _exeAdapter(
bool reverse,
address adapter,
address to,
address poolAddress,
bytes memory moreinfo,
address refundTo
) internal {
if (reverse) {
(bool s, bytes memory res) = address(adapter).call(
abi.encodePacked(
abi.encodeWithSelector(
IAdapter.sellQuote.selector,
to,
poolAddress,
moreinfo
),
ORIGIN_PAYER + uint(uint160(refundTo))
)
);
if (!s) {
_revert(res);
}
} else {
(bool s, bytes memory res) = address(adapter).call(
abi.encodePacked(
abi.encodeWithSelector(
IAdapter.sellBase.selector,
to,
poolAddress,
moreinfo
),
ORIGIN_PAYER + uint(uint160(refundTo))
)
);
if (!s) {
_revert(res);
}
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with "FailedCall".
* https://github.com/OpenZeppelin/openzeppelin-contracts/blob/c64a1edb67b6e3f4a15cca8909c9482ad33a02b0/contracts/utils/Address.sol#L135-L149
*/
function _revert(bytes memory returndata) internal pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly ("memory-safe") {
revert(add(returndata, 0x20), mload(returndata))
}
} else {
revert("adaptor call failed");
}
}
/// @notice Transfers tokens internally within the contract.
/// @param payer The address of the payer.
/// @param to The address of the receiver.
/// @param fromTokenWithMode FromToken with mode encoded in high bits
/// @param amount The amount of tokens to be transferred.
/// @dev Handles the transfer of ERC20 tokens or native tokens within the contract.
function _transferInternal(
address payer,
address to,
uint256 fromTokenWithMode,
uint256 amount
) internal {
address token = address(uint160(fromTokenWithMode & _ADDRESS_MASK));
uint256 mode = fromTokenWithMode & _TRANSFER_MODE_MASK;
if (mode == _MODE_NO_TRANSFER) {
return;
} else if (mode == _MODE_BY_INVEST) {
SafeERC20.safeTransfer(IERC20(token), to, amount);
return;
} else if (mode == _MODE_PERMIT2) {
// Permit2 mode - reserved for future implementation
return;
} else {
if (payer == address(this)) {
SafeERC20.safeTransfer(IERC20(token), to, amount);
} else {
IApproveProxy(_APPROVE_PROXY).claimTokens(token, payer, to, amount);
}
}
}
/// @notice Transfers the specified token to the user.
/// @param token The address of the token to be transferred.
/// @param to The address of the receiver.
/// @dev Handles the withdrawal of tokens to the user, converting WETH to ETH if necessary.
function _transferTokenToUser(address token, address to) internal {
if ((IERC20(token).isETH())) {
uint256 wethBal = IERC20(address(uint160(_WETH))).balanceOf(
address(this)
);
if (wethBal > 0) {
IWETH(address(uint160(_WETH))).transfer(
_WNATIVE_RELAY,
wethBal
);
IWNativeRelayer(_WNATIVE_RELAY).withdraw(wethBal);
}
if (to != address(this)) {
uint256 ethBal = address(this).balance;
if (ethBal > 0) {
(bool success, ) = payable(to).call{value: ethBal}("");
require(success, "transfer native token failed");
}
}
} else {
if (to != address(this)) {
uint256 bal = IERC20(token).balanceOf(address(this));
if (bal > 0) {
SafeERC20.safeTransfer(IERC20(token), to, bal);
}
}
}
}
/// @notice Converts a uint256 value into an address.
/// @param param The uint256 value to be converted.
/// @return result The address obtained from the conversion.
/// @dev This function is used to extract an address from a uint256,
/// typically used when dealing with low-level data operations or when addresses are packed into larger data types.
function _bytes32ToAddress(
uint256 param
) internal pure returns (address result) {
assembly {
result := and(param, _ADDRESS_MASK)
}
}
}/// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../interfaces/IDexRouter.sol";
/// @title Base contract with common permit handling logics
abstract contract CommonUtils is IDexRouter {
address internal constant _ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
uint256 internal constant _ADDRESS_MASK =
0x000000000000000000000000ffffffffffffffffffffffffffffffffffffffff;
uint256 internal constant _REVERSE_MASK =
0x8000000000000000000000000000000000000000000000000000000000000000;
uint256 internal constant _ORDER_ID_MASK =
0xffffffffffffffffffffffff0000000000000000000000000000000000000000;
uint256 internal constant _WEIGHT_MASK =
0x00000000000000000000ffff0000000000000000000000000000000000000000;
uint256 internal constant _CALL_GAS_LIMIT = 5000;
uint256 internal constant ORIGIN_PAYER =
0x3ca20afc2ccc0000000000000000000000000000000000000000000000000000;
uint256 internal constant SWAP_AMOUNT =
0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff;
uint256 internal constant _WETH_MASK =
0x4000000000000000000000000000000000000000000000000000000000000000;
uint256 internal constant _ONE_FOR_ZERO_MASK = 1 << 255; // Mask for identifying if the swap is one-for-zero
uint256 internal constant _WETH_UNWRAP_MASK = 1 << 253; // Mask for identifying if WETH should be unwrapped to ETH
uint256 internal constant _MODE_LEGACY = 0;
uint256 internal constant _MODE_NO_TRANSFER = 1 << 251;
uint256 internal constant _MODE_BY_INVEST = 1 << 250;
uint256 internal constant _MODE_PERMIT2 = 1 << 249;
uint256 internal constant _TRANSFER_MODE_MASK = 0x0E00000000000000000000000000000000000000000000000000000000000000;
uint256 internal constant _INPUT_INDEX_MASK =
0x0000000000000000ff0000000000000000000000000000000000000000000000;
uint256 internal constant _OUTPUT_INDEX_MASK =
0x000000000000000000ff00000000000000000000000000000000000000000000;
/// @dev WETH address is network-specific and needs to be changed before deployment.
/// It can not be moved to immutable as immutables are not supported in assembly
// ETH: C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
// BSC: bb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c
// OEC: 8f8526dbfd6e38e3d8307702ca8469bae6c56c15
// LOCAL: 5FbDB2315678afecb367f032d93F642f64180aa3
// LOCAL2: 02121128f1Ed0AdA5Df3a87f42752fcE4Ad63e59
// POLYGON: 0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270
// AVAX: B31f66AA3C1e785363F0875A1B74E27b85FD66c7
// FTM: 21be370D5312f44cB42ce377BC9b8a0cEF1A4C83
// ARB: 82aF49447D8a07e3bd95BD0d56f35241523fBab1
// OP: 4200000000000000000000000000000000000006
// CRO: 5C7F8A570d578ED84E63fdFA7b1eE72dEae1AE23
// CFX: 14b2D3bC65e74DAE1030EAFd8ac30c533c976A9b
// POLYZK 4F9A0e7FD2Bf6067db6994CF12E4495Df938E6e9
address public constant _WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
// address public constant _WETH = 0x5FbDB2315678afecb367f032d93F642f64180aa3; // hardhat1
// address public constant _WETH = 0x707531c9999AaeF9232C8FEfBA31FBa4cB78d84a; // hardhat2
// ETH: 70cBb871E8f30Fc8Ce23609E9E0Ea87B6b222F58
// ETH-DEV:02D0131E5Cc86766e234EbF1eBe33444443b98a3
// BSC: d99cAE3FAC551f6b6Ba7B9f19bDD316951eeEE98
// OEC: E9BBD6eC0c9Ca71d3DcCD1282EE9de4F811E50aF
// LOCAL: e7f1725E7734CE288F8367e1Bb143E90bb3F0512
// LOCAL2: 95D7fF1684a8F2e202097F28Dc2e56F773A55D02
// POLYGON: 40aA958dd87FC8305b97f2BA922CDdCa374bcD7f
// AVAX: 70cBb871E8f30Fc8Ce23609E9E0Ea87B6b222F58
// FTM: E9BBD6eC0c9Ca71d3DcCD1282EE9de4F811E50aF
// ARB: E9BBD6eC0c9Ca71d3DcCD1282EE9de4F811E50aF
// OP: 100F3f74125C8c724C7C0eE81E4dd5626830dD9a
// CRO: E9BBD6eC0c9Ca71d3DcCD1282EE9de4F811E50aF
// CFX: 100F3f74125C8c724C7C0eE81E4dd5626830dD9a
// POLYZK 1b5d39419C268b76Db06DE49e38B010fbFB5e226
address public constant _APPROVE_PROXY = 0x70cBb871E8f30Fc8Ce23609E9E0Ea87B6b222F58;
// address public constant _APPROVE_PROXY = 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512; // hardhat1
// address public constant _APPROVE_PROXY = 0x2538a10b7fFb1B78c890c870FC152b10be121f04; // hardhat2
// ETH: 5703B683c7F928b721CA95Da988d73a3299d4757
// BSC: 0B5f474ad0e3f7ef629BD10dbf9e4a8Fd60d9A48
// OEC: d99cAE3FAC551f6b6Ba7B9f19bDD316951eeEE98
// LOCAL: D49a0e9A4CD5979aE36840f542D2d7f02C4817Be
// LOCAL2: 11457D5b1025D162F3d9B7dBeab6E1fBca20e043
// POLYGON: f332761c673b59B21fF6dfa8adA44d78c12dEF09
// AVAX: 3B86917369B83a6892f553609F3c2F439C184e31
// FTM: 40aA958dd87FC8305b97f2BA922CDdCa374bcD7f
// ARB: d99cAE3FAC551f6b6Ba7B9f19bDD316951eeEE98
// OP: 40aA958dd87FC8305b97f2BA922CDdCa374bcD7f
// CRO: 40aA958dd87FC8305b97f2BA922CDdCa374bcD7f
// CFX: 40aA958dd87FC8305b97f2BA922CDdCa374bcD7f
// POLYZK d2F0aC2012C8433F235c8e5e97F2368197DD06C7
address public constant _WNATIVE_RELAY = 0x5703B683c7F928b721CA95Da988d73a3299d4757;
// address public constant _WNATIVE_RELAY = 0x0B306BF915C4d645ff596e518fAf3F9669b97016; // hardhat1
// address public constant _WNATIVE_RELAY = 0x6A47346e722937B60Df7a1149168c0E76DD6520f; // hardhat2
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title Library for reverting with custom errors efficiently
/// @notice Contains functions for reverting with custom errors with different argument types efficiently
/// @dev To use this library, declare `using CustomRevert for bytes4;` and replace `revert CustomError()` with
/// `CustomError.selector.revertWith()`
/// @dev The functions may tamper with the free memory pointer but it is fine since the call context is exited immediately
library CustomRevert {
/// @dev ERC-7751 error for wrapping bubbled up reverts
error WrappedError(address target, bytes4 selector, bytes reason, bytes details);
/// @dev Reverts with the selector of a custom error in the scratch space
function revertWith(bytes4 selector) internal pure {
assembly ("memory-safe") {
mstore(0, selector)
revert(0, 0x04)
}
}
/// @dev Reverts with a custom error with an address argument in the scratch space
function revertWith(bytes4 selector, address addr) internal pure {
assembly ("memory-safe") {
mstore(0, selector)
mstore(0x04, and(addr, 0xffffffffffffffffffffffffffffffffffffffff))
revert(0, 0x24)
}
}
/// @dev Reverts with a custom error with an int24 argument in the scratch space
function revertWith(bytes4 selector, int24 value) internal pure {
assembly ("memory-safe") {
mstore(0, selector)
mstore(0x04, signextend(2, value))
revert(0, 0x24)
}
}
/// @dev Reverts with a custom error with a uint160 argument in the scratch space
function revertWith(bytes4 selector, uint160 value) internal pure {
assembly ("memory-safe") {
mstore(0, selector)
mstore(0x04, and(value, 0xffffffffffffffffffffffffffffffffffffffff))
revert(0, 0x24)
}
}
/// @dev Reverts with a custom error with two int24 arguments
function revertWith(bytes4 selector, int24 value1, int24 value2) internal pure {
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(fmp, selector)
mstore(add(fmp, 0x04), signextend(2, value1))
mstore(add(fmp, 0x24), signextend(2, value2))
revert(fmp, 0x44)
}
}
/// @dev Reverts with a custom error with two uint160 arguments
function revertWith(bytes4 selector, uint160 value1, uint160 value2) internal pure {
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(fmp, selector)
mstore(add(fmp, 0x04), and(value1, 0xffffffffffffffffffffffffffffffffffffffff))
mstore(add(fmp, 0x24), and(value2, 0xffffffffffffffffffffffffffffffffffffffff))
revert(fmp, 0x44)
}
}
/// @dev Reverts with a custom error with two address arguments
function revertWith(bytes4 selector, address value1, address value2) internal pure {
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(fmp, selector)
mstore(add(fmp, 0x04), and(value1, 0xffffffffffffffffffffffffffffffffffffffff))
mstore(add(fmp, 0x24), and(value2, 0xffffffffffffffffffffffffffffffffffffffff))
revert(fmp, 0x44)
}
}
/// @notice bubble up the revert message returned by a call and revert with a wrapped ERC-7751 error
/// @dev this method can be vulnerable to revert data bombs
function bubbleUpAndRevertWith(
address revertingContract,
bytes4 revertingFunctionSelector,
bytes4 additionalContext
) internal pure {
bytes4 wrappedErrorSelector = WrappedError.selector;
assembly ("memory-safe") {
// Ensure the size of the revert data is a multiple of 32 bytes
let encodedDataSize := mul(div(add(returndatasize(), 31), 32), 32)
let fmp := mload(0x40)
// Encode wrapped error selector, address, function selector, offset, additional context, size, revert reason
mstore(fmp, wrappedErrorSelector)
mstore(add(fmp, 0x04), and(revertingContract, 0xffffffffffffffffffffffffffffffffffffffff))
mstore(
add(fmp, 0x24),
and(revertingFunctionSelector, 0xffffffff00000000000000000000000000000000000000000000000000000000)
)
// offset revert reason
mstore(add(fmp, 0x44), 0x80)
// offset additional context
mstore(add(fmp, 0x64), add(0xa0, encodedDataSize))
// size revert reason
mstore(add(fmp, 0x84), returndatasize())
// revert reason
returndatacopy(add(fmp, 0xa4), 0, returndatasize())
// size additional context
mstore(add(fmp, add(0xa4, encodedDataSize)), 0x04)
// additional context
mstore(
add(fmp, add(0xc4, encodedDataSize)),
and(additionalContext, 0xffffffff00000000000000000000000000000000000000000000000000000000)
)
revert(fmp, add(0xe4, encodedDataSize))
}
}
}/// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title Base contract with common payable logics
abstract contract EthReceiver {
receive() external payable {
// solhint-disable-next-line avoid-tx-origin
require(msg.sender != tx.origin, "ETH deposit rejected");
}
}/// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
library PMMLib {
// ============ Struct ============
struct PMMSwapRequest {
uint256 pathIndex;
address payer;
address fromToken;
address toToken;
uint256 fromTokenAmountMax;
uint256 toTokenAmountMax;
uint256 salt;
uint256 deadLine;
bool isPushOrder;
bytes extension;
// address marketMaker;
// uint256 subIndex;
// bytes signature;
// uint256 source; 1byte type + 1byte bool(reverse) + 0...0 + 20 bytes address
}
struct PMMBaseRequest {
uint256 fromTokenAmount;
uint256 minReturnAmount;
uint256 deadLine;
bool fromNative;
bool toNative;
}
enum PMM_ERROR {
NO_ERROR,
INVALID_OPERATOR,
QUOTE_EXPIRED,
ORDER_CANCELLED_OR_FINALIZED,
REMAINING_AMOUNT_NOT_ENOUGH,
INVALID_AMOUNT_REQUEST,
FROM_TOKEN_PAYER_ERROR,
TO_TOKEN_PAYER_ERROR,
WRONG_FROM_TOKEN
}
event PMMSwap(
uint256 pathIndex,
uint256 subIndex,
uint256 errorCode
);
error PMMErrorCode(uint256 errorCode);
}/// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
library RevertReasonForwarder {
function reRevert() internal pure {
// bubble up revert reason from latest external call
/// @solidity memory-safe-assembly
assembly { // solhint-disable-line no-inline-assembly
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
}
}/// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
library RouterErrors {
error ReturnAmountIsNotEnough();
error InvalidMsgValue();
error ERC20TransferFailed();
error EmptyPools();
error InvalidFromToken();
error MsgValuedNotRequired();
}/// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {CustomRevert} from "./CustomRevert.sol";
/**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/
library SafeCast {
error SafeCastOverflow();
using CustomRevert for bytes4;
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*
* _Available since v4.7._
*/
function toUint248(uint256 value) internal pure returns (uint248) {
require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*
* _Available since v4.7._
*/
function toUint240(uint256 value) internal pure returns (uint240) {
require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*
* _Available since v4.7._
*/
function toUint232(uint256 value) internal pure returns (uint232) {
require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*
* _Available since v4.2._
*/
function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*
* _Available since v4.7._
*/
function toUint216(uint256 value) internal pure returns (uint216) {
require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*
* _Available since v4.7._
*/
function toUint208(uint256 value) internal pure returns (uint208) {
require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*
* _Available since v4.7._
*/
function toUint200(uint256 value) internal pure returns (uint200) {
require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*
* _Available since v4.7._
*/
function toUint192(uint256 value) internal pure returns (uint192) {
require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*
* _Available since v4.7._
*/
function toUint184(uint256 value) internal pure returns (uint184) {
require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*
* _Available since v4.7._
*/
function toUint176(uint256 value) internal pure returns (uint176) {
require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*
* _Available since v4.7._
*/
function toUint168(uint256 value) internal pure returns (uint168) {
require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*
* _Available since v4.7._
*/
function toUint160(uint256 value) internal pure returns (uint160) {
require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*
* _Available since v4.7._
*/
function toUint152(uint256 value) internal pure returns (uint152) {
require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*
* _Available since v4.7._
*/
function toUint144(uint256 value) internal pure returns (uint144) {
require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*
* _Available since v4.7._
*/
function toUint136(uint256 value) internal pure returns (uint136) {
require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v2.5._
*/
function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
return uint128(value);
}
/// @notice Cast a int128 to a uint128, revert on overflow or underflow
/// @param x The int128 to be casted
/// @return y The casted integer, now type uint128
function toUint128(int128 x) internal pure returns (uint128 y) {
if (x < 0) SafeCastOverflow.selector.revertWith();
y = uint128(x);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*
* _Available since v4.7._
*/
function toUint120(uint256 value) internal pure returns (uint120) {
require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*
* _Available since v4.7._
*/
function toUint112(uint256 value) internal pure returns (uint112) {
require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*
* _Available since v4.7._
*/
function toUint104(uint256 value) internal pure returns (uint104) {
require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*
* _Available since v4.2._
*/
function toUint96(uint256 value) internal pure returns (uint96) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*
* _Available since v4.7._
*/
function toUint88(uint256 value) internal pure returns (uint88) {
require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*
* _Available since v4.7._
*/
function toUint80(uint256 value) internal pure returns (uint80) {
require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*
* _Available since v4.7._
*/
function toUint72(uint256 value) internal pure returns (uint72) {
require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v2.5._
*/
function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*
* _Available since v4.7._
*/
function toUint56(uint256 value) internal pure returns (uint56) {
require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*
* _Available since v4.7._
*/
function toUint48(uint256 value) internal pure returns (uint48) {
require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*
* _Available since v4.7._
*/
function toUint40(uint256 value) internal pure returns (uint40) {
require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v2.5._
*/
function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*
* _Available since v4.7._
*/
function toUint24(uint256 value) internal pure returns (uint24) {
require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v2.5._
*/
function toUint16(uint256 value) internal pure returns (uint16) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*
* _Available since v2.5._
*/
function toUint8(uint256 value) internal pure returns (uint8) {
require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*
* _Available since v3.0._
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*
* _Available since v4.7._
*/
function toInt248(int256 value) internal pure returns (int248) {
require(value >= type(int248).min && value <= type(int248).max, "SafeCast: value doesn't fit in 248 bits");
return int248(value);
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*
* _Available since v4.7._
*/
function toInt240(int256 value) internal pure returns (int240) {
require(value >= type(int240).min && value <= type(int240).max, "SafeCast: value doesn't fit in 240 bits");
return int240(value);
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*
* _Available since v4.7._
*/
function toInt232(int256 value) internal pure returns (int232) {
require(value >= type(int232).min && value <= type(int232).max, "SafeCast: value doesn't fit in 232 bits");
return int232(value);
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*
* _Available since v4.7._
*/
function toInt224(int256 value) internal pure returns (int224) {
require(value >= type(int224).min && value <= type(int224).max, "SafeCast: value doesn't fit in 224 bits");
return int224(value);
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*
* _Available since v4.7._
*/
function toInt216(int256 value) internal pure returns (int216) {
require(value >= type(int216).min && value <= type(int216).max, "SafeCast: value doesn't fit in 216 bits");
return int216(value);
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*
* _Available since v4.7._
*/
function toInt208(int256 value) internal pure returns (int208) {
require(value >= type(int208).min && value <= type(int208).max, "SafeCast: value doesn't fit in 208 bits");
return int208(value);
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*
* _Available since v4.7._
*/
function toInt200(int256 value) internal pure returns (int200) {
require(value >= type(int200).min && value <= type(int200).max, "SafeCast: value doesn't fit in 200 bits");
return int200(value);
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*
* _Available since v4.7._
*/
function toInt192(int256 value) internal pure returns (int192) {
require(value >= type(int192).min && value <= type(int192).max, "SafeCast: value doesn't fit in 192 bits");
return int192(value);
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*
* _Available since v4.7._
*/
function toInt184(int256 value) internal pure returns (int184) {
require(value >= type(int184).min && value <= type(int184).max, "SafeCast: value doesn't fit in 184 bits");
return int184(value);
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*
* _Available since v4.7._
*/
function toInt176(int256 value) internal pure returns (int176) {
require(value >= type(int176).min && value <= type(int176).max, "SafeCast: value doesn't fit in 176 bits");
return int176(value);
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*
* _Available since v4.7._
*/
function toInt168(int256 value) internal pure returns (int168) {
require(value >= type(int168).min && value <= type(int168).max, "SafeCast: value doesn't fit in 168 bits");
return int168(value);
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*
* _Available since v4.7._
*/
function toInt160(int256 value) internal pure returns (int160) {
require(value >= type(int160).min && value <= type(int160).max, "SafeCast: value doesn't fit in 160 bits");
return int160(value);
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*
* _Available since v4.7._
*/
function toInt152(int256 value) internal pure returns (int152) {
require(value >= type(int152).min && value <= type(int152).max, "SafeCast: value doesn't fit in 152 bits");
return int152(value);
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*
* _Available since v4.7._
*/
function toInt144(int256 value) internal pure returns (int144) {
require(value >= type(int144).min && value <= type(int144).max, "SafeCast: value doesn't fit in 144 bits");
return int144(value);
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*
* _Available since v4.7._
*/
function toInt136(int256 value) internal pure returns (int136) {
require(value >= type(int136).min && value <= type(int136).max, "SafeCast: value doesn't fit in 136 bits");
return int136(value);
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v3.1._
*/
function toInt128(int256 value) internal pure returns (int128) {
require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits");
return int128(value);
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*
* _Available since v4.7._
*/
function toInt120(int256 value) internal pure returns (int120) {
require(value >= type(int120).min && value <= type(int120).max, "SafeCast: value doesn't fit in 120 bits");
return int120(value);
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*
* _Available since v4.7._
*/
function toInt112(int256 value) internal pure returns (int112) {
require(value >= type(int112).min && value <= type(int112).max, "SafeCast: value doesn't fit in 112 bits");
return int112(value);
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*
* _Available since v4.7._
*/
function toInt104(int256 value) internal pure returns (int104) {
require(value >= type(int104).min && value <= type(int104).max, "SafeCast: value doesn't fit in 104 bits");
return int104(value);
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*
* _Available since v4.7._
*/
function toInt96(int256 value) internal pure returns (int96) {
require(value >= type(int96).min && value <= type(int96).max, "SafeCast: value doesn't fit in 96 bits");
return int96(value);
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*
* _Available since v4.7._
*/
function toInt88(int256 value) internal pure returns (int88) {
require(value >= type(int88).min && value <= type(int88).max, "SafeCast: value doesn't fit in 88 bits");
return int88(value);
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*
* _Available since v4.7._
*/
function toInt80(int256 value) internal pure returns (int80) {
require(value >= type(int80).min && value <= type(int80).max, "SafeCast: value doesn't fit in 80 bits");
return int80(value);
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*
* _Available since v4.7._
*/
function toInt72(int256 value) internal pure returns (int72) {
require(value >= type(int72).min && value <= type(int72).max, "SafeCast: value doesn't fit in 72 bits");
return int72(value);
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v3.1._
*/
function toInt64(int256 value) internal pure returns (int64) {
require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits");
return int64(value);
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*
* _Available since v4.7._
*/
function toInt56(int256 value) internal pure returns (int56) {
require(value >= type(int56).min && value <= type(int56).max, "SafeCast: value doesn't fit in 56 bits");
return int56(value);
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*
* _Available since v4.7._
*/
function toInt48(int256 value) internal pure returns (int48) {
require(value >= type(int48).min && value <= type(int48).max, "SafeCast: value doesn't fit in 48 bits");
return int48(value);
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*
* _Available since v4.7._
*/
function toInt40(int256 value) internal pure returns (int40) {
require(value >= type(int40).min && value <= type(int40).max, "SafeCast: value doesn't fit in 40 bits");
return int40(value);
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v3.1._
*/
function toInt32(int256 value) internal pure returns (int32) {
require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits");
return int32(value);
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*
* _Available since v4.7._
*/
function toInt24(int256 value) internal pure returns (int24) {
require(value >= type(int24).min && value <= type(int24).max, "SafeCast: value doesn't fit in 24 bits");
return int24(value);
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v3.1._
*/
function toInt16(int256 value) internal pure returns (int16) {
require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits");
return int16(value);
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*
* _Available since v3.1._
*/
function toInt8(int256 value) internal pure returns (int8) {
require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits");
return int8(value);
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*
* _Available since v3.0._
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
return int256(value);
}
}/// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./SafeMath.sol"; import "./Address.sol"; import "./RevertReasonForwarder.sol"; import "../interfaces/IERC20.sol"; import "../interfaces/IERC20Permit.sol"; import "../interfaces/IDaiLikePermit.sol"; // File @1inch/solidity-utils/contracts/libraries/[email protected] library SafeERC20 { error SafeTransferFailed(); error SafeTransferFromFailed(); error ForceApproveFailed(); error SafeIncreaseAllowanceFailed(); error SafeDecreaseAllowanceFailed(); error SafePermitBadLength(); // Ensures method do not revert or return boolean `true`, admits call to non-smart-contract function safeTransferFrom(IERC20 token, address from, address to, uint256 amount) internal { bytes4 selector = token.transferFrom.selector; bool success; /// @solidity memory-safe-assembly assembly { // solhint-disable-line no-inline-assembly let data := mload(0x40) mstore(data, selector) mstore(add(data, 0x04), from) mstore(add(data, 0x24), to) mstore(add(data, 0x44), amount) success := call(gas(), token, 0, data, 100, 0x0, 0x20) if success { switch returndatasize() case 0 { success := gt(extcodesize(token), 0) } default { success := and(gt(returndatasize(), 31), eq(mload(0), 1)) } } } if (!success) revert SafeTransferFromFailed(); } // Ensures method do not revert or return boolean `true`, admits call to non-smart-contract function safeTransfer(IERC20 token, address to, uint256 value) internal { if (!_makeCall(token, token.transfer.selector, to, value)) { revert SafeTransferFailed(); } } function safeApprove(IERC20 token, address spender, uint256 value) internal { forceApprove(token, spender, value); } // If `approve(from, to, amount)` fails, try to `approve(from, to, 0)` before retry function forceApprove(IERC20 token, address spender, uint256 value) internal { if (!_makeCall(token, token.approve.selector, spender, value)) { if (!_makeCall(token, token.approve.selector, spender, 0) || !_makeCall(token, token.approve.selector, spender, value)) { revert ForceApproveFailed(); } } } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 allowance = token.allowance(address(this), spender); if (value > type(uint256).max - allowance) revert SafeIncreaseAllowanceFailed(); forceApprove(token, spender, allowance + value); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 allowance = token.allowance(address(this), spender); if (value > allowance) revert SafeDecreaseAllowanceFailed(); forceApprove(token, spender, allowance - value); } function safePermit(IERC20 token, bytes calldata permit) internal { bool success; if (permit.length == 32 * 7) { success = _makeCalldataCall(token, IERC20Permit.permit.selector, permit); } else if (permit.length == 32 * 8) { success = _makeCalldataCall(token, IDaiLikePermit.permit.selector, permit); } else { revert SafePermitBadLength(); } if (!success) RevertReasonForwarder.reRevert(); } function _makeCall(IERC20 token, bytes4 selector, address to, uint256 amount) private returns(bool success) { /// @solidity memory-safe-assembly assembly { // solhint-disable-line no-inline-assembly let data := mload(0x40) mstore(data, selector) mstore(add(data, 0x04), to) mstore(add(data, 0x24), amount) success := call(gas(), token, 0, data, 0x44, 0x0, 0x20) if success { switch returndatasize() case 0 { success := gt(extcodesize(token), 0) } default { success := and(gt(returndatasize(), 31), eq(mload(0), 1)) } } } } function _makeCalldataCall(IERC20 token, bytes4 selector, bytes calldata args) private returns(bool success) { /// @solidity memory-safe-assembly assembly { // solhint-disable-line no-inline-assembly let len := add(4, args.length) let data := mload(0x40) mstore(data, selector) calldatacopy(add(data, 0x04), args.offset, args.length) success := call(gas(), token, 0, data, len, 0x0, 0x20) if success { switch returndatasize() case 0 { success := gt(extcodesize(token), 0) } default { success := and(gt(returndatasize(), 31), eq(mload(0), 1)) } } } } }
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
library SafeMath {
uint256 constant WAD = 10**18;
uint256 constant RAY = 10**27;
function wad() public pure returns (uint256) {
return WAD;
}
function ray() public pure returns (uint256) {
return RAY;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a <= b ? a : b;
}
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b;
}
function sqrt(uint256 a) internal pure returns (uint256 b) {
if (a > 3) {
b = a;
uint256 x = a / 2 + 1;
while (x < b) {
b = x;
x = (a / x + x) / 2;
}
} else if (a != 0) {
b = 1;
}
}
function wmul(uint256 a, uint256 b) internal pure returns (uint256) {
return mul(a, b) / WAD;
}
function wmulRound(uint256 a, uint256 b) internal pure returns (uint256) {
return add(mul(a, b), WAD / 2) / WAD;
}
function rmul(uint256 a, uint256 b) internal pure returns (uint256) {
return mul(a, b) / RAY;
}
function rmulRound(uint256 a, uint256 b) internal pure returns (uint256) {
return add(mul(a, b), RAY / 2) / RAY;
}
function wdiv(uint256 a, uint256 b) internal pure returns (uint256) {
return div(mul(a, WAD), b);
}
function wdivRound(uint256 a, uint256 b) internal pure returns (uint256) {
return add(mul(a, WAD), b / 2) / b;
}
function rdiv(uint256 a, uint256 b) internal pure returns (uint256) {
return div(mul(a, RAY), b);
}
function rdivRound(uint256 a, uint256 b) internal pure returns (uint256) {
return add(mul(a, RAY), b / 2) / b;
}
function wpow(uint256 x, uint256 n) internal pure returns (uint256) {
uint256 result = WAD;
while (n > 0) {
if (n % 2 != 0) {
result = wmul(result, x);
}
x = wmul(x, x);
n /= 2;
}
return result;
}
function rpow(uint256 x, uint256 n) internal pure returns (uint256) {
uint256 result = RAY;
while (n > 0) {
if (n % 2 != 0) {
result = rmul(result, x);
}
x = rmul(x, x);
n /= 2;
}
return result;
}
function divCeil(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 quotient = div(a, b);
uint256 remainder = a - quotient * b;
if (remainder > 0) {
return quotient + 1;
} else {
return quotient;
}
}
}/// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {CommonUtils} from "./CommonUtils.sol";
import {IUni} from "../interfaces/IUni.sol";
import {IUniV3} from "../interfaces/IUniV3.sol";
/// @title UniswapTokenInfoHelper
/// @notice Helper functions for getting fromToken and toToken from
/// encoded pools array of unxswap and uniswapV3Swap methods.
/// @dev This contract will be used in DexRouter and DexRouterExactOut. So the
/// masks are re-defined here and keep the same as in the original contracts.
abstract contract UniswapTokenInfoHelper is CommonUtils {
function _getUnxswapTokenInfo(bool sendValue, bytes32[] calldata pools)
internal
view
returns (address fromToken, address toToken)
{
require(pools.length > 0, "pools must be greater than 0");
// get fromToken
address firstPoolAddr = address(uint160(uint256(pools[0]) & _ADDRESS_MASK));
// default: token0 to token1; reverse: token1 to token0
bool firstReversed = (uint256(pools[0]) & _REVERSE_MASK) != 0;
fromToken = firstReversed ? IUni(firstPoolAddr).token1() : IUni(firstPoolAddr).token0();
if (fromToken == _WETH && sendValue) {
fromToken = _ETH;
}
// get toToken
bytes32 lastPool = pools[pools.length - 1];
address lastPoolAddr = address(uint160(uint256(lastPool) & _ADDRESS_MASK));
bool lastReversed = (uint256(lastPool) & _REVERSE_MASK) != 0;
toToken = lastReversed ? IUni(lastPoolAddr).token0() : IUni(lastPoolAddr).token1();
bool isWeth = (uint256(lastPool) & _WETH_MASK) != 0; // unwrap weth to eth eventually
if (toToken == _WETH && isWeth) {
toToken = _ETH;
}
}
function _getUniswapV3TokenInfo(bool sendValue, uint256[] calldata pools)
internal
view
returns (address fromToken, address toToken)
{
require(pools.length > 0, "pools must be greater than 0");
// get fromToken
address firstPoolAddr = address(uint160(pools[0] & _ADDRESS_MASK));
bool firstZeroForOne = (pools[0] & _ONE_FOR_ZERO_MASK) == 0;
fromToken = firstZeroForOne ? IUniV3(firstPoolAddr).token0() : IUniV3(firstPoolAddr).token1();
if (fromToken == _WETH && sendValue) {
fromToken = _ETH;
}
// get toToken
uint256 lastPool = pools[pools.length - 1];
address lastPoolAddr = address(uint160(lastPool & _ADDRESS_MASK));
bool lastZeroForOne = (lastPool & _ONE_FOR_ZERO_MASK) == 0;
toToken = lastZeroForOne ? IUniV3(lastPoolAddr).token1() : IUniV3(lastPoolAddr).token0();
bool unwrapWeth = (lastPool & _WETH_UNWRAP_MASK) != 0; // unwrap weth to eth eventually
if (toToken == _WETH && unwrapWeth) {
toToken = _ETH;
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {SafeMath} from "./SafeMath.sol";
import {IERC20} from "../interfaces/IERC20.sol";
import {SafeERC20} from "./SafeERC20.sol";
library UniversalERC20 {
using SafeMath for uint256;
using SafeERC20 for IERC20;
IERC20 private constant ETH_ADDRESS =
IERC20(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE);
function universalTransfer(
IERC20 token,
address payable to,
uint256 amount
) internal {
if (amount > 0) {
if (isETH(token)) {
to.transfer(amount);
} else {
token.safeTransfer(to, amount);
}
}
}
function universalTransferFrom(
IERC20 token,
address from,
address payable to,
uint256 amount
) internal {
if (amount > 0) {
token.safeTransferFrom(from, to, amount);
}
}
function universalApproveMax(
IERC20 token,
address to,
uint256 amount
) internal {
uint256 allowance = token.allowance(address(this), to);
if (allowance < amount) {
token.forceApprove(to, type(uint256).max);
}
}
function universalBalanceOf(IERC20 token, address who)
internal
view
returns (uint256)
{
if (isETH(token)) {
return who.balance;
} else {
return token.balanceOf(who);
}
}
function tokenBalanceOf(IERC20 token, address who)
internal
view
returns (uint256)
{
return token.balanceOf(who);
}
function isETH(IERC20 token) internal pure returns (bool) {
return token == ETH_ADDRESS;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./interfaces/IUni.sol";
import "./libraries/UniversalERC20.sol";
import "./libraries/CommonUtils.sol";
contract UnxswapRouter is CommonUtils {
uint256 private constant _IS_TOKEN0_TAX =
0x1000000000000000000000000000000000000000000000000000000000000000;
uint256 private constant _IS_TOKEN1_TAX =
0x2000000000000000000000000000000000000000000000000000000000000000;
uint256 private constant _CLAIM_TOKENS_CALL_SELECTOR_32 =
0x0a5ea46600000000000000000000000000000000000000000000000000000000;
uint256 private constant _TRANSFER_DEPOSIT_SELECTOR =
0xa9059cbbd0e30db0000000000000000000000000000000000000000000000000;
uint256 private constant _SWAP_GETRESERVES_SELECTOR =
0x022c0d9f0902f1ac000000000000000000000000000000000000000000000000;
uint256 private constant _WITHDRAW_TRNASFER_SELECTOR =
0x2e1a7d4da9059cbb000000000000000000000000000000000000000000000000;
uint256 private constant _BALANCEOF_TOKEN0_SELECTOR =
0x70a082310dfe1681000000000000000000000000000000000000000000000000;
uint256 private constant _BALANCEOF_TOKEN1_SELECTOR =
0x70a08231d21220a7000000000000000000000000000000000000000000000000;
uint256 private constant _NUMERATOR_MASK =
0x0000000000000000ffffffff0000000000000000000000000000000000000000;
uint256 private constant _DENOMINATOR = 1_000_000_000;
uint256 private constant _NUMERATOR_OFFSET = 160;
//-------------------------------
//------- Internal Functions ----
//-------------------------------
/// @notice Performs the internal logic for executing a swap using the Unxswap protocol.
/// @param srcToken The token to be swapped.
/// @param amount The amount of the source token to be swapped.
/// @param minReturn The minimum amount of tokens that must be received for the swap to be valid, protecting against slippage.
/// @param pools The array of pool identifiers that define the swap route.
/// @param payer The address of the entity providing the source tokens for the swap.
/// @param receiver The address that will receive the tokens after the swap.
/// @return returnAmount The amount of tokens received from the swap.
/// @dev This internal function encapsulates the core logic of the Unxswap token swap process. It is meant to be called by other external functions that set up the required parameters. The actual interaction with the Unxswap pools and the token transfer mechanics are implemented here.
function _unxswapInternal(
IERC20 srcToken,
uint256 amount,
uint256 minReturn,
// solhint-disable-next-line no-unused-vars
bytes32[] calldata pools,
address payer,
address receiver
) internal returns (uint256 returnAmount) {
assembly {
// solhint-disable-line no-inline-assembly
function revertWithReason(m, len) {
mstore(
0,
0x08c379a000000000000000000000000000000000000000000000000000000000
)
mstore(
0x20,
0x0000002000000000000000000000000000000000000000000000000000000000
)
mstore(0x40, m)
revert(0, len)
}
function _getTokenAddr(emptyPtr, pair, selector) -> token {
mstore(emptyPtr, selector)
if iszero(
staticcall(
gas(),
pair,
add(0x04, emptyPtr),
0x04,
0x00,
0x20
)
) {
revertWithReason(
0x0000001067657420746f6b656e206661696c6564000000000000000000000000,
0x54
) // "get token failed"
}
token := mload(0x00)
}
function _getBalanceOfToken0(emptyPtr, pair) -> token0, balance0 {
mstore(emptyPtr, _BALANCEOF_TOKEN0_SELECTOR)
if iszero(
staticcall(
gas(),
pair,
add(0x04, emptyPtr),
0x04,
0x00,
0x20
)
) {
revertWithReason(
0x00000012746f6b656e302063616c6c206661696c656400000000000000000000,
0x56
) // "token0 call failed"
}
token0 := mload(0x00)
mstore(add(0x04, emptyPtr), pair)
if iszero(
staticcall(gas(), token0, emptyPtr, 0x24, 0x00, 0x20)
) {
revertWithReason(
0x0000001562616c616e63654f662063616c6c206661696c656400000000000000,
0x59
) // "balanceOf call failed"
}
balance0 := mload(0x00)
}
function _getBalanceOfToken1(emptyPtr, pair) -> token1, balance1 {
mstore(emptyPtr, _BALANCEOF_TOKEN1_SELECTOR)
if iszero(
staticcall(
gas(),
pair,
add(0x04, emptyPtr),
0x04,
0x00,
0x20
)
) {
revertWithReason(
0x00000012746f6b656e312063616c6c206661696c656400000000000000000000,
0x56
) // "token1 call failed"
}
token1 := mload(0x00)
mstore(add(0x04, emptyPtr), pair)
if iszero(
staticcall(gas(), token1, emptyPtr, 0x24, 0x00, 0x20)
) {
revertWithReason(
0x0000001562616c616e63654f662063616c6c206661696c656400000000000000,
0x59
) // "balanceOf call failed"
}
balance1 := mload(0x00)
}
function swap(
emptyPtr,
swapAmount,
pair,
reversed,
isToken0Tax,
isToken1Tax,
numerator,
dst
) -> ret {
mstore(emptyPtr, _SWAP_GETRESERVES_SELECTOR)
if iszero(
staticcall(
gas(),
pair,
add(0x04, emptyPtr),
0x4,
0x00,
0x40
)
) {
// we only need the first 0x40 bytes, no need timestamp info
revertWithReason(
0x0000001472657365727665732063616c6c206661696c65640000000000000000,
0x58
) // "reserves call failed"
}
let reserve0 := mload(0x00)
let reserve1 := mload(0x20)
switch reversed
case 0 {
//swap token0 for token1
if isToken0Tax {
let token0, balance0 := _getBalanceOfToken0(
emptyPtr,
pair
)
swapAmount := sub(balance0, reserve0)
}
}
default {
//swap token1 for token0
if isToken1Tax {
let token1, balance1 := _getBalanceOfToken1(
emptyPtr,
pair
)
swapAmount := sub(balance1, reserve1)
}
let temp := reserve0
reserve0 := reserve1
reserve1 := temp
}
ret := mul(swapAmount, numerator)
ret := div(
mul(ret, reserve1),
add(ret, mul(reserve0, _DENOMINATOR))
)
mstore(emptyPtr, _SWAP_GETRESERVES_SELECTOR)
switch reversed
case 0 {
mstore(add(emptyPtr, 0x04), 0)
mstore(add(emptyPtr, 0x24), ret)
}
default {
mstore(add(emptyPtr, 0x04), ret)
mstore(add(emptyPtr, 0x24), 0)
}
mstore(add(emptyPtr, 0x44), dst)
mstore(add(emptyPtr, 0x64), 0x80)
mstore(add(emptyPtr, 0x84), 0)
if iszero(call(gas(), pair, 0, emptyPtr, 0xa4, 0, 0)) {
revertWithReason(
0x00000010737761702063616c6c206661696c6564000000000000000000000000,
0x54
) // "swap call failed"
}
}
let poolsOffset
let poolsEndOffset
{
let len := pools.length
poolsOffset := pools.offset //
poolsEndOffset := add(poolsOffset, mul(len, 32))
if eq(len, 0) {
revertWithReason(
0x000000b656d70747920706f6f6c73000000000000000000000000000000000000,
0x4e
) // "empty pools"
}
}
let emptyPtr := mload(0x40)
let rawPair := calldataload(poolsOffset)
switch eq(_ETH, srcToken)
case 1 {
// require callvalue() >= amount, lt: if x < y return 1,else return 0
if eq(lt(callvalue(), amount), 1) {
revertWithReason(
0x00000011696e76616c6964206d73672e76616c75650000000000000000000000,
0x55
) // "invalid msg.value"
}
mstore(emptyPtr, _TRANSFER_DEPOSIT_SELECTOR)
if iszero(
call(gas(), _WETH, amount, add(emptyPtr, 0x04), 0x4, 0, 0)
) {
revertWithReason(
0x000000126465706f73697420455448206661696c656400000000000000000000,
0x56
) // "deposit ETH failed"
}
mstore(add(0x04, emptyPtr), and(rawPair, _ADDRESS_MASK))
mstore(add(0x24, emptyPtr), amount)
if iszero(call(gas(), _WETH, 0, emptyPtr, 0x44, 0, 0x20)) {
revertWithReason(
0x000000147472616e736665722057455448206661696c65640000000000000000,
0x58
) // "transfer WETH failed"
}
}
default {
if callvalue() {
revertWithReason(
0x00000011696e76616c6964206d73672e76616c75650000000000000000000000,
0x55
) // "invalid msg.value"
}
mstore(emptyPtr, _CLAIM_TOKENS_CALL_SELECTOR_32)
mstore(add(emptyPtr, 0x4), srcToken)
mstore(add(emptyPtr, 0x24), payer)
mstore(add(emptyPtr, 0x44), and(rawPair, _ADDRESS_MASK))
mstore(add(emptyPtr, 0x64), amount)
if iszero(
call(gas(), _APPROVE_PROXY, 0, emptyPtr, 0x84, 0, 0)
) {
revertWithReason(
0x00000012636c61696d20746f6b656e206661696c656400000000000000000000,
0x56
) // "claim token failed"
}
}
returnAmount := amount
for {
let i := add(poolsOffset, 0x20)
} lt(i, poolsEndOffset) {
i := add(i, 0x20)
} {
let nextRawPair := calldataload(i)
returnAmount := swap(
emptyPtr,
returnAmount,
and(rawPair, _ADDRESS_MASK),
and(rawPair, _REVERSE_MASK),
and(rawPair, _IS_TOKEN0_TAX),
and(rawPair, _IS_TOKEN1_TAX),
shr(_NUMERATOR_OFFSET, and(rawPair, _NUMERATOR_MASK)),
and(nextRawPair, _ADDRESS_MASK)
)
rawPair := nextRawPair
}
let toToken
switch and(rawPair, _WETH_MASK)
case 0 {
let beforeAmount
switch and(rawPair, _REVERSE_MASK)
case 0 {
if and(rawPair, _IS_TOKEN1_TAX) {
mstore(emptyPtr, _BALANCEOF_TOKEN1_SELECTOR)
if iszero(
staticcall(
gas(),
and(rawPair, _ADDRESS_MASK),
add(0x04, emptyPtr),
0x04,
0x00,
0x20
)
) {
revertWithReason(
0x00000012746f6b656e312063616c6c206661696c656400000000000000000000,
0x56
) // "token1 call failed"
}
toToken := mload(0)
mstore(add(0x04, emptyPtr), receiver)
if iszero(
staticcall(
gas(),
toToken,
emptyPtr,
0x24,
0x00,
0x20
)
) {
revertWithReason(
0x00000015746f6b656e312062616c616e6365206661696c656400000000000000,
0x59
) // "token1 balance failed"
}
beforeAmount := mload(0)
}
}
default {
if and(rawPair, _IS_TOKEN0_TAX) {
mstore(emptyPtr, _BALANCEOF_TOKEN0_SELECTOR)
if iszero(
staticcall(
gas(),
and(rawPair, _ADDRESS_MASK),
add(0x04, emptyPtr),
0x04,
0x00,
0x20
)
) {
revertWithReason(
0x00000012746f6b656e302063616c6c206661696c656400000000000000000000,
0x56
) // "token0 call failed"
}
toToken := mload(0)
mstore(add(0x04, emptyPtr), receiver)
if iszero(
staticcall(
gas(),
toToken,
emptyPtr,
0x24,
0x00,
0x20
)
) {
revertWithReason(
0x00000015746f6b656e302062616c616e6365206661696c656400000000000000,
0x56
) // "token0 balance failed"
}
beforeAmount := mload(0)
}
}
returnAmount := swap(
emptyPtr,
returnAmount,
and(rawPair, _ADDRESS_MASK),
and(rawPair, _REVERSE_MASK),
and(rawPair, _IS_TOKEN0_TAX),
and(rawPair, _IS_TOKEN1_TAX),
shr(_NUMERATOR_OFFSET, and(rawPair, _NUMERATOR_MASK)),
receiver
)
switch lt(0x0, toToken)
case 1 {
mstore(emptyPtr, _BALANCEOF_TOKEN0_SELECTOR)
mstore(add(0x04, emptyPtr), receiver)
if iszero(
staticcall(gas(), toToken, emptyPtr, 0x24, 0x00, 0x20)
) {
revertWithReason(
0x000000146765742062616c616e63654f66206661696c65640000000000000000,
0x58
) // "get balanceOf failed"
}
returnAmount := sub(mload(0), beforeAmount)
}
default {
// set token0 addr for the non-safemoon token
switch and(rawPair, _REVERSE_MASK)
case 0 {
// get token1
toToken := _getTokenAddr(
emptyPtr,
and(rawPair, _ADDRESS_MASK),
_BALANCEOF_TOKEN1_SELECTOR
)
}
default {
// get token0
toToken := _getTokenAddr(
emptyPtr,
and(rawPair, _ADDRESS_MASK),
_BALANCEOF_TOKEN0_SELECTOR
)
}
}
}
default {
toToken := _ETH
returnAmount := swap(
emptyPtr,
returnAmount,
and(rawPair, _ADDRESS_MASK),
and(rawPair, _REVERSE_MASK),
and(rawPair, _IS_TOKEN0_TAX),
and(rawPair, _IS_TOKEN1_TAX),
shr(_NUMERATOR_OFFSET, and(rawPair, _NUMERATOR_MASK)),
address()
)
mstore(emptyPtr, _WITHDRAW_TRNASFER_SELECTOR)
mstore(add(emptyPtr, 0x08), _WNATIVE_RELAY)
mstore(add(emptyPtr, 0x28), returnAmount)
if iszero(
call(gas(), _WETH, 0, add(0x04, emptyPtr), 0x44, 0, 0x20)
) {
revertWithReason(
0x000000147472616e736665722057455448206661696c65640000000000000000,
0x58
) // "transfer WETH failed"
}
mstore(add(emptyPtr, 0x04), returnAmount)
if iszero(
call(gas(), _WNATIVE_RELAY, 0, emptyPtr, 0x24, 0, 0x20)
) {
revertWithReason(
0x00000013776974686472617720455448206661696c6564000000000000000000,
0x57
) // "withdraw ETH failed"
}
if iszero(call(gas(), receiver, returnAmount, 0, 0, 0, 0)) {
revertWithReason(
0x000000137472616e7366657220455448206661696c6564000000000000000000,
0x57
) // "transfer ETH failed"
}
}
}
}
}/// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
import "./interfaces/IUniswapV3SwapCallback.sol";
import "./interfaces/IUniV3.sol";
import "./interfaces/IWETH.sol";
import "./interfaces/IWNativeRelayer.sol";
import "./libraries/Address.sol";
import "./libraries/CommonUtils.sol";
import "./libraries/RouterErrors.sol";
import "./libraries/SafeCast.sol";
contract UnxswapV3Router is IUniswapV3SwapCallback, CommonUtils {
using Address for address payable;
bytes32 private constant _POOL_INIT_CODE_HASH =
0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54; // Pool init code hash
bytes32 private constant _FF_FACTORY = 0xff1F98431c8aD98523631AE4a59f267346ea31F9840000000000000000000000; // Factory address
// concatenation of token0(), token1() fee(), transfer() and claimTokens() selectors
bytes32 private constant _SELECTORS =
0x0dfe1681d21220a7ddca3f43a9059cbb0a5ea466000000000000000000000000;
// concatenation of withdraw(uint),transfer()
bytes32 private constant _SELECTORS2 =
0x2e1a7d4da9059cbb000000000000000000000000000000000000000000000000;
bytes32 private constant _SELECTORS3 =
0xa9059cbb70a08231000000000000000000000000000000000000000000000000;
uint160 private constant _MIN_SQRT_RATIO = 4_295_128_739 + 1;
uint160 private constant _MAX_SQRT_RATIO =
1_461_446_703_485_210_103_287_273_052_203_988_822_378_723_970_342 - 1;
bytes32 private constant _SWAP_SELECTOR =
0x128acb0800000000000000000000000000000000000000000000000000000000; // Swap function selector
uint256 private constant _INT256_MAX =
0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff; // Maximum int256
uint256 private constant _INT256_MIN =
0x8000000000000000000000000000000000000000000000000000000000000000; // Minimum int256
/// @notice Conducts a swap using the Uniswap V3 protocol internally within the contract.
/// @param payer The address of the account providing the tokens for the swap.
/// @param receiver The address that will receive the tokens after the swap.
/// @param amount The amount of the source token to be swapped.
/// @param minReturn The minimum amount of tokens that must be received for the swap to be valid, safeguarding against excessive slippage.
/// @param pools An array of pool identifiers defining the swap route within Uniswap V3.
/// @return returnAmount The amount of tokens received from the swap.
/// @dev This internal function encapsulates the core logic for executing swaps on Uniswap V3. It is intended to be used by other functions in the contract that prepare and pass the necessary parameters. The function handles the swapping process, ensuring that the minimum return is met and managing the transfer of tokens.
function _uniswapV3Swap(
address payer,
address payable receiver,
uint256 amount,
uint256 minReturn,
uint256[] calldata pools
) internal returns (uint256 returnAmount) {
assembly {
function _revertWithReason(m, len) {
mstore(
0,
0x08c379a000000000000000000000000000000000000000000000000000000000
)
mstore(
0x20,
0x0000002000000000000000000000000000000000000000000000000000000000
)
mstore(0x40, m)
revert(0, len)
}
function _makeSwap(_receiver, _payer, _refundTo, _pool, _amount)
-> _returnAmount
{
if lt(_INT256_MAX, _amount) {
mstore(
0,
0xb3f79fd000000000000000000000000000000000000000000000000000000000
) //SafeCastToInt256Failed()
revert(0, 4)
}
let freePtr := mload(0x40)
let zeroForOne := eq(and(_pool, _ONE_FOR_ZERO_MASK), 0)
let poolAddr := and(_pool, _ADDRESS_MASK)
switch zeroForOne
case 1 {
mstore(freePtr, _SWAP_SELECTOR)
let paramPtr := add(freePtr, 4)
mstore(paramPtr, _receiver)
mstore(add(paramPtr, 0x20), true)
mstore(add(paramPtr, 0x40), _amount)
mstore(add(paramPtr, 0x60), _MIN_SQRT_RATIO)
mstore(add(paramPtr, 0x80), 0xa0)
mstore(add(paramPtr, 0xa0), 64)
mstore(add(paramPtr, 0xc0), _payer)
mstore(add(paramPtr, 0xe0), _refundTo)
let success := call(
gas(),
poolAddr,
0,
freePtr,
0x104,
0,
0
)
if iszero(success) {
revert(0, 32)
}
returndatacopy(0, 32, 32) // only copy _amount1 MEM[0:] <= RETURNDATA[32:32+32]
}
default {
mstore(freePtr, _SWAP_SELECTOR)
let paramPtr := add(freePtr, 4)
mstore(paramPtr, _receiver)
mstore(add(paramPtr, 0x20), false)
mstore(add(paramPtr, 0x40), _amount)
mstore(add(paramPtr, 0x60), _MAX_SQRT_RATIO)
mstore(add(paramPtr, 0x80), 0xa0)
mstore(add(paramPtr, 0xa0), 64)
mstore(add(paramPtr, 0xc0), _payer)
mstore(add(paramPtr, 0xe0), _refundTo)
let success := call(
gas(),
poolAddr,
0,
freePtr,
0x104,
0,
0
)
if iszero(success) {
revert(0, 32)
}
returndatacopy(0, 0, 32) // only copy _amount0 MEM[0:] <= RETURNDATA[0:0+32]
}
_returnAmount := mload(0)
if lt(_returnAmount, _INT256_MIN) {
mstore(
0,
0x88c8ee9c00000000000000000000000000000000000000000000000000000000
) //SafeCastToUint256Failed()
revert(0, 4)
}
_returnAmount := add(1, not(_returnAmount)) // -a = ~a + 1
}
function _wrapWeth(_amount) {
// require callvalue() >= amount, lt: if x < y return 1,else return 0
if eq(lt(callvalue(), _amount), 1) {
mstore(
0,
0x1841b4e100000000000000000000000000000000000000000000000000000000
) // InvalidMsgValue()
revert(0, 4)
}
let success := call(gas(), _WETH, _amount, 0, 0, 0, 0) //进入fallback逻辑
if iszero(success) {
_revertWithReason(
0x0000001357455448206465706f736974206661696c6564000000000000000000,
87
) //WETH deposit failed
}
}
function _unWrapWeth(_receiver, _amount) {
let freePtr := mload(0x40)
let transferPtr := add(freePtr, 4)
mstore(freePtr, _SELECTORS2) // withdraw amountWith to amount
// transfer
mstore(add(transferPtr, 4), _WNATIVE_RELAY)
mstore(add(transferPtr, 36), _amount)
let success := call(gas(), _WETH, 0, transferPtr, 68, 0, 0)
if iszero(success) {
_revertWithReason(
0x000000147472616e736665722077657468206661696c65640000000000000000,
88
) // transfer weth failed
}
// withdraw
mstore(add(freePtr, 4), _amount)
success := call(gas(), _WNATIVE_RELAY, 0, freePtr, 36, 0, 0)
if iszero(success) {
_revertWithReason(
0x0000001477697468647261772077657468206661696c65640000000000000000,
88
) // withdraw weth failed
}
// msg.value transfer
success := call(gas(), _receiver, _amount, 0, 0, 0, 0)
if iszero(success) {
_revertWithReason(
0x0000001173656e64206574686572206661696c65640000000000000000000000,
85
) // send ether failed
}
}
function _token0(_pool) -> token0 {
let freePtr := mload(0x40)
mstore(freePtr, _SELECTORS)
let success := staticcall(gas(), _pool, freePtr, 0x4, 0, 0)
if iszero(success) {
_revertWithReason(
0x0000001167657420746f6b656e30206661696c65640000000000000000000000,
85
) // get token0 failed
}
returndatacopy(0, 0, 32)
token0 := mload(0)
}
function _token1(_pool) -> token1 {
let freePtr := mload(0x40)
mstore(freePtr, _SELECTORS)
let success := staticcall(
gas(),
_pool,
add(freePtr, 4),
0x4,
0,
0
)
if iszero(success) {
_revertWithReason(
0x0000001167657420746f6b656e31206661696c65640000000000000000000000,
84
) // get token1 failed
}
returndatacopy(0, 0, 32)
token1 := mload(0)
}
let firstPoolStart
let lastPoolStart
{
let len := pools.length
firstPoolStart := pools.offset //
lastPoolStart := sub(add(firstPoolStart, mul(len, 32)), 32)
if eq(len, 0) {
mstore(
0,
0x67e7c0f600000000000000000000000000000000000000000000000000000000
) // EmptyPools()
revert(0, 4)
}
}
let refundTo := payer
{
let wrapWeth := gt(callvalue(), 0)
if wrapWeth {
_wrapWeth(amount)
payer := address()
}
}
mstore(96, amount) // 96 is not override by _makeSwap, since it only use freePtr memory, and it is not override by unWrapWeth ethier
for {
let i := firstPoolStart
} lt(i, lastPoolStart) {
i := add(i, 32)
} {
amount := _makeSwap(
address(),
payer,
refundTo,
calldataload(i),
amount
)
payer := address()
}
{
let unwrapWeth := gt(
and(calldataload(lastPoolStart), _WETH_UNWRAP_MASK),
0
) // pools[lastIndex] & _WETH_UNWRAP_MASK > 0
// last one or only one
switch unwrapWeth
case 1 {
returnAmount := _makeSwap(
address(),
payer,
refundTo,
calldataload(lastPoolStart),
amount
)
_unWrapWeth(receiver, returnAmount)
}
case 0 {
returnAmount := _makeSwap(
receiver,
payer,
refundTo,
calldataload(lastPoolStart),
amount
)
}
}
}
}
/// @inheritdoc IUniswapV3SwapCallback
function uniswapV3SwapCallback(
int256 amount0Delta,
int256 amount1Delta,
bytes calldata /*data*/
) external override {
assembly {
// solhint-disable-line no-inline-assembly
function reRevert() {
returndatacopy(0, 0, returndatasize())
revert(0, returndatasize())
}
function getBalanceAndTransfer(emptyPtr, token) {
mstore(emptyPtr, _SELECTORS3)
mstore(add(8, emptyPtr), address())
if iszero(
staticcall(gas(), token, add(4, emptyPtr), 36, 0, 32)
) {
reRevert()
}
let amount := mload(0)
if gt(amount, 0) {
let refundTo := calldataload(164)
mstore(add(4, emptyPtr), refundTo)
mstore(add(36, emptyPtr), amount)
validateERC20Transfer(
call(gas(), token, 0, emptyPtr, 0x44, 0, 0x20)
)
}
}
function validateERC20Transfer(status) {
if iszero(status) {
reRevert()
}
let success := or(
iszero(returndatasize()), // empty return data
and(gt(returndatasize(), 31), eq(mload(0), 1)) // true in return data
)
if iszero(success) {
mstore(
0,
0xf27f64e400000000000000000000000000000000000000000000000000000000
) // ERC20TransferFailed()
revert(0, 4)
}
}
let emptyPtr := mload(0x40)
let resultPtr := add(emptyPtr, 21) // 0x15 = _FF_FACTORY size
mstore(emptyPtr, _SELECTORS)
// token0
if iszero(staticcall(gas(), caller(), emptyPtr, 4, 0, 32)) {
reRevert()
}
//token1
if iszero(
staticcall(gas(), caller(), add(emptyPtr, 4), 4, 32, 32)
) {
reRevert()
}
// fee
if iszero(
staticcall(gas(), caller(), add(emptyPtr, 8), 4, 64, 32)
) {
reRevert()
}
let token
let amount
switch sgt(amount0Delta, 0)
case 1 {
token := mload(0)
amount := amount0Delta
}
default {
token := mload(32)
amount := amount1Delta
}
// let salt := keccak256(0, 96)
mstore(emptyPtr, _FF_FACTORY)
mstore(resultPtr, keccak256(0, 96)) // Compute the inner hash in-place
mstore(add(resultPtr, 32), _POOL_INIT_CODE_HASH)
let pool := and(keccak256(emptyPtr, 85), _ADDRESS_MASK)
if iszero(eq(pool, caller())) {
// if xor(pool, caller()) {
mstore(
0,
0xb2c0272200000000000000000000000000000000000000000000000000000000
) // BadPool()
revert(0, 4)
}
let payer := calldataload(132) // 4+32+32+32+32 = 132
mstore(emptyPtr, _SELECTORS)
switch eq(payer, address())
case 1 {
// token.safeTransfer(msg.sender,amount)
mstore(add(emptyPtr, 0x10), caller())
mstore(add(emptyPtr, 0x30), amount)
validateERC20Transfer(
call(gas(), token, 0, add(emptyPtr, 0x0c), 0x44, 0, 0x20)
)
getBalanceAndTransfer(emptyPtr, token)
}
default {
// approveProxy.claimTokens(token, payer, msg.sender, amount);
mstore(add(emptyPtr, 0x14), token)
mstore(add(emptyPtr, 0x34), payer)
mstore(add(emptyPtr, 0x54), caller())
mstore(add(emptyPtr, 0x74), amount)
validateERC20Transfer(
call(
gas(),
_APPROVE_PROXY,
0,
add(emptyPtr, 0x10),
0x84,
0,
0x20
)
)
}
}
}
}{
"optimizer": {
"enabled": true,
"runs": 1
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[],"name":"SafeTransferFailed","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"commissionRate1","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"commissionRate2","type":"uint256"},{"indexed":false,"internalType":"bool","name":"isToBCommission","type":"bool"},{"indexed":false,"internalType":"uint256","name":"trimRate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"chargeRate","type":"uint256"}],"name":"CommissionAndTrimInfo","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"fromToken","type":"address"},{"indexed":false,"internalType":"address","name":"toToken","type":"address"},{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"fromAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"returnAmount","type":"uint256"}],"name":"OrderRecord","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"}],"name":"SwapOrderId","type":"event"},{"inputs":[],"name":"_APPROVE_PROXY","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_WETH","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_WNATIVE_RELAY","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"components":[{"internalType":"uint256","name":"fromToken","type":"uint256"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"fromTokenAmount","type":"uint256"},{"internalType":"uint256","name":"minReturnAmount","type":"uint256"},{"internalType":"uint256","name":"deadLine","type":"uint256"}],"internalType":"struct IDexRouter.BaseRequest","name":"baseRequest","type":"tuple"},{"components":[{"internalType":"address[]","name":"mixAdapters","type":"address[]"},{"internalType":"address[]","name":"assetTo","type":"address[]"},{"internalType":"uint256[]","name":"rawData","type":"uint256[]"},{"internalType":"bytes[]","name":"extraData","type":"bytes[]"},{"internalType":"uint256","name":"fromToken","type":"uint256"}],"internalType":"struct IDexRouter.RouterPath[]","name":"paths","type":"tuple[]"}],"name":"dagSwapByOrderId","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"components":[{"internalType":"uint256","name":"fromToken","type":"uint256"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"fromTokenAmount","type":"uint256"},{"internalType":"uint256","name":"minReturnAmount","type":"uint256"},{"internalType":"uint256","name":"deadLine","type":"uint256"}],"internalType":"struct IDexRouter.BaseRequest","name":"baseRequest","type":"tuple"},{"components":[{"internalType":"address[]","name":"mixAdapters","type":"address[]"},{"internalType":"address[]","name":"assetTo","type":"address[]"},{"internalType":"uint256[]","name":"rawData","type":"uint256[]"},{"internalType":"bytes[]","name":"extraData","type":"bytes[]"},{"internalType":"uint256","name":"fromToken","type":"uint256"}],"internalType":"struct IDexRouter.RouterPath[]","name":"paths","type":"tuple[]"}],"name":"dagSwapTo","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"fromToken","type":"uint256"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"fromTokenAmount","type":"uint256"},{"internalType":"uint256","name":"minReturnAmount","type":"uint256"},{"internalType":"uint256","name":"deadLine","type":"uint256"}],"internalType":"struct IDexRouter.BaseRequest","name":"baseRequest","type":"tuple"},{"internalType":"uint256[]","name":"batchesAmount","type":"uint256[]"},{"components":[{"internalType":"address[]","name":"mixAdapters","type":"address[]"},{"internalType":"address[]","name":"assetTo","type":"address[]"},{"internalType":"uint256[]","name":"rawData","type":"uint256[]"},{"internalType":"bytes[]","name":"extraData","type":"bytes[]"},{"internalType":"uint256","name":"fromToken","type":"uint256"}],"internalType":"struct IDexRouter.RouterPath[][]","name":"batches","type":"tuple[][]"},{"components":[{"internalType":"uint256","name":"pathIndex","type":"uint256"},{"internalType":"address","name":"payer","type":"address"},{"internalType":"address","name":"fromToken","type":"address"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"fromTokenAmountMax","type":"uint256"},{"internalType":"uint256","name":"toTokenAmountMax","type":"uint256"},{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"uint256","name":"deadLine","type":"uint256"},{"internalType":"bool","name":"isPushOrder","type":"bool"},{"internalType":"bytes","name":"extension","type":"bytes"}],"internalType":"struct PMMLib.PMMSwapRequest[]","name":"extraData","type":"tuple[]"},{"internalType":"address","name":"to","type":"address"}],"name":"smartSwapByInvest","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"fromToken","type":"uint256"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"fromTokenAmount","type":"uint256"},{"internalType":"uint256","name":"minReturnAmount","type":"uint256"},{"internalType":"uint256","name":"deadLine","type":"uint256"}],"internalType":"struct IDexRouter.BaseRequest","name":"baseRequest","type":"tuple"},{"internalType":"uint256[]","name":"batchesAmount","type":"uint256[]"},{"components":[{"internalType":"address[]","name":"mixAdapters","type":"address[]"},{"internalType":"address[]","name":"assetTo","type":"address[]"},{"internalType":"uint256[]","name":"rawData","type":"uint256[]"},{"internalType":"bytes[]","name":"extraData","type":"bytes[]"},{"internalType":"uint256","name":"fromToken","type":"uint256"}],"internalType":"struct IDexRouter.RouterPath[][]","name":"batches","type":"tuple[][]"},{"components":[{"internalType":"uint256","name":"pathIndex","type":"uint256"},{"internalType":"address","name":"payer","type":"address"},{"internalType":"address","name":"fromToken","type":"address"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"fromTokenAmountMax","type":"uint256"},{"internalType":"uint256","name":"toTokenAmountMax","type":"uint256"},{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"uint256","name":"deadLine","type":"uint256"},{"internalType":"bool","name":"isPushOrder","type":"bool"},{"internalType":"bytes","name":"extension","type":"bytes"}],"internalType":"struct PMMLib.PMMSwapRequest[]","name":"","type":"tuple[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"address","name":"refundTo","type":"address"}],"name":"smartSwapByInvestWithRefund","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"components":[{"internalType":"uint256","name":"fromToken","type":"uint256"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"fromTokenAmount","type":"uint256"},{"internalType":"uint256","name":"minReturnAmount","type":"uint256"},{"internalType":"uint256","name":"deadLine","type":"uint256"}],"internalType":"struct IDexRouter.BaseRequest","name":"baseRequest","type":"tuple"},{"internalType":"uint256[]","name":"batchesAmount","type":"uint256[]"},{"components":[{"internalType":"address[]","name":"mixAdapters","type":"address[]"},{"internalType":"address[]","name":"assetTo","type":"address[]"},{"internalType":"uint256[]","name":"rawData","type":"uint256[]"},{"internalType":"bytes[]","name":"extraData","type":"bytes[]"},{"internalType":"uint256","name":"fromToken","type":"uint256"}],"internalType":"struct IDexRouter.RouterPath[][]","name":"batches","type":"tuple[][]"},{"components":[{"internalType":"uint256","name":"pathIndex","type":"uint256"},{"internalType":"address","name":"payer","type":"address"},{"internalType":"address","name":"fromToken","type":"address"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"fromTokenAmountMax","type":"uint256"},{"internalType":"uint256","name":"toTokenAmountMax","type":"uint256"},{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"uint256","name":"deadLine","type":"uint256"},{"internalType":"bool","name":"isPushOrder","type":"bool"},{"internalType":"bytes","name":"extension","type":"bytes"}],"internalType":"struct PMMLib.PMMSwapRequest[]","name":"","type":"tuple[]"}],"name":"smartSwapByOrderId","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"components":[{"internalType":"uint256","name":"fromToken","type":"uint256"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"fromTokenAmount","type":"uint256"},{"internalType":"uint256","name":"minReturnAmount","type":"uint256"},{"internalType":"uint256","name":"deadLine","type":"uint256"}],"internalType":"struct IDexRouter.BaseRequest","name":"baseRequest","type":"tuple"},{"internalType":"uint256[]","name":"batchesAmount","type":"uint256[]"},{"components":[{"internalType":"address[]","name":"mixAdapters","type":"address[]"},{"internalType":"address[]","name":"assetTo","type":"address[]"},{"internalType":"uint256[]","name":"rawData","type":"uint256[]"},{"internalType":"bytes[]","name":"extraData","type":"bytes[]"},{"internalType":"uint256","name":"fromToken","type":"uint256"}],"internalType":"struct IDexRouter.RouterPath[][]","name":"batches","type":"tuple[][]"},{"components":[{"internalType":"uint256","name":"pathIndex","type":"uint256"},{"internalType":"address","name":"payer","type":"address"},{"internalType":"address","name":"fromToken","type":"address"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"fromTokenAmountMax","type":"uint256"},{"internalType":"uint256","name":"toTokenAmountMax","type":"uint256"},{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"uint256","name":"deadLine","type":"uint256"},{"internalType":"bool","name":"isPushOrder","type":"bool"},{"internalType":"bytes","name":"extension","type":"bytes"}],"internalType":"struct PMMLib.PMMSwapRequest[]","name":"","type":"tuple[]"}],"name":"smartSwapTo","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"uint256","name":"rawdata","type":"uint256"}],"name":"swapWrap","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"components":[{"internalType":"uint256","name":"fromToken","type":"uint256"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"fromTokenAmount","type":"uint256"},{"internalType":"uint256","name":"minReturnAmount","type":"uint256"},{"internalType":"uint256","name":"deadLine","type":"uint256"}],"internalType":"struct IDexRouter.BaseRequest","name":"baseRequest","type":"tuple"}],"name":"swapWrapToWithBaseRequest","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"int256","name":"amount0Delta","type":"int256"},{"internalType":"int256","name":"amount1Delta","type":"int256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"uniswapV3SwapCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"receiver","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minReturn","type":"uint256"},{"internalType":"uint256[]","name":"pools","type":"uint256[]"}],"name":"uniswapV3SwapTo","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"components":[{"internalType":"uint256","name":"fromToken","type":"uint256"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"fromTokenAmount","type":"uint256"},{"internalType":"uint256","name":"minReturnAmount","type":"uint256"},{"internalType":"uint256","name":"deadLine","type":"uint256"}],"internalType":"struct IDexRouter.BaseRequest","name":"baseRequest","type":"tuple"},{"internalType":"uint256[]","name":"pools","type":"uint256[]"}],"name":"uniswapV3SwapToWithBaseRequest","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"srcToken","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minReturn","type":"uint256"},{"internalType":"bytes32[]","name":"pools","type":"bytes32[]"}],"name":"unxswapByOrderId","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"srcToken","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minReturn","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"bytes32[]","name":"pools","type":"bytes32[]"}],"name":"unxswapTo","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"components":[{"internalType":"uint256","name":"fromToken","type":"uint256"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"fromTokenAmount","type":"uint256"},{"internalType":"uint256","name":"minReturnAmount","type":"uint256"},{"internalType":"uint256","name":"deadLine","type":"uint256"}],"internalType":"struct IDexRouter.BaseRequest","name":"baseRequest","type":"tuple"},{"internalType":"bytes32[]","name":"pools","type":"bytes32[]"}],"name":"unxswapToWithBaseRequest","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]Contract Creation Code
608060405234801561001057600080fd5b50615ec480620000216000396000f3fe6080604052600436106100dd5760003560e01c806301617fab1461013457806303b87e5f1461014757806308298b5a1461016d5780630c307f76146101805780630d5f0e3b1461019357806344014e98146101a657806354fd4d50146101b9578063591b3d08146101fc5780636aa476451461020f57806373679b6b146102445780639871efa41461026657806398d2ac6214610279578063b80c2f091461028c578063b88154771461029f578063e0af3616146102b2578063e99bfa95146102d4578063f2c42696146102e7578063fa461e33146102fa57600080fd5b3661012f5732330361012d5760405162461bcd60e51b81526020600482015260146024820152731155120819195c1bdcda5d081c995a9958dd195960621b60448201526064015b60405180910390fd5b005b600080fd5b61012d610142366004614e10565b61031a565b61015a610155366004614eba565b61033d565b6040519081526020015b60405180910390f35b61015a61017b366004614f86565b6103ee565b61015a61018e366004614ff8565b6104d8565b61015a6101a136600461506a565b6106fa565b61015a6101b4366004614ff8565b610755565b3480156101c557600080fd5b506101ef6040518060400160405280600a81526020016976312e302e362d64616760b01b81525081565b60405161016491906150fd565b61015a61020a3660046156f9565b610873565b34801561021b57600080fd5b506102377370cbb871e8f30fc8ce23609e9e0ea87b6b222f5881565b60405161016491906157bb565b34801561025057600080fd5b50610237600080516020615def83398151915281565b61015a61027436600461506a565b610b71565b61012d6102873660046157cf565b610b8b565b61015a61029a36600461580e565b610cd0565b61015a6102ad366004614ff8565b610d2d565b3480156102be57600080fd5b50610237600080516020615e0f83398151915281565b61015a6102e23660046158c4565b610ef3565b61015a6102f5366004615974565b610f03565b34801561030657600080fd5b5061012d6103153660046159ce565b610f1d565b600160ff1b81166001600160801b03821661033784338484611167565b50505050565b60008760800135428110156103645760405162461bcd60e51b815260040161012490615a4d565b6040518b8152600080516020615e6f8339815191529060200160405180910390a16103df33808c61039a368e90038e018e615a75565b8c8c808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152506103da92508d91508e9050615a91565b61151d565b9b9a5050505050505050505050565b60405160a087901c8152600090600080516020615e6f8339815191529060200160405180910390a1600080610427600034118686611671565b9150915060006104368a61194d565b90506001600160a01b0381161561044d578061045d565b600080516020615e2f8339815191525b9050826001600160a01b0316816001600160a01b0316146104ba5760405162461bcd60e51b81526020600482015260176024820152760eadcf0e6eec2e07440e8ded6cadc40dad2e6dac2e8c6d604b1b6044820152606401610124565b6104ca83838b8b338c8c8c611959565b9a9950505050505050505050565b60008360800135428110156104ff5760405162461bcd60e51b815260040161012490615a4d565b826105405760405162461bcd60e51b815260206004820152601160248201527007061746873206d757374206265203e203607c1b6044820152606401610124565b604051878152600080516020615e6f8339815191529060200160405180910390a16001600160a01b038616156105765785610578565b335b9550600080610585611a21565b915091506000600760f91b878760008181106105a3576105a3615a9e565b90506020028101906105b59190615ab4565b608001351690506105e0836105ca8a3561194d565b6105da60408c0160208d01615ad4565b84611d15565b6105f96105f360408a0160208b01615ad4565b8a611efa565b945060008061062685338d8d6040013588600001518f60200160208101906106219190615ad4565b611f9b565b915091506106388a8a8a333387611fe5565b610657858c838d60200160208101906106519190615ad4565b886121a0565b508661067261066c60408d0160208e01615ad4565b8d611efa565b61067c9190615b07565b965089606001358710156106a25760405162461bcd60e51b815260040161012490615b20565b600080516020615e4f8339815191526106bb8b3561194d565b6106cb60408d0160208e01615ad4565b328d604001358b6040516106e3959493929190615b50565b60405180910390a150505050505095945050505050565b60405160a086901c8152600090600080516020615e6f8339815191529060200160405180910390a1600080610733600034118686612441565b91509150610747338984848b8b8b8b612713565b925050505b95945050505050565b600083608001354281101561077c5760405162461bcd60e51b815260040161012490615a4d565b604051878152600080516020615e6f8339815191529060200160405180910390a16000806107ae600034118787612441565b90925090506001600160a01b0382166107c7883561194d565b6001600160a01b03161480156107fd57506001600160a01b0381166107f26040890160208a01615ad4565b6001600160a01b0316145b6108455760405162461bcd60e51b81526020600482015260196024820152780eadcd2e6eec2e0ac667440e8ded6cadc40dad2e6dac2e8c6d603b1b6044820152606401610124565b61086633896001600160a01b031684848b604001358c606001358c8c612713565b9998505050505050505050565b600086608001514281101561089a5760405162461bcd60e51b815260040161012490615a4d565b60006108a9896000015161194d565b905073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeed196001600160a01b0382160161090f5760405162461bcd60e51b815260206004820152601460248201527324b73b30b634b21039b7bab931b2903a37b5b2b760611b6044820152606401610124565b6001600160a01b03841661095e5760405162461bcd60e51b8152602060048201526016602482015275726566756e64546f206973206164647265737328302960501b6044820152606401610124565b6001600160a01b0385166109a75760405162461bcd60e51b815260206004820152601060248201526f746f206973206164647265737328302960801b6044820152606401610124565b60008960400151116109f25760405162461bcd60e51b8152602060048201526014602482015273066726f6d546f6b656e416d6f756e7420697320360641b6044820152606401610124565b6040516370a0823160e01b81526000906001600160a01b038316906370a0823190610a219030906004016157bb565b602060405180830381865afa158015610a3e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a629190615b84565b905060005b8951811015610ac9578a60400151828b8381518110610a8857610a88615a9e565b6020026020010151610a9a9190615b9d565b610aa49190615bb4565b8a8281518110610ab657610ab6615a9e565b6020908102919091010152600101610a67565b5060408a0181905260208a0151610ae09087611efa565b9350610af08a8a8a30898b6127e3565b83610aff8b6020015188611efa565b610b099190615b07565b93508960600151841015610b2f5760405162461bcd60e51b815260040161012490615b20565b600080516020615e4f833981519152828b60200151328d6040015188604051610b5c959493929190615b50565b60405180910390a15050509695505050505050565b6000610b818686863387876103ee565b9695505050505050565b806080013542811015610bb05760405162461bcd60e51b815260040161012490615a4d565b600080610bbd843561194d565b90506001600160a01b038116600080516020615e2f833981519152148015610c0a5750600080516020615e0f833981519152610bff6040860160208701615ad4565b6001600160a01b0316145b15610c185760009150610cb8565b6001600160a01b038116600080516020615e0f833981519152148015610c635750600080516020615e2f833981519152610c586040860160208701615ad4565b6001600160a01b0316145b15610c715760019150610cb8565b60405162461bcd60e51b815260206004820152601c60248201527b29bbb0b82bb930b81d1034b73b30b634b2103a37b5b2b7103830b4b960211b6044820152606401610124565b610cc88686848760400135611167565b505050505050565b6000876080013542811015610cf75760405162461bcd60e51b815260040161012490615a4d565b6040518a8152600080516020615e6f8339815191529060200160405180910390a16104ca33808061039a368e90038e018e615a75565b6000836080013542811015610d545760405162461bcd60e51b815260040161012490615a4d565b604051878152600080516020615e6f8339815191529060200160405180910390a1600080610d86600034118787611671565b90925090506000610d97883561194d565b9050826001600160a01b0316816001600160a01b03161480610de157506001600160a01b038116158015610de157506001600160a01b038316600080516020615e2f833981519152145b610e2b5760405162461bcd60e51b815260206004820152601b60248201527a0eadcf0e6eec2e07440cce4dedaa8ded6cadc40dad2e6dac2e8c6d602b1b6044820152606401610124565b6001600160a01b038216610e4560408a0160208b01615ad4565b6001600160a01b03161480610e9357506000610e6760408a0160208b01615ad4565b6001600160a01b0316148015610e9357506001600160a01b038216600080516020615e2f833981519152145b610edb5760405162461bcd60e51b81526020600482015260196024820152780eadcf0e6eec2e07440e8dea8ded6cadc40dad2e6dac2e8c6d603b1b6044820152606401610124565b6104ca83838a604001358b60600135338e8d8d611959565b6000610b81868686868687610873565b6000610f1285338686866104d8565b90505b949350505050565b610fbe565b3d6000803e3d6000fd5b67a9059cbb70a0823160c01b815230816008015260206000602483600401855afa610f5957610f59610f22565b6000518015610f845760a435600483015260248201819052610f846020600060448582885af1610f89565b505050565b80610f9657610f96610f22565b600160005114601f3d11163d151780610fba57633c9fd93960e21b60005260046000fd5b5050565b604051601581017306ff0b40e9091053eee51fa1d482ce5d852f523360611b825260206000600484335afa610ff557610ff5610f22565b6020806004808501335afa61100c5761100c610f22565b60206040600460088501335afa61102557611025610f22565b600080600088136001811461104157602051925087915061104a565b60005192508891505b506001733819ef38dd499eb7273946d69836632e4573819f605a1b03198452606060002083527fe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b5460208401526001600160a01b03605585201692503383146110bd57635960139160e11b60005260046000fd5b60843592507306ff0b40e9091053eee51fa1d482ce5d852f523360611b84523083146001811461112f5782601486015283603486015233605486015281607486015261112a6020600060846010890160007370cbb871e8f30fc8ce23609e9e0ea87b6b222f585af1610f89565b61115c565b336010860152816030860152611152602060006044600c89016000885af1610f89565b61115c8386610f2c565b505050505050505050565b604051848152600080516020615e6f8339815191529060200160405180910390a1600081116111cd5760405162461bcd60e51b81526020600482015260126024820152710616d6f756e74206d757374206265203e20360741b6044820152606401610124565b6001600160a01b038316156111e257826111e4565b335b92506000806111f1611a21565b9150915060008461121057600080516020615e2f833981519152611220565b600080516020615e0f8339815191525b905060008561123d57600080516020615e0f83398151915261124d565b600080516020615e2f8339815191525b905061125c8483836000611d15565b60008061127186338b8a896000015188611f9b565b9150915087156113ef5760405163052f523360e11b81527370cbb871e8f30fc8ce23609e9e0ea87b6b222f5890630a5ea466906112d490600080516020615e0f833981519152903390600080516020615def833981519152908d90600401615bd6565b600060405180830381600087803b1580156112ee57600080fd5b505af1158015611302573d6000803e3d6000fd5b5050604051632e1a7d4d60e01b8152600481018a9052600080516020615def8339815191529250632e1a7d4d9150602401600060405180830381600087803b15801561134d57600080fd5b505af1158015611361573d6000803e3d6000fd5b505050506001600160a01b03821630146113ea576000826001600160a01b03164760405160006040518083038185875af1925050503d80600081146113c2576040519150601f19603f3d011682016040523d82523d6000602084013e6113c7565b606091505b50509050806113e85760405162461bcd60e51b815260040161012490615c00565b505b6114c9565b855161143d5786341461143d5760405162461bcd60e51b81526020600482015260166024820152751d985b1d59481b9bdd08195c5d585b08185b5bdd5b9d60521b6044820152606401610124565b600080516020615e0f8339815191526001600160a01b031663d0e30db0886040518263ffffffff1660e01b81526004016000604051808303818588803b15801561148657600080fd5b505af115801561149a573d6000803e3d6000fd5b505050506001600160a01b038316301490506114c9576114c9600080516020615e0f8339815191528389612b7d565b60006114d8878b84878a6121a0565b9050600080516020615e4f8339815191528585328b6114f78682615b07565b604051611508959493929190615b50565b60405180910390a15050505050505050505050565b60006001600160a01b038516156115345784611536565b335b9450600080611543611a21565b915091506000600760f91b8560008151811061156157611561615a9e565b602002602001015160008151811061157b5761157b615a9e565b6020026020010151608001511690506115a68361159b896000015161194d565b896020015184611d15565b6115b4876020015189611efa565b93506000806115d3858d8c8c6040015188600001518e60200151611f9b565b915091506115e58989898f8f876127e3565b6115f6858b838c60200151886121a0565b5050508361160888602001518a611efa565b6116129190615b07565b935086606001518410156116385760405162461bcd60e51b815260040161012490615b20565b600080516020615e4f833981519152611654886000015161194d565b8860200151328a6040015188604051610b5c959493929190615b50565b600080826116915760405162461bcd60e51b815260040161012490615c36565b60006001600160a01b03858560008181106116ae576116ae615a9e565b9050602002013560001c1690506000600160ff1b868660008181106116d5576116d5615a9e565b9050602002013560001c166000141590508061175257816001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015611729573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061174d9190615c6c565b6117b4565b816001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015611790573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117b49190615c6c565b93506001600160a01b038416600080516020615e0f8339815191521480156117d95750865b156117f057600080516020615e2f83398151915293505b600086866117ff600182615b07565b81811061180e5761180e615a9e565b60200291909101359150506001600160a01b038116600160ff1b821615158061189857816001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561186f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118939190615c6c565b6118fa565b816001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156118d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118fa9190615c6c565b9550600160fe1b831615156001600160a01b038716600080516020615e0f8339815191521480156119285750805b1561193f57600080516020615e2f83398151915296505b505050505050935093915050565b6001600160a01b031690565b60006001600160a01b038416156119705783611972565b335b935060008061197f611a21565b91509150611990828c8c6000611d15565b61199a8a87611efa565b92506119ae87878d8d8d8d8b8b8a8a612bad565b826119b98b88611efa565b6119c39190615b07565b9250878310156119e55760405162461bcd60e51b815260040161012490615b20565b600080516020615e4f8339815191528b8b328c87604051611a0a959493929190615b50565b60405180910390a150505b98975050505050505050565b6040805161010081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101919091526040805160c081018252600080825260208201819052918101829052606081018290526080810182905260a081019190915260203603356001600160d01b031981166522220afc2bbb60d01b8114651111057e155560d11b821417651111057e155560d11b8214651e51057e155560d11b83141785526522220afc2bbb60d01b8214653ca20afc2bbb60d01b831417856020015265ffffffffffff60a01b831660a01c85604001526001600160a01b0383168560600152604036033592506000600160ff1b8416118560e001526001600160a01b03831685608001526001811460018114611b5d5760008660a0015260008660c00152611b88565b6060360335935065ffffffffffff60a01b841660a01c8660a001526001600160a01b0384168660c001525b506000925060018103611b9a57606092505b50653ca20afc2bbb60d01b8114651e51057e155560d11b82141715611bbe57604091505b602082013603356001600160d01b031981169150653bbbbbbb911160d11b82146577777777111160d01b831417845265ffffffffffff60a01b811660a01c84602001526001600160a01b03811684604001526040830136033590506001600160a01b0381168460600152653bbbbbbb911160d11b821460018114611c4f576000856080015260008560a00152611c7c565b60608401360335915065ffffffffffff60a01b821660a01c85608001526001600160a01b0382168560a001525b50505050816000015180611c91575081602001515b80611c9a575080515b15611d11577f6895551786bbb86042fcc29bf0c6657e90b7d1e78721946cb40dde1d3508854582604001518360a001518460e0015184602001518560800151604051611d08959493929190948552602085019390935290151560408401526060830152608082015260a00190565b60405180910390a15b9091565b600160fb1b8116151580611d2e5750600160fa1b811615155b80611d3e5750600160f91b811615155b8015611d48575083515b15611da15760405162461bcd60e51b815260206004820152602360248201527f46726f6d20746f6b656e20636f6d6d697373696f6e206e6f7420737570706f726044820152621d195960ea1b6064820152608401610124565b816001600160a01b0316836001600160a01b031603611df35760405162461bcd60e51b815260206004820152600e60248201526d496e76616c696420746f6b656e7360901b6044820152606401610124565b83518015611e02575083602001515b15611e4e5760405162461bcd60e51b815260206004820152601c60248201527b24b73b30b634b21031b7b6b6b4b9b9b4b7b7103234b932b1ba34b7b760211b6044820152606401610124565b83518015611e715750826001600160a01b031684608001516001600160a01b0316145b80611e9d575083602001518015611e9d5750816001600160a01b031684608001516001600160a01b0316145b80611eb457508351158015611eb457508360200151155b6103375760405162461bcd60e51b8152602060048201526017602482015276496e76616c696420636f6d6d697373696f6e20696e666f60481b6044820152606401610124565b6000611f1d565b62461bcd60e51b600052600160e51b6020528060405250806000fd5b600080516020615e2f833981519152831460018114611f8f57604051602481016040526370a0823160e01b815283600482015260206000602483885afa905080611f8457611f846058740519d95d0818985b185b98d953d98819985a5b195960421b611f01565b506000519150611f94565b823191505b5092915050565b600080876020015180611fab5750835b15611fc457309150611fbd8330611efa565b9050611fc8565b8591505b875115611fda57611fda888887612bf5565b965096945050505050565b6000611ff636889003880188615a75565b90506000612007826000015161194d565b9050600061203c8888600081811061202157612021615a9e565b90506020028101906120339190615ab4565b6080013561194d565b9050612050826001600160a01b03166130ea565b156120f9576001600160a01b038116600080516020615e0f8339815191521461208b5760405162461bcd60e51b815260040161012490615c89565b600080516020615e0f8339815191526001600160a01b031663d0e30db084604001516040518263ffffffff1660e01b81526004016000604051808303818588803b1580156120d857600080fd5b505af11580156120ec573d6000803e3d6000fd5b505050505030955061216a565b816001600160a01b0316816001600160a01b03161461212a5760405162461bcd60e51b815260040161012490615c89565b341561216a5760405162461bcd60e51b815260206004820152600f60248201526e076616c7565206d757374206265203608c1b6044820152606401610124565b612192868587866040015161218b88602001516001600160a01b03166130ea565b8d8d613106565b61115c836020015185613189565b600085602001511580156121b357508151155b156121c05750600061074c565b60006121cc8430611efa565b9050848110156122165760405162461bcd60e51b815260206004820152601560248201527434b73b30b634b2103130b630b731b29030b33a32b960591b6044820152606401610124565b60006122228683615b07565b90508760200151156122f5576301c9c3808860a0015189604001516122479190615cb6565b11156122935760405162461bcd60e51b815260206004820152601b60248201527a195c9c9bdc8818dbdb5b5a5cdcda5bdb881c985d19481b1a5b5a5d602a1b6044820152606401610124565b6000633b9aca008960a001518a604001516122ae9190615cb6565b6122b89084615b9d565b6122c29190615bb4565b90506122e4600187838c604001518d606001518e60a001518f60c0015161341f565b9250826122f18183615b07565b9150505b835180156123065750836060015181115b1561242b576064846020015111156123585760405162461bcd60e51b8152602060048201526015602482015274195c9c9bdc881d1c9a5b481c985d19481b1a5b5a5d605a1b6044820152606401610124565b6103e8846080015111156123a25760405162461bcd60e51b81526020600482015260116024820152706572726f7220636861726765207261746560781b6044820152606401610124565b60008460600151826123b49190615b07565b905060006103e88660200151846123cb9190615b9d565b6123d59190615bb4565b9050808211156123e3578091505b6124106000888489608001516103e86123fc9190615b07565b8a604001518b608001518c60a0015161341f565b61241a8286615cb6565b94506124268284615b07565b925050505b612436858883613722565b505095945050505050565b600080826124615760405162461bcd60e51b815260040161012490615c36565b60006001600160a01b038585600081811061247e5761247e615a9e565b905060200201351690506000600160ff1b868660008181106124a2576124a2615a9e565b905060200201351660001490508061251b57816001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156124f2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125169190615c6c565b61257d565b816001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015612559573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061257d9190615c6c565b93506001600160a01b038416600080516020615e0f8339815191521480156125a25750865b156125b957600080516020615e2f83398151915293505b600086866125c8600182615b07565b8181106125d7576125d7615a9e565b60200291909101359150506001600160a01b038116600160ff1b8216158061266057816001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015612637573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061265b9190615c6c565b6126c2565b816001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561269e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126c29190615c6c565b9550600160fd1b831615156001600160a01b038716600080516020615e0f8339815191521480156119285750801561193f57600080516020615e2f8339815191529650505050505050935093915050565b6000806001600160a01b038916156127335761272e8961194d565b612735565b335b9050600080612742611a21565b91509150612753828b8b6000611d15565b61275d8984611efa565b93506127708c848a8a8d8b8b8989613767565b8361277b8a85611efa565b6127859190615b07565b9350868410156127a75760405162461bcd60e51b815260040161012490615b20565b600080516020615e4f8339815191528a8a328b886040516127cc959493929190615b50565b60405180910390a150505098975050505050505050565b855186906000906127f39061194d565b90506127fe816130ea565b156128f057600080516020615e0f8339815191526001600160a01b031663d0e30db083604001516040518263ffffffff1660e01b81526004016000604051808303818588803b15801561285057600080fd5b505af1158015612864573d6000803e3d6000fd5b5050505050600080516020615e0f8339815191526001600160a01b03166128c28760008151811061289757612897615a9e565b60200260200101516000815181106128b1576128b1615a9e565b60200260200101516080015161194d565b6001600160a01b0316146128e85760405162461bcd60e51b815260040161012490615c89565b309450612936565b806001600160a01b03166129108760008151811061289757612897615a9e565b6001600160a01b0316146129365760405162461bcd60e51b815260040161012490615c89565b6000805b88518110156129725788818151811061295557612955615a9e565b6020026020010151826129689190615cb6565b915060010161293a565b5082604001518111156129e55760405162461bcd60e51b815260206004820152603560248201527f526f7574653a206e756d626572206f6620626174636865732073686f756c64206044820152741899480f0f48199c9bdb551bdad95b905b5bdd5b9d605a1b6064820152608401610124565b508551875114612a295760405162461bcd60e51b815260206004820152600f60248201526e0d8cadccee8d040dad2e6dac2e8c6d608b1b6044820152606401610124565b60005b8651811015612b64578015612b075786600081518110612a4e57612a4e615a9e565b6020026020010151600081518110612a6857612a68615a9e565b602002602001015160800151878281518110612a8657612a86615a9e565b6020026020010151600081518110612aa057612aa0615a9e565b60200260200101516080015114612b075760405162461bcd60e51b815260206004820152602560248201527f496e636f6e73697374656e742066726f6d546f6b656e206163726f7373206261604482015264746368657360d81b6064820152608401610124565b612b5c868686612b2387602001516001600160a01b03166130ea565b8c8681518110612b3557612b35615a9e565b60200260200101518c8781518110612b4f57612b4f615a9e565b602002602001015161379c565b600101612a2c565b50612b73826020015184613189565b5050505050505050565b612b908363a9059cbb60e01b84846138e6565b610f845760405163fb7f507960e01b815260040160405180910390fd5b600080612bc2848d8d8b87600001518e611f9b565b90925090508b612bd78b8a8a8a8a8689613939565b50612be5858d848d886121a0565b5050505050505050505050505050565b612ed2565b80820281158282048414178402612c195763ad251c276000526004601cfd5b9290920492915050565b600082821015612c3b576346e72d036000526004601cfd5b500390565b60008060008085855af180610f8457610f8460607c1c20636f6d6d697373696f6e2077697468206574686572206572726f72611f01565b6040516084810160405263052f523360e11b815281600482015282602482015283604482015284606482015260008060848360007370cbb871e8f30fc8ce23609e9e0ea87b6b222f585af1905080612ceb57612ceb60577304d8db185a5b481d1bdad95b9cc819985a5b1959604a1b611f01565b5050505050565b600080604051604881016040526ba9059cbba9059cbb70a0823160a01b815230600c82015260206000602460088401875afa80612d4c57612d4c6058740519d95d0818985b185b98d953d98819985a5b195960421b611f01565b600051898801612d77670de0b6b3a764000083612d7284670de0b6b3a76400008e612bfa565b612bfa565b95505080851115612da657612da6605975055a5b9d985b1a5908185b5bdd5b9d0c54d8d85b1959603a1b611f01565b8660088401528460288401526020600060446004860160008a5af1915081601f3d1160016000511416151615612ddf573d863b15171591505b81612e0c57612e0c605f7c1b7472616e7366657220746f6b656e2072656665726572206661696c00611f01565b8815612e8157612e1c8582612c23565b93508860048401528360248401526020600060448560008a5af1915081601f3d1160016000511416151615612e54573d863b15171591505b81612e8157612e81605f7c1b7472616e7366657220746f6b656e2072656665726572206661696c00611f01565b5050509550959350505050565b604051606081016040528181528260208201528360408201527f0d3b1268ca3dbb6d3d8a0ea35f44f8f9d58cf578d732680b71b6904fb2733e0d606082a150505050565b608083015160e084015160a08501516040860151601090920281151501600080516020615e2f8339815191528414610100020191600091829182918291906301c9c3808282011115612f4657612f46605f7c1b6572726f7220636f6d6d697373696f6e2072617465206c696d697400611f01565b60608b015160c08c01519096509450818101633b9aca00038983028190049450898202049250866101008114612fd1576101018114612ff4576101108114612fd1576101118114612ff457801561303a5760018114613051576010811461307f57601181146130ab57612fcc60526e0e696e76616c69642073746174757360701b611f01565b6130dc565b612fdb8588612c40565b612fcc8786600080516020615e2f833981519152612e8e565b612ffe8588612c40565b6130178786600080516020615e2f833981519152612e8e565b6130218487612c40565b612fcc8685600080516020615e2f833981519152612e8e565b61304685888d8c612c77565b612fcc87868b612e8e565b61305d85888d8c612c77565b61306887868b612e8e565b61307484878d8c612c77565b612fcc86858b612e8e565b61308b85308d8c612c77565b613099600080858a8d612cf2565b506130a588828c612e8e565b506130dc565b6130b9848601308d8c612c77565b6130c68287858a8d612cf2565b6130d189838d612e8e565b612be588828d612e8e565b505050505050505050505050565b6001600160a01b0316600080516020615e2f8339815191521490565b80600061312c8288604080518082019091529182526001600160a01b0316602082015290565b905060005b8281101561317d578015613143573099505b6131758a8a89848a8a8a8881811061315d5761315d615a9e565b905060200281019061316f9190615ab4565b886140f5565b600101613131565b50505050505050505050565b61319b826001600160a01b03166130ea565b1561338c576040516370a0823160e01b8152600090600080516020615e0f833981519152906370a08231906131d49030906004016157bb565b602060405180830381865afa1580156131f1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132159190615b84565b905080156133025760405163a9059cbb60e01b8152600080516020615def833981519152600482015260248101829052600080516020615e0f8339815191529063a9059cbb906044016020604051808303816000875af115801561327d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132a19190615cc9565b50604051632e1a7d4d60e01b815260048101829052600080516020615def83398151915290632e1a7d4d90602401600060405180830381600087803b1580156132e957600080fd5b505af11580156132fd573d6000803e3d6000fd5b505050505b6001600160a01b0382163014610f8457478015610337576000836001600160a01b03168260405160006040518083038185875af1925050503d8060008114613366576040519150601f19603f3d011682016040523d82523d6000602084013e61336b565b606091505b5050905080612ceb5760405162461bcd60e51b815260040161012490615c00565b6001600160a01b0381163014610fba576040516370a0823160e01b81526000906001600160a01b038416906370a08231906133cb9030906004016157bb565b602060405180830381865afa1580156133e8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061340c9190615b84565b90508015610f8457610f84838383612b7d565b613591565b60008060008085855af180610f8457610f84605571045cd95b9908195d1a195c8819985a5b1959605a1b611f01565b6040516044810160405263a9059cbb60e01b8152826004820152836024820152602060006044836000865af1905080601f3d116001600051141615161561349c5750803b153d17155b8061033757610337605975055d1c985b9cd9995c881d1bdad95b8819985a5b1959603a1b611f01565b604051606081016040528181528260208201528360408201527ff171268de859ec269c52bbfac94dcb7715e784de194342abb284bf34fd30b32d606082a150505050565b604051606081016040528181528260208201528360408201527f7bec7d55a62a7a7b8068f1533e2a3bbf727b3e2e57f30c576fe159da60e09a65606082a150505050565b604051606081016040528181528260208201528360408201527ffd08115c8e43d2a49d95ee18d7f69b8bbac60bd368c73cf22d30664a22a0626d606082a150505050565b6001600160a01b03928316921681840185850204808603601089151502600080516020615e2f83398151915289140180601181146136015760108114613653576001811461368b5780156136dd576135fc60526e0e696e76616c69642073746174757360701b611f01565b613715565b871561362a576136118488613424565b61362a8785600080516020615e2f8339815191526134c5565b85156135fc5761363a8386613424565b6135fc8584600080516020615e2f8339815191526134c5565b871561366f5761366484888c613453565b61366f87858c6134c5565b85156135fc5761368083868c613453565b6135fc85848c6134c5565b87156136b45761369b8488613424565b6136b48785600080516020615e2f833981519152613509565b85156135fc576136c48386613424565b6135fc8584600080516020615e2f83398151915261354d565b87156136f9576136ee84888c613453565b6136f987858c613509565b85156137155761370a83868c613453565b61371585848c61354d565b5050505050505050505050565b600080516020615e2f8339815191528314600181146137545761374f826001600160a01b03851686613453565b610337565b610337826001600160a01b038516613424565b60008061377c848c8c8c87600001518c611f9b565b9150915061378e8b838b8b8a8a6145d6565b506130dc848b838a876121a0565b60006137b4826000815181106128b1576128b1615a9e565b905060008060008451905060005b818110156137155780156137f7576137e58682815181106128b1576128b1615a9e565b94506137f18530611efa565b9650309a505b30613803600184615b07565b8214801561380f575088155b1561381b5750886138b3565b613826600184615b07565b8210801561385c57508661383b836001615cb6565b8151811061384b5761384b615a9e565b602002602001015160200151516001145b156138ae578661386d836001615cb6565b8151811061387d5761387d615a9e565b60200260200101516020015160008151811061389b5761389b615a9e565b60200260200101519050600194506138b3565b600094505b6138da8c8c838b8b87815181106138cc576138cc615a9e565b602002602001015189614934565b508392506001016137c2565b60006040518481528360048201528260248201526020600060448360008a5af19150508015610f15573d801561392857600160005114601f3d11169150613930565b6000863b1191505b50949350505050565b6000613b60565b828152600060206000600484600401865afa613975576139756054700419d95d081d1bdad95b8819985a5b195960621b611f01565b505060005192915050565b6770a082310dfe168160c01b815260008060206000600485600401875afa6139c3576139c3605672049d1bdad95b8c0818d85b1b0819985a5b195960521b611f01565b600051915083836004015260206000602485855afa613a0057613a006059750558985b185b98d953d98818d85b1b0819985a5b1959603a1b611f01565b60005190509250929050565b6770a08231d21220a760c01b815260008060206000600485600401875afa6139c3576139c3605672049d1bdad95b8c4818d85b1b0819985a5b195960521b611f01565b668b0367c240bc6b60c21b8152600060406000600484600401875afa613a9257613a92605874051c995cd95c9d995cc818d85b1b0819985a5b195960421b611f01565b600051602051868015613abe578915613ab657613aaf8786613a0c565b8390039650505b909190613ad5565b8815613ad557613ace8786613980565b8490039650505b50668b0367c240bc6b60c21b8452898502633b9aca009290920282019102049050848015613b0f5781600484015260006024840152613b1d565b600060048401528160248401525b50886044830152608060648301526000608483015260008060a4846000885af1611a1557611a15605470041cddd85c0818d85b1b0819985a5b195960621b611f01565b846020850281018580613b8757613b87604e6b0b656d70747920706f6f6c7360901b611f01565b5060405182358b600080516020615e2f8339815191521460018114613c40573415613bcc57613bcc60557111696e76616c6964206d73672e76616c756560581b611f01565b63052f523360e11b83528c60048401528760248401526001600160a01b03821660448401528b606484015260008060848560007370cbb871e8f30fc8ce23609e9e0ea87b6b222f585af1613c3b57613c3b6056720498db185a5b481d1bdad95b8819985a5b195960521b611f01565b613d0d565b60018c341003613c6a57613c6a60557111696e76616c6964206d73672e76616c756560581b611f01565b670a9059cbbd0e30db60c41b835260008060048086018f600080516020615e0f8339815191525af1613cb757613cb76056720499195c1bdcda5d081155120819985a5b195960521b611f01565b6001600160a01b03821683600401528b8360240152602060006044856000600080516020615e0f8339815191525af1613d0d57613d0d605874051d1c985b9cd9995c8815d155120819985a5b195960421b611f01565b508a9450602084015b83811015613d6c578035613d606001600160a01b03821663ffffffff60a01b851660a01c600160fd1b8616600160fc1b8716600160ff1b88166001600160a01b0389168d8b613a4f565b96509150602001613d16565b5060009350600160fe1b81168015613eaf57600080516020615e2f8339815191529450613dc63063ffffffff60a01b841660a01c600160fd1b8516600160fc1b8616600160ff1b87166001600160a01b0388168c8a613a4f565b9550672e1a7d4da9059cbb60c01b8352600080516020615def8339815191526008840152856028840152602060006044856004016000600080516020615e0f8339815191525af1613e3457613e34605874051d1c985b9cd9995c8815d155120819985a5b195960421b611f01565b856004840152602060006024856000600080516020615def8339815191525af1613e7a57613e7a60577304ddda5d1a191c985dc81155120819985a5b1959604a1b611f01565b600080600080898b5af1613eaa57613eaa60577304dd1c985b9cd9995c881155120819985a5b1959604a1b611f01565b6140e5565b60009350600160ff1b82168015613f5d57600160fc1b831615613f58576770a082310dfe168160c01b8452602060006004866004016001600160a01b0387165afa613f1557613f15605672049d1bdad95b8c0818d85b1b0819985a5b195960521b611f01565b600051955087846004015260206000602486895afa613f5257613f52605675055d1bdad95b8c0818985b185b98d94819985a5b1959603a1b611f01565b60005194505b613ff5565b600160fd1b831615613ff5576770a08231d21220a760c01b8452602060006004866004016001600160a01b0387165afa613fb257613fb2605672049d1bdad95b8c4818d85b1b0819985a5b195960521b611f01565b600051955087846004015260206000602486895afa613fef57613fef605975055d1bdad95b8c4818985b185b98d94819985a5b1959603a1b611f01565b60005194505b5061402d8763ffffffff60a01b841660a01c600160fd1b8516600160fc1b8616600160ff1b87166001600160a01b0388168c8a613a4f565b9550846000106001811461409657600160ff1b8316801561406e576140676770a082310dfe168160c01b6001600160a01b03861687613940565b9650614090565b61408d6770a08231d21220a760c01b6001600160a01b03861687613940565b96505b506140e3565b6770a082310dfe168160c01b845287846004015260206000602486895afa6140db576140db6058740519d95d0818985b185b98d953d98819985a5b195960421b611f01565b846000510396505b505b5050505050979650505050505050565b6000806000614107856080013561194d565b905060006141158680615ce6565b90501161415e5760405162461bcd60e51b8152602060048201526017602482015276065646765206c656e677468206d757374206265203e203604c1b6044820152606401610124565b61416b6040860186615ce6565b90506141778680615ce6565b905014801561419e575061418e6060860186615ce6565b905061419a8680615ce6565b9050145b80156141c257506141b26020860186615ce6565b90506141be8680615ce6565b9050145b6142055760405162461bcd60e51b81526020600482015260146024820152730e0c2e8d040d8cadccee8d040dad2e6dac2e8c6d60631b6044820152606401610124565b86156142c5576040516370a0823160e01b81526001600160a01b038216906370a08231906142379030906004016157bb565b602060405180830381865afa158015614254573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142789190615b84565b9750600088116142c55760405162461bcd60e51b815260206004820152601860248201527706e6f64652062616c616e6365206d757374206265203e20360441b6044820152606401610124565b60005b6142d28680615ce6565b90508110156137155760008080806142ed60408b018b615ce6565b868181106142fd576142fd615a9e565b9050602002013560001b905061ffff60a01b811660a01c915060ff60b81b811660b81c935060ff60b01b811660b01c92508b841461437c5760405162461bcd60e51b815260206004820152601c60248201527b1b9bd919481a5b9c1d5d125b99195e081a5b98dbdb9cda5cdd195b9d60221b6044820152606401610124565b828410801561438c575088518311155b6143d25760405162461bcd60e51b81526020600482015260176024820152766e6f646520696e646578206f7574206f662072616e676560481b6044820152606401610124565b6143dc8289615cb6565b975060016143ea8b80615ce6565b6143f5929150615b07565b85036144485787612710146144485760405162461bcd60e51b81526020600482015260196024820152780746f74616c576569676874206d75737420626520313030303603c1b6044820152606401610124565b50600060016144578b80615ce6565b614462929150615b07565b850361447957614472878e615b07565b905061449f565b612710614486838f615b9d565b6144909190615bb4565b905061449c8188615cb6565b96505b80156144e6576144e68f6144b660208d018d615ce6565b888181106144c6576144c6615a9e565b90506020020160208101906144db9190615ad4565b8c6080013584614ac2565b5087513090831480156144f757508a155b156144ff57508c5b6145c761450f60408c018c615ce6565b8781811061451f5761451f615a9e565b602002919091013590506145338c80615ce6565b8881811061454357614543615a9e565b90506020020160208101906145589190615ad4565b61456560608e018e615ce6565b8981811061457557614575615a9e565b90506020028101906145879190615d2f565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250505060208e0151869150614b9f565b508360010193505050506142c8565b600061486f565b6000856001600160ff1b0310156145ff57630b3f79fd60e41b60005260046000fd5b604051600160ff1b8616156001600160a01b038716816001811461469357630251596160e31b845260048401868152600060208201528a604082015273fffd8963efd1fc6a506488495d951d5263988d25606082015260a06080820152604060a08201528760c08201528860e082015250600080610104866000865af1806146875760206000fd5b5060206000803e6146f6565b630251596160e31b845260048401868152600160208201528a60408201526401000276a4606082015260a06080820152604060a08201528760c08201528860e082015250600080610104866000865af1806146ee5760206000fd5b5060208060003e5b505050506000519050600160ff1b81101561471c576322323ba760e21b60005260046000fd5b1960010195945050505050565b60018134100361474457631841b4e160e01b60005260046000fd5b60008060008084600080516020615e0f8339815191525af180610fba57610fba60577304d5d155120819195c1bdcda5d0819985a5b1959604a1b611f01565b60405160048101672e1a7d4da9059cbb60c01b8252600080516020615def83398151915260048201528360248201526000806044836000600080516020615e0f8339815191525af19050806147f5576147f5605874051d1c985b9cd9995c881dd95d1a0819985a5b195960421b611f01565b8360048301526000806024846000600080516020615def8339815191525af190508061483e5761483e605874051dda5d1a191c985dc81dd95d1a0819985a5b195960421b611f01565b60008060008087875af190508061033757610337605571045cd95b9908195d1a195c8819985a5b1959605a1b611f01565b82601f19602084028201018380614891576333f3e07b60e11b60005260046000fd5b50886000341180156148aa576148a689614729565b309a505b5087606052825b828110156148d4576148c7898235848e306145dd565b309b5098506020016148b1565b506000600160fd1b83351611925082600181146148f657801561491557614926565b614904898435848e306145dd565b9450614910858b614783565b614926565b614923898435848e8e6145dd565b94505b505050509695505050505050565b6000805b835151811015612b735760008460400151828151811061495a5761495a615a9e565b602090810291909101015190506001600160a01b038116600160ff1b821661ffff60a084901c1661498b8187615cb6565b88515190965061499d90600190615b07565b8503614a0457612710861115614a045760405162461bcd60e51b815260206004820152602660248201527f746f74616c5765696768742063616e206e6f7420657863656564203130303030604482015265081b1a5b5a5d60d21b6064820152608401610124565b86614a635760008161271014614a3057612710614a21838c615b9d565b614a2b9190615bb4565b614a32565b895b9050614a618d8a602001518881518110614a4e57614a4e615a9e565b60200260200101518b6080015184614ac2565b505b50614aac8188600001518681518110614a7e57614a7e615a9e565b60200260200101518b858b606001518981518110614a9e57614a9e615a9e565b60200260200101518f614bc7565b5050508080614aba90615d75565b915050614938565b6001600160a01b038216600760f91b8316601f60fb1b8101614ae5575050610337565b600160fa1b8103614b0257614afb828685612b7d565b5050610337565b600160f91b8103614b14575050610337565b306001600160a01b03871603614b3457614b2f828685612b7d565b610cc8565b60405163052f523360e11b81527370cbb871e8f30fc8ce23609e9e0ea87b6b222f5890630a5ea46690614b719085908a908a908990600401615bd6565b600060405180830381600087803b158015614b8b57600080fd5b505af115801561317d573d6000803e3d6000fd5b600160ff1b85166001600160a01b038616614bbe828786848988614bc7565b50505050505050565b8515614ccc57600080866001600160a01b0316636f7929f260e01b878787604051602401614bf793929190615d8e565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614c456001600160a01b038616650f2882bf0b3360d21b615cb6565b604051602001614c56929190615dba565b60408051601f1981840301815290829052614c7091615ddc565b6000604051808303816000865af19150503d8060008114614cad576040519150601f19603f3d011682016040523d82523d6000602084013e614cb2565b606091505b509150915081614cc557614cc581614dc0565b5050610cc8565b600080866001600160a01b03166330e6ae3160e01b878787604051602401614cf693929190615d8e565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614d446001600160a01b038616650f2882bf0b3360d21b615cb6565b604051602001614d55929190615dba565b60408051601f1981840301815290829052614d6f91615ddc565b6000604051808303816000865af19150503d8060008114614dac576040519150601f19603f3d011682016040523d82523d6000602084013e614db1565b606091505b509150915081612b7357612b73815b805115614dcf57805160208201fd5b60405162461bcd60e51b81526020600482015260136024820152721859185c1d1bdc8818d85b1b0819985a5b1959606a1b6044820152606401610124565b50565b60008060408385031215614e2357600080fd5b50508035926020909101359150565b6001600160a01b0381168114614e0d57600080fd5b8035614e5281614e32565b919050565b600060a08284031215614e6957600080fd5b50919050565b60008083601f840112614e8157600080fd5b5081356001600160401b03811115614e9857600080fd5b6020830191508360208260051b8501011115614eb357600080fd5b9250929050565b60008060008060008060008060006101408a8c031215614ed957600080fd5b8935985060208a0135614eeb81614e32565b9750614efa8b60408c01614e57565b965060e08a01356001600160401b0380821115614f1657600080fd5b614f228d838e01614e6f565b90985096506101008c0135915080821115614f3c57600080fd5b614f488d838e01614e6f565b90965094506101208c0135915080821115614f6257600080fd5b50614f6f8c828d01614e6f565b915080935050809150509295985092959850929598565b60008060008060008060a08789031215614f9f57600080fd5b8635955060208701359450604087013593506060870135614fbf81614e32565b925060808701356001600160401b03811115614fda57600080fd5b614fe689828a01614e6f565b979a9699509497509295939492505050565b6000806000806000610100868803121561501157600080fd5b85359450602086013561502381614e32565b93506150328760408801614e57565b925060e08601356001600160401b0381111561504d57600080fd5b61505988828901614e6f565b969995985093965092949392505050565b60008060008060006080868803121561508257600080fd5b85359450602086013593506040860135925060608601356001600160401b0381111561504d57600080fd5b60005b838110156150c85781810151838201526020016150b0565b50506000910152565b600081518084526150e98160208601602086016150ad565b601f01601f19169290920160200192915050565b60208152600061511060208301846150d1565b9392505050565b634e487b7160e01b600052604160045260246000fd5b60405160a081016001600160401b038111828210171561514f5761514f615117565b60405290565b60405161014081016001600160401b038111828210171561514f5761514f615117565b604051601f8201601f191681016001600160401b03811182821017156151a0576151a0615117565b604052919050565b600060a082840312156151ba57600080fd5b6151c261512d565b90508135815260208201356151d681614e32565b8060208301525060408201356040820152606082013560608201526080820135608082015292915050565b60006001600160401b0382111561521a5761521a615117565b5060051b60200190565b600082601f83011261523557600080fd5b8135602061524a61524583615201565b615178565b82815260059290921b8401810191818101908684111561526957600080fd5b8286015b84811015615284578035835291830191830161526d565b509695505050505050565b600082601f8301126152a057600080fd5b813560206152b061524583615201565b82815260059290921b840181019181810190868411156152cf57600080fd5b8286015b848110156152845780356152e681614e32565b83529183019183016152d3565b600082601f83011261530457600080fd5b81356001600160401b0381111561531d5761531d615117565b615330601f8201601f1916602001615178565b81815284602083860101111561534557600080fd5b816020850160208301376000918101602001919091529392505050565b600082601f83011261537357600080fd5b8135602061538361524583615201565b82815260059290921b840181019181810190868411156153a257600080fd5b8286015b848110156152845780356001600160401b038111156153c55760008081fd5b6153d38986838b01016152f3565b8452509183019183016153a6565b60006153ef61524584615201565b838152905060208101600584901b830185101561540b57600080fd5b825b8460051b840181101561557b576001600160401b03813581101561543057600080fd5b8135850187601f82011261544357600080fd5b6154506152458235615201565b81358082526020808301929160051b8401018a81111561546f57600080fd5b602084015b8181101561556457858135111561548a57600080fd5b8035850160a0818e03601f190112156154a257600080fd5b6154aa61512d565b87602083013511156154bb57600080fd5b6154cd8e60208085013585010161528f565b815287604083013511156154e057600080fd5b6154f38e6020604085013585010161528f565b6020820152876060830135111561550957600080fd5b61551c8e60206060850135850101615224565b6040820152876080830135111561553257600080fd5b6155458e60206080850135850101615362565b606082015260a091909101356080820152845260209384019301615474565b50508552505060209283019291909101905061540d565b50509392505050565b600082601f83011261559557600080fd5b615110838335602085016153e1565b8015158114614e0d57600080fd5b8035614e52816155a4565b600082601f8301126155ce57600080fd5b813560206155de61524583615201565b82815260059290921b840181019181810190868411156155fd57600080fd5b8286015b848110156152845780356001600160401b03808211156156215760008081fd5b90880190610140828b03601f190181131561563c5760008081fd5b615644615155565b8784013581526040615657818601614e47565b898301526060615668818701614e47565b828401526080915061567b828701614e47565b818401525060a0808601358284015260c0915081860135818401525060e0808601358284015261010091508186013581840152506101206156bd8187016155b2565b838301529285013592848411156156d657600091508182fd5b6156e48e8b868901016152f3565b90830152508652505050918301918301615601565b600080600080600080610140878903121561571357600080fd5b61571d88886151a8565b955060a08701356001600160401b038082111561573957600080fd5b6157458a838b01615224565b965060c089013591508082111561575b57600080fd5b6157678a838b01615584565b955060e089013591508082111561577d57600080fd5b5061578a89828a016155bd565b93505061010087013561579c81614e32565b91506101208701356157ad81614e32565b809150509295509295509295565b6001600160a01b0391909116815260200190565b600080600060e084860312156157e457600080fd5b8335925060208401356157f681614e32565b91506158058560408601614e57565b90509250925092565b600080600080600080600080610120898b03121561582b57600080fd5b8835975061583c8a60208b01614e57565b965060c08901356001600160401b038082111561585857600080fd5b6158648c838d01614e6f565b909850965060e08b013591508082111561587d57600080fd5b6158898c838d01614e6f565b90965094506101008b01359150808211156158a357600080fd5b506158b08b828c01614e6f565b999c989b5096995094979396929594505050565b600080600080600061012086880312156158dd57600080fd5b6158e787876151a8565b945060a08601356001600160401b038082111561590357600080fd5b61590f89838a01615224565b955060c088013591508082111561592557600080fd5b61593189838a01615584565b945060e088013591508082111561594757600080fd5b50615954888289016155bd565b92505061010086013561596681614e32565b809150509295509295909350565b60008060008060e0858703121561598a57600080fd5b8435935061599b8660208701614e57565b925060c08501356001600160401b038111156159b657600080fd5b6159c287828801614e6f565b95989497509550505050565b600080600080606085870312156159e457600080fd5b843593506020850135925060408501356001600160401b0380821115615a0957600080fd5b818701915087601f830112615a1d57600080fd5b813581811115615a2c57600080fd5b886020828501011115615a3e57600080fd5b95989497505060200194505050565b6020808252600e908201526d149bdd5d194e88195e1c1a5c995960921b604082015260600190565b600060a08284031215615a8757600080fd5b61511083836151a8565b60006151103684846153e1565b634e487b7160e01b600052603260045260246000fd5b60008235609e19833603018112615aca57600080fd5b9190910192915050565b600060208284031215615ae657600080fd5b813561511081614e32565b634e487b7160e01b600052601160045260246000fd5b81810381811115615b1a57615b1a615af1565b92915050565b602080825260169082015275135a5b881c995d1d5c9b881b9bdd081c995858da195960521b604082015260600190565b6001600160a01b03958616815293851660208501529190931660408301526060820192909252608081019190915260a00190565b600060208284031215615b9657600080fd5b5051919050565b8082028115828204841417615b1a57615b1a615af1565b600082615bd157634e487b7160e01b600052601260045260246000fd5b500490565b6001600160a01b039485168152928416602084015292166040820152606081019190915260800190565b6020808252601c908201527b1d1c985b9cd9995c881b985d1a5d99481d1bdad95b8819985a5b195960221b604082015260600190565b6020808252601c908201527b0706f6f6c73206d7573742062652067726561746572207468616e20360241b604082015260600190565b600060208284031215615c7e57600080fd5b815161511081614e32565b6020808252601390820152720ccd2e4e6e8a8ded6cadc40dad2e6dac2e8c6d606b1b604082015260600190565b80820180821115615b1a57615b1a615af1565b600060208284031215615cdb57600080fd5b8151615110816155a4565b6000808335601e19843603018112615cfd57600080fd5b8301803591506001600160401b03821115615d1757600080fd5b6020019150600581901b3603821315614eb357600080fd5b6000808335601e19843603018112615d4657600080fd5b8301803591506001600160401b03821115615d6057600080fd5b602001915036819003821315614eb357600080fd5b600060018201615d8757615d87615af1565b5060010190565b6001600160a01b03848116825283166020820152606060408201819052600090610f12908301846150d1565b60008351615dcc8184602088016150ad565b9190910191825250602001919050565b60008251615aca8184602087016150ad56fe0000000000000000000000005703b683c7f928b721ca95da988d73a3299d4757000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1bb43f2da90e35f7b0cf38521ca95a49e68eb42fac49924930a5bd73cdf7576c7724394874fdd8ad13292ec739b441f85c6559f10dc4141b8d4c0fa4cbf55bdba26469706673582212206404d06f72c994e664bef3d395a67f53d8848bf8d4e626470b96f048d9ecdb0764736f6c63430008110033
Deployed Bytecode
0x6080604052600436106100dd5760003560e01c806301617fab1461013457806303b87e5f1461014757806308298b5a1461016d5780630c307f76146101805780630d5f0e3b1461019357806344014e98146101a657806354fd4d50146101b9578063591b3d08146101fc5780636aa476451461020f57806373679b6b146102445780639871efa41461026657806398d2ac6214610279578063b80c2f091461028c578063b88154771461029f578063e0af3616146102b2578063e99bfa95146102d4578063f2c42696146102e7578063fa461e33146102fa57600080fd5b3661012f5732330361012d5760405162461bcd60e51b81526020600482015260146024820152731155120819195c1bdcda5d081c995a9958dd195960621b60448201526064015b60405180910390fd5b005b600080fd5b61012d610142366004614e10565b61031a565b61015a610155366004614eba565b61033d565b6040519081526020015b60405180910390f35b61015a61017b366004614f86565b6103ee565b61015a61018e366004614ff8565b6104d8565b61015a6101a136600461506a565b6106fa565b61015a6101b4366004614ff8565b610755565b3480156101c557600080fd5b506101ef6040518060400160405280600a81526020016976312e302e362d64616760b01b81525081565b60405161016491906150fd565b61015a61020a3660046156f9565b610873565b34801561021b57600080fd5b506102377370cbb871e8f30fc8ce23609e9e0ea87b6b222f5881565b60405161016491906157bb565b34801561025057600080fd5b50610237600080516020615def83398151915281565b61015a61027436600461506a565b610b71565b61012d6102873660046157cf565b610b8b565b61015a61029a36600461580e565b610cd0565b61015a6102ad366004614ff8565b610d2d565b3480156102be57600080fd5b50610237600080516020615e0f83398151915281565b61015a6102e23660046158c4565b610ef3565b61015a6102f5366004615974565b610f03565b34801561030657600080fd5b5061012d6103153660046159ce565b610f1d565b600160ff1b81166001600160801b03821661033784338484611167565b50505050565b60008760800135428110156103645760405162461bcd60e51b815260040161012490615a4d565b6040518b8152600080516020615e6f8339815191529060200160405180910390a16103df33808c61039a368e90038e018e615a75565b8c8c808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152506103da92508d91508e9050615a91565b61151d565b9b9a5050505050505050505050565b60405160a087901c8152600090600080516020615e6f8339815191529060200160405180910390a1600080610427600034118686611671565b9150915060006104368a61194d565b90506001600160a01b0381161561044d578061045d565b600080516020615e2f8339815191525b9050826001600160a01b0316816001600160a01b0316146104ba5760405162461bcd60e51b81526020600482015260176024820152760eadcf0e6eec2e07440e8ded6cadc40dad2e6dac2e8c6d604b1b6044820152606401610124565b6104ca83838b8b338c8c8c611959565b9a9950505050505050505050565b60008360800135428110156104ff5760405162461bcd60e51b815260040161012490615a4d565b826105405760405162461bcd60e51b815260206004820152601160248201527007061746873206d757374206265203e203607c1b6044820152606401610124565b604051878152600080516020615e6f8339815191529060200160405180910390a16001600160a01b038616156105765785610578565b335b9550600080610585611a21565b915091506000600760f91b878760008181106105a3576105a3615a9e565b90506020028101906105b59190615ab4565b608001351690506105e0836105ca8a3561194d565b6105da60408c0160208d01615ad4565b84611d15565b6105f96105f360408a0160208b01615ad4565b8a611efa565b945060008061062685338d8d6040013588600001518f60200160208101906106219190615ad4565b611f9b565b915091506106388a8a8a333387611fe5565b610657858c838d60200160208101906106519190615ad4565b886121a0565b508661067261066c60408d0160208e01615ad4565b8d611efa565b61067c9190615b07565b965089606001358710156106a25760405162461bcd60e51b815260040161012490615b20565b600080516020615e4f8339815191526106bb8b3561194d565b6106cb60408d0160208e01615ad4565b328d604001358b6040516106e3959493929190615b50565b60405180910390a150505050505095945050505050565b60405160a086901c8152600090600080516020615e6f8339815191529060200160405180910390a1600080610733600034118686612441565b91509150610747338984848b8b8b8b612713565b925050505b95945050505050565b600083608001354281101561077c5760405162461bcd60e51b815260040161012490615a4d565b604051878152600080516020615e6f8339815191529060200160405180910390a16000806107ae600034118787612441565b90925090506001600160a01b0382166107c7883561194d565b6001600160a01b03161480156107fd57506001600160a01b0381166107f26040890160208a01615ad4565b6001600160a01b0316145b6108455760405162461bcd60e51b81526020600482015260196024820152780eadcd2e6eec2e0ac667440e8ded6cadc40dad2e6dac2e8c6d603b1b6044820152606401610124565b61086633896001600160a01b031684848b604001358c606001358c8c612713565b9998505050505050505050565b600086608001514281101561089a5760405162461bcd60e51b815260040161012490615a4d565b60006108a9896000015161194d565b905073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeed196001600160a01b0382160161090f5760405162461bcd60e51b815260206004820152601460248201527324b73b30b634b21039b7bab931b2903a37b5b2b760611b6044820152606401610124565b6001600160a01b03841661095e5760405162461bcd60e51b8152602060048201526016602482015275726566756e64546f206973206164647265737328302960501b6044820152606401610124565b6001600160a01b0385166109a75760405162461bcd60e51b815260206004820152601060248201526f746f206973206164647265737328302960801b6044820152606401610124565b60008960400151116109f25760405162461bcd60e51b8152602060048201526014602482015273066726f6d546f6b656e416d6f756e7420697320360641b6044820152606401610124565b6040516370a0823160e01b81526000906001600160a01b038316906370a0823190610a219030906004016157bb565b602060405180830381865afa158015610a3e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a629190615b84565b905060005b8951811015610ac9578a60400151828b8381518110610a8857610a88615a9e565b6020026020010151610a9a9190615b9d565b610aa49190615bb4565b8a8281518110610ab657610ab6615a9e565b6020908102919091010152600101610a67565b5060408a0181905260208a0151610ae09087611efa565b9350610af08a8a8a30898b6127e3565b83610aff8b6020015188611efa565b610b099190615b07565b93508960600151841015610b2f5760405162461bcd60e51b815260040161012490615b20565b600080516020615e4f833981519152828b60200151328d6040015188604051610b5c959493929190615b50565b60405180910390a15050509695505050505050565b6000610b818686863387876103ee565b9695505050505050565b806080013542811015610bb05760405162461bcd60e51b815260040161012490615a4d565b600080610bbd843561194d565b90506001600160a01b038116600080516020615e2f833981519152148015610c0a5750600080516020615e0f833981519152610bff6040860160208701615ad4565b6001600160a01b0316145b15610c185760009150610cb8565b6001600160a01b038116600080516020615e0f833981519152148015610c635750600080516020615e2f833981519152610c586040860160208701615ad4565b6001600160a01b0316145b15610c715760019150610cb8565b60405162461bcd60e51b815260206004820152601c60248201527b29bbb0b82bb930b81d1034b73b30b634b2103a37b5b2b7103830b4b960211b6044820152606401610124565b610cc88686848760400135611167565b505050505050565b6000876080013542811015610cf75760405162461bcd60e51b815260040161012490615a4d565b6040518a8152600080516020615e6f8339815191529060200160405180910390a16104ca33808061039a368e90038e018e615a75565b6000836080013542811015610d545760405162461bcd60e51b815260040161012490615a4d565b604051878152600080516020615e6f8339815191529060200160405180910390a1600080610d86600034118787611671565b90925090506000610d97883561194d565b9050826001600160a01b0316816001600160a01b03161480610de157506001600160a01b038116158015610de157506001600160a01b038316600080516020615e2f833981519152145b610e2b5760405162461bcd60e51b815260206004820152601b60248201527a0eadcf0e6eec2e07440cce4dedaa8ded6cadc40dad2e6dac2e8c6d602b1b6044820152606401610124565b6001600160a01b038216610e4560408a0160208b01615ad4565b6001600160a01b03161480610e9357506000610e6760408a0160208b01615ad4565b6001600160a01b0316148015610e9357506001600160a01b038216600080516020615e2f833981519152145b610edb5760405162461bcd60e51b81526020600482015260196024820152780eadcf0e6eec2e07440e8dea8ded6cadc40dad2e6dac2e8c6d603b1b6044820152606401610124565b6104ca83838a604001358b60600135338e8d8d611959565b6000610b81868686868687610873565b6000610f1285338686866104d8565b90505b949350505050565b610fbe565b3d6000803e3d6000fd5b67a9059cbb70a0823160c01b815230816008015260206000602483600401855afa610f5957610f59610f22565b6000518015610f845760a435600483015260248201819052610f846020600060448582885af1610f89565b505050565b80610f9657610f96610f22565b600160005114601f3d11163d151780610fba57633c9fd93960e21b60005260046000fd5b5050565b604051601581017306ff0b40e9091053eee51fa1d482ce5d852f523360611b825260206000600484335afa610ff557610ff5610f22565b6020806004808501335afa61100c5761100c610f22565b60206040600460088501335afa61102557611025610f22565b600080600088136001811461104157602051925087915061104a565b60005192508891505b506001733819ef38dd499eb7273946d69836632e4573819f605a1b03198452606060002083527fe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b5460208401526001600160a01b03605585201692503383146110bd57635960139160e11b60005260046000fd5b60843592507306ff0b40e9091053eee51fa1d482ce5d852f523360611b84523083146001811461112f5782601486015283603486015233605486015281607486015261112a6020600060846010890160007370cbb871e8f30fc8ce23609e9e0ea87b6b222f585af1610f89565b61115c565b336010860152816030860152611152602060006044600c89016000885af1610f89565b61115c8386610f2c565b505050505050505050565b604051848152600080516020615e6f8339815191529060200160405180910390a1600081116111cd5760405162461bcd60e51b81526020600482015260126024820152710616d6f756e74206d757374206265203e20360741b6044820152606401610124565b6001600160a01b038316156111e257826111e4565b335b92506000806111f1611a21565b9150915060008461121057600080516020615e2f833981519152611220565b600080516020615e0f8339815191525b905060008561123d57600080516020615e0f83398151915261124d565b600080516020615e2f8339815191525b905061125c8483836000611d15565b60008061127186338b8a896000015188611f9b565b9150915087156113ef5760405163052f523360e11b81527370cbb871e8f30fc8ce23609e9e0ea87b6b222f5890630a5ea466906112d490600080516020615e0f833981519152903390600080516020615def833981519152908d90600401615bd6565b600060405180830381600087803b1580156112ee57600080fd5b505af1158015611302573d6000803e3d6000fd5b5050604051632e1a7d4d60e01b8152600481018a9052600080516020615def8339815191529250632e1a7d4d9150602401600060405180830381600087803b15801561134d57600080fd5b505af1158015611361573d6000803e3d6000fd5b505050506001600160a01b03821630146113ea576000826001600160a01b03164760405160006040518083038185875af1925050503d80600081146113c2576040519150601f19603f3d011682016040523d82523d6000602084013e6113c7565b606091505b50509050806113e85760405162461bcd60e51b815260040161012490615c00565b505b6114c9565b855161143d5786341461143d5760405162461bcd60e51b81526020600482015260166024820152751d985b1d59481b9bdd08195c5d585b08185b5bdd5b9d60521b6044820152606401610124565b600080516020615e0f8339815191526001600160a01b031663d0e30db0886040518263ffffffff1660e01b81526004016000604051808303818588803b15801561148657600080fd5b505af115801561149a573d6000803e3d6000fd5b505050506001600160a01b038316301490506114c9576114c9600080516020615e0f8339815191528389612b7d565b60006114d8878b84878a6121a0565b9050600080516020615e4f8339815191528585328b6114f78682615b07565b604051611508959493929190615b50565b60405180910390a15050505050505050505050565b60006001600160a01b038516156115345784611536565b335b9450600080611543611a21565b915091506000600760f91b8560008151811061156157611561615a9e565b602002602001015160008151811061157b5761157b615a9e565b6020026020010151608001511690506115a68361159b896000015161194d565b896020015184611d15565b6115b4876020015189611efa565b93506000806115d3858d8c8c6040015188600001518e60200151611f9b565b915091506115e58989898f8f876127e3565b6115f6858b838c60200151886121a0565b5050508361160888602001518a611efa565b6116129190615b07565b935086606001518410156116385760405162461bcd60e51b815260040161012490615b20565b600080516020615e4f833981519152611654886000015161194d565b8860200151328a6040015188604051610b5c959493929190615b50565b600080826116915760405162461bcd60e51b815260040161012490615c36565b60006001600160a01b03858560008181106116ae576116ae615a9e565b9050602002013560001c1690506000600160ff1b868660008181106116d5576116d5615a9e565b9050602002013560001c166000141590508061175257816001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015611729573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061174d9190615c6c565b6117b4565b816001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015611790573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117b49190615c6c565b93506001600160a01b038416600080516020615e0f8339815191521480156117d95750865b156117f057600080516020615e2f83398151915293505b600086866117ff600182615b07565b81811061180e5761180e615a9e565b60200291909101359150506001600160a01b038116600160ff1b821615158061189857816001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561186f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118939190615c6c565b6118fa565b816001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156118d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118fa9190615c6c565b9550600160fe1b831615156001600160a01b038716600080516020615e0f8339815191521480156119285750805b1561193f57600080516020615e2f83398151915296505b505050505050935093915050565b6001600160a01b031690565b60006001600160a01b038416156119705783611972565b335b935060008061197f611a21565b91509150611990828c8c6000611d15565b61199a8a87611efa565b92506119ae87878d8d8d8d8b8b8a8a612bad565b826119b98b88611efa565b6119c39190615b07565b9250878310156119e55760405162461bcd60e51b815260040161012490615b20565b600080516020615e4f8339815191528b8b328c87604051611a0a959493929190615b50565b60405180910390a150505b98975050505050505050565b6040805161010081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101919091526040805160c081018252600080825260208201819052918101829052606081018290526080810182905260a081019190915260203603356001600160d01b031981166522220afc2bbb60d01b8114651111057e155560d11b821417651111057e155560d11b8214651e51057e155560d11b83141785526522220afc2bbb60d01b8214653ca20afc2bbb60d01b831417856020015265ffffffffffff60a01b831660a01c85604001526001600160a01b0383168560600152604036033592506000600160ff1b8416118560e001526001600160a01b03831685608001526001811460018114611b5d5760008660a0015260008660c00152611b88565b6060360335935065ffffffffffff60a01b841660a01c8660a001526001600160a01b0384168660c001525b506000925060018103611b9a57606092505b50653ca20afc2bbb60d01b8114651e51057e155560d11b82141715611bbe57604091505b602082013603356001600160d01b031981169150653bbbbbbb911160d11b82146577777777111160d01b831417845265ffffffffffff60a01b811660a01c84602001526001600160a01b03811684604001526040830136033590506001600160a01b0381168460600152653bbbbbbb911160d11b821460018114611c4f576000856080015260008560a00152611c7c565b60608401360335915065ffffffffffff60a01b821660a01c85608001526001600160a01b0382168560a001525b50505050816000015180611c91575081602001515b80611c9a575080515b15611d11577f6895551786bbb86042fcc29bf0c6657e90b7d1e78721946cb40dde1d3508854582604001518360a001518460e0015184602001518560800151604051611d08959493929190948552602085019390935290151560408401526060830152608082015260a00190565b60405180910390a15b9091565b600160fb1b8116151580611d2e5750600160fa1b811615155b80611d3e5750600160f91b811615155b8015611d48575083515b15611da15760405162461bcd60e51b815260206004820152602360248201527f46726f6d20746f6b656e20636f6d6d697373696f6e206e6f7420737570706f726044820152621d195960ea1b6064820152608401610124565b816001600160a01b0316836001600160a01b031603611df35760405162461bcd60e51b815260206004820152600e60248201526d496e76616c696420746f6b656e7360901b6044820152606401610124565b83518015611e02575083602001515b15611e4e5760405162461bcd60e51b815260206004820152601c60248201527b24b73b30b634b21031b7b6b6b4b9b9b4b7b7103234b932b1ba34b7b760211b6044820152606401610124565b83518015611e715750826001600160a01b031684608001516001600160a01b0316145b80611e9d575083602001518015611e9d5750816001600160a01b031684608001516001600160a01b0316145b80611eb457508351158015611eb457508360200151155b6103375760405162461bcd60e51b8152602060048201526017602482015276496e76616c696420636f6d6d697373696f6e20696e666f60481b6044820152606401610124565b6000611f1d565b62461bcd60e51b600052600160e51b6020528060405250806000fd5b600080516020615e2f833981519152831460018114611f8f57604051602481016040526370a0823160e01b815283600482015260206000602483885afa905080611f8457611f846058740519d95d0818985b185b98d953d98819985a5b195960421b611f01565b506000519150611f94565b823191505b5092915050565b600080876020015180611fab5750835b15611fc457309150611fbd8330611efa565b9050611fc8565b8591505b875115611fda57611fda888887612bf5565b965096945050505050565b6000611ff636889003880188615a75565b90506000612007826000015161194d565b9050600061203c8888600081811061202157612021615a9e565b90506020028101906120339190615ab4565b6080013561194d565b9050612050826001600160a01b03166130ea565b156120f9576001600160a01b038116600080516020615e0f8339815191521461208b5760405162461bcd60e51b815260040161012490615c89565b600080516020615e0f8339815191526001600160a01b031663d0e30db084604001516040518263ffffffff1660e01b81526004016000604051808303818588803b1580156120d857600080fd5b505af11580156120ec573d6000803e3d6000fd5b505050505030955061216a565b816001600160a01b0316816001600160a01b03161461212a5760405162461bcd60e51b815260040161012490615c89565b341561216a5760405162461bcd60e51b815260206004820152600f60248201526e076616c7565206d757374206265203608c1b6044820152606401610124565b612192868587866040015161218b88602001516001600160a01b03166130ea565b8d8d613106565b61115c836020015185613189565b600085602001511580156121b357508151155b156121c05750600061074c565b60006121cc8430611efa565b9050848110156122165760405162461bcd60e51b815260206004820152601560248201527434b73b30b634b2103130b630b731b29030b33a32b960591b6044820152606401610124565b60006122228683615b07565b90508760200151156122f5576301c9c3808860a0015189604001516122479190615cb6565b11156122935760405162461bcd60e51b815260206004820152601b60248201527a195c9c9bdc8818dbdb5b5a5cdcda5bdb881c985d19481b1a5b5a5d602a1b6044820152606401610124565b6000633b9aca008960a001518a604001516122ae9190615cb6565b6122b89084615b9d565b6122c29190615bb4565b90506122e4600187838c604001518d606001518e60a001518f60c0015161341f565b9250826122f18183615b07565b9150505b835180156123065750836060015181115b1561242b576064846020015111156123585760405162461bcd60e51b8152602060048201526015602482015274195c9c9bdc881d1c9a5b481c985d19481b1a5b5a5d605a1b6044820152606401610124565b6103e8846080015111156123a25760405162461bcd60e51b81526020600482015260116024820152706572726f7220636861726765207261746560781b6044820152606401610124565b60008460600151826123b49190615b07565b905060006103e88660200151846123cb9190615b9d565b6123d59190615bb4565b9050808211156123e3578091505b6124106000888489608001516103e86123fc9190615b07565b8a604001518b608001518c60a0015161341f565b61241a8286615cb6565b94506124268284615b07565b925050505b612436858883613722565b505095945050505050565b600080826124615760405162461bcd60e51b815260040161012490615c36565b60006001600160a01b038585600081811061247e5761247e615a9e565b905060200201351690506000600160ff1b868660008181106124a2576124a2615a9e565b905060200201351660001490508061251b57816001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156124f2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125169190615c6c565b61257d565b816001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015612559573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061257d9190615c6c565b93506001600160a01b038416600080516020615e0f8339815191521480156125a25750865b156125b957600080516020615e2f83398151915293505b600086866125c8600182615b07565b8181106125d7576125d7615a9e565b60200291909101359150506001600160a01b038116600160ff1b8216158061266057816001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015612637573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061265b9190615c6c565b6126c2565b816001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561269e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126c29190615c6c565b9550600160fd1b831615156001600160a01b038716600080516020615e0f8339815191521480156119285750801561193f57600080516020615e2f8339815191529650505050505050935093915050565b6000806001600160a01b038916156127335761272e8961194d565b612735565b335b9050600080612742611a21565b91509150612753828b8b6000611d15565b61275d8984611efa565b93506127708c848a8a8d8b8b8989613767565b8361277b8a85611efa565b6127859190615b07565b9350868410156127a75760405162461bcd60e51b815260040161012490615b20565b600080516020615e4f8339815191528a8a328b886040516127cc959493929190615b50565b60405180910390a150505098975050505050505050565b855186906000906127f39061194d565b90506127fe816130ea565b156128f057600080516020615e0f8339815191526001600160a01b031663d0e30db083604001516040518263ffffffff1660e01b81526004016000604051808303818588803b15801561285057600080fd5b505af1158015612864573d6000803e3d6000fd5b5050505050600080516020615e0f8339815191526001600160a01b03166128c28760008151811061289757612897615a9e565b60200260200101516000815181106128b1576128b1615a9e565b60200260200101516080015161194d565b6001600160a01b0316146128e85760405162461bcd60e51b815260040161012490615c89565b309450612936565b806001600160a01b03166129108760008151811061289757612897615a9e565b6001600160a01b0316146129365760405162461bcd60e51b815260040161012490615c89565b6000805b88518110156129725788818151811061295557612955615a9e565b6020026020010151826129689190615cb6565b915060010161293a565b5082604001518111156129e55760405162461bcd60e51b815260206004820152603560248201527f526f7574653a206e756d626572206f6620626174636865732073686f756c64206044820152741899480f0f48199c9bdb551bdad95b905b5bdd5b9d605a1b6064820152608401610124565b508551875114612a295760405162461bcd60e51b815260206004820152600f60248201526e0d8cadccee8d040dad2e6dac2e8c6d608b1b6044820152606401610124565b60005b8651811015612b64578015612b075786600081518110612a4e57612a4e615a9e565b6020026020010151600081518110612a6857612a68615a9e565b602002602001015160800151878281518110612a8657612a86615a9e565b6020026020010151600081518110612aa057612aa0615a9e565b60200260200101516080015114612b075760405162461bcd60e51b815260206004820152602560248201527f496e636f6e73697374656e742066726f6d546f6b656e206163726f7373206261604482015264746368657360d81b6064820152608401610124565b612b5c868686612b2387602001516001600160a01b03166130ea565b8c8681518110612b3557612b35615a9e565b60200260200101518c8781518110612b4f57612b4f615a9e565b602002602001015161379c565b600101612a2c565b50612b73826020015184613189565b5050505050505050565b612b908363a9059cbb60e01b84846138e6565b610f845760405163fb7f507960e01b815260040160405180910390fd5b600080612bc2848d8d8b87600001518e611f9b565b90925090508b612bd78b8a8a8a8a8689613939565b50612be5858d848d886121a0565b5050505050505050505050505050565b612ed2565b80820281158282048414178402612c195763ad251c276000526004601cfd5b9290920492915050565b600082821015612c3b576346e72d036000526004601cfd5b500390565b60008060008085855af180610f8457610f8460607c1c20636f6d6d697373696f6e2077697468206574686572206572726f72611f01565b6040516084810160405263052f523360e11b815281600482015282602482015283604482015284606482015260008060848360007370cbb871e8f30fc8ce23609e9e0ea87b6b222f585af1905080612ceb57612ceb60577304d8db185a5b481d1bdad95b9cc819985a5b1959604a1b611f01565b5050505050565b600080604051604881016040526ba9059cbba9059cbb70a0823160a01b815230600c82015260206000602460088401875afa80612d4c57612d4c6058740519d95d0818985b185b98d953d98819985a5b195960421b611f01565b600051898801612d77670de0b6b3a764000083612d7284670de0b6b3a76400008e612bfa565b612bfa565b95505080851115612da657612da6605975055a5b9d985b1a5908185b5bdd5b9d0c54d8d85b1959603a1b611f01565b8660088401528460288401526020600060446004860160008a5af1915081601f3d1160016000511416151615612ddf573d863b15171591505b81612e0c57612e0c605f7c1b7472616e7366657220746f6b656e2072656665726572206661696c00611f01565b8815612e8157612e1c8582612c23565b93508860048401528360248401526020600060448560008a5af1915081601f3d1160016000511416151615612e54573d863b15171591505b81612e8157612e81605f7c1b7472616e7366657220746f6b656e2072656665726572206661696c00611f01565b5050509550959350505050565b604051606081016040528181528260208201528360408201527f0d3b1268ca3dbb6d3d8a0ea35f44f8f9d58cf578d732680b71b6904fb2733e0d606082a150505050565b608083015160e084015160a08501516040860151601090920281151501600080516020615e2f8339815191528414610100020191600091829182918291906301c9c3808282011115612f4657612f46605f7c1b6572726f7220636f6d6d697373696f6e2072617465206c696d697400611f01565b60608b015160c08c01519096509450818101633b9aca00038983028190049450898202049250866101008114612fd1576101018114612ff4576101108114612fd1576101118114612ff457801561303a5760018114613051576010811461307f57601181146130ab57612fcc60526e0e696e76616c69642073746174757360701b611f01565b6130dc565b612fdb8588612c40565b612fcc8786600080516020615e2f833981519152612e8e565b612ffe8588612c40565b6130178786600080516020615e2f833981519152612e8e565b6130218487612c40565b612fcc8685600080516020615e2f833981519152612e8e565b61304685888d8c612c77565b612fcc87868b612e8e565b61305d85888d8c612c77565b61306887868b612e8e565b61307484878d8c612c77565b612fcc86858b612e8e565b61308b85308d8c612c77565b613099600080858a8d612cf2565b506130a588828c612e8e565b506130dc565b6130b9848601308d8c612c77565b6130c68287858a8d612cf2565b6130d189838d612e8e565b612be588828d612e8e565b505050505050505050505050565b6001600160a01b0316600080516020615e2f8339815191521490565b80600061312c8288604080518082019091529182526001600160a01b0316602082015290565b905060005b8281101561317d578015613143573099505b6131758a8a89848a8a8a8881811061315d5761315d615a9e565b905060200281019061316f9190615ab4565b886140f5565b600101613131565b50505050505050505050565b61319b826001600160a01b03166130ea565b1561338c576040516370a0823160e01b8152600090600080516020615e0f833981519152906370a08231906131d49030906004016157bb565b602060405180830381865afa1580156131f1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132159190615b84565b905080156133025760405163a9059cbb60e01b8152600080516020615def833981519152600482015260248101829052600080516020615e0f8339815191529063a9059cbb906044016020604051808303816000875af115801561327d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132a19190615cc9565b50604051632e1a7d4d60e01b815260048101829052600080516020615def83398151915290632e1a7d4d90602401600060405180830381600087803b1580156132e957600080fd5b505af11580156132fd573d6000803e3d6000fd5b505050505b6001600160a01b0382163014610f8457478015610337576000836001600160a01b03168260405160006040518083038185875af1925050503d8060008114613366576040519150601f19603f3d011682016040523d82523d6000602084013e61336b565b606091505b5050905080612ceb5760405162461bcd60e51b815260040161012490615c00565b6001600160a01b0381163014610fba576040516370a0823160e01b81526000906001600160a01b038416906370a08231906133cb9030906004016157bb565b602060405180830381865afa1580156133e8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061340c9190615b84565b90508015610f8457610f84838383612b7d565b613591565b60008060008085855af180610f8457610f84605571045cd95b9908195d1a195c8819985a5b1959605a1b611f01565b6040516044810160405263a9059cbb60e01b8152826004820152836024820152602060006044836000865af1905080601f3d116001600051141615161561349c5750803b153d17155b8061033757610337605975055d1c985b9cd9995c881d1bdad95b8819985a5b1959603a1b611f01565b604051606081016040528181528260208201528360408201527ff171268de859ec269c52bbfac94dcb7715e784de194342abb284bf34fd30b32d606082a150505050565b604051606081016040528181528260208201528360408201527f7bec7d55a62a7a7b8068f1533e2a3bbf727b3e2e57f30c576fe159da60e09a65606082a150505050565b604051606081016040528181528260208201528360408201527ffd08115c8e43d2a49d95ee18d7f69b8bbac60bd368c73cf22d30664a22a0626d606082a150505050565b6001600160a01b03928316921681840185850204808603601089151502600080516020615e2f83398151915289140180601181146136015760108114613653576001811461368b5780156136dd576135fc60526e0e696e76616c69642073746174757360701b611f01565b613715565b871561362a576136118488613424565b61362a8785600080516020615e2f8339815191526134c5565b85156135fc5761363a8386613424565b6135fc8584600080516020615e2f8339815191526134c5565b871561366f5761366484888c613453565b61366f87858c6134c5565b85156135fc5761368083868c613453565b6135fc85848c6134c5565b87156136b45761369b8488613424565b6136b48785600080516020615e2f833981519152613509565b85156135fc576136c48386613424565b6135fc8584600080516020615e2f83398151915261354d565b87156136f9576136ee84888c613453565b6136f987858c613509565b85156137155761370a83868c613453565b61371585848c61354d565b5050505050505050505050565b600080516020615e2f8339815191528314600181146137545761374f826001600160a01b03851686613453565b610337565b610337826001600160a01b038516613424565b60008061377c848c8c8c87600001518c611f9b565b9150915061378e8b838b8b8a8a6145d6565b506130dc848b838a876121a0565b60006137b4826000815181106128b1576128b1615a9e565b905060008060008451905060005b818110156137155780156137f7576137e58682815181106128b1576128b1615a9e565b94506137f18530611efa565b9650309a505b30613803600184615b07565b8214801561380f575088155b1561381b5750886138b3565b613826600184615b07565b8210801561385c57508661383b836001615cb6565b8151811061384b5761384b615a9e565b602002602001015160200151516001145b156138ae578661386d836001615cb6565b8151811061387d5761387d615a9e565b60200260200101516020015160008151811061389b5761389b615a9e565b60200260200101519050600194506138b3565b600094505b6138da8c8c838b8b87815181106138cc576138cc615a9e565b602002602001015189614934565b508392506001016137c2565b60006040518481528360048201528260248201526020600060448360008a5af19150508015610f15573d801561392857600160005114601f3d11169150613930565b6000863b1191505b50949350505050565b6000613b60565b828152600060206000600484600401865afa613975576139756054700419d95d081d1bdad95b8819985a5b195960621b611f01565b505060005192915050565b6770a082310dfe168160c01b815260008060206000600485600401875afa6139c3576139c3605672049d1bdad95b8c0818d85b1b0819985a5b195960521b611f01565b600051915083836004015260206000602485855afa613a0057613a006059750558985b185b98d953d98818d85b1b0819985a5b1959603a1b611f01565b60005190509250929050565b6770a08231d21220a760c01b815260008060206000600485600401875afa6139c3576139c3605672049d1bdad95b8c4818d85b1b0819985a5b195960521b611f01565b668b0367c240bc6b60c21b8152600060406000600484600401875afa613a9257613a92605874051c995cd95c9d995cc818d85b1b0819985a5b195960421b611f01565b600051602051868015613abe578915613ab657613aaf8786613a0c565b8390039650505b909190613ad5565b8815613ad557613ace8786613980565b8490039650505b50668b0367c240bc6b60c21b8452898502633b9aca009290920282019102049050848015613b0f5781600484015260006024840152613b1d565b600060048401528160248401525b50886044830152608060648301526000608483015260008060a4846000885af1611a1557611a15605470041cddd85c0818d85b1b0819985a5b195960621b611f01565b846020850281018580613b8757613b87604e6b0b656d70747920706f6f6c7360901b611f01565b5060405182358b600080516020615e2f8339815191521460018114613c40573415613bcc57613bcc60557111696e76616c6964206d73672e76616c756560581b611f01565b63052f523360e11b83528c60048401528760248401526001600160a01b03821660448401528b606484015260008060848560007370cbb871e8f30fc8ce23609e9e0ea87b6b222f585af1613c3b57613c3b6056720498db185a5b481d1bdad95b8819985a5b195960521b611f01565b613d0d565b60018c341003613c6a57613c6a60557111696e76616c6964206d73672e76616c756560581b611f01565b670a9059cbbd0e30db60c41b835260008060048086018f600080516020615e0f8339815191525af1613cb757613cb76056720499195c1bdcda5d081155120819985a5b195960521b611f01565b6001600160a01b03821683600401528b8360240152602060006044856000600080516020615e0f8339815191525af1613d0d57613d0d605874051d1c985b9cd9995c8815d155120819985a5b195960421b611f01565b508a9450602084015b83811015613d6c578035613d606001600160a01b03821663ffffffff60a01b851660a01c600160fd1b8616600160fc1b8716600160ff1b88166001600160a01b0389168d8b613a4f565b96509150602001613d16565b5060009350600160fe1b81168015613eaf57600080516020615e2f8339815191529450613dc63063ffffffff60a01b841660a01c600160fd1b8516600160fc1b8616600160ff1b87166001600160a01b0388168c8a613a4f565b9550672e1a7d4da9059cbb60c01b8352600080516020615def8339815191526008840152856028840152602060006044856004016000600080516020615e0f8339815191525af1613e3457613e34605874051d1c985b9cd9995c8815d155120819985a5b195960421b611f01565b856004840152602060006024856000600080516020615def8339815191525af1613e7a57613e7a60577304ddda5d1a191c985dc81155120819985a5b1959604a1b611f01565b600080600080898b5af1613eaa57613eaa60577304dd1c985b9cd9995c881155120819985a5b1959604a1b611f01565b6140e5565b60009350600160ff1b82168015613f5d57600160fc1b831615613f58576770a082310dfe168160c01b8452602060006004866004016001600160a01b0387165afa613f1557613f15605672049d1bdad95b8c0818d85b1b0819985a5b195960521b611f01565b600051955087846004015260206000602486895afa613f5257613f52605675055d1bdad95b8c0818985b185b98d94819985a5b1959603a1b611f01565b60005194505b613ff5565b600160fd1b831615613ff5576770a08231d21220a760c01b8452602060006004866004016001600160a01b0387165afa613fb257613fb2605672049d1bdad95b8c4818d85b1b0819985a5b195960521b611f01565b600051955087846004015260206000602486895afa613fef57613fef605975055d1bdad95b8c4818985b185b98d94819985a5b1959603a1b611f01565b60005194505b5061402d8763ffffffff60a01b841660a01c600160fd1b8516600160fc1b8616600160ff1b87166001600160a01b0388168c8a613a4f565b9550846000106001811461409657600160ff1b8316801561406e576140676770a082310dfe168160c01b6001600160a01b03861687613940565b9650614090565b61408d6770a08231d21220a760c01b6001600160a01b03861687613940565b96505b506140e3565b6770a082310dfe168160c01b845287846004015260206000602486895afa6140db576140db6058740519d95d0818985b185b98d953d98819985a5b195960421b611f01565b846000510396505b505b5050505050979650505050505050565b6000806000614107856080013561194d565b905060006141158680615ce6565b90501161415e5760405162461bcd60e51b8152602060048201526017602482015276065646765206c656e677468206d757374206265203e203604c1b6044820152606401610124565b61416b6040860186615ce6565b90506141778680615ce6565b905014801561419e575061418e6060860186615ce6565b905061419a8680615ce6565b9050145b80156141c257506141b26020860186615ce6565b90506141be8680615ce6565b9050145b6142055760405162461bcd60e51b81526020600482015260146024820152730e0c2e8d040d8cadccee8d040dad2e6dac2e8c6d60631b6044820152606401610124565b86156142c5576040516370a0823160e01b81526001600160a01b038216906370a08231906142379030906004016157bb565b602060405180830381865afa158015614254573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142789190615b84565b9750600088116142c55760405162461bcd60e51b815260206004820152601860248201527706e6f64652062616c616e6365206d757374206265203e20360441b6044820152606401610124565b60005b6142d28680615ce6565b90508110156137155760008080806142ed60408b018b615ce6565b868181106142fd576142fd615a9e565b9050602002013560001b905061ffff60a01b811660a01c915060ff60b81b811660b81c935060ff60b01b811660b01c92508b841461437c5760405162461bcd60e51b815260206004820152601c60248201527b1b9bd919481a5b9c1d5d125b99195e081a5b98dbdb9cda5cdd195b9d60221b6044820152606401610124565b828410801561438c575088518311155b6143d25760405162461bcd60e51b81526020600482015260176024820152766e6f646520696e646578206f7574206f662072616e676560481b6044820152606401610124565b6143dc8289615cb6565b975060016143ea8b80615ce6565b6143f5929150615b07565b85036144485787612710146144485760405162461bcd60e51b81526020600482015260196024820152780746f74616c576569676874206d75737420626520313030303603c1b6044820152606401610124565b50600060016144578b80615ce6565b614462929150615b07565b850361447957614472878e615b07565b905061449f565b612710614486838f615b9d565b6144909190615bb4565b905061449c8188615cb6565b96505b80156144e6576144e68f6144b660208d018d615ce6565b888181106144c6576144c6615a9e565b90506020020160208101906144db9190615ad4565b8c6080013584614ac2565b5087513090831480156144f757508a155b156144ff57508c5b6145c761450f60408c018c615ce6565b8781811061451f5761451f615a9e565b602002919091013590506145338c80615ce6565b8881811061454357614543615a9e565b90506020020160208101906145589190615ad4565b61456560608e018e615ce6565b8981811061457557614575615a9e565b90506020028101906145879190615d2f565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250505060208e0151869150614b9f565b508360010193505050506142c8565b600061486f565b6000856001600160ff1b0310156145ff57630b3f79fd60e41b60005260046000fd5b604051600160ff1b8616156001600160a01b038716816001811461469357630251596160e31b845260048401868152600060208201528a604082015273fffd8963efd1fc6a506488495d951d5263988d25606082015260a06080820152604060a08201528760c08201528860e082015250600080610104866000865af1806146875760206000fd5b5060206000803e6146f6565b630251596160e31b845260048401868152600160208201528a60408201526401000276a4606082015260a06080820152604060a08201528760c08201528860e082015250600080610104866000865af1806146ee5760206000fd5b5060208060003e5b505050506000519050600160ff1b81101561471c576322323ba760e21b60005260046000fd5b1960010195945050505050565b60018134100361474457631841b4e160e01b60005260046000fd5b60008060008084600080516020615e0f8339815191525af180610fba57610fba60577304d5d155120819195c1bdcda5d0819985a5b1959604a1b611f01565b60405160048101672e1a7d4da9059cbb60c01b8252600080516020615def83398151915260048201528360248201526000806044836000600080516020615e0f8339815191525af19050806147f5576147f5605874051d1c985b9cd9995c881dd95d1a0819985a5b195960421b611f01565b8360048301526000806024846000600080516020615def8339815191525af190508061483e5761483e605874051dda5d1a191c985dc81dd95d1a0819985a5b195960421b611f01565b60008060008087875af190508061033757610337605571045cd95b9908195d1a195c8819985a5b1959605a1b611f01565b82601f19602084028201018380614891576333f3e07b60e11b60005260046000fd5b50886000341180156148aa576148a689614729565b309a505b5087606052825b828110156148d4576148c7898235848e306145dd565b309b5098506020016148b1565b506000600160fd1b83351611925082600181146148f657801561491557614926565b614904898435848e306145dd565b9450614910858b614783565b614926565b614923898435848e8e6145dd565b94505b505050509695505050505050565b6000805b835151811015612b735760008460400151828151811061495a5761495a615a9e565b602090810291909101015190506001600160a01b038116600160ff1b821661ffff60a084901c1661498b8187615cb6565b88515190965061499d90600190615b07565b8503614a0457612710861115614a045760405162461bcd60e51b815260206004820152602660248201527f746f74616c5765696768742063616e206e6f7420657863656564203130303030604482015265081b1a5b5a5d60d21b6064820152608401610124565b86614a635760008161271014614a3057612710614a21838c615b9d565b614a2b9190615bb4565b614a32565b895b9050614a618d8a602001518881518110614a4e57614a4e615a9e565b60200260200101518b6080015184614ac2565b505b50614aac8188600001518681518110614a7e57614a7e615a9e565b60200260200101518b858b606001518981518110614a9e57614a9e615a9e565b60200260200101518f614bc7565b5050508080614aba90615d75565b915050614938565b6001600160a01b038216600760f91b8316601f60fb1b8101614ae5575050610337565b600160fa1b8103614b0257614afb828685612b7d565b5050610337565b600160f91b8103614b14575050610337565b306001600160a01b03871603614b3457614b2f828685612b7d565b610cc8565b60405163052f523360e11b81527370cbb871e8f30fc8ce23609e9e0ea87b6b222f5890630a5ea46690614b719085908a908a908990600401615bd6565b600060405180830381600087803b158015614b8b57600080fd5b505af115801561317d573d6000803e3d6000fd5b600160ff1b85166001600160a01b038616614bbe828786848988614bc7565b50505050505050565b8515614ccc57600080866001600160a01b0316636f7929f260e01b878787604051602401614bf793929190615d8e565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614c456001600160a01b038616650f2882bf0b3360d21b615cb6565b604051602001614c56929190615dba565b60408051601f1981840301815290829052614c7091615ddc565b6000604051808303816000865af19150503d8060008114614cad576040519150601f19603f3d011682016040523d82523d6000602084013e614cb2565b606091505b509150915081614cc557614cc581614dc0565b5050610cc8565b600080866001600160a01b03166330e6ae3160e01b878787604051602401614cf693929190615d8e565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614d446001600160a01b038616650f2882bf0b3360d21b615cb6565b604051602001614d55929190615dba565b60408051601f1981840301815290829052614d6f91615ddc565b6000604051808303816000865af19150503d8060008114614dac576040519150601f19603f3d011682016040523d82523d6000602084013e614db1565b606091505b509150915081612b7357612b73815b805115614dcf57805160208201fd5b60405162461bcd60e51b81526020600482015260136024820152721859185c1d1bdc8818d85b1b0819985a5b1959606a1b6044820152606401610124565b50565b60008060408385031215614e2357600080fd5b50508035926020909101359150565b6001600160a01b0381168114614e0d57600080fd5b8035614e5281614e32565b919050565b600060a08284031215614e6957600080fd5b50919050565b60008083601f840112614e8157600080fd5b5081356001600160401b03811115614e9857600080fd5b6020830191508360208260051b8501011115614eb357600080fd5b9250929050565b60008060008060008060008060006101408a8c031215614ed957600080fd5b8935985060208a0135614eeb81614e32565b9750614efa8b60408c01614e57565b965060e08a01356001600160401b0380821115614f1657600080fd5b614f228d838e01614e6f565b90985096506101008c0135915080821115614f3c57600080fd5b614f488d838e01614e6f565b90965094506101208c0135915080821115614f6257600080fd5b50614f6f8c828d01614e6f565b915080935050809150509295985092959850929598565b60008060008060008060a08789031215614f9f57600080fd5b8635955060208701359450604087013593506060870135614fbf81614e32565b925060808701356001600160401b03811115614fda57600080fd5b614fe689828a01614e6f565b979a9699509497509295939492505050565b6000806000806000610100868803121561501157600080fd5b85359450602086013561502381614e32565b93506150328760408801614e57565b925060e08601356001600160401b0381111561504d57600080fd5b61505988828901614e6f565b969995985093965092949392505050565b60008060008060006080868803121561508257600080fd5b85359450602086013593506040860135925060608601356001600160401b0381111561504d57600080fd5b60005b838110156150c85781810151838201526020016150b0565b50506000910152565b600081518084526150e98160208601602086016150ad565b601f01601f19169290920160200192915050565b60208152600061511060208301846150d1565b9392505050565b634e487b7160e01b600052604160045260246000fd5b60405160a081016001600160401b038111828210171561514f5761514f615117565b60405290565b60405161014081016001600160401b038111828210171561514f5761514f615117565b604051601f8201601f191681016001600160401b03811182821017156151a0576151a0615117565b604052919050565b600060a082840312156151ba57600080fd5b6151c261512d565b90508135815260208201356151d681614e32565b8060208301525060408201356040820152606082013560608201526080820135608082015292915050565b60006001600160401b0382111561521a5761521a615117565b5060051b60200190565b600082601f83011261523557600080fd5b8135602061524a61524583615201565b615178565b82815260059290921b8401810191818101908684111561526957600080fd5b8286015b84811015615284578035835291830191830161526d565b509695505050505050565b600082601f8301126152a057600080fd5b813560206152b061524583615201565b82815260059290921b840181019181810190868411156152cf57600080fd5b8286015b848110156152845780356152e681614e32565b83529183019183016152d3565b600082601f83011261530457600080fd5b81356001600160401b0381111561531d5761531d615117565b615330601f8201601f1916602001615178565b81815284602083860101111561534557600080fd5b816020850160208301376000918101602001919091529392505050565b600082601f83011261537357600080fd5b8135602061538361524583615201565b82815260059290921b840181019181810190868411156153a257600080fd5b8286015b848110156152845780356001600160401b038111156153c55760008081fd5b6153d38986838b01016152f3565b8452509183019183016153a6565b60006153ef61524584615201565b838152905060208101600584901b830185101561540b57600080fd5b825b8460051b840181101561557b576001600160401b03813581101561543057600080fd5b8135850187601f82011261544357600080fd5b6154506152458235615201565b81358082526020808301929160051b8401018a81111561546f57600080fd5b602084015b8181101561556457858135111561548a57600080fd5b8035850160a0818e03601f190112156154a257600080fd5b6154aa61512d565b87602083013511156154bb57600080fd5b6154cd8e60208085013585010161528f565b815287604083013511156154e057600080fd5b6154f38e6020604085013585010161528f565b6020820152876060830135111561550957600080fd5b61551c8e60206060850135850101615224565b6040820152876080830135111561553257600080fd5b6155458e60206080850135850101615362565b606082015260a091909101356080820152845260209384019301615474565b50508552505060209283019291909101905061540d565b50509392505050565b600082601f83011261559557600080fd5b615110838335602085016153e1565b8015158114614e0d57600080fd5b8035614e52816155a4565b600082601f8301126155ce57600080fd5b813560206155de61524583615201565b82815260059290921b840181019181810190868411156155fd57600080fd5b8286015b848110156152845780356001600160401b03808211156156215760008081fd5b90880190610140828b03601f190181131561563c5760008081fd5b615644615155565b8784013581526040615657818601614e47565b898301526060615668818701614e47565b828401526080915061567b828701614e47565b818401525060a0808601358284015260c0915081860135818401525060e0808601358284015261010091508186013581840152506101206156bd8187016155b2565b838301529285013592848411156156d657600091508182fd5b6156e48e8b868901016152f3565b90830152508652505050918301918301615601565b600080600080600080610140878903121561571357600080fd5b61571d88886151a8565b955060a08701356001600160401b038082111561573957600080fd5b6157458a838b01615224565b965060c089013591508082111561575b57600080fd5b6157678a838b01615584565b955060e089013591508082111561577d57600080fd5b5061578a89828a016155bd565b93505061010087013561579c81614e32565b91506101208701356157ad81614e32565b809150509295509295509295565b6001600160a01b0391909116815260200190565b600080600060e084860312156157e457600080fd5b8335925060208401356157f681614e32565b91506158058560408601614e57565b90509250925092565b600080600080600080600080610120898b03121561582b57600080fd5b8835975061583c8a60208b01614e57565b965060c08901356001600160401b038082111561585857600080fd5b6158648c838d01614e6f565b909850965060e08b013591508082111561587d57600080fd5b6158898c838d01614e6f565b90965094506101008b01359150808211156158a357600080fd5b506158b08b828c01614e6f565b999c989b5096995094979396929594505050565b600080600080600061012086880312156158dd57600080fd5b6158e787876151a8565b945060a08601356001600160401b038082111561590357600080fd5b61590f89838a01615224565b955060c088013591508082111561592557600080fd5b61593189838a01615584565b945060e088013591508082111561594757600080fd5b50615954888289016155bd565b92505061010086013561596681614e32565b809150509295509295909350565b60008060008060e0858703121561598a57600080fd5b8435935061599b8660208701614e57565b925060c08501356001600160401b038111156159b657600080fd5b6159c287828801614e6f565b95989497509550505050565b600080600080606085870312156159e457600080fd5b843593506020850135925060408501356001600160401b0380821115615a0957600080fd5b818701915087601f830112615a1d57600080fd5b813581811115615a2c57600080fd5b886020828501011115615a3e57600080fd5b95989497505060200194505050565b6020808252600e908201526d149bdd5d194e88195e1c1a5c995960921b604082015260600190565b600060a08284031215615a8757600080fd5b61511083836151a8565b60006151103684846153e1565b634e487b7160e01b600052603260045260246000fd5b60008235609e19833603018112615aca57600080fd5b9190910192915050565b600060208284031215615ae657600080fd5b813561511081614e32565b634e487b7160e01b600052601160045260246000fd5b81810381811115615b1a57615b1a615af1565b92915050565b602080825260169082015275135a5b881c995d1d5c9b881b9bdd081c995858da195960521b604082015260600190565b6001600160a01b03958616815293851660208501529190931660408301526060820192909252608081019190915260a00190565b600060208284031215615b9657600080fd5b5051919050565b8082028115828204841417615b1a57615b1a615af1565b600082615bd157634e487b7160e01b600052601260045260246000fd5b500490565b6001600160a01b039485168152928416602084015292166040820152606081019190915260800190565b6020808252601c908201527b1d1c985b9cd9995c881b985d1a5d99481d1bdad95b8819985a5b195960221b604082015260600190565b6020808252601c908201527b0706f6f6c73206d7573742062652067726561746572207468616e20360241b604082015260600190565b600060208284031215615c7e57600080fd5b815161511081614e32565b6020808252601390820152720ccd2e4e6e8a8ded6cadc40dad2e6dac2e8c6d606b1b604082015260600190565b80820180821115615b1a57615b1a615af1565b600060208284031215615cdb57600080fd5b8151615110816155a4565b6000808335601e19843603018112615cfd57600080fd5b8301803591506001600160401b03821115615d1757600080fd5b6020019150600581901b3603821315614eb357600080fd5b6000808335601e19843603018112615d4657600080fd5b8301803591506001600160401b03821115615d6057600080fd5b602001915036819003821315614eb357600080fd5b600060018201615d8757615d87615af1565b5060010190565b6001600160a01b03848116825283166020820152606060408201819052600090610f12908301846150d1565b60008351615dcc8184602088016150ad565b9190910191825250602001919050565b60008251615aca8184602087016150ad56fe0000000000000000000000005703b683c7f928b721ca95da988d73a3299d4757000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1bb43f2da90e35f7b0cf38521ca95a49e68eb42fac49924930a5bd73cdf7576c7724394874fdd8ad13292ec739b441f85c6559f10dc4141b8d4c0fa4cbf55bdba26469706673582212206404d06f72c994e664bef3d395a67f53d8848bf8d4e626470b96f048d9ecdb0764736f6c63430008110033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 34 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|---|---|---|---|---|
| BASE | 100.00% | $3,406.23 | 0.0000157 | $0.053481 |
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
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.