Integrating Axiom and Uniswap V4 For Data-Rich Trustless DeFi Applications
October 4th, 2023

How Uniswap V4 & Axiom come together

Uniswap V4 represents the latest iteration of the leading decentralized exchange protocol. It introduces an innovative hooks architecture that enables developers augment pool functionality at different stages in a pools lifecycle.

Figure from draft of Uniswap V4 Whitepaper
Figure from draft of Uniswap V4 Whitepaper

Hooks allow building customized features on top of Uniswap pools, like whitelisting liquidity pools, oracles, and more. However, hooks have limited access to on-chain data, hindering their capabilities. Meanwhile, Axiom has introduced an on-chain "coprocessor" for Ethereum. Axiom allows smart contracts to make queries for historical data like past prices, balances, contract states and have the results verified on-chain via zk proofs Axiom uses two main contracts for you to accomplish this:

Note - If you’re like me, you’re not a God-Tier cryptographer like the folks at Axiom. I highly recommend to review some of the common blockchain cryptographic concepts. The more you understand these concepts the more Axiom and it’s capabilities will “click“ more for you Merkle Trees | zero-knowledge proofs | Ethereum Data Structures

AxiomV1 - a cache of Ethereum block hashes starting from genesis

AxiomV1 is a smart contract that caches historical blockchain data to allow verifying queries about the past. It stores past block hashes in two main ways:

  • As Merkle roots of consecutive blocks grouped together. This lets you prove a specific block hash is valid.

  • In a Merkle Mountain Range structure. This allows verifying ranges of blocks.

AxiomV1 has functions like updateRecent and updateHistorical that add new hashed blocks to the cache by verifying them with zk-proofs. It provides methods like isBlockHashValid to verify a specific block hash against the cached roots. And mmrVerifyBlockHash to verify against the Merkle Mountain Range.

The contract stores the latest mountain range and commitments to past ones. This allows using the cache to verify historical blockchain queries through cryptographic proofs of validity. The cache is updated over time so an increasing range of historical data can be proven. So in summary, AxiomV1 maintains verifiable caches of past block hashes that allow proving historical blockchain data through zk proofs.

AxiomV1Query - A smart contract which fulfills queries against AxiomV1

The query protocol allows requesting and verifying historical blockchain data through Axiom's contract. Here's a quick rundown of how it works:

  • To request data, you call Axiom's sendQuery or sendOffchainQuery functions. This submits the query specifying what data you need.

  • You provide a payment in ETH when submitting the query. This acts as a bounty for someone to do the work of fetching your requested data.

  • The query also specifies a deadline block. If the data isn't provided by then, you can get a refund.

  • To respond to a query, an Axiom node operator runs the off-chain work of retrieving the requested data from Ethereum's history.

  • The node then generates a zk cryptographic proof that verifies the data is correct.

  • This proof gets submitted back on-chain via the fulfillQuery function.

  • Axiom's contract checks the proof is valid and matches the original request.

  • If everything checks out, the contract records the data as verified.

So in summary, the query protocol consists of the on-chain functions to request data, pay bounties, refund, and verify responses. The core innovation is using zk proofs to generate proofs of historical blockchain data.

Integrating these two technologies unlocks alot of new potential. With Axiom providing trustless historical data access and Uniswap V4 hooks enabling custom functionality on liquidity pools, developers can now build data-rich defi apps on top of the Uniswap Protocol. Together, Axiom and Uniswap V4 provide the perfect ingredients for the next evolution of sophisticated data-driven DeFi products.

The integration of Axiom and Uniswap V4 brings a new era of possibility for data-rich decentralized finance applications. Axiom unlocks historical on-chain data for use in smart contracts by allowing developers to query information like past prices, balances, ownership records, and contract states. These results can be reliably incorporated into dapps thanks to Axiom's use of zk proofs for verifiable computation. By using Axiom with Uniswap hooks, developers can build decentralized applications that intelligently leverage historical data in automated, trustless ways.

Uniswap V4 🤝 Axiom Hook Ideas

Here are some ideas for Uniswap V4 hooks using Axiom

  1. TWAP trading based on historical prices - Execute TWAP trades using price data fetched from Axiom.

  2. Limit order hook - Place limit orders using Axiom to access historical pricing data off-chain.

  3. Lending fee adjustment - Adjust lending rates based on historical utilization ratios pulled from Axiom.

  4. Automated concentrated liquidity - Optimize concentrated liquidity positions based on historical trade data.

  5. Decentralized TWAP arbitrage - Arbitrage across DEXs using historical prices from Axiom.

  6. Liquidity provider profiler - Analyze historical provider behavior using Axiom data to identify profitable LPs.

  7. Time-based access control - Restrict access based on past on-chain activity verified through Axiom.

  8. Decentralized moving averages - Calculate custom on-chain moving averages using historical pricing data.

  9. Smart contract price feeds - Build reliable on-chain price feeds using historical data from Axiom.

  10. Liquidity incentives framework - Reward LPs based on historical usage data pulled from Axiom.

  11. Automated ecosystem buybacks - Perform token buybacks when historical prices hit specific thresholds.

  12. Automated Blacklist Identification - Identify malicious actors by analyzing transaction histories and patterns of abuse.

Resources to get started

Hooks using Axiom

Built by @saucepoint on Twitter during the ETHNYC Hackathon

A hook using Axiom I’m currently implementing - will be finished soon!

The buyback hook uses Axiom to access historical price data for a protocol's token. It sets a target price threshold and monitors the current price. When the price crosses below the threshold, the hook automatically executes a buyback.

Axiom Documentation & Talks/Articles

Axiom Demo Projects(This is really useful for seeing Axiom in action, especially the code examples as well)

Compilation of Uniswap Hooks Resources and some of my examples

Subscribe to Adam
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.
More from Adam

Skeleton

Skeleton

Skeleton