📋 Description
src/pages/Bond.tsx computes early-withdrawal slash penalties via getPenaltyRate(status) (0.2 for locked, 0.1 for grace-period, 0 for active) and computeWithdrawBreakdown(bond), which derives penaltyPercent, penaltyAmount, resultingBalance, and a raw penaltyUsdc. This money-affecting logic — surfaced both in the slash-exposure banner and the ConfirmDialog breakdown — currently has no unit tests.
Why this matters: the penalty breakdown is the number a user sees before irreversibly slashing funds. A rounding or rate error here is a financial-trust bug. These pure functions are trivially testable and must be locked down.
🎯 Requirements & Context
Functional requirements
Context & constraints
- Keep behavior identical; this is test-and-extract only, no penalty-policy change.
- TypeScript
strict; the extracted module must be fully typed and TSDoc'd.
🛠️ Suggested Execution
1. Fork & branch
git checkout -b test/bond-penalty-math
2. Implement changes
- Move the pure helpers to
src/lib/bondPenalty.ts, re-import into Bond.tsx, add TSDoc.
- Cover edge cases: zero-amount bond, fractional USDC amounts,
active status yielding zero penalty, very large amounts (no precision loss in the displayed string).
3. Test & commit
npm run test
npm run lint
npm run build
- Paste the Vitest run summary into the PR.
Example commit message
test(bond): extract and unit-test penalty rate + withdraw breakdown math
Moves getPenaltyRate/computeWithdrawBreakdown to src/lib/bondPenalty.ts and
covers every status branch plus the penalty+resulting==amount invariant.
✅ Acceptance Criteria & Guidelines
| Requirement |
Target |
| Penalty helpers extracted + TSDoc'd |
Required |
| All status branches covered |
Required |
| Conservation invariant asserted |
Required |
| Vitest coverage of the module |
≥ 95% |
npm run lint + npm run build + npm run test clean |
Required |
| Timeframe |
96 hours from assignment |
💬 Community & Support
Questions and design discussion — join the Credence contributor community on Discord: https://discord.gg/nmnPBkBge
Please comment to ask to be assigned before you start so we can avoid duplicate work and unblock you fast. 🚀
📋 Description
src/pages/Bond.tsxcomputes early-withdrawal slash penalties viagetPenaltyRate(status)(0.2 forlocked, 0.1 forgrace-period, 0 foractive) andcomputeWithdrawBreakdown(bond), which derivespenaltyPercent,penaltyAmount,resultingBalance, and a rawpenaltyUsdc. This money-affecting logic — surfaced both in the slash-exposure banner and theConfirmDialogbreakdown — currently has no unit tests.🎯 Requirements & Context
Functional requirements
getPenaltyRateandcomputeWithdrawBreakdown(and theformatUsdchelper) into a testable module if they are not already exported — prefersrc/lib/bondPenalty.tsand import them back intoBond.tsx.BondStatusbranch and the rate→amount→resulting-balance chain.penaltyPercentis an integer percent;penaltyAmount/resultingBalanceuse theformatUsdcthousands-grouped +USDCsuffix.penaltyUsdc + resultingUsdc === bondAmount(within floating-point tolerance) across representative amounts.Context & constraints
strict; the extracted module must be fully typed and TSDoc'd.🛠️ Suggested Execution
1. Fork & branch
2. Implement changes
src/lib/bondPenalty.ts, re-import intoBond.tsx, add TSDoc.activestatus yielding zero penalty, very large amounts (no precision loss in the displayed string).3. Test & commit
npm run test npm run lint npm run buildExample commit message
✅ Acceptance Criteria & Guidelines
npm run lint+npm run build+npm run testclean💬 Community & Support
Questions and design discussion — join the Credence contributor community on Discord: https://discord.gg/nmnPBkBge
Please comment to ask to be assigned before you start so we can avoid duplicate work and unblock you fast. 🚀