Skip to content

Commit

Permalink
borrow amount fix
Browse files Browse the repository at this point in the history
  • Loading branch information
abrzezinski94 committed Jul 4, 2024
1 parent 5c96962 commit 1e355ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions components/StakeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,32 @@ function StakeForm({ token: selectedToken, clientContext }: StakeFormProps) {
)

const amountToBorrow = useMemo(() => {
const stakeAmount =
isSwapMode && bestRoute && stakeBank
? toUiDecimals(bestRoute.outAmount, stakeBank.mintDecimals)
: inputAmount
const borrowPrice = borrowBank?.uiPrice
const stakePrice = stakeBank?.uiPrice
if (!borrowPrice || !stakePrice || !Number(inputAmount)) return 0
if (!borrowPrice || !stakePrice || !Number(stakeAmount)) return 0
if (clientContext === 'jlp') {
const borrowAmount =
stakeBank?.uiPrice * Number(inputAmount) * (leverage - 1)
stakeBank?.uiPrice * Number(stakeAmount) * (leverage - 1)
return borrowAmount
} else {
const priceDifference = (stakePrice - borrowPrice) / borrowPrice
const borrowAmount =
(1 + priceDifference) * Number(inputAmount) * (leverage - 1)
(1 + priceDifference) * Number(stakeAmount) * (leverage - 1)
return borrowAmount
}
}, [clientContext, leverage, borrowBank, stakeBank, inputAmount])
}, [
isSwapMode,
bestRoute,
stakeBank,
inputAmount,
borrowBank?.uiPrice,
clientContext,
leverage,
])

const availableVaultBalance = useMemo(() => {
if (!borrowBank) return 0
Expand Down
2 changes: 1 addition & 1 deletion hooks/useJupiterMints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const fetchJupiterTokens = async () => {
const mangoTokens = data.filter(
(t) => jlpBankMints.includes(t.address) || lstBankMints.includes(t.address),
)
console.log(mangoTokens, '@@@@@@')

return {
mangoTokens,
jupiterTokens: data,
Expand Down

0 comments on commit 1e355ae

Please sign in to comment.