Optimizing DeFi with ERC-4337 and AI Agents

EthCC[8] · 3 Jul 2025 · 19:05

Yehia Tarek presents AI agents integrated with ERC-4337 smart accounts. The presentation examines automated cross-chain DeFi strategies, gas optimization and yield monitoring for digital-asset management.

Speakers

Topics

From EthCC[8], hosted by Ethereum France.

Transcript

Hello and welcome everyone. Thank you for taking time for this talk. My name is Yaha. I'm a blockchain engineer at Nethermind. I mainly work on smart contract and server side. Uh this talk will be about onchain AI agent with abstract wallet. uh I will start the first uh two or three slide just a very quick introduction to make sure we are all on the same page uh then we'll share some design decision uh I was discovering when working on this then risk and challenges and at the end I will share with you some cool AI agent I found when doing some search

so first uh for AI agent we have a lot of onchain AI agent like for trading for NFT for a lot of different thing. Today we will talk about the defy optimization one. The AI agent we may use for defy. And when I mention AI agent for defy, I don't mean uh trading bots. I mean mainly wallet. So when you have an AI agent, you don't need it for trading only. Like you don't need a DCA for like AI agent to do a DCA, but it would be much more useful uh for your wallet. So you like you not need you need to have all your saving

you not your saving on trading bots but you may put all your saving on a wallet and that what uh this talk about is to how to optimize defy mainly by taking some TVL from CFI platform and give it to your decentraliz your decentralized finance applications using AI. So everyone from attendees I feel everyone is technical so I will not take a look time on this. So everyone knows the issues of uh CFI applications like custody, transparency, control, all of this everyone know about them. When you use defy application, you have your ownership transparency, self-custodials, everything.

And even from investment perspective, if you are using not custodial wallets on Solana for example, you would uh get the Trump memecoin uh much earlier. Uh but and of course air drops and higher yield higher yield for pools. But uh centralized exchange have a huge point which is tools. Like when you use any centralized exchange you have all tools in one place with a stable fees. So you don't need to worry about anything. You set your strategy your strategy for saving and you save your money on a centralized exchange and you feel it is more safe than having it on like um any non-custodial wallet.

So uh the main idea is to find a way uh to bring all TVLs from centralized exchanges to uh defy. To do this our gateway could be the abstract wallet. So I hope everyone know about abstract wallet like quickly it is the new version of externally owned account and have uh two main component pay master user operation entry and bundler everything. So uh this wallet can be our gateway as it's programmable we can add our own pools and add our own uh like code and plugins for it. Y ERC4337 not the newest version which is 7702.

The main reason was the private key. Everyone knows that the private key is a bit problematic. If you have your old wallet and you transfigure it to externally own it account private key still an issue like someone still can use your wallet with a private key you can lose all your fund and also one of the main issues is it's like new standard not experimented yet and not yet for usage so I prefer it use using the old one to make sure I have all standard features and everything more or less stable of course some other teams on ERC7702 did a great job like Porto team if someone heard about them they had a talk

yesterday so I was amazed to see the features they have for example you don't need the private key on their case because they offered a way to like you need only to delete the private key just make it disappear and use social media recovery which was great still you will have an issue if you have the private key but it was quite interesting and it's quite easier to use than the standard abstract wallet and have native pay master but still in development but was quite interesting. Anyway, whatever the way we use it, the end goal we have is to have a better way uh to use defy and uh features we may be able to

implement. For example, abstract wallet have session keys. Session key we can use it to set a policy for the AI agent. We have gas flexibility. For example, the AI agent can decide what is the most optimal way to pay your fees each time you execute a transaction and easier crosschain execution. Uh for me I keep check uh checking all uh like uh bridges centralize it decentralize it one see what is the lowest fees then pick it which doesn't need a human to do this like AI agent can just check all bridges and pick the best one automating boring task like keep claiming from certain pools and when claiming I claim

on a time if it is on mainet that the gas fees is not so expensive which is uh cool and um the like the common thing the common thing about all these features is it doesn't need AI too much like if you think about it most of this uh features we are able to do it with normal automation just write code for example uh uh for question execution use an aggregator pick the best aggregator you know and use it automated boarding task write a Python script which is a fair point but if we take an example like this for example

I have some a lot of stable coin it is my saving I don't want to risk them I want only to get some passive income from stable uh pools so simply I will deposit all my uh USDC USDT whatever on a pool then I keep waiting until I find a pool with higher yield I keep switching between them just rebalancing my portfolio. But then I will discover that some pools have fees more extra fees or have some locking time which may cause issues. And in other cases uh you may not have the best uh like yield or not best APY but

it would offer you uh let's say uh some air drops or some points here. The AI agent can be used because with AI agent you have some context awareness. You know what's happening and like the AI agent help you to decide your strategy. So the I agent aware of what you prefer and you can program it or like talk with it saying okay like I prefer this aggregators I prefer this defy project I believe in one two three and the AI agent should have the needed tools so it can fetch all data and help you doing this.

So uh at the end like for the automation mainly your AI agent the more tools the more automated script you give to your agent or like the more code you give your agent as a tool the more your AI agent will be strong and the more features you can create starting from like picking what is the best strategy for you like catching any new opportunity for example for the bridging aggregator stuff if you are using them with a if you are using um AI agent sometimes aggregator give offer like you do transactions for free if you are doing a script it will not catch it it will just catch the exact fees so some

