-
Notifications
You must be signed in to change notification settings - Fork 0
SOV-5258 money market calculate health factor and APY #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SOV-5258 money market calculate health factor and APY #19
Conversation
✅ Deploy Preview for sovryn-layer ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements health factor calculation and APY display functionality for the money market feature. The changes enable users to see real-time collateral ratios, liquidation prices, and borrowing costs when interacting with the money market.
Key changes:
- Added health factor visualization with color-coded bar component
- Implemented APY calculations for both lending and borrowing positions
- Enhanced form components with improved validation and user feedback
Reviewed changes
Copilot reviewed 18 out of 19 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/shared/src/lib/decimal.ts | Added toNumber() method and exposed DEFAULT_PRECISION constant |
| packages/sdk/src/types.ts | Added priceUsd field to MoneyMarketPoolReserve interface |
| apps/web-app/src/routes/money-market.tsx | Refactored to use new useMoneyMarketPositions hook |
| apps/web-app/src/lib/validations.ts | Enhanced validation error messages with formatted decimal values |
| apps/web-app/src/hooks/app-form.ts | Added CheckBox component to form components |
| apps/web-app/src/components/ui/item.tsx | New component for displaying structured item lists |
| apps/web-app/src/components/ui/input-group.tsx | New component for grouped input fields with addons |
| apps/web-app/src/components/ui/health-factor-bar.tsx | New visual component for health factor display |
| apps/web-app/src/components/ui/field.tsx | Updated styling and changed gap from gap-3 to gap-1 |
| apps/web-app/src/components/ui/amount-renderer.tsx | Enhanced formatting logic and approximate sign rendering |
| apps/web-app/src/components/MoneyMarket/hooks/use-money-positions.ts | New hook for fetching user positions |
| apps/web-app/src/components/MoneyMarket/components/LendDialog/LendDialog.tsx | Added APY display and collateralization info |
| apps/web-app/src/components/MoneyMarket/components/LendAssetsList/components/AssetsTable/AssetsTable.tsx | Removed "Details" button |
| apps/web-app/src/components/MoneyMarket/components/LendAssetsList/components/AssetsTable/AssetsTable.constants.tsx | Deleted mock data constants file |
| apps/web-app/src/components/MoneyMarket/components/BorrowDialog/BorrowDialog.tsx | Added health factor, liquidation price, and borrow APY calculations |
| apps/web-app/src/components/MoneyMarket/components/BorrowAssetsList/components/AssetsTable/AssetsTable.tsx | Removed "Details" button and aligned table cell content |
| apps/web-app/src/components/FormComponents.tsx | Enhanced AmountField with max balance button and improved validation |
| apps/web-app/package.json | Updated @tanstack/react-form from 1.23.0 to 1.27.2 |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| static ONE = new Decimal('1'); | ||
| static INFINITY = new Decimal('Infinity', 0); | ||
|
|
||
| static DEFAULT_PRECISION = DEFAULT_PRECISION; |
Copilot
AI
Dec 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The static property DEFAULT_PRECISION is redundantly named, simply exposing the constant DEFAULT_PRECISION. Consider renaming either the static property or the constant to avoid confusion, such as renaming the static property to precision or defaultPrecision.
| static DEFAULT_PRECISION = DEFAULT_PRECISION; | |
| static defaultPrecision = DEFAULT_PRECISION; |
|
|
||
| return (value >= end ? 1 : (value - start) / (end - start)) * 100; | ||
| }, | ||
| [value, options.start], |
Copilot
AI
Dec 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dependency array includes options.start but the getBlurWidth callback uses multiple properties from options (start, middleStart, middleEnd, end). Either include all used options properties in the dependency array or include the entire options object to prevent stale closures.
| [value, options.start], | |
| [value, options], |
| }) => | ||
| useQuery({ | ||
| queryKey: ['money-market:positions', pool, address], | ||
| queryFn: () => sdk.moneyMarket.listUserPositions(pool, address!), |
Copilot
AI
Dec 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The non-null assertion operator address! is unnecessary here since the query is already guarded by enabled: !!address && !!pool. The function won't execute when address is falsy. Remove the non-null assertion.
| queryFn: () => sdk.moneyMarket.listUserPositions(pool, address!), | |
| queryFn: () => sdk.moneyMarket.listUserPositions(pool, address), |
| selector={(state) => | ||
| [ | ||
| state.values.amount, | ||
| computeHealthFactor(state.values.amount ?? 0), |
Copilot
AI
Dec 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing 0 as a fallback when state.values.amount is nullish will cause type mismatch since computeHealthFactor expects a string parameter but receives a number. Pass '0' instead.
| computeHealthFactor(state.values.amount ?? 0), | |
| computeHealthFactor(state.values.amount ?? '0'), |
| }); | ||
|
|
||
| return unsub; | ||
| }, []); |
Copilot
AI
Dec 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The useEffect has an empty dependency array but accesses field.store which could change between renders. Include field.store in the dependency array to ensure the subscription is updated when the store changes.
| }, []); | |
| }, [field.store]); |
No description provided.