Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughAdds realized and total bad-debt fields to market GraphQL and types, ensures subgraph transformation supplies a default realizedBadDebt, surfaces realizedBadDebt into warnings logic (introducing an internal BAD_DEBT check), updates hooks to accept full Market, shortens a cache TTL, and enables WalletConnect in wallet config. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant UI as UI
participant GQL as GraphQL API
participant Subgraph as Subgraph Transform
participant Warnings as Warnings Util
UI->>GQL: request markets (includes badDebt, realizedBadDebt)
GQL-->>UI: returns markets with debt fields
UI->>Subgraph: transform market (ensure realizedBadDebt.underlying default '0')
Subgraph-->>UI: market detail
UI->>Warnings: getMarketWarningsWithDetail(market: Market)
alt realizedBadDebt.underlying > 0 and realizedBadDebt*1000 > supply
Warnings-->>UI: warnings + BAD_DEBT
else
Warnings-->>UI: warnings (no BAD_DEBT)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/data-sources/subgraph/market.ts (1)
268-272: Use existing badDebtRealizations data
The subgraph already returnsbadDebtRealizationsin your liquidation query. Instead of hardcoding'0'inrealizedBadDebt, mirror the parsing logic fromsrc/data-sources/subgraph/market-liquidations.ts. If you must defer, add a comment explaining why this stays defaulted.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
src/data-sources/subgraph/market.ts(1 hunks)src/graphql/morpho-api-queries.ts(2 hunks)src/hooks/useMarketWarnings.ts(3 hunks)src/hooks/useUserPositionsSummaryData.ts(1 hunks)src/store/createWagmiConfig.ts(2 hunks)src/utils/types.ts(1 hunks)src/utils/warnings.ts(5 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/hooks/useMarketWarnings.ts (1)
src/utils/types.ts (1)
Market(260-307)
src/utils/warnings.ts (1)
src/utils/types.ts (2)
WarningWithDetail(81-86)Market(260-307)
🔇 Additional comments (2)
src/hooks/useMarketWarnings.ts (2)
9-12: LGTM: Type signature simplified.Accepting the full
Markettype is cleaner thanPick<Market, ...>and makes the function signature easier to maintain. The change aligns with the addition ofrealizedBadDebtto the Market type.Also applies to: 30-34
21-21: Dependency addition looks correct.Adding
market.realizedBadDebt.underlyingensures the warnings recompute when bad debt changes. The granular property access is appropriate here.
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/utils/warnings.ts(5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/utils/warnings.ts (1)
src/utils/types.ts (2)
WarningWithDetail(81-86)Market(260-307)
| // Append bad debt warnings | ||
| try { | ||
| const badDebtUnderlying = market.realizedBadDebt.underlying; | ||
| if (badDebtUnderlying != null) { | ||
| const badDebt = BigInt(badDebtUnderlying); | ||
| if (badDebt > 0n) { | ||
| // only push the bad debt error is it's > 10BPS | ||
| const supplyAssets = BigInt(market.state.supplyAssets); | ||
| if (badDebt * 1000n > supplyAssets) { | ||
| result.push(BAD_DEBT); | ||
| } | ||
| } | ||
| } | ||
| } catch { | ||
| // ignore invalid BigInt values (e.g., decimal strings like "0.00") | ||
| } |
There was a problem hiding this comment.
Fix bad-debt parsing
realizedBadDebt.underlying shows up as decimal text (e.g. "0.05"). BigInt throws, we hit the catch, and the warning never fires even though debt exists. Parse as a float (or other decimal helper) and guard before comparing; same for supplyAssets.
- const badDebtUnderlying = market.realizedBadDebt.underlying;
- if (badDebtUnderlying != null) {
- const badDebt = BigInt(badDebtUnderlying);
- if (badDebt > 0n) {
- // only push the bad debt error is it's > 10BPS
- const supplyAssets = BigInt(market.state.supplyAssets);
- if (badDebt * 1000n > supplyAssets) {
- result.push(BAD_DEBT);
- }
- }
- }
+ const badDebtValue = Number(market.realizedBadDebt?.underlying ?? '0');
+ const supplyValue = Number(market.state?.supplyAssets ?? '0');
+ if (
+ Number.isFinite(badDebtValue) &&
+ Number.isFinite(supplyValue) &&
+ badDebtValue > 0 &&
+ badDebtValue * 1000 > supplyValue
+ ) {
+ result.push(BAD_DEBT);
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Append bad debt warnings | |
| try { | |
| const badDebtUnderlying = market.realizedBadDebt.underlying; | |
| if (badDebtUnderlying != null) { | |
| const badDebt = BigInt(badDebtUnderlying); | |
| if (badDebt > 0n) { | |
| // only push the bad debt error is it's > 10BPS | |
| const supplyAssets = BigInt(market.state.supplyAssets); | |
| if (badDebt * 1000n > supplyAssets) { | |
| result.push(BAD_DEBT); | |
| } | |
| } | |
| } | |
| } catch { | |
| // ignore invalid BigInt values (e.g., decimal strings like "0.00") | |
| } | |
| // Append bad debt warnings | |
| try { | |
| const badDebtValue = Number(market.realizedBadDebt?.underlying ?? '0'); | |
| const supplyValue = Number(market.state?.supplyAssets ?? '0'); | |
| if ( | |
| Number.isFinite(badDebtValue) && | |
| Number.isFinite(supplyValue) && | |
| badDebtValue > 0 && | |
| badDebtValue * 1000 > supplyValue | |
| ) { | |
| result.push(BAD_DEBT); | |
| } | |
| } catch { | |
| // ignore invalid BigInt values (e.g., decimal strings like "0.00") | |
| } |
🤖 Prompt for AI Agents
In src/utils/warnings.ts around lines 184 to 199, replace the current BigInt
parsing/try-catch with numeric/decimal-safe parsing: parse
realizedBadDebt.underlying and market.state.supplyAssets as decimals (e.g.,
parseFloat or a Decimal/Big library) only proceed if both parse to finite
numbers, compute the ratio (badDebt / supplyAssets) and push BAD_DEBT when the
ratio > 0.001 (10 bps); if you need integer precision use a scaled integer
approach (multiply decimals to an agreed scale before comparing) and remove the
silent BigInt swallow so numeric parsing errors are handled by the guard checks
instead.
There was a problem hiding this comment.
The field should return string, expect to be integer.
Does your comment still hold?
There was a problem hiding this comment.
@antoncoding, you're right—if realizedBadDebt.underlying is an integer string (like "1234567890"), then BigInt() is the correct parser. My original comment assumed decimal text, which was incorrect.
The current implementation looks fine. The try-catch guards against malformed data, but if the API always returns valid integer strings, it should work as intended.
If you want to verify the catch block isn't hiding real issues, you could temporarily log any errors during development, but otherwise the code is sound.
🐰
Summary by CodeRabbit
New Features
Chores