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.
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]
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
unlockpattern 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).
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.
The primary deployment script for the protocol.
- Hook Mining: Uses
HookMinerto find a CREATE2 salt that results in a hook address with the correct Uniswap v4 flags (beforeSwap, afterSwap). - Setup: Deploys both
InvestInGasHookandLiFiBridger, links them together, and sets the defaultPoolKey. - Initialization: Automatically initializes the pool with a default price (approx. Tick 38698) to ensure swaps are immediately functional.
A robust finalization utility that ensures the environment is production-ready.
- Hook Calibration: Aligns the Hook's internal
poolKeywith 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
LiquidityHelperto bypass Uniswap v4 callback complexities and inject initial concentrated depth.
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).
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.
A migration utility used to update an already-deployed hook's poolKey to a new fee tier without redeploying the entire contract.
| 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 |
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.
Ensure you have the following installed:
- Foundry:
curl -L https://foundry.paradigm.xyz | bash - Git:
sudo apt install git(or equivalent)
-
Clone the repository:
git clone https://github.com/InvestInGas/v4-contracts.git cd v4-contracts -
Install dependencies:
forge install
-
Build the project:
forge build
Duplicate the .env template and configure your secrets:
cp .env.example .envRequired Variables:
PRIVATE_KEY: Your wallet private key (without0x). 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).
We use a Foundry script to securely deploy and configure both contracts.
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_KEYOn success, the script will output the deployed addresses:
=== Deployment Summary ===
InvestInGasHook: 0x...
LiFiBridger: 0x...
Important: Save these addresses for your configuration.