feat: intent calculator - #485
Open
57Ark wants to merge 9 commits into
Open
Conversation
… 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.