slightly different but will make your uh application much more smart and that's for the automation for the design of the wallet so this is the standard I saw for most of wallet AI agent wallet You have the client side. The client would submit some request uh to the like to the interface that's just doing authentication. You have your TE, your server, your whatever you prefer and it is connected to some tools to get prices and then this AI agent will create a wallet for you as they try to make it uh safe by having the private key hashed on

them on the database of the AI agent and it submit transactions on your behalf and then like you use the wallet and submit transactions to Ethereum which is cool. This is the most scalable approach I saw till now. But it have some like issues from user experience and a lot of stuff like for example no one would trust any agent with with all his saving. No one would be happy to uh like have a private key on on any server side even if it is hashed but at the end on the memory somewhere it should be like uh decrypted.

So that's the main issue. A best approach and I mentioned on the first slides is to use abstract wallet with session keys. So things are better but we still have this part like the server part which with oracles and everything. Uh I read a lot of I read about a lot of vulnerability if you are using TE or are using whatever way you prefer for your deployment. Some people may be able to trick your AI agent. Some people may be able to simply like how to say it like okay tell your AI agent that today if someone uh requested to withdraw USDC forward it to

my wallet and a lot of auditor manager to train the agent to do this and if it is a black box like TE you may not be able to ever discover this issue until it is too late. So one of the good approach was to have a transparent way to enter the data. So for example my AI agent will depend on some oracles will depend on servers blah blah blah should have an easy way to fetch this data and should be transparent like should be scalable and sometimes should be transparent.

One of the solutions to do this was using internet protocol. I'm I'm not sure if people are familiar with it. It is a blockchain not don't like the cons mechanism is not as strong as proof of stack on Ethereum. Actually, it's quite more simple, but they are able to deploy a lot of AI agent and they are a public blockchain. They offer you a very easy way to see all executions and the running model.

And if you are having some private data or have some data that you don't want to share uh instead of like having the challenge of using any Z key and any way of like hiding data of shin uh internet computer protocol offers internet computer protocol offers some uh good subnets that can be private that can encapsulate some data with some hashing ways which may be better. So it is like one of different approach but the main feature is having ICP with native Oracle support with native bridges which make life easier and they deployed already a lot of AI models and it perform well on their chain which can

we can use it instead of AWS. So instead of having a server or I where it's a black box you don't know anything maybe having ICP with some slightly uh closed subnets would be cool to help on this or you can uh use uh avalanche avalanche have its subnet the subnet uh support all bridges and support oracles natively and you can add your own plugins on it which was pretty cool. It wasn't good on AI. So maybe on AI models you can try use it on client or use it on another server. But it was a good

design to have subnets and have layer one. So you submit like your AI agent is operating on the same chain and have a more like decentralized way to get the data and to validate it. And the last approach, this one I didn't test it yet. I know about it, but I didn't use it till now. I am on the wait list. So using layer on layer would be cool. I read the white paper. So it will depend on stacking and depend on token.

I don't think it would be strong for a lot of static data in my opinion because it isn't depending on like build on top on the top of proof of stack. So it should have some limitation like maybe the ICP would be stronger on this. Uh but like I will not be sure until I test it myself. Uh hopefully it will be live soon. Until now in my opinion this approach is like the most scalable one but like how to deploy your AI agent, how to deploy the model is still uh more or less challenging.

Okay. Then uh the tools for AI agent one of the things that was quite interesting was using uh um pretty simple equations like everyone is familiar with this equations. It's just the APY. You are calculating your APY reward and calculating your loss when using liquidity pool when using them as a tool even if your AI agent is already like trained to use them. Uh it is um like it is not so guaranteed that the context will not go away like you need to have the context restricted and using mass as tools was quite interesting on this part.

And it helped me a lot like to have all context more or less strict and safer on this part. The risk and challenges we have of course like as I said before tricking the AI agent the challenge UX I will manage it I will talk about it on the next slide and of course new product menu hack uh for example for the AI agent tools. uh when you have a lot of mass AI agents I feel the models become faster but a lot of AI expert I work with told me that's not true I don't know why yet but when I use logger or use monitoring it is clear that having mass equations make the models more or

less faster but I don't know why if someone knows that would be quite interesting but it really affect the context of the agent and make it much faster and uh I found some a lot of projects doing the same use case would like to share it with you. So, uh, Lumlai have a very, uh, interesting way for on boarding. Like on boarding is quite easy. You can import your private key or use your own. Same for AI models. Uh, Pearl was the most client side AI agent I found. You do everything on really on a desktop app.

Askina have the best resources for learning and blogs. Uh, hey Anon was pretty cool. uh as they offer manual way and automatic way to do everything. Hyper signals I am excited because it's on hyper native and call me post are two partners like interesting people but I couldn't test it yet. I am on the white list too. Mamu may be my favorite to be honest. It is for like for for saving like to have a lot of liquidity pool and have them on the saving side and it was quite good on rebalancing different pools and to have a lot of savings inside it and

that's all [Applause] any question. Hi, thanks for the talk and my question about the session keys. Uh who generating the session keys and which type of session keys you are generating if it's ECDSA or P256? Do you know? Uh so uh mainly mainly who generate uh the session key should be on the client side from the wallet uh like managed by the user.

uh which session key we are testing both each have some like uh pros and cons for example ECDA is much simpler but uh you know it uh may not get be like maybe expired and some issues on it so like the best approach is having it like what we did we did it uh like hybrid so it depend on the tool we decide what each session key will ask so if it is pretty expensive thing we prefer having ECD in now if not like we keep the other way.

I think that's all. Thank you very much. [Applause]