# UniBrain Hook 🧠 Automate Onchain Functions ### What The `UniBrain` hook is designed to automatically trigger onchain actions using an automated Dutch Auction via a Uniswap V4 Pool ### How Imagine you want to automatically trigger an onchain action. How do you automate that? You pay a third-party to automatically trigger that function call -- *onchain or offchain*. **The UniBrain hook turns UniswapV4 into a hub for triggering onchain function calls.** ![](https://hackmd.io/_uploads/BkdeuAqGa.png) Instead of paying an offchain third-party or bootstrapping a new decentralized network, the UniBrain hook uses a Dutch Action to incentivize an existing network (i.e. block builders and searchers) to automatically trigger any onchain function by executing a profitable trade via the UniswapV4 protocol. ### Why There are many legitimate reasons for needing to automatically trigger an onchain function call. And it's up to the person/team setting up the UniBrain hook for Uniswap V4. # How It Works The UniBrain hook is designed to automate any onchain action at a predetermind time by using an automated Dutch Auction to incentive "rational economic actors" to periodally swap via the pool and **automatically triggering on onchain function call**. For example let's imagine we have a UniswapV4 DAI/USDC pool with a $1,000 worth of liquidity. And we want an onchain function to be called every 30 minutes. There is a cost to executing the onchain transaction. Let's assume it costs $0.03 to execute the onchain transaction. The UniBrain hook will automatically start a Dutch Auction every 30 minutes. And during this period the cost of purchasing USDC with DAI will decrease by $0.01 every 10 seconds. At a certain point in time it becomes profitable to execute a swap via the DAI/USDC pool. - 10 seconds = $-0.02 profit - 20 seconds = $-0.01 profit - 30 seconds = $0.00 profit - 40 seconds = $0.01 profit - 50 seconds = $0.02 profit In-turn automatically executing the onchain function call at a competitive price. **A win/win for everyone.** Searchers gets a small profit and an onchain service/protocol relying on that automation can sleep easily at night knowing their infrastructure will continue to run smoothly. # Hook Specification There are two primary smart contracts: 1. UniBrainHook 2. UniBrainHub ### UniBrainHook The UniBrain hook automatically starts a Dutch Auction at a designated time interval i.e. every 30 minutes. Changing the price curve between the two assets and incentivizing a swap to occur in the pool. ![](https://hackmd.io/_uploads/Syq1b1izT.png) Every swap will trigger a function call to the UniBrainHub. ### UniBrainHub The UniBrainHub upon receiving a "ping" from the UniBrain hook will execute a sequential transaction call to an external contract - **the function call can be set to anything**.