Skip to content

🩹 market: mirror fixed repay rounding in position preview - #10

Merged
cruzdanilo merged 1 commit into
mainfrom
fix
May 12, 2026
Merged

🩹 market: mirror fixed repay rounding in position preview#10
cruzdanilo merged 1 commit into
mainfrom
fix

Conversation

@cruzdanilo

@cruzdanilo cruzdanilo commented May 11, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes

    • Market UI rounding for fixed-repay calculations now matches the position preview, ensuring consistent and accurate displayed repay amounts.
  • Chores

    • Bumped library with a patch release and added a release note documenting the rounding alignment.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 11, 2026

Copy link
Copy Markdown

Walkthrough

Updates fixed repayment logic to apply backup fee deduction and additional fixed-point steps when backup supply is constrained; adds a changeset documenting a patch release that the market UI mirrors the position preview rounding.

Changes

Fixed Repay Position Calculation

Layer / File(s) Summary
Repay Calculation with Backup Fee
src/market/fixedRepayPosition.ts
Under the mulWad(k, x) <= backupSupplied && x <= totalPosition branch, replaces the prior early return x with calculations: derive scaledPrincipal, compute capped gross from unassignedEarnings and backupSupplied, compute fee-adjusted/capped pos, recompute earned and repay, and return pos adjusted when repay > assets.
Release Notes
.changeset/kind-walls-write.md
Adds a changeset entry declaring a patch release for @exactly/lib and notes the market UI now mirrors the fixed repay rounding behavior used in the position preview.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: mirroring fixed repay rounding behavior in the market UI's position preview, which aligns with both file changes.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request updates the fixedRepayPosition function to align its rounding logic with fixedRepayAssets for position previews. The changes introduce a calculation for gross yield and adjust the return value to account for backup fees. Feedback was provided to improve consistency and precision by refactoring the logic to use a scaledPrincipal variable, which avoids redundant calculations and unnecessary rounding steps.

Comment thread src/market/fixedRepayPosition.ts Outdated
@sentry

sentry Bot commented May 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.75%. Comparing base (2ba65ce) to head (941f683).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/market/fixedRepayPosition.ts 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #10      +/-   ##
==========================================
- Coverage   80.75%   80.75%   -0.01%     
==========================================
  Files          46       46              
  Lines         686      691       +5     
  Branches       96       96              
==========================================
+ Hits          554      558       +4     
  Misses        128      128              
- Partials        4        5       +1     

☔ View full report in Codecov by Sentry.
📢 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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ac0588070f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/market/fixedRepayPosition.ts Outdated
Comment thread src/market/fixedRepayPosition.ts Outdated

@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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 27583557-27d6-41a0-8e89-186169ea6b9e

📥 Commits

Reviewing files that changed from the base of the PR and between ac05880 and f139e77.

📒 Files selected for processing (2)
  • .changeset/kind-walls-write.md
  • src/market/fixedRepayPosition.ts

Comment thread src/market/fixedRepayPosition.ts

@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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 837c893a-7c0d-4aef-b4fe-93a409c8ae43

📥 Commits

Reviewing files that changed from the base of the PR and between f139e77 and 941f683.

📒 Files selected for processing (2)
  • .changeset/kind-walls-write.md
  • src/market/fixedRepayPosition.ts

const pos = min(assets + gross - mulWad(gross, backupFeeRate), totalPosition);
const earned = mulDiv(unassignedEarnings, min(mulDiv(pos, principal, totalPosition), backupSupplied), backupSupplied);
const repay = pos - earned + mulWad(earned, backupFeeRate);
if (scaledPrincipal <= backupSupplied && x <= totalPosition) return pos - (repay > assets ? repay - assets : 0n);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Consider documenting the return adjustment logic.

The expression pos - (repay > assets ? repay - assets : 0n) performs a non-trivial adjustment. When repay > assets, this effectively returns pos - repay + assets, which algebraically simplifies to a complex relationship between earned amounts, fees, and the backup fee rate. A brief inline comment explaining the business logic (e.g., "adjust position to account for repayment shortfall") would aid maintainability.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 941f68361a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

const pos = min(assets + gross - mulWad(gross, backupFeeRate), totalPosition);
const earned = mulDiv(unassignedEarnings, min(mulDiv(pos, principal, totalPosition), backupSupplied), backupSupplied);
const repay = pos - earned + mulWad(earned, backupFeeRate);
if (scaledPrincipal <= backupSupplied && x <= totalPosition) return pos - (repay > assets ? repay - assets : 0n);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Revalidate the corrected position

After this patch's one-shot subtraction, the returned position can still cost more than the caller's asset limit because lowering pos also lowers the earned-yield offset used by fixedRepayAssets. For example, with principal=7743n, fee=408n, borrowed=813061n, supplied=647081n, unassignedEarnings=298005n, backupFeeRate=450351310267204224n, lastAccrual=1n, maturity=1000, timestamp=1, and assets=119n, this branch returns 1900n, but fixedRepayAssets(..., 1900n, 1) is 120n. Please iterate/recompute until the forward calculation is <= assets rather than subtracting only the first observed excess.

Useful? React with 👍 / 👎.

@cruzdanilo
cruzdanilo merged commit 941f683 into main May 12, 2026
5 checks passed
@cruzdanilo
cruzdanilo deleted the fix branch May 12, 2026 21:17
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