Skip to content

MarcusWentz/eth-new-york-2025

Repository files navigation

⛓️ Cross-Chain Volatility Hook 🪝

Dynamic fee Uniswap v4 Hook using cross-chain Chainlink volatility data via LayerZero

Summary: This project implements a Uniswap v4 hook that dynamically adjusts trading fees based on real-time volatility data sourced from multiple blockchains. By leveraging Chainlink's price feeds on Arbitrum and transmitting this data via LayerZero's cross-chain messaging protocol, the hook creates a more responsive and risk-adjusted fee structure for liquidity providers.

Technical Architecture: The system consists of three core components: a data ingestion contract on Arbitrum that reads Chainlink's ETH-USD 30-Day Realized Vol metric, a LayerZero bridge integration that securely transmits volatility data across chains with minimal latency, and a Uniswap v4 hook contract that receives cross-chain volatility updates and implements dynamic fee adjustments in the beforeSwap function.

ETHGlobal NYC August 2025 Team

Marcus Wentz Dina Deljanin Mylo Bennett

Leveraging the Uniswap v4 Hook Template

(original template README below)

This template provides a starting point for writing Uniswap v4 Hooks, including a simple example and preconfigured test environment. Start by creating a new repository using the "Use this template" button at the top right of this page. Alternatively you can also click this link:

Use this Template

  1. The example hook Counter.sol demonstrates the beforeSwap() and afterSwap() hooks
  2. The test template Counter.t.sol preconfigures the v4 pool manager, test tokens, and test liquidity.
Updating to v4-template:latest

This template is actively maintained -- you can update the v4 dependencies, scripts, and helpers:

git remote add template https://github.com/uniswapfoundation/v4-template
git fetch template
git merge template/main <BRANCH> --allow-unrelated-histories

Requirements

This template is designed to work with Foundry (stable). If you are using Foundry Nightly, you may encounter compatibility issues. You can update your Foundry installation to the latest stable version by running:

foundryup

To set up the project, run the following commands in your terminal to install dependencies and run the tests:

forge install
forge test

Local Development

Other than writing unit tests (recommended!), you can only deploy & test hooks on anvil locally. Scripts are available in the script/ directory, which can be used to deploy hooks, create pools, provide liquidity and swap tokens. The scripts support both local anvil environment as well as running them directly on a production network.

Troubleshooting

Permission Denied

When installing dependencies with forge install, Github may throw a Permission Denied error

Typically caused by missing Github SSH keys, and can be resolved by following the steps here

Or adding the keys to your ssh-agent, if you have already uploaded SSH keys

Anvil fork test failures

Some versions of Foundry may limit contract code size to ~25kb, which could prevent local tests to fail. You can resolve this by setting the code-size-limit flag

anvil --code-size-limit 40000

Hook deployment failures

Hook deployment failures are caused by incorrect flags or incorrect salt mining

  1. Verify the flags are in agreement:
    • getHookCalls() returns the correct flags
    • flags provided to HookMiner.find(...)
  2. Verify salt mining is correct:
    • In forge test: the deployer for: new Hook{salt: salt}(...) and HookMiner.find(deployer, ...) are the same. This will be address(this). If using vm.prank, the deployer will be the pranking address
    • In forge script: the deployer must be the CREATE2 Proxy: 0x4e59b44847b379578588920cA78FbF26c0B4956C
      • If anvil does not have the CREATE2 deployer, your foundry may be out of date. You can update it with foundryup

Additional Resources

Forge Deploy and Verify

Arbitrum Sepolia

Deploy EthRealizedVolatility.sol

forge create src/EthRealizedVolatility.sol:EthRealizedVolatility \
--private-key $devTestnetPrivateKey \
--rpc-url $arbitrumSepoliaHTTPS  \
--etherscan-api-key $arbiscanApiKey \
--broadcast \
--verify 

Deploy LayerZeroArbToUniOApp.sol

forge create src/LayerZeroArbToUniOApp.sol:LayerZeroArbToUniOApp \
--private-key $devTestnetPrivateKey \
--rpc-url $arbitrumSepoliaHTTPS  \
--etherscan-api-key $arbiscanApiKey \
--broadcast \
--verify 

Unichain Sepolia

EthUsd.sol

forge create src/EthUsd.sol:EthUsd \
--private-key $devTestnetPrivateKey \
--rpc-url https://sepolia.unichain.org \
--verify \
--verifier blockscout \
--verifier-url https://unichain-sepolia.blockscout.com/api/ \
--broadcast

LayerZeroUniToArbOApp.sol

forge create src/LayerZeroUniToArbOApp.sol:LayerZeroUniToArbOApp \
--private-key $devTestnetPrivateKey \
--rpc-url https://sepolia.unichain.org \
--verify \
--verifier blockscout \
--verifier-url https://unichain-sepolia.blockscout.com/api/ \
--broadcast

Verify Blockscout Contract Already Deployed

forge verify-contract \
--rpc-url https://sepolia.unichain.org \
<contract_address> \
<contract_file_path> \
--verifier blockscout \
--verifier-url https://unichain-sepolia.blockscout.com/api/

Hook Counter.sol

forge script script/00_DeployHook.s.sol:DeployHookScript \
--private-key $devTestnetPrivateKey \
--rpc-url https://sepolia.unichain.org \
--broadcast 

Verify Uniswap V4 Hook Contract Already Deployed

Use the contractAddress from CREATE2 from

broadcast/00_DeployHook.s.sol/1301/run-latest.json

then run

forge verify-contract \
--rpc-url https://sepolia.unichain.org \
<contract_address> \
src/Counter.sol:Counter \
--verifier blockscout \
--verifier-url https://unichain-sepolia.blockscout.com/api/

Arbitrum Sepolia Deployments

EthRealizedVolatility.sol

https://sepolia.arbiscan.io/address/0xeef4f98dd12fcc6193ccce792f3983803d0b56ed#code

LayerZeroArbToUniOApp.sol

https://sepolia.arbiscan.io/address/0xc26ea02fb53594952b64559278bd0622555584e4#code

Unichain Sepolia Deployments

EthUsd.sol

https://unichain-sepolia.blockscout.com/address/0xE00fAe47783A593f3975A13Dec9D957A437d1118?tab=contract

LayerZeroUniToArbOApp.sol

https://unichain-sepolia.blockscout.com/address/0x5eCe667D03F29695937F23178aBad9B89434D630?tab=contract

Hook Counter.sol

https://unichain-sepolia.blockscout.com/address/0xe802507CEF5511C4A1577d829C03870B5fbAcaC0?tab=contract

LayerZero Bridge Communication

https://testnet.layerzeroscan.com/tx/0xba24eade9471711df2e5f143b4af3c5da859fd36dc3be7b6b2a0834252ae4cc7

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •