ETH Price: $3,266.44 (+2.83%)
Gas: 2 Gwei

Contract

0xb0C9B6D67608bE300398d0e4FB0cCa3891E1B33F
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

Latest 1 internal transaction

Advanced mode:
Parent Transaction Hash Block From To
176845722023-07-13 12:26:59379 days ago1689251219  Contract Creation0 ETH
Loading...
Loading

Similar Match Source Code
This contract matches the deployed Bytecode of the Source Code for Contract 0x2b3C5708...aCBF94880
The constructor portion of the code might be different and could alter the actual behaviour of the contract

Contract Name:
Drips

Compiler Version
v0.8.20+commit.a1b79de6

Optimization Enabled:
Yes with 7700 runs

Other Settings:
default evmVersion
File 1 of 17 : Drips.sol
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.20;

import {
    Streams, StreamConfig, StreamsHistory, StreamConfigImpl, StreamReceiver
} from "./Streams.sol";
import {Managed} from "./Managed.sol";
import {Splits, SplitsReceiver} from "./Splits.sol";
import {IERC20, SafeERC20} from "openzeppelin-contracts/token/ERC20/utils/SafeERC20.sol";

using SafeERC20 for IERC20;

/// @notice The account metadata.
/// The key and the value are not standardized by the protocol, it's up to the users
/// to establish and follow conventions to ensure compatibility with the consumers.
struct AccountMetadata {
    /// @param key The metadata key
    bytes32 key;
    /// @param value The metadata value
    bytes value;
}

/// @notice Drips protocol contract. Automatically streams and splits funds between accounts.
///
/// The account can transfer some funds to their streams balance in the contract
/// and configure a list of receivers, to whom they want to stream these funds.
/// As soon as the streams balance is enough to cover at least 1 second of streaming
/// to the configured receivers, the funds start streaming automatically.
/// Every second funds are deducted from the streams balance and moved to their receivers.
/// The process stops automatically when the streams balance is not enough to cover another second.
///
/// Every account has a receiver balance, in which they have funds received from other accounts.
/// The streamed funds are added to the receiver balances in global cycles.
/// Every `cycleSecs` seconds the protocol adds streamed funds to the receivers' balances,
/// so recently streamed funds may not be receivable immediately.
/// `cycleSecs` is a constant configured when the Drips contract is deployed.
/// The receiver balance is independent from the streams balance,
/// to stream received funds they need to be first collected and then added to the streams balance.
///
/// The account can share collected funds with other accounts by using splits.
/// When collecting, the account gives each of their splits receivers
/// a fraction of the received funds.
/// Funds received from splits are available for collection immediately regardless of the cycle.
/// They aren't exempt from being split, so they too can be split when collected.
/// Accounts can build chains and networks of splits between each other.
/// Anybody can request collection of funds for any account,
/// which can be used to enforce the flow of funds in the network of splits.
///
/// The concept of something happening periodically, e.g. every second or every `cycleSecs` are
/// only high-level abstractions for the account, Ethereum isn't really capable of scheduling work.
/// The actual implementation emulates that behavior by calculating the results of the scheduled
/// events based on how many seconds have passed and only when the account needs their outcomes.
///
/// The contract can store at most `type(int128).max` which is `2 ^ 127 - 1` units of each token.
contract Drips is Managed, Streams, Splits {
    /// @notice Maximum number of streams receivers of a single account.
    /// Limits cost of changes in streams configuration.
    uint256 public constant MAX_STREAMS_RECEIVERS = _MAX_STREAMS_RECEIVERS;
    /// @notice The additional decimals for all amtPerSec values.
    uint8 public constant AMT_PER_SEC_EXTRA_DECIMALS = _AMT_PER_SEC_EXTRA_DECIMALS;
    /// @notice The multiplier for all amtPerSec values.
    uint160 public constant AMT_PER_SEC_MULTIPLIER = _AMT_PER_SEC_MULTIPLIER;
    /// @notice Maximum number of splits receivers of a single account.
    /// Limits the cost of splitting.
    uint256 public constant MAX_SPLITS_RECEIVERS = _MAX_SPLITS_RECEIVERS;
    /// @notice The total splits weight of an account
    uint32 public constant TOTAL_SPLITS_WEIGHT = _TOTAL_SPLITS_WEIGHT;
    /// @notice The offset of the controlling driver ID in the account ID.
    /// In other words the controlling driver ID is the highest 32 bits of the account ID.
    /// Every account ID is a 256-bit integer constructed by concatenating:
    /// `driverId (32 bits) | driverCustomData (224 bits)`.
    uint8 public constant DRIVER_ID_OFFSET = 224;
    /// @notice The total amount the protocol can store of each token.
    /// It's the minimum of _MAX_STREAMS_BALANCE and _MAX_SPLITS_BALANCE.
    uint128 public constant MAX_TOTAL_BALANCE = _MAX_STREAMS_BALANCE;
    /// @notice On every timestamp `T`, which is a multiple of `cycleSecs`, the receivers
    /// gain access to steams received during `T - cycleSecs` to `T - 1`.
    /// Always higher than 1.
    uint32 public immutable cycleSecs;
    /// @notice The minimum amtPerSec of a stream. It's 1 token per cycle.
    uint160 public immutable minAmtPerSec;
    /// @notice The ERC-1967 storage slot holding a single `DripsStorage` structure.
    bytes32 private immutable _dripsStorageSlot = _erc1967Slot("eip1967.drips.storage");

    /// @notice Emitted when a driver is registered
    /// @param driverId The driver ID
    /// @param driverAddr The driver address
    event DriverRegistered(uint32 indexed driverId, address indexed driverAddr);

    /// @notice Emitted when a driver address is updated
    /// @param driverId The driver ID
    /// @param oldDriverAddr The old driver address
    /// @param newDriverAddr The new driver address
    event DriverAddressUpdated(
        uint32 indexed driverId, address indexed oldDriverAddr, address indexed newDriverAddr
    );

    /// @notice Emitted when funds are withdrawn.
    /// @param erc20 The used ERC-20 token.
    /// @param receiver The address that the funds are sent to.
    /// @param amt The withdrawn amount.
    event Withdrawn(IERC20 indexed erc20, address indexed receiver, uint256 amt);

    /// @notice Emitted by the account to broadcast metadata.
    /// The key and the value are not standardized by the protocol, it's up to the users
    /// to establish and follow conventions to ensure compatibility with the consumers.
    /// @param accountId The ID of the account emitting metadata
    /// @param key The metadata key
    /// @param value The metadata value
    event AccountMetadataEmitted(uint256 indexed accountId, bytes32 indexed key, bytes value);

    struct DripsStorage {
        /// @notice The next driver ID that will be used when registering.
        uint32 nextDriverId;
        /// @notice Driver addresses.
        mapping(uint32 driverId => address) driverAddresses;
        /// @notice The balance of each token currently stored in the protocol.
        mapping(IERC20 erc20 => Balance) balances;
    }

    /// @notice The balance currently stored in the protocol.
    struct Balance {
        /// @notice The balance currently stored in streaming.
        uint128 streams;
        /// @notice The balance currently stored in splitting.
        uint128 splits;
    }

    /// @param cycleSecs_ The length of cycleSecs to be used in the contract instance.
    /// Low value makes funds more available by shortening the average time
    /// of funds being frozen between being taken from the accounts'
    /// streams balance and being receivable by their receivers.
    /// High value makes receiving cheaper by making it process less cycles for a given time range.
    /// Must be higher than 1.
    constructor(uint32 cycleSecs_)
        Streams(cycleSecs_, _erc1967Slot("eip1967.streams.storage"))
        Splits(_erc1967Slot("eip1967.splits.storage"))
    {
        cycleSecs = Streams._cycleSecs;
        minAmtPerSec = Streams._minAmtPerSec;
    }

    /// @notice A modifier making functions callable only by the driver controlling the account.
    /// @param accountId The account ID.
    modifier onlyDriver(uint256 accountId) {
        // `accountId` has value:
        // `driverId (32 bits) | driverCustomData (224 bits)`
        // By bit shifting we get value:
        // `zeros (224 bits) | driverId (32 bits)`
        // By casting down we get value:
        // `driverId (32 bits)`
        uint32 driverId = uint32(accountId >> DRIVER_ID_OFFSET);
        _assertCallerIsDriver(driverId);
        _;
    }

    /// @notice Verifies that the caller controls the given driver ID and reverts otherwise.
    /// @param driverId The driver ID.
    function _assertCallerIsDriver(uint32 driverId) internal view {
        require(driverAddress(driverId) == msg.sender, "Callable only by the driver");
    }

    /// @notice Registers a driver.
    /// The driver is assigned a unique ID and a range of account IDs it can control.
    /// That range consists of all 2^224 account IDs with highest 32 bits equal to the driver ID.
    /// Every account ID is a 256-bit integer constructed by concatenating:
    /// `driverId (32 bits) | driverCustomData (224 bits)`.
    /// Every driver ID is assigned only to a single address,
    /// but a single address can have multiple driver IDs assigned to it.
    /// @param driverAddr The address of the driver. Must not be zero address.
    /// It should be a smart contract capable of dealing with the Drips API.
    /// It shouldn't be an EOA because the API requires making multiple calls per transaction.
    /// @return driverId The registered driver ID.
    function registerDriver(address driverAddr) public whenNotPaused returns (uint32 driverId) {
        require(driverAddr != address(0), "Driver registered for 0 address");
        DripsStorage storage dripsStorage = _dripsStorage();
        driverId = dripsStorage.nextDriverId++;
        dripsStorage.driverAddresses[driverId] = driverAddr;
        emit DriverRegistered(driverId, driverAddr);
    }

    /// @notice Returns the driver address.
    /// @param driverId The driver ID to look up.
    /// @return driverAddr The address of the driver.
    /// If the driver hasn't been registered yet, returns address 0.
    function driverAddress(uint32 driverId) public view returns (address driverAddr) {
        return _dripsStorage().driverAddresses[driverId];
    }

    /// @notice Updates the driver address. Must be called from the current driver address.
    /// @param driverId The driver ID.
    /// @param newDriverAddr The new address of the driver.
    /// It should be a smart contract capable of dealing with the Drips API.
    /// It shouldn't be an EOA because the API requires making multiple calls per transaction.
    function updateDriverAddress(uint32 driverId, address newDriverAddr) public whenNotPaused {
        _assertCallerIsDriver(driverId);
        _dripsStorage().driverAddresses[driverId] = newDriverAddr;
        emit DriverAddressUpdated(driverId, msg.sender, newDriverAddr);
    }

    /// @notice Returns the driver ID which will be assigned for the next registered driver.
    /// @return driverId The next driver ID.
    function nextDriverId() public view returns (uint32 driverId) {
        return _dripsStorage().nextDriverId;
    }

    /// @notice Returns the amount currently stored in the protocol of the given token.
    /// The sum of streaming and splitting balances can never exceed `MAX_TOTAL_BALANCE`.
    /// The amount of tokens held by the Drips contract exceeding the sum of
    /// streaming and splitting balances can be `withdraw`n.
    /// @param erc20 The used ERC-20 token.
    /// It must preserve amounts, so if some amount of tokens is transferred to
    /// an address, then later the same amount must be transferable from that address.
    /// Tokens which rebase the holders' balances, collect taxes on transfers,
    /// or impose any restrictions on holding or transferring tokens are not supported.
    /// If you use such tokens in the protocol, they can get stuck or lost.
    /// @return streamsBalance The balance currently stored in streaming.
    /// @return splitsBalance The balance currently stored in splitting.
    function balances(IERC20 erc20)
        public
        view
        returns (uint128 streamsBalance, uint128 splitsBalance)
    {
        Balance storage balance = _dripsStorage().balances[erc20];
        return (balance.streams, balance.splits);
    }

    /// @notice Increases the balance of the given token currently stored in streams.
    /// No funds are transferred, all the tokens are expected to be already held by Drips.
    /// The new total balance is verified to have coverage in the held tokens
    /// and to be within the limit of `MAX_TOTAL_BALANCE`.
    /// @param erc20 The used ERC-20 token.
    /// @param amt The amount to increase the streams balance by.
    function _increaseStreamsBalance(IERC20 erc20, uint128 amt) internal {
        _verifyBalanceIncrease(erc20, amt);
        _dripsStorage().balances[erc20].streams += amt;
    }

    /// @notice Decreases the balance of the given token currently stored in streams.
    /// No funds are transferred, but the tokens held by Drips
    /// above the total balance become withdrawable.
    /// @param erc20 The used ERC-20 token.
    /// @param amt The amount to decrease the streams balance by.
    function _decreaseStreamsBalance(IERC20 erc20, uint128 amt) internal {
        _dripsStorage().balances[erc20].streams -= amt;
    }

    /// @notice Increases the balance of the given token currently stored in streams.
    /// No funds are transferred, all the tokens are expected to be already held by Drips.
    /// The new total balance is verified to have coverage in the held tokens
    /// and to be within the limit of `MAX_TOTAL_BALANCE`.
    /// @param erc20 The used ERC-20 token.
    /// @param amt The amount to increase the streams balance by.
    function _increaseSplitsBalance(IERC20 erc20, uint128 amt) internal {
        _verifyBalanceIncrease(erc20, amt);
        _dripsStorage().balances[erc20].splits += amt;
    }

    /// @notice Decreases the balance of the given token currently stored in splits.
    /// No funds are transferred, but the tokens held by Drips
    /// above the total balance become withdrawable.
    /// @param erc20 The used ERC-20 token.
    /// @param amt The amount to decrease the splits balance by.
    function _decreaseSplitsBalance(IERC20 erc20, uint128 amt) internal {
        _dripsStorage().balances[erc20].splits -= amt;
    }

    /// @notice Moves the balance of the given token currently stored in streams to splits.
    /// No funds are transferred, all the tokens are already held by Drips.
    /// @param erc20 The used ERC-20 token.
    /// @param amt The amount to decrease the splits balance by.
    function _moveBalanceFromStreamsToSplits(IERC20 erc20, uint128 amt) internal {
        Balance storage balance = _dripsStorage().balances[erc20];
        balance.streams -= amt;
        balance.splits += amt;
    }

    /// @notice Verifies that the balance of streams or splits can be increased by the given amount.
    /// The sum of streaming and splitting balances is checked to not exceed
    /// `MAX_TOTAL_BALANCE` or the amount of tokens held by the Drips.
    /// @param erc20 The used ERC-20 token.
    /// @param amt The amount to increase the streams or splits balance by.
    function _verifyBalanceIncrease(IERC20 erc20, uint128 amt) internal view {
        (uint256 streamsBalance, uint128 splitsBalance) = balances(erc20);
        uint256 newTotalBalance = streamsBalance + splitsBalance + amt;
        require(newTotalBalance <= MAX_TOTAL_BALANCE, "Total balance too high");
        require(newTotalBalance <= _tokenBalance(erc20), "Token balance too low");
    }

    /// @notice Transfers withdrawable funds to an address.
    /// The withdrawable funds are held by the Drips contract,
    /// but not used in the protocol, so they are free to be transferred out.
    /// Anybody can call `withdraw`, so all withdrawable funds should be withdrawn
    /// or used in the protocol before any 3rd parties have a chance to do that.
    /// @param erc20 The used ERC-20 token.
    /// It must preserve amounts, so if some amount of tokens is transferred to
    /// an address, then later the same amount must be transferable from that address.
    /// Tokens which rebase the holders' balances, collect taxes on transfers,
    /// or impose any restrictions on holding or transferring tokens are not supported.
    /// If you use such tokens in the protocol, they can get stuck or lost.
    /// @param receiver The address to send withdrawn funds to.
    /// @param amt The withdrawn amount.
    /// It must be at most the difference between the balance of the token held by the Drips
    /// contract address and the sum of balances managed by the protocol as indicated by `balances`.
    function withdraw(IERC20 erc20, address receiver, uint256 amt) public {
        (uint128 streamsBalance, uint128 splitsBalance) = balances(erc20);
        uint256 withdrawable = _tokenBalance(erc20) - streamsBalance - splitsBalance;
        require(amt <= withdrawable, "Withdrawal amount too high");
        emit Withdrawn(erc20, receiver, amt);
        erc20.safeTransfer(receiver, amt);
    }

    function _tokenBalance(IERC20 erc20) internal view returns (uint256) {
        return erc20.balanceOf(address(this));
    }

    /// @notice Counts cycles from which streams can be collected.
    /// This function can be used to detect that there are
    /// too many cycles to analyze in a single transaction.
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// It must preserve amounts, so if some amount of tokens is transferred to
    /// an address, then later the same amount must be transferable from that address.
    /// Tokens which rebase the holders' balances, collect taxes on transfers,
    /// or impose any restrictions on holding or transferring tokens are not supported.
    /// If you use such tokens in the protocol, they can get stuck or lost.
    /// @return cycles The number of cycles which can be flushed
    function receivableStreamsCycles(uint256 accountId, IERC20 erc20)
        public
        view
        returns (uint32 cycles)
    {
        return Streams._receivableStreamsCycles(accountId, erc20);
    }

    /// @notice Calculate effects of calling `receiveStreams` with the given parameters.
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// It must preserve amounts, so if some amount of tokens is transferred to
    /// an address, then later the same amount must be transferable from that address.
    /// Tokens which rebase the holders' balances, collect taxes on transfers,
    /// or impose any restrictions on holding or transferring tokens are not supported.
    /// If you use such tokens in the protocol, they can get stuck or lost.
    /// @param maxCycles The maximum number of received streams cycles.
    /// If too low, receiving will be cheap, but may not cover many cycles.
    /// If too high, receiving may become too expensive to fit in a single transaction.
    /// @return receivableAmt The amount which would be received
    function receiveStreamsResult(uint256 accountId, IERC20 erc20, uint32 maxCycles)
        public
        view
        returns (uint128 receivableAmt)
    {
        (receivableAmt,,,,) = Streams._receiveStreamsResult(accountId, erc20, maxCycles);
    }

    /// @notice Receive streams for the account.
    /// Received streams cycles won't need to be analyzed ever again.
    /// Calling this function does not collect but makes the funds ready to be split and collected.
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// It must preserve amounts, so if some amount of tokens is transferred to
    /// an address, then later the same amount must be transferable from that address.
    /// Tokens which rebase the holders' balances, collect taxes on transfers,
    /// or impose any restrictions on holding or transferring tokens are not supported.
    /// If you use such tokens in the protocol, they can get stuck or lost.
    /// @param maxCycles The maximum number of received streams cycles.
    /// If too low, receiving will be cheap, but may not cover many cycles.
    /// If too high, receiving may become too expensive to fit in a single transaction.
    /// @return receivedAmt The received amount
    function receiveStreams(uint256 accountId, IERC20 erc20, uint32 maxCycles)
        public
        whenNotPaused
        returns (uint128 receivedAmt)
    {
        receivedAmt = Streams._receiveStreams(accountId, erc20, maxCycles);
        if (receivedAmt != 0) {
            _moveBalanceFromStreamsToSplits(erc20, receivedAmt);
            Splits._addSplittable(accountId, erc20, receivedAmt);
        }
    }

    /// @notice Receive streams from the currently running cycle from a single sender.
    /// It doesn't receive streams from the finished cycles, to do that use `receiveStreams`.
    /// Squeezed funds won't be received in the next calls to `squeezeStreams` or `receiveStreams`.
    /// Only funds streamed before `block.timestamp` can be squeezed.
    /// @param accountId The ID of the account receiving streams to squeeze funds for.
    /// @param erc20 The used ERC-20 token.
    /// It must preserve amounts, so if some amount of tokens is transferred to
    /// an address, then later the same amount must be transferable from that address.
    /// Tokens which rebase the holders' balances, collect taxes on transfers,
    /// or impose any restrictions on holding or transferring tokens are not supported.
    /// If you use such tokens in the protocol, they can get stuck or lost.
    /// @param senderId The ID of the streaming account to squeeze funds from.
    /// @param historyHash The sender's history hash that was valid right before
    /// they set up the sequence of configurations described by `streamsHistory`.
    /// @param streamsHistory The sequence of the sender's streams configurations.
    /// It can start at an arbitrary past configuration, but must describe all the configurations
    /// which have been used since then including the current one, in the chronological order.
    /// Only streams described by `streamsHistory` will be squeezed.
    /// If `streamsHistory` entries have no receivers, they won't be squeezed.
    /// @return amt The squeezed amount.
    function squeezeStreams(
        uint256 accountId,
        IERC20 erc20,
        uint256 senderId,
        bytes32 historyHash,
        StreamsHistory[] memory streamsHistory
    ) public whenNotPaused returns (uint128 amt) {
        amt = Streams._squeezeStreams(accountId, erc20, senderId, historyHash, streamsHistory);
        if (amt != 0) {
            _moveBalanceFromStreamsToSplits(erc20, amt);
            Splits._addSplittable(accountId, erc20, amt);
        }
    }

    /// @notice Calculate effects of calling `squeezeStreams` with the given parameters.
    /// See its documentation for more details.
    /// @param accountId The ID of the account receiving streams to squeeze funds for.
    /// @param erc20 The used ERC-20 token.
    /// It must preserve amounts, so if some amount of tokens is transferred to
    /// an address, then later the same amount must be transferable from that address.
    /// Tokens which rebase the holders' balances, collect taxes on transfers,
    /// or impose any restrictions on holding or transferring tokens are not supported.
    /// If you use such tokens in the protocol, they can get stuck or lost.
    /// @param senderId The ID of the streaming account to squeeze funds from.
    /// @param historyHash The sender's history hash that was valid right before `streamsHistory`.
    /// @param streamsHistory The sequence of the sender's streams configurations.
    /// @return amt The squeezed amount.
    function squeezeStreamsResult(
        uint256 accountId,
        IERC20 erc20,
        uint256 senderId,
        bytes32 historyHash,
        StreamsHistory[] memory streamsHistory
    ) public view returns (uint128 amt) {
        (amt,,,,) =
            Streams._squeezeStreamsResult(accountId, erc20, senderId, historyHash, streamsHistory);
    }

    /// @notice Returns account's received but not split yet funds.
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// It must preserve amounts, so if some amount of tokens is transferred to
    /// an address, then later the same amount must be transferable from that address.
    /// Tokens which rebase the holders' balances, collect taxes on transfers,
    /// or impose any restrictions on holding or transferring tokens are not supported.
    /// If you use such tokens in the protocol, they can get stuck or lost.
    /// @return amt The amount received but not split yet.
    function splittable(uint256 accountId, IERC20 erc20) public view returns (uint128 amt) {
        return Splits._splittable(accountId, erc20);
    }

    /// @notice Calculate the result of splitting an amount using the current splits configuration.
    /// @param accountId The account ID.
    /// @param currReceivers The list of the account's current splits receivers.
    /// It must be exactly the same as the last list set for the account with `setSplits`.
    /// @param amount The amount being split.
    /// @return collectableAmt The amount made collectable for the account
    /// on top of what was collectable before.
    /// @return splitAmt The amount split to the account's splits receivers
    function splitResult(uint256 accountId, SplitsReceiver[] memory currReceivers, uint128 amount)
        public
        view
        returns (uint128 collectableAmt, uint128 splitAmt)
    {
        return Splits._splitResult(accountId, currReceivers, amount);
    }

    /// @notice Splits the account's splittable funds among receivers.
    /// The entire splittable balance of the given ERC-20 token is split.
    /// All split funds are split using the current splits configuration.
    /// Because the account can update their splits configuration at any time,
    /// it is possible that calling this function will be frontrun,
    /// and all the splittable funds will become splittable only using the new configuration.
    /// The account must be trusted with how funds sent to them will be splits,
    /// in the end they can do with their funds whatever they want by changing the configuration.
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// It must preserve amounts, so if some amount of tokens is transferred to
    /// an address, then later the same amount must be transferable from that address.
    /// Tokens which rebase the holders' balances, collect taxes on transfers,
    /// or impose any restrictions on holding or transferring tokens are not supported.
    /// If you use such tokens in the protocol, they can get stuck or lost.
    /// @param currReceivers The list of the account's current splits receivers.
    /// It must be exactly the same as the last list set for the account with `setSplits`.
    /// @return collectableAmt The amount made collectable for the account
    /// on top of what was collectable before.
    /// @return splitAmt The amount split to the account's splits receivers
    function split(uint256 accountId, IERC20 erc20, SplitsReceiver[] memory currReceivers)
        public
        whenNotPaused
        returns (uint128 collectableAmt, uint128 splitAmt)
    {
        return Splits._split(accountId, erc20, currReceivers);
    }

    /// @notice Returns account's received funds already split and ready to be collected.
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// It must preserve amounts, so if some amount of tokens is transferred to
    /// an address, then later the same amount must be transferable from that address.
    /// Tokens which rebase the holders' balances, collect taxes on transfers,
    /// or impose any restrictions on holding or transferring tokens are not supported.
    /// If you use such tokens in the protocol, they can get stuck or lost.
    /// @return amt The collectable amount.
    function collectable(uint256 accountId, IERC20 erc20) public view returns (uint128 amt) {
        return Splits._collectable(accountId, erc20);
    }

    /// @notice Collects account's received already split funds and makes them withdrawable.
    /// Anybody can call `withdraw`, so all withdrawable funds should be withdrawn
    /// or used in the protocol before any 3rd parties have a chance to do that.
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// It must preserve amounts, so if some amount of tokens is transferred to
    /// an address, then later the same amount must be transferable from that address.
    /// Tokens which rebase the holders' balances, collect taxes on transfers,
    /// or impose any restrictions on holding or transferring tokens are not supported.
    /// If you use such tokens in the protocol, they can get stuck or lost.
    /// @return amt The collected amount
    function collect(uint256 accountId, IERC20 erc20)
        public
        whenNotPaused
        onlyDriver(accountId)
        returns (uint128 amt)
    {
        amt = Splits._collect(accountId, erc20);
        if (amt != 0) _decreaseSplitsBalance(erc20, amt);
    }

    /// @notice Gives funds from the account to the receiver.
    /// The receiver can split and collect them immediately.
    /// Requires that the tokens used to give are already sent to Drips and are withdrawable.
    /// Anybody can call `withdraw`, so all withdrawable funds should be withdrawn
    /// or used in the protocol before any 3rd parties have a chance to do that.
    /// @param accountId The account ID.
    /// @param receiver The receiver account ID.
    /// @param erc20 The used ERC-20 token.
    /// It must preserve amounts, so if some amount of tokens is transferred to
    /// an address, then later the same amount must be transferable from that address.
    /// Tokens which rebase the holders' balances, collect taxes on transfers,
    /// or impose any restrictions on holding or transferring tokens are not supported.
    /// If you use such tokens in the protocol, they can get stuck or lost.
    /// @param amt The given amount
    function give(uint256 accountId, uint256 receiver, IERC20 erc20, uint128 amt)
        public
        whenNotPaused
        onlyDriver(accountId)
    {
        if (amt != 0) _increaseSplitsBalance(erc20, amt);
        Splits._give(accountId, receiver, erc20, amt);
    }

    /// @notice Current account streams state.
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// It must preserve amounts, so if some amount of tokens is transferred to
    /// an address, then later the same amount must be transferable from that address.
    /// Tokens which rebase the holders' balances, collect taxes on transfers,
    /// or impose any restrictions on holding or transferring tokens are not supported.
    /// If you use such tokens in the protocol, they can get stuck or lost.
    /// @return streamsHash The current streams receivers list hash, see `hashStreams`
    /// @return streamsHistoryHash The current streams history hash, see `hashStreamsHistory`.
    /// @return updateTime The time when streams have been configured for the last time.
    /// @return balance The balance when streams have been configured for the last time.
    /// @return maxEnd The current maximum end time of streaming.
    function streamsState(uint256 accountId, IERC20 erc20)
        public
        view
        returns (
            bytes32 streamsHash,
            bytes32 streamsHistoryHash,
            uint32 updateTime,
            uint128 balance,
            uint32 maxEnd
        )
    {
        return Streams._streamsState(accountId, erc20);
    }

    /// @notice The account's streams balance at the given timestamp.
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// It must preserve amounts, so if some amount of tokens is transferred to
    /// an address, then later the same amount must be transferable from that address.
    /// Tokens which rebase the holders' balances, collect taxes on transfers,
    /// or impose any restrictions on holding or transferring tokens are not supported.
    /// If you use such tokens in the protocol, they can get stuck or lost.
    /// @param currReceivers The current streams receivers list.
    /// It must be exactly the same as the last list set for the account with `setStreams`.
    /// @param timestamp The timestamps for which balance should be calculated.
    /// It can't be lower than the timestamp of the last call to `setStreams`.
    /// If it's bigger than `block.timestamp`, then it's a prediction assuming
    /// that `setStreams` won't be called before `timestamp`.
    /// @return balance The account balance on `timestamp`
    function balanceAt(
        uint256 accountId,
        IERC20 erc20,
        StreamReceiver[] memory currReceivers,
        uint32 timestamp
    ) public view returns (uint128 balance) {
        return Streams._balanceAt(accountId, erc20, currReceivers, timestamp);
    }

    /// @notice Sets the account's streams configuration.
    /// Requires that the tokens used to increase the streams balance
    /// are already sent to Drips and are withdrawable.
    /// If the streams balance is decreased, the released tokens become withdrawable.
    /// Anybody can call `withdraw`, so all withdrawable funds should be withdrawn
    /// or used in the protocol before any 3rd parties have a chance to do that.
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// It must preserve amounts, so if some amount of tokens is transferred to
    /// an address, then later the same amount must be transferable from that address.
    /// Tokens which rebase the holders' balances, collect taxes on transfers,
    /// or impose any restrictions on holding or transferring tokens are not supported.
    /// If you use such tokens in the protocol, they can get stuck or lost.
    /// @param currReceivers The current streams receivers list.
    /// It must be exactly the same as the last list set for the account with `setStreams`.
    /// If this is the first update, pass an empty array.
    /// @param balanceDelta The streams balance change to be applied.
    /// Positive to add funds to the streams balance, negative to remove them.
    /// @param newReceivers The list of the streams receivers of the account to be set.
    /// Must be sorted by the receivers' addresses, deduplicated and without 0 amtPerSecs.
    /// @param maxEndHint1 An optional parameter allowing gas optimization, pass `0` to ignore it.
    /// The first hint for finding the maximum end time when all streams stop due to funds
    /// running out after the balance is updated and the new receivers list is applied.
    /// Hints have no effect on the results of calling this function, except potentially saving gas.
    /// Hints are Unix timestamps used as the starting points for binary search for the time
    /// when funds run out in the range of timestamps from the current block's to `2^32`.
    /// Hints lower than the current timestamp are ignored.
    /// You can provide zero, one or two hints. The order of hints doesn't matter.
    /// Hints are the most effective when one of them is lower than or equal to
    /// the last timestamp when funds are still streamed, and the other one is strictly larger
    /// than that timestamp,the smaller the difference between such hints, the higher gas savings.
    /// The savings are the highest possible when one of the hints is equal to
    /// the last timestamp when funds are still streamed, and the other one is larger by 1.
    /// It's worth noting that the exact timestamp of the block in which this function is executed
    /// may affect correctness of the hints, especially if they're precise.
    /// Hints don't provide any benefits when balance is not enough to cover
    /// a single second of streaming or is enough to cover all streams until timestamp `2^32`.
    /// Even inaccurate hints can be useful, and providing a single hint
    /// or two hints that don't enclose the time when funds run out can still save some gas.
    /// Providing poor hints that don't reduce the number of binary search steps
    /// may cause slightly higher gas usage than not providing any hints.
    /// @param maxEndHint2 An optional parameter allowing gas optimization, pass `0` to ignore it.
    /// The second hint for finding the maximum end time, see `maxEndHint1` docs for more details.
    /// @return realBalanceDelta The actually applied streams balance change.
    /// If it's lower than zero, it's the negative of the amount that became withdrawable.
    function setStreams(
        uint256 accountId,
        IERC20 erc20,
        StreamReceiver[] memory currReceivers,
        int128 balanceDelta,
        StreamReceiver[] memory newReceivers,
        // slither-disable-next-line similar-names
        uint32 maxEndHint1,
        uint32 maxEndHint2
    ) public whenNotPaused onlyDriver(accountId) returns (int128 realBalanceDelta) {
        if (balanceDelta > 0) _increaseStreamsBalance(erc20, uint128(balanceDelta));
        realBalanceDelta = Streams._setStreams(
            accountId, erc20, currReceivers, balanceDelta, newReceivers, maxEndHint1, maxEndHint2
        );
        if (realBalanceDelta < 0) _decreaseStreamsBalance(erc20, uint128(-realBalanceDelta));
    }

    /// @notice Calculates the hash of the streams configuration.
    /// It's used to verify if streams configuration is the previously set one.
    /// @param receivers The list of the streams receivers.
    /// Must be sorted by the receivers' addresses, deduplicated and without 0 amtPerSecs.
    /// If the streams have never been updated, pass an empty array.
    /// @return streamsHash The hash of the streams configuration
    function hashStreams(StreamReceiver[] memory receivers)
        public
        pure
        returns (bytes32 streamsHash)
    {
        return Streams._hashStreams(receivers);
    }

    /// @notice Calculates the hash of the streams history
    /// after the streams configuration is updated.
    /// @param oldStreamsHistoryHash The history hash
    /// that was valid before the streams were updated.
    /// The `streamsHistoryHash` of the account before they set streams for the first time is `0`.
    /// @param streamsHash The hash of the streams receivers being set.
    /// @param updateTime The timestamp when the streams were updated.
    /// @param maxEnd The maximum end of the streams being set.
    /// @return streamsHistoryHash The hash of the updated streams history.
    function hashStreamsHistory(
        bytes32 oldStreamsHistoryHash,
        bytes32 streamsHash,
        uint32 updateTime,
        uint32 maxEnd
    ) public pure returns (bytes32 streamsHistoryHash) {
        return Streams._hashStreamsHistory(oldStreamsHistoryHash, streamsHash, updateTime, maxEnd);
    }

    /// @notice Sets the account splits configuration.
    /// The configuration is common for all ERC-20 tokens.
    /// Nothing happens to the currently splittable funds, but when they are split
    /// after this function finishes, the new splits configuration will be used.
    /// Because anybody can call `split`, calling this function may be frontrun
    /// and all the currently splittable funds will be split using the old splits configuration.
    /// @param accountId The account ID.
    /// @param receivers The list of the account's splits receivers to be set.
    /// Must be sorted by the splits receivers' addresses, deduplicated and without 0 weights.
    /// Each splits receiver will be getting `weight / TOTAL_SPLITS_WEIGHT`
    /// share of the funds collected by the account.
    /// If the sum of weights of all receivers is less than `_TOTAL_SPLITS_WEIGHT`,
    /// some funds won't be split, but they will be left for the account to collect.
    /// It's valid to include the account's own `accountId` in the list of receivers,
    /// but funds split to themselves return to their splittable balance and are not collectable.
    /// This is usually unwanted, because if splitting is repeated,
    /// funds split to themselves will be again split using the current configuration.
    /// Splitting 100% to self effectively blocks splitting unless the configuration is updated.
    function setSplits(uint256 accountId, SplitsReceiver[] memory receivers)
        public
        whenNotPaused
        onlyDriver(accountId)
    {
        Splits._setSplits(accountId, receivers);
    }

    /// @notice Current account's splits hash, see `hashSplits`.
    /// @param accountId The account ID.
    /// @return currSplitsHash The current account's splits hash
    function splitsHash(uint256 accountId) public view returns (bytes32 currSplitsHash) {
        return Splits._splitsHash(accountId);
    }

    /// @notice Calculates the hash of the list of splits receivers.
    /// @param receivers The list of the splits receivers.
    /// Must be sorted by the splits receivers' addresses, deduplicated and without 0 weights.
    /// @return receiversHash The hash of the list of splits receivers.
    function hashSplits(SplitsReceiver[] memory receivers)
        public
        pure
        returns (bytes32 receiversHash)
    {
        return Splits._hashSplits(receivers);
    }

    /// @notice Emits account metadata.
    /// The keys and the values are not standardized by the protocol, it's up to the users
    /// to establish and follow conventions to ensure compatibility with the consumers.
    /// @param accountId The account ID.
    /// @param accountMetadata The list of account metadata.
    function emitAccountMetadata(uint256 accountId, AccountMetadata[] calldata accountMetadata)
        public
        whenNotPaused
        onlyDriver(accountId)
    {
        unchecked {
            for (uint256 i = 0; i < accountMetadata.length; i++) {
                AccountMetadata calldata metadata = accountMetadata[i];
                emit AccountMetadataEmitted(accountId, metadata.key, metadata.value);
            }
        }
    }

    /// @notice Returns the Drips storage.
    /// @return storageRef The storage.
    function _dripsStorage() internal view returns (DripsStorage storage storageRef) {
        bytes32 slot = _dripsStorageSlot;
        // slither-disable-next-line assembly
        assembly {
            storageRef.slot := slot
        }
    }
}

File 2 of 17 : Streams.sol
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.20;

import {IERC20} from "openzeppelin-contracts/token/ERC20/IERC20.sol";

/// @notice A stream receiver
struct StreamReceiver {
    /// @notice The account ID.
    uint256 accountId;
    /// @notice The stream configuration.
    StreamConfig config;
}

/// @notice The sender streams history entry, used when squeezing streams.
struct StreamsHistory {
    /// @notice Streams receivers list hash, see `_hashStreams`.
    /// If it's non-zero, `receivers` must be empty.
    bytes32 streamsHash;
    /// @notice The streams receivers. If it's non-empty, `streamsHash` must be `0`.
    /// If it's empty, this history entry will be skipped when squeezing streams
    /// and `streamsHash` will be used when verifying the streams history validity.
    /// Skipping a history entry allows cutting gas usage on analysis
    /// of parts of the streams history which are not worth squeezing.
    /// The hash of an empty receivers list is `0`, so when the sender updates
    /// their receivers list to be empty, the new `StreamsHistory` entry will have
    /// both the `streamsHash` equal to `0` and the `receivers` empty making it always skipped.
    /// This is fine, because there can't be any funds to squeeze from that entry anyway.
    StreamReceiver[] receivers;
    /// @notice The time when streams have been configured
    uint32 updateTime;
    /// @notice The maximum end time of streaming.
    uint32 maxEnd;
}

/// @notice Describes a streams configuration.
/// It's a 256-bit integer constructed by concatenating the configuration parameters:
/// `streamId (32 bits) | amtPerSec (160 bits) | start (32 bits) | duration (32 bits)`.
/// `streamId` is an arbitrary number used to identify a stream.
/// It's a part of the configuration but the protocol doesn't use it.
/// `amtPerSec` is the amount per second being streamed. Must never be zero.
/// It must have additional `Streams._AMT_PER_SEC_EXTRA_DECIMALS` decimals and can have fractions.
/// To achieve that its value must be multiplied by `Streams._AMT_PER_SEC_MULTIPLIER`.
/// `start` is the timestamp when streaming should start.
/// If zero, use the timestamp when the stream is configured.
/// `duration` is the duration of streaming.
/// If zero, stream until balance runs out.
type StreamConfig is uint256;

using StreamConfigImpl for StreamConfig global;

library StreamConfigImpl {
    /// @notice Create a new StreamConfig.
    /// @param streamId_ An arbitrary number used to identify a stream.
    /// It's a part of the configuration but the protocol doesn't use it.
    /// @param amtPerSec_ The amount per second being streamed. Must never be zero.
    /// It must have additional `Streams._AMT_PER_SEC_EXTRA_DECIMALS`
    /// decimals and can have fractions.
    /// To achieve that the passed value must be multiplied by `Streams._AMT_PER_SEC_MULTIPLIER`.
    /// @param start_ The timestamp when streaming should start.
    /// If zero, use the timestamp when the stream is configured.
    /// @param duration_ The duration of streaming. If zero, stream until the balance runs out.
    function create(uint32 streamId_, uint160 amtPerSec_, uint32 start_, uint32 duration_)
        internal
        pure
        returns (StreamConfig)
    {
        // By assignment we get `config` value:
        // `zeros (224 bits) | streamId (32 bits)`
        uint256 config = streamId_;
        // By bit shifting we get `config` value:
        // `zeros (64 bits) | streamId (32 bits) | zeros (160 bits)`
        // By bit masking we get `config` value:
        // `zeros (64 bits) | streamId (32 bits) | amtPerSec (160 bits)`
        config = (config << 160) | amtPerSec_;
        // By bit shifting we get `config` value:
        // `zeros (32 bits) | streamId (32 bits) | amtPerSec (160 bits) | zeros (32 bits)`
        // By bit masking we get `config` value:
        // `zeros (32 bits) | streamId (32 bits) | amtPerSec (160 bits) | start (32 bits)`
        config = (config << 32) | start_;
        // By bit shifting we get `config` value:
        // `streamId (32 bits) | amtPerSec (160 bits) | start (32 bits) | zeros (32 bits)`
        // By bit masking we get `config` value:
        // `streamId (32 bits) | amtPerSec (160 bits) | start (32 bits) | duration (32 bits)`
        config = (config << 32) | duration_;
        return StreamConfig.wrap(config);
    }

    /// @notice Extracts streamId from a `StreamConfig`
    function streamId(StreamConfig config) internal pure returns (uint32) {
        // `config` has value:
        // `streamId (32 bits) | amtPerSec (160 bits) | start (32 bits) | duration (32 bits)`
        // By bit shifting we get value:
        // `zeros (224 bits) | streamId (32 bits)`
        // By casting down we get value:
        // `streamId (32 bits)`
        return uint32(StreamConfig.unwrap(config) >> 224);
    }

    /// @notice Extracts amtPerSec from a `StreamConfig`
    function amtPerSec(StreamConfig config) internal pure returns (uint160) {
        // `config` has value:
        // `streamId (32 bits) | amtPerSec (160 bits) | start (32 bits) | duration (32 bits)`
        // By bit shifting we get value:
        // `zeros (64 bits) | streamId (32 bits) | amtPerSec (160 bits)`
        // By casting down we get value:
        // `amtPerSec (160 bits)`
        return uint160(StreamConfig.unwrap(config) >> 64);
    }

    /// @notice Extracts start from a `StreamConfig`
    function start(StreamConfig config) internal pure returns (uint32) {
        // `config` has value:
        // `streamId (32 bits) | amtPerSec (160 bits) | start (32 bits) | duration (32 bits)`
        // By bit shifting we get value:
        // `zeros (32 bits) | streamId (32 bits) | amtPerSec (160 bits) | start (32 bits)`
        // By casting down we get value:
        // `start (32 bits)`
        return uint32(StreamConfig.unwrap(config) >> 32);
    }

    /// @notice Extracts duration from a `StreamConfig`
    function duration(StreamConfig config) internal pure returns (uint32) {
        // `config` has value:
        // `streamId (32 bits) | amtPerSec (160 bits) | start (32 bits) | duration (32 bits)`
        // By casting down we get value:
        // `duration (32 bits)`
        return uint32(StreamConfig.unwrap(config));
    }

    /// @notice Compares two `StreamConfig`s.
    /// First compares `streamId`s, then `amtPerSec`s, then `start`s and finally `duration`s.
    /// @return isLower True if `config` is strictly lower than `otherConfig`.
    function lt(StreamConfig config, StreamConfig otherConfig)
        internal
        pure
        returns (bool isLower)
    {
        // Both configs have value:
        // `streamId (32 bits) | amtPerSec (160 bits) | start (32 bits) | duration (32 bits)`
        // Comparing them as integers is equivalent to comparing their fields from left to right.
        return StreamConfig.unwrap(config) < StreamConfig.unwrap(otherConfig);
    }
}

/// @notice Streams can keep track of at most `type(int128).max`
/// which is `2 ^ 127 - 1` units of each ERC-20 token.
/// It's up to the caller to guarantee that this limit is never exceeded,
/// failing to do so may result in a total protocol collapse.
abstract contract Streams {
    /// @notice Maximum number of streams receivers of a single account.
    /// Limits cost of changes in streams configuration.
    uint256 internal constant _MAX_STREAMS_RECEIVERS = 100;
    /// @notice The additional decimals for all amtPerSec values.
    uint8 internal constant _AMT_PER_SEC_EXTRA_DECIMALS = 9;
    /// @notice The multiplier for all amtPerSec values. It's `10 ** _AMT_PER_SEC_EXTRA_DECIMALS`.
    uint160 internal constant _AMT_PER_SEC_MULTIPLIER = 1_000_000_000;
    /// @notice The amount the contract can keep track of each ERC-20 token.
    uint128 internal constant _MAX_STREAMS_BALANCE = uint128(type(int128).max);
    /// @notice On every timestamp `T`, which is a multiple of `cycleSecs`, the receivers
    /// gain access to streams received during `T - cycleSecs` to `T - 1`.
    /// Always higher than 1.
    // slither-disable-next-line naming-convention
    uint32 internal immutable _cycleSecs;
    /// @notice The minimum amtPerSec of a stream. It's 1 token per cycle.
    // slither-disable-next-line naming-convention
    uint160 internal immutable _minAmtPerSec;
    /// @notice The storage slot holding a single `StreamsStorage` structure.
    bytes32 private immutable _streamsStorageSlot;

    /// @notice Emitted when the streams configuration of an account is updated.
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// @param receiversHash The streams receivers list hash
    /// @param streamsHistoryHash The streams history hash that was valid right before the update.
    /// @param balance The account's streams balance. These funds will be streamed to the receivers.
    /// @param maxEnd The maximum end time of streaming, when funds run out.
    /// If funds run out after the timestamp `type(uint32).max`, it's set to `type(uint32).max`.
    /// If the balance is 0 or there are no receivers, it's set to the current timestamp.
    event StreamsSet(
        uint256 indexed accountId,
        IERC20 indexed erc20,
        bytes32 indexed receiversHash,
        bytes32 streamsHistoryHash,
        uint128 balance,
        uint32 maxEnd
    );

    /// @notice Emitted when an account is seen in a streams receivers list.
    /// @param receiversHash The streams receivers list hash
    /// @param accountId The account ID.
    /// @param config The streams configuration.
    event StreamReceiverSeen(
        bytes32 indexed receiversHash, uint256 indexed accountId, StreamConfig config
    );

    /// @notice Emitted when streams are received.
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// @param amt The received amount.
    /// @param receivableCycles The number of cycles which still can be received.
    event ReceivedStreams(
        uint256 indexed accountId, IERC20 indexed erc20, uint128 amt, uint32 receivableCycles
    );

    /// @notice Emitted when streams are squeezed.
    /// @param accountId The squeezing account ID.
    /// @param erc20 The used ERC-20 token.
    /// @param senderId The ID of the streaming account from whom funds are squeezed.
    /// @param amt The squeezed amount.
    /// @param streamsHistoryHashes The history hashes of all squeezed streams history entries.
    /// Each history hash matches `streamsHistoryHash` emitted in its `StreamsSet`
    /// when the squeezed streams configuration was set.
    /// Sorted in the oldest streams configuration to the newest.
    event SqueezedStreams(
        uint256 indexed accountId,
        IERC20 indexed erc20,
        uint256 indexed senderId,
        uint128 amt,
        bytes32[] streamsHistoryHashes
    );

    struct StreamsStorage {
        /// @notice Account streams states.
        mapping(IERC20 erc20 => mapping(uint256 accountId => StreamsState)) states;
    }

    struct StreamsState {
        /// @notice The streams history hash, see `_hashStreamsHistory`.
        bytes32 streamsHistoryHash;
        /// @notice The next squeezable timestamps.
        /// Each `N`th element of the array is the next squeezable timestamp
        /// of the `N`th sender's streams configuration in effect in the current cycle.
        mapping(uint256 accountId => uint32[2 ** 32]) nextSqueezed;
        /// @notice The streams receivers list hash, see `_hashStreams`.
        bytes32 streamsHash;
        /// @notice The next cycle to be received
        uint32 nextReceivableCycle;
        /// @notice The time when streams have been configured for the last time.
        uint32 updateTime;
        /// @notice The maximum end time of streaming.
        uint32 maxEnd;
        /// @notice The balance when streams have been configured for the last time.
        uint128 balance;
        /// @notice The number of streams configurations seen in the current cycle
        uint32 currCycleConfigs;
        /// @notice The changes of received amounts on specific cycle.
        /// The keys are cycles, each cycle `C` becomes receivable on timestamp `C * cycleSecs`.
        /// Values for cycles before `nextReceivableCycle` are guaranteed to be zeroed.
        /// This means that the value of `amtDeltas[nextReceivableCycle].thisCycle` is always
        /// relative to 0 or in other words it's an absolute value independent from other cycles.
        mapping(uint32 cycle => AmtDelta) amtDeltas;
    }

    struct AmtDelta {
        /// @notice Amount delta applied on this cycle
        int128 thisCycle;
        /// @notice Amount delta applied on the next cycle
        int128 nextCycle;
    }

    /// @param cycleSecs The length of cycleSecs to be used in the contract instance.
    /// Low value makes funds more available by shortening the average time
    /// of funds being frozen between being taken from the accounts'
    /// streams balance and being receivable by their receivers.
    /// High value makes receiving cheaper by making it process less cycles for a given time range.
    /// Must be higher than 1.
    /// @param streamsStorageSlot The storage slot to holding a single `StreamsStorage` structure.
    constructor(uint32 cycleSecs, bytes32 streamsStorageSlot) {
        require(cycleSecs > 1, "Cycle length too low");
        _cycleSecs = cycleSecs;
        _minAmtPerSec = (_AMT_PER_SEC_MULTIPLIER + cycleSecs - 1) / cycleSecs;
        _streamsStorageSlot = streamsStorageSlot;
    }

    /// @notice Receive streams from unreceived cycles of the account.
    /// Received streams cycles won't need to be analyzed ever again.
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// @param maxCycles The maximum number of received streams cycles.
    /// If too low, receiving will be cheap, but may not cover many cycles.
    /// If too high, receiving may become too expensive to fit in a single transaction.
    /// @return receivedAmt The received amount
    function _receiveStreams(uint256 accountId, IERC20 erc20, uint32 maxCycles)
        internal
        returns (uint128 receivedAmt)
    {
        uint32 receivableCycles;
        uint32 fromCycle;
        uint32 toCycle;
        int128 finalAmtPerCycle;
        (receivedAmt, receivableCycles, fromCycle, toCycle, finalAmtPerCycle) =
            _receiveStreamsResult(accountId, erc20, maxCycles);
        if (fromCycle != toCycle) {
            StreamsState storage state = _streamsStorage().states[erc20][accountId];
            state.nextReceivableCycle = toCycle;
            mapping(uint32 cycle => AmtDelta) storage amtDeltas = state.amtDeltas;
            unchecked {
                for (uint32 cycle = fromCycle; cycle < toCycle; cycle++) {
                    delete amtDeltas[cycle];
                }
                // The next cycle delta must be relative to the last received cycle, which deltas
                // got zeroed. In other words the next cycle delta must be an absolute value.
                if (finalAmtPerCycle != 0) {
                    amtDeltas[toCycle].thisCycle += finalAmtPerCycle;
                }
            }
        }
        emit ReceivedStreams(accountId, erc20, receivedAmt, receivableCycles);
    }

    /// @notice Calculate effects of calling `_receiveStreams` with the given parameters.
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// @param maxCycles The maximum number of received streams cycles.
    /// If too low, receiving will be cheap, but may not cover many cycles.
    /// If too high, receiving may become too expensive to fit in a single transaction.
    /// @return receivedAmt The amount which would be received
    /// @return receivableCycles The number of cycles which would still be receivable after the call
    /// @return fromCycle The cycle from which funds would be received
    /// @return toCycle The cycle to which funds would be received
    /// @return amtPerCycle The amount per cycle when `toCycle` starts.
    function _receiveStreamsResult(uint256 accountId, IERC20 erc20, uint32 maxCycles)
        internal
        view
        returns (
            uint128 receivedAmt,
            uint32 receivableCycles,
            uint32 fromCycle,
            uint32 toCycle,
            int128 amtPerCycle
        )
    {
        unchecked {
            (fromCycle, toCycle) = _receivableStreamsCyclesRange(accountId, erc20);
            if (toCycle - fromCycle > maxCycles) {
                receivableCycles = toCycle - fromCycle - maxCycles;
                toCycle -= receivableCycles;
            }
            mapping(uint32 cycle => AmtDelta) storage amtDeltas =
                _streamsStorage().states[erc20][accountId].amtDeltas;
            for (uint32 cycle = fromCycle; cycle < toCycle; cycle++) {
                AmtDelta memory amtDelta = amtDeltas[cycle];
                amtPerCycle += amtDelta.thisCycle;
                receivedAmt += uint128(amtPerCycle);
                amtPerCycle += amtDelta.nextCycle;
            }
        }
    }

    /// @notice Counts cycles from which streams can be received.
    /// This function can be used to detect that there are
    /// too many cycles to analyze in a single transaction.
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// @return cycles The number of cycles which can be flushed
    function _receivableStreamsCycles(uint256 accountId, IERC20 erc20)
        internal
        view
        returns (uint32 cycles)
    {
        unchecked {
            (uint32 fromCycle, uint32 toCycle) = _receivableStreamsCyclesRange(accountId, erc20);
            return toCycle - fromCycle;
        }
    }

    /// @notice Calculates the cycles range from which streams can be received.
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// @return fromCycle The cycle from which funds can be received
    /// @return toCycle The cycle to which funds can be received
    function _receivableStreamsCyclesRange(uint256 accountId, IERC20 erc20)
        private
        view
        returns (uint32 fromCycle, uint32 toCycle)
    {
        fromCycle = _streamsStorage().states[erc20][accountId].nextReceivableCycle;
        toCycle = _cycleOf(_currTimestamp());
        // slither-disable-next-line timestamp
        if (fromCycle == 0 || toCycle < fromCycle) {
            toCycle = fromCycle;
        }
    }

    /// @notice Receive streams from the currently running cycle from a single sender.
    /// It doesn't receive streams from the finished cycles, to do that use `_receiveStreams`.
    /// Squeezed funds won't be received in the next calls
    /// to `_squeezeStreams` or `_receiveStreams`.
    /// Only funds streamed before `block.timestamp` can be squeezed.
    /// @param accountId The ID of the account receiving streams to squeeze funds for.
    /// @param erc20 The used ERC-20 token.
    /// @param senderId The ID of the streaming account to squeeze funds from.
    /// @param historyHash The sender's history hash that was valid right before
    /// they set up the sequence of configurations described by `streamsHistory`.
    /// @param streamsHistory The sequence of the sender's streams configurations.
    /// It can start at an arbitrary past configuration, but must describe all the configurations
    /// which have been used since then including the current one, in the chronological order.
    /// Only streams described by `streamsHistory` will be squeezed.
    /// If `streamsHistory` entries have no receivers, they won't be squeezed.
    /// @return amt The squeezed amount.
    function _squeezeStreams(
        uint256 accountId,
        IERC20 erc20,
        uint256 senderId,
        bytes32 historyHash,
        StreamsHistory[] memory streamsHistory
    ) internal returns (uint128 amt) {
        unchecked {
            uint256 squeezedNum;
            uint256[] memory squeezedRevIdxs;
            bytes32[] memory historyHashes;
            uint256 currCycleConfigs;
            (amt, squeezedNum, squeezedRevIdxs, historyHashes, currCycleConfigs) =
                _squeezeStreamsResult(accountId, erc20, senderId, historyHash, streamsHistory);
            bytes32[] memory squeezedHistoryHashes = new bytes32[](squeezedNum);
            StreamsState storage state = _streamsStorage().states[erc20][accountId];
            uint32[2 ** 32] storage nextSqueezed = state.nextSqueezed[senderId];
            for (uint256 i = 0; i < squeezedNum; i++) {
                // `squeezedRevIdxs` are sorted from the newest configuration to the oldest,
                // but we need to consume them from the oldest to the newest.
                uint256 revIdx = squeezedRevIdxs[squeezedNum - i - 1];
                squeezedHistoryHashes[i] = historyHashes[historyHashes.length - revIdx];
                nextSqueezed[currCycleConfigs - revIdx] = _currTimestamp();
            }
            uint32 cycleStart = _currCycleStart();
            _addDeltaRange(
                state, cycleStart, cycleStart + 1, -int160(amt * _AMT_PER_SEC_MULTIPLIER)
            );
            emit SqueezedStreams(accountId, erc20, senderId, amt, squeezedHistoryHashes);
        }
    }

    /// @notice Calculate effects of calling `_squeezeStreams` with the given parameters.
    /// See its documentation for more details.
    /// @param accountId The ID of the account receiving streams to squeeze funds for.
    /// @param erc20 The used ERC-20 token.
    /// @param senderId The ID of the streaming account to squeeze funds from.
    /// @param historyHash The sender's history hash that was valid right before `streamsHistory`.
    /// @param streamsHistory The sequence of the sender's streams configurations.
    /// @return amt The squeezed amount.
    /// @return squeezedNum The number of squeezed history entries.
    /// @return squeezedRevIdxs The indexes of the squeezed history entries.
    /// The indexes are reversed, meaning that to get the actual index in an array,
    /// they must counted from the end of arrays, as in `arrayLength - squeezedRevIdxs[i]`.
    /// These indexes can be safely used to access `streamsHistory`, `historyHashes`
    /// and `nextSqueezed` regardless of their lengths.
    /// `squeezeRevIdxs` is sorted ascending, from pointing at the most recent entry to the oldest.
    /// @return historyHashes The history hashes valid
    /// for squeezing each of `streamsHistory` entries.
    /// In other words history hashes which had been valid right before each streams
    /// configuration was set, matching `streamsHistoryHash` emitted in its `StreamsSet`.
    /// The first item is always equal to `historyHash`.
    /// @return currCycleConfigs The number of the sender's
    /// streams configurations which have been seen in the current cycle.
    /// This is also the number of used entries in each of the sender's `nextSqueezed` arrays.
    function _squeezeStreamsResult(
        uint256 accountId,
        IERC20 erc20,
        uint256 senderId,
        bytes32 historyHash,
        StreamsHistory[] memory streamsHistory
    )
        internal
        view
        returns (
            uint128 amt,
            uint256 squeezedNum,
            uint256[] memory squeezedRevIdxs,
            bytes32[] memory historyHashes,
            uint256 currCycleConfigs
        )
    {
        {
            StreamsState storage sender = _streamsStorage().states[erc20][senderId];
            historyHashes =
                _verifyStreamsHistory(historyHash, streamsHistory, sender.streamsHistoryHash);
            // If the last update was not in the current cycle,
            // there's only the single latest history entry to squeeze in the current cycle.
            currCycleConfigs = 1;
            // slither-disable-next-line timestamp
            if (sender.updateTime >= _currCycleStart()) currCycleConfigs = sender.currCycleConfigs;
        }
        squeezedRevIdxs = new uint256[](streamsHistory.length);
        uint32[2 ** 32] storage nextSqueezed =
            _streamsStorage().states[erc20][accountId].nextSqueezed[senderId];
        uint32 squeezeEndCap = _currTimestamp();
        unchecked {
            for (uint256 i = 1; i <= streamsHistory.length && i <= currCycleConfigs; i++) {
                StreamsHistory memory historyEntry = streamsHistory[streamsHistory.length - i];
                if (historyEntry.receivers.length != 0) {
                    uint32 squeezeStartCap = nextSqueezed[currCycleConfigs - i];
                    if (squeezeStartCap < _currCycleStart()) squeezeStartCap = _currCycleStart();
                    if (squeezeStartCap < historyEntry.updateTime) {
                        squeezeStartCap = historyEntry.updateTime;
                    }
                    if (squeezeStartCap < squeezeEndCap) {
                        squeezedRevIdxs[squeezedNum++] = i;
                        amt += _squeezedAmt(accountId, historyEntry, squeezeStartCap, squeezeEndCap);
                    }
                }
                squeezeEndCap = historyEntry.updateTime;
            }
        }
    }

    /// @notice Verify a streams history and revert if it's invalid.
    /// @param historyHash The account's history hash that was valid right before `streamsHistory`.
    /// @param streamsHistory The sequence of the account's streams configurations.
    /// @param finalHistoryHash The history hash at the end of `streamsHistory`.
    /// @return historyHashes The history hashes valid
    /// for squeezing each of `streamsHistory` entries.
    /// In other words history hashes which had been valid right before each streams
    /// configuration was set, matching `streamsHistoryHash`es emitted in `StreamsSet`.
    /// The first item is always equal to `historyHash` and `finalHistoryHash` is never included.
    function _verifyStreamsHistory(
        bytes32 historyHash,
        StreamsHistory[] memory streamsHistory,
        bytes32 finalHistoryHash
    ) private pure returns (bytes32[] memory historyHashes) {
        historyHashes = new bytes32[](streamsHistory.length);
        for (uint256 i = 0; i < streamsHistory.length; i++) {
            StreamsHistory memory historyEntry = streamsHistory[i];
            bytes32 streamsHash = historyEntry.streamsHash;
            if (historyEntry.receivers.length != 0) {
                require(streamsHash == 0, "Entry with hash and receivers");
                streamsHash = _hashStreams(historyEntry.receivers);
            }
            historyHashes[i] = historyHash;
            historyHash = _hashStreamsHistory(
                historyHash, streamsHash, historyEntry.updateTime, historyEntry.maxEnd
            );
        }
        // slither-disable-next-line incorrect-equality,timestamp
        require(historyHash == finalHistoryHash, "Invalid streams history");
    }

    /// @notice Calculate the amount squeezable by an account from a single streams history entry.
    /// @param accountId The ID of the account to squeeze streams for.
    /// @param historyEntry The squeezed history entry.
    /// @param squeezeStartCap The squeezed time range start.
    /// @param squeezeEndCap The squeezed time range end.
    /// @return squeezedAmt The squeezed amount.
    function _squeezedAmt(
        uint256 accountId,
        StreamsHistory memory historyEntry,
        uint32 squeezeStartCap,
        uint32 squeezeEndCap
    ) private view returns (uint128 squeezedAmt) {
        unchecked {
            StreamReceiver[] memory receivers = historyEntry.receivers;
            // Binary search for the `idx` of the first occurrence of `accountId`
            uint256 idx = 0;
            for (uint256 idxCap = receivers.length; idx < idxCap;) {
                uint256 idxMid = (idx + idxCap) / 2;
                if (receivers[idxMid].accountId < accountId) {
                    idx = idxMid + 1;
                } else {
                    idxCap = idxMid;
                }
            }
            uint32 updateTime = historyEntry.updateTime;
            uint32 maxEnd = historyEntry.maxEnd;
            uint256 amt = 0;
            for (; idx < receivers.length; idx++) {
                StreamReceiver memory receiver = receivers[idx];
                if (receiver.accountId != accountId) break;
                (uint32 start, uint32 end) =
                    _streamRange(receiver, updateTime, maxEnd, squeezeStartCap, squeezeEndCap);
                amt += _streamedAmt(receiver.config.amtPerSec(), start, end);
            }
            return uint128(amt);
        }
    }

    /// @notice Current account streams state.
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// @return streamsHash The current streams receivers list hash, see `_hashStreams`
    /// @return streamsHistoryHash The current streams history hash, see `_hashStreamsHistory`.
    /// @return updateTime The time when streams have been configured for the last time.
    /// @return balance The balance when streams have been configured for the last time.
    /// @return maxEnd The current maximum end time of streaming.
    function _streamsState(uint256 accountId, IERC20 erc20)
        internal
        view
        returns (
            bytes32 streamsHash,
            bytes32 streamsHistoryHash,
            uint32 updateTime,
            uint128 balance,
            uint32 maxEnd
        )
    {
        StreamsState storage state = _streamsStorage().states[erc20][accountId];
        return (
            state.streamsHash,
            state.streamsHistoryHash,
            state.updateTime,
            state.balance,
            state.maxEnd
        );
    }

    /// @notice The account's streams balance at the given timestamp.
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// @param currReceivers The current streams receivers list.
    /// It must be exactly the same as the last list set for the account with `_setStreams`.
    /// @param timestamp The timestamps for which balance should be calculated.
    /// It can't be lower than the timestamp of the last call to `_setStreams`.
    /// If it's bigger than `block.timestamp`, then it's a prediction assuming
    /// that `_setStreams` won't be called before `timestamp`.
    /// @return balance The account balance on `timestamp`
    function _balanceAt(
        uint256 accountId,
        IERC20 erc20,
        StreamReceiver[] memory currReceivers,
        uint32 timestamp
    ) internal view returns (uint128 balance) {
        StreamsState storage state = _streamsStorage().states[erc20][accountId];
        require(timestamp >= state.updateTime, "Timestamp before the last update");
        _verifyStreamsReceivers(currReceivers, state);
        return _calcBalance(state.balance, state.updateTime, state.maxEnd, currReceivers, timestamp);
    }

    /// @notice Calculates the streams balance at a given timestamp.
    /// @param lastBalance The balance when streaming started.
    /// @param lastUpdate The timestamp when streaming started.
    /// @param maxEnd The maximum end time of streaming.
    /// @param receivers The list of streams receivers.
    /// @param timestamp The timestamps for which balance should be calculated.
    /// It can't be lower than `lastUpdate`.
    /// If it's bigger than `block.timestamp`, then it's a prediction assuming
    /// that `_setStreams` won't be called before `timestamp`.
    /// @return balance The account balance on `timestamp`
    function _calcBalance(
        uint128 lastBalance,
        uint32 lastUpdate,
        uint32 maxEnd,
        StreamReceiver[] memory receivers,
        uint32 timestamp
    ) private view returns (uint128 balance) {
        unchecked {
            balance = lastBalance;
            for (uint256 i = 0; i < receivers.length; i++) {
                StreamReceiver memory receiver = receivers[i];
                (uint32 start, uint32 end) = _streamRange({
                    receiver: receiver,
                    updateTime: lastUpdate,
                    maxEnd: maxEnd,
                    startCap: lastUpdate,
                    endCap: timestamp
                });
                balance -= uint128(_streamedAmt(receiver.config.amtPerSec(), start, end));
            }
        }
    }

    /// @notice Sets the account's streams configuration.
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// @param currReceivers The current streams receivers list.
    /// It must be exactly the same as the last list set for the account with `_setStreams`.
    /// If this is the first update, pass an empty array.
    /// @param balanceDelta The streams balance change being applied.
    /// Positive when adding funds to the streams balance, negative to removing them.
    /// @param newReceivers The list of the streams receivers of the account to be set.
    /// Must be sorted, deduplicated and without 0 amtPerSecs.
    /// @param maxEndHint1 An optional parameter allowing gas optimization, pass `0` to ignore it.
    /// The first hint for finding the maximum end time when all streams stop due to funds
    /// running out after the balance is updated and the new receivers list is applied.
    /// Hints have no effect on the results of calling this function, except potentially saving gas.
    /// Hints are Unix timestamps used as the starting points for binary search for the time
    /// when funds run out in the range of timestamps from the current block's to `2^32`.
    /// Hints lower than the current timestamp are ignored.
    /// You can provide zero, one or two hints. The order of hints doesn't matter.
    /// Hints are the most effective when one of them is lower than or equal to
    /// the last timestamp when funds are still streamed, and the other one is strictly larger
    /// than that timestamp,the smaller the difference between such hints, the higher gas savings.
    /// The savings are the highest possible when one of the hints is equal to
    /// the last timestamp when funds are still streamed, and the other one is larger by 1.
    /// It's worth noting that the exact timestamp of the block in which this function is executed
    /// may affect correctness of the hints, especially if they're precise.
    /// Hints don't provide any benefits when balance is not enough to cover
    /// a single second of streaming or is enough to cover all streams until timestamp `2^32`.
    /// Even inaccurate hints can be useful, and providing a single hint
    /// or two hints that don't enclose the time when funds run out can still save some gas.
    /// Providing poor hints that don't reduce the number of binary search steps
    /// may cause slightly higher gas usage than not providing any hints.
    /// @param maxEndHint2 An optional parameter allowing gas optimization, pass `0` to ignore it.
    /// The second hint for finding the maximum end time, see `maxEndHint1` docs for more details.
    /// @return realBalanceDelta The actually applied streams balance change.
    function _setStreams(
        uint256 accountId,
        IERC20 erc20,
        StreamReceiver[] memory currReceivers,
        int128 balanceDelta,
        StreamReceiver[] memory newReceivers,
        // slither-disable-next-line similar-names
        uint32 maxEndHint1,
        uint32 maxEndHint2
    ) internal returns (int128 realBalanceDelta) {
        unchecked {
            StreamsState storage state = _streamsStorage().states[erc20][accountId];
            _verifyStreamsReceivers(currReceivers, state);
            uint32 lastUpdate = state.updateTime;
            uint128 newBalance;
            uint32 newMaxEnd;
            {
                uint32 currMaxEnd = state.maxEnd;
                int128 currBalance = int128(
                    _calcBalance(
                        state.balance, lastUpdate, currMaxEnd, currReceivers, _currTimestamp()
                    )
                );
                realBalanceDelta = balanceDelta;
                // Cap `realBalanceDelta` at withdrawal of the entire `currBalance`
                if (realBalanceDelta < -currBalance) {
                    realBalanceDelta = -currBalance;
                }
                newBalance = uint128(currBalance + realBalanceDelta);
                newMaxEnd = _calcMaxEnd(newBalance, newReceivers, maxEndHint1, maxEndHint2);
                _updateReceiverStates(
                    _streamsStorage().states[erc20],
                    currReceivers,
                    lastUpdate,
                    currMaxEnd,
                    newReceivers,
                    newMaxEnd
                );
            }
            state.updateTime = _currTimestamp();
            state.maxEnd = newMaxEnd;
            state.balance = newBalance;
            bytes32 streamsHistory = state.streamsHistoryHash;
            // slither-disable-next-line timestamp
            if (streamsHistory != 0 && _cycleOf(lastUpdate) != _cycleOf(_currTimestamp())) {
                state.currCycleConfigs = 2;
            } else {
                state.currCycleConfigs++;
            }
            bytes32 newStreamsHash = _hashStreams(newReceivers);
            state.streamsHistoryHash =
                _hashStreamsHistory(streamsHistory, newStreamsHash, _currTimestamp(), newMaxEnd);
            emit StreamsSet(accountId, erc20, newStreamsHash, streamsHistory, newBalance, newMaxEnd);
            // slither-disable-next-line timestamp
            if (newStreamsHash != state.streamsHash) {
                state.streamsHash = newStreamsHash;
                for (uint256 i = 0; i < newReceivers.length; i++) {
                    StreamReceiver memory receiver = newReceivers[i];
                    emit StreamReceiverSeen(newStreamsHash, receiver.accountId, receiver.config);
                }
            }
        }
    }

    /// @notice Verifies that the provided list of receivers is currently active for the account.
    /// @param currReceivers The verified list of receivers.
    /// @param state The account's state.
    function _verifyStreamsReceivers(
        StreamReceiver[] memory currReceivers,
        StreamsState storage state
    ) private view {
        require(_hashStreams(currReceivers) == state.streamsHash, "Invalid streams receivers list");
    }

    /// @notice Calculates the maximum end time of all streams.
    /// @param balance The balance when streaming starts.
    /// @param receivers The list of streams receivers.
    /// Must be sorted, deduplicated and without 0 amtPerSecs.
    /// @param hint1 The first hint for finding the maximum end time.
    /// See `_setStreams` docs for `maxEndHint1` for more details.
    /// @param hint2 The second hint for finding the maximum end time.
    /// See `_setStreams` docs for `maxEndHint2` for more details.
    /// @return maxEnd The maximum end time of streaming.
    function _calcMaxEnd(
        uint128 balance,
        StreamReceiver[] memory receivers,
        uint32 hint1,
        uint32 hint2
    ) private view returns (uint32 maxEnd) {
        (uint256[] memory configs, uint256 configsLen) = _buildConfigs(receivers);

        uint256 enoughEnd = _currTimestamp();
        // slither-disable-start incorrect-equality,timestamp
        if (configsLen == 0 || balance == 0) {
            return uint32(enoughEnd);
        }

        uint256 notEnoughEnd = type(uint32).max;
        if (_isBalanceEnough(balance, configs, configsLen, notEnoughEnd)) {
            return uint32(notEnoughEnd);
        }

        if (hint1 > enoughEnd && hint1 < notEnoughEnd) {
            if (_isBalanceEnough(balance, configs, configsLen, hint1)) {
                enoughEnd = hint1;
            } else {
                notEnoughEnd = hint1;
            }
        }

        if (hint2 > enoughEnd && hint2 < notEnoughEnd) {
            if (_isBalanceEnough(balance, configs, configsLen, hint2)) {
                enoughEnd = hint2;
            } else {
                notEnoughEnd = hint2;
            }
        }

        while (true) {
            uint256 end;
            unchecked {
                end = (enoughEnd + notEnoughEnd) / 2;
            }
            if (end == enoughEnd) {
                return uint32(end);
            }
            if (_isBalanceEnough(balance, configs, configsLen, end)) {
                enoughEnd = end;
            } else {
                notEnoughEnd = end;
            }
        }
        // slither-disable-end incorrect-equality,timestamp
    }

    /// @notice Check if a given balance is enough to cover all streams with the given `maxEnd`.
    /// @param balance The balance when streaming starts.
    /// @param configs The list of streams configurations.
    /// @param configsLen The length of `configs`.
    /// @param maxEnd The maximum end time of streaming.
    /// @return isEnough `true` if the balance is enough, `false` otherwise.
    function _isBalanceEnough(
        uint256 balance,
        uint256[] memory configs,
        uint256 configsLen,
        uint256 maxEnd
    ) private view returns (bool isEnough) {
        unchecked {
            uint256 spent = 0;
            for (uint256 i = 0; i < configsLen; i++) {
                (uint256 amtPerSec, uint256 start, uint256 end) = _getConfig(configs, i);
                // slither-disable-next-line timestamp
                if (maxEnd <= start) {
                    continue;
                }
                // slither-disable-next-line timestamp
                if (end > maxEnd) {
                    end = maxEnd;
                }
                spent += _streamedAmt(amtPerSec, start, end);
                if (spent > balance) {
                    return false;
                }
            }
            return true;
        }
    }

    /// @notice Build a preprocessed list of streams configurations from receivers.
    /// @param receivers The list of streams receivers.
    /// Must be sorted, deduplicated and without 0 amtPerSecs.
    /// @return configs The list of streams configurations
    /// @return configsLen The length of `configs`
    function _buildConfigs(StreamReceiver[] memory receivers)
        private
        view
        returns (uint256[] memory configs, uint256 configsLen)
    {
        unchecked {
            require(receivers.length <= _MAX_STREAMS_RECEIVERS, "Too many streams receivers");
            configs = new uint256[](receivers.length);
            for (uint256 i = 0; i < receivers.length; i++) {
                StreamReceiver memory receiver = receivers[i];
                if (i > 0) {
                    require(_isOrdered(receivers[i - 1], receiver), "Streams receivers not sorted");
                }
                configsLen = _addConfig(configs, configsLen, receiver);
            }
        }
    }

    /// @notice Preprocess and add a stream receiver to the list of configurations.
    /// @param configs The list of streams configurations
    /// @param configsLen The length of `configs`
    /// @param receiver The added stream receiver.
    /// @return newConfigsLen The new length of `configs`
    function _addConfig(
        uint256[] memory configs,
        uint256 configsLen,
        StreamReceiver memory receiver
    ) private view returns (uint256 newConfigsLen) {
        uint160 amtPerSec = receiver.config.amtPerSec();
        require(amtPerSec >= _minAmtPerSec, "Stream receiver amtPerSec too low");
        (uint32 start, uint32 end) =
            _streamRangeInFuture(receiver, _currTimestamp(), type(uint32).max);
        // slither-disable-next-line incorrect-equality,timestamp
        if (start == end) {
            return configsLen;
        }
        // By assignment we get `config` value:
        // `zeros (96 bits) | amtPerSec (160 bits)`
        uint256 config = amtPerSec;
        // By bit shifting we get `config` value:
        // `zeros (64 bits) | amtPerSec (160 bits) | zeros (32 bits)`
        // By bit masking we get `config` value:
        // `zeros (64 bits) | amtPerSec (160 bits) | start (32 bits)`
        config = (config << 32) | start;
        // By bit shifting we get `config` value:
        // `zeros (32 bits) | amtPerSec (160 bits) | start (32 bits) | zeros (32 bits)`
        // By bit masking we get `config` value:
        // `zeros (32 bits) | amtPerSec (160 bits) | start (32 bits) | end (32 bits)`
        config = (config << 32) | end;
        configs[configsLen] = config;
        unchecked {
            return configsLen + 1;
        }
    }

    /// @notice Load a streams configuration from the list.
    /// @param configs The list of streams configurations
    /// @param idx The loaded configuration index. It must be smaller than the `configs` length.
    /// @return amtPerSec The amount per second being streamed.
    /// @return start The timestamp when streaming starts.
    /// @return end The maximum timestamp when streaming ends.
    function _getConfig(uint256[] memory configs, uint256 idx)
        private
        pure
        returns (uint256 amtPerSec, uint256 start, uint256 end)
    {
        uint256 config;
        // `config` has value:
        // `zeros (32 bits) | amtPerSec (160 bits) | start (32 bits) | end (32 bits)`
        // slither-disable-next-line assembly
        assembly ("memory-safe") {
            config := mload(add(32, add(configs, shl(5, idx))))
        }
        // By bit shifting we get value:
        // `zeros (96 bits) | amtPerSec (160 bits)`
        amtPerSec = config >> 64;
        // By bit shifting we get value:
        // `zeros (64 bits) | amtPerSec (160 bits) | start (32 bits)`
        // By casting down we get value:
        // `start (32 bits)`
        start = uint32(config >> 32);
        // By casting down we get value:
        // `end (32 bits)`
        end = uint32(config);
    }

    /// @notice Calculates the hash of the streams configuration.
    /// It's used to verify if streams configuration is the previously set one.
    /// @param receivers The list of the streams receivers.
    /// Must be sorted, deduplicated and without 0 amtPerSecs.
    /// If the streams have never been updated, pass an empty array.
    /// @return streamsHash The hash of the streams configuration
    function _hashStreams(StreamReceiver[] memory receivers)
        internal
        pure
        returns (bytes32 streamsHash)
    {
        if (receivers.length == 0) {
            return bytes32(0);
        }
        return keccak256(abi.encode(receivers));
    }

    /// @notice Calculates the hash of the streams history
    /// after the streams configuration is updated.
    /// @param oldStreamsHistoryHash The history hash
    /// that was valid before the streams were updated.
    /// The `streamsHistoryHash` of an account before they set streams for the first time is `0`.
    /// @param streamsHash The hash of the streams receivers being set.
    /// @param updateTime The timestamp when the streams were updated.
    /// @param maxEnd The maximum end of the streams being set.
    /// @return streamsHistoryHash The hash of the updated streams history.
    function _hashStreamsHistory(
        bytes32 oldStreamsHistoryHash,
        bytes32 streamsHash,
        uint32 updateTime,
        uint32 maxEnd
    ) internal pure returns (bytes32 streamsHistoryHash) {
        return keccak256(abi.encode(oldStreamsHistoryHash, streamsHash, updateTime, maxEnd));
    }

    /// @notice Applies the effects of the change of the streams on the receivers' streams state.
    /// @param states The streams states for the used ERC-20 token.
    /// @param currReceivers The list of the streams receivers
    /// set in the last streams update of the account.
    /// If this is the first update, pass an empty array.
    /// @param lastUpdate the last time the sender updated the streams.
    /// If this is the first update, pass zero.
    /// @param currMaxEnd The maximum end time of streaming according to the last streams update.
    /// @param newReceivers  The list of the streams receivers of the account to be set.
    /// Must be sorted, deduplicated and without 0 amtPerSecs.
    /// @param newMaxEnd The maximum end time of streaming according to the new configuration.
    // slither-disable-next-line cyclomatic-complexity
    function _updateReceiverStates(
        mapping(uint256 accountId => StreamsState) storage states,
        StreamReceiver[] memory currReceivers,
        uint32 lastUpdate,
        uint32 currMaxEnd,
        StreamReceiver[] memory newReceivers,
        uint32 newMaxEnd
    ) private {
        uint256 currIdx = 0;
        uint256 newIdx = 0;
        while (true) {
            bool pickCurr = currIdx < currReceivers.length;
            // slither-disable-next-line uninitialized-local
            StreamReceiver memory currRecv;
            if (pickCurr) {
                currRecv = currReceivers[currIdx];
            }

            bool pickNew = newIdx < newReceivers.length;
            // slither-disable-next-line uninitialized-local
            StreamReceiver memory newRecv;
            if (pickNew) {
                newRecv = newReceivers[newIdx];
            }

            // Limit picking both curr and new to situations when they differ only by time
            if (pickCurr && pickNew) {
                if (
                    currRecv.accountId != newRecv.accountId
                        || currRecv.config.amtPerSec() != newRecv.config.amtPerSec()
                ) {
                    pickCurr = _isOrdered(currRecv, newRecv);
                    pickNew = !pickCurr;
                }
            }

            if (pickCurr && pickNew) {
                // Shift the existing stream to fulfil the new configuration
                StreamsState storage state = states[currRecv.accountId];
                (uint32 currStart, uint32 currEnd) =
                    _streamRangeInFuture(currRecv, lastUpdate, currMaxEnd);
                (uint32 newStart, uint32 newEnd) =
                    _streamRangeInFuture(newRecv, _currTimestamp(), newMaxEnd);
                int256 amtPerSec = int256(uint256(currRecv.config.amtPerSec()));
                // Move the start and end times if updated. This has the same effects as calling
                // _addDeltaRange(state, currStart, currEnd, -amtPerSec);
                // _addDeltaRange(state, newStart, newEnd, amtPerSec);
                // but it allows skipping storage access if there's no change to the starts or ends.
                _addDeltaRange(state, currStart, newStart, -amtPerSec);
                _addDeltaRange(state, currEnd, newEnd, amtPerSec);
                // Ensure that the account receives the updated cycles
                uint32 currStartCycle = _cycleOf(currStart);
                uint32 newStartCycle = _cycleOf(newStart);
                // The `currStartCycle > newStartCycle` check is just an optimization.
                // If it's false, then `state.nextReceivableCycle > newStartCycle` must be
                // false too, there's no need to pay for the storage access to check it.
                // slither-disable-next-line timestamp
                if (currStartCycle > newStartCycle && state.nextReceivableCycle > newStartCycle) {
                    state.nextReceivableCycle = newStartCycle;
                }
            } else if (pickCurr) {
                // Remove an existing stream
                // slither-disable-next-line similar-names
                StreamsState storage state = states[currRecv.accountId];
                (uint32 start, uint32 end) = _streamRangeInFuture(currRecv, lastUpdate, currMaxEnd);
                // slither-disable-next-line similar-names
                int256 amtPerSec = int256(uint256(currRecv.config.amtPerSec()));
                _addDeltaRange(state, start, end, -amtPerSec);
            } else if (pickNew) {
                // Create a new stream
                StreamsState storage state = states[newRecv.accountId];
                // slither-disable-next-line uninitialized-local
                (uint32 start, uint32 end) =
                    _streamRangeInFuture(newRecv, _currTimestamp(), newMaxEnd);
                int256 amtPerSec = int256(uint256(newRecv.config.amtPerSec()));
                _addDeltaRange(state, start, end, amtPerSec);
                // Ensure that the account receives the updated cycles
                uint32 startCycle = _cycleOf(start);
                // slither-disable-next-line timestamp
                uint32 nextReceivableCycle = state.nextReceivableCycle;
                if (nextReceivableCycle == 0 || nextReceivableCycle > startCycle) {
                    state.nextReceivableCycle = startCycle;
                }
            } else {
                break;
            }

            unchecked {
                if (pickCurr) {
                    currIdx++;
                }
                if (pickNew) {
                    newIdx++;
                }
            }
        }
    }

    /// @notice Calculates the time range in the future in which a receiver will be streamed to.
    /// @param receiver The stream receiver.
    /// @param maxEnd The maximum end time of streaming.
    function _streamRangeInFuture(StreamReceiver memory receiver, uint32 updateTime, uint32 maxEnd)
        private
        view
        returns (uint32 start, uint32 end)
    {
        return _streamRange(receiver, updateTime, maxEnd, _currTimestamp(), type(uint32).max);
    }

    /// @notice Calculates the time range in which a receiver is to be streamed to.
    /// This range is capped to provide a view on the stream through a specific time window.
    /// @param receiver The stream receiver.
    /// @param updateTime The time when the stream is configured.
    /// @param maxEnd The maximum end time of streaming.
    /// @param startCap The timestamp the streaming range start should be capped to.
    /// @param endCap The timestamp the streaming range end should be capped to.
    function _streamRange(
        StreamReceiver memory receiver,
        uint32 updateTime,
        uint32 maxEnd,
        uint32 startCap,
        uint32 endCap
    ) private pure returns (uint32 start, uint32 end_) {
        start = receiver.config.start();
        // slither-disable-start timestamp
        if (start == 0) {
            start = updateTime;
        }
        uint40 end;
        unchecked {
            end = uint40(start) + receiver.config.duration();
        }
        // slither-disable-next-line incorrect-equality
        if (end == start || end > maxEnd) {
            end = maxEnd;
        }
        if (start < startCap) {
            start = startCap;
        }
        if (end > endCap) {
            end = endCap;
        }
        if (end < start) {
            end = start;
        }
        // slither-disable-end timestamp
        return (start, uint32(end));
    }

    /// @notice Adds funds received by an account in a given time range
    /// @param state The account state
    /// @param start The timestamp from which the delta takes effect
    /// @param end The timestamp until which the delta takes effect
    /// @param amtPerSec The streaming rate
    function _addDeltaRange(StreamsState storage state, uint32 start, uint32 end, int256 amtPerSec)
        private
    {
        // slither-disable-next-line incorrect-equality,timestamp
        if (start == end) {
            return;
        }
        mapping(uint32 cycle => AmtDelta) storage amtDeltas = state.amtDeltas;
        _addDelta(amtDeltas, start, amtPerSec);
        _addDelta(amtDeltas, end, -amtPerSec);
    }

    /// @notice Adds delta of funds received by an account at a given time
    /// @param amtDeltas The account amount deltas
    /// @param timestamp The timestamp when the deltas need to be added
    /// @param amtPerSec The streaming rate
    function _addDelta(
        mapping(uint32 cycle => AmtDelta) storage amtDeltas,
        uint256 timestamp,
        int256 amtPerSec
    ) private {
        unchecked {
            // In order to set a delta on a specific timestamp it must be introduced in two cycles.
            // These formulas follow the logic from `_streamedAmt`, see it for more details.
            int256 amtPerSecMultiplier = int160(_AMT_PER_SEC_MULTIPLIER);
            int256 fullCycle = (int256(uint256(_cycleSecs)) * amtPerSec) / amtPerSecMultiplier;
            // slither-disable-next-line weak-prng
            int256 nextCycle = (int256(timestamp % _cycleSecs) * amtPerSec) / amtPerSecMultiplier;
            AmtDelta storage amtDelta = amtDeltas[_cycleOf(uint32(timestamp))];
            // Any over- or under-flows are fine, they're guaranteed to be fixed by a matching
            // under- or over-flow from the other call to `_addDelta` made by `_addDeltaRange`.
            // This is because the total balance of `Streams` can never exceed `type(int128).max`,
            // so in the end no amtDelta can have delta higher than `type(int128).max`.
            amtDelta.thisCycle += int128(fullCycle - nextCycle);
            amtDelta.nextCycle += int128(nextCycle);
        }
    }

    /// @notice Checks if two receivers fulfil the sortedness requirement of the receivers list.
    /// @param prev The previous receiver
    /// @param next The next receiver
    function _isOrdered(StreamReceiver memory prev, StreamReceiver memory next)
        private
        pure
        returns (bool)
    {
        if (prev.accountId != next.accountId) {
            return prev.accountId < next.accountId;
        }
        return prev.config.lt(next.config);
    }

    /// @notice Calculates the amount streamed over a time range.
    /// The amount streamed in the `N`th second of each cycle is:
    /// `(N + 1) * amtPerSec / AMT_PER_SEC_MULTIPLIER - N * amtPerSec / AMT_PER_SEC_MULTIPLIER`.
    /// For a range of `N`s from `0` to `M` the sum of the streamed amounts is calculated as:
    /// `M * amtPerSec / AMT_PER_SEC_MULTIPLIER` assuming that `M <= cycleSecs`.
    /// For an arbitrary time range across multiple cycles the amount
    /// is calculated as the sum of the amount streamed in the start cycle,
    /// each of the full cycles in between and the end cycle.
    /// This algorithm has the following properties:
    /// - During every second full units are streamed, there are no partially streamed units.
    /// - Unstreamed fractions are streamed when they add up into full units.
    /// - Unstreamed fractions don't add up across cycle end boundaries.
    /// - Some seconds stream more units and some less.
    /// - Every `N`th second of each cycle streams the same amount.
    /// - Every full cycle streams the same amount.
    /// - The amount streamed in a given second is independent from the streaming start and end.
    /// - Streaming over time ranges `A:B` and then `B:C` is equivalent to streaming over `A:C`.
    /// - Different streams existing in the system don't interfere with each other.
    /// @param amtPerSec The streaming rate
    /// @param start The streaming start time
    /// @param end The streaming end time
    /// @return amt The streamed amount
    function _streamedAmt(uint256 amtPerSec, uint256 start, uint256 end)
        private
        view
        returns (uint256 amt)
    {
        // This function is written in Yul because it can be called thousands of times
        // per transaction and it needs to be optimized as much as possible.
        // As of Solidity 0.8.13, rewriting it in unchecked Solidity triples its gas cost.
        uint256 cycleSecs = _cycleSecs;
        // slither-disable-next-line assembly
        assembly {
            let endedCycles := sub(div(end, cycleSecs), div(start, cycleSecs))
            // slither-disable-next-line divide-before-multiply
            let amtPerCycle := div(mul(cycleSecs, amtPerSec), _AMT_PER_SEC_MULTIPLIER)
            amt := mul(endedCycles, amtPerCycle)
            // slither-disable-next-line weak-prng
            let amtEnd := div(mul(mod(end, cycleSecs), amtPerSec), _AMT_PER_SEC_MULTIPLIER)
            amt := add(amt, amtEnd)
            // slither-disable-next-line weak-prng
            let amtStart := div(mul(mod(start, cycleSecs), amtPerSec), _AMT_PER_SEC_MULTIPLIER)
            amt := sub(amt, amtStart)
        }
    }

    /// @notice Calculates the cycle containing the given timestamp.
    /// @param timestamp The timestamp.
    /// @return cycle The cycle containing the timestamp.
    function _cycleOf(uint32 timestamp) private view returns (uint32 cycle) {
        unchecked {
            return timestamp / _cycleSecs + 1;
        }
    }

    /// @notice The current timestamp, casted to the contract's internal representation.
    /// @return timestamp The current timestamp
    function _currTimestamp() private view returns (uint32 timestamp) {
        return uint32(block.timestamp);
    }

    /// @notice The current cycle start timestamp, casted to the contract's internal representation.
    /// @return timestamp The current cycle start timestamp
    function _currCycleStart() private view returns (uint32 timestamp) {
        unchecked {
            uint32 currTimestamp = _currTimestamp();
            // slither-disable-next-line weak-prng
            return currTimestamp - (currTimestamp % _cycleSecs);
        }
    }

    /// @notice Returns the Streams storage.
    /// @return streamsStorage The storage.
    function _streamsStorage() private view returns (StreamsStorage storage streamsStorage) {
        bytes32 slot = _streamsStorageSlot;
        // slither-disable-next-line assembly
        assembly {
            streamsStorage.slot := slot
        }
    }
}

File 3 of 17 : Managed.sol
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.20;

import {UUPSUpgradeable} from "openzeppelin-contracts/proxy/utils/UUPSUpgradeable.sol";
import {ERC1967Proxy} from "openzeppelin-contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {EnumerableSet} from "openzeppelin-contracts/utils/structs/EnumerableSet.sol";
import {StorageSlot} from "openzeppelin-contracts/utils/StorageSlot.sol";

using EnumerableSet for EnumerableSet.AddressSet;

/// @notice A mix-in for contract pausing, upgrading and admin management.
/// It can't be used directly, only via a proxy. It uses the upgrade-safe ERC-1967 storage scheme.
///
/// Managed uses the ERC-1967 admin slot to store the admin address.
/// All instances of the contracts have admin address `0x00` and are forever paused.
/// When a proxy uses such contract via delegation, the proxy should define
/// the initial admin address and the contract is initially unpaused.
abstract contract Managed is UUPSUpgradeable {
    /// @notice The pointer to the storage slot holding a single `ManagedStorage` structure.
    bytes32 private immutable _managedStorageSlot = _erc1967Slot("eip1967.managed.storage");

    /// @notice Emitted when a new admin of the contract is proposed.
    /// The proposed admin must call `acceptAdmin` to finalize the change.
    /// @param currentAdmin The current admin address.
    /// @param newAdmin The proposed admin address.
    event NewAdminProposed(address indexed currentAdmin, address indexed newAdmin);

    /// @notice Emitted when the pauses role is granted.
    /// @param pauser The address that the pauser role was granted to.
    /// @param admin The address of the admin that triggered the change.
    event PauserGranted(address indexed pauser, address indexed admin);

    /// @notice Emitted when the pauses role is revoked.
    /// @param pauser The address that the pauser role was revoked from.
    /// @param admin The address of the admin that triggered the change.
    event PauserRevoked(address indexed pauser, address indexed admin);

    /// @notice Emitted when the pause is triggered.
    /// @param pauser The address that triggered the change.
    event Paused(address indexed pauser);

    /// @notice Emitted when the pause is lifted.
    /// @param pauser The address that triggered the change.
    event Unpaused(address indexed pauser);

    struct ManagedStorage {
        bool isPaused;
        EnumerableSet.AddressSet pausers;
        address proposedAdmin;
    }

    /// @notice Throws if called by any caller other than the admin.
    modifier onlyAdmin() {
        require(admin() == msg.sender, "Caller not the admin");
        _;
    }

    /// @notice Throws if called by any caller other than the admin or a pauser.
    modifier onlyAdminOrPauser() {
        require(admin() == msg.sender || isPauser(msg.sender), "Caller not the admin or a pauser");
        _;
    }

    /// @notice Modifier to make a function callable only when the contract is not paused.
    modifier whenNotPaused() {
        require(!isPaused(), "Contract paused");
        _;
    }

    /// @notice Modifier to make a function callable only when the contract is paused.
    modifier whenPaused() {
        require(isPaused(), "Contract not paused");
        _;
    }

    /// @notice Initializes the contract in paused state and with no admin.
    /// The contract instance can be used only as a call delegation target for a proxy.
    constructor() {
        _managedStorage().isPaused = true;
    }

    /// @notice Returns the current implementation address.
    function implementation() public view returns (address) {
        return _getImplementation();
    }

    /// @notice Returns the address of the current admin.
    function admin() public view returns (address) {
        return _getAdmin();
    }

    /// @notice Returns the proposed address to change the admin to.
    function proposedAdmin() public view returns (address) {
        return _managedStorage().proposedAdmin;
    }

    /// @notice Proposes a change of the admin of the contract.
    /// The proposed new admin must call `acceptAdmin` to finalize the change.
    /// To cancel a proposal propose a different address, e.g. the zero address.
    /// Can only be called by the current admin.
    /// @param newAdmin The proposed admin address.
    function proposeNewAdmin(address newAdmin) public onlyAdmin {
        emit NewAdminProposed(msg.sender, newAdmin);
        _managedStorage().proposedAdmin = newAdmin;
    }

    /// @notice Applies a proposed change of the admin of the contract.
    /// Sets the proposed admin to the zero address.
    /// Can only be called by the proposed admin.
    function acceptAdmin() public {
        require(proposedAdmin() == msg.sender, "Caller not the proposed admin");
        _updateAdmin(msg.sender);
    }

    /// @notice Changes the admin of the contract to address zero.
    /// It's no longer possible to change the admin or upgrade the contract afterwards.
    /// Can only be called by the current admin.
    function renounceAdmin() public onlyAdmin {
        _updateAdmin(address(0));
    }

    /// @notice Sets the current admin of the contract and clears the proposed admin.
    /// @param newAdmin The admin address being set. Can be the zero address.
    function _updateAdmin(address newAdmin) internal {
        emit AdminChanged(admin(), newAdmin);
        _managedStorage().proposedAdmin = address(0);
        StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
    }

    /// @notice Grants the pauser role to an address. Callable only by the admin.
    /// @param pauser The granted address.
    function grantPauser(address pauser) public onlyAdmin {
        require(_managedStorage().pausers.add(pauser), "Address already is a pauser");
        emit PauserGranted(pauser, msg.sender);
    }

    /// @notice Revokes the pauser role from an address. Callable only by the admin.
    /// @param pauser The revoked address.
    function revokePauser(address pauser) public onlyAdmin {
        require(_managedStorage().pausers.remove(pauser), "Address is not a pauser");
        emit PauserRevoked(pauser, msg.sender);
    }

    /// @notice Checks if an address is a pauser.
    /// @param pauser The checked address.
    /// @return isAddrPauser True if the address is a pauser.
    function isPauser(address pauser) public view returns (bool isAddrPauser) {
        return _managedStorage().pausers.contains(pauser);
    }

    /// @notice Returns all the addresses with the pauser role.
    /// @return pausersList The list of all the pausers, ordered arbitrarily.
    /// The list's order may change after granting or revoking the pauser role.
    function allPausers() public view returns (address[] memory pausersList) {
        return _managedStorage().pausers.values();
    }

    /// @notice Returns true if the contract is paused, and false otherwise.
    function isPaused() public view returns (bool) {
        return _managedStorage().isPaused;
    }

    /// @notice Triggers stopped state. Callable only by the admin or a pauser.
    function pause() public onlyAdminOrPauser whenNotPaused {
        _managedStorage().isPaused = true;
        emit Paused(msg.sender);
    }

    /// @notice Returns to normal state. Callable only by the admin or a pauser.
    function unpause() public onlyAdminOrPauser whenPaused {
        _managedStorage().isPaused = false;
        emit Unpaused(msg.sender);
    }

    /// @notice Calculates the quasi ERC-1967 slot pointer.
    /// @param name The name of the slot, should be globally unique
    /// @return slot The slot pointer
    function _erc1967Slot(string memory name) internal pure returns (bytes32 slot) {
        // The original ERC-1967 subtracts 1 from the hash to get 1 storage slot
        // under an index without a known hash preimage which is enough to store a single address.
        // This implementation subtracts 1024 to get 1024 slots without a known preimage
        // allowing securely storing much larger structures.
        return bytes32(uint256(keccak256(bytes(name))) - 1024);
    }

    /// @notice Returns the Managed storage.
    /// @return storageRef The storage.
    function _managedStorage() internal view returns (ManagedStorage storage storageRef) {
        bytes32 slot = _managedStorageSlot;
        // slither-disable-next-line assembly
        assembly {
            storageRef.slot := slot
        }
    }

    /// @notice Authorizes the contract upgrade. See `UUPSUpgradeable` docs for more details.
    function _authorizeUpgrade(address /* newImplementation */ ) internal view override onlyAdmin {
        return;
    }
}

/// @notice A generic proxy for contracts implementing `Managed`.
contract ManagedProxy is ERC1967Proxy {
    constructor(Managed logic, address admin) ERC1967Proxy(address(logic), new bytes(0)) {
        _changeAdmin(admin);
    }
}

File 4 of 17 : Splits.sol
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.20;

import {IERC20} from "openzeppelin-contracts/token/ERC20/IERC20.sol";

/// @notice A splits receiver
struct SplitsReceiver {
    /// @notice The account ID.
    uint256 accountId;
    /// @notice The splits weight. Must never be zero.
    /// The account will be getting `weight / _TOTAL_SPLITS_WEIGHT`
    /// share of the funds collected by the splitting account.
    uint32 weight;
}

/// @notice Splits can keep track of at most `type(uint128).max`
/// which is `2 ^ 128 - 1` units of each ERC-20 token.
/// It's up to the caller to guarantee that this limit is never exceeded,
/// failing to do so may result in a total protocol collapse.
abstract contract Splits {
    /// @notice Maximum number of splits receivers of a single account.
    /// Limits the cost of splitting.
    uint256 internal constant _MAX_SPLITS_RECEIVERS = 200;
    /// @notice The total splits weight of an account.
    uint32 internal constant _TOTAL_SPLITS_WEIGHT = 1_000_000;
    /// @notice The amount the contract can keep track of each ERC-20 token.
    // slither-disable-next-line unused-state
    uint128 internal constant _MAX_SPLITS_BALANCE = type(uint128).max;
    /// @notice The storage slot holding a single `SplitsStorage` structure.
    bytes32 private immutable _splitsStorageSlot;

    /// @notice Emitted when an account collects funds
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// @param collected The collected amount
    event Collected(uint256 indexed accountId, IERC20 indexed erc20, uint128 collected);

    /// @notice Emitted when funds are split from an account to a receiver.
    /// This is caused by the account collecting received funds.
    /// @param accountId The account ID.
    /// @param receiver The splits receiver account ID
    /// @param erc20 The used ERC-20 token.
    /// @param amt The amount split to the receiver
    event Split(
        uint256 indexed accountId, uint256 indexed receiver, IERC20 indexed erc20, uint128 amt
    );

    /// @notice Emitted when funds are made collectable after splitting.
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// @param amt The amount made collectable for the account
    /// on top of what was collectable before.
    event Collectable(uint256 indexed accountId, IERC20 indexed erc20, uint128 amt);

    /// @notice Emitted when funds are given from the account to the receiver.
    /// @param accountId The account ID.
    /// @param receiver The receiver account ID.
    /// @param erc20 The used ERC-20 token.
    /// @param amt The given amount
    event Given(
        uint256 indexed accountId, uint256 indexed receiver, IERC20 indexed erc20, uint128 amt
    );

    /// @notice Emitted when the account's splits are updated.
    /// @param accountId The account ID.
    /// @param receiversHash The splits receivers list hash
    event SplitsSet(uint256 indexed accountId, bytes32 indexed receiversHash);

    /// @notice Emitted when an account is seen in a splits receivers list.
    /// @param receiversHash The splits receivers list hash
    /// @param accountId The account ID.
    /// @param weight The splits weight. Must never be zero.
    /// The account will be getting `weight / _TOTAL_SPLITS_WEIGHT`
    /// share of the funds collected by the splitting account.
    event SplitsReceiverSeen(
        bytes32 indexed receiversHash, uint256 indexed accountId, uint32 weight
    );

    struct SplitsStorage {
        /// @notice Account splits states.
        mapping(uint256 accountId => SplitsState) splitsStates;
    }

    struct SplitsState {
        /// @notice The account's splits configuration hash, see `hashSplits`.
        bytes32 splitsHash;
        /// @notice The account's splits balances.
        mapping(IERC20 erc20 => SplitsBalance) balances;
    }

    struct SplitsBalance {
        /// @notice The not yet split balance, must be split before collecting by the account.
        uint128 splittable;
        /// @notice The already split balance, ready to be collected by the account.
        uint128 collectable;
    }

    /// @param splitsStorageSlot The storage slot to holding a single `SplitsStorage` structure.
    constructor(bytes32 splitsStorageSlot) {
        _splitsStorageSlot = splitsStorageSlot;
    }

    function _addSplittable(uint256 accountId, IERC20 erc20, uint128 amt) internal {
        _splitsStorage().splitsStates[accountId].balances[erc20].splittable += amt;
    }

    /// @notice Returns account's received but not split yet funds.
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// @return amt The amount received but not split yet.
    function _splittable(uint256 accountId, IERC20 erc20) internal view returns (uint128 amt) {
        return _splitsStorage().splitsStates[accountId].balances[erc20].splittable;
    }

    /// @notice Calculate the result of splitting an amount using the current splits configuration.
    /// @param accountId The account ID.
    /// @param currReceivers The list of the account's current splits receivers.
    /// It must be exactly the same as the last list set for the account with `_setSplits`.
    /// @param amount The amount being split.
    /// @return collectableAmt The amount made collectable for the account
    /// on top of what was collectable before.
    /// @return splitAmt The amount split to the account's splits receivers
    function _splitResult(uint256 accountId, SplitsReceiver[] memory currReceivers, uint128 amount)
        internal
        view
        returns (uint128 collectableAmt, uint128 splitAmt)
    {
        _assertCurrSplits(accountId, currReceivers);
        if (amount == 0) {
            return (0, 0);
        }
        unchecked {
            uint160 splitsWeight = 0;
            for (uint256 i = 0; i < currReceivers.length; i++) {
                splitsWeight += currReceivers[i].weight;
            }
            splitAmt = uint128(amount * splitsWeight / _TOTAL_SPLITS_WEIGHT);
            collectableAmt = amount - splitAmt;
        }
    }

    /// @notice Splits the account's splittable funds among receivers.
    /// The entire splittable balance of the given ERC-20 token is split.
    /// All split funds are split using the current splits configuration.
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// @param currReceivers The list of the account's current splits receivers.
    /// It must be exactly the same as the last list set for the account with `_setSplits`.
    /// @return collectableAmt The amount made collectable for the account
    /// on top of what was collectable before.
    /// @return splitAmt The amount split to the account's splits receivers
    function _split(uint256 accountId, IERC20 erc20, SplitsReceiver[] memory currReceivers)
        internal
        returns (uint128 collectableAmt, uint128 splitAmt)
    {
        _assertCurrSplits(accountId, currReceivers);
        SplitsBalance storage balance = _splitsStorage().splitsStates[accountId].balances[erc20];

        collectableAmt = balance.splittable;
        if (collectableAmt == 0) {
            return (0, 0);
        }
        balance.splittable = 0;

        unchecked {
            uint160 splitsWeight = 0;
            for (uint256 i = 0; i < currReceivers.length; i++) {
                splitsWeight += currReceivers[i].weight;
                uint128 currSplitAmt =
                    uint128(collectableAmt * splitsWeight / _TOTAL_SPLITS_WEIGHT) - splitAmt;
                splitAmt += currSplitAmt;
                uint256 receiver = currReceivers[i].accountId;
                _addSplittable(receiver, erc20, currSplitAmt);
                emit Split(accountId, receiver, erc20, currSplitAmt);
            }
            collectableAmt -= splitAmt;
            balance.collectable += collectableAmt;
        }
        emit Collectable(accountId, erc20, collectableAmt);
    }

    /// @notice Returns account's received funds already split and ready to be collected.
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// @return amt The collectable amount.
    function _collectable(uint256 accountId, IERC20 erc20) internal view returns (uint128 amt) {
        return _splitsStorage().splitsStates[accountId].balances[erc20].collectable;
    }

    /// @notice Collects account's received already split funds.
    /// @param accountId The account ID.
    /// @param erc20 The used ERC-20 token.
    /// @return amt The collected amount
    function _collect(uint256 accountId, IERC20 erc20) internal returns (uint128 amt) {
        SplitsBalance storage balance = _splitsStorage().splitsStates[accountId].balances[erc20];
        amt = balance.collectable;
        balance.collectable = 0;
        emit Collected(accountId, erc20, amt);
    }

    /// @notice Gives funds from the account to the receiver.
    /// The receiver can split and collect them immediately.
    /// @param accountId The account ID.
    /// @param receiver The receiver account ID.
    /// @param erc20 The used ERC-20 token.
    /// @param amt The given amount
    function _give(uint256 accountId, uint256 receiver, IERC20 erc20, uint128 amt) internal {
        _addSplittable(receiver, erc20, amt);
        emit Given(accountId, receiver, erc20, amt);
    }

    /// @notice Sets the account splits configuration.
    /// The configuration is common for all ERC-20 tokens.
    /// Nothing happens to the currently splittable funds, but when they are split
    /// after this function finishes, the new splits configuration will be used.
    /// @param accountId The account ID.
    /// @param receivers The list of the account's splits receivers to be set.
    /// Must be sorted by the splits receivers' addresses, deduplicated and without 0 weights.
    /// Each splits receiver will be getting `weight / _TOTAL_SPLITS_WEIGHT`
    /// share of the funds collected by the account.
    /// If the sum of weights of all receivers is less than `_TOTAL_SPLITS_WEIGHT`,
    /// some funds won't be split, but they will be left for the account to collect.
    /// It's valid to include the account's own `accountId` in the list of receivers,
    /// but funds split to themselves return to their splittable balance and are not collectable.
    /// This is usually unwanted, because if splitting is repeated,
    /// funds split to themselves will be again split using the current configuration.
    /// Splitting 100% to self effectively blocks splitting unless the configuration is updated.
    function _setSplits(uint256 accountId, SplitsReceiver[] memory receivers) internal {
        SplitsState storage state = _splitsStorage().splitsStates[accountId];
        bytes32 newSplitsHash = _hashSplits(receivers);
        emit SplitsSet(accountId, newSplitsHash);
        if (newSplitsHash != state.splitsHash) {
            _assertSplitsValid(receivers, newSplitsHash);
            state.splitsHash = newSplitsHash;
        }
    }

    /// @notice Validates a list of splits receivers and emits events for them
    /// @param receivers The list of splits receivers
    /// @param receiversHash The hash of the list of splits receivers.
    /// Must be sorted by the splits receivers' addresses, deduplicated and without 0 weights.
    function _assertSplitsValid(SplitsReceiver[] memory receivers, bytes32 receiversHash) private {
        unchecked {
            require(receivers.length <= _MAX_SPLITS_RECEIVERS, "Too many splits receivers");
            uint64 totalWeight = 0;
            // slither-disable-next-line uninitialized-local
            uint256 prevAccountId;
            for (uint256 i = 0; i < receivers.length; i++) {
                SplitsReceiver memory receiver = receivers[i];
                uint32 weight = receiver.weight;
                require(weight != 0, "Splits receiver weight is zero");
                totalWeight += weight;
                uint256 accountId = receiver.accountId;
                if (i > 0) require(prevAccountId < accountId, "Splits receivers not sorted");
                prevAccountId = accountId;
                emit SplitsReceiverSeen(receiversHash, accountId, weight);
            }
            require(totalWeight <= _TOTAL_SPLITS_WEIGHT, "Splits weights sum too high");
        }
    }

    /// @notice Asserts that the list of splits receivers is the account's currently used one.
    /// @param accountId The account ID.
    /// @param currReceivers The list of the account's current splits receivers.
    function _assertCurrSplits(uint256 accountId, SplitsReceiver[] memory currReceivers)
        internal
        view
    {
        require(
            _hashSplits(currReceivers) == _splitsHash(accountId), "Invalid current splits receivers"
        );
    }

    /// @notice Current account's splits hash, see `hashSplits`.
    /// @param accountId The account ID.
    /// @return currSplitsHash The current account's splits hash
    function _splitsHash(uint256 accountId) internal view returns (bytes32 currSplitsHash) {
        return _splitsStorage().splitsStates[accountId].splitsHash;
    }

    /// @notice Calculates the hash of the list of splits receivers.
    /// @param receivers The list of the splits receivers.
    /// Must be sorted by the splits receivers' addresses, deduplicated and without 0 weights.
    /// @return receiversHash The hash of the list of splits receivers.
    function _hashSplits(SplitsReceiver[] memory receivers)
        internal
        pure
        returns (bytes32 receiversHash)
    {
        if (receivers.length == 0) {
            return bytes32(0);
        }
        return keccak256(abi.encode(receivers));
    }

    /// @notice Returns the Splits storage.
    /// @return splitsStorage The storage.
    function _splitsStorage() private view returns (SplitsStorage storage splitsStorage) {
        bytes32 slot = _splitsStorageSlot;
        // slither-disable-next-line assembly
        assembly {
            splitsStorage.slot := slot
        }
    }
}

File 5 of 17 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/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;

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    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));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    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");
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Compatible with tokens that require the approval to be set to
     * 0 before setting it to a non-zero value.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    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");
        require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation 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).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // 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 cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return
            success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
    }
}

File 6 of 17 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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);
}

File 7 of 17 : UUPSUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/UUPSUpgradeable.sol)

pragma solidity ^0.8.0;

import "../../interfaces/draft-IERC1822.sol";
import "../ERC1967/ERC1967Upgrade.sol";

/**
 * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
 * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
 *
 * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
 * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
 * `UUPSUpgradeable` with a custom implementation of upgrades.
 *
 * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
 *
 * _Available since v4.1._
 */
abstract contract UUPSUpgradeable is IERC1822Proxiable, ERC1967Upgrade {
    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
    address private immutable __self = address(this);

    /**
     * @dev Check that the execution is being performed through a delegatecall call and that the execution context is
     * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
     * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
     * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
     * fail.
     */
    modifier onlyProxy() {
        require(address(this) != __self, "Function must be called through delegatecall");
        require(_getImplementation() == __self, "Function must be called through active proxy");
        _;
    }

    /**
     * @dev Check that the execution is not being performed through a delegate call. This allows a function to be
     * callable on the implementing contract but not through proxies.
     */
    modifier notDelegated() {
        require(address(this) == __self, "UUPSUpgradeable: must not be called through delegatecall");
        _;
    }

    /**
     * @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
     * implementation. It is used to validate the implementation's compatibility when performing an upgrade.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
     */
    function proxiableUUID() external view virtual override notDelegated returns (bytes32) {
        return _IMPLEMENTATION_SLOT;
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     *
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function upgradeTo(address newImplementation) public virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, new bytes(0), false);
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
     * encoded in `data`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     *
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, data, true);
    }

    /**
     * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
     * {upgradeTo} and {upgradeToAndCall}.
     *
     * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
     *
     * ```solidity
     * function _authorizeUpgrade(address) internal override onlyOwner {}
     * ```
     */
    function _authorizeUpgrade(address newImplementation) internal virtual;
}

File 8 of 17 : ERC1967Proxy.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (proxy/ERC1967/ERC1967Proxy.sol)

pragma solidity ^0.8.0;

import "../Proxy.sol";
import "./ERC1967Upgrade.sol";

/**
 * @dev This contract implements an upgradeable proxy. It is upgradeable because calls are delegated to an
 * implementation address that can be changed. This address is stored in storage in the location specified by
 * https://eips.ethereum.org/EIPS/eip-1967[EIP1967], so that it doesn't conflict with the storage layout of the
 * implementation behind the proxy.
 */
contract ERC1967Proxy is Proxy, ERC1967Upgrade {
    /**
     * @dev Initializes the upgradeable proxy with an initial implementation specified by `_logic`.
     *
     * If `_data` is nonempty, it's used as data in a delegate call to `_logic`. This will typically be an encoded
     * function call, and allows initializing the storage of the proxy like a Solidity constructor.
     */
    constructor(address _logic, bytes memory _data) payable {
        _upgradeToAndCall(_logic, _data, false);
    }

    /**
     * @dev Returns the current implementation address.
     */
    function _implementation() internal view virtual override returns (address impl) {
        return ERC1967Upgrade._getImplementation();
    }
}

File 9 of 17 : EnumerableSet.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.

pragma solidity ^0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```solidity
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
 * unusable.
 * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
 * array of EnumerableSet.
 * ====
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastValue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastValue;
                // Update the index for the moved value
                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        bytes32[] memory store = _values(set._inner);
        bytes32[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }
}

File 10 of 17 : StorageSlot.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.

pragma solidity ^0.8.0;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC1967 implementation slot:
 * ```solidity
 * contract ERC1967 {
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 *
 * _Available since v4.1 for `address`, `bool`, `bytes32`, `uint256`._
 * _Available since v4.9 for `string`, `bytes`._
 */
library StorageSlot {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` with member `value` located at `slot`.
     */
    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.
     */
    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` with member `value` located at `slot`.
     */
    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
     */
    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }
}

File 11 of 17 : IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/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);
}

File 12 of 17 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [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://consensys.net/diligence/blog/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.8.0/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 functionCallWithValue(target, data, 0, "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");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, 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) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, 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) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or 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 {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // 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);
        }
    }
}

File 13 of 17 : draft-IERC1822.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)

pragma solidity ^0.8.0;

/**
 * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
 * proxy whose upgrades are fully controlled by the current implementation.
 */
interface IERC1822Proxiable {
    /**
     * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
     * address.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy.
     */
    function proxiableUUID() external view returns (bytes32);
}

File 14 of 17 : ERC1967Upgrade.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/ERC1967/ERC1967Upgrade.sol)

pragma solidity ^0.8.2;

import "../beacon/IBeacon.sol";
import "../../interfaces/IERC1967.sol";
import "../../interfaces/draft-IERC1822.sol";
import "../../utils/Address.sol";
import "../../utils/StorageSlot.sol";

/**
 * @dev This abstract contract provides getters and event emitting update functions for
 * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
 *
 * _Available since v4.1._
 */
abstract contract ERC1967Upgrade is IERC1967 {
    // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
    bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;

    /**
     * @dev Storage slot with the address of the current implementation.
     * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
     * validated in the constructor.
     */
    bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    /**
     * @dev Returns the current implementation address.
     */
    function _getImplementation() internal view returns (address) {
        return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 implementation slot.
     */
    function _setImplementation(address newImplementation) private {
        require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
        StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
    }

    /**
     * @dev Perform implementation upgrade
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeTo(address newImplementation) internal {
        _setImplementation(newImplementation);
        emit Upgraded(newImplementation);
    }

    /**
     * @dev Perform implementation upgrade with additional setup call.
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeToAndCall(address newImplementation, bytes memory data, bool forceCall) internal {
        _upgradeTo(newImplementation);
        if (data.length > 0 || forceCall) {
            Address.functionDelegateCall(newImplementation, data);
        }
    }

    /**
     * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeToAndCallUUPS(address newImplementation, bytes memory data, bool forceCall) internal {
        // Upgrades from old implementations will perform a rollback test. This test requires the new
        // implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing
        // this special case will break upgrade paths from old UUPS implementation to new ones.
        if (StorageSlot.getBooleanSlot(_ROLLBACK_SLOT).value) {
            _setImplementation(newImplementation);
        } else {
            try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
                require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID");
            } catch {
                revert("ERC1967Upgrade: new implementation is not UUPS");
            }
            _upgradeToAndCall(newImplementation, data, forceCall);
        }
    }

    /**
     * @dev Storage slot with the admin of the contract.
     * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
     * validated in the constructor.
     */
    bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

    /**
     * @dev Returns the current admin.
     */
    function _getAdmin() internal view returns (address) {
        return StorageSlot.getAddressSlot(_ADMIN_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 admin slot.
     */
    function _setAdmin(address newAdmin) private {
        require(newAdmin != address(0), "ERC1967: new admin is the zero address");
        StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
    }

    /**
     * @dev Changes the admin of the proxy.
     *
     * Emits an {AdminChanged} event.
     */
    function _changeAdmin(address newAdmin) internal {
        emit AdminChanged(_getAdmin(), newAdmin);
        _setAdmin(newAdmin);
    }

    /**
     * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
     * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
     */
    bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;

    /**
     * @dev Returns the current beacon.
     */
    function _getBeacon() internal view returns (address) {
        return StorageSlot.getAddressSlot(_BEACON_SLOT).value;
    }

    /**
     * @dev Stores a new beacon in the EIP1967 beacon slot.
     */
    function _setBeacon(address newBeacon) private {
        require(Address.isContract(newBeacon), "ERC1967: new beacon is not a contract");
        require(
            Address.isContract(IBeacon(newBeacon).implementation()),
            "ERC1967: beacon implementation is not a contract"
        );
        StorageSlot.getAddressSlot(_BEACON_SLOT).value = newBeacon;
    }

    /**
     * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
     * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
     *
     * Emits a {BeaconUpgraded} event.
     */
    function _upgradeBeaconToAndCall(address newBeacon, bytes memory data, bool forceCall) internal {
        _setBeacon(newBeacon);
        emit BeaconUpgraded(newBeacon);
        if (data.length > 0 || forceCall) {
            Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
        }
    }
}

File 15 of 17 : Proxy.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (proxy/Proxy.sol)

pragma solidity ^0.8.0;

/**
 * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
 * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to
 * be specified by overriding the virtual {_implementation} function.
 *
 * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a
 * different contract through the {_delegate} function.
 *
 * The success and return data of the delegated call will be returned back to the caller of the proxy.
 */
abstract contract Proxy {
    /**
     * @dev Delegates the current call to `implementation`.
     *
     * This function does not return to its internal call site, it will return directly to the external caller.
     */
    function _delegate(address implementation) internal virtual {
        assembly {
            // Copy msg.data. We take full control of memory in this inline assembly
            // block because it will not return to Solidity code. We overwrite the
            // Solidity scratch pad at memory position 0.
            calldatacopy(0, 0, calldatasize())

            // Call the implementation.
            // out and outsize are 0 because we don't know the size yet.
            let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)

            // Copy the returned data.
            returndatacopy(0, 0, returndatasize())

            switch result
            // delegatecall returns 0 on error.
            case 0 {
                revert(0, returndatasize())
            }
            default {
                return(0, returndatasize())
            }
        }
    }

    /**
     * @dev This is a virtual function that should be overridden so it returns the address to which the fallback function
     * and {_fallback} should delegate.
     */
    function _implementation() internal view virtual returns (address);

    /**
     * @dev Delegates the current call to the address returned by `_implementation()`.
     *
     * This function does not return to its internal call site, it will return directly to the external caller.
     */
    function _fallback() internal virtual {
        _beforeFallback();
        _delegate(_implementation());
    }

    /**
     * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
     * function in the contract matches the call data.
     */
    fallback() external payable virtual {
        _fallback();
    }

    /**
     * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data
     * is empty.
     */
    receive() external payable virtual {
        _fallback();
    }

    /**
     * @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback`
     * call, or as part of the Solidity `fallback` or `receive` functions.
     *
     * If overridden should call `super._beforeFallback()`.
     */
    function _beforeFallback() internal virtual {}
}

File 16 of 17 : IBeacon.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)

pragma solidity ^0.8.0;

/**
 * @dev This is the interface that {BeaconProxy} expects of its beacon.
 */
interface IBeacon {
    /**
     * @dev Must return an address that can be used as a delegate call target.
     *
     * {BeaconProxy} will check that this address is a contract.
     */
    function implementation() external view returns (address);
}

File 17 of 17 : IERC1967.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC1967.sol)

pragma solidity ^0.8.0;

/**
 * @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.
 *
 * _Available since v4.8.3._
 */
interface IERC1967 {
    /**
     * @dev Emitted when the implementation is upgraded.
     */
    event Upgraded(address indexed implementation);

    /**
     * @dev Emitted when the admin account has changed.
     */
    event AdminChanged(address previousAdmin, address newAdmin);

    /**
     * @dev Emitted when the beacon is changed.
     */
    event BeaconUpgraded(address indexed beacon);
}

Settings
{
  "remappings": [
    "chainlink/=lib/chainlink/contracts/src/v0.8/",
    "ds-test/=lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-std/=lib/forge-std/src/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/",
    "openzeppelin/=lib/openzeppelin-contracts/contracts/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 7700
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "shanghai",
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"uint32","name":"cycleSecs_","type":"uint32"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"accountId","type":"uint256"},{"indexed":true,"internalType":"bytes32","name":"key","type":"bytes32"},{"indexed":false,"internalType":"bytes","name":"value","type":"bytes"}],"name":"AccountMetadataEmitted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"previousAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"AdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"beacon","type":"address"}],"name":"BeaconUpgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"accountId","type":"uint256"},{"indexed":true,"internalType":"contract IERC20","name":"erc20","type":"address"},{"indexed":false,"internalType":"uint128","name":"amt","type":"uint128"}],"name":"Collectable","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"accountId","type":"uint256"},{"indexed":true,"internalType":"contract IERC20","name":"erc20","type":"address"},{"indexed":false,"internalType":"uint128","name":"collected","type":"uint128"}],"name":"Collected","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint32","name":"driverId","type":"uint32"},{"indexed":true,"internalType":"address","name":"oldDriverAddr","type":"address"},{"indexed":true,"internalType":"address","name":"newDriverAddr","type":"address"}],"name":"DriverAddressUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint32","name":"driverId","type":"uint32"},{"indexed":true,"internalType":"address","name":"driverAddr","type":"address"}],"name":"DriverRegistered","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"accountId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"receiver","type":"uint256"},{"indexed":true,"internalType":"contract IERC20","name":"erc20","type":"address"},{"indexed":false,"internalType":"uint128","name":"amt","type":"uint128"}],"name":"Given","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"currentAdmin","type":"address"},{"indexed":true,"internalType":"address","name":"newAdmin","type":"address"}],"name":"NewAdminProposed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pauser","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pauser","type":"address"},{"indexed":true,"internalType":"address","name":"admin","type":"address"}],"name":"PauserGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pauser","type":"address"},{"indexed":true,"internalType":"address","name":"admin","type":"address"}],"name":"PauserRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"accountId","type":"uint256"},{"indexed":true,"internalType":"contract IERC20","name":"erc20","type":"address"},{"indexed":false,"internalType":"uint128","name":"amt","type":"uint128"},{"indexed":false,"internalType":"uint32","name":"receivableCycles","type":"uint32"}],"name":"ReceivedStreams","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"accountId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"receiver","type":"uint256"},{"indexed":true,"internalType":"contract IERC20","name":"erc20","type":"address"},{"indexed":false,"internalType":"uint128","name":"amt","type":"uint128"}],"name":"Split","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"receiversHash","type":"bytes32"},{"indexed":true,"internalType":"uint256","name":"accountId","type":"uint256"},{"indexed":false,"internalType":"uint32","name":"weight","type":"uint32"}],"name":"SplitsReceiverSeen","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"accountId","type":"uint256"},{"indexed":true,"internalType":"bytes32","name":"receiversHash","type":"bytes32"}],"name":"SplitsSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"accountId","type":"uint256"},{"indexed":true,"internalType":"contract IERC20","name":"erc20","type":"address"},{"indexed":true,"internalType":"uint256","name":"senderId","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"amt","type":"uint128"},{"indexed":false,"internalType":"bytes32[]","name":"streamsHistoryHashes","type":"bytes32[]"}],"name":"SqueezedStreams","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"receiversHash","type":"bytes32"},{"indexed":true,"internalType":"uint256","name":"accountId","type":"uint256"},{"indexed":false,"internalType":"StreamConfig","name":"config","type":"uint256"}],"name":"StreamReceiverSeen","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"accountId","type":"uint256"},{"indexed":true,"internalType":"contract IERC20","name":"erc20","type":"address"},{"indexed":true,"internalType":"bytes32","name":"receiversHash","type":"bytes32"},{"indexed":false,"internalType":"bytes32","name":"streamsHistoryHash","type":"bytes32"},{"indexed":false,"internalType":"uint128","name":"balance","type":"uint128"},{"indexed":false,"internalType":"uint32","name":"maxEnd","type":"uint32"}],"name":"StreamsSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pauser","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IERC20","name":"erc20","type":"address"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"amt","type":"uint256"}],"name":"Withdrawn","type":"event"},{"inputs":[],"name":"AMT_PER_SEC_EXTRA_DECIMALS","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"AMT_PER_SEC_MULTIPLIER","outputs":[{"internalType":"uint160","name":"","type":"uint160"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DRIVER_ID_OFFSET","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_SPLITS_RECEIVERS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_STREAMS_RECEIVERS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_TOTAL_BALANCE","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TOTAL_SPLITS_WEIGHT","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"acceptAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"admin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"allPausers","outputs":[{"internalType":"address[]","name":"pausersList","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"internalType":"contract IERC20","name":"erc20","type":"address"},{"components":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"internalType":"StreamConfig","name":"config","type":"uint256"}],"internalType":"struct StreamReceiver[]","name":"currReceivers","type":"tuple[]"},{"internalType":"uint32","name":"timestamp","type":"uint32"}],"name":"balanceAt","outputs":[{"internalType":"uint128","name":"balance","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"erc20","type":"address"}],"name":"balances","outputs":[{"internalType":"uint128","name":"streamsBalance","type":"uint128"},{"internalType":"uint128","name":"splitsBalance","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"internalType":"contract IERC20","name":"erc20","type":"address"}],"name":"collect","outputs":[{"internalType":"uint128","name":"amt","type":"uint128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"internalType":"contract IERC20","name":"erc20","type":"address"}],"name":"collectable","outputs":[{"internalType":"uint128","name":"amt","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"cycleSecs","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"driverId","type":"uint32"}],"name":"driverAddress","outputs":[{"internalType":"address","name":"driverAddr","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"components":[{"internalType":"bytes32","name":"key","type":"bytes32"},{"internalType":"bytes","name":"value","type":"bytes"}],"internalType":"struct AccountMetadata[]","name":"accountMetadata","type":"tuple[]"}],"name":"emitAccountMetadata","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"internalType":"uint256","name":"receiver","type":"uint256"},{"internalType":"contract IERC20","name":"erc20","type":"address"},{"internalType":"uint128","name":"amt","type":"uint128"}],"name":"give","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pauser","type":"address"}],"name":"grantPauser","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"internalType":"uint32","name":"weight","type":"uint32"}],"internalType":"struct SplitsReceiver[]","name":"receivers","type":"tuple[]"}],"name":"hashSplits","outputs":[{"internalType":"bytes32","name":"receiversHash","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"internalType":"StreamConfig","name":"config","type":"uint256"}],"internalType":"struct StreamReceiver[]","name":"receivers","type":"tuple[]"}],"name":"hashStreams","outputs":[{"internalType":"bytes32","name":"streamsHash","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes32","name":"oldStreamsHistoryHash","type":"bytes32"},{"internalType":"bytes32","name":"streamsHash","type":"bytes32"},{"internalType":"uint32","name":"updateTime","type":"uint32"},{"internalType":"uint32","name":"maxEnd","type":"uint32"}],"name":"hashStreamsHistory","outputs":[{"internalType":"bytes32","name":"streamsHistoryHash","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"implementation","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pauser","type":"address"}],"name":"isPauser","outputs":[{"internalType":"bool","name":"isAddrPauser","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minAmtPerSec","outputs":[{"internalType":"uint160","name":"","type":"uint160"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nextDriverId","outputs":[{"internalType":"uint32","name":"driverId","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newAdmin","type":"address"}],"name":"proposeNewAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"proposedAdmin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"internalType":"contract IERC20","name":"erc20","type":"address"}],"name":"receivableStreamsCycles","outputs":[{"internalType":"uint32","name":"cycles","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"internalType":"contract IERC20","name":"erc20","type":"address"},{"internalType":"uint32","name":"maxCycles","type":"uint32"}],"name":"receiveStreams","outputs":[{"internalType":"uint128","name":"receivedAmt","type":"uint128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"internalType":"contract IERC20","name":"erc20","type":"address"},{"internalType":"uint32","name":"maxCycles","type":"uint32"}],"name":"receiveStreamsResult","outputs":[{"internalType":"uint128","name":"receivableAmt","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"driverAddr","type":"address"}],"name":"registerDriver","outputs":[{"internalType":"uint32","name":"driverId","type":"uint32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pauser","type":"address"}],"name":"revokePauser","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"components":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"internalType":"uint32","name":"weight","type":"uint32"}],"internalType":"struct SplitsReceiver[]","name":"receivers","type":"tuple[]"}],"name":"setSplits","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"internalType":"contract IERC20","name":"erc20","type":"address"},{"components":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"internalType":"StreamConfig","name":"config","type":"uint256"}],"internalType":"struct StreamReceiver[]","name":"currReceivers","type":"tuple[]"},{"internalType":"int128","name":"balanceDelta","type":"int128"},{"components":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"internalType":"StreamConfig","name":"config","type":"uint256"}],"internalType":"struct StreamReceiver[]","name":"newReceivers","type":"tuple[]"},{"internalType":"uint32","name":"maxEndHint1","type":"uint32"},{"internalType":"uint32","name":"maxEndHint2","type":"uint32"}],"name":"setStreams","outputs":[{"internalType":"int128","name":"realBalanceDelta","type":"int128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"internalType":"contract IERC20","name":"erc20","type":"address"},{"components":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"internalType":"uint32","name":"weight","type":"uint32"}],"internalType":"struct SplitsReceiver[]","name":"currReceivers","type":"tuple[]"}],"name":"split","outputs":[{"internalType":"uint128","name":"collectableAmt","type":"uint128"},{"internalType":"uint128","name":"splitAmt","type":"uint128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"components":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"internalType":"uint32","name":"weight","type":"uint32"}],"internalType":"struct SplitsReceiver[]","name":"currReceivers","type":"tuple[]"},{"internalType":"uint128","name":"amount","type":"uint128"}],"name":"splitResult","outputs":[{"internalType":"uint128","name":"collectableAmt","type":"uint128"},{"internalType":"uint128","name":"splitAmt","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"accountId","type":"uint256"}],"name":"splitsHash","outputs":[{"internalType":"bytes32","name":"currSplitsHash","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"internalType":"contract IERC20","name":"erc20","type":"address"}],"name":"splittable","outputs":[{"internalType":"uint128","name":"amt","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"internalType":"contract IERC20","name":"erc20","type":"address"},{"internalType":"uint256","name":"senderId","type":"uint256"},{"internalType":"bytes32","name":"historyHash","type":"bytes32"},{"components":[{"internalType":"bytes32","name":"streamsHash","type":"bytes32"},{"components":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"internalType":"StreamConfig","name":"config","type":"uint256"}],"internalType":"struct StreamReceiver[]","name":"receivers","type":"tuple[]"},{"internalType":"uint32","name":"updateTime","type":"uint32"},{"internalType":"uint32","name":"maxEnd","type":"uint32"}],"internalType":"struct StreamsHistory[]","name":"streamsHistory","type":"tuple[]"}],"name":"squeezeStreams","outputs":[{"internalType":"uint128","name":"amt","type":"uint128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"internalType":"contract IERC20","name":"erc20","type":"address"},{"internalType":"uint256","name":"senderId","type":"uint256"},{"internalType":"bytes32","name":"historyHash","type":"bytes32"},{"components":[{"internalType":"bytes32","name":"streamsHash","type":"bytes32"},{"components":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"internalType":"StreamConfig","name":"config","type":"uint256"}],"internalType":"struct StreamReceiver[]","name":"receivers","type":"tuple[]"},{"internalType":"uint32","name":"updateTime","type":"uint32"},{"internalType":"uint32","name":"maxEnd","type":"uint32"}],"internalType":"struct StreamsHistory[]","name":"streamsHistory","type":"tuple[]"}],"name":"squeezeStreamsResult","outputs":[{"internalType":"uint128","name":"amt","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"accountId","type":"uint256"},{"internalType":"contract IERC20","name":"erc20","type":"address"}],"name":"streamsState","outputs":[{"internalType":"bytes32","name":"streamsHash","type":"bytes32"},{"internalType":"bytes32","name":"streamsHistoryHash","type":"bytes32"},{"internalType":"uint32","name":"updateTime","type":"uint32"},{"internalType":"uint128","name":"balance","type":"uint128"},{"internalType":"uint32","name":"maxEnd","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"driverId","type":"uint32"},{"internalType":"address","name":"newDriverAddr","type":"address"}],"name":"updateDriverAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"}],"name":"upgradeTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"erc20","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"amt","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]

Deployed Bytecode

0x608060405260043610610324575f3560e01c80637dd3f81c116101a7578063b187bd26116100e7578063f0f4fd5e11610092578063f851a4401161006d578063f851a44014610add578063f98e7e1d14610af1578063fa93c0a214610b10578063ff27d01914610b2f575f80fd5b8063f0f4fd5e14610a8b578063f11d513914610aaa578063f4e45f2d14610abe575f80fd5b8063c82051dd116100c2578063c82051dd14610a1a578063d9caed1214610a4d578063d9e0107014610a6c575f80fd5b8063b187bd2614610993578063b3a3a573146109c9578063c1a96fe2146109fb575f80fd5b80638cd771801161015257806398aba1cf1161012d57806398aba1cf14610906578063a63767461461093f578063a69aff3c1461095e578063aeefca1c14610974575f80fd5b80638cd77180146108b45780638d3c100a146108d35780638e48a7e5146108f2575f80fd5b80638456cb59116101825780638456cb59146107ad578063879db483146107c15780638bad0c0a146108a0575f80fd5b80637dd3f81c146107135780637e5b5a83146107325780637fe76df01461078e575f80fd5b80633659cfe61161027257806352d1902d1161021d5780635c60da1b116101f85780635c60da1b1461068e578063631d669c146106a257806369610257146106d557806374dd0565146106f4575f80fd5b806352d1902d146106275780635429f17514610649578063577e012c1461066f575f80fd5b8063444e249f1161024d578063444e249f146105c257806346fbf68e146105e55780634f1ef28614610614575f80fd5b80633659cfe614610578578063387d2a2f146105975780633f4ba83a146105ae575f80fd5b80631ec026c8116102d257806327e235e3116102ad57806327e235e31461048e578063302dea391461050657806332f751ec14610525575f80fd5b80631ec026c814610419578063202bbca1146104505780632776f94c1461046f575f80fd5b80630e18b681116103025780630e18b681146103925780630ea2063a146103a657806319af3267146103e5575f80fd5b806302cfc7531461032857806309c1d95f1461034957806309d48a9414610368575b5f80fd5b348015610333575f80fd5b506103476103423660046153bd565b610b43565b005b348015610354575f80fd5b50610347610363366004615415565b610bd9565b348015610373575f80fd5b5061037c610ce9565b6040516103899190615430565b60405180910390f35b34801561039d575f80fd5b50610347610d1c565b3480156103b1575f80fd5b506103c56103c036600461547c565b610db2565b604080516001600160801b03938416815292909116602083015201610389565b3480156103f0575f80fd5b506104046103ff3660046154d1565b610e44565b60405163ffffffff9091168152602001610389565b348015610424575f80fd5b506104386104333660046154d1565b610e58565b6040516001600160801b039091168152602001610389565b34801561045b575f80fd5b5061043861046a36600461557a565b610ebe565b34801561047a575f80fd5b506104386104893660046156c7565b610edb565b348015610499575f80fd5b506103c56104a8366004615415565b6001600160a01b03165f90815260027ff94794517c2a8c0bbc93f8232e73a9c0381c83eecda81a4f8a722dc7055c6b2c0160205260409020546001600160801b03808216927001000000000000000000000000000000009092041690565b348015610511575f80fd5b5061043861052036600461572d565b610ef3565b348015610530575f80fd5b507fe8b5d5c9b680c1fe7b4e140cb3994baa0dd775346136353dbe31ddb68b924fa7600301546001600160a01b03165b6040516001600160a01b039091168152602001610389565b348015610583575f80fd5b50610347610592366004615415565b610fa4565b3480156105a2575f80fd5b50610560633b9aca0081565b3480156105b9575f80fd5b50610347611117565b3480156105cd575f80fd5b506104386f7fffffffffffffffffffffffffffffff81565b3480156105f0575f80fd5b506106046105ff366004615415565b611269565b6040519015158152602001610389565b610347610622366004615768565b611297565b348015610632575f80fd5b5061063b6113fc565b604051908152602001610389565b348015610654575f80fd5b5061065d600981565b60405160ff9091168152602001610389565b34801561067a575f80fd5b5061063b61068936600461580a565b6114c0565b348015610699575f80fd5b506105606114ca565b3480156106ad575f80fd5b506104047f0000000000000000000000000000000000000000000000000000000000093a8081565b3480156106e0575f80fd5b506103476106ef36600461583c565b6114d3565b3480156106ff575f80fd5b5061063b61070e3660046158b4565b6115dd565b34801561071e575f80fd5b5061063b61072d3660046158cb565b61160f565b34801561073d575f80fd5b5061056061074c366004615903565b63ffffffff165f90815260017ff94794517c2a8c0bbc93f8232e73a9c0381c83eecda81a4f8a722dc7055c6b2c0160205260409020546001600160a01b031690565b348015610799575f80fd5b506103476107a8366004615415565b611657565b3480156107b8575f80fd5b50610347611767565b3480156107cc575f80fd5b506108666107db3660046154d1565b6001600160a01b03165f9081527fc657394ed3e88f77dbba29657b638cd4d5f65812a0ec8f97c1d4ebf37caa3f13602090815260408083209383529290522060028101548154600390920154909263ffffffff64010000000083048116926001600160801b036c01000000000000000000000000820416926801000000000000000090910490911690565b60408051958652602086019490945263ffffffff928316938501939093526001600160801b0316606084015216608082015260a001610389565b3480156108ab575f80fd5b506103476118bd565b3480156108bf575f80fd5b5061063b6108ce36600461591c565b611925565b3480156108de575f80fd5b506104386108ed3660046154d1565b61192f565b3480156108fd575f80fd5b5061065d60e081565b348015610911575f80fd5b507ff94794517c2a8c0bbc93f8232e73a9c0381c83eecda81a4f8a722dc7055c6b2c5463ffffffff16610404565b34801561094a575f80fd5b50610347610959366004615415565b6119e4565b348015610969575f80fd5b50610404620f424081565b34801561097f575f80fd5b5061034761098e36600461594e565b611ad4565b34801561099e575f80fd5b507fe8b5d5c9b680c1fe7b4e140cb3994baa0dd775346136353dbe31ddb68b924fa75460ff16610604565b3480156109d4575f80fd5b506109e86109e3366004615978565b611bea565b604051600f9190910b8152602001610389565b348015610a06575f80fd5b50610438610a1536600461572d565b611cc2565b348015610a25575f80fd5b506105607f000000000000000000000000000000000000000000000000000000000000067681565b348015610a58575f80fd5b50610347610a67366004615a2c565b611cdb565b348015610a77575f80fd5b50610347610a86366004615a80565b611e0a565b348015610a96575f80fd5b50610404610aa5366004615415565b611eb0565b348015610ab5575f80fd5b5061063b60c881565b348015610ac9575f80fd5b506103c5610ad8366004615aba565b612046565b348015610ae8575f80fd5b50610560612053565b348015610afc575f80fd5b50610438610b0b3660046154d1565b61205c565b348015610b1b575f80fd5b50610438610b2a36600461557a565b6120ae565b348015610b3a575f80fd5b5061063b606481565b7fe8b5d5c9b680c1fe7b4e140cb3994baa0dd775346136353dbe31ddb68b924fa75460ff1615610bba5760405162461bcd60e51b815260206004820152600f60248201527f436f6e747261637420706175736564000000000000000000000000000000000060448201526064015b60405180910390fd5b8160e081901c610bc981612163565b610bd38484612200565b50505050565b33610be2612053565b6001600160a01b031614610c385760405162461bcd60e51b815260206004820152601460248201527f43616c6c6572206e6f74207468652061646d696e0000000000000000000000006044820152606401610bb1565b610c6560017fe8b5d5c9b680c1fe7b4e140cb3994baa0dd775346136353dbe31ddb68b924fa7018261227e565b610cb15760405162461bcd60e51b815260206004820152601b60248201527f4164647265737320616c726561647920697320612070617573657200000000006044820152606401610bb1565b60405133906001600160a01b038316907fbb7fff487ca65a5841fe463ac801812d2aeb3c2059f6e44b2b3cdab8ee7c3db0905f90a350565b6060610d177fe8b5d5c9b680c1fe7b4e140cb3994baa0dd775346136353dbe31ddb68b924fa7600101612292565b905090565b33610d5160037fe8b5d5c9b680c1fe7b4e140cb3994baa0dd775346136353dbe31ddb68b924fa701546001600160a01b031690565b6001600160a01b031614610da75760405162461bcd60e51b815260206004820152601d60248201527f43616c6c6572206e6f74207468652070726f706f7365642061646d696e0000006044820152606401610bb1565b610db03361229e565b565b5f80610ddf7fe8b5d5c9b680c1fe7b4e140cb3994baa0dd775346136353dbe31ddb68b924fa75460ff1690565b15610e2c5760405162461bcd60e51b815260206004820152600f60248201527f436f6e74726163742070617573656400000000000000000000000000000000006044820152606401610bb1565b610e3785858561238f565b915091505b935093915050565b5f610e4f838361259f565b90505b92915050565b5f8281527f4a4773e83022ffd434f8ef4bde63b284fd5172dc2a7b5e180d8b7135f9af9313602090815260408083206001600160a01b038516845260010190915281205470010000000000000000000000000000000090046001600160801b0316610e4f565b5f610ecc86868686866125b6565b50929998505050505050505050565b5f610ee88585858561282b565b90505b949350505050565b5f610f1f7fe8b5d5c9b680c1fe7b4e140cb3994baa0dd775346136353dbe31ddb68b924fa75460ff1690565b15610f6c5760405162461bcd60e51b815260206004820152600f60248201527f436f6e74726163742070617573656400000000000000000000000000000000006044820152606401610bb1565b610f7784848461292d565b90506001600160801b03811615610f9d57610f928382612ac0565b610f9d848483612b88565b9392505050565b6001600160a01b037f000000000000000000000000b0c9b6d67608be300398d0e4fb0cca3891e1b33f1630036110425760405162461bcd60e51b815260206004820152602c60248201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060448201527f64656c656761746563616c6c00000000000000000000000000000000000000006064820152608401610bb1565b7f000000000000000000000000b0c9b6d67608be300398d0e4fb0cca3891e1b33f6001600160a01b0316611074612be4565b6001600160a01b0316146110f05760405162461bcd60e51b815260206004820152602c60248201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060448201527f6163746976652070726f787900000000000000000000000000000000000000006064820152608401610bb1565b6110f981612c16565b604080515f8082526020820190925261111491839190612c75565b50565b33611120612053565b6001600160a01b03161480611139575061113933611269565b6111855760405162461bcd60e51b815260206004820181905260248201527f43616c6c6572206e6f74207468652061646d696e206f722061207061757365726044820152606401610bb1565b7fe8b5d5c9b680c1fe7b4e140cb3994baa0dd775346136353dbe31ddb68b924fa75460ff166111f65760405162461bcd60e51b815260206004820152601360248201527f436f6e7472616374206e6f7420706175736564000000000000000000000000006044820152606401610bb1565b7fe8b5d5c9b680c1fe7b4e140cb3994baa0dd775346136353dbe31ddb68b924fa780547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016905560405133907f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa905f90a2565b5f610e5260017fe8b5d5c9b680c1fe7b4e140cb3994baa0dd775346136353dbe31ddb68b924fa70183612e1a565b6001600160a01b037f000000000000000000000000b0c9b6d67608be300398d0e4fb0cca3891e1b33f1630036113355760405162461bcd60e51b815260206004820152602c60248201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060448201527f64656c656761746563616c6c00000000000000000000000000000000000000006064820152608401610bb1565b7f000000000000000000000000b0c9b6d67608be300398d0e4fb0cca3891e1b33f6001600160a01b0316611367612be4565b6001600160a01b0316146113e35760405162461bcd60e51b815260206004820152602c60248201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060448201527f6163746976652070726f787900000000000000000000000000000000000000006064820152608401610bb1565b6113ec82612c16565b6113f882826001612c75565b5050565b5f306001600160a01b037f000000000000000000000000b0c9b6d67608be300398d0e4fb0cca3891e1b33f161461149b5760405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c60448201527f6c6564207468726f7567682064656c656761746563616c6c00000000000000006064820152608401610bb1565b507f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc90565b5f610e5282612e3b565b5f610d17612be4565b7fe8b5d5c9b680c1fe7b4e140cb3994baa0dd775346136353dbe31ddb68b924fa75460ff16156115455760405162461bcd60e51b815260206004820152600f60248201527f436f6e74726163742070617573656400000000000000000000000000000000006044820152606401610bb1565b8260e081901c61155481612163565b5f5b838110156115d5573685858381811061157157611571615b04565b90506020028101906115839190615b31565b90508035877f104963f2a5dc192f8154d2714d24eff1983117445036fb4dc408713d73b36aa56115b66020850185615b6d565b6040516115c4929190615bce565b60405180910390a350600101611556565b505050505050565b5f8181527f4a4773e83022ffd434f8ef4bde63b284fd5172dc2a7b5e180d8b7135f9af93136020526040812054610e52565b60408051602080820187905281830186905263ffffffff808616606084015284166080808401919091528351808403909101815260a090920190925280519101205f90610ee8565b33611660612053565b6001600160a01b0316146116b65760405162461bcd60e51b815260206004820152601460248201527f43616c6c6572206e6f74207468652061646d696e0000000000000000000000006044820152606401610bb1565b6116e360017fe8b5d5c9b680c1fe7b4e140cb3994baa0dd775346136353dbe31ddb68b924fa70182612e79565b61172f5760405162461bcd60e51b815260206004820152601760248201527f41646472657373206973206e6f742061207061757365720000000000000000006044820152606401610bb1565b60405133906001600160a01b038316907ffd55549bcbafb9531a61db3cfb88d1cca64e215b12def56e6ea913fe1ac91fd2905f90a350565b33611770612053565b6001600160a01b03161480611789575061178933611269565b6117d55760405162461bcd60e51b815260206004820181905260248201527f43616c6c6572206e6f74207468652061646d696e206f722061207061757365726044820152606401610bb1565b7fe8b5d5c9b680c1fe7b4e140cb3994baa0dd775346136353dbe31ddb68b924fa75460ff16156118475760405162461bcd60e51b815260206004820152600f60248201527f436f6e74726163742070617573656400000000000000000000000000000000006044820152606401610bb1565b7fe8b5d5c9b680c1fe7b4e140cb3994baa0dd775346136353dbe31ddb68b924fa780547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016600117905560405133907f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258905f90a2565b336118c6612053565b6001600160a01b03161461191c5760405162461bcd60e51b815260206004820152601460248201527f43616c6c6572206e6f74207468652061646d696e0000000000000000000000006044820152606401610bb1565b610db05f61229e565b5f610e5282612e8d565b5f61195b7fe8b5d5c9b680c1fe7b4e140cb3994baa0dd775346136353dbe31ddb68b924fa75460ff1690565b156119a85760405162461bcd60e51b815260206004820152600f60248201527f436f6e74726163742070617573656400000000000000000000000000000000006044820152606401610bb1565b8260e081901c6119b781612163565b6119c18585612eae565b92506001600160801b038316156119dc576119dc8484612f58565b505092915050565b336119ed612053565b6001600160a01b031614611a435760405162461bcd60e51b815260206004820152601460248201527f43616c6c6572206e6f74207468652061646d696e0000000000000000000000006044820152606401610bb1565b6040516001600160a01b0382169033907fed2d93e7985747cd1a4a093c2cc3bb73d0f177b81bdfd26020e8f20a97e8112e905f90a37fe8b5d5c9b680c1fe7b4e140cb3994baa0dd775346136353dbe31ddb68b924fa760030180547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0392909216919091179055565b7fe8b5d5c9b680c1fe7b4e140cb3994baa0dd775346136353dbe31ddb68b924fa75460ff1615611b465760405162461bcd60e51b815260206004820152600f60248201527f436f6e74726163742070617573656400000000000000000000000000000000006044820152606401610bb1565b611b4f82612163565b807ff94794517c2a8c0bbc93f8232e73a9c0381c83eecda81a4f8a722dc7055c6b2c63ffffffff84165f818152600192909201602052604080832080547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b03958616179055519284169233927f5a2904d4b2f1a05120ab193be9a140a7ad8d310e3bb91af232d47f2f55fa388291a45050565b5f611c167fe8b5d5c9b680c1fe7b4e140cb3994baa0dd775346136353dbe31ddb68b924fa75460ff1690565b15611c635760405162461bcd60e51b815260206004820152600f60248201527f436f6e74726163742070617573656400000000000000000000000000000000006044820152606401610bb1565b8760e081901c611c7281612163565b5f87600f0b1315611c8757611c878988612fea565b611c968a8a8a8a8a8a8a613046565b92505f83600f0b1215611cb557611cb589611cb085615c29565b613436565b5050979650505050505050565b5f611cce848484613488565b5092979650505050505050565b6001600160a01b0383165f90815260027ff94794517c2a8c0bbc93f8232e73a9c0381c83eecda81a4f8a722dc7055c6b2c0160205260408120546001600160801b038082169270010000000000000000000000000000000090920416908183611d438861357d565b611d4d9190615c65565b611d579190615c65565b905080841115611da95760405162461bcd60e51b815260206004820152601a60248201527f5769746864726177616c20616d6f756e7420746f6f20686967680000000000006044820152606401610bb1565b846001600160a01b0316866001600160a01b03167fd1c19fbcd4551a5edfb66d43d2e337c04837afda3482b42bdf569a8fccdae5fb86604051611dee91815260200190565b60405180910390a36115d56001600160a01b03871686866135fe565b7fe8b5d5c9b680c1fe7b4e140cb3994baa0dd775346136353dbe31ddb68b924fa75460ff1615611e7c5760405162461bcd60e51b815260206004820152600f60248201527f436f6e74726163742070617573656400000000000000000000000000000000006044820152606401610bb1565b8360e081901c611e8b81612163565b6001600160801b03831615611ea457611ea4848461367e565b6115d5868686866136f2565b5f611edc7fe8b5d5c9b680c1fe7b4e140cb3994baa0dd775346136353dbe31ddb68b924fa75460ff1690565b15611f295760405162461bcd60e51b815260206004820152600f60248201527f436f6e74726163742070617573656400000000000000000000000000000000006044820152606401610bb1565b6001600160a01b038216611f7f5760405162461bcd60e51b815260206004820152601f60248201527f447269766572207265676973746572656420666f7220302061646472657373006044820152606401610bb1565b7ff94794517c2a8c0bbc93f8232e73a9c0381c83eecda81a4f8a722dc7055c6b2c805463ffffffff16815f611fb383615c78565b82546101009290920a63ffffffff81810219909316918316021790915581165f81815260018401602052604080822080547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0389169081179091559051939550927f749894a8ffc45e1d212322a05461004c7bc358b4d36325766b63526b1ccf8bdf9190a350919050565b5f80610e3785858561374e565b5f610d176137e0565b5f8281527f4a4773e83022ffd434f8ef4bde63b284fd5172dc2a7b5e180d8b7135f9af9313602090815260408083206001600160a01b03851684526001019091528120546001600160801b0316610e4f565b5f6120da7fe8b5d5c9b680c1fe7b4e140cb3994baa0dd775346136353dbe31ddb68b924fa75460ff1690565b156121275760405162461bcd60e51b815260206004820152600f60248201527f436f6e74726163742070617573656400000000000000000000000000000000006044820152606401610bb1565b6121348686868686613807565b90506001600160801b0381161561215a5761214f8582612ac0565b61215a868683612b88565b95945050505050565b336121aa8263ffffffff165f90815260017ff94794517c2a8c0bbc93f8232e73a9c0381c83eecda81a4f8a722dc7055c6b2c0160205260409020546001600160a01b031690565b6001600160a01b0316146111145760405162461bcd60e51b815260206004820152601b60248201527f43616c6c61626c65206f6e6c79206279207468652064726976657200000000006044820152606401610bb1565b5f8281527f4a4773e83022ffd434f8ef4bde63b284fd5172dc2a7b5e180d8b7135f9af9313602052604081209061223683612e3b565b905080847f8af909ffa127c333d18602940f67f3fd57368f15b6860033919818daa60c168460405160405180910390a381548114610bd35761227883826139f6565b90555050565b5f610e4f836001600160a01b038416613bdd565b60605f610f9d83613c29565b7f7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f6122c7612053565b604080516001600160a01b03928316815291841660208301520160405180910390a160037fe8b5d5c9b680c1fe7b4e140cb3994baa0dd775346136353dbe31ddb68b924fa70180547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055807fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035b80547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b039290921691909117905550565b5f8061239b8584613c82565b5f8581527f4a4773e83022ffd434f8ef4bde63b284fd5172dc2a7b5e180d8b7135f9af9313602090815260408083206001600160a01b0388168452600101909152812080546001600160801b03169350908390036123ff575f809250925050610e3c565b80547fffffffffffffffffffffffffffffffff000000000000000000000000000000001681555f805b85518110156125105785818151811061244357612443615b04565b60200260200101516020015163ffffffff16820191505f84620f424063ffffffff1684886001600160801b0316026001600160a01b03168161248757612487615c9a565b0403905080850194505f8783815181106124a3576124a3615b04565b60200260200101515f015190506124bb818a84612b88565b6040516001600160801b03831681526001600160a01b038a169082908c907f0f5c5377da15431a8fe400f76e6631e1d39a8c4b98de9e11d3386a181af86b8e9060200160405180910390a45050600101612428565b505080546001600160801b0370010000000000000000000000000000000080830482169585900395860182160291161781556040516001600160a01b0386169087907fe21d6055950f21e524e22827c40bf5a9358c4a24a90b110fae69fb3011a2a9d99061258e9087906001600160801b0391909116815260200190565b60405180910390a350935093915050565b5f805f6125ac8585613d05565b0395945050505050565b5f8060608082807fc657394ed3e88f77dbba29657b638cd4d5f65812a0ec8f97c1d4ebf37caa3f136001600160a01b038b165f908152602091825260408082208c835290925220805490915061260f9089908990613d89565b92506001915061261d613f44565b600382015463ffffffff918216640100000000909104909116106126695760038101547c0100000000000000000000000000000000000000000000000000000000900463ffffffff1691505b50855167ffffffffffffffff81111561268457612684615246565b6040519080825280602002602001820160405280156126ad578160200160208202803683370190505b506001600160a01b038a165f9081527fc657394ed3e88f77dbba29657b638cd4d5f65812a0ec8f97c1d4ebf37caa3f13602090815260408083208e845282528083208c8452600190810190925290912091945042905b885181111580156127145750838111155b1561281b575f89828b51038151811061272f5761272f615b04565b602002602001015190508060200151515f1461280d575f84838703640100000000811061275e5761275e615b04565b600891828204019190066004029054906101000a900463ffffffff169050612784613f44565b63ffffffff168163ffffffff1610156127a25761279f613f44565b90505b816040015163ffffffff168163ffffffff1610156127c1575060408101515b8363ffffffff168163ffffffff16101561280b5782888a806001019b50815181106127ee576127ee615b04565b6020026020010181815250506128068f838387613f86565b8a0199505b505b604001519150600101612703565b5050509550955095509550959050565b6001600160a01b0383165f9081527fc657394ed3e88f77dbba29657b638cd4d5f65812a0ec8f97c1d4ebf37caa3f136020908152604080832087845290915281206003810154640100000000900463ffffffff90811690841610156128d25760405162461bcd60e51b815260206004820181905260248201527f54696d657374616d70206265666f726520746865206c617374207570646174656044820152606401610bb1565b6128dc84826140d4565b6003810154612923906001600160801b036c010000000000000000000000008204169063ffffffff640100000000820481169168010000000000000000900416878761412f565b9695505050505050565b5f805f805f61293d888888613488565b93985091965094509250905063ffffffff80841690831614612a61575f7fc657394ed3e88f77dbba29657b638cd4d5f65812a0ec8f97c1d4ebf37caa3f136001600160a01b0389165f908152602091825260408082208c8352909252206003810180547fffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000001663ffffffff8616179055905060048101845b8463ffffffff168163ffffffff161015612a055763ffffffff81165f908152602083905260408120556001016129d4565b5082600f0b5f14612a5e5763ffffffff84165f90815260208290526040902080546001600160801b03600f82900b8601167fffffffffffffffffffffffffffffffff000000000000000000000000000000009091161790555b50505b604080516001600160801b038716815263ffffffff861660208201526001600160a01b038916918a917f6c91d10ec47151439d4dc2df77dbc3a78e8502b9176aeb4d6ab0b1823d95d34c910160405180910390a3505050509392505050565b6001600160a01b0382165f90815260027ff94794517c2a8c0bbc93f8232e73a9c0381c83eecda81a4f8a722dc7055c6b2c0160205260408120805490918391839190612b169084906001600160801b0316615cc7565b92506101000a8154816001600160801b0302191690836001600160801b0316021790555081815f0160108282829054906101000a90046001600160801b0316612b5f9190615ce7565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550505050565b5f8381527f4a4773e83022ffd434f8ef4bde63b284fd5172dc2a7b5e180d8b7135f9af9313602090815260408083206001600160a01b038616845260010190915281208054839290612b5f9084906001600160801b0316615ce7565b5f7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5b546001600160a01b0316919050565b33612c1f612053565b6001600160a01b0316146111145760405162461bcd60e51b815260206004820152601460248201527f43616c6c6572206e6f74207468652061646d696e0000000000000000000000006044820152606401610bb1565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff1615612cad57612ca883614195565b505050565b826001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015612d07575060408051601f3d908101601f19168201909252612d0491810190615d07565b60015b612d795760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201527f6f6e206973206e6f7420555550530000000000000000000000000000000000006064820152608401610bb1565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc8114612e0e5760405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f7860448201527f6961626c655555494400000000000000000000000000000000000000000000006064820152608401610bb1565b50612ca8838383614239565b6001600160a01b0381165f9081526001830160205260408120541515610e4f565b5f81515f03612e4b57505f919050565b81604051602001612e5c9190615d1e565b604051602081830303815290604052805190602001209050919050565b5f610e4f836001600160a01b03841661425d565b5f81515f03612e9d57505f919050565b81604051602001612e5c9190615d72565b5f8281527f4a4773e83022ffd434f8ef4bde63b284fd5172dc2a7b5e180d8b7135f9af9313602090815260408083206001600160a01b038516808552600190910183529281902080546001600160801b038082168355835170010000000000000000000000000000000090920416808252925192949193919287927fda8ee04f8f2a5164dfc0b6c5ba78ebe975683b40c2500950b514e7444d3f541b928290030190a35092915050565b807ff94794517c2a8c0bbc93f8232e73a9c0381c83eecda81a4f8a722dc7055c6b2c6001600160a01b0384165f908152600291909101602052604090208054601090612fc290849070010000000000000000000000000000000090046001600160801b0316615cc7565b92506101000a8154816001600160801b0302191690836001600160801b031602179055505050565b612ff48282614347565b6001600160a01b0382165f90815260027ff94794517c2a8c0bbc93f8232e73a9c0381c83eecda81a4f8a722dc7055c6b2c01602052604081208054839290612fc29084906001600160801b0316615ce7565b6001600160a01b0386165f9081527fc657394ed3e88f77dbba29657b638cd4d5f65812a0ec8f97c1d4ebf37caa3f13602090815260408083208a8452909152812061309187826140d4565b6003810154640100000000810463ffffffff908116915f9182916801000000000000000081049091169082906130e3906c0100000000000000000000000090046001600160801b031686848f4261412f565b90508a9650805f03600f0b87600f0b12156130fe57805f0396505b868101935061310f848b8b8b61447d565b6001600160a01b038e165f9081527fc657394ed3e88f77dbba29657b638cd4d5f65812a0ec8f97c1d4ebf37caa3f1360205260409020909350613156908d87858e886145db565b505061315f4290565b6003850180547fffffffffffffffffffffffffffffffffffffffff0000000000000000ffffffff1664010000000063ffffffff938416027fffffffffffffffffffffffffffffffffffffffff00000000ffffffffffffffff16176801000000000000000092841692909202919091177fffffffff00000000000000000000000000000000ffffffffffffffffffffffff166c010000000000000000000000006001600160801b0385160217905583548015801590613239575061322142614903565b63ffffffff1661323085614903565b63ffffffff1614155b15613288576003850180547bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167c02000000000000000000000000000000000000000000000000000000001790556132e2565b600385018054600163ffffffff7c010000000000000000000000000000000000000000000000000000000080840482169290920116027bffffffffffffffffffffffffffffffffffffffffffffffffffffffff9091161790555b5f6132ec8a612e8d565b60408051602080820186905281830184905263ffffffff428116606084015287166080808401919091528351808403909101815260a09092019092528051910120909150865f0181905550808d6001600160a01b03168f7f8b23331305d892ba8ae0d5ad747051e5d007302b8b0eba8f45ebdc5f82962f6d858888604051613396939291909283526001600160801b0391909116602083015263ffffffff16604082015260600190565b60405180910390a48560020154811461342557600286018190555f5b8a51811015613423575f8b82815181106133ce576133ce615b04565b60200260200101519050805f0151837f68f8694c2f9c9f45540d88ae439aaf8a7c84d05392f23a12e2ebdc75ed31ad1e836020015160405161341291815260200190565b60405180910390a3506001016133b2565b505b505050505050979650505050505050565b6001600160a01b0382165f90815260027ff94794517c2a8c0bbc93f8232e73a9c0381c83eecda81a4f8a722dc7055c6b2c01602052604081208054839290612fc29084906001600160801b0316615cc7565b5f805f805f6134978888613d05565b909350915063ffffffff80871684840390911611156134bd578583830303935083820391505b6001600160a01b0387165f9081527fc657394ed3e88f77dbba29657b638cd4d5f65812a0ec8f97c1d4ebf37caa3f13602090815260408083208b84529091529020600401835b8363ffffffff168163ffffffff1610156135705763ffffffff81165f9081526020838152604091829020825180840190935254600f81810b808552700100000000000000000000000000000000909204900b92909101829052939093019687019690920191600101613503565b5050939792965093509350565b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201525f906001600160a01b038316906370a0823190602401602060405180830381865afa1580156135da573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e529190615d07565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb00000000000000000000000000000000000000000000000000000000179052612ca890849061494a565b6136888282614347565b807ff94794517c2a8c0bbc93f8232e73a9c0381c83eecda81a4f8a722dc7055c6b2c6001600160a01b0384165f908152600291909101602052604090208054601090612fc290849070010000000000000000000000000000000090046001600160801b0316615ce7565b6136fd838383612b88565b6040516001600160801b03821681526001600160a01b03831690849086907f30e2797f85108749fb58c0e7da3e229828df7b148755f420c96d565c7ab6d8329060200160405180910390a450505050565b5f8061375a8585613c82565b826001600160801b03165f0361377457505f905080610e3c565b5f805b85518110156137b55785818151811061379257613792615b04565b60200260200101516020015163ffffffff16820191508080600101915050613777565b50620f42406001600160a01b036001600160801b038616830216049150818403925050935093915050565b5f7fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103612c07565b5f806060805f61381a8a8a8a8a8a6125b6565b9398509196509450925090505f8467ffffffffffffffff81111561384057613840615246565b604051908082528060200260200182016040528015613869578160200160208202803683370190505b506001600160a01b038b165f9081527fc657394ed3e88f77dbba29657b638cd4d5f65812a0ec8f97c1d4ebf37caa3f13602090815260408083208f845282528083208d845260018101909252822092935091905b87811015613971575f876001838b0303815181106138dd576138dd615b04565b602002602001015190508681885103815181106138fc576138fc615b04565b602002602001015185838151811061391657613916615b04565b60209081029190910101524283828803640100000000811061393a5761393a615b04565b600891828204019190066004026101000a81548163ffffffff021916908363ffffffff1602179055505080806001019150506138bd565b505f61397b613f44565b90506139a0838283600101633b9aca008d6001600160801b0316025f0360130b614a30565b8b8d6001600160a01b03168f7fa02343a8d410763ab5aa692d1838108ac9ceaadf187c5071fa7dbbd10d20c2958c886040516139dd929190615db3565b60405180910390a4505050505050505095945050505050565b60c882511115613a485760405162461bcd60e51b815260206004820152601960248201527f546f6f206d616e792073706c69747320726563656976657273000000000000006044820152606401610bb1565b5f80805b8451811015613b7f575f858281518110613a6857613a68615b04565b602002602001015190505f816020015190508063ffffffff165f03613acf5760405162461bcd60e51b815260206004820152601e60248201527f53706c69747320726563656976657220776569676874206973207a65726f00006044820152606401610bb1565b815163ffffffff821695909501948315613b3257808510613b325760405162461bcd60e51b815260206004820152601b60248201527f53706c69747320726563656976657273206e6f7420736f7274656400000000006044820152606401610bb1565b60405163ffffffff831681529094508490819088907feb9ab17f5929fcbcb68f4adf670d54c00ab00934512a4c92938d59b43a0463ea9060200160405180910390a3505050600101613a4c565b50620f424067ffffffffffffffff83161115610bd35760405162461bcd60e51b815260206004820152601b60248201527f53706c69747320776569676874732073756d20746f6f206869676800000000006044820152606401610bb1565b5f818152600183016020526040812054613c2257508154600181810184555f848152602080822090930184905584548482528286019093526040902091909155610e52565b505f610e52565b6060815f01805480602002602001604051908101604052809291908181526020018280548015613c7657602002820191905f5260205f20905b815481526020019060010190808311613c62575b50505050509050919050565b5f8281527f4a4773e83022ffd434f8ef4bde63b284fd5172dc2a7b5e180d8b7135f9af93136020526040902054613cb882612e3b565b146113f85760405162461bcd60e51b815260206004820181905260248201527f496e76616c69642063757272656e742073706c697473207265636569766572736044820152606401610bb1565b6001600160a01b0381165f9081527fc657394ed3e88f77dbba29657b638cd4d5f65812a0ec8f97c1d4ebf37caa3f136020908152604080832085845290915281206003015463ffffffff1690613d5a42614903565b905063ffffffff82161580613d7a57508163ffffffff168163ffffffff16105b15613d825750805b9250929050565b6060825167ffffffffffffffff811115613da557613da5615246565b604051908082528060200260200182016040528015613dce578160200160208202803683370190505b5090505f5b8351811015613ef4575f848281518110613def57613def615b04565b602002602001015190505f815f015190508160200151515f14613e6a578015613e5a5760405162461bcd60e51b815260206004820152601d60248201527f456e7472792077697468206861736820616e64207265636569766572730000006044820152606401610bb1565b613e678260200151612e8d565b90505b86848481518110613e7d57613e7d615b04565b602002602001018181525050613edd878284604001518560600151604080516020808201969096528082019490945263ffffffff928316606085015291166080808401919091528151808403909101815260a09092019052805191012090565b965050508080613eec90615e08565b915050613dd3565b50818414610f9d5760405162461bcd60e51b815260206004820152601760248201527f496e76616c69642073747265616d7320686973746f72790000000000000000006044820152606401610bb1565b5f4263ffffffff7f0000000000000000000000000000000000000000000000000000000000093a80811690821681613f7e57613f7e615c9a565b069003919050565b602083015180515f919082905b80821015613fdd575f600283830104905088848281518110613fb757613fb7615b04565b60200260200101515f01511015613fd357806001019250613fd7565b8091505b50613f93565b50604086015160608701515f5b84518410156140c7575f85858151811061400657614006615b04565b602002602001015190508a815f01511461402057506140c7565b5f8061402f8387878e8e614a72565b915091506140b4614044846020015160401c90565b6001600160a01b03168363ffffffff168363ffffffff16633b9aca0063ffffffff7f0000000000000000000000000000000000000000000000000000000000093a801680840685028290048184068602839004958202929092049381900492049190910391909102919091010390565b6001909701969093019250613fea915050565b9998505050505050505050565b80600201546140e283612e8d565b146113f85760405162461bcd60e51b815260206004820152601e60248201527f496e76616c69642073747265616d7320726563656976657273206c69737400006044820152606401610bb1565b845f5b835181101561418b575f84828151811061414e5761414e615b04565b602002602001015190505f80614167838a8a8c8a614a72565b9150915061417c614044846020015160401c90565b90940393505050600101614132565b5095945050505050565b6001600160a01b0381163b6142125760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201527f6f74206120636f6e7472616374000000000000000000000000000000000000006064820152608401610bb1565b807f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc612356565b61424283614b3d565b5f8251118061424e5750805b15612ca857610bd38383614b7c565b5f8181526001830160205260408120548015614337575f61427f600183615c65565b85549091505f9061429290600190615c65565b90508181146142f1575f865f0182815481106142b0576142b0615b04565b905f5260205f200154905080875f0184815481106142d0576142d0615b04565b5f918252602080832090910192909255918252600188019052604090208390555b855486908061430257614302615e3f565b600190038181905f5260205f20015f90559055856001015f8681526020019081526020015f205f905560019350505050610e52565b5f915050610e52565b5092915050565b6001600160a01b0382165f90815260027ff94794517c2a8c0bbc93f8232e73a9c0381c83eecda81a4f8a722dc7055c6b2c0160205260408120546001600160801b03808216927001000000000000000000000000000000009092048116919084166143b28385615e6c565b6143bc9190615e6c565b90506f7fffffffffffffffffffffffffffffff81111561441e5760405162461bcd60e51b815260206004820152601660248201527f546f74616c2062616c616e636520746f6f2068696768000000000000000000006044820152606401610bb1565b6144278561357d565b8111156144765760405162461bcd60e51b815260206004820152601560248201527f546f6b656e2062616c616e636520746f6f206c6f7700000000000000000000006044820152606401610bb1565b5050505050565b5f805f61448986614ba1565b915091505f6144954290565b63ffffffff1690508115806144b157506001600160801b038816155b156144c0579250610eeb915050565b63ffffffff6144da6001600160801b038a16858584614cfa565b156144ea579350610eeb92505050565b818763ffffffff161180156145045750808763ffffffff16105b1561454057614524896001600160801b031685858a63ffffffff16614cfa565b15614537578663ffffffff169150614540565b5063ffffffff86165b818663ffffffff1611801561455a5750808663ffffffff16105b156145965761457a896001600160801b031685858963ffffffff16614cfa565b1561458d578563ffffffff169150614596565b5063ffffffff85165b6002818301048281036145af579450610eeb9350505050565b6145c48a6001600160801b0316868684614cfa565b156145d1578092506145d5565b8091505b50614596565b5f805b8651604080518082019091525f808252602082015290831090811561461a5788848151811061460f5761460f615b04565b602002602001015190505b8551604080518082019091525f80825260208201529084109081156146565787858151811061464b5761464b615b04565b602002602001015190505b8380156146605750815b156146b2578051835114158061469c5750602081015160401c6001600160a01b0316614690846020015160401c90565b6001600160a01b031614155b156146b2576146ab8382614dbe565b9350831591505b8380156146bc5750815b156147b65782515f90815260208d90526040812090806146dd868e8e614de4565b915091505f806146f4866146ee4290565b8e614de4565b915091505f614707896020015160401c90565b6001600160a01b0316905061472686868561472185615e7f565b614a30565b61473286858484614a30565b5f61473c86614903565b90505f61474885614903565b90508063ffffffff168263ffffffff161180156147715750600388015463ffffffff8083169116115b156147a9576003880180547fffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000001663ffffffff83161790555b50505050505050506148d6565b831561480e5782515f90815260208d90526040812090806147d8868e8e614de4565b915091505f6147eb876020015160401c90565b6001600160a01b0316905061480584848461472185615e7f565b505050506148d6565b81156148cd5780515f90815260208d905260408120908061483084428c614de4565b915091505f614843856020015160401c90565b6001600160a01b0316905061485a84848484614a30565b5f61486484614903565b600386015490915063ffffffff1680158061488a57508163ffffffff168163ffffffff16115b156148c2576003860180547fffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000001663ffffffff84161790555b5050505050506148d6565b505050506148f9565b83156148e3576001909501945b81156148f0576001909401935b505050506145de565b5050505050505050565b5f7f0000000000000000000000000000000000000000000000000000000000093a8063ffffffff168263ffffffff168161493f5761493f615c9a565b046001019050919050565b5f61499e826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316614df79092919063ffffffff16565b905080515f14806149be5750808060200190518101906149be9190615eb5565b612ca85760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610bb1565b8163ffffffff168363ffffffff160315610bd35760048401614a598163ffffffff861684614e05565b6144768163ffffffff8516614a6d85615e7f565b614e05565b5f80614a82876020015160201c90565b91508163ffffffff165f03614a95578591505b5f614aa1886020015190565b63ffffffff84811691168101915064ffffffffff82161480614acf57508563ffffffff168164ffffffffff16115b15614add575063ffffffff85165b8463ffffffff168363ffffffff161015614af5578492505b8363ffffffff168164ffffffffff161115614b13575063ffffffff83165b8263ffffffff168164ffffffffff161015614b31575063ffffffff82165b90509550959350505050565b614b4681614195565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a250565b6060610e4f8383604051806060016040528060278152602001615f3a60279139614f0b565b60605f606483511115614bf65760405162461bcd60e51b815260206004820152601a60248201527f546f6f206d616e792073747265616d73207265636569766572730000000000006044820152606401610bb1565b825167ffffffffffffffff811115614c1057614c10615246565b604051908082528060200260200182016040528015614c39578160200160208202803683370190505b5091505f5b8351811015614cf4575f848281518110614c5a57614c5a615b04565b602002602001015190505f821115614cde57614c92856001840381518110614c8457614c84615b04565b602002602001015182614dbe565b614cde5760405162461bcd60e51b815260206004820152601c60248201527f53747265616d7320726563656976657273206e6f7420736f72746564000000006044820152606401610bb1565b614ce9848483614f75565b925050600101614c3e565b50915091565b5f80805b84811015614db1576020600582901b8701810151604081901c9163ffffffff9082901c81169116818711614d3457505050614da9565b86811115614d3f5750855b633b9aca007f0000000000000000000000000000000000000000000000000000000000093a8063ffffffff168084068502829004818504828504038287028490040291840686029290920401038501945089851115614da5575f95505050505050610eeb565b5050505b600101614cfe565b5060019695505050505050565b805182515f9114614dd457508051825110610e52565b6020828101519084015110610e4f565b5f80610e378585854263ffffffff614a72565b6060610eeb84845f856150bb565b633b9aca005f8163ffffffff7f0000000000000000000000000000000000000000000000000000000000093a801684020590505f82847f0000000000000000000000000000000000000000000000000000000000093a8063ffffffff168781614e7057614e70615c9a565b060281614e7f57614e7f615c9a565b0590505f865f614e8e88614903565b63ffffffff16815260208101919091526040015f2080547001000000000000000000000000000000007fffffffffffffffffffffffffffffffff00000000000000000000000000000000821695859003600f92830b016001600160801b0390811696871782900490920b9094011690920290921790555050505050565b60605f80856001600160a01b031685604051614f279190615ef6565b5f60405180830381855af49150503d805f8114614f5f576040519150601f19603f3d011682016040523d82523d5f602084013e614f64565b606091505b5091509150612923868383876151a9565b5f80614f85836020015160401c90565b90507f00000000000000000000000000000000000000000000000000000000000006766001600160a01b0316816001600160a01b0316101561502f5760405162461bcd60e51b815260206004820152602160248201527f53747265616d20726563656976657220616d7450657253656320746f6f206c6f60448201527f77000000000000000000000000000000000000000000000000000000000000006064820152608401610bb1565b5f80615040854263ffffffff614de4565b915091508063ffffffff168263ffffffff160361506257859350505050610f9d565b5f836001600160a01b031690508263ffffffff16602082901b1790508163ffffffff16602082901b179050808888815181106150a0576150a0615b04565b60209081029190910101525050600190940195945050505050565b6060824710156151335760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c00000000000000000000000000000000000000000000000000006064820152608401610bb1565b5f80866001600160a01b0316858760405161514e9190615ef6565b5f6040518083038185875af1925050503d805f8114615188576040519150601f19603f3d011682016040523d82523d5f602084013e61518d565b606091505b509150915061519e878383876151a9565b979650505050505050565b606083156152175782515f03615210576001600160a01b0385163b6152105760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610bb1565b5081610eeb565b610eeb838381511561522c5781518083602001fd5b8060405162461bcd60e51b8152600401610bb19190615f07565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6040805190810167ffffffffffffffff8111828210171561529657615296615246565b60405290565b6040516080810167ffffffffffffffff8111828210171561529657615296615246565b604051601f8201601f1916810167ffffffffffffffff811182821017156152e8576152e8615246565b604052919050565b5f67ffffffffffffffff82111561530957615309615246565b5060051b60200190565b803563ffffffff81168114615326575f80fd5b919050565b5f82601f83011261533a575f80fd5b8135602061534f61534a836152f0565b6152bf565b82815260069290921b8401810191818101908684111561536d575f80fd5b8286015b848110156153b25760408189031215615389575f8081fd5b615391615273565b813581526153a0858301615313565b81860152835291830191604001615371565b509695505050505050565b5f80604083850312156153ce575f80fd5b82359150602083013567ffffffffffffffff8111156153eb575f80fd5b6153f78582860161532b565b9150509250929050565b6001600160a01b0381168114611114575f80fd5b5f60208284031215615425575f80fd5b8135610f9d81615401565b602080825282518282018190525f9190848201906040850190845b818110156154705783516001600160a01b03168352928401929184019160010161544b565b50909695505050505050565b5f805f6060848603121561548e575f80fd5b8335925060208401356154a081615401565b9150604084013567ffffffffffffffff8111156154bb575f80fd5b6154c78682870161532b565b9150509250925092565b5f80604083850312156154e2575f80fd5b8235915060208301356154f481615401565b809150509250929050565b5f82601f83011261550e575f80fd5b8135602061551e61534a836152f0565b82815260069290921b8401810191818101908684111561553c575f80fd5b8286015b848110156153b25760408189031215615558575f8081fd5b615560615273565b813581528482013585820152835291830191604001615540565b5f805f805f60a0868803121561558e575f80fd5b8535945061559f6020870135615401565b60208601359350604086013592506060860135915067ffffffffffffffff608087013511156155cc575f80fd5b6080860135860187601f8201126155e1575f80fd5b6155ee61534a82356152f0565b81358082526020808301929160051b8401018a81111561560c575f80fd5b602084015b818110156156b55767ffffffffffffffff8135111561562e575f80fd5b803585016080601f19828f03011215615645575f80fd5b61564d61529c565b6020820135815267ffffffffffffffff6040830135111561566c575f80fd5b61567f8e602060408501358501016154ff565b602082015261569060608301615313565b60408201526156a160808301615313565b606082015285525060209384019301615611565b50508093505050509295509295909350565b5f805f80608085870312156156da575f80fd5b8435935060208501356156ec81615401565b9250604085013567ffffffffffffffff811115615707575f80fd5b615713878288016154ff565b92505061572260608601615313565b905092959194509250565b5f805f6060848603121561573f575f80fd5b83359250602084013561575181615401565b915061575f60408501615313565b90509250925092565b5f8060408385031215615779575f80fd5b823561578481615401565b915060208381013567ffffffffffffffff808211156157a1575f80fd5b818601915086601f8301126157b4575f80fd5b8135818111156157c6576157c6615246565b6157d884601f19601f840116016152bf565b915080825287848285010111156157ed575f80fd5b80848401858401375f848284010152508093505050509250929050565b5f6020828403121561581a575f80fd5b813567ffffffffffffffff811115615830575f80fd5b610eeb8482850161532b565b5f805f6040848603121561584e575f80fd5b83359250602084013567ffffffffffffffff8082111561586c575f80fd5b818601915086601f83011261587f575f80fd5b81358181111561588d575f80fd5b8760208260051b85010111156158a1575f80fd5b6020830194508093505050509250925092565b5f602082840312156158c4575f80fd5b5035919050565b5f805f80608085870312156158de575f80fd5b84359350602085013592506158f560408601615313565b915061572260608601615313565b5f60208284031215615913575f80fd5b610e4f82615313565b5f6020828403121561592c575f80fd5b813567ffffffffffffffff811115615942575f80fd5b610eeb848285016154ff565b5f806040838503121561595f575f80fd5b61596883615313565b915060208301356154f481615401565b5f805f805f805f60e0888a03121561598e575f80fd5b8735965060208801356159a081615401565b9550604088013567ffffffffffffffff808211156159bc575f80fd5b6159c88b838c016154ff565b965060608a0135915081600f0b82146159df575f80fd5b909450608089013590808211156159f4575f80fd5b50615a018a828b016154ff565b935050615a1060a08901615313565b9150615a1e60c08901615313565b905092959891949750929550565b5f805f60608486031215615a3e575f80fd5b8335615a4981615401565b92506020840135615a5981615401565b929592945050506040919091013590565b80356001600160801b0381168114615326575f80fd5b5f805f8060808587031215615a93575f80fd5b84359350602085013592506040850135615aac81615401565b915061572260608601615a6a565b5f805f60608486031215615acc575f80fd5b83359250602084013567ffffffffffffffff811115615ae9575f80fd5b615af58682870161532b565b92505061575f60408501615a6a565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f82357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc1833603018112615b63575f80fd5b9190910192915050565b5f8083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe1843603018112615ba0575f80fd5b83018035915067ffffffffffffffff821115615bba575f80fd5b602001915036819003821315613d82575f80fd5b60208152816020820152818360408301375f818301604090810191909152601f909201601f19160101919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f81600f0b7fffffffffffffffffffffffffffffffff800000000000000000000000000000008103615c5d57615c5d615bfc565b5f0392915050565b81810381811115610e5257610e52615bfc565b5f63ffffffff808316818103615c9057615c90615bfc565b6001019392505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b6001600160801b0382811682821603908082111561434057614340615bfc565b6001600160801b0381811683821601908082111561434057614340615bfc565b5f60208284031215615d17575f80fd5b5051919050565b602080825282518282018190525f919060409081850190868401855b82811015615d655781518051855286015163ffffffff16868501529284019290850190600101615d3a565b5091979650505050505050565b602080825282518282018190525f919060409081850190868401855b82811015615d6557815180518552860151868501529284019290850190600101615d8e565b5f604082016001600160801b0385168352602060408185015281855180845260608601915082870193505f5b81811015615dfb57845183529383019391830191600101615ddf565b5090979650505050505050565b5f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203615e3857615e38615bfc565b5060010190565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603160045260245ffd5b80820180821115610e5257610e52615bfc565b5f7f80000000000000000000000000000000000000000000000000000000000000008203615eaf57615eaf615bfc565b505f0390565b5f60208284031215615ec5575f80fd5b81518015158114610f9d575f80fd5b5f5b83811015615eee578181015183820152602001615ed6565b50505f910152565b5f8251615b63818460208701615ed4565b602081525f8251806020840152615f25816040850160208701615ed4565b601f01601f1916919091016040019291505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220ea9063c9d039d70ceafca55b07de00ceec354fa5a13adbf7e1180cd175caf33764736f6c63430008140033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.