Skip to content

fix(revolut): keep stock tickers like META out of crypto and stop dropping dividends and splits - #371

Merged
GeiserX merged 5 commits into
mainfrom
fix/audit-p32
Sep 30, 2026
Merged

GeiserX merged 5 commits into
mainfrom
fix/audit-p32

Conversation

@GeiserX

@GeiserX GeiserX commented Sep 30, 2026 •

Copy link
Copy Markdown
Owner

Problem

A Revolut user who traded META got it treated as a crypto-asset. So did U (Unity), S, W, M, H, BILL, AMP, TEL, BIO, IP, VVV, BEAM, MET, GT, LIT and CASH. All of them are also coin symbols in the CoinGecko list the parser uses to spot crypto. The sale went to the "otros elementos" block (1633/1637) instead of listed shares (0328/0331). An open position counted for Modelo 721 and dropped out of 720 and D-6.

The transaction log also lost two kinds of row without a word. A DIVIDEND row has an empty Quantity and a STOCK SPLIT row has a zero amount. The parser skipped every row with no quantity before it looked at the type, and it only warned about unknown rows that had an amount. So dividends never reached 0029. After a split, the later sale found only the pre-split shares, raised "lotes insuficientes" and booked the rest at zero cost, which overstates the gain.

Fix

  • The 17 tickers go into STOCK_TICKER_CONFLICTS in scripts/update-crypto-symbols.ts, and I took them out of src/parsers/crypto-symbols.ts. I removed them by hand from the existing snapshot rather than refetching CoinGecko, so this diff doesn't also churn the rest of the list. The next run of the script gives the same result. BTC, ETH and the other real coins are still CRYPTO.
  • A DIVIDEND row becomes a Dividends cash transaction. Revolut reports it net of withholding with no separate withholding row, so an info message tells the user to take the gross amount and the tax withheld from Revolut's annual tax report for 0029 and 0588.
  • A STOCK SPLIT row becomes an FS or RS corporate action that carries the shares added (negative for a reverse split). The parser does not size the ratio. Yearly exports are parsed one file at a time and then merged, so one file's holding can be only part of the position. The FIFO engine sizes it at the split date from the lots it holds for that symbol across every file: (held + added) / held. It then rescales the lots and each lot keeps its full cost (Art. 37.1.a LIRPF). If it holds nothing, the split is not applied and fifo.split_unresolved warns, in all five locales. A row with no quantity at all gets the parser's revolut.split_unresolved warning.
  • wash-sale.ts uses the ratio FIFO applied, so the anti-churning cap and the deferred-loss release compare shares in the same units after the split.
  • FIFO keyed splits by ISIN only, and Revolut has no ISINs. A split without an ISIN now applies to the symbol-keyed lots, the same key wash-sale.ts uses. Actions that carry an ISIN or a "SPLIT n FOR d" ratio work as before.
  • Any other ticker row (spin-off, stock merger) counts toward the unknown-type warning, even when its amount is zero. The exception is Revolut's own entity-transfer rows ("TRANSFER FROM REVOLUT ... TO REVOLUT ..."): the holding doesn't change, so they are skipped without a warning.

Regression tests

The new tests are in tests/parsers/revolut.test.ts. Run against main, 27 of the 114 fail:

× classifies META as STK in the transaction log   (and the 16 other tickers)
× puts META and U disposals in the listed-shares block (0328/0331)
× turns a DIVIDEND row into a Dividends cash transaction and says it is net
× turns a STOCK SPLIT row into a split, so the later sale finds all its shares
× applies a reverse split given as a negative quantity
× sizes a split from every merged file, not only the file that has the split row
× applies a split before a buy on the split date, which is already in post-split shares
× measures the anti-churning cap in post-split shares with the ratio FIFO applied
× warns when the engine holds no shares to size a split from
× warns when a STOCK SPLIT row has no quantity
× counts any other ticker row it cannot handle, even with a zero amount
      Tests  27 failed | 87 passed (114)

Two yearly files show why the parser can't size the split. The 2023 file buys 5 NVDA for USD 2000. The 2024 file buys 1 for USD 700, then has STOCK SPLIT +54 and SELL 60. Sizing from the 2024 file alone gave 55-for-1 and a cost of 436.36 with no warning. Now the engine sizes it from the lots of both files: 10-for-1, cost 2700. The first version of this branch failed five of the new tests:

× sizes a split from every merged file, not only the file that has the split row
  AssertionError: expected '55:1' to be '10:1'
× applies a split before a buy on the split date, which is already in post-split shares
  AssertionError: expected [...] to not include 'fifo.insufficient_lots'
× warns when the engine holds no shares to size a split from
× skips Revolut's own entity-transfer rows quietly
      Tests  5 failed | 109 passed (114)

