Everything you need to know about on-chain limit orders
How do on-chain limit orders actually work? Today, we take you through the nitty-gritty of their on-chain execution and answer some of the most common questions about limit orders at DeFi Saver.
We first introduced limit orders about five years ago, when we noticed a growing interest in bringing one of the most familiar trading tools from traditional markets to DeFi. Today, we’re happy to pass $9M in executed limit order volume across Mainnet and our supported L2s.
And lately, we’ve been taking inspiration from some of the most common questions we get on Discord, which led us to put together a series of in-depth articles exploring why we built some of DeFi Saver’s features in the first place.
We’ll dive into the context and history behind each one, share a few fun facts along the way, and, most importantly, explain how the feature works and answer some of the most common questions you might have when using it through DFS.
Sounds like a lot to cover? Let’s get into it.
Understanding limit orders
You do not have to have dabbled in traditional equities to know trading in any market ultimately comes down to the same basic idea of giving structured instructions to a market venue on how and when you want to trade.
Limit orders are part of a broader family of order types, traditionally divided into four main categories: Market, Limit, Stop Loss, and Stop Buy orders.
Market Orders are an instruction to buy or sell an asset immediately at the best available price.
Limit Orders, on the other hand, enable buying or selling an asset only at a specified price or better.
Stop Loss ultimately becomes a market order once an asset reaches a specified trigger price, typically used to limit potential losses.
Finally, Stop Buy orders also become market orders once an asset reaches a specified trigger price, typically used to enter a position once the market moves above a certain level
However, traditional markets have historically had their series of limitations. They have set trading hours, meaning the venues close overnight and on weekends. Orders can remain queued until markets reopen, and in volatile conditions, execution can lag behind price movements.
And unlike DeFi, you rely on centralized brokers and market makers to route and execute orders.
To top it off, before electronic trading took over, these instructions were handled in those famed open-outcry trading pits, where traders shouted orders and used hand signals to communicate whether they wanted to buy or sell.
And if you have ever watched Trading Places, this might ring a bell.
DeFi definitely has some of these assumptions.
There are no traditional market hours, no broker sitting between you and the protocol, and execution can be automated directly on-chain.
On-chain limit orders, however, do not come without their own set of challenges.
Now, let’s go over all the pros and cons that accompany them (as well as the ways we, at DFS, work around them).
How on-chain limit orders work
A limit order goes through a few checks before the swap is actually executed. So, when you create an order, you tell DeFi Saver what you want to happen under specific conditions.
For example:
If the price hits $78,000, swap this much of Token A for Token B.
Our backend then monitors the relevant price and checks the condition every few seconds. Once it detects that the condition has been met, it prepares and submits the transaction.
But that is not the final check.

When the tx reaches the smart contract, the conditions are checked again on-chain. If the price moves too quickly (in extremely volatile periods) and no longer meets the required condition by the time the tx is processed, it will ultimately revert.
Moreover, these orders are part of our DFS Automation toolkit. That means a limit order lets you set the price at which you want a swap to execute, while our backend takes care of monitoring the market and preparing the tx.
Once you set your metrics and sign the tx, that's it. Our backend monitors the order and handles the execution when the conditions are met.

Helpful note: This also means that you are not the one executing the swap when the order triggers; our backend is. So, changing your wallet's RPC or using a MEV-protected RPC when setting up the order will not determine how the eventual limit order tx is submitted. All DFS Automation tools have their own MEV protection in place.
MEV protection can still be useful for other swaps where your wallet is directly submitting the transaction.
What happens when the price is triggered
This is where some of the confusion around limit orders came from.
On-chain limit orders need a certain amount of room between the point where an order is detected and the point where its tx is actually executed. Previously, at DeFi Saver, that buffer was 1%.
For example, if you set an order to buy WETH at $2,500, the system could previously require the relevant quote to reach approximately $2,475 before triggering the order.
We have since reduced that buffer from 1% to 0.15% to bring the execution threshold closer to your target. The available swap quote still needs to be slightly better than your target before execution is attempted, so it can leave room for small price movements while the transaction is being prepared and submitted.
Important note: This does not change your limit price, but it means reaching that price alone does not guarantee immediate execution.
But why is there a buffer in the first place?
Great, and completely understandable question.
The reason is the aforementioned small amount of price movement that has to be accounted for while a transaction is being prepared and sent on-chain. It is not intended to change your limit or make the final swap execute at a worse price.
What happens if I don't have enough tokens when my limit order triggers?
The wallet needs to have enough of the token being sold when the order is executed. If the required balance is not available when the limit order triggers, the tx will revert.
However, the order itself does not necessarily disappear. If the required funds return to the wallet before the order expires, and the is still met, the order can execute.
Can I cancel a limit order after creating it?
Of course. An active limit order can be canceled as long as it has not already been executed.
Can the limit order partially fill?
Nope. Either the order fills completely, or not at all. The order will never split.
We hope this clears up some of the confusion around limit orders. If you enjoyed the read and would like to see more pieces like this in the future, let us know. The writer of this piece is, after all, always hungry for compliments.
Until the next post, stay safe out there!🫡
Stay connected:
📢: Official Twitter/X