feat(balances): track delegations for Solana - #7903
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughSolana SPL token account loading now retrieves balances and delegations together, persists them in memory, exposes chain-specific allowances, resets allowance state on account changes, and renders delegation status in token table rows. EVM approval handling remains unchanged. ChangesSolana SPL account loading
Balance and delegation persistence
Chain-specific allowance access
Account reset and token presentation
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant TokenRow
participant useTokenAllowances
participant allowancesAtom
participant SPLPersistence
TokenRow->>useTokenAllowances: request allowance state
useTokenAllowances->>allowancesAtom: read Solana delegation
SPLPersistence->>allowancesAtom: write fetched delegation
allowancesAtom-->>TokenRow: return allowance
TokenRow->>TokenRow: render delegation status
Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
…/cowswap into feat/sol-delegation-tracking
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
libs/balances-and-allowances/src/hooks/usePersistSplViaMulticall.test.tsx (1)
98-103: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover delegation persistence, not only balances.
This helper exposes only
balancesAtom, while the mock guarantees no delegate match. Add a delegated account case that assertsallowancesAtomreceives the mint’s delegated amount; otherwiseapplySolanaAllowancescan regress unnoticed.🤖 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 `@libs/balances-and-allowances/src/hooks/usePersistSplViaMulticall.test.tsx` around lines 98 - 103, Extend the test helper and add a delegated-account test case for usePersistSplViaMulticall. Configure the mocked delegation to match the relevant mint, then assert that allowancesAtom contains the delegated amount after applySolanaAllowances runs, while preserving the existing balancesAtom assertions.apps/cowswap-frontend/src/legacy/components/Tokens/SplDelegationCell.tsx (1)
1-9: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse the explicit component/style file boundary.
Rename this presentational component to
SplDelegationCell.pure.tsx, move its label styling behindSplDelegationCell.styled.ts, and import it as a namespace. As per coding guidelines, “Put styles in*.styled.ts” and “Import styles asimport * as styledEl from './X.styled'.”🤖 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/legacy/components/Tokens/SplDelegationCell.tsx` around lines 1 - 9, Rename the presentational component file to SplDelegationCell.pure.tsx, move its label styling into SplDelegationCell.styled.ts, and update the component to import that module as the styledEl namespace. Replace the existing ApproveLabel import and references with the namespace-based styled element while preserving the component’s behavior.Source: Coding guidelines
🤖 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 `@libs/balances-and-allowances/src/services/readSolanaTokenAccounts.ts`:
- Around line 23-30: Remove the obsolete {`@link` fetchSolanaTokenBalances}
reference from the documentation above the reader and replace it with generic
wording describing downstream balance and delegation consumers, while preserving
the existing explanation about the single batched account read.
In `@libs/balances-and-allowances/src/state/allowancesAtom.ts`:
- Around line 49-52: Scope cached Solana delegations by wallet account to
prevent same-chain wallet switches from showing stale approvals. In
libs/balances-and-allowances/src/state/allowancesAtom.ts lines 49-52, add an
account dimension or ownership metadata; in
libs/balances-and-allowances/src/hooks/usePersistSplViaMulticall.ts lines
106-112, pass the current account and at lines 134-145 persist under its
normalized key or clear stale chain data; in
libs/balances-and-allowances/src/hooks/useTokenAllowances.ts lines 54-56, read
only the current account’s allowance map.
---
Nitpick comments:
In `@apps/cowswap-frontend/src/legacy/components/Tokens/SplDelegationCell.tsx`:
- Around line 1-9: Rename the presentational component file to
SplDelegationCell.pure.tsx, move its label styling into
SplDelegationCell.styled.ts, and update the component to import that module as
the styledEl namespace. Replace the existing ApproveLabel import and references
with the namespace-based styled element while preserving the component’s
behavior.
In `@libs/balances-and-allowances/src/hooks/usePersistSplViaMulticall.test.tsx`:
- Around line 98-103: Extend the test helper and add a delegated-account test
case for usePersistSplViaMulticall. Configure the mocked delegation to match the
relevant mint, then assert that allowancesAtom contains the delegated amount
after applySolanaAllowances runs, while preserving the existing balancesAtom
assertions.
🪄 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 Plus
Run ID: 6b318861-72a2-4412-a599-379c448dbd33
📒 Files selected for processing (14)
apps/cowswap-frontend/src/legacy/components/Tokens/SplDelegationCell.tsxapps/cowswap-frontend/src/legacy/components/Tokens/TokensTableRow.tsxapps/cowswap-frontend/src/locales/en-US.polibs/balances-and-allowances/src/const/solanaSettlement.tslibs/balances-and-allowances/src/hooks/usePersistBalancesViaWebCalls.test.tsxlibs/balances-and-allowances/src/hooks/usePersistBalancesViaWebCalls.tslibs/balances-and-allowances/src/hooks/usePersistSplViaMulticall.test.tsxlibs/balances-and-allowances/src/hooks/usePersistSplViaMulticall.tslibs/balances-and-allowances/src/hooks/useTokenAllowances.tslibs/balances-and-allowances/src/services/fetchSolanaTokenAccounts.test.tslibs/balances-and-allowances/src/services/fetchSolanaTokenAccounts.tslibs/balances-and-allowances/src/services/fetchSolanaTokenBalances.test.tslibs/balances-and-allowances/src/services/readSolanaTokenAccounts.tslibs/balances-and-allowances/src/state/allowancesAtom.ts
💤 Files with no reviewable changes (1)
- libs/balances-and-allowances/src/services/fetchSolanaTokenBalances.test.ts
…/cowswap into feat/sol-delegation-tracking
There was a problem hiding this comment.
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 `@libs/balances-and-allowances/src/updaters/BalancesResetUpdater.ts`:
- Around line 24-35: The account-change guard in the useEffect must use the
SDK’s areAddressesEqual for address comparison instead of prevAccount !==
account. Preserve the existing prevAccount check and explicitly handle
undefined/null values as supported by areAddressesEqual so equivalent EVM
addresses with different casing do not reset balances or allowances.
🪄 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 Plus
Run ID: 9f83008a-c112-4701-9820-274817176ef2
📒 Files selected for processing (2)
libs/balances-and-allowances/src/services/readSolanaTokenAccounts.tslibs/balances-and-allowances/src/updaters/BalancesResetUpdater.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- libs/balances-and-allowances/src/services/readSolanaTokenAccounts.ts
elena-zh
left a comment
There was a problem hiding this comment.
Hey @limitofzero , thank you, it works as described.
However, I'm not sure in tems on UI:
- A green dash is something new that we have never used before . If approval flow wirks defferently, and we don't need to trigger it from this page, then it would be nice simply to change a dash color to
Maybe @fairlighteth has other options to propose.
- I'd also not show this dash to a not connected user since it is a useless one.
For a EVM-chain we show 'approve' button that calls 'connect wallet' button, however, not sure if we need this action on Solana network
- Lastly: link to a token's details on Blockexplorer is missing for solana on this PR:
However, it is present on other chains
Could you please take a look at these issues?
Hey @elena-zh, thank you, addressed |
# Conflicts: # apps/cowswap-frontend/package.json # apps/explorer/package.json # bundle-size.jsonc # libs/events/package.json # libs/types/package.json # pnpm-lock.yaml
…/cowswap into feat/sol-delegation-tracking # Conflicts: # bundle-size.jsonc






Summary
Track and surface SPL token delegations for Solana on the account tokens page (
/#/account/tokens).A delegation is the Solana analogue of an EVM allowance: a token account approves the CoW settlement program (via its settlement-state PDA) to pull the sell funds at execution time. This PR fetches that delegation alongside the SPL balance in a single batched read and shows it in the token table's Actions column, mirroring how EVM approvals are displayed — read-only for now, since there is no manual Solana approve flow yet.
To Test
set solana flag enabled: localStorage.setItem('IS_SOLANA_ENABLED', '1')
Currently we don't have approve interface for SPL. But you can create a limit order via this demo with enabled solana flag(details) and after this you will see that the source token is approved
Summary by CodeRabbit
Summary