ERC-20
Overview
Max Total Supply
18,180.559349967751871256 LPePyvCurveLUSD-27DEC21
Holders
1,096
Market
Onchain Market Cap
$0.00
Circulating Supply Market Cap
-
Other Info
Token Contract (WITH 18 Decimals)
Balance
0.958541087221373913 LPePyvCurveLUSD-27DEC21Value
$0.00Loading...
Loading
Loading...
Loading
Loading...
Loading
# | Exchange | Pair | Price | 24H Volume | % Volume |
---|
Contract Name:
ConvergentCurvePool
Compiler Version
v0.7.1+commit.f4a555be
Optimization Enabled:
Yes with 10000 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "./interfaces/IERC20Decimals.sol"; import "./balancer-core-v2/lib/math/LogExpMath.sol"; import "./balancer-core-v2/lib/math/FixedPoint.sol"; import "./balancer-core-v2/vault/interfaces/IMinimalSwapInfoPool.sol"; import "./balancer-core-v2/vault/interfaces/IVault.sol"; import "./balancer-core-v2/pools/BalancerPoolToken.sol"; contract ConvergentCurvePool is IMinimalSwapInfoPool, BalancerPoolToken { using LogExpMath for uint256; using FixedPoint for uint256; // The token we expect to stay constant in value IERC20 public immutable underlying; uint8 public immutable underlyingDecimals; // The token we expect to appreciate to match underlying IERC20 public immutable bond; uint8 public immutable bondDecimals; // The expiration time uint256 public immutable expiration; // The number of seconds in our timescale uint256 public immutable unitSeconds; // The Balancer pool data // Note we change style to match Balancer's custom getter IVault private immutable _vault; bytes32 private immutable _poolId; // The fees recorded during swaps. These will be 18 point not token decimal encoded uint128 public feesUnderlying; uint128 public feesBond; // Stored records of governance tokens address public immutable governance; // The percent of each trade's implied yield to collect as LP fee uint256 public immutable percentFee; // The percent of LP fees that is payed to governance uint256 public immutable percentFeeGov; // Store constant token indexes for ascending sorted order // In this case despite these being internal it's cleaner // to ignore linting rules that require _ /* solhint-disable private-vars-leading-underscore */ uint256 internal immutable baseIndex; uint256 internal immutable bondIndex; /* solhint-enable private-vars-leading-underscore */ // The max percent fee for governance, immutable after compilation uint256 public constant FEE_BOUND = 3e17; /// @notice This event allows the frontend to track the fees /// @param collectedBase the base asset tokens fees collected in this txn /// @param collectedBond the bond asset tokens fees collected in this txn /// @param remainingBase the amount of base asset fees have been charged but not collected /// @param remainingBond the amount of bond asset fees have been charged but not collected /// @dev All values emitted by this event are 18 point fixed not token native decimals event FeeCollection( uint256 collectedBase, uint256 collectedBond, uint256 remainingBase, uint256 remainingBond ); /// @dev We need need to set the immutables on contract creation /// Note - We expect both 'bond' and 'underlying' to have 'decimals()' /// @param _underlying The asset which the second asset should appreciate to match /// @param _bond The asset which should be appreciating /// @param _expiration The time in unix seconds when the bond asset should equal the underlying asset /// @param _unitSeconds The number of seconds in a unit of time, for example 1 year in seconds /// @param vault The balancer vault /// @param _percentFee The percent each trade's yield to collect as fees /// @param _percentFeeGov The percent of collected that go to governance /// @param _governance The address which gets minted reward lp /// @param name The balancer pool token name /// @param symbol The balancer pool token symbol constructor( IERC20 _underlying, IERC20 _bond, uint256 _expiration, uint256 _unitSeconds, IVault vault, uint256 _percentFee, uint256 _percentFeeGov, address _governance, string memory name, string memory symbol ) BalancerPoolToken(name, symbol) { // Sanity Check require(_expiration - block.timestamp < _unitSeconds); // Initialization on the vault bytes32 poolId = vault.registerPool( IVault.PoolSpecialization.TWO_TOKEN ); IERC20[] memory tokens = new IERC20[](2); if (_underlying < _bond) { tokens[0] = _underlying; tokens[1] = _bond; } else { tokens[0] = _bond; tokens[1] = _underlying; } // Pass in zero addresses for Asset Managers // Note - functions below assume this token order vault.registerTokens(poolId, tokens, new address[](2)); // Set immutable state variables _vault = vault; _poolId = poolId; percentFee = _percentFee; // We check that the gov percent fee is less than bound require(_percentFeeGov < FEE_BOUND, "Fee too high"); percentFeeGov = _percentFeeGov; underlying = _underlying; underlyingDecimals = IERC20Decimals(address(_underlying)).decimals(); bond = _bond; bondDecimals = IERC20Decimals(address(_bond)).decimals(); expiration = _expiration; unitSeconds = _unitSeconds; governance = _governance; // Calculate the preset indexes for ordering bool underlyingFirst = _underlying < _bond; baseIndex = underlyingFirst ? 0 : 1; bondIndex = underlyingFirst ? 1 : 0; } // Balancer Interface required Getters /// @dev Returns the vault for this pool /// @return The vault for this pool function getVault() external view returns (IVault) { return _vault; } /// @dev Returns the poolId for this pool /// @return The poolId for this pool function getPoolId() external view returns (bytes32) { return _poolId; } // Trade Functionality /// @dev Called by the Vault on swaps to get a price quote /// @param swapRequest The request which contains the details of the swap /// @param currentBalanceTokenIn The input token balance /// @param currentBalanceTokenOut The output token balance /// @return the amount of the output or input token amount of for swap function onSwap( SwapRequest memory swapRequest, uint256 currentBalanceTokenIn, uint256 currentBalanceTokenOut ) public override returns (uint256) { // Check that the sender is pool, we change state so must make // this check. require(msg.sender == address(_vault), "Non Vault caller"); // Tokens amounts are passed to us in decimal form of the tokens // But we want theme in 18 point uint256 amount; bool isOutputSwap = swapRequest.kind == IVault.SwapKind.GIVEN_IN; if (isOutputSwap) { amount = _tokenToFixed(swapRequest.amount, swapRequest.tokenIn); } else { amount = _tokenToFixed(swapRequest.amount, swapRequest.tokenOut); } currentBalanceTokenIn = _tokenToFixed( currentBalanceTokenIn, swapRequest.tokenIn ); currentBalanceTokenOut = _tokenToFixed( currentBalanceTokenOut, swapRequest.tokenOut ); // We apply the trick which is used in the paper and // double count the reserves because the curve provisions liquidity // for prices above one underlying per bond, which we don't want to be accessible (uint256 tokenInReserve, uint256 tokenOutReserve) = _adjustedReserve( currentBalanceTokenIn, swapRequest.tokenIn, currentBalanceTokenOut, swapRequest.tokenOut ); // We switch on if this is an input or output case if (isOutputSwap) { // We get quote uint256 quote = solveTradeInvariant( amount, tokenInReserve, tokenOutReserve, isOutputSwap ); // We assign the trade fee quote = _assignTradeFee(amount, quote, swapRequest.tokenOut, false); // We return the quote return _fixedToToken(quote, swapRequest.tokenOut); } else { // We get the quote uint256 quote = solveTradeInvariant( amount, tokenOutReserve, tokenInReserve, isOutputSwap ); // We assign the trade fee quote = _assignTradeFee(quote, amount, swapRequest.tokenOut, true); // We return the output return _fixedToToken(quote, swapRequest.tokenIn); } } /// @dev Hook for joining the pool that must be called from the vault. /// It mints a proportional number of tokens compared to current LP pool, /// based on the maximum input the user indicates. /// @param poolId The balancer pool id, checked to ensure non erroneous vault call // @param sender Unused by this pool but in interface /// @param recipient The address which will receive lp tokens. /// @param currentBalances The current pool balances, sorted by address low to high. length 2 // @param latestBlockNumberUsed last block number unused in this pool /// @param protocolSwapFee The percent of pool fees to be paid to the Balancer Protocol /// @param userData Abi encoded fixed length 2 array containing max inputs also sorted by /// address low to high /// @return amountsIn The actual amounts of token the vault should move to this pool /// @return dueProtocolFeeAmounts The amounts of each token to pay as protocol fees function onJoinPool( bytes32 poolId, address, // sender address recipient, uint256[] memory currentBalances, uint256, uint256 protocolSwapFee, bytes calldata userData ) external override returns ( uint256[] memory amountsIn, uint256[] memory dueProtocolFeeAmounts ) { // Default checks require(msg.sender == address(_vault), "Non Vault caller"); require(poolId == _poolId, "Wrong pool id"); uint256[] memory maxAmountsIn = abi.decode(userData, (uint256[])); require( currentBalances.length == 2 && maxAmountsIn.length == 2, "Invalid format" ); // We must normalize the inputs to 18 point _normalizeSortedArray(currentBalances); _normalizeSortedArray(maxAmountsIn); // Mint LP to the governance address. // The {} zoning here helps solidity figure out the stack { ( uint256 localFeeUnderlying, uint256 localFeeBond ) = _mintGovernanceLP(currentBalances); dueProtocolFeeAmounts = new uint256[](2); dueProtocolFeeAmounts[baseIndex] = localFeeUnderlying.mulDown( protocolSwapFee ); dueProtocolFeeAmounts[bondIndex] = localFeeBond.mulDown( protocolSwapFee ); } // Mint for the user amountsIn = _mintLP( maxAmountsIn[baseIndex], maxAmountsIn[bondIndex], currentBalances, recipient ); // We now have make the outputs have the correct decimals _denormalizeSortedArray(amountsIn); _denormalizeSortedArray(dueProtocolFeeAmounts); } /// @dev Hook for leaving the pool that must be called from the vault. /// It burns a proportional number of tokens compared to current LP pool, /// based on the minium output the user wants. /// @param poolId The balancer pool id, checked to ensure non erroneous vault call // @param sender Unused by this pool but in interface /// @param recipient The address which will receive the withdraw tokens. /// @param currentBalances The current pool balances, sorted by address low to high. length 2 // @param latestBlockNumberUsed last block number unused in this pool /// @param protocolSwapFee The percent of pool fees to be paid to the Balancer Protocol /// @param userData Abi encoded fixed length 2 array containing min outputs also sorted by /// address low to high /// @return amountsOut The number of each token to send to the caller /// @return dueProtocolFeeAmounts The amounts of each token to pay as protocol fees function onExitPool( bytes32 poolId, address, address recipient, uint256[] memory currentBalances, uint256, uint256 protocolSwapFee, bytes calldata userData ) external override returns ( uint256[] memory amountsOut, uint256[] memory dueProtocolFeeAmounts ) { // Default checks require(msg.sender == address(_vault), "Non Vault caller"); require(poolId == _poolId, "Wrong pool id"); uint256[] memory minAmountsOut = abi.decode(userData, (uint256[])); require( currentBalances.length == 2 && minAmountsOut.length == 2, "Invalid format" ); // We have to convert to 18 decimals _normalizeSortedArray(currentBalances); _normalizeSortedArray(minAmountsOut); // Mint LP for the governance address. // {} zones to help solidity figure out the stack { ( uint256 localFeeUnderlying, uint256 localFeeBond ) = _mintGovernanceLP(currentBalances); // Calculate the amount of fees for balancer to collect dueProtocolFeeAmounts = new uint256[](2); dueProtocolFeeAmounts[baseIndex] = localFeeUnderlying.mulDown( protocolSwapFee ); dueProtocolFeeAmounts[bondIndex] = localFeeBond.mulDown( protocolSwapFee ); } amountsOut = _burnLP( minAmountsOut[baseIndex], minAmountsOut[bondIndex], currentBalances, recipient ); // We need to convert the balancer outputs to token decimals instead of 18 _denormalizeSortedArray(amountsOut); _denormalizeSortedArray(dueProtocolFeeAmounts); return (amountsOut, dueProtocolFeeAmounts); } /// @dev Returns the balances so that they'll be in the order [underlying, bond]. /// @param currentBalances balances sorted low to high of address value. function _getSortedBalances(uint256[] memory currentBalances) internal view returns (uint256 underlyingBalance, uint256 bondBalance) { return (currentBalances[baseIndex], currentBalances[bondIndex]); } /// @dev Turns an array of token amounts into an array of 18 point amounts /// @param data The data to normalize function _normalizeSortedArray(uint256[] memory data) internal view { data[baseIndex] = _normalize(data[baseIndex], underlyingDecimals, 18); data[bondIndex] = _normalize(data[bondIndex], bondDecimals, 18); } /// @dev Turns an array of 18 point amounts into token amounts /// @param data The data to turn in to token decimals function _denormalizeSortedArray(uint256[] memory data) internal view { data[baseIndex] = _normalize(data[baseIndex], 18, underlyingDecimals); data[bondIndex] = _normalize(data[bondIndex], 18, bondDecimals); } // Math libraries and internal routing /// @dev Calculates how many tokens should be outputted given an input plus reserve variables /// Assumes all inputs are in 18 point fixed compatible with the balancer fixed math lib. /// Since solving for an input is almost exactly the same as an output you can indicate /// if this is an input or output calculation in the call. /// @param amountX The amount of token x sent in normalized to have 18 decimals /// @param reserveX The amount of the token x currently held by the pool normalized to 18 decimals /// @param reserveY The amount of the token y currently held by the pool normalized to 18 decimals /// @param out Is true if the pool will receive amountX and false if it is expected to produce it. /// @return Either if 'out' is true the amount of Y token to send to the user or /// if 'out' is false the amount of Y Token to take from the user function solveTradeInvariant( uint256 amountX, uint256 reserveX, uint256 reserveY, bool out ) public view returns (uint256) { // Gets 1 - t uint256 a = _getYieldExponent(); // calculate x before ^ a uint256 xBeforePowA = LogExpMath.pow(reserveX, a); // calculate y before ^ a uint256 yBeforePowA = LogExpMath.pow(reserveY, a); // calculate x after ^ a uint256 xAfterPowA = out ? LogExpMath.pow(reserveX + amountX, a) : LogExpMath.pow(reserveX.sub(amountX), a); // Calculate y_after = ( x_before ^a + y_ before ^a - x_after^a)^(1/a) // Will revert with underflow here if the liquidity isn't enough for the trade uint256 yAfter = (xBeforePowA + yBeforePowA).sub(xAfterPowA); // Note that this call is to FixedPoint Div so works as intended yAfter = LogExpMath.pow(yAfter, uint256(FixedPoint.ONE).divDown(a)); // The amount of Y token to send is (reserveY_before - reserveY_after) return out ? reserveY.sub(yAfter) : yAfter.sub(reserveY); } /// @dev Adds a fee equal to to 'feePercent' of remaining interest to each trade /// This function accepts both input and output trades, amd expects that all /// inputs are in fixed 18 point /// @param amountIn The trade's amountIn in fixed 18 point /// @param amountOut The trade's amountOut in fixed 18 point /// @param outputToken The output token /// @param isInputTrade True if the trader is requesting a quote for the amount of input /// they need to provide to get 'amountOut' false otherwise /// @return The updated output quote // Note - The safe math in this function implicitly prevents the price of 'bond' in underlying // from being higher than 1. function _assignTradeFee( uint256 amountIn, uint256 amountOut, IERC20 outputToken, bool isInputTrade ) internal returns (uint256) { // The math splits on if this is input or output if (isInputTrade) { // Then it splits again on which token is the bond if (outputToken == bond) { // If the output is bond the implied yield is out - in uint256 impliedYieldFee = percentFee.mulDown( amountOut.sub(amountIn) ); // we record that fee collected from the underlying feesUnderlying += uint128(impliedYieldFee); // and return the adjusted input quote return amountIn.add(impliedYieldFee); } else { // If the input token is bond the implied yield is in - out uint256 impliedYieldFee = percentFee.mulDown( amountIn.sub(amountOut) ); // we record that collected fee from the input bond feesBond += uint128(impliedYieldFee); // and return the updated input quote return amountIn.add(impliedYieldFee); } } else { if (outputToken == bond) { // If the output is bond the implied yield is out - in uint256 impliedYieldFee = percentFee.mulDown( amountOut.sub(amountIn) ); // we record that fee collected from the bond output feesBond += uint128(impliedYieldFee); // and then return the updated output return amountOut.sub(impliedYieldFee); } else { // If the output is underlying the implied yield is in - out uint256 impliedYieldFee = percentFee.mulDown( amountIn.sub(amountOut) ); // we record the collected underlying fee feesUnderlying += uint128(impliedYieldFee); // and then return the updated output quote return amountOut.sub(impliedYieldFee); } } } /// @dev Mints the maximum possible LP given a set of max inputs /// @param inputUnderlying The max underlying to deposit /// @param inputBond The max bond to deposit /// @param currentBalances The current pool balances, sorted by address low to high. length 2 /// @param recipient The person who receives the lp funds /// @return amountsIn The actual amounts of token deposited in token sorted order function _mintLP( uint256 inputUnderlying, uint256 inputBond, uint256[] memory currentBalances, address recipient ) internal returns (uint256[] memory amountsIn) { // Initialize the memory array with length amountsIn = new uint256[](2); // Passing in in memory array helps stack but we use locals for better names (uint256 reserveUnderlying, uint256 reserveBond) = _getSortedBalances( currentBalances ); uint256 localTotalSupply = totalSupply(); // Check if the pool is initialized if (localTotalSupply == 0) { // When uninitialized we mint exactly the underlying input // in LP tokens _mintPoolTokens(recipient, inputUnderlying); // Return the right data amountsIn[baseIndex] = inputUnderlying; amountsIn[bondIndex] = 0; return (amountsIn); } // Get the reserve ratio, the say how many underlying per bond in the reserve // (input underlying / reserve underlying) is the percent increase caused by deposit uint256 underlyingPerBond = reserveUnderlying.divDown(reserveBond); // Use the underlying per bond to get the needed number of input underlying uint256 neededUnderlying = underlyingPerBond.mulDown(inputBond); // If the user can't provide enough underlying if (neededUnderlying > inputUnderlying) { // The increase in total supply is the input underlying // as a ratio to reserve uint256 mintAmount = (inputUnderlying.mulDown(localTotalSupply)) .divDown(reserveUnderlying); // We mint a new amount of as the the percent increase given // by the ratio of the input underlying to the reserve underlying _mintPoolTokens(recipient, mintAmount); // In this case we use the whole input of underlying // and consume (inputUnderlying/underlyingPerBond) bonds amountsIn[baseIndex] = inputUnderlying; amountsIn[bondIndex] = inputUnderlying.divDown(underlyingPerBond); } else { // We calculate the percent increase in the reserves from contributing // all of the bond uint256 mintAmount = (neededUnderlying.mulDown(localTotalSupply)) .divDown(reserveUnderlying); // We then mint an amount of pool token which corresponds to that increase _mintPoolTokens(recipient, mintAmount); // The indicate we consumed the input bond and (inputBond*underlyingPerBond) amountsIn[baseIndex] = neededUnderlying; amountsIn[bondIndex] = inputBond; } } /// @dev Burns at least enough LP tokens from the sender to produce /// as set of minium outputs. /// @param minOutputUnderlying The minimum output in underlying /// @param minOutputBond The minimum output in the bond /// @param currentBalances The current pool balances, sorted by address low to high. length 2 /// @param source The address to burn from. /// @return amountsReleased in address sorted order function _burnLP( uint256 minOutputUnderlying, uint256 minOutputBond, uint256[] memory currentBalances, address source ) internal returns (uint256[] memory amountsReleased) { // Initialize the memory array with length amountsReleased = new uint256[](2); // We take in sorted token arrays to help the stack but // use local names to improve readability (uint256 reserveUnderlying, uint256 reserveBond) = _getSortedBalances( currentBalances ); uint256 localTotalSupply = totalSupply(); // Calculate the ratio of the minOutputUnderlying to reserve uint256 underlyingPerBond = reserveUnderlying.divDown(reserveBond); // If the ratio won't produce enough bond if (minOutputUnderlying > minOutputBond.mulDown(underlyingPerBond)) { // In this case we burn enough tokens to output 'minOutputUnderlying' // which will be the total supply times the percent of the underlying // reserve which this amount of underlying is. uint256 burned = (minOutputUnderlying.mulDown(localTotalSupply)) .divDown(reserveUnderlying); _burnPoolTokens(source, burned); // We return that we released 'minOutputUnderlying' and the number of bonds that // preserves the reserve ratio amountsReleased[baseIndex] = minOutputUnderlying; amountsReleased[bondIndex] = minOutputUnderlying.divDown( underlyingPerBond ); } else { // Then the amount burned is the ratio of the minOutputBond // to the reserve of bond times the total supply uint256 burned = (minOutputBond.mulDown(localTotalSupply)).divDown( reserveBond ); _burnPoolTokens(source, burned); // We return that we released all of the minOutputBond // and the number of underlying which preserves the reserve ratio amountsReleased[baseIndex] = minOutputBond.mulDown( underlyingPerBond ); amountsReleased[bondIndex] = minOutputBond; } } /// @dev Mints LP tokens from a percentage of the stored fees and then updates them /// @param currentBalances The current pool balances, sorted by address low to high. length 2 /// expects the inputs to be 18 point fixed /// @return Returns the fee amounts as (feeUnderlying, feeBond) to avoid other sloads function _mintGovernanceLP(uint256[] memory currentBalances) internal returns (uint256, uint256) { // Load and cast the stored fees // Note - Because of sizes should only be one sload uint256 localFeeUnderlying = uint256(feesUnderlying); uint256 localFeeBond = uint256(feesBond); if (percentFeeGov == 0) { // We reset this state because it is expected that this function // resets the amount to match what's consumed and in the zero fee case // that's everything. (feesUnderlying, feesBond) = (0, 0); // Emit a fee tracking event emit FeeCollection(localFeeUnderlying, localFeeBond, 0, 0); // Return the used fees return (localFeeUnderlying, localFeeBond); } // Calculate the gov fee which is the assigned fees times the // percent uint256 govFeeUnderlying = localFeeUnderlying.mulDown(percentFeeGov); uint256 govFeeBond = localFeeBond.mulDown(percentFeeGov); // Mint the actual LP for gov address uint256[] memory consumed = _mintLP( govFeeUnderlying, govFeeBond, currentBalances, governance ); // We calculate the actual fees used uint256 usedFeeUnderlying = (consumed[baseIndex]).divDown( percentFeeGov ); uint256 usedFeeBond = (consumed[bondIndex]).divDown(percentFeeGov); // Calculate the remaining fees, note due to rounding errors they are likely to // be true that usedFees + remainingFees > originalFees by a very small rounding error // this is safe as with a bounded gov fee it never consumes LP funds. uint256 remainingUnderlying = govFeeUnderlying .sub(consumed[baseIndex]) .divDown(percentFeeGov); uint256 remainingBond = govFeeBond.sub(consumed[bondIndex]).divDown( percentFeeGov ); // Emit fee tracking event emit FeeCollection( usedFeeUnderlying, usedFeeBond, remainingUnderlying, remainingBond ); // Store the remaining fees feesUnderlying = uint128(remainingUnderlying); feesBond = uint128(remainingBond); // We return the fees which were removed from storage return (usedFeeUnderlying, usedFeeBond); } /// @dev Calculates 1 - t /// @return Returns 1 - t, encoded as a fraction in 18 decimal fixed point function _getYieldExponent() internal virtual view returns (uint256) { // The fractional time uint256 timeTillExpiry = block.timestamp < expiration ? expiration - block.timestamp : 0; timeTillExpiry *= 1e18; // timeTillExpiry now contains the a fixed point of the years remaining timeTillExpiry = timeTillExpiry.divDown(unitSeconds * 1e18); uint256 result = uint256(FixedPoint.ONE).sub(timeTillExpiry); // Sanity Check require(result != 0); // Return result return result; } /// @dev Applies the reserve adjustment from the paper and returns the reserves /// Note: The inputs should be in 18 point fixed to match the LP decimals /// @param reserveTokenIn The reserve of the input token /// @param tokenIn The address of the input token /// @param reserveTokenOut The reserve of the output token /// @return Returns (adjustedReserveIn, adjustedReserveOut) function _adjustedReserve( uint256 reserveTokenIn, IERC20 tokenIn, uint256 reserveTokenOut, IERC20 tokenOut ) internal view returns (uint256, uint256) { // We need to identify the bond asset and the underlying // This check is slightly redundant in most cases but more secure if (tokenIn == underlying && tokenOut == bond) { // We return (underlyingReserve, bondReserve + totalLP) return (reserveTokenIn, reserveTokenOut + totalSupply()); } else if (tokenIn == bond && tokenOut == underlying) { // We return (bondReserve + totalLP, underlyingReserve) return (reserveTokenIn + totalSupply(), reserveTokenOut); } // This should never be hit revert("Token request doesn't match stored"); } /// @dev Turns a token which is either 'bond' or 'underlying' into 18 point decimal /// @param amount The amount of the token in native decimal encoding /// @param token The address of the token /// @return The amount of token encoded into 18 point fixed point function _tokenToFixed(uint256 amount, IERC20 token) internal view returns (uint256) { // In both cases we are targeting 18 point if (token == underlying) { return _normalize(amount, underlyingDecimals, 18); } else if (token == bond) { return _normalize(amount, bondDecimals, 18); } // Should never happen revert("Called with non pool token"); } /// @dev Turns an 18 fixed point amount into a token amount /// Token must be either 'bond' or 'underlying' /// @param amount The amount of the token in 18 decimal fixed point /// @param token The address of the token /// @return The amount of token encoded in native decimal point function _fixedToToken(uint256 amount, IERC20 token) internal view returns (uint256) { if (token == underlying) { // Recodes to 'underlyingDecimals' decimals return _normalize(amount, 18, underlyingDecimals); } else if (token == bond) { // Recodes to 'bondDecimals' decimals return _normalize(amount, 18, bondDecimals); } // Should never happen revert("Called with non pool token"); } /// @dev Takes an 'amount' encoded with 'decimalsBefore' decimals and /// re encodes it with 'decimalsAfter' decimals /// @param amount The amount to normalize /// @param decimalsBefore The decimal encoding before /// @param decimalsAfter The decimal encoding after function _normalize( uint256 amount, uint8 decimalsBefore, uint8 decimalsAfter ) internal pure returns (uint256) { // If we need to increase the decimals if (decimalsBefore > decimalsAfter) { // Then we shift right the amount by the number of decimals amount = amount / 10**(decimalsBefore - decimalsAfter); // If we need to decrease the number } else if (decimalsBefore < decimalsAfter) { // then we shift left by the difference amount = amount * 10**(decimalsAfter - decimalsBefore); } // If nothing changed this is a no-op return amount; } }
// SPDX-License-Identifier: Apache-2.0 pragma solidity >=0.7.0; import "../balancer-core-v2/lib/openzeppelin/ERC20.sol"; interface IERC20Decimals is IERC20 { // Non standard but almost all erc20 have this function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated // documentation files (the “Software”), to deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the // Software. // THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. pragma solidity ^0.7.0; import "../helpers/BalancerErrors.sol"; /* solhint-disable */ /** * @dev Exponentiation and logarithm functions for 18 decimal fixed point numbers (both base and exponent/argument). * * 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 = 128000000000000000000; // 2ˆ7 int256 constant a0 = 38877084059945950922200000000000000000000000000000000000; // eˆ(x0) (no decimals) int256 constant x1 = 64000000000000000000; // 2ˆ6 int256 constant a1 = 6235149080811616882910000000; // eˆ(x1) (no decimals) // 20 decimal constants int256 constant x2 = 3200000000000000000000; // 2ˆ5 int256 constant a2 = 7896296018268069516100000000000000; // eˆ(x2) int256 constant x3 = 1600000000000000000000; // 2ˆ4 int256 constant a3 = 888611052050787263676000000; // eˆ(x3) int256 constant x4 = 800000000000000000000; // 2ˆ3 int256 constant a4 = 298095798704172827474000; // eˆ(x4) int256 constant x5 = 400000000000000000000; // 2ˆ2 int256 constant a5 = 5459815003314423907810; // eˆ(x5) int256 constant x6 = 200000000000000000000; // 2ˆ1 int256 constant a6 = 738905609893065022723; // eˆ(x6) int256 constant x7 = 100000000000000000000; // 2ˆ0 int256 constant a7 = 271828182845904523536; // eˆ(x7) int256 constant x8 = 50000000000000000000; // 2ˆ-1 int256 constant a8 = 164872127070012814685; // eˆ(x8) int256 constant x9 = 25000000000000000000; // 2ˆ-2 int256 constant a9 = 128402541668774148407; // eˆ(x9) int256 constant x10 = 12500000000000000000; // 2ˆ-3 int256 constant a10 = 113314845306682631683; // eˆ(x10) int256 constant x11 = 6250000000000000000; // 2ˆ-4 int256 constant a11 = 106449445891785942956; // 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 < 2**255, Errors.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, Errors.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, Errors.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, Errors.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, Errors.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: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. pragma solidity ^0.7.0; import "./LogExpMath.sol"; import "../helpers/BalancerErrors.sol"; /* solhint-disable private-vars-leading-underscore */ library FixedPoint { uint256 internal constant ONE = 1e18; // 18 decimal places uint256 internal constant MAX_POW_RELATIVE_ERROR = 10000; // 10^(-14) // Minimum base for the power function when the exponent is 'free' (larger than ONE). uint256 internal constant MIN_POW_BASE_FREE_EXPONENT = 0.7e18; function add(uint256 a, uint256 b) internal pure returns (uint256) { // Fixed Point addition is the same as regular checked addition uint256 c = a + b; _require(c >= a, Errors.ADD_OVERFLOW); return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { // Fixed Point addition is the same as regular checked addition _require(b <= a, Errors.SUB_OVERFLOW); uint256 c = a - b; return c; } function mulDown(uint256 a, uint256 b) internal pure returns (uint256) { uint256 product = a * b; _require(a == 0 || product / a == b, Errors.MUL_OVERFLOW); return product / ONE; } function mulUp(uint256 a, uint256 b) internal pure returns (uint256) { uint256 product = a * b; _require(a == 0 || product / a == b, Errors.MUL_OVERFLOW); if (product == 0) { return 0; } else { // The traditional divUp formula is: // divUp(x, y) := (x + y - 1) / y // To avoid intermediate overflow in the addition, we distribute the division and get: // divUp(x, y) := (x - 1) / y + 1 // Note that this requires x != 0, which we already tested for. return ((product - 1) / ONE) + 1; } } function divDown(uint256 a, uint256 b) internal pure returns (uint256) { _require(b != 0, Errors.ZERO_DIVISION); if (a == 0) { return 0; } else { uint256 aInflated = a * ONE; _require(aInflated / a == ONE, Errors.DIV_INTERNAL); // mul overflow return aInflated / b; } } function divUp(uint256 a, uint256 b) internal pure returns (uint256) { _require(b != 0, Errors.ZERO_DIVISION); if (a == 0) { return 0; } else { uint256 aInflated = a * ONE; _require(aInflated / a == ONE, Errors.DIV_INTERNAL); // mul overflow // The traditional divUp formula is: // divUp(x, y) := (x + y - 1) / y // To avoid intermediate overflow in the addition, we distribute the division and get: // divUp(x, y) := (x - 1) / y + 1 // Note that this requires x != 0, which we already tested for. return ((aInflated - 1) / b) + 1; } } /** * @dev Returns x^y, assuming both are fixed point numbers, rounding down. The result is guaranteed to not be above * the true value (that is, the error function expected - actual is always positive). */ function powDown(uint256 x, uint256 y) internal pure returns (uint256) { uint256 raw = LogExpMath.pow(x, y); uint256 maxError = add(mulUp(raw, MAX_POW_RELATIVE_ERROR), 1); if (raw < maxError) { return 0; } else { return sub(raw, maxError); } } /** * @dev Returns x^y, assuming both are fixed point numbers, rounding up. The result is guaranteed to not be below * the true value (that is, the error function expected - actual is always negative). */ function powUp(uint256 x, uint256 y) internal pure returns (uint256) { uint256 raw = LogExpMath.pow(x, y); uint256 maxError = add(mulUp(raw, MAX_POW_RELATIVE_ERROR), 1); return add(raw, maxError); } /** * @dev Returns the complement of a value (1 - x), capped to 0 if x is larger than 1. * * Useful when computing the complement for values with some level of relative error, as it strips this error and * prevents intermediate negative values. */ function complement(uint256 x) internal pure returns (uint256) { return (x < ONE) ? (ONE - x) : 0; } }
// SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "./IBasePool.sol"; /** * @dev Pool contracts with the MinimalSwapInfo or TwoToken specialization settings should implement this interface. * * This is called by the Vault when a user calls `IVault.swap` or `IVault.batchSwap` to swap with this Pool. * Returns the number of tokens the Pool will grant to the user in a 'given in' swap, or that the user will grant * to the pool in a 'given out' swap. * * This can often be implemented by a `view` function, since many pricing algorithms don't need to track state * changes in swaps. However, contracts implementing this in non-view functions should check that the caller is * indeed the Vault. */ interface IMinimalSwapInfoPool is IBasePool { function onSwap( SwapRequest memory swapRequest, uint256 currentBalanceTokenIn, uint256 currentBalanceTokenOut ) external returns (uint256 amount); }
// SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. pragma experimental ABIEncoderV2; import "../../lib/openzeppelin/IERC20.sol"; import "./IWETH.sol"; import "./IAsset.sol"; import "./IAuthorizer.sol"; import "./IFlashLoanRecipient.sol"; import "../ProtocolFeesCollector.sol"; import "../../lib/helpers/ISignaturesValidator.sol"; import "../../lib/helpers/ITemporarilyPausable.sol"; pragma solidity ^0.7.0; /** * @dev Full external interface for the Vault core contract - no external or public methods exist in the contract that * don't override one of these declarations. */ interface IVault is ISignaturesValidator, ITemporarilyPausable { // Generalities about the Vault: // // - Whenever documentation refers to 'tokens', it strictly refers to ERC20-compliant token contracts. Tokens are // transferred out of the Vault by calling the `IERC20.transfer` function, and transferred in by calling // `IERC20.transferFrom`. In these cases, the sender must have previously allowed the Vault to use their tokens by // calling `IERC20.approve`. The only deviation from the ERC20 standard that is supported is functions not returning // a boolean value: in these scenarios, a non-reverting call is assumed to be successful. // // - All non-view functions in the Vault are non-reentrant: calling them while another one is mid-execution (e.g. // while execution control is transferred to a token contract during a swap) will result in a revert. View // functions can be called in a re-reentrant way, but doing so might cause them to return inconsistent results. // Contracts calling view functions in the Vault must make sure the Vault has not already been entered. // // - View functions revert if referring to either unregistered Pools, or unregistered tokens for registered Pools. // Authorizer // // Some system actions are permissioned, like setting and collecting protocol fees. This permissioning system exists // outside of the Vault in the Authorizer contract: the Vault simply calls the Authorizer to check if the caller // can perform a given action. /** * @dev Returns the Vault's Authorizer. */ function getAuthorizer() external view returns (IAuthorizer); /** * @dev Sets a new Authorizer for the Vault. The caller must be allowed by the current Authorizer to do this. * * Emits an `AuthorizerChanged` event. */ function setAuthorizer(IAuthorizer newAuthorizer) external; /** * @dev Emitted when a new authorizer is set by `setAuthorizer`. */ event AuthorizerChanged(IAuthorizer indexed newAuthorizer); // Relayers // // Additionally, it is possible for an account to perform certain actions on behalf of another one, using their // Vault ERC20 allowance and Internal Balance. These accounts are said to be 'relayers' for these Vault functions, // and are expected to be smart contracts with sound authentication mechanisms. For an account to be able to wield // this power, two things must occur: // - The Authorizer must grant the account the permission to be a relayer for the relevant Vault function. This // means that Balancer governance must approve each individual contract to act as a relayer for the intended // functions. // - Each user must approve the relayer to act on their behalf. // This double protection means users cannot be tricked into approving malicious relayers (because they will not // have been allowed by the Authorizer via governance), nor can malicious relayers approved by a compromised // Authorizer or governance drain user funds, since they would also need to be approved by each individual user. /** * @dev Returns true if `user` has approved `relayer` to act as a relayer for them. */ function hasApprovedRelayer(address user, address relayer) external view returns (bool); /** * @dev Allows `relayer` to act as a relayer for `sender` if `approved` is true, and disallows it otherwise. * * Emits a `RelayerApprovalChanged` event. */ function setRelayerApproval( address sender, address relayer, bool approved ) external; /** * @dev Emitted every time a relayer is approved or disapproved by `setRelayerApproval`. */ event RelayerApprovalChanged(address indexed relayer, address indexed sender, bool approved); // Internal Balance // // Users can deposit tokens into the Vault, where they are allocated to their Internal Balance, and later // transferred or withdrawn. It can also be used as a source of tokens when joining Pools, as a destination // when exiting them, and as either when performing swaps. This usage of Internal Balance results in greatly reduced // gas costs when compared to relying on plain ERC20 transfers, leading to large savings for frequent users. // // Internal Balance management features batching, which means a single contract call can be used to perform multiple // operations of different kinds, with different senders and recipients, at once. /** * @dev Returns `user`'s Internal Balance for a set of tokens. */ function getInternalBalance(address user, IERC20[] memory tokens) external view returns (uint256[] memory); /** * @dev Performs a set of user balance operations, which involve Internal Balance (deposit, withdraw or transfer) * and plain ERC20 transfers using the Vault's allowance. This last feature is particularly useful for relayers, as * it lets integrators reuse a user's Vault allowance. * * For each operation, if the caller is not `sender`, it must be an authorized relayer for them. */ function manageUserBalance(UserBalanceOp[] memory ops) external payable; /** * @dev Data for `manageUserBalance` operations, which include the possibility for ETH to be sent and received without manual WETH wrapping or unwrapping. */ struct UserBalanceOp { UserBalanceOpKind kind; IAsset asset; uint256 amount; address sender; address payable recipient; } // There are four possible operations in `manageUserBalance`: // // - DEPOSIT_INTERNAL // Increases the Internal Balance of the `recipient` account by transferring tokens from the corresponding // `sender`. The sender must have allowed the Vault to use their tokens via `IERC20.approve()`. // // ETH can be used by passing the ETH sentinel value as the asset and forwarding ETH in the call: it will be wrapped // and deposited as WETH. Any ETH amount remaining will be sent back to the caller (not the sender, which is // relevant for relayers). // // Emits an `InternalBalanceChanged` event. // // // - WITHDRAW_INTERNAL // Decreases the Internal Balance of the `sender` account by transferring tokens to the `recipient`. // // ETH can be used by passing the ETH sentinel value as the asset. This will deduct WETH instead, unwrap it and send // it to the recipient as ETH. // // Emits an `InternalBalanceChanged` event. // // // - TRANSFER_INTERNAL // Transfers tokens from the Internal Balance of the `sender` account to the Internal Balance of `recipient`. // // Reverts if the ETH sentinel value is passed. // // Emits an `InternalBalanceChanged` event. // // // - TRANSFER_EXTERNAL // Transfers tokens from `sender` to `recipient`, using the Vault's ERC20 allowance. This is typically used by // relayers, as it lets them reuse a user's Vault allowance. // // Reverts if the ETH sentinel value is passed. // // Emits an `ExternalBalanceTransfer` event. enum UserBalanceOpKind { DEPOSIT_INTERNAL, WITHDRAW_INTERNAL, TRANSFER_INTERNAL, TRANSFER_EXTERNAL } /** * @dev Emitted when a user's Internal Balance changes, either from calls to `manageUserBalance`, or through * interacting with Pools using Internal Balance. * * Because Internal Balance works exclusively with ERC20 tokens, ETH deposits and withdrawals will use the WETH * address. */ event InternalBalanceChanged(address indexed user, IERC20 indexed token, int256 delta); /** * @dev Emitted when a user's Vault ERC20 allowance is used by the Vault to transfer tokens to an external account. */ event ExternalBalanceTransfer(IERC20 indexed token, address indexed sender, address recipient, uint256 amount); // Pools // // There are three specialization settings for Pools, which allow for cheaper swaps at the cost of reduced // functionality: // // - General: no specialization, suited for all Pools. IGeneralPool is used for swap request callbacks, passing the // balance of all tokens in the Pool. These Pools have the largest swap costs (because of the extra storage reads), // which increase with the number of registered tokens. // // - Minimal Swap Info: IMinimalSwapInfoPool is used instead of IGeneralPool, which saves gas by only passing the // balance of the two tokens involved in the swap. This is suitable for some pricing algorithms, like the weighted // constant product one popularized by Balancer V1. Swap costs are smaller compared to general Pools, and are // independent of the number of registered tokens. // // - Two Token: only allows two tokens to be registered. This achieves the lowest possible swap gas cost. Like // minimal swap info Pools, these are called via IMinimalSwapInfoPool. enum PoolSpecialization { GENERAL, MINIMAL_SWAP_INFO, TWO_TOKEN } /** * @dev Registers the caller account as a Pool with a given specialization setting. Returns the Pool's ID, which * is used in all Pool-related functions. Pools cannot be deregistered, nor can the Pool's specialization be * changed. * * The caller is expected to be a smart contract that implements either `IGeneralPool` or `IMinimalSwapInfoPool`, * depending on the chosen specialization setting. This contract is known as the Pool's contract. * * Note that the same contract may register itself as multiple Pools with unique Pool IDs, or in other words, * multiple Pools may share the same contract. * * Emits a `PoolRegistered` event. */ function registerPool(PoolSpecialization specialization) external returns (bytes32); /** * @dev Emitted when a Pool is registered by calling `registerPool`. */ event PoolRegistered(bytes32 indexed poolId, address indexed poolAddress, PoolSpecialization specialization); /** * @dev Returns a Pool's contract address and specialization setting. */ function getPool(bytes32 poolId) external view returns (address, PoolSpecialization); /** * @dev Registers `tokens` for the `poolId` Pool. Must be called by the Pool's contract. * * Pools can only interact with tokens they have registered. Users join a Pool by transferring registered tokens, * exit by receiving registered tokens, and can only swap registered tokens. * * Each token can only be registered once. For Pools with the Two Token specialization, `tokens` must have a length * of two, that is, both tokens must be registered in the same `registerTokens` call, and they must be sorted in * ascending order. * * The `tokens` and `assetManagers` arrays must have the same length, and each entry in these indicates the Asset * Manager for the corresponding token. Asset Managers can manage a Pool's tokens via `managePoolBalance`, * depositing and withdrawing them directly, and can even set their balance to arbitrary amounts. They are therefore * expected to be highly secured smart contracts with sound design principles, and the decision to register an * Asset Manager should not be made lightly. * * Pools can choose not to assign an Asset Manager to a given token by passing in the zero address. Once an Asset * Manager is set, it cannot be changed except by deregistering the associated token and registering again with a * different Asset Manager. * * Emits a `TokensRegistered` event. */ function registerTokens( bytes32 poolId, IERC20[] memory tokens, address[] memory assetManagers ) external; /** * @dev Emitted when a Pool registers tokens by calling `registerTokens`. */ event TokensRegistered(bytes32 indexed poolId, IERC20[] tokens, address[] assetManagers); /** * @dev Deregisters `tokens` for the `poolId` Pool. Must be called by the Pool's contract. * * Only registered tokens (via `registerTokens`) can be deregistered. Additionally, they must have zero total * balance. For Pools with the Two Token specialization, `tokens` must have a length of two, that is, both tokens * must be deregistered in the same `deregisterTokens` call. * * A deregistered token can be re-registered later on, possibly with a different Asset Manager. * * Emits a `TokensDeregistered` event. */ function deregisterTokens(bytes32 poolId, IERC20[] memory tokens) external; /** * @dev Emitted when a Pool deregisters tokens by calling `deregisterTokens`. */ event TokensDeregistered(bytes32 indexed poolId, IERC20[] tokens); /** * @dev Returns detailed information for a Pool's registered token. * * `cash` is the number of tokens the Vault currently holds for the Pool. `managed` is the number of tokens * withdrawn and held outside the Vault by the Pool's token Asset Manager. The Pool's total balance for `token` * equals the sum of `cash` and `managed`. * * Internally, `cash` and `managed` are stored using 112 bits. No action can ever cause a Pool's token `cash`, * `managed` or `total` balance to be greater than 2^112 - 1. * * `lastChangeBlock` is the number of the block in which `token`'s total balance was last modified (via either a * join, exit, swap, or Asset Manager update). This value is useful to avoid so-called 'sandwich attacks', for * example when developing price oracles. A change of zero (e.g. caused by a swap with amount zero) is considered a * change for this purpose, and will update `lastChangeBlock`. * * `assetManager` is the Pool's token Asset Manager. */ function getPoolTokenInfo(bytes32 poolId, IERC20 token) external view returns ( uint256 cash, uint256 managed, uint256 lastChangeBlock, address assetManager ); /** * @dev Returns a Pool's registered tokens, the total balance for each, and the latest block when *any* of * the tokens' `balances` changed. * * The order of the `tokens` array is the same order that will be used in `joinPool`, `exitPool`, as well as in all * Pool hooks (where applicable). Calls to `registerTokens` and `deregisterTokens` may change this order. * * If a Pool only registers tokens once, and these are sorted in ascending order, they will be stored in the same * order as passed to `registerTokens`. * * Total balances include both tokens held by the Vault and those withdrawn by the Pool's Asset Managers. These are * the amounts used by joins, exits and swaps. For a detailed breakdown of token balances, use `getPoolTokenInfo` * instead. */ function getPoolTokens(bytes32 poolId) external view returns ( IERC20[] memory tokens, uint256[] memory balances, uint256 lastChangeBlock ); /** * @dev Called by users to join a Pool, which transfers tokens from `sender` into the Pool's balance. This will * trigger custom Pool behavior, which will typically grant something in return to `recipient` - often tokenized * Pool shares. * * If the caller is not `sender`, it must be an authorized relayer for them. * * The `assets` and `maxAmountsIn` arrays must have the same length, and each entry indicates the maximum amount * to send for each asset. The amounts to send are decided by the Pool and not the Vault: it just enforces * these maximums. * * If joining a Pool that holds WETH, it is possible to send ETH directly: the Vault will do the wrapping. To enable * this mechanism, the IAsset sentinel value (the zero address) must be passed in the `assets` array instead of the * WETH address. Note that it is not possible to combine ETH and WETH in the same join. Any excess ETH will be sent * back to the caller (not the sender, which is important for relayers). * * `assets` must have the same length and order as the array returned by `getPoolTokens`. This prevents issues when * interacting with Pools that register and deregister tokens frequently. If sending ETH however, the array must be * sorted *before* replacing the WETH address with the ETH sentinel value (the zero address), which means the final * `assets` array might not be sorted. Pools with no registered tokens cannot be joined. * * If `fromInternalBalance` is true, the caller's Internal Balance will be preferred: ERC20 transfers will only * be made for the difference between the requested amount and Internal Balance (if any). Note that ETH cannot be * withdrawn from Internal Balance: attempting to do so will trigger a revert. * * This causes the Vault to call the `IBasePool.onJoinPool` hook on the Pool's contract, where Pools implement * their own custom logic. This typically requires additional information from the user (such as the expected number * of Pool shares). This can be encoded in the `userData` argument, which is ignored by the Vault and passed * directly to the Pool's contract, as is `recipient`. * * Emits a `PoolBalanceChanged` event. */ function joinPool( bytes32 poolId, address sender, address recipient, JoinPoolRequest memory request ) external payable; struct JoinPoolRequest { IAsset[] assets; uint256[] maxAmountsIn; bytes userData; bool fromInternalBalance; } /** * @dev Called by users to exit a Pool, which transfers tokens from the Pool's balance to `recipient`. This will * trigger custom Pool behavior, which will typically ask for something in return from `sender` - often tokenized * Pool shares. The amount of tokens that can be withdrawn is limited by the Pool's `cash` balance (see * `getPoolTokenInfo`). * * If the caller is not `sender`, it must be an authorized relayer for them. * * The `tokens` and `minAmountsOut` arrays must have the same length, and each entry in these indicates the minimum * token amount to receive for each token contract. The amounts to send are decided by the Pool and not the Vault: * it just enforces these minimums. * * If exiting a Pool that holds WETH, it is possible to receive ETH directly: the Vault will do the unwrapping. To * enable this mechanism, the IAsset sentinel value (the zero address) must be passed in the `assets` array instead * of the WETH address. Note that it is not possible to combine ETH and WETH in the same exit. * * `assets` must have the same length and order as the array returned by `getPoolTokens`. This prevents issues when * interacting with Pools that register and deregister tokens frequently. If receiving ETH however, the array must * be sorted *before* replacing the WETH address with the ETH sentinel value (the zero address), which means the * final `assets` array might not be sorted. Pools with no registered tokens cannot be exited. * * If `toInternalBalance` is true, the tokens will be deposited to `recipient`'s Internal Balance. Otherwise, * an ERC20 transfer will be performed. Note that ETH cannot be deposited to Internal Balance: attempting to * do so will trigger a revert. * * `minAmountsOut` is the minimum amount of tokens the user expects to get out of the Pool, for each token in the * `tokens` array. This array must match the Pool's registered tokens. * * This causes the Vault to call the `IBasePool.onExitPool` hook on the Pool's contract, where Pools implement * their own custom logic. This typically requires additional information from the user (such as the expected number * of Pool shares to return). This can be encoded in the `userData` argument, which is ignored by the Vault and * passed directly to the Pool's contract. * * Emits a `PoolBalanceChanged` event. */ function exitPool( bytes32 poolId, address sender, address payable recipient, ExitPoolRequest memory request ) external; struct ExitPoolRequest { IAsset[] assets; uint256[] minAmountsOut; bytes userData; bool toInternalBalance; } /** * @dev Emitted when a user joins or exits a Pool by calling `joinPool` or `exitPool`, respectively. */ event PoolBalanceChanged( bytes32 indexed poolId, address indexed liquidityProvider, IERC20[] tokens, int256[] deltas, uint256[] protocolFeeAmounts ); enum PoolBalanceChangeKind { JOIN, EXIT } // Swaps // // Users can swap tokens with Pools by calling the `swap` and `batchSwap` functions. To do this, // they need not trust Pool contracts in any way: all security checks are made by the Vault. They must however be // aware of the Pools' pricing algorithms in order to estimate the prices Pools will quote. // // The `swap` function executes a single swap, while `batchSwap` can perform multiple swaps in sequence. // In each individual swap, tokens of one kind are sent from the sender to the Pool (this is the 'token in'), // and tokens of another kind are sent from the Pool to the recipient in exchange (this is the 'token out'). // More complex swaps, such as one token in to multiple tokens out can be achieved by batching together // individual swaps. // // There are two swap kinds: // - 'given in' swaps, where the amount of tokens in (sent to the Pool) is known, and the Pool determines (via the // `onSwap` hook) the amount of tokens out (to send to the recipient). // - 'given out' swaps, where the amount of tokens out (received from the Pool) is known, and the Pool determines // (via the `onSwap` hook) the amount of tokens in (to receive from the sender). // // Additionally, it is possible to chain swaps using a placeholder input amount, which the Vault replaces with // the calculated output of the previous swap. If the previous swap was 'given in', this will be the calculated // tokenOut amount. If the previous swap was 'given out', it will use the calculated tokenIn amount. These extended // swaps are known as 'multihop' swaps, since they 'hop' through a number of intermediate tokens before arriving at // the final intended token. // // In all cases, tokens are only transferred in and out of the Vault (or withdrawn from and deposited into Internal // Balance) after all individual swaps have been completed, and the net token balance change computed. This makes // certain swap patterns, such as multihops, or swaps that interact with the same token pair in multiple Pools, cost // much less gas than they would otherwise. // // It also means that under certain conditions it is possible to perform arbitrage by swapping with multiple // Pools in a way that results in net token movement out of the Vault (profit), with no tokens being sent in (only // updating the Pool's internal accounting). // // To protect users from front-running or the market changing rapidly, they supply a list of 'limits' for each token // involved in the swap, where either the maximum number of tokens to send (by passing a positive value) or the // minimum amount of tokens to receive (by passing a negative value) is specified. // // Additionally, a 'deadline' timestamp can also be provided, forcing the swap to fail if it occurs after // this point in time (e.g. if the transaction failed to be included in a block promptly). // // If interacting with Pools that hold WETH, it is possible to both send and receive ETH directly: the Vault will do // the wrapping and unwrapping. To enable this mechanism, the IAsset sentinel value (the zero address) must be // passed in the `assets` array instead of the WETH address. Note that it is possible to combine ETH and WETH in the // same swap. Any excess ETH will be sent back to the caller (not the sender, which is relevant for relayers). // // Finally, Internal Balance can be used when either sending or receiving tokens. enum SwapKind { GIVEN_IN, GIVEN_OUT } /** * @dev Performs a swap with a single Pool. * * If the swap is 'given in' (the number of tokens to send to the Pool is known), it returns the amount of tokens * taken from the Pool, which must be greater than or equal to `limit`. * * If the swap is 'given out' (the number of tokens to take from the Pool is known), it returns the amount of tokens * sent to the Pool, which must be less than or equal to `limit`. * * Internal Balance usage and the recipient are determined by the `funds` struct. * * Emits a `Swap` event. */ function swap( SingleSwap memory singleSwap, FundManagement memory funds, uint256 limit, uint256 deadline ) external payable returns (uint256); /** * @dev Data for a single swap executed by `swap`. `amount` is either `amountIn` or `amountOut` depending on * the `kind` value. * * `assetIn` and `assetOut` are either token addresses, or the IAsset sentinel value for ETH (the zero address). * Note that Pools never interact with ETH directly: it will be wrapped to or unwrapped from WETH by the Vault. * * The `userData` field is ignored by the Vault, but forwarded to the Pool in the `onSwap` hook, and may be * used to extend swap behavior. */ struct SingleSwap { bytes32 poolId; SwapKind kind; IAsset assetIn; IAsset assetOut; uint256 amount; bytes userData; } /** * @dev Performs a series of swaps with one or multiple Pools. In each individual swap, the caller determines either * the amount of tokens sent to or received from the Pool, depending on the `kind` value. * * Returns an array with the net Vault asset balance deltas. Positive amounts represent tokens (or ETH) sent to the * Vault, and negative amounts represent tokens (or ETH) sent by the Vault. Each delta corresponds to the asset at * the same index in the `assets` array. * * Swaps are executed sequentially, in the order specified by the `swaps` array. Each array element describes a * Pool, the token to be sent to this Pool, the token to receive from it, and an amount that is either `amountIn` or * `amountOut` depending on the swap kind. * * Multihop swaps can be executed by passing an `amount` value of zero for a swap. This will cause the amount in/out * of the previous swap to be used as the amount in for the current one. In a 'given in' swap, 'tokenIn' must equal * the previous swap's `tokenOut`. For a 'given out' swap, `tokenOut` must equal the previous swap's `tokenIn`. * * The `assets` array contains the addresses of all assets involved in the swaps. These are either token addresses, * or the IAsset sentinel value for ETH (the zero address). Each entry in the `swaps` array specifies tokens in and * out by referencing an index in `assets`. Note that Pools never interact with ETH directly: it will be wrapped to * or unwrapped from WETH by the Vault. * * Internal Balance usage, sender, and recipient are determined by the `funds` struct. The `limits` array specifies * the minimum or maximum amount of each token the vault is allowed to transfer. * * `batchSwap` can be used to make a single swap, like `swap` does, but doing so requires more gas than the * equivalent `swap` call. * * Emits `Swap` events. */ function batchSwap( SwapKind kind, BatchSwapStep[] memory swaps, IAsset[] memory assets, FundManagement memory funds, int256[] memory limits, uint256 deadline ) external payable returns (int256[] memory); /** * @dev Data for each individual swap executed by `batchSwap`. The asset in and out fields are indexes into the * `assets` array passed to that function, and ETH assets are converted to WETH. * * If `amount` is zero, the multihop mechanism is used to determine the actual amount based on the amount in/out * from the previous swap, depending on the swap kind. * * The `userData` field is ignored by the Vault, but forwarded to the Pool in the `onSwap` hook, and may be * used to extend swap behavior. */ struct BatchSwapStep { bytes32 poolId; uint256 assetInIndex; uint256 assetOutIndex; uint256 amount; bytes userData; } /** * @dev Emitted for each individual swap performed by `swap` or `batchSwap`. */ event Swap( bytes32 indexed poolId, IERC20 indexed tokenIn, IERC20 indexed tokenOut, uint256 amountIn, uint256 amountOut ); /** * @dev All tokens in a swap are either sent from the `sender` account to the Vault, or from the Vault to the * `recipient` account. * * If the caller is not `sender`, it must be an authorized relayer for them. * * If `fromInternalBalance` is true, the `sender`'s Internal Balance will be preferred, performing an ERC20 * transfer for the difference between the requested amount and the User's Internal Balance (if any). The `sender` * must have allowed the Vault to use their tokens via `IERC20.approve()`. This matches the behavior of * `joinPool`. * * If `toInternalBalance` is true, tokens will be deposited to `recipient`'s internal balance instead of * transferred. This matches the behavior of `exitPool`. * * Note that ETH cannot be deposited to or withdrawn from Internal Balance: attempting to do so will trigger a * revert. */ struct FundManagement { address sender; bool fromInternalBalance; address payable recipient; bool toInternalBalance; } /** * @dev Simulates a call to `batchSwap`, returning an array of Vault asset deltas. Calls to `swap` cannot be * simulated directly, but an equivalent `batchSwap` call can and will yield the exact same result. * * Each element in the array corresponds to the asset at the same index, and indicates the number of tokens (or ETH) * the Vault would take from the sender (if positive) or send to the recipient (if negative). The arguments it * receives are the same that an equivalent `batchSwap` call would receive. * * Unlike `batchSwap`, this function performs no checks on the sender or recipient field in the `funds` struct. * This makes it suitable to be called by off-chain applications via eth_call without needing to hold tokens, * approve them for the Vault, or even know a user's address. * * Note that this function is not 'view' (due to implementation details): the client code must explicitly execute * eth_call instead of eth_sendTransaction. */ function queryBatchSwap( SwapKind kind, BatchSwapStep[] memory swaps, IAsset[] memory assets, FundManagement memory funds ) external returns (int256[] memory assetDeltas); // Flash Loans /** * @dev Performs a 'flash loan', sending tokens to `recipient`, executing the `receiveFlashLoan` hook on it, * and then reverting unless the tokens plus a proportional protocol fee have been returned. * * The `tokens` and `amounts` arrays must have the same length, and each entry in these indicates the loan amount * for each token contract. `tokens` must be sorted in ascending order. * * The 'userData' field is ignored by the Vault, and forwarded as-is to `recipient` as part of the * `receiveFlashLoan` call. * * Emits `FlashLoan` events. */ function flashLoan( IFlashLoanRecipient recipient, IERC20[] memory tokens, uint256[] memory amounts, bytes memory userData ) external; /** * @dev Emitted for each individual flash loan performed by `flashLoan`. */ event FlashLoan(IFlashLoanRecipient indexed recipient, IERC20 indexed token, uint256 amount, uint256 feeAmount); // Asset Management // // Each token registered for a Pool can be assigned an Asset Manager, which is able to freely withdraw the Pool's // tokens from the Vault, deposit them, or assign arbitrary values to its `managed` balance (see // `getPoolTokenInfo`). This makes them extremely powerful and dangerous. Even if an Asset Manager only directly // controls one of the tokens in a Pool, a malicious manager could set that token's balance to manipulate the // prices of the other tokens, and then drain the Pool with swaps. The risk of using Asset Managers is therefore // not constrained to the tokens they are managing, but extends to the entire Pool's holdings. // // However, a properly designed Asset Manager smart contract can be safely used for the Pool's benefit, // for example by lending unused tokens out for interest, or using them to participate in voting protocols. // // This concept is unrelated to the IAsset interface. /** * @dev Performs a set of Pool balance operations, which may be either withdrawals, deposits or updates. * * Pool Balance management features batching, which means a single contract call can be used to perform multiple * operations of different kinds, with different Pools and tokens, at once. * * For each operation, the caller must be registered as the Asset Manager for `token` in `poolId`. */ function managePoolBalance(PoolBalanceOp[] memory ops) external; struct PoolBalanceOp { PoolBalanceOpKind kind; bytes32 poolId; IERC20 token; uint256 amount; } /** * Withdrawals decrease the Pool's cash, but increase its managed balance, leaving the total balance unchanged. * * Deposits increase the Pool's cash, but decrease its managed balance, leaving the total balance unchanged. * * Updates don't affect the Pool's cash balance, but because the managed balance changes, it does alter the total. * The external amount can be either increased or decreased by this call (i.e., reporting a gain or a loss). */ enum PoolBalanceOpKind { WITHDRAW, DEPOSIT, UPDATE } /** * @dev Emitted when a Pool's token Asset Manager alters its balance via `managePoolBalance`. */ event PoolBalanceManaged( bytes32 indexed poolId, address indexed assetManager, IERC20 indexed token, int256 cashDelta, int256 managedDelta ); // Protocol Fees // // Some operations cause the Vault to collect tokens in the form of protocol fees, which can then be withdrawn by // permissioned accounts. // // There are two kinds of protocol fees: // // - flash loan fees: charged on all flash loans, as a percentage of the amounts lent. // // - swap fees: a percentage of the fees charged by Pools when performing swaps. For a number of reasons, including // swap gas costs and interface simplicity, protocol swap fees are not charged on each individual swap. Rather, // Pools are expected to keep track of how much they have charged in swap fees, and pay any outstanding debts to the // Vault when they are joined or exited. This prevents users from joining a Pool with unpaid debt, as well as // exiting a Pool in debt without first paying their share. /** * @dev Returns the current protocol fee module. */ function getProtocolFeesCollector() external view returns (ProtocolFeesCollector); /** * @dev Safety mechanism to pause most Vault operations in the event of an emergency - typically detection of an * error in some part of the system. * * The Vault can only be paused during an initial time period, after which pausing is forever disabled. * * While the contract is paused, the following features are disabled: * - depositing and transferring internal balance * - transferring external balance (using the Vault's allowance) * - swaps * - joining Pools * - Asset Manager interactions * * Internal Balance can still be withdrawn, and Pools exited. */ function setPaused(bool paused) external; /** * @dev Returns the Vault's WETH instance. */ function WETH() external view returns (IWETH); // solhint-disable-previous-line func-name-mixedcase }
// SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. pragma solidity ^0.7.0; import "../lib/math/Math.sol"; import "../lib/openzeppelin/IERC20.sol"; import "../lib/openzeppelin/IERC20Permit.sol"; import "../lib/openzeppelin/EIP712.sol"; /** * @title Highly opinionated token implementation * @author Balancer Labs * @dev * - Includes functions to increase and decrease allowance as a workaround * for the well-known issue with `approve`: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * - Allows for 'infinite allowance', where an allowance of 0xff..ff is not * decreased by calls to transferFrom * - Lets a token holder use `transferFrom` to send their own tokens, * without first setting allowance * - Emits 'Approval' events whenever allowance is changed by `transferFrom` */ contract BalancerPoolToken is IERC20, IERC20Permit, EIP712 { using Math for uint256; // State variables uint8 private constant _DECIMALS = 18; mapping(address => uint256) private _balance; mapping(address => mapping(address => uint256)) private _allowance; uint256 private _totalSupply; string private _name; string private _symbol; mapping(address => uint256) private _nonces; // solhint-disable-next-line var-name-mixedcase bytes32 private immutable _PERMIT_TYPE_HASH = keccak256( "Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)" ); // Function declarations constructor(string memory tokenName, string memory tokenSymbol) EIP712(tokenName, "1") { _name = tokenName; _symbol = tokenSymbol; } // External functions function allowance(address owner, address spender) external view override returns (uint256) { return _allowance[owner][spender]; } function balanceOf(address account) external view override returns (uint256) { return _balance[account]; } function approve(address spender, uint256 amount) external override returns (bool) { _setAllowance(msg.sender, spender, amount); return true; } function increaseApproval(address spender, uint256 amount) external returns (bool) { _setAllowance(msg.sender, spender, _allowance[msg.sender][spender].add(amount)); return true; } function decreaseApproval(address spender, uint256 amount) external returns (bool) { uint256 currentAllowance = _allowance[msg.sender][spender]; if (amount >= currentAllowance) { _setAllowance(msg.sender, spender, 0); } else { _setAllowance(msg.sender, spender, currentAllowance.sub(amount)); } return true; } function transfer(address recipient, uint256 amount) external override returns (bool) { _move(msg.sender, recipient, amount); return true; } function transferFrom( address sender, address recipient, uint256 amount ) external override returns (bool) { uint256 currentAllowance = _allowance[sender][msg.sender]; _require(msg.sender == sender || currentAllowance >= amount, Errors.INSUFFICIENT_ALLOWANCE); _move(sender, recipient, amount); if (msg.sender != sender && currentAllowance != uint256(-1)) { // Because of the previous require, we know that if msg.sender != sender then currentAllowance >= amount _setAllowance(sender, msg.sender, currentAllowance - amount); } return true; } function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) public virtual override { // solhint-disable-next-line not-rely-on-time _require(block.timestamp <= deadline, Errors.EXPIRED_PERMIT); uint256 nonce = _nonces[owner]; bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPE_HASH, owner, spender, value, nonce, deadline)); bytes32 hash = _hashTypedDataV4(structHash); address signer = ecrecover(hash, v, r, s); _require((signer != address(0)) && (signer == owner), Errors.INVALID_SIGNATURE); _nonces[owner] = nonce + 1; _setAllowance(owner, spender, value); } // Public functions function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public pure returns (uint8) { return _DECIMALS; } function totalSupply() public view override returns (uint256) { return _totalSupply; } function nonces(address owner) external view override returns (uint256) { return _nonces[owner]; } // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view override returns (bytes32) { return _domainSeparatorV4(); } // Internal functions function _mintPoolTokens(address recipient, uint256 amount) internal { _balance[recipient] = _balance[recipient].add(amount); _totalSupply = _totalSupply.add(amount); emit Transfer(address(0), recipient, amount); } function _burnPoolTokens(address sender, uint256 amount) internal { uint256 currentBalance = _balance[sender]; _require(currentBalance >= amount, Errors.INSUFFICIENT_BALANCE); _balance[sender] = currentBalance - amount; _totalSupply = _totalSupply.sub(amount); emit Transfer(sender, address(0), amount); } function _move( address sender, address recipient, uint256 amount ) internal { uint256 currentBalance = _balance[sender]; _require(currentBalance >= amount, Errors.INSUFFICIENT_BALANCE); // Prohibit transfers to the zero address to avoid confusion with the // Transfer event emitted by `_burnPoolTokens` _require(recipient != address(0), Errors.ERC20_TRANSFER_TO_ZERO_ADDRESS); _balance[sender] = currentBalance - amount; _balance[recipient] = _balance[recipient].add(amount); emit Transfer(sender, recipient, amount); } // Private functions function _setAllowance( address owner, address spender, uint256 amount ) private { _allowance[owner][spender] = amount; emit Approval(owner, spender, amount); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.7.0; import "../helpers/BalancerErrors.sol"; import "./IERC20.sol"; import "./SafeMath.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is IERC20 { using SafeMath for uint256; mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(msg.sender, recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(msg.sender, spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve( sender, msg.sender, _allowances[sender][msg.sender].sub(amount, Errors.ERC20_TRANSFER_EXCEEDS_ALLOWANCE) ); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve( msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue, Errors.ERC20_DECREASED_ALLOWANCE_BELOW_ZERO) ); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { _require(sender != address(0), Errors.ERC20_TRANSFER_FROM_ZERO_ADDRESS); _require(recipient != address(0), Errors.ERC20_TRANSFER_TO_ZERO_ADDRESS); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, Errors.ERC20_TRANSFER_EXCEEDS_BALANCE); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { _require(account != address(0), Errors.ERC20_MINT_TO_ZERO_ADDRESS); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { _require(account != address(0), Errors.ERC20_BURN_FROM_ZERO_ADDRESS); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, Errors.ERC20_BURN_EXCEEDS_ALLOWANCE); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { _require(owner != address(0), Errors.ERC20_APPROVE_FROM_ZERO_ADDRESS); _require(spender != address(0), Errors.ERC20_APPROVE_TO_ZERO_ADDRESS); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applications that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
// SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. pragma solidity ^0.7.0; // solhint-disable /** * @dev Reverts if `condition` is false, with a revert reason containing `errorCode`. Only codes up to 999 are * supported. */ function _require(bool condition, uint256 errorCode) pure { if (!condition) _revert(errorCode); } /** * @dev Reverts with a revert reason containing `errorCode`. Only codes up to 999 are supported. */ function _revert(uint256 errorCode) pure { // We're going to dynamically create a revert string based on the error code, with the following format: // 'BAL#{errorCode}' // where the code is left-padded with zeroes to three digits (so they range from 000 to 999). // // We don't have revert strings embedded in the contract to save bytecode size: it takes much less space to store a // number (8 to 16 bits) than the individual string characters. // // The dynamic string creation algorithm that follows could be implemented in Solidity, but assembly allows for a // much denser implementation, again saving bytecode size. Given this function unconditionally reverts, this is a // safe place to rely on it without worrying about how its usage might affect e.g. memory contents. assembly { // First, we need to compute the ASCII representation of the error code. We assume that it is in the 0-999 // range, so we only need to convert three digits. To convert the digits to ASCII, we add 0x30, the value for // the '0' character. let units := add(mod(errorCode, 10), 0x30) errorCode := div(errorCode, 10) let tenths := add(mod(errorCode, 10), 0x30) errorCode := div(errorCode, 10) let hundreds := add(mod(errorCode, 10), 0x30) // With the individual characters, we can now construct the full string. The "BAL#" part is a known constant // (0x42414c23): we simply shift this by 24 (to provide space for the 3 bytes of the error code), and add the // characters to it, each shifted by a multiple of 8. // The revert reason is then shifted left by 200 bits (256 minus the length of the string, 7 characters * 8 bits // per character = 56) to locate it in the most significant part of the 256 slot (the beginning of a byte // array). let revertReason := shl(200, add(0x42414c23000000, add(add(units, shl(8, tenths)), shl(16, hundreds)))) // We can now encode the reason in memory, which can be safely overwritten as we're about to revert. The encoded // message will have the following layout: // [ revert reason identifier ] [ string location offset ] [ string length ] [ string contents ] // The Solidity revert reason identifier is 0x08c739a0, the function selector of the Error(string) function. We // also write zeroes to the next 28 bytes of memory, but those are about to be overwritten. mstore(0x0, 0x08c379a000000000000000000000000000000000000000000000000000000000) // Next is the offset to the location of the string, which will be placed immediately after (20 bytes away). mstore(0x04, 0x0000000000000000000000000000000000000000000000000000000000000020) // The string length is fixed: 7 characters. mstore(0x24, 7) // Finally, the string itself is stored. mstore(0x44, revertReason) // Even if the string is only 7 bytes long, we need to return a full 32 byte slot containing it. The length of // the encoded message is therefore 4 + 32 + 32 + 32 = 100. revert(0, 100) } } library Errors { // Math uint256 internal constant ADD_OVERFLOW = 0; uint256 internal constant SUB_OVERFLOW = 1; uint256 internal constant SUB_UNDERFLOW = 2; uint256 internal constant MUL_OVERFLOW = 3; uint256 internal constant ZERO_DIVISION = 4; uint256 internal constant DIV_INTERNAL = 5; uint256 internal constant X_OUT_OF_BOUNDS = 6; uint256 internal constant Y_OUT_OF_BOUNDS = 7; uint256 internal constant PRODUCT_OUT_OF_BOUNDS = 8; uint256 internal constant INVALID_EXPONENT = 9; // Input uint256 internal constant OUT_OF_BOUNDS = 100; uint256 internal constant UNSORTED_ARRAY = 101; uint256 internal constant UNSORTED_TOKENS = 102; uint256 internal constant INPUT_LENGTH_MISMATCH = 103; uint256 internal constant ZERO_TOKEN = 104; // Shared pools uint256 internal constant MIN_TOKENS = 200; uint256 internal constant MAX_TOKENS = 201; uint256 internal constant MAX_SWAP_FEE_PERCENTAGE = 202; uint256 internal constant MIN_SWAP_FEE_PERCENTAGE = 203; uint256 internal constant MINIMUM_BPT = 204; uint256 internal constant CALLER_NOT_VAULT = 205; uint256 internal constant UNINITIALIZED = 206; uint256 internal constant BPT_IN_MAX_AMOUNT = 207; uint256 internal constant BPT_OUT_MIN_AMOUNT = 208; uint256 internal constant EXPIRED_PERMIT = 209; // Pools uint256 internal constant MIN_AMP = 300; uint256 internal constant MAX_AMP = 301; uint256 internal constant MIN_WEIGHT = 302; uint256 internal constant MAX_STABLE_TOKENS = 303; uint256 internal constant MAX_IN_RATIO = 304; uint256 internal constant MAX_OUT_RATIO = 305; uint256 internal constant MIN_BPT_IN_FOR_TOKEN_OUT = 306; uint256 internal constant MAX_OUT_BPT_FOR_TOKEN_IN = 307; uint256 internal constant NORMALIZED_WEIGHT_INVARIANT = 308; uint256 internal constant INVALID_TOKEN = 309; uint256 internal constant UNHANDLED_JOIN_KIND = 310; uint256 internal constant ZERO_INVARIANT = 311; uint256 internal constant ORACLE_INVALID_SECONDS_QUERY = 312; uint256 internal constant ORACLE_NOT_INITIALIZED = 313; uint256 internal constant ORACLE_QUERY_TOO_OLD = 314; uint256 internal constant ORACLE_INVALID_INDEX = 315; uint256 internal constant ORACLE_BAD_SECS = 316; // Lib uint256 internal constant REENTRANCY = 400; uint256 internal constant SENDER_NOT_ALLOWED = 401; uint256 internal constant PAUSED = 402; uint256 internal constant PAUSE_WINDOW_EXPIRED = 403; uint256 internal constant MAX_PAUSE_WINDOW_DURATION = 404; uint256 internal constant MAX_BUFFER_PERIOD_DURATION = 405; uint256 internal constant INSUFFICIENT_BALANCE = 406; uint256 internal constant INSUFFICIENT_ALLOWANCE = 407; uint256 internal constant ERC20_TRANSFER_FROM_ZERO_ADDRESS = 408; uint256 internal constant ERC20_TRANSFER_TO_ZERO_ADDRESS = 409; uint256 internal constant ERC20_MINT_TO_ZERO_ADDRESS = 410; uint256 internal constant ERC20_BURN_FROM_ZERO_ADDRESS = 411; uint256 internal constant ERC20_APPROVE_FROM_ZERO_ADDRESS = 412; uint256 internal constant ERC20_APPROVE_TO_ZERO_ADDRESS = 413; uint256 internal constant ERC20_TRANSFER_EXCEEDS_ALLOWANCE = 414; uint256 internal constant ERC20_DECREASED_ALLOWANCE_BELOW_ZERO = 415; uint256 internal constant ERC20_TRANSFER_EXCEEDS_BALANCE = 416; uint256 internal constant ERC20_BURN_EXCEEDS_ALLOWANCE = 417; uint256 internal constant SAFE_ERC20_CALL_FAILED = 418; uint256 internal constant ADDRESS_INSUFFICIENT_BALANCE = 419; uint256 internal constant ADDRESS_CANNOT_SEND_VALUE = 420; uint256 internal constant SAFE_CAST_VALUE_CANT_FIT_INT256 = 421; uint256 internal constant GRANT_SENDER_NOT_ADMIN = 422; uint256 internal constant REVOKE_SENDER_NOT_ADMIN = 423; uint256 internal constant RENOUNCE_SENDER_NOT_ALLOWED = 424; uint256 internal constant BUFFER_PERIOD_EXPIRED = 425; // Vault uint256 internal constant INVALID_POOL_ID = 500; uint256 internal constant CALLER_NOT_POOL = 501; uint256 internal constant SENDER_NOT_ASSET_MANAGER = 502; uint256 internal constant USER_DOESNT_ALLOW_RELAYER = 503; uint256 internal constant INVALID_SIGNATURE = 504; uint256 internal constant EXIT_BELOW_MIN = 505; uint256 internal constant JOIN_ABOVE_MAX = 506; uint256 internal constant SWAP_LIMIT = 507; uint256 internal constant SWAP_DEADLINE = 508; uint256 internal constant CANNOT_SWAP_SAME_TOKEN = 509; uint256 internal constant UNKNOWN_AMOUNT_IN_FIRST_SWAP = 510; uint256 internal constant MALCONSTRUCTED_MULTIHOP_SWAP = 511; uint256 internal constant INTERNAL_BALANCE_OVERFLOW = 512; uint256 internal constant INSUFFICIENT_INTERNAL_BALANCE = 513; uint256 internal constant INVALID_ETH_INTERNAL_BALANCE = 514; uint256 internal constant INVALID_POST_LOAN_BALANCE = 515; uint256 internal constant INSUFFICIENT_ETH = 516; uint256 internal constant UNALLOCATED_ETH = 517; uint256 internal constant ETH_TRANSFER = 518; uint256 internal constant CANNOT_USE_ETH_SENTINEL = 519; uint256 internal constant TOKENS_MISMATCH = 520; uint256 internal constant TOKEN_NOT_REGISTERED = 521; uint256 internal constant TOKEN_ALREADY_REGISTERED = 522; uint256 internal constant TOKENS_ALREADY_SET = 523; uint256 internal constant TOKENS_LENGTH_MUST_BE_2 = 524; uint256 internal constant NONZERO_TOKEN_BALANCE = 525; uint256 internal constant BALANCE_TOTAL_OVERFLOW = 526; uint256 internal constant POOL_NO_TOKENS = 527; uint256 internal constant INSUFFICIENT_FLASH_LOAN_BALANCE = 528; // Fees uint256 internal constant SWAP_FEE_PERCENTAGE_TOO_HIGH = 600; uint256 internal constant FLASH_LOAN_FEE_PERCENTAGE_TOO_HIGH = 601; uint256 internal constant INSUFFICIENT_FLASH_LOAN_FEE_AMOUNT = 602; }
// SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
// SPDX-License-Identifier: MIT pragma solidity ^0.7.0; import "../helpers/BalancerErrors.sol"; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; _require(c >= a, Errors.ADD_OVERFLOW); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, Errors.SUB_OVERFLOW); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, uint256 errorCode) internal pure returns (uint256) { _require(b <= a, errorCode); uint256 c = a - b; return c; } }
// SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "./IVault.sol"; import "./IPoolSwapStructs.sol"; /** * @dev Interface for adding and removing liquidity that all Pool contracts should implement. Note that this is not * the complete Pool contract interface, as it is missing the swap hooks. Pool contracts should also inherit from * either IGeneralPool or IMinimalSwapInfoPool */ interface IBasePool is IPoolSwapStructs { /** * @dev Called by the Vault when a user calls `IVault.joinPool` to add liquidity to this Pool. Returns how many of * each registered token the user should provide, as well as the amount of protocol fees the Pool owes to the Vault. * The Vault will then take tokens from `sender` and add them to the Pool's balances, as well as collect * the reported amount in protocol fees, which the pool should calculate based on `protocolSwapFeePercentage`. * * Protocol fees are reported and charged on join events so that the Pool is free of debt whenever new users join. * * `sender` is the account performing the join (from which tokens will be withdrawn), and `recipient` is the account * designated to receive any benefits (typically pool shares). `currentBalances` contains the total balances * for each token the Pool registered in the Vault, in the same order that `IVault.getPoolTokens` would return. * * `lastChangeBlock` is the last block in which *any* of the Pool's registered tokens last changed its total * balance. * * `userData` contains any pool-specific instructions needed to perform the calculations, such as the type of * join (e.g., proportional given an amount of pool shares, single-asset, multi-asset, etc.) * * Contracts implementing this function should check that the caller is indeed the Vault before performing any * state-changing operations, such as minting pool shares. */ function onJoinPool( bytes32 poolId, address sender, address recipient, uint256[] memory balances, uint256 lastChangeBlock, uint256 protocolSwapFeePercentage, bytes memory userData ) external returns (uint256[] memory amountsIn, uint256[] memory dueProtocolFeeAmounts); /** * @dev Called by the Vault when a user calls `IVault.exitPool` to remove liquidity from this Pool. Returns how many * tokens the Vault should deduct from the Pool's balances, as well as the amount of protocol fees the Pool owes * to the Vault. The Vault will then take tokens from the Pool's balances and send them to `recipient`, * as well as collect the reported amount in protocol fees, which the Pool should calculate based on * `protocolSwapFeePercentage`. * * Protocol fees are charged on exit events to guarantee that users exiting the Pool have paid their share. * * `sender` is the account performing the exit (typically the pool shareholder), and `recipient` is the account * to which the Vault will send the proceeds. `currentBalances` contains the total token balances for each token * the Pool registered in the Vault, in the same order that `IVault.getPoolTokens` would return. * * `lastChangeBlock` is the last block in which *any* of the Pool's registered tokens last changed its total * balance. * * `userData` contains any pool-specific instructions needed to perform the calculations, such as the type of * exit (e.g., proportional given an amount of pool shares, single-asset, multi-asset, etc.) * * Contracts implementing this function should check that the caller is indeed the Vault before performing any * state-changing operations, such as burning pool shares. */ function onExitPool( bytes32 poolId, address sender, address recipient, uint256[] memory balances, uint256 lastChangeBlock, uint256 protocolSwapFeePercentage, bytes memory userData ) external returns (uint256[] memory amountsOut, uint256[] memory dueProtocolFeeAmounts); }
// SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "../../lib/openzeppelin/IERC20.sol"; import "./IVault.sol"; interface IPoolSwapStructs { // This is not really an interface - it just defines common structs used by other interfaces: IGeneralPool and // IMinimalSwapInfoPool. // // This data structure represents a request for a token swap, where `kind` indicates the swap type ('given in' or // 'given out') which indicates whether or not the amount sent by the pool is known. // // The pool receives `tokenIn` and sends `tokenOut`. `amount` is the number of `tokenIn` tokens the pool will take // in, or the number of `tokenOut` tokens the Pool will send out, depending on the given swap `kind`. // // All other fields are not strictly necessary for most swaps, but are provided to support advanced scenarios in // some Pools. // // `poolId` is the ID of the Pool involved in the swap - this is useful for Pool contracts that implement more than // one Pool. // // The meaning of `lastChangeBlock` depends on the Pool specialization: // - Two Token or Minimal Swap Info: the last block in which either `tokenIn` or `tokenOut` changed its total // balance. // - General: the last block in which *any* of the Pool's registered tokens changed its total balance. // // `from` is the origin address for the funds the Pool receives, and `to` is the destination address // where the Pool sends the outgoing tokens. // // `userData` is extra data provided by the caller - typically a signature from a trusted party. struct SwapRequest { IVault.SwapKind kind; IERC20 tokenIn; IERC20 tokenOut; uint256 amount; // Misc data bytes32 poolId; uint256 lastChangeBlock; address from; address to; bytes userData; } }
// SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. pragma solidity ^0.7.0; import "../../lib/openzeppelin/IERC20.sol"; /** * @dev Interface for the WETH token contract used internally for wrapping and unwrapping, to support * sending and receiving ETH in joins, swaps, and internal balance deposits and withdrawals. */ interface IWETH is IERC20 { function deposit() external payable; function withdraw(uint256 amount) external; }
// SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. pragma solidity ^0.7.0; /** * @dev This is an empty interface used to represent either ERC20-conforming token contracts or ETH (using the zero * address sentinel value). We're just relying on the fact that `interface` can be used to declare new address-like * types. * * This concept is unrelated to a Pool's Asset Managers. */ interface IAsset { // solhint-disable-previous-line no-empty-blocks }
// SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. pragma solidity ^0.7.0; interface IAuthorizer { /** * @dev Returns true if `account` can perform the action described by `actionId` in the contract `where`. */ function canPerform( bytes32 actionId, address account, address where ) external view returns (bool); }
// SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. pragma solidity ^0.7.0; // Inspired by Aave Protocol's IFlashLoanReceiver. import "../../lib/openzeppelin/IERC20.sol"; interface IFlashLoanRecipient { /** * @dev When `flashLoan` is called on the Vault, it invokes the `receiveFlashLoan` hook on the recipient. * * At the time of the call, the Vault will have transferred `amounts` for `tokens` to the recipient. Before this * call returns, the recipient must have transferred `amounts` plus `feeAmounts` for each token back to the * Vault, or else the entire flash loan will revert. * * `userData` is the same value passed in the `IVault.flashLoan` call. */ function receiveFlashLoan( IERC20[] memory tokens, uint256[] memory amounts, uint256[] memory feeAmounts, bytes memory userData ) external; }
// SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "../lib/openzeppelin/IERC20.sol"; import "../lib/helpers/InputHelpers.sol"; import "../lib/helpers/Authentication.sol"; import "../lib/openzeppelin/ReentrancyGuard.sol"; import "../lib/openzeppelin/SafeERC20.sol"; import "./interfaces/IVault.sol"; import "./interfaces/IAuthorizer.sol"; /** * @dev This an auxiliary contract to the Vault, deployed by it during construction. It offloads some of the tasks the * Vault performs to reduce its overall bytecode size. * * The current values for all protocol fee percentages are stored here, and any tokens charged as protocol fees are * sent to this contract, where they may be withdrawn by authorized entities. All authorization tasks are delegated * to the Vault's own authorizer. */ contract ProtocolFeesCollector is Authentication, ReentrancyGuard { using SafeERC20 for IERC20; // Absolute maximum fee percentages (1e18 = 100%, 1e16 = 1%). uint256 private constant _MAX_PROTOCOL_SWAP_FEE_PERCENTAGE = 50e16; // 50% uint256 private constant _MAX_PROTOCOL_FLASH_LOAN_FEE_PERCENTAGE = 1e16; // 1% IVault public immutable vault; // All fee percentages are 18-decimal fixed point numbers. // The swap fee is charged whenever a swap occurs, as a percentage of the fee charged by the Pool. These are not // actually charged on each individual swap: the `Vault` relies on the Pools being honest and reporting fees due // when users join and exit them. uint256 private _swapFeePercentage; // The flash loan fee is charged whenever a flash loan occurs, as a percentage of the tokens lent. uint256 private _flashLoanFeePercentage; event SwapFeePercentageChanged(uint256 newSwapFeePercentage); event FlashLoanFeePercentageChanged(uint256 newFlashLoanFeePercentage); constructor(IVault _vault) // The ProtocolFeesCollector is a singleton, so it simply uses its own address to disambiguate action // identifiers. Authentication(bytes32(uint256(address(this)))) { vault = _vault; } function withdrawCollectedFees( IERC20[] calldata tokens, uint256[] calldata amounts, address recipient ) external nonReentrant authenticate { InputHelpers.ensureInputLengthMatch(tokens.length, amounts.length); for (uint256 i = 0; i < tokens.length; ++i) { IERC20 token = tokens[i]; uint256 amount = amounts[i]; token.safeTransfer(recipient, amount); } } function setSwapFeePercentage(uint256 newSwapFeePercentage) external authenticate { _require(newSwapFeePercentage <= _MAX_PROTOCOL_SWAP_FEE_PERCENTAGE, Errors.SWAP_FEE_PERCENTAGE_TOO_HIGH); _swapFeePercentage = newSwapFeePercentage; emit SwapFeePercentageChanged(newSwapFeePercentage); } function setFlashLoanFeePercentage(uint256 newFlashLoanFeePercentage) external authenticate { _require( newFlashLoanFeePercentage <= _MAX_PROTOCOL_FLASH_LOAN_FEE_PERCENTAGE, Errors.FLASH_LOAN_FEE_PERCENTAGE_TOO_HIGH ); _flashLoanFeePercentage = newFlashLoanFeePercentage; emit FlashLoanFeePercentageChanged(newFlashLoanFeePercentage); } function getSwapFeePercentage() external view returns (uint256) { return _swapFeePercentage; } function getFlashLoanFeePercentage() external view returns (uint256) { return _flashLoanFeePercentage; } function getCollectedFeeAmounts(IERC20[] memory tokens) external view returns (uint256[] memory feeAmounts) { feeAmounts = new uint256[](tokens.length); for (uint256 i = 0; i < tokens.length; ++i) { feeAmounts[i] = tokens[i].balanceOf(address(this)); } } function getAuthorizer() external view returns (IAuthorizer) { return _getAuthorizer(); } function _canPerform(bytes32 actionId, address account) internal view override returns (bool) { return _getAuthorizer().canPerform(actionId, account, address(this)); } function _getAuthorizer() internal view returns (IAuthorizer) { return vault.getAuthorizer(); } }
// SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. pragma solidity ^0.7.0; /** * @dev Interface for the SignatureValidator helper, used to support meta-transactions. */ interface ISignaturesValidator { /** * @dev Returns the EIP712 domain separator. */ function getDomainSeparator() external view returns (bytes32); /** * @dev Returns the next nonce used by an address to sign messages. */ function getNextNonce(address user) external view returns (uint256); }
// SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. pragma solidity ^0.7.0; /** * @dev Interface for the TemporarilyPausable helper. */ interface ITemporarilyPausable { /** * @dev Emitted every time the pause state changes by `_setPaused`. */ event PausedStateChanged(bool paused); /** * @dev Returns the current paused state. */ function getPausedState() external view returns ( bool paused, uint256 pauseWindowEndTime, uint256 bufferPeriodEndTime ); }
// SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. pragma solidity ^0.7.0; import "../openzeppelin/IERC20.sol"; import "./BalancerErrors.sol"; import "../../vault/interfaces/IAsset.sol"; library InputHelpers { function ensureInputLengthMatch(uint256 a, uint256 b) internal pure { _require(a == b, Errors.INPUT_LENGTH_MISMATCH); } function ensureInputLengthMatch( uint256 a, uint256 b, uint256 c ) internal pure { _require(a == b && b == c, Errors.INPUT_LENGTH_MISMATCH); } function ensureArrayIsSorted(IAsset[] memory array) internal pure { address[] memory addressArray; // solhint-disable-next-line no-inline-assembly assembly { addressArray := array } ensureArrayIsSorted(addressArray); } function ensureArrayIsSorted(IERC20[] memory array) internal pure { address[] memory addressArray; // solhint-disable-next-line no-inline-assembly assembly { addressArray := array } ensureArrayIsSorted(addressArray); } function ensureArrayIsSorted(address[] memory array) internal pure { if (array.length < 2) { return; } address previous = array[0]; for (uint256 i = 1; i < array.length; ++i) { address current = array[i]; _require(previous < current, Errors.UNSORTED_ARRAY); previous = current; } } }
// SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. pragma solidity ^0.7.0; import "./BalancerErrors.sol"; import "./IAuthentication.sol"; /** * @dev Building block for performing access control on external functions. * * This contract is used via the `authenticate` modifier (or the `_authenticateCaller` function), which can be applied * to external functions to only make them callable by authorized accounts. * * Derived contracts must implement the `_canPerform` function, which holds the actual access control logic. */ abstract contract Authentication is IAuthentication { bytes32 private immutable _actionIdDisambiguator; /** * @dev The main purpose of the `actionIdDisambiguator` is to prevent accidental function selector collisions in * multi contract systems. * * There are two main uses for it: * - if the contract is a singleton, any unique identifier can be used to make the associated action identifiers * unique. The contract's own address is a good option. * - if the contract belongs to a family that shares action identifiers for the same functions, an identifier * shared by the entire family (and no other contract) should be used instead. */ constructor(bytes32 actionIdDisambiguator) { _actionIdDisambiguator = actionIdDisambiguator; } /** * @dev Reverts unless the caller is allowed to call this function. Should only be applied to external functions. */ modifier authenticate() { _authenticateCaller(); _; } /** * @dev Reverts unless the caller is allowed to call the entry point function. */ function _authenticateCaller() internal view { bytes32 actionId = getActionId(msg.sig); _require(_canPerform(actionId, msg.sender), Errors.SENDER_NOT_ALLOWED); } function getActionId(bytes4 selector) public view override returns (bytes32) { // Each external function is dynamically assigned an action identifier as the hash of the disambiguator and the // function selector. Disambiguation is necessary to avoid potential collisions in the function selectors of // multiple contracts. return keccak256(abi.encodePacked(_actionIdDisambiguator, selector)); } function _canPerform(bytes32 actionId, address user) internal view virtual returns (bool); }
// SPDX-License-Identifier: MIT // Based on the ReentrancyGuard library from OpenZeppelin Contracts, altered to reduce bytecode size. // Modifier code is inlined by the compiler, which causes its code to appear multiple times in the codebase. By using // private functions, we achieve the same end result with slightly higher runtime gas costs, but reduced bytecode size. pragma solidity ^0.7.0; import "../helpers/BalancerErrors.sol"; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor() { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and make it call a * `private` function that does the actual work. */ modifier nonReentrant() { _enterNonReentrant(); _; _exitNonReentrant(); } function _enterNonReentrant() private { // On the first call to nonReentrant, _status will be _NOT_ENTERED _require(_status != _ENTERED, Errors.REENTRANCY); // Any calls to nonReentrant after this point will fail _status = _ENTERED; } function _exitNonReentrant() private { // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } }
// SPDX-License-Identifier: MIT // Based on the ReentrancyGuard library from OpenZeppelin Contracts, altered to reduce gas costs. // The `safeTransfer` and `safeTransferFrom` functions assume that `token` is a contract (an account with code), and // work differently from the OpenZeppelin version if it is not. pragma solidity ^0.7.0; import "../helpers/BalancerErrors.sol"; import "./IERC20.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(address(token), abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(address(token), abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * * WARNING: `token` is assumed to be a contract: calls to EOAs will *not* revert. */ function _callOptionalReturn(address token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. (bool success, bytes memory returndata) = token.call(data); // If the low-level call didn't succeed we return whatever was returned from it. assembly { if eq(success, 0) { returndatacopy(0, 0, returndatasize()) revert(0, returndatasize()) } } // Finally we check the returndata size is either zero or true - note that this check will always pass for EOAs _require(returndata.length == 0 || abi.decode(returndata, (bool)), Errors.SAFE_ERC20_CALL_FAILED); } }
// SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. pragma solidity ^0.7.0; interface IAuthentication { /** * @dev Returns the action identifier associated with the external function described by `selector`. */ function getActionId(bytes4 selector) external view returns (bytes32); }
// SPDX-License-Identifier: MIT pragma solidity ^0.7.0; import "../helpers/BalancerErrors.sol"; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow checks. * Adapted from OpenZeppelin's SafeMath library */ library Math { /** * @dev Returns the addition of two unsigned integers of 256 bits, reverting on overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; _require(c >= a, Errors.ADD_OVERFLOW); return c; } /** * @dev Returns the addition of two signed integers, reverting on overflow. */ function add(int256 a, int256 b) internal pure returns (int256) { int256 c = a + b; _require((b >= 0 && c >= a) || (b < 0 && c < a), Errors.ADD_OVERFLOW); return c; } /** * @dev Returns the subtraction of two unsigned integers of 256 bits, reverting on overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { _require(b <= a, Errors.SUB_OVERFLOW); uint256 c = a - b; return c; } /** * @dev Returns the subtraction of two signed integers, reverting on overflow. */ function sub(int256 a, int256 b) internal pure returns (int256) { int256 c = a - b; _require((b >= 0 && c <= a) || (b < 0 && c > a), Errors.SUB_OVERFLOW); return c; } /** * @dev Returns the largest of two numbers of 256 bits. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a >= b ? a : b; } /** * @dev Returns the smallest of two numbers of 256 bits. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } function mul(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a * b; _require(a == 0 || c / a == b, Errors.MUL_OVERFLOW); return c; } function divDown(uint256 a, uint256 b) internal pure returns (uint256) { _require(b != 0, Errors.ZERO_DIVISION); return a / b; } function divUp(uint256 a, uint256 b) internal pure returns (uint256) { _require(b != 0, Errors.ZERO_DIVISION); if (a == 0) { return 0; } else { return 1 + (a - 1) / b; } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over `owner`'s tokens, * given `owner`'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for `permit`, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data. * * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible, * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding * they need in their contracts using a combination of `abi.encode` and `keccak256`. * * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA * ({_hashTypedDataV4}). * * The implementation of the domain separator was designed to be as efficient as possible while still properly updating * the chain id to protect against replay attacks on an eventual fork of the chain. * * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask]. * * _Available since v3.4._ */ abstract contract EIP712 { /* solhint-disable var-name-mixedcase */ bytes32 private immutable _HASHED_NAME; bytes32 private immutable _HASHED_VERSION; bytes32 private immutable _TYPE_HASH; /* solhint-enable var-name-mixedcase */ /** * @dev Initializes the domain separator and parameter caches. * * The meaning of `name` and `version` is specified in * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]: * * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol. * - `version`: the current major version of the signing domain. * * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart * contract upgrade]. */ constructor(string memory name, string memory version) { _HASHED_NAME = keccak256(bytes(name)); _HASHED_VERSION = keccak256(bytes(version)); _TYPE_HASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"); } /** * @dev Returns the domain separator for the current chain. */ function _domainSeparatorV4() internal view virtual returns (bytes32) { return keccak256(abi.encode(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION, _getChainId(), address(this))); } /** * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this * function returns the hash of the fully encoded EIP712 message for this domain. * * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example: * * ```solidity * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode( * keccak256("Mail(address to,string contents)"), * mailTo, * keccak256(bytes(mailContents)) * ))); * address signer = ECDSA.recover(digest, signature); * ``` */ function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) { return keccak256(abi.encodePacked("\x19\x01", _domainSeparatorV4(), structHash)); } function _getChainId() private view returns (uint256 chainId) { // Silence state mutability warning without generating bytecode. // See https://github.com/ethereum/solidity/issues/10090#issuecomment-741789128 and // https://github.com/ethereum/solidity/issues/2691 this; // solhint-disable-next-line no-inline-assembly assembly { chainId := chainid() } } }
{ "optimizer": { "enabled": true, "runs": 10000 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "abi" ] } }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"contract IERC20","name":"_underlying","type":"address"},{"internalType":"contract IERC20","name":"_bond","type":"address"},{"internalType":"uint256","name":"_expiration","type":"uint256"},{"internalType":"uint256","name":"_unitSeconds","type":"uint256"},{"internalType":"contract IVault","name":"vault","type":"address"},{"internalType":"uint256","name":"_percentFee","type":"uint256"},{"internalType":"uint256","name":"_percentFeeGov","type":"uint256"},{"internalType":"address","name":"_governance","type":"address"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"collectedBase","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"collectedBond","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"remainingBase","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"remainingBond","type":"uint256"}],"name":"FeeCollection","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"FEE_BOUND","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"bond","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"bondDecimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"decreaseApproval","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"expiration","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feesBond","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feesUnderlying","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPoolId","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getVault","outputs":[{"internalType":"contract IVault","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"governance","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"increaseApproval","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"poolId","type":"bytes32"},{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256[]","name":"currentBalances","type":"uint256[]"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"protocolSwapFee","type":"uint256"},{"internalType":"bytes","name":"userData","type":"bytes"}],"name":"onExitPool","outputs":[{"internalType":"uint256[]","name":"amountsOut","type":"uint256[]"},{"internalType":"uint256[]","name":"dueProtocolFeeAmounts","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"poolId","type":"bytes32"},{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256[]","name":"currentBalances","type":"uint256[]"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"protocolSwapFee","type":"uint256"},{"internalType":"bytes","name":"userData","type":"bytes"}],"name":"onJoinPool","outputs":[{"internalType":"uint256[]","name":"amountsIn","type":"uint256[]"},{"internalType":"uint256[]","name":"dueProtocolFeeAmounts","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"enum IVault.SwapKind","name":"kind","type":"uint8"},{"internalType":"contract IERC20","name":"tokenIn","type":"address"},{"internalType":"contract IERC20","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes32","name":"poolId","type":"bytes32"},{"internalType":"uint256","name":"lastChangeBlock","type":"uint256"},{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"bytes","name":"userData","type":"bytes"}],"internalType":"struct IPoolSwapStructs.SwapRequest","name":"swapRequest","type":"tuple"},{"internalType":"uint256","name":"currentBalanceTokenIn","type":"uint256"},{"internalType":"uint256","name":"currentBalanceTokenOut","type":"uint256"}],"name":"onSwap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"percentFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"percentFeeGov","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountX","type":"uint256"},{"internalType":"uint256","name":"reserveX","type":"uint256"},{"internalType":"uint256","name":"reserveY","type":"uint256"},{"internalType":"bool","name":"out","type":"bool"}],"name":"solveTradeInvariant","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"underlying","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"underlyingDecimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unitSeconds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
6102a06040527f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c960e0523480156200003657600080fd5b506040516200430238038062004302833981016040819052620000599162000679565b6040805180820190915260018152603160f81b602080830191825284519085019081206080529151902060a0527f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60c052825183918391620000be91600391620004ff565b508051620000d4906004906020840190620004ff565b5050508642890310620000e657600080fd5b6040516309b2760f60e01b81526000906001600160a01b038816906309b2760f9062000118906002906004016200081e565b602060405180830381600087803b1580156200013357600080fd5b505af115801562000148573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200016e919062000660565b6040805160028082526060808301845293945090916020830190803683370190505090508a6001600160a01b03168c6001600160a01b0316101562000211578b81600081518110620001bc57fe5b60200260200101906001600160a01b031690816001600160a01b0316815250508a81600181518110620001eb57fe5b60200260200101906001600160a01b031690816001600160a01b03168152505062000270565b8a816000815181106200022057fe5b60200260200101906001600160a01b031690816001600160a01b0316815250508b816001815181106200024f57fe5b60200260200101906001600160a01b031690816001600160a01b0316815250505b6040805160028082526060820183526001600160a01b038b16926366a9c7d29286928692602083019080368337019050506040518463ffffffff1660e01b8152600401620002c19392919062000782565b600060405180830381600087803b158015620002dc57600080fd5b505af1158015620002f1573d6000803e3d6000fd5b5050506001600160601b031960608a901b166101c052506101e0829052610220879052670429d069189e00008610620003475760405162461bcd60e51b81526004016200033e9062000833565b60405180910390fd5b6102408690526001600160601b031960608d901b16610100526040805163313ce56760e01b815290516001600160a01b038e169163313ce567916004808301926020929190829003018186803b158015620003a157600080fd5b505afa158015620003b6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620003dc919062000758565b60f81b6001600160f81b0319166101205260608b901b6001600160601b031916610140526040805163313ce56760e01b815290516001600160a01b038d169163313ce567916004808301926020929190829003018186803b1580156200044157600080fd5b505afa15801562000456573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200047c919062000758565b60f81b6001600160f81b031916610160526101808a90526101a0899052606085901b6001600160601b031916610200526001600160a01b038b8116908d161080620004c9576001620004cc565b60005b60ff166102605280620004e1576000620004e4565b60015b60ff166102805250620008659b505050505050505050505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200054257805160ff191683800117855562000572565b8280016001018555821562000572579182015b828111156200057257825182559160200191906001019062000555565b506200058092915062000584565b5090565b5b8082111562000580576000815560010162000585565b80516001600160a01b0381168114620005b357600080fd5b92915050565b600082601f830112620005ca578081fd5b81516001600160401b0380821115620005e1578283fd5b6040516020601f8401601f191682018101838111838210171562000603578586fd5b806040525081945083825286818588010111156200062057600080fd5b600092505b8383101562000644578583018101518284018201529182019162000625565b83831115620006565760008185840101525b5050505092915050565b60006020828403121562000672578081fd5b5051919050565b6000806000806000806000806000806101408b8d03121562000699578586fd5b620006a58c8c6200059b565b9950620006b68c60208d016200059b565b985060408b0151975060608b01519650620006d58c60808d016200059b565b955060a08b0151945060c08b01519350620006f48c60e08d016200059b565b6101008c01519093506001600160401b038082111562000712578384fd5b620007208e838f01620005b9565b93506101208d015191508082111562000737578283fd5b50620007468d828e01620005b9565b9150509295989b9194979a5092959850565b6000602082840312156200076a578081fd5b815160ff811681146200077b578182fd5b9392505050565b60006060820185835260206060818501528186518084526080860191508288019350845b81811015620007ce57620007bb855162000859565b83529383019391830191600101620007a6565b505084810360408601528551808252908201925081860190845b818110156200081057620007fd835162000859565b85529383019391830191600101620007e8565b509298975050505050505050565b60208101600383106200082d57fe5b91905290565b6020808252600c908201526b08ccaca40e8dede40d0d2ced60a31b604082015260600190565b6001600160a01b031690565b60805160a05160c05160e0516101005160601c6101205160f81c6101405160601c6101605160f81c610180516101a0516101c05160601c6101e0516102005160601c6102205161024051610260516102805161389362000a6f600039806108c9528061093a5280610f7c5280610fed52806113ab5280611407528061160252806116cd528061189352806119305280611a1052806122a1528061236352806123f7528061254552508061088852806109065280610f3b5280610fb95280611314528061137052806115985280611659528061185252806118f7528061197952806119d55280612267528061232252806123be52806125115250806105c7528061147352806114eb5280611519528061157652806115e0528061163452806116a852508061060f5280611f5d52508061063352806115495250806105a352806107865280610e395250806107245280610a625280610b105280610de05250806110885280611ad45250806105eb5280611a6e5280611a9d5250806110ac52806113de5280611a455280611d5e52806121bb5250806106575280611d205280611df75280611e465280611f14528061202b528061217b52508061055f528061134752806119ae5280611cf152806121555250806106d55280611cb35280611dbb5280611e825280612115525080610ca052508061125f5250806112a152508061128052506138936000f3fe608060405234801561001057600080fd5b50600436106101f05760003560e01c806370a082311161010f578063d505accf116100a2578063eaee3f3b11610071578063eaee3f3b146103be578063f1cd96ba146103c6578063f46c39e7146103ce578063f7b94283146103e3576101f0565b8063d505accf14610370578063d5c096c414610385578063d73dd62314610398578063dd62ed3e146103ab576101f0565b80638d928af8116100de5780638d928af81461033a57806395d89b41146103425780639d2c110c1461034a578063a9059cbb1461035d576101f0565b806370a08231146102e057806374f3b009146102f357806379155050146103145780637ecebe0014610327576101f0565b806338fff2d0116101875780635aa6e675116101565780635aa6e675146102a857806364c9ec6f146102bd57806366188463146102c55780636f307dc3146102d8576101f0565b806338fff2d01461028857806341bd436a146102905780634665096d146102985780634c1a4115146102a0576101f0565b806325a760c2116101c357806325a760c21461025b57806329e4f36214610270578063313ce567146102785780633644e51514610280576101f0565b806306fdde03146101f5578063095ea7b31461021357806318160ddd1461023357806323b872dd14610248575b600080fd5b6101fd6103eb565b60405161020a919061362e565b60405180910390f35b610226610221366004613279565b61049f565b60405161020a919061359c565b61023b6104b6565b60405161020a91906135a7565b6102266102563660046131c4565b6104bc565b61026361055d565b60405161020a9190613810565b61023b610581565b61026361058d565b61023b610592565b61023b6105a1565b61023b6105c5565b61023b6105e9565b61023b61060d565b6102b0610631565b60405161020a919061355a565b6102b0610655565b6102266102d3366004613279565b610679565b6102b06106d3565b61023b6102ee366004613170565b6106f7565b6103066103013660046132d7565b610716565b60405161020a92919061356e565b61023b6103223660046134a6565b610994565b61023b610335366004613170565b610a45565b6102b0610a60565b6101fd610a84565b61023b6103583660046133aa565b610b03565b61022661036b366004613279565b610c5e565b61038361037e366004613204565b610c6b565b005b6103066103933660046132d7565b610dd2565b6102266103a6366004613279565b611025565b61023b6103b936600461318c565b61105b565b61023b611086565b6102636110aa565b6103d66110ce565b60405161020a91906137d8565b6103d66110fa565b60038054604080516020601f60027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104955780601f1061046a57610100808354040283529160200191610495565b820191906000526020600020905b81548152906001019060200180831161047857829003601f168201915b5050505050905090565b60006104ac338484611112565b5060015b92915050565b60025490565b6001600160a01b038316600081815260016020908152604080832033808552925282205491926104fa9114806104f25750838210155b61019761117a565b61050585858561118c565b336001600160a01b0386161480159061053e57507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8114155b15610550576105508533858403611112565b60019150505b9392505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b670429d069189e000081565b601290565b600061059c61125b565b905090565b7f000000000000000000000000000000000000000000000000000000000000000090565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b3360009081526001602090815260408083206001600160a01b03861684529091528120548083106106b5576106b033856000611112565b6106c9565b6106c933856106c484876112f8565b611112565b5060019392505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b6001600160a01b0381166000908152602081905260409020545b919050565b606080336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614610784576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161077b9061369f565b60405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000008a146107dd576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161077b9061376a565b60606107eb848601866132a4565b9050875160021480156107ff575080516002145b610835576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161077b90613733565b61083e8861130e565b6108478161130e565b6000806108538a61143f565b6040805160028082526060820190925292945090925081602001602082028036833701905050935061088582896117a1565b847f0000000000000000000000000000000000000000000000000000000000000000815181106108b157fe5b60209081029190910101526108c681896117a1565b847f0000000000000000000000000000000000000000000000000000000000000000815181106108f257fe5b6020026020010181815250505050610972817f00000000000000000000000000000000000000000000000000000000000000008151811061092f57fe5b6020026020010151827f00000000000000000000000000000000000000000000000000000000000000008151811061096357fe5b60200260200101518a8c6117d7565b925061097d83611973565b61098682611973565b509850989650505050505050565b60008061099f611a69565b905060006109ad8683611b21565b905060006109bb8684611b21565b90506000856109dc576109d76109d1898b6112f8565b85611b21565b6109e8565b6109e889890185611b21565b905060006109f8848401836112f8565b9050610a1581610a10670de0b6b3a764000088611c5e565b611b21565b905086610a2b57610a2681896112f8565b610a35565b610a3588826112f8565b955050505050505b949350505050565b6001600160a01b031660009081526005602052604090205490565b7f000000000000000000000000000000000000000000000000000000000000000090565b60048054604080516020601f60027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104955780601f1061046a57610100808354040283529160200191610495565b6000336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614610b67576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161077b9061369f565b6000808086516001811115610b7857fe5b1490508015610b9a57610b9386606001518760200151611caf565b9150610baf565b610bac86606001518760400151611caf565b91505b610bbd858760200151611caf565b9450610bcd848760400151611caf565b9350600080610be6878960200151888b60400151611db6565b915091508215610c2d576000610bfe85848487610994565b9050610c1185828b604001516000611f0a565b9050610c21818a60400151612111565b95505050505050610556565b6000610c3b85838587610994565b9050610c4e81868b604001516001611f0a565b9050610c21818a60200151612111565b60006104ac33848461118c565b610c798442111560d161117a565b6001600160a01b0387166000908152600560209081526040808320549051909291610cd0917f0000000000000000000000000000000000000000000000000000000000000000918c918c918c9188918d91016135b0565b6040516020818303038152906040528051906020012090506000610cf3826121df565b9050600060018288888860405160008152602001604052604051610d1a9493929190613610565b6020604051602081039080840390855afa158015610d3c573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe001519150610d9c90506001600160a01b03821615801590610d9457508b6001600160a01b0316826001600160a01b0316145b6101f861117a565b6001600160a01b038b166000908152600560205260409020600185019055610dc58b8b8b611112565b5050505050505050505050565b606080336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614610e37576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161077b9061369f565b7f00000000000000000000000000000000000000000000000000000000000000008a14610e90576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161077b9061376a565b6060610e9e848601866132a4565b905087516002148015610eb2575080516002145b610ee8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161077b90613733565b610ef18861130e565b610efa8161130e565b600080610f068a61143f565b60408051600280825260608201909252929450909250816020016020820280368337019050509350610f3882896117a1565b847f000000000000000000000000000000000000000000000000000000000000000081518110610f6457fe5b6020908102919091010152610f7981896117a1565b847f000000000000000000000000000000000000000000000000000000000000000081518110610fa557fe5b6020026020010181815250505050610972817f000000000000000000000000000000000000000000000000000000000000000081518110610fe257fe5b6020026020010151827f00000000000000000000000000000000000000000000000000000000000000008151811061101657fe5b60200260200101518a8c612218565b3360008181526001602090815260408083206001600160a01b038716845290915281205490916104ac9185906106c4908661243b565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b60065470010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff1681565b6006546fffffffffffffffffffffffffffffffff1681565b6001600160a01b0380841660008181526001602090815260408083209487168084529490915290819020849055517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259061116d9085906135a7565b60405180910390a3505050565b81611188576111888161244d565b5050565b6001600160a01b0383166000908152602081905260409020546111b48282101561019661117a565b6111cb6001600160a01b038416151561019961117a565b6001600160a01b038085166000908152602081905260408082208585039055918516815220546111fb908361243b565b6001600160a01b0380851660008181526020819052604090819020939093559151908616907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9061124d9086906135a7565b60405180910390a350505050565b60007f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000006112c86124ba565b306040516020016112dd9594939291906135e4565b60405160208183030381529060405280519060200120905090565b600061130883831115600161117a565b50900390565b61136d817f00000000000000000000000000000000000000000000000000000000000000008151811061133d57fe5b60200260200101517f000000000000000000000000000000000000000000000000000000000000000060126124be565b817f00000000000000000000000000000000000000000000000000000000000000008151811061139957fe5b602002602001018181525050611404817f0000000000000000000000000000000000000000000000000000000000000000815181106113d457fe5b60200260200101517f000000000000000000000000000000000000000000000000000000000000000060126124be565b817f00000000000000000000000000000000000000000000000000000000000000008151811061143057fe5b60200260200101818152505050565b60065460009081906fffffffffffffffffffffffffffffffff808216917001000000000000000000000000000000009004167f00000000000000000000000000000000000000000000000000000000000000006114e357600060068190556040517f9f878c349b0fc751f12168fdf539db8c1848b81c0751432f28626da5aa7024ee916114d1918591859181906137f5565b60405180910390a1909250905061179c565b600061150f837f00000000000000000000000000000000000000000000000000000000000000006117a1565b9050600061153d837f00000000000000000000000000000000000000000000000000000000000000006117a1565b9050606061156d83838a7f0000000000000000000000000000000000000000000000000000000000000000612218565b905060006115d77f0000000000000000000000000000000000000000000000000000000000000000837f0000000000000000000000000000000000000000000000000000000000000000815181106115c157fe5b6020026020010151611c5e90919063ffffffff16565b9050600061162b7f0000000000000000000000000000000000000000000000000000000000000000847f0000000000000000000000000000000000000000000000000000000000000000815181106115c157fe5b9050600061169f7f0000000000000000000000000000000000000000000000000000000000000000611699867f00000000000000000000000000000000000000000000000000000000000000008151811061168257fe5b6020026020010151896112f890919063ffffffff16565b90611c5e565b905060006116f67f0000000000000000000000000000000000000000000000000000000000000000611699877f00000000000000000000000000000000000000000000000000000000000000008151811061168257fe5b90507f9f878c349b0fc751f12168fdf539db8c1848b81c0751432f28626da5aa7024ee8484848460405161172d94939291906137f5565b60405180910390a1600680546fffffffffffffffffffffffffffffffff928316700100000000000000000000000000000000029383167fffffffffffffffffffffffffffffffff0000000000000000000000000000000090911617909116919091179055909750955050505050505b915091565b60008282026117c58415806117be5750838583816117bb57fe5b04145b600361117a565b670de0b6b3a764000090049392505050565b60408051600280825260608083018452926020830190803683370190505090506000806118038561250b565b9150915060006118116104b6565b9050600061181f8484611c5e565b905061182b88826117a1565b8911156118ce576000611842856116998c866117a1565b905061184e878261257f565b89867f00000000000000000000000000000000000000000000000000000000000000008151811061187b57fe5b60209081029190910101526118908a83611c5e565b867f0000000000000000000000000000000000000000000000000000000000000000815181106118bc57fe5b60200260200101818152505050611967565b60006118de846116998b866117a1565b90506118ea878261257f565b6118f489836117a1565b867f00000000000000000000000000000000000000000000000000000000000000008151811061192057fe5b60200260200101818152505088867f00000000000000000000000000000000000000000000000000000000000000008151811061195957fe5b602002602001018181525050505b50505050949350505050565b6119d2817f0000000000000000000000000000000000000000000000000000000000000000815181106119a257fe5b602002602001015160127f00000000000000000000000000000000000000000000000000000000000000006124be565b817f0000000000000000000000000000000000000000000000000000000000000000815181106119fe57fe5b602002602001018181525050611404817f000000000000000000000000000000000000000000000000000000000000000081518110611a3957fe5b602002602001015160127f00000000000000000000000000000000000000000000000000000000000000006124be565b6000807f00000000000000000000000000000000000000000000000000000000000000004210611a9a576000611abe565b427f0000000000000000000000000000000000000000000000000000000000000000035b670de0b6b3a76400009081029150611af99082907f000000000000000000000000000000000000000000000000000000000000000002611c5e565b90506000611b0f670de0b6b3a7640000836112f8565b905080611b1b57600080fd5b91505090565b600081611b375750670de0b6b3a76400006104b0565b82611b44575060006104b0565b611b717f80000000000000000000000000000000000000000000000000000000000000008410600661117a565b82611b97770bce5086492111aea88f4bb1ca6bcf584181ea8059f765328410600761117a565b826000670c7d713b49da000083138015611bb85750670f43fc2c04ee000083125b15611bef576000611bc884612612565b9050670de0b6b3a764000080820784020583670de0b6b3a764000083050201915050611bfd565b81611bf984612749565b0290505b670de0b6b3a76400009005611c4b7ffffffffffffffffffffffffffffffffffffffffffffffffdc702bd3a30fc00008212801590611c44575068070c1cc73b00c800008213155b600861117a565b611c5481612ae9565b9695505050505050565b6000611c6d821515600461117a565b82611c7a575060006104b0565b670de0b6b3a764000083810290611c9d90858381611c9457fe5b0414600561117a565b828181611ca657fe5b049150506104b0565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b03161415611d1e57611d17837f000000000000000000000000000000000000000000000000000000000000000060126124be565b90506104b0565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b03161415611d8457611d17837f000000000000000000000000000000000000000000000000000000000000000060126124be565b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161077b906137a1565b6000807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316856001600160a01b0316148015611e2b57507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b0316145b15611e445785611e396104b6565b850191509150611f01565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316856001600160a01b0316148015611eb657507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b0316145b15611ecf57611ec36104b6565b86018491509150611f01565b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161077b906136d6565b94509492505050565b60008115612029577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b03161415611fd8576000611f82611f5b86886112f8565b7f0000000000000000000000000000000000000000000000000000000000000000906117a1565b600680546fffffffffffffffffffffffffffffffff8082168401167fffffffffffffffffffffffffffffffff000000000000000000000000000000009091161790559050611fd0868261243b565b915050610a3d565b6000611fe7611f5b87876112f8565b600680546fffffffffffffffffffffffffffffffff7001000000000000000000000000000000008083048216850182160291161790559050611fd0868261243b565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b031614156120b4576000612072611f5b86886112f8565b600680546fffffffffffffffffffffffffffffffff7001000000000000000000000000000000008083048216850182160291161790559050611fd085826112f8565b60006120c3611f5b87876112f8565b600680546fffffffffffffffffffffffffffffffff8082168401167fffffffffffffffffffffffffffffffff000000000000000000000000000000009091161790559050611fd085826112f8565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b0316141561217957611d178360127f00000000000000000000000000000000000000000000000000000000000000006124be565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b03161415611d8457611d178360127f00000000000000000000000000000000000000000000000000000000000000006124be565b60006121e961125b565b826040516020016121fb929190613524565b604051602081830303815290604052805190602001209050919050565b60408051600280825260608083018452926020830190803683370190505090506000806122448561250b565b9150915060006122526104b6565b9050806122de576122638589612fb9565b87847f00000000000000000000000000000000000000000000000000000000000000008151811061229057fe5b6020026020010181815250506000847f0000000000000000000000000000000000000000000000000000000000000000815181106122ca57fe5b602002602001018181525050505050610a3d565b60006122ea8484611c5e565b905060006122f8828a6117a1565b90508981111561239e576000612312866116998d876117a1565b905061231e8882612fb9565b8a877f00000000000000000000000000000000000000000000000000000000000000008151811061234b57fe5b60209081029190910101526123608b84611c5e565b877f00000000000000000000000000000000000000000000000000000000000000008151811061238c57fe5b6020026020010181815250505061242e565b60006123ae8661169984876117a1565b90506123ba8882612fb9565b81877f0000000000000000000000000000000000000000000000000000000000000000815181106123e757fe5b60200260200101818152505089877f00000000000000000000000000000000000000000000000000000000000000008151811061242057fe5b602002602001018181525050505b5050505050949350505050565b6000828201610556848210158361117a565b7f08c379a0000000000000000000000000000000000000000000000000000000006000908152602060045260076024526642414c23000030600a808404818106603090810160081b95839006959095019082900491820690940160101b939093010160c81b604452606490fd5b4690565b60008160ff168360ff1611156124e75781830360ff16600a0a84816124df57fe5b049350612503565b8160ff168360ff1610156125035782820360ff16600a0a840293505b509192915050565b600080827f00000000000000000000000000000000000000000000000000000000000000008151811061253a57fe5b6020026020010151837f00000000000000000000000000000000000000000000000000000000000000008151811061256e57fe5b602002602001015191509150915091565b6001600160a01b0382166000908152602081905260409020546125a78282101561019661117a565b6001600160a01b038316600090815260208190526040902082820390556002546125d190836112f8565b6002556040516000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9061116d9086906135a7565b670de0b6b3a7640000026000806ec097ce7bc90715b34b9f1000000000808401907fffffffffffffffffffffffffffffffffff3f68318436f8ea4cb460f0000000008501028161265e57fe5b05905060006ec097ce7bc90715b34b9f100000000082800205905081806ec097ce7bc90715b34b9f100000000081840205915060038205016ec097ce7bc90715b34b9f100000000082840205915060058205016ec097ce7bc90715b34b9f100000000082840205915060078205016ec097ce7bc90715b34b9f100000000082840205915060098205016ec097ce7bc90715b34b9f1000000000828402059150600b8205016ec097ce7bc90715b34b9f1000000000828402059150600d8205016ec097ce7bc90715b34b9f1000000000828402059150600f826002919005919091010295945050505050565b6000670de0b6b3a76400008212156127865761277c826ec097ce7bc90715b34b9f10000000008161277657fe5b05612749565b6000039050610711565b60007e1600ef3172e58d2e933ec884fde10064c63b5372d805e203c000000000000083126127d757770195e54c5dd42177f53a27172fa9ec630262827000000000830592506806f05b59d3b2000000015b73011798004d755d3c8bc8e03204cf44619e000000831261280f576b1425982cf597cd205cef7380830592506803782dace9d9000000015b606492830292026e01855144814a7ff805980ff00840008312612857576e01855144814a7ff805980ff008400068056bc75e2d63100000840205925068ad78ebc5ac62000000015b6b02df0ab5a80a22c61ab5a7008312612892576b02df0ab5a80a22c61ab5a70068056bc75e2d6310000084020592506856bc75e2d631000000015b693f1fce3da636ea5cf85083126128c957693f1fce3da636ea5cf85068056bc75e2d631000008402059250682b5e3af16b18800000015b690127fa27722cc06cc5e2831261290057690127fa27722cc06cc5e268056bc75e2d6310000084020592506815af1d78b58c400000015b68280e60114edb805d0383126129355768280e60114edb805d0368056bc75e2d631000008402059250680ad78ebc5ac6200000015b680ebc5fb41746121110831261296057680ebc5fb4174612111068056bc75e2d631000009384020592015b6808f00f760a4b2db55d8312612995576808f00f760a4b2db55d68056bc75e2d6310000084020592506802b5e3af16b1880000015b6806f5f177578893793783126129ca576806f5f177578893793768056bc75e2d63100000840205925068015af1d78b58c40000015b6806248f33704b28660383126129fe576806248f33704b28660368056bc75e2d63100000840205925067ad78ebc5ac620000015b6805c548670b9510e7ac8312612a32576805c548670b9510e7ac68056bc75e2d6310000084020592506756bc75e2d6310000015b600068056bc75e2d63100000840168056bc75e2d631000008086030281612a5557fe5b059050600068056bc75e2d63100000828002059050818068056bc75e2d63100000818402059150600382050168056bc75e2d63100000828402059150600582050168056bc75e2d63100000828402059150600782050168056bc75e2d63100000828402059150600982050168056bc75e2d63100000828402059150600b820501600202606485820105979650505050505050565b6000612b2e7ffffffffffffffffffffffffffffffffffffffffffffffffdc702bd3a30fc00008312158015612b27575068070c1cc73b00c800008313155b600961117a565b6000821215612b6257612b4382600003612ae9565b6ec097ce7bc90715b34b9f100000000081612b5a57fe5b059050610711565b60006806f05b59d3b20000008312612bb857507ffffffffffffffffffffffffffffffffffffffffffffffff90fa4a62c4e00000090910190770195e54c5dd42177f53a27172fa9ec630262827000000000612c04565b6803782dace9d90000008312612c0057507ffffffffffffffffffffffffffffffffffffffffffffffffc87d2531627000000909101906b1425982cf597cd205cef7380612c04565b5060015b6064929092029168056bc75e2d6310000068ad78ebc5ac620000008412612c6a577fffffffffffffffffffffffffffffffffffffffffffffff5287143a539e0000009093019268056bc75e2d631000006e01855144814a7ff805980ff008400082020590505b6856bc75e2d6310000008412612cbc577fffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf0000009093019268056bc75e2d631000006b02df0ab5a80a22c61ab5a70082020590505b682b5e3af16b188000008412612d0c577fffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e78000009093019268056bc75e2d63100000693f1fce3da636ea5cf85082020590505b6815af1d78b58c4000008412612d5c577fffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c000009093019268056bc75e2d63100000690127fa27722cc06cc5e282020590505b680ad78ebc5ac62000008412612dab577ffffffffffffffffffffffffffffffffffffffffffffffff5287143a539e000009093019268056bc75e2d6310000068280e60114edb805d0382020590505b68056bc75e2d631000008412612dfa577ffffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf000009093019268056bc75e2d63100000680ebc5fb4174612111082020590505b6802b5e3af16b18800008412612e49577ffffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e7800009093019268056bc75e2d631000006808f00f760a4b2db55d82020590505b68015af1d78b58c400008412612e98577ffffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c00009093019268056bc75e2d631000006806f5f177578893793782020590505b68056bc75e2d631000008481019085906002908280020505918201919050600368056bc75e2d631000008783020505918201919050600468056bc75e2d631000008783020505918201919050600568056bc75e2d631000008783020505918201919050600668056bc75e2d631000008783020505918201919050600768056bc75e2d631000008783020505918201919050600868056bc75e2d631000008783020505918201919050600968056bc75e2d631000008783020505918201919050600a68056bc75e2d631000008783020505918201919050600b68056bc75e2d631000008783020505918201919050600c68056bc75e2d631000008783020505918201919050606468056bc75e2d63100000848402058502059695505050505050565b6001600160a01b038216600090815260208190526040902054612fdc908261243b565b6001600160a01b038316600090815260208190526040902055600254613002908261243b565b6002556040516001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef906130439085906135a7565b60405180910390a35050565b80356104b081613845565b600082601f83011261306a578081fd5b813567ffffffffffffffff811115613080578182fd5b602080820261309082820161381e565b838152935081840185830182870184018810156130ac57600080fd5b600092505b848310156130cf5780358252600192909201919083019083016130b1565b505050505092915050565b600082601f8301126130ea578081fd5b813567ffffffffffffffff811115613100578182fd5b61313160207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8401160161381e565b915080825283602082850101111561314857600080fd5b8060208401602084013760009082016020015292915050565b8035600281106104b057600080fd5b600060208284031215613181578081fd5b813561055681613845565b6000806040838503121561319e578081fd5b82356131a981613845565b915060208301356131b981613845565b809150509250929050565b6000806000606084860312156131d8578081fd5b83356131e381613845565b925060208401356131f381613845565b929592945050506040919091013590565b600080600080600080600060e0888a03121561321e578283fd5b873561322981613845565b9650602088013561323981613845565b95506040880135945060608801359350608088013560ff8116811461325c578384fd5b9699959850939692959460a0840135945060c09093013592915050565b6000806040838503121561328b578182fd5b823561329681613845565b946020939093013593505050565b6000602082840312156132b5578081fd5b813567ffffffffffffffff8111156132cb578182fd5b610a3d8482850161305a565b60008060008060008060008060e0898b0312156132f2578081fd5b88359750602089013561330481613845565b9650604089013561331481613845565b9550606089013567ffffffffffffffff80821115613330578283fd5b61333c8c838d0161305a565b965060808b0135955060a08b0135945060c08b013591508082111561335f578283fd5b818b0191508b601f830112613372578283fd5b813581811115613380578384fd5b8c6020828501011115613391578384fd5b6020830194508093505050509295985092959890939650565b6000806000606084860312156133be578283fd5b833567ffffffffffffffff808211156133d5578485fd5b81860191506101208083890312156133eb578586fd5b6133f48161381e565b90506134008884613161565b815261340f886020850161304f565b6020820152613421886040850161304f565b6040820152606083013560608201526080830135608082015260a083013560a08201526134518860c0850161304f565b60c08201526134638860e0850161304f565b60e0820152610100808401358381111561347b578788fd5b6134878a8287016130da565b9183019190915250976020870135975060409096013595945050505050565b600080600080608085870312156134bb578182fd5b843593506020850135925060408501359150606085013580151581146134df578182fd5b939692955090935050565b6000815180845260208085019450808401835b83811015613519578151875295820195908201906001016134fd565b509495945050505050565b7f190100000000000000000000000000000000000000000000000000000000000081526002810192909252602282015260420190565b6001600160a01b0391909116815260200190565b60006040825261358160408301856134ea565b828103602084015261359381856134ea565b95945050505050565b901515815260200190565b90815260200190565b9586526001600160a01b0394851660208701529290931660408501526060840152608083019190915260a082015260c00190565b9485526020850193909352604084019190915260608301526001600160a01b0316608082015260a00190565b93845260ff9290921660208401526040830152606082015260800190565b6000602080835283518082850152825b8181101561365a5785810183015185820160400152820161363e565b8181111561366b5783604083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016929092016040019392505050565b60208082526010908201527f4e6f6e205661756c742063616c6c657200000000000000000000000000000000604082015260600190565b60208082526022908201527f546f6b656e207265717565737420646f65736e2774206d617463682073746f7260408201527f6564000000000000000000000000000000000000000000000000000000000000606082015260800190565b6020808252600e908201527f496e76616c696420666f726d6174000000000000000000000000000000000000604082015260600190565b6020808252600d908201527f57726f6e6720706f6f6c20696400000000000000000000000000000000000000604082015260600190565b6020808252601a908201527f43616c6c65642077697468206e6f6e20706f6f6c20746f6b656e000000000000604082015260600190565b6fffffffffffffffffffffffffffffffff91909116815260200190565b93845260208401929092526040830152606082015260800190565b60ff91909116815260200190565b60405181810167ffffffffffffffff8111828210171561383d57600080fd5b604052919050565b6001600160a01b038116811461385a57600080fd5b5056fea264697066735822122048dc0ac939a1088f45b3d5b39850b113811c6c1baf733420a00f3f6c9dc8984264736f6c63430007010033000000000000000000000000ed279fdd11ca84beef15af5d39bb4d4bee23f0ca000000000000000000000000a2b3d083aa1eaa8453bfb477f062a208ed85cbbf0000000000000000000000000000000000000000000000000000000061c9e0e2000000000000000000000000000000000000000000000000000000002d248040000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c8000000000000000000000000000000000000000000000000016345785d8a000000000000000000000000000000000000000000000000000002c68af0bb140000000000000000000000000000654be0b5556f8eadbc2d140505445fa32715ef2b000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000000002e4c5020456c656d656e74205072696e636970616c20546f6b656e20797643757276654c5553442d3237444543323100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000174c506550797643757276654c5553442d32374445433231000000000000000000
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106101f05760003560e01c806370a082311161010f578063d505accf116100a2578063eaee3f3b11610071578063eaee3f3b146103be578063f1cd96ba146103c6578063f46c39e7146103ce578063f7b94283146103e3576101f0565b8063d505accf14610370578063d5c096c414610385578063d73dd62314610398578063dd62ed3e146103ab576101f0565b80638d928af8116100de5780638d928af81461033a57806395d89b41146103425780639d2c110c1461034a578063a9059cbb1461035d576101f0565b806370a08231146102e057806374f3b009146102f357806379155050146103145780637ecebe0014610327576101f0565b806338fff2d0116101875780635aa6e675116101565780635aa6e675146102a857806364c9ec6f146102bd57806366188463146102c55780636f307dc3146102d8576101f0565b806338fff2d01461028857806341bd436a146102905780634665096d146102985780634c1a4115146102a0576101f0565b806325a760c2116101c357806325a760c21461025b57806329e4f36214610270578063313ce567146102785780633644e51514610280576101f0565b806306fdde03146101f5578063095ea7b31461021357806318160ddd1461023357806323b872dd14610248575b600080fd5b6101fd6103eb565b60405161020a919061362e565b60405180910390f35b610226610221366004613279565b61049f565b60405161020a919061359c565b61023b6104b6565b60405161020a91906135a7565b6102266102563660046131c4565b6104bc565b61026361055d565b60405161020a9190613810565b61023b610581565b61026361058d565b61023b610592565b61023b6105a1565b61023b6105c5565b61023b6105e9565b61023b61060d565b6102b0610631565b60405161020a919061355a565b6102b0610655565b6102266102d3366004613279565b610679565b6102b06106d3565b61023b6102ee366004613170565b6106f7565b6103066103013660046132d7565b610716565b60405161020a92919061356e565b61023b6103223660046134a6565b610994565b61023b610335366004613170565b610a45565b6102b0610a60565b6101fd610a84565b61023b6103583660046133aa565b610b03565b61022661036b366004613279565b610c5e565b61038361037e366004613204565b610c6b565b005b6103066103933660046132d7565b610dd2565b6102266103a6366004613279565b611025565b61023b6103b936600461318c565b61105b565b61023b611086565b6102636110aa565b6103d66110ce565b60405161020a91906137d8565b6103d66110fa565b60038054604080516020601f60027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104955780601f1061046a57610100808354040283529160200191610495565b820191906000526020600020905b81548152906001019060200180831161047857829003601f168201915b5050505050905090565b60006104ac338484611112565b5060015b92915050565b60025490565b6001600160a01b038316600081815260016020908152604080832033808552925282205491926104fa9114806104f25750838210155b61019761117a565b61050585858561118c565b336001600160a01b0386161480159061053e57507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8114155b15610550576105508533858403611112565b60019150505b9392505050565b7f000000000000000000000000000000000000000000000000000000000000001281565b670429d069189e000081565b601290565b600061059c61125b565b905090565b7f893b30574bf183d69413717f30b17062ec9dfd8b00020000000000000000006190565b7f00000000000000000000000000000000000000000000000002c68af0bb14000081565b7f0000000000000000000000000000000000000000000000000000000061c9e0e281565b7f000000000000000000000000000000000000000000000000016345785d8a000081565b7f000000000000000000000000654be0b5556f8eadbc2d140505445fa32715ef2b81565b7f000000000000000000000000a2b3d083aa1eaa8453bfb477f062a208ed85cbbf81565b3360009081526001602090815260408083206001600160a01b03861684529091528120548083106106b5576106b033856000611112565b6106c9565b6106c933856106c484876112f8565b611112565b5060019392505050565b7f000000000000000000000000ed279fdd11ca84beef15af5d39bb4d4bee23f0ca81565b6001600160a01b0381166000908152602081905260409020545b919050565b606080336001600160a01b037f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c81614610784576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161077b9061369f565b60405180910390fd5b7f893b30574bf183d69413717f30b17062ec9dfd8b0002000000000000000000618a146107dd576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161077b9061376a565b60606107eb848601866132a4565b9050875160021480156107ff575080516002145b610835576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161077b90613733565b61083e8861130e565b6108478161130e565b6000806108538a61143f565b6040805160028082526060820190925292945090925081602001602082028036833701905050935061088582896117a1565b847f0000000000000000000000000000000000000000000000000000000000000001815181106108b157fe5b60209081029190910101526108c681896117a1565b847f0000000000000000000000000000000000000000000000000000000000000000815181106108f257fe5b6020026020010181815250505050610972817f00000000000000000000000000000000000000000000000000000000000000018151811061092f57fe5b6020026020010151827f00000000000000000000000000000000000000000000000000000000000000008151811061096357fe5b60200260200101518a8c6117d7565b925061097d83611973565b61098682611973565b509850989650505050505050565b60008061099f611a69565b905060006109ad8683611b21565b905060006109bb8684611b21565b90506000856109dc576109d76109d1898b6112f8565b85611b21565b6109e8565b6109e889890185611b21565b905060006109f8848401836112f8565b9050610a1581610a10670de0b6b3a764000088611c5e565b611b21565b905086610a2b57610a2681896112f8565b610a35565b610a3588826112f8565b955050505050505b949350505050565b6001600160a01b031660009081526005602052604090205490565b7f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c890565b60048054604080516020601f60027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104955780601f1061046a57610100808354040283529160200191610495565b6000336001600160a01b037f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c81614610b67576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161077b9061369f565b6000808086516001811115610b7857fe5b1490508015610b9a57610b9386606001518760200151611caf565b9150610baf565b610bac86606001518760400151611caf565b91505b610bbd858760200151611caf565b9450610bcd848760400151611caf565b9350600080610be6878960200151888b60400151611db6565b915091508215610c2d576000610bfe85848487610994565b9050610c1185828b604001516000611f0a565b9050610c21818a60400151612111565b95505050505050610556565b6000610c3b85838587610994565b9050610c4e81868b604001516001611f0a565b9050610c21818a60200151612111565b60006104ac33848461118c565b610c798442111560d161117a565b6001600160a01b0387166000908152600560209081526040808320549051909291610cd0917f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9918c918c918c9188918d91016135b0565b6040516020818303038152906040528051906020012090506000610cf3826121df565b9050600060018288888860405160008152602001604052604051610d1a9493929190613610565b6020604051602081039080840390855afa158015610d3c573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe001519150610d9c90506001600160a01b03821615801590610d9457508b6001600160a01b0316826001600160a01b0316145b6101f861117a565b6001600160a01b038b166000908152600560205260409020600185019055610dc58b8b8b611112565b5050505050505050505050565b606080336001600160a01b037f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c81614610e37576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161077b9061369f565b7f893b30574bf183d69413717f30b17062ec9dfd8b0002000000000000000000618a14610e90576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161077b9061376a565b6060610e9e848601866132a4565b905087516002148015610eb2575080516002145b610ee8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161077b90613733565b610ef18861130e565b610efa8161130e565b600080610f068a61143f565b60408051600280825260608201909252929450909250816020016020820280368337019050509350610f3882896117a1565b847f000000000000000000000000000000000000000000000000000000000000000181518110610f6457fe5b6020908102919091010152610f7981896117a1565b847f000000000000000000000000000000000000000000000000000000000000000081518110610fa557fe5b6020026020010181815250505050610972817f000000000000000000000000000000000000000000000000000000000000000181518110610fe257fe5b6020026020010151827f00000000000000000000000000000000000000000000000000000000000000008151811061101657fe5b60200260200101518a8c612218565b3360008181526001602090815260408083206001600160a01b038716845290915281205490916104ac9185906106c4908661243b565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b7f000000000000000000000000000000000000000000000000000000002d24804081565b7f000000000000000000000000000000000000000000000000000000000000001281565b60065470010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff1681565b6006546fffffffffffffffffffffffffffffffff1681565b6001600160a01b0380841660008181526001602090815260408083209487168084529490915290819020849055517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259061116d9085906135a7565b60405180910390a3505050565b81611188576111888161244d565b5050565b6001600160a01b0383166000908152602081905260409020546111b48282101561019661117a565b6111cb6001600160a01b038416151561019961117a565b6001600160a01b038085166000908152602081905260408082208585039055918516815220546111fb908361243b565b6001600160a01b0380851660008181526020819052604090819020939093559151908616907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9061124d9086906135a7565b60405180910390a350505050565b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f7f0c693297bedfe1135d6ae4275b2391ddf22678cd12353452d37248508c3b6b777fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc66112c86124ba565b306040516020016112dd9594939291906135e4565b60405160208183030381529060405280519060200120905090565b600061130883831115600161117a565b50900390565b61136d817f00000000000000000000000000000000000000000000000000000000000000018151811061133d57fe5b60200260200101517f000000000000000000000000000000000000000000000000000000000000001260126124be565b817f00000000000000000000000000000000000000000000000000000000000000018151811061139957fe5b602002602001018181525050611404817f0000000000000000000000000000000000000000000000000000000000000000815181106113d457fe5b60200260200101517f000000000000000000000000000000000000000000000000000000000000001260126124be565b817f00000000000000000000000000000000000000000000000000000000000000008151811061143057fe5b60200260200101818152505050565b60065460009081906fffffffffffffffffffffffffffffffff808216917001000000000000000000000000000000009004167f00000000000000000000000000000000000000000000000002c68af0bb1400006114e357600060068190556040517f9f878c349b0fc751f12168fdf539db8c1848b81c0751432f28626da5aa7024ee916114d1918591859181906137f5565b60405180910390a1909250905061179c565b600061150f837f00000000000000000000000000000000000000000000000002c68af0bb1400006117a1565b9050600061153d837f00000000000000000000000000000000000000000000000002c68af0bb1400006117a1565b9050606061156d83838a7f000000000000000000000000654be0b5556f8eadbc2d140505445fa32715ef2b612218565b905060006115d77f00000000000000000000000000000000000000000000000002c68af0bb140000837f0000000000000000000000000000000000000000000000000000000000000001815181106115c157fe5b6020026020010151611c5e90919063ffffffff16565b9050600061162b7f00000000000000000000000000000000000000000000000002c68af0bb140000847f0000000000000000000000000000000000000000000000000000000000000000815181106115c157fe5b9050600061169f7f00000000000000000000000000000000000000000000000002c68af0bb140000611699867f00000000000000000000000000000000000000000000000000000000000000018151811061168257fe5b6020026020010151896112f890919063ffffffff16565b90611c5e565b905060006116f67f00000000000000000000000000000000000000000000000002c68af0bb140000611699877f00000000000000000000000000000000000000000000000000000000000000008151811061168257fe5b90507f9f878c349b0fc751f12168fdf539db8c1848b81c0751432f28626da5aa7024ee8484848460405161172d94939291906137f5565b60405180910390a1600680546fffffffffffffffffffffffffffffffff928316700100000000000000000000000000000000029383167fffffffffffffffffffffffffffffffff0000000000000000000000000000000090911617909116919091179055909750955050505050505b915091565b60008282026117c58415806117be5750838583816117bb57fe5b04145b600361117a565b670de0b6b3a764000090049392505050565b60408051600280825260608083018452926020830190803683370190505090506000806118038561250b565b9150915060006118116104b6565b9050600061181f8484611c5e565b905061182b88826117a1565b8911156118ce576000611842856116998c866117a1565b905061184e878261257f565b89867f00000000000000000000000000000000000000000000000000000000000000018151811061187b57fe5b60209081029190910101526118908a83611c5e565b867f0000000000000000000000000000000000000000000000000000000000000000815181106118bc57fe5b60200260200101818152505050611967565b60006118de846116998b866117a1565b90506118ea878261257f565b6118f489836117a1565b867f00000000000000000000000000000000000000000000000000000000000000018151811061192057fe5b60200260200101818152505088867f00000000000000000000000000000000000000000000000000000000000000008151811061195957fe5b602002602001018181525050505b50505050949350505050565b6119d2817f0000000000000000000000000000000000000000000000000000000000000001815181106119a257fe5b602002602001015160127f00000000000000000000000000000000000000000000000000000000000000126124be565b817f0000000000000000000000000000000000000000000000000000000000000001815181106119fe57fe5b602002602001018181525050611404817f000000000000000000000000000000000000000000000000000000000000000081518110611a3957fe5b602002602001015160127f00000000000000000000000000000000000000000000000000000000000000126124be565b6000807f0000000000000000000000000000000000000000000000000000000061c9e0e24210611a9a576000611abe565b427f0000000000000000000000000000000000000000000000000000000061c9e0e2035b670de0b6b3a76400009081029150611af99082907f000000000000000000000000000000000000000000000000000000002d24804002611c5e565b90506000611b0f670de0b6b3a7640000836112f8565b905080611b1b57600080fd5b91505090565b600081611b375750670de0b6b3a76400006104b0565b82611b44575060006104b0565b611b717f80000000000000000000000000000000000000000000000000000000000000008410600661117a565b82611b97770bce5086492111aea88f4bb1ca6bcf584181ea8059f765328410600761117a565b826000670c7d713b49da000083138015611bb85750670f43fc2c04ee000083125b15611bef576000611bc884612612565b9050670de0b6b3a764000080820784020583670de0b6b3a764000083050201915050611bfd565b81611bf984612749565b0290505b670de0b6b3a76400009005611c4b7ffffffffffffffffffffffffffffffffffffffffffffffffdc702bd3a30fc00008212801590611c44575068070c1cc73b00c800008213155b600861117a565b611c5481612ae9565b9695505050505050565b6000611c6d821515600461117a565b82611c7a575060006104b0565b670de0b6b3a764000083810290611c9d90858381611c9457fe5b0414600561117a565b828181611ca657fe5b049150506104b0565b60007f000000000000000000000000ed279fdd11ca84beef15af5d39bb4d4bee23f0ca6001600160a01b0316826001600160a01b03161415611d1e57611d17837f000000000000000000000000000000000000000000000000000000000000001260126124be565b90506104b0565b7f000000000000000000000000a2b3d083aa1eaa8453bfb477f062a208ed85cbbf6001600160a01b0316826001600160a01b03161415611d8457611d17837f000000000000000000000000000000000000000000000000000000000000001260126124be565b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161077b906137a1565b6000807f000000000000000000000000ed279fdd11ca84beef15af5d39bb4d4bee23f0ca6001600160a01b0316856001600160a01b0316148015611e2b57507f000000000000000000000000a2b3d083aa1eaa8453bfb477f062a208ed85cbbf6001600160a01b0316836001600160a01b0316145b15611e445785611e396104b6565b850191509150611f01565b7f000000000000000000000000a2b3d083aa1eaa8453bfb477f062a208ed85cbbf6001600160a01b0316856001600160a01b0316148015611eb657507f000000000000000000000000ed279fdd11ca84beef15af5d39bb4d4bee23f0ca6001600160a01b0316836001600160a01b0316145b15611ecf57611ec36104b6565b86018491509150611f01565b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161077b906136d6565b94509492505050565b60008115612029577f000000000000000000000000a2b3d083aa1eaa8453bfb477f062a208ed85cbbf6001600160a01b0316836001600160a01b03161415611fd8576000611f82611f5b86886112f8565b7f000000000000000000000000000000000000000000000000016345785d8a0000906117a1565b600680546fffffffffffffffffffffffffffffffff8082168401167fffffffffffffffffffffffffffffffff000000000000000000000000000000009091161790559050611fd0868261243b565b915050610a3d565b6000611fe7611f5b87876112f8565b600680546fffffffffffffffffffffffffffffffff7001000000000000000000000000000000008083048216850182160291161790559050611fd0868261243b565b7f000000000000000000000000a2b3d083aa1eaa8453bfb477f062a208ed85cbbf6001600160a01b0316836001600160a01b031614156120b4576000612072611f5b86886112f8565b600680546fffffffffffffffffffffffffffffffff7001000000000000000000000000000000008083048216850182160291161790559050611fd085826112f8565b60006120c3611f5b87876112f8565b600680546fffffffffffffffffffffffffffffffff8082168401167fffffffffffffffffffffffffffffffff000000000000000000000000000000009091161790559050611fd085826112f8565b60007f000000000000000000000000ed279fdd11ca84beef15af5d39bb4d4bee23f0ca6001600160a01b0316826001600160a01b0316141561217957611d178360127f00000000000000000000000000000000000000000000000000000000000000126124be565b7f000000000000000000000000a2b3d083aa1eaa8453bfb477f062a208ed85cbbf6001600160a01b0316826001600160a01b03161415611d8457611d178360127f00000000000000000000000000000000000000000000000000000000000000126124be565b60006121e961125b565b826040516020016121fb929190613524565b604051602081830303815290604052805190602001209050919050565b60408051600280825260608083018452926020830190803683370190505090506000806122448561250b565b9150915060006122526104b6565b9050806122de576122638589612fb9565b87847f00000000000000000000000000000000000000000000000000000000000000018151811061229057fe5b6020026020010181815250506000847f0000000000000000000000000000000000000000000000000000000000000000815181106122ca57fe5b602002602001018181525050505050610a3d565b60006122ea8484611c5e565b905060006122f8828a6117a1565b90508981111561239e576000612312866116998d876117a1565b905061231e8882612fb9565b8a877f00000000000000000000000000000000000000000000000000000000000000018151811061234b57fe5b60209081029190910101526123608b84611c5e565b877f00000000000000000000000000000000000000000000000000000000000000008151811061238c57fe5b6020026020010181815250505061242e565b60006123ae8661169984876117a1565b90506123ba8882612fb9565b81877f0000000000000000000000000000000000000000000000000000000000000001815181106123e757fe5b60200260200101818152505089877f00000000000000000000000000000000000000000000000000000000000000008151811061242057fe5b602002602001018181525050505b5050505050949350505050565b6000828201610556848210158361117a565b7f08c379a0000000000000000000000000000000000000000000000000000000006000908152602060045260076024526642414c23000030600a808404818106603090810160081b95839006959095019082900491820690940160101b939093010160c81b604452606490fd5b4690565b60008160ff168360ff1611156124e75781830360ff16600a0a84816124df57fe5b049350612503565b8160ff168360ff1610156125035782820360ff16600a0a840293505b509192915050565b600080827f00000000000000000000000000000000000000000000000000000000000000018151811061253a57fe5b6020026020010151837f00000000000000000000000000000000000000000000000000000000000000008151811061256e57fe5b602002602001015191509150915091565b6001600160a01b0382166000908152602081905260409020546125a78282101561019661117a565b6001600160a01b038316600090815260208190526040902082820390556002546125d190836112f8565b6002556040516000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9061116d9086906135a7565b670de0b6b3a7640000026000806ec097ce7bc90715b34b9f1000000000808401907fffffffffffffffffffffffffffffffffff3f68318436f8ea4cb460f0000000008501028161265e57fe5b05905060006ec097ce7bc90715b34b9f100000000082800205905081806ec097ce7bc90715b34b9f100000000081840205915060038205016ec097ce7bc90715b34b9f100000000082840205915060058205016ec097ce7bc90715b34b9f100000000082840205915060078205016ec097ce7bc90715b34b9f100000000082840205915060098205016ec097ce7bc90715b34b9f1000000000828402059150600b8205016ec097ce7bc90715b34b9f1000000000828402059150600d8205016ec097ce7bc90715b34b9f1000000000828402059150600f826002919005919091010295945050505050565b6000670de0b6b3a76400008212156127865761277c826ec097ce7bc90715b34b9f10000000008161277657fe5b05612749565b6000039050610711565b60007e1600ef3172e58d2e933ec884fde10064c63b5372d805e203c000000000000083126127d757770195e54c5dd42177f53a27172fa9ec630262827000000000830592506806f05b59d3b2000000015b73011798004d755d3c8bc8e03204cf44619e000000831261280f576b1425982cf597cd205cef7380830592506803782dace9d9000000015b606492830292026e01855144814a7ff805980ff00840008312612857576e01855144814a7ff805980ff008400068056bc75e2d63100000840205925068ad78ebc5ac62000000015b6b02df0ab5a80a22c61ab5a7008312612892576b02df0ab5a80a22c61ab5a70068056bc75e2d6310000084020592506856bc75e2d631000000015b693f1fce3da636ea5cf85083126128c957693f1fce3da636ea5cf85068056bc75e2d631000008402059250682b5e3af16b18800000015b690127fa27722cc06cc5e2831261290057690127fa27722cc06cc5e268056bc75e2d6310000084020592506815af1d78b58c400000015b68280e60114edb805d0383126129355768280e60114edb805d0368056bc75e2d631000008402059250680ad78ebc5ac6200000015b680ebc5fb41746121110831261296057680ebc5fb4174612111068056bc75e2d631000009384020592015b6808f00f760a4b2db55d8312612995576808f00f760a4b2db55d68056bc75e2d6310000084020592506802b5e3af16b1880000015b6806f5f177578893793783126129ca576806f5f177578893793768056bc75e2d63100000840205925068015af1d78b58c40000015b6806248f33704b28660383126129fe576806248f33704b28660368056bc75e2d63100000840205925067ad78ebc5ac620000015b6805c548670b9510e7ac8312612a32576805c548670b9510e7ac68056bc75e2d6310000084020592506756bc75e2d6310000015b600068056bc75e2d63100000840168056bc75e2d631000008086030281612a5557fe5b059050600068056bc75e2d63100000828002059050818068056bc75e2d63100000818402059150600382050168056bc75e2d63100000828402059150600582050168056bc75e2d63100000828402059150600782050168056bc75e2d63100000828402059150600982050168056bc75e2d63100000828402059150600b820501600202606485820105979650505050505050565b6000612b2e7ffffffffffffffffffffffffffffffffffffffffffffffffdc702bd3a30fc00008312158015612b27575068070c1cc73b00c800008313155b600961117a565b6000821215612b6257612b4382600003612ae9565b6ec097ce7bc90715b34b9f100000000081612b5a57fe5b059050610711565b60006806f05b59d3b20000008312612bb857507ffffffffffffffffffffffffffffffffffffffffffffffff90fa4a62c4e00000090910190770195e54c5dd42177f53a27172fa9ec630262827000000000612c04565b6803782dace9d90000008312612c0057507ffffffffffffffffffffffffffffffffffffffffffffffffc87d2531627000000909101906b1425982cf597cd205cef7380612c04565b5060015b6064929092029168056bc75e2d6310000068ad78ebc5ac620000008412612c6a577fffffffffffffffffffffffffffffffffffffffffffffff5287143a539e0000009093019268056bc75e2d631000006e01855144814a7ff805980ff008400082020590505b6856bc75e2d6310000008412612cbc577fffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf0000009093019268056bc75e2d631000006b02df0ab5a80a22c61ab5a70082020590505b682b5e3af16b188000008412612d0c577fffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e78000009093019268056bc75e2d63100000693f1fce3da636ea5cf85082020590505b6815af1d78b58c4000008412612d5c577fffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c000009093019268056bc75e2d63100000690127fa27722cc06cc5e282020590505b680ad78ebc5ac62000008412612dab577ffffffffffffffffffffffffffffffffffffffffffffffff5287143a539e000009093019268056bc75e2d6310000068280e60114edb805d0382020590505b68056bc75e2d631000008412612dfa577ffffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf000009093019268056bc75e2d63100000680ebc5fb4174612111082020590505b6802b5e3af16b18800008412612e49577ffffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e7800009093019268056bc75e2d631000006808f00f760a4b2db55d82020590505b68015af1d78b58c400008412612e98577ffffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c00009093019268056bc75e2d631000006806f5f177578893793782020590505b68056bc75e2d631000008481019085906002908280020505918201919050600368056bc75e2d631000008783020505918201919050600468056bc75e2d631000008783020505918201919050600568056bc75e2d631000008783020505918201919050600668056bc75e2d631000008783020505918201919050600768056bc75e2d631000008783020505918201919050600868056bc75e2d631000008783020505918201919050600968056bc75e2d631000008783020505918201919050600a68056bc75e2d631000008783020505918201919050600b68056bc75e2d631000008783020505918201919050600c68056bc75e2d631000008783020505918201919050606468056bc75e2d63100000848402058502059695505050505050565b6001600160a01b038216600090815260208190526040902054612fdc908261243b565b6001600160a01b038316600090815260208190526040902055600254613002908261243b565b6002556040516001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef906130439085906135a7565b60405180910390a35050565b80356104b081613845565b600082601f83011261306a578081fd5b813567ffffffffffffffff811115613080578182fd5b602080820261309082820161381e565b838152935081840185830182870184018810156130ac57600080fd5b600092505b848310156130cf5780358252600192909201919083019083016130b1565b505050505092915050565b600082601f8301126130ea578081fd5b813567ffffffffffffffff811115613100578182fd5b61313160207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8401160161381e565b915080825283602082850101111561314857600080fd5b8060208401602084013760009082016020015292915050565b8035600281106104b057600080fd5b600060208284031215613181578081fd5b813561055681613845565b6000806040838503121561319e578081fd5b82356131a981613845565b915060208301356131b981613845565b809150509250929050565b6000806000606084860312156131d8578081fd5b83356131e381613845565b925060208401356131f381613845565b929592945050506040919091013590565b600080600080600080600060e0888a03121561321e578283fd5b873561322981613845565b9650602088013561323981613845565b95506040880135945060608801359350608088013560ff8116811461325c578384fd5b9699959850939692959460a0840135945060c09093013592915050565b6000806040838503121561328b578182fd5b823561329681613845565b946020939093013593505050565b6000602082840312156132b5578081fd5b813567ffffffffffffffff8111156132cb578182fd5b610a3d8482850161305a565b60008060008060008060008060e0898b0312156132f2578081fd5b88359750602089013561330481613845565b9650604089013561331481613845565b9550606089013567ffffffffffffffff80821115613330578283fd5b61333c8c838d0161305a565b965060808b0135955060a08b0135945060c08b013591508082111561335f578283fd5b818b0191508b601f830112613372578283fd5b813581811115613380578384fd5b8c6020828501011115613391578384fd5b6020830194508093505050509295985092959890939650565b6000806000606084860312156133be578283fd5b833567ffffffffffffffff808211156133d5578485fd5b81860191506101208083890312156133eb578586fd5b6133f48161381e565b90506134008884613161565b815261340f886020850161304f565b6020820152613421886040850161304f565b6040820152606083013560608201526080830135608082015260a083013560a08201526134518860c0850161304f565b60c08201526134638860e0850161304f565b60e0820152610100808401358381111561347b578788fd5b6134878a8287016130da565b9183019190915250976020870135975060409096013595945050505050565b600080600080608085870312156134bb578182fd5b843593506020850135925060408501359150606085013580151581146134df578182fd5b939692955090935050565b6000815180845260208085019450808401835b83811015613519578151875295820195908201906001016134fd565b509495945050505050565b7f190100000000000000000000000000000000000000000000000000000000000081526002810192909252602282015260420190565b6001600160a01b0391909116815260200190565b60006040825261358160408301856134ea565b828103602084015261359381856134ea565b95945050505050565b901515815260200190565b90815260200190565b9586526001600160a01b0394851660208701529290931660408501526060840152608083019190915260a082015260c00190565b9485526020850193909352604084019190915260608301526001600160a01b0316608082015260a00190565b93845260ff9290921660208401526040830152606082015260800190565b6000602080835283518082850152825b8181101561365a5785810183015185820160400152820161363e565b8181111561366b5783604083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016929092016040019392505050565b60208082526010908201527f4e6f6e205661756c742063616c6c657200000000000000000000000000000000604082015260600190565b60208082526022908201527f546f6b656e207265717565737420646f65736e2774206d617463682073746f7260408201527f6564000000000000000000000000000000000000000000000000000000000000606082015260800190565b6020808252600e908201527f496e76616c696420666f726d6174000000000000000000000000000000000000604082015260600190565b6020808252600d908201527f57726f6e6720706f6f6c20696400000000000000000000000000000000000000604082015260600190565b6020808252601a908201527f43616c6c65642077697468206e6f6e20706f6f6c20746f6b656e000000000000604082015260600190565b6fffffffffffffffffffffffffffffffff91909116815260200190565b93845260208401929092526040830152606082015260800190565b60ff91909116815260200190565b60405181810167ffffffffffffffff8111828210171561383d57600080fd5b604052919050565b6001600160a01b038116811461385a57600080fd5b5056fea264697066735822122048dc0ac939a1088f45b3d5b39850b113811c6c1baf733420a00f3f6c9dc8984264736f6c63430007010033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000ed279fdd11ca84beef15af5d39bb4d4bee23f0ca000000000000000000000000a2b3d083aa1eaa8453bfb477f062a208ed85cbbf0000000000000000000000000000000000000000000000000000000061c9e0e2000000000000000000000000000000000000000000000000000000002d248040000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c8000000000000000000000000000000000000000000000000016345785d8a000000000000000000000000000000000000000000000000000002c68af0bb140000000000000000000000000000654be0b5556f8eadbc2d140505445fa32715ef2b000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000000002e4c5020456c656d656e74205072696e636970616c20546f6b656e20797643757276654c5553442d3237444543323100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000174c506550797643757276654c5553442d32374445433231000000000000000000
-----Decoded View---------------
Arg [0] : _underlying (address): 0xEd279fDD11cA84bEef15AF5D39BB4d4bEE23F0cA
Arg [1] : _bond (address): 0xa2b3d083AA1eaa8453BfB477f062A208Ed85cBBF
Arg [2] : _expiration (uint256): 1640620258
Arg [3] : _unitSeconds (uint256): 757366848
Arg [4] : vault (address): 0xBA12222222228d8Ba445958a75a0704d566BF2C8
Arg [5] : _percentFee (uint256): 100000000000000000
Arg [6] : _percentFeeGov (uint256): 200000000000000000
Arg [7] : _governance (address): 0x654BE0B5556F8EadbC2D140505445fA32715eF2b
Arg [8] : name (string): LP Element Principal Token yvCurveLUSD-27DEC21
Arg [9] : symbol (string): LPePyvCurveLUSD-27DEC21
-----Encoded View---------------
15 Constructor Arguments found :
Arg [0] : 000000000000000000000000ed279fdd11ca84beef15af5d39bb4d4bee23f0ca
Arg [1] : 000000000000000000000000a2b3d083aa1eaa8453bfb477f062a208ed85cbbf
Arg [2] : 0000000000000000000000000000000000000000000000000000000061c9e0e2
Arg [3] : 000000000000000000000000000000000000000000000000000000002d248040
Arg [4] : 000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c8
Arg [5] : 000000000000000000000000000000000000000000000000016345785d8a0000
Arg [6] : 00000000000000000000000000000000000000000000000002c68af0bb140000
Arg [7] : 000000000000000000000000654be0b5556f8eadbc2d140505445fa32715ef2b
Arg [8] : 0000000000000000000000000000000000000000000000000000000000000140
Arg [9] : 00000000000000000000000000000000000000000000000000000000000001a0
Arg [10] : 000000000000000000000000000000000000000000000000000000000000002e
Arg [11] : 4c5020456c656d656e74205072696e636970616c20546f6b656e207976437572
Arg [12] : 76654c5553442d32374445433231000000000000000000000000000000000000
Arg [13] : 0000000000000000000000000000000000000000000000000000000000000017
Arg [14] : 4c506550797643757276654c5553442d32374445433231000000000000000000
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A token is a representation of an on-chain or off-chain asset. The token page shows information such as price, total supply, holders, transfers and social links. Learn more about this page in our Knowledge Base.