You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
✨ market: add fixed borrow position and assets previews - #14
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.
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.
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.
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: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
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
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
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.
❌ 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).
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.
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
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.
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 totimestampthe 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 fitsposition, capped by protocol liquidity. this is the inverse of the above. the fee isassets * g(assets), withgnearly flat, so it runs regula falsi (illinois) on the exact owed amount. the first step is the closed formposition / (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
borrowAtMaturityon 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.Generated by Claude Code
Summary by CodeRabbit