Feature Tip: Add private address tag to any address under My Name Tag !
More Info
Private Name Tags
ContractCreator
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
0xc6cf648fb4db7bfe691f4c3ce9aafeb86f9569a4389a19055728aad584552c37 | Claim Tokens | (pending) | 51 mins ago | IN | 0 ETH | (Pending) | |||
Claim Tokens | 21643312 | 3 days ago | IN | 0 ETH | 0.0013284 | ||||
Claim Tokens | 21642171 | 3 days ago | IN | 0 ETH | 0.00107366 | ||||
Claim Token | 21635558 | 4 days ago | IN | 0 ETH | 0.00126548 | ||||
Claim Tokens | 21632803 | 5 days ago | IN | 0 ETH | 0.00693552 | ||||
Claim Tokens | 21612473 | 8 days ago | IN | 0 ETH | 0.00184645 | ||||
Claim Tokens | 21608293 | 8 days ago | IN | 0 ETH | 0.000262 | ||||
Claim Tokens | 21607547 | 8 days ago | IN | 0 ETH | 0.00137711 | ||||
Claim Tokens | 21606208 | 8 days ago | IN | 0 ETH | 0.00172091 | ||||
Claim Tokens | 21596211 | 10 days ago | IN | 0 ETH | 0.00276273 | ||||
Claim Tokens | 21593455 | 10 days ago | IN | 0 ETH | 0.00290584 | ||||
Claim Tokens | 21593442 | 10 days ago | IN | 0 ETH | 0.00366127 | ||||
Claim Tokens | 21593424 | 10 days ago | IN | 0 ETH | 0.00943247 | ||||
Claim Tokens | 21593377 | 10 days ago | IN | 0 ETH | 0.00113521 | ||||
Claim Tokens | 21592431 | 10 days ago | IN | 0 ETH | 0.00090757 | ||||
Claim Token | 21591320 | 11 days ago | IN | 0 ETH | 0.00061385 | ||||
Claim Tokens | 21591268 | 11 days ago | IN | 0 ETH | 0.00115478 | ||||
Claim Tokens | 21590784 | 11 days ago | IN | 0 ETH | 0.00248837 | ||||
Claim Token | 21590328 | 11 days ago | IN | 0 ETH | 0.00040566 | ||||
Claim Token | 21590277 | 11 days ago | IN | 0 ETH | 0.00308616 | ||||
Claim Tokens | 21587053 | 11 days ago | IN | 0 ETH | 0.00282141 | ||||
Claim Tokens | 21585004 | 11 days ago | IN | 0 ETH | 0.00179254 | ||||
Claim Tokens | 21572568 | 13 days ago | IN | 0 ETH | 0.00391175 | ||||
Claim Tokens | 21570364 | 13 days ago | IN | 0 ETH | 0.00133484 | ||||
Claim Tokens | 21552255 | 16 days ago | IN | 0 ETH | 0.01191934 |
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Contract Name:
FeeDistributor
Compiler Version
v0.7.1+commit.f4a555be
Optimization Enabled:
Yes with 9999 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// 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 "@balancer-labs/v2-interfaces/contracts/solidity-utils/helpers/IAuthentication.sol"; import "@balancer-labs/v2-interfaces/contracts/liquidity-mining/IFeeDistributor.sol"; import "@balancer-labs/v2-interfaces/contracts/liquidity-mining/IVotingEscrow.sol"; import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/ReentrancyGuard.sol"; import "@balancer-labs/v2-solidity-utils/contracts/helpers/OptionalOnlyCaller.sol"; import "@balancer-labs/v2-solidity-utils/contracts/helpers/InputHelpers.sol"; import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/SafeERC20.sol"; import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/SafeMath.sol"; import "@balancer-labs/v2-solidity-utils/contracts/math/Math.sol"; // solhint-disable not-rely-on-time /** * @title Fee Distributor * @notice Distributes any tokens transferred to the contract (e.g. Protocol fees and any BAL emissions) among veBAL * holders proportionally based on a snapshot of the week at which the tokens are sent to the FeeDistributor contract. * @dev Supports distributing arbitrarily many different tokens. In order to start distributing a new token to veBAL * holders simply transfer the tokens to the `FeeDistributor` contract and then call `checkpointToken`. */ contract FeeDistributor is IFeeDistributor, OptionalOnlyCaller, ReentrancyGuard { using SafeMath for uint256; using SafeERC20 for IERC20; IVotingEscrow private immutable _votingEscrow; uint256 private immutable _startTime; // Global State uint256 private _timeCursor; mapping(uint256 => uint256) private _veSupplyCache; // Token State // `startTime` and `timeCursor` are both timestamps so comfortably fit in a uint64. // `cachedBalance` will comfortably fit the total supply of any meaningful token. // Should more than 2^128 tokens be sent to this contract then checkpointing this token will fail until enough // tokens have been claimed to bring the total balance back below 2^128. struct TokenState { uint64 startTime; uint64 timeCursor; uint128 cachedBalance; } mapping(IERC20 => TokenState) private _tokenState; mapping(IERC20 => mapping(uint256 => uint256)) private _tokensPerWeek; // User State // `startTime` and `timeCursor` are timestamps so will comfortably fit in a uint64. // For `lastEpochCheckpointed` to overflow would need over 2^128 transactions to the VotingEscrow contract. struct UserState { uint64 startTime; uint64 timeCursor; uint128 lastEpochCheckpointed; } mapping(address => UserState) internal _userState; mapping(address => mapping(uint256 => uint256)) private _userBalanceAtTimestamp; mapping(address => mapping(IERC20 => uint256)) private _userTokenTimeCursor; constructor(IVotingEscrow votingEscrow, uint256 startTime) EIP712("FeeDistributor", "1") { _votingEscrow = votingEscrow; startTime = _roundDownTimestamp(startTime); uint256 currentWeek = _roundDownTimestamp(block.timestamp); require(startTime >= currentWeek, "Cannot start before current week"); if (startTime == currentWeek) { // We assume that `votingEscrow` has been deployed in a week previous to this one. // If `votingEscrow` did not have a non-zero supply at the beginning of the current week // then any tokens which are distributed this week will be lost permanently. require(votingEscrow.totalSupply(currentWeek) > 0, "Zero total supply results in lost tokens"); } _startTime = startTime; _timeCursor = startTime; } /** * @notice Returns the VotingEscrow (veBAL) token contract */ function getVotingEscrow() external view override returns (IVotingEscrow) { return _votingEscrow; } /** * @notice Returns the global time cursor representing the most earliest uncheckpointed week. */ function getTimeCursor() external view override returns (uint256) { return _timeCursor; } /** * @notice Returns the user-level time cursor representing the most earliest uncheckpointed week. * @param user - The address of the user to query. */ function getUserTimeCursor(address user) external view override returns (uint256) { return _userState[user].timeCursor; } /** * @notice Returns the token-level time cursor storing the timestamp at up to which tokens have been distributed. * @param token - The ERC20 token address to query. */ function getTokenTimeCursor(IERC20 token) external view override returns (uint256) { return _tokenState[token].timeCursor; } /** * @notice Returns the user-level time cursor storing the timestamp of the latest token distribution claimed. * @param user - The address of the user to query. * @param token - The ERC20 token address to query. */ function getUserTokenTimeCursor(address user, IERC20 token) external view override returns (uint256) { return _getUserTokenTimeCursor(user, token); } /** * @notice Returns the user's cached balance of veBAL as of the provided timestamp. * @dev Only timestamps which fall on Thursdays 00:00:00 UTC will return correct values. * This function requires `user` to have been checkpointed past `timestamp` so that their balance is cached. * @param user - The address of the user of which to read the cached balance of. * @param timestamp - The timestamp at which to read the `user`'s cached balance at. */ function getUserBalanceAtTimestamp(address user, uint256 timestamp) external view override returns (uint256) { return _userBalanceAtTimestamp[user][timestamp]; } /** * @notice Returns the cached total supply of veBAL as of the provided timestamp. * @dev Only timestamps which fall on Thursdays 00:00:00 UTC will return correct values. * This function requires the contract to have been checkpointed past `timestamp` so that the supply is cached. * @param timestamp - The timestamp at which to read the cached total supply at. */ function getTotalSupplyAtTimestamp(uint256 timestamp) external view override returns (uint256) { return _veSupplyCache[timestamp]; } /** * @notice Returns the FeeDistributor's cached balance of `token`. */ function getTokenLastBalance(IERC20 token) external view override returns (uint256) { return _tokenState[token].cachedBalance; } /** * @notice Returns the amount of `token` which the FeeDistributor received in the week beginning at `timestamp`. * @param token - The ERC20 token address to query. * @param timestamp - The timestamp corresponding to the beginning of the week of interest. */ function getTokensDistributedInWeek(IERC20 token, uint256 timestamp) external view override returns (uint256) { return _tokensPerWeek[token][timestamp]; } // Depositing /** * @notice Deposits tokens to be distributed in the current week. * @dev Sending tokens directly to the FeeDistributor instead of using `depositToken` may result in tokens being * retroactively distributed to past weeks, or for the distribution to carry over to future weeks. * * If for some reason `depositToken` cannot be called, in order to ensure that all tokens are correctly distributed * manually call `checkpointToken` before and after the token transfer. * @param token - The ERC20 token address to distribute. * @param amount - The amount of tokens to deposit. */ function depositToken(IERC20 token, uint256 amount) external override nonReentrant { _checkpointToken(token, false); token.safeTransferFrom(msg.sender, address(this), amount); _checkpointToken(token, true); } /** * @notice Deposits tokens to be distributed in the current week. * @dev A version of `depositToken` which supports depositing multiple `tokens` at once. * See `depositToken` for more details. * @param tokens - An array of ERC20 token addresses to distribute. * @param amounts - An array of token amounts to deposit. */ function depositTokens(IERC20[] calldata tokens, uint256[] calldata amounts) external override nonReentrant { InputHelpers.ensureInputLengthMatch(tokens.length, amounts.length); uint256 length = tokens.length; for (uint256 i = 0; i < length; ++i) { _checkpointToken(tokens[i], false); tokens[i].safeTransferFrom(msg.sender, address(this), amounts[i]); _checkpointToken(tokens[i], true); } } // Checkpointing /** * @notice Caches the total supply of veBAL at the beginning of each week. * This function will be called automatically before claiming tokens to ensure the contract is properly updated. */ function checkpoint() external override nonReentrant { _checkpointTotalSupply(); } /** * @notice Caches the user's balance of veBAL at the beginning of each week. * This function will be called automatically before claiming tokens to ensure the contract is properly updated. * @param user - The address of the user to be checkpointed. */ function checkpointUser(address user) external override nonReentrant { _checkpointUserBalance(user); } /** * @notice Assigns any newly-received tokens held by the FeeDistributor to weekly distributions. * @dev Any `token` balance held by the FeeDistributor above that which is returned by `getTokenLastBalance` * will be distributed evenly across the time period since `token` was last checkpointed. * * This function will be called automatically before claiming tokens to ensure the contract is properly updated. * @param token - The ERC20 token address to be checkpointed. */ function checkpointToken(IERC20 token) external override nonReentrant { _checkpointToken(token, true); } /** * @notice Assigns any newly-received tokens held by the FeeDistributor to weekly distributions. * @dev A version of `checkpointToken` which supports checkpointing multiple tokens. * See `checkpointToken` for more details. * @param tokens - An array of ERC20 token addresses to be checkpointed. */ function checkpointTokens(IERC20[] calldata tokens) external override nonReentrant { uint256 tokensLength = tokens.length; for (uint256 i = 0; i < tokensLength; ++i) { _checkpointToken(tokens[i], true); } } // Claiming /** * @notice Claims all pending distributions of the provided token for a user. * @dev It's not necessary to explicitly checkpoint before calling this function, it will ensure the FeeDistributor * is up to date before calculating the amount of tokens to be claimed. * @param user - The user on behalf of which to claim. * @param token - The ERC20 token address to be claimed. * @return The amount of `token` sent to `user` as a result of claiming. */ function claimToken(address user, IERC20 token) external override nonReentrant optionalOnlyCaller(user) returns (uint256) { _checkpointTotalSupply(); _checkpointUserBalance(user); _checkpointToken(token, false); uint256 amount = _claimToken(user, token); return amount; } /** * @notice Claims a number of tokens on behalf of a user. * @dev A version of `claimToken` which supports claiming multiple `tokens` on behalf of `user`. * See `claimToken` for more details. * @param user - The user on behalf of which to claim. * @param tokens - An array of ERC20 token addresses to be claimed. * @return An array of the amounts of each token in `tokens` sent to `user` as a result of claiming. */ function claimTokens(address user, IERC20[] calldata tokens) external override nonReentrant optionalOnlyCaller(user) returns (uint256[] memory) { _checkpointTotalSupply(); _checkpointUserBalance(user); uint256 tokensLength = tokens.length; uint256[] memory amounts = new uint256[](tokensLength); for (uint256 i = 0; i < tokensLength; ++i) { _checkpointToken(tokens[i], false); amounts[i] = _claimToken(user, tokens[i]); } return amounts; } // Internal functions /** * @dev It is required that both the global, token and user state have been properly checkpointed * before calling this function. */ function _claimToken(address user, IERC20 token) internal returns (uint256) { TokenState storage tokenState = _tokenState[token]; uint256 nextUserTokenWeekToClaim = _getUserTokenTimeCursor(user, token); // The first week which cannot be correctly claimed is the earliest of: // - A) The global or user time cursor (whichever is earliest), rounded up to the end of the week. // - B) The token time cursor, rounded down to the beginning of the week. // // This prevents the two failure modes: // - A) A user may claim a week for which we have not processed their balance, resulting in tokens being locked. // - B) A user may claim a week which then receives more tokens to be distributed. However the user has // already claimed for that week so their share of these new tokens are lost. uint256 firstUnclaimableWeek = Math.min( _roundUpTimestamp(Math.min(_timeCursor, _userState[user].timeCursor)), _roundDownTimestamp(tokenState.timeCursor) ); mapping(uint256 => uint256) storage tokensPerWeek = _tokensPerWeek[token]; mapping(uint256 => uint256) storage userBalanceAtTimestamp = _userBalanceAtTimestamp[user]; uint256 amount; for (uint256 i = 0; i < 20; ++i) { // We clearly cannot claim for `firstUnclaimableWeek` and so we break here. if (nextUserTokenWeekToClaim >= firstUnclaimableWeek) break; amount += (tokensPerWeek[nextUserTokenWeekToClaim] * userBalanceAtTimestamp[nextUserTokenWeekToClaim]) / _veSupplyCache[nextUserTokenWeekToClaim]; nextUserTokenWeekToClaim += 1 weeks; } // Update the stored user-token time cursor to prevent this user claiming this week again. _userTokenTimeCursor[user][token] = nextUserTokenWeekToClaim; if (amount > 0) { // For a token to be claimable it must have been added to the cached balance so this is safe. tokenState.cachedBalance = uint128(tokenState.cachedBalance - amount); token.safeTransfer(user, amount); emit TokensClaimed(user, token, amount, nextUserTokenWeekToClaim); } return amount; } /** * @dev Calculate the amount of `token` to be distributed to `_votingEscrow` holders since the last checkpoint. */ function _checkpointToken(IERC20 token, bool force) internal { TokenState storage tokenState = _tokenState[token]; uint256 lastTokenTime = tokenState.timeCursor; uint256 timeSinceLastCheckpoint; if (lastTokenTime == 0) { // If it's the first time we're checkpointing this token then start distributing from now. // Also mark at which timestamp users should start attempts to claim this token from. lastTokenTime = block.timestamp; tokenState.startTime = uint64(_roundDownTimestamp(block.timestamp)); // Prevent someone from assigning tokens to an inaccessible week. require(block.timestamp > _startTime, "Fee distribution has not started yet"); } else { timeSinceLastCheckpoint = block.timestamp - lastTokenTime; if (!force) { // Checkpointing N times within a single week is completely equivalent to checkpointing once at the end. // We then want to get as close as possible to a single checkpoint every Wed 23:59 UTC to save gas. // We then skip checkpointing if we're in the same week as the previous checkpoint. bool alreadyCheckpointedThisWeek = _roundDownTimestamp(block.timestamp) == _roundDownTimestamp(lastTokenTime); // However we want to ensure that all of this week's fees are assigned to the current week without // overspilling into the next week. To mitigate this, we checkpoint if we're near the end of the week. bool nearingEndOfWeek = _roundUpTimestamp(block.timestamp) - block.timestamp < 1 days; // This ensures that we checkpoint once at the beginning of the week and again for each user interaction // towards the end of the week to give an accurate final reading of the balance. if (alreadyCheckpointedThisWeek && !nearingEndOfWeek) { return; } } } tokenState.timeCursor = uint64(block.timestamp); uint256 tokenBalance = token.balanceOf(address(this)); uint256 newTokensToDistribute = tokenBalance.sub(tokenState.cachedBalance); if (newTokensToDistribute == 0) return; require(tokenBalance <= type(uint128).max, "Maximum token balance exceeded"); tokenState.cachedBalance = uint128(tokenBalance); uint256 firstIncompleteWeek = _roundDownTimestamp(lastTokenTime); uint256 nextWeek = 0; // Distribute `newTokensToDistribute` evenly across the time period from `lastTokenTime` to now. // These tokens are assigned to weeks proportionally to how much of this period falls into each week. mapping(uint256 => uint256) storage tokensPerWeek = _tokensPerWeek[token]; for (uint256 i = 0; i < 20; ++i) { // This is safe as we're incrementing a timestamp. nextWeek = firstIncompleteWeek + 1 weeks; if (block.timestamp < nextWeek) { // `firstIncompleteWeek` is now the beginning of the current week, i.e. this is the final iteration. if (timeSinceLastCheckpoint == 0 && block.timestamp == lastTokenTime) { tokensPerWeek[firstIncompleteWeek] += newTokensToDistribute; } else { // block.timestamp >= lastTokenTime by definition. tokensPerWeek[firstIncompleteWeek] += (newTokensToDistribute * (block.timestamp - lastTokenTime)) / timeSinceLastCheckpoint; } // As we've caught up to the present then we should now break. break; } else { // We've gone a full week or more without checkpointing so need to distribute tokens to previous weeks. if (timeSinceLastCheckpoint == 0 && nextWeek == lastTokenTime) { // It shouldn't be possible to enter this block tokensPerWeek[firstIncompleteWeek] += newTokensToDistribute; } else { // nextWeek > lastTokenTime by definition. tokensPerWeek[firstIncompleteWeek] += (newTokensToDistribute * (nextWeek - lastTokenTime)) / timeSinceLastCheckpoint; } } // We've now "checkpointed" up to the beginning of next week so must update timestamps appropriately. lastTokenTime = nextWeek; firstIncompleteWeek = nextWeek; } emit TokenCheckpointed(token, newTokensToDistribute, lastTokenTime); } /** * @dev Cache the `user`'s balance of `_votingEscrow` at the beginning of each new week */ function _checkpointUserBalance(address user) internal { uint256 maxUserEpoch = _votingEscrow.user_point_epoch(user); // If user has no epochs then they have never locked veBAL. // They clearly will not then receive fees. if (maxUserEpoch == 0) return; UserState storage userState = _userState[user]; // `nextWeekToCheckpoint` represents the timestamp of the beginning of the first week // which we haven't checkpointed the user's VotingEscrow balance yet. uint256 nextWeekToCheckpoint = userState.timeCursor; uint256 userEpoch; if (nextWeekToCheckpoint == 0) { // First checkpoint for user so need to do the initial binary search userEpoch = _findTimestampUserEpoch(user, _startTime, 0, maxUserEpoch); } else { if (nextWeekToCheckpoint >= block.timestamp) { // User has checkpointed the current week already so perform early return. // This prevents a user from processing epochs created later in this week, however this is not an issue // as if a significant number of these builds up then the user will skip past them with a binary search. return; } // Otherwise use the value saved from last time userEpoch = userState.lastEpochCheckpointed; // This optimizes a scenario common for power users, which have frequent `VotingEscrow` interactions in // the same week. We assume that any such user is also claiming fees every week, and so we only perform // a binary search here rather than integrating it into the main search algorithm, effectively skipping // most of the week's irrelevant checkpoints. // The slight tradeoff is that users who have multiple infrequent `VotingEscrow` interactions and also don't // claim frequently will also perform the binary search, despite it not leading to gas savings. if (maxUserEpoch - userEpoch > 20) { userEpoch = _findTimestampUserEpoch(user, nextWeekToCheckpoint, userEpoch, maxUserEpoch); } } // Epoch 0 is always empty so bump onto the next one so that we start on a valid epoch. if (userEpoch == 0) { userEpoch = 1; } IVotingEscrow.Point memory nextUserPoint = _votingEscrow.user_point_history(user, userEpoch); // If this is the first checkpoint for the user, calculate the first week they're eligible for. // i.e. the timestamp of the first Thursday after they locked. // If this is earlier then the first distribution then fast forward to then. if (nextWeekToCheckpoint == 0) { // Disallow checkpointing before `startTime`. require(block.timestamp > _startTime, "Fee distribution has not started yet"); nextWeekToCheckpoint = Math.max(_startTime, _roundUpTimestamp(nextUserPoint.ts)); userState.startTime = uint64(nextWeekToCheckpoint); } // It's safe to increment `userEpoch` and `nextWeekToCheckpoint` in this loop as epochs and timestamps // are always much smaller than 2^256 and are being incremented by small values. IVotingEscrow.Point memory currentUserPoint; for (uint256 i = 0; i < 50; ++i) { if (nextWeekToCheckpoint >= nextUserPoint.ts && userEpoch <= maxUserEpoch) { // The week being considered is contained in a user epoch after that described by `currentUserPoint`. // We then shift `nextUserPoint` into `currentUserPoint` and query the Point for the next user epoch. // We do this in order to step though epochs until we find the first epoch starting after // `nextWeekToCheckpoint`, making the previous epoch the one that contains `nextWeekToCheckpoint`. userEpoch += 1; currentUserPoint = nextUserPoint; if (userEpoch > maxUserEpoch) { nextUserPoint = IVotingEscrow.Point(0, 0, 0, 0); } else { nextUserPoint = _votingEscrow.user_point_history(user, userEpoch); } } else { // The week being considered lies inside the user epoch described by `oldUserPoint` // we can then use it to calculate the user's balance at the beginning of the week. if (nextWeekToCheckpoint >= block.timestamp) { // Break if we're trying to cache the user's balance at a timestamp in the future. // We only perform this check here to ensure that we can still process checkpoints created // in the current week. break; } int128 dt = int128(nextWeekToCheckpoint - currentUserPoint.ts); uint256 userBalance = currentUserPoint.bias > currentUserPoint.slope * dt ? uint256(currentUserPoint.bias - currentUserPoint.slope * dt) : 0; // User's lock has expired and they haven't relocked yet. if (userBalance == 0 && userEpoch > maxUserEpoch) { nextWeekToCheckpoint = _roundUpTimestamp(block.timestamp); break; } // User had a nonzero lock and so is eligible to collect fees. _userBalanceAtTimestamp[user][nextWeekToCheckpoint] = userBalance; nextWeekToCheckpoint += 1 weeks; } } // We subtract off 1 from the userEpoch to step back once so that on the next attempt to checkpoint // the current `currentUserPoint` will be loaded as `nextUserPoint`. This ensures that we can't skip over the // user epoch containing `nextWeekToCheckpoint`. // userEpoch > 0 so this is safe. userState.lastEpochCheckpointed = uint64(userEpoch - 1); userState.timeCursor = uint64(nextWeekToCheckpoint); } /** * @dev Cache the totalSupply of VotingEscrow token at the beginning of each new week */ function _checkpointTotalSupply() internal { uint256 nextWeekToCheckpoint = _timeCursor; uint256 weekStart = _roundDownTimestamp(block.timestamp); // We expect `timeCursor == weekStart + 1 weeks` when fully up to date. if (nextWeekToCheckpoint > weekStart || weekStart == block.timestamp) { // We've already checkpointed up to this week so perform early return return; } _votingEscrow.checkpoint(); // Step through the each week and cache the total supply at beginning of week on this contract for (uint256 i = 0; i < 20; ++i) { if (nextWeekToCheckpoint > weekStart) break; _veSupplyCache[nextWeekToCheckpoint] = _votingEscrow.totalSupply(nextWeekToCheckpoint); // This is safe as we're incrementing a timestamp nextWeekToCheckpoint += 1 weeks; } // Update state to the end of the current week (`weekStart` + 1 weeks) _timeCursor = nextWeekToCheckpoint; } // Helper functions /** * @dev Wrapper around `_userTokenTimeCursor` which returns the start timestamp for `token` * if `user` has not attempted to interact with it previously. */ function _getUserTokenTimeCursor(address user, IERC20 token) internal view returns (uint256) { uint256 userTimeCursor = _userTokenTimeCursor[user][token]; if (userTimeCursor > 0) return userTimeCursor; // This is the first time that the user has interacted with this token. // We then start from the latest out of either when `user` first locked veBAL or `token` was first checkpointed. return Math.max(_userState[user].startTime, _tokenState[token].startTime); } /** * @dev Return the user epoch number for `user` corresponding to the provided `timestamp` */ function _findTimestampUserEpoch( address user, uint256 timestamp, uint256 minUserEpoch, uint256 maxUserEpoch ) internal view returns (uint256) { uint256 min = minUserEpoch; uint256 max = maxUserEpoch; // Perform binary search through epochs to find epoch containing `timestamp` for (uint256 i = 0; i < 128; ++i) { if (min >= max) break; // Algorithm assumes that inputs are less than 2^128 so this operation is safe. // +2 avoids getting stuck in min == mid < max uint256 mid = (min + max + 2) / 2; IVotingEscrow.Point memory pt = _votingEscrow.user_point_history(user, mid); if (pt.ts <= timestamp) { min = mid; } else { // max > min so this is safe. max = mid - 1; } } return min; } /** * @dev Rounds the provided timestamp down to the beginning of the previous week (Thurs 00:00 UTC) */ function _roundDownTimestamp(uint256 timestamp) private pure returns (uint256) { // Division by zero or overflows are impossible here. return (timestamp / 1 weeks) * 1 weeks; } /** * @dev Rounds the provided timestamp up to the beginning of the next week (Thurs 00:00 UTC) */ function _roundUpTimestamp(uint256 timestamp) private pure returns (uint256) { // Overflows are impossible here for all realistic inputs. return _roundDownTimestamp(timestamp + 1 weeks - 1); } }
// 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 "../solidity-utils/helpers/IAuthentication.sol"; import "../vault/IVault.sol"; interface IAuthorizerAdaptor is IAuthentication { /** * @notice Returns the Balancer Vault */ function getVault() external view returns (IVault); /** * @notice Returns the Authorizer */ function getAuthorizer() external view returns (IAuthorizer); /** * @notice Performs an arbitrary function call on a target contract, provided the caller is authorized to do so. * @param target - Address of the contract to be called * @param data - Calldata to be sent to the target contract * @return The bytes encoded return value from the performed function call */ function performAction(address target, bytes calldata data) external payable returns (bytes memory); }
// 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 experimental ABIEncoderV2; import "../solidity-utils/openzeppelin/IERC20.sol"; import "../solidity-utils/helpers/IAuthentication.sol"; import "../solidity-utils/helpers/ISignaturesValidator.sol"; import "../solidity-utils/helpers/ITemporarilyPausable.sol"; import "../solidity-utils/misc/IWETH.sol"; import "./IAsset.sol"; import "./IAuthorizer.sol"; import "./IFlashLoanRecipient.sol"; import "./IProtocolFeesCollector.sol"; pragma solidity ^0.7.0; /** * @dev Full external interface for the Vault core contract - no external or public methods exist in the contract that * don't override one of these declarations. */ interface IVault is ISignaturesValidator, ITemporarilyPausable, IAuthentication { // Generalities about the Vault: // // - Whenever documentation refers to 'tokens', it strictly refers to ERC20-compliant token contracts. Tokens are // transferred out of the Vault by calling the `IERC20.transfer` function, and transferred in by calling // `IERC20.transferFrom`. In these cases, the sender must have previously allowed the Vault to use their tokens by // calling `IERC20.approve`. The only deviation from the ERC20 standard that is supported is functions not returning // a boolean value: in these scenarios, a non-reverting call is assumed to be successful. // // - All non-view functions in the Vault are non-reentrant: calling them while another one is mid-execution (e.g. // while execution control is transferred to a token contract during a swap) will result in a revert. View // functions can be called in a re-reentrant way, but doing so might cause them to return inconsistent results. // Contracts calling view functions in the Vault must make sure the Vault has not already been entered. // // - View functions revert if referring to either unregistered Pools, or unregistered tokens for registered Pools. // Authorizer // // Some system actions are permissioned, like setting and collecting protocol fees. This permissioning system exists // outside of the Vault in the Authorizer contract: the Vault simply calls the Authorizer to check if the caller // can perform a given action. /** * @dev Returns the Vault's Authorizer. */ function getAuthorizer() external view returns (IAuthorizer); /** * @dev Sets a new Authorizer for the Vault. The caller must be allowed by the current Authorizer to do this. * * Emits an `AuthorizerChanged` event. */ function setAuthorizer(IAuthorizer newAuthorizer) external; /** * @dev Emitted when a new authorizer is set by `setAuthorizer`. */ event AuthorizerChanged(IAuthorizer indexed newAuthorizer); // Relayers // // Additionally, it is possible for an account to perform certain actions on behalf of another one, using their // Vault ERC20 allowance and Internal Balance. These accounts are said to be 'relayers' for these Vault functions, // and are expected to be smart contracts with sound authentication mechanisms. For an account to be able to wield // this power, two things must occur: // - The Authorizer must grant the account the permission to be a relayer for the relevant Vault function. This // means that Balancer governance must approve each individual contract to act as a relayer for the intended // functions. // - Each user must approve the relayer to act on their behalf. // This double protection means users cannot be tricked into approving malicious relayers (because they will not // have been allowed by the Authorizer via governance), nor can malicious relayers approved by a compromised // Authorizer or governance drain user funds, since they would also need to be approved by each individual user. /** * @dev Returns true if `user` has approved `relayer` to act as a relayer for them. */ function hasApprovedRelayer(address user, address relayer) external view returns (bool); /** * @dev Allows `relayer` to act as a relayer for `sender` if `approved` is true, and disallows it otherwise. * * Emits a `RelayerApprovalChanged` event. */ function setRelayerApproval( address sender, address relayer, bool approved ) external; /** * @dev Emitted every time a relayer is approved or disapproved by `setRelayerApproval`. */ event RelayerApprovalChanged(address indexed relayer, address indexed sender, bool approved); // Internal Balance // // Users can deposit tokens into the Vault, where they are allocated to their Internal Balance, and later // transferred or withdrawn. It can also be used as a source of tokens when joining Pools, as a destination // when exiting them, and as either when performing swaps. This usage of Internal Balance results in greatly reduced // gas costs when compared to relying on plain ERC20 transfers, leading to large savings for frequent users. // // Internal Balance management features batching, which means a single contract call can be used to perform multiple // operations of different kinds, with different senders and recipients, at once. /** * @dev Returns `user`'s Internal Balance for a set of tokens. */ function getInternalBalance(address user, IERC20[] memory tokens) external view returns (uint256[] memory); /** * @dev Performs a set of user balance operations, which involve Internal Balance (deposit, withdraw or transfer) * and plain ERC20 transfers using the Vault's allowance. This last feature is particularly useful for relayers, as * it lets integrators reuse a user's Vault allowance. * * For each operation, if the caller is not `sender`, it must be an authorized relayer for them. */ function manageUserBalance(UserBalanceOp[] memory ops) external payable; /** * @dev Data for `manageUserBalance` operations, which include the possibility for ETH to be sent and received without manual WETH wrapping or unwrapping. */ struct UserBalanceOp { UserBalanceOpKind kind; IAsset asset; uint256 amount; address sender; address payable recipient; } // There are four possible operations in `manageUserBalance`: // // - DEPOSIT_INTERNAL // Increases the Internal Balance of the `recipient` account by transferring tokens from the corresponding // `sender`. The sender must have allowed the Vault to use their tokens via `IERC20.approve()`. // // ETH can be used by passing the ETH sentinel value as the asset and forwarding ETH in the call: it will be wrapped // and deposited as WETH. Any ETH amount remaining will be sent back to the caller (not the sender, which is // relevant for relayers). // // Emits an `InternalBalanceChanged` event. // // // - WITHDRAW_INTERNAL // Decreases the Internal Balance of the `sender` account by transferring tokens to the `recipient`. // // ETH can be used by passing the ETH sentinel value as the asset. This will deduct WETH instead, unwrap it and send // it to the recipient as ETH. // // Emits an `InternalBalanceChanged` event. // // // - TRANSFER_INTERNAL // Transfers tokens from the Internal Balance of the `sender` account to the Internal Balance of `recipient`. // // Reverts if the ETH sentinel value is passed. // // Emits an `InternalBalanceChanged` event. // // // - TRANSFER_EXTERNAL // Transfers tokens from `sender` to `recipient`, using the Vault's ERC20 allowance. This is typically used by // relayers, as it lets them reuse a user's Vault allowance. // // Reverts if the ETH sentinel value is passed. // // Emits an `ExternalBalanceTransfer` event. enum UserBalanceOpKind { DEPOSIT_INTERNAL, WITHDRAW_INTERNAL, TRANSFER_INTERNAL, TRANSFER_EXTERNAL } /** * @dev Emitted when a user's Internal Balance changes, either from calls to `manageUserBalance`, or through * interacting with Pools using Internal Balance. * * Because Internal Balance works exclusively with ERC20 tokens, ETH deposits and withdrawals will use the WETH * address. */ event InternalBalanceChanged(address indexed user, IERC20 indexed token, int256 delta); /** * @dev Emitted when a user's Vault ERC20 allowance is used by the Vault to transfer tokens to an external account. */ event ExternalBalanceTransfer(IERC20 indexed token, address indexed sender, address recipient, uint256 amount); // Pools // // There are three specialization settings for Pools, which allow for cheaper swaps at the cost of reduced // functionality: // // - General: no specialization, suited for all Pools. IGeneralPool is used for swap request callbacks, passing the // balance of all tokens in the Pool. These Pools have the largest swap costs (because of the extra storage reads), // which increase with the number of registered tokens. // // - Minimal Swap Info: IMinimalSwapInfoPool is used instead of IGeneralPool, which saves gas by only passing the // balance of the two tokens involved in the swap. This is suitable for some pricing algorithms, like the weighted // constant product one popularized by Balancer V1. Swap costs are smaller compared to general Pools, and are // independent of the number of registered tokens. // // - Two Token: only allows two tokens to be registered. This achieves the lowest possible swap gas cost. Like // minimal swap info Pools, these are called via IMinimalSwapInfoPool. enum PoolSpecialization { GENERAL, MINIMAL_SWAP_INFO, TWO_TOKEN } /** * @dev Registers the caller account as a Pool with a given specialization setting. Returns the Pool's ID, which * is used in all Pool-related functions. Pools cannot be deregistered, nor can the Pool's specialization be * changed. * * The caller is expected to be a smart contract that implements either `IGeneralPool` or `IMinimalSwapInfoPool`, * depending on the chosen specialization setting. This contract is known as the Pool's contract. * * Note that the same contract may register itself as multiple Pools with unique Pool IDs, or in other words, * multiple Pools may share the same contract. * * Emits a `PoolRegistered` event. */ function registerPool(PoolSpecialization specialization) external returns (bytes32); /** * @dev Emitted when a Pool is registered by calling `registerPool`. */ event PoolRegistered(bytes32 indexed poolId, address indexed poolAddress, PoolSpecialization specialization); /** * @dev Returns a Pool's contract address and specialization setting. */ function getPool(bytes32 poolId) external view returns (address, PoolSpecialization); /** * @dev Registers `tokens` for the `poolId` Pool. Must be called by the Pool's contract. * * Pools can only interact with tokens they have registered. Users join a Pool by transferring registered tokens, * exit by receiving registered tokens, and can only swap registered tokens. * * Each token can only be registered once. For Pools with the Two Token specialization, `tokens` must have a length * of two, that is, both tokens must be registered in the same `registerTokens` call, and they must be sorted in * ascending order. * * The `tokens` and `assetManagers` arrays must have the same length, and each entry in these indicates the Asset * Manager for the corresponding token. Asset Managers can manage a Pool's tokens via `managePoolBalance`, * depositing and withdrawing them directly, and can even set their balance to arbitrary amounts. They are therefore * expected to be highly secured smart contracts with sound design principles, and the decision to register an * Asset Manager should not be made lightly. * * Pools can choose not to assign an Asset Manager to a given token by passing in the zero address. Once an Asset * Manager is set, it cannot be changed except by deregistering the associated token and registering again with a * different Asset Manager. * * Emits a `TokensRegistered` event. */ function registerTokens( bytes32 poolId, IERC20[] memory tokens, address[] memory assetManagers ) external; /** * @dev Emitted when a Pool registers tokens by calling `registerTokens`. */ event TokensRegistered(bytes32 indexed poolId, IERC20[] tokens, address[] assetManagers); /** * @dev Deregisters `tokens` for the `poolId` Pool. Must be called by the Pool's contract. * * Only registered tokens (via `registerTokens`) can be deregistered. Additionally, they must have zero total * balance. For Pools with the Two Token specialization, `tokens` must have a length of two, that is, both tokens * must be deregistered in the same `deregisterTokens` call. * * A deregistered token can be re-registered later on, possibly with a different Asset Manager. * * Emits a `TokensDeregistered` event. */ function deregisterTokens(bytes32 poolId, IERC20[] memory tokens) external; /** * @dev Emitted when a Pool deregisters tokens by calling `deregisterTokens`. */ event TokensDeregistered(bytes32 indexed poolId, IERC20[] tokens); /** * @dev Returns detailed information for a Pool's registered token. * * `cash` is the number of tokens the Vault currently holds for the Pool. `managed` is the number of tokens * withdrawn and held outside the Vault by the Pool's token Asset Manager. The Pool's total balance for `token` * equals the sum of `cash` and `managed`. * * Internally, `cash` and `managed` are stored using 112 bits. No action can ever cause a Pool's token `cash`, * `managed` or `total` balance to be greater than 2^112 - 1. * * `lastChangeBlock` is the number of the block in which `token`'s total balance was last modified (via either a * join, exit, swap, or Asset Manager update). This value is useful to avoid so-called 'sandwich attacks', for * example when developing price oracles. A change of zero (e.g. caused by a swap with amount zero) is considered a * change for this purpose, and will update `lastChangeBlock`. * * `assetManager` is the Pool's token Asset Manager. */ function getPoolTokenInfo(bytes32 poolId, IERC20 token) external view returns ( uint256 cash, uint256 managed, uint256 lastChangeBlock, address assetManager ); /** * @dev Returns a Pool's registered tokens, the total balance for each, and the latest block when *any* of * the tokens' `balances` changed. * * The order of the `tokens` array is the same order that will be used in `joinPool`, `exitPool`, as well as in all * Pool hooks (where applicable). Calls to `registerTokens` and `deregisterTokens` may change this order. * * If a Pool only registers tokens once, and these are sorted in ascending order, they will be stored in the same * order as passed to `registerTokens`. * * Total balances include both tokens held by the Vault and those withdrawn by the Pool's Asset Managers. These are * the amounts used by joins, exits and swaps. For a detailed breakdown of token balances, use `getPoolTokenInfo` * instead. */ function getPoolTokens(bytes32 poolId) external view returns ( IERC20[] memory tokens, uint256[] memory balances, uint256 lastChangeBlock ); /** * @dev Called by users to join a Pool, which transfers tokens from `sender` into the Pool's balance. This will * trigger custom Pool behavior, which will typically grant something in return to `recipient` - often tokenized * Pool shares. * * If the caller is not `sender`, it must be an authorized relayer for them. * * The `assets` and `maxAmountsIn` arrays must have the same length, and each entry indicates the maximum amount * to send for each asset. The amounts to send are decided by the Pool and not the Vault: it just enforces * these maximums. * * If joining a Pool that holds WETH, it is possible to send ETH directly: the Vault will do the wrapping. To enable * this mechanism, the IAsset sentinel value (the zero address) must be passed in the `assets` array instead of the * WETH address. Note that it is not possible to combine ETH and WETH in the same join. Any excess ETH will be sent * back to the caller (not the sender, which is important for relayers). * * `assets` must have the same length and order as the array returned by `getPoolTokens`. This prevents issues when * interacting with Pools that register and deregister tokens frequently. If sending ETH however, the array must be * sorted *before* replacing the WETH address with the ETH sentinel value (the zero address), which means the final * `assets` array might not be sorted. Pools with no registered tokens cannot be joined. * * If `fromInternalBalance` is true, the caller's Internal Balance will be preferred: ERC20 transfers will only * be made for the difference between the requested amount and Internal Balance (if any). Note that ETH cannot be * withdrawn from Internal Balance: attempting to do so will trigger a revert. * * This causes the Vault to call the `IBasePool.onJoinPool` hook on the Pool's contract, where Pools implement * their own custom logic. This typically requires additional information from the user (such as the expected number * of Pool shares). This can be encoded in the `userData` argument, which is ignored by the Vault and passed * directly to the Pool's contract, as is `recipient`. * * Emits a `PoolBalanceChanged` event. */ function joinPool( bytes32 poolId, address sender, address recipient, JoinPoolRequest memory request ) external payable; struct JoinPoolRequest { IAsset[] assets; uint256[] maxAmountsIn; bytes userData; bool fromInternalBalance; } /** * @dev Called by users to exit a Pool, which transfers tokens from the Pool's balance to `recipient`. This will * trigger custom Pool behavior, which will typically ask for something in return from `sender` - often tokenized * Pool shares. The amount of tokens that can be withdrawn is limited by the Pool's `cash` balance (see * `getPoolTokenInfo`). * * If the caller is not `sender`, it must be an authorized relayer for them. * * The `tokens` and `minAmountsOut` arrays must have the same length, and each entry in these indicates the minimum * token amount to receive for each token contract. The amounts to send are decided by the Pool and not the Vault: * it just enforces these minimums. * * If exiting a Pool that holds WETH, it is possible to receive ETH directly: the Vault will do the unwrapping. To * enable this mechanism, the IAsset sentinel value (the zero address) must be passed in the `assets` array instead * of the WETH address. Note that it is not possible to combine ETH and WETH in the same exit. * * `assets` must have the same length and order as the array returned by `getPoolTokens`. This prevents issues when * interacting with Pools that register and deregister tokens frequently. If receiving ETH however, the array must * be sorted *before* replacing the WETH address with the ETH sentinel value (the zero address), which means the * final `assets` array might not be sorted. Pools with no registered tokens cannot be exited. * * If `toInternalBalance` is true, the tokens will be deposited to `recipient`'s Internal Balance. Otherwise, * an ERC20 transfer will be performed. Note that ETH cannot be deposited to Internal Balance: attempting to * do so will trigger a revert. * * `minAmountsOut` is the minimum amount of tokens the user expects to get out of the Pool, for each token in the * `tokens` array. This array must match the Pool's registered tokens. * * This causes the Vault to call the `IBasePool.onExitPool` hook on the Pool's contract, where Pools implement * their own custom logic. This typically requires additional information from the user (such as the expected number * of Pool shares to return). This can be encoded in the `userData` argument, which is ignored by the Vault and * passed directly to the Pool's contract. * * Emits a `PoolBalanceChanged` event. */ function exitPool( bytes32 poolId, address sender, address payable recipient, ExitPoolRequest memory request ) external; struct ExitPoolRequest { IAsset[] assets; uint256[] minAmountsOut; bytes userData; bool toInternalBalance; } /** * @dev Emitted when a user joins or exits a Pool by calling `joinPool` or `exitPool`, respectively. */ event PoolBalanceChanged( bytes32 indexed poolId, address indexed liquidityProvider, IERC20[] tokens, int256[] deltas, uint256[] protocolFeeAmounts ); enum PoolBalanceChangeKind { JOIN, EXIT } // Swaps // // Users can swap tokens with Pools by calling the `swap` and `batchSwap` functions. To do this, // they need not trust Pool contracts in any way: all security checks are made by the Vault. They must however be // aware of the Pools' pricing algorithms in order to estimate the prices Pools will quote. // // The `swap` function executes a single swap, while `batchSwap` can perform multiple swaps in sequence. // In each individual swap, tokens of one kind are sent from the sender to the Pool (this is the 'token in'), // and tokens of another kind are sent from the Pool to the recipient in exchange (this is the 'token out'). // More complex swaps, such as one token in to multiple tokens out can be achieved by batching together // individual swaps. // // There are two swap kinds: // - 'given in' swaps, where the amount of tokens in (sent to the Pool) is known, and the Pool determines (via the // `onSwap` hook) the amount of tokens out (to send to the recipient). // - 'given out' swaps, where the amount of tokens out (received from the Pool) is known, and the Pool determines // (via the `onSwap` hook) the amount of tokens in (to receive from the sender). // // Additionally, it is possible to chain swaps using a placeholder input amount, which the Vault replaces with // the calculated output of the previous swap. If the previous swap was 'given in', this will be the calculated // tokenOut amount. If the previous swap was 'given out', it will use the calculated tokenIn amount. These extended // swaps are known as 'multihop' swaps, since they 'hop' through a number of intermediate tokens before arriving at // the final intended token. // // In all cases, tokens are only transferred in and out of the Vault (or withdrawn from and deposited into Internal // Balance) after all individual swaps have been completed, and the net token balance change computed. This makes // certain swap patterns, such as multihops, or swaps that interact with the same token pair in multiple Pools, cost // much less gas than they would otherwise. // // It also means that under certain conditions it is possible to perform arbitrage by swapping with multiple // Pools in a way that results in net token movement out of the Vault (profit), with no tokens being sent in (only // updating the Pool's internal accounting). // // To protect users from front-running or the market changing rapidly, they supply a list of 'limits' for each token // involved in the swap, where either the maximum number of tokens to send (by passing a positive value) or the // minimum amount of tokens to receive (by passing a negative value) is specified. // // Additionally, a 'deadline' timestamp can also be provided, forcing the swap to fail if it occurs after // this point in time (e.g. if the transaction failed to be included in a block promptly). // // If interacting with Pools that hold WETH, it is possible to both send and receive ETH directly: the Vault will do // the wrapping and unwrapping. To enable this mechanism, the IAsset sentinel value (the zero address) must be // passed in the `assets` array instead of the WETH address. Note that it is possible to combine ETH and WETH in the // same swap. Any excess ETH will be sent back to the caller (not the sender, which is relevant for relayers). // // Finally, Internal Balance can be used when either sending or receiving tokens. enum SwapKind { GIVEN_IN, GIVEN_OUT } /** * @dev Performs a swap with a single Pool. * * If the swap is 'given in' (the number of tokens to send to the Pool is known), it returns the amount of tokens * taken from the Pool, which must be greater than or equal to `limit`. * * If the swap is 'given out' (the number of tokens to take from the Pool is known), it returns the amount of tokens * sent to the Pool, which must be less than or equal to `limit`. * * Internal Balance usage and the recipient are determined by the `funds` struct. * * Emits a `Swap` event. */ function swap( SingleSwap memory singleSwap, FundManagement memory funds, uint256 limit, uint256 deadline ) external payable returns (uint256); /** * @dev Data for a single swap executed by `swap`. `amount` is either `amountIn` or `amountOut` depending on * the `kind` value. * * `assetIn` and `assetOut` are either token addresses, or the IAsset sentinel value for ETH (the zero address). * Note that Pools never interact with ETH directly: it will be wrapped to or unwrapped from WETH by the Vault. * * The `userData` field is ignored by the Vault, but forwarded to the Pool in the `onSwap` hook, and may be * used to extend swap behavior. */ struct SingleSwap { bytes32 poolId; SwapKind kind; IAsset assetIn; IAsset assetOut; uint256 amount; bytes userData; } /** * @dev Performs a series of swaps with one or multiple Pools. In each individual swap, the caller determines either * the amount of tokens sent to or received from the Pool, depending on the `kind` value. * * Returns an array with the net Vault asset balance deltas. Positive amounts represent tokens (or ETH) sent to the * Vault, and negative amounts represent tokens (or ETH) sent by the Vault. Each delta corresponds to the asset at * the same index in the `assets` array. * * Swaps are executed sequentially, in the order specified by the `swaps` array. Each array element describes a * Pool, the token to be sent to this Pool, the token to receive from it, and an amount that is either `amountIn` or * `amountOut` depending on the swap kind. * * Multihop swaps can be executed by passing an `amount` value of zero for a swap. This will cause the amount in/out * of the previous swap to be used as the amount in for the current one. In a 'given in' swap, 'tokenIn' must equal * the previous swap's `tokenOut`. For a 'given out' swap, `tokenOut` must equal the previous swap's `tokenIn`. * * The `assets` array contains the addresses of all assets involved in the swaps. These are either token addresses, * or the IAsset sentinel value for ETH (the zero address). Each entry in the `swaps` array specifies tokens in and * out by referencing an index in `assets`. Note that Pools never interact with ETH directly: it will be wrapped to * or unwrapped from WETH by the Vault. * * Internal Balance usage, sender, and recipient are determined by the `funds` struct. The `limits` array specifies * the minimum or maximum amount of each token the vault is allowed to transfer. * * `batchSwap` can be used to make a single swap, like `swap` does, but doing so requires more gas than the * equivalent `swap` call. * * Emits `Swap` events. */ function batchSwap( SwapKind kind, BatchSwapStep[] memory swaps, IAsset[] memory assets, FundManagement memory funds, int256[] memory limits, uint256 deadline ) external payable returns (int256[] memory); /** * @dev Data for each individual swap executed by `batchSwap`. The asset in and out fields are indexes into the * `assets` array passed to that function, and ETH assets are converted to WETH. * * If `amount` is zero, the multihop mechanism is used to determine the actual amount based on the amount in/out * from the previous swap, depending on the swap kind. * * The `userData` field is ignored by the Vault, but forwarded to the Pool in the `onSwap` hook, and may be * used to extend swap behavior. */ struct BatchSwapStep { bytes32 poolId; uint256 assetInIndex; uint256 assetOutIndex; uint256 amount; bytes userData; } /** * @dev Emitted for each individual swap performed by `swap` or `batchSwap`. */ event Swap( bytes32 indexed poolId, IERC20 indexed tokenIn, IERC20 indexed tokenOut, uint256 amountIn, uint256 amountOut ); /** * @dev All tokens in a swap are either sent from the `sender` account to the Vault, or from the Vault to the * `recipient` account. * * If the caller is not `sender`, it must be an authorized relayer for them. * * If `fromInternalBalance` is true, the `sender`'s Internal Balance will be preferred, performing an ERC20 * transfer for the difference between the requested amount and the User's Internal Balance (if any). The `sender` * must have allowed the Vault to use their tokens via `IERC20.approve()`. This matches the behavior of * `joinPool`. * * If `toInternalBalance` is true, tokens will be deposited to `recipient`'s internal balance instead of * transferred. This matches the behavior of `exitPool`. * * Note that ETH cannot be deposited to or withdrawn from Internal Balance: attempting to do so will trigger a * revert. */ struct FundManagement { address sender; bool fromInternalBalance; address payable recipient; bool toInternalBalance; } /** * @dev Simulates a call to `batchSwap`, returning an array of Vault asset deltas. Calls to `swap` cannot be * simulated directly, but an equivalent `batchSwap` call can and will yield the exact same result. * * Each element in the array corresponds to the asset at the same index, and indicates the number of tokens (or ETH) * the Vault would take from the sender (if positive) or send to the recipient (if negative). The arguments it * receives are the same that an equivalent `batchSwap` call would receive. * * Unlike `batchSwap`, this function performs no checks on the sender or recipient field in the `funds` struct. * This makes it suitable to be called by off-chain applications via eth_call without needing to hold tokens, * approve them for the Vault, or even know a user's address. * * Note that this function is not 'view' (due to implementation details): the client code must explicitly execute * eth_call instead of eth_sendTransaction. */ function queryBatchSwap( SwapKind kind, BatchSwapStep[] memory swaps, IAsset[] memory assets, FundManagement memory funds ) external returns (int256[] memory assetDeltas); // Flash Loans /** * @dev Performs a 'flash loan', sending tokens to `recipient`, executing the `receiveFlashLoan` hook on it, * and then reverting unless the tokens plus a proportional protocol fee have been returned. * * The `tokens` and `amounts` arrays must have the same length, and each entry in these indicates the loan amount * for each token contract. `tokens` must be sorted in ascending order. * * The 'userData' field is ignored by the Vault, and forwarded as-is to `recipient` as part of the * `receiveFlashLoan` call. * * Emits `FlashLoan` events. */ function flashLoan( IFlashLoanRecipient recipient, IERC20[] memory tokens, uint256[] memory amounts, bytes memory userData ) external; /** * @dev Emitted for each individual flash loan performed by `flashLoan`. */ event FlashLoan(IFlashLoanRecipient indexed recipient, IERC20 indexed token, uint256 amount, uint256 feeAmount); // Asset Management // // Each token registered for a Pool can be assigned an Asset Manager, which is able to freely withdraw the Pool's // tokens from the Vault, deposit them, or assign arbitrary values to its `managed` balance (see // `getPoolTokenInfo`). This makes them extremely powerful and dangerous. Even if an Asset Manager only directly // controls one of the tokens in a Pool, a malicious manager could set that token's balance to manipulate the // prices of the other tokens, and then drain the Pool with swaps. The risk of using Asset Managers is therefore // not constrained to the tokens they are managing, but extends to the entire Pool's holdings. // // However, a properly designed Asset Manager smart contract can be safely used for the Pool's benefit, // for example by lending unused tokens out for interest, or using them to participate in voting protocols. // // This concept is unrelated to the IAsset interface. /** * @dev Performs a set of Pool balance operations, which may be either withdrawals, deposits or updates. * * Pool Balance management features batching, which means a single contract call can be used to perform multiple * operations of different kinds, with different Pools and tokens, at once. * * For each operation, the caller must be registered as the Asset Manager for `token` in `poolId`. */ function managePoolBalance(PoolBalanceOp[] memory ops) external; struct PoolBalanceOp { PoolBalanceOpKind kind; bytes32 poolId; IERC20 token; uint256 amount; } /** * Withdrawals decrease the Pool's cash, but increase its managed balance, leaving the total balance unchanged. * * Deposits increase the Pool's cash, but decrease its managed balance, leaving the total balance unchanged. * * Updates don't affect the Pool's cash balance, but because the managed balance changes, it does alter the total. * The external amount can be either increased or decreased by this call (i.e., reporting a gain or a loss). */ enum PoolBalanceOpKind { WITHDRAW, DEPOSIT, UPDATE } /** * @dev Emitted when a Pool's token Asset Manager alters its balance via `managePoolBalance`. */ event PoolBalanceManaged( bytes32 indexed poolId, address indexed assetManager, IERC20 indexed token, int256 cashDelta, int256 managedDelta ); // Protocol Fees // // Some operations cause the Vault to collect tokens in the form of protocol fees, which can then be withdrawn by // permissioned accounts. // // There are two kinds of protocol fees: // // - flash loan fees: charged on all flash loans, as a percentage of the amounts lent. // // - swap fees: a percentage of the fees charged by Pools when performing swaps. For a number of reasons, including // swap gas costs and interface simplicity, protocol swap fees are not charged on each individual swap. Rather, // Pools are expected to keep track of how much they have charged in swap fees, and pay any outstanding debts to the // Vault when they are joined or exited. This prevents users from joining a Pool with unpaid debt, as well as // exiting a Pool in debt without first paying their share. /** * @dev Returns the current protocol fee module. */ function getProtocolFeesCollector() external view returns (IProtocolFeesCollector); /** * @dev Safety mechanism to pause most Vault operations in the event of an emergency - typically detection of an * error in some part of the system. * * The Vault can only be paused during an initial time period, after which pausing is forever disabled. * * While the contract is paused, the following features are disabled: * - depositing and transferring internal balance * - transferring external balance (using the Vault's allowance) * - swaps * - joining Pools * - Asset Manager interactions * * Internal Balance can still be withdrawn, and Pools exited. */ function setPaused(bool paused) external; /** * @dev Returns the Vault's WETH instance. */ function WETH() external view returns (IWETH); // solhint-disable-previous-line func-name-mixedcase }
// SPDX-License-Identifier: MIT // 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 "@balancer-labs/v2-interfaces/contracts/solidity-utils/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 Address library from OpenZeppelin Contracts, altered by removing the `isContract` checks on // `functionCall` and `functionDelegateCall` in order to save gas, as the recipients are known to be contracts. pragma solidity ^0.7.0; import "@balancer-labs/v2-interfaces/contracts/solidity-utils/helpers/BalancerErrors.sol"; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } // solhint-disable max-line-length /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { _require(address(this).balance >= amount, Errors.ADDRESS_INSUFFICIENT_BALANCE); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); _require(success, Errors.ADDRESS_CANNOT_SEND_VALUE); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call(data); return verifyCallResult(success, returndata); } // solhint-enable max-line-length /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but passing some native ETH as msg.value to the call. * * _Available since v3.4._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: value }(data); return verifyCallResult(success, returndata); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata); } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling up the * revert reason or using the one provided. * * _Available since v4.3._ */ function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { _revert(Errors.LOW_LEVEL_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; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
// SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. pragma solidity ^0.7.0; /** * @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"; /** * @dev Interface for WETH9. * See https://github.com/gnosis/canonical-weth/blob/0dd1ea3e295eef916d0c6223ec63141137d22d67/contracts/WETH9.sol */ interface IWETH is IERC20 { function deposit() external payable; function withdraw(uint256 amount) external; }
// SPDX-License-Identifier: 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; // Inspired by Aave Protocol's IFlashLoanReceiver. import "../solidity-utils/openzeppelin/IERC20.sol"; interface IFlashLoanRecipient { /** * @dev When `flashLoan` is called on the Vault, it invokes the `receiveFlashLoan` hook on the recipient. * * At the time of the call, the Vault will have transferred `amounts` for `tokens` to the recipient. Before this * call returns, the recipient must have transferred `amounts` plus `feeAmounts` for each token back to the * Vault, or else the entire flash loan will revert. * * `userData` is the same value passed in the `IVault.flashLoan` call. */ function receiveFlashLoan( IERC20[] memory tokens, uint256[] memory amounts, uint256[] memory feeAmounts, bytes memory userData ) external; }
// SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "../solidity-utils/openzeppelin/IERC20.sol"; import "./IVault.sol"; import "./IAuthorizer.sol"; interface IProtocolFeesCollector { event SwapFeePercentageChanged(uint256 newSwapFeePercentage); event FlashLoanFeePercentageChanged(uint256 newFlashLoanFeePercentage); function withdrawCollectedFees( IERC20[] calldata tokens, uint256[] calldata amounts, address recipient ) external; function setSwapFeePercentage(uint256 newSwapFeePercentage) external; function setFlashLoanFeePercentage(uint256 newFlashLoanFeePercentage) external; function getSwapFeePercentage() external view returns (uint256); function getFlashLoanFeePercentage() external view returns (uint256); function getCollectedFeeAmounts(IERC20[] memory tokens) external view returns (uint256[] memory feeAmounts); function getAuthorizer() external view returns (IAuthorizer); function vault() external view returns (IVault); }
// SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. pragma 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; uint256 internal constant NOT_TWO_TOKENS = 210; uint256 internal constant DISABLED = 211; // 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; uint256 internal constant AMP_END_TIME_TOO_CLOSE = 317; uint256 internal constant AMP_ONGOING_UPDATE = 318; uint256 internal constant AMP_RATE_TOO_HIGH = 319; uint256 internal constant AMP_NO_ONGOING_UPDATE = 320; uint256 internal constant STABLE_INVARIANT_DIDNT_CONVERGE = 321; uint256 internal constant STABLE_GET_BALANCE_DIDNT_CONVERGE = 322; uint256 internal constant RELAYER_NOT_CONTRACT = 323; uint256 internal constant BASE_POOL_RELAYER_NOT_CALLED = 324; uint256 internal constant REBALANCING_RELAYER_REENTERED = 325; uint256 internal constant GRADUAL_UPDATE_TIME_TRAVEL = 326; uint256 internal constant SWAPS_DISABLED = 327; uint256 internal constant CALLER_IS_NOT_LBP_OWNER = 328; uint256 internal constant PRICE_RATE_OVERFLOW = 329; uint256 internal constant INVALID_JOIN_EXIT_KIND_WHILE_SWAPS_DISABLED = 330; uint256 internal constant WEIGHT_CHANGE_TOO_FAST = 331; uint256 internal constant LOWER_GREATER_THAN_UPPER_TARGET = 332; uint256 internal constant UPPER_TARGET_TOO_HIGH = 333; uint256 internal constant UNHANDLED_BY_LINEAR_POOL = 334; uint256 internal constant OUT_OF_TARGET_RANGE = 335; uint256 internal constant UNHANDLED_EXIT_KIND = 336; uint256 internal constant UNAUTHORIZED_EXIT = 337; uint256 internal constant MAX_MANAGEMENT_SWAP_FEE_PERCENTAGE = 338; uint256 internal constant UNHANDLED_BY_MANAGED_POOL = 339; uint256 internal constant UNHANDLED_BY_PHANTOM_POOL = 340; uint256 internal constant TOKEN_DOES_NOT_HAVE_RATE_PROVIDER = 341; uint256 internal constant INVALID_INITIALIZATION = 342; uint256 internal constant OUT_OF_NEW_TARGET_RANGE = 343; uint256 internal constant FEATURE_DISABLED = 344; uint256 internal constant UNINITIALIZED_POOL_CONTROLLER = 345; uint256 internal constant SET_SWAP_FEE_DURING_FEE_CHANGE = 346; uint256 internal constant SET_SWAP_FEE_PENDING_FEE_CHANGE = 347; uint256 internal constant CHANGE_TOKENS_DURING_WEIGHT_CHANGE = 348; uint256 internal constant CHANGE_TOKENS_PENDING_WEIGHT_CHANGE = 349; uint256 internal constant MAX_WEIGHT = 350; uint256 internal constant UNAUTHORIZED_JOIN = 351; uint256 internal constant MAX_MANAGEMENT_AUM_FEE_PERCENTAGE = 352; // 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; uint256 internal constant CALLER_IS_NOT_OWNER = 426; uint256 internal constant NEW_OWNER_IS_ZERO = 427; uint256 internal constant CODE_DEPLOYMENT_FAILED = 428; uint256 internal constant CALL_TO_NON_CONTRACT = 429; uint256 internal constant LOW_LEVEL_CALL_FAILED = 430; uint256 internal constant NOT_PAUSED = 431; uint256 internal constant ADDRESS_ALREADY_ALLOWLISTED = 432; uint256 internal constant ADDRESS_NOT_ALLOWLISTED = 433; uint256 internal constant ERC20_BURN_EXCEEDS_BALANCE = 434; uint256 internal constant INVALID_OPERATION = 435; uint256 internal constant CODEC_OVERFLOW = 436; uint256 internal constant IN_RECOVERY_MODE = 437; uint256 internal constant NOT_IN_RECOVERY_MODE = 438; uint256 internal constant INDUCED_FAILURE = 439; uint256 internal constant EXPIRED_SIGNATURE = 440; uint256 internal constant MALFORMED_SIGNATURE = 441; // 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; uint256 internal constant AUM_FEE_PERCENTAGE_TOO_HIGH = 603; // Misc uint256 internal constant SHOULD_NOT_HAPPEN = 999; }
// SPDX-License-Identifier: MIT pragma solidity ^0.7.0; import "@balancer-labs/v2-interfaces/contracts/solidity-utils/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; import "@balancer-labs/v2-interfaces/contracts/solidity-utils/helpers/BalancerErrors.sol"; import "@balancer-labs/v2-interfaces/contracts/solidity-utils/helpers/ISignaturesValidator.sol"; import "../openzeppelin/EIP712.sol"; /** * @dev Utility for signing Solidity function calls. */ abstract contract EOASignaturesValidator is ISignaturesValidator, EIP712 { // Replay attack prevention for each account. mapping(address => uint256) internal _nextNonce; function getDomainSeparator() public view override returns (bytes32) { return _domainSeparatorV4(); } function getNextNonce(address account) public view override returns (uint256) { return _nextNonce[account]; } function _ensureValidSignature( address account, bytes32 structHash, bytes memory signature, uint256 errorCode ) internal { return _ensureValidSignature(account, structHash, signature, type(uint256).max, errorCode); } function _ensureValidSignature( address account, bytes32 structHash, bytes memory signature, uint256 deadline, uint256 errorCode ) internal { bytes32 digest = _hashTypedDataV4(structHash); _require(_isValidSignature(account, digest, signature), errorCode); // We could check for the deadline before validating the signature, but this leads to saner error processing (as // we only care about expired deadlines if the signature is correct) and only affects the gas cost of the revert // scenario, which will only occur infrequently, if ever. // The deadline is timestamp-based: it should not be relied upon for sub-minute accuracy. // solhint-disable-next-line not-rely-on-time _require(deadline >= block.timestamp, Errors.EXPIRED_SIGNATURE); // We only advance the nonce after validating the signature. This is irrelevant for this module, but it can be // important in derived contracts that override _isValidSignature (e.g. SignaturesValidator), as we want for // the observable state to still have the current nonce as the next valid one. _nextNonce[account] += 1; } function _isValidSignature( address account, bytes32 digest, bytes memory signature ) internal view virtual returns (bool) { _require(signature.length == 65, Errors.MALFORMED_SIGNATURE); bytes32 r; bytes32 s; uint8 v; // ecrecover takes the r, s and v signature parameters, and the only way to get them is to use assembly. assembly { r := mload(add(signature, 0x20)) s := mload(add(signature, 0x40)) v := byte(0, mload(add(signature, 0x60))) } address recoveredAddress = ecrecover(digest, v, r, s); // ecrecover returns the zero address on recover failure, so we need to handle that explicitly. return (recoveredAddress != address(0) && recoveredAddress == account); } function _toArraySignature( uint8 v, bytes32 r, bytes32 s ) internal pure returns (bytes memory) { bytes memory signature = new bytes(65); assembly { mstore(add(signature, 32), r) mstore(add(signature, 64), s) mstore8(add(signature, 96), v) } return signature; } }
// 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() } } }
// 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 "@balancer-labs/v2-interfaces/contracts/solidity-utils/openzeppelin/IERC1271.sol"; import "./EOASignaturesValidator.sol"; import "../openzeppelin/Address.sol"; /** * @dev Utility for signing Solidity function calls. */ abstract contract SignaturesValidator is EOASignaturesValidator { using Address for address; function _isValidSignature( address account, bytes32 digest, bytes memory signature ) internal view virtual override returns (bool) { if (account.isContract()) { return IERC1271(account).isValidSignature(digest, signature) == IERC1271.isValidSignature.selector; } else { return super._isValidSignature(account, digest, signature); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (interfaces/IERC1271.sol) pragma solidity ^0.7.0; /** * @dev Interface of the ERC1271 standard signature validation method for * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271]. * * _Available since v4.1._ */ interface IERC1271 { /** * @dev Should return whether the signature provided is valid for the provided data * @param hash Hash of the data to be signed * @param signature Signature byte array associated with _data */ function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue); }
// 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 "@balancer-labs/v2-interfaces/contracts/solidity-utils/helpers/IOptionalOnlyCaller.sol"; import "@balancer-labs/v2-interfaces/contracts/solidity-utils/helpers/BalancerErrors.sol"; import "./SignaturesValidator.sol"; abstract contract OptionalOnlyCaller is IOptionalOnlyCaller, SignaturesValidator { mapping(address => bool) private _isOnlyCallerEnabled; bytes32 private constant _SET_ONLY_CALLER_CHECK_TYPEHASH = keccak256( "SetOnlyCallerCheck(address user,bool enabled,uint256 nonce)" ); /** * @dev Reverts if the verification mechanism is enabled and the given address is not the caller. * @param user - Address to validate as the only allowed caller, if the verification is enabled. */ modifier optionalOnlyCaller(address user) { _verifyCaller(user); _; } function setOnlyCallerCheck(bool enabled) external override { _setOnlyCallerCheck(msg.sender, enabled); } function setOnlyCallerCheckWithSignature( address user, bool enabled, bytes memory signature ) external override { bytes32 structHash = keccak256(abi.encode(_SET_ONLY_CALLER_CHECK_TYPEHASH, user, enabled, getNextNonce(user))); _ensureValidSignature(user, structHash, signature, Errors.INVALID_SIGNATURE); _setOnlyCallerCheck(user, enabled); } function _setOnlyCallerCheck(address user, bool enabled) private { _isOnlyCallerEnabled[user] = enabled; emit OnlyCallerOptIn(user, enabled); } function isOnlyCallerEnabled(address user) external view override returns (bool) { return _isOnlyCallerEnabled[user]; } function _verifyCaller(address user) private view { if (_isOnlyCallerEnabled[user]) { _require(msg.sender == user, Errors.SENDER_NOT_ALLOWED); } } }
// 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 OptionalOnlyCaller helper, used to opt in to a caller * verification for a given address to methods that are otherwise callable by any address. */ interface IOptionalOnlyCaller { /** * @dev Emitted every time setOnlyCallerCheck is called. */ event OnlyCallerOptIn(address user, bool enabled); /** * @dev Enables / disables verification mechanism for caller. * @param enabled - True if caller verification shall be enabled, false otherwise. */ function setOnlyCallerCheck(bool enabled) external; function setOnlyCallerCheckWithSignature( address user, bool enabled, bytes memory signature ) external; /** * @dev Returns true if caller verification is enabled for the given user, false otherwise. */ function isOnlyCallerEnabled(address user) 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; pragma experimental ABIEncoderV2; import "../solidity-utils/openzeppelin/IERC20.sol"; import "./IVotingEscrow.sol"; /** * @title Fee Distributor * @notice Distributes any tokens transferred to the contract (e.g. Protocol fees and any BAL emissions) among veBAL * holders proportionally based on a snapshot of the week at which the tokens are sent to the FeeDistributor contract. * @dev Supports distributing arbitrarily many different tokens. In order to start distributing a new token to veBAL * holders simply transfer the tokens to the `FeeDistributor` contract and then call `checkpointToken`. */ interface IFeeDistributor { event TokenCheckpointed(IERC20 token, uint256 amount, uint256 lastCheckpointTimestamp); event TokensClaimed(address user, IERC20 token, uint256 amount, uint256 userTokenTimeCursor); /** * @notice Returns the VotingEscrow (veBAL) token contract */ function getVotingEscrow() external view returns (IVotingEscrow); /** * @notice Returns the global time cursor representing the most earliest uncheckpointed week. */ function getTimeCursor() external view returns (uint256); /** * @notice Returns the user-level time cursor representing the most earliest uncheckpointed week. * @param user - The address of the user to query. */ function getUserTimeCursor(address user) external view returns (uint256); /** * @notice Returns the token-level time cursor storing the timestamp at up to which tokens have been distributed. * @param token - The ERC20 token address to query. */ function getTokenTimeCursor(IERC20 token) external view returns (uint256); /** * @notice Returns the user-level time cursor storing the timestamp of the latest token distribution claimed. * @param user - The address of the user to query. * @param token - The ERC20 token address to query. */ function getUserTokenTimeCursor(address user, IERC20 token) external view returns (uint256); /** * @notice Returns the user's cached balance of veBAL as of the provided timestamp. * @dev Only timestamps which fall on Thursdays 00:00:00 UTC will return correct values. * This function requires `user` to have been checkpointed past `timestamp` so that their balance is cached. * @param user - The address of the user of which to read the cached balance of. * @param timestamp - The timestamp at which to read the `user`'s cached balance at. */ function getUserBalanceAtTimestamp(address user, uint256 timestamp) external view returns (uint256); /** * @notice Returns the cached total supply of veBAL as of the provided timestamp. * @dev Only timestamps which fall on Thursdays 00:00:00 UTC will return correct values. * This function requires the contract to have been checkpointed past `timestamp` so that the supply is cached. * @param timestamp - The timestamp at which to read the cached total supply at. */ function getTotalSupplyAtTimestamp(uint256 timestamp) external view returns (uint256); /** * @notice Returns the FeeDistributor's cached balance of `token`. */ function getTokenLastBalance(IERC20 token) external view returns (uint256); /** * @notice Returns the amount of `token` which the FeeDistributor received in the week beginning at `timestamp`. * @param token - The ERC20 token address to query. * @param timestamp - The timestamp corresponding to the beginning of the week of interest. */ function getTokensDistributedInWeek(IERC20 token, uint256 timestamp) external view returns (uint256); // Depositing /** * @notice Deposits tokens to be distributed in the current week. * @dev Sending tokens directly to the FeeDistributor instead of using `depositTokens` may result in tokens being * retroactively distributed to past weeks, or for the distribution to carry over to future weeks. * * If for some reason `depositTokens` cannot be called, in order to ensure that all tokens are correctly distributed * manually call `checkpointToken` before and after the token transfer. * @param token - The ERC20 token address to distribute. * @param amount - The amount of tokens to deposit. */ function depositToken(IERC20 token, uint256 amount) external; /** * @notice Deposits tokens to be distributed in the current week. * @dev A version of `depositToken` which supports depositing multiple `tokens` at once. * See `depositToken` for more details. * @param tokens - An array of ERC20 token addresses to distribute. * @param amounts - An array of token amounts to deposit. */ function depositTokens(IERC20[] calldata tokens, uint256[] calldata amounts) external; // Checkpointing /** * @notice Caches the total supply of veBAL at the beginning of each week. * This function will be called automatically before claiming tokens to ensure the contract is properly updated. */ function checkpoint() external; /** * @notice Caches the user's balance of veBAL at the beginning of each week. * This function will be called automatically before claiming tokens to ensure the contract is properly updated. * @param user - The address of the user to be checkpointed. */ function checkpointUser(address user) external; /** * @notice Assigns any newly-received tokens held by the FeeDistributor to weekly distributions. * @dev Any `token` balance held by the FeeDistributor above that which is returned by `getTokenLastBalance` * will be distributed evenly across the time period since `token` was last checkpointed. * * This function will be called automatically before claiming tokens to ensure the contract is properly updated. * @param token - The ERC20 token address to be checkpointed. */ function checkpointToken(IERC20 token) external; /** * @notice Assigns any newly-received tokens held by the FeeDistributor to weekly distributions. * @dev A version of `checkpointToken` which supports checkpointing multiple tokens. * See `checkpointToken` for more details. * @param tokens - An array of ERC20 token addresses to be checkpointed. */ function checkpointTokens(IERC20[] calldata tokens) external; // Claiming /** * @notice Claims all pending distributions of the provided token for a user. * @dev It's not necessary to explicitly checkpoint before calling this function, it will ensure the FeeDistributor * is up to date before calculating the amount of tokens to be claimed. * @param user - The user on behalf of which to claim. * @param token - The ERC20 token address to be claimed. * @return The amount of `token` sent to `user` as a result of claiming. */ function claimToken(address user, IERC20 token) external returns (uint256); /** * @notice Claims a number of tokens on behalf of a user. * @dev A version of `claimToken` which supports claiming multiple `tokens` on behalf of `user`. * See `claimToken` for more details. * @param user - The user on behalf of which to claim. * @param tokens - An array of ERC20 token addresses to be claimed. * @return An array of the amounts of each token in `tokens` sent to `user` as a result of claiming. */ function claimTokens(address user, IERC20[] calldata tokens) external returns (uint256[] memory); }
// 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 "./IAuthorizerAdaptor.sol"; // For compatibility, we're keeping the same function names as in the original Curve code, including the mixed-case // naming convention. // solhint-disable func-name-mixedcase interface IVotingEscrow { struct Point { int128 bias; int128 slope; // - dweight / dt uint256 ts; uint256 blk; // block } function epoch() external view returns (uint256); function totalSupply(uint256 timestamp) external view returns (uint256); function user_point_epoch(address user) external view returns (uint256); function point_history(uint256 timestamp) external view returns (Point memory); function user_point_history(address user, uint256 timestamp) external view returns (Point memory); function checkpoint() external; function admin() external view returns (IAuthorizerAdaptor); function smart_wallet_checker() external view returns (address); function commit_smart_wallet_checker(address newSmartWalletChecker) external; function apply_smart_wallet_checker() 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; import "@balancer-labs/v2-interfaces/contracts/solidity-utils/openzeppelin/IERC20.sol"; import "@balancer-labs/v2-interfaces/contracts/solidity-utils/helpers/BalancerErrors.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(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: 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 "@balancer-labs/v2-interfaces/contracts/solidity-utils/helpers/BalancerErrors.sol"; import "@balancer-labs/v2-interfaces/contracts/solidity-utils/openzeppelin/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. // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = token.call(data); // If the low-level call didn't succeed we return whatever was returned from it. // solhint-disable-next-line no-inline-assembly 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: MIT pragma solidity ^0.7.0; import "@balancer-labs/v2-interfaces/contracts/solidity-utils/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 absolute value of a signed integer. */ function abs(int256 a) internal pure returns (uint256) { return a > 0 ? uint256(a) : uint256(-a); } /** * @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 div( uint256 a, uint256 b, bool roundUp ) internal pure returns (uint256) { return roundUp ? divUp(a, b) : divDown(a, b); } 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; } } }
{ "optimizer": { "enabled": true, "runs": 9999 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"contract IVotingEscrow","name":"votingEscrow","type":"address"},{"internalType":"uint256","name":"startTime","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"bool","name":"enabled","type":"bool"}],"name":"OnlyCallerOptIn","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IERC20","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"lastCheckpointTimestamp","type":"uint256"}],"name":"TokenCheckpointed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"contract IERC20","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"userTokenTimeCursor","type":"uint256"}],"name":"TokensClaimed","type":"event"},{"inputs":[],"name":"checkpoint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"checkpointToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20[]","name":"tokens","type":"address[]"}],"name":"checkpointTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"checkpointUser","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"claimToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"contract IERC20[]","name":"tokens","type":"address[]"}],"name":"claimTokens","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"depositToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20[]","name":"tokens","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"name":"depositTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getDomainSeparator","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getNextNonce","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTimeCursor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"getTokenLastBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"getTokenTimeCursor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"getTokensDistributedInWeek","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"getTotalSupplyAtTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"getUserBalanceAtTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"getUserTimeCursor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"getUserTokenTimeCursor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getVotingEscrow","outputs":[{"internalType":"contract IVotingEscrow","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"isOnlyCallerEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"enabled","type":"bool"}],"name":"setOnlyCallerCheck","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"bool","name":"enabled","type":"bool"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"setOnlyCallerCheckWithSignature","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
6101206040523480156200001257600080fd5b5060405162002977380380620029778339810160408190526200003591620001d0565b604080518082018252600e81526d2332b2a234b9ba3934b13aba37b960911b602080830191825283518085019094526001808552603160f81b9185019182529251909120608052915190912060a0527f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60c0526002556001600160601b0319606083901b1660e052620000c881620001c4565b90506000620000d742620001c4565b905080821015620001055760405162461bcd60e51b8152600401620000fc9062000223565b60405180910390fd5b80821415620001b35760405163bd85b03960e01b81526000906001600160a01b0385169063bd85b039906200013f908590600401620002a0565b60206040518083038186803b1580156200015857600080fd5b505afa1580156200016d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200019391906200020a565b11620001b35760405162461bcd60e51b8152600401620000fc9062000258565b5061010081905260035550620002a9565b62093a80908190040290565b60008060408385031215620001e3578182fd5b82516001600160a01b0381168114620001fa578283fd5b6020939093015192949293505050565b6000602082840312156200021c578081fd5b5051919050565b6020808252818101527f43616e6e6f74207374617274206265666f72652063757272656e74207765656b604082015260600190565b60208082526028908201527f5a65726f20746f74616c20737570706c7920726573756c747320696e206c6f736040820152677420746f6b656e7360c01b606082015260800190565b90815260200190565b60805160a05160c05160e05160601c6101005161265e62000319600039806109ab5280610b0a5280610b6f5280610eec52508061033e52806108cd5280610a7a5280610c825280611453528061152752806119bc5250806118805250806118c25250806118a1525061265e6000f3fe608060405234801561001057600080fd5b50600436106101825760003560e01c806390193b7c116100d8578063ca31879d1161008c578063e811f44b11610066578063e811f44b1461030e578063ed24911d14610321578063fcaa54ee1461032957610182565b8063ca31879d146102d5578063d3dc4ca1146102e8578063de681faf146102fb57610182565b8063a1648aa5116100bd578063a1648aa51461029a578063acbc1428146102ba578063c2c4c5c1146102cd57610182565b806390193b7c14610274578063905d10ac1461028757610182565b80634f3c50901161013a57806382aa5ad41161011457806382aa5ad414610239578063876e69a114610241578063887204671461025457610182565b80634f3c5090146102005780637b8d6221146102135780638050a7ee1461022657610182565b80632308805b1161016b5780632308805b146101ba578063338b5dea146101da5780633902b9bc146101ed57610182565b806308b0308a1461018757806314866e08146101a5575b600080fd5b61018f61033c565b60405161019c91906122df565b60405180910390f35b6101b86101b3366004611f44565b610360565b005b6101cd6101c8366004611f44565b61037c565b60405161019c91906123f8565b6101b86101e83660046120ba565b6103ca565b6101b86101fb366004611f44565b610416565b6101cd61020e36600461225d565b610429565b6101b8610221366004612125565b61043b565b6101cd610234366004612082565b61051e565b6101cd610533565b6101cd61024f366004611f44565b610539565b610267610262366004611f60565b610577565b60405161019c91906123b5565b6101cd610282366004611f44565b61065a565b6101b86102953660046120e5565b610682565b6102ad6102a8366004611f44565b6106b7565b60405161019c91906123ed565b6101cd6102c8366004611f44565b6106e2565b6101b8610720565b6101cd6102e3366004612082565b61073a565b6101cd6102f63660046120ba565b610782565b6101cd6103093660046120ba565b6107b7565b6101b861031c36600461218e565b6107ec565b6101cd6107f6565b6101b8610337366004611fb3565b610805565b7f000000000000000000000000000000000000000000000000000000000000000090565b610368610876565b6103718161088d565b610379610e5d565b50565b73ffffffffffffffffffffffffffffffffffffffff1660009081526005602052604090205470010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff1690565b6103d2610876565b6103dd826000610e64565b6103ff73ffffffffffffffffffffffffffffffffffffffff831633308461128e565b61040a826001610e64565b610412610e5d565b5050565b61041e610876565b610371816001610e64565b60009081526004602052604090205490565b610443610876565b61044d8382611331565b8260005b8181101561050e5761048486868381811061046857fe5b905060200201602081019061047d9190611f44565b6000610e64565b6104db333086868581811061049557fe5b905060200201358989868181106104a857fe5b90506020020160208101906104bd9190611f44565b73ffffffffffffffffffffffffffffffffffffffff1692919061128e565b6105068686838181106104ea57fe5b90506020020160208101906104ff9190611f44565b6001610e64565b600101610451565b5050610518610e5d565b50505050565b600061052a838361133e565b90505b92915050565b60035490565b73ffffffffffffffffffffffffffffffffffffffff1660009081526007602052604090205468010000000000000000900467ffffffffffffffff1690565b6060610581610876565b8361058b816113d6565b610593611428565b61059c8561088d565b8260608167ffffffffffffffff811180156105b657600080fd5b506040519080825280602002602001820160405280156105e0578160200160208202803683370190505b50905060005b82811015610646576105fd87878381811061046857fe5b6106278888888481811061060d57fe5b90506020020160208101906106229190611f44565b6115d2565b82828151811061063357fe5b60209081029190910101526001016105e6565b5092505050610653610e5d565b9392505050565b73ffffffffffffffffffffffffffffffffffffffff1660009081526020819052604090205490565b61068a610876565b8060005b818110156106ad576106a58484838181106104ea57fe5b60010161068e565b5050610412610e5d565b73ffffffffffffffffffffffffffffffffffffffff1660009081526001602052604090205460ff1690565b73ffffffffffffffffffffffffffffffffffffffff1660009081526005602052604090205468010000000000000000900467ffffffffffffffff1690565b610728610876565b610730611428565b610738610e5d565b565b6000610744610876565b8261074e816113d6565b610756611428565b61075f8461088d565b61076a836000610e64565b600061077685856115d2565b9250505061052d610e5d565b73ffffffffffffffffffffffffffffffffffffffff919091166000908152600660209081526040808320938352929052205490565b73ffffffffffffffffffffffffffffffffffffffff919091166000908152600860209081526040808320938352929052205490565b61037933826117ef565b600061080061187c565b905090565b60007fbd291ffccec065968fe20c5f8debdad73ab50837733f357eeae8814178015a9084846108338761065a565b6040516020016108469493929190612401565b60405160208183030381529060405280519060200120905061086c8482846101f8611919565b61051884846117ef565b610887600280541415610190611946565b60028055565b6040517f010ae75700000000000000000000000000000000000000000000000000000000815260009073ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000169063010ae757906109029085906004016122df565b60206040518083038186803b15801561091a57600080fd5b505afa15801561092e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109529190612275565b90508061095f5750610379565b73ffffffffffffffffffffffffffffffffffffffff82166000908152600760205260408120805490916801000000000000000090910467ffffffffffffffff1690816109d9576109d2857f0000000000000000000000000000000000000000000000000000000000000000600087611954565b9050610a2c565b4282106109e95750505050610379565b50815470010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff1660148185031115610a2c57610a2985838387611954565b90505b80610a35575060015b610a3d611ebb565b6040517f28d09d4700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016906328d09d4790610ab1908990869060040161238f565b60806040518083038186803b158015610ac957600080fd5b505afa158015610add573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b019190612206565b905082610bd5577f00000000000000000000000000000000000000000000000000000000000000004211610b6a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b6190612548565b60405180910390fd5b610ba07f0000000000000000000000000000000000000000000000000000000000000000610b9b8360400151611a75565b611a85565b84547fffffffffffffffffffffffffffffffffffffffffffffffff00000000000000001667ffffffffffffffff821617855592505b610bdd611ebb565b60005b6032811015610dc25782604001518510158015610bfd5750868411155b15610d115760018401935082915086841115610c455760405180608001604052806000600f0b81526020016000600f0b81526020016000815260200160008152509250610d0c565b6040517f28d09d4700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016906328d09d4790610cb9908b90889060040161238f565b60806040518083038186803b158015610cd157600080fd5b505afa158015610ce5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d099190612206565b92505b610dba565b428510610d1d57610dc2565b6000826040015186039050600081846020015102600f0b8460000151600f0b13610d48576000610d59565b81846020015102846000015103600f0b5b905080158015610d6857508886115b15610d7f57610d7642611a75565b96505050610dc2565b73ffffffffffffffffffffffffffffffffffffffff8a1660009081526008602090815260408083208a84529091529020555062093a80909401935b600101610be0565b505083546fffffffffffffffffffffffffffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9290920167ffffffffffffffff90811670010000000000000000000000000000000002929092177fffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff1668010000000000000000939092169290920217909155505050565b6001600255565b73ffffffffffffffffffffffffffffffffffffffff82166000908152600560205260408120805490916801000000000000000090910467ffffffffffffffff169081610f4857429150610eb642611a9c565b83547fffffffffffffffffffffffffffffffffffffffffffffffff00000000000000001667ffffffffffffffff919091161783557f00000000000000000000000000000000000000000000000000000000000000004211610f43576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b6190612548565b610f9a565b814203905083610f9a576000610f5d83611a9c565b610f6642611a9c565b14905060006201518042610f7942611a75565b03109050818015610f88575080155b15610f97575050505050610412565b50505b82547fffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff16680100000000000000004267ffffffffffffffff16021783556040517f70a0823100000000000000000000000000000000000000000000000000000000815260009073ffffffffffffffffffffffffffffffffffffffff8716906370a082319061102c9030906004016122df565b60206040518083038186803b15801561104457600080fd5b505afa158015611058573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061107c9190612275565b84549091506000906110b590839070010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff16611aa8565b9050806110c6575050505050610412565b6fffffffffffffffffffffffffffffffff821115611110576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b6190612511565b84546fffffffffffffffffffffffffffffffff808416700100000000000000000000000000000000029116178555600061114985611a9c565b73ffffffffffffffffffffffffffffffffffffffff8916600090815260066020526040812091925090815b6014811015611246578362093a80019250824210156111e4578615801561119a57508742145b156111b85760008481526020839052604090208054860190556111df565b868842038602816111c557fe5b600086815260208590526040902080549290910490910190555b611246565b861580156111f157508783145b1561120f576000848152602083905260409020805486019055611236565b8688840386028161121c57fe5b600086815260208590526040902080549290910490910190555b9196508692508291600101611174565b507f9b7f1a85a4c9b4e59e1b6527d9969c50cdfb3a1a467d0c4a51fb0ed8bf07f1308a858960405161127a939291906124e3565b60405180910390a150505050505050505050565b610518846323b872dd60e01b8585856040516024016112af93929190612300565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152611ab6565b6104128183146067611946565b73ffffffffffffffffffffffffffffffffffffffff8083166000908152600960209081526040808320938516835292905290812054801561138057905061052d565b73ffffffffffffffffffffffffffffffffffffffff808516600090815260076020908152604080832054938716835260059091529020546113ce9167ffffffffffffffff9081169116611a85565b949350505050565b73ffffffffffffffffffffffffffffffffffffffff811660009081526001602052604090205460ff1615610379576103793373ffffffffffffffffffffffffffffffffffffffff831614610191611946565b600354600061143642611a9c565b90508082118061144557504281145b15611451575050610738565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663c2c4c5c16040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156114b957600080fd5b505af11580156114cd573d6000803e3d6000fd5b5050505060005b60148110156115cb57818311156114ea576115cb565b6040517fbd85b03900000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000169063bd85b0399061155c9086906004016123f8565b60206040518083038186803b15801561157457600080fd5b505afa158015611588573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115ac9190612275565b60008481526004602052604090205562093a80909201916001016114d4565b5050600355565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260056020526040812081611602858561133e565b60035473ffffffffffffffffffffffffffffffffffffffff8716600090815260076020526040812054929350916116829161165c91611657919068010000000000000000900467ffffffffffffffff16611b63565b611a75565b845461167d9068010000000000000000900467ffffffffffffffff16611a9c565b611b63565b73ffffffffffffffffffffffffffffffffffffffff8087166000908152600660209081526040808320938b16835260089091528120929350909190805b6014811015611713578486106116d457611713565b600086815260046020908152604080832054868352818420549288905292205402816116fc57fe5b62093a8097909701960491909101906001016116bf565b5073ffffffffffffffffffffffffffffffffffffffff808a166000908152600960209081526040808320938c1683529290522085905580156117e35785546fffffffffffffffffffffffffffffffff700100000000000000000000000000000000808304821684900382160291161786556117a573ffffffffffffffffffffffffffffffffffffffff89168a83611b72565b7fff097c7d8b1957a4ff09ef1361b5fb54dcede3941ba836d0beb9d10bec725de6898983886040516117da9493929190612359565b60405180910390a15b98975050505050505050565b73ffffffffffffffffffffffffffffffffffffffff82166000908152600160205260409081902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016831515179055517fac9874a7a931a3f5c9f202c6d9cf40de5d21506993c9f9c38ca8265add89584c906118709084908490612331565b60405180910390a15050565b60007f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000006118e9611b96565b306040516020016118fe959493929190612434565b60405160208183030381529060405280519060200120905090565b6105188484847fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff85611b9a565b816104125761041281611bfe565b60008282825b6080811015611a695781831061196f57611a69565b600282840181010461197f611ebb565b6040517f28d09d4700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016906328d09d47906119f3908d90869060040161238f565b60806040518083038186803b158015611a0b57600080fd5b505afa158015611a1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a439190612206565b905088816040015111611a5857819450611a5f565b6001820393505b505060010161195a565b50909695505050505050565b600061052d62093a7f8301611a9c565b600081831015611a95578161052a565b5090919050565b62093a80908190040290565b600061052a83836001611c6b565b600060608373ffffffffffffffffffffffffffffffffffffffff1683604051611adf919061228d565b6000604051808303816000865af19150503d8060008114611b1c576040519150601f19603f3d011682016040523d82523d6000602084013e611b21565b606091505b50915091506000821415611b39573d6000803e3d6000fd5b610518815160001480611b5b575081806020019051810190611b5b91906121aa565b6101a2611946565b6000818310611a95578161052a565b611b918363a9059cbb60e01b84846040516024016112af92919061238f565b505050565b4690565b6000611ba585611c81565b9050611bbb611bb5878387611cba565b83611946565b611bca428410156101b8611946565b50505073ffffffffffffffffffffffffffffffffffffffff9092166000908152602081905260409020805460010190555050565b7f08c379a0000000000000000000000000000000000000000000000000000000006000908152602060045260076024526642414c23000030600a808404818106603090810160081b95839006959095019082900491820690940160101b939093010160c81b604452606490fd5b6000611c7a8484111583611946565b5050900390565b6000611c8b61187c565b82604051602001611c9d9291906122a9565b604051602081830303815290604052805190602001209050919050565b6000611cdb8473ffffffffffffffffffffffffffffffffffffffff16611dc2565b15611db0576040517f1626ba7e000000000000000000000000000000000000000000000000000000008082529073ffffffffffffffffffffffffffffffffffffffff861690631626ba7e90611d36908790879060040161246d565b60206040518083038186803b158015611d4e57600080fd5b505afa158015611d62573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d8691906121c6565b7fffffffff0000000000000000000000000000000000000000000000000000000016149050610653565b611dbb848484611dc8565b9050610653565b3b151590565b6000611dda82516041146101b9611946565b60208281015160408085015160608601518251600080825295019283905292939092811a91600190611e139089908590889088906124c5565b6020604051602081039080840390855afa158015611e35573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff8116158015906117e357508773ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161498975050505050505050565b60405180608001604052806000600f0b81526020016000600f0b815260200160008152602001600081525090565b60008083601f840112611efa578182fd5b50813567ffffffffffffffff811115611f11578182fd5b6020830191508360208083028501011115611f2b57600080fd5b9250929050565b8051600f81900b811461052d57600080fd5b600060208284031215611f55578081fd5b8135610653816125f8565b600080600060408486031215611f74578182fd5b8335611f7f816125f8565b9250602084013567ffffffffffffffff811115611f9a578283fd5b611fa686828701611ee9565b9497909650939450505050565b600080600060608486031215611fc7578283fd5b8335611fd2816125f8565b9250602084810135611fe38161261a565b9250604085013567ffffffffffffffff80821115611fff578384fd5b818701915087601f830112612012578384fd5b813581811115612020578485fd5b612050847fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f840116016125a5565b91508082528884828501011115612065578485fd5b808484018584013784848284010152508093505050509250925092565b60008060408385031215612094578182fd5b823561209f816125f8565b915060208301356120af816125f8565b809150509250929050565b600080604083850312156120cc578182fd5b82356120d7816125f8565b946020939093013593505050565b600080602083850312156120f7578182fd5b823567ffffffffffffffff81111561210d578283fd5b61211985828601611ee9565b90969095509350505050565b6000806000806040858703121561213a578081fd5b843567ffffffffffffffff80821115612151578283fd5b61215d88838901611ee9565b90965094506020870135915080821115612175578283fd5b5061218287828801611ee9565b95989497509550505050565b60006020828403121561219f578081fd5b81356106538161261a565b6000602082840312156121bb578081fd5b81516106538161261a565b6000602082840312156121d7578081fd5b81517fffffffff0000000000000000000000000000000000000000000000000000000081168114610653578182fd5b600060808284031215612217578081fd5b61222160806125a5565b61222b8484611f32565b815261223a8460208501611f32565b602082015260408301516040820152606083015160608201528091505092915050565b60006020828403121561226e578081fd5b5035919050565b600060208284031215612286578081fd5b5051919050565b6000825161229f8184602087016125cc565b9190910192915050565b7f190100000000000000000000000000000000000000000000000000000000000081526002810192909252602282015260420190565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b73ffffffffffffffffffffffffffffffffffffffff9384168152919092166020820152604081019190915260600190565b73ffffffffffffffffffffffffffffffffffffffff9290921682521515602082015260400190565b73ffffffffffffffffffffffffffffffffffffffff94851681529290931660208301526040820152606081019190915260800190565b73ffffffffffffffffffffffffffffffffffffffff929092168252602082015260400190565b6020808252825182820181905260009190848201906040850190845b81811015611a69578351835292840192918401916001016123d1565b901515815260200190565b90815260200190565b93845273ffffffffffffffffffffffffffffffffffffffff92909216602084015215156040830152606082015260800190565b94855260208501939093526040840191909152606083015273ffffffffffffffffffffffffffffffffffffffff16608082015260a00190565b60008382526040602083015282518060408401526124928160608501602087016125cc565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016919091016060019392505050565b93845260ff9290921660208401526040830152606082015260800190565b73ffffffffffffffffffffffffffffffffffffffff9390931683526020830191909152604082015260600190565b6020808252601e908201527f4d6178696d756d20746f6b656e2062616c616e63652065786365656465640000604082015260600190565b60208082526024908201527f46656520646973747269627574696f6e20686173206e6f74207374617274656460408201527f2079657400000000000000000000000000000000000000000000000000000000606082015260800190565b60405181810167ffffffffffffffff811182821017156125c457600080fd5b604052919050565b60005b838110156125e75781810151838201526020016125cf565b838111156105185750506000910152565b73ffffffffffffffffffffffffffffffffffffffff8116811461037957600080fd5b801515811461037957600080fdfea26469706673582212206e91ba3bf7fae396c65faebeef9a2ad330d9087256688eb7df956fb362f6a77264736f6c63430007010033000000000000000000000000c128a9954e6c874ea3d62ce62b468ba073093f250000000000000000000000000000000000000000000000000000000062cf5c80
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106101825760003560e01c806390193b7c116100d8578063ca31879d1161008c578063e811f44b11610066578063e811f44b1461030e578063ed24911d14610321578063fcaa54ee1461032957610182565b8063ca31879d146102d5578063d3dc4ca1146102e8578063de681faf146102fb57610182565b8063a1648aa5116100bd578063a1648aa51461029a578063acbc1428146102ba578063c2c4c5c1146102cd57610182565b806390193b7c14610274578063905d10ac1461028757610182565b80634f3c50901161013a57806382aa5ad41161011457806382aa5ad414610239578063876e69a114610241578063887204671461025457610182565b80634f3c5090146102005780637b8d6221146102135780638050a7ee1461022657610182565b80632308805b1161016b5780632308805b146101ba578063338b5dea146101da5780633902b9bc146101ed57610182565b806308b0308a1461018757806314866e08146101a5575b600080fd5b61018f61033c565b60405161019c91906122df565b60405180910390f35b6101b86101b3366004611f44565b610360565b005b6101cd6101c8366004611f44565b61037c565b60405161019c91906123f8565b6101b86101e83660046120ba565b6103ca565b6101b86101fb366004611f44565b610416565b6101cd61020e36600461225d565b610429565b6101b8610221366004612125565b61043b565b6101cd610234366004612082565b61051e565b6101cd610533565b6101cd61024f366004611f44565b610539565b610267610262366004611f60565b610577565b60405161019c91906123b5565b6101cd610282366004611f44565b61065a565b6101b86102953660046120e5565b610682565b6102ad6102a8366004611f44565b6106b7565b60405161019c91906123ed565b6101cd6102c8366004611f44565b6106e2565b6101b8610720565b6101cd6102e3366004612082565b61073a565b6101cd6102f63660046120ba565b610782565b6101cd6103093660046120ba565b6107b7565b6101b861031c36600461218e565b6107ec565b6101cd6107f6565b6101b8610337366004611fb3565b610805565b7f000000000000000000000000c128a9954e6c874ea3d62ce62b468ba073093f2590565b610368610876565b6103718161088d565b610379610e5d565b50565b73ffffffffffffffffffffffffffffffffffffffff1660009081526005602052604090205470010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff1690565b6103d2610876565b6103dd826000610e64565b6103ff73ffffffffffffffffffffffffffffffffffffffff831633308461128e565b61040a826001610e64565b610412610e5d565b5050565b61041e610876565b610371816001610e64565b60009081526004602052604090205490565b610443610876565b61044d8382611331565b8260005b8181101561050e5761048486868381811061046857fe5b905060200201602081019061047d9190611f44565b6000610e64565b6104db333086868581811061049557fe5b905060200201358989868181106104a857fe5b90506020020160208101906104bd9190611f44565b73ffffffffffffffffffffffffffffffffffffffff1692919061128e565b6105068686838181106104ea57fe5b90506020020160208101906104ff9190611f44565b6001610e64565b600101610451565b5050610518610e5d565b50505050565b600061052a838361133e565b90505b92915050565b60035490565b73ffffffffffffffffffffffffffffffffffffffff1660009081526007602052604090205468010000000000000000900467ffffffffffffffff1690565b6060610581610876565b8361058b816113d6565b610593611428565b61059c8561088d565b8260608167ffffffffffffffff811180156105b657600080fd5b506040519080825280602002602001820160405280156105e0578160200160208202803683370190505b50905060005b82811015610646576105fd87878381811061046857fe5b6106278888888481811061060d57fe5b90506020020160208101906106229190611f44565b6115d2565b82828151811061063357fe5b60209081029190910101526001016105e6565b5092505050610653610e5d565b9392505050565b73ffffffffffffffffffffffffffffffffffffffff1660009081526020819052604090205490565b61068a610876565b8060005b818110156106ad576106a58484838181106104ea57fe5b60010161068e565b5050610412610e5d565b73ffffffffffffffffffffffffffffffffffffffff1660009081526001602052604090205460ff1690565b73ffffffffffffffffffffffffffffffffffffffff1660009081526005602052604090205468010000000000000000900467ffffffffffffffff1690565b610728610876565b610730611428565b610738610e5d565b565b6000610744610876565b8261074e816113d6565b610756611428565b61075f8461088d565b61076a836000610e64565b600061077685856115d2565b9250505061052d610e5d565b73ffffffffffffffffffffffffffffffffffffffff919091166000908152600660209081526040808320938352929052205490565b73ffffffffffffffffffffffffffffffffffffffff919091166000908152600860209081526040808320938352929052205490565b61037933826117ef565b600061080061187c565b905090565b60007fbd291ffccec065968fe20c5f8debdad73ab50837733f357eeae8814178015a9084846108338761065a565b6040516020016108469493929190612401565b60405160208183030381529060405280519060200120905061086c8482846101f8611919565b61051884846117ef565b610887600280541415610190611946565b60028055565b6040517f010ae75700000000000000000000000000000000000000000000000000000000815260009073ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000c128a9954e6c874ea3d62ce62b468ba073093f25169063010ae757906109029085906004016122df565b60206040518083038186803b15801561091a57600080fd5b505afa15801561092e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109529190612275565b90508061095f5750610379565b73ffffffffffffffffffffffffffffffffffffffff82166000908152600760205260408120805490916801000000000000000090910467ffffffffffffffff1690816109d9576109d2857f0000000000000000000000000000000000000000000000000000000062cf5c80600087611954565b9050610a2c565b4282106109e95750505050610379565b50815470010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff1660148185031115610a2c57610a2985838387611954565b90505b80610a35575060015b610a3d611ebb565b6040517f28d09d4700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000c128a9954e6c874ea3d62ce62b468ba073093f2516906328d09d4790610ab1908990869060040161238f565b60806040518083038186803b158015610ac957600080fd5b505afa158015610add573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b019190612206565b905082610bd5577f0000000000000000000000000000000000000000000000000000000062cf5c804211610b6a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b6190612548565b60405180910390fd5b610ba07f0000000000000000000000000000000000000000000000000000000062cf5c80610b9b8360400151611a75565b611a85565b84547fffffffffffffffffffffffffffffffffffffffffffffffff00000000000000001667ffffffffffffffff821617855592505b610bdd611ebb565b60005b6032811015610dc25782604001518510158015610bfd5750868411155b15610d115760018401935082915086841115610c455760405180608001604052806000600f0b81526020016000600f0b81526020016000815260200160008152509250610d0c565b6040517f28d09d4700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000c128a9954e6c874ea3d62ce62b468ba073093f2516906328d09d4790610cb9908b90889060040161238f565b60806040518083038186803b158015610cd157600080fd5b505afa158015610ce5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d099190612206565b92505b610dba565b428510610d1d57610dc2565b6000826040015186039050600081846020015102600f0b8460000151600f0b13610d48576000610d59565b81846020015102846000015103600f0b5b905080158015610d6857508886115b15610d7f57610d7642611a75565b96505050610dc2565b73ffffffffffffffffffffffffffffffffffffffff8a1660009081526008602090815260408083208a84529091529020555062093a80909401935b600101610be0565b505083546fffffffffffffffffffffffffffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9290920167ffffffffffffffff90811670010000000000000000000000000000000002929092177fffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff1668010000000000000000939092169290920217909155505050565b6001600255565b73ffffffffffffffffffffffffffffffffffffffff82166000908152600560205260408120805490916801000000000000000090910467ffffffffffffffff169081610f4857429150610eb642611a9c565b83547fffffffffffffffffffffffffffffffffffffffffffffffff00000000000000001667ffffffffffffffff919091161783557f0000000000000000000000000000000000000000000000000000000062cf5c804211610f43576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b6190612548565b610f9a565b814203905083610f9a576000610f5d83611a9c565b610f6642611a9c565b14905060006201518042610f7942611a75565b03109050818015610f88575080155b15610f97575050505050610412565b50505b82547fffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff16680100000000000000004267ffffffffffffffff16021783556040517f70a0823100000000000000000000000000000000000000000000000000000000815260009073ffffffffffffffffffffffffffffffffffffffff8716906370a082319061102c9030906004016122df565b60206040518083038186803b15801561104457600080fd5b505afa158015611058573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061107c9190612275565b84549091506000906110b590839070010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff16611aa8565b9050806110c6575050505050610412565b6fffffffffffffffffffffffffffffffff821115611110576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b6190612511565b84546fffffffffffffffffffffffffffffffff808416700100000000000000000000000000000000029116178555600061114985611a9c565b73ffffffffffffffffffffffffffffffffffffffff8916600090815260066020526040812091925090815b6014811015611246578362093a80019250824210156111e4578615801561119a57508742145b156111b85760008481526020839052604090208054860190556111df565b868842038602816111c557fe5b600086815260208590526040902080549290910490910190555b611246565b861580156111f157508783145b1561120f576000848152602083905260409020805486019055611236565b8688840386028161121c57fe5b600086815260208590526040902080549290910490910190555b9196508692508291600101611174565b507f9b7f1a85a4c9b4e59e1b6527d9969c50cdfb3a1a467d0c4a51fb0ed8bf07f1308a858960405161127a939291906124e3565b60405180910390a150505050505050505050565b610518846323b872dd60e01b8585856040516024016112af93929190612300565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152611ab6565b6104128183146067611946565b73ffffffffffffffffffffffffffffffffffffffff8083166000908152600960209081526040808320938516835292905290812054801561138057905061052d565b73ffffffffffffffffffffffffffffffffffffffff808516600090815260076020908152604080832054938716835260059091529020546113ce9167ffffffffffffffff9081169116611a85565b949350505050565b73ffffffffffffffffffffffffffffffffffffffff811660009081526001602052604090205460ff1615610379576103793373ffffffffffffffffffffffffffffffffffffffff831614610191611946565b600354600061143642611a9c565b90508082118061144557504281145b15611451575050610738565b7f000000000000000000000000c128a9954e6c874ea3d62ce62b468ba073093f2573ffffffffffffffffffffffffffffffffffffffff1663c2c4c5c16040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156114b957600080fd5b505af11580156114cd573d6000803e3d6000fd5b5050505060005b60148110156115cb57818311156114ea576115cb565b6040517fbd85b03900000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000c128a9954e6c874ea3d62ce62b468ba073093f25169063bd85b0399061155c9086906004016123f8565b60206040518083038186803b15801561157457600080fd5b505afa158015611588573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115ac9190612275565b60008481526004602052604090205562093a80909201916001016114d4565b5050600355565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260056020526040812081611602858561133e565b60035473ffffffffffffffffffffffffffffffffffffffff8716600090815260076020526040812054929350916116829161165c91611657919068010000000000000000900467ffffffffffffffff16611b63565b611a75565b845461167d9068010000000000000000900467ffffffffffffffff16611a9c565b611b63565b73ffffffffffffffffffffffffffffffffffffffff8087166000908152600660209081526040808320938b16835260089091528120929350909190805b6014811015611713578486106116d457611713565b600086815260046020908152604080832054868352818420549288905292205402816116fc57fe5b62093a8097909701960491909101906001016116bf565b5073ffffffffffffffffffffffffffffffffffffffff808a166000908152600960209081526040808320938c1683529290522085905580156117e35785546fffffffffffffffffffffffffffffffff700100000000000000000000000000000000808304821684900382160291161786556117a573ffffffffffffffffffffffffffffffffffffffff89168a83611b72565b7fff097c7d8b1957a4ff09ef1361b5fb54dcede3941ba836d0beb9d10bec725de6898983886040516117da9493929190612359565b60405180910390a15b98975050505050505050565b73ffffffffffffffffffffffffffffffffffffffff82166000908152600160205260409081902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016831515179055517fac9874a7a931a3f5c9f202c6d9cf40de5d21506993c9f9c38ca8265add89584c906118709084908490612331565b60405180910390a15050565b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f7f0618c188edbe06a8ffa15e11b4f74493cfd6f23aba7fab610364d908072aac997fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc66118e9611b96565b306040516020016118fe959493929190612434565b60405160208183030381529060405280519060200120905090565b6105188484847fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff85611b9a565b816104125761041281611bfe565b60008282825b6080811015611a695781831061196f57611a69565b600282840181010461197f611ebb565b6040517f28d09d4700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000c128a9954e6c874ea3d62ce62b468ba073093f2516906328d09d47906119f3908d90869060040161238f565b60806040518083038186803b158015611a0b57600080fd5b505afa158015611a1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a439190612206565b905088816040015111611a5857819450611a5f565b6001820393505b505060010161195a565b50909695505050505050565b600061052d62093a7f8301611a9c565b600081831015611a95578161052a565b5090919050565b62093a80908190040290565b600061052a83836001611c6b565b600060608373ffffffffffffffffffffffffffffffffffffffff1683604051611adf919061228d565b6000604051808303816000865af19150503d8060008114611b1c576040519150601f19603f3d011682016040523d82523d6000602084013e611b21565b606091505b50915091506000821415611b39573d6000803e3d6000fd5b610518815160001480611b5b575081806020019051810190611b5b91906121aa565b6101a2611946565b6000818310611a95578161052a565b611b918363a9059cbb60e01b84846040516024016112af92919061238f565b505050565b4690565b6000611ba585611c81565b9050611bbb611bb5878387611cba565b83611946565b611bca428410156101b8611946565b50505073ffffffffffffffffffffffffffffffffffffffff9092166000908152602081905260409020805460010190555050565b7f08c379a0000000000000000000000000000000000000000000000000000000006000908152602060045260076024526642414c23000030600a808404818106603090810160081b95839006959095019082900491820690940160101b939093010160c81b604452606490fd5b6000611c7a8484111583611946565b5050900390565b6000611c8b61187c565b82604051602001611c9d9291906122a9565b604051602081830303815290604052805190602001209050919050565b6000611cdb8473ffffffffffffffffffffffffffffffffffffffff16611dc2565b15611db0576040517f1626ba7e000000000000000000000000000000000000000000000000000000008082529073ffffffffffffffffffffffffffffffffffffffff861690631626ba7e90611d36908790879060040161246d565b60206040518083038186803b158015611d4e57600080fd5b505afa158015611d62573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d8691906121c6565b7fffffffff0000000000000000000000000000000000000000000000000000000016149050610653565b611dbb848484611dc8565b9050610653565b3b151590565b6000611dda82516041146101b9611946565b60208281015160408085015160608601518251600080825295019283905292939092811a91600190611e139089908590889088906124c5565b6020604051602081039080840390855afa158015611e35573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff8116158015906117e357508773ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161498975050505050505050565b60405180608001604052806000600f0b81526020016000600f0b815260200160008152602001600081525090565b60008083601f840112611efa578182fd5b50813567ffffffffffffffff811115611f11578182fd5b6020830191508360208083028501011115611f2b57600080fd5b9250929050565b8051600f81900b811461052d57600080fd5b600060208284031215611f55578081fd5b8135610653816125f8565b600080600060408486031215611f74578182fd5b8335611f7f816125f8565b9250602084013567ffffffffffffffff811115611f9a578283fd5b611fa686828701611ee9565b9497909650939450505050565b600080600060608486031215611fc7578283fd5b8335611fd2816125f8565b9250602084810135611fe38161261a565b9250604085013567ffffffffffffffff80821115611fff578384fd5b818701915087601f830112612012578384fd5b813581811115612020578485fd5b612050847fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f840116016125a5565b91508082528884828501011115612065578485fd5b808484018584013784848284010152508093505050509250925092565b60008060408385031215612094578182fd5b823561209f816125f8565b915060208301356120af816125f8565b809150509250929050565b600080604083850312156120cc578182fd5b82356120d7816125f8565b946020939093013593505050565b600080602083850312156120f7578182fd5b823567ffffffffffffffff81111561210d578283fd5b61211985828601611ee9565b90969095509350505050565b6000806000806040858703121561213a578081fd5b843567ffffffffffffffff80821115612151578283fd5b61215d88838901611ee9565b90965094506020870135915080821115612175578283fd5b5061218287828801611ee9565b95989497509550505050565b60006020828403121561219f578081fd5b81356106538161261a565b6000602082840312156121bb578081fd5b81516106538161261a565b6000602082840312156121d7578081fd5b81517fffffffff0000000000000000000000000000000000000000000000000000000081168114610653578182fd5b600060808284031215612217578081fd5b61222160806125a5565b61222b8484611f32565b815261223a8460208501611f32565b602082015260408301516040820152606083015160608201528091505092915050565b60006020828403121561226e578081fd5b5035919050565b600060208284031215612286578081fd5b5051919050565b6000825161229f8184602087016125cc565b9190910192915050565b7f190100000000000000000000000000000000000000000000000000000000000081526002810192909252602282015260420190565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b73ffffffffffffffffffffffffffffffffffffffff9384168152919092166020820152604081019190915260600190565b73ffffffffffffffffffffffffffffffffffffffff9290921682521515602082015260400190565b73ffffffffffffffffffffffffffffffffffffffff94851681529290931660208301526040820152606081019190915260800190565b73ffffffffffffffffffffffffffffffffffffffff929092168252602082015260400190565b6020808252825182820181905260009190848201906040850190845b81811015611a69578351835292840192918401916001016123d1565b901515815260200190565b90815260200190565b93845273ffffffffffffffffffffffffffffffffffffffff92909216602084015215156040830152606082015260800190565b94855260208501939093526040840191909152606083015273ffffffffffffffffffffffffffffffffffffffff16608082015260a00190565b60008382526040602083015282518060408401526124928160608501602087016125cc565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016919091016060019392505050565b93845260ff9290921660208401526040830152606082015260800190565b73ffffffffffffffffffffffffffffffffffffffff9390931683526020830191909152604082015260600190565b6020808252601e908201527f4d6178696d756d20746f6b656e2062616c616e63652065786365656465640000604082015260600190565b60208082526024908201527f46656520646973747269627574696f6e20686173206e6f74207374617274656460408201527f2079657400000000000000000000000000000000000000000000000000000000606082015260800190565b60405181810167ffffffffffffffff811182821017156125c457600080fd5b604052919050565b60005b838110156125e75781810151838201526020016125cf565b838111156105185750506000910152565b73ffffffffffffffffffffffffffffffffffffffff8116811461037957600080fd5b801515811461037957600080fdfea26469706673582212206e91ba3bf7fae396c65faebeef9a2ad330d9087256688eb7df956fb362f6a77264736f6c63430007010033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000c128a9954e6c874ea3d62ce62b468ba073093f250000000000000000000000000000000000000000000000000000000062cf5c80
-----Decoded View---------------
Arg [0] : votingEscrow (address): 0xC128a9954e6c874eA3d62ce62B468bA073093F25
Arg [1] : startTime (uint256): 1657756800
-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 000000000000000000000000c128a9954e6c874ea3d62ce62b468ba073093f25
Arg [1] : 0000000000000000000000000000000000000000000000000000000062cf5c80
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.