Nidhi

Pay contributors on any chain, only once their work is verified. Uniswap v4 hook, CCIP 2.0, ENSv2

Nidhi

Created At

ETHGlobal Mumbai

Project Description

DAOs hand out a lot of money for work: grants, bounties, milestones. Almost all of it still runs on trust. A multisig signs a transfer, everyone hopes the work was actually done, and if the contributor lives on another chain somebody bridges it by hand afterwards.

Nidhi (Sanskrit for "treasury") makes the payment itself enforce the rules. A grant can only leave the treasury if three things hold at the moment of the swap:

  1. Two different accounts signed it: an approver who says "pay this" and an auditor who says "the work is real". Who counts as an approver or auditor isn't stored in our contracts. It's read live from the DAO's ENS name (nidhi-dao.eth on ENSv2). Revoke someone in ENS and they're out instantly.
  2. The payee is an ENS subname like alice.nidhi-dao.eth, and her address is resolved for the destination chain at payout time. If the name has expired or has no address on that chain, nothing moves.
  3. The amount fits under a daily cap and inside a price band quoted with Uniswap's V4Quoter and guarded against manipulation with StateView.

When all of that holds, a Uniswap v4 hook swaps the treasury's WETH into the payout token, takes the entire output itself via afterSwapReturnDelta, and hands it straight to Chainlink CCIP 2.0. The tokens never sit in anyone's wallet in between. On the destination chain, a defensive receiver pays the grantee and sends an ACK receipt back, so the source chain marks the grant SETTLED. If the payout or ACK fails on the far side, the funds are held in the contract-never lost—and retried automatically via Chainlink Automation or permissionless calls. Chains with no direct CCIP lane are reached through an on-chain multi-hop relay.

For code work we went one step further and built an autonomous milestone pipeline. The DAO posts a task on-chain via NidhiBountyBoard (an ERC-1271 contract signer holding the ENS approver role): title, repo, amount, and required file paths. When a PR tagged with that task ID is merged and CI is green, the agent verifies it against a deterministic rubric, signs as auditor, and triggers the swap payout without needing a human at payout time. Open bounties work too: the first merged PR wins, and the contributor gets their own <github-name>.nidhi-dao.eth subname.

It's live on four testnets (Sepolia, Base Sepolia, Arbitrum Sepolia, Unichain Sepolia) with a working app that reads everything straight from chain. With CCIP 2.0 Faster-Than-Finality, grants reach the grantee in about 7 minutes instead of 15 to 25. We measured 6m 36s to Base and 7m 15s to Arbitrum on live testnet grants.

How it's Made

Contracts are written in Solidity 0.8.26 with Foundry. The core is NidhiHook, a Uniswap v4 hook built on OpenZeppelin's uniswap-hooks BaseHook with exactly three permissions: beforeSwap, afterSwap, and afterSwapReturnDelta. The address flag bits are 0xC4, mined with HookMiner per chain.

Because sender inside a Uniswap v4 hook is the router rather than the user, NidhiSwapRouter stores msg.sender in EIP-1153 transient storage (tstore) before calling PoolManager.unlock(), and NidhiHook reads it via msgSender() (tload) to bind execution to mandate.executor.

beforeSwap decodes the grant from hookData and enforces 10 sequential checks:

  • an EIP-712 mandate from an approver and an attestation from an auditor (ECDSA first, ERC-1271 fallback so a Safe or NidhiBountyBoard can hold the role);
  • the two signers must be distinct and hold live roles via IGrantAuthority;
  • the grantId has never been used, the deadline hasn't passed, and the swap is exact-input;
  • the payee address matches live ENSv2 subname resolution for the destination chain;
  • the daily spending cap;
  • an optional reference-price guard reading a canonical pool's slot0 through StateView.

afterSwap then take()s the full output directly into NidhiDispatcher and returns +output as the hook delta, so the swapper receives zero tokens.

The hacky bit: a gated hook normally breaks quoting because V4Quoter simulates the swap without a signed mandate. We pass the chain's V4Quoter into the hook and let it through with a zero delta (the quoter reverts its own swap anyway), so the app quotes every grant with the real V4Quoter. Liquidity is minted as a DAO-owned NFT through PositionManager with Permit2 after we proved in a fork test that liquidity seeded via the v4 test router can be drained by anyone.

ENS: ENSv2Authority maps each role (approver, auditor, guardian) to an Enhanced Access Control (EAC) ROLE_SET_TEXT permission on nidhi-dao.eth's PermissionedResolver. resolveGrantee walks registry -> subregistry -> resolver and reads addr using the ENSIP-11 coin type of the destination chain. We tested three subname models: alice (shared resolver), bob (own resolver, DAO control renounced), and carol (expiring grant window). NidhiBountyBoard holds the approver role on-chain, and the agent's identity is auditor.nidhi-dao.eth.

CCIP: NidhiDispatcher sends a programmable token transfer (tokens + grant data) and maintains a forward-only ledger (NONE -> DISPATCHED -> HELD / SETTLED). DestinationReceiver decouples the payout and return ACK in separate try/catch blocks so a reverting transfer or depleted fee reserve never reverts ccipReceive. Chainlink Automation (checkUpkeep / performUpkeep, MAX_BATCH=10) automatically retries held payouts and pending ACKs. For chains without a direct lane, NidhiHopRelay forwards the token transfer across an intermediate chain and rewrites the messageId on the return receipt; we settled Base -> Arbitrum -> Unichain live.

For CCIP 2.0 Faster-Than-Finality, NidhiDispatcher encodes GenericExtraArgsV3 with a configurable block depth per lane, and DestinationReceiver opts in via getCCVsAndFinalityConfig strictly for its known source dispatcher. Probing the lanes live showed Sepolia -> Base and Sepolia -> Arbitrum require a 32-block depth, cutting settlement to 6m 36s and 7m 15s.

Agent & Frontend: The TypeScript/viem agent runs in GitHub Actions on PR merge. A deterministic rubric checks merge status, review count, green CI runs, file globs, and diff bounds, while a multi-LLM jury (Groq, Cerebras, Gemini, Claude) holds advisory veto power only. The React + Vite + wagmi/viem + TanStack Query frontend runs statically on GitHub Pages with a build-time snapshot and incremental log cache for sub-3s loads.

Testing & Security: 139 Foundry tests across 16 suites (unit, fuzz, and invariant tests proving zero residual balances, value conservation, and daily cap enforcement), Slither static analysis (38 findings triaged, 0 open High/Medium), live Sepolia fork tests, and mainnet fork rehearsals across 7 chains.

background image mobile

Join the mailing list

Get the latest news and updates

Nidhi | ETHGlobal