AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Low 48 Monero

Refactor swap logic and state management (#3472)

Public commit record

What the developer wrote

Authored by malik1004x

100/100 · Strong
Refactor swap logic and state management (#3472)

* add unit tests for provider code

* fix provider issues uncovered by unit test

* readd providerName

* fix migration from hive

* delete unused widget

* remove ExchangeViewModel and ExchangeTradeViewModel. good riddance!

* remove dead providers from trade monitor

* adjust old ui that we still temporarily use

* add states for sending

* adjust confirm sheet and external modal

* adjust filter store

* remove dead import

* remove unreachable widget

* add SwapConfirmBottomWidget (bloc-based rather than mobx-based)

* add handler (wip)

* string

* WHY the FUCK was this EVER done here? TODO fix solana balances in a bit

* move swapsxyz registration to swapsxyz provider

* make everything final

* back by popular demand (2 calls), mergeFindTradeByIdResult. also, copyWith

* adjust mergeFindTradeByIdResult calls to new format

* remove old quick-fixes that will now be handled properly

* add safeParse to Money

* add di defs for the new classes

* fix currency fetching when balances are not loaded

* add(_Init()); (i forgor)

* add transformers to bloc

* properly fetch rates after actions

* add cubit to context because of course i forgot

* refactor rates cubit to load the rates async (sync took two business days)

* set source correctly in source selector modal

* do not display spinny loady thingie when it's not loading

* apparently we sent the wrong request to swaptrade and nobody noticed for years. that's why it worked like shit!

* minor integration fixes

* add nice toString to provider rate

* ugly ahh workaround because flutter is shit

* properly load rates on toggling providers

* don't show disabled providers in selector

* remove observers

* slight fixes to improve performance

* move SwapBloc to its own folder

* minor perf fixes

* add currency provider and allow switching currencies

* reset swap source if wallet doesn't support it

* readd refund address button

* fix setting fiat amount controller

* add button disable condition

* pop that sheet

* proper failure state

* stealthex extra id oopsie

* ()

* new db table

* add wallet switch

* add uri for external send

* transaction creation, i guess?

* adjust old ui to new state

* are glasses a valid company expense atp?

* actually display the error if tx creation throws

* up pubspec

* memo support

* add bloc_presentation

* add address validation and aliaspay support

* prevent going to unreachable widget in input state

* no ugly ahh blank field for trade id

* Transakcja Wysłana!

* proper provider during rate fetch

* show "no rates found" if no rates found

* save to TradesStore

* store provider settings

* don't store 1 = 0 rates

* small save/load fix

* fix trade tile

* fallback to different providers on fail

* change payoutAddress in TradeRequest to String

* fix exolix error message

* ln receive support

* remove unused methods

* fix zero bug

* stop cards from disappearing when state is gone

* reformat

* logs

* migration

* fix old trades not showing in history

* rate timer

* fix secrets parse

* remove print

* parse -> safeParse

* dispose properly

* state emit fix since this was made before i did more than 2 states

* account check that makes sense

* only allow proceeding if we have rates

* disable dragging down the confirm sheet (like on send)

* better input validation

* fix no_http_imports ci

* fix select all on centralized

* chainflip throw on status code

* actually pass the trocador provider name

* pass changenow amounts

* check script

* letsexchange String -> double

* changenow nullable fields + status code check

* trocador print body

* swaptrade rate is null check

* expand provider check to all providers

* [slop] new exchange provider check script

* fix many minor provider bugs

* fix near intents bug? i think? it doesn't fail anymore so...

* [slop] update test script

* trocador integration that actually works

* minor parse fixes

* fix text

* cleanup _onSwapInitiated because it was absurdly long

* add a way to disable forced provider if they don't have a rate

* spacing

* refactor TradeRequest to only hold Money instead of SwapAmount since only cryptoAmount was ever actually used

* swap all is back!

* persist swap all on changing currency (or drop it)

* add "ALL" text

* ci

* remove pubspec.lock because i think it fucked up ci?

* [revert this] pin bitcoin_base to commit hash

* restore low fee alert

* fix extremely embarassing swapsxyz bug

* findTradeById -> updateTrade

* move SwapAmountBox into separate file

* adjust to Money.toDouble no longer existing

* fix imports in swap

* adjust anypay to refactor

* remove double di registration

* minor fixes for the new widgets

* fixed rate fix

* adjust to money object improvements

* remove version

* remove dead import

* fix changenow payout addr

* fix csv export

* disable exolix

* fix letsexchange creation time

* fix confirm sheet overflow

* reset sources on direction reversal

* fix fiat amount decimals

* fix error color

* disable stealthex

* fix swaptrade

* restore guards for swap all and decentralized providers

* bugfixes

* add extra id to external modal

* block providers that don't support external send

* disable swap all for external send

* properly switch wallet

* fail on db save fail

* don't fail fetching all trades if one deserialize fails

* fix serialization

* make id the primary key instead of autoincrement

* readd providerName to db

* fix swapsxyz updates

* bugfixes

* hide address after swap

* add external refund addresses for internal swaps

* timeout for providers

* fix low fee alert if bloc is closed too fast

* fix

* fixes

* remove some unused stuff

* remove some unused stuff

* fix race

* fixes

* pass empty amount

* fix altvm

* fix swaptrade rate

* make jupiter executeswap use schemas properly

* fixes

* remove title param

* fixes

* fixes

* fixes

* get rid of the stupid if/elses

* move converter

* nicer provider apis

* fix jupiter, sigh

* fix swapsxyz, double sigh

* more fixes

* fix trocador providers

* fix

* fix

* fix exchange rate

* yup

* do fetchRate in a way that actually fucking makes sense

* get zec addrs

* for best results git add the fucking file

* more tests, i guess

* make :czarek: happy

* DAMNIT

* fixes

* finally fix trocador

* finally fix trocador... again

* fixes

* fix swapsxyz update

* fix pay anything

* fix tests

* format

* ughhhhhh fix the chain id

* remove dead code (this was dead since its addition and nobody noticed, lol)

* swaptrade fix. damnit

* add hardware wallet confirmation popup

* add hardware wallet confirmation popup... again

* sigh

* ci

* prevent trocador ratelimits

* fixes

* fixes and stuff

* yup

* cache

* tests ig

* make FiatAmountBar nicer :)

* sighhhh unspentcointype or sth i am so triggered by this little enum

* bitcoin accounts, kinda

* handle ln invoices and addresses in generic way

* rename

* rename

* nanogpt

* fixed rate? more like broken rate amirite

* fail on trade.save() error

* update overrides

* this really should be the default...

* swapsxyz decimals fix

* more decimals to make amounts parsing less likely to fail

* sigh.

* delete empty files

* imports

* fix

* this check didn't actually do anything

* overrides

* fix tests

* revert changes for pubspec

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Omar <omarh.ismail1@gmail.com>
✓ Descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference✓ Names security-relevant behavior explicitly
The short version

What changed, and why it matters

This is a very large code refactor of the cryptocurrency swap/exchange feature in Cake Wallet. It rewrites how exchange rates are fetched, how trades are created and tracked, and how trade history is stored in the local database. The commit also adds many unit tests and fixes numerous small bugs in individual exchange providers. While the changes touch security-sensitive areas (sending money, storing trade data, parsing amounts), the commit message and diff do not describe this as a security patch, and there is no explicit disclosure of a vulnerability. The biggest security-relevant change is a database migration that restructures how past trades are stored; a bug here could affect user records but is not shown to be exploitable by an attacker.

Recommended action

Treat this as a high-risk functional refactor rather than a confirmed security fix. Reviewers should focus on: (1) correctness of the SQLite trade migration and data loss potential; (2) accuracy of Money.safeParse and ExchangeRate.fromAmounts to prevent amount manipulation; (3) that each exchange provider still sends the intended API requests and validates responses; (4) that the new SwapBloc correctly gates external sends, refund addresses, and hardware-wallet confirmations; (5) that the CI change allowing http imports in tool/ and test/ does not weaken production code checks. Regression testing of swap creation, rate display, and trade history is strongly advised before release.

Security signals we found

01

Large-scale rewrite of trade creation, rate fetching, and status monitoring

02

Database schema migration for Trade table with data reconstruction from old columns

03

New amount parsing helper (Money.safeParse) and exchange-rate math (ExchangeRate.fromAmounts)

04

Multiple provider-specific fixes for request/response handling (swaptrade, swapsxyz, trocador, changenow, etc.)

05

Removal of old ExchangeViewModel/ExchangeTradeViewModel and replacement with SwapBloc/RateCubit

06

Changes to Thorchain address lookup and LNURL pay address provider logic

07

Addition of hardware wallet confirmation popup in swap flow

08

External send/refund address handling added for internal swaps

09

CI workflow change allowing http imports in tool/ and test/ directories

Risk score

Why this scored 48/100

Our methodology →
Potential impact 12/30
Exploitability 8/25
Stealth signal 6/15
Affected reach 14/15
Confidence 5/10
Evidence quality 3/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.