More Info
Private Name Tags
ContractCreator
Loading...
Loading
Contract Source Code Verified (Exact Match)
Contract Name:
PoolV2
Compiler Version
v0.8.26+commit.8a97fa7a
Optimization Enabled:
Yes with 100 runs
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {OwnableRoles} from "../lib/solady/src/auth/OwnableRoles.sol"; import {ERC20} from "../lib/solady/src/tokens/ERC20.sol"; import {ReentrancyGuard} from "../lib/solady/src/utils/ReentrancyGuard.sol"; import {FixedPointMathLib} from "../lib/solady/src/utils/FixedPointMathLib.sol"; import {SafeTransferLib} from "../lib/solady/src/utils/SafeTransferLib.sol"; import {IRateProvider} from "./RateProvider/IRateProvider.sol"; import {LogExpMath} from "./BalancerLibCode/LogExpMath.sol"; import {PoolToken} from "./PoolToken.sol"; contract PoolV2 is OwnableRoles, ReentrancyGuard { uint256 constant PRECISION = 1_000_000_000_000_000_000; uint256 constant MAX_NUM_TOKENS = 32; uint256 constant ALL_TOKENS_FLAG = 14_528_991_250_861_404_666_834_535_435_384_615_765_856_667_510_756_806_797_353_855_100_662_256_435_713; // sum((i+1) << 8*i) uint256 constant POOL_VB_MASK = 2 ** 128 - 1; uint128 constant POOL_VB_SHIFT = 128; uint256 constant VB_MASK = 2 ** 96 - 1; uint256 constant RATE_MASK = 2 ** 80 - 1; uint128 constant RATE_SHIFT = 96; uint128 constant PACKED_WEIGHT_SHIFT = 176; uint256 constant WEIGHT_SCALE = 1_000_000_000_000; uint256 constant WEIGHT_MASK = 2 ** 20 - 1; uint128 constant TARGET_WEIGHT_SHIFT = 20; uint128 constant LOWER_BAND_SHIFT = 40; uint128 constant UPPER_BAND_SHIFT = 60; uint256 constant MAX_POW_REL_ERR = 100; // 1e-16 /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ error Pool__InputOutputTokensSame(); error Pool__IndexOutOfBounds(); error Pool__MaxLimitExceeded(); error Pool__ZeroAmount(); error Pool__MustBeInitiatedWithMoreThanOneToken(); error Pool__MustBeInitiatedWithAGreaterThanZero(); error Pool__InvalidParams(); error Pool__CannotBeZeroAddress(); error Pool__InvalidDecimals(); error Pool__SumOfWeightsMustBeOne(); error Pool__InvalidRateProvided(); error Pool__NoConvergence(); error Pool__RatioBelowLowerBound(); error Pool__RatioAboveUpperBound(); error Pool__SlippageLimitExceeded(); error Pool__NeedToDepositAtleastOneToken(); error Pool__InitialDepositAmountMustBeNonZero(); error Pool__NewWeightsLengthMismatch(); error Pool__ProposedWeightOutOfRange(); error Pool__NewSupplyIsGreaterThanPrevSupply(); error Pool__LpAmountSuppliedIsLessThanChangeInSupply(); error Pool__TokenDecimalCannotBeZero(); error Pool__AmountsMustBeNonZero(); error Pool__WeightOutOfBounds(); error Pool__PoolIsFull(); error Pool__RampActive(); error Pool__PoolIsEmpty(); error Pool__TokenAlreadyPartOfPool(); error Pool__CannotRescuePoolToken(); error Pool__BandsOutOfBounds(); error Pool__WeightsDoNotAddUp(); error Pool__AlreadyPaused(); error Pool__NotPaused(); error Pool__Killed(); error Pool__NoSurplus(); error Pool__NoRate(); error Pool__Paused(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* EVENTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ event Swap( address indexed caller, address receiver, uint256 tokenIn, uint256 tokenOut, uint256 amountIn, uint256 amountOut ); event AddLiquidity(address indexed caller, address receiver, uint256[] amountsIn, uint256 lpAmount); event RemoveLiquidity(address indexed caller, address receiver, uint256 lpAmount); event RemoveLiquiditySingle( address indexed caller, address receiver, uint256 token, uint256 amountOut, uint256 lpAmount ); event RateUpdate(uint256 indexed token, uint256 rate); event Pause(address indexed caller); event Unpause(address indexed caller); event Kill(); event AddToken(uint256 index, address token, address rateProvider, uint256 rate, uint256 weight, uint256 amount); event SetSwapFeeRate(uint256 rate); event SetWeightBand(uint256 indexed token, uint256 lower, uint256 upper); event SetRateProvider(uint256 token, address rateProvider); event SetRamp(uint256 amplification, uint256[] weights, uint256 duration, uint256 start); event SetRampStep(uint256 rampStep); event StopRamp(); event SetStaking(address vaultAddress); event SetGuardian(address indexed caller, address guardian); event TokenRemoved(uint256 indexed tokenIndex, address indexed token); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* AUTH */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ uint256 constant ROLE_POOL_OWNER = 1 << 0; // 0x1 uint256 constant ROLE_POOL_MANAGER = 1 << 1; // 0x2 uint256 constant ROLE_POOL_MONITOR = 1 << 2; // 0x4 modifier onlyPoolOwner() { _checkRoles(ROLE_POOL_OWNER); _; } modifier onlyPoolMonitor() { _checkRoles(ROLE_POOL_MONITOR | ROLE_POOL_OWNER); _; } modifier onlyPoolManager() { _checkRoles(ROLE_POOL_MANAGER | ROLE_POOL_OWNER); _; } uint256 public amplification; // A * f**n uint256 public numTokens; uint256 public supply; address public tokenAddress; address public vaultAddress; address[MAX_NUM_TOKENS] public tokens; uint256[MAX_NUM_TOKENS] public rateMultipliers; // An array of: [10 ** (36 - tokens_[n].decimals()), ... for n in range(numTokens)] address[MAX_NUM_TOKENS] public rateProviders; uint256[MAX_NUM_TOKENS] public packedVirtualBalances; // x_i = b_i r_i (96) | r_i (80) | w_i (20) | target w_i (20) | lower (20) | upper (20) bool public paused; bool public killed; uint256 public swapFeeRate; uint256 public rampStep; uint256 public rampLastTime; uint256 public rampStopTime; uint256 public targetAmplification; uint256 packedPoolVirtualBalance; // vbProd (128) | vbSum (128) // vbProd: pi, product term `product((w_i * D / x_i)^(w_i n))` // vbSum: sigma, sum term `sum(x_i)` /// @notice constructor /// @dev sum of all weights /// @dev rebasing tokens not supported /// @param tokenAddress_ address of the poolToken /// @param amplification_ the pool amplification factor (in 18 decimals) /// @param tokens_ array of addresses of tokens in the pool /// @param rateProviders_ array of addresses of rate providers for the tokens in the pool /// @param weights_ weight of each token (in 18 decimals) constructor( address tokenAddress_, uint256 amplification_, address[] memory tokens_, address[] memory rateProviders_, uint256[] memory weights_, address owner_ ) { if (tokenAddress_ == address(0)) revert Pool__InvalidParams(); uint256 _numTokens = tokens_.length; if (_numTokens > MAX_NUM_TOKENS) revert Pool__MaxLimitExceeded(); if (_numTokens < 2) { revert Pool__MustBeInitiatedWithMoreThanOneToken(); } if (rateProviders_.length != _numTokens || weights_.length != _numTokens) { revert Pool__InvalidParams(); } if (amplification_ < PRECISION) { revert Pool__MustBeInitiatedWithAGreaterThanZero(); } amplification = amplification_; numTokens = _numTokens; uint256 weightSum; for (uint256 t = 0; t < MAX_NUM_TOKENS; t++) { if (t == _numTokens) break; if (tokens_[t] == address(0)) { revert Pool__CannotBeZeroAddress(); } tokens[t] = tokens_[t]; if (rateProviders_[t] == address(0)) { revert Pool__CannotBeZeroAddress(); } rateProviders[t] = rateProviders_[t]; uint8 decimals = ERC20(tokens_[t]).decimals(); if (decimals == 0) { revert Pool__TokenDecimalCannotBeZero(); } rateMultipliers[t] = 10 ** (36 - decimals); if (weights_[t] == 0) { revert Pool__InvalidParams(); } uint256 _packedWeight = _packWeight(weights_[t], weights_[t], PRECISION, PRECISION); packedVirtualBalances[t] = _packVirtualBalance(0, 0, _packedWeight); weightSum += weights_[t]; } if (weightSum != PRECISION) { revert Pool__SumOfWeightsMustBeOne(); } rampStep = 1; _initializeOwner(owner_); _grantRoles(owner_, ROLE_POOL_OWNER); tokenAddress = tokenAddress_; } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* POOL FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @notice swap one pool token for another /// @param tokenIn_ index of the input token /// @param tokenOut_ index of the output token /// @param tokenInAmount_ amount of input token to take from the caller /// @param minTokenOutAmount_ minimum amount of output token to send /// @param receiver_ account to receive the output token /// @return the amount of output token function swap( uint256 tokenIn_, uint256 tokenOut_, uint256 tokenInAmount_, uint256 minTokenOutAmount_, address receiver_ ) external nonReentrant returns (uint256) { uint256 _numTokens = numTokens; if (tokenIn_ == tokenOut_) revert Pool__InputOutputTokensSame(); if (tokenIn_ >= _numTokens || tokenOut_ >= _numTokens) revert Pool__IndexOutOfBounds(); if (tokenInAmount_ == 0) revert Pool__ZeroAmount(); // update rates for from and to tokens (uint256 _virtualBalanceProd, uint256 _virtualBalanceSum) = _unpackPoolVirtualBalance(packedPoolVirtualBalance); (_virtualBalanceProd, _virtualBalanceSum) = _updateRates( FixedPointMathLib.rawAdd(tokenIn_, 1) | (FixedPointMathLib.rawAdd(tokenOut_, 1) << 8), _virtualBalanceProd, _virtualBalanceSum ); uint256 _prevVirtualBalanceSum = _virtualBalanceSum; (uint256 _prevVirtualBalanceX, uint256 _rateX, uint256 _packedWeightX) = _unpackVirtualBalance(packedVirtualBalances[tokenIn_]); uint256 _weightTimesNOfX = _unpackWeightTimesN(_packedWeightX, _numTokens); (uint256 _prevVirtualBalanceY, uint256 _rateY, uint256 _packedWeightY) = _unpackVirtualBalance(packedVirtualBalances[tokenOut_]); uint256 _weightTimesNOfY = _unpackWeightTimesN(_packedWeightY, _numTokens); // adjust tokenInAmount_ to 18 decimals uint256 _adjustedTokenInAmount = FixedPointMathLib.mulWad(tokenInAmount_, rateMultipliers[tokenIn_]); // (tokenInAmount_ * rateMultipliers[tokenIn_]) / PRECISION uint256 _tokenInFee = (_adjustedTokenInAmount * swapFeeRate) / PRECISION; uint256 _changeInVirtualBalanceTokenIn = ((_adjustedTokenInAmount - _tokenInFee) * _rateX) / PRECISION; uint256 _virtualBalanceX = _prevVirtualBalanceX + _changeInVirtualBalanceTokenIn; // update x_i and remove x_j from variables _virtualBalanceProd = _virtualBalanceProd * _powUp(_prevVirtualBalanceY, _weightTimesNOfY) / _powDown((_virtualBalanceX * PRECISION) / _prevVirtualBalanceX, _weightTimesNOfX); _virtualBalanceSum = _virtualBalanceSum + _changeInVirtualBalanceTokenIn - _prevVirtualBalanceY; // calculate new balance of out token uint256 _virtualBalanceY = _calculateVirtualBalance( _weightTimesNOfY, _prevVirtualBalanceY, supply, amplification, _virtualBalanceProd, _virtualBalanceSum ); _virtualBalanceSum += _virtualBalanceY; // check bands _checkBands( (_prevVirtualBalanceX * PRECISION) / _prevVirtualBalanceSum, (_virtualBalanceX * PRECISION) / _virtualBalanceSum, _packedWeightX ); _checkBands( (_prevVirtualBalanceY * PRECISION) / _prevVirtualBalanceSum, (_virtualBalanceY * PRECISION) / _virtualBalanceSum, _packedWeightY ); uint256 _adjustedTokenOutAmount = FixedPointMathLib.divWad(_prevVirtualBalanceY - _virtualBalanceY, _rateY); uint256 _tokenOutAmount = FixedPointMathLib.divWad(_adjustedTokenOutAmount, rateMultipliers[tokenOut_]); // (_adjustedTokenOutAmount * PRECISION) / rateMultipliers[tokenOut_] if (_tokenOutAmount < minTokenOutAmount_) { revert Pool__SlippageLimitExceeded(); } if (_tokenInFee > 0) { // add fee to pool _changeInVirtualBalanceTokenIn = (_tokenInFee * _rateX) / PRECISION; _virtualBalanceProd = (_virtualBalanceProd * PRECISION) / _powDown( (_virtualBalanceX + _changeInVirtualBalanceTokenIn) * PRECISION / _virtualBalanceX, _weightTimesNOfX ); _virtualBalanceX += _changeInVirtualBalanceTokenIn; _virtualBalanceSum += _changeInVirtualBalanceTokenIn; } // update variables packedVirtualBalances[tokenIn_] = _packVirtualBalance(_virtualBalanceX, _rateX, _packedWeightX); packedVirtualBalances[tokenOut_] = _packVirtualBalance(_virtualBalanceY, _rateY, _packedWeightY); _virtualBalanceProd = (_virtualBalanceProd * PRECISION) / _powUp(_virtualBalanceY, _weightTimesNOfY); // mint fees if (_tokenInFee > 0) { uint256 _supply; (_supply, _virtualBalanceProd) = _updateSupply(supply, _virtualBalanceProd, _virtualBalanceSum); } packedPoolVirtualBalance = _packPoolVirtualBalance(_virtualBalanceProd, _virtualBalanceSum); // transfer tokens SafeTransferLib.safeTransferFrom(tokens[tokenIn_], msg.sender, address(this), tokenInAmount_); SafeTransferLib.safeTransfer(tokens[tokenOut_], receiver_, _tokenOutAmount); emit Swap(msg.sender, receiver_, tokenIn_, tokenOut_, tokenInAmount_, _tokenOutAmount); return _tokenOutAmount; } /// @notice deposit tokens into the pool /// @param amounts_ array of the amount for each token to take from caller /// @param minLpAmount_ minimum amount of lp tokens to mint /// @param receiver_ account to receive the lp tokens /// @return amount of LP tokens minted function addLiquidity(uint256[] calldata amounts_, uint256 minLpAmount_, address receiver_) external nonReentrant returns (uint256) { uint256 _numTokens = numTokens; if (amounts_.length != _numTokens) revert Pool__InvalidParams(); (uint256 _virtualBalanceProd, uint256 _virtualBalanceSum) = _unpackPoolVirtualBalance(packedPoolVirtualBalance); uint256 _prevVirtualBalance; uint256 _rate; uint256 _packedWeight; // find lowest relative increase in balance uint256 _tokens = 0; uint256 _lowest = type(uint256).max; uint256 _sh; for (uint256 t = 0; t < MAX_NUM_TOKENS; t++) { if (t == _numTokens) break; uint256 __amount = amounts_[t]; if (__amount > 0) { uint256 _adjustedAmount = FixedPointMathLib.mulWad(__amount, rateMultipliers[t]); // (__amount * rateMultipliers[t]) / PRECISION _tokens = _tokens | (FixedPointMathLib.rawAdd(t, 1) << _sh); _sh = FixedPointMathLib.rawAdd(_sh, 8); if (_virtualBalanceSum > 0 && _lowest > 0) { (_prevVirtualBalance, _rate, _packedWeight) = _unpackVirtualBalance(packedVirtualBalances[t]); _lowest = FixedPointMathLib.min(_adjustedAmount * _rate / _prevVirtualBalance, _lowest); } } else { _lowest = 0; } } if (_sh == 0) revert Pool__NeedToDepositAtleastOneToken(); // update rates (_virtualBalanceProd, _virtualBalanceSum) = _updateRates(_tokens, _virtualBalanceProd, _virtualBalanceSum); uint256 _prevSupply = supply; uint256 _virtualBalanceProdFinal = _virtualBalanceProd; uint256 _virtualBalanceSumFinal = _virtualBalanceSum; uint256 _prevVirtualBalanceSum = _virtualBalanceSum; uint256[] memory _prevRatios = new uint256[](_numTokens); uint256 _virtualBalance; for (uint256 t = 0; t < MAX_NUM_TOKENS; t++) { if (t == _numTokens) break; uint256 __amount = amounts_[t]; uint256 _adjustedAmount = FixedPointMathLib.mulWad(__amount, rateMultipliers[t]); // (__amount * rateMultipliers[t]) / PRECISION if (_adjustedAmount == 0) { if (!(_prevSupply > 0)) { revert Pool__InitialDepositAmountMustBeNonZero(); } continue; } // update stored virtual balance (_prevVirtualBalance, _rate, _packedWeight) = _unpackVirtualBalance(packedVirtualBalances[t]); uint256 _changeInVirtualBalance = (_adjustedAmount * _rate) / PRECISION; _virtualBalance = _prevVirtualBalance + _changeInVirtualBalance; packedVirtualBalances[t] = _packVirtualBalance(_virtualBalance, _rate, _packedWeight); if (_prevSupply > 0) { _prevRatios[t] = (_prevVirtualBalance * PRECISION) / _prevVirtualBalanceSum; uint256 _weightTimesN = _unpackWeightTimesN(_packedWeight, _numTokens); // update product and sum of virtual balances _virtualBalanceProdFinal = ( _virtualBalanceProdFinal * _powUp((_prevVirtualBalance * PRECISION) / _virtualBalance, _weightTimesN) ) / PRECISION; // the `D^n` factor will be updated in `_calculateSupply()` _virtualBalanceSumFinal += _changeInVirtualBalance; // remove fees from balance and recalculate sum and product uint256 _fee = ( (_changeInVirtualBalance - (_prevVirtualBalance * _lowest) / PRECISION) * (swapFeeRate / 2) ) / PRECISION; _virtualBalanceProd = ( _virtualBalanceProd * _powUp((_prevVirtualBalance * PRECISION) / (_virtualBalance - _fee), _weightTimesN) ) / PRECISION; _virtualBalanceSum += _changeInVirtualBalance - _fee; } SafeTransferLib.safeTransferFrom(tokens[t], msg.sender, address(this), __amount); } uint256 _supply = _prevSupply; if (_prevSupply == 0) { // initial deposit, calculate necessary variables (_virtualBalanceProd, _virtualBalanceSum) = _calculateVirtualBalanceProdSum(); if (!(_virtualBalanceProd > 0)) revert Pool__AmountsMustBeNonZero(); _supply = _virtualBalanceSum; } else { // check bands for (uint256 t = 0; t < MAX_NUM_TOKENS; t++) { if (t == _numTokens) break; if (amounts_[t] == 0) continue; (_virtualBalance, _rate, _packedWeight) = _unpackVirtualBalance(packedVirtualBalances[t]); _checkBands(_prevRatios[t], (_virtualBalance * PRECISION) / _virtualBalanceSumFinal, _packedWeight); } } // mint LP tokens (_supply, _virtualBalanceProd) = _calculateSupply( _numTokens, _supply, amplification, _virtualBalanceProd, _virtualBalanceSum, _prevSupply == 0 ); uint256 _toMint = _supply - _prevSupply; if (!(_toMint > 0 && _toMint >= minLpAmount_)) { revert Pool__SlippageLimitExceeded(); } PoolToken(tokenAddress).mint(receiver_, _toMint); emit AddLiquidity(msg.sender, receiver_, amounts_, _toMint); uint256 _supplyFinal = _supply; if (_prevSupply > 0) { // mint fees (_supplyFinal, _virtualBalanceProdFinal) = _calculateSupply( _numTokens, _prevSupply, amplification, _virtualBalanceProdFinal, _virtualBalanceSumFinal, true ); PoolToken(tokenAddress).mint(vaultAddress, _supplyFinal - _supply); } else { _virtualBalanceProdFinal = _virtualBalanceProd; _virtualBalanceSumFinal = _virtualBalanceSum; } supply = _supplyFinal; packedPoolVirtualBalance = _packPoolVirtualBalance(_virtualBalanceProdFinal, _virtualBalanceSumFinal); return _toMint; } /// @notice deposit tokens into the pool /// @param amounts_ array of the amount for each token to take from caller /// @param minLpAmount_ minimum amount of lp tokens to mint /// @param owner_ address from which to add liquidity from /// @param receiver_ account to receive the lp tokens /// @return amount of LP tokens minted function addLiquidityFor(uint256[] calldata amounts_, uint256 minLpAmount_, address owner_, address receiver_) external nonReentrant returns (uint256) { uint256 _numTokens = numTokens; if (amounts_.length != _numTokens) revert Pool__InvalidParams(); (uint256 _virtualBalanceProd, uint256 _virtualBalanceSum) = _unpackPoolVirtualBalance(packedPoolVirtualBalance); uint256 _prevVirtualBalance; uint256 _rate; uint256 _packedWeight; // find lowest relative increase in balance uint256 _tokens = 0; uint256 _lowest = type(uint256).max; uint256 _sh; for (uint256 t = 0; t < MAX_NUM_TOKENS; t++) { if (t == _numTokens) break; uint256 __amount = amounts_[t]; if (__amount > 0) { uint256 _adjustedAmount = FixedPointMathLib.mulWad(__amount, rateMultipliers[t]); // (__amount * rateMultipliers[t]) / PRECISION _tokens = _tokens | (FixedPointMathLib.rawAdd(t, 1) << _sh); _sh = FixedPointMathLib.rawAdd(_sh, 8); if (_virtualBalanceSum > 0 && _lowest > 0) { (_prevVirtualBalance, _rate, _packedWeight) = _unpackVirtualBalance(packedVirtualBalances[t]); _lowest = FixedPointMathLib.min(_adjustedAmount * _rate / _prevVirtualBalance, _lowest); } } else { _lowest = 0; } } if (_sh == 0) revert Pool__NeedToDepositAtleastOneToken(); // update rates (_virtualBalanceProd, _virtualBalanceSum) = _updateRates(_tokens, _virtualBalanceProd, _virtualBalanceSum); uint256 _prevSupply = supply; uint256 _virtualBalanceProdFinal = _virtualBalanceProd; uint256 _virtualBalanceSumFinal = _virtualBalanceSum; uint256 _prevVirtualBalanceSum = _virtualBalanceSum; uint256[] memory _prevRatios = new uint256[](_numTokens); uint256 _virtualBalance; for (uint256 t = 0; t < MAX_NUM_TOKENS; t++) { if (t == _numTokens) break; uint256 __amount = amounts_[t]; uint256 _adjustedAmount = FixedPointMathLib.mulWad(__amount, rateMultipliers[t]); // (__amount * rateMultipliers[t]) / PRECISION if (_adjustedAmount == 0) { if (!(_prevSupply > 0)) { revert Pool__InitialDepositAmountMustBeNonZero(); } continue; } // update stored virtual balance (_prevVirtualBalance, _rate, _packedWeight) = _unpackVirtualBalance(packedVirtualBalances[t]); uint256 _changeInVirtualBalance = (_adjustedAmount * _rate) / PRECISION; _virtualBalance = _prevVirtualBalance + _changeInVirtualBalance; packedVirtualBalances[t] = _packVirtualBalance(_virtualBalance, _rate, _packedWeight); if (_prevSupply > 0) { _prevRatios[t] = (_prevVirtualBalance * PRECISION) / _prevVirtualBalanceSum; uint256 _weightTimesN = _unpackWeightTimesN(_packedWeight, _numTokens); // update product and sum of virtual balances _virtualBalanceProdFinal = ( _virtualBalanceProdFinal * _powUp((_prevVirtualBalance * PRECISION) / _virtualBalance, _weightTimesN) ) / PRECISION; // the `D^n` factor will be updated in `_calculateSupply()` _virtualBalanceSumFinal += _changeInVirtualBalance; // remove fees from balance and recalculate sum and product uint256 _fee = ( (_changeInVirtualBalance - (_prevVirtualBalance * _lowest) / PRECISION) * (swapFeeRate / 2) ) / PRECISION; _virtualBalanceProd = ( _virtualBalanceProd * _powUp((_prevVirtualBalance * PRECISION) / (_virtualBalance - _fee), _weightTimesN) ) / PRECISION; _virtualBalanceSum += _changeInVirtualBalance - _fee; } SafeTransferLib.safeTransferFrom(tokens[t], owner_, address(this), __amount); } uint256 _supply = _prevSupply; if (_prevSupply == 0) { // initial deposit, calculate necessary variables (_virtualBalanceProd, _virtualBalanceSum) = _calculateVirtualBalanceProdSum(); if (!(_virtualBalanceProd > 0)) revert Pool__AmountsMustBeNonZero(); _supply = _virtualBalanceSum; } else { // check bands for (uint256 t = 0; t < MAX_NUM_TOKENS; t++) { if (t == _numTokens) break; if (amounts_[t] == 0) continue; (_virtualBalance, _rate, _packedWeight) = _unpackVirtualBalance(packedVirtualBalances[t]); _checkBands(_prevRatios[t], (_virtualBalance * PRECISION) / _virtualBalanceSumFinal, _packedWeight); } } // mint LP tokens (_supply, _virtualBalanceProd) = _calculateSupply( _numTokens, _supply, amplification, _virtualBalanceProd, _virtualBalanceSum, _prevSupply == 0 ); uint256 _toMint = _supply - _prevSupply; if (!(_toMint > 0 && _toMint >= minLpAmount_)) { revert Pool__SlippageLimitExceeded(); } PoolToken(tokenAddress).mint(receiver_, _toMint); emit AddLiquidity(msg.sender, receiver_, amounts_, _toMint); uint256 _supplyFinal = _supply; if (_prevSupply > 0) { // mint fees (_supplyFinal, _virtualBalanceProdFinal) = _calculateSupply( _numTokens, _prevSupply, amplification, _virtualBalanceProdFinal, _virtualBalanceSumFinal, true ); PoolToken(tokenAddress).mint(vaultAddress, _supplyFinal - _supply); } else { _virtualBalanceProdFinal = _virtualBalanceProd; _virtualBalanceSumFinal = _virtualBalanceSum; } supply = _supplyFinal; packedPoolVirtualBalance = _packPoolVirtualBalance(_virtualBalanceProdFinal, _virtualBalanceSumFinal); return _toMint; } /// @notice withdraw tokens from the pool in a balanced manner /// @param lpAmount_ amount of lp tokens to burn /// @param minAmounts_ array of minimum amount of each token to send /// @param receiver_ account to receive the tokens function removeLiquidity(uint256 lpAmount_, uint256[] calldata minAmounts_, address receiver_) external nonReentrant { uint256 _numTokens = numTokens; if (minAmounts_.length != _numTokens || minAmounts_.length > MAX_NUM_TOKENS) revert Pool__InvalidParams(); // update supply uint256 _prevSupply = supply; uint256 _supply = _prevSupply - lpAmount_; supply = _supply; PoolToken(tokenAddress).burn(msg.sender, lpAmount_); emit RemoveLiquidity(msg.sender, receiver_, lpAmount_); // update variables and transfer tokens uint256 _virtualBalanceProd = PRECISION; uint256 _virtualBalanceSum = 0; uint256 _prevVirtualBalance; uint256 _rate; uint256 _packedWeight; for (uint256 t = 0; t < MAX_NUM_TOKENS; t++) { if (t == _numTokens) break; (_prevVirtualBalance, _rate, _packedWeight) = _unpackVirtualBalance(packedVirtualBalances[t]); uint256 __weight = _unpackWeightTimesN(_packedWeight, 1); uint256 dVb = (_prevVirtualBalance * lpAmount_) / _prevSupply; uint256 vb = _prevVirtualBalance - dVb; packedVirtualBalances[t] = _packVirtualBalance(vb, _rate, _packedWeight); _virtualBalanceProd = FixedPointMathLib.rawDiv( FixedPointMathLib.rawMul( _virtualBalanceProd, _powDown( FixedPointMathLib.rawDiv(FixedPointMathLib.rawMul(_supply, __weight), vb), FixedPointMathLib.rawMul(__weight, _numTokens) ) ), PRECISION ); _virtualBalanceSum = FixedPointMathLib.rawAdd(_virtualBalanceSum, vb); uint256 _adjustedAmount = (dVb * PRECISION) / _rate; uint256 _amount = FixedPointMathLib.divWad(_adjustedAmount, rateMultipliers[t]); // (_adjustedAmount * PRECISION) / rateMultiplers[t] if (_amount < minAmounts_[t]) revert Pool__SlippageLimitExceeded(); SafeTransferLib.safeTransfer(tokens[t], receiver_, _amount); } packedPoolVirtualBalance = _packPoolVirtualBalance(_virtualBalanceProd, _virtualBalanceSum); } /// @notice withdraw a single token from the pool /// @param token_ index of the token to withdraw /// @param lpAmount_ amount of lp tokens to burn /// @param minTokenOutAmount_ minimum amount of tokens to send /// @param receiver_ account to receive the token /// @return the amount of the token sent function removeLiquiditySingle(uint256 token_, uint256 lpAmount_, uint256 minTokenOutAmount_, address receiver_) external nonReentrant returns (uint256) { uint256 _numTokens = numTokens; if (token_ >= _numTokens) revert Pool__InvalidParams(); // update rate (uint256 _virtualBalanceProd, uint256 _virtualBalanceSum) = _unpackPoolVirtualBalance(packedPoolVirtualBalance); (_virtualBalanceProd, _virtualBalanceSum) = _updateRates(FixedPointMathLib.rawAdd(token_, 1), _virtualBalanceProd, _virtualBalanceSum); uint256 _prevVirtualBalanceSum = _virtualBalanceSum; // update supply uint256 _prevSupply = supply; uint256 _newSupply = _prevSupply - lpAmount_; supply = _newSupply; PoolToken(tokenAddress).burn(msg.sender, lpAmount_); (uint256 _prevVirtualBalance, uint256 _rate, uint256 _packedWeight) = _unpackVirtualBalance(packedVirtualBalances[token_]); uint256 _weightTimesN = _unpackWeightTimesN(_packedWeight, _numTokens); // update variables _virtualBalanceProd = (_virtualBalanceProd * _powUp(_prevVirtualBalance, _weightTimesN)) / PRECISION; for (uint256 t = 0; t < MAX_NUM_TOKENS; t++) { if (t == _numTokens) break; _virtualBalanceProd = (_virtualBalanceProd * _newSupply) / _prevSupply; } _virtualBalanceSum = _virtualBalanceSum - _prevVirtualBalance; // calculate new balance of token uint256 _virtualBalance = _calculateVirtualBalance( _weightTimesN, _prevVirtualBalance, _newSupply, amplification, _virtualBalanceProd, _virtualBalanceSum ); uint256 _changeInVirtualBalance = _prevVirtualBalance - _virtualBalance; uint256 _fee = _changeInVirtualBalance * swapFeeRate / 2 / PRECISION; _changeInVirtualBalance -= _fee; _virtualBalance += _fee; uint256 _adjustedTokenOutAmount = (_changeInVirtualBalance * PRECISION) / _rate; uint256 _tokenOutAmount = FixedPointMathLib.divWad(_adjustedTokenOutAmount, rateMultipliers[token_]); // _adjustedTokenOutAmount * PRECISION / rateMultipliers[token_] if (_tokenOutAmount < minTokenOutAmount_) { revert Pool__SlippageLimitExceeded(); } // update variables packedVirtualBalances[token_] = _packVirtualBalance(_virtualBalance, _rate, _packedWeight); _virtualBalanceProd = (_virtualBalanceProd * PRECISION) / _powUp(_virtualBalance, _weightTimesN); _virtualBalanceSum = _virtualBalanceSum + _virtualBalance; for (uint256 t = 0; t < MAX_NUM_TOKENS; t++) { if (t == _numTokens) break; if (t == token_) { _checkBands( (_prevVirtualBalance * PRECISION) / _prevVirtualBalanceSum, (_virtualBalance * PRECISION) / _virtualBalanceSum, _packedWeight ); } else { (uint256 _virtualBalanceLoop,, uint256 _packedWeightLoop) = _unpackVirtualBalance(packedVirtualBalances[t]); _checkBands( (_virtualBalanceLoop * PRECISION) / _prevVirtualBalanceSum, (_virtualBalanceLoop * PRECISION) / _virtualBalanceSum, _packedWeightLoop ); } } if (_fee > 0) { // mint fee (_newSupply, _virtualBalanceProd) = _updateSupply(_newSupply, _virtualBalanceProd, _virtualBalanceSum); } packedPoolVirtualBalance = _packPoolVirtualBalance(_virtualBalanceProd, _virtualBalanceSum); SafeTransferLib.safeTransfer(tokens[token_], receiver_, _tokenOutAmount); emit RemoveLiquiditySingle(msg.sender, receiver_, token_, _tokenOutAmount, lpAmount_); return _tokenOutAmount; } /// @notice update the stored rate of any of the pool's tokens /// @dev if no assets are passed in, every asset will be updated /// @param tokens_ array of indices of tokens to update function updateRates(uint256[] calldata tokens_) external { uint256 _numTokens = numTokens; uint256 _tokens; for (uint256 t = 0; t < MAX_NUM_TOKENS; t++) { if (t == tokens_.length) break; if (tokens_[t] >= _numTokens) revert Pool__IndexOutOfBounds(); _tokens = _tokens | ((tokens_[t] + 1) << (FixedPointMathLib.rawMul(8, t))); } if (tokens_.length == 0) _tokens = ALL_TOKENS_FLAG; (uint256 _virtualBalanceProd, uint256 _virtualBalanceSum) = _unpackPoolVirtualBalance(packedPoolVirtualBalance); (_virtualBalanceProd, _virtualBalanceSum) = _updateRates(_tokens, _virtualBalanceProd, _virtualBalanceSum); packedPoolVirtualBalance = _packPoolVirtualBalance(_virtualBalanceProd, _virtualBalanceSum); } /// @notice update weights and amplification factor, if possible /// @dev will only update the weights if a ramp is active and at least the minimum time step has been reached /// @return boolean to indicate whether the weights and amplification factor have been updated function updateWeights() external returns (bool) { _checkIfPaused(); bool _updated = false; (uint256 _virtualBalanceProd, uint256 _virtualBalanceSum) = _unpackPoolVirtualBalance(packedPoolVirtualBalance); (_virtualBalanceProd, _updated) = _updateWeights(_virtualBalanceProd); if (_updated && _virtualBalanceSum > 0) { (, _virtualBalanceProd) = _updateSupply(supply, _virtualBalanceProd, _virtualBalanceSum); packedPoolVirtualBalance = _packPoolVirtualBalance(_virtualBalanceProd, _virtualBalanceSum); } return _updated; } /// @notice get the pool's virtual balance product (pi) and sum (sigma) /// @return tuple with product and sum function virtualBalanceProdSum() external view returns (uint256, uint256) { return _unpackPoolVirtualBalance(packedPoolVirtualBalance); } /// @notice get the virtual balance of a token /// @param token_ index of the token in the pool /// @return virtual balance of the token function virtualBalance(uint256 token_) external view returns (uint256) { if (token_ >= numTokens) revert Pool__IndexOutOfBounds(); return packedVirtualBalances[token_] & VB_MASK; } /// @notice get the rate of an token /// @param token_ index of the token /// @return rate of the token function rate(uint256 token_) external view returns (uint256) { if (token_ >= numTokens) revert Pool__IndexOutOfBounds(); return (packedVirtualBalances[token_] >> RATE_SHIFT) & RATE_MASK; } /// @notice get the weight of a token /// @dev does not take into account any active ramp /// @param token_ index of the token /// @return tuple with weight, target weight, lower band width, upper weight band width function weight(uint256 token_) external view returns (uint256, uint256, uint256, uint256) { if (token_ >= numTokens) revert Pool__IndexOutOfBounds(); (uint256 _weight, uint256 _target, uint256 _lower, uint256 _upper) = _unpackWeight(packedVirtualBalances[token_] >> PACKED_WEIGHT_SHIFT); if (rampLastTime == 0) _target = _weight; return (_weight, _target, _lower, _upper); } /// @notice get the packed weight of a token in a packed format /// @dev does not take into account any active ramp /// @param token_ index of the token /// @return weight in packed format function packedWeight(uint256 token_) external view returns (uint256) { if (token_ >= numTokens) revert Pool__IndexOutOfBounds(); return packedVirtualBalances[token_] >> PACKED_WEIGHT_SHIFT; } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ADMIN FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @notice pause the pool function pause() external onlyPoolMonitor { if (paused) revert Pool__AlreadyPaused(); paused = true; emit Pause(msg.sender); } /// @notice unpause the pool function unpause() external onlyPoolMonitor { if (!paused) revert Pool__NotPaused(); if (killed) revert Pool__Killed(); paused = false; emit Unpause(msg.sender); } /// @notice kill the pool function kill() external onlyPoolOwner { if (!paused) revert Pool__NotPaused(); if (killed) revert Pool__Killed(); killed = true; emit Kill(); } /// @notice add a new token to the pool /// @dev can only be called if no ramp is currently active /// @dev every other token will their weight reduced pro rata /// @dev caller should assure that amplification before and after the call are the same /// @param token_ address of the token to add /// @param rateProvider_ rate provider for the token /// @param weight_ weight of the new token /// @param lower_ lower band width /// @param upper_ upper band width /// @param amount_ amount of tokens /// @param amplification_ new pool amplification factor /// @param receiver_ account to receive the lp tokens minted function addToken( address token_, address rateProvider_, uint256 weight_, uint256 lower_, uint256 upper_, uint256 amount_, uint256 amplification_, uint256 minLpAmount_, address receiver_ ) external onlyPoolManager { if (amount_ == 0) revert Pool__ZeroAmount(); uint256 _prevNumTokens = numTokens; if (_prevNumTokens >= MAX_NUM_TOKENS) revert Pool__PoolIsFull(); if (amplification_ == 0) revert Pool__ZeroAmount(); if (rampLastTime != 0) revert Pool__RampActive(); if (supply == 0) revert Pool__PoolIsEmpty(); if (!(weight_ > 0 && weight_ <= PRECISION / 100)) { revert Pool__InvalidParams(); } if (lower_ > PRECISION || upper_ > PRECISION) { revert Pool__InvalidParams(); } // update weights for existing tokens uint256 _numTokens = _prevNumTokens + 1; uint256 _virtualBalance; uint256 _rate; uint256 _packedWeight; uint256 _prevWeight; uint256 _target; uint256 _lower; uint256 _upper; for (uint256 t = 0; t < MAX_NUM_TOKENS; t++) { if (t == _prevNumTokens) break; if (tokens[t] == token_) revert Pool__TokenAlreadyPartOfPool(); (_virtualBalance, _rate, _packedWeight) = _unpackVirtualBalance(packedVirtualBalances[t]); (_prevWeight, _target, _lower, _upper) = _unpackWeight(_packedWeight); _packedWeight = _packWeight( FixedPointMathLib.rawSub( _prevWeight, FixedPointMathLib.rawDiv(FixedPointMathLib.rawMul(_prevWeight, weight_), PRECISION) ), _target, _lower, _upper ); packedVirtualBalances[t] = _packVirtualBalance(_virtualBalance, _rate, _packedWeight); } // IRateProvider(provider).rate(address) is assumed to be 10**18 precision _rate = IRateProvider(rateProvider_).rate(token_); if (_rate == 0) revert Pool__NoRate(); uint256 _adjustedAmount = FixedPointMathLib.mulWad(amount_, (10 ** (36 - ERC20(token_).decimals()))); // (amount_ * (10 ** (36 - ERC20(token_).decimals()))) / PRECISION _virtualBalance = (_adjustedAmount * _rate) / PRECISION; _packedWeight = _packWeight(weight_, weight_, _lower, _upper); // set parameters for new token numTokens = _numTokens; tokens[_prevNumTokens] = token_; rateMultipliers[_prevNumTokens] = 10 ** (36 - ERC20(token_).decimals()); rateProviders[_prevNumTokens] = rateProvider_; packedVirtualBalances[_prevNumTokens] = _packVirtualBalance(_virtualBalance, _rate, _packedWeight); // recalculate variables (uint256 _virtualBalanceProd, uint256 _virtualBalanceSum) = _calculateVirtualBalanceProdSum(); // update supply uint256 _prevSupply = supply; uint256 __supply; (__supply, _virtualBalanceProd) = _calculateSupply( _numTokens, _virtualBalanceSum, amplification_, _virtualBalanceProd, _virtualBalanceSum, true ); amplification = amplification_; supply = __supply; packedPoolVirtualBalance = _packPoolVirtualBalance(_virtualBalanceProd, _virtualBalanceSum); SafeTransferLib.safeTransferFrom(token_, msg.sender, address(this), amount_); if (__supply <= _prevSupply) revert Pool__InvalidParams(); uint256 _lpAmount = FixedPointMathLib.rawSub(__supply, _prevSupply); if (_lpAmount < minLpAmount_) revert Pool__InvalidParams(); PoolToken(tokenAddress).mint(receiver_, _lpAmount); emit AddToken(_prevNumTokens, token_, rateProvider_, _rate, weight_, amount_); } /// @notice remove a token from the pool /// @dev can only be called when no ramp is currently active /// @param tokenIndex_ index of the token to be removed in the pool /// @param lpAmount_ lpAmount to be burnt to compensate for the removed token amount /// @param amplification_ proposed new amplification /// @param newWeights_ proposed new weights /// @param duration_ duration of the ramp in seconds function removeToken( uint256 tokenIndex_, uint256 lpAmount_, uint256 amplification_, uint256[] calldata newWeights_, uint256 duration_ ) external onlyPoolManager { uint256 _numTokens = numTokens; if (_numTokens <= 2) revert Pool__MustBeInitiatedWithMoreThanOneToken(); if (paused) revert Pool__Paused(); if (amplification_ == 0) revert Pool__ZeroAmount(); if (rampLastTime != 0) revert Pool__RampActive(); if (tokenIndex_ >= numTokens) revert Pool__IndexOutOfBounds(); if (newWeights_.length != _numTokens - 1) revert Pool__NewWeightsLengthMismatch(); rampLastTime = block.timestamp; rampStopTime = block.timestamp + duration_; address removedAddress = tokens[tokenIndex_]; uint256 _newNumTokens = _numTokens - 1; address[] memory _newTokens = new address[](_newNumTokens); uint256[] memory _newRateMultipliers = new uint256[](_newNumTokens); address[] memory _newRateProviders = new address[](_newNumTokens); uint256[] memory _newPackedVirtualBalances = new uint256[](_newNumTokens); uint256 weightSum = 0; uint256 newIndex = 0; for (uint256 t = 0; t < _newNumTokens; t++) { if (t == tokenIndex_) continue; _newTokens[newIndex] = tokens[t]; _newRateMultipliers[newIndex] = rateMultipliers[t]; _newRateProviders[newIndex] = rateProviders[t]; (uint256 _virtualBalance, uint256 _rate,) = _unpackVirtualBalance(packedVirtualBalances[t]); uint256 _newWeight = newWeights_[t]; if (_newWeight == 0 || _newWeight > PRECISION) revert Pool__ProposedWeightOutOfRange(); weightSum += _newWeight; _newPackedVirtualBalances[newIndex] = _packVirtualBalance(_virtualBalance, _rate, _packWeight(_newWeight, _newWeight, PRECISION, PRECISION)); newIndex++; } if (weightSum != PRECISION) revert Pool__WeightsDoNotAddUp(); for (uint256 t = 0; t < MAX_NUM_TOKENS; t++) { if (t == _newNumTokens) break; tokens[t] = _newTokens[t]; rateMultipliers[t] = _newRateMultipliers[t]; rateProviders[t] = _newRateProviders[t]; packedVirtualBalances[t] = _newPackedVirtualBalances[t]; } numTokens--; (uint256 vbProd, uint256 vbSum) = _calculateVirtualBalanceProdSum(); uint256 prevSupply = supply; uint256 newSupply; (newSupply, vbProd) = _calculateSupply(numTokens, vbSum, amplification_, vbProd, vbSum, true); uint256 changeInSupply = prevSupply - newSupply; if (newSupply > prevSupply) revert Pool__NewSupplyIsGreaterThanPrevSupply(); if (lpAmount_ < changeInSupply) revert Pool__LpAmountSuppliedIsLessThanChangeInSupply(); uint256 _lpSurplus = lpAmount_ - changeInSupply; if (_lpSurplus > 0) { PoolToken(tokenAddress).mint(msg.sender, _lpSurplus); } amplification = amplification_; packedPoolVirtualBalance = _packPoolVirtualBalance(vbProd, vbSum); PoolToken(tokenAddress).burn(msg.sender, lpAmount_); supply = newSupply; uint256 balance = ERC20(removedAddress).balanceOf(address(this)); SafeTransferLib.safeTransfer(removedAddress, msg.sender, balance); emit TokenRemoved(tokenIndex_, removedAddress); } /// @notice rescue tokens from this contract /// @dev cannot be used to rescue pool tokens /// @param token_ the token to be rescued /// @param receiver_ receiver of the rescued tokens function rescue(address token_, address receiver_) external onlyPoolManager { uint256 _numTokens = numTokens; for (uint256 t = 0; t < MAX_NUM_TOKENS; t++) { if (t == _numTokens) break; if (!(token_ != tokens[t])) revert Pool__CannotRescuePoolToken(); } uint256 _amount = ERC20(token_).balanceOf(address(this)); SafeTransferLib.safeTransfer(token_, receiver_, _amount); } /// @notice skim surplus of a pool token /// @param token_ index of the token /// @param receiver_ receiver of the skimmed tokens function skim(uint256 token_, address receiver_) external onlyPoolManager { if (token_ >= numTokens) revert Pool__IndexOutOfBounds(); (uint256 _virtualBalance, uint256 _rate,) = _unpackVirtualBalance(packedVirtualBalances[token_]); uint256 _adjustedExpected = (_virtualBalance * PRECISION) / _rate + 1; uint256 _expected = FixedPointMathLib.divWad(_adjustedExpected, rateMultipliers[token_]); // (_adjustedExpected * PRECISION) / rateMultiplers[token_] address _token = tokens[token_]; uint256 _actual = ERC20(_token).balanceOf(address(this)); if (_actual <= _expected) revert Pool__NoSurplus(); SafeTransferLib.safeTransfer(_token, receiver_, _actual - _expected); } /// @notice set new swap fee rate /// @param feeRate_ new swap fee rate (in 18 decimals) function setSwapFeeRate(uint256 feeRate_) external onlyPoolManager { if (feeRate_ > PRECISION / 100) revert Pool__InvalidParams(); swapFeeRate = feeRate_; emit SetSwapFeeRate(feeRate_); } /// @notice set safety weight bands, if any user operation puts the weight outside of the bands, the transaction will revert /// @param tokens_ array of indices of the tokens to set the bands for /// @param lower_ array of widths of the lower band /// @param upper_ array of widths of the upper band function setWeightBands(uint256[] calldata tokens_, uint256[] calldata lower_, uint256[] calldata upper_) external onlyPoolManager { if (!(lower_.length == tokens_.length && upper_.length == tokens_.length)) revert Pool__InvalidParams(); uint256 _numTokens = numTokens; for (uint256 t = 0; t < MAX_NUM_TOKENS; t++) { if (t == tokens_.length) break; uint256 _token = tokens_[t]; if (_token >= _numTokens) revert Pool__IndexOutOfBounds(); if (!(lower_[t] <= PRECISION && upper_[t] <= PRECISION)) { revert Pool__BandsOutOfBounds(); } (uint256 _virtualBalance, uint256 _rate, uint256 _packedWeight) = _unpackVirtualBalance(packedVirtualBalances[_token]); (uint256 _weight, uint256 _target,,) = _unpackWeight(_packedWeight); _packedWeight = _packWeight(_weight, _target, lower_[t], upper_[t]); packedVirtualBalances[_token] = _packVirtualBalance(_virtualBalance, _rate, _packedWeight); emit SetWeightBand(_token, lower_[t], upper_[t]); } } /// @notice set a rate provider for a token /// @param token_ index of the token /// @param rateProvider_ new rate provider for the token function setRateProvider(uint256 token_, address rateProvider_) external onlyPoolManager { if (token_ >= numTokens) revert Pool__IndexOutOfBounds(); rateProviders[token_] = rateProvider_; (uint256 _virtualBalanceProd, uint256 _virtualBalanceSum) = _unpackPoolVirtualBalance(packedPoolVirtualBalance); (_virtualBalanceProd, _virtualBalanceSum) = _updateRates(token_ + 1, _virtualBalanceProd, _virtualBalanceSum); packedPoolVirtualBalance = _packPoolVirtualBalance(_virtualBalanceProd, _virtualBalanceSum); emit SetRateProvider(token_, rateProvider_); } /// @notice schedule an amplification and/or weight change /// @dev effective amplification at any time is `amplification/f^n` /// @param amplification_ new amplification factor (in 18 decimals) /// @param weights_ array of the new weight for each token (in 18 decimals) /// @param duration_ duration of the ramp (in seconds) /// @param start_ ramp start time function setRamp(uint256 amplification_, uint256[] calldata weights_, uint256 duration_, uint256 start_) external onlyPoolManager { uint256 _numTokens = numTokens; if (amplification_ == 0) revert Pool__InvalidParams(); if (weights_.length != _numTokens) revert Pool__InvalidParams(); if (start_ < block.timestamp) revert Pool__InvalidParams(); bool _updated; (uint256 _virtualBalanceProd, uint256 _virtualBalanceSum) = _unpackPoolVirtualBalance(packedPoolVirtualBalance); (_virtualBalanceProd, _updated) = _updateWeights(_virtualBalanceProd); if (_updated) { uint256 _supply; (_supply, _virtualBalanceProd) = _updateSupply(supply, _virtualBalanceProd, _virtualBalanceSum); packedPoolVirtualBalance = _packPoolVirtualBalance(_virtualBalanceProd, _virtualBalanceSum); } if (rampLastTime != 0) revert Pool__RampActive(); rampLastTime = start_; rampStopTime = start_ + duration_; targetAmplification = amplification_; uint256 _total; for (uint256 t = 0; t < MAX_NUM_TOKENS; t++) { if (t == _numTokens) break; uint256 _newWeight = weights_[t]; if (_newWeight >= PRECISION) revert Pool__WeightOutOfBounds(); _total += _newWeight; (uint256 _virtualBalance, uint256 _rate, uint256 _packedWeight) = _unpackVirtualBalance(packedVirtualBalances[t]); (uint256 _weight,, uint256 _lower, uint256 _upper) = _unpackWeight(_packedWeight); _packedWeight = _packWeight(_weight, _newWeight, _lower, _upper); packedVirtualBalances[t] = _packVirtualBalance(_virtualBalance, _rate, _packedWeight); } if (_total != PRECISION) revert Pool__WeightsDoNotAddUp(); emit SetRamp(amplification_, weights_, duration_, start_); } /// @notice set the minimum time b/w ramp step /// @param rampStep_ minimum step time (in seconds) function setRampStep(uint256 rampStep_) external onlyPoolManager { if (rampStep_ == 0) revert Pool__InvalidParams(); rampStep = rampStep_; emit SetRampStep(rampStep_); } /// @notice stop an active ramp function stopRamp() external onlyPoolManager { rampLastTime = 0; rampStopTime = 0; emit StopRamp(); } /// @notice set the address that receives yield, slashings and swap fees /// @param vaultAddress_ new vault address function setVaultAddress(address vaultAddress_) external onlyPoolManager { if (vaultAddress_ == address(0)) revert Pool__InvalidParams(); vaultAddress = vaultAddress_; emit SetStaking(vaultAddress_); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* INTERNAL FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @notice update rates of specific tokens /// @dev loops through the bytes in `token_` until a zero or a number larger than the number of assets is encountered /// @dev update weights (if needed) prior to checking any rates /// @dev will recalculate supply and mint/burn to vault contract if any weight or rate has updated /// @dev will revert if any rate increases by more than 10%, unless called by management /// @param tokens_ integer where each byte represents a token index offset by one /// @param virtualBalanceProd_ product term (pi) before update /// @param virtualBalanceSum_ sum term (sigma) before update /// @return tuple with new product and sum term function _updateRates(uint256 tokens_, uint256 virtualBalanceProd_, uint256 virtualBalanceSum_) internal returns (uint256, uint256) { _checkIfPaused(); uint256 _virtualBalanceSum = virtualBalanceSum_; (uint256 _virtualBalanceProd, bool _updated) = _updateWeights(virtualBalanceProd_); uint256 _numTokens = numTokens; for (uint256 t = 0; t < MAX_NUM_TOKENS; t++) { uint256 token = (tokens_ >> FixedPointMathLib.rawMul(8, t)) & 255; if (token == 0 || token > _numTokens) { break; } token = FixedPointMathLib.rawSub(token, 1); address provider = rateProviders[token]; (uint256 _prevVirtualBalance, uint256 _prevRate, uint256 _packedWeight) = _unpackVirtualBalance(packedVirtualBalances[token]); // IRateProvider(provider).rate(address) is assumed to be 10**18 precision uint256 _rate = IRateProvider(provider).rate(tokens[token]); if (!(_rate > 0)) revert Pool__InvalidRateProvided(); // no rate change if (_rate == _prevRate) continue; // cap upward rate movement to 10% if (_rate > (_prevRate * 11) / 10 && _prevRate > 0) { _checkOwner(); } uint256 _virtualBalance; if (_prevRate > 0 && _virtualBalanceSum > 0) { // factor out old rate and factor in new rate uint256 weightTimesN = _unpackWeightTimesN(_packedWeight, _numTokens); _virtualBalanceProd = (_virtualBalanceProd * _powUp((_prevRate * PRECISION) / _rate, weightTimesN)) / PRECISION; _virtualBalance = (_prevVirtualBalance * _rate) / _prevRate; _virtualBalanceSum = _virtualBalanceSum + _virtualBalance - _prevVirtualBalance; } packedVirtualBalances[token] = _packVirtualBalance(_virtualBalance, _rate, _packedWeight); emit RateUpdate(token, _rate); } if (!_updated && _virtualBalanceProd == virtualBalanceProd_ && _virtualBalanceSum == virtualBalanceSum_) { return (_virtualBalanceProd, _virtualBalanceSum); } // recalculate supply and mint/burn token to vault address uint256 _supply; (_supply, _virtualBalanceProd) = _updateSupply(supply, _virtualBalanceProd, _virtualBalanceSum); return (_virtualBalanceProd, _virtualBalanceSum); } /// @notice apply a step in amplitude and weight ramp, if applicable /// @dev caller is reponsible for updating supply if a step has been taken /// @param vbProd_ product term(pi) before update /// @return tuple with new product term and flag indicating if a step has been taken function _updateWeights(uint256 vbProd_) internal returns (uint256, bool) { uint256 _span = rampLastTime; uint256 _duration = rampStopTime; if ( _span == 0 || _span > block.timestamp || (block.timestamp - _span < rampStep && _duration > block.timestamp) ) { // scenarios: // 1) no ramp is active // 2) ramp is scheduled for in the future // 3) weights have been updated too recently and ramp hasnt finished yet return (vbProd_, false); } if (block.timestamp < _duration) { // ramp in progress _duration -= _span; rampLastTime = block.timestamp; } else { // ramp has finished _duration = 0; rampLastTime = 0; rampStopTime = 0; } _span = block.timestamp - _span; // update amplification uint256 _current = amplification; uint256 _target = targetAmplification; if (_duration == 0) { _current = _target; } else { if (_current > _target) { _current = _current - ((_current - _target) * _span) / _duration; } else { _current = _current + ((_target - _current) * _span) / _duration; } } amplification = _current; // update weights uint256 _virtualBalance = 0; uint256 _rate = 0; uint256 _packedWeight = 0; uint256 _lower = 0; uint256 _upper = 0; for (uint256 t = 0; t < MAX_NUM_TOKENS; t++) { if (t == numTokens) break; (_virtualBalance, _rate, _packedWeight) = _unpackVirtualBalance(packedVirtualBalances[t]); (_current, _target, _lower, _upper) = _unpackWeight(_packedWeight); if (_duration == 0) { _current = _target; } else { if (_current > _target) { _current -= ((_current - _target) * _span) / _duration; } else { _current += ((_target - _current) * _span) / _duration; } } _packedWeight = _packWeight(_current, _target, _lower, _upper); packedVirtualBalances[t] = _packVirtualBalance(_virtualBalance, _rate, _packedWeight); } uint256 vbProd = 0; uint256 _supply = supply; if (_supply > 0) { vbProd = _calculateVirtualBalanceProd(_supply); } return (vbProd, true); } /// @notice calculate supply and burn or mint difference from the vault contract /// @param supply_ previous supply /// @param vbProd_ product term (pi) /// @param vbSum_ sum term (sigma) /// @return tuple with new supply and product term function _updateSupply(uint256 supply_, uint256 vbProd_, uint256 vbSum_) internal returns (uint256, uint256) { if (supply_ == 0) return (0, vbProd_); (uint256 _supply, uint256 _virtualBalanceProd) = _calculateSupply(numTokens, supply_, amplification, vbProd_, vbSum_, true); if (_supply > supply_) { PoolToken(tokenAddress).mint(vaultAddress, _supply - supply_); } else if (_supply < supply_) { PoolToken(tokenAddress).burn(vaultAddress, supply_ - _supply); } supply = _supply; return (_supply, _virtualBalanceProd); } /// @notice check whether asset is within safety band, or if previously outside, moves closer to it /// @dev reverts if conditions are not met /// @param prevRatio_ token ratio before user action /// @param ratio_ token ratio after user action /// @param packedWeight_ packed weight function _checkBands(uint256 prevRatio_, uint256 ratio_, uint256 packedWeight_) internal pure { uint256 _weight = FixedPointMathLib.rawMul(packedWeight_ & WEIGHT_MASK, WEIGHT_SCALE); // lower limit check uint256 limit = FixedPointMathLib.rawMul((packedWeight_ >> LOWER_BAND_SHIFT) & WEIGHT_MASK, WEIGHT_SCALE); if (limit > _weight) { limit = 0; } else { limit = FixedPointMathLib.rawSub(_weight, limit); } if (ratio_ < limit) { if (ratio_ <= prevRatio_) { revert Pool__RatioBelowLowerBound(); } return; } // upper limit check limit = FixedPointMathLib.min( FixedPointMathLib.rawAdd(_weight, FixedPointMathLib.rawMul(packedWeight_ >> UPPER_BAND_SHIFT, WEIGHT_SCALE)), PRECISION ); if (ratio_ > limit) { if (ratio_ >= prevRatio_) { revert Pool__RatioAboveUpperBound(); } } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* AUTH FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ function assignRole(address user_, uint256 role_) external onlyPoolOwner { _grantRoles(user_, role_); } function revokeRole(address user_, uint256 role_) external onlyPoolOwner { _removeRoles(user_, role_); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* MATH FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @notice calculate product term (pi) and sum term (sigma) /// @return tuple with product and sum term function _calculateVirtualBalanceProdSum() internal view returns (uint256, uint256) { uint256 s = 0; for (uint256 t = 0; t < MAX_NUM_TOKENS; t++) { if (t == numTokens) { break; } s = FixedPointMathLib.rawAdd(s, packedVirtualBalances[t] & VB_MASK); } uint256 p = _calculateVirtualBalanceProd(s); return (p, s); } /// @notice calculate product term (pi) /// @param supply_ supply to use in product term /// @return product term function _calculateVirtualBalanceProd(uint256 supply_) internal view returns (uint256) { uint256 _numTokens = numTokens; uint256 _p = PRECISION; for (uint256 t = 0; t < MAX_NUM_TOKENS; ++t) { if (t == _numTokens) { break; } uint256 _virtualBalance; uint256 _packedWeight; (_virtualBalance,, _packedWeight) = _unpackVirtualBalance(packedVirtualBalances[t]); uint256 _weight = _unpackWeightTimesN(_packedWeight, 1); if (!(_weight > 0 && _virtualBalance > 0)) revert Pool__InvalidParams(); // p = product((D * w_i / vb_i)^(w_i * n)) _p = FixedPointMathLib.rawDiv( FixedPointMathLib.rawMul( _p, _powDown( FixedPointMathLib.rawDiv(FixedPointMathLib.rawMul(supply_, _weight), _virtualBalance), FixedPointMathLib.rawMul(_weight, _numTokens) ) ), PRECISION ); } return _p; } /// @notice calculate supply iteratively /// @param numTokens_ number of tokens in the pool /// @param supply_ supply as used in product term /// @param amplification_ amplification factor (A f^n) /// @param virtualBalanceProd_ product term (pi) /// @param virtualBalanceSum_ sum term (sigma) /// @param up_ whether to round up /// @return tuple with new supply and product term function _calculateSupply( uint256 numTokens_, uint256 supply_, uint256 amplification_, uint256 virtualBalanceProd_, uint256 virtualBalanceSum_, bool up_ ) internal pure returns (uint256, uint256) { // D[m+1] = (A f^n sigma - D[m] pi[m] )) / (A f^n - 1) // = (_l - _s _r) / _d uint256 _l = amplification_; // left: A f^n sigma uint256 _d = _l - PRECISION; // denominator: A f*n - 1 _l = _l * virtualBalanceSum_; uint256 _s = supply_; // supply: D[m] uint256 _r = virtualBalanceProd_; // right: pi[m] for (uint256 i = 0; i < 256; i++) { if (!(_s > 0)) { revert Pool__InvalidParams(); } uint256 _sp = FixedPointMathLib.rawDiv(FixedPointMathLib.rawSub(_l, FixedPointMathLib.rawMul(_s, _r)), _d); // D[m+1] = (_l - _s * _r) / _d // update product term pi[m+1] = (D[m+1]/D[m])^n pi(m) for (uint256 t = 0; t < MAX_NUM_TOKENS; t++) { if (t == numTokens_) { break; } _r = FixedPointMathLib.rawDiv(FixedPointMathLib.rawMul(_r, _sp), _s); // _r * _sp / _s } uint256 _delta = 0; if (_sp >= _s) { _delta = FixedPointMathLib.rawSub(_sp, _s); } else { _delta = FixedPointMathLib.rawSub(_s, _sp); } if (FixedPointMathLib.rawDiv(FixedPointMathLib.rawMul(_delta, PRECISION), _s) <= MAX_POW_REL_ERR) { _delta = FixedPointMathLib.rawDiv(FixedPointMathLib.rawMul(_sp, MAX_POW_REL_ERR), PRECISION); if (up_) { _sp += _delta; } else { _sp -= _delta; } return (_sp, _r); } _s = _sp; } revert Pool__NoConvergence(); } /// @notice calculate a single token's virtual balance iteratively using newton's method /// @param wn_ token weight times number of tokens /// @param y_ starting value /// @param supply_ supply /// @param amplification_ amplification factor `A f^n` /// @param vbProd_ intermediary product term (pi~), pi with previous balances factored out and new balance factored in /// @param vbSum_ intermediary sum term (sigma~), sigma with previous balances subtracted and new balance added /// @return new token virtual balance function _calculateVirtualBalance( uint256 wn_, uint256 y_, uint256 supply_, uint256 amplification_, uint256 vbProd_, uint256 vbSum_ ) internal pure returns (uint256) { // y = x_j, sum' = sum(x_i, i != j), prod' = D^n w_j^(v_j) prod((w_i/x_i)^v_i, i != j) // Iteratively find root of g(y) using Newton's method // g(y) = y^(v_j + 1) + (sum' + (1 / (A f^n) - 1) D) y^(v_j) - D prod' / (A f^n) // = y^(v_j + 1) + b y^(v_j) - c // y[n+1] = y[n] - g(y[n])/g'(y[n]) // = (y[n]^2 + b (1 - q) y[n] + c q y[n]^(1 - v_j)) / ((q + 1) y[n] + b)) uint256 b = (supply_ * PRECISION) / amplification_; // b' = sigma + D / (A f^n) uint256 c = (vbProd_ * b) / PRECISION; // c' = D / (A f^n) * pi b += vbSum_; uint256 q = (PRECISION * PRECISION) / wn_; // q = 1 / v_i = 1 / (w_i n) uint256 y = y_; for (uint256 i = 0; i < 256; i++) { if (!(y > 0)) revert Pool__InvalidParams(); uint256 yp = (y + b + supply_ * q / PRECISION + c * q / _powUp(y, wn_) - b * q / PRECISION - supply_) * y / (q * y / PRECISION + y + b - supply_); uint256 delta = 0; if (yp >= y) { delta = yp - y; } else { delta = y - yp; } if (FixedPointMathLib.rawDiv(FixedPointMathLib.rawMul(delta, PRECISION), y) <= MAX_POW_REL_ERR) { yp += FixedPointMathLib.rawDiv(FixedPointMathLib.rawMul(yp, MAX_POW_REL_ERR), PRECISION); return yp; } y = yp; } revert Pool__NoConvergence(); } /// @notice pack virtual balance of a token along with other related variables /// @param virtualBalance_ virtual balance of a token /// @param rate_ token rate /// @param packedWeight_ packed weight of a token /// @return packed variable function _packVirtualBalance(uint256 virtualBalance_, uint256 rate_, uint256 packedWeight_) internal pure returns (uint256) { if (virtualBalance_ > VB_MASK || rate_ > RATE_MASK) { revert Pool__InvalidParams(); } return virtualBalance_ | (rate_ << RATE_SHIFT) | (packedWeight_ << PACKED_WEIGHT_SHIFT); } /// @notice unpack variable to it's components /// @param packed_ packed variable /// @return tuple with virtual balance, rate and packed weight function _unpackVirtualBalance(uint256 packed_) internal pure returns (uint256, uint256, uint256) { return (packed_ & VB_MASK, (packed_ >> RATE_SHIFT) & RATE_MASK, packed_ >> PACKED_WEIGHT_SHIFT); } /// @notice pack weight with target and bands /// @param weight_ weight with 18 decimals /// @param target_ target weight with 18 decimals /// @param lower_ lower band with 18 decimals, allowed distance from weight in negative direction /// @param upper_ upper band with 18 decimal, allowed distance from weight in positive direction function _packWeight(uint256 weight_, uint256 target_, uint256 lower_, uint256 upper_) internal pure returns (uint256) { return ( (FixedPointMathLib.rawDiv(weight_, WEIGHT_SCALE)) | (FixedPointMathLib.rawDiv(target_, WEIGHT_SCALE) << TARGET_WEIGHT_SHIFT) | (FixedPointMathLib.rawDiv(lower_, WEIGHT_SCALE) << LOWER_BAND_SHIFT) | (FixedPointMathLib.rawDiv(upper_, WEIGHT_SCALE) << UPPER_BAND_SHIFT) ); } /// @notice unpack weight to its components /// @param packed_ packed weight /// @return tuple with weight, target weight, lower band and upper band (all in 18 decimals) function _unpackWeight(uint256 packed_) internal pure returns (uint256, uint256, uint256, uint256) { return ( FixedPointMathLib.rawMul(packed_ & WEIGHT_MASK, WEIGHT_SCALE), FixedPointMathLib.rawMul((packed_ >> TARGET_WEIGHT_SHIFT) & WEIGHT_MASK, WEIGHT_SCALE), FixedPointMathLib.rawMul((packed_ >> LOWER_BAND_SHIFT) & WEIGHT_MASK, WEIGHT_SCALE), FixedPointMathLib.rawMul(packed_ >> UPPER_BAND_SHIFT, WEIGHT_SCALE) ); } /// @notice unpack weight and multiply by number of tokens /// @param packed_ packed weight /// @param numTokens_ number of tokens /// @return weight multiplied by number of tokens (18 decimals) function _unpackWeightTimesN(uint256 packed_, uint256 numTokens_) internal pure returns (uint256) { return FixedPointMathLib.rawMul(FixedPointMathLib.rawMul(packed_ & WEIGHT_MASK, WEIGHT_SCALE), numTokens_); } /// @notice pack pool product and sum term /// @param prod_ Product term (pi) /// @param sum_ Sum term (sigma) /// @return packed term function _packPoolVirtualBalance(uint256 prod_, uint256 sum_) internal pure returns (uint256) { if (prod_ <= POOL_VB_MASK && sum_ <= POOL_VB_MASK) { return prod_ | (sum_ << POOL_VB_SHIFT); } revert Pool__InvalidParams(); } /// @notice unpack pool product and sum term /// @param packed_ packed terms /// @return tuple with pool product term (pi) and pool sum term (sigma) function _unpackPoolVirtualBalance(uint256 packed_) internal pure returns (uint256, uint256) { return (packed_ & POOL_VB_MASK, packed_ >> POOL_VB_SHIFT); } function _checkIfPaused() internal view { if (paused == true) { revert Pool__Paused(); } } function _powUp(uint256 x, uint256 y) internal pure returns (uint256) { uint256 p = LogExpMath.pow(x, y); // uint256 p = FixedPointMathLib.rpow(x, y, 1); if (p == 0) return 0; // p + (p * MAX_POW_REL_ERR - 1) / PRECISION + 1 return FixedPointMathLib.rawAdd( FixedPointMathLib.rawAdd( p, FixedPointMathLib.rawDiv( FixedPointMathLib.rawSub(FixedPointMathLib.rawMul(p, MAX_POW_REL_ERR), 1), PRECISION ) ), 1 ); } function _powDown(uint256 x, uint256 y) internal pure returns (uint256) { uint256 p = LogExpMath.pow(x, y); // uint256 p = FixedPointMathLib.rpow(x, y, 1); if (p == 0) return 0; // (p * MAX_POW_REL_ERR - 1) / PRECISION + 1 uint256 e = FixedPointMathLib.rawAdd( FixedPointMathLib.rawDiv( FixedPointMathLib.rawSub(FixedPointMathLib.rawMul(p, MAX_POW_REL_ERR), 1), PRECISION ), 1 ); if (p < e) return 0; return FixedPointMathLib.rawSub(p, e); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; import {Ownable} from "./Ownable.sol"; /// @notice Simple single owner and multiroles authorization mixin. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/auth/OwnableRoles.sol) /// /// @dev Note: /// This implementation does NOT auto-initialize the owner to `msg.sender`. /// You MUST call the `_initializeOwner` in the constructor / initializer. /// /// While the ownable portion follows /// [EIP-173](https://eips.ethereum.org/EIPS/eip-173) for compatibility, /// the nomenclature for the 2-step ownership handover may be unique to this codebase. abstract contract OwnableRoles is Ownable { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* EVENTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The `user`'s roles is updated to `roles`. /// Each bit of `roles` represents whether the role is set. event RolesUpdated(address indexed user, uint256 indexed roles); /// @dev `keccak256(bytes("RolesUpdated(address,uint256)"))`. uint256 private constant _ROLES_UPDATED_EVENT_SIGNATURE = 0x715ad5ce61fc9595c7b415289d59cf203f23a94fa06f04af7e489a0a76e1fe26; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* STORAGE */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The role slot of `user` is given by: /// ``` /// mstore(0x00, or(shl(96, user), _ROLE_SLOT_SEED)) /// let roleSlot := keccak256(0x00, 0x20) /// ``` /// This automatically ignores the upper bits of the `user` in case /// they are not clean, as well as keep the `keccak256` under 32-bytes. /// /// Note: This is equivalent to `uint32(bytes4(keccak256("_OWNER_SLOT_NOT")))`. uint256 private constant _ROLE_SLOT_SEED = 0x8b78c6d8; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* INTERNAL FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Overwrite the roles directly without authorization guard. function _setRoles(address user, uint256 roles) internal virtual { /// @solidity memory-safe-assembly assembly { mstore(0x0c, _ROLE_SLOT_SEED) mstore(0x00, user) // Store the new value. sstore(keccak256(0x0c, 0x20), roles) // Emit the {RolesUpdated} event. log3(0, 0, _ROLES_UPDATED_EVENT_SIGNATURE, shr(96, mload(0x0c)), roles) } } /// @dev Updates the roles directly without authorization guard. /// If `on` is true, each set bit of `roles` will be turned on, /// otherwise, each set bit of `roles` will be turned off. function _updateRoles(address user, uint256 roles, bool on) internal virtual { /// @solidity memory-safe-assembly assembly { mstore(0x0c, _ROLE_SLOT_SEED) mstore(0x00, user) let roleSlot := keccak256(0x0c, 0x20) // Load the current value. let current := sload(roleSlot) // Compute the updated roles if `on` is true. let updated := or(current, roles) // Compute the updated roles if `on` is false. // Use `and` to compute the intersection of `current` and `roles`, // `xor` it with `current` to flip the bits in the intersection. if iszero(on) { updated := xor(current, and(current, roles)) } // Then, store the new value. sstore(roleSlot, updated) // Emit the {RolesUpdated} event. log3(0, 0, _ROLES_UPDATED_EVENT_SIGNATURE, shr(96, mload(0x0c)), updated) } } /// @dev Grants the roles directly without authorization guard. /// Each bit of `roles` represents the role to turn on. function _grantRoles(address user, uint256 roles) internal virtual { _updateRoles(user, roles, true); } /// @dev Removes the roles directly without authorization guard. /// Each bit of `roles` represents the role to turn off. function _removeRoles(address user, uint256 roles) internal virtual { _updateRoles(user, roles, false); } /// @dev Throws if the sender does not have any of the `roles`. function _checkRoles(uint256 roles) internal view virtual { /// @solidity memory-safe-assembly assembly { // Compute the role slot. mstore(0x0c, _ROLE_SLOT_SEED) mstore(0x00, caller()) // Load the stored value, and if the `and` intersection // of the value and `roles` is zero, revert. if iszero(and(sload(keccak256(0x0c, 0x20)), roles)) { mstore(0x00, 0x82b42900) // `Unauthorized()`. revert(0x1c, 0x04) } } } /// @dev Throws if the sender is not the owner, /// and does not have any of the `roles`. /// Checks for ownership first, then lazily checks for roles. function _checkOwnerOrRoles(uint256 roles) internal view virtual { /// @solidity memory-safe-assembly assembly { // If the caller is not the stored owner. // Note: `_ROLE_SLOT_SEED` is equal to `_OWNER_SLOT_NOT`. if iszero(eq(caller(), sload(not(_ROLE_SLOT_SEED)))) { // Compute the role slot. mstore(0x0c, _ROLE_SLOT_SEED) mstore(0x00, caller()) // Load the stored value, and if the `and` intersection // of the value and `roles` is zero, revert. if iszero(and(sload(keccak256(0x0c, 0x20)), roles)) { mstore(0x00, 0x82b42900) // `Unauthorized()`. revert(0x1c, 0x04) } } } } /// @dev Throws if the sender does not have any of the `roles`, /// and is not the owner. /// Checks for roles first, then lazily checks for ownership. function _checkRolesOrOwner(uint256 roles) internal view virtual { /// @solidity memory-safe-assembly assembly { // Compute the role slot. mstore(0x0c, _ROLE_SLOT_SEED) mstore(0x00, caller()) // Load the stored value, and if the `and` intersection // of the value and `roles` is zero, revert. if iszero(and(sload(keccak256(0x0c, 0x20)), roles)) { // If the caller is not the stored owner. // Note: `_ROLE_SLOT_SEED` is equal to `_OWNER_SLOT_NOT`. if iszero(eq(caller(), sload(not(_ROLE_SLOT_SEED)))) { mstore(0x00, 0x82b42900) // `Unauthorized()`. revert(0x1c, 0x04) } } } } /// @dev Convenience function to return a `roles` bitmap from an array of `ordinals`. /// This is meant for frontends like Etherscan, and is therefore not fully optimized. /// Not recommended to be called on-chain. /// Made internal to conserve bytecode. Wrap it in a public function if needed. function _rolesFromOrdinals(uint8[] memory ordinals) internal pure returns (uint256 roles) { /// @solidity memory-safe-assembly assembly { for { let i := shl(5, mload(ordinals)) } i { i := sub(i, 0x20) } { // We don't need to mask the values of `ordinals`, as Solidity // cleans dirty upper bits when storing variables into memory. roles := or(shl(mload(add(ordinals, i)), 1), roles) } } } /// @dev Convenience function to return an array of `ordinals` from the `roles` bitmap. /// This is meant for frontends like Etherscan, and is therefore not fully optimized. /// Not recommended to be called on-chain. /// Made internal to conserve bytecode. Wrap it in a public function if needed. function _ordinalsFromRoles(uint256 roles) internal pure returns (uint8[] memory ordinals) { /// @solidity memory-safe-assembly assembly { // Grab the pointer to the free memory. ordinals := mload(0x40) let ptr := add(ordinals, 0x20) let o := 0 // The absence of lookup tables, De Bruijn, etc., here is intentional for // smaller bytecode, as this function is not meant to be called on-chain. for { let t := roles } 1 {} { mstore(ptr, o) // `shr` 5 is equivalent to multiplying by 0x20. // Push back into the ordinals array if the bit is set. ptr := add(ptr, shl(5, and(t, 1))) o := add(o, 1) t := shr(o, roles) if iszero(t) { break } } // Store the length of `ordinals`. mstore(ordinals, shr(5, sub(ptr, add(ordinals, 0x20)))) // Allocate the memory. mstore(0x40, ptr) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* PUBLIC UPDATE FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Allows the owner to grant `user` `roles`. /// If the `user` already has a role, then it will be an no-op for the role. function grantRoles(address user, uint256 roles) public payable virtual onlyOwner { _grantRoles(user, roles); } /// @dev Allows the owner to remove `user` `roles`. /// If the `user` does not have a role, then it will be an no-op for the role. function revokeRoles(address user, uint256 roles) public payable virtual onlyOwner { _removeRoles(user, roles); } /// @dev Allow the caller to remove their own roles. /// If the caller does not have a role, then it will be an no-op for the role. function renounceRoles(uint256 roles) public payable virtual { _removeRoles(msg.sender, roles); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* PUBLIC READ FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the roles of `user`. function rolesOf(address user) public view virtual returns (uint256 roles) { /// @solidity memory-safe-assembly assembly { // Compute the role slot. mstore(0x0c, _ROLE_SLOT_SEED) mstore(0x00, user) // Load the stored value. roles := sload(keccak256(0x0c, 0x20)) } } /// @dev Returns whether `user` has any of `roles`. function hasAnyRole(address user, uint256 roles) public view virtual returns (bool) { return rolesOf(user) & roles != 0; } /// @dev Returns whether `user` has all of `roles`. function hasAllRoles(address user, uint256 roles) public view virtual returns (bool) { return rolesOf(user) & roles == roles; } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* MODIFIERS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Marks a function as only callable by an account with `roles`. modifier onlyRoles(uint256 roles) virtual { _checkRoles(roles); _; } /// @dev Marks a function as only callable by the owner or by an account /// with `roles`. Checks for ownership first, then lazily checks for roles. modifier onlyOwnerOrRoles(uint256 roles) virtual { _checkOwnerOrRoles(roles); _; } /// @dev Marks a function as only callable by an account with `roles` /// or the owner. Checks for roles first, then lazily checks for ownership. modifier onlyRolesOrOwner(uint256 roles) virtual { _checkRolesOrOwner(roles); _; } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ROLE CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // IYKYK uint256 internal constant _ROLE_0 = 1 << 0; uint256 internal constant _ROLE_1 = 1 << 1; uint256 internal constant _ROLE_2 = 1 << 2; uint256 internal constant _ROLE_3 = 1 << 3; uint256 internal constant _ROLE_4 = 1 << 4; uint256 internal constant _ROLE_5 = 1 << 5; uint256 internal constant _ROLE_6 = 1 << 6; uint256 internal constant _ROLE_7 = 1 << 7; uint256 internal constant _ROLE_8 = 1 << 8; uint256 internal constant _ROLE_9 = 1 << 9; uint256 internal constant _ROLE_10 = 1 << 10; uint256 internal constant _ROLE_11 = 1 << 11; uint256 internal constant _ROLE_12 = 1 << 12; uint256 internal constant _ROLE_13 = 1 << 13; uint256 internal constant _ROLE_14 = 1 << 14; uint256 internal constant _ROLE_15 = 1 << 15; uint256 internal constant _ROLE_16 = 1 << 16; uint256 internal constant _ROLE_17 = 1 << 17; uint256 internal constant _ROLE_18 = 1 << 18; uint256 internal constant _ROLE_19 = 1 << 19; uint256 internal constant _ROLE_20 = 1 << 20; uint256 internal constant _ROLE_21 = 1 << 21; uint256 internal constant _ROLE_22 = 1 << 22; uint256 internal constant _ROLE_23 = 1 << 23; uint256 internal constant _ROLE_24 = 1 << 24; uint256 internal constant _ROLE_25 = 1 << 25; uint256 internal constant _ROLE_26 = 1 << 26; uint256 internal constant _ROLE_27 = 1 << 27; uint256 internal constant _ROLE_28 = 1 << 28; uint256 internal constant _ROLE_29 = 1 << 29; uint256 internal constant _ROLE_30 = 1 << 30; uint256 internal constant _ROLE_31 = 1 << 31; uint256 internal constant _ROLE_32 = 1 << 32; uint256 internal constant _ROLE_33 = 1 << 33; uint256 internal constant _ROLE_34 = 1 << 34; uint256 internal constant _ROLE_35 = 1 << 35; uint256 internal constant _ROLE_36 = 1 << 36; uint256 internal constant _ROLE_37 = 1 << 37; uint256 internal constant _ROLE_38 = 1 << 38; uint256 internal constant _ROLE_39 = 1 << 39; uint256 internal constant _ROLE_40 = 1 << 40; uint256 internal constant _ROLE_41 = 1 << 41; uint256 internal constant _ROLE_42 = 1 << 42; uint256 internal constant _ROLE_43 = 1 << 43; uint256 internal constant _ROLE_44 = 1 << 44; uint256 internal constant _ROLE_45 = 1 << 45; uint256 internal constant _ROLE_46 = 1 << 46; uint256 internal constant _ROLE_47 = 1 << 47; uint256 internal constant _ROLE_48 = 1 << 48; uint256 internal constant _ROLE_49 = 1 << 49; uint256 internal constant _ROLE_50 = 1 << 50; uint256 internal constant _ROLE_51 = 1 << 51; uint256 internal constant _ROLE_52 = 1 << 52; uint256 internal constant _ROLE_53 = 1 << 53; uint256 internal constant _ROLE_54 = 1 << 54; uint256 internal constant _ROLE_55 = 1 << 55; uint256 internal constant _ROLE_56 = 1 << 56; uint256 internal constant _ROLE_57 = 1 << 57; uint256 internal constant _ROLE_58 = 1 << 58; uint256 internal constant _ROLE_59 = 1 << 59; uint256 internal constant _ROLE_60 = 1 << 60; uint256 internal constant _ROLE_61 = 1 << 61; uint256 internal constant _ROLE_62 = 1 << 62; uint256 internal constant _ROLE_63 = 1 << 63; uint256 internal constant _ROLE_64 = 1 << 64; uint256 internal constant _ROLE_65 = 1 << 65; uint256 internal constant _ROLE_66 = 1 << 66; uint256 internal constant _ROLE_67 = 1 << 67; uint256 internal constant _ROLE_68 = 1 << 68; uint256 internal constant _ROLE_69 = 1 << 69; uint256 internal constant _ROLE_70 = 1 << 70; uint256 internal constant _ROLE_71 = 1 << 71; uint256 internal constant _ROLE_72 = 1 << 72; uint256 internal constant _ROLE_73 = 1 << 73; uint256 internal constant _ROLE_74 = 1 << 74; uint256 internal constant _ROLE_75 = 1 << 75; uint256 internal constant _ROLE_76 = 1 << 76; uint256 internal constant _ROLE_77 = 1 << 77; uint256 internal constant _ROLE_78 = 1 << 78; uint256 internal constant _ROLE_79 = 1 << 79; uint256 internal constant _ROLE_80 = 1 << 80; uint256 internal constant _ROLE_81 = 1 << 81; uint256 internal constant _ROLE_82 = 1 << 82; uint256 internal constant _ROLE_83 = 1 << 83; uint256 internal constant _ROLE_84 = 1 << 84; uint256 internal constant _ROLE_85 = 1 << 85; uint256 internal constant _ROLE_86 = 1 << 86; uint256 internal constant _ROLE_87 = 1 << 87; uint256 internal constant _ROLE_88 = 1 << 88; uint256 internal constant _ROLE_89 = 1 << 89; uint256 internal constant _ROLE_90 = 1 << 90; uint256 internal constant _ROLE_91 = 1 << 91; uint256 internal constant _ROLE_92 = 1 << 92; uint256 internal constant _ROLE_93 = 1 << 93; uint256 internal constant _ROLE_94 = 1 << 94; uint256 internal constant _ROLE_95 = 1 << 95; uint256 internal constant _ROLE_96 = 1 << 96; uint256 internal constant _ROLE_97 = 1 << 97; uint256 internal constant _ROLE_98 = 1 << 98; uint256 internal constant _ROLE_99 = 1 << 99; uint256 internal constant _ROLE_100 = 1 << 100; uint256 internal constant _ROLE_101 = 1 << 101; uint256 internal constant _ROLE_102 = 1 << 102; uint256 internal constant _ROLE_103 = 1 << 103; uint256 internal constant _ROLE_104 = 1 << 104; uint256 internal constant _ROLE_105 = 1 << 105; uint256 internal constant _ROLE_106 = 1 << 106; uint256 internal constant _ROLE_107 = 1 << 107; uint256 internal constant _ROLE_108 = 1 << 108; uint256 internal constant _ROLE_109 = 1 << 109; uint256 internal constant _ROLE_110 = 1 << 110; uint256 internal constant _ROLE_111 = 1 << 111; uint256 internal constant _ROLE_112 = 1 << 112; uint256 internal constant _ROLE_113 = 1 << 113; uint256 internal constant _ROLE_114 = 1 << 114; uint256 internal constant _ROLE_115 = 1 << 115; uint256 internal constant _ROLE_116 = 1 << 116; uint256 internal constant _ROLE_117 = 1 << 117; uint256 internal constant _ROLE_118 = 1 << 118; uint256 internal constant _ROLE_119 = 1 << 119; uint256 internal constant _ROLE_120 = 1 << 120; uint256 internal constant _ROLE_121 = 1 << 121; uint256 internal constant _ROLE_122 = 1 << 122; uint256 internal constant _ROLE_123 = 1 << 123; uint256 internal constant _ROLE_124 = 1 << 124; uint256 internal constant _ROLE_125 = 1 << 125; uint256 internal constant _ROLE_126 = 1 << 126; uint256 internal constant _ROLE_127 = 1 << 127; uint256 internal constant _ROLE_128 = 1 << 128; uint256 internal constant _ROLE_129 = 1 << 129; uint256 internal constant _ROLE_130 = 1 << 130; uint256 internal constant _ROLE_131 = 1 << 131; uint256 internal constant _ROLE_132 = 1 << 132; uint256 internal constant _ROLE_133 = 1 << 133; uint256 internal constant _ROLE_134 = 1 << 134; uint256 internal constant _ROLE_135 = 1 << 135; uint256 internal constant _ROLE_136 = 1 << 136; uint256 internal constant _ROLE_137 = 1 << 137; uint256 internal constant _ROLE_138 = 1 << 138; uint256 internal constant _ROLE_139 = 1 << 139; uint256 internal constant _ROLE_140 = 1 << 140; uint256 internal constant _ROLE_141 = 1 << 141; uint256 internal constant _ROLE_142 = 1 << 142; uint256 internal constant _ROLE_143 = 1 << 143; uint256 internal constant _ROLE_144 = 1 << 144; uint256 internal constant _ROLE_145 = 1 << 145; uint256 internal constant _ROLE_146 = 1 << 146; uint256 internal constant _ROLE_147 = 1 << 147; uint256 internal constant _ROLE_148 = 1 << 148; uint256 internal constant _ROLE_149 = 1 << 149; uint256 internal constant _ROLE_150 = 1 << 150; uint256 internal constant _ROLE_151 = 1 << 151; uint256 internal constant _ROLE_152 = 1 << 152; uint256 internal constant _ROLE_153 = 1 << 153; uint256 internal constant _ROLE_154 = 1 << 154; uint256 internal constant _ROLE_155 = 1 << 155; uint256 internal constant _ROLE_156 = 1 << 156; uint256 internal constant _ROLE_157 = 1 << 157; uint256 internal constant _ROLE_158 = 1 << 158; uint256 internal constant _ROLE_159 = 1 << 159; uint256 internal constant _ROLE_160 = 1 << 160; uint256 internal constant _ROLE_161 = 1 << 161; uint256 internal constant _ROLE_162 = 1 << 162; uint256 internal constant _ROLE_163 = 1 << 163; uint256 internal constant _ROLE_164 = 1 << 164; uint256 internal constant _ROLE_165 = 1 << 165; uint256 internal constant _ROLE_166 = 1 << 166; uint256 internal constant _ROLE_167 = 1 << 167; uint256 internal constant _ROLE_168 = 1 << 168; uint256 internal constant _ROLE_169 = 1 << 169; uint256 internal constant _ROLE_170 = 1 << 170; uint256 internal constant _ROLE_171 = 1 << 171; uint256 internal constant _ROLE_172 = 1 << 172; uint256 internal constant _ROLE_173 = 1 << 173; uint256 internal constant _ROLE_174 = 1 << 174; uint256 internal constant _ROLE_175 = 1 << 175; uint256 internal constant _ROLE_176 = 1 << 176; uint256 internal constant _ROLE_177 = 1 << 177; uint256 internal constant _ROLE_178 = 1 << 178; uint256 internal constant _ROLE_179 = 1 << 179; uint256 internal constant _ROLE_180 = 1 << 180; uint256 internal constant _ROLE_181 = 1 << 181; uint256 internal constant _ROLE_182 = 1 << 182; uint256 internal constant _ROLE_183 = 1 << 183; uint256 internal constant _ROLE_184 = 1 << 184; uint256 internal constant _ROLE_185 = 1 << 185; uint256 internal constant _ROLE_186 = 1 << 186; uint256 internal constant _ROLE_187 = 1 << 187; uint256 internal constant _ROLE_188 = 1 << 188; uint256 internal constant _ROLE_189 = 1 << 189; uint256 internal constant _ROLE_190 = 1 << 190; uint256 internal constant _ROLE_191 = 1 << 191; uint256 internal constant _ROLE_192 = 1 << 192; uint256 internal constant _ROLE_193 = 1 << 193; uint256 internal constant _ROLE_194 = 1 << 194; uint256 internal constant _ROLE_195 = 1 << 195; uint256 internal constant _ROLE_196 = 1 << 196; uint256 internal constant _ROLE_197 = 1 << 197; uint256 internal constant _ROLE_198 = 1 << 198; uint256 internal constant _ROLE_199 = 1 << 199; uint256 internal constant _ROLE_200 = 1 << 200; uint256 internal constant _ROLE_201 = 1 << 201; uint256 internal constant _ROLE_202 = 1 << 202; uint256 internal constant _ROLE_203 = 1 << 203; uint256 internal constant _ROLE_204 = 1 << 204; uint256 internal constant _ROLE_205 = 1 << 205; uint256 internal constant _ROLE_206 = 1 << 206; uint256 internal constant _ROLE_207 = 1 << 207; uint256 internal constant _ROLE_208 = 1 << 208; uint256 internal constant _ROLE_209 = 1 << 209; uint256 internal constant _ROLE_210 = 1 << 210; uint256 internal constant _ROLE_211 = 1 << 211; uint256 internal constant _ROLE_212 = 1 << 212; uint256 internal constant _ROLE_213 = 1 << 213; uint256 internal constant _ROLE_214 = 1 << 214; uint256 internal constant _ROLE_215 = 1 << 215; uint256 internal constant _ROLE_216 = 1 << 216; uint256 internal constant _ROLE_217 = 1 << 217; uint256 internal constant _ROLE_218 = 1 << 218; uint256 internal constant _ROLE_219 = 1 << 219; uint256 internal constant _ROLE_220 = 1 << 220; uint256 internal constant _ROLE_221 = 1 << 221; uint256 internal constant _ROLE_222 = 1 << 222; uint256 internal constant _ROLE_223 = 1 << 223; uint256 internal constant _ROLE_224 = 1 << 224; uint256 internal constant _ROLE_225 = 1 << 225; uint256 internal constant _ROLE_226 = 1 << 226; uint256 internal constant _ROLE_227 = 1 << 227; uint256 internal constant _ROLE_228 = 1 << 228; uint256 internal constant _ROLE_229 = 1 << 229; uint256 internal constant _ROLE_230 = 1 << 230; uint256 internal constant _ROLE_231 = 1 << 231; uint256 internal constant _ROLE_232 = 1 << 232; uint256 internal constant _ROLE_233 = 1 << 233; uint256 internal constant _ROLE_234 = 1 << 234; uint256 internal constant _ROLE_235 = 1 << 235; uint256 internal constant _ROLE_236 = 1 << 236; uint256 internal constant _ROLE_237 = 1 << 237; uint256 internal constant _ROLE_238 = 1 << 238; uint256 internal constant _ROLE_239 = 1 << 239; uint256 internal constant _ROLE_240 = 1 << 240; uint256 internal constant _ROLE_241 = 1 << 241; uint256 internal constant _ROLE_242 = 1 << 242; uint256 internal constant _ROLE_243 = 1 << 243; uint256 internal constant _ROLE_244 = 1 << 244; uint256 internal constant _ROLE_245 = 1 << 245; uint256 internal constant _ROLE_246 = 1 << 246; uint256 internal constant _ROLE_247 = 1 << 247; uint256 internal constant _ROLE_248 = 1 << 248; uint256 internal constant _ROLE_249 = 1 << 249; uint256 internal constant _ROLE_250 = 1 << 250; uint256 internal constant _ROLE_251 = 1 << 251; uint256 internal constant _ROLE_252 = 1 << 252; uint256 internal constant _ROLE_253 = 1 << 253; uint256 internal constant _ROLE_254 = 1 << 254; uint256 internal constant _ROLE_255 = 1 << 255; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Simple ERC20 + EIP-2612 implementation. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/tokens/ERC20.sol) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol) /// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol) /// /// @dev Note: /// - The ERC20 standard allows minting and transferring to and from the zero address, /// minting and transferring zero tokens, as well as self-approvals. /// For performance, this implementation WILL NOT revert for such actions. /// Please add any checks with overrides if desired. /// - The `permit` function uses the ecrecover precompile (0x1). /// /// If you are overriding: /// - NEVER violate the ERC20 invariant: /// the total sum of all balances must be equal to `totalSupply()`. /// - Check that the overridden function is actually used in the function you want to /// change the behavior of. Much of the code has been manually inlined for performance. abstract contract ERC20 { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The total supply has overflowed. error TotalSupplyOverflow(); /// @dev The allowance has overflowed. error AllowanceOverflow(); /// @dev The allowance has underflowed. error AllowanceUnderflow(); /// @dev Insufficient balance. error InsufficientBalance(); /// @dev Insufficient allowance. error InsufficientAllowance(); /// @dev The permit is invalid. error InvalidPermit(); /// @dev The permit has expired. error PermitExpired(); /// @dev The allowance of Permit2 is fixed at infinity. error Permit2AllowanceIsFixedAtInfinity(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* EVENTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Emitted when `amount` tokens is transferred from `from` to `to`. event Transfer(address indexed from, address indexed to, uint256 amount); /// @dev Emitted when `amount` tokens is approved by `owner` to be used by `spender`. event Approval(address indexed owner, address indexed spender, uint256 amount); /// @dev `keccak256(bytes("Transfer(address,address,uint256)"))`. uint256 private constant _TRANSFER_EVENT_SIGNATURE = 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef; /// @dev `keccak256(bytes("Approval(address,address,uint256)"))`. uint256 private constant _APPROVAL_EVENT_SIGNATURE = 0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* STORAGE */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The storage slot for the total supply. uint256 private constant _TOTAL_SUPPLY_SLOT = 0x05345cdf77eb68f44c; /// @dev The balance slot of `owner` is given by: /// ``` /// mstore(0x0c, _BALANCE_SLOT_SEED) /// mstore(0x00, owner) /// let balanceSlot := keccak256(0x0c, 0x20) /// ``` uint256 private constant _BALANCE_SLOT_SEED = 0x87a211a2; /// @dev The allowance slot of (`owner`, `spender`) is given by: /// ``` /// mstore(0x20, spender) /// mstore(0x0c, _ALLOWANCE_SLOT_SEED) /// mstore(0x00, owner) /// let allowanceSlot := keccak256(0x0c, 0x34) /// ``` uint256 private constant _ALLOWANCE_SLOT_SEED = 0x7f5e9f20; /// @dev The nonce slot of `owner` is given by: /// ``` /// mstore(0x0c, _NONCES_SLOT_SEED) /// mstore(0x00, owner) /// let nonceSlot := keccak256(0x0c, 0x20) /// ``` uint256 private constant _NONCES_SLOT_SEED = 0x38377508; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev `(_NONCES_SLOT_SEED << 16) | 0x1901`. uint256 private constant _NONCES_SLOT_SEED_WITH_SIGNATURE_PREFIX = 0x383775081901; /// @dev `keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")`. bytes32 private constant _DOMAIN_TYPEHASH = 0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f; /// @dev `keccak256("1")`. /// If you need to use a different version, override `_versionHash`. bytes32 private constant _DEFAULT_VERSION_HASH = 0xc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6; /// @dev `keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)")`. bytes32 private constant _PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9; /// @dev The canonical Permit2 address. /// For signature-based allowance granting for single transaction ERC20 `transferFrom`. /// To enable, override `_givePermit2InfiniteAllowance()`. /// [Github](https://github.com/Uniswap/permit2) /// [Etherscan](https://etherscan.io/address/0x000000000022D473030F116dDEE9F6B43aC78BA3) address internal constant _PERMIT2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ERC20 METADATA */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the name of the token. function name() public view virtual returns (string memory); /// @dev Returns the symbol of the token. function symbol() public view virtual returns (string memory); /// @dev Returns the decimals places of the token. function decimals() public view virtual returns (uint8) { return 18; } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ERC20 */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the amount of tokens in existence. function totalSupply() public view virtual returns (uint256 result) { /// @solidity memory-safe-assembly assembly { result := sload(_TOTAL_SUPPLY_SLOT) } } /// @dev Returns the amount of tokens owned by `owner`. function balanceOf(address owner) public view virtual returns (uint256 result) { /// @solidity memory-safe-assembly assembly { mstore(0x0c, _BALANCE_SLOT_SEED) mstore(0x00, owner) result := sload(keccak256(0x0c, 0x20)) } } /// @dev Returns the amount of tokens that `spender` can spend on behalf of `owner`. function allowance(address owner, address spender) public view virtual returns (uint256 result) { if (_givePermit2InfiniteAllowance()) { if (spender == _PERMIT2) return type(uint256).max; } /// @solidity memory-safe-assembly assembly { mstore(0x20, spender) mstore(0x0c, _ALLOWANCE_SLOT_SEED) mstore(0x00, owner) result := sload(keccak256(0x0c, 0x34)) } } /// @dev Sets `amount` as the allowance of `spender` over the caller's tokens. /// /// Emits a {Approval} event. function approve(address spender, uint256 amount) public virtual returns (bool) { if (_givePermit2InfiniteAllowance()) { /// @solidity memory-safe-assembly assembly { // If `spender == _PERMIT2 && amount != type(uint256).max`. if iszero(or(xor(shr(96, shl(96, spender)), _PERMIT2), iszero(not(amount)))) { mstore(0x00, 0x3f68539a) // `Permit2AllowanceIsFixedAtInfinity()`. revert(0x1c, 0x04) } } } /// @solidity memory-safe-assembly assembly { // Compute the allowance slot and store the amount. mstore(0x20, spender) mstore(0x0c, _ALLOWANCE_SLOT_SEED) mstore(0x00, caller()) sstore(keccak256(0x0c, 0x34), amount) // Emit the {Approval} event. mstore(0x00, amount) log3(0x00, 0x20, _APPROVAL_EVENT_SIGNATURE, caller(), shr(96, mload(0x2c))) } return true; } /// @dev Transfer `amount` tokens from the caller to `to`. /// /// Requirements: /// - `from` must at least have `amount`. /// /// Emits a {Transfer} event. function transfer(address to, uint256 amount) public virtual returns (bool) { _beforeTokenTransfer(msg.sender, to, amount); /// @solidity memory-safe-assembly assembly { // Compute the balance slot and load its value. mstore(0x0c, _BALANCE_SLOT_SEED) mstore(0x00, caller()) let fromBalanceSlot := keccak256(0x0c, 0x20) let fromBalance := sload(fromBalanceSlot) // Revert if insufficient balance. if gt(amount, fromBalance) { mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`. revert(0x1c, 0x04) } // Subtract and store the updated balance. sstore(fromBalanceSlot, sub(fromBalance, amount)) // Compute the balance slot of `to`. mstore(0x00, to) let toBalanceSlot := keccak256(0x0c, 0x20) // Add and store the updated balance of `to`. // Will not overflow because the sum of all user balances // cannot exceed the maximum uint256 value. sstore(toBalanceSlot, add(sload(toBalanceSlot), amount)) // Emit the {Transfer} event. mstore(0x20, amount) log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, caller(), shr(96, mload(0x0c))) } _afterTokenTransfer(msg.sender, to, amount); return true; } /// @dev Transfers `amount` tokens from `from` to `to`. /// /// Note: Does not update the allowance if it is the maximum uint256 value. /// /// Requirements: /// - `from` must at least have `amount`. /// - The caller must have at least `amount` of allowance to transfer the tokens of `from`. /// /// Emits a {Transfer} event. function transferFrom(address from, address to, uint256 amount) public virtual returns (bool) { _beforeTokenTransfer(from, to, amount); // Code duplication is for zero-cost abstraction if possible. if (_givePermit2InfiniteAllowance()) { /// @solidity memory-safe-assembly assembly { let from_ := shl(96, from) if iszero(eq(caller(), _PERMIT2)) { // Compute the allowance slot and load its value. mstore(0x20, caller()) mstore(0x0c, or(from_, _ALLOWANCE_SLOT_SEED)) let allowanceSlot := keccak256(0x0c, 0x34) let allowance_ := sload(allowanceSlot) // If the allowance is not the maximum uint256 value. if not(allowance_) { // Revert if the amount to be transferred exceeds the allowance. if gt(amount, allowance_) { mstore(0x00, 0x13be252b) // `InsufficientAllowance()`. revert(0x1c, 0x04) } // Subtract and store the updated allowance. sstore(allowanceSlot, sub(allowance_, amount)) } } // Compute the balance slot and load its value. mstore(0x0c, or(from_, _BALANCE_SLOT_SEED)) let fromBalanceSlot := keccak256(0x0c, 0x20) let fromBalance := sload(fromBalanceSlot) // Revert if insufficient balance. if gt(amount, fromBalance) { mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`. revert(0x1c, 0x04) } // Subtract and store the updated balance. sstore(fromBalanceSlot, sub(fromBalance, amount)) // Compute the balance slot of `to`. mstore(0x00, to) let toBalanceSlot := keccak256(0x0c, 0x20) // Add and store the updated balance of `to`. // Will not overflow because the sum of all user balances // cannot exceed the maximum uint256 value. sstore(toBalanceSlot, add(sload(toBalanceSlot), amount)) // Emit the {Transfer} event. mstore(0x20, amount) log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, from_), shr(96, mload(0x0c))) } } else { /// @solidity memory-safe-assembly assembly { let from_ := shl(96, from) // Compute the allowance slot and load its value. mstore(0x20, caller()) mstore(0x0c, or(from_, _ALLOWANCE_SLOT_SEED)) let allowanceSlot := keccak256(0x0c, 0x34) let allowance_ := sload(allowanceSlot) // If the allowance is not the maximum uint256 value. if not(allowance_) { // Revert if the amount to be transferred exceeds the allowance. if gt(amount, allowance_) { mstore(0x00, 0x13be252b) // `InsufficientAllowance()`. revert(0x1c, 0x04) } // Subtract and store the updated allowance. sstore(allowanceSlot, sub(allowance_, amount)) } // Compute the balance slot and load its value. mstore(0x0c, or(from_, _BALANCE_SLOT_SEED)) let fromBalanceSlot := keccak256(0x0c, 0x20) let fromBalance := sload(fromBalanceSlot) // Revert if insufficient balance. if gt(amount, fromBalance) { mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`. revert(0x1c, 0x04) } // Subtract and store the updated balance. sstore(fromBalanceSlot, sub(fromBalance, amount)) // Compute the balance slot of `to`. mstore(0x00, to) let toBalanceSlot := keccak256(0x0c, 0x20) // Add and store the updated balance of `to`. // Will not overflow because the sum of all user balances // cannot exceed the maximum uint256 value. sstore(toBalanceSlot, add(sload(toBalanceSlot), amount)) // Emit the {Transfer} event. mstore(0x20, amount) log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, from_), shr(96, mload(0x0c))) } } _afterTokenTransfer(from, to, amount); return true; } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* EIP-2612 */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev For more performance, override to return the constant value /// of `keccak256(bytes(name()))` if `name()` will never change. function _constantNameHash() internal view virtual returns (bytes32 result) {} /// @dev If you need a different value, override this function. function _versionHash() internal view virtual returns (bytes32 result) { result = _DEFAULT_VERSION_HASH; } /// @dev For inheriting contracts to increment the nonce. function _incrementNonce(address owner) internal virtual { /// @solidity memory-safe-assembly assembly { mstore(0x0c, _NONCES_SLOT_SEED) mstore(0x00, owner) let nonceSlot := keccak256(0x0c, 0x20) sstore(nonceSlot, add(1, sload(nonceSlot))) } } /// @dev Returns the current nonce for `owner`. /// This value is used to compute the signature for EIP-2612 permit. function nonces(address owner) public view virtual returns (uint256 result) { /// @solidity memory-safe-assembly assembly { // Compute the nonce slot and load its value. mstore(0x0c, _NONCES_SLOT_SEED) mstore(0x00, owner) result := sload(keccak256(0x0c, 0x20)) } } /// @dev Sets `value` as the allowance of `spender` over the tokens of `owner`, /// authorized by a signed approval by `owner`. /// /// Emits a {Approval} event. function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) public virtual { if (_givePermit2InfiniteAllowance()) { /// @solidity memory-safe-assembly assembly { // If `spender == _PERMIT2 && value != type(uint256).max`. if iszero(or(xor(shr(96, shl(96, spender)), _PERMIT2), iszero(not(value)))) { mstore(0x00, 0x3f68539a) // `Permit2AllowanceIsFixedAtInfinity()`. revert(0x1c, 0x04) } } } bytes32 nameHash = _constantNameHash(); // We simply calculate it on-the-fly to allow for cases where the `name` may change. if (nameHash == bytes32(0)) nameHash = keccak256(bytes(name())); bytes32 versionHash = _versionHash(); /// @solidity memory-safe-assembly assembly { // Revert if the block timestamp is greater than `deadline`. if gt(timestamp(), deadline) { mstore(0x00, 0x1a15a3cc) // `PermitExpired()`. revert(0x1c, 0x04) } let m := mload(0x40) // Grab the free memory pointer. // Clean the upper 96 bits. owner := shr(96, shl(96, owner)) spender := shr(96, shl(96, spender)) // Compute the nonce slot and load its value. mstore(0x0e, _NONCES_SLOT_SEED_WITH_SIGNATURE_PREFIX) mstore(0x00, owner) let nonceSlot := keccak256(0x0c, 0x20) let nonceValue := sload(nonceSlot) // Prepare the domain separator. mstore(m, _DOMAIN_TYPEHASH) mstore(add(m, 0x20), nameHash) mstore(add(m, 0x40), versionHash) mstore(add(m, 0x60), chainid()) mstore(add(m, 0x80), address()) mstore(0x2e, keccak256(m, 0xa0)) // Prepare the struct hash. mstore(m, _PERMIT_TYPEHASH) mstore(add(m, 0x20), owner) mstore(add(m, 0x40), spender) mstore(add(m, 0x60), value) mstore(add(m, 0x80), nonceValue) mstore(add(m, 0xa0), deadline) mstore(0x4e, keccak256(m, 0xc0)) // Prepare the ecrecover calldata. mstore(0x00, keccak256(0x2c, 0x42)) mstore(0x20, and(0xff, v)) mstore(0x40, r) mstore(0x60, s) let t := staticcall(gas(), 1, 0x00, 0x80, 0x20, 0x20) // If the ecrecover fails, the returndatasize will be 0x00, // `owner` will be checked if it equals the hash at 0x00, // which evaluates to false (i.e. 0), and we will revert. // If the ecrecover succeeds, the returndatasize will be 0x20, // `owner` will be compared against the returned address at 0x20. if iszero(eq(mload(returndatasize()), owner)) { mstore(0x00, 0xddafbaef) // `InvalidPermit()`. revert(0x1c, 0x04) } // Increment and store the updated nonce. sstore(nonceSlot, add(nonceValue, t)) // `t` is 1 if ecrecover succeeds. // Compute the allowance slot and store the value. // The `owner` is already at slot 0x20. mstore(0x40, or(shl(160, _ALLOWANCE_SLOT_SEED), spender)) sstore(keccak256(0x2c, 0x34), value) // Emit the {Approval} event. log3(add(m, 0x60), 0x20, _APPROVAL_EVENT_SIGNATURE, owner, spender) mstore(0x40, m) // Restore the free memory pointer. mstore(0x60, 0) // Restore the zero pointer. } } /// @dev Returns the EIP-712 domain separator for the EIP-2612 permit. function DOMAIN_SEPARATOR() public view virtual returns (bytes32 result) { bytes32 nameHash = _constantNameHash(); // We simply calculate it on-the-fly to allow for cases where the `name` may change. if (nameHash == bytes32(0)) nameHash = keccak256(bytes(name())); bytes32 versionHash = _versionHash(); /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Grab the free memory pointer. mstore(m, _DOMAIN_TYPEHASH) mstore(add(m, 0x20), nameHash) mstore(add(m, 0x40), versionHash) mstore(add(m, 0x60), chainid()) mstore(add(m, 0x80), address()) result := keccak256(m, 0xa0) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* INTERNAL MINT FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Mints `amount` tokens to `to`, increasing the total supply. /// /// Emits a {Transfer} event. function _mint(address to, uint256 amount) internal virtual { _beforeTokenTransfer(address(0), to, amount); /// @solidity memory-safe-assembly assembly { let totalSupplyBefore := sload(_TOTAL_SUPPLY_SLOT) let totalSupplyAfter := add(totalSupplyBefore, amount) // Revert if the total supply overflows. if lt(totalSupplyAfter, totalSupplyBefore) { mstore(0x00, 0xe5cfe957) // `TotalSupplyOverflow()`. revert(0x1c, 0x04) } // Store the updated total supply. sstore(_TOTAL_SUPPLY_SLOT, totalSupplyAfter) // Compute the balance slot and load its value. mstore(0x0c, _BALANCE_SLOT_SEED) mstore(0x00, to) let toBalanceSlot := keccak256(0x0c, 0x20) // Add and store the updated balance. sstore(toBalanceSlot, add(sload(toBalanceSlot), amount)) // Emit the {Transfer} event. mstore(0x20, amount) log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, 0, shr(96, mload(0x0c))) } _afterTokenTransfer(address(0), to, amount); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* INTERNAL BURN FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Burns `amount` tokens from `from`, reducing the total supply. /// /// Emits a {Transfer} event. function _burn(address from, uint256 amount) internal virtual { _beforeTokenTransfer(from, address(0), amount); /// @solidity memory-safe-assembly assembly { // Compute the balance slot and load its value. mstore(0x0c, _BALANCE_SLOT_SEED) mstore(0x00, from) let fromBalanceSlot := keccak256(0x0c, 0x20) let fromBalance := sload(fromBalanceSlot) // Revert if insufficient balance. if gt(amount, fromBalance) { mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`. revert(0x1c, 0x04) } // Subtract and store the updated balance. sstore(fromBalanceSlot, sub(fromBalance, amount)) // Subtract and store the updated total supply. sstore(_TOTAL_SUPPLY_SLOT, sub(sload(_TOTAL_SUPPLY_SLOT), amount)) // Emit the {Transfer} event. mstore(0x00, amount) log3(0x00, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, shl(96, from)), 0) } _afterTokenTransfer(from, address(0), amount); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* INTERNAL TRANSFER FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Moves `amount` of tokens from `from` to `to`. function _transfer(address from, address to, uint256 amount) internal virtual { _beforeTokenTransfer(from, to, amount); /// @solidity memory-safe-assembly assembly { let from_ := shl(96, from) // Compute the balance slot and load its value. mstore(0x0c, or(from_, _BALANCE_SLOT_SEED)) let fromBalanceSlot := keccak256(0x0c, 0x20) let fromBalance := sload(fromBalanceSlot) // Revert if insufficient balance. if gt(amount, fromBalance) { mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`. revert(0x1c, 0x04) } // Subtract and store the updated balance. sstore(fromBalanceSlot, sub(fromBalance, amount)) // Compute the balance slot of `to`. mstore(0x00, to) let toBalanceSlot := keccak256(0x0c, 0x20) // Add and store the updated balance of `to`. // Will not overflow because the sum of all user balances // cannot exceed the maximum uint256 value. sstore(toBalanceSlot, add(sload(toBalanceSlot), amount)) // Emit the {Transfer} event. mstore(0x20, amount) log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, from_), shr(96, mload(0x0c))) } _afterTokenTransfer(from, to, amount); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* INTERNAL ALLOWANCE FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Updates the allowance of `owner` for `spender` based on spent `amount`. function _spendAllowance(address owner, address spender, uint256 amount) internal virtual { if (_givePermit2InfiniteAllowance()) { if (spender == _PERMIT2) return; // Do nothing, as allowance is infinite. } /// @solidity memory-safe-assembly assembly { // Compute the allowance slot and load its value. mstore(0x20, spender) mstore(0x0c, _ALLOWANCE_SLOT_SEED) mstore(0x00, owner) let allowanceSlot := keccak256(0x0c, 0x34) let allowance_ := sload(allowanceSlot) // If the allowance is not the maximum uint256 value. if not(allowance_) { // Revert if the amount to be transferred exceeds the allowance. if gt(amount, allowance_) { mstore(0x00, 0x13be252b) // `InsufficientAllowance()`. revert(0x1c, 0x04) } // Subtract and store the updated allowance. sstore(allowanceSlot, sub(allowance_, amount)) } } } /// @dev Sets `amount` as the allowance of `spender` over the tokens of `owner`. /// /// Emits a {Approval} event. function _approve(address owner, address spender, uint256 amount) internal virtual { if (_givePermit2InfiniteAllowance()) { /// @solidity memory-safe-assembly assembly { // If `spender == _PERMIT2 && amount != type(uint256).max`. if iszero(or(xor(shr(96, shl(96, spender)), _PERMIT2), iszero(not(amount)))) { mstore(0x00, 0x3f68539a) // `Permit2AllowanceIsFixedAtInfinity()`. revert(0x1c, 0x04) } } } /// @solidity memory-safe-assembly assembly { let owner_ := shl(96, owner) // Compute the allowance slot and store the amount. mstore(0x20, spender) mstore(0x0c, or(owner_, _ALLOWANCE_SLOT_SEED)) sstore(keccak256(0x0c, 0x34), amount) // Emit the {Approval} event. mstore(0x00, amount) log3(0x00, 0x20, _APPROVAL_EVENT_SIGNATURE, shr(96, owner_), shr(96, mload(0x2c))) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* HOOKS TO OVERRIDE */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Hook that is called before any transfer of tokens. /// This includes minting and burning. 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. function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {} /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* PERMIT2 */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns whether to fix the Permit2 contract's allowance at infinity. /// /// This value should be kept constant after contract initialization, /// or else the actual allowance values may not match with the {Approval} events. /// For best performance, return a compile-time constant for zero-cost abstraction. function _givePermit2InfiniteAllowance() internal view virtual returns (bool) { return true; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Reentrancy guard mixin. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/ReentrancyGuard.sol) abstract contract ReentrancyGuard { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Unauthorized reentrant call. error Reentrancy(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* STORAGE */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Equivalent to: `uint72(bytes9(keccak256("_REENTRANCY_GUARD_SLOT")))`. /// 9 bytes is large enough to avoid collisions with lower slots, /// but not too large to result in excessive bytecode bloat. uint256 private constant _REENTRANCY_GUARD_SLOT = 0x929eee149b4bd21268; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* REENTRANCY GUARD */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Guards a function from reentrancy. modifier nonReentrant() virtual { /// @solidity memory-safe-assembly assembly { if eq(sload(_REENTRANCY_GUARD_SLOT), address()) { mstore(0x00, 0xab143c06) // `Reentrancy()`. revert(0x1c, 0x04) } sstore(_REENTRANCY_GUARD_SLOT, address()) } _; /// @solidity memory-safe-assembly assembly { sstore(_REENTRANCY_GUARD_SLOT, codesize()) } } /// @dev Guards a view function from read-only reentrancy. modifier nonReadReentrant() virtual { /// @solidity memory-safe-assembly assembly { if eq(sload(_REENTRANCY_GUARD_SLOT), address()) { mstore(0x00, 0xab143c06) // `Reentrancy()`. revert(0x1c, 0x04) } } _; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Arithmetic library with operations for fixed-point numbers. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/FixedPointMathLib.sol) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol) library FixedPointMathLib { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The operation failed, as the output exceeds the maximum value of uint256. error ExpOverflow(); /// @dev The operation failed, as the output exceeds the maximum value of uint256. error FactorialOverflow(); /// @dev The operation failed, due to an overflow. error RPowOverflow(); /// @dev The mantissa is too big to fit. error MantissaOverflow(); /// @dev The operation failed, due to an multiplication overflow. error MulWadFailed(); /// @dev The operation failed, due to an multiplication overflow. error SMulWadFailed(); /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero. error DivWadFailed(); /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero. error SDivWadFailed(); /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero. error MulDivFailed(); /// @dev The division failed, as the denominator is zero. error DivFailed(); /// @dev The full precision multiply-divide operation failed, either due /// to the result being larger than 256 bits, or a division by a zero. error FullMulDivFailed(); /// @dev The output is undefined, as the input is less-than-or-equal to zero. error LnWadUndefined(); /// @dev The input outside the acceptable domain. error OutOfDomain(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The scalar of ETH and most ERC20s. uint256 internal constant WAD = 1e18; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* SIMPLIFIED FIXED POINT OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Equivalent to `(x * y) / WAD` rounded down. function mulWad(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Equivalent to `require(y == 0 || x <= type(uint256).max / y)`. if gt(x, div(not(0), y)) { if y { mstore(0x00, 0xbac65e5b) // `MulWadFailed()`. revert(0x1c, 0x04) } } z := div(mul(x, y), WAD) } } /// @dev Equivalent to `(x * y) / WAD` rounded down. function sMulWad(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := mul(x, y) // Equivalent to `require((x == 0 || z / x == y) && !(x == -1 && y == type(int256).min))`. if iszero(gt(or(iszero(x), eq(sdiv(z, x), y)), lt(not(x), eq(y, shl(255, 1))))) { mstore(0x00, 0xedcd4dd4) // `SMulWadFailed()`. revert(0x1c, 0x04) } z := sdiv(z, WAD) } } /// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks. function rawMulWad(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := div(mul(x, y), WAD) } } /// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks. function rawSMulWad(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := sdiv(mul(x, y), WAD) } } /// @dev Equivalent to `(x * y) / WAD` rounded up. function mulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mul(x, y) // Equivalent to `require(y == 0 || x <= type(uint256).max / y)`. if iszero(eq(div(z, y), x)) { if y { mstore(0x00, 0xbac65e5b) // `MulWadFailed()`. revert(0x1c, 0x04) } } z := add(iszero(iszero(mod(z, WAD))), div(z, WAD)) } } /// @dev Equivalent to `(x * y) / WAD` rounded up, but without overflow checks. function rawMulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := add(iszero(iszero(mod(mul(x, y), WAD))), div(mul(x, y), WAD)) } } /// @dev Equivalent to `(x * WAD) / y` rounded down. function divWad(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Equivalent to `require(y != 0 && x <= type(uint256).max / WAD)`. if iszero(mul(y, lt(x, add(1, div(not(0), WAD))))) { mstore(0x00, 0x7c5f487d) // `DivWadFailed()`. revert(0x1c, 0x04) } z := div(mul(x, WAD), y) } } /// @dev Equivalent to `(x * WAD) / y` rounded down. function sDivWad(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := mul(x, WAD) // Equivalent to `require(y != 0 && ((x * WAD) / WAD == x))`. if iszero(mul(y, eq(sdiv(z, WAD), x))) { mstore(0x00, 0x5c43740d) // `SDivWadFailed()`. revert(0x1c, 0x04) } z := sdiv(z, y) } } /// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks. function rawDivWad(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := div(mul(x, WAD), y) } } /// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks. function rawSDivWad(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := sdiv(mul(x, WAD), y) } } /// @dev Equivalent to `(x * WAD) / y` rounded up. function divWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Equivalent to `require(y != 0 && x <= type(uint256).max / WAD)`. if iszero(mul(y, lt(x, add(1, div(not(0), WAD))))) { mstore(0x00, 0x7c5f487d) // `DivWadFailed()`. revert(0x1c, 0x04) } z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y)) } } /// @dev Equivalent to `(x * WAD) / y` rounded up, but without overflow and divide by zero checks. function rawDivWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y)) } } /// @dev Equivalent to `x` to the power of `y`. /// because `x ** y = (e ** ln(x)) ** y = e ** (ln(x) * y)`. /// Note: This function is an approximation. function powWad(int256 x, int256 y) internal pure returns (int256) { // Using `ln(x)` means `x` must be greater than 0. return expWad((lnWad(x) * y) / int256(WAD)); } /// @dev Returns `exp(x)`, denominated in `WAD`. /// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln /// Note: This function is an approximation. Monotonically increasing. function expWad(int256 x) internal pure returns (int256 r) { unchecked { // When the result is less than 0.5 we return zero. // This happens when `x <= (log(1e-18) * 1e18) ~ -4.15e19`. if (x <= -41446531673892822313) return r; /// @solidity memory-safe-assembly assembly { // When the result is greater than `(2**255 - 1) / 1e18` we can not represent it as // an int. This happens when `x >= floor(log((2**255 - 1) / 1e18) * 1e18) ≈ 135`. if iszero(slt(x, 135305999368893231589)) { mstore(0x00, 0xa37bfec9) // `ExpOverflow()`. revert(0x1c, 0x04) } } // `x` is now in the range `(-42, 136) * 1e18`. Convert to `(-42, 136) * 2**96` // for more intermediate precision and a binary basis. This base conversion // is a multiplication by 1e18 / 2**96 = 5**18 / 2**78. x = (x << 78) / 5 ** 18; // Reduce range of x to (-½ ln 2, ½ ln 2) * 2**96 by factoring out powers // of two such that exp(x) = exp(x') * 2**k, where k is an integer. // Solving this gives k = round(x / log(2)) and x' = x - k * log(2). int256 k = ((x << 96) / 54916777467707473351141471128 + 2 ** 95) >> 96; x = x - k * 54916777467707473351141471128; // `k` is in the range `[-61, 195]`. // Evaluate using a (6, 7)-term rational approximation. // `p` is made monic, we'll multiply by a scale factor later. int256 y = x + 1346386616545796478920950773328; y = ((y * x) >> 96) + 57155421227552351082224309758442; int256 p = y + x - 94201549194550492254356042504812; p = ((p * y) >> 96) + 28719021644029726153956944680412240; p = p * x + (4385272521454847904659076985693276 << 96); // We leave `p` in `2**192` basis so we don't need to scale it back up for the division. int256 q = x - 2855989394907223263936484059900; q = ((q * x) >> 96) + 50020603652535783019961831881945; q = ((q * x) >> 96) - 533845033583426703283633433725380; q = ((q * x) >> 96) + 3604857256930695427073651918091429; q = ((q * x) >> 96) - 14423608567350463180887372962807573; q = ((q * x) >> 96) + 26449188498355588339934803723976023; /// @solidity memory-safe-assembly assembly { // Div in assembly because solidity adds a zero check despite the unchecked. // The q polynomial won't have zeros in the domain as all its roots are complex. // No scaling is necessary because p is already `2**96` too large. r := sdiv(p, q) } // r should be in the range `(0.09, 0.25) * 2**96`. // We now need to multiply r by: // - The scale factor `s ≈ 6.031367120`. // - The `2**k` factor from the range reduction. // - The `1e18 / 2**96` factor for base conversion. // We do this all at once, with an intermediate result in `2**213` // basis, so the final right shift is always by a positive amount. r = int256( (uint256(r) * 3822833074963236453042738258902158003155416615667) >> uint256(195 - k) ); } } /// @dev Returns `ln(x)`, denominated in `WAD`. /// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln /// Note: This function is an approximation. Monotonically increasing. function lnWad(int256 x) internal pure returns (int256 r) { /// @solidity memory-safe-assembly assembly { // We want to convert `x` from `10**18` fixed point to `2**96` fixed point. // We do this by multiplying by `2**96 / 10**18`. But since // `ln(x * C) = ln(x) + ln(C)`, we can simply do nothing here // and add `ln(2**96 / 10**18)` at the end. // Compute `k = log2(x) - 96`, `r = 159 - k = 255 - log2(x) = 255 ^ log2(x)`. r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x)) r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x)))) r := or(r, shl(5, lt(0xffffffff, shr(r, x)))) r := or(r, shl(4, lt(0xffff, shr(r, x)))) r := or(r, shl(3, lt(0xff, shr(r, x)))) // We place the check here for more optimal stack operations. if iszero(sgt(x, 0)) { mstore(0x00, 0x1615e638) // `LnWadUndefined()`. revert(0x1c, 0x04) } // forgefmt: disable-next-item r := xor(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)), 0xf8f9f9faf9fdfafbf9fdfcfdfafbfcfef9fafdfafcfcfbfefafafcfbffffffff)) // Reduce range of x to (1, 2) * 2**96 // ln(2^k * x) = k * ln(2) + ln(x) x := shr(159, shl(r, x)) // Evaluate using a (8, 8)-term rational approximation. // `p` is made monic, we will multiply by a scale factor later. // forgefmt: disable-next-item let p := sub( // This heavily nested expression is to avoid stack-too-deep for via-ir. sar(96, mul(add(43456485725739037958740375743393, sar(96, mul(add(24828157081833163892658089445524, sar(96, mul(add(3273285459638523848632254066296, x), x))), x))), x)), 11111509109440967052023855526967) p := sub(sar(96, mul(p, x)), 45023709667254063763336534515857) p := sub(sar(96, mul(p, x)), 14706773417378608786704636184526) p := sub(mul(p, x), shl(96, 795164235651350426258249787498)) // We leave `p` in `2**192` basis so we don't need to scale it back up for the division. // `q` is monic by convention. let q := add(5573035233440673466300451813936, x) q := add(71694874799317883764090561454958, sar(96, mul(x, q))) q := add(283447036172924575727196451306956, sar(96, mul(x, q))) q := add(401686690394027663651624208769553, sar(96, mul(x, q))) q := add(204048457590392012362485061816622, sar(96, mul(x, q))) q := add(31853899698501571402653359427138, sar(96, mul(x, q))) q := add(909429971244387300277376558375, sar(96, mul(x, q))) // `p / q` is in the range `(0, 0.125) * 2**96`. // Finalization, we need to: // - Multiply by the scale factor `s = 5.549…`. // - Add `ln(2**96 / 10**18)`. // - Add `k * ln(2)`. // - Multiply by `10**18 / 2**96 = 5**18 >> 78`. // The q polynomial is known not to have zeros in the domain. // No scaling required because p is already `2**96` too large. p := sdiv(p, q) // Multiply by the scaling factor: `s * 5**18 * 2**96`, base is now `5**18 * 2**192`. p := mul(1677202110996718588342820967067443963516166, p) // Add `ln(2) * k * 5**18 * 2**192`. // forgefmt: disable-next-item p := add(mul(16597577552685614221487285958193947469193820559219878177908093499208371, sub(159, r)), p) // Add `ln(2**96 / 10**18) * 5**18 * 2**192`. p := add(600920179829731861736702779321621459595472258049074101567377883020018308, p) // Base conversion: mul `2**18 / 2**192`. r := sar(174, p) } } /// @dev Returns `W_0(x)`, denominated in `WAD`. /// See: https://en.wikipedia.org/wiki/Lambert_W_function /// a.k.a. Product log function. This is an approximation of the principal branch. /// Note: This function is an approximation. Monotonically increasing. function lambertW0Wad(int256 x) internal pure returns (int256 w) { // forgefmt: disable-next-item unchecked { if ((w = x) <= -367879441171442322) revert OutOfDomain(); // `x` less than `-1/e`. (int256 wad, int256 p) = (int256(WAD), x); uint256 c; // Whether we need to avoid catastrophic cancellation. uint256 i = 4; // Number of iterations. if (w <= 0x1ffffffffffff) { if (-0x4000000000000 <= w) { i = 1; // Inputs near zero only take one step to converge. } else if (w <= -0x3ffffffffffffff) { i = 32; // Inputs near `-1/e` take very long to converge. } } else if (uint256(w >> 63) == uint256(0)) { /// @solidity memory-safe-assembly assembly { // Inline log2 for more performance, since the range is small. let v := shr(49, w) let l := shl(3, lt(0xff, v)) l := add(or(l, byte(and(0x1f, shr(shr(l, v), 0x8421084210842108cc6318c6db6d54be)), 0x0706060506020504060203020504030106050205030304010505030400000000)), 49) w := sdiv(shl(l, 7), byte(sub(l, 31), 0x0303030303030303040506080c13)) c := gt(l, 60) i := add(2, add(gt(l, 53), c)) } } else { int256 ll = lnWad(w = lnWad(w)); /// @solidity memory-safe-assembly assembly { // `w = ln(x) - ln(ln(x)) + b * ln(ln(x)) / ln(x)`. w := add(sdiv(mul(ll, 1023715080943847266), w), sub(w, ll)) i := add(3, iszero(shr(68, x))) c := iszero(shr(143, x)) } if (c == uint256(0)) { do { // If `x` is big, use Newton's so that intermediate values won't overflow. int256 e = expWad(w); /// @solidity memory-safe-assembly assembly { let t := mul(w, div(e, wad)) w := sub(w, sdiv(sub(t, x), div(add(e, t), wad))) } if (p <= w) break; p = w; } while (--i != uint256(0)); /// @solidity memory-safe-assembly assembly { w := sub(w, sgt(w, 2)) } return w; } } do { // Otherwise, use Halley's for faster convergence. int256 e = expWad(w); /// @solidity memory-safe-assembly assembly { let t := add(w, wad) let s := sub(mul(w, e), mul(x, wad)) w := sub(w, sdiv(mul(s, wad), sub(mul(e, t), sdiv(mul(add(t, wad), s), add(t, t))))) } if (p <= w) break; p = w; } while (--i != c); /// @solidity memory-safe-assembly assembly { w := sub(w, sgt(w, 2)) } // For certain ranges of `x`, we'll use the quadratic-rate recursive formula of // R. Iacono and J.P. Boyd for the last iteration, to avoid catastrophic cancellation. if (c == uint256(0)) return w; int256 t = w | 1; /// @solidity memory-safe-assembly assembly { x := sdiv(mul(x, wad), t) } x = (t * (wad + lnWad(x))); /// @solidity memory-safe-assembly assembly { w := sdiv(x, add(wad, t)) } } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* GENERAL NUMBER UTILITIES */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns `a * b == x * y`, with full precision. function fullMulEq(uint256 a, uint256 b, uint256 x, uint256 y) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { result := and(eq(mul(a, b), mul(x, y)), eq(mulmod(x, y, not(0)), mulmod(a, b, not(0)))) } } /// @dev Calculates `floor(x * y / d)` with full precision. /// Throws if result overflows a uint256 or when `d` is zero. /// Credit to Remco Bloemen under MIT license: https://2π.com/21/muldiv function fullMulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // 512-bit multiply `[p1 p0] = x * y`. // Compute the product mod `2**256` and mod `2**256 - 1` // then use the Chinese Remainder Theorem to reconstruct // the 512 bit result. The result is stored in two 256 // variables such that `product = p1 * 2**256 + p0`. // Temporarily use `z` as `p0` to save gas. z := mul(x, y) // Lower 256 bits of `x * y`. for {} 1 {} { // If overflows. if iszero(mul(or(iszero(x), eq(div(z, x), y)), d)) { let mm := mulmod(x, y, not(0)) let p1 := sub(mm, add(z, lt(mm, z))) // Upper 256 bits of `x * y`. /*------------------- 512 by 256 division --------------------*/ // Make division exact by subtracting the remainder from `[p1 p0]`. let r := mulmod(x, y, d) // Compute remainder using mulmod. let t := and(d, sub(0, d)) // The least significant bit of `d`. `t >= 1`. // Make sure `z` is less than `2**256`. Also prevents `d == 0`. // Placing the check here seems to give more optimal stack operations. if iszero(gt(d, p1)) { mstore(0x00, 0xae47f702) // `FullMulDivFailed()`. revert(0x1c, 0x04) } d := div(d, t) // Divide `d` by `t`, which is a power of two. // Invert `d mod 2**256` // Now that `d` is an odd number, it has an inverse // modulo `2**256` such that `d * inv = 1 mod 2**256`. // Compute the inverse by starting with a seed that is correct // correct for four bits. That is, `d * inv = 1 mod 2**4`. let inv := xor(2, mul(3, d)) // Now use 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. inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**8 inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**16 inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**32 inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**64 inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**128 z := mul( // Divide [p1 p0] by the factors of two. // Shift in bits from `p1` into `p0`. For this we need // to flip `t` such that it is `2**256 / t`. or(mul(sub(p1, gt(r, z)), add(div(sub(0, t), t), 1)), div(sub(z, r), t)), mul(sub(2, mul(d, inv)), inv) // inverse mod 2**256 ) break } z := div(z, d) break } } } /// @dev Calculates `floor(x * y / d)` with full precision. /// Behavior is undefined if `d` is zero or the final result cannot fit in 256 bits. /// Performs the full 512 bit calculation regardless. function fullMulDivUnchecked(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mul(x, y) let mm := mulmod(x, y, not(0)) let p1 := sub(mm, add(z, lt(mm, z))) let t := and(d, sub(0, d)) let r := mulmod(x, y, d) d := div(d, t) let inv := xor(2, mul(3, d)) inv := mul(inv, sub(2, mul(d, inv))) inv := mul(inv, sub(2, mul(d, inv))) inv := mul(inv, sub(2, mul(d, inv))) inv := mul(inv, sub(2, mul(d, inv))) inv := mul(inv, sub(2, mul(d, inv))) z := mul( or(mul(sub(p1, gt(r, z)), add(div(sub(0, t), t), 1)), div(sub(z, r), t)), mul(sub(2, mul(d, inv)), inv) ) } } /// @dev Calculates `floor(x * y / d)` with full precision, rounded up. /// Throws if result overflows a uint256 or when `d` is zero. /// Credit to Uniswap-v3-core under MIT license: /// https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/FullMath.sol function fullMulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { z = fullMulDiv(x, y, d); /// @solidity memory-safe-assembly assembly { if mulmod(x, y, d) { z := add(z, 1) if iszero(z) { mstore(0x00, 0xae47f702) // `FullMulDivFailed()`. revert(0x1c, 0x04) } } } } /// @dev Calculates `floor(x * y / 2 ** n)` with full precision. /// Throws if result overflows a uint256. /// Credit to Philogy under MIT license: /// https://github.com/SorellaLabs/angstrom/blob/main/contracts/src/libraries/X128MathLib.sol function fullMulDivN(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Temporarily use `z` as `p0` to save gas. z := mul(x, y) // Lower 256 bits of `x * y`. We'll call this `z`. for {} 1 {} { if iszero(or(iszero(x), eq(div(z, x), y))) { let k := and(n, 0xff) // `n`, cleaned. let mm := mulmod(x, y, not(0)) let p1 := sub(mm, add(z, lt(mm, z))) // Upper 256 bits of `x * y`. // | p1 | z | // Before: | p1_0 ¦ p1_1 | z_0 ¦ z_1 | // Final: | 0 ¦ p1_0 | p1_1 ¦ z_0 | // Check that final `z` doesn't overflow by checking that p1_0 = 0. if iszero(shr(k, p1)) { z := add(shl(sub(256, k), p1), shr(k, z)) break } mstore(0x00, 0xae47f702) // `FullMulDivFailed()`. revert(0x1c, 0x04) } z := shr(and(n, 0xff), z) break } } } /// @dev Returns `floor(x * y / d)`. /// Reverts if `x * y` overflows, or `d` is zero. function mulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mul(x, y) // Equivalent to `require(d != 0 && (y == 0 || x <= type(uint256).max / y))`. if iszero(mul(or(iszero(x), eq(div(z, x), y)), d)) { mstore(0x00, 0xad251c27) // `MulDivFailed()`. revert(0x1c, 0x04) } z := div(z, d) } } /// @dev Returns `ceil(x * y / d)`. /// Reverts if `x * y` overflows, or `d` is zero. function mulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mul(x, y) // Equivalent to `require(d != 0 && (y == 0 || x <= type(uint256).max / y))`. if iszero(mul(or(iszero(x), eq(div(z, x), y)), d)) { mstore(0x00, 0xad251c27) // `MulDivFailed()`. revert(0x1c, 0x04) } z := add(iszero(iszero(mod(z, d))), div(z, d)) } } /// @dev Returns `x`, the modular multiplicative inverse of `a`, such that `(a * x) % n == 1`. function invMod(uint256 a, uint256 n) internal pure returns (uint256 x) { /// @solidity memory-safe-assembly assembly { let g := n let r := mod(a, n) for { let y := 1 } 1 {} { let q := div(g, r) let t := g g := r r := sub(t, mul(r, q)) let u := x x := y y := sub(u, mul(y, q)) if iszero(r) { break } } x := mul(eq(g, 1), add(x, mul(slt(x, 0), n))) } } /// @dev Returns `ceil(x / d)`. /// Reverts if `d` is zero. function divUp(uint256 x, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { if iszero(d) { mstore(0x00, 0x65244e4e) // `DivFailed()`. revert(0x1c, 0x04) } z := add(iszero(iszero(mod(x, d))), div(x, d)) } } /// @dev Returns `max(0, x - y)`. function zeroFloorSub(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mul(gt(x, y), sub(x, y)) } } /// @dev Returns `condition ? x : y`, without branching. function ternary(bool condition, uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), iszero(condition))) } } /// @dev Returns `condition ? x : y`, without branching. function ternary(bool condition, bytes32 x, bytes32 y) internal pure returns (bytes32 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), iszero(condition))) } } /// @dev Returns `condition ? x : y`, without branching. function ternary(bool condition, address x, address y) internal pure returns (address z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), iszero(condition))) } } /// @dev Exponentiate `x` to `y` by squaring, denominated in base `b`. /// Reverts if the computation overflows. function rpow(uint256 x, uint256 y, uint256 b) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mul(b, iszero(y)) // `0 ** 0 = 1`. Otherwise, `0 ** n = 0`. if x { z := xor(b, mul(xor(b, x), and(y, 1))) // `z = isEven(y) ? scale : x` let half := shr(1, b) // Divide `b` by 2. // Divide `y` by 2 every iteration. for { y := shr(1, y) } y { y := shr(1, y) } { let xx := mul(x, x) // Store x squared. let xxRound := add(xx, half) // Round to the nearest number. // Revert if `xx + half` overflowed, or if `x ** 2` overflows. if or(lt(xxRound, xx), shr(128, x)) { mstore(0x00, 0x49f7642b) // `RPowOverflow()`. revert(0x1c, 0x04) } x := div(xxRound, b) // Set `x` to scaled `xxRound`. // If `y` is odd: if and(y, 1) { let zx := mul(z, x) // Compute `z * x`. let zxRound := add(zx, half) // Round to the nearest number. // If `z * x` overflowed or `zx + half` overflowed: if or(xor(div(zx, x), z), lt(zxRound, zx)) { // Revert if `x` is non-zero. if x { mstore(0x00, 0x49f7642b) // `RPowOverflow()`. revert(0x1c, 0x04) } } z := div(zxRound, b) // Return properly scaled `zxRound`. } } } } } /// @dev Returns the square root of `x`, rounded down. function sqrt(uint256 x) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // `floor(sqrt(2**15)) = 181`. `sqrt(2**15) - 181 = 2.84`. z := 181 // The "correct" value is 1, but this saves a multiplication later. // This segment is to get a reasonable initial estimate for the Babylonian method. With a bad // start, the correct # of bits increases ~linearly each iteration instead of ~quadratically. // Let `y = x / 2**r`. We check `y >= 2**(k + 8)` // but shift right by `k` bits to ensure that if `x >= 256`, then `y >= 256`. let r := shl(7, lt(0xffffffffffffffffffffffffffffffffff, x)) r := or(r, shl(6, lt(0xffffffffffffffffff, shr(r, x)))) r := or(r, shl(5, lt(0xffffffffff, shr(r, x)))) r := or(r, shl(4, lt(0xffffff, shr(r, x)))) z := shl(shr(1, r), z) // Goal was to get `z*z*y` within a small factor of `x`. More iterations could // get y in a tighter range. Currently, we will have y in `[256, 256*(2**16))`. // We ensured `y >= 256` so that the relative difference between `y` and `y+1` is small. // That's not possible if `x < 256` but we can just verify those cases exhaustively. // Now, `z*z*y <= x < z*z*(y+1)`, and `y <= 2**(16+8)`, and either `y >= 256`, or `x < 256`. // Correctness can be checked exhaustively for `x < 256`, so we assume `y >= 256`. // Then `z*sqrt(y)` is within `sqrt(257)/sqrt(256)` of `sqrt(x)`, or about 20bps. // For `s` in the range `[1/256, 256]`, the estimate `f(s) = (181/1024) * (s+1)` // is in the range `(1/2.84 * sqrt(s), 2.84 * sqrt(s))`, // with largest error when `s = 1` and when `s = 256` or `1/256`. // Since `y` is in `[256, 256*(2**16))`, let `a = y/65536`, so that `a` is in `[1/256, 256)`. // Then we can estimate `sqrt(y)` using // `sqrt(65536) * 181/1024 * (a + 1) = 181/4 * (y + 65536)/65536 = 181 * (y + 65536)/2**18`. // There is no overflow risk here since `y < 2**136` after the first branch above. z := shr(18, mul(z, add(shr(r, x), 65536))) // A `mul()` is saved from starting `z` at 181. // Given the worst case multiplicative error of 2.84 above, 7 iterations should be enough. z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) // If `x+1` is a perfect square, the Babylonian method cycles between // `floor(sqrt(x))` and `ceil(sqrt(x))`. This statement ensures we return floor. // See: https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division z := sub(z, lt(div(x, z), z)) } } /// @dev Returns the cube root of `x`, rounded down. /// Credit to bout3fiddy and pcaversaccio under AGPLv3 license: /// https://github.com/pcaversaccio/snekmate/blob/main/src/utils/Math.vy /// Formally verified by xuwinnie: /// https://github.com/vectorized/solady/blob/main/audits/xuwinnie-solady-cbrt-proof.pdf function cbrt(uint256 x) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { let r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x)) r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x)))) r := or(r, shl(5, lt(0xffffffff, shr(r, x)))) r := or(r, shl(4, lt(0xffff, shr(r, x)))) r := or(r, shl(3, lt(0xff, shr(r, x)))) // Makeshift lookup table to nudge the approximate log2 result. z := div(shl(div(r, 3), shl(lt(0xf, shr(r, x)), 0xf)), xor(7, mod(r, 3))) // Newton-Raphson's. z := div(add(add(div(x, mul(z, z)), z), z), 3) z := div(add(add(div(x, mul(z, z)), z), z), 3) z := div(add(add(div(x, mul(z, z)), z), z), 3) z := div(add(add(div(x, mul(z, z)), z), z), 3) z := div(add(add(div(x, mul(z, z)), z), z), 3) z := div(add(add(div(x, mul(z, z)), z), z), 3) z := div(add(add(div(x, mul(z, z)), z), z), 3) // Round down. z := sub(z, lt(div(x, mul(z, z)), z)) } } /// @dev Returns the square root of `x`, denominated in `WAD`, rounded down. function sqrtWad(uint256 x) internal pure returns (uint256 z) { unchecked { if (x <= type(uint256).max / 10 ** 18) return sqrt(x * 10 ** 18); z = (1 + sqrt(x)) * 10 ** 9; z = (fullMulDivUnchecked(x, 10 ** 18, z) + z) >> 1; } /// @solidity memory-safe-assembly assembly { z := sub(z, gt(999999999999999999, sub(mulmod(z, z, x), 1))) // Round down. } } /// @dev Returns the cube root of `x`, denominated in `WAD`, rounded down. /// Formally verified by xuwinnie: /// https://github.com/vectorized/solady/blob/main/audits/xuwinnie-solady-cbrt-proof.pdf function cbrtWad(uint256 x) internal pure returns (uint256 z) { unchecked { if (x <= type(uint256).max / 10 ** 36) return cbrt(x * 10 ** 36); z = (1 + cbrt(x)) * 10 ** 12; z = (fullMulDivUnchecked(x, 10 ** 36, z * z) + z + z) / 3; } /// @solidity memory-safe-assembly assembly { let p := x for {} 1 {} { if iszero(shr(229, p)) { if iszero(shr(199, p)) { p := mul(p, 100000000000000000) // 10 ** 17. break } p := mul(p, 100000000) // 10 ** 8. break } if iszero(shr(249, p)) { p := mul(p, 100) } break } let t := mulmod(mul(z, z), z, p) z := sub(z, gt(lt(t, shr(1, p)), iszero(t))) // Round down. } } /// @dev Returns the factorial of `x`. function factorial(uint256 x) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := 1 if iszero(lt(x, 58)) { mstore(0x00, 0xaba0f2a2) // `FactorialOverflow()`. revert(0x1c, 0x04) } for {} x { x := sub(x, 1) } { z := mul(z, x) } } } /// @dev Returns the log2 of `x`. /// Equivalent to computing the index of the most significant bit (MSB) of `x`. /// Returns 0 if `x` is zero. function log2(uint256 x) internal pure returns (uint256 r) { /// @solidity memory-safe-assembly assembly { r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x)) r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x)))) r := or(r, shl(5, lt(0xffffffff, shr(r, x)))) r := or(r, shl(4, lt(0xffff, shr(r, x)))) r := or(r, shl(3, lt(0xff, shr(r, x)))) // forgefmt: disable-next-item r := or(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)), 0x0706060506020504060203020504030106050205030304010505030400000000)) } } /// @dev Returns the log2 of `x`, rounded up. /// Returns 0 if `x` is zero. function log2Up(uint256 x) internal pure returns (uint256 r) { r = log2(x); /// @solidity memory-safe-assembly assembly { r := add(r, lt(shl(r, 1), x)) } } /// @dev Returns the log10 of `x`. /// Returns 0 if `x` is zero. function log10(uint256 x) internal pure returns (uint256 r) { /// @solidity memory-safe-assembly assembly { if iszero(lt(x, 100000000000000000000000000000000000000)) { x := div(x, 100000000000000000000000000000000000000) r := 38 } if iszero(lt(x, 100000000000000000000)) { x := div(x, 100000000000000000000) r := add(r, 20) } if iszero(lt(x, 10000000000)) { x := div(x, 10000000000) r := add(r, 10) } if iszero(lt(x, 100000)) { x := div(x, 100000) r := add(r, 5) } r := add(r, add(gt(x, 9), add(gt(x, 99), add(gt(x, 999), gt(x, 9999))))) } } /// @dev Returns the log10 of `x`, rounded up. /// Returns 0 if `x` is zero. function log10Up(uint256 x) internal pure returns (uint256 r) { r = log10(x); /// @solidity memory-safe-assembly assembly { r := add(r, lt(exp(10, r), x)) } } /// @dev Returns the log256 of `x`. /// Returns 0 if `x` is zero. function log256(uint256 x) internal pure returns (uint256 r) { /// @solidity memory-safe-assembly assembly { r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x)) r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x)))) r := or(r, shl(5, lt(0xffffffff, shr(r, x)))) r := or(r, shl(4, lt(0xffff, shr(r, x)))) r := or(shr(3, r), lt(0xff, shr(r, x))) } } /// @dev Returns the log256 of `x`, rounded up. /// Returns 0 if `x` is zero. function log256Up(uint256 x) internal pure returns (uint256 r) { r = log256(x); /// @solidity memory-safe-assembly assembly { r := add(r, lt(shl(shl(3, r), 1), x)) } } /// @dev Returns the scientific notation format `mantissa * 10 ** exponent` of `x`. /// Useful for compressing prices (e.g. using 25 bit mantissa and 7 bit exponent). function sci(uint256 x) internal pure returns (uint256 mantissa, uint256 exponent) { /// @solidity memory-safe-assembly assembly { mantissa := x if mantissa { if iszero(mod(mantissa, 1000000000000000000000000000000000)) { mantissa := div(mantissa, 1000000000000000000000000000000000) exponent := 33 } if iszero(mod(mantissa, 10000000000000000000)) { mantissa := div(mantissa, 10000000000000000000) exponent := add(exponent, 19) } if iszero(mod(mantissa, 1000000000000)) { mantissa := div(mantissa, 1000000000000) exponent := add(exponent, 12) } if iszero(mod(mantissa, 1000000)) { mantissa := div(mantissa, 1000000) exponent := add(exponent, 6) } if iszero(mod(mantissa, 10000)) { mantissa := div(mantissa, 10000) exponent := add(exponent, 4) } if iszero(mod(mantissa, 100)) { mantissa := div(mantissa, 100) exponent := add(exponent, 2) } if iszero(mod(mantissa, 10)) { mantissa := div(mantissa, 10) exponent := add(exponent, 1) } } } } /// @dev Convenience function for packing `x` into a smaller number using `sci`. /// The `mantissa` will be in bits [7..255] (the upper 249 bits). /// The `exponent` will be in bits [0..6] (the lower 7 bits). /// Use `SafeCastLib` to safely ensure that the `packed` number is small /// enough to fit in the desired unsigned integer type: /// ``` /// uint32 packed = SafeCastLib.toUint32(FixedPointMathLib.packSci(777 ether)); /// ``` function packSci(uint256 x) internal pure returns (uint256 packed) { (x, packed) = sci(x); // Reuse for `mantissa` and `exponent`. /// @solidity memory-safe-assembly assembly { if shr(249, x) { mstore(0x00, 0xce30380c) // `MantissaOverflow()`. revert(0x1c, 0x04) } packed := or(shl(7, x), packed) } } /// @dev Convenience function for unpacking a packed number from `packSci`. function unpackSci(uint256 packed) internal pure returns (uint256 unpacked) { unchecked { unpacked = (packed >> 7) * 10 ** (packed & 0x7f); } } /// @dev Returns the average of `x` and `y`. Rounds towards zero. function avg(uint256 x, uint256 y) internal pure returns (uint256 z) { unchecked { z = (x & y) + ((x ^ y) >> 1); } } /// @dev Returns the average of `x` and `y`. Rounds towards negative infinity. function avg(int256 x, int256 y) internal pure returns (int256 z) { unchecked { z = (x >> 1) + (y >> 1) + (x & y & 1); } } /// @dev Returns the absolute value of `x`. function abs(int256 x) internal pure returns (uint256 z) { unchecked { z = (uint256(x) + uint256(x >> 255)) ^ uint256(x >> 255); } } /// @dev Returns the absolute distance between `x` and `y`. function dist(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := add(xor(sub(0, gt(x, y)), sub(y, x)), gt(x, y)) } } /// @dev Returns the absolute distance between `x` and `y`. function dist(int256 x, int256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := add(xor(sub(0, sgt(x, y)), sub(y, x)), sgt(x, y)) } } /// @dev Returns the minimum of `x` and `y`. function min(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), lt(y, x))) } } /// @dev Returns the minimum of `x` and `y`. function min(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), slt(y, x))) } } /// @dev Returns the maximum of `x` and `y`. function max(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), gt(y, x))) } } /// @dev Returns the maximum of `x` and `y`. function max(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), sgt(y, x))) } } /// @dev Returns `x`, bounded to `minValue` and `maxValue`. function clamp(uint256 x, uint256 minValue, uint256 maxValue) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, minValue), gt(minValue, x))) z := xor(z, mul(xor(z, maxValue), lt(maxValue, z))) } } /// @dev Returns `x`, bounded to `minValue` and `maxValue`. function clamp(int256 x, int256 minValue, int256 maxValue) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, minValue), sgt(minValue, x))) z := xor(z, mul(xor(z, maxValue), slt(maxValue, z))) } } /// @dev Returns greatest common divisor of `x` and `y`. function gcd(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { for { z := x } y {} { let t := y y := mod(z, y) z := t } } } /// @dev Returns `a + (b - a) * (t - begin) / (end - begin)`, /// with `t` clamped between `begin` and `end` (inclusive). /// Agnostic to the order of (`a`, `b`) and (`end`, `begin`). /// If `begins == end`, returns `t <= begin ? a : b`. function lerp(uint256 a, uint256 b, uint256 t, uint256 begin, uint256 end) internal pure returns (uint256) { if (begin > end) (t, begin, end) = (~t, ~begin, ~end); if (t <= begin) return a; if (t >= end) return b; unchecked { if (b >= a) return a + fullMulDiv(b - a, t - begin, end - begin); return a - fullMulDiv(a - b, t - begin, end - begin); } } /// @dev Returns `a + (b - a) * (t - begin) / (end - begin)`. /// with `t` clamped between `begin` and `end` (inclusive). /// Agnostic to the order of (`a`, `b`) and (`end`, `begin`). /// If `begins == end`, returns `t <= begin ? a : b`. function lerp(int256 a, int256 b, int256 t, int256 begin, int256 end) internal pure returns (int256) { if (begin > end) (t, begin, end) = (~t, ~begin, ~end); if (t <= begin) return a; if (t >= end) return b; // forgefmt: disable-next-item unchecked { if (b >= a) return int256(uint256(a) + fullMulDiv(uint256(b - a), uint256(t - begin), uint256(end - begin))); return int256(uint256(a) - fullMulDiv(uint256(a - b), uint256(t - begin), uint256(end - begin))); } } /// @dev Returns if `x` is an even number. Some people may need this. function isEven(uint256 x) internal pure returns (bool) { return x & uint256(1) == uint256(0); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* RAW NUMBER OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns `x + y`, without checking for overflow. function rawAdd(uint256 x, uint256 y) internal pure returns (uint256 z) { unchecked { z = x + y; } } /// @dev Returns `x + y`, without checking for overflow. function rawAdd(int256 x, int256 y) internal pure returns (int256 z) { unchecked { z = x + y; } } /// @dev Returns `x - y`, without checking for underflow. function rawSub(uint256 x, uint256 y) internal pure returns (uint256 z) { unchecked { z = x - y; } } /// @dev Returns `x - y`, without checking for underflow. function rawSub(int256 x, int256 y) internal pure returns (int256 z) { unchecked { z = x - y; } } /// @dev Returns `x * y`, without checking for overflow. function rawMul(uint256 x, uint256 y) internal pure returns (uint256 z) { unchecked { z = x * y; } } /// @dev Returns `x * y`, without checking for overflow. function rawMul(int256 x, int256 y) internal pure returns (int256 z) { unchecked { z = x * y; } } /// @dev Returns `x / y`, returning 0 if `y` is zero. function rawDiv(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := div(x, y) } } /// @dev Returns `x / y`, returning 0 if `y` is zero. function rawSDiv(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := sdiv(x, y) } } /// @dev Returns `x % y`, returning 0 if `y` is zero. function rawMod(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mod(x, y) } } /// @dev Returns `x % y`, returning 0 if `y` is zero. function rawSMod(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := smod(x, y) } } /// @dev Returns `(x + y) % d`, return 0 if `d` if zero. function rawAddMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := addmod(x, y, d) } } /// @dev Returns `(x * y) % d`, return 0 if `d` if zero. function rawMulMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mulmod(x, y, d) } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeTransferLib.sol) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol) /// @author Permit2 operations from (https://github.com/Uniswap/permit2/blob/main/src/libraries/Permit2Lib.sol) /// /// @dev Note: /// - For ETH transfers, please use `forceSafeTransferETH` for DoS protection. library SafeTransferLib { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The ETH transfer has failed. error ETHTransferFailed(); /// @dev The ERC20 `transferFrom` has failed. error TransferFromFailed(); /// @dev The ERC20 `transfer` has failed. error TransferFailed(); /// @dev The ERC20 `approve` has failed. error ApproveFailed(); /// @dev The ERC20 `totalSupply` query has failed. error TotalSupplyQueryFailed(); /// @dev The Permit2 operation has failed. error Permit2Failed(); /// @dev The Permit2 amount must be less than `2**160 - 1`. error Permit2AmountOverflow(); /// @dev The Permit2 approve operation has failed. error Permit2ApproveFailed(); /// @dev The Permit2 lockdown operation has failed. error Permit2LockdownFailed(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Suggested gas stipend for contract receiving ETH that disallows any storage writes. uint256 internal constant GAS_STIPEND_NO_STORAGE_WRITES = 2300; /// @dev Suggested gas stipend for contract receiving ETH to perform a few /// storage reads and writes, but low enough to prevent griefing. uint256 internal constant GAS_STIPEND_NO_GRIEF = 100000; /// @dev The unique EIP-712 domain domain separator for the DAI token contract. bytes32 internal constant DAI_DOMAIN_SEPARATOR = 0xdbb8cf42e1ecb028be3f3dbc922e1d878b963f411dc388ced501601c60f7c6f7; /// @dev The address for the WETH9 contract on Ethereum mainnet. address internal constant WETH9 = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; /// @dev The canonical Permit2 address. /// [Github](https://github.com/Uniswap/permit2) /// [Etherscan](https://etherscan.io/address/0x000000000022D473030F116dDEE9F6B43aC78BA3) address internal constant PERMIT2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ETH OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // If the ETH transfer MUST succeed with a reasonable gas budget, use the force variants. // // The regular variants: // - Forwards all remaining gas to the target. // - Reverts if the target reverts. // - Reverts if the current contract has insufficient balance. // // The force variants: // - Forwards with an optional gas stipend // (defaults to `GAS_STIPEND_NO_GRIEF`, which is sufficient for most cases). // - If the target reverts, or if the gas stipend is exhausted, // creates a temporary contract to force send the ETH via `SELFDESTRUCT`. // Future compatible with `SENDALL`: https://eips.ethereum.org/EIPS/eip-4758. // - Reverts if the current contract has insufficient balance. // // The try variants: // - Forwards with a mandatory gas stipend. // - Instead of reverting, returns whether the transfer succeeded. /// @dev Sends `amount` (in wei) ETH to `to`. function safeTransferETH(address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { if iszero(call(gas(), to, amount, codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`. revert(0x1c, 0x04) } } } /// @dev Sends all the ETH in the current contract to `to`. function safeTransferAllETH(address to) internal { /// @solidity memory-safe-assembly assembly { // Transfer all the ETH and check if it succeeded or not. if iszero(call(gas(), to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`. revert(0x1c, 0x04) } } } /// @dev Force sends `amount` (in wei) ETH to `to`, with a `gasStipend`. function forceSafeTransferETH(address to, uint256 amount, uint256 gasStipend) internal { /// @solidity memory-safe-assembly assembly { if lt(selfbalance(), amount) { mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`. revert(0x1c, 0x04) } if iszero(call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, to) // Store the address in scratch space. mstore8(0x0b, 0x73) // Opcode `PUSH20`. mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`. if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation. } } } /// @dev Force sends all the ETH in the current contract to `to`, with a `gasStipend`. function forceSafeTransferAllETH(address to, uint256 gasStipend) internal { /// @solidity memory-safe-assembly assembly { if iszero(call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, to) // Store the address in scratch space. mstore8(0x0b, 0x73) // Opcode `PUSH20`. mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`. if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation. } } } /// @dev Force sends `amount` (in wei) ETH to `to`, with `GAS_STIPEND_NO_GRIEF`. function forceSafeTransferETH(address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { if lt(selfbalance(), amount) { mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`. revert(0x1c, 0x04) } if iszero(call(GAS_STIPEND_NO_GRIEF, to, amount, codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, to) // Store the address in scratch space. mstore8(0x0b, 0x73) // Opcode `PUSH20`. mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`. if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation. } } } /// @dev Force sends all the ETH in the current contract to `to`, with `GAS_STIPEND_NO_GRIEF`. function forceSafeTransferAllETH(address to) internal { /// @solidity memory-safe-assembly assembly { // forgefmt: disable-next-item if iszero(call(GAS_STIPEND_NO_GRIEF, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, to) // Store the address in scratch space. mstore8(0x0b, 0x73) // Opcode `PUSH20`. mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`. if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation. } } } /// @dev Sends `amount` (in wei) ETH to `to`, with a `gasStipend`. function trySafeTransferETH(address to, uint256 amount, uint256 gasStipend) internal returns (bool success) { /// @solidity memory-safe-assembly assembly { success := call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00) } } /// @dev Sends all the ETH in the current contract to `to`, with a `gasStipend`. function trySafeTransferAllETH(address to, uint256 gasStipend) internal returns (bool success) { /// @solidity memory-safe-assembly assembly { success := call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ERC20 OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Sends `amount` of ERC20 `token` from `from` to `to`. /// Reverts upon failure. /// /// The `from` account must have at least `amount` approved for /// the current contract to manage. function safeTransferFrom(address token, address from, address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x60, amount) // Store the `amount` argument. mstore(0x40, to) // Store the `to` argument. mstore(0x2c, shl(96, from)) // Store the `from` argument. mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`. let success := call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20) if iszero(and(eq(mload(0x00), 1), success)) { if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) { mstore(0x00, 0x7939f424) // `TransferFromFailed()`. revert(0x1c, 0x04) } } mstore(0x60, 0) // Restore the zero slot to zero. mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Sends `amount` of ERC20 `token` from `from` to `to`. /// /// The `from` account must have at least `amount` approved for the current contract to manage. function trySafeTransferFrom(address token, address from, address to, uint256 amount) internal returns (bool success) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x60, amount) // Store the `amount` argument. mstore(0x40, to) // Store the `to` argument. mstore(0x2c, shl(96, from)) // Store the `from` argument. mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`. success := call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20) if iszero(and(eq(mload(0x00), 1), success)) { success := lt(or(iszero(extcodesize(token)), returndatasize()), success) } mstore(0x60, 0) // Restore the zero slot to zero. mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Sends all of ERC20 `token` from `from` to `to`. /// Reverts upon failure. /// /// The `from` account must have their entire balance approved for the current contract to manage. function safeTransferAllFrom(address token, address from, address to) internal returns (uint256 amount) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x40, to) // Store the `to` argument. mstore(0x2c, shl(96, from)) // Store the `from` argument. mstore(0x0c, 0x70a08231000000000000000000000000) // `balanceOf(address)`. // Read the balance, reverting upon failure. if iszero( and( // The arguments of `and` are evaluated from right to left. gt(returndatasize(), 0x1f), // At least 32 bytes returned. staticcall(gas(), token, 0x1c, 0x24, 0x60, 0x20) ) ) { mstore(0x00, 0x7939f424) // `TransferFromFailed()`. revert(0x1c, 0x04) } mstore(0x00, 0x23b872dd) // `transferFrom(address,address,uint256)`. amount := mload(0x60) // The `amount` is already at 0x60. We'll need to return it. // Perform the transfer, reverting upon failure. let success := call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20) if iszero(and(eq(mload(0x00), 1), success)) { if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) { mstore(0x00, 0x7939f424) // `TransferFromFailed()`. revert(0x1c, 0x04) } } mstore(0x60, 0) // Restore the zero slot to zero. mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Sends `amount` of ERC20 `token` from the current contract to `to`. /// Reverts upon failure. function safeTransfer(address token, address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { mstore(0x14, to) // Store the `to` argument. mstore(0x34, amount) // Store the `amount` argument. mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`. // Perform the transfer, reverting upon failure. let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) if iszero(and(eq(mload(0x00), 1), success)) { if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) { mstore(0x00, 0x90b8ec18) // `TransferFailed()`. revert(0x1c, 0x04) } } mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten. } } /// @dev Sends all of ERC20 `token` from the current contract to `to`. /// Reverts upon failure. function safeTransferAll(address token, address to) internal returns (uint256 amount) { /// @solidity memory-safe-assembly assembly { mstore(0x00, 0x70a08231) // Store the function selector of `balanceOf(address)`. mstore(0x20, address()) // Store the address of the current contract. // Read the balance, reverting upon failure. if iszero( and( // The arguments of `and` are evaluated from right to left. gt(returndatasize(), 0x1f), // At least 32 bytes returned. staticcall(gas(), token, 0x1c, 0x24, 0x34, 0x20) ) ) { mstore(0x00, 0x90b8ec18) // `TransferFailed()`. revert(0x1c, 0x04) } mstore(0x14, to) // Store the `to` argument. amount := mload(0x34) // The `amount` is already at 0x34. We'll need to return it. mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`. // Perform the transfer, reverting upon failure. let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) if iszero(and(eq(mload(0x00), 1), success)) { if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) { mstore(0x00, 0x90b8ec18) // `TransferFailed()`. revert(0x1c, 0x04) } } mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten. } } /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract. /// Reverts upon failure. function safeApprove(address token, address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { mstore(0x14, to) // Store the `to` argument. mstore(0x34, amount) // Store the `amount` argument. mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`. let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) if iszero(and(eq(mload(0x00), 1), success)) { if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) { mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`. revert(0x1c, 0x04) } } mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten. } } /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract. /// If the initial attempt to approve fails, attempts to reset the approved amount to zero, /// then retries the approval again (some tokens, e.g. USDT, requires this). /// Reverts upon failure. function safeApproveWithRetry(address token, address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { mstore(0x14, to) // Store the `to` argument. mstore(0x34, amount) // Store the `amount` argument. mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`. // Perform the approval, retrying upon failure. let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) if iszero(and(eq(mload(0x00), 1), success)) { if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) { mstore(0x34, 0) // Store 0 for the `amount`. mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`. pop(call(gas(), token, 0, 0x10, 0x44, codesize(), 0x00)) // Reset the approval. mstore(0x34, amount) // Store back the original `amount`. // Retry the approval, reverting upon failure. success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) if iszero(and(eq(mload(0x00), 1), success)) { // Check the `extcodesize` again just in case the token selfdestructs lol. if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) { mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`. revert(0x1c, 0x04) } } } } mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten. } } /// @dev Returns the amount of ERC20 `token` owned by `account`. /// Returns zero if the `token` does not exist. function balanceOf(address token, address account) internal view returns (uint256 amount) { /// @solidity memory-safe-assembly assembly { mstore(0x14, account) // Store the `account` argument. mstore(0x00, 0x70a08231000000000000000000000000) // `balanceOf(address)`. amount := mul( // The arguments of `mul` are evaluated from right to left. mload(0x20), and( // The arguments of `and` are evaluated from right to left. gt(returndatasize(), 0x1f), // At least 32 bytes returned. staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20) ) ) } } /// @dev Returns the total supply of the `token`. /// Reverts if the token does not exist or does not implement `totalSupply()`. function totalSupply(address token) internal view returns (uint256 result) { /// @solidity memory-safe-assembly assembly { mstore(0x00, 0x18160ddd) // `totalSupply()`. if iszero( and(gt(returndatasize(), 0x1f), staticcall(gas(), token, 0x1c, 0x04, 0x00, 0x20)) ) { mstore(0x00, 0x54cd9435) // `TotalSupplyQueryFailed()`. revert(0x1c, 0x04) } result := mload(0x00) } } /// @dev Sends `amount` of ERC20 `token` from `from` to `to`. /// If the initial attempt fails, try to use Permit2 to transfer the token. /// Reverts upon failure. /// /// The `from` account must have at least `amount` approved for the current contract to manage. function safeTransferFrom2(address token, address from, address to, uint256 amount) internal { if (!trySafeTransferFrom(token, from, to, amount)) { permit2TransferFrom(token, from, to, amount); } } /// @dev Sends `amount` of ERC20 `token` from `from` to `to` via Permit2. /// Reverts upon failure. function permit2TransferFrom(address token, address from, address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) mstore(add(m, 0x74), shr(96, shl(96, token))) mstore(add(m, 0x54), amount) mstore(add(m, 0x34), to) mstore(add(m, 0x20), shl(96, from)) // `transferFrom(address,address,uint160,address)`. mstore(m, 0x36c78516000000000000000000000000) let p := PERMIT2 let exists := eq(chainid(), 1) if iszero(exists) { exists := iszero(iszero(extcodesize(p))) } if iszero( and( call(gas(), p, 0, add(m, 0x10), 0x84, codesize(), 0x00), lt(iszero(extcodesize(token)), exists) // Token has code and Permit2 exists. ) ) { mstore(0x00, 0x7939f4248757f0fd) // `TransferFromFailed()` or `Permit2AmountOverflow()`. revert(add(0x18, shl(2, iszero(iszero(shr(160, amount))))), 0x04) } } } /// @dev Permit a user to spend a given amount of /// another user's tokens via native EIP-2612 permit if possible, falling /// back to Permit2 if native permit fails or is not implemented on the token. function permit2( address token, address owner, address spender, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { bool success; /// @solidity memory-safe-assembly assembly { for {} shl(96, xor(token, WETH9)) {} { mstore(0x00, 0x3644e515) // `DOMAIN_SEPARATOR()`. if iszero( and( // The arguments of `and` are evaluated from right to left. lt(iszero(mload(0x00)), eq(returndatasize(), 0x20)), // Returns 1 non-zero word. // Gas stipend to limit gas burn for tokens that don't refund gas when // an non-existing function is called. 5K should be enough for a SLOAD. staticcall(5000, token, 0x1c, 0x04, 0x00, 0x20) ) ) { break } // After here, we can be sure that token is a contract. let m := mload(0x40) mstore(add(m, 0x34), spender) mstore(add(m, 0x20), shl(96, owner)) mstore(add(m, 0x74), deadline) if eq(mload(0x00), DAI_DOMAIN_SEPARATOR) { mstore(0x14, owner) mstore(0x00, 0x7ecebe00000000000000000000000000) // `nonces(address)`. mstore( add(m, 0x94), lt(iszero(amount), staticcall(gas(), token, 0x10, 0x24, add(m, 0x54), 0x20)) ) mstore(m, 0x8fcbaf0c000000000000000000000000) // `IDAIPermit.permit`. // `nonces` is already at `add(m, 0x54)`. // `amount != 0` is already stored at `add(m, 0x94)`. mstore(add(m, 0xb4), and(0xff, v)) mstore(add(m, 0xd4), r) mstore(add(m, 0xf4), s) success := call(gas(), token, 0, add(m, 0x10), 0x104, codesize(), 0x00) break } mstore(m, 0xd505accf000000000000000000000000) // `IERC20Permit.permit`. mstore(add(m, 0x54), amount) mstore(add(m, 0x94), and(0xff, v)) mstore(add(m, 0xb4), r) mstore(add(m, 0xd4), s) success := call(gas(), token, 0, add(m, 0x10), 0xe4, codesize(), 0x00) break } } if (!success) simplePermit2(token, owner, spender, amount, deadline, v, r, s); } /// @dev Simple permit on the Permit2 contract. function simplePermit2( address token, address owner, address spender, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) mstore(m, 0x927da105) // `allowance(address,address,address)`. { let addressMask := shr(96, not(0)) mstore(add(m, 0x20), and(addressMask, owner)) mstore(add(m, 0x40), and(addressMask, token)) mstore(add(m, 0x60), and(addressMask, spender)) mstore(add(m, 0xc0), and(addressMask, spender)) } let p := mul(PERMIT2, iszero(shr(160, amount))) if iszero( and( // The arguments of `and` are evaluated from right to left. gt(returndatasize(), 0x5f), // Returns 3 words: `amount`, `expiration`, `nonce`. staticcall(gas(), p, add(m, 0x1c), 0x64, add(m, 0x60), 0x60) ) ) { mstore(0x00, 0x6b836e6b8757f0fd) // `Permit2Failed()` or `Permit2AmountOverflow()`. revert(add(0x18, shl(2, iszero(p))), 0x04) } mstore(m, 0x2b67b570) // `Permit2.permit` (PermitSingle variant). // `owner` is already `add(m, 0x20)`. // `token` is already at `add(m, 0x40)`. mstore(add(m, 0x60), amount) mstore(add(m, 0x80), 0xffffffffffff) // `expiration = type(uint48).max`. // `nonce` is already at `add(m, 0xa0)`. // `spender` is already at `add(m, 0xc0)`. mstore(add(m, 0xe0), deadline) mstore(add(m, 0x100), 0x100) // `signature` offset. mstore(add(m, 0x120), 0x41) // `signature` length. mstore(add(m, 0x140), r) mstore(add(m, 0x160), s) mstore(add(m, 0x180), shl(248, v)) if iszero( // Revert if token does not have code, or if the call fails. mul(extcodesize(token), call(gas(), p, 0, add(m, 0x1c), 0x184, codesize(), 0x00))) { mstore(0x00, 0x6b836e6b) // `Permit2Failed()`. revert(0x1c, 0x04) } } } /// @dev Approves `spender` to spend `amount` of `token` for `address(this)`. function permit2Approve(address token, address spender, uint160 amount, uint48 expiration) internal { /// @solidity memory-safe-assembly assembly { let addressMask := shr(96, not(0)) let m := mload(0x40) mstore(m, 0x87517c45) // `approve(address,address,uint160,uint48)`. mstore(add(m, 0x20), and(addressMask, token)) mstore(add(m, 0x40), and(addressMask, spender)) mstore(add(m, 0x60), and(addressMask, amount)) mstore(add(m, 0x80), and(0xffffffffffff, expiration)) if iszero(call(gas(), PERMIT2, 0, add(m, 0x1c), 0xa0, codesize(), 0x00)) { mstore(0x00, 0x324f14ae) // `Permit2ApproveFailed()`. revert(0x1c, 0x04) } } } /// @dev Revokes an approval for `token` and `spender` for `address(this)`. function permit2Lockdown(address token, address spender) internal { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) mstore(m, 0xcc53287f) // `Permit2.lockdown`. mstore(add(m, 0x20), 0x20) // Offset of the `approvals`. mstore(add(m, 0x40), 1) // `approvals.length`. mstore(add(m, 0x60), shr(96, shl(96, token))) mstore(add(m, 0x80), shr(96, shl(96, spender))) if iszero(call(gas(), PERMIT2, 0, add(m, 0x1c), 0xa0, codesize(), 0x00)) { mstore(0x00, 0x96b3de23) // `Permit2LockdownFailed()`. revert(0x1c, 0x04) } } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IRateProvider { function rate(address token) external view returns (uint256); } /// @dev returns (rate, quote token decimals) interface IRateProviderV2 { function rate(address token) external view returns (uint256, uint8); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /* solhint-disable */ /** * @dev Exponentiation and logarithm functions for 18 decimal fixed point numbers (both base and exponent/argument). * @dev forked from https://github.com/balancer/balancer-v2-monorepo/blob/599b0cd8f744e1eabef3600d79a2c2b0aea3ddcb/pkg/solidity-utils/contracts/math/LogExpMath.sol * * Exponentiation and logarithm with arbitrary bases (x^y and log_x(y)) are implemented by conversion to natural * exponentiation and logarithm (where the base is Euler's number). * * @author Fernando Martinelli - @fernandomartinelli * @author Sergio Yuhjtman - @sergioyuhjtman * @author Daniel Fernandez - @dmf7z */ library LogExpMath { // All fixed point multiplications and divisions are inlined. This means we need to divide by ONE when multiplying // two numbers, and multiply by ONE when dividing them. // All arguments and return values are 18 decimal fixed point numbers. int256 constant ONE_18 = 1e18; // Internally, intermediate values are computed with higher precision as 20 decimal fixed point numbers, and in the // case of ln36, 36 decimals. int256 constant ONE_20 = 1e20; int256 constant ONE_36 = 1e36; // The domain of natural exponentiation is bound by the word size and number of decimals used. // // Because internally the result will be stored using 20 decimals, the largest possible result is // (2^255 - 1) / 10^20, which makes the largest exponent ln((2^255 - 1) / 10^20) = 130.700829182905140221. // The smallest possible result is 10^(-18), which makes largest negative argument // ln(10^(-18)) = -41.446531673892822312. // We use 130.0 and -41.0 to have some safety margin. int256 constant MAX_NATURAL_EXPONENT = 130e18; int256 constant MIN_NATURAL_EXPONENT = -41e18; // Bounds for ln_36's argument. Both ln(0.9) and ln(1.1) can be represented with 36 decimal places in a fixed point // 256 bit integer. int256 constant LN_36_LOWER_BOUND = ONE_18 - 1e17; int256 constant LN_36_UPPER_BOUND = ONE_18 + 1e17; uint256 constant MILD_EXPONENT_BOUND = 2 ** 254 / uint256(ONE_20); // 18 decimal constants int256 constant x0 = 128_000_000_000_000_000_000; // 2ˆ7 int256 constant a0 = 38_877_084_059_945_950_922_200_000_000_000_000_000_000_000_000_000_000_000; // eˆ(x0) (no decimals) int256 constant x1 = 64_000_000_000_000_000_000; // 2ˆ6 int256 constant a1 = 6_235_149_080_811_616_882_910_000_000; // eˆ(x1) (no decimals) // 20 decimal constants int256 constant x2 = 3_200_000_000_000_000_000_000; // 2ˆ5 int256 constant a2 = 7_896_296_018_268_069_516_100_000_000_000_000; // eˆ(x2) int256 constant x3 = 1_600_000_000_000_000_000_000; // 2ˆ4 int256 constant a3 = 888_611_052_050_787_263_676_000_000; // eˆ(x3) int256 constant x4 = 800_000_000_000_000_000_000; // 2ˆ3 int256 constant a4 = 298_095_798_704_172_827_474_000; // eˆ(x4) int256 constant x5 = 400_000_000_000_000_000_000; // 2ˆ2 int256 constant a5 = 5_459_815_003_314_423_907_810; // eˆ(x5) int256 constant x6 = 200_000_000_000_000_000_000; // 2ˆ1 int256 constant a6 = 738_905_609_893_065_022_723; // eˆ(x6) int256 constant x7 = 100_000_000_000_000_000_000; // 2ˆ0 int256 constant a7 = 271_828_182_845_904_523_536; // eˆ(x7) int256 constant x8 = 50_000_000_000_000_000_000; // 2ˆ-1 int256 constant a8 = 164_872_127_070_012_814_685; // eˆ(x8) int256 constant x9 = 25_000_000_000_000_000_000; // 2ˆ-2 int256 constant a9 = 128_402_541_668_774_148_407; // eˆ(x9) int256 constant x10 = 12_500_000_000_000_000_000; // 2ˆ-3 int256 constant a10 = 113_314_845_306_682_631_683; // eˆ(x10) int256 constant x11 = 6_250_000_000_000_000_000; // 2ˆ-4 int256 constant a11 = 106_449_445_891_785_942_956; // eˆ(x11) /** * @dev Exponentiation (x^y) with unsigned 18 decimal fixed point base and exponent. * * Reverts if ln(x) * y is smaller than `MIN_NATURAL_EXPONENT`, or larger than `MAX_NATURAL_EXPONENT`. */ function pow(uint256 x, uint256 y) internal pure returns (uint256) { if (y == 0) { // We solve the 0^0 indetermination by making it equal one. return uint256(ONE_18); } if (x == 0) { return 0; } // Instead of computing x^y directly, we instead rely on the properties of logarithms and exponentiation to // arrive at that result. In particular, exp(ln(x)) = x, and ln(x^y) = y * ln(x). This means // x^y = exp(y * ln(x)). // The ln function takes a signed value, so we need to make sure x fits in the signed 256 bit range. require(x >> 255 == 0, "X out of bounds"); int256 x_int256 = int256(x); // We will compute y * ln(x) in a single step. Depending on the value of x, we can either use ln or ln_36. In // both cases, we leave the division by ONE_18 (due to fixed point multiplication) to the end. // This prevents y * ln(x) from overflowing, and at the same time guarantees y fits in the signed 256 bit range. require(y < MILD_EXPONENT_BOUND, "Y out of bounds"); int256 y_int256 = int256(y); int256 logx_times_y; if (LN_36_LOWER_BOUND < x_int256 && x_int256 < LN_36_UPPER_BOUND) { int256 ln_36_x = _ln_36(x_int256); // ln_36_x has 36 decimal places, so multiplying by y_int256 isn't as straightforward, since we can't just // bring y_int256 to 36 decimal places, as it might overflow. Instead, we perform two 18 decimal // multiplications and add the results: one with the first 18 decimals of ln_36_x, and one with the // (downscaled) last 18 decimals. logx_times_y = ((ln_36_x / ONE_18) * y_int256 + ((ln_36_x % ONE_18) * y_int256) / ONE_18); } else { logx_times_y = _ln(x_int256) * y_int256; } logx_times_y /= ONE_18; // Finally, we compute exp(y * ln(x)) to arrive at x^y require(MIN_NATURAL_EXPONENT <= logx_times_y && logx_times_y <= MAX_NATURAL_EXPONENT, "Product out of bounds"); return uint256(exp(logx_times_y)); } /** * @dev Natural exponentiation (e^x) with signed 18 decimal fixed point exponent. * * Reverts if `x` is smaller than MIN_NATURAL_EXPONENT, or larger than `MAX_NATURAL_EXPONENT`. */ function exp(int256 x) internal pure returns (int256) { require(x >= MIN_NATURAL_EXPONENT && x <= MAX_NATURAL_EXPONENT, "Invalid Exponent"); if (x < 0) { // We only handle positive exponents: e^(-x) is computed as 1 / e^x. We can safely make x positive since it // fits in the signed 256 bit range (as it is larger than MIN_NATURAL_EXPONENT). // Fixed point division requires multiplying by ONE_18. return ((ONE_18 * ONE_18) / exp(-x)); } // First, we use the fact that e^(x+y) = e^x * e^y to decompose x into a sum of powers of two, which we call x_n, // where x_n == 2^(7 - n), and e^x_n = a_n has been precomputed. We choose the first x_n, x0, to equal 2^7 // because all larger powers are larger than MAX_NATURAL_EXPONENT, and therefore not present in the // decomposition. // At the end of this process we will have the product of all e^x_n = a_n that apply, and the remainder of this // decomposition, which will be lower than the smallest x_n. // exp(x) = k_0 * a_0 * k_1 * a_1 * ... + k_n * a_n * exp(remainder), where each k_n equals either 0 or 1. // We mutate x by subtracting x_n, making it the remainder of the decomposition. // The first two a_n (e^(2^7) and e^(2^6)) are too large if stored as 18 decimal numbers, and could cause // intermediate overflows. Instead we store them as plain integers, with 0 decimals. // Additionally, x0 + x1 is larger than MAX_NATURAL_EXPONENT, which means they will not both be present in the // decomposition. // For each x_n, we test if that term is present in the decomposition (if x is larger than it), and if so deduct // it and compute the accumulated product. int256 firstAN; if (x >= x0) { x -= x0; firstAN = a0; } else if (x >= x1) { x -= x1; firstAN = a1; } else { firstAN = 1; // One with no decimal places } // We now transform x into a 20 decimal fixed point number, to have enhanced precision when computing the // smaller terms. x *= 100; // `product` is the accumulated product of all a_n (except a0 and a1), which starts at 20 decimal fixed point // one. Recall that fixed point multiplication requires dividing by ONE_20. int256 product = ONE_20; if (x >= x2) { x -= x2; product = (product * a2) / ONE_20; } if (x >= x3) { x -= x3; product = (product * a3) / ONE_20; } if (x >= x4) { x -= x4; product = (product * a4) / ONE_20; } if (x >= x5) { x -= x5; product = (product * a5) / ONE_20; } if (x >= x6) { x -= x6; product = (product * a6) / ONE_20; } if (x >= x7) { x -= x7; product = (product * a7) / ONE_20; } if (x >= x8) { x -= x8; product = (product * a8) / ONE_20; } if (x >= x9) { x -= x9; product = (product * a9) / ONE_20; } // x10 and x11 are unnecessary here since we have high enough precision already. // Now we need to compute e^x, where x is small (in particular, it is smaller than x9). We use the Taylor series // expansion for e^x: 1 + x + (x^2 / 2!) + (x^3 / 3!) + ... + (x^n / n!). int256 seriesSum = ONE_20; // The initial one in the sum, with 20 decimal places. int256 term; // Each term in the sum, where the nth term is (x^n / n!). // The first term is simply x. term = x; seriesSum += term; // Each term (x^n / n!) equals the previous one times x, divided by n. Since x is a fixed point number, // multiplying by it requires dividing by ONE_20, but dividing by the non-fixed point n values does not. term = ((term * x) / ONE_20) / 2; seriesSum += term; term = ((term * x) / ONE_20) / 3; seriesSum += term; term = ((term * x) / ONE_20) / 4; seriesSum += term; term = ((term * x) / ONE_20) / 5; seriesSum += term; term = ((term * x) / ONE_20) / 6; seriesSum += term; term = ((term * x) / ONE_20) / 7; seriesSum += term; term = ((term * x) / ONE_20) / 8; seriesSum += term; term = ((term * x) / ONE_20) / 9; seriesSum += term; term = ((term * x) / ONE_20) / 10; seriesSum += term; term = ((term * x) / ONE_20) / 11; seriesSum += term; term = ((term * x) / ONE_20) / 12; seriesSum += term; // 12 Taylor terms are sufficient for 18 decimal precision. // We now have the first a_n (with no decimals), and the product of all other a_n present, and the Taylor // approximation of the exponentiation of the remainder (both with 20 decimals). All that remains is to multiply // all three (one 20 decimal fixed point multiplication, dividing by ONE_20, and one integer multiplication), // and then drop two digits to return an 18 decimal value. return (((product * seriesSum) / ONE_20) * firstAN) / 100; } /** * @dev Logarithm (log(arg, base), with signed 18 decimal fixed point base and argument. */ function log(int256 arg, int256 base) internal pure returns (int256) { // This performs a simple base change: log(arg, base) = ln(arg) / ln(base). // Both logBase and logArg are computed as 36 decimal fixed point numbers, either by using ln_36, or by // upscaling. int256 logBase; if (LN_36_LOWER_BOUND < base && base < LN_36_UPPER_BOUND) { logBase = _ln_36(base); } else { logBase = _ln(base) * ONE_18; } int256 logArg; if (LN_36_LOWER_BOUND < arg && arg < LN_36_UPPER_BOUND) { logArg = _ln_36(arg); } else { logArg = _ln(arg) * ONE_18; } // When dividing, we multiply by ONE_18 to arrive at a result with 18 decimal places return (logArg * ONE_18) / logBase; } /** * @dev Natural logarithm (ln(a)) with signed 18 decimal fixed point argument. */ function ln(int256 a) internal pure returns (int256) { // The real natural logarithm is not defined for negative numbers or zero. require(a > 0, "Out of bounds"); if (LN_36_LOWER_BOUND < a && a < LN_36_UPPER_BOUND) { return _ln_36(a) / ONE_18; } else { return _ln(a); } } /** * @dev Internal natural logarithm (ln(a)) with signed 18 decimal fixed point argument. */ function _ln(int256 a) private pure returns (int256) { if (a < ONE_18) { // Since ln(a^k) = k * ln(a), we can compute ln(a) as ln(a) = ln((1/a)^(-1)) = - ln((1/a)). If a is less // than one, 1/a will be greater than one, and this if statement will not be entered in the recursive call. // Fixed point division requires multiplying by ONE_18. return (-_ln((ONE_18 * ONE_18) / a)); } // First, we use the fact that ln^(a * b) = ln(a) + ln(b) to decompose ln(a) into a sum of powers of two, which // we call x_n, where x_n == 2^(7 - n), which are the natural logarithm of precomputed quantities a_n (that is, // ln(a_n) = x_n). We choose the first x_n, x0, to equal 2^7 because the exponential of all larger powers cannot // be represented as 18 fixed point decimal numbers in 256 bits, and are therefore larger than a. // At the end of this process we will have the sum of all x_n = ln(a_n) that apply, and the remainder of this // decomposition, which will be lower than the smallest a_n. // ln(a) = k_0 * x_0 + k_1 * x_1 + ... + k_n * x_n + ln(remainder), where each k_n equals either 0 or 1. // We mutate a by subtracting a_n, making it the remainder of the decomposition. // For reasons related to how `exp` works, the first two a_n (e^(2^7) and e^(2^6)) are not stored as fixed point // numbers with 18 decimals, but instead as plain integers with 0 decimals, so we need to multiply them by // ONE_18 to convert them to fixed point. // For each a_n, we test if that term is present in the decomposition (if a is larger than it), and if so divide // by it and compute the accumulated sum. int256 sum = 0; if (a >= a0 * ONE_18) { a /= a0; // Integer, not fixed point division sum += x0; } if (a >= a1 * ONE_18) { a /= a1; // Integer, not fixed point division sum += x1; } // All other a_n and x_n are stored as 20 digit fixed point numbers, so we convert the sum and a to this format. sum *= 100; a *= 100; // Because further a_n are 20 digit fixed point numbers, we multiply by ONE_20 when dividing by them. if (a >= a2) { a = (a * ONE_20) / a2; sum += x2; } if (a >= a3) { a = (a * ONE_20) / a3; sum += x3; } if (a >= a4) { a = (a * ONE_20) / a4; sum += x4; } if (a >= a5) { a = (a * ONE_20) / a5; sum += x5; } if (a >= a6) { a = (a * ONE_20) / a6; sum += x6; } if (a >= a7) { a = (a * ONE_20) / a7; sum += x7; } if (a >= a8) { a = (a * ONE_20) / a8; sum += x8; } if (a >= a9) { a = (a * ONE_20) / a9; sum += x9; } if (a >= a10) { a = (a * ONE_20) / a10; sum += x10; } if (a >= a11) { a = (a * ONE_20) / a11; sum += x11; } // a is now a small number (smaller than a_11, which roughly equals 1.06). This means we can use a Taylor series // that converges rapidly for values of `a` close to one - the same one used in ln_36. // Let z = (a - 1) / (a + 1). // ln(a) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1)) // Recall that 20 digit fixed point division requires multiplying by ONE_20, and multiplication requires // division by ONE_20. int256 z = ((a - ONE_20) * ONE_20) / (a + ONE_20); int256 z_squared = (z * z) / ONE_20; // num is the numerator of the series: the z^(2 * n + 1) term int256 num = z; // seriesSum holds the accumulated sum of each term in the series, starting with the initial z int256 seriesSum = num; // In each step, the numerator is multiplied by z^2 num = (num * z_squared) / ONE_20; seriesSum += num / 3; num = (num * z_squared) / ONE_20; seriesSum += num / 5; num = (num * z_squared) / ONE_20; seriesSum += num / 7; num = (num * z_squared) / ONE_20; seriesSum += num / 9; num = (num * z_squared) / ONE_20; seriesSum += num / 11; // 6 Taylor terms are sufficient for 36 decimal precision. // Finally, we multiply by 2 (non fixed point) to compute ln(remainder) seriesSum *= 2; // We now have the sum of all x_n present, and the Taylor approximation of the logarithm of the remainder (both // with 20 decimals). All that remains is to sum these two, and then drop two digits to return a 18 decimal // value. return (sum + seriesSum) / 100; } /** * @dev Intrnal high precision (36 decimal places) natural logarithm (ln(x)) with signed 18 decimal fixed point argument, * for x close to one. * * Should only be used if x is between LN_36_LOWER_BOUND and LN_36_UPPER_BOUND. */ function _ln_36(int256 x) private pure returns (int256) { // Since ln(1) = 0, a value of x close to one will yield a very small result, which makes using 36 digits // worthwhile. // First, we transform x to a 36 digit fixed point value. x *= ONE_18; // We will use the following Taylor expansion, which converges very rapidly. Let z = (x - 1) / (x + 1). // ln(x) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1)) // Recall that 36 digit fixed point division requires multiplying by ONE_36, and multiplication requires // division by ONE_36. int256 z = ((x - ONE_36) * ONE_36) / (x + ONE_36); int256 z_squared = (z * z) / ONE_36; // num is the numerator of the series: the z^(2 * n + 1) term int256 num = z; // seriesSum holds the accumulated sum of each term in the series, starting with the initial z int256 seriesSum = num; // In each step, the numerator is multiplied by z^2 num = (num * z_squared) / ONE_36; seriesSum += num / 3; num = (num * z_squared) / ONE_36; seriesSum += num / 5; num = (num * z_squared) / ONE_36; seriesSum += num / 7; num = (num * z_squared) / ONE_36; seriesSum += num / 9; num = (num * z_squared) / ONE_36; seriesSum += num / 11; num = (num * z_squared) / ONE_36; seriesSum += num / 13; num = (num * z_squared) / ONE_36; seriesSum += num / 15; // 8 Taylor terms are sufficient for 36 decimal precision. // All that remains is multiplying by 2 (non fixed point). return seriesSum * 2; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {ERC20} from "../lib/solady/src/tokens/ERC20.sol"; import {Ownable} from "../lib/solady/src/auth/Ownable.sol"; contract PoolToken is ERC20, Ownable { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ error Token__CallerIsNotPool(); error Token__PoolAddressCannotBeZero(); error Token__VaultAddressCannotBeZero(); error Token__RecipientCannotBeZeroAddress(); error Token__PerformanceFeeCannotExceed8000bps(); error Token__PoolAddressAlreadySet(); error Token__VaultAddressAlreadySet(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* EVENTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ event PoolAddressSet(address newPoolAddress); event VaultAddressSet(address newVaultAddress); event PerformanceFeeSet(uint256 performanceFee); event PerformanceFeeRecipientSet(address performanceFeeRecipient); string internal _name; string internal _symbol; uint8 internal _decimals; address public poolAddress; address public vaultAddress; bool private poolAddressSet = false; bool private vaultAddressSet = false; /// @dev performance fee in basis points uint256 public performanceFeeInBps; /// @dev peformance fee recipient address public performanceFeeRecipient; function _checkCallerIsPool() internal view { if (msg.sender != poolAddress) { revert Token__CallerIsNotPool(); } } constructor(string memory name_, string memory symbol_, uint8 decimals_, address owner_) { _name = name_; _symbol = symbol_; _decimals = decimals_; _setOwner(owner_); } function name() public view virtual override returns (string memory) { return _name; } function symbol() public view virtual override returns (string memory) { return _symbol; } function decimals() public view virtual override returns (uint8) { return _decimals; } function mint(address to_, uint256 amount_) public { _checkCallerIsPool(); if (to_ == vaultAddress) { uint256 feeAmount = (amount_ * performanceFeeInBps) / 10_000; _mint(performanceFeeRecipient, feeAmount); _mint(to_, amount_ - feeAmount); } else { _mint(to_, amount_); } } function burn(address from_, uint256 amount_) public { _checkCallerIsPool(); _burn(from_, amount_); } function setPool(address poolAddress_) public onlyOwner { if (poolAddressSet) revert Token__PoolAddressAlreadySet(); if (poolAddress_ == address(0)) revert Token__PoolAddressCannotBeZero(); poolAddress = poolAddress_; poolAddressSet = true; emit PoolAddressSet(poolAddress_); } function setVaultAddress(address vaultAddress_) public onlyOwner { if (vaultAddressSet) revert Token__VaultAddressAlreadySet(); if (vaultAddress_ == address(0)) revert Token__VaultAddressCannotBeZero(); vaultAddress = vaultAddress_; vaultAddressSet = true; emit VaultAddressSet(vaultAddress_); } /** * @notice Sets the performance fee in basis points. * @param fee_ The new performance fee, capped at 8000 basis points. */ function setPerformanceFeeInBps(uint256 fee_) public onlyOwner { if (performanceFeeRecipient == address(0)) revert Token__RecipientCannotBeZeroAddress(); if (fee_ > 8000) revert Token__PerformanceFeeCannotExceed8000bps(); performanceFeeInBps = fee_; emit PerformanceFeeSet(fee_); } /** * @notice Sets the recipient for performance fees. * @param recipient_ The address to receive performance fees. */ function setPerformanceFeeRecipient(address recipient_) public onlyOwner { if (recipient_ == address(0)) revert Token__RecipientCannotBeZeroAddress(); performanceFeeRecipient = recipient_; emit PerformanceFeeRecipientSet(recipient_); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Simple single owner authorization mixin. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/auth/Ownable.sol) /// /// @dev Note: /// This implementation does NOT auto-initialize the owner to `msg.sender`. /// You MUST call the `_initializeOwner` in the constructor / initializer. /// /// While the ownable portion follows /// [EIP-173](https://eips.ethereum.org/EIPS/eip-173) for compatibility, /// the nomenclature for the 2-step ownership handover may be unique to this codebase. abstract contract Ownable { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The caller is not authorized to call the function. error Unauthorized(); /// @dev The `newOwner` cannot be the zero address. error NewOwnerIsZeroAddress(); /// @dev The `pendingOwner` does not have a valid handover request. error NoHandoverRequest(); /// @dev Cannot double-initialize. error AlreadyInitialized(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* EVENTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The ownership is transferred from `oldOwner` to `newOwner`. /// This event is intentionally kept the same as OpenZeppelin's Ownable to be /// compatible with indexers and [EIP-173](https://eips.ethereum.org/EIPS/eip-173), /// despite it not being as lightweight as a single argument event. event OwnershipTransferred(address indexed oldOwner, address indexed newOwner); /// @dev An ownership handover to `pendingOwner` has been requested. event OwnershipHandoverRequested(address indexed pendingOwner); /// @dev The ownership handover to `pendingOwner` has been canceled. event OwnershipHandoverCanceled(address indexed pendingOwner); /// @dev `keccak256(bytes("OwnershipTransferred(address,address)"))`. uint256 private constant _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE = 0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0; /// @dev `keccak256(bytes("OwnershipHandoverRequested(address)"))`. uint256 private constant _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE = 0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d; /// @dev `keccak256(bytes("OwnershipHandoverCanceled(address)"))`. uint256 private constant _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE = 0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* STORAGE */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The owner slot is given by: /// `bytes32(~uint256(uint32(bytes4(keccak256("_OWNER_SLOT_NOT")))))`. /// It is intentionally chosen to be a high value /// to avoid collision with lower slots. /// The choice of manual storage layout is to enable compatibility /// with both regular and upgradeable contracts. bytes32 internal constant _OWNER_SLOT = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927; /// The ownership handover slot of `newOwner` is given by: /// ``` /// mstore(0x00, or(shl(96, user), _HANDOVER_SLOT_SEED)) /// let handoverSlot := keccak256(0x00, 0x20) /// ``` /// It stores the expiry timestamp of the two-step ownership handover. uint256 private constant _HANDOVER_SLOT_SEED = 0x389a75e1; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* INTERNAL FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Override to return true to make `_initializeOwner` prevent double-initialization. function _guardInitializeOwner() internal pure virtual returns (bool guard) {} /// @dev Initializes the owner directly without authorization guard. /// This function must be called upon initialization, /// regardless of whether the contract is upgradeable or not. /// This is to enable generalization to both regular and upgradeable contracts, /// and to save gas in case the initial owner is not the caller. /// For performance reasons, this function will not check if there /// is an existing owner. function _initializeOwner(address newOwner) internal virtual { if (_guardInitializeOwner()) { /// @solidity memory-safe-assembly assembly { let ownerSlot := _OWNER_SLOT if sload(ownerSlot) { mstore(0x00, 0x0dc149f0) // `AlreadyInitialized()`. revert(0x1c, 0x04) } // Clean the upper 96 bits. newOwner := shr(96, shl(96, newOwner)) // Store the new value. sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner)))) // Emit the {OwnershipTransferred} event. log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner) } } else { /// @solidity memory-safe-assembly assembly { // Clean the upper 96 bits. newOwner := shr(96, shl(96, newOwner)) // Store the new value. sstore(_OWNER_SLOT, newOwner) // Emit the {OwnershipTransferred} event. log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner) } } } /// @dev Sets the owner directly without authorization guard. function _setOwner(address newOwner) internal virtual { if (_guardInitializeOwner()) { /// @solidity memory-safe-assembly assembly { let ownerSlot := _OWNER_SLOT // Clean the upper 96 bits. newOwner := shr(96, shl(96, newOwner)) // Emit the {OwnershipTransferred} event. log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner) // Store the new value. sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner)))) } } else { /// @solidity memory-safe-assembly assembly { let ownerSlot := _OWNER_SLOT // Clean the upper 96 bits. newOwner := shr(96, shl(96, newOwner)) // Emit the {OwnershipTransferred} event. log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner) // Store the new value. sstore(ownerSlot, newOwner) } } } /// @dev Throws if the sender is not the owner. function _checkOwner() internal view virtual { /// @solidity memory-safe-assembly assembly { // If the caller is not the stored owner, revert. if iszero(eq(caller(), sload(_OWNER_SLOT))) { mstore(0x00, 0x82b42900) // `Unauthorized()`. revert(0x1c, 0x04) } } } /// @dev Returns how long a two-step ownership handover is valid for in seconds. /// Override to return a different value if needed. /// Made internal to conserve bytecode. Wrap it in a public function if needed. function _ownershipHandoverValidFor() internal view virtual returns (uint64) { return 48 * 3600; } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* PUBLIC UPDATE FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Allows the owner to transfer the ownership to `newOwner`. function transferOwnership(address newOwner) public payable virtual onlyOwner { /// @solidity memory-safe-assembly assembly { if iszero(shl(96, newOwner)) { mstore(0x00, 0x7448fbae) // `NewOwnerIsZeroAddress()`. revert(0x1c, 0x04) } } _setOwner(newOwner); } /// @dev Allows the owner to renounce their ownership. function renounceOwnership() public payable virtual onlyOwner { _setOwner(address(0)); } /// @dev Request a two-step ownership handover to the caller. /// The request will automatically expire in 48 hours (172800 seconds) by default. function requestOwnershipHandover() public payable virtual { unchecked { uint256 expires = block.timestamp + _ownershipHandoverValidFor(); /// @solidity memory-safe-assembly assembly { // Compute and set the handover slot to `expires`. mstore(0x0c, _HANDOVER_SLOT_SEED) mstore(0x00, caller()) sstore(keccak256(0x0c, 0x20), expires) // Emit the {OwnershipHandoverRequested} event. log2(0, 0, _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE, caller()) } } } /// @dev Cancels the two-step ownership handover to the caller, if any. function cancelOwnershipHandover() public payable virtual { /// @solidity memory-safe-assembly assembly { // Compute and set the handover slot to 0. mstore(0x0c, _HANDOVER_SLOT_SEED) mstore(0x00, caller()) sstore(keccak256(0x0c, 0x20), 0) // Emit the {OwnershipHandoverCanceled} event. log2(0, 0, _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE, caller()) } } /// @dev Allows the owner to complete the two-step ownership handover to `pendingOwner`. /// Reverts if there is no existing ownership handover requested by `pendingOwner`. function completeOwnershipHandover(address pendingOwner) public payable virtual onlyOwner { /// @solidity memory-safe-assembly assembly { // Compute and set the handover slot to 0. mstore(0x0c, _HANDOVER_SLOT_SEED) mstore(0x00, pendingOwner) let handoverSlot := keccak256(0x0c, 0x20) // If the handover does not exist, or has expired. if gt(timestamp(), sload(handoverSlot)) { mstore(0x00, 0x6f5e8818) // `NoHandoverRequest()`. revert(0x1c, 0x04) } // Set the handover slot to 0. sstore(handoverSlot, 0) } _setOwner(pendingOwner); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* PUBLIC READ FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the owner of the contract. function owner() public view virtual returns (address result) { /// @solidity memory-safe-assembly assembly { result := sload(_OWNER_SLOT) } } /// @dev Returns the expiry timestamp for the two-step ownership handover to `pendingOwner`. function ownershipHandoverExpiresAt(address pendingOwner) public view virtual returns (uint256 result) { /// @solidity memory-safe-assembly assembly { // Compute the handover slot. mstore(0x0c, _HANDOVER_SLOT_SEED) mstore(0x00, pendingOwner) // Load the handover slot. result := sload(keccak256(0x0c, 0x20)) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* MODIFIERS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Marks a function as only callable by the owner. modifier onlyOwner() virtual { _checkOwner(); _; } }
{ "remappings": [ "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/", "ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/", "erc4626-tests/=lib/erc4626-tests/", "forge-std/=lib/forge-std/src/", "openzeppelin-contracts/=lib/openzeppelin-contracts/", "solady/=lib/solady/src/", "halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/" ], "optimizer": { "enabled": true, "runs": 100 }, "metadata": { "useLiteralContent": false, "bytecodeHash": "ipfs", "appendCBOR": true }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "cancun", "viaIR": true, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"tokenAddress_","type":"address"},{"internalType":"uint256","name":"amplification_","type":"uint256"},{"internalType":"address[]","name":"tokens_","type":"address[]"},{"internalType":"address[]","name":"rateProviders_","type":"address[]"},{"internalType":"uint256[]","name":"weights_","type":"uint256[]"},{"internalType":"address","name":"owner_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadyInitialized","type":"error"},{"inputs":[],"name":"NewOwnerIsZeroAddress","type":"error"},{"inputs":[],"name":"NoHandoverRequest","type":"error"},{"inputs":[],"name":"Pool__AlreadyPaused","type":"error"},{"inputs":[],"name":"Pool__AmountsMustBeNonZero","type":"error"},{"inputs":[],"name":"Pool__BandsOutOfBounds","type":"error"},{"inputs":[],"name":"Pool__CannotBeZeroAddress","type":"error"},{"inputs":[],"name":"Pool__CannotRescuePoolToken","type":"error"},{"inputs":[],"name":"Pool__IndexOutOfBounds","type":"error"},{"inputs":[],"name":"Pool__InitialDepositAmountMustBeNonZero","type":"error"},{"inputs":[],"name":"Pool__InputOutputTokensSame","type":"error"},{"inputs":[],"name":"Pool__InvalidDecimals","type":"error"},{"inputs":[],"name":"Pool__InvalidParams","type":"error"},{"inputs":[],"name":"Pool__InvalidRateProvided","type":"error"},{"inputs":[],"name":"Pool__Killed","type":"error"},{"inputs":[],"name":"Pool__LpAmountSuppliedIsLessThanChangeInSupply","type":"error"},{"inputs":[],"name":"Pool__MaxLimitExceeded","type":"error"},{"inputs":[],"name":"Pool__MustBeInitiatedWithAGreaterThanZero","type":"error"},{"inputs":[],"name":"Pool__MustBeInitiatedWithMoreThanOneToken","type":"error"},{"inputs":[],"name":"Pool__NeedToDepositAtleastOneToken","type":"error"},{"inputs":[],"name":"Pool__NewSupplyIsGreaterThanPrevSupply","type":"error"},{"inputs":[],"name":"Pool__NewWeightsLengthMismatch","type":"error"},{"inputs":[],"name":"Pool__NoConvergence","type":"error"},{"inputs":[],"name":"Pool__NoRate","type":"error"},{"inputs":[],"name":"Pool__NoSurplus","type":"error"},{"inputs":[],"name":"Pool__NotPaused","type":"error"},{"inputs":[],"name":"Pool__Paused","type":"error"},{"inputs":[],"name":"Pool__PoolIsEmpty","type":"error"},{"inputs":[],"name":"Pool__PoolIsFull","type":"error"},{"inputs":[],"name":"Pool__ProposedWeightOutOfRange","type":"error"},{"inputs":[],"name":"Pool__RampActive","type":"error"},{"inputs":[],"name":"Pool__RatioAboveUpperBound","type":"error"},{"inputs":[],"name":"Pool__RatioBelowLowerBound","type":"error"},{"inputs":[],"name":"Pool__SlippageLimitExceeded","type":"error"},{"inputs":[],"name":"Pool__SumOfWeightsMustBeOne","type":"error"},{"inputs":[],"name":"Pool__TokenAlreadyPartOfPool","type":"error"},{"inputs":[],"name":"Pool__TokenDecimalCannotBeZero","type":"error"},{"inputs":[],"name":"Pool__WeightOutOfBounds","type":"error"},{"inputs":[],"name":"Pool__WeightsDoNotAddUp","type":"error"},{"inputs":[],"name":"Pool__ZeroAmount","type":"error"},{"inputs":[],"name":"Reentrancy","type":"error"},{"inputs":[],"name":"Unauthorized","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"amountsIn","type":"uint256[]"},{"indexed":false,"internalType":"uint256","name":"lpAmount","type":"uint256"}],"name":"AddLiquidity","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"index","type":"uint256"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"address","name":"rateProvider","type":"address"},{"indexed":false,"internalType":"uint256","name":"rate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"weight","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"AddToken","type":"event"},{"anonymous":false,"inputs":[],"name":"Kill","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"OwnershipHandoverCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"OwnershipHandoverRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"}],"name":"Pause","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"token","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"rate","type":"uint256"}],"name":"RateUpdate","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"lpAmount","type":"uint256"}],"name":"RemoveLiquidity","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"token","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountOut","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"lpAmount","type":"uint256"}],"name":"RemoveLiquiditySingle","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"uint256","name":"roles","type":"uint256"}],"name":"RolesUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"address","name":"guardian","type":"address"}],"name":"SetGuardian","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amplification","type":"uint256"},{"indexed":false,"internalType":"uint256[]","name":"weights","type":"uint256[]"},{"indexed":false,"internalType":"uint256","name":"duration","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"start","type":"uint256"}],"name":"SetRamp","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"rampStep","type":"uint256"}],"name":"SetRampStep","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"token","type":"uint256"},{"indexed":false,"internalType":"address","name":"rateProvider","type":"address"}],"name":"SetRateProvider","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"vaultAddress","type":"address"}],"name":"SetStaking","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"rate","type":"uint256"}],"name":"SetSwapFeeRate","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"token","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"lower","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"upper","type":"uint256"}],"name":"SetWeightBand","type":"event"},{"anonymous":false,"inputs":[],"name":"StopRamp","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokenOut","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountOut","type":"uint256"}],"name":"Swap","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenIndex","type":"uint256"},{"indexed":true,"internalType":"address","name":"token","type":"address"}],"name":"TokenRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"}],"name":"Unpause","type":"event"},{"inputs":[{"internalType":"uint256[]","name":"amounts_","type":"uint256[]"},{"internalType":"uint256","name":"minLpAmount_","type":"uint256"},{"internalType":"address","name":"receiver_","type":"address"}],"name":"addLiquidity","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"amounts_","type":"uint256[]"},{"internalType":"uint256","name":"minLpAmount_","type":"uint256"},{"internalType":"address","name":"owner_","type":"address"},{"internalType":"address","name":"receiver_","type":"address"}],"name":"addLiquidityFor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token_","type":"address"},{"internalType":"address","name":"rateProvider_","type":"address"},{"internalType":"uint256","name":"weight_","type":"uint256"},{"internalType":"uint256","name":"lower_","type":"uint256"},{"internalType":"uint256","name":"upper_","type":"uint256"},{"internalType":"uint256","name":"amount_","type":"uint256"},{"internalType":"uint256","name":"amplification_","type":"uint256"},{"internalType":"uint256","name":"minLpAmount_","type":"uint256"},{"internalType":"address","name":"receiver_","type":"address"}],"name":"addToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"amplification","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user_","type":"address"},{"internalType":"uint256","name":"role_","type":"uint256"}],"name":"assignRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cancelOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"completeOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"roles","type":"uint256"}],"name":"grantRoles","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"roles","type":"uint256"}],"name":"hasAllRoles","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"roles","type":"uint256"}],"name":"hasAnyRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"kill","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"killed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"numTokens","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"result","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"ownershipHandoverExpiresAt","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"packedVirtualBalances","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"token_","type":"uint256"}],"name":"packedWeight","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rampLastTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rampStep","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rampStopTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"token_","type":"uint256"}],"name":"rate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"rateMultipliers","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"rateProviders","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"lpAmount_","type":"uint256"},{"internalType":"uint256[]","name":"minAmounts_","type":"uint256[]"},{"internalType":"address","name":"receiver_","type":"address"}],"name":"removeLiquidity","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"token_","type":"uint256"},{"internalType":"uint256","name":"lpAmount_","type":"uint256"},{"internalType":"uint256","name":"minTokenOutAmount_","type":"uint256"},{"internalType":"address","name":"receiver_","type":"address"}],"name":"removeLiquiditySingle","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenIndex_","type":"uint256"},{"internalType":"uint256","name":"lpAmount_","type":"uint256"},{"internalType":"uint256","name":"amplification_","type":"uint256"},{"internalType":"uint256[]","name":"newWeights_","type":"uint256[]"},{"internalType":"uint256","name":"duration_","type":"uint256"}],"name":"removeToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"roles","type":"uint256"}],"name":"renounceRoles","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"requestOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token_","type":"address"},{"internalType":"address","name":"receiver_","type":"address"}],"name":"rescue","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user_","type":"address"},{"internalType":"uint256","name":"role_","type":"uint256"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"roles","type":"uint256"}],"name":"revokeRoles","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"rolesOf","outputs":[{"internalType":"uint256","name":"roles","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amplification_","type":"uint256"},{"internalType":"uint256[]","name":"weights_","type":"uint256[]"},{"internalType":"uint256","name":"duration_","type":"uint256"},{"internalType":"uint256","name":"start_","type":"uint256"}],"name":"setRamp","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"rampStep_","type":"uint256"}],"name":"setRampStep","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"token_","type":"uint256"},{"internalType":"address","name":"rateProvider_","type":"address"}],"name":"setRateProvider","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"feeRate_","type":"uint256"}],"name":"setSwapFeeRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"vaultAddress_","type":"address"}],"name":"setVaultAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"tokens_","type":"uint256[]"},{"internalType":"uint256[]","name":"lower_","type":"uint256[]"},{"internalType":"uint256[]","name":"upper_","type":"uint256[]"}],"name":"setWeightBands","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"token_","type":"uint256"},{"internalType":"address","name":"receiver_","type":"address"}],"name":"skim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stopRamp","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"supply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenIn_","type":"uint256"},{"internalType":"uint256","name":"tokenOut_","type":"uint256"},{"internalType":"uint256","name":"tokenInAmount_","type":"uint256"},{"internalType":"uint256","name":"minTokenOutAmount_","type":"uint256"},{"internalType":"address","name":"receiver_","type":"address"}],"name":"swap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"swapFeeRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"targetAmplification","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"tokens","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"tokens_","type":"uint256[]"}],"name":"updateRates","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"updateWeights","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"vaultAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"token_","type":"uint256"}],"name":"virtualBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"virtualBalanceProdSum","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"token_","type":"uint256"}],"name":"weight","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
6080806040523461030657615cd2803803809161001c8285610453565b833981019060c081830312610306576100348161048a565b91602082015191604081015160018060401b03811161030657826100599183016104b5565b60608201519091906001600160401b038111610306578361007b9183016104b5565b60808201519091906001600160401b0381116103065781019380601f860112156103065784516100aa8161049e565b956100b86040519788610453565b81875260208088019260051b82010192831161030657602001905b8282106104435750505060a06100e9910161048a565b946001600160a01b031680156102b457825194602086116104345760028610610425578583511480159061041a575b6102b457670de0b6b3a7640000811061040b575f55846001555f955f965b60208810156103f45786881461032c576001600160a01b03610158898761051a565b51161561031d576001600160a01b03610171898761051a565b5160058a0180546001600160a01b0319166001600160a01b039390921683169190911790556101a0898661051a565b51161561031d576001600160a01b036101b9898661051a565b5160458a0180546001600160a01b0319166001600160a01b039390921683169190911790556004906020906101ee8b8961051a565b51166040519283809263313ce56760e01b82525afa8015610312575f906102d2575b60ff91501680156102c35760240360ff81116102a05760ff16604d81116102a057600a0a8860250155610243888761051a565b51156102b45769f4240f4240000000000061025e898861051a565b5164e8d4a51000806102708c8b61051a565b510460141b9104171760b01b886065015561028b888761051a565b5181018091116102a057600190970196610136565b634e487b7160e01b5f52601160045260245ffd5b6341598eb160e01b5f5260045ffd5b63f849159d60e01b5f5260045ffd5b506020813d821161030a575b816102eb60209383610453565b81010312610306575160ff811681036103065760ff90610210565b5f80fd5b3d91506102de565b6040513d5f823e3d90fd5b6309867afd60e41b5f5260045ffd5b93509450945050670de0b6b3a764000091505b036103e55760016087556001600160a01b038116638b78c6d8198190555f7f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08180a3638b78c6d8600c525f526020600c206001815417809155600c5160601c7f715ad5ce61fc9595c7b415289d59cf203f23a94fa06f04af7e489a0a76e1fe265f80a3600380546001600160a01b03191691909117905560405161578f90816105438239f35b634c93afb760e11b5f5260045ffd5b93509450945050670de0b6b3a7640000915061033f565b63b0ac429160e01b5f5260045ffd5b508585511415610118565b63a596ef6d60e01b5f5260045ffd5b6317fb4af160e11b5f5260045ffd5b81518152602091820191016100d3565b601f909101601f19168101906001600160401b0382119082101761047657604052565b634e487b7160e01b5f52604160045260245ffd5b51906001600160a01b038216820361030657565b6001600160401b0381116104765760051b60200190565b9080601f830112156103065781516104cc8161049e565b926104da6040519485610453565b81845260208085019260051b82010192831161030657602001905b8282106105025750505090565b6020809161050f8461048a565b8152019101906104f5565b805182101561052e5760209160051b010190565b634e487b7160e01b5f52603260045260245ffdfe6102c0806040526004361015610013575f80fd5b5f6101e0525f3560e01c908163047fc9aa14613648575080630912ed77146136245780631082ae95146135de578063183a4f6e146135c65780631c10893f146135a75780631cd64df41461356e5780631f3a0e41146135495780632569296214613500578063267f4cf9146134e35780632797da80146134815780632d3eac441461340f5780632de94807146133dd5780632e3036c7146133ae57806331e7e487146131d35780633a04801d146131b65780633e8847ec14612bc85780633f4ba83a14612b5d57806341c0e1b514612ac6578063430bf08a14612a9b578063455611f214612a795780634a4ee7b114612a515780634bb77d9d1461295e5780634f64b2be146129285780634fdf5d1d14612822578063514e62fc146127e757806354d1f13d1461278f578063562e19df146122c45780635c975abb1461229f57806365c303a5146122665780636e18c5b414611e55578063715018a614611e005780638456cb5914611d8a57806385535cc514611d155780638aa044e414611cbd5780638d56c63914611b915780638da5cb5b14611b625780638e499bcf14611b4257806394068a9314611b0e5780639d76ea5814611ae3578063a3820aa51461191d578063abfed9fd14611853578063b533789714611833578063b6efab3914611813578063c6e1d3e7146117e7578063c7d0a17f146112e0578063cc33448214610e5f578063d1154ff014610dff578063d13630af14610789578063d6c094b31461075d578063dc036c9a14610495578063e7ee6ad614610453578063ef407c3c1461041d578063f04e283e146103c6578063f2fde38b14610381578063f8dc929c14610361578063f8e27f93146102d15763fee81cf414610295575f80fd5b346102ca5760203660031901126102ca576102ae613662565b63389a75e1600c526101e05152602080600c2054604051908152f35b6101e05180fd5b346102ca5760203660031901126102ca5760043560015481101561034c5760208110156103325761030a6080916065015460b01c613c3d565b916088541561032b575b604051938452602084015260408301526060820152f35b5082610314565b634e487b7160e01b6101e05152603260045260246101e051fd5b6367e0bf5f60e01b6101e0515260046101e051fd5b346102ca576101e0513660031901126102ca576020608954604051908152f35b60203660031901126102ca57610395613662565b61039d6138da565b8060601b156103b6576103af906144f7565b6101e05180f35b637448fbae6101e051526004601cfd5b60203660031901126102ca576103da613662565b6103e26138da565b63389a75e1600c52806101e051526020600c20908154421161040d576103af916101e05190556144f7565b636f5e88186101e051526004601cfd5b346102ca5760203660031901126102ca5760043560208110156102ca57604501546040516001600160a01b039091168152602090f35b346102ca5760203660031901126102ca5760043560015481101561034c576020811015610332576001600160501b036020916065015460601c16604051908152f35b346102ca5760603660031901126102ca576004356024356001600160401b0381116102ca576104c89036906004016136ba565b6104d3929192613678565b903068929eee149b4bd21268541461074d573068929eee149b4bd2126855600154808214801590610743575b61072e576002549161051185846137ee565b60028190556003549095906001600160a01b0316803b156102ca57604051632770a7eb60e21b81526101e0519091829081806105518733600484016137fb565b03916101e051905af1801561072057610705575b506040517fd8ae9b9ba89e637bcb66a69ac91e8f688018e81d6f92c57e02226425c8efbdf6339180610598858a836137fb565b0390a2670de0b6b3a76400006101e0516101e0515b60208110156106dc578581146106dc576065810180548a91906105cf90613c1e565b620fffff81989398959295168c6105e68b8b61372b565b906105f09161373e565b98896105fb916137ee565b9461060886938885613c99565b906101e05150558b810264e8d4a5100002920264e8d4a5100002049061062d91614307565b02670de0b6b3a76400009004930193670de0b6b3a7640000810290808204670de0b6b3a764000014901517156106c2576106759161066a9161373e565b6025830154906144b9565b9061068181878d6136f7565b3582106106ad5760058101546001926106a4918b906001600160a01b03166142b6565b019190916105ad565b634647d8b560e01b6101e0515260046101e051fd5b634e487b7160e01b6101e05152601160045260246101e051fd5b5096509450505050506106ef9250613be1565b608b553868929eee149b4bd21268556101e05180f35b6101e0516107129161375c565b6101e0516102ca5787610565565b6040513d6101e051823e3d90fd5b6341598eb160e01b6101e0515260046101e051fd5b50602082116104ff565b63ab143c066101e051526004601cfd5b346102ca5760203660031901126102ca5760043560208110156102ca5760250154604051908152602090f35b346102ca5760803660031901126102ca576004356001600160401b0381116102ca576107b99036906004016136ba565b906107c2613678565b610160526107ce6136a4565b903068929eee149b4bd21268541461074d573068929eee149b4bd2126855600154610100819052830361072e57608b546101e0515f1960e0526001600160801b03821693909260809290921c918391825b6020811015610df2576101005181146108d55761083d8189856136f7565b3580156108c25760258201546001929160089161085991613ccc565b95838301891b17970194861515806108b7575b61087c575b505b0194929461081f565b6108a2906101e0515061089d6108958460650154613c1e565b50909261372b565b61373e565b8060e0511060e0518218021860e05289610871565b5060e051151561086c565b506001906101e09694965160e052610873565b50939490949291925b15610ddd576108ec92613cfa565b6101c0526101c051928160025461012052946101c0519361090f610100516137a8565b60c0526101e0516101a0525b60206101a0511015610dd357610100516101a05114610b27576109426101a05183856136f7565b356101808190526101a0516025015461095a91613ccc565b8015610b09576101e051506109916101a051606501670de0b6b3a76400006109828254613c1e565b6101409592955280949561372b565b0460a0526109b06109a460a051856136ea565b92610140519084613c99565b9055610120516109f2575b505061018051610160516101a051600501546109e2929130916001600160a01b0316613fc6565b60016101a051016101a05261091b565b81670de0b6b3a764000081989a93999794990204670de0b6b3a764000014871517156106c257610b0192610a82610aeb92610a7d610a93670de0b6b3a7640000610a888198610a828f610a4a6101c05186830261373e565b610a596101a05160c0516137da565b526101005161014051620fffff160264e8d4a510000290610a7d908990870261373e565b613f99565b9061372b565b049d60a051906136ea565b9a86610abd610ab182610aa860e0518661372b565b0460a0516137ee565b60865460011c9061372b565b0460808190526101005161014051620fffff160264e8d4a5100002938891610ae4916137ee565b910261373e565b0493610afb60805160a0516137ee565b906136ea565b9487806109bb565b50610120516109e25763f6ef3f5d60e01b6101e0515260046101e051fd5b91959290945b6101205180610d2557505050610b416140ba565b80918015610d105782610b6592915b6101205115926101e0515490610100516141d6565b929096610b7561012051896137ee565b9687151580610d04575b156106ad576003546001600160a01b0316803b156102ca576040516340c10f1960e01b81526101e051909182908180610bbc8e8a600484016137fb565b03916101e051905af1801561072057610ce9575b507f67902069e86c21d5ad116d9df073bf02a2bfdbd591414157cda22d3b8476cd5391610c0589604051938493339785613816565b0390a26101205186929015610cd75750505081610c2e916101e051546101205161010051614106565b60035460045491956001600160a01b039182169290911690610c5090846137ee565b823b156102ca57610c7b9260405180809581946340c10f1960e01b83526101e05196600484016137fb565b03916101e051905af1801561072057610cb8575b5090602093610ca1925b600255613be1565b608b553868929eee149b4bd2126855604051908152f35b6101e051919291610cc89161375c565b6101e0516102ca579084610c8f565b60209650610ca1945090925090610c99565b6101e051610cf69161375c565b6101e0516102ca5789610bd0565b50602435881015610b7f565b63df7da5cd60e01b6101e0515260046101e051fd5b6101e097949392969597515b6020811015610dc257610100518114610dc257610d4f8188886136f7565b3515610dba576065810154610d6390613c1e565b92919050610d738260c0516137da565b519281670de0b6b3a7640000810204670de0b6b3a764000014821517156106c257600193610dae8d670de0b6b3a7640000610db4950261373e565b90614024565b01610d31565b600190610db4565b5081610b6592939495989697610b50565b9195929094610b2d565b631f0ebc5760e21b6101e0515260046101e051fd5b50939490949291926108de565b346102ca5760203660031901126102ca57600435610e1b6138a4565b662386f26fc10000811161072e576020817f15a280e3a8fba7bb6a16834e8c4c8cf503351db60f83e74124075ff74b3d611992608655604051908152a16101e05180f35b346102ca576101203660031901126102ca57610e79613662565b610e8161368e565b6044359160c43591906101043560a4356001600160a01b03821682036102ca57610ea96138a4565b80156112b6576001549160208310156112cb5785156112b6576088546112a1576002541561128c578615158061127b575b1561072e57670de0b6b3a7640000606435118015611268575b61072e57600183018084116106c2576101e05195966001600160a01b038616969586805b602089101561125857878914610fa757505060058701546001600160a01b03168814610f925760658701805490978b91610f5090613c1e565b610f5d909b92919b613c3d565b90819e9381988102670de0b6b3a76400009004900392610f7c93613c76565b90610f8692613c99565b90556001019790610f17565b6364d9dc7160e11b6101e0515260046101e051fd5b909a9750602496999895985b60018060a01b03169a60208c604051998a80926305d4ec6560e11b82528b60048301525afa978815610720576101e05198611220575b50871561120b5760405163313ce56760e01b8152906020826004818b5afa9182156107205761104a8a6110458e61103f61103a61105398670de0b6b3a7640000976101e051916111dc575b5061385a565b61386b565b90613ccc565b61372b565b04928a80613c76565b600185905560058b0180546001600160a01b0319168817905560405163313ce56760e01b815292906020846004818b5afa90811561072057898c948f8f6110ad61103a6110cb976111089b6101e051916111dc575061385a565b602582015560450180546001600160a01b0319169091179055613c99565b60658c01556110fc6110ec6110de6140ba565b80929188826002549b614106565b90966101e0515586600255613be1565b608b5530903390613fc6565b8181111561072e57039060e435821061072e576003546001600160a01b031691823b156102ca576111539260405180809581946340c10f1960e01b83526101e05196600484016137fb565b03916101e051905af18015610720576111b7575b7f3c078e7a1bc2cbd8c7cd625a6d75d084e96e6701c6a324576b75a688b38a1c5360c0878787878c88604051958652602086015260408501526060840152608083015260a0820152a16101e05180f35b6101e0519195949392916111ca9161375c565b6101e0516102ca579091929386611167565b6111fe915060203d602011611204575b6111f6818361375c565b810190613841565b5f611034565b503d6111ec565b639cfd11eb60e01b6101e0515260046101e051fd5b9097506020813d602011611250575b8161123c6020938361375c565b8101031261124c5751968c610fe9565b5f80fd5b3d915061122f565b909a975060249699989598610fb3565b50670de0b6b3a764000060843511610ef3565b50662386f26fc10000871115610eda565b632468d44760e11b6101e0515260046101e051fd5b632ffc992d60e21b6101e0515260046101e051fd5b630b5556e560e11b6101e0515260046101e051fd5b6331cc28bd60e01b6101e0515260046101e051fd5b346102ca5760a03660031901126102ca576064356001600160401b0381116102ca576113109036906004016136ba565b906113196138a4565b6001549060028211156117d25760ff608554166117bd57604435156112b6576088546112a15781600435101561034c575f1982019182116106c2578183036117a8574260885561136b608435426136ea565b6089556020600435101561033257600560043501546001600160a01b0316611392836137a8565b61139b846137a8565b916113a5856137a8565b936113af866137a8565b6101e051909790918291825b8984106116ac5750505050670de0b6b3a764000003611697576101e0515b602081101561168b57858114611476576001906001600160a01b036113fe82866137da565b51166101e051508160050190838060a01b0316838060a01b031982541617905561142881866137da565b51602582015560a082901b82900361144082886137da565b51166101e051508160450190838060a01b0316838060a01b031982541617905561146a81896137da565b516065820155016113d9565b509450505050505b60015480156106c2575f1901806001556114aa6114996140ba565b809291600254948260443591614106565b9190926114b784826137ee565b908411611676578060243510611661576114d3906024356137ee565b806115fb575b506114eb916044356101e05155613be1565b608b556003546001600160a01b0316803b156102ca57604051632770a7eb60e21b81526101e05190918290818061152860243533600484016137fb565b03916101e051905af18015610720576115e0575b506002556040516370a0823160e01b8152306004820152602081602481855afa8015610720576101e051906115ac575b611578915033836142b6565b6004357fb3036f81a7a8205f3b94de16897df636d553839d92289fb7ec72dd2d541328426101e0516101e051a36101e05180f35b506020813d6020116115d8575b816115c66020938361375c565b8101031261124c57611578905161156c565b3d91506115b9565b6101e0516115ed9161375c565b6101e0516102ca578261153c565b6003546001600160a01b031690813b156102ca5760405180926340c10f1960e01b825281806116326101e0519533600484016137fb565b03916101e051905af1801561072057156114d9576101e0516116539161375c565b6101e0516102ca57846114d9565b634f0397ab60e01b6101e0515260046101e051fd5b635d7e4ee960e01b6101e0515260046101e051fd5b5094505050505061147e565b63083aafed60e41b6101e0515260046101e051fd5b600435841461179f5760208410156103325760058401546001600160a01b03166116d682896137da565b5260258401546116e6828a6137da565b5260458401546001600160a01b03166116ff828b6137da565b52606584015461170e90613c1e565b50959061171c8685876136f7565b35968715801561178e575b6117795769f4240f4240000000000064e8d4a510006117498a611758966136ea565b9904601481901b171791613c99565b611762828d6137da565b525f1981146106c2576001809101935b01926113bb565b6303aa729960e61b6101e0515260046101e051fd5b50670de0b6b3a76400008811611727565b92600190611772565b633bfe822760e11b6101e0515260046101e051fd5b63b8c449b360e01b6101e0515260046101e051fd5b63a596ef6d60e01b6101e0515260046101e051fd5b346102ca5760203660031901126102ca5760043560208110156102ca5760650154604051908152602090f35b346102ca576101e0513660031901126102ca576020608a54604051908152f35b346102ca576101e0513660031901126102ca576020608854604051908152f35b346102ca5760403660031901126102ca5760043561186f61368e565b6118776138a4565b60015482101561034c576020821015610332576045820180546001600160a01b0319166001600160a01b038316179055608b549160018101918282116106c2577f908a8bb84530a3f5baf8a0432620a6480e8b2af2e2423dae1222231a90caa5a4936040936118ff916118f991608082901c916001600160801b031690613cfa565b90613be1565b608b5582519182526001600160a01b03166020820152a16101e05180f35b346102ca5760603660031901126102ca576004356001600160401b0381116102ca5761194d9036906004016136ba565b906024356001600160401b0381116102ca5761196d9036906004016136ba565b92906044356001600160401b0381116102ca5761198e9036906004016136ba565b906119976138a4565b83861480611ada575b1561072e57600154936101e0515b602081106119bd576101e05180f35b818114611ad5576119cf8183896136f7565b35908682101561034c57670de0b6b3a76400006119ed828b896136f7565b35111580611ab8575b15611aa3576020821015610332578185611a5583611a37611a4f8b8f8b90611a488660019c60650199611a41611a2c8c54613c1e565b9b919b9a909a613c3d565b50509690986136f7565b35946136f7565b3592613c76565b91613c99565b90557f80394b5329e114f22712d6166857cd77c88256d851082e141591f481227fb8b96040611a85848d8b6136f7565b35611a91858a8a6136f7565b3582519182526020820152a2016119ae565b63bd18ee1f60e01b6101e0515260046101e051fd5b50670de0b6b3a7640000611acd8287876136f7565b3511156119f6565b6103af565b508382146119a0565b346102ca576101e0513660031901126102ca576003546040516001600160a01b039091168152602090f35b346102ca576101e0513660031901126102ca57608b54604080516001600160801b038316815260809290921c602083015290f35b346102ca576101e0513660031901126102ca576020600154604051908152f35b346102ca576101e0513660031901126102ca57638b78c6d819546040516001600160a01b039091168152602090f35b346102ca5760403660031901126102ca57600435611bad61368e565b611bb56138a4565b60015482101561034c57602082101561033257611bd58260650154613c1e565b50670de0b6b3a7640000820291808304670de0b6b3a764000014901517156106c257611c009161373e565b600181018091116106c2576025830154611c19916144b9565b6005909201546040516370a0823160e01b81523060048201526001600160a01b03919091169190602081602481865afa908115610720576101e05191611c8b575b5083811115611c76576103af93611c70916137ee565b916142b6565b63996f8ab960e01b6101e0515260046101e051fd5b90506020813d602011611cb5575b81611ca66020938361375c565b8101031261124c575184611c5a565b3d9150611c99565b346102ca5760203660031901126102ca57600435611cd96138a4565b801561072e576020817f03cd63f3fef742f82f64d7e1775b22c4fe9ed6d2bf0ca7cc04146d620e190ab292608755604051908152a16101e05180f35b346102ca5760203660031901126102ca57611d2e613662565b611d366138a4565b6001600160a01b0316801561072e57600480546001600160a01b031916821790556040519081527f58fd5d9c33114e6edf8ea5d30956f8d1a4ab112b004f99928b4bcf1b87d6666290602090a16101e05180f35b346102ca576101e0513660031901126102ca57611da56138bf565b60855460ff8116611deb5760ff19166001176085556101e05133907f5ee71a369c8672edded508e624ffc9257fa1ae6886ef32905c18e60196bca3999080a26101e05180f35b639784de2160e01b6101e0515260046101e051fd5b6101e0513660031901126102ca57611e166138da565b6101e051638b78c6d819547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a36101e051638b78c6d81981905580f35b346102ca5760803660031901126102ca57611e6e6136a4565b3068929eee149b4bd21268541461074d573068929eee149b4bd212685560015460043581111561072e57608b54611eb990608081901c906001600160801b0316600435600101613cfa565b919060025492611ecb602435856137ee565b60028190556003549091906001600160a01b0316803b156102ca57604051632770a7eb60e21b81526101e051909182908180611f0d60243533600484016137fb565b03916101e051905af180156107205761224b575b506020600435101561033257670de0b6b3a764000092611f6792611f4a60043560650154613c1e565b9691959093610a8264e8d4a510008a620fffff8b16020288613f99565b04966101e051905b60208210612224575b50509664e8d4a5100088611fae888a89611fde9b9c9d8a611f99818c6137ee565b978895620fffff6101e0515495160202614340565b99611fe4611fbc8c896137ee565b670de0b6b3a7640000611fd16086548361372b565b60011c049a8b80926137ee565b9c6136ea565b9a670de0b6b3a7640000810290808204670de0b6b3a764000014901517156106c257612013866120209261373e565b60256004350154906144b9565b9460443586106106ad5788612035918d613c99565b606560043501558015670de0b6b3a76400008083028390041417156106c2578a61207d61208392670de0b6b3a7640000610ae464e8d4a510008f620fffff8f16020285613f99565b936136ea565b976101e0515b602081101561220a578a811461215857600435810361210e57670de0b6b3a76400008802888104670de0b6b3a764000014891517156106c257876120cc9161373e565b908c670de0b6b3a7640000810204670de0b6b3a7640000148d1517156106c2576121088a6001938f8e670de0b6b3a7640000610dae920261373e565b01612089565b606581015461211c90613c1e565b9291670de0b6b3a7640000808202925081159183041417156106c25760019281610dae8e61214d8d6121539661373e565b9261373e565b612108565b5091945091969450602098508492975061217a95505b6121f7575b5050613be1565b608b556005600435015461219a90839083906001600160a01b03166142b6565b6040519060018060a01b031681526004358382015281604082015260243560608201527f7a3728879285f3ca5108b5f39698f28002a6b72cac81653343b8a7dfb75037f160803392a23868929eee149b4bd2126855604051908152f35b9161220192613aac565b90508187612173565b5091945091969450602098508492975061217a955061216e565b90978789146122455761223d8261089d8560019461372b565b980190611f6f565b97611f78565b6101e0516122589161375c565b6101e0516102ca5786611f21565b346102ca5760203660031901126102ca5760043560015481101561034c576020811015610332576020906065015460b01c604051908152f35b346102ca576101e0513660031901126102ca57602060ff608554166040519015158152f35b346102ca5760a03660031901126102ca576084356001600160a01b03811681036102ca573068929eee149b4bd21268541461074d573068929eee149b4bd21268556001546004356024351461277a57806004351080159061276e575b61034c57604435156112b657612355608b5460018060801b0381169060801c9060016024350160081b60016004350117613cfa565b929091602060043510156103325761237260043560650154613c1e565b959094602060243510156103325761238f60243560650154613c1e565b919889986101e051506123aa60043560250154604435613ccc565b956123f9670de0b6b3a76400006123d484611045836123cc8d6086549061372b565b04809c6137ee565b0496610a826123e3898c6136ea565b9d64e8d4a510008d620fffff8b16020290613f99565b908b670de0b6b3a7640000810204670de0b6b3a7640000148c1517156106c2578c80928d8b8d620fffff89160264e8d4a510000291670de0b6b3a764000002906124429161373e565b9061244c91614307565b6124559161373e565b9d6124618f99846136ea565b9061246b916137ee565b80988c6002546101e0515491620fffff8c160264e8d4a51000029461248f95614340565b968761249a916136ea565b9880670de0b6b3a7640000810204670de0b6b3a764000014811517156106c257848d610dae8c670de0b6b3a76400006124d887826124df980261373e565b930261373e565b670de0b6b3a7640000820290828204670de0b6b3a764000014831517156106c2576125099161373e565b9086670de0b6b3a7640000810204670de0b6b3a764000014871517156106c25784612554886125599361254f8a612566978f610dae90670de0b6b3a7640000870261373e565b6137ee565b6144b9565b60256024350154906144b9565b996064358b106106ad57866126a4575b8492612593949261258692613c99565b6065600435015584613c99565b60656024350155670de0b6b3a7640000888102988015908a0490911417156106c2576020976125d8859364e8d4a510006125ea98620fffff6125de9616020290613f99565b9061373e565b91612690575b50613be1565b608b556005600435015461260e9060443590309033906001600160a01b0316613fc6565b6005602435015461262b90839083906001600160a01b03166142b6565b6040519060018060a01b0316815260043583820152602435604082015260443560608201528160808201527fb3e2773606abfd36b5bd91394b3a54d1398336c65005baf7bf7a05efeffaf75b60a03392a23868929eee149b4bd2126855604051908152f35b61269c91600254613aac565b9050816125e4565b670de0b6b3a76400006126be83899e959a9e96949661372b565b049b83670de0b6b3a7640000810204670de0b6b3a764000014841517156106c2576126e98d836136ea565b9182670de0b6b3a7640000810204670de0b6b3a764000014831517156106c25786948e93828d620fffff8e160264e8d4a510000291670de0b6b3a764000002906127329161373e565b9061273c91614307565b61274f91670de0b6b3a76400000261373e565b9d612759916136ea565b91612763916136ea565b979250929092612576565b50806024351015612320565b63a8bf4d5f60e01b6101e0515260046101e051fd5b6101e0513660031901126102ca5763389a75e1600c52336101e051526101e0516020600c2055337ffa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c926101e0516101e051a26101e05180f35b346102ca5760403660031901126102ca57612800613662565b638b78c6d8600c526101e05152602060243581600c2054161515604051908152f35b346102ca5760403660031901126102ca5761283b613662565b61284361368e565b61284b6138a4565b6001546101e05190926001600160a01b0381169290915b6020811015612919578481146128a35760058101546001600160a01b0316841461288e57600101612862565b63103d1a8760e31b6101e0515260046101e051fd5b509091602493506020905b6040516370a0823160e01b815230600482015294859182905afa918215610720576101e051926128e3575b6103af93506142b6565b91506020833d602011612911575b816128fe6020938361375c565b8101031261124c576103af9251916128d9565b3d91506128f1565b509091602493506020906128ae565b346102ca5760203660031901126102ca5760043560208110156102ca57600501546040516001600160a01b039091168152602090f35b346102ca5760203660031901126102ca576004356001600160401b0381116102ca5761298e9036906004016136ba565b6001546101e051928391905b602083106129ff575b505050156129d8575b608b546129ce916118f991608081901c916001600160801b0390911690613cfa565b608b556101e05180f35b507f201f1e1d1c1b1a191817161514131211100f0e0d0c0b0a0908070605040302016129ac565b90929193828514612a485783612a168685856136f7565b35101561034c57612a288584846136f7565b3560018101919082106106c2576001918660031b1b17940191929061299a565b938293506129a3565b60403660031901126102ca576103af612a68613662565b612a706138da565b60243590614534565b346102ca576101e0513660031901126102ca5760206101e05154604051908152f35b346102ca576101e0513660031901126102ca576004546040516001600160a01b039091168152602090f35b346102ca576101e0513660031901126102ca57612ae161387c565b60855460ff811615612b485760ff8160081c16612b335761ff001916610100176085556101e0517fbe26733c2bf6ff3ea5ba8cfe744422bd49052ff9ed5685c9e81e6f9321dbaddd9080a16101e05180f35b631c6a9ca160e11b6101e0515260046101e051fd5b6363856c5960e01b6101e0515260046101e051fd5b346102ca576101e0513660031901126102ca57612b786138bf565b60855460ff811615612b485760ff8160081c16612b335760ff1916608555337faeb196d352664784d1900b0e7414a8face7d29f4dae8c4b0cf68ed477423bbf46101e0516101e051a26101e05180f35b3461124c57606036600319011261124c576004356001600160401b03811161124c57612bf89036906004016136ba565b90612c01613678565b903068929eee149b4bd2126854146131a9573068929eee149b4bd21268556001546102005261020051830361319a57608b545f19610220526001600160801b038116925f9260809290921c918391825b602081101561318c57610200518114612cf657612c6f8189856136f7565b358015612ce557906008612c8a600193836025015490613ccc565b95838301891b1797019486151580612cd9575b612cad575b505b01949294612c51565b612cc19061089d6108958460650154613c1e565b80610220511061022051821802186102205289612ca2565b50610220511515612c9d565b506001905f61022097959752612ca4565b5095939490949291925b1561317d57612d0e92613cfa565b61028052926102805190849260025495946102805191612d30610200516137a8565b935f610240525b602061024051101561316f57610200516102405114612f7557612d5e6102405183856136f7565b35612d70610240516025015482613ccc565b8015612f5f57612d9e670de0b6b3a764000061024051606501612d938154613c1e565b93919490809661372b565b0461026052612dbb82612db461026051866136ea565b9586613c99565b90558c612df5575b50506102405160050154612de5929150309033906001600160a01b0316613fc6565b6001610240510161024052612d37565b90969a87670de0b6b3a7640000819c949c9b959b0204670de0b6b3a76400001488151715612f4b5761028051612e3590670de0b6b3a76400008a0261373e565b61024051612e43908b6137da565b5261020051620fffff83160264e8d4a51000028b670de0b6b3a76400008a0290612e6c9161373e565b90612e7691613f99565b612e7f9161372b565b670de0b6b3a764000090049a61026051612e98916136ea565b9661022051612ea7908261372b565b670de0b6b3a764000090046102605190612ec0916137ee565b60865460011c612ecf9161372b565b670de0b6b3a764000090049a8b926102005190620fffff160264e8d4a510000292612ef9916137ee565b612f0c91670de0b6b3a76400000261373e565b90612f1691613f99565b612f1f9161372b565b670de0b6b3a76400009004976102605190612f39916137ee565b612f42916136ea565b958a8080612dc3565b634e487b7160e01b5f52601160045260245ffd5b505088612de55763f6ef3f5d60e01b5f5260045ffd5b9295909694979391975b84806130c85750505050612f916140ba565b809180156130b95782612faf92915b8615925f5490610200516141d6565b929097612fbc858a6137ee565b97881515806130ad575b1561309e576003546001600160a01b031691823b1561124c575f61300381948c6040519687809481936340c10f1960e01b83528b600484016137fb565b03925af1928315613093577f67902069e86c21d5ad116d9df073bf02a2bfdbd591414157cda22d3b8476cd539361307e575b506130488a604051938493339785613816565b0390a28691831561306b57505050610c2e9183916101e051549061020051614106565b60209750610ca195509093509150610c99565b5f6130889161375c565b5f6101e0528b613035565b6040513d5f823e3d90fd5b634647d8b560e01b5f5260045ffd5b50602435891015612fc6565b63df7da5cd60e01b5f5260045ffd5b5f9995939998969492985b602081101561315c5761020051811461315c576130f18189896136f7565b351561315457808b6131136131098360650154613c1e565b95919390506137da565b519281670de0b6b3a7640000810204670de0b6b3a76400001482151715612f4b57600193610dae8d670de0b6b3a764000061314e950261373e565b016130d3565b60019061314e565b50908093959950612faf92949698612fa0565b929590969497939197612f7f565b631f0ebc5760e21b5f5260045ffd5b509593949094929192612d00565b6341598eb160e01b5f5260045ffd5b63ab143c065f526004601cfd5b3461124c575f36600319011261124c576020608654604051908152f35b3461124c57608036600319011261124c576004356024356001600160401b03811161124c576132069036906004016136ba565b60443591606435936132166138a4565b60015493811561319a5784840361319a5742861061319a57608b54608081901c90613249906001600160801b0316613909565b91909161338d575b505060885461337e578560885561326881876136ea565b60895581608a555f955f965b6020881015613367578688146132f25761328f8887876136f7565b3597670de0b6b3a76400008910156132e3576132ad896001936136ea565b986132da82606501916132d1611a4f6132c68554613c1e565b949194939093613c3d565b93915091613c76565b90550196613274565b630152ac2f60e31b5f5260045ffd5b9092949550670de0b6b3a7640000919396505b03613358576133487fb0fb14f34df2e6ea25fc5285462fa7522278318522be931036565d550e5236a5956040519586958652608060208701526080860191613707565b91604084015260608301520390a1005b63083aafed60e41b5f5260045ffd5b9092949550670de0b6b3a764000091939650613305565b632ffc992d60e21b5f5260045ffd5b61339d816133a493600254613aac565b9050613be1565b608b558680613251565b3461124c57604036600319011261124c576133db6133ca613662565b6133d261387c565b60243590614579565b005b3461124c57602036600319011261124c576133f6613662565b638b78c6d8600c525f52602080600c2054604051908152f35b3461124c575f36600319011261124c576134276138e9565b608b54602090608081901c90613445906001600160801b0316613909565b918280613478575b61345e575b50506040519015158152f35b61339d8161346e93600254613aac565b608b558280613452565b5080151561344d565b3461124c57602036600319011261124c576004356001548110156134d45760208110156134c0576001600160601b036020916065015416604051908152f35b634e487b7160e01b5f52603260045260245ffd5b6367e0bf5f60e01b5f5260045ffd5b3461124c575f36600319011261124c576020608754604051908152f35b5f36600319011261124c5763389a75e1600c52335f526202a30042016020600c2055337fdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d5f80a2005b3461124c575f36600319011261124c57602060ff60855460081c166040519015158152f35b3461124c57604036600319011261124c576020613589613662565b60243590638b78c6d8600c525f528082600c20541614604051908152f35b604036600319011261124c576133db6135be613662565b6133d26138da565b602036600319011261124c576133db60043533614534565b3461124c575f36600319011261124c576135f66138a4565b5f6088555f6089557fc3014e77feddea63dc4c4b247508845d74eb35678da2e55000c3bb655727650e5f80a1005b3461124c57604036600319011261124c576133db613640613662565b612a7061387c565b3461124c575f36600319011261124c576020906002548152f35b600435906001600160a01b038216820361124c57565b604435906001600160a01b038216820361124c57565b602435906001600160a01b038216820361124c57565b606435906001600160a01b038216820361124c57565b9181601f8401121561124c578235916001600160401b03831161124c576020808501948460051b01011161124c57565b91908201809211612f4b57565b91908110156134c05760051b0190565b81835290916001600160fb1b03831161124c5760209260051b809284830137010190565b81810292918115918404141715612f4b57565b8115613748570490565b634e487b7160e01b5f52601260045260245ffd5b90601f801991011681019081106001600160401b0382111761377d57604052565b634e487b7160e01b5f52604160045260245ffd5b6001600160401b03811161377d5760051b60200190565b906137b282613791565b6137bf604051918261375c565b82815280926137d0601f1991613791565b0190602036910137565b80518210156134c05760209160051b010190565b91908203918211612f4b57565b6001600160a01b039091168152602081019190915260400190565b9493929160409261383c9260018060a01b03168752606060208801526060870191613707565b930152565b9081602091031261124c575160ff8116810361124c5790565b60ff166024039060ff8211612f4b57565b60ff16604d8111612f4b57600a0a90565b638b78c6d8600c52335f5260016020600c2054161561389757565b6382b429005f526004601cfd5b638b78c6d8600c52335f5260036020600c2054161561389757565b638b78c6d8600c52335f5260056020600c2054161561389757565b638b78c6d81954330361389757565b600160ff608554161515146138fa57565b63b8c449b360e01b5f5260045ffd5b90608854916089549083158015613aa3575b8015613a85575b613a7d575080839142105f14613a695761394b9161393f916137ee565b92426088555b426137ee565b915f5490608a548180159386855f14613a2e575050505b5f555f5b6020811015613a245760015481146139fd57600190806065016139ba876139a0611a4f87896139958754613c1e565b969196959095613c3d565b9592809592949195925f146139c25750505050805b613c76565b905501613966565b848111156139e657506139b59261089d6139e09261104587866137ee565b906137ee565b91506139b59261089d610afb9261104585886137ee565b50505090505b5f60025480613a14575b5090600190565b613a1e91506145bb565b5f613a0d565b5050509050613a03565b9091928083115f14613a54579261089d6139e092611045613a4f96866137ee565b613962565b9261089d610afb9261104585613a4f976137ee565b505061394b5f925f6088555f608955613945565b92505f919050565b50613a9084426137ee565b6087541180156139225750428211613922565b5042841161391b565b9092915f938215613bd85790613ac891600154845f5491614106565b93909180831115613b5f576003546004546001600160a01b0390811692911690613af290856137ee565b91813b15613b5b57918391613b1e93836040518096819582946340c10f1960e01b8452600484016137fb565b03925af18015613b5057613b38575b50505b806002559190565b613b4382809261375c565b613b4d5780613b2d565b80fd5b6040513d84823e3d90fd5b8380fd5b8091508210613b6f575b50613b30565b6003546004546001600160a01b0391821692911690613b8f9084906137ee565b823b1561124c57613bb9925f9283604051809681958294632770a7eb60e21b8452600484016137fb565b03925af180156130935715613b69575f613bd29161375c565b5f613b69565b935050505f9190565b906001600160801b0382111580613c0d575b613c06576341598eb160e01b5f5260045ffd5b60801b1790565b506001600160801b03811115613bf3565b6001600160601b038116916001600160501b038260601c169160b01c90565b9064e8d4a51000620fffff8316029164e8d4a51000620fffff8260141c16029164e8d4a5100080620fffff8460281c160292603c1c0290565b90919264e8d4a510008080809304603c1b950460281b930460141b910417171790565b90916001600160601b0382118015613cbc575b61319a5760b01b9160601b171790565b506001600160501b038311613cac565b90805f19048211613ce7575b670de0b6b3a764000091020490565b8015613cd85763bac65e5b5f526004601cfd5b91613d036138e9565b806102a052613d1182613909565b90936001545f5b60208110613d72575b505050159182613d68575b5081613d5b575b50613d5357613d49906102a05190600254613aac565b9050906102a05190565b906102a05190565b90506102a051145f613d33565b831491505f613d2c565b60ff838260031b1c1680158015613f90575b613f8a575f1981019060208210156134c05760018060a01b0360448201541690613db16064820154613c1e565b9190602060018060a01b036004860154166024604051809881936305d4ec6560e11b835260048301525afa948515613093575f95613f57575b508415613f4857808514613f3a57600b8102818104600b1482151715612f4b57600a9004851180613f31575b613f24575b5f9181151580613f18575b613e74575b5050927f516c8bdb823996757c901b6b9bd210afa82c6ec8d550f0e57cd3f64896f7319c926064613e636020948460019a9998613c99565b910155604051908152a25b01613d18565b9296959493909c9150670de0b6b3a76400008d02918d808404670de0b6b3a76400001490151715612f4b578480938a620fffff8b160264e8d4a510000291613ebb9161373e565b90613ec591613f99565b613ece9161372b565b670de0b6b3a764000090049c613ee4838561372b565b90613eee9161373e565b92836102a05190613efe916136ea565b90613f08916137ee565b6102a0529293949591905f613e2b565b506102a0511515613e26565b613f2c6138da565b613e1b565b50801515613e16565b505050505050600190613e6e565b639531a3a160e01b5f5260045ffd5b9094506020813d8211613f82575b81613f726020938361375c565b8101031261124c5751935f613dea565b3d9150613f65565b50613d21565b50828111613d84565b90613fa391614b00565b8015613fc157670de0b6b3a7640000606482025f1901040160010190565b505f90565b916040519360605260405260601b602c526323b872dd60601b600c5260205f6064601c82855af1908160015f51141615614006575b50505f606052604052565b3b153d171015614017575f80613ffb565b637939f4245f526004601cfd5b9164e8d4a51000620fffff8216029064e8d4a51000620fffff8260281c16028281115f146140b357505f5b831061409a5764e8d4a5100090603c1c020180670de0b6b3a764000010670de0b6b3a7640000821802188111614083575050565b101561408b57565b63b1a539bd60e01b5f5260045ffd5b505011156140a457565b637b3a1f9560e01b5f5260045ffd5b820361404f565b6001545f91825b60208410156140fd578284146140eb576001906001600160601b03856065015416019301926140c1565b925090505b6140f9826145bb565b9190565b925090506140f0565b9290939491670de0b6b3a763ffff19810195818711612f4b576141289161372b565b9390945f915b61010083106141465763b138078b60e01b5f5260045ffd5b801561319a5781878202870304905f5b602081106141ba575b506064908083106141a957670de0b6b3a76400008184035b0204111561418a5760019092019161412e565b9294506140f9935050670de0b6b3a764000060648302049190506136ea565b670de0b6b3a7640000838203614177565b978689146141d057818360019202049801614156565b9761415f565b939592909491670de0b6b3a763ffff19810196818811612f4b576141f99161372b565b9490955f915b61010083106142175763b138078b60e01b5f5260045ffd5b801561319a5781888202880304905f5b6020811061429a575b5060649080831061428957670de0b6b3a76400008184035b0204111561425b576001909201916141ff565b94505050909250670de0b6b3a76400006064830204905f14614280576140f9916136ea565b6140f9916137ee565b670de0b6b3a7640000838203614248565b98878a146142b057818360019202049901614227565b98614230565b919060145260345263a9059cbb60601b5f5260205f6044601082855af1908160015f511416156142e9575b50505f603452565b3b153d1710156142fa575f806142e1565b6390b8ec185f526004601cfd5b9061431191614b00565b8015613fc157670de0b6b3a7640000606482025f19010460018101821061433a5790035f190190565b50505f90565b92909194670de0b6b3a76400008602868104670de0b6b3a76400001487151715612f4b5761438461437d61438b94670de0b6b3a76400009361373e565b809761372b565b04946136ea565b90821561374857826a0c097ce7bc90715b34b9f160241b0490935f945b61010086106143c05763b138078b60e01b5f5260045ffd5b801561319a576064614451846125d88a61254f8961444c88670de0b6b3a76400006144468f614440848f8a61254f8a8f6144398161441f61104597610afb8a9c8f966144328161442c8f8b8f916125d8968f61441f90614425936136ea565b9361372b565b04906136ea565b9561372b565b918d613f99565b04906137ee565b9961372b565b046136ea565b6136ea565b918083106144a157670de0b6b3a764000061446c82856137ee565b0204111561447f576001909501946143a8565b94505050505061449e9150670de0b6b3a76400006064820204906136ea565b90565b670de0b6b3a76400006144b484836137ee565b61446c565b7812725dd1d243aba0e75fe645cc4873f9e65afe688c928e1f2281108202156144ea57670de0b6b3a7640000020490565b637c5f487d5f526004601cfd5b60018060a01b031680638b78c6d819547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a3638b78c6d81955565b638b78c6d8600c525f526020600c2090815490811618809155600c5160601c7f715ad5ce61fc9595c7b415289d59cf203f23a94fa06f04af7e489a0a76e1fe265f80a3565b638b78c6d8600c525f526020600c2090815417809155600c5160601c7f715ad5ce61fc9595c7b415289d59cf203f23a94fa06f04af7e489a0a76e1fe265f80a3565b6001545f670de0b6b3a76400005b602082101561463f5782821461463f57620fffff906145eb8360650154613c1e565b9050929092169064e8d4a510008202151580614636575b1561319a5761462c8260019464e8d4a510008089670de0b6b3a7640000970202928a020204614307565b02049101906145c9565b50821515614602565b9250505090565b9068056bc75e2d630fffff198201918213600116612f4b57565b906803782dace9d8ffffff198201918213600116612f4b57565b906806f05b59d3b1ffffff198201918213600116612f4b57565b9068ad78ebc5ac61ffffff198201918213600116612f4b57565b906856bc75e2d630ffffff198201918213600116612f4b57565b90682b5e3af16b187fffff198201918213600116612f4b57565b906815af1d78b58c3fffff198201918213600116612f4b57565b90680ad78ebc5ac61fffff198201918213600116612f4b57565b906802b5e3af16b187ffff198201918213600116612f4b57565b9068015af1d78b58c3ffff198201918213600116612f4b57565b906803782dace9d90000008201915f6803782dace9d900000084129112908015821691151617612f4b57565b9068ad78ebc5ac620000008201915f68ad78ebc5ac6200000084129112908015821691151617612f4b57565b906856bc75e2d6310000008201915f6856bc75e2d63100000084129112908015821691151617612f4b57565b90682b5e3af16b188000008201915f682b5e3af16b1880000084129112908015821691151617612f4b57565b906815af1d78b58c4000008201915f6815af1d78b58c40000084129112908015821691151617612f4b57565b90680ad78ebc5ac62000008201915f680ad78ebc5ac620000084129112908015821691151617612f4b57565b9068056bc75e2d631000008201915f68056bc75e2d6310000084129112908015821691151617612f4b57565b906802b5e3af16b18800008201915f6802b5e3af16b188000084129112908015821691151617612f4b57565b9068015af1d78b58c400008201915f68015af1d78b58c4000084129112908015821691151617612f4b57565b9067ad78ebc5ac6200008201915f67ad78ebc5ac62000084129112908015821691151617612f4b57565b906756bc75e2d63100008201915f6756bc75e2d631000084129112908015821691151617612f4b57565b908168056bc75e2d6310000001918212600116612f4b57565b9190915f8382019384129112908015821691151617612f4b57565b908160011b9180830560021490151715612f4b57565b90606482029180830560641490151715612f4b57565b9068056bc75e2d6310000082029180830568056bc75e2d631000001490151715612f4b57565b906b02df0ab5a80a22c61ab5a7008202918083056b02df0ab5a80a22c61ab5a7001490151715612f4b57565b90693f1fce3da636ea5cf850820291808305693f1fce3da636ea5cf8501490151715612f4b57565b90690127fa27722cc06cc5e2820291808305690127fa27722cc06cc5e21490151715612f4b57565b9068280e60114edb805d0382029180830568280e60114edb805d031490151715612f4b57565b90680ebc5fb41746121110820291808305680ebc5fb417461211101490151715612f4b57565b906808f00f760a4b2db55d8202918083056808f00f760a4b2db55d1490151715612f4b57565b906806f5f17757889379378202918083056806f5f17757889379371490151715612f4b57565b81810292915f8212600160ff1b821416612f4b578184051490151715612f4b57565b811561374857600160ff1b81145f19831416612f4b570590565b8115614e9157801561433a578060ff1c614e5a57770bce5086492111aea88f4bb1ca6bcf584181ea8059f76532821015614e235780670c7d713b49da00001280614e12575b15614df257670de0b6b3a76400008102908105670de0b6b3a764000003612f4b576ec097ce7bc90715b34b9f0fffffffff19810190600181831316612f4b576a0c097ce7bc90715b34b9f160241b8202918083056a0c097ce7bc90715b34b9f160241b1490151715612f4b576a0c097ce7bc90715b34b9f160241b8101905f6a0c097ce7bc90715b34b9f160241b83129112908015821691151617612f4b57614bed91614ae6565b614bf78180614ac4565b6a0c097ce7bc90715b34b9f160241b90058080808085614c18828098614ac4565b6a0c097ce7bc90715b34b9f160241b90059060038205614c3791614943565b91614c4191614ac4565b6a0c097ce7bc90715b34b9f160241b90059060058205614c6091614943565b91614c6a91614ac4565b6a0c097ce7bc90715b34b9f160241b90059060078205614c8991614943565b91614c9391614ac4565b6a0c097ce7bc90715b34b9f160241b90059060098205614cb291614943565b91614cbc91614ac4565b6a0c097ce7bc90715b34b9f160241b900590600b8205614cdb91614943565b91614ce591614ac4565b6a0c097ce7bc90715b34b9f160241b900590600d8205614d0491614943565b91614d0e91614ac4565b6a0c097ce7bc90715b34b9f160241b9005600f9005614d2c91614943565b614d359061495e565b90614d4a81670de0b6b3a76400008405614ac4565b91670de0b6b3a7640000900790614d6091614ac4565b670de0b6b3a76400009005614d7491614943565b670de0b6b3a7640000905b0580680238fd42c5cf03ffff19131580614ddf575b15614da25761449e90615348565b60405162461bcd60e51b815260206004820152601560248201527450726f64756374206f7574206f6620626f756e647360581b6044820152606490fd5b5068070c1cc73b00c80000811315614d94565b670de0b6b3a764000091614e08614e0d92614eaf565b614ac4565b614d7f565b50670f43fc2c04ee00008112614b45565b60405162461bcd60e51b815260206004820152600f60248201526e59206f7574206f6620626f756e647360881b6044820152606490fd5b60405162461bcd60e51b815260206004820152600f60248201526e58206f7574206f6620626f756e647360881b6044820152606490fd5b5050670de0b6b3a764000090565b600160ff1b8114612f4b575f0390565b670de0b6b3a764000081126152e05761449e906150a7905f775803bcc5cb9634ba4cfb2213f784019318ed4dcb6017880f60361b8212156152b7575b73011798004d755d3c8bc8e03204cf44619e00000082121561525d575b6150a261506061506061509b61503061507561509561508b61503061501a614f3b614f356150609c614974565b9c614974565b6e01855144814a7ff805980ff008400081121561522d575b6b02df0ab5a80a22c61ab5a700811215615200575b693f1fce3da636ea5cf8508112156151d5575b690127fa27722cc06cc5e28112156151aa575b68280e60114edb805d03811215615180575b680ebc5fb41746121110811215615156575b6808f00f760a4b2db55d81121561512c575b6806f5f1775788937937811215615102575b6806248f33704b2866038112156150d8575b6805c548670b9510e7ac8112156150ae575b61501461500e61500983614646565b61498a565b91614852565b90614ae6565b61508561507b61503061503f6150308580614ac4565b68056bc75e2d63100000900590565b80988561506c6150308461506661505a61503083809d614ac4565b94600386055b90614943565b93614ac4565b9e8f6005900590565b9c614ac4565b9960078b05615060565b98614ac4565b9560098705615060565b94614ac4565b600b900590565b61495e565b6064900590565b6150cc6150bd6150d29261498a565b6805c548670b9510e7ac900590565b9c614900565b9b614ffa565b6150f66150e76150fc9261498a565b6806248f33704b286603900590565b9c6148d6565b9b614fe8565b6151206151116151269261498a565b6806f5f1775788937937900590565b9c6148aa565b9b614fd6565b61514a61513b6151509261498a565b6808f00f760a4b2db55d900590565b9c61487e565b9b614fc4565b61517461516561517a9261498a565b680ebc5fb41746121110900590565b9c614852565b9b614fb2565b61519e61518f6151a49261498a565b68280e60114edb805d03900590565b9c614826565b9b614fa0565b6151c96151b96151cf9261498a565b690127fa27722cc06cc5e2900590565b9c6147fa565b9b614f8e565b6151f46151e46151fa9261498a565b693f1fce3da636ea5cf850900590565b9c6147ce565b9b614f7b565b61522161520f6152279261498a565b6b02df0ab5a80a22c61ab5a700900590565b9c6147a2565b9b614f68565b61525161523c6152579261498a565b6e01855144814a7ff805980ff0084000900590565b9c614776565b9b614f53565b906150a261506061506061509b61503061507561509561508b61503061501a614f3b614f356152a461529e6150609e6b1425982cf597cd205cef7380900590565b9e61474a565b9c50505050505050505050505050614f08565b5072195e54c5dd42177f53a27172fa9ec63026282760241b90056806f05b59d3b2000000614eeb565b6152fb615300916a0c097ce7bc90715b34b9f160241b614ae6565b614eaf565b61449e90614e9f565b1561531057565b60405162461bcd60e51b815260206004820152601060248201526f125b9d985b1a5908115e1c1bdb995b9d60821b6044820152606490fd5b680238fd42c5cf03ffff1981121580615746575b61536590615309565b5f811261571d576806f05b59d3b200000081126156e3576153859061467a565b6153a572195e54c5dd42177f53a27172fa9ec63026282760241b91614974565b68056bc75e2d631000009068ad78ebc5ac620000008112156156c3575b6856bc75e2d6310000008112156156a8575b682b5e3af16b1880000081121561568d575b6815af1d78b58c400000811215615672575b680ad78ebc5ac6200000811215615657575b68056bc75e2d6310000081121561563c575b6802b5e3af16b1880000811215615621575b68015af1d78b58c40000811215615606575b8080808080808080806154528161492a565b61545c8280614ac4565b68056bc75e2d63100000900560029005908161547791614943565b9161548191614ac4565b68056bc75e2d63100000900560039005908161549c91614943565b916154a691614ac4565b68056bc75e2d6310000090056004900590816154c191614943565b916154cb91614ac4565b68056bc75e2d6310000090056005900590816154e691614943565b916154f091614ac4565b68056bc75e2d63100000900560069005908161550b91614943565b9161551591614ac4565b68056bc75e2d63100000900560079005908161553091614943565b9161553a91614ac4565b68056bc75e2d63100000900560089005908161555591614943565b9161555f91614ac4565b68056bc75e2d63100000900560099005908161557a91614943565b9161558491614ac4565b68056bc75e2d631000009005600a9005908161559f91614943565b916155a991614ac4565b68056bc75e2d631000009005600b900590816155c491614943565b916155ce91614ac4565b68056bc75e2d631000009005600c90056155e791614943565b6155f091614ac4565b68056bc75e2d631000009005906150a791614ac4565b61503061561561561b92614730565b92614a9e565b90615440565b61503061563061563692614716565b92614a78565b9061542e565b61503061564b61565192614646565b92614a52565b9061541c565b61503061566661566c926146fc565b92614a2c565b9061540a565b615030615681615687926146e2565b92614a04565b906153f8565b61503061569c6156a2926146c8565b926149dc565b906153e6565b6150306156b76156bd926146ae565b926149b0565b906153d4565b6156cd9150614694565b6e01855144814a7ff805980ff0084000906153c2565b6803782dace9d90000008112615712576156fc90614660565b6153a56b1425982cf597cd205cef738091614974565b6153a5600191614974565b61573d6157386a0c097ce7bc90715b34b9f160241b92614e9f565b615348565b61449e91614ae6565b5068070c1cc73b00c8000081131561535c56fea2646970667358221220071e635e6ce0fe15b9370ebff787ee040261846f697e48c551992e1f8f1d6ef164736f6c634300081a00330000000000000000000000003bcb4f5c22758b145820e1126e69d96f891d5f8b00000000000000000000000000000000000000000000003635c9adc5dea0000000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001800000000000000000000000001b514df3413da9931eb31f2ab72e32c0a507cad50000000000000000000000000000000000000000000000000000000000000002000000000000000000000000039e2fb66102314ce7b64ce5ce3e5183bc94ad38000000000000000000000000fa85fe5a8f5560e9039c04f2b0a90de1415abd7000000000000000000000000000000000000000000000000000000000000000020000000000000000000000005c6e05d97af61637fdf5144ad4ed81a12bfd35b00000000000000000000000005c6e05d97af61637fdf5144ad4ed81a12bfd35b00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000016345785d8a00000000000000000000000000000000000000000000000000000c7d713b49da0000
Deployed Bytecode
0x6102c0806040526004361015610013575f80fd5b5f6101e0525f3560e01c908163047fc9aa14613648575080630912ed77146136245780631082ae95146135de578063183a4f6e146135c65780631c10893f146135a75780631cd64df41461356e5780631f3a0e41146135495780632569296214613500578063267f4cf9146134e35780632797da80146134815780632d3eac441461340f5780632de94807146133dd5780632e3036c7146133ae57806331e7e487146131d35780633a04801d146131b65780633e8847ec14612bc85780633f4ba83a14612b5d57806341c0e1b514612ac6578063430bf08a14612a9b578063455611f214612a795780634a4ee7b114612a515780634bb77d9d1461295e5780634f64b2be146129285780634fdf5d1d14612822578063514e62fc146127e757806354d1f13d1461278f578063562e19df146122c45780635c975abb1461229f57806365c303a5146122665780636e18c5b414611e55578063715018a614611e005780638456cb5914611d8a57806385535cc514611d155780638aa044e414611cbd5780638d56c63914611b915780638da5cb5b14611b625780638e499bcf14611b4257806394068a9314611b0e5780639d76ea5814611ae3578063a3820aa51461191d578063abfed9fd14611853578063b533789714611833578063b6efab3914611813578063c6e1d3e7146117e7578063c7d0a17f146112e0578063cc33448214610e5f578063d1154ff014610dff578063d13630af14610789578063d6c094b31461075d578063dc036c9a14610495578063e7ee6ad614610453578063ef407c3c1461041d578063f04e283e146103c6578063f2fde38b14610381578063f8dc929c14610361578063f8e27f93146102d15763fee81cf414610295575f80fd5b346102ca5760203660031901126102ca576102ae613662565b63389a75e1600c526101e05152602080600c2054604051908152f35b6101e05180fd5b346102ca5760203660031901126102ca5760043560015481101561034c5760208110156103325761030a6080916065015460b01c613c3d565b916088541561032b575b604051938452602084015260408301526060820152f35b5082610314565b634e487b7160e01b6101e05152603260045260246101e051fd5b6367e0bf5f60e01b6101e0515260046101e051fd5b346102ca576101e0513660031901126102ca576020608954604051908152f35b60203660031901126102ca57610395613662565b61039d6138da565b8060601b156103b6576103af906144f7565b6101e05180f35b637448fbae6101e051526004601cfd5b60203660031901126102ca576103da613662565b6103e26138da565b63389a75e1600c52806101e051526020600c20908154421161040d576103af916101e05190556144f7565b636f5e88186101e051526004601cfd5b346102ca5760203660031901126102ca5760043560208110156102ca57604501546040516001600160a01b039091168152602090f35b346102ca5760203660031901126102ca5760043560015481101561034c576020811015610332576001600160501b036020916065015460601c16604051908152f35b346102ca5760603660031901126102ca576004356024356001600160401b0381116102ca576104c89036906004016136ba565b6104d3929192613678565b903068929eee149b4bd21268541461074d573068929eee149b4bd2126855600154808214801590610743575b61072e576002549161051185846137ee565b60028190556003549095906001600160a01b0316803b156102ca57604051632770a7eb60e21b81526101e0519091829081806105518733600484016137fb565b03916101e051905af1801561072057610705575b506040517fd8ae9b9ba89e637bcb66a69ac91e8f688018e81d6f92c57e02226425c8efbdf6339180610598858a836137fb565b0390a2670de0b6b3a76400006101e0516101e0515b60208110156106dc578581146106dc576065810180548a91906105cf90613c1e565b620fffff81989398959295168c6105e68b8b61372b565b906105f09161373e565b98896105fb916137ee565b9461060886938885613c99565b906101e05150558b810264e8d4a5100002920264e8d4a5100002049061062d91614307565b02670de0b6b3a76400009004930193670de0b6b3a7640000810290808204670de0b6b3a764000014901517156106c2576106759161066a9161373e565b6025830154906144b9565b9061068181878d6136f7565b3582106106ad5760058101546001926106a4918b906001600160a01b03166142b6565b019190916105ad565b634647d8b560e01b6101e0515260046101e051fd5b634e487b7160e01b6101e05152601160045260246101e051fd5b5096509450505050506106ef9250613be1565b608b553868929eee149b4bd21268556101e05180f35b6101e0516107129161375c565b6101e0516102ca5787610565565b6040513d6101e051823e3d90fd5b6341598eb160e01b6101e0515260046101e051fd5b50602082116104ff565b63ab143c066101e051526004601cfd5b346102ca5760203660031901126102ca5760043560208110156102ca5760250154604051908152602090f35b346102ca5760803660031901126102ca576004356001600160401b0381116102ca576107b99036906004016136ba565b906107c2613678565b610160526107ce6136a4565b903068929eee149b4bd21268541461074d573068929eee149b4bd2126855600154610100819052830361072e57608b546101e0515f1960e0526001600160801b03821693909260809290921c918391825b6020811015610df2576101005181146108d55761083d8189856136f7565b3580156108c25760258201546001929160089161085991613ccc565b95838301891b17970194861515806108b7575b61087c575b505b0194929461081f565b6108a2906101e0515061089d6108958460650154613c1e565b50909261372b565b61373e565b8060e0511060e0518218021860e05289610871565b5060e051151561086c565b506001906101e09694965160e052610873565b50939490949291925b15610ddd576108ec92613cfa565b6101c0526101c051928160025461012052946101c0519361090f610100516137a8565b60c0526101e0516101a0525b60206101a0511015610dd357610100516101a05114610b27576109426101a05183856136f7565b356101808190526101a0516025015461095a91613ccc565b8015610b09576101e051506109916101a051606501670de0b6b3a76400006109828254613c1e565b6101409592955280949561372b565b0460a0526109b06109a460a051856136ea565b92610140519084613c99565b9055610120516109f2575b505061018051610160516101a051600501546109e2929130916001600160a01b0316613fc6565b60016101a051016101a05261091b565b81670de0b6b3a764000081989a93999794990204670de0b6b3a764000014871517156106c257610b0192610a82610aeb92610a7d610a93670de0b6b3a7640000610a888198610a828f610a4a6101c05186830261373e565b610a596101a05160c0516137da565b526101005161014051620fffff160264e8d4a510000290610a7d908990870261373e565b613f99565b9061372b565b049d60a051906136ea565b9a86610abd610ab182610aa860e0518661372b565b0460a0516137ee565b60865460011c9061372b565b0460808190526101005161014051620fffff160264e8d4a5100002938891610ae4916137ee565b910261373e565b0493610afb60805160a0516137ee565b906136ea565b9487806109bb565b50610120516109e25763f6ef3f5d60e01b6101e0515260046101e051fd5b91959290945b6101205180610d2557505050610b416140ba565b80918015610d105782610b6592915b6101205115926101e0515490610100516141d6565b929096610b7561012051896137ee565b9687151580610d04575b156106ad576003546001600160a01b0316803b156102ca576040516340c10f1960e01b81526101e051909182908180610bbc8e8a600484016137fb565b03916101e051905af1801561072057610ce9575b507f67902069e86c21d5ad116d9df073bf02a2bfdbd591414157cda22d3b8476cd5391610c0589604051938493339785613816565b0390a26101205186929015610cd75750505081610c2e916101e051546101205161010051614106565b60035460045491956001600160a01b039182169290911690610c5090846137ee565b823b156102ca57610c7b9260405180809581946340c10f1960e01b83526101e05196600484016137fb565b03916101e051905af1801561072057610cb8575b5090602093610ca1925b600255613be1565b608b553868929eee149b4bd2126855604051908152f35b6101e051919291610cc89161375c565b6101e0516102ca579084610c8f565b60209650610ca1945090925090610c99565b6101e051610cf69161375c565b6101e0516102ca5789610bd0565b50602435881015610b7f565b63df7da5cd60e01b6101e0515260046101e051fd5b6101e097949392969597515b6020811015610dc257610100518114610dc257610d4f8188886136f7565b3515610dba576065810154610d6390613c1e565b92919050610d738260c0516137da565b519281670de0b6b3a7640000810204670de0b6b3a764000014821517156106c257600193610dae8d670de0b6b3a7640000610db4950261373e565b90614024565b01610d31565b600190610db4565b5081610b6592939495989697610b50565b9195929094610b2d565b631f0ebc5760e21b6101e0515260046101e051fd5b50939490949291926108de565b346102ca5760203660031901126102ca57600435610e1b6138a4565b662386f26fc10000811161072e576020817f15a280e3a8fba7bb6a16834e8c4c8cf503351db60f83e74124075ff74b3d611992608655604051908152a16101e05180f35b346102ca576101203660031901126102ca57610e79613662565b610e8161368e565b6044359160c43591906101043560a4356001600160a01b03821682036102ca57610ea96138a4565b80156112b6576001549160208310156112cb5785156112b6576088546112a1576002541561128c578615158061127b575b1561072e57670de0b6b3a7640000606435118015611268575b61072e57600183018084116106c2576101e05195966001600160a01b038616969586805b602089101561125857878914610fa757505060058701546001600160a01b03168814610f925760658701805490978b91610f5090613c1e565b610f5d909b92919b613c3d565b90819e9381988102670de0b6b3a76400009004900392610f7c93613c76565b90610f8692613c99565b90556001019790610f17565b6364d9dc7160e11b6101e0515260046101e051fd5b909a9750602496999895985b60018060a01b03169a60208c604051998a80926305d4ec6560e11b82528b60048301525afa978815610720576101e05198611220575b50871561120b5760405163313ce56760e01b8152906020826004818b5afa9182156107205761104a8a6110458e61103f61103a61105398670de0b6b3a7640000976101e051916111dc575b5061385a565b61386b565b90613ccc565b61372b565b04928a80613c76565b600185905560058b0180546001600160a01b0319168817905560405163313ce56760e01b815292906020846004818b5afa90811561072057898c948f8f6110ad61103a6110cb976111089b6101e051916111dc575061385a565b602582015560450180546001600160a01b0319169091179055613c99565b60658c01556110fc6110ec6110de6140ba565b80929188826002549b614106565b90966101e0515586600255613be1565b608b5530903390613fc6565b8181111561072e57039060e435821061072e576003546001600160a01b031691823b156102ca576111539260405180809581946340c10f1960e01b83526101e05196600484016137fb565b03916101e051905af18015610720576111b7575b7f3c078e7a1bc2cbd8c7cd625a6d75d084e96e6701c6a324576b75a688b38a1c5360c0878787878c88604051958652602086015260408501526060840152608083015260a0820152a16101e05180f35b6101e0519195949392916111ca9161375c565b6101e0516102ca579091929386611167565b6111fe915060203d602011611204575b6111f6818361375c565b810190613841565b5f611034565b503d6111ec565b639cfd11eb60e01b6101e0515260046101e051fd5b9097506020813d602011611250575b8161123c6020938361375c565b8101031261124c5751968c610fe9565b5f80fd5b3d915061122f565b909a975060249699989598610fb3565b50670de0b6b3a764000060843511610ef3565b50662386f26fc10000871115610eda565b632468d44760e11b6101e0515260046101e051fd5b632ffc992d60e21b6101e0515260046101e051fd5b630b5556e560e11b6101e0515260046101e051fd5b6331cc28bd60e01b6101e0515260046101e051fd5b346102ca5760a03660031901126102ca576064356001600160401b0381116102ca576113109036906004016136ba565b906113196138a4565b6001549060028211156117d25760ff608554166117bd57604435156112b6576088546112a15781600435101561034c575f1982019182116106c2578183036117a8574260885561136b608435426136ea565b6089556020600435101561033257600560043501546001600160a01b0316611392836137a8565b61139b846137a8565b916113a5856137a8565b936113af866137a8565b6101e051909790918291825b8984106116ac5750505050670de0b6b3a764000003611697576101e0515b602081101561168b57858114611476576001906001600160a01b036113fe82866137da565b51166101e051508160050190838060a01b0316838060a01b031982541617905561142881866137da565b51602582015560a082901b82900361144082886137da565b51166101e051508160450190838060a01b0316838060a01b031982541617905561146a81896137da565b516065820155016113d9565b509450505050505b60015480156106c2575f1901806001556114aa6114996140ba565b809291600254948260443591614106565b9190926114b784826137ee565b908411611676578060243510611661576114d3906024356137ee565b806115fb575b506114eb916044356101e05155613be1565b608b556003546001600160a01b0316803b156102ca57604051632770a7eb60e21b81526101e05190918290818061152860243533600484016137fb565b03916101e051905af18015610720576115e0575b506002556040516370a0823160e01b8152306004820152602081602481855afa8015610720576101e051906115ac575b611578915033836142b6565b6004357fb3036f81a7a8205f3b94de16897df636d553839d92289fb7ec72dd2d541328426101e0516101e051a36101e05180f35b506020813d6020116115d8575b816115c66020938361375c565b8101031261124c57611578905161156c565b3d91506115b9565b6101e0516115ed9161375c565b6101e0516102ca578261153c565b6003546001600160a01b031690813b156102ca5760405180926340c10f1960e01b825281806116326101e0519533600484016137fb565b03916101e051905af1801561072057156114d9576101e0516116539161375c565b6101e0516102ca57846114d9565b634f0397ab60e01b6101e0515260046101e051fd5b635d7e4ee960e01b6101e0515260046101e051fd5b5094505050505061147e565b63083aafed60e41b6101e0515260046101e051fd5b600435841461179f5760208410156103325760058401546001600160a01b03166116d682896137da565b5260258401546116e6828a6137da565b5260458401546001600160a01b03166116ff828b6137da565b52606584015461170e90613c1e565b50959061171c8685876136f7565b35968715801561178e575b6117795769f4240f4240000000000064e8d4a510006117498a611758966136ea565b9904601481901b171791613c99565b611762828d6137da565b525f1981146106c2576001809101935b01926113bb565b6303aa729960e61b6101e0515260046101e051fd5b50670de0b6b3a76400008811611727565b92600190611772565b633bfe822760e11b6101e0515260046101e051fd5b63b8c449b360e01b6101e0515260046101e051fd5b63a596ef6d60e01b6101e0515260046101e051fd5b346102ca5760203660031901126102ca5760043560208110156102ca5760650154604051908152602090f35b346102ca576101e0513660031901126102ca576020608a54604051908152f35b346102ca576101e0513660031901126102ca576020608854604051908152f35b346102ca5760403660031901126102ca5760043561186f61368e565b6118776138a4565b60015482101561034c576020821015610332576045820180546001600160a01b0319166001600160a01b038316179055608b549160018101918282116106c2577f908a8bb84530a3f5baf8a0432620a6480e8b2af2e2423dae1222231a90caa5a4936040936118ff916118f991608082901c916001600160801b031690613cfa565b90613be1565b608b5582519182526001600160a01b03166020820152a16101e05180f35b346102ca5760603660031901126102ca576004356001600160401b0381116102ca5761194d9036906004016136ba565b906024356001600160401b0381116102ca5761196d9036906004016136ba565b92906044356001600160401b0381116102ca5761198e9036906004016136ba565b906119976138a4565b83861480611ada575b1561072e57600154936101e0515b602081106119bd576101e05180f35b818114611ad5576119cf8183896136f7565b35908682101561034c57670de0b6b3a76400006119ed828b896136f7565b35111580611ab8575b15611aa3576020821015610332578185611a5583611a37611a4f8b8f8b90611a488660019c60650199611a41611a2c8c54613c1e565b9b919b9a909a613c3d565b50509690986136f7565b35946136f7565b3592613c76565b91613c99565b90557f80394b5329e114f22712d6166857cd77c88256d851082e141591f481227fb8b96040611a85848d8b6136f7565b35611a91858a8a6136f7565b3582519182526020820152a2016119ae565b63bd18ee1f60e01b6101e0515260046101e051fd5b50670de0b6b3a7640000611acd8287876136f7565b3511156119f6565b6103af565b508382146119a0565b346102ca576101e0513660031901126102ca576003546040516001600160a01b039091168152602090f35b346102ca576101e0513660031901126102ca57608b54604080516001600160801b038316815260809290921c602083015290f35b346102ca576101e0513660031901126102ca576020600154604051908152f35b346102ca576101e0513660031901126102ca57638b78c6d819546040516001600160a01b039091168152602090f35b346102ca5760403660031901126102ca57600435611bad61368e565b611bb56138a4565b60015482101561034c57602082101561033257611bd58260650154613c1e565b50670de0b6b3a7640000820291808304670de0b6b3a764000014901517156106c257611c009161373e565b600181018091116106c2576025830154611c19916144b9565b6005909201546040516370a0823160e01b81523060048201526001600160a01b03919091169190602081602481865afa908115610720576101e05191611c8b575b5083811115611c76576103af93611c70916137ee565b916142b6565b63996f8ab960e01b6101e0515260046101e051fd5b90506020813d602011611cb5575b81611ca66020938361375c565b8101031261124c575184611c5a565b3d9150611c99565b346102ca5760203660031901126102ca57600435611cd96138a4565b801561072e576020817f03cd63f3fef742f82f64d7e1775b22c4fe9ed6d2bf0ca7cc04146d620e190ab292608755604051908152a16101e05180f35b346102ca5760203660031901126102ca57611d2e613662565b611d366138a4565b6001600160a01b0316801561072e57600480546001600160a01b031916821790556040519081527f58fd5d9c33114e6edf8ea5d30956f8d1a4ab112b004f99928b4bcf1b87d6666290602090a16101e05180f35b346102ca576101e0513660031901126102ca57611da56138bf565b60855460ff8116611deb5760ff19166001176085556101e05133907f5ee71a369c8672edded508e624ffc9257fa1ae6886ef32905c18e60196bca3999080a26101e05180f35b639784de2160e01b6101e0515260046101e051fd5b6101e0513660031901126102ca57611e166138da565b6101e051638b78c6d819547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a36101e051638b78c6d81981905580f35b346102ca5760803660031901126102ca57611e6e6136a4565b3068929eee149b4bd21268541461074d573068929eee149b4bd212685560015460043581111561072e57608b54611eb990608081901c906001600160801b0316600435600101613cfa565b919060025492611ecb602435856137ee565b60028190556003549091906001600160a01b0316803b156102ca57604051632770a7eb60e21b81526101e051909182908180611f0d60243533600484016137fb565b03916101e051905af180156107205761224b575b506020600435101561033257670de0b6b3a764000092611f6792611f4a60043560650154613c1e565b9691959093610a8264e8d4a510008a620fffff8b16020288613f99565b04966101e051905b60208210612224575b50509664e8d4a5100088611fae888a89611fde9b9c9d8a611f99818c6137ee565b978895620fffff6101e0515495160202614340565b99611fe4611fbc8c896137ee565b670de0b6b3a7640000611fd16086548361372b565b60011c049a8b80926137ee565b9c6136ea565b9a670de0b6b3a7640000810290808204670de0b6b3a764000014901517156106c257612013866120209261373e565b60256004350154906144b9565b9460443586106106ad5788612035918d613c99565b606560043501558015670de0b6b3a76400008083028390041417156106c2578a61207d61208392670de0b6b3a7640000610ae464e8d4a510008f620fffff8f16020285613f99565b936136ea565b976101e0515b602081101561220a578a811461215857600435810361210e57670de0b6b3a76400008802888104670de0b6b3a764000014891517156106c257876120cc9161373e565b908c670de0b6b3a7640000810204670de0b6b3a7640000148d1517156106c2576121088a6001938f8e670de0b6b3a7640000610dae920261373e565b01612089565b606581015461211c90613c1e565b9291670de0b6b3a7640000808202925081159183041417156106c25760019281610dae8e61214d8d6121539661373e565b9261373e565b612108565b5091945091969450602098508492975061217a95505b6121f7575b5050613be1565b608b556005600435015461219a90839083906001600160a01b03166142b6565b6040519060018060a01b031681526004358382015281604082015260243560608201527f7a3728879285f3ca5108b5f39698f28002a6b72cac81653343b8a7dfb75037f160803392a23868929eee149b4bd2126855604051908152f35b9161220192613aac565b90508187612173565b5091945091969450602098508492975061217a955061216e565b90978789146122455761223d8261089d8560019461372b565b980190611f6f565b97611f78565b6101e0516122589161375c565b6101e0516102ca5786611f21565b346102ca5760203660031901126102ca5760043560015481101561034c576020811015610332576020906065015460b01c604051908152f35b346102ca576101e0513660031901126102ca57602060ff608554166040519015158152f35b346102ca5760a03660031901126102ca576084356001600160a01b03811681036102ca573068929eee149b4bd21268541461074d573068929eee149b4bd21268556001546004356024351461277a57806004351080159061276e575b61034c57604435156112b657612355608b5460018060801b0381169060801c9060016024350160081b60016004350117613cfa565b929091602060043510156103325761237260043560650154613c1e565b959094602060243510156103325761238f60243560650154613c1e565b919889986101e051506123aa60043560250154604435613ccc565b956123f9670de0b6b3a76400006123d484611045836123cc8d6086549061372b565b04809c6137ee565b0496610a826123e3898c6136ea565b9d64e8d4a510008d620fffff8b16020290613f99565b908b670de0b6b3a7640000810204670de0b6b3a7640000148c1517156106c2578c80928d8b8d620fffff89160264e8d4a510000291670de0b6b3a764000002906124429161373e565b9061244c91614307565b6124559161373e565b9d6124618f99846136ea565b9061246b916137ee565b80988c6002546101e0515491620fffff8c160264e8d4a51000029461248f95614340565b968761249a916136ea565b9880670de0b6b3a7640000810204670de0b6b3a764000014811517156106c257848d610dae8c670de0b6b3a76400006124d887826124df980261373e565b930261373e565b670de0b6b3a7640000820290828204670de0b6b3a764000014831517156106c2576125099161373e565b9086670de0b6b3a7640000810204670de0b6b3a764000014871517156106c25784612554886125599361254f8a612566978f610dae90670de0b6b3a7640000870261373e565b6137ee565b6144b9565b60256024350154906144b9565b996064358b106106ad57866126a4575b8492612593949261258692613c99565b6065600435015584613c99565b60656024350155670de0b6b3a7640000888102988015908a0490911417156106c2576020976125d8859364e8d4a510006125ea98620fffff6125de9616020290613f99565b9061373e565b91612690575b50613be1565b608b556005600435015461260e9060443590309033906001600160a01b0316613fc6565b6005602435015461262b90839083906001600160a01b03166142b6565b6040519060018060a01b0316815260043583820152602435604082015260443560608201528160808201527fb3e2773606abfd36b5bd91394b3a54d1398336c65005baf7bf7a05efeffaf75b60a03392a23868929eee149b4bd2126855604051908152f35b61269c91600254613aac565b9050816125e4565b670de0b6b3a76400006126be83899e959a9e96949661372b565b049b83670de0b6b3a7640000810204670de0b6b3a764000014841517156106c2576126e98d836136ea565b9182670de0b6b3a7640000810204670de0b6b3a764000014831517156106c25786948e93828d620fffff8e160264e8d4a510000291670de0b6b3a764000002906127329161373e565b9061273c91614307565b61274f91670de0b6b3a76400000261373e565b9d612759916136ea565b91612763916136ea565b979250929092612576565b50806024351015612320565b63a8bf4d5f60e01b6101e0515260046101e051fd5b6101e0513660031901126102ca5763389a75e1600c52336101e051526101e0516020600c2055337ffa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c926101e0516101e051a26101e05180f35b346102ca5760403660031901126102ca57612800613662565b638b78c6d8600c526101e05152602060243581600c2054161515604051908152f35b346102ca5760403660031901126102ca5761283b613662565b61284361368e565b61284b6138a4565b6001546101e05190926001600160a01b0381169290915b6020811015612919578481146128a35760058101546001600160a01b0316841461288e57600101612862565b63103d1a8760e31b6101e0515260046101e051fd5b509091602493506020905b6040516370a0823160e01b815230600482015294859182905afa918215610720576101e051926128e3575b6103af93506142b6565b91506020833d602011612911575b816128fe6020938361375c565b8101031261124c576103af9251916128d9565b3d91506128f1565b509091602493506020906128ae565b346102ca5760203660031901126102ca5760043560208110156102ca57600501546040516001600160a01b039091168152602090f35b346102ca5760203660031901126102ca576004356001600160401b0381116102ca5761298e9036906004016136ba565b6001546101e051928391905b602083106129ff575b505050156129d8575b608b546129ce916118f991608081901c916001600160801b0390911690613cfa565b608b556101e05180f35b507f201f1e1d1c1b1a191817161514131211100f0e0d0c0b0a0908070605040302016129ac565b90929193828514612a485783612a168685856136f7565b35101561034c57612a288584846136f7565b3560018101919082106106c2576001918660031b1b17940191929061299a565b938293506129a3565b60403660031901126102ca576103af612a68613662565b612a706138da565b60243590614534565b346102ca576101e0513660031901126102ca5760206101e05154604051908152f35b346102ca576101e0513660031901126102ca576004546040516001600160a01b039091168152602090f35b346102ca576101e0513660031901126102ca57612ae161387c565b60855460ff811615612b485760ff8160081c16612b335761ff001916610100176085556101e0517fbe26733c2bf6ff3ea5ba8cfe744422bd49052ff9ed5685c9e81e6f9321dbaddd9080a16101e05180f35b631c6a9ca160e11b6101e0515260046101e051fd5b6363856c5960e01b6101e0515260046101e051fd5b346102ca576101e0513660031901126102ca57612b786138bf565b60855460ff811615612b485760ff8160081c16612b335760ff1916608555337faeb196d352664784d1900b0e7414a8face7d29f4dae8c4b0cf68ed477423bbf46101e0516101e051a26101e05180f35b3461124c57606036600319011261124c576004356001600160401b03811161124c57612bf89036906004016136ba565b90612c01613678565b903068929eee149b4bd2126854146131a9573068929eee149b4bd21268556001546102005261020051830361319a57608b545f19610220526001600160801b038116925f9260809290921c918391825b602081101561318c57610200518114612cf657612c6f8189856136f7565b358015612ce557906008612c8a600193836025015490613ccc565b95838301891b1797019486151580612cd9575b612cad575b505b01949294612c51565b612cc19061089d6108958460650154613c1e565b80610220511061022051821802186102205289612ca2565b50610220511515612c9d565b506001905f61022097959752612ca4565b5095939490949291925b1561317d57612d0e92613cfa565b61028052926102805190849260025495946102805191612d30610200516137a8565b935f610240525b602061024051101561316f57610200516102405114612f7557612d5e6102405183856136f7565b35612d70610240516025015482613ccc565b8015612f5f57612d9e670de0b6b3a764000061024051606501612d938154613c1e565b93919490809661372b565b0461026052612dbb82612db461026051866136ea565b9586613c99565b90558c612df5575b50506102405160050154612de5929150309033906001600160a01b0316613fc6565b6001610240510161024052612d37565b90969a87670de0b6b3a7640000819c949c9b959b0204670de0b6b3a76400001488151715612f4b5761028051612e3590670de0b6b3a76400008a0261373e565b61024051612e43908b6137da565b5261020051620fffff83160264e8d4a51000028b670de0b6b3a76400008a0290612e6c9161373e565b90612e7691613f99565b612e7f9161372b565b670de0b6b3a764000090049a61026051612e98916136ea565b9661022051612ea7908261372b565b670de0b6b3a764000090046102605190612ec0916137ee565b60865460011c612ecf9161372b565b670de0b6b3a764000090049a8b926102005190620fffff160264e8d4a510000292612ef9916137ee565b612f0c91670de0b6b3a76400000261373e565b90612f1691613f99565b612f1f9161372b565b670de0b6b3a76400009004976102605190612f39916137ee565b612f42916136ea565b958a8080612dc3565b634e487b7160e01b5f52601160045260245ffd5b505088612de55763f6ef3f5d60e01b5f5260045ffd5b9295909694979391975b84806130c85750505050612f916140ba565b809180156130b95782612faf92915b8615925f5490610200516141d6565b929097612fbc858a6137ee565b97881515806130ad575b1561309e576003546001600160a01b031691823b1561124c575f61300381948c6040519687809481936340c10f1960e01b83528b600484016137fb565b03925af1928315613093577f67902069e86c21d5ad116d9df073bf02a2bfdbd591414157cda22d3b8476cd539361307e575b506130488a604051938493339785613816565b0390a28691831561306b57505050610c2e9183916101e051549061020051614106565b60209750610ca195509093509150610c99565b5f6130889161375c565b5f6101e0528b613035565b6040513d5f823e3d90fd5b634647d8b560e01b5f5260045ffd5b50602435891015612fc6565b63df7da5cd60e01b5f5260045ffd5b5f9995939998969492985b602081101561315c5761020051811461315c576130f18189896136f7565b351561315457808b6131136131098360650154613c1e565b95919390506137da565b519281670de0b6b3a7640000810204670de0b6b3a76400001482151715612f4b57600193610dae8d670de0b6b3a764000061314e950261373e565b016130d3565b60019061314e565b50908093959950612faf92949698612fa0565b929590969497939197612f7f565b631f0ebc5760e21b5f5260045ffd5b509593949094929192612d00565b6341598eb160e01b5f5260045ffd5b63ab143c065f526004601cfd5b3461124c575f36600319011261124c576020608654604051908152f35b3461124c57608036600319011261124c576004356024356001600160401b03811161124c576132069036906004016136ba565b60443591606435936132166138a4565b60015493811561319a5784840361319a5742861061319a57608b54608081901c90613249906001600160801b0316613909565b91909161338d575b505060885461337e578560885561326881876136ea565b60895581608a555f955f965b6020881015613367578688146132f25761328f8887876136f7565b3597670de0b6b3a76400008910156132e3576132ad896001936136ea565b986132da82606501916132d1611a4f6132c68554613c1e565b949194939093613c3d565b93915091613c76565b90550196613274565b630152ac2f60e31b5f5260045ffd5b9092949550670de0b6b3a7640000919396505b03613358576133487fb0fb14f34df2e6ea25fc5285462fa7522278318522be931036565d550e5236a5956040519586958652608060208701526080860191613707565b91604084015260608301520390a1005b63083aafed60e41b5f5260045ffd5b9092949550670de0b6b3a764000091939650613305565b632ffc992d60e21b5f5260045ffd5b61339d816133a493600254613aac565b9050613be1565b608b558680613251565b3461124c57604036600319011261124c576133db6133ca613662565b6133d261387c565b60243590614579565b005b3461124c57602036600319011261124c576133f6613662565b638b78c6d8600c525f52602080600c2054604051908152f35b3461124c575f36600319011261124c576134276138e9565b608b54602090608081901c90613445906001600160801b0316613909565b918280613478575b61345e575b50506040519015158152f35b61339d8161346e93600254613aac565b608b558280613452565b5080151561344d565b3461124c57602036600319011261124c576004356001548110156134d45760208110156134c0576001600160601b036020916065015416604051908152f35b634e487b7160e01b5f52603260045260245ffd5b6367e0bf5f60e01b5f5260045ffd5b3461124c575f36600319011261124c576020608754604051908152f35b5f36600319011261124c5763389a75e1600c52335f526202a30042016020600c2055337fdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d5f80a2005b3461124c575f36600319011261124c57602060ff60855460081c166040519015158152f35b3461124c57604036600319011261124c576020613589613662565b60243590638b78c6d8600c525f528082600c20541614604051908152f35b604036600319011261124c576133db6135be613662565b6133d26138da565b602036600319011261124c576133db60043533614534565b3461124c575f36600319011261124c576135f66138a4565b5f6088555f6089557fc3014e77feddea63dc4c4b247508845d74eb35678da2e55000c3bb655727650e5f80a1005b3461124c57604036600319011261124c576133db613640613662565b612a7061387c565b3461124c575f36600319011261124c576020906002548152f35b600435906001600160a01b038216820361124c57565b604435906001600160a01b038216820361124c57565b602435906001600160a01b038216820361124c57565b606435906001600160a01b038216820361124c57565b9181601f8401121561124c578235916001600160401b03831161124c576020808501948460051b01011161124c57565b91908201809211612f4b57565b91908110156134c05760051b0190565b81835290916001600160fb1b03831161124c5760209260051b809284830137010190565b81810292918115918404141715612f4b57565b8115613748570490565b634e487b7160e01b5f52601260045260245ffd5b90601f801991011681019081106001600160401b0382111761377d57604052565b634e487b7160e01b5f52604160045260245ffd5b6001600160401b03811161377d5760051b60200190565b906137b282613791565b6137bf604051918261375c565b82815280926137d0601f1991613791565b0190602036910137565b80518210156134c05760209160051b010190565b91908203918211612f4b57565b6001600160a01b039091168152602081019190915260400190565b9493929160409261383c9260018060a01b03168752606060208801526060870191613707565b930152565b9081602091031261124c575160ff8116810361124c5790565b60ff166024039060ff8211612f4b57565b60ff16604d8111612f4b57600a0a90565b638b78c6d8600c52335f5260016020600c2054161561389757565b6382b429005f526004601cfd5b638b78c6d8600c52335f5260036020600c2054161561389757565b638b78c6d8600c52335f5260056020600c2054161561389757565b638b78c6d81954330361389757565b600160ff608554161515146138fa57565b63b8c449b360e01b5f5260045ffd5b90608854916089549083158015613aa3575b8015613a85575b613a7d575080839142105f14613a695761394b9161393f916137ee565b92426088555b426137ee565b915f5490608a548180159386855f14613a2e575050505b5f555f5b6020811015613a245760015481146139fd57600190806065016139ba876139a0611a4f87896139958754613c1e565b969196959095613c3d565b9592809592949195925f146139c25750505050805b613c76565b905501613966565b848111156139e657506139b59261089d6139e09261104587866137ee565b906137ee565b91506139b59261089d610afb9261104585886137ee565b50505090505b5f60025480613a14575b5090600190565b613a1e91506145bb565b5f613a0d565b5050509050613a03565b9091928083115f14613a54579261089d6139e092611045613a4f96866137ee565b613962565b9261089d610afb9261104585613a4f976137ee565b505061394b5f925f6088555f608955613945565b92505f919050565b50613a9084426137ee565b6087541180156139225750428211613922565b5042841161391b565b9092915f938215613bd85790613ac891600154845f5491614106565b93909180831115613b5f576003546004546001600160a01b0390811692911690613af290856137ee565b91813b15613b5b57918391613b1e93836040518096819582946340c10f1960e01b8452600484016137fb565b03925af18015613b5057613b38575b50505b806002559190565b613b4382809261375c565b613b4d5780613b2d565b80fd5b6040513d84823e3d90fd5b8380fd5b8091508210613b6f575b50613b30565b6003546004546001600160a01b0391821692911690613b8f9084906137ee565b823b1561124c57613bb9925f9283604051809681958294632770a7eb60e21b8452600484016137fb565b03925af180156130935715613b69575f613bd29161375c565b5f613b69565b935050505f9190565b906001600160801b0382111580613c0d575b613c06576341598eb160e01b5f5260045ffd5b60801b1790565b506001600160801b03811115613bf3565b6001600160601b038116916001600160501b038260601c169160b01c90565b9064e8d4a51000620fffff8316029164e8d4a51000620fffff8260141c16029164e8d4a5100080620fffff8460281c160292603c1c0290565b90919264e8d4a510008080809304603c1b950460281b930460141b910417171790565b90916001600160601b0382118015613cbc575b61319a5760b01b9160601b171790565b506001600160501b038311613cac565b90805f19048211613ce7575b670de0b6b3a764000091020490565b8015613cd85763bac65e5b5f526004601cfd5b91613d036138e9565b806102a052613d1182613909565b90936001545f5b60208110613d72575b505050159182613d68575b5081613d5b575b50613d5357613d49906102a05190600254613aac565b9050906102a05190565b906102a05190565b90506102a051145f613d33565b831491505f613d2c565b60ff838260031b1c1680158015613f90575b613f8a575f1981019060208210156134c05760018060a01b0360448201541690613db16064820154613c1e565b9190602060018060a01b036004860154166024604051809881936305d4ec6560e11b835260048301525afa948515613093575f95613f57575b508415613f4857808514613f3a57600b8102818104600b1482151715612f4b57600a9004851180613f31575b613f24575b5f9181151580613f18575b613e74575b5050927f516c8bdb823996757c901b6b9bd210afa82c6ec8d550f0e57cd3f64896f7319c926064613e636020948460019a9998613c99565b910155604051908152a25b01613d18565b9296959493909c9150670de0b6b3a76400008d02918d808404670de0b6b3a76400001490151715612f4b578480938a620fffff8b160264e8d4a510000291613ebb9161373e565b90613ec591613f99565b613ece9161372b565b670de0b6b3a764000090049c613ee4838561372b565b90613eee9161373e565b92836102a05190613efe916136ea565b90613f08916137ee565b6102a0529293949591905f613e2b565b506102a0511515613e26565b613f2c6138da565b613e1b565b50801515613e16565b505050505050600190613e6e565b639531a3a160e01b5f5260045ffd5b9094506020813d8211613f82575b81613f726020938361375c565b8101031261124c5751935f613dea565b3d9150613f65565b50613d21565b50828111613d84565b90613fa391614b00565b8015613fc157670de0b6b3a7640000606482025f1901040160010190565b505f90565b916040519360605260405260601b602c526323b872dd60601b600c5260205f6064601c82855af1908160015f51141615614006575b50505f606052604052565b3b153d171015614017575f80613ffb565b637939f4245f526004601cfd5b9164e8d4a51000620fffff8216029064e8d4a51000620fffff8260281c16028281115f146140b357505f5b831061409a5764e8d4a5100090603c1c020180670de0b6b3a764000010670de0b6b3a7640000821802188111614083575050565b101561408b57565b63b1a539bd60e01b5f5260045ffd5b505011156140a457565b637b3a1f9560e01b5f5260045ffd5b820361404f565b6001545f91825b60208410156140fd578284146140eb576001906001600160601b03856065015416019301926140c1565b925090505b6140f9826145bb565b9190565b925090506140f0565b9290939491670de0b6b3a763ffff19810195818711612f4b576141289161372b565b9390945f915b61010083106141465763b138078b60e01b5f5260045ffd5b801561319a5781878202870304905f5b602081106141ba575b506064908083106141a957670de0b6b3a76400008184035b0204111561418a5760019092019161412e565b9294506140f9935050670de0b6b3a764000060648302049190506136ea565b670de0b6b3a7640000838203614177565b978689146141d057818360019202049801614156565b9761415f565b939592909491670de0b6b3a763ffff19810196818811612f4b576141f99161372b565b9490955f915b61010083106142175763b138078b60e01b5f5260045ffd5b801561319a5781888202880304905f5b6020811061429a575b5060649080831061428957670de0b6b3a76400008184035b0204111561425b576001909201916141ff565b94505050909250670de0b6b3a76400006064830204905f14614280576140f9916136ea565b6140f9916137ee565b670de0b6b3a7640000838203614248565b98878a146142b057818360019202049901614227565b98614230565b919060145260345263a9059cbb60601b5f5260205f6044601082855af1908160015f511416156142e9575b50505f603452565b3b153d1710156142fa575f806142e1565b6390b8ec185f526004601cfd5b9061431191614b00565b8015613fc157670de0b6b3a7640000606482025f19010460018101821061433a5790035f190190565b50505f90565b92909194670de0b6b3a76400008602868104670de0b6b3a76400001487151715612f4b5761438461437d61438b94670de0b6b3a76400009361373e565b809761372b565b04946136ea565b90821561374857826a0c097ce7bc90715b34b9f160241b0490935f945b61010086106143c05763b138078b60e01b5f5260045ffd5b801561319a576064614451846125d88a61254f8961444c88670de0b6b3a76400006144468f614440848f8a61254f8a8f6144398161441f61104597610afb8a9c8f966144328161442c8f8b8f916125d8968f61441f90614425936136ea565b9361372b565b04906136ea565b9561372b565b918d613f99565b04906137ee565b9961372b565b046136ea565b6136ea565b918083106144a157670de0b6b3a764000061446c82856137ee565b0204111561447f576001909501946143a8565b94505050505061449e9150670de0b6b3a76400006064820204906136ea565b90565b670de0b6b3a76400006144b484836137ee565b61446c565b7812725dd1d243aba0e75fe645cc4873f9e65afe688c928e1f2281108202156144ea57670de0b6b3a7640000020490565b637c5f487d5f526004601cfd5b60018060a01b031680638b78c6d819547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a3638b78c6d81955565b638b78c6d8600c525f526020600c2090815490811618809155600c5160601c7f715ad5ce61fc9595c7b415289d59cf203f23a94fa06f04af7e489a0a76e1fe265f80a3565b638b78c6d8600c525f526020600c2090815417809155600c5160601c7f715ad5ce61fc9595c7b415289d59cf203f23a94fa06f04af7e489a0a76e1fe265f80a3565b6001545f670de0b6b3a76400005b602082101561463f5782821461463f57620fffff906145eb8360650154613c1e565b9050929092169064e8d4a510008202151580614636575b1561319a5761462c8260019464e8d4a510008089670de0b6b3a7640000970202928a020204614307565b02049101906145c9565b50821515614602565b9250505090565b9068056bc75e2d630fffff198201918213600116612f4b57565b906803782dace9d8ffffff198201918213600116612f4b57565b906806f05b59d3b1ffffff198201918213600116612f4b57565b9068ad78ebc5ac61ffffff198201918213600116612f4b57565b906856bc75e2d630ffffff198201918213600116612f4b57565b90682b5e3af16b187fffff198201918213600116612f4b57565b906815af1d78b58c3fffff198201918213600116612f4b57565b90680ad78ebc5ac61fffff198201918213600116612f4b57565b906802b5e3af16b187ffff198201918213600116612f4b57565b9068015af1d78b58c3ffff198201918213600116612f4b57565b906803782dace9d90000008201915f6803782dace9d900000084129112908015821691151617612f4b57565b9068ad78ebc5ac620000008201915f68ad78ebc5ac6200000084129112908015821691151617612f4b57565b906856bc75e2d6310000008201915f6856bc75e2d63100000084129112908015821691151617612f4b57565b90682b5e3af16b188000008201915f682b5e3af16b1880000084129112908015821691151617612f4b57565b906815af1d78b58c4000008201915f6815af1d78b58c40000084129112908015821691151617612f4b57565b90680ad78ebc5ac62000008201915f680ad78ebc5ac620000084129112908015821691151617612f4b57565b9068056bc75e2d631000008201915f68056bc75e2d6310000084129112908015821691151617612f4b57565b906802b5e3af16b18800008201915f6802b5e3af16b188000084129112908015821691151617612f4b57565b9068015af1d78b58c400008201915f68015af1d78b58c4000084129112908015821691151617612f4b57565b9067ad78ebc5ac6200008201915f67ad78ebc5ac62000084129112908015821691151617612f4b57565b906756bc75e2d63100008201915f6756bc75e2d631000084129112908015821691151617612f4b57565b908168056bc75e2d6310000001918212600116612f4b57565b9190915f8382019384129112908015821691151617612f4b57565b908160011b9180830560021490151715612f4b57565b90606482029180830560641490151715612f4b57565b9068056bc75e2d6310000082029180830568056bc75e2d631000001490151715612f4b57565b906b02df0ab5a80a22c61ab5a7008202918083056b02df0ab5a80a22c61ab5a7001490151715612f4b57565b90693f1fce3da636ea5cf850820291808305693f1fce3da636ea5cf8501490151715612f4b57565b90690127fa27722cc06cc5e2820291808305690127fa27722cc06cc5e21490151715612f4b57565b9068280e60114edb805d0382029180830568280e60114edb805d031490151715612f4b57565b90680ebc5fb41746121110820291808305680ebc5fb417461211101490151715612f4b57565b906808f00f760a4b2db55d8202918083056808f00f760a4b2db55d1490151715612f4b57565b906806f5f17757889379378202918083056806f5f17757889379371490151715612f4b57565b81810292915f8212600160ff1b821416612f4b578184051490151715612f4b57565b811561374857600160ff1b81145f19831416612f4b570590565b8115614e9157801561433a578060ff1c614e5a57770bce5086492111aea88f4bb1ca6bcf584181ea8059f76532821015614e235780670c7d713b49da00001280614e12575b15614df257670de0b6b3a76400008102908105670de0b6b3a764000003612f4b576ec097ce7bc90715b34b9f0fffffffff19810190600181831316612f4b576a0c097ce7bc90715b34b9f160241b8202918083056a0c097ce7bc90715b34b9f160241b1490151715612f4b576a0c097ce7bc90715b34b9f160241b8101905f6a0c097ce7bc90715b34b9f160241b83129112908015821691151617612f4b57614bed91614ae6565b614bf78180614ac4565b6a0c097ce7bc90715b34b9f160241b90058080808085614c18828098614ac4565b6a0c097ce7bc90715b34b9f160241b90059060038205614c3791614943565b91614c4191614ac4565b6a0c097ce7bc90715b34b9f160241b90059060058205614c6091614943565b91614c6a91614ac4565b6a0c097ce7bc90715b34b9f160241b90059060078205614c8991614943565b91614c9391614ac4565b6a0c097ce7bc90715b34b9f160241b90059060098205614cb291614943565b91614cbc91614ac4565b6a0c097ce7bc90715b34b9f160241b900590600b8205614cdb91614943565b91614ce591614ac4565b6a0c097ce7bc90715b34b9f160241b900590600d8205614d0491614943565b91614d0e91614ac4565b6a0c097ce7bc90715b34b9f160241b9005600f9005614d2c91614943565b614d359061495e565b90614d4a81670de0b6b3a76400008405614ac4565b91670de0b6b3a7640000900790614d6091614ac4565b670de0b6b3a76400009005614d7491614943565b670de0b6b3a7640000905b0580680238fd42c5cf03ffff19131580614ddf575b15614da25761449e90615348565b60405162461bcd60e51b815260206004820152601560248201527450726f64756374206f7574206f6620626f756e647360581b6044820152606490fd5b5068070c1cc73b00c80000811315614d94565b670de0b6b3a764000091614e08614e0d92614eaf565b614ac4565b614d7f565b50670f43fc2c04ee00008112614b45565b60405162461bcd60e51b815260206004820152600f60248201526e59206f7574206f6620626f756e647360881b6044820152606490fd5b60405162461bcd60e51b815260206004820152600f60248201526e58206f7574206f6620626f756e647360881b6044820152606490fd5b5050670de0b6b3a764000090565b600160ff1b8114612f4b575f0390565b670de0b6b3a764000081126152e05761449e906150a7905f775803bcc5cb9634ba4cfb2213f784019318ed4dcb6017880f60361b8212156152b7575b73011798004d755d3c8bc8e03204cf44619e00000082121561525d575b6150a261506061506061509b61503061507561509561508b61503061501a614f3b614f356150609c614974565b9c614974565b6e01855144814a7ff805980ff008400081121561522d575b6b02df0ab5a80a22c61ab5a700811215615200575b693f1fce3da636ea5cf8508112156151d5575b690127fa27722cc06cc5e28112156151aa575b68280e60114edb805d03811215615180575b680ebc5fb41746121110811215615156575b6808f00f760a4b2db55d81121561512c575b6806f5f1775788937937811215615102575b6806248f33704b2866038112156150d8575b6805c548670b9510e7ac8112156150ae575b61501461500e61500983614646565b61498a565b91614852565b90614ae6565b61508561507b61503061503f6150308580614ac4565b68056bc75e2d63100000900590565b80988561506c6150308461506661505a61503083809d614ac4565b94600386055b90614943565b93614ac4565b9e8f6005900590565b9c614ac4565b9960078b05615060565b98614ac4565b9560098705615060565b94614ac4565b600b900590565b61495e565b6064900590565b6150cc6150bd6150d29261498a565b6805c548670b9510e7ac900590565b9c614900565b9b614ffa565b6150f66150e76150fc9261498a565b6806248f33704b286603900590565b9c6148d6565b9b614fe8565b6151206151116151269261498a565b6806f5f1775788937937900590565b9c6148aa565b9b614fd6565b61514a61513b6151509261498a565b6808f00f760a4b2db55d900590565b9c61487e565b9b614fc4565b61517461516561517a9261498a565b680ebc5fb41746121110900590565b9c614852565b9b614fb2565b61519e61518f6151a49261498a565b68280e60114edb805d03900590565b9c614826565b9b614fa0565b6151c96151b96151cf9261498a565b690127fa27722cc06cc5e2900590565b9c6147fa565b9b614f8e565b6151f46151e46151fa9261498a565b693f1fce3da636ea5cf850900590565b9c6147ce565b9b614f7b565b61522161520f6152279261498a565b6b02df0ab5a80a22c61ab5a700900590565b9c6147a2565b9b614f68565b61525161523c6152579261498a565b6e01855144814a7ff805980ff0084000900590565b9c614776565b9b614f53565b906150a261506061506061509b61503061507561509561508b61503061501a614f3b614f356152a461529e6150609e6b1425982cf597cd205cef7380900590565b9e61474a565b9c50505050505050505050505050614f08565b5072195e54c5dd42177f53a27172fa9ec63026282760241b90056806f05b59d3b2000000614eeb565b6152fb615300916a0c097ce7bc90715b34b9f160241b614ae6565b614eaf565b61449e90614e9f565b1561531057565b60405162461bcd60e51b815260206004820152601060248201526f125b9d985b1a5908115e1c1bdb995b9d60821b6044820152606490fd5b680238fd42c5cf03ffff1981121580615746575b61536590615309565b5f811261571d576806f05b59d3b200000081126156e3576153859061467a565b6153a572195e54c5dd42177f53a27172fa9ec63026282760241b91614974565b68056bc75e2d631000009068ad78ebc5ac620000008112156156c3575b6856bc75e2d6310000008112156156a8575b682b5e3af16b1880000081121561568d575b6815af1d78b58c400000811215615672575b680ad78ebc5ac6200000811215615657575b68056bc75e2d6310000081121561563c575b6802b5e3af16b1880000811215615621575b68015af1d78b58c40000811215615606575b8080808080808080806154528161492a565b61545c8280614ac4565b68056bc75e2d63100000900560029005908161547791614943565b9161548191614ac4565b68056bc75e2d63100000900560039005908161549c91614943565b916154a691614ac4565b68056bc75e2d6310000090056004900590816154c191614943565b916154cb91614ac4565b68056bc75e2d6310000090056005900590816154e691614943565b916154f091614ac4565b68056bc75e2d63100000900560069005908161550b91614943565b9161551591614ac4565b68056bc75e2d63100000900560079005908161553091614943565b9161553a91614ac4565b68056bc75e2d63100000900560089005908161555591614943565b9161555f91614ac4565b68056bc75e2d63100000900560099005908161557a91614943565b9161558491614ac4565b68056bc75e2d631000009005600a9005908161559f91614943565b916155a991614ac4565b68056bc75e2d631000009005600b900590816155c491614943565b916155ce91614ac4565b68056bc75e2d631000009005600c90056155e791614943565b6155f091614ac4565b68056bc75e2d631000009005906150a791614ac4565b61503061561561561b92614730565b92614a9e565b90615440565b61503061563061563692614716565b92614a78565b9061542e565b61503061564b61565192614646565b92614a52565b9061541c565b61503061566661566c926146fc565b92614a2c565b9061540a565b615030615681615687926146e2565b92614a04565b906153f8565b61503061569c6156a2926146c8565b926149dc565b906153e6565b6150306156b76156bd926146ae565b926149b0565b906153d4565b6156cd9150614694565b6e01855144814a7ff805980ff0084000906153c2565b6803782dace9d90000008112615712576156fc90614660565b6153a56b1425982cf597cd205cef738091614974565b6153a5600191614974565b61573d6157386a0c097ce7bc90715b34b9f160241b92614e9f565b615348565b61449e91614ae6565b5068070c1cc73b00c8000081131561535c56fea2646970667358221220071e635e6ce0fe15b9370ebff787ee040261846f697e48c551992e1f8f1d6ef164736f6c634300081a0033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000003bcb4f5c22758b145820e1126e69d96f891d5f8b00000000000000000000000000000000000000000000003635c9adc5dea0000000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001800000000000000000000000001b514df3413da9931eb31f2ab72e32c0a507cad50000000000000000000000000000000000000000000000000000000000000002000000000000000000000000039e2fb66102314ce7b64ce5ce3e5183bc94ad38000000000000000000000000fa85fe5a8f5560e9039c04f2b0a90de1415abd7000000000000000000000000000000000000000000000000000000000000000020000000000000000000000005c6e05d97af61637fdf5144ad4ed81a12bfd35b00000000000000000000000005c6e05d97af61637fdf5144ad4ed81a12bfd35b00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000016345785d8a00000000000000000000000000000000000000000000000000000c7d713b49da0000
-----Decoded View---------------
Arg [0] : tokenAddress_ (address): 0x3BcB4F5C22758b145820E1126E69d96F891d5F8b
Arg [1] : amplification_ (uint256): 1000000000000000000000
Arg [2] : tokens_ (address[]): 0x039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38,0xfA85Fe5A8F5560e9039C04f2b0a90dE1415aBD70
Arg [3] : rateProviders_ (address[]): 0x5C6e05D97AF61637FDf5144AD4ed81A12bfD35b0,0x5C6e05D97AF61637FDf5144AD4ed81A12bfD35b0
Arg [4] : weights_ (uint256[]): 100000000000000000,900000000000000000
Arg [5] : owner_ (address): 0x1b514df3413DA9931eB31f2Ab72e32c0A507Cad5
-----Encoded View---------------
15 Constructor Arguments found :
Arg [0] : 0000000000000000000000003bcb4f5c22758b145820e1126e69d96f891d5f8b
Arg [1] : 00000000000000000000000000000000000000000000003635c9adc5dea00000
Arg [2] : 00000000000000000000000000000000000000000000000000000000000000c0
Arg [3] : 0000000000000000000000000000000000000000000000000000000000000120
Arg [4] : 0000000000000000000000000000000000000000000000000000000000000180
Arg [5] : 0000000000000000000000001b514df3413da9931eb31f2ab72e32c0a507cad5
Arg [6] : 0000000000000000000000000000000000000000000000000000000000000002
Arg [7] : 000000000000000000000000039e2fb66102314ce7b64ce5ce3e5183bc94ad38
Arg [8] : 000000000000000000000000fa85fe5a8f5560e9039c04f2b0a90de1415abd70
Arg [9] : 0000000000000000000000000000000000000000000000000000000000000002
Arg [10] : 0000000000000000000000005c6e05d97af61637fdf5144ad4ed81a12bfd35b0
Arg [11] : 0000000000000000000000005c6e05d97af61637fdf5144ad4ed81a12bfd35b0
Arg [12] : 0000000000000000000000000000000000000000000000000000000000000002
Arg [13] : 000000000000000000000000000000000000000000000000016345785d8a0000
Arg [14] : 0000000000000000000000000000000000000000000000000c7d713b49da0000
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
[ 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.