Allow unfunded orders with approval#4536
Conversation
|
Claude finished @fleupold's task in 3m 0s —— View job PR Review: Allow unfunded orders with approvalThe approach is sound. The new branch only relaxes the non- I left 3 inline comments (one minor logging suggestion + two doc/typo nits). Nothing blocking. One design question worth a sanity check (not posting inline):
Minor reuse note:
|
There was a problem hiding this comment.
Code Review
This pull request introduces an allowance method to the BalanceFetching trait and its implementations to retrieve a user's on-chain allowance. The OrderValidator is updated to accept zero-balance orders if they are backed by a sufficient pre-existing allowance, and corresponding tests are added. The reviewer suggests propagating RPC errors from the allowance call instead of swallowing them with unwrap_or(U256::ZERO), which could otherwise mask transient network issues as validation errors.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
|
@claude review again please |
|
Claude finished @fleupold's task in 2m 26s —— View job Re-review: Allow unfunded orders with approvalAll actionable feedback from the previous round has been addressed:
I re-verified the core logic:
Non-blocking observation (no change requested): the approval path requires The previously-raised scope question (this also relaxes market orders, not just limit orders) was already acknowledged in the prior thread, so I won't re-open it. LGTM. 👍 |
| buy_amount: alloy::primitives::U256::from(1), | ||
| sell_amount: alloy::primitives::U256::from(1), | ||
| fee_amount: alloy::primitives::U256::from(0), |
There was a problem hiding this comment.
| buy_amount: alloy::primitives::U256::from(1), | |
| sell_amount: alloy::primitives::U256::from(1), | |
| fee_amount: alloy::primitives::U256::from(0), | |
| buy_amount: U256::ONE, | |
| sell_amount: U256::ONE, | |
| fee_amount: U256::ZERO, |
| .returning(move |_, _| Err(create_error())); | ||
| balance_fetcher | ||
| .expect_allowance() | ||
| .returning(|_, _, _| Ok(alloy::primitives::U256::ZERO)); |
There was a problem hiding this comment.
| .returning(|_, _, _| Ok(alloy::primitives::U256::ZERO)); | |
| .returning(|_, _, _| Ok(U256::ZERO)); |
| .returning(|_, _| Err(TransferSimulationError::InsufficientBalance)); | ||
| balance_fetcher | ||
| .expect_allowance() | ||
| .returning(|_, _, _| Ok(alloy::primitives::U256::ZERO)); |
There was a problem hiding this comment.
| .returning(|_, _, _| Ok(alloy::primitives::U256::ZERO)); | |
| .returning(|_, _, _| Ok(U256::ZERO)); |
Description
There are use cases in which we want to allow limit order placement even if no funds are available yet. The existing logic requires the user to have at least 1 wei of balance. Reason for this is spam protection (funding a wallet requires a transaction and thus someone to spend gas). However, the same applies to setting an on-chain allowance.
This PR adds logic to allow completely unfunded accounts to place limit orders as long as they have set an onchain approval. Note that the cost of doing this is roughly equivalent to transferring 1 wei of token into an account (and then using a free permit pre-hook to set allowance, which would pass today's test). Therefore, I don't expect the spam surface to increase.
Changes
allowancemethod on the balance fetcherHow to test
Added unit test and adapted e2e test
Additional Context
Context: https://nomevlabs.slack.com/archives/C0A9GFVLLD6/p1781605451078769