ETH Price: $2,433.43 (+3.60%)
Gas: 4.45 Gwei

Transaction Decoder

Block:
21324096 at Dec-03-2024 07:34:23 PM +UTC
Transaction Fee:
0.0051774411221757 ETH $12.60
Gas Used:
166,860 Gas / 31.028653495 Gwei

Emitted Events:

115 WETH9.Deposit( dst=SquidMulticall, wad=150000000000000000 )
116 WETH9.Transfer( src=SquidMulticall, dst=0x876002653144939E97B02264fF342b0fd349A056, wad=445500000000000 )
117 WETH9.Approval( src=SquidMulticall, guy=FixedPricePool, wad=149554500000000000 )
118 WETH9.Transfer( src=SquidMulticall, dst=FixedPricePool, wad=148054499999999999 )
119 FixedPricePool.BuyFixedShares( recipient=[Sender] 0x1dd5e266acffa1c98cd706b42b92155556eb4016, sharesOut=13064938846825858955895, baseAssetsIn=145151470588235293, feesPaid=2903029411764706 )
120 WETH9.Transfer( src=SquidMulticall, dst=[Sender] 0x1dd5e266acffa1c98cd706b42b92155556eb4016, wad=1500000000000001 )

Account State Difference:

  Address   Before After State Difference Code
0x1DD5e266...556EB4016
0.160987687867610351 Eth
Nonce: 66
0.005810246745434651 Eth
Nonce: 67
0.1551774411221757
(Titan Builder)
8.489027654076639178 Eth8.489540754389207278 Eth0.0005131003125681
0xC02aaA39...83C756Cc2 2,831,604.038825968720500152 Eth2,831,604.188825968720500152 Eth0.15
0xc63CC402...B48c653a0

Execution Trace

ETH 0.15 SquidRouterProxy.58181a80( )
  • ETH 0.15 SquidRouter.fundAndRunMulticall( token=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE, amount=150000000000000000, calls= )
    • ETH 0.15 SquidMulticall.run( calls= )
      • ETH 0.15 WETH9.CALL( )
      • WETH9.transfer( dst=0x876002653144939E97B02264fF342b0fd349A056, wad=445500000000000 ) => ( True )
      • WETH9.balanceOf( 0xaD6Cea45f98444a922a2b4fE96b8C90F0862D2F4 ) => ( 149554500000000001 )
      • WETH9.approve( guy=0xc63CC402d121F876798CA18E36a4553B48c653a0, wad=149554500000000000 ) => ( True )
      • FixedPricePool.buyExactShares( )
        • FixedPricePool.buyExactShares( )
          • 0xb5d72ed6a5a87e76bfa4aa54fdd24cc684596cdf.512742d9( )
          • 0xb5d72ed6a5a87e76bfa4aa54fdd24cc684596cdf.512742d9( )
          • WETH9.transferFrom( src=0xaD6Cea45f98444a922a2b4fE96b8C90F0862D2F4, dst=0xc63CC402d121F876798CA18E36a4553B48c653a0, wad=148054499999999999 ) => ( True )
          • WETH9.balanceOf( 0xaD6Cea45f98444a922a2b4fE96b8C90F0862D2F4 ) => ( 1500000000000002 )
          • WETH9.transfer( dst=0x1DD5e266aCfFa1C98cD706B42B92155556EB4016, wad=1500000000000001 ) => ( True )
            File 1 of 6: SquidRouterProxy
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            // General interface for upgradable contracts
            interface IUpgradable {
                error NotOwner();
                error InvalidOwner();
                error InvalidCodeHash();
                error InvalidImplementation();
                error SetupFailed();
                error NotProxy();
                event Upgraded(address indexed newImplementation);
                event OwnershipTransferred(address indexed newOwner);
                // Get current owner
                function owner() external view returns (address);
                function contractId() external pure returns (bytes32);
                function upgrade(
                    address newImplementation,
                    bytes32 newImplementationCodeHash,
                    bytes calldata params
                ) external;
                function setup(bytes calldata data) external;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            import { IUpgradable } from '../interfaces/IUpgradable.sol';
            contract Proxy {
                error InvalidImplementation();
                error SetupFailed();
                error EtherNotAccepted();
                error NotOwner();
                error AlreadyInitialized();
                // bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)
                bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
                // keccak256('owner')
                bytes32 internal constant _OWNER_SLOT = 0x02016836a56b71f0d02689e69e326f4f4c1b9057164ef592671cf0d37c8040c0;
                constructor() {
                    // solhint-disable-next-line no-inline-assembly
                    assembly {
                        sstore(_OWNER_SLOT, caller())
                    }
                }
                function init(
                    address implementationAddress,
                    address newOwner,
                    bytes memory params
                ) external {
                    address owner;
                    // solhint-disable-next-line no-inline-assembly
                    assembly {
                        owner := sload(_OWNER_SLOT)
                    }
                    if (msg.sender != owner) revert NotOwner();
                    if (implementation() != address(0)) revert AlreadyInitialized();
                    if (IUpgradable(implementationAddress).contractId() != contractId()) revert InvalidImplementation();
                    // solhint-disable-next-line no-inline-assembly
                    assembly {
                        sstore(_IMPLEMENTATION_SLOT, implementationAddress)
                        sstore(_OWNER_SLOT, newOwner)
                    }
                    // solhint-disable-next-line avoid-low-level-calls
                    (bool success, ) = implementationAddress.delegatecall(
                        //0x9ded06df is the setup selector.
                        abi.encodeWithSelector(0x9ded06df, params)
                    );
                    if (!success) revert SetupFailed();
                }
                // solhint-disable-next-line no-empty-blocks
                function contractId() internal pure virtual returns (bytes32) {}
                function implementation() public view returns (address implementation_) {
                    // solhint-disable-next-line no-inline-assembly
                    assembly {
                        implementation_ := sload(_IMPLEMENTATION_SLOT)
                    }
                }
                // solhint-disable-next-line no-empty-blocks
                function setup(bytes calldata data) public {}
                // solhint-disable-next-line no-complex-fallback
                fallback() external payable {
                    address implementaion_ = implementation();
                    // solhint-disable-next-line no-inline-assembly
                    assembly {
                        calldatacopy(0, 0, calldatasize())
                        let result := delegatecall(gas(), implementaion_, 0, calldatasize(), 0, 0)
                        returndatacopy(0, 0, returndatasize())
                        switch result
                        case 0 {
                            revert(0, returndatasize())
                        }
                        default {
                            return(0, returndatasize())
                        }
                    }
                }
                receive() external payable virtual {
                    revert EtherNotAccepted();
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity 0.8.17;
            import {Proxy} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/upgradables/Proxy.sol";
            contract SquidRouterProxy is Proxy {
                function contractId() internal pure override returns (bytes32 id) {
                    id = keccak256("squid-router");
                }
            }
            

            File 2 of 6: WETH9
            // Copyright (C) 2015, 2016, 2017 Dapphub
            
            // This program is free software: you can redistribute it and/or modify
            // it under the terms of the GNU General Public License as published by
            // the Free Software Foundation, either version 3 of the License, or
            // (at your option) any later version.
            
            // This program is distributed in the hope that it will be useful,
            // but WITHOUT ANY WARRANTY; without even the implied warranty of
            // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
            // GNU General Public License for more details.
            
            // You should have received a copy of the GNU General Public License
            // along with this program.  If not, see <http://www.gnu.org/licenses/>.
            
            pragma solidity ^0.4.18;
            
            contract WETH9 {
                string public name     = "Wrapped Ether";
                string public symbol   = "WETH";
                uint8  public decimals = 18;
            
                event  Approval(address indexed src, address indexed guy, uint wad);
                event  Transfer(address indexed src, address indexed dst, uint wad);
                event  Deposit(address indexed dst, uint wad);
                event  Withdrawal(address indexed src, uint wad);
            
                mapping (address => uint)                       public  balanceOf;
                mapping (address => mapping (address => uint))  public  allowance;
            
                function() public payable {
                    deposit();
                }
                function deposit() public payable {
                    balanceOf[msg.sender] += msg.value;
                    Deposit(msg.sender, msg.value);
                }
                function withdraw(uint wad) public {
                    require(balanceOf[msg.sender] >= wad);
                    balanceOf[msg.sender] -= wad;
                    msg.sender.transfer(wad);
                    Withdrawal(msg.sender, wad);
                }
            
                function totalSupply() public view returns (uint) {
                    return this.balance;
                }
            
                function approve(address guy, uint wad) public returns (bool) {
                    allowance[msg.sender][guy] = wad;
                    Approval(msg.sender, guy, wad);
                    return true;
                }
            
                function transfer(address dst, uint wad) public returns (bool) {
                    return transferFrom(msg.sender, dst, wad);
                }
            
                function transferFrom(address src, address dst, uint wad)
                    public
                    returns (bool)
                {
                    require(balanceOf[src] >= wad);
            
                    if (src != msg.sender && allowance[src][msg.sender] != uint(-1)) {
                        require(allowance[src][msg.sender] >= wad);
                        allowance[src][msg.sender] -= wad;
                    }
            
                    balanceOf[src] -= wad;
                    balanceOf[dst] += wad;
            
                    Transfer(src, dst, wad);
            
                    return true;
                }
            }
            
            
            /*
                                GNU GENERAL PUBLIC LICENSE
                                   Version 3, 29 June 2007
            
             Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
             Everyone is permitted to copy and distribute verbatim copies
             of this license document, but changing it is not allowed.
            
                                        Preamble
            
              The GNU General Public License is a free, copyleft license for
            software and other kinds of works.
            
              The licenses for most software and other practical works are designed
            to take away your freedom to share and change the works.  By contrast,
            the GNU General Public License is intended to guarantee your freedom to
            share and change all versions of a program--to make sure it remains free
            software for all its users.  We, the Free Software Foundation, use the
            GNU General Public License for most of our software; it applies also to
            any other work released this way by its authors.  You can apply it to
            your programs, too.
            
              When we speak of free software, we are referring to freedom, not
            price.  Our General Public Licenses are designed to make sure that you
            have the freedom to distribute copies of free software (and charge for
            them if you wish), that you receive source code or can get it if you
            want it, that you can change the software or use pieces of it in new
            free programs, and that you know you can do these things.
            
              To protect your rights, we need to prevent others from denying you
            these rights or asking you to surrender the rights.  Therefore, you have
            certain responsibilities if you distribute copies of the software, or if
            you modify it: responsibilities to respect the freedom of others.
            
              For example, if you distribute copies of such a program, whether
            gratis or for a fee, you must pass on to the recipients the same
            freedoms that you received.  You must make sure that they, too, receive
            or can get the source code.  And you must show them these terms so they
            know their rights.
            
              Developers that use the GNU GPL protect your rights with two steps:
            (1) assert copyright on the software, and (2) offer you this License
            giving you legal permission to copy, distribute and/or modify it.
            
              For the developers' and authors' protection, the GPL clearly explains
            that there is no warranty for this free software.  For both users' and
            authors' sake, the GPL requires that modified versions be marked as
            changed, so that their problems will not be attributed erroneously to
            authors of previous versions.
            
              Some devices are designed to deny users access to install or run
            modified versions of the software inside them, although the manufacturer
            can do so.  This is fundamentally incompatible with the aim of
            protecting users' freedom to change the software.  The systematic
            pattern of such abuse occurs in the area of products for individuals to
            use, which is precisely where it is most unacceptable.  Therefore, we
            have designed this version of the GPL to prohibit the practice for those
            products.  If such problems arise substantially in other domains, we
            stand ready to extend this provision to those domains in future versions
            of the GPL, as needed to protect the freedom of users.
            
              Finally, every program is threatened constantly by software patents.
            States should not allow patents to restrict development and use of
            software on general-purpose computers, but in those that do, we wish to
            avoid the special danger that patents applied to a free program could
            make it effectively proprietary.  To prevent this, the GPL assures that
            patents cannot be used to render the program non-free.
            
              The precise terms and conditions for copying, distribution and
            modification follow.
            
                                   TERMS AND CONDITIONS
            
              0. Definitions.
            
              "This License" refers to version 3 of the GNU General Public License.
            
              "Copyright" also means copyright-like laws that apply to other kinds of
            works, such as semiconductor masks.
            
              "The Program" refers to any copyrightable work licensed under this
            License.  Each licensee is addressed as "you".  "Licensees" and
            "recipients" may be individuals or organizations.
            
              To "modify" a work means to copy from or adapt all or part of the work
            in a fashion requiring copyright permission, other than the making of an
            exact copy.  The resulting work is called a "modified version" of the
            earlier work or a work "based on" the earlier work.
            
              A "covered work" means either the unmodified Program or a work based
            on the Program.
            
              To "propagate" a work means to do anything with it that, without
            permission, would make you directly or secondarily liable for
            infringement under applicable copyright law, except executing it on a
            computer or modifying a private copy.  Propagation includes copying,
            distribution (with or without modification), making available to the
            public, and in some countries other activities as well.
            
              To "convey" a work means any kind of propagation that enables other
            parties to make or receive copies.  Mere interaction with a user through
            a computer network, with no transfer of a copy, is not conveying.
            
              An interactive user interface displays "Appropriate Legal Notices"
            to the extent that it includes a convenient and prominently visible
            feature that (1) displays an appropriate copyright notice, and (2)
            tells the user that there is no warranty for the work (except to the
            extent that warranties are provided), that licensees may convey the
            work under this License, and how to view a copy of this License.  If
            the interface presents a list of user commands or options, such as a
            menu, a prominent item in the list meets this criterion.
            
              1. Source Code.
            
              The "source code" for a work means the preferred form of the work
            for making modifications to it.  "Object code" means any non-source
            form of a work.
            
              A "Standard Interface" means an interface that either is an official
            standard defined by a recognized standards body, or, in the case of
            interfaces specified for a particular programming language, one that
            is widely used among developers working in that language.
            
              The "System Libraries" of an executable work include anything, other
            than the work as a whole, that (a) is included in the normal form of
            packaging a Major Component, but which is not part of that Major
            Component, and (b) serves only to enable use of the work with that
            Major Component, or to implement a Standard Interface for which an
            implementation is available to the public in source code form.  A
            "Major Component", in this context, means a major essential component
            (kernel, window system, and so on) of the specific operating system
            (if any) on which the executable work runs, or a compiler used to
            produce the work, or an object code interpreter used to run it.
            
              The "Corresponding Source" for a work in object code form means all
            the source code needed to generate, install, and (for an executable
            work) run the object code and to modify the work, including scripts to
            control those activities.  However, it does not include the work's
            System Libraries, or general-purpose tools or generally available free
            programs which are used unmodified in performing those activities but
            which are not part of the work.  For example, Corresponding Source
            includes interface definition files associated with source files for
            the work, and the source code for shared libraries and dynamically
            linked subprograms that the work is specifically designed to require,
            such as by intimate data communication or control flow between those
            subprograms and other parts of the work.
            
              The Corresponding Source need not include anything that users
            can regenerate automatically from other parts of the Corresponding
            Source.
            
              The Corresponding Source for a work in source code form is that
            same work.
            
              2. Basic Permissions.
            
              All rights granted under this License are granted for the term of
            copyright on the Program, and are irrevocable provided the stated
            conditions are met.  This License explicitly affirms your unlimited
            permission to run the unmodified Program.  The output from running a
            covered work is covered by this License only if the output, given its
            content, constitutes a covered work.  This License acknowledges your
            rights of fair use or other equivalent, as provided by copyright law.
            
              You may make, run and propagate covered works that you do not
            convey, without conditions so long as your license otherwise remains
            in force.  You may convey covered works to others for the sole purpose
            of having them make modifications exclusively for you, or provide you
            with facilities for running those works, provided that you comply with
            the terms of this License in conveying all material for which you do
            not control copyright.  Those thus making or running the covered works
            for you must do so exclusively on your behalf, under your direction
            and control, on terms that prohibit them from making any copies of
            your copyrighted material outside their relationship with you.
            
              Conveying under any other circumstances is permitted solely under
            the conditions stated below.  Sublicensing is not allowed; section 10
            makes it unnecessary.
            
              3. Protecting Users' Legal Rights From Anti-Circumvention Law.
            
              No covered work shall be deemed part of an effective technological
            measure under any applicable law fulfilling obligations under article
            11 of the WIPO copyright treaty adopted on 20 December 1996, or
            similar laws prohibiting or restricting circumvention of such
            measures.
            
              When you convey a covered work, you waive any legal power to forbid
            circumvention of technological measures to the extent such circumvention
            is effected by exercising rights under this License with respect to
            the covered work, and you disclaim any intention to limit operation or
            modification of the work as a means of enforcing, against the work's
            users, your or third parties' legal rights to forbid circumvention of
            technological measures.
            
              4. Conveying Verbatim Copies.
            
              You may convey verbatim copies of the Program's source code as you
            receive it, in any medium, provided that you conspicuously and
            appropriately publish on each copy an appropriate copyright notice;
            keep intact all notices stating that this License and any
            non-permissive terms added in accord with section 7 apply to the code;
            keep intact all notices of the absence of any warranty; and give all
            recipients a copy of this License along with the Program.
            
              You may charge any price or no price for each copy that you convey,
            and you may offer support or warranty protection for a fee.
            
              5. Conveying Modified Source Versions.
            
              You may convey a work based on the Program, or the modifications to
            produce it from the Program, in the form of source code under the
            terms of section 4, provided that you also meet all of these conditions:
            
                a) The work must carry prominent notices stating that you modified
                it, and giving a relevant date.
            
                b) The work must carry prominent notices stating that it is
                released under this License and any conditions added under section
                7.  This requirement modifies the requirement in section 4 to
                "keep intact all notices".
            
                c) You must license the entire work, as a whole, under this
                License to anyone who comes into possession of a copy.  This
                License will therefore apply, along with any applicable section 7
                additional terms, to the whole of the work, and all its parts,
                regardless of how they are packaged.  This License gives no
                permission to license the work in any other way, but it does not
                invalidate such permission if you have separately received it.
            
                d) If the work has interactive user interfaces, each must display
                Appropriate Legal Notices; however, if the Program has interactive
                interfaces that do not display Appropriate Legal Notices, your
                work need not make them do so.
            
              A compilation of a covered work with other separate and independent
            works, which are not by their nature extensions of the covered work,
            and which are not combined with it such as to form a larger program,
            in or on a volume of a storage or distribution medium, is called an
            "aggregate" if the compilation and its resulting copyright are not
            used to limit the access or legal rights of the compilation's users
            beyond what the individual works permit.  Inclusion of a covered work
            in an aggregate does not cause this License to apply to the other
            parts of the aggregate.
            
              6. Conveying Non-Source Forms.
            
              You may convey a covered work in object code form under the terms
            of sections 4 and 5, provided that you also convey the
            machine-readable Corresponding Source under the terms of this License,
            in one of these ways:
            
                a) Convey the object code in, or embodied in, a physical product
                (including a physical distribution medium), accompanied by the
                Corresponding Source fixed on a durable physical medium
                customarily used for software interchange.
            
                b) Convey the object code in, or embodied in, a physical product
                (including a physical distribution medium), accompanied by a
                written offer, valid for at least three years and valid for as
                long as you offer spare parts or customer support for that product
                model, to give anyone who possesses the object code either (1) a
                copy of the Corresponding Source for all the software in the
                product that is covered by this License, on a durable physical
                medium customarily used for software interchange, for a price no
                more than your reasonable cost of physically performing this
                conveying of source, or (2) access to copy the
                Corresponding Source from a network server at no charge.
            
                c) Convey individual copies of the object code with a copy of the
                written offer to provide the Corresponding Source.  This
                alternative is allowed only occasionally and noncommercially, and
                only if you received the object code with such an offer, in accord
                with subsection 6b.
            
                d) Convey the object code by offering access from a designated
                place (gratis or for a charge), and offer equivalent access to the
                Corresponding Source in the same way through the same place at no
                further charge.  You need not require recipients to copy the
                Corresponding Source along with the object code.  If the place to
                copy the object code is a network server, the Corresponding Source
                may be on a different server (operated by you or a third party)
                that supports equivalent copying facilities, provided you maintain
                clear directions next to the object code saying where to find the
                Corresponding Source.  Regardless of what server hosts the
                Corresponding Source, you remain obligated to ensure that it is
                available for as long as needed to satisfy these requirements.
            
                e) Convey the object code using peer-to-peer transmission, provided
                you inform other peers where the object code and Corresponding
                Source of the work are being offered to the general public at no
                charge under subsection 6d.
            
              A separable portion of the object code, whose source code is excluded
            from the Corresponding Source as a System Library, need not be
            included in conveying the object code work.
            
              A "User Product" is either (1) a "consumer product", which means any
            tangible personal property which is normally used for personal, family,
            or household purposes, or (2) anything designed or sold for incorporation
            into a dwelling.  In determining whether a product is a consumer product,
            doubtful cases shall be resolved in favor of coverage.  For a particular
            product received by a particular user, "normally used" refers to a
            typical or common use of that class of product, regardless of the status
            of the particular user or of the way in which the particular user
            actually uses, or expects or is expected to use, the product.  A product
            is a consumer product regardless of whether the product has substantial
            commercial, industrial or non-consumer uses, unless such uses represent
            the only significant mode of use of the product.
            
              "Installation Information" for a User Product means any methods,
            procedures, authorization keys, or other information required to install
            and execute modified versions of a covered work in that User Product from
            a modified version of its Corresponding Source.  The information must
            suffice to ensure that the continued functioning of the modified object
            code is in no case prevented or interfered with solely because
            modification has been made.
            
              If you convey an object code work under this section in, or with, or
            specifically for use in, a User Product, and the conveying occurs as
            part of a transaction in which the right of possession and use of the
            User Product is transferred to the recipient in perpetuity or for a
            fixed term (regardless of how the transaction is characterized), the
            Corresponding Source conveyed under this section must be accompanied
            by the Installation Information.  But this requirement does not apply
            if neither you nor any third party retains the ability to install
            modified object code on the User Product (for example, the work has
            been installed in ROM).
            
              The requirement to provide Installation Information does not include a
            requirement to continue to provide support service, warranty, or updates
            for a work that has been modified or installed by the recipient, or for
            the User Product in which it has been modified or installed.  Access to a
            network may be denied when the modification itself materially and
            adversely affects the operation of the network or violates the rules and
            protocols for communication across the network.
            
              Corresponding Source conveyed, and Installation Information provided,
            in accord with this section must be in a format that is publicly
            documented (and with an implementation available to the public in
            source code form), and must require no special password or key for
            unpacking, reading or copying.
            
              7. Additional Terms.
            
              "Additional permissions" are terms that supplement the terms of this
            License by making exceptions from one or more of its conditions.
            Additional permissions that are applicable to the entire Program shall
            be treated as though they were included in this License, to the extent
            that they are valid under applicable law.  If additional permissions
            apply only to part of the Program, that part may be used separately
            under those permissions, but the entire Program remains governed by
            this License without regard to the additional permissions.
            
              When you convey a copy of a covered work, you may at your option
            remove any additional permissions from that copy, or from any part of
            it.  (Additional permissions may be written to require their own
            removal in certain cases when you modify the work.)  You may place
            additional permissions on material, added by you to a covered work,
            for which you have or can give appropriate copyright permission.
            
              Notwithstanding any other provision of this License, for material you
            add to a covered work, you may (if authorized by the copyright holders of
            that material) supplement the terms of this License with terms:
            
                a) Disclaiming warranty or limiting liability differently from the
                terms of sections 15 and 16 of this License; or
            
                b) Requiring preservation of specified reasonable legal notices or
                author attributions in that material or in the Appropriate Legal
                Notices displayed by works containing it; or
            
                c) Prohibiting misrepresentation of the origin of that material, or
                requiring that modified versions of such material be marked in
                reasonable ways as different from the original version; or
            
                d) Limiting the use for publicity purposes of names of licensors or
                authors of the material; or
            
                e) Declining to grant rights under trademark law for use of some
                trade names, trademarks, or service marks; or
            
                f) Requiring indemnification of licensors and authors of that
                material by anyone who conveys the material (or modified versions of
                it) with contractual assumptions of liability to the recipient, for
                any liability that these contractual assumptions directly impose on
                those licensors and authors.
            
              All other non-permissive additional terms are considered "further
            restrictions" within the meaning of section 10.  If the Program as you
            received it, or any part of it, contains a notice stating that it is
            governed by this License along with a term that is a further
            restriction, you may remove that term.  If a license document contains
            a further restriction but permits relicensing or conveying under this
            License, you may add to a covered work material governed by the terms
            of that license document, provided that the further restriction does
            not survive such relicensing or conveying.
            
              If you add terms to a covered work in accord with this section, you
            must place, in the relevant source files, a statement of the
            additional terms that apply to those files, or a notice indicating
            where to find the applicable terms.
            
              Additional terms, permissive or non-permissive, may be stated in the
            form of a separately written license, or stated as exceptions;
            the above requirements apply either way.
            
              8. Termination.
            
              You may not propagate or modify a covered work except as expressly
            provided under this License.  Any attempt otherwise to propagate or
            modify it is void, and will automatically terminate your rights under
            this License (including any patent licenses granted under the third
            paragraph of section 11).
            
              However, if you cease all violation of this License, then your
            license from a particular copyright holder is reinstated (a)
            provisionally, unless and until the copyright holder explicitly and
            finally terminates your license, and (b) permanently, if the copyright
            holder fails to notify you of the violation by some reasonable means
            prior to 60 days after the cessation.
            
              Moreover, your license from a particular copyright holder is
            reinstated permanently if the copyright holder notifies you of the
            violation by some reasonable means, this is the first time you have
            received notice of violation of this License (for any work) from that
            copyright holder, and you cure the violation prior to 30 days after
            your receipt of the notice.
            
              Termination of your rights under this section does not terminate the
            licenses of parties who have received copies or rights from you under
            this License.  If your rights have been terminated and not permanently
            reinstated, you do not qualify to receive new licenses for the same
            material under section 10.
            
              9. Acceptance Not Required for Having Copies.
            
              You are not required to accept this License in order to receive or
            run a copy of the Program.  Ancillary propagation of a covered work
            occurring solely as a consequence of using peer-to-peer transmission
            to receive a copy likewise does not require acceptance.  However,
            nothing other than this License grants you permission to propagate or
            modify any covered work.  These actions infringe copyright if you do
            not accept this License.  Therefore, by modifying or propagating a
            covered work, you indicate your acceptance of this License to do so.
            
              10. Automatic Licensing of Downstream Recipients.
            
              Each time you convey a covered work, the recipient automatically
            receives a license from the original licensors, to run, modify and
            propagate that work, subject to this License.  You are not responsible
            for enforcing compliance by third parties with this License.
            
              An "entity transaction" is a transaction transferring control of an
            organization, or substantially all assets of one, or subdividing an
            organization, or merging organizations.  If propagation of a covered
            work results from an entity transaction, each party to that
            transaction who receives a copy of the work also receives whatever
            licenses to the work the party's predecessor in interest had or could
            give under the previous paragraph, plus a right to possession of the
            Corresponding Source of the work from the predecessor in interest, if
            the predecessor has it or can get it with reasonable efforts.
            
              You may not impose any further restrictions on the exercise of the
            rights granted or affirmed under this License.  For example, you may
            not impose a license fee, royalty, or other charge for exercise of
            rights granted under this License, and you may not initiate litigation
            (including a cross-claim or counterclaim in a lawsuit) alleging that
            any patent claim is infringed by making, using, selling, offering for
            sale, or importing the Program or any portion of it.
            
              11. Patents.
            
              A "contributor" is a copyright holder who authorizes use under this
            License of the Program or a work on which the Program is based.  The
            work thus licensed is called the contributor's "contributor version".
            
              A contributor's "essential patent claims" are all patent claims
            owned or controlled by the contributor, whether already acquired or
            hereafter acquired, that would be infringed by some manner, permitted
            by this License, of making, using, or selling its contributor version,
            but do not include claims that would be infringed only as a
            consequence of further modification of the contributor version.  For
            purposes of this definition, "control" includes the right to grant
            patent sublicenses in a manner consistent with the requirements of
            this License.
            
              Each contributor grants you a non-exclusive, worldwide, royalty-free
            patent license under the contributor's essential patent claims, to
            make, use, sell, offer for sale, import and otherwise run, modify and
            propagate the contents of its contributor version.
            
              In the following three paragraphs, a "patent license" is any express
            agreement or commitment, however denominated, not to enforce a patent
            (such as an express permission to practice a patent or covenant not to
            sue for patent infringement).  To "grant" such a patent license to a
            party means to make such an agreement or commitment not to enforce a
            patent against the party.
            
              If you convey a covered work, knowingly relying on a patent license,
            and the Corresponding Source of the work is not available for anyone
            to copy, free of charge and under the terms of this License, through a
            publicly available network server or other readily accessible means,
            then you must either (1) cause the Corresponding Source to be so
            available, or (2) arrange to deprive yourself of the benefit of the
            patent license for this particular work, or (3) arrange, in a manner
            consistent with the requirements of this License, to extend the patent
            license to downstream recipients.  "Knowingly relying" means you have
            actual knowledge that, but for the patent license, your conveying the
            covered work in a country, or your recipient's use of the covered work
            in a country, would infringe one or more identifiable patents in that
            country that you have reason to believe are valid.
            
              If, pursuant to or in connection with a single transaction or
            arrangement, you convey, or propagate by procuring conveyance of, a
            covered work, and grant a patent license to some of the parties
            receiving the covered work authorizing them to use, propagate, modify
            or convey a specific copy of the covered work, then the patent license
            you grant is automatically extended to all recipients of the covered
            work and works based on it.
            
              A patent license is "discriminatory" if it does not include within
            the scope of its coverage, prohibits the exercise of, or is
            conditioned on the non-exercise of one or more of the rights that are
            specifically granted under this License.  You may not convey a covered
            work if you are a party to an arrangement with a third party that is
            in the business of distributing software, under which you make payment
            to the third party based on the extent of your activity of conveying
            the work, and under which the third party grants, to any of the
            parties who would receive the covered work from you, a discriminatory
            patent license (a) in connection with copies of the covered work
            conveyed by you (or copies made from those copies), or (b) primarily
            for and in connection with specific products or compilations that
            contain the covered work, unless you entered into that arrangement,
            or that patent license was granted, prior to 28 March 2007.
            
              Nothing in this License shall be construed as excluding or limiting
            any implied license or other defenses to infringement that may
            otherwise be available to you under applicable patent law.
            
              12. No Surrender of Others' Freedom.
            
              If conditions are imposed on you (whether by court order, agreement or
            otherwise) that contradict the conditions of this License, they do not
            excuse you from the conditions of this License.  If you cannot convey a
            covered work so as to satisfy simultaneously your obligations under this
            License and any other pertinent obligations, then as a consequence you may
            not convey it at all.  For example, if you agree to terms that obligate you
            to collect a royalty for further conveying from those to whom you convey
            the Program, the only way you could satisfy both those terms and this
            License would be to refrain entirely from conveying the Program.
            
              13. Use with the GNU Affero General Public License.
            
              Notwithstanding any other provision of this License, you have
            permission to link or combine any covered work with a work licensed
            under version 3 of the GNU Affero General Public License into a single
            combined work, and to convey the resulting work.  The terms of this
            License will continue to apply to the part which is the covered work,
            but the special requirements of the GNU Affero General Public License,
            section 13, concerning interaction through a network will apply to the
            combination as such.
            
              14. Revised Versions of this License.
            
              The Free Software Foundation may publish revised and/or new versions of
            the GNU General Public License from time to time.  Such new versions will
            be similar in spirit to the present version, but may differ in detail to
            address new problems or concerns.
            
              Each version is given a distinguishing version number.  If the
            Program specifies that a certain numbered version of the GNU General
            Public License "or any later version" applies to it, you have the
            option of following the terms and conditions either of that numbered
            version or of any later version published by the Free Software
            Foundation.  If the Program does not specify a version number of the
            GNU General Public License, you may choose any version ever published
            by the Free Software Foundation.
            
              If the Program specifies that a proxy can decide which future
            versions of the GNU General Public License can be used, that proxy's
            public statement of acceptance of a version permanently authorizes you
            to choose that version for the Program.
            
              Later license versions may give you additional or different
            permissions.  However, no additional obligations are imposed on any
            author or copyright holder as a result of your choosing to follow a
            later version.
            
              15. Disclaimer of Warranty.
            
              THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
            APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
            HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
            OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
            THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
            PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
            IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
            ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
            
              16. Limitation of Liability.
            
              IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
            WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
            THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
            GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
            USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
            DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
            PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
            EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
            SUCH DAMAGES.
            
              17. Interpretation of Sections 15 and 16.
            
              If the disclaimer of warranty and limitation of liability provided
            above cannot be given local legal effect according to their terms,
            reviewing courts shall apply local law that most closely approximates
            an absolute waiver of all civil liability in connection with the
            Program, unless a warranty or assumption of liability accompanies a
            copy of the Program in return for a fee.
            
                                 END OF TERMS AND CONDITIONS
            
                        How to Apply These Terms to Your New Programs
            
              If you develop a new program, and you want it to be of the greatest
            possible use to the public, the best way to achieve this is to make it
            free software which everyone can redistribute and change under these terms.
            
              To do so, attach the following notices to the program.  It is safest
            to attach them to the start of each source file to most effectively
            state the exclusion of warranty; and each file should have at least
            the "copyright" line and a pointer to where the full notice is found.
            
                <one line to give the program's name and a brief idea of what it does.>
                Copyright (C) <year>  <name of author>
            
                This program is free software: you can redistribute it and/or modify
                it under the terms of the GNU General Public License as published by
                the Free Software Foundation, either version 3 of the License, or
                (at your option) any later version.
            
                This program is distributed in the hope that it will be useful,
                but WITHOUT ANY WARRANTY; without even the implied warranty of
                MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                GNU General Public License for more details.
            
                You should have received a copy of the GNU General Public License
                along with this program.  If not, see <http://www.gnu.org/licenses/>.
            
            Also add information on how to contact you by electronic and paper mail.
            
              If the program does terminal interaction, make it output a short
            notice like this when it starts in an interactive mode:
            
                <program>  Copyright (C) <year>  <name of author>
                This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
                This is free software, and you are welcome to redistribute it
                under certain conditions; type `show c' for details.
            
            The hypothetical commands `show w' and `show c' should show the appropriate
            parts of the General Public License.  Of course, your program's commands
            might be different; for a GUI interface, you would use an "about box".
            
              You should also get your employer (if you work as a programmer) or school,
            if any, to sign a "copyright disclaimer" for the program, if necessary.
            For more information on this, and how to apply and follow the GNU GPL, see
            <http://www.gnu.org/licenses/>.
            
              The GNU General Public License does not permit incorporating your program
            into proprietary programs.  If your program is a subroutine library, you
            may consider it more useful to permit linking proprietary applications with
            the library.  If this is what you want to do, use the GNU Lesser General
            Public License instead of this License.  But first, please read
            <http://www.gnu.org/philosophy/why-not-lgpl.html>.
            
            */

            File 3 of 6: SquidMulticall
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/IERC1155Receiver.sol)
            pragma solidity ^0.8.0;
            import "../../utils/introspection/IERC165.sol";
            /**
             * @dev _Available since v3.1._
             */
            interface IERC1155Receiver is IERC165 {
                /**
                 * @dev Handles the receipt of a single ERC1155 token type. This function is
                 * called at the end of a `safeTransferFrom` after the balance has been updated.
                 *
                 * NOTE: To accept the transfer, this must return
                 * `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
                 * (i.e. 0xf23a6e61, or its own function selector).
                 *
                 * @param operator The address which initiated the transfer (i.e. msg.sender)
                 * @param from The address which previously owned the token
                 * @param id The ID of the token being transferred
                 * @param value The amount of tokens being transferred
                 * @param data Additional data with no specified format
                 * @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
                 */
                function onERC1155Received(
                    address operator,
                    address from,
                    uint256 id,
                    uint256 value,
                    bytes calldata data
                ) external returns (bytes4);
                /**
                 * @dev Handles the receipt of a multiple ERC1155 token types. This function
                 * is called at the end of a `safeBatchTransferFrom` after the balances have
                 * been updated.
                 *
                 * NOTE: To accept the transfer(s), this must return
                 * `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
                 * (i.e. 0xbc197c81, or its own function selector).
                 *
                 * @param operator The address which initiated the batch transfer (i.e. msg.sender)
                 * @param from The address which previously owned the token
                 * @param ids An array containing ids of each token being transferred (order and length must match values array)
                 * @param values An array containing amounts of each token being transferred (order and length must match ids array)
                 * @param data Additional data with no specified format
                 * @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
                 */
                function onERC1155BatchReceived(
                    address operator,
                    address from,
                    uint256[] calldata ids,
                    uint256[] calldata values,
                    bytes calldata data
                ) external returns (bytes4);
            }
            // 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);
            }
            // 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);
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v4.9.3) (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. Meant to be used with tokens that require the approval
                 * to be set to zero before setting it to a non-zero value, such as USDT.
                 */
                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));
                }
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)
            pragma solidity ^0.8.0;
            /**
             * @title ERC721 token receiver interface
             * @dev Interface for any contract that wants to support safeTransfers
             * from ERC721 asset contracts.
             */
            interface IERC721Receiver {
                /**
                 * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
                 * by `operator` from `from`, this function is called.
                 *
                 * It must return its Solidity selector to confirm the token transfer.
                 * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
                 *
                 * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
                 */
                function onERC721Received(
                    address operator,
                    address from,
                    uint256 tokenId,
                    bytes calldata data
                ) external returns (bytes4);
            }
            // 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);
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
            pragma solidity ^0.8.0;
            /**
             * @dev Interface of the ERC165 standard, as defined in the
             * https://eips.ethereum.org/EIPS/eip-165[EIP].
             *
             * Implementers can declare support of contract interfaces, which can then be
             * queried by others ({ERC165Checker}).
             *
             * For an implementation, see {ERC165}.
             */
            interface IERC165 {
                /**
                 * @dev Returns true if this contract implements the interface defined by
                 * `interfaceId`. See the corresponding
                 * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
                 * to learn more about how these ids are created.
                 *
                 * This function call must use less than 30 000 gas.
                 */
                function supportsInterface(bytes4 interfaceId) external view returns (bool);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.9;
            /// @title SquidMulticall
            /// @notice Multicall logic specific to Squid calls format. The contract specificity is mainly
            /// to enable ERC20 and native token amounts in calldata between two calls.
            /// @dev Support receiption of NFTs.
            interface ISquidMulticall {
                /// @notice Call type that enables to specific behaviours of the multicall.
                enum CallType {
                    // Will simply run calldata
                    Default,
                    // Will update amount field in calldata with ERC20 token balance of the multicall contract.
                    FullTokenBalance,
                    // Will update amount field in calldata with native token balance of the multicall contract.
                    FullNativeBalance,
                    // Will run a safeTransferFrom to get full ERC20 token balance of the caller.
                    CollectTokenBalance
                }
                /// @notice Calldata format expected by multicall.
                struct Call {
                    // Call type, see CallType struct description.
                    CallType callType;
                    // Address that will be called.
                    address target;
                    // Native token amount that will be sent in call.
                    uint256 value;
                    // Calldata that will be send in call.
                    bytes callData;
                    // Extra data used by multicall depending on call type.
                    // Default: unused (provide 0x)
                    // FullTokenBalance: address of the ERC20 token to get balance of and zero indexed position
                    // of the amount parameter to update in function call contained by calldata.
                    // Expect format is: abi.encode(address token, uint256 amountParameterPosition)
                    // Eg: for function swap(address tokenIn, uint amountIn, address tokenOut, uint amountOutMin,)
                    // amountParameterPosition would be 1.
                    // FullNativeBalance: unused (provide 0x)
                    // CollectTokenBalance: address of the ERC20 token to collect.
                    // Expect format is: abi.encode(address token)
                    bytes payload;
                }
                /// Thrown when one of the calls fails.
                /// @param callPosition Zero indexed position of the call in the call set provided to the
                /// multicall.
                /// @param reason Revert data returned by contract called in failing call.
                error CallFailed(uint256 callPosition, bytes reason);
                /// @notice Main function of the multicall that runs the call set.
                /// @param calls Call set to be ran by multicall.
                function run(Call[] calldata calls) external payable;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity 0.8.23;
            import {ISquidMulticall} from "../interfaces/ISquidMulticall.sol";
            import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
            import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
            import {IERC1155Receiver} from "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";
            import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
            contract SquidMulticall is ISquidMulticall, IERC721Receiver, IERC1155Receiver {
                using SafeERC20 for IERC20;
                bytes4 private constant ERC165_INTERFACE_ID = 0x01ffc9a7;
                bytes4 private constant ERC721_TOKENRECEIVER_INTERFACE_ID = 0x150b7a02;
                bytes4 private constant ERC1155_TOKENRECEIVER_INTERFACE_ID = 0x4e2312e0;
                /// @inheritdoc ISquidMulticall
                function run(Call[] calldata calls) external payable {
                    for (uint256 i = 0; i < calls.length; i++) {
                        Call memory call = calls[i];
                        if (call.callType == CallType.FullTokenBalance) {
                            (address token, uint256 amountParameterPosition) = abi.decode(
                                call.payload,
                                (address, uint256)
                            );
                            uint256 amount = IERC20(token).balanceOf(address(this));
                            // Deduct 1 from amount to keep hot balances and reduce gas cost
                            if (amount > 0) {
                                // Cannot underflow because amount > 0
                                unchecked {
                                    amount -= 1;
                                }
                            }
                            _setCallDataParameter(call.callData, amountParameterPosition, amount);
                        } else if (call.callType == CallType.FullNativeBalance) {
                            call.value = address(this).balance;
                        } else if (call.callType == CallType.CollectTokenBalance) {
                            address token = abi.decode(call.payload, (address));
                            uint256 senderBalance = IERC20(token).balanceOf(msg.sender);
                            IERC20(token).safeTransferFrom(msg.sender, address(this), senderBalance);
                            continue;
                        }
                        (bool success, bytes memory data) = call.target.call{value: call.value}(call.callData);
                        if (!success) revert CallFailed(i, data);
                    }
                }
                function _setCallDataParameter(
                    bytes memory callData,
                    uint256 parameterPosition,
                    uint256 value
                ) private pure {
                    assembly {
                        // 36 bytes shift because 32 for prefix + 4 for selector
                        mstore(add(callData, add(36, mul(parameterPosition, 32))), value)
                    }
                }
                /// @notice Implementation required by ERC165 for NFT reception.
                /// See https://eips.ethereum.org/EIPS/eip-165.
                function supportsInterface(bytes4 interfaceId) external pure returns (bool) {
                    return
                        interfaceId == ERC1155_TOKENRECEIVER_INTERFACE_ID ||
                        interfaceId == ERC721_TOKENRECEIVER_INTERFACE_ID ||
                        interfaceId == ERC165_INTERFACE_ID;
                }
                /// @notice Implementation required by ERC721 for NFT reception.
                /// See https://eips.ethereum.org/EIPS/eip-721.
                function onERC721Received(
                    address,
                    address,
                    uint256,
                    bytes calldata
                ) external pure returns (bytes4) {
                    return IERC721Receiver.onERC721Received.selector;
                }
                /// @notice Implementation required by ERC1155 for NFT reception.
                /// See https://eips.ethereum.org/EIPS/eip-1155.
                function onERC1155Received(
                    address,
                    address,
                    uint256,
                    uint256,
                    bytes calldata
                ) external pure returns (bytes4) {
                    return IERC1155Receiver.onERC1155Received.selector;
                }
                /// @notice Implementation required by ERC1155 for NFT reception.
                /// See https://eips.ethereum.org/EIPS/eip-1155.
                function onERC1155BatchReceived(
                    address,
                    address,
                    uint256[] calldata,
                    uint256[] calldata,
                    bytes calldata
                ) external pure returns (bytes4) {
                    return IERC1155Receiver.onERC1155BatchReceived.selector;
                }
                /// @dev Enable native tokens reception with .transfer or .send
                receive() external payable {}
            }
            

            File 4 of 6: FixedPricePool
            // SPDX-License-Identifier: AGPL-3.0-only
            pragma solidity =0.8.25;
            import {
                BasePool,
                FixedPointMathLib,
                SafeTransferLib,
                MerkleProofLib,
                PoolStatus,
                PoolType,
                IERC20,
                Tier,
                TiersModified,
                FjordMath
            } from "./BasePool.sol";
            import { SafeCastLib } from "solady/utils/SafeCastLib.sol";
            /// @title FixedERC2Pool
            /// @notice A fixed price pool that allows users to purchase shares with a predefined standard ERC20 token.
            /// @notice The pool creator can set the number of shares available for purchase, the price of each share,
            /// @notice the sale start and end dates, the redemption date, and the maximum number of shares a user can purchase.
            /// @notice The pool creator can also set a minimum number of shares that must be sold for the sale to be considered successful.
            /// @notice The pool creator can also set a platform fee and a swap fee that will be taken from the raised funds.
            /// @dev Creation will fail if the asset token has less than 2 or more than 18 decimals, or if the share token has more than 18 decimals.
            /// @dev The pool will fail if the sale start date is after the sale end date, or if the redemption date is before the sale end date.
            /// @dev The pool will fail if the platform fee or swap fee is greater than or equal to 1e18.
            /// @dev The pool will fail if the price of each share is 0, or if the minimum number of shares that must be sold is greater than the number of shares available for purchase.
            contract FixedPricePool is BasePool {
                /// -----------------------------------------------------------------------
                /// Dependencies
                /// -----------------------------------------------------------------------
                using MerkleProofLib for bytes32;
                using FixedPointMathLib for uint256;
                using SafeTransferLib for address;
                using FjordMath for uint256;
                using SafeCastLib for uint256;
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// Errors
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                error TierMaxPurchaseExceeded();
                error TierPurchaseTooLow(uint256 tierIndex);
                error InvalidTierPurchaseAmount();
                error SlippageExceeded();
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// Events
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// @notice Emitted when a user purchases shares in the pool.
                event BuyFixedShares(
                    address indexed recipient, uint256 sharesOut, uint256 baseAssetsIn, uint256 feesPaid
                );
                /// @notice Emitted when a tiered sale rolls over to the next tier.
                event TierRollover(uint256 newTier);
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// Constructor
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                constructor(address _sablier) BasePool(_sablier) { }
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// FIXED PRICE LOGIC -- Immutable Arguments -- Public -- Read Functions
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// @notice The number of assets (with decimals) required to purchase 1 share.
                /// @dev This value is normalized to 18 decimals.
                function assetsPerToken() public pure returns (uint256) {
                    return _getArgUint256(ASSETS_PER_TOKEN_OFFSET);
                }
                /// @notice All the tiers available for this sale.
                function tiers() public pure returns (Tier[] memory) {
                    return abi.decode(_getArgBytes(TIERS_OFFSET, _tierDataLength()), (Tier[]));
                }
                /// @notice Whether the sale has multiple Tiers enabled, modifying the sale price and user-specific limits per tier.
                function isTiered() public pure returns (bool) {
                    return _tierDataLength() > EMPTY_TIER_ARRAY_OFFSET;
                }
                /// @notice The current tier of the sale.
                function getCurrentTierData() public view returns (Tier memory) {
                    return tiers()[currentTier];
                }
                /// @notice The tier data for a specific index.
                function getTierData(uint256 index) public pure returns (Tier memory) {
                    return tiers()[index];
                }
                /// @notice The number of tiers slots allocated to the tiers array.
                /// @dev This is used to instantiate
                function getTierLength() public pure returns (uint8) {
                    uint256 offDiff = _tierDataLength().rawSub(EMPTY_TIER_ARRAY_OFFSET);
                    if (offDiff == 0) {
                        return SafeCastLib.toUint8(0);
                    } else {
                        return (offDiff.rawDiv(TIER_BASE_OFFSET)).toUint8();
                    }
                }
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// FIXED PRICE LOGIC -- Immutable Arguments -- Internal -- Read Functions
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// @notice The byte length of the `Tiers` arg, used to decode the tiers array into the proper number of elements.
                function _tierDataLength() internal pure returns (uint256) {
                    return _getArgUint256(TIER_DATA_LENGTH_OFFSET);
                }
                /// -----------------------------------------------------------------------
                /// FIXED PRICE LOGIC -- Mutable State -- Public
                /// -----------------------------------------------------------------------
                /// @notice The active Tier of the sale, if in use.
                uint8 public currentTier;
                /// @notice The number of shares sold per tier.
                mapping(uint8 tier => uint256 totalSold) public amountSoldInTier;
                /// @notice The number of shares sold per tier per user.
                mapping(uint8 tier => mapping(address user => uint256 purchaseAmount)) public purchasedByTier;
                /// @notice The number of shares purchased by each user.
                /// @dev This value is normalized to 18 decimals.
                mapping(address user => uint256 sharesPurchased) public purchasedShares;
                /// @notice The total number of shares sold during the sale so far.
                /// @dev This value is normalized to 18 decimals.
                uint256 public totalSharesSold;
                /// @notice The total number of shares remaining for purchase.
                /// @dev This value is normalized to 18 decimals.
                function sharesRemaining() public view returns (uint256) {
                    return sharesForSale().rawSub(totalSharesSold);
                }
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// GLOBAL LOGIC -- OVERRIDE REQUIRED -- Public -- Read Functions
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// @notice Checks if the sale period has passed or the pool has reached its shares out cap.
                function canClose() public view override returns (bool) {
                    if (status == PoolStatus.Closed || status == PoolStatus.Canceled) {
                        return false;
                    }
                    // Greater comparision for safety purpose only
                    if (totalSharesSold >= sharesForSale() || uint40(block.timestamp) >= saleEnd()) {
                        return true;
                    }
                    return false;
                }
                /// @notice The underlying pricing mechanism for the pool.
                function poolType() public pure override returns (PoolType) {
                    return PoolType.Fixed;
                }
                /// @notice The keccak256 hash of the function used to buy shares in the pool.
                function typeHash() public pure override returns (bytes32) {
                    return keccak256(
                        "BuyExactShares(uint256 sharesOut,address recipient,uint32 nonce,uint64 deadline)"
                    );
                }
                /// @notice Returns the number of shares remaining for purchase for a specific user.
                /// @param user The address of the user to check.
                /// @return The number of shares remaining for purchase.
                /// @dev This value is normalized to 18 decimals.
                function userTokensRemaining(address user) public view override returns (uint256) {
                    return maximumTokensPerUser().rawSub(purchasedShares[user]).min(sharesRemaining());
                }
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// GLOBAL LOGIC -- OVERRIDE REQUIRED -- Internal -- Read Functions
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                ///@notice Checks if the minimum number of asset tokens have been swapped into the pool
                ///surpassed the creator-defined minimum.
                ///@dev Returning false will trigger refunds on `close` and user refunds on `redeem`.
                function _minReserveMet() internal view override returns (bool) {
                    if (minimumTokensForSale() > 0 && totalSharesSold < minimumTokensForSale()) {
                        return false;
                    }
                    return true;
                }
                /// -----------------------------------------------------------------------
                /// BUY LOGIC -- OVERRIDE REQUIRED -- Internal -- Read Functions
                /// -----------------------------------------------------------------------
                /// @notice Calculates the number of asset tokens that will be swapped into the pool before fees.
                /// @dev For overflow pools this is always the tokenAmount passed in, we're just conforming to the interface.
                function _calculateBaseAssetsIn(
                    address recipient,
                    uint256 tokenAmount,
                    uint256 maxPricePerShare
                )
                    internal
                    view
                    override
                    returns (uint256, TiersModified[] memory)
                {
                    if (!isTiered()) {
                        return (tokenAmount.mulWadUp(assetsPerToken()), new TiersModified[](0));
                    }
                    return _calculateTieredPurchase(recipient, tokenAmount, maxPricePerShare);
                }
                /// @notice Normalizes the assets being swapped in to 18 decimals, if needed.
                /// @param amount The amount of assets being swapped in.
                function _normalizeAmount(uint256 amount) internal pure override returns (uint256) {
                    return amount.normalize(shareDecimals());
                }
                /// @notice Checks if the pool has reached its asset token hard cap.
                /// @dev This value does not account for assets in the pool in the form of swap fees.
                function _raiseCapMet() internal view override returns (bool) {
                    // Greater comparision for safety purpose only
                    return totalSharesSold >= sharesForSale();
                }
                /// @notice Validates the amount of shares being swapped in do not exceed Overflow specific limits.
                /// @dev The amount of shares being swapped in must not exceed the shares for sale.
                /// @dev The amount of shares remaining for purchase before the pool cap is met after the swap must be greater than the mandatoryMinimumSwapIn to prevent the pool from being left with dust.
                /// @param amount The amount of shares being swapped in.
                function _validatePoolLimits(uint256 amount) internal view override {
                    if (amount > sharesForSale()) {
                        revert MaxPurchaseExeeded();
                    }
                    if (totalSharesSold.rawAdd(amount) > sharesForSale()) {
                        revert MaxPurchaseExeeded();
                    }
                    if (
                        mandatoryMinimumSwapIn() > 0 && sharesRemaining().rawSub(amount) > 0
                            && sharesRemaining().rawSub(amount) < mandatoryMinimumSwapIn()
                    ) {
                        revert MandatoryMinimumSwapThreshold();
                    }
                }
                /// @notice Validates the amount of shares being swapped in do not exceed FixedPrice specific user limits.
                /// @dev The amount of shares purchased in total(including this swap) by the user must not exceed the user's maximum purchase limit.
                /// @dev The amount of shares purchased in total(including this swap) must not be less than the user's minimum purchase limit.
                /// @param recipient The address of the user swapping in.
                /// @param tokenAmount The amount of shares being swapped in.
                function _validateUserLimits(address recipient, uint256 tokenAmount) internal view override {
                    uint256 updatedUserAmount = purchasedShares[recipient].rawAdd(tokenAmount);
                    if (updatedUserAmount > maximumTokensPerUser()) revert UserMaxPurchaseExceeded();
                    if (updatedUserAmount < minimumTokensPerUser()) revert UserMinPurchaseNotMet();
                }
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// BUY LOGIC -- OVERRIDE REQUIRED --  Internal -- Write Functions
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// @notice Helper function to emit the BuyFixedShares event post purchase.
                /// @dev All values are denormalized before being emitted.
                function _emitBuyEvent(
                    address recipient,
                    uint256 assetsIn,
                    uint256 feesPaid,
                    uint256 sharesOut
                )
                    internal
                    override
                {
                    emit BuyFixedShares(
                        recipient,
                        sharesOut.denormalizeDown(shareDecimals()),
                        assetsIn.denormalizeUp(assetDecimals()),
                        feesPaid.denormalizeUp(assetDecimals())
                    );
                }
                /// @notice Updates the pool state after a successful asset swap in.
                /// @dev Updates the total shares sold, the user's purchased shares, the user's assets in,
                /// the total assets in, and the total fees in.
                function _updatePoolState(
                    address recipient,
                    uint256 assetsIn,
                    uint256 sharesOut,
                    uint256 fees,
                    TiersModified[] memory tiersModified
                )
                    internal
                    override
                    returns (uint256)
                {
                    //Update Pool shares
                    totalSharesSold = totalSharesSold.rawAdd(sharesOut);
                    purchasedShares[recipient] = purchasedShares[recipient].rawAdd(sharesOut);
                    //Update Pool assets
                    userNormalizedAssetsIn[recipient] = userNormalizedAssetsIn[recipient].rawAdd(assetsIn);
                    totalNormalizedAssetsIn = totalNormalizedAssetsIn.rawAdd(assetsIn);
                    //Update Pool fees
                    totalNormalizedAssetFeesIn = totalNormalizedAssetFeesIn.rawAdd(fees);
                    if (isTiered()) {
                        _updateTierData(recipient, tiersModified);
                    }
                    return (assetsIn.rawAdd(fees));
                }
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// BUY LOGIC --  TIER SPECIFIC -- Internal -- Read Functions
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                ///@notice Helper function to calculate the amount of assets the user will swap into the pool and the amount of shares they are able to receive.
                ///@param tier The tier the user is attempting to purchase in.
                ///@param tierIndex The index of the tier the user is attempting to purchase in.
                ///@param newTotalUserPurchased The total amount of shares the user will have purchased in the tier after this purchase.
                ///@param newTotalSold The total amount of shares sold in the tier after this purchase.
                ///@param sharesOut The amount of shares the user is attempting to purchase.
                ///@return assetsIn The total amount of assets the user will swap into the pool before swap fees are applied.
                ///@return sharesOutInTier The total amount of shares the user will purchase in the tier.
                ///@dev This function will revert if the user is attempting to purchase more shares than they are allowed across all tiers.
                function _calculatePurchaseAmounts(
                    Tier memory tier,
                    address recipient,
                    uint8 tierIndex,
                    uint256 newTotalUserPurchased,
                    uint256 newTotalSold,
                    uint256 sharesOut
                )
                    internal
                    view
                    returns (uint256 assetsIn, uint256 sharesOutInTier)
                {
                    (uint256 userMaxAssetsIn, uint256 userMaxSharesOutInTier) = (0, 0);
                    (uint256 tierMaxAssetsIn, uint256 tierMaxSharesOutInTier) = (0, 0);
                    if (newTotalUserPurchased > tier.maximumPerUser) {
                        (userMaxAssetsIn, userMaxSharesOutInTier) =
                            _handleExcessPurchase(tier, recipient, tierIndex);
                    }
                    if (newTotalSold > tier.amountForSale) {
                        (tierMaxAssetsIn, tierMaxSharesOutInTier) = _handleTierOverflow(tier, tierIndex);
                    }
                    if (userMaxAssetsIn == 0 && tierMaxAssetsIn == 0) {
                        assetsIn = sharesOut.mulWadUp(tier.pricePerShare);
                        sharesOutInTier = sharesOut;
                    }
                    // If only the tier limit was exceeded
                    else if (userMaxAssetsIn == 0) {
                        (assetsIn, sharesOutInTier) = (tierMaxAssetsIn, tierMaxSharesOutInTier);
                    }
                    // If only the user limit was exceeded
                    else if (tierMaxAssetsIn == 0) {
                        (assetsIn, sharesOutInTier) = (userMaxAssetsIn, userMaxSharesOutInTier);
                    }
                    // If both limits were exceeded, take the minimum
                    else {
                        if (tierMaxAssetsIn < userMaxAssetsIn) {
                            (assetsIn, sharesOutInTier) = (tierMaxAssetsIn, tierMaxSharesOutInTier);
                        } else {
                            (assetsIn, sharesOutInTier) = (userMaxAssetsIn, userMaxSharesOutInTier);
                        }
                    }
                }
                ///@notice Helper function to handle the case where a user is attempting to purchase more shares than they are allowed for that tier.
                ///@param tier The tier the user is attempting to purchase in.
                ///@param recipient The address of the user attempting to purchase.
                ///@param tierIndex The index of the tier the user is attempting to purchase in.
                ///@dev This function will revert if there is no next tier as that would indicate they are unable to fulfill the current order.
                function _handleExcessPurchase(
                    Tier memory tier,
                    address recipient,
                    uint8 tierIndex
                )
                    internal
                    view
                    returns (uint256 assetsIn, uint256 sharesOutInTier)
                {
                    _validateNextTierExists(tierIndex);
                    sharesOutInTier = tier.maximumPerUser.rawSub(purchasedByTier[tierIndex][recipient]);
                    assetsIn = sharesOutInTier.mulWadUp(tier.pricePerShare);
                }
                ///@notice Helper function to handle the case where a user is attempting to purchase more shares than are available in the current tier.
                ///@param tier The tier the user is attempting to purchase in.
                ///@param tierIndex The index of the tier the user is attempting to purchase in.
                ///@dev This function will revert if there is no next tier as that would indicate they are unable to fulfill the current order.
                function _handleTierOverflow(
                    Tier memory tier,
                    uint8 tierIndex
                )
                    internal
                    view
                    returns (uint256 assetsIn, uint256 sharesOutInTier)
                {
                    _validateNextTierExists(tierIndex);
                    sharesOutInTier = tier.amountForSale.rawSub(amountSoldInTier[tierIndex]);
                    assetsIn = sharesOutInTier.mulWadUp(tier.pricePerShare);
                }
                ///@notice Helper function to check that the requested swap amount meets the minimum purchase requirements for the tier.
                // function _validateMinimumPurchase(
                //     uint256 tierIndex,
                //     uint256 minimumPerUser,
                //     uint256 tokenAmount
                // )
                //     internal
                //     pure
                // {
                //     if (tokenAmount < minimumPerUser) {
                //         revert TierPurchaseTooLow(tierIndex);
                //     }
                // }
                ///@notice Helper function to validate that the next tier exists before attempting to purchase in it and accessing OOB data.
                ///@param tierIndex The index of the tier the user is attempting to purchase in.
                ///@dev This function will revert if there is no next tier as that would indicate they are unable to fulfill the current order.
                function _validateNextTierExists(uint8 tierIndex) internal pure {
                    if (tierIndex + 1 > getTierLength() - 1) {
                        revert TierMaxPurchaseExceeded();
                    }
                }
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// BUY LOGIC --  TIER SPECIFIC -- Internal -- Write Functions
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                ///@notice Helper function to check if the current tier has reached its maximum shares sold and rollover to the next tier if needed.
                ///@param currentTierSharesOut The total amount of shares sold in the current tier.
                ///@param maximumInTier The maximum amount of shares that can be sold in the current tier.
                ///@dev emits a `TierRollover` event if the current tier has reached its maximum shares sold.
                function _handleTierRollover(uint256 currentTierSharesOut, uint256 maximumInTier) internal {
                    if (currentTierSharesOut >= maximumInTier) {
                        currentTier++;
                        emit TierRollover(currentTier);
                    }
                }
                ///@notice Helper function to perform an iteration across the current tier and all subsequent tiers to validate the user's
                ///requested purchase amount is within the bounds of the Tiers combined min/max purchase limits.
                ///@param recipient The address of the user purchasing shares.
                ///@param shareAmount The amount of shares the user is attempting to purchase.
                ///@return assetsIn The total amount of assets the user will swap into the pool before swap fees are applied.
                ///@dev This function will revert if the user is attempting to purchase more shares than they are allowed across all tiers. It will additionally
                ///rollover the tier to the next one if the current tier reaches its maximum shares sold within this transaction.
                function _calculateTieredPurchase(
                    address recipient,
                    uint256 shareAmount,
                    uint256 maxPricePerShare
                )
                    internal
                    view
                    returns (uint256 assetsIn, TiersModified[] memory tiersModified)
                {
                    uint256 tempSharesOut;
                    uint8 lengthOfTiers = getTierLength();
                    uint8 iter;
                    tiersModified = new TiersModified[](lengthOfTiers);
                    for (uint8 i = currentTier; i < lengthOfTiers; i++) {
                        if (maxPricePerShare != 0 && getTierData(i).pricePerShare > maxPricePerShare) {
                            revert SlippageExceeded();
                        }
                        //Ensure there is a next tier available and the user is not attempting to purchase more/less shares than they are allowed.
                        (uint256 assetsInInTier, uint256 sharesOutInTier) =
                            _validateAndReturnTierLimits(i, recipient, shareAmount.rawSub(tempSharesOut));
                        tiersModified[iter] = TiersModified({
                            tierIndex: i,
                            assetsIn: assetsInInTier,
                            sharesOutInTier: sharesOutInTier
                        });
                        tempSharesOut = tempSharesOut.rawAdd(sharesOutInTier);
                        assetsIn = assetsIn.rawAdd(assetsInInTier);
                        if (tempSharesOut > shareAmount) {
                            revert TierMaxPurchaseExceeded();
                        }
                        //If the user has purchased the requested amount of shares, exit the loop.
                        if (tempSharesOut == shareAmount) {
                            break;
                        }
                        unchecked {
                            iter++;
                        }
                    }
                    if (tempSharesOut != shareAmount) {
                        revert InvalidTierPurchaseAmount();
                    }
                }
                ///@notice Helper function to update state data for the tier at index after this iteration of purchases is complete.
                function _updateTierData(address recipient, TiersModified[] memory tiersModified) internal {
                    uint8 length = tiersModified.length.toUint8();
                    for (uint8 i; i < length; i++) {
                        if (tiersModified[i].assetsIn == 0) {
                            continue;
                        }
                        uint8 tierIndex = tiersModified[i].tierIndex;
                        uint256 sharesOutInTier = tiersModified[i].sharesOutInTier;
                        purchasedByTier[tierIndex][recipient] += sharesOutInTier;
                        amountSoldInTier[tierIndex] += sharesOutInTier;
                        _handleTierRollover(amountSoldInTier[tierIndex], getTierData(tierIndex).amountForSale);
                    }
                }
                ///@notice Helper function to update state data for the tier at index after this iteration of purchases is complete, and return both the assets in and shares out for the user.
                ///@param tierIndex The index of the tier to update.
                ///@param recipient The address of the user purchasing shares.
                ///@param sharesOutInTier The amount of shares the user is purchasing in the tier.
                ///@dev This function will revert if the user is attempting to purchase more shares than they are allowed across all tiers.
                function _validateAndReturnTierLimits(
                    uint8 tierIndex,
                    address recipient,
                    uint256 tokenAmount
                )
                    internal
                    view
                    returns (uint256 assetsIn, uint256 sharesOutInTier)
                {
                    Tier memory tier = getTierData(tierIndex);
                    // if one tier fail this condition when rollover the whole transaction will be reverted
                    if (tokenAmount < tier.minimumPerUser) {
                        revert TierPurchaseTooLow(tierIndex);
                    }
                    // _validateMinimumPurchase(tierIndex, tier.minimumPerUser, tokenAmount);
                    (assetsIn, sharesOutInTier) = _calculatePurchaseAmounts(
                        tier,
                        recipient,
                        tierIndex,
                        purchasedByTier[tierIndex][recipient].rawAdd(tokenAmount),
                        amountSoldInTier[tierIndex].rawAdd(tokenAmount),
                        tokenAmount
                    );
                }
                /// -----------------------------------------------------------------------
                /// BUY LOGIC -- PUBLIC -- Write Functions
                /// -----------------------------------------------------------------------
                ///@notice Allows a user to purchase shares in the pool by swapping in assets.
                ///@param sharesOut The amount of shares to swap out the pool.
                ///@param recipient The address that will receive the shares.
                ///@param deadline The deadline for the swap to be executed.
                ///@param signature The signature of the user authorizing the swap.
                ///@param proof The Merkle proof for the user's whitelist status.
                ///@dev If the pool has reached its asset token hard cap, the pool will emit a `PoolCompleted` event.
                /// @dev The sharesOut value should not be normalized to 18 decimals when supplied.
                function buyExactShares(
                    uint256 sharesOut,
                    address recipient,
                    uint64 deadline,
                    bytes memory signature,
                    bytes32[] memory proof
                )
                    public
                    whenSaleActive
                {
                    buy(sharesOut, recipient, deadline, signature, proof, 0);
                }
                ///@notice Allows a user to purchase shares in the pool by swapping in assets.
                ///@param sharesOut The amount of shares to swap out the pool.
                ///@param recipient The address that will receive the shares.
                ///@param deadline The deadline for the swap to be executed.
                ///@param signature The signature of the user authorizing the swap.
                ///@param proof The Merkle proof for the user's whitelist status.
                ///@param maxPricePerShare The maximum price per share the user is willing to pay.
                ///@dev If the pool has reached its asset token hard cap, the pool will emit a `PoolCompleted` event.
                /// @dev The sharesOut value should not be normalized to 18 decimals when supplied.
                function buyExactShares(
                    uint256 sharesOut,
                    address recipient,
                    uint64 deadline,
                    bytes memory signature,
                    bytes32[] memory proof,
                    uint256 maxPricePerShare
                )
                    public
                    whenSaleActive
                {
                    buy(sharesOut, recipient, deadline, signature, proof, maxPricePerShare);
                }
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// CLOSE LOGIC -- Overriden --  Internal -- Read Functionss
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// @notice Calculates and denormalizes the number of unsold shares that will be refunded to the owner.
                /// @dev For FixedPricePools this is the difference between the total shares sold and the shares available for purchase.
                function _calculateLeftoverShares() internal view override returns (uint256 sharesNotSold) {
                    sharesNotSold = (sharesForSale().rawSub(totalSharesSold)).denormalizeDown(shareDecimals());
                }
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// CLOSE LOGIC -- Overriden --  Internal -- Write Functions
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// @notice Helper function to handle refunding in the case of a minReserve not being met.
                /// @dev Refunds all shares to the owner(), and distro's asset swap fees to the platform.
                function _handleManagerRefund()
                    internal
                    override
                    returns (uint256 sharesNotSold, uint256 fundsRaised, uint256 swapFeesGenerated)
                {
                    (sharesNotSold, fundsRaised, swapFeesGenerated) = super._handleManagerRefund();
                    sharesNotSold = sharesNotSold.rawSub(totalSharesSold.denormalizeDown(shareDecimals()));
                    if (shareToken() != address(0)) {
                        uint256 sharesTotal = IERC20(shareToken()).balanceOf(address(this));
                        if (sharesTotal > 0) {
                            shareToken().safeTransfer(owner(), sharesTotal);
                        }
                    }
                }
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// REDEEM LOGIC -- Overriden --  Internal -- READ Functions
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// @notice Calculates and denormalizes the number of shares owed to the user based on the number of shares they have purchased.
                function _calculateSharesOwed(address sender)
                    internal
                    view
                    override
                    returns (uint256 sharesOut)
                {
                    sharesOut = purchasedShares[sender].denormalizeDown(shareDecimals());
                }
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// REDEEM LOGIC -- Overriden --  Internal -- Write Functions
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// @notice Sets the users assets in and purchased shares balances to 0 after a successful redemption.
                function _handleUpdateUserRedemption(address sender) internal override {
                    purchasedShares[sender] = 0;
                    userNormalizedAssetsIn[sender] = 0;
                }
                /// @notice Helper function to handle refunding in the case of a minReserve not being met.
                /// @dev Refunds all assets to the purchaser sans swap fees.
                function _handleUserRefund(address sender) internal override returns (uint256 assetsOwed) {
                    assetsOwed = userNormalizedAssetsIn[sender].denormalizeDown(assetDecimals());
                    purchasedShares[sender] = 0;
                    userNormalizedAssetsIn[sender] = 0;
                    if (assetsOwed > 0) {
                        assetToken().safeTransfer(sender, assetsOwed);
                    }
                }
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                ///  EIP712 Helper Functions
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// @notice Overrides the default domain name and version for EIP-712 signatures.
                function _domainNameAndVersion()
                    internal
                    pure
                    override
                    returns (string memory name, string memory version)
                {
                    name = "FixedPricePool";
                    version = "1.0.0";
                }
            }
            // SPDX-License-Identifier: AGPL-3.0-only
            pragma solidity =0.8.25;
            import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol";
            import { FixedPointMathLib } from "solady/utils/FixedPointMathLib.sol";
            import { ReentrancyGuard } from "solady/utils/ReentrancyGuard.sol";
            import { Clone } from "solady/utils/Clone.sol";
            import { MerkleProofLib } from "solady/utils/MerkleProofLib.sol";
            import { EIP712 } from "solady/utils/EIP712.sol";
            import { ECDSA } from "solady/utils/ECDSA.sol";
            import { ud60x18 } from "@prb/math/src/UD60x18.sol";
            import {
                ISablierV2LockupLinear,
                IERC20
            } from "@sablier/v2-core/src/interfaces/ISablierV2LockupLinear.sol";
            import { Broker, LockupLinear } from "@sablier/v2-core/src/types/DataTypes.sol";
            import { FjordMath } from "./libraries/FjordMath.sol";
            import { FjordConstants } from "./libraries/FjordConstants.sol";
            enum PoolStatus {
                Active,
                Paused,
                Closed,
                Canceled
            }
            enum PoolType {
                Fixed,
                Overflow
            }
            /// @notice A struct representing a tiered sale within a FixedPricePool.
            /// @param amountForSale The total number of shares available for purchase in this tier.
            /// @param pricePerShare The price per share in this tier.
            /// @param maximumPerUser The maximum number of shares a user can purchase in this tier.
            /// @param minimumPerUser The minimum number of shares a user must purchase in this tier.
            struct Tier {
                uint256 amountForSale;
                uint256 pricePerShare;
                uint256 maximumPerUser;
                uint256 minimumPerUser;
            }
            struct TiersModified {
                uint8 tierIndex;
                uint256 assetsIn;
                uint256 sharesOutInTier;
            }
            abstract contract BasePool is Clone, ReentrancyGuard, EIP712, FjordConstants {
                /// -----------------------------------------------------------------------
                /// Dependencies
                /// -----------------------------------------------------------------------
                using SafeTransferLib for address;
                using FixedPointMathLib for uint256;
                using FjordMath for *;
                using MerkleProofLib for *;
                using ECDSA for bytes32;
                /// -----------------------------------------------------------------------
                /// Errors
                /// -----------------------------------------------------------------------
                /// @notice Error when the whitelist proof provided is invalid or does not exist.
                error InvalidProof();
                /// @notice Error when the recovered signer of the signature is not the delegate signer.
                error InvalidSignature();
                /// @notice Error when the user attempts to purchase/supply more than the maximum allowed.
                error MaxPurchaseExeeded();
                /// @notice Error when the user attempts to purchase/supply less than the minimum allowed.
                error MinPurchaseNotMet();
                /// @notice Error when the user attempts to redeem shares that they do not have.
                error NoSharesRedeemable();
                /// @notice Error when the caller is not the pool owner.
                error NotOwner();
                /// @notice Error when the redemption timestamp has not been reached.
                error RedeemedTooEarly();
                /// @notice Error when the sale is still active.
                error SaleActive();
                /// @notice Error when a redeem is called on a canceled pool.
                error SaleCancelled();
                /// @notice Error when the sale is paused/canceled/closed.
                error SaleInactive();
                /// @notice Error when the sale is not cancelable due to the sale being active.
                error SaleNotCancelable();
                /// @notice Error when the sale is not pausable due to the sale being closed or cancelled.
                error SaleNotPausable();
                /// @notice Error when the user attempts to purchase/supply an amount that would leave less than the minimum swap threshold available in the pool.
                error MandatoryMinimumSwapThreshold();
                /// @notice Error when the signature deadline has passed.
                error StaleSignature();
                /// @notice Error emitted when a user tries to redeem a token that is not redeemable, generally due to the token being airdropped on a different chain post sale.
                error TokenNotRedeemable();
                /// @notice Error when a user tries to swap an amount of tokens that is 0.
                error TransferZero();
                /// @notice Error when a user tries to purchase more than the maximum purchase amount.
                error UserMaxPurchaseExceeded();
                /// @notice Error when the user tries to purchase less than the minimum purchase amount.
                error UserMinPurchaseNotMet();
                /// @notice Error when the recipient address is the zero address.
                error ZeroAddress();
                /// @notice Invalid close operations.
                error CloseConditionNotMet();
                /// -----------------------------------------------------------------------
                /// Events
                /// -----------------------------------------------------------------------
                /// @notice Emitted when the pool is closed and the funds are distributed.
                event Closed(
                    uint256 totalFundsRaised, uint256 totalSharesSold, uint256 platformFee, uint256 swapFee
                );
                /// @notice Emitted when the pool is paused or unpaused.
                event PauseToggled(bool paused);
                /// @notice Emitted when the pool is canceled before it begins.
                event PoolCanceled();
                /// @notice Emitted when the pool is able to close early due to reaching its raise cap.
                event PoolCompleted();
                /// @notice Emitted when a user is refunded due to the raise goal not being met.
                event Refunded(address indexed recipient, uint256 amount);
                /// @notice Emitted when a user redeems their shares post sale if the raise goal was met.
                event Redeemed(address indexed recipient, uint256 shares, uint256 streamID);
                /// @notice Emitted when the raise goal is not met and the pool is closed.
                event RaiseGoalNotMet(uint256 sharesNotSold, uint256 fundsRaised, uint256 feesGenerated);
                /// -----------------------------------------------------------------------
                /// Immutable Arguments -- Public
                /// -----------------------------------------------------------------------
                ISablierV2LockupLinear public immutable SABLIER;
                /// -----------------------------------------------------------------------
                /// Immutable Arguments -- Public
                /// -----------------------------------------------------------------------
                /// @notice The owner of the pool.
                /// @dev The owner can cancel the sale before it starts, pause/unpause the sale, and will receive the funds raised post sale.
                function owner() public pure returns (address) {
                    return _getArgAddress(OWNER_OFFSET);
                }
                /// @notice The address of the share token that is being sold off by the creator.
                function shareToken() public pure returns (address) {
                    return _getArgAddress(SHARE_TOKEN_OFFSET);
                }
                /// @notice Returns the address of the asset token used for purchasing shares.
                function assetToken() public pure returns (address) {
                    return _getArgAddress(ASSET_TOKEN_OFFSET);
                }
                /// @notice Returns the address of the recipient of platform and swap fees generated by the pool.
                function feeRecipient() public pure returns (address) {
                    return _getArgAddress(FEE_RECIPIENT_OFFSET);
                }
                /// @notice Returns the address of the delegate signer used for anti-snipe protection.
                /// @dev This address is provided by the factory contract and is protocol-owned.
                function delegateSigner() public pure returns (address) {
                    return _getArgAddress(DELEGATE_SIGNER_OFFSET);
                }
                /// @notice The total number of shares that are being sold during the sale.
                /// @dev This value is normalized to 18 decimals.
                function sharesForSale() public pure virtual returns (uint256) {
                    return _getArgUint256(SHARES_FOR_SALE_OFFSET);
                }
                /// @notice Returns the minimum raise goal defined by the creator.
                /// @dev For FixedPricePools, this is the number of shares that must be sold.
                /// @dev For OverflowPools, this is the number of assets that must be raised.
                /// @dev If the minimum raise goal is not met, users and creator are refunded.
                /// @dev This value is normalized to 18 decimals.
                function minimumTokensForSale() public pure returns (uint256) {
                    return _getArgUint256(MINIMUM_TOKENS_FOR_SALE_OFFSET);
                }
                /// @notice Returns the maximum number of tokens that can be purchased within a sale.
                /// @dev For FixedPricePools, this is the number of shares a user can purchase.
                /// @dev For OverflowPools, this is the number of assets a user can used to purchase.
                /// @dev This value is normalized to 18 decimals.
                function maximumTokensPerUser() public pure returns (uint256) {
                    return _getArgUint256(MAXIMUM_TOKENS_PER_USER_OFFSET);
                }
                /// @notice Returns the minimum number of tokens that must be purchased within a sale.
                /// @dev For FixedPricePools, this is the minimum number of shares a user must purchase.
                /// @dev For OverflowPools, this is the minimum number of assets a user must use to purchase.
                /// @dev This value is normalized to 18 decimals.
                function minimumTokensPerUser() public pure returns (uint256) {
                    return _getArgUint256(MINIMUM_TOKENS_PER_USER_OFFSET);
                }
                /// @notice The swap fee charged on each purchase.
                /// @dev This value is scaled to WAD such that 1e18 is equivalent to a 100% swap fee.
                function swapFeeWAD() public pure returns (uint64) {
                    return _getArgUint64(SWAP_FEE_WAD_OFFSET);
                }
                /// @notice The platform fee charged on post-sale funds raised.
                function platformFeeWAD() public pure returns (uint64) {
                    return _getArgUint64(PLATFORM_FEE_WAD_OFFSET);
                }
                /// @notice The timestamp at which the sale will start.
                function saleStart() public pure returns (uint40) {
                    return _getArgUint40(SALE_START_OFFSET);
                }
                /// @notice The timestamp at which the sale will end.
                /// @dev This value is bypassed if a raise goal is defined and met or exceeded.
                function saleEnd() public pure returns (uint40) {
                    return _getArgUint40(SALE_END_OFFSET);
                }
                /// @notice The timestamp at which users will be able to redeem their shares.
                /// @dev This value is bypassed in favor of a 24H max should a sale end early due to meeting its raise cap.
                function redemptionDelay() public pure returns (uint40) {
                    return _getArgUint40(REDEMPTION_DELAY_OFFSET);
                }
                /// @notice The timestamp at which the vesting period will end.
                function vestEnd() public pure returns (uint40) {
                    return _getArgUint40(VEST_END_OFFSET);
                }
                /// @notice The timestamp at which the vesting cliff period will end.
                function vestCliff() public pure returns (uint40) {
                    return _getArgUint40(VEST_CLIFF_OFFSET);
                }
                /// @notice The number of decimals for the share token.
                function shareDecimals() public pure returns (uint8) {
                    return _getArgUint8(SHARE_TOKEN_DECIMALS_OFFSET);
                }
                /// @notice Returns the number of decimals for the asset token.
                function assetDecimals() public pure returns (uint8) {
                    return _getArgUint8(ASSET_TOKEN_DECIMALS_OFFSET);
                }
                /// @notice Returns true if the anti-snipe feature is enabled, false otherwise.
                /// @dev If anti-snipe is enabled, a valid signature from a delegate signer is required to make a purchase.
                function antiSnipeEnabled() public pure returns (bool) {
                    return _getArgUint8(ANTISNIPE_ENABLED_OFFSET) != 0;
                }
                /// @notice A merkle root representing a whitelist of addresses allowed to participate in the sale.
                /// @dev If the whitelist is empty, the sale is open to all addresses.
                function whitelistMerkleRoot() public pure returns (bytes32) {
                    return _getArgBytes32(WHITELIST_MERKLE_ROOT_OFFSET);
                }
                function vestingEnabled() public pure returns (bool) {
                    return vestEnd() > saleEnd();
                }
                /// -----------------------------------------------------------------------
                /// Mutable State -- Public
                /// -----------------------------------------------------------------------
                /// @notice The current transaction nonce of the recipient, used for anti-snipe replay protection.
                mapping(address user => uint32 nonce) public nonces;
                /// @notice The current status of the pool (Paused, Active, Canceled, Closed).
                PoolStatus public status;
                /// @notice The total number of assets received during the sale, sans swap fees.
                /// @dev Must be denormalized before use.
                uint256 public totalNormalizedAssetsIn;
                /// @notice The total amount of swap fees generated during the sale.
                /// @dev Must be denormalized before use.
                uint256 public totalNormalizedAssetFeesIn;
                /// @notice The total normalized number of assets received per user, without accounting for swap fees.
                /// @dev Must be denormalized before use.
                mapping(address user => uint256 assetsIn) public userNormalizedAssetsIn;
                /// @dev actual sale end timestamp
                uint256 public saleEndTimestamp;
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// Constructor
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                constructor(address sablier) {
                    SABLIER = ISablierV2LockupLinear(sablier);
                }
                /// -----------------------------------------------------------------------
                /// Modifiers
                /// -----------------------------------------------------------------------
                /// @notice Checks if the caller is the owner of the pool.
                modifier onlyOwner() {
                    if (msg.sender != owner()) {
                        revert NotOwner();
                    }
                    _;
                }
                /// @notice Checks if the current timestamp is lessthan the sale start, greater than the sale end, or canceled/closed/paused.
                /// @dev If the sale is not active, the pool bought into.
                modifier whenSaleActive() {
                    if (
                        uint40(block.timestamp) < saleStart() || uint40(block.timestamp) >= saleEnd()
                            || PoolStatus.Active != status
                    ) {
                        revert SaleInactive();
                    }
                    _;
                }
                /// -----------------------------------------------------------------------
                /// GLOBAL LOGIC -- OVERRIDE REQUIRED -- Public -- Read Functions
                /// -----------------------------------------------------------------------
                /// @notice Checks if the pool can be closed.
                /// @return True if the pool can be closed, false otherwise.
                /// @dev The pool can be closed if all shares have been sold, or the sale end date has passed.
                function canClose() public view virtual returns (bool);
                /// @notice Returns the pool's pricing model (Fixed or Overflow).
                function poolType() public pure virtual returns (PoolType);
                /// @notice Returns the hash of the EIP712 typehash for the pool's buy function.
                function typeHash() public pure virtual returns (bytes32);
                /// @notice Returns the number of tokens remaining for purchase.
                /// @dev For FixedPricePools, this is the Math.min(sharesForSale - totalSharesSold, maximumTokensPerUser - purchasedShares[user]).
                /// @dev For OverflowPools, this is maximumTokensPerUser - rawAssetsIn[user] when mTPU > 0.
                function userTokensRemaining(address user) public view virtual returns (uint256);
                /// -----------------------------------------------------------------------
                /// GLOBAL LOGIC -- OVERRIDE REQUIRED -- Internal -- Read Functions
                /// -----------------------------------------------------------------------
                ///@dev Checks if the minimum reserve is set and whether or not the shares/assets in sold surpasses this value.
                function _minReserveMet() internal view virtual returns (bool);
                /// -----------------------------------------------------------------------
                /// GLOBAL LOGIC -- Public -- Read Functions
                /// -----------------------------------------------------------------------
                /// @notice Whether or not a non-empty whitelist is present.
                function hasWhitelist() public pure returns (bool) {
                    return whitelistMerkleRoot() != 0;
                }
                /// -----------------------------------------------------------------------
                /// BUY LOGIC -- OVERRIDE REQUIRED -- Internal -- Read Functions
                /// -----------------------------------------------------------------------
                ///@notice Calculates the base assets in based on the pool type.
                ///@dev For FixedPricePools, this will additionally handle tier logic.
                function _calculateBaseAssetsIn(
                    address recipient,
                    uint256 tokenAmount,
                    uint256 maxPricePerShare
                )
                    internal
                    view
                    virtual
                    returns (uint256, TiersModified[] memory);
                ///@dev Normalizes the amount based on the pool type.
                ///@dev For FixedPricePools, this is the number of shares being purchased.
                ///@dev For OverflowPools, this is the number of assets being used to purchase.
                function _normalizeAmount(uint256 amount) internal pure virtual returns (uint256);
                ///@dev Checks if the raise cap has been met and if the pool can be closed early.
                function _raiseCapMet() internal view virtual returns (bool);
                ///@notice Validates the pool limits based on the pool type.
                ///@param amount The number of tokens being purchased/used to purchase based on the pool type.
                ///@dev For fixed price pools this checks total shares sold, for overflow pools this checks total assets in.
                function _validatePoolLimits(uint256 amount) internal view virtual;
                ///@notice Updates the user's normalized assets in the pool.
                ///@param recipient The address of the recipient of the purchase.
                ///@param tokenAmount The number of tokens being purchased/used to purchase based on the pool type.
                ///@dev Checks if the updated user amount exceeds the maximumTokensPerUser and reverts if so.
                function _validateUserLimits(address recipient, uint256 tokenAmount) internal view virtual;
                /// -----------------------------------------------------------------------
                /// BUY LOGIC -- OVERRIDE REQUIRED -- Internal -- Write Functions
                /// -----------------------------------------------------------------------
                ///@dev Emits the buy event for the pool based on the pool type's implementation.
                function _emitBuyEvent(
                    address recipient,
                    uint256 assetsIn,
                    uint256 feesPaid,
                    uint256 sharesOut
                )
                    internal
                    virtual;
                ///@dev Handles updating pool state and user state post-purchase.
                ///@dev Additionally handles the transfer of assets to the pool.
                ///@param recipient The address of the recipient of the purchase.
                ///@param assetsIn The number of assets being used to purchase based on the pool type.
                ///@param sharesOut The number of shares being purchased based on the pool type.
                ///@param fees The swap fees generated from the purchase.
                function _updatePoolState(
                    address recipient,
                    uint256 assetsIn,
                    uint256 sharesOut,
                    uint256 fees,
                    TiersModified[] memory updatedTiers
                )
                    internal
                    virtual
                    returns (uint256);
                /// -----------------------------------------------------------------------
                /// BUY LOGIC -- Public -- Read Functions
                /// -----------------------------------------------------------------------
                ///@notice Returns the minimum swap threshold required for a purchase to be valid.
                ///@dev This is used to prevent rounding errors when making swaps between tokens of varying decimals.
                function mandatoryMinimumSwapIn() public pure virtual returns (uint256) {
                    return shareDecimals().mandatoryMinimumSwapIn(assetDecimals());
                }
                ///@notice Calculates the swap fees and assets in based on the pool type and token amount being purchased/used to purchase.
                ///@param recipient The address of the recipient of the purchase.
                ///@param tokenAmount The number of tokens being purchased/used to purchase based on the pool type.
                ///@dev This function will account for tiers and all user-defined purchase limits, if applicable.
                function previewBuy(
                    uint256 tokenAmount,
                    address recipient
                )
                    public
                    view
                    returns (uint256 assetsIn, uint256 feesPaid, TiersModified[] memory updatedTiers)
                {
                    return previewBuy(tokenAmount, recipient, 0);
                }
                ///@notice Calculates the swap fees and assets in based on the pool type and token amount being purchased/used to purchase.
                ///@param recipient The address of the recipient of the purchase.
                ///@param tokenAmount The number of tokens being purchased/used to purchase based on the pool type.
                ///@dev This function will account for tiers and all user-defined purchase limits, if applicable.
                function previewBuy(
                    uint256 tokenAmount,
                    address recipient,
                    uint256 maxPricePerShare
                )
                    public
                    view
                    returns (uint256 assetsIn, uint256 feesPaid, TiersModified[] memory updatedTiers)
                {
                    //Normalize the token amount based on the pool type
                    tokenAmount = _normalizeAmount(tokenAmount);
                    //Zero-checks and min/max purchase amount checks
                    _validateBaseConditions(tokenAmount, recipient);
                    //Pool-type specific conditional checks
                    _validatePoolLimits(tokenAmount);
                    //Pool-type specific User-specific conditional checks
                    _validateUserLimits(recipient, tokenAmount);
                    (assetsIn, updatedTiers) = _calculateBaseAssetsIn(recipient, tokenAmount, maxPricePerShare);
                    feesPaid = _calculateFees(assetsIn);
                }
                /// -----------------------------------------------------------------------
                /// BUY LOGIC -- Internal -- Read Functions
                /// -----------------------------------------------------------------------
                /// @notice restrict access to whitelisted addresses.
                /// @dev  checks if the recipient address is whitelisted using a Merkle proof.
                function _validateWhitelist(address recipient, bytes32[] memory proof) internal pure {
                    if (!proof.verify(whitelistMerkleRoot(), keccak256(abi.encodePacked(recipient)))) {
                        revert InvalidProof();
                    }
                }
                ///@notice Verifies the signature of buy payload for anti-snipe protection.
                ///@param recipient The address of the recipient of the purchase.
                ///@param tokenAmount The number of tokens being purchased/used to purchase based on the pool type.
                ///@param deadline The deadline for the signature to be valid.
                ///@param signature The signature to be verified.
                ///@dev Recovers the signer of the payload and compares it to the delegate signer.
                function _validateAntisnipe(
                    address recipient,
                    uint256 tokenAmount,
                    uint64 deadline,
                    bytes memory signature
                )
                    internal
                    view
                {
                    if (uint64(block.timestamp) > deadline) {
                        revert StaleSignature();
                    }
                    bytes32 expectedDigest = getDigest(tokenAmount, recipient, deadline);
                    address signer = expectedDigest.recover(signature);
                    if (signer != delegateSigner()) {
                        revert InvalidSignature();
                    }
                }
                ///@notice Helper function to validate non-zero token amounts and recipient addresses and
                ///ensures minimum purchase amounts are upheld. Passes the signature and proof to the
                ///_checkWhitelistAndAntisnipe function.
                function _validateBaseConditions(uint256 tokenAmount, address recipient) internal pure {
                    if (tokenAmount == 0) revert TransferZero();
                    if (recipient == address(0)) revert ZeroAddress();
                    if (tokenAmount < mandatoryMinimumSwapIn()) revert MinPurchaseNotMet();
                }
                ///@notice Calculates the swap fees based on the swapFeeWAD and the token amount.
                function _calculateFees(uint256 assetsIn) internal pure returns (uint256) {
                    return assetsIn.mulWadUp(swapFeeWAD());
                }
                /// -----------------------------------------------------------------------
                /// BUY LOGIC -- Internal --  Write Functions
                /// -----------------------------------------------------------------------
                /// @notice Allows any user to purchase shares in the pool.
                /// @param amount The number of shares to purchase (Fixed) or assets in (Overflow).
                /// @param recipient The address to receive the shares.
                /// @param deadline The deadline for the signature to be valid if anti-snipe is enabled.
                /// @param signature The signature to be verified if anti-snipe is enabled.
                /// @param proof The Merkle proof to be verified if a whitelist is present.
                function buy(
                    uint256 amount,
                    address recipient,
                    uint64 deadline,
                    bytes memory signature,
                    bytes32[] memory proof,
                    uint256 maxPricePerShare
                )
                    internal
                    nonReentrant
                    whenSaleActive
                {
                    if (hasWhitelist()) {
                        _validateWhitelist(recipient, proof);
                    }
                    if (antiSnipeEnabled()) {
                        _validateAntisnipe(recipient, amount, deadline, signature);
                    }
                    (uint256 normalizedAssetsIn, uint256 normalizedFees, TiersModified[] memory updatedTiers) =
                        previewBuy(amount, recipient, maxPricePerShare);
                    uint256 sharesOut = poolType() == PoolType.Fixed ? amount.normalize(shareDecimals()) : 0;
                    uint256 normalizedAssetsOwed =
                        _updatePoolState(recipient, normalizedAssetsIn, sharesOut, normalizedFees, updatedTiers);
                    if (normalizedAssetsOwed > 0) {
                        assetToken().safeTransferFrom(
                            msg.sender, address(this), normalizedAssetsOwed.denormalizeUp(assetDecimals())
                        );
                    }
                    if (antiSnipeEnabled()) {
                        // increase nonce
                        nonces[recipient]++;
                    }
                    _emitBuyEvent(recipient, normalizedAssetsIn, normalizedFees, sharesOut);
                    //close early if the raise cap is met
                    _handleEarlyClose();
                }
                /// @notice Checks if the pool has met its raise cap
                /// and if so, emits the PoolCompleted event.
                function _handleEarlyClose() internal {
                    if (_raiseCapMet()) {
                        emit PoolCompleted();
                        close();
                    }
                }
                /// -----------------------------------------------------------------------
                /// CLOSE LOGIC -- OVERRIDE REQUIRED -- Internal -- Read Functions
                /// -----------------------------------------------------------------------
                ///@notice Calculates the leftover shares that were not sold during the sale.
                ///@dev If overflow, this is sharesForSale(), otherwise it's sharesForSale() - totalSharesSold.
                function _calculateLeftoverShares() internal view virtual returns (uint256);
                /// -----------------------------------------------------------------------
                /// CLOSE LOGIC -- OVERRIDE REQUIRED -- Internal -- Write Functions
                /// -----------------------------------------------------------------------
                /// @notice Handles the refund of the owner's shares in the pool and the transfer of swap fees to the fee recipient.
                /// @dev Only called if the raise goal was not met. The overriding function should handle the transfer of funds to the owner
                /// according to the pool type.
                function _handleManagerRefund()
                    internal
                    virtual
                    returns (uint256 sharesNotSold, uint256 fundsRaised, uint256 swapFees)
                {
                    sharesNotSold = sharesForSale().denormalizeDown(shareDecimals());
                    swapFees = totalNormalizedAssetFeesIn.denormalizeDown(assetDecimals());
                    if (swapFees > 0) {
                        assetToken().safeTransfer(feeRecipient(), swapFees);
                    }
                    fundsRaised = totalNormalizedAssetsIn.denormalizeUp(assetDecimals());
                    uint256 currentBalance = assetToken().balanceOf(address(this));
                    if (fundsRaised > currentBalance) {
                        // possible precision loss after denormalize
                        fundsRaised = currentBalance;
                    } else if (fundsRaised < currentBalance) {
                        // if someone donates assets to the pool, then take all back to owner
                        assetToken().safeTransfer(owner(), currentBalance - fundsRaised);
                    }
                }
                /// -----------------------------------------------------------------------
                /// CLOSE LOGIC -- Public -- Write Functions
                /// -----------------------------------------------------------------------
                // @notice Allows any user to close the pool and distribute the fees.
                // @dev The pool can only be closed after the sale end date has passed, OR the max shares sold have been reached.
                function close() public {
                    if (!canClose()) {
                        revert CloseConditionNotMet();
                    }
                    status = PoolStatus.Closed;
                    saleEndTimestamp =
                        uint256(saleEnd()) < block.timestamp ? uint256(saleEnd()) : block.timestamp;
                    if (!_minReserveMet()) {
                        (uint256 sharesNotSold, uint256 fundsRaised, uint256 swapFee) = _handleManagerRefund();
                        emit RaiseGoalNotMet(sharesNotSold, fundsRaised, swapFee);
                        return;
                    } else {
                        // avoid shawdow variable
                        (uint256 platformFees, uint256 swapFees, uint256 totalFees) = _calculateCloseFees();
                        if (totalFees > 0) {
                            assetToken().safeTransfer(feeRecipient(), totalFees);
                        }
                        uint256 fundsRaised = IERC20(assetToken()).balanceOf(address(this));
                        if (fundsRaised > 0) {
                            assetToken().safeTransfer(owner(), fundsRaised);
                        }
                        uint256 sharesNotSold = _calculateLeftoverShares();
                        // return the unsold shares to the owner
                        if (sharesNotSold > 0 && shareToken() != address(0)) {
                            shareToken().safeTransfer(owner(), sharesNotSold);
                        }
                        //totalsharessold, fundsraised
                        emit Closed(
                            fundsRaised,
                            sharesForSale().denormalizeDown(shareDecimals()).rawSub(sharesNotSold),
                            platformFees,
                            swapFees
                        );
                        if (vestingEnabled()) {
                            shareToken().safeApprove(address(SABLIER), type(uint256).max);
                        }
                    }
                }
                /// -----------------------------------------------------------------------
                /// CLOSE LOGIC -- Internal -- Read Functions
                /// -----------------------------------------------------------------------
                ///@dev Calculates the fees generated during the sale and denormalizes them for event emission and transfer.
                function _calculateCloseFees()
                    internal
                    view
                    returns (uint256 platformFees, uint256 swapFees, uint256 totalFees)
                {
                    platformFees = totalNormalizedAssetsIn.mulWad(platformFeeWAD());
                    // denormalize the fees for event emission.
                    swapFees = totalNormalizedAssetFeesIn.denormalizeDown(assetDecimals());
                    platformFees = platformFees.denormalizeDown(assetDecimals());
                    // totalFees sum of platformFees and swapFees
                    totalFees = platformFees + swapFees;
                }
                /// -----------------------------------------------------------------------
                /// REDEEM LOGIC -- OVERRIDE REQUIRED - Internal -- Read Functions
                /// -----------------------------------------------------------------------
                /// @notice Calculates the amount of shares owed to the user based on the pool type.
                /// @dev For FixedPricePools, this is the number of shares the user has purchased directly.
                /// @dev For OverflowPools, this is calculate as the ratio of the users assets to the total assets in the pool
                /// multiplied by the total shares for sale.
                function _calculateSharesOwed(address user) internal view virtual returns (uint256);
                /// -----------------------------------------------------------------------
                /// REDEEM LOGIC -- OVERRIDE REQUIRED - Internal -- Write Functions
                /// -----------------------------------------------------------------------
                /// @notice Handles the refund/transfer of the user's assets in the pool if the raise goal was not met
                /// and updates user-specific state variables.
                /// @dev For FixedPricePools, this sets the user's sharesPurchased and assetsIn to 0.
                /// @dev For OverflowPools, this sets the user's assetsIn to 0.
                function _handleUserRefund(address user) internal virtual returns (uint256 assetsOwed);
                /// @notice Handles the state updates triggered on user-specific variables of pool state post-redemption.
                /// @dev For FixedPricePools, this sets the user's sharesPurchased and assetsIn to 0.
                /// @dev For OverflowPools, this sets the user's assetsIn to 0.
                function _handleUpdateUserRedemption(address sender) internal virtual;
                /// -----------------------------------------------------------------------
                /// REDEEM LOGIC -- External -- Write Functions
                /// -----------------------------------------------------------------------
                // @notice Allows any user to redeem their shares after the redemption timestamp has passed.
                // @dev Users can only redeem their shares if the sale has closed and the redemption timestamp has passed.
                // unless the pool met a hard cap and closed early, at which point the redemption timestamp is
                function redeem() external nonReentrant returns (uint256 streamID) {
                    if (status == PoolStatus.Canceled) {
                        revert SaleCancelled();
                    }
                    if (status != PoolStatus.Closed) {
                        revert SaleActive();
                    }
                    if (block.timestamp < saleEndTimestamp + redemptionDelay()) {
                        revert RedeemedTooEarly();
                    }
                    uint256 sharesOut;
                    address sender = msg.sender;
                    if (!_minReserveMet()) {
                        emit Refunded(sender, _handleUserRefund(sender));
                    } else {
                        if (shareToken() != address(0)) {
                            sharesOut = _calculateSharesOwed(sender);
                            if (sharesOut == 0) {
                                revert NoSharesRedeemable();
                            }
                            _handleUpdateUserRedemption(sender);
                            streamID = _handleRedemptionPayment(sender, sharesOut);
                            emit Redeemed(sender, sharesOut, streamID);
                        } else {
                            revert TokenNotRedeemable();
                        }
                    }
                }
                /// -----------------------------------------------------------------------
                /// REDEEM LOGIC -- Internal -- Write Functions
                /// -----------------------------------------------------------------------
                ///@notice Handles the transfer of shares to the user post-redemption.
                ///@param recipient The address of the recipient of the shares.
                ///@param sharesOwed The number of shares owed to the user.
                ///@dev Only utilized if the raise goal was met.
                ///@dev If vesting is enabled and not expired, the shares are streamed to the user via sablier.
                function _handleRedemptionPayment(
                    address recipient,
                    uint256 sharesOwed
                )
                    internal
                    returns (uint256 streamID)
                {
                    if (vestingEnabled() && vestEnd() > uint40(block.timestamp)) {
                        LockupLinear.CreateWithRange memory params;
                        params.sender = owner();
                        params.recipient = recipient;
                        params.totalAmount = uint128(sharesOwed);
                        params.asset = IERC20(shareToken());
                        params.cancelable = false;
                        params.range =
                            LockupLinear.Range({ start: saleEnd(), end: vestEnd(), cliff: vestCliff() });
                        params.broker = Broker(address(0), ud60x18(0));
                        streamID = SABLIER.createWithRange(params);
                    } else {
                        shareToken().safeTransfer(recipient, sharesOwed);
                    }
                }
                /// -----------------------------------------------------------------------
                /// POOL ADMIN LOGIC -- External -- Owner-Only -- Write Functions
                /// -----------------------------------------------------------------------
                /// @notice Allows the pool creator to cancel the sale and withdraw all funds and shares before a sale begins.
                /// @dev The pool can only be canceled if the sale has not started.
                function cancelSale() external nonReentrant onlyOwner {
                    if (status != PoolStatus.Active && status != PoolStatus.Paused) {
                        revert SaleNotCancelable();
                    }
                    if (uint40(block.timestamp) >= saleStart()) {
                        revert SaleActive();
                    }
                    status = PoolStatus.Canceled;
                    if (shareToken() != address(0)) {
                        shareToken().safeTransfer(owner(), sharesForSale().denormalizeDown(shareDecimals()));
                    }
                    emit PoolCanceled();
                }
                /// @notice Allows the pool creator to pause/unpause the sale, halting/enabling any trading activity.
                function togglePause() external nonReentrant onlyOwner {
                    if (status == PoolStatus.Canceled || status == PoolStatus.Closed) {
                        revert SaleNotPausable();
                    }
                    bool paused = status == PoolStatus.Paused;
                    status = paused ? PoolStatus.Active : PoolStatus.Paused;
                    emit PauseToggled(!paused);
                }
                /// -----------------------------------------------------------------------
                /// EIP712 Logic  -- External -- Read Functions
                /// -----------------------------------------------------------------------
                /// @notice Returns the expected digest for the EIP712 signature.
                /// @param tokenAmount The number of tokens being purchased/used to purchase based on the pool type.
                /// @param recipient The address of the recipient of the purchase.
                /// @param deadline The deadline for the signature to be valid.
                function getDigest(
                    uint256 tokenAmount,
                    address recipient,
                    uint64 deadline
                )
                    public
                    view
                    returns (bytes32)
                {
                    return _hashTypedData(
                        keccak256(
                            abi.encode(typeHash(), tokenAmount, recipient, nonces[recipient] + 1, deadline)
                        )
                    );
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.4;
            /// @notice Safe integer casting library that reverts on overflow.
            /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeCastLib.sol)
            /// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/SafeCast.sol)
            library SafeCastLib {
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                       CUSTOM ERRORS                        */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                error Overflow();
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*          UNSIGNED INTEGER SAFE CASTING OPERATIONS          */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                function toUint8(uint256 x) internal pure returns (uint8) {
                    if (x >= 1 << 8) _revertOverflow();
                    return uint8(x);
                }
                function toUint16(uint256 x) internal pure returns (uint16) {
                    if (x >= 1 << 16) _revertOverflow();
                    return uint16(x);
                }
                function toUint24(uint256 x) internal pure returns (uint24) {
                    if (x >= 1 << 24) _revertOverflow();
                    return uint24(x);
                }
                function toUint32(uint256 x) internal pure returns (uint32) {
                    if (x >= 1 << 32) _revertOverflow();
                    return uint32(x);
                }
                function toUint40(uint256 x) internal pure returns (uint40) {
                    if (x >= 1 << 40) _revertOverflow();
                    return uint40(x);
                }
                function toUint48(uint256 x) internal pure returns (uint48) {
                    if (x >= 1 << 48) _revertOverflow();
                    return uint48(x);
                }
                function toUint56(uint256 x) internal pure returns (uint56) {
                    if (x >= 1 << 56) _revertOverflow();
                    return uint56(x);
                }
                function toUint64(uint256 x) internal pure returns (uint64) {
                    if (x >= 1 << 64) _revertOverflow();
                    return uint64(x);
                }
                function toUint72(uint256 x) internal pure returns (uint72) {
                    if (x >= 1 << 72) _revertOverflow();
                    return uint72(x);
                }
                function toUint80(uint256 x) internal pure returns (uint80) {
                    if (x >= 1 << 80) _revertOverflow();
                    return uint80(x);
                }
                function toUint88(uint256 x) internal pure returns (uint88) {
                    if (x >= 1 << 88) _revertOverflow();
                    return uint88(x);
                }
                function toUint96(uint256 x) internal pure returns (uint96) {
                    if (x >= 1 << 96) _revertOverflow();
                    return uint96(x);
                }
                function toUint104(uint256 x) internal pure returns (uint104) {
                    if (x >= 1 << 104) _revertOverflow();
                    return uint104(x);
                }
                function toUint112(uint256 x) internal pure returns (uint112) {
                    if (x >= 1 << 112) _revertOverflow();
                    return uint112(x);
                }
                function toUint120(uint256 x) internal pure returns (uint120) {
                    if (x >= 1 << 120) _revertOverflow();
                    return uint120(x);
                }
                function toUint128(uint256 x) internal pure returns (uint128) {
                    if (x >= 1 << 128) _revertOverflow();
                    return uint128(x);
                }
                function toUint136(uint256 x) internal pure returns (uint136) {
                    if (x >= 1 << 136) _revertOverflow();
                    return uint136(x);
                }
                function toUint144(uint256 x) internal pure returns (uint144) {
                    if (x >= 1 << 144) _revertOverflow();
                    return uint144(x);
                }
                function toUint152(uint256 x) internal pure returns (uint152) {
                    if (x >= 1 << 152) _revertOverflow();
                    return uint152(x);
                }
                function toUint160(uint256 x) internal pure returns (uint160) {
                    if (x >= 1 << 160) _revertOverflow();
                    return uint160(x);
                }
                function toUint168(uint256 x) internal pure returns (uint168) {
                    if (x >= 1 << 168) _revertOverflow();
                    return uint168(x);
                }
                function toUint176(uint256 x) internal pure returns (uint176) {
                    if (x >= 1 << 176) _revertOverflow();
                    return uint176(x);
                }
                function toUint184(uint256 x) internal pure returns (uint184) {
                    if (x >= 1 << 184) _revertOverflow();
                    return uint184(x);
                }
                function toUint192(uint256 x) internal pure returns (uint192) {
                    if (x >= 1 << 192) _revertOverflow();
                    return uint192(x);
                }
                function toUint200(uint256 x) internal pure returns (uint200) {
                    if (x >= 1 << 200) _revertOverflow();
                    return uint200(x);
                }
                function toUint208(uint256 x) internal pure returns (uint208) {
                    if (x >= 1 << 208) _revertOverflow();
                    return uint208(x);
                }
                function toUint216(uint256 x) internal pure returns (uint216) {
                    if (x >= 1 << 216) _revertOverflow();
                    return uint216(x);
                }
                function toUint224(uint256 x) internal pure returns (uint224) {
                    if (x >= 1 << 224) _revertOverflow();
                    return uint224(x);
                }
                function toUint232(uint256 x) internal pure returns (uint232) {
                    if (x >= 1 << 232) _revertOverflow();
                    return uint232(x);
                }
                function toUint240(uint256 x) internal pure returns (uint240) {
                    if (x >= 1 << 240) _revertOverflow();
                    return uint240(x);
                }
                function toUint248(uint256 x) internal pure returns (uint248) {
                    if (x >= 1 << 248) _revertOverflow();
                    return uint248(x);
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*           SIGNED INTEGER SAFE CASTING OPERATIONS           */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                function toInt8(int256 x) internal pure returns (int8) {
                    int8 y = int8(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt16(int256 x) internal pure returns (int16) {
                    int16 y = int16(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt24(int256 x) internal pure returns (int24) {
                    int24 y = int24(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt32(int256 x) internal pure returns (int32) {
                    int32 y = int32(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt40(int256 x) internal pure returns (int40) {
                    int40 y = int40(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt48(int256 x) internal pure returns (int48) {
                    int48 y = int48(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt56(int256 x) internal pure returns (int56) {
                    int56 y = int56(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt64(int256 x) internal pure returns (int64) {
                    int64 y = int64(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt72(int256 x) internal pure returns (int72) {
                    int72 y = int72(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt80(int256 x) internal pure returns (int80) {
                    int80 y = int80(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt88(int256 x) internal pure returns (int88) {
                    int88 y = int88(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt96(int256 x) internal pure returns (int96) {
                    int96 y = int96(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt104(int256 x) internal pure returns (int104) {
                    int104 y = int104(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt112(int256 x) internal pure returns (int112) {
                    int112 y = int112(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt120(int256 x) internal pure returns (int120) {
                    int120 y = int120(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt128(int256 x) internal pure returns (int128) {
                    int128 y = int128(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt136(int256 x) internal pure returns (int136) {
                    int136 y = int136(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt144(int256 x) internal pure returns (int144) {
                    int144 y = int144(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt152(int256 x) internal pure returns (int152) {
                    int152 y = int152(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt160(int256 x) internal pure returns (int160) {
                    int160 y = int160(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt168(int256 x) internal pure returns (int168) {
                    int168 y = int168(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt176(int256 x) internal pure returns (int176) {
                    int176 y = int176(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt184(int256 x) internal pure returns (int184) {
                    int184 y = int184(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt192(int256 x) internal pure returns (int192) {
                    int192 y = int192(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt200(int256 x) internal pure returns (int200) {
                    int200 y = int200(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt208(int256 x) internal pure returns (int208) {
                    int208 y = int208(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt216(int256 x) internal pure returns (int216) {
                    int216 y = int216(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt224(int256 x) internal pure returns (int224) {
                    int224 y = int224(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt232(int256 x) internal pure returns (int232) {
                    int232 y = int232(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt240(int256 x) internal pure returns (int240) {
                    int240 y = int240(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt248(int256 x) internal pure returns (int248) {
                    int248 y = int248(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*               OTHER SAFE CASTING OPERATIONS                */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                function toInt256(uint256 x) internal pure returns (int256) {
                    if (x >= 1 << 255) _revertOverflow();
                    return int256(x);
                }
                function toUint256(int256 x) internal pure returns (uint256) {
                    if (x < 0) _revertOverflow();
                    return uint256(x);
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                      PRIVATE HELPERS                       */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                function _revertOverflow() private pure {
                    /// @solidity memory-safe-assembly
                    assembly {
                        // Store the function selector of `Overflow()`.
                        mstore(0x00, 0x35278d12)
                        // Revert with (offset, size).
                        revert(0x1c, 0x04)
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.4;
            /// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
            /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeTransferLib.sol)
            /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)
            ///
            /// @dev Note:
            /// - For ETH transfers, please use `forceSafeTransferETH` for DoS protection.
            /// - For ERC20s, this implementation won't check that a token has code,
            ///   responsibility is delegated to the caller.
            library SafeTransferLib {
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                       CUSTOM ERRORS                        */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev The ETH transfer has failed.
                error ETHTransferFailed();
                /// @dev The ERC20 `transferFrom` has failed.
                error TransferFromFailed();
                /// @dev The ERC20 `transfer` has failed.
                error TransferFailed();
                /// @dev The ERC20 `approve` has failed.
                error ApproveFailed();
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                         CONSTANTS                          */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Suggested gas stipend for contract receiving ETH that disallows any storage writes.
                uint256 internal constant GAS_STIPEND_NO_STORAGE_WRITES = 2300;
                /// @dev Suggested gas stipend for contract receiving ETH to perform a few
                /// storage reads and writes, but low enough to prevent griefing.
                uint256 internal constant GAS_STIPEND_NO_GRIEF = 100000;
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                       ETH OPERATIONS                       */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                // If the ETH transfer MUST succeed with a reasonable gas budget, use the force variants.
                //
                // The regular variants:
                // - Forwards all remaining gas to the target.
                // - Reverts if the target reverts.
                // - Reverts if the current contract has insufficient balance.
                //
                // The force variants:
                // - Forwards with an optional gas stipend
                //   (defaults to `GAS_STIPEND_NO_GRIEF`, which is sufficient for most cases).
                // - If the target reverts, or if the gas stipend is exhausted,
                //   creates a temporary contract to force send the ETH via `SELFDESTRUCT`.
                //   Future compatible with `SENDALL`: https://eips.ethereum.org/EIPS/eip-4758.
                // - Reverts if the current contract has insufficient balance.
                //
                // The try variants:
                // - Forwards with a mandatory gas stipend.
                // - Instead of reverting, returns whether the transfer succeeded.
                /// @dev Sends `amount` (in wei) ETH to `to`.
                function safeTransferETH(address to, uint256 amount) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if iszero(call(gas(), to, amount, codesize(), 0x00, codesize(), 0x00)) {
                            mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
                            revert(0x1c, 0x04)
                        }
                    }
                }
                /// @dev Sends all the ETH in the current contract to `to`.
                function safeTransferAllETH(address to) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        // Transfer all the ETH and check if it succeeded or not.
                        if iszero(call(gas(), to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {
                            mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
                            revert(0x1c, 0x04)
                        }
                    }
                }
                /// @dev Force sends `amount` (in wei) ETH to `to`, with a `gasStipend`.
                function forceSafeTransferETH(address to, uint256 amount, uint256 gasStipend) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if lt(selfbalance(), amount) {
                            mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
                            revert(0x1c, 0x04)
                        }
                        if iszero(call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)) {
                            mstore(0x00, to) // Store the address in scratch space.
                            mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                            mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                            if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
                        }
                    }
                }
                /// @dev Force sends all the ETH in the current contract to `to`, with a `gasStipend`.
                function forceSafeTransferAllETH(address to, uint256 gasStipend) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if iszero(call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {
                            mstore(0x00, to) // Store the address in scratch space.
                            mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                            mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                            if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
                        }
                    }
                }
                /// @dev Force sends `amount` (in wei) ETH to `to`, with `GAS_STIPEND_NO_GRIEF`.
                function forceSafeTransferETH(address to, uint256 amount) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if lt(selfbalance(), amount) {
                            mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
                            revert(0x1c, 0x04)
                        }
                        if iszero(call(GAS_STIPEND_NO_GRIEF, to, amount, codesize(), 0x00, codesize(), 0x00)) {
                            mstore(0x00, to) // Store the address in scratch space.
                            mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                            mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                            if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
                        }
                    }
                }
                /// @dev Force sends all the ETH in the current contract to `to`, with `GAS_STIPEND_NO_GRIEF`.
                function forceSafeTransferAllETH(address to) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        // forgefmt: disable-next-item
                        if iszero(call(GAS_STIPEND_NO_GRIEF, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {
                            mstore(0x00, to) // Store the address in scratch space.
                            mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                            mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                            if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
                        }
                    }
                }
                /// @dev Sends `amount` (in wei) ETH to `to`, with a `gasStipend`.
                function trySafeTransferETH(address to, uint256 amount, uint256 gasStipend)
                    internal
                    returns (bool success)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        success := call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)
                    }
                }
                /// @dev Sends all the ETH in the current contract to `to`, with a `gasStipend`.
                function trySafeTransferAllETH(address to, uint256 gasStipend)
                    internal
                    returns (bool success)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        success := call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)
                    }
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                      ERC20 OPERATIONS                      */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Sends `amount` of ERC20 `token` from `from` to `to`.
                /// Reverts upon failure.
                ///
                /// The `from` account must have at least `amount` approved for
                /// the current contract to manage.
                function safeTransferFrom(address token, address from, address to, uint256 amount) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        let m := mload(0x40) // Cache the free memory pointer.
                        mstore(0x60, amount) // Store the `amount` argument.
                        mstore(0x40, to) // Store the `to` argument.
                        mstore(0x2c, shl(96, from)) // Store the `from` argument.
                        mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`.
                        // Perform the transfer, reverting upon failure.
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                                call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
                            )
                        ) {
                            mstore(0x00, 0x7939f424) // `TransferFromFailed()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x60, 0) // Restore the zero slot to zero.
                        mstore(0x40, m) // Restore the free memory pointer.
                    }
                }
                /// @dev Sends all of ERC20 `token` from `from` to `to`.
                /// Reverts upon failure.
                ///
                /// The `from` account must have their entire balance approved for
                /// the current contract to manage.
                function safeTransferAllFrom(address token, address from, address to)
                    internal
                    returns (uint256 amount)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        let m := mload(0x40) // Cache the free memory pointer.
                        mstore(0x40, to) // Store the `to` argument.
                        mstore(0x2c, shl(96, from)) // Store the `from` argument.
                        mstore(0x0c, 0x70a08231000000000000000000000000) // `balanceOf(address)`.
                        // Read the balance, reverting upon failure.
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                gt(returndatasize(), 0x1f), // At least 32 bytes returned.
                                staticcall(gas(), token, 0x1c, 0x24, 0x60, 0x20)
                            )
                        ) {
                            mstore(0x00, 0x7939f424) // `TransferFromFailed()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x00, 0x23b872dd) // `transferFrom(address,address,uint256)`.
                        amount := mload(0x60) // The `amount` is already at 0x60. We'll need to return it.
                        // Perform the transfer, reverting upon failure.
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                                call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
                            )
                        ) {
                            mstore(0x00, 0x7939f424) // `TransferFromFailed()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x60, 0) // Restore the zero slot to zero.
                        mstore(0x40, m) // Restore the free memory pointer.
                    }
                }
                /// @dev Sends `amount` of ERC20 `token` from the current contract to `to`.
                /// Reverts upon failure.
                function safeTransfer(address token, address to, uint256 amount) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        mstore(0x14, to) // Store the `to` argument.
                        mstore(0x34, amount) // Store the `amount` argument.
                        mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.
                        // Perform the transfer, reverting upon failure.
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                                call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
                            )
                        ) {
                            mstore(0x00, 0x90b8ec18) // `TransferFailed()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
                    }
                }
                /// @dev Sends all of ERC20 `token` from the current contract to `to`.
                /// Reverts upon failure.
                function safeTransferAll(address token, address to) internal returns (uint256 amount) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        mstore(0x00, 0x70a08231) // Store the function selector of `balanceOf(address)`.
                        mstore(0x20, address()) // Store the address of the current contract.
                        // Read the balance, reverting upon failure.
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                gt(returndatasize(), 0x1f), // At least 32 bytes returned.
                                staticcall(gas(), token, 0x1c, 0x24, 0x34, 0x20)
                            )
                        ) {
                            mstore(0x00, 0x90b8ec18) // `TransferFailed()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x14, to) // Store the `to` argument.
                        amount := mload(0x34) // The `amount` is already at 0x34. We'll need to return it.
                        mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.
                        // Perform the transfer, reverting upon failure.
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                                call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
                            )
                        ) {
                            mstore(0x00, 0x90b8ec18) // `TransferFailed()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
                    }
                }
                /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract.
                /// Reverts upon failure.
                function safeApprove(address token, address to, uint256 amount) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        mstore(0x14, to) // Store the `to` argument.
                        mstore(0x34, amount) // Store the `amount` argument.
                        mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.
                        // Perform the approval, reverting upon failure.
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                                call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
                            )
                        ) {
                            mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
                    }
                }
                /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract.
                /// If the initial attempt to approve fails, attempts to reset the approved amount to zero,
                /// then retries the approval again (some tokens, e.g. USDT, requires this).
                /// Reverts upon failure.
                function safeApproveWithRetry(address token, address to, uint256 amount) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        mstore(0x14, to) // Store the `to` argument.
                        mstore(0x34, amount) // Store the `amount` argument.
                        mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.
                        // Perform the approval, retrying upon failure.
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                                call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
                            )
                        ) {
                            mstore(0x34, 0) // Store 0 for the `amount`.
                            mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.
                            pop(call(gas(), token, 0, 0x10, 0x44, codesize(), 0x00)) // Reset the approval.
                            mstore(0x34, amount) // Store back the original `amount`.
                            // Retry the approval, reverting upon failure.
                            if iszero(
                                and(
                                    or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                                    call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
                                )
                            ) {
                                mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`.
                                revert(0x1c, 0x04)
                            }
                        }
                        mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
                    }
                }
                /// @dev Returns the amount of ERC20 `token` owned by `account`.
                /// Returns zero if the `token` does not exist.
                function balanceOf(address token, address account) internal view returns (uint256 amount) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        mstore(0x14, account) // Store the `account` argument.
                        mstore(0x00, 0x70a08231000000000000000000000000) // `balanceOf(address)`.
                        amount :=
                            mul(
                                mload(0x20),
                                and( // The arguments of `and` are evaluated from right to left.
                                    gt(returndatasize(), 0x1f), // At least 32 bytes returned.
                                    staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20)
                                )
                            )
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.4;
            /// @notice Arithmetic library with operations for fixed-point numbers.
            /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/FixedPointMathLib.sol)
            /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol)
            library FixedPointMathLib {
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                       CUSTOM ERRORS                        */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev The operation failed, as the output exceeds the maximum value of uint256.
                error ExpOverflow();
                /// @dev The operation failed, as the output exceeds the maximum value of uint256.
                error FactorialOverflow();
                /// @dev The operation failed, due to an overflow.
                error RPowOverflow();
                /// @dev The mantissa is too big to fit.
                error MantissaOverflow();
                /// @dev The operation failed, due to an multiplication overflow.
                error MulWadFailed();
                /// @dev The operation failed, due to an multiplication overflow.
                error SMulWadFailed();
                /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.
                error DivWadFailed();
                /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.
                error SDivWadFailed();
                /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.
                error MulDivFailed();
                /// @dev The division failed, as the denominator is zero.
                error DivFailed();
                /// @dev The full precision multiply-divide operation failed, either due
                /// to the result being larger than 256 bits, or a division by a zero.
                error FullMulDivFailed();
                /// @dev The output is undefined, as the input is less-than-or-equal to zero.
                error LnWadUndefined();
                /// @dev The input outside the acceptable domain.
                error OutOfDomain();
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                         CONSTANTS                          */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev The scalar of ETH and most ERC20s.
                uint256 internal constant WAD = 1e18;
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*              SIMPLIFIED FIXED POINT OPERATIONS             */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Equivalent to `(x * y) / WAD` rounded down.
                function mulWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        // Equivalent to `require(y == 0 || x <= type(uint256).max / y)`.
                        if mul(y, gt(x, div(not(0), y))) {
                            mstore(0x00, 0xbac65e5b) // `MulWadFailed()`.
                            revert(0x1c, 0x04)
                        }
                        z := div(mul(x, y), WAD)
                    }
                }
                /// @dev Equivalent to `(x * y) / WAD` rounded down.
                function sMulWad(int256 x, int256 y) internal pure returns (int256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := mul(x, y)
                        // Equivalent to `require((x == 0 || z / x == y) && !(x == -1 && y == type(int256).min))`.
                        if iszero(gt(or(iszero(x), eq(sdiv(z, x), y)), lt(not(x), eq(y, shl(255, 1))))) {
                            mstore(0x00, 0xedcd4dd4) // `SMulWadFailed()`.
                            revert(0x1c, 0x04)
                        }
                        z := sdiv(z, WAD)
                    }
                }
                /// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks.
                function rawMulWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := div(mul(x, y), WAD)
                    }
                }
                /// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks.
                function rawSMulWad(int256 x, int256 y) internal pure returns (int256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := sdiv(mul(x, y), WAD)
                    }
                }
                /// @dev Equivalent to `(x * y) / WAD` rounded up.
                function mulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        // Equivalent to `require(y == 0 || x <= type(uint256).max / y)`.
                        if mul(y, gt(x, div(not(0), y))) {
                            mstore(0x00, 0xbac65e5b) // `MulWadFailed()`.
                            revert(0x1c, 0x04)
                        }
                        z := add(iszero(iszero(mod(mul(x, y), WAD))), div(mul(x, y), WAD))
                    }
                }
                /// @dev Equivalent to `(x * y) / WAD` rounded up, but without overflow checks.
                function rawMulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := add(iszero(iszero(mod(mul(x, y), WAD))), div(mul(x, y), WAD))
                    }
                }
                /// @dev Equivalent to `(x * WAD) / y` rounded down.
                function divWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        // Equivalent to `require(y != 0 && (WAD == 0 || x <= type(uint256).max / WAD))`.
                        if iszero(mul(y, iszero(mul(WAD, gt(x, div(not(0), WAD)))))) {
                            mstore(0x00, 0x7c5f487d) // `DivWadFailed()`.
                            revert(0x1c, 0x04)
                        }
                        z := div(mul(x, WAD), y)
                    }
                }
                /// @dev Equivalent to `(x * WAD) / y` rounded down.
                function sDivWad(int256 x, int256 y) internal pure returns (int256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := mul(x, WAD)
                        // Equivalent to `require(y != 0 && ((x * WAD) / WAD == x))`.
                        if iszero(and(iszero(iszero(y)), eq(sdiv(z, WAD), x))) {
                            mstore(0x00, 0x5c43740d) // `SDivWadFailed()`.
                            revert(0x1c, 0x04)
                        }
                        z := sdiv(mul(x, WAD), y)
                    }
                }
                /// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks.
                function rawDivWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := div(mul(x, WAD), y)
                    }
                }
                /// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks.
                function rawSDivWad(int256 x, int256 y) internal pure returns (int256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := sdiv(mul(x, WAD), y)
                    }
                }
                /// @dev Equivalent to `(x * WAD) / y` rounded up.
                function divWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        // Equivalent to `require(y != 0 && (WAD == 0 || x <= type(uint256).max / WAD))`.
                        if iszero(mul(y, iszero(mul(WAD, gt(x, div(not(0), WAD)))))) {
                            mstore(0x00, 0x7c5f487d) // `DivWadFailed()`.
                            revert(0x1c, 0x04)
                        }
                        z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y))
                    }
                }
                /// @dev Equivalent to `(x * WAD) / y` rounded up, but without overflow and divide by zero checks.
                function rawDivWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y))
                    }
                }
                /// @dev Equivalent to `x` to the power of `y`.
                /// because `x ** y = (e ** ln(x)) ** y = e ** (ln(x) * y)`.
                function powWad(int256 x, int256 y) internal pure returns (int256) {
                    // Using `ln(x)` means `x` must be greater than 0.
                    return expWad((lnWad(x) * y) / int256(WAD));
                }
                /// @dev Returns `exp(x)`, denominated in `WAD`.
                /// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln
                function expWad(int256 x) internal pure returns (int256 r) {
                    unchecked {
                        // When the result is less than 0.5 we return zero.
                        // This happens when `x <= (log(1e-18) * 1e18) ~ -4.15e19`.
                        if (x <= -41446531673892822313) return r;
                        /// @solidity memory-safe-assembly
                        assembly {
                            // When the result is greater than `(2**255 - 1) / 1e18` we can not represent it as
                            // an int. This happens when `x >= floor(log((2**255 - 1) / 1e18) * 1e18) ≈ 135`.
                            if iszero(slt(x, 135305999368893231589)) {
                                mstore(0x00, 0xa37bfec9) // `ExpOverflow()`.
                                revert(0x1c, 0x04)
                            }
                        }
                        // `x` is now in the range `(-42, 136) * 1e18`. Convert to `(-42, 136) * 2**96`
                        // for more intermediate precision and a binary basis. This base conversion
                        // is a multiplication by 1e18 / 2**96 = 5**18 / 2**78.
                        x = (x << 78) / 5 ** 18;
                        // Reduce range of x to (-½ ln 2, ½ ln 2) * 2**96 by factoring out powers
                        // of two such that exp(x) = exp(x') * 2**k, where k is an integer.
                        // Solving this gives k = round(x / log(2)) and x' = x - k * log(2).
                        int256 k = ((x << 96) / 54916777467707473351141471128 + 2 ** 95) >> 96;
                        x = x - k * 54916777467707473351141471128;
                        // `k` is in the range `[-61, 195]`.
                        // Evaluate using a (6, 7)-term rational approximation.
                        // `p` is made monic, we'll multiply by a scale factor later.
                        int256 y = x + 1346386616545796478920950773328;
                        y = ((y * x) >> 96) + 57155421227552351082224309758442;
                        int256 p = y + x - 94201549194550492254356042504812;
                        p = ((p * y) >> 96) + 28719021644029726153956944680412240;
                        p = p * x + (4385272521454847904659076985693276 << 96);
                        // We leave `p` in `2**192` basis so we don't need to scale it back up for the division.
                        int256 q = x - 2855989394907223263936484059900;
                        q = ((q * x) >> 96) + 50020603652535783019961831881945;
                        q = ((q * x) >> 96) - 533845033583426703283633433725380;
                        q = ((q * x) >> 96) + 3604857256930695427073651918091429;
                        q = ((q * x) >> 96) - 14423608567350463180887372962807573;
                        q = ((q * x) >> 96) + 26449188498355588339934803723976023;
                        /// @solidity memory-safe-assembly
                        assembly {
                            // Div in assembly because solidity adds a zero check despite the unchecked.
                            // The q polynomial won't have zeros in the domain as all its roots are complex.
                            // No scaling is necessary because p is already `2**96` too large.
                            r := sdiv(p, q)
                        }
                        // r should be in the range `(0.09, 0.25) * 2**96`.
                        // We now need to multiply r by:
                        // - The scale factor `s ≈ 6.031367120`.
                        // - The `2**k` factor from the range reduction.
                        // - The `1e18 / 2**96` factor for base conversion.
                        // We do this all at once, with an intermediate result in `2**213`
                        // basis, so the final right shift is always by a positive amount.
                        r = int256(
                            (uint256(r) * 3822833074963236453042738258902158003155416615667) >> uint256(195 - k)
                        );
                    }
                }
                /// @dev Returns `ln(x)`, denominated in `WAD`.
                /// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln
                function lnWad(int256 x) internal pure returns (int256 r) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        // We want to convert `x` from `10**18` fixed point to `2**96` fixed point.
                        // We do this by multiplying by `2**96 / 10**18`. But since
                        // `ln(x * C) = ln(x) + ln(C)`, we can simply do nothing here
                        // and add `ln(2**96 / 10**18)` at the end.
                        // Compute `k = log2(x) - 96`, `r = 159 - k = 255 - log2(x) = 255 ^ log2(x)`.
                        r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
                        r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
                        r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
                        r := or(r, shl(4, lt(0xffff, shr(r, x))))
                        r := or(r, shl(3, lt(0xff, shr(r, x))))
                        // We place the check here for more optimal stack operations.
                        if iszero(sgt(x, 0)) {
                            mstore(0x00, 0x1615e638) // `LnWadUndefined()`.
                            revert(0x1c, 0x04)
                        }
                        // forgefmt: disable-next-item
                        r := xor(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),
                            0xf8f9f9faf9fdfafbf9fdfcfdfafbfcfef9fafdfafcfcfbfefafafcfbffffffff))
                        // Reduce range of x to (1, 2) * 2**96
                        // ln(2^k * x) = k * ln(2) + ln(x)
                        x := shr(159, shl(r, x))
                        // Evaluate using a (8, 8)-term rational approximation.
                        // `p` is made monic, we will multiply by a scale factor later.
                        // forgefmt: disable-next-item
                        let p := sub( // This heavily nested expression is to avoid stack-too-deep for via-ir.
                            sar(96, mul(add(43456485725739037958740375743393,
                            sar(96, mul(add(24828157081833163892658089445524,
                            sar(96, mul(add(3273285459638523848632254066296,
                                x), x))), x))), x)), 11111509109440967052023855526967)
                        p := sub(sar(96, mul(p, x)), 45023709667254063763336534515857)
                        p := sub(sar(96, mul(p, x)), 14706773417378608786704636184526)
                        p := sub(mul(p, x), shl(96, 795164235651350426258249787498))
                        // We leave `p` in `2**192` basis so we don't need to scale it back up for the division.
                        // `q` is monic by convention.
                        let q := add(5573035233440673466300451813936, x)
                        q := add(71694874799317883764090561454958, sar(96, mul(x, q)))
                        q := add(283447036172924575727196451306956, sar(96, mul(x, q)))
                        q := add(401686690394027663651624208769553, sar(96, mul(x, q)))
                        q := add(204048457590392012362485061816622, sar(96, mul(x, q)))
                        q := add(31853899698501571402653359427138, sar(96, mul(x, q)))
                        q := add(909429971244387300277376558375, sar(96, mul(x, q)))
                        // `p / q` is in the range `(0, 0.125) * 2**96`.
                        // Finalization, we need to:
                        // - Multiply by the scale factor `s = 5.549…`.
                        // - Add `ln(2**96 / 10**18)`.
                        // - Add `k * ln(2)`.
                        // - Multiply by `10**18 / 2**96 = 5**18 >> 78`.
                        // The q polynomial is known not to have zeros in the domain.
                        // No scaling required because p is already `2**96` too large.
                        p := sdiv(p, q)
                        // Multiply by the scaling factor: `s * 5**18 * 2**96`, base is now `5**18 * 2**192`.
                        p := mul(1677202110996718588342820967067443963516166, p)
                        // Add `ln(2) * k * 5**18 * 2**192`.
                        // forgefmt: disable-next-item
                        p := add(mul(16597577552685614221487285958193947469193820559219878177908093499208371, sub(159, r)), p)
                        // Add `ln(2**96 / 10**18) * 5**18 * 2**192`.
                        p := add(600920179829731861736702779321621459595472258049074101567377883020018308, p)
                        // Base conversion: mul `2**18 / 2**192`.
                        r := sar(174, p)
                    }
                }
                /// @dev Returns `W_0(x)`, denominated in `WAD`.
                /// See: https://en.wikipedia.org/wiki/Lambert_W_function
                /// a.k.a. Product log function. This is an approximation of the principal branch.
                function lambertW0Wad(int256 x) internal pure returns (int256 w) {
                    // forgefmt: disable-next-item
                    unchecked {
                        if ((w = x) <= -367879441171442322) revert OutOfDomain(); // `x` less than `-1/e`.
                        int256 wad = int256(WAD);
                        int256 p = x;
                        uint256 c; // Whether we need to avoid catastrophic cancellation.
                        uint256 i = 4; // Number of iterations.
                        if (w <= 0x1ffffffffffff) {
                            if (-0x4000000000000 <= w) {
                                i = 1; // Inputs near zero only take one step to converge.
                            } else if (w <= -0x3ffffffffffffff) {
                                i = 32; // Inputs near `-1/e` take very long to converge.
                            }
                        } else if (w >> 63 == 0) {
                            /// @solidity memory-safe-assembly
                            assembly {
                                // Inline log2 for more performance, since the range is small.
                                let v := shr(49, w)
                                let l := shl(3, lt(0xff, v))
                                l := add(or(l, byte(and(0x1f, shr(shr(l, v), 0x8421084210842108cc6318c6db6d54be)),
                                    0x0706060506020504060203020504030106050205030304010505030400000000)), 49)
                                w := sdiv(shl(l, 7), byte(sub(l, 31), 0x0303030303030303040506080c13))
                                c := gt(l, 60)
                                i := add(2, add(gt(l, 53), c))
                            }
                        } else {
                            int256 ll = lnWad(w = lnWad(w));
                            /// @solidity memory-safe-assembly
                            assembly {
                                // `w = ln(x) - ln(ln(x)) + b * ln(ln(x)) / ln(x)`.
                                w := add(sdiv(mul(ll, 1023715080943847266), w), sub(w, ll))
                                i := add(3, iszero(shr(68, x)))
                                c := iszero(shr(143, x))
                            }
                            if (c == 0) {
                                do { // If `x` is big, use Newton's so that intermediate values won't overflow.
                                    int256 e = expWad(w);
                                    /// @solidity memory-safe-assembly
                                    assembly {
                                        let t := mul(w, div(e, wad))
                                        w := sub(w, sdiv(sub(t, x), div(add(e, t), wad)))
                                    }
                                    if (p <= w) break;
                                    p = w;
                                } while (--i != 0);
                                /// @solidity memory-safe-assembly
                                assembly {
                                    w := sub(w, sgt(w, 2))
                                }
                                return w;
                            }
                        }
                        do { // Otherwise, use Halley's for faster convergence.
                            int256 e = expWad(w);
                            /// @solidity memory-safe-assembly
                            assembly {
                                let t := add(w, wad)
                                let s := sub(mul(w, e), mul(x, wad))
                                w := sub(w, sdiv(mul(s, wad), sub(mul(e, t), sdiv(mul(add(t, wad), s), add(t, t)))))
                            }
                            if (p <= w) break;
                            p = w;
                        } while (--i != c);
                        /// @solidity memory-safe-assembly
                        assembly {
                            w := sub(w, sgt(w, 2))
                        }
                        // For certain ranges of `x`, we'll use the quadratic-rate recursive formula of
                        // R. Iacono and J.P. Boyd for the last iteration, to avoid catastrophic cancellation.
                        if (c != 0) {
                            int256 t = w | 1;
                            /// @solidity memory-safe-assembly
                            assembly {
                                x := sdiv(mul(x, wad), t)
                            }
                            x = (t * (wad + lnWad(x)));
                            /// @solidity memory-safe-assembly
                            assembly {
                                w := sdiv(x, add(wad, t))
                            }
                        }
                    }
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                  GENERAL NUMBER UTILITIES                  */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Calculates `floor(x * y / d)` with full precision.
                /// Throws if result overflows a uint256 or when `d` is zero.
                /// Credit to Remco Bloemen under MIT license: https://2π.com/21/muldiv
                function fullMulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 result) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        for {} 1 {} {
                            // 512-bit multiply `[p1 p0] = x * y`.
                            // Compute the product mod `2**256` and mod `2**256 - 1`
                            // then use the Chinese Remainder Theorem to reconstruct
                            // the 512 bit result. The result is stored in two 256
                            // variables such that `product = p1 * 2**256 + p0`.
                            // Least significant 256 bits of the product.
                            result := mul(x, y) // Temporarily use `result` as `p0` to save gas.
                            let mm := mulmod(x, y, not(0))
                            // Most significant 256 bits of the product.
                            let p1 := sub(mm, add(result, lt(mm, result)))
                            // Handle non-overflow cases, 256 by 256 division.
                            if iszero(p1) {
                                if iszero(d) {
                                    mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.
                                    revert(0x1c, 0x04)
                                }
                                result := div(result, d)
                                break
                            }
                            // Make sure the result is less than `2**256`. Also prevents `d == 0`.
                            if iszero(gt(d, p1)) {
                                mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.
                                revert(0x1c, 0x04)
                            }
                            /*------------------- 512 by 256 division --------------------*/
                            // Make division exact by subtracting the remainder from `[p1 p0]`.
                            // Compute remainder using mulmod.
                            let r := mulmod(x, y, d)
                            // `t` is the least significant bit of `d`.
                            // Always greater or equal to 1.
                            let t := and(d, sub(0, d))
                            // Divide `d` by `t`, which is a power of two.
                            d := div(d, t)
                            // Invert `d mod 2**256`
                            // Now that `d` is an odd number, it has an inverse
                            // modulo `2**256` such that `d * inv = 1 mod 2**256`.
                            // Compute the inverse by starting with a seed that is correct
                            // correct for four bits. That is, `d * inv = 1 mod 2**4`.
                            let inv := xor(2, mul(3, d))
                            // Now use Newton-Raphson iteration to improve the precision.
                            // Thanks to Hensel's lifting lemma, this also works in modular
                            // arithmetic, doubling the correct bits in each step.
                            inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**8
                            inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**16
                            inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**32
                            inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**64
                            inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**128
                            result :=
                                mul(
                                    // Divide [p1 p0] by the factors of two.
                                    // Shift in bits from `p1` into `p0`. For this we need
                                    // to flip `t` such that it is `2**256 / t`.
                                    or(
                                        mul(sub(p1, gt(r, result)), add(div(sub(0, t), t), 1)),
                                        div(sub(result, r), t)
                                    ),
                                    // inverse mod 2**256
                                    mul(inv, sub(2, mul(d, inv)))
                                )
                            break
                        }
                    }
                }
                /// @dev Calculates `floor(x * y / d)` with full precision, rounded up.
                /// Throws if result overflows a uint256 or when `d` is zero.
                /// Credit to Uniswap-v3-core under MIT license:
                /// https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/FullMath.sol
                function fullMulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 result) {
                    result = fullMulDiv(x, y, d);
                    /// @solidity memory-safe-assembly
                    assembly {
                        if mulmod(x, y, d) {
                            result := add(result, 1)
                            if iszero(result) {
                                mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.
                                revert(0x1c, 0x04)
                            }
                        }
                    }
                }
                /// @dev Returns `floor(x * y / d)`.
                /// Reverts if `x * y` overflows, or `d` is zero.
                function mulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        // Equivalent to require(d != 0 && (y == 0 || x <= type(uint256).max / y))
                        if iszero(mul(d, iszero(mul(y, gt(x, div(not(0), y)))))) {
                            mstore(0x00, 0xad251c27) // `MulDivFailed()`.
                            revert(0x1c, 0x04)
                        }
                        z := div(mul(x, y), d)
                    }
                }
                /// @dev Returns `ceil(x * y / d)`.
                /// Reverts if `x * y` overflows, or `d` is zero.
                function mulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        // Equivalent to require(d != 0 && (y == 0 || x <= type(uint256).max / y))
                        if iszero(mul(d, iszero(mul(y, gt(x, div(not(0), y)))))) {
                            mstore(0x00, 0xad251c27) // `MulDivFailed()`.
                            revert(0x1c, 0x04)
                        }
                        z := add(iszero(iszero(mod(mul(x, y), d))), div(mul(x, y), d))
                    }
                }
                /// @dev Returns `ceil(x / d)`.
                /// Reverts if `d` is zero.
                function divUp(uint256 x, uint256 d) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if iszero(d) {
                            mstore(0x00, 0x65244e4e) // `DivFailed()`.
                            revert(0x1c, 0x04)
                        }
                        z := add(iszero(iszero(mod(x, d))), div(x, d))
                    }
                }
                /// @dev Returns `max(0, x - y)`.
                function zeroFloorSub(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := mul(gt(x, y), sub(x, y))
                    }
                }
                /// @dev Exponentiate `x` to `y` by squaring, denominated in base `b`.
                /// Reverts if the computation overflows.
                function rpow(uint256 x, uint256 y, uint256 b) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := mul(b, iszero(y)) // `0 ** 0 = 1`. Otherwise, `0 ** n = 0`.
                        if x {
                            z := xor(b, mul(xor(b, x), and(y, 1))) // `z = isEven(y) ? scale : x`
                            let half := shr(1, b) // Divide `b` by 2.
                            // Divide `y` by 2 every iteration.
                            for { y := shr(1, y) } y { y := shr(1, y) } {
                                let xx := mul(x, x) // Store x squared.
                                let xxRound := add(xx, half) // Round to the nearest number.
                                // Revert if `xx + half` overflowed, or if `x ** 2` overflows.
                                if or(lt(xxRound, xx), shr(128, x)) {
                                    mstore(0x00, 0x49f7642b) // `RPowOverflow()`.
                                    revert(0x1c, 0x04)
                                }
                                x := div(xxRound, b) // Set `x` to scaled `xxRound`.
                                // If `y` is odd:
                                if and(y, 1) {
                                    let zx := mul(z, x) // Compute `z * x`.
                                    let zxRound := add(zx, half) // Round to the nearest number.
                                    // If `z * x` overflowed or `zx + half` overflowed:
                                    if or(xor(div(zx, x), z), lt(zxRound, zx)) {
                                        // Revert if `x` is non-zero.
                                        if iszero(iszero(x)) {
                                            mstore(0x00, 0x49f7642b) // `RPowOverflow()`.
                                            revert(0x1c, 0x04)
                                        }
                                    }
                                    z := div(zxRound, b) // Return properly scaled `zxRound`.
                                }
                            }
                        }
                    }
                }
                /// @dev Returns the square root of `x`.
                function sqrt(uint256 x) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        // `floor(sqrt(2**15)) = 181`. `sqrt(2**15) - 181 = 2.84`.
                        z := 181 // The "correct" value is 1, but this saves a multiplication later.
                        // This segment is to get a reasonable initial estimate for the Babylonian method. With a bad
                        // start, the correct # of bits increases ~linearly each iteration instead of ~quadratically.
                        // Let `y = x / 2**r`. We check `y >= 2**(k + 8)`
                        // but shift right by `k` bits to ensure that if `x >= 256`, then `y >= 256`.
                        let r := shl(7, lt(0xffffffffffffffffffffffffffffffffff, x))
                        r := or(r, shl(6, lt(0xffffffffffffffffff, shr(r, x))))
                        r := or(r, shl(5, lt(0xffffffffff, shr(r, x))))
                        r := or(r, shl(4, lt(0xffffff, shr(r, x))))
                        z := shl(shr(1, r), z)
                        // Goal was to get `z*z*y` within a small factor of `x`. More iterations could
                        // get y in a tighter range. Currently, we will have y in `[256, 256*(2**16))`.
                        // We ensured `y >= 256` so that the relative difference between `y` and `y+1` is small.
                        // That's not possible if `x < 256` but we can just verify those cases exhaustively.
                        // Now, `z*z*y <= x < z*z*(y+1)`, and `y <= 2**(16+8)`, and either `y >= 256`, or `x < 256`.
                        // Correctness can be checked exhaustively for `x < 256`, so we assume `y >= 256`.
                        // Then `z*sqrt(y)` is within `sqrt(257)/sqrt(256)` of `sqrt(x)`, or about 20bps.
                        // For `s` in the range `[1/256, 256]`, the estimate `f(s) = (181/1024) * (s+1)`
                        // is in the range `(1/2.84 * sqrt(s), 2.84 * sqrt(s))`,
                        // with largest error when `s = 1` and when `s = 256` or `1/256`.
                        // Since `y` is in `[256, 256*(2**16))`, let `a = y/65536`, so that `a` is in `[1/256, 256)`.
                        // Then we can estimate `sqrt(y)` using
                        // `sqrt(65536) * 181/1024 * (a + 1) = 181/4 * (y + 65536)/65536 = 181 * (y + 65536)/2**18`.
                        // There is no overflow risk here since `y < 2**136` after the first branch above.
                        z := shr(18, mul(z, add(shr(r, x), 65536))) // A `mul()` is saved from starting `z` at 181.
                        // Given the worst case multiplicative error of 2.84 above, 7 iterations should be enough.
                        z := shr(1, add(z, div(x, z)))
                        z := shr(1, add(z, div(x, z)))
                        z := shr(1, add(z, div(x, z)))
                        z := shr(1, add(z, div(x, z)))
                        z := shr(1, add(z, div(x, z)))
                        z := shr(1, add(z, div(x, z)))
                        z := shr(1, add(z, div(x, z)))
                        // If `x+1` is a perfect square, the Babylonian method cycles between
                        // `floor(sqrt(x))` and `ceil(sqrt(x))`. This statement ensures we return floor.
                        // See: https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division
                        z := sub(z, lt(div(x, z), z))
                    }
                }
                /// @dev Returns the cube root of `x`.
                /// Credit to bout3fiddy and pcaversaccio under AGPLv3 license:
                /// https://github.com/pcaversaccio/snekmate/blob/main/src/utils/Math.vy
                function cbrt(uint256 x) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        let r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
                        r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
                        r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
                        r := or(r, shl(4, lt(0xffff, shr(r, x))))
                        r := or(r, shl(3, lt(0xff, shr(r, x))))
                        z := div(shl(div(r, 3), shl(lt(0xf, shr(r, x)), 0xf)), xor(7, mod(r, 3)))
                        z := div(add(add(div(x, mul(z, z)), z), z), 3)
                        z := div(add(add(div(x, mul(z, z)), z), z), 3)
                        z := div(add(add(div(x, mul(z, z)), z), z), 3)
                        z := div(add(add(div(x, mul(z, z)), z), z), 3)
                        z := div(add(add(div(x, mul(z, z)), z), z), 3)
                        z := div(add(add(div(x, mul(z, z)), z), z), 3)
                        z := div(add(add(div(x, mul(z, z)), z), z), 3)
                        z := sub(z, lt(div(x, mul(z, z)), z))
                    }
                }
                /// @dev Returns the square root of `x`, denominated in `WAD`.
                function sqrtWad(uint256 x) internal pure returns (uint256 z) {
                    unchecked {
                        z = 10 ** 9;
                        if (x <= type(uint256).max / 10 ** 36 - 1) {
                            x *= 10 ** 18;
                            z = 1;
                        }
                        z *= sqrt(x);
                    }
                }
                /// @dev Returns the cube root of `x`, denominated in `WAD`.
                function cbrtWad(uint256 x) internal pure returns (uint256 z) {
                    unchecked {
                        z = 10 ** 12;
                        if (x <= (type(uint256).max / 10 ** 36) * 10 ** 18 - 1) {
                            if (x >= type(uint256).max / 10 ** 36) {
                                x *= 10 ** 18;
                                z = 10 ** 6;
                            } else {
                                x *= 10 ** 36;
                                z = 1;
                            }
                        }
                        z *= cbrt(x);
                    }
                }
                /// @dev Returns the factorial of `x`.
                function factorial(uint256 x) internal pure returns (uint256 result) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if iszero(lt(x, 58)) {
                            mstore(0x00, 0xaba0f2a2) // `FactorialOverflow()`.
                            revert(0x1c, 0x04)
                        }
                        for { result := 1 } x { x := sub(x, 1) } { result := mul(result, x) }
                    }
                }
                /// @dev Returns the log2 of `x`.
                /// Equivalent to computing the index of the most significant bit (MSB) of `x`.
                /// Returns 0 if `x` is zero.
                function log2(uint256 x) internal pure returns (uint256 r) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
                        r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
                        r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
                        r := or(r, shl(4, lt(0xffff, shr(r, x))))
                        r := or(r, shl(3, lt(0xff, shr(r, x))))
                        // forgefmt: disable-next-item
                        r := or(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),
                            0x0706060506020504060203020504030106050205030304010505030400000000))
                    }
                }
                /// @dev Returns the log2 of `x`, rounded up.
                /// Returns 0 if `x` is zero.
                function log2Up(uint256 x) internal pure returns (uint256 r) {
                    r = log2(x);
                    /// @solidity memory-safe-assembly
                    assembly {
                        r := add(r, lt(shl(r, 1), x))
                    }
                }
                /// @dev Returns the log10 of `x`.
                /// Returns 0 if `x` is zero.
                function log10(uint256 x) internal pure returns (uint256 r) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if iszero(lt(x, 100000000000000000000000000000000000000)) {
                            x := div(x, 100000000000000000000000000000000000000)
                            r := 38
                        }
                        if iszero(lt(x, 100000000000000000000)) {
                            x := div(x, 100000000000000000000)
                            r := add(r, 20)
                        }
                        if iszero(lt(x, 10000000000)) {
                            x := div(x, 10000000000)
                            r := add(r, 10)
                        }
                        if iszero(lt(x, 100000)) {
                            x := div(x, 100000)
                            r := add(r, 5)
                        }
                        r := add(r, add(gt(x, 9), add(gt(x, 99), add(gt(x, 999), gt(x, 9999)))))
                    }
                }
                /// @dev Returns the log10 of `x`, rounded up.
                /// Returns 0 if `x` is zero.
                function log10Up(uint256 x) internal pure returns (uint256 r) {
                    r = log10(x);
                    /// @solidity memory-safe-assembly
                    assembly {
                        r := add(r, lt(exp(10, r), x))
                    }
                }
                /// @dev Returns the log256 of `x`.
                /// Returns 0 if `x` is zero.
                function log256(uint256 x) internal pure returns (uint256 r) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
                        r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
                        r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
                        r := or(r, shl(4, lt(0xffff, shr(r, x))))
                        r := or(shr(3, r), lt(0xff, shr(r, x)))
                    }
                }
                /// @dev Returns the log256 of `x`, rounded up.
                /// Returns 0 if `x` is zero.
                function log256Up(uint256 x) internal pure returns (uint256 r) {
                    r = log256(x);
                    /// @solidity memory-safe-assembly
                    assembly {
                        r := add(r, lt(shl(shl(3, r), 1), x))
                    }
                }
                /// @dev Returns the scientific notation format `mantissa * 10 ** exponent` of `x`.
                /// Useful for compressing prices (e.g. using 25 bit mantissa and 7 bit exponent).
                function sci(uint256 x) internal pure returns (uint256 mantissa, uint256 exponent) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        mantissa := x
                        if mantissa {
                            if iszero(mod(mantissa, 1000000000000000000000000000000000)) {
                                mantissa := div(mantissa, 1000000000000000000000000000000000)
                                exponent := 33
                            }
                            if iszero(mod(mantissa, 10000000000000000000)) {
                                mantissa := div(mantissa, 10000000000000000000)
                                exponent := add(exponent, 19)
                            }
                            if iszero(mod(mantissa, 1000000000000)) {
                                mantissa := div(mantissa, 1000000000000)
                                exponent := add(exponent, 12)
                            }
                            if iszero(mod(mantissa, 1000000)) {
                                mantissa := div(mantissa, 1000000)
                                exponent := add(exponent, 6)
                            }
                            if iszero(mod(mantissa, 10000)) {
                                mantissa := div(mantissa, 10000)
                                exponent := add(exponent, 4)
                            }
                            if iszero(mod(mantissa, 100)) {
                                mantissa := div(mantissa, 100)
                                exponent := add(exponent, 2)
                            }
                            if iszero(mod(mantissa, 10)) {
                                mantissa := div(mantissa, 10)
                                exponent := add(exponent, 1)
                            }
                        }
                    }
                }
                /// @dev Convenience function for packing `x` into a smaller number using `sci`.
                /// The `mantissa` will be in bits [7..255] (the upper 249 bits).
                /// The `exponent` will be in bits [0..6] (the lower 7 bits).
                /// Use `SafeCastLib` to safely ensure that the `packed` number is small
                /// enough to fit in the desired unsigned integer type:
                /// ```
                ///     uint32 packed = SafeCastLib.toUint32(FixedPointMathLib.packSci(777 ether));
                /// ```
                function packSci(uint256 x) internal pure returns (uint256 packed) {
                    (x, packed) = sci(x); // Reuse for `mantissa` and `exponent`.
                    /// @solidity memory-safe-assembly
                    assembly {
                        if shr(249, x) {
                            mstore(0x00, 0xce30380c) // `MantissaOverflow()`.
                            revert(0x1c, 0x04)
                        }
                        packed := or(shl(7, x), packed)
                    }
                }
                /// @dev Convenience function for unpacking a packed number from `packSci`.
                function unpackSci(uint256 packed) internal pure returns (uint256 unpacked) {
                    unchecked {
                        unpacked = (packed >> 7) * 10 ** (packed & 0x7f);
                    }
                }
                /// @dev Returns the average of `x` and `y`.
                function avg(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    unchecked {
                        z = (x & y) + ((x ^ y) >> 1);
                    }
                }
                /// @dev Returns the average of `x` and `y`.
                function avg(int256 x, int256 y) internal pure returns (int256 z) {
                    unchecked {
                        z = (x >> 1) + (y >> 1) + (((x & 1) + (y & 1)) >> 1);
                    }
                }
                /// @dev Returns the absolute value of `x`.
                function abs(int256 x) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := xor(sub(0, shr(255, x)), add(sub(0, shr(255, x)), x))
                    }
                }
                /// @dev Returns the absolute distance between `x` and `y`.
                function dist(int256 x, int256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := xor(mul(xor(sub(y, x), sub(x, y)), sgt(x, y)), sub(y, x))
                    }
                }
                /// @dev Returns the minimum of `x` and `y`.
                function min(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := xor(x, mul(xor(x, y), lt(y, x)))
                    }
                }
                /// @dev Returns the minimum of `x` and `y`.
                function min(int256 x, int256 y) internal pure returns (int256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := xor(x, mul(xor(x, y), slt(y, x)))
                    }
                }
                /// @dev Returns the maximum of `x` and `y`.
                function max(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := xor(x, mul(xor(x, y), gt(y, x)))
                    }
                }
                /// @dev Returns the maximum of `x` and `y`.
                function max(int256 x, int256 y) internal pure returns (int256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := xor(x, mul(xor(x, y), sgt(y, x)))
                    }
                }
                /// @dev Returns `x`, bounded to `minValue` and `maxValue`.
                function clamp(uint256 x, uint256 minValue, uint256 maxValue)
                    internal
                    pure
                    returns (uint256 z)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := xor(x, mul(xor(x, minValue), gt(minValue, x)))
                        z := xor(z, mul(xor(z, maxValue), lt(maxValue, z)))
                    }
                }
                /// @dev Returns `x`, bounded to `minValue` and `maxValue`.
                function clamp(int256 x, int256 minValue, int256 maxValue) internal pure returns (int256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := xor(x, mul(xor(x, minValue), sgt(minValue, x)))
                        z := xor(z, mul(xor(z, maxValue), slt(maxValue, z)))
                    }
                }
                /// @dev Returns greatest common divisor of `x` and `y`.
                function gcd(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        for { z := x } y {} {
                            let t := y
                            y := mod(z, y)
                            z := t
                        }
                    }
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                   RAW NUMBER OPERATIONS                    */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Returns `x + y`, without checking for overflow.
                function rawAdd(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    unchecked {
                        z = x + y;
                    }
                }
                /// @dev Returns `x + y`, without checking for overflow.
                function rawAdd(int256 x, int256 y) internal pure returns (int256 z) {
                    unchecked {
                        z = x + y;
                    }
                }
                /// @dev Returns `x - y`, without checking for underflow.
                function rawSub(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    unchecked {
                        z = x - y;
                    }
                }
                /// @dev Returns `x - y`, without checking for underflow.
                function rawSub(int256 x, int256 y) internal pure returns (int256 z) {
                    unchecked {
                        z = x - y;
                    }
                }
                /// @dev Returns `x * y`, without checking for overflow.
                function rawMul(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    unchecked {
                        z = x * y;
                    }
                }
                /// @dev Returns `x * y`, without checking for overflow.
                function rawMul(int256 x, int256 y) internal pure returns (int256 z) {
                    unchecked {
                        z = x * y;
                    }
                }
                /// @dev Returns `x / y`, returning 0 if `y` is zero.
                function rawDiv(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := div(x, y)
                    }
                }
                /// @dev Returns `x / y`, returning 0 if `y` is zero.
                function rawSDiv(int256 x, int256 y) internal pure returns (int256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := sdiv(x, y)
                    }
                }
                /// @dev Returns `x % y`, returning 0 if `y` is zero.
                function rawMod(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := mod(x, y)
                    }
                }
                /// @dev Returns `x % y`, returning 0 if `y` is zero.
                function rawSMod(int256 x, int256 y) internal pure returns (int256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := smod(x, y)
                    }
                }
                /// @dev Returns `(x + y) % d`, return 0 if `d` if zero.
                function rawAddMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := addmod(x, y, d)
                    }
                }
                /// @dev Returns `(x * y) % d`, return 0 if `d` if zero.
                function rawMulMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := mulmod(x, y, d)
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.4;
            /// @notice Reentrancy guard mixin.
            /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/ReentrancyGuard.sol)
            abstract contract ReentrancyGuard {
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                       CUSTOM ERRORS                        */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Unauthorized reentrant call.
                error Reentrancy();
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                          STORAGE                           */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Equivalent to: `uint72(bytes9(keccak256("_REENTRANCY_GUARD_SLOT")))`.
                /// 9 bytes is large enough to avoid collisions with lower slots,
                /// but not too large to result in excessive bytecode bloat.
                uint256 private constant _REENTRANCY_GUARD_SLOT = 0x929eee149b4bd21268;
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                      REENTRANCY GUARD                      */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Guards a function from reentrancy.
                modifier nonReentrant() virtual {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if eq(sload(_REENTRANCY_GUARD_SLOT), address()) {
                            mstore(0x00, 0xab143c06) // `Reentrancy()`.
                            revert(0x1c, 0x04)
                        }
                        sstore(_REENTRANCY_GUARD_SLOT, address())
                    }
                    _;
                    /// @solidity memory-safe-assembly
                    assembly {
                        sstore(_REENTRANCY_GUARD_SLOT, codesize())
                    }
                }
                /// @dev Guards a view function from read-only reentrancy.
                modifier nonReadReentrant() virtual {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if eq(sload(_REENTRANCY_GUARD_SLOT), address()) {
                            mstore(0x00, 0xab143c06) // `Reentrancy()`.
                            revert(0x1c, 0x04)
                        }
                    }
                    _;
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.4;
            /// @notice Class with helper read functions for clone with immutable args.
            /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/Clone.sol)
            /// @author Adapted from clones with immutable args by zefram.eth, Saw-mon & Natalie
            /// (https://github.com/Saw-mon-and-Natalie/clones-with-immutable-args)
            abstract contract Clone {
                /// @dev Reads all of the immutable args.
                function _getArgBytes() internal pure returns (bytes memory arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := mload(0x40)
                        let length := sub(calldatasize(), add(2, offset)) // 2 bytes are used for the length.
                        mstore(arg, length) // Store the length.
                        calldatacopy(add(arg, 0x20), offset, length)
                        let o := add(add(arg, 0x20), length)
                        mstore(o, 0) // Zeroize the slot after the bytes.
                        mstore(0x40, add(o, 0x20)) // Allocate the memory.
                    }
                }
                /// @dev Reads an immutable arg with type bytes.
                function _getArgBytes(uint256 argOffset, uint256 length)
                    internal
                    pure
                    returns (bytes memory arg)
                {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := mload(0x40)
                        mstore(arg, length) // Store the length.
                        calldatacopy(add(arg, 0x20), add(offset, argOffset), length)
                        let o := add(add(arg, 0x20), length)
                        mstore(o, 0) // Zeroize the slot after the bytes.
                        mstore(0x40, add(o, 0x20)) // Allocate the memory.
                    }
                }
                /// @dev Reads an immutable arg with type address.
                function _getArgAddress(uint256 argOffset) internal pure returns (address arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(96, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads a uint256 array stored in the immutable args.
                function _getArgUint256Array(uint256 argOffset, uint256 length)
                    internal
                    pure
                    returns (uint256[] memory arg)
                {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := mload(0x40)
                        mstore(arg, length) // Store the length.
                        calldatacopy(add(arg, 0x20), add(offset, argOffset), shl(5, length))
                        mstore(0x40, add(add(arg, 0x20), shl(5, length))) // Allocate the memory.
                    }
                }
                /// @dev Reads a bytes32 array stored in the immutable args.
                function _getArgBytes32Array(uint256 argOffset, uint256 length)
                    internal
                    pure
                    returns (bytes32[] memory arg)
                {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := mload(0x40)
                        mstore(arg, length) // Store the length.
                        calldatacopy(add(arg, 0x20), add(offset, argOffset), shl(5, length))
                        mstore(0x40, add(add(arg, 0x20), shl(5, length))) // Allocate the memory.
                    }
                }
                /// @dev Reads an immutable arg with type bytes32.
                function _getArgBytes32(uint256 argOffset) internal pure returns (bytes32 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := calldataload(add(offset, argOffset))
                    }
                }
                /// @dev Reads an immutable arg with type uint256.
                function _getArgUint256(uint256 argOffset) internal pure returns (uint256 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := calldataload(add(offset, argOffset))
                    }
                }
                /// @dev Reads an immutable arg with type uint248.
                function _getArgUint248(uint256 argOffset) internal pure returns (uint248 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(8, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint240.
                function _getArgUint240(uint256 argOffset) internal pure returns (uint240 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(16, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint232.
                function _getArgUint232(uint256 argOffset) internal pure returns (uint232 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(24, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint224.
                function _getArgUint224(uint256 argOffset) internal pure returns (uint224 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(0x20, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint216.
                function _getArgUint216(uint256 argOffset) internal pure returns (uint216 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(40, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint208.
                function _getArgUint208(uint256 argOffset) internal pure returns (uint208 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(48, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint200.
                function _getArgUint200(uint256 argOffset) internal pure returns (uint200 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(56, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint192.
                function _getArgUint192(uint256 argOffset) internal pure returns (uint192 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(64, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint184.
                function _getArgUint184(uint256 argOffset) internal pure returns (uint184 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(72, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint176.
                function _getArgUint176(uint256 argOffset) internal pure returns (uint176 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(80, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint168.
                function _getArgUint168(uint256 argOffset) internal pure returns (uint168 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(88, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint160.
                function _getArgUint160(uint256 argOffset) internal pure returns (uint160 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(96, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint152.
                function _getArgUint152(uint256 argOffset) internal pure returns (uint152 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(104, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint144.
                function _getArgUint144(uint256 argOffset) internal pure returns (uint144 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(112, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint136.
                function _getArgUint136(uint256 argOffset) internal pure returns (uint136 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(120, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint128.
                function _getArgUint128(uint256 argOffset) internal pure returns (uint128 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(128, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint120.
                function _getArgUint120(uint256 argOffset) internal pure returns (uint120 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(136, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint112.
                function _getArgUint112(uint256 argOffset) internal pure returns (uint112 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(144, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint104.
                function _getArgUint104(uint256 argOffset) internal pure returns (uint104 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(152, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint96.
                function _getArgUint96(uint256 argOffset) internal pure returns (uint96 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(160, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint88.
                function _getArgUint88(uint256 argOffset) internal pure returns (uint88 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(168, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint80.
                function _getArgUint80(uint256 argOffset) internal pure returns (uint80 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(176, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint72.
                function _getArgUint72(uint256 argOffset) internal pure returns (uint72 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(184, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint64.
                function _getArgUint64(uint256 argOffset) internal pure returns (uint64 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(192, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint56.
                function _getArgUint56(uint256 argOffset) internal pure returns (uint56 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(200, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint48.
                function _getArgUint48(uint256 argOffset) internal pure returns (uint48 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(208, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint40.
                function _getArgUint40(uint256 argOffset) internal pure returns (uint40 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(216, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint32.
                function _getArgUint32(uint256 argOffset) internal pure returns (uint32 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(224, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint24.
                function _getArgUint24(uint256 argOffset) internal pure returns (uint24 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(232, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint16.
                function _getArgUint16(uint256 argOffset) internal pure returns (uint16 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(240, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint8.
                function _getArgUint8(uint256 argOffset) internal pure returns (uint8 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(248, calldataload(add(offset, argOffset)))
                    }
                }
                /// @return offset The offset of the packed immutable args in calldata.
                function _getImmutableArgsOffset() internal pure returns (uint256 offset) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        offset := sub(calldatasize(), shr(240, calldataload(sub(calldatasize(), 2))))
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.4;
            /// @notice Gas optimized verification of proof of inclusion for a leaf in a Merkle tree.
            /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/MerkleProofLib.sol)
            /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/MerkleProofLib.sol)
            /// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/MerkleProof.sol)
            library MerkleProofLib {
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*            MERKLE PROOF VERIFICATION OPERATIONS            */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Returns whether `leaf` exists in the Merkle tree with `root`, given `proof`.
                function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf)
                    internal
                    pure
                    returns (bool isValid)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if mload(proof) {
                            // Initialize `offset` to the offset of `proof` elements in memory.
                            let offset := add(proof, 0x20)
                            // Left shift by 5 is equivalent to multiplying by 0x20.
                            let end := add(offset, shl(5, mload(proof)))
                            // Iterate over proof elements to compute root hash.
                            for {} 1 {} {
                                // Slot of `leaf` in scratch space.
                                // If the condition is true: 0x20, otherwise: 0x00.
                                let scratch := shl(5, gt(leaf, mload(offset)))
                                // Store elements to hash contiguously in scratch space.
                                // Scratch space is 64 bytes (0x00 - 0x3f) and both elements are 32 bytes.
                                mstore(scratch, leaf)
                                mstore(xor(scratch, 0x20), mload(offset))
                                // Reuse `leaf` to store the hash to reduce stack operations.
                                leaf := keccak256(0x00, 0x40)
                                offset := add(offset, 0x20)
                                if iszero(lt(offset, end)) { break }
                            }
                        }
                        isValid := eq(leaf, root)
                    }
                }
                /// @dev Returns whether `leaf` exists in the Merkle tree with `root`, given `proof`.
                function verifyCalldata(bytes32[] calldata proof, bytes32 root, bytes32 leaf)
                    internal
                    pure
                    returns (bool isValid)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if proof.length {
                            // Left shift by 5 is equivalent to multiplying by 0x20.
                            let end := add(proof.offset, shl(5, proof.length))
                            // Initialize `offset` to the offset of `proof` in the calldata.
                            let offset := proof.offset
                            // Iterate over proof elements to compute root hash.
                            for {} 1 {} {
                                // Slot of `leaf` in scratch space.
                                // If the condition is true: 0x20, otherwise: 0x00.
                                let scratch := shl(5, gt(leaf, calldataload(offset)))
                                // Store elements to hash contiguously in scratch space.
                                // Scratch space is 64 bytes (0x00 - 0x3f) and both elements are 32 bytes.
                                mstore(scratch, leaf)
                                mstore(xor(scratch, 0x20), calldataload(offset))
                                // Reuse `leaf` to store the hash to reduce stack operations.
                                leaf := keccak256(0x00, 0x40)
                                offset := add(offset, 0x20)
                                if iszero(lt(offset, end)) { break }
                            }
                        }
                        isValid := eq(leaf, root)
                    }
                }
                /// @dev Returns whether all `leaves` exist in the Merkle tree with `root`,
                /// given `proof` and `flags`.
                ///
                /// Note:
                /// - Breaking the invariant `flags.length == (leaves.length - 1) + proof.length`
                ///   will always return false.
                /// - The sum of the lengths of `proof` and `leaves` must never overflow.
                /// - Any non-zero word in the `flags` array is treated as true.
                /// - The memory offset of `proof` must be non-zero
                ///   (i.e. `proof` is not pointing to the scratch space).
                function verifyMultiProof(
                    bytes32[] memory proof,
                    bytes32 root,
                    bytes32[] memory leaves,
                    bool[] memory flags
                ) internal pure returns (bool isValid) {
                    // Rebuilds the root by consuming and producing values on a queue.
                    // The queue starts with the `leaves` array, and goes into a `hashes` array.
                    // After the process, the last element on the queue is verified
                    // to be equal to the `root`.
                    //
                    // The `flags` array denotes whether the sibling
                    // should be popped from the queue (`flag == true`), or
                    // should be popped from the `proof` (`flag == false`).
                    /// @solidity memory-safe-assembly
                    assembly {
                        // Cache the lengths of the arrays.
                        let leavesLength := mload(leaves)
                        let proofLength := mload(proof)
                        let flagsLength := mload(flags)
                        // Advance the pointers of the arrays to point to the data.
                        leaves := add(0x20, leaves)
                        proof := add(0x20, proof)
                        flags := add(0x20, flags)
                        // If the number of flags is correct.
                        for {} eq(add(leavesLength, proofLength), add(flagsLength, 1)) {} {
                            // For the case where `proof.length + leaves.length == 1`.
                            if iszero(flagsLength) {
                                // `isValid = (proof.length == 1 ? proof[0] : leaves[0]) == root`.
                                isValid := eq(mload(xor(leaves, mul(xor(proof, leaves), proofLength))), root)
                                break
                            }
                            // The required final proof offset if `flagsLength` is not zero, otherwise zero.
                            let proofEnd := add(proof, shl(5, proofLength))
                            // We can use the free memory space for the queue.
                            // We don't need to allocate, since the queue is temporary.
                            let hashesFront := mload(0x40)
                            // Copy the leaves into the hashes.
                            // Sometimes, a little memory expansion costs less than branching.
                            // Should cost less, even with a high free memory offset of 0x7d00.
                            leavesLength := shl(5, leavesLength)
                            for { let i := 0 } iszero(eq(i, leavesLength)) { i := add(i, 0x20) } {
                                mstore(add(hashesFront, i), mload(add(leaves, i)))
                            }
                            // Compute the back of the hashes.
                            let hashesBack := add(hashesFront, leavesLength)
                            // This is the end of the memory for the queue.
                            // We recycle `flagsLength` to save on stack variables (sometimes save gas).
                            flagsLength := add(hashesBack, shl(5, flagsLength))
                            for {} 1 {} {
                                // Pop from `hashes`.
                                let a := mload(hashesFront)
                                // Pop from `hashes`.
                                let b := mload(add(hashesFront, 0x20))
                                hashesFront := add(hashesFront, 0x40)
                                // If the flag is false, load the next proof,
                                // else, pops from the queue.
                                if iszero(mload(flags)) {
                                    // Loads the next proof.
                                    b := mload(proof)
                                    proof := add(proof, 0x20)
                                    // Unpop from `hashes`.
                                    hashesFront := sub(hashesFront, 0x20)
                                }
                                // Advance to the next flag.
                                flags := add(flags, 0x20)
                                // Slot of `a` in scratch space.
                                // If the condition is true: 0x20, otherwise: 0x00.
                                let scratch := shl(5, gt(a, b))
                                // Hash the scratch space and push the result onto the queue.
                                mstore(scratch, a)
                                mstore(xor(scratch, 0x20), b)
                                mstore(hashesBack, keccak256(0x00, 0x40))
                                hashesBack := add(hashesBack, 0x20)
                                if iszero(lt(hashesBack, flagsLength)) { break }
                            }
                            isValid :=
                                and(
                                    // Checks if the last value in the queue is same as the root.
                                    eq(mload(sub(hashesBack, 0x20)), root),
                                    // And whether all the proofs are used, if required.
                                    eq(proofEnd, proof)
                                )
                            break
                        }
                    }
                }
                /// @dev Returns whether all `leaves` exist in the Merkle tree with `root`,
                /// given `proof` and `flags`.
                ///
                /// Note:
                /// - Breaking the invariant `flags.length == (leaves.length - 1) + proof.length`
                ///   will always return false.
                /// - Any non-zero word in the `flags` array is treated as true.
                /// - The calldata offset of `proof` must be non-zero
                ///   (i.e. `proof` is from a regular Solidity function with a 4-byte selector).
                function verifyMultiProofCalldata(
                    bytes32[] calldata proof,
                    bytes32 root,
                    bytes32[] calldata leaves,
                    bool[] calldata flags
                ) internal pure returns (bool isValid) {
                    // Rebuilds the root by consuming and producing values on a queue.
                    // The queue starts with the `leaves` array, and goes into a `hashes` array.
                    // After the process, the last element on the queue is verified
                    // to be equal to the `root`.
                    //
                    // The `flags` array denotes whether the sibling
                    // should be popped from the queue (`flag == true`), or
                    // should be popped from the `proof` (`flag == false`).
                    /// @solidity memory-safe-assembly
                    assembly {
                        // If the number of flags is correct.
                        for {} eq(add(leaves.length, proof.length), add(flags.length, 1)) {} {
                            // For the case where `proof.length + leaves.length == 1`.
                            if iszero(flags.length) {
                                // `isValid = (proof.length == 1 ? proof[0] : leaves[0]) == root`.
                                // forgefmt: disable-next-item
                                isValid := eq(
                                    calldataload(
                                        xor(leaves.offset, mul(xor(proof.offset, leaves.offset), proof.length))
                                    ),
                                    root
                                )
                                break
                            }
                            // The required final proof offset if `flagsLength` is not zero, otherwise zero.
                            let proofEnd := add(proof.offset, shl(5, proof.length))
                            // We can use the free memory space for the queue.
                            // We don't need to allocate, since the queue is temporary.
                            let hashesFront := mload(0x40)
                            // Copy the leaves into the hashes.
                            // Sometimes, a little memory expansion costs less than branching.
                            // Should cost less, even with a high free memory offset of 0x7d00.
                            calldatacopy(hashesFront, leaves.offset, shl(5, leaves.length))
                            // Compute the back of the hashes.
                            let hashesBack := add(hashesFront, shl(5, leaves.length))
                            // This is the end of the memory for the queue.
                            // We recycle `flagsLength` to save on stack variables (sometimes save gas).
                            flags.length := add(hashesBack, shl(5, flags.length))
                            // We don't need to make a copy of `proof.offset` or `flags.offset`,
                            // as they are pass-by-value (this trick may not always save gas).
                            for {} 1 {} {
                                // Pop from `hashes`.
                                let a := mload(hashesFront)
                                // Pop from `hashes`.
                                let b := mload(add(hashesFront, 0x20))
                                hashesFront := add(hashesFront, 0x40)
                                // If the flag is false, load the next proof,
                                // else, pops from the queue.
                                if iszero(calldataload(flags.offset)) {
                                    // Loads the next proof.
                                    b := calldataload(proof.offset)
                                    proof.offset := add(proof.offset, 0x20)
                                    // Unpop from `hashes`.
                                    hashesFront := sub(hashesFront, 0x20)
                                }
                                // Advance to the next flag offset.
                                flags.offset := add(flags.offset, 0x20)
                                // Slot of `a` in scratch space.
                                // If the condition is true: 0x20, otherwise: 0x00.
                                let scratch := shl(5, gt(a, b))
                                // Hash the scratch space and push the result onto the queue.
                                mstore(scratch, a)
                                mstore(xor(scratch, 0x20), b)
                                mstore(hashesBack, keccak256(0x00, 0x40))
                                hashesBack := add(hashesBack, 0x20)
                                if iszero(lt(hashesBack, flags.length)) { break }
                            }
                            isValid :=
                                and(
                                    // Checks if the last value in the queue is same as the root.
                                    eq(mload(sub(hashesBack, 0x20)), root),
                                    // And whether all the proofs are used, if required.
                                    eq(proofEnd, proof.offset)
                                )
                            break
                        }
                    }
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                   EMPTY CALLDATA HELPERS                   */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Returns an empty calldata bytes32 array.
                function emptyProof() internal pure returns (bytes32[] calldata proof) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        proof.length := 0
                    }
                }
                /// @dev Returns an empty calldata bytes32 array.
                function emptyLeaves() internal pure returns (bytes32[] calldata leaves) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        leaves.length := 0
                    }
                }
                /// @dev Returns an empty calldata bool array.
                function emptyFlags() internal pure returns (bool[] calldata flags) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        flags.length := 0
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.4;
            /// @notice Contract for EIP-712 typed structured data hashing and signing.
            /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/EIP712.sol)
            /// @author Modified from Solbase (https://github.com/Sol-DAO/solbase/blob/main/src/utils/EIP712.sol)
            /// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/EIP712.sol)
            ///
            /// @dev Note, this implementation:
            /// - Uses `address(this)` for the `verifyingContract` field.
            /// - Does NOT use the optional EIP-712 salt.
            /// - Does NOT use any EIP-712 extensions.
            /// This is for simplicity and to save gas.
            /// If you need to customize, please fork / modify accordingly.
            abstract contract EIP712 {
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                  CONSTANTS AND IMMUTABLES                  */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev `keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")`.
                bytes32 internal constant _DOMAIN_TYPEHASH =
                    0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f;
                uint256 private immutable _cachedThis;
                uint256 private immutable _cachedChainId;
                bytes32 private immutable _cachedNameHash;
                bytes32 private immutable _cachedVersionHash;
                bytes32 private immutable _cachedDomainSeparator;
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                        CONSTRUCTOR                         */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Cache the hashes for cheaper runtime gas costs.
                /// In the case of upgradeable contracts (i.e. proxies),
                /// or if the chain id changes due to a hard fork,
                /// the domain separator will be seamlessly calculated on-the-fly.
                constructor() {
                    _cachedThis = uint256(uint160(address(this)));
                    _cachedChainId = block.chainid;
                    string memory name;
                    string memory version;
                    if (!_domainNameAndVersionMayChange()) (name, version) = _domainNameAndVersion();
                    bytes32 nameHash = _domainNameAndVersionMayChange() ? bytes32(0) : keccak256(bytes(name));
                    bytes32 versionHash =
                        _domainNameAndVersionMayChange() ? bytes32(0) : keccak256(bytes(version));
                    _cachedNameHash = nameHash;
                    _cachedVersionHash = versionHash;
                    bytes32 separator;
                    if (!_domainNameAndVersionMayChange()) {
                        /// @solidity memory-safe-assembly
                        assembly {
                            let m := mload(0x40) // Load the free memory pointer.
                            mstore(m, _DOMAIN_TYPEHASH)
                            mstore(add(m, 0x20), nameHash)
                            mstore(add(m, 0x40), versionHash)
                            mstore(add(m, 0x60), chainid())
                            mstore(add(m, 0x80), address())
                            separator := keccak256(m, 0xa0)
                        }
                    }
                    _cachedDomainSeparator = separator;
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                   FUNCTIONS TO OVERRIDE                    */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Please override this function to return the domain name and version.
                /// ```
                ///     function _domainNameAndVersion()
                ///         internal
                ///         pure
                ///         virtual
                ///         returns (string memory name, string memory version)
                ///     {
                ///         name = "Solady";
                ///         version = "1";
                ///     }
                /// ```
                ///
                /// Note: If the returned result may change after the contract has been deployed,
                /// you must override `_domainNameAndVersionMayChange()` to return true.
                function _domainNameAndVersion()
                    internal
                    view
                    virtual
                    returns (string memory name, string memory version);
                /// @dev Returns if `_domainNameAndVersion()` may change
                /// after the contract has been deployed (i.e. after the constructor).
                /// Default: false.
                function _domainNameAndVersionMayChange() internal pure virtual returns (bool result) {}
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                     HASHING OPERATIONS                     */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Returns the EIP-712 domain separator.
                function _domainSeparator() internal view virtual returns (bytes32 separator) {
                    if (_domainNameAndVersionMayChange()) {
                        separator = _buildDomainSeparator();
                    } else {
                        separator = _cachedDomainSeparator;
                        if (_cachedDomainSeparatorInvalidated()) separator = _buildDomainSeparator();
                    }
                }
                /// @dev Returns the hash of the fully encoded EIP-712 message for this domain,
                /// given `structHash`, as defined in
                /// https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct.
                ///
                /// The hash can be used together with {ECDSA-recover} to obtain the signer of a message:
                /// ```
                ///     bytes32 digest = _hashTypedData(keccak256(abi.encode(
                ///         keccak256("Mail(address to,string contents)"),
                ///         mailTo,
                ///         keccak256(bytes(mailContents))
                ///     )));
                ///     address signer = ECDSA.recover(digest, signature);
                /// ```
                function _hashTypedData(bytes32 structHash) internal view virtual returns (bytes32 digest) {
                    // We will use `digest` to store the domain separator to save a bit of gas.
                    if (_domainNameAndVersionMayChange()) {
                        digest = _buildDomainSeparator();
                    } else {
                        digest = _cachedDomainSeparator;
                        if (_cachedDomainSeparatorInvalidated()) digest = _buildDomainSeparator();
                    }
                    /// @solidity memory-safe-assembly
                    assembly {
                        // Compute the digest.
                        mstore(0x00, 0x1901000000000000) // Store "\\x19\\x01".
                        mstore(0x1a, digest) // Store the domain separator.
                        mstore(0x3a, structHash) // Store the struct hash.
                        digest := keccak256(0x18, 0x42)
                        // Restore the part of the free memory slot that was overwritten.
                        mstore(0x3a, 0)
                    }
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                    EIP-5267 OPERATIONS                     */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev See: https://eips.ethereum.org/EIPS/eip-5267
                function eip712Domain()
                    public
                    view
                    virtual
                    returns (
                        bytes1 fields,
                        string memory name,
                        string memory version,
                        uint256 chainId,
                        address verifyingContract,
                        bytes32 salt,
                        uint256[] memory extensions
                    )
                {
                    fields = hex"0f"; // `0b01111`.
                    (name, version) = _domainNameAndVersion();
                    chainId = block.chainid;
                    verifyingContract = address(this);
                    salt = salt; // `bytes32(0)`.
                    extensions = extensions; // `new uint256[](0)`.
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                      PRIVATE HELPERS                       */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Returns the EIP-712 domain separator.
                function _buildDomainSeparator() private view returns (bytes32 separator) {
                    // We will use `separator` to store the name hash to save a bit of gas.
                    bytes32 versionHash;
                    if (_domainNameAndVersionMayChange()) {
                        (string memory name, string memory version) = _domainNameAndVersion();
                        separator = keccak256(bytes(name));
                        versionHash = keccak256(bytes(version));
                    } else {
                        separator = _cachedNameHash;
                        versionHash = _cachedVersionHash;
                    }
                    /// @solidity memory-safe-assembly
                    assembly {
                        let m := mload(0x40) // Load the free memory pointer.
                        mstore(m, _DOMAIN_TYPEHASH)
                        mstore(add(m, 0x20), separator) // Name hash.
                        mstore(add(m, 0x40), versionHash)
                        mstore(add(m, 0x60), chainid())
                        mstore(add(m, 0x80), address())
                        separator := keccak256(m, 0xa0)
                    }
                }
                /// @dev Returns if the cached domain separator has been invalidated.
                function _cachedDomainSeparatorInvalidated() private view returns (bool result) {
                    uint256 cachedChainId = _cachedChainId;
                    uint256 cachedThis = _cachedThis;
                    /// @solidity memory-safe-assembly
                    assembly {
                        result := iszero(and(eq(chainid(), cachedChainId), eq(address(), cachedThis)))
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.4;
            /// @notice Gas optimized ECDSA wrapper.
            /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/ECDSA.sol)
            /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/ECDSA.sol)
            /// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/ECDSA.sol)
            ///
            /// @dev Note:
            /// - The recovery functions use the ecrecover precompile (0x1).
            /// - As of Solady version 0.0.68, the `recover` variants will revert upon recovery failure.
            ///   This is for more safety by default.
            ///   Use the `tryRecover` variants if you need to get the zero address back
            ///   upon recovery failure instead.
            /// - As of Solady version 0.0.134, all `bytes signature` variants accept both
            ///   regular 65-byte `(r, s, v)` and EIP-2098 `(r, vs)` short form signatures.
            ///   See: https://eips.ethereum.org/EIPS/eip-2098
            ///   This is for calldata efficiency on smart accounts prevalent on L2s.
            ///
            /// WARNING! Do NOT use signatures as unique identifiers:
            /// - Use a nonce in the digest to prevent replay attacks on the same contract.
            /// - Use EIP-712 for the digest to prevent replay attacks across different chains and contracts.
            ///   EIP-712 also enables readable signing of typed data for better user safety.
            /// This implementation does NOT check if a signature is non-malleable.
            library ECDSA {
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                        CUSTOM ERRORS                       */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev The signature is invalid.
                error InvalidSignature();
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                    RECOVERY OPERATIONS                     */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Recovers the signer's address from a message digest `hash`, and the `signature`.
                function recover(bytes32 hash, bytes memory signature) internal view returns (address result) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        result := 1
                        let m := mload(0x40) // Cache the free memory pointer.
                        for {} 1 {} {
                            mstore(0x00, hash)
                            mstore(0x40, mload(add(signature, 0x20))) // `r`.
                            if eq(mload(signature), 64) {
                                let vs := mload(add(signature, 0x40))
                                mstore(0x20, add(shr(255, vs), 27)) // `v`.
                                mstore(0x60, shr(1, shl(1, vs))) // `s`.
                                break
                            }
                            if eq(mload(signature), 65) {
                                mstore(0x20, byte(0, mload(add(signature, 0x60)))) // `v`.
                                mstore(0x60, mload(add(signature, 0x40))) // `s`.
                                break
                            }
                            result := 0
                            break
                        }
                        result :=
                            mload(
                                staticcall(
                                    gas(), // Amount of gas left for the transaction.
                                    result, // Address of `ecrecover`.
                                    0x00, // Start of input.
                                    0x80, // Size of input.
                                    0x01, // Start of output.
                                    0x20 // Size of output.
                                )
                            )
                        // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
                        if iszero(returndatasize()) {
                            mstore(0x00, 0x8baa579f) // `InvalidSignature()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x60, 0) // Restore the zero slot.
                        mstore(0x40, m) // Restore the free memory pointer.
                    }
                }
                /// @dev Recovers the signer's address from a message digest `hash`, and the `signature`.
                function recoverCalldata(bytes32 hash, bytes calldata signature)
                    internal
                    view
                    returns (address result)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        result := 1
                        let m := mload(0x40) // Cache the free memory pointer.
                        mstore(0x00, hash)
                        for {} 1 {} {
                            if eq(signature.length, 64) {
                                let vs := calldataload(add(signature.offset, 0x20))
                                mstore(0x20, add(shr(255, vs), 27)) // `v`.
                                mstore(0x40, calldataload(signature.offset)) // `r`.
                                mstore(0x60, shr(1, shl(1, vs))) // `s`.
                                break
                            }
                            if eq(signature.length, 65) {
                                mstore(0x20, byte(0, calldataload(add(signature.offset, 0x40)))) // `v`.
                                calldatacopy(0x40, signature.offset, 0x40) // Copy `r` and `s`.
                                break
                            }
                            result := 0
                            break
                        }
                        result :=
                            mload(
                                staticcall(
                                    gas(), // Amount of gas left for the transaction.
                                    result, // Address of `ecrecover`.
                                    0x00, // Start of input.
                                    0x80, // Size of input.
                                    0x01, // Start of output.
                                    0x20 // Size of output.
                                )
                            )
                        // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
                        if iszero(returndatasize()) {
                            mstore(0x00, 0x8baa579f) // `InvalidSignature()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x60, 0) // Restore the zero slot.
                        mstore(0x40, m) // Restore the free memory pointer.
                    }
                }
                /// @dev Recovers the signer's address from a message digest `hash`,
                /// and the EIP-2098 short form signature defined by `r` and `vs`.
                function recover(bytes32 hash, bytes32 r, bytes32 vs) internal view returns (address result) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        let m := mload(0x40) // Cache the free memory pointer.
                        mstore(0x00, hash)
                        mstore(0x20, add(shr(255, vs), 27)) // `v`.
                        mstore(0x40, r)
                        mstore(0x60, shr(1, shl(1, vs))) // `s`.
                        result :=
                            mload(
                                staticcall(
                                    gas(), // Amount of gas left for the transaction.
                                    1, // Address of `ecrecover`.
                                    0x00, // Start of input.
                                    0x80, // Size of input.
                                    0x01, // Start of output.
                                    0x20 // Size of output.
                                )
                            )
                        // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
                        if iszero(returndatasize()) {
                            mstore(0x00, 0x8baa579f) // `InvalidSignature()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x60, 0) // Restore the zero slot.
                        mstore(0x40, m) // Restore the free memory pointer.
                    }
                }
                /// @dev Recovers the signer's address from a message digest `hash`,
                /// and the signature defined by `v`, `r`, `s`.
                function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s)
                    internal
                    view
                    returns (address result)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        let m := mload(0x40) // Cache the free memory pointer.
                        mstore(0x00, hash)
                        mstore(0x20, and(v, 0xff))
                        mstore(0x40, r)
                        mstore(0x60, s)
                        result :=
                            mload(
                                staticcall(
                                    gas(), // Amount of gas left for the transaction.
                                    1, // Address of `ecrecover`.
                                    0x00, // Start of input.
                                    0x80, // Size of input.
                                    0x01, // Start of output.
                                    0x20 // Size of output.
                                )
                            )
                        // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
                        if iszero(returndatasize()) {
                            mstore(0x00, 0x8baa579f) // `InvalidSignature()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x60, 0) // Restore the zero slot.
                        mstore(0x40, m) // Restore the free memory pointer.
                    }
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                   TRY-RECOVER OPERATIONS                   */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                // WARNING!
                // These functions will NOT revert upon recovery failure.
                // Instead, they will return the zero address upon recovery failure.
                // It is critical that the returned address is NEVER compared against
                // a zero address (e.g. an uninitialized address variable).
                /// @dev Recovers the signer's address from a message digest `hash`, and the `signature`.
                function tryRecover(bytes32 hash, bytes memory signature)
                    internal
                    view
                    returns (address result)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        result := 1
                        let m := mload(0x40) // Cache the free memory pointer.
                        for {} 1 {} {
                            mstore(0x00, hash)
                            mstore(0x40, mload(add(signature, 0x20))) // `r`.
                            if eq(mload(signature), 64) {
                                let vs := mload(add(signature, 0x40))
                                mstore(0x20, add(shr(255, vs), 27)) // `v`.
                                mstore(0x60, shr(1, shl(1, vs))) // `s`.
                                break
                            }
                            if eq(mload(signature), 65) {
                                mstore(0x20, byte(0, mload(add(signature, 0x60)))) // `v`.
                                mstore(0x60, mload(add(signature, 0x40))) // `s`.
                                break
                            }
                            result := 0
                            break
                        }
                        pop(
                            staticcall(
                                gas(), // Amount of gas left for the transaction.
                                result, // Address of `ecrecover`.
                                0x00, // Start of input.
                                0x80, // Size of input.
                                0x40, // Start of output.
                                0x20 // Size of output.
                            )
                        )
                        mstore(0x60, 0) // Restore the zero slot.
                        // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
                        result := mload(xor(0x60, returndatasize()))
                        mstore(0x40, m) // Restore the free memory pointer.
                    }
                }
                /// @dev Recovers the signer's address from a message digest `hash`, and the `signature`.
                function tryRecoverCalldata(bytes32 hash, bytes calldata signature)
                    internal
                    view
                    returns (address result)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        result := 1
                        let m := mload(0x40) // Cache the free memory pointer.
                        mstore(0x00, hash)
                        for {} 1 {} {
                            if eq(signature.length, 64) {
                                let vs := calldataload(add(signature.offset, 0x20))
                                mstore(0x20, add(shr(255, vs), 27)) // `v`.
                                mstore(0x40, calldataload(signature.offset)) // `r`.
                                mstore(0x60, shr(1, shl(1, vs))) // `s`.
                                break
                            }
                            if eq(signature.length, 65) {
                                mstore(0x20, byte(0, calldataload(add(signature.offset, 0x40)))) // `v`.
                                calldatacopy(0x40, signature.offset, 0x40) // Copy `r` and `s`.
                                break
                            }
                            result := 0
                            break
                        }
                        pop(
                            staticcall(
                                gas(), // Amount of gas left for the transaction.
                                result, // Address of `ecrecover`.
                                0x00, // Start of input.
                                0x80, // Size of input.
                                0x40, // Start of output.
                                0x20 // Size of output.
                            )
                        )
                        mstore(0x60, 0) // Restore the zero slot.
                        // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
                        result := mload(xor(0x60, returndatasize()))
                        mstore(0x40, m) // Restore the free memory pointer.
                    }
                }
                /// @dev Recovers the signer's address from a message digest `hash`,
                /// and the EIP-2098 short form signature defined by `r` and `vs`.
                function tryRecover(bytes32 hash, bytes32 r, bytes32 vs)
                    internal
                    view
                    returns (address result)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        let m := mload(0x40) // Cache the free memory pointer.
                        mstore(0x00, hash)
                        mstore(0x20, add(shr(255, vs), 27)) // `v`.
                        mstore(0x40, r)
                        mstore(0x60, shr(1, shl(1, vs))) // `s`.
                        pop(
                            staticcall(
                                gas(), // Amount of gas left for the transaction.
                                1, // Address of `ecrecover`.
                                0x00, // Start of input.
                                0x80, // Size of input.
                                0x40, // Start of output.
                                0x20 // Size of output.
                            )
                        )
                        mstore(0x60, 0) // Restore the zero slot.
                        // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
                        result := mload(xor(0x60, returndatasize()))
                        mstore(0x40, m) // Restore the free memory pointer.
                    }
                }
                /// @dev Recovers the signer's address from a message digest `hash`,
                /// and the signature defined by `v`, `r`, `s`.
                function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s)
                    internal
                    view
                    returns (address result)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        let m := mload(0x40) // Cache the free memory pointer.
                        mstore(0x00, hash)
                        mstore(0x20, and(v, 0xff))
                        mstore(0x40, r)
                        mstore(0x60, s)
                        pop(
                            staticcall(
                                gas(), // Amount of gas left for the transaction.
                                1, // Address of `ecrecover`.
                                0x00, // Start of input.
                                0x80, // Size of input.
                                0x40, // Start of output.
                                0x20 // Size of output.
                            )
                        )
                        mstore(0x60, 0) // Restore the zero slot.
                        // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
                        result := mload(xor(0x60, returndatasize()))
                        mstore(0x40, m) // Restore the free memory pointer.
                    }
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                     HASHING OPERATIONS                     */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Returns an Ethereum Signed Message, created from a `hash`.
                /// This produces a hash corresponding to the one signed with the
                /// [`eth_sign`](https://eth.wiki/json-rpc/API#eth_sign)
                /// JSON-RPC method as part of EIP-191.
                function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 result) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        mstore(0x20, hash) // Store into scratch space for keccak256.
                        mstore(0x00, "\\x00\\x00\\x00\\x00\\x19Ethereum Signed Message:\
            32") // 28 bytes.
                        result := keccak256(0x04, 0x3c) // `32 * 2 - (32 - 28) = 60 = 0x3c`.
                    }
                }
                /// @dev Returns an Ethereum Signed Message, created from `s`.
                /// This produces a hash corresponding to the one signed with the
                /// [`eth_sign`](https://eth.wiki/json-rpc/API#eth_sign)
                /// JSON-RPC method as part of EIP-191.
                /// Note: Supports lengths of `s` up to 999999 bytes.
                function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32 result) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        let sLength := mload(s)
                        let o := 0x20
                        mstore(o, "\\x19Ethereum Signed Message:\
            ") // 26 bytes, zero-right-padded.
                        mstore(0x00, 0x00)
                        // Convert the `s.length` to ASCII decimal representation: `base10(s.length)`.
                        for { let temp := sLength } 1 {} {
                            o := sub(o, 1)
                            mstore8(o, add(48, mod(temp, 10)))
                            temp := div(temp, 10)
                            if iszero(temp) { break }
                        }
                        let n := sub(0x3a, o) // Header length: `26 + 32 - o`.
                        // Throw an out-of-offset error (consumes all gas) if the header exceeds 32 bytes.
                        returndatacopy(returndatasize(), returndatasize(), gt(n, 0x20))
                        mstore(s, or(mload(0x00), mload(n))) // Temporarily store the header.
                        result := keccak256(add(s, sub(0x20, n)), add(n, sLength))
                        mstore(s, sLength) // Restore the length.
                    }
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                   EMPTY CALLDATA HELPERS                   */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Returns an empty calldata bytes.
                function emptySignature() internal pure returns (bytes calldata signature) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        signature.length := 0
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            /*
            ██████╗ ██████╗ ██████╗ ███╗   ███╗ █████╗ ████████╗██╗  ██╗
            ██╔══██╗██╔══██╗██╔══██╗████╗ ████║██╔══██╗╚══██╔══╝██║  ██║
            ██████╔╝██████╔╝██████╔╝██╔████╔██║███████║   ██║   ███████║
            ██╔═══╝ ██╔══██╗██╔══██╗██║╚██╔╝██║██╔══██║   ██║   ██╔══██║
            ██║     ██║  ██║██████╔╝██║ ╚═╝ ██║██║  ██║   ██║   ██║  ██║
            ╚═╝     ╚═╝  ╚═╝╚═════╝ ╚═╝     ╚═╝╚═╝  ╚═╝   ╚═╝   ╚═╝  ╚═╝
            ██╗   ██╗██████╗  ██████╗  ██████╗ ██╗  ██╗ ██╗ █████╗
            ██║   ██║██╔══██╗██╔════╝ ██╔═████╗╚██╗██╔╝███║██╔══██╗
            ██║   ██║██║  ██║███████╗ ██║██╔██║ ╚███╔╝ ╚██║╚█████╔╝
            ██║   ██║██║  ██║██╔═══██╗████╔╝██║ ██╔██╗  ██║██╔══██╗
            ╚██████╔╝██████╔╝╚██████╔╝╚██████╔╝██╔╝ ██╗ ██║╚█████╔╝
             ╚═════╝ ╚═════╝  ╚═════╝  ╚═════╝ ╚═╝  ╚═╝ ╚═╝ ╚════╝
            */
            import "./ud60x18/Casting.sol";
            import "./ud60x18/Constants.sol";
            import "./ud60x18/Conversions.sol";
            import "./ud60x18/Errors.sol";
            import "./ud60x18/Helpers.sol";
            import "./ud60x18/Math.sol";
            import "./ud60x18/ValueType.sol";
            // SPDX-License-Identifier: GPL-3.0-or-later
            pragma solidity >=0.8.19;
            import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
            import { Lockup, LockupLinear } from "../types/DataTypes.sol";
            import { ISablierV2Lockup } from "./ISablierV2Lockup.sol";
            /// @title ISablierV2LockupLinear
            /// @notice Creates and manages Lockup streams with linear streaming functions.
            interface ISablierV2LockupLinear is ISablierV2Lockup {
                /*//////////////////////////////////////////////////////////////////////////
                                                   EVENTS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Emitted when a stream is created.
                /// @param streamId The id of the newly created stream.
                /// @param funder The address which funded the stream.
                /// @param sender The address streaming the assets, with the ability to cancel the stream.
                /// @param recipient The address receiving the assets.
                /// @param amounts Struct containing (i) the deposit amount, (ii) the protocol fee amount, and (iii) the
                /// broker fee amount, all denoted in units of the asset's decimals.
                /// @param asset The contract address of the ERC-20 asset used for streaming.
                /// @param cancelable Boolean indicating whether the stream will be cancelable or not.
                /// @param transferable Boolean indicating whether the stream NFT is transferable or not.
                /// @param range Struct containing (i) the stream's start time, (ii) cliff time, and (iii) end time, all as Unix
                /// timestamps.
                /// @param broker The address of the broker who has helped create the stream, e.g. a front-end website.
                event CreateLockupLinearStream(
                    uint256 streamId,
                    address funder,
                    address indexed sender,
                    address indexed recipient,
                    Lockup.CreateAmounts amounts,
                    IERC20 indexed asset,
                    bool cancelable,
                    bool transferable,
                    LockupLinear.Range range,
                    address broker
                );
                /*//////////////////////////////////////////////////////////////////////////
                                             CONSTANT FUNCTIONS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Retrieves the stream's cliff time, which is a Unix timestamp.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function getCliffTime(uint256 streamId) external view returns (uint40 cliffTime);
                /// @notice Retrieves the stream's range, which is a struct containing (i) the stream's start time, (ii) cliff
                /// time, and (iii) end time, all as Unix timestamps.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function getRange(uint256 streamId) external view returns (LockupLinear.Range memory range);
                /// @notice Retrieves the stream entity.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function getStream(uint256 streamId) external view returns (LockupLinear.Stream memory stream);
                /// @notice Calculates the amount streamed to the recipient, denoted in units of the asset's decimals.
                ///
                /// When the stream is warm, the streaming function is:
                ///
                /// $$
                /// f(x) = x * d + c
                /// $$
                ///
                /// Where:
                ///
                /// - $x$ is the elapsed time divided by the stream's total duration.
                /// - $d$ is the deposited amount.
                /// - $c$ is the cliff amount.
                ///
                /// Upon cancellation of the stream, the amount streamed is calculated as the difference between the deposited
                /// amount and the refunded amount. Ultimately, when the stream becomes depleted, the streamed amount is equivalent
                /// to the total amount withdrawn.
                ///
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function streamedAmountOf(uint256 streamId) external view returns (uint128 streamedAmount);
                /*//////////////////////////////////////////////////////////////////////////
                                           NON-CONSTANT FUNCTIONS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Creates a stream by setting the start time to `block.timestamp`, and the end time to
                /// the sum of `block.timestamp` and `params.durations.total`. The stream is funded by `msg.sender` and is wrapped
                /// in an ERC-721 NFT.
                ///
                /// @dev Emits a {Transfer} and {CreateLockupLinearStream} event.
                ///
                /// Requirements:
                /// - All requirements in {createWithRange} must be met for the calculated parameters.
                ///
                /// @param params Struct encapsulating the function parameters, which are documented in {DataTypes}.
                /// @return streamId The id of the newly created stream.
                function createWithDurations(LockupLinear.CreateWithDurations calldata params)
                    external
                    returns (uint256 streamId);
                /// @notice Creates a stream with the provided start time and end time as the range. The stream is
                /// funded by `msg.sender` and is wrapped in an ERC-721 NFT.
                ///
                /// @dev Emits a {Transfer} and {CreateLockupLinearStream} event.
                ///
                /// Notes:
                /// - As long as the times are ordered, it is not an error for the start or the cliff time to be in the past.
                ///
                /// Requirements:
                /// - Must not be delegate called.
                /// - `params.totalAmount` must be greater than zero.
                /// - If set, `params.broker.fee` must not be greater than `MAX_FEE`.
                /// - `params.range.start` must be less than or equal to `params.range.cliff`.
                /// - `params.range.cliff` must be less than `params.range.end`.
                /// - `params.range.end` must be in the future.
                /// - `params.recipient` must not be the zero address.
                /// - `msg.sender` must have allowed this contract to spend at least `params.totalAmount` assets.
                ///
                /// @param params Struct encapsulating the function parameters, which are documented in {DataTypes}.
                /// @return streamId The id of the newly created stream.
                function createWithRange(LockupLinear.CreateWithRange calldata params) external returns (uint256 streamId);
            }
            // SPDX-License-Identifier: GPL-3.0-or-later
            pragma solidity >=0.8.19;
            import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
            import { UD2x18 } from "@prb/math/src/UD2x18.sol";
            import { UD60x18 } from "@prb/math/src/UD60x18.sol";
            // DataTypes.sol
            //
            // This file defines all structs used in V2 Core, most of which are organized under three namespaces:
            //
            // - Lockup
            // - LockupDynamic
            // - LockupLinear
            //
            // You will notice that some structs contain "slot" annotations - they are used to indicate the
            // storage layout of the struct. It is more gas efficient to group small data types together so
            // that they fit in a single 32-byte slot.
            /// @notice Struct encapsulating the broker parameters passed to the create functions. Both can be set to zero.
            /// @param account The address receiving the broker's fee.
            /// @param fee The broker's percentage fee from the total amount, denoted as a fixed-point number where 1e18 is 100%.
            struct Broker {
                address account;
                UD60x18 fee;
            }
            /// @notice Namespace for the structs used in both {SablierV2LockupLinear} and {SablierV2LockupDynamic}.
            library Lockup {
                /// @notice Struct encapsulating the deposit, withdrawn, and refunded amounts, all denoted in units
                /// of the asset's decimals.
                /// @dev Because the deposited and the withdrawn amount are often read together, declaring them in
                /// the same slot saves gas.
                /// @param deposited The initial amount deposited in the stream, net of fees.
                /// @param withdrawn The cumulative amount withdrawn from the stream.
                /// @param refunded The amount refunded to the sender. Unless the stream was canceled, this is always zero.
                struct Amounts {
                    // slot 0
                    uint128 deposited;
                    uint128 withdrawn;
                    // slot 1
                    uint128 refunded;
                }
                /// @notice Struct encapsulating the deposit amount, the protocol fee amount, and the broker fee amount,
                /// all denoted in units of the asset's decimals.
                /// @param deposit The amount to deposit in the stream.
                /// @param protocolFee The protocol fee amount.
                /// @param brokerFee The broker fee amount.
                struct CreateAmounts {
                    uint128 deposit;
                    uint128 protocolFee;
                    uint128 brokerFee;
                }
                /// @notice Enum representing the different statuses of a stream.
                /// @custom:value PENDING Stream created but not started; assets are in a pending state.
                /// @custom:value STREAMING Active stream where assets are currently being streamed.
                /// @custom:value SETTLED All assets have been streamed; recipient is due to withdraw them.
                /// @custom:value CANCELED Canceled stream; remaining assets await recipient's withdrawal.
                /// @custom:value DEPLETED Depleted stream; all assets have been withdrawn and/or refunded.
                enum Status {
                    PENDING, // value 0
                    STREAMING, // value 1
                    SETTLED, // value 2
                    CANCELED, // value 3
                    DEPLETED // value 4
                }
            }
            /// @notice Namespace for the structs used in {SablierV2LockupDynamic}.
            library LockupDynamic {
                /// @notice Struct encapsulating the parameters for the {SablierV2LockupDynamic.createWithDeltas} function.
                /// @param sender The address streaming the assets, with the ability to cancel the stream. It doesn't have to be the
                /// same as `msg.sender`.
                /// @param recipient The address receiving the assets.
                /// @param totalAmount The total amount of ERC-20 assets to be paid, including the stream deposit and any potential
                /// fees, all denoted in units of the asset's decimals.
                /// @param asset The contract address of the ERC-20 asset used for streaming.
                /// @param cancelable Indicates if the stream is cancelable.
                /// @param transferable Indicates if the stream NFT is transferable.
                /// @param broker Struct containing (i) the address of the broker assisting in creating the stream, and (ii) the
                /// percentage fee paid to the broker from `totalAmount`, denoted as a fixed-point number. Both can be set to zero.
                /// @param segments Segments with deltas used to compose the custom streaming curve. Milestones are calculated by
                /// starting from `block.timestamp` and adding each delta to the previous milestone.
                struct CreateWithDeltas {
                    address sender;
                    bool cancelable;
                    bool transferable;
                    address recipient;
                    uint128 totalAmount;
                    IERC20 asset;
                    Broker broker;
                    SegmentWithDelta[] segments;
                }
                /// @notice Struct encapsulating the parameters for the {SablierV2LockupDynamic.createWithMilestones}
                /// function.
                /// @param sender The address streaming the assets, with the ability to cancel the stream. It doesn't have to be the
                /// same as `msg.sender`.
                /// @param startTime The Unix timestamp indicating the stream's start.
                /// @param cancelable Indicates if the stream is cancelable.
                /// @param transferable Indicates if the stream NFT is transferable.
                /// @param recipient The address receiving the assets.
                /// @param totalAmount The total amount of ERC-20 assets to be paid, including the stream deposit and any potential
                /// fees, all denoted in units of the asset's decimals.
                /// @param asset The contract address of the ERC-20 asset used for streaming.
                /// @param broker Struct containing (i) the address of the broker assisting in creating the stream, and (ii) the
                /// percentage fee paid to the broker from `totalAmount`, denoted as a fixed-point number. Both can be set to zero.
                /// @param segments Segments used to compose the custom streaming curve.
                struct CreateWithMilestones {
                    address sender;
                    uint40 startTime;
                    bool cancelable;
                    bool transferable;
                    address recipient;
                    uint128 totalAmount;
                    IERC20 asset;
                    Broker broker;
                    Segment[] segments;
                }
                /// @notice Struct encapsulating the time range.
                /// @param start The Unix timestamp indicating the stream's start.
                /// @param end The Unix timestamp indicating the stream's end.
                struct Range {
                    uint40 start;
                    uint40 end;
                }
                /// @notice Segment struct used in the Lockup Dynamic stream.
                /// @param amount The amount of assets to be streamed in this segment, denoted in units of the asset's decimals.
                /// @param exponent The exponent of this segment, denoted as a fixed-point number.
                /// @param milestone The Unix timestamp indicating this segment's end.
                struct Segment {
                    // slot 0
                    uint128 amount;
                    UD2x18 exponent;
                    uint40 milestone;
                }
                /// @notice Segment struct used at runtime in {SablierV2LockupDynamic.createWithDeltas}.
                /// @param amount The amount of assets to be streamed in this segment, denoted in units of the asset's decimals.
                /// @param exponent The exponent of this segment, denoted as a fixed-point number.
                /// @param delta The time difference in seconds between this segment and the previous one.
                struct SegmentWithDelta {
                    uint128 amount;
                    UD2x18 exponent;
                    uint40 delta;
                }
                /// @notice Lockup Dynamic stream.
                /// @dev The fields are arranged like this to save gas via tight variable packing.
                /// @param sender The address streaming the assets, with the ability to cancel the stream.
                /// @param startTime The Unix timestamp indicating the stream's start.
                /// @param endTime The Unix timestamp indicating the stream's end.
                /// @param isCancelable Boolean indicating if the stream is cancelable.
                /// @param wasCanceled Boolean indicating if the stream was canceled.
                /// @param asset The contract address of the ERC-20 asset used for streaming.
                /// @param isDepleted Boolean indicating if the stream is depleted.
                /// @param isStream Boolean indicating if the struct entity exists.
                /// @param isTransferable Boolean indicating if the stream NFT is transferable.
                /// @param amounts Struct containing the deposit, withdrawn, and refunded amounts, all denoted in units of the
                /// asset's decimals.
                /// @param segments Segments used to compose the custom streaming curve.
                struct Stream {
                    // slot 0
                    address sender;
                    uint40 startTime;
                    uint40 endTime;
                    bool isCancelable;
                    bool wasCanceled;
                    // slot 1
                    IERC20 asset;
                    bool isDepleted;
                    bool isStream;
                    bool isTransferable;
                    // slot 2 and 3
                    Lockup.Amounts amounts;
                    // slots [4..n]
                    Segment[] segments;
                }
            }
            /// @notice Namespace for the structs used in {SablierV2LockupLinear}.
            library LockupLinear {
                /// @notice Struct encapsulating the parameters for the {SablierV2LockupLinear.createWithDurations} function.
                /// @param sender The address streaming the assets, with the ability to cancel the stream. It doesn't have to be the
                /// same as `msg.sender`.
                /// @param recipient The address receiving the assets.
                /// @param totalAmount The total amount of ERC-20 assets to be paid, including the stream deposit and any potential
                /// fees, all denoted in units of the asset's decimals.
                /// @param asset The contract address of the ERC-20 asset used for streaming.
                /// @param cancelable Indicates if the stream is cancelable.
                /// @param transferable Indicates if the stream NFT is transferable.
                /// @param durations Struct containing (i) cliff period duration and (ii) total stream duration, both in seconds.
                /// @param broker Struct containing (i) the address of the broker assisting in creating the stream, and (ii) the
                /// percentage fee paid to the broker from `totalAmount`, denoted as a fixed-point number. Both can be set to zero.
                struct CreateWithDurations {
                    address sender;
                    address recipient;
                    uint128 totalAmount;
                    IERC20 asset;
                    bool cancelable;
                    bool transferable;
                    Durations durations;
                    Broker broker;
                }
                /// @notice Struct encapsulating the parameters for the {SablierV2LockupLinear.createWithRange} function.
                /// @param sender The address streaming the assets, with the ability to cancel the stream. It doesn't have to be the
                /// same as `msg.sender`.
                /// @param recipient The address receiving the assets.
                /// @param totalAmount The total amount of ERC-20 assets to be paid, including the stream deposit and any potential
                /// fees, all denoted in units of the asset's decimals.
                /// @param asset The contract address of the ERC-20 asset used for streaming.
                /// @param cancelable Indicates if the stream is cancelable.
                /// @param transferable Indicates if the stream NFT is transferable.
                /// @param range Struct containing (i) the stream's start time, (ii) cliff time, and (iii) end time, all as Unix
                /// timestamps.
                /// @param broker Struct containing (i) the address of the broker assisting in creating the stream, and (ii) the
                /// percentage fee paid to the broker from `totalAmount`, denoted as a fixed-point number. Both can be set to zero.
                struct CreateWithRange {
                    address sender;
                    address recipient;
                    uint128 totalAmount;
                    IERC20 asset;
                    bool cancelable;
                    bool transferable;
                    Range range;
                    Broker broker;
                }
                /// @notice Struct encapsulating the cliff duration and the total duration.
                /// @param cliff The cliff duration in seconds.
                /// @param total The total duration in seconds.
                struct Durations {
                    uint40 cliff;
                    uint40 total;
                }
                /// @notice Struct encapsulating the time range.
                /// @param start The Unix timestamp for the stream's start.
                /// @param cliff The Unix timestamp for the cliff period's end.
                /// @param end The Unix timestamp for the stream's end.
                struct Range {
                    uint40 start;
                    uint40 cliff;
                    uint40 end;
                }
                /// @notice Lockup Linear stream.
                /// @dev The fields are arranged like this to save gas via tight variable packing.
                /// @param sender The address streaming the assets, with the ability to cancel the stream.
                /// @param startTime The Unix timestamp indicating the stream's start.
                /// @param cliffTime The Unix timestamp indicating the cliff period's end.
                /// @param isCancelable Boolean indicating if the stream is cancelable.
                /// @param wasCanceled Boolean indicating if the stream was canceled.
                /// @param asset The contract address of the ERC-20 asset used for streaming.
                /// @param endTime The Unix timestamp indicating the stream's end.
                /// @param isDepleted Boolean indicating if the stream is depleted.
                /// @param isStream Boolean indicating if the struct entity exists.
                /// @param isTransferable Boolean indicating if the stream NFT is transferable.
                /// @param amounts Struct containing the deposit, withdrawn, and refunded amounts, all denoted in units of the
                /// asset's decimals.
                struct Stream {
                    // slot 0
                    address sender;
                    uint40 startTime;
                    uint40 cliffTime;
                    bool isCancelable;
                    bool wasCanceled;
                    // slot 1
                    IERC20 asset;
                    uint40 endTime;
                    bool isDepleted;
                    bool isStream;
                    bool isTransferable;
                    // slot 2 and 3
                    Lockup.Amounts amounts;
                }
            }
            // SPDX-License-Identifier: AGPL-3.0-only
            pragma solidity =0.8.25;
            import { FixedPointMathLib } from "solady/utils/FixedPointMathLib.sol";
            library FjordMath {
                using FixedPointMathLib for uint256;
                /// @notice The scaling factor for all normalization/denormalization operations
                uint256 private constant SCALING_FACTOR = 18;
                /// @notice Normalize a value to the scaling factor
                /// @param value The value to normalize
                /// @param decimals The number of decimals of the value
                /// @dev No greater than check is required as > 18 decimals are not supported
                function normalize(uint256 value, uint8 decimals) internal pure returns (uint256) {
                    if (decimals < SCALING_FACTOR) {
                        return value * (10 ** (SCALING_FACTOR - decimals));
                    }
                    return value;
                }
                /// @notice Denormalizes a value back to its original value
                /// @param value The value to denormalize
                /// @param decimals The number of decimals of the value
                /// @dev No greater than check is required as > 18 decimals are not supported. This function rounds up post division.
                function denormalizeUp(uint256 value, uint8 decimals) internal pure returns (uint256) {
                    if (decimals < SCALING_FACTOR) {
                        return value.divUp(10 ** (SCALING_FACTOR - decimals));
                    }
                    return value;
                }
                /// @notice Denormalizes a value back to its original value
                /// @param value The value to denormalize
                /// @param decimals The number of decimals of the value
                /// @dev No greater than check is required as > 18 decimals are not supported. This function rounds down post division.
                function denormalizeDown(uint256 value, uint8 decimals) internal pure returns (uint256) {
                    if (decimals < SCALING_FACTOR) {
                        return value / (10 ** (SCALING_FACTOR - decimals));
                    }
                    return value;
                }
                ///@notice Returns the minimum swap threshold required for a purchase to be valid.
                ///@dev This is used to prevent rounding errors when making swaps between tokens of varying decimals.
                function mandatoryMinimumSwapIn(
                    uint8 shareDecimals,
                    uint8 assetDecimals
                )
                    public
                    pure
                    returns (uint256)
                {
                    if (shareDecimals > assetDecimals) {
                        return 10 ** (shareDecimals - assetDecimals + 2);
                    } else {
                        return 0;
                    }
                }
            }
            // SPDX-License-Identifier: AGPL-3.0-only
            pragma solidity =0.8.25;
            abstract contract FjordConstants {
                //-----------------------------------------------------------------------------------------------------------------------------------------
                // BASE POOL OFFSETS ONLY
                //-----------------------------------------------------------------------------------------------------------------------------------------
                uint256 internal constant OWNER_OFFSET = 0; // Increment offset by 20
                uint256 internal constant SHARE_TOKEN_OFFSET = 20; // Increment offset by 20
                uint256 internal constant ASSET_TOKEN_OFFSET = 40; // Increment offset by 20
                uint256 internal constant FEE_RECIPIENT_OFFSET = 60; // Increment offset by 20
                uint256 internal constant DELEGATE_SIGNER_OFFSET = 80; // Increment offset by 20
                uint256 internal constant SHARES_FOR_SALE_OFFSET = 100; // Increment offset by 32
                uint256 internal constant MINIMUM_TOKENS_FOR_SALE_OFFSET = 132; // Increment offset by 32
                uint256 internal constant MAXIMUM_TOKENS_PER_USER_OFFSET = 164; // Increment offset by 32
                uint256 internal constant MINIMUM_TOKENS_PER_USER_OFFSET = 196; // Increment offset by 32
                uint256 internal constant SWAP_FEE_WAD_OFFSET = 228; // Increment offset by 8
                uint256 internal constant PLATFORM_FEE_WAD_OFFSET = 236; // Increment offset by 8
                uint256 internal constant SALE_START_OFFSET = 244; // Increment offset by 5
                uint256 internal constant SALE_END_OFFSET = 249; // Increment offset by 5
                uint256 internal constant REDEMPTION_DELAY_OFFSET = 254; // Increment offset by 5
                uint256 internal constant VEST_END_OFFSET = 259; // Increment offset by 5
                uint256 internal constant VEST_CLIFF_OFFSET = 264; // Increment offset by 5
                uint256 internal constant SHARE_TOKEN_DECIMALS_OFFSET = 269; // Increment offset by 1
                uint256 internal constant ASSET_TOKEN_DECIMALS_OFFSET = 270; // Increment offset by 1
                uint256 internal constant ANTISNIPE_ENABLED_OFFSET = 271; // Increment offset by 1
                uint256 internal constant WHITELIST_MERKLE_ROOT_OFFSET = 272; // Increment offset by 32
                //-----------------------------------------------------------------------------------------------------------------------------------------
                // FIXED PRICE OFFSETS ONLY
                //-----------------------------------------------------------------------------------------------------------------------------------------
                uint256 internal constant ASSETS_PER_TOKEN_OFFSET = 304; // Increment offset by 32
                uint256 internal constant TIER_DATA_LENGTH_OFFSET = 336; // Increment offset by 32
                uint256 internal constant TIERS_OFFSET = 368; // Increment offset by 32
                uint256 internal constant EMPTY_TIER_ARRAY_OFFSET = 64; // Size of an empty encoded Tier[] struct
                uint256 internal constant TIER_BASE_OFFSET = 128; // Size of an encoded Tier struct (uint256,uint256,uint256,uint256)
                //-----------------------------------------------------------------------------------------------------------------------------------------
                //OVERFLOW OFFSETS ONLY
                //-----------------------------------------------------------------------------------------------------------------------------------------
                uint256 internal constant ASSET_HARD_CAP_OFFSET = 304; // Increment offset by 32
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "./Errors.sol" as CastingErrors;
            import { MAX_UINT128, MAX_UINT40 } from "../Common.sol";
            import { uMAX_SD1x18 } from "../sd1x18/Constants.sol";
            import { SD1x18 } from "../sd1x18/ValueType.sol";
            import { uMAX_SD21x18 } from "../sd21x18/Constants.sol";
            import { SD21x18 } from "../sd21x18/ValueType.sol";
            import { uMAX_SD59x18 } from "../sd59x18/Constants.sol";
            import { SD59x18 } from "../sd59x18/ValueType.sol";
            import { uMAX_UD2x18 } from "../ud2x18/Constants.sol";
            import { uMAX_UD21x18 } from "../ud21x18/Constants.sol";
            import { UD2x18 } from "../ud2x18/ValueType.sol";
            import { UD21x18 } from "../ud21x18/ValueType.sol";
            import { UD60x18 } from "./ValueType.sol";
            /// @notice Casts a UD60x18 number into SD1x18.
            /// @dev Requirements:
            /// - x ≤ uMAX_SD1x18
            function intoSD1x18(UD60x18 x) pure returns (SD1x18 result) {
                uint256 xUint = UD60x18.unwrap(x);
                if (xUint > uint256(int256(uMAX_SD1x18))) {
                    revert CastingErrors.PRBMath_UD60x18_IntoSD1x18_Overflow(x);
                }
                result = SD1x18.wrap(int64(uint64(xUint)));
            }
            /// @notice Casts a UD60x18 number into SD21x18.
            /// @dev Requirements:
            /// - x ≤ uMAX_SD21x18
            function intoSD21x18(UD60x18 x) pure returns (SD21x18 result) {
                uint256 xUint = UD60x18.unwrap(x);
                if (xUint > uint256(int256(uMAX_SD21x18))) {
                    revert CastingErrors.PRBMath_UD60x18_IntoSD21x18_Overflow(x);
                }
                result = SD21x18.wrap(int128(uint128(xUint)));
            }
            /// @notice Casts a UD60x18 number into UD2x18.
            /// @dev Requirements:
            /// - x ≤ uMAX_UD2x18
            function intoUD2x18(UD60x18 x) pure returns (UD2x18 result) {
                uint256 xUint = UD60x18.unwrap(x);
                if (xUint > uMAX_UD2x18) {
                    revert CastingErrors.PRBMath_UD60x18_IntoUD2x18_Overflow(x);
                }
                result = UD2x18.wrap(uint64(xUint));
            }
            /// @notice Casts a UD60x18 number into UD21x18.
            /// @dev Requirements:
            /// - x ≤ uMAX_UD21x18
            function intoUD21x18(UD60x18 x) pure returns (UD21x18 result) {
                uint256 xUint = UD60x18.unwrap(x);
                if (xUint > uMAX_UD21x18) {
                    revert CastingErrors.PRBMath_UD60x18_IntoUD21x18_Overflow(x);
                }
                result = UD21x18.wrap(uint128(xUint));
            }
            /// @notice Casts a UD60x18 number into SD59x18.
            /// @dev Requirements:
            /// - x ≤ uMAX_SD59x18
            function intoSD59x18(UD60x18 x) pure returns (SD59x18 result) {
                uint256 xUint = UD60x18.unwrap(x);
                if (xUint > uint256(uMAX_SD59x18)) {
                    revert CastingErrors.PRBMath_UD60x18_IntoSD59x18_Overflow(x);
                }
                result = SD59x18.wrap(int256(xUint));
            }
            /// @notice Casts a UD60x18 number into uint128.
            /// @dev This is basically an alias for {unwrap}.
            function intoUint256(UD60x18 x) pure returns (uint256 result) {
                result = UD60x18.unwrap(x);
            }
            /// @notice Casts a UD60x18 number into uint128.
            /// @dev Requirements:
            /// - x ≤ MAX_UINT128
            function intoUint128(UD60x18 x) pure returns (uint128 result) {
                uint256 xUint = UD60x18.unwrap(x);
                if (xUint > MAX_UINT128) {
                    revert CastingErrors.PRBMath_UD60x18_IntoUint128_Overflow(x);
                }
                result = uint128(xUint);
            }
            /// @notice Casts a UD60x18 number into uint40.
            /// @dev Requirements:
            /// - x ≤ MAX_UINT40
            function intoUint40(UD60x18 x) pure returns (uint40 result) {
                uint256 xUint = UD60x18.unwrap(x);
                if (xUint > MAX_UINT40) {
                    revert CastingErrors.PRBMath_UD60x18_IntoUint40_Overflow(x);
                }
                result = uint40(xUint);
            }
            /// @notice Alias for {wrap}.
            function ud(uint256 x) pure returns (UD60x18 result) {
                result = UD60x18.wrap(x);
            }
            /// @notice Alias for {wrap}.
            function ud60x18(uint256 x) pure returns (UD60x18 result) {
                result = UD60x18.wrap(x);
            }
            /// @notice Unwraps a UD60x18 number into uint256.
            function unwrap(UD60x18 x) pure returns (uint256 result) {
                result = UD60x18.unwrap(x);
            }
            /// @notice Wraps a uint256 number into the UD60x18 value type.
            function wrap(uint256 x) pure returns (UD60x18 result) {
                result = UD60x18.wrap(x);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { UD60x18 } from "./ValueType.sol";
            // NOTICE: the "u" prefix stands for "unwrapped".
            /// @dev Euler's number as a UD60x18 number.
            UD60x18 constant E = UD60x18.wrap(2_718281828459045235);
            /// @dev The maximum input permitted in {exp}.
            uint256 constant uEXP_MAX_INPUT = 133_084258667509499440;
            UD60x18 constant EXP_MAX_INPUT = UD60x18.wrap(uEXP_MAX_INPUT);
            /// @dev The maximum input permitted in {exp2}.
            uint256 constant uEXP2_MAX_INPUT = 192e18 - 1;
            UD60x18 constant EXP2_MAX_INPUT = UD60x18.wrap(uEXP2_MAX_INPUT);
            /// @dev Half the UNIT number.
            uint256 constant uHALF_UNIT = 0.5e18;
            UD60x18 constant HALF_UNIT = UD60x18.wrap(uHALF_UNIT);
            /// @dev $log_2(10)$ as a UD60x18 number.
            uint256 constant uLOG2_10 = 3_321928094887362347;
            UD60x18 constant LOG2_10 = UD60x18.wrap(uLOG2_10);
            /// @dev $log_2(e)$ as a UD60x18 number.
            uint256 constant uLOG2_E = 1_442695040888963407;
            UD60x18 constant LOG2_E = UD60x18.wrap(uLOG2_E);
            /// @dev The maximum value a UD60x18 number can have.
            uint256 constant uMAX_UD60x18 = 115792089237316195423570985008687907853269984665640564039457_584007913129639935;
            UD60x18 constant MAX_UD60x18 = UD60x18.wrap(uMAX_UD60x18);
            /// @dev The maximum whole value a UD60x18 number can have.
            uint256 constant uMAX_WHOLE_UD60x18 = 115792089237316195423570985008687907853269984665640564039457_000000000000000000;
            UD60x18 constant MAX_WHOLE_UD60x18 = UD60x18.wrap(uMAX_WHOLE_UD60x18);
            /// @dev PI as a UD60x18 number.
            UD60x18 constant PI = UD60x18.wrap(3_141592653589793238);
            /// @dev The unit number, which gives the decimal precision of UD60x18.
            uint256 constant uUNIT = 1e18;
            UD60x18 constant UNIT = UD60x18.wrap(uUNIT);
            /// @dev The unit number squared.
            uint256 constant uUNIT_SQUARED = 1e36;
            UD60x18 constant UNIT_SQUARED = UD60x18.wrap(uUNIT_SQUARED);
            /// @dev Zero as a UD60x18 number.
            UD60x18 constant ZERO = UD60x18.wrap(0);
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { uMAX_UD60x18, uUNIT } from "./Constants.sol";
            import { PRBMath_UD60x18_Convert_Overflow } from "./Errors.sol";
            import { UD60x18 } from "./ValueType.sol";
            /// @notice Converts a UD60x18 number to a simple integer by dividing it by `UNIT`.
            /// @dev The result is rounded toward zero.
            /// @param x The UD60x18 number to convert.
            /// @return result The same number in basic integer form.
            function convert(UD60x18 x) pure returns (uint256 result) {
                result = UD60x18.unwrap(x) / uUNIT;
            }
            /// @notice Converts a simple integer to UD60x18 by multiplying it by `UNIT`.
            ///
            /// @dev Requirements:
            /// - x ≤ MAX_UD60x18 / UNIT
            ///
            /// @param x The basic integer to convert.
            /// @return result The same number converted to UD60x18.
            function convert(uint256 x) pure returns (UD60x18 result) {
                if (x > uMAX_UD60x18 / uUNIT) {
                    revert PRBMath_UD60x18_Convert_Overflow(x);
                }
                unchecked {
                    result = UD60x18.wrap(x * uUNIT);
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { UD60x18 } from "./ValueType.sol";
            /// @notice Thrown when ceiling a number overflows UD60x18.
            error PRBMath_UD60x18_Ceil_Overflow(UD60x18 x);
            /// @notice Thrown when converting a basic integer to the fixed-point format overflows UD60x18.
            error PRBMath_UD60x18_Convert_Overflow(uint256 x);
            /// @notice Thrown when taking the natural exponent of a base greater than 133_084258667509499441.
            error PRBMath_UD60x18_Exp_InputTooBig(UD60x18 x);
            /// @notice Thrown when taking the binary exponent of a base greater than 192e18.
            error PRBMath_UD60x18_Exp2_InputTooBig(UD60x18 x);
            /// @notice Thrown when taking the geometric mean of two numbers and multiplying them overflows UD60x18.
            error PRBMath_UD60x18_Gm_Overflow(UD60x18 x, UD60x18 y);
            /// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD1x18.
            error PRBMath_UD60x18_IntoSD1x18_Overflow(UD60x18 x);
            /// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD21x18.
            error PRBMath_UD60x18_IntoSD21x18_Overflow(UD60x18 x);
            /// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD59x18.
            error PRBMath_UD60x18_IntoSD59x18_Overflow(UD60x18 x);
            /// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in UD2x18.
            error PRBMath_UD60x18_IntoUD2x18_Overflow(UD60x18 x);
            /// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in UD21x18.
            error PRBMath_UD60x18_IntoUD21x18_Overflow(UD60x18 x);
            /// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint128.
            error PRBMath_UD60x18_IntoUint128_Overflow(UD60x18 x);
            /// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint40.
            error PRBMath_UD60x18_IntoUint40_Overflow(UD60x18 x);
            /// @notice Thrown when taking the logarithm of a number less than UNIT.
            error PRBMath_UD60x18_Log_InputTooSmall(UD60x18 x);
            /// @notice Thrown when calculating the square root overflows UD60x18.
            error PRBMath_UD60x18_Sqrt_Overflow(UD60x18 x);
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { wrap } from "./Casting.sol";
            import { UD60x18 } from "./ValueType.sol";
            /// @notice Implements the checked addition operation (+) in the UD60x18 type.
            function add(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                result = wrap(x.unwrap() + y.unwrap());
            }
            /// @notice Implements the AND (&) bitwise operation in the UD60x18 type.
            function and(UD60x18 x, uint256 bits) pure returns (UD60x18 result) {
                result = wrap(x.unwrap() & bits);
            }
            /// @notice Implements the AND (&) bitwise operation in the UD60x18 type.
            function and2(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                result = wrap(x.unwrap() & y.unwrap());
            }
            /// @notice Implements the equal operation (==) in the UD60x18 type.
            function eq(UD60x18 x, UD60x18 y) pure returns (bool result) {
                result = x.unwrap() == y.unwrap();
            }
            /// @notice Implements the greater than operation (>) in the UD60x18 type.
            function gt(UD60x18 x, UD60x18 y) pure returns (bool result) {
                result = x.unwrap() > y.unwrap();
            }
            /// @notice Implements the greater than or equal to operation (>=) in the UD60x18 type.
            function gte(UD60x18 x, UD60x18 y) pure returns (bool result) {
                result = x.unwrap() >= y.unwrap();
            }
            /// @notice Implements a zero comparison check function in the UD60x18 type.
            function isZero(UD60x18 x) pure returns (bool result) {
                // This wouldn't work if x could be negative.
                result = x.unwrap() == 0;
            }
            /// @notice Implements the left shift operation (<<) in the UD60x18 type.
            function lshift(UD60x18 x, uint256 bits) pure returns (UD60x18 result) {
                result = wrap(x.unwrap() << bits);
            }
            /// @notice Implements the lower than operation (<) in the UD60x18 type.
            function lt(UD60x18 x, UD60x18 y) pure returns (bool result) {
                result = x.unwrap() < y.unwrap();
            }
            /// @notice Implements the lower than or equal to operation (<=) in the UD60x18 type.
            function lte(UD60x18 x, UD60x18 y) pure returns (bool result) {
                result = x.unwrap() <= y.unwrap();
            }
            /// @notice Implements the checked modulo operation (%) in the UD60x18 type.
            function mod(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                result = wrap(x.unwrap() % y.unwrap());
            }
            /// @notice Implements the not equal operation (!=) in the UD60x18 type.
            function neq(UD60x18 x, UD60x18 y) pure returns (bool result) {
                result = x.unwrap() != y.unwrap();
            }
            /// @notice Implements the NOT (~) bitwise operation in the UD60x18 type.
            function not(UD60x18 x) pure returns (UD60x18 result) {
                result = wrap(~x.unwrap());
            }
            /// @notice Implements the OR (|) bitwise operation in the UD60x18 type.
            function or(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                result = wrap(x.unwrap() | y.unwrap());
            }
            /// @notice Implements the right shift operation (>>) in the UD60x18 type.
            function rshift(UD60x18 x, uint256 bits) pure returns (UD60x18 result) {
                result = wrap(x.unwrap() >> bits);
            }
            /// @notice Implements the checked subtraction operation (-) in the UD60x18 type.
            function sub(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                result = wrap(x.unwrap() - y.unwrap());
            }
            /// @notice Implements the unchecked addition operation (+) in the UD60x18 type.
            function uncheckedAdd(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                unchecked {
                    result = wrap(x.unwrap() + y.unwrap());
                }
            }
            /// @notice Implements the unchecked subtraction operation (-) in the UD60x18 type.
            function uncheckedSub(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                unchecked {
                    result = wrap(x.unwrap() - y.unwrap());
                }
            }
            /// @notice Implements the XOR (^) bitwise operation in the UD60x18 type.
            function xor(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                result = wrap(x.unwrap() ^ y.unwrap());
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "../Common.sol" as Common;
            import "./Errors.sol" as Errors;
            import { wrap } from "./Casting.sol";
            import {
                uEXP_MAX_INPUT,
                uEXP2_MAX_INPUT,
                uHALF_UNIT,
                uLOG2_10,
                uLOG2_E,
                uMAX_UD60x18,
                uMAX_WHOLE_UD60x18,
                UNIT,
                uUNIT,
                uUNIT_SQUARED,
                ZERO
            } from "./Constants.sol";
            import { UD60x18 } from "./ValueType.sol";
            /*//////////////////////////////////////////////////////////////////////////
                                        MATHEMATICAL FUNCTIONS
            //////////////////////////////////////////////////////////////////////////*/
            /// @notice Calculates the arithmetic average of x and y using the following formula:
            ///
            /// $$
            /// avg(x, y) = (x & y) + ((xUint ^ yUint) / 2)
            /// $$
            ///
            /// In English, this is what this formula does:
            ///
            /// 1. AND x and y.
            /// 2. Calculate half of XOR x and y.
            /// 3. Add the two results together.
            ///
            /// This technique is known as SWAR, which stands for "SIMD within a register". You can read more about it here:
            /// https://devblogs.microsoft.com/oldnewthing/20220207-00/?p=106223
            ///
            /// @dev Notes:
            /// - The result is rounded toward zero.
            ///
            /// @param x The first operand as a UD60x18 number.
            /// @param y The second operand as a UD60x18 number.
            /// @return result The arithmetic average as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function avg(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                uint256 xUint = x.unwrap();
                uint256 yUint = y.unwrap();
                unchecked {
                    result = wrap((xUint & yUint) + ((xUint ^ yUint) >> 1));
                }
            }
            /// @notice Yields the smallest whole number greater than or equal to x.
            ///
            /// @dev This is optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional
            /// counterparts. See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
            ///
            /// Requirements:
            /// - x ≤ MAX_WHOLE_UD60x18
            ///
            /// @param x The UD60x18 number to ceil.
            /// @return result The smallest whole number greater than or equal to x, as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function ceil(UD60x18 x) pure returns (UD60x18 result) {
                uint256 xUint = x.unwrap();
                if (xUint > uMAX_WHOLE_UD60x18) {
                    revert Errors.PRBMath_UD60x18_Ceil_Overflow(x);
                }
                assembly ("memory-safe") {
                    // Equivalent to `x % UNIT`.
                    let remainder := mod(x, uUNIT)
                    // Equivalent to `UNIT - remainder`.
                    let delta := sub(uUNIT, remainder)
                    // Equivalent to `x + remainder > 0 ? delta : 0`.
                    result := add(x, mul(delta, gt(remainder, 0)))
                }
            }
            /// @notice Divides two UD60x18 numbers, returning a new UD60x18 number.
            ///
            /// @dev Uses {Common.mulDiv} to enable overflow-safe multiplication and division.
            ///
            /// Notes:
            /// - Refer to the notes in {Common.mulDiv}.
            ///
            /// Requirements:
            /// - Refer to the requirements in {Common.mulDiv}.
            ///
            /// @param x The numerator as a UD60x18 number.
            /// @param y The denominator as a UD60x18 number.
            /// @return result The quotient as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function div(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                result = wrap(Common.mulDiv(x.unwrap(), uUNIT, y.unwrap()));
            }
            /// @notice Calculates the natural exponent of x using the following formula:
            ///
            /// $$
            /// e^x = 2^{x * log_2{e}}
            /// $$
            ///
            /// @dev Requirements:
            /// - x ≤ 133_084258667509499440
            ///
            /// @param x The exponent as a UD60x18 number.
            /// @return result The result as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function exp(UD60x18 x) pure returns (UD60x18 result) {
                uint256 xUint = x.unwrap();
                // This check prevents values greater than 192e18 from being passed to {exp2}.
                if (xUint > uEXP_MAX_INPUT) {
                    revert Errors.PRBMath_UD60x18_Exp_InputTooBig(x);
                }
                unchecked {
                    // Inline the fixed-point multiplication to save gas.
                    uint256 doubleUnitProduct = xUint * uLOG2_E;
                    result = exp2(wrap(doubleUnitProduct / uUNIT));
                }
            }
            /// @notice Calculates the binary exponent of x using the binary fraction method.
            ///
            /// @dev See https://ethereum.stackexchange.com/q/79903/24693
            ///
            /// Requirements:
            /// - x < 192e18
            /// - The result must fit in UD60x18.
            ///
            /// @param x The exponent as a UD60x18 number.
            /// @return result The result as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function exp2(UD60x18 x) pure returns (UD60x18 result) {
                uint256 xUint = x.unwrap();
                // Numbers greater than or equal to 192e18 don't fit in the 192.64-bit format.
                if (xUint > uEXP2_MAX_INPUT) {
                    revert Errors.PRBMath_UD60x18_Exp2_InputTooBig(x);
                }
                // Convert x to the 192.64-bit fixed-point format.
                uint256 x_192x64 = (xUint << 64) / uUNIT;
                // Pass x to the {Common.exp2} function, which uses the 192.64-bit fixed-point number representation.
                result = wrap(Common.exp2(x_192x64));
            }
            /// @notice Yields the greatest whole number less than or equal to x.
            /// @dev Optimized for fractional value inputs, because every whole value has (1e18 - 1) fractional counterparts.
            /// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
            /// @param x The UD60x18 number to floor.
            /// @return result The greatest whole number less than or equal to x, as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function floor(UD60x18 x) pure returns (UD60x18 result) {
                assembly ("memory-safe") {
                    // Equivalent to `x % UNIT`.
                    let remainder := mod(x, uUNIT)
                    // Equivalent to `x - remainder > 0 ? remainder : 0)`.
                    result := sub(x, mul(remainder, gt(remainder, 0)))
                }
            }
            /// @notice Yields the excess beyond the floor of x using the odd function definition.
            /// @dev See https://en.wikipedia.org/wiki/Fractional_part.
            /// @param x The UD60x18 number to get the fractional part of.
            /// @return result The fractional part of x as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function frac(UD60x18 x) pure returns (UD60x18 result) {
                assembly ("memory-safe") {
                    result := mod(x, uUNIT)
                }
            }
            /// @notice Calculates the geometric mean of x and y, i.e. $\\sqrt{x * y}$, rounding down.
            ///
            /// @dev Requirements:
            /// - x * y must fit in UD60x18.
            ///
            /// @param x The first operand as a UD60x18 number.
            /// @param y The second operand as a UD60x18 number.
            /// @return result The result as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function gm(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                uint256 xUint = x.unwrap();
                uint256 yUint = y.unwrap();
                if (xUint == 0 || yUint == 0) {
                    return ZERO;
                }
                unchecked {
                    // Checking for overflow this way is faster than letting Solidity do it.
                    uint256 xyUint = xUint * yUint;
                    if (xyUint / xUint != yUint) {
                        revert Errors.PRBMath_UD60x18_Gm_Overflow(x, y);
                    }
                    // We don't need to multiply the result by `UNIT` here because the x*y product picked up a factor of `UNIT`
                    // during multiplication. See the comments in {Common.sqrt}.
                    result = wrap(Common.sqrt(xyUint));
                }
            }
            /// @notice Calculates the inverse of x.
            ///
            /// @dev Notes:
            /// - The result is rounded toward zero.
            ///
            /// Requirements:
            /// - x must not be zero.
            ///
            /// @param x The UD60x18 number for which to calculate the inverse.
            /// @return result The inverse as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function inv(UD60x18 x) pure returns (UD60x18 result) {
                unchecked {
                    result = wrap(uUNIT_SQUARED / x.unwrap());
                }
            }
            /// @notice Calculates the natural logarithm of x using the following formula:
            ///
            /// $$
            /// ln{x} = log_2{x} / log_2{e}
            /// $$
            ///
            /// @dev Notes:
            /// - Refer to the notes in {log2}.
            /// - The precision isn't sufficiently fine-grained to return exactly `UNIT` when the input is `E`.
            ///
            /// Requirements:
            /// - Refer to the requirements in {log2}.
            ///
            /// @param x The UD60x18 number for which to calculate the natural logarithm.
            /// @return result The natural logarithm as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function ln(UD60x18 x) pure returns (UD60x18 result) {
                unchecked {
                    // Inline the fixed-point multiplication to save gas. This is overflow-safe because the maximum value that
                    // {log2} can return is ~196_205294292027477728.
                    result = wrap(log2(x).unwrap() * uUNIT / uLOG2_E);
                }
            }
            /// @notice Calculates the common logarithm of x using the following formula:
            ///
            /// $$
            /// log_{10}{x} = log_2{x} / log_2{10}
            /// $$
            ///
            /// However, if x is an exact power of ten, a hard coded value is returned.
            ///
            /// @dev Notes:
            /// - Refer to the notes in {log2}.
            ///
            /// Requirements:
            /// - Refer to the requirements in {log2}.
            ///
            /// @param x The UD60x18 number for which to calculate the common logarithm.
            /// @return result The common logarithm as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function log10(UD60x18 x) pure returns (UD60x18 result) {
                uint256 xUint = x.unwrap();
                if (xUint < uUNIT) {
                    revert Errors.PRBMath_UD60x18_Log_InputTooSmall(x);
                }
                // Note that the `mul` in this assembly block is the standard multiplication operation, not {UD60x18.mul}.
                // prettier-ignore
                assembly ("memory-safe") {
                    switch x
                    case 1 { result := mul(uUNIT, sub(0, 18)) }
                    case 10 { result := mul(uUNIT, sub(1, 18)) }
                    case 100 { result := mul(uUNIT, sub(2, 18)) }
                    case 1000 { result := mul(uUNIT, sub(3, 18)) }
                    case 10000 { result := mul(uUNIT, sub(4, 18)) }
                    case 100000 { result := mul(uUNIT, sub(5, 18)) }
                    case 1000000 { result := mul(uUNIT, sub(6, 18)) }
                    case 10000000 { result := mul(uUNIT, sub(7, 18)) }
                    case 100000000 { result := mul(uUNIT, sub(8, 18)) }
                    case 1000000000 { result := mul(uUNIT, sub(9, 18)) }
                    case 10000000000 { result := mul(uUNIT, sub(10, 18)) }
                    case 100000000000 { result := mul(uUNIT, sub(11, 18)) }
                    case 1000000000000 { result := mul(uUNIT, sub(12, 18)) }
                    case 10000000000000 { result := mul(uUNIT, sub(13, 18)) }
                    case 100000000000000 { result := mul(uUNIT, sub(14, 18)) }
                    case 1000000000000000 { result := mul(uUNIT, sub(15, 18)) }
                    case 10000000000000000 { result := mul(uUNIT, sub(16, 18)) }
                    case 100000000000000000 { result := mul(uUNIT, sub(17, 18)) }
                    case 1000000000000000000 { result := 0 }
                    case 10000000000000000000 { result := uUNIT }
                    case 100000000000000000000 { result := mul(uUNIT, 2) }
                    case 1000000000000000000000 { result := mul(uUNIT, 3) }
                    case 10000000000000000000000 { result := mul(uUNIT, 4) }
                    case 100000000000000000000000 { result := mul(uUNIT, 5) }
                    case 1000000000000000000000000 { result := mul(uUNIT, 6) }
                    case 10000000000000000000000000 { result := mul(uUNIT, 7) }
                    case 100000000000000000000000000 { result := mul(uUNIT, 8) }
                    case 1000000000000000000000000000 { result := mul(uUNIT, 9) }
                    case 10000000000000000000000000000 { result := mul(uUNIT, 10) }
                    case 100000000000000000000000000000 { result := mul(uUNIT, 11) }
                    case 1000000000000000000000000000000 { result := mul(uUNIT, 12) }
                    case 10000000000000000000000000000000 { result := mul(uUNIT, 13) }
                    case 100000000000000000000000000000000 { result := mul(uUNIT, 14) }
                    case 1000000000000000000000000000000000 { result := mul(uUNIT, 15) }
                    case 10000000000000000000000000000000000 { result := mul(uUNIT, 16) }
                    case 100000000000000000000000000000000000 { result := mul(uUNIT, 17) }
                    case 1000000000000000000000000000000000000 { result := mul(uUNIT, 18) }
                    case 10000000000000000000000000000000000000 { result := mul(uUNIT, 19) }
                    case 100000000000000000000000000000000000000 { result := mul(uUNIT, 20) }
                    case 1000000000000000000000000000000000000000 { result := mul(uUNIT, 21) }
                    case 10000000000000000000000000000000000000000 { result := mul(uUNIT, 22) }
                    case 100000000000000000000000000000000000000000 { result := mul(uUNIT, 23) }
                    case 1000000000000000000000000000000000000000000 { result := mul(uUNIT, 24) }
                    case 10000000000000000000000000000000000000000000 { result := mul(uUNIT, 25) }
                    case 100000000000000000000000000000000000000000000 { result := mul(uUNIT, 26) }
                    case 1000000000000000000000000000000000000000000000 { result := mul(uUNIT, 27) }
                    case 10000000000000000000000000000000000000000000000 { result := mul(uUNIT, 28) }
                    case 100000000000000000000000000000000000000000000000 { result := mul(uUNIT, 29) }
                    case 1000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 30) }
                    case 10000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 31) }
                    case 100000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 32) }
                    case 1000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 33) }
                    case 10000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 34) }
                    case 100000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 35) }
                    case 1000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 36) }
                    case 10000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 37) }
                    case 100000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 38) }
                    case 1000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 39) }
                    case 10000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 40) }
                    case 100000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 41) }
                    case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 42) }
                    case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 43) }
                    case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 44) }
                    case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 45) }
                    case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 46) }
                    case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 47) }
                    case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 48) }
                    case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 49) }
                    case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 50) }
                    case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 51) }
                    case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 52) }
                    case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 53) }
                    case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 54) }
                    case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 55) }
                    case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 56) }
                    case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 57) }
                    case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 58) }
                    case 100000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 59) }
                    default { result := uMAX_UD60x18 }
                }
                if (result.unwrap() == uMAX_UD60x18) {
                    unchecked {
                        // Inline the fixed-point division to save gas.
                        result = wrap(log2(x).unwrap() * uUNIT / uLOG2_10);
                    }
                }
            }
            /// @notice Calculates the binary logarithm of x using the iterative approximation algorithm:
            ///
            /// $$
            /// log_2{x} = n + log_2{y}, \\text{ where } y = x*2^{-n}, \\ y \\in [1, 2)
            /// $$
            ///
            /// For $0 \\leq x \\lt 1$, the input is inverted:
            ///
            /// $$
            /// log_2{x} = -log_2{\\frac{1}{x}}
            /// $$
            ///
            /// @dev See https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation
            ///
            /// Notes:
            /// - Due to the lossy precision of the iterative approximation, the results are not perfectly accurate to the last decimal.
            ///
            /// Requirements:
            /// - x ≥ UNIT
            ///
            /// @param x The UD60x18 number for which to calculate the binary logarithm.
            /// @return result The binary logarithm as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function log2(UD60x18 x) pure returns (UD60x18 result) {
                uint256 xUint = x.unwrap();
                if (xUint < uUNIT) {
                    revert Errors.PRBMath_UD60x18_Log_InputTooSmall(x);
                }
                unchecked {
                    // Calculate the integer part of the logarithm.
                    uint256 n = Common.msb(xUint / uUNIT);
                    // This is the integer part of the logarithm as a UD60x18 number. The operation can't overflow because n
                    // n is at most 255 and UNIT is 1e18.
                    uint256 resultUint = n * uUNIT;
                    // Calculate $y = x * 2^{-n}$.
                    uint256 y = xUint >> n;
                    // If y is the unit number, the fractional part is zero.
                    if (y == uUNIT) {
                        return wrap(resultUint);
                    }
                    // Calculate the fractional part via the iterative approximation.
                    // The `delta >>= 1` part is equivalent to `delta /= 2`, but shifting bits is more gas efficient.
                    uint256 DOUBLE_UNIT = 2e18;
                    for (uint256 delta = uHALF_UNIT; delta > 0; delta >>= 1) {
                        y = (y * y) / uUNIT;
                        // Is y^2 >= 2e18 and so in the range [2e18, 4e18)?
                        if (y >= DOUBLE_UNIT) {
                            // Add the 2^{-m} factor to the logarithm.
                            resultUint += delta;
                            // Halve y, which corresponds to z/2 in the Wikipedia article.
                            y >>= 1;
                        }
                    }
                    result = wrap(resultUint);
                }
            }
            /// @notice Multiplies two UD60x18 numbers together, returning a new UD60x18 number.
            ///
            /// @dev Uses {Common.mulDiv} to enable overflow-safe multiplication and division.
            ///
            /// Notes:
            /// - Refer to the notes in {Common.mulDiv}.
            ///
            /// Requirements:
            /// - Refer to the requirements in {Common.mulDiv}.
            ///
            /// @dev See the documentation in {Common.mulDiv18}.
            /// @param x The multiplicand as a UD60x18 number.
            /// @param y The multiplier as a UD60x18 number.
            /// @return result The product as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function mul(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                result = wrap(Common.mulDiv18(x.unwrap(), y.unwrap()));
            }
            /// @notice Raises x to the power of y.
            ///
            /// For $1 \\leq x \\leq \\infty$, the following standard formula is used:
            ///
            /// $$
            /// x^y = 2^{log_2{x} * y}
            /// $$
            ///
            /// For $0 \\leq x \\lt 1$, since the unsigned {log2} is undefined, an equivalent formula is used:
            ///
            /// $$
            /// i = \\frac{1}{x}
            /// w = 2^{log_2{i} * y}
            /// x^y = \\frac{1}{w}
            /// $$
            ///
            /// @dev Notes:
            /// - Refer to the notes in {log2} and {mul}.
            /// - Returns `UNIT` for 0^0.
            /// - It may not perform well with very small values of x. Consider using SD59x18 as an alternative.
            ///
            /// Requirements:
            /// - Refer to the requirements in {exp2}, {log2}, and {mul}.
            ///
            /// @param x The base as a UD60x18 number.
            /// @param y The exponent as a UD60x18 number.
            /// @return result The result as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function pow(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                uint256 xUint = x.unwrap();
                uint256 yUint = y.unwrap();
                // If both x and y are zero, the result is `UNIT`. If just x is zero, the result is always zero.
                if (xUint == 0) {
                    return yUint == 0 ? UNIT : ZERO;
                }
                // If x is `UNIT`, the result is always `UNIT`.
                else if (xUint == uUNIT) {
                    return UNIT;
                }
                // If y is zero, the result is always `UNIT`.
                if (yUint == 0) {
                    return UNIT;
                }
                // If y is `UNIT`, the result is always x.
                else if (yUint == uUNIT) {
                    return x;
                }
                // If x is > UNIT, use the standard formula.
                if (xUint > uUNIT) {
                    result = exp2(mul(log2(x), y));
                }
                // Conversely, if x < UNIT, use the equivalent formula.
                else {
                    UD60x18 i = wrap(uUNIT_SQUARED / xUint);
                    UD60x18 w = exp2(mul(log2(i), y));
                    result = wrap(uUNIT_SQUARED / w.unwrap());
                }
            }
            /// @notice Raises x (a UD60x18 number) to the power y (an unsigned basic integer) using the well-known
            /// algorithm "exponentiation by squaring".
            ///
            /// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring.
            ///
            /// Notes:
            /// - Refer to the notes in {Common.mulDiv18}.
            /// - Returns `UNIT` for 0^0.
            ///
            /// Requirements:
            /// - The result must fit in UD60x18.
            ///
            /// @param x The base as a UD60x18 number.
            /// @param y The exponent as a uint256.
            /// @return result The result as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function powu(UD60x18 x, uint256 y) pure returns (UD60x18 result) {
                // Calculate the first iteration of the loop in advance.
                uint256 xUint = x.unwrap();
                uint256 resultUint = y & 1 > 0 ? xUint : uUNIT;
                // Equivalent to `for(y /= 2; y > 0; y /= 2)`.
                for (y >>= 1; y > 0; y >>= 1) {
                    xUint = Common.mulDiv18(xUint, xUint);
                    // Equivalent to `y % 2 == 1`.
                    if (y & 1 > 0) {
                        resultUint = Common.mulDiv18(resultUint, xUint);
                    }
                }
                result = wrap(resultUint);
            }
            /// @notice Calculates the square root of x using the Babylonian method.
            ///
            /// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
            ///
            /// Notes:
            /// - The result is rounded toward zero.
            ///
            /// Requirements:
            /// - x ≤ MAX_UD60x18 / UNIT
            ///
            /// @param x The UD60x18 number for which to calculate the square root.
            /// @return result The result as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function sqrt(UD60x18 x) pure returns (UD60x18 result) {
                uint256 xUint = x.unwrap();
                unchecked {
                    if (xUint > uMAX_UD60x18 / uUNIT) {
                        revert Errors.PRBMath_UD60x18_Sqrt_Overflow(x);
                    }
                    // Multiply x by `UNIT` to account for the factor of `UNIT` picked up when multiplying two UD60x18 numbers.
                    // In this case, the two numbers are both the square root.
                    result = wrap(Common.sqrt(xUint * uUNIT));
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "./Casting.sol" as Casting;
            import "./Helpers.sol" as Helpers;
            import "./Math.sol" as Math;
            /// @notice The unsigned 60.18-decimal fixed-point number representation, which can have up to 60 digits and up to 18
            /// decimals. The values of this are bound by the minimum and the maximum values permitted by the Solidity type uint256.
            /// @dev The value type is defined here so it can be imported in all other files.
            type UD60x18 is uint256;
            /*//////////////////////////////////////////////////////////////////////////
                                                CASTING
            //////////////////////////////////////////////////////////////////////////*/
            using {
                Casting.intoSD1x18,
                Casting.intoSD21x18,
                Casting.intoSD59x18,
                Casting.intoUD2x18,
                Casting.intoUD21x18,
                Casting.intoUint128,
                Casting.intoUint256,
                Casting.intoUint40,
                Casting.unwrap
            } for UD60x18 global;
            /*//////////////////////////////////////////////////////////////////////////
                                        MATHEMATICAL FUNCTIONS
            //////////////////////////////////////////////////////////////////////////*/
            // The global "using for" directive makes the functions in this library callable on the UD60x18 type.
            using {
                Math.avg,
                Math.ceil,
                Math.div,
                Math.exp,
                Math.exp2,
                Math.floor,
                Math.frac,
                Math.gm,
                Math.inv,
                Math.ln,
                Math.log10,
                Math.log2,
                Math.mul,
                Math.pow,
                Math.powu,
                Math.sqrt
            } for UD60x18 global;
            /*//////////////////////////////////////////////////////////////////////////
                                            HELPER FUNCTIONS
            //////////////////////////////////////////////////////////////////////////*/
            // The global "using for" directive makes the functions in this library callable on the UD60x18 type.
            using {
                Helpers.add,
                Helpers.and,
                Helpers.eq,
                Helpers.gt,
                Helpers.gte,
                Helpers.isZero,
                Helpers.lshift,
                Helpers.lt,
                Helpers.lte,
                Helpers.mod,
                Helpers.neq,
                Helpers.not,
                Helpers.or,
                Helpers.rshift,
                Helpers.sub,
                Helpers.uncheckedAdd,
                Helpers.uncheckedSub,
                Helpers.xor
            } for UD60x18 global;
            /*//////////////////////////////////////////////////////////////////////////
                                                OPERATORS
            //////////////////////////////////////////////////////////////////////////*/
            // The global "using for" directive makes it possible to use these operators on the UD60x18 type.
            using {
                Helpers.add as +,
                Helpers.and2 as &,
                Math.div as /,
                Helpers.eq as ==,
                Helpers.gt as >,
                Helpers.gte as >=,
                Helpers.lt as <,
                Helpers.lte as <=,
                Helpers.or as |,
                Helpers.mod as %,
                Math.mul as *,
                Helpers.neq as !=,
                Helpers.not as ~,
                Helpers.sub as -,
                Helpers.xor as ^
            } for UD60x18 global;
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
            pragma solidity ^0.8.20;
            /**
             * @dev Interface of the ERC-20 standard as defined in the ERC.
             */
            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 value of tokens in existence.
                 */
                function totalSupply() external view returns (uint256);
                /**
                 * @dev Returns the value of tokens owned by `account`.
                 */
                function balanceOf(address account) external view returns (uint256);
                /**
                 * @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);
                /**
                 * @dev Moves a `value` amount of tokens from `from` to `to` using the
                 * allowance mechanism. `value` 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 value) external returns (bool);
            }
            // SPDX-License-Identifier: GPL-3.0-or-later
            pragma solidity >=0.8.19;
            import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
            import { IERC721Metadata } from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
            import { Lockup } from "../types/DataTypes.sol";
            import { ISablierV2Base } from "./ISablierV2Base.sol";
            import { ISablierV2NFTDescriptor } from "./ISablierV2NFTDescriptor.sol";
            /// @title ISablierV2Lockup
            /// @notice Common logic between all Sablier V2 Lockup streaming contracts.
            interface ISablierV2Lockup is
                ISablierV2Base, // 1 inherited component
                IERC721Metadata // 2 inherited components
            {
                /*//////////////////////////////////////////////////////////////////////////
                                                   EVENTS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Emitted when a stream is canceled.
                /// @param streamId The id of the stream.
                /// @param sender The address of the stream's sender.
                /// @param recipient The address of the stream's recipient.
                /// @param asset The contract address of the ERC-20 asset used for streaming.
                /// @param senderAmount The amount of assets refunded to the stream's sender, denoted in units of the asset's
                /// decimals.
                /// @param recipientAmount The amount of assets left for the stream's recipient to withdraw, denoted in units of the
                /// asset's decimals.
                event CancelLockupStream(
                    uint256 streamId,
                    address indexed sender,
                    address indexed recipient,
                    IERC20 indexed asset,
                    uint128 senderAmount,
                    uint128 recipientAmount
                );
                /// @notice Emitted when a sender gives up the right to cancel a stream.
                /// @param streamId The id of the stream.
                event RenounceLockupStream(uint256 indexed streamId);
                /// @notice Emitted when the admin sets a new NFT descriptor contract.
                /// @param admin The address of the current contract admin.
                /// @param oldNFTDescriptor The address of the old NFT descriptor contract.
                /// @param newNFTDescriptor The address of the new NFT descriptor contract.
                event SetNFTDescriptor(
                    address indexed admin, ISablierV2NFTDescriptor oldNFTDescriptor, ISablierV2NFTDescriptor newNFTDescriptor
                );
                /// @notice Emitted when assets are withdrawn from a stream.
                /// @param streamId The id of the stream.
                /// @param to The address that has received the withdrawn assets.
                /// @param asset The contract address of the ERC-20 asset used for streaming.
                /// @param amount The amount of assets withdrawn, denoted in units of the asset's decimals.
                event WithdrawFromLockupStream(uint256 indexed streamId, address indexed to, IERC20 indexed asset, uint128 amount);
                /*//////////////////////////////////////////////////////////////////////////
                                             CONSTANT FUNCTIONS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Retrieves the address of the ERC-20 asset used for streaming.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function getAsset(uint256 streamId) external view returns (IERC20 asset);
                /// @notice Retrieves the amount deposited in the stream, denoted in units of the asset's decimals.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function getDepositedAmount(uint256 streamId) external view returns (uint128 depositedAmount);
                /// @notice Retrieves the stream's end time, which is a Unix timestamp.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function getEndTime(uint256 streamId) external view returns (uint40 endTime);
                /// @notice Retrieves the stream's recipient.
                /// @dev Reverts if the NFT has been burned.
                /// @param streamId The stream id for the query.
                function getRecipient(uint256 streamId) external view returns (address recipient);
                /// @notice Retrieves the amount refunded to the sender after a cancellation, denoted in units of the asset's
                /// decimals. This amount is always zero unless the stream was canceled.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function getRefundedAmount(uint256 streamId) external view returns (uint128 refundedAmount);
                /// @notice Retrieves the stream's sender.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function getSender(uint256 streamId) external view returns (address sender);
                /// @notice Retrieves the stream's start time, which is a Unix timestamp.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function getStartTime(uint256 streamId) external view returns (uint40 startTime);
                /// @notice Retrieves the amount withdrawn from the stream, denoted in units of the asset's decimals.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function getWithdrawnAmount(uint256 streamId) external view returns (uint128 withdrawnAmount);
                /// @notice Retrieves a flag indicating whether the stream can be canceled. When the stream is cold, this
                /// flag is always `false`.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function isCancelable(uint256 streamId) external view returns (bool result);
                /// @notice Retrieves a flag indicating whether the stream is cold, i.e. settled, canceled, or depleted.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function isCold(uint256 streamId) external view returns (bool result);
                /// @notice Retrieves a flag indicating whether the stream is depleted.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function isDepleted(uint256 streamId) external view returns (bool result);
                /// @notice Retrieves a flag indicating whether the stream exists.
                /// @dev Does not revert if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function isStream(uint256 streamId) external view returns (bool result);
                /// @notice Retrieves a flag indicating whether the stream NFT can be transferred.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function isTransferable(uint256 streamId) external view returns (bool result);
                /// @notice Retrieves a flag indicating whether the stream is warm, i.e. either pending or streaming.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function isWarm(uint256 streamId) external view returns (bool result);
                /// @notice Counter for stream ids, used in the create functions.
                function nextStreamId() external view returns (uint256);
                /// @notice Calculates the amount that the sender would be refunded if the stream were canceled, denoted in units
                /// of the asset's decimals.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function refundableAmountOf(uint256 streamId) external view returns (uint128 refundableAmount);
                /// @notice Retrieves the stream's status.
                /// @param streamId The stream id for the query.
                function statusOf(uint256 streamId) external view returns (Lockup.Status status);
                /// @notice Calculates the amount streamed to the recipient, denoted in units of the asset's decimals.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function streamedAmountOf(uint256 streamId) external view returns (uint128 streamedAmount);
                /// @notice Retrieves a flag indicating whether the stream was canceled.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function wasCanceled(uint256 streamId) external view returns (bool result);
                /// @notice Calculates the amount that the recipient can withdraw from the stream, denoted in units of the asset's
                /// decimals.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function withdrawableAmountOf(uint256 streamId) external view returns (uint128 withdrawableAmount);
                /*//////////////////////////////////////////////////////////////////////////
                                           NON-CONSTANT FUNCTIONS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Burns the NFT associated with the stream.
                ///
                /// @dev Emits a {Transfer} event.
                ///
                /// Requirements:
                /// - Must not be delegate called.
                /// - `streamId` must reference a depleted stream.
                /// - The NFT must exist.
                /// - `msg.sender` must be either the NFT owner or an approved third party.
                ///
                /// @param streamId The id of the stream NFT to burn.
                function burn(uint256 streamId) external;
                /// @notice Cancels the stream and refunds any remaining assets to the sender.
                ///
                /// @dev Emits a {Transfer}, {CancelLockupStream}, and {MetadataUpdate} event.
                ///
                /// Notes:
                /// - If there any assets left for the recipient to withdraw, the stream is marked as canceled. Otherwise, the
                /// stream is marked as depleted.
                /// - This function attempts to invoke a hook on the recipient, if the resolved address is a contract.
                ///
                /// Requirements:
                /// - Must not be delegate called.
                /// - The stream must be warm and cancelable.
                /// - `msg.sender` must be the stream's sender.
                ///
                /// @param streamId The id of the stream to cancel.
                function cancel(uint256 streamId) external;
                /// @notice Cancels multiple streams and refunds any remaining assets to the sender.
                ///
                /// @dev Emits multiple {Transfer}, {CancelLockupStream}, and {MetadataUpdate} events.
                ///
                /// Notes:
                /// - Refer to the notes in {cancel}.
                ///
                /// Requirements:
                /// - All requirements from {cancel} must be met for each stream.
                ///
                /// @param streamIds The ids of the streams to cancel.
                function cancelMultiple(uint256[] calldata streamIds) external;
                /// @notice Removes the right of the stream's sender to cancel the stream.
                ///
                /// @dev Emits a {RenounceLockupStream} and {MetadataUpdate} event.
                ///
                /// Notes:
                /// - This is an irreversible operation.
                /// - This function attempts to invoke a hook on the stream's recipient, provided that the recipient is a contract.
                ///
                /// Requirements:
                /// - Must not be delegate called.
                /// - `streamId` must reference a warm stream.
                /// - `msg.sender` must be the stream's sender.
                /// - The stream must be cancelable.
                ///
                /// @param streamId The id of the stream to renounce.
                function renounce(uint256 streamId) external;
                /// @notice Sets a new NFT descriptor contract, which produces the URI describing the Sablier stream NFTs.
                ///
                /// @dev Emits a {SetNFTDescriptor} and {BatchMetadataUpdate} event.
                ///
                /// Notes:
                /// - Does not revert if the NFT descriptor is the same.
                ///
                /// Requirements:
                /// - `msg.sender` must be the contract admin.
                ///
                /// @param newNFTDescriptor The address of the new NFT descriptor contract.
                function setNFTDescriptor(ISablierV2NFTDescriptor newNFTDescriptor) external;
                /// @notice Withdraws the provided amount of assets from the stream to the `to` address.
                ///
                /// @dev Emits a {Transfer}, {WithdrawFromLockupStream}, and {MetadataUpdate} event.
                ///
                /// Notes:
                /// - This function attempts to invoke a hook on the stream's recipient, provided that the recipient is a contract
                /// and `msg.sender` is either the sender or an approved operator.
                ///
                /// Requirements:
                /// - Must not be delegate called.
                /// - `streamId` must not reference a null or depleted stream.
                /// - `msg.sender` must be the stream's sender, the stream's recipient or an approved third party.
                /// - `to` must be the recipient if `msg.sender` is the stream's sender.
                /// - `to` must not be the zero address.
                /// - `amount` must be greater than zero and must not exceed the withdrawable amount.
                ///
                /// @param streamId The id of the stream to withdraw from.
                /// @param to The address receiving the withdrawn assets.
                /// @param amount The amount to withdraw, denoted in units of the asset's decimals.
                function withdraw(uint256 streamId, address to, uint128 amount) external;
                /// @notice Withdraws the maximum withdrawable amount from the stream to the provided address `to`.
                ///
                /// @dev Emits a {Transfer}, {WithdrawFromLockupStream}, and {MetadataUpdate} event.
                ///
                /// Notes:
                /// - Refer to the notes in {withdraw}.
                ///
                /// Requirements:
                /// - Refer to the requirements in {withdraw}.
                ///
                /// @param streamId The id of the stream to withdraw from.
                /// @param to The address receiving the withdrawn assets.
                function withdrawMax(uint256 streamId, address to) external;
                /// @notice Withdraws the maximum withdrawable amount from the stream to the current recipient, and transfers the
                /// NFT to `newRecipient`.
                ///
                /// @dev Emits a {WithdrawFromLockupStream} and a {Transfer} event.
                ///
                /// Notes:
                /// - If the withdrawable amount is zero, the withdrawal is skipped.
                /// - Refer to the notes in {withdraw}.
                ///
                /// Requirements:
                /// - `msg.sender` must be the stream's recipient.
                /// - Refer to the requirements in {withdraw}.
                /// - Refer to the requirements in {IERC721.transferFrom}.
                ///
                /// @param streamId The id of the stream NFT to transfer.
                /// @param newRecipient The address of the new owner of the stream NFT.
                function withdrawMaxAndTransfer(uint256 streamId, address newRecipient) external;
                /// @notice Withdraws assets from streams to the provided address `to`.
                ///
                /// @dev Emits multiple {Transfer}, {WithdrawFromLockupStream}, and {MetadataUpdate} events.
                ///
                /// Notes:
                /// - This function attempts to call a hook on the recipient of each stream, unless `msg.sender` is the recipient.
                ///
                /// Requirements:
                /// - All requirements from {withdraw} must be met for each stream.
                /// - There must be an equal number of `streamIds` and `amounts`.
                ///
                /// @param streamIds The ids of the streams to withdraw from.
                /// @param to The address receiving the withdrawn assets.
                /// @param amounts The amounts to withdraw, denoted in units of the asset's decimals.
                function withdrawMultiple(uint256[] calldata streamIds, address to, uint128[] calldata amounts) external;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            /*
            ██████╗ ██████╗ ██████╗ ███╗   ███╗ █████╗ ████████╗██╗  ██╗
            ██╔══██╗██╔══██╗██╔══██╗████╗ ████║██╔══██╗╚══██╔══╝██║  ██║
            ██████╔╝██████╔╝██████╔╝██╔████╔██║███████║   ██║   ███████║
            ██╔═══╝ ██╔══██╗██╔══██╗██║╚██╔╝██║██╔══██║   ██║   ██╔══██║
            ██║     ██║  ██║██████╔╝██║ ╚═╝ ██║██║  ██║   ██║   ██║  ██║
            ╚═╝     ╚═╝  ╚═╝╚═════╝ ╚═╝     ╚═╝╚═╝  ╚═╝   ╚═╝   ╚═╝  ╚═╝
            ██╗   ██╗██████╗ ██████╗ ██╗  ██╗ ██╗ █████╗
            ██║   ██║██╔══██╗╚════██╗╚██╗██╔╝███║██╔══██╗
            ██║   ██║██║  ██║ █████╔╝ ╚███╔╝ ╚██║╚█████╔╝
            ██║   ██║██║  ██║██╔═══╝  ██╔██╗  ██║██╔══██╗
            ╚██████╔╝██████╔╝███████╗██╔╝ ██╗ ██║╚█████╔╝
             ╚═════╝ ╚═════╝ ╚══════╝╚═╝  ╚═╝ ╚═╝ ╚════╝
            */
            import "./ud2x18/Casting.sol";
            import "./ud2x18/Constants.sol";
            import "./ud2x18/Errors.sol";
            import "./ud2x18/ValueType.sol";
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            // Common.sol
            //
            // Common mathematical functions used in both SD59x18 and UD60x18. Note that these global functions do not
            // always operate with SD59x18 and UD60x18 numbers.
            /*//////////////////////////////////////////////////////////////////////////
                                            CUSTOM ERRORS
            //////////////////////////////////////////////////////////////////////////*/
            /// @notice Thrown when the resultant value in {mulDiv} overflows uint256.
            error PRBMath_MulDiv_Overflow(uint256 x, uint256 y, uint256 denominator);
            /// @notice Thrown when the resultant value in {mulDiv18} overflows uint256.
            error PRBMath_MulDiv18_Overflow(uint256 x, uint256 y);
            /// @notice Thrown when one of the inputs passed to {mulDivSigned} is `type(int256).min`.
            error PRBMath_MulDivSigned_InputTooSmall();
            /// @notice Thrown when the resultant value in {mulDivSigned} overflows int256.
            error PRBMath_MulDivSigned_Overflow(int256 x, int256 y);
            /*//////////////////////////////////////////////////////////////////////////
                                                CONSTANTS
            //////////////////////////////////////////////////////////////////////////*/
            /// @dev The maximum value a uint128 number can have.
            uint128 constant MAX_UINT128 = type(uint128).max;
            /// @dev The maximum value a uint40 number can have.
            uint40 constant MAX_UINT40 = type(uint40).max;
            /// @dev The maximum value a uint64 number can have.
            uint64 constant MAX_UINT64 = type(uint64).max;
            /// @dev The unit number, which the decimal precision of the fixed-point types.
            uint256 constant UNIT = 1e18;
            /// @dev The unit number inverted mod 2^256.
            uint256 constant UNIT_INVERSE = 78156646155174841979727994598816262306175212592076161876661_508869554232690281;
            /// @dev The the largest power of two that divides the decimal value of `UNIT`. The logarithm of this value is the least significant
            /// bit in the binary representation of `UNIT`.
            uint256 constant UNIT_LPOTD = 262144;
            /*//////////////////////////////////////////////////////////////////////////
                                                FUNCTIONS
            //////////////////////////////////////////////////////////////////////////*/
            /// @notice Calculates the binary exponent of x using the binary fraction method.
            /// @dev Has to use 192.64-bit fixed-point numbers. See https://ethereum.stackexchange.com/a/96594/24693.
            /// @param x The exponent as an unsigned 192.64-bit fixed-point number.
            /// @return result The result as an unsigned 60.18-decimal fixed-point number.
            /// @custom:smtchecker abstract-function-nondet
            function exp2(uint256 x) pure returns (uint256 result) {
                unchecked {
                    // Start from 0.5 in the 192.64-bit fixed-point format.
                    result = 0x800000000000000000000000000000000000000000000000;
                    // The following logic multiplies the result by $\\sqrt{2^{-i}}$ when the bit at position i is 1. Key points:
                    //
                    // 1. Intermediate results will not overflow, as the starting point is 2^191 and all magic factors are under 2^65.
                    // 2. The rationale for organizing the if statements into groups of 8 is gas savings. If the result of performing
                    // a bitwise AND operation between x and any value in the array [0x80; 0x40; 0x20; 0x10; 0x08; 0x04; 0x02; 0x01] is 1,
                    // we know that `x & 0xFF` is also 1.
                    if (x & 0xFF00000000000000 > 0) {
                        if (x & 0x8000000000000000 > 0) {
                            result = (result * 0x16A09E667F3BCC909) >> 64;
                        }
                        if (x & 0x4000000000000000 > 0) {
                            result = (result * 0x1306FE0A31B7152DF) >> 64;
                        }
                        if (x & 0x2000000000000000 > 0) {
                            result = (result * 0x1172B83C7D517ADCE) >> 64;
                        }
                        if (x & 0x1000000000000000 > 0) {
                            result = (result * 0x10B5586CF9890F62A) >> 64;
                        }
                        if (x & 0x800000000000000 > 0) {
                            result = (result * 0x1059B0D31585743AE) >> 64;
                        }
                        if (x & 0x400000000000000 > 0) {
                            result = (result * 0x102C9A3E778060EE7) >> 64;
                        }
                        if (x & 0x200000000000000 > 0) {
                            result = (result * 0x10163DA9FB33356D8) >> 64;
                        }
                        if (x & 0x100000000000000 > 0) {
                            result = (result * 0x100B1AFA5ABCBED61) >> 64;
                        }
                    }
                    if (x & 0xFF000000000000 > 0) {
                        if (x & 0x80000000000000 > 0) {
                            result = (result * 0x10058C86DA1C09EA2) >> 64;
                        }
                        if (x & 0x40000000000000 > 0) {
                            result = (result * 0x1002C605E2E8CEC50) >> 64;
                        }
                        if (x & 0x20000000000000 > 0) {
                            result = (result * 0x100162F3904051FA1) >> 64;
                        }
                        if (x & 0x10000000000000 > 0) {
                            result = (result * 0x1000B175EFFDC76BA) >> 64;
                        }
                        if (x & 0x8000000000000 > 0) {
                            result = (result * 0x100058BA01FB9F96D) >> 64;
                        }
                        if (x & 0x4000000000000 > 0) {
                            result = (result * 0x10002C5CC37DA9492) >> 64;
                        }
                        if (x & 0x2000000000000 > 0) {
                            result = (result * 0x1000162E525EE0547) >> 64;
                        }
                        if (x & 0x1000000000000 > 0) {
                            result = (result * 0x10000B17255775C04) >> 64;
                        }
                    }
                    if (x & 0xFF0000000000 > 0) {
                        if (x & 0x800000000000 > 0) {
                            result = (result * 0x1000058B91B5BC9AE) >> 64;
                        }
                        if (x & 0x400000000000 > 0) {
                            result = (result * 0x100002C5C89D5EC6D) >> 64;
                        }
                        if (x & 0x200000000000 > 0) {
                            result = (result * 0x10000162E43F4F831) >> 64;
                        }
                        if (x & 0x100000000000 > 0) {
                            result = (result * 0x100000B1721BCFC9A) >> 64;
                        }
                        if (x & 0x80000000000 > 0) {
                            result = (result * 0x10000058B90CF1E6E) >> 64;
                        }
                        if (x & 0x40000000000 > 0) {
                            result = (result * 0x1000002C5C863B73F) >> 64;
                        }
                        if (x & 0x20000000000 > 0) {
                            result = (result * 0x100000162E430E5A2) >> 64;
                        }
                        if (x & 0x10000000000 > 0) {
                            result = (result * 0x1000000B172183551) >> 64;
                        }
                    }
                    if (x & 0xFF00000000 > 0) {
                        if (x & 0x8000000000 > 0) {
                            result = (result * 0x100000058B90C0B49) >> 64;
                        }
                        if (x & 0x4000000000 > 0) {
                            result = (result * 0x10000002C5C8601CC) >> 64;
                        }
                        if (x & 0x2000000000 > 0) {
                            result = (result * 0x1000000162E42FFF0) >> 64;
                        }
                        if (x & 0x1000000000 > 0) {
                            result = (result * 0x10000000B17217FBB) >> 64;
                        }
                        if (x & 0x800000000 > 0) {
                            result = (result * 0x1000000058B90BFCE) >> 64;
                        }
                        if (x & 0x400000000 > 0) {
                            result = (result * 0x100000002C5C85FE3) >> 64;
                        }
                        if (x & 0x200000000 > 0) {
                            result = (result * 0x10000000162E42FF1) >> 64;
                        }
                        if (x & 0x100000000 > 0) {
                            result = (result * 0x100000000B17217F8) >> 64;
                        }
                    }
                    if (x & 0xFF000000 > 0) {
                        if (x & 0x80000000 > 0) {
                            result = (result * 0x10000000058B90BFC) >> 64;
                        }
                        if (x & 0x40000000 > 0) {
                            result = (result * 0x1000000002C5C85FE) >> 64;
                        }
                        if (x & 0x20000000 > 0) {
                            result = (result * 0x100000000162E42FF) >> 64;
                        }
                        if (x & 0x10000000 > 0) {
                            result = (result * 0x1000000000B17217F) >> 64;
                        }
                        if (x & 0x8000000 > 0) {
                            result = (result * 0x100000000058B90C0) >> 64;
                        }
                        if (x & 0x4000000 > 0) {
                            result = (result * 0x10000000002C5C860) >> 64;
                        }
                        if (x & 0x2000000 > 0) {
                            result = (result * 0x1000000000162E430) >> 64;
                        }
                        if (x & 0x1000000 > 0) {
                            result = (result * 0x10000000000B17218) >> 64;
                        }
                    }
                    if (x & 0xFF0000 > 0) {
                        if (x & 0x800000 > 0) {
                            result = (result * 0x1000000000058B90C) >> 64;
                        }
                        if (x & 0x400000 > 0) {
                            result = (result * 0x100000000002C5C86) >> 64;
                        }
                        if (x & 0x200000 > 0) {
                            result = (result * 0x10000000000162E43) >> 64;
                        }
                        if (x & 0x100000 > 0) {
                            result = (result * 0x100000000000B1721) >> 64;
                        }
                        if (x & 0x80000 > 0) {
                            result = (result * 0x10000000000058B91) >> 64;
                        }
                        if (x & 0x40000 > 0) {
                            result = (result * 0x1000000000002C5C8) >> 64;
                        }
                        if (x & 0x20000 > 0) {
                            result = (result * 0x100000000000162E4) >> 64;
                        }
                        if (x & 0x10000 > 0) {
                            result = (result * 0x1000000000000B172) >> 64;
                        }
                    }
                    if (x & 0xFF00 > 0) {
                        if (x & 0x8000 > 0) {
                            result = (result * 0x100000000000058B9) >> 64;
                        }
                        if (x & 0x4000 > 0) {
                            result = (result * 0x10000000000002C5D) >> 64;
                        }
                        if (x & 0x2000 > 0) {
                            result = (result * 0x1000000000000162E) >> 64;
                        }
                        if (x & 0x1000 > 0) {
                            result = (result * 0x10000000000000B17) >> 64;
                        }
                        if (x & 0x800 > 0) {
                            result = (result * 0x1000000000000058C) >> 64;
                        }
                        if (x & 0x400 > 0) {
                            result = (result * 0x100000000000002C6) >> 64;
                        }
                        if (x & 0x200 > 0) {
                            result = (result * 0x10000000000000163) >> 64;
                        }
                        if (x & 0x100 > 0) {
                            result = (result * 0x100000000000000B1) >> 64;
                        }
                    }
                    if (x & 0xFF > 0) {
                        if (x & 0x80 > 0) {
                            result = (result * 0x10000000000000059) >> 64;
                        }
                        if (x & 0x40 > 0) {
                            result = (result * 0x1000000000000002C) >> 64;
                        }
                        if (x & 0x20 > 0) {
                            result = (result * 0x10000000000000016) >> 64;
                        }
                        if (x & 0x10 > 0) {
                            result = (result * 0x1000000000000000B) >> 64;
                        }
                        if (x & 0x8 > 0) {
                            result = (result * 0x10000000000000006) >> 64;
                        }
                        if (x & 0x4 > 0) {
                            result = (result * 0x10000000000000003) >> 64;
                        }
                        if (x & 0x2 > 0) {
                            result = (result * 0x10000000000000001) >> 64;
                        }
                        if (x & 0x1 > 0) {
                            result = (result * 0x10000000000000001) >> 64;
                        }
                    }
                    // In the code snippet below, two operations are executed simultaneously:
                    //
                    // 1. The result is multiplied by $(2^n + 1)$, where $2^n$ represents the integer part, and the additional 1
                    // accounts for the initial guess of 0.5. This is achieved by subtracting from 191 instead of 192.
                    // 2. The result is then converted to an unsigned 60.18-decimal fixed-point format.
                    //
                    // The underlying logic is based on the relationship $2^{191-ip} = 2^{ip} / 2^{191}$, where $ip$ denotes the,
                    // integer part, $2^n$.
                    result *= UNIT;
                    result >>= (191 - (x >> 64));
                }
            }
            /// @notice Finds the zero-based index of the first 1 in the binary representation of x.
            ///
            /// @dev See the note on "msb" in this Wikipedia article: https://en.wikipedia.org/wiki/Find_first_set
            ///
            /// Each step in this implementation is equivalent to this high-level code:
            ///
            /// ```solidity
            /// if (x >= 2 ** 128) {
            ///     x >>= 128;
            ///     result += 128;
            /// }
            /// ```
            ///
            /// Where 128 is replaced with each respective power of two factor. See the full high-level implementation here:
            /// https://gist.github.com/PaulRBerg/f932f8693f2733e30c4d479e8e980948
            ///
            /// The Yul instructions used below are:
            ///
            /// - "gt" is "greater than"
            /// - "or" is the OR bitwise operator
            /// - "shl" is "shift left"
            /// - "shr" is "shift right"
            ///
            /// @param x The uint256 number for which to find the index of the most significant bit.
            /// @return result The index of the most significant bit as a uint256.
            /// @custom:smtchecker abstract-function-nondet
            function msb(uint256 x) pure returns (uint256 result) {
                // 2^128
                assembly ("memory-safe") {
                    let factor := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
                    x := shr(factor, x)
                    result := or(result, factor)
                }
                // 2^64
                assembly ("memory-safe") {
                    let factor := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))
                    x := shr(factor, x)
                    result := or(result, factor)
                }
                // 2^32
                assembly ("memory-safe") {
                    let factor := shl(5, gt(x, 0xFFFFFFFF))
                    x := shr(factor, x)
                    result := or(result, factor)
                }
                // 2^16
                assembly ("memory-safe") {
                    let factor := shl(4, gt(x, 0xFFFF))
                    x := shr(factor, x)
                    result := or(result, factor)
                }
                // 2^8
                assembly ("memory-safe") {
                    let factor := shl(3, gt(x, 0xFF))
                    x := shr(factor, x)
                    result := or(result, factor)
                }
                // 2^4
                assembly ("memory-safe") {
                    let factor := shl(2, gt(x, 0xF))
                    x := shr(factor, x)
                    result := or(result, factor)
                }
                // 2^2
                assembly ("memory-safe") {
                    let factor := shl(1, gt(x, 0x3))
                    x := shr(factor, x)
                    result := or(result, factor)
                }
                // 2^1
                // No need to shift x any more.
                assembly ("memory-safe") {
                    let factor := gt(x, 0x1)
                    result := or(result, factor)
                }
            }
            /// @notice Calculates x*y÷denominator with 512-bit precision.
            ///
            /// @dev Credits to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv.
            ///
            /// Notes:
            /// - The result is rounded toward zero.
            ///
            /// Requirements:
            /// - The denominator must not be zero.
            /// - The result must fit in uint256.
            ///
            /// @param x The multiplicand as a uint256.
            /// @param y The multiplier as a uint256.
            /// @param denominator The divisor as a uint256.
            /// @return result The result as a uint256.
            /// @custom:smtchecker abstract-function-nondet
            function mulDiv(uint256 x, uint256 y, uint256 denominator) pure returns (uint256 result) {
                // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
                // use the Chinese Remainder Theorem to reconstruct the 512-bit result. The result is stored in two 256
                // variables such that product = prod1 * 2^256 + prod0.
                uint256 prod0; // Least significant 256 bits of the product
                uint256 prod1; // Most significant 256 bits of the product
                assembly ("memory-safe") {
                    let mm := mulmod(x, y, not(0))
                    prod0 := mul(x, y)
                    prod1 := sub(sub(mm, prod0), lt(mm, prod0))
                }
                // Handle non-overflow cases, 256 by 256 division.
                if (prod1 == 0) {
                    unchecked {
                        return prod0 / denominator;
                    }
                }
                // Make sure the result is less than 2^256. Also prevents denominator == 0.
                if (prod1 >= denominator) {
                    revert PRBMath_MulDiv_Overflow(x, y, denominator);
                }
                ////////////////////////////////////////////////////////////////////////////
                // 512 by 256 division
                ////////////////////////////////////////////////////////////////////////////
                // Make division exact by subtracting the remainder from [prod1 prod0].
                uint256 remainder;
                assembly ("memory-safe") {
                    // Compute remainder using the mulmod Yul instruction.
                    remainder := mulmod(x, y, denominator)
                    // Subtract 256 bit number from 512-bit number.
                    prod1 := sub(prod1, gt(remainder, prod0))
                    prod0 := sub(prod0, remainder)
                }
                unchecked {
                    // Calculate the largest power of two divisor of the denominator using the unary operator ~. This operation cannot overflow
                    // because the denominator cannot be zero at this point in the function execution. The result is always >= 1.
                    // For more detail, see https://cs.stackexchange.com/q/138556/92363.
                    uint256 lpotdod = denominator & (~denominator + 1);
                    uint256 flippedLpotdod;
                    assembly ("memory-safe") {
                        // Factor powers of two out of denominator.
                        denominator := div(denominator, lpotdod)
                        // Divide [prod1 prod0] by lpotdod.
                        prod0 := div(prod0, lpotdod)
                        // Get the flipped value `2^256 / lpotdod`. If the `lpotdod` is zero, the flipped value is one.
                        // `sub(0, lpotdod)` produces the two's complement version of `lpotdod`, which is equivalent to flipping all the bits.
                        // However, `div` interprets this value as an unsigned value: https://ethereum.stackexchange.com/q/147168/24693
                        flippedLpotdod := add(div(sub(0, lpotdod), lpotdod), 1)
                    }
                    // Shift in bits from prod1 into prod0.
                    prod0 |= prod1 * flippedLpotdod;
                    // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
                    // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
                    // four bits. That is, denominator * inv = 1 mod 2^4.
                    uint256 inverse = (3 * denominator) ^ 2;
                    // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
                    // in modular arithmetic, doubling the correct bits in each step.
                    inverse *= 2 - denominator * inverse; // inverse mod 2^8
                    inverse *= 2 - denominator * inverse; // inverse mod 2^16
                    inverse *= 2 - denominator * inverse; // inverse mod 2^32
                    inverse *= 2 - denominator * inverse; // inverse mod 2^64
                    inverse *= 2 - denominator * inverse; // inverse mod 2^128
                    inverse *= 2 - denominator * inverse; // inverse mod 2^256
                    // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
                    // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
                    // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
                    // is no longer required.
                    result = prod0 * inverse;
                }
            }
            /// @notice Calculates x*y÷1e18 with 512-bit precision.
            ///
            /// @dev A variant of {mulDiv} with constant folding, i.e. in which the denominator is hard coded to 1e18.
            ///
            /// Notes:
            /// - The body is purposely left uncommented; to understand how this works, see the documentation in {mulDiv}.
            /// - The result is rounded toward zero.
            /// - We take as an axiom that the result cannot be `MAX_UINT256` when x and y solve the following system of equations:
            ///
            /// $$
            /// \\begin{cases}
            ///     x * y = MAX\\_UINT256 * UNIT \\\\
            ///     (x * y) \\% UNIT \\geq \\frac{UNIT}{2}
            /// \\end{cases}
            /// $$
            ///
            /// Requirements:
            /// - Refer to the requirements in {mulDiv}.
            /// - The result must fit in uint256.
            ///
            /// @param x The multiplicand as an unsigned 60.18-decimal fixed-point number.
            /// @param y The multiplier as an unsigned 60.18-decimal fixed-point number.
            /// @return result The result as an unsigned 60.18-decimal fixed-point number.
            /// @custom:smtchecker abstract-function-nondet
            function mulDiv18(uint256 x, uint256 y) pure returns (uint256 result) {
                uint256 prod0;
                uint256 prod1;
                assembly ("memory-safe") {
                    let mm := mulmod(x, y, not(0))
                    prod0 := mul(x, y)
                    prod1 := sub(sub(mm, prod0), lt(mm, prod0))
                }
                if (prod1 == 0) {
                    unchecked {
                        return prod0 / UNIT;
                    }
                }
                if (prod1 >= UNIT) {
                    revert PRBMath_MulDiv18_Overflow(x, y);
                }
                uint256 remainder;
                assembly ("memory-safe") {
                    remainder := mulmod(x, y, UNIT)
                    result :=
                        mul(
                            or(
                                div(sub(prod0, remainder), UNIT_LPOTD),
                                mul(sub(prod1, gt(remainder, prod0)), add(div(sub(0, UNIT_LPOTD), UNIT_LPOTD), 1))
                            ),
                            UNIT_INVERSE
                        )
                }
            }
            /// @notice Calculates x*y÷denominator with 512-bit precision.
            ///
            /// @dev This is an extension of {mulDiv} for signed numbers, which works by computing the signs and the absolute values separately.
            ///
            /// Notes:
            /// - The result is rounded toward zero.
            ///
            /// Requirements:
            /// - Refer to the requirements in {mulDiv}.
            /// - None of the inputs can be `type(int256).min`.
            /// - The result must fit in int256.
            ///
            /// @param x The multiplicand as an int256.
            /// @param y The multiplier as an int256.
            /// @param denominator The divisor as an int256.
            /// @return result The result as an int256.
            /// @custom:smtchecker abstract-function-nondet
            function mulDivSigned(int256 x, int256 y, int256 denominator) pure returns (int256 result) {
                if (x == type(int256).min || y == type(int256).min || denominator == type(int256).min) {
                    revert PRBMath_MulDivSigned_InputTooSmall();
                }
                // Get hold of the absolute values of x, y and the denominator.
                uint256 xAbs;
                uint256 yAbs;
                uint256 dAbs;
                unchecked {
                    xAbs = x < 0 ? uint256(-x) : uint256(x);
                    yAbs = y < 0 ? uint256(-y) : uint256(y);
                    dAbs = denominator < 0 ? uint256(-denominator) : uint256(denominator);
                }
                // Compute the absolute value of x*y÷denominator. The result must fit in int256.
                uint256 resultAbs = mulDiv(xAbs, yAbs, dAbs);
                if (resultAbs > uint256(type(int256).max)) {
                    revert PRBMath_MulDivSigned_Overflow(x, y);
                }
                // Get the signs of x, y and the denominator.
                uint256 sx;
                uint256 sy;
                uint256 sd;
                assembly ("memory-safe") {
                    // "sgt" is the "signed greater than" assembly instruction and "sub(0,1)" is -1 in two's complement.
                    sx := sgt(x, sub(0, 1))
                    sy := sgt(y, sub(0, 1))
                    sd := sgt(denominator, sub(0, 1))
                }
                // XOR over sx, sy and sd. What this does is to check whether there are 1 or 3 negative signs in the inputs.
                // If there are, the result should be negative. Otherwise, it should be positive.
                unchecked {
                    result = sx ^ sy ^ sd == 0 ? -int256(resultAbs) : int256(resultAbs);
                }
            }
            /// @notice Calculates the square root of x using the Babylonian method.
            ///
            /// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
            ///
            /// Notes:
            /// - If x is not a perfect square, the result is rounded down.
            /// - Credits to OpenZeppelin for the explanations in comments below.
            ///
            /// @param x The uint256 number for which to calculate the square root.
            /// @return result The result as a uint256.
            /// @custom:smtchecker abstract-function-nondet
            function sqrt(uint256 x) pure returns (uint256 result) {
                if (x == 0) {
                    return 0;
                }
                // For our first guess, we calculate the biggest power of 2 which is smaller than the square root of x.
                //
                // We know that the "msb" (most significant bit) of x is a power of 2 such that we have:
                //
                // $$
                // msb(x) <= x <= 2*msb(x)$
                // $$
                //
                // We write $msb(x)$ as $2^k$, and we get:
                //
                // $$
                // k = log_2(x)
                // $$
                //
                // Thus, we can write the initial inequality as:
                //
                // $$
                // 2^{log_2(x)} <= x <= 2*2^{log_2(x)+1} \\\\
                // sqrt(2^k) <= sqrt(x) < sqrt(2^{k+1}) \\\\
                // 2^{k/2} <= sqrt(x) < 2^{(k+1)/2} <= 2^{(k/2)+1}
                // $$
                //
                // Consequently, $2^{log_2(x) /2} is a good first approximation of sqrt(x) with at least one correct bit.
                uint256 xAux = uint256(x);
                result = 1;
                if (xAux >= 2 ** 128) {
                    xAux >>= 128;
                    result <<= 64;
                }
                if (xAux >= 2 ** 64) {
                    xAux >>= 64;
                    result <<= 32;
                }
                if (xAux >= 2 ** 32) {
                    xAux >>= 32;
                    result <<= 16;
                }
                if (xAux >= 2 ** 16) {
                    xAux >>= 16;
                    result <<= 8;
                }
                if (xAux >= 2 ** 8) {
                    xAux >>= 8;
                    result <<= 4;
                }
                if (xAux >= 2 ** 4) {
                    xAux >>= 4;
                    result <<= 2;
                }
                if (xAux >= 2 ** 2) {
                    result <<= 1;
                }
                // At this point, `result` is an estimation with at least one bit of precision. We know the true value has at
                // most 128 bits, since it is the square root of a uint256. Newton's method converges quadratically (precision
                // doubles at every iteration). We thus need at most 7 iteration to turn our partial result with one bit of
                // precision into the expected uint128 result.
                unchecked {
                    result = (result + x / result) >> 1;
                    result = (result + x / result) >> 1;
                    result = (result + x / result) >> 1;
                    result = (result + x / result) >> 1;
                    result = (result + x / result) >> 1;
                    result = (result + x / result) >> 1;
                    result = (result + x / result) >> 1;
                    // If x is not a perfect square, round the result toward zero.
                    uint256 roundedResult = x / result;
                    if (result >= roundedResult) {
                        result = roundedResult;
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { SD1x18 } from "./ValueType.sol";
            /// @dev Euler's number as an SD1x18 number.
            SD1x18 constant E = SD1x18.wrap(2_718281828459045235);
            /// @dev The maximum value an SD1x18 number can have.
            int64 constant uMAX_SD1x18 = 9_223372036854775807;
            SD1x18 constant MAX_SD1x18 = SD1x18.wrap(uMAX_SD1x18);
            /// @dev The minimum value an SD1x18 number can have.
            int64 constant uMIN_SD1x18 = -9_223372036854775808;
            SD1x18 constant MIN_SD1x18 = SD1x18.wrap(uMIN_SD1x18);
            /// @dev PI as an SD1x18 number.
            SD1x18 constant PI = SD1x18.wrap(3_141592653589793238);
            /// @dev The unit number, which gives the decimal precision of SD1x18.
            SD1x18 constant UNIT = SD1x18.wrap(1e18);
            int64 constant uUNIT = 1e18;
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "./Casting.sol" as Casting;
            /// @notice The signed 1.18-decimal fixed-point number representation, which can have up to 1 digit and up to 18
            /// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
            /// type int64. This is useful when end users want to use int64 to save gas, e.g. with tight variable packing in contract
            /// storage.
            type SD1x18 is int64;
            /*//////////////////////////////////////////////////////////////////////////
                                                CASTING
            //////////////////////////////////////////////////////////////////////////*/
            using {
                Casting.intoSD59x18,
                Casting.intoUD60x18,
                Casting.intoUint128,
                Casting.intoUint256,
                Casting.intoUint40,
                Casting.unwrap
            } for SD1x18 global;
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { SD21x18 } from "./ValueType.sol";
            /// @dev Euler's number as an SD21x18 number.
            SD21x18 constant E = SD21x18.wrap(2_718281828459045235);
            /// @dev The maximum value an SD21x18 number can have.
            int128 constant uMAX_SD21x18 = 170141183460469231731_687303715884105727;
            SD21x18 constant MAX_SD21x18 = SD21x18.wrap(uMAX_SD21x18);
            /// @dev The minimum value an SD21x18 number can have.
            int128 constant uMIN_SD21x18 = -170141183460469231731_687303715884105728;
            SD21x18 constant MIN_SD21x18 = SD21x18.wrap(uMIN_SD21x18);
            /// @dev PI as an SD21x18 number.
            SD21x18 constant PI = SD21x18.wrap(3_141592653589793238);
            /// @dev The unit number, which gives the decimal precision of SD21x18.
            SD21x18 constant UNIT = SD21x18.wrap(1e18);
            int128 constant uUNIT = 1e18;
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "./Casting.sol" as Casting;
            /// @notice The signed 21.18-decimal fixed-point number representation, which can have up to 21 digits and up to 18
            /// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
            /// type int128. This is useful when end users want to use int128 to save gas, e.g. with tight variable packing in contract
            /// storage.
            type SD21x18 is int128;
            /*//////////////////////////////////////////////////////////////////////////
                                                CASTING
            //////////////////////////////////////////////////////////////////////////*/
            using {
                Casting.intoSD59x18,
                Casting.intoUD60x18,
                Casting.intoUint128,
                Casting.intoUint256,
                Casting.intoUint40,
                Casting.unwrap
            } for SD21x18 global;
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { SD59x18 } from "./ValueType.sol";
            // NOTICE: the "u" prefix stands for "unwrapped".
            /// @dev Euler's number as an SD59x18 number.
            SD59x18 constant E = SD59x18.wrap(2_718281828459045235);
            /// @dev The maximum input permitted in {exp}.
            int256 constant uEXP_MAX_INPUT = 133_084258667509499440;
            SD59x18 constant EXP_MAX_INPUT = SD59x18.wrap(uEXP_MAX_INPUT);
            /// @dev Any value less than this returns 0 in {exp}.
            int256 constant uEXP_MIN_THRESHOLD = -41_446531673892822322;
            SD59x18 constant EXP_MIN_THRESHOLD = SD59x18.wrap(uEXP_MIN_THRESHOLD);
            /// @dev The maximum input permitted in {exp2}.
            int256 constant uEXP2_MAX_INPUT = 192e18 - 1;
            SD59x18 constant EXP2_MAX_INPUT = SD59x18.wrap(uEXP2_MAX_INPUT);
            /// @dev Any value less than this returns 0 in {exp2}.
            int256 constant uEXP2_MIN_THRESHOLD = -59_794705707972522261;
            SD59x18 constant EXP2_MIN_THRESHOLD = SD59x18.wrap(uEXP2_MIN_THRESHOLD);
            /// @dev Half the UNIT number.
            int256 constant uHALF_UNIT = 0.5e18;
            SD59x18 constant HALF_UNIT = SD59x18.wrap(uHALF_UNIT);
            /// @dev $log_2(10)$ as an SD59x18 number.
            int256 constant uLOG2_10 = 3_321928094887362347;
            SD59x18 constant LOG2_10 = SD59x18.wrap(uLOG2_10);
            /// @dev $log_2(e)$ as an SD59x18 number.
            int256 constant uLOG2_E = 1_442695040888963407;
            SD59x18 constant LOG2_E = SD59x18.wrap(uLOG2_E);
            /// @dev The maximum value an SD59x18 number can have.
            int256 constant uMAX_SD59x18 = 57896044618658097711785492504343953926634992332820282019728_792003956564819967;
            SD59x18 constant MAX_SD59x18 = SD59x18.wrap(uMAX_SD59x18);
            /// @dev The maximum whole value an SD59x18 number can have.
            int256 constant uMAX_WHOLE_SD59x18 = 57896044618658097711785492504343953926634992332820282019728_000000000000000000;
            SD59x18 constant MAX_WHOLE_SD59x18 = SD59x18.wrap(uMAX_WHOLE_SD59x18);
            /// @dev The minimum value an SD59x18 number can have.
            int256 constant uMIN_SD59x18 = -57896044618658097711785492504343953926634992332820282019728_792003956564819968;
            SD59x18 constant MIN_SD59x18 = SD59x18.wrap(uMIN_SD59x18);
            /// @dev The minimum whole value an SD59x18 number can have.
            int256 constant uMIN_WHOLE_SD59x18 = -57896044618658097711785492504343953926634992332820282019728_000000000000000000;
            SD59x18 constant MIN_WHOLE_SD59x18 = SD59x18.wrap(uMIN_WHOLE_SD59x18);
            /// @dev PI as an SD59x18 number.
            SD59x18 constant PI = SD59x18.wrap(3_141592653589793238);
            /// @dev The unit number, which gives the decimal precision of SD59x18.
            int256 constant uUNIT = 1e18;
            SD59x18 constant UNIT = SD59x18.wrap(1e18);
            /// @dev The unit number squared.
            int256 constant uUNIT_SQUARED = 1e36;
            SD59x18 constant UNIT_SQUARED = SD59x18.wrap(uUNIT_SQUARED);
            /// @dev Zero as an SD59x18 number.
            SD59x18 constant ZERO = SD59x18.wrap(0);
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "./Casting.sol" as Casting;
            import "./Helpers.sol" as Helpers;
            import "./Math.sol" as Math;
            /// @notice The signed 59.18-decimal fixed-point number representation, which can have up to 59 digits and up to 18
            /// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
            /// type int256.
            type SD59x18 is int256;
            /*//////////////////////////////////////////////////////////////////////////
                                                CASTING
            //////////////////////////////////////////////////////////////////////////*/
            using {
                Casting.intoInt256,
                Casting.intoSD1x18,
                Casting.intoSD21x18,
                Casting.intoUD2x18,
                Casting.intoUD21x18,
                Casting.intoUD60x18,
                Casting.intoUint256,
                Casting.intoUint128,
                Casting.intoUint40,
                Casting.unwrap
            } for SD59x18 global;
            /*//////////////////////////////////////////////////////////////////////////
                                        MATHEMATICAL FUNCTIONS
            //////////////////////////////////////////////////////////////////////////*/
            using {
                Math.abs,
                Math.avg,
                Math.ceil,
                Math.div,
                Math.exp,
                Math.exp2,
                Math.floor,
                Math.frac,
                Math.gm,
                Math.inv,
                Math.log10,
                Math.log2,
                Math.ln,
                Math.mul,
                Math.pow,
                Math.powu,
                Math.sqrt
            } for SD59x18 global;
            /*//////////////////////////////////////////////////////////////////////////
                                            HELPER FUNCTIONS
            //////////////////////////////////////////////////////////////////////////*/
            using {
                Helpers.add,
                Helpers.and,
                Helpers.eq,
                Helpers.gt,
                Helpers.gte,
                Helpers.isZero,
                Helpers.lshift,
                Helpers.lt,
                Helpers.lte,
                Helpers.mod,
                Helpers.neq,
                Helpers.not,
                Helpers.or,
                Helpers.rshift,
                Helpers.sub,
                Helpers.uncheckedAdd,
                Helpers.uncheckedSub,
                Helpers.uncheckedUnary,
                Helpers.xor
            } for SD59x18 global;
            /*//////////////////////////////////////////////////////////////////////////
                                                OPERATORS
            //////////////////////////////////////////////////////////////////////////*/
            // The global "using for" directive makes it possible to use these operators on the SD59x18 type.
            using {
                Helpers.add as +,
                Helpers.and2 as &,
                Math.div as /,
                Helpers.eq as ==,
                Helpers.gt as >,
                Helpers.gte as >=,
                Helpers.lt as <,
                Helpers.lte as <=,
                Helpers.mod as %,
                Math.mul as *,
                Helpers.neq as !=,
                Helpers.not as ~,
                Helpers.or as |,
                Helpers.sub as -,
                Helpers.unary as -,
                Helpers.xor as ^
            } for SD59x18 global;
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { UD2x18 } from "./ValueType.sol";
            /// @dev Euler's number as a UD2x18 number.
            UD2x18 constant E = UD2x18.wrap(2_718281828459045235);
            /// @dev The maximum value a UD2x18 number can have.
            uint64 constant uMAX_UD2x18 = 18_446744073709551615;
            UD2x18 constant MAX_UD2x18 = UD2x18.wrap(uMAX_UD2x18);
            /// @dev PI as a UD2x18 number.
            UD2x18 constant PI = UD2x18.wrap(3_141592653589793238);
            /// @dev The unit number, which gives the decimal precision of UD2x18.
            UD2x18 constant UNIT = UD2x18.wrap(1e18);
            uint64 constant uUNIT = 1e18;
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { UD21x18 } from "./ValueType.sol";
            /// @dev Euler's number as a UD21x18 number.
            UD21x18 constant E = UD21x18.wrap(2_718281828459045235);
            /// @dev The maximum value a UD21x18 number can have.
            uint128 constant uMAX_UD21x18 = 340282366920938463463_374607431768211455;
            UD21x18 constant MAX_UD21x18 = UD21x18.wrap(uMAX_UD21x18);
            /// @dev PI as a UD21x18 number.
            UD21x18 constant PI = UD21x18.wrap(3_141592653589793238);
            /// @dev The unit number, which gives the decimal precision of UD21x18.
            uint256 constant uUNIT = 1e18;
            UD21x18 constant UNIT = UD21x18.wrap(1e18);
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "./Casting.sol" as Casting;
            /// @notice The unsigned 2.18-decimal fixed-point number representation, which can have up to 2 digits and up to 18
            /// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
            /// type uint64. This is useful when end users want to use uint64 to save gas, e.g. with tight variable packing in contract
            /// storage.
            type UD2x18 is uint64;
            /*//////////////////////////////////////////////////////////////////////////
                                                CASTING
            //////////////////////////////////////////////////////////////////////////*/
            using {
                Casting.intoSD59x18,
                Casting.intoUD60x18,
                Casting.intoUint128,
                Casting.intoUint256,
                Casting.intoUint40,
                Casting.unwrap
            } for UD2x18 global;
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "./Casting.sol" as Casting;
            /// @notice The unsigned 21.18-decimal fixed-point number representation, which can have up to 21 digits and up to 18
            /// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
            /// type uint128. This is useful when end users want to use uint128 to save gas, e.g. with tight variable packing in contract
            /// storage.
            type UD21x18 is uint128;
            /*//////////////////////////////////////////////////////////////////////////
                                                CASTING
            //////////////////////////////////////////////////////////////////////////*/
            using {
                Casting.intoSD59x18,
                Casting.intoUD60x18,
                Casting.intoUint128,
                Casting.intoUint256,
                Casting.intoUint40,
                Casting.unwrap
            } for UD21x18 global;
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Metadata.sol)
            pragma solidity ^0.8.20;
            import {IERC721} from "../IERC721.sol";
            /**
             * @title ERC-721 Non-Fungible Token Standard, optional metadata extension
             * @dev See https://eips.ethereum.org/EIPS/eip-721
             */
            interface IERC721Metadata is IERC721 {
                /**
                 * @dev Returns the token collection name.
                 */
                function name() external view returns (string memory);
                /**
                 * @dev Returns the token collection symbol.
                 */
                function symbol() external view returns (string memory);
                /**
                 * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
                 */
                function tokenURI(uint256 tokenId) external view returns (string memory);
            }
            // SPDX-License-Identifier: GPL-3.0-or-later
            pragma solidity >=0.8.19;
            import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
            import { UD60x18 } from "@prb/math/src/UD60x18.sol";
            import { IAdminable } from "./IAdminable.sol";
            import { ISablierV2Comptroller } from "./ISablierV2Comptroller.sol";
            /// @title ISablierV2Base
            /// @notice Base logic for all Sablier V2 streaming contracts.
            interface ISablierV2Base is IAdminable {
                /*//////////////////////////////////////////////////////////////////////////
                                                   EVENTS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Emitted when the admin claims all protocol revenues accrued for a particular ERC-20 asset.
                /// @param admin The address of the contract admin.
                /// @param asset The contract address of the ERC-20 asset the protocol revenues have been claimed for.
                /// @param protocolRevenues The amount of protocol revenues claimed, denoted in units of the asset's decimals.
                event ClaimProtocolRevenues(address indexed admin, IERC20 indexed asset, uint128 protocolRevenues);
                /// @notice Emitted when the admin sets a new comptroller contract.
                /// @param admin The address of the contract admin.
                /// @param oldComptroller The address of the old comptroller contract.
                /// @param newComptroller The address of the new comptroller contract.
                event SetComptroller(
                    address indexed admin, ISablierV2Comptroller oldComptroller, ISablierV2Comptroller newComptroller
                );
                /*//////////////////////////////////////////////////////////////////////////
                                             CONSTANT FUNCTIONS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Retrieves the maximum fee that can be charged by the protocol or a broker, denoted as a fixed-point
                /// number where 1e18 is 100%.
                /// @dev This value is hard coded as a constant.
                function MAX_FEE() external view returns (UD60x18);
                /// @notice Retrieves the address of the comptroller contract, responsible for the Sablier V2 protocol
                /// configuration.
                function comptroller() external view returns (ISablierV2Comptroller);
                /// @notice Retrieves the protocol revenues accrued for the provided ERC-20 asset, in units of the asset's
                /// decimals.
                /// @param asset The contract address of the ERC-20 asset to query.
                function protocolRevenues(IERC20 asset) external view returns (uint128 revenues);
                /*//////////////////////////////////////////////////////////////////////////
                                           NON-CONSTANT FUNCTIONS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Claims all accumulated protocol revenues for the provided ERC-20 asset.
                ///
                /// @dev Emits a {ClaimProtocolRevenues} event.
                ///
                /// Requirements:
                /// - `msg.sender` must be the contract admin.
                ///
                /// @param asset The contract address of the ERC-20 asset for which to claim protocol revenues.
                function claimProtocolRevenues(IERC20 asset) external;
                /// @notice Assigns a new comptroller contract responsible for the protocol configuration.
                ///
                /// @dev Emits a {SetComptroller} event.
                ///
                /// Notes:
                /// - Does not revert if the comptroller is the same.
                ///
                /// Requirements:
                /// - `msg.sender` must be the contract admin.
                ///
                /// @param newComptroller The address of the new comptroller contract.
                function setComptroller(ISablierV2Comptroller newComptroller) external;
            }
            // SPDX-License-Identifier: GPL-3.0-or-later
            pragma solidity >=0.8.19;
            import { IERC721Metadata } from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
            /// @title ISablierV2NFTDescriptor
            /// @notice This contract generates the URI describing the Sablier V2 stream NFTs.
            /// @dev Inspired by Uniswap V3 Positions NFTs.
            interface ISablierV2NFTDescriptor {
                /// @notice Produces the URI describing a particular stream NFT.
                /// @dev This is a data URI with the JSON contents directly inlined.
                /// @param sablier The address of the Sablier contract the stream was created in.
                /// @param streamId The id of the stream for which to produce a description.
                /// @return uri The URI of the ERC721-compliant metadata.
                function tokenURI(IERC721Metadata sablier, uint256 streamId) external view returns (string memory uri);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "../Common.sol" as Common;
            import "./Errors.sol" as Errors;
            import { SD59x18 } from "../sd59x18/ValueType.sol";
            import { UD60x18 } from "../ud60x18/ValueType.sol";
            import { UD2x18 } from "./ValueType.sol";
            /// @notice Casts a UD2x18 number into SD59x18.
            /// @dev There is no overflow check because UD2x18 ⊆ SD59x18.
            function intoSD59x18(UD2x18 x) pure returns (SD59x18 result) {
                result = SD59x18.wrap(int256(uint256(UD2x18.unwrap(x))));
            }
            /// @notice Casts a UD2x18 number into UD60x18.
            /// @dev There is no overflow check because UD2x18 ⊆ UD60x18.
            function intoUD60x18(UD2x18 x) pure returns (UD60x18 result) {
                result = UD60x18.wrap(UD2x18.unwrap(x));
            }
            /// @notice Casts a UD2x18 number into uint128.
            /// @dev There is no overflow check because UD2x18 ⊆ uint128.
            function intoUint128(UD2x18 x) pure returns (uint128 result) {
                result = uint128(UD2x18.unwrap(x));
            }
            /// @notice Casts a UD2x18 number into uint256.
            /// @dev There is no overflow check because UD2x18 ⊆ uint256.
            function intoUint256(UD2x18 x) pure returns (uint256 result) {
                result = uint256(UD2x18.unwrap(x));
            }
            /// @notice Casts a UD2x18 number into uint40.
            /// @dev Requirements:
            /// - x ≤ MAX_UINT40
            function intoUint40(UD2x18 x) pure returns (uint40 result) {
                uint64 xUint = UD2x18.unwrap(x);
                if (xUint > uint64(Common.MAX_UINT40)) {
                    revert Errors.PRBMath_UD2x18_IntoUint40_Overflow(x);
                }
                result = uint40(xUint);
            }
            /// @notice Alias for {wrap}.
            function ud2x18(uint64 x) pure returns (UD2x18 result) {
                result = UD2x18.wrap(x);
            }
            /// @notice Unwrap a UD2x18 number into uint64.
            function unwrap(UD2x18 x) pure returns (uint64 result) {
                result = UD2x18.unwrap(x);
            }
            /// @notice Wraps a uint64 number into UD2x18.
            function wrap(uint64 x) pure returns (UD2x18 result) {
                result = UD2x18.wrap(x);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { UD2x18 } from "./ValueType.sol";
            /// @notice Thrown when trying to cast a UD2x18 number that doesn't fit in uint40.
            error PRBMath_UD2x18_IntoUint40_Overflow(UD2x18 x);
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "../Common.sol" as Common;
            import "./Errors.sol" as CastingErrors;
            import { SD59x18 } from "../sd59x18/ValueType.sol";
            import { UD60x18 } from "../ud60x18/ValueType.sol";
            import { SD1x18 } from "./ValueType.sol";
            /// @notice Casts an SD1x18 number into SD59x18.
            /// @dev There is no overflow check because SD1x18 ⊆ SD59x18.
            function intoSD59x18(SD1x18 x) pure returns (SD59x18 result) {
                result = SD59x18.wrap(int256(SD1x18.unwrap(x)));
            }
            /// @notice Casts an SD1x18 number into UD60x18.
            /// @dev Requirements:
            /// - x ≥ 0
            function intoUD60x18(SD1x18 x) pure returns (UD60x18 result) {
                int64 xInt = SD1x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD1x18_ToUD60x18_Underflow(x);
                }
                result = UD60x18.wrap(uint64(xInt));
            }
            /// @notice Casts an SD1x18 number into uint128.
            /// @dev Requirements:
            /// - x ≥ 0
            function intoUint128(SD1x18 x) pure returns (uint128 result) {
                int64 xInt = SD1x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD1x18_ToUint128_Underflow(x);
                }
                result = uint128(uint64(xInt));
            }
            /// @notice Casts an SD1x18 number into uint256.
            /// @dev Requirements:
            /// - x ≥ 0
            function intoUint256(SD1x18 x) pure returns (uint256 result) {
                int64 xInt = SD1x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD1x18_ToUint256_Underflow(x);
                }
                result = uint256(uint64(xInt));
            }
            /// @notice Casts an SD1x18 number into uint40.
            /// @dev Requirements:
            /// - x ≥ 0
            /// - x ≤ MAX_UINT40
            function intoUint40(SD1x18 x) pure returns (uint40 result) {
                int64 xInt = SD1x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD1x18_ToUint40_Underflow(x);
                }
                if (xInt > int64(uint64(Common.MAX_UINT40))) {
                    revert CastingErrors.PRBMath_SD1x18_ToUint40_Overflow(x);
                }
                result = uint40(uint64(xInt));
            }
            /// @notice Alias for {wrap}.
            function sd1x18(int64 x) pure returns (SD1x18 result) {
                result = SD1x18.wrap(x);
            }
            /// @notice Unwraps an SD1x18 number into int64.
            function unwrap(SD1x18 x) pure returns (int64 result) {
                result = SD1x18.unwrap(x);
            }
            /// @notice Wraps an int64 number into SD1x18.
            function wrap(int64 x) pure returns (SD1x18 result) {
                result = SD1x18.wrap(x);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "../Common.sol" as Common;
            import "./Errors.sol" as CastingErrors;
            import { SD59x18 } from "../sd59x18/ValueType.sol";
            import { UD60x18 } from "../ud60x18/ValueType.sol";
            import { SD21x18 } from "./ValueType.sol";
            /// @notice Casts an SD21x18 number into SD59x18.
            /// @dev There is no overflow check because SD21x18 ⊆ SD59x18.
            function intoSD59x18(SD21x18 x) pure returns (SD59x18 result) {
                result = SD59x18.wrap(int256(SD21x18.unwrap(x)));
            }
            /// @notice Casts an SD21x18 number into UD60x18.
            /// @dev Requirements:
            /// - x ≥ 0
            function intoUD60x18(SD21x18 x) pure returns (UD60x18 result) {
                int128 xInt = SD21x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD21x18_ToUD60x18_Underflow(x);
                }
                result = UD60x18.wrap(uint128(xInt));
            }
            /// @notice Casts an SD21x18 number into uint128.
            /// @dev Requirements:
            /// - x ≥ 0
            function intoUint128(SD21x18 x) pure returns (uint128 result) {
                int128 xInt = SD21x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD21x18_ToUint128_Underflow(x);
                }
                result = uint128(xInt);
            }
            /// @notice Casts an SD21x18 number into uint256.
            /// @dev Requirements:
            /// - x ≥ 0
            function intoUint256(SD21x18 x) pure returns (uint256 result) {
                int128 xInt = SD21x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD21x18_ToUint256_Underflow(x);
                }
                result = uint256(uint128(xInt));
            }
            /// @notice Casts an SD21x18 number into uint40.
            /// @dev Requirements:
            /// - x ≥ 0
            /// - x ≤ MAX_UINT40
            function intoUint40(SD21x18 x) pure returns (uint40 result) {
                int128 xInt = SD21x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD21x18_ToUint40_Underflow(x);
                }
                if (xInt > int128(uint128(Common.MAX_UINT40))) {
                    revert CastingErrors.PRBMath_SD21x18_ToUint40_Overflow(x);
                }
                result = uint40(uint128(xInt));
            }
            /// @notice Alias for {wrap}.
            function sd21x18(int128 x) pure returns (SD21x18 result) {
                result = SD21x18.wrap(x);
            }
            /// @notice Unwraps an SD21x18 number into int128.
            function unwrap(SD21x18 x) pure returns (int128 result) {
                result = SD21x18.unwrap(x);
            }
            /// @notice Wraps an int128 number into SD21x18.
            function wrap(int128 x) pure returns (SD21x18 result) {
                result = SD21x18.wrap(x);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "./Errors.sol" as CastingErrors;
            import { MAX_UINT128, MAX_UINT40 } from "../Common.sol";
            import { uMAX_SD1x18, uMIN_SD1x18 } from "../sd1x18/Constants.sol";
            import { SD1x18 } from "../sd1x18/ValueType.sol";
            import { uMAX_SD21x18, uMIN_SD21x18 } from "../sd21x18/Constants.sol";
            import { SD21x18 } from "../sd21x18/ValueType.sol";
            import { uMAX_UD2x18 } from "../ud2x18/Constants.sol";
            import { UD2x18 } from "../ud2x18/ValueType.sol";
            import { uMAX_UD21x18 } from "../ud21x18/Constants.sol";
            import { UD21x18 } from "../ud21x18/ValueType.sol";
            import { UD60x18 } from "../ud60x18/ValueType.sol";
            import { SD59x18 } from "./ValueType.sol";
            /// @notice Casts an SD59x18 number into int256.
            /// @dev This is basically a functional alias for {unwrap}.
            function intoInt256(SD59x18 x) pure returns (int256 result) {
                result = SD59x18.unwrap(x);
            }
            /// @notice Casts an SD59x18 number into SD1x18.
            /// @dev Requirements:
            /// - x ≥ uMIN_SD1x18
            /// - x ≤ uMAX_SD1x18
            function intoSD1x18(SD59x18 x) pure returns (SD1x18 result) {
                int256 xInt = SD59x18.unwrap(x);
                if (xInt < uMIN_SD1x18) {
                    revert CastingErrors.PRBMath_SD59x18_IntoSD1x18_Underflow(x);
                }
                if (xInt > uMAX_SD1x18) {
                    revert CastingErrors.PRBMath_SD59x18_IntoSD1x18_Overflow(x);
                }
                result = SD1x18.wrap(int64(xInt));
            }
            /// @notice Casts an SD59x18 number into SD21x18.
            /// @dev Requirements:
            /// - x ≥ uMIN_SD21x18
            /// - x ≤ uMAX_SD21x18
            function intoSD21x18(SD59x18 x) pure returns (SD21x18 result) {
                int256 xInt = SD59x18.unwrap(x);
                if (xInt < uMIN_SD21x18) {
                    revert CastingErrors.PRBMath_SD59x18_IntoSD21x18_Underflow(x);
                }
                if (xInt > uMAX_SD21x18) {
                    revert CastingErrors.PRBMath_SD59x18_IntoSD21x18_Overflow(x);
                }
                result = SD21x18.wrap(int128(xInt));
            }
            /// @notice Casts an SD59x18 number into UD2x18.
            /// @dev Requirements:
            /// - x ≥ 0
            /// - x ≤ uMAX_UD2x18
            function intoUD2x18(SD59x18 x) pure returns (UD2x18 result) {
                int256 xInt = SD59x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD59x18_IntoUD2x18_Underflow(x);
                }
                if (xInt > int256(uint256(uMAX_UD2x18))) {
                    revert CastingErrors.PRBMath_SD59x18_IntoUD2x18_Overflow(x);
                }
                result = UD2x18.wrap(uint64(uint256(xInt)));
            }
            /// @notice Casts an SD59x18 number into UD21x18.
            /// @dev Requirements:
            /// - x ≥ 0
            /// - x ≤ uMAX_UD21x18
            function intoUD21x18(SD59x18 x) pure returns (UD21x18 result) {
                int256 xInt = SD59x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD59x18_IntoUD21x18_Underflow(x);
                }
                if (xInt > int256(uint256(uMAX_UD21x18))) {
                    revert CastingErrors.PRBMath_SD59x18_IntoUD21x18_Overflow(x);
                }
                result = UD21x18.wrap(uint128(uint256(xInt)));
            }
            /// @notice Casts an SD59x18 number into UD60x18.
            /// @dev Requirements:
            /// - x ≥ 0
            function intoUD60x18(SD59x18 x) pure returns (UD60x18 result) {
                int256 xInt = SD59x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD59x18_IntoUD60x18_Underflow(x);
                }
                result = UD60x18.wrap(uint256(xInt));
            }
            /// @notice Casts an SD59x18 number into uint256.
            /// @dev Requirements:
            /// - x ≥ 0
            function intoUint256(SD59x18 x) pure returns (uint256 result) {
                int256 xInt = SD59x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD59x18_IntoUint256_Underflow(x);
                }
                result = uint256(xInt);
            }
            /// @notice Casts an SD59x18 number into uint128.
            /// @dev Requirements:
            /// - x ≥ 0
            /// - x ≤ uMAX_UINT128
            function intoUint128(SD59x18 x) pure returns (uint128 result) {
                int256 xInt = SD59x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD59x18_IntoUint128_Underflow(x);
                }
                if (xInt > int256(uint256(MAX_UINT128))) {
                    revert CastingErrors.PRBMath_SD59x18_IntoUint128_Overflow(x);
                }
                result = uint128(uint256(xInt));
            }
            /// @notice Casts an SD59x18 number into uint40.
            /// @dev Requirements:
            /// - x ≥ 0
            /// - x ≤ MAX_UINT40
            function intoUint40(SD59x18 x) pure returns (uint40 result) {
                int256 xInt = SD59x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD59x18_IntoUint40_Underflow(x);
                }
                if (xInt > int256(uint256(MAX_UINT40))) {
                    revert CastingErrors.PRBMath_SD59x18_IntoUint40_Overflow(x);
                }
                result = uint40(uint256(xInt));
            }
            /// @notice Alias for {wrap}.
            function sd(int256 x) pure returns (SD59x18 result) {
                result = SD59x18.wrap(x);
            }
            /// @notice Alias for {wrap}.
            function sd59x18(int256 x) pure returns (SD59x18 result) {
                result = SD59x18.wrap(x);
            }
            /// @notice Unwraps an SD59x18 number into int256.
            function unwrap(SD59x18 x) pure returns (int256 result) {
                result = SD59x18.unwrap(x);
            }
            /// @notice Wraps an int256 number into SD59x18.
            function wrap(int256 x) pure returns (SD59x18 result) {
                result = SD59x18.wrap(x);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { wrap } from "./Casting.sol";
            import { SD59x18 } from "./ValueType.sol";
            /// @notice Implements the checked addition operation (+) in the SD59x18 type.
            function add(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                return wrap(x.unwrap() + y.unwrap());
            }
            /// @notice Implements the AND (&) bitwise operation in the SD59x18 type.
            function and(SD59x18 x, int256 bits) pure returns (SD59x18 result) {
                return wrap(x.unwrap() & bits);
            }
            /// @notice Implements the AND (&) bitwise operation in the SD59x18 type.
            function and2(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                return wrap(x.unwrap() & y.unwrap());
            }
            /// @notice Implements the equal (=) operation in the SD59x18 type.
            function eq(SD59x18 x, SD59x18 y) pure returns (bool result) {
                result = x.unwrap() == y.unwrap();
            }
            /// @notice Implements the greater than operation (>) in the SD59x18 type.
            function gt(SD59x18 x, SD59x18 y) pure returns (bool result) {
                result = x.unwrap() > y.unwrap();
            }
            /// @notice Implements the greater than or equal to operation (>=) in the SD59x18 type.
            function gte(SD59x18 x, SD59x18 y) pure returns (bool result) {
                result = x.unwrap() >= y.unwrap();
            }
            /// @notice Implements a zero comparison check function in the SD59x18 type.
            function isZero(SD59x18 x) pure returns (bool result) {
                result = x.unwrap() == 0;
            }
            /// @notice Implements the left shift operation (<<) in the SD59x18 type.
            function lshift(SD59x18 x, uint256 bits) pure returns (SD59x18 result) {
                result = wrap(x.unwrap() << bits);
            }
            /// @notice Implements the lower than operation (<) in the SD59x18 type.
            function lt(SD59x18 x, SD59x18 y) pure returns (bool result) {
                result = x.unwrap() < y.unwrap();
            }
            /// @notice Implements the lower than or equal to operation (<=) in the SD59x18 type.
            function lte(SD59x18 x, SD59x18 y) pure returns (bool result) {
                result = x.unwrap() <= y.unwrap();
            }
            /// @notice Implements the unchecked modulo operation (%) in the SD59x18 type.
            function mod(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                result = wrap(x.unwrap() % y.unwrap());
            }
            /// @notice Implements the not equal operation (!=) in the SD59x18 type.
            function neq(SD59x18 x, SD59x18 y) pure returns (bool result) {
                result = x.unwrap() != y.unwrap();
            }
            /// @notice Implements the NOT (~) bitwise operation in the SD59x18 type.
            function not(SD59x18 x) pure returns (SD59x18 result) {
                result = wrap(~x.unwrap());
            }
            /// @notice Implements the OR (|) bitwise operation in the SD59x18 type.
            function or(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                result = wrap(x.unwrap() | y.unwrap());
            }
            /// @notice Implements the right shift operation (>>) in the SD59x18 type.
            function rshift(SD59x18 x, uint256 bits) pure returns (SD59x18 result) {
                result = wrap(x.unwrap() >> bits);
            }
            /// @notice Implements the checked subtraction operation (-) in the SD59x18 type.
            function sub(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                result = wrap(x.unwrap() - y.unwrap());
            }
            /// @notice Implements the checked unary minus operation (-) in the SD59x18 type.
            function unary(SD59x18 x) pure returns (SD59x18 result) {
                result = wrap(-x.unwrap());
            }
            /// @notice Implements the unchecked addition operation (+) in the SD59x18 type.
            function uncheckedAdd(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                unchecked {
                    result = wrap(x.unwrap() + y.unwrap());
                }
            }
            /// @notice Implements the unchecked subtraction operation (-) in the SD59x18 type.
            function uncheckedSub(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                unchecked {
                    result = wrap(x.unwrap() - y.unwrap());
                }
            }
            /// @notice Implements the unchecked unary minus operation (-) in the SD59x18 type.
            function uncheckedUnary(SD59x18 x) pure returns (SD59x18 result) {
                unchecked {
                    result = wrap(-x.unwrap());
                }
            }
            /// @notice Implements the XOR (^) bitwise operation in the SD59x18 type.
            function xor(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                result = wrap(x.unwrap() ^ y.unwrap());
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "../Common.sol" as Common;
            import "./Errors.sol" as Errors;
            import {
                uEXP_MAX_INPUT,
                uEXP2_MAX_INPUT,
                uEXP_MIN_THRESHOLD,
                uEXP2_MIN_THRESHOLD,
                uHALF_UNIT,
                uLOG2_10,
                uLOG2_E,
                uMAX_SD59x18,
                uMAX_WHOLE_SD59x18,
                uMIN_SD59x18,
                uMIN_WHOLE_SD59x18,
                UNIT,
                uUNIT,
                uUNIT_SQUARED,
                ZERO
            } from "./Constants.sol";
            import { wrap } from "./Helpers.sol";
            import { SD59x18 } from "./ValueType.sol";
            /// @notice Calculates the absolute value of x.
            ///
            /// @dev Requirements:
            /// - x > MIN_SD59x18.
            ///
            /// @param x The SD59x18 number for which to calculate the absolute value.
            /// @return result The absolute value of x as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function abs(SD59x18 x) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                if (xInt == uMIN_SD59x18) {
                    revert Errors.PRBMath_SD59x18_Abs_MinSD59x18();
                }
                result = xInt < 0 ? wrap(-xInt) : x;
            }
            /// @notice Calculates the arithmetic average of x and y.
            ///
            /// @dev Notes:
            /// - The result is rounded toward zero.
            ///
            /// @param x The first operand as an SD59x18 number.
            /// @param y The second operand as an SD59x18 number.
            /// @return result The arithmetic average as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function avg(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                int256 yInt = y.unwrap();
                unchecked {
                    // This operation is equivalent to `x / 2 +  y / 2`, and it can never overflow.
                    int256 sum = (xInt >> 1) + (yInt >> 1);
                    if (sum < 0) {
                        // If at least one of x and y is odd, add 1 to the result, because shifting negative numbers to the right
                        // rounds toward negative infinity. The right part is equivalent to `sum + (x % 2 == 1 || y % 2 == 1)`.
                        assembly ("memory-safe") {
                            result := add(sum, and(or(xInt, yInt), 1))
                        }
                    } else {
                        // Add 1 if both x and y are odd to account for the double 0.5 remainder truncated after shifting.
                        result = wrap(sum + (xInt & yInt & 1));
                    }
                }
            }
            /// @notice Yields the smallest whole number greater than or equal to x.
            ///
            /// @dev Optimized for fractional value inputs, because every whole value has (1e18 - 1) fractional counterparts.
            /// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
            ///
            /// Requirements:
            /// - x ≤ MAX_WHOLE_SD59x18
            ///
            /// @param x The SD59x18 number to ceil.
            /// @return result The smallest whole number greater than or equal to x, as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function ceil(SD59x18 x) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                if (xInt > uMAX_WHOLE_SD59x18) {
                    revert Errors.PRBMath_SD59x18_Ceil_Overflow(x);
                }
                int256 remainder = xInt % uUNIT;
                if (remainder == 0) {
                    result = x;
                } else {
                    unchecked {
                        // Solidity uses C fmod style, which returns a modulus with the same sign as x.
                        int256 resultInt = xInt - remainder;
                        if (xInt > 0) {
                            resultInt += uUNIT;
                        }
                        result = wrap(resultInt);
                    }
                }
            }
            /// @notice Divides two SD59x18 numbers, returning a new SD59x18 number.
            ///
            /// @dev This is an extension of {Common.mulDiv} for signed numbers, which works by computing the signs and the absolute
            /// values separately.
            ///
            /// Notes:
            /// - Refer to the notes in {Common.mulDiv}.
            /// - The result is rounded toward zero.
            ///
            /// Requirements:
            /// - Refer to the requirements in {Common.mulDiv}.
            /// - None of the inputs can be `MIN_SD59x18`.
            /// - The denominator must not be zero.
            /// - The result must fit in SD59x18.
            ///
            /// @param x The numerator as an SD59x18 number.
            /// @param y The denominator as an SD59x18 number.
            /// @return result The quotient as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function div(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                int256 yInt = y.unwrap();
                if (xInt == uMIN_SD59x18 || yInt == uMIN_SD59x18) {
                    revert Errors.PRBMath_SD59x18_Div_InputTooSmall();
                }
                // Get hold of the absolute values of x and y.
                uint256 xAbs;
                uint256 yAbs;
                unchecked {
                    xAbs = xInt < 0 ? uint256(-xInt) : uint256(xInt);
                    yAbs = yInt < 0 ? uint256(-yInt) : uint256(yInt);
                }
                // Compute the absolute value (x*UNIT÷y). The resulting value must fit in SD59x18.
                uint256 resultAbs = Common.mulDiv(xAbs, uint256(uUNIT), yAbs);
                if (resultAbs > uint256(uMAX_SD59x18)) {
                    revert Errors.PRBMath_SD59x18_Div_Overflow(x, y);
                }
                // Check if x and y have the same sign using two's complement representation. The left-most bit represents the sign (1 for
                // negative, 0 for positive or zero).
                bool sameSign = (xInt ^ yInt) > -1;
                // If the inputs have the same sign, the result should be positive. Otherwise, it should be negative.
                unchecked {
                    result = wrap(sameSign ? int256(resultAbs) : -int256(resultAbs));
                }
            }
            /// @notice Calculates the natural exponent of x using the following formula:
            ///
            /// $$
            /// e^x = 2^{x * log_2{e}}
            /// $$
            ///
            /// @dev Notes:
            /// - Refer to the notes in {exp2}.
            ///
            /// Requirements:
            /// - Refer to the requirements in {exp2}.
            /// - x < 133_084258667509499441.
            ///
            /// @param x The exponent as an SD59x18 number.
            /// @return result The result as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function exp(SD59x18 x) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                // Any input less than the threshold returns zero.
                // This check also prevents an overflow for very small numbers.
                if (xInt < uEXP_MIN_THRESHOLD) {
                    return ZERO;
                }
                // This check prevents values greater than 192e18 from being passed to {exp2}.
                if (xInt > uEXP_MAX_INPUT) {
                    revert Errors.PRBMath_SD59x18_Exp_InputTooBig(x);
                }
                unchecked {
                    // Inline the fixed-point multiplication to save gas.
                    int256 doubleUnitProduct = xInt * uLOG2_E;
                    result = exp2(wrap(doubleUnitProduct / uUNIT));
                }
            }
            /// @notice Calculates the binary exponent of x using the binary fraction method using the following formula:
            ///
            /// $$
            /// 2^{-x} = \\frac{1}{2^x}
            /// $$
            ///
            /// @dev See https://ethereum.stackexchange.com/q/79903/24693.
            ///
            /// Notes:
            /// - If x < -59_794705707972522261, the result is zero.
            ///
            /// Requirements:
            /// - x < 192e18.
            /// - The result must fit in SD59x18.
            ///
            /// @param x The exponent as an SD59x18 number.
            /// @return result The result as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function exp2(SD59x18 x) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                if (xInt < 0) {
                    // The inverse of any number less than the threshold is truncated to zero.
                    if (xInt < uEXP2_MIN_THRESHOLD) {
                        return ZERO;
                    }
                    unchecked {
                        // Inline the fixed-point inversion to save gas.
                        result = wrap(uUNIT_SQUARED / exp2(wrap(-xInt)).unwrap());
                    }
                } else {
                    // Numbers greater than or equal to 192e18 don't fit in the 192.64-bit format.
                    if (xInt > uEXP2_MAX_INPUT) {
                        revert Errors.PRBMath_SD59x18_Exp2_InputTooBig(x);
                    }
                    unchecked {
                        // Convert x to the 192.64-bit fixed-point format.
                        uint256 x_192x64 = uint256((xInt << 64) / uUNIT);
                        // It is safe to cast the result to int256 due to the checks above.
                        result = wrap(int256(Common.exp2(x_192x64)));
                    }
                }
            }
            /// @notice Yields the greatest whole number less than or equal to x.
            ///
            /// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional
            /// counterparts. See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
            ///
            /// Requirements:
            /// - x ≥ MIN_WHOLE_SD59x18
            ///
            /// @param x The SD59x18 number to floor.
            /// @return result The greatest whole number less than or equal to x, as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function floor(SD59x18 x) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                if (xInt < uMIN_WHOLE_SD59x18) {
                    revert Errors.PRBMath_SD59x18_Floor_Underflow(x);
                }
                int256 remainder = xInt % uUNIT;
                if (remainder == 0) {
                    result = x;
                } else {
                    unchecked {
                        // Solidity uses C fmod style, which returns a modulus with the same sign as x.
                        int256 resultInt = xInt - remainder;
                        if (xInt < 0) {
                            resultInt -= uUNIT;
                        }
                        result = wrap(resultInt);
                    }
                }
            }
            /// @notice Yields the excess beyond the floor of x for positive numbers and the part of the number to the right.
            /// of the radix point for negative numbers.
            /// @dev Based on the odd function definition. https://en.wikipedia.org/wiki/Fractional_part
            /// @param x The SD59x18 number to get the fractional part of.
            /// @return result The fractional part of x as an SD59x18 number.
            function frac(SD59x18 x) pure returns (SD59x18 result) {
                result = wrap(x.unwrap() % uUNIT);
            }
            /// @notice Calculates the geometric mean of x and y, i.e. $\\sqrt{x * y}$.
            ///
            /// @dev Notes:
            /// - The result is rounded toward zero.
            ///
            /// Requirements:
            /// - x * y must fit in SD59x18.
            /// - x * y must not be negative, since complex numbers are not supported.
            ///
            /// @param x The first operand as an SD59x18 number.
            /// @param y The second operand as an SD59x18 number.
            /// @return result The result as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function gm(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                int256 yInt = y.unwrap();
                if (xInt == 0 || yInt == 0) {
                    return ZERO;
                }
                unchecked {
                    // Equivalent to `xy / x != y`. Checking for overflow this way is faster than letting Solidity do it.
                    int256 xyInt = xInt * yInt;
                    if (xyInt / xInt != yInt) {
                        revert Errors.PRBMath_SD59x18_Gm_Overflow(x, y);
                    }
                    // The product must not be negative, since complex numbers are not supported.
                    if (xyInt < 0) {
                        revert Errors.PRBMath_SD59x18_Gm_NegativeProduct(x, y);
                    }
                    // We don't need to multiply the result by `UNIT` here because the x*y product picked up a factor of `UNIT`
                    // during multiplication. See the comments in {Common.sqrt}.
                    uint256 resultUint = Common.sqrt(uint256(xyInt));
                    result = wrap(int256(resultUint));
                }
            }
            /// @notice Calculates the inverse of x.
            ///
            /// @dev Notes:
            /// - The result is rounded toward zero.
            ///
            /// Requirements:
            /// - x must not be zero.
            ///
            /// @param x The SD59x18 number for which to calculate the inverse.
            /// @return result The inverse as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function inv(SD59x18 x) pure returns (SD59x18 result) {
                result = wrap(uUNIT_SQUARED / x.unwrap());
            }
            /// @notice Calculates the natural logarithm of x using the following formula:
            ///
            /// $$
            /// ln{x} = log_2{x} / log_2{e}
            /// $$
            ///
            /// @dev Notes:
            /// - Refer to the notes in {log2}.
            /// - The precision isn't sufficiently fine-grained to return exactly `UNIT` when the input is `E`.
            ///
            /// Requirements:
            /// - Refer to the requirements in {log2}.
            ///
            /// @param x The SD59x18 number for which to calculate the natural logarithm.
            /// @return result The natural logarithm as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function ln(SD59x18 x) pure returns (SD59x18 result) {
                // Inline the fixed-point multiplication to save gas. This is overflow-safe because the maximum value that
                // {log2} can return is ~195_205294292027477728.
                result = wrap(log2(x).unwrap() * uUNIT / uLOG2_E);
            }
            /// @notice Calculates the common logarithm of x using the following formula:
            ///
            /// $$
            /// log_{10}{x} = log_2{x} / log_2{10}
            /// $$
            ///
            /// However, if x is an exact power of ten, a hard coded value is returned.
            ///
            /// @dev Notes:
            /// - Refer to the notes in {log2}.
            ///
            /// Requirements:
            /// - Refer to the requirements in {log2}.
            ///
            /// @param x The SD59x18 number for which to calculate the common logarithm.
            /// @return result The common logarithm as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function log10(SD59x18 x) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                if (xInt < 0) {
                    revert Errors.PRBMath_SD59x18_Log_InputTooSmall(x);
                }
                // Note that the `mul` in this block is the standard multiplication operation, not {SD59x18.mul}.
                // prettier-ignore
                assembly ("memory-safe") {
                    switch x
                    case 1 { result := mul(uUNIT, sub(0, 18)) }
                    case 10 { result := mul(uUNIT, sub(1, 18)) }
                    case 100 { result := mul(uUNIT, sub(2, 18)) }
                    case 1000 { result := mul(uUNIT, sub(3, 18)) }
                    case 10000 { result := mul(uUNIT, sub(4, 18)) }
                    case 100000 { result := mul(uUNIT, sub(5, 18)) }
                    case 1000000 { result := mul(uUNIT, sub(6, 18)) }
                    case 10000000 { result := mul(uUNIT, sub(7, 18)) }
                    case 100000000 { result := mul(uUNIT, sub(8, 18)) }
                    case 1000000000 { result := mul(uUNIT, sub(9, 18)) }
                    case 10000000000 { result := mul(uUNIT, sub(10, 18)) }
                    case 100000000000 { result := mul(uUNIT, sub(11, 18)) }
                    case 1000000000000 { result := mul(uUNIT, sub(12, 18)) }
                    case 10000000000000 { result := mul(uUNIT, sub(13, 18)) }
                    case 100000000000000 { result := mul(uUNIT, sub(14, 18)) }
                    case 1000000000000000 { result := mul(uUNIT, sub(15, 18)) }
                    case 10000000000000000 { result := mul(uUNIT, sub(16, 18)) }
                    case 100000000000000000 { result := mul(uUNIT, sub(17, 18)) }
                    case 1000000000000000000 { result := 0 }
                    case 10000000000000000000 { result := uUNIT }
                    case 100000000000000000000 { result := mul(uUNIT, 2) }
                    case 1000000000000000000000 { result := mul(uUNIT, 3) }
                    case 10000000000000000000000 { result := mul(uUNIT, 4) }
                    case 100000000000000000000000 { result := mul(uUNIT, 5) }
                    case 1000000000000000000000000 { result := mul(uUNIT, 6) }
                    case 10000000000000000000000000 { result := mul(uUNIT, 7) }
                    case 100000000000000000000000000 { result := mul(uUNIT, 8) }
                    case 1000000000000000000000000000 { result := mul(uUNIT, 9) }
                    case 10000000000000000000000000000 { result := mul(uUNIT, 10) }
                    case 100000000000000000000000000000 { result := mul(uUNIT, 11) }
                    case 1000000000000000000000000000000 { result := mul(uUNIT, 12) }
                    case 10000000000000000000000000000000 { result := mul(uUNIT, 13) }
                    case 100000000000000000000000000000000 { result := mul(uUNIT, 14) }
                    case 1000000000000000000000000000000000 { result := mul(uUNIT, 15) }
                    case 10000000000000000000000000000000000 { result := mul(uUNIT, 16) }
                    case 100000000000000000000000000000000000 { result := mul(uUNIT, 17) }
                    case 1000000000000000000000000000000000000 { result := mul(uUNIT, 18) }
                    case 10000000000000000000000000000000000000 { result := mul(uUNIT, 19) }
                    case 100000000000000000000000000000000000000 { result := mul(uUNIT, 20) }
                    case 1000000000000000000000000000000000000000 { result := mul(uUNIT, 21) }
                    case 10000000000000000000000000000000000000000 { result := mul(uUNIT, 22) }
                    case 100000000000000000000000000000000000000000 { result := mul(uUNIT, 23) }
                    case 1000000000000000000000000000000000000000000 { result := mul(uUNIT, 24) }
                    case 10000000000000000000000000000000000000000000 { result := mul(uUNIT, 25) }
                    case 100000000000000000000000000000000000000000000 { result := mul(uUNIT, 26) }
                    case 1000000000000000000000000000000000000000000000 { result := mul(uUNIT, 27) }
                    case 10000000000000000000000000000000000000000000000 { result := mul(uUNIT, 28) }
                    case 100000000000000000000000000000000000000000000000 { result := mul(uUNIT, 29) }
                    case 1000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 30) }
                    case 10000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 31) }
                    case 100000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 32) }
                    case 1000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 33) }
                    case 10000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 34) }
                    case 100000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 35) }
                    case 1000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 36) }
                    case 10000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 37) }
                    case 100000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 38) }
                    case 1000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 39) }
                    case 10000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 40) }
                    case 100000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 41) }
                    case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 42) }
                    case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 43) }
                    case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 44) }
                    case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 45) }
                    case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 46) }
                    case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 47) }
                    case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 48) }
                    case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 49) }
                    case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 50) }
                    case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 51) }
                    case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 52) }
                    case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 53) }
                    case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 54) }
                    case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 55) }
                    case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 56) }
                    case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 57) }
                    case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 58) }
                    default { result := uMAX_SD59x18 }
                }
                if (result.unwrap() == uMAX_SD59x18) {
                    unchecked {
                        // Inline the fixed-point division to save gas.
                        result = wrap(log2(x).unwrap() * uUNIT / uLOG2_10);
                    }
                }
            }
            /// @notice Calculates the binary logarithm of x using the iterative approximation algorithm:
            ///
            /// $$
            /// log_2{x} = n + log_2{y}, \\text{ where } y = x*2^{-n}, \\ y \\in [1, 2)
            /// $$
            ///
            /// For $0 \\leq x \\lt 1$, the input is inverted:
            ///
            /// $$
            /// log_2{x} = -log_2{\\frac{1}{x}}
            /// $$
            ///
            /// @dev See https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation.
            ///
            /// Notes:
            /// - Due to the lossy precision of the iterative approximation, the results are not perfectly accurate to the last decimal.
            ///
            /// Requirements:
            /// - x > 0
            ///
            /// @param x The SD59x18 number for which to calculate the binary logarithm.
            /// @return result The binary logarithm as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function log2(SD59x18 x) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                if (xInt <= 0) {
                    revert Errors.PRBMath_SD59x18_Log_InputTooSmall(x);
                }
                unchecked {
                    int256 sign;
                    if (xInt >= uUNIT) {
                        sign = 1;
                    } else {
                        sign = -1;
                        // Inline the fixed-point inversion to save gas.
                        xInt = uUNIT_SQUARED / xInt;
                    }
                    // Calculate the integer part of the logarithm.
                    uint256 n = Common.msb(uint256(xInt / uUNIT));
                    // This is the integer part of the logarithm as an SD59x18 number. The operation can't overflow
                    // because n is at most 255, `UNIT` is 1e18, and the sign is either 1 or -1.
                    int256 resultInt = int256(n) * uUNIT;
                    // Calculate $y = x * 2^{-n}$.
                    int256 y = xInt >> n;
                    // If y is the unit number, the fractional part is zero.
                    if (y == uUNIT) {
                        return wrap(resultInt * sign);
                    }
                    // Calculate the fractional part via the iterative approximation.
                    // The `delta >>= 1` part is equivalent to `delta /= 2`, but shifting bits is more gas efficient.
                    int256 DOUBLE_UNIT = 2e18;
                    for (int256 delta = uHALF_UNIT; delta > 0; delta >>= 1) {
                        y = (y * y) / uUNIT;
                        // Is y^2 >= 2e18 and so in the range [2e18, 4e18)?
                        if (y >= DOUBLE_UNIT) {
                            // Add the 2^{-m} factor to the logarithm.
                            resultInt = resultInt + delta;
                            // Halve y, which corresponds to z/2 in the Wikipedia article.
                            y >>= 1;
                        }
                    }
                    resultInt *= sign;
                    result = wrap(resultInt);
                }
            }
            /// @notice Multiplies two SD59x18 numbers together, returning a new SD59x18 number.
            ///
            /// @dev Notes:
            /// - Refer to the notes in {Common.mulDiv18}.
            ///
            /// Requirements:
            /// - Refer to the requirements in {Common.mulDiv18}.
            /// - None of the inputs can be `MIN_SD59x18`.
            /// - The result must fit in SD59x18.
            ///
            /// @param x The multiplicand as an SD59x18 number.
            /// @param y The multiplier as an SD59x18 number.
            /// @return result The product as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function mul(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                int256 yInt = y.unwrap();
                if (xInt == uMIN_SD59x18 || yInt == uMIN_SD59x18) {
                    revert Errors.PRBMath_SD59x18_Mul_InputTooSmall();
                }
                // Get hold of the absolute values of x and y.
                uint256 xAbs;
                uint256 yAbs;
                unchecked {
                    xAbs = xInt < 0 ? uint256(-xInt) : uint256(xInt);
                    yAbs = yInt < 0 ? uint256(-yInt) : uint256(yInt);
                }
                // Compute the absolute value (x*y÷UNIT). The resulting value must fit in SD59x18.
                uint256 resultAbs = Common.mulDiv18(xAbs, yAbs);
                if (resultAbs > uint256(uMAX_SD59x18)) {
                    revert Errors.PRBMath_SD59x18_Mul_Overflow(x, y);
                }
                // Check if x and y have the same sign using two's complement representation. The left-most bit represents the sign (1 for
                // negative, 0 for positive or zero).
                bool sameSign = (xInt ^ yInt) > -1;
                // If the inputs have the same sign, the result should be positive. Otherwise, it should be negative.
                unchecked {
                    result = wrap(sameSign ? int256(resultAbs) : -int256(resultAbs));
                }
            }
            /// @notice Raises x to the power of y using the following formula:
            ///
            /// $$
            /// x^y = 2^{log_2{x} * y}
            /// $$
            ///
            /// @dev Notes:
            /// - Refer to the notes in {exp2}, {log2}, and {mul}.
            /// - Returns `UNIT` for 0^0.
            ///
            /// Requirements:
            /// - Refer to the requirements in {exp2}, {log2}, and {mul}.
            ///
            /// @param x The base as an SD59x18 number.
            /// @param y Exponent to raise x to, as an SD59x18 number
            /// @return result x raised to power y, as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function pow(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                int256 yInt = y.unwrap();
                // If both x and y are zero, the result is `UNIT`. If just x is zero, the result is always zero.
                if (xInt == 0) {
                    return yInt == 0 ? UNIT : ZERO;
                }
                // If x is `UNIT`, the result is always `UNIT`.
                else if (xInt == uUNIT) {
                    return UNIT;
                }
                // If y is zero, the result is always `UNIT`.
                if (yInt == 0) {
                    return UNIT;
                }
                // If y is `UNIT`, the result is always x.
                else if (yInt == uUNIT) {
                    return x;
                }
                // Calculate the result using the formula.
                result = exp2(mul(log2(x), y));
            }
            /// @notice Raises x (an SD59x18 number) to the power y (an unsigned basic integer) using the well-known
            /// algorithm "exponentiation by squaring".
            ///
            /// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring.
            ///
            /// Notes:
            /// - Refer to the notes in {Common.mulDiv18}.
            /// - Returns `UNIT` for 0^0.
            ///
            /// Requirements:
            /// - Refer to the requirements in {abs} and {Common.mulDiv18}.
            /// - The result must fit in SD59x18.
            ///
            /// @param x The base as an SD59x18 number.
            /// @param y The exponent as a uint256.
            /// @return result The result as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function powu(SD59x18 x, uint256 y) pure returns (SD59x18 result) {
                uint256 xAbs = uint256(abs(x).unwrap());
                // Calculate the first iteration of the loop in advance.
                uint256 resultAbs = y & 1 > 0 ? xAbs : uint256(uUNIT);
                // Equivalent to `for(y /= 2; y > 0; y /= 2)`.
                uint256 yAux = y;
                for (yAux >>= 1; yAux > 0; yAux >>= 1) {
                    xAbs = Common.mulDiv18(xAbs, xAbs);
                    // Equivalent to `y % 2 == 1`.
                    if (yAux & 1 > 0) {
                        resultAbs = Common.mulDiv18(resultAbs, xAbs);
                    }
                }
                // The result must fit in SD59x18.
                if (resultAbs > uint256(uMAX_SD59x18)) {
                    revert Errors.PRBMath_SD59x18_Powu_Overflow(x, y);
                }
                unchecked {
                    // Is the base negative and the exponent odd? If yes, the result should be negative.
                    int256 resultInt = int256(resultAbs);
                    bool isNegative = x.unwrap() < 0 && y & 1 == 1;
                    if (isNegative) {
                        resultInt = -resultInt;
                    }
                    result = wrap(resultInt);
                }
            }
            /// @notice Calculates the square root of x using the Babylonian method.
            ///
            /// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
            ///
            /// Notes:
            /// - Only the positive root is returned.
            /// - The result is rounded toward zero.
            ///
            /// Requirements:
            /// - x ≥ 0, since complex numbers are not supported.
            /// - x ≤ MAX_SD59x18 / UNIT
            ///
            /// @param x The SD59x18 number for which to calculate the square root.
            /// @return result The result as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function sqrt(SD59x18 x) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                if (xInt < 0) {
                    revert Errors.PRBMath_SD59x18_Sqrt_NegativeInput(x);
                }
                if (xInt > uMAX_SD59x18 / uUNIT) {
                    revert Errors.PRBMath_SD59x18_Sqrt_Overflow(x);
                }
                unchecked {
                    // Multiply x by `UNIT` to account for the factor of `UNIT` picked up when multiplying two SD59x18 numbers.
                    // In this case, the two numbers are both the square root.
                    uint256 resultUint = Common.sqrt(uint256(xInt * uUNIT));
                    result = wrap(int256(resultUint));
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "../Common.sol" as Common;
            import "./Errors.sol" as Errors;
            import { SD59x18 } from "../sd59x18/ValueType.sol";
            import { UD60x18 } from "../ud60x18/ValueType.sol";
            import { UD21x18 } from "./ValueType.sol";
            /// @notice Casts a UD21x18 number into SD59x18.
            /// @dev There is no overflow check because UD21x18 ⊆ SD59x18.
            function intoSD59x18(UD21x18 x) pure returns (SD59x18 result) {
                result = SD59x18.wrap(int256(uint256(UD21x18.unwrap(x))));
            }
            /// @notice Casts a UD21x18 number into UD60x18.
            /// @dev There is no overflow check because UD21x18 ⊆ UD60x18.
            function intoUD60x18(UD21x18 x) pure returns (UD60x18 result) {
                result = UD60x18.wrap(UD21x18.unwrap(x));
            }
            /// @notice Casts a UD21x18 number into uint128.
            /// @dev This is basically an alias for {unwrap}.
            function intoUint128(UD21x18 x) pure returns (uint128 result) {
                result = UD21x18.unwrap(x);
            }
            /// @notice Casts a UD21x18 number into uint256.
            /// @dev There is no overflow check because UD21x18 ⊆ uint256.
            function intoUint256(UD21x18 x) pure returns (uint256 result) {
                result = uint256(UD21x18.unwrap(x));
            }
            /// @notice Casts a UD21x18 number into uint40.
            /// @dev Requirements:
            /// - x ≤ MAX_UINT40
            function intoUint40(UD21x18 x) pure returns (uint40 result) {
                uint128 xUint = UD21x18.unwrap(x);
                if (xUint > uint128(Common.MAX_UINT40)) {
                    revert Errors.PRBMath_UD21x18_IntoUint40_Overflow(x);
                }
                result = uint40(xUint);
            }
            /// @notice Alias for {wrap}.
            function ud21x18(uint128 x) pure returns (UD21x18 result) {
                result = UD21x18.wrap(x);
            }
            /// @notice Unwrap a UD21x18 number into uint128.
            function unwrap(UD21x18 x) pure returns (uint128 result) {
                result = UD21x18.unwrap(x);
            }
            /// @notice Wraps a uint128 number into UD21x18.
            function wrap(uint128 x) pure returns (UD21x18 result) {
                result = UD21x18.wrap(x);
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol)
            pragma solidity ^0.8.20;
            import {IERC165} from "../../utils/introspection/IERC165.sol";
            /**
             * @dev Required interface of an ERC-721 compliant contract.
             */
            interface IERC721 is IERC165 {
                /**
                 * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
                 */
                event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
                /**
                 * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
                 */
                event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
                /**
                 * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
                 */
                event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
                /**
                 * @dev Returns the number of tokens in ``owner``'s account.
                 */
                function balanceOf(address owner) external view returns (uint256 balance);
                /**
                 * @dev Returns the owner of the `tokenId` token.
                 *
                 * Requirements:
                 *
                 * - `tokenId` must exist.
                 */
                function ownerOf(uint256 tokenId) external view returns (address owner);
                /**
                 * @dev Safely transfers `tokenId` token from `from` to `to`.
                 *
                 * Requirements:
                 *
                 * - `from` cannot be the zero address.
                 * - `to` cannot be the zero address.
                 * - `tokenId` token must exist and be owned by `from`.
                 * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
                 * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
                 *   a safe transfer.
                 *
                 * Emits a {Transfer} event.
                 */
                function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
                /**
                 * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
                 * are aware of the ERC-721 protocol to prevent tokens from being forever locked.
                 *
                 * Requirements:
                 *
                 * - `from` cannot be the zero address.
                 * - `to` cannot be the zero address.
                 * - `tokenId` token must exist and be owned by `from`.
                 * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or
                 *   {setApprovalForAll}.
                 * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
                 *   a safe transfer.
                 *
                 * Emits a {Transfer} event.
                 */
                function safeTransferFrom(address from, address to, uint256 tokenId) external;
                /**
                 * @dev Transfers `tokenId` token from `from` to `to`.
                 *
                 * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC-721
                 * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
                 * understand this adds an external call which potentially creates a reentrancy vulnerability.
                 *
                 * Requirements:
                 *
                 * - `from` cannot be the zero address.
                 * - `to` cannot be the zero address.
                 * - `tokenId` token must be owned by `from`.
                 * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
                 *
                 * Emits a {Transfer} event.
                 */
                function transferFrom(address from, address to, uint256 tokenId) external;
                /**
                 * @dev Gives permission to `to` to transfer `tokenId` token to another account.
                 * The approval is cleared when the token is transferred.
                 *
                 * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
                 *
                 * Requirements:
                 *
                 * - The caller must own the token or be an approved operator.
                 * - `tokenId` must exist.
                 *
                 * Emits an {Approval} event.
                 */
                function approve(address to, uint256 tokenId) external;
                /**
                 * @dev Approve or remove `operator` as an operator for the caller.
                 * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
                 *
                 * Requirements:
                 *
                 * - The `operator` cannot be the address zero.
                 *
                 * Emits an {ApprovalForAll} event.
                 */
                function setApprovalForAll(address operator, bool approved) external;
                /**
                 * @dev Returns the account approved for `tokenId` token.
                 *
                 * Requirements:
                 *
                 * - `tokenId` must exist.
                 */
                function getApproved(uint256 tokenId) external view returns (address operator);
                /**
                 * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
                 *
                 * See {setApprovalForAll}
                 */
                function isApprovedForAll(address owner, address operator) external view returns (bool);
            }
            // SPDX-License-Identifier: GPL-3.0-or-later
            pragma solidity >=0.8.19;
            /// @title IAdminable
            /// @notice Contract module that provides a basic access control mechanism, with an admin that can be
            /// granted exclusive access to specific functions. The inheriting contract must set the initial admin
            /// in the constructor.
            interface IAdminable {
                /*//////////////////////////////////////////////////////////////////////////
                                                   EVENTS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Emitted when the admin is transferred.
                /// @param oldAdmin The address of the old admin.
                /// @param newAdmin The address of the new admin.
                event TransferAdmin(address indexed oldAdmin, address indexed newAdmin);
                /*//////////////////////////////////////////////////////////////////////////
                                             CONSTANT FUNCTIONS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice The address of the admin account or contract.
                function admin() external view returns (address);
                /*//////////////////////////////////////////////////////////////////////////
                                           NON-CONSTANT FUNCTIONS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Transfers the contract admin to a new address.
                ///
                /// @dev Notes:
                /// - Does not revert if the admin is the same.
                /// - This function can potentially leave the contract without an admin, thereby removing any
                /// functionality that is only available to the admin.
                ///
                /// Requirements:
                /// - `msg.sender` must be the contract admin.
                ///
                /// @param newAdmin The address of the new admin.
                function transferAdmin(address newAdmin) external;
            }
            // SPDX-License-Identifier: GPL-3.0-or-later
            pragma solidity >=0.8.19;
            import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
            import { UD60x18 } from "@prb/math/src/UD60x18.sol";
            import { IAdminable } from "./IAdminable.sol";
            /// @title ISablierV2Controller
            /// @notice This contract is in charge of the Sablier V2 protocol configuration, handling such values as the
            /// protocol fees.
            interface ISablierV2Comptroller is IAdminable {
                /*//////////////////////////////////////////////////////////////////////////
                                                   EVENTS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Emitted when the admin sets a new flash fee.
                /// @param admin The address of the contract admin.
                /// @param oldFlashFee The old flash fee, denoted as a fixed-point number.
                /// @param newFlashFee The new flash fee, denoted as a fixed-point number.
                event SetFlashFee(address indexed admin, UD60x18 oldFlashFee, UD60x18 newFlashFee);
                /// @notice Emitted when the admin sets a new protocol fee for the provided ERC-20 asset.
                /// @param admin The address of the contract admin.
                /// @param asset The contract address of the ERC-20 asset the new protocol fee has been set for.
                /// @param oldProtocolFee The old protocol fee, denoted as a fixed-point number.
                /// @param newProtocolFee The new protocol fee, denoted as a fixed-point number.
                event SetProtocolFee(address indexed admin, IERC20 indexed asset, UD60x18 oldProtocolFee, UD60x18 newProtocolFee);
                /// @notice Emitted when the admin enables or disables an ERC-20 asset for flash loaning.
                /// @param admin The address of the contract admin.
                /// @param asset The contract address of the ERC-20 asset to toggle.
                /// @param newFlag Whether the ERC-20 asset can be flash loaned.
                event ToggleFlashAsset(address indexed admin, IERC20 indexed asset, bool newFlag);
                /*//////////////////////////////////////////////////////////////////////////
                                             CONSTANT FUNCTIONS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Retrieves the global flash fee, denoted as a fixed-point number where 1e18 is 100%.
                ///
                /// @dev Notes:
                /// - This fee represents a percentage, not an amount. Do not confuse it with {IERC3156FlashLender.flashFee},
                /// which calculates the fee amount for a specified flash loan amount.
                /// - Unlike the protocol fee, this is a global fee applied to all flash loans, not a per-asset fee.
                function flashFee() external view returns (UD60x18 fee);
                /// @notice Retrieves a flag indicating whether the provided ERC-20 asset can be flash loaned.
                /// @param token The contract address of the ERC-20 asset to check.
                function isFlashAsset(IERC20 token) external view returns (bool result);
                /// @notice Retrieves the protocol fee for all streams created with the provided ERC-20 asset.
                /// @param asset The contract address of the ERC-20 asset to query.
                /// @return fee The protocol fee denoted as a fixed-point number where 1e18 is 100%.
                function protocolFees(IERC20 asset) external view returns (UD60x18 fee);
                /*//////////////////////////////////////////////////////////////////////////
                                           NON-CONSTANT FUNCTIONS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Updates the flash fee charged on all flash loans made with any ERC-20 asset.
                ///
                /// @dev Emits a {SetFlashFee} event.
                ///
                /// Notes:
                /// - Does not revert if the fee is the same.
                ///
                /// Requirements:
                /// - `msg.sender` must be the contract admin.
                ///
                /// @param newFlashFee The new flash fee to set, denoted as a fixed-point number where 1e18 is 100%.
                function setFlashFee(UD60x18 newFlashFee) external;
                /// @notice Sets a new protocol fee that will be charged on all streams created with the provided ERC-20 asset.
                ///
                /// @dev Emits a {SetProtocolFee} event.
                ///
                /// Notes:
                /// - The fee is not denoted in units of the asset's decimals; it is a fixed-point number. Refer to the
                /// PRBMath documentation for more detail on the logic of UD60x18.
                /// - Does not revert if the fee is the same.
                ///
                /// Requirements:
                /// - `msg.sender` must be the contract admin.
                ///
                /// @param asset The contract address of the ERC-20 asset to update the fee for.
                /// @param newProtocolFee The new protocol fee, denoted as a fixed-point number where 1e18 is 100%.
                function setProtocolFee(IERC20 asset, UD60x18 newProtocolFee) external;
                /// @notice Toggles the flash loanability of an ERC-20 asset.
                ///
                /// @dev Emits a {ToggleFlashAsset} event.
                ///
                /// Requirements:
                /// - `msg.sender` must be the admin.
                ///
                /// @param asset The address of the ERC-20 asset to toggle.
                function toggleFlashAsset(IERC20 asset) external;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { SD1x18 } from "./ValueType.sol";
            /// @notice Thrown when trying to cast an SD1x18 number that doesn't fit in UD60x18.
            error PRBMath_SD1x18_ToUD60x18_Underflow(SD1x18 x);
            /// @notice Thrown when trying to cast an SD1x18 number that doesn't fit in uint128.
            error PRBMath_SD1x18_ToUint128_Underflow(SD1x18 x);
            /// @notice Thrown when trying to cast an SD1x18 number that doesn't fit in uint256.
            error PRBMath_SD1x18_ToUint256_Underflow(SD1x18 x);
            /// @notice Thrown when trying to cast an SD1x18 number that doesn't fit in uint40.
            error PRBMath_SD1x18_ToUint40_Overflow(SD1x18 x);
            /// @notice Thrown when trying to cast an SD1x18 number that doesn't fit in uint40.
            error PRBMath_SD1x18_ToUint40_Underflow(SD1x18 x);
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { SD21x18 } from "./ValueType.sol";
            /// @notice Thrown when trying to cast an SD21x18 number that doesn't fit in uint128.
            error PRBMath_SD21x18_ToUint128_Underflow(SD21x18 x);
            /// @notice Thrown when trying to cast an SD21x18 number that doesn't fit in UD60x18.
            error PRBMath_SD21x18_ToUD60x18_Underflow(SD21x18 x);
            /// @notice Thrown when trying to cast an SD21x18 number that doesn't fit in uint256.
            error PRBMath_SD21x18_ToUint256_Underflow(SD21x18 x);
            /// @notice Thrown when trying to cast an SD21x18 number that doesn't fit in uint40.
            error PRBMath_SD21x18_ToUint40_Overflow(SD21x18 x);
            /// @notice Thrown when trying to cast an SD21x18 number that doesn't fit in uint40.
            error PRBMath_SD21x18_ToUint40_Underflow(SD21x18 x);
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { SD59x18 } from "./ValueType.sol";
            /// @notice Thrown when taking the absolute value of `MIN_SD59x18`.
            error PRBMath_SD59x18_Abs_MinSD59x18();
            /// @notice Thrown when ceiling a number overflows SD59x18.
            error PRBMath_SD59x18_Ceil_Overflow(SD59x18 x);
            /// @notice Thrown when converting a basic integer to the fixed-point format overflows SD59x18.
            error PRBMath_SD59x18_Convert_Overflow(int256 x);
            /// @notice Thrown when converting a basic integer to the fixed-point format underflows SD59x18.
            error PRBMath_SD59x18_Convert_Underflow(int256 x);
            /// @notice Thrown when dividing two numbers and one of them is `MIN_SD59x18`.
            error PRBMath_SD59x18_Div_InputTooSmall();
            /// @notice Thrown when dividing two numbers and one of the intermediary unsigned results overflows SD59x18.
            error PRBMath_SD59x18_Div_Overflow(SD59x18 x, SD59x18 y);
            /// @notice Thrown when taking the natural exponent of a base greater than 133_084258667509499441.
            error PRBMath_SD59x18_Exp_InputTooBig(SD59x18 x);
            /// @notice Thrown when taking the binary exponent of a base greater than 192e18.
            error PRBMath_SD59x18_Exp2_InputTooBig(SD59x18 x);
            /// @notice Thrown when flooring a number underflows SD59x18.
            error PRBMath_SD59x18_Floor_Underflow(SD59x18 x);
            /// @notice Thrown when taking the geometric mean of two numbers and their product is negative.
            error PRBMath_SD59x18_Gm_NegativeProduct(SD59x18 x, SD59x18 y);
            /// @notice Thrown when taking the geometric mean of two numbers and multiplying them overflows SD59x18.
            error PRBMath_SD59x18_Gm_Overflow(SD59x18 x, SD59x18 y);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in SD1x18.
            error PRBMath_SD59x18_IntoSD1x18_Overflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in SD1x18.
            error PRBMath_SD59x18_IntoSD1x18_Underflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in SD21x18.
            error PRBMath_SD59x18_IntoSD21x18_Overflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in SD21x18.
            error PRBMath_SD59x18_IntoSD21x18_Underflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in UD2x18.
            error PRBMath_SD59x18_IntoUD2x18_Overflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in UD2x18.
            error PRBMath_SD59x18_IntoUD2x18_Underflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in UD21x18.
            error PRBMath_SD59x18_IntoUD21x18_Overflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in UD21x18.
            error PRBMath_SD59x18_IntoUD21x18_Underflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in UD60x18.
            error PRBMath_SD59x18_IntoUD60x18_Underflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in uint128.
            error PRBMath_SD59x18_IntoUint128_Overflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in uint128.
            error PRBMath_SD59x18_IntoUint128_Underflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in uint256.
            error PRBMath_SD59x18_IntoUint256_Underflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in uint40.
            error PRBMath_SD59x18_IntoUint40_Overflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in uint40.
            error PRBMath_SD59x18_IntoUint40_Underflow(SD59x18 x);
            /// @notice Thrown when taking the logarithm of a number less than or equal to zero.
            error PRBMath_SD59x18_Log_InputTooSmall(SD59x18 x);
            /// @notice Thrown when multiplying two numbers and one of the inputs is `MIN_SD59x18`.
            error PRBMath_SD59x18_Mul_InputTooSmall();
            /// @notice Thrown when multiplying two numbers and the intermediary absolute result overflows SD59x18.
            error PRBMath_SD59x18_Mul_Overflow(SD59x18 x, SD59x18 y);
            /// @notice Thrown when raising a number to a power and the intermediary absolute result overflows SD59x18.
            error PRBMath_SD59x18_Powu_Overflow(SD59x18 x, uint256 y);
            /// @notice Thrown when taking the square root of a negative number.
            error PRBMath_SD59x18_Sqrt_NegativeInput(SD59x18 x);
            /// @notice Thrown when the calculating the square root overflows SD59x18.
            error PRBMath_SD59x18_Sqrt_Overflow(SD59x18 x);
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { UD21x18 } from "./ValueType.sol";
            /// @notice Thrown when trying to cast a UD21x18 number that doesn't fit in uint40.
            error PRBMath_UD21x18_IntoUint40_Overflow(UD21x18 x);
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)
            pragma solidity ^0.8.20;
            /**
             * @dev Interface of the ERC-165 standard, as defined in the
             * https://eips.ethereum.org/EIPS/eip-165[ERC].
             *
             * Implementers can declare support of contract interfaces, which can then be
             * queried by others ({ERC165Checker}).
             *
             * For an implementation, see {ERC165}.
             */
            interface IERC165 {
                /**
                 * @dev Returns true if this contract implements the interface defined by
                 * `interfaceId`. See the corresponding
                 * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
                 * to learn more about how these ids are created.
                 *
                 * This function call must use less than 30 000 gas.
                 */
                function supportsInterface(bytes4 interfaceId) external view returns (bool);
            }
            

            File 5 of 6: SquidRouter
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            import { IUpgradable } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IUpgradable.sol';
            /**
             * @title IAxelarGasService Interface
             * @notice This is an interface for the AxelarGasService contract which manages gas payments
             * and refunds for cross-chain communication on the Axelar network.
             * @dev This interface inherits IUpgradable
             */
            interface IAxelarGasService is IUpgradable {
                error InvalidAddress();
                error NotCollector();
                error InvalidAmounts();
                event GasPaidForContractCall(
                    address indexed sourceAddress,
                    string destinationChain,
                    string destinationAddress,
                    bytes32 indexed payloadHash,
                    address gasToken,
                    uint256 gasFeeAmount,
                    address refundAddress
                );
                event GasPaidForContractCallWithToken(
                    address indexed sourceAddress,
                    string destinationChain,
                    string destinationAddress,
                    bytes32 indexed payloadHash,
                    string symbol,
                    uint256 amount,
                    address gasToken,
                    uint256 gasFeeAmount,
                    address refundAddress
                );
                event NativeGasPaidForContractCall(
                    address indexed sourceAddress,
                    string destinationChain,
                    string destinationAddress,
                    bytes32 indexed payloadHash,
                    uint256 gasFeeAmount,
                    address refundAddress
                );
                event NativeGasPaidForContractCallWithToken(
                    address indexed sourceAddress,
                    string destinationChain,
                    string destinationAddress,
                    bytes32 indexed payloadHash,
                    string symbol,
                    uint256 amount,
                    uint256 gasFeeAmount,
                    address refundAddress
                );
                event GasPaidForExpressCall(
                    address indexed sourceAddress,
                    string destinationChain,
                    string destinationAddress,
                    bytes32 indexed payloadHash,
                    address gasToken,
                    uint256 gasFeeAmount,
                    address refundAddress
                );
                event GasPaidForExpressCallWithToken(
                    address indexed sourceAddress,
                    string destinationChain,
                    string destinationAddress,
                    bytes32 indexed payloadHash,
                    string symbol,
                    uint256 amount,
                    address gasToken,
                    uint256 gasFeeAmount,
                    address refundAddress
                );
                event NativeGasPaidForExpressCall(
                    address indexed sourceAddress,
                    string destinationChain,
                    string destinationAddress,
                    bytes32 indexed payloadHash,
                    uint256 gasFeeAmount,
                    address refundAddress
                );
                event NativeGasPaidForExpressCallWithToken(
                    address indexed sourceAddress,
                    string destinationChain,
                    string destinationAddress,
                    bytes32 indexed payloadHash,
                    string symbol,
                    uint256 amount,
                    uint256 gasFeeAmount,
                    address refundAddress
                );
                event GasAdded(bytes32 indexed txHash, uint256 indexed logIndex, address gasToken, uint256 gasFeeAmount, address refundAddress);
                event NativeGasAdded(bytes32 indexed txHash, uint256 indexed logIndex, uint256 gasFeeAmount, address refundAddress);
                event ExpressGasAdded(bytes32 indexed txHash, uint256 indexed logIndex, address gasToken, uint256 gasFeeAmount, address refundAddress);
                event NativeExpressGasAdded(bytes32 indexed txHash, uint256 indexed logIndex, uint256 gasFeeAmount, address refundAddress);
                event Refunded(bytes32 indexed txHash, uint256 indexed logIndex, address payable receiver, address token, uint256 amount);
                /**
                 * @notice Pay for gas using ERC20 tokens for a contract call on a destination chain.
                 * @dev This function is called on the source chain before calling the gateway to execute a remote contract.
                 * @param sender The address making the payment
                 * @param destinationChain The target chain where the contract call will be made
                 * @param destinationAddress The target address on the destination chain
                 * @param payload Data payload for the contract call
                 * @param gasToken The address of the ERC20 token used to pay for gas
                 * @param gasFeeAmount The amount of tokens to pay for gas
                 * @param refundAddress The address where refunds, if any, should be sent
                 */
                function payGasForContractCall(
                    address sender,
                    string calldata destinationChain,
                    string calldata destinationAddress,
                    bytes calldata payload,
                    address gasToken,
                    uint256 gasFeeAmount,
                    address refundAddress
                ) external;
                /**
                 * @notice Pay for gas using ERC20 tokens for a contract call with tokens on a destination chain.
                 * @dev This function is called on the source chain before calling the gateway to execute a remote contract.
                 * @param sender The address making the payment
                 * @param destinationChain The target chain where the contract call with tokens will be made
                 * @param destinationAddress The target address on the destination chain
                 * @param payload Data payload for the contract call with tokens
                 * @param symbol The symbol of the token to be sent with the call
                 * @param amount The amount of tokens to be sent with the call
                 * @param gasToken The address of the ERC20 token used to pay for gas
                 * @param gasFeeAmount The amount of tokens to pay for gas
                 * @param refundAddress The address where refunds, if any, should be sent
                 */
                function payGasForContractCallWithToken(
                    address sender,
                    string calldata destinationChain,
                    string calldata destinationAddress,
                    bytes calldata payload,
                    string calldata symbol,
                    uint256 amount,
                    address gasToken,
                    uint256 gasFeeAmount,
                    address refundAddress
                ) external;
                /**
                 * @notice Pay for gas using native currency for a contract call on a destination chain.
                 * @dev This function is called on the source chain before calling the gateway to execute a remote contract.
                 * @param sender The address making the payment
                 * @param destinationChain The target chain where the contract call will be made
                 * @param destinationAddress The target address on the destination chain
                 * @param payload Data payload for the contract call
                 * @param refundAddress The address where refunds, if any, should be sent
                 */
                function payNativeGasForContractCall(
                    address sender,
                    string calldata destinationChain,
                    string calldata destinationAddress,
                    bytes calldata payload,
                    address refundAddress
                ) external payable;
                /**
                 * @notice Pay for gas using native currency for a contract call with tokens on a destination chain.
                 * @dev This function is called on the source chain before calling the gateway to execute a remote contract.
                 * @param sender The address making the payment
                 * @param destinationChain The target chain where the contract call with tokens will be made
                 * @param destinationAddress The target address on the destination chain
                 * @param payload Data payload for the contract call with tokens
                 * @param symbol The symbol of the token to be sent with the call
                 * @param amount The amount of tokens to be sent with the call
                 * @param refundAddress The address where refunds, if any, should be sent
                 */
                function payNativeGasForContractCallWithToken(
                    address sender,
                    string calldata destinationChain,
                    string calldata destinationAddress,
                    bytes calldata payload,
                    string calldata symbol,
                    uint256 amount,
                    address refundAddress
                ) external payable;
                /**
                 * @notice Pay for gas using ERC20 tokens for an express contract call on a destination chain.
                 * @dev This function is called on the source chain before calling the gateway to express execute a remote contract.
                 * @param sender The address making the payment
                 * @param destinationChain The target chain where the contract call will be made
                 * @param destinationAddress The target address on the destination chain
                 * @param payload Data payload for the contract call
                 * @param gasToken The address of the ERC20 token used to pay for gas
                 * @param gasFeeAmount The amount of tokens to pay for gas
                 * @param refundAddress The address where refunds, if any, should be sent
                 */
                function payGasForExpressCall(
                    address sender,
                    string calldata destinationChain,
                    string calldata destinationAddress,
                    bytes calldata payload,
                    address gasToken,
                    uint256 gasFeeAmount,
                    address refundAddress
                ) external;
                /**
                 * @notice Pay for gas using ERC20 tokens for an express contract call with tokens on a destination chain.
                 * @dev This function is called on the source chain before calling the gateway to express execute a remote contract.
                 * @param sender The address making the payment
                 * @param destinationChain The target chain where the contract call with tokens will be made
                 * @param destinationAddress The target address on the destination chain
                 * @param payload Data payload for the contract call with tokens
                 * @param symbol The symbol of the token to be sent with the call
                 * @param amount The amount of tokens to be sent with the call
                 * @param gasToken The address of the ERC20 token used to pay for gas
                 * @param gasFeeAmount The amount of tokens to pay for gas
                 * @param refundAddress The address where refunds, if any, should be sent
                 */
                function payGasForExpressCallWithToken(
                    address sender,
                    string calldata destinationChain,
                    string calldata destinationAddress,
                    bytes calldata payload,
                    string calldata symbol,
                    uint256 amount,
                    address gasToken,
                    uint256 gasFeeAmount,
                    address refundAddress
                ) external;
                /**
                 * @notice Pay for gas using native currency for an express contract call on a destination chain.
                 * @dev This function is called on the source chain before calling the gateway to execute a remote contract.
                 * @param sender The address making the payment
                 * @param destinationChain The target chain where the contract call will be made
                 * @param destinationAddress The target address on the destination chain
                 * @param payload Data payload for the contract call
                 * @param refundAddress The address where refunds, if any, should be sent
                 */
                function payNativeGasForExpressCall(
                    address sender,
                    string calldata destinationChain,
                    string calldata destinationAddress,
                    bytes calldata payload,
                    address refundAddress
                ) external payable;
                /**
                 * @notice Pay for gas using native currency for an express contract call with tokens on a destination chain.
                 * @dev This function is called on the source chain before calling the gateway to execute a remote contract.
                 * @param sender The address making the payment
                 * @param destinationChain The target chain where the contract call with tokens will be made
                 * @param destinationAddress The target address on the destination chain
                 * @param payload Data payload for the contract call with tokens
                 * @param symbol The symbol of the token to be sent with the call
                 * @param amount The amount of tokens to be sent with the call
                 * @param refundAddress The address where refunds, if any, should be sent
                 */
                function payNativeGasForExpressCallWithToken(
                    address sender,
                    string calldata destinationChain,
                    string calldata destinationAddress,
                    bytes calldata payload,
                    string calldata symbol,
                    uint256 amount,
                    address refundAddress
                ) external payable;
                /**
                 * @notice Add additional gas payment using ERC20 tokens after initiating a cross-chain call.
                 * @dev This function can be called on the source chain after calling the gateway to execute a remote contract.
                 * @param txHash The transaction hash of the cross-chain call
                 * @param logIndex The log index for the cross-chain call
                 * @param gasToken The ERC20 token address used to add gas
                 * @param gasFeeAmount The amount of tokens to add as gas
                 * @param refundAddress The address where refunds, if any, should be sent
                 */
                function addGas(
                    bytes32 txHash,
                    uint256 logIndex,
                    address gasToken,
                    uint256 gasFeeAmount,
                    address refundAddress
                ) external;
                /**
                 * @notice Add additional gas payment using native currency after initiating a cross-chain call.
                 * @dev This function can be called on the source chain after calling the gateway to execute a remote contract.
                 * @param txHash The transaction hash of the cross-chain call
                 * @param logIndex The log index for the cross-chain call
                 * @param refundAddress The address where refunds, if any, should be sent
                 */
                function addNativeGas(
                    bytes32 txHash,
                    uint256 logIndex,
                    address refundAddress
                ) external payable;
                /**
                 * @notice Add additional gas payment using ERC20 tokens after initiating an express cross-chain call.
                 * @dev This function can be called on the source chain after calling the gateway to express execute a remote contract.
                 * @param txHash The transaction hash of the cross-chain call
                 * @param logIndex The log index for the cross-chain call
                 * @param gasToken The ERC20 token address used to add gas
                 * @param gasFeeAmount The amount of tokens to add as gas
                 * @param refundAddress The address where refunds, if any, should be sent
                 */
                function addExpressGas(
                    bytes32 txHash,
                    uint256 logIndex,
                    address gasToken,
                    uint256 gasFeeAmount,
                    address refundAddress
                ) external;
                /**
                 * @notice Add additional gas payment using native currency after initiating an express cross-chain call.
                 * @dev This function can be called on the source chain after calling the gateway to express execute a remote contract.
                 * @param txHash The transaction hash of the cross-chain call
                 * @param logIndex The log index for the cross-chain call
                 * @param refundAddress The address where refunds, if any, should be sent
                 */
                function addNativeExpressGas(
                    bytes32 txHash,
                    uint256 logIndex,
                    address refundAddress
                ) external payable;
                /**
                 * @notice Allows the gasCollector to collect accumulated fees from the contract.
                 * @dev Use address(0) as the token address for native currency.
                 * @param receiver The address to receive the collected fees
                 * @param tokens Array of token addresses to be collected
                 * @param amounts Array of amounts to be collected for each respective token address
                 */
                function collectFees(
                    address payable receiver,
                    address[] calldata tokens,
                    uint256[] calldata amounts
                ) external;
                /**
                 * @notice Refunds gas payment to the receiver in relation to a specific cross-chain transaction.
                 * @dev Only callable by the gasCollector.
                 * @dev Use address(0) as the token address to refund native currency.
                 * @param txHash The transaction hash of the cross-chain call
                 * @param logIndex The log index for the cross-chain call
                 * @param receiver The address to receive the refund
                 * @param token The token address to be refunded
                 * @param amount The amount to refund
                 */
                function refund(
                    bytes32 txHash,
                    uint256 logIndex,
                    address payable receiver,
                    address token,
                    uint256 amount
                ) external;
                /**
                 * @notice Returns the address of the designated gas collector.
                 * @return address of the gas collector
                 */
                function gasCollector() external returns (address);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            import { IAxelarGateway } from '../interfaces/IAxelarGateway.sol';
            import { ExpressExecutorTracker } from './ExpressExecutorTracker.sol';
            import { SafeTokenTransferFrom, SafeTokenTransfer } from '../libs/SafeTransfer.sol';
            import { IERC20 } from '../interfaces/IERC20.sol';
            contract AxelarExpressExecutable is ExpressExecutorTracker {
                using SafeTokenTransfer for IERC20;
                using SafeTokenTransferFrom for IERC20;
                IAxelarGateway public immutable gateway;
                constructor(address gateway_) {
                    if (gateway_ == address(0)) revert InvalidAddress();
                    gateway = IAxelarGateway(gateway_);
                }
                function execute(
                    bytes32 commandId,
                    string calldata sourceChain,
                    string calldata sourceAddress,
                    bytes calldata payload
                ) external {
                    bytes32 payloadHash = keccak256(payload);
                    if (!gateway.validateContractCall(commandId, sourceChain, sourceAddress, payloadHash))
                        revert NotApprovedByGateway();
                    address expressExecutor = _popExpressExecutor(commandId, sourceChain, sourceAddress, payloadHash);
                    if (expressExecutor != address(0)) {
                        // slither-disable-next-line reentrancy-events
                        emit ExpressExecutionFulfilled(commandId, sourceChain, sourceAddress, payloadHash, expressExecutor);
                    } else {
                        _execute(sourceChain, sourceAddress, payload);
                    }
                }
                function executeWithToken(
                    bytes32 commandId,
                    string calldata sourceChain,
                    string calldata sourceAddress,
                    bytes calldata payload,
                    string calldata tokenSymbol,
                    uint256 amount
                ) external {
                    bytes32 payloadHash = keccak256(payload);
                    if (
                        !gateway.validateContractCallAndMint(
                            commandId,
                            sourceChain,
                            sourceAddress,
                            payloadHash,
                            tokenSymbol,
                            amount
                        )
                    ) revert NotApprovedByGateway();
                    address expressExecutor = _popExpressExecutorWithToken(
                        commandId,
                        sourceChain,
                        sourceAddress,
                        payloadHash,
                        tokenSymbol,
                        amount
                    );
                    if (expressExecutor != address(0)) {
                        // slither-disable-next-line reentrancy-events
                        emit ExpressExecutionWithTokenFulfilled(
                            commandId,
                            sourceChain,
                            sourceAddress,
                            payloadHash,
                            tokenSymbol,
                            amount,
                            expressExecutor
                        );
                        address gatewayToken = gateway.tokenAddresses(tokenSymbol);
                        IERC20(gatewayToken).safeTransfer(expressExecutor, amount);
                    } else {
                        _executeWithToken(sourceChain, sourceAddress, payload, tokenSymbol, amount);
                    }
                }
                function expressExecute(
                    bytes32 commandId,
                    string calldata sourceChain,
                    string calldata sourceAddress,
                    bytes calldata payload
                ) external payable virtual {
                    if (gateway.isCommandExecuted(commandId)) revert AlreadyExecuted();
                    address expressExecutor = msg.sender;
                    bytes32 payloadHash = keccak256(payload);
                    emit ExpressExecuted(commandId, sourceChain, sourceAddress, payloadHash, expressExecutor);
                    _setExpressExecutor(commandId, sourceChain, sourceAddress, payloadHash, expressExecutor);
                    _execute(sourceChain, sourceAddress, payload);
                }
                function expressExecuteWithToken(
                    bytes32 commandId,
                    string calldata sourceChain,
                    string calldata sourceAddress,
                    bytes calldata payload,
                    string calldata symbol,
                    uint256 amount
                ) external payable virtual {
                    if (gateway.isCommandExecuted(commandId)) revert AlreadyExecuted();
                    address expressExecutor = msg.sender;
                    address gatewayToken = gateway.tokenAddresses(symbol);
                    bytes32 payloadHash = keccak256(payload);
                    emit ExpressExecutedWithToken(
                        commandId,
                        sourceChain,
                        sourceAddress,
                        payloadHash,
                        symbol,
                        amount,
                        expressExecutor
                    );
                    _setExpressExecutorWithToken(
                        commandId,
                        sourceChain,
                        sourceAddress,
                        payloadHash,
                        symbol,
                        amount,
                        expressExecutor
                    );
                    IERC20(gatewayToken).safeTransferFrom(expressExecutor, address(this), amount);
                    _executeWithToken(sourceChain, sourceAddress, payload, symbol, amount);
                }
                function _execute(
                    string calldata sourceChain,
                    string calldata sourceAddress,
                    bytes calldata payload
                ) internal virtual {}
                function _executeWithToken(
                    string calldata sourceChain,
                    string calldata sourceAddress,
                    bytes calldata payload,
                    string calldata tokenSymbol,
                    uint256 amount
                ) internal virtual {}
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            import { IAxelarExpressExecutable } from '../interfaces/IAxelarExpressExecutable.sol';
            abstract contract ExpressExecutorTracker is IAxelarExpressExecutable {
                bytes32 internal constant PREFIX_EXPRESS_EXECUTE = keccak256('express-execute');
                bytes32 internal constant PREFIX_EXPRESS_EXECUTE_WITH_TOKEN = keccak256('express-execute-with-token');
                function _expressExecuteSlot(
                    bytes32 commandId,
                    string calldata sourceChain,
                    string calldata sourceAddress,
                    bytes32 payloadHash
                ) internal pure returns (bytes32 slot) {
                    slot = keccak256(abi.encode(PREFIX_EXPRESS_EXECUTE, commandId, sourceChain, sourceAddress, payloadHash));
                }
                function _expressExecuteWithTokenSlot(
                    bytes32 commandId,
                    string calldata sourceChain,
                    string calldata sourceAddress,
                    bytes32 payloadHash,
                    string calldata symbol,
                    uint256 amount
                ) internal pure returns (bytes32 slot) {
                    slot = keccak256(
                        abi.encode(
                            PREFIX_EXPRESS_EXECUTE_WITH_TOKEN,
                            commandId,
                            sourceChain,
                            sourceAddress,
                            payloadHash,
                            symbol,
                            amount
                        )
                    );
                }
                function getExpressExecutor(
                    bytes32 commandId,
                    string calldata sourceChain,
                    string calldata sourceAddress,
                    bytes32 payloadHash
                ) external view returns (address expressExecutor) {
                    bytes32 slot = _expressExecuteSlot(commandId, sourceChain, sourceAddress, payloadHash);
                    assembly {
                        expressExecutor := sload(slot)
                    }
                }
                function getExpressExecutorWithToken(
                    bytes32 commandId,
                    string calldata sourceChain,
                    string calldata sourceAddress,
                    bytes32 payloadHash,
                    string calldata symbol,
                    uint256 amount
                ) external view returns (address expressExecutor) {
                    bytes32 slot = _expressExecuteWithTokenSlot(commandId, sourceChain, sourceAddress, payloadHash, symbol, amount);
                    assembly {
                        expressExecutor := sload(slot)
                    }
                }
                function _setExpressExecutor(
                    bytes32 commandId,
                    string calldata sourceChain,
                    string calldata sourceAddress,
                    bytes32 payloadHash,
                    address expressExecutor
                ) internal {
                    bytes32 slot = _expressExecuteSlot(commandId, sourceChain, sourceAddress, payloadHash);
                    address currentExecutor;
                    assembly {
                        currentExecutor := sload(slot)
                    }
                    if (currentExecutor != address(0)) revert ExpressExecutorAlreadySet();
                    assembly {
                        sstore(slot, expressExecutor)
                    }
                }
                function _setExpressExecutorWithToken(
                    bytes32 commandId,
                    string calldata sourceChain,
                    string calldata sourceAddress,
                    bytes32 payloadHash,
                    string calldata symbol,
                    uint256 amount,
                    address expressExecutor
                ) internal {
                    bytes32 slot = _expressExecuteWithTokenSlot(commandId, sourceChain, sourceAddress, payloadHash, symbol, amount);
                    address currentExecutor;
                    assembly {
                        currentExecutor := sload(slot)
                    }
                    if (currentExecutor != address(0)) revert ExpressExecutorAlreadySet();
                    assembly {
                        sstore(slot, expressExecutor)
                    }
                }
                function _popExpressExecutor(
                    bytes32 commandId,
                    string calldata sourceChain,
                    string calldata sourceAddress,
                    bytes32 payloadHash
                ) internal returns (address expressExecutor) {
                    bytes32 slot = _expressExecuteSlot(commandId, sourceChain, sourceAddress, payloadHash);
                    assembly {
                        expressExecutor := sload(slot)
                        if expressExecutor {
                            sstore(slot, 0)
                        }
                    }
                }
                function _popExpressExecutorWithToken(
                    bytes32 commandId,
                    string calldata sourceChain,
                    string calldata sourceAddress,
                    bytes32 payloadHash,
                    string calldata symbol,
                    uint256 amount
                ) internal returns (address expressExecutor) {
                    bytes32 slot = _expressExecuteWithTokenSlot(commandId, sourceChain, sourceAddress, payloadHash, symbol, amount);
                    assembly {
                        expressExecutor := sload(slot)
                        if expressExecutor {
                            sstore(slot, 0)
                        }
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            import { IAxelarGateway } from './IAxelarGateway.sol';
            interface IAxelarExecutable {
                error InvalidAddress();
                error NotApprovedByGateway();
                function gateway() external view returns (IAxelarGateway);
                function execute(
                    bytes32 commandId,
                    string calldata sourceChain,
                    string calldata sourceAddress,
                    bytes calldata payload
                ) external;
                function executeWithToken(
                    bytes32 commandId,
                    string calldata sourceChain,
                    string calldata sourceAddress,
                    bytes calldata payload,
                    string calldata tokenSymbol,
                    uint256 amount
                ) external;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            import { IAxelarExecutable } from './IAxelarExecutable.sol';
            /**
             * @title IAxelarExpressExecutable
             * @notice Interface for the Axelar Express Executable contract.
             */
            interface IAxelarExpressExecutable is IAxelarExecutable {
                // Custom errors
                error AlreadyExecuted();
                error InsufficientValue();
                error ExpressExecutorAlreadySet();
                /**
                 * @notice Emitted when an express execution is successfully performed.
                 * @param commandId The unique identifier for the command.
                 * @param sourceChain The source chain.
                 * @param sourceAddress The source address.
                 * @param payloadHash The hash of the payload.
                 * @param expressExecutor The address of the express executor.
                 */
                event ExpressExecuted(
                    bytes32 indexed commandId,
                    string sourceChain,
                    string sourceAddress,
                    bytes32 payloadHash,
                    address indexed expressExecutor
                );
                /**
                 * @notice Emitted when an express execution with a token is successfully performed.
                 * @param commandId The unique identifier for the command.
                 * @param sourceChain The source chain.
                 * @param sourceAddress The source address.
                 * @param payloadHash The hash of the payload.
                 * @param symbol The token symbol.
                 * @param amount The amount of tokens.
                 * @param expressExecutor The address of the express executor.
                 */
                event ExpressExecutedWithToken(
                    bytes32 indexed commandId,
                    string sourceChain,
                    string sourceAddress,
                    bytes32 payloadHash,
                    string symbol,
                    uint256 indexed amount,
                    address indexed expressExecutor
                );
                /**
                 * @notice Emitted when an express execution is fulfilled.
                 * @param commandId The commandId for the contractCall.
                 * @param sourceChain The source chain.
                 * @param sourceAddress The source address.
                 * @param payloadHash The hash of the payload.
                 * @param expressExecutor The address of the express executor.
                 */
                event ExpressExecutionFulfilled(
                    bytes32 indexed commandId,
                    string sourceChain,
                    string sourceAddress,
                    bytes32 payloadHash,
                    address indexed expressExecutor
                );
                /**
                 * @notice Emitted when an express execution with a token is fulfilled.
                 * @param commandId The commandId for the contractCallWithToken.
                 * @param sourceChain The source chain.
                 * @param sourceAddress The source address.
                 * @param payloadHash The hash of the payload.
                 * @param symbol The token symbol.
                 * @param amount The amount of tokens.
                 * @param expressExecutor The address of the express executor.
                 */
                event ExpressExecutionWithTokenFulfilled(
                    bytes32 indexed commandId,
                    string sourceChain,
                    string sourceAddress,
                    bytes32 payloadHash,
                    string symbol,
                    uint256 indexed amount,
                    address indexed expressExecutor
                );
                /**
                 * @notice Returns the express executor for a given command.
                 * @param commandId The commandId for the contractCall.
                 * @param sourceChain The source chain.
                 * @param sourceAddress The source address.
                 * @param payloadHash The hash of the payload.
                 * @return expressExecutor The address of the express executor.
                 */
                function getExpressExecutor(
                    bytes32 commandId,
                    string calldata sourceChain,
                    string calldata sourceAddress,
                    bytes32 payloadHash
                ) external view returns (address expressExecutor);
                /**
                 * @notice Returns the express executor with token for a given command.
                 * @param commandId The commandId for the contractCallWithToken.
                 * @param sourceChain The source chain.
                 * @param sourceAddress The source address.
                 * @param payloadHash The hash of the payload.
                 * @param symbol The token symbol.
                 * @param amount The amount of tokens.
                 * @return expressExecutor The address of the express executor.
                 */
                function getExpressExecutorWithToken(
                    bytes32 commandId,
                    string calldata sourceChain,
                    string calldata sourceAddress,
                    bytes32 payloadHash,
                    string calldata symbol,
                    uint256 amount
                ) external view returns (address expressExecutor);
                /**
                 * @notice Express executes a contract call.
                 * @param commandId The commandId for the contractCall.
                 * @param sourceChain The source chain.
                 * @param sourceAddress The source address.
                 * @param payload The payload data.
                 */
                function expressExecute(
                    bytes32 commandId,
                    string calldata sourceChain,
                    string calldata sourceAddress,
                    bytes calldata payload
                ) external payable;
                /**
                 * @notice Express executes a contract call with token.
                 * @param commandId The commandId for the contractCallWithToken.
                 * @param sourceChain The source chain.
                 * @param sourceAddress The source address.
                 * @param payload The payload data.
                 * @param symbol The token symbol.
                 * @param amount The amount of token.
                 */
                function expressExecuteWithToken(
                    bytes32 commandId,
                    string calldata sourceChain,
                    string calldata sourceAddress,
                    bytes calldata payload,
                    string calldata symbol,
                    uint256 amount
                ) external payable;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            import { IGovernable } from './IGovernable.sol';
            import { IImplementation } from './IImplementation.sol';
            interface IAxelarGateway is IImplementation, IGovernable {
                /**********\\
                |* Errors *|
                \\**********/
                error NotSelf();
                error InvalidCodeHash();
                error SetupFailed();
                error InvalidAuthModule();
                error InvalidTokenDeployer();
                error InvalidAmount();
                error InvalidChainId();
                error InvalidCommands();
                error TokenDoesNotExist(string symbol);
                error TokenAlreadyExists(string symbol);
                error TokenDeployFailed(string symbol);
                error TokenContractDoesNotExist(address token);
                error BurnFailed(string symbol);
                error MintFailed(string symbol);
                error InvalidSetMintLimitsParams();
                error ExceedMintLimit(string symbol);
                /**********\\
                |* Events *|
                \\**********/
                event TokenSent(
                    address indexed sender,
                    string destinationChain,
                    string destinationAddress,
                    string symbol,
                    uint256 amount
                );
                event ContractCall(
                    address indexed sender,
                    string destinationChain,
                    string destinationContractAddress,
                    bytes32 indexed payloadHash,
                    bytes payload
                );
                event ContractCallWithToken(
                    address indexed sender,
                    string destinationChain,
                    string destinationContractAddress,
                    bytes32 indexed payloadHash,
                    bytes payload,
                    string symbol,
                    uint256 amount
                );
                event Executed(bytes32 indexed commandId);
                event TokenDeployed(string symbol, address tokenAddresses);
                event ContractCallApproved(
                    bytes32 indexed commandId,
                    string sourceChain,
                    string sourceAddress,
                    address indexed contractAddress,
                    bytes32 indexed payloadHash,
                    bytes32 sourceTxHash,
                    uint256 sourceEventIndex
                );
                event ContractCallApprovedWithMint(
                    bytes32 indexed commandId,
                    string sourceChain,
                    string sourceAddress,
                    address indexed contractAddress,
                    bytes32 indexed payloadHash,
                    string symbol,
                    uint256 amount,
                    bytes32 sourceTxHash,
                    uint256 sourceEventIndex
                );
                event ContractCallExecuted(bytes32 indexed commandId);
                event TokenMintLimitUpdated(string symbol, uint256 limit);
                event OperatorshipTransferred(bytes newOperatorsData);
                event Upgraded(address indexed implementation);
                /********************\\
                |* Public Functions *|
                \\********************/
                function sendToken(
                    string calldata destinationChain,
                    string calldata destinationAddress,
                    string calldata symbol,
                    uint256 amount
                ) external;
                function callContract(
                    string calldata destinationChain,
                    string calldata contractAddress,
                    bytes calldata payload
                ) external;
                function callContractWithToken(
                    string calldata destinationChain,
                    string calldata contractAddress,
                    bytes calldata payload,
                    string calldata symbol,
                    uint256 amount
                ) external;
                function isContractCallApproved(
                    bytes32 commandId,
                    string calldata sourceChain,
                    string calldata sourceAddress,
                    address contractAddress,
                    bytes32 payloadHash
                ) external view returns (bool);
                function isContractCallAndMintApproved(
                    bytes32 commandId,
                    string calldata sourceChain,
                    string calldata sourceAddress,
                    address contractAddress,
                    bytes32 payloadHash,
                    string calldata symbol,
                    uint256 amount
                ) external view returns (bool);
                function validateContractCall(
                    bytes32 commandId,
                    string calldata sourceChain,
                    string calldata sourceAddress,
                    bytes32 payloadHash
                ) external returns (bool);
                function validateContractCallAndMint(
                    bytes32 commandId,
                    string calldata sourceChain,
                    string calldata sourceAddress,
                    bytes32 payloadHash,
                    string calldata symbol,
                    uint256 amount
                ) external returns (bool);
                /***********\\
                |* Getters *|
                \\***********/
                function authModule() external view returns (address);
                function tokenDeployer() external view returns (address);
                function tokenMintLimit(string memory symbol) external view returns (uint256);
                function tokenMintAmount(string memory symbol) external view returns (uint256);
                function allTokensFrozen() external view returns (bool);
                function implementation() external view returns (address);
                function tokenAddresses(string memory symbol) external view returns (address);
                function tokenFrozen(string memory symbol) external view returns (bool);
                function isCommandExecuted(bytes32 commandId) external view returns (bool);
                /************************\\
                |* Governance Functions *|
                \\************************/
                function setTokenMintLimits(string[] calldata symbols, uint256[] calldata limits) external;
                function upgrade(
                    address newImplementation,
                    bytes32 newImplementationCodeHash,
                    bytes calldata setupParams
                ) external;
                /**********************\\
                |* External Functions *|
                \\**********************/
                function execute(bytes calldata input) external;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            // General interface for upgradable contracts
            interface IContractIdentifier {
                /**
                 * @notice Returns the contract ID. It can be used as a check during upgrades.
                 * @dev Meant to be overridden in derived contracts.
                 * @return bytes32 The contract ID
                 */
                function contractId() external pure returns (bytes32);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            /**
             * @dev Interface of the ERC20 standard as defined in the EIP.
             */
            interface IERC20 {
                error InvalidAccount();
                /**
                 * @dev Returns the amount of tokens in existence.
                 */
                function totalSupply() external view returns (uint256);
                /**
                 * @dev Returns the amount of tokens owned by `account`.
                 */
                function balanceOf(address account) external view returns (uint256);
                /**
                 * @dev Moves `amount` tokens from the caller's account to `recipient`.
                 *
                 * Returns a boolean value indicating whether the operation succeeded.
                 *
                 * Emits a {Transfer} event.
                 */
                function transfer(address recipient, uint256 amount) external returns (bool);
                /**
                 * @dev Returns the remaining number of tokens that `spender` will be
                 * allowed to spend on behalf of `owner` through {transferFrom}. This is
                 * zero by default.
                 *
                 * This value changes when {approve} or {transferFrom} are called.
                 */
                function allowance(address owner, address spender) external view returns (uint256);
                /**
                 * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
                 *
                 * Returns a boolean value indicating whether the operation succeeded.
                 *
                 * IMPORTANT: Beware that changing an allowance with this method brings the risk
                 * that someone may use both the old and the new allowance by unfortunate
                 * transaction ordering. One possible solution to mitigate this race
                 * condition is to first reduce the spender's allowance to 0 and set the
                 * desired value afterwards:
                 * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
                 *
                 * Emits an {Approval} event.
                 */
                function approve(address spender, uint256 amount) external returns (bool);
                /**
                 * @dev Moves `amount` tokens from `sender` to `recipient` using the
                 * allowance mechanism. `amount` is then deducted from the caller's
                 * allowance.
                 *
                 * Returns a boolean value indicating whether the operation succeeded.
                 *
                 * Emits a {Transfer} event.
                 */
                function transferFrom(
                    address sender,
                    address recipient,
                    uint256 amount
                ) external returns (bool);
                /**
                 * @dev Emitted when `value` tokens are moved from one account (`from`) to
                 * another (`to`).
                 *
                 * Note that `value` may be zero.
                 */
                event Transfer(address indexed from, address indexed to, uint256 value);
                /**
                 * @dev Emitted when the allowance of a `spender` for an `owner` is set by
                 * a call to {approve}. `value` is the new allowance.
                 */
                event Approval(address indexed owner, address indexed spender, uint256 value);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            /**
             * @title IGovernable Interface
             * @notice This is an interface used by the AxelarGateway contract to manage governance and mint limiter roles.
             */
            interface IGovernable {
                error NotGovernance();
                error NotMintLimiter();
                error InvalidGovernance();
                error InvalidMintLimiter();
                event GovernanceTransferred(address indexed previousGovernance, address indexed newGovernance);
                event MintLimiterTransferred(address indexed previousGovernance, address indexed newGovernance);
                /**
                 * @notice Returns the governance address.
                 * @return address of the governance
                 */
                function governance() external view returns (address);
                /**
                 * @notice Returns the mint limiter address.
                 * @return address of the mint limiter
                 */
                function mintLimiter() external view returns (address);
                /**
                 * @notice Transfer the governance role to another address.
                 * @param newGovernance The new governance address
                 */
                function transferGovernance(address newGovernance) external;
                /**
                 * @notice Transfer the mint limiter role to another address.
                 * @param newGovernance The new mint limiter address
                 */
                function transferMintLimiter(address newGovernance) external;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            import { IContractIdentifier } from './IContractIdentifier.sol';
            interface IImplementation is IContractIdentifier {
                error NotProxy();
                function setup(bytes calldata data) external;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            /**
             * @title IOwnable Interface
             * @notice IOwnable is an interface that abstracts the implementation of a
             * contract with ownership control features. It's commonly used in upgradable
             * contracts and includes the functionality to get current owner, transfer
             * ownership, and propose and accept ownership.
             */
            interface IOwnable {
                error NotOwner();
                error InvalidOwner();
                error InvalidOwnerAddress();
                event OwnershipTransferStarted(address indexed newOwner);
                event OwnershipTransferred(address indexed newOwner);
                /**
                 * @notice Returns the current owner of the contract.
                 * @return address The address of the current owner
                 */
                function owner() external view returns (address);
                /**
                 * @notice Returns the address of the pending owner of the contract.
                 * @return address The address of the pending owner
                 */
                function pendingOwner() external view returns (address);
                /**
                 * @notice Transfers ownership of the contract to a new address
                 * @param newOwner The address to transfer ownership to
                 */
                function transferOwnership(address newOwner) external;
                /**
                 * @notice Proposes to transfer the contract's ownership to a new address.
                 * The new owner needs to accept the ownership explicitly.
                 * @param newOwner The address to transfer ownership to
                 */
                function proposeOwnership(address newOwner) external;
                /**
                 * @notice Transfers ownership to the pending owner.
                 * @dev Can only be called by the pending owner
                 */
                function acceptOwnership() external;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            import { IOwnable } from './IOwnable.sol';
            import { IImplementation } from './IImplementation.sol';
            // General interface for upgradable contracts
            interface IUpgradable is IOwnable, IImplementation {
                error InvalidCodeHash();
                error InvalidImplementation();
                error SetupFailed();
                event Upgraded(address indexed newImplementation);
                function implementation() external view returns (address);
                function upgrade(
                    address newImplementation,
                    bytes32 newImplementationCodeHash,
                    bytes calldata params
                ) external;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            import { IERC20 } from '../interfaces/IERC20.sol';
            error TokenTransferFailed();
            /*
             * @title SafeTokenCall
             * @dev This library is used for performing safe token transfers.
             */
            library SafeTokenCall {
                /*
                 * @notice Make a safe call to a token contract.
                 * @param token The token contract to interact with.
                 * @param callData The function call data.
                 * @throws TokenTransferFailed error if transfer of token is not successful.
                 */
                function safeCall(IERC20 token, bytes memory callData) internal {
                    (bool success, bytes memory returnData) = address(token).call(callData);
                    bool transferred = success && (returnData.length == uint256(0) || abi.decode(returnData, (bool)));
                    if (!transferred || address(token).code.length == 0) revert TokenTransferFailed();
                }
            }
            /*
             * @title SafeTokenTransfer
             * @dev This library safely transfers tokens from the contract to a recipient.
             */
            library SafeTokenTransfer {
                /*
                 * @notice Transfer tokens to a recipient.
                 * @param token The token contract.
                 * @param receiver The recipient of the tokens.
                 * @param amount The amount of tokens to transfer.
                 */
                function safeTransfer(
                    IERC20 token,
                    address receiver,
                    uint256 amount
                ) internal {
                    SafeTokenCall.safeCall(token, abi.encodeWithSelector(IERC20.transfer.selector, receiver, amount));
                }
            }
            /*
             * @title SafeTokenTransferFrom
             * @dev This library helps to safely transfer tokens on behalf of a token holder.
             */
            library SafeTokenTransferFrom {
                /*
                 * @notice Transfer tokens on behalf of a token holder.
                 * @param token The token contract.
                 * @param from The address of the token holder.
                 * @param to The address the tokens are to be sent to.
                 * @param amount The amount of tokens to be transferred.
                 */
                function safeTransferFrom(
                    IERC20 token,
                    address from,
                    address to,
                    uint256 amount
                ) internal {
                    SafeTokenCall.safeCall(token, abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, amount));
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            import { IImplementation } from '../interfaces/IImplementation.sol';
            /**
             * @title Implementation
             * @notice This contract serves as a base for other contracts and enforces a proxy-first access restriction.
             * @dev Derived contracts must implement the setup function.
             */
            abstract contract Implementation is IImplementation {
                address private immutable implementationAddress;
                /**
                 * @dev Contract constructor that sets the implementation address to the address of this contract.
                 */
                constructor() {
                    implementationAddress = address(this);
                }
                /**
                 * @dev Modifier to require the caller to be the proxy contract.
                 * Reverts if the caller is the current contract (i.e., the implementation contract itself).
                 */
                modifier onlyProxy() {
                    if (implementationAddress == address(this)) revert NotProxy();
                    _;
                }
                /**
                 * @notice Initializes contract parameters.
                 * This function is intended to be overridden by derived contracts.
                 * The overriding function must have the onlyProxy modifier.
                 * @param params The parameters to be used for initialization
                 */
                function setup(bytes calldata params) external virtual;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            import { IImplementation } from '../interfaces/IImplementation.sol';
            import { IUpgradable } from '../interfaces/IUpgradable.sol';
            import { Ownable } from '../utils/Ownable.sol';
            import { Implementation } from './Implementation.sol';
            /**
             * @title Upgradable Contract
             * @notice This contract provides an interface for upgradable smart contracts and includes the functionality to perform upgrades.
             */
            abstract contract Upgradable is Ownable, Implementation, IUpgradable {
                // bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)
                bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
                /**
                 * @notice Constructor sets the implementation address to the address of the contract itself
                 * @dev This is used in the onlyProxy modifier to prevent certain functions from being called directly
                 * on the implementation contract itself.
                 * @dev The owner is initially set as address(1) because the actual owner is set within the proxy. It is not
                 * set as the zero address because Ownable is designed to throw an error for ownership transfers to the zero address.
                 */
                constructor() Ownable(address(1)) {}
                /**
                 * @notice Returns the address of the current implementation
                 * @return implementation_ Address of the current implementation
                 */
                function implementation() public view returns (address implementation_) {
                    assembly {
                        implementation_ := sload(_IMPLEMENTATION_SLOT)
                    }
                }
                /**
                 * @notice Upgrades the contract to a new implementation
                 * @param newImplementation The address of the new implementation contract
                 * @param newImplementationCodeHash The codehash of the new implementation contract
                 * @param params Optional setup parameters for the new implementation contract
                 * @dev This function is only callable by the owner.
                 */
                function upgrade(
                    address newImplementation,
                    bytes32 newImplementationCodeHash,
                    bytes calldata params
                ) external override onlyOwner {
                    if (IUpgradable(newImplementation).contractId() != IUpgradable(implementation()).contractId())
                        revert InvalidImplementation();
                    if (newImplementationCodeHash != newImplementation.codehash) revert InvalidCodeHash();
                    assembly {
                        sstore(_IMPLEMENTATION_SLOT, newImplementation)
                    }
                    emit Upgraded(newImplementation);
                    if (params.length > 0) {
                        // slither-disable-next-line controlled-delegatecall
                        (bool success, ) = newImplementation.delegatecall(abi.encodeWithSelector(this.setup.selector, params));
                        if (!success) revert SetupFailed();
                    }
                }
                /**
                 * @notice Sets up the contract with initial data
                 * @param data Initialization data for the contract
                 * @dev This function is only callable by the proxy contract.
                 */
                function setup(bytes calldata data) external override(IImplementation, Implementation) onlyProxy {
                    _setup(data);
                }
                /**
                 * @notice Internal function to set up the contract with initial data
                 * @param data Initialization data for the contract
                 * @dev This function should be implemented in derived contracts.
                 */
                function _setup(bytes calldata data) internal virtual {}
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            import { IOwnable } from '../interfaces/IOwnable.sol';
            /**
             * @title Ownable
             * @notice A contract module which provides a basic access control mechanism, where
             * there is an account (an owner) that can be granted exclusive access to
             * specific functions.
             *
             * The owner account is set through ownership transfer. This module makes
             * it possible to transfer the ownership of the contract to a new account in one
             * step, as well as to an interim pending owner. In the second flow the ownership does not
             * change until the pending owner accepts the ownership transfer.
             */
            abstract contract Ownable is IOwnable {
                // keccak256('owner')
                bytes32 internal constant _OWNER_SLOT = 0x02016836a56b71f0d02689e69e326f4f4c1b9057164ef592671cf0d37c8040c0;
                // keccak256('ownership-transfer')
                bytes32 internal constant _OWNERSHIP_TRANSFER_SLOT =
                    0x9855384122b55936fbfb8ca5120e63c6537a1ac40caf6ae33502b3c5da8c87d1;
                /**
                 * @notice Initializes the contract by transferring ownership to the owner parameter.
                 * @param _owner Address to set as the initial owner of the contract
                 */
                constructor(address _owner) {
                    _transferOwnership(_owner);
                }
                /**
                 * @notice Modifier that throws an error if called by any account other than the owner.
                 */
                modifier onlyOwner() {
                    if (owner() != msg.sender) revert NotOwner();
                    _;
                }
                /**
                 * @notice Returns the current owner of the contract.
                 * @return owner_ The current owner of the contract
                 */
                function owner() public view returns (address owner_) {
                    assembly {
                        owner_ := sload(_OWNER_SLOT)
                    }
                }
                /**
                 * @notice Returns the pending owner of the contract.
                 * @return owner_ The pending owner of the contract
                 */
                function pendingOwner() public view returns (address owner_) {
                    assembly {
                        owner_ := sload(_OWNERSHIP_TRANSFER_SLOT)
                    }
                }
                /**
                 * @notice Transfers ownership of the contract to a new account `newOwner`.
                 * @dev Can only be called by the current owner.
                 * @param newOwner The address to transfer ownership to
                 */
                function transferOwnership(address newOwner) external virtual onlyOwner {
                    _transferOwnership(newOwner);
                }
                /**
                 * @notice Propose to transfer ownership of the contract to a new account `newOwner`.
                 * @dev Can only be called by the current owner. The ownership does not change
                 * until the new owner accepts the ownership transfer.
                 * @param newOwner The address to transfer ownership to
                 */
                function proposeOwnership(address newOwner) external virtual onlyOwner {
                    if (newOwner == address(0)) revert InvalidOwnerAddress();
                    emit OwnershipTransferStarted(newOwner);
                    assembly {
                        sstore(_OWNERSHIP_TRANSFER_SLOT, newOwner)
                    }
                }
                /**
                 * @notice Accepts ownership of the contract.
                 * @dev Can only be called by the pending owner
                 */
                function acceptOwnership() external virtual {
                    address newOwner = pendingOwner();
                    if (newOwner != msg.sender) revert InvalidOwner();
                    _transferOwnership(newOwner);
                }
                /**
                 * @notice Internal function to transfer ownership of the contract to a new account `newOwner`.
                 * @dev Called in the constructor to set the initial owner.
                 * @param newOwner The address to transfer ownership to
                 */
                function _transferOwnership(address newOwner) internal virtual {
                    if (newOwner == address(0)) revert InvalidOwnerAddress();
                    emit OwnershipTransferred(newOwner);
                    assembly {
                        sstore(_OWNER_SLOT, newOwner)
                        sstore(_OWNERSHIP_TRANSFER_SLOT, 0)
                    }
                }
            }
            // 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);
            }
            // 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);
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v4.9.3) (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. Meant to be used with tokens that require the approval
                 * to be set to zero before setting it to a non-zero value, such as USDT.
                 */
                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));
                }
            }
            // 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);
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.9;
            /// @title TokenMessenger
            /// @notice Sends messages and receives messages to/from MessageTransmitters
            /// and to/from TokenMinters
            interface ICCTPTokenMessenger {
                /// @notice Deposits and burns tokens from sender to be minted on destination domain.
                /// Emits a `DepositForBurn` event.
                /// @dev reverts if:
                /// - given burnToken is not supported
                /// - given destinationDomain has no TokenMessenger registered
                /// - transferFrom() reverts. For example, if sender's burnToken balance or approved allowance
                /// to this contract is less than `amount`.
                /// - burn() reverts. For example, if `amount` is 0.
                /// - MessageTransmitter returns false or reverts.
                /// @param amount amount of tokens to burn
                /// @param destinationDomain destination domain
                /// @param mintRecipient address of mint recipient on destination domain
                /// @param burnToken address of contract to burn deposited tokens, on local domain
                /// @return nonce unique nonce reserved by message
                function depositForBurn(
                    uint256 amount,
                    uint32 destinationDomain,
                    bytes32 mintRecipient,
                    address burnToken
                ) external returns (uint64 nonce);
                /// @notice Deposits and burns tokens from sender to be minted on destination domain. The mint
                /// on the destination domain must be called by `destinationCaller`.
                /// WARNING: if the `destinationCaller` does not represent a valid address as bytes32, then it will not be possible
                /// to broadcast the message on the destination domain. This is an advanced feature, and the standard
                /// depositForBurn() should be preferred for use cases where a specific destination caller is not required.
                /// Emits a `DepositForBurn` event.
                /// @dev reverts if:
                /// - given destinationCaller is zero address
                /// - given burnToken is not supported
                /// - given destinationDomain has no TokenMessenger registered
                /// - transferFrom() reverts. For example, if sender's burnToken balance or approved allowance
                /// to this contract is less than `amount`.
                /// - burn() reverts. For example, if `amount` is 0.
                /// - MessageTransmitter returns false or reverts.
                /// @param amount amount of tokens to burn
                /// @param destinationDomain destination domain
                /// @param mintRecipient address of mint recipient on destination domain
                /// @param burnToken address of contract to burn deposited tokens, on local domain
                /// @param destinationCaller caller on the destination domain, as bytes32
                /// @return nonce unique nonce reserved by message
                function depositForBurnWithCaller(
                    uint256 amount,
                    uint32 destinationDomain,
                    bytes32 mintRecipient,
                    address burnToken,
                    bytes32 destinationCaller
                ) external returns (uint64 nonce);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.9;
            /// @title Chainflip Receiver Interface
            /// @dev The ICFReceiver interface is the interface required to receive tokens and
            /// cross-chain calls from the Chainflip Protocol.
            interface ICFReceiver {
                /// @notice Called by Chainflip protocol when receiving tokens on destination chain.
                /// Contains the logic that will run the payload calldata content.
                /// @param sourceChain Source chain according to the Chainflip Protocol's nomenclature.
                /// @param sourceAddress Source address on the source chain.
                /// @param payload Value provided by Squid containing the calldata that will be ran on destination chain.
                /// Expected format is: abi.encode(ISquidMulticall.Call[] calls, address refundRecipient,
                /// bytes32 salt).
                /// @param token Address of the ERC20 token received. 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
                /// in case of native token.
                /// @param amount Amount of ERC20 token received. This will match msg.value for native tokens.
                function cfReceive(
                    uint32 sourceChain,
                    bytes calldata sourceAddress,
                    bytes calldata payload,
                    address token,
                    uint256 amount
                ) external payable;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.9;
            /// @title RoledPausable
            /// @notice Provide logic to pause a contract and grant au pauser role.
            /// In case of a pauser update, current pauser provide the address of the potential new
            /// pauser. Potential new pauser then has to accept the role.
            /// @dev Contract uses hard coded slot values for variable to prevent storage clashes when upgrading.
            interface IRoledPausable {
                /// @notice Emitted when current pauser starts the update process.
                /// @param currentPauser Address of the current pauser proposing new one.
                /// @param pendingPauser Address of the potential new pauser.
                event PauserProposed(address indexed currentPauser, address indexed pendingPauser);
                /// @notice Emitted when pending pauser accepts pauser role.
                /// @param newPauser Address of the new pauser.
                event PauserUpdated(address indexed newPauser);
                /// @notice Emitted when contract is paused.
                event Paused();
                /// @notice Emitted when contract is unpaused.
                event Unpaused();
                /// @notice Thrown when a pausable function is called while the contract is paused.
                error ContractIsPaused();
                /// @notice Thrown when function is only meant to be called by current pauser.
                error OnlyPauser();
                /// @notice Thrown when function is only meant to be called by pending pauser.
                error OnlyPendingPauser();
                /// @notice Start pauser role update process by providing new pauser address.
                /// @dev Only callable by current pauser.
                /// @param newPauser Address of the potential new pauser.
                function updatePauser(address newPauser) external;
                /// @notice Let pending pauser accept pauser role.
                /// @dev Only callable by pending pauser.
                function acceptPauser() external;
                /// @notice Let pauser pause the contract.
                /// @dev Only callable by current pauser.
                function pause() external;
                /// @notice Let pauser unpause the contract.
                /// @dev Only callable by current pauser.
                function unpause() external;
                /// @notice Get pause state.
                /// @dev Return true if paused and false if not paused.
                function paused() external view returns (bool value);
                /// @notice Get pauser address.
                function pauser() external view returns (address value);
                /// @notice Get pending pauser address.
                function pendingPauser() external view returns (address value);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.9;
            /// @title SquidMulticall
            /// @notice Multicall logic specific to Squid calls format. The contract specificity is mainly
            /// to enable ERC20 and native token amounts in calldata between two calls.
            /// @dev Support receiption of NFTs.
            interface ISquidMulticall {
                /// @notice Call type that enables to specific behaviours of the multicall.
                enum CallType {
                    // Will simply run calldata
                    Default,
                    // Will update amount field in calldata with ERC20 token balance of the multicall contract.
                    FullTokenBalance,
                    // Will update amount field in calldata with native token balance of the multicall contract.
                    FullNativeBalance,
                    // Will run a safeTransferFrom to get full ERC20 token balance of the caller.
                    CollectTokenBalance
                }
                /// @notice Calldata format expected by multicall.
                struct Call {
                    // Call type, see CallType struct description.
                    CallType callType;
                    // Address that will be called.
                    address target;
                    // Native token amount that will be sent in call.
                    uint256 value;
                    // Calldata that will be send in call.
                    bytes callData;
                    // Extra data used by multicall depending on call type.
                    // Default: unused (provide 0x)
                    // FullTokenBalance: address of the ERC20 token to get balance of and zero indexed position
                    // of the amount parameter to update in function call contained by calldata.
                    // Expect format is: abi.encode(address token, uint256 amountParameterPosition)
                    // Eg: for function swap(address tokenIn, uint amountIn, address tokenOut, uint amountOutMin,)
                    // amountParameterPosition would be 1.
                    // FullNativeBalance: unused (provide 0x)
                    // CollectTokenBalance: address of the ERC20 token to collect.
                    // Expect format is: abi.encode(address token)
                    bytes payload;
                }
                /// Thrown when one of the calls fails.
                /// @param callPosition Zero indexed position of the call in the call set provided to the
                /// multicall.
                /// @param reason Revert data returned by contract called in failing call.
                error CallFailed(uint256 callPosition, bytes reason);
                /// @notice Main function of the multicall that runs the call set.
                /// @param calls Call set to be ran by multicall.
                function run(Call[] calldata calls) external payable;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.9;
            import {ISquidMulticall} from "./ISquidMulticall.sol";
            import {IPermit2} from "../interfaces/uniswap/IPermit2.sol";
            /// @title SquidRouter
            /// @notice Main entry point of the protocol. It mainly provides endpoints to interact safely
            /// with the multicall or CCTP, and receiver function to handle asset reception for bridges.
            interface ISquidRouter {
                /// @notice Emitted when the calldata content of a payload is successfully ran on destination chain.
                /// @param payloadHash Keccak256 of the payload bytes value. Differ from one call to another in case of
                /// identical parameters value thanks to a salt value.
                event CrossMulticallExecuted(bytes32 indexed payloadHash);
                /// @notice Emitted when the calldata content of a payload failed to be ran on destination chain and
                /// ERC20 tokens are sent to refund recipient address.
                /// @param payloadHash Keccak256 hash of the payload bytes value. Differ from one call to another in case
                /// of identical parameters value thanks to a salt value.
                /// @param reason Revert data returned by contract called in failing call.
                /// @param refundRecipient Address that will receive bridged ERC20 tokens on destination chain in case
                /// of multicall failure.
                event CrossMulticallFailed(
                    bytes32 indexed payloadHash,
                    bytes reason,
                    address indexed refundRecipient
                );
                /// @notice Thrown when address(0) is provided to a parameter that does not allow it.
                error ZeroAddressProvided();
                /// @notice Thrown when Chainflip receiver function is called by any address other that Chainflip
                /// vault contract.
                error OnlyCfVault();
                /// @notice Collect ERC20 and/or native tokens from user and send them to multicall. Then run multicall.
                /// @dev Require either ERC20 or permit2 allowance from the user to the router address.
                /// Indeed, permit2's transferFrom2 is used instead of regulat transferFrom. Meaning that if there is no
                /// regular allowance from user to the router for ERC20 token, permit2 allowance will be used if granted.
                /// @dev Native tokens can be provided on top of ERC20 tokens, both will be sent to multicall.
                /// @param token Address of the ERC20 token to be provided to the multicall to run the calls.
                /// 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE in case of native token.
                /// @param amount Amount of ERC20 tokens to be provided to the multicall. If native token is selected, this
                /// value has not effect.
                /// @param calls Calls to be ran by the multicall, formatted in accordance to Call struct.
                function fundAndRunMulticall(
                    address token,
                    uint256 amount,
                    ISquidMulticall.Call[] calldata calls
                ) external payable;
                /// @notice Collect ERC20 tokens from user and send them to multicall thanks to a permit2 signed permit. Then run
                /// multicall.
                /// @dev Native tokens can be provided on top of ERC20 tokens by the relayer of the permit, both will be sent
                /// to multicall.
                /// @dev Transaction sender can either be the holder of the funds, or the separate relayer. In the later case,
                /// witness must be included in the data signed, according to the permit2 protocol.
                /// @dev See https://docs.uniswap.org/contracts/permit2/reference/signature-transfer for more information about
                /// permit2 protocol requirements.
                /// @dev ERC20 token and amount values to be used are provided in the permit data.
                /// @param calls Calls to be ran by the multicall, formatted in accordance to Call struct.
                /// @param from Holder of the funds to be provided. Can defer from the sender of the transaction in case of a
                /// relayed transaction.
                /// @param permit Permit data according to permit2 protocol.
                /// @param signature Signature data according to permit2 protocol.
                function permitFundAndRunMulticall(
                    ISquidMulticall.Call[] memory calls,
                    address from,
                    IPermit2.PermitTransferFrom calldata permit,
                    bytes calldata signature
                ) external payable;
                /// @notice Collect USDC tokens from user and trigger CCTP bridging.
                /// @dev This endpoint is meant to enable CCTP bridging at the end of a multicall. It also enable integrations
                /// with Squid CCTP bridging relayer infrasctructure.
                /// @dev Require either ERC20 or permit2 allowance from the user to the router address.
                /// Indeed, permit2's transferFrom2 is used instead of regulat transferFrom. Meaning that if there is no
                /// regular allowance from user to the router for ERC20 token, permit2 allowance will be used if granted.
                /// @dev CCTP's replaceDepositForBurn function is not made available for security reason. Integrators need to
                /// be careful with the parameters they provide.
                /// @dev Require owner to call `approveCctpTokenMessenger` function first.
                /// @param amount Amount of USDC tokens to be bridged.
                /// @param destinationDomain Destination chain according to CCTP's nomenclature.
                /// This param is checked for potential irrelevant values by CCTP contract.
                /// See https://developers.circle.com/stablecoins/docs/cctp-technical-reference.
                /// @param destinationAddress Address that will receive USDC tokens on destination chain.
                /// This param is checked for not zero value by CCTP contract.
                /// @param destinationCaller Address that will be able to trigger USDC tokens reception on destination chain.
                /// This param is checked for not zero value to disable anonymous actions.
                function cctpBridge(
                    uint256 amount,
                    uint32 destinationDomain,
                    bytes32 destinationAddress,
                    bytes32 destinationCaller
                ) external;
                /// @notice Collect USDC tokens from user thanks to a permit2 signed permit and trigger CCTP bridging.
                /// @dev Transaction sender can either be the holder of the funds, or the separate relayer. In the later case,
                /// witness must be included in the data signed, according to the permit2 protocol.
                /// @dev See https://docs.uniswap.org/contracts/permit2/reference/signature-transfer for more information about
                /// permit2 protocol requirements.
                /// @dev USDC token and amount values to be used are provided in the permit data.
                /// Permit token address value is checked to match USDC token address.
                /// @dev CCTP's replaceDepositForBurn function is not made available for security reason. Integrators need to
                /// be careful with the parameters they provide.
                /// @dev Require owner to call `approveCctpTokenMessenger` function first.
                /// @param destinationDomain Destination chain according to CCTP's nomenclature.
                /// This param is checked for potential irrelevant values by CCTP contract.
                /// See https://developers.circle.com/stablecoins/docs/cctp-technical-reference.
                /// @param destinationAddress Address that will receive USDC tokens on destination chain.
                /// This param is checked for not zero value by CCTP contract.
                /// @param destinationCaller Address that will be able to trigger USDC tokens reception on destination chain.
                /// This param is checked for not zero value to disable anonymous actions.
                /// @param from Holder of the funds to be provided. Can defer from the sender of the transaction in case of a
                /// relayed transaction.
                /// @param permit Permit data according to permit2 protocol.
                /// @param signature Signature data according to permit2 protocol.
                function permitCctpBridge(
                    uint32 destinationDomain,
                    bytes32 destinationAddress,
                    bytes32 destinationCaller,
                    address from,
                    IPermit2.PermitTransferFrom calldata permit,
                    bytes calldata signature
                ) external;
                /// @notice Approve CCTP Token Messenger to access unlimited amount of USDC. Enables to not have to
                /// approve each time a user wants to bridge USDC. Requires to monitor CCTP Token Messenger allowance.
                /// @dev Only owner can call.
                function approveCctpTokenMessenger() external;
                /// @notice Collect ERC20 and/or native tokens from user and send them to multicall. Then bridge tokens
                /// through Axelar bridge and run multicall on destination chain. This endpoint is deprecated and will be
                /// removed in a future upgrade.
                /// @dev Require either ERC20 or permit2 allowance from the user to the router address.
                /// Indeed, permit2's transferFrom2 is used instead of regulat transferFrom. Meaning that if there is no
                /// regular allowance from user to the router for ERC20 token, permit2 allowance will be used if granted.
                /// @dev Require to provide native amount to cover gas service. The amount has to be computed off chain with
                /// Axelar SDK.
                /// @dev Native tokens provided on top of an ERC20 token will be sent to gas service. Thus you need to provide
                /// native amount to cover gas service on top of native amount for calls
                /// @dev Gas service providing is handled internally.
                /// @param bridgedTokenSymbol Symbol of the token that will be sent to Axelar bridge.
                /// @param amount Amount of ERC20 tokens to be collect for bridging.
                /// @param destinationChain Destination chain for bridging according to Axelar's nomenclature.
                /// @param destinationAddress Address that will receive bridged ERC20 tokens on destination chain.
                /// @param payload Bytes value containing calls to be ran by the multicall on destination chain.
                /// Expected format is: abi.encode(ISquidMulticall.Call[] calls, address refundRecipient, bytes32 salt).
                /// @param gasRefundRecipient Address that will receive native tokens left on gas service after process is
                /// done.
                /// @param enableExpress If true is provided, Axelar's express (aka Squid's boost) feature will be used.
                function bridgeCall(
                    string calldata bridgedTokenSymbol,
                    uint256 amount,
                    string calldata destinationChain,
                    string calldata destinationAddress,
                    bytes calldata payload,
                    address gasRefundRecipient,
                    bool enableExpress
                ) external payable;
                /// @notice Collect ERC20 and/or native tokens from user and send them to multicall. Then run multicall and
                /// bridge tokens through Axelar bridge before running multicall on destination chain. This endpoint is
                /// deprecated and will be removed in a future upgrade.
                /// @dev Require either ERC20 or permit2 allowance from the user to the router address.
                /// Indeed, permit2's transferFrom2 is used instead of regulat transferFrom. Meaning that if there is no
                /// regular allowance from user to the router for ERC20 token, permit2 allowance will be used if granted.
                /// @dev Require to provide native amount to cover gas service. The amount has to be computed off chain with
                /// Axelar SDK.
                /// @dev Native tokens provided on top of an ERC20 token will be sent to gas service. If input token is native
                /// tokens, input amount will be sent to multicall and the rest to gas service. Thus you need to provide native
                /// amount to cover gas service on top of native amount for calls.
                /// @dev Gas service providing is handled internally.
                /// @param token Address of the ERC20 token to be provided to the multicall to run the calls.
                /// 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE in case of native token.
                /// @param amount Amount of ERC20 or native tokens to be provided to the multicall.
                /// @param calls Calls to be ran by the multicall on source chain, formatted in accordance to Call struct.
                /// @param bridgedTokenSymbol Symbol of the token that will be sent to Axelar bridge.
                /// @param destinationChain Destination chain for bridging according to Axelar's nomenclature.
                /// @param destinationAddress Address that will receive bridged ERC20 tokens on destination chain.
                /// @param payload Bytes value containing calls to be ran by the multicall on destination chain.
                /// Expected format is: abi.encode(ISquidMulticall.Call[] calls, address refundRecipient, bytes32 salt).
                /// @param gasRefundRecipient Address that will receive native tokens left on gas service after process is
                /// done.
                /// @param enableExpress If true is provided, Axelar's express (aka Squid's boost) feature will be used.
                function callBridgeCall(
                    address token,
                    uint256 amount,
                    ISquidMulticall.Call[] calldata calls,
                    string calldata bridgedTokenSymbol,
                    string calldata destinationChain,
                    string calldata destinationAddress,
                    bytes calldata payload,
                    address gasRefundRecipient,
                    bool enableExpress
                ) external payable;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.9;
            interface IExpressCallHandler {
                error AlreadyExpressCalled();
                error SameDestinationAsCaller();
                event ExpressReceive(bytes payload, bytes32 indexed sendHash, address indexed expressCaller);
                event ExpressExecutionFulfilled(bytes payload, bytes32 indexed sendHash, address indexed expressCaller);
                /**
                 * @notice Gets the address of the express caller for a specific token transfer
                 * @param payload the payload for the receive token
                 * @param commandId The unique hash for this token transfer
                 * @return expressCaller The address of the express caller for this token transfer
                 */
                function getExpressReceiveToken(
                    bytes calldata payload,
                    bytes32 commandId
                ) external view returns (address expressCaller);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            /**
             * @title IInterchainTokenExecutable
             * @notice Contracts should implement this interface to accept calls from the InterchainTokenService.
             */
            interface IInterchainTokenExecutable {
                /**
                 * @notice This will be called after the tokens are sent to this contract.
                 * @dev Execution should revert unless the msg.sender is the InterchainTokenService
                 * @param commandId The unique message id for the call.
                 * @param sourceChain The name of the source chain.
                 * @param sourceAddress The address that sent the contract call.
                 * @param data The data to be processed.
                 * @param tokenId The tokenId of the token manager managing the token.
                 * @param token The address of the token.
                 * @param amount The amount of tokens that were sent.
                 * @return bytes32 Hash indicating success of the execution.
                 */
                function executeWithInterchainToken(
                    bytes32 commandId,
                    string calldata sourceChain,
                    bytes calldata sourceAddress,
                    bytes calldata data,
                    bytes32 tokenId,
                    address token,
                    uint256 amount
                ) external returns (bytes32);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            import {IInterchainTokenExecutable} from "./IInterchainTokenExecutable.sol";
            /**
             * @title IInterchainTokenExpressExecutable
             * @notice Contracts should implement this interface to accept express calls from the InterchainTokenService.
             */
            interface IInterchainTokenExpressExecutable is IInterchainTokenExecutable {
                /**
                 * @notice Executes express logic in the context of an interchain token transfer.
                 * @dev Only callable by the interchain token service.
                 * @param commandId The unique message id for the call.
                 * @param sourceChain The source chain of the token transfer.
                 * @param sourceAddress The source address of the token transfer.
                 * @param data The data associated with the token transfer.
                 * @param tokenId The token ID.
                 * @param token The token address.
                 * @param amount The amount of tokens to be transferred.
                 * @return bytes32 Hash indicating success of the express execution.
                 */
                function expressExecuteWithInterchainToken(
                    bytes32 commandId,
                    string calldata sourceChain,
                    bytes calldata sourceAddress,
                    bytes calldata data,
                    bytes32 tokenId,
                    address token,
                    uint256 amount
                ) external returns (bytes32);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.9;
            import {IAxelarExecutable} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarExecutable.sol";
            import {IContractIdentifier} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IContractIdentifier.sol";
            import {IExpressCallHandler} from "./IExpressCallHandler.sol";
            import {ITokenManagerType} from "./ITokenManagerType.sol";
            import {IPausable} from "./IPausable.sol";
            import {IMulticall} from "./IMulticall.sol";
            interface IInterchainTokenService is
                ITokenManagerType,
                IExpressCallHandler,
                IAxelarExecutable,
                IPausable,
                IMulticall,
                IContractIdentifier
            {
                error ZeroAddress();
                error LengthMismatch();
                error InvalidTokenManagerImplementation();
                error NotRemoteService();
                error TokenManagerDoesNotExist(bytes32 tokenId);
                error NotTokenManager();
                error ExecuteWithInterchainTokenFailed(address contractAddress);
                error NotCanonicalTokenManager();
                error GatewayToken();
                error TokenManagerDeploymentFailed();
                error StandardizedTokenDeploymentFailed();
                error DoesNotAcceptExpressExecute(address contractAddress);
                error SelectorUnknown();
                error InvalidMetadataVersion(uint32 version);
                error AlreadyExecuted(bytes32 commandId);
                error ExecuteWithTokenNotSupported();
                error InvalidExpressSelector();
                event TokenSent(bytes32 indexed tokenId, string destinationChain, bytes destinationAddress, uint256 indexed amount);
                event TokenSentWithData(
                    bytes32 indexed tokenId,
                    string destinationChain,
                    bytes destinationAddress,
                    uint256 indexed amount,
                    address indexed sourceAddress,
                    bytes data
                );
                event TokenReceived(
                    bytes32 indexed tokenId,
                    string sourceChain,
                    address indexed destinationAddress,
                    uint256 indexed amount
                );
                event TokenReceivedWithData(
                    bytes32 indexed tokenId,
                    string sourceChain,
                    address indexed destinationAddress,
                    uint256 indexed amount,
                    bytes sourceAddress,
                    bytes data
                );
                event RemoteTokenManagerDeploymentInitialized(
                    bytes32 indexed tokenId,
                    string destinationChain,
                    uint256 indexed gasValue,
                    TokenManagerType indexed tokenManagerType,
                    bytes params
                );
                event RemoteStandardizedTokenAndManagerDeploymentInitialized(
                    bytes32 indexed tokenId,
                    string tokenName,
                    string tokenSymbol,
                    uint8 tokenDecimals,
                    bytes distributor,
                    bytes mintTo,
                    uint256 indexed mintAmount,
                    bytes operator,
                    string destinationChain,
                    uint256 indexed gasValue
                );
                event TokenManagerDeployed(bytes32 indexed tokenId, TokenManagerType indexed tokenManagerType, bytes params);
                event StandardizedTokenDeployed(
                    bytes32 indexed tokenId,
                    address indexed distributor,
                    string name,
                    string symbol,
                    uint8 decimals,
                    uint256 indexed mintAmount,
                    address mintTo
                );
                event CustomTokenIdClaimed(bytes32 indexed tokenId, address indexed deployer, bytes32 indexed salt);
                /**
                 * @notice Returns the address of the token manager deployer contract.
                 * @return tokenManagerDeployerAddress The address of the token manager deployer contract.
                 */
                function tokenManagerDeployer() external view returns (address tokenManagerDeployerAddress);
                /**
                 * @notice Returns the address of the standardized token deployer contract.
                 * @return standardizedTokenDeployerAddress The address of the standardized token deployer contract.
                 */
                function standardizedTokenDeployer() external view returns (address standardizedTokenDeployerAddress);
                /**
                 * @notice Returns the address of the token manager associated with the given tokenId.
                 * @param tokenId The tokenId of the token manager.
                 * @return tokenManagerAddress The address of the token manager.
                 */
                function getTokenManagerAddress(bytes32 tokenId) external view returns (address tokenManagerAddress);
                /**
                 * @notice Returns the address of the valid token manager associated with the given tokenId.
                 * @param tokenId The tokenId of the token manager.
                 * @return tokenManagerAddress The address of the valid token manager.
                 */
                function getValidTokenManagerAddress(bytes32 tokenId) external view returns (address tokenManagerAddress);
                /**
                 * @notice Returns the address of the token associated with the given tokenId.
                 * @param tokenId The tokenId of the token manager.
                 * @return tokenAddress The address of the token.
                 */
                function getTokenAddress(bytes32 tokenId) external view returns (address tokenAddress);
                /**
                 * @notice Returns the address of the standardized token associated with the given tokenId.
                 * @param tokenId The tokenId of the standardized token.
                 * @return tokenAddress The address of the standardized token.
                 */
                function getStandardizedTokenAddress(bytes32 tokenId) external view returns (address tokenAddress);
                /**
                 * @notice Returns the canonical tokenId associated with the given tokenAddress.
                 * @param tokenAddress The address of the token.
                 * @return tokenId The canonical tokenId associated with the tokenAddress.
                 */
                function getCanonicalTokenId(address tokenAddress) external view returns (bytes32 tokenId);
                /**
                 * @notice Returns the custom tokenId associated with the given operator and salt.
                 * @param operator The operator address.
                 * @param salt The salt used for token id calculation.
                 * @return tokenId The custom tokenId associated with the operator and salt.
                 */
                function getCustomTokenId(address operator, bytes32 salt) external view returns (bytes32 tokenId);
                /**
                 * @notice Registers a canonical token and returns its associated tokenId.
                 * @param tokenAddress The address of the canonical token.
                 * @return tokenId The tokenId associated with the registered canonical token.
                 */
                function registerCanonicalToken(address tokenAddress) external payable returns (bytes32 tokenId);
                /**
                 * @notice Deploys a standardized canonical token on a remote chain.
                 * @param tokenId The tokenId of the canonical token.
                 * @param destinationChain The name of the destination chain.
                 * @param gasValue The gas value for deployment.
                 */
                function deployRemoteCanonicalToken(
                    bytes32 tokenId,
                    string calldata destinationChain,
                    uint256 gasValue
                ) external payable;
                /**
                 * @notice Deploys a custom token manager contract.
                 * @param salt The salt used for token manager deployment.
                 * @param tokenManagerType The type of token manager.
                 * @param params The deployment parameters.
                 * @return tokenId The tokenId of the deployed token manager.
                 */
                function deployCustomTokenManager(
                    bytes32 salt,
                    TokenManagerType tokenManagerType,
                    bytes memory params
                ) external payable returns (bytes32 tokenId);
                /**
                 * @notice Deploys a custom token manager contract on a remote chain.
                 * @param salt The salt used for token manager deployment.
                 * @param destinationChain The name of the destination chain.
                 * @param tokenManagerType The type of token manager.
                 * @param params The deployment parameters.
                 * @param gasValue The gas value for deployment.
                 */
                function deployRemoteCustomTokenManager(
                    bytes32 salt,
                    string calldata destinationChain,
                    TokenManagerType tokenManagerType,
                    bytes calldata params,
                    uint256 gasValue
                ) external payable returns (bytes32 tokenId);
                /**
                 * @notice Deploys a standardized token and registers it. The token manager type will be lock/unlock unless the distributor matches its address, in which case it will be a mint/burn one.
                 * @param salt The salt used for token deployment.
                 * @param name The name of the standardized token.
                 * @param symbol The symbol of the standardized token.
                 * @param decimals The number of decimals for the standardized token.
                 * @param mintAmount The amount of tokens to mint to the deployer.
                 * @param distributor The address of the distributor for mint/burn operations.
                 */
                function deployAndRegisterStandardizedToken(
                    bytes32 salt,
                    string calldata name,
                    string calldata symbol,
                    uint8 decimals,
                    uint256 mintAmount,
                    address distributor
                ) external payable;
                /**
                 * @notice Deploys and registers a standardized token on a remote chain.
                 * @param salt The salt used for token deployment.
                 * @param name The name of the standardized tokens.
                 * @param symbol The symbol of the standardized tokens.
                 * @param decimals The number of decimals for the standardized tokens.
                 * @param distributor The distributor data for mint/burn operations.
                 * @param mintTo The address where the minted tokens will be sent upon deployment.
                 * @param mintAmount The amount of tokens to be minted upon deployment.
                 * @param operator The operator data for standardized tokens.
                 * @param destinationChain The name of the destination chain.
                 * @param gasValue The gas value for deployment.
                 */
                function deployAndRegisterRemoteStandardizedToken(
                    bytes32 salt,
                    string memory name,
                    string memory symbol,
                    uint8 decimals,
                    bytes memory distributor,
                    bytes memory mintTo,
                    uint256 mintAmount,
                    bytes memory operator,
                    string calldata destinationChain,
                    uint256 gasValue
                ) external payable;
                /**
                 * @notice Returns the implementation address for a given token manager type.
                 * @param tokenManagerType The type of token manager.
                 * @return tokenManagerAddress The address of the token manager implementation.
                 */
                function getImplementation(uint256 tokenManagerType) external view returns (address tokenManagerAddress);
                function interchainTransfer(
                    bytes32 tokenId,
                    string calldata destinationChain,
                    bytes calldata destinationAddress,
                    uint256 amount,
                    bytes calldata metadata
                ) external;
                function sendTokenWithData(
                    bytes32 tokenId,
                    string calldata destinationChain,
                    bytes calldata destinationAddress,
                    uint256 amount,
                    bytes calldata data
                ) external;
                /**
                 * @notice Initiates an interchain token transfer. Only callable by TokenManagers
                 * @param tokenId The tokenId of the token to be transmitted.
                 * @param sourceAddress The source address of the token.
                 * @param destinationChain The name of the destination chain.
                 * @param destinationAddress The destination address on the destination chain.
                 * @param amount The amount of tokens to transmit.
                 * @param metadata The metadata associated with the transmission.
                 */
                function transmitSendToken(
                    bytes32 tokenId,
                    address sourceAddress,
                    string calldata destinationChain,
                    bytes memory destinationAddress,
                    uint256 amount,
                    bytes calldata metadata
                ) external payable;
                /**
                 * @notice Sets the flow limits for multiple tokens.
                 * @param tokenIds An array of tokenIds.
                 * @param flowLimits An array of flow limits corresponding to the tokenIds.
                 */
                function setFlowLimits(bytes32[] calldata tokenIds, uint256[] calldata flowLimits) external;
                /**
                 * @notice Returns the flow limit for a specific token.
                 * @param tokenId The tokenId of the token.
                 * @return flowLimit The flow limit for the token.
                 */
                function getFlowLimit(bytes32 tokenId) external view returns (uint256 flowLimit);
                /**
                 * @notice Returns the total amount of outgoing flow for a specific token.
                 * @param tokenId The tokenId of the token.
                 * @return flowOutAmount The total amount of outgoing flow for the token.
                 */
                function getFlowOutAmount(bytes32 tokenId) external view returns (uint256 flowOutAmount);
                /**
                 * @notice Returns the total amount of incoming flow for a specific token.
                 * @param tokenId The tokenId of the token.
                 * @return flowInAmount The total amount of incoming flow for the token.
                 */
                function getFlowInAmount(bytes32 tokenId) external view returns (uint256 flowInAmount);
                /**
                 * @notice Sets the paused state of the contract.
                 * @param paused The boolean value indicating whether the contract is paused or not.
                 */
                function setPaused(bool paused) external;
                /**
                 * @notice Uses the caller's tokens to fullfill a sendCall ahead of time. Use this only if you have detected an outgoing interchainTransfer that matches the parameters passed here.
                 * @param payload the payload of the receive token
                 * @param commandId the commandId calculated from the event at the sourceChain.
                 */
                function expressReceiveToken(bytes calldata payload, bytes32 commandId, string calldata sourceChain) external;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.9;
            /**
             * @title IMulticall
             * @notice This contract is a multi-functional smart contract which allows for multiple
             * contract calls in a single transaction.
             */
            interface IMulticall {
                /**
                 * @notice Performs multiple delegate calls and returns the results of all calls as an array
                 * @dev This function requires that the contract has sufficient balance for the delegate calls.
                 * If any of the calls fail, the function will revert with the failure message.
                 * @param data An array of encoded function calls
                 * @return results An bytes array with the return data of each function call
                 */
                function multicall(bytes[] calldata data) external payable returns (bytes[] memory results);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            import {IInterchainTokenExecutable} from "./IInterchainTokenExecutable.sol";
            /**
             * @title InterchainTokenExecutable
             * @notice Abstract contract that defines an interface for executing arbitrary logic
             * in the context of interchain token operations.
             * @dev This contract should be inherited by contracts that intend to execute custom
             * logic in response to interchain token actions such as transfers. This contract
             * will only be called by the interchain token service.
             */
            abstract contract InterchainTokenExecutable is IInterchainTokenExecutable {
                error NotService(address caller);
                address public immutable interchainTokenService;
                bytes32 internal constant EXECUTE_SUCCESS = keccak256("its-execute-success");
                /**
                 * @notice Creates a new InterchainTokenExecutable contract.
                 * @param interchainTokenService_ The address of the interchain token service that will call this contract.
                 */
                constructor(address interchainTokenService_) {
                    interchainTokenService = interchainTokenService_;
                }
                /**
                 * Modifier to restrict function execution to the interchain token service.
                 */
                modifier onlyService() {
                    if (msg.sender != interchainTokenService) revert NotService(msg.sender);
                    _;
                }
                /**
                 * @notice Executes logic in the context of an interchain token transfer.
                 * @dev Only callable by the interchain token service.
                 * @param commandId The message id for the call.
                 * @param sourceChain The source chain of the token transfer.
                 * @param sourceAddress The source address of the token transfer.
                 * @param data The data associated with the token transfer.
                 * @param tokenId The token ID.
                 * @param token The token address.
                 * @param amount The amount of tokens being transferred.
                 * @return bytes32 Hash indicating success of the execution.
                 */
                function executeWithInterchainToken(
                    bytes32 commandId,
                    string calldata sourceChain,
                    bytes calldata sourceAddress,
                    bytes calldata data,
                    bytes32 tokenId,
                    address token,
                    uint256 amount
                ) external virtual onlyService returns (bytes32) {
                    _executeWithInterchainToken(commandId, sourceChain, sourceAddress, data, tokenId, token, amount);
                    return EXECUTE_SUCCESS;
                }
                /**
                 * @notice Internal function containing the logic to be executed with interchain token transfer.
                 * @dev Logic must be implemented by derived contracts.
                 * @param sourceChain The source chain of the token transfer.
                 * @param sourceAddress The source address of the token transfer.
                 * @param data The data associated with the token transfer.
                 * @param tokenId The token ID.
                 * @param token The token address.
                 * @param amount The amount of tokens being transferred.
                 */
                function _executeWithInterchainToken(
                    bytes32 commandId,
                    string calldata sourceChain,
                    bytes calldata sourceAddress,
                    bytes calldata data,
                    bytes32 tokenId,
                    address token,
                    uint256 amount
                ) internal virtual;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            import {IInterchainTokenExpressExecutable} from "./IInterchainTokenExpressExecutable.sol";
            import {InterchainTokenExecutable} from "./InterchainTokenExecutable.sol";
            /**
             * @title InterchainTokenExpressExecutable
             * @notice Abstract contract that defines an interface for executing express logic in the context of interchain token operations.
             * @dev This contract extends `InterchainTokenExecutable` to provide express execution capabilities. It is intended to be inherited by contracts
             * that implement express logic for interchain token actions. This contract will only be called by the interchain token service.
             */
            abstract contract InterchainTokenExpressExecutable is IInterchainTokenExpressExecutable, InterchainTokenExecutable {
                bytes32 internal constant EXPRESS_EXECUTE_SUCCESS = keccak256("its-express-execute-success");
                /**
                 * @notice Creates a new InterchainTokenExpressExecutable contract.
                 * @param interchainTokenService_ The address of the interchain token service that will call this contract.
                 */
                constructor(address interchainTokenService_) InterchainTokenExecutable(interchainTokenService_) {}
                /**
                 * @notice Executes express logic in the context of an interchain token transfer.
                 * @dev Only callable by the interchain token service.
                 * @param commandId The message id for the call.
                 * @param sourceChain The source chain of the token transfer.
                 * @param sourceAddress The source address of the token transfer.
                 * @param data The data associated with the token transfer.
                 * @param tokenId The token ID.
                 * @param token The token address.
                 * @param amount The amount of tokens to be transferred.
                 * @return bytes32 Hash indicating success of the express execution.
                 */
                function expressExecuteWithInterchainToken(
                    bytes32 commandId,
                    string calldata sourceChain,
                    bytes calldata sourceAddress,
                    bytes calldata data,
                    bytes32 tokenId,
                    address token,
                    uint256 amount
                ) external virtual onlyService returns (bytes32) {
                    _executeWithInterchainToken(commandId, sourceChain, sourceAddress, data, tokenId, token, amount);
                    return EXPRESS_EXECUTE_SUCCESS;
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.9;
            /**
             * @title Pausable
             * @notice This contract provides a mechanism to halt the execution of specific functions
             * if a pause condition is activated.
             */
            interface IPausable {
                event PausedSet(bool indexed paused);
                error Paused();
                /**
                 * @notice Check if the contract is paused
                 * @return paused A boolean representing the pause status. True if paused, false otherwise.
                 */
                function isPaused() external view returns (bool);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.9;
            /**
             * @title ITokenManagerType
             * @notice A simple interface that defines all the token manager types
             */
            interface ITokenManagerType {
                enum TokenManagerType {
                    MINT_BURN,
                    MINT_BURN_FROM,
                    LOCK_UNLOCK,
                    LOCK_UNLOCK_FEE
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.9;
            /// @title Permit2
            /// @notice Permit2 handles signature-based transfers in SignatureTransfer and allowance-based transfers in AllowanceTransfer.
            /// @dev Users must approve Permit2 before calling any of the transfer functions.
            interface IPermit2 {
                /// @notice The token and amount details for a transfer signed in the permit transfer signature
                struct TokenPermissions {
                    // ERC20 token address
                    address token;
                    // the maximum amount that can be spent
                    uint256 amount;
                }
                /// @notice The signed permit message for a single token transfer
                struct PermitTransferFrom {
                    TokenPermissions permitted;
                    // a unique value for every token owner's signature to prevent signature replays
                    uint256 nonce;
                    // deadline on the permit signature
                    uint256 deadline;
                }
                /// @notice Specifies the recipient address and amount for batched transfers.
                /// @dev Recipients and amounts correspond to the index of the signed token permissions array.
                /// @dev Reverts if the requested amount is greater than the permitted signed amount.
                struct SignatureTransferDetails {
                    // recipient address
                    address to;
                    // spender requested amount
                    uint256 requestedAmount;
                }
                /// @notice Transfer approved tokens from one address to another
                /// @param from The address to transfer from
                /// @param to The address of the recipient
                /// @param amount The amount of the token to transfer
                /// @param token The token address to transfer
                /// @dev Requires the from address to have approved at least the desired amount
                /// of tokens to msg.sender.
                function transferFrom(address from, address to, uint160 amount, address token) external;
                /// @notice Transfers a token using a signed permit message
                /// @dev Reverts if the requested amount is greater than the permitted signed amount
                /// @param permit The permit data signed over by the owner
                /// @param owner The owner of the tokens to transfer
                /// @param transferDetails The spender's requested transfer details for the permitted token
                /// @param signature The signature to verify
                function permitTransferFrom(
                    PermitTransferFrom memory permit,
                    SignatureTransferDetails calldata transferDetails,
                    address owner,
                    bytes calldata signature
                ) external;
                /// @notice Transfers a token using a signed permit message
                /// @notice Includes extra data provided by the caller to verify signature over
                /// @dev The witness type string must follow EIP712 ordering of nested structs and must include the TokenPermissions type definition
                /// @dev Reverts if the requested amount is greater than the permitted signed amount
                /// @param permit The permit data signed over by the owner
                /// @param owner The owner of the tokens to transfer
                /// @param transferDetails The spender's requested transfer details for the permitted token
                /// @param witness Extra data to include when checking the user signature
                /// @param witnessTypeString The EIP-712 type definition for remaining string stub of the typehash
                /// @param signature The signature to verify
                function permitWitnessTransferFrom(
                    PermitTransferFrom memory permit,
                    SignatureTransferDetails calldata transferDetails,
                    address owner,
                    bytes32 witness,
                    string calldata witnessTypeString,
                    bytes calldata signature
                ) external;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.9;
            import {IRoledPausable} from "../interfaces/IRoledPausable.sol";
            import {StorageSlot} from "./StorageSlot.sol";
            abstract contract RoledPausable is IRoledPausable {
                using StorageSlot for bytes32;
                /// Hard coded slot numbers for contract variables.
                bytes32 internal constant PAUSED_SLOT = keccak256("RoledPausable.paused");
                bytes32 internal constant PAUSER_SLOT = keccak256("RoledPausable.pauser");
                bytes32 internal constant PENDING_PAUSER_SLOT = keccak256("RoledPausable.pendingPauser");
                /// @notice msg.sender has the pauser role by default.
                constructor() {
                    _setPauser(msg.sender);
                }
                /// @notice Check if contract is paused and revert if so.
                /// @dev Meant to be used in inheritor contract.
                modifier whenNotPaused() {
                    if (paused()) revert ContractIsPaused();
                    _;
                }
                /// @inheritdoc IRoledPausable
                function updatePauser(address newPauser) external {
                    _onlyPauser();
                    PENDING_PAUSER_SLOT.setAddress(newPauser);
                    emit PauserProposed(msg.sender, newPauser);
                }
                /// @inheritdoc IRoledPausable
                function acceptPauser() external {
                    if (msg.sender != pendingPauser()) revert OnlyPendingPauser();
                    _setPauser(msg.sender);
                    PENDING_PAUSER_SLOT.setAddress(address(0));
                }
                /// @inheritdoc IRoledPausable
                function pause() external virtual {
                    _onlyPauser();
                    PAUSED_SLOT.setBool(true);
                    emit Paused();
                }
                /// @inheritdoc IRoledPausable
                function unpause() external virtual {
                    _onlyPauser();
                    PAUSED_SLOT.setBool(false);
                    emit Unpaused();
                }
                /// @inheritdoc IRoledPausable
                function paused() public view returns (bool value) {
                    value = PAUSED_SLOT.getBool();
                }
                /// @inheritdoc IRoledPausable
                function pauser() public view returns (address value) {
                    value = PAUSER_SLOT.getAddress();
                }
                /// @inheritdoc IRoledPausable
                function pendingPauser() public view returns (address value) {
                    value = PENDING_PAUSER_SLOT.getAddress();
                }
                /// @notice Update pauser value in storage.
                /// @param _pauser New pauser address value.
                function _setPauser(address _pauser) internal {
                    PAUSER_SLOT.setAddress(_pauser);
                    emit PauserUpdated(_pauser);
                }
                /// @notice Check if caller is pauser and revert if not.
                /// @dev Meant to be used in inheritor contract.
                function _onlyPauser() internal view {
                    if (msg.sender != pauser()) revert OnlyPauser();
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.9;
            /// @title StorageSlot
            /// @notice Provide functions to easily read and write different type of
            /// values at specific slots in storage.
            library StorageSlot {
                /// @notice Enable to set a uint256 value at a specific slot in storage.
                /// @param slot Slot to be written in.
                /// @param value Value to be written in the slot.
                function setUint256(bytes32 slot, uint256 value) internal {
                    assembly {
                        sstore(slot, value)
                    }
                }
                /// @notice Enable to get a uint256 value at a specific slot in storage.
                /// @param slot Slot to get value from.
                function getUint256(bytes32 slot) internal view returns (uint256 value) {
                    assembly {
                        value := sload(slot)
                    }
                }
                /// @notice Enable to set an address value at a specific slot in storage.
                /// @param slot Slot to be written in.
                /// @param value Value to be written in the slot.
                function setAddress(bytes32 slot, address value) internal {
                    assembly {
                        sstore(slot, value)
                    }
                }
                /// @notice Enable to get a address value at a specific slot in storage.
                /// @param slot Slot to get value from.
                function getAddress(bytes32 slot) internal view returns (address value) {
                    assembly {
                        value := sload(slot)
                    }
                }
                /// @notice Enable to set a bool value at a specific slot in storage.
                /// @param slot Slot to be written in.
                /// @param value Value to be written in the slot.
                function setBool(bytes32 slot, bool value) internal {
                    assembly {
                        sstore(slot, value)
                    }
                }
                /// @notice Enable to get a bool value at a specific slot in storage.
                /// @param slot Slot to get value from.
                function getBool(bytes32 slot) internal view returns (bool value) {
                    assembly {
                        value := sload(slot)
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity 0.8.23;
            import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
            import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
            import {Address} from "@openzeppelin/contracts/utils/Address.sol";
            /// @title Utils
            /// @notice Library for general purpose functions and values.
            library Utils {
                using SafeERC20 for IERC20;
                using Address for address payable;
                /// @notice Thrown when an approval call to an ERC20 contract failed.
                error ApprovalFailed();
                /// @notice Thrown when service has zero address because not available on current chain.
                error ServiceUnavailable();
                /// @notice Arbitrary address chosen to represent native token of current network.
                address internal constant nativeToken = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
                /// @notice Handle logic around approval for ERC20 token contracts depending on
                /// the context. Will give unlimited allowance on first call and only trigger
                /// again if allowance is below expected amount.
                /// @dev Handle allowance reset to comply with USDT token contract.
                /// @dev Should not be used with any contract that holds ERC20 tokens.
                /// @param token Address of the ERC20 token contract to send approval to.
                /// @param spender Address that will be granted allowance.
                /// @param amount Amount of ERC20 token to grant allowance for.
                function smartApprove(address token, address spender, uint256 amount) internal {
                    uint256 allowance = IERC20(token).allowance(address(this), spender);
                    if (allowance < amount) {
                        if (allowance > 0) {
                            _approveCall(token, spender, 0);
                        }
                        _approveCall(token, spender, type(uint256).max);
                    }
                }
                /// @notice Create, send and check low level approval call.
                /// @dev Should not be used with any contract that holds ERC20 tokens.
                /// @param token Address of the ERC20 token contract to send approval to.
                /// @param spender Address that will be granted allowance.
                /// @param amount Amount of ERC20 token to grant allowance for.
                function _approveCall(address token, address spender, uint256 amount) private {
                    // Unlimited approval is not security issue since the contract does not store any ERC20 token.
                    (bool success, ) = token.call(
                        abi.encodeWithSelector(IERC20.approve.selector, spender, amount)
                    );
                    if (!success) revert ApprovalFailed();
                }
                /// @notice Transfer token in a safe way wether it is ERC20 or native.
                /// @param token Address of the ERC20 token to be transfered.
                /// 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE in case of native token.
                /// @param to Address that will receive the tokens.
                /// @param amount Amount of ERC20 or native tokens to transfer.
                function smartTransfer(address token, address payable to, uint256 amount) internal {
                    if (token == nativeToken) {
                        to.sendValue(amount);
                    } else {
                        IERC20(token).safeTransfer(to, amount);
                    }
                }
                /// @notice Make sure required service is available on current network by checking if an address
                /// have been provided for it. Revert transaction otherwise.
                /// @param service Address of the service to be checked.
                function checkServiceAvailability(address service) internal pure {
                    if (service == address(0)) revert ServiceUnavailable();
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity 0.8.23;
            import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
            import {IPermit2} from "../interfaces/uniswap/IPermit2.sol";
            abstract contract SquidPermit2 {
                // Type hashes required for witness encoding for permit2 in SquidRouter.
                bytes32 public constant FUND_AND_RUN_MULTICALL_DATA_TYPEHASH =
                    keccak256("FundAndRunMulticallData(bytes32 hashedCalls)");
                bytes32 public constant CCTP_BRIDGE_DATA_TYPEHASH =
                    keccak256(
                        "CCTPBridgeData(uint32 destinationDomain,bytes32 destinationAddress,bytes32 destinationCaller)"
                    );
                // Witness type strings required for witness encoding for permit2 in SquidRouter.
                string public constant FUND_AND_RUN_MULTICALL_WITNESS_TYPE_STRING =
                    "FundAndRunMulticallData witness)FundAndRunMulticallData(bytes32 hashedCalls)TokenPermissions(address token,uint256 amount)";
                string public constant CCTP_BRIDGE_WITNESS_TYPE_STRING =
                    "CCTPBridgeData witness)CCTPBridgeData(uint32 destinationDomain,bytes32 destinationAddress,bytes32 destinationCaller)TokenPermissions(address token,uint256 amount)";
                IPermit2 public immutable permit2;
                /// @notice Thrown when a function using permit2 protocol is called why it is not available on current network.
                error Permit2Unavailable();
                /// @notice Thrown when a transferFrom2 call does not either have regular ERC20 or permit2 allowance.
                error TransferFailed();
                /// @notice Thrown when a value greater than type(uint160).max is cast to uint160.
                error UnsafeCast();
                /// @param _permit2 Address of the relevant Uniswap's Permit2.sol contract deployment
                /// Can be zero address if permit2 is not available on current network.
                constructor(address _permit2) {
                    permit2 = IPermit2(_permit2);
                }
                /// @notice Check if permit2 is available on current network and revert otherwise.
                modifier onlyIfPermit2Available() {
                    if (address(permit2) == address(0)) revert Permit2Unavailable();
                    _;
                }
                /// @notice Try to transferFrom tokens with regular ERC20 allowance, and falls back to permit2 allowance
                /// if not.
                /// @param token Address of the ERC20 token to be collected.
                /// @param from Address of the holder of the funds to be collected.
                /// @param to Address of the receiver of the funds to be collected.
                /// @param amount Amount of ERC20 token to be collected.
                function _transferFrom2(address token, address from, address to, uint256 amount) internal {
                    // Generate calldata for a standard transferFrom call.
                    bytes memory inputData = abi.encodeCall(IERC20.transferFrom, (from, to, amount));
                    bool success; // Call the token contract as normal, capturing whether it succeeded.
                    assembly {
                        success := and(
                            // Set success to whether the call reverted, if not we check it either
                            // returned exactly 1 (can't just be non-zero data), or had no return data.
                            or(eq(mload(0), 1), iszero(returndatasize())),
                            // Counterintuitively, this call() must be positioned after the or() in the
                            // surrounding and() because and() evaluates its arguments from right to left.
                            // We use 0 and 32 to copy up to 32 bytes of return data into the first slot of scratch space.
                            call(gas(), token, 0, add(inputData, 32), mload(inputData), 0, 32)
                        )
                    }
                    // We'll fall back to using Permit2 if calling transferFrom on the token directly reverted.
                    if (!success) {
                        // Revert transfer if Permit2 is not available.
                        if (address(permit2) == address(0)) revert TransferFailed();
                        permit2.transferFrom(from, to, _toUint160(amount), address(token));
                    }
                }
                /// @notice Safely casts uint256 to uint160.
                /// @param value The uint256 to be cast.
                /// @return Casted uint160 value.
                function _toUint160(uint256 value) private pure returns (uint160) {
                    if (value > type(uint160).max) revert UnsafeCast();
                    return uint160(value);
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity 0.8.23;
            import {ISquidRouter} from "../interfaces/ISquidRouter.sol";
            import {ISquidMulticall} from "../interfaces/ISquidMulticall.sol";
            import {IPermit2} from "../interfaces/uniswap/IPermit2.sol";
            import {IInterchainTokenService} from "../interfaces/its/IInterchainTokenService.sol";
            import {ICFReceiver} from "../interfaces/chainflip/ICFReceiver.sol";
            import {ICCTPTokenMessenger} from "../interfaces/cctp/ICCTPTokenMessenger.sol";
            import {IAxelarGasService} from "@axelar-network/axelar-cgp-solidity/contracts/interfaces/IAxelarGasService.sol"; // Deprecated
            import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
            import {AxelarExpressExecutable} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/express/AxelarExpressExecutable.sol";
            import {InterchainTokenExpressExecutable} from "../interfaces/its/InterchainTokenExpressExecutable.sol";
            import {Upgradable} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/upgradable/Upgradable.sol";
            import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
            import {Address} from "@openzeppelin/contracts/utils/Address.sol";
            import {StorageSlot} from "../libraries/StorageSlot.sol";
            import {SquidPermit2} from "./SquidPermit2.sol";
            import {RoledPausable} from "../libraries/RoledPausable.sol";
            import {Utils} from "../libraries/Utils.sol";
            contract SquidRouter is
                ISquidRouter,
                ICFReceiver,
                AxelarExpressExecutable,
                InterchainTokenExpressExecutable,
                Upgradable,
                SquidPermit2,
                RoledPausable
            {
                using SafeERC20 for IERC20;
                using StorageSlot for bytes32;
                address public immutable squidMulticall;
                address public immutable chainflipVault;
                address public immutable usdc;
                address public immutable cctpTokenMessenger;
                address public immutable axelarGasService; // Deprecated
                /// @param _squidMulticall Address of the relevant Squid's SquidMulticall.sol contract deployment.
                /// @param _permit2 Address of the relevant Uniswap's Permit2.sol contract deployment
                /// Can be zero address if not available on current network.
                /// @param _axelarGateway Address of the relevant Axelar's AxelarGateway.sol contract deployment.
                /// @param _interchainTokenService Address of the relevant Axelar's InterchainTokenService.sol contract
                /// deployment.
                /// @param _chainflipVault Address of the relevant Chainflip's Vault.sol contract deployment. Can be zero
                /// address if not available on current network.
                /// @param _usdc Address of the relevant Circle's USDC contract deployment (contract name defers from one chain
                /// to another). Can be zero address if not available on current network.
                /// @param _cctpTokenMessenger Address of the relevant Circle's TokenMessenger.sol contract deployment. Can be
                /// zero address if not available on current network.
                /// @param _axelarGasService Address of the relevant Axelar's AxelarGasService.sol contract deployment. The related
                /// logic is deprecated and will be removed in a future upgrade.
                constructor(
                    address _squidMulticall,
                    address _permit2,
                    address _axelarGateway,
                    address _interchainTokenService,
                    address _chainflipVault,
                    address _usdc,
                    address _cctpTokenMessenger,
                    address _axelarGasService // Deprecated
                )
                    AxelarExpressExecutable(_axelarGateway)
                    InterchainTokenExpressExecutable(_interchainTokenService)
                    SquidPermit2(_permit2)
                {
                    if (
                        _squidMulticall == address(0) ||
                        _interchainTokenService == address(0) ||
                        _axelarGasService == address(0) // Deprecated
                    ) revert ZeroAddressProvided();
                    squidMulticall = _squidMulticall;
                    chainflipVault = _chainflipVault;
                    usdc = _usdc;
                    cctpTokenMessenger = _cctpTokenMessenger;
                    axelarGasService = _axelarGasService; // Deprecated
                }
                //////////////////////////////////////////////////////////////
                //                                                          //
                //                        Multicall                         //
                //                                                          //
                //////////////////////////////////////////////////////////////
                /// @inheritdoc ISquidRouter
                function fundAndRunMulticall(
                    address token,
                    uint256 amount,
                    ISquidMulticall.Call[] calldata calls
                ) public payable whenNotPaused {
                    // No transfer done if native token is selected as token
                    if (token != Utils.nativeToken) {
                        _transferFrom2(token, msg.sender, address(squidMulticall), amount);
                    }
                    ISquidMulticall(squidMulticall).run{value: msg.value}(calls);
                }
                /// @inheritdoc ISquidRouter
                function permitFundAndRunMulticall(
                    ISquidMulticall.Call[] calldata calls,
                    address from,
                    IPermit2.PermitTransferFrom calldata permit,
                    bytes calldata signature
                ) external payable whenNotPaused onlyIfPermit2Available {
                    IPermit2.SignatureTransferDetails memory transferDetails = IPermit2
                        .SignatureTransferDetails({
                            to: address(squidMulticall),
                            requestedAmount: permit.permitted.amount
                        });
                    if (from == msg.sender) {
                        // If holder of the funds is sender of the transaction, call the relevant permit2 function.
                        permit2.permitTransferFrom(permit, transferDetails, from, signature);
                    } else {
                        // If holder of the funds is not sender of the transaction, build the witness data and call the relevant
                        // permit2 function.
                        bytes32 hashedCalls = keccak256(abi.encode(calls));
                        bytes32 witness = keccak256(
                            abi.encode(FUND_AND_RUN_MULTICALL_DATA_TYPEHASH, hashedCalls)
                        );
                        permit2.permitWitnessTransferFrom(
                            permit,
                            transferDetails,
                            from,
                            witness,
                            FUND_AND_RUN_MULTICALL_WITNESS_TYPE_STRING,
                            signature
                        );
                    }
                    ISquidMulticall(squidMulticall).run{value: msg.value}(calls);
                }
                //////////////////////////////////////////////////////////////
                //                                                          //
                //                     CCTP endpoints                       //
                //                                                          //
                //////////////////////////////////////////////////////////////
                /// @inheritdoc ISquidRouter
                function cctpBridge(
                    uint256 amount,
                    uint32 destinationDomain,
                    bytes32 destinationAddress,
                    bytes32 destinationCaller
                ) external whenNotPaused {
                    Utils.checkServiceAvailability(cctpTokenMessenger);
                    if (destinationCaller == bytes32(0)) revert ZeroAddressProvided();
                    _transferFrom2(usdc, msg.sender, address(this), amount);
                    ICCTPTokenMessenger(cctpTokenMessenger).depositForBurnWithCaller(
                        amount,
                        destinationDomain,
                        destinationAddress,
                        usdc,
                        destinationCaller
                    );
                }
                /// @inheritdoc ISquidRouter
                function permitCctpBridge(
                    uint32 destinationDomain,
                    bytes32 destinationAddress,
                    bytes32 destinationCaller,
                    address from,
                    IPermit2.PermitTransferFrom calldata permit,
                    bytes calldata signature
                ) external whenNotPaused onlyIfPermit2Available {
                    Utils.checkServiceAvailability(cctpTokenMessenger);
                    if (destinationCaller == bytes32(0)) revert ZeroAddressProvided();
                    IPermit2.SignatureTransferDetails memory transferDetails = IPermit2
                        .SignatureTransferDetails({
                            to: address(this),
                            requestedAmount: permit.permitted.amount
                        });
                    if (from == msg.sender) {
                        // If holder of the funds is sender of the transaction, call the relevant permit2 function.
                        permit2.permitTransferFrom(permit, transferDetails, from, signature);
                    } else {
                        // If holder of the funds is not sender of the transaction, build the witness data and call the relevant
                        // permit2 function.
                        bytes32 witness = keccak256(
                            abi.encode(
                                CCTP_BRIDGE_DATA_TYPEHASH,
                                destinationDomain,
                                destinationAddress,
                                destinationCaller
                            )
                        );
                        permit2.permitWitnessTransferFrom(
                            permit,
                            transferDetails,
                            from,
                            witness,
                            CCTP_BRIDGE_WITNESS_TYPE_STRING,
                            signature
                        );
                    }
                    ICCTPTokenMessenger(cctpTokenMessenger).depositForBurnWithCaller(
                        permit.permitted.amount,
                        destinationDomain,
                        destinationAddress,
                        usdc,
                        destinationCaller
                    );
                }
                /// @inheritdoc ISquidRouter
                function approveCctpTokenMessenger() external onlyOwner {
                    // Unlimited approval is not security issue since the contract does not store any ERC20 token.
                    IERC20(usdc).approve(cctpTokenMessenger, type(uint256).max);
                }
                //////////////////////////////////////////////////////////////
                //                                                          //
                //                     Bridge receivers                     //
                //                                                          //
                //////////////////////////////////////////////////////////////
                /// @inheritdoc ICFReceiver
                function cfReceive(
                    uint32,
                    bytes calldata,
                    bytes calldata payload,
                    address token,
                    uint256 amount
                ) external payable {
                    if (msg.sender != chainflipVault) revert OnlyCfVault();
                    _processDestinationCalls(payload, token, amount);
                }
                /// @notice Called by Axelar protocol when receiving ERC20 tokens on destination chain.
                /// Contains the logic that will run the payload calldata content.
                /// @param payload Value provided by Squid containing the calldata that will be ran on destination chain.
                /// Expected format is: abi.encode(ISquidMulticall.Call[] calls, address refundRecipient,
                /// bytes32 salt) or abi.encode(address refundRecipient, bytes32 salt) if funds need to be directly sent
                /// to destination address.
                /// @param tokenSymbol Symbol of the ERC20 token bridged.
                /// @param amount Amount of the ERC20 token bridged.
                function _executeWithToken(
                    string calldata,
                    string calldata,
                    bytes calldata payload,
                    string calldata tokenSymbol,
                    uint256 amount
                ) internal override {
                    address token = gateway.tokenAddresses(tokenSymbol);
                    _processPayload(payload, token, amount);
                }
                /// @notice Called by Interchain Token Service when receiving tokens on destination chain.
                /// Contains the logic that will run the payload calldata content.
                /// @param payload Value provided by Squid containing the calldata that will be ran on destination chain.
                /// Expected format is: abi.encode(ISquidMulticall.Call[] calls, address refundRecipient,
                /// bytes32 salt) or abi.encode(address refundRecipient, bytes32 salt) if funds need to be directly sent
                /// to destination address.
                /// @param token Address of the ERC20 token bridged.
                /// @param amount Amount of the ERC20 token bridged.
                function _executeWithInterchainToken(
                    bytes32,
                    string calldata,
                    bytes calldata,
                    bytes calldata payload,
                    bytes32,
                    address token,
                    uint256 amount
                ) internal override {
                    _processPayload(payload, token, amount);
                }
                /// @notice Check size of payload and processes is accordingly. If there is no calls, send tokens
                /// directly to user. If there are calls, run them.
                /// @dev Does not work with native token.
                /// @param payload Value provided by Squid containing the calldata that will be ran on destination chain.
                /// Expected format is: abi.encode(ISquidMulticall.Call[] calls, address refundRecipient,
                /// bytes32 salt) or abi.encode(address refundRecipient, bytes32 salt) if funds need to be directly sent
                /// to destination address.
                /// @param token Address of the ERC20 token to be either provided to the multicall to run the calls, or
                /// sent to user.
                /// @param amount Amount of the ERC20 token used. Must match msg.value
                /// if native tokens.
                function _processPayload(bytes calldata payload, address token, uint256 amount) private {
                    // If there is no call data, payload will be exactly 64 bytes (32 for padded address + 32
                    // for salt)
                    if (payload.length == 64) {
                        (address destinationAddress, ) = abi.decode(payload, (address, bytes32));
                        IERC20(token).safeTransfer(destinationAddress, amount);
                    } else {
                        _processDestinationCalls(payload, token, amount);
                    }
                }
                /// @notice Parse payload, approve multicall and run calldata on it. In case of multicall fail,
                /// bridged ERC20 tokens are refunded to refund recipient address.
                /// @param token Address of the ERC20 token to be provided to the multicall to run the calls.
                /// 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE in case of native token.
                /// @param amount Amount of ERC20 or native tokens to be provided to the multicall. Must match msg.value
                /// if native tokens.
                /// @param payload Value to be parsed to get calldata that will be ran on multicall as well as
                /// refund recipient address.
                /// Expected format is: abi.encode(ISquidMulticall.Call[] calls, address refundRecipient,
                /// bytes32 salt).
                function _processDestinationCalls(
                    bytes calldata payload,
                    address token,
                    uint256 amount
                ) private {
                    (ISquidMulticall.Call[] memory calls, address payable refundRecipient, ) = abi.decode(
                        payload,
                        (ISquidMulticall.Call[], address, bytes32)
                        // Last value is a salt that is only used to make to hash of payload vary in case of
                        // identical content of 2 calls
                    );
                    if (token != Utils.nativeToken) {
                        Utils.smartApprove(token, address(squidMulticall), amount);
                    }
                    try ISquidMulticall(squidMulticall).run{value: msg.value}(calls) {
                        emit CrossMulticallExecuted(keccak256(payload));
                    } catch (bytes memory reason) {
                        // Refund tokens to refund recipient if swap fails
                        Utils.smartTransfer(token, refundRecipient, amount);
                        emit CrossMulticallFailed(keccak256(payload), reason, refundRecipient);
                    }
                }
                //////////////////////////////////////////////////////////////
                //                                                          //
                //                        Utilities                         //
                //                                                          //
                //////////////////////////////////////////////////////////////
                /// @notice Enable onwer of the contract to transfer tokens that have been mistakenly sent to it.
                /// There is no custody risk as this contract is not meant to hold any funds in between users calls.
                /// @dev Only owner can call.
                /// @param token Address of the ERC20 token to be transfered.
                /// 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE in case of native token.
                /// @param to Address that will receive the tokens.
                /// @param amount Amount of ERC20 or native tokens to transfer.
                function rescueFunds(address token, address payable to, uint256 amount) external onlyOwner {
                    Utils.smartTransfer(token, to, amount);
                }
                //////////////////////////////////////////////////////////////
                //                                                          //
                //                    Proxy requirements                    //
                //                                                          //
                //////////////////////////////////////////////////////////////
                /// @notice Return hard coded identifier for proxy check during upgrade.
                /// @return id Hardcoded id.
                function contractId() external pure override returns (bytes32 id) {
                    id = keccak256("squid-router");
                }
                /// @notice Called by proxy during upgrade. Set pauser role to provided address.
                /// @param data Bytes containing pauser address. Checked for not zero address.
                /// Expected format is: abi.encode(address pauser).
                function _setup(bytes calldata data) internal override {
                    address _pauser = abi.decode(data, (address));
                    if (_pauser == address(0)) revert ZeroAddressProvided();
                    _setPauser(_pauser);
                }
                //////////////////////////////////////////////////////////////
                //                                                          //
                //                    Deprecated endpoints                  //
                //                                                          //
                //////////////////////////////////////////////////////////////
                /// @inheritdoc ISquidRouter
                function bridgeCall(
                    string calldata bridgedTokenSymbol,
                    uint256 amount,
                    string calldata destinationChain,
                    string calldata destinationAddress,
                    bytes calldata payload,
                    address gasRefundRecipient,
                    bool enableExpress
                ) external payable whenNotPaused {
                    address bridgedTokenAddress = gateway.tokenAddresses(bridgedTokenSymbol);
                    _transferFrom2(bridgedTokenAddress, msg.sender, address(this), amount);
                    _bridgeCall(
                        bridgedTokenSymbol,
                        bridgedTokenAddress,
                        destinationChain,
                        destinationAddress,
                        payload,
                        gasRefundRecipient,
                        enableExpress
                    );
                }
                /// @inheritdoc ISquidRouter
                function callBridgeCall(
                    address token,
                    uint256 amount,
                    ISquidMulticall.Call[] calldata calls,
                    string calldata bridgedTokenSymbol,
                    string calldata destinationChain,
                    string calldata destinationAddress,
                    bytes calldata payload,
                    address gasRefundRecipient,
                    bool enableExpress
                ) external payable whenNotPaused {
                    uint256 valueToSend;
                    if (token == Utils.nativeToken) {
                        valueToSend = amount;
                    } else {
                        _transferFrom2(token, msg.sender, address(squidMulticall), amount);
                    }
                    ISquidMulticall(squidMulticall).run{value: valueToSend}(calls);
                    address bridgedTokenAddress = gateway.tokenAddresses(bridgedTokenSymbol);
                    _bridgeCall(
                        bridgedTokenSymbol,
                        bridgedTokenAddress,
                        destinationChain,
                        destinationAddress,
                        payload,
                        gasRefundRecipient,
                        enableExpress
                    );
                }
                /// @notice Helper for handling Axelar gas service funding and Axelar bridging.
                /// @param bridgedTokenSymbol Symbol of the ERC20 token that will be sent to Axelar bridge.
                /// @param bridgedTokenAddress Address of the ERC20 token that will be sent to Axelar bridge.
                /// @param destinationChain Destination chain for bridging according to Axelar's nomenclature.
                /// @param destinationAddress Address that will receive bridged ERC20 tokens on destination chain.
                /// @param payload Bytes value containing calls to be ran by the multicall on destination chain.
                /// Expected format is: abi.encode(ISquidMulticall.Call[] calls, address refundRecipient, bytes32 salt).
                /// @param gasRefundRecipient Address that will receive native tokens left on gas service after process is
                /// done.
                /// @param enableExpress If true is provided, Axelar's express (aka Squid's boost) feature will be used.
                function _bridgeCall(
                    string calldata bridgedTokenSymbol,
                    address bridgedTokenAddress,
                    string calldata destinationChain,
                    string calldata destinationAddress,
                    bytes calldata payload,
                    address gasRefundRecipient,
                    bool enableExpress
                ) private {
                    uint256 bridgedTokenBalance = IERC20(bridgedTokenAddress).balanceOf(address(this));
                    if (address(this).balance > 0) {
                        if (enableExpress) {
                            IAxelarGasService(axelarGasService).payNativeGasForExpressCallWithToken{
                                value: address(this).balance
                            }(
                                address(this),
                                destinationChain,
                                destinationAddress,
                                payload,
                                bridgedTokenSymbol,
                                bridgedTokenBalance,
                                gasRefundRecipient
                            );
                        } else {
                            IAxelarGasService(axelarGasService).payNativeGasForContractCallWithToken{
                                value: address(this).balance
                            }(
                                address(this),
                                destinationChain,
                                destinationAddress,
                                payload,
                                bridgedTokenSymbol,
                                bridgedTokenBalance,
                                gasRefundRecipient
                            );
                        }
                    }
                    Utils.smartApprove(bridgedTokenAddress, address(gateway), bridgedTokenBalance);
                    gateway.callContractWithToken(
                        destinationChain,
                        destinationAddress,
                        payload,
                        bridgedTokenSymbol,
                        bridgedTokenBalance
                    );
                }
            }
            

            File 6 of 6: FixedPricePool
            // SPDX-License-Identifier: AGPL-3.0-only
            pragma solidity =0.8.25;
            import {
                BasePool,
                FixedPointMathLib,
                SafeTransferLib,
                MerkleProofLib,
                PoolStatus,
                PoolType,
                IERC20,
                Tier,
                TiersModified,
                FjordMath
            } from "./BasePool.sol";
            import { SafeCastLib } from "solady/utils/SafeCastLib.sol";
            /// @title FixedERC2Pool
            /// @notice A fixed price pool that allows users to purchase shares with a predefined standard ERC20 token.
            /// @notice The pool creator can set the number of shares available for purchase, the price of each share,
            /// @notice the sale start and end dates, the redemption date, and the maximum number of shares a user can purchase.
            /// @notice The pool creator can also set a minimum number of shares that must be sold for the sale to be considered successful.
            /// @notice The pool creator can also set a platform fee and a swap fee that will be taken from the raised funds.
            /// @dev Creation will fail if the asset token has less than 2 or more than 18 decimals, or if the share token has more than 18 decimals.
            /// @dev The pool will fail if the sale start date is after the sale end date, or if the redemption date is before the sale end date.
            /// @dev The pool will fail if the platform fee or swap fee is greater than or equal to 1e18.
            /// @dev The pool will fail if the price of each share is 0, or if the minimum number of shares that must be sold is greater than the number of shares available for purchase.
            contract FixedPricePool is BasePool {
                /// -----------------------------------------------------------------------
                /// Dependencies
                /// -----------------------------------------------------------------------
                using MerkleProofLib for bytes32;
                using FixedPointMathLib for uint256;
                using SafeTransferLib for address;
                using FjordMath for uint256;
                using SafeCastLib for uint256;
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// Errors
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                error TierMaxPurchaseExceeded();
                error TierPurchaseTooLow(uint256 tierIndex);
                error InvalidTierPurchaseAmount();
                error SlippageExceeded();
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// Events
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// @notice Emitted when a user purchases shares in the pool.
                event BuyFixedShares(
                    address indexed recipient, uint256 sharesOut, uint256 baseAssetsIn, uint256 feesPaid
                );
                /// @notice Emitted when a tiered sale rolls over to the next tier.
                event TierRollover(uint256 newTier);
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// Constructor
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                constructor(address _sablier) BasePool(_sablier) { }
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// FIXED PRICE LOGIC -- Immutable Arguments -- Public -- Read Functions
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// @notice The number of assets (with decimals) required to purchase 1 share.
                /// @dev This value is normalized to 18 decimals.
                function assetsPerToken() public pure returns (uint256) {
                    return _getArgUint256(ASSETS_PER_TOKEN_OFFSET);
                }
                /// @notice All the tiers available for this sale.
                function tiers() public pure returns (Tier[] memory) {
                    return abi.decode(_getArgBytes(TIERS_OFFSET, _tierDataLength()), (Tier[]));
                }
                /// @notice Whether the sale has multiple Tiers enabled, modifying the sale price and user-specific limits per tier.
                function isTiered() public pure returns (bool) {
                    return _tierDataLength() > EMPTY_TIER_ARRAY_OFFSET;
                }
                /// @notice The current tier of the sale.
                function getCurrentTierData() public view returns (Tier memory) {
                    return tiers()[currentTier];
                }
                /// @notice The tier data for a specific index.
                function getTierData(uint256 index) public pure returns (Tier memory) {
                    return tiers()[index];
                }
                /// @notice The number of tiers slots allocated to the tiers array.
                /// @dev This is used to instantiate
                function getTierLength() public pure returns (uint8) {
                    uint256 offDiff = _tierDataLength().rawSub(EMPTY_TIER_ARRAY_OFFSET);
                    if (offDiff == 0) {
                        return SafeCastLib.toUint8(0);
                    } else {
                        return (offDiff.rawDiv(TIER_BASE_OFFSET)).toUint8();
                    }
                }
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// FIXED PRICE LOGIC -- Immutable Arguments -- Internal -- Read Functions
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// @notice The byte length of the `Tiers` arg, used to decode the tiers array into the proper number of elements.
                function _tierDataLength() internal pure returns (uint256) {
                    return _getArgUint256(TIER_DATA_LENGTH_OFFSET);
                }
                /// -----------------------------------------------------------------------
                /// FIXED PRICE LOGIC -- Mutable State -- Public
                /// -----------------------------------------------------------------------
                /// @notice The active Tier of the sale, if in use.
                uint8 public currentTier;
                /// @notice The number of shares sold per tier.
                mapping(uint8 tier => uint256 totalSold) public amountSoldInTier;
                /// @notice The number of shares sold per tier per user.
                mapping(uint8 tier => mapping(address user => uint256 purchaseAmount)) public purchasedByTier;
                /// @notice The number of shares purchased by each user.
                /// @dev This value is normalized to 18 decimals.
                mapping(address user => uint256 sharesPurchased) public purchasedShares;
                /// @notice The total number of shares sold during the sale so far.
                /// @dev This value is normalized to 18 decimals.
                uint256 public totalSharesSold;
                /// @notice The total number of shares remaining for purchase.
                /// @dev This value is normalized to 18 decimals.
                function sharesRemaining() public view returns (uint256) {
                    return sharesForSale().rawSub(totalSharesSold);
                }
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// GLOBAL LOGIC -- OVERRIDE REQUIRED -- Public -- Read Functions
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// @notice Checks if the sale period has passed or the pool has reached its shares out cap.
                function canClose() public view override returns (bool) {
                    if (status == PoolStatus.Closed || status == PoolStatus.Canceled) {
                        return false;
                    }
                    // Greater comparision for safety purpose only
                    if (totalSharesSold >= sharesForSale() || uint40(block.timestamp) >= saleEnd()) {
                        return true;
                    }
                    return false;
                }
                /// @notice The underlying pricing mechanism for the pool.
                function poolType() public pure override returns (PoolType) {
                    return PoolType.Fixed;
                }
                /// @notice The keccak256 hash of the function used to buy shares in the pool.
                function typeHash() public pure override returns (bytes32) {
                    return keccak256(
                        "BuyExactShares(uint256 sharesOut,address recipient,uint32 nonce,uint64 deadline)"
                    );
                }
                /// @notice Returns the number of shares remaining for purchase for a specific user.
                /// @param user The address of the user to check.
                /// @return The number of shares remaining for purchase.
                /// @dev This value is normalized to 18 decimals.
                function userTokensRemaining(address user) public view override returns (uint256) {
                    return maximumTokensPerUser().rawSub(purchasedShares[user]).min(sharesRemaining());
                }
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// GLOBAL LOGIC -- OVERRIDE REQUIRED -- Internal -- Read Functions
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                ///@notice Checks if the minimum number of asset tokens have been swapped into the pool
                ///surpassed the creator-defined minimum.
                ///@dev Returning false will trigger refunds on `close` and user refunds on `redeem`.
                function _minReserveMet() internal view override returns (bool) {
                    if (minimumTokensForSale() > 0 && totalSharesSold < minimumTokensForSale()) {
                        return false;
                    }
                    return true;
                }
                /// -----------------------------------------------------------------------
                /// BUY LOGIC -- OVERRIDE REQUIRED -- Internal -- Read Functions
                /// -----------------------------------------------------------------------
                /// @notice Calculates the number of asset tokens that will be swapped into the pool before fees.
                /// @dev For overflow pools this is always the tokenAmount passed in, we're just conforming to the interface.
                function _calculateBaseAssetsIn(
                    address recipient,
                    uint256 tokenAmount,
                    uint256 maxPricePerShare
                )
                    internal
                    view
                    override
                    returns (uint256, TiersModified[] memory)
                {
                    if (!isTiered()) {
                        return (tokenAmount.mulWadUp(assetsPerToken()), new TiersModified[](0));
                    }
                    return _calculateTieredPurchase(recipient, tokenAmount, maxPricePerShare);
                }
                /// @notice Normalizes the assets being swapped in to 18 decimals, if needed.
                /// @param amount The amount of assets being swapped in.
                function _normalizeAmount(uint256 amount) internal pure override returns (uint256) {
                    return amount.normalize(shareDecimals());
                }
                /// @notice Checks if the pool has reached its asset token hard cap.
                /// @dev This value does not account for assets in the pool in the form of swap fees.
                function _raiseCapMet() internal view override returns (bool) {
                    // Greater comparision for safety purpose only
                    return totalSharesSold >= sharesForSale();
                }
                /// @notice Validates the amount of shares being swapped in do not exceed Overflow specific limits.
                /// @dev The amount of shares being swapped in must not exceed the shares for sale.
                /// @dev The amount of shares remaining for purchase before the pool cap is met after the swap must be greater than the mandatoryMinimumSwapIn to prevent the pool from being left with dust.
                /// @param amount The amount of shares being swapped in.
                function _validatePoolLimits(uint256 amount) internal view override {
                    if (amount > sharesForSale()) {
                        revert MaxPurchaseExeeded();
                    }
                    if (totalSharesSold.rawAdd(amount) > sharesForSale()) {
                        revert MaxPurchaseExeeded();
                    }
                    if (
                        mandatoryMinimumSwapIn() > 0 && sharesRemaining().rawSub(amount) > 0
                            && sharesRemaining().rawSub(amount) < mandatoryMinimumSwapIn()
                    ) {
                        revert MandatoryMinimumSwapThreshold();
                    }
                }
                /// @notice Validates the amount of shares being swapped in do not exceed FixedPrice specific user limits.
                /// @dev The amount of shares purchased in total(including this swap) by the user must not exceed the user's maximum purchase limit.
                /// @dev The amount of shares purchased in total(including this swap) must not be less than the user's minimum purchase limit.
                /// @param recipient The address of the user swapping in.
                /// @param tokenAmount The amount of shares being swapped in.
                function _validateUserLimits(address recipient, uint256 tokenAmount) internal view override {
                    uint256 updatedUserAmount = purchasedShares[recipient].rawAdd(tokenAmount);
                    if (updatedUserAmount > maximumTokensPerUser()) revert UserMaxPurchaseExceeded();
                    if (updatedUserAmount < minimumTokensPerUser()) revert UserMinPurchaseNotMet();
                }
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// BUY LOGIC -- OVERRIDE REQUIRED --  Internal -- Write Functions
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// @notice Helper function to emit the BuyFixedShares event post purchase.
                /// @dev All values are denormalized before being emitted.
                function _emitBuyEvent(
                    address recipient,
                    uint256 assetsIn,
                    uint256 feesPaid,
                    uint256 sharesOut
                )
                    internal
                    override
                {
                    emit BuyFixedShares(
                        recipient,
                        sharesOut.denormalizeDown(shareDecimals()),
                        assetsIn.denormalizeUp(assetDecimals()),
                        feesPaid.denormalizeUp(assetDecimals())
                    );
                }
                /// @notice Updates the pool state after a successful asset swap in.
                /// @dev Updates the total shares sold, the user's purchased shares, the user's assets in,
                /// the total assets in, and the total fees in.
                function _updatePoolState(
                    address recipient,
                    uint256 assetsIn,
                    uint256 sharesOut,
                    uint256 fees,
                    TiersModified[] memory tiersModified
                )
                    internal
                    override
                    returns (uint256)
                {
                    //Update Pool shares
                    totalSharesSold = totalSharesSold.rawAdd(sharesOut);
                    purchasedShares[recipient] = purchasedShares[recipient].rawAdd(sharesOut);
                    //Update Pool assets
                    userNormalizedAssetsIn[recipient] = userNormalizedAssetsIn[recipient].rawAdd(assetsIn);
                    totalNormalizedAssetsIn = totalNormalizedAssetsIn.rawAdd(assetsIn);
                    //Update Pool fees
                    totalNormalizedAssetFeesIn = totalNormalizedAssetFeesIn.rawAdd(fees);
                    if (isTiered()) {
                        _updateTierData(recipient, tiersModified);
                    }
                    return (assetsIn.rawAdd(fees));
                }
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// BUY LOGIC --  TIER SPECIFIC -- Internal -- Read Functions
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                ///@notice Helper function to calculate the amount of assets the user will swap into the pool and the amount of shares they are able to receive.
                ///@param tier The tier the user is attempting to purchase in.
                ///@param tierIndex The index of the tier the user is attempting to purchase in.
                ///@param newTotalUserPurchased The total amount of shares the user will have purchased in the tier after this purchase.
                ///@param newTotalSold The total amount of shares sold in the tier after this purchase.
                ///@param sharesOut The amount of shares the user is attempting to purchase.
                ///@return assetsIn The total amount of assets the user will swap into the pool before swap fees are applied.
                ///@return sharesOutInTier The total amount of shares the user will purchase in the tier.
                ///@dev This function will revert if the user is attempting to purchase more shares than they are allowed across all tiers.
                function _calculatePurchaseAmounts(
                    Tier memory tier,
                    address recipient,
                    uint8 tierIndex,
                    uint256 newTotalUserPurchased,
                    uint256 newTotalSold,
                    uint256 sharesOut
                )
                    internal
                    view
                    returns (uint256 assetsIn, uint256 sharesOutInTier)
                {
                    (uint256 userMaxAssetsIn, uint256 userMaxSharesOutInTier) = (0, 0);
                    (uint256 tierMaxAssetsIn, uint256 tierMaxSharesOutInTier) = (0, 0);
                    if (newTotalUserPurchased > tier.maximumPerUser) {
                        (userMaxAssetsIn, userMaxSharesOutInTier) =
                            _handleExcessPurchase(tier, recipient, tierIndex);
                    }
                    if (newTotalSold > tier.amountForSale) {
                        (tierMaxAssetsIn, tierMaxSharesOutInTier) = _handleTierOverflow(tier, tierIndex);
                    }
                    if (userMaxAssetsIn == 0 && tierMaxAssetsIn == 0) {
                        assetsIn = sharesOut.mulWadUp(tier.pricePerShare);
                        sharesOutInTier = sharesOut;
                    }
                    // If only the tier limit was exceeded
                    else if (userMaxAssetsIn == 0) {
                        (assetsIn, sharesOutInTier) = (tierMaxAssetsIn, tierMaxSharesOutInTier);
                    }
                    // If only the user limit was exceeded
                    else if (tierMaxAssetsIn == 0) {
                        (assetsIn, sharesOutInTier) = (userMaxAssetsIn, userMaxSharesOutInTier);
                    }
                    // If both limits were exceeded, take the minimum
                    else {
                        if (tierMaxAssetsIn < userMaxAssetsIn) {
                            (assetsIn, sharesOutInTier) = (tierMaxAssetsIn, tierMaxSharesOutInTier);
                        } else {
                            (assetsIn, sharesOutInTier) = (userMaxAssetsIn, userMaxSharesOutInTier);
                        }
                    }
                }
                ///@notice Helper function to handle the case where a user is attempting to purchase more shares than they are allowed for that tier.
                ///@param tier The tier the user is attempting to purchase in.
                ///@param recipient The address of the user attempting to purchase.
                ///@param tierIndex The index of the tier the user is attempting to purchase in.
                ///@dev This function will revert if there is no next tier as that would indicate they are unable to fulfill the current order.
                function _handleExcessPurchase(
                    Tier memory tier,
                    address recipient,
                    uint8 tierIndex
                )
                    internal
                    view
                    returns (uint256 assetsIn, uint256 sharesOutInTier)
                {
                    _validateNextTierExists(tierIndex);
                    sharesOutInTier = tier.maximumPerUser.rawSub(purchasedByTier[tierIndex][recipient]);
                    assetsIn = sharesOutInTier.mulWadUp(tier.pricePerShare);
                }
                ///@notice Helper function to handle the case where a user is attempting to purchase more shares than are available in the current tier.
                ///@param tier The tier the user is attempting to purchase in.
                ///@param tierIndex The index of the tier the user is attempting to purchase in.
                ///@dev This function will revert if there is no next tier as that would indicate they are unable to fulfill the current order.
                function _handleTierOverflow(
                    Tier memory tier,
                    uint8 tierIndex
                )
                    internal
                    view
                    returns (uint256 assetsIn, uint256 sharesOutInTier)
                {
                    _validateNextTierExists(tierIndex);
                    sharesOutInTier = tier.amountForSale.rawSub(amountSoldInTier[tierIndex]);
                    assetsIn = sharesOutInTier.mulWadUp(tier.pricePerShare);
                }
                ///@notice Helper function to check that the requested swap amount meets the minimum purchase requirements for the tier.
                // function _validateMinimumPurchase(
                //     uint256 tierIndex,
                //     uint256 minimumPerUser,
                //     uint256 tokenAmount
                // )
                //     internal
                //     pure
                // {
                //     if (tokenAmount < minimumPerUser) {
                //         revert TierPurchaseTooLow(tierIndex);
                //     }
                // }
                ///@notice Helper function to validate that the next tier exists before attempting to purchase in it and accessing OOB data.
                ///@param tierIndex The index of the tier the user is attempting to purchase in.
                ///@dev This function will revert if there is no next tier as that would indicate they are unable to fulfill the current order.
                function _validateNextTierExists(uint8 tierIndex) internal pure {
                    if (tierIndex + 1 > getTierLength() - 1) {
                        revert TierMaxPurchaseExceeded();
                    }
                }
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// BUY LOGIC --  TIER SPECIFIC -- Internal -- Write Functions
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                ///@notice Helper function to check if the current tier has reached its maximum shares sold and rollover to the next tier if needed.
                ///@param currentTierSharesOut The total amount of shares sold in the current tier.
                ///@param maximumInTier The maximum amount of shares that can be sold in the current tier.
                ///@dev emits a `TierRollover` event if the current tier has reached its maximum shares sold.
                function _handleTierRollover(uint256 currentTierSharesOut, uint256 maximumInTier) internal {
                    if (currentTierSharesOut >= maximumInTier) {
                        currentTier++;
                        emit TierRollover(currentTier);
                    }
                }
                ///@notice Helper function to perform an iteration across the current tier and all subsequent tiers to validate the user's
                ///requested purchase amount is within the bounds of the Tiers combined min/max purchase limits.
                ///@param recipient The address of the user purchasing shares.
                ///@param shareAmount The amount of shares the user is attempting to purchase.
                ///@return assetsIn The total amount of assets the user will swap into the pool before swap fees are applied.
                ///@dev This function will revert if the user is attempting to purchase more shares than they are allowed across all tiers. It will additionally
                ///rollover the tier to the next one if the current tier reaches its maximum shares sold within this transaction.
                function _calculateTieredPurchase(
                    address recipient,
                    uint256 shareAmount,
                    uint256 maxPricePerShare
                )
                    internal
                    view
                    returns (uint256 assetsIn, TiersModified[] memory tiersModified)
                {
                    uint256 tempSharesOut;
                    uint8 lengthOfTiers = getTierLength();
                    uint8 iter;
                    tiersModified = new TiersModified[](lengthOfTiers);
                    for (uint8 i = currentTier; i < lengthOfTiers; i++) {
                        if (maxPricePerShare != 0 && getTierData(i).pricePerShare > maxPricePerShare) {
                            revert SlippageExceeded();
                        }
                        //Ensure there is a next tier available and the user is not attempting to purchase more/less shares than they are allowed.
                        (uint256 assetsInInTier, uint256 sharesOutInTier) =
                            _validateAndReturnTierLimits(i, recipient, shareAmount.rawSub(tempSharesOut));
                        tiersModified[iter] = TiersModified({
                            tierIndex: i,
                            assetsIn: assetsInInTier,
                            sharesOutInTier: sharesOutInTier
                        });
                        tempSharesOut = tempSharesOut.rawAdd(sharesOutInTier);
                        assetsIn = assetsIn.rawAdd(assetsInInTier);
                        if (tempSharesOut > shareAmount) {
                            revert TierMaxPurchaseExceeded();
                        }
                        //If the user has purchased the requested amount of shares, exit the loop.
                        if (tempSharesOut == shareAmount) {
                            break;
                        }
                        unchecked {
                            iter++;
                        }
                    }
                    if (tempSharesOut != shareAmount) {
                        revert InvalidTierPurchaseAmount();
                    }
                }
                ///@notice Helper function to update state data for the tier at index after this iteration of purchases is complete.
                function _updateTierData(address recipient, TiersModified[] memory tiersModified) internal {
                    uint8 length = tiersModified.length.toUint8();
                    for (uint8 i; i < length; i++) {
                        if (tiersModified[i].assetsIn == 0) {
                            continue;
                        }
                        uint8 tierIndex = tiersModified[i].tierIndex;
                        uint256 sharesOutInTier = tiersModified[i].sharesOutInTier;
                        purchasedByTier[tierIndex][recipient] += sharesOutInTier;
                        amountSoldInTier[tierIndex] += sharesOutInTier;
                        _handleTierRollover(amountSoldInTier[tierIndex], getTierData(tierIndex).amountForSale);
                    }
                }
                ///@notice Helper function to update state data for the tier at index after this iteration of purchases is complete, and return both the assets in and shares out for the user.
                ///@param tierIndex The index of the tier to update.
                ///@param recipient The address of the user purchasing shares.
                ///@param sharesOutInTier The amount of shares the user is purchasing in the tier.
                ///@dev This function will revert if the user is attempting to purchase more shares than they are allowed across all tiers.
                function _validateAndReturnTierLimits(
                    uint8 tierIndex,
                    address recipient,
                    uint256 tokenAmount
                )
                    internal
                    view
                    returns (uint256 assetsIn, uint256 sharesOutInTier)
                {
                    Tier memory tier = getTierData(tierIndex);
                    // if one tier fail this condition when rollover the whole transaction will be reverted
                    if (tokenAmount < tier.minimumPerUser) {
                        revert TierPurchaseTooLow(tierIndex);
                    }
                    // _validateMinimumPurchase(tierIndex, tier.minimumPerUser, tokenAmount);
                    (assetsIn, sharesOutInTier) = _calculatePurchaseAmounts(
                        tier,
                        recipient,
                        tierIndex,
                        purchasedByTier[tierIndex][recipient].rawAdd(tokenAmount),
                        amountSoldInTier[tierIndex].rawAdd(tokenAmount),
                        tokenAmount
                    );
                }
                /// -----------------------------------------------------------------------
                /// BUY LOGIC -- PUBLIC -- Write Functions
                /// -----------------------------------------------------------------------
                ///@notice Allows a user to purchase shares in the pool by swapping in assets.
                ///@param sharesOut The amount of shares to swap out the pool.
                ///@param recipient The address that will receive the shares.
                ///@param deadline The deadline for the swap to be executed.
                ///@param signature The signature of the user authorizing the swap.
                ///@param proof The Merkle proof for the user's whitelist status.
                ///@dev If the pool has reached its asset token hard cap, the pool will emit a `PoolCompleted` event.
                /// @dev The sharesOut value should not be normalized to 18 decimals when supplied.
                function buyExactShares(
                    uint256 sharesOut,
                    address recipient,
                    uint64 deadline,
                    bytes memory signature,
                    bytes32[] memory proof
                )
                    public
                    whenSaleActive
                {
                    buy(sharesOut, recipient, deadline, signature, proof, 0);
                }
                ///@notice Allows a user to purchase shares in the pool by swapping in assets.
                ///@param sharesOut The amount of shares to swap out the pool.
                ///@param recipient The address that will receive the shares.
                ///@param deadline The deadline for the swap to be executed.
                ///@param signature The signature of the user authorizing the swap.
                ///@param proof The Merkle proof for the user's whitelist status.
                ///@param maxPricePerShare The maximum price per share the user is willing to pay.
                ///@dev If the pool has reached its asset token hard cap, the pool will emit a `PoolCompleted` event.
                /// @dev The sharesOut value should not be normalized to 18 decimals when supplied.
                function buyExactShares(
                    uint256 sharesOut,
                    address recipient,
                    uint64 deadline,
                    bytes memory signature,
                    bytes32[] memory proof,
                    uint256 maxPricePerShare
                )
                    public
                    whenSaleActive
                {
                    buy(sharesOut, recipient, deadline, signature, proof, maxPricePerShare);
                }
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// CLOSE LOGIC -- Overriden --  Internal -- Read Functionss
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// @notice Calculates and denormalizes the number of unsold shares that will be refunded to the owner.
                /// @dev For FixedPricePools this is the difference between the total shares sold and the shares available for purchase.
                function _calculateLeftoverShares() internal view override returns (uint256 sharesNotSold) {
                    sharesNotSold = (sharesForSale().rawSub(totalSharesSold)).denormalizeDown(shareDecimals());
                }
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// CLOSE LOGIC -- Overriden --  Internal -- Write Functions
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// @notice Helper function to handle refunding in the case of a minReserve not being met.
                /// @dev Refunds all shares to the owner(), and distro's asset swap fees to the platform.
                function _handleManagerRefund()
                    internal
                    override
                    returns (uint256 sharesNotSold, uint256 fundsRaised, uint256 swapFeesGenerated)
                {
                    (sharesNotSold, fundsRaised, swapFeesGenerated) = super._handleManagerRefund();
                    sharesNotSold = sharesNotSold.rawSub(totalSharesSold.denormalizeDown(shareDecimals()));
                    if (shareToken() != address(0)) {
                        uint256 sharesTotal = IERC20(shareToken()).balanceOf(address(this));
                        if (sharesTotal > 0) {
                            shareToken().safeTransfer(owner(), sharesTotal);
                        }
                    }
                }
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// REDEEM LOGIC -- Overriden --  Internal -- READ Functions
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// @notice Calculates and denormalizes the number of shares owed to the user based on the number of shares they have purchased.
                function _calculateSharesOwed(address sender)
                    internal
                    view
                    override
                    returns (uint256 sharesOut)
                {
                    sharesOut = purchasedShares[sender].denormalizeDown(shareDecimals());
                }
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// REDEEM LOGIC -- Overriden --  Internal -- Write Functions
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// @notice Sets the users assets in and purchased shares balances to 0 after a successful redemption.
                function _handleUpdateUserRedemption(address sender) internal override {
                    purchasedShares[sender] = 0;
                    userNormalizedAssetsIn[sender] = 0;
                }
                /// @notice Helper function to handle refunding in the case of a minReserve not being met.
                /// @dev Refunds all assets to the purchaser sans swap fees.
                function _handleUserRefund(address sender) internal override returns (uint256 assetsOwed) {
                    assetsOwed = userNormalizedAssetsIn[sender].denormalizeDown(assetDecimals());
                    purchasedShares[sender] = 0;
                    userNormalizedAssetsIn[sender] = 0;
                    if (assetsOwed > 0) {
                        assetToken().safeTransfer(sender, assetsOwed);
                    }
                }
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                ///  EIP712 Helper Functions
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// @notice Overrides the default domain name and version for EIP-712 signatures.
                function _domainNameAndVersion()
                    internal
                    pure
                    override
                    returns (string memory name, string memory version)
                {
                    name = "FixedPricePool";
                    version = "1.0.0";
                }
            }
            // SPDX-License-Identifier: AGPL-3.0-only
            pragma solidity =0.8.25;
            import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol";
            import { FixedPointMathLib } from "solady/utils/FixedPointMathLib.sol";
            import { ReentrancyGuard } from "solady/utils/ReentrancyGuard.sol";
            import { Clone } from "solady/utils/Clone.sol";
            import { MerkleProofLib } from "solady/utils/MerkleProofLib.sol";
            import { EIP712 } from "solady/utils/EIP712.sol";
            import { ECDSA } from "solady/utils/ECDSA.sol";
            import { ud60x18 } from "@prb/math/src/UD60x18.sol";
            import {
                ISablierV2LockupLinear,
                IERC20
            } from "@sablier/v2-core/src/interfaces/ISablierV2LockupLinear.sol";
            import { Broker, LockupLinear } from "@sablier/v2-core/src/types/DataTypes.sol";
            import { FjordMath } from "./libraries/FjordMath.sol";
            import { FjordConstants } from "./libraries/FjordConstants.sol";
            enum PoolStatus {
                Active,
                Paused,
                Closed,
                Canceled
            }
            enum PoolType {
                Fixed,
                Overflow
            }
            /// @notice A struct representing a tiered sale within a FixedPricePool.
            /// @param amountForSale The total number of shares available for purchase in this tier.
            /// @param pricePerShare The price per share in this tier.
            /// @param maximumPerUser The maximum number of shares a user can purchase in this tier.
            /// @param minimumPerUser The minimum number of shares a user must purchase in this tier.
            struct Tier {
                uint256 amountForSale;
                uint256 pricePerShare;
                uint256 maximumPerUser;
                uint256 minimumPerUser;
            }
            struct TiersModified {
                uint8 tierIndex;
                uint256 assetsIn;
                uint256 sharesOutInTier;
            }
            abstract contract BasePool is Clone, ReentrancyGuard, EIP712, FjordConstants {
                /// -----------------------------------------------------------------------
                /// Dependencies
                /// -----------------------------------------------------------------------
                using SafeTransferLib for address;
                using FixedPointMathLib for uint256;
                using FjordMath for *;
                using MerkleProofLib for *;
                using ECDSA for bytes32;
                /// -----------------------------------------------------------------------
                /// Errors
                /// -----------------------------------------------------------------------
                /// @notice Error when the whitelist proof provided is invalid or does not exist.
                error InvalidProof();
                /// @notice Error when the recovered signer of the signature is not the delegate signer.
                error InvalidSignature();
                /// @notice Error when the user attempts to purchase/supply more than the maximum allowed.
                error MaxPurchaseExeeded();
                /// @notice Error when the user attempts to purchase/supply less than the minimum allowed.
                error MinPurchaseNotMet();
                /// @notice Error when the user attempts to redeem shares that they do not have.
                error NoSharesRedeemable();
                /// @notice Error when the caller is not the pool owner.
                error NotOwner();
                /// @notice Error when the redemption timestamp has not been reached.
                error RedeemedTooEarly();
                /// @notice Error when the sale is still active.
                error SaleActive();
                /// @notice Error when a redeem is called on a canceled pool.
                error SaleCancelled();
                /// @notice Error when the sale is paused/canceled/closed.
                error SaleInactive();
                /// @notice Error when the sale is not cancelable due to the sale being active.
                error SaleNotCancelable();
                /// @notice Error when the sale is not pausable due to the sale being closed or cancelled.
                error SaleNotPausable();
                /// @notice Error when the user attempts to purchase/supply an amount that would leave less than the minimum swap threshold available in the pool.
                error MandatoryMinimumSwapThreshold();
                /// @notice Error when the signature deadline has passed.
                error StaleSignature();
                /// @notice Error emitted when a user tries to redeem a token that is not redeemable, generally due to the token being airdropped on a different chain post sale.
                error TokenNotRedeemable();
                /// @notice Error when a user tries to swap an amount of tokens that is 0.
                error TransferZero();
                /// @notice Error when a user tries to purchase more than the maximum purchase amount.
                error UserMaxPurchaseExceeded();
                /// @notice Error when the user tries to purchase less than the minimum purchase amount.
                error UserMinPurchaseNotMet();
                /// @notice Error when the recipient address is the zero address.
                error ZeroAddress();
                /// @notice Invalid close operations.
                error CloseConditionNotMet();
                /// -----------------------------------------------------------------------
                /// Events
                /// -----------------------------------------------------------------------
                /// @notice Emitted when the pool is closed and the funds are distributed.
                event Closed(
                    uint256 totalFundsRaised, uint256 totalSharesSold, uint256 platformFee, uint256 swapFee
                );
                /// @notice Emitted when the pool is paused or unpaused.
                event PauseToggled(bool paused);
                /// @notice Emitted when the pool is canceled before it begins.
                event PoolCanceled();
                /// @notice Emitted when the pool is able to close early due to reaching its raise cap.
                event PoolCompleted();
                /// @notice Emitted when a user is refunded due to the raise goal not being met.
                event Refunded(address indexed recipient, uint256 amount);
                /// @notice Emitted when a user redeems their shares post sale if the raise goal was met.
                event Redeemed(address indexed recipient, uint256 shares, uint256 streamID);
                /// @notice Emitted when the raise goal is not met and the pool is closed.
                event RaiseGoalNotMet(uint256 sharesNotSold, uint256 fundsRaised, uint256 feesGenerated);
                /// -----------------------------------------------------------------------
                /// Immutable Arguments -- Public
                /// -----------------------------------------------------------------------
                ISablierV2LockupLinear public immutable SABLIER;
                /// -----------------------------------------------------------------------
                /// Immutable Arguments -- Public
                /// -----------------------------------------------------------------------
                /// @notice The owner of the pool.
                /// @dev The owner can cancel the sale before it starts, pause/unpause the sale, and will receive the funds raised post sale.
                function owner() public pure returns (address) {
                    return _getArgAddress(OWNER_OFFSET);
                }
                /// @notice The address of the share token that is being sold off by the creator.
                function shareToken() public pure returns (address) {
                    return _getArgAddress(SHARE_TOKEN_OFFSET);
                }
                /// @notice Returns the address of the asset token used for purchasing shares.
                function assetToken() public pure returns (address) {
                    return _getArgAddress(ASSET_TOKEN_OFFSET);
                }
                /// @notice Returns the address of the recipient of platform and swap fees generated by the pool.
                function feeRecipient() public pure returns (address) {
                    return _getArgAddress(FEE_RECIPIENT_OFFSET);
                }
                /// @notice Returns the address of the delegate signer used for anti-snipe protection.
                /// @dev This address is provided by the factory contract and is protocol-owned.
                function delegateSigner() public pure returns (address) {
                    return _getArgAddress(DELEGATE_SIGNER_OFFSET);
                }
                /// @notice The total number of shares that are being sold during the sale.
                /// @dev This value is normalized to 18 decimals.
                function sharesForSale() public pure virtual returns (uint256) {
                    return _getArgUint256(SHARES_FOR_SALE_OFFSET);
                }
                /// @notice Returns the minimum raise goal defined by the creator.
                /// @dev For FixedPricePools, this is the number of shares that must be sold.
                /// @dev For OverflowPools, this is the number of assets that must be raised.
                /// @dev If the minimum raise goal is not met, users and creator are refunded.
                /// @dev This value is normalized to 18 decimals.
                function minimumTokensForSale() public pure returns (uint256) {
                    return _getArgUint256(MINIMUM_TOKENS_FOR_SALE_OFFSET);
                }
                /// @notice Returns the maximum number of tokens that can be purchased within a sale.
                /// @dev For FixedPricePools, this is the number of shares a user can purchase.
                /// @dev For OverflowPools, this is the number of assets a user can used to purchase.
                /// @dev This value is normalized to 18 decimals.
                function maximumTokensPerUser() public pure returns (uint256) {
                    return _getArgUint256(MAXIMUM_TOKENS_PER_USER_OFFSET);
                }
                /// @notice Returns the minimum number of tokens that must be purchased within a sale.
                /// @dev For FixedPricePools, this is the minimum number of shares a user must purchase.
                /// @dev For OverflowPools, this is the minimum number of assets a user must use to purchase.
                /// @dev This value is normalized to 18 decimals.
                function minimumTokensPerUser() public pure returns (uint256) {
                    return _getArgUint256(MINIMUM_TOKENS_PER_USER_OFFSET);
                }
                /// @notice The swap fee charged on each purchase.
                /// @dev This value is scaled to WAD such that 1e18 is equivalent to a 100% swap fee.
                function swapFeeWAD() public pure returns (uint64) {
                    return _getArgUint64(SWAP_FEE_WAD_OFFSET);
                }
                /// @notice The platform fee charged on post-sale funds raised.
                function platformFeeWAD() public pure returns (uint64) {
                    return _getArgUint64(PLATFORM_FEE_WAD_OFFSET);
                }
                /// @notice The timestamp at which the sale will start.
                function saleStart() public pure returns (uint40) {
                    return _getArgUint40(SALE_START_OFFSET);
                }
                /// @notice The timestamp at which the sale will end.
                /// @dev This value is bypassed if a raise goal is defined and met or exceeded.
                function saleEnd() public pure returns (uint40) {
                    return _getArgUint40(SALE_END_OFFSET);
                }
                /// @notice The timestamp at which users will be able to redeem their shares.
                /// @dev This value is bypassed in favor of a 24H max should a sale end early due to meeting its raise cap.
                function redemptionDelay() public pure returns (uint40) {
                    return _getArgUint40(REDEMPTION_DELAY_OFFSET);
                }
                /// @notice The timestamp at which the vesting period will end.
                function vestEnd() public pure returns (uint40) {
                    return _getArgUint40(VEST_END_OFFSET);
                }
                /// @notice The timestamp at which the vesting cliff period will end.
                function vestCliff() public pure returns (uint40) {
                    return _getArgUint40(VEST_CLIFF_OFFSET);
                }
                /// @notice The number of decimals for the share token.
                function shareDecimals() public pure returns (uint8) {
                    return _getArgUint8(SHARE_TOKEN_DECIMALS_OFFSET);
                }
                /// @notice Returns the number of decimals for the asset token.
                function assetDecimals() public pure returns (uint8) {
                    return _getArgUint8(ASSET_TOKEN_DECIMALS_OFFSET);
                }
                /// @notice Returns true if the anti-snipe feature is enabled, false otherwise.
                /// @dev If anti-snipe is enabled, a valid signature from a delegate signer is required to make a purchase.
                function antiSnipeEnabled() public pure returns (bool) {
                    return _getArgUint8(ANTISNIPE_ENABLED_OFFSET) != 0;
                }
                /// @notice A merkle root representing a whitelist of addresses allowed to participate in the sale.
                /// @dev If the whitelist is empty, the sale is open to all addresses.
                function whitelistMerkleRoot() public pure returns (bytes32) {
                    return _getArgBytes32(WHITELIST_MERKLE_ROOT_OFFSET);
                }
                function vestingEnabled() public pure returns (bool) {
                    return vestEnd() > saleEnd();
                }
                /// -----------------------------------------------------------------------
                /// Mutable State -- Public
                /// -----------------------------------------------------------------------
                /// @notice The current transaction nonce of the recipient, used for anti-snipe replay protection.
                mapping(address user => uint32 nonce) public nonces;
                /// @notice The current status of the pool (Paused, Active, Canceled, Closed).
                PoolStatus public status;
                /// @notice The total number of assets received during the sale, sans swap fees.
                /// @dev Must be denormalized before use.
                uint256 public totalNormalizedAssetsIn;
                /// @notice The total amount of swap fees generated during the sale.
                /// @dev Must be denormalized before use.
                uint256 public totalNormalizedAssetFeesIn;
                /// @notice The total normalized number of assets received per user, without accounting for swap fees.
                /// @dev Must be denormalized before use.
                mapping(address user => uint256 assetsIn) public userNormalizedAssetsIn;
                /// @dev actual sale end timestamp
                uint256 public saleEndTimestamp;
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                /// Constructor
                /// -----------------------------------------------------------------------------------------------------------------------------------------
                constructor(address sablier) {
                    SABLIER = ISablierV2LockupLinear(sablier);
                }
                /// -----------------------------------------------------------------------
                /// Modifiers
                /// -----------------------------------------------------------------------
                /// @notice Checks if the caller is the owner of the pool.
                modifier onlyOwner() {
                    if (msg.sender != owner()) {
                        revert NotOwner();
                    }
                    _;
                }
                /// @notice Checks if the current timestamp is lessthan the sale start, greater than the sale end, or canceled/closed/paused.
                /// @dev If the sale is not active, the pool bought into.
                modifier whenSaleActive() {
                    if (
                        uint40(block.timestamp) < saleStart() || uint40(block.timestamp) >= saleEnd()
                            || PoolStatus.Active != status
                    ) {
                        revert SaleInactive();
                    }
                    _;
                }
                /// -----------------------------------------------------------------------
                /// GLOBAL LOGIC -- OVERRIDE REQUIRED -- Public -- Read Functions
                /// -----------------------------------------------------------------------
                /// @notice Checks if the pool can be closed.
                /// @return True if the pool can be closed, false otherwise.
                /// @dev The pool can be closed if all shares have been sold, or the sale end date has passed.
                function canClose() public view virtual returns (bool);
                /// @notice Returns the pool's pricing model (Fixed or Overflow).
                function poolType() public pure virtual returns (PoolType);
                /// @notice Returns the hash of the EIP712 typehash for the pool's buy function.
                function typeHash() public pure virtual returns (bytes32);
                /// @notice Returns the number of tokens remaining for purchase.
                /// @dev For FixedPricePools, this is the Math.min(sharesForSale - totalSharesSold, maximumTokensPerUser - purchasedShares[user]).
                /// @dev For OverflowPools, this is maximumTokensPerUser - rawAssetsIn[user] when mTPU > 0.
                function userTokensRemaining(address user) public view virtual returns (uint256);
                /// -----------------------------------------------------------------------
                /// GLOBAL LOGIC -- OVERRIDE REQUIRED -- Internal -- Read Functions
                /// -----------------------------------------------------------------------
                ///@dev Checks if the minimum reserve is set and whether or not the shares/assets in sold surpasses this value.
                function _minReserveMet() internal view virtual returns (bool);
                /// -----------------------------------------------------------------------
                /// GLOBAL LOGIC -- Public -- Read Functions
                /// -----------------------------------------------------------------------
                /// @notice Whether or not a non-empty whitelist is present.
                function hasWhitelist() public pure returns (bool) {
                    return whitelistMerkleRoot() != 0;
                }
                /// -----------------------------------------------------------------------
                /// BUY LOGIC -- OVERRIDE REQUIRED -- Internal -- Read Functions
                /// -----------------------------------------------------------------------
                ///@notice Calculates the base assets in based on the pool type.
                ///@dev For FixedPricePools, this will additionally handle tier logic.
                function _calculateBaseAssetsIn(
                    address recipient,
                    uint256 tokenAmount,
                    uint256 maxPricePerShare
                )
                    internal
                    view
                    virtual
                    returns (uint256, TiersModified[] memory);
                ///@dev Normalizes the amount based on the pool type.
                ///@dev For FixedPricePools, this is the number of shares being purchased.
                ///@dev For OverflowPools, this is the number of assets being used to purchase.
                function _normalizeAmount(uint256 amount) internal pure virtual returns (uint256);
                ///@dev Checks if the raise cap has been met and if the pool can be closed early.
                function _raiseCapMet() internal view virtual returns (bool);
                ///@notice Validates the pool limits based on the pool type.
                ///@param amount The number of tokens being purchased/used to purchase based on the pool type.
                ///@dev For fixed price pools this checks total shares sold, for overflow pools this checks total assets in.
                function _validatePoolLimits(uint256 amount) internal view virtual;
                ///@notice Updates the user's normalized assets in the pool.
                ///@param recipient The address of the recipient of the purchase.
                ///@param tokenAmount The number of tokens being purchased/used to purchase based on the pool type.
                ///@dev Checks if the updated user amount exceeds the maximumTokensPerUser and reverts if so.
                function _validateUserLimits(address recipient, uint256 tokenAmount) internal view virtual;
                /// -----------------------------------------------------------------------
                /// BUY LOGIC -- OVERRIDE REQUIRED -- Internal -- Write Functions
                /// -----------------------------------------------------------------------
                ///@dev Emits the buy event for the pool based on the pool type's implementation.
                function _emitBuyEvent(
                    address recipient,
                    uint256 assetsIn,
                    uint256 feesPaid,
                    uint256 sharesOut
                )
                    internal
                    virtual;
                ///@dev Handles updating pool state and user state post-purchase.
                ///@dev Additionally handles the transfer of assets to the pool.
                ///@param recipient The address of the recipient of the purchase.
                ///@param assetsIn The number of assets being used to purchase based on the pool type.
                ///@param sharesOut The number of shares being purchased based on the pool type.
                ///@param fees The swap fees generated from the purchase.
                function _updatePoolState(
                    address recipient,
                    uint256 assetsIn,
                    uint256 sharesOut,
                    uint256 fees,
                    TiersModified[] memory updatedTiers
                )
                    internal
                    virtual
                    returns (uint256);
                /// -----------------------------------------------------------------------
                /// BUY LOGIC -- Public -- Read Functions
                /// -----------------------------------------------------------------------
                ///@notice Returns the minimum swap threshold required for a purchase to be valid.
                ///@dev This is used to prevent rounding errors when making swaps between tokens of varying decimals.
                function mandatoryMinimumSwapIn() public pure virtual returns (uint256) {
                    return shareDecimals().mandatoryMinimumSwapIn(assetDecimals());
                }
                ///@notice Calculates the swap fees and assets in based on the pool type and token amount being purchased/used to purchase.
                ///@param recipient The address of the recipient of the purchase.
                ///@param tokenAmount The number of tokens being purchased/used to purchase based on the pool type.
                ///@dev This function will account for tiers and all user-defined purchase limits, if applicable.
                function previewBuy(
                    uint256 tokenAmount,
                    address recipient
                )
                    public
                    view
                    returns (uint256 assetsIn, uint256 feesPaid, TiersModified[] memory updatedTiers)
                {
                    return previewBuy(tokenAmount, recipient, 0);
                }
                ///@notice Calculates the swap fees and assets in based on the pool type and token amount being purchased/used to purchase.
                ///@param recipient The address of the recipient of the purchase.
                ///@param tokenAmount The number of tokens being purchased/used to purchase based on the pool type.
                ///@dev This function will account for tiers and all user-defined purchase limits, if applicable.
                function previewBuy(
                    uint256 tokenAmount,
                    address recipient,
                    uint256 maxPricePerShare
                )
                    public
                    view
                    returns (uint256 assetsIn, uint256 feesPaid, TiersModified[] memory updatedTiers)
                {
                    //Normalize the token amount based on the pool type
                    tokenAmount = _normalizeAmount(tokenAmount);
                    //Zero-checks and min/max purchase amount checks
                    _validateBaseConditions(tokenAmount, recipient);
                    //Pool-type specific conditional checks
                    _validatePoolLimits(tokenAmount);
                    //Pool-type specific User-specific conditional checks
                    _validateUserLimits(recipient, tokenAmount);
                    (assetsIn, updatedTiers) = _calculateBaseAssetsIn(recipient, tokenAmount, maxPricePerShare);
                    feesPaid = _calculateFees(assetsIn);
                }
                /// -----------------------------------------------------------------------
                /// BUY LOGIC -- Internal -- Read Functions
                /// -----------------------------------------------------------------------
                /// @notice restrict access to whitelisted addresses.
                /// @dev  checks if the recipient address is whitelisted using a Merkle proof.
                function _validateWhitelist(address recipient, bytes32[] memory proof) internal pure {
                    if (!proof.verify(whitelistMerkleRoot(), keccak256(abi.encodePacked(recipient)))) {
                        revert InvalidProof();
                    }
                }
                ///@notice Verifies the signature of buy payload for anti-snipe protection.
                ///@param recipient The address of the recipient of the purchase.
                ///@param tokenAmount The number of tokens being purchased/used to purchase based on the pool type.
                ///@param deadline The deadline for the signature to be valid.
                ///@param signature The signature to be verified.
                ///@dev Recovers the signer of the payload and compares it to the delegate signer.
                function _validateAntisnipe(
                    address recipient,
                    uint256 tokenAmount,
                    uint64 deadline,
                    bytes memory signature
                )
                    internal
                    view
                {
                    if (uint64(block.timestamp) > deadline) {
                        revert StaleSignature();
                    }
                    bytes32 expectedDigest = getDigest(tokenAmount, recipient, deadline);
                    address signer = expectedDigest.recover(signature);
                    if (signer != delegateSigner()) {
                        revert InvalidSignature();
                    }
                }
                ///@notice Helper function to validate non-zero token amounts and recipient addresses and
                ///ensures minimum purchase amounts are upheld. Passes the signature and proof to the
                ///_checkWhitelistAndAntisnipe function.
                function _validateBaseConditions(uint256 tokenAmount, address recipient) internal pure {
                    if (tokenAmount == 0) revert TransferZero();
                    if (recipient == address(0)) revert ZeroAddress();
                    if (tokenAmount < mandatoryMinimumSwapIn()) revert MinPurchaseNotMet();
                }
                ///@notice Calculates the swap fees based on the swapFeeWAD and the token amount.
                function _calculateFees(uint256 assetsIn) internal pure returns (uint256) {
                    return assetsIn.mulWadUp(swapFeeWAD());
                }
                /// -----------------------------------------------------------------------
                /// BUY LOGIC -- Internal --  Write Functions
                /// -----------------------------------------------------------------------
                /// @notice Allows any user to purchase shares in the pool.
                /// @param amount The number of shares to purchase (Fixed) or assets in (Overflow).
                /// @param recipient The address to receive the shares.
                /// @param deadline The deadline for the signature to be valid if anti-snipe is enabled.
                /// @param signature The signature to be verified if anti-snipe is enabled.
                /// @param proof The Merkle proof to be verified if a whitelist is present.
                function buy(
                    uint256 amount,
                    address recipient,
                    uint64 deadline,
                    bytes memory signature,
                    bytes32[] memory proof,
                    uint256 maxPricePerShare
                )
                    internal
                    nonReentrant
                    whenSaleActive
                {
                    if (hasWhitelist()) {
                        _validateWhitelist(recipient, proof);
                    }
                    if (antiSnipeEnabled()) {
                        _validateAntisnipe(recipient, amount, deadline, signature);
                    }
                    (uint256 normalizedAssetsIn, uint256 normalizedFees, TiersModified[] memory updatedTiers) =
                        previewBuy(amount, recipient, maxPricePerShare);
                    uint256 sharesOut = poolType() == PoolType.Fixed ? amount.normalize(shareDecimals()) : 0;
                    uint256 normalizedAssetsOwed =
                        _updatePoolState(recipient, normalizedAssetsIn, sharesOut, normalizedFees, updatedTiers);
                    if (normalizedAssetsOwed > 0) {
                        assetToken().safeTransferFrom(
                            msg.sender, address(this), normalizedAssetsOwed.denormalizeUp(assetDecimals())
                        );
                    }
                    if (antiSnipeEnabled()) {
                        // increase nonce
                        nonces[recipient]++;
                    }
                    _emitBuyEvent(recipient, normalizedAssetsIn, normalizedFees, sharesOut);
                    //close early if the raise cap is met
                    _handleEarlyClose();
                }
                /// @notice Checks if the pool has met its raise cap
                /// and if so, emits the PoolCompleted event.
                function _handleEarlyClose() internal {
                    if (_raiseCapMet()) {
                        emit PoolCompleted();
                        close();
                    }
                }
                /// -----------------------------------------------------------------------
                /// CLOSE LOGIC -- OVERRIDE REQUIRED -- Internal -- Read Functions
                /// -----------------------------------------------------------------------
                ///@notice Calculates the leftover shares that were not sold during the sale.
                ///@dev If overflow, this is sharesForSale(), otherwise it's sharesForSale() - totalSharesSold.
                function _calculateLeftoverShares() internal view virtual returns (uint256);
                /// -----------------------------------------------------------------------
                /// CLOSE LOGIC -- OVERRIDE REQUIRED -- Internal -- Write Functions
                /// -----------------------------------------------------------------------
                /// @notice Handles the refund of the owner's shares in the pool and the transfer of swap fees to the fee recipient.
                /// @dev Only called if the raise goal was not met. The overriding function should handle the transfer of funds to the owner
                /// according to the pool type.
                function _handleManagerRefund()
                    internal
                    virtual
                    returns (uint256 sharesNotSold, uint256 fundsRaised, uint256 swapFees)
                {
                    sharesNotSold = sharesForSale().denormalizeDown(shareDecimals());
                    swapFees = totalNormalizedAssetFeesIn.denormalizeDown(assetDecimals());
                    if (swapFees > 0) {
                        assetToken().safeTransfer(feeRecipient(), swapFees);
                    }
                    fundsRaised = totalNormalizedAssetsIn.denormalizeUp(assetDecimals());
                    uint256 currentBalance = assetToken().balanceOf(address(this));
                    if (fundsRaised > currentBalance) {
                        // possible precision loss after denormalize
                        fundsRaised = currentBalance;
                    } else if (fundsRaised < currentBalance) {
                        // if someone donates assets to the pool, then take all back to owner
                        assetToken().safeTransfer(owner(), currentBalance - fundsRaised);
                    }
                }
                /// -----------------------------------------------------------------------
                /// CLOSE LOGIC -- Public -- Write Functions
                /// -----------------------------------------------------------------------
                // @notice Allows any user to close the pool and distribute the fees.
                // @dev The pool can only be closed after the sale end date has passed, OR the max shares sold have been reached.
                function close() public {
                    if (!canClose()) {
                        revert CloseConditionNotMet();
                    }
                    status = PoolStatus.Closed;
                    saleEndTimestamp =
                        uint256(saleEnd()) < block.timestamp ? uint256(saleEnd()) : block.timestamp;
                    if (!_minReserveMet()) {
                        (uint256 sharesNotSold, uint256 fundsRaised, uint256 swapFee) = _handleManagerRefund();
                        emit RaiseGoalNotMet(sharesNotSold, fundsRaised, swapFee);
                        return;
                    } else {
                        // avoid shawdow variable
                        (uint256 platformFees, uint256 swapFees, uint256 totalFees) = _calculateCloseFees();
                        if (totalFees > 0) {
                            assetToken().safeTransfer(feeRecipient(), totalFees);
                        }
                        uint256 fundsRaised = IERC20(assetToken()).balanceOf(address(this));
                        if (fundsRaised > 0) {
                            assetToken().safeTransfer(owner(), fundsRaised);
                        }
                        uint256 sharesNotSold = _calculateLeftoverShares();
                        // return the unsold shares to the owner
                        if (sharesNotSold > 0 && shareToken() != address(0)) {
                            shareToken().safeTransfer(owner(), sharesNotSold);
                        }
                        //totalsharessold, fundsraised
                        emit Closed(
                            fundsRaised,
                            sharesForSale().denormalizeDown(shareDecimals()).rawSub(sharesNotSold),
                            platformFees,
                            swapFees
                        );
                        if (vestingEnabled()) {
                            shareToken().safeApprove(address(SABLIER), type(uint256).max);
                        }
                    }
                }
                /// -----------------------------------------------------------------------
                /// CLOSE LOGIC -- Internal -- Read Functions
                /// -----------------------------------------------------------------------
                ///@dev Calculates the fees generated during the sale and denormalizes them for event emission and transfer.
                function _calculateCloseFees()
                    internal
                    view
                    returns (uint256 platformFees, uint256 swapFees, uint256 totalFees)
                {
                    platformFees = totalNormalizedAssetsIn.mulWad(platformFeeWAD());
                    // denormalize the fees for event emission.
                    swapFees = totalNormalizedAssetFeesIn.denormalizeDown(assetDecimals());
                    platformFees = platformFees.denormalizeDown(assetDecimals());
                    // totalFees sum of platformFees and swapFees
                    totalFees = platformFees + swapFees;
                }
                /// -----------------------------------------------------------------------
                /// REDEEM LOGIC -- OVERRIDE REQUIRED - Internal -- Read Functions
                /// -----------------------------------------------------------------------
                /// @notice Calculates the amount of shares owed to the user based on the pool type.
                /// @dev For FixedPricePools, this is the number of shares the user has purchased directly.
                /// @dev For OverflowPools, this is calculate as the ratio of the users assets to the total assets in the pool
                /// multiplied by the total shares for sale.
                function _calculateSharesOwed(address user) internal view virtual returns (uint256);
                /// -----------------------------------------------------------------------
                /// REDEEM LOGIC -- OVERRIDE REQUIRED - Internal -- Write Functions
                /// -----------------------------------------------------------------------
                /// @notice Handles the refund/transfer of the user's assets in the pool if the raise goal was not met
                /// and updates user-specific state variables.
                /// @dev For FixedPricePools, this sets the user's sharesPurchased and assetsIn to 0.
                /// @dev For OverflowPools, this sets the user's assetsIn to 0.
                function _handleUserRefund(address user) internal virtual returns (uint256 assetsOwed);
                /// @notice Handles the state updates triggered on user-specific variables of pool state post-redemption.
                /// @dev For FixedPricePools, this sets the user's sharesPurchased and assetsIn to 0.
                /// @dev For OverflowPools, this sets the user's assetsIn to 0.
                function _handleUpdateUserRedemption(address sender) internal virtual;
                /// -----------------------------------------------------------------------
                /// REDEEM LOGIC -- External -- Write Functions
                /// -----------------------------------------------------------------------
                // @notice Allows any user to redeem their shares after the redemption timestamp has passed.
                // @dev Users can only redeem their shares if the sale has closed and the redemption timestamp has passed.
                // unless the pool met a hard cap and closed early, at which point the redemption timestamp is
                function redeem() external nonReentrant returns (uint256 streamID) {
                    if (status == PoolStatus.Canceled) {
                        revert SaleCancelled();
                    }
                    if (status != PoolStatus.Closed) {
                        revert SaleActive();
                    }
                    if (block.timestamp < saleEndTimestamp + redemptionDelay()) {
                        revert RedeemedTooEarly();
                    }
                    uint256 sharesOut;
                    address sender = msg.sender;
                    if (!_minReserveMet()) {
                        emit Refunded(sender, _handleUserRefund(sender));
                    } else {
                        if (shareToken() != address(0)) {
                            sharesOut = _calculateSharesOwed(sender);
                            if (sharesOut == 0) {
                                revert NoSharesRedeemable();
                            }
                            _handleUpdateUserRedemption(sender);
                            streamID = _handleRedemptionPayment(sender, sharesOut);
                            emit Redeemed(sender, sharesOut, streamID);
                        } else {
                            revert TokenNotRedeemable();
                        }
                    }
                }
                /// -----------------------------------------------------------------------
                /// REDEEM LOGIC -- Internal -- Write Functions
                /// -----------------------------------------------------------------------
                ///@notice Handles the transfer of shares to the user post-redemption.
                ///@param recipient The address of the recipient of the shares.
                ///@param sharesOwed The number of shares owed to the user.
                ///@dev Only utilized if the raise goal was met.
                ///@dev If vesting is enabled and not expired, the shares are streamed to the user via sablier.
                function _handleRedemptionPayment(
                    address recipient,
                    uint256 sharesOwed
                )
                    internal
                    returns (uint256 streamID)
                {
                    if (vestingEnabled() && vestEnd() > uint40(block.timestamp)) {
                        LockupLinear.CreateWithRange memory params;
                        params.sender = owner();
                        params.recipient = recipient;
                        params.totalAmount = uint128(sharesOwed);
                        params.asset = IERC20(shareToken());
                        params.cancelable = false;
                        params.range =
                            LockupLinear.Range({ start: saleEnd(), end: vestEnd(), cliff: vestCliff() });
                        params.broker = Broker(address(0), ud60x18(0));
                        streamID = SABLIER.createWithRange(params);
                    } else {
                        shareToken().safeTransfer(recipient, sharesOwed);
                    }
                }
                /// -----------------------------------------------------------------------
                /// POOL ADMIN LOGIC -- External -- Owner-Only -- Write Functions
                /// -----------------------------------------------------------------------
                /// @notice Allows the pool creator to cancel the sale and withdraw all funds and shares before a sale begins.
                /// @dev The pool can only be canceled if the sale has not started.
                function cancelSale() external nonReentrant onlyOwner {
                    if (status != PoolStatus.Active && status != PoolStatus.Paused) {
                        revert SaleNotCancelable();
                    }
                    if (uint40(block.timestamp) >= saleStart()) {
                        revert SaleActive();
                    }
                    status = PoolStatus.Canceled;
                    if (shareToken() != address(0)) {
                        shareToken().safeTransfer(owner(), sharesForSale().denormalizeDown(shareDecimals()));
                    }
                    emit PoolCanceled();
                }
                /// @notice Allows the pool creator to pause/unpause the sale, halting/enabling any trading activity.
                function togglePause() external nonReentrant onlyOwner {
                    if (status == PoolStatus.Canceled || status == PoolStatus.Closed) {
                        revert SaleNotPausable();
                    }
                    bool paused = status == PoolStatus.Paused;
                    status = paused ? PoolStatus.Active : PoolStatus.Paused;
                    emit PauseToggled(!paused);
                }
                /// -----------------------------------------------------------------------
                /// EIP712 Logic  -- External -- Read Functions
                /// -----------------------------------------------------------------------
                /// @notice Returns the expected digest for the EIP712 signature.
                /// @param tokenAmount The number of tokens being purchased/used to purchase based on the pool type.
                /// @param recipient The address of the recipient of the purchase.
                /// @param deadline The deadline for the signature to be valid.
                function getDigest(
                    uint256 tokenAmount,
                    address recipient,
                    uint64 deadline
                )
                    public
                    view
                    returns (bytes32)
                {
                    return _hashTypedData(
                        keccak256(
                            abi.encode(typeHash(), tokenAmount, recipient, nonces[recipient] + 1, deadline)
                        )
                    );
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.4;
            /// @notice Safe integer casting library that reverts on overflow.
            /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeCastLib.sol)
            /// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/SafeCast.sol)
            library SafeCastLib {
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                       CUSTOM ERRORS                        */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                error Overflow();
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*          UNSIGNED INTEGER SAFE CASTING OPERATIONS          */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                function toUint8(uint256 x) internal pure returns (uint8) {
                    if (x >= 1 << 8) _revertOverflow();
                    return uint8(x);
                }
                function toUint16(uint256 x) internal pure returns (uint16) {
                    if (x >= 1 << 16) _revertOverflow();
                    return uint16(x);
                }
                function toUint24(uint256 x) internal pure returns (uint24) {
                    if (x >= 1 << 24) _revertOverflow();
                    return uint24(x);
                }
                function toUint32(uint256 x) internal pure returns (uint32) {
                    if (x >= 1 << 32) _revertOverflow();
                    return uint32(x);
                }
                function toUint40(uint256 x) internal pure returns (uint40) {
                    if (x >= 1 << 40) _revertOverflow();
                    return uint40(x);
                }
                function toUint48(uint256 x) internal pure returns (uint48) {
                    if (x >= 1 << 48) _revertOverflow();
                    return uint48(x);
                }
                function toUint56(uint256 x) internal pure returns (uint56) {
                    if (x >= 1 << 56) _revertOverflow();
                    return uint56(x);
                }
                function toUint64(uint256 x) internal pure returns (uint64) {
                    if (x >= 1 << 64) _revertOverflow();
                    return uint64(x);
                }
                function toUint72(uint256 x) internal pure returns (uint72) {
                    if (x >= 1 << 72) _revertOverflow();
                    return uint72(x);
                }
                function toUint80(uint256 x) internal pure returns (uint80) {
                    if (x >= 1 << 80) _revertOverflow();
                    return uint80(x);
                }
                function toUint88(uint256 x) internal pure returns (uint88) {
                    if (x >= 1 << 88) _revertOverflow();
                    return uint88(x);
                }
                function toUint96(uint256 x) internal pure returns (uint96) {
                    if (x >= 1 << 96) _revertOverflow();
                    return uint96(x);
                }
                function toUint104(uint256 x) internal pure returns (uint104) {
                    if (x >= 1 << 104) _revertOverflow();
                    return uint104(x);
                }
                function toUint112(uint256 x) internal pure returns (uint112) {
                    if (x >= 1 << 112) _revertOverflow();
                    return uint112(x);
                }
                function toUint120(uint256 x) internal pure returns (uint120) {
                    if (x >= 1 << 120) _revertOverflow();
                    return uint120(x);
                }
                function toUint128(uint256 x) internal pure returns (uint128) {
                    if (x >= 1 << 128) _revertOverflow();
                    return uint128(x);
                }
                function toUint136(uint256 x) internal pure returns (uint136) {
                    if (x >= 1 << 136) _revertOverflow();
                    return uint136(x);
                }
                function toUint144(uint256 x) internal pure returns (uint144) {
                    if (x >= 1 << 144) _revertOverflow();
                    return uint144(x);
                }
                function toUint152(uint256 x) internal pure returns (uint152) {
                    if (x >= 1 << 152) _revertOverflow();
                    return uint152(x);
                }
                function toUint160(uint256 x) internal pure returns (uint160) {
                    if (x >= 1 << 160) _revertOverflow();
                    return uint160(x);
                }
                function toUint168(uint256 x) internal pure returns (uint168) {
                    if (x >= 1 << 168) _revertOverflow();
                    return uint168(x);
                }
                function toUint176(uint256 x) internal pure returns (uint176) {
                    if (x >= 1 << 176) _revertOverflow();
                    return uint176(x);
                }
                function toUint184(uint256 x) internal pure returns (uint184) {
                    if (x >= 1 << 184) _revertOverflow();
                    return uint184(x);
                }
                function toUint192(uint256 x) internal pure returns (uint192) {
                    if (x >= 1 << 192) _revertOverflow();
                    return uint192(x);
                }
                function toUint200(uint256 x) internal pure returns (uint200) {
                    if (x >= 1 << 200) _revertOverflow();
                    return uint200(x);
                }
                function toUint208(uint256 x) internal pure returns (uint208) {
                    if (x >= 1 << 208) _revertOverflow();
                    return uint208(x);
                }
                function toUint216(uint256 x) internal pure returns (uint216) {
                    if (x >= 1 << 216) _revertOverflow();
                    return uint216(x);
                }
                function toUint224(uint256 x) internal pure returns (uint224) {
                    if (x >= 1 << 224) _revertOverflow();
                    return uint224(x);
                }
                function toUint232(uint256 x) internal pure returns (uint232) {
                    if (x >= 1 << 232) _revertOverflow();
                    return uint232(x);
                }
                function toUint240(uint256 x) internal pure returns (uint240) {
                    if (x >= 1 << 240) _revertOverflow();
                    return uint240(x);
                }
                function toUint248(uint256 x) internal pure returns (uint248) {
                    if (x >= 1 << 248) _revertOverflow();
                    return uint248(x);
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*           SIGNED INTEGER SAFE CASTING OPERATIONS           */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                function toInt8(int256 x) internal pure returns (int8) {
                    int8 y = int8(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt16(int256 x) internal pure returns (int16) {
                    int16 y = int16(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt24(int256 x) internal pure returns (int24) {
                    int24 y = int24(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt32(int256 x) internal pure returns (int32) {
                    int32 y = int32(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt40(int256 x) internal pure returns (int40) {
                    int40 y = int40(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt48(int256 x) internal pure returns (int48) {
                    int48 y = int48(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt56(int256 x) internal pure returns (int56) {
                    int56 y = int56(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt64(int256 x) internal pure returns (int64) {
                    int64 y = int64(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt72(int256 x) internal pure returns (int72) {
                    int72 y = int72(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt80(int256 x) internal pure returns (int80) {
                    int80 y = int80(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt88(int256 x) internal pure returns (int88) {
                    int88 y = int88(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt96(int256 x) internal pure returns (int96) {
                    int96 y = int96(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt104(int256 x) internal pure returns (int104) {
                    int104 y = int104(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt112(int256 x) internal pure returns (int112) {
                    int112 y = int112(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt120(int256 x) internal pure returns (int120) {
                    int120 y = int120(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt128(int256 x) internal pure returns (int128) {
                    int128 y = int128(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt136(int256 x) internal pure returns (int136) {
                    int136 y = int136(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt144(int256 x) internal pure returns (int144) {
                    int144 y = int144(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt152(int256 x) internal pure returns (int152) {
                    int152 y = int152(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt160(int256 x) internal pure returns (int160) {
                    int160 y = int160(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt168(int256 x) internal pure returns (int168) {
                    int168 y = int168(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt176(int256 x) internal pure returns (int176) {
                    int176 y = int176(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt184(int256 x) internal pure returns (int184) {
                    int184 y = int184(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt192(int256 x) internal pure returns (int192) {
                    int192 y = int192(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt200(int256 x) internal pure returns (int200) {
                    int200 y = int200(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt208(int256 x) internal pure returns (int208) {
                    int208 y = int208(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt216(int256 x) internal pure returns (int216) {
                    int216 y = int216(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt224(int256 x) internal pure returns (int224) {
                    int224 y = int224(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt232(int256 x) internal pure returns (int232) {
                    int232 y = int232(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt240(int256 x) internal pure returns (int240) {
                    int240 y = int240(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                function toInt248(int256 x) internal pure returns (int248) {
                    int248 y = int248(x);
                    if (x != y) _revertOverflow();
                    return y;
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*               OTHER SAFE CASTING OPERATIONS                */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                function toInt256(uint256 x) internal pure returns (int256) {
                    if (x >= 1 << 255) _revertOverflow();
                    return int256(x);
                }
                function toUint256(int256 x) internal pure returns (uint256) {
                    if (x < 0) _revertOverflow();
                    return uint256(x);
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                      PRIVATE HELPERS                       */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                function _revertOverflow() private pure {
                    /// @solidity memory-safe-assembly
                    assembly {
                        // Store the function selector of `Overflow()`.
                        mstore(0x00, 0x35278d12)
                        // Revert with (offset, size).
                        revert(0x1c, 0x04)
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.4;
            /// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
            /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeTransferLib.sol)
            /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)
            ///
            /// @dev Note:
            /// - For ETH transfers, please use `forceSafeTransferETH` for DoS protection.
            /// - For ERC20s, this implementation won't check that a token has code,
            ///   responsibility is delegated to the caller.
            library SafeTransferLib {
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                       CUSTOM ERRORS                        */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev The ETH transfer has failed.
                error ETHTransferFailed();
                /// @dev The ERC20 `transferFrom` has failed.
                error TransferFromFailed();
                /// @dev The ERC20 `transfer` has failed.
                error TransferFailed();
                /// @dev The ERC20 `approve` has failed.
                error ApproveFailed();
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                         CONSTANTS                          */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Suggested gas stipend for contract receiving ETH that disallows any storage writes.
                uint256 internal constant GAS_STIPEND_NO_STORAGE_WRITES = 2300;
                /// @dev Suggested gas stipend for contract receiving ETH to perform a few
                /// storage reads and writes, but low enough to prevent griefing.
                uint256 internal constant GAS_STIPEND_NO_GRIEF = 100000;
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                       ETH OPERATIONS                       */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                // If the ETH transfer MUST succeed with a reasonable gas budget, use the force variants.
                //
                // The regular variants:
                // - Forwards all remaining gas to the target.
                // - Reverts if the target reverts.
                // - Reverts if the current contract has insufficient balance.
                //
                // The force variants:
                // - Forwards with an optional gas stipend
                //   (defaults to `GAS_STIPEND_NO_GRIEF`, which is sufficient for most cases).
                // - If the target reverts, or if the gas stipend is exhausted,
                //   creates a temporary contract to force send the ETH via `SELFDESTRUCT`.
                //   Future compatible with `SENDALL`: https://eips.ethereum.org/EIPS/eip-4758.
                // - Reverts if the current contract has insufficient balance.
                //
                // The try variants:
                // - Forwards with a mandatory gas stipend.
                // - Instead of reverting, returns whether the transfer succeeded.
                /// @dev Sends `amount` (in wei) ETH to `to`.
                function safeTransferETH(address to, uint256 amount) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if iszero(call(gas(), to, amount, codesize(), 0x00, codesize(), 0x00)) {
                            mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
                            revert(0x1c, 0x04)
                        }
                    }
                }
                /// @dev Sends all the ETH in the current contract to `to`.
                function safeTransferAllETH(address to) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        // Transfer all the ETH and check if it succeeded or not.
                        if iszero(call(gas(), to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {
                            mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
                            revert(0x1c, 0x04)
                        }
                    }
                }
                /// @dev Force sends `amount` (in wei) ETH to `to`, with a `gasStipend`.
                function forceSafeTransferETH(address to, uint256 amount, uint256 gasStipend) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if lt(selfbalance(), amount) {
                            mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
                            revert(0x1c, 0x04)
                        }
                        if iszero(call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)) {
                            mstore(0x00, to) // Store the address in scratch space.
                            mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                            mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                            if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
                        }
                    }
                }
                /// @dev Force sends all the ETH in the current contract to `to`, with a `gasStipend`.
                function forceSafeTransferAllETH(address to, uint256 gasStipend) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if iszero(call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {
                            mstore(0x00, to) // Store the address in scratch space.
                            mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                            mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                            if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
                        }
                    }
                }
                /// @dev Force sends `amount` (in wei) ETH to `to`, with `GAS_STIPEND_NO_GRIEF`.
                function forceSafeTransferETH(address to, uint256 amount) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if lt(selfbalance(), amount) {
                            mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
                            revert(0x1c, 0x04)
                        }
                        if iszero(call(GAS_STIPEND_NO_GRIEF, to, amount, codesize(), 0x00, codesize(), 0x00)) {
                            mstore(0x00, to) // Store the address in scratch space.
                            mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                            mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                            if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
                        }
                    }
                }
                /// @dev Force sends all the ETH in the current contract to `to`, with `GAS_STIPEND_NO_GRIEF`.
                function forceSafeTransferAllETH(address to) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        // forgefmt: disable-next-item
                        if iszero(call(GAS_STIPEND_NO_GRIEF, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {
                            mstore(0x00, to) // Store the address in scratch space.
                            mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                            mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                            if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
                        }
                    }
                }
                /// @dev Sends `amount` (in wei) ETH to `to`, with a `gasStipend`.
                function trySafeTransferETH(address to, uint256 amount, uint256 gasStipend)
                    internal
                    returns (bool success)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        success := call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)
                    }
                }
                /// @dev Sends all the ETH in the current contract to `to`, with a `gasStipend`.
                function trySafeTransferAllETH(address to, uint256 gasStipend)
                    internal
                    returns (bool success)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        success := call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)
                    }
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                      ERC20 OPERATIONS                      */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Sends `amount` of ERC20 `token` from `from` to `to`.
                /// Reverts upon failure.
                ///
                /// The `from` account must have at least `amount` approved for
                /// the current contract to manage.
                function safeTransferFrom(address token, address from, address to, uint256 amount) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        let m := mload(0x40) // Cache the free memory pointer.
                        mstore(0x60, amount) // Store the `amount` argument.
                        mstore(0x40, to) // Store the `to` argument.
                        mstore(0x2c, shl(96, from)) // Store the `from` argument.
                        mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`.
                        // Perform the transfer, reverting upon failure.
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                                call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
                            )
                        ) {
                            mstore(0x00, 0x7939f424) // `TransferFromFailed()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x60, 0) // Restore the zero slot to zero.
                        mstore(0x40, m) // Restore the free memory pointer.
                    }
                }
                /// @dev Sends all of ERC20 `token` from `from` to `to`.
                /// Reverts upon failure.
                ///
                /// The `from` account must have their entire balance approved for
                /// the current contract to manage.
                function safeTransferAllFrom(address token, address from, address to)
                    internal
                    returns (uint256 amount)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        let m := mload(0x40) // Cache the free memory pointer.
                        mstore(0x40, to) // Store the `to` argument.
                        mstore(0x2c, shl(96, from)) // Store the `from` argument.
                        mstore(0x0c, 0x70a08231000000000000000000000000) // `balanceOf(address)`.
                        // Read the balance, reverting upon failure.
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                gt(returndatasize(), 0x1f), // At least 32 bytes returned.
                                staticcall(gas(), token, 0x1c, 0x24, 0x60, 0x20)
                            )
                        ) {
                            mstore(0x00, 0x7939f424) // `TransferFromFailed()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x00, 0x23b872dd) // `transferFrom(address,address,uint256)`.
                        amount := mload(0x60) // The `amount` is already at 0x60. We'll need to return it.
                        // Perform the transfer, reverting upon failure.
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                                call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
                            )
                        ) {
                            mstore(0x00, 0x7939f424) // `TransferFromFailed()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x60, 0) // Restore the zero slot to zero.
                        mstore(0x40, m) // Restore the free memory pointer.
                    }
                }
                /// @dev Sends `amount` of ERC20 `token` from the current contract to `to`.
                /// Reverts upon failure.
                function safeTransfer(address token, address to, uint256 amount) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        mstore(0x14, to) // Store the `to` argument.
                        mstore(0x34, amount) // Store the `amount` argument.
                        mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.
                        // Perform the transfer, reverting upon failure.
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                                call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
                            )
                        ) {
                            mstore(0x00, 0x90b8ec18) // `TransferFailed()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
                    }
                }
                /// @dev Sends all of ERC20 `token` from the current contract to `to`.
                /// Reverts upon failure.
                function safeTransferAll(address token, address to) internal returns (uint256 amount) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        mstore(0x00, 0x70a08231) // Store the function selector of `balanceOf(address)`.
                        mstore(0x20, address()) // Store the address of the current contract.
                        // Read the balance, reverting upon failure.
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                gt(returndatasize(), 0x1f), // At least 32 bytes returned.
                                staticcall(gas(), token, 0x1c, 0x24, 0x34, 0x20)
                            )
                        ) {
                            mstore(0x00, 0x90b8ec18) // `TransferFailed()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x14, to) // Store the `to` argument.
                        amount := mload(0x34) // The `amount` is already at 0x34. We'll need to return it.
                        mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.
                        // Perform the transfer, reverting upon failure.
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                                call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
                            )
                        ) {
                            mstore(0x00, 0x90b8ec18) // `TransferFailed()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
                    }
                }
                /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract.
                /// Reverts upon failure.
                function safeApprove(address token, address to, uint256 amount) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        mstore(0x14, to) // Store the `to` argument.
                        mstore(0x34, amount) // Store the `amount` argument.
                        mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.
                        // Perform the approval, reverting upon failure.
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                                call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
                            )
                        ) {
                            mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
                    }
                }
                /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract.
                /// If the initial attempt to approve fails, attempts to reset the approved amount to zero,
                /// then retries the approval again (some tokens, e.g. USDT, requires this).
                /// Reverts upon failure.
                function safeApproveWithRetry(address token, address to, uint256 amount) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        mstore(0x14, to) // Store the `to` argument.
                        mstore(0x34, amount) // Store the `amount` argument.
                        mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.
                        // Perform the approval, retrying upon failure.
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                                call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
                            )
                        ) {
                            mstore(0x34, 0) // Store 0 for the `amount`.
                            mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.
                            pop(call(gas(), token, 0, 0x10, 0x44, codesize(), 0x00)) // Reset the approval.
                            mstore(0x34, amount) // Store back the original `amount`.
                            // Retry the approval, reverting upon failure.
                            if iszero(
                                and(
                                    or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                                    call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
                                )
                            ) {
                                mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`.
                                revert(0x1c, 0x04)
                            }
                        }
                        mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
                    }
                }
                /// @dev Returns the amount of ERC20 `token` owned by `account`.
                /// Returns zero if the `token` does not exist.
                function balanceOf(address token, address account) internal view returns (uint256 amount) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        mstore(0x14, account) // Store the `account` argument.
                        mstore(0x00, 0x70a08231000000000000000000000000) // `balanceOf(address)`.
                        amount :=
                            mul(
                                mload(0x20),
                                and( // The arguments of `and` are evaluated from right to left.
                                    gt(returndatasize(), 0x1f), // At least 32 bytes returned.
                                    staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20)
                                )
                            )
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.4;
            /// @notice Arithmetic library with operations for fixed-point numbers.
            /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/FixedPointMathLib.sol)
            /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol)
            library FixedPointMathLib {
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                       CUSTOM ERRORS                        */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev The operation failed, as the output exceeds the maximum value of uint256.
                error ExpOverflow();
                /// @dev The operation failed, as the output exceeds the maximum value of uint256.
                error FactorialOverflow();
                /// @dev The operation failed, due to an overflow.
                error RPowOverflow();
                /// @dev The mantissa is too big to fit.
                error MantissaOverflow();
                /// @dev The operation failed, due to an multiplication overflow.
                error MulWadFailed();
                /// @dev The operation failed, due to an multiplication overflow.
                error SMulWadFailed();
                /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.
                error DivWadFailed();
                /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.
                error SDivWadFailed();
                /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.
                error MulDivFailed();
                /// @dev The division failed, as the denominator is zero.
                error DivFailed();
                /// @dev The full precision multiply-divide operation failed, either due
                /// to the result being larger than 256 bits, or a division by a zero.
                error FullMulDivFailed();
                /// @dev The output is undefined, as the input is less-than-or-equal to zero.
                error LnWadUndefined();
                /// @dev The input outside the acceptable domain.
                error OutOfDomain();
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                         CONSTANTS                          */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev The scalar of ETH and most ERC20s.
                uint256 internal constant WAD = 1e18;
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*              SIMPLIFIED FIXED POINT OPERATIONS             */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Equivalent to `(x * y) / WAD` rounded down.
                function mulWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        // Equivalent to `require(y == 0 || x <= type(uint256).max / y)`.
                        if mul(y, gt(x, div(not(0), y))) {
                            mstore(0x00, 0xbac65e5b) // `MulWadFailed()`.
                            revert(0x1c, 0x04)
                        }
                        z := div(mul(x, y), WAD)
                    }
                }
                /// @dev Equivalent to `(x * y) / WAD` rounded down.
                function sMulWad(int256 x, int256 y) internal pure returns (int256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := mul(x, y)
                        // Equivalent to `require((x == 0 || z / x == y) && !(x == -1 && y == type(int256).min))`.
                        if iszero(gt(or(iszero(x), eq(sdiv(z, x), y)), lt(not(x), eq(y, shl(255, 1))))) {
                            mstore(0x00, 0xedcd4dd4) // `SMulWadFailed()`.
                            revert(0x1c, 0x04)
                        }
                        z := sdiv(z, WAD)
                    }
                }
                /// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks.
                function rawMulWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := div(mul(x, y), WAD)
                    }
                }
                /// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks.
                function rawSMulWad(int256 x, int256 y) internal pure returns (int256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := sdiv(mul(x, y), WAD)
                    }
                }
                /// @dev Equivalent to `(x * y) / WAD` rounded up.
                function mulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        // Equivalent to `require(y == 0 || x <= type(uint256).max / y)`.
                        if mul(y, gt(x, div(not(0), y))) {
                            mstore(0x00, 0xbac65e5b) // `MulWadFailed()`.
                            revert(0x1c, 0x04)
                        }
                        z := add(iszero(iszero(mod(mul(x, y), WAD))), div(mul(x, y), WAD))
                    }
                }
                /// @dev Equivalent to `(x * y) / WAD` rounded up, but without overflow checks.
                function rawMulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := add(iszero(iszero(mod(mul(x, y), WAD))), div(mul(x, y), WAD))
                    }
                }
                /// @dev Equivalent to `(x * WAD) / y` rounded down.
                function divWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        // Equivalent to `require(y != 0 && (WAD == 0 || x <= type(uint256).max / WAD))`.
                        if iszero(mul(y, iszero(mul(WAD, gt(x, div(not(0), WAD)))))) {
                            mstore(0x00, 0x7c5f487d) // `DivWadFailed()`.
                            revert(0x1c, 0x04)
                        }
                        z := div(mul(x, WAD), y)
                    }
                }
                /// @dev Equivalent to `(x * WAD) / y` rounded down.
                function sDivWad(int256 x, int256 y) internal pure returns (int256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := mul(x, WAD)
                        // Equivalent to `require(y != 0 && ((x * WAD) / WAD == x))`.
                        if iszero(and(iszero(iszero(y)), eq(sdiv(z, WAD), x))) {
                            mstore(0x00, 0x5c43740d) // `SDivWadFailed()`.
                            revert(0x1c, 0x04)
                        }
                        z := sdiv(mul(x, WAD), y)
                    }
                }
                /// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks.
                function rawDivWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := div(mul(x, WAD), y)
                    }
                }
                /// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks.
                function rawSDivWad(int256 x, int256 y) internal pure returns (int256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := sdiv(mul(x, WAD), y)
                    }
                }
                /// @dev Equivalent to `(x * WAD) / y` rounded up.
                function divWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        // Equivalent to `require(y != 0 && (WAD == 0 || x <= type(uint256).max / WAD))`.
                        if iszero(mul(y, iszero(mul(WAD, gt(x, div(not(0), WAD)))))) {
                            mstore(0x00, 0x7c5f487d) // `DivWadFailed()`.
                            revert(0x1c, 0x04)
                        }
                        z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y))
                    }
                }
                /// @dev Equivalent to `(x * WAD) / y` rounded up, but without overflow and divide by zero checks.
                function rawDivWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y))
                    }
                }
                /// @dev Equivalent to `x` to the power of `y`.
                /// because `x ** y = (e ** ln(x)) ** y = e ** (ln(x) * y)`.
                function powWad(int256 x, int256 y) internal pure returns (int256) {
                    // Using `ln(x)` means `x` must be greater than 0.
                    return expWad((lnWad(x) * y) / int256(WAD));
                }
                /// @dev Returns `exp(x)`, denominated in `WAD`.
                /// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln
                function expWad(int256 x) internal pure returns (int256 r) {
                    unchecked {
                        // When the result is less than 0.5 we return zero.
                        // This happens when `x <= (log(1e-18) * 1e18) ~ -4.15e19`.
                        if (x <= -41446531673892822313) return r;
                        /// @solidity memory-safe-assembly
                        assembly {
                            // When the result is greater than `(2**255 - 1) / 1e18` we can not represent it as
                            // an int. This happens when `x >= floor(log((2**255 - 1) / 1e18) * 1e18) ≈ 135`.
                            if iszero(slt(x, 135305999368893231589)) {
                                mstore(0x00, 0xa37bfec9) // `ExpOverflow()`.
                                revert(0x1c, 0x04)
                            }
                        }
                        // `x` is now in the range `(-42, 136) * 1e18`. Convert to `(-42, 136) * 2**96`
                        // for more intermediate precision and a binary basis. This base conversion
                        // is a multiplication by 1e18 / 2**96 = 5**18 / 2**78.
                        x = (x << 78) / 5 ** 18;
                        // Reduce range of x to (-½ ln 2, ½ ln 2) * 2**96 by factoring out powers
                        // of two such that exp(x) = exp(x') * 2**k, where k is an integer.
                        // Solving this gives k = round(x / log(2)) and x' = x - k * log(2).
                        int256 k = ((x << 96) / 54916777467707473351141471128 + 2 ** 95) >> 96;
                        x = x - k * 54916777467707473351141471128;
                        // `k` is in the range `[-61, 195]`.
                        // Evaluate using a (6, 7)-term rational approximation.
                        // `p` is made monic, we'll multiply by a scale factor later.
                        int256 y = x + 1346386616545796478920950773328;
                        y = ((y * x) >> 96) + 57155421227552351082224309758442;
                        int256 p = y + x - 94201549194550492254356042504812;
                        p = ((p * y) >> 96) + 28719021644029726153956944680412240;
                        p = p * x + (4385272521454847904659076985693276 << 96);
                        // We leave `p` in `2**192` basis so we don't need to scale it back up for the division.
                        int256 q = x - 2855989394907223263936484059900;
                        q = ((q * x) >> 96) + 50020603652535783019961831881945;
                        q = ((q * x) >> 96) - 533845033583426703283633433725380;
                        q = ((q * x) >> 96) + 3604857256930695427073651918091429;
                        q = ((q * x) >> 96) - 14423608567350463180887372962807573;
                        q = ((q * x) >> 96) + 26449188498355588339934803723976023;
                        /// @solidity memory-safe-assembly
                        assembly {
                            // Div in assembly because solidity adds a zero check despite the unchecked.
                            // The q polynomial won't have zeros in the domain as all its roots are complex.
                            // No scaling is necessary because p is already `2**96` too large.
                            r := sdiv(p, q)
                        }
                        // r should be in the range `(0.09, 0.25) * 2**96`.
                        // We now need to multiply r by:
                        // - The scale factor `s ≈ 6.031367120`.
                        // - The `2**k` factor from the range reduction.
                        // - The `1e18 / 2**96` factor for base conversion.
                        // We do this all at once, with an intermediate result in `2**213`
                        // basis, so the final right shift is always by a positive amount.
                        r = int256(
                            (uint256(r) * 3822833074963236453042738258902158003155416615667) >> uint256(195 - k)
                        );
                    }
                }
                /// @dev Returns `ln(x)`, denominated in `WAD`.
                /// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln
                function lnWad(int256 x) internal pure returns (int256 r) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        // We want to convert `x` from `10**18` fixed point to `2**96` fixed point.
                        // We do this by multiplying by `2**96 / 10**18`. But since
                        // `ln(x * C) = ln(x) + ln(C)`, we can simply do nothing here
                        // and add `ln(2**96 / 10**18)` at the end.
                        // Compute `k = log2(x) - 96`, `r = 159 - k = 255 - log2(x) = 255 ^ log2(x)`.
                        r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
                        r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
                        r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
                        r := or(r, shl(4, lt(0xffff, shr(r, x))))
                        r := or(r, shl(3, lt(0xff, shr(r, x))))
                        // We place the check here for more optimal stack operations.
                        if iszero(sgt(x, 0)) {
                            mstore(0x00, 0x1615e638) // `LnWadUndefined()`.
                            revert(0x1c, 0x04)
                        }
                        // forgefmt: disable-next-item
                        r := xor(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),
                            0xf8f9f9faf9fdfafbf9fdfcfdfafbfcfef9fafdfafcfcfbfefafafcfbffffffff))
                        // Reduce range of x to (1, 2) * 2**96
                        // ln(2^k * x) = k * ln(2) + ln(x)
                        x := shr(159, shl(r, x))
                        // Evaluate using a (8, 8)-term rational approximation.
                        // `p` is made monic, we will multiply by a scale factor later.
                        // forgefmt: disable-next-item
                        let p := sub( // This heavily nested expression is to avoid stack-too-deep for via-ir.
                            sar(96, mul(add(43456485725739037958740375743393,
                            sar(96, mul(add(24828157081833163892658089445524,
                            sar(96, mul(add(3273285459638523848632254066296,
                                x), x))), x))), x)), 11111509109440967052023855526967)
                        p := sub(sar(96, mul(p, x)), 45023709667254063763336534515857)
                        p := sub(sar(96, mul(p, x)), 14706773417378608786704636184526)
                        p := sub(mul(p, x), shl(96, 795164235651350426258249787498))
                        // We leave `p` in `2**192` basis so we don't need to scale it back up for the division.
                        // `q` is monic by convention.
                        let q := add(5573035233440673466300451813936, x)
                        q := add(71694874799317883764090561454958, sar(96, mul(x, q)))
                        q := add(283447036172924575727196451306956, sar(96, mul(x, q)))
                        q := add(401686690394027663651624208769553, sar(96, mul(x, q)))
                        q := add(204048457590392012362485061816622, sar(96, mul(x, q)))
                        q := add(31853899698501571402653359427138, sar(96, mul(x, q)))
                        q := add(909429971244387300277376558375, sar(96, mul(x, q)))
                        // `p / q` is in the range `(0, 0.125) * 2**96`.
                        // Finalization, we need to:
                        // - Multiply by the scale factor `s = 5.549…`.
                        // - Add `ln(2**96 / 10**18)`.
                        // - Add `k * ln(2)`.
                        // - Multiply by `10**18 / 2**96 = 5**18 >> 78`.
                        // The q polynomial is known not to have zeros in the domain.
                        // No scaling required because p is already `2**96` too large.
                        p := sdiv(p, q)
                        // Multiply by the scaling factor: `s * 5**18 * 2**96`, base is now `5**18 * 2**192`.
                        p := mul(1677202110996718588342820967067443963516166, p)
                        // Add `ln(2) * k * 5**18 * 2**192`.
                        // forgefmt: disable-next-item
                        p := add(mul(16597577552685614221487285958193947469193820559219878177908093499208371, sub(159, r)), p)
                        // Add `ln(2**96 / 10**18) * 5**18 * 2**192`.
                        p := add(600920179829731861736702779321621459595472258049074101567377883020018308, p)
                        // Base conversion: mul `2**18 / 2**192`.
                        r := sar(174, p)
                    }
                }
                /// @dev Returns `W_0(x)`, denominated in `WAD`.
                /// See: https://en.wikipedia.org/wiki/Lambert_W_function
                /// a.k.a. Product log function. This is an approximation of the principal branch.
                function lambertW0Wad(int256 x) internal pure returns (int256 w) {
                    // forgefmt: disable-next-item
                    unchecked {
                        if ((w = x) <= -367879441171442322) revert OutOfDomain(); // `x` less than `-1/e`.
                        int256 wad = int256(WAD);
                        int256 p = x;
                        uint256 c; // Whether we need to avoid catastrophic cancellation.
                        uint256 i = 4; // Number of iterations.
                        if (w <= 0x1ffffffffffff) {
                            if (-0x4000000000000 <= w) {
                                i = 1; // Inputs near zero only take one step to converge.
                            } else if (w <= -0x3ffffffffffffff) {
                                i = 32; // Inputs near `-1/e` take very long to converge.
                            }
                        } else if (w >> 63 == 0) {
                            /// @solidity memory-safe-assembly
                            assembly {
                                // Inline log2 for more performance, since the range is small.
                                let v := shr(49, w)
                                let l := shl(3, lt(0xff, v))
                                l := add(or(l, byte(and(0x1f, shr(shr(l, v), 0x8421084210842108cc6318c6db6d54be)),
                                    0x0706060506020504060203020504030106050205030304010505030400000000)), 49)
                                w := sdiv(shl(l, 7), byte(sub(l, 31), 0x0303030303030303040506080c13))
                                c := gt(l, 60)
                                i := add(2, add(gt(l, 53), c))
                            }
                        } else {
                            int256 ll = lnWad(w = lnWad(w));
                            /// @solidity memory-safe-assembly
                            assembly {
                                // `w = ln(x) - ln(ln(x)) + b * ln(ln(x)) / ln(x)`.
                                w := add(sdiv(mul(ll, 1023715080943847266), w), sub(w, ll))
                                i := add(3, iszero(shr(68, x)))
                                c := iszero(shr(143, x))
                            }
                            if (c == 0) {
                                do { // If `x` is big, use Newton's so that intermediate values won't overflow.
                                    int256 e = expWad(w);
                                    /// @solidity memory-safe-assembly
                                    assembly {
                                        let t := mul(w, div(e, wad))
                                        w := sub(w, sdiv(sub(t, x), div(add(e, t), wad)))
                                    }
                                    if (p <= w) break;
                                    p = w;
                                } while (--i != 0);
                                /// @solidity memory-safe-assembly
                                assembly {
                                    w := sub(w, sgt(w, 2))
                                }
                                return w;
                            }
                        }
                        do { // Otherwise, use Halley's for faster convergence.
                            int256 e = expWad(w);
                            /// @solidity memory-safe-assembly
                            assembly {
                                let t := add(w, wad)
                                let s := sub(mul(w, e), mul(x, wad))
                                w := sub(w, sdiv(mul(s, wad), sub(mul(e, t), sdiv(mul(add(t, wad), s), add(t, t)))))
                            }
                            if (p <= w) break;
                            p = w;
                        } while (--i != c);
                        /// @solidity memory-safe-assembly
                        assembly {
                            w := sub(w, sgt(w, 2))
                        }
                        // For certain ranges of `x`, we'll use the quadratic-rate recursive formula of
                        // R. Iacono and J.P. Boyd for the last iteration, to avoid catastrophic cancellation.
                        if (c != 0) {
                            int256 t = w | 1;
                            /// @solidity memory-safe-assembly
                            assembly {
                                x := sdiv(mul(x, wad), t)
                            }
                            x = (t * (wad + lnWad(x)));
                            /// @solidity memory-safe-assembly
                            assembly {
                                w := sdiv(x, add(wad, t))
                            }
                        }
                    }
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                  GENERAL NUMBER UTILITIES                  */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Calculates `floor(x * y / d)` with full precision.
                /// Throws if result overflows a uint256 or when `d` is zero.
                /// Credit to Remco Bloemen under MIT license: https://2π.com/21/muldiv
                function fullMulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 result) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        for {} 1 {} {
                            // 512-bit multiply `[p1 p0] = x * y`.
                            // Compute the product mod `2**256` and mod `2**256 - 1`
                            // then use the Chinese Remainder Theorem to reconstruct
                            // the 512 bit result. The result is stored in two 256
                            // variables such that `product = p1 * 2**256 + p0`.
                            // Least significant 256 bits of the product.
                            result := mul(x, y) // Temporarily use `result` as `p0` to save gas.
                            let mm := mulmod(x, y, not(0))
                            // Most significant 256 bits of the product.
                            let p1 := sub(mm, add(result, lt(mm, result)))
                            // Handle non-overflow cases, 256 by 256 division.
                            if iszero(p1) {
                                if iszero(d) {
                                    mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.
                                    revert(0x1c, 0x04)
                                }
                                result := div(result, d)
                                break
                            }
                            // Make sure the result is less than `2**256`. Also prevents `d == 0`.
                            if iszero(gt(d, p1)) {
                                mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.
                                revert(0x1c, 0x04)
                            }
                            /*------------------- 512 by 256 division --------------------*/
                            // Make division exact by subtracting the remainder from `[p1 p0]`.
                            // Compute remainder using mulmod.
                            let r := mulmod(x, y, d)
                            // `t` is the least significant bit of `d`.
                            // Always greater or equal to 1.
                            let t := and(d, sub(0, d))
                            // Divide `d` by `t`, which is a power of two.
                            d := div(d, t)
                            // Invert `d mod 2**256`
                            // Now that `d` is an odd number, it has an inverse
                            // modulo `2**256` such that `d * inv = 1 mod 2**256`.
                            // Compute the inverse by starting with a seed that is correct
                            // correct for four bits. That is, `d * inv = 1 mod 2**4`.
                            let inv := xor(2, mul(3, d))
                            // Now use Newton-Raphson iteration to improve the precision.
                            // Thanks to Hensel's lifting lemma, this also works in modular
                            // arithmetic, doubling the correct bits in each step.
                            inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**8
                            inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**16
                            inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**32
                            inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**64
                            inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**128
                            result :=
                                mul(
                                    // Divide [p1 p0] by the factors of two.
                                    // Shift in bits from `p1` into `p0`. For this we need
                                    // to flip `t` such that it is `2**256 / t`.
                                    or(
                                        mul(sub(p1, gt(r, result)), add(div(sub(0, t), t), 1)),
                                        div(sub(result, r), t)
                                    ),
                                    // inverse mod 2**256
                                    mul(inv, sub(2, mul(d, inv)))
                                )
                            break
                        }
                    }
                }
                /// @dev Calculates `floor(x * y / d)` with full precision, rounded up.
                /// Throws if result overflows a uint256 or when `d` is zero.
                /// Credit to Uniswap-v3-core under MIT license:
                /// https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/FullMath.sol
                function fullMulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 result) {
                    result = fullMulDiv(x, y, d);
                    /// @solidity memory-safe-assembly
                    assembly {
                        if mulmod(x, y, d) {
                            result := add(result, 1)
                            if iszero(result) {
                                mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.
                                revert(0x1c, 0x04)
                            }
                        }
                    }
                }
                /// @dev Returns `floor(x * y / d)`.
                /// Reverts if `x * y` overflows, or `d` is zero.
                function mulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        // Equivalent to require(d != 0 && (y == 0 || x <= type(uint256).max / y))
                        if iszero(mul(d, iszero(mul(y, gt(x, div(not(0), y)))))) {
                            mstore(0x00, 0xad251c27) // `MulDivFailed()`.
                            revert(0x1c, 0x04)
                        }
                        z := div(mul(x, y), d)
                    }
                }
                /// @dev Returns `ceil(x * y / d)`.
                /// Reverts if `x * y` overflows, or `d` is zero.
                function mulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        // Equivalent to require(d != 0 && (y == 0 || x <= type(uint256).max / y))
                        if iszero(mul(d, iszero(mul(y, gt(x, div(not(0), y)))))) {
                            mstore(0x00, 0xad251c27) // `MulDivFailed()`.
                            revert(0x1c, 0x04)
                        }
                        z := add(iszero(iszero(mod(mul(x, y), d))), div(mul(x, y), d))
                    }
                }
                /// @dev Returns `ceil(x / d)`.
                /// Reverts if `d` is zero.
                function divUp(uint256 x, uint256 d) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if iszero(d) {
                            mstore(0x00, 0x65244e4e) // `DivFailed()`.
                            revert(0x1c, 0x04)
                        }
                        z := add(iszero(iszero(mod(x, d))), div(x, d))
                    }
                }
                /// @dev Returns `max(0, x - y)`.
                function zeroFloorSub(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := mul(gt(x, y), sub(x, y))
                    }
                }
                /// @dev Exponentiate `x` to `y` by squaring, denominated in base `b`.
                /// Reverts if the computation overflows.
                function rpow(uint256 x, uint256 y, uint256 b) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := mul(b, iszero(y)) // `0 ** 0 = 1`. Otherwise, `0 ** n = 0`.
                        if x {
                            z := xor(b, mul(xor(b, x), and(y, 1))) // `z = isEven(y) ? scale : x`
                            let half := shr(1, b) // Divide `b` by 2.
                            // Divide `y` by 2 every iteration.
                            for { y := shr(1, y) } y { y := shr(1, y) } {
                                let xx := mul(x, x) // Store x squared.
                                let xxRound := add(xx, half) // Round to the nearest number.
                                // Revert if `xx + half` overflowed, or if `x ** 2` overflows.
                                if or(lt(xxRound, xx), shr(128, x)) {
                                    mstore(0x00, 0x49f7642b) // `RPowOverflow()`.
                                    revert(0x1c, 0x04)
                                }
                                x := div(xxRound, b) // Set `x` to scaled `xxRound`.
                                // If `y` is odd:
                                if and(y, 1) {
                                    let zx := mul(z, x) // Compute `z * x`.
                                    let zxRound := add(zx, half) // Round to the nearest number.
                                    // If `z * x` overflowed or `zx + half` overflowed:
                                    if or(xor(div(zx, x), z), lt(zxRound, zx)) {
                                        // Revert if `x` is non-zero.
                                        if iszero(iszero(x)) {
                                            mstore(0x00, 0x49f7642b) // `RPowOverflow()`.
                                            revert(0x1c, 0x04)
                                        }
                                    }
                                    z := div(zxRound, b) // Return properly scaled `zxRound`.
                                }
                            }
                        }
                    }
                }
                /// @dev Returns the square root of `x`.
                function sqrt(uint256 x) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        // `floor(sqrt(2**15)) = 181`. `sqrt(2**15) - 181 = 2.84`.
                        z := 181 // The "correct" value is 1, but this saves a multiplication later.
                        // This segment is to get a reasonable initial estimate for the Babylonian method. With a bad
                        // start, the correct # of bits increases ~linearly each iteration instead of ~quadratically.
                        // Let `y = x / 2**r`. We check `y >= 2**(k + 8)`
                        // but shift right by `k` bits to ensure that if `x >= 256`, then `y >= 256`.
                        let r := shl(7, lt(0xffffffffffffffffffffffffffffffffff, x))
                        r := or(r, shl(6, lt(0xffffffffffffffffff, shr(r, x))))
                        r := or(r, shl(5, lt(0xffffffffff, shr(r, x))))
                        r := or(r, shl(4, lt(0xffffff, shr(r, x))))
                        z := shl(shr(1, r), z)
                        // Goal was to get `z*z*y` within a small factor of `x`. More iterations could
                        // get y in a tighter range. Currently, we will have y in `[256, 256*(2**16))`.
                        // We ensured `y >= 256` so that the relative difference between `y` and `y+1` is small.
                        // That's not possible if `x < 256` but we can just verify those cases exhaustively.
                        // Now, `z*z*y <= x < z*z*(y+1)`, and `y <= 2**(16+8)`, and either `y >= 256`, or `x < 256`.
                        // Correctness can be checked exhaustively for `x < 256`, so we assume `y >= 256`.
                        // Then `z*sqrt(y)` is within `sqrt(257)/sqrt(256)` of `sqrt(x)`, or about 20bps.
                        // For `s` in the range `[1/256, 256]`, the estimate `f(s) = (181/1024) * (s+1)`
                        // is in the range `(1/2.84 * sqrt(s), 2.84 * sqrt(s))`,
                        // with largest error when `s = 1` and when `s = 256` or `1/256`.
                        // Since `y` is in `[256, 256*(2**16))`, let `a = y/65536`, so that `a` is in `[1/256, 256)`.
                        // Then we can estimate `sqrt(y)` using
                        // `sqrt(65536) * 181/1024 * (a + 1) = 181/4 * (y + 65536)/65536 = 181 * (y + 65536)/2**18`.
                        // There is no overflow risk here since `y < 2**136` after the first branch above.
                        z := shr(18, mul(z, add(shr(r, x), 65536))) // A `mul()` is saved from starting `z` at 181.
                        // Given the worst case multiplicative error of 2.84 above, 7 iterations should be enough.
                        z := shr(1, add(z, div(x, z)))
                        z := shr(1, add(z, div(x, z)))
                        z := shr(1, add(z, div(x, z)))
                        z := shr(1, add(z, div(x, z)))
                        z := shr(1, add(z, div(x, z)))
                        z := shr(1, add(z, div(x, z)))
                        z := shr(1, add(z, div(x, z)))
                        // If `x+1` is a perfect square, the Babylonian method cycles between
                        // `floor(sqrt(x))` and `ceil(sqrt(x))`. This statement ensures we return floor.
                        // See: https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division
                        z := sub(z, lt(div(x, z), z))
                    }
                }
                /// @dev Returns the cube root of `x`.
                /// Credit to bout3fiddy and pcaversaccio under AGPLv3 license:
                /// https://github.com/pcaversaccio/snekmate/blob/main/src/utils/Math.vy
                function cbrt(uint256 x) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        let r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
                        r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
                        r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
                        r := or(r, shl(4, lt(0xffff, shr(r, x))))
                        r := or(r, shl(3, lt(0xff, shr(r, x))))
                        z := div(shl(div(r, 3), shl(lt(0xf, shr(r, x)), 0xf)), xor(7, mod(r, 3)))
                        z := div(add(add(div(x, mul(z, z)), z), z), 3)
                        z := div(add(add(div(x, mul(z, z)), z), z), 3)
                        z := div(add(add(div(x, mul(z, z)), z), z), 3)
                        z := div(add(add(div(x, mul(z, z)), z), z), 3)
                        z := div(add(add(div(x, mul(z, z)), z), z), 3)
                        z := div(add(add(div(x, mul(z, z)), z), z), 3)
                        z := div(add(add(div(x, mul(z, z)), z), z), 3)
                        z := sub(z, lt(div(x, mul(z, z)), z))
                    }
                }
                /// @dev Returns the square root of `x`, denominated in `WAD`.
                function sqrtWad(uint256 x) internal pure returns (uint256 z) {
                    unchecked {
                        z = 10 ** 9;
                        if (x <= type(uint256).max / 10 ** 36 - 1) {
                            x *= 10 ** 18;
                            z = 1;
                        }
                        z *= sqrt(x);
                    }
                }
                /// @dev Returns the cube root of `x`, denominated in `WAD`.
                function cbrtWad(uint256 x) internal pure returns (uint256 z) {
                    unchecked {
                        z = 10 ** 12;
                        if (x <= (type(uint256).max / 10 ** 36) * 10 ** 18 - 1) {
                            if (x >= type(uint256).max / 10 ** 36) {
                                x *= 10 ** 18;
                                z = 10 ** 6;
                            } else {
                                x *= 10 ** 36;
                                z = 1;
                            }
                        }
                        z *= cbrt(x);
                    }
                }
                /// @dev Returns the factorial of `x`.
                function factorial(uint256 x) internal pure returns (uint256 result) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if iszero(lt(x, 58)) {
                            mstore(0x00, 0xaba0f2a2) // `FactorialOverflow()`.
                            revert(0x1c, 0x04)
                        }
                        for { result := 1 } x { x := sub(x, 1) } { result := mul(result, x) }
                    }
                }
                /// @dev Returns the log2 of `x`.
                /// Equivalent to computing the index of the most significant bit (MSB) of `x`.
                /// Returns 0 if `x` is zero.
                function log2(uint256 x) internal pure returns (uint256 r) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
                        r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
                        r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
                        r := or(r, shl(4, lt(0xffff, shr(r, x))))
                        r := or(r, shl(3, lt(0xff, shr(r, x))))
                        // forgefmt: disable-next-item
                        r := or(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),
                            0x0706060506020504060203020504030106050205030304010505030400000000))
                    }
                }
                /// @dev Returns the log2 of `x`, rounded up.
                /// Returns 0 if `x` is zero.
                function log2Up(uint256 x) internal pure returns (uint256 r) {
                    r = log2(x);
                    /// @solidity memory-safe-assembly
                    assembly {
                        r := add(r, lt(shl(r, 1), x))
                    }
                }
                /// @dev Returns the log10 of `x`.
                /// Returns 0 if `x` is zero.
                function log10(uint256 x) internal pure returns (uint256 r) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if iszero(lt(x, 100000000000000000000000000000000000000)) {
                            x := div(x, 100000000000000000000000000000000000000)
                            r := 38
                        }
                        if iszero(lt(x, 100000000000000000000)) {
                            x := div(x, 100000000000000000000)
                            r := add(r, 20)
                        }
                        if iszero(lt(x, 10000000000)) {
                            x := div(x, 10000000000)
                            r := add(r, 10)
                        }
                        if iszero(lt(x, 100000)) {
                            x := div(x, 100000)
                            r := add(r, 5)
                        }
                        r := add(r, add(gt(x, 9), add(gt(x, 99), add(gt(x, 999), gt(x, 9999)))))
                    }
                }
                /// @dev Returns the log10 of `x`, rounded up.
                /// Returns 0 if `x` is zero.
                function log10Up(uint256 x) internal pure returns (uint256 r) {
                    r = log10(x);
                    /// @solidity memory-safe-assembly
                    assembly {
                        r := add(r, lt(exp(10, r), x))
                    }
                }
                /// @dev Returns the log256 of `x`.
                /// Returns 0 if `x` is zero.
                function log256(uint256 x) internal pure returns (uint256 r) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
                        r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
                        r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
                        r := or(r, shl(4, lt(0xffff, shr(r, x))))
                        r := or(shr(3, r), lt(0xff, shr(r, x)))
                    }
                }
                /// @dev Returns the log256 of `x`, rounded up.
                /// Returns 0 if `x` is zero.
                function log256Up(uint256 x) internal pure returns (uint256 r) {
                    r = log256(x);
                    /// @solidity memory-safe-assembly
                    assembly {
                        r := add(r, lt(shl(shl(3, r), 1), x))
                    }
                }
                /// @dev Returns the scientific notation format `mantissa * 10 ** exponent` of `x`.
                /// Useful for compressing prices (e.g. using 25 bit mantissa and 7 bit exponent).
                function sci(uint256 x) internal pure returns (uint256 mantissa, uint256 exponent) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        mantissa := x
                        if mantissa {
                            if iszero(mod(mantissa, 1000000000000000000000000000000000)) {
                                mantissa := div(mantissa, 1000000000000000000000000000000000)
                                exponent := 33
                            }
                            if iszero(mod(mantissa, 10000000000000000000)) {
                                mantissa := div(mantissa, 10000000000000000000)
                                exponent := add(exponent, 19)
                            }
                            if iszero(mod(mantissa, 1000000000000)) {
                                mantissa := div(mantissa, 1000000000000)
                                exponent := add(exponent, 12)
                            }
                            if iszero(mod(mantissa, 1000000)) {
                                mantissa := div(mantissa, 1000000)
                                exponent := add(exponent, 6)
                            }
                            if iszero(mod(mantissa, 10000)) {
                                mantissa := div(mantissa, 10000)
                                exponent := add(exponent, 4)
                            }
                            if iszero(mod(mantissa, 100)) {
                                mantissa := div(mantissa, 100)
                                exponent := add(exponent, 2)
                            }
                            if iszero(mod(mantissa, 10)) {
                                mantissa := div(mantissa, 10)
                                exponent := add(exponent, 1)
                            }
                        }
                    }
                }
                /// @dev Convenience function for packing `x` into a smaller number using `sci`.
                /// The `mantissa` will be in bits [7..255] (the upper 249 bits).
                /// The `exponent` will be in bits [0..6] (the lower 7 bits).
                /// Use `SafeCastLib` to safely ensure that the `packed` number is small
                /// enough to fit in the desired unsigned integer type:
                /// ```
                ///     uint32 packed = SafeCastLib.toUint32(FixedPointMathLib.packSci(777 ether));
                /// ```
                function packSci(uint256 x) internal pure returns (uint256 packed) {
                    (x, packed) = sci(x); // Reuse for `mantissa` and `exponent`.
                    /// @solidity memory-safe-assembly
                    assembly {
                        if shr(249, x) {
                            mstore(0x00, 0xce30380c) // `MantissaOverflow()`.
                            revert(0x1c, 0x04)
                        }
                        packed := or(shl(7, x), packed)
                    }
                }
                /// @dev Convenience function for unpacking a packed number from `packSci`.
                function unpackSci(uint256 packed) internal pure returns (uint256 unpacked) {
                    unchecked {
                        unpacked = (packed >> 7) * 10 ** (packed & 0x7f);
                    }
                }
                /// @dev Returns the average of `x` and `y`.
                function avg(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    unchecked {
                        z = (x & y) + ((x ^ y) >> 1);
                    }
                }
                /// @dev Returns the average of `x` and `y`.
                function avg(int256 x, int256 y) internal pure returns (int256 z) {
                    unchecked {
                        z = (x >> 1) + (y >> 1) + (((x & 1) + (y & 1)) >> 1);
                    }
                }
                /// @dev Returns the absolute value of `x`.
                function abs(int256 x) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := xor(sub(0, shr(255, x)), add(sub(0, shr(255, x)), x))
                    }
                }
                /// @dev Returns the absolute distance between `x` and `y`.
                function dist(int256 x, int256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := xor(mul(xor(sub(y, x), sub(x, y)), sgt(x, y)), sub(y, x))
                    }
                }
                /// @dev Returns the minimum of `x` and `y`.
                function min(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := xor(x, mul(xor(x, y), lt(y, x)))
                    }
                }
                /// @dev Returns the minimum of `x` and `y`.
                function min(int256 x, int256 y) internal pure returns (int256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := xor(x, mul(xor(x, y), slt(y, x)))
                    }
                }
                /// @dev Returns the maximum of `x` and `y`.
                function max(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := xor(x, mul(xor(x, y), gt(y, x)))
                    }
                }
                /// @dev Returns the maximum of `x` and `y`.
                function max(int256 x, int256 y) internal pure returns (int256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := xor(x, mul(xor(x, y), sgt(y, x)))
                    }
                }
                /// @dev Returns `x`, bounded to `minValue` and `maxValue`.
                function clamp(uint256 x, uint256 minValue, uint256 maxValue)
                    internal
                    pure
                    returns (uint256 z)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := xor(x, mul(xor(x, minValue), gt(minValue, x)))
                        z := xor(z, mul(xor(z, maxValue), lt(maxValue, z)))
                    }
                }
                /// @dev Returns `x`, bounded to `minValue` and `maxValue`.
                function clamp(int256 x, int256 minValue, int256 maxValue) internal pure returns (int256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := xor(x, mul(xor(x, minValue), sgt(minValue, x)))
                        z := xor(z, mul(xor(z, maxValue), slt(maxValue, z)))
                    }
                }
                /// @dev Returns greatest common divisor of `x` and `y`.
                function gcd(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        for { z := x } y {} {
                            let t := y
                            y := mod(z, y)
                            z := t
                        }
                    }
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                   RAW NUMBER OPERATIONS                    */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Returns `x + y`, without checking for overflow.
                function rawAdd(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    unchecked {
                        z = x + y;
                    }
                }
                /// @dev Returns `x + y`, without checking for overflow.
                function rawAdd(int256 x, int256 y) internal pure returns (int256 z) {
                    unchecked {
                        z = x + y;
                    }
                }
                /// @dev Returns `x - y`, without checking for underflow.
                function rawSub(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    unchecked {
                        z = x - y;
                    }
                }
                /// @dev Returns `x - y`, without checking for underflow.
                function rawSub(int256 x, int256 y) internal pure returns (int256 z) {
                    unchecked {
                        z = x - y;
                    }
                }
                /// @dev Returns `x * y`, without checking for overflow.
                function rawMul(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    unchecked {
                        z = x * y;
                    }
                }
                /// @dev Returns `x * y`, without checking for overflow.
                function rawMul(int256 x, int256 y) internal pure returns (int256 z) {
                    unchecked {
                        z = x * y;
                    }
                }
                /// @dev Returns `x / y`, returning 0 if `y` is zero.
                function rawDiv(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := div(x, y)
                    }
                }
                /// @dev Returns `x / y`, returning 0 if `y` is zero.
                function rawSDiv(int256 x, int256 y) internal pure returns (int256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := sdiv(x, y)
                    }
                }
                /// @dev Returns `x % y`, returning 0 if `y` is zero.
                function rawMod(uint256 x, uint256 y) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := mod(x, y)
                    }
                }
                /// @dev Returns `x % y`, returning 0 if `y` is zero.
                function rawSMod(int256 x, int256 y) internal pure returns (int256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := smod(x, y)
                    }
                }
                /// @dev Returns `(x + y) % d`, return 0 if `d` if zero.
                function rawAddMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := addmod(x, y, d)
                    }
                }
                /// @dev Returns `(x * y) % d`, return 0 if `d` if zero.
                function rawMulMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        z := mulmod(x, y, d)
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.4;
            /// @notice Reentrancy guard mixin.
            /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/ReentrancyGuard.sol)
            abstract contract ReentrancyGuard {
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                       CUSTOM ERRORS                        */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Unauthorized reentrant call.
                error Reentrancy();
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                          STORAGE                           */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Equivalent to: `uint72(bytes9(keccak256("_REENTRANCY_GUARD_SLOT")))`.
                /// 9 bytes is large enough to avoid collisions with lower slots,
                /// but not too large to result in excessive bytecode bloat.
                uint256 private constant _REENTRANCY_GUARD_SLOT = 0x929eee149b4bd21268;
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                      REENTRANCY GUARD                      */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Guards a function from reentrancy.
                modifier nonReentrant() virtual {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if eq(sload(_REENTRANCY_GUARD_SLOT), address()) {
                            mstore(0x00, 0xab143c06) // `Reentrancy()`.
                            revert(0x1c, 0x04)
                        }
                        sstore(_REENTRANCY_GUARD_SLOT, address())
                    }
                    _;
                    /// @solidity memory-safe-assembly
                    assembly {
                        sstore(_REENTRANCY_GUARD_SLOT, codesize())
                    }
                }
                /// @dev Guards a view function from read-only reentrancy.
                modifier nonReadReentrant() virtual {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if eq(sload(_REENTRANCY_GUARD_SLOT), address()) {
                            mstore(0x00, 0xab143c06) // `Reentrancy()`.
                            revert(0x1c, 0x04)
                        }
                    }
                    _;
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.4;
            /// @notice Class with helper read functions for clone with immutable args.
            /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/Clone.sol)
            /// @author Adapted from clones with immutable args by zefram.eth, Saw-mon & Natalie
            /// (https://github.com/Saw-mon-and-Natalie/clones-with-immutable-args)
            abstract contract Clone {
                /// @dev Reads all of the immutable args.
                function _getArgBytes() internal pure returns (bytes memory arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := mload(0x40)
                        let length := sub(calldatasize(), add(2, offset)) // 2 bytes are used for the length.
                        mstore(arg, length) // Store the length.
                        calldatacopy(add(arg, 0x20), offset, length)
                        let o := add(add(arg, 0x20), length)
                        mstore(o, 0) // Zeroize the slot after the bytes.
                        mstore(0x40, add(o, 0x20)) // Allocate the memory.
                    }
                }
                /// @dev Reads an immutable arg with type bytes.
                function _getArgBytes(uint256 argOffset, uint256 length)
                    internal
                    pure
                    returns (bytes memory arg)
                {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := mload(0x40)
                        mstore(arg, length) // Store the length.
                        calldatacopy(add(arg, 0x20), add(offset, argOffset), length)
                        let o := add(add(arg, 0x20), length)
                        mstore(o, 0) // Zeroize the slot after the bytes.
                        mstore(0x40, add(o, 0x20)) // Allocate the memory.
                    }
                }
                /// @dev Reads an immutable arg with type address.
                function _getArgAddress(uint256 argOffset) internal pure returns (address arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(96, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads a uint256 array stored in the immutable args.
                function _getArgUint256Array(uint256 argOffset, uint256 length)
                    internal
                    pure
                    returns (uint256[] memory arg)
                {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := mload(0x40)
                        mstore(arg, length) // Store the length.
                        calldatacopy(add(arg, 0x20), add(offset, argOffset), shl(5, length))
                        mstore(0x40, add(add(arg, 0x20), shl(5, length))) // Allocate the memory.
                    }
                }
                /// @dev Reads a bytes32 array stored in the immutable args.
                function _getArgBytes32Array(uint256 argOffset, uint256 length)
                    internal
                    pure
                    returns (bytes32[] memory arg)
                {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := mload(0x40)
                        mstore(arg, length) // Store the length.
                        calldatacopy(add(arg, 0x20), add(offset, argOffset), shl(5, length))
                        mstore(0x40, add(add(arg, 0x20), shl(5, length))) // Allocate the memory.
                    }
                }
                /// @dev Reads an immutable arg with type bytes32.
                function _getArgBytes32(uint256 argOffset) internal pure returns (bytes32 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := calldataload(add(offset, argOffset))
                    }
                }
                /// @dev Reads an immutable arg with type uint256.
                function _getArgUint256(uint256 argOffset) internal pure returns (uint256 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := calldataload(add(offset, argOffset))
                    }
                }
                /// @dev Reads an immutable arg with type uint248.
                function _getArgUint248(uint256 argOffset) internal pure returns (uint248 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(8, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint240.
                function _getArgUint240(uint256 argOffset) internal pure returns (uint240 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(16, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint232.
                function _getArgUint232(uint256 argOffset) internal pure returns (uint232 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(24, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint224.
                function _getArgUint224(uint256 argOffset) internal pure returns (uint224 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(0x20, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint216.
                function _getArgUint216(uint256 argOffset) internal pure returns (uint216 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(40, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint208.
                function _getArgUint208(uint256 argOffset) internal pure returns (uint208 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(48, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint200.
                function _getArgUint200(uint256 argOffset) internal pure returns (uint200 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(56, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint192.
                function _getArgUint192(uint256 argOffset) internal pure returns (uint192 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(64, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint184.
                function _getArgUint184(uint256 argOffset) internal pure returns (uint184 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(72, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint176.
                function _getArgUint176(uint256 argOffset) internal pure returns (uint176 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(80, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint168.
                function _getArgUint168(uint256 argOffset) internal pure returns (uint168 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(88, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint160.
                function _getArgUint160(uint256 argOffset) internal pure returns (uint160 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(96, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint152.
                function _getArgUint152(uint256 argOffset) internal pure returns (uint152 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(104, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint144.
                function _getArgUint144(uint256 argOffset) internal pure returns (uint144 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(112, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint136.
                function _getArgUint136(uint256 argOffset) internal pure returns (uint136 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(120, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint128.
                function _getArgUint128(uint256 argOffset) internal pure returns (uint128 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(128, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint120.
                function _getArgUint120(uint256 argOffset) internal pure returns (uint120 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(136, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint112.
                function _getArgUint112(uint256 argOffset) internal pure returns (uint112 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(144, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint104.
                function _getArgUint104(uint256 argOffset) internal pure returns (uint104 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(152, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint96.
                function _getArgUint96(uint256 argOffset) internal pure returns (uint96 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(160, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint88.
                function _getArgUint88(uint256 argOffset) internal pure returns (uint88 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(168, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint80.
                function _getArgUint80(uint256 argOffset) internal pure returns (uint80 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(176, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint72.
                function _getArgUint72(uint256 argOffset) internal pure returns (uint72 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(184, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint64.
                function _getArgUint64(uint256 argOffset) internal pure returns (uint64 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(192, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint56.
                function _getArgUint56(uint256 argOffset) internal pure returns (uint56 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(200, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint48.
                function _getArgUint48(uint256 argOffset) internal pure returns (uint48 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(208, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint40.
                function _getArgUint40(uint256 argOffset) internal pure returns (uint40 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(216, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint32.
                function _getArgUint32(uint256 argOffset) internal pure returns (uint32 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(224, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint24.
                function _getArgUint24(uint256 argOffset) internal pure returns (uint24 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(232, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint16.
                function _getArgUint16(uint256 argOffset) internal pure returns (uint16 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(240, calldataload(add(offset, argOffset)))
                    }
                }
                /// @dev Reads an immutable arg with type uint8.
                function _getArgUint8(uint256 argOffset) internal pure returns (uint8 arg) {
                    uint256 offset = _getImmutableArgsOffset();
                    /// @solidity memory-safe-assembly
                    assembly {
                        arg := shr(248, calldataload(add(offset, argOffset)))
                    }
                }
                /// @return offset The offset of the packed immutable args in calldata.
                function _getImmutableArgsOffset() internal pure returns (uint256 offset) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        offset := sub(calldatasize(), shr(240, calldataload(sub(calldatasize(), 2))))
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.4;
            /// @notice Gas optimized verification of proof of inclusion for a leaf in a Merkle tree.
            /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/MerkleProofLib.sol)
            /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/MerkleProofLib.sol)
            /// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/MerkleProof.sol)
            library MerkleProofLib {
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*            MERKLE PROOF VERIFICATION OPERATIONS            */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Returns whether `leaf` exists in the Merkle tree with `root`, given `proof`.
                function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf)
                    internal
                    pure
                    returns (bool isValid)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if mload(proof) {
                            // Initialize `offset` to the offset of `proof` elements in memory.
                            let offset := add(proof, 0x20)
                            // Left shift by 5 is equivalent to multiplying by 0x20.
                            let end := add(offset, shl(5, mload(proof)))
                            // Iterate over proof elements to compute root hash.
                            for {} 1 {} {
                                // Slot of `leaf` in scratch space.
                                // If the condition is true: 0x20, otherwise: 0x00.
                                let scratch := shl(5, gt(leaf, mload(offset)))
                                // Store elements to hash contiguously in scratch space.
                                // Scratch space is 64 bytes (0x00 - 0x3f) and both elements are 32 bytes.
                                mstore(scratch, leaf)
                                mstore(xor(scratch, 0x20), mload(offset))
                                // Reuse `leaf` to store the hash to reduce stack operations.
                                leaf := keccak256(0x00, 0x40)
                                offset := add(offset, 0x20)
                                if iszero(lt(offset, end)) { break }
                            }
                        }
                        isValid := eq(leaf, root)
                    }
                }
                /// @dev Returns whether `leaf` exists in the Merkle tree with `root`, given `proof`.
                function verifyCalldata(bytes32[] calldata proof, bytes32 root, bytes32 leaf)
                    internal
                    pure
                    returns (bool isValid)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if proof.length {
                            // Left shift by 5 is equivalent to multiplying by 0x20.
                            let end := add(proof.offset, shl(5, proof.length))
                            // Initialize `offset` to the offset of `proof` in the calldata.
                            let offset := proof.offset
                            // Iterate over proof elements to compute root hash.
                            for {} 1 {} {
                                // Slot of `leaf` in scratch space.
                                // If the condition is true: 0x20, otherwise: 0x00.
                                let scratch := shl(5, gt(leaf, calldataload(offset)))
                                // Store elements to hash contiguously in scratch space.
                                // Scratch space is 64 bytes (0x00 - 0x3f) and both elements are 32 bytes.
                                mstore(scratch, leaf)
                                mstore(xor(scratch, 0x20), calldataload(offset))
                                // Reuse `leaf` to store the hash to reduce stack operations.
                                leaf := keccak256(0x00, 0x40)
                                offset := add(offset, 0x20)
                                if iszero(lt(offset, end)) { break }
                            }
                        }
                        isValid := eq(leaf, root)
                    }
                }
                /// @dev Returns whether all `leaves` exist in the Merkle tree with `root`,
                /// given `proof` and `flags`.
                ///
                /// Note:
                /// - Breaking the invariant `flags.length == (leaves.length - 1) + proof.length`
                ///   will always return false.
                /// - The sum of the lengths of `proof` and `leaves` must never overflow.
                /// - Any non-zero word in the `flags` array is treated as true.
                /// - The memory offset of `proof` must be non-zero
                ///   (i.e. `proof` is not pointing to the scratch space).
                function verifyMultiProof(
                    bytes32[] memory proof,
                    bytes32 root,
                    bytes32[] memory leaves,
                    bool[] memory flags
                ) internal pure returns (bool isValid) {
                    // Rebuilds the root by consuming and producing values on a queue.
                    // The queue starts with the `leaves` array, and goes into a `hashes` array.
                    // After the process, the last element on the queue is verified
                    // to be equal to the `root`.
                    //
                    // The `flags` array denotes whether the sibling
                    // should be popped from the queue (`flag == true`), or
                    // should be popped from the `proof` (`flag == false`).
                    /// @solidity memory-safe-assembly
                    assembly {
                        // Cache the lengths of the arrays.
                        let leavesLength := mload(leaves)
                        let proofLength := mload(proof)
                        let flagsLength := mload(flags)
                        // Advance the pointers of the arrays to point to the data.
                        leaves := add(0x20, leaves)
                        proof := add(0x20, proof)
                        flags := add(0x20, flags)
                        // If the number of flags is correct.
                        for {} eq(add(leavesLength, proofLength), add(flagsLength, 1)) {} {
                            // For the case where `proof.length + leaves.length == 1`.
                            if iszero(flagsLength) {
                                // `isValid = (proof.length == 1 ? proof[0] : leaves[0]) == root`.
                                isValid := eq(mload(xor(leaves, mul(xor(proof, leaves), proofLength))), root)
                                break
                            }
                            // The required final proof offset if `flagsLength` is not zero, otherwise zero.
                            let proofEnd := add(proof, shl(5, proofLength))
                            // We can use the free memory space for the queue.
                            // We don't need to allocate, since the queue is temporary.
                            let hashesFront := mload(0x40)
                            // Copy the leaves into the hashes.
                            // Sometimes, a little memory expansion costs less than branching.
                            // Should cost less, even with a high free memory offset of 0x7d00.
                            leavesLength := shl(5, leavesLength)
                            for { let i := 0 } iszero(eq(i, leavesLength)) { i := add(i, 0x20) } {
                                mstore(add(hashesFront, i), mload(add(leaves, i)))
                            }
                            // Compute the back of the hashes.
                            let hashesBack := add(hashesFront, leavesLength)
                            // This is the end of the memory for the queue.
                            // We recycle `flagsLength` to save on stack variables (sometimes save gas).
                            flagsLength := add(hashesBack, shl(5, flagsLength))
                            for {} 1 {} {
                                // Pop from `hashes`.
                                let a := mload(hashesFront)
                                // Pop from `hashes`.
                                let b := mload(add(hashesFront, 0x20))
                                hashesFront := add(hashesFront, 0x40)
                                // If the flag is false, load the next proof,
                                // else, pops from the queue.
                                if iszero(mload(flags)) {
                                    // Loads the next proof.
                                    b := mload(proof)
                                    proof := add(proof, 0x20)
                                    // Unpop from `hashes`.
                                    hashesFront := sub(hashesFront, 0x20)
                                }
                                // Advance to the next flag.
                                flags := add(flags, 0x20)
                                // Slot of `a` in scratch space.
                                // If the condition is true: 0x20, otherwise: 0x00.
                                let scratch := shl(5, gt(a, b))
                                // Hash the scratch space and push the result onto the queue.
                                mstore(scratch, a)
                                mstore(xor(scratch, 0x20), b)
                                mstore(hashesBack, keccak256(0x00, 0x40))
                                hashesBack := add(hashesBack, 0x20)
                                if iszero(lt(hashesBack, flagsLength)) { break }
                            }
                            isValid :=
                                and(
                                    // Checks if the last value in the queue is same as the root.
                                    eq(mload(sub(hashesBack, 0x20)), root),
                                    // And whether all the proofs are used, if required.
                                    eq(proofEnd, proof)
                                )
                            break
                        }
                    }
                }
                /// @dev Returns whether all `leaves` exist in the Merkle tree with `root`,
                /// given `proof` and `flags`.
                ///
                /// Note:
                /// - Breaking the invariant `flags.length == (leaves.length - 1) + proof.length`
                ///   will always return false.
                /// - Any non-zero word in the `flags` array is treated as true.
                /// - The calldata offset of `proof` must be non-zero
                ///   (i.e. `proof` is from a regular Solidity function with a 4-byte selector).
                function verifyMultiProofCalldata(
                    bytes32[] calldata proof,
                    bytes32 root,
                    bytes32[] calldata leaves,
                    bool[] calldata flags
                ) internal pure returns (bool isValid) {
                    // Rebuilds the root by consuming and producing values on a queue.
                    // The queue starts with the `leaves` array, and goes into a `hashes` array.
                    // After the process, the last element on the queue is verified
                    // to be equal to the `root`.
                    //
                    // The `flags` array denotes whether the sibling
                    // should be popped from the queue (`flag == true`), or
                    // should be popped from the `proof` (`flag == false`).
                    /// @solidity memory-safe-assembly
                    assembly {
                        // If the number of flags is correct.
                        for {} eq(add(leaves.length, proof.length), add(flags.length, 1)) {} {
                            // For the case where `proof.length + leaves.length == 1`.
                            if iszero(flags.length) {
                                // `isValid = (proof.length == 1 ? proof[0] : leaves[0]) == root`.
                                // forgefmt: disable-next-item
                                isValid := eq(
                                    calldataload(
                                        xor(leaves.offset, mul(xor(proof.offset, leaves.offset), proof.length))
                                    ),
                                    root
                                )
                                break
                            }
                            // The required final proof offset if `flagsLength` is not zero, otherwise zero.
                            let proofEnd := add(proof.offset, shl(5, proof.length))
                            // We can use the free memory space for the queue.
                            // We don't need to allocate, since the queue is temporary.
                            let hashesFront := mload(0x40)
                            // Copy the leaves into the hashes.
                            // Sometimes, a little memory expansion costs less than branching.
                            // Should cost less, even with a high free memory offset of 0x7d00.
                            calldatacopy(hashesFront, leaves.offset, shl(5, leaves.length))
                            // Compute the back of the hashes.
                            let hashesBack := add(hashesFront, shl(5, leaves.length))
                            // This is the end of the memory for the queue.
                            // We recycle `flagsLength` to save on stack variables (sometimes save gas).
                            flags.length := add(hashesBack, shl(5, flags.length))
                            // We don't need to make a copy of `proof.offset` or `flags.offset`,
                            // as they are pass-by-value (this trick may not always save gas).
                            for {} 1 {} {
                                // Pop from `hashes`.
                                let a := mload(hashesFront)
                                // Pop from `hashes`.
                                let b := mload(add(hashesFront, 0x20))
                                hashesFront := add(hashesFront, 0x40)
                                // If the flag is false, load the next proof,
                                // else, pops from the queue.
                                if iszero(calldataload(flags.offset)) {
                                    // Loads the next proof.
                                    b := calldataload(proof.offset)
                                    proof.offset := add(proof.offset, 0x20)
                                    // Unpop from `hashes`.
                                    hashesFront := sub(hashesFront, 0x20)
                                }
                                // Advance to the next flag offset.
                                flags.offset := add(flags.offset, 0x20)
                                // Slot of `a` in scratch space.
                                // If the condition is true: 0x20, otherwise: 0x00.
                                let scratch := shl(5, gt(a, b))
                                // Hash the scratch space and push the result onto the queue.
                                mstore(scratch, a)
                                mstore(xor(scratch, 0x20), b)
                                mstore(hashesBack, keccak256(0x00, 0x40))
                                hashesBack := add(hashesBack, 0x20)
                                if iszero(lt(hashesBack, flags.length)) { break }
                            }
                            isValid :=
                                and(
                                    // Checks if the last value in the queue is same as the root.
                                    eq(mload(sub(hashesBack, 0x20)), root),
                                    // And whether all the proofs are used, if required.
                                    eq(proofEnd, proof.offset)
                                )
                            break
                        }
                    }
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                   EMPTY CALLDATA HELPERS                   */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Returns an empty calldata bytes32 array.
                function emptyProof() internal pure returns (bytes32[] calldata proof) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        proof.length := 0
                    }
                }
                /// @dev Returns an empty calldata bytes32 array.
                function emptyLeaves() internal pure returns (bytes32[] calldata leaves) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        leaves.length := 0
                    }
                }
                /// @dev Returns an empty calldata bool array.
                function emptyFlags() internal pure returns (bool[] calldata flags) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        flags.length := 0
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.4;
            /// @notice Contract for EIP-712 typed structured data hashing and signing.
            /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/EIP712.sol)
            /// @author Modified from Solbase (https://github.com/Sol-DAO/solbase/blob/main/src/utils/EIP712.sol)
            /// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/EIP712.sol)
            ///
            /// @dev Note, this implementation:
            /// - Uses `address(this)` for the `verifyingContract` field.
            /// - Does NOT use the optional EIP-712 salt.
            /// - Does NOT use any EIP-712 extensions.
            /// This is for simplicity and to save gas.
            /// If you need to customize, please fork / modify accordingly.
            abstract contract EIP712 {
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                  CONSTANTS AND IMMUTABLES                  */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev `keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")`.
                bytes32 internal constant _DOMAIN_TYPEHASH =
                    0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f;
                uint256 private immutable _cachedThis;
                uint256 private immutable _cachedChainId;
                bytes32 private immutable _cachedNameHash;
                bytes32 private immutable _cachedVersionHash;
                bytes32 private immutable _cachedDomainSeparator;
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                        CONSTRUCTOR                         */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Cache the hashes for cheaper runtime gas costs.
                /// In the case of upgradeable contracts (i.e. proxies),
                /// or if the chain id changes due to a hard fork,
                /// the domain separator will be seamlessly calculated on-the-fly.
                constructor() {
                    _cachedThis = uint256(uint160(address(this)));
                    _cachedChainId = block.chainid;
                    string memory name;
                    string memory version;
                    if (!_domainNameAndVersionMayChange()) (name, version) = _domainNameAndVersion();
                    bytes32 nameHash = _domainNameAndVersionMayChange() ? bytes32(0) : keccak256(bytes(name));
                    bytes32 versionHash =
                        _domainNameAndVersionMayChange() ? bytes32(0) : keccak256(bytes(version));
                    _cachedNameHash = nameHash;
                    _cachedVersionHash = versionHash;
                    bytes32 separator;
                    if (!_domainNameAndVersionMayChange()) {
                        /// @solidity memory-safe-assembly
                        assembly {
                            let m := mload(0x40) // Load the free memory pointer.
                            mstore(m, _DOMAIN_TYPEHASH)
                            mstore(add(m, 0x20), nameHash)
                            mstore(add(m, 0x40), versionHash)
                            mstore(add(m, 0x60), chainid())
                            mstore(add(m, 0x80), address())
                            separator := keccak256(m, 0xa0)
                        }
                    }
                    _cachedDomainSeparator = separator;
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                   FUNCTIONS TO OVERRIDE                    */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Please override this function to return the domain name and version.
                /// ```
                ///     function _domainNameAndVersion()
                ///         internal
                ///         pure
                ///         virtual
                ///         returns (string memory name, string memory version)
                ///     {
                ///         name = "Solady";
                ///         version = "1";
                ///     }
                /// ```
                ///
                /// Note: If the returned result may change after the contract has been deployed,
                /// you must override `_domainNameAndVersionMayChange()` to return true.
                function _domainNameAndVersion()
                    internal
                    view
                    virtual
                    returns (string memory name, string memory version);
                /// @dev Returns if `_domainNameAndVersion()` may change
                /// after the contract has been deployed (i.e. after the constructor).
                /// Default: false.
                function _domainNameAndVersionMayChange() internal pure virtual returns (bool result) {}
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                     HASHING OPERATIONS                     */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Returns the EIP-712 domain separator.
                function _domainSeparator() internal view virtual returns (bytes32 separator) {
                    if (_domainNameAndVersionMayChange()) {
                        separator = _buildDomainSeparator();
                    } else {
                        separator = _cachedDomainSeparator;
                        if (_cachedDomainSeparatorInvalidated()) separator = _buildDomainSeparator();
                    }
                }
                /// @dev Returns the hash of the fully encoded EIP-712 message for this domain,
                /// given `structHash`, as defined in
                /// https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct.
                ///
                /// The hash can be used together with {ECDSA-recover} to obtain the signer of a message:
                /// ```
                ///     bytes32 digest = _hashTypedData(keccak256(abi.encode(
                ///         keccak256("Mail(address to,string contents)"),
                ///         mailTo,
                ///         keccak256(bytes(mailContents))
                ///     )));
                ///     address signer = ECDSA.recover(digest, signature);
                /// ```
                function _hashTypedData(bytes32 structHash) internal view virtual returns (bytes32 digest) {
                    // We will use `digest` to store the domain separator to save a bit of gas.
                    if (_domainNameAndVersionMayChange()) {
                        digest = _buildDomainSeparator();
                    } else {
                        digest = _cachedDomainSeparator;
                        if (_cachedDomainSeparatorInvalidated()) digest = _buildDomainSeparator();
                    }
                    /// @solidity memory-safe-assembly
                    assembly {
                        // Compute the digest.
                        mstore(0x00, 0x1901000000000000) // Store "\\x19\\x01".
                        mstore(0x1a, digest) // Store the domain separator.
                        mstore(0x3a, structHash) // Store the struct hash.
                        digest := keccak256(0x18, 0x42)
                        // Restore the part of the free memory slot that was overwritten.
                        mstore(0x3a, 0)
                    }
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                    EIP-5267 OPERATIONS                     */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev See: https://eips.ethereum.org/EIPS/eip-5267
                function eip712Domain()
                    public
                    view
                    virtual
                    returns (
                        bytes1 fields,
                        string memory name,
                        string memory version,
                        uint256 chainId,
                        address verifyingContract,
                        bytes32 salt,
                        uint256[] memory extensions
                    )
                {
                    fields = hex"0f"; // `0b01111`.
                    (name, version) = _domainNameAndVersion();
                    chainId = block.chainid;
                    verifyingContract = address(this);
                    salt = salt; // `bytes32(0)`.
                    extensions = extensions; // `new uint256[](0)`.
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                      PRIVATE HELPERS                       */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Returns the EIP-712 domain separator.
                function _buildDomainSeparator() private view returns (bytes32 separator) {
                    // We will use `separator` to store the name hash to save a bit of gas.
                    bytes32 versionHash;
                    if (_domainNameAndVersionMayChange()) {
                        (string memory name, string memory version) = _domainNameAndVersion();
                        separator = keccak256(bytes(name));
                        versionHash = keccak256(bytes(version));
                    } else {
                        separator = _cachedNameHash;
                        versionHash = _cachedVersionHash;
                    }
                    /// @solidity memory-safe-assembly
                    assembly {
                        let m := mload(0x40) // Load the free memory pointer.
                        mstore(m, _DOMAIN_TYPEHASH)
                        mstore(add(m, 0x20), separator) // Name hash.
                        mstore(add(m, 0x40), versionHash)
                        mstore(add(m, 0x60), chainid())
                        mstore(add(m, 0x80), address())
                        separator := keccak256(m, 0xa0)
                    }
                }
                /// @dev Returns if the cached domain separator has been invalidated.
                function _cachedDomainSeparatorInvalidated() private view returns (bool result) {
                    uint256 cachedChainId = _cachedChainId;
                    uint256 cachedThis = _cachedThis;
                    /// @solidity memory-safe-assembly
                    assembly {
                        result := iszero(and(eq(chainid(), cachedChainId), eq(address(), cachedThis)))
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.4;
            /// @notice Gas optimized ECDSA wrapper.
            /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/ECDSA.sol)
            /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/ECDSA.sol)
            /// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/ECDSA.sol)
            ///
            /// @dev Note:
            /// - The recovery functions use the ecrecover precompile (0x1).
            /// - As of Solady version 0.0.68, the `recover` variants will revert upon recovery failure.
            ///   This is for more safety by default.
            ///   Use the `tryRecover` variants if you need to get the zero address back
            ///   upon recovery failure instead.
            /// - As of Solady version 0.0.134, all `bytes signature` variants accept both
            ///   regular 65-byte `(r, s, v)` and EIP-2098 `(r, vs)` short form signatures.
            ///   See: https://eips.ethereum.org/EIPS/eip-2098
            ///   This is for calldata efficiency on smart accounts prevalent on L2s.
            ///
            /// WARNING! Do NOT use signatures as unique identifiers:
            /// - Use a nonce in the digest to prevent replay attacks on the same contract.
            /// - Use EIP-712 for the digest to prevent replay attacks across different chains and contracts.
            ///   EIP-712 also enables readable signing of typed data for better user safety.
            /// This implementation does NOT check if a signature is non-malleable.
            library ECDSA {
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                        CUSTOM ERRORS                       */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev The signature is invalid.
                error InvalidSignature();
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                    RECOVERY OPERATIONS                     */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Recovers the signer's address from a message digest `hash`, and the `signature`.
                function recover(bytes32 hash, bytes memory signature) internal view returns (address result) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        result := 1
                        let m := mload(0x40) // Cache the free memory pointer.
                        for {} 1 {} {
                            mstore(0x00, hash)
                            mstore(0x40, mload(add(signature, 0x20))) // `r`.
                            if eq(mload(signature), 64) {
                                let vs := mload(add(signature, 0x40))
                                mstore(0x20, add(shr(255, vs), 27)) // `v`.
                                mstore(0x60, shr(1, shl(1, vs))) // `s`.
                                break
                            }
                            if eq(mload(signature), 65) {
                                mstore(0x20, byte(0, mload(add(signature, 0x60)))) // `v`.
                                mstore(0x60, mload(add(signature, 0x40))) // `s`.
                                break
                            }
                            result := 0
                            break
                        }
                        result :=
                            mload(
                                staticcall(
                                    gas(), // Amount of gas left for the transaction.
                                    result, // Address of `ecrecover`.
                                    0x00, // Start of input.
                                    0x80, // Size of input.
                                    0x01, // Start of output.
                                    0x20 // Size of output.
                                )
                            )
                        // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
                        if iszero(returndatasize()) {
                            mstore(0x00, 0x8baa579f) // `InvalidSignature()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x60, 0) // Restore the zero slot.
                        mstore(0x40, m) // Restore the free memory pointer.
                    }
                }
                /// @dev Recovers the signer's address from a message digest `hash`, and the `signature`.
                function recoverCalldata(bytes32 hash, bytes calldata signature)
                    internal
                    view
                    returns (address result)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        result := 1
                        let m := mload(0x40) // Cache the free memory pointer.
                        mstore(0x00, hash)
                        for {} 1 {} {
                            if eq(signature.length, 64) {
                                let vs := calldataload(add(signature.offset, 0x20))
                                mstore(0x20, add(shr(255, vs), 27)) // `v`.
                                mstore(0x40, calldataload(signature.offset)) // `r`.
                                mstore(0x60, shr(1, shl(1, vs))) // `s`.
                                break
                            }
                            if eq(signature.length, 65) {
                                mstore(0x20, byte(0, calldataload(add(signature.offset, 0x40)))) // `v`.
                                calldatacopy(0x40, signature.offset, 0x40) // Copy `r` and `s`.
                                break
                            }
                            result := 0
                            break
                        }
                        result :=
                            mload(
                                staticcall(
                                    gas(), // Amount of gas left for the transaction.
                                    result, // Address of `ecrecover`.
                                    0x00, // Start of input.
                                    0x80, // Size of input.
                                    0x01, // Start of output.
                                    0x20 // Size of output.
                                )
                            )
                        // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
                        if iszero(returndatasize()) {
                            mstore(0x00, 0x8baa579f) // `InvalidSignature()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x60, 0) // Restore the zero slot.
                        mstore(0x40, m) // Restore the free memory pointer.
                    }
                }
                /// @dev Recovers the signer's address from a message digest `hash`,
                /// and the EIP-2098 short form signature defined by `r` and `vs`.
                function recover(bytes32 hash, bytes32 r, bytes32 vs) internal view returns (address result) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        let m := mload(0x40) // Cache the free memory pointer.
                        mstore(0x00, hash)
                        mstore(0x20, add(shr(255, vs), 27)) // `v`.
                        mstore(0x40, r)
                        mstore(0x60, shr(1, shl(1, vs))) // `s`.
                        result :=
                            mload(
                                staticcall(
                                    gas(), // Amount of gas left for the transaction.
                                    1, // Address of `ecrecover`.
                                    0x00, // Start of input.
                                    0x80, // Size of input.
                                    0x01, // Start of output.
                                    0x20 // Size of output.
                                )
                            )
                        // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
                        if iszero(returndatasize()) {
                            mstore(0x00, 0x8baa579f) // `InvalidSignature()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x60, 0) // Restore the zero slot.
                        mstore(0x40, m) // Restore the free memory pointer.
                    }
                }
                /// @dev Recovers the signer's address from a message digest `hash`,
                /// and the signature defined by `v`, `r`, `s`.
                function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s)
                    internal
                    view
                    returns (address result)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        let m := mload(0x40) // Cache the free memory pointer.
                        mstore(0x00, hash)
                        mstore(0x20, and(v, 0xff))
                        mstore(0x40, r)
                        mstore(0x60, s)
                        result :=
                            mload(
                                staticcall(
                                    gas(), // Amount of gas left for the transaction.
                                    1, // Address of `ecrecover`.
                                    0x00, // Start of input.
                                    0x80, // Size of input.
                                    0x01, // Start of output.
                                    0x20 // Size of output.
                                )
                            )
                        // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
                        if iszero(returndatasize()) {
                            mstore(0x00, 0x8baa579f) // `InvalidSignature()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x60, 0) // Restore the zero slot.
                        mstore(0x40, m) // Restore the free memory pointer.
                    }
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                   TRY-RECOVER OPERATIONS                   */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                // WARNING!
                // These functions will NOT revert upon recovery failure.
                // Instead, they will return the zero address upon recovery failure.
                // It is critical that the returned address is NEVER compared against
                // a zero address (e.g. an uninitialized address variable).
                /// @dev Recovers the signer's address from a message digest `hash`, and the `signature`.
                function tryRecover(bytes32 hash, bytes memory signature)
                    internal
                    view
                    returns (address result)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        result := 1
                        let m := mload(0x40) // Cache the free memory pointer.
                        for {} 1 {} {
                            mstore(0x00, hash)
                            mstore(0x40, mload(add(signature, 0x20))) // `r`.
                            if eq(mload(signature), 64) {
                                let vs := mload(add(signature, 0x40))
                                mstore(0x20, add(shr(255, vs), 27)) // `v`.
                                mstore(0x60, shr(1, shl(1, vs))) // `s`.
                                break
                            }
                            if eq(mload(signature), 65) {
                                mstore(0x20, byte(0, mload(add(signature, 0x60)))) // `v`.
                                mstore(0x60, mload(add(signature, 0x40))) // `s`.
                                break
                            }
                            result := 0
                            break
                        }
                        pop(
                            staticcall(
                                gas(), // Amount of gas left for the transaction.
                                result, // Address of `ecrecover`.
                                0x00, // Start of input.
                                0x80, // Size of input.
                                0x40, // Start of output.
                                0x20 // Size of output.
                            )
                        )
                        mstore(0x60, 0) // Restore the zero slot.
                        // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
                        result := mload(xor(0x60, returndatasize()))
                        mstore(0x40, m) // Restore the free memory pointer.
                    }
                }
                /// @dev Recovers the signer's address from a message digest `hash`, and the `signature`.
                function tryRecoverCalldata(bytes32 hash, bytes calldata signature)
                    internal
                    view
                    returns (address result)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        result := 1
                        let m := mload(0x40) // Cache the free memory pointer.
                        mstore(0x00, hash)
                        for {} 1 {} {
                            if eq(signature.length, 64) {
                                let vs := calldataload(add(signature.offset, 0x20))
                                mstore(0x20, add(shr(255, vs), 27)) // `v`.
                                mstore(0x40, calldataload(signature.offset)) // `r`.
                                mstore(0x60, shr(1, shl(1, vs))) // `s`.
                                break
                            }
                            if eq(signature.length, 65) {
                                mstore(0x20, byte(0, calldataload(add(signature.offset, 0x40)))) // `v`.
                                calldatacopy(0x40, signature.offset, 0x40) // Copy `r` and `s`.
                                break
                            }
                            result := 0
                            break
                        }
                        pop(
                            staticcall(
                                gas(), // Amount of gas left for the transaction.
                                result, // Address of `ecrecover`.
                                0x00, // Start of input.
                                0x80, // Size of input.
                                0x40, // Start of output.
                                0x20 // Size of output.
                            )
                        )
                        mstore(0x60, 0) // Restore the zero slot.
                        // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
                        result := mload(xor(0x60, returndatasize()))
                        mstore(0x40, m) // Restore the free memory pointer.
                    }
                }
                /// @dev Recovers the signer's address from a message digest `hash`,
                /// and the EIP-2098 short form signature defined by `r` and `vs`.
                function tryRecover(bytes32 hash, bytes32 r, bytes32 vs)
                    internal
                    view
                    returns (address result)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        let m := mload(0x40) // Cache the free memory pointer.
                        mstore(0x00, hash)
                        mstore(0x20, add(shr(255, vs), 27)) // `v`.
                        mstore(0x40, r)
                        mstore(0x60, shr(1, shl(1, vs))) // `s`.
                        pop(
                            staticcall(
                                gas(), // Amount of gas left for the transaction.
                                1, // Address of `ecrecover`.
                                0x00, // Start of input.
                                0x80, // Size of input.
                                0x40, // Start of output.
                                0x20 // Size of output.
                            )
                        )
                        mstore(0x60, 0) // Restore the zero slot.
                        // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
                        result := mload(xor(0x60, returndatasize()))
                        mstore(0x40, m) // Restore the free memory pointer.
                    }
                }
                /// @dev Recovers the signer's address from a message digest `hash`,
                /// and the signature defined by `v`, `r`, `s`.
                function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s)
                    internal
                    view
                    returns (address result)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        let m := mload(0x40) // Cache the free memory pointer.
                        mstore(0x00, hash)
                        mstore(0x20, and(v, 0xff))
                        mstore(0x40, r)
                        mstore(0x60, s)
                        pop(
                            staticcall(
                                gas(), // Amount of gas left for the transaction.
                                1, // Address of `ecrecover`.
                                0x00, // Start of input.
                                0x80, // Size of input.
                                0x40, // Start of output.
                                0x20 // Size of output.
                            )
                        )
                        mstore(0x60, 0) // Restore the zero slot.
                        // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
                        result := mload(xor(0x60, returndatasize()))
                        mstore(0x40, m) // Restore the free memory pointer.
                    }
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                     HASHING OPERATIONS                     */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Returns an Ethereum Signed Message, created from a `hash`.
                /// This produces a hash corresponding to the one signed with the
                /// [`eth_sign`](https://eth.wiki/json-rpc/API#eth_sign)
                /// JSON-RPC method as part of EIP-191.
                function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 result) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        mstore(0x20, hash) // Store into scratch space for keccak256.
                        mstore(0x00, "\\x00\\x00\\x00\\x00\\x19Ethereum Signed Message:\
            32") // 28 bytes.
                        result := keccak256(0x04, 0x3c) // `32 * 2 - (32 - 28) = 60 = 0x3c`.
                    }
                }
                /// @dev Returns an Ethereum Signed Message, created from `s`.
                /// This produces a hash corresponding to the one signed with the
                /// [`eth_sign`](https://eth.wiki/json-rpc/API#eth_sign)
                /// JSON-RPC method as part of EIP-191.
                /// Note: Supports lengths of `s` up to 999999 bytes.
                function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32 result) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        let sLength := mload(s)
                        let o := 0x20
                        mstore(o, "\\x19Ethereum Signed Message:\
            ") // 26 bytes, zero-right-padded.
                        mstore(0x00, 0x00)
                        // Convert the `s.length` to ASCII decimal representation: `base10(s.length)`.
                        for { let temp := sLength } 1 {} {
                            o := sub(o, 1)
                            mstore8(o, add(48, mod(temp, 10)))
                            temp := div(temp, 10)
                            if iszero(temp) { break }
                        }
                        let n := sub(0x3a, o) // Header length: `26 + 32 - o`.
                        // Throw an out-of-offset error (consumes all gas) if the header exceeds 32 bytes.
                        returndatacopy(returndatasize(), returndatasize(), gt(n, 0x20))
                        mstore(s, or(mload(0x00), mload(n))) // Temporarily store the header.
                        result := keccak256(add(s, sub(0x20, n)), add(n, sLength))
                        mstore(s, sLength) // Restore the length.
                    }
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                   EMPTY CALLDATA HELPERS                   */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Returns an empty calldata bytes.
                function emptySignature() internal pure returns (bytes calldata signature) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        signature.length := 0
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            /*
            ██████╗ ██████╗ ██████╗ ███╗   ███╗ █████╗ ████████╗██╗  ██╗
            ██╔══██╗██╔══██╗██╔══██╗████╗ ████║██╔══██╗╚══██╔══╝██║  ██║
            ██████╔╝██████╔╝██████╔╝██╔████╔██║███████║   ██║   ███████║
            ██╔═══╝ ██╔══██╗██╔══██╗██║╚██╔╝██║██╔══██║   ██║   ██╔══██║
            ██║     ██║  ██║██████╔╝██║ ╚═╝ ██║██║  ██║   ██║   ██║  ██║
            ╚═╝     ╚═╝  ╚═╝╚═════╝ ╚═╝     ╚═╝╚═╝  ╚═╝   ╚═╝   ╚═╝  ╚═╝
            ██╗   ██╗██████╗  ██████╗  ██████╗ ██╗  ██╗ ██╗ █████╗
            ██║   ██║██╔══██╗██╔════╝ ██╔═████╗╚██╗██╔╝███║██╔══██╗
            ██║   ██║██║  ██║███████╗ ██║██╔██║ ╚███╔╝ ╚██║╚█████╔╝
            ██║   ██║██║  ██║██╔═══██╗████╔╝██║ ██╔██╗  ██║██╔══██╗
            ╚██████╔╝██████╔╝╚██████╔╝╚██████╔╝██╔╝ ██╗ ██║╚█████╔╝
             ╚═════╝ ╚═════╝  ╚═════╝  ╚═════╝ ╚═╝  ╚═╝ ╚═╝ ╚════╝
            */
            import "./ud60x18/Casting.sol";
            import "./ud60x18/Constants.sol";
            import "./ud60x18/Conversions.sol";
            import "./ud60x18/Errors.sol";
            import "./ud60x18/Helpers.sol";
            import "./ud60x18/Math.sol";
            import "./ud60x18/ValueType.sol";
            // SPDX-License-Identifier: GPL-3.0-or-later
            pragma solidity >=0.8.19;
            import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
            import { Lockup, LockupLinear } from "../types/DataTypes.sol";
            import { ISablierV2Lockup } from "./ISablierV2Lockup.sol";
            /// @title ISablierV2LockupLinear
            /// @notice Creates and manages Lockup streams with linear streaming functions.
            interface ISablierV2LockupLinear is ISablierV2Lockup {
                /*//////////////////////////////////////////////////////////////////////////
                                                   EVENTS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Emitted when a stream is created.
                /// @param streamId The id of the newly created stream.
                /// @param funder The address which funded the stream.
                /// @param sender The address streaming the assets, with the ability to cancel the stream.
                /// @param recipient The address receiving the assets.
                /// @param amounts Struct containing (i) the deposit amount, (ii) the protocol fee amount, and (iii) the
                /// broker fee amount, all denoted in units of the asset's decimals.
                /// @param asset The contract address of the ERC-20 asset used for streaming.
                /// @param cancelable Boolean indicating whether the stream will be cancelable or not.
                /// @param transferable Boolean indicating whether the stream NFT is transferable or not.
                /// @param range Struct containing (i) the stream's start time, (ii) cliff time, and (iii) end time, all as Unix
                /// timestamps.
                /// @param broker The address of the broker who has helped create the stream, e.g. a front-end website.
                event CreateLockupLinearStream(
                    uint256 streamId,
                    address funder,
                    address indexed sender,
                    address indexed recipient,
                    Lockup.CreateAmounts amounts,
                    IERC20 indexed asset,
                    bool cancelable,
                    bool transferable,
                    LockupLinear.Range range,
                    address broker
                );
                /*//////////////////////////////////////////////////////////////////////////
                                             CONSTANT FUNCTIONS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Retrieves the stream's cliff time, which is a Unix timestamp.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function getCliffTime(uint256 streamId) external view returns (uint40 cliffTime);
                /// @notice Retrieves the stream's range, which is a struct containing (i) the stream's start time, (ii) cliff
                /// time, and (iii) end time, all as Unix timestamps.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function getRange(uint256 streamId) external view returns (LockupLinear.Range memory range);
                /// @notice Retrieves the stream entity.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function getStream(uint256 streamId) external view returns (LockupLinear.Stream memory stream);
                /// @notice Calculates the amount streamed to the recipient, denoted in units of the asset's decimals.
                ///
                /// When the stream is warm, the streaming function is:
                ///
                /// $$
                /// f(x) = x * d + c
                /// $$
                ///
                /// Where:
                ///
                /// - $x$ is the elapsed time divided by the stream's total duration.
                /// - $d$ is the deposited amount.
                /// - $c$ is the cliff amount.
                ///
                /// Upon cancellation of the stream, the amount streamed is calculated as the difference between the deposited
                /// amount and the refunded amount. Ultimately, when the stream becomes depleted, the streamed amount is equivalent
                /// to the total amount withdrawn.
                ///
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function streamedAmountOf(uint256 streamId) external view returns (uint128 streamedAmount);
                /*//////////////////////////////////////////////////////////////////////////
                                           NON-CONSTANT FUNCTIONS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Creates a stream by setting the start time to `block.timestamp`, and the end time to
                /// the sum of `block.timestamp` and `params.durations.total`. The stream is funded by `msg.sender` and is wrapped
                /// in an ERC-721 NFT.
                ///
                /// @dev Emits a {Transfer} and {CreateLockupLinearStream} event.
                ///
                /// Requirements:
                /// - All requirements in {createWithRange} must be met for the calculated parameters.
                ///
                /// @param params Struct encapsulating the function parameters, which are documented in {DataTypes}.
                /// @return streamId The id of the newly created stream.
                function createWithDurations(LockupLinear.CreateWithDurations calldata params)
                    external
                    returns (uint256 streamId);
                /// @notice Creates a stream with the provided start time and end time as the range. The stream is
                /// funded by `msg.sender` and is wrapped in an ERC-721 NFT.
                ///
                /// @dev Emits a {Transfer} and {CreateLockupLinearStream} event.
                ///
                /// Notes:
                /// - As long as the times are ordered, it is not an error for the start or the cliff time to be in the past.
                ///
                /// Requirements:
                /// - Must not be delegate called.
                /// - `params.totalAmount` must be greater than zero.
                /// - If set, `params.broker.fee` must not be greater than `MAX_FEE`.
                /// - `params.range.start` must be less than or equal to `params.range.cliff`.
                /// - `params.range.cliff` must be less than `params.range.end`.
                /// - `params.range.end` must be in the future.
                /// - `params.recipient` must not be the zero address.
                /// - `msg.sender` must have allowed this contract to spend at least `params.totalAmount` assets.
                ///
                /// @param params Struct encapsulating the function parameters, which are documented in {DataTypes}.
                /// @return streamId The id of the newly created stream.
                function createWithRange(LockupLinear.CreateWithRange calldata params) external returns (uint256 streamId);
            }
            // SPDX-License-Identifier: GPL-3.0-or-later
            pragma solidity >=0.8.19;
            import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
            import { UD2x18 } from "@prb/math/src/UD2x18.sol";
            import { UD60x18 } from "@prb/math/src/UD60x18.sol";
            // DataTypes.sol
            //
            // This file defines all structs used in V2 Core, most of which are organized under three namespaces:
            //
            // - Lockup
            // - LockupDynamic
            // - LockupLinear
            //
            // You will notice that some structs contain "slot" annotations - they are used to indicate the
            // storage layout of the struct. It is more gas efficient to group small data types together so
            // that they fit in a single 32-byte slot.
            /// @notice Struct encapsulating the broker parameters passed to the create functions. Both can be set to zero.
            /// @param account The address receiving the broker's fee.
            /// @param fee The broker's percentage fee from the total amount, denoted as a fixed-point number where 1e18 is 100%.
            struct Broker {
                address account;
                UD60x18 fee;
            }
            /// @notice Namespace for the structs used in both {SablierV2LockupLinear} and {SablierV2LockupDynamic}.
            library Lockup {
                /// @notice Struct encapsulating the deposit, withdrawn, and refunded amounts, all denoted in units
                /// of the asset's decimals.
                /// @dev Because the deposited and the withdrawn amount are often read together, declaring them in
                /// the same slot saves gas.
                /// @param deposited The initial amount deposited in the stream, net of fees.
                /// @param withdrawn The cumulative amount withdrawn from the stream.
                /// @param refunded The amount refunded to the sender. Unless the stream was canceled, this is always zero.
                struct Amounts {
                    // slot 0
                    uint128 deposited;
                    uint128 withdrawn;
                    // slot 1
                    uint128 refunded;
                }
                /// @notice Struct encapsulating the deposit amount, the protocol fee amount, and the broker fee amount,
                /// all denoted in units of the asset's decimals.
                /// @param deposit The amount to deposit in the stream.
                /// @param protocolFee The protocol fee amount.
                /// @param brokerFee The broker fee amount.
                struct CreateAmounts {
                    uint128 deposit;
                    uint128 protocolFee;
                    uint128 brokerFee;
                }
                /// @notice Enum representing the different statuses of a stream.
                /// @custom:value PENDING Stream created but not started; assets are in a pending state.
                /// @custom:value STREAMING Active stream where assets are currently being streamed.
                /// @custom:value SETTLED All assets have been streamed; recipient is due to withdraw them.
                /// @custom:value CANCELED Canceled stream; remaining assets await recipient's withdrawal.
                /// @custom:value DEPLETED Depleted stream; all assets have been withdrawn and/or refunded.
                enum Status {
                    PENDING, // value 0
                    STREAMING, // value 1
                    SETTLED, // value 2
                    CANCELED, // value 3
                    DEPLETED // value 4
                }
            }
            /// @notice Namespace for the structs used in {SablierV2LockupDynamic}.
            library LockupDynamic {
                /// @notice Struct encapsulating the parameters for the {SablierV2LockupDynamic.createWithDeltas} function.
                /// @param sender The address streaming the assets, with the ability to cancel the stream. It doesn't have to be the
                /// same as `msg.sender`.
                /// @param recipient The address receiving the assets.
                /// @param totalAmount The total amount of ERC-20 assets to be paid, including the stream deposit and any potential
                /// fees, all denoted in units of the asset's decimals.
                /// @param asset The contract address of the ERC-20 asset used for streaming.
                /// @param cancelable Indicates if the stream is cancelable.
                /// @param transferable Indicates if the stream NFT is transferable.
                /// @param broker Struct containing (i) the address of the broker assisting in creating the stream, and (ii) the
                /// percentage fee paid to the broker from `totalAmount`, denoted as a fixed-point number. Both can be set to zero.
                /// @param segments Segments with deltas used to compose the custom streaming curve. Milestones are calculated by
                /// starting from `block.timestamp` and adding each delta to the previous milestone.
                struct CreateWithDeltas {
                    address sender;
                    bool cancelable;
                    bool transferable;
                    address recipient;
                    uint128 totalAmount;
                    IERC20 asset;
                    Broker broker;
                    SegmentWithDelta[] segments;
                }
                /// @notice Struct encapsulating the parameters for the {SablierV2LockupDynamic.createWithMilestones}
                /// function.
                /// @param sender The address streaming the assets, with the ability to cancel the stream. It doesn't have to be the
                /// same as `msg.sender`.
                /// @param startTime The Unix timestamp indicating the stream's start.
                /// @param cancelable Indicates if the stream is cancelable.
                /// @param transferable Indicates if the stream NFT is transferable.
                /// @param recipient The address receiving the assets.
                /// @param totalAmount The total amount of ERC-20 assets to be paid, including the stream deposit and any potential
                /// fees, all denoted in units of the asset's decimals.
                /// @param asset The contract address of the ERC-20 asset used for streaming.
                /// @param broker Struct containing (i) the address of the broker assisting in creating the stream, and (ii) the
                /// percentage fee paid to the broker from `totalAmount`, denoted as a fixed-point number. Both can be set to zero.
                /// @param segments Segments used to compose the custom streaming curve.
                struct CreateWithMilestones {
                    address sender;
                    uint40 startTime;
                    bool cancelable;
                    bool transferable;
                    address recipient;
                    uint128 totalAmount;
                    IERC20 asset;
                    Broker broker;
                    Segment[] segments;
                }
                /// @notice Struct encapsulating the time range.
                /// @param start The Unix timestamp indicating the stream's start.
                /// @param end The Unix timestamp indicating the stream's end.
                struct Range {
                    uint40 start;
                    uint40 end;
                }
                /// @notice Segment struct used in the Lockup Dynamic stream.
                /// @param amount The amount of assets to be streamed in this segment, denoted in units of the asset's decimals.
                /// @param exponent The exponent of this segment, denoted as a fixed-point number.
                /// @param milestone The Unix timestamp indicating this segment's end.
                struct Segment {
                    // slot 0
                    uint128 amount;
                    UD2x18 exponent;
                    uint40 milestone;
                }
                /// @notice Segment struct used at runtime in {SablierV2LockupDynamic.createWithDeltas}.
                /// @param amount The amount of assets to be streamed in this segment, denoted in units of the asset's decimals.
                /// @param exponent The exponent of this segment, denoted as a fixed-point number.
                /// @param delta The time difference in seconds between this segment and the previous one.
                struct SegmentWithDelta {
                    uint128 amount;
                    UD2x18 exponent;
                    uint40 delta;
                }
                /// @notice Lockup Dynamic stream.
                /// @dev The fields are arranged like this to save gas via tight variable packing.
                /// @param sender The address streaming the assets, with the ability to cancel the stream.
                /// @param startTime The Unix timestamp indicating the stream's start.
                /// @param endTime The Unix timestamp indicating the stream's end.
                /// @param isCancelable Boolean indicating if the stream is cancelable.
                /// @param wasCanceled Boolean indicating if the stream was canceled.
                /// @param asset The contract address of the ERC-20 asset used for streaming.
                /// @param isDepleted Boolean indicating if the stream is depleted.
                /// @param isStream Boolean indicating if the struct entity exists.
                /// @param isTransferable Boolean indicating if the stream NFT is transferable.
                /// @param amounts Struct containing the deposit, withdrawn, and refunded amounts, all denoted in units of the
                /// asset's decimals.
                /// @param segments Segments used to compose the custom streaming curve.
                struct Stream {
                    // slot 0
                    address sender;
                    uint40 startTime;
                    uint40 endTime;
                    bool isCancelable;
                    bool wasCanceled;
                    // slot 1
                    IERC20 asset;
                    bool isDepleted;
                    bool isStream;
                    bool isTransferable;
                    // slot 2 and 3
                    Lockup.Amounts amounts;
                    // slots [4..n]
                    Segment[] segments;
                }
            }
            /// @notice Namespace for the structs used in {SablierV2LockupLinear}.
            library LockupLinear {
                /// @notice Struct encapsulating the parameters for the {SablierV2LockupLinear.createWithDurations} function.
                /// @param sender The address streaming the assets, with the ability to cancel the stream. It doesn't have to be the
                /// same as `msg.sender`.
                /// @param recipient The address receiving the assets.
                /// @param totalAmount The total amount of ERC-20 assets to be paid, including the stream deposit and any potential
                /// fees, all denoted in units of the asset's decimals.
                /// @param asset The contract address of the ERC-20 asset used for streaming.
                /// @param cancelable Indicates if the stream is cancelable.
                /// @param transferable Indicates if the stream NFT is transferable.
                /// @param durations Struct containing (i) cliff period duration and (ii) total stream duration, both in seconds.
                /// @param broker Struct containing (i) the address of the broker assisting in creating the stream, and (ii) the
                /// percentage fee paid to the broker from `totalAmount`, denoted as a fixed-point number. Both can be set to zero.
                struct CreateWithDurations {
                    address sender;
                    address recipient;
                    uint128 totalAmount;
                    IERC20 asset;
                    bool cancelable;
                    bool transferable;
                    Durations durations;
                    Broker broker;
                }
                /// @notice Struct encapsulating the parameters for the {SablierV2LockupLinear.createWithRange} function.
                /// @param sender The address streaming the assets, with the ability to cancel the stream. It doesn't have to be the
                /// same as `msg.sender`.
                /// @param recipient The address receiving the assets.
                /// @param totalAmount The total amount of ERC-20 assets to be paid, including the stream deposit and any potential
                /// fees, all denoted in units of the asset's decimals.
                /// @param asset The contract address of the ERC-20 asset used for streaming.
                /// @param cancelable Indicates if the stream is cancelable.
                /// @param transferable Indicates if the stream NFT is transferable.
                /// @param range Struct containing (i) the stream's start time, (ii) cliff time, and (iii) end time, all as Unix
                /// timestamps.
                /// @param broker Struct containing (i) the address of the broker assisting in creating the stream, and (ii) the
                /// percentage fee paid to the broker from `totalAmount`, denoted as a fixed-point number. Both can be set to zero.
                struct CreateWithRange {
                    address sender;
                    address recipient;
                    uint128 totalAmount;
                    IERC20 asset;
                    bool cancelable;
                    bool transferable;
                    Range range;
                    Broker broker;
                }
                /// @notice Struct encapsulating the cliff duration and the total duration.
                /// @param cliff The cliff duration in seconds.
                /// @param total The total duration in seconds.
                struct Durations {
                    uint40 cliff;
                    uint40 total;
                }
                /// @notice Struct encapsulating the time range.
                /// @param start The Unix timestamp for the stream's start.
                /// @param cliff The Unix timestamp for the cliff period's end.
                /// @param end The Unix timestamp for the stream's end.
                struct Range {
                    uint40 start;
                    uint40 cliff;
                    uint40 end;
                }
                /// @notice Lockup Linear stream.
                /// @dev The fields are arranged like this to save gas via tight variable packing.
                /// @param sender The address streaming the assets, with the ability to cancel the stream.
                /// @param startTime The Unix timestamp indicating the stream's start.
                /// @param cliffTime The Unix timestamp indicating the cliff period's end.
                /// @param isCancelable Boolean indicating if the stream is cancelable.
                /// @param wasCanceled Boolean indicating if the stream was canceled.
                /// @param asset The contract address of the ERC-20 asset used for streaming.
                /// @param endTime The Unix timestamp indicating the stream's end.
                /// @param isDepleted Boolean indicating if the stream is depleted.
                /// @param isStream Boolean indicating if the struct entity exists.
                /// @param isTransferable Boolean indicating if the stream NFT is transferable.
                /// @param amounts Struct containing the deposit, withdrawn, and refunded amounts, all denoted in units of the
                /// asset's decimals.
                struct Stream {
                    // slot 0
                    address sender;
                    uint40 startTime;
                    uint40 cliffTime;
                    bool isCancelable;
                    bool wasCanceled;
                    // slot 1
                    IERC20 asset;
                    uint40 endTime;
                    bool isDepleted;
                    bool isStream;
                    bool isTransferable;
                    // slot 2 and 3
                    Lockup.Amounts amounts;
                }
            }
            // SPDX-License-Identifier: AGPL-3.0-only
            pragma solidity =0.8.25;
            import { FixedPointMathLib } from "solady/utils/FixedPointMathLib.sol";
            library FjordMath {
                using FixedPointMathLib for uint256;
                /// @notice The scaling factor for all normalization/denormalization operations
                uint256 private constant SCALING_FACTOR = 18;
                /// @notice Normalize a value to the scaling factor
                /// @param value The value to normalize
                /// @param decimals The number of decimals of the value
                /// @dev No greater than check is required as > 18 decimals are not supported
                function normalize(uint256 value, uint8 decimals) internal pure returns (uint256) {
                    if (decimals < SCALING_FACTOR) {
                        return value * (10 ** (SCALING_FACTOR - decimals));
                    }
                    return value;
                }
                /// @notice Denormalizes a value back to its original value
                /// @param value The value to denormalize
                /// @param decimals The number of decimals of the value
                /// @dev No greater than check is required as > 18 decimals are not supported. This function rounds up post division.
                function denormalizeUp(uint256 value, uint8 decimals) internal pure returns (uint256) {
                    if (decimals < SCALING_FACTOR) {
                        return value.divUp(10 ** (SCALING_FACTOR - decimals));
                    }
                    return value;
                }
                /// @notice Denormalizes a value back to its original value
                /// @param value The value to denormalize
                /// @param decimals The number of decimals of the value
                /// @dev No greater than check is required as > 18 decimals are not supported. This function rounds down post division.
                function denormalizeDown(uint256 value, uint8 decimals) internal pure returns (uint256) {
                    if (decimals < SCALING_FACTOR) {
                        return value / (10 ** (SCALING_FACTOR - decimals));
                    }
                    return value;
                }
                ///@notice Returns the minimum swap threshold required for a purchase to be valid.
                ///@dev This is used to prevent rounding errors when making swaps between tokens of varying decimals.
                function mandatoryMinimumSwapIn(
                    uint8 shareDecimals,
                    uint8 assetDecimals
                )
                    public
                    pure
                    returns (uint256)
                {
                    if (shareDecimals > assetDecimals) {
                        return 10 ** (shareDecimals - assetDecimals + 2);
                    } else {
                        return 0;
                    }
                }
            }
            // SPDX-License-Identifier: AGPL-3.0-only
            pragma solidity =0.8.25;
            abstract contract FjordConstants {
                //-----------------------------------------------------------------------------------------------------------------------------------------
                // BASE POOL OFFSETS ONLY
                //-----------------------------------------------------------------------------------------------------------------------------------------
                uint256 internal constant OWNER_OFFSET = 0; // Increment offset by 20
                uint256 internal constant SHARE_TOKEN_OFFSET = 20; // Increment offset by 20
                uint256 internal constant ASSET_TOKEN_OFFSET = 40; // Increment offset by 20
                uint256 internal constant FEE_RECIPIENT_OFFSET = 60; // Increment offset by 20
                uint256 internal constant DELEGATE_SIGNER_OFFSET = 80; // Increment offset by 20
                uint256 internal constant SHARES_FOR_SALE_OFFSET = 100; // Increment offset by 32
                uint256 internal constant MINIMUM_TOKENS_FOR_SALE_OFFSET = 132; // Increment offset by 32
                uint256 internal constant MAXIMUM_TOKENS_PER_USER_OFFSET = 164; // Increment offset by 32
                uint256 internal constant MINIMUM_TOKENS_PER_USER_OFFSET = 196; // Increment offset by 32
                uint256 internal constant SWAP_FEE_WAD_OFFSET = 228; // Increment offset by 8
                uint256 internal constant PLATFORM_FEE_WAD_OFFSET = 236; // Increment offset by 8
                uint256 internal constant SALE_START_OFFSET = 244; // Increment offset by 5
                uint256 internal constant SALE_END_OFFSET = 249; // Increment offset by 5
                uint256 internal constant REDEMPTION_DELAY_OFFSET = 254; // Increment offset by 5
                uint256 internal constant VEST_END_OFFSET = 259; // Increment offset by 5
                uint256 internal constant VEST_CLIFF_OFFSET = 264; // Increment offset by 5
                uint256 internal constant SHARE_TOKEN_DECIMALS_OFFSET = 269; // Increment offset by 1
                uint256 internal constant ASSET_TOKEN_DECIMALS_OFFSET = 270; // Increment offset by 1
                uint256 internal constant ANTISNIPE_ENABLED_OFFSET = 271; // Increment offset by 1
                uint256 internal constant WHITELIST_MERKLE_ROOT_OFFSET = 272; // Increment offset by 32
                //-----------------------------------------------------------------------------------------------------------------------------------------
                // FIXED PRICE OFFSETS ONLY
                //-----------------------------------------------------------------------------------------------------------------------------------------
                uint256 internal constant ASSETS_PER_TOKEN_OFFSET = 304; // Increment offset by 32
                uint256 internal constant TIER_DATA_LENGTH_OFFSET = 336; // Increment offset by 32
                uint256 internal constant TIERS_OFFSET = 368; // Increment offset by 32
                uint256 internal constant EMPTY_TIER_ARRAY_OFFSET = 64; // Size of an empty encoded Tier[] struct
                uint256 internal constant TIER_BASE_OFFSET = 128; // Size of an encoded Tier struct (uint256,uint256,uint256,uint256)
                //-----------------------------------------------------------------------------------------------------------------------------------------
                //OVERFLOW OFFSETS ONLY
                //-----------------------------------------------------------------------------------------------------------------------------------------
                uint256 internal constant ASSET_HARD_CAP_OFFSET = 304; // Increment offset by 32
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "./Errors.sol" as CastingErrors;
            import { MAX_UINT128, MAX_UINT40 } from "../Common.sol";
            import { uMAX_SD1x18 } from "../sd1x18/Constants.sol";
            import { SD1x18 } from "../sd1x18/ValueType.sol";
            import { uMAX_SD21x18 } from "../sd21x18/Constants.sol";
            import { SD21x18 } from "../sd21x18/ValueType.sol";
            import { uMAX_SD59x18 } from "../sd59x18/Constants.sol";
            import { SD59x18 } from "../sd59x18/ValueType.sol";
            import { uMAX_UD2x18 } from "../ud2x18/Constants.sol";
            import { uMAX_UD21x18 } from "../ud21x18/Constants.sol";
            import { UD2x18 } from "../ud2x18/ValueType.sol";
            import { UD21x18 } from "../ud21x18/ValueType.sol";
            import { UD60x18 } from "./ValueType.sol";
            /// @notice Casts a UD60x18 number into SD1x18.
            /// @dev Requirements:
            /// - x ≤ uMAX_SD1x18
            function intoSD1x18(UD60x18 x) pure returns (SD1x18 result) {
                uint256 xUint = UD60x18.unwrap(x);
                if (xUint > uint256(int256(uMAX_SD1x18))) {
                    revert CastingErrors.PRBMath_UD60x18_IntoSD1x18_Overflow(x);
                }
                result = SD1x18.wrap(int64(uint64(xUint)));
            }
            /// @notice Casts a UD60x18 number into SD21x18.
            /// @dev Requirements:
            /// - x ≤ uMAX_SD21x18
            function intoSD21x18(UD60x18 x) pure returns (SD21x18 result) {
                uint256 xUint = UD60x18.unwrap(x);
                if (xUint > uint256(int256(uMAX_SD21x18))) {
                    revert CastingErrors.PRBMath_UD60x18_IntoSD21x18_Overflow(x);
                }
                result = SD21x18.wrap(int128(uint128(xUint)));
            }
            /// @notice Casts a UD60x18 number into UD2x18.
            /// @dev Requirements:
            /// - x ≤ uMAX_UD2x18
            function intoUD2x18(UD60x18 x) pure returns (UD2x18 result) {
                uint256 xUint = UD60x18.unwrap(x);
                if (xUint > uMAX_UD2x18) {
                    revert CastingErrors.PRBMath_UD60x18_IntoUD2x18_Overflow(x);
                }
                result = UD2x18.wrap(uint64(xUint));
            }
            /// @notice Casts a UD60x18 number into UD21x18.
            /// @dev Requirements:
            /// - x ≤ uMAX_UD21x18
            function intoUD21x18(UD60x18 x) pure returns (UD21x18 result) {
                uint256 xUint = UD60x18.unwrap(x);
                if (xUint > uMAX_UD21x18) {
                    revert CastingErrors.PRBMath_UD60x18_IntoUD21x18_Overflow(x);
                }
                result = UD21x18.wrap(uint128(xUint));
            }
            /// @notice Casts a UD60x18 number into SD59x18.
            /// @dev Requirements:
            /// - x ≤ uMAX_SD59x18
            function intoSD59x18(UD60x18 x) pure returns (SD59x18 result) {
                uint256 xUint = UD60x18.unwrap(x);
                if (xUint > uint256(uMAX_SD59x18)) {
                    revert CastingErrors.PRBMath_UD60x18_IntoSD59x18_Overflow(x);
                }
                result = SD59x18.wrap(int256(xUint));
            }
            /// @notice Casts a UD60x18 number into uint128.
            /// @dev This is basically an alias for {unwrap}.
            function intoUint256(UD60x18 x) pure returns (uint256 result) {
                result = UD60x18.unwrap(x);
            }
            /// @notice Casts a UD60x18 number into uint128.
            /// @dev Requirements:
            /// - x ≤ MAX_UINT128
            function intoUint128(UD60x18 x) pure returns (uint128 result) {
                uint256 xUint = UD60x18.unwrap(x);
                if (xUint > MAX_UINT128) {
                    revert CastingErrors.PRBMath_UD60x18_IntoUint128_Overflow(x);
                }
                result = uint128(xUint);
            }
            /// @notice Casts a UD60x18 number into uint40.
            /// @dev Requirements:
            /// - x ≤ MAX_UINT40
            function intoUint40(UD60x18 x) pure returns (uint40 result) {
                uint256 xUint = UD60x18.unwrap(x);
                if (xUint > MAX_UINT40) {
                    revert CastingErrors.PRBMath_UD60x18_IntoUint40_Overflow(x);
                }
                result = uint40(xUint);
            }
            /// @notice Alias for {wrap}.
            function ud(uint256 x) pure returns (UD60x18 result) {
                result = UD60x18.wrap(x);
            }
            /// @notice Alias for {wrap}.
            function ud60x18(uint256 x) pure returns (UD60x18 result) {
                result = UD60x18.wrap(x);
            }
            /// @notice Unwraps a UD60x18 number into uint256.
            function unwrap(UD60x18 x) pure returns (uint256 result) {
                result = UD60x18.unwrap(x);
            }
            /// @notice Wraps a uint256 number into the UD60x18 value type.
            function wrap(uint256 x) pure returns (UD60x18 result) {
                result = UD60x18.wrap(x);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { UD60x18 } from "./ValueType.sol";
            // NOTICE: the "u" prefix stands for "unwrapped".
            /// @dev Euler's number as a UD60x18 number.
            UD60x18 constant E = UD60x18.wrap(2_718281828459045235);
            /// @dev The maximum input permitted in {exp}.
            uint256 constant uEXP_MAX_INPUT = 133_084258667509499440;
            UD60x18 constant EXP_MAX_INPUT = UD60x18.wrap(uEXP_MAX_INPUT);
            /// @dev The maximum input permitted in {exp2}.
            uint256 constant uEXP2_MAX_INPUT = 192e18 - 1;
            UD60x18 constant EXP2_MAX_INPUT = UD60x18.wrap(uEXP2_MAX_INPUT);
            /// @dev Half the UNIT number.
            uint256 constant uHALF_UNIT = 0.5e18;
            UD60x18 constant HALF_UNIT = UD60x18.wrap(uHALF_UNIT);
            /// @dev $log_2(10)$ as a UD60x18 number.
            uint256 constant uLOG2_10 = 3_321928094887362347;
            UD60x18 constant LOG2_10 = UD60x18.wrap(uLOG2_10);
            /// @dev $log_2(e)$ as a UD60x18 number.
            uint256 constant uLOG2_E = 1_442695040888963407;
            UD60x18 constant LOG2_E = UD60x18.wrap(uLOG2_E);
            /// @dev The maximum value a UD60x18 number can have.
            uint256 constant uMAX_UD60x18 = 115792089237316195423570985008687907853269984665640564039457_584007913129639935;
            UD60x18 constant MAX_UD60x18 = UD60x18.wrap(uMAX_UD60x18);
            /// @dev The maximum whole value a UD60x18 number can have.
            uint256 constant uMAX_WHOLE_UD60x18 = 115792089237316195423570985008687907853269984665640564039457_000000000000000000;
            UD60x18 constant MAX_WHOLE_UD60x18 = UD60x18.wrap(uMAX_WHOLE_UD60x18);
            /// @dev PI as a UD60x18 number.
            UD60x18 constant PI = UD60x18.wrap(3_141592653589793238);
            /// @dev The unit number, which gives the decimal precision of UD60x18.
            uint256 constant uUNIT = 1e18;
            UD60x18 constant UNIT = UD60x18.wrap(uUNIT);
            /// @dev The unit number squared.
            uint256 constant uUNIT_SQUARED = 1e36;
            UD60x18 constant UNIT_SQUARED = UD60x18.wrap(uUNIT_SQUARED);
            /// @dev Zero as a UD60x18 number.
            UD60x18 constant ZERO = UD60x18.wrap(0);
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { uMAX_UD60x18, uUNIT } from "./Constants.sol";
            import { PRBMath_UD60x18_Convert_Overflow } from "./Errors.sol";
            import { UD60x18 } from "./ValueType.sol";
            /// @notice Converts a UD60x18 number to a simple integer by dividing it by `UNIT`.
            /// @dev The result is rounded toward zero.
            /// @param x The UD60x18 number to convert.
            /// @return result The same number in basic integer form.
            function convert(UD60x18 x) pure returns (uint256 result) {
                result = UD60x18.unwrap(x) / uUNIT;
            }
            /// @notice Converts a simple integer to UD60x18 by multiplying it by `UNIT`.
            ///
            /// @dev Requirements:
            /// - x ≤ MAX_UD60x18 / UNIT
            ///
            /// @param x The basic integer to convert.
            /// @return result The same number converted to UD60x18.
            function convert(uint256 x) pure returns (UD60x18 result) {
                if (x > uMAX_UD60x18 / uUNIT) {
                    revert PRBMath_UD60x18_Convert_Overflow(x);
                }
                unchecked {
                    result = UD60x18.wrap(x * uUNIT);
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { UD60x18 } from "./ValueType.sol";
            /// @notice Thrown when ceiling a number overflows UD60x18.
            error PRBMath_UD60x18_Ceil_Overflow(UD60x18 x);
            /// @notice Thrown when converting a basic integer to the fixed-point format overflows UD60x18.
            error PRBMath_UD60x18_Convert_Overflow(uint256 x);
            /// @notice Thrown when taking the natural exponent of a base greater than 133_084258667509499441.
            error PRBMath_UD60x18_Exp_InputTooBig(UD60x18 x);
            /// @notice Thrown when taking the binary exponent of a base greater than 192e18.
            error PRBMath_UD60x18_Exp2_InputTooBig(UD60x18 x);
            /// @notice Thrown when taking the geometric mean of two numbers and multiplying them overflows UD60x18.
            error PRBMath_UD60x18_Gm_Overflow(UD60x18 x, UD60x18 y);
            /// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD1x18.
            error PRBMath_UD60x18_IntoSD1x18_Overflow(UD60x18 x);
            /// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD21x18.
            error PRBMath_UD60x18_IntoSD21x18_Overflow(UD60x18 x);
            /// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD59x18.
            error PRBMath_UD60x18_IntoSD59x18_Overflow(UD60x18 x);
            /// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in UD2x18.
            error PRBMath_UD60x18_IntoUD2x18_Overflow(UD60x18 x);
            /// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in UD21x18.
            error PRBMath_UD60x18_IntoUD21x18_Overflow(UD60x18 x);
            /// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint128.
            error PRBMath_UD60x18_IntoUint128_Overflow(UD60x18 x);
            /// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint40.
            error PRBMath_UD60x18_IntoUint40_Overflow(UD60x18 x);
            /// @notice Thrown when taking the logarithm of a number less than UNIT.
            error PRBMath_UD60x18_Log_InputTooSmall(UD60x18 x);
            /// @notice Thrown when calculating the square root overflows UD60x18.
            error PRBMath_UD60x18_Sqrt_Overflow(UD60x18 x);
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { wrap } from "./Casting.sol";
            import { UD60x18 } from "./ValueType.sol";
            /// @notice Implements the checked addition operation (+) in the UD60x18 type.
            function add(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                result = wrap(x.unwrap() + y.unwrap());
            }
            /// @notice Implements the AND (&) bitwise operation in the UD60x18 type.
            function and(UD60x18 x, uint256 bits) pure returns (UD60x18 result) {
                result = wrap(x.unwrap() & bits);
            }
            /// @notice Implements the AND (&) bitwise operation in the UD60x18 type.
            function and2(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                result = wrap(x.unwrap() & y.unwrap());
            }
            /// @notice Implements the equal operation (==) in the UD60x18 type.
            function eq(UD60x18 x, UD60x18 y) pure returns (bool result) {
                result = x.unwrap() == y.unwrap();
            }
            /// @notice Implements the greater than operation (>) in the UD60x18 type.
            function gt(UD60x18 x, UD60x18 y) pure returns (bool result) {
                result = x.unwrap() > y.unwrap();
            }
            /// @notice Implements the greater than or equal to operation (>=) in the UD60x18 type.
            function gte(UD60x18 x, UD60x18 y) pure returns (bool result) {
                result = x.unwrap() >= y.unwrap();
            }
            /// @notice Implements a zero comparison check function in the UD60x18 type.
            function isZero(UD60x18 x) pure returns (bool result) {
                // This wouldn't work if x could be negative.
                result = x.unwrap() == 0;
            }
            /// @notice Implements the left shift operation (<<) in the UD60x18 type.
            function lshift(UD60x18 x, uint256 bits) pure returns (UD60x18 result) {
                result = wrap(x.unwrap() << bits);
            }
            /// @notice Implements the lower than operation (<) in the UD60x18 type.
            function lt(UD60x18 x, UD60x18 y) pure returns (bool result) {
                result = x.unwrap() < y.unwrap();
            }
            /// @notice Implements the lower than or equal to operation (<=) in the UD60x18 type.
            function lte(UD60x18 x, UD60x18 y) pure returns (bool result) {
                result = x.unwrap() <= y.unwrap();
            }
            /// @notice Implements the checked modulo operation (%) in the UD60x18 type.
            function mod(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                result = wrap(x.unwrap() % y.unwrap());
            }
            /// @notice Implements the not equal operation (!=) in the UD60x18 type.
            function neq(UD60x18 x, UD60x18 y) pure returns (bool result) {
                result = x.unwrap() != y.unwrap();
            }
            /// @notice Implements the NOT (~) bitwise operation in the UD60x18 type.
            function not(UD60x18 x) pure returns (UD60x18 result) {
                result = wrap(~x.unwrap());
            }
            /// @notice Implements the OR (|) bitwise operation in the UD60x18 type.
            function or(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                result = wrap(x.unwrap() | y.unwrap());
            }
            /// @notice Implements the right shift operation (>>) in the UD60x18 type.
            function rshift(UD60x18 x, uint256 bits) pure returns (UD60x18 result) {
                result = wrap(x.unwrap() >> bits);
            }
            /// @notice Implements the checked subtraction operation (-) in the UD60x18 type.
            function sub(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                result = wrap(x.unwrap() - y.unwrap());
            }
            /// @notice Implements the unchecked addition operation (+) in the UD60x18 type.
            function uncheckedAdd(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                unchecked {
                    result = wrap(x.unwrap() + y.unwrap());
                }
            }
            /// @notice Implements the unchecked subtraction operation (-) in the UD60x18 type.
            function uncheckedSub(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                unchecked {
                    result = wrap(x.unwrap() - y.unwrap());
                }
            }
            /// @notice Implements the XOR (^) bitwise operation in the UD60x18 type.
            function xor(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                result = wrap(x.unwrap() ^ y.unwrap());
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "../Common.sol" as Common;
            import "./Errors.sol" as Errors;
            import { wrap } from "./Casting.sol";
            import {
                uEXP_MAX_INPUT,
                uEXP2_MAX_INPUT,
                uHALF_UNIT,
                uLOG2_10,
                uLOG2_E,
                uMAX_UD60x18,
                uMAX_WHOLE_UD60x18,
                UNIT,
                uUNIT,
                uUNIT_SQUARED,
                ZERO
            } from "./Constants.sol";
            import { UD60x18 } from "./ValueType.sol";
            /*//////////////////////////////////////////////////////////////////////////
                                        MATHEMATICAL FUNCTIONS
            //////////////////////////////////////////////////////////////////////////*/
            /// @notice Calculates the arithmetic average of x and y using the following formula:
            ///
            /// $$
            /// avg(x, y) = (x & y) + ((xUint ^ yUint) / 2)
            /// $$
            ///
            /// In English, this is what this formula does:
            ///
            /// 1. AND x and y.
            /// 2. Calculate half of XOR x and y.
            /// 3. Add the two results together.
            ///
            /// This technique is known as SWAR, which stands for "SIMD within a register". You can read more about it here:
            /// https://devblogs.microsoft.com/oldnewthing/20220207-00/?p=106223
            ///
            /// @dev Notes:
            /// - The result is rounded toward zero.
            ///
            /// @param x The first operand as a UD60x18 number.
            /// @param y The second operand as a UD60x18 number.
            /// @return result The arithmetic average as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function avg(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                uint256 xUint = x.unwrap();
                uint256 yUint = y.unwrap();
                unchecked {
                    result = wrap((xUint & yUint) + ((xUint ^ yUint) >> 1));
                }
            }
            /// @notice Yields the smallest whole number greater than or equal to x.
            ///
            /// @dev This is optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional
            /// counterparts. See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
            ///
            /// Requirements:
            /// - x ≤ MAX_WHOLE_UD60x18
            ///
            /// @param x The UD60x18 number to ceil.
            /// @return result The smallest whole number greater than or equal to x, as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function ceil(UD60x18 x) pure returns (UD60x18 result) {
                uint256 xUint = x.unwrap();
                if (xUint > uMAX_WHOLE_UD60x18) {
                    revert Errors.PRBMath_UD60x18_Ceil_Overflow(x);
                }
                assembly ("memory-safe") {
                    // Equivalent to `x % UNIT`.
                    let remainder := mod(x, uUNIT)
                    // Equivalent to `UNIT - remainder`.
                    let delta := sub(uUNIT, remainder)
                    // Equivalent to `x + remainder > 0 ? delta : 0`.
                    result := add(x, mul(delta, gt(remainder, 0)))
                }
            }
            /// @notice Divides two UD60x18 numbers, returning a new UD60x18 number.
            ///
            /// @dev Uses {Common.mulDiv} to enable overflow-safe multiplication and division.
            ///
            /// Notes:
            /// - Refer to the notes in {Common.mulDiv}.
            ///
            /// Requirements:
            /// - Refer to the requirements in {Common.mulDiv}.
            ///
            /// @param x The numerator as a UD60x18 number.
            /// @param y The denominator as a UD60x18 number.
            /// @return result The quotient as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function div(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                result = wrap(Common.mulDiv(x.unwrap(), uUNIT, y.unwrap()));
            }
            /// @notice Calculates the natural exponent of x using the following formula:
            ///
            /// $$
            /// e^x = 2^{x * log_2{e}}
            /// $$
            ///
            /// @dev Requirements:
            /// - x ≤ 133_084258667509499440
            ///
            /// @param x The exponent as a UD60x18 number.
            /// @return result The result as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function exp(UD60x18 x) pure returns (UD60x18 result) {
                uint256 xUint = x.unwrap();
                // This check prevents values greater than 192e18 from being passed to {exp2}.
                if (xUint > uEXP_MAX_INPUT) {
                    revert Errors.PRBMath_UD60x18_Exp_InputTooBig(x);
                }
                unchecked {
                    // Inline the fixed-point multiplication to save gas.
                    uint256 doubleUnitProduct = xUint * uLOG2_E;
                    result = exp2(wrap(doubleUnitProduct / uUNIT));
                }
            }
            /// @notice Calculates the binary exponent of x using the binary fraction method.
            ///
            /// @dev See https://ethereum.stackexchange.com/q/79903/24693
            ///
            /// Requirements:
            /// - x < 192e18
            /// - The result must fit in UD60x18.
            ///
            /// @param x The exponent as a UD60x18 number.
            /// @return result The result as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function exp2(UD60x18 x) pure returns (UD60x18 result) {
                uint256 xUint = x.unwrap();
                // Numbers greater than or equal to 192e18 don't fit in the 192.64-bit format.
                if (xUint > uEXP2_MAX_INPUT) {
                    revert Errors.PRBMath_UD60x18_Exp2_InputTooBig(x);
                }
                // Convert x to the 192.64-bit fixed-point format.
                uint256 x_192x64 = (xUint << 64) / uUNIT;
                // Pass x to the {Common.exp2} function, which uses the 192.64-bit fixed-point number representation.
                result = wrap(Common.exp2(x_192x64));
            }
            /// @notice Yields the greatest whole number less than or equal to x.
            /// @dev Optimized for fractional value inputs, because every whole value has (1e18 - 1) fractional counterparts.
            /// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
            /// @param x The UD60x18 number to floor.
            /// @return result The greatest whole number less than or equal to x, as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function floor(UD60x18 x) pure returns (UD60x18 result) {
                assembly ("memory-safe") {
                    // Equivalent to `x % UNIT`.
                    let remainder := mod(x, uUNIT)
                    // Equivalent to `x - remainder > 0 ? remainder : 0)`.
                    result := sub(x, mul(remainder, gt(remainder, 0)))
                }
            }
            /// @notice Yields the excess beyond the floor of x using the odd function definition.
            /// @dev See https://en.wikipedia.org/wiki/Fractional_part.
            /// @param x The UD60x18 number to get the fractional part of.
            /// @return result The fractional part of x as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function frac(UD60x18 x) pure returns (UD60x18 result) {
                assembly ("memory-safe") {
                    result := mod(x, uUNIT)
                }
            }
            /// @notice Calculates the geometric mean of x and y, i.e. $\\sqrt{x * y}$, rounding down.
            ///
            /// @dev Requirements:
            /// - x * y must fit in UD60x18.
            ///
            /// @param x The first operand as a UD60x18 number.
            /// @param y The second operand as a UD60x18 number.
            /// @return result The result as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function gm(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                uint256 xUint = x.unwrap();
                uint256 yUint = y.unwrap();
                if (xUint == 0 || yUint == 0) {
                    return ZERO;
                }
                unchecked {
                    // Checking for overflow this way is faster than letting Solidity do it.
                    uint256 xyUint = xUint * yUint;
                    if (xyUint / xUint != yUint) {
                        revert Errors.PRBMath_UD60x18_Gm_Overflow(x, y);
                    }
                    // We don't need to multiply the result by `UNIT` here because the x*y product picked up a factor of `UNIT`
                    // during multiplication. See the comments in {Common.sqrt}.
                    result = wrap(Common.sqrt(xyUint));
                }
            }
            /// @notice Calculates the inverse of x.
            ///
            /// @dev Notes:
            /// - The result is rounded toward zero.
            ///
            /// Requirements:
            /// - x must not be zero.
            ///
            /// @param x The UD60x18 number for which to calculate the inverse.
            /// @return result The inverse as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function inv(UD60x18 x) pure returns (UD60x18 result) {
                unchecked {
                    result = wrap(uUNIT_SQUARED / x.unwrap());
                }
            }
            /// @notice Calculates the natural logarithm of x using the following formula:
            ///
            /// $$
            /// ln{x} = log_2{x} / log_2{e}
            /// $$
            ///
            /// @dev Notes:
            /// - Refer to the notes in {log2}.
            /// - The precision isn't sufficiently fine-grained to return exactly `UNIT` when the input is `E`.
            ///
            /// Requirements:
            /// - Refer to the requirements in {log2}.
            ///
            /// @param x The UD60x18 number for which to calculate the natural logarithm.
            /// @return result The natural logarithm as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function ln(UD60x18 x) pure returns (UD60x18 result) {
                unchecked {
                    // Inline the fixed-point multiplication to save gas. This is overflow-safe because the maximum value that
                    // {log2} can return is ~196_205294292027477728.
                    result = wrap(log2(x).unwrap() * uUNIT / uLOG2_E);
                }
            }
            /// @notice Calculates the common logarithm of x using the following formula:
            ///
            /// $$
            /// log_{10}{x} = log_2{x} / log_2{10}
            /// $$
            ///
            /// However, if x is an exact power of ten, a hard coded value is returned.
            ///
            /// @dev Notes:
            /// - Refer to the notes in {log2}.
            ///
            /// Requirements:
            /// - Refer to the requirements in {log2}.
            ///
            /// @param x The UD60x18 number for which to calculate the common logarithm.
            /// @return result The common logarithm as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function log10(UD60x18 x) pure returns (UD60x18 result) {
                uint256 xUint = x.unwrap();
                if (xUint < uUNIT) {
                    revert Errors.PRBMath_UD60x18_Log_InputTooSmall(x);
                }
                // Note that the `mul` in this assembly block is the standard multiplication operation, not {UD60x18.mul}.
                // prettier-ignore
                assembly ("memory-safe") {
                    switch x
                    case 1 { result := mul(uUNIT, sub(0, 18)) }
                    case 10 { result := mul(uUNIT, sub(1, 18)) }
                    case 100 { result := mul(uUNIT, sub(2, 18)) }
                    case 1000 { result := mul(uUNIT, sub(3, 18)) }
                    case 10000 { result := mul(uUNIT, sub(4, 18)) }
                    case 100000 { result := mul(uUNIT, sub(5, 18)) }
                    case 1000000 { result := mul(uUNIT, sub(6, 18)) }
                    case 10000000 { result := mul(uUNIT, sub(7, 18)) }
                    case 100000000 { result := mul(uUNIT, sub(8, 18)) }
                    case 1000000000 { result := mul(uUNIT, sub(9, 18)) }
                    case 10000000000 { result := mul(uUNIT, sub(10, 18)) }
                    case 100000000000 { result := mul(uUNIT, sub(11, 18)) }
                    case 1000000000000 { result := mul(uUNIT, sub(12, 18)) }
                    case 10000000000000 { result := mul(uUNIT, sub(13, 18)) }
                    case 100000000000000 { result := mul(uUNIT, sub(14, 18)) }
                    case 1000000000000000 { result := mul(uUNIT, sub(15, 18)) }
                    case 10000000000000000 { result := mul(uUNIT, sub(16, 18)) }
                    case 100000000000000000 { result := mul(uUNIT, sub(17, 18)) }
                    case 1000000000000000000 { result := 0 }
                    case 10000000000000000000 { result := uUNIT }
                    case 100000000000000000000 { result := mul(uUNIT, 2) }
                    case 1000000000000000000000 { result := mul(uUNIT, 3) }
                    case 10000000000000000000000 { result := mul(uUNIT, 4) }
                    case 100000000000000000000000 { result := mul(uUNIT, 5) }
                    case 1000000000000000000000000 { result := mul(uUNIT, 6) }
                    case 10000000000000000000000000 { result := mul(uUNIT, 7) }
                    case 100000000000000000000000000 { result := mul(uUNIT, 8) }
                    case 1000000000000000000000000000 { result := mul(uUNIT, 9) }
                    case 10000000000000000000000000000 { result := mul(uUNIT, 10) }
                    case 100000000000000000000000000000 { result := mul(uUNIT, 11) }
                    case 1000000000000000000000000000000 { result := mul(uUNIT, 12) }
                    case 10000000000000000000000000000000 { result := mul(uUNIT, 13) }
                    case 100000000000000000000000000000000 { result := mul(uUNIT, 14) }
                    case 1000000000000000000000000000000000 { result := mul(uUNIT, 15) }
                    case 10000000000000000000000000000000000 { result := mul(uUNIT, 16) }
                    case 100000000000000000000000000000000000 { result := mul(uUNIT, 17) }
                    case 1000000000000000000000000000000000000 { result := mul(uUNIT, 18) }
                    case 10000000000000000000000000000000000000 { result := mul(uUNIT, 19) }
                    case 100000000000000000000000000000000000000 { result := mul(uUNIT, 20) }
                    case 1000000000000000000000000000000000000000 { result := mul(uUNIT, 21) }
                    case 10000000000000000000000000000000000000000 { result := mul(uUNIT, 22) }
                    case 100000000000000000000000000000000000000000 { result := mul(uUNIT, 23) }
                    case 1000000000000000000000000000000000000000000 { result := mul(uUNIT, 24) }
                    case 10000000000000000000000000000000000000000000 { result := mul(uUNIT, 25) }
                    case 100000000000000000000000000000000000000000000 { result := mul(uUNIT, 26) }
                    case 1000000000000000000000000000000000000000000000 { result := mul(uUNIT, 27) }
                    case 10000000000000000000000000000000000000000000000 { result := mul(uUNIT, 28) }
                    case 100000000000000000000000000000000000000000000000 { result := mul(uUNIT, 29) }
                    case 1000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 30) }
                    case 10000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 31) }
                    case 100000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 32) }
                    case 1000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 33) }
                    case 10000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 34) }
                    case 100000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 35) }
                    case 1000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 36) }
                    case 10000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 37) }
                    case 100000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 38) }
                    case 1000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 39) }
                    case 10000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 40) }
                    case 100000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 41) }
                    case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 42) }
                    case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 43) }
                    case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 44) }
                    case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 45) }
                    case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 46) }
                    case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 47) }
                    case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 48) }
                    case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 49) }
                    case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 50) }
                    case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 51) }
                    case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 52) }
                    case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 53) }
                    case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 54) }
                    case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 55) }
                    case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 56) }
                    case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 57) }
                    case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 58) }
                    case 100000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 59) }
                    default { result := uMAX_UD60x18 }
                }
                if (result.unwrap() == uMAX_UD60x18) {
                    unchecked {
                        // Inline the fixed-point division to save gas.
                        result = wrap(log2(x).unwrap() * uUNIT / uLOG2_10);
                    }
                }
            }
            /// @notice Calculates the binary logarithm of x using the iterative approximation algorithm:
            ///
            /// $$
            /// log_2{x} = n + log_2{y}, \\text{ where } y = x*2^{-n}, \\ y \\in [1, 2)
            /// $$
            ///
            /// For $0 \\leq x \\lt 1$, the input is inverted:
            ///
            /// $$
            /// log_2{x} = -log_2{\\frac{1}{x}}
            /// $$
            ///
            /// @dev See https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation
            ///
            /// Notes:
            /// - Due to the lossy precision of the iterative approximation, the results are not perfectly accurate to the last decimal.
            ///
            /// Requirements:
            /// - x ≥ UNIT
            ///
            /// @param x The UD60x18 number for which to calculate the binary logarithm.
            /// @return result The binary logarithm as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function log2(UD60x18 x) pure returns (UD60x18 result) {
                uint256 xUint = x.unwrap();
                if (xUint < uUNIT) {
                    revert Errors.PRBMath_UD60x18_Log_InputTooSmall(x);
                }
                unchecked {
                    // Calculate the integer part of the logarithm.
                    uint256 n = Common.msb(xUint / uUNIT);
                    // This is the integer part of the logarithm as a UD60x18 number. The operation can't overflow because n
                    // n is at most 255 and UNIT is 1e18.
                    uint256 resultUint = n * uUNIT;
                    // Calculate $y = x * 2^{-n}$.
                    uint256 y = xUint >> n;
                    // If y is the unit number, the fractional part is zero.
                    if (y == uUNIT) {
                        return wrap(resultUint);
                    }
                    // Calculate the fractional part via the iterative approximation.
                    // The `delta >>= 1` part is equivalent to `delta /= 2`, but shifting bits is more gas efficient.
                    uint256 DOUBLE_UNIT = 2e18;
                    for (uint256 delta = uHALF_UNIT; delta > 0; delta >>= 1) {
                        y = (y * y) / uUNIT;
                        // Is y^2 >= 2e18 and so in the range [2e18, 4e18)?
                        if (y >= DOUBLE_UNIT) {
                            // Add the 2^{-m} factor to the logarithm.
                            resultUint += delta;
                            // Halve y, which corresponds to z/2 in the Wikipedia article.
                            y >>= 1;
                        }
                    }
                    result = wrap(resultUint);
                }
            }
            /// @notice Multiplies two UD60x18 numbers together, returning a new UD60x18 number.
            ///
            /// @dev Uses {Common.mulDiv} to enable overflow-safe multiplication and division.
            ///
            /// Notes:
            /// - Refer to the notes in {Common.mulDiv}.
            ///
            /// Requirements:
            /// - Refer to the requirements in {Common.mulDiv}.
            ///
            /// @dev See the documentation in {Common.mulDiv18}.
            /// @param x The multiplicand as a UD60x18 number.
            /// @param y The multiplier as a UD60x18 number.
            /// @return result The product as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function mul(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                result = wrap(Common.mulDiv18(x.unwrap(), y.unwrap()));
            }
            /// @notice Raises x to the power of y.
            ///
            /// For $1 \\leq x \\leq \\infty$, the following standard formula is used:
            ///
            /// $$
            /// x^y = 2^{log_2{x} * y}
            /// $$
            ///
            /// For $0 \\leq x \\lt 1$, since the unsigned {log2} is undefined, an equivalent formula is used:
            ///
            /// $$
            /// i = \\frac{1}{x}
            /// w = 2^{log_2{i} * y}
            /// x^y = \\frac{1}{w}
            /// $$
            ///
            /// @dev Notes:
            /// - Refer to the notes in {log2} and {mul}.
            /// - Returns `UNIT` for 0^0.
            /// - It may not perform well with very small values of x. Consider using SD59x18 as an alternative.
            ///
            /// Requirements:
            /// - Refer to the requirements in {exp2}, {log2}, and {mul}.
            ///
            /// @param x The base as a UD60x18 number.
            /// @param y The exponent as a UD60x18 number.
            /// @return result The result as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function pow(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
                uint256 xUint = x.unwrap();
                uint256 yUint = y.unwrap();
                // If both x and y are zero, the result is `UNIT`. If just x is zero, the result is always zero.
                if (xUint == 0) {
                    return yUint == 0 ? UNIT : ZERO;
                }
                // If x is `UNIT`, the result is always `UNIT`.
                else if (xUint == uUNIT) {
                    return UNIT;
                }
                // If y is zero, the result is always `UNIT`.
                if (yUint == 0) {
                    return UNIT;
                }
                // If y is `UNIT`, the result is always x.
                else if (yUint == uUNIT) {
                    return x;
                }
                // If x is > UNIT, use the standard formula.
                if (xUint > uUNIT) {
                    result = exp2(mul(log2(x), y));
                }
                // Conversely, if x < UNIT, use the equivalent formula.
                else {
                    UD60x18 i = wrap(uUNIT_SQUARED / xUint);
                    UD60x18 w = exp2(mul(log2(i), y));
                    result = wrap(uUNIT_SQUARED / w.unwrap());
                }
            }
            /// @notice Raises x (a UD60x18 number) to the power y (an unsigned basic integer) using the well-known
            /// algorithm "exponentiation by squaring".
            ///
            /// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring.
            ///
            /// Notes:
            /// - Refer to the notes in {Common.mulDiv18}.
            /// - Returns `UNIT` for 0^0.
            ///
            /// Requirements:
            /// - The result must fit in UD60x18.
            ///
            /// @param x The base as a UD60x18 number.
            /// @param y The exponent as a uint256.
            /// @return result The result as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function powu(UD60x18 x, uint256 y) pure returns (UD60x18 result) {
                // Calculate the first iteration of the loop in advance.
                uint256 xUint = x.unwrap();
                uint256 resultUint = y & 1 > 0 ? xUint : uUNIT;
                // Equivalent to `for(y /= 2; y > 0; y /= 2)`.
                for (y >>= 1; y > 0; y >>= 1) {
                    xUint = Common.mulDiv18(xUint, xUint);
                    // Equivalent to `y % 2 == 1`.
                    if (y & 1 > 0) {
                        resultUint = Common.mulDiv18(resultUint, xUint);
                    }
                }
                result = wrap(resultUint);
            }
            /// @notice Calculates the square root of x using the Babylonian method.
            ///
            /// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
            ///
            /// Notes:
            /// - The result is rounded toward zero.
            ///
            /// Requirements:
            /// - x ≤ MAX_UD60x18 / UNIT
            ///
            /// @param x The UD60x18 number for which to calculate the square root.
            /// @return result The result as a UD60x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function sqrt(UD60x18 x) pure returns (UD60x18 result) {
                uint256 xUint = x.unwrap();
                unchecked {
                    if (xUint > uMAX_UD60x18 / uUNIT) {
                        revert Errors.PRBMath_UD60x18_Sqrt_Overflow(x);
                    }
                    // Multiply x by `UNIT` to account for the factor of `UNIT` picked up when multiplying two UD60x18 numbers.
                    // In this case, the two numbers are both the square root.
                    result = wrap(Common.sqrt(xUint * uUNIT));
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "./Casting.sol" as Casting;
            import "./Helpers.sol" as Helpers;
            import "./Math.sol" as Math;
            /// @notice The unsigned 60.18-decimal fixed-point number representation, which can have up to 60 digits and up to 18
            /// decimals. The values of this are bound by the minimum and the maximum values permitted by the Solidity type uint256.
            /// @dev The value type is defined here so it can be imported in all other files.
            type UD60x18 is uint256;
            /*//////////////////////////////////////////////////////////////////////////
                                                CASTING
            //////////////////////////////////////////////////////////////////////////*/
            using {
                Casting.intoSD1x18,
                Casting.intoSD21x18,
                Casting.intoSD59x18,
                Casting.intoUD2x18,
                Casting.intoUD21x18,
                Casting.intoUint128,
                Casting.intoUint256,
                Casting.intoUint40,
                Casting.unwrap
            } for UD60x18 global;
            /*//////////////////////////////////////////////////////////////////////////
                                        MATHEMATICAL FUNCTIONS
            //////////////////////////////////////////////////////////////////////////*/
            // The global "using for" directive makes the functions in this library callable on the UD60x18 type.
            using {
                Math.avg,
                Math.ceil,
                Math.div,
                Math.exp,
                Math.exp2,
                Math.floor,
                Math.frac,
                Math.gm,
                Math.inv,
                Math.ln,
                Math.log10,
                Math.log2,
                Math.mul,
                Math.pow,
                Math.powu,
                Math.sqrt
            } for UD60x18 global;
            /*//////////////////////////////////////////////////////////////////////////
                                            HELPER FUNCTIONS
            //////////////////////////////////////////////////////////////////////////*/
            // The global "using for" directive makes the functions in this library callable on the UD60x18 type.
            using {
                Helpers.add,
                Helpers.and,
                Helpers.eq,
                Helpers.gt,
                Helpers.gte,
                Helpers.isZero,
                Helpers.lshift,
                Helpers.lt,
                Helpers.lte,
                Helpers.mod,
                Helpers.neq,
                Helpers.not,
                Helpers.or,
                Helpers.rshift,
                Helpers.sub,
                Helpers.uncheckedAdd,
                Helpers.uncheckedSub,
                Helpers.xor
            } for UD60x18 global;
            /*//////////////////////////////////////////////////////////////////////////
                                                OPERATORS
            //////////////////////////////////////////////////////////////////////////*/
            // The global "using for" directive makes it possible to use these operators on the UD60x18 type.
            using {
                Helpers.add as +,
                Helpers.and2 as &,
                Math.div as /,
                Helpers.eq as ==,
                Helpers.gt as >,
                Helpers.gte as >=,
                Helpers.lt as <,
                Helpers.lte as <=,
                Helpers.or as |,
                Helpers.mod as %,
                Math.mul as *,
                Helpers.neq as !=,
                Helpers.not as ~,
                Helpers.sub as -,
                Helpers.xor as ^
            } for UD60x18 global;
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
            pragma solidity ^0.8.20;
            /**
             * @dev Interface of the ERC-20 standard as defined in the ERC.
             */
            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 value of tokens in existence.
                 */
                function totalSupply() external view returns (uint256);
                /**
                 * @dev Returns the value of tokens owned by `account`.
                 */
                function balanceOf(address account) external view returns (uint256);
                /**
                 * @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);
                /**
                 * @dev Moves a `value` amount of tokens from `from` to `to` using the
                 * allowance mechanism. `value` 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 value) external returns (bool);
            }
            // SPDX-License-Identifier: GPL-3.0-or-later
            pragma solidity >=0.8.19;
            import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
            import { IERC721Metadata } from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
            import { Lockup } from "../types/DataTypes.sol";
            import { ISablierV2Base } from "./ISablierV2Base.sol";
            import { ISablierV2NFTDescriptor } from "./ISablierV2NFTDescriptor.sol";
            /// @title ISablierV2Lockup
            /// @notice Common logic between all Sablier V2 Lockup streaming contracts.
            interface ISablierV2Lockup is
                ISablierV2Base, // 1 inherited component
                IERC721Metadata // 2 inherited components
            {
                /*//////////////////////////////////////////////////////////////////////////
                                                   EVENTS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Emitted when a stream is canceled.
                /// @param streamId The id of the stream.
                /// @param sender The address of the stream's sender.
                /// @param recipient The address of the stream's recipient.
                /// @param asset The contract address of the ERC-20 asset used for streaming.
                /// @param senderAmount The amount of assets refunded to the stream's sender, denoted in units of the asset's
                /// decimals.
                /// @param recipientAmount The amount of assets left for the stream's recipient to withdraw, denoted in units of the
                /// asset's decimals.
                event CancelLockupStream(
                    uint256 streamId,
                    address indexed sender,
                    address indexed recipient,
                    IERC20 indexed asset,
                    uint128 senderAmount,
                    uint128 recipientAmount
                );
                /// @notice Emitted when a sender gives up the right to cancel a stream.
                /// @param streamId The id of the stream.
                event RenounceLockupStream(uint256 indexed streamId);
                /// @notice Emitted when the admin sets a new NFT descriptor contract.
                /// @param admin The address of the current contract admin.
                /// @param oldNFTDescriptor The address of the old NFT descriptor contract.
                /// @param newNFTDescriptor The address of the new NFT descriptor contract.
                event SetNFTDescriptor(
                    address indexed admin, ISablierV2NFTDescriptor oldNFTDescriptor, ISablierV2NFTDescriptor newNFTDescriptor
                );
                /// @notice Emitted when assets are withdrawn from a stream.
                /// @param streamId The id of the stream.
                /// @param to The address that has received the withdrawn assets.
                /// @param asset The contract address of the ERC-20 asset used for streaming.
                /// @param amount The amount of assets withdrawn, denoted in units of the asset's decimals.
                event WithdrawFromLockupStream(uint256 indexed streamId, address indexed to, IERC20 indexed asset, uint128 amount);
                /*//////////////////////////////////////////////////////////////////////////
                                             CONSTANT FUNCTIONS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Retrieves the address of the ERC-20 asset used for streaming.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function getAsset(uint256 streamId) external view returns (IERC20 asset);
                /// @notice Retrieves the amount deposited in the stream, denoted in units of the asset's decimals.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function getDepositedAmount(uint256 streamId) external view returns (uint128 depositedAmount);
                /// @notice Retrieves the stream's end time, which is a Unix timestamp.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function getEndTime(uint256 streamId) external view returns (uint40 endTime);
                /// @notice Retrieves the stream's recipient.
                /// @dev Reverts if the NFT has been burned.
                /// @param streamId The stream id for the query.
                function getRecipient(uint256 streamId) external view returns (address recipient);
                /// @notice Retrieves the amount refunded to the sender after a cancellation, denoted in units of the asset's
                /// decimals. This amount is always zero unless the stream was canceled.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function getRefundedAmount(uint256 streamId) external view returns (uint128 refundedAmount);
                /// @notice Retrieves the stream's sender.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function getSender(uint256 streamId) external view returns (address sender);
                /// @notice Retrieves the stream's start time, which is a Unix timestamp.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function getStartTime(uint256 streamId) external view returns (uint40 startTime);
                /// @notice Retrieves the amount withdrawn from the stream, denoted in units of the asset's decimals.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function getWithdrawnAmount(uint256 streamId) external view returns (uint128 withdrawnAmount);
                /// @notice Retrieves a flag indicating whether the stream can be canceled. When the stream is cold, this
                /// flag is always `false`.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function isCancelable(uint256 streamId) external view returns (bool result);
                /// @notice Retrieves a flag indicating whether the stream is cold, i.e. settled, canceled, or depleted.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function isCold(uint256 streamId) external view returns (bool result);
                /// @notice Retrieves a flag indicating whether the stream is depleted.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function isDepleted(uint256 streamId) external view returns (bool result);
                /// @notice Retrieves a flag indicating whether the stream exists.
                /// @dev Does not revert if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function isStream(uint256 streamId) external view returns (bool result);
                /// @notice Retrieves a flag indicating whether the stream NFT can be transferred.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function isTransferable(uint256 streamId) external view returns (bool result);
                /// @notice Retrieves a flag indicating whether the stream is warm, i.e. either pending or streaming.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function isWarm(uint256 streamId) external view returns (bool result);
                /// @notice Counter for stream ids, used in the create functions.
                function nextStreamId() external view returns (uint256);
                /// @notice Calculates the amount that the sender would be refunded if the stream were canceled, denoted in units
                /// of the asset's decimals.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function refundableAmountOf(uint256 streamId) external view returns (uint128 refundableAmount);
                /// @notice Retrieves the stream's status.
                /// @param streamId The stream id for the query.
                function statusOf(uint256 streamId) external view returns (Lockup.Status status);
                /// @notice Calculates the amount streamed to the recipient, denoted in units of the asset's decimals.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function streamedAmountOf(uint256 streamId) external view returns (uint128 streamedAmount);
                /// @notice Retrieves a flag indicating whether the stream was canceled.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function wasCanceled(uint256 streamId) external view returns (bool result);
                /// @notice Calculates the amount that the recipient can withdraw from the stream, denoted in units of the asset's
                /// decimals.
                /// @dev Reverts if `streamId` references a null stream.
                /// @param streamId The stream id for the query.
                function withdrawableAmountOf(uint256 streamId) external view returns (uint128 withdrawableAmount);
                /*//////////////////////////////////////////////////////////////////////////
                                           NON-CONSTANT FUNCTIONS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Burns the NFT associated with the stream.
                ///
                /// @dev Emits a {Transfer} event.
                ///
                /// Requirements:
                /// - Must not be delegate called.
                /// - `streamId` must reference a depleted stream.
                /// - The NFT must exist.
                /// - `msg.sender` must be either the NFT owner or an approved third party.
                ///
                /// @param streamId The id of the stream NFT to burn.
                function burn(uint256 streamId) external;
                /// @notice Cancels the stream and refunds any remaining assets to the sender.
                ///
                /// @dev Emits a {Transfer}, {CancelLockupStream}, and {MetadataUpdate} event.
                ///
                /// Notes:
                /// - If there any assets left for the recipient to withdraw, the stream is marked as canceled. Otherwise, the
                /// stream is marked as depleted.
                /// - This function attempts to invoke a hook on the recipient, if the resolved address is a contract.
                ///
                /// Requirements:
                /// - Must not be delegate called.
                /// - The stream must be warm and cancelable.
                /// - `msg.sender` must be the stream's sender.
                ///
                /// @param streamId The id of the stream to cancel.
                function cancel(uint256 streamId) external;
                /// @notice Cancels multiple streams and refunds any remaining assets to the sender.
                ///
                /// @dev Emits multiple {Transfer}, {CancelLockupStream}, and {MetadataUpdate} events.
                ///
                /// Notes:
                /// - Refer to the notes in {cancel}.
                ///
                /// Requirements:
                /// - All requirements from {cancel} must be met for each stream.
                ///
                /// @param streamIds The ids of the streams to cancel.
                function cancelMultiple(uint256[] calldata streamIds) external;
                /// @notice Removes the right of the stream's sender to cancel the stream.
                ///
                /// @dev Emits a {RenounceLockupStream} and {MetadataUpdate} event.
                ///
                /// Notes:
                /// - This is an irreversible operation.
                /// - This function attempts to invoke a hook on the stream's recipient, provided that the recipient is a contract.
                ///
                /// Requirements:
                /// - Must not be delegate called.
                /// - `streamId` must reference a warm stream.
                /// - `msg.sender` must be the stream's sender.
                /// - The stream must be cancelable.
                ///
                /// @param streamId The id of the stream to renounce.
                function renounce(uint256 streamId) external;
                /// @notice Sets a new NFT descriptor contract, which produces the URI describing the Sablier stream NFTs.
                ///
                /// @dev Emits a {SetNFTDescriptor} and {BatchMetadataUpdate} event.
                ///
                /// Notes:
                /// - Does not revert if the NFT descriptor is the same.
                ///
                /// Requirements:
                /// - `msg.sender` must be the contract admin.
                ///
                /// @param newNFTDescriptor The address of the new NFT descriptor contract.
                function setNFTDescriptor(ISablierV2NFTDescriptor newNFTDescriptor) external;
                /// @notice Withdraws the provided amount of assets from the stream to the `to` address.
                ///
                /// @dev Emits a {Transfer}, {WithdrawFromLockupStream}, and {MetadataUpdate} event.
                ///
                /// Notes:
                /// - This function attempts to invoke a hook on the stream's recipient, provided that the recipient is a contract
                /// and `msg.sender` is either the sender or an approved operator.
                ///
                /// Requirements:
                /// - Must not be delegate called.
                /// - `streamId` must not reference a null or depleted stream.
                /// - `msg.sender` must be the stream's sender, the stream's recipient or an approved third party.
                /// - `to` must be the recipient if `msg.sender` is the stream's sender.
                /// - `to` must not be the zero address.
                /// - `amount` must be greater than zero and must not exceed the withdrawable amount.
                ///
                /// @param streamId The id of the stream to withdraw from.
                /// @param to The address receiving the withdrawn assets.
                /// @param amount The amount to withdraw, denoted in units of the asset's decimals.
                function withdraw(uint256 streamId, address to, uint128 amount) external;
                /// @notice Withdraws the maximum withdrawable amount from the stream to the provided address `to`.
                ///
                /// @dev Emits a {Transfer}, {WithdrawFromLockupStream}, and {MetadataUpdate} event.
                ///
                /// Notes:
                /// - Refer to the notes in {withdraw}.
                ///
                /// Requirements:
                /// - Refer to the requirements in {withdraw}.
                ///
                /// @param streamId The id of the stream to withdraw from.
                /// @param to The address receiving the withdrawn assets.
                function withdrawMax(uint256 streamId, address to) external;
                /// @notice Withdraws the maximum withdrawable amount from the stream to the current recipient, and transfers the
                /// NFT to `newRecipient`.
                ///
                /// @dev Emits a {WithdrawFromLockupStream} and a {Transfer} event.
                ///
                /// Notes:
                /// - If the withdrawable amount is zero, the withdrawal is skipped.
                /// - Refer to the notes in {withdraw}.
                ///
                /// Requirements:
                /// - `msg.sender` must be the stream's recipient.
                /// - Refer to the requirements in {withdraw}.
                /// - Refer to the requirements in {IERC721.transferFrom}.
                ///
                /// @param streamId The id of the stream NFT to transfer.
                /// @param newRecipient The address of the new owner of the stream NFT.
                function withdrawMaxAndTransfer(uint256 streamId, address newRecipient) external;
                /// @notice Withdraws assets from streams to the provided address `to`.
                ///
                /// @dev Emits multiple {Transfer}, {WithdrawFromLockupStream}, and {MetadataUpdate} events.
                ///
                /// Notes:
                /// - This function attempts to call a hook on the recipient of each stream, unless `msg.sender` is the recipient.
                ///
                /// Requirements:
                /// - All requirements from {withdraw} must be met for each stream.
                /// - There must be an equal number of `streamIds` and `amounts`.
                ///
                /// @param streamIds The ids of the streams to withdraw from.
                /// @param to The address receiving the withdrawn assets.
                /// @param amounts The amounts to withdraw, denoted in units of the asset's decimals.
                function withdrawMultiple(uint256[] calldata streamIds, address to, uint128[] calldata amounts) external;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            /*
            ██████╗ ██████╗ ██████╗ ███╗   ███╗ █████╗ ████████╗██╗  ██╗
            ██╔══██╗██╔══██╗██╔══██╗████╗ ████║██╔══██╗╚══██╔══╝██║  ██║
            ██████╔╝██████╔╝██████╔╝██╔████╔██║███████║   ██║   ███████║
            ██╔═══╝ ██╔══██╗██╔══██╗██║╚██╔╝██║██╔══██║   ██║   ██╔══██║
            ██║     ██║  ██║██████╔╝██║ ╚═╝ ██║██║  ██║   ██║   ██║  ██║
            ╚═╝     ╚═╝  ╚═╝╚═════╝ ╚═╝     ╚═╝╚═╝  ╚═╝   ╚═╝   ╚═╝  ╚═╝
            ██╗   ██╗██████╗ ██████╗ ██╗  ██╗ ██╗ █████╗
            ██║   ██║██╔══██╗╚════██╗╚██╗██╔╝███║██╔══██╗
            ██║   ██║██║  ██║ █████╔╝ ╚███╔╝ ╚██║╚█████╔╝
            ██║   ██║██║  ██║██╔═══╝  ██╔██╗  ██║██╔══██╗
            ╚██████╔╝██████╔╝███████╗██╔╝ ██╗ ██║╚█████╔╝
             ╚═════╝ ╚═════╝ ╚══════╝╚═╝  ╚═╝ ╚═╝ ╚════╝
            */
            import "./ud2x18/Casting.sol";
            import "./ud2x18/Constants.sol";
            import "./ud2x18/Errors.sol";
            import "./ud2x18/ValueType.sol";
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            // Common.sol
            //
            // Common mathematical functions used in both SD59x18 and UD60x18. Note that these global functions do not
            // always operate with SD59x18 and UD60x18 numbers.
            /*//////////////////////////////////////////////////////////////////////////
                                            CUSTOM ERRORS
            //////////////////////////////////////////////////////////////////////////*/
            /// @notice Thrown when the resultant value in {mulDiv} overflows uint256.
            error PRBMath_MulDiv_Overflow(uint256 x, uint256 y, uint256 denominator);
            /// @notice Thrown when the resultant value in {mulDiv18} overflows uint256.
            error PRBMath_MulDiv18_Overflow(uint256 x, uint256 y);
            /// @notice Thrown when one of the inputs passed to {mulDivSigned} is `type(int256).min`.
            error PRBMath_MulDivSigned_InputTooSmall();
            /// @notice Thrown when the resultant value in {mulDivSigned} overflows int256.
            error PRBMath_MulDivSigned_Overflow(int256 x, int256 y);
            /*//////////////////////////////////////////////////////////////////////////
                                                CONSTANTS
            //////////////////////////////////////////////////////////////////////////*/
            /// @dev The maximum value a uint128 number can have.
            uint128 constant MAX_UINT128 = type(uint128).max;
            /// @dev The maximum value a uint40 number can have.
            uint40 constant MAX_UINT40 = type(uint40).max;
            /// @dev The maximum value a uint64 number can have.
            uint64 constant MAX_UINT64 = type(uint64).max;
            /// @dev The unit number, which the decimal precision of the fixed-point types.
            uint256 constant UNIT = 1e18;
            /// @dev The unit number inverted mod 2^256.
            uint256 constant UNIT_INVERSE = 78156646155174841979727994598816262306175212592076161876661_508869554232690281;
            /// @dev The the largest power of two that divides the decimal value of `UNIT`. The logarithm of this value is the least significant
            /// bit in the binary representation of `UNIT`.
            uint256 constant UNIT_LPOTD = 262144;
            /*//////////////////////////////////////////////////////////////////////////
                                                FUNCTIONS
            //////////////////////////////////////////////////////////////////////////*/
            /// @notice Calculates the binary exponent of x using the binary fraction method.
            /// @dev Has to use 192.64-bit fixed-point numbers. See https://ethereum.stackexchange.com/a/96594/24693.
            /// @param x The exponent as an unsigned 192.64-bit fixed-point number.
            /// @return result The result as an unsigned 60.18-decimal fixed-point number.
            /// @custom:smtchecker abstract-function-nondet
            function exp2(uint256 x) pure returns (uint256 result) {
                unchecked {
                    // Start from 0.5 in the 192.64-bit fixed-point format.
                    result = 0x800000000000000000000000000000000000000000000000;
                    // The following logic multiplies the result by $\\sqrt{2^{-i}}$ when the bit at position i is 1. Key points:
                    //
                    // 1. Intermediate results will not overflow, as the starting point is 2^191 and all magic factors are under 2^65.
                    // 2. The rationale for organizing the if statements into groups of 8 is gas savings. If the result of performing
                    // a bitwise AND operation between x and any value in the array [0x80; 0x40; 0x20; 0x10; 0x08; 0x04; 0x02; 0x01] is 1,
                    // we know that `x & 0xFF` is also 1.
                    if (x & 0xFF00000000000000 > 0) {
                        if (x & 0x8000000000000000 > 0) {
                            result = (result * 0x16A09E667F3BCC909) >> 64;
                        }
                        if (x & 0x4000000000000000 > 0) {
                            result = (result * 0x1306FE0A31B7152DF) >> 64;
                        }
                        if (x & 0x2000000000000000 > 0) {
                            result = (result * 0x1172B83C7D517ADCE) >> 64;
                        }
                        if (x & 0x1000000000000000 > 0) {
                            result = (result * 0x10B5586CF9890F62A) >> 64;
                        }
                        if (x & 0x800000000000000 > 0) {
                            result = (result * 0x1059B0D31585743AE) >> 64;
                        }
                        if (x & 0x400000000000000 > 0) {
                            result = (result * 0x102C9A3E778060EE7) >> 64;
                        }
                        if (x & 0x200000000000000 > 0) {
                            result = (result * 0x10163DA9FB33356D8) >> 64;
                        }
                        if (x & 0x100000000000000 > 0) {
                            result = (result * 0x100B1AFA5ABCBED61) >> 64;
                        }
                    }
                    if (x & 0xFF000000000000 > 0) {
                        if (x & 0x80000000000000 > 0) {
                            result = (result * 0x10058C86DA1C09EA2) >> 64;
                        }
                        if (x & 0x40000000000000 > 0) {
                            result = (result * 0x1002C605E2E8CEC50) >> 64;
                        }
                        if (x & 0x20000000000000 > 0) {
                            result = (result * 0x100162F3904051FA1) >> 64;
                        }
                        if (x & 0x10000000000000 > 0) {
                            result = (result * 0x1000B175EFFDC76BA) >> 64;
                        }
                        if (x & 0x8000000000000 > 0) {
                            result = (result * 0x100058BA01FB9F96D) >> 64;
                        }
                        if (x & 0x4000000000000 > 0) {
                            result = (result * 0x10002C5CC37DA9492) >> 64;
                        }
                        if (x & 0x2000000000000 > 0) {
                            result = (result * 0x1000162E525EE0547) >> 64;
                        }
                        if (x & 0x1000000000000 > 0) {
                            result = (result * 0x10000B17255775C04) >> 64;
                        }
                    }
                    if (x & 0xFF0000000000 > 0) {
                        if (x & 0x800000000000 > 0) {
                            result = (result * 0x1000058B91B5BC9AE) >> 64;
                        }
                        if (x & 0x400000000000 > 0) {
                            result = (result * 0x100002C5C89D5EC6D) >> 64;
                        }
                        if (x & 0x200000000000 > 0) {
                            result = (result * 0x10000162E43F4F831) >> 64;
                        }
                        if (x & 0x100000000000 > 0) {
                            result = (result * 0x100000B1721BCFC9A) >> 64;
                        }
                        if (x & 0x80000000000 > 0) {
                            result = (result * 0x10000058B90CF1E6E) >> 64;
                        }
                        if (x & 0x40000000000 > 0) {
                            result = (result * 0x1000002C5C863B73F) >> 64;
                        }
                        if (x & 0x20000000000 > 0) {
                            result = (result * 0x100000162E430E5A2) >> 64;
                        }
                        if (x & 0x10000000000 > 0) {
                            result = (result * 0x1000000B172183551) >> 64;
                        }
                    }
                    if (x & 0xFF00000000 > 0) {
                        if (x & 0x8000000000 > 0) {
                            result = (result * 0x100000058B90C0B49) >> 64;
                        }
                        if (x & 0x4000000000 > 0) {
                            result = (result * 0x10000002C5C8601CC) >> 64;
                        }
                        if (x & 0x2000000000 > 0) {
                            result = (result * 0x1000000162E42FFF0) >> 64;
                        }
                        if (x & 0x1000000000 > 0) {
                            result = (result * 0x10000000B17217FBB) >> 64;
                        }
                        if (x & 0x800000000 > 0) {
                            result = (result * 0x1000000058B90BFCE) >> 64;
                        }
                        if (x & 0x400000000 > 0) {
                            result = (result * 0x100000002C5C85FE3) >> 64;
                        }
                        if (x & 0x200000000 > 0) {
                            result = (result * 0x10000000162E42FF1) >> 64;
                        }
                        if (x & 0x100000000 > 0) {
                            result = (result * 0x100000000B17217F8) >> 64;
                        }
                    }
                    if (x & 0xFF000000 > 0) {
                        if (x & 0x80000000 > 0) {
                            result = (result * 0x10000000058B90BFC) >> 64;
                        }
                        if (x & 0x40000000 > 0) {
                            result = (result * 0x1000000002C5C85FE) >> 64;
                        }
                        if (x & 0x20000000 > 0) {
                            result = (result * 0x100000000162E42FF) >> 64;
                        }
                        if (x & 0x10000000 > 0) {
                            result = (result * 0x1000000000B17217F) >> 64;
                        }
                        if (x & 0x8000000 > 0) {
                            result = (result * 0x100000000058B90C0) >> 64;
                        }
                        if (x & 0x4000000 > 0) {
                            result = (result * 0x10000000002C5C860) >> 64;
                        }
                        if (x & 0x2000000 > 0) {
                            result = (result * 0x1000000000162E430) >> 64;
                        }
                        if (x & 0x1000000 > 0) {
                            result = (result * 0x10000000000B17218) >> 64;
                        }
                    }
                    if (x & 0xFF0000 > 0) {
                        if (x & 0x800000 > 0) {
                            result = (result * 0x1000000000058B90C) >> 64;
                        }
                        if (x & 0x400000 > 0) {
                            result = (result * 0x100000000002C5C86) >> 64;
                        }
                        if (x & 0x200000 > 0) {
                            result = (result * 0x10000000000162E43) >> 64;
                        }
                        if (x & 0x100000 > 0) {
                            result = (result * 0x100000000000B1721) >> 64;
                        }
                        if (x & 0x80000 > 0) {
                            result = (result * 0x10000000000058B91) >> 64;
                        }
                        if (x & 0x40000 > 0) {
                            result = (result * 0x1000000000002C5C8) >> 64;
                        }
                        if (x & 0x20000 > 0) {
                            result = (result * 0x100000000000162E4) >> 64;
                        }
                        if (x & 0x10000 > 0) {
                            result = (result * 0x1000000000000B172) >> 64;
                        }
                    }
                    if (x & 0xFF00 > 0) {
                        if (x & 0x8000 > 0) {
                            result = (result * 0x100000000000058B9) >> 64;
                        }
                        if (x & 0x4000 > 0) {
                            result = (result * 0x10000000000002C5D) >> 64;
                        }
                        if (x & 0x2000 > 0) {
                            result = (result * 0x1000000000000162E) >> 64;
                        }
                        if (x & 0x1000 > 0) {
                            result = (result * 0x10000000000000B17) >> 64;
                        }
                        if (x & 0x800 > 0) {
                            result = (result * 0x1000000000000058C) >> 64;
                        }
                        if (x & 0x400 > 0) {
                            result = (result * 0x100000000000002C6) >> 64;
                        }
                        if (x & 0x200 > 0) {
                            result = (result * 0x10000000000000163) >> 64;
                        }
                        if (x & 0x100 > 0) {
                            result = (result * 0x100000000000000B1) >> 64;
                        }
                    }
                    if (x & 0xFF > 0) {
                        if (x & 0x80 > 0) {
                            result = (result * 0x10000000000000059) >> 64;
                        }
                        if (x & 0x40 > 0) {
                            result = (result * 0x1000000000000002C) >> 64;
                        }
                        if (x & 0x20 > 0) {
                            result = (result * 0x10000000000000016) >> 64;
                        }
                        if (x & 0x10 > 0) {
                            result = (result * 0x1000000000000000B) >> 64;
                        }
                        if (x & 0x8 > 0) {
                            result = (result * 0x10000000000000006) >> 64;
                        }
                        if (x & 0x4 > 0) {
                            result = (result * 0x10000000000000003) >> 64;
                        }
                        if (x & 0x2 > 0) {
                            result = (result * 0x10000000000000001) >> 64;
                        }
                        if (x & 0x1 > 0) {
                            result = (result * 0x10000000000000001) >> 64;
                        }
                    }
                    // In the code snippet below, two operations are executed simultaneously:
                    //
                    // 1. The result is multiplied by $(2^n + 1)$, where $2^n$ represents the integer part, and the additional 1
                    // accounts for the initial guess of 0.5. This is achieved by subtracting from 191 instead of 192.
                    // 2. The result is then converted to an unsigned 60.18-decimal fixed-point format.
                    //
                    // The underlying logic is based on the relationship $2^{191-ip} = 2^{ip} / 2^{191}$, where $ip$ denotes the,
                    // integer part, $2^n$.
                    result *= UNIT;
                    result >>= (191 - (x >> 64));
                }
            }
            /// @notice Finds the zero-based index of the first 1 in the binary representation of x.
            ///
            /// @dev See the note on "msb" in this Wikipedia article: https://en.wikipedia.org/wiki/Find_first_set
            ///
            /// Each step in this implementation is equivalent to this high-level code:
            ///
            /// ```solidity
            /// if (x >= 2 ** 128) {
            ///     x >>= 128;
            ///     result += 128;
            /// }
            /// ```
            ///
            /// Where 128 is replaced with each respective power of two factor. See the full high-level implementation here:
            /// https://gist.github.com/PaulRBerg/f932f8693f2733e30c4d479e8e980948
            ///
            /// The Yul instructions used below are:
            ///
            /// - "gt" is "greater than"
            /// - "or" is the OR bitwise operator
            /// - "shl" is "shift left"
            /// - "shr" is "shift right"
            ///
            /// @param x The uint256 number for which to find the index of the most significant bit.
            /// @return result The index of the most significant bit as a uint256.
            /// @custom:smtchecker abstract-function-nondet
            function msb(uint256 x) pure returns (uint256 result) {
                // 2^128
                assembly ("memory-safe") {
                    let factor := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
                    x := shr(factor, x)
                    result := or(result, factor)
                }
                // 2^64
                assembly ("memory-safe") {
                    let factor := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))
                    x := shr(factor, x)
                    result := or(result, factor)
                }
                // 2^32
                assembly ("memory-safe") {
                    let factor := shl(5, gt(x, 0xFFFFFFFF))
                    x := shr(factor, x)
                    result := or(result, factor)
                }
                // 2^16
                assembly ("memory-safe") {
                    let factor := shl(4, gt(x, 0xFFFF))
                    x := shr(factor, x)
                    result := or(result, factor)
                }
                // 2^8
                assembly ("memory-safe") {
                    let factor := shl(3, gt(x, 0xFF))
                    x := shr(factor, x)
                    result := or(result, factor)
                }
                // 2^4
                assembly ("memory-safe") {
                    let factor := shl(2, gt(x, 0xF))
                    x := shr(factor, x)
                    result := or(result, factor)
                }
                // 2^2
                assembly ("memory-safe") {
                    let factor := shl(1, gt(x, 0x3))
                    x := shr(factor, x)
                    result := or(result, factor)
                }
                // 2^1
                // No need to shift x any more.
                assembly ("memory-safe") {
                    let factor := gt(x, 0x1)
                    result := or(result, factor)
                }
            }
            /// @notice Calculates x*y÷denominator with 512-bit precision.
            ///
            /// @dev Credits to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv.
            ///
            /// Notes:
            /// - The result is rounded toward zero.
            ///
            /// Requirements:
            /// - The denominator must not be zero.
            /// - The result must fit in uint256.
            ///
            /// @param x The multiplicand as a uint256.
            /// @param y The multiplier as a uint256.
            /// @param denominator The divisor as a uint256.
            /// @return result The result as a uint256.
            /// @custom:smtchecker abstract-function-nondet
            function mulDiv(uint256 x, uint256 y, uint256 denominator) pure returns (uint256 result) {
                // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
                // use the Chinese Remainder Theorem to reconstruct the 512-bit result. The result is stored in two 256
                // variables such that product = prod1 * 2^256 + prod0.
                uint256 prod0; // Least significant 256 bits of the product
                uint256 prod1; // Most significant 256 bits of the product
                assembly ("memory-safe") {
                    let mm := mulmod(x, y, not(0))
                    prod0 := mul(x, y)
                    prod1 := sub(sub(mm, prod0), lt(mm, prod0))
                }
                // Handle non-overflow cases, 256 by 256 division.
                if (prod1 == 0) {
                    unchecked {
                        return prod0 / denominator;
                    }
                }
                // Make sure the result is less than 2^256. Also prevents denominator == 0.
                if (prod1 >= denominator) {
                    revert PRBMath_MulDiv_Overflow(x, y, denominator);
                }
                ////////////////////////////////////////////////////////////////////////////
                // 512 by 256 division
                ////////////////////////////////////////////////////////////////////////////
                // Make division exact by subtracting the remainder from [prod1 prod0].
                uint256 remainder;
                assembly ("memory-safe") {
                    // Compute remainder using the mulmod Yul instruction.
                    remainder := mulmod(x, y, denominator)
                    // Subtract 256 bit number from 512-bit number.
                    prod1 := sub(prod1, gt(remainder, prod0))
                    prod0 := sub(prod0, remainder)
                }
                unchecked {
                    // Calculate the largest power of two divisor of the denominator using the unary operator ~. This operation cannot overflow
                    // because the denominator cannot be zero at this point in the function execution. The result is always >= 1.
                    // For more detail, see https://cs.stackexchange.com/q/138556/92363.
                    uint256 lpotdod = denominator & (~denominator + 1);
                    uint256 flippedLpotdod;
                    assembly ("memory-safe") {
                        // Factor powers of two out of denominator.
                        denominator := div(denominator, lpotdod)
                        // Divide [prod1 prod0] by lpotdod.
                        prod0 := div(prod0, lpotdod)
                        // Get the flipped value `2^256 / lpotdod`. If the `lpotdod` is zero, the flipped value is one.
                        // `sub(0, lpotdod)` produces the two's complement version of `lpotdod`, which is equivalent to flipping all the bits.
                        // However, `div` interprets this value as an unsigned value: https://ethereum.stackexchange.com/q/147168/24693
                        flippedLpotdod := add(div(sub(0, lpotdod), lpotdod), 1)
                    }
                    // Shift in bits from prod1 into prod0.
                    prod0 |= prod1 * flippedLpotdod;
                    // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
                    // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
                    // four bits. That is, denominator * inv = 1 mod 2^4.
                    uint256 inverse = (3 * denominator) ^ 2;
                    // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
                    // in modular arithmetic, doubling the correct bits in each step.
                    inverse *= 2 - denominator * inverse; // inverse mod 2^8
                    inverse *= 2 - denominator * inverse; // inverse mod 2^16
                    inverse *= 2 - denominator * inverse; // inverse mod 2^32
                    inverse *= 2 - denominator * inverse; // inverse mod 2^64
                    inverse *= 2 - denominator * inverse; // inverse mod 2^128
                    inverse *= 2 - denominator * inverse; // inverse mod 2^256
                    // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
                    // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
                    // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
                    // is no longer required.
                    result = prod0 * inverse;
                }
            }
            /// @notice Calculates x*y÷1e18 with 512-bit precision.
            ///
            /// @dev A variant of {mulDiv} with constant folding, i.e. in which the denominator is hard coded to 1e18.
            ///
            /// Notes:
            /// - The body is purposely left uncommented; to understand how this works, see the documentation in {mulDiv}.
            /// - The result is rounded toward zero.
            /// - We take as an axiom that the result cannot be `MAX_UINT256` when x and y solve the following system of equations:
            ///
            /// $$
            /// \\begin{cases}
            ///     x * y = MAX\\_UINT256 * UNIT \\\\
            ///     (x * y) \\% UNIT \\geq \\frac{UNIT}{2}
            /// \\end{cases}
            /// $$
            ///
            /// Requirements:
            /// - Refer to the requirements in {mulDiv}.
            /// - The result must fit in uint256.
            ///
            /// @param x The multiplicand as an unsigned 60.18-decimal fixed-point number.
            /// @param y The multiplier as an unsigned 60.18-decimal fixed-point number.
            /// @return result The result as an unsigned 60.18-decimal fixed-point number.
            /// @custom:smtchecker abstract-function-nondet
            function mulDiv18(uint256 x, uint256 y) pure returns (uint256 result) {
                uint256 prod0;
                uint256 prod1;
                assembly ("memory-safe") {
                    let mm := mulmod(x, y, not(0))
                    prod0 := mul(x, y)
                    prod1 := sub(sub(mm, prod0), lt(mm, prod0))
                }
                if (prod1 == 0) {
                    unchecked {
                        return prod0 / UNIT;
                    }
                }
                if (prod1 >= UNIT) {
                    revert PRBMath_MulDiv18_Overflow(x, y);
                }
                uint256 remainder;
                assembly ("memory-safe") {
                    remainder := mulmod(x, y, UNIT)
                    result :=
                        mul(
                            or(
                                div(sub(prod0, remainder), UNIT_LPOTD),
                                mul(sub(prod1, gt(remainder, prod0)), add(div(sub(0, UNIT_LPOTD), UNIT_LPOTD), 1))
                            ),
                            UNIT_INVERSE
                        )
                }
            }
            /// @notice Calculates x*y÷denominator with 512-bit precision.
            ///
            /// @dev This is an extension of {mulDiv} for signed numbers, which works by computing the signs and the absolute values separately.
            ///
            /// Notes:
            /// - The result is rounded toward zero.
            ///
            /// Requirements:
            /// - Refer to the requirements in {mulDiv}.
            /// - None of the inputs can be `type(int256).min`.
            /// - The result must fit in int256.
            ///
            /// @param x The multiplicand as an int256.
            /// @param y The multiplier as an int256.
            /// @param denominator The divisor as an int256.
            /// @return result The result as an int256.
            /// @custom:smtchecker abstract-function-nondet
            function mulDivSigned(int256 x, int256 y, int256 denominator) pure returns (int256 result) {
                if (x == type(int256).min || y == type(int256).min || denominator == type(int256).min) {
                    revert PRBMath_MulDivSigned_InputTooSmall();
                }
                // Get hold of the absolute values of x, y and the denominator.
                uint256 xAbs;
                uint256 yAbs;
                uint256 dAbs;
                unchecked {
                    xAbs = x < 0 ? uint256(-x) : uint256(x);
                    yAbs = y < 0 ? uint256(-y) : uint256(y);
                    dAbs = denominator < 0 ? uint256(-denominator) : uint256(denominator);
                }
                // Compute the absolute value of x*y÷denominator. The result must fit in int256.
                uint256 resultAbs = mulDiv(xAbs, yAbs, dAbs);
                if (resultAbs > uint256(type(int256).max)) {
                    revert PRBMath_MulDivSigned_Overflow(x, y);
                }
                // Get the signs of x, y and the denominator.
                uint256 sx;
                uint256 sy;
                uint256 sd;
                assembly ("memory-safe") {
                    // "sgt" is the "signed greater than" assembly instruction and "sub(0,1)" is -1 in two's complement.
                    sx := sgt(x, sub(0, 1))
                    sy := sgt(y, sub(0, 1))
                    sd := sgt(denominator, sub(0, 1))
                }
                // XOR over sx, sy and sd. What this does is to check whether there are 1 or 3 negative signs in the inputs.
                // If there are, the result should be negative. Otherwise, it should be positive.
                unchecked {
                    result = sx ^ sy ^ sd == 0 ? -int256(resultAbs) : int256(resultAbs);
                }
            }
            /// @notice Calculates the square root of x using the Babylonian method.
            ///
            /// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
            ///
            /// Notes:
            /// - If x is not a perfect square, the result is rounded down.
            /// - Credits to OpenZeppelin for the explanations in comments below.
            ///
            /// @param x The uint256 number for which to calculate the square root.
            /// @return result The result as a uint256.
            /// @custom:smtchecker abstract-function-nondet
            function sqrt(uint256 x) pure returns (uint256 result) {
                if (x == 0) {
                    return 0;
                }
                // For our first guess, we calculate the biggest power of 2 which is smaller than the square root of x.
                //
                // We know that the "msb" (most significant bit) of x is a power of 2 such that we have:
                //
                // $$
                // msb(x) <= x <= 2*msb(x)$
                // $$
                //
                // We write $msb(x)$ as $2^k$, and we get:
                //
                // $$
                // k = log_2(x)
                // $$
                //
                // Thus, we can write the initial inequality as:
                //
                // $$
                // 2^{log_2(x)} <= x <= 2*2^{log_2(x)+1} \\\\
                // sqrt(2^k) <= sqrt(x) < sqrt(2^{k+1}) \\\\
                // 2^{k/2} <= sqrt(x) < 2^{(k+1)/2} <= 2^{(k/2)+1}
                // $$
                //
                // Consequently, $2^{log_2(x) /2} is a good first approximation of sqrt(x) with at least one correct bit.
                uint256 xAux = uint256(x);
                result = 1;
                if (xAux >= 2 ** 128) {
                    xAux >>= 128;
                    result <<= 64;
                }
                if (xAux >= 2 ** 64) {
                    xAux >>= 64;
                    result <<= 32;
                }
                if (xAux >= 2 ** 32) {
                    xAux >>= 32;
                    result <<= 16;
                }
                if (xAux >= 2 ** 16) {
                    xAux >>= 16;
                    result <<= 8;
                }
                if (xAux >= 2 ** 8) {
                    xAux >>= 8;
                    result <<= 4;
                }
                if (xAux >= 2 ** 4) {
                    xAux >>= 4;
                    result <<= 2;
                }
                if (xAux >= 2 ** 2) {
                    result <<= 1;
                }
                // At this point, `result` is an estimation with at least one bit of precision. We know the true value has at
                // most 128 bits, since it is the square root of a uint256. Newton's method converges quadratically (precision
                // doubles at every iteration). We thus need at most 7 iteration to turn our partial result with one bit of
                // precision into the expected uint128 result.
                unchecked {
                    result = (result + x / result) >> 1;
                    result = (result + x / result) >> 1;
                    result = (result + x / result) >> 1;
                    result = (result + x / result) >> 1;
                    result = (result + x / result) >> 1;
                    result = (result + x / result) >> 1;
                    result = (result + x / result) >> 1;
                    // If x is not a perfect square, round the result toward zero.
                    uint256 roundedResult = x / result;
                    if (result >= roundedResult) {
                        result = roundedResult;
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { SD1x18 } from "./ValueType.sol";
            /// @dev Euler's number as an SD1x18 number.
            SD1x18 constant E = SD1x18.wrap(2_718281828459045235);
            /// @dev The maximum value an SD1x18 number can have.
            int64 constant uMAX_SD1x18 = 9_223372036854775807;
            SD1x18 constant MAX_SD1x18 = SD1x18.wrap(uMAX_SD1x18);
            /// @dev The minimum value an SD1x18 number can have.
            int64 constant uMIN_SD1x18 = -9_223372036854775808;
            SD1x18 constant MIN_SD1x18 = SD1x18.wrap(uMIN_SD1x18);
            /// @dev PI as an SD1x18 number.
            SD1x18 constant PI = SD1x18.wrap(3_141592653589793238);
            /// @dev The unit number, which gives the decimal precision of SD1x18.
            SD1x18 constant UNIT = SD1x18.wrap(1e18);
            int64 constant uUNIT = 1e18;
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "./Casting.sol" as Casting;
            /// @notice The signed 1.18-decimal fixed-point number representation, which can have up to 1 digit and up to 18
            /// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
            /// type int64. This is useful when end users want to use int64 to save gas, e.g. with tight variable packing in contract
            /// storage.
            type SD1x18 is int64;
            /*//////////////////////////////////////////////////////////////////////////
                                                CASTING
            //////////////////////////////////////////////////////////////////////////*/
            using {
                Casting.intoSD59x18,
                Casting.intoUD60x18,
                Casting.intoUint128,
                Casting.intoUint256,
                Casting.intoUint40,
                Casting.unwrap
            } for SD1x18 global;
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { SD21x18 } from "./ValueType.sol";
            /// @dev Euler's number as an SD21x18 number.
            SD21x18 constant E = SD21x18.wrap(2_718281828459045235);
            /// @dev The maximum value an SD21x18 number can have.
            int128 constant uMAX_SD21x18 = 170141183460469231731_687303715884105727;
            SD21x18 constant MAX_SD21x18 = SD21x18.wrap(uMAX_SD21x18);
            /// @dev The minimum value an SD21x18 number can have.
            int128 constant uMIN_SD21x18 = -170141183460469231731_687303715884105728;
            SD21x18 constant MIN_SD21x18 = SD21x18.wrap(uMIN_SD21x18);
            /// @dev PI as an SD21x18 number.
            SD21x18 constant PI = SD21x18.wrap(3_141592653589793238);
            /// @dev The unit number, which gives the decimal precision of SD21x18.
            SD21x18 constant UNIT = SD21x18.wrap(1e18);
            int128 constant uUNIT = 1e18;
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "./Casting.sol" as Casting;
            /// @notice The signed 21.18-decimal fixed-point number representation, which can have up to 21 digits and up to 18
            /// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
            /// type int128. This is useful when end users want to use int128 to save gas, e.g. with tight variable packing in contract
            /// storage.
            type SD21x18 is int128;
            /*//////////////////////////////////////////////////////////////////////////
                                                CASTING
            //////////////////////////////////////////////////////////////////////////*/
            using {
                Casting.intoSD59x18,
                Casting.intoUD60x18,
                Casting.intoUint128,
                Casting.intoUint256,
                Casting.intoUint40,
                Casting.unwrap
            } for SD21x18 global;
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { SD59x18 } from "./ValueType.sol";
            // NOTICE: the "u" prefix stands for "unwrapped".
            /// @dev Euler's number as an SD59x18 number.
            SD59x18 constant E = SD59x18.wrap(2_718281828459045235);
            /// @dev The maximum input permitted in {exp}.
            int256 constant uEXP_MAX_INPUT = 133_084258667509499440;
            SD59x18 constant EXP_MAX_INPUT = SD59x18.wrap(uEXP_MAX_INPUT);
            /// @dev Any value less than this returns 0 in {exp}.
            int256 constant uEXP_MIN_THRESHOLD = -41_446531673892822322;
            SD59x18 constant EXP_MIN_THRESHOLD = SD59x18.wrap(uEXP_MIN_THRESHOLD);
            /// @dev The maximum input permitted in {exp2}.
            int256 constant uEXP2_MAX_INPUT = 192e18 - 1;
            SD59x18 constant EXP2_MAX_INPUT = SD59x18.wrap(uEXP2_MAX_INPUT);
            /// @dev Any value less than this returns 0 in {exp2}.
            int256 constant uEXP2_MIN_THRESHOLD = -59_794705707972522261;
            SD59x18 constant EXP2_MIN_THRESHOLD = SD59x18.wrap(uEXP2_MIN_THRESHOLD);
            /// @dev Half the UNIT number.
            int256 constant uHALF_UNIT = 0.5e18;
            SD59x18 constant HALF_UNIT = SD59x18.wrap(uHALF_UNIT);
            /// @dev $log_2(10)$ as an SD59x18 number.
            int256 constant uLOG2_10 = 3_321928094887362347;
            SD59x18 constant LOG2_10 = SD59x18.wrap(uLOG2_10);
            /// @dev $log_2(e)$ as an SD59x18 number.
            int256 constant uLOG2_E = 1_442695040888963407;
            SD59x18 constant LOG2_E = SD59x18.wrap(uLOG2_E);
            /// @dev The maximum value an SD59x18 number can have.
            int256 constant uMAX_SD59x18 = 57896044618658097711785492504343953926634992332820282019728_792003956564819967;
            SD59x18 constant MAX_SD59x18 = SD59x18.wrap(uMAX_SD59x18);
            /// @dev The maximum whole value an SD59x18 number can have.
            int256 constant uMAX_WHOLE_SD59x18 = 57896044618658097711785492504343953926634992332820282019728_000000000000000000;
            SD59x18 constant MAX_WHOLE_SD59x18 = SD59x18.wrap(uMAX_WHOLE_SD59x18);
            /// @dev The minimum value an SD59x18 number can have.
            int256 constant uMIN_SD59x18 = -57896044618658097711785492504343953926634992332820282019728_792003956564819968;
            SD59x18 constant MIN_SD59x18 = SD59x18.wrap(uMIN_SD59x18);
            /// @dev The minimum whole value an SD59x18 number can have.
            int256 constant uMIN_WHOLE_SD59x18 = -57896044618658097711785492504343953926634992332820282019728_000000000000000000;
            SD59x18 constant MIN_WHOLE_SD59x18 = SD59x18.wrap(uMIN_WHOLE_SD59x18);
            /// @dev PI as an SD59x18 number.
            SD59x18 constant PI = SD59x18.wrap(3_141592653589793238);
            /// @dev The unit number, which gives the decimal precision of SD59x18.
            int256 constant uUNIT = 1e18;
            SD59x18 constant UNIT = SD59x18.wrap(1e18);
            /// @dev The unit number squared.
            int256 constant uUNIT_SQUARED = 1e36;
            SD59x18 constant UNIT_SQUARED = SD59x18.wrap(uUNIT_SQUARED);
            /// @dev Zero as an SD59x18 number.
            SD59x18 constant ZERO = SD59x18.wrap(0);
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "./Casting.sol" as Casting;
            import "./Helpers.sol" as Helpers;
            import "./Math.sol" as Math;
            /// @notice The signed 59.18-decimal fixed-point number representation, which can have up to 59 digits and up to 18
            /// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
            /// type int256.
            type SD59x18 is int256;
            /*//////////////////////////////////////////////////////////////////////////
                                                CASTING
            //////////////////////////////////////////////////////////////////////////*/
            using {
                Casting.intoInt256,
                Casting.intoSD1x18,
                Casting.intoSD21x18,
                Casting.intoUD2x18,
                Casting.intoUD21x18,
                Casting.intoUD60x18,
                Casting.intoUint256,
                Casting.intoUint128,
                Casting.intoUint40,
                Casting.unwrap
            } for SD59x18 global;
            /*//////////////////////////////////////////////////////////////////////////
                                        MATHEMATICAL FUNCTIONS
            //////////////////////////////////////////////////////////////////////////*/
            using {
                Math.abs,
                Math.avg,
                Math.ceil,
                Math.div,
                Math.exp,
                Math.exp2,
                Math.floor,
                Math.frac,
                Math.gm,
                Math.inv,
                Math.log10,
                Math.log2,
                Math.ln,
                Math.mul,
                Math.pow,
                Math.powu,
                Math.sqrt
            } for SD59x18 global;
            /*//////////////////////////////////////////////////////////////////////////
                                            HELPER FUNCTIONS
            //////////////////////////////////////////////////////////////////////////*/
            using {
                Helpers.add,
                Helpers.and,
                Helpers.eq,
                Helpers.gt,
                Helpers.gte,
                Helpers.isZero,
                Helpers.lshift,
                Helpers.lt,
                Helpers.lte,
                Helpers.mod,
                Helpers.neq,
                Helpers.not,
                Helpers.or,
                Helpers.rshift,
                Helpers.sub,
                Helpers.uncheckedAdd,
                Helpers.uncheckedSub,
                Helpers.uncheckedUnary,
                Helpers.xor
            } for SD59x18 global;
            /*//////////////////////////////////////////////////////////////////////////
                                                OPERATORS
            //////////////////////////////////////////////////////////////////////////*/
            // The global "using for" directive makes it possible to use these operators on the SD59x18 type.
            using {
                Helpers.add as +,
                Helpers.and2 as &,
                Math.div as /,
                Helpers.eq as ==,
                Helpers.gt as >,
                Helpers.gte as >=,
                Helpers.lt as <,
                Helpers.lte as <=,
                Helpers.mod as %,
                Math.mul as *,
                Helpers.neq as !=,
                Helpers.not as ~,
                Helpers.or as |,
                Helpers.sub as -,
                Helpers.unary as -,
                Helpers.xor as ^
            } for SD59x18 global;
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { UD2x18 } from "./ValueType.sol";
            /// @dev Euler's number as a UD2x18 number.
            UD2x18 constant E = UD2x18.wrap(2_718281828459045235);
            /// @dev The maximum value a UD2x18 number can have.
            uint64 constant uMAX_UD2x18 = 18_446744073709551615;
            UD2x18 constant MAX_UD2x18 = UD2x18.wrap(uMAX_UD2x18);
            /// @dev PI as a UD2x18 number.
            UD2x18 constant PI = UD2x18.wrap(3_141592653589793238);
            /// @dev The unit number, which gives the decimal precision of UD2x18.
            UD2x18 constant UNIT = UD2x18.wrap(1e18);
            uint64 constant uUNIT = 1e18;
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { UD21x18 } from "./ValueType.sol";
            /// @dev Euler's number as a UD21x18 number.
            UD21x18 constant E = UD21x18.wrap(2_718281828459045235);
            /// @dev The maximum value a UD21x18 number can have.
            uint128 constant uMAX_UD21x18 = 340282366920938463463_374607431768211455;
            UD21x18 constant MAX_UD21x18 = UD21x18.wrap(uMAX_UD21x18);
            /// @dev PI as a UD21x18 number.
            UD21x18 constant PI = UD21x18.wrap(3_141592653589793238);
            /// @dev The unit number, which gives the decimal precision of UD21x18.
            uint256 constant uUNIT = 1e18;
            UD21x18 constant UNIT = UD21x18.wrap(1e18);
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "./Casting.sol" as Casting;
            /// @notice The unsigned 2.18-decimal fixed-point number representation, which can have up to 2 digits and up to 18
            /// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
            /// type uint64. This is useful when end users want to use uint64 to save gas, e.g. with tight variable packing in contract
            /// storage.
            type UD2x18 is uint64;
            /*//////////////////////////////////////////////////////////////////////////
                                                CASTING
            //////////////////////////////////////////////////////////////////////////*/
            using {
                Casting.intoSD59x18,
                Casting.intoUD60x18,
                Casting.intoUint128,
                Casting.intoUint256,
                Casting.intoUint40,
                Casting.unwrap
            } for UD2x18 global;
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "./Casting.sol" as Casting;
            /// @notice The unsigned 21.18-decimal fixed-point number representation, which can have up to 21 digits and up to 18
            /// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
            /// type uint128. This is useful when end users want to use uint128 to save gas, e.g. with tight variable packing in contract
            /// storage.
            type UD21x18 is uint128;
            /*//////////////////////////////////////////////////////////////////////////
                                                CASTING
            //////////////////////////////////////////////////////////////////////////*/
            using {
                Casting.intoSD59x18,
                Casting.intoUD60x18,
                Casting.intoUint128,
                Casting.intoUint256,
                Casting.intoUint40,
                Casting.unwrap
            } for UD21x18 global;
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Metadata.sol)
            pragma solidity ^0.8.20;
            import {IERC721} from "../IERC721.sol";
            /**
             * @title ERC-721 Non-Fungible Token Standard, optional metadata extension
             * @dev See https://eips.ethereum.org/EIPS/eip-721
             */
            interface IERC721Metadata is IERC721 {
                /**
                 * @dev Returns the token collection name.
                 */
                function name() external view returns (string memory);
                /**
                 * @dev Returns the token collection symbol.
                 */
                function symbol() external view returns (string memory);
                /**
                 * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
                 */
                function tokenURI(uint256 tokenId) external view returns (string memory);
            }
            // SPDX-License-Identifier: GPL-3.0-or-later
            pragma solidity >=0.8.19;
            import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
            import { UD60x18 } from "@prb/math/src/UD60x18.sol";
            import { IAdminable } from "./IAdminable.sol";
            import { ISablierV2Comptroller } from "./ISablierV2Comptroller.sol";
            /// @title ISablierV2Base
            /// @notice Base logic for all Sablier V2 streaming contracts.
            interface ISablierV2Base is IAdminable {
                /*//////////////////////////////////////////////////////////////////////////
                                                   EVENTS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Emitted when the admin claims all protocol revenues accrued for a particular ERC-20 asset.
                /// @param admin The address of the contract admin.
                /// @param asset The contract address of the ERC-20 asset the protocol revenues have been claimed for.
                /// @param protocolRevenues The amount of protocol revenues claimed, denoted in units of the asset's decimals.
                event ClaimProtocolRevenues(address indexed admin, IERC20 indexed asset, uint128 protocolRevenues);
                /// @notice Emitted when the admin sets a new comptroller contract.
                /// @param admin The address of the contract admin.
                /// @param oldComptroller The address of the old comptroller contract.
                /// @param newComptroller The address of the new comptroller contract.
                event SetComptroller(
                    address indexed admin, ISablierV2Comptroller oldComptroller, ISablierV2Comptroller newComptroller
                );
                /*//////////////////////////////////////////////////////////////////////////
                                             CONSTANT FUNCTIONS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Retrieves the maximum fee that can be charged by the protocol or a broker, denoted as a fixed-point
                /// number where 1e18 is 100%.
                /// @dev This value is hard coded as a constant.
                function MAX_FEE() external view returns (UD60x18);
                /// @notice Retrieves the address of the comptroller contract, responsible for the Sablier V2 protocol
                /// configuration.
                function comptroller() external view returns (ISablierV2Comptroller);
                /// @notice Retrieves the protocol revenues accrued for the provided ERC-20 asset, in units of the asset's
                /// decimals.
                /// @param asset The contract address of the ERC-20 asset to query.
                function protocolRevenues(IERC20 asset) external view returns (uint128 revenues);
                /*//////////////////////////////////////////////////////////////////////////
                                           NON-CONSTANT FUNCTIONS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Claims all accumulated protocol revenues for the provided ERC-20 asset.
                ///
                /// @dev Emits a {ClaimProtocolRevenues} event.
                ///
                /// Requirements:
                /// - `msg.sender` must be the contract admin.
                ///
                /// @param asset The contract address of the ERC-20 asset for which to claim protocol revenues.
                function claimProtocolRevenues(IERC20 asset) external;
                /// @notice Assigns a new comptroller contract responsible for the protocol configuration.
                ///
                /// @dev Emits a {SetComptroller} event.
                ///
                /// Notes:
                /// - Does not revert if the comptroller is the same.
                ///
                /// Requirements:
                /// - `msg.sender` must be the contract admin.
                ///
                /// @param newComptroller The address of the new comptroller contract.
                function setComptroller(ISablierV2Comptroller newComptroller) external;
            }
            // SPDX-License-Identifier: GPL-3.0-or-later
            pragma solidity >=0.8.19;
            import { IERC721Metadata } from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
            /// @title ISablierV2NFTDescriptor
            /// @notice This contract generates the URI describing the Sablier V2 stream NFTs.
            /// @dev Inspired by Uniswap V3 Positions NFTs.
            interface ISablierV2NFTDescriptor {
                /// @notice Produces the URI describing a particular stream NFT.
                /// @dev This is a data URI with the JSON contents directly inlined.
                /// @param sablier The address of the Sablier contract the stream was created in.
                /// @param streamId The id of the stream for which to produce a description.
                /// @return uri The URI of the ERC721-compliant metadata.
                function tokenURI(IERC721Metadata sablier, uint256 streamId) external view returns (string memory uri);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "../Common.sol" as Common;
            import "./Errors.sol" as Errors;
            import { SD59x18 } from "../sd59x18/ValueType.sol";
            import { UD60x18 } from "../ud60x18/ValueType.sol";
            import { UD2x18 } from "./ValueType.sol";
            /// @notice Casts a UD2x18 number into SD59x18.
            /// @dev There is no overflow check because UD2x18 ⊆ SD59x18.
            function intoSD59x18(UD2x18 x) pure returns (SD59x18 result) {
                result = SD59x18.wrap(int256(uint256(UD2x18.unwrap(x))));
            }
            /// @notice Casts a UD2x18 number into UD60x18.
            /// @dev There is no overflow check because UD2x18 ⊆ UD60x18.
            function intoUD60x18(UD2x18 x) pure returns (UD60x18 result) {
                result = UD60x18.wrap(UD2x18.unwrap(x));
            }
            /// @notice Casts a UD2x18 number into uint128.
            /// @dev There is no overflow check because UD2x18 ⊆ uint128.
            function intoUint128(UD2x18 x) pure returns (uint128 result) {
                result = uint128(UD2x18.unwrap(x));
            }
            /// @notice Casts a UD2x18 number into uint256.
            /// @dev There is no overflow check because UD2x18 ⊆ uint256.
            function intoUint256(UD2x18 x) pure returns (uint256 result) {
                result = uint256(UD2x18.unwrap(x));
            }
            /// @notice Casts a UD2x18 number into uint40.
            /// @dev Requirements:
            /// - x ≤ MAX_UINT40
            function intoUint40(UD2x18 x) pure returns (uint40 result) {
                uint64 xUint = UD2x18.unwrap(x);
                if (xUint > uint64(Common.MAX_UINT40)) {
                    revert Errors.PRBMath_UD2x18_IntoUint40_Overflow(x);
                }
                result = uint40(xUint);
            }
            /// @notice Alias for {wrap}.
            function ud2x18(uint64 x) pure returns (UD2x18 result) {
                result = UD2x18.wrap(x);
            }
            /// @notice Unwrap a UD2x18 number into uint64.
            function unwrap(UD2x18 x) pure returns (uint64 result) {
                result = UD2x18.unwrap(x);
            }
            /// @notice Wraps a uint64 number into UD2x18.
            function wrap(uint64 x) pure returns (UD2x18 result) {
                result = UD2x18.wrap(x);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { UD2x18 } from "./ValueType.sol";
            /// @notice Thrown when trying to cast a UD2x18 number that doesn't fit in uint40.
            error PRBMath_UD2x18_IntoUint40_Overflow(UD2x18 x);
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "../Common.sol" as Common;
            import "./Errors.sol" as CastingErrors;
            import { SD59x18 } from "../sd59x18/ValueType.sol";
            import { UD60x18 } from "../ud60x18/ValueType.sol";
            import { SD1x18 } from "./ValueType.sol";
            /// @notice Casts an SD1x18 number into SD59x18.
            /// @dev There is no overflow check because SD1x18 ⊆ SD59x18.
            function intoSD59x18(SD1x18 x) pure returns (SD59x18 result) {
                result = SD59x18.wrap(int256(SD1x18.unwrap(x)));
            }
            /// @notice Casts an SD1x18 number into UD60x18.
            /// @dev Requirements:
            /// - x ≥ 0
            function intoUD60x18(SD1x18 x) pure returns (UD60x18 result) {
                int64 xInt = SD1x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD1x18_ToUD60x18_Underflow(x);
                }
                result = UD60x18.wrap(uint64(xInt));
            }
            /// @notice Casts an SD1x18 number into uint128.
            /// @dev Requirements:
            /// - x ≥ 0
            function intoUint128(SD1x18 x) pure returns (uint128 result) {
                int64 xInt = SD1x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD1x18_ToUint128_Underflow(x);
                }
                result = uint128(uint64(xInt));
            }
            /// @notice Casts an SD1x18 number into uint256.
            /// @dev Requirements:
            /// - x ≥ 0
            function intoUint256(SD1x18 x) pure returns (uint256 result) {
                int64 xInt = SD1x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD1x18_ToUint256_Underflow(x);
                }
                result = uint256(uint64(xInt));
            }
            /// @notice Casts an SD1x18 number into uint40.
            /// @dev Requirements:
            /// - x ≥ 0
            /// - x ≤ MAX_UINT40
            function intoUint40(SD1x18 x) pure returns (uint40 result) {
                int64 xInt = SD1x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD1x18_ToUint40_Underflow(x);
                }
                if (xInt > int64(uint64(Common.MAX_UINT40))) {
                    revert CastingErrors.PRBMath_SD1x18_ToUint40_Overflow(x);
                }
                result = uint40(uint64(xInt));
            }
            /// @notice Alias for {wrap}.
            function sd1x18(int64 x) pure returns (SD1x18 result) {
                result = SD1x18.wrap(x);
            }
            /// @notice Unwraps an SD1x18 number into int64.
            function unwrap(SD1x18 x) pure returns (int64 result) {
                result = SD1x18.unwrap(x);
            }
            /// @notice Wraps an int64 number into SD1x18.
            function wrap(int64 x) pure returns (SD1x18 result) {
                result = SD1x18.wrap(x);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "../Common.sol" as Common;
            import "./Errors.sol" as CastingErrors;
            import { SD59x18 } from "../sd59x18/ValueType.sol";
            import { UD60x18 } from "../ud60x18/ValueType.sol";
            import { SD21x18 } from "./ValueType.sol";
            /// @notice Casts an SD21x18 number into SD59x18.
            /// @dev There is no overflow check because SD21x18 ⊆ SD59x18.
            function intoSD59x18(SD21x18 x) pure returns (SD59x18 result) {
                result = SD59x18.wrap(int256(SD21x18.unwrap(x)));
            }
            /// @notice Casts an SD21x18 number into UD60x18.
            /// @dev Requirements:
            /// - x ≥ 0
            function intoUD60x18(SD21x18 x) pure returns (UD60x18 result) {
                int128 xInt = SD21x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD21x18_ToUD60x18_Underflow(x);
                }
                result = UD60x18.wrap(uint128(xInt));
            }
            /// @notice Casts an SD21x18 number into uint128.
            /// @dev Requirements:
            /// - x ≥ 0
            function intoUint128(SD21x18 x) pure returns (uint128 result) {
                int128 xInt = SD21x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD21x18_ToUint128_Underflow(x);
                }
                result = uint128(xInt);
            }
            /// @notice Casts an SD21x18 number into uint256.
            /// @dev Requirements:
            /// - x ≥ 0
            function intoUint256(SD21x18 x) pure returns (uint256 result) {
                int128 xInt = SD21x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD21x18_ToUint256_Underflow(x);
                }
                result = uint256(uint128(xInt));
            }
            /// @notice Casts an SD21x18 number into uint40.
            /// @dev Requirements:
            /// - x ≥ 0
            /// - x ≤ MAX_UINT40
            function intoUint40(SD21x18 x) pure returns (uint40 result) {
                int128 xInt = SD21x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD21x18_ToUint40_Underflow(x);
                }
                if (xInt > int128(uint128(Common.MAX_UINT40))) {
                    revert CastingErrors.PRBMath_SD21x18_ToUint40_Overflow(x);
                }
                result = uint40(uint128(xInt));
            }
            /// @notice Alias for {wrap}.
            function sd21x18(int128 x) pure returns (SD21x18 result) {
                result = SD21x18.wrap(x);
            }
            /// @notice Unwraps an SD21x18 number into int128.
            function unwrap(SD21x18 x) pure returns (int128 result) {
                result = SD21x18.unwrap(x);
            }
            /// @notice Wraps an int128 number into SD21x18.
            function wrap(int128 x) pure returns (SD21x18 result) {
                result = SD21x18.wrap(x);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "./Errors.sol" as CastingErrors;
            import { MAX_UINT128, MAX_UINT40 } from "../Common.sol";
            import { uMAX_SD1x18, uMIN_SD1x18 } from "../sd1x18/Constants.sol";
            import { SD1x18 } from "../sd1x18/ValueType.sol";
            import { uMAX_SD21x18, uMIN_SD21x18 } from "../sd21x18/Constants.sol";
            import { SD21x18 } from "../sd21x18/ValueType.sol";
            import { uMAX_UD2x18 } from "../ud2x18/Constants.sol";
            import { UD2x18 } from "../ud2x18/ValueType.sol";
            import { uMAX_UD21x18 } from "../ud21x18/Constants.sol";
            import { UD21x18 } from "../ud21x18/ValueType.sol";
            import { UD60x18 } from "../ud60x18/ValueType.sol";
            import { SD59x18 } from "./ValueType.sol";
            /// @notice Casts an SD59x18 number into int256.
            /// @dev This is basically a functional alias for {unwrap}.
            function intoInt256(SD59x18 x) pure returns (int256 result) {
                result = SD59x18.unwrap(x);
            }
            /// @notice Casts an SD59x18 number into SD1x18.
            /// @dev Requirements:
            /// - x ≥ uMIN_SD1x18
            /// - x ≤ uMAX_SD1x18
            function intoSD1x18(SD59x18 x) pure returns (SD1x18 result) {
                int256 xInt = SD59x18.unwrap(x);
                if (xInt < uMIN_SD1x18) {
                    revert CastingErrors.PRBMath_SD59x18_IntoSD1x18_Underflow(x);
                }
                if (xInt > uMAX_SD1x18) {
                    revert CastingErrors.PRBMath_SD59x18_IntoSD1x18_Overflow(x);
                }
                result = SD1x18.wrap(int64(xInt));
            }
            /// @notice Casts an SD59x18 number into SD21x18.
            /// @dev Requirements:
            /// - x ≥ uMIN_SD21x18
            /// - x ≤ uMAX_SD21x18
            function intoSD21x18(SD59x18 x) pure returns (SD21x18 result) {
                int256 xInt = SD59x18.unwrap(x);
                if (xInt < uMIN_SD21x18) {
                    revert CastingErrors.PRBMath_SD59x18_IntoSD21x18_Underflow(x);
                }
                if (xInt > uMAX_SD21x18) {
                    revert CastingErrors.PRBMath_SD59x18_IntoSD21x18_Overflow(x);
                }
                result = SD21x18.wrap(int128(xInt));
            }
            /// @notice Casts an SD59x18 number into UD2x18.
            /// @dev Requirements:
            /// - x ≥ 0
            /// - x ≤ uMAX_UD2x18
            function intoUD2x18(SD59x18 x) pure returns (UD2x18 result) {
                int256 xInt = SD59x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD59x18_IntoUD2x18_Underflow(x);
                }
                if (xInt > int256(uint256(uMAX_UD2x18))) {
                    revert CastingErrors.PRBMath_SD59x18_IntoUD2x18_Overflow(x);
                }
                result = UD2x18.wrap(uint64(uint256(xInt)));
            }
            /// @notice Casts an SD59x18 number into UD21x18.
            /// @dev Requirements:
            /// - x ≥ 0
            /// - x ≤ uMAX_UD21x18
            function intoUD21x18(SD59x18 x) pure returns (UD21x18 result) {
                int256 xInt = SD59x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD59x18_IntoUD21x18_Underflow(x);
                }
                if (xInt > int256(uint256(uMAX_UD21x18))) {
                    revert CastingErrors.PRBMath_SD59x18_IntoUD21x18_Overflow(x);
                }
                result = UD21x18.wrap(uint128(uint256(xInt)));
            }
            /// @notice Casts an SD59x18 number into UD60x18.
            /// @dev Requirements:
            /// - x ≥ 0
            function intoUD60x18(SD59x18 x) pure returns (UD60x18 result) {
                int256 xInt = SD59x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD59x18_IntoUD60x18_Underflow(x);
                }
                result = UD60x18.wrap(uint256(xInt));
            }
            /// @notice Casts an SD59x18 number into uint256.
            /// @dev Requirements:
            /// - x ≥ 0
            function intoUint256(SD59x18 x) pure returns (uint256 result) {
                int256 xInt = SD59x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD59x18_IntoUint256_Underflow(x);
                }
                result = uint256(xInt);
            }
            /// @notice Casts an SD59x18 number into uint128.
            /// @dev Requirements:
            /// - x ≥ 0
            /// - x ≤ uMAX_UINT128
            function intoUint128(SD59x18 x) pure returns (uint128 result) {
                int256 xInt = SD59x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD59x18_IntoUint128_Underflow(x);
                }
                if (xInt > int256(uint256(MAX_UINT128))) {
                    revert CastingErrors.PRBMath_SD59x18_IntoUint128_Overflow(x);
                }
                result = uint128(uint256(xInt));
            }
            /// @notice Casts an SD59x18 number into uint40.
            /// @dev Requirements:
            /// - x ≥ 0
            /// - x ≤ MAX_UINT40
            function intoUint40(SD59x18 x) pure returns (uint40 result) {
                int256 xInt = SD59x18.unwrap(x);
                if (xInt < 0) {
                    revert CastingErrors.PRBMath_SD59x18_IntoUint40_Underflow(x);
                }
                if (xInt > int256(uint256(MAX_UINT40))) {
                    revert CastingErrors.PRBMath_SD59x18_IntoUint40_Overflow(x);
                }
                result = uint40(uint256(xInt));
            }
            /// @notice Alias for {wrap}.
            function sd(int256 x) pure returns (SD59x18 result) {
                result = SD59x18.wrap(x);
            }
            /// @notice Alias for {wrap}.
            function sd59x18(int256 x) pure returns (SD59x18 result) {
                result = SD59x18.wrap(x);
            }
            /// @notice Unwraps an SD59x18 number into int256.
            function unwrap(SD59x18 x) pure returns (int256 result) {
                result = SD59x18.unwrap(x);
            }
            /// @notice Wraps an int256 number into SD59x18.
            function wrap(int256 x) pure returns (SD59x18 result) {
                result = SD59x18.wrap(x);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { wrap } from "./Casting.sol";
            import { SD59x18 } from "./ValueType.sol";
            /// @notice Implements the checked addition operation (+) in the SD59x18 type.
            function add(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                return wrap(x.unwrap() + y.unwrap());
            }
            /// @notice Implements the AND (&) bitwise operation in the SD59x18 type.
            function and(SD59x18 x, int256 bits) pure returns (SD59x18 result) {
                return wrap(x.unwrap() & bits);
            }
            /// @notice Implements the AND (&) bitwise operation in the SD59x18 type.
            function and2(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                return wrap(x.unwrap() & y.unwrap());
            }
            /// @notice Implements the equal (=) operation in the SD59x18 type.
            function eq(SD59x18 x, SD59x18 y) pure returns (bool result) {
                result = x.unwrap() == y.unwrap();
            }
            /// @notice Implements the greater than operation (>) in the SD59x18 type.
            function gt(SD59x18 x, SD59x18 y) pure returns (bool result) {
                result = x.unwrap() > y.unwrap();
            }
            /// @notice Implements the greater than or equal to operation (>=) in the SD59x18 type.
            function gte(SD59x18 x, SD59x18 y) pure returns (bool result) {
                result = x.unwrap() >= y.unwrap();
            }
            /// @notice Implements a zero comparison check function in the SD59x18 type.
            function isZero(SD59x18 x) pure returns (bool result) {
                result = x.unwrap() == 0;
            }
            /// @notice Implements the left shift operation (<<) in the SD59x18 type.
            function lshift(SD59x18 x, uint256 bits) pure returns (SD59x18 result) {
                result = wrap(x.unwrap() << bits);
            }
            /// @notice Implements the lower than operation (<) in the SD59x18 type.
            function lt(SD59x18 x, SD59x18 y) pure returns (bool result) {
                result = x.unwrap() < y.unwrap();
            }
            /// @notice Implements the lower than or equal to operation (<=) in the SD59x18 type.
            function lte(SD59x18 x, SD59x18 y) pure returns (bool result) {
                result = x.unwrap() <= y.unwrap();
            }
            /// @notice Implements the unchecked modulo operation (%) in the SD59x18 type.
            function mod(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                result = wrap(x.unwrap() % y.unwrap());
            }
            /// @notice Implements the not equal operation (!=) in the SD59x18 type.
            function neq(SD59x18 x, SD59x18 y) pure returns (bool result) {
                result = x.unwrap() != y.unwrap();
            }
            /// @notice Implements the NOT (~) bitwise operation in the SD59x18 type.
            function not(SD59x18 x) pure returns (SD59x18 result) {
                result = wrap(~x.unwrap());
            }
            /// @notice Implements the OR (|) bitwise operation in the SD59x18 type.
            function or(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                result = wrap(x.unwrap() | y.unwrap());
            }
            /// @notice Implements the right shift operation (>>) in the SD59x18 type.
            function rshift(SD59x18 x, uint256 bits) pure returns (SD59x18 result) {
                result = wrap(x.unwrap() >> bits);
            }
            /// @notice Implements the checked subtraction operation (-) in the SD59x18 type.
            function sub(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                result = wrap(x.unwrap() - y.unwrap());
            }
            /// @notice Implements the checked unary minus operation (-) in the SD59x18 type.
            function unary(SD59x18 x) pure returns (SD59x18 result) {
                result = wrap(-x.unwrap());
            }
            /// @notice Implements the unchecked addition operation (+) in the SD59x18 type.
            function uncheckedAdd(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                unchecked {
                    result = wrap(x.unwrap() + y.unwrap());
                }
            }
            /// @notice Implements the unchecked subtraction operation (-) in the SD59x18 type.
            function uncheckedSub(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                unchecked {
                    result = wrap(x.unwrap() - y.unwrap());
                }
            }
            /// @notice Implements the unchecked unary minus operation (-) in the SD59x18 type.
            function uncheckedUnary(SD59x18 x) pure returns (SD59x18 result) {
                unchecked {
                    result = wrap(-x.unwrap());
                }
            }
            /// @notice Implements the XOR (^) bitwise operation in the SD59x18 type.
            function xor(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                result = wrap(x.unwrap() ^ y.unwrap());
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "../Common.sol" as Common;
            import "./Errors.sol" as Errors;
            import {
                uEXP_MAX_INPUT,
                uEXP2_MAX_INPUT,
                uEXP_MIN_THRESHOLD,
                uEXP2_MIN_THRESHOLD,
                uHALF_UNIT,
                uLOG2_10,
                uLOG2_E,
                uMAX_SD59x18,
                uMAX_WHOLE_SD59x18,
                uMIN_SD59x18,
                uMIN_WHOLE_SD59x18,
                UNIT,
                uUNIT,
                uUNIT_SQUARED,
                ZERO
            } from "./Constants.sol";
            import { wrap } from "./Helpers.sol";
            import { SD59x18 } from "./ValueType.sol";
            /// @notice Calculates the absolute value of x.
            ///
            /// @dev Requirements:
            /// - x > MIN_SD59x18.
            ///
            /// @param x The SD59x18 number for which to calculate the absolute value.
            /// @return result The absolute value of x as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function abs(SD59x18 x) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                if (xInt == uMIN_SD59x18) {
                    revert Errors.PRBMath_SD59x18_Abs_MinSD59x18();
                }
                result = xInt < 0 ? wrap(-xInt) : x;
            }
            /// @notice Calculates the arithmetic average of x and y.
            ///
            /// @dev Notes:
            /// - The result is rounded toward zero.
            ///
            /// @param x The first operand as an SD59x18 number.
            /// @param y The second operand as an SD59x18 number.
            /// @return result The arithmetic average as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function avg(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                int256 yInt = y.unwrap();
                unchecked {
                    // This operation is equivalent to `x / 2 +  y / 2`, and it can never overflow.
                    int256 sum = (xInt >> 1) + (yInt >> 1);
                    if (sum < 0) {
                        // If at least one of x and y is odd, add 1 to the result, because shifting negative numbers to the right
                        // rounds toward negative infinity. The right part is equivalent to `sum + (x % 2 == 1 || y % 2 == 1)`.
                        assembly ("memory-safe") {
                            result := add(sum, and(or(xInt, yInt), 1))
                        }
                    } else {
                        // Add 1 if both x and y are odd to account for the double 0.5 remainder truncated after shifting.
                        result = wrap(sum + (xInt & yInt & 1));
                    }
                }
            }
            /// @notice Yields the smallest whole number greater than or equal to x.
            ///
            /// @dev Optimized for fractional value inputs, because every whole value has (1e18 - 1) fractional counterparts.
            /// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
            ///
            /// Requirements:
            /// - x ≤ MAX_WHOLE_SD59x18
            ///
            /// @param x The SD59x18 number to ceil.
            /// @return result The smallest whole number greater than or equal to x, as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function ceil(SD59x18 x) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                if (xInt > uMAX_WHOLE_SD59x18) {
                    revert Errors.PRBMath_SD59x18_Ceil_Overflow(x);
                }
                int256 remainder = xInt % uUNIT;
                if (remainder == 0) {
                    result = x;
                } else {
                    unchecked {
                        // Solidity uses C fmod style, which returns a modulus with the same sign as x.
                        int256 resultInt = xInt - remainder;
                        if (xInt > 0) {
                            resultInt += uUNIT;
                        }
                        result = wrap(resultInt);
                    }
                }
            }
            /// @notice Divides two SD59x18 numbers, returning a new SD59x18 number.
            ///
            /// @dev This is an extension of {Common.mulDiv} for signed numbers, which works by computing the signs and the absolute
            /// values separately.
            ///
            /// Notes:
            /// - Refer to the notes in {Common.mulDiv}.
            /// - The result is rounded toward zero.
            ///
            /// Requirements:
            /// - Refer to the requirements in {Common.mulDiv}.
            /// - None of the inputs can be `MIN_SD59x18`.
            /// - The denominator must not be zero.
            /// - The result must fit in SD59x18.
            ///
            /// @param x The numerator as an SD59x18 number.
            /// @param y The denominator as an SD59x18 number.
            /// @return result The quotient as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function div(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                int256 yInt = y.unwrap();
                if (xInt == uMIN_SD59x18 || yInt == uMIN_SD59x18) {
                    revert Errors.PRBMath_SD59x18_Div_InputTooSmall();
                }
                // Get hold of the absolute values of x and y.
                uint256 xAbs;
                uint256 yAbs;
                unchecked {
                    xAbs = xInt < 0 ? uint256(-xInt) : uint256(xInt);
                    yAbs = yInt < 0 ? uint256(-yInt) : uint256(yInt);
                }
                // Compute the absolute value (x*UNIT÷y). The resulting value must fit in SD59x18.
                uint256 resultAbs = Common.mulDiv(xAbs, uint256(uUNIT), yAbs);
                if (resultAbs > uint256(uMAX_SD59x18)) {
                    revert Errors.PRBMath_SD59x18_Div_Overflow(x, y);
                }
                // Check if x and y have the same sign using two's complement representation. The left-most bit represents the sign (1 for
                // negative, 0 for positive or zero).
                bool sameSign = (xInt ^ yInt) > -1;
                // If the inputs have the same sign, the result should be positive. Otherwise, it should be negative.
                unchecked {
                    result = wrap(sameSign ? int256(resultAbs) : -int256(resultAbs));
                }
            }
            /// @notice Calculates the natural exponent of x using the following formula:
            ///
            /// $$
            /// e^x = 2^{x * log_2{e}}
            /// $$
            ///
            /// @dev Notes:
            /// - Refer to the notes in {exp2}.
            ///
            /// Requirements:
            /// - Refer to the requirements in {exp2}.
            /// - x < 133_084258667509499441.
            ///
            /// @param x The exponent as an SD59x18 number.
            /// @return result The result as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function exp(SD59x18 x) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                // Any input less than the threshold returns zero.
                // This check also prevents an overflow for very small numbers.
                if (xInt < uEXP_MIN_THRESHOLD) {
                    return ZERO;
                }
                // This check prevents values greater than 192e18 from being passed to {exp2}.
                if (xInt > uEXP_MAX_INPUT) {
                    revert Errors.PRBMath_SD59x18_Exp_InputTooBig(x);
                }
                unchecked {
                    // Inline the fixed-point multiplication to save gas.
                    int256 doubleUnitProduct = xInt * uLOG2_E;
                    result = exp2(wrap(doubleUnitProduct / uUNIT));
                }
            }
            /// @notice Calculates the binary exponent of x using the binary fraction method using the following formula:
            ///
            /// $$
            /// 2^{-x} = \\frac{1}{2^x}
            /// $$
            ///
            /// @dev See https://ethereum.stackexchange.com/q/79903/24693.
            ///
            /// Notes:
            /// - If x < -59_794705707972522261, the result is zero.
            ///
            /// Requirements:
            /// - x < 192e18.
            /// - The result must fit in SD59x18.
            ///
            /// @param x The exponent as an SD59x18 number.
            /// @return result The result as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function exp2(SD59x18 x) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                if (xInt < 0) {
                    // The inverse of any number less than the threshold is truncated to zero.
                    if (xInt < uEXP2_MIN_THRESHOLD) {
                        return ZERO;
                    }
                    unchecked {
                        // Inline the fixed-point inversion to save gas.
                        result = wrap(uUNIT_SQUARED / exp2(wrap(-xInt)).unwrap());
                    }
                } else {
                    // Numbers greater than or equal to 192e18 don't fit in the 192.64-bit format.
                    if (xInt > uEXP2_MAX_INPUT) {
                        revert Errors.PRBMath_SD59x18_Exp2_InputTooBig(x);
                    }
                    unchecked {
                        // Convert x to the 192.64-bit fixed-point format.
                        uint256 x_192x64 = uint256((xInt << 64) / uUNIT);
                        // It is safe to cast the result to int256 due to the checks above.
                        result = wrap(int256(Common.exp2(x_192x64)));
                    }
                }
            }
            /// @notice Yields the greatest whole number less than or equal to x.
            ///
            /// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional
            /// counterparts. See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
            ///
            /// Requirements:
            /// - x ≥ MIN_WHOLE_SD59x18
            ///
            /// @param x The SD59x18 number to floor.
            /// @return result The greatest whole number less than or equal to x, as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function floor(SD59x18 x) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                if (xInt < uMIN_WHOLE_SD59x18) {
                    revert Errors.PRBMath_SD59x18_Floor_Underflow(x);
                }
                int256 remainder = xInt % uUNIT;
                if (remainder == 0) {
                    result = x;
                } else {
                    unchecked {
                        // Solidity uses C fmod style, which returns a modulus with the same sign as x.
                        int256 resultInt = xInt - remainder;
                        if (xInt < 0) {
                            resultInt -= uUNIT;
                        }
                        result = wrap(resultInt);
                    }
                }
            }
            /// @notice Yields the excess beyond the floor of x for positive numbers and the part of the number to the right.
            /// of the radix point for negative numbers.
            /// @dev Based on the odd function definition. https://en.wikipedia.org/wiki/Fractional_part
            /// @param x The SD59x18 number to get the fractional part of.
            /// @return result The fractional part of x as an SD59x18 number.
            function frac(SD59x18 x) pure returns (SD59x18 result) {
                result = wrap(x.unwrap() % uUNIT);
            }
            /// @notice Calculates the geometric mean of x and y, i.e. $\\sqrt{x * y}$.
            ///
            /// @dev Notes:
            /// - The result is rounded toward zero.
            ///
            /// Requirements:
            /// - x * y must fit in SD59x18.
            /// - x * y must not be negative, since complex numbers are not supported.
            ///
            /// @param x The first operand as an SD59x18 number.
            /// @param y The second operand as an SD59x18 number.
            /// @return result The result as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function gm(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                int256 yInt = y.unwrap();
                if (xInt == 0 || yInt == 0) {
                    return ZERO;
                }
                unchecked {
                    // Equivalent to `xy / x != y`. Checking for overflow this way is faster than letting Solidity do it.
                    int256 xyInt = xInt * yInt;
                    if (xyInt / xInt != yInt) {
                        revert Errors.PRBMath_SD59x18_Gm_Overflow(x, y);
                    }
                    // The product must not be negative, since complex numbers are not supported.
                    if (xyInt < 0) {
                        revert Errors.PRBMath_SD59x18_Gm_NegativeProduct(x, y);
                    }
                    // We don't need to multiply the result by `UNIT` here because the x*y product picked up a factor of `UNIT`
                    // during multiplication. See the comments in {Common.sqrt}.
                    uint256 resultUint = Common.sqrt(uint256(xyInt));
                    result = wrap(int256(resultUint));
                }
            }
            /// @notice Calculates the inverse of x.
            ///
            /// @dev Notes:
            /// - The result is rounded toward zero.
            ///
            /// Requirements:
            /// - x must not be zero.
            ///
            /// @param x The SD59x18 number for which to calculate the inverse.
            /// @return result The inverse as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function inv(SD59x18 x) pure returns (SD59x18 result) {
                result = wrap(uUNIT_SQUARED / x.unwrap());
            }
            /// @notice Calculates the natural logarithm of x using the following formula:
            ///
            /// $$
            /// ln{x} = log_2{x} / log_2{e}
            /// $$
            ///
            /// @dev Notes:
            /// - Refer to the notes in {log2}.
            /// - The precision isn't sufficiently fine-grained to return exactly `UNIT` when the input is `E`.
            ///
            /// Requirements:
            /// - Refer to the requirements in {log2}.
            ///
            /// @param x The SD59x18 number for which to calculate the natural logarithm.
            /// @return result The natural logarithm as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function ln(SD59x18 x) pure returns (SD59x18 result) {
                // Inline the fixed-point multiplication to save gas. This is overflow-safe because the maximum value that
                // {log2} can return is ~195_205294292027477728.
                result = wrap(log2(x).unwrap() * uUNIT / uLOG2_E);
            }
            /// @notice Calculates the common logarithm of x using the following formula:
            ///
            /// $$
            /// log_{10}{x} = log_2{x} / log_2{10}
            /// $$
            ///
            /// However, if x is an exact power of ten, a hard coded value is returned.
            ///
            /// @dev Notes:
            /// - Refer to the notes in {log2}.
            ///
            /// Requirements:
            /// - Refer to the requirements in {log2}.
            ///
            /// @param x The SD59x18 number for which to calculate the common logarithm.
            /// @return result The common logarithm as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function log10(SD59x18 x) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                if (xInt < 0) {
                    revert Errors.PRBMath_SD59x18_Log_InputTooSmall(x);
                }
                // Note that the `mul` in this block is the standard multiplication operation, not {SD59x18.mul}.
                // prettier-ignore
                assembly ("memory-safe") {
                    switch x
                    case 1 { result := mul(uUNIT, sub(0, 18)) }
                    case 10 { result := mul(uUNIT, sub(1, 18)) }
                    case 100 { result := mul(uUNIT, sub(2, 18)) }
                    case 1000 { result := mul(uUNIT, sub(3, 18)) }
                    case 10000 { result := mul(uUNIT, sub(4, 18)) }
                    case 100000 { result := mul(uUNIT, sub(5, 18)) }
                    case 1000000 { result := mul(uUNIT, sub(6, 18)) }
                    case 10000000 { result := mul(uUNIT, sub(7, 18)) }
                    case 100000000 { result := mul(uUNIT, sub(8, 18)) }
                    case 1000000000 { result := mul(uUNIT, sub(9, 18)) }
                    case 10000000000 { result := mul(uUNIT, sub(10, 18)) }
                    case 100000000000 { result := mul(uUNIT, sub(11, 18)) }
                    case 1000000000000 { result := mul(uUNIT, sub(12, 18)) }
                    case 10000000000000 { result := mul(uUNIT, sub(13, 18)) }
                    case 100000000000000 { result := mul(uUNIT, sub(14, 18)) }
                    case 1000000000000000 { result := mul(uUNIT, sub(15, 18)) }
                    case 10000000000000000 { result := mul(uUNIT, sub(16, 18)) }
                    case 100000000000000000 { result := mul(uUNIT, sub(17, 18)) }
                    case 1000000000000000000 { result := 0 }
                    case 10000000000000000000 { result := uUNIT }
                    case 100000000000000000000 { result := mul(uUNIT, 2) }
                    case 1000000000000000000000 { result := mul(uUNIT, 3) }
                    case 10000000000000000000000 { result := mul(uUNIT, 4) }
                    case 100000000000000000000000 { result := mul(uUNIT, 5) }
                    case 1000000000000000000000000 { result := mul(uUNIT, 6) }
                    case 10000000000000000000000000 { result := mul(uUNIT, 7) }
                    case 100000000000000000000000000 { result := mul(uUNIT, 8) }
                    case 1000000000000000000000000000 { result := mul(uUNIT, 9) }
                    case 10000000000000000000000000000 { result := mul(uUNIT, 10) }
                    case 100000000000000000000000000000 { result := mul(uUNIT, 11) }
                    case 1000000000000000000000000000000 { result := mul(uUNIT, 12) }
                    case 10000000000000000000000000000000 { result := mul(uUNIT, 13) }
                    case 100000000000000000000000000000000 { result := mul(uUNIT, 14) }
                    case 1000000000000000000000000000000000 { result := mul(uUNIT, 15) }
                    case 10000000000000000000000000000000000 { result := mul(uUNIT, 16) }
                    case 100000000000000000000000000000000000 { result := mul(uUNIT, 17) }
                    case 1000000000000000000000000000000000000 { result := mul(uUNIT, 18) }
                    case 10000000000000000000000000000000000000 { result := mul(uUNIT, 19) }
                    case 100000000000000000000000000000000000000 { result := mul(uUNIT, 20) }
                    case 1000000000000000000000000000000000000000 { result := mul(uUNIT, 21) }
                    case 10000000000000000000000000000000000000000 { result := mul(uUNIT, 22) }
                    case 100000000000000000000000000000000000000000 { result := mul(uUNIT, 23) }
                    case 1000000000000000000000000000000000000000000 { result := mul(uUNIT, 24) }
                    case 10000000000000000000000000000000000000000000 { result := mul(uUNIT, 25) }
                    case 100000000000000000000000000000000000000000000 { result := mul(uUNIT, 26) }
                    case 1000000000000000000000000000000000000000000000 { result := mul(uUNIT, 27) }
                    case 10000000000000000000000000000000000000000000000 { result := mul(uUNIT, 28) }
                    case 100000000000000000000000000000000000000000000000 { result := mul(uUNIT, 29) }
                    case 1000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 30) }
                    case 10000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 31) }
                    case 100000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 32) }
                    case 1000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 33) }
                    case 10000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 34) }
                    case 100000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 35) }
                    case 1000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 36) }
                    case 10000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 37) }
                    case 100000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 38) }
                    case 1000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 39) }
                    case 10000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 40) }
                    case 100000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 41) }
                    case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 42) }
                    case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 43) }
                    case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 44) }
                    case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 45) }
                    case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 46) }
                    case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 47) }
                    case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 48) }
                    case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 49) }
                    case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 50) }
                    case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 51) }
                    case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 52) }
                    case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 53) }
                    case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 54) }
                    case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 55) }
                    case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 56) }
                    case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 57) }
                    case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 58) }
                    default { result := uMAX_SD59x18 }
                }
                if (result.unwrap() == uMAX_SD59x18) {
                    unchecked {
                        // Inline the fixed-point division to save gas.
                        result = wrap(log2(x).unwrap() * uUNIT / uLOG2_10);
                    }
                }
            }
            /// @notice Calculates the binary logarithm of x using the iterative approximation algorithm:
            ///
            /// $$
            /// log_2{x} = n + log_2{y}, \\text{ where } y = x*2^{-n}, \\ y \\in [1, 2)
            /// $$
            ///
            /// For $0 \\leq x \\lt 1$, the input is inverted:
            ///
            /// $$
            /// log_2{x} = -log_2{\\frac{1}{x}}
            /// $$
            ///
            /// @dev See https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation.
            ///
            /// Notes:
            /// - Due to the lossy precision of the iterative approximation, the results are not perfectly accurate to the last decimal.
            ///
            /// Requirements:
            /// - x > 0
            ///
            /// @param x The SD59x18 number for which to calculate the binary logarithm.
            /// @return result The binary logarithm as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function log2(SD59x18 x) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                if (xInt <= 0) {
                    revert Errors.PRBMath_SD59x18_Log_InputTooSmall(x);
                }
                unchecked {
                    int256 sign;
                    if (xInt >= uUNIT) {
                        sign = 1;
                    } else {
                        sign = -1;
                        // Inline the fixed-point inversion to save gas.
                        xInt = uUNIT_SQUARED / xInt;
                    }
                    // Calculate the integer part of the logarithm.
                    uint256 n = Common.msb(uint256(xInt / uUNIT));
                    // This is the integer part of the logarithm as an SD59x18 number. The operation can't overflow
                    // because n is at most 255, `UNIT` is 1e18, and the sign is either 1 or -1.
                    int256 resultInt = int256(n) * uUNIT;
                    // Calculate $y = x * 2^{-n}$.
                    int256 y = xInt >> n;
                    // If y is the unit number, the fractional part is zero.
                    if (y == uUNIT) {
                        return wrap(resultInt * sign);
                    }
                    // Calculate the fractional part via the iterative approximation.
                    // The `delta >>= 1` part is equivalent to `delta /= 2`, but shifting bits is more gas efficient.
                    int256 DOUBLE_UNIT = 2e18;
                    for (int256 delta = uHALF_UNIT; delta > 0; delta >>= 1) {
                        y = (y * y) / uUNIT;
                        // Is y^2 >= 2e18 and so in the range [2e18, 4e18)?
                        if (y >= DOUBLE_UNIT) {
                            // Add the 2^{-m} factor to the logarithm.
                            resultInt = resultInt + delta;
                            // Halve y, which corresponds to z/2 in the Wikipedia article.
                            y >>= 1;
                        }
                    }
                    resultInt *= sign;
                    result = wrap(resultInt);
                }
            }
            /// @notice Multiplies two SD59x18 numbers together, returning a new SD59x18 number.
            ///
            /// @dev Notes:
            /// - Refer to the notes in {Common.mulDiv18}.
            ///
            /// Requirements:
            /// - Refer to the requirements in {Common.mulDiv18}.
            /// - None of the inputs can be `MIN_SD59x18`.
            /// - The result must fit in SD59x18.
            ///
            /// @param x The multiplicand as an SD59x18 number.
            /// @param y The multiplier as an SD59x18 number.
            /// @return result The product as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function mul(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                int256 yInt = y.unwrap();
                if (xInt == uMIN_SD59x18 || yInt == uMIN_SD59x18) {
                    revert Errors.PRBMath_SD59x18_Mul_InputTooSmall();
                }
                // Get hold of the absolute values of x and y.
                uint256 xAbs;
                uint256 yAbs;
                unchecked {
                    xAbs = xInt < 0 ? uint256(-xInt) : uint256(xInt);
                    yAbs = yInt < 0 ? uint256(-yInt) : uint256(yInt);
                }
                // Compute the absolute value (x*y÷UNIT). The resulting value must fit in SD59x18.
                uint256 resultAbs = Common.mulDiv18(xAbs, yAbs);
                if (resultAbs > uint256(uMAX_SD59x18)) {
                    revert Errors.PRBMath_SD59x18_Mul_Overflow(x, y);
                }
                // Check if x and y have the same sign using two's complement representation. The left-most bit represents the sign (1 for
                // negative, 0 for positive or zero).
                bool sameSign = (xInt ^ yInt) > -1;
                // If the inputs have the same sign, the result should be positive. Otherwise, it should be negative.
                unchecked {
                    result = wrap(sameSign ? int256(resultAbs) : -int256(resultAbs));
                }
            }
            /// @notice Raises x to the power of y using the following formula:
            ///
            /// $$
            /// x^y = 2^{log_2{x} * y}
            /// $$
            ///
            /// @dev Notes:
            /// - Refer to the notes in {exp2}, {log2}, and {mul}.
            /// - Returns `UNIT` for 0^0.
            ///
            /// Requirements:
            /// - Refer to the requirements in {exp2}, {log2}, and {mul}.
            ///
            /// @param x The base as an SD59x18 number.
            /// @param y Exponent to raise x to, as an SD59x18 number
            /// @return result x raised to power y, as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function pow(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                int256 yInt = y.unwrap();
                // If both x and y are zero, the result is `UNIT`. If just x is zero, the result is always zero.
                if (xInt == 0) {
                    return yInt == 0 ? UNIT : ZERO;
                }
                // If x is `UNIT`, the result is always `UNIT`.
                else if (xInt == uUNIT) {
                    return UNIT;
                }
                // If y is zero, the result is always `UNIT`.
                if (yInt == 0) {
                    return UNIT;
                }
                // If y is `UNIT`, the result is always x.
                else if (yInt == uUNIT) {
                    return x;
                }
                // Calculate the result using the formula.
                result = exp2(mul(log2(x), y));
            }
            /// @notice Raises x (an SD59x18 number) to the power y (an unsigned basic integer) using the well-known
            /// algorithm "exponentiation by squaring".
            ///
            /// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring.
            ///
            /// Notes:
            /// - Refer to the notes in {Common.mulDiv18}.
            /// - Returns `UNIT` for 0^0.
            ///
            /// Requirements:
            /// - Refer to the requirements in {abs} and {Common.mulDiv18}.
            /// - The result must fit in SD59x18.
            ///
            /// @param x The base as an SD59x18 number.
            /// @param y The exponent as a uint256.
            /// @return result The result as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function powu(SD59x18 x, uint256 y) pure returns (SD59x18 result) {
                uint256 xAbs = uint256(abs(x).unwrap());
                // Calculate the first iteration of the loop in advance.
                uint256 resultAbs = y & 1 > 0 ? xAbs : uint256(uUNIT);
                // Equivalent to `for(y /= 2; y > 0; y /= 2)`.
                uint256 yAux = y;
                for (yAux >>= 1; yAux > 0; yAux >>= 1) {
                    xAbs = Common.mulDiv18(xAbs, xAbs);
                    // Equivalent to `y % 2 == 1`.
                    if (yAux & 1 > 0) {
                        resultAbs = Common.mulDiv18(resultAbs, xAbs);
                    }
                }
                // The result must fit in SD59x18.
                if (resultAbs > uint256(uMAX_SD59x18)) {
                    revert Errors.PRBMath_SD59x18_Powu_Overflow(x, y);
                }
                unchecked {
                    // Is the base negative and the exponent odd? If yes, the result should be negative.
                    int256 resultInt = int256(resultAbs);
                    bool isNegative = x.unwrap() < 0 && y & 1 == 1;
                    if (isNegative) {
                        resultInt = -resultInt;
                    }
                    result = wrap(resultInt);
                }
            }
            /// @notice Calculates the square root of x using the Babylonian method.
            ///
            /// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
            ///
            /// Notes:
            /// - Only the positive root is returned.
            /// - The result is rounded toward zero.
            ///
            /// Requirements:
            /// - x ≥ 0, since complex numbers are not supported.
            /// - x ≤ MAX_SD59x18 / UNIT
            ///
            /// @param x The SD59x18 number for which to calculate the square root.
            /// @return result The result as an SD59x18 number.
            /// @custom:smtchecker abstract-function-nondet
            function sqrt(SD59x18 x) pure returns (SD59x18 result) {
                int256 xInt = x.unwrap();
                if (xInt < 0) {
                    revert Errors.PRBMath_SD59x18_Sqrt_NegativeInput(x);
                }
                if (xInt > uMAX_SD59x18 / uUNIT) {
                    revert Errors.PRBMath_SD59x18_Sqrt_Overflow(x);
                }
                unchecked {
                    // Multiply x by `UNIT` to account for the factor of `UNIT` picked up when multiplying two SD59x18 numbers.
                    // In this case, the two numbers are both the square root.
                    uint256 resultUint = Common.sqrt(uint256(xInt * uUNIT));
                    result = wrap(int256(resultUint));
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import "../Common.sol" as Common;
            import "./Errors.sol" as Errors;
            import { SD59x18 } from "../sd59x18/ValueType.sol";
            import { UD60x18 } from "../ud60x18/ValueType.sol";
            import { UD21x18 } from "./ValueType.sol";
            /// @notice Casts a UD21x18 number into SD59x18.
            /// @dev There is no overflow check because UD21x18 ⊆ SD59x18.
            function intoSD59x18(UD21x18 x) pure returns (SD59x18 result) {
                result = SD59x18.wrap(int256(uint256(UD21x18.unwrap(x))));
            }
            /// @notice Casts a UD21x18 number into UD60x18.
            /// @dev There is no overflow check because UD21x18 ⊆ UD60x18.
            function intoUD60x18(UD21x18 x) pure returns (UD60x18 result) {
                result = UD60x18.wrap(UD21x18.unwrap(x));
            }
            /// @notice Casts a UD21x18 number into uint128.
            /// @dev This is basically an alias for {unwrap}.
            function intoUint128(UD21x18 x) pure returns (uint128 result) {
                result = UD21x18.unwrap(x);
            }
            /// @notice Casts a UD21x18 number into uint256.
            /// @dev There is no overflow check because UD21x18 ⊆ uint256.
            function intoUint256(UD21x18 x) pure returns (uint256 result) {
                result = uint256(UD21x18.unwrap(x));
            }
            /// @notice Casts a UD21x18 number into uint40.
            /// @dev Requirements:
            /// - x ≤ MAX_UINT40
            function intoUint40(UD21x18 x) pure returns (uint40 result) {
                uint128 xUint = UD21x18.unwrap(x);
                if (xUint > uint128(Common.MAX_UINT40)) {
                    revert Errors.PRBMath_UD21x18_IntoUint40_Overflow(x);
                }
                result = uint40(xUint);
            }
            /// @notice Alias for {wrap}.
            function ud21x18(uint128 x) pure returns (UD21x18 result) {
                result = UD21x18.wrap(x);
            }
            /// @notice Unwrap a UD21x18 number into uint128.
            function unwrap(UD21x18 x) pure returns (uint128 result) {
                result = UD21x18.unwrap(x);
            }
            /// @notice Wraps a uint128 number into UD21x18.
            function wrap(uint128 x) pure returns (UD21x18 result) {
                result = UD21x18.wrap(x);
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol)
            pragma solidity ^0.8.20;
            import {IERC165} from "../../utils/introspection/IERC165.sol";
            /**
             * @dev Required interface of an ERC-721 compliant contract.
             */
            interface IERC721 is IERC165 {
                /**
                 * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
                 */
                event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
                /**
                 * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
                 */
                event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
                /**
                 * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
                 */
                event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
                /**
                 * @dev Returns the number of tokens in ``owner``'s account.
                 */
                function balanceOf(address owner) external view returns (uint256 balance);
                /**
                 * @dev Returns the owner of the `tokenId` token.
                 *
                 * Requirements:
                 *
                 * - `tokenId` must exist.
                 */
                function ownerOf(uint256 tokenId) external view returns (address owner);
                /**
                 * @dev Safely transfers `tokenId` token from `from` to `to`.
                 *
                 * Requirements:
                 *
                 * - `from` cannot be the zero address.
                 * - `to` cannot be the zero address.
                 * - `tokenId` token must exist and be owned by `from`.
                 * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
                 * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
                 *   a safe transfer.
                 *
                 * Emits a {Transfer} event.
                 */
                function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
                /**
                 * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
                 * are aware of the ERC-721 protocol to prevent tokens from being forever locked.
                 *
                 * Requirements:
                 *
                 * - `from` cannot be the zero address.
                 * - `to` cannot be the zero address.
                 * - `tokenId` token must exist and be owned by `from`.
                 * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or
                 *   {setApprovalForAll}.
                 * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
                 *   a safe transfer.
                 *
                 * Emits a {Transfer} event.
                 */
                function safeTransferFrom(address from, address to, uint256 tokenId) external;
                /**
                 * @dev Transfers `tokenId` token from `from` to `to`.
                 *
                 * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC-721
                 * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
                 * understand this adds an external call which potentially creates a reentrancy vulnerability.
                 *
                 * Requirements:
                 *
                 * - `from` cannot be the zero address.
                 * - `to` cannot be the zero address.
                 * - `tokenId` token must be owned by `from`.
                 * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
                 *
                 * Emits a {Transfer} event.
                 */
                function transferFrom(address from, address to, uint256 tokenId) external;
                /**
                 * @dev Gives permission to `to` to transfer `tokenId` token to another account.
                 * The approval is cleared when the token is transferred.
                 *
                 * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
                 *
                 * Requirements:
                 *
                 * - The caller must own the token or be an approved operator.
                 * - `tokenId` must exist.
                 *
                 * Emits an {Approval} event.
                 */
                function approve(address to, uint256 tokenId) external;
                /**
                 * @dev Approve or remove `operator` as an operator for the caller.
                 * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
                 *
                 * Requirements:
                 *
                 * - The `operator` cannot be the address zero.
                 *
                 * Emits an {ApprovalForAll} event.
                 */
                function setApprovalForAll(address operator, bool approved) external;
                /**
                 * @dev Returns the account approved for `tokenId` token.
                 *
                 * Requirements:
                 *
                 * - `tokenId` must exist.
                 */
                function getApproved(uint256 tokenId) external view returns (address operator);
                /**
                 * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
                 *
                 * See {setApprovalForAll}
                 */
                function isApprovedForAll(address owner, address operator) external view returns (bool);
            }
            // SPDX-License-Identifier: GPL-3.0-or-later
            pragma solidity >=0.8.19;
            /// @title IAdminable
            /// @notice Contract module that provides a basic access control mechanism, with an admin that can be
            /// granted exclusive access to specific functions. The inheriting contract must set the initial admin
            /// in the constructor.
            interface IAdminable {
                /*//////////////////////////////////////////////////////////////////////////
                                                   EVENTS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Emitted when the admin is transferred.
                /// @param oldAdmin The address of the old admin.
                /// @param newAdmin The address of the new admin.
                event TransferAdmin(address indexed oldAdmin, address indexed newAdmin);
                /*//////////////////////////////////////////////////////////////////////////
                                             CONSTANT FUNCTIONS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice The address of the admin account or contract.
                function admin() external view returns (address);
                /*//////////////////////////////////////////////////////////////////////////
                                           NON-CONSTANT FUNCTIONS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Transfers the contract admin to a new address.
                ///
                /// @dev Notes:
                /// - Does not revert if the admin is the same.
                /// - This function can potentially leave the contract without an admin, thereby removing any
                /// functionality that is only available to the admin.
                ///
                /// Requirements:
                /// - `msg.sender` must be the contract admin.
                ///
                /// @param newAdmin The address of the new admin.
                function transferAdmin(address newAdmin) external;
            }
            // SPDX-License-Identifier: GPL-3.0-or-later
            pragma solidity >=0.8.19;
            import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
            import { UD60x18 } from "@prb/math/src/UD60x18.sol";
            import { IAdminable } from "./IAdminable.sol";
            /// @title ISablierV2Controller
            /// @notice This contract is in charge of the Sablier V2 protocol configuration, handling such values as the
            /// protocol fees.
            interface ISablierV2Comptroller is IAdminable {
                /*//////////////////////////////////////////////////////////////////////////
                                                   EVENTS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Emitted when the admin sets a new flash fee.
                /// @param admin The address of the contract admin.
                /// @param oldFlashFee The old flash fee, denoted as a fixed-point number.
                /// @param newFlashFee The new flash fee, denoted as a fixed-point number.
                event SetFlashFee(address indexed admin, UD60x18 oldFlashFee, UD60x18 newFlashFee);
                /// @notice Emitted when the admin sets a new protocol fee for the provided ERC-20 asset.
                /// @param admin The address of the contract admin.
                /// @param asset The contract address of the ERC-20 asset the new protocol fee has been set for.
                /// @param oldProtocolFee The old protocol fee, denoted as a fixed-point number.
                /// @param newProtocolFee The new protocol fee, denoted as a fixed-point number.
                event SetProtocolFee(address indexed admin, IERC20 indexed asset, UD60x18 oldProtocolFee, UD60x18 newProtocolFee);
                /// @notice Emitted when the admin enables or disables an ERC-20 asset for flash loaning.
                /// @param admin The address of the contract admin.
                /// @param asset The contract address of the ERC-20 asset to toggle.
                /// @param newFlag Whether the ERC-20 asset can be flash loaned.
                event ToggleFlashAsset(address indexed admin, IERC20 indexed asset, bool newFlag);
                /*//////////////////////////////////////////////////////////////////////////
                                             CONSTANT FUNCTIONS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Retrieves the global flash fee, denoted as a fixed-point number where 1e18 is 100%.
                ///
                /// @dev Notes:
                /// - This fee represents a percentage, not an amount. Do not confuse it with {IERC3156FlashLender.flashFee},
                /// which calculates the fee amount for a specified flash loan amount.
                /// - Unlike the protocol fee, this is a global fee applied to all flash loans, not a per-asset fee.
                function flashFee() external view returns (UD60x18 fee);
                /// @notice Retrieves a flag indicating whether the provided ERC-20 asset can be flash loaned.
                /// @param token The contract address of the ERC-20 asset to check.
                function isFlashAsset(IERC20 token) external view returns (bool result);
                /// @notice Retrieves the protocol fee for all streams created with the provided ERC-20 asset.
                /// @param asset The contract address of the ERC-20 asset to query.
                /// @return fee The protocol fee denoted as a fixed-point number where 1e18 is 100%.
                function protocolFees(IERC20 asset) external view returns (UD60x18 fee);
                /*//////////////////////////////////////////////////////////////////////////
                                           NON-CONSTANT FUNCTIONS
                //////////////////////////////////////////////////////////////////////////*/
                /// @notice Updates the flash fee charged on all flash loans made with any ERC-20 asset.
                ///
                /// @dev Emits a {SetFlashFee} event.
                ///
                /// Notes:
                /// - Does not revert if the fee is the same.
                ///
                /// Requirements:
                /// - `msg.sender` must be the contract admin.
                ///
                /// @param newFlashFee The new flash fee to set, denoted as a fixed-point number where 1e18 is 100%.
                function setFlashFee(UD60x18 newFlashFee) external;
                /// @notice Sets a new protocol fee that will be charged on all streams created with the provided ERC-20 asset.
                ///
                /// @dev Emits a {SetProtocolFee} event.
                ///
                /// Notes:
                /// - The fee is not denoted in units of the asset's decimals; it is a fixed-point number. Refer to the
                /// PRBMath documentation for more detail on the logic of UD60x18.
                /// - Does not revert if the fee is the same.
                ///
                /// Requirements:
                /// - `msg.sender` must be the contract admin.
                ///
                /// @param asset The contract address of the ERC-20 asset to update the fee for.
                /// @param newProtocolFee The new protocol fee, denoted as a fixed-point number where 1e18 is 100%.
                function setProtocolFee(IERC20 asset, UD60x18 newProtocolFee) external;
                /// @notice Toggles the flash loanability of an ERC-20 asset.
                ///
                /// @dev Emits a {ToggleFlashAsset} event.
                ///
                /// Requirements:
                /// - `msg.sender` must be the admin.
                ///
                /// @param asset The address of the ERC-20 asset to toggle.
                function toggleFlashAsset(IERC20 asset) external;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { SD1x18 } from "./ValueType.sol";
            /// @notice Thrown when trying to cast an SD1x18 number that doesn't fit in UD60x18.
            error PRBMath_SD1x18_ToUD60x18_Underflow(SD1x18 x);
            /// @notice Thrown when trying to cast an SD1x18 number that doesn't fit in uint128.
            error PRBMath_SD1x18_ToUint128_Underflow(SD1x18 x);
            /// @notice Thrown when trying to cast an SD1x18 number that doesn't fit in uint256.
            error PRBMath_SD1x18_ToUint256_Underflow(SD1x18 x);
            /// @notice Thrown when trying to cast an SD1x18 number that doesn't fit in uint40.
            error PRBMath_SD1x18_ToUint40_Overflow(SD1x18 x);
            /// @notice Thrown when trying to cast an SD1x18 number that doesn't fit in uint40.
            error PRBMath_SD1x18_ToUint40_Underflow(SD1x18 x);
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { SD21x18 } from "./ValueType.sol";
            /// @notice Thrown when trying to cast an SD21x18 number that doesn't fit in uint128.
            error PRBMath_SD21x18_ToUint128_Underflow(SD21x18 x);
            /// @notice Thrown when trying to cast an SD21x18 number that doesn't fit in UD60x18.
            error PRBMath_SD21x18_ToUD60x18_Underflow(SD21x18 x);
            /// @notice Thrown when trying to cast an SD21x18 number that doesn't fit in uint256.
            error PRBMath_SD21x18_ToUint256_Underflow(SD21x18 x);
            /// @notice Thrown when trying to cast an SD21x18 number that doesn't fit in uint40.
            error PRBMath_SD21x18_ToUint40_Overflow(SD21x18 x);
            /// @notice Thrown when trying to cast an SD21x18 number that doesn't fit in uint40.
            error PRBMath_SD21x18_ToUint40_Underflow(SD21x18 x);
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { SD59x18 } from "./ValueType.sol";
            /// @notice Thrown when taking the absolute value of `MIN_SD59x18`.
            error PRBMath_SD59x18_Abs_MinSD59x18();
            /// @notice Thrown when ceiling a number overflows SD59x18.
            error PRBMath_SD59x18_Ceil_Overflow(SD59x18 x);
            /// @notice Thrown when converting a basic integer to the fixed-point format overflows SD59x18.
            error PRBMath_SD59x18_Convert_Overflow(int256 x);
            /// @notice Thrown when converting a basic integer to the fixed-point format underflows SD59x18.
            error PRBMath_SD59x18_Convert_Underflow(int256 x);
            /// @notice Thrown when dividing two numbers and one of them is `MIN_SD59x18`.
            error PRBMath_SD59x18_Div_InputTooSmall();
            /// @notice Thrown when dividing two numbers and one of the intermediary unsigned results overflows SD59x18.
            error PRBMath_SD59x18_Div_Overflow(SD59x18 x, SD59x18 y);
            /// @notice Thrown when taking the natural exponent of a base greater than 133_084258667509499441.
            error PRBMath_SD59x18_Exp_InputTooBig(SD59x18 x);
            /// @notice Thrown when taking the binary exponent of a base greater than 192e18.
            error PRBMath_SD59x18_Exp2_InputTooBig(SD59x18 x);
            /// @notice Thrown when flooring a number underflows SD59x18.
            error PRBMath_SD59x18_Floor_Underflow(SD59x18 x);
            /// @notice Thrown when taking the geometric mean of two numbers and their product is negative.
            error PRBMath_SD59x18_Gm_NegativeProduct(SD59x18 x, SD59x18 y);
            /// @notice Thrown when taking the geometric mean of two numbers and multiplying them overflows SD59x18.
            error PRBMath_SD59x18_Gm_Overflow(SD59x18 x, SD59x18 y);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in SD1x18.
            error PRBMath_SD59x18_IntoSD1x18_Overflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in SD1x18.
            error PRBMath_SD59x18_IntoSD1x18_Underflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in SD21x18.
            error PRBMath_SD59x18_IntoSD21x18_Overflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in SD21x18.
            error PRBMath_SD59x18_IntoSD21x18_Underflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in UD2x18.
            error PRBMath_SD59x18_IntoUD2x18_Overflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in UD2x18.
            error PRBMath_SD59x18_IntoUD2x18_Underflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in UD21x18.
            error PRBMath_SD59x18_IntoUD21x18_Overflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in UD21x18.
            error PRBMath_SD59x18_IntoUD21x18_Underflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in UD60x18.
            error PRBMath_SD59x18_IntoUD60x18_Underflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in uint128.
            error PRBMath_SD59x18_IntoUint128_Overflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in uint128.
            error PRBMath_SD59x18_IntoUint128_Underflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in uint256.
            error PRBMath_SD59x18_IntoUint256_Underflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in uint40.
            error PRBMath_SD59x18_IntoUint40_Overflow(SD59x18 x);
            /// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in uint40.
            error PRBMath_SD59x18_IntoUint40_Underflow(SD59x18 x);
            /// @notice Thrown when taking the logarithm of a number less than or equal to zero.
            error PRBMath_SD59x18_Log_InputTooSmall(SD59x18 x);
            /// @notice Thrown when multiplying two numbers and one of the inputs is `MIN_SD59x18`.
            error PRBMath_SD59x18_Mul_InputTooSmall();
            /// @notice Thrown when multiplying two numbers and the intermediary absolute result overflows SD59x18.
            error PRBMath_SD59x18_Mul_Overflow(SD59x18 x, SD59x18 y);
            /// @notice Thrown when raising a number to a power and the intermediary absolute result overflows SD59x18.
            error PRBMath_SD59x18_Powu_Overflow(SD59x18 x, uint256 y);
            /// @notice Thrown when taking the square root of a negative number.
            error PRBMath_SD59x18_Sqrt_NegativeInput(SD59x18 x);
            /// @notice Thrown when the calculating the square root overflows SD59x18.
            error PRBMath_SD59x18_Sqrt_Overflow(SD59x18 x);
            // SPDX-License-Identifier: MIT
            pragma solidity >=0.8.19;
            import { UD21x18 } from "./ValueType.sol";
            /// @notice Thrown when trying to cast a UD21x18 number that doesn't fit in uint40.
            error PRBMath_UD21x18_IntoUint40_Overflow(UD21x18 x);
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)
            pragma solidity ^0.8.20;
            /**
             * @dev Interface of the ERC-165 standard, as defined in the
             * https://eips.ethereum.org/EIPS/eip-165[ERC].
             *
             * Implementers can declare support of contract interfaces, which can then be
             * queried by others ({ERC165Checker}).
             *
             * For an implementation, see {ERC165}.
             */
            interface IERC165 {
                /**
                 * @dev Returns true if this contract implements the interface defined by
                 * `interfaceId`. See the corresponding
                 * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
                 * to learn more about how these ids are created.
                 *
                 * This function call must use less than 30 000 gas.
                 */
                function supportsInterface(bytes4 interfaceId) external view returns (bool);
            }