Skip to content

refactor: llamalend user borrow position queries#2037

Open
OnlyJousting wants to merge 11 commits intomainfrom
refactor/llamalend-user-read-queries
Open

refactor: llamalend user borrow position queries#2037
OnlyJousting wants to merge 11 commits intomainfrom
refactor/llamalend-user-read-queries

Conversation

@OnlyJousting
Copy link
Contributor

@OnlyJousting OnlyJousting commented Feb 16, 2026

Changes:

  • Unified borrow position data hooks: Deleted separate useBorrowPositionDetails (lend) and useLoanPositionDetails (loan) hooks, replacing them with a single shared useBorrowPositionDetails in llamalend/features/market-position-details together with shared query usage
  • Reorganized user queries: Moved scattered user query files (user-balances, user-health, user-prices, user-state, user-current-leverage) into a consolidated llamalend/queries/user/ directory with a barrel export index.ts
  • Added new user queries: Created dedicated query files for user-bands, user-loss, user-market-balances, and user-supply-boost (previously inlined or scattered)
  • Centralized query invalidation: Added invalidation.ts in the user queries directory and invalidate.ts in lend entities, providing a single invalidateAllUserMarketDetails function for joint invalidation of all user position queries
  • Updated all consumers: Updated ~40+ files across lend, loan, and llamalend domains to import from the new consolidated locations
  • Minor cleanup: Replaced Number() conversions with unary + operator, and removed duplicate invalidation calls (e.g. in close-position.mutation.ts and in /lend/PageLendMarket/ManageLoanTabs), normalize market and marketId naming from llamma/llammaId

@vercel
Copy link

vercel bot commented Feb 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
curve-dapp Ready Ready Preview, Comment Feb 18, 2026 0:05am
curve-dapp-storybook Ready Ready Preview, Comment Feb 18, 2026 0:05am

Request Review

}),
pendingMessage: () => t`Closing position...`,
successMessage: () => t`Position closed successfully!`,
onSuccess: () => invalidateAllUserBorrowDetails({ chainId, marketId, userAddress }),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

invalidation was duplicated here, it happens in useLlammaMutation

@OnlyJousting OnlyJousting requested review from 0xAlunara, 0xPearce and DanielSchiavini and removed request for 0xAlunara February 17, 2026 21:36
<NoPosition type="supply" />
</Stack>
)}
{hasSupplyPosition ? <SupplyPositionDetails {...supplyPositionDetails} /> : <NoPosition type="supply" />}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I missed this in a previous PR so I snuck it into this one 🙈

import { useMarketUserBandsBalances } from '@/llamalend/features/bands-chart/queries/market-user-bands-balances.query'
import { parseFetchedBandsBalances } from '@/llamalend/features/bands-chart/queries/utils'
import { useLoanExists } from '@/llamalend/queries/loan-exists'
import { useLoanExists } from '@/llamalend/queries/user'
Copy link
Contributor

Choose a reason for hiding this comment

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

Lint error wrt ordering

import { type CloseLoanMutation, useClosePositionMutation } from '@/llamalend/mutations/close-position.mutation'
import { useCloseLoanIsApproved } from '@/llamalend/queries/close-loan/close-loan-is-approved.query'
import { useUserState } from '@/llamalend/queries/user-state.query'
import { useUserState } from '@/llamalend/queries/user/user-state.query'
Copy link
Contributor

Choose a reason for hiding this comment

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

Could've used the index.ts no?

import { useCloseEstimateGas } from '@/llamalend/queries/close-loan/close-loan-gas-estimate.query'
import { useCloseLoanIsApproved } from '@/llamalend/queries/close-loan/close-loan-is-approved.query'
import { useUserState } from '@/llamalend/queries/user-state.query'
import { useUserState } from '@/llamalend/queries/user/user-state.query'
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

@@ -0,0 +1 @@
export * from './useBorrowPositionDetails'
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure a barrel is useful here but I'll allow it

marketId: market.id,
userAddress: api.signerAddress,
})
void Promise.all([
Copy link
Contributor

Choose a reason for hiding this comment

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

why void and not await? It's already async and awaiting the loan exists, might as well complete it
(the answer is you copied it from user-loan-details but i only found out later, i dunno might as well add an await here)

invalidateUserHealth({ marketId, userAddress, chainId, isFull: true }),
invalidateUserHealth({ marketId, userAddress, chainId, isFull: false }),
invalidateUserBalances({ marketId, userAddress, chainId }),
invalidateAllUserPositionQueries({ marketId, userAddress, chainId }),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we actually move this to invalidation.ts in the user folder?

}

// invalidate user prices to keep ohlc chart liquidation range in sync
await invalidateUserPrices({
Copy link
Contributor

Choose a reason for hiding this comment

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

Not invalidating user prices anymore is deliberate? It's not covered by invalidateAllUserMarketDetails

} from '@/llamalend/features/market-position-details'
import { calculateLtv, getIsUserCloseToLiquidation, getLiquidationStatus, hasV2Leverage } from '@/llamalend/llama.utils'
import type { LlamaMarketTemplate } from '@/llamalend/llamalend.types'
import { useLoanExists } from '@/llamalend/queries/user'
Copy link
Contributor

Choose a reason for hiding this comment

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

Lint import order error

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.

2 participants