fix(swap): fund routed token taxes from gross budgets #1383

Merged
PlasticDigits merged 3 commits from fix/1381-route-local-tax into main 2026-10-04 11:06:36 +00:00
Owner

CL8Y→ALPHA→UST1→USTR could quote successfully while requiring a separate ALPHA wallet balance to fund a middle-hop tax. Funding protocol v1 collects configured taxes from each route's own gross budgets, delivers the exact economic input declared to each pair, and quotes the executable net result. Traders fund the offered asset and network fees only.

Refs #1381. Production rollout/live acceptance remains pending AC9.

Implementation

  • Token/router 1.2.0: authenticated gross/economic/net tax funding, once-per-boundary buys, owned residue, dust isolation, atomic settlement and preserved trader controls. Explicit v1 entry prevents mixed-version wallet-debit fallback.
  • Independent trusted trading capability discovery; supported intermediates absent from the Create catalog remain eligible. Funded GET/POST/manual hybrid/exact-output ranking, stable progress identity and exact gross cache keys.
  • Swap/Trade/invoice/native budgets and preflight align with execution. Failed config/balance/exemption refreshes retain protection; manual and invoice hybrid plans use funded amounts. V1 measured gas fallback is 600k + 1.7M per hop with existing book/native overhead; auto simulation stays 1.2×.
  • Updated invariants, legacy compatibility playbooks, verifiers, coordinated migration instructions, and synthetic public receipts in docs/qa/issue-1381.

Validation

make verify-issue-1381: PASS=13 / FAIL=0 / SKIP=1. Contract/indexer/frontend checks and retests passed: 884 contract, 513 indexer, 268 targeted frontend tests. Clippy, changed-source formatting, frontend types/lint/build, schema generation, secret scan and commit hooks passed. Frontend lint has five existing warnings.

Actual LocalTerra stores/migrations and eleven execution/rollback scenarios passed, including mixed 18/6 decimals, zero intermediate balances, multiple tax tokens, first/final taxes, router dust, exact feature invoice payment, native wrap/unwrap and atomic failures. The three-hop multi-tax measurement was 4,530,025 gas. Results and evidence explain wider-suite reruns and evidence limits.

Issue acceptance checklist

  • AC1 — actual zero-intermediate and multiple-tax route execution.
  • AC2 — route-funded charges; retained identity, exemptions and controls.
  • AC3 — pair-credit, sink/supply, quote/reverse and residue accounting.
  • AC4 — gross authorization; existing wallet balances/allowances/dust unused.
  • AC5 — supported taxed intermediates eligible/net-ranked; incompatible versions rejected.
  • AC6 — GET/POST/manual/exact-output/progress/cache/fallback funding consistency.
  • AC7 — Swap/Trade/Max/invoice/native budgets and failed-discovery protections.
  • AC8 — zero/exempt and legacy direct-pair/SendFrom security regressions.
  • AC9 production — LocalTerra migration/capability verification passed; Columbus-5 coordinated deployment and live execution were skipped because DEX multisig/CMM signing custody was unavailable. Read-only production inventory still shows legacy router 11640/ALPHA 11666.
  • AC10 — atomic rollback, accurate funding/balance recovery and no automatic resend.

Agent review instructions

Follow the agent checklist and RT1381 invariants. Use an isolated worktree, dedicated Postgres DB, current optimized artifacts and LocalTerra. Run make verify-issue-1381; provide VERIFY_ISSUE_1381_LEGACY_ARTIFACTS and VERIFY_ISSUE_1381_WRAP_STACK_ENV for migration/native checks.

An agent may skip a check it cannot complete, record its concrete reason through VERIFY_ISSUE_1381_SKIP_*_REASON, and mark overall verification PASS with explicit skips. Executed failures remain FAIL; skipped criteria stay unverified. The historical shared-stack Layer B suite and physical wallet/reporter replay were not rerun. Follow the coordinated rollout runbook when authorized signing custody becomes available; source verification does not establish production deployment.

