Skip to content

fix(swap): route Paraswap collateral swaps through the adapter#3012

Closed
mgrabina wants to merge 1 commit into
mainfrom
worktree/dreamy-galileo-abcdff
Closed

fix(swap): route Paraswap collateral swaps through the adapter#3012
mgrabina wants to merge 1 commit into
mainfrom
worktree/dreamy-galileo-abcdff

Conversation

@mgrabina

@mgrabina mgrabina commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

General Changes

  • Fixes Paraswap collateral swaps failing on Sonic — Source Decimals Mismatch (swap out of USDC) and Price impact too high / ESTIMATED_LOSS_GREATER_THAN_MAX_IMPACT (swap into USDC).

Developer Notes

Root cause. The Swaps refactor (#2739) changed non-flashloan collateral swaps to render the plain SwapActionsViaParaswap path, which swaps the aTokens directly through Paraswap. That depends on Paraswap pricing the aTokens correctly, which it doesn't on every chain. On Sonic, Paraswap has wrong metadata for aUSDC — it reports srcDecimals/destDecimals: 18 (aUSDC is 6) and values it at $0:

aToken  aWS  -> aUSDC : destDecimals 18 (WRONG), destUSD $0.00  -> ESTIMATED_LOSS_GREATER_THAN_MAX_IMPACT (quote rejected)
aToken  aUSDC-> aWS   : srcDecimals  18 (WRONG), srcUSD  $0.00  -> buildTx -> Source Decimals Mismatch
underlying wS -> USDC : destDecimals  6 (right),  destUSD $0.46  -> OK
underlying USDC-> wS  : srcDecimals   6 (right),  srcUSD  $0.10  -> OK

So both directions break on Sonic, at different stages (quote vs build), and neither is fixable client-side — Paraswap mis-values the aToken server-side.

Fix — restore the pre-refactor behavior. Before #2739, Paraswap collateral swaps quoted and built on the underlying tokens and executed via the collateral-swap adapter with flash toggled by health factor (pool.swapCollateral({ flash }); flash: false = swapAndDeposit). This change restores that:

  1. useSwapQuote — quote Paraswap collateral on the underlying tokens (exclude CollateralSwap from the Paraswap usesAddressToSwap branch), which Paraswap prices correctly.
  2. CollateralSwapActions — Paraswap collateral always renders CollateralSwapActionsViaParaswapAdapters (the adapter operates on underlying), instead of the direct-aToken SwapActionsViaParaswap.
  3. CollateralSwapActionsViaParaswapAdaptersuseFlashLoan: state.useFlashloan ?? false (was hardcoded true), so a healthy HF runs swapAndDeposit (no flashloan) and a low HF flashloans — exactly the old behavior. useFlowSelector already computes useFlashloan from the HF impact.

Scope / safety:

  • The non-flashloan path is preserved (it's swapAndDeposit via the adapter, not a flashloan), so no new flashloan fee for healthy positions.
  • CoW collateral swaps are untouched (CoW prices/trades aTokens fine).
  • SwapActionsViaParaswap is unchanged and still used for plain Swap.
  • Earlier revisions of this PR (force-flashloan; then sourcing buildTx decimals from the route) were dropped — the first removed the cheaper non-flashloan path, the second only fixed one direction's build and couldn't fix the quote-stage rejection.

@vercel

vercel Bot commented Jun 8, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
interface Ready Ready Preview, Comment Jun 11, 2026 7:54pm

Request Review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f12961556b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/components/transactions/Swap/hooks/useSwapQuote.ts
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

📦 Next.js Bundle Analysis for aave-ui

This analysis was generated by the Next.js Bundle Analysis action. 🤖

🎉 Global Bundle Size Decreased

Page Size (compressed)
global 1.25 MB (-32 B)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

One Page Changed Size

The following page changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/history 36.34 KB (🟡 +6 B) 1.29 MB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

@mgrabina mgrabina force-pushed the worktree/dreamy-galileo-abcdff branch from f129615 to e503750 Compare June 8, 2026 21:39
@mgrabina mgrabina changed the title fix(swap): quote Paraswap collateral swaps on underlying tokens fix(swap): force flashloan flow for Paraswap collateral swaps Jun 8, 2026
@mgrabina

mgrabina commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

@codex

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e503750296

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/components/transactions/Swap/hooks/useFlowSelector.ts Outdated
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

📦 Next.js Bundle Analysis for aave-ui

This analysis was generated by the Next.js Bundle Analysis action. 🤖

🎉 Global Bundle Size Decreased

Page Size (compressed)
global 1.25 MB (-31 B)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

@mgrabina mgrabina force-pushed the worktree/dreamy-galileo-abcdff branch from e503750 to 0f02a38 Compare June 11, 2026 18:22
@mgrabina mgrabina changed the title fix(swap): force flashloan flow for Paraswap collateral swaps fix(swap): build Paraswap tx with the priceRoute decimals Jun 11, 2026
@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

📦 Next.js Bundle Analysis for aave-ui

This analysis was generated by the Next.js Bundle Analysis action. 🤖

⚠️ Global Bundle Size Increased

Page Size (compressed)
global 1.25 MB (🟡 +1 B)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

Non-flashloan Paraswap collateral swaps were sent to the plain
SwapActionsViaParaswap path, which swaps the aTokens directly. That depends on
Paraswap pricing the aTokens, which it doesn't do correctly on every chain: on
Sonic it reports aUSDC as 18 decimals and values it at $0, so the quote is
rejected (ESTIMATED_LOSS_GREATER_THAN_MAX_IMPACT) or the build fails (Source
Decimals Mismatch).

Restore the pre-refactor behavior: Paraswap collateral swaps always go through
the collateral-swap adapter, which operates on the underlying tokens. It runs
swapAndDeposit (no flashloan) or a flashloan depending on the health-factor
impact, as before. The quote uses the underlying tokens too, which Paraswap
prices correctly.
@mgrabina mgrabina force-pushed the worktree/dreamy-galileo-abcdff branch from 0f02a38 to 6acb5e1 Compare June 11, 2026 19:49
@mgrabina mgrabina changed the title fix(swap): build Paraswap tx with the priceRoute decimals fix(swap): route Paraswap collateral swaps through the adapter Jun 11, 2026
@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

📦 Next.js Bundle Analysis for aave-ui

This analysis was generated by the Next.js Bundle Analysis action. 🤖

🎉 Global Bundle Size Decreased

Page Size (compressed)
global 1.25 MB (-32 B)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

One Page Changed Size

The following page changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/history 36.34 KB (🟡 +6 B) 1.29 MB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

@mgrabina mgrabina closed this Jun 11, 2026
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.

1 participant