feat(indexer): tax-aware route/solve ranking for community tax CW20 #1131

Merged
PlasticDigits merged 2 commits from issue/615-tax-aware-route-ranking into main 2026-08-24 02:45:18 +00:00
PlasticDigits commented 2026-08-24 00:54:05 +00:00 (Migrated from gitlab.com)

Summary

  • Rank GET /api/v1/route/solve by catalog net_out, keep hop LCD/DB sims 1:1 (H-01 / T592-1).
  • Skip option-2 middle-hop TAX sells (extra-debit leftover would sit on the router). token_in tax first-hop stays eligible.
  • Swap/Trade You Receive is post-buy-split; submit still Sends declared and uses pre-tax min_return.
  • Unmigrated columbus-5 11611 hops stay Honest until COMMUNITY_TAX_OPTION2_CODE_IDS / COMMUNITY_TAX_OPTION2_DATA_HASHES.
  • New playbook skills/AGENTS_INDEXER_TAX_AWARE_ROUTING.md (R615-1–R615-8). make verify-issue-615.

Closes #615

Acceptance (#615)

  • Path rank uses net_out; hop LCD/DB sims unchanged.
  • Middle-hop TAX sell skipped when that token is not token_in (option-2 wasm only, env/code-id/hash pin).
  • token_in tax: same leftover on remaining paths; winner is max ask raw_out / net_out.
  • token_out tax: estimated_amount_out_net is buy-split; You Receive uses net; min_return stays pre-tax.
  • Manager-exempt trader → 0 bps; unknown/LCD fail-closed (keep catalog bps).
  • Hybrid GET cache key includes tax identity (in/out bps + router-hops-tax + exempt).
  • Unmigrated 11611 Honest hops until explicit COMMUNITY_TAX_OPTION2_* flip (documented in #607 playbook + R615-5).
  • make verify-issue-607 still green; new make verify-issue-615 (docs + indexer lib + frontend helpers, first pass + retest).
  • Skills + docs/route-solver.md + ADR 0002 amendment + docs/indexer-invariants.md + AGENTS.md cross-links.

Not in this MR

  • Option-2 classify/wasm (lives on feat/607-router-tax-option-2; do not merge that here). Ranking only.
  • Live columbus-5 / LocalTerra execute of UST1→TAX→USTR skip (unit-tested; needs option-2 wasm + env flip).
  • Catalog does not store data_hash; hash pin is env-only.
  • Pair/router FoT math, spoofable client buy_bps, and retail pool_only (#596).
  • Optional LCD TaxPreview on every hop (catalog snapshot + optional IsProtocolExempt only).

Follow-up

After CMM migrate / option-2 wasm: set COMMUNITY_TAX_OPTION2_CODE_IDS (e.g. 11611) or COMMUNITY_TAX_OPTION2_DATA_HASHES. Ranking then skips middle TAX hops. Wasm must actually tax hops — the env only changes ranking.

Test plan

  • make verify-issue-615 (includes verify-issue-607, indexer community_tax_rank / cache / merge_picks, frontend net helpers)
  • Reviewer: TAX→UST1 vs TAX→USTR→UST1 both eligible; pick higher raw
  • Reviewer: UST1→TAX You Receive net; execute still Sends declared
  • Reviewer: after option-2 flip, UST1→TAX→USTR skipped vs UST1→USTR
  • Reviewer: unmigrated 11611 still allows middle TAX hop
  • Reviewer: manager-exempt net_out == raw_out
  • Reviewer: cache isolation tax vs ordinary CW20
## Summary - Rank `GET /api/v1/route/solve` by catalog **`net_out`**, keep hop LCD/DB sims 1:1 (**H-01** / **T592-1**). - Skip option-2 **middle-hop TAX sells** (extra-debit leftover would sit on the router). `token_in` tax first-hop stays eligible. - Swap/Trade **You Receive** is post-buy-split; submit still Sends declared and uses **pre-tax** `min_return`. - Unmigrated columbus-5 **11611** hops stay Honest until `COMMUNITY_TAX_OPTION2_CODE_IDS` / `COMMUNITY_TAX_OPTION2_DATA_HASHES`. - New playbook [`skills/AGENTS_INDEXER_TAX_AWARE_ROUTING.md`](skills/AGENTS_INDEXER_TAX_AWARE_ROUTING.md) (**R615-1–R615-8**). `make verify-issue-615`. Closes #615 ## Acceptance (#615) - [x] Path rank uses `net_out`; hop LCD/DB sims unchanged. - [x] Middle-hop TAX sell skipped when that token is not `token_in` (**option-2 wasm only**, env/code-id/hash pin). - [x] `token_in` tax: same leftover on remaining paths; winner is max ask `raw_out` / `net_out`. - [x] `token_out` tax: `estimated_amount_out_net` is buy-split; You Receive uses net; `min_return` stays pre-tax. - [x] Manager-exempt `trader` → 0 bps; unknown/LCD fail-closed (keep catalog bps). - [x] Hybrid GET cache key includes tax identity (in/out bps + router-hops-tax + exempt). - [x] Unmigrated 11611 Honest hops until explicit `COMMUNITY_TAX_OPTION2_*` flip (documented in #607 playbook + R615-5). - [x] `make verify-issue-607` still green; new `make verify-issue-615` (docs + indexer lib + frontend helpers, first pass + retest). - [x] Skills + `docs/route-solver.md` + ADR 0002 amendment + `docs/indexer-invariants.md` + `AGENTS.md` cross-links. ## Not in this MR - Option-2 **classify/wasm** (lives on `feat/607-router-tax-option-2`; do not merge that here). Ranking only. - Live columbus-5 / LocalTerra execute of UST1→TAX→USTR skip (unit-tested; needs option-2 wasm + env flip). - Catalog does not store `data_hash`; hash pin is env-only. - Pair/router FoT math, spoofable client `buy_bps`, and retail `pool_only` (#596). - Optional LCD `TaxPreview` on every hop (catalog snapshot + optional `IsProtocolExempt` only). ## Follow-up After CMM migrate / option-2 wasm: set `COMMUNITY_TAX_OPTION2_CODE_IDS` (e.g. `11611`) or `COMMUNITY_TAX_OPTION2_DATA_HASHES`. Ranking then skips middle TAX hops. Wasm must actually tax hops — the env only changes ranking. ## Test plan - [x] `make verify-issue-615` (includes `verify-issue-607`, indexer `community_tax_rank` / cache / merge_picks, frontend net helpers) - [ ] Reviewer: TAX→UST1 vs TAX→USTR→UST1 both eligible; pick higher raw - [ ] Reviewer: UST1→TAX You Receive net; execute still Sends declared - [ ] Reviewer: after option-2 flip, UST1→TAX→USTR skipped vs UST1→USTR - [ ] Reviewer: unmigrated 11611 still allows middle TAX hop - [ ] Reviewer: manager-exempt `net_out == raw_out` - [ ] Reviewer: cache isolation tax vs ordinary CW20
PlasticDigits commented 2026-08-24 00:54:14 +00:00 (Migrated from gitlab.com)

mentioned in issue #615

mentioned in issue #615
PlasticDigits commented 2026-08-24 02:45:17 +00:00 (Migrated from gitlab.com)

added 8 commits

  • 17ee753b...77d57d20 - 7 commits from branch main
  • 574793b4 - Merge origin/main into issue/615-tax-aware-route-ranking

Compare with previous version

added 8 commits <ul><li>17ee753b...77d57d20 - 7 commits from branch <code>main</code></li><li>574793b4 - Merge origin/main into issue/615-tax-aware-route-ranking</li></ul> [Compare with previous version](/PlasticDigits/cl8y-dex-terraclassic/-/merge_requests/413/diffs?diff_id=1978579726&start_sha=17ee753b692eb3407d142b2254ecea796ea92f5a)
PlasticDigits commented 2026-08-24 02:45:18 +00:00 (Migrated from gitlab.com)

mentioned in commit 2d9b573b6f

mentioned in commit 2d9b573b6fa8a2f34af1e778cb9e235f3e3bf9cc
PlasticDigits (Migrated from gitlab.com) merged commit 2d9b573b6f into main 2026-08-24 02:45:18 +00:00
PlasticDigits commented 2026-08-24 03:01:16 +00:00 (Migrated from gitlab.com)

mentioned in issue #616

mentioned in issue #616
PlasticDigits commented 2026-08-24 03:01:57 +00:00 (Migrated from gitlab.com)

mentioned in issue #611

mentioned in issue #611
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
code/cl8y-dex-terraclassic!1131
No description provided.