Skip to content

Revert "fix: Fixes allowances issue with limit orders"#7656

Open
Danziger wants to merge 1 commit into
developfrom
revert-7614-fix/limit-allowances
Open

Revert "fix: Fixes allowances issue with limit orders"#7656
Danziger wants to merge 1 commit into
developfrom
revert-7614-fix/limit-allowances

Conversation

@Danziger

@Danziger Danziger commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

This reverts commit be0d4c7.

Summary

Switch back to the old behaviour where only 0.05% of the original sell amount is needed in order to not trigger the inssuficient allowance warning.

To Test

  1. Create a limit order.
  2. Revoke its allowance.
  3. Verify the allowance warning appears.
  4. Approve 0.05% of the sell token.
  5. Verify the allowance warning disappears.

Background

Slack conversation: https://nomevlabs.slack.com/archives/C0361CDG8GP/p1781601276928229

Summary by CodeRabbit

  • Refactor

    • Simplified internal order validation logic for balance and allowance calculations by removing legacy remainder-based computations.
  • Tests

    • Streamlined test coverage for order parameter validation to focus on critical threshold scenarios.

@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sdk-tools Ready Ready Preview Jun 16, 2026 4:33pm
storybook Ready Ready Preview Jun 16, 2026 4:33pm
widget-configurator Ready Ready Preview Jun 16, 2026 4:33pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
cosmos Ignored Ignored Jun 16, 2026 4:33pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

getOrderParams drops the getRemainderAmountsWithoutSurplus dependency and removes sellAmountRemaining from the _hasEnoughBalanceAndAllowance helper. Both balance and allowance sufficiency now derive from sellAmount (scaled by PERCENTAGE_FOR_PARTIAL_FILLS for partially fillable orders). Tests are trimmed to match the simplified threshold logic and use lowercased token addresses as map keys.

Changes

Allowance/Balance Sufficiency Simplification

Layer / File(s) Summary
Core logic: remove remainder path, unify sellAmount threshold
apps/cowswap-frontend/src/modules/ordersTable/utils/getOrderParams.ts
Removes getRemainderAmountsWithoutSurplus import and sellAmountRemaining parameter. _hasEnoughBalanceAndAllowance now computes both hasEnoughBalance and hasEnoughAllowance from a single amount derived from sellAmount (scaled by PERCENTAGE_FOR_PARTIAL_FILLS for partially fillable orders). getOrderParams calls getBiggerAmount directly for allowance selection before the first fill.
Test update: threshold-based assertions, lowercased address keys
apps/cowswap-frontend/src/modules/ordersTable/utils/getOrderParams.test.ts
Removes unused helpers and getAddressKey import; rebuilds BASE_BALANCES_AND_ALLOWANCES with lowercased token addresses; replaces prior multi-scenario partially-fillable allowance tests with two threshold-based cases (>0.05% and <0.05% of sellAmount).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • cowprotocol/cowswap#7614: Directly modifies the same getOrderParams.ts / _hasEnoughBalanceAndAllowance function and getOrderParams.test.ts, targeting the same allowance-vs-remaining/sell-amount sufficiency logic for partially-fillable orders.

Suggested reviewers

  • fairlighteth

Poem

🐇 Hoppity-skip, the remainder's gone,
No surplus subtracted from dusk until dawn.
sellAmount alone sets the bar now, hooray —
One threshold for balance and allowance today!
The tests shed their weight like a rabbit in spring,
Simplicity rules — what a glorious thing! 🌸

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: reverting a previous fix to restore original allowance behavior for limit orders.
Description check ✅ Passed The description includes all required template sections: Summary with context, To Test with clear verification steps, and Background with Slack reference.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch revert-7614-fix/limit-allowances

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying swap-dev with  Cloudflare Pages  Cloudflare Pages

Latest commit: 530a006
Status: ✅  Deploy successful!
Preview URL: https://65ff2def.swap-dev-5u6.pages.dev
Branch Preview URL: https://revert-7614-fix-limit-allowa.swap-dev-5u6.pages.dev