All 114 pass now. One test covers the anti-churning cap across a split: 10 bought in January, 1 in February, a 10-for-1 split, then a loss sale of 100. It defers 50 of the 500 loss. If I stop passing FIFO's ratios to detectWashSales, it fails with expected '0.00' to be '50.00'.

Also run: the FIFO, corporate-action, wash-sale, report, merge and i18n test files (337 tests pass), tsc --noEmit and eslint on the changed files.

…pping dividends and splits

META, U, S, W, M, BILL and eleven other US tickers were also in the
CoinGecko coin list, so a Revolut stock trade in them was classed CRYPTO:
the sale went to the "otros elementos" block instead of listed shares,
and the holding counted for Modelo 721 instead of 720/D-6. They are now
in the generator's stock-ticker conflict list and out of the generated set.

In the transaction log, DIVIDEND rows (empty quantity) and STOCK SPLIT
rows (zero amount) were skipped before any type check, with no warning.
Dividends now become Dividends cash rows with a note that Revolut reports
them net. A split becomes an FS/RS corporate action sized from the
holding built up in the file, and the FIFO engine now applies an
ISIN-less split to the symbol-keyed lots, as wash-sale already did. Any
other ticker row is counted in the unknown-type warning whatever its amount.
@coderabbitai

coderabbitai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 46 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository: GeiserX/DeclaRenta/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 2fbb5230-1b54-441b-b46f-003120155074

📥 Commits

Reviewing files that changed from the base of the PR and between 68b9719 and cf17b43.

📒 Files selected for processing (12)
  • scripts/update-crypto-symbols.ts
  • src/engine/fifo.ts
  • src/engine/wash-sale.ts
  • src/generators/report.ts
  • src/i18n/locales/ca.ts
  • src/i18n/locales/en.ts
  • src/i18n/locales/es.ts
  • src/i18n/locales/eu.ts
  • src/i18n/locales/gl.ts
  • src/parsers/crypto-symbols.ts
  • src/parsers/revolut.ts
  • tests/parsers/revolut.test.ts
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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.

@codecov

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.80220% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.55%. Comparing base (8162330) to head (cf17b43).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/engine/fifo.ts 95.45% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #371      +/-   ##
==========================================
+ Coverage   92.40%   92.55%   +0.15%     
==========================================
  Files          56       56              
  Lines        6409     6502      +93     
  Branches     2168     2205      +37     
==========================================
+ Hits         5922     6018      +96     
+ Misses        407      406       -1     
+ Partials       80       78       -2     
Files with missing lines Coverage Δ
src/engine/wash-sale.ts 97.81% <100.00%> (+0.45%) ⬆️
src/generators/report.ts 96.31% <100.00%> (ø)
src/i18n/locales/ca.ts 100.00% <ø> (ø)
src/i18n/locales/en.ts 100.00% <ø> (ø)
src/i18n/locales/es.ts 100.00% <ø> (ø)
src/i18n/locales/eu.ts 100.00% <ø> (ø)
src/i18n/locales/gl.ts 100.00% <ø> (ø)
src/parsers/crypto-symbols.ts 100.00% <ø> (ø)
src/parsers/revolut.ts 97.68% <100.00%> (+2.05%) ⬆️
src/engine/fifo.ts 96.07% <95.45%> (-0.10%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

A Revolut STOCK SPLIT row gives only the shares added. The parser sized the
ratio from the holding inside its own file, but yearly exports are parsed
one by one and merged, and FIFO then applied that ratio to every lot of the
symbol. With 5 shares bought in the 2023 file and 1 in the 2024 file, +54
became 55-for-1 instead of 10-for-1 and a sale of 60 was costed at 436.36
instead of 2700, with no warning.

The parser now carries the signed quantity on the corporate action. The FIFO
engine sizes the ratio at split time from the lots it holds under that key,
(held + added) / held, across all merged files, and warns
(fifo.split_unresolved) when it holds nothing. wash-sale.ts takes the ratio
FIFO applied, so the anti-churning cap stays in the same share units.
Revolut's own entity-transfer rows are skipped quietly.
@GeiserX
GeiserX merged commit cf32237 into main Sep 30, 2026
6 checks passed
@GeiserX
GeiserX deleted the fix/audit-p32 branch September 30, 2026 17:38
GeiserX added a commit that referenced this pull request Nov 19, 2026
…t of crypto so they keep their pre-sale anti-churning block

CVX, STX, ADI, BDX and CFG are S&P 500 tickers that are also CoinGecko coin
symbols, so a Revolut row in them was typed CRYPTO. With crypto now on the
art. 33.5.e window (only the year after the sale), a held buy before a loss
sale no longer blocked the loss of these listed shares, which letter f
covers (2 months before or after). They join the generator's stock-ticker
conflict list and leave the generated set, as META and the others did in
#371.
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