Skip to content

✨ market: add fixed borrow position and assets previews - #14

Open
cruzdanilo wants to merge 1 commit into
mainfrom
claude/project-thread-0urvjx
Open

cruzdanilo wants to merge 1 commit into
mainfrom
claude/project-thread-0urvjx

Conversation

@cruzdanilo

@cruzdanilo cruzdanilo commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

what

two pure previews for borrowAtMaturity, from a raw market snapshot:

  • fixedBorrowPosition(snapshot, maturity, assets, timestamp): the position (principal + fee) the market would record. it projects the market to timestamp the same way the contract does before pricing: floating debt accrual, the pool's backup earnings and the floating assets average. it uses the same rounding, and it throws where the contract reverts (zero borrow, unmatched pool, insufficient protocol liquidity).
  • fixedBorrowAssets(snapshot, maturity, position, timestamp): the most assets whose position fits position, capped by protocol liquidity. this is the inverse of the above. the fee is assets * g(assets), with g nearly flat, so it runs regula falsi (illinois) on the exact owed amount. the first step is the closed form position / (1 + g). it converges to the wei in 3 rate evaluations at the median, at most 18 in fuzzing even for borrows that take most of the market. the bracket always holds one point that fits and one that doesn't, and the result is always one that fits.

the snapshot holds the market's own storage fields and the pool at the maturity, so a previewer can return it as is.

tests

  • forward: matches borrowAtMaturity on anvil, to the wei, across 3 timestamps, every valid maturity and amounts from 1 wei to 100k usdc. a state override covers the average damping down. the liquidity and pool reverts are covered too.
  • inverse: on anvil, the result fits the position and one more wei doesn't. a property test checks the same against the forward preview over random utilizations, averages, reserve factors, maturities and sizes.
  • full line and branch coverage of both files.

Generated by Claude Code

Summary by CodeRabbit

  • New Features
    • Added previews for fixed-borrow repayment positions and the assets available to borrow. The estimates account for the selected maturity and current market conditions, helping you review a fixed-borrow amount before proceeding.

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

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 34 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

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 2336bed5-0c1a-452f-b06d-d1dabd8ab059
Commits

Reviewing files that changed from the base of the PR and between afec7fa and a085667.

Files selected for processing: 6

  • .changeset/brave-pools-borrow.md
  • src/index.ts
  • src/market/fixedBorrowAssets.ts
  • src/market/fixedBorrowPosition.ts
  • test/market.test.ts
  • wagmi.config.mts

Walkthrough

The pull request adds fixed-borrow position and assets preview functions. It adds maturity-specific market calculations, exports both previews from the package entry point, and adds tests that compare calculations with market calls.

Changes

Fixed borrow previews

Layer / File(s) Summary
Market state and position preview
src/market/fixedBorrowPosition.ts, test/market.test.ts, wagmi.config.mts
Adds snapshot and market types, maturity-specific market calculations, fixed-borrow factor calculation, and position preview. Tests compare preview results with market calls and check rejection cases.
Assets preview and package integration
src/market/fixedBorrowAssets.ts, src/index.ts, test/market.test.ts, .changeset/brave-pools-borrow.md
Adds an assets preview that searches for the greatest fitting asset amount. Exports both preview functions and adds tests for fitting amounts and position/asset inversion. Adds a minor-release changeset.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant fixedBorrowPosition
  participant fixedBorrowMarket
  participant fixedBorrowFactor
  Caller->>fixedBorrowPosition: snapshot, maturity, assets, timestamp
  fixedBorrowPosition->>fixedBorrowMarket: snapshot, maturity, timestamp
  fixedBorrowMarket-->>fixedBorrowPosition: market state and available liquidity
  fixedBorrowPosition->>fixedBorrowFactor: market state and assets
  fixedBorrowFactor-->>fixedBorrowPosition: fixed-borrow factor
  fixedBorrowPosition-->>Caller: assets plus rounded interest
Loading
Merge Risk: Moderate · previous review afec7

The new fixed-borrow previews can return a position or liquidity bound that differs from what the market actually records. This happens when other maturity pools hold unassigned earnings. Callers relying on the previews for borrow amounts could see mismatched results, so the snapshot and market model should be corrected before merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "✨ market: add fixed borrow position and assets previews" matches the main change. The PR adds fixedBorrowPosition and fixedBorrowAssets, two pure previews for borrowAtMaturity built from a …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "✨ market: add fixed borrow position and assets previews" matches the main change. The PR adds fixedBorrowPosition and fixedBorrowAssets, two pure previews for borrowAtMaturity built from a market snapshot. The title is concise and names both new functions, so a teammate scanning history can identify the primary change. The emoji is a minor style choice and does not affect clarity.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Simplify code

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T15:49:56.670369Z a085667 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.07692% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.54%. Comparing base (d9fedbc) to head (a085667).

Files with missing lines Patch % Lines
src/index.ts 0.00% 2 Missing ⚠️
wagmi.config.mts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #14      +/-   ##
==========================================
+ Coverage   80.75%   86.54%   +5.78%     
==========================================
  Files          46       48       +2     
  Lines         691      847     +156     
  Branches       96      117      +21     
==========================================
+ Hits          558      733     +175     
+ Misses        128      105      -23     
- Partials        5        9       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: ead9e97e-e7de-476a-9ec2-c94a1111db8e
Commits

Reviewing files that changed from the base of the PR and between d9fedbc and afec7fa.

Files selected for processing: 6

  • .changeset/brave-pools-borrow.md
  • src/index.ts
  • src/market/fixedBorrowAssets.ts
  • src/market/fixedBorrowPosition.ts
  • test/market.test.ts
  • wagmi.config.mts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Comment thread src/index.ts Resolved
Comment thread src/market/fixedBorrowPosition.ts Resolved
Comment thread test/market.test.ts Resolved
@cruzdanilo
cruzdanilo force-pushed the claude/project-thread-0urvjx branch from afec7fa to a085667 Compare November 23, 2026 15:47

This branch has not been deployed

No deployments
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