View logs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/cowswap-frontend/src/modules/ordersTable/utils/getOrderParams.test.ts`:
- Around line 13-16: In the getOrderParams.test.ts file, replace all direct uses
of `.toLowerCase()` on address properties with the `getAddressKey()` function
from `@cowprotocol/cow-sdk` to maintain consistency with production code.
Specifically, update all occurrences where
`BASE_ORDER.inputToken.address.toLowerCase()` is used as a key in map objects
(such as in the balances and allowances objects) to instead use
`getAddressKey(BASE_ORDER.inputToken.address)`. Make sure to import
`getAddressKey` if it is not already imported, and apply this pattern
consistently throughout the test file wherever addresses are used as object
keys.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1ecece6f-9e54-4e21-9532-8172b071ee11

📥 Commits

Reviewing files that changed from the base of the PR and between af26cda and 530a006.

📒 Files selected for processing (2)
  • apps/cowswap-frontend/src/modules/ordersTable/utils/getOrderParams.test.ts
  • apps/cowswap-frontend/src/modules/ordersTable/utils/getOrderParams.ts

Comment on lines +13 to +16
[BASE_ORDER.inputToken.address.toLowerCase()]: BigInt(BASE_ORDER.sellAmount),
},
allowances: {
[getAddressKey(BASE_ORDER.inputToken.address)]: BigInt(BASE_ORDER.sellAmount),
[BASE_ORDER.inputToken.address.toLowerCase()]: BigInt(BASE_ORDER.sellAmount),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use getAddressKey instead of toLowerCase() for address keys.

The test creates map keys with .toLowerCase() while the production code uses getAddressKey() for lookups. This violates the coding guideline and creates implicit coupling to getAddressKey's implementation details.

Proposed fix
+import { getAddressKey } from '`@cowprotocol/cow-sdk`'
 import { BalancesAndAllowances } from '`@cowprotocol/balances-and-allowances`'

 import { getOrderParams } from './getOrderParams'

Then replace all occurrences of inputToken.address.toLowerCase() with getAddressKey(inputToken.address):

   const BASE_BALANCES_AND_ALLOWANCES: BalancesAndAllowances = {
     balances: {
-      [BASE_ORDER.inputToken.address.toLowerCase()]: BigInt(BASE_ORDER.sellAmount),
+      [getAddressKey(BASE_ORDER.inputToken.address)]: BigInt(BASE_ORDER.sellAmount),
     },
     allowances: {
-      [BASE_ORDER.inputToken.address.toLowerCase()]: BigInt(BASE_ORDER.sellAmount),
+      [getAddressKey(BASE_ORDER.inputToken.address)]: BigInt(BASE_ORDER.sellAmount),
     },

Apply the same pattern to lines 70, 81, 93, and 104.

As per coding guidelines: "MUST NOT normalize addresses with address.toLowerCase(); use getAddressKey from @cowprotocol/cow-sdk"

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
[BASE_ORDER.inputToken.address.toLowerCase()]: BigInt(BASE_ORDER.sellAmount),
},
allowances: {
[getAddressKey(BASE_ORDER.inputToken.address)]: BigInt(BASE_ORDER.sellAmount),
[BASE_ORDER.inputToken.address.toLowerCase()]: BigInt(BASE_ORDER.sellAmount),
[getAddressKey(BASE_ORDER.inputToken.address)]: BigInt(BASE_ORDER.sellAmount),
},
allowances: {
[getAddressKey(BASE_ORDER.inputToken.address)]: BigInt(BASE_ORDER.sellAmount),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/cowswap-frontend/src/modules/ordersTable/utils/getOrderParams.test.ts`
around lines 13 - 16, In the getOrderParams.test.ts file, replace all direct
uses of `.toLowerCase()` on address properties with the `getAddressKey()`
function from `@cowprotocol/cow-sdk` to maintain consistency with production code.
Specifically, update all occurrences where
`BASE_ORDER.inputToken.address.toLowerCase()` is used as a key in map objects
(such as in the balances and allowances objects) to instead use
`getAddressKey(BASE_ORDER.inputToken.address)`. Make sure to import
`getAddressKey` if it is not already imported, and apply this pattern
consistently throughout the test file wherever addresses are used as object
keys.

Source: Coding guidelines

@elena-zh elena-zh requested a review from a team June 17, 2026 08:53
@elena-zh elena-zh self-assigned this Jun 17, 2026

@elena-zh elena-zh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants