Source Code
Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
TokenTracker
Latest 1 internal transaction
Advanced mode:
| Parent Transaction Hash | Method | Block |
From
|
|
To
|
||
|---|---|---|---|---|---|---|---|
| 0x6102a060 | 15398483 | 1291 days ago | Contract Creation | 0 ETH |
Loading...
Loading
Loading...
Loading
Cross-Chain Transactions
Loading...
Loading
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";
// SECURITY - A governance address can freeze trading and deposits but has no access to user funds
// and cannot stop withdraws.
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, this is the total fees collected by LPs on all trades.
// These will be 18 point not token decimal encoded
uint120 public feesUnderlying;
uint120 public feesBond;
// A bool to indicate if the contract is paused, stored with 'fees bond'
bool public paused;
// The fees which have been allocated to pay governance, a percent of LP fees on trades
// Since we don't have access to transfer they must be stored so governance can collect them later
uint128 public governanceFeesUnderlying;
uint128 public governanceFeesBond;
// A mapping of who can pause
mapping(address => bool) public pausers;
// 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;
// State saying if the contract is paused
/// @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
/// @param _pauser An address that can pause trades and deposits
constructor(
IERC20 _underlying,
IERC20 _bond,
uint256 _expiration,
uint256 _unitSeconds,
IVault vault,
uint256 _percentFee,
uint256 _percentFeeGov,
address _governance,
string memory name,
string memory symbol,
address _pauser
) 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;
}
// Set that the _pauser can pause
pausers[_pauser] = true;
// 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 notPaused 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 no fee is collected on join only when they are paid to governance
/// @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
notPaused
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"
);
require(
recipient != governance,
"Governance address LP would be locked"
);
// We must normalize the inputs to 18 point
_normalizeSortedArray(currentBalances);
_normalizeSortedArray(maxAmountsIn);
// This (1) removes governance fees and balancer fees which are collected but not paid
// from the current balances (2) adds any to be collected gov fees to state (3) calculates
// the fees to be paid to balancer on this call.
dueProtocolFeeAmounts = _feeAccounting(
currentBalances,
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 The address which is the source of the LP token
// @param recipient Unused by this pool but in interface
/// @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 uint256 which is the number of LP tokens the user wants to
/// withdraw
/// @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 sender,
address,
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 lpOut = abi.decode(userData, (uint256));
// We have to convert to 18 decimals
_normalizeSortedArray(currentBalances);
// This (1) removes governance fees and balancer fees which are collected but not paid
// from the current balances (2) adds any to be collected gov fees to state (3) calculates
// the fees to be paid to balancer on this call.
dueProtocolFeeAmounts = _feeAccounting(
currentBalances,
protocolSwapFee
);
// If governance is withdrawing they can get all of the fees
if (sender == governance) {
// Init the array
amountsOut = new uint256[](2);
// Governance withdraws the fees which have been paid to them
amountsOut[baseIndex] = uint256(governanceFeesUnderlying);
amountsOut[bondIndex] = uint256(governanceFeesBond);
// We now have to zero the governance fees
governanceFeesUnderlying = 0;
governanceFeesBond = 0;
} else {
// Calculate the user's proportion of the reserves
amountsOut = _burnLP(lpOut, currentBalances, sender);
}
// 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);
}
// Permission-ed functions
/// @notice checks for a pause on trading and depositing functionality
modifier notPaused() {
require(!paused, "Paused");
_;
}
/// @notice Allows an authorized address or the owner to pause this contract
/// @param pauseStatus true for paused, false for not paused
/// @dev the caller must be authorized
function pause(bool pauseStatus) external {
require(pausers[msg.sender], "Sender not Authorized");
paused = pauseStatus;
}
/// @notice Governance sets someone's pause status
/// @param who The address
/// @param status true for able to pause false for not
function setPauser(address who, bool status) external {
require(msg.sender == governance, "Sender not Owner");
pausers[who] = status;
}
// 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 += uint120(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 += uint120(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 += uint120(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 += uint120(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 a number of LP tokens and returns the amount of the pool which they own.
/// @param lpOut The minimum output in underlying
/// @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 lpOut,
uint256[] memory currentBalances,
address source
) internal returns (uint256[] memory amountsReleased) {
// Load the number of LP token
uint256 localTotalSupply = totalSupply();
// Burn the LP tokens from the user
_burnPoolTokens(source, lpOut);
// Initialize the memory array with length 2
amountsReleased = new uint256[](2);
// They get a percent ratio of the pool, div down will cause a very small
// rounding error loss.
amountsReleased[baseIndex] = (currentBalances[baseIndex].mulDown(lpOut))
.divDown(localTotalSupply);
amountsReleased[bondIndex] = (currentBalances[bondIndex].mulDown(lpOut))
.divDown(localTotalSupply);
}
/// @dev Calculates 1 - t
/// @return Returns 1 - t, encoded as a fraction in 18 decimal fixed point
function _getYieldExponent() internal view virtual 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");
}
/// @notice Mutates the input current balances array to remove fees paid to governance and balancer
/// Also resets the LP storage and realizes governance fees, returns the fees which are paid
/// to balancer
/// @param currentBalances The overall balances
/// @param balancerFee The percent of LP fees that balancer takes as a fee
/// @return dueProtocolFees The fees which will be paid to balancer on this join or exit
/// @dev WARNING - Solidity will implicitly cast a 'uint256[] calldata' to 'uint256[] memory' on function calls, but
/// since calldata is immutable mutations made in this call are discarded in future references to the
/// variable in other functions. 'currentBalances' must STRICTLY be of type uint256[] memory for this
/// function to work.
function _feeAccounting(
uint256[] memory currentBalances,
uint256 balancerFee
) internal returns (uint256[] memory dueProtocolFees) {
// Load the total fees
uint256 localFeeUnderlying = uint256(feesUnderlying);
uint256 localFeeBond = uint256(feesBond);
dueProtocolFees = new uint256[](2);
// Calculate the balancer fee [this also implicitly returns this data]
dueProtocolFees[baseIndex] = localFeeUnderlying.mulDown(balancerFee);
dueProtocolFees[bondIndex] = localFeeBond.mulDown(balancerFee);
// Calculate the governance fee from total LP
uint256 govFeeBase = localFeeUnderlying.mulDown(percentFeeGov);
uint256 govFeeBond = localFeeBond.mulDown(percentFeeGov);
// Add the fees collected by gov to the stored ones
governanceFeesUnderlying += uint128(govFeeBase);
governanceFeesBond += uint128(govFeeBond);
// We subtract the amounts which are paid as fee but have not been collected.
// This leaves LPs with the deposits plus their amount of fees
currentBalances[baseIndex] = currentBalances[baseIndex]
.sub(dueProtocolFees[baseIndex])
.sub(governanceFeesUnderlying);
currentBalances[bondIndex] = currentBalances[bondIndex]
.sub(dueProtocolFees[bondIndex])
.sub(governanceFeesBond);
// Since all fees have been accounted for we reset the LP fees collected to zero
feesUnderlying = uint120(0);
feesBond = uint120(0);
}
/// @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",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"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"},{"internalType":"address","name":"_pauser","type":"address"}],"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":"uint120","name":"","type":"uint120"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feesUnderlying","outputs":[{"internalType":"uint120","name":"","type":"uint120"}],"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":[],"name":"governanceFeesBond","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"governanceFeesUnderlying","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"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":"sender","type":"address"},{"internalType":"address","name":"","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":[{"internalType":"bool","name":"pauseStatus","type":"bool"}],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"pausers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","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":"address","name":"who","type":"address"},{"internalType":"bool","name":"status","type":"bool"}],"name":"setPauser","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
6102a06040527f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c960e0523480156200003657600080fd5b50604051620046073803806200460783398101604081905262000059916200069a565b6040805180820190915260018152603160f81b602080830191825285519086019081206080529151902060a0527f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60c052835184918491620000be9160039162000520565b508051620000d490600490602084019062000520565b50505087428a0310620000e657600080fd5b6040516309b2760f60e01b81526000906001600160a01b038916906309b2760f9062000118906002906004016200085a565b602060405180830381600087803b1580156200013357600080fd5b505af115801562000148573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200016e919062000681565b6040805160028082526060808301845293945090916020830190803683370190505090508b6001600160a01b03168d6001600160a01b0316101562000211578c81600081518110620001bc57fe5b60200260200101906001600160a01b031690816001600160a01b0316815250508b81600181518110620001eb57fe5b60200260200101906001600160a01b031690816001600160a01b03168152505062000270565b8b816000815181106200022057fe5b60200260200101906001600160a01b031690816001600160a01b0316815250508c816001815181106200024f57fe5b60200260200101906001600160a01b031690816001600160a01b0316815250505b6001600160a01b03838116600090815260086020908152604091829020805460ff1916600117905581516002808252606082018452938d16936366a9c7d2938793879392919083019080368337019050506040518463ffffffff1660e01b8152600401620002e193929190620007be565b600060405180830381600087803b158015620002fc57600080fd5b505af115801562000311573d6000803e3d6000fd5b5050506001600160601b031960608b901b166101c052506101e0829052610220889052670429d069189e00008710620003675760405162461bcd60e51b81526004016200035e906200086f565b60405180910390fd5b6102408790526001600160601b031960608e901b16610100526040805163313ce56760e01b815290516001600160a01b038f169163313ce567916004808301926020929190829003018186803b158015620003c157600080fd5b505afa158015620003d6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620003fc919062000794565b60f81b6001600160f81b0319166101205260608c901b6001600160601b031916610140526040805163313ce56760e01b815290516001600160a01b038e169163313ce567916004808301926020929190829003018186803b1580156200046157600080fd5b505afa15801562000476573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200049c919062000794565b60f81b6001600160f81b031916610160526101808b90526101a08a9052606086901b6001600160601b031916610200526001600160a01b038c8116908e161080620004e9576001620004ec565b60005b60ff1661026052806200050157600062000504565b60015b60ff166102805250620008a19c50505050505050505050505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200056357805160ff191683800117855562000593565b8280016001018555821562000593579182015b828111156200059357825182559160200191906001019062000576565b50620005a1929150620005a5565b5090565b5b80821115620005a15760008155600101620005a6565b80516001600160a01b0381168114620005d457600080fd5b92915050565b600082601f830112620005eb578081fd5b81516001600160401b038082111562000602578283fd5b6040516020601f8401601f191682018101838111838210171562000624578586fd5b806040525081945083825286818588010111156200064157600080fd5b600092505b8383101562000665578583018101518284018201529182019162000646565b83831115620006775760008185840101525b5050505092915050565b60006020828403121562000693578081fd5b5051919050565b60008060008060008060008060008060006101608c8e031215620006bc578687fd5b620006c88d8d620005bc565b9a50620006d98d60208e01620005bc565b995060408c0151985060608c01519750620006f88d60808e01620005bc565b965060a08c0151955060c08c01519450620007178d60e08e01620005bc565b6101008d01519094506001600160401b0381111562000734578384fd5b620007428e828f01620005da565b6101208e015190945090506001600160401b0381111562000761578283fd5b6200076f8e828f01620005da565b925050620007828d6101408e01620005bc565b90509295989b509295989b9093969950565b600060208284031215620007a6578081fd5b815160ff81168114620007b7578182fd5b9392505050565b60006060820185835260206060818501528186518084526080860191508288019350845b818110156200080a57620007f7855162000895565b83529383019391830191600101620007e2565b505084810360408601528551808252908201925081860190845b818110156200084c5762000839835162000895565b8552938301939183019160010162000824565b509298975050505050505050565b60208101600383106200086957fe5b91905290565b6020808252600c908201526b08ccaca40e8dede40d0d2ced60a31b604082015260600190565b6001600160a01b031690565b60805160a05160c05160e0516101005160601c6101205160f81c6101405160601c6101605160f81c610180516101a0516101c05160601c6101e0516102005160601c61022051610240516102605161028051613b6b62000a9c60003980610b2f52806111d3528061158e52806115ea52806116bf52806118b252806118e652806119125280611a445280611a705280611b4a52806123e752806124a9528061253d52806130e1525080610ac7528061119f52806114f75280611553528061167e52806117c852806117fb528061184352806119bc5280611a045280611ab35280611b0f52806123ad5280612468528061250452806130ad52508061077f52806116fb52806117295250806107c752806120635250806107eb528061091c5280610a53528061112b52508061075b52806109ef52806110ae5250806109b05280610c7e5280610d72528061106f52508061126e5280611c0e5250806107a35280611ba85280611bd752508061129252806115c15280611b7f5280611e98528061230152508061083a5280611e5a5280611f175280611f66528061201a528061215152806122c15250806106eb528061152a5280611ae85280611e2b528061229b5250806108b85280611ded5280611edb5280611fa2528061225b525080610ee85250806114425250806114845250806114635250613b6b6000f3fe608060405234801561001057600080fd5b50600436106102925760003560e01c80636f8f69b7116101605780639d2c110c116100d8578063dd62ed3e1161008c578063f1cd96ba11610071578063f1cd96ba146104c6578063f46c39e7146104ce578063f7b94283146104e357610292565b8063dd62ed3e146104ab578063eaee3f3b146104be57610292565b8063d505accf116100bd578063d505accf14610472578063d5c096c414610485578063d73dd6231461049857610292565b80639d2c110c1461044c578063a9059cbb1461045f57610292565b8063791550501161012f57806380f51c121161011457806380f51c12146104295780638d928af81461043c57806395d89b411461044457610292565b806379155050146104035780637ecebe001461041657610292565b80636f8f69b7146103b457806370a08231146103bc5780637180c8ca146103cf57806374f3b009146103e257610292565b8063386ade671161020e5780635aa6e675116101c257806364c9ec6f116101a757806364c9ec6f1461039157806366188463146103995780636f307dc3146103ac57610292565b80635aa6e675146103745780635c975abb1461038957610292565b806341bd436a116101f357806341bd436a1461035c5780634665096d146103645780634c1a41151461036c57610292565b8063386ade671461033f57806338fff2d01461035457610292565b806323b872dd1161026557806329e4f3621161024a57806329e4f36214610327578063313ce5671461032f5780633644e5151461033757610292565b806323b872dd146102ff57806325a760c21461031257610292565b806302329a291461029757806306fdde03146102ac578063095ea7b3146102ca57806318160ddd146102ea575b600080fd5b6102aa6102a536600461347e565b6104eb565b005b6102b4610577565b6040516102c19190613803565b60405180910390f35b6102dd6102d8366004613420565b61062b565b6040516102c19190613771565b6102f2610642565b6040516102c1919061377c565b6102dd61030d366004613336565b610648565b61031a6106e9565b6040516102c19190613ae8565b6102f261070d565b61031a610719565b6102f261071e565b61034761072d565b6040516102c19190613acb565b6102f2610759565b6102f261077d565b6102f26107a1565b6102f26107c5565b61037c6107e9565b6040516102c1919061372f565b6102dd61080d565b61037c610838565b6102dd6103a7366004613420565b61085c565b61037c6108b6565b6103476108da565b6102f26103ca3660046132e2565b6108f2565b6102aa6103dd3660046133eb565b610911565b6103f56103f0366004613499565b6109a2565b6040516102c1929190613743565b6102f2610411366004613680565b610b9b565b6102f26104243660046132e2565b610c4c565b6102dd6104373660046132e2565b610c67565b61037c610c7c565b6102b4610ca0565b6102f261045a36600461356c565b610d1f565b6102dd61046d366004613420565b610ea6565b6102aa610480366004613376565b610eb3565b6103f5610493366004613499565b61101a565b6102dd6104a6366004613420565b61120b565b6102f26104b93660046132fe565b611241565b6102f261126c565b61031a611290565b6104d66112b4565b6040516102c19190613aaf565b6104d66112de565b3360009081526008602052604090205460ff166105235760405162461bcd60e51b815260040161051a90613976565b60405180910390fd5b600680549115157e01000000000000000000000000000000000000000000000000000000000000027fff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff909216919091179055565b60038054604080516020601f60027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156106215780601f106105f657610100808354040283529160200191610621565b820191906000526020600020905b81548152906001019060200180831161060457829003601f168201915b5050505050905090565b60006106383384846112f5565b5060015b92915050565b60025490565b6001600160a01b0383166000818152600160209081526040808320338085529252822054919261068691148061067e5750838210155b61019761135d565b61069185858561136f565b336001600160a01b038616148015906106ca57507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8114155b156106dc576106dc85338584036112f5565b60019150505b9392505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b670429d069189e000081565b601290565b600061072861143e565b905090565b60075470010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff1681565b7f000000000000000000000000000000000000000000000000000000000000000090565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b6006547e01000000000000000000000000000000000000000000000000000000000000900460ff1681565b7f000000000000000000000000000000000000000000000000000000000000000081565b3360009081526001602090815260408083206001600160a01b038616845290915281205480831061089857610893338560006112f5565b6108ac565b6108ac33856108a784876114db565b6112f5565b5060019392505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b6007546fffffffffffffffffffffffffffffffff1681565b6001600160a01b0381166000908152602081905260409020545b919050565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146109595760405162461bcd60e51b815260040161051a906138e2565b6001600160a01b0391909116600090815260086020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016911515919091179055565b606080336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146109ed5760405162461bcd60e51b815260040161051a90613874565b7f00000000000000000000000000000000000000000000000000000000000000008a14610a2c5760405162461bcd60e51b815260040161051a906139e4565b6000610a3a84860186613668565b9050610a45886114f1565b610a4f8887611622565b91507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168a6001600160a01b03161415610b6d576040805160028082526060820183529091602083019080368337505060075482519295506fffffffffffffffffffffffffffffffff16918591507f0000000000000000000000000000000000000000000000000000000000000000908110610aef57fe5b602002602001018181525050600760109054906101000a90046fffffffffffffffffffffffffffffffff166fffffffffffffffffffffffffffffffff16837f000000000000000000000000000000000000000000000000000000000000000081518110610b5857fe5b60209081029190910101526000600755610b7b565b610b7881898c611979565b92505b610b8483611aad565b610b8d82611aad565b509850989650505050505050565b600080610ba6611ba3565b90506000610bb48683611c5b565b90506000610bc28684611c5b565b9050600085610be357610bde610bd8898b6114db565b85611c5b565b610bef565b610bef89890185611c5b565b90506000610bff848401836114db565b9050610c1c81610c17670de0b6b3a764000088611d98565b611c5b565b905086610c3257610c2d81896114db565b610c3c565b610c3c88826114db565b955050505050505b949350505050565b6001600160a01b031660009081526005602052604090205490565b60086020526000908152604090205460ff1681565b7f000000000000000000000000000000000000000000000000000000000000000090565b60048054604080516020601f60027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156106215780601f106105f657610100808354040283529160200191610621565b6006546000907e01000000000000000000000000000000000000000000000000000000000000900460ff1615610d675760405162461bcd60e51b815260040161051a906138ab565b336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614610daf5760405162461bcd60e51b815260040161051a90613874565b6000808086516001811115610dc057fe5b1490508015610de257610ddb86606001518760200151611de9565b9150610df7565b610df486606001518760400151611de9565b91505b610e05858760200151611de9565b9450610e15848760400151611de9565b9350600080610e2e878960200151888b60400151611ed6565b915091508215610e75576000610e4685848487610b9b565b9050610e5985828b604001516000612010565b9050610e69818a60400151612257565b955050505050506106e2565b6000610e8385838587610b9b565b9050610e9681868b604001516001612010565b9050610e69818a60200151612257565b600061063833848461136f565b610ec18442111560d161135d565b6001600160a01b0387166000908152600560209081526040808320549051909291610f18917f0000000000000000000000000000000000000000000000000000000000000000918c918c918c9188918d9101613785565b6040516020818303038152906040528051906020012090506000610f3b82612325565b9050600060018288888860405160008152602001604052604051610f6294939291906137e5565b6020604051602081039080840390855afa158015610f84573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe001519150610fe490506001600160a01b03821615801590610fdc57508b6001600160a01b0316826001600160a01b0316145b6101f861135d565b6001600160a01b038b16600090815260056020526040902060018501905561100d8b8b8b6112f5565b5050505050505050505050565b60065460609081907e01000000000000000000000000000000000000000000000000000000000000900460ff16156110645760405162461bcd60e51b815260040161051a906138ab565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146110ac5760405162461bcd60e51b815260040161051a90613874565b7f00000000000000000000000000000000000000000000000000000000000000008a146110eb5760405162461bcd60e51b815260040161051a906139e4565b60606110f98486018661344b565b90508751600214801561110d575080516002145b6111295760405162461bcd60e51b815260040161051a906139ad565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316896001600160a01b0316141561117b5760405162461bcd60e51b815260040161051a90613a52565b611184886114f1565b61118d816114f1565b6111978887611622565b9150610b78817f0000000000000000000000000000000000000000000000000000000000000000815181106111c857fe5b6020026020010151827f0000000000000000000000000000000000000000000000000000000000000000815181106111fc57fe5b60200260200101518a8c61235e565b3360008181526001602090815260408083206001600160a01b038716845290915281205490916106389185906108a79086612581565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b6006546f0100000000000000000000000000000090046effffffffffffffffffffffffffffff1681565b6006546effffffffffffffffffffffffffffff1681565b6001600160a01b0380841660008181526001602090815260408083209487168084529490915290819020849055517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259061135090859061377c565b60405180910390a3505050565b8161136b5761136b81612593565b5050565b6001600160a01b0383166000908152602081905260409020546113978282101561019661135d565b6113ae6001600160a01b038416151561019961135d565b6001600160a01b038085166000908152602081905260408082208585039055918516815220546113de9083612581565b6001600160a01b0380851660008181526020819052604090819020939093559151908616907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9061143090869061377c565b60405180910390a350505050565b60007f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000006114ab6125e6565b306040516020016114c09594939291906137b9565b60405160208183030381529060405280519060200120905090565b60006114eb83831115600161135d565b50900390565b611550817f00000000000000000000000000000000000000000000000000000000000000008151811061152057fe5b60200260200101517f000000000000000000000000000000000000000000000000000000000000000060126125ea565b817f00000000000000000000000000000000000000000000000000000000000000008151811061157c57fe5b6020026020010181815250506115e7817f0000000000000000000000000000000000000000000000000000000000000000815181106115b757fe5b60200260200101517f000000000000000000000000000000000000000000000000000000000000000060126125ea565b817f00000000000000000000000000000000000000000000000000000000000000008151811061161357fe5b60200260200101818152505050565b60065460408051600280825260608083018452936effffffffffffffffffffffffffffff808216946f010000000000000000000000000000009092041692919060208301908036833701905050925061167b8285612637565b837f0000000000000000000000000000000000000000000000000000000000000000815181106116a757fe5b60209081029190910101526116bc8185612637565b837f0000000000000000000000000000000000000000000000000000000000000000815181106116e857fe5b6020908102919091010152600061171f837f0000000000000000000000000000000000000000000000000000000000000000612637565b9050600061174d837f0000000000000000000000000000000000000000000000000000000000000000612637565b600780547fffffffffffffffffffffffffffffffff0000000000000000000000000000000081166fffffffffffffffffffffffffffffffff918216860182161780821670010000000000000000000000000000000091829004831685018316909102179182905587519293506118409291169061183a9088907f00000000000000000000000000000000000000000000000000000000000000009081106117f057fe5b60200260200101518a7f00000000000000000000000000000000000000000000000000000000000000008151811061182457fe5b60200260200101516114db90919063ffffffff16565b906114db565b877f00000000000000000000000000000000000000000000000000000000000000008151811061186c57fe5b60200260200101818152505061190f600760109054906101000a90046fffffffffffffffffffffffffffffffff166fffffffffffffffffffffffffffffffff1661183a877f0000000000000000000000000000000000000000000000000000000000000000815181106118db57fe5b60200260200101518a7f00000000000000000000000000000000000000000000000000000000000000008151811061182457fe5b877f00000000000000000000000000000000000000000000000000000000000000008151811061193b57fe5b60209081029190910101525050600680547fffff00000000000000000000000000000000000000000000000000000000000016905550909392505050565b60606000611985610642565b9050611991838661266d565b6040805160028082526060820183529091602083019080368337019050509150611a01816119fb87877f0000000000000000000000000000000000000000000000000000000000000000815181106119e557fe5b602002602001015161263790919063ffffffff16565b90611d98565b827f000000000000000000000000000000000000000000000000000000000000000081518110611a2d57fe5b602002602001018181525050611a6d816119fb87877f0000000000000000000000000000000000000000000000000000000000000000815181106119e557fe5b827f000000000000000000000000000000000000000000000000000000000000000081518110611a9957fe5b602002602001018181525050509392505050565b611b0c817f000000000000000000000000000000000000000000000000000000000000000081518110611adc57fe5b602002602001015160127f00000000000000000000000000000000000000000000000000000000000000006125ea565b817f000000000000000000000000000000000000000000000000000000000000000081518110611b3857fe5b6020026020010181815250506115e7817f000000000000000000000000000000000000000000000000000000000000000081518110611b7357fe5b602002602001015160127f00000000000000000000000000000000000000000000000000000000000000006125ea565b6000807f00000000000000000000000000000000000000000000000000000000000000004210611bd4576000611bf8565b427f0000000000000000000000000000000000000000000000000000000000000000035b670de0b6b3a76400009081029150611c339082907f000000000000000000000000000000000000000000000000000000000000000002611d98565b90506000611c49670de0b6b3a7640000836114db565b905080611c5557600080fd5b91505090565b600081611c715750670de0b6b3a764000061063c565b82611c7e5750600061063c565b611cab7f80000000000000000000000000000000000000000000000000000000000000008410600661135d565b82611cd1770bce5086492111aea88f4bb1ca6bcf584181ea8059f765328410600761135d565b826000670c7d713b49da000083138015611cf25750670f43fc2c04ee000083125b15611d29576000611d0284612700565b9050670de0b6b3a764000080820784020583670de0b6b3a764000083050201915050611d37565b81611d3384612837565b0290505b670de0b6b3a76400009005611d857ffffffffffffffffffffffffffffffffffffffffffffffffdc702bd3a30fc00008212801590611d7e575068070c1cc73b00c800008213155b600861135d565b611d8e81612bd7565b9695505050505050565b6000611da7821515600461135d565b82611db45750600061063c565b670de0b6b3a764000083810290611dd790858381611dce57fe5b0414600561135d565b828181611de057fe5b0491505061063c565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b03161415611e5857611e51837f000000000000000000000000000000000000000000000000000000000000000060126125ea565b905061063c565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b03161415611ebe57611e51837f000000000000000000000000000000000000000000000000000000000000000060126125ea565b60405162461bcd60e51b815260040161051a90613a1b565b6000807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316856001600160a01b0316148015611f4b57507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b0316145b15611f645785611f59610642565b850191509150612007565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316856001600160a01b0316148015611fd657507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b0316145b15611fef57611fe3610642565b86018491509150612007565b60405162461bcd60e51b815260040161051a90613919565b94509492505050565b6000811561214f577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b031614156120dd57600061208861206186886114db565b7f000000000000000000000000000000000000000000000000000000000000000090612637565b600680546effffffffffffffffffffffffffffff8082168401167fffffffffffffffffffffffffffffffffff00000000000000000000000000000090911617905590506120d58682612581565b915050610c44565b60006120ec61206187876114db565b600680546effffffffffffffffffffffffffffff6f0100000000000000000000000000000080830482168501909116027fffff000000000000000000000000000000ffffffffffffffffffffffffffffff90911617905590506120d58682612581565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b031614156121fb57600061219861206186886114db565b600680546effffffffffffffffffffffffffffff6f0100000000000000000000000000000080830482168501909116027fffff000000000000000000000000000000ffffffffffffffffffffffffffffff90911617905590506120d585826114db565b600061220a61206187876114db565b600680546effffffffffffffffffffffffffffff8082168401167fffffffffffffffffffffffffffffffffff00000000000000000000000000000090911617905590506120d585826114db565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b031614156122bf57611e518360127f00000000000000000000000000000000000000000000000000000000000000006125ea565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b03161415611ebe57611e518360127f00000000000000000000000000000000000000000000000000000000000000006125ea565b600061232f61143e565b826040516020016123419291906136f9565b604051602081830303815290604052805190602001209050919050565b604080516002808252606080830184529260208301908036833701905050905060008061238a856130a7565b915091506000612398610642565b905080612424576123a9858961311b565b87847f0000000000000000000000000000000000000000000000000000000000000000815181106123d657fe5b6020026020010181815250506000847f00000000000000000000000000000000000000000000000000000000000000008151811061241057fe5b602002602001018181525050505050610c44565b60006124308484611d98565b9050600061243e828a612637565b9050898111156124e4576000612458866119fb8d87612637565b9050612464888261311b565b8a877f00000000000000000000000000000000000000000000000000000000000000008151811061249157fe5b60209081029190910101526124a68b84611d98565b877f0000000000000000000000000000000000000000000000000000000000000000815181106124d257fe5b60200260200101818152505050612574565b60006124f4866119fb8487612637565b9050612500888261311b565b81877f00000000000000000000000000000000000000000000000000000000000000008151811061252d57fe5b60200260200101818152505089877f00000000000000000000000000000000000000000000000000000000000000008151811061256657fe5b602002602001018181525050505b5050505050949350505050565b60008282016106e2848210158361135d565b62461bcd60e51b6000908152602060045260076024526642414c23000030600a808404818106603090810160081b95839006959095019082900491820690940160101b939093010160c81b604452606490fd5b4690565b60008160ff168360ff1611156126135781830360ff16600a0a848161260b57fe5b04935061262f565b8160ff168360ff16101561262f5782820360ff16600a0a840293505b509192915050565b600082820261265b84158061265457508385838161265157fe5b04145b600361135d565b670de0b6b3a764000090049392505050565b6001600160a01b0382166000908152602081905260409020546126958282101561019661135d565b6001600160a01b038316600090815260208190526040902082820390556002546126bf90836114db565b6002556040516000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9061135090869061377c565b670de0b6b3a7640000026000806ec097ce7bc90715b34b9f1000000000808401907fffffffffffffffffffffffffffffffffff3f68318436f8ea4cb460f0000000008501028161274c57fe5b05905060006ec097ce7bc90715b34b9f100000000082800205905081806ec097ce7bc90715b34b9f100000000081840205915060038205016ec097ce7bc90715b34b9f100000000082840205915060058205016ec097ce7bc90715b34b9f100000000082840205915060078205016ec097ce7bc90715b34b9f100000000082840205915060098205016ec097ce7bc90715b34b9f1000000000828402059150600b8205016ec097ce7bc90715b34b9f1000000000828402059150600d8205016ec097ce7bc90715b34b9f1000000000828402059150600f826002919005919091010295945050505050565b6000670de0b6b3a76400008212156128745761286a826ec097ce7bc90715b34b9f10000000008161286457fe5b05612837565b600003905061090c565b60007e1600ef3172e58d2e933ec884fde10064c63b5372d805e203c000000000000083126128c557770195e54c5dd42177f53a27172fa9ec630262827000000000830592506806f05b59d3b2000000015b73011798004d755d3c8bc8e03204cf44619e00000083126128fd576b1425982cf597cd205cef7380830592506803782dace9d9000000015b606492830292026e01855144814a7ff805980ff00840008312612945576e01855144814a7ff805980ff008400068056bc75e2d63100000840205925068ad78ebc5ac62000000015b6b02df0ab5a80a22c61ab5a7008312612980576b02df0ab5a80a22c61ab5a70068056bc75e2d6310000084020592506856bc75e2d631000000015b693f1fce3da636ea5cf85083126129b757693f1fce3da636ea5cf85068056bc75e2d631000008402059250682b5e3af16b18800000015b690127fa27722cc06cc5e283126129ee57690127fa27722cc06cc5e268056bc75e2d6310000084020592506815af1d78b58c400000015b68280e60114edb805d038312612a235768280e60114edb805d0368056bc75e2d631000008402059250680ad78ebc5ac6200000015b680ebc5fb417461211108312612a4e57680ebc5fb4174612111068056bc75e2d631000009384020592015b6808f00f760a4b2db55d8312612a83576808f00f760a4b2db55d68056bc75e2d6310000084020592506802b5e3af16b1880000015b6806f5f17757889379378312612ab8576806f5f177578893793768056bc75e2d63100000840205925068015af1d78b58c40000015b6806248f33704b2866038312612aec576806248f33704b28660368056bc75e2d63100000840205925067ad78ebc5ac620000015b6805c548670b9510e7ac8312612b20576805c548670b9510e7ac68056bc75e2d6310000084020592506756bc75e2d6310000015b600068056bc75e2d63100000840168056bc75e2d631000008086030281612b4357fe5b059050600068056bc75e2d63100000828002059050818068056bc75e2d63100000818402059150600382050168056bc75e2d63100000828402059150600582050168056bc75e2d63100000828402059150600782050168056bc75e2d63100000828402059150600982050168056bc75e2d63100000828402059150600b820501600202606485820105979650505050505050565b6000612c1c7ffffffffffffffffffffffffffffffffffffffffffffffffdc702bd3a30fc00008312158015612c15575068070c1cc73b00c800008313155b600961135d565b6000821215612c5057612c3182600003612bd7565b6ec097ce7bc90715b34b9f100000000081612c4857fe5b05905061090c565b60006806f05b59d3b20000008312612ca657507ffffffffffffffffffffffffffffffffffffffffffffffff90fa4a62c4e00000090910190770195e54c5dd42177f53a27172fa9ec630262827000000000612cf2565b6803782dace9d90000008312612cee57507ffffffffffffffffffffffffffffffffffffffffffffffffc87d2531627000000909101906b1425982cf597cd205cef7380612cf2565b5060015b6064929092029168056bc75e2d6310000068ad78ebc5ac620000008412612d58577fffffffffffffffffffffffffffffffffffffffffffffff5287143a539e0000009093019268056bc75e2d631000006e01855144814a7ff805980ff008400082020590505b6856bc75e2d6310000008412612daa577fffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf0000009093019268056bc75e2d631000006b02df0ab5a80a22c61ab5a70082020590505b682b5e3af16b188000008412612dfa577fffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e78000009093019268056bc75e2d63100000693f1fce3da636ea5cf85082020590505b6815af1d78b58c4000008412612e4a577fffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c000009093019268056bc75e2d63100000690127fa27722cc06cc5e282020590505b680ad78ebc5ac62000008412612e99577ffffffffffffffffffffffffffffffffffffffffffffffff5287143a539e000009093019268056bc75e2d6310000068280e60114edb805d0382020590505b68056bc75e2d631000008412612ee8577ffffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf000009093019268056bc75e2d63100000680ebc5fb4174612111082020590505b6802b5e3af16b18800008412612f37577ffffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e7800009093019268056bc75e2d631000006808f00f760a4b2db55d82020590505b68015af1d78b58c400008412612f86577ffffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c00009093019268056bc75e2d631000006806f5f177578893793782020590505b68056bc75e2d631000008481019085906002908280020505918201919050600368056bc75e2d631000008783020505918201919050600468056bc75e2d631000008783020505918201919050600568056bc75e2d631000008783020505918201919050600668056bc75e2d631000008783020505918201919050600768056bc75e2d631000008783020505918201919050600868056bc75e2d631000008783020505918201919050600968056bc75e2d631000008783020505918201919050600a68056bc75e2d631000008783020505918201919050600b68056bc75e2d631000008783020505918201919050600c68056bc75e2d631000008783020505918201919050606468056bc75e2d63100000848402058502059695505050505050565b600080827f0000000000000000000000000000000000000000000000000000000000000000815181106130d657fe5b6020026020010151837f00000000000000000000000000000000000000000000000000000000000000008151811061310a57fe5b602002602001015191509150915091565b6001600160a01b03821660009081526020819052604090205461313e9082612581565b6001600160a01b0383166000908152602081905260409020556002546131649082612581565b6002556040516001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef906131a590859061377c565b60405180910390a35050565b803561063c81613b1d565b600082601f8301126131cc578081fd5b813567ffffffffffffffff8111156131e2578182fd5b60208082026131f2828201613af6565b8381529350818401858301828701840188101561320e57600080fd5b600092505b84831015613231578035825260019290920191908301908301613213565b505050505092915050565b8035801515811461063c57600080fd5b600082601f83011261325c578081fd5b813567ffffffffffffffff811115613272578182fd5b6132a360207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f84011601613af6565b91508082528360208285010111156132ba57600080fd5b8060208401602084013760009082016020015292915050565b80356002811061063c57600080fd5b6000602082840312156132f3578081fd5b81356106e281613b1d565b60008060408385031215613310578081fd5b823561331b81613b1d565b9150602083013561332b81613b1d565b809150509250929050565b60008060006060848603121561334a578081fd5b833561335581613b1d565b9250602084013561336581613b1d565b929592945050506040919091013590565b600080600080600080600060e0888a031215613390578283fd5b873561339b81613b1d565b965060208801356133ab81613b1d565b95506040880135945060608801359350608088013560ff811681146133ce578384fd5b9699959850939692959460a0840135945060c09093013592915050565b600080604083850312156133fd578182fd5b823561340881613b1d565b9150613417846020850161323c565b90509250929050565b60008060408385031215613432578182fd5b823561343d81613b1d565b946020939093013593505050565b60006020828403121561345c578081fd5b813567ffffffffffffffff811115613472578182fd5b610c44848285016131bc565b60006020828403121561348f578081fd5b6106e2838361323c565b60008060008060008060008060e0898b0312156134b4578081fd5b8835975060208901356134c681613b1d565b965060408901356134d681613b1d565b9550606089013567ffffffffffffffff808211156134f2578283fd5b6134fe8c838d016131bc565b965060808b0135955060a08b0135945060c08b0135915080821115613521578283fd5b818b0191508b601f830112613534578283fd5b813581811115613542578384fd5b8c6020828501011115613553578384fd5b6020830194508093505050509295985092959890939650565b600080600060608486031215613580578081fd5b833567ffffffffffffffff80821115613597578283fd5b81860191506101208083890312156135ad578384fd5b6135b681613af6565b90506135c288846132d3565b81526135d188602085016131b1565b60208201526135e388604085016131b1565b6040820152606083013560608201526080830135608082015260a083013560a08201526136138860c085016131b1565b60c08201526136258860e085016131b1565b60e0820152610100808401358381111561363d578586fd5b6136498a82870161324c565b9183019190915250976020870135975060409096013595945050505050565b600060208284031215613679578081fd5b5035919050565b60008060008060808587031215613695578182fd5b8435935060208501359250604085013591506136b4866060870161323c565b905092959194509250565b6000815180845260208085019450808401835b838110156136ee578151875295820195908201906001016136d2565b509495945050505050565b7f190100000000000000000000000000000000000000000000000000000000000081526002810192909252602282015260420190565b6001600160a01b0391909116815260200190565b60006040825261375660408301856136bf565b828103602084015261376881856136bf565b95945050505050565b901515815260200190565b90815260200190565b9586526001600160a01b0394851660208701529290931660408501526060840152608083019190915260a082015260c00190565b9485526020850193909352604084019190915260608301526001600160a01b0316608082015260a00190565b93845260ff9290921660208401526040830152606082015260800190565b6000602080835283518082850152825b8181101561382f57858101830151858201604001528201613813565b818111156138405783604083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016929092016040019392505050565b60208082526010908201527f4e6f6e205661756c742063616c6c657200000000000000000000000000000000604082015260600190565b60208082526006908201527f5061757365640000000000000000000000000000000000000000000000000000604082015260600190565b60208082526010908201527f53656e646572206e6f74204f776e657200000000000000000000000000000000604082015260600190565b60208082526022908201527f546f6b656e207265717565737420646f65736e2774206d617463682073746f7260408201527f6564000000000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526015908201527f53656e646572206e6f7420417574686f72697a65640000000000000000000000604082015260600190565b6020808252600e908201527f496e76616c696420666f726d6174000000000000000000000000000000000000604082015260600190565b6020808252600d908201527f57726f6e6720706f6f6c20696400000000000000000000000000000000000000604082015260600190565b6020808252601a908201527f43616c6c65642077697468206e6f6e20706f6f6c20746f6b656e000000000000604082015260600190565b60208082526025908201527f476f7665726e616e63652061646472657373204c5020776f756c64206265206c60408201527f6f636b6564000000000000000000000000000000000000000000000000000000606082015260800190565b6effffffffffffffffffffffffffffff91909116815260200190565b6fffffffffffffffffffffffffffffffff91909116815260200190565b60ff91909116815260200190565b60405181810167ffffffffffffffff81118282101715613b1557600080fd5b604052919050565b6001600160a01b0381168114613b3257600080fd5b5056fea264697066735822122062385ba561002c4c3cbe6b7e05f77806788ecb112b0b5cc06387cad05665d1df64736f6c634300070100330000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000009459654777bb2669ad8ad0b54e876d4b5ff77f40000000000000000000000000000000000000000000000000000000063f8b61400000000000000000000000000000000000000000000000000000000bbfba128000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c8000000000000000000000000000000000000000000000000016345785d8a000000000000000000000000000000000000000000000000000002c68af0bb14000000000000000000000000000082ef450fb7f06e3294f2f19ed1713b255af0f541000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000040309f197e7f94b555904df0f788a3f48cf326ab00000000000000000000000000000000000000000000000000000000000000284c5020456c656d656e74205072696e636970616c20546f6b656e2079764441492d3234464542323300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000114c50655079764441492d32344645423233000000000000000000000000000000
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106102925760003560e01c80636f8f69b7116101605780639d2c110c116100d8578063dd62ed3e1161008c578063f1cd96ba11610071578063f1cd96ba146104c6578063f46c39e7146104ce578063f7b94283146104e357610292565b8063dd62ed3e146104ab578063eaee3f3b146104be57610292565b8063d505accf116100bd578063d505accf14610472578063d5c096c414610485578063d73dd6231461049857610292565b80639d2c110c1461044c578063a9059cbb1461045f57610292565b8063791550501161012f57806380f51c121161011457806380f51c12146104295780638d928af81461043c57806395d89b411461044457610292565b806379155050146104035780637ecebe001461041657610292565b80636f8f69b7146103b457806370a08231146103bc5780637180c8ca146103cf57806374f3b009146103e257610292565b8063386ade671161020e5780635aa6e675116101c257806364c9ec6f116101a757806364c9ec6f1461039157806366188463146103995780636f307dc3146103ac57610292565b80635aa6e675146103745780635c975abb1461038957610292565b806341bd436a116101f357806341bd436a1461035c5780634665096d146103645780634c1a41151461036c57610292565b8063386ade671461033f57806338fff2d01461035457610292565b806323b872dd1161026557806329e4f3621161024a57806329e4f36214610327578063313ce5671461032f5780633644e5151461033757610292565b806323b872dd146102ff57806325a760c21461031257610292565b806302329a291461029757806306fdde03146102ac578063095ea7b3146102ca57806318160ddd146102ea575b600080fd5b6102aa6102a536600461347e565b6104eb565b005b6102b4610577565b6040516102c19190613803565b60405180910390f35b6102dd6102d8366004613420565b61062b565b6040516102c19190613771565b6102f2610642565b6040516102c1919061377c565b6102dd61030d366004613336565b610648565b61031a6106e9565b6040516102c19190613ae8565b6102f261070d565b61031a610719565b6102f261071e565b61034761072d565b6040516102c19190613acb565b6102f2610759565b6102f261077d565b6102f26107a1565b6102f26107c5565b61037c6107e9565b6040516102c1919061372f565b6102dd61080d565b61037c610838565b6102dd6103a7366004613420565b61085c565b61037c6108b6565b6103476108da565b6102f26103ca3660046132e2565b6108f2565b6102aa6103dd3660046133eb565b610911565b6103f56103f0366004613499565b6109a2565b6040516102c1929190613743565b6102f2610411366004613680565b610b9b565b6102f26104243660046132e2565b610c4c565b6102dd6104373660046132e2565b610c67565b61037c610c7c565b6102b4610ca0565b6102f261045a36600461356c565b610d1f565b6102dd61046d366004613420565b610ea6565b6102aa610480366004613376565b610eb3565b6103f5610493366004613499565b61101a565b6102dd6104a6366004613420565b61120b565b6102f26104b93660046132fe565b611241565b6102f261126c565b61031a611290565b6104d66112b4565b6040516102c19190613aaf565b6104d66112de565b3360009081526008602052604090205460ff166105235760405162461bcd60e51b815260040161051a90613976565b60405180910390fd5b600680549115157e01000000000000000000000000000000000000000000000000000000000000027fff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff909216919091179055565b60038054604080516020601f60027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156106215780601f106105f657610100808354040283529160200191610621565b820191906000526020600020905b81548152906001019060200180831161060457829003601f168201915b5050505050905090565b60006106383384846112f5565b5060015b92915050565b60025490565b6001600160a01b0383166000818152600160209081526040808320338085529252822054919261068691148061067e5750838210155b61019761135d565b61069185858561136f565b336001600160a01b038616148015906106ca57507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8114155b156106dc576106dc85338584036112f5565b60019150505b9392505050565b7f000000000000000000000000000000000000000000000000000000000000001281565b670429d069189e000081565b601290565b600061072861143e565b905090565b60075470010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff1681565b7f7f4a33dee068c4fa012d64677c61519a578dfa3500020000000000000000034690565b7f00000000000000000000000000000000000000000000000002c68af0bb14000081565b7f0000000000000000000000000000000000000000000000000000000063f8b61481565b7f000000000000000000000000000000000000000000000000016345785d8a000081565b7f00000000000000000000000082ef450fb7f06e3294f2f19ed1713b255af0f54181565b6006547e01000000000000000000000000000000000000000000000000000000000000900460ff1681565b7f00000000000000000000000009459654777bb2669ad8ad0b54e876d4b5ff77f481565b3360009081526001602090815260408083206001600160a01b038616845290915281205480831061089857610893338560006112f5565b6108ac565b6108ac33856108a784876114db565b6112f5565b5060019392505050565b7f0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f81565b6007546fffffffffffffffffffffffffffffffff1681565b6001600160a01b0381166000908152602081905260409020545b919050565b336001600160a01b037f00000000000000000000000082ef450fb7f06e3294f2f19ed1713b255af0f54116146109595760405162461bcd60e51b815260040161051a906138e2565b6001600160a01b0391909116600090815260086020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016911515919091179055565b606080336001600160a01b037f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c816146109ed5760405162461bcd60e51b815260040161051a90613874565b7f7f4a33dee068c4fa012d64677c61519a578dfa350002000000000000000003468a14610a2c5760405162461bcd60e51b815260040161051a906139e4565b6000610a3a84860186613668565b9050610a45886114f1565b610a4f8887611622565b91507f00000000000000000000000082ef450fb7f06e3294f2f19ed1713b255af0f5416001600160a01b03168a6001600160a01b03161415610b6d576040805160028082526060820183529091602083019080368337505060075482519295506fffffffffffffffffffffffffffffffff16918591507f0000000000000000000000000000000000000000000000000000000000000001908110610aef57fe5b602002602001018181525050600760109054906101000a90046fffffffffffffffffffffffffffffffff166fffffffffffffffffffffffffffffffff16837f000000000000000000000000000000000000000000000000000000000000000081518110610b5857fe5b60209081029190910101526000600755610b7b565b610b7881898c611979565b92505b610b8483611aad565b610b8d82611aad565b509850989650505050505050565b600080610ba6611ba3565b90506000610bb48683611c5b565b90506000610bc28684611c5b565b9050600085610be357610bde610bd8898b6114db565b85611c5b565b610bef565b610bef89890185611c5b565b90506000610bff848401836114db565b9050610c1c81610c17670de0b6b3a764000088611d98565b611c5b565b905086610c3257610c2d81896114db565b610c3c565b610c3c88826114db565b955050505050505b949350505050565b6001600160a01b031660009081526005602052604090205490565b60086020526000908152604090205460ff1681565b7f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c890565b60048054604080516020601f60027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156106215780601f106105f657610100808354040283529160200191610621565b6006546000907e01000000000000000000000000000000000000000000000000000000000000900460ff1615610d675760405162461bcd60e51b815260040161051a906138ab565b336001600160a01b037f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c81614610daf5760405162461bcd60e51b815260040161051a90613874565b6000808086516001811115610dc057fe5b1490508015610de257610ddb86606001518760200151611de9565b9150610df7565b610df486606001518760400151611de9565b91505b610e05858760200151611de9565b9450610e15848760400151611de9565b9350600080610e2e878960200151888b60400151611ed6565b915091508215610e75576000610e4685848487610b9b565b9050610e5985828b604001516000612010565b9050610e69818a60400151612257565b955050505050506106e2565b6000610e8385838587610b9b565b9050610e9681868b604001516001612010565b9050610e69818a60200151612257565b600061063833848461136f565b610ec18442111560d161135d565b6001600160a01b0387166000908152600560209081526040808320549051909291610f18917f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9918c918c918c9188918d9101613785565b6040516020818303038152906040528051906020012090506000610f3b82612325565b9050600060018288888860405160008152602001604052604051610f6294939291906137e5565b6020604051602081039080840390855afa158015610f84573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe001519150610fe490506001600160a01b03821615801590610fdc57508b6001600160a01b0316826001600160a01b0316145b6101f861135d565b6001600160a01b038b16600090815260056020526040902060018501905561100d8b8b8b6112f5565b5050505050505050505050565b60065460609081907e01000000000000000000000000000000000000000000000000000000000000900460ff16156110645760405162461bcd60e51b815260040161051a906138ab565b336001600160a01b037f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c816146110ac5760405162461bcd60e51b815260040161051a90613874565b7f7f4a33dee068c4fa012d64677c61519a578dfa350002000000000000000003468a146110eb5760405162461bcd60e51b815260040161051a906139e4565b60606110f98486018661344b565b90508751600214801561110d575080516002145b6111295760405162461bcd60e51b815260040161051a906139ad565b7f00000000000000000000000082ef450fb7f06e3294f2f19ed1713b255af0f5416001600160a01b0316896001600160a01b0316141561117b5760405162461bcd60e51b815260040161051a90613a52565b611184886114f1565b61118d816114f1565b6111978887611622565b9150610b78817f0000000000000000000000000000000000000000000000000000000000000001815181106111c857fe5b6020026020010151827f0000000000000000000000000000000000000000000000000000000000000000815181106111fc57fe5b60200260200101518a8c61235e565b3360008181526001602090815260408083206001600160a01b038716845290915281205490916106389185906108a79086612581565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b7f00000000000000000000000000000000000000000000000000000000bbfba12881565b7f000000000000000000000000000000000000000000000000000000000000001281565b6006546f0100000000000000000000000000000090046effffffffffffffffffffffffffffff1681565b6006546effffffffffffffffffffffffffffff1681565b6001600160a01b0380841660008181526001602090815260408083209487168084529490915290819020849055517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259061135090859061377c565b60405180910390a3505050565b8161136b5761136b81612593565b5050565b6001600160a01b0383166000908152602081905260409020546113978282101561019661135d565b6113ae6001600160a01b038416151561019961135d565b6001600160a01b038085166000908152602081905260408082208585039055918516815220546113de9083612581565b6001600160a01b0380851660008181526020819052604090819020939093559151908616907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9061143090869061377c565b60405180910390a350505050565b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f7fb1853e2c64ed14dad302b024b6fddf1c8e54bed135c05e297f349103c94e744e7fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc66114ab6125e6565b306040516020016114c09594939291906137b9565b60405160208183030381529060405280519060200120905090565b60006114eb83831115600161135d565b50900390565b611550817f00000000000000000000000000000000000000000000000000000000000000018151811061152057fe5b60200260200101517f000000000000000000000000000000000000000000000000000000000000001260126125ea565b817f00000000000000000000000000000000000000000000000000000000000000018151811061157c57fe5b6020026020010181815250506115e7817f0000000000000000000000000000000000000000000000000000000000000000815181106115b757fe5b60200260200101517f000000000000000000000000000000000000000000000000000000000000001260126125ea565b817f00000000000000000000000000000000000000000000000000000000000000008151811061161357fe5b60200260200101818152505050565b60065460408051600280825260608083018452936effffffffffffffffffffffffffffff808216946f010000000000000000000000000000009092041692919060208301908036833701905050925061167b8285612637565b837f0000000000000000000000000000000000000000000000000000000000000001815181106116a757fe5b60209081029190910101526116bc8185612637565b837f0000000000000000000000000000000000000000000000000000000000000000815181106116e857fe5b6020908102919091010152600061171f837f00000000000000000000000000000000000000000000000002c68af0bb140000612637565b9050600061174d837f00000000000000000000000000000000000000000000000002c68af0bb140000612637565b600780547fffffffffffffffffffffffffffffffff0000000000000000000000000000000081166fffffffffffffffffffffffffffffffff918216860182161780821670010000000000000000000000000000000091829004831685018316909102179182905587519293506118409291169061183a9088907f00000000000000000000000000000000000000000000000000000000000000019081106117f057fe5b60200260200101518a7f00000000000000000000000000000000000000000000000000000000000000018151811061182457fe5b60200260200101516114db90919063ffffffff16565b906114db565b877f00000000000000000000000000000000000000000000000000000000000000018151811061186c57fe5b60200260200101818152505061190f600760109054906101000a90046fffffffffffffffffffffffffffffffff166fffffffffffffffffffffffffffffffff1661183a877f0000000000000000000000000000000000000000000000000000000000000000815181106118db57fe5b60200260200101518a7f00000000000000000000000000000000000000000000000000000000000000008151811061182457fe5b877f00000000000000000000000000000000000000000000000000000000000000008151811061193b57fe5b60209081029190910101525050600680547fffff00000000000000000000000000000000000000000000000000000000000016905550909392505050565b60606000611985610642565b9050611991838661266d565b6040805160028082526060820183529091602083019080368337019050509150611a01816119fb87877f0000000000000000000000000000000000000000000000000000000000000001815181106119e557fe5b602002602001015161263790919063ffffffff16565b90611d98565b827f000000000000000000000000000000000000000000000000000000000000000181518110611a2d57fe5b602002602001018181525050611a6d816119fb87877f0000000000000000000000000000000000000000000000000000000000000000815181106119e557fe5b827f000000000000000000000000000000000000000000000000000000000000000081518110611a9957fe5b602002602001018181525050509392505050565b611b0c817f000000000000000000000000000000000000000000000000000000000000000181518110611adc57fe5b602002602001015160127f00000000000000000000000000000000000000000000000000000000000000126125ea565b817f000000000000000000000000000000000000000000000000000000000000000181518110611b3857fe5b6020026020010181815250506115e7817f000000000000000000000000000000000000000000000000000000000000000081518110611b7357fe5b602002602001015160127f00000000000000000000000000000000000000000000000000000000000000126125ea565b6000807f0000000000000000000000000000000000000000000000000000000063f8b6144210611bd4576000611bf8565b427f0000000000000000000000000000000000000000000000000000000063f8b614035b670de0b6b3a76400009081029150611c339082907f00000000000000000000000000000000000000000000000000000000bbfba12802611d98565b90506000611c49670de0b6b3a7640000836114db565b905080611c5557600080fd5b91505090565b600081611c715750670de0b6b3a764000061063c565b82611c7e5750600061063c565b611cab7f80000000000000000000000000000000000000000000000000000000000000008410600661135d565b82611cd1770bce5086492111aea88f4bb1ca6bcf584181ea8059f765328410600761135d565b826000670c7d713b49da000083138015611cf25750670f43fc2c04ee000083125b15611d29576000611d0284612700565b9050670de0b6b3a764000080820784020583670de0b6b3a764000083050201915050611d37565b81611d3384612837565b0290505b670de0b6b3a76400009005611d857ffffffffffffffffffffffffffffffffffffffffffffffffdc702bd3a30fc00008212801590611d7e575068070c1cc73b00c800008213155b600861135d565b611d8e81612bd7565b9695505050505050565b6000611da7821515600461135d565b82611db45750600061063c565b670de0b6b3a764000083810290611dd790858381611dce57fe5b0414600561135d565b828181611de057fe5b0491505061063c565b60007f0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f6001600160a01b0316826001600160a01b03161415611e5857611e51837f000000000000000000000000000000000000000000000000000000000000001260126125ea565b905061063c565b7f00000000000000000000000009459654777bb2669ad8ad0b54e876d4b5ff77f46001600160a01b0316826001600160a01b03161415611ebe57611e51837f000000000000000000000000000000000000000000000000000000000000001260126125ea565b60405162461bcd60e51b815260040161051a90613a1b565b6000807f0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f6001600160a01b0316856001600160a01b0316148015611f4b57507f00000000000000000000000009459654777bb2669ad8ad0b54e876d4b5ff77f46001600160a01b0316836001600160a01b0316145b15611f645785611f59610642565b850191509150612007565b7f00000000000000000000000009459654777bb2669ad8ad0b54e876d4b5ff77f46001600160a01b0316856001600160a01b0316148015611fd657507f0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f6001600160a01b0316836001600160a01b0316145b15611fef57611fe3610642565b86018491509150612007565b60405162461bcd60e51b815260040161051a90613919565b94509492505050565b6000811561214f577f00000000000000000000000009459654777bb2669ad8ad0b54e876d4b5ff77f46001600160a01b0316836001600160a01b031614156120dd57600061208861206186886114db565b7f000000000000000000000000000000000000000000000000016345785d8a000090612637565b600680546effffffffffffffffffffffffffffff8082168401167fffffffffffffffffffffffffffffffffff00000000000000000000000000000090911617905590506120d58682612581565b915050610c44565b60006120ec61206187876114db565b600680546effffffffffffffffffffffffffffff6f0100000000000000000000000000000080830482168501909116027fffff000000000000000000000000000000ffffffffffffffffffffffffffffff90911617905590506120d58682612581565b7f00000000000000000000000009459654777bb2669ad8ad0b54e876d4b5ff77f46001600160a01b0316836001600160a01b031614156121fb57600061219861206186886114db565b600680546effffffffffffffffffffffffffffff6f0100000000000000000000000000000080830482168501909116027fffff000000000000000000000000000000ffffffffffffffffffffffffffffff90911617905590506120d585826114db565b600061220a61206187876114db565b600680546effffffffffffffffffffffffffffff8082168401167fffffffffffffffffffffffffffffffffff00000000000000000000000000000090911617905590506120d585826114db565b60007f0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f6001600160a01b0316826001600160a01b031614156122bf57611e518360127f00000000000000000000000000000000000000000000000000000000000000126125ea565b7f00000000000000000000000009459654777bb2669ad8ad0b54e876d4b5ff77f46001600160a01b0316826001600160a01b03161415611ebe57611e518360127f00000000000000000000000000000000000000000000000000000000000000126125ea565b600061232f61143e565b826040516020016123419291906136f9565b604051602081830303815290604052805190602001209050919050565b604080516002808252606080830184529260208301908036833701905050905060008061238a856130a7565b915091506000612398610642565b905080612424576123a9858961311b565b87847f0000000000000000000000000000000000000000000000000000000000000001815181106123d657fe5b6020026020010181815250506000847f00000000000000000000000000000000000000000000000000000000000000008151811061241057fe5b602002602001018181525050505050610c44565b60006124308484611d98565b9050600061243e828a612637565b9050898111156124e4576000612458866119fb8d87612637565b9050612464888261311b565b8a877f00000000000000000000000000000000000000000000000000000000000000018151811061249157fe5b60209081029190910101526124a68b84611d98565b877f0000000000000000000000000000000000000000000000000000000000000000815181106124d257fe5b60200260200101818152505050612574565b60006124f4866119fb8487612637565b9050612500888261311b565b81877f00000000000000000000000000000000000000000000000000000000000000018151811061252d57fe5b60200260200101818152505089877f00000000000000000000000000000000000000000000000000000000000000008151811061256657fe5b602002602001018181525050505b5050505050949350505050565b60008282016106e2848210158361135d565b62461bcd60e51b6000908152602060045260076024526642414c23000030600a808404818106603090810160081b95839006959095019082900491820690940160101b939093010160c81b604452606490fd5b4690565b60008160ff168360ff1611156126135781830360ff16600a0a848161260b57fe5b04935061262f565b8160ff168360ff16101561262f5782820360ff16600a0a840293505b509192915050565b600082820261265b84158061265457508385838161265157fe5b04145b600361135d565b670de0b6b3a764000090049392505050565b6001600160a01b0382166000908152602081905260409020546126958282101561019661135d565b6001600160a01b038316600090815260208190526040902082820390556002546126bf90836114db565b6002556040516000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9061135090869061377c565b670de0b6b3a7640000026000806ec097ce7bc90715b34b9f1000000000808401907fffffffffffffffffffffffffffffffffff3f68318436f8ea4cb460f0000000008501028161274c57fe5b05905060006ec097ce7bc90715b34b9f100000000082800205905081806ec097ce7bc90715b34b9f100000000081840205915060038205016ec097ce7bc90715b34b9f100000000082840205915060058205016ec097ce7bc90715b34b9f100000000082840205915060078205016ec097ce7bc90715b34b9f100000000082840205915060098205016ec097ce7bc90715b34b9f1000000000828402059150600b8205016ec097ce7bc90715b34b9f1000000000828402059150600d8205016ec097ce7bc90715b34b9f1000000000828402059150600f826002919005919091010295945050505050565b6000670de0b6b3a76400008212156128745761286a826ec097ce7bc90715b34b9f10000000008161286457fe5b05612837565b600003905061090c565b60007e1600ef3172e58d2e933ec884fde10064c63b5372d805e203c000000000000083126128c557770195e54c5dd42177f53a27172fa9ec630262827000000000830592506806f05b59d3b2000000015b73011798004d755d3c8bc8e03204cf44619e00000083126128fd576b1425982cf597cd205cef7380830592506803782dace9d9000000015b606492830292026e01855144814a7ff805980ff00840008312612945576e01855144814a7ff805980ff008400068056bc75e2d63100000840205925068ad78ebc5ac62000000015b6b02df0ab5a80a22c61ab5a7008312612980576b02df0ab5a80a22c61ab5a70068056bc75e2d6310000084020592506856bc75e2d631000000015b693f1fce3da636ea5cf85083126129b757693f1fce3da636ea5cf85068056bc75e2d631000008402059250682b5e3af16b18800000015b690127fa27722cc06cc5e283126129ee57690127fa27722cc06cc5e268056bc75e2d6310000084020592506815af1d78b58c400000015b68280e60114edb805d038312612a235768280e60114edb805d0368056bc75e2d631000008402059250680ad78ebc5ac6200000015b680ebc5fb417461211108312612a4e57680ebc5fb4174612111068056bc75e2d631000009384020592015b6808f00f760a4b2db55d8312612a83576808f00f760a4b2db55d68056bc75e2d6310000084020592506802b5e3af16b1880000015b6806f5f17757889379378312612ab8576806f5f177578893793768056bc75e2d63100000840205925068015af1d78b58c40000015b6806248f33704b2866038312612aec576806248f33704b28660368056bc75e2d63100000840205925067ad78ebc5ac620000015b6805c548670b9510e7ac8312612b20576805c548670b9510e7ac68056bc75e2d6310000084020592506756bc75e2d6310000015b600068056bc75e2d63100000840168056bc75e2d631000008086030281612b4357fe5b059050600068056bc75e2d63100000828002059050818068056bc75e2d63100000818402059150600382050168056bc75e2d63100000828402059150600582050168056bc75e2d63100000828402059150600782050168056bc75e2d63100000828402059150600982050168056bc75e2d63100000828402059150600b820501600202606485820105979650505050505050565b6000612c1c7ffffffffffffffffffffffffffffffffffffffffffffffffdc702bd3a30fc00008312158015612c15575068070c1cc73b00c800008313155b600961135d565b6000821215612c5057612c3182600003612bd7565b6ec097ce7bc90715b34b9f100000000081612c4857fe5b05905061090c565b60006806f05b59d3b20000008312612ca657507ffffffffffffffffffffffffffffffffffffffffffffffff90fa4a62c4e00000090910190770195e54c5dd42177f53a27172fa9ec630262827000000000612cf2565b6803782dace9d90000008312612cee57507ffffffffffffffffffffffffffffffffffffffffffffffffc87d2531627000000909101906b1425982cf597cd205cef7380612cf2565b5060015b6064929092029168056bc75e2d6310000068ad78ebc5ac620000008412612d58577fffffffffffffffffffffffffffffffffffffffffffffff5287143a539e0000009093019268056bc75e2d631000006e01855144814a7ff805980ff008400082020590505b6856bc75e2d6310000008412612daa577fffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf0000009093019268056bc75e2d631000006b02df0ab5a80a22c61ab5a70082020590505b682b5e3af16b188000008412612dfa577fffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e78000009093019268056bc75e2d63100000693f1fce3da636ea5cf85082020590505b6815af1d78b58c4000008412612e4a577fffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c000009093019268056bc75e2d63100000690127fa27722cc06cc5e282020590505b680ad78ebc5ac62000008412612e99577ffffffffffffffffffffffffffffffffffffffffffffffff5287143a539e000009093019268056bc75e2d6310000068280e60114edb805d0382020590505b68056bc75e2d631000008412612ee8577ffffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf000009093019268056bc75e2d63100000680ebc5fb4174612111082020590505b6802b5e3af16b18800008412612f37577ffffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e7800009093019268056bc75e2d631000006808f00f760a4b2db55d82020590505b68015af1d78b58c400008412612f86577ffffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c00009093019268056bc75e2d631000006806f5f177578893793782020590505b68056bc75e2d631000008481019085906002908280020505918201919050600368056bc75e2d631000008783020505918201919050600468056bc75e2d631000008783020505918201919050600568056bc75e2d631000008783020505918201919050600668056bc75e2d631000008783020505918201919050600768056bc75e2d631000008783020505918201919050600868056bc75e2d631000008783020505918201919050600968056bc75e2d631000008783020505918201919050600a68056bc75e2d631000008783020505918201919050600b68056bc75e2d631000008783020505918201919050600c68056bc75e2d631000008783020505918201919050606468056bc75e2d63100000848402058502059695505050505050565b600080827f0000000000000000000000000000000000000000000000000000000000000001815181106130d657fe5b6020026020010151837f00000000000000000000000000000000000000000000000000000000000000008151811061310a57fe5b602002602001015191509150915091565b6001600160a01b03821660009081526020819052604090205461313e9082612581565b6001600160a01b0383166000908152602081905260409020556002546131649082612581565b6002556040516001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef906131a590859061377c565b60405180910390a35050565b803561063c81613b1d565b600082601f8301126131cc578081fd5b813567ffffffffffffffff8111156131e2578182fd5b60208082026131f2828201613af6565b8381529350818401858301828701840188101561320e57600080fd5b600092505b84831015613231578035825260019290920191908301908301613213565b505050505092915050565b8035801515811461063c57600080fd5b600082601f83011261325c578081fd5b813567ffffffffffffffff811115613272578182fd5b6132a360207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f84011601613af6565b91508082528360208285010111156132ba57600080fd5b8060208401602084013760009082016020015292915050565b80356002811061063c57600080fd5b6000602082840312156132f3578081fd5b81356106e281613b1d565b60008060408385031215613310578081fd5b823561331b81613b1d565b9150602083013561332b81613b1d565b809150509250929050565b60008060006060848603121561334a578081fd5b833561335581613b1d565b9250602084013561336581613b1d565b929592945050506040919091013590565b600080600080600080600060e0888a031215613390578283fd5b873561339b81613b1d565b965060208801356133ab81613b1d565b95506040880135945060608801359350608088013560ff811681146133ce578384fd5b9699959850939692959460a0840135945060c09093013592915050565b600080604083850312156133fd578182fd5b823561340881613b1d565b9150613417846020850161323c565b90509250929050565b60008060408385031215613432578182fd5b823561343d81613b1d565b946020939093013593505050565b60006020828403121561345c578081fd5b813567ffffffffffffffff811115613472578182fd5b610c44848285016131bc565b60006020828403121561348f578081fd5b6106e2838361323c565b60008060008060008060008060e0898b0312156134b4578081fd5b8835975060208901356134c681613b1d565b965060408901356134d681613b1d565b9550606089013567ffffffffffffffff808211156134f2578283fd5b6134fe8c838d016131bc565b965060808b0135955060a08b0135945060c08b0135915080821115613521578283fd5b818b0191508b601f830112613534578283fd5b813581811115613542578384fd5b8c6020828501011115613553578384fd5b6020830194508093505050509295985092959890939650565b600080600060608486031215613580578081fd5b833567ffffffffffffffff80821115613597578283fd5b81860191506101208083890312156135ad578384fd5b6135b681613af6565b90506135c288846132d3565b81526135d188602085016131b1565b60208201526135e388604085016131b1565b6040820152606083013560608201526080830135608082015260a083013560a08201526136138860c085016131b1565b60c08201526136258860e085016131b1565b60e0820152610100808401358381111561363d578586fd5b6136498a82870161324c565b9183019190915250976020870135975060409096013595945050505050565b600060208284031215613679578081fd5b5035919050565b60008060008060808587031215613695578182fd5b8435935060208501359250604085013591506136b4866060870161323c565b905092959194509250565b6000815180845260208085019450808401835b838110156136ee578151875295820195908201906001016136d2565b509495945050505050565b7f190100000000000000000000000000000000000000000000000000000000000081526002810192909252602282015260420190565b6001600160a01b0391909116815260200190565b60006040825261375660408301856136bf565b828103602084015261376881856136bf565b95945050505050565b901515815260200190565b90815260200190565b9586526001600160a01b0394851660208701529290931660408501526060840152608083019190915260a082015260c00190565b9485526020850193909352604084019190915260608301526001600160a01b0316608082015260a00190565b93845260ff9290921660208401526040830152606082015260800190565b6000602080835283518082850152825b8181101561382f57858101830151858201604001528201613813565b818111156138405783604083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016929092016040019392505050565b60208082526010908201527f4e6f6e205661756c742063616c6c657200000000000000000000000000000000604082015260600190565b60208082526006908201527f5061757365640000000000000000000000000000000000000000000000000000604082015260600190565b60208082526010908201527f53656e646572206e6f74204f776e657200000000000000000000000000000000604082015260600190565b60208082526022908201527f546f6b656e207265717565737420646f65736e2774206d617463682073746f7260408201527f6564000000000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526015908201527f53656e646572206e6f7420417574686f72697a65640000000000000000000000604082015260600190565b6020808252600e908201527f496e76616c696420666f726d6174000000000000000000000000000000000000604082015260600190565b6020808252600d908201527f57726f6e6720706f6f6c20696400000000000000000000000000000000000000604082015260600190565b6020808252601a908201527f43616c6c65642077697468206e6f6e20706f6f6c20746f6b656e000000000000604082015260600190565b60208082526025908201527f476f7665726e616e63652061646472657373204c5020776f756c64206265206c60408201527f6f636b6564000000000000000000000000000000000000000000000000000000606082015260800190565b6effffffffffffffffffffffffffffff91909116815260200190565b6fffffffffffffffffffffffffffffffff91909116815260200190565b60ff91909116815260200190565b60405181810167ffffffffffffffff81118282101715613b1557600080fd5b604052919050565b6001600160a01b0381168114613b3257600080fd5b5056fea264697066735822122062385ba561002c4c3cbe6b7e05f77806788ecb112b0b5cc06387cad05665d1df64736f6c63430007010033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000009459654777bb2669ad8ad0b54e876d4b5ff77f40000000000000000000000000000000000000000000000000000000063f8b61400000000000000000000000000000000000000000000000000000000bbfba128000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c8000000000000000000000000000000000000000000000000016345785d8a000000000000000000000000000000000000000000000000000002c68af0bb14000000000000000000000000000082ef450fb7f06e3294f2f19ed1713b255af0f541000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000040309f197e7f94b555904df0f788a3f48cf326ab00000000000000000000000000000000000000000000000000000000000000284c5020456c656d656e74205072696e636970616c20546f6b656e2079764441492d3234464542323300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000114c50655079764441492d32344645423233000000000000000000000000000000
-----Decoded View---------------
Arg [0] : _underlying (address): 0x6B175474E89094C44Da98b954EedeAC495271d0F
Arg [1] : _bond (address): 0x09459654777Bb2669AD8aD0b54E876D4b5Ff77F4
Arg [2] : _expiration (uint256): 1677243924
Arg [3] : _unitSeconds (uint256): 3153830184
Arg [4] : vault (address): 0xBA12222222228d8Ba445958a75a0704d566BF2C8
Arg [5] : _percentFee (uint256): 100000000000000000
Arg [6] : _percentFeeGov (uint256): 200000000000000000
Arg [7] : _governance (address): 0x82eF450FB7f06E3294F2f19ed1713b255Af0f541
Arg [8] : name (string): LP Element Principal Token yvDAI-24FEB23
Arg [9] : symbol (string): LPePyvDAI-24FEB23
Arg [10] : _pauser (address): 0x40309f197e7f94B555904DF0f788a3F48cF326aB
-----Encoded View---------------
16 Constructor Arguments found :
Arg [0] : 0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f
Arg [1] : 00000000000000000000000009459654777bb2669ad8ad0b54e876d4b5ff77f4
Arg [2] : 0000000000000000000000000000000000000000000000000000000063f8b614
Arg [3] : 00000000000000000000000000000000000000000000000000000000bbfba128
Arg [4] : 000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c8
Arg [5] : 000000000000000000000000000000000000000000000000016345785d8a0000
Arg [6] : 00000000000000000000000000000000000000000000000002c68af0bb140000
Arg [7] : 00000000000000000000000082ef450fb7f06e3294f2f19ed1713b255af0f541
Arg [8] : 0000000000000000000000000000000000000000000000000000000000000160
Arg [9] : 00000000000000000000000000000000000000000000000000000000000001c0
Arg [10] : 00000000000000000000000040309f197e7f94b555904df0f788a3f48cf326ab
Arg [11] : 0000000000000000000000000000000000000000000000000000000000000028
Arg [12] : 4c5020456c656d656e74205072696e636970616c20546f6b656e207976444149
Arg [13] : 2d32344645423233000000000000000000000000000000000000000000000000
Arg [14] : 0000000000000000000000000000000000000000000000000000000000000011
Arg [15] : 4c50655079764441492d32344645423233000000000000000000000000000000
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 33 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.