CL8Y→ALPHA→UST1→USTR could quote successfully while requiring a separate ALPHA wallet balance to fund a middle-hop tax. Funding protocol v1 collects configured taxes from each route's own gross budgets, delivers the exact economic input declared to each pair, and quotes the executable net result. Traders fund the offered asset and network fees only. Refs #1381. Production rollout/live acceptance remains pending AC9. ## Implementation - Token/router 1.2.0: authenticated gross/economic/net tax funding, once-per-boundary buys, owned residue, dust isolation, atomic settlement and preserved trader controls. Explicit v1 entry prevents mixed-version wallet-debit fallback. - Independent trusted trading capability discovery; supported intermediates absent from the Create catalog remain eligible. Funded GET/POST/manual hybrid/exact-output ranking, stable progress identity and exact gross cache keys. - Swap/Trade/invoice/native budgets and preflight align with execution. Failed config/balance/exemption refreshes retain protection; manual and invoice hybrid plans use funded amounts. V1 measured gas fallback is 600k + 1.7M per hop with existing book/native overhead; auto simulation stays 1.2×. - Updated invariants, legacy compatibility playbooks, verifiers, coordinated migration instructions, and synthetic public receipts in [docs/qa/issue-1381](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/branch/fix/1381-route-local-tax/docs/qa/issue-1381). ## Validation `make verify-issue-1381`: **PASS=13 / FAIL=0 / SKIP=1**. Contract/indexer/frontend checks and retests passed: **884 contract**, **513 indexer**, **268 targeted frontend tests**. Clippy, changed-source formatting, frontend types/lint/build, schema generation, secret scan and commit hooks passed. Frontend lint has five existing warnings. Actual LocalTerra stores/migrations and eleven execution/rollback scenarios passed, including mixed 18/6 decimals, zero intermediate balances, multiple tax tokens, first/final taxes, router dust, exact feature invoice payment, native wrap/unwrap and atomic failures. The three-hop multi-tax measurement was **4,530,025 gas**. [Results and evidence](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/branch/fix/1381-route-local-tax/docs/qa/issue-1381/RESULTS.md) explain wider-suite reruns and evidence limits. ## Issue acceptance checklist - [x] AC1 — actual zero-intermediate and multiple-tax route execution. - [x] AC2 — route-funded charges; retained identity, exemptions and controls. - [x] AC3 — pair-credit, sink/supply, quote/reverse and residue accounting. - [x] AC4 — gross authorization; existing wallet balances/allowances/dust unused. - [x] AC5 — supported taxed intermediates eligible/net-ranked; incompatible versions rejected. - [x] AC6 — GET/POST/manual/exact-output/progress/cache/fallback funding consistency. - [x] AC7 — Swap/Trade/Max/invoice/native budgets and failed-discovery protections. - [x] AC8 — zero/exempt and legacy direct-pair/SendFrom security regressions. - [ ] AC9 production — LocalTerra migration/capability verification passed; Columbus-5 coordinated deployment and live execution were skipped because DEX multisig/CMM signing custody was unavailable. Read-only production inventory still shows legacy router 11640/ALPHA 11666. - [x] AC10 — atomic rollback, accurate funding/balance recovery and no automatic resend. ## Agent review instructions Follow [the agent checklist](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/branch/fix/1381-route-local-tax/docs/qa/issue-1381/README.md) and [RT1381 invariants](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/branch/fix/1381-route-local-tax/skills/AGENTS_ROUTE_LOCAL_TAX.md). Use an isolated worktree, dedicated Postgres DB, current optimized artifacts and LocalTerra. Run `make verify-issue-1381`; provide `VERIFY_ISSUE_1381_LEGACY_ARTIFACTS` and `VERIFY_ISSUE_1381_WRAP_STACK_ENV` for migration/native checks. An agent may skip a check it cannot complete, record its concrete reason through `VERIFY_ISSUE_1381_SKIP_*_REASON`, and mark overall verification **PASS with explicit skips**. Executed failures remain FAIL; skipped criteria stay unverified. The historical shared-stack Layer B suite and physical wallet/reporter replay were not rerun. Follow the coordinated rollout runbook when authorized signing custody becomes available; source verification does not establish production deployment.
fix(swap): fund token taxes from gross route budgets
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
ef873dcc5a
Collect routed sell and buy taxes from per-hop budgets and align contract execution, quotes, clients, and verification.
Merge main and retain tax funding, liquidity quality and migration guidance
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
e830c60fe2
Fix receive browser fixtures for strict tax discovery
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
fd0f0fb250
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!1383
No description provided.