Source Code
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Loading...
Loading
Cross-Chain Transactions
Loading...
Loading
Contract Name:
BancorArbitrage
Compiler Version
v0.8.19+commit.7dd6d404
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import { ReentrancyGuardUpgradeable } from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { IUniswapV2Router02 } from "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
import { ISwapRouter } from "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";
import { IWETH } from "@uniswap/v2-periphery/contracts/interfaces/IWETH.sol";
import { IAsset as IBalancerAsset } from "@balancer-labs/v2-interfaces/contracts/vault/IAsset.sol";
import { IVault as IBalancerVault } from "@balancer-labs/v2-interfaces/contracts/vault/IVault.sol";
import { IFlashLoanRecipient as IBalancerFlashLoanRecipient } from "@balancer-labs/v2-interfaces/contracts/vault/IFlashLoanRecipient.sol";
import { castTokens as castToBalancerTokens } from "../exchanges/BalancerUtils.sol";
import { Token } from "../token/Token.sol";
import { TokenLibrary } from "../token/TokenLibrary.sol";
import { Upgradeable } from "../utility/Upgradeable.sol";
import { Utils, ZeroValue } from "../utility/Utils.sol";
import { IBancorNetwork, IFlashLoanRecipient } from "../exchanges/interfaces/IBancorNetwork.sol";
import { IBancorNetworkV2 } from "../exchanges/interfaces/IBancorNetworkV2.sol";
import { ICarbonController, TradeAction } from "../exchanges/interfaces/ICarbonController.sol";
import { ICarbonPOL } from "../exchanges/interfaces/ICarbonPOL.sol";
import { ICurvePool } from "../exchanges/interfaces/ICurvePool.sol";
import { PPM_RESOLUTION } from "../utility/Constants.sol";
/**
* @dev BancorArbitrage contract
*/
contract BancorArbitrage is ReentrancyGuardUpgradeable, Utils, Upgradeable {
using SafeERC20 for IERC20;
using TokenLibrary for Token;
using Address for address payable;
error InvalidTradePlatformId();
error InvalidFlashloanPlatformId();
error InvalidRouteLength();
error InvalidInitialAndFinalTokens();
error InvalidFlashloanFormat();
error InvalidFlashLoanCaller();
error MinTargetAmountTooHigh();
error MinTargetAmountNotReached();
error InvalidSourceToken();
error InvalidETHAmountSent();
error SourceAmountTooHigh();
error InvalidCarbonPOLTrade();
error InvalidCurvePool();
error InvalidWethTrade();
// trade args v2
struct TradeRoute {
uint16 platformId;
Token sourceToken;
Token targetToken;
uint256 sourceAmount;
uint256 minTargetAmount;
uint256 deadline;
address customAddress;
uint256 customInt;
bytes customData;
}
// flashloan args
struct Flashloan {
uint16 platformId;
IERC20[] sourceTokens;
uint256[] sourceAmounts;
}
// rewards settings
struct Rewards {
uint32 percentagePPM;
uint256 maxAmount;
}
// platforms
struct Platforms {
IBancorNetworkV2 bancorNetworkV2;
IBancorNetwork bancorNetworkV3;
IUniswapV2Router02 uniV2Router;
ISwapRouter uniV3Router;
IUniswapV2Router02 sushiswapRouter;
ICarbonController carbonController;
IBalancerVault balancerVault;
ICarbonPOL carbonPOL;
}
// platform ids
uint16 public constant PLATFORM_ID_BANCOR_V2 = 1;
uint16 public constant PLATFORM_ID_BANCOR_V3 = 2;
uint16 public constant PLATFORM_ID_UNISWAP_V2_FORK = 3;
uint16 public constant PLATFORM_ID_UNISWAP_V3_FORK = 4;
uint16 public constant PLATFORM_ID_SUSHISWAP = 5;
uint16 public constant PLATFORM_ID_CARBON_FORK = 6;
uint16 public constant PLATFORM_ID_BALANCER = 7;
uint16 public constant PLATFORM_ID_CARBON_POL = 8;
uint16 public constant PLATFORM_ID_CURVE = 9;
uint16 public constant PLATFORM_ID_WETH = 10;
// minimum number of trade routes supported
uint256 private constant MIN_ROUTE_LENGTH = 2;
// maximum number of trade routes supported
uint256 private constant MAX_ROUTE_LENGTH = 10;
// boolean flags encoded in customInt for each platform
uint256 private constant CARBON_TRADE_BY_TARGET_FLAG = 1; // 0001
// the bnt contract
IERC20 internal immutable _bnt;
// WETH9 contract
IERC20 internal immutable _weth;
// bancor v2 network contract
IBancorNetworkV2 internal immutable _bancorNetworkV2;
// bancor v3 network contract
IBancorNetwork internal immutable _bancorNetworkV3;
// uniswap v2 router contract
IUniswapV2Router02 internal immutable _uniswapV2Router;
// uniswap v3 router contract
ISwapRouter internal immutable _uniswapV3Router;
// sushiSwap router contract
IUniswapV2Router02 internal immutable _sushiSwapRouter;
// Carbon controller contract
ICarbonController internal immutable _carbonController;
// Balancer Vault
IBalancerVault internal immutable _balancerVault;
// Carbon POL contract
ICarbonPOL internal immutable _carbonPOL;
// Protocol wallet address
address internal immutable _protocolWallet;
// rewards defaults
Rewards internal _rewards;
// deprecated variable
uint256 private deprecated;
// upgrade forward-compatibility storage gap
uint256[MAX_GAP - 3] private __gap;
/**
* @dev triggered after a successful arb is executed
*/
event ArbitrageExecuted(
address indexed caller,
uint16[] platformIds,
address[] tokenPath,
address[] sourceTokens,
uint256[] sourceAmounts,
uint256[] protocolAmounts,
uint256[] rewardAmounts
);
/**
* @dev triggered when the rewards settings are updated
*/
event RewardsUpdated(
uint32 prevPercentagePPM,
uint32 newPercentagePPM,
uint256 prevMaxAmount,
uint256 newMaxAmount
);
/**
* @dev used to set immutable state variables and initialize the implementation
*/
constructor(
IERC20 initBnt,
IERC20 initWeth,
address initProtocolWallet,
Platforms memory platforms
) validAddress(address(initWeth)) validAddress(address(initProtocolWallet)) {
_bnt = initBnt;
_weth = initWeth;
_protocolWallet = initProtocolWallet;
_bancorNetworkV2 = platforms.bancorNetworkV2;
_bancorNetworkV3 = platforms.bancorNetworkV3;
_uniswapV2Router = platforms.uniV2Router;
_uniswapV3Router = platforms.uniV3Router;
_sushiSwapRouter = platforms.sushiswapRouter;
_carbonController = platforms.carbonController;
_balancerVault = platforms.balancerVault;
_carbonPOL = platforms.carbonPOL;
initialize();
}
/**
* @dev fully initializes the contract and its parents
*/
function initialize() public initializer {
__BancorArbitrage_init();
}
// solhint-disable func-name-mixedcase
/**
* @dev initializes the contract and its parents
*/
function __BancorArbitrage_init() internal onlyInitializing {
__ReentrancyGuard_init();
__Upgradeable_init();
__BancorArbitrage_init_unchained();
}
/**
* @dev performs contract-specific initialization
*/
function __BancorArbitrage_init_unchained() internal onlyInitializing {
_rewards = Rewards({ percentagePPM: 500000, maxAmount: 1000 * 1e18 });
}
/**
* @dev authorize the contract to receive the native token
*/
receive() external payable {}
/**
* @inheritdoc Upgradeable
*/
function version() public pure override(Upgradeable) returns (uint16) {
return 11;
}
/**
* @dev checks whether the specified number of routes is supported
*/
modifier validRouteLength(uint256 length) {
// validate inputs
_validRouteLength(length);
_;
}
/**
* @dev validRouteLength logic for gas optimization
*/
function _validRouteLength(uint256 length) internal pure {
if (length < MIN_ROUTE_LENGTH || length > MAX_ROUTE_LENGTH) {
revert InvalidRouteLength();
}
}
/**
* @dev sets the rewards settings
*
* requirements:
*
* - the caller must be the admin of the contract
*/
function setRewards(
Rewards calldata newRewards
) external onlyAdmin validFee(newRewards.percentagePPM) greaterThanZero(newRewards.maxAmount) {
uint32 prevPercentagePPM = _rewards.percentagePPM;
uint256 prevMaxAmount = _rewards.maxAmount;
// return if the rewards are the same
if (prevPercentagePPM == newRewards.percentagePPM && prevMaxAmount == newRewards.maxAmount) {
return;
}
_rewards = newRewards;
emit RewardsUpdated({
prevPercentagePPM: prevPercentagePPM,
newPercentagePPM: newRewards.percentagePPM,
prevMaxAmount: prevMaxAmount,
newMaxAmount: newRewards.maxAmount
});
}
/**
* @dev returns the rewards settings
*/
function rewards() external view returns (Rewards memory) {
return _rewards;
}
/**
* @dev execute multi-step arbitrage trade between exchanges using one or more flashloans
*/
function flashloanAndArbV2(
Flashloan[] memory flashloans,
TradeRoute[] memory routes
) public nonReentrant validRouteLength(routes.length) validateFlashloans(flashloans) {
// abi encode the data to be passed in to the flashloan platform
bytes memory encodedData = _encodeFlashloanData(flashloans, routes);
// take flashloan
_takeFlashloan(flashloans[0], encodedData);
// allocate the rewards
(address[] memory sourceTokens, uint256[] memory sourceAmounts) = _extractTokensAndAmounts(flashloans);
_allocateRewards(sourceTokens, sourceAmounts, routes, msg.sender);
}
/**
* @dev callback function for bancor V3 flashloan
* @dev performs the arbitrage trades
*/
function onFlashLoan(
address caller,
IERC20 erc20Token,
uint256 amount,
uint256 feeAmount,
bytes memory data
) external {
// validate inputs
if (msg.sender != address(_bancorNetworkV3) || caller != address(this)) {
revert InvalidFlashLoanCaller();
}
// execute the next flashloan or the arbitrage
_decodeAndActOnFlashloanData(data);
// return the flashloan
Token(address(erc20Token)).safeTransfer(msg.sender, amount + feeAmount);
}
/**
* @dev callback function for Balancer flashloan
*/
function receiveFlashLoan(
IERC20[] memory tokens,
uint256[] memory amounts,
uint256[] memory feeAmounts,
bytes memory userData
) external {
if (msg.sender != address(_balancerVault)) {
revert InvalidFlashLoanCaller();
}
// execute the next flashloan or the arbitrage
_decodeAndActOnFlashloanData(userData);
// return the flashloans
for (uint256 i = 0; i < tokens.length; i = uncheckedInc(i)) {
Token(address(tokens[i])).safeTransfer(msg.sender, amounts[i] + feeAmounts[i]);
}
}
/**
* @dev execute multi-step arbitrage trade between exchanges using user funds
* @dev must approve token before executing the function
*/
function fundAndArb(
TradeRoute[] calldata routes,
Token token,
uint256 sourceAmount
) external payable nonReentrant validRouteLength(routes.length) greaterThanZero(sourceAmount) {
// perform validations
_validateFundAndArbParams(token, routes[routes.length - 1].targetToken, sourceAmount, msg.value);
// transfer the tokens from user
token.safeTransferFrom(msg.sender, address(this), sourceAmount);
// perform the arbitrage
_arbitrageV2(routes);
// return the tokens to the user
// safe due to nonReentrant modifier (forwards all available gas in case of ETH)
token.unsafeTransfer(msg.sender, sourceAmount);
// allocate the rewards
address[] memory sourceTokens = new address[](1);
uint256[] memory sourceAmounts = new uint256[](1);
sourceTokens[0] = address(token);
sourceAmounts[0] = sourceAmount;
_allocateRewards(sourceTokens, sourceAmounts, routes, msg.sender);
}
/**
* @dev perform validations for fundAndArb functions
*/
function _validateFundAndArbParams(
Token token,
Token finalToken,
uint256 sourceAmount,
uint256 value
) private pure {
// verify that the last token in the process is the arb token
if (finalToken != token) {
revert InvalidInitialAndFinalTokens();
}
// validate ETH amount sent with function is correct
if (token.isNative()) {
if (value != sourceAmount) {
revert InvalidETHAmountSent();
}
} else {
if (value > 0) {
revert InvalidETHAmountSent();
}
}
}
/**
* @dev encode the flashloan and route data
*/
function _encodeFlashloanData(
Flashloan[] memory flashloans,
TradeRoute[] memory routes
) private pure returns (bytes memory encodedData) {
Flashloan[] memory remainingFlashloans = new Flashloan[](flashloans.length - 1);
for (uint256 i = 0; i < remainingFlashloans.length; i = uncheckedInc(i)) {
remainingFlashloans[i] = flashloans[uncheckedInc(i)];
}
// abi encode the data to be passed in to the flashloan platform
encodedData = abi.encode(remainingFlashloans, routes);
}
/**
* @dev decode the flashloan data and either execute the next flashloan or the arbitrage
*/
function _decodeAndActOnFlashloanData(bytes memory data) private {
// decode the arb data
(Flashloan[] memory flashloans, TradeRoute[] memory routes) = abi.decode(data, (Flashloan[], TradeRoute[]));
// if the flashloan array is empty, perform the arbitrage
if (flashloans.length == 0) {
_arbitrageV2(routes);
} else {
// else execute the next flashloan in the sequence
// abi encode the data to be passed in to the flashloan platform
data = _encodeFlashloanData(flashloans, routes);
// take flashloan
_takeFlashloan(flashloans[0], data);
}
}
/**
* @dev flashloan logic
*/
function _takeFlashloan(Flashloan memory flashloan, bytes memory data) private {
if (flashloan.platformId == PLATFORM_ID_BANCOR_V3) {
// take a flashloan on Bancor v3, execution continues in `onFlashloan`
_bancorNetworkV3.flashLoan(
Token(address(flashloan.sourceTokens[0])),
flashloan.sourceAmounts[0],
IFlashLoanRecipient(address(this)),
data
);
} else if (flashloan.platformId == PLATFORM_ID_BALANCER) {
// take a flashloan on Balancer, execution continues in `receiveFlashLoan`
_balancerVault.flashLoan(
IBalancerFlashLoanRecipient(address(this)),
castToBalancerTokens(flashloan.sourceTokens),
flashloan.sourceAmounts,
data
);
} else {
// invalid flashloan platform
revert InvalidFlashloanPlatformId();
}
}
/**
* @dev arbitrage logic
*/
function _arbitrageV2(TradeRoute[] memory routes) private {
// perform the trade routes
for (uint256 i = 0; i < routes.length; i = uncheckedInc(i)) {
TradeRoute memory route = routes[i];
uint256 sourceTokenBalance = route.sourceToken.balanceOf(address(this));
uint256 sourceAmount;
if (route.sourceAmount == 0 || route.sourceAmount > sourceTokenBalance) {
sourceAmount = sourceTokenBalance;
} else {
sourceAmount = route.sourceAmount;
}
// perform the trade
_trade(
route.platformId,
route.sourceToken,
route.targetToken,
sourceAmount,
route.minTargetAmount,
route.deadline,
route.customAddress,
route.customInt,
route.customData
);
}
}
/**
* @dev handles the trade logic per route
*/
function _trade(
uint256 platformId,
Token sourceToken,
Token targetToken,
uint256 sourceAmount,
uint256 minTargetAmount,
uint256 deadline,
address customAddress,
uint256 customInt,
bytes memory customData
) private {
if (platformId == PLATFORM_ID_BANCOR_V2) {
// allow the network to withdraw the source tokens
_setPlatformAllowance(sourceToken, address(_bancorNetworkV2), sourceAmount);
// build the conversion path
address[] memory path = new address[](3);
path[0] = address(sourceToken);
path[1] = customAddress; // pool token address
path[2] = address(targetToken);
uint256 val = sourceToken.isNative() ? sourceAmount : 0;
// perform the trade
_bancorNetworkV2.convertByPath{ value: val }(
path,
sourceAmount,
minTargetAmount,
address(0x0),
address(0x0),
0
);
return;
}
if (platformId == PLATFORM_ID_BANCOR_V3) {
// allow the network to withdraw the source tokens
_setPlatformAllowance(sourceToken, address(_bancorNetworkV3), sourceAmount);
uint256 val = sourceToken.isNative() ? sourceAmount : 0;
// perform the trade
_bancorNetworkV3.tradeBySourceAmountArb{ value: val }(
sourceToken,
targetToken,
sourceAmount,
minTargetAmount,
deadline,
address(0x0)
);
return;
}
if (platformId == PLATFORM_ID_UNISWAP_V2_FORK || platformId == PLATFORM_ID_SUSHISWAP) {
IUniswapV2Router02 router;
// if router address is not provided, use default address
if (customAddress == address(0)) {
router = platformId == PLATFORM_ID_UNISWAP_V2_FORK ? _uniswapV2Router : _sushiSwapRouter;
} else {
router = IUniswapV2Router02(customAddress);
}
// allow the router to withdraw the source tokens
_setPlatformAllowance(sourceToken, address(router), sourceAmount);
// build the path
address[] memory path = new address[](2);
// perform the trade
if (sourceToken.isNative()) {
path[0] = address(_weth);
path[1] = address(targetToken);
router.swapExactETHForTokens{ value: sourceAmount }(minTargetAmount, path, address(this), deadline);
} else if (targetToken.isNative()) {
path[0] = address(sourceToken);
path[1] = address(_weth);
router.swapExactTokensForETH(sourceAmount, minTargetAmount, path, address(this), deadline);
} else {
path[0] = address(sourceToken);
path[1] = address(targetToken);
router.swapExactTokensForTokens(sourceAmount, minTargetAmount, path, address(this), deadline);
}
return;
}
if (platformId == PLATFORM_ID_UNISWAP_V3_FORK) {
ISwapRouter router;
// if router address is not provided, use default address
if (customAddress == address(0)) {
router = _uniswapV3Router;
} else {
router = ISwapRouter(customAddress);
}
// allow the router to withdraw the source tokens
_setPlatformAllowance(sourceToken, address(router), sourceAmount);
// build the params
ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams({
tokenIn: address(sourceToken),
tokenOut: address(targetToken),
fee: uint24(customInt), // fee
recipient: address(this),
deadline: deadline,
amountIn: sourceAmount,
amountOutMinimum: minTargetAmount,
sqrtPriceLimitX96: uint160(0)
});
// perform the trade
router.exactInputSingle(params);
return;
}
if (platformId == PLATFORM_ID_CARBON_FORK) {
ICarbonController controller;
// if carbon controller address is not provided, use default address
if (customAddress == address(0)) {
controller = _carbonController;
} else {
controller = ICarbonController(customAddress);
}
// Carbon accepts 2^128 - 1 max for minTargetAmount
if (minTargetAmount > type(uint128).max) {
revert MinTargetAmountTooHigh();
}
// allow the carbon controller to withdraw the source tokens
_setPlatformAllowance(sourceToken, address(controller), sourceAmount);
// decode trade by target flag (if the LSB of customInt is set to 1, we trade by target)
bool tradeByTargetAmount = (customInt & CARBON_TRADE_BY_TARGET_FLAG) == CARBON_TRADE_BY_TARGET_FLAG;
uint256 val = sourceToken.isNative() ? sourceAmount : 0;
// decode the trade actions passed in as customData
TradeAction[] memory tradeActions = abi.decode(customData, (TradeAction[]));
// perform the trade
if (tradeByTargetAmount) {
controller.tradeByTargetAmount{ value: val }(
sourceToken,
targetToken,
tradeActions,
deadline,
uint128(minTargetAmount) // minTargetAmount = maxInput for trade by target
);
} else {
controller.tradeBySourceAmount{ value: val }(
sourceToken,
targetToken,
tradeActions,
deadline,
uint128(minTargetAmount)
);
}
return;
}
if (platformId == PLATFORM_ID_BALANCER) {
IBalancerVault router = _balancerVault;
// allow the router to withdraw the source tokens
_setPlatformAllowance(sourceToken, address(router), sourceAmount);
IBalancerVault.SingleSwap memory singleSwap = IBalancerVault.SingleSwap({
poolId: bytes32(customInt),
kind: IBalancerVault.SwapKind.GIVEN_IN,
assetIn: IBalancerAsset(sourceToken.isNative() ? address(0) : address(sourceToken)),
assetOut: IBalancerAsset(targetToken.isNative() ? address(0) : address(targetToken)),
amount: sourceAmount,
userData: bytes("") // customData
});
IBalancerVault.FundManagement memory funds = IBalancerVault.FundManagement({
sender: address(this),
fromInternalBalance: false,
recipient: payable(address(this)),
toInternalBalance: false
});
// perform the trade
uint256 value = singleSwap.assetIn == IBalancerAsset(address(0)) ? sourceAmount : 0;
router.swap{ value: value }(singleSwap, funds, minTargetAmount, deadline);
return;
}
if (platformId == PLATFORM_ID_CARBON_POL) {
// Carbon POL accepts 2^128 - 1 max for sourceAmount
if (sourceAmount > type(uint128).max) {
revert SourceAmountTooHigh();
}
// verify source token is ETH or BNT
if (!sourceToken.isNative() && !sourceToken.isEqual(_bnt)) {
revert InvalidCarbonPOLTrade();
}
// if source token is BNT, we can only trade it for ETH
if (sourceToken.isEqual(_bnt) && !targetToken.isNative()) {
revert InvalidCarbonPOLTrade();
}
// allow carbon pol to withdraw the source tokens
_setPlatformAllowance(sourceToken, address(_carbonPOL), sourceAmount);
// get the target amount for the trade
uint128 targetAmount = _carbonPOL.expectedTradeReturn(targetToken, uint128(sourceAmount));
// verify the expected return
if (targetAmount < minTargetAmount) {
revert MinTargetAmountNotReached();
}
uint256 val = sourceToken.isNative() ? sourceAmount : 0;
// perform the trade
_carbonPOL.trade{ value: val }(targetToken, targetAmount);
return;
}
if (platformId == PLATFORM_ID_CURVE) {
ICurvePool curvePool = ICurvePool(customAddress);
if (address(curvePool) == address(0)) {
revert InvalidCurvePool();
}
// allow the curve pool to withdraw the source tokens and perform the trade
uint256 val = sourceToken.isNative() ? sourceAmount : 0;
_setPlatformAllowance(sourceToken, address(curvePool), sourceAmount);
curvePool.exchange{ value: val }(
int128(int256(customInt)),
int128(int256(customInt >> 128)),
sourceAmount,
minTargetAmount
);
return;
}
if (platformId == PLATFORM_ID_WETH) {
// Platform WETH accepts only wETH -> ETH and ETH -> wETH trades
if (sourceToken.isNative() && targetToken.isEqual(_weth)) {
IWETH(address(_weth)).deposit{ value: sourceAmount }();
} else if (sourceToken.isEqual(_weth) && targetToken.isNative()) {
IWETH(address(_weth)).withdraw(sourceAmount);
} else {
revert InvalidWethTrade();
}
return;
}
revert InvalidTradePlatformId();
}
/**
* @dev allocates the rewards to the caller and sends the rest to the protocol wallet
*/
function _allocateRewards(
address[] memory sourceTokens,
uint256[] memory sourceAmounts,
TradeRoute[] memory routes,
address caller
) internal {
uint256 tokenLength = sourceTokens.length;
uint256[] memory protocolAmounts = new uint256[](tokenLength);
uint256[] memory rewardAmounts = new uint256[](tokenLength);
// transfer each of the remaining token balances to the caller and protocol wallet
for (uint256 i = 0; i < tokenLength; i = uncheckedInc(i)) {
Token sourceToken = Token(sourceTokens[i]);
uint256 balance = sourceToken.balanceOf(address(this));
uint256 rewardAmount = (balance * _rewards.percentagePPM) / PPM_RESOLUTION;
uint256 protocolAmount;
// safe because _rewards.percentagePPM <= PPM_RESOLUTION
unchecked {
protocolAmount = balance - rewardAmount;
}
// handle protocol amount
if (protocolAmount > 0) {
if (sourceToken.isEqual(_bnt)) {
// if token is bnt burn it directly
// transferring bnt to the token's address triggers a burn
sourceToken.safeTransfer(address(_bnt), protocolAmount);
} else {
// else transfer to protocol wallet
// safe due to nonReentrant modifier (forwards all available gas in case of ETH)
sourceToken.unsafeTransfer(_protocolWallet, protocolAmount);
}
}
// handle reward amount
if (rewardAmount > 0) {
// safe due to nonReentrant modifier (forwards all available gas in case of ETH)
sourceToken.unsafeTransfer(caller, rewardAmount);
}
// set current reward and protocol amounts for the event
rewardAmounts[i] = rewardAmount;
protocolAmounts[i] = protocolAmount;
}
(
uint16[] memory platformIds,
address[] memory path,
address[] memory uniqueTokens,
uint256 uniqueCount
) = _buildArbPath(routes);
// sweep the remaining tokens after the arb
_sweepLeftoverTokens(uniqueTokens, uniqueCount);
emit ArbitrageExecuted(caller, platformIds, path, sourceTokens, sourceAmounts, protocolAmounts, rewardAmounts);
}
/**
* @dev sweep leftover tokens to the protocol wallet
*/
function _sweepLeftoverTokens(address[] memory uniqueTokens, uint256 uniqueCount) private {
for (uint256 i = 0; i < uniqueCount; i = uncheckedInc(i)) {
Token token = Token(uniqueTokens[i]);
uint256 tokenBalance = token.balanceOf(address(this));
if (tokenBalance == 0) {
continue;
}
if (token.isEqual(_bnt)) {
// if token is bnt burn it directly
token.safeTransfer(address(_bnt), tokenBalance);
} else {
// else transfer to protocol wallet
token.unsafeTransfer(_protocolWallet, tokenBalance);
}
}
}
/**
* @dev build arb path from TradeRoute array
*/
function _buildArbPath(
TradeRoute[] memory routes
)
private
pure
returns (uint16[] memory platformIds, address[] memory path, address[] memory uniqueTokens, uint256 uniqueCount)
{
platformIds = new uint16[](routes.length);
path = new address[](routes.length * 2);
uniqueTokens = new address[](routes.length * 2); // Maximum possible unique tokens
uniqueCount = 0;
for (uint256 i = 0; i < routes.length; i = uncheckedInc(i)) {
platformIds[i] = routes[i].platformId;
address sourceAddress = address(routes[i].sourceToken);
address targetAddress = address(routes[i].targetToken);
// Add source and target tokens to path
path[i * 2] = sourceAddress;
path[i * 2 + 1] = targetAddress;
// Check for uniqueness and add to uniqueTokens
if (!_isInArray(sourceAddress, uniqueTokens, uniqueCount)) {
uniqueTokens[uniqueCount] = sourceAddress;
uniqueCount = uncheckedInc(uniqueCount);
}
if (!_isInArray(targetAddress, uniqueTokens, uniqueCount)) {
uniqueTokens[uniqueCount] = targetAddress;
uniqueCount = uncheckedInc(uniqueCount);
}
}
return (platformIds, path, uniqueTokens, uniqueCount);
}
/**
* @dev extract tokens and amounts from Flashloan array
*/
function _extractTokensAndAmounts(
Flashloan[] memory flashloans
) private pure returns (address[] memory, uint256[] memory) {
uint256 totalLength = 0;
for (uint256 i = 0; i < flashloans.length; i = uncheckedInc(i)) {
totalLength += flashloans[i].sourceTokens.length;
}
address[] memory tokens = new address[](totalLength);
uint256[] memory amounts = new uint256[](totalLength);
uint256 index = 0;
for (uint256 i = 0; i < flashloans.length; i = uncheckedInc(i)) {
for (uint256 j = 0; j < flashloans[i].sourceTokens.length; j = uncheckedInc(j)) {
tokens[index] = address(flashloans[i].sourceTokens[j]);
amounts[index] = flashloans[i].sourceAmounts[j];
index = uncheckedInc(index);
}
}
return (tokens, amounts);
}
/**
* @dev set platform allowance to the max amount if it's less than the input amount
*/
function _setPlatformAllowance(Token token, address platform, uint256 inputAmount) private {
if (token.isNative()) {
return;
}
uint256 allowance = token.toIERC20().allowance(address(this), platform);
if (allowance < inputAmount) {
// increase allowance to the max amount if allowance < inputAmount
token.forceApprove(platform, type(uint256).max);
}
}
/**
* @dev check if an address is in an array
*/
function _isInArray(address element, address[] memory array, uint256 arrayLength) private pure returns (bool) {
for (uint256 i = 0; i < arrayLength; i = uncheckedInc(i)) {
if (array[i] == element) {
return true;
}
}
return false;
}
function uncheckedInc(uint256 i) private pure returns (uint256 j) {
unchecked {
j = i + 1;
}
}
/**
* @dev perform various checks for flashloan source tokens and amounts
* check if any of the flashloan amounts are zero in value
*/
modifier validateFlashloans(Flashloan[] memory flashloans) {
if (flashloans.length == 0) {
revert InvalidFlashloanFormat();
}
for (uint256 i = 0; i < flashloans.length; i = uncheckedInc(i)) {
Flashloan memory flashloan = flashloans[i];
uint256[] memory sourceAmounts = flashloan.sourceAmounts;
uint256 numOfSourceTokens = flashloan.sourceTokens.length;
uint256 numOfSourceAmounts = sourceAmounts.length;
if (
numOfSourceTokens == 0 ||
numOfSourceTokens != numOfSourceAmounts ||
(flashloan.platformId == PLATFORM_ID_BANCOR_V3 && numOfSourceTokens > 1)
) {
revert InvalidFlashloanFormat();
}
// check source amounts are not zero in value
for (uint256 j = 0; j < numOfSourceAmounts; j = uncheckedInc(j)) {
if (sourceAmounts[j] == 0) {
revert ZeroValue();
}
}
}
_;
}
}// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
interface IAuthentication {
/**
* @dev Returns the action identifier associated with the external function described by `selector`.
*/
function getActionId(bytes4 selector) external view returns (bytes32);
}// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
/**
* @dev Interface for the SignatureValidator helper, used to support meta-transactions.
*/
interface ISignaturesValidator {
/**
* @dev Returns the EIP712 domain separator.
*/
function getDomainSeparator() external view returns (bytes32);
/**
* @dev Returns the next nonce used by an address to sign messages.
*/
function getNextNonce(address user) external view returns (uint256);
}// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
/**
* @dev Interface for the TemporarilyPausable helper.
*/
interface ITemporarilyPausable {
/**
* @dev Emitted every time the pause state changes by `_setPaused`.
*/
event PausedStateChanged(bool paused);
/**
* @dev Returns the current paused state.
*/
function getPausedState()
external
view
returns (
bool paused,
uint256 pauseWindowEndTime,
uint256 bufferPeriodEndTime
);
}// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
import "../openzeppelin/IERC20.sol";
/**
* @dev Interface for WETH9.
* See https://github.com/gnosis/canonical-weth/blob/0dd1ea3e295eef916d0c6223ec63141137d22d67/contracts/WETH9.sol
*/
interface IWETH is IERC20 {
function deposit() external payable;
function withdraw(uint256 amount) external;
}// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
/**
* @dev This is an empty interface used to represent either ERC20-conforming token contracts or ETH (using the zero
* address sentinel value). We're just relying on the fact that `interface` can be used to declare new address-like
* types.
*
* This concept is unrelated to a Pool's Asset Managers.
*/
interface IAsset {
// solhint-disable-previous-line no-empty-blocks
}// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
interface IAuthorizer {
/**
* @dev Returns true if `account` can perform the action described by `actionId` in the contract `where`.
*/
function canPerform(
bytes32 actionId,
address account,
address where
) external view returns (bool);
}// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
// Inspired by Aave Protocol's IFlashLoanReceiver.
import "../solidity-utils/openzeppelin/IERC20.sol";
interface IFlashLoanRecipient {
/**
* @dev When `flashLoan` is called on the Vault, it invokes the `receiveFlashLoan` hook on the recipient.
*
* At the time of the call, the Vault will have transferred `amounts` for `tokens` to the recipient. Before this
* call returns, the recipient must have transferred `amounts` plus `feeAmounts` for each token back to the
* Vault, or else the entire flash loan will revert.
*
* `userData` is the same value passed in the `IVault.flashLoan` call.
*/
function receiveFlashLoan(
IERC20[] memory tokens,
uint256[] memory amounts,
uint256[] memory feeAmounts,
bytes memory userData
) external;
}// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;
import "../solidity-utils/openzeppelin/IERC20.sol";
import "./IVault.sol";
import "./IAuthorizer.sol";
interface IProtocolFeesCollector {
event SwapFeePercentageChanged(uint256 newSwapFeePercentage);
event FlashLoanFeePercentageChanged(uint256 newFlashLoanFeePercentage);
function withdrawCollectedFees(
IERC20[] calldata tokens,
uint256[] calldata amounts,
address recipient
) external;
function setSwapFeePercentage(uint256 newSwapFeePercentage) external;
function setFlashLoanFeePercentage(uint256 newFlashLoanFeePercentage) external;
function getSwapFeePercentage() external view returns (uint256);
function getFlashLoanFeePercentage() external view returns (uint256);
function getCollectedFeeAmounts(IERC20[] memory tokens) external view returns (uint256[] memory feeAmounts);
function getAuthorizer() external view returns (IAuthorizer);
function vault() external view returns (IVault);
}// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma experimental ABIEncoderV2;
import "../solidity-utils/openzeppelin/IERC20.sol";
import "../solidity-utils/helpers/IAuthentication.sol";
import "../solidity-utils/helpers/ISignaturesValidator.sol";
import "../solidity-utils/helpers/ITemporarilyPausable.sol";
import "../solidity-utils/misc/IWETH.sol";
import "./IAsset.sol";
import "./IAuthorizer.sol";
import "./IFlashLoanRecipient.sol";
import "./IProtocolFeesCollector.sol";
pragma solidity >=0.7.0 <0.9.0;
/**
* @dev Full external interface for the Vault core contract - no external or public methods exist in the contract that
* don't override one of these declarations.
*/
interface IVault is ISignaturesValidator, ITemporarilyPausable, IAuthentication {
// Generalities about the Vault:
//
// - Whenever documentation refers to 'tokens', it strictly refers to ERC20-compliant token contracts. Tokens are
// transferred out of the Vault by calling the `IERC20.transfer` function, and transferred in by calling
// `IERC20.transferFrom`. In these cases, the sender must have previously allowed the Vault to use their tokens by
// calling `IERC20.approve`. The only deviation from the ERC20 standard that is supported is functions not returning
// a boolean value: in these scenarios, a non-reverting call is assumed to be successful.
//
// - All non-view functions in the Vault are non-reentrant: calling them while another one is mid-execution (e.g.
// while execution control is transferred to a token contract during a swap) will result in a revert. View
// functions can be called in a re-reentrant way, but doing so might cause them to return inconsistent results.
// Contracts calling view functions in the Vault must make sure the Vault has not already been entered.
//
// - View functions revert if referring to either unregistered Pools, or unregistered tokens for registered Pools.
// Authorizer
//
// Some system actions are permissioned, like setting and collecting protocol fees. This permissioning system exists
// outside of the Vault in the Authorizer contract: the Vault simply calls the Authorizer to check if the caller
// can perform a given action.
/**
* @dev Returns the Vault's Authorizer.
*/
function getAuthorizer() external view returns (IAuthorizer);
/**
* @dev Sets a new Authorizer for the Vault. The caller must be allowed by the current Authorizer to do this.
*
* Emits an `AuthorizerChanged` event.
*/
function setAuthorizer(IAuthorizer newAuthorizer) external;
/**
* @dev Emitted when a new authorizer is set by `setAuthorizer`.
*/
event AuthorizerChanged(IAuthorizer indexed newAuthorizer);
// Relayers
//
// Additionally, it is possible for an account to perform certain actions on behalf of another one, using their
// Vault ERC20 allowance and Internal Balance. These accounts are said to be 'relayers' for these Vault functions,
// and are expected to be smart contracts with sound authentication mechanisms. For an account to be able to wield
// this power, two things must occur:
// - The Authorizer must grant the account the permission to be a relayer for the relevant Vault function. This
// means that Balancer governance must approve each individual contract to act as a relayer for the intended
// functions.
// - Each user must approve the relayer to act on their behalf.
// This double protection means users cannot be tricked into approving malicious relayers (because they will not
// have been allowed by the Authorizer via governance), nor can malicious relayers approved by a compromised
// Authorizer or governance drain user funds, since they would also need to be approved by each individual user.
/**
* @dev Returns true if `user` has approved `relayer` to act as a relayer for them.
*/
function hasApprovedRelayer(address user, address relayer) external view returns (bool);
/**
* @dev Allows `relayer` to act as a relayer for `sender` if `approved` is true, and disallows it otherwise.
*
* Emits a `RelayerApprovalChanged` event.
*/
function setRelayerApproval(
address sender,
address relayer,
bool approved
) external;
/**
* @dev Emitted every time a relayer is approved or disapproved by `setRelayerApproval`.
*/
event RelayerApprovalChanged(address indexed relayer, address indexed sender, bool approved);
// Internal Balance
//
// Users can deposit tokens into the Vault, where they are allocated to their Internal Balance, and later
// transferred or withdrawn. It can also be used as a source of tokens when joining Pools, as a destination
// when exiting them, and as either when performing swaps. This usage of Internal Balance results in greatly reduced
// gas costs when compared to relying on plain ERC20 transfers, leading to large savings for frequent users.
//
// Internal Balance management features batching, which means a single contract call can be used to perform multiple
// operations of different kinds, with different senders and recipients, at once.
/**
* @dev Returns `user`'s Internal Balance for a set of tokens.
*/
function getInternalBalance(address user, IERC20[] memory tokens) external view returns (uint256[] memory);
/**
* @dev Performs a set of user balance operations, which involve Internal Balance (deposit, withdraw or transfer)
* and plain ERC20 transfers using the Vault's allowance. This last feature is particularly useful for relayers, as
* it lets integrators reuse a user's Vault allowance.
*
* For each operation, if the caller is not `sender`, it must be an authorized relayer for them.
*/
function manageUserBalance(UserBalanceOp[] memory ops) external payable;
/**
* @dev Data for `manageUserBalance` operations, which include the possibility for ETH to be sent and received
without manual WETH wrapping or unwrapping.
*/
struct UserBalanceOp {
UserBalanceOpKind kind;
IAsset asset;
uint256 amount;
address sender;
address payable recipient;
}
// There are four possible operations in `manageUserBalance`:
//
// - DEPOSIT_INTERNAL
// Increases the Internal Balance of the `recipient` account by transferring tokens from the corresponding
// `sender`. The sender must have allowed the Vault to use their tokens via `IERC20.approve()`.
//
// ETH can be used by passing the ETH sentinel value as the asset and forwarding ETH in the call: it will be wrapped
// and deposited as WETH. Any ETH amount remaining will be sent back to the caller (not the sender, which is
// relevant for relayers).
//
// Emits an `InternalBalanceChanged` event.
//
//
// - WITHDRAW_INTERNAL
// Decreases the Internal Balance of the `sender` account by transferring tokens to the `recipient`.
//
// ETH can be used by passing the ETH sentinel value as the asset. This will deduct WETH instead, unwrap it and send
// it to the recipient as ETH.
//
// Emits an `InternalBalanceChanged` event.
//
//
// - TRANSFER_INTERNAL
// Transfers tokens from the Internal Balance of the `sender` account to the Internal Balance of `recipient`.
//
// Reverts if the ETH sentinel value is passed.
//
// Emits an `InternalBalanceChanged` event.
//
//
// - TRANSFER_EXTERNAL
// Transfers tokens from `sender` to `recipient`, using the Vault's ERC20 allowance. This is typically used by
// relayers, as it lets them reuse a user's Vault allowance.
//
// Reverts if the ETH sentinel value is passed.
//
// Emits an `ExternalBalanceTransfer` event.
enum UserBalanceOpKind { DEPOSIT_INTERNAL, WITHDRAW_INTERNAL, TRANSFER_INTERNAL, TRANSFER_EXTERNAL }
/**
* @dev Emitted when a user's Internal Balance changes, either from calls to `manageUserBalance`, or through
* interacting with Pools using Internal Balance.
*
* Because Internal Balance works exclusively with ERC20 tokens, ETH deposits and withdrawals will use the WETH
* address.
*/
event InternalBalanceChanged(address indexed user, IERC20 indexed token, int256 delta);
/**
* @dev Emitted when a user's Vault ERC20 allowance is used by the Vault to transfer tokens to an external account.
*/
event ExternalBalanceTransfer(IERC20 indexed token, address indexed sender, address recipient, uint256 amount);
// Pools
//
// There are three specialization settings for Pools, which allow for cheaper swaps at the cost of reduced
// functionality:
//
// - General: no specialization, suited for all Pools. IGeneralPool is used for swap request callbacks, passing the
// balance of all tokens in the Pool. These Pools have the largest swap costs (because of the extra storage reads),
// which increase with the number of registered tokens.
//
// - Minimal Swap Info: IMinimalSwapInfoPool is used instead of IGeneralPool, which saves gas by only passing the
// balance of the two tokens involved in the swap. This is suitable for some pricing algorithms, like the weighted
// constant product one popularized by Balancer V1. Swap costs are smaller compared to general Pools, and are
// independent of the number of registered tokens.
//
// - Two Token: only allows two tokens to be registered. This achieves the lowest possible swap gas cost. Like
// minimal swap info Pools, these are called via IMinimalSwapInfoPool.
enum PoolSpecialization { GENERAL, MINIMAL_SWAP_INFO, TWO_TOKEN }
/**
* @dev Registers the caller account as a Pool with a given specialization setting. Returns the Pool's ID, which
* is used in all Pool-related functions. Pools cannot be deregistered, nor can the Pool's specialization be
* changed.
*
* The caller is expected to be a smart contract that implements either `IGeneralPool` or `IMinimalSwapInfoPool`,
* depending on the chosen specialization setting. This contract is known as the Pool's contract.
*
* Note that the same contract may register itself as multiple Pools with unique Pool IDs, or in other words,
* multiple Pools may share the same contract.
*
* Emits a `PoolRegistered` event.
*/
function registerPool(PoolSpecialization specialization) external returns (bytes32);
/**
* @dev Emitted when a Pool is registered by calling `registerPool`.
*/
event PoolRegistered(bytes32 indexed poolId, address indexed poolAddress, PoolSpecialization specialization);
/**
* @dev Returns a Pool's contract address and specialization setting.
*/
function getPool(bytes32 poolId) external view returns (address, PoolSpecialization);
/**
* @dev Registers `tokens` for the `poolId` Pool. Must be called by the Pool's contract.
*
* Pools can only interact with tokens they have registered. Users join a Pool by transferring registered tokens,
* exit by receiving registered tokens, and can only swap registered tokens.
*
* Each token can only be registered once. For Pools with the Two Token specialization, `tokens` must have a length
* of two, that is, both tokens must be registered in the same `registerTokens` call, and they must be sorted in
* ascending order.
*
* The `tokens` and `assetManagers` arrays must have the same length, and each entry in these indicates the Asset
* Manager for the corresponding token. Asset Managers can manage a Pool's tokens via `managePoolBalance`,
* depositing and withdrawing them directly, and can even set their balance to arbitrary amounts. They are therefore
* expected to be highly secured smart contracts with sound design principles, and the decision to register an
* Asset Manager should not be made lightly.
*
* Pools can choose not to assign an Asset Manager to a given token by passing in the zero address. Once an Asset
* Manager is set, it cannot be changed except by deregistering the associated token and registering again with a
* different Asset Manager.
*
* Emits a `TokensRegistered` event.
*/
function registerTokens(
bytes32 poolId,
IERC20[] memory tokens,
address[] memory assetManagers
) external;
/**
* @dev Emitted when a Pool registers tokens by calling `registerTokens`.
*/
event TokensRegistered(bytes32 indexed poolId, IERC20[] tokens, address[] assetManagers);
/**
* @dev Deregisters `tokens` for the `poolId` Pool. Must be called by the Pool's contract.
*
* Only registered tokens (via `registerTokens`) can be deregistered. Additionally, they must have zero total
* balance. For Pools with the Two Token specialization, `tokens` must have a length of two, that is, both tokens
* must be deregistered in the same `deregisterTokens` call.
*
* A deregistered token can be re-registered later on, possibly with a different Asset Manager.
*
* Emits a `TokensDeregistered` event.
*/
function deregisterTokens(bytes32 poolId, IERC20[] memory tokens) external;
/**
* @dev Emitted when a Pool deregisters tokens by calling `deregisterTokens`.
*/
event TokensDeregistered(bytes32 indexed poolId, IERC20[] tokens);
/**
* @dev Returns detailed information for a Pool's registered token.
*
* `cash` is the number of tokens the Vault currently holds for the Pool. `managed` is the number of tokens
* withdrawn and held outside the Vault by the Pool's token Asset Manager. The Pool's total balance for `token`
* equals the sum of `cash` and `managed`.
*
* Internally, `cash` and `managed` are stored using 112 bits. No action can ever cause a Pool's token `cash`,
* `managed` or `total` balance to be greater than 2^112 - 1.
*
* `lastChangeBlock` is the number of the block in which `token`'s total balance was last modified (via either a
* join, exit, swap, or Asset Manager update). This value is useful to avoid so-called 'sandwich attacks', for
* example when developing price oracles. A change of zero (e.g. caused by a swap with amount zero) is considered a
* change for this purpose, and will update `lastChangeBlock`.
*
* `assetManager` is the Pool's token Asset Manager.
*/
function getPoolTokenInfo(bytes32 poolId, IERC20 token)
external
view
returns (
uint256 cash,
uint256 managed,
uint256 lastChangeBlock,
address assetManager
);
/**
* @dev Returns a Pool's registered tokens, the total balance for each, and the latest block when *any* of
* the tokens' `balances` changed.
*
* The order of the `tokens` array is the same order that will be used in `joinPool`, `exitPool`, as well as in all
* Pool hooks (where applicable). Calls to `registerTokens` and `deregisterTokens` may change this order.
*
* If a Pool only registers tokens once, and these are sorted in ascending order, they will be stored in the same
* order as passed to `registerTokens`.
*
* Total balances include both tokens held by the Vault and those withdrawn by the Pool's Asset Managers. These are
* the amounts used by joins, exits and swaps. For a detailed breakdown of token balances, use `getPoolTokenInfo`
* instead.
*/
function getPoolTokens(bytes32 poolId)
external
view
returns (
IERC20[] memory tokens,
uint256[] memory balances,
uint256 lastChangeBlock
);
/**
* @dev Called by users to join a Pool, which transfers tokens from `sender` into the Pool's balance. This will
* trigger custom Pool behavior, which will typically grant something in return to `recipient` - often tokenized
* Pool shares.
*
* If the caller is not `sender`, it must be an authorized relayer for them.
*
* The `assets` and `maxAmountsIn` arrays must have the same length, and each entry indicates the maximum amount
* to send for each asset. The amounts to send are decided by the Pool and not the Vault: it just enforces
* these maximums.
*
* If joining a Pool that holds WETH, it is possible to send ETH directly: the Vault will do the wrapping. To enable
* this mechanism, the IAsset sentinel value (the zero address) must be passed in the `assets` array instead of the
* WETH address. Note that it is not possible to combine ETH and WETH in the same join. Any excess ETH will be sent
* back to the caller (not the sender, which is important for relayers).
*
* `assets` must have the same length and order as the array returned by `getPoolTokens`. This prevents issues when
* interacting with Pools that register and deregister tokens frequently. If sending ETH however, the array must be
* sorted *before* replacing the WETH address with the ETH sentinel value (the zero address), which means the final
* `assets` array might not be sorted. Pools with no registered tokens cannot be joined.
*
* If `fromInternalBalance` is true, the caller's Internal Balance will be preferred: ERC20 transfers will only
* be made for the difference between the requested amount and Internal Balance (if any). Note that ETH cannot be
* withdrawn from Internal Balance: attempting to do so will trigger a revert.
*
* This causes the Vault to call the `IBasePool.onJoinPool` hook on the Pool's contract, where Pools implement
* their own custom logic. This typically requires additional information from the user (such as the expected number
* of Pool shares). This can be encoded in the `userData` argument, which is ignored by the Vault and passed
* directly to the Pool's contract, as is `recipient`.
*
* Emits a `PoolBalanceChanged` event.
*/
function joinPool(
bytes32 poolId,
address sender,
address recipient,
JoinPoolRequest memory request
) external payable;
struct JoinPoolRequest {
IAsset[] assets;
uint256[] maxAmountsIn;
bytes userData;
bool fromInternalBalance;
}
/**
* @dev Called by users to exit a Pool, which transfers tokens from the Pool's balance to `recipient`. This will
* trigger custom Pool behavior, which will typically ask for something in return from `sender` - often tokenized
* Pool shares. The amount of tokens that can be withdrawn is limited by the Pool's `cash` balance (see
* `getPoolTokenInfo`).
*
* If the caller is not `sender`, it must be an authorized relayer for them.
*
* The `tokens` and `minAmountsOut` arrays must have the same length, and each entry in these indicates the minimum
* token amount to receive for each token contract. The amounts to send are decided by the Pool and not the Vault:
* it just enforces these minimums.
*
* If exiting a Pool that holds WETH, it is possible to receive ETH directly: the Vault will do the unwrapping. To
* enable this mechanism, the IAsset sentinel value (the zero address) must be passed in the `assets` array instead
* of the WETH address. Note that it is not possible to combine ETH and WETH in the same exit.
*
* `assets` must have the same length and order as the array returned by `getPoolTokens`. This prevents issues when
* interacting with Pools that register and deregister tokens frequently. If receiving ETH however, the array must
* be sorted *before* replacing the WETH address with the ETH sentinel value (the zero address), which means the
* final `assets` array might not be sorted. Pools with no registered tokens cannot be exited.
*
* If `toInternalBalance` is true, the tokens will be deposited to `recipient`'s Internal Balance. Otherwise,
* an ERC20 transfer will be performed. Note that ETH cannot be deposited to Internal Balance: attempting to
* do so will trigger a revert.
*
* `minAmountsOut` is the minimum amount of tokens the user expects to get out of the Pool, for each token in the
* `tokens` array. This array must match the Pool's registered tokens.
*
* This causes the Vault to call the `IBasePool.onExitPool` hook on the Pool's contract, where Pools implement
* their own custom logic. This typically requires additional information from the user (such as the expected number
* of Pool shares to return). This can be encoded in the `userData` argument, which is ignored by the Vault and
* passed directly to the Pool's contract.
*
* Emits a `PoolBalanceChanged` event.
*/
function exitPool(
bytes32 poolId,
address sender,
address payable recipient,
ExitPoolRequest memory request
) external;
struct ExitPoolRequest {
IAsset[] assets;
uint256[] minAmountsOut;
bytes userData;
bool toInternalBalance;
}
/**
* @dev Emitted when a user joins or exits a Pool by calling `joinPool` or `exitPool`, respectively.
*/
event PoolBalanceChanged(
bytes32 indexed poolId,
address indexed liquidityProvider,
IERC20[] tokens,
int256[] deltas,
uint256[] protocolFeeAmounts
);
enum PoolBalanceChangeKind { JOIN, EXIT }
// Swaps
//
// Users can swap tokens with Pools by calling the `swap` and `batchSwap` functions. To do this,
// they need not trust Pool contracts in any way: all security checks are made by the Vault. They must however be
// aware of the Pools' pricing algorithms in order to estimate the prices Pools will quote.
//
// The `swap` function executes a single swap, while `batchSwap` can perform multiple swaps in sequence.
// In each individual swap, tokens of one kind are sent from the sender to the Pool (this is the 'token in'),
// and tokens of another kind are sent from the Pool to the recipient in exchange (this is the 'token out').
// More complex swaps, such as one token in to multiple tokens out can be achieved by batching together
// individual swaps.
//
// There are two swap kinds:
// - 'given in' swaps, where the amount of tokens in (sent to the Pool) is known, and the Pool determines (via the
// `onSwap` hook) the amount of tokens out (to send to the recipient).
// - 'given out' swaps, where the amount of tokens out (received from the Pool) is known, and the Pool determines
// (via the `onSwap` hook) the amount of tokens in (to receive from the sender).
//
// Additionally, it is possible to chain swaps using a placeholder input amount, which the Vault replaces with
// the calculated output of the previous swap. If the previous swap was 'given in', this will be the calculated
// tokenOut amount. If the previous swap was 'given out', it will use the calculated tokenIn amount. These extended
// swaps are known as 'multihop' swaps, since they 'hop' through a number of intermediate tokens before arriving at
// the final intended token.
//
// In all cases, tokens are only transferred in and out of the Vault (or withdrawn from and deposited into Internal
// Balance) after all individual swaps have been completed, and the net token balance change computed. This makes
// certain swap patterns, such as multihops, or swaps that interact with the same token pair in multiple Pools, cost
// much less gas than they would otherwise.
//
// It also means that under certain conditions it is possible to perform arbitrage by swapping with multiple
// Pools in a way that results in net token movement out of the Vault (profit), with no tokens being sent in (only
// updating the Pool's internal accounting).
//
// To protect users from front-running or the market changing rapidly, they supply a list of 'limits' for each token
// involved in the swap, where either the maximum number of tokens to send (by passing a positive value) or the
// minimum amount of tokens to receive (by passing a negative value) is specified.
//
// Additionally, a 'deadline' timestamp can also be provided, forcing the swap to fail if it occurs after
// this point in time (e.g. if the transaction failed to be included in a block promptly).
//
// If interacting with Pools that hold WETH, it is possible to both send and receive ETH directly: the Vault will do
// the wrapping and unwrapping. To enable this mechanism, the IAsset sentinel value (the zero address) must be
// passed in the `assets` array instead of the WETH address. Note that it is possible to combine ETH and WETH in the
// same swap. Any excess ETH will be sent back to the caller (not the sender, which is relevant for relayers).
//
// Finally, Internal Balance can be used when either sending or receiving tokens.
enum SwapKind { GIVEN_IN, GIVEN_OUT }
/**
* @dev Performs a swap with a single Pool.
*
* If the swap is 'given in' (the number of tokens to send to the Pool is known), it returns the amount of tokens
* taken from the Pool, which must be greater than or equal to `limit`.
*
* If the swap is 'given out' (the number of tokens to take from the Pool is known), it returns the amount of tokens
* sent to the Pool, which must be less than or equal to `limit`.
*
* Internal Balance usage and the recipient are determined by the `funds` struct.
*
* Emits a `Swap` event.
*/
function swap(
SingleSwap memory singleSwap,
FundManagement memory funds,
uint256 limit,
uint256 deadline
) external payable returns (uint256);
/**
* @dev Data for a single swap executed by `swap`. `amount` is either `amountIn` or `amountOut` depending on
* the `kind` value.
*
* `assetIn` and `assetOut` are either token addresses, or the IAsset sentinel value for ETH (the zero address).
* Note that Pools never interact with ETH directly: it will be wrapped to or unwrapped from WETH by the Vault.
*
* The `userData` field is ignored by the Vault, but forwarded to the Pool in the `onSwap` hook, and may be
* used to extend swap behavior.
*/
struct SingleSwap {
bytes32 poolId;
SwapKind kind;
IAsset assetIn;
IAsset assetOut;
uint256 amount;
bytes userData;
}
/**
* @dev Performs a series of swaps with one or multiple Pools. In each individual swap, the caller determines either
* the amount of tokens sent to or received from the Pool, depending on the `kind` value.
*
* Returns an array with the net Vault asset balance deltas. Positive amounts represent tokens (or ETH) sent to the
* Vault, and negative amounts represent tokens (or ETH) sent by the Vault. Each delta corresponds to the asset at
* the same index in the `assets` array.
*
* Swaps are executed sequentially, in the order specified by the `swaps` array. Each array element describes a
* Pool, the token to be sent to this Pool, the token to receive from it, and an amount that is either `amountIn` or
* `amountOut` depending on the swap kind.
*
* Multihop swaps can be executed by passing an `amount` value of zero for a swap. This will cause the amount in/out
* of the previous swap to be used as the amount in for the current one. In a 'given in' swap, 'tokenIn' must equal
* the previous swap's `tokenOut`. For a 'given out' swap, `tokenOut` must equal the previous swap's `tokenIn`.
*
* The `assets` array contains the addresses of all assets involved in the swaps. These are either token addresses,
* or the IAsset sentinel value for ETH (the zero address). Each entry in the `swaps` array specifies tokens in and
* out by referencing an index in `assets`. Note that Pools never interact with ETH directly: it will be wrapped to
* or unwrapped from WETH by the Vault.
*
* Internal Balance usage, sender, and recipient are determined by the `funds` struct. The `limits` array specifies
* the minimum or maximum amount of each token the vault is allowed to transfer.
*
* `batchSwap` can be used to make a single swap, like `swap` does, but doing so requires more gas than the
* equivalent `swap` call.
*
* Emits `Swap` events.
*/
function batchSwap(
SwapKind kind,
BatchSwapStep[] memory swaps,
IAsset[] memory assets,
FundManagement memory funds,
int256[] memory limits,
uint256 deadline
) external payable returns (int256[] memory);
/**
* @dev Data for each individual swap executed by `batchSwap`. The asset in and out fields are indexes into the
* `assets` array passed to that function, and ETH assets are converted to WETH.
*
* If `amount` is zero, the multihop mechanism is used to determine the actual amount based on the amount in/out
* from the previous swap, depending on the swap kind.
*
* The `userData` field is ignored by the Vault, but forwarded to the Pool in the `onSwap` hook, and may be
* used to extend swap behavior.
*/
struct BatchSwapStep {
bytes32 poolId;
uint256 assetInIndex;
uint256 assetOutIndex;
uint256 amount;
bytes userData;
}
/**
* @dev Emitted for each individual swap performed by `swap` or `batchSwap`.
*/
event Swap(
bytes32 indexed poolId,
IERC20 indexed tokenIn,
IERC20 indexed tokenOut,
uint256 amountIn,
uint256 amountOut
);
/**
* @dev All tokens in a swap are either sent from the `sender` account to the Vault, or from the Vault to the
* `recipient` account.
*
* If the caller is not `sender`, it must be an authorized relayer for them.
*
* If `fromInternalBalance` is true, the `sender`'s Internal Balance will be preferred, performing an ERC20
* transfer for the difference between the requested amount and the User's Internal Balance (if any). The `sender`
* must have allowed the Vault to use their tokens via `IERC20.approve()`. This matches the behavior of
* `joinPool`.
*
* If `toInternalBalance` is true, tokens will be deposited to `recipient`'s internal balance instead of
* transferred. This matches the behavior of `exitPool`.
*
* Note that ETH cannot be deposited to or withdrawn from Internal Balance: attempting to do so will trigger a
* revert.
*/
struct FundManagement {
address sender;
bool fromInternalBalance;
address payable recipient;
bool toInternalBalance;
}
/**
* @dev Simulates a call to `batchSwap`, returning an array of Vault asset deltas. Calls to `swap` cannot be
* simulated directly, but an equivalent `batchSwap` call can and will yield the exact same result.
*
* Each element in the array corresponds to the asset at the same index, and indicates the number of tokens (or ETH)
* the Vault would take from the sender (if positive) or send to the recipient (if negative). The arguments it
* receives are the same that an equivalent `batchSwap` call would receive.
*
* Unlike `batchSwap`, this function performs no checks on the sender or recipient field in the `funds` struct.
* This makes it suitable to be called by off-chain applications via eth_call without needing to hold tokens,
* approve them for the Vault, or even know a user's address.
*
* Note that this function is not 'view' (due to implementation details): the client code must explicitly execute
* eth_call instead of eth_sendTransaction.
*/
function queryBatchSwap(
SwapKind kind,
BatchSwapStep[] memory swaps,
IAsset[] memory assets,
FundManagement memory funds
) external returns (int256[] memory assetDeltas);
// Flash Loans
/**
* @dev Performs a 'flash loan', sending tokens to `recipient`, executing the `receiveFlashLoan` hook on it,
* and then reverting unless the tokens plus a proportional protocol fee have been returned.
*
* The `tokens` and `amounts` arrays must have the same length, and each entry in these indicates the loan amount
* for each token contract. `tokens` must be sorted in ascending order.
*
* The 'userData' field is ignored by the Vault, and forwarded as-is to `recipient` as part of the
* `receiveFlashLoan` call.
*
* Emits `FlashLoan` events.
*/
function flashLoan(
IFlashLoanRecipient recipient,
IERC20[] memory tokens,
uint256[] memory amounts,
bytes memory userData
) external;
/**
* @dev Emitted for each individual flash loan performed by `flashLoan`.
*/
event FlashLoan(IFlashLoanRecipient indexed recipient, IERC20 indexed token, uint256 amount, uint256 feeAmount);
// Asset Management
//
// Each token registered for a Pool can be assigned an Asset Manager, which is able to freely withdraw the Pool's
// tokens from the Vault, deposit them, or assign arbitrary values to its `managed` balance (see
// `getPoolTokenInfo`). This makes them extremely powerful and dangerous. Even if an Asset Manager only directly
// controls one of the tokens in a Pool, a malicious manager could set that token's balance to manipulate the
// prices of the other tokens, and then drain the Pool with swaps. The risk of using Asset Managers is therefore
// not constrained to the tokens they are managing, but extends to the entire Pool's holdings.
//
// However, a properly designed Asset Manager smart contract can be safely used for the Pool's benefit,
// for example by lending unused tokens out for interest, or using them to participate in voting protocols.
//
// This concept is unrelated to the IAsset interface.
/**
* @dev Performs a set of Pool balance operations, which may be either withdrawals, deposits or updates.
*
* Pool Balance management features batching, which means a single contract call can be used to perform multiple
* operations of different kinds, with different Pools and tokens, at once.
*
* For each operation, the caller must be registered as the Asset Manager for `token` in `poolId`.
*/
function managePoolBalance(PoolBalanceOp[] memory ops) external;
struct PoolBalanceOp {
PoolBalanceOpKind kind;
bytes32 poolId;
IERC20 token;
uint256 amount;
}
/**
* Withdrawals decrease the Pool's cash, but increase its managed balance, leaving the total balance unchanged.
*
* Deposits increase the Pool's cash, but decrease its managed balance, leaving the total balance unchanged.
*
* Updates don't affect the Pool's cash balance, but because the managed balance changes, it does alter the total.
* The external amount can be either increased or decreased by this call (i.e., reporting a gain or a loss).
*/
enum PoolBalanceOpKind { WITHDRAW, DEPOSIT, UPDATE }
/**
* @dev Emitted when a Pool's token Asset Manager alters its balance via `managePoolBalance`.
*/
event PoolBalanceManaged(
bytes32 indexed poolId,
address indexed assetManager,
IERC20 indexed token,
int256 cashDelta,
int256 managedDelta
);
// Protocol Fees
//
// Some operations cause the Vault to collect tokens in the form of protocol fees, which can then be withdrawn by
// permissioned accounts.
//
// There are two kinds of protocol fees:
//
// - flash loan fees: charged on all flash loans, as a percentage of the amounts lent.
//
// - swap fees: a percentage of the fees charged by Pools when performing swaps. For a number of reasons, including
// swap gas costs and interface simplicity, protocol swap fees are not charged on each individual swap. Rather,
// Pools are expected to keep track of how much they have charged in swap fees, and pay any outstanding debts to the
// Vault when they are joined or exited. This prevents users from joining a Pool with unpaid debt, as well as
// exiting a Pool in debt without first paying their share.
/**
* @dev Returns the current protocol fee module.
*/
function getProtocolFeesCollector() external view returns (IProtocolFeesCollector);
/**
* @dev Safety mechanism to pause most Vault operations in the event of an emergency - typically detection of an
* error in some part of the system.
*
* The Vault can only be paused during an initial time period, after which pausing is forever disabled.
*
* While the contract is paused, the following features are disabled:
* - depositing and transferring internal balance
* - transferring external balance (using the Vault's allowance)
* - swaps
* - joining Pools
* - Asset Manager interactions
*
* Internal Balance can still be withdrawn, and Pools exited.
*/
function setPaused(bool paused) external;
/**
* @dev Returns the Vault's WETH instance.
*/
function WETH() external view returns (IWETH);
// solhint-disable-previous-line func-name-mixedcase
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControlEnumerable.sol)
pragma solidity ^0.8.0;
import "./IAccessControlEnumerableUpgradeable.sol";
import "./AccessControlUpgradeable.sol";
import "../utils/structs/EnumerableSetUpgradeable.sol";
import "../proxy/utils/Initializable.sol";
/**
* @dev Extension of {AccessControl} that allows enumerating the members of each role.
*/
abstract contract AccessControlEnumerableUpgradeable is Initializable, IAccessControlEnumerableUpgradeable, AccessControlUpgradeable {
function __AccessControlEnumerable_init() internal onlyInitializing {
}
function __AccessControlEnumerable_init_unchained() internal onlyInitializing {
}
using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet;
mapping(bytes32 => EnumerableSetUpgradeable.AddressSet) private _roleMembers;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControlEnumerableUpgradeable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns one of the accounts that have `role`. `index` must be a
* value between 0 and {getRoleMemberCount}, non-inclusive.
*
* Role bearers are not sorted in any particular way, and their ordering may
* change at any point.
*
* WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
* you perform all queries on the same block. See the following
* https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
* for more information.
*/
function getRoleMember(bytes32 role, uint256 index) public view virtual override returns (address) {
return _roleMembers[role].at(index);
}
/**
* @dev Returns the number of accounts that have `role`. Can be used
* together with {getRoleMember} to enumerate all bearers of a role.
*/
function getRoleMemberCount(bytes32 role) public view virtual override returns (uint256) {
return _roleMembers[role].length();
}
/**
* @dev Overload {_grantRole} to track enumerable memberships
*/
function _grantRole(bytes32 role, address account) internal virtual override {
super._grantRole(role, account);
_roleMembers[role].add(account);
}
/**
* @dev Overload {_revokeRole} to track enumerable memberships
*/
function _revokeRole(bytes32 role, address account) internal virtual override {
super._revokeRole(role, account);
_roleMembers[role].remove(account);
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/AccessControl.sol)
pragma solidity ^0.8.0;
import "./IAccessControlUpgradeable.sol";
import "../utils/ContextUpgradeable.sol";
import "../utils/StringsUpgradeable.sol";
import "../utils/introspection/ERC165Upgradeable.sol";
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```solidity
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```solidity
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
* to enforce additional security measures for this role.
*/
abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable {
function __AccessControl_init() internal onlyInitializing {
}
function __AccessControl_init_unchained() internal onlyInitializing {
}
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with a standardized message including the required role.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*
* _Available since v4.1._
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
return _roles[role].members[account];
}
/**
* @dev Revert with a standard message if `_msgSender()` is missing `role`.
* Overriding this function changes the behavior of the {onlyRole} modifier.
*
* Format of the revert message is described in {_checkRole}.
*
* _Available since v4.6._
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Revert with a standard message if `account` is missing `role`.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
StringsUpgradeable.toHexString(account),
" is missing role ",
StringsUpgradeable.toHexString(uint256(role), 32)
)
)
);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleGranted} event.
*/
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleRevoked} event.
*/
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event. Note that unlike {grantRole}, this function doesn't perform any
* checks on the calling account.
*
* May emit a {RoleGranted} event.
*
* [WARNING]
* ====
* This function should only be called from the constructor when setting
* up the initial roles for the system.
*
* Using this function in any other way is effectively circumventing the admin
* system imposed by {AccessControl}.
* ====
*
* NOTE: This function is deprecated in favor of {_grantRole}.
*/
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Grants `role` to `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
/**
* @dev Revokes `role` from `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControlEnumerable.sol)
pragma solidity ^0.8.0;
import "./IAccessControlUpgradeable.sol";
/**
* @dev External interface of AccessControlEnumerable declared to support ERC165 detection.
*/
interface IAccessControlEnumerableUpgradeable is IAccessControlUpgradeable {
/**
* @dev Returns one of the accounts that have `role`. `index` must be a
* value between 0 and {getRoleMemberCount}, non-inclusive.
*
* Role bearers are not sorted in any particular way, and their ordering may
* change at any point.
*
* WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
* you perform all queries on the same block. See the following
* https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
* for more information.
*/
function getRoleMember(bytes32 role, uint256 index) external view returns (address);
/**
* @dev Returns the number of accounts that have `role`. Can be used
* together with {getRoleMember} to enumerate all bearers of a role.
*/
function getRoleMemberCount(bytes32 role) external view returns (uint256);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
pragma solidity ^0.8.0;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControlUpgradeable {
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*
* _Available since v3.1._
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
* constructor.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: setting the version to 255 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized != type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuardUpgradeable is Initializable {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
function __ReentrancyGuard_init() internal onlyInitializing {
__ReentrancyGuard_init_unchained();
}
function __ReentrancyGuard_init_unchained() internal onlyInitializing {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/MathUpgradeable.sol";
import "./math/SignedMathUpgradeable.sol";
/**
* @dev String operations.
*/
library StringsUpgradeable {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = MathUpgradeable.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toString(int256 value) internal pure returns (string memory) {
return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMathUpgradeable.abs(value))));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, MathUpgradeable.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return keccak256(bytes(a)) == keccak256(bytes(b));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165Upgradeable.sol";
import "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable {
function __ERC165_init() internal onlyInitializing {
}
function __ERC165_init_unchained() internal onlyInitializing {
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165Upgradeable).interfaceId;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165Upgradeable {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library MathUpgradeable {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1, "Math: mulDiv overflow");
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMathUpgradeable {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.0;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```solidity
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSetUpgradeable {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping(bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
if (lastIndex != toDeleteIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastValue;
// Update the index for the moved value
set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(address from, address to, uint256 amount) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
// decrementing then incrementing.
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
// Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
// Overflow not possible: amount <= accountBalance <= totalSupply.
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `amount`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Compatible with tokens that require the approval to be set to
* 0 before setting it to a non-zero value.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}pragma solidity >=0.6.2;
interface IUniswapV2Router01 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
function removeLiquidityETH(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
function removeLiquidityETHWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}pragma solidity >=0.6.2;
import './IUniswapV2Router01.sol';
interface IUniswapV2Router02 is IUniswapV2Router01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
}pragma solidity >=0.5.0;
interface IWETH {
function deposit() external payable;
function transfer(address to, uint value) external returns (bool);
function withdraw(uint) external;
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.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: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;
import '@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol';
/// @title Router token swapping functionality
/// @notice Functions for swapping tokens via Uniswap V3
interface ISwapRouter is IUniswapV3SwapCallback {
struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
uint160 sqrtPriceLimitX96;
}
/// @notice Swaps `amountIn` of one token for as much as possible of another token
/// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata
/// @return amountOut The amount of the received token
function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);
struct ExactInputParams {
bytes path;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
}
/// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path
/// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata
/// @return amountOut The amount of the received token
function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);
struct ExactOutputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountOut;
uint256 amountInMaximum;
uint160 sqrtPriceLimitX96;
}
/// @notice Swaps as little as possible of one token for `amountOut` of another token
/// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata
/// @return amountIn The amount of the input token
function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);
struct ExactOutputParams {
bytes path;
address recipient;
uint256 deadline;
uint256 amountOut;
uint256 amountInMaximum;
}
/// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed)
/// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata
/// @return amountIn The amount of the input token
function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import { IERC20 as IStandardERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IERC20 as IBalancerERC20 } from "@balancer-labs/v2-interfaces/contracts/vault/IFlashLoanRecipient.sol";
function castTokens(IStandardERC20[] memory inputTokens) pure returns (IBalancerERC20[] memory outputTokens) {
// solhint-disable no-inline-assembly
assembly {
outputTokens := inputTokens
}
// solhint-enable no-inline-assembly
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { Token } from "../../token/Token.sol";
/**
* @dev Flash-loan recipient interface
*/
interface IFlashLoanRecipient {
/**
* @dev a flash-loan recipient callback after each the caller must return the borrowed amount and an additional fee
*/
function onFlashLoan(
address caller,
IERC20 erc20Token,
uint256 amount,
uint256 feeAmount,
bytes memory data
) external;
}
/**
* @dev Bancor Network interface
*/
interface IBancorNetwork {
/**
* @dev returns the respective pool collection for the provided pool
*/
function collectionByPool(Token pool) external view returns (address);
/**
* @dev performs a trade by providing the input source amount, sends the proceeds to the optional beneficiary (or
* to the address of the caller, in case it's not supplied), and returns the trade target amount
*
* requirements:
*
* - the caller must have approved the network to transfer the source tokens on its behalf (except for in the
* native token case)
* - the caller must be the _bancorArbitrage contract
*/
function tradeBySourceAmountArb(
Token sourceToken,
Token targetToken,
uint256 sourceAmount,
uint256 minReturnAmount,
uint256 deadline,
address beneficiary
) external payable returns (uint256);
/**
* @dev performs a trade by providing the output target amount, sends the proceeds to the optional beneficiary (or
* to the address of the caller, in case it's not supplied), and returns the trade source amount
*
* requirements:
*
* - the caller must have approved the network to transfer the source tokens on its behalf (except for in the
* native token case)
* - the caller must be the _bancorArbitrage contract
*/
function tradeByTargetAmountArb(
Token sourceToken,
Token targetToken,
uint256 targetAmount,
uint256 maxSourceAmount,
uint256 deadline,
address beneficiary
) external payable returns (uint256);
/**
* @dev provides a flash-loan
*
* requirements:
*
* - the recipient's callback must return *at least* the borrowed amount and fee back to the specified return address
*/
function flashLoan(Token token, uint256 amount, IFlashLoanRecipient recipient, bytes calldata data) external;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { Token } from "../../token/Token.sol";
/**
* Bancor Network V2 interface
*/
interface IBancorNetworkV2 {
function convertByPath(
address[] memory _path,
uint256 _amount,
uint256 _minReturn,
address _beneficiary,
address _affiliateAccount,
uint256 _affiliateFee
) external payable returns (uint256);
function conversionPath(Token _sourceToken, Token _targetToken) external view returns (address[] memory);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { Token } from "../../token/Token.sol";
struct TradeAction {
uint256 strategyId;
uint128 amount;
}
/**
* Carbon controller interface
*/
interface ICarbonController {
/**
* @dev performs a trade by specifying a fixed source amount
*
* notes:
*
* - excess native token is returned to the sender if any
*
* requirements:
*
* - the caller must have approved the source token
*/
function tradeBySourceAmount(
Token sourceToken,
Token targetToken,
TradeAction[] calldata tradeActions,
uint256 deadline,
uint128 minReturn
) external payable returns (uint128);
/**
* @dev performs a trade by specifying a fixed target amount
*
* notes:
*
* - excess native token is returned to the sender if any
*
* requirements:
*
* - the caller must have approved the source token
*/
function tradeByTargetAmount(
Token sourceToken,
Token targetToken,
TradeAction[] calldata tradeActions,
uint256 deadline,
uint128 maxInput
) external payable returns (uint128);
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.19;
import { Token } from "../../token/Token.sol";
/**
* @notice CarbonPOL interface
*/
interface ICarbonPOL {
/**
* @notice returns the expected trade output (tokens received) given an token amount sent
*/
function expectedTradeReturn(Token token, uint128 ethAmount) external view returns (uint128 tokenAmount);
/**
* @notice returns the expected trade input (how many tokens to send) given a token amount received
*/
function expectedTradeInput(Token token, uint128 tokenAmount) external view returns (uint128 ethAmount);
/**
* @notice trades ETH for *amount* of token based on the current token price (trade by target amount)
* @notice if token == ETH, trades BNT for amount of ETH
*/
function trade(Token token, uint128 amount) external payable;
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.19;
/**
* @notice ICurvePool interface
*/
interface ICurvePool {
/**
* @notice Perform an exchange between two coins
* @dev Index values can be found via the `coins` public getter method
* @param sourceTokenIndex Index value for the coin to send
* @param targetTokenIndex Index valie of the coin to recieve
* @param dx Amount of `sourceToken` being exchanged
* @param min_dy Minimum amount of `targetToken` to receive
* @return Actual amount of `targetToken` received
*/
function exchange(int128 sourceTokenIndex, int128 targetTokenIndex, uint256 dx, uint256 min_dy) external payable returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
/**
* @dev extends the SafeERC20 library with additional operations
*/
library SafeERC20Ex {
using SafeERC20 for IERC20;
/**
* @dev ensures that the spender has sufficient allowance
*/
function ensureApprove(IERC20 token, address spender, uint256 amount) internal {
if (amount == 0) {
return;
}
uint256 allowance = token.allowance(address(this), spender);
if (allowance >= amount) {
return;
}
if (allowance > 0) {
token.safeApprove(spender, 0);
}
token.safeApprove(spender, amount);
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
/**
* @dev the main purpose of the Token interfaces is to ensure artificially that we won't use ERC20's standard functions,
* but only their safe versions, which are provided by SafeERC20 and SafeERC20Ex via the TokenLibrary contract
*/
interface Token {}// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { SafeERC20Ex } from "./SafeERC20Ex.sol";
import { Token } from "./Token.sol";
/**
* @dev This library implements ERC20 and SafeERC20 utilities for both the native token and for ERC20 tokens
*/
library TokenLibrary {
using SafeERC20 for IERC20;
using SafeERC20Ex for IERC20;
using Address for address payable;
error PermitUnsupported();
// the address that represents the native token reserve
address private constant NATIVE_TOKEN_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
// the symbol that represents the native token
string private constant NATIVE_TOKEN_SYMBOL = "ETH";
// the decimals for the native token
uint8 private constant NATIVE_TOKEN_DECIMALS = 18;
// the token representing the native token
Token public constant NATIVE_TOKEN = Token(NATIVE_TOKEN_ADDRESS);
/**
* @dev returns whether the provided token represents an ERC20 or the native token reserve
*/
function isNative(Token token) internal pure returns (bool) {
return address(token) == NATIVE_TOKEN_ADDRESS;
}
/**
* @dev returns the symbol of the native token/ERC20 token
*/
function symbol(Token token) internal view returns (string memory) {
if (isNative(token)) {
return NATIVE_TOKEN_SYMBOL;
}
return toERC20(token).symbol();
}
/**
* @dev returns the decimals of the native token/ERC20 token
*/
function decimals(Token token) internal view returns (uint8) {
if (isNative(token)) {
return NATIVE_TOKEN_DECIMALS;
}
return toERC20(token).decimals();
}
/**
* @dev returns the balance of the native token/ERC20 token
*/
function balanceOf(Token token, address account) internal view returns (uint256) {
if (isNative(token)) {
return account.balance;
}
return toIERC20(token).balanceOf(account);
}
/**
* @dev transfers a specific amount of the native token/ERC20 token
* @dev forwards all available gas if sending native token
*/
function unsafeTransfer(Token token, address to, uint256 amount) internal {
if (amount == 0) {
return;
}
if (isNative(token)) {
payable(to).sendValue(amount);
} else {
toIERC20(token).safeTransfer(to, amount);
}
}
/**
* @dev transfers a specific amount of the native token/ERC20 token
*/
function safeTransfer(Token token, address to, uint256 amount) internal {
if (amount == 0) {
return;
}
if (isNative(token)) {
payable(to).transfer(amount);
} else {
toIERC20(token).safeTransfer(to, amount);
}
}
/**
* @dev transfers a specific amount of the native token/ERC20 token from a specific holder using the allowance mechanism
*
* note that the function does not perform any action if the native token is provided
*/
function safeTransferFrom(Token token, address from, address to, uint256 amount) internal {
if (amount == 0 || isNative(token)) {
return;
}
toIERC20(token).safeTransferFrom(from, to, amount);
}
/**
* @dev approves a specific amount of the native token/ERC20 token from a specific holder
*
* note that the function does not perform any action if the native token is provided
*/
function safeApprove(Token token, address spender, uint256 amount) internal {
if (isNative(token)) {
return;
}
toIERC20(token).safeApprove(spender, amount);
}
/**
* @dev force approves a specific amount of the native token/ERC20 token from a specific holder
*
* note that the function does not perform any action if the native token is provided
*/
function forceApprove(Token token, address spender, uint256 amount) internal {
if (isNative(token)) {
return;
}
toIERC20(token).forceApprove(spender, amount);
}
/**
* @dev increases allowance of the native token/ERC20 token from a specific holder
*
* note that the function does not perform any action if the native token is provided
*/
function safeIncreaseAllowance(Token token, address spender, uint256 amount) internal {
if (isNative(token)) {
return;
}
toIERC20(token).safeIncreaseAllowance(spender, amount);
}
/**
* @dev ensures that the spender has sufficient allowance
*
* note that the function does not perform any action if the native token is provided
*/
function ensureApprove(Token token, address spender, uint256 amount) internal {
if (isNative(token)) {
return;
}
toIERC20(token).ensureApprove(spender, amount);
}
/**
* @dev compares between a token and another raw ERC20 token
*/
function isEqual(Token token, IERC20 erc20Token) internal pure returns (bool) {
return toIERC20(token) == erc20Token;
}
/**
* @dev utility function that converts a token to an IERC20
*/
function toIERC20(Token token) internal pure returns (IERC20) {
return IERC20(address(token));
}
/**
* @dev utility function that converts a token to an ERC20
*/
function toERC20(Token token) internal pure returns (ERC20) {
return ERC20(address(token));
}
}// SPDX-License-Identifier: MIT pragma solidity 0.8.19; uint32 constant PPM_RESOLUTION = 1_000_000;
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import { AccessControlEnumerableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/AccessControlEnumerableUpgradeable.sol";
import { IUpgradeable } from "./interfaces/IUpgradeable.sol";
import { AccessDenied } from "./Utils.sol";
/**
* @dev this contract provides common utilities for upgradeable contracts
*
* note that we're using the Transparent Upgradeable Proxy pattern and *not* the Universal Upgradeable Proxy Standard
* (UUPS) pattern, therefore initializing the implementation contracts is not necessary or required
*/
abstract contract Upgradeable is IUpgradeable, AccessControlEnumerableUpgradeable {
error AlreadyInitialized();
// the admin role is used to allow a non-proxy admin to perform additional initialization/setup during contract
// upgrades
bytes32 internal constant ROLE_ADMIN = keccak256("ROLE_ADMIN");
uint32 internal constant MAX_GAP = 50;
uint16 internal _initializations;
// upgrade forward-compatibility storage gap
uint256[MAX_GAP - 1] private __gap;
// solhint-disable func-name-mixedcase
/**
* @dev initializes the contract and its parents
*/
function __Upgradeable_init() internal onlyInitializing {
__AccessControl_init();
__Upgradeable_init_unchained();
}
/**
* @dev performs contract-specific initialization
*/
function __Upgradeable_init_unchained() internal onlyInitializing {
_initializations = version();
// set up administrative roles
_setRoleAdmin(ROLE_ADMIN, ROLE_ADMIN);
// allow the deployer to initially be the admin of the contract
_setupRole(ROLE_ADMIN, msg.sender);
}
// solhint-enable func-name-mixedcase
modifier onlyAdmin() {
_hasRole(ROLE_ADMIN, msg.sender);
_;
}
modifier onlyRoleMember(bytes32 role) {
_hasRole(role, msg.sender);
_;
}
function version() public view virtual override returns (uint16);
/**
* @dev returns the admin role
*/
function roleAdmin() external pure returns (bytes32) {
return ROLE_ADMIN;
}
/**
* @dev performs post-upgrade initialization
*
* requirements:
*
* - this must can be called only once per-upgrade
*/
function postUpgrade(bytes calldata data) external {
uint16 initializations = _initializations + 1;
if (initializations != version()) {
revert AlreadyInitialized();
}
_initializations = initializations;
_postUpgrade(data);
}
/**
* @dev an optional post-upgrade callback that can be implemented by child contracts
*/
function _postUpgrade(bytes calldata /* data */) internal virtual {}
function _hasRole(bytes32 role, address account) internal view {
if (!hasRole(role, account)) {
revert AccessDenied();
}
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import { PPM_RESOLUTION } from "./Constants.sol";
error AccessDenied();
error InvalidAddress();
error InvalidFee();
error ZeroValue();
/**
* @dev common utilities
*/
abstract contract Utils {
// allows execution by the caller only
modifier only(address caller) {
_only(caller);
_;
}
function _only(address caller) internal view {
if (msg.sender != caller) {
revert AccessDenied();
}
}
// verifies that a value is greater than zero
modifier greaterThanZero(uint256 value) {
_greaterThanZero(value);
_;
}
// error message binary size optimization
function _greaterThanZero(uint256 value) internal pure {
if (value == 0) {
revert ZeroValue();
}
}
// validates an address - currently only checks that it isn't null
modifier validAddress(address addr) {
_validAddress(addr);
_;
}
// error message binary size optimization
function _validAddress(address addr) internal pure {
if (addr == address(0)) {
revert InvalidAddress();
}
}
// ensures that the fee is valid
modifier validFee(uint32 fee) {
_validFee(fee);
_;
}
// error message binary size optimization
function _validFee(uint32 fee) internal pure {
if (fee > PPM_RESOLUTION) {
revert InvalidFee();
}
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import { IVersioned } from "./IVersioned.sol";
import { IAccessControlEnumerableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/IAccessControlEnumerableUpgradeable.sol";
/**
* @dev this is the common interface for upgradeable contracts
*/
interface IUpgradeable is IAccessControlEnumerableUpgradeable, IVersioned {
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
/**
* @dev an interface for a versioned contract
*/
interface IVersioned {
function version() external view returns (uint16);
}{
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "none",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 20000
},
"remappings": [],
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"contract IERC20","name":"initBnt","type":"address"},{"internalType":"contract IERC20","name":"initWeth","type":"address"},{"internalType":"address","name":"initProtocolWallet","type":"address"},{"components":[{"internalType":"contract IBancorNetworkV2","name":"bancorNetworkV2","type":"address"},{"internalType":"contract IBancorNetwork","name":"bancorNetworkV3","type":"address"},{"internalType":"contract IUniswapV2Router02","name":"uniV2Router","type":"address"},{"internalType":"contract ISwapRouter","name":"uniV3Router","type":"address"},{"internalType":"contract IUniswapV2Router02","name":"sushiswapRouter","type":"address"},{"internalType":"contract ICarbonController","name":"carbonController","type":"address"},{"internalType":"contract IVault","name":"balancerVault","type":"address"},{"internalType":"contract ICarbonPOL","name":"carbonPOL","type":"address"}],"internalType":"struct BancorArbitrage.Platforms","name":"platforms","type":"tuple"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AccessDenied","type":"error"},{"inputs":[],"name":"AlreadyInitialized","type":"error"},{"inputs":[],"name":"InvalidAddress","type":"error"},{"inputs":[],"name":"InvalidCarbonPOLTrade","type":"error"},{"inputs":[],"name":"InvalidCurvePool","type":"error"},{"inputs":[],"name":"InvalidETHAmountSent","type":"error"},{"inputs":[],"name":"InvalidFee","type":"error"},{"inputs":[],"name":"InvalidFlashLoanCaller","type":"error"},{"inputs":[],"name":"InvalidFlashloanFormat","type":"error"},{"inputs":[],"name":"InvalidFlashloanPlatformId","type":"error"},{"inputs":[],"name":"InvalidInitialAndFinalTokens","type":"error"},{"inputs":[],"name":"InvalidRouteLength","type":"error"},{"inputs":[],"name":"InvalidSourceToken","type":"error"},{"inputs":[],"name":"InvalidTradePlatformId","type":"error"},{"inputs":[],"name":"InvalidWethTrade","type":"error"},{"inputs":[],"name":"MinTargetAmountNotReached","type":"error"},{"inputs":[],"name":"MinTargetAmountTooHigh","type":"error"},{"inputs":[],"name":"SourceAmountTooHigh","type":"error"},{"inputs":[],"name":"ZeroValue","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint16[]","name":"platformIds","type":"uint16[]"},{"indexed":false,"internalType":"address[]","name":"tokenPath","type":"address[]"},{"indexed":false,"internalType":"address[]","name":"sourceTokens","type":"address[]"},{"indexed":false,"internalType":"uint256[]","name":"sourceAmounts","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"protocolAmounts","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"rewardAmounts","type":"uint256[]"}],"name":"ArbitrageExecuted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"prevPercentagePPM","type":"uint32"},{"indexed":false,"internalType":"uint32","name":"newPercentagePPM","type":"uint32"},{"indexed":false,"internalType":"uint256","name":"prevMaxAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newMaxAmount","type":"uint256"}],"name":"RewardsUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PLATFORM_ID_BALANCER","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PLATFORM_ID_BANCOR_V2","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PLATFORM_ID_BANCOR_V3","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PLATFORM_ID_CARBON_FORK","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PLATFORM_ID_CARBON_POL","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PLATFORM_ID_CURVE","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PLATFORM_ID_SUSHISWAP","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PLATFORM_ID_UNISWAP_V2_FORK","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PLATFORM_ID_UNISWAP_V3_FORK","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PLATFORM_ID_WETH","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint16","name":"platformId","type":"uint16"},{"internalType":"contract IERC20[]","name":"sourceTokens","type":"address[]"},{"internalType":"uint256[]","name":"sourceAmounts","type":"uint256[]"}],"internalType":"struct BancorArbitrage.Flashloan[]","name":"flashloans","type":"tuple[]"},{"components":[{"internalType":"uint16","name":"platformId","type":"uint16"},{"internalType":"contract Token","name":"sourceToken","type":"address"},{"internalType":"contract Token","name":"targetToken","type":"address"},{"internalType":"uint256","name":"sourceAmount","type":"uint256"},{"internalType":"uint256","name":"minTargetAmount","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"address","name":"customAddress","type":"address"},{"internalType":"uint256","name":"customInt","type":"uint256"},{"internalType":"bytes","name":"customData","type":"bytes"}],"internalType":"struct BancorArbitrage.TradeRoute[]","name":"routes","type":"tuple[]"}],"name":"flashloanAndArbV2","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint16","name":"platformId","type":"uint16"},{"internalType":"contract Token","name":"sourceToken","type":"address"},{"internalType":"contract Token","name":"targetToken","type":"address"},{"internalType":"uint256","name":"sourceAmount","type":"uint256"},{"internalType":"uint256","name":"minTargetAmount","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"address","name":"customAddress","type":"address"},{"internalType":"uint256","name":"customInt","type":"uint256"},{"internalType":"bytes","name":"customData","type":"bytes"}],"internalType":"struct BancorArbitrage.TradeRoute[]","name":"routes","type":"tuple[]"},{"internalType":"contract Token","name":"token","type":"address"},{"internalType":"uint256","name":"sourceAmount","type":"uint256"}],"name":"fundAndArb","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getRoleMember","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleMemberCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"caller","type":"address"},{"internalType":"contract IERC20","name":"erc20Token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"feeAmount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"onFlashLoan","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"name":"postUpgrade","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20[]","name":"tokens","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"uint256[]","name":"feeAmounts","type":"uint256[]"},{"internalType":"bytes","name":"userData","type":"bytes"}],"name":"receiveFlashLoan","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rewards","outputs":[{"components":[{"internalType":"uint32","name":"percentagePPM","type":"uint32"},{"internalType":"uint256","name":"maxAmount","type":"uint256"}],"internalType":"struct BancorArbitrage.Rewards","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"roleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"percentagePPM","type":"uint32"},{"internalType":"uint256","name":"maxAmount","type":"uint256"}],"internalType":"struct BancorArbitrage.Rewards","name":"newRewards","type":"tuple"}],"name":"setRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"pure","type":"function"},{"stateMutability":"payable","type":"receive"}]Contract Creation Code
6101e06040523480156200001257600080fd5b50604051620066d2380380620066d2833981016040819052620000359162000724565b826200004181620000d2565b826200004d81620000d2565b6001600160a01b03808716608090815286821660a09081528683166101c0528551831660c09081526020870151841660e0908152604088015185166101005260608801518516610120529287015184166101405290860151831661016052850151821661018052840151166101a052620000c6620000fd565b5050505050506200085e565b6001600160a01b038116620000fa5760405163e6c4247b60e01b815260040160405180910390fd5b50565b600054610100900460ff16158080156200011e5750600054600160ff909116105b806200013a5750303b1580156200013a575060005460ff166001145b620001a35760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084015b60405180910390fd5b6000805460ff191660011790558015620001c7576000805461ff0019166101001790555b620001d16200021a565b8015620000fa576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a150565b600054610100900460ff16620002765760405162461bcd60e51b815260206004820152602b6024820152600080516020620066b283398151915260448201526a6e697469616c697a696e6760a81b60648201526084016200019a565b6200028062000296565b6200028a620002fc565b620002946200036c565b565b600054610100900460ff16620002f25760405162461bcd60e51b815260206004820152602b6024820152600080516020620066b283398151915260448201526a6e697469616c697a696e6760a81b60648201526084016200019a565b6200029462000402565b600054610100900460ff16620003585760405162461bcd60e51b815260206004820152602b6024820152600080516020620066b283398151915260448201526a6e697469616c697a696e6760a81b60648201526084016200019a565b6200036262000464565b62000294620004c0565b600054610100900460ff16620003c85760405162461bcd60e51b815260206004820152602b6024820152600080516020620066b283398151915260448201526a6e697469616c697a696e6760a81b60648201526084016200019a565b604080518082019091526207a120808252683635c9adc5dea00000602090920182905261012d805463ffffffff1916909117905561012e55565b600054610100900460ff166200045e5760405162461bcd60e51b815260206004820152602b6024820152600080516020620066b283398151915260448201526a6e697469616c697a696e6760a81b60648201526084016200019a565b60018055565b600054610100900460ff16620002945760405162461bcd60e51b815260206004820152602b6024820152600080516020620066b283398151915260448201526a6e697469616c697a696e6760a81b60648201526084016200019a565b600054610100900460ff166200051c5760405162461bcd60e51b815260206004820152602b6024820152600080516020620066b283398151915260448201526a6e697469616c697a696e6760a81b60648201526084016200019a565b60fb805461ffff1916600b17905562000545600080516020620066928339815191528062000560565b620002946000805160206200669283398151915233620005ab565b600082815260976020526040808220600101805490849055905190918391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b620005b78282620005bb565b5050565b620005c78282620005e6565b600082815260c960205260409020620005e190826200068a565b505050565b60008281526097602090815260408083206001600160a01b038516845290915290205460ff16620005b75760008281526097602090815260408083206001600160a01b03851684529091529020805460ff19166001179055620006463390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000620006a1836001600160a01b038416620006aa565b90505b92915050565b6000818152600183016020526040812054620006f357508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155620006a4565b506000620006a4565b6001600160a01b0381168114620000fa57600080fd5b80516200071f81620006fc565b919050565b6000806000808486036101608112156200073d57600080fd5b85516200074a81620006fc565b60208701519095506200075d81620006fc565b60408701519094506200077081620006fc565b9250610100605f1982018113156200078757600080fd5b60405191508082016001600160401b0381118382101715620007b957634e487b7160e01b600052604160045260246000fd5b604052620007ca6060880162000712565b8252620007da6080880162000712565b6020830152620007ed60a0880162000712565b60408301526200080060c0880162000712565b60608301526200081360e0880162000712565b60808301526200082581880162000712565b60a0830152506200083a610120870162000712565b60c08201526200084e610140870162000712565b60e0820152939692955090935050565b60805160a05160c05160e05161010051610120516101405161016051610180516101a0516101c051615d286200096a60003960008181611763015261216801526000818161345b015281816134d30152613610015260008181610e2d01528181611364015261313401526000612f39015260006129ba01526000612dbf015260006129e00152600081816106080152818161127401528181612861015261291401526000818161268c0152612792015260008181612a5c01528181612bc5015281816137ce015281816138040152818161387301526138fd0152600081816116f20152818161172a015281816120f70152818161212f0152818161335e01526133c70152615d286000f3fe6080604052600436106101c65760003560e01c806383428014116100f7578063a217fddf11610095578063d0d479ff11610064578063d0d479ff14610539578063d547741f1461054c578063d8f3a0f81461056c578063f04f27071461058157600080fd5b8063a217fddf146104da578063a2195341146104ef578063a36f0d6014610504578063ca15c8731461051957600080fd5b806391d14854116100d157806391d14854146103ee57806393867fb51461043457806396bfaa9e146104675780639ec5a8941461048757600080fd5b806383428014146103815780638cd2403d146103965780639010d07c146103b657600080fd5b806336568abe1161016457806353487aa71161013e57806353487aa71461032e57806354fd4d501461034357806378c88229146103575780638129fc1c1461036c57600080fd5b806336568abe146102e457806345c9908014610304578063493b7e441461031957600080fd5b8063248a9ca3116101a0578063248a9ca314610251578063269c20e11461028f5780632e540b10146102a45780632f2ff15d146102c457600080fd5b806301ffc9a7146101d257806314d5c1a61461020757806323e30c8b1461022f57600080fd5b366101cd57005b600080fd5b3480156101de57600080fd5b506101f26101ed36600461475f565b6105a1565b60405190151581526020015b60405180910390f35b34801561021357600080fd5b5061021c600181565b60405161ffff90911681526020016101fe565b34801561023b57600080fd5b5061024f61024a366004614914565b6105fd565b005b34801561025d57600080fd5b5061028161026c36600461498a565b60009081526097602052604090206001015490565b6040519081526020016101fe565b34801561029b57600080fd5b5061021c600481565b3480156102b057600080fd5b5061024f6102bf366004614be1565b6106a4565b3480156102d057600080fd5b5061024f6102df366004614d23565b61086b565b3480156102f057600080fd5b5061024f6102ff366004614d23565b610895565b34801561031057600080fd5b5061021c600581565b34801561032557600080fd5b5061021c600381565b34801561033a57600080fd5b5061021c600981565b34801561034f57600080fd5b50600b61021c565b34801561036357600080fd5b5061021c600781565b34801561037857600080fd5b5061024f61093c565b34801561038d57600080fd5b5061021c600281565b3480156103a257600080fd5b5061024f6103b1366004614d53565b610ace565b3480156103c257600080fd5b506103d66103d1366004614dc5565b610b56565b6040516001600160a01b0390911681526020016101fe565b3480156103fa57600080fd5b506101f2610409366004614d23565b60009182526097602090815260408084206001600160a01b0393909316845291905290205460ff1690565b34801561044057600080fd5b507f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca025096610281565b34801561047357600080fd5b5061024f610482366004614de7565b610b75565b34801561049357600080fd5b5060408051808201825260008082526020918201528151808301835261012d5463ffffffff1680825261012e549183019182528351908152905191810191909152016101fe565b3480156104e657600080fd5b50610281600081565b3480156104fb57600080fd5b5061021c600881565b34801561051057600080fd5b5061021c600681565b34801561052557600080fd5b5061028161053436600461498a565b610c85565b61024f610547366004614dff565b610c9c565b34801561055857600080fd5b5061024f610567366004614d23565b610dfd565b34801561057857600080fd5b5061021c600a81565b34801561058d57600080fd5b5061024f61059c366004614e8b565b610e22565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f5a05180f0000000000000000000000000000000000000000000000000000000014806105f757506105f782610f15565b92915050565b336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614158061063e57506001600160a01b0385163014155b15610675576040517fe17c49b700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61067e81610fac565b61069d3361068c8486614f67565b6001600160a01b0387169190611009565b5050505050565b6106ac611084565b80516106b7816110f7565b8280516000036106f3576040517f4a7aa2a800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60005b815181101561080a57600082828151811061071357610713614f7a565b6020908102919091018101516040810151918101515182519193509081158061073c5750808214155b806107575750835161ffff1660021480156107575750600182115b1561078e576040517f4a7aa2a800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60005b818110156107f4578381815181106107ab576107ab614f7a565b60200260200101516000036107ec576040517f7c946ed700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600101610791565b50505050506108038160010190565b90506106f6565b506000610817858561113d565b905061083d8560008151811061082f5761082f614f7a565b602002602001015182611246565b600080610849876113f4565b91509150610859828288336115dc565b505050505061086760018055565b5050565b60008281526097602052604090206001015461088681611875565b610890838361187f565b505050565b6001600160a01b0381163314610932576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b61086782826118a1565b600054610100900460ff161580801561095c5750600054600160ff909116105b806109765750303b158015610976575060005460ff166001145b610a02576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a65640000000000000000000000000000000000006064820152608401610929565b600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790558015610a6057600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff166101001790555b610a686118c3565b8015610acb57600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b50565b60fb54600090610ae39061ffff166001614fa9565b905061ffff8116600b14610b23576040517f0dc149f000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60fb80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00001661ffff8316179055505050565b600082815260c960205260408120610b6e9083611974565b9392505050565b610b9f7f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca02509633611980565b610bac6020820182614fd6565b610bb5816119dc565b8160200135610bc381611a1f565b61012d5461012e5463ffffffff90911690610be16020860186614fd6565b63ffffffff168263ffffffff16148015610bfe5750846020013581145b15610c0a575050505050565b8461012d610c188282614ff3565b507f707740459746824d259c9a0c2bfabcb04306f48ffc0c1c9c1404e990bf67d217905082610c4a6020880188614fd6565b6040805163ffffffff938416815292909116602083810191909152908201849052870135606082015260800160405180910390a15050505050565b600081815260c9602052604081206105f790611a59565b610ca4611084565b82610cae816110f7565b81610cb881611a1f565b610d02848787610cc960018261503b565b818110610cd857610cd8614f7a565b9050602002810190610cea919061504e565b610cfb90606081019060400161508c565b8534611a63565b610d176001600160a01b038516333086611b48565b610d29610d2486886150a9565b611b8a565b610d3d6001600160a01b0385163385611c4d565b6040805160018082528183019092526000916020808301908036833750506040805160018082528183019092529293506000929150602080830190803683370190505090508582600081518110610d9657610d96614f7a565b60200260200101906001600160a01b031690816001600160a01b0316815250508481600081518110610dca57610dca614f7a565b6020908102919091010152610dea8282610de48a8c6150a9565b336115dc565b50505050610df760018055565b50505050565b600082815260976020526040902060010154610e1881611875565b61089083836118a1565b336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614610e84576040517fe17c49b700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610e8d81610fac565b60005b845181101561069d57610f0d33848381518110610eaf57610eaf614f7a565b6020026020010151868481518110610ec957610ec9614f7a565b6020026020010151610edb9190614f67565b878481518110610eed57610eed614f7a565b60200260200101516001600160a01b03166110099092919063ffffffff16565b600101610e90565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b0000000000000000000000000000000000000000000000000000000014806105f757507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316146105f7565b60008082806020019051810190610fc391906152c1565b915091508151600003610fd95761089081611b8a565b610fe3828261113d565b925061089082600081518110610ffb57610ffb614f7a565b602002602001015184611246565b8060000361101657505050565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03841603611070576040516001600160a01b0383169082156108fc029083906000818181858888f19350505050158015610df7573d6000803e3d6000fd5b6108906001600160a01b0384168383611c91565b6002600154036110f0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610929565b6002600155565b60028110806111065750600a81115b15610acb576040517f76987d0e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b606060006001845161114f919061503b565b67ffffffffffffffff811115611167576111676147c6565b6040519080825280602002602001820160405280156111c057816020015b6111ad6040518060600160405280600061ffff16815260200160608152602001606081525090565b8152602001906001900390816111855790505b50905060005b815181101561121a578460018201815181106111e4576111e4614f7a565b60200260200101518282815181106111fe576111fe614f7a565b60200260200101819052506112138160010190565b90506111c6565b50808360405160200161122e92919061558d565b60405160208183030381529060405291505092915050565b815161ffff167ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01611336577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663adf51de183602001516000815181106112b8576112b8614f7a565b602002602001015184604001516000815181106112d7576112d7614f7a565b602002602001015130856040518563ffffffff1660e01b81526004016113009493929190615685565b600060405180830381600087803b15801561131a57600080fd5b505af115801561132e573d6000803e3d6000fd5b505050505050565b815161ffff167ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9016113c2577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316635c38449e3061139d856020015190565b8560400151856040518563ffffffff1660e01b815260040161130094939291906156c1565b6040517f0d82421600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6060806000805b84518110156114385784818151811061141657611416614f7a565b602002602001015160200151518261142e9190614f67565b91506001016113fb565b5060008167ffffffffffffffff811115611454576114546147c6565b60405190808252806020026020018201604052801561147d578160200160208202803683370190505b50905060008267ffffffffffffffff81111561149b5761149b6147c6565b6040519080825280602002602001820160405280156114c4578160200160208202803683370190505b5090506000805b87518110156115cf5760005b8882815181106114e9576114e9614f7a565b602002602001015160200151518110156115c65788828151811061150f5761150f614f7a565b602002602001015160200151818151811061152c5761152c614f7a565b602002602001015185848151811061154657611546614f7a565b60200260200101906001600160a01b031690816001600160a01b03168152505088828151811061157857611578614f7a565b602002602001015160400151818151811061159557611595614f7a565b60200260200101518484815181106115af576115af614f7a565b6020908102919091010152600192830192016114d7565b506001016114cb565b5091969095509350505050565b835160008167ffffffffffffffff8111156115f9576115f96147c6565b604051908082528060200260200182016040528015611622578160200160208202803683370190505b50905060008267ffffffffffffffff811115611640576116406147c6565b604051908082528060200260200182016040528015611669578160200160208202803683370190505b50905060005b838110156117f557600088828151811061168b5761168b614f7a565b6020026020010151905060006116b330836001600160a01b0316611d3a90919063ffffffff16565b61012d54909150600090620f4240906116d29063ffffffff1684615739565b6116dc9190615750565b9050808203828214611788576001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116908516036117545761174f6001600160a01b0385167f000000000000000000000000000000000000000000000000000000000000000083611009565b611788565b6117886001600160a01b0385167f000000000000000000000000000000000000000000000000000000000000000083611c4d565b81156117a2576117a26001600160a01b0385168a84611c4d565b818686815181106117b5576117b5614f7a565b602002602001018181525050808786815181106117d4576117d4614f7a565b602002602001018181525050505050506117ee8160010190565b905061166f565b5060008060008061180589611df7565b93509350935093506118178282612095565b876001600160a01b03167f5d6ce85adcad908fcf78bd40c0eb5b27bd4e0759ba3f1603df6aa38fc8b2efb585858e8e8b8b60405161185a969594939291906157c4565b60405180910390a25050505050505050505050565b60018055565b610acb8133612198565b6118898282612227565b600082815260c96020526040902061089090826122e7565b6118ab82826122fc565b600082815260c960205260409020610890908261239d565b600054610100900460ff1661195a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401610929565b6119626123b2565b61196a612451565b6119726124f8565b565b6000610b6e83836125e4565b60008281526097602090815260408083206001600160a01b038516845290915290205460ff16610867576040517f4ca8886700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b620f424063ffffffff82161115610acb576040517f58d620b300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80600003610acb576040517f7c946ed700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006105f7825490565b836001600160a01b0316836001600160a01b031614611aae576040517ffa48e42300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03851603611b1057818114611b0b576040517f74ebc29c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610df7565b8015610df7576040517f74ebc29c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b801580611b71575073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038516145b610df757610df76001600160a01b03851684848461260e565b60005b8151811015610867576000828281518110611baa57611baa614f7a565b602002602001015190506000611bd63083602001516001600160a01b0316611d3a90919063ffffffff16565b90506000826060015160001480611bf05750818360600151115b15611bfc575080611c03565b5060608201515b611c39836000015161ffff16846020015185604001518487608001518860a001518960c001518a60e001518b610100015161265f565b505050611c468160010190565b9050611b8d565b80600003611c5a57505050565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03841603611070576108906001600160a01b038316826139cc565b6040516001600160a01b0383166024820152604481018290526108909084907fa9059cbb00000000000000000000000000000000000000000000000000000000906064015b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152613b19565b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03841603611d7157506001600160a01b038116316105f7565b826040517f70a082310000000000000000000000000000000000000000000000000000000081526001600160a01b03848116600483015291909116906370a0823190602401602060405180830381865afa158015611dd3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b6e9190615866565b60608060606000845167ffffffffffffffff811115611e1857611e186147c6565b604051908082528060200260200182016040528015611e41578160200160208202803683370190505b50935084516002611e529190615739565b67ffffffffffffffff811115611e6a57611e6a6147c6565b604051908082528060200260200182016040528015611e93578160200160208202803683370190505b50925084516002611ea49190615739565b67ffffffffffffffff811115611ebc57611ebc6147c6565b604051908082528060200260200182016040528015611ee5578160200160208202803683370190505b5091506000905060005b855181101561208d57858181518110611f0a57611f0a614f7a565b602002602001015160000151858281518110611f2857611f28614f7a565b602002602001019061ffff16908161ffff16815250506000868281518110611f5257611f52614f7a565b60200260200101516020015190506000878381518110611f7457611f74614f7a565b60200260200101516040015190508186846002611f919190615739565b81518110611fa157611fa1614f7a565b6001600160a01b03909216602092830291909101909101528086611fc6856002615739565b611fd1906001614f67565b81518110611fe157611fe1614f7a565b60200260200101906001600160a01b031690816001600160a01b03168152505061200c828686613c1b565b612042578185858151811061202357612023614f7a565b6001600160a01b03909216602092830291909101909101526001840193505b61204d818686613c1b565b612083578085858151811061206457612064614f7a565b6001600160a01b03909216602092830291909101909101526001840193505b5050600101611eef565b509193509193565b60005b818110156108905760008382815181106120b4576120b4614f7a565b6020026020010151905060006120dc30836001600160a01b0316611d3a90919063ffffffff16565b9050806000036120ed575050612190565b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000811690831603612159576121546001600160a01b0383167f000000000000000000000000000000000000000000000000000000000000000083611009565b61218d565b61218d6001600160a01b0383167f000000000000000000000000000000000000000000000000000000000000000083611c4d565b50505b600101612098565b60008281526097602090815260408083206001600160a01b038516845290915290205460ff16610867576121cb81613c76565b6121d6836020613c88565b6040516020016121e792919061587f565b60408051601f19818403018152908290527f08c379a000000000000000000000000000000000000000000000000000000000825261092991600401615900565b60008281526097602090815260408083206001600160a01b038516845290915290205460ff166108675760008281526097602090815260408083206001600160a01b0385168452909152902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790556122a33390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000610b6e836001600160a01b038416613ecb565b60008281526097602090815260408083206001600160a01b038516845290915290205460ff16156108675760008281526097602090815260408083206001600160a01b038516808552925280832080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000610b6e836001600160a01b038416613f1a565b600054610100900460ff16612449576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401610929565b611972614014565b600054610100900460ff166124e8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401610929565b6124f06140ab565b611972614142565b600054610100900460ff1661258f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401610929565b604080518082019091526207a120808252683635c9adc5dea00000602090920182905261012d80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000016909117905561012e55565b60008260000182815481106125fb576125fb614f7a565b9060005260206000200154905092915050565b6040516001600160a01b0380851660248301528316604482015260648101829052610df79085907f23b872dd0000000000000000000000000000000000000000000000000000000090608401611cd6565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8901612834576126b1887f000000000000000000000000000000000000000000000000000000000000000088614258565b604080516003808252608082019092526000916020820160608036833701905050905088816000815181106126e8576126e8614f7a565b60200260200101906001600160a01b031690816001600160a01b031681525050838160018151811061271c5761271c614f7a565b60200260200101906001600160a01b031690816001600160a01b031681525050878160028151811061275057612750614f7a565b6001600160a01b0392831660209182029290920101526000908a1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1461278c57600061278e565b875b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663b77d239b82848b8b60008060006040518863ffffffff1660e01b81526004016127e996959493929190615913565b60206040518083038185885af1158015612807573d6000803e3d6000fd5b50505050506040513d601f19601f8201168201806040525081019061282c9190615866565b5050506139c1565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe890161298c57612886887f000000000000000000000000000000000000000000000000000000000000000088614258565b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038a16146128b35760006128b5565b865b6040517fd895feee0000000000000000000000000000000000000000000000000000000081526001600160a01b038b811660048301528a81166024830152604482018a90526064820189905260848201889052600060a48301529192507f00000000000000000000000000000000000000000000000000000000000000009091169063d895feee90839060c40160206040518083038185885af1158015612960573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906129859190615866565b50506139c1565b600389148061299b5750600589145b15612d855760006001600160a01b038416612a075760038a146129de577f0000000000000000000000000000000000000000000000000000000000000000612a00565b7f00000000000000000000000000000000000000000000000000000000000000005b9050612a0a565b50825b612a15898289614258565b60408051600280825260608201835260009260208301908036833701905050905073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038b1603612b6b577f000000000000000000000000000000000000000000000000000000000000000081600081518110612a8e57612a8e614f7a565b60200260200101906001600160a01b031690816001600160a01b0316815250508881600181518110612ac257612ac2614f7a565b6001600160a01b0392831660209182029290920101526040517f7ff36ab500000000000000000000000000000000000000000000000000000000815290831690637ff36ab5908a90612b1e908b90869030908d90600401615959565b60006040518083038185885af1158015612b3c573d6000803e3d6000fd5b50505050506040513d6000823e601f3d908101601f19168201604052612b65919081019061598e565b50612985565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038a1603612c9a578981600081518110612ba357612ba3614f7a565b60200260200101906001600160a01b031690816001600160a01b0316815250507f000000000000000000000000000000000000000000000000000000000000000081600181518110612bf757612bf7614f7a565b6001600160a01b0392831660209182029290920101526040517f18cbafe5000000000000000000000000000000000000000000000000000000008152908316906318cbafe590612c53908b908b90869030908d906004016159c3565b6000604051808303816000875af1158015612c72573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612b65919081019061598e565b8981600081518110612cae57612cae614f7a565b60200260200101906001600160a01b031690816001600160a01b0316815250508881600181518110612ce257612ce2614f7a565b6001600160a01b0392831660209182029290920101526040517f38ed1739000000000000000000000000000000000000000000000000000000008152908316906338ed173990612d3e908b908b90869030908d906004016159c3565b6000604051808303816000875af1158015612d5d573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261282c919081019061598e565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc8901612eff5760006001600160a01b038416612de357507f0000000000000000000000000000000000000000000000000000000000000000612de6565b50825b612df1898289614258565b60408051610100810182526001600160a01b038b811682528a81166020830190815262ffffff8781168486019081523060608601908152608086018c815260a087018f815260c088018f8152600060e08a0190815299517f414bf38900000000000000000000000000000000000000000000000000000000815289518916600482015296518816602488015293519094166044860152905185166064850152516084840152905160a48301525160c48201529251811660e484015290919083169063414bf38990610104016020604051808303816000875af1158015612edb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061282c9190615866565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa890161310b5760006001600160a01b038416612f5d57507f0000000000000000000000000000000000000000000000000000000000000000612f60565b50825b6fffffffffffffffffffffffffffffffff861115612faa576040517f7d5ee39100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b612fb5898289614258565b600183811614600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038c1614612fe8576000612fea565b885b90506000848060200190518101906130029190615a1f565b9050821561308857836001600160a01b031663102ee9ba838e8e858d8f6040518763ffffffff1660e01b815260040161303f959493929190615ad2565b60206040518083038185885af115801561305d573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906130829190615b6f565b50613102565b836001600160a01b031663f1c5e014838e8e858d8f6040518763ffffffff1660e01b81526004016130bd959493929190615ad2565b60206040518083038185885af11580156130db573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906131009190615b6f565b505b505050506139c1565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff989016132c3577f000000000000000000000000000000000000000000000000000000000000000061315e898289614258565b6040805160c0810182528481526000602082018190529181016001600160a01b038c1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee146131a1578b6131a4565b60005b6001600160a01b031681526020016131e18b6001600160a01b03166001600160a01b031673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1490565b6131eb578a6131ee565b60005b6001600160a01b03908116825260208083018c9052604080518083018252600080825294820152805160808101825230808252928101859052808201929092526060820184905284015193945092161561324957600061324b565b895b9050836001600160a01b03166352bbbe298285858d8d6040518663ffffffff1660e01b81526004016132809493929190615b8a565b60206040518083038185885af115801561329e573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906131009190615866565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff88901613677576fffffffffffffffffffffffffffffffff861115613334576040517fcd0ac5e600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b0389161415801561338e57507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0390811690891614155b156133c5576040517f0896c96900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0390811690891614801561341e575073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03881614155b15613455576040517f0896c96900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b613480887f000000000000000000000000000000000000000000000000000000000000000088614258565b6040517f824316880000000000000000000000000000000000000000000000000000000081526001600160a01b0388811660048301526fffffffffffffffffffffffffffffffff881660248301526000917f000000000000000000000000000000000000000000000000000000000000000090911690638243168890604401602060405180830381865afa15801561351c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135409190615b6f565b905085816fffffffffffffffffffffffffffffffff16101561358e576040517fb34424fd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038b16146135bb5760006135bd565b875b6040517f4747919d0000000000000000000000000000000000000000000000000000000081526001600160a01b038b811660048301526fffffffffffffffffffffffffffffffff851660248301529192507f000000000000000000000000000000000000000000000000000000000000000090911690634747919d9083906044016000604051808303818588803b15801561365757600080fd5b505af115801561366b573d6000803e3d6000fd5b505050505050506139c1565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7890161377e57826001600160a01b0381166136df576040517fa79aa26d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038b161461370c57600061370e565b875b905061371b8a838a614258565b6040517f3df02124000000000000000000000000000000000000000000000000000000008152600f85900b6004820152608085901d602482015260448101899052606481018890526001600160a01b03831690633df021249083906084016127e9565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6890161398f5773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b0389161480156137fd57507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03908116908816145b15613871577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db0876040518263ffffffff1660e01b81526004016000604051808303818588803b15801561385d57600080fd5b505af1158015613100573d6000803e3d6000fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b039081169089161480156138c9575073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038816145b1561395d576040517f2e1a7d4d000000000000000000000000000000000000000000000000000000008152600481018790527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690632e1a7d4d90602401600060405180830381600087803b15801561394957600080fd5b505af1158015613102573d6000803e3d6000fd5b6040517f93f8a1ad00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f8260f36600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505050505050505050565b80471015613a36576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e63650000006044820152606401610929565b6000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114613a83576040519150601f19603f3d011682016040523d82523d6000602084013e613a88565b606091505b5050905080610890576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d617920686176652072657665727465640000000000006064820152608401610929565b6000613b6e826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166143569092919063ffffffff16565b9050805160001480613b8f575080806020019051810190613b8f9190615c83565b610890576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610929565b6000805b82811015613c6b57846001600160a01b0316848281518110613c4357613c43614f7a565b60200260200101516001600160a01b031603613c63576001915050610b6e565b600101613c1f565b506000949350505050565b60606105f76001600160a01b03831660145b60606000613c97836002615739565b613ca2906002614f67565b67ffffffffffffffff811115613cba57613cba6147c6565b6040519080825280601f01601f191660200182016040528015613ce4576020820181803683370190505b5090507f300000000000000000000000000000000000000000000000000000000000000081600081518110613d1b57613d1b614f7a565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110613d7e57613d7e614f7a565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053506000613dba846002615739565b613dc5906001614f67565b90505b6001811115613e62577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110613e0657613e06614f7a565b1a60f81b828281518110613e1c57613e1c614f7a565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535060049490941c93613e5b81615ca5565b9050613dc8565b508315610b6e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610929565b6000818152600183016020526040812054613f12575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556105f7565b5060006105f7565b60008181526001830160205260408120548015614003576000613f3e60018361503b565b8554909150600090613f529060019061503b565b9050818114613fb7576000866000018281548110613f7257613f72614f7a565b9060005260206000200154905080876000018481548110613f9557613f95614f7a565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080613fc857613fc8615cda565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506105f7565b60009150506105f7565b5092915050565b600054610100900460ff1661186f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401610929565b600054610100900460ff16611972576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401610929565b600054610100900460ff166141d9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401610929565b60fb80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000016600b17905561422e7f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca0250968061436d565b6119727f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca025096336143b8565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b0384160361428157505050565b60006001600160a01b0384166040517fdd62ed3e0000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038581166024830152919091169063dd62ed3e90604401602060405180830381865afa1580156142f4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906143189190615866565b905081811015610df757610df76001600160a01b038516847fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6143c2565b606061436584846000856143ff565b949350505050565b600082815260976020526040808220600101805490849055905190918391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b610867828261187f565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038416036143eb57505050565b6108906001600160a01b038416838361450b565b606082471015614491576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c00000000000000000000000000000000000000000000000000006064820152608401610929565b600080866001600160a01b031685876040516144ad9190615d09565b60006040518083038185875af1925050503d80600081146144ea576040519150601f19603f3d011682016040523d82523d6000602084013e6144ef565b606091505b5091509150614500878383876145e1565b979650505050505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f095ea7b30000000000000000000000000000000000000000000000000000000017905261458a8482614674565b610df7576040516001600160a01b0384166024820152600060448201526145d79085907f095ea7b30000000000000000000000000000000000000000000000000000000090606401611cd6565b610df78482613b19565b6060831561466a578251600003614663576001600160a01b0385163b614663576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610929565b5081614365565b614365838361471b565b6000806000846001600160a01b0316846040516146919190615d09565b6000604051808303816000865af19150503d80600081146146ce576040519150601f19603f3d011682016040523d82523d6000602084013e6146d3565b606091505b50915091508180156146fd5750805115806146fd5750808060200190518101906146fd9190615c83565b801561471257506001600160a01b0385163b15155b95945050505050565b81511561472b5781518083602001fd5b806040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109299190615900565b60006020828403121561477157600080fd5b81357fffffffff0000000000000000000000000000000000000000000000000000000081168114610b6e57600080fd5b6001600160a01b0381168114610acb57600080fd5b80356147c1816147a1565b919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b604051610120810167ffffffffffffffff81118282101715614819576148196147c6565b60405290565b6040516060810167ffffffffffffffff81118282101715614819576148196147c6565b6040805190810167ffffffffffffffff81118282101715614819576148196147c6565b604051601f8201601f1916810167ffffffffffffffff8111828210171561488e5761488e6147c6565b604052919050565b600067ffffffffffffffff8211156148b0576148b06147c6565b50601f01601f191660200190565b600082601f8301126148cf57600080fd5b81356148e26148dd82614896565b614865565b8181528460208386010111156148f757600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080600060a0868803121561492c57600080fd5b8535614937816147a1565b94506020860135614947816147a1565b93506040860135925060608601359150608086013567ffffffffffffffff81111561497157600080fd5b61497d888289016148be565b9150509295509295909350565b60006020828403121561499c57600080fd5b5035919050565b600067ffffffffffffffff8211156149bd576149bd6147c6565b5060051b60200190565b61ffff81168114610acb57600080fd5b80356147c1816149c7565b600082601f8301126149f357600080fd5b81356020614a036148dd836149a3565b82815260059290921b84018101918181019086841115614a2257600080fd5b8286015b84811015614a46578035614a39816147a1565b8352918301918301614a26565b509695505050505050565b600082601f830112614a6257600080fd5b81356020614a726148dd836149a3565b82815260059290921b84018101918181019086841115614a9157600080fd5b8286015b84811015614a465780358352918301918301614a95565b6000614aba6148dd846149a3565b8381529050602080820190600585901b840186811115614ad957600080fd5b845b81811015614bb657803567ffffffffffffffff80821115614afc5760008081fd5b90870190610120828b031215614b125760008081fd5b614b1a6147f5565b614b23836149d7565b8152614b308684016147b6565b868201526040614b418185016147b6565b90820152606083810135908201526080808401359082015260a0808401359082015260c0614b708185016147b6565b9082015260e083810135908201526101008084013583811115614b935760008081fd5b614b9f8d8287016148be565b918301919091525086525050928201928201614adb565b505050509392505050565b600082601f830112614bd257600080fd5b610b6e83833560208501614aac565b60008060408385031215614bf457600080fd5b823567ffffffffffffffff80821115614c0c57600080fd5b818501915085601f830112614c2057600080fd5b81356020614c306148dd836149a3565b82815260059290921b84018101918181019089841115614c4f57600080fd5b8286015b84811015614cf557803586811115614c6b5760008081fd5b87016060818d03601f1901811315614c835760008081fd5b614c8b61481f565b86830135614c98816149c7565b8152604083013589811115614cad5760008081fd5b614cbb8f89838701016149e2565b8289015250908201359088821115614cd35760008081fd5b614ce18e8884860101614a51565b604082015285525050918301918301614c53565b5096505086013592505080821115614d0c57600080fd5b50614d1985828601614bc1565b9150509250929050565b60008060408385031215614d3657600080fd5b823591506020830135614d48816147a1565b809150509250929050565b60008060208385031215614d6657600080fd5b823567ffffffffffffffff80821115614d7e57600080fd5b818501915085601f830112614d9257600080fd5b813581811115614da157600080fd5b866020828501011115614db357600080fd5b60209290920196919550909350505050565b60008060408385031215614dd857600080fd5b50508035926020909101359150565b600060408284031215614df957600080fd5b50919050565b60008060008060608587031215614e1557600080fd5b843567ffffffffffffffff80821115614e2d57600080fd5b818701915087601f830112614e4157600080fd5b813581811115614e5057600080fd5b8860208260051b8501011115614e6557600080fd5b60209283019650945050850135614e7b816147a1565b9396929550929360400135925050565b60008060008060808587031215614ea157600080fd5b843567ffffffffffffffff80821115614eb957600080fd5b614ec5888389016149e2565b95506020870135915080821115614edb57600080fd5b614ee788838901614a51565b94506040870135915080821115614efd57600080fd5b614f0988838901614a51565b93506060870135915080821115614f1f57600080fd5b50614f2c878288016148be565b91505092959194509250565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b808201808211156105f7576105f7614f38565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b61ffff81811683821601908082111561400d5761400d614f38565b63ffffffff81168114610acb57600080fd5b600060208284031215614fe857600080fd5b8135610b6e81614fc4565b8135614ffe81614fc4565b63ffffffff81167fffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000083541617825550602082013560018201555050565b818103818111156105f7576105f7614f38565b600082357ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffee183360301811261508257600080fd5b9190910192915050565b60006020828403121561509e57600080fd5b8135610b6e816147a1565b6000610b6e368484614aac565b80516147c1816149c7565b600082601f8301126150d257600080fd5b815160206150e26148dd836149a3565b82815260059290921b8401810191818101908684111561510157600080fd5b8286015b84811015614a465780518352918301918301615105565b80516147c1816147a1565b60005b8381101561514257818101518382015260200161512a565b50506000910152565b600082601f83011261515c57600080fd5b815161516a6148dd82614896565b81815284602083860101111561517f57600080fd5b614365826020830160208701615127565b600082601f8301126151a157600080fd5b815160206151b16148dd836149a3565b82815260059290921b840181019181810190868411156151d057600080fd5b8286015b84811015614a4657805167ffffffffffffffff808211156151f55760008081fd5b818901915061012080601f19848d030112156152115760008081fd5b6152196147f5565b6152248885016150b6565b8152604061523381860161511c565b89830152606061524481870161511c565b828401526080915081860151818401525060a0808601518284015260c0915081860151818401525060e061527981870161511c565b8284015261010091508186015181840152508285015192508383111561529f5760008081fd5b6152ad8d8a8588010161514b565b9082015286525050509183019183016151d4565b600080604083850312156152d457600080fd5b825167ffffffffffffffff808211156152ec57600080fd5b818501915085601f83011261530057600080fd5b815161530e6148dd826149a3565b8082825260208201915060208360051b86010192508883111561533057600080fd5b602085015b838110156154385780518581111561534c57600080fd5b86016060818c03601f1901121561536257600080fd5b61536a61481f565b6020820151615378816149c7565b815260408201518781111561538c57600080fd5b8201603f81018d1361539d57600080fd5b60208101516153ae6148dd826149a3565b81815260059190911b82016040019060208101908f8311156153cf57600080fd5b6040840193505b828410156153fa5783516153e9816147a1565b8252602093840193909101906153d6565b602085015250505060608201518781111561541457600080fd5b6154238d6020838601016150c1565b60408301525084525060209283019201615335565b506020880151909650935050508082111561545257600080fd5b50614d1985828601615190565b600081518084526020808501945080840160005b8381101561548f57815187529582019590820190600101615473565b509495945050505050565b600081518084526154b2816020860160208601615127565b601f01601f19169290920160200192915050565b600081518084526020808501808196508360051b8101915082860160005b858110156155805782840389528151805161ffff168552858101516001600160a01b0390811687870152604080830151821690870152606080830151908701526080808301519087015260a0808301519087015260c0808301519091169086015260e08082015190860152610100908101516101209186018290529061556c8187018361549a565b9a87019a95505050908401906001016154e4565b5091979650505050505050565b60006040808301818452808651808352606092508286019150828160051b8701016020808a016000805b85811015615664578a85037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa00187528251805161ffff168652848101518587018a905280518a880181905290860190849060808901905b808310156156375783516001600160a01b0316825292880192600192909201919088019061560e565b50928c0151888403898e01529261564e818561545f565b9a88019a985050509385019350506001016155b7565b5050508782039088015261567881896154c6565b9998505050505050505050565b60006001600160a01b038087168352856020840152808516604084015250608060608301526156b7608083018461549a565b9695505050505050565b6000608082016001600160a01b038088168452602060808186015282885180855260a087019150828a01945060005b8181101561570e5785518516835294830194918301916001016156f0565b50508581036040870152615722818961545f565b93505050508281036060840152614500818561549a565b80820281158282048414176105f7576105f7614f38565b600082615786577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b600081518084526020808501945080840160005b8381101561548f5781516001600160a01b03168752958201959082019060010161579f565b60c0808252875190820181905260009060209060e0840190828b01845b8281101561580157815161ffff16845292840192908401906001016157e1565b50505083810382850152615815818a61578b565b915050828103604084015261582a818861578b565b9050828103606084015261583e818761545f565b90508281036080840152615852818661545f565b905082810360a0840152615678818561545f565b60006020828403121561587857600080fd5b5051919050565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516158b7816017850160208801615127565b7f206973206d697373696e6720726f6c652000000000000000000000000000000060179184019182015283516158f4816028840160208801615127565b01602801949350505050565b602081526000610b6e602083018461549a565b60c08152600061592660c083018961578b565b60208301979097525060408101949094526001600160a01b0392831660608501529116608083015260a090910152919050565b848152608060208201526000615972608083018661578b565b6001600160a01b03949094166040830152506060015292915050565b6000602082840312156159a057600080fd5b815167ffffffffffffffff8111156159b757600080fd5b614365848285016150c1565b85815284602082015260a0604082015260006159e260a083018661578b565b6001600160a01b0394909416606083015250608001529392505050565b80516fffffffffffffffffffffffffffffffff811681146147c157600080fd5b60006020808385031215615a3257600080fd5b825167ffffffffffffffff811115615a4957600080fd5b8301601f81018513615a5a57600080fd5b8051615a686148dd826149a3565b81815260069190911b82018301908381019087831115615a8757600080fd5b928401925b828410156145005760408489031215615aa55760008081fd5b615aad614842565b84518152615abc8686016159ff565b8187015282526040939093019290840190615a8c565b600060a082016001600160a01b0380891684526020818916818601526040915060a08286015282885180855260c087019150828a01945060005b81811015615b43578551805184528401516fffffffffffffffffffffffffffffffff16848401529483019491840191600101615b0c565b5050606086018890526fffffffffffffffffffffffffffffffff8716608087015293506156b792505050565b600060208284031215615b8157600080fd5b610b6e826159ff565b60e08152845160e08201526000602086015160028110615bd3577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b61010083015260408601516001600160a01b03166101208301526060860151615c086101408401826001600160a01b03169052565b50608086015161016083015260a086015160c0610180840152615c2f6101a084018261549a565b915050615c7160208301866001600160a01b03808251168352602082015115156020840152806040830151166040840152506060810151151560608301525050565b60a082019390935260c0015292915050565b600060208284031215615c9557600080fd5b81518015158114610b6e57600080fd5b600081615cb457615cb4614f38565b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603160045260246000fd5b6000825161508281846020870161512756fea164736f6c6343000813000a2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca025096496e697469616c697a61626c653a20636f6e7472616374206973206e6f7420690000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000ba7d1581db6248dc9177466a328bf457703c8f840000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb0000000000000000000000000eef417e1d5cc832e619ae18d2f140de2999dd4fb0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f000000000000000000000000c537e898cd774e2dcba3b14ea6f34c93d5ea45e1000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c8000000000000000000000000d06146d292f9651c1d7cf54a3162791dfc2bef46
Deployed Bytecode
0x6080604052600436106101c65760003560e01c806383428014116100f7578063a217fddf11610095578063d0d479ff11610064578063d0d479ff14610539578063d547741f1461054c578063d8f3a0f81461056c578063f04f27071461058157600080fd5b8063a217fddf146104da578063a2195341146104ef578063a36f0d6014610504578063ca15c8731461051957600080fd5b806391d14854116100d157806391d14854146103ee57806393867fb51461043457806396bfaa9e146104675780639ec5a8941461048757600080fd5b806383428014146103815780638cd2403d146103965780639010d07c146103b657600080fd5b806336568abe1161016457806353487aa71161013e57806353487aa71461032e57806354fd4d501461034357806378c88229146103575780638129fc1c1461036c57600080fd5b806336568abe146102e457806345c9908014610304578063493b7e441461031957600080fd5b8063248a9ca3116101a0578063248a9ca314610251578063269c20e11461028f5780632e540b10146102a45780632f2ff15d146102c457600080fd5b806301ffc9a7146101d257806314d5c1a61461020757806323e30c8b1461022f57600080fd5b366101cd57005b600080fd5b3480156101de57600080fd5b506101f26101ed36600461475f565b6105a1565b60405190151581526020015b60405180910390f35b34801561021357600080fd5b5061021c600181565b60405161ffff90911681526020016101fe565b34801561023b57600080fd5b5061024f61024a366004614914565b6105fd565b005b34801561025d57600080fd5b5061028161026c36600461498a565b60009081526097602052604090206001015490565b6040519081526020016101fe565b34801561029b57600080fd5b5061021c600481565b3480156102b057600080fd5b5061024f6102bf366004614be1565b6106a4565b3480156102d057600080fd5b5061024f6102df366004614d23565b61086b565b3480156102f057600080fd5b5061024f6102ff366004614d23565b610895565b34801561031057600080fd5b5061021c600581565b34801561032557600080fd5b5061021c600381565b34801561033a57600080fd5b5061021c600981565b34801561034f57600080fd5b50600b61021c565b34801561036357600080fd5b5061021c600781565b34801561037857600080fd5b5061024f61093c565b34801561038d57600080fd5b5061021c600281565b3480156103a257600080fd5b5061024f6103b1366004614d53565b610ace565b3480156103c257600080fd5b506103d66103d1366004614dc5565b610b56565b6040516001600160a01b0390911681526020016101fe565b3480156103fa57600080fd5b506101f2610409366004614d23565b60009182526097602090815260408084206001600160a01b0393909316845291905290205460ff1690565b34801561044057600080fd5b507f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca025096610281565b34801561047357600080fd5b5061024f610482366004614de7565b610b75565b34801561049357600080fd5b5060408051808201825260008082526020918201528151808301835261012d5463ffffffff1680825261012e549183019182528351908152905191810191909152016101fe565b3480156104e657600080fd5b50610281600081565b3480156104fb57600080fd5b5061021c600881565b34801561051057600080fd5b5061021c600681565b34801561052557600080fd5b5061028161053436600461498a565b610c85565b61024f610547366004614dff565b610c9c565b34801561055857600080fd5b5061024f610567366004614d23565b610dfd565b34801561057857600080fd5b5061021c600a81565b34801561058d57600080fd5b5061024f61059c366004614e8b565b610e22565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f5a05180f0000000000000000000000000000000000000000000000000000000014806105f757506105f782610f15565b92915050565b336001600160a01b037f000000000000000000000000eef417e1d5cc832e619ae18d2f140de2999dd4fb1614158061063e57506001600160a01b0385163014155b15610675576040517fe17c49b700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61067e81610fac565b61069d3361068c8486614f67565b6001600160a01b0387169190611009565b5050505050565b6106ac611084565b80516106b7816110f7565b8280516000036106f3576040517f4a7aa2a800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60005b815181101561080a57600082828151811061071357610713614f7a565b6020908102919091018101516040810151918101515182519193509081158061073c5750808214155b806107575750835161ffff1660021480156107575750600182115b1561078e576040517f4a7aa2a800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60005b818110156107f4578381815181106107ab576107ab614f7a565b60200260200101516000036107ec576040517f7c946ed700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600101610791565b50505050506108038160010190565b90506106f6565b506000610817858561113d565b905061083d8560008151811061082f5761082f614f7a565b602002602001015182611246565b600080610849876113f4565b91509150610859828288336115dc565b505050505061086760018055565b5050565b60008281526097602052604090206001015461088681611875565b610890838361187f565b505050565b6001600160a01b0381163314610932576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b61086782826118a1565b600054610100900460ff161580801561095c5750600054600160ff909116105b806109765750303b158015610976575060005460ff166001145b610a02576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a65640000000000000000000000000000000000006064820152608401610929565b600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790558015610a6057600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff166101001790555b610a686118c3565b8015610acb57600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b50565b60fb54600090610ae39061ffff166001614fa9565b905061ffff8116600b14610b23576040517f0dc149f000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60fb80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00001661ffff8316179055505050565b600082815260c960205260408120610b6e9083611974565b9392505050565b610b9f7f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca02509633611980565b610bac6020820182614fd6565b610bb5816119dc565b8160200135610bc381611a1f565b61012d5461012e5463ffffffff90911690610be16020860186614fd6565b63ffffffff168263ffffffff16148015610bfe5750846020013581145b15610c0a575050505050565b8461012d610c188282614ff3565b507f707740459746824d259c9a0c2bfabcb04306f48ffc0c1c9c1404e990bf67d217905082610c4a6020880188614fd6565b6040805163ffffffff938416815292909116602083810191909152908201849052870135606082015260800160405180910390a15050505050565b600081815260c9602052604081206105f790611a59565b610ca4611084565b82610cae816110f7565b81610cb881611a1f565b610d02848787610cc960018261503b565b818110610cd857610cd8614f7a565b9050602002810190610cea919061504e565b610cfb90606081019060400161508c565b8534611a63565b610d176001600160a01b038516333086611b48565b610d29610d2486886150a9565b611b8a565b610d3d6001600160a01b0385163385611c4d565b6040805160018082528183019092526000916020808301908036833750506040805160018082528183019092529293506000929150602080830190803683370190505090508582600081518110610d9657610d96614f7a565b60200260200101906001600160a01b031690816001600160a01b0316815250508481600081518110610dca57610dca614f7a565b6020908102919091010152610dea8282610de48a8c6150a9565b336115dc565b50505050610df760018055565b50505050565b600082815260976020526040902060010154610e1881611875565b61089083836118a1565b336001600160a01b037f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c81614610e84576040517fe17c49b700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610e8d81610fac565b60005b845181101561069d57610f0d33848381518110610eaf57610eaf614f7a565b6020026020010151868481518110610ec957610ec9614f7a565b6020026020010151610edb9190614f67565b878481518110610eed57610eed614f7a565b60200260200101516001600160a01b03166110099092919063ffffffff16565b600101610e90565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b0000000000000000000000000000000000000000000000000000000014806105f757507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316146105f7565b60008082806020019051810190610fc391906152c1565b915091508151600003610fd95761089081611b8a565b610fe3828261113d565b925061089082600081518110610ffb57610ffb614f7a565b602002602001015184611246565b8060000361101657505050565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03841603611070576040516001600160a01b0383169082156108fc029083906000818181858888f19350505050158015610df7573d6000803e3d6000fd5b6108906001600160a01b0384168383611c91565b6002600154036110f0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610929565b6002600155565b60028110806111065750600a81115b15610acb576040517f76987d0e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b606060006001845161114f919061503b565b67ffffffffffffffff811115611167576111676147c6565b6040519080825280602002602001820160405280156111c057816020015b6111ad6040518060600160405280600061ffff16815260200160608152602001606081525090565b8152602001906001900390816111855790505b50905060005b815181101561121a578460018201815181106111e4576111e4614f7a565b60200260200101518282815181106111fe576111fe614f7a565b60200260200101819052506112138160010190565b90506111c6565b50808360405160200161122e92919061558d565b60405160208183030381529060405291505092915050565b815161ffff167ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01611336577f000000000000000000000000eef417e1d5cc832e619ae18d2f140de2999dd4fb6001600160a01b031663adf51de183602001516000815181106112b8576112b8614f7a565b602002602001015184604001516000815181106112d7576112d7614f7a565b602002602001015130856040518563ffffffff1660e01b81526004016113009493929190615685565b600060405180830381600087803b15801561131a57600080fd5b505af115801561132e573d6000803e3d6000fd5b505050505050565b815161ffff167ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9016113c2577f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c86001600160a01b0316635c38449e3061139d856020015190565b8560400151856040518563ffffffff1660e01b815260040161130094939291906156c1565b6040517f0d82421600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6060806000805b84518110156114385784818151811061141657611416614f7a565b602002602001015160200151518261142e9190614f67565b91506001016113fb565b5060008167ffffffffffffffff811115611454576114546147c6565b60405190808252806020026020018201604052801561147d578160200160208202803683370190505b50905060008267ffffffffffffffff81111561149b5761149b6147c6565b6040519080825280602002602001820160405280156114c4578160200160208202803683370190505b5090506000805b87518110156115cf5760005b8882815181106114e9576114e9614f7a565b602002602001015160200151518110156115c65788828151811061150f5761150f614f7a565b602002602001015160200151818151811061152c5761152c614f7a565b602002602001015185848151811061154657611546614f7a565b60200260200101906001600160a01b031690816001600160a01b03168152505088828151811061157857611578614f7a565b602002602001015160400151818151811061159557611595614f7a565b60200260200101518484815181106115af576115af614f7a565b6020908102919091010152600192830192016114d7565b506001016114cb565b5091969095509350505050565b835160008167ffffffffffffffff8111156115f9576115f96147c6565b604051908082528060200260200182016040528015611622578160200160208202803683370190505b50905060008267ffffffffffffffff811115611640576116406147c6565b604051908082528060200260200182016040528015611669578160200160208202803683370190505b50905060005b838110156117f557600088828151811061168b5761168b614f7a565b6020026020010151905060006116b330836001600160a01b0316611d3a90919063ffffffff16565b61012d54909150600090620f4240906116d29063ffffffff1684615739565b6116dc9190615750565b9050808203828214611788576001600160a01b037f0000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c8116908516036117545761174f6001600160a01b0385167f0000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c83611009565b611788565b6117886001600160a01b0385167f000000000000000000000000ba7d1581db6248dc9177466a328bf457703c8f8483611c4d565b81156117a2576117a26001600160a01b0385168a84611c4d565b818686815181106117b5576117b5614f7a565b602002602001018181525050808786815181106117d4576117d4614f7a565b602002602001018181525050505050506117ee8160010190565b905061166f565b5060008060008061180589611df7565b93509350935093506118178282612095565b876001600160a01b03167f5d6ce85adcad908fcf78bd40c0eb5b27bd4e0759ba3f1603df6aa38fc8b2efb585858e8e8b8b60405161185a969594939291906157c4565b60405180910390a25050505050505050505050565b60018055565b610acb8133612198565b6118898282612227565b600082815260c96020526040902061089090826122e7565b6118ab82826122fc565b600082815260c960205260409020610890908261239d565b600054610100900460ff1661195a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401610929565b6119626123b2565b61196a612451565b6119726124f8565b565b6000610b6e83836125e4565b60008281526097602090815260408083206001600160a01b038516845290915290205460ff16610867576040517f4ca8886700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b620f424063ffffffff82161115610acb576040517f58d620b300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80600003610acb576040517f7c946ed700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006105f7825490565b836001600160a01b0316836001600160a01b031614611aae576040517ffa48e42300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03851603611b1057818114611b0b576040517f74ebc29c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610df7565b8015610df7576040517f74ebc29c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b801580611b71575073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038516145b610df757610df76001600160a01b03851684848461260e565b60005b8151811015610867576000828281518110611baa57611baa614f7a565b602002602001015190506000611bd63083602001516001600160a01b0316611d3a90919063ffffffff16565b90506000826060015160001480611bf05750818360600151115b15611bfc575080611c03565b5060608201515b611c39836000015161ffff16846020015185604001518487608001518860a001518960c001518a60e001518b610100015161265f565b505050611c468160010190565b9050611b8d565b80600003611c5a57505050565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03841603611070576108906001600160a01b038316826139cc565b6040516001600160a01b0383166024820152604481018290526108909084907fa9059cbb00000000000000000000000000000000000000000000000000000000906064015b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152613b19565b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03841603611d7157506001600160a01b038116316105f7565b826040517f70a082310000000000000000000000000000000000000000000000000000000081526001600160a01b03848116600483015291909116906370a0823190602401602060405180830381865afa158015611dd3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b6e9190615866565b60608060606000845167ffffffffffffffff811115611e1857611e186147c6565b604051908082528060200260200182016040528015611e41578160200160208202803683370190505b50935084516002611e529190615739565b67ffffffffffffffff811115611e6a57611e6a6147c6565b604051908082528060200260200182016040528015611e93578160200160208202803683370190505b50925084516002611ea49190615739565b67ffffffffffffffff811115611ebc57611ebc6147c6565b604051908082528060200260200182016040528015611ee5578160200160208202803683370190505b5091506000905060005b855181101561208d57858181518110611f0a57611f0a614f7a565b602002602001015160000151858281518110611f2857611f28614f7a565b602002602001019061ffff16908161ffff16815250506000868281518110611f5257611f52614f7a565b60200260200101516020015190506000878381518110611f7457611f74614f7a565b60200260200101516040015190508186846002611f919190615739565b81518110611fa157611fa1614f7a565b6001600160a01b03909216602092830291909101909101528086611fc6856002615739565b611fd1906001614f67565b81518110611fe157611fe1614f7a565b60200260200101906001600160a01b031690816001600160a01b03168152505061200c828686613c1b565b612042578185858151811061202357612023614f7a565b6001600160a01b03909216602092830291909101909101526001840193505b61204d818686613c1b565b612083578085858151811061206457612064614f7a565b6001600160a01b03909216602092830291909101909101526001840193505b5050600101611eef565b509193509193565b60005b818110156108905760008382815181106120b4576120b4614f7a565b6020026020010151905060006120dc30836001600160a01b0316611d3a90919063ffffffff16565b9050806000036120ed575050612190565b6001600160a01b037f0000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c811690831603612159576121546001600160a01b0383167f0000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c83611009565b61218d565b61218d6001600160a01b0383167f000000000000000000000000ba7d1581db6248dc9177466a328bf457703c8f8483611c4d565b50505b600101612098565b60008281526097602090815260408083206001600160a01b038516845290915290205460ff16610867576121cb81613c76565b6121d6836020613c88565b6040516020016121e792919061587f565b60408051601f19818403018152908290527f08c379a000000000000000000000000000000000000000000000000000000000825261092991600401615900565b60008281526097602090815260408083206001600160a01b038516845290915290205460ff166108675760008281526097602090815260408083206001600160a01b0385168452909152902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790556122a33390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000610b6e836001600160a01b038416613ecb565b60008281526097602090815260408083206001600160a01b038516845290915290205460ff16156108675760008281526097602090815260408083206001600160a01b038516808552925280832080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000610b6e836001600160a01b038416613f1a565b600054610100900460ff16612449576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401610929565b611972614014565b600054610100900460ff166124e8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401610929565b6124f06140ab565b611972614142565b600054610100900460ff1661258f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401610929565b604080518082019091526207a120808252683635c9adc5dea00000602090920182905261012d80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000016909117905561012e55565b60008260000182815481106125fb576125fb614f7a565b9060005260206000200154905092915050565b6040516001600160a01b0380851660248301528316604482015260648101829052610df79085907f23b872dd0000000000000000000000000000000000000000000000000000000090608401611cd6565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8901612834576126b1887f0000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb088614258565b604080516003808252608082019092526000916020820160608036833701905050905088816000815181106126e8576126e8614f7a565b60200260200101906001600160a01b031690816001600160a01b031681525050838160018151811061271c5761271c614f7a565b60200260200101906001600160a01b031690816001600160a01b031681525050878160028151811061275057612750614f7a565b6001600160a01b0392831660209182029290920101526000908a1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1461278c57600061278e565b875b90507f0000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb06001600160a01b031663b77d239b82848b8b60008060006040518863ffffffff1660e01b81526004016127e996959493929190615913565b60206040518083038185885af1158015612807573d6000803e3d6000fd5b50505050506040513d601f19601f8201168201806040525081019061282c9190615866565b5050506139c1565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe890161298c57612886887f000000000000000000000000eef417e1d5cc832e619ae18d2f140de2999dd4fb88614258565b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038a16146128b35760006128b5565b865b6040517fd895feee0000000000000000000000000000000000000000000000000000000081526001600160a01b038b811660048301528a81166024830152604482018a90526064820189905260848201889052600060a48301529192507f000000000000000000000000eef417e1d5cc832e619ae18d2f140de2999dd4fb9091169063d895feee90839060c40160206040518083038185885af1158015612960573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906129859190615866565b50506139c1565b600389148061299b5750600589145b15612d855760006001600160a01b038416612a075760038a146129de577f000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f612a00565b7f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d5b9050612a0a565b50825b612a15898289614258565b60408051600280825260608201835260009260208301908036833701905050905073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038b1603612b6b577f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281600081518110612a8e57612a8e614f7a565b60200260200101906001600160a01b031690816001600160a01b0316815250508881600181518110612ac257612ac2614f7a565b6001600160a01b0392831660209182029290920101526040517f7ff36ab500000000000000000000000000000000000000000000000000000000815290831690637ff36ab5908a90612b1e908b90869030908d90600401615959565b60006040518083038185885af1158015612b3c573d6000803e3d6000fd5b50505050506040513d6000823e601f3d908101601f19168201604052612b65919081019061598e565b50612985565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038a1603612c9a578981600081518110612ba357612ba3614f7a565b60200260200101906001600160a01b031690816001600160a01b0316815250507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281600181518110612bf757612bf7614f7a565b6001600160a01b0392831660209182029290920101526040517f18cbafe5000000000000000000000000000000000000000000000000000000008152908316906318cbafe590612c53908b908b90869030908d906004016159c3565b6000604051808303816000875af1158015612c72573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612b65919081019061598e565b8981600081518110612cae57612cae614f7a565b60200260200101906001600160a01b031690816001600160a01b0316815250508881600181518110612ce257612ce2614f7a565b6001600160a01b0392831660209182029290920101526040517f38ed1739000000000000000000000000000000000000000000000000000000008152908316906338ed173990612d3e908b908b90869030908d906004016159c3565b6000604051808303816000875af1158015612d5d573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261282c919081019061598e565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc8901612eff5760006001600160a01b038416612de357507f000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564612de6565b50825b612df1898289614258565b60408051610100810182526001600160a01b038b811682528a81166020830190815262ffffff8781168486019081523060608601908152608086018c815260a087018f815260c088018f8152600060e08a0190815299517f414bf38900000000000000000000000000000000000000000000000000000000815289518916600482015296518816602488015293519094166044860152905185166064850152516084840152905160a48301525160c48201529251811660e484015290919083169063414bf38990610104016020604051808303816000875af1158015612edb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061282c9190615866565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa890161310b5760006001600160a01b038416612f5d57507f000000000000000000000000c537e898cd774e2dcba3b14ea6f34c93d5ea45e1612f60565b50825b6fffffffffffffffffffffffffffffffff861115612faa576040517f7d5ee39100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b612fb5898289614258565b600183811614600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038c1614612fe8576000612fea565b885b90506000848060200190518101906130029190615a1f565b9050821561308857836001600160a01b031663102ee9ba838e8e858d8f6040518763ffffffff1660e01b815260040161303f959493929190615ad2565b60206040518083038185885af115801561305d573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906130829190615b6f565b50613102565b836001600160a01b031663f1c5e014838e8e858d8f6040518763ffffffff1660e01b81526004016130bd959493929190615ad2565b60206040518083038185885af11580156130db573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906131009190615b6f565b505b505050506139c1565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff989016132c3577f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c861315e898289614258565b6040805160c0810182528481526000602082018190529181016001600160a01b038c1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee146131a1578b6131a4565b60005b6001600160a01b031681526020016131e18b6001600160a01b03166001600160a01b031673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1490565b6131eb578a6131ee565b60005b6001600160a01b03908116825260208083018c9052604080518083018252600080825294820152805160808101825230808252928101859052808201929092526060820184905284015193945092161561324957600061324b565b895b9050836001600160a01b03166352bbbe298285858d8d6040518663ffffffff1660e01b81526004016132809493929190615b8a565b60206040518083038185885af115801561329e573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906131009190615866565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff88901613677576fffffffffffffffffffffffffffffffff861115613334576040517fcd0ac5e600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b0389161415801561338e57507f0000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c6001600160a01b0390811690891614155b156133c5576040517f0896c96900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7f0000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c6001600160a01b0390811690891614801561341e575073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03881614155b15613455576040517f0896c96900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b613480887f000000000000000000000000d06146d292f9651c1d7cf54a3162791dfc2bef4688614258565b6040517f824316880000000000000000000000000000000000000000000000000000000081526001600160a01b0388811660048301526fffffffffffffffffffffffffffffffff881660248301526000917f000000000000000000000000d06146d292f9651c1d7cf54a3162791dfc2bef4690911690638243168890604401602060405180830381865afa15801561351c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135409190615b6f565b905085816fffffffffffffffffffffffffffffffff16101561358e576040517fb34424fd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038b16146135bb5760006135bd565b875b6040517f4747919d0000000000000000000000000000000000000000000000000000000081526001600160a01b038b811660048301526fffffffffffffffffffffffffffffffff851660248301529192507f000000000000000000000000d06146d292f9651c1d7cf54a3162791dfc2bef4690911690634747919d9083906044016000604051808303818588803b15801561365757600080fd5b505af115801561366b573d6000803e3d6000fd5b505050505050506139c1565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7890161377e57826001600160a01b0381166136df576040517fa79aa26d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038b161461370c57600061370e565b875b905061371b8a838a614258565b6040517f3df02124000000000000000000000000000000000000000000000000000000008152600f85900b6004820152608085901d602482015260448101899052606481018890526001600160a01b03831690633df021249083906084016127e9565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6890161398f5773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b0389161480156137fd57507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b03908116908816145b15613871577f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663d0e30db0876040518263ffffffff1660e01b81526004016000604051808303818588803b15801561385d57600080fd5b505af1158015613100573d6000803e3d6000fd5b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b039081169089161480156138c9575073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038816145b1561395d576040517f2e1a7d4d000000000000000000000000000000000000000000000000000000008152600481018790527f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031690632e1a7d4d90602401600060405180830381600087803b15801561394957600080fd5b505af1158015613102573d6000803e3d6000fd5b6040517f93f8a1ad00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f8260f36600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505050505050505050565b80471015613a36576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e63650000006044820152606401610929565b6000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114613a83576040519150601f19603f3d011682016040523d82523d6000602084013e613a88565b606091505b5050905080610890576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d617920686176652072657665727465640000000000006064820152608401610929565b6000613b6e826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166143569092919063ffffffff16565b9050805160001480613b8f575080806020019051810190613b8f9190615c83565b610890576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610929565b6000805b82811015613c6b57846001600160a01b0316848281518110613c4357613c43614f7a565b60200260200101516001600160a01b031603613c63576001915050610b6e565b600101613c1f565b506000949350505050565b60606105f76001600160a01b03831660145b60606000613c97836002615739565b613ca2906002614f67565b67ffffffffffffffff811115613cba57613cba6147c6565b6040519080825280601f01601f191660200182016040528015613ce4576020820181803683370190505b5090507f300000000000000000000000000000000000000000000000000000000000000081600081518110613d1b57613d1b614f7a565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110613d7e57613d7e614f7a565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053506000613dba846002615739565b613dc5906001614f67565b90505b6001811115613e62577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110613e0657613e06614f7a565b1a60f81b828281518110613e1c57613e1c614f7a565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535060049490941c93613e5b81615ca5565b9050613dc8565b508315610b6e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610929565b6000818152600183016020526040812054613f12575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556105f7565b5060006105f7565b60008181526001830160205260408120548015614003576000613f3e60018361503b565b8554909150600090613f529060019061503b565b9050818114613fb7576000866000018281548110613f7257613f72614f7a565b9060005260206000200154905080876000018481548110613f9557613f95614f7a565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080613fc857613fc8615cda565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506105f7565b60009150506105f7565b5092915050565b600054610100900460ff1661186f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401610929565b600054610100900460ff16611972576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401610929565b600054610100900460ff166141d9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401610929565b60fb80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000016600b17905561422e7f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca0250968061436d565b6119727f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca025096336143b8565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b0384160361428157505050565b60006001600160a01b0384166040517fdd62ed3e0000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038581166024830152919091169063dd62ed3e90604401602060405180830381865afa1580156142f4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906143189190615866565b905081811015610df757610df76001600160a01b038516847fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6143c2565b606061436584846000856143ff565b949350505050565b600082815260976020526040808220600101805490849055905190918391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b610867828261187f565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038416036143eb57505050565b6108906001600160a01b038416838361450b565b606082471015614491576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c00000000000000000000000000000000000000000000000000006064820152608401610929565b600080866001600160a01b031685876040516144ad9190615d09565b60006040518083038185875af1925050503d80600081146144ea576040519150601f19603f3d011682016040523d82523d6000602084013e6144ef565b606091505b5091509150614500878383876145e1565b979650505050505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f095ea7b30000000000000000000000000000000000000000000000000000000017905261458a8482614674565b610df7576040516001600160a01b0384166024820152600060448201526145d79085907f095ea7b30000000000000000000000000000000000000000000000000000000090606401611cd6565b610df78482613b19565b6060831561466a578251600003614663576001600160a01b0385163b614663576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610929565b5081614365565b614365838361471b565b6000806000846001600160a01b0316846040516146919190615d09565b6000604051808303816000865af19150503d80600081146146ce576040519150601f19603f3d011682016040523d82523d6000602084013e6146d3565b606091505b50915091508180156146fd5750805115806146fd5750808060200190518101906146fd9190615c83565b801561471257506001600160a01b0385163b15155b95945050505050565b81511561472b5781518083602001fd5b806040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109299190615900565b60006020828403121561477157600080fd5b81357fffffffff0000000000000000000000000000000000000000000000000000000081168114610b6e57600080fd5b6001600160a01b0381168114610acb57600080fd5b80356147c1816147a1565b919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b604051610120810167ffffffffffffffff81118282101715614819576148196147c6565b60405290565b6040516060810167ffffffffffffffff81118282101715614819576148196147c6565b6040805190810167ffffffffffffffff81118282101715614819576148196147c6565b604051601f8201601f1916810167ffffffffffffffff8111828210171561488e5761488e6147c6565b604052919050565b600067ffffffffffffffff8211156148b0576148b06147c6565b50601f01601f191660200190565b600082601f8301126148cf57600080fd5b81356148e26148dd82614896565b614865565b8181528460208386010111156148f757600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080600060a0868803121561492c57600080fd5b8535614937816147a1565b94506020860135614947816147a1565b93506040860135925060608601359150608086013567ffffffffffffffff81111561497157600080fd5b61497d888289016148be565b9150509295509295909350565b60006020828403121561499c57600080fd5b5035919050565b600067ffffffffffffffff8211156149bd576149bd6147c6565b5060051b60200190565b61ffff81168114610acb57600080fd5b80356147c1816149c7565b600082601f8301126149f357600080fd5b81356020614a036148dd836149a3565b82815260059290921b84018101918181019086841115614a2257600080fd5b8286015b84811015614a46578035614a39816147a1565b8352918301918301614a26565b509695505050505050565b600082601f830112614a6257600080fd5b81356020614a726148dd836149a3565b82815260059290921b84018101918181019086841115614a9157600080fd5b8286015b84811015614a465780358352918301918301614a95565b6000614aba6148dd846149a3565b8381529050602080820190600585901b840186811115614ad957600080fd5b845b81811015614bb657803567ffffffffffffffff80821115614afc5760008081fd5b90870190610120828b031215614b125760008081fd5b614b1a6147f5565b614b23836149d7565b8152614b308684016147b6565b868201526040614b418185016147b6565b90820152606083810135908201526080808401359082015260a0808401359082015260c0614b708185016147b6565b9082015260e083810135908201526101008084013583811115614b935760008081fd5b614b9f8d8287016148be565b918301919091525086525050928201928201614adb565b505050509392505050565b600082601f830112614bd257600080fd5b610b6e83833560208501614aac565b60008060408385031215614bf457600080fd5b823567ffffffffffffffff80821115614c0c57600080fd5b818501915085601f830112614c2057600080fd5b81356020614c306148dd836149a3565b82815260059290921b84018101918181019089841115614c4f57600080fd5b8286015b84811015614cf557803586811115614c6b5760008081fd5b87016060818d03601f1901811315614c835760008081fd5b614c8b61481f565b86830135614c98816149c7565b8152604083013589811115614cad5760008081fd5b614cbb8f89838701016149e2565b8289015250908201359088821115614cd35760008081fd5b614ce18e8884860101614a51565b604082015285525050918301918301614c53565b5096505086013592505080821115614d0c57600080fd5b50614d1985828601614bc1565b9150509250929050565b60008060408385031215614d3657600080fd5b823591506020830135614d48816147a1565b809150509250929050565b60008060208385031215614d6657600080fd5b823567ffffffffffffffff80821115614d7e57600080fd5b818501915085601f830112614d9257600080fd5b813581811115614da157600080fd5b866020828501011115614db357600080fd5b60209290920196919550909350505050565b60008060408385031215614dd857600080fd5b50508035926020909101359150565b600060408284031215614df957600080fd5b50919050565b60008060008060608587031215614e1557600080fd5b843567ffffffffffffffff80821115614e2d57600080fd5b818701915087601f830112614e4157600080fd5b813581811115614e5057600080fd5b8860208260051b8501011115614e6557600080fd5b60209283019650945050850135614e7b816147a1565b9396929550929360400135925050565b60008060008060808587031215614ea157600080fd5b843567ffffffffffffffff80821115614eb957600080fd5b614ec5888389016149e2565b95506020870135915080821115614edb57600080fd5b614ee788838901614a51565b94506040870135915080821115614efd57600080fd5b614f0988838901614a51565b93506060870135915080821115614f1f57600080fd5b50614f2c878288016148be565b91505092959194509250565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b808201808211156105f7576105f7614f38565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b61ffff81811683821601908082111561400d5761400d614f38565b63ffffffff81168114610acb57600080fd5b600060208284031215614fe857600080fd5b8135610b6e81614fc4565b8135614ffe81614fc4565b63ffffffff81167fffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000083541617825550602082013560018201555050565b818103818111156105f7576105f7614f38565b600082357ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffee183360301811261508257600080fd5b9190910192915050565b60006020828403121561509e57600080fd5b8135610b6e816147a1565b6000610b6e368484614aac565b80516147c1816149c7565b600082601f8301126150d257600080fd5b815160206150e26148dd836149a3565b82815260059290921b8401810191818101908684111561510157600080fd5b8286015b84811015614a465780518352918301918301615105565b80516147c1816147a1565b60005b8381101561514257818101518382015260200161512a565b50506000910152565b600082601f83011261515c57600080fd5b815161516a6148dd82614896565b81815284602083860101111561517f57600080fd5b614365826020830160208701615127565b600082601f8301126151a157600080fd5b815160206151b16148dd836149a3565b82815260059290921b840181019181810190868411156151d057600080fd5b8286015b84811015614a4657805167ffffffffffffffff808211156151f55760008081fd5b818901915061012080601f19848d030112156152115760008081fd5b6152196147f5565b6152248885016150b6565b8152604061523381860161511c565b89830152606061524481870161511c565b828401526080915081860151818401525060a0808601518284015260c0915081860151818401525060e061527981870161511c565b8284015261010091508186015181840152508285015192508383111561529f5760008081fd5b6152ad8d8a8588010161514b565b9082015286525050509183019183016151d4565b600080604083850312156152d457600080fd5b825167ffffffffffffffff808211156152ec57600080fd5b818501915085601f83011261530057600080fd5b815161530e6148dd826149a3565b8082825260208201915060208360051b86010192508883111561533057600080fd5b602085015b838110156154385780518581111561534c57600080fd5b86016060818c03601f1901121561536257600080fd5b61536a61481f565b6020820151615378816149c7565b815260408201518781111561538c57600080fd5b8201603f81018d1361539d57600080fd5b60208101516153ae6148dd826149a3565b81815260059190911b82016040019060208101908f8311156153cf57600080fd5b6040840193505b828410156153fa5783516153e9816147a1565b8252602093840193909101906153d6565b602085015250505060608201518781111561541457600080fd5b6154238d6020838601016150c1565b60408301525084525060209283019201615335565b506020880151909650935050508082111561545257600080fd5b50614d1985828601615190565b600081518084526020808501945080840160005b8381101561548f57815187529582019590820190600101615473565b509495945050505050565b600081518084526154b2816020860160208601615127565b601f01601f19169290920160200192915050565b600081518084526020808501808196508360051b8101915082860160005b858110156155805782840389528151805161ffff168552858101516001600160a01b0390811687870152604080830151821690870152606080830151908701526080808301519087015260a0808301519087015260c0808301519091169086015260e08082015190860152610100908101516101209186018290529061556c8187018361549a565b9a87019a95505050908401906001016154e4565b5091979650505050505050565b60006040808301818452808651808352606092508286019150828160051b8701016020808a016000805b85811015615664578a85037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa00187528251805161ffff168652848101518587018a905280518a880181905290860190849060808901905b808310156156375783516001600160a01b0316825292880192600192909201919088019061560e565b50928c0151888403898e01529261564e818561545f565b9a88019a985050509385019350506001016155b7565b5050508782039088015261567881896154c6565b9998505050505050505050565b60006001600160a01b038087168352856020840152808516604084015250608060608301526156b7608083018461549a565b9695505050505050565b6000608082016001600160a01b038088168452602060808186015282885180855260a087019150828a01945060005b8181101561570e5785518516835294830194918301916001016156f0565b50508581036040870152615722818961545f565b93505050508281036060840152614500818561549a565b80820281158282048414176105f7576105f7614f38565b600082615786577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b600081518084526020808501945080840160005b8381101561548f5781516001600160a01b03168752958201959082019060010161579f565b60c0808252875190820181905260009060209060e0840190828b01845b8281101561580157815161ffff16845292840192908401906001016157e1565b50505083810382850152615815818a61578b565b915050828103604084015261582a818861578b565b9050828103606084015261583e818761545f565b90508281036080840152615852818661545f565b905082810360a0840152615678818561545f565b60006020828403121561587857600080fd5b5051919050565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516158b7816017850160208801615127565b7f206973206d697373696e6720726f6c652000000000000000000000000000000060179184019182015283516158f4816028840160208801615127565b01602801949350505050565b602081526000610b6e602083018461549a565b60c08152600061592660c083018961578b565b60208301979097525060408101949094526001600160a01b0392831660608501529116608083015260a090910152919050565b848152608060208201526000615972608083018661578b565b6001600160a01b03949094166040830152506060015292915050565b6000602082840312156159a057600080fd5b815167ffffffffffffffff8111156159b757600080fd5b614365848285016150c1565b85815284602082015260a0604082015260006159e260a083018661578b565b6001600160a01b0394909416606083015250608001529392505050565b80516fffffffffffffffffffffffffffffffff811681146147c157600080fd5b60006020808385031215615a3257600080fd5b825167ffffffffffffffff811115615a4957600080fd5b8301601f81018513615a5a57600080fd5b8051615a686148dd826149a3565b81815260069190911b82018301908381019087831115615a8757600080fd5b928401925b828410156145005760408489031215615aa55760008081fd5b615aad614842565b84518152615abc8686016159ff565b8187015282526040939093019290840190615a8c565b600060a082016001600160a01b0380891684526020818916818601526040915060a08286015282885180855260c087019150828a01945060005b81811015615b43578551805184528401516fffffffffffffffffffffffffffffffff16848401529483019491840191600101615b0c565b5050606086018890526fffffffffffffffffffffffffffffffff8716608087015293506156b792505050565b600060208284031215615b8157600080fd5b610b6e826159ff565b60e08152845160e08201526000602086015160028110615bd3577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b61010083015260408601516001600160a01b03166101208301526060860151615c086101408401826001600160a01b03169052565b50608086015161016083015260a086015160c0610180840152615c2f6101a084018261549a565b915050615c7160208301866001600160a01b03808251168352602082015115156020840152806040830151166040840152506060810151151560608301525050565b60a082019390935260c0015292915050565b600060208284031215615c9557600080fd5b81518015158114610b6e57600080fd5b600081615cb457615cb4614f38565b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603160045260246000fd5b6000825161508281846020870161512756fea164736f6c6343000813000a
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000ba7d1581db6248dc9177466a328bf457703c8f840000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb0000000000000000000000000eef417e1d5cc832e619ae18d2f140de2999dd4fb0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f000000000000000000000000c537e898cd774e2dcba3b14ea6f34c93d5ea45e1000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c8000000000000000000000000d06146d292f9651c1d7cf54a3162791dfc2bef46
-----Decoded View---------------
Arg [0] : initBnt (address): 0x1F573D6Fb3F13d689FF844B4cE37794d79a7FF1C
Arg [1] : initWeth (address): 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
Arg [2] : initProtocolWallet (address): 0xba7d1581Db6248DC9177466a328BF457703c8f84
Arg [3] : platforms (tuple):
Arg [1] : bancorNetworkV2 (address): 0x2F9EC37d6CcFFf1caB21733BdaDEdE11c823cCB0
Arg [2] : bancorNetworkV3 (address): 0xeEF417e1D5CC832e619ae18D2F140De2999dD4fB
Arg [3] : uniV2Router (address): 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
Arg [4] : uniV3Router (address): 0xE592427A0AEce92De3Edee1F18E0157C05861564
Arg [5] : sushiswapRouter (address): 0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F
Arg [6] : carbonController (address): 0xC537e898CD774e2dCBa3B14Ea6f34C93d5eA45e1
Arg [7] : balancerVault (address): 0xBA12222222228d8Ba445958a75a0704d566BF2C8
Arg [8] : carbonPOL (address): 0xD06146D292F9651C1D7cf54A3162791DFc2bEf46
-----Encoded View---------------
11 Constructor Arguments found :
Arg [0] : 0000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c
Arg [1] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Arg [2] : 000000000000000000000000ba7d1581db6248dc9177466a328bf457703c8f84
Arg [3] : 0000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb0
Arg [4] : 000000000000000000000000eef417e1d5cc832e619ae18d2f140de2999dd4fb
Arg [5] : 0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d
Arg [6] : 000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564
Arg [7] : 000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f
Arg [8] : 000000000000000000000000c537e898cd774e2dcba3b14ea6f34c93d5ea45e1
Arg [9] : 000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c8
Arg [10] : 000000000000000000000000d06146d292f9651c1d7cf54a3162791dfc2bef46
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 33 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.