Privacy-preserving Uniswap V4 Hook with encrypted intent matching, FHE-based privacy, and delta-neutral strategies.
- Uniswap V4 Integration - Complete guide to our Uniswap V4 hook implementation
- Pyth Integration - Oracle integration for delta-zero strategy
PrivacyPoolHook is a Uniswap V4 hook that enables private swaps through encrypted intents and batch matching. It uses Zama's FHEVM (Fully Homomorphic Encryption) to provide complete transaction privacy while maintaining capital efficiency through intent matching.
- Intent Matching: Opposite intents matched internally without touching AMM
- Full Privacy: Both amounts (euint64) and actions (euint8) are encrypted
- Capital Efficiency: Majority of trades settle without touching AMM
- MEV Resistance: Encrypted amounts + actions + batch execution
- ERC7984 Standard: Full OpenZeppelin compliance for encrypted tokens
- Delta-Zero Strategy: Automated rebalancing using Pyth oracles
- Simple Lending: Collateralized lending protocol integration
-
PrivacyPoolHook - Main hook contract implementing:
- Encrypted intent submission
- Batch settlement with internal matching
- Deposit/withdraw with encrypted pool tokens
- Integration with Uniswap V4 pool manager
-
PoolEncryptedToken (ERC7984) - Privacy-preserving token standard:
- Encrypted balances using Zama FHEVM
- Confidential transfers
- 1:1 backing with ERC20 reserves
-
DeltaZeroStrategy - Automated rebalancing:
- Monitors pool price via Pyth oracle
- Executes rebalancing when price deviates
- Integrates with lending protocol
-
SimpleLending - Collateralized lending:
- ETH borrowing against collateral
- 6% annual interest rate
- 90% collateral factor
- Amounts:
euint64- Nobody can see trade size - Actions:
euint8- Nobody can see trade direction (0=swap0→1, 1=swap1→0) - Only relayer with FHE permissions can decrypt for matching
- Users deposit ERC20 → receive encrypted pool tokens (ERC7984)
- Users submit encrypted intents (amount + action both encrypted)
- Relayer matches opposite intents off-chain (with FHE permissions)
- Settlement: internal transfers (matched) + net AMM swap (unmatched)
- Users withdraw encrypted tokens → receive ERC20 back
- Node.js >= 20
- npm >= 7.0.0
- Hardhat 2.26.0
cd hardhat
npm installSet up your environment variables using Hardhat vars:
npx hardhat vars setupRequired variables:
MNEMONIC- Your wallet mnemonic (defaults to test mnemonic)INFURA_API_KEY- For Sepolia deploymentETHERSCAN_API_KEY- For contract verification
The project is configured for:
- hardhat (default) - Local development network
- anvil - Foundry local network (port 8545)
- sepolia - Ethereum testnet
npm run compileThis will:
- Compile all Solidity contracts (0.8.27 & 0.8.26)
- Generate TypeChain types
- Use Cancun EVM version with IR compilation
npm testThis runs the complete test suite:
- PrivacyPoolHook basic functionality
- Settlement mechanism
- Shuttle operations
- Delta-zero strategy with Pyth oracle
- SimpleLending protocol
For coverage:
npm run coveragenpm run clean # Clean artifacts and regenerate types
npm run compile # Compile contracts
npm run test # Run all tests
npm run test:sepolia # Run tests on Sepolia
npm run lint # Lint Solidity and TypeScript
npm run prettier:write # Format code
npm run chain # Start local Hardhat node- Start a local node:
npm run chain- Deploy contracts:
npm run deploy:localhostnpm run deploy:sepoliaVerify contracts:
npm run verify:sepoliahardhat/
├── contracts/
│ ├── PrivacyPoolHook.sol # Main hook implementation
│ ├── DeltaZeroStrategy.sol # Rebalancing strategy
│ ├── SimpleLending.sol # Lending protocol
│ ├── tokens/
│ │ ├── PoolEncryptedToken.sol # ERC7984 implementation
│ │ └── ConfidentialToken.sol # Base encrypted token
│ ├── libraries/
│ │ ├── IntentTypes.sol # Intent data structures
│ │ └── SettlementLib.sol # Settlement logic
│ ├── interfaces/
│ │ ├── IDeltaZeroStrategy.sol
│ │ └── ISimpleLending.sol
│ └── mocks/ # Testing utilities
├── test/ # Test files
├── scripts/ # Deployment scripts
└── tasks/ # Hardhat tasks
- @fhevm/solidity (0.9.1) - Zama FHEVM for encryption
- @uniswap/v4-core (1.0.2) - Uniswap V4 protocol
- @uniswap/v4-periphery (1.0.3) - Uniswap V4 utilities
- @pythnetwork/pyth-sdk-solidity (4.2.0) - Price oracles
- @openzeppelin/contracts (5.4.0) - Standard contracts
- openzeppelin-confidential-contracts - Encrypted token standards
The test suite is organized into modules:
- PrivacyPoolHook.ts - Basic hook functionality
- PrivacyPoolHook.settlement.ts - Intent settlement and matching
- PrivacyPoolHook.shuttle.ts - Token deposit/withdraw flows
- PrivacyPoolHook.deltazero.ts - Oracle integration and rebalancing
- Version: 0.8.27 (primary), 0.8.26 (compatibility)
- Optimizer: Enabled with runs=1 (minimize bytecode)
- EVM Version: Cancun
- Via IR: Enabled (prevents stack too deep errors)
- ReentrancyGuard on all external functions
- Ownable2Step for safe ownership transfers
- SafeERC20 for token interactions
- FHE encryption for sensitive data
- Comprehensive test coverage
BSD-3-Clause-Clear
Based on the fhevm-hardhat-template by Zama.