Skip to content

feat: intent calculator - #485

Open
57Ark wants to merge 9 commits into
nextfrom
feat/intent-calculator-graph
Open

feat: intent calculator#485
57Ark wants to merge 9 commits into
nextfrom
feat/intent-calculator-graph

Conversation

@57Ark

@57Ark 57Ark commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

57Ark and others added 9 commits August 15, 2026 15:00
… graph

Every intent is now a row in one table — which slots of the chain

  wallet ─add─▶ account ─convert(in→U)─▶ borrow|repay ─convert(U→out)─▶ ─withdraw─▶ wallet

are filled and which of three formulas gives the debt delta:

  debtForLeverage(C, L) = C·(L−1)     proportionalDebt(dC) = D0·dC/C0     price = oracle | RWA 1:1

## Structure
- math.ts     — the formulas + the leverage / debt-band checks
- plan.ts     — Step language (add/borrow/repay/convert/withdraw/claim/close) and pure,
                sync planners for the 5 start intents and the 3 resume tails; identity
                converts are legal and let one planner cover every S/T shape
- view.ts     — AccountView (collateral, band, price, fattest) read once per preview
- realize.ts  — the single async walk: ledger, convert → identity | RWA wrap/unwrap |
                router swap (keep = ledger balance − spend), repay capped by underlying on
                the ledger, quota update and calls appended once
- index.ts    — service is a switch over planners; public contract unchanged
- operations.ts — the op vocabulary in one file (was 13 directories)
- types.ts    — StartIntent types + IntentPreviewError next to the result types

## Removed
intents/full/*, intents/resume/*, utils/{simulate-adjust-state,with-quota-update,
assemble-operation-calls}.ts, operations/** — six copies of the RWA branching, two balance
bookkeeping mechanisms and the third ledger pass in simulateState.

## Size
Intent logic 2 114 → 1 226 lines (517 of them pure math/plans, testable without an sdk
mock); module logic 3 660 → 2 740; the client-v3 calculator this replaces is 11 073.

## Tests
- math.test.ts (5) and plan.test.ts (18): invariants on plain numbers
- 12 regression onchain suites moved to tests/, expectations unchanged (75 tests)
- docs/plans/intent-calculator-simplification.md: plan + result

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The pool service signals a missing route by throwing, so `unsupportedTokenPair`
was practically unreachable and an unroutable pair escaped the simulate
namespace as an exception. An explicitly requested `tokenOut` was trusted
rather than checked, failing later inside call assembly, and the deposit
default for `tokenIn` picked the first of a route set instead of the pool
underlying both `LpParams` and `PoolService` promise.

Also drops the leftovers resume removal left behind: the duplicate
`PreviewProps`, an unused generic and a stale section heading.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

2 participants