Source Code
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Cross-Chain Transactions
Loading...
Loading
Contract Name:
TwabController
Compiler Version
v0.8.19+commit.7dd6d404
Optimization Enabled:
Yes with 200 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import { SafeCast } from "openzeppelin/utils/math/SafeCast.sol";
import { TwabLib } from "./libraries/TwabLib.sol";
import { ObservationLib } from "./libraries/ObservationLib.sol";
/// @notice Emitted when an account already points to the same delegate address that is being set
error SameDelegateAlreadySet(address delegate);
/// @notice Emitted when an account tries to transfer to the sponsorship address
error CannotTransferToSponsorshipAddress();
/// @notice Emitted when the period length is too short
error PeriodLengthTooShort();
/// @notice Emitted when the period offset is not in the past.
/// @param periodOffset The period offset that was passed in
error PeriodOffsetInFuture(uint48 periodOffset);
/// @notice Emitted when a user tries to mint or transfer to the zero address
error TransferToZeroAddress();
// The minimum period length
uint48 constant MINIMUM_PERIOD_LENGTH = 1 hours;
// Allows users to revoke their chances to win by delegating to the sponsorship address.
address constant SPONSORSHIP_ADDRESS = address(1);
/**
* @title Time-Weighted Average Balance Controller
* @author PoolTogether Inc.
* @dev Time-Weighted Average Balance Controller for ERC20 tokens.
* @notice This TwabController uses the TwabLib to provide token balances and on-chain historical
lookups to a user(s) time-weighted average balance. Each user is mapped to an
Account struct containing the TWAB history (ring buffer) and ring buffer parameters.
Every token.transfer() creates a new TWAB observation. The new TWAB observation is
stored in the circular ring buffer as either a new observation or rewriting a
previous observation with new parameters. One observation per period is stored.
The TwabLib guarantees minimum 1 year of search history if a period is a day.
*/
contract TwabController {
using SafeCast for uint256;
/// @notice Sets the minimum period length for Observations. When a period elapses, a new Observation is recorded, otherwise the most recent Observation is updated.
uint48 public immutable PERIOD_LENGTH;
/// @notice Sets the beginning timestamp for the first period. This allows us to maximize storage as well as line up periods with a chosen timestamp.
/// @dev Ensure that the PERIOD_OFFSET is in the past.
uint48 public immutable PERIOD_OFFSET;
/* ============ State ============ */
/// @notice Record of token holders TWABs for each account for each vault.
mapping(address => mapping(address => TwabLib.Account)) internal userObservations;
/// @notice Record of tickets total supply and ring buff parameters used for observation.
mapping(address => TwabLib.Account) internal totalSupplyObservations;
/// @notice vault => user => delegate.
mapping(address => mapping(address => address)) internal delegates;
/* ============ Events ============ */
/**
* @notice Emitted when a balance or delegateBalance is increased.
* @param vault the vault for which the balance increased
* @param user the users whose balance increased
* @param amount the amount the balance increased by
* @param delegateAmount the amount the delegateBalance increased by
*/
event IncreasedBalance(
address indexed vault,
address indexed user,
uint112 amount,
uint112 delegateAmount
);
/**
* @notice Emited when a balance or delegateBalance is decreased.
* @param vault the vault for which the balance decreased
* @param user the users whose balance decreased
* @param amount the amount the balance decreased by
* @param delegateAmount the amount the delegateBalance decreased by
*/
event DecreasedBalance(
address indexed vault,
address indexed user,
uint112 amount,
uint112 delegateAmount
);
/**
* @notice Emited when an Observation is recorded to the Ring Buffer.
* @param vault the vault for which the Observation was recorded
* @param user the users whose Observation was recorded
* @param balance the resulting balance
* @param delegateBalance the resulting delegated balance
* @param isNew whether the observation is new or not
* @param observation the observation that was created or updated
*/
event ObservationRecorded(
address indexed vault,
address indexed user,
uint112 balance,
uint112 delegateBalance,
bool isNew,
ObservationLib.Observation observation
);
/**
* @notice Emitted when a user delegates their balance to another address.
* @param vault the vault for which the balance was delegated
* @param delegator the user who delegated their balance
* @param delegate the user who received the delegated balance
*/
event Delegated(address indexed vault, address indexed delegator, address indexed delegate);
/**
* @notice Emitted when the total supply or delegateTotalSupply is increased.
* @param vault the vault for which the total supply increased
* @param amount the amount the total supply increased by
* @param delegateAmount the amount the delegateTotalSupply increased by
*/
event IncreasedTotalSupply(address indexed vault, uint112 amount, uint112 delegateAmount);
/**
* @notice Emitted when the total supply or delegateTotalSupply is decreased.
* @param vault the vault for which the total supply decreased
* @param amount the amount the total supply decreased by
* @param delegateAmount the amount the delegateTotalSupply decreased by
*/
event DecreasedTotalSupply(address indexed vault, uint112 amount, uint112 delegateAmount);
/**
* @notice Emited when a Total Supply Observation is recorded to the Ring Buffer.
* @param vault the vault for which the Observation was recorded
* @param balance the resulting balance
* @param delegateBalance the resulting delegated balance
* @param isNew whether the observation is new or not
* @param observation the observation that was created or updated
*/
event TotalSupplyObservationRecorded(
address indexed vault,
uint112 balance,
uint112 delegateBalance,
bool isNew,
ObservationLib.Observation observation
);
/* ============ Constructor ============ */
/**
* @notice Construct a new TwabController.
* @dev Reverts if the period offset is in the future.
* @param _periodLength Sets the minimum period length for Observations. When a period elapses, a new Observation
* is recorded, otherwise the most recent Observation is updated.
* @param _periodOffset Sets the beginning timestamp for the first period. This allows us to maximize storage as well
* as line up periods with a chosen timestamp.
*/
constructor(uint48 _periodLength, uint48 _periodOffset) {
if (_periodLength < MINIMUM_PERIOD_LENGTH) {
revert PeriodLengthTooShort();
}
if (_periodOffset > block.timestamp) {
revert PeriodOffsetInFuture(_periodOffset);
}
PERIOD_LENGTH = _periodLength;
PERIOD_OFFSET = _periodOffset;
}
/* ============ External Read Functions ============ */
/**
* @notice Loads the current TWAB Account data for a specific vault stored for a user.
* @dev Note this is a very expensive function
* @param vault the vault for which the data is being queried
* @param user the user whose data is being queried
* @return The current TWAB Account data of the user
*/
function getAccount(address vault, address user) external view returns (TwabLib.Account memory) {
return userObservations[vault][user];
}
/**
* @notice Loads the current total supply TWAB Account data for a specific vault.
* @dev Note this is a very expensive function
* @param vault the vault for which the data is being queried
* @return The current total supply TWAB Account data
*/
function getTotalSupplyAccount(address vault) external view returns (TwabLib.Account memory) {
return totalSupplyObservations[vault];
}
/**
* @notice The current token balance of a user for a specific vault.
* @param vault the vault for which the balance is being queried
* @param user the user whose balance is being queried
* @return The current token balance of the user
*/
function balanceOf(address vault, address user) external view returns (uint256) {
return userObservations[vault][user].details.balance;
}
/**
* @notice The total supply of tokens for a vault.
* @param vault the vault for which the total supply is being queried
* @return The total supply of tokens for a vault
*/
function totalSupply(address vault) external view returns (uint256) {
return totalSupplyObservations[vault].details.balance;
}
/**
* @notice The total delegated amount of tokens for a vault.
* @dev Delegated balance is not 1:1 with the token total supply. Users may delegate their
* balance to the sponsorship address, which will result in those tokens being subtracted
* from the total.
* @param vault the vault for which the total delegated supply is being queried
* @return The total delegated amount of tokens for a vault
*/
function totalSupplyDelegateBalance(address vault) external view returns (uint256) {
return totalSupplyObservations[vault].details.delegateBalance;
}
/**
* @notice The current delegate of a user for a specific vault.
* @param vault the vault for which the delegate balance is being queried
* @param user the user whose delegate balance is being queried
* @return The current delegate balance of the user
*/
function delegateOf(address vault, address user) external view returns (address) {
return _delegateOf(vault, user);
}
/**
* @notice The current delegateBalance of a user for a specific vault.
* @dev the delegateBalance is the sum of delegated balance to this user
* @param vault the vault for which the delegateBalance is being queried
* @param user the user whose delegateBalance is being queried
* @return The current delegateBalance of the user
*/
function delegateBalanceOf(address vault, address user) external view returns (uint256) {
return userObservations[vault][user].details.delegateBalance;
}
/**
* @notice Looks up a users balance at a specific time in the past.
* @param vault the vault for which the balance is being queried
* @param user the user whose balance is being queried
* @param periodEndOnOrAfterTime The time in the past for which the balance is being queried. The time will be snapped to a period end time on or after the timestamp.
* @return The balance of the user at the target time
*/
function getBalanceAt(
address vault,
address user,
uint48 periodEndOnOrAfterTime
) external view returns (uint256) {
TwabLib.Account storage _account = userObservations[vault][user];
return TwabLib.getBalanceAt(PERIOD_LENGTH, PERIOD_OFFSET, _account.observations, _account.details, _periodEndOnOrAfter(periodEndOnOrAfterTime));
}
/**
* @notice Looks up the total supply at a specific time in the past.
* @param vault the vault for which the total supply is being queried
* @param periodEndOnOrAfterTime The time in the past for which the balance is being queried. The time will be snapped to a period end time on or after the timestamp.
* @return The total supply at the target time
*/
function getTotalSupplyAt(address vault, uint48 periodEndOnOrAfterTime) external view returns (uint256) {
TwabLib.Account storage _account = totalSupplyObservations[vault];
return TwabLib.getBalanceAt(PERIOD_LENGTH, PERIOD_OFFSET, _account.observations, _account.details, _periodEndOnOrAfter(periodEndOnOrAfterTime));
}
/**
* @notice Looks up the average balance of a user between two timestamps.
* @dev Timestamps are Unix timestamps denominated in seconds
* @param vault the vault for which the average balance is being queried
* @param user the user whose average balance is being queried
* @param startTime the start of the time range for which the average balance is being queried. The time will be snapped to a period end time on or after the timestamp.
* @param endTime the end of the time range for which the average balance is being queried. The time will be snapped to a period end time on or after the timestamp.
* @return The average balance of the user between the two timestamps
*/
function getTwabBetween(
address vault,
address user,
uint48 startTime,
uint48 endTime
) external view returns (uint256) {
TwabLib.Account storage _account = userObservations[vault][user];
// We snap the timestamps to the period end on or after the timestamp because the total supply records will be sparsely populated.
// if two users update during a period, then the total supply observation will only exist for the last one.
return
TwabLib.getTwabBetween(
PERIOD_LENGTH,
PERIOD_OFFSET,
_account.observations,
_account.details,
_periodEndOnOrAfter(startTime),
_periodEndOnOrAfter(endTime)
);
}
/**
* @notice Looks up the average total supply between two timestamps.
* @dev Timestamps are Unix timestamps denominated in seconds
* @param vault the vault for which the average total supply is being queried
* @param startTime the start of the time range for which the average total supply is being queried
* @param endTime the end of the time range for which the average total supply is being queried
* @return The average total supply between the two timestamps
*/
function getTotalSupplyTwabBetween(
address vault,
uint48 startTime,
uint48 endTime
) external view returns (uint256) {
TwabLib.Account storage _account = totalSupplyObservations[vault];
// We snap the timestamps to the period end on or after the timestamp because the total supply records will be sparsely populated.
// if two users update during a period, then the total supply observation will only exist for the last one.
return
TwabLib.getTwabBetween(
PERIOD_LENGTH,
PERIOD_OFFSET,
_account.observations,
_account.details,
_periodEndOnOrAfter(startTime),
_periodEndOnOrAfter(endTime)
);
}
/**
* @notice Computes the period end timestamp on or after the given timestamp.
* @param _timestamp The timestamp to check
* @return The end timestamp of the period that ends on or immediately after the given timestamp
*/
function periodEndOnOrAfter(uint48 _timestamp) external view returns (uint48) {
return _periodEndOnOrAfter(_timestamp);
}
/**
* @notice Computes the period end timestamp on or after the given timestamp.
* @param _timestamp The timestamp to compute the period end time for
* @return A period end time.
*/
function _periodEndOnOrAfter(uint48 _timestamp) internal view returns (uint48) {
if (_timestamp < PERIOD_OFFSET) {
return PERIOD_OFFSET;
}
if ((_timestamp - PERIOD_OFFSET) % PERIOD_LENGTH == 0) {
return _timestamp;
}
return TwabLib.getPeriodEndTime(
PERIOD_LENGTH,
PERIOD_OFFSET,
TwabLib.getTimestampPeriod(PERIOD_LENGTH, PERIOD_OFFSET, _timestamp)
);
}
/**
* @notice Looks up the newest observation for a user.
* @param vault the vault for which the observation is being queried
* @param user the user whose observation is being queried
* @return index The index of the observation
* @return observation The observation of the user
*/
function getNewestObservation(
address vault,
address user
) external view returns (uint16, ObservationLib.Observation memory) {
TwabLib.Account storage _account = userObservations[vault][user];
return TwabLib.getNewestObservation(_account.observations, _account.details);
}
/**
* @notice Looks up the oldest observation for a user.
* @param vault the vault for which the observation is being queried
* @param user the user whose observation is being queried
* @return index The index of the observation
* @return observation The observation of the user
*/
function getOldestObservation(
address vault,
address user
) external view returns (uint16, ObservationLib.Observation memory) {
TwabLib.Account storage _account = userObservations[vault][user];
return TwabLib.getOldestObservation(_account.observations, _account.details);
}
/**
* @notice Looks up the newest total supply observation for a vault.
* @param vault the vault for which the observation is being queried
* @return index The index of the observation
* @return observation The total supply observation
*/
function getNewestTotalSupplyObservation(
address vault
) external view returns (uint16, ObservationLib.Observation memory) {
TwabLib.Account storage _account = totalSupplyObservations[vault];
return TwabLib.getNewestObservation(_account.observations, _account.details);
}
/**
* @notice Looks up the oldest total supply observation for a vault.
* @param vault the vault for which the observation is being queried
* @return index The index of the observation
* @return observation The total supply observation
*/
function getOldestTotalSupplyObservation(
address vault
) external view returns (uint16, ObservationLib.Observation memory) {
TwabLib.Account storage _account = totalSupplyObservations[vault];
return TwabLib.getOldestObservation(_account.observations, _account.details);
}
/**
* @notice Calculates the period a timestamp falls into.
* @param time The timestamp to check
* @return period The period the timestamp falls into
*/
function getTimestampPeriod(uint48 time) external view returns (uint48) {
return TwabLib.getTimestampPeriod(PERIOD_LENGTH, PERIOD_OFFSET, time);
}
/**
* @notice Checks if the given timestamp is before the current overwrite period.
* @param time The timestamp to check
* @return True if the given time is finalized, false if it's during the current overwrite period.
*/
function hasFinalized(uint48 time) external view returns (bool) {
return TwabLib.hasFinalized(PERIOD_LENGTH, PERIOD_OFFSET, time);
}
/**
* @notice Computes the timestamp at which the current overwrite period started.
* @dev The overwrite period is the period during which observations are collated.
* @return period The timestamp at which the current overwrite period started.
*/
function currentOverwritePeriodStartedAt() external view returns (uint48) {
return TwabLib.currentOverwritePeriodStartedAt(PERIOD_LENGTH, PERIOD_OFFSET);
}
/* ============ External Write Functions ============ */
/**
* @notice Mints new balance and delegateBalance for a given user.
* @dev Note that if the provided user to mint to is delegating that the delegate's
* delegateBalance will be updated.
* @dev Mint is expected to be called by the Vault.
* @param _to The address to mint balance and delegateBalance to
* @param _amount The amount to mint
*/
function mint(address _to, uint112 _amount) external {
if (_to == address(0)) {
revert TransferToZeroAddress();
}
_transferBalance(msg.sender, address(0), _to, _amount);
}
/**
* @notice Burns balance and delegateBalance for a given user.
* @dev Note that if the provided user to burn from is delegating that the delegate's
* delegateBalance will be updated.
* @dev Burn is expected to be called by the Vault.
* @param _from The address to burn balance and delegateBalance from
* @param _amount The amount to burn
*/
function burn(address _from, uint112 _amount) external {
_transferBalance(msg.sender, _from, address(0), _amount);
}
/**
* @notice Transfers balance and delegateBalance from a given user.
* @dev Note that if the provided user to transfer from is delegating that the delegate's
* delegateBalance will be updated.
* @param _from The address to transfer the balance and delegateBalance from
* @param _to The address to transfer balance and delegateBalance to
* @param _amount The amount to transfer
*/
function transfer(address _from, address _to, uint112 _amount) external {
if (_to == address(0)) {
revert TransferToZeroAddress();
}
_transferBalance(msg.sender, _from, _to, _amount);
}
/**
* @notice Sets a delegate for a user which forwards the delegateBalance tied to the user's
* balance to the delegate's delegateBalance.
* @param _vault The vault for which the delegate is being set
* @param _to the address to delegate to
*/
function delegate(address _vault, address _to) external {
_delegate(_vault, msg.sender, _to);
}
/**
* @notice Delegate user balance to the sponsorship address.
* @dev Must only be called by the Vault contract.
* @param _from Address of the user delegating their balance to the sponsorship address.
*/
function sponsor(address _from) external {
_delegate(msg.sender, _from, SPONSORSHIP_ADDRESS);
}
/* ============ Internal Functions ============ */
/**
* @notice Transfers a user's vault balance from one address to another.
* @dev If the user is delegating, their delegate's delegateBalance is also updated.
* @dev If we are minting or burning tokens then the total supply is also updated.
* @param _vault the vault for which the balance is being transferred
* @param _from the address from which the balance is being transferred
* @param _to the address to which the balance is being transferred
* @param _amount the amount of balance being transferred
*/
function _transferBalance(address _vault, address _from, address _to, uint112 _amount) internal {
if (_to == SPONSORSHIP_ADDRESS) {
revert CannotTransferToSponsorshipAddress();
}
if (_from == _to) {
return;
}
// If we are transferring tokens from a delegated account to an undelegated account
address _fromDelegate = _delegateOf(_vault, _from);
address _toDelegate = _delegateOf(_vault, _to);
if (_from != address(0)) {
bool _isFromDelegate = _fromDelegate == _from;
_decreaseBalances(_vault, _from, _amount, _isFromDelegate ? _amount : 0);
// If the user is not delegating to themself, decrease the delegate's delegateBalance
// If the user is delegating to the sponsorship address, don't adjust the delegateBalance
if (!_isFromDelegate && _fromDelegate != SPONSORSHIP_ADDRESS) {
_decreaseBalances(_vault, _fromDelegate, 0, _amount);
}
// Burn balance if we're transferring to address(0)
// Burn delegateBalance if we're transferring to address(0) and burning from an address that is not delegating to the sponsorship address
// Burn delegateBalance if we're transferring to an address delegating to the sponsorship address from an address that isn't delegating to the sponsorship address
if (
_to == address(0) ||
(_toDelegate == SPONSORSHIP_ADDRESS && _fromDelegate != SPONSORSHIP_ADDRESS)
) {
// If the user is delegating to the sponsorship address, don't adjust the total supply delegateBalance
_decreaseTotalSupplyBalances(
_vault,
_to == address(0) ? _amount : 0,
(_to == address(0) && _fromDelegate != SPONSORSHIP_ADDRESS) ||
(_toDelegate == SPONSORSHIP_ADDRESS && _fromDelegate != SPONSORSHIP_ADDRESS)
? _amount
: 0
);
}
}
// If we are transferring tokens to an address other than address(0)
if (_to != address(0)) {
bool _isToDelegate = _toDelegate == _to;
// If the user is delegating to themself, increase their delegateBalance
_increaseBalances(_vault, _to, _amount, _isToDelegate ? _amount : 0);
// Otherwise, increase their delegates delegateBalance if it is not the sponsorship address
if (!_isToDelegate && _toDelegate != SPONSORSHIP_ADDRESS) {
_increaseBalances(_vault, _toDelegate, 0, _amount);
}
// Mint balance if we're transferring from address(0)
// Mint delegateBalance if we're transferring from address(0) and to an address not delegating to the sponsorship address
// Mint delegateBalance if we're transferring from an address delegating to the sponsorship address to an address that isn't delegating to the sponsorship address
if (
_from == address(0) ||
(_fromDelegate == SPONSORSHIP_ADDRESS && _toDelegate != SPONSORSHIP_ADDRESS)
) {
_increaseTotalSupplyBalances(
_vault,
_from == address(0) ? _amount : 0,
(_from == address(0) && _toDelegate != SPONSORSHIP_ADDRESS) ||
(_fromDelegate == SPONSORSHIP_ADDRESS && _toDelegate != SPONSORSHIP_ADDRESS)
? _amount
: 0
);
}
}
}
/**
* @notice Looks up the delegate of a user.
* @param _vault the vault for which the user's delegate is being queried
* @param _user the address to query the delegate of
* @return The address of the user's delegate
*/
function _delegateOf(address _vault, address _user) internal view returns (address) {
address _userDelegate;
if (_user != address(0)) {
_userDelegate = delegates[_vault][_user];
// If the user has not delegated, then the user is the delegate
if (_userDelegate == address(0)) {
_userDelegate = _user;
}
}
return _userDelegate;
}
/**
* @notice Transfers a user's vault delegateBalance from one address to another.
* @param _vault the vault for which the delegateBalance is being transferred
* @param _fromDelegate the address from which the delegateBalance is being transferred
* @param _toDelegate the address to which the delegateBalance is being transferred
* @param _amount the amount of delegateBalance being transferred
*/
function _transferDelegateBalance(
address _vault,
address _fromDelegate,
address _toDelegate,
uint112 _amount
) internal {
// If we are transferring tokens from a delegated account to an undelegated account
if (_fromDelegate != address(0) && _fromDelegate != SPONSORSHIP_ADDRESS) {
_decreaseBalances(_vault, _fromDelegate, 0, _amount);
// If we are delegating to the zero address, decrease total supply
// If we are delegating to the sponsorship address, decrease total supply
if (_toDelegate == address(0) || _toDelegate == SPONSORSHIP_ADDRESS) {
_decreaseTotalSupplyBalances(_vault, 0, _amount);
}
}
// If we are transferring tokens from an undelegated account to a delegated account
if (_toDelegate != address(0) && _toDelegate != SPONSORSHIP_ADDRESS) {
_increaseBalances(_vault, _toDelegate, 0, _amount);
// If we are removing delegation from the zero address, increase total supply
// If we are removing delegation from the sponsorship address, increase total supply
if (_fromDelegate == address(0) || _fromDelegate == SPONSORSHIP_ADDRESS) {
_increaseTotalSupplyBalances(_vault, 0, _amount);
}
}
}
/**
* @notice Sets a delegate for a user which forwards the delegateBalance tied to the user's
* balance to the delegate's delegateBalance. "Sponsoring" means the funds aren't delegated
* to anyone; this can be done by passing address(0) or the SPONSORSHIP_ADDRESS as the delegate.
* @param _vault The vault for which the delegate is being set
* @param _from the address to delegate from
* @param _to the address to delegate to
*/
function _delegate(address _vault, address _from, address _to) internal {
address _currentDelegate = _delegateOf(_vault, _from);
// address(0) is interpreted as sponsoring, so they don't need to know the sponsorship address.
address to = _to == address(0) ? SPONSORSHIP_ADDRESS : _to;
if (to == _currentDelegate) {
revert SameDelegateAlreadySet(to);
}
delegates[_vault][_from] = to;
_transferDelegateBalance(
_vault,
_currentDelegate,
_to,
SafeCast.toUint112(userObservations[_vault][_from].details.balance)
);
emit Delegated(_vault, _from, to);
}
/**
* @notice Increases a user's balance and delegateBalance for a specific vault.
* @param _vault the vault for which the balance is being increased
* @param _user the address of the user whose balance is being increased
* @param _amount the amount of balance being increased
* @param _delegateAmount the amount of delegateBalance being increased
*/
function _increaseBalances(
address _vault,
address _user,
uint112 _amount,
uint112 _delegateAmount
) internal {
TwabLib.Account storage _account = userObservations[_vault][_user];
(
ObservationLib.Observation memory _observation,
bool _isNewObservation,
bool _isObservationRecorded,
TwabLib.AccountDetails memory accountDetails
) = TwabLib.increaseBalances(PERIOD_LENGTH, PERIOD_OFFSET, _account, _amount, _delegateAmount);
// Always emit the balance change event
if (_amount != 0 || _delegateAmount != 0) {
emit IncreasedBalance(_vault, _user, _amount, _delegateAmount);
}
// Conditionally emit the observation recorded event
if (_isObservationRecorded) {
emit ObservationRecorded(
_vault,
_user,
accountDetails.balance,
accountDetails.delegateBalance,
_isNewObservation,
_observation
);
}
}
/**
* @notice Decreases the a user's balance and delegateBalance for a specific vault.
* @param _vault the vault for which the totalSupply balance is being decreased
* @param _amount the amount of balance being decreased
* @param _delegateAmount the amount of delegateBalance being decreased
*/
function _decreaseBalances(
address _vault,
address _user,
uint112 _amount,
uint112 _delegateAmount
) internal {
TwabLib.Account storage _account = userObservations[_vault][_user];
(
ObservationLib.Observation memory _observation,
bool _isNewObservation,
bool _isObservationRecorded,
TwabLib.AccountDetails memory accountDetails
) = TwabLib.decreaseBalances(
PERIOD_LENGTH,
PERIOD_OFFSET,
_account,
_amount,
_delegateAmount,
"TC/observation-burn-lt-delegate-balance"
);
// Always emit the balance change event
if (_amount != 0 || _delegateAmount != 0) {
emit DecreasedBalance(_vault, _user, _amount, _delegateAmount);
}
// Conditionally emit the observation recorded event
if (_isObservationRecorded) {
emit ObservationRecorded(
_vault,
_user,
accountDetails.balance,
accountDetails.delegateBalance,
_isNewObservation,
_observation
);
}
}
/**
* @notice Decreases the totalSupply balance and delegateBalance for a specific vault.
* @param _vault the vault for which the totalSupply balance is being decreased
* @param _amount the amount of balance being decreased
* @param _delegateAmount the amount of delegateBalance being decreased
*/
function _decreaseTotalSupplyBalances(
address _vault,
uint112 _amount,
uint112 _delegateAmount
) internal {
TwabLib.Account storage _account = totalSupplyObservations[_vault];
(
ObservationLib.Observation memory _observation,
bool _isNewObservation,
bool _isObservationRecorded,
TwabLib.AccountDetails memory accountDetails
) = TwabLib.decreaseBalances(
PERIOD_LENGTH,
PERIOD_OFFSET,
_account,
_amount,
_delegateAmount,
"TC/burn-amount-exceeds-total-supply-balance"
);
// Always emit the balance change event
if (_amount != 0 || _delegateAmount != 0) {
emit DecreasedTotalSupply(_vault, _amount, _delegateAmount);
}
// Conditionally emit the observation recorded event
if (_isObservationRecorded) {
emit TotalSupplyObservationRecorded(
_vault,
accountDetails.balance,
accountDetails.delegateBalance,
_isNewObservation,
_observation
);
}
}
/**
* @notice Increases the totalSupply balance and delegateBalance for a specific vault.
* @param _vault the vault for which the totalSupply balance is being increased
* @param _amount the amount of balance being increased
* @param _delegateAmount the amount of delegateBalance being increased
*/
function _increaseTotalSupplyBalances(
address _vault,
uint112 _amount,
uint112 _delegateAmount
) internal {
TwabLib.Account storage _account = totalSupplyObservations[_vault];
(
ObservationLib.Observation memory _observation,
bool _isNewObservation,
bool _isObservationRecorded,
TwabLib.AccountDetails memory accountDetails
) = TwabLib.increaseBalances(PERIOD_LENGTH, PERIOD_OFFSET, _account, _amount, _delegateAmount);
// Always emit the balance change event
if (_amount != 0 || _delegateAmount != 0) {
emit IncreasedTotalSupply(_vault, _amount, _delegateAmount);
}
// Conditionally emit the observation recorded event
if (_isObservationRecorded) {
emit TotalSupplyObservationRecorded(
_vault,
accountDetails.balance,
accountDetails.delegateBalance,
_isNewObservation,
_observation
);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.0;
/**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such 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.
*
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/
library SafeCast {
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*
* _Available since v4.7._
*/
function toUint248(uint256 value) internal pure returns (uint248) {
require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*
* _Available since v4.7._
*/
function toUint240(uint256 value) internal pure returns (uint240) {
require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*
* _Available since v4.7._
*/
function toUint232(uint256 value) internal pure returns (uint232) {
require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*
* _Available since v4.2._
*/
function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*
* _Available since v4.7._
*/
function toUint216(uint256 value) internal pure returns (uint216) {
require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*
* _Available since v4.7._
*/
function toUint208(uint256 value) internal pure returns (uint208) {
require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*
* _Available since v4.7._
*/
function toUint200(uint256 value) internal pure returns (uint200) {
require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*
* _Available since v4.7._
*/
function toUint192(uint256 value) internal pure returns (uint192) {
require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*
* _Available since v4.7._
*/
function toUint184(uint256 value) internal pure returns (uint184) {
require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*
* _Available since v4.7._
*/
function toUint176(uint256 value) internal pure returns (uint176) {
require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*
* _Available since v4.7._
*/
function toUint168(uint256 value) internal pure returns (uint168) {
require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*
* _Available since v4.7._
*/
function toUint160(uint256 value) internal pure returns (uint160) {
require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*
* _Available since v4.7._
*/
function toUint152(uint256 value) internal pure returns (uint152) {
require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*
* _Available since v4.7._
*/
function toUint144(uint256 value) internal pure returns (uint144) {
require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*
* _Available since v4.7._
*/
function toUint136(uint256 value) internal pure returns (uint136) {
require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v2.5._
*/
function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*
* _Available since v4.7._
*/
function toUint120(uint256 value) internal pure returns (uint120) {
require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*
* _Available since v4.7._
*/
function toUint112(uint256 value) internal pure returns (uint112) {
require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*
* _Available since v4.7._
*/
function toUint104(uint256 value) internal pure returns (uint104) {
require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*
* _Available since v4.2._
*/
function toUint96(uint256 value) internal pure returns (uint96) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*
* _Available since v4.7._
*/
function toUint88(uint256 value) internal pure returns (uint88) {
require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*
* _Available since v4.7._
*/
function toUint80(uint256 value) internal pure returns (uint80) {
require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*
* _Available since v4.7._
*/
function toUint72(uint256 value) internal pure returns (uint72) {
require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v2.5._
*/
function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*
* _Available since v4.7._
*/
function toUint56(uint256 value) internal pure returns (uint56) {
require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*
* _Available since v4.7._
*/
function toUint48(uint256 value) internal pure returns (uint48) {
require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*
* _Available since v4.7._
*/
function toUint40(uint256 value) internal pure returns (uint40) {
require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v2.5._
*/
function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*
* _Available since v4.7._
*/
function toUint24(uint256 value) internal pure returns (uint24) {
require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v2.5._
*/
function toUint16(uint256 value) internal pure returns (uint16) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*
* _Available since v2.5._
*/
function toUint8(uint256 value) internal pure returns (uint8) {
require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*
* _Available since v3.0._
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*
* _Available since v4.7._
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*
* _Available since v4.7._
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*
* _Available since v4.7._
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*
* _Available since v4.7._
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*
* _Available since v4.7._
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*
* _Available since v4.7._
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*
* _Available since v4.7._
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*
* _Available since v4.7._
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*
* _Available since v4.7._
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*
* _Available since v4.7._
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*
* _Available since v4.7._
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*
* _Available since v4.7._
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*
* _Available since v4.7._
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*
* _Available since v4.7._
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*
* _Available since v4.7._
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v3.1._
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*
* _Available since v4.7._
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*
* _Available since v4.7._
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*
* _Available since v4.7._
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*
* _Available since v4.7._
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*
* _Available since v4.7._
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*
* _Available since v4.7._
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*
* _Available since v4.7._
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v3.1._
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*
* _Available since v4.7._
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*
* _Available since v4.7._
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*
* _Available since v4.7._
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v3.1._
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*
* _Available since v4.7._
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v3.1._
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*
* _Available since v3.1._
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*
* _Available since v3.0._
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
return int256(value);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import "ring-buffer-lib/RingBufferLib.sol";
import { ObservationLib, MAX_CARDINALITY } from "./ObservationLib.sol";
/// @notice Emitted when a balance is decreased by an amount that exceeds the amount available.
/// @param balance The current balance of the account
/// @param amount The amount being decreased from the account's balance
/// @param message An additional message describing the error
error BalanceLTAmount(uint112 balance, uint112 amount, string message);
/// @notice Emitted when a delegate balance is decreased by an amount that exceeds the amount available.
/// @param delegateBalance The current delegate balance of the account
/// @param delegateAmount The amount being decreased from the account's delegate balance
/// @param message An additional message describing the error
error DelegateBalanceLTAmount(uint112 delegateBalance, uint112 delegateAmount, string message);
/// @notice Emitted when a request is made for a twab that is not yet finalized.
/// @param timestamp The requested timestamp
/// @param currentOverwritePeriodStartedAt The current overwrite period start time
error TimestampNotFinalized(uint256 timestamp, uint256 currentOverwritePeriodStartedAt);
/// @notice Emitted when a TWAB time range start is after the end.
/// @param start The start time
/// @param end The end time
error InvalidTimeRange(uint256 start, uint256 end);
/// @notice Emitted when there is insufficient history to lookup a twab time range
/// @param requestedTimestamp The timestamp requested
/// @param oldestTimestamp The oldest timestamp that can be read
error InsufficientHistory(uint48 requestedTimestamp, uint48 oldestTimestamp);
/**
* @title PoolTogether V5 TwabLib (Library)
* @author PoolTogether Inc Team
* @dev Time-Weighted Average Balance Library for ERC20 tokens.
* @notice This TwabLib adds on-chain historical lookups to a user(s) time-weighted average balance.
* Each user is mapped to an Account struct containing the TWAB history (ring buffer) and
* ring buffer parameters. Every token.transfer() creates a new TWAB checkpoint. The new
* TWAB checkpoint is stored in the circular ring buffer, as either a new checkpoint or
* rewriting a previous checkpoint with new parameters. One checkpoint per day is stored.
* The TwabLib guarantees minimum 1 year of search history.
* @notice There are limitations to the Observation data structure used. Ensure your token is
* compatible before using this library. Ensure the date ranges you're relying on are
* within safe boundaries.
*/
library TwabLib {
/**
* @notice Struct ring buffer parameters for single user Account.
* @param balance Current token balance for an Account
* @param delegateBalance Current delegate balance for an Account (active balance for chance)
* @param nextObservationIndex Next uninitialized or updatable ring buffer checkpoint storage slot
* @param cardinality Current total "initialized" ring buffer checkpoints for single user Account.
* Used to set initial boundary conditions for an efficient binary search.
*/
struct AccountDetails {
uint112 balance;
uint112 delegateBalance;
uint16 nextObservationIndex;
uint16 cardinality;
}
/**
* @notice Account details and historical twabs.
* @dev The size of observations is MAX_CARDINALITY from the ObservationLib.
* @param details The account details
* @param observations The history of observations for this account
*/
struct Account {
AccountDetails details;
ObservationLib.Observation[9600] observations;
}
/**
* @notice Increase a user's balance and delegate balance by a given amount.
* @dev This function mutates the provided account.
* @param PERIOD_LENGTH The length of an overwrite period
* @param PERIOD_OFFSET The offset of the first period
* @param _account The account to update
* @param _amount The amount to increase the balance by
* @param _delegateAmount The amount to increase the delegate balance by
* @return observation The new/updated observation
* @return isNew Whether or not the observation is new or overwrote a previous one
* @return isObservationRecorded Whether or not the observation was recorded to storage
*/
function increaseBalances(
uint48 PERIOD_LENGTH,
uint48 PERIOD_OFFSET,
Account storage _account,
uint112 _amount,
uint112 _delegateAmount
)
internal
returns (ObservationLib.Observation memory observation, bool isNew, bool isObservationRecorded, AccountDetails memory accountDetails)
{
accountDetails = _account.details;
isObservationRecorded = _delegateAmount != uint112(0);
// Only record a new Observation if the users delegateBalance has changed.
if (isObservationRecorded) {
(observation, isNew, accountDetails) = _recordObservation(PERIOD_LENGTH, PERIOD_OFFSET, accountDetails, _account);
}
accountDetails.balance += _amount;
accountDetails.delegateBalance += _delegateAmount;
_account.details = accountDetails;
}
/**
* @notice Decrease a user's balance and delegate balance by a given amount.
* @dev This function mutates the provided account.
* @param PERIOD_LENGTH The length of an overwrite period
* @param PERIOD_OFFSET The offset of the first period
* @param _account The account to update
* @param _amount The amount to decrease the balance by
* @param _delegateAmount The amount to decrease the delegate balance by
* @param _revertMessage The revert message to use if the balance is insufficient
* @return observation The new/updated observation
* @return isNew Whether or not the observation is new or overwrote a previous one
* @return isObservationRecorded Whether or not the observation was recorded to storage
*/
function decreaseBalances(
uint48 PERIOD_LENGTH,
uint48 PERIOD_OFFSET,
Account storage _account,
uint112 _amount,
uint112 _delegateAmount,
string memory _revertMessage
)
internal
returns (ObservationLib.Observation memory observation, bool isNew, bool isObservationRecorded, AccountDetails memory accountDetails)
{
accountDetails = _account.details;
if (accountDetails.balance < _amount) {
revert BalanceLTAmount(accountDetails.balance, _amount, _revertMessage);
}
if (accountDetails.delegateBalance < _delegateAmount) {
revert DelegateBalanceLTAmount(
accountDetails.delegateBalance,
_delegateAmount,
_revertMessage
);
}
isObservationRecorded = _delegateAmount != uint112(0);
// Only record a new Observation if the users delegateBalance has changed.
if (isObservationRecorded) {
(observation, isNew, accountDetails) = _recordObservation(PERIOD_LENGTH, PERIOD_OFFSET, accountDetails, _account);
}
unchecked {
accountDetails.balance -= _amount;
accountDetails.delegateBalance -= _delegateAmount;
}
_account.details = accountDetails;
}
/**
* @notice Looks up the oldest observation in the circular buffer.
* @param _observations The circular buffer of observations
* @param _accountDetails The account details to query with
* @return index The index of the oldest observation
* @return observation The oldest observation in the circular buffer
*/
function getOldestObservation(
ObservationLib.Observation[MAX_CARDINALITY] storage _observations,
AccountDetails memory _accountDetails
) internal view returns (uint16 index, ObservationLib.Observation memory observation) {
// If the circular buffer has not been fully populated, we go to the beginning of the buffer at index 0.
if (_accountDetails.cardinality < MAX_CARDINALITY) {
index = 0;
observation = _observations[0];
} else {
index = _accountDetails.nextObservationIndex;
observation = _observations[index];
}
}
/**
* @notice Looks up the newest observation in the circular buffer.
* @param _observations The circular buffer of observations
* @param _accountDetails The account details to query with
* @return index The index of the newest observation
* @return observation The newest observation in the circular buffer
*/
function getNewestObservation(
ObservationLib.Observation[MAX_CARDINALITY] storage _observations,
AccountDetails memory _accountDetails
) internal view returns (uint16 index, ObservationLib.Observation memory observation) {
index = uint16(
RingBufferLib.newestIndex(_accountDetails.nextObservationIndex, MAX_CARDINALITY)
);
observation = _observations[index];
}
/**
* @notice Looks up a users balance at a specific time in the past. The time must be before the current overwrite period.
* @dev Ensure timestamps are safe using requireFinalized
* @param PERIOD_LENGTH The length of an overwrite period
* @param PERIOD_OFFSET The offset of the first period
* @param _observations The circular buffer of observations
* @param _accountDetails The account details to query with
* @param _targetTime The time to look up the balance at
* @return balance The balance at the target time
*/
function getBalanceAt(
uint48 PERIOD_LENGTH,
uint48 PERIOD_OFFSET,
ObservationLib.Observation[MAX_CARDINALITY] storage _observations,
AccountDetails memory _accountDetails,
uint48 _targetTime
) internal requireFinalized(PERIOD_LENGTH, PERIOD_OFFSET, _targetTime) view returns (uint256) {
(ObservationLib.Observation memory prevOrAtObservation, uint16 index, bool isBeforeHistory) = _getPreviousOrAtObservation(
PERIOD_OFFSET,
_observations,
_accountDetails,
_targetTime
);
if (isBeforeHistory) {
return 0;
} else {
return _getBalanceOf(_observations, _accountDetails, prevOrAtObservation, index);
}
}
/**
* @notice Looks up a users TWAB for a time range. The time must be before the current overwrite period.
* @dev If the timestamps in the range are not exact matches of observations, the balance is extrapolated using the previous observation.
* @param PERIOD_LENGTH The length of an overwrite period
* @param PERIOD_OFFSET The offset of the first period
* @param _observations The circular buffer of observations
* @param _accountDetails The account details to query with
* @param _startTime The start of the time range
* @param _endTime The end of the time range
* @return twab The TWAB for the time range
*/
function getTwabBetween(
uint48 PERIOD_LENGTH,
uint48 PERIOD_OFFSET,
ObservationLib.Observation[MAX_CARDINALITY] storage _observations,
AccountDetails memory _accountDetails,
uint48 _startTime,
uint48 _endTime
) internal view requireFinalized(PERIOD_LENGTH, PERIOD_OFFSET, _endTime) returns (uint256) {
if (_startTime > _endTime) {
revert InvalidTimeRange(_startTime, _endTime);
}
(ObservationLib.Observation memory endObservation,uint16 endIndex,) = _getPreviousOrAtObservation(
PERIOD_OFFSET,
_observations,
_accountDetails,
_endTime
);
if (_startTime == _endTime) {
return _getBalanceOf(_observations, _accountDetails, endObservation, endIndex);
}
(ObservationLib.Observation memory startObservation,uint16 startIndex,) = _getPreviousOrAtObservation(
PERIOD_OFFSET,
_observations,
_accountDetails,
_startTime
);
if (startObservation.timestamp != _startTime) {
startObservation = _calculateTemporaryObservation(_observations, _accountDetails, startObservation, startIndex, _startTime);
}
if (endObservation.timestamp != _endTime) {
endObservation = _calculateTemporaryObservation(_observations, _accountDetails, endObservation, endIndex, _endTime);
}
// Difference in amount / time
return
(endObservation.cumulativeBalance - startObservation.cumulativeBalance) /
(_endTime - _startTime);
}
/**
* @notice Retrieves a delegate balance for a specific observation record
* @param _observations The ring buffer of observations
* @param _accountDetails The account details
* @param _observation The observation whose delegate balance we want to determine
* @param _observationIndex The index of the observation in the ring buffer
* @return The delegate balance held at the time of the observation
*/
function _getBalanceOf(
ObservationLib.Observation[MAX_CARDINALITY] storage _observations,
AccountDetails memory _accountDetails,
ObservationLib.Observation memory _observation,
uint32 _observationIndex
) internal view returns (uint160) {
uint32 nextIndex = uint32(RingBufferLib.nextIndex(_observationIndex, MAX_CARDINALITY));
ObservationLib.Observation memory nextObservation = _observations[nextIndex];
// if there is no next observation, then they never held a balance previously.
if (nextObservation.timestamp == 0 || nextObservation.timestamp < _observation.timestamp) {
return _accountDetails.delegateBalance;
} else { // compute the balance
// compute the balance using the twab in reverse
return (nextObservation.cumulativeBalance - _observation.cumulativeBalance) /
(nextObservation.timestamp - _observation.timestamp);
}
}
/**
* @notice Given an AccountDetails with updated balances, either updates the latest Observation or records a new one
* @param PERIOD_LENGTH The overwrite period length
* @param PERIOD_OFFSET The overwrite period offset
* @param _accountDetails The updated account details
* @param _account The account to update
* @return observation The new/updated observation
* @return isNew Whether or not the observation is new or overwrote a previous one
* @return newAccountDetails The new account details
*/
function _recordObservation(
uint48 PERIOD_LENGTH,
uint48 PERIOD_OFFSET,
AccountDetails memory _accountDetails,
Account storage _account
) internal returns (ObservationLib.Observation memory observation, bool isNew, AccountDetails memory newAccountDetails) {
uint32 currentTime = uint32(block.timestamp);
uint16 nextIndex;
ObservationLib.Observation memory newestObservation;
(nextIndex, newestObservation, isNew) = _getNextObservationIndex(
PERIOD_LENGTH,
PERIOD_OFFSET,
_account.observations,
_accountDetails
);
if (isNew) {
// If the index is new, then we increase the next index to use
_accountDetails.nextObservationIndex = uint16(
RingBufferLib.nextIndex(uint256(nextIndex), MAX_CARDINALITY)
);
// Prevent the Account specific cardinality from exceeding the MAX_CARDINALITY.
// The ring buffer length is limited by MAX_CARDINALITY. IF the account.cardinality
// exceeds the max cardinality, new observations would be incorrectly set or the
// observation would be out of "bounds" of the ring buffer. Once reached the
// Account.cardinality will continue to be equal to max cardinality.
_accountDetails.cardinality = _accountDetails.cardinality < MAX_CARDINALITY ? _accountDetails.cardinality + 1 : MAX_CARDINALITY;
}
observation = ObservationLib.Observation({
cumulativeBalance: _extrapolateFromBalance(newestObservation, _accountDetails.delegateBalance, currentTime),
timestamp: currentTime
});
// Write to storage
_account.observations[nextIndex] = observation;
newAccountDetails = _accountDetails;
}
/**
* @notice Calculates a temporary observation for a given time using the previous observation.
* @dev This is used to extrapolate a balance for any given time.
* @param _observation The previous observation
* @param _observationIndex The index of the previous observation
* @param _time The time to extrapolate to
* @return observation The observation
*/
function _calculateTemporaryObservation(
ObservationLib.Observation[MAX_CARDINALITY] storage _observations,
AccountDetails memory _accountDetails,
ObservationLib.Observation memory _observation,
uint16 _observationIndex,
uint48 _time
) private view returns (ObservationLib.Observation memory) {
uint160 balance = _getBalanceOf(_observations, _accountDetails, _observation, _observationIndex);
return
ObservationLib.Observation({
cumulativeBalance: _extrapolateFromBalance(_observation, balance, _time),
timestamp: _time
});
}
/**
* @notice Looks up the next observation index to write to in the circular buffer.
* @dev If the current time is in the same period as the newest observation, we overwrite it.
* @dev If the current time is in a new period, we increment the index and write a new observation.
* @param PERIOD_LENGTH The length of an overwrite period
* @param PERIOD_OFFSET The offset of the first period
* @param _observations The circular buffer of observations
* @param _accountDetails The account details to query with
* @return index The index of the next observation slot to overwrite
* @return newestObservation The newest observation in the circular buffer
* @return isNew Whether or not the observation is new
*/
function _getNextObservationIndex(
uint48 PERIOD_LENGTH,
uint48 PERIOD_OFFSET,
ObservationLib.Observation[MAX_CARDINALITY] storage _observations,
AccountDetails memory _accountDetails
)
private
view
returns (uint16 index, ObservationLib.Observation memory newestObservation, bool isNew)
{
uint16 newestIndex;
(newestIndex, newestObservation) = getNewestObservation(_observations, _accountDetails);
// if we're in the same block, return
if (newestObservation.timestamp == block.timestamp) {
return (newestIndex, newestObservation, false);
}
uint48 currentPeriod = _getTimestampPeriod(PERIOD_LENGTH, PERIOD_OFFSET, uint48(block.timestamp));
uint48 newestObservationPeriod = _getTimestampPeriod(
PERIOD_LENGTH,
PERIOD_OFFSET,
newestObservation.timestamp
);
// Create a new Observation if it's the first period or the current time falls within a new period
if (_accountDetails.cardinality == 0 || currentPeriod > newestObservationPeriod) {
return (
_accountDetails.nextObservationIndex,
newestObservation,
true
);
}
// Otherwise, we're overwriting the current newest Observation
return (newestIndex, newestObservation, false);
}
/**
* @notice Computes the start time of the current overwrite period
* @param PERIOD_LENGTH The length of an overwrite period
* @param PERIOD_OFFSET The offset of the first period
* @return The start time of the current overwrite period
*/
function _currentOverwritePeriodStartedAt(
uint48 PERIOD_LENGTH,
uint48 PERIOD_OFFSET
) private view returns (uint48) {
uint48 period = getTimestampPeriod(PERIOD_LENGTH, PERIOD_OFFSET, uint48(block.timestamp));
return getPeriodStartTime(PERIOD_LENGTH, PERIOD_OFFSET, period);
}
/**
* @notice Calculates the next cumulative balance using a provided Observation and timestamp.
* @param _observation The observation to extrapolate from
* @param _timestamp The timestamp to extrapolate to
* @return cumulativeBalance The cumulative balance at the timestamp
*/
function _extrapolateFromBalance(
ObservationLib.Observation memory _observation,
uint160 _balance,
uint48 _timestamp
) private pure returns (uint160 cumulativeBalance) {
// new cumulative balance = provided cumulative balance (or zero) + (current balance * elapsed seconds)
return
_observation.cumulativeBalance +
_balance *
(_timestamp - _observation.timestamp);
}
/**
* @notice Calculates the period a timestamp falls within.
* @dev All timestamps prior to the PERIOD_OFFSET fall within period 0.
* @param PERIOD_LENGTH The length of an overwrite period
* @param PERIOD_OFFSET The offset of the first period
* @param _timestamp The timestamp to calculate the period for
* @return period The period
*/
function getTimestampPeriod(
uint48 PERIOD_LENGTH,
uint48 PERIOD_OFFSET,
uint48 _timestamp
) internal pure returns (uint48 period) {
return _getTimestampPeriod(PERIOD_LENGTH, PERIOD_OFFSET, _timestamp);
}
/**
* @notice Computes the overwrite period start time given the current time
* @param PERIOD_LENGTH The length of an overwrite period
* @param PERIOD_OFFSET The offset of the first period
* @return The start time for the current overwrite period.
*/
function currentOverwritePeriodStartedAt(
uint48 PERIOD_LENGTH,
uint48 PERIOD_OFFSET
) internal view returns (uint48) {
return _currentOverwritePeriodStartedAt(PERIOD_LENGTH, PERIOD_OFFSET);
}
/**
* @notice Calculates the period a timestamp falls within.
* @dev Timestamp prior to the PERIOD_OFFSET are considered to be in period 0.
* @param PERIOD_LENGTH The length of an overwrite period
* @param PERIOD_OFFSET The offset of the first period
* @param _timestamp The timestamp to calculate the period for
* @return period The period
*/
function _getTimestampPeriod(
uint48 PERIOD_LENGTH,
uint48 PERIOD_OFFSET,
uint48 _timestamp
) private pure returns (uint48) {
if (_timestamp <= PERIOD_OFFSET) {
return 0;
}
return (_timestamp - PERIOD_OFFSET) / PERIOD_LENGTH;
}
/**
* @notice Calculates the start timestamp for a period
* @param PERIOD_LENGTH The period length to use to calculate the period
* @param PERIOD_OFFSET The period offset to use to calculate the period
* @param _period The period to check
* @return _timestamp The timestamp at which the period starts
*/
function getPeriodStartTime(
uint48 PERIOD_LENGTH,
uint48 PERIOD_OFFSET,
uint48 _period
) internal pure returns (uint48) {
return _period * PERIOD_LENGTH + PERIOD_OFFSET;
}
/**
* @notice Calculates the last timestamp for a period
* @param PERIOD_LENGTH The period length to use to calculate the period
* @param PERIOD_OFFSET The period offset to use to calculate the period
* @param _period The period to check
* @return _timestamp The timestamp at which the period ends
*/
function getPeriodEndTime(
uint48 PERIOD_LENGTH,
uint48 PERIOD_OFFSET,
uint48 _period
) internal pure returns (uint48) {
return (_period+1) * PERIOD_LENGTH + PERIOD_OFFSET;
}
/**
* @notice Looks up the newest observation before or at a given timestamp.
* @dev If an observation is available at the target time, it is returned. Otherwise, the newest observation before the target time is returned.
* @param PERIOD_OFFSET The period offset to use to calculate the period
* @param _observations The circular buffer of observations
* @param _accountDetails The account details to query with
* @param _targetTime The timestamp to look up
* @return prevOrAtObservation The observation
*/
function getPreviousOrAtObservation(
uint48 PERIOD_OFFSET,
ObservationLib.Observation[MAX_CARDINALITY] storage _observations,
AccountDetails memory _accountDetails,
uint48 _targetTime
) internal view returns (ObservationLib.Observation memory prevOrAtObservation) {
(prevOrAtObservation,,) = _getPreviousOrAtObservation(PERIOD_OFFSET, _observations, _accountDetails, _targetTime);
}
/**
* @notice Looks up the newest observation before or at a given timestamp.
* @dev If an observation is available at the target time, it is returned. Otherwise, the newest observation before the target time is returned.
* @param _observations The circular buffer of observations
* @param _accountDetails The account details to query with
* @param _targetTime The timestamp to look up
* @return obs The observation
* @return index The index of the observation. If the obs is prior to history, this will be zero
* @return isBeforeHistory True if the observation is made up due to a lack of sufficient history
*/
function _getPreviousOrAtObservation(
uint48 PERIOD_OFFSET,
ObservationLib.Observation[MAX_CARDINALITY] storage _observations,
AccountDetails memory _accountDetails,
uint48 _targetTime
) private view returns (ObservationLib.Observation memory obs, uint16 index, bool isBeforeHistory) {
ObservationLib.Observation memory prevOrAtObservation;
// If there are no observations, return a zeroed observation
if (_accountDetails.cardinality == 0) {
return (
ObservationLib.Observation({ cumulativeBalance: 0, timestamp: PERIOD_OFFSET }),
0,
true
);
}
uint16 oldestTwabIndex;
(oldestTwabIndex, prevOrAtObservation) = getOldestObservation(_observations, _accountDetails);
// if the requested time is older than the oldest observation
if (_targetTime < prevOrAtObservation.timestamp) {
// if the user didn't have any activity prior to the oldest observation, then we know they had a zero balance
if (_accountDetails.cardinality < MAX_CARDINALITY) {
return (
ObservationLib.Observation({ cumulativeBalance: 0, timestamp: _targetTime }),
0,
true
);
} else {
// if we are missing their history, we must revert
revert InsufficientHistory(_targetTime, prevOrAtObservation.timestamp);
}
}
// We know targetTime >= oldestObservation.timestamp because of the above if statement, so we can return here.
if (_accountDetails.cardinality == 1) {
return (
prevOrAtObservation,
oldestTwabIndex,
false
);
}
uint16 newestTwabIndex;
ObservationLib.Observation memory afterOrAtObservation;
// Find the newest observation
(newestTwabIndex, afterOrAtObservation) = getNewestObservation(_observations, _accountDetails);
// if the target time is at or after the newest, return it
if (_targetTime >= afterOrAtObservation.timestamp) {
return (afterOrAtObservation, newestTwabIndex, false);
}
// if we know there is only 1 observation older than the newest
if (_accountDetails.cardinality == 2) {
return (prevOrAtObservation, oldestTwabIndex, false);
}
// Otherwise, we perform a binarySearch to find the observation before or at the timestamp
(prevOrAtObservation, oldestTwabIndex, afterOrAtObservation, newestTwabIndex) = ObservationLib.binarySearch(
_observations,
newestTwabIndex,
oldestTwabIndex,
_targetTime,
_accountDetails.cardinality
);
// If the afterOrAt is at, we can skip a temporary Observation computation by returning it here
if (afterOrAtObservation.timestamp == _targetTime) {
return (afterOrAtObservation, newestTwabIndex, false);
}
return (prevOrAtObservation, oldestTwabIndex, false);
}
/**
* @notice Checks if the given timestamp is safe to perform a historic balance lookup on.
* @dev A timestamp is safe if it is before the current overwrite period
* @param PERIOD_LENGTH The period length to use to calculate the period
* @param PERIOD_OFFSET The period offset to use to calculate the period
* @param _time The timestamp to check
* @return isSafe Whether or not the timestamp is safe
*/
function hasFinalized(
uint48 PERIOD_LENGTH,
uint48 PERIOD_OFFSET,
uint48 _time
) internal view returns (bool) {
return _hasFinalized(PERIOD_LENGTH, PERIOD_OFFSET, _time);
}
/**
* @notice Checks if the given timestamp is safe to perform a historic balance lookup on.
* @dev A timestamp is safe if it is on or before the current overwrite period start time
* @param PERIOD_LENGTH The period length to use to calculate the period
* @param PERIOD_OFFSET The period offset to use to calculate the period
* @param _time The timestamp to check
* @return isSafe Whether or not the timestamp is safe
*/
function _hasFinalized(
uint48 PERIOD_LENGTH,
uint48 PERIOD_OFFSET,
uint48 _time
) private view returns (bool) {
// It's safe if equal to the overwrite period start time, because the cumulative balance won't be impacted
return _time <= _currentOverwritePeriodStartedAt(PERIOD_LENGTH, PERIOD_OFFSET);
}
/**
* @notice Checks if the given timestamp is safe to perform a historic balance lookup on.
* @param PERIOD_LENGTH The period length to use to calculate the period
* @param PERIOD_OFFSET The period offset to use to calculate the period
* @param _timestamp The timestamp to check
*/
modifier requireFinalized(uint48 PERIOD_LENGTH, uint48 PERIOD_OFFSET, uint256 _timestamp) {
// The current period can still be changed; so the start of the period marks the beginning of unsafe timestamps.
uint48 overwritePeriodStartTime = _currentOverwritePeriodStartedAt(PERIOD_LENGTH, PERIOD_OFFSET);
// timestamp == overwritePeriodStartTime doesn't matter, because the cumulative balance won't be impacted
if (_timestamp > overwritePeriodStartTime) {
revert TimestampNotFinalized(_timestamp, overwritePeriodStartTime);
}
_;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import "ring-buffer-lib/RingBufferLib.sol";
/**
* @dev Sets max ring buffer length in the Account.observations Observation list.
* As users transfer/mint/burn tickets new Observation checkpoints are recorded.
* The current `MAX_CARDINALITY` guarantees a one year minimum, of accurate historical lookups.
* @dev The user Account.Account.cardinality parameter can NOT exceed the max cardinality variable.
* Preventing "corrupted" ring buffer lookup pointers and new observation checkpoints.
*/
uint16 constant MAX_CARDINALITY = 9600; // with min period of 1 hour, this allows for minimum 400 days of history
/**
* @title Observation Library
* @notice This library allows one to store an array of timestamped values and efficiently search them.
* @dev Largely pulled from Uniswap V3 Oracle.sol: https://github.com/Uniswap/v3-core/blob/c05a0e2c8c08c460fb4d05cfdda30b3ad8deeaac/contracts/libraries/Oracle.sol
* @author PoolTogether Inc.
*/
library ObservationLib {
/**
* @notice Observation, which includes an amount and timestamp.
* @param balance `balance` at `timestamp`.
* @param cumulativeBalance the cumulative time-weighted balance at `timestamp`.
* @param timestamp Recorded `timestamp`.
*/
struct Observation {
uint160 cumulativeBalance;
uint48 timestamp;
}
/**
* @notice Fetches Observations `beforeOrAt` and `afterOrAt` a `_target`, eg: where [`beforeOrAt`, `afterOrAt`] is satisfied.
* The result may be the same Observation, or adjacent Observations.
* @dev The _target must fall within the boundaries of the provided _observations.
* Meaning the _target must be: older than the most recent Observation and younger, or the same age as, the oldest Observation.
* @dev If `_newestObservationIndex` is less than `_oldestObservationIndex`, it means that we've wrapped around the circular buffer.
* So the most recent observation will be at `_oldestObservationIndex + _cardinality - 1`, at the beginning of the circular buffer.
* @param _observations List of Observations to search through.
* @param _newestObservationIndex Index of the newest Observation. Right side of the circular buffer.
* @param _oldestObservationIndex Index of the oldest Observation. Left side of the circular buffer.
* @param _target Timestamp at which we are searching the Observation.
* @param _cardinality Cardinality of the circular buffer we are searching through.
* @return beforeOrAt Observation recorded before, or at, the target.
* @return beforeOrAtIndex Index of observation recorded before, or at, the target.
* @return afterOrAt Observation recorded at, or after, the target.
* @return afterOrAtIndex Index of observation recorded at, or after, the target.
*/
function binarySearch(
Observation[MAX_CARDINALITY] storage _observations,
uint24 _newestObservationIndex,
uint24 _oldestObservationIndex,
uint48 _target,
uint16 _cardinality
) internal view returns (Observation memory beforeOrAt, uint16 beforeOrAtIndex, Observation memory afterOrAt, uint16 afterOrAtIndex) {
uint256 leftSide = _oldestObservationIndex;
uint256 rightSide = _newestObservationIndex < leftSide
? leftSide + _cardinality - 1
: _newestObservationIndex;
uint256 currentIndex;
while (true) {
// We start our search in the middle of the `leftSide` and `rightSide`.
// After each iteration, we narrow down the search to the left or the right side while still starting our search in the middle.
currentIndex = (leftSide + rightSide) / 2;
beforeOrAtIndex = uint16(RingBufferLib.wrap(currentIndex, _cardinality));
beforeOrAt = _observations[beforeOrAtIndex];
uint48 beforeOrAtTimestamp = beforeOrAt.timestamp;
// We've landed on an uninitialized timestamp, keep searching higher (more recently).
if (beforeOrAtTimestamp == 0) {
leftSide = uint16(RingBufferLib.nextIndex(leftSide, _cardinality));
continue;
}
afterOrAtIndex = uint16(RingBufferLib.nextIndex(currentIndex, _cardinality));
afterOrAt = _observations[afterOrAtIndex];
bool targetAfterOrAt = beforeOrAtTimestamp <= _target;
// Check if we've found the corresponding Observation.
if (targetAfterOrAt && _target <= afterOrAt.timestamp) {
break;
}
// If `beforeOrAtTimestamp` is greater than `_target`, then we keep searching lower. To the left of the current index.
if (!targetAfterOrAt) {
rightSide = currentIndex - 1;
} else {
// Otherwise, we keep searching higher. To the right of the current index.
leftSide = currentIndex + 1;
}
}
}
}// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.17;
/**
* NOTE: There is a difference in meaning between "cardinality" and "count":
* - cardinality is the physical size of the ring buffer (i.e. max elements).
* - count is the number of elements in the buffer, which may be less than cardinality.
*/
library RingBufferLib {
/**
* @notice Returns wrapped TWAB index.
* @dev In order to navigate the TWAB circular buffer, we need to use the modulo operator.
* @dev For example, if `_index` is equal to 32 and the TWAB circular buffer is of `_cardinality` 32,
* it will return 0 and will point to the first element of the array.
* @param _index Index used to navigate through the TWAB circular buffer.
* @param _cardinality TWAB buffer cardinality.
* @return TWAB index.
*/
function wrap(uint256 _index, uint256 _cardinality) internal pure returns (uint256) {
return _index % _cardinality;
}
/**
* @notice Computes the negative offset from the given index, wrapped by the cardinality.
* @dev We add `_cardinality` to `_index` to be able to offset even if `_amount` is superior to `_cardinality`.
* @param _index The index from which to offset
* @param _amount The number of indices to offset. This is subtracted from the given index.
* @param _count The number of elements in the ring buffer
* @return Offsetted index.
*/
function offset(
uint256 _index,
uint256 _amount,
uint256 _count
) internal pure returns (uint256) {
return wrap(_index + _count - _amount, _count);
}
/// @notice Returns the index of the last recorded TWAB
/// @param _nextIndex The next available twab index. This will be recorded to next.
/// @param _count The count of the TWAB history.
/// @return The index of the last recorded TWAB
function newestIndex(uint256 _nextIndex, uint256 _count)
internal
pure
returns (uint256)
{
if (_count == 0) {
return 0;
}
return wrap(_nextIndex + _count - 1, _count);
}
function oldestIndex(uint256 _nextIndex, uint256 _count, uint256 _cardinality)
internal
pure
returns (uint256)
{
if (_count < _cardinality) {
return 0;
} else {
return wrap(_nextIndex + _cardinality, _cardinality);
}
}
/// @notice Computes the ring buffer index that follows the given one, wrapped by cardinality
/// @param _index The index to increment
/// @param _cardinality The number of elements in the Ring Buffer
/// @return The next index relative to the given index. Will wrap around to 0 if the next index == cardinality
function nextIndex(uint256 _index, uint256 _cardinality)
internal
pure
returns (uint256)
{
return wrap(_index + 1, _cardinality);
}
/// @notice Computes the ring buffer index that preceeds the given one, wrapped by cardinality
/// @param _index The index to increment
/// @param _cardinality The number of elements in the Ring Buffer
/// @return The prev index relative to the given index. Will wrap around to the end if the prev index == 0
function prevIndex(uint256 _index, uint256 _cardinality)
internal
pure
returns (uint256)
{
return _index == 0 ? _cardinality - 1 : _index - 1;
}
}{
"remappings": [
"ds-test/=lib/forge-std/lib/ds-test/src/",
"forge-std/=lib/forge-std/src/",
"aave-address-book/=lib/aave-address-book/src/",
"chainlink/=lib/pt-v5-chainlink-vrf-v2-direct/lib/chainlink/contracts/src/v0.8/",
"openzeppelin/=lib/openzeppelin-contracts/contracts/",
"prb-math/=lib/pt-v5-cgda-liquidator/lib/prb-math/src/",
"solidity-stringutils/=lib/solidity-stringutils/src/",
"yield-daddy/=lib/yield-daddy/src/",
"pt-v5-chainlink-vrf-v2-direct/=lib/pt-v5-chainlink-vrf-v2-direct/src/",
"pt-v5-draw-auction/=lib/pt-v5-draw-auction/src/",
"pt-v5-cgda-liquidator/=lib/pt-v5-cgda-liquidator/src/",
"pt-v5-liquidator-interfaces/=lib/pt-v5-cgda-liquidator/lib/pt-v5-liquidator-interfaces/src/interfaces/",
"pt-v5-prize-pool/=lib/pt-v5-prize-pool/src/",
"pt-v5-twab-controller/=lib/pt-v5-twab-controller/src/",
"pt-v5-vault/=lib/pt-v5-vault/src/",
"pt-v5-vault-boost/=lib/pt-v5-vault-boost/src/",
"pt-v5-vault-mock/=lib/pt-v5-vault/test/contracts/mock/",
"pt-v5-claimer/=lib/pt-v5-claimer/src/",
"rng/=lib/pt-v5-draw-auction/lib/pt-v5-rng-contracts/contracts/",
"rng-contracts/=lib/pt-v5-draw-auction/lib/pt-v5-rng-contracts/contracts/",
"remote-owner/=lib/pt-v5-draw-auction/lib/remote-owner/src/",
"@aave/core-v3/=lib/aave-address-book/lib/aave-v3-core/",
"@aave/periphery-v3/=lib/aave-address-book/lib/aave-v3-periphery/",
"@openzeppelin/=lib/pt-v5-draw-auction/lib/openzeppelin-contracts/",
"@prb/test/=lib/pt-v5-vault-boost/lib/prb-math/lib/prb-test/src/",
"aave-v3-core/=lib/aave-address-book/lib/aave-v3-core/",
"aave-v3-periphery/=lib/aave-address-book/lib/aave-v3-periphery/",
"brokentoken/=lib/pt-v5-vault/lib/brokentoken/src/",
"create3-factory/=lib/yield-daddy/lib/create3-factory/",
"erc4626-tests/=lib/pt-v5-vault/lib/erc4626-tests/",
"erc5164-interfaces/=lib/pt-v5-draw-auction/lib/remote-owner/lib/erc5164-interfaces/src/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"owner-manager-contracts/=lib/pt-v5-chainlink-vrf-v2-direct/lib/owner-manager-contracts/contracts/",
"owner-manager/=lib/pt-v5-chainlink-vrf-v2-direct/lib/owner-manager-contracts/contracts/",
"prb-test/=lib/pt-v5-vault-boost/lib/prb-math/lib/prb-test/src/",
"pt-v5-rng-contracts/=lib/pt-v5-rng-contracts/contracts/",
"pt-v5-twab-delegator/=lib/pt-v5-twab-delegator/src/",
"ring-buffer-lib/=lib/pt-v5-twab-controller/lib/ring-buffer-lib/src/",
"rng/=lib/pt-v5-draw-auction/lib/pt-v5-rng-contracts/contracts/",
"solmate/=lib/yield-daddy/lib/solmate/src/",
"uniform-random-number/=lib/pt-v5-prize-pool/lib/uniform-random-number/src/",
"weird-erc20/=lib/pt-v5-vault/lib/brokentoken/lib/weird-erc20/src/"
],
"optimizer": {
"enabled": true,
"runs": 200,
"details": {
"peephole": true,
"inliner": true,
"deduplicate": true,
"cse": true,
"yul": true
}
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "paris",
"viaIR": true,
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"uint48","name":"_periodLength","type":"uint48"},{"internalType":"uint48","name":"_periodOffset","type":"uint48"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint112","name":"balance","type":"uint112"},{"internalType":"uint112","name":"amount","type":"uint112"},{"internalType":"string","name":"message","type":"string"}],"name":"BalanceLTAmount","type":"error"},{"inputs":[],"name":"CannotTransferToSponsorshipAddress","type":"error"},{"inputs":[{"internalType":"uint112","name":"delegateBalance","type":"uint112"},{"internalType":"uint112","name":"delegateAmount","type":"uint112"},{"internalType":"string","name":"message","type":"string"}],"name":"DelegateBalanceLTAmount","type":"error"},{"inputs":[{"internalType":"uint48","name":"requestedTimestamp","type":"uint48"},{"internalType":"uint48","name":"oldestTimestamp","type":"uint48"}],"name":"InsufficientHistory","type":"error"},{"inputs":[{"internalType":"uint256","name":"start","type":"uint256"},{"internalType":"uint256","name":"end","type":"uint256"}],"name":"InvalidTimeRange","type":"error"},{"inputs":[],"name":"PeriodLengthTooShort","type":"error"},{"inputs":[{"internalType":"uint48","name":"periodOffset","type":"uint48"}],"name":"PeriodOffsetInFuture","type":"error"},{"inputs":[{"internalType":"address","name":"delegate","type":"address"}],"name":"SameDelegateAlreadySet","type":"error"},{"inputs":[{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"uint256","name":"currentOverwritePeriodStartedAt","type":"uint256"}],"name":"TimestampNotFinalized","type":"error"},{"inputs":[],"name":"TransferToZeroAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint112","name":"amount","type":"uint112"},{"indexed":false,"internalType":"uint112","name":"delegateAmount","type":"uint112"}],"name":"DecreasedBalance","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":false,"internalType":"uint112","name":"amount","type":"uint112"},{"indexed":false,"internalType":"uint112","name":"delegateAmount","type":"uint112"}],"name":"DecreasedTotalSupply","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":true,"internalType":"address","name":"delegator","type":"address"},{"indexed":true,"internalType":"address","name":"delegate","type":"address"}],"name":"Delegated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint112","name":"amount","type":"uint112"},{"indexed":false,"internalType":"uint112","name":"delegateAmount","type":"uint112"}],"name":"IncreasedBalance","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":false,"internalType":"uint112","name":"amount","type":"uint112"},{"indexed":false,"internalType":"uint112","name":"delegateAmount","type":"uint112"}],"name":"IncreasedTotalSupply","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint112","name":"balance","type":"uint112"},{"indexed":false,"internalType":"uint112","name":"delegateBalance","type":"uint112"},{"indexed":false,"internalType":"bool","name":"isNew","type":"bool"},{"components":[{"internalType":"uint160","name":"cumulativeBalance","type":"uint160"},{"internalType":"uint48","name":"timestamp","type":"uint48"}],"indexed":false,"internalType":"struct ObservationLib.Observation","name":"observation","type":"tuple"}],"name":"ObservationRecorded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":false,"internalType":"uint112","name":"balance","type":"uint112"},{"indexed":false,"internalType":"uint112","name":"delegateBalance","type":"uint112"},{"indexed":false,"internalType":"bool","name":"isNew","type":"bool"},{"components":[{"internalType":"uint160","name":"cumulativeBalance","type":"uint160"},{"internalType":"uint48","name":"timestamp","type":"uint48"}],"indexed":false,"internalType":"struct ObservationLib.Observation","name":"observation","type":"tuple"}],"name":"TotalSupplyObservationRecorded","type":"event"},{"inputs":[],"name":"PERIOD_LENGTH","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PERIOD_OFFSET","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"user","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"uint112","name":"_amount","type":"uint112"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"currentOverwritePeriodStartedAt","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_vault","type":"address"},{"internalType":"address","name":"_to","type":"address"}],"name":"delegate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"user","type":"address"}],"name":"delegateBalanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"user","type":"address"}],"name":"delegateOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"user","type":"address"}],"name":"getAccount","outputs":[{"components":[{"components":[{"internalType":"uint112","name":"balance","type":"uint112"},{"internalType":"uint112","name":"delegateBalance","type":"uint112"},{"internalType":"uint16","name":"nextObservationIndex","type":"uint16"},{"internalType":"uint16","name":"cardinality","type":"uint16"}],"internalType":"struct TwabLib.AccountDetails","name":"details","type":"tuple"},{"components":[{"internalType":"uint160","name":"cumulativeBalance","type":"uint160"},{"internalType":"uint48","name":"timestamp","type":"uint48"}],"internalType":"struct ObservationLib.Observation[9600]","name":"observations","type":"tuple[9600]"}],"internalType":"struct TwabLib.Account","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"user","type":"address"},{"internalType":"uint48","name":"periodEndOnOrAfterTime","type":"uint48"}],"name":"getBalanceAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"user","type":"address"}],"name":"getNewestObservation","outputs":[{"internalType":"uint16","name":"","type":"uint16"},{"components":[{"internalType":"uint160","name":"cumulativeBalance","type":"uint160"},{"internalType":"uint48","name":"timestamp","type":"uint48"}],"internalType":"struct ObservationLib.Observation","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"}],"name":"getNewestTotalSupplyObservation","outputs":[{"internalType":"uint16","name":"","type":"uint16"},{"components":[{"internalType":"uint160","name":"cumulativeBalance","type":"uint160"},{"internalType":"uint48","name":"timestamp","type":"uint48"}],"internalType":"struct ObservationLib.Observation","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"user","type":"address"}],"name":"getOldestObservation","outputs":[{"internalType":"uint16","name":"","type":"uint16"},{"components":[{"internalType":"uint160","name":"cumulativeBalance","type":"uint160"},{"internalType":"uint48","name":"timestamp","type":"uint48"}],"internalType":"struct ObservationLib.Observation","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"}],"name":"getOldestTotalSupplyObservation","outputs":[{"internalType":"uint16","name":"","type":"uint16"},{"components":[{"internalType":"uint160","name":"cumulativeBalance","type":"uint160"},{"internalType":"uint48","name":"timestamp","type":"uint48"}],"internalType":"struct ObservationLib.Observation","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint48","name":"time","type":"uint48"}],"name":"getTimestampPeriod","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"}],"name":"getTotalSupplyAccount","outputs":[{"components":[{"components":[{"internalType":"uint112","name":"balance","type":"uint112"},{"internalType":"uint112","name":"delegateBalance","type":"uint112"},{"internalType":"uint16","name":"nextObservationIndex","type":"uint16"},{"internalType":"uint16","name":"cardinality","type":"uint16"}],"internalType":"struct TwabLib.AccountDetails","name":"details","type":"tuple"},{"components":[{"internalType":"uint160","name":"cumulativeBalance","type":"uint160"},{"internalType":"uint48","name":"timestamp","type":"uint48"}],"internalType":"struct ObservationLib.Observation[9600]","name":"observations","type":"tuple[9600]"}],"internalType":"struct TwabLib.Account","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"uint48","name":"periodEndOnOrAfterTime","type":"uint48"}],"name":"getTotalSupplyAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"uint48","name":"startTime","type":"uint48"},{"internalType":"uint48","name":"endTime","type":"uint48"}],"name":"getTotalSupplyTwabBetween","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"user","type":"address"},{"internalType":"uint48","name":"startTime","type":"uint48"},{"internalType":"uint48","name":"endTime","type":"uint48"}],"name":"getTwabBetween","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint48","name":"time","type":"uint48"}],"name":"hasFinalized","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint112","name":"_amount","type":"uint112"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint48","name":"_timestamp","type":"uint48"}],"name":"periodEndOnOrAfter","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"}],"name":"sponsor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"}],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"}],"name":"totalSupplyDelegateBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint112","name":"_amount","type":"uint112"}],"name":"transfer","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
60c034620001aa57601f62002f4f38819003918201601f19168301916001600160401b03831184841017620001af578084926040948552833981010312620001aa576200005a60206200005283620001c5565b9201620001c5565b9065ffffffffffff610e10818316106200019957821642811162000181575060805260a052604051612d759081620001da82396080518181816102610152818161041301528181610533015281816105ce0152818161075d0152818161092901528181610e0901528181610f3101528181610ff1015281816113580152818161185a0152818161198101528181611ac101528181611c2c01528181611d5401528181611ea90152611f99015260a05181818161043501528181610555015281816105aa0152818161073c0152818161090501528181610b6c01528181610e2b01528181610f5801528181610fd00152818161131a015281816118390152818161196001528181611aa001528181611c0b01528181611d3301528181611e880152611f780152f35b60249060405190630eb4f33f60e01b82526004820152fd5b6040516238782760e91b8152600490fd5b600080fd5b634e487b7160e01b600052604160045260246000fd5b519065ffffffffffff82168203620001aa5756fe6040608081526004908136101561001557600080fd5b600091823560e01c9081630b6511f214611015578163221b8d1714610fa6578163222bae1614610ece5781633357aebd14610dc65781633621b5a914610d785781633aaa523214610d335781633d59415114610c9d57816347c6394a14610c33578163486fd27914610be65781634a5958ba14610b905781634c08d8e814610b4d57816375cfddfe14610ae6578163766c4f371461098657816376b4679c14610955578163805965f9146108e45781638ab656861461060657816394b723f71461057f57816396a4af13146104e65781639cead372146103da57508063b5f783a81461039c578063be007929146102fa578063bfa1e161146102c6578063e4dc2aa414610285578063e7a891b914610243578063f7888aec146101f35763fd5908471461014157600080fd5b346101ef57806003193601126101ef57610159611063565b9061016261107e565b61016a611239565b506001600160a01b039283168452602084815282852091909316845282528083209261019461117d565b9261019e85611288565b84526101a86111b3565b9182600180970191905b61258082106101d4575050506101d0945083015251918291826110d5565b0390f35b878481926101e1866112c1565b8152019301910190916101b2565b5080fd5b50346101ef57806003193601126101ef576001600160701b0381602093610218611063565b61022061107e565b6001600160a01b0391821683528287528383209116825285522054915191168152f35b50346101ef57816003193601126101ef576020905165ffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b50346101ef5760203660031901126101ef576020916001600160701b039082906001600160a01b036102b5611063565b168152600185522054169051908152f35b50346101ef5760203660031901126101ef5760209065ffffffffffff6102f26102ed611096565b611318565b915191168152f35b50346101ef57806003193601126101ef57610363816101d09361031b611063565b61032361107e565b9082602061032f61117d565b82815201526001600160a01b03908116835260208381528484209290911683525220600161035c82611288565b910161244b565b915161ffff909116815281516001600160a01b03166020808301919091529091015165ffffffffffff1660408201529081906060820190565b50346101ef57806003193601126101ef576020906103c96103bb611063565b6103c361107e565b90611772565b90516001600160a01b039091168152f35b9050346104e257816003193601126104e257816103f5611063565b936103fe6110c0565b6001600160a01b0390951681526001602052207f0000000000000000000000000000000000000000000000000000000000000000937f0000000000000000000000000000000000000000000000000000000000000000919061045f90611318565b9461046982611288565b9365ffffffffffff6104938561048e838b169561048985421684836129f4565b612a2c565b612a49565b90811683116104b5576020876104ae8a89600189018a612529565b9051908152f35b865163947ad91360e01b815291820192835265ffffffffffff1660208301529081906040010390fd5b0390fd5b8280fd5b9050346104e25760603660031901126104e25781610502611063565b9361050b61107e565b6105136110ab565b6001600160a01b03968716835260208381528484209290971683529552207f0000000000000000000000000000000000000000000000000000000000000000937f0000000000000000000000000000000000000000000000000000000000000000919061045f90611318565b5050346101ef5760203660031901126101ef5760209061059d611096565b65ffffffffffff806105fa7f000000000000000000000000000000000000000000000000000000000000000061048e7f000000000000000000000000000000000000000000000000000000000000000061048942861684836129f4565b16911611159051908152f35b839150346101ef57826003193601126101ef57610621611063565b9261062a61107e565b936106353382611772565b6001600160a01b038681169690948715949290919085156108de5760015b878083169116978189146108c757861696878a5260209360028552868b20338c528552868b208a6bffffffffffffffffffffffff60a01b825416179055888b528a8552868b20338c5285526001600160701b039788888d205416968988116108745750899a9b9c84159384159689888099610869575b610832575b5050159081610826575b50610709575b8c8c338c7f2190b8902ea4a5dbea665e1965f2b2c0b04788c8831da4d881b56ddc9ead4fe88480a480f35b61071491879161180a565b9161081b575b5061072a575b80808080806106de565b84918289526001825261078181858b207f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000612055565b9590919293878d826107e6575b5050505061079e575b5050610720565b856107d7937feae651f8ba33ae01bde5a6272915d135baf7c791a99def90e70c81aeb809135897865116950151169451948594856117c4565b0390a280848080808080610797565b7ffb57251c875b0c08eb0c579e0007f5f325dc5d7db5ff497ff16ff602bcbf84a692825191825288820152a2878c878d61078e565b60019150148961071a565b6001915014158e6106d8565b61083c9185611a2c565b80811561085f575b610850575b8f896106ce565b61085a8984611ccf565b610849565b5060018214610844565b5060018814156106c9565b885162461bcd60e51b8152908101879052602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663132206269747360c81b6064820152608490fd5b8551634929aa6560e01b81528086018a9052602490fd5b81610653565b5050346101ef57816003193601126101ef5760209065ffffffffffff6102f27f000000000000000000000000000000000000000000000000000000000000000061048e7f000000000000000000000000000000000000000000000000000000000000000061048942861684836129f4565b5050346101ef5736600319011261098357610980610971611063565b610979611167565b9033611490565b80f35b80fd5b839150346101ef57602090816003193601126104e2576109a4611063565b916109af8333611772565b916001600160a01b03808416919060018314610acf5733875260028452878720951694858752835286862060016bffffffffffffffffffffffff60a01b82541617905533865285835286862085875283526001600160701b0392838888205416938411610a7d57505060019495508015159081610a72575b50610a57575b5050337f2190b8902ea4a5dbea665e1965f2b2c0b04788c8831da4d881b56ddc9ead4fe88480a480f35b610a6581610a6b9333611a2c565b33611ccf565b8380610a2d565b859150141586610a27565b875162461bcd60e51b815291820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663132206269747360c81b606482015260849150fd5b8751634929aa6560e01b8152600181840152602490fd5b8383346101ef5760603660031901126101ef57610b01611063565b610b0961107e565b90604435926001600160701b0384168403610b49576001600160a01b03831615610b3a575061098093945033611529565b51633a954ecd60e21b81528590fd5b8480fd5b5050346101ef57816003193601126101ef576020905165ffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b5050346101ef57806003193601126101ef576001600160701b0381602093610bb6611063565b610bbe61107e565b6001600160a01b0391821683528287528383209116825285522054915160709290921c168152f35b8383346101ef57806003193601126101ef57610c00611063565b610c08611167565b916001600160a01b03821615610c2457509061098091336113d6565b51633a954ecd60e21b81528490fd5b5050346101ef57806003193601126101ef57610363816101d093610c55611063565b610c5d61107e565b90826020610c6961117d565b82815201526001600160a01b039081168352602083815284842092909116835252206001610c9682611288565b910161249b565b82843461098357602091826003193601126101ef57610cba611063565b610cc2611239565b506001600160a01b0316825260018084528183209093610ce061117d565b93610cea83611288565b8552610cf46111b3565b92860190835b6125808210610d18575050506101d0945083015251918291826110d5565b87848192610d25866112c1565b815201930191019091610cfa565b5050346101ef5760203660031901126101ef576020916001600160701b039082906001600160a01b03610d64611063565b16815260018552205460701c169051908152f35b5050346101ef5760203660031901126101ef57610363816101d093610d9b611063565b816020610da661117d565b828152015260018060a01b03168152600160205220600161035c82611288565b9050346104e25760603660031901126104e257610de1611063565b9082610deb6110c0565b94610df46110ab565b6001600160a01b0390941681526001602052207f0000000000000000000000000000000000000000000000000000000000000000947f00000000000000000000000000000000000000000000000000000000000000009190610e5f90610e5990611318565b94611318565b95610e6982611288565b9365ffffffffffff610e898561048e838c169561048985421684836129f4565b9081168311610ea5576020886104ae8b8a8a60018a018b612596565b875163947ad91360e01b815291820192835265ffffffffffff1660208301529081906040010390fd5b82843461098357608036600319011261098357610ee9611063565b610ef161107e565b91610efa6110ab565b906064359365ffffffffffff9384861686036104e2579086929160018060a01b0380911683528260205283832091168252602052207f0000000000000000000000000000000000000000000000000000000000000000610f83610f7d7f000000000000000000000000000000000000000000000000000000000000000094611318565b95611318565b96610f8d83611288565b94610e898561048e838c169561048985421684836129f4565b5050346101ef5760203660031901126101ef5760209065ffffffffffff6102f2610fce611096565b7f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000006129f4565b5050346101ef5760203660031901126101ef57610363816101d093611038611063565b81602061104361117d565b828152015260018060a01b031681526001602052206001610c9682611288565b600435906001600160a01b038216820361107957565b600080fd5b602435906001600160a01b038216820361107957565b565b6004359065ffffffffffff8216820361107957565b6044359065ffffffffffff8216820361107957565b6024359065ffffffffffff8216820361107957565b9190916209608081019280519160806001600160701b03808551168352602093849182870151168285015261ffff60606040978289820151168988015201511660608501520151910190926000915b6125808310611134575050505050565b845180516001600160a01b0316825260209081015165ffffffffffff169082015260019084908301950192019193611124565b602435906001600160701b038216820361107957565b604051906040820182811067ffffffffffffffff82111761119d57604052565b634e487b7160e01b600052604160045260246000fd5b604051906204b000820182811067ffffffffffffffff82111761119d57604052565b604051906080820182811067ffffffffffffffff82111761119d57604052565b604051906060820182811067ffffffffffffffff82111761119d57604052565b61121d6111d5565b9060008252600060208301526000604083015260006060830152565b61124161117d565b9061124a611215565b82526112546111b3565b6000805b6204b000811061126b5750506020830152565b60209061127661117d565b83815283838201528185015201611258565b906112916111d5565b91546001600160701b0380821684528160701c16602084015261ffff8160e01c16604084015260f01c6060830152565b9065ffffffffffff6112d161117d565b92546001600160a01b038116845260a01c166020830152565b65ffffffffffff918216908216039190821161130257565b634e487b7160e01b600052601160045260246000fd5b7f000000000000000000000000000000000000000000000000000000000000000065ffffffffffff808216818416106113d05761135582846112ea565b927f00000000000000000000000000000000000000000000000000000000000000009382851680156113ba57838092160616156113b3578161139a60019285876129f4565b1601908111611302576113b09261048e91612a2c565b90565b9250505090565b634e487b7160e01b600052601260045260246000fd5b50905090565b6001600160a01b039290918381166001811461147e5780156114775761109494838361142161140760019689611772565b938416948514918360008415611471575080915b8a61192a565b1580611467575b611456575b50501480159061144e575b6000901561144857508091611f52565b91611f52565b506000611438565b611460918661180a565b388361142d565b5083831415611428565b9161141b565b5050505050565b604051635bb7132160e11b8152600490fd5b6001600160a01b039290918381168015611477576110949483836114d36114b960019689611772565b938416948514918360008415611523575080915b8a611b92565b1580611519575b611508575b505014801590611500575b600090156114fa57508091611e1d565b91611e1d565b5060006114ea565b6115129186611a2c565b38836114df565b50838314156114da565b916114cd565b6001600160a01b0393909291848316600181811461147e578683168281146117685784906115578589611772565b96611562818a611772565b918015968b8b8915968761167b575b505050505084611588575b50505050505050505050565b86906115a98b84169687149183600084600014611675575080915b8d61192a565b158061166b575b61165a575b50508390611644575b6115cb575b80808061157c565b6115fd966000841561163e575084955b84611633575b8415611611575b50505050600090600014611609575091611f52565b388080808080806115c3565b905091611f52565b16811492509082611628575b5050388080806115e8565b14159050388061161d565b8383141594506115e1565b956115db565b50808786161480156115be5750808214156115be565b611664918961180a565b38856115b5565b50838514156115b0565b916115a3565b611697928d169485149360008560001461176257508192611b92565b1580611758575b611748575b8a8615808015611732575b6116bc575b50808b8a611571565b6116f192876000831561172c57508b935b83611721575b83156116ff575b5050506000906000146116f9575088905b8b611e1d565b388a816116b3565b906116eb565b8716811492509082611716575b505038878e6116da565b14159050863861170c565b8282141593506116d3565b936116cd565b50868286161480156116ae5750868314156116ae565b611753888a8c611a2c565b6116a3565b508481141561169e565b92611b92565b5050505050505050565b600091906001600160a01b03908183169081611790575b5050505090565b908260409394959216825260026020528282209082526020522054169081156117bc575b808080611789565b9050386117b4565b6001600160701b0391821681529116602080830191909152911515604082015282516001600160a01b0316606082015291015165ffffffffffff16608082015260a00190565b60018060a01b0380911680926000928284528360205260408420911694859182855260205261187e81604086207f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000612055565b9491959092966001600160701b03809516806118f1575b505050506118a6575b505050505050565b7f2eb17e9371eb7318e7c285b069645e929592ec62f0cdc4d643a25c90f28b2713938160206118e3938551169401511693604051948594856117c4565b0390a338808080808061189e565b7feb6e9317593a8d7c742d6d9f0fd98b797fb448ca2e1751fff686eb1b926908a69160409182519182526020820152a386863880611895565b91909160018060a01b0380911692839182600052600060205260406000209116948591826000526020526119a5818560406000207f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000612121565b9491959092966001600160701b039485821615801590611a21575b6119d457505050506118a657505050505050565b604080516001600160701b0393841681529190921660208201527feb6e9317593a8d7c742d6d9f0fd98b797fb448ca2e1751fff686eb1b926908a691819081015b0390a386863880611895565b5085811615156119c0565b9060018060a01b03809216918291600094838652856020526040928387209216958692838252602052611ae584822083611a646111f5565b91602783527f54432f6f62736572766174696f6e2d6275726e2d6c742d64656c65676174652d60208401526662616c616e636560c81b888401527f00000000000000000000000000000000000000000000000000000000000000007f000000000000000000000000000000000000000000000000000000000000000061220e565b959197909293876001600160701b038097169182611b5b575b5050505050611b11575b50505050505050565b7f2eb17e9371eb7318e7c285b069645e929592ec62f0cdc4d643a25c90f28b271394826020611b4c94865116950151169451948594856117c4565b0390a338808080808080611b08565b7fecea9d1177e84dfeb854ffa4eea25661654c8b077bfa1d9ddf6c5bfbae5f30919282519182526020820152a38787388781611afe565b91909160018060a01b038091169283918260005260006020526040600020911694859182600052602052611c5060406000208286611bce6111f5565b92602784527f54432f6f62736572766174696f6e2d6275726e2d6c742d64656c65676174652d60208501526662616c616e636560c81b60408501527f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000612300565b9491959092966001600160701b039485821615801590611cc4575b611c7f57505050506118a657505050505050565b604080516001600160701b0393841681529190921660208201527fecea9d1177e84dfeb854ffa4eea25661654c8b077bfa1d9ddf6c5bfbae5f30919181908101611a15565b508581161515611c6b565b60018060a01b031690816000526001602052611d78604060002082611cf26111f5565b91602b83527f54432f6275726e2d616d6f756e742d657863656564732d746f74616c2d73757060208401526a706c792d62616c616e636560a81b60408401527f00000000000000000000000000000000000000000000000000000000000000007f000000000000000000000000000000000000000000000000000000000000000061220e565b91929390856001600160701b0380931680611de5575b5050611d9b575050505050565b7feae651f8ba33ae01bde5a6272915d135baf7c791a99def90e70c81aeb809135893816020611dd8938551169401511693604051948594856117c4565b0390a23880808080611477565b60407faa5ae1dd90198687ea3c711472b6ec97b9962a1cfcfdbc4917ac9d19063823bc91815190600082526020820152a28538611d8e565b6001600160a01b031660008181526001602052604090209092839291611ecd908284611e476111f5565b92602b84527f54432f6275726e2d616d6f756e742d657863656564732d746f74616c2d73757060208501526a706c792d62616c616e636560a81b60408501527f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000612300565b9392959091946001600160701b039384821615801590611f47575b611efb575b505050611d9b575050505050565b604080516001600160701b0393841681529190921660208201527faa5ae1dd90198687ea3c711472b6ec97b9962a1cfcfdbc4917ac9d19063823bc91819081015b0390a2853880611eed565b508481161515611ee8565b6001600160a01b031660008181526001602052604090209092839291611fbd90829084907f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000612121565b9392959091946001600160701b03938482161580159061202f575b611fea57505050611d9b575050505050565b604080516001600160701b0393841681529190921660208201527ffb57251c875b0c08eb0c579e0007f5f325dc5d7db5ff497ff16ff602bcbf84a69181908101611f3c565b508481161515611fd8565b9190916001600160701b038080941691160191821161130257565b919361205f61117d565b600081526000602082015294600094612076611215565b5061208082611288565b936001600160701b039081831615159687612102575b5050808551168181116113025785526120b660208601928284511661203a565b81811690925284516040860151606087015160709490941b600160701b600160e01b0316919092161760e09190911b61ffff60e01b161760f09190911b6001600160f01b031916179055565b84985061211394939692995061274a565b959195939095963880612096565b92919490939461212f61117d565b600081526000602082015295600095612146611215565b5061215083611288565b946001600160701b03918284161515978861218a575b505061217682918288511661203a565b1685526120b660208601928284511661203a565b61219f929a508399509685916121769861274a565b9891989690989991612166565b919392906001600160701b03809116835260209416848301526060604083015280519081606084015260005b8281106121fa57505060809293506000838284010152601f8019910116010190565b8181018601518482016080015285016121d8565b9294909161221a61117d565b600081526000602082015295600095612231611215565b5061223b83611288565b946001600160701b039182602088015116838516918282106122e1575050151596876122c2575b5050845181168086526020860180518316939093039182169092526040850151606086015160709290921b600160701b600160e01b031690921760e09290921b61ffff60e01b169190911760f09190911b6001600160f01b031916179055565b8498506122d394939692995061274a565b959195939095963880612262565b604051635f46f05b60e11b81529182916104de918890600485016121ac565b9395919092949561230f61117d565b600081526000602082015296600096612326611215565b5061233084611288565b956001600160701b0392838851168484168110612406575083602089015116848616918282106123e7575050151597886123c8575b5050855182160381168086526020860180518316939093039182169092526040850151606086015160709290921b600160701b600160e01b031690921760e09290921b61ffff60e01b169190911760f09190911b6001600160f01b031916179055565b85929a50839950906123db93979161274a565b91989097919538612365565b604051635f46f05b60e11b81529182916104de918990600485016121ac565b6104de8492604051938493631a587c8d60e31b8552600485016121ac565b612580821015612435570190600090565b634e487b7160e01b600052603260045260246000fd5b91906000602061245961117d565b828152015261ffff9061258082606083015116106000146124815750506113b06000926112c1565b6113b0916040612495920151168094612424565b506112c1565b919060206040916124aa61117d565b6000928184809352015261ffff92839101511661258091828201918281116124fe5761257f019182116124ea575091612495916113b09306168094612424565b634e487b7160e01b81526011600452602490fd5b634e487b7160e01b82526011600452602482fd5b9190820180921161130257565b81156113ba570690565b9282826125369395612a63565b90939190156125485750505050600090565b6001600160a01b03936125619361ffff909116926126a4565b1690565b6001600160a01b03918216908216039190821161130257565b6001600160a01b03918216919082156113ba57160490565b9293919365ffffffffffff9182841683831696818811612686576125bc8682858a612a63565b509390928398818b14612663578684846125d593612a63565b5090809b896020830151160361264b575b5050866020850151160361262a575b5050945195516001600160a01b0396612561965061262393925061261d918816908816612565565b936112ea565b169061257e565b6125619750612623949361261d936126439389936128af565b9582936125f5565b61265b929b5090879185856128af565b9838806125e6565b506001600160a01b03995061256198505061ffff909316955090935091506126a4565b6044888360405191630e781b2360e31b835260048301526024820152fd5b92909263ffffffff8092169060018201809211611302576126ce9261258061249593061690612424565b602081019165ffffffffffff9182845116801590811561273a575b50156127035750505050602001516001600160701b031690565b5181516113b0955061262392918491602091839161272d916001600160a01b039182169116612565565b96511692015116906112ea565b90508360208401511611386126e9565b612793836020929694939661275d61117d565b6000948186809352015261276f611215565b50600163ffffffff42169785602061278561117d565b828152015201978891612902565b9591908287612825575b6127b5916001600160701b03602088015116906129a9565b906127de6127c161117d565b6001600160a01b0393841681526020810194855298899290612424565b949094612811575051835492516001600160d01b031990931691161760a09190911b65ffffffffffff60a01b1617905590565b634e487b7160e01b81526004819052602490fd5b5061ffff808316906001820180921161289b5780612580809306166040880152606087019185828451169180831060001461288d57505060010181811161287957916127b5939186935b169052915061279d565b634e487b7160e01b87526011600452602487fd5b6127b595939194925061286f565b634e487b7160e01b86526011600452602486fd5b916128dd6128e39382879461ffff65ffffffffffff98600060206128d161117d565b828152015216926126a4565b906129a9565b916128ec61117d565b6001600160a01b03909316835216602082015290565b9392909181612921916000602061291761117d565b828152015261249b565b919092829565ffffffffffff9384602082015116421461299c575061295b9061294d85421684836129f4565b928560208a015116916129f4565b9061ffff93846060850151161592831561298d575b5050506129805750509190600090565b6040015116929160019150565b81169116119050388080612970565b9650505050509190600090565b80516020909101516001600160a01b039391841691849165ffffffffffff916129d4918316906112ea565b169216838382021692818404149015171561130257019081116113025790565b919065ffffffffffff918282168382161115612a23578291612a15916112ea565b1691169081156113ba570490565b50505050600090565b91909165ffffffffffff8080941691160291821691820361130257565b91909165ffffffffffff8080941691160191821161130257565b93919093612a6f61117d565b90600094858352856020809401528583612a8761117d565b82815201526060840161ffff928382511615612d175750612aa8858961244b565b65ffffffffffff9591959283808484015116951694808610612cc85750600197888783511614612cb957612aeb908b85612ae061117d565b82815201528c61249b565b858582949394015116871015612ca957505186169160028314612c9a5750851695851694612b1761117d565b8a81528a84820152978a9b8b8285612b2d61117d565b83815283898201529a839c819450818110600014612c8a5750612b509250612512565b6000198101908111612c2d5792949392859291905b955b612b8a575b5050505050508301511614612b82575050929190565b945092919050565b90919293949d506124959c9b9a50612ba28e82612512565b831c612bbb85612bb2888461251f565b169e8f85612424565b9a88888d0151169a8b15612c62575050838101808211612c2d576124959b9c9d9e9f8a612bf588612bec8b8661251f565b169e8f88612424565b9c119182158b8b8f83612c52575b505050612c4a57869215612c41575050506000198101908111612c2d57835b929190959493612b67565b634e487b7160e01b8e52601160045260248efd5b93509150612c22565b505050612b6c565b0151168d111590508b8b8f612c03565b9a509a9b9c9d9e919050838101809111612c2d579084612c8387869461251f565b1691612c22565b9150509594939592919092612b65565b97505050505050509350929190565b9850509950505050505050929190565b50509550505050509350929190565b96509250509596975061258092919450511610600014612cf95750612ceb61117d565b918483528201529190600190565b6044925060405191636029932560e11b835260048301526024820152fd5b95969750505050905065ffffffffffff612d2f61117d565b928584521690820152919060019056fea2646970667358221220afb56b34cd42494a198582b00e709aa76432ef2648596f22f181398cd7fb350b64736f6c634300081300330000000000000000000000000000000000000000000000000000000000000e100000000000000000000000000000000000000000000000000000000064ee4030
Deployed Bytecode
0x6040608081526004908136101561001557600080fd5b600091823560e01c9081630b6511f214611015578163221b8d1714610fa6578163222bae1614610ece5781633357aebd14610dc65781633621b5a914610d785781633aaa523214610d335781633d59415114610c9d57816347c6394a14610c33578163486fd27914610be65781634a5958ba14610b905781634c08d8e814610b4d57816375cfddfe14610ae6578163766c4f371461098657816376b4679c14610955578163805965f9146108e45781638ab656861461060657816394b723f71461057f57816396a4af13146104e65781639cead372146103da57508063b5f783a81461039c578063be007929146102fa578063bfa1e161146102c6578063e4dc2aa414610285578063e7a891b914610243578063f7888aec146101f35763fd5908471461014157600080fd5b346101ef57806003193601126101ef57610159611063565b9061016261107e565b61016a611239565b506001600160a01b039283168452602084815282852091909316845282528083209261019461117d565b9261019e85611288565b84526101a86111b3565b9182600180970191905b61258082106101d4575050506101d0945083015251918291826110d5565b0390f35b878481926101e1866112c1565b8152019301910190916101b2565b5080fd5b50346101ef57806003193601126101ef576001600160701b0381602093610218611063565b61022061107e565b6001600160a01b0391821683528287528383209116825285522054915191168152f35b50346101ef57816003193601126101ef576020905165ffffffffffff7f0000000000000000000000000000000000000000000000000000000000000e10168152f35b50346101ef5760203660031901126101ef576020916001600160701b039082906001600160a01b036102b5611063565b168152600185522054169051908152f35b50346101ef5760203660031901126101ef5760209065ffffffffffff6102f26102ed611096565b611318565b915191168152f35b50346101ef57806003193601126101ef57610363816101d09361031b611063565b61032361107e565b9082602061032f61117d565b82815201526001600160a01b03908116835260208381528484209290911683525220600161035c82611288565b910161244b565b915161ffff909116815281516001600160a01b03166020808301919091529091015165ffffffffffff1660408201529081906060820190565b50346101ef57806003193601126101ef576020906103c96103bb611063565b6103c361107e565b90611772565b90516001600160a01b039091168152f35b9050346104e257816003193601126104e257816103f5611063565b936103fe6110c0565b6001600160a01b0390951681526001602052207f0000000000000000000000000000000000000000000000000000000000000e10937f0000000000000000000000000000000000000000000000000000000064ee4030919061045f90611318565b9461046982611288565b9365ffffffffffff6104938561048e838b169561048985421684836129f4565b612a2c565b612a49565b90811683116104b5576020876104ae8a89600189018a612529565b9051908152f35b865163947ad91360e01b815291820192835265ffffffffffff1660208301529081906040010390fd5b0390fd5b8280fd5b9050346104e25760603660031901126104e25781610502611063565b9361050b61107e565b6105136110ab565b6001600160a01b03968716835260208381528484209290971683529552207f0000000000000000000000000000000000000000000000000000000000000e10937f0000000000000000000000000000000000000000000000000000000064ee4030919061045f90611318565b5050346101ef5760203660031901126101ef5760209061059d611096565b65ffffffffffff806105fa7f0000000000000000000000000000000000000000000000000000000064ee403061048e7f0000000000000000000000000000000000000000000000000000000000000e1061048942861684836129f4565b16911611159051908152f35b839150346101ef57826003193601126101ef57610621611063565b9261062a61107e565b936106353382611772565b6001600160a01b038681169690948715949290919085156108de5760015b878083169116978189146108c757861696878a5260209360028552868b20338c528552868b208a6bffffffffffffffffffffffff60a01b825416179055888b528a8552868b20338c5285526001600160701b039788888d205416968988116108745750899a9b9c84159384159689888099610869575b610832575b5050159081610826575b50610709575b8c8c338c7f2190b8902ea4a5dbea665e1965f2b2c0b04788c8831da4d881b56ddc9ead4fe88480a480f35b61071491879161180a565b9161081b575b5061072a575b80808080806106de565b84918289526001825261078181858b207f0000000000000000000000000000000000000000000000000000000064ee40307f0000000000000000000000000000000000000000000000000000000000000e10612055565b9590919293878d826107e6575b5050505061079e575b5050610720565b856107d7937feae651f8ba33ae01bde5a6272915d135baf7c791a99def90e70c81aeb809135897865116950151169451948594856117c4565b0390a280848080808080610797565b7ffb57251c875b0c08eb0c579e0007f5f325dc5d7db5ff497ff16ff602bcbf84a692825191825288820152a2878c878d61078e565b60019150148961071a565b6001915014158e6106d8565b61083c9185611a2c565b80811561085f575b610850575b8f896106ce565b61085a8984611ccf565b610849565b5060018214610844565b5060018814156106c9565b885162461bcd60e51b8152908101879052602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663132206269747360c81b6064820152608490fd5b8551634929aa6560e01b81528086018a9052602490fd5b81610653565b5050346101ef57816003193601126101ef5760209065ffffffffffff6102f27f0000000000000000000000000000000000000000000000000000000064ee403061048e7f0000000000000000000000000000000000000000000000000000000000000e1061048942861684836129f4565b5050346101ef5736600319011261098357610980610971611063565b610979611167565b9033611490565b80f35b80fd5b839150346101ef57602090816003193601126104e2576109a4611063565b916109af8333611772565b916001600160a01b03808416919060018314610acf5733875260028452878720951694858752835286862060016bffffffffffffffffffffffff60a01b82541617905533865285835286862085875283526001600160701b0392838888205416938411610a7d57505060019495508015159081610a72575b50610a57575b5050337f2190b8902ea4a5dbea665e1965f2b2c0b04788c8831da4d881b56ddc9ead4fe88480a480f35b610a6581610a6b9333611a2c565b33611ccf565b8380610a2d565b859150141586610a27565b875162461bcd60e51b815291820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663132206269747360c81b606482015260849150fd5b8751634929aa6560e01b8152600181840152602490fd5b8383346101ef5760603660031901126101ef57610b01611063565b610b0961107e565b90604435926001600160701b0384168403610b49576001600160a01b03831615610b3a575061098093945033611529565b51633a954ecd60e21b81528590fd5b8480fd5b5050346101ef57816003193601126101ef576020905165ffffffffffff7f0000000000000000000000000000000000000000000000000000000064ee4030168152f35b5050346101ef57806003193601126101ef576001600160701b0381602093610bb6611063565b610bbe61107e565b6001600160a01b0391821683528287528383209116825285522054915160709290921c168152f35b8383346101ef57806003193601126101ef57610c00611063565b610c08611167565b916001600160a01b03821615610c2457509061098091336113d6565b51633a954ecd60e21b81528490fd5b5050346101ef57806003193601126101ef57610363816101d093610c55611063565b610c5d61107e565b90826020610c6961117d565b82815201526001600160a01b039081168352602083815284842092909116835252206001610c9682611288565b910161249b565b82843461098357602091826003193601126101ef57610cba611063565b610cc2611239565b506001600160a01b0316825260018084528183209093610ce061117d565b93610cea83611288565b8552610cf46111b3565b92860190835b6125808210610d18575050506101d0945083015251918291826110d5565b87848192610d25866112c1565b815201930191019091610cfa565b5050346101ef5760203660031901126101ef576020916001600160701b039082906001600160a01b03610d64611063565b16815260018552205460701c169051908152f35b5050346101ef5760203660031901126101ef57610363816101d093610d9b611063565b816020610da661117d565b828152015260018060a01b03168152600160205220600161035c82611288565b9050346104e25760603660031901126104e257610de1611063565b9082610deb6110c0565b94610df46110ab565b6001600160a01b0390941681526001602052207f0000000000000000000000000000000000000000000000000000000000000e10947f0000000000000000000000000000000000000000000000000000000064ee40309190610e5f90610e5990611318565b94611318565b95610e6982611288565b9365ffffffffffff610e898561048e838c169561048985421684836129f4565b9081168311610ea5576020886104ae8b8a8a60018a018b612596565b875163947ad91360e01b815291820192835265ffffffffffff1660208301529081906040010390fd5b82843461098357608036600319011261098357610ee9611063565b610ef161107e565b91610efa6110ab565b906064359365ffffffffffff9384861686036104e2579086929160018060a01b0380911683528260205283832091168252602052207f0000000000000000000000000000000000000000000000000000000000000e10610f83610f7d7f0000000000000000000000000000000000000000000000000000000064ee403094611318565b95611318565b96610f8d83611288565b94610e898561048e838c169561048985421684836129f4565b5050346101ef5760203660031901126101ef5760209065ffffffffffff6102f2610fce611096565b7f0000000000000000000000000000000000000000000000000000000064ee40307f0000000000000000000000000000000000000000000000000000000000000e106129f4565b5050346101ef5760203660031901126101ef57610363816101d093611038611063565b81602061104361117d565b828152015260018060a01b031681526001602052206001610c9682611288565b600435906001600160a01b038216820361107957565b600080fd5b602435906001600160a01b038216820361107957565b565b6004359065ffffffffffff8216820361107957565b6044359065ffffffffffff8216820361107957565b6024359065ffffffffffff8216820361107957565b9190916209608081019280519160806001600160701b03808551168352602093849182870151168285015261ffff60606040978289820151168988015201511660608501520151910190926000915b6125808310611134575050505050565b845180516001600160a01b0316825260209081015165ffffffffffff169082015260019084908301950192019193611124565b602435906001600160701b038216820361107957565b604051906040820182811067ffffffffffffffff82111761119d57604052565b634e487b7160e01b600052604160045260246000fd5b604051906204b000820182811067ffffffffffffffff82111761119d57604052565b604051906080820182811067ffffffffffffffff82111761119d57604052565b604051906060820182811067ffffffffffffffff82111761119d57604052565b61121d6111d5565b9060008252600060208301526000604083015260006060830152565b61124161117d565b9061124a611215565b82526112546111b3565b6000805b6204b000811061126b5750506020830152565b60209061127661117d565b83815283838201528185015201611258565b906112916111d5565b91546001600160701b0380821684528160701c16602084015261ffff8160e01c16604084015260f01c6060830152565b9065ffffffffffff6112d161117d565b92546001600160a01b038116845260a01c166020830152565b65ffffffffffff918216908216039190821161130257565b634e487b7160e01b600052601160045260246000fd5b7f0000000000000000000000000000000000000000000000000000000064ee403065ffffffffffff808216818416106113d05761135582846112ea565b927f0000000000000000000000000000000000000000000000000000000000000e109382851680156113ba57838092160616156113b3578161139a60019285876129f4565b1601908111611302576113b09261048e91612a2c565b90565b9250505090565b634e487b7160e01b600052601260045260246000fd5b50905090565b6001600160a01b039290918381166001811461147e5780156114775761109494838361142161140760019689611772565b938416948514918360008415611471575080915b8a61192a565b1580611467575b611456575b50501480159061144e575b6000901561144857508091611f52565b91611f52565b506000611438565b611460918661180a565b388361142d565b5083831415611428565b9161141b565b5050505050565b604051635bb7132160e11b8152600490fd5b6001600160a01b039290918381168015611477576110949483836114d36114b960019689611772565b938416948514918360008415611523575080915b8a611b92565b1580611519575b611508575b505014801590611500575b600090156114fa57508091611e1d565b91611e1d565b5060006114ea565b6115129186611a2c565b38836114df565b50838314156114da565b916114cd565b6001600160a01b0393909291848316600181811461147e578683168281146117685784906115578589611772565b96611562818a611772565b918015968b8b8915968761167b575b505050505084611588575b50505050505050505050565b86906115a98b84169687149183600084600014611675575080915b8d61192a565b158061166b575b61165a575b50508390611644575b6115cb575b80808061157c565b6115fd966000841561163e575084955b84611633575b8415611611575b50505050600090600014611609575091611f52565b388080808080806115c3565b905091611f52565b16811492509082611628575b5050388080806115e8565b14159050388061161d565b8383141594506115e1565b956115db565b50808786161480156115be5750808214156115be565b611664918961180a565b38856115b5565b50838514156115b0565b916115a3565b611697928d169485149360008560001461176257508192611b92565b1580611758575b611748575b8a8615808015611732575b6116bc575b50808b8a611571565b6116f192876000831561172c57508b935b83611721575b83156116ff575b5050506000906000146116f9575088905b8b611e1d565b388a816116b3565b906116eb565b8716811492509082611716575b505038878e6116da565b14159050863861170c565b8282141593506116d3565b936116cd565b50868286161480156116ae5750868314156116ae565b611753888a8c611a2c565b6116a3565b508481141561169e565b92611b92565b5050505050505050565b600091906001600160a01b03908183169081611790575b5050505090565b908260409394959216825260026020528282209082526020522054169081156117bc575b808080611789565b9050386117b4565b6001600160701b0391821681529116602080830191909152911515604082015282516001600160a01b0316606082015291015165ffffffffffff16608082015260a00190565b60018060a01b0380911680926000928284528360205260408420911694859182855260205261187e81604086207f0000000000000000000000000000000000000000000000000000000064ee40307f0000000000000000000000000000000000000000000000000000000000000e10612055565b9491959092966001600160701b03809516806118f1575b505050506118a6575b505050505050565b7f2eb17e9371eb7318e7c285b069645e929592ec62f0cdc4d643a25c90f28b2713938160206118e3938551169401511693604051948594856117c4565b0390a338808080808061189e565b7feb6e9317593a8d7c742d6d9f0fd98b797fb448ca2e1751fff686eb1b926908a69160409182519182526020820152a386863880611895565b91909160018060a01b0380911692839182600052600060205260406000209116948591826000526020526119a5818560406000207f0000000000000000000000000000000000000000000000000000000064ee40307f0000000000000000000000000000000000000000000000000000000000000e10612121565b9491959092966001600160701b039485821615801590611a21575b6119d457505050506118a657505050505050565b604080516001600160701b0393841681529190921660208201527feb6e9317593a8d7c742d6d9f0fd98b797fb448ca2e1751fff686eb1b926908a691819081015b0390a386863880611895565b5085811615156119c0565b9060018060a01b03809216918291600094838652856020526040928387209216958692838252602052611ae584822083611a646111f5565b91602783527f54432f6f62736572766174696f6e2d6275726e2d6c742d64656c65676174652d60208401526662616c616e636560c81b888401527f0000000000000000000000000000000000000000000000000000000064ee40307f0000000000000000000000000000000000000000000000000000000000000e1061220e565b959197909293876001600160701b038097169182611b5b575b5050505050611b11575b50505050505050565b7f2eb17e9371eb7318e7c285b069645e929592ec62f0cdc4d643a25c90f28b271394826020611b4c94865116950151169451948594856117c4565b0390a338808080808080611b08565b7fecea9d1177e84dfeb854ffa4eea25661654c8b077bfa1d9ddf6c5bfbae5f30919282519182526020820152a38787388781611afe565b91909160018060a01b038091169283918260005260006020526040600020911694859182600052602052611c5060406000208286611bce6111f5565b92602784527f54432f6f62736572766174696f6e2d6275726e2d6c742d64656c65676174652d60208501526662616c616e636560c81b60408501527f0000000000000000000000000000000000000000000000000000000064ee40307f0000000000000000000000000000000000000000000000000000000000000e10612300565b9491959092966001600160701b039485821615801590611cc4575b611c7f57505050506118a657505050505050565b604080516001600160701b0393841681529190921660208201527fecea9d1177e84dfeb854ffa4eea25661654c8b077bfa1d9ddf6c5bfbae5f30919181908101611a15565b508581161515611c6b565b60018060a01b031690816000526001602052611d78604060002082611cf26111f5565b91602b83527f54432f6275726e2d616d6f756e742d657863656564732d746f74616c2d73757060208401526a706c792d62616c616e636560a81b60408401527f0000000000000000000000000000000000000000000000000000000064ee40307f0000000000000000000000000000000000000000000000000000000000000e1061220e565b91929390856001600160701b0380931680611de5575b5050611d9b575050505050565b7feae651f8ba33ae01bde5a6272915d135baf7c791a99def90e70c81aeb809135893816020611dd8938551169401511693604051948594856117c4565b0390a23880808080611477565b60407faa5ae1dd90198687ea3c711472b6ec97b9962a1cfcfdbc4917ac9d19063823bc91815190600082526020820152a28538611d8e565b6001600160a01b031660008181526001602052604090209092839291611ecd908284611e476111f5565b92602b84527f54432f6275726e2d616d6f756e742d657863656564732d746f74616c2d73757060208501526a706c792d62616c616e636560a81b60408501527f0000000000000000000000000000000000000000000000000000000064ee40307f0000000000000000000000000000000000000000000000000000000000000e10612300565b9392959091946001600160701b039384821615801590611f47575b611efb575b505050611d9b575050505050565b604080516001600160701b0393841681529190921660208201527faa5ae1dd90198687ea3c711472b6ec97b9962a1cfcfdbc4917ac9d19063823bc91819081015b0390a2853880611eed565b508481161515611ee8565b6001600160a01b031660008181526001602052604090209092839291611fbd90829084907f0000000000000000000000000000000000000000000000000000000064ee40307f0000000000000000000000000000000000000000000000000000000000000e10612121565b9392959091946001600160701b03938482161580159061202f575b611fea57505050611d9b575050505050565b604080516001600160701b0393841681529190921660208201527ffb57251c875b0c08eb0c579e0007f5f325dc5d7db5ff497ff16ff602bcbf84a69181908101611f3c565b508481161515611fd8565b9190916001600160701b038080941691160191821161130257565b919361205f61117d565b600081526000602082015294600094612076611215565b5061208082611288565b936001600160701b039081831615159687612102575b5050808551168181116113025785526120b660208601928284511661203a565b81811690925284516040860151606087015160709490941b600160701b600160e01b0316919092161760e09190911b61ffff60e01b161760f09190911b6001600160f01b031916179055565b84985061211394939692995061274a565b959195939095963880612096565b92919490939461212f61117d565b600081526000602082015295600095612146611215565b5061215083611288565b946001600160701b03918284161515978861218a575b505061217682918288511661203a565b1685526120b660208601928284511661203a565b61219f929a508399509685916121769861274a565b9891989690989991612166565b919392906001600160701b03809116835260209416848301526060604083015280519081606084015260005b8281106121fa57505060809293506000838284010152601f8019910116010190565b8181018601518482016080015285016121d8565b9294909161221a61117d565b600081526000602082015295600095612231611215565b5061223b83611288565b946001600160701b039182602088015116838516918282106122e1575050151596876122c2575b5050845181168086526020860180518316939093039182169092526040850151606086015160709290921b600160701b600160e01b031690921760e09290921b61ffff60e01b169190911760f09190911b6001600160f01b031916179055565b8498506122d394939692995061274a565b959195939095963880612262565b604051635f46f05b60e11b81529182916104de918890600485016121ac565b9395919092949561230f61117d565b600081526000602082015296600096612326611215565b5061233084611288565b956001600160701b0392838851168484168110612406575083602089015116848616918282106123e7575050151597886123c8575b5050855182160381168086526020860180518316939093039182169092526040850151606086015160709290921b600160701b600160e01b031690921760e09290921b61ffff60e01b169190911760f09190911b6001600160f01b031916179055565b85929a50839950906123db93979161274a565b91989097919538612365565b604051635f46f05b60e11b81529182916104de918990600485016121ac565b6104de8492604051938493631a587c8d60e31b8552600485016121ac565b612580821015612435570190600090565b634e487b7160e01b600052603260045260246000fd5b91906000602061245961117d565b828152015261ffff9061258082606083015116106000146124815750506113b06000926112c1565b6113b0916040612495920151168094612424565b506112c1565b919060206040916124aa61117d565b6000928184809352015261ffff92839101511661258091828201918281116124fe5761257f019182116124ea575091612495916113b09306168094612424565b634e487b7160e01b81526011600452602490fd5b634e487b7160e01b82526011600452602482fd5b9190820180921161130257565b81156113ba570690565b9282826125369395612a63565b90939190156125485750505050600090565b6001600160a01b03936125619361ffff909116926126a4565b1690565b6001600160a01b03918216908216039190821161130257565b6001600160a01b03918216919082156113ba57160490565b9293919365ffffffffffff9182841683831696818811612686576125bc8682858a612a63565b509390928398818b14612663578684846125d593612a63565b5090809b896020830151160361264b575b5050866020850151160361262a575b5050945195516001600160a01b0396612561965061262393925061261d918816908816612565565b936112ea565b169061257e565b6125619750612623949361261d936126439389936128af565b9582936125f5565b61265b929b5090879185856128af565b9838806125e6565b506001600160a01b03995061256198505061ffff909316955090935091506126a4565b6044888360405191630e781b2360e31b835260048301526024820152fd5b92909263ffffffff8092169060018201809211611302576126ce9261258061249593061690612424565b602081019165ffffffffffff9182845116801590811561273a575b50156127035750505050602001516001600160701b031690565b5181516113b0955061262392918491602091839161272d916001600160a01b039182169116612565565b96511692015116906112ea565b90508360208401511611386126e9565b612793836020929694939661275d61117d565b6000948186809352015261276f611215565b50600163ffffffff42169785602061278561117d565b828152015201978891612902565b9591908287612825575b6127b5916001600160701b03602088015116906129a9565b906127de6127c161117d565b6001600160a01b0393841681526020810194855298899290612424565b949094612811575051835492516001600160d01b031990931691161760a09190911b65ffffffffffff60a01b1617905590565b634e487b7160e01b81526004819052602490fd5b5061ffff808316906001820180921161289b5780612580809306166040880152606087019185828451169180831060001461288d57505060010181811161287957916127b5939186935b169052915061279d565b634e487b7160e01b87526011600452602487fd5b6127b595939194925061286f565b634e487b7160e01b86526011600452602486fd5b916128dd6128e39382879461ffff65ffffffffffff98600060206128d161117d565b828152015216926126a4565b906129a9565b916128ec61117d565b6001600160a01b03909316835216602082015290565b9392909181612921916000602061291761117d565b828152015261249b565b919092829565ffffffffffff9384602082015116421461299c575061295b9061294d85421684836129f4565b928560208a015116916129f4565b9061ffff93846060850151161592831561298d575b5050506129805750509190600090565b6040015116929160019150565b81169116119050388080612970565b9650505050509190600090565b80516020909101516001600160a01b039391841691849165ffffffffffff916129d4918316906112ea565b169216838382021692818404149015171561130257019081116113025790565b919065ffffffffffff918282168382161115612a23578291612a15916112ea565b1691169081156113ba570490565b50505050600090565b91909165ffffffffffff8080941691160291821691820361130257565b91909165ffffffffffff8080941691160191821161130257565b93919093612a6f61117d565b90600094858352856020809401528583612a8761117d565b82815201526060840161ffff928382511615612d175750612aa8858961244b565b65ffffffffffff9591959283808484015116951694808610612cc85750600197888783511614612cb957612aeb908b85612ae061117d565b82815201528c61249b565b858582949394015116871015612ca957505186169160028314612c9a5750851695851694612b1761117d565b8a81528a84820152978a9b8b8285612b2d61117d565b83815283898201529a839c819450818110600014612c8a5750612b509250612512565b6000198101908111612c2d5792949392859291905b955b612b8a575b5050505050508301511614612b82575050929190565b945092919050565b90919293949d506124959c9b9a50612ba28e82612512565b831c612bbb85612bb2888461251f565b169e8f85612424565b9a88888d0151169a8b15612c62575050838101808211612c2d576124959b9c9d9e9f8a612bf588612bec8b8661251f565b169e8f88612424565b9c119182158b8b8f83612c52575b505050612c4a57869215612c41575050506000198101908111612c2d57835b929190959493612b67565b634e487b7160e01b8e52601160045260248efd5b93509150612c22565b505050612b6c565b0151168d111590508b8b8f612c03565b9a509a9b9c9d9e919050838101809111612c2d579084612c8387869461251f565b1691612c22565b9150509594939592919092612b65565b97505050505050509350929190565b9850509950505050505050929190565b50509550505050509350929190565b96509250509596975061258092919450511610600014612cf95750612ceb61117d565b918483528201529190600190565b6044925060405191636029932560e11b835260048301526024820152fd5b95969750505050905065ffffffffffff612d2f61117d565b928584521690820152919060019056fea2646970667358221220afb56b34cd42494a198582b00e709aa76432ef2648596f22f181398cd7fb350b64736f6c63430008130033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000000000000000000000000000000000000000000e100000000000000000000000000000000000000000000000000000000064ee4030
-----Decoded View---------------
Arg [0] : _periodLength (uint48): 3600
Arg [1] : _periodOffset (uint48): 1693335600
-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 0000000000000000000000000000000000000000000000000000000000000e10
Arg [1] : 0000000000000000000000000000000000000000000000000000000064ee4030
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$90.96
Net Worth in ETH
0.040392
Token Allocations
POOL
100.00%
Multichain Portfolio | 32 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|---|---|---|---|---|
| ARB | 100.00% | $0.047646 | 1,909.0255 | $90.96 |
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.