|
| 1 | +# Deployment & Integration Guide |
| 2 | + |
| 3 | +Deploying the `no_JIT` Hook adds a powerful layer of economic security to any Uniswap v4 pool. This guide outlines the steps for deployment and integration. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- **A Deployed Uniswap v4 Core:** You need a running instance of the Uniswap v4 contracts (`PoolManager`). |
| 8 | +- **Foundry:** For compiling and deploying. |
| 9 | +- **Governor Address:** An address (ideally a Multisig or DAO Timelock) that will have administrative control over the hook's parameters. |
| 10 | + |
| 11 | +## Step 1: Deployment |
| 12 | + |
| 13 | +The hook contract is self-contained. Deploy it using Foundry: |
| 14 | + |
| 15 | +```bash |
| 16 | +# Ensure your .env file has PRIVATE_KEY and an RPC_URL |
| 17 | +forge create src/ProductionJITHook.sol:ProductionJITHook \ |
| 18 | + --rpc-url $RPC_URL \ |
| 19 | + --private-key $PRIVATE_KEY \ |
| 20 | + --constructor-args <POOL_MANAGER_ADDRESS> <GOVERNOR_ADDRESS> \ |
| 21 | + --verify |
| 22 | +``` |
| 23 | + |
| 24 | +- **`<POOL_MANAGER_ADDRESS>`:** The address of the deployed `PoolManager.sol`. |
| 25 | +- **`<GOVERNOR_ADDRESS>`:** The address designated for governance. |
| 26 | + |
| 27 | +Take note of the deployed hook's address. |
| 28 | + |
| 29 | +## Step 2: Pool Initialization with the Hook |
| 30 | + |
| 31 | +When creating a new Uniswap v4 pool, you must specify the hook address during initialization. |
| 32 | + |
| 33 | +The `PoolManager`'s `initialize` function takes a `hook` parameter. Provide the address of your newly deployed `ProductionJITHook` contract here. |
| 34 | + |
| 35 | +**Example using Foundry script:** |
| 36 | + |
| 37 | +```solidity |
| 38 | +// In a Forge script |
| 39 | +IPoolManager.PoolKey memory key = IPoolManager.PoolKey({ |
| 40 | + currency0: token0, |
| 41 | + currency1: token1, |
| 42 | + fee: 3000, |
| 43 | + tickSpacing: 60, |
| 44 | + hooks: address(deployedJitHook) // <-- CRITICAL STEP |
| 45 | +}); |
| 46 | +
|
| 47 | +poolManager.initialize(key, initialSqrtPriceX96, bytes("")); |
| 48 | +``` |
| 49 | + |
| 50 | +**Important:** The hook must be set at the time of pool creation. It cannot be added to an existing pool. |
| 51 | + |
| 52 | +## Step 3: Initial Configuration (by Governor) |
| 53 | + |
| 54 | +Once deployed, the governor must configure the hook's parameters to activate the defense. |
| 55 | + |
| 56 | +```solidity |
| 57 | +// This would be a call from the Governor address |
| 58 | +function configureHook(ProductionJITHook hook) public { |
| 59 | + // Corresponds to τ in the paper |
| 60 | + // Example: Set threshold to 10% of total liquidity |
| 61 | + hook.setThreshold(1000); // 1000 bps = 10% |
| 62 | +
|
| 63 | + // Corresponds to φ_penalty in the paper |
| 64 | + // Example: Set penalty fee to 1.00% |
| 65 | + hook.setPenaltyFee(10000); // 10000 pips = 1% |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | +After this transaction is confirmed, the `no_JIT` defense is fully active for all swaps in the associated pool. |
| 70 | + |
| 71 | +## Integration Considerations |
| 72 | + |
| 73 | +- **Gas Overhead:** The `beforeSwap` and `afterAddLiquidity` logic is highly optimized. It involves 1 SLOAD and 1 SSTORE per liquidity addition in a block, and 1 SLOAD per swap. The overhead is minimal and predictable. |
| 74 | +- **Frontend Integration:** Ensure your dApp's frontend can correctly interpret potential swap failures or altered fee information if a trade is identified as part of a JIT attack. |
0 commit comments