Privacy-First P2P Token Exchange powered by Fully Homomorphic Encryption (FHE)
FHE-OTC is a decentralized over-the-counter trading platform that enables private peer-to-peer token swaps using Fully Homomorphic Encryption. All sensitive trading dataβprices, amounts, and order detailsβremain encrypted on-chain, providing unprecedented privacy for institutional and retail traders.
- π Encrypted Order Book - Prices and amounts never exposed on-chain
- π‘οΈ MEV Protection - No front-running possible without price visibility
- π€ P2P Matching - Direct counterparty settlement without intermediaries
- π EVM Compatible - Works on Arbitrum, Base, and any EVM chain with CoFHE
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend (React) β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β Wallet β β Order β β Trade β β
β β Connection β β Form β β History β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β β
β cofhejs SDK β
β (Client-side Encryption) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Smart Contracts (Solidity) β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β FHE-OTC.sol β β
β β βββββββββββββββ βββββββββββββββ βββββββββββββββ β β
β β β Encrypted β β Order β β Settlement β β β
β β β Order Book β β Matching β β Engine β β β
β β βββββββββββββββ βββββββββββββββ βββββββββββββββ β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β CoFHE Coprocessor β
β (FHE Operations on Encrypted Data) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Blockchain Layer β
β Arbitrum / Base / Ethereum (with CoFHE support) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Data Type | Traditional DEX | FHE-OTC |
|---|---|---|
| Order Price | Visible to all | Encrypted |
| Order Amount | Visible to all | Encrypted |
| Order Direction | Visible to all | Encrypted |
| Counterparty Identity | Visible after match | Optional anonymity |
| MEV Exposure | High risk | Protected |
- Node.js 20+
- Bun or npm
- Foundry (for contract development)
- MetaMask or compatible wallet
# Clone the repository
git clone https://github.com/buffedgecko/fhe-otc.git
cd fhe-otc
# Install dependencies
bun install
# Setup environment
cp .env.example .env# Deploy to Arbitrum Sepolia
forge script script/Deploy.s.sol --rpc-url $ARBITRUM_SEPOLIA_RPC --broadcast
# Or deploy to Base Sepolia
forge script script/Deploy.s.sol --rpc-url $BASE_SEPOLIA_RPC --broadcastcd frontend
bun install
bun run devfhe-otc/
βββ contracts/
β βββ src/
β βββ FHEOTC.sol # Main OTC contract
β βββ EncryptedOrder.sol # Order data structures
β βββ interfaces/ # Contract interfaces
βββ frontend/
β βββ src/
β β βββ components/ # React components
β β βββ hooks/ # Custom hooks for FHE
β β βββ pages/ # Next.js pages
β β βββ lib/ # Utilities
β βββ package.json
βββ docs/
β βββ ARCHITECTURE.md # Detailed architecture
β βββ SECURITY.md # Security considerations
β βββ TUTORIAL.md # Step-by-step guide
βββ test/
β βββ FHEOTC.t.sol # Foundry tests
βββ foundry.toml
βββ package.json
βββ README.md
# Run all tests
forge test
# Run with verbosity
forge test -vvv
# Run specific test
forge test --match-test test_CreateOrderLarge token swaps without market impact or front-running risk.
OTC deals between parties who want to keep terms confidential.
Execute trades without exposing your intentions to searchers.
Trade large amounts without triggering price manipulation.
function createOrder(
address tokenA,
address tokenB,
InEuint64 calldata encryptedAmountA,
InEuint64 calldata encryptedAmountB,
bytes calldata encryptedPrice
) external returns (bytes32 orderId);function matchOrders(
bytes32 orderA,
bytes32 orderB,
Permission calldata permission
) external;function cancelOrder(
bytes32 orderId,
Permission calldata permission
) external;FHE-OTC uses the following encrypted operations:
| Operation | Description |
|---|---|
FHE.add() |
Add encrypted amounts |
FHE.sub() |
Subtract encrypted amounts |
FHE.mul() |
Multiply encrypted values |
FHE.eq() |
Check equality (encrypted result) |
FHE.lt() |
Less than comparison |
FHE.gt() |
Greater than comparison |
FHE.select() |
Conditional selection |
| Network | Chain ID | RPC | Faucet |
|---|---|---|---|
| Arbitrum Sepolia | 421614 | https://sepolia-rollup.arbitrum.io/rpc |
Alchemy Faucet |
| Base Sepolia | 84532 | https://sepolia.base.org |
Alchemy Faucet |
| Ethereum Sepolia | 11155111 | https://rpc.sepolia.org |
Alchemy Faucet |
MIT License - See LICENSE for details.
- Fhenix - FHE Infrastructure
- Zama - TFHE Library
- CoFHE - Solidity FHE Library
- cofhejs - JavaScript SDK
- Telegram: Fhenix Community
- Discord: Fhenix Discord
- Twitter: @FhenixIO
Built for Fhenix Private By Design dApp Buildathon Wave 2 π