Skip to content

InvestInGas/v4-contracts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

InvestInGas - ETH-Native Gas Futures

InvestInGas is a decentralized application that enables users to hedge against Ethereum gas price volatility. Built as a Uniswap v4 Hook, it allows users to purchase "Gas Positions" - NFT-represented futures contracts that lock in a specific gas price.

Architecture

The system consists of two primary contracts:

  • InvestInGasHook: A Uniswap v4 hook that manages the purchase logic. Users swap USDC for WETH, which is then locked into a gas position.
  • LiFiBridger: A helper contract that leverages LiFi (LI.FI) to bridge assets (ETH) to other chains when a user redeems their position.
graph LR
    User[User] -- USDC --> Hook[InvestInGas Hook]
    Hook -- WETH --> Position[NFT Position]
    Position -- Redeem --> Bridger[LiFi Bridger]
    Bridger -- ETH --> Target[Target Chain]
Loading

Contracts (src/)

InvestInGasHook.sol

The core logic of the protocol, implemented as a Uniswap v4 Hook.

  • Position Management: Mints ERC721 tokens (IIGPOS) representing gas positions.
  • Swap Integration: Uses the Uniswap v4 unlock pattern to swap USDC for WETH gas-efficiently.
  • Redemption: Orchestrates redemptions, either locally on Sepolia or cross-chain via the LiFiBridger.
  • Expiry Logic: Users can claim a refund of their WETH (minus a small fee) if their position expires without being used.
  • Fees: Manages protocol fees (50 bps) and expiry refund fees (200 bps).

LiFiBridger.sol

A dedicated helper for cross-chain asset movement.

  • LiFi Integration: Interacts with the LiFi Diamond to bridge ETH to various destination chains.
  • WETH Handling: Automatically unwraps WETH to native ETH before bridging or local transfer.
  • Direct Transfers: Handles "redemptions" to the same chain (Sepolia) by simply unwrapping and sending ETH.

Scripts (script/)

DeployInvestInGas.s.sol

The primary deployment script for the protocol.

  • Hook Mining: Uses HookMiner to find a CREATE2 salt that results in a hook address with the correct Uniswap v4 flags (beforeSwap, afterSwap).
  • Setup: Deploys both InvestInGasHook and LiFiBridger, links them together, and sets the default PoolKey.
  • Initialization: Automatically initializes the pool with a default price (approx. Tick 38698) to ensure swaps are immediately functional.

FinalFix.s.sol

A robust finalization utility that ensures the environment is production-ready.

  • Hook Calibration: Aligns the Hook's internal poolKey with the target liquidity pool.
  • Pool Initialization: Initializes the Uniswap v4 pool with a specific sqrtPriceX96 (e.g., at tick 198000 for approx. $2500 per ETH).
  • Liquidity injection: Uses a custom LiquidityHelper to bypass Uniswap v4 callback complexities and inject initial concentrated depth.

AddLiquidity.s.sol

A complex script to add liquidity to the Uniswap v4 pool.

  • LiquidityHelper: Deploys a temporary helper contract to handle the Uniswap v4 unlockCallback.
  • Target Tier: Currently optimized for the 3001 fee tier (0.3001% fee, 60 tick spacing) to avoid collisions with standard user pools.
  • Position Setup: Adds concentrated liquidity around the active price (Tick 198000 range).

CheckPoolState.s.sol

A diagnostic utility to check the current price and liquidity across multiple pool tiers (0.3%, 0.05%, 1.0%). Use this to verify if a pool is "healthy" before attempting a purchase.

AlignExistingHook.s.sol

A migration utility used to update an already-deployed hook's poolKey to a new fee tier without redeploying the entire contract.

Supported Chains

Chain Type Chain ID
Sepolia Deployment Network 11155111
Arbitrum Sepolia Cross-chain destination 421614
Base Sepolia Cross-chain destination 84532
Optimism Sepolia Cross-chain destination 11155420

Uniswap v4 Pool Setup

The system is optimized for the following pool configuration:

  • Pair: USDC / WETH
  • Fee Tier: 3001 (0.3001%)
  • Tick Spacing: 60
  • Hook Flags: BEFORE_SWAP | AFTER_SWAP

Warning: Swaps will revert with PriceLimitAlreadyExceeded if the pool is uninitialized or has zero liquidity at the target price range. Use FinalFix.s.sol to bootstrap a new environment.

Getting Started

Prerequisites

Ensure you have the following installed:

  • Foundry: curl -L https://foundry.paradigm.xyz | bash
  • Git: sudo apt install git (or equivalent)

Installation

  1. Clone the repository:

    git clone https://github.com/InvestInGas/v4-contracts.git
    cd v4-contracts
  2. Install dependencies:

    forge install
  3. Build the project:

    forge build

Configuration

Duplicate the .env template and configure your secrets:

cp .env.example .env

Required Variables:

  • PRIVATE_KEY: Your wallet private key (without 0x). Keep this secret!
  • SEPOLIA_RPC: RPC URL for Sepolia (e.g., from Alchemy or Infura).

Optional Variables:

  • ETHERSCAN_API_KEY: For automatic contract verification.
  • RELAYER_ADDRESS: Address of the relayer (defaults to deployer if unset).

Deployment Guide

We use a Foundry script to securely deploy and configure both contracts.

1. Deploy to Sepolia

Run the following command to deploy, broadcast, and verify:

source .env && forge script script/DeployInvestInGas.s.sol \
  --rpc-url $SEPOLIA_RPC \
  --broadcast \
  --verify \
  --etherscan-api-key $ETHERSCAN_API_KEY

2. Verify Output

On success, the script will output the deployed addresses:

=== Deployment Summary ===
InvestInGasHook: 0x...
LiFiBridger: 0x...

Important: Save these addresses for your configuration.

About

Uniswap v4 Hook-based Gas Hedging Engine. Lock in future gas prices via NFT-represented derivatives.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors