Contract
0x4918D46D6189f65a67FC1f33153417435Ef6a0C9
1
Contract Overview
Balance:
0 MATIC
My Name Tag:
Not Available
Txn Hash |
Method
|
Block
|
From
|
To
|
Value | [Txn Fee] | |||
---|---|---|---|---|---|---|---|---|---|
0x13d48a2d979a13b85848e84e29e9e520f3175dd2fccd481481db3c225c348aac | 0x60a06040 | 29391571 | 180 days 19 hrs ago | 0x3a791e828fdd420fbe16416efdf509e4b9088dd4 | IN | Create: TWABDelegator | 0 MATIC | 0.1021694059 |
[ Download CSV Export ]
Latest 1 internal transaction
Parent Txn Hash | Block | From | To | Value | |||
---|---|---|---|---|---|---|---|
0x13d48a2d979a13b85848e84e29e9e520f3175dd2fccd481481db3c225c348aac | 29391571 | 180 days 19 hrs ago | 0x4918d46d6189f65a67fc1f33153417435ef6a0c9 | Contract Creation | 0 MATIC |
[ Download CSV Export ]
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
TWABDelegator
Compiler Version
v0.8.6+commit.11564f7e
Optimization Enabled:
Yes with 2000 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-3.0 pragma solidity 0.8.6; import "@openzeppelin/contracts/proxy/Clones.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@pooltogether/v4-core/contracts/interfaces/ITicket.sol"; import "./Delegation.sol"; import "./LowLevelDelegator.sol"; import "./PermitAndMulticall.sol"; /** * @title Delegate chances to win to multiple accounts. * @notice This contract allows accounts to easily delegate a portion of their tickets to multiple delegatees. The delegatees chance of winning prizes is increased by the delegated amount. If a delegator doesn't want to actively manage the delegations, then they can stake on the contract and appoint representatives. */ contract TWABDelegator is ERC20, LowLevelDelegator, PermitAndMulticall { using Address for address; using Clones for address; using SafeERC20 for IERC20; /* ============ Events ============ */ /** * @notice Emitted when ticket associated with this contract has been set. * @param ticket Address of the ticket */ event TicketSet(ITicket indexed ticket); /** * @notice Emitted when tickets have been staked. * @param delegator Address of the delegator * @param amount Amount of tickets staked */ event TicketsStaked(address indexed delegator, uint256 amount); /** * @notice Emitted when tickets have been unstaked. * @param delegator Address of the delegator * @param recipient Address of the recipient that will receive the tickets * @param amount Amount of tickets unstaked */ event TicketsUnstaked(address indexed delegator, address indexed recipient, uint256 amount); /** * @notice Emitted when a new delegation is created. * @param delegator Delegator of the delegation * @param slot Slot of the delegation * @param lockUntil Timestamp until which the delegation is locked * @param delegatee Address of the delegatee * @param delegation Address of the delegation that was created * @param user Address of the user who created the delegation */ event DelegationCreated( address indexed delegator, uint256 indexed slot, uint96 lockUntil, address indexed delegatee, Delegation delegation, address user ); /** * @notice Emitted when a delegatee is updated. * @param delegator Address of the delegator * @param slot Slot of the delegation * @param delegatee Address of the delegatee * @param lockUntil Timestamp until which the delegation is locked * @param user Address of the user who updated the delegatee */ event DelegateeUpdated( address indexed delegator, uint256 indexed slot, address indexed delegatee, uint96 lockUntil, address user ); /** * @notice Emitted when a delegation is funded. * @param delegator Address of the delegator * @param slot Slot of the delegation * @param amount Amount of tickets that were sent to the delegation * @param user Address of the user who funded the delegation */ event DelegationFunded( address indexed delegator, uint256 indexed slot, uint256 amount, address indexed user ); /** * @notice Emitted when a delegation is funded from the staked amount. * @param delegator Address of the delegator * @param slot Slot of the delegation * @param amount Amount of tickets that were sent to the delegation * @param user Address of the user who pulled funds from the delegator stake to the delegation */ event DelegationFundedFromStake( address indexed delegator, uint256 indexed slot, uint256 amount, address indexed user ); /** * @notice Emitted when an amount of tickets has been withdrawn from a delegation. The tickets are held by this contract and the delegator stake is increased. * @param delegator Address of the delegator * @param slot Slot of the delegation * @param amount Amount of tickets withdrawn * @param user Address of the user who withdrew the tickets */ event WithdrewDelegationToStake( address indexed delegator, uint256 indexed slot, uint256 amount, address indexed user ); /** * @notice Emitted when a delegator withdraws an amount of tickets from a delegation to a specified wallet. * @param delegator Address of the delegator * @param slot Slot of the delegation * @param amount Amount of tickets withdrawn * @param to Recipient address of withdrawn tickets */ event TransferredDelegation( address indexed delegator, uint256 indexed slot, uint256 amount, address indexed to ); /** * @notice Emitted when a representative is set. * @param delegator Address of the delegator * @param representative Address of the representative * @param set Boolean indicating if the representative was set or unset */ event RepresentativeSet(address indexed delegator, address indexed representative, bool set); /* ============ Variables ============ */ /// @notice Prize pool ticket to which this contract is tied to. ITicket public immutable ticket; /// @notice Max lock time during which a delegation cannot be updated. uint256 public constant MAX_LOCK = 180 days; /** * @notice Representative elected by the delegator to handle delegation. * @dev Representative can only handle delegation and cannot withdraw tickets to their wallet. * @dev delegator => representative => bool allowing representative to represent the delegator */ mapping(address => mapping(address => bool)) internal representatives; /* ============ Constructor ============ */ /** * @notice Creates a new TWAB Delegator that is bound to the given ticket contract. * @param name_ The name for the staked ticket token * @param symbol_ The symbol for the staked ticket token * @param _ticket Address of the ticket contract */ constructor( string memory name_, string memory symbol_, ITicket _ticket ) LowLevelDelegator() ERC20(name_, symbol_) { require(address(_ticket) != address(0), "TWABDelegator/tick-not-zero-addr"); ticket = _ticket; emit TicketSet(_ticket); } /* ============ External Functions ============ */ /** * @notice Stake `_amount` of tickets in this contract. * @dev Tickets can be staked on behalf of a `_to` user. * @param _to Address to which the stake will be attributed * @param _amount Amount of tickets to stake */ function stake(address _to, uint256 _amount) external { _requireAmountGtZero(_amount); IERC20(ticket).safeTransferFrom(msg.sender, address(this), _amount); _mint(_to, _amount); emit TicketsStaked(_to, _amount); } /** * @notice Unstake `_amount` of tickets from this contract. Transfers ticket to the passed `_to` address. * @dev If delegator has delegated his whole stake, he will first have to withdraw from a delegation to be able to unstake. * @param _to Address of the recipient that will receive the tickets * @param _amount Amount of tickets to unstake */ function unstake(address _to, uint256 _amount) external { _requireRecipientNotZeroAddress(_to); _requireAmountGtZero(_amount); _burn(msg.sender, _amount); IERC20(ticket).safeTransfer(_to, _amount); emit TicketsUnstaked(msg.sender, _to, _amount); } /** * @notice Creates a new delegation. This will create a new Delegation contract for the given slot and have it delegate its tickets to the given delegatee. If a non-zero lock duration is passed, then the delegatee cannot be changed, nor funding withdrawn, until the lock has expired. * @dev The `_delegator` and `_slot` params are used to compute the salt of the delegation * @param _delegator Address of the delegator that will be able to handle the delegation * @param _slot Slot of the delegation * @param _delegatee Address of the delegatee * @param _lockDuration Duration of time for which the delegation is locked. Must be less than the max duration. * @return Returns the address of the Delegation contract that will hold the tickets */ function createDelegation( address _delegator, uint256 _slot, address _delegatee, uint96 _lockDuration ) external returns (Delegation) { _requireDelegatorOrRepresentative(_delegator); _requireDelegateeNotZeroAddress(_delegatee); _requireLockDuration(_lockDuration); uint96 _lockUntil = _computeLockUntil(_lockDuration); Delegation _delegation = _createDelegation( _computeSalt(_delegator, bytes32(_slot)), _lockUntil ); _setDelegateeCall(_delegation, _delegatee); emit DelegationCreated(_delegator, _slot, _lockUntil, _delegatee, _delegation, msg.sender); return _delegation; } /** * @notice Updates the delegatee and lock duration for a delegation slot. * @dev Only callable by the `_delegator` or their representative. * @dev Will revert if delegation is still locked. * @param _delegator Address of the delegator * @param _slot Slot of the delegation * @param _delegatee Address of the delegatee * @param _lockDuration Duration of time during which the delegatee cannot be changed nor withdrawn * @return The address of the Delegation */ function updateDelegatee( address _delegator, uint256 _slot, address _delegatee, uint96 _lockDuration ) external returns (Delegation) { _requireDelegatorOrRepresentative(_delegator); _requireDelegateeNotZeroAddress(_delegatee); _requireLockDuration(_lockDuration); Delegation _delegation = Delegation(_computeAddress(_delegator, _slot)); _requireDelegationUnlocked(_delegation); uint96 _lockUntil = _computeLockUntil(_lockDuration); if (_lockDuration > 0) { _delegation.setLockUntil(_lockUntil); } _setDelegateeCall(_delegation, _delegatee); emit DelegateeUpdated(_delegator, _slot, _delegatee, _lockUntil, msg.sender); return _delegation; } /** * @notice Fund a delegation by transferring tickets from the caller to the delegation. * @dev Callable by anyone. * @dev Will revert if delegation does not exist. * @param _delegator Address of the delegator * @param _slot Slot of the delegation * @param _amount Amount of tickets to transfer * @return The address of the Delegation */ function fundDelegation( address _delegator, uint256 _slot, uint256 _amount ) external returns (Delegation) { require(_delegator != address(0), "TWABDelegator/dlgtr-not-zero-adr"); _requireAmountGtZero(_amount); Delegation _delegation = Delegation(_computeAddress(_delegator, _slot)); IERC20(ticket).safeTransferFrom(msg.sender, address(_delegation), _amount); emit DelegationFunded(_delegator, _slot, _amount, msg.sender); return _delegation; } /** * @notice Fund a delegation using the `_delegator` stake. * @dev Callable only by the `_delegator` or a representative. * @dev Will revert if delegation does not exist. * @dev Will revert if `_amount` is greater than the staked amount. * @param _delegator Address of the delegator * @param _slot Slot of the delegation * @param _amount Amount of tickets to send to the delegation from the staked amount * @return The address of the Delegation */ function fundDelegationFromStake( address _delegator, uint256 _slot, uint256 _amount ) external returns (Delegation) { _requireDelegatorOrRepresentative(_delegator); _requireAmountGtZero(_amount); Delegation _delegation = Delegation(_computeAddress(_delegator, _slot)); _burn(_delegator, _amount); IERC20(ticket).safeTransfer(address(_delegation), _amount); emit DelegationFundedFromStake(_delegator, _slot, _amount, msg.sender); return _delegation; } /** * @notice Withdraw tickets from a delegation. The tickets will be held by this contract and the delegator's stake will increase. * @dev Only callable by the `_delegator` or a representative. * @dev Will send the tickets to this contract and increase the `_delegator` staked amount. * @dev Will revert if delegation is still locked. * @param _delegator Address of the delegator * @param _slot Slot of the delegation * @param _amount Amount of tickets to withdraw * @return The address of the Delegation */ function withdrawDelegationToStake( address _delegator, uint256 _slot, uint256 _amount ) external returns (Delegation) { _requireDelegatorOrRepresentative(_delegator); Delegation _delegation = Delegation(_computeAddress(_delegator, _slot)); _transfer(_delegation, address(this), _amount); _mint(_delegator, _amount); emit WithdrewDelegationToStake(_delegator, _slot, _amount, msg.sender); return _delegation; } /** * @notice Withdraw an `_amount` of tickets from a delegation. The delegator is assumed to be the caller. * @dev Tickets are sent directly to the passed `_to` address. * @dev Will revert if delegation is still locked. * @param _slot Slot of the delegation * @param _amount Amount to withdraw * @param _to Account to transfer the withdrawn tickets to * @return The address of the Delegation */ function transferDelegationTo( uint256 _slot, uint256 _amount, address _to ) external returns (Delegation) { _requireRecipientNotZeroAddress(_to); Delegation _delegation = Delegation(_computeAddress(msg.sender, _slot)); _transfer(_delegation, _to, _amount); emit TransferredDelegation(msg.sender, _slot, _amount, _to); return _delegation; } /** * @notice Allow an account to set or unset a `_representative` to handle delegation. * @dev If `_set` is `true`, `_representative` will be set as representative of `msg.sender`. * @dev If `_set` is `false`, `_representative` will be unset as representative of `msg.sender`. * @param _representative Address of the representative * @param _set Set or unset the representative */ function setRepresentative(address _representative, bool _set) external { require(_representative != address(0), "TWABDelegator/rep-not-zero-addr"); representatives[msg.sender][_representative] = _set; emit RepresentativeSet(msg.sender, _representative, _set); } /** * @notice Returns whether or not the given rep is a representative of the delegator. * @param _delegator The delegator * @param _representative The representative to check for * @return True if the rep is a rep, false otherwise */ function isRepresentativeOf(address _delegator, address _representative) external view returns (bool) { return representatives[_delegator][_representative]; } /** * @notice Allows a user to call multiple functions on the same contract. Useful for EOA who wants to batch transactions. * @param _data An array of encoded function calls. The calls must be abi-encoded calls to this contract. * @return The results from each function call */ function multicall(bytes[] calldata _data) external returns (bytes[] memory) { return _multicall(_data); } /** * @notice Alow a user to approve ticket and run various calls in one transaction. * @param _amount Amount of tickets to approve * @param _permitSignature Permit signature * @param _data Datas to call with `functionDelegateCall` */ function permitAndMulticall( uint256 _amount, Signature calldata _permitSignature, bytes[] calldata _data ) external { _permitAndMulticall(IERC20Permit(address(ticket)), _amount, _permitSignature, _data); } /** * @notice Allows the caller to easily get the details for a delegation. * @param _delegator The delegator address * @param _slot The delegation slot they are using * @return delegation The address that holds tickets for the delegation * @return delegatee The address that tickets are being delegated to * @return balance The balance of tickets in the delegation * @return lockUntil The timestamp at which the delegation unlocks * @return wasCreated Whether or not the delegation has been created */ function getDelegation(address _delegator, uint256 _slot) external view returns ( Delegation delegation, address delegatee, uint256 balance, uint256 lockUntil, bool wasCreated ) { delegation = Delegation(_computeAddress(_delegator, _slot)); wasCreated = address(delegation).isContract(); delegatee = ticket.delegateOf(address(delegation)); balance = ticket.balanceOf(address(delegation)); if (wasCreated) { lockUntil = delegation.lockUntil(); } } /** * @notice Computes the address of the delegation for the delegator + slot combination. * @param _delegator The user who is delegating tickets * @param _slot The delegation slot * @return The address of the delegation. This is the address that holds the balance of tickets. */ function computeDelegationAddress(address _delegator, uint256 _slot) external view returns (address) { return _computeAddress(_delegator, _slot); } /** * @notice Returns the ERC20 token decimals. * @dev This value is equal to the decimals of the ticket being delegated. * @return ERC20 token decimals */ function decimals() public view virtual override returns (uint8) { return ERC20(address(ticket)).decimals(); } /* ============ Internal Functions ============ */ /** * @notice Computes the address of a delegation contract using the delegator and slot as a salt. The contract is a clone, also known as minimal proxy contract. * @param _delegator Address of the delegator * @param _slot Slot of the delegation * @return Address at which the delegation contract will be deployed */ function _computeAddress(address _delegator, uint256 _slot) internal view returns (address) { return _computeAddress(_computeSalt(_delegator, bytes32(_slot))); } /** * @notice Computes the timestamp at which the delegation unlocks, after which the delegatee can be changed and tickets withdrawn. * @param _lockDuration The duration of the lock * @return The lock expiration timestamp */ function _computeLockUntil(uint96 _lockDuration) internal view returns (uint96) { unchecked { return uint96(block.timestamp) + _lockDuration; } } /** * @notice Delegates tickets from the `_delegation` contract to the `_delegatee` address. * @param _delegation Address of the delegation contract * @param _delegatee Address of the delegatee */ function _setDelegateeCall(Delegation _delegation, address _delegatee) internal { bytes4 _selector = ticket.delegate.selector; bytes memory _data = abi.encodeWithSelector(_selector, _delegatee); _executeCall(_delegation, _data); } /** * @notice Tranfers tickets from the Delegation contract to the `_to` address. * @param _delegation Address of the delegation contract * @param _to Address of the recipient * @param _amount Amount of tickets to transfer */ function _transferCall( Delegation _delegation, address _to, uint256 _amount ) internal { bytes4 _selector = ticket.transfer.selector; bytes memory _data = abi.encodeWithSelector(_selector, _to, _amount); _executeCall(_delegation, _data); } /** * @notice Execute a function call on the delegation contract. * @param _delegation Address of the delegation contract * @param _data The call data that will be executed * @return The return datas from the calls */ function _executeCall(Delegation _delegation, bytes memory _data) internal returns (bytes[] memory) { Delegation.Call[] memory _calls = new Delegation.Call[](1); _calls[0] = Delegation.Call({ to: address(ticket), data: _data }); return _delegation.executeCalls(_calls); } /** * @notice Transfers tickets from a delegation contract to `_to`. * @param _delegation Address of the delegation contract * @param _to Address of the recipient * @param _amount Amount of tickets to transfer */ function _transfer( Delegation _delegation, address _to, uint256 _amount ) internal { _requireAmountGtZero(_amount); _requireDelegationUnlocked(_delegation); _transferCall(_delegation, _to, _amount); } /* ============ Modifier/Require Functions ============ */ /** * @notice Require to only allow the delegator or representative to call a function. * @param _delegator Address of the delegator */ function _requireDelegatorOrRepresentative(address _delegator) internal view { require( _delegator == msg.sender || representatives[_delegator][msg.sender], "TWABDelegator/not-dlgtr-or-rep" ); } /** * @notice Require to verify that `_delegatee` is not address zero. * @param _delegatee Address of the delegatee */ function _requireDelegateeNotZeroAddress(address _delegatee) internal pure { require(_delegatee != address(0), "TWABDelegator/dlgt-not-zero-addr"); } /** * @notice Require to verify that `_amount` is greater than 0. * @param _amount Amount to check */ function _requireAmountGtZero(uint256 _amount) internal pure { require(_amount > 0, "TWABDelegator/amount-gt-zero"); } /** * @notice Require to verify that `_to` is not address zero. * @param _to Address to check */ function _requireRecipientNotZeroAddress(address _to) internal pure { require(_to != address(0), "TWABDelegator/to-not-zero-addr"); } /** * @notice Require to verify if a `_delegation` is locked. * @param _delegation Delegation to check */ function _requireDelegationUnlocked(Delegation _delegation) internal view { require(block.timestamp >= _delegation.lockUntil(), "TWABDelegator/delegation-locked"); } /** * @notice Require to verify that a `_lockDuration` does not exceed the maximum lock duration. * @param _lockDuration Lock duration to check */ function _requireLockDuration(uint256 _lockDuration) internal pure { require(_lockDuration <= MAX_LOCK, "TWABDelegator/lock-too-long"); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (proxy/Clones.sol) pragma solidity ^0.8.0; /** * @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for * deploying minimal proxy contracts, also known as "clones". * * > To simply and cheaply clone contract functionality in an immutable way, this standard specifies * > a minimal bytecode implementation that delegates all calls to a known, fixed address. * * The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2` * (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the * deterministic method. * * _Available since v3.4._ */ library Clones { /** * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`. * * This function uses the create opcode, which should never revert. */ function clone(address implementation) internal returns (address instance) { /// @solidity memory-safe-assembly assembly { let ptr := mload(0x40) mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) mstore(add(ptr, 0x14), shl(0x60, implementation)) mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000) instance := create(0, ptr, 0x37) } require(instance != address(0), "ERC1167: create failed"); } /** * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`. * * This function uses the create2 opcode and a `salt` to deterministically deploy * the clone. Using the same `implementation` and `salt` multiple time will revert, since * the clones cannot be deployed twice at the same address. */ function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) { /// @solidity memory-safe-assembly assembly { let ptr := mload(0x40) mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) mstore(add(ptr, 0x14), shl(0x60, implementation)) mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000) instance := create2(0, ptr, 0x37, salt) } require(instance != address(0), "ERC1167: create2 failed"); } /** * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}. */ function predictDeterministicAddress( address implementation, bytes32 salt, address deployer ) internal pure returns (address predicted) { /// @solidity memory-safe-assembly assembly { let ptr := mload(0x40) mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) mstore(add(ptr, 0x14), shl(0x60, implementation)) mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf3ff00000000000000000000000000000000) mstore(add(ptr, 0x38), shl(0x60, deployer)) mstore(add(ptr, 0x4c), salt) mstore(add(ptr, 0x6c), keccak256(ptr, 0x37)) predicted := keccak256(add(ptr, 0x37), 0x55) } } /** * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}. */ function predictDeterministicAddress(address implementation, bytes32 salt) internal view returns (address predicted) { return predictDeterministicAddress(implementation, salt, address(this)); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.0; import "./IERC20.sol"; import "./extensions/IERC20Metadata.sol"; import "../../utils/Context.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `to` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _transfer(owner, to, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on * `transferFrom`. This is semantically equivalent to an infinite approval. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _approve(owner, spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * NOTE: Does not update the allowance if the current allowance * is the maximum `uint256`. * * Requirements: * * - `from` and `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. * - the caller must have allowance for ``from``'s tokens of at least * `amount`. */ function transferFrom( address from, address to, uint256 amount ) public virtual override returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, amount); _transfer(from, to, amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, allowance(owner, spender) + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { address owner = _msgSender(); uint256 currentAllowance = allowance(owner, spender); require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(owner, spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `from` to `to`. * * This internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. */ function _transfer( address from, address to, uint256 amount ) internal virtual { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(from, to, amount); uint256 fromBalance = _balances[from]; require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[from] = fromBalance - amount; } _balances[to] += amount; emit Transfer(from, to, amount); _afterTokenTransfer(from, to, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); _afterTokenTransfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; } _totalSupply -= amount; emit Transfer(account, address(0), amount); _afterTokenTransfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Updates `owner` s allowance for `spender` based on spent `amount`. * * Does not update the allowance amount in case of infinite allowance. * Revert if not enough allowance is available. * * Might emit an {Approval} event. */ function _spendAllowance( address owner, address spender, uint256 amount ) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { require(currentAllowance >= amount, "ERC20: insufficient allowance"); unchecked { _approve(owner, spender, currentAllowance - amount); } } } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * has been transferred to `to`. * - when `from` is zero, `amount` tokens have been minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens have been burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../extensions/draft-IERC20Permit.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } function safePermit( IERC20Permit token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity 0.8.6; import "../libraries/TwabLib.sol"; import "./IControlledToken.sol"; interface ITicket is IControlledToken { /** * @notice A struct containing details for an Account. * @param balance The current balance for an Account. * @param nextTwabIndex The next available index to store a new twab. * @param cardinality The number of recorded twabs (plus one!). */ struct AccountDetails { uint224 balance; uint16 nextTwabIndex; uint16 cardinality; } /** * @notice Combines account details with their twab history. * @param details The account details. * @param twabs The history of twabs for this account. */ struct Account { AccountDetails details; ObservationLib.Observation[65535] twabs; } /** * @notice Emitted when TWAB balance has been delegated to another user. * @param delegator Address of the delegator. * @param delegate Address of the delegate. */ event Delegated(address indexed delegator, address indexed delegate); /** * @notice Emitted when ticket is initialized. * @param name Ticket name (eg: PoolTogether Dai Ticket (Compound)). * @param symbol Ticket symbol (eg: PcDAI). * @param decimals Ticket decimals. * @param controller Token controller address. */ event TicketInitialized(string name, string symbol, uint8 decimals, address indexed controller); /** * @notice Emitted when a new TWAB has been recorded. * @param delegate The recipient of the ticket power (may be the same as the user). * @param newTwab Updated TWAB of a ticket holder after a successful TWAB recording. */ event NewUserTwab( address indexed delegate, ObservationLib.Observation newTwab ); /** * @notice Emitted when a new total supply TWAB has been recorded. * @param newTotalSupplyTwab Updated TWAB of tickets total supply after a successful total supply TWAB recording. */ event NewTotalSupplyTwab(ObservationLib.Observation newTotalSupplyTwab); /** * @notice Retrieves the address of the delegate to whom `user` has delegated their tickets. * @dev Address of the delegate will be the zero address if `user` has not delegated their tickets. * @param user Address of the delegator. * @return Address of the delegate. */ function delegateOf(address user) external view returns (address); /** * @notice Delegate time-weighted average balances to an alternative address. * @dev Transfers (including mints) trigger the storage of a TWAB in delegate(s) account, instead of the targetted sender and/or recipient address(s). * @dev To reset the delegate, pass the zero address (0x000.000) as `to` parameter. * @dev Current delegate address should be different from the new delegate address `to`. * @param to Recipient of delegated TWAB. */ function delegate(address to) external; /** * @notice Allows the controller to delegate on a users behalf. * @param user The user for whom to delegate * @param delegate The new delegate */ function controllerDelegateFor(address user, address delegate) external; /** * @notice Allows a user to delegate via signature * @param user The user who is delegating * @param delegate The new delegate * @param deadline The timestamp by which this must be submitted * @param v The v portion of the ECDSA sig * @param r The r portion of the ECDSA sig * @param s The s portion of the ECDSA sig */ function delegateWithSignature( address user, address delegate, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @notice Gets a users twab context. This is a struct with their balance, next twab index, and cardinality. * @param user The user for whom to fetch the TWAB context. * @return The TWAB context, which includes { balance, nextTwabIndex, cardinality } */ function getAccountDetails(address user) external view returns (TwabLib.AccountDetails memory); /** * @notice Gets the TWAB at a specific index for a user. * @param user The user for whom to fetch the TWAB. * @param index The index of the TWAB to fetch. * @return The TWAB, which includes the twab amount and the timestamp. */ function getTwab(address user, uint16 index) external view returns (ObservationLib.Observation memory); /** * @notice Retrieves `user` TWAB balance. * @param user Address of the user whose TWAB is being fetched. * @param timestamp Timestamp at which we want to retrieve the TWAB balance. * @return The TWAB balance at the given timestamp. */ function getBalanceAt(address user, uint64 timestamp) external view returns (uint256); /** * @notice Retrieves `user` TWAB balances. * @param user Address of the user whose TWABs are being fetched. * @param timestamps Timestamps range at which we want to retrieve the TWAB balances. * @return `user` TWAB balances. */ function getBalancesAt(address user, uint64[] calldata timestamps) external view returns (uint256[] memory); /** * @notice Retrieves the average balance held by a user for a given time frame. * @param user The user whose balance is checked. * @param startTime The start time of the time frame. * @param endTime The end time of the time frame. * @return The average balance that the user held during the time frame. */ function getAverageBalanceBetween( address user, uint64 startTime, uint64 endTime ) external view returns (uint256); /** * @notice Retrieves the average balances held by a user for a given time frame. * @param user The user whose balance is checked. * @param startTimes The start time of the time frame. * @param endTimes The end time of the time frame. * @return The average balance that the user held during the time frame. */ function getAverageBalancesBetween( address user, uint64[] calldata startTimes, uint64[] calldata endTimes ) external view returns (uint256[] memory); /** * @notice Retrieves the total supply TWAB balance at the given timestamp. * @param timestamp Timestamp at which we want to retrieve the total supply TWAB balance. * @return The total supply TWAB balance at the given timestamp. */ function getTotalSupplyAt(uint64 timestamp) external view returns (uint256); /** * @notice Retrieves the total supply TWAB balance between the given timestamps range. * @param timestamps Timestamps range at which we want to retrieve the total supply TWAB balance. * @return Total supply TWAB balances. */ function getTotalSuppliesAt(uint64[] calldata timestamps) external view returns (uint256[] memory); /** * @notice Retrieves the average total supply balance for a set of given time frames. * @param startTimes Array of start times. * @param endTimes Array of end times. * @return The average total supplies held during the time frame. */ function getAverageTotalSuppliesBetween( uint64[] calldata startTimes, uint64[] calldata endTimes ) external view returns (uint256[] memory); }
// SPDX-License-Identifier: GPL-3.0 pragma solidity 0.8.6; /** * @title Contract instantiated via CREATE2 to handle a Delegation by a delegator to a delegatee. * @notice A Delegation allows his owner to execute calls on behalf of the contract. * @dev This contract is intended to be counterfactually instantiated via CREATE2 through the LowLevelDelegator contract. * @dev This contract will hold tickets that will be delegated to a chosen delegatee. */ contract Delegation { /** * @notice A structure to define arbitrary contract calls. * @param to The address to call * @param data The call data */ struct Call { address to; bytes data; } /// @notice Contract owner. address private _owner; /// @notice Timestamp until which the delegation is locked. uint96 public lockUntil; /** * @notice Initializes the delegation. * @param _lockUntil Timestamp until which the delegation is locked */ function initialize(uint96 _lockUntil) external { require(_owner == address(0), "Delegation/already-init"); _owner = msg.sender; lockUntil = _lockUntil; } /** * @notice Executes calls on behalf of this contract. * @param calls The array of calls to be executed * @return An array of the return values for each of the calls */ function executeCalls(Call[] calldata calls) external onlyOwner returns (bytes[] memory) { uint256 _callsLength = calls.length; bytes[] memory response = new bytes[](_callsLength); Call memory call; for (uint256 i; i < _callsLength; i++) { call = calls[i]; response[i] = _executeCall(call.to, call.data); } return response; } /** * @notice Set the timestamp until which the delegation is locked. * @param _lockUntil The timestamp until which the delegation is locked */ function setLockUntil(uint96 _lockUntil) external onlyOwner { lockUntil = _lockUntil; } /** * @notice Executes a call to another contract. * @param to The address to call * @param data The call data * @return The return data from the call */ function _executeCall(address to, bytes memory data) internal returns (bytes memory) { (bool succeeded, bytes memory returnValue) = to.call{ value: 0 }(data); require(succeeded, string(returnValue)); return returnValue; } /// @notice Modifier to only allow the contract owner to call a function modifier onlyOwner() { require(msg.sender == _owner, "Delegation/only-owner"); _; } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity 0.8.6; import "@openzeppelin/contracts/proxy/Clones.sol"; import "./Delegation.sol"; /// @title The LowLevelDelegator allows users to create delegations very cheaply. contract LowLevelDelegator { using Clones for address; /// @notice The instance to which all proxies will point. Delegation public delegationInstance; /// @notice Contract constructor. constructor() { delegationInstance = new Delegation(); delegationInstance.initialize(uint96(0)); } /** * @notice Creates a clone of the delegation. * @param _salt Random number used to deterministically deploy the clone * @param _lockUntil Timestamp until which the delegation is locked * @return The newly created delegation */ function _createDelegation(bytes32 _salt, uint96 _lockUntil) internal returns (Delegation) { Delegation _delegation = Delegation(address(delegationInstance).cloneDeterministic(_salt)); _delegation.initialize(_lockUntil); return _delegation; } /** * @notice Computes the address of a clone, also known as minimal proxy contract. * @param _salt Random number used to compute the address * @return Address at which the clone will be deployed */ function _computeAddress(bytes32 _salt) internal view returns (address) { return address(delegationInstance).predictDeterministicAddress(_salt, address(this)); } /** * @notice Computes salt used to deterministically deploy a clone. * @param _delegator Address of the delegator * @param _slot Slot of the delegation * @return Salt used to deterministically deploy a clone. */ function _computeSalt(address _delegator, bytes32 _slot) internal pure returns (bytes32) { return keccak256(abi.encodePacked(_delegator, _slot)); } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity 0.8.6; import "@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol"; import "@openzeppelin/contracts/utils/Address.sol"; /** * @notice Allows a user to permit token spend and then call multiple functions on a contract. */ contract PermitAndMulticall { /** * @notice Secp256k1 signature values. * @param deadline Timestamp at which the signature expires * @param v `v` portion of the signature * @param r `r` portion of the signature * @param s `s` portion of the signature */ struct Signature { uint256 deadline; uint8 v; bytes32 r; bytes32 s; } /** * @notice Allows a user to call multiple functions on the same contract. Useful for EOA who want to batch transactions. * @param _data An array of encoded function calls. The calls must be abi-encoded calls to this contract. * @return The results from each function call */ function _multicall(bytes[] calldata _data) internal virtual returns (bytes[] memory) { uint256 _dataLength = _data.length; bytes[] memory results = new bytes[](_dataLength); for (uint256 i; i < _dataLength; i++) { results[i] = Address.functionDelegateCall(address(this), _data[i]); } return results; } /** * @notice Allow a user to approve an ERC20 token and run various calls in one transaction. * @param _permitToken Address of the ERC20 token * @param _amount Amount of tickets to approve * @param _permitSignature Permit signature * @param _data Datas to call with `functionDelegateCall` */ function _permitAndMulticall( IERC20Permit _permitToken, uint256 _amount, Signature calldata _permitSignature, bytes[] calldata _data ) internal { _permitToken.permit( msg.sender, address(this), _amount, _permitSignature.deadline, _permitSignature.v, _permitSignature.r, _permitSignature.s ); _multicall(_data); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity 0.8.6; import "./ExtendedSafeCastLib.sol"; import "./OverflowSafeComparatorLib.sol"; import "./RingBufferLib.sol"; import "./ObservationLib.sol"; /** * @title PoolTogether V4 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. The TwabLib (using existing blocktimes of 1block/15sec) guarantees minimum 7.4 years of search history. */ library TwabLib { using OverflowSafeComparatorLib for uint32; using ExtendedSafeCastLib for uint256; /** * @notice Sets max ring buffer length in the Account.twabs Observation list. As users transfer/mint/burn tickets new Observation checkpoints are recorded. The current max cardinality guarantees a seven year minimum, of accurate historical lookups with current estimates of 1 new block every 15 seconds - assuming each block contains a transfer to trigger an observation write to storage. * @dev The user Account.AccountDetails.cardinality parameter can NOT exceed the max cardinality variable. Preventing "corrupted" ring buffer lookup pointers and new observation checkpoints. The MAX_CARDINALITY in fact guarantees at least 7.4 years of records: If 14 = block time in seconds (2**24) * 14 = 234881024 seconds of history 234881024 / (365 * 24 * 60 * 60) ~= 7.44 years */ uint24 public constant MAX_CARDINALITY = 16777215; // 2**24 /** @notice Struct ring buffer parameters for single user Account * @param balance Current balance for an Account * @param nextTwabIndex Next uninitialized or updatable ring buffer checkpoint storage slot * @param cardinality Current total "initialized" ring buffer checkpoints for single user AccountDetails. Used to set initial boundary conditions for an efficient binary search. */ struct AccountDetails { uint208 balance; uint24 nextTwabIndex; uint24 cardinality; } /// @notice Combines account details with their twab history /// @param details The account details /// @param twabs The history of twabs for this account struct Account { AccountDetails details; ObservationLib.Observation[MAX_CARDINALITY] twabs; } /// @notice Increases an account's balance and records a new twab. /// @param _account The account whose balance will be increased /// @param _amount The amount to increase the balance by /// @param _currentTime The current time /// @return accountDetails The new AccountDetails /// @return twab The user's latest TWAB /// @return isNew Whether the TWAB is new function increaseBalance( Account storage _account, uint208 _amount, uint32 _currentTime ) internal returns ( AccountDetails memory accountDetails, ObservationLib.Observation memory twab, bool isNew ) { AccountDetails memory _accountDetails = _account.details; (accountDetails, twab, isNew) = _nextTwab(_account.twabs, _accountDetails, _currentTime); accountDetails.balance = _accountDetails.balance + _amount; } /** @notice Calculates the next TWAB checkpoint for an account with a decreasing balance. * @dev With Account struct and amount decreasing calculates the next TWAB observable checkpoint. * @param _account Account whose balance will be decreased * @param _amount Amount to decrease the balance by * @param _revertMessage Revert message for insufficient balance * @return accountDetails Updated Account.details struct * @return twab TWAB observation (with decreasing average) * @return isNew Whether TWAB is new or calling twice in the same block */ function decreaseBalance( Account storage _account, uint208 _amount, string memory _revertMessage, uint32 _currentTime ) internal returns ( AccountDetails memory accountDetails, ObservationLib.Observation memory twab, bool isNew ) { AccountDetails memory _accountDetails = _account.details; require(_accountDetails.balance >= _amount, _revertMessage); (accountDetails, twab, isNew) = _nextTwab(_account.twabs, _accountDetails, _currentTime); unchecked { accountDetails.balance -= _amount; } } /** @notice Calculates the average balance held by a user for a given time frame. * @dev Finds the average balance between start and end timestamp epochs. Validates the supplied end time is within the range of elapsed time i.e. less then timestamp of now. * @param _twabs Individual user Observation recorded checkpoints passed as storage pointer * @param _accountDetails User AccountDetails struct loaded in memory * @param _startTime Start of timestamp range as an epoch * @param _endTime End of timestamp range as an epoch * @param _currentTime Block.timestamp * @return Average balance of user held between epoch timestamps start and end */ function getAverageBalanceBetween( ObservationLib.Observation[MAX_CARDINALITY] storage _twabs, AccountDetails memory _accountDetails, uint32 _startTime, uint32 _endTime, uint32 _currentTime ) internal view returns (uint256) { uint32 endTime = _endTime > _currentTime ? _currentTime : _endTime; return _getAverageBalanceBetween(_twabs, _accountDetails, _startTime, endTime, _currentTime); } /// @notice Retrieves the oldest TWAB /// @param _twabs The storage array of twabs /// @param _accountDetails The TWAB account details /// @return index The index of the oldest TWAB in the twabs array /// @return twab The oldest TWAB function oldestTwab( ObservationLib.Observation[MAX_CARDINALITY] storage _twabs, AccountDetails memory _accountDetails ) internal view returns (uint24 index, ObservationLib.Observation memory twab) { index = _accountDetails.nextTwabIndex; twab = _twabs[index]; // If the TWAB is not initialized we go to the beginning of the TWAB circular buffer at index 0 if (twab.timestamp == 0) { index = 0; twab = _twabs[0]; } } /// @notice Retrieves the newest TWAB /// @param _twabs The storage array of twabs /// @param _accountDetails The TWAB account details /// @return index The index of the newest TWAB in the twabs array /// @return twab The newest TWAB function newestTwab( ObservationLib.Observation[MAX_CARDINALITY] storage _twabs, AccountDetails memory _accountDetails ) internal view returns (uint24 index, ObservationLib.Observation memory twab) { index = uint24(RingBufferLib.newestIndex(_accountDetails.nextTwabIndex, MAX_CARDINALITY)); twab = _twabs[index]; } /// @notice Retrieves amount at `_targetTime` timestamp /// @param _twabs List of TWABs to search through. /// @param _accountDetails Accounts details /// @param _targetTime Timestamp at which the reserved TWAB should be for. /// @return uint256 TWAB amount at `_targetTime`. function getBalanceAt( ObservationLib.Observation[MAX_CARDINALITY] storage _twabs, AccountDetails memory _accountDetails, uint32 _targetTime, uint32 _currentTime ) internal view returns (uint256) { uint32 timeToTarget = _targetTime > _currentTime ? _currentTime : _targetTime; return _getBalanceAt(_twabs, _accountDetails, timeToTarget, _currentTime); } /// @notice Calculates the average balance held by a user for a given time frame. /// @param _startTime The start time of the time frame. /// @param _endTime The end time of the time frame. /// @return The average balance that the user held during the time frame. function _getAverageBalanceBetween( ObservationLib.Observation[MAX_CARDINALITY] storage _twabs, AccountDetails memory _accountDetails, uint32 _startTime, uint32 _endTime, uint32 _currentTime ) private view returns (uint256) { (uint24 oldestTwabIndex, ObservationLib.Observation memory oldTwab) = oldestTwab( _twabs, _accountDetails ); (uint24 newestTwabIndex, ObservationLib.Observation memory newTwab) = newestTwab( _twabs, _accountDetails ); ObservationLib.Observation memory startTwab = _calculateTwab( _twabs, _accountDetails, newTwab, oldTwab, newestTwabIndex, oldestTwabIndex, _startTime, _currentTime ); ObservationLib.Observation memory endTwab = _calculateTwab( _twabs, _accountDetails, newTwab, oldTwab, newestTwabIndex, oldestTwabIndex, _endTime, _currentTime ); // Difference in amount / time return (endTwab.amount - startTwab.amount) / OverflowSafeComparatorLib.checkedSub(endTwab.timestamp, startTwab.timestamp, _currentTime); } /** @notice Searches TWAB history and calculate the difference between amount(s)/timestamp(s) to return average balance between the Observations closes to the supplied targetTime. * @param _twabs Individual user Observation recorded checkpoints passed as storage pointer * @param _accountDetails User AccountDetails struct loaded in memory * @param _targetTime Target timestamp to filter Observations in the ring buffer binary search * @param _currentTime Block.timestamp * @return uint256 Time-weighted average amount between two closest observations. */ function _getBalanceAt( ObservationLib.Observation[MAX_CARDINALITY] storage _twabs, AccountDetails memory _accountDetails, uint32 _targetTime, uint32 _currentTime ) private view returns (uint256) { uint24 newestTwabIndex; ObservationLib.Observation memory afterOrAt; ObservationLib.Observation memory beforeOrAt; (newestTwabIndex, beforeOrAt) = newestTwab(_twabs, _accountDetails); // If `_targetTime` is chronologically after the newest TWAB, we can simply return the current balance if (beforeOrAt.timestamp.lte(_targetTime, _currentTime)) { return _accountDetails.balance; } uint24 oldestTwabIndex; // Now, set before to the oldest TWAB (oldestTwabIndex, beforeOrAt) = oldestTwab(_twabs, _accountDetails); // If `_targetTime` is chronologically before the oldest TWAB, we can early return if (_targetTime.lt(beforeOrAt.timestamp, _currentTime)) { return 0; } // Otherwise, we perform the `binarySearch` (beforeOrAt, afterOrAt) = ObservationLib.binarySearch( _twabs, newestTwabIndex, oldestTwabIndex, _targetTime, _accountDetails.cardinality, _currentTime ); // Sum the difference in amounts and divide by the difference in timestamps. // The time-weighted average balance uses time measured between two epoch timestamps as // a constaint on the measurement when calculating the time weighted average balance. return (afterOrAt.amount - beforeOrAt.amount) / OverflowSafeComparatorLib.checkedSub(afterOrAt.timestamp, beforeOrAt.timestamp, _currentTime); } /** @notice Calculates a user TWAB for a target timestamp using the historical TWAB records. The balance is linearly interpolated: amount differences / timestamp differences using the simple (after.amount - before.amount / end.timestamp - start.timestamp) formula. /** @dev Binary search in _calculateTwab fails when searching out of bounds. Thus, before searching we exclude target timestamps out of range of newest/oldest TWAB(s). IF a search is before or after the range we "extrapolate" a Observation from the expected state. * @param _twabs Individual user Observation recorded checkpoints passed as storage pointer * @param _accountDetails User AccountDetails struct loaded in memory * @param _newestTwab Newest TWAB in history (end of ring buffer) * @param _oldestTwab Olderst TWAB in history (end of ring buffer) * @param _newestTwabIndex Pointer in ring buffer to newest TWAB * @param _oldestTwabIndex Pointer in ring buffer to oldest TWAB * @param _targetTimestamp Epoch timestamp to calculate for time (T) in the TWAB * @param _time Block.timestamp * @return accountDetails Updated Account.details struct */ function _calculateTwab( ObservationLib.Observation[MAX_CARDINALITY] storage _twabs, AccountDetails memory _accountDetails, ObservationLib.Observation memory _newestTwab, ObservationLib.Observation memory _oldestTwab, uint24 _newestTwabIndex, uint24 _oldestTwabIndex, uint32 _targetTimestamp, uint32 _time ) private view returns (ObservationLib.Observation memory) { // If `_targetTimestamp` is chronologically after the newest TWAB, we extrapolate a new one if (_newestTwab.timestamp.lt(_targetTimestamp, _time)) { return _computeNextTwab(_newestTwab, _accountDetails.balance, _targetTimestamp); } if (_newestTwab.timestamp == _targetTimestamp) { return _newestTwab; } if (_oldestTwab.timestamp == _targetTimestamp) { return _oldestTwab; } // If `_targetTimestamp` is chronologically before the oldest TWAB, we create a zero twab if (_targetTimestamp.lt(_oldestTwab.timestamp, _time)) { return ObservationLib.Observation({ amount: 0, timestamp: _targetTimestamp }); } // Otherwise, both timestamps must be surrounded by twabs. ( ObservationLib.Observation memory beforeOrAtStart, ObservationLib.Observation memory afterOrAtStart ) = ObservationLib.binarySearch( _twabs, _newestTwabIndex, _oldestTwabIndex, _targetTimestamp, _accountDetails.cardinality, _time ); uint224 heldBalance = (afterOrAtStart.amount - beforeOrAtStart.amount) / OverflowSafeComparatorLib.checkedSub(afterOrAtStart.timestamp, beforeOrAtStart.timestamp, _time); return _computeNextTwab(beforeOrAtStart, heldBalance, _targetTimestamp); } /** * @notice Calculates the next TWAB using the newestTwab and updated balance. * @dev Storage of the TWAB obersation is managed by the calling function and not _computeNextTwab. * @param _currentTwab Newest Observation in the Account.twabs list * @param _currentBalance User balance at time of most recent (newest) checkpoint write * @param _time Current block.timestamp * @return TWAB Observation */ function _computeNextTwab( ObservationLib.Observation memory _currentTwab, uint224 _currentBalance, uint32 _time ) private pure returns (ObservationLib.Observation memory) { // New twab amount = last twab amount (or zero) + (current amount * elapsed seconds) return ObservationLib.Observation({ amount: _currentTwab.amount + _currentBalance * (_time.checkedSub(_currentTwab.timestamp, _time)), timestamp: _time }); } /// @notice Sets a new TWAB Observation at the next available index and returns the new account details. /// @dev Note that if _currentTime is before the last observation timestamp, it appears as an overflow /// @param _twabs The twabs array to insert into /// @param _accountDetails The current account details /// @param _currentTime The current time /// @return accountDetails The new account details /// @return twab The newest twab (may or may not be brand-new) /// @return isNew Whether the newest twab was created by this call function _nextTwab( ObservationLib.Observation[MAX_CARDINALITY] storage _twabs, AccountDetails memory _accountDetails, uint32 _currentTime ) private returns ( AccountDetails memory accountDetails, ObservationLib.Observation memory twab, bool isNew ) { (, ObservationLib.Observation memory _newestTwab) = newestTwab(_twabs, _accountDetails); // if we're in the same block, return if (_newestTwab.timestamp == _currentTime) { return (_accountDetails, _newestTwab, false); } ObservationLib.Observation memory newTwab = _computeNextTwab( _newestTwab, _accountDetails.balance, _currentTime ); _twabs[_accountDetails.nextTwabIndex] = newTwab; AccountDetails memory nextAccountDetails = push(_accountDetails); return (nextAccountDetails, newTwab, true); } /// @notice "Pushes" a new element on the AccountDetails ring buffer, and returns the new AccountDetails /// @param _accountDetails The account details from which to pull the cardinality and next index /// @return The new AccountDetails function push(AccountDetails memory _accountDetails) internal pure returns (AccountDetails memory) { _accountDetails.nextTwabIndex = uint24( RingBufferLib.nextIndex(_accountDetails.nextTwabIndex, 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 // AccountDetails.cardinality will continue to be equal to max cardinality. if (_accountDetails.cardinality < MAX_CARDINALITY) { _accountDetails.cardinality += 1; } return _accountDetails; } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity 0.8.6; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; /** @title IControlledToken * @author PoolTogether Inc Team * @notice ERC20 Tokens with a controller for minting & burning. */ interface IControlledToken is IERC20 { /** @notice Interface to the contract responsible for controlling mint/burn */ function controller() external view returns (address); /** * @notice Allows the controller to mint tokens for a user account * @dev May be overridden to provide more granular control over minting * @param user Address of the receiver of the minted tokens * @param amount Amount of tokens to mint */ function controllerMint(address user, uint256 amount) external; /** * @notice Allows the controller to burn tokens from a user account * @dev May be overridden to provide more granular control over burning * @param user Address of the holder account to burn tokens from * @param amount Amount of tokens to burn */ function controllerBurn(address user, uint256 amount) external; /** * @notice Allows an operator via the controller to burn tokens on behalf of a user account * @dev May be overridden to provide more granular control over operator-burning * @param operator Address of the operator performing the burn action via the controller contract * @param user Address of the holder account to burn tokens from * @param amount Amount of tokens to burn */ function controllerBurnFrom( address operator, address user, uint256 amount ) external; }
// SPDX-License-Identifier: GPL-3.0 pragma solidity 0.8.6; /** * @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 ExtendedSafeCastLib { /** * @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 */ 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 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 */ 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 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 */ 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 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 224 bits */ function toUint192(uint256 value) internal pure returns (uint192) { require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits"); return uint192(value); } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity 0.8.6; /// @title OverflowSafeComparatorLib library to share comparator functions between contracts /// @dev Code taken from Uniswap V3 Oracle.sol: https://github.com/Uniswap/v3-core/blob/3e88af408132fc957e3e406f65a0ce2b1ca06c3d/contracts/libraries/Oracle.sol /// @author PoolTogether Inc. library OverflowSafeComparatorLib { /// @notice 32-bit timestamps comparator. /// @dev safe for 0 or 1 overflows, `_a` and `_b` must be chronologically before or equal to time. /// @param _a A comparison timestamp from which to determine the relative position of `_timestamp`. /// @param _b Timestamp to compare against `_a`. /// @param _timestamp A timestamp truncated to 32 bits. /// @return bool Whether `_a` is chronologically < `_b`. function lt( uint32 _a, uint32 _b, uint32 _timestamp ) internal pure returns (bool) { // No need to adjust if there hasn't been an overflow if (_a <= _timestamp && _b <= _timestamp) return _a < _b; uint256 aAdjusted = _a > _timestamp ? _a : _a + 2**32; uint256 bAdjusted = _b > _timestamp ? _b : _b + 2**32; return aAdjusted < bAdjusted; } /// @notice 32-bit timestamps comparator. /// @dev safe for 0 or 1 overflows, `_a` and `_b` must be chronologically before or equal to time. /// @param _a A comparison timestamp from which to determine the relative position of `_timestamp`. /// @param _b Timestamp to compare against `_a`. /// @param _timestamp A timestamp truncated to 32 bits. /// @return bool Whether `_a` is chronologically <= `_b`. function lte( uint32 _a, uint32 _b, uint32 _timestamp ) internal pure returns (bool) { // No need to adjust if there hasn't been an overflow if (_a <= _timestamp && _b <= _timestamp) return _a <= _b; uint256 aAdjusted = _a > _timestamp ? _a : _a + 2**32; uint256 bAdjusted = _b > _timestamp ? _b : _b + 2**32; return aAdjusted <= bAdjusted; } /// @notice 32-bit timestamp subtractor /// @dev safe for 0 or 1 overflows, where `_a` and `_b` must be chronologically before or equal to time /// @param _a The subtraction left operand /// @param _b The subtraction right operand /// @param _timestamp The current time. Expected to be chronologically after both. /// @return The difference between a and b, adjusted for overflow function checkedSub( uint32 _a, uint32 _b, uint32 _timestamp ) internal pure returns (uint32) { // No need to adjust if there hasn't been an overflow if (_a <= _timestamp && _b <= _timestamp) return _a - _b; uint256 aAdjusted = _a > _timestamp ? _a : _a + 2**32; uint256 bAdjusted = _b > _timestamp ? _b : _b + 2**32; return uint32(aAdjusted - bAdjusted); } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity 0.8.6; 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 _cardinality The number of elements in the ring buffer * @return Offsetted index. */ function offset( uint256 _index, uint256 _amount, uint256 _cardinality ) internal pure returns (uint256) { return wrap(_index + _cardinality - _amount, _cardinality); } /// @notice Returns the index of the last recorded TWAB /// @param _nextIndex The next available twab index. This will be recorded to next. /// @param _cardinality The cardinality of the TWAB history. /// @return The index of the last recorded TWAB function newestIndex(uint256 _nextIndex, uint256 _cardinality) internal pure returns (uint256) { if (_cardinality == 0) { return 0; } return wrap(_nextIndex + _cardinality - 1, _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); } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity 0.8.6; import "@openzeppelin/contracts/utils/math/SafeCast.sol"; import "./OverflowSafeComparatorLib.sol"; import "./RingBufferLib.sol"; /** * @title Observation Library * @notice This library allows one to store an array of timestamped values and efficiently binary 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 { using OverflowSafeComparatorLib for uint32; using SafeCast for uint256; /// @notice The maximum number of observations uint24 public constant MAX_CARDINALITY = 16777215; // 2**24 /** * @notice Observation, which includes an amount and timestamp. * @param amount `amount` at `timestamp`. * @param timestamp Recorded `timestamp`. */ struct Observation { uint224 amount; uint32 timestamp; } /** * @notice Fetches Observations `beforeOrAt` and `atOrAfter` a `_target`, eg: where [`beforeOrAt`, `atOrAfter`] is satisfied. * The result may be the same Observation, or adjacent Observations. * @dev The answer must be contained in the array used when the target is located within the stored Observation. * boundaries: 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. * @param _time Timestamp at which we perform the binary search. * @return beforeOrAt Observation recorded before, or at, the target. * @return atOrAfter Observation recorded at, or after, the target. */ function binarySearch( Observation[MAX_CARDINALITY] storage _observations, uint24 _newestObservationIndex, uint24 _oldestObservationIndex, uint32 _target, uint24 _cardinality, uint32 _time ) internal view returns (Observation memory beforeOrAt, Observation memory atOrAfter) { 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; beforeOrAt = _observations[uint24(RingBufferLib.wrap(currentIndex, _cardinality))]; uint32 beforeOrAtTimestamp = beforeOrAt.timestamp; // We've landed on an uninitialized timestamp, keep searching higher (more recently). if (beforeOrAtTimestamp == 0) { leftSide = currentIndex + 1; continue; } atOrAfter = _observations[uint24(RingBufferLib.nextIndex(currentIndex, _cardinality))]; bool targetAtOrAfter = beforeOrAtTimestamp.lte(_target, _time); // Check if we've found the corresponding Observation. if (targetAtOrAfter && _target.lte(atOrAfter.timestamp, _time)) { break; } // If `beforeOrAtTimestamp` is greater than `_target`, then we keep searching lower. To the left of the current index. if (!targetAtOrAfter) { rightSide = currentIndex - 1; } else { // Otherwise, we keep searching higher. To the left of the current index. leftSide = currentIndex + 1; } } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/math/SafeCast.sol) 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) { require(value >= type(int248).min && value <= type(int248).max, "SafeCast: value doesn't fit in 248 bits"); return int248(value); } /** * @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) { require(value >= type(int240).min && value <= type(int240).max, "SafeCast: value doesn't fit in 240 bits"); return int240(value); } /** * @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) { require(value >= type(int232).min && value <= type(int232).max, "SafeCast: value doesn't fit in 232 bits"); return int232(value); } /** * @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) { require(value >= type(int224).min && value <= type(int224).max, "SafeCast: value doesn't fit in 224 bits"); return int224(value); } /** * @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) { require(value >= type(int216).min && value <= type(int216).max, "SafeCast: value doesn't fit in 216 bits"); return int216(value); } /** * @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) { require(value >= type(int208).min && value <= type(int208).max, "SafeCast: value doesn't fit in 208 bits"); return int208(value); } /** * @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) { require(value >= type(int200).min && value <= type(int200).max, "SafeCast: value doesn't fit in 200 bits"); return int200(value); } /** * @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) { require(value >= type(int192).min && value <= type(int192).max, "SafeCast: value doesn't fit in 192 bits"); return int192(value); } /** * @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) { require(value >= type(int184).min && value <= type(int184).max, "SafeCast: value doesn't fit in 184 bits"); return int184(value); } /** * @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) { require(value >= type(int176).min && value <= type(int176).max, "SafeCast: value doesn't fit in 176 bits"); return int176(value); } /** * @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) { require(value >= type(int168).min && value <= type(int168).max, "SafeCast: value doesn't fit in 168 bits"); return int168(value); } /** * @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) { require(value >= type(int160).min && value <= type(int160).max, "SafeCast: value doesn't fit in 160 bits"); return int160(value); } /** * @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) { require(value >= type(int152).min && value <= type(int152).max, "SafeCast: value doesn't fit in 152 bits"); return int152(value); } /** * @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) { require(value >= type(int144).min && value <= type(int144).max, "SafeCast: value doesn't fit in 144 bits"); return int144(value); } /** * @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) { require(value >= type(int136).min && value <= type(int136).max, "SafeCast: value doesn't fit in 136 bits"); return int136(value); } /** * @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) { require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits"); return int128(value); } /** * @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) { require(value >= type(int120).min && value <= type(int120).max, "SafeCast: value doesn't fit in 120 bits"); return int120(value); } /** * @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) { require(value >= type(int112).min && value <= type(int112).max, "SafeCast: value doesn't fit in 112 bits"); return int112(value); } /** * @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) { require(value >= type(int104).min && value <= type(int104).max, "SafeCast: value doesn't fit in 104 bits"); return int104(value); } /** * @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) { require(value >= type(int96).min && value <= type(int96).max, "SafeCast: value doesn't fit in 96 bits"); return int96(value); } /** * @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) { require(value >= type(int88).min && value <= type(int88).max, "SafeCast: value doesn't fit in 88 bits"); return int88(value); } /** * @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) { require(value >= type(int80).min && value <= type(int80).max, "SafeCast: value doesn't fit in 80 bits"); return int80(value); } /** * @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) { require(value >= type(int72).min && value <= type(int72).max, "SafeCast: value doesn't fit in 72 bits"); return int72(value); } /** * @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) { require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits"); return int64(value); } /** * @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) { require(value >= type(int56).min && value <= type(int56).max, "SafeCast: value doesn't fit in 56 bits"); return int56(value); } /** * @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) { require(value >= type(int48).min && value <= type(int48).max, "SafeCast: value doesn't fit in 48 bits"); return int48(value); } /** * @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) { require(value >= type(int40).min && value <= type(int40).max, "SafeCast: value doesn't fit in 40 bits"); return int40(value); } /** * @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) { require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits"); return int32(value); } /** * @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) { require(value >= type(int24).min && value <= type(int24).max, "SafeCast: value doesn't fit in 24 bits"); return int24(value); } /** * @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) { require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits"); return int16(value); } /** * @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) { require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits"); return int8(value); } /** * @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); } }
{ "optimizer": { "enabled": true, "runs": 2000 }, "evmVersion": "berlin", "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "metadata": { "useLiteralContent": true }, "libraries": {} }
[{"inputs":[{"internalType":"string","name":"name_","type":"string"},{"internalType":"string","name":"symbol_","type":"string"},{"internalType":"contract ITicket","name":"_ticket","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"delegator","type":"address"},{"indexed":true,"internalType":"uint256","name":"slot","type":"uint256"},{"indexed":true,"internalType":"address","name":"delegatee","type":"address"},{"indexed":false,"internalType":"uint96","name":"lockUntil","type":"uint96"},{"indexed":false,"internalType":"address","name":"user","type":"address"}],"name":"DelegateeUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"delegator","type":"address"},{"indexed":true,"internalType":"uint256","name":"slot","type":"uint256"},{"indexed":false,"internalType":"uint96","name":"lockUntil","type":"uint96"},{"indexed":true,"internalType":"address","name":"delegatee","type":"address"},{"indexed":false,"internalType":"contract Delegation","name":"delegation","type":"address"},{"indexed":false,"internalType":"address","name":"user","type":"address"}],"name":"DelegationCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"delegator","type":"address"},{"indexed":true,"internalType":"uint256","name":"slot","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"address","name":"user","type":"address"}],"name":"DelegationFunded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"delegator","type":"address"},{"indexed":true,"internalType":"uint256","name":"slot","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"address","name":"user","type":"address"}],"name":"DelegationFundedFromStake","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"delegator","type":"address"},{"indexed":true,"internalType":"address","name":"representative","type":"address"},{"indexed":false,"internalType":"bool","name":"set","type":"bool"}],"name":"RepresentativeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract ITicket","name":"ticket","type":"address"}],"name":"TicketSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"delegator","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"TicketsStaked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"delegator","type":"address"},{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"TicketsUnstaked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"delegator","type":"address"},{"indexed":true,"internalType":"uint256","name":"slot","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"TransferredDelegation","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"delegator","type":"address"},{"indexed":true,"internalType":"uint256","name":"slot","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"address","name":"user","type":"address"}],"name":"WithdrewDelegationToStake","type":"event"},{"inputs":[],"name":"MAX_LOCK","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_delegator","type":"address"},{"internalType":"uint256","name":"_slot","type":"uint256"}],"name":"computeDelegationAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_delegator","type":"address"},{"internalType":"uint256","name":"_slot","type":"uint256"},{"internalType":"address","name":"_delegatee","type":"address"},{"internalType":"uint96","name":"_lockDuration","type":"uint96"}],"name":"createDelegation","outputs":[{"internalType":"contract Delegation","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"delegationInstance","outputs":[{"internalType":"contract Delegation","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_delegator","type":"address"},{"internalType":"uint256","name":"_slot","type":"uint256"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"fundDelegation","outputs":[{"internalType":"contract Delegation","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_delegator","type":"address"},{"internalType":"uint256","name":"_slot","type":"uint256"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"fundDelegationFromStake","outputs":[{"internalType":"contract Delegation","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_delegator","type":"address"},{"internalType":"uint256","name":"_slot","type":"uint256"}],"name":"getDelegation","outputs":[{"internalType":"contract Delegation","name":"delegation","type":"address"},{"internalType":"address","name":"delegatee","type":"address"},{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"lockUntil","type":"uint256"},{"internalType":"bool","name":"wasCreated","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_delegator","type":"address"},{"internalType":"address","name":"_representative","type":"address"}],"name":"isRepresentativeOf","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"_data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"","type":"bytes[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"components":[{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"internalType":"struct PermitAndMulticall.Signature","name":"_permitSignature","type":"tuple"},{"internalType":"bytes[]","name":"_data","type":"bytes[]"}],"name":"permitAndMulticall","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_representative","type":"address"},{"internalType":"bool","name":"_set","type":"bool"}],"name":"setRepresentative","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"stake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ticket","outputs":[{"internalType":"contract ITicket","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_slot","type":"uint256"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_to","type":"address"}],"name":"transferDelegationTo","outputs":[{"internalType":"contract Delegation","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"unstake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_delegator","type":"address"},{"internalType":"uint256","name":"_slot","type":"uint256"},{"internalType":"address","name":"_delegatee","type":"address"},{"internalType":"uint96","name":"_lockDuration","type":"uint96"}],"name":"updateDelegatee","outputs":[{"internalType":"contract Delegation","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_delegator","type":"address"},{"internalType":"uint256","name":"_slot","type":"uint256"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"withdrawDelegationToStake","outputs":[{"internalType":"contract Delegation","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
60a06040523480156200001157600080fd5b506040516200389238038062003892833981016040819052620000349162000317565b8251839083906200004d906003906020850190620001ac565b50805162000063906004906020840190620001ac565b50505060405162000074906200023b565b604051809103906000f08015801562000091573d6000803e3d6000fd5b50600580546001600160a01b0319166001600160a01b0392909216918217905560405163909f1cad60e01b81526000600482015263909f1cad90602401600060405180830381600087803b158015620000e957600080fd5b505af1158015620000fe573d6000803e3d6000fd5b505050506001600160a01b0381166200015d5760405162461bcd60e51b815260206004820181905260248201527f5457414244656c656761746f722f7469636b2d6e6f742d7a65726f2d61646472604482015260640160405180910390fd5b6001600160601b0319606082901b166080526040516001600160a01b038216907f9f9d59c87dbdc6ca82d9e5924782004b9aebc366c505c0ccab12f61e2a9f332190600090a2505050620003f7565b828054620001ba90620003a4565b90600052602060002090601f016020900481019282620001de576000855562000229565b82601f10620001f957805160ff191683800117855562000229565b8280016001018555821562000229579182015b82811115620002295782518255916020019190600101906200020c565b506200023792915062000249565b5090565b6107fc806200309683390190565b5b808211156200023757600081556001016200024a565b600082601f8301126200027257600080fd5b81516001600160401b03808211156200028f576200028f620003e1565b604051601f8301601f19908116603f01168101908282118183101715620002ba57620002ba620003e1565b81604052838152602092508683858801011115620002d757600080fd5b600091505b83821015620002fb5785820183015181830184015290820190620002dc565b838211156200030d5760008385830101525b9695505050505050565b6000806000606084860312156200032d57600080fd5b83516001600160401b03808211156200034557600080fd5b620003538783880162000260565b945060208601519150808211156200036a57600080fd5b50620003798682870162000260565b604086015190935090506001600160a01b03811681146200039957600080fd5b809150509250925092565b600181811c90821680620003b957607f821691505b60208210811415620003db57634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052604160045260246000fd5b60805160601c612c4162000455600039600081816102e4015281816104c4015281816105c8015281816107a001528181610c8e01528181610d3001528181610df001528181610ea701528181610ff0015261201a0152612c416000f3fe608060405234801561001057600080fd5b50600436106101c45760003560e01c8063889de805116100f9578063ac9650d811610097578063ca40edf111610071578063ca40edf114610418578063dd62ed3e14610460578063e18fa6eb14610499578063e7880ae1146104ac57600080fd5b8063ac9650d8146103d2578063adc9772e146103f2578063c2a672e01461040557600080fd5b806395d89b41116100d357806395d89b4114610391578063982b1f2f14610399578063a457c2d7146103ac578063a9059cbb146103bf57600080fd5b8063889de8051461032f5780638b4b4ec91461034257806390ab08851461035557600080fd5b80635f66501111610166578063666f7af611610140578063666f7af6146102b95780636c59f295146102cc5780636cc25db7146102df57806370a082311461030657600080fd5b80635f6650111461027157806363fc611f1461029c57806365a5d5f0146102af57600080fd5b806318160ddd116101a257806318160ddd1461021f57806323b872dd14610231578063313ce56714610244578063395093511461025e57600080fd5b806306452792146101c957806306fdde03146101de578063095ea7b3146101fc575b600080fd5b6101dc6101d73660046127df565b6104bf565b005b6101e66104f2565b6040516101f391906129fc565b60405180910390f35b61020f61020a36600461259a565b610584565b60405190151581526020016101f3565b6002545b6040519081526020016101f3565b61020f61023f36600461252b565b61059e565b61024c6105c4565b60405160ff90911681526020016101f3565b61020f61026c36600461259a565b61065c565b61028461027f366004612619565b61069b565b6040516001600160a01b0390911681526020016101f3565b600554610284906001600160a01b031681565b61022362ed4e0081565b6102846102c7366004612619565b61071f565b6102846102da3660046125c6565b61080e565b6102847f000000000000000000000000000000000000000000000000000000000000000081565b6102236103143660046124b8565b6001600160a01b031660009081526020819052604090205490565b61028461033d3660046125c6565b610954565b610284610350366004612845565b610a4f565b61020f6103633660046124f2565b6001600160a01b03918216600090815260066020908152604080832093909416825291909152205460ff1690565b6101e6610ab9565b6101dc6103a736600461256c565b610ac8565b61020f6103ba36600461259a565b610ba9565b61020f6103cd36600461259a565b610c5e565b6103e56103e036600461264e565b610c6c565b6040516101f3919061291d565b6101dc61040036600461259a565b610c78565b6101dc61041336600461259a565b610d07565b61042b61042636600461259a565b610d94565b604080516001600160a01b0396871681529590941660208601529284019190915260608301521515608082015260a0016101f3565b61022361046e3660046124f2565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6102846104a7366004612619565b610fb7565b6102846104ba36600461259a565b61105d565b6104ec7f000000000000000000000000000000000000000000000000000000000000000085858585611069565b50505050565b60606003805461050190612b00565b80601f016020809104026020016040519081016040528092919081815260200182805461052d90612b00565b801561057a5780601f1061054f5761010080835404028352916020019161057a565b820191906000526020600020905b81548152906001019060200180831161055d57829003601f168201915b5050505050905090565b600033610592818585611141565b60019150505b92915050565b6000336105ac858285611299565b6105b7858585611325565b60019150505b9392505050565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b15801561061f57600080fd5b505afa158015610633573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610657919061289b565b905090565b3360008181526001602090815260408083206001600160a01b03871684529091528120549091906105929082908690610696908790612aa5565b611141565b60006106a68461153c565b60006106b285856115c5565b90506106bf81308561161b565b6106c9858461163d565b336001600160a01b031684866001600160a01b03167f6862a473baa6176f1c866c69aa93da8508d7afc71b52dddc9d5e8b0bb7aab6f48660405161070f91815260200190565b60405180910390a4949350505050565b60006001600160a01b03841661077c5760405162461bcd60e51b815260206004820181905260248201527f5457414244656c656761746f722f646c6774722d6e6f742d7a65726f2d61647260448201526064015b60405180910390fd5b61078582611715565b600061079185856115c5565b90506107c86001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016338386611765565b336001600160a01b031684866001600160a01b03167f383183291bd9a7fb8bd9c7c86c5013a89d1490c9f4e486da279804b83729a1dc8660405161070f91815260200190565b60006108198561153c565b61082283611816565b610839826bffffffffffffffffffffffff1661186c565b600061084586866115c5565b9050610850816118bf565b4283016bffffffffffffffffffffffff8416156108e8576040517fac2293af0000000000000000000000000000000000000000000000000000000081526bffffffffffffffffffffffff821660048201526001600160a01b0383169063ac2293af90602401600060405180830381600087803b1580156108cf57600080fd5b505af11580156108e3573d6000803e3d6000fd5b505050505b6108f2828661198d565b604080516bffffffffffffffffffffffff831681523360208201526001600160a01b03808816928992918b16917ffd96a87f22afea1e17a7117a4923f1499a1c1eb2bd7c492caf07f3a3c38ade6f910160405180910390a45095945050505050565b600061095f8561153c565b61096883611816565b61097f826bffffffffffffffffffffffff1661186c565b42820160006109d96109d388886040516bffffffffffffffffffffffff19606084901b1660208201526034810182905260009060540160405160208183030381529060405280519060200120905092915050565b83611a13565b90506109e5818661198d565b604080516bffffffffffffffffffffffff841681526001600160a01b03838116602083015233828401529151878316928992908b16917f5533acb96061e404278604d3df68397263be1d4b9df394136a2968802633d8a59181900360600190a49695505050505050565b6000610a5a82611ab9565b6000610a6633866115c5565b9050610a7381848661161b565b826001600160a01b031685336001600160a01b03167f622b7da8a20026f1176ccc7ec0a635a4544a67e99b0125018e3d89b888ce8ebe8760405161070f91815260200190565b60606004805461050190612b00565b6001600160a01b038216610b1e5760405162461bcd60e51b815260206004820152601f60248201527f5457414244656c656761746f722f7265702d6e6f742d7a65726f2d61646472006044820152606401610773565b3360008181526006602090815260408083206001600160a01b0387168085529083529281902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001686151590811790915590519081529192917f50062a33e55b9f3dfcf05fbf1356b7c92313796cfb8526cdee5a497fcbb8cc3391015b60405180910390a35050565b3360008181526001602090815260408083206001600160a01b038716845290915281205490919083811015610c465760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760448201527f207a65726f0000000000000000000000000000000000000000000000000000006064820152608401610773565b610c538286868403611141565b506001949350505050565b600033610592818585611325565b60606105bd8383611b0f565b610c8181611715565b610cb66001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016333084611765565b610cc0828261163d565b816001600160a01b03167f15c2c6e5db9e25d828754c9c5cee6c5c3df074e6ac26e7491c0f8ce7bbd447d682604051610cfb91815260200190565b60405180910390a25050565b610d1082611ab9565b610d1981611715565b610d233382611c09565b610d576001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168383611d8e565b6040518181526001600160a01b0383169033907ff7128607975b3ff61bc02d19a1c8267e526f7a5b7144dc4efcdac634663fd36990602001610b9d565b6000806000806000610da687876115c5565b94506001600160a01b0385163b15156040517f8d22ea2a0000000000000000000000000000000000000000000000000000000081526001600160a01b0387811660048301529192507f000000000000000000000000000000000000000000000000000000000000000090911690638d22ea2a9060240160206040518083038186803b158015610e3457600080fd5b505afa158015610e48573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e6c91906124d5565b6040517f70a082310000000000000000000000000000000000000000000000000000000081526001600160a01b0387811660048301529195507f0000000000000000000000000000000000000000000000000000000000000000909116906370a082319060240160206040518083038186803b158015610eeb57600080fd5b505afa158015610eff573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f2391906127c6565b92508015610fad57846001600160a01b0316633c78929e6040518163ffffffff1660e01b815260040160206040518083038186803b158015610f6457600080fd5b505afa158015610f78573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f9c91906128b8565b6bffffffffffffffffffffffff1691505b9295509295909350565b6000610fc28461153c565b610fcb82611715565b6000610fd785856115c5565b9050610fe38584611c09565b6110176001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168285611d8e565b336001600160a01b031684866001600160a01b03167fb1968721eeb35d2206c8aa91805bc908019965ff4cff13c158f89956fb8e92488660405161070f91815260200190565b60006105bd83836115c5565b6001600160a01b03851663d505accf333087873561108d60408a0160208b0161287e565b604080517fffffffff0000000000000000000000000000000000000000000000000000000060e089901b1681526001600160a01b0396871660048201529590941660248601526044850192909252606484015260ff16608483015286013560a4820152606086013560c482015260e401600060405180830381600087803b15801561111757600080fd5b505af115801561112b573d6000803e3d6000fd5b505050506111398282611b0f565b505050505050565b6001600160a01b0383166111bc5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460448201527f72657373000000000000000000000000000000000000000000000000000000006064820152608401610773565b6001600160a01b0382166112385760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f20616464726560448201527f73730000000000000000000000000000000000000000000000000000000000006064820152608401610773565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b0383811660009081526001602090815260408083209386168352929052205460001981146104ec57818110156113185760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610773565b6104ec8484848403611141565b6001600160a01b0383166113a15760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f20616460448201527f64726573730000000000000000000000000000000000000000000000000000006064820152608401610773565b6001600160a01b03821661141d5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201527f65737300000000000000000000000000000000000000000000000000000000006064820152608401610773565b6001600160a01b038316600090815260208190526040902054818110156114ac5760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e742065786365656473206260448201527f616c616e636500000000000000000000000000000000000000000000000000006064820152608401610773565b6001600160a01b038085166000908152602081905260408082208585039055918516815290812080548492906114e3908490612aa5565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161152f91815260200190565b60405180910390a36104ec565b6001600160a01b03811633148061157657506001600160a01b038116600090815260066020908152604080832033845290915290205460ff165b6115c25760405162461bcd60e51b815260206004820152601e60248201527f5457414244656c656761746f722f6e6f742d646c6774722d6f722d72657000006044820152606401610773565b50565b60006105bd61161684846040516bffffffffffffffffffffffff19606084901b1660208201526034810182905260009060540160405160208183030381529060405280519060200120905092915050565b611dd7565b61162481611715565b61162d836118bf565b611638838383611e60565b505050565b6001600160a01b0382166116935760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610773565b80600260008282546116a59190612aa5565b90915550506001600160a01b038216600090815260208190526040812080548392906116d2908490612aa5565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90602001610b9d565b600081116115c25760405162461bcd60e51b815260206004820152601c60248201527f5457414244656c656761746f722f616d6f756e742d67742d7a65726f000000006044820152606401610773565b6040516001600160a01b03808516602483015283166044820152606481018290526104ec9085907f23b872dd00000000000000000000000000000000000000000000000000000000906084015b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152611ee3565b6001600160a01b0381166115c25760405162461bcd60e51b815260206004820181905260248201527f5457414244656c656761746f722f646c67742d6e6f742d7a65726f2d616464726044820152606401610773565b62ed4e008111156115c25760405162461bcd60e51b815260206004820152601b60248201527f5457414244656c656761746f722f6c6f636b2d746f6f2d6c6f6e6700000000006044820152606401610773565b806001600160a01b0316633c78929e6040518163ffffffff1660e01b815260040160206040518083038186803b1580156118f857600080fd5b505afa15801561190c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061193091906128b8565b6bffffffffffffffffffffffff164210156115c25760405162461bcd60e51b815260206004820152601f60248201527f5457414244656c656761746f722f64656c65676174696f6e2d6c6f636b6564006044820152606401610773565b604080516001600160a01b0383166024808301919091528251808303909101815260449091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f5c19a95c0000000000000000000000000000000000000000000000000000000090811790915290611a0c8482611fc8565b5050505050565b6005546000908190611a2e906001600160a01b03168561210c565b6040517f909f1cad0000000000000000000000000000000000000000000000000000000081526bffffffffffffffffffffffff851660048201529091506001600160a01b0382169063909f1cad90602401600060405180830381600087803b158015611a9957600080fd5b505af1158015611aad573d6000803e3d6000fd5b50929695505050505050565b6001600160a01b0381166115c25760405162461bcd60e51b815260206004820152601e60248201527f5457414244656c656761746f722f746f2d6e6f742d7a65726f2d6164647200006044820152606401610773565b60608160008167ffffffffffffffff811115611b2d57611b2d612b82565b604051908082528060200260200182016040528015611b6057816020015b6060815260200190600190039081611b4b5790505b50905060005b82811015611c0057611bd030878784818110611b8457611b84612b6c565b9050602002810190611b969190612a0f565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506121c392505050565b828281518110611be257611be2612b6c565b60200260200101819052508080611bf890612b3b565b915050611b66565b50949350505050565b6001600160a01b038216611c855760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f2061646472657360448201527f73000000000000000000000000000000000000000000000000000000000000006064820152608401610773565b6001600160a01b03821660009081526020819052604090205481811015611d145760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e60448201527f63650000000000000000000000000000000000000000000000000000000000006064820152608401610773565b6001600160a01b0383166000908152602081905260408120838303905560028054849290611d43908490612abd565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3505050565b6040516001600160a01b0383166024820152604481018290526116389084907fa9059cbb00000000000000000000000000000000000000000000000000000000906064016117b2565b600554600090610598906001600160a01b031683306040517f3d602d80600a3d3981f3363d3d373d3d3d363d730000000000000000000000008152606093841b60148201527f5af43d82803e903d91602b57fd5bf3ff000000000000000000000000000000006028820152921b6038830152604c8201526037808220606c830152605591012090565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb00000000000000000000000000000000000000000000000000000000908117909152906111398582611fc8565b6000611f38826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166121e89092919063ffffffff16565b8051909150156116385780806020019051810190611f5691906127a9565b6116385760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610773565b60408051600180825281830190925260609160009190816020015b604080518082019091526000815260606020820152815260200190600190039081611fe357905050905060405180604001604052807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602001848152508160008151811061205e5761205e612b6c565b60209081029190910101526040517fde9443bf0000000000000000000000000000000000000000000000000000000081526001600160a01b0385169063de9443bf906120ae90849060040161297f565b600060405180830381600087803b1580156120c857600080fd5b505af11580156120dc573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526121049190810190612690565b949350505050565b60006040517f3d602d80600a3d3981f3363d3d373d3d3d363d7300000000000000000000000081528360601b60148201527f5af43d82803e903d91602b57fd5bf300000000000000000000000000000000006028820152826037826000f59150506001600160a01b0381166105985760405162461bcd60e51b815260206004820152601760248201527f455243313136373a2063726561746532206661696c65640000000000000000006044820152606401610773565b60606105bd8383604051806060016040528060278152602001612be5602791396121f7565b606061210484846000856122eb565b60606001600160a01b0384163b6122765760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f60448201527f6e747261637400000000000000000000000000000000000000000000000000006064820152608401610773565b600080856001600160a01b0316856040516122919190612901565b600060405180830381855af49150503d80600081146122cc576040519150601f19603f3d011682016040523d82523d6000602084013e6122d1565b606091505b50915091506122e1828286612433565b9695505050505050565b6060824710156123635760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c00000000000000000000000000000000000000000000000000006064820152608401610773565b6001600160a01b0385163b6123ba5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610773565b600080866001600160a01b031685876040516123d69190612901565b60006040518083038185875af1925050503d8060008114612413576040519150601f19603f3d011682016040523d82523d6000602084013e612418565b606091505b5091509150612428828286612433565b979650505050505050565b606083156124425750816105bd565b8251156124525782518084602001fd5b8160405162461bcd60e51b815260040161077391906129fc565b60008083601f84011261247e57600080fd5b50813567ffffffffffffffff81111561249657600080fd5b6020830191508360208260051b85010111156124b157600080fd5b9250929050565b6000602082840312156124ca57600080fd5b81356105bd81612b98565b6000602082840312156124e757600080fd5b81516105bd81612b98565b6000806040838503121561250557600080fd5b823561251081612b98565b9150602083013561252081612b98565b809150509250929050565b60008060006060848603121561254057600080fd5b833561254b81612b98565b9250602084013561255b81612b98565b929592945050506040919091013590565b6000806040838503121561257f57600080fd5b823561258a81612b98565b9150602083013561252081612bad565b600080604083850312156125ad57600080fd5b82356125b881612b98565b946020939093013593505050565b600080600080608085870312156125dc57600080fd5b84356125e781612b98565b93506020850135925060408501356125fe81612b98565b9150606085013561260e81612bca565b939692955090935050565b60008060006060848603121561262e57600080fd5b833561263981612b98565b95602085013595506040909401359392505050565b6000806020838503121561266157600080fd5b823567ffffffffffffffff81111561267857600080fd5b6126848582860161246c565b90969095509350505050565b600060208083850312156126a357600080fd5b825167ffffffffffffffff808211156126bb57600080fd5b8185019150601f86818401126126d057600080fd5b8251828111156126e2576126e2612b82565b8060051b6126f1868201612a74565b8281528681019086880183880189018c101561270c57600080fd5b600093505b8484101561279a5780518781111561272857600080fd5b8801603f81018d1361273957600080fd5b8981015160408982111561274f5761274f612b82565b6127608c601f198b85011601612a74565b8281528f8284860101111561277457600080fd5b612783838e8301848701612ad4565b865250505060019390930192918801918801612711565b509a9950505050505050505050565b6000602082840312156127bb57600080fd5b81516105bd81612bad565b6000602082840312156127d857600080fd5b5051919050565b60008060008084860360c08112156127f657600080fd5b853594506080601f198201121561280c57600080fd5b5060208501925060a085013567ffffffffffffffff81111561282d57600080fd5b6128398782880161246c565b95989497509550505050565b60008060006060848603121561285a57600080fd5b8335925060208401359150604084013561287381612b98565b809150509250925092565b60006020828403121561289057600080fd5b81356105bd81612bbb565b6000602082840312156128ad57600080fd5b81516105bd81612bbb565b6000602082840312156128ca57600080fd5b81516105bd81612bca565b600081518084526128ed816020860160208601612ad4565b601f01601f19169290920160200192915050565b60008251612913818460208701612ad4565b9190910192915050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b8281101561297257603f198886030184526129608583516128d5565b94509285019290850190600101612944565b5092979650505050505050565b60006020808301818452808551808352604092508286019150828160051b87010184880160005b838110156129ee57888303603f19018552815180516001600160a01b031684528701518784018790526129db878501826128d5565b95880195935050908601906001016129a6565b509098975050505050505050565b6020815260006105bd60208301846128d5565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe1843603018112612a4457600080fd5b83018035915067ffffffffffffffff821115612a5f57600080fd5b6020019150368190038213156124b157600080fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715612a9d57612a9d612b82565b604052919050565b60008219821115612ab857612ab8612b56565b500190565b600082821015612acf57612acf612b56565b500390565b60005b83811015612aef578181015183820152602001612ad7565b838111156104ec5750506000910152565b600181811c90821680612b1457607f821691505b60208210811415612b3557634e487b7160e01b600052602260045260246000fd5b50919050565b6000600019821415612b4f57612b4f612b56565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b03811681146115c257600080fd5b80151581146115c257600080fd5b60ff811681146115c257600080fd5b6bffffffffffffffffffffffff811681146115c257600080fdfe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220eaa276041816cc3d6c433f3388c3e693963f13496cb2cf334f483aba072d983364736f6c63430008060033608060405234801561001057600080fd5b506107dc806100206000396000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c80633c78929e14610051578063909f1cad146100a3578063ac2293af146100b8578063de9443bf146100cb575b600080fd5b600054610081907401000000000000000000000000000000000000000090046bffffffffffffffffffffffff1681565b6040516bffffffffffffffffffffffff90911681526020015b60405180910390f35b6100b66100b136600461049e565b6100eb565b005b6100b66100c636600461049e565b610182565b6100de6100d9366004610429565b610234565b60405161009a919061051b565b60005473ffffffffffffffffffffffffffffffffffffffff16156101565760405162461bcd60e51b815260206004820152601760248201527f44656c65676174696f6e2f616c72656164792d696e697400000000000000000060448201526064015b60405180910390fd5b6bffffffffffffffffffffffff1674010000000000000000000000000000000000000000023317600055565b60005473ffffffffffffffffffffffffffffffffffffffff1633146101e95760405162461bcd60e51b815260206004820152601560248201527f44656c65676174696f6e2f6f6e6c792d6f776e65720000000000000000000000604482015260640161014d565b600080546bffffffffffffffffffffffff909216740100000000000000000000000000000000000000000273ffffffffffffffffffffffffffffffffffffffff909216919091179055565b60005460609073ffffffffffffffffffffffffffffffffffffffff16331461029e5760405162461bcd60e51b815260206004820152601560248201527f44656c65676174696f6e2f6f6e6c792d6f776e65720000000000000000000000604482015260640161014d565b8160008167ffffffffffffffff8111156102ba576102ba610790565b6040519080825280602002602001820160405280156102ed57816020015b60608152602001906001900390816102d85790505b5060408051808201909152600081526060602082015290915060005b83811015610382578686828181106103235761032361077a565b905060200281019061033591906105ae565b61033e9061063c565b91506103528260000151836020015161038d565b8382815181106103645761036461077a565b6020026020010181905250808061037a90610733565b915050610309565b509095945050505050565b60606000808473ffffffffffffffffffffffffffffffffffffffff166000856040516103b991906104ff565b60006040518083038185875af1925050503d80600081146103f6576040519150601f19603f3d011682016040523d82523d6000602084013e6103fb565b606091505b50915091508181906104205760405162461bcd60e51b815260040161014d919061059b565b50949350505050565b6000806020838503121561043c57600080fd5b823567ffffffffffffffff8082111561045457600080fd5b818501915085601f83011261046857600080fd5b81358181111561047757600080fd5b8660208260051b850101111561048c57600080fd5b60209290920196919550909350505050565b6000602082840312156104b057600080fd5b81356bffffffffffffffffffffffff811681146104cc57600080fd5b9392505050565b600081518084526104eb816020860160208601610703565b601f01601f19169290920160200192915050565b60008251610511818460208701610703565b9190910192915050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b8281101561058e577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc088860301845261057c8583516104d3565b94509285019290850190600101610542565b5092979650505050505050565b6020815260006104cc60208301846104d3565b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc183360301811261051157600080fd5b6040805190810167ffffffffffffffff8111828210171561060557610605610790565b60405290565b604051601f8201601f1916810167ffffffffffffffff8111828210171561063457610634610790565b604052919050565b60006040823603121561064e57600080fd5b6106566105e2565b823573ffffffffffffffffffffffffffffffffffffffff8116811461067a57600080fd5b815260208381013567ffffffffffffffff8082111561069857600080fd5b9085019036601f8301126106ab57600080fd5b8135818111156106bd576106bd610790565b6106cf84601f19601f8401160161060b565b915080825236848285010111156106e557600080fd5b80848401858401376000908201840152918301919091525092915050565b60005b8381101561071e578181015183820152602001610706565b8381111561072d576000848401525b50505050565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82141561077357634e487b7160e01b600052601160045260246000fd5b5060010190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fdfea2646970667358221220e12294174ea821f82c2a1f83c4f824acb92d2de0e672f2347c9eb5611a26a93564736f6c63430008060033000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000c8a87436dd0f97f28bf46f330802dfd36aab1550000000000000000000000000000000000000000000000000000000000000020506f6f6c546f676574686572205374616b6564206155534443205469636b6574000000000000000000000000000000000000000000000000000000000000000a73746b5054615553444300000000000000000000000000000000000000000000
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000c8a87436dd0f97f28bf46f330802dfd36aab1550000000000000000000000000000000000000000000000000000000000000020506f6f6c546f676574686572205374616b6564206155534443205469636b6574000000000000000000000000000000000000000000000000000000000000000a73746b5054615553444300000000000000000000000000000000000000000000
-----Decoded View---------------
Arg [0] : name_ (string): PoolTogether Staked aUSDC Ticket
Arg [1] : symbol_ (string): stkPTaUSDC
Arg [2] : _ticket (address): 0x0c8a87436dd0f97f28bf46f330802dfd36aab155
-----Encoded View---------------
7 Constructor Arguments found :
Arg [0] : 0000000000000000000000000000000000000000000000000000000000000060
Arg [1] : 00000000000000000000000000000000000000000000000000000000000000a0
Arg [2] : 0000000000000000000000000c8a87436dd0f97f28bf46f330802dfd36aab155
Arg [3] : 0000000000000000000000000000000000000000000000000000000000000020
Arg [4] : 506f6f6c546f676574686572205374616b6564206155534443205469636b6574
Arg [5] : 000000000000000000000000000000000000000000000000000000000000000a
Arg [6] : 73746b5054615553444300000000000000000000000000000000000000000000
Age | Block | Fee Address | BC Fee Address | Voting Power | Jailed | Incoming |
---|