State variables and roles

  • _ammState

    Struct containing the AMM’s square-root spot price, lower range price and upper range price, each being a uint160 (In Q64.96 format). The AMM is modelled as a single UniswapV3 range order but without discrete price ticks. In order to save gas on storage ops, the three variables are packed into two uint256 slots as follows:

    /**
        @notice Packed struct that contains all variables relevant to the state of the AMM.
        
        * a: sqrtSpotPriceX96
        * b: sqrtPriceLowX96
        * c: sqrtPriceHighX96
            
        This arrangement saves 1 storage slot by packing the variables at the bit level.
        
        @dev Should never be used directly without the help of the TightPack library.
    
        @dev slot1: << 32 free bits | upper 64 bits of b | all 160 bits of a >>
             slot2: << lower 96 bits of b | all 160 bits of c >>
     */
    struct AMMState {
        uint256 slot1;
        uint256 slot2;
    }
  • HotWriteSlot

    Struct containing parameters that get updated on every HOT swap.

    /**
        @notice Packed struct containing state variables which get updated on HOT swaps.
    
        * lastProcessedBlockQuoteCount: Number of HOT swaps processed in the last block.
        * feeGrowthE6Token0: Fee growth in pips, per second, of AMM swap fee for token0.
        * feeMaxToken0: Maximum AMM swap fee for token0.
        * feeMinToken0: Minimum AMM swap fee for token0.
        * feeGrowthE6Token1: Fee growth in pips, per second, of AMM swap fee for token1.
        * feeMaxToken1: Maximum AMM swap fee for token1.
        * feeMinToken1: Minimum AMM swap fee for token1.
        * lastStateUpdateTimestamp: Block timestamp of the last AMM state update from an HOT swap.
        * lastProcessedQuoteTimestamp: Block timestamp of the last processed HOT swap (not all HOT swaps update AMM state).
        * lastProcessedSignatureTimestamp: Signature timestamp of the last HOT swap which has been successfully processed.
        * alternatingNonceBitmap: Nonce bitmap (see AlternatingNonceBitmap library and docs).
     */
    struct HotWriteSlot {
        uint8 lastProcessedBlockQuoteCount;
        uint16 feeGrowthE6Token0;
        uint16 feeMaxToken0;
        uint16 feeMinToken0;
        uint16 feeGrowthE6Token1;
        uint16 feeMaxToken1;
        uint16 feeMinToken1;
        uint32 lastStateUpdateTimestamp;
        uint32 lastProcessedQuoteTimestamp;
        uint32 lastProcessedSignatureTimestamp;
        uint56 alternatingNonceBitmap;
    }
  • hotReadSlot

    Struct containing parameters that get read, but not updated, during HOT swaps:

    /**
        @notice Contains read-only variables required during execution of an HOT swap.
        * isPaused: Indicates whether the contract is paused or not.     
        * maxAllowedQuotes: Maximum number of quotes that can be processed in a single block.
        * maxOracleDeviationBipsLower: Maximum deviation in bips allowed when, sqrtSpotPrice < sqrtOraclePrice
        * maxOracleDeviationBipsUpper: Maximum deviation in bips allowed when, sqrtSpotPrice >= sqrtOraclePrice
        * hotFeeBipsToken0: Fee in basis points for all subsequent hot for token0.
        * hotFeeBipsToken1: Fee in basis points for all subsequent hot for token1.
        * signer: Address of the signer of the HOT.
     */
    struct HotReadSlot {
        bool isPaused;
        uint8 maxAllowedQuotes;
        uint16 maxOracleDeviationBipsLower;
        uint16 maxOracleDeviationBipsUpper;
        uint16 hotFeeBipsToken0;
        uint16 hotFeeBipsToken1;
        address signer;
    }

    signeris responsible for signing the HybridOrderType struct during HOT swaps. It can be either a EOA or an EIP-1271 compliant smart contract wallet.

  • maxOracleDeviationBipsLower is the maximum allowed deviation in basis points term between the square root of the oracle price, and the square root of the spot price when sqrtSpotPrice < sqrtOraclePrice. If during deposits or HOT swaps, this deviation threshold is exceeded, then we assume that the spot price is manipulated currently, and we revert the action.

  • maxOracleDeviationBipsUpper works exactly like maxOracleDeviationBipsLower, but is used when sqrtSpotPrice >= sqrtOraclePrice

  • maxToken{0,1}VolumeToQuote Maximum amount of volume that signer is allowed to quote on each HOT swap.

    These have been implemented as absolute bounds on the per-swap volume, instead of as a fraction of current pool reserves, in order to reduce the attack surface due to how pool reserves are easy to manipulate. manager is expected to update these bounds as frequently as necessary, as deposits and withdrawals change reserves in the pool.

    WARNING: The higher these values are, the more flexibility hotReadSlot.signer has in filling larger HOT swaps, but it also increases the risk of losses for LPs in case of mis-priced quotes. The HOT contract trusts that manager sets these values appropriately according to the needs of liquidityProvider.

  • manager

    Address which is responsible for:

    • Updating all parameters in hotReadSlot

    • Pausing the HOT contract, hence acting as a circuit-breaker

    • Updating maximum volume of each HOT swap (maxToken0VolumeToQuote and maxToken1VolumeToQuote)

    WARNING: In order to maximise the effectiveness of manager as a circuit breaker, and placing reasonable bounds on the amount of volume that signer is allowed to quote on each HOT swap, manager should not collude with signer nor liquidityProvider.

  • liquidityProvider

    Set as immutable upon initialization.

    Liquidity provider is responsible for:

    • Depositing reserves.

    • Withdrawing reserves.

    • Set AMM position’s price bounds.

WARNING: The HOT contract makes no assumptions with regards to how reserves are managed or tokenized, and assumes that liquidityProvider is a smart contract that implements sufficient internal protections. manager can pause the contract at any time, should liquidityProvider be faulty.

Last updated