Source Code
Latest 1 from a total of 1 transactions
| Transaction Hash |
Method
|
Block
|
From
|
|
To
|
||||
|---|---|---|---|---|---|---|---|---|---|
| Initialize | 18333519 | 881 days ago | IN | 0 ETH | 0.00227845 |
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 { PPM_RESOLUTION } from "../utility/Constants.sol";
import { MathEx } from "../utility/MathEx.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 SourceTokenIsNotETH();
error TargetTokenIsETH();
// 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 = 6;
uint16 public constant PLATFORM_ID_BALANCER = 7;
uint16 public constant PLATFORM_ID_CARBON_POL = 8;
// 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;
// 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 a "virtual" constructor that is only used to set immutable state variables
*/
constructor(
IERC20 initBnt,
address initProtocolWallet,
Platforms memory platforms
)
validAddress(address(initBnt))
validAddress(address(initProtocolWallet))
validAddress(address(platforms.bancorNetworkV2))
validAddress(address(platforms.bancorNetworkV3))
validAddress(address(platforms.uniV2Router))
validAddress(address(platforms.uniV3Router))
validAddress(address(platforms.sushiswapRouter))
validAddress(address(platforms.carbonController))
validAddress(address(platforms.balancerVault))
validAddress(address(platforms.carbonPOL))
{
_bnt = initBnt;
_weth = IERC20(platforms.uniV2Router.WETH());
_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;
}
/**
* @dev fully initializes the contract and its parents
*/
function initialize() external 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: 100000, maxAmount: 100 * 1e18 });
}
/**
* @dev authorize the contract to receive the native token
*/
receive() external payable {}
/**
* @inheritdoc Upgradeable
*/
function version() public pure override(Upgradeable) returns (uint16) {
return 7;
}
/**
* @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 view {
// verify that the last token in the process is the arb token
if (finalToken != token) {
revert InvalidInitialAndFinalTokens();
}
// validate token is tradeable on v3
if (!token.isEqual(_bnt) && _bancorNetworkV3.collectionByPool(token) == address(0)) {
revert InvalidSourceToken();
}
// 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);
}
address tokenIn = sourceToken.isNative() ? address(_weth) : address(sourceToken);
address tokenOut = targetToken.isNative() ? address(_weth) : address(targetToken);
if (tokenIn == address(_weth)) {
IWETH(address(_weth)).deposit{ value: sourceAmount }();
}
// allow the router to withdraw the source tokens
_setPlatformAllowance(Token(tokenIn), address(router), sourceAmount);
// build the params
ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams({
tokenIn: tokenIn,
tokenOut: tokenOut,
fee: uint24(customInt), // fee
recipient: address(this),
deadline: deadline,
amountIn: sourceAmount,
amountOutMinimum: minTargetAmount,
sqrtPriceLimitX96: uint160(0)
});
// perform the trade
router.exactInputSingle(params);
if (tokenOut == address(_weth)) {
IWETH(address(_weth)).withdraw(_weth.balanceOf(address(this)));
}
return;
}
if (platformId == PLATFORM_ID_CARBON) {
// 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(_carbonController), sourceAmount);
uint256 val = sourceToken.isNative() ? sourceAmount : 0;
// decode the trade actions passed in as customData
TradeAction[] memory tradeActions = abi.decode(customData, (TradeAction[]));
// perform the trade
_carbonController.tradeBySourceAmount{ value: val }(
sourceToken,
targetToken,
tradeActions,
deadline,
uint128(minTargetAmount)
);
uint256 remainingSourceTokens = sourceToken.balanceOf(address(this));
if (remainingSourceTokens > 0) {
// transfer any remaining source tokens to the protocol wallet
// safe due to nonReentrant modifier (forwards all available gas in case of ETH)
sourceToken.unsafeTransfer(_protocolWallet, remainingSourceTokens);
}
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();
}
// Carbon POL accepts only ETH for sourceToken
if (!sourceToken.isNative()) {
revert SourceTokenIsNotETH();
}
// Carbon POL accepts only non-ETH for targetToken
if (targetToken.isNative()) {
revert TargetTokenIsETH();
}
// get the expected return
uint128 targetAmount = _carbonPOL.expectedTradeReturn(targetToken, uint128(sourceAmount));
// verify the expected return
if (targetAmount < minTargetAmount) {
revert MinTargetAmountNotReached();
}
// perform the trade
_carbonPOL.trade{ value: sourceAmount }(targetToken, targetAmount);
uint256 remainingSourceTokens = sourceToken.balanceOf(address(this));
if (remainingSourceTokens > 0) {
// transfer any remaining source tokens to the protocol wallet
// safe due to nonReentrant modifier (forwards all available gas in case of ETH)
sourceToken.unsafeTransfer(_protocolWallet, remainingSourceTokens);
}
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 = MathEx.mulDivF(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) = _buildArbPath(routes);
emit ArbitrageExecuted(caller, platformIds, path, sourceTokens, sourceAmounts, protocolAmounts, rewardAmounts);
}
/**
* @dev build arb path from TradeRoute array
*/
function _buildArbPath(
TradeRoute[] memory routes
) private pure returns (uint16[] memory platformIds, address[] memory path) {
platformIds = new uint16[](routes.length);
path = new address[](routes.length * 2);
for (uint256 i = 0; i < routes.length; i = uncheckedInc(i)) {
platformIds[i] = routes[i].platformId;
path[i * 2] = address(routes[i].sourceToken);
path[uncheckedInc(i * 2)] = address(routes[i].targetToken);
}
}
/**
* @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);
}
}
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];
if (flashloan.sourceTokens.length == 0) {
revert InvalidFlashloanFormat();
}
if (flashloan.sourceTokens.length != flashloan.sourceAmounts.length) {
revert InvalidFlashloanFormat();
}
if (flashloan.platformId == PLATFORM_ID_BANCOR_V3 && flashloan.sourceTokens.length > 1) {
revert InvalidFlashloanFormat();
}
// check source amounts are not zero in value
uint256[] memory sourceAmounts = flashloan.sourceAmounts;
for (uint256 j = 0; j < sourceAmounts.length; 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 eth amount sent for a token
*/
function expectedTradeReturn(Token token, uint128 ethAmount) external view returns (uint128 tokenAmount);
/**
* @notice trades ETH for *amount* of token based on the current token price (trade by target amount)
*/
function trade(Token token, uint128 amount) external payable;
}// 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;
/**
* @dev this library provides a set of complex math operations
*/
library MathEx {
error Overflow();
/**
* @dev returns the largest integer smaller than or equal to `x * y / z`
*/
function mulDivF(uint256 x, uint256 y, uint256 z) internal pure returns (uint256) {
// safe because no `+` or `-` or `*`
unchecked {
(uint256 xyhi, uint256 xylo) = _mul512(x, y);
// if `x * y < 2 ^ 256`
if (xyhi == 0) {
return xylo / z;
}
// assert `x * y / z < 2 ^ 256`
if (xyhi >= z) {
revert Overflow();
}
uint256 m = _mulMod(x, y, z); // `m = x * y % z`
(uint256 nhi, uint256 nlo) = _sub512(xyhi, xylo, m); // `n = x * y - m` hence `n / z = floor(x * y / z)`
// if `n < 2 ^ 256`
if (nhi == 0) {
return nlo / z;
}
uint256 p = _unsafeSub(0, z) & z; // `p` is the largest power of 2 which `z` is divisible by
uint256 q = _div512(nhi, nlo, p); // `n` is divisible by `p` because `n` is divisible by `z` and `z` is divisible by `p`
uint256 r = _inv256(z / p); // `z / p = 1 mod 2` hence `inverse(z / p) = 1 mod 2 ^ 256`
return _unsafeMul(q, r); // `q * r = (n / p) * inverse(z / p) = n / z`
}
}
/**
* @dev returns the smallest integer larger than or equal to `x * y / z`
*/
function mulDivC(uint256 x, uint256 y, uint256 z) internal pure returns (uint256) {
uint256 w = mulDivF(x, y, z);
if (_mulMod(x, y, z) > 0) {
if (w >= type(uint256).max) {
revert Overflow();
}
unchecked {
// safe because `w < type(uint256).max`
return w + 1;
}
}
return w;
}
/**
* @dev returns the smallest integer `z` such that `x * y / z <= 2 ^ 256 - 1`
*/
function minFactor(uint256 x, uint256 y) internal pure returns (uint256) {
(uint256 hi, uint256 lo) = _mul512(x, y);
unchecked {
// safe because:
// - if `x < 2 ^ 256 - 1` or `y < 2 ^ 256 - 1`
// then `hi < 2 ^ 256 - 2`
// hence neither `hi + 1` nor `hi + 2` overflows
// - if `x = 2 ^ 256 - 1` and `y = 2 ^ 256 - 1`
// then `hi = 2 ^ 256 - 2 = ~lo`
// hence `hi + 1`, which does not overflow, is computed
return hi > ~lo ? hi + 2 : hi + 1;
}
/* reasoning:
|
| general:
| - find the smallest integer `z` such that `x * y / z <= 2 ^ 256 - 1`
| - the value of `x * y` is represented via `2 ^ 256 * hi + lo`
| - the expression `~lo` is equivalent to `2 ^ 256 - 1 - lo`
|
| symbols:
| - let `H` denote `hi`
| - let `L` denote `lo`
| - let `N` denote `2 ^ 256 - 1`
|
| inference:
| `x * y / z <= 2 ^ 256 - 1` <-->
| `x * y / (2 ^ 256 - 1) <= z` <-->
| `((N + 1) * H + L) / N <= z` <-->
| `(N * H + H + L) / N <= z` <-->
| `H + (H + L) / N <= z`
|
| inference:
| `0 <= H <= N && 0 <= L <= N` <-->
| `0 <= H + L <= N + N` <-->
| `0 <= H + L <= N * 2` <-->
| `0 <= (H + L) / N <= 2`
|
| inference:
| - `0 = (H + L) / N` --> `H + L = 0` --> `x * y = 0` --> `z = 1 = H + 1`
| - `0 < (H + L) / N <= 1` --> `H + (H + L) / N <= H + 1` --> `z = H + 1`
| - `1 < (H + L) / N <= 2` --> `H + (H + L) / N <= H + 2` --> `z = H + 2`
|
| implementation:
| - if `hi > ~lo`:
| `~L < H <= N` <-->
| `N - L < H <= N` <-->
| `N < H + L <= N + L` <-->
| `1 < (H + L) / N <= 2` <-->
| `H + 1 < H + (H + L) / N <= H + 2` <-->
| `z = H + 2`
| - if `hi <= ~lo`:
| `H <= ~L` <-->
| `H <= N - L` <-->
| `H + L <= N` <-->
| `(H + L) / N <= 1` <-->
| `H + (H + L) / N <= H + 1` <-->
| `z = H + 1`
|
*/
}
/**
* @dev returns the value of `x * y`
*/
function _mul512(uint256 x, uint256 y) private pure returns (uint256, uint256) {
uint256 p = _mulModMax(x, y);
uint256 q = _unsafeMul(x, y);
if (p >= q) {
unchecked {
// safe because `p >= q`
return (p - q, q);
}
}
unchecked {
// safe because `p < q` hence `_unsafeSub(p, q) > 0`
return (_unsafeSub(p, q) - 1, q);
}
}
/**
* @dev returns the value of `x - y`
*/
function _sub512(uint256 xhi, uint256 xlo, uint256 y) private pure returns (uint256, uint256) {
if (xlo >= y) {
unchecked {
// safe because `xlo >= y`
return (xhi, xlo - y);
}
}
return (xhi - 1, _unsafeSub(xlo, y));
}
/**
* @dev returns the value of `x / pow2n`, given that `x` is divisible by `pow2n`
*/
function _div512(uint256 xhi, uint256 xlo, uint256 pow2n) private pure returns (uint256) {
// safe because no `+` or `-` or `*`
unchecked {
uint256 pow2nInv = _unsafeAdd(_unsafeSub(0, pow2n) / pow2n, 1); // `1 << (256 - n)`
return _unsafeMul(xhi, pow2nInv) | (xlo / pow2n); // `(xhi << (256 - n)) | (xlo >> n)`
}
}
/**
* @dev returns the inverse of `d` modulo `2 ^ 256`, given that `d` is congruent to `1` modulo `2`
*/
function _inv256(uint256 d) private pure returns (uint256) {
// approximate the root of `f(x) = 1 / x - d` using the newton–raphson convergence method
uint256 x = 1;
unchecked {
// safe because `i < 8`
for (uint256 i = 0; i < 8; i++) {
x = _unsafeMul(x, _unsafeSub(2, _unsafeMul(x, d))); // `x = x * (2 - x * d) mod 2 ^ 256`
}
}
return x;
}
/**
* @dev returns `(x + y) % 2 ^ 256`
*/
function _unsafeAdd(uint256 x, uint256 y) private pure returns (uint256) {
unchecked {
return x + y;
}
}
/**
* @dev returns `(x - y) % 2 ^ 256`
*/
function _unsafeSub(uint256 x, uint256 y) private pure returns (uint256) {
unchecked {
return x - y;
}
}
/**
* @dev returns `(x * y) % 2 ^ 256`
*/
function _unsafeMul(uint256 x, uint256 y) private pure returns (uint256) {
unchecked {
return x * y;
}
}
/**
* @dev returns `x * y % (2 ^ 256 - 1)`
*/
function _mulModMax(uint256 x, uint256 y) private pure returns (uint256) {
return mulmod(x, y, type(uint256).max);
}
/**
* @dev returns `x * y % z`
*/
function _mulMod(uint256 x, uint256 y, uint256 z) private pure returns (uint256) {
return mulmod(x, y, z);
}
}// 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 = 1;
// 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":"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":"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":"MinTargetAmountNotReached","type":"error"},{"inputs":[],"name":"MinTargetAmountTooHigh","type":"error"},{"inputs":[],"name":"Overflow","type":"error"},{"inputs":[],"name":"SourceAmountTooHigh","type":"error"},{"inputs":[],"name":"SourceTokenIsNotETH","type":"error"},{"inputs":[],"name":"TargetTokenIsETH","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","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_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":[{"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
6101e06040523480156200001257600080fd5b50604051620061893803806200618983398101604081905262000035916200021e565b826200004181620001cb565b826200004d81620001cb565b82516200005a81620001cb565b60208401516200006a81620001cb565b60408501516200007a81620001cb565b60608601516200008a81620001cb565b60808701516200009a81620001cb565b60a0880151620000aa81620001cb565b60c0890151620000ba81620001cb565b60e08a0151620000ca81620001cb565b8c6001600160a01b03166080816001600160a01b0316815250508a604001516001600160a01b031663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000127573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200014d919062000345565b6001600160a01b0390811660a09081529c81166101c0528b51811660c090815260208d0151821660e090815260408e015183166101005260608e015183166101205260808e01518316610140529d8d01518216610160528c01518116610180529b909a0151909a166101a052506200036c9950505050505050505050565b6001600160a01b038116620001f35760405163e6c4247b60e01b815260040160405180910390fd5b50565b6001600160a01b0381168114620001f357600080fd5b80516200021981620001f6565b919050565b60008060008385036101408112156200023657600080fd5b84516200024381620001f6565b60208601519094506200025681620001f6565b9250610100603f1982018113156200026d57600080fd5b60405191508082016001600160401b03811183821017156200029f57634e487b7160e01b600052604160045260246000fd5b8060405250620002b2604087016200020c565b8252620002c2606087016200020c565b6020830152620002d5608087016200020c565b6040830152620002e860a087016200020c565b6060830152620002fb60c087016200020c565b60808301526200030e60e087016200020c565b60a0830152620003208187016200020c565b60c0830152506200033561012086016200020c565b60e0820152809150509250925092565b6000602082840312156200035857600080fd5b81516200036581620001f6565b9392505050565b60805160a05160c05160e05161010051610120516101405161016051610180516101a0516101c051615d0a6200047f6000396000818161177f0152818161339001526138850152600081816136e701526137f2015260008181610e530152818161138a01526133de01526000818161325d01526132cd015260006129ed01526000612df201526000612a130152600081816105c80152818161129a01528181611b2a0152818161289401526129470152600081816126bf01526127c5015260008181612a8f01528181612bf801528181612e4701528181612e9701528181612ebb01528181612ef4015281816130ac015261311101526000818161170e015281816117460152611ab90152615d0a6000f3fe6080604052600436106101b05760003560e01c806383428014116100ec578063a217fddf1161008a578063d0d479ff11610064578063d0d479ff146104f9578063d547741f1461050c578063f04f27071461052c578063fb1e68761461054c57600080fd5b8063a217fddf146104af578063a2195341146104c4578063ca15c873146104d957600080fd5b806391d14854116100c657806391d14854146103c357806393867fb51461040957806396bfaa9e1461043c5780639ec5a8941461045c57600080fd5b806383428014146103565780638cd2403d1461036b5780639010d07c1461038b57600080fd5b80632f2ff15d11610159578063493b7e4411610133578063493b7e441461030357806354fd4d501461031857806378c882291461032c5780638129fc1c1461034157600080fd5b80632f2ff15d146102ae57806336568abe146102ce57806345c99080146102ee57600080fd5b8063248a9ca31161018a578063248a9ca31461023b578063269c20e1146102795780632e540b101461028e57600080fd5b806301ffc9a7146101bc57806314d5c1a6146101f157806323e30c8b1461021957600080fd5b366101b757005b600080fd5b3480156101c857600080fd5b506101dc6101d7366004614730565b610561565b60405190151581526020015b60405180910390f35b3480156101fd57600080fd5b50610206600181565b60405161ffff90911681526020016101e8565b34801561022557600080fd5b506102396102343660046148e5565b6105bd565b005b34801561024757600080fd5b5061026b61025636600461495b565b60009081526097602052604090206001015490565b6040519081526020016101e8565b34801561028557600080fd5b50610206600481565b34801561029a57600080fd5b506102396102a9366004614bb2565b610664565b3480156102ba57600080fd5b506102396102c9366004614cf4565b610891565b3480156102da57600080fd5b506102396102e9366004614cf4565b6108bb565b3480156102fa57600080fd5b50610206600581565b34801561030f57600080fd5b50610206600381565b34801561032457600080fd5b506007610206565b34801561033857600080fd5b50610206600781565b34801561034d57600080fd5b50610239610962565b34801561036257600080fd5b50610206600281565b34801561037757600080fd5b50610239610386366004614d24565b610af4565b34801561039757600080fd5b506103ab6103a6366004614d96565b610b7c565b6040516001600160a01b0390911681526020016101e8565b3480156103cf57600080fd5b506101dc6103de366004614cf4565b60009182526097602090815260408084206001600160a01b0393909316845291905290205460ff1690565b34801561041557600080fd5b507f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca02509661026b565b34801561044857600080fd5b50610239610457366004614db8565b610b9b565b34801561046857600080fd5b5060408051808201825260008082526020918201528151808301835261012d5463ffffffff1680825261012e549183019182528351908152905191810191909152016101e8565b3480156104bb57600080fd5b5061026b600081565b3480156104d057600080fd5b50610206600881565b3480156104e557600080fd5b5061026b6104f436600461495b565b610cab565b610239610507366004614dd0565b610cc2565b34801561051857600080fd5b50610239610527366004614cf4565b610e23565b34801561053857600080fd5b50610239610547366004614e5c565b610e48565b34801561055857600080fd5b50610206600681565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f5a05180f0000000000000000000000000000000000000000000000000000000014806105b757506105b782610f3b565b92915050565b336001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161415806105fe57506001600160a01b0385163014155b15610635576040517fe17c49b700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61063e81610fd2565b61065d3361064c8486614f38565b6001600160a01b038716919061102f565b5050505050565b61066c6110aa565b80516106778161111d565b8280516000036106b3576040517f4a7aa2a800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60005b81518110156108305760008282815181106106d3576106d3614f4b565b6020026020010151905080602001515160000361071c576040517f4a7aa2a800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8060400151518160200151511461075f576040517f4a7aa2a800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b805161ffff16600214801561077957506001816020015151115b156107b0576040517f4a7aa2a800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b604081015160005b815181101561081c578181815181106107d3576107d3614f4b565b6020026020010151600003610814576040517f7c946ed700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001016107b8565b5050506108298160010190565b90506106b6565b50600061083d8585611163565b90506108638560008151811061085557610855614f4b565b60200260200101518261126c565b60008061086f8761141a565b9150915061087f82828833611602565b505050505061088d60018055565b5050565b6000828152609760205260409020600101546108ac8161187e565b6108b68383611888565b505050565b6001600160a01b0381163314610958576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b61088d82826118aa565b600054610100900460ff16158080156109825750600054600160ff909116105b8061099c5750303b15801561099c575060005460ff166001145b610a28576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a6564000000000000000000000000000000000000606482015260840161094f565b600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790558015610a8657600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff166101001790555b610a8e6118cc565b8015610af157600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b50565b60fb54600090610b099061ffff166001614f7a565b905061ffff8116600714610b49576040517f0dc149f000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60fb80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00001661ffff8316179055505050565b600082815260c960205260408120610b94908361197d565b9392505050565b610bc57f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca02509633611989565b610bd26020820182614fa7565b610bdb816119e5565b8160200135610be981611a28565b61012d5461012e5463ffffffff90911690610c076020860186614fa7565b63ffffffff168263ffffffff16148015610c245750846020013581145b15610c30575050505050565b8461012d610c3e8282614fc4565b507f707740459746824d259c9a0c2bfabcb04306f48ffc0c1c9c1404e990bf67d217905082610c706020880188614fa7565b6040805163ffffffff938416815292909116602083810191909152908201849052870135606082015260800160405180910390a15050505050565b600081815260c9602052604081206105b790611a62565b610cca6110aa565b82610cd48161111d565b81610cde81611a28565b610d28848787610cef60018261500c565b818110610cfe57610cfe614f4b565b9050602002810190610d10919061501f565b610d2190606081019060400161505d565b8534611a6c565b610d3d6001600160a01b038516333086611c73565b610d4f610d4a868861507a565b611cb5565b610d636001600160a01b0385163385611d78565b6040805160018082528183019092526000916020808301908036833750506040805160018082528183019092529293506000929150602080830190803683370190505090508582600081518110610dbc57610dbc614f4b565b60200260200101906001600160a01b031690816001600160a01b0316815250508481600081518110610df057610df0614f4b565b6020908102919091010152610e108282610e0a8a8c61507a565b33611602565b50505050610e1d60018055565b50505050565b600082815260976020526040902060010154610e3e8161187e565b6108b683836118aa565b336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614610eaa576040517fe17c49b700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610eb381610fd2565b60005b845181101561065d57610f3333848381518110610ed557610ed5614f4b565b6020026020010151868481518110610eef57610eef614f4b565b6020026020010151610f019190614f38565b878481518110610f1357610f13614f4b565b60200260200101516001600160a01b031661102f9092919063ffffffff16565b600101610eb6565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b0000000000000000000000000000000000000000000000000000000014806105b757507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316146105b7565b60008082806020019051810190610fe99190615292565b915091508151600003610fff576108b681611cb5565b6110098282611163565b92506108b68260008151811061102157611021614f4b565b60200260200101518461126c565b8060000361103c57505050565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03841603611096576040516001600160a01b0383169082156108fc029083906000818181858888f19350505050158015610e1d573d6000803e3d6000fd5b6108b66001600160a01b0384168383611dbc565b600260015403611116576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640161094f565b6002600155565b600281108061112c5750600a81115b15610af1576040517f76987d0e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6060600060018451611175919061500c565b67ffffffffffffffff81111561118d5761118d614797565b6040519080825280602002602001820160405280156111e657816020015b6111d36040518060600160405280600061ffff16815260200160608152602001606081525090565b8152602001906001900390816111ab5790505b50905060005b81518110156112405784600182018151811061120a5761120a614f4b565b602002602001015182828151811061122457611224614f4b565b60200260200101819052506112398160010190565b90506111ec565b50808360405160200161125492919061555e565b60405160208183030381529060405291505092915050565b815161ffff167ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0161135c577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663adf51de183602001516000815181106112de576112de614f4b565b602002602001015184604001516000815181106112fd576112fd614f4b565b602002602001015130856040518563ffffffff1660e01b81526004016113269493929190615656565b600060405180830381600087803b15801561134057600080fd5b505af1158015611354573d6000803e3d6000fd5b505050505050565b815161ffff167ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9016113e8577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316635c38449e306113c3856020015190565b8560400151856040518563ffffffff1660e01b81526004016113269493929190615692565b6040517f0d82421600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6060806000805b845181101561145e5784818151811061143c5761143c614f4b565b60200260200101516020015151826114549190614f38565b9150600101611421565b5060008167ffffffffffffffff81111561147a5761147a614797565b6040519080825280602002602001820160405280156114a3578160200160208202803683370190505b50905060008267ffffffffffffffff8111156114c1576114c1614797565b6040519080825280602002602001820160405280156114ea578160200160208202803683370190505b5090506000805b87518110156115f55760005b88828151811061150f5761150f614f4b565b602002602001015160200151518110156115ec5788828151811061153557611535614f4b565b602002602001015160200151818151811061155257611552614f4b565b602002602001015185848151811061156c5761156c614f4b565b60200260200101906001600160a01b031690816001600160a01b03168152505088828151811061159e5761159e614f4b565b60200260200101516040015181815181106115bb576115bb614f4b565b60200260200101518484815181106115d5576115d5614f4b565b6020908102919091010152600192830192016114fd565b506001016114f1565b5091969095509350505050565b835160008167ffffffffffffffff81111561161f5761161f614797565b604051908082528060200260200182016040528015611648578160200160208202803683370190505b50905060008267ffffffffffffffff81111561166657611666614797565b60405190808252806020026020018201604052801561168f578160200160208202803683370190505b50905060005b838110156118115760008882815181106116b1576116b1614f4b565b6020026020010151905060006116d930836001600160a01b0316611e6590919063ffffffff16565b61012d549091506000906116f890839063ffffffff16620f4240611f22565b90508082038282146117a4576001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116908516036117705761176b6001600160a01b0385167f00000000000000000000000000000000000000000000000000000000000000008361102f565b6117a4565b6117a46001600160a01b0385167f000000000000000000000000000000000000000000000000000000000000000083611d78565b81156117be576117be6001600160a01b0385168a84611d78565b818686815181106117d1576117d1614f4b565b602002602001018181525050808786815181106117f0576117f0614f4b565b6020026020010181815250505050505061180a8160010190565b9050611695565b5060008061181e87612016565b91509150856001600160a01b03167f5d6ce85adcad908fcf78bd40c0eb5b27bd4e0759ba3f1603df6aa38fc8b2efb583838c8c898960405161186596959493929190615743565b60405180910390a2505050505050505050565b60018055565b610af181336121cb565b611892828261225a565b600082815260c9602052604090206108b6908261231a565b6118b4828261232f565b600082815260c9602052604090206108b690826123d0565b600054610100900460ff16611963576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e67000000000000000000000000000000000000000000606482015260840161094f565b61196b6123e5565b611973612484565b61197b61252b565b565b6000610b948383612617565b60008281526097602090815260408083206001600160a01b038516845290915290205460ff1661088d576040517f4ca8886700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b620f424063ffffffff82161115610af1576040517f58d620b300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80600003610af1576040517f7c946ed700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006105b7825490565b836001600160a01b0316836001600160a01b031614611ab7576040517ffa48e42300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0390811690851614158015611ba257506040517f9bca0e700000000000000000000000000000000000000000000000000000000081526001600160a01b0385811660048301526000917f000000000000000000000000000000000000000000000000000000000000000090911690639bca0e7090602401602060405180830381865afa158015611b73573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b9791906157e5565b6001600160a01b0316145b15611bd9576040517f2889ee7500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03851603611c3b57818114611c36576040517f74ebc29c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610e1d565b8015610e1d576040517f74ebc29c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b801580611c9c575073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038516145b610e1d57610e1d6001600160a01b038516848484612641565b60005b815181101561088d576000828281518110611cd557611cd5614f4b565b602002602001015190506000611d013083602001516001600160a01b0316611e6590919063ffffffff16565b90506000826060015160001480611d1b5750818360600151115b15611d27575080611d2e565b5060608201515b611d64836000015161ffff16846020015185604001518487608001518860a001518960c001518a60e001518b6101000151612692565b505050611d718160010190565b9050611cb8565b80600003611d8557505050565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03841603611096576108b66001600160a01b038316826138e7565b6040516001600160a01b0383166024820152604481018290526108b69084907fa9059cbb00000000000000000000000000000000000000000000000000000000906064015b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152613a34565b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03841603611e9c57506001600160a01b038116316105b7565b826040517f70a082310000000000000000000000000000000000000000000000000000000081526001600160a01b03848116600483015291909116906370a0823190602401602060405180830381865afa158015611efe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b949190615802565b6000806000611f318686613b36565b9150915081600003611f5657838181611f4c57611f4c61581b565b0492505050610b94565b838210611f8f576040517f35278d1200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000611f9c878787613b71565b9050600080611fac858585613b8c565b9150915081600003611fd457868181611fc757611fc761581b565b0495505050505050610b94565b6000878103881690611fe7848484613bbc565b90506000612003838b81611ffd57611ffd61581b565b04613bf9565b919091029b9a5050505050505050505050565b606080825167ffffffffffffffff81111561203357612033614797565b60405190808252806020026020018201604052801561205c578160200160208202803683370190505b5091508251600261206d919061584a565b67ffffffffffffffff81111561208557612085614797565b6040519080825280602002602001820160405280156120ae578160200160208202803683370190505b50905060005b83518110156121c5578381815181106120cf576120cf614f4b565b6020026020010151600001518382815181106120ed576120ed614f4b565b602002602001019061ffff16908161ffff168152505083818151811061211557612115614f4b565b6020026020010151602001518282600261212f919061584a565b8151811061213f5761213f614f4b565b60200260200101906001600160a01b031690816001600160a01b03168152505083818151811061217157612171614f4b565b6020026020010151604001518261219483600261218e919061584a565b60010190565b815181106121a4576121a4614f4b565b6001600160a01b0392909216602092830291909101909101526001016120b4565b50915091565b60008281526097602090815260408083206001600160a01b038516845290915290205460ff1661088d576121fe81613c21565b612209836020613c33565b60405160200161221a929190615861565b60408051601f19818403018152908290527f08c379a000000000000000000000000000000000000000000000000000000000825261094f916004016158e2565b60008281526097602090815260408083206001600160a01b038516845290915290205460ff1661088d5760008281526097602090815260408083206001600160a01b0385168452909152902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790556122d63390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000610b94836001600160a01b038416613e76565b60008281526097602090815260408083206001600160a01b038516845290915290205460ff161561088d5760008281526097602090815260408083206001600160a01b038516808552925280832080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000610b94836001600160a01b038416613ec5565b600054610100900460ff1661247c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e67000000000000000000000000000000000000000000606482015260840161094f565b61197b613fb8565b600054610100900460ff1661251b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e67000000000000000000000000000000000000000000606482015260840161094f565b61252361404f565b61197b6140e6565b600054610100900460ff166125c2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e67000000000000000000000000000000000000000000606482015260840161094f565b60408051808201909152620186a080825268056bc75e2d63100000602090920182905261012d80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000016909117905561012e55565b600082600001828154811061262e5761262e614f4b565b9060005260206000200154905092915050565b6040516001600160a01b0380851660248301528316604482015260648101829052610e1d9085907f23b872dd0000000000000000000000000000000000000000000000000000000090608401611e01565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8901612867576126e4887f0000000000000000000000000000000000000000000000000000000000000000886141fc565b6040805160038082526080820190925260009160208201606080368337019050509050888160008151811061271b5761271b614f4b565b60200260200101906001600160a01b031690816001600160a01b031681525050838160018151811061274f5761274f614f4b565b60200260200101906001600160a01b031690816001600160a01b031681525050878160028151811061278357612783614f4b565b6001600160a01b0392831660209182029290920101526000908a1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee146127bf5760006127c1565b875b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663b77d239b82848b8b60008060006040518863ffffffff1660e01b815260040161281c969594939291906158f5565b60206040518083038185885af115801561283a573d6000803e3d6000fd5b50505050506040513d601f19601f8201168201806040525081019061285f9190615802565b5050506138dc565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe89016129bf576128b9887f0000000000000000000000000000000000000000000000000000000000000000886141fc565b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038a16146128e65760006128e8565b865b6040517fd895feee0000000000000000000000000000000000000000000000000000000081526001600160a01b038b811660048301528a81166024830152604482018a90526064820189905260848201889052600060a48301529192507f00000000000000000000000000000000000000000000000000000000000000009091169063d895feee90839060c40160206040518083038185885af1158015612993573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906129b89190615802565b50506138dc565b60038914806129ce5750600589145b15612db85760006001600160a01b038416612a3a5760038a14612a11577f0000000000000000000000000000000000000000000000000000000000000000612a33565b7f00000000000000000000000000000000000000000000000000000000000000005b9050612a3d565b50825b612a488982896141fc565b60408051600280825260608201835260009260208301908036833701905050905073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038b1603612b9e577f000000000000000000000000000000000000000000000000000000000000000081600081518110612ac157612ac1614f4b565b60200260200101906001600160a01b031690816001600160a01b0316815250508881600181518110612af557612af5614f4b565b6001600160a01b0392831660209182029290920101526040517f7ff36ab500000000000000000000000000000000000000000000000000000000815290831690637ff36ab5908a90612b51908b90869030908d9060040161593b565b60006040518083038185885af1158015612b6f573d6000803e3d6000fd5b50505050506040513d6000823e601f3d908101601f19168201604052612b989190810190615970565b506129b8565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038a1603612ccd578981600081518110612bd657612bd6614f4b565b60200260200101906001600160a01b031690816001600160a01b0316815250507f000000000000000000000000000000000000000000000000000000000000000081600181518110612c2a57612c2a614f4b565b6001600160a01b0392831660209182029290920101526040517f18cbafe5000000000000000000000000000000000000000000000000000000008152908316906318cbafe590612c86908b908b90869030908d906004016159a5565b6000604051808303816000875af1158015612ca5573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612b989190810190615970565b8981600081518110612ce157612ce1614f4b565b60200260200101906001600160a01b031690816001600160a01b0316815250508881600181518110612d1557612d15614f4b565b6001600160a01b0392831660209182029290920101526040517f38ed1739000000000000000000000000000000000000000000000000000000008152908316906338ed173990612d71908b908b90869030908d906004016159a5565b6000604051808303816000875af1158015612d90573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261285f9190810190615970565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc89016131e65760006001600160a01b038416612e1657507f0000000000000000000000000000000000000000000000000000000000000000612e19565b50825b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038b1614612e455789612e67565b7f00000000000000000000000000000000000000000000000000000000000000005b9050600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038b1614612e955789612eb7565b7f00000000000000000000000000000000000000000000000000000000000000005b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b031603612f67577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db08a6040518263ffffffff1660e01b81526004016000604051808303818588803b158015612f4d57600080fd5b505af1158015612f61573d6000803e3d6000fd5b50505050505b612f7282848b6141fc565b60408051610100810182526001600160a01b038085168252838116602083015262ffffff881682840152306060830152608082018a905260a082018c905260c082018b9052600060e083015291517f414bf389000000000000000000000000000000000000000000000000000000008152909185169063414bf389906130669084906004016000610100820190506001600160a01b0380845116835280602085015116602084015262ffffff60408501511660408401528060608501511660608401526080840151608084015260a084015160a084015260c084015160c08401528060e08501511660e08401525092915050565b6020604051808303816000875af1158015613085573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130a99190615802565b507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b0316036131dd576040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690632e1a7d4d9082906370a0823190602401602060405180830381865afa158015613168573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061318c9190615802565b6040518263ffffffff1660e01b81526004016131aa91815260200190565b600060405180830381600087803b1580156131c457600080fd5b505af11580156131d8573d6000803e3d6000fd5b505050505b505050506138dc565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa89016133b5576fffffffffffffffffffffffffffffffff851115613257576040517f7d5ee39100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b613282887f0000000000000000000000000000000000000000000000000000000000000000886141fc565b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038a16146132af5760006132b1565b865b90506000828060200190518101906132c99190615a01565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663f1c5e014838c8c858b8d6040518763ffffffff1660e01b8152600401613320959493929190615ab4565b60206040518083038185885af115801561333e573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906133639190615b51565b5060006133796001600160a01b038c1630611e65565b9050801561285f5761285f6001600160a01b038c167f000000000000000000000000000000000000000000000000000000000000000083611d78565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff98901613577577f00000000000000000000000000000000000000000000000000000000000000006134088982896141fc565b6040805160c0810182528481526000602082018190529181016001600160a01b038c1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1461344b578b61344e565b60005b6001600160a01b0316815260200161348b8b6001600160a01b03166001600160a01b031673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1490565b613495578a613498565b60005b6001600160a01b03908116825260208083018c905260408051808301825260008082529482015280516080810182523080825292810185905280820192909252606082018490528401519394509216156134f35760006134f5565b895b9050836001600160a01b03166352bbbe298285858d8d6040518663ffffffff1660e01b815260040161352a9493929190615b6c565b60206040518083038185885af1158015613548573d6000803e3d6000fd5b50505050506040513d601f19601f8201168201806040525081019061356d9190615802565b50505050506138dc565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff889016138aa576fffffffffffffffffffffffffffffffff8611156135e8576040517fcd0ac5e600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b0389161461363e576040517f8a39b80100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03881603613694576040517f7a9404b000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f824316880000000000000000000000000000000000000000000000000000000081526001600160a01b0388811660048301526fffffffffffffffffffffffffffffffff881660248301526000917f000000000000000000000000000000000000000000000000000000000000000090911690638243168890604401602060405180830381865afa158015613730573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137549190615b51565b905085816fffffffffffffffffffffffffffffffff1610156137a2576040517fb34424fd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f4747919d0000000000000000000000000000000000000000000000000000000081526001600160a01b0389811660048301526fffffffffffffffffffffffffffffffff831660248301527f00000000000000000000000000000000000000000000000000000000000000001690634747919d9089906044016000604051808303818588803b15801561383757600080fd5b505af115801561384b573d6000803e3d6000fd5b5050505050600061386e308b6001600160a01b0316611e6590919063ffffffff16565b905080156129b8576129b86001600160a01b038b167f000000000000000000000000000000000000000000000000000000000000000083611d78565b6040517f8260f36600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505050505050505050565b80471015613951576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e6365000000604482015260640161094f565b6000826001600160a01b03168260405160006040518083038185875af1925050503d806000811461399e576040519150601f19603f3d011682016040523d82523d6000602084013e6139a3565b606091505b50509050806108b6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d61792068617665207265766572746564000000000000606482015260840161094f565b6000613a89826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166142fa9092919063ffffffff16565b9050805160001480613aaa575080806020019051810190613aaa9190615c65565b6108b6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f74207375636365656400000000000000000000000000000000000000000000606482015260840161094f565b6000806000613b458585614311565b9050848402808210613b5e579081900392509050613b6a565b60018183030393509150505b9250929050565b60008180613b8157613b8161581b565b838509949350505050565b600080828410613ba25750839050818303613bb4565b613bad60018661500c565b9150508183035b935093915050565b600080613bda8380830381613bd357613bd361581b565b0460010190565b9050828481613beb57613beb61581b565b048186021795945050505050565b60006001815b6008811015613c1a5783820260020382029150600101613bff565b5092915050565b60606105b76001600160a01b03831660145b60606000613c4283600261584a565b613c4d906002614f38565b67ffffffffffffffff811115613c6557613c65614797565b6040519080825280601f01601f191660200182016040528015613c8f576020820181803683370190505b5090507f300000000000000000000000000000000000000000000000000000000000000081600081518110613cc657613cc6614f4b565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110613d2957613d29614f4b565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053506000613d6584600261584a565b613d70906001614f38565b90505b6001811115613e0d577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110613db157613db1614f4b565b1a60f81b828281518110613dc757613dc7614f4b565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535060049490941c93613e0681615c87565b9050613d73565b508315610b94576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161094f565b6000818152600183016020526040812054613ebd575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556105b7565b5060006105b7565b60008181526001830160205260408120548015613fae576000613ee960018361500c565b8554909150600090613efd9060019061500c565b9050818114613f62576000866000018281548110613f1d57613f1d614f4b565b9060005260206000200154905080876000018481548110613f4057613f40614f4b565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080613f7357613f73615cbc565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506105b7565b60009150506105b7565b600054610100900460ff16611878576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e67000000000000000000000000000000000000000000606482015260840161094f565b600054610100900460ff1661197b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e67000000000000000000000000000000000000000000606482015260840161094f565b600054610100900460ff1661417d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e67000000000000000000000000000000000000000000606482015260840161094f565b60fb80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00001660011790556141d27f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca0250968061433e565b61197b7f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca02509633614389565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b0384160361422557505050565b60006001600160a01b0384166040517fdd62ed3e0000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038581166024830152919091169063dd62ed3e90604401602060405180830381865afa158015614298573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142bc9190615802565b905081811015610e1d57610e1d6001600160a01b038516847fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff614393565b606061430984846000856143d0565b949350505050565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8284099392505050565b600082815260976020526040808220600101805490849055905190918391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b61088d8282611888565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038416036143bc57505050565b6108b66001600160a01b03841683836144dc565b606082471015614462576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c0000000000000000000000000000000000000000000000000000606482015260840161094f565b600080866001600160a01b0316858760405161447e9190615ceb565b60006040518083038185875af1925050503d80600081146144bb576040519150601f19603f3d011682016040523d82523d6000602084013e6144c0565b606091505b50915091506144d1878383876145b2565b979650505050505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f095ea7b30000000000000000000000000000000000000000000000000000000017905261455b8482614645565b610e1d576040516001600160a01b0384166024820152600060448201526145a89085907f095ea7b30000000000000000000000000000000000000000000000000000000090606401611e01565b610e1d8482613a34565b6060831561463b578251600003614634576001600160a01b0385163b614634576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161094f565b5081614309565b61430983836146ec565b6000806000846001600160a01b0316846040516146629190615ceb565b6000604051808303816000865af19150503d806000811461469f576040519150601f19603f3d011682016040523d82523d6000602084013e6146a4565b606091505b50915091508180156146ce5750805115806146ce5750808060200190518101906146ce9190615c65565b80156146e357506001600160a01b0385163b15155b95945050505050565b8151156146fc5781518083602001fd5b806040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161094f91906158e2565b60006020828403121561474257600080fd5b81357fffffffff0000000000000000000000000000000000000000000000000000000081168114610b9457600080fd5b6001600160a01b0381168114610af157600080fd5b803561479281614772565b919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b604051610120810167ffffffffffffffff811182821017156147ea576147ea614797565b60405290565b6040516060810167ffffffffffffffff811182821017156147ea576147ea614797565b6040805190810167ffffffffffffffff811182821017156147ea576147ea614797565b604051601f8201601f1916810167ffffffffffffffff8111828210171561485f5761485f614797565b604052919050565b600067ffffffffffffffff82111561488157614881614797565b50601f01601f191660200190565b600082601f8301126148a057600080fd5b81356148b36148ae82614867565b614836565b8181528460208386010111156148c857600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080600060a086880312156148fd57600080fd5b853561490881614772565b9450602086013561491881614772565b93506040860135925060608601359150608086013567ffffffffffffffff81111561494257600080fd5b61494e8882890161488f565b9150509295509295909350565b60006020828403121561496d57600080fd5b5035919050565b600067ffffffffffffffff82111561498e5761498e614797565b5060051b60200190565b61ffff81168114610af157600080fd5b803561479281614998565b600082601f8301126149c457600080fd5b813560206149d46148ae83614974565b82815260059290921b840181019181810190868411156149f357600080fd5b8286015b84811015614a17578035614a0a81614772565b83529183019183016149f7565b509695505050505050565b600082601f830112614a3357600080fd5b81356020614a436148ae83614974565b82815260059290921b84018101918181019086841115614a6257600080fd5b8286015b84811015614a175780358352918301918301614a66565b6000614a8b6148ae84614974565b8381529050602080820190600585901b840186811115614aaa57600080fd5b845b81811015614b8757803567ffffffffffffffff80821115614acd5760008081fd5b90870190610120828b031215614ae35760008081fd5b614aeb6147c6565b614af4836149a8565b8152614b01868401614787565b868201526040614b12818501614787565b90820152606083810135908201526080808401359082015260a0808401359082015260c0614b41818501614787565b9082015260e083810135908201526101008084013583811115614b645760008081fd5b614b708d82870161488f565b918301919091525086525050928201928201614aac565b505050509392505050565b600082601f830112614ba357600080fd5b610b9483833560208501614a7d565b60008060408385031215614bc557600080fd5b823567ffffffffffffffff80821115614bdd57600080fd5b818501915085601f830112614bf157600080fd5b81356020614c016148ae83614974565b82815260059290921b84018101918181019089841115614c2057600080fd5b8286015b84811015614cc657803586811115614c3c5760008081fd5b87016060818d03601f1901811315614c545760008081fd5b614c5c6147f0565b86830135614c6981614998565b8152604083013589811115614c7e5760008081fd5b614c8c8f89838701016149b3565b8289015250908201359088821115614ca45760008081fd5b614cb28e8884860101614a22565b604082015285525050918301918301614c24565b5096505086013592505080821115614cdd57600080fd5b50614cea85828601614b92565b9150509250929050565b60008060408385031215614d0757600080fd5b823591506020830135614d1981614772565b809150509250929050565b60008060208385031215614d3757600080fd5b823567ffffffffffffffff80821115614d4f57600080fd5b818501915085601f830112614d6357600080fd5b813581811115614d7257600080fd5b866020828501011115614d8457600080fd5b60209290920196919550909350505050565b60008060408385031215614da957600080fd5b50508035926020909101359150565b600060408284031215614dca57600080fd5b50919050565b60008060008060608587031215614de657600080fd5b843567ffffffffffffffff80821115614dfe57600080fd5b818701915087601f830112614e1257600080fd5b813581811115614e2157600080fd5b8860208260051b8501011115614e3657600080fd5b60209283019650945050850135614e4c81614772565b9396929550929360400135925050565b60008060008060808587031215614e7257600080fd5b843567ffffffffffffffff80821115614e8a57600080fd5b614e96888389016149b3565b95506020870135915080821115614eac57600080fd5b614eb888838901614a22565b94506040870135915080821115614ece57600080fd5b614eda88838901614a22565b93506060870135915080821115614ef057600080fd5b50614efd8782880161488f565b91505092959194509250565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b808201808211156105b7576105b7614f09565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b61ffff818116838216019080821115613c1a57613c1a614f09565b63ffffffff81168114610af157600080fd5b600060208284031215614fb957600080fd5b8135610b9481614f95565b8135614fcf81614f95565b63ffffffff81167fffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000083541617825550602082013560018201555050565b818103818111156105b7576105b7614f09565b600082357ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffee183360301811261505357600080fd5b9190910192915050565b60006020828403121561506f57600080fd5b8135610b9481614772565b6000610b94368484614a7d565b805161479281614998565b600082601f8301126150a357600080fd5b815160206150b36148ae83614974565b82815260059290921b840181019181810190868411156150d257600080fd5b8286015b84811015614a1757805183529183019183016150d6565b805161479281614772565b60005b838110156151135781810151838201526020016150fb565b50506000910152565b600082601f83011261512d57600080fd5b815161513b6148ae82614867565b81815284602083860101111561515057600080fd5b6143098260208301602087016150f8565b600082601f83011261517257600080fd5b815160206151826148ae83614974565b82815260059290921b840181019181810190868411156151a157600080fd5b8286015b84811015614a1757805167ffffffffffffffff808211156151c65760008081fd5b818901915061012080601f19848d030112156151e25760008081fd5b6151ea6147c6565b6151f5888501615087565b815260406152048186016150ed565b8983015260606152158187016150ed565b828401526080915081860151818401525060a0808601518284015260c0915081860151818401525060e061524a8187016150ed565b828401526101009150818601518184015250828501519250838311156152705760008081fd5b61527e8d8a8588010161511c565b9082015286525050509183019183016151a5565b600080604083850312156152a557600080fd5b825167ffffffffffffffff808211156152bd57600080fd5b818501915085601f8301126152d157600080fd5b81516152df6148ae82614974565b8082825260208201915060208360051b86010192508883111561530157600080fd5b602085015b838110156154095780518581111561531d57600080fd5b86016060818c03601f1901121561533357600080fd5b61533b6147f0565b602082015161534981614998565b815260408201518781111561535d57600080fd5b8201603f81018d1361536e57600080fd5b602081015161537f6148ae82614974565b81815260059190911b82016040019060208101908f8311156153a057600080fd5b6040840193505b828410156153cb5783516153ba81614772565b8252602093840193909101906153a7565b60208501525050506060820151878111156153e557600080fd5b6153f48d602083860101615092565b60408301525084525060209283019201615306565b506020880151909650935050508082111561542357600080fd5b50614cea85828601615161565b600081518084526020808501945080840160005b8381101561546057815187529582019590820190600101615444565b509495945050505050565b600081518084526154838160208601602086016150f8565b601f01601f19169290920160200192915050565b600081518084526020808501808196508360051b8101915082860160005b858110156155515782840389528151805161ffff168552858101516001600160a01b0390811687870152604080830151821690870152606080830151908701526080808301519087015260a0808301519087015260c0808301519091169086015260e08082015190860152610100908101516101209186018290529061553d8187018361546b565b9a87019a95505050908401906001016154b5565b5091979650505050505050565b60006040808301818452808651808352606092508286019150828160051b8701016020808a016000805b85811015615635578a85037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa00187528251805161ffff168652848101518587018a905280518a880181905290860190849060808901905b808310156156085783516001600160a01b031682529288019260019290920191908801906155df565b50928c0151888403898e01529261561f8185615430565b9a88019a98505050938501935050600101615588565b505050878203908801526156498189615497565b9998505050505050505050565b60006001600160a01b03808716835285602084015280851660408401525060806060830152615688608083018461546b565b9695505050505050565b6000608082016001600160a01b038088168452602060808186015282885180855260a087019150828a01945060005b818110156156df5785518516835294830194918301916001016156c1565b505085810360408701526156f38189615430565b935050505082810360608401526144d1818561546b565b600081518084526020808501945080840160005b838110156154605781516001600160a01b03168752958201959082019060010161571e565b60c0808252875190820181905260009060209060e0840190828b01845b8281101561578057815161ffff1684529284019290840190600101615760565b50505083810382850152615794818a61570a565b91505082810360408401526157a9818861570a565b905082810360608401526157bd8187615430565b905082810360808401526157d18186615430565b905082810360a08401526156498185615430565b6000602082840312156157f757600080fd5b8151610b9481614772565b60006020828403121561581457600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b80820281158282048414176105b7576105b7614f09565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516158998160178501602088016150f8565b7f206973206d697373696e6720726f6c652000000000000000000000000000000060179184019182015283516158d68160288401602088016150f8565b01602801949350505050565b602081526000610b94602083018461546b565b60c08152600061590860c083018961570a565b60208301979097525060408101949094526001600160a01b0392831660608501529116608083015260a090910152919050565b848152608060208201526000615954608083018661570a565b6001600160a01b03949094166040830152506060015292915050565b60006020828403121561598257600080fd5b815167ffffffffffffffff81111561599957600080fd5b61430984828501615092565b85815284602082015260a0604082015260006159c460a083018661570a565b6001600160a01b0394909416606083015250608001529392505050565b80516fffffffffffffffffffffffffffffffff8116811461479257600080fd5b60006020808385031215615a1457600080fd5b825167ffffffffffffffff811115615a2b57600080fd5b8301601f81018513615a3c57600080fd5b8051615a4a6148ae82614974565b81815260069190911b82018301908381019087831115615a6957600080fd5b928401925b828410156144d15760408489031215615a875760008081fd5b615a8f614813565b84518152615a9e8686016159e1565b8187015282526040939093019290840190615a6e565b600060a082016001600160a01b0380891684526020818916818601526040915060a08286015282885180855260c087019150828a01945060005b81811015615b25578551805184528401516fffffffffffffffffffffffffffffffff16848401529483019491840191600101615aee565b5050606086018890526fffffffffffffffffffffffffffffffff87166080870152935061568892505050565b600060208284031215615b6357600080fd5b610b94826159e1565b60e08152845160e08201526000602086015160028110615bb5577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b61010083015260408601516001600160a01b03166101208301526060860151615bea6101408401826001600160a01b03169052565b50608086015161016083015260a086015160c0610180840152615c116101a084018261546b565b915050615c5360208301866001600160a01b03808251168352602082015115156020840152806040830151166040840152506060810151151560608301525050565b60a082019390935260c0015292915050565b600060208284031215615c7757600080fd5b81518015158114610b9457600080fd5b600081615c9657615c96614f09565b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603160045260246000fd5b600082516150538184602087016150f856fea164736f6c6343000813000a0000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c000000000000000000000000ba7d1581db6248dc9177466a328bf457703c8f840000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb0000000000000000000000000eef417e1d5cc832e619ae18d2f140de2999dd4fb0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f000000000000000000000000c537e898cd774e2dcba3b14ea6f34c93d5ea45e1000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c8000000000000000000000000d06146d292f9651c1d7cf54a3162791dfc2bef46
Deployed Bytecode
0x6080604052600436106101b05760003560e01c806383428014116100ec578063a217fddf1161008a578063d0d479ff11610064578063d0d479ff146104f9578063d547741f1461050c578063f04f27071461052c578063fb1e68761461054c57600080fd5b8063a217fddf146104af578063a2195341146104c4578063ca15c873146104d957600080fd5b806391d14854116100c657806391d14854146103c357806393867fb51461040957806396bfaa9e1461043c5780639ec5a8941461045c57600080fd5b806383428014146103565780638cd2403d1461036b5780639010d07c1461038b57600080fd5b80632f2ff15d11610159578063493b7e4411610133578063493b7e441461030357806354fd4d501461031857806378c882291461032c5780638129fc1c1461034157600080fd5b80632f2ff15d146102ae57806336568abe146102ce57806345c99080146102ee57600080fd5b8063248a9ca31161018a578063248a9ca31461023b578063269c20e1146102795780632e540b101461028e57600080fd5b806301ffc9a7146101bc57806314d5c1a6146101f157806323e30c8b1461021957600080fd5b366101b757005b600080fd5b3480156101c857600080fd5b506101dc6101d7366004614730565b610561565b60405190151581526020015b60405180910390f35b3480156101fd57600080fd5b50610206600181565b60405161ffff90911681526020016101e8565b34801561022557600080fd5b506102396102343660046148e5565b6105bd565b005b34801561024757600080fd5b5061026b61025636600461495b565b60009081526097602052604090206001015490565b6040519081526020016101e8565b34801561028557600080fd5b50610206600481565b34801561029a57600080fd5b506102396102a9366004614bb2565b610664565b3480156102ba57600080fd5b506102396102c9366004614cf4565b610891565b3480156102da57600080fd5b506102396102e9366004614cf4565b6108bb565b3480156102fa57600080fd5b50610206600581565b34801561030f57600080fd5b50610206600381565b34801561032457600080fd5b506007610206565b34801561033857600080fd5b50610206600781565b34801561034d57600080fd5b50610239610962565b34801561036257600080fd5b50610206600281565b34801561037757600080fd5b50610239610386366004614d24565b610af4565b34801561039757600080fd5b506103ab6103a6366004614d96565b610b7c565b6040516001600160a01b0390911681526020016101e8565b3480156103cf57600080fd5b506101dc6103de366004614cf4565b60009182526097602090815260408084206001600160a01b0393909316845291905290205460ff1690565b34801561041557600080fd5b507f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca02509661026b565b34801561044857600080fd5b50610239610457366004614db8565b610b9b565b34801561046857600080fd5b5060408051808201825260008082526020918201528151808301835261012d5463ffffffff1680825261012e549183019182528351908152905191810191909152016101e8565b3480156104bb57600080fd5b5061026b600081565b3480156104d057600080fd5b50610206600881565b3480156104e557600080fd5b5061026b6104f436600461495b565b610cab565b610239610507366004614dd0565b610cc2565b34801561051857600080fd5b50610239610527366004614cf4565b610e23565b34801561053857600080fd5b50610239610547366004614e5c565b610e48565b34801561055857600080fd5b50610206600681565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f5a05180f0000000000000000000000000000000000000000000000000000000014806105b757506105b782610f3b565b92915050565b336001600160a01b037f000000000000000000000000eef417e1d5cc832e619ae18d2f140de2999dd4fb161415806105fe57506001600160a01b0385163014155b15610635576040517fe17c49b700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61063e81610fd2565b61065d3361064c8486614f38565b6001600160a01b038716919061102f565b5050505050565b61066c6110aa565b80516106778161111d565b8280516000036106b3576040517f4a7aa2a800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60005b81518110156108305760008282815181106106d3576106d3614f4b565b6020026020010151905080602001515160000361071c576040517f4a7aa2a800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8060400151518160200151511461075f576040517f4a7aa2a800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b805161ffff16600214801561077957506001816020015151115b156107b0576040517f4a7aa2a800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b604081015160005b815181101561081c578181815181106107d3576107d3614f4b565b6020026020010151600003610814576040517f7c946ed700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001016107b8565b5050506108298160010190565b90506106b6565b50600061083d8585611163565b90506108638560008151811061085557610855614f4b565b60200260200101518261126c565b60008061086f8761141a565b9150915061087f82828833611602565b505050505061088d60018055565b5050565b6000828152609760205260409020600101546108ac8161187e565b6108b68383611888565b505050565b6001600160a01b0381163314610958576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b61088d82826118aa565b600054610100900460ff16158080156109825750600054600160ff909116105b8061099c5750303b15801561099c575060005460ff166001145b610a28576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a6564000000000000000000000000000000000000606482015260840161094f565b600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790558015610a8657600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff166101001790555b610a8e6118cc565b8015610af157600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b50565b60fb54600090610b099061ffff166001614f7a565b905061ffff8116600714610b49576040517f0dc149f000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60fb80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00001661ffff8316179055505050565b600082815260c960205260408120610b94908361197d565b9392505050565b610bc57f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca02509633611989565b610bd26020820182614fa7565b610bdb816119e5565b8160200135610be981611a28565b61012d5461012e5463ffffffff90911690610c076020860186614fa7565b63ffffffff168263ffffffff16148015610c245750846020013581145b15610c30575050505050565b8461012d610c3e8282614fc4565b507f707740459746824d259c9a0c2bfabcb04306f48ffc0c1c9c1404e990bf67d217905082610c706020880188614fa7565b6040805163ffffffff938416815292909116602083810191909152908201849052870135606082015260800160405180910390a15050505050565b600081815260c9602052604081206105b790611a62565b610cca6110aa565b82610cd48161111d565b81610cde81611a28565b610d28848787610cef60018261500c565b818110610cfe57610cfe614f4b565b9050602002810190610d10919061501f565b610d2190606081019060400161505d565b8534611a6c565b610d3d6001600160a01b038516333086611c73565b610d4f610d4a868861507a565b611cb5565b610d636001600160a01b0385163385611d78565b6040805160018082528183019092526000916020808301908036833750506040805160018082528183019092529293506000929150602080830190803683370190505090508582600081518110610dbc57610dbc614f4b565b60200260200101906001600160a01b031690816001600160a01b0316815250508481600081518110610df057610df0614f4b565b6020908102919091010152610e108282610e0a8a8c61507a565b33611602565b50505050610e1d60018055565b50505050565b600082815260976020526040902060010154610e3e8161187e565b6108b683836118aa565b336001600160a01b037f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c81614610eaa576040517fe17c49b700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610eb381610fd2565b60005b845181101561065d57610f3333848381518110610ed557610ed5614f4b565b6020026020010151868481518110610eef57610eef614f4b565b6020026020010151610f019190614f38565b878481518110610f1357610f13614f4b565b60200260200101516001600160a01b031661102f9092919063ffffffff16565b600101610eb6565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b0000000000000000000000000000000000000000000000000000000014806105b757507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316146105b7565b60008082806020019051810190610fe99190615292565b915091508151600003610fff576108b681611cb5565b6110098282611163565b92506108b68260008151811061102157611021614f4b565b60200260200101518461126c565b8060000361103c57505050565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03841603611096576040516001600160a01b0383169082156108fc029083906000818181858888f19350505050158015610e1d573d6000803e3d6000fd5b6108b66001600160a01b0384168383611dbc565b600260015403611116576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640161094f565b6002600155565b600281108061112c5750600a81115b15610af1576040517f76987d0e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6060600060018451611175919061500c565b67ffffffffffffffff81111561118d5761118d614797565b6040519080825280602002602001820160405280156111e657816020015b6111d36040518060600160405280600061ffff16815260200160608152602001606081525090565b8152602001906001900390816111ab5790505b50905060005b81518110156112405784600182018151811061120a5761120a614f4b565b602002602001015182828151811061122457611224614f4b565b60200260200101819052506112398160010190565b90506111ec565b50808360405160200161125492919061555e565b60405160208183030381529060405291505092915050565b815161ffff167ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0161135c577f000000000000000000000000eef417e1d5cc832e619ae18d2f140de2999dd4fb6001600160a01b031663adf51de183602001516000815181106112de576112de614f4b565b602002602001015184604001516000815181106112fd576112fd614f4b565b602002602001015130856040518563ffffffff1660e01b81526004016113269493929190615656565b600060405180830381600087803b15801561134057600080fd5b505af1158015611354573d6000803e3d6000fd5b505050505050565b815161ffff167ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9016113e8577f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c86001600160a01b0316635c38449e306113c3856020015190565b8560400151856040518563ffffffff1660e01b81526004016113269493929190615692565b6040517f0d82421600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6060806000805b845181101561145e5784818151811061143c5761143c614f4b565b60200260200101516020015151826114549190614f38565b9150600101611421565b5060008167ffffffffffffffff81111561147a5761147a614797565b6040519080825280602002602001820160405280156114a3578160200160208202803683370190505b50905060008267ffffffffffffffff8111156114c1576114c1614797565b6040519080825280602002602001820160405280156114ea578160200160208202803683370190505b5090506000805b87518110156115f55760005b88828151811061150f5761150f614f4b565b602002602001015160200151518110156115ec5788828151811061153557611535614f4b565b602002602001015160200151818151811061155257611552614f4b565b602002602001015185848151811061156c5761156c614f4b565b60200260200101906001600160a01b031690816001600160a01b03168152505088828151811061159e5761159e614f4b565b60200260200101516040015181815181106115bb576115bb614f4b565b60200260200101518484815181106115d5576115d5614f4b565b6020908102919091010152600192830192016114fd565b506001016114f1565b5091969095509350505050565b835160008167ffffffffffffffff81111561161f5761161f614797565b604051908082528060200260200182016040528015611648578160200160208202803683370190505b50905060008267ffffffffffffffff81111561166657611666614797565b60405190808252806020026020018201604052801561168f578160200160208202803683370190505b50905060005b838110156118115760008882815181106116b1576116b1614f4b565b6020026020010151905060006116d930836001600160a01b0316611e6590919063ffffffff16565b61012d549091506000906116f890839063ffffffff16620f4240611f22565b90508082038282146117a4576001600160a01b037f0000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c8116908516036117705761176b6001600160a01b0385167f0000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c8361102f565b6117a4565b6117a46001600160a01b0385167f000000000000000000000000ba7d1581db6248dc9177466a328bf457703c8f8483611d78565b81156117be576117be6001600160a01b0385168a84611d78565b818686815181106117d1576117d1614f4b565b602002602001018181525050808786815181106117f0576117f0614f4b565b6020026020010181815250505050505061180a8160010190565b9050611695565b5060008061181e87612016565b91509150856001600160a01b03167f5d6ce85adcad908fcf78bd40c0eb5b27bd4e0759ba3f1603df6aa38fc8b2efb583838c8c898960405161186596959493929190615743565b60405180910390a2505050505050505050565b60018055565b610af181336121cb565b611892828261225a565b600082815260c9602052604090206108b6908261231a565b6118b4828261232f565b600082815260c9602052604090206108b690826123d0565b600054610100900460ff16611963576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e67000000000000000000000000000000000000000000606482015260840161094f565b61196b6123e5565b611973612484565b61197b61252b565b565b6000610b948383612617565b60008281526097602090815260408083206001600160a01b038516845290915290205460ff1661088d576040517f4ca8886700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b620f424063ffffffff82161115610af1576040517f58d620b300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80600003610af1576040517f7c946ed700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006105b7825490565b836001600160a01b0316836001600160a01b031614611ab7576040517ffa48e42300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7f0000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c6001600160a01b0390811690851614158015611ba257506040517f9bca0e700000000000000000000000000000000000000000000000000000000081526001600160a01b0385811660048301526000917f000000000000000000000000eef417e1d5cc832e619ae18d2f140de2999dd4fb90911690639bca0e7090602401602060405180830381865afa158015611b73573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b9791906157e5565b6001600160a01b0316145b15611bd9576040517f2889ee7500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03851603611c3b57818114611c36576040517f74ebc29c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610e1d565b8015610e1d576040517f74ebc29c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b801580611c9c575073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038516145b610e1d57610e1d6001600160a01b038516848484612641565b60005b815181101561088d576000828281518110611cd557611cd5614f4b565b602002602001015190506000611d013083602001516001600160a01b0316611e6590919063ffffffff16565b90506000826060015160001480611d1b5750818360600151115b15611d27575080611d2e565b5060608201515b611d64836000015161ffff16846020015185604001518487608001518860a001518960c001518a60e001518b6101000151612692565b505050611d718160010190565b9050611cb8565b80600003611d8557505050565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03841603611096576108b66001600160a01b038316826138e7565b6040516001600160a01b0383166024820152604481018290526108b69084907fa9059cbb00000000000000000000000000000000000000000000000000000000906064015b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152613a34565b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03841603611e9c57506001600160a01b038116316105b7565b826040517f70a082310000000000000000000000000000000000000000000000000000000081526001600160a01b03848116600483015291909116906370a0823190602401602060405180830381865afa158015611efe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b949190615802565b6000806000611f318686613b36565b9150915081600003611f5657838181611f4c57611f4c61581b565b0492505050610b94565b838210611f8f576040517f35278d1200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000611f9c878787613b71565b9050600080611fac858585613b8c565b9150915081600003611fd457868181611fc757611fc761581b565b0495505050505050610b94565b6000878103881690611fe7848484613bbc565b90506000612003838b81611ffd57611ffd61581b565b04613bf9565b919091029b9a5050505050505050505050565b606080825167ffffffffffffffff81111561203357612033614797565b60405190808252806020026020018201604052801561205c578160200160208202803683370190505b5091508251600261206d919061584a565b67ffffffffffffffff81111561208557612085614797565b6040519080825280602002602001820160405280156120ae578160200160208202803683370190505b50905060005b83518110156121c5578381815181106120cf576120cf614f4b565b6020026020010151600001518382815181106120ed576120ed614f4b565b602002602001019061ffff16908161ffff168152505083818151811061211557612115614f4b565b6020026020010151602001518282600261212f919061584a565b8151811061213f5761213f614f4b565b60200260200101906001600160a01b031690816001600160a01b03168152505083818151811061217157612171614f4b565b6020026020010151604001518261219483600261218e919061584a565b60010190565b815181106121a4576121a4614f4b565b6001600160a01b0392909216602092830291909101909101526001016120b4565b50915091565b60008281526097602090815260408083206001600160a01b038516845290915290205460ff1661088d576121fe81613c21565b612209836020613c33565b60405160200161221a929190615861565b60408051601f19818403018152908290527f08c379a000000000000000000000000000000000000000000000000000000000825261094f916004016158e2565b60008281526097602090815260408083206001600160a01b038516845290915290205460ff1661088d5760008281526097602090815260408083206001600160a01b0385168452909152902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790556122d63390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000610b94836001600160a01b038416613e76565b60008281526097602090815260408083206001600160a01b038516845290915290205460ff161561088d5760008281526097602090815260408083206001600160a01b038516808552925280832080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000610b94836001600160a01b038416613ec5565b600054610100900460ff1661247c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e67000000000000000000000000000000000000000000606482015260840161094f565b61197b613fb8565b600054610100900460ff1661251b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e67000000000000000000000000000000000000000000606482015260840161094f565b61252361404f565b61197b6140e6565b600054610100900460ff166125c2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e67000000000000000000000000000000000000000000606482015260840161094f565b60408051808201909152620186a080825268056bc75e2d63100000602090920182905261012d80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000016909117905561012e55565b600082600001828154811061262e5761262e614f4b565b9060005260206000200154905092915050565b6040516001600160a01b0380851660248301528316604482015260648101829052610e1d9085907f23b872dd0000000000000000000000000000000000000000000000000000000090608401611e01565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8901612867576126e4887f0000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb0886141fc565b6040805160038082526080820190925260009160208201606080368337019050509050888160008151811061271b5761271b614f4b565b60200260200101906001600160a01b031690816001600160a01b031681525050838160018151811061274f5761274f614f4b565b60200260200101906001600160a01b031690816001600160a01b031681525050878160028151811061278357612783614f4b565b6001600160a01b0392831660209182029290920101526000908a1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee146127bf5760006127c1565b875b90507f0000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb06001600160a01b031663b77d239b82848b8b60008060006040518863ffffffff1660e01b815260040161281c969594939291906158f5565b60206040518083038185885af115801561283a573d6000803e3d6000fd5b50505050506040513d601f19601f8201168201806040525081019061285f9190615802565b5050506138dc565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe89016129bf576128b9887f000000000000000000000000eef417e1d5cc832e619ae18d2f140de2999dd4fb886141fc565b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038a16146128e65760006128e8565b865b6040517fd895feee0000000000000000000000000000000000000000000000000000000081526001600160a01b038b811660048301528a81166024830152604482018a90526064820189905260848201889052600060a48301529192507f000000000000000000000000eef417e1d5cc832e619ae18d2f140de2999dd4fb9091169063d895feee90839060c40160206040518083038185885af1158015612993573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906129b89190615802565b50506138dc565b60038914806129ce5750600589145b15612db85760006001600160a01b038416612a3a5760038a14612a11577f000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f612a33565b7f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d5b9050612a3d565b50825b612a488982896141fc565b60408051600280825260608201835260009260208301908036833701905050905073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038b1603612b9e577f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281600081518110612ac157612ac1614f4b565b60200260200101906001600160a01b031690816001600160a01b0316815250508881600181518110612af557612af5614f4b565b6001600160a01b0392831660209182029290920101526040517f7ff36ab500000000000000000000000000000000000000000000000000000000815290831690637ff36ab5908a90612b51908b90869030908d9060040161593b565b60006040518083038185885af1158015612b6f573d6000803e3d6000fd5b50505050506040513d6000823e601f3d908101601f19168201604052612b989190810190615970565b506129b8565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038a1603612ccd578981600081518110612bd657612bd6614f4b565b60200260200101906001600160a01b031690816001600160a01b0316815250507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281600181518110612c2a57612c2a614f4b565b6001600160a01b0392831660209182029290920101526040517f18cbafe5000000000000000000000000000000000000000000000000000000008152908316906318cbafe590612c86908b908b90869030908d906004016159a5565b6000604051808303816000875af1158015612ca5573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612b989190810190615970565b8981600081518110612ce157612ce1614f4b565b60200260200101906001600160a01b031690816001600160a01b0316815250508881600181518110612d1557612d15614f4b565b6001600160a01b0392831660209182029290920101526040517f38ed1739000000000000000000000000000000000000000000000000000000008152908316906338ed173990612d71908b908b90869030908d906004016159a5565b6000604051808303816000875af1158015612d90573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261285f9190810190615970565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc89016131e65760006001600160a01b038416612e1657507f000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564612e19565b50825b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038b1614612e455789612e67565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc25b9050600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038b1614612e955789612eb7565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc25b90507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316826001600160a01b031603612f67577f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663d0e30db08a6040518263ffffffff1660e01b81526004016000604051808303818588803b158015612f4d57600080fd5b505af1158015612f61573d6000803e3d6000fd5b50505050505b612f7282848b6141fc565b60408051610100810182526001600160a01b038085168252838116602083015262ffffff881682840152306060830152608082018a905260a082018c905260c082018b9052600060e083015291517f414bf389000000000000000000000000000000000000000000000000000000008152909185169063414bf389906130669084906004016000610100820190506001600160a01b0380845116835280602085015116602084015262ffffff60408501511660408401528060608501511660608401526080840151608084015260a084015160a084015260c084015160c08401528060e08501511660e08401525092915050565b6020604051808303816000875af1158015613085573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130a99190615802565b507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316826001600160a01b0316036131dd576040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201527f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031690632e1a7d4d9082906370a0823190602401602060405180830381865afa158015613168573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061318c9190615802565b6040518263ffffffff1660e01b81526004016131aa91815260200190565b600060405180830381600087803b1580156131c457600080fd5b505af11580156131d8573d6000803e3d6000fd5b505050505b505050506138dc565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa89016133b5576fffffffffffffffffffffffffffffffff851115613257576040517f7d5ee39100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b613282887f000000000000000000000000c537e898cd774e2dcba3b14ea6f34c93d5ea45e1886141fc565b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038a16146132af5760006132b1565b865b90506000828060200190518101906132c99190615a01565b90507f000000000000000000000000c537e898cd774e2dcba3b14ea6f34c93d5ea45e16001600160a01b031663f1c5e014838c8c858b8d6040518763ffffffff1660e01b8152600401613320959493929190615ab4565b60206040518083038185885af115801561333e573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906133639190615b51565b5060006133796001600160a01b038c1630611e65565b9050801561285f5761285f6001600160a01b038c167f000000000000000000000000ba7d1581db6248dc9177466a328bf457703c8f8483611d78565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff98901613577577f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c86134088982896141fc565b6040805160c0810182528481526000602082018190529181016001600160a01b038c1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1461344b578b61344e565b60005b6001600160a01b0316815260200161348b8b6001600160a01b03166001600160a01b031673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1490565b613495578a613498565b60005b6001600160a01b03908116825260208083018c905260408051808301825260008082529482015280516080810182523080825292810185905280820192909252606082018490528401519394509216156134f35760006134f5565b895b9050836001600160a01b03166352bbbe298285858d8d6040518663ffffffff1660e01b815260040161352a9493929190615b6c565b60206040518083038185885af1158015613548573d6000803e3d6000fd5b50505050506040513d601f19601f8201168201806040525081019061356d9190615802565b50505050506138dc565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff889016138aa576fffffffffffffffffffffffffffffffff8611156135e8576040517fcd0ac5e600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b0389161461363e576040517f8a39b80100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03881603613694576040517f7a9404b000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f824316880000000000000000000000000000000000000000000000000000000081526001600160a01b0388811660048301526fffffffffffffffffffffffffffffffff881660248301526000917f000000000000000000000000d06146d292f9651c1d7cf54a3162791dfc2bef4690911690638243168890604401602060405180830381865afa158015613730573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137549190615b51565b905085816fffffffffffffffffffffffffffffffff1610156137a2576040517fb34424fd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f4747919d0000000000000000000000000000000000000000000000000000000081526001600160a01b0389811660048301526fffffffffffffffffffffffffffffffff831660248301527f000000000000000000000000d06146d292f9651c1d7cf54a3162791dfc2bef461690634747919d9089906044016000604051808303818588803b15801561383757600080fd5b505af115801561384b573d6000803e3d6000fd5b5050505050600061386e308b6001600160a01b0316611e6590919063ffffffff16565b905080156129b8576129b86001600160a01b038b167f000000000000000000000000ba7d1581db6248dc9177466a328bf457703c8f8483611d78565b6040517f8260f36600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505050505050505050565b80471015613951576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e6365000000604482015260640161094f565b6000826001600160a01b03168260405160006040518083038185875af1925050503d806000811461399e576040519150601f19603f3d011682016040523d82523d6000602084013e6139a3565b606091505b50509050806108b6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d61792068617665207265766572746564000000000000606482015260840161094f565b6000613a89826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166142fa9092919063ffffffff16565b9050805160001480613aaa575080806020019051810190613aaa9190615c65565b6108b6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f74207375636365656400000000000000000000000000000000000000000000606482015260840161094f565b6000806000613b458585614311565b9050848402808210613b5e579081900392509050613b6a565b60018183030393509150505b9250929050565b60008180613b8157613b8161581b565b838509949350505050565b600080828410613ba25750839050818303613bb4565b613bad60018661500c565b9150508183035b935093915050565b600080613bda8380830381613bd357613bd361581b565b0460010190565b9050828481613beb57613beb61581b565b048186021795945050505050565b60006001815b6008811015613c1a5783820260020382029150600101613bff565b5092915050565b60606105b76001600160a01b03831660145b60606000613c4283600261584a565b613c4d906002614f38565b67ffffffffffffffff811115613c6557613c65614797565b6040519080825280601f01601f191660200182016040528015613c8f576020820181803683370190505b5090507f300000000000000000000000000000000000000000000000000000000000000081600081518110613cc657613cc6614f4b565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110613d2957613d29614f4b565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053506000613d6584600261584a565b613d70906001614f38565b90505b6001811115613e0d577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110613db157613db1614f4b565b1a60f81b828281518110613dc757613dc7614f4b565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535060049490941c93613e0681615c87565b9050613d73565b508315610b94576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161094f565b6000818152600183016020526040812054613ebd575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556105b7565b5060006105b7565b60008181526001830160205260408120548015613fae576000613ee960018361500c565b8554909150600090613efd9060019061500c565b9050818114613f62576000866000018281548110613f1d57613f1d614f4b565b9060005260206000200154905080876000018481548110613f4057613f40614f4b565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080613f7357613f73615cbc565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506105b7565b60009150506105b7565b600054610100900460ff16611878576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e67000000000000000000000000000000000000000000606482015260840161094f565b600054610100900460ff1661197b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e67000000000000000000000000000000000000000000606482015260840161094f565b600054610100900460ff1661417d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e67000000000000000000000000000000000000000000606482015260840161094f565b60fb80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00001660011790556141d27f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca0250968061433e565b61197b7f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca02509633614389565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b0384160361422557505050565b60006001600160a01b0384166040517fdd62ed3e0000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038581166024830152919091169063dd62ed3e90604401602060405180830381865afa158015614298573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142bc9190615802565b905081811015610e1d57610e1d6001600160a01b038516847fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff614393565b606061430984846000856143d0565b949350505050565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8284099392505050565b600082815260976020526040808220600101805490849055905190918391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b61088d8282611888565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038416036143bc57505050565b6108b66001600160a01b03841683836144dc565b606082471015614462576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c0000000000000000000000000000000000000000000000000000606482015260840161094f565b600080866001600160a01b0316858760405161447e9190615ceb565b60006040518083038185875af1925050503d80600081146144bb576040519150601f19603f3d011682016040523d82523d6000602084013e6144c0565b606091505b50915091506144d1878383876145b2565b979650505050505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f095ea7b30000000000000000000000000000000000000000000000000000000017905261455b8482614645565b610e1d576040516001600160a01b0384166024820152600060448201526145a89085907f095ea7b30000000000000000000000000000000000000000000000000000000090606401611e01565b610e1d8482613a34565b6060831561463b578251600003614634576001600160a01b0385163b614634576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161094f565b5081614309565b61430983836146ec565b6000806000846001600160a01b0316846040516146629190615ceb565b6000604051808303816000865af19150503d806000811461469f576040519150601f19603f3d011682016040523d82523d6000602084013e6146a4565b606091505b50915091508180156146ce5750805115806146ce5750808060200190518101906146ce9190615c65565b80156146e357506001600160a01b0385163b15155b95945050505050565b8151156146fc5781518083602001fd5b806040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161094f91906158e2565b60006020828403121561474257600080fd5b81357fffffffff0000000000000000000000000000000000000000000000000000000081168114610b9457600080fd5b6001600160a01b0381168114610af157600080fd5b803561479281614772565b919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b604051610120810167ffffffffffffffff811182821017156147ea576147ea614797565b60405290565b6040516060810167ffffffffffffffff811182821017156147ea576147ea614797565b6040805190810167ffffffffffffffff811182821017156147ea576147ea614797565b604051601f8201601f1916810167ffffffffffffffff8111828210171561485f5761485f614797565b604052919050565b600067ffffffffffffffff82111561488157614881614797565b50601f01601f191660200190565b600082601f8301126148a057600080fd5b81356148b36148ae82614867565b614836565b8181528460208386010111156148c857600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080600060a086880312156148fd57600080fd5b853561490881614772565b9450602086013561491881614772565b93506040860135925060608601359150608086013567ffffffffffffffff81111561494257600080fd5b61494e8882890161488f565b9150509295509295909350565b60006020828403121561496d57600080fd5b5035919050565b600067ffffffffffffffff82111561498e5761498e614797565b5060051b60200190565b61ffff81168114610af157600080fd5b803561479281614998565b600082601f8301126149c457600080fd5b813560206149d46148ae83614974565b82815260059290921b840181019181810190868411156149f357600080fd5b8286015b84811015614a17578035614a0a81614772565b83529183019183016149f7565b509695505050505050565b600082601f830112614a3357600080fd5b81356020614a436148ae83614974565b82815260059290921b84018101918181019086841115614a6257600080fd5b8286015b84811015614a175780358352918301918301614a66565b6000614a8b6148ae84614974565b8381529050602080820190600585901b840186811115614aaa57600080fd5b845b81811015614b8757803567ffffffffffffffff80821115614acd5760008081fd5b90870190610120828b031215614ae35760008081fd5b614aeb6147c6565b614af4836149a8565b8152614b01868401614787565b868201526040614b12818501614787565b90820152606083810135908201526080808401359082015260a0808401359082015260c0614b41818501614787565b9082015260e083810135908201526101008084013583811115614b645760008081fd5b614b708d82870161488f565b918301919091525086525050928201928201614aac565b505050509392505050565b600082601f830112614ba357600080fd5b610b9483833560208501614a7d565b60008060408385031215614bc557600080fd5b823567ffffffffffffffff80821115614bdd57600080fd5b818501915085601f830112614bf157600080fd5b81356020614c016148ae83614974565b82815260059290921b84018101918181019089841115614c2057600080fd5b8286015b84811015614cc657803586811115614c3c5760008081fd5b87016060818d03601f1901811315614c545760008081fd5b614c5c6147f0565b86830135614c6981614998565b8152604083013589811115614c7e5760008081fd5b614c8c8f89838701016149b3565b8289015250908201359088821115614ca45760008081fd5b614cb28e8884860101614a22565b604082015285525050918301918301614c24565b5096505086013592505080821115614cdd57600080fd5b50614cea85828601614b92565b9150509250929050565b60008060408385031215614d0757600080fd5b823591506020830135614d1981614772565b809150509250929050565b60008060208385031215614d3757600080fd5b823567ffffffffffffffff80821115614d4f57600080fd5b818501915085601f830112614d6357600080fd5b813581811115614d7257600080fd5b866020828501011115614d8457600080fd5b60209290920196919550909350505050565b60008060408385031215614da957600080fd5b50508035926020909101359150565b600060408284031215614dca57600080fd5b50919050565b60008060008060608587031215614de657600080fd5b843567ffffffffffffffff80821115614dfe57600080fd5b818701915087601f830112614e1257600080fd5b813581811115614e2157600080fd5b8860208260051b8501011115614e3657600080fd5b60209283019650945050850135614e4c81614772565b9396929550929360400135925050565b60008060008060808587031215614e7257600080fd5b843567ffffffffffffffff80821115614e8a57600080fd5b614e96888389016149b3565b95506020870135915080821115614eac57600080fd5b614eb888838901614a22565b94506040870135915080821115614ece57600080fd5b614eda88838901614a22565b93506060870135915080821115614ef057600080fd5b50614efd8782880161488f565b91505092959194509250565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b808201808211156105b7576105b7614f09565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b61ffff818116838216019080821115613c1a57613c1a614f09565b63ffffffff81168114610af157600080fd5b600060208284031215614fb957600080fd5b8135610b9481614f95565b8135614fcf81614f95565b63ffffffff81167fffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000083541617825550602082013560018201555050565b818103818111156105b7576105b7614f09565b600082357ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffee183360301811261505357600080fd5b9190910192915050565b60006020828403121561506f57600080fd5b8135610b9481614772565b6000610b94368484614a7d565b805161479281614998565b600082601f8301126150a357600080fd5b815160206150b36148ae83614974565b82815260059290921b840181019181810190868411156150d257600080fd5b8286015b84811015614a1757805183529183019183016150d6565b805161479281614772565b60005b838110156151135781810151838201526020016150fb565b50506000910152565b600082601f83011261512d57600080fd5b815161513b6148ae82614867565b81815284602083860101111561515057600080fd5b6143098260208301602087016150f8565b600082601f83011261517257600080fd5b815160206151826148ae83614974565b82815260059290921b840181019181810190868411156151a157600080fd5b8286015b84811015614a1757805167ffffffffffffffff808211156151c65760008081fd5b818901915061012080601f19848d030112156151e25760008081fd5b6151ea6147c6565b6151f5888501615087565b815260406152048186016150ed565b8983015260606152158187016150ed565b828401526080915081860151818401525060a0808601518284015260c0915081860151818401525060e061524a8187016150ed565b828401526101009150818601518184015250828501519250838311156152705760008081fd5b61527e8d8a8588010161511c565b9082015286525050509183019183016151a5565b600080604083850312156152a557600080fd5b825167ffffffffffffffff808211156152bd57600080fd5b818501915085601f8301126152d157600080fd5b81516152df6148ae82614974565b8082825260208201915060208360051b86010192508883111561530157600080fd5b602085015b838110156154095780518581111561531d57600080fd5b86016060818c03601f1901121561533357600080fd5b61533b6147f0565b602082015161534981614998565b815260408201518781111561535d57600080fd5b8201603f81018d1361536e57600080fd5b602081015161537f6148ae82614974565b81815260059190911b82016040019060208101908f8311156153a057600080fd5b6040840193505b828410156153cb5783516153ba81614772565b8252602093840193909101906153a7565b60208501525050506060820151878111156153e557600080fd5b6153f48d602083860101615092565b60408301525084525060209283019201615306565b506020880151909650935050508082111561542357600080fd5b50614cea85828601615161565b600081518084526020808501945080840160005b8381101561546057815187529582019590820190600101615444565b509495945050505050565b600081518084526154838160208601602086016150f8565b601f01601f19169290920160200192915050565b600081518084526020808501808196508360051b8101915082860160005b858110156155515782840389528151805161ffff168552858101516001600160a01b0390811687870152604080830151821690870152606080830151908701526080808301519087015260a0808301519087015260c0808301519091169086015260e08082015190860152610100908101516101209186018290529061553d8187018361546b565b9a87019a95505050908401906001016154b5565b5091979650505050505050565b60006040808301818452808651808352606092508286019150828160051b8701016020808a016000805b85811015615635578a85037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa00187528251805161ffff168652848101518587018a905280518a880181905290860190849060808901905b808310156156085783516001600160a01b031682529288019260019290920191908801906155df565b50928c0151888403898e01529261561f8185615430565b9a88019a98505050938501935050600101615588565b505050878203908801526156498189615497565b9998505050505050505050565b60006001600160a01b03808716835285602084015280851660408401525060806060830152615688608083018461546b565b9695505050505050565b6000608082016001600160a01b038088168452602060808186015282885180855260a087019150828a01945060005b818110156156df5785518516835294830194918301916001016156c1565b505085810360408701526156f38189615430565b935050505082810360608401526144d1818561546b565b600081518084526020808501945080840160005b838110156154605781516001600160a01b03168752958201959082019060010161571e565b60c0808252875190820181905260009060209060e0840190828b01845b8281101561578057815161ffff1684529284019290840190600101615760565b50505083810382850152615794818a61570a565b91505082810360408401526157a9818861570a565b905082810360608401526157bd8187615430565b905082810360808401526157d18186615430565b905082810360a08401526156498185615430565b6000602082840312156157f757600080fd5b8151610b9481614772565b60006020828403121561581457600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b80820281158282048414176105b7576105b7614f09565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516158998160178501602088016150f8565b7f206973206d697373696e6720726f6c652000000000000000000000000000000060179184019182015283516158d68160288401602088016150f8565b01602801949350505050565b602081526000610b94602083018461546b565b60c08152600061590860c083018961570a565b60208301979097525060408101949094526001600160a01b0392831660608501529116608083015260a090910152919050565b848152608060208201526000615954608083018661570a565b6001600160a01b03949094166040830152506060015292915050565b60006020828403121561598257600080fd5b815167ffffffffffffffff81111561599957600080fd5b61430984828501615092565b85815284602082015260a0604082015260006159c460a083018661570a565b6001600160a01b0394909416606083015250608001529392505050565b80516fffffffffffffffffffffffffffffffff8116811461479257600080fd5b60006020808385031215615a1457600080fd5b825167ffffffffffffffff811115615a2b57600080fd5b8301601f81018513615a3c57600080fd5b8051615a4a6148ae82614974565b81815260069190911b82018301908381019087831115615a6957600080fd5b928401925b828410156144d15760408489031215615a875760008081fd5b615a8f614813565b84518152615a9e8686016159e1565b8187015282526040939093019290840190615a6e565b600060a082016001600160a01b0380891684526020818916818601526040915060a08286015282885180855260c087019150828a01945060005b81811015615b25578551805184528401516fffffffffffffffffffffffffffffffff16848401529483019491840191600101615aee565b5050606086018890526fffffffffffffffffffffffffffffffff87166080870152935061568892505050565b600060208284031215615b6357600080fd5b610b94826159e1565b60e08152845160e08201526000602086015160028110615bb5577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b61010083015260408601516001600160a01b03166101208301526060860151615bea6101408401826001600160a01b03169052565b50608086015161016083015260a086015160c0610180840152615c116101a084018261546b565b915050615c5360208301866001600160a01b03808251168352602082015115156020840152806040830151166040840152506060810151151560608301525050565b60a082019390935260c0015292915050565b600060208284031215615c7757600080fd5b81518015158114610b9457600080fd5b600081615c9657615c96614f09565b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603160045260246000fd5b600082516150538184602087016150f856fea164736f6c6343000813000a
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c000000000000000000000000ba7d1581db6248dc9177466a328bf457703c8f840000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb0000000000000000000000000eef417e1d5cc832e619ae18d2f140de2999dd4fb0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f000000000000000000000000c537e898cd774e2dcba3b14ea6f34c93d5ea45e1000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c8000000000000000000000000d06146d292f9651c1d7cf54a3162791dfc2bef46
-----Decoded View---------------
Arg [0] : initBnt (address): 0x1F573D6Fb3F13d689FF844B4cE37794d79a7FF1C
Arg [1] : initProtocolWallet (address): 0xba7d1581Db6248DC9177466a328BF457703c8f84
Arg [2] : 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---------------
10 Constructor Arguments found :
Arg [0] : 0000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c
Arg [1] : 000000000000000000000000ba7d1581db6248dc9177466a328bf457703c8f84
Arg [2] : 0000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb0
Arg [3] : 000000000000000000000000eef417e1d5cc832e619ae18d2f140de2999dd4fb
Arg [4] : 0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d
Arg [5] : 000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564
Arg [6] : 000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f
Arg [7] : 000000000000000000000000c537e898cd774e2dcba3b14ea6f34c93d5ea45e1
Arg [8] : 000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c8
Arg [9] : 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
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.