Build with Tenbin
Everything you need to run Tenbin, launch your own index, and quote or trade it from your own product.
Overview
Tenbin turns one wallet into a weighted index (for example 40% ETH, 30% BTC, 30% USDC) that two venues trade at once: Uniswap v4 through a custom-curve hook, and 1inch Aqua through a custom SwapVM instruction (opcode 0xd0). Both call the same quote() over the wallet's real balances, so their prices are identical and any arbitrage loop loses.
- Makers launch an index from their own wallet and choose how much each venue may sell.
- Traders trade it on either venue with any Uniswap v4 router, a 1inch SwapVM order, or one call to
TenbinLoopRouter. - Apps read the whole book in one call through
TenbinLens, privately through Anon-RPC if they want.
The contracts keep the project's first name (Tenbin*); the product is Tenbin. The plain-words explainer with diagrams is docs/explained.md ↗.
Quickstart
Needs Foundry ↗ and Node 22. About 5 minutes on a first run.
git clone --recursive https://github.com/Abhist17/tenbin
cd tenbin
(cd contracts && npm ci) && (cd web && npm ci)
./scripts/demo.shdemo.sh forks Base Sepolia (with the real Uniswap v4 PoolManager), deploys everything, launches a 40/30/30 index, trades on both venues, prints the numbers (0 wei apart; the loop loses) and opens this app on localhost:3000. Connect Dev #2 (trader) to trade.
Run the app
# against the local fork that demo.sh started
cd web && npm run dev
# against Base Sepolia (every read goes through Anon-RPC)
NEXT_PUBLIC_TENBIN_NETWORK=base-sepolia npm run devAddresses come from contracts/deployments/<network>.json; npm run sync copies them and the ABIs into the app.
Deploy to Base Sepolia
./scripts/setup-deployer.sh # fresh testnet wallet, encrypted; you choose the password
# fund the printed address with >= 0.005 Base Sepolia ETH (the deploy uses ~0.0002)
./scripts/deploy-base-sepolia.sh # deploy, launch the demo index, demo trades, 36 on-chain checksIt is resumable: run it again and finished steps are skipped. Already have a testnet key? cast wallet import tenbin-deployer --interactive.
Launch an index
The easiest way is the app: Create → Launch walks a wallet through six transactions and resumes after a reload. The same steps from code:
TenbinHookFactory.deploy(salt): your hook, at an address with Uniswap v4's permission bits (mine the salt withHookMiner, or in the browser like the app does).token.approve(aqua, max)for each token: the wallet's only approval.hook.setIndex(tokens, weights, fee): weights in 1e18 (40% =0.4e18), fee0.003e18.PoolManager.initialize(key, SQRT_PRICE_1_1)for each pair, with the key below.aqua.ship(hook, hook.strategy(nonce), tokens, limits): what Uniswap may sell.aqua.ship(swapVM, strategy, [a, b], limits)per pair, with the order fromTenbinLens.activeAquaOrder(hook, a, b): what 1inch may sell.
PoolKey({
currency0: min(a, b), currency1: max(a, b),
fee: 0, // the hook charges the 0.30% itself
tickSpacing: 60,
hooks: IHooks(hook)
})Quote both venues
One eth_call returns both venues' quotes and whether each venue can fill it (venue limit, 30% per-trade cap).
import { createPublicClient, http, parseUnits } from "viem";
import { baseSepolia } from "viem/chains";
import { TenbinLensAbi } from "./abis"; // web/src/generated/abis.ts
const client = createPublicClient({ chain: baseSepolia, transport: http() });
const { result } = await client.simulateContract({
address: LENS, abi: TenbinLensAbi, functionName: "quoteBoth",
args: [HOOK, SWAP_VM, WETH, USDC, parseUnits("0.1", 18), true], // exact in
});
const [v4In, v4Out, v4Ok, aquaIn, aquaOut, aquaOk] = result; // v4Out === aquaOutTenbinLens.book(hook, swapVM) returns every token's weight, balance, pending claims and both venue limits; quoteRoute quotes a multi-leg route exactly.
Trade
Simplest: one call that works on either venue, or several legs across both.
token.approve(loopRouter, amountIn);
TenbinLoopRouter(loopRouter).execute(
hook,
[USDC, WETH], // path
[0], // venue per leg: 0 = Uniswap v4, 1 = 1inch Aqua
amountIn, minOut, recipient
);- Uniswap v4: any v4 router (Universal Router, or your own) with the pool key above. The official V4Quoter returns exactly the hook's quote.
- 1inch Aqua:
swapVM.swap(order, amount, takerData)with the order fromTenbinLens.activeAquaOrder.
Read privately
The app sends every chain read through the Ethereum Foundation's Anon-RPC (Tor, falling back to Nym), with a separate isolation key per maker, pair and trader. Reuse its transport: web/src/lib/anon.ts exports readClient(label, key), a viem client whose reads are anonymised and logged for the Privacy page.
import { keys, readClient } from "@/lib/anon";
const c = readClient("my index", keys.maker(myAddress));
const book = await c.readContract({ address: LENS, abi: TenbinLensAbi, functionName: "book", args: [HOOK, SWAP_VM] });Contracts and addresses
Deployed on Base Sepolia for this build. Source: contracts/src ↗.
| Contract | What it does | Address |
|---|---|---|
TenbinHookFactory | Deploys one hook per maker (CREATE2, v4 permission bits) | 0x2F4578…51B18D ↗ |
TenbinLens | Read helper: the whole book, quotes on both venues, route quotes, previews | 0xe0410d…F9ca5b ↗ |
TenbinLoopRouter | One call for multi-leg trades across both venues | 0xcA34AB…671b25 ↗ |
TenbinSwapVMRouter | Official 1inch AquaSwapVMRouter plus opcode 0xd0 | 0x758fFD…F1db93 ↗ |
Aqua | 1inch Aqua (venue limits; the wallet's only approval) | 0x78999A…370239 ↗ |
PoolManager | Uniswap v4 (official deployment) | 0x05E733…A03408 ↗ |
Demo index (hook) | A live 40/30/30 index to trade against | 0xb6879F…ac6888 ↗ |
Test everything
./scripts/check-all.sh # contracts (incl. fork tests), typecheck + lint, fresh fork + deploy,
# 36 on-chain checks, 27 user flows, the browser suite (~6 min)
cd contracts && forge test # 59 tests: unit, fuzz, invariants, audit PoC, gas, fork
cd web && npm run e2e # every screen in real Chrome on a fresh fork
cd web && npm run e2e:testnet # the deployed site: reads really go through Anon-RPCLimits
- Tenbin does not reduce LVR: traders who rebalance you capture the market move; you earn the 0.30% fee.
- One trade can move at most 30% of a balance; each venue sells only up to its limit.
- Uniswap input waits as claims until the next swap or a
flush(); it is priced in at once. - Use a dedicated wallet: quotes read its live balances.
- Testnet only. Not externally audited; see AUDIT.md ↗.