Loading video player...
[Music]
If you're looking to build any D5
application during the weekend, let me
tell you something. Now, it is fully
possible to customize all of your D5
experience from the swap cycle. meaning
before and after the swap, you can add
some sort of like logic that allows you
to customize the way that you interact
with your users. For example, let's say
you are looking to add before this a
logic that allows you to wist some sort
of addresses in order for you to
understand who are the ones that
interact with your pool. So from real
world assets to incentive or lordies or
even why not you want to improve
liquidity providers capital efficiency
there's certain ways that after this
talk you're going to understand not just
how to build over the weekend but also
how to be part of the future financial
infrastructure my name is Angel Cando I
am the developer community manager here
in the UNISA foundation and along with
my colleague Ditba we are going to guide
you over the UNISA B4 protocol hooks,
clear problem statements for you to
build and also a B4 template that is
going to allow you to first your first
um hook. Uh but first, let me introduce
you the UNISA Foundation. In pursuit of
a more open and fair financial system,
the UNISA Foundation supports the
growth decentralization and
sustainability of the UNISA community,
focusing on five key pillars. Protocol
innovation, developers, we are here for
sure. Governance, research, and
security. So, yeah, let's go over the
Uniswap protocol understanding. Just as
a brief recap, the unis swap protocol it
is a peer-to-peer system designed for
exchanging cryptocurrencies or ERC20
tokens. So for example, if you are
looking to trade ETH for USDC in a
decentralized ways, the in a
decentralized way, the protocol, it is a
set of smart contracts that connects
from one side the liquidity providers
and on the other the traders in this
case you wanted to trade ETH for USDC.
Um, and it's important to mention that
all of these contracts are not
unbreakable and of course these are
designed to prioritize censorship
resistance, security, self custody and
way more. um the UNISA BD1 it was
launched on uh 2018 but over the time
the protocol it's been improving for
sure and we now have um B4 version that
not just allows you to trade any 20 to20
tokens um but also uh more than the
content liquidity meaning on the B3 and
B4 version you have the possibility as a
liquidity provider to say hey I want to
add my liquidity from this range or
prices range. Now we have the singleton
architecture for example everything is
in one contract all the pools all the
tokens meaning not just gas efficiency
but it providing a better experience out
there. In the past we used to have fixed
uh fees from uh 0.3%
to 1%. Now we have continuous fees
spectrum and dynamic fees meaning as a
developer you have the full field uh
flexibility out there to decide what are
the fees you want to implement for your
users and we also have the ESC uh 6909
and flash accounting meaning uh from
internal tokens transactions as
arbitrari and operations with like mini
minimal token uh transfer. We're not
just looking for gas efficiency, but
providing uh a seamless trading
experience out there in a decentralized
ways. And fine, and finally um I don't
know if you remember, but I mentioned
some sort of like logic that you can add
before and after the swap. We call that
hooks, meaning having the possibility to
add arbitrary logic attached to the life
cycle operations. So again, now you have
the full possibility to customize your
DeFi application from the beginning and
of course stick the decision you um
think are be the best for your users out
there. So just from a visual perspective
back in the day and like the B3 version
of the protocol launched in 2021
um if you wanted to trade ETH for D. So
these are uh two different operations
going first uh from ETH to USDC and then
from USDC to D or if you want to use uh
USDT like the same. Um but now with the
B4 uh including the single toe contract
but also the flash accounting everything
happens in just one uh transaction
inside one contract. So yeah a better
experience that you can look not just in
like the gas efficiency but then your
users are going to um notice 100% from
uh the the the price impact and way
more. And finally, hooks that if you
remember I mentioned before and after
the swap, you can add some sort of like
custom logic or scripts that allows you
um to add external contracts that
finally modify the pool behavior. Um so
important note in here is the fact that
you can only add one hoop per pool but
then one hoop can serve many pools out
there. And the B4 protocol includes 14
hooks um hook functions available from
before and after the swap. You can add
or remove liquidity, donations, update
fees and way more. Just in a few
seconds, my colleague DBA is going to
show you some of them and through our
template you're going to understand how
to activate it. Just let me go um real
quick on the flow and how the protocol
works in order for you to understand
where to add or um delete that logic. So
on you uh start the swap the system is
going to check before swag flap meaning
if you added any custom logic the system
is going to be there and executed. If
not, just execute the swap right as a
normal transaction. And then after the
execution of the swap, it is going to
check after the swap flag if you added
any sort of like custom logic or not.
And for sure execute it till the end of
the swap. So now you understand what are
like some of the features and
possibilities that allows you to
customize all of the DeFi um experience
out there. Hopefully uh during the
weekend you're going to ended up
building one of these hooks. But now I
want to show you along with my colleague
Deva some of like clear problem
statements and also how to use the B4
template. So that way again not just
building hooks here at it global but
then the future of the D5 application
that you go ahead.
>> Thank you so much for that wonderful
explanation Angela. I'll be going over
some problem statements now that we have
designed to give you some ideas to hack
over this weekend. The first one is the
stable stable efficiency at scale. This
problem is about designing a hook that
targets the stable coin pairs with trade
sizes over half a million dollars on
mainet. The main thing to consider here
is of course the mainet gas costs which
can get quite expensive. You also need
to think about how would this hook
compete with other taxes in that market
and how do you reduce me on trades of
such large sizes.
The next one is the TBAP execution hook
which is very closely related to the
previous problem. This is about
designing a hook that enables TBAP which
is time weighted average price execution
for large swaps. So could you possibly
split an a large order into much smaller
orders and have them split over time so
that you get a much better price
execution. Um could you also minimize
slippage using this? Some things that
you might want to look into this are how
do you integrate it with 1 in limit
orders or even the smart order router
from unis swap.
The next is the pendle style AMM
rebuild. So pendle allows you to split
an eelbearing asset into a principal
token and an eel token and it has an
time decking emm to price such assets.
The problem statement here is of course
how do you design a PMM style AMM on
unis swap itself as a v4 hook and this
is something that we are really excited
to see.
The next is the world ID verified pools.
So Coinbase already uses unis swap v4
hooks for its verified pools that allows
users to only interact with pools that
meet the institutional AYC KYC and AML
standards. So you could also use the
same thing to build a world ID mini app
that allows verified users to interact
with certain liquidity pools. The things
that you also need to think about here
is how do you improve and mitigate civil
resistance, improve UX and compliance in
DeFi with such verified pools.
The next is the lottery pools with
social yield. I'm pretty sure most of
you know what pull together is, but it
is a no- loss lottery where people pull
in some assets and the yield is
redistributed to people as the lottery.
So, how do you recreate such no- loss
lotteryies for stable coin pairs using a
hook enabled world mini app? Again,
using some previous ideas and mix and
matching these. Could you also
incorporate social rewards, world ID and
gas abstraction features directly into
this v4?
The next is the smart borrow. Another
superpower that is unlocked by hugs is
the rehypothetication of liquidity.
Which means that you can put out of
range liquidity into platforms like a or
similar lending protocols like compound
or morpho and have them generate yield
even though it might not be generating
on unis swap. Some other ideas that you
can look into uh is smart borrowing,
leveraging automation and even
conditional loan logic.
Another thing that's uh uh hooks unlock
is the assets that were previously not
available on unis swap can now be uh
available on pools through uh hooks. So
could you design a hook that supports
the primary issuance of RWAS and of
course integrate KYC compliance checks
arc 6343 or other institutional
standards into this.
The next two problems are a bit
complicated, but again they're looking
for open innovation in these cases. The
first one is the under 5K E swaps on L2.
Um, in this case, you need to design a
hook for ETHUSDC swaps which fall under
the range of 5,000 on Unien and of
course other low cost L2s like B and you
need to guarantee best price execution
and compete with aggregators. NIS swap
already does a pretty good job at this,
but could you design a hook that takes
it to the next level? The next problem
again takes it a step further which is
to trade with medium-sized trades. How
do you recapture mess for LPS in these
cases or probably create an incentive
mechanism that boosts volume or
liquidity depth for such pairs on L2s?
Again, we know that these problems are
hard but you feel free to take some
ideas from previous uh hooks and try to
put uh put on these. Again, you're not
limited to the ideas that I've just
discussed and you're free to choose any
ideas for this hackathon.
The next are some resources that I'd
like to discuss. The first one is the
hook directory by atrium academy which
is the learning arm of UF and it
conducts the unis swap incubator over
the year. Uh they have a hookathon at
the end of each cohort and the public
and the projects are all public on this
notion doc that you can get by scanning
this QR code. Uh we highly encourage you
to go and take a look at this to see how
the previous hooks have been built uh
especially the hooks that have won some
prizes and you can get and take a look
at all of their backend and front-end
code for your own inspiration for your
hooks. The next is the UF hacker
toolkit. This toolkit is something that
has everything at one place. It has all
the bounties that are there, all of the
judging criteria that we need, all of
the ideas that I've just discussed, the
documentation and resources and so much
more. So, uh, feel free again go go go
go ahead and scan this QR code to get
the toolkit. The next up is the V4
template. The V4 template is something
that we've designed to help you get up
to speed on developing hooks. So, uh,
again, you just scan this QR code and
get the uh, GitHub link and you can just
clone this repo and you uh, it has all
of the dependencies installed. It has
many of the scripts to deploy a pool,
deploy the liquidity to such boost your
hook as well. And this is the perfect
way to get started with hook development
on V4. I'll give you a small rundown or
demo of how to use this V4 template.
Okay, I think this should be visible
now. So I've already cloned the repo to
my local machine and this is the readme
for this. It's uh pretty standard to get
started with this. You just clone the
repo and then do a foundry up to make
sure that you are on the latest version
of foundry. Do forge install which I've
already done and then you can do a forge
test to make sure that everything has
been done correctly.
Um while that runs uh I'll show you the
important parts. So over here we have
the scripts. uh the base scripts and the
liquidity helpers to help with the
liquidity provision, the deploy scripts,
the create pool. I'll I'll come back to
those and the test run. Okay. Yeah. So,
src, which has the counter.soul is the
main file that you want to be looking
at. This is where you actually develop
your hook and this is a very basic
sample hook that we have developed for
you. Um this is a counter which has four
mappings that counts anytime a before
swap book is called and after swap book
is called before add liquidity before
remove liquidity. Again these are the 14
hope functions that you can use for V
before hope development and you need to
set all of them true uh the ones that
you probably are using for so the before
add liquidity would be true over here
before swap after swap and of course the
before remove liquidity.
In this case, we're not doing a lot, but
in fact, just incrementing the counter
by one whenever this function is called,
and it's a very basic hook, but it
serves the purpose for a demo. In this
case is where you define all of the
tests. So, whenever you're testing your
hook is where this is where you'll write
all of your tests.
You set up uh the hook by deploying the
hook by adding that hook to a pool,
deploying that pool with some liquidity,
and then testing the hooks over here.
And before add liquidity should be one
before because we have already added
liquidity to the pool. Everything should
be zero. After you make a swap the
before swap and after swap should both
turn into one because in a swap life
cycle both before swap and after swap
are called. Again for test liquidity you
do the same things. What I want to show
you over here is let's say I do I I want
to actually go ahead and test this hook
on a real uh on a real test net or even
mainet. I can just make a anvil fork of
this. So I'll do anvil fork RPC URL. I'm
using Uni Sapoleia for this case. But
again it's just a fork of the unicia
itself. It's started now. So what I can
do is let let's say I want to deploy
this hook. So I would need to call the
deploy hook script. I'll call forge
script and I already have a lot of it
rewritten
call 0. Yes. And I can just call this
and this should ideally deploy the hook.
The constants are the private key and
the RPC URL uh which I've already taken
from the anvil itself.
And we're just waiting for this. Let me
probably increase this over here.
And yes, everything went successfully.
We even got the hook address. Um so now
assume you want to use this hook and
test with this. So you would go to the
base script which is available in
scripts and change the hook address over
here. After you change the hook address
you probably want to deploy some tokens
and I've just created this small script
which says to create tokens. I've
created two mock tokens and I'll deploy
these tokens and mint some to the
message. So I can just call this as
well.
scripts
uh 018.
And this should ideally create two mock
tokens and mint me about 10,000 of each
uh because the decimals are 18 for both.
And we should see yes the transactions
are coming on anvil as well.
It compiles
and yes everything goes successfully
over here as well. We get both the token
zero and token one address. Let me copy
these again. Change these on
the base script to make sure that is
available everywhere else. After I've
created the tokens, I would like to
create a pool and add liquidity.
With this script, you'll be able to
create an ad liquidity. I can show you
what it does. It sets the LP, the tick
spacing, the starting price, both the
token amount. So I'm I'm just in uh
initializing a pool with 100 tokens of
each take uh you have to create a pool
key for that of course it fetches the
currency zero and currency one from the
base script the hook contract as well
from there and
it mints the liquidity for both of them.
So this is an action based uh
multicol. So you need to use actions
like these then you value pass and then
you just multi call with everything. So
this should create a pool and add
liquidity all at the same time with this
multi call
setting up the AVM
and yes everything was successful once
more. So we have set up the pool and we
have deployed liquidity to this. The
final step is to of course just do the
swap and we can do a swap using the
script. Let me run the swap as well.
Uh we'll do a 03 swap.
For swap as well, we just get the pool
key. You need to specify uh every pool
on V4 is identified by these five
parameters which is currency zero,
currency one, fee, tick spacing and
hooks. Uh these all identify a unique
pool and with these pools you approve
the tokens first. We're uploading both
of them because we're just testing. And
then we call the swap router swap tokens
for tokens. And again, you just specify
how much tokens you want to send in, how
much you want to get out. Again, this is
bad practice, but we're just testing.
And yes, it goes successfully as well.
So this is how you use all of the V4
template and its scripts. And you can
use it in a production environment or
for local testing as well. You have
everything available over here. And
happy development.
[Music]
Deep dive into Uniswap v4 and how hooks let you customize the entire swap lifecycle. Angela Ocando introduces v4 upgrades—singleton architecture, continuous/dynamic fees, ERC-6909 + flash accounting—and explains pre/post-swap hooks. Dayitva Goel outlines concrete hook ideas (from stable-stable execution and TBAP to RWA/KYC pools and rehypothecation). A hands-on demo shows the official v4 Hook Template: writing a simple counter hook, testing with Foundry, forking, deploying a hook, creating tokens, spinning up a pool, adding liquidity, and executing a swap. 00:02 Why v4 now: customize DeFi around the swap 00:33 Hooks = pre/post-swap custom logic (whitelists, loyalty, RWA, LP UX) 01:31 Uniswap Foundation pillars & role 01:56 Protocol recap: LPs ↔ traders; censorship-resistant, self-custody 03:13 What’s new in v4: singleton, dynamic fees, ERC-6909, flash accounting 04:38 Hooks overview: 1 hook per pool; 14 hook functions available 05:02 v3 routing vs v4 singleton + flash accounting (one tx) 06:00 Where hooks run: before/after swap, add/remove liquidity, fees, donate 07:25 Hook lifecycle flags (before/after) & flow 07:48 Hack ideas: large stable-stable, TBAP execution, Pendle-style AMM 09:15 World ID–verified/KYC pools; sybil resistance & UX 10:01 No-loss lottery pools with social yield (Pull-Together-style) 10:20 Smart borrow: rehypothecate out-of-range liquidity 10:38 RWA primary issuance hooks + compliance (ARC-standards) 11:09 L2 sub-$5k ETH-USDC best-price hooks; mid-size trade incentives 12:20 Resources: Hook Directory (Atrium), Hacker Toolkit 13:01 v4 Hook Template intro (GitHub) 13:54 Setup: clone, Foundry update, forge test 14:16 Scripts tour: deploy, create pool, liquidity helpers 14:37 Example hook: counter.sol (before/after swap & liquidity) 15:22 Writing tests: deploy hook, add liquidity, assert counters 16:12 Anvil fork (Uni Sepolia) for local testing 16:43 Deploy the hook (forge script) → get hook address 17:11 Configure base script with hook address 17:57 Create mock tokens & mint balances 18:38 Create pool + add liquidity (multicall actions) 20:09 Execute a swap via router; pool key params in v4 20:26 Wrap-up: template = fastest path to production hooks _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 🇮🇳 *ETHGlobal New Delhi* This workshop is specifically for ETHGlobal New Delhi, a 3-day hackathon held September 19-21 at the India International Convention & Expo Centre, bringing together the most skilled web3 developers, designers and product builders from all around the globe for a weekend-long adventure to advance the Ethereum ecosystem! Watch the full ETHGlobal New Delhi 2025 playlist here: https://www.youtube.com/playlist?list=PLXzKMXK2aHh7zCFW3hBqatZ18rQaYeEJL _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ✅ *Follow Uniswap Foundation* X: https://x.com/UniswapFND ✅ *Follow ETHGlobal* X: https://x.com/ETHGlobal Warpcast: https://warpcast.com/ethglobal Website: https://ethglobal.com YouTube: https://www.youtube.com/c/ETHGlobal _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _Are you interested in Ethereum development and entrepreneurship?_ 👉 Sign up for the next ETHGlobal event: https://ethglobal.com/events 🎁 Get exclusive access and perks with ETHGlobal Plus! https://ethglobal.com/plus 📣 Want us to throw an event in your city? Tell us where! https://ethglobal.com/city