diff --git a/components/StakeForm.tsx b/components/StakeForm.tsx index b4938e3..26e3b55 100644 --- a/components/StakeForm.tsx +++ b/components/StakeForm.tsx @@ -166,9 +166,6 @@ function StakeForm({ token: selectedToken }: StakeFormProps) { setSubmitting(true) try { - console.log('starting deposit') - console.log('amountToBorrow', amountToBorrow) - const newAccountNum = getNextAccountNumber(mangoAccounts) const { signature: tx, slot } = await stakeAndCreate( client, @@ -214,6 +211,22 @@ function StakeForm({ token: selectedToken }: StakeFormProps) { setLeverage(v * 1) }, []) + const leverageMax = useMemo(() => { + if (!stakeBank || !borrowBank) return 1 + const borrowInitLiabWeight = borrowBank.scaledInitLiabWeight( + borrowBank.price, + ) + const stakeInitAssetWeight = stakeBank.scaledInitAssetWeight( + stakeBank.price, + ) + if (!borrowInitLiabWeight || !stakeInitAssetWeight) return 1 + + const x = stakeInitAssetWeight.div(borrowInitLiabWeight).toNumber() + const conversionRate = borrowBank.uiPrice / stakeBank.uiPrice + const y = 1 - conversionRate * stakeInitAssetWeight.toNumber() + return 1 + x / y + }, [stakeBank, borrowBank]) + useEffect(() => { const group = mangoStore.getState().group set((state) => { @@ -311,7 +324,7 @@ function StakeForm({ token: selectedToken }: StakeFormProps) {

{leverage}x

diff --git a/components/UnstakeForm.tsx b/components/UnstakeForm.tsx index ac43685..f393981 100644 --- a/components/UnstakeForm.tsx +++ b/components/UnstakeForm.tsx @@ -158,7 +158,6 @@ function UnstakeForm({ token: selectedToken }: UnstakeFormProps) { setSubmitting(true) try { - console.log('starting deposit') const { signature: tx } = await unstakeAndClose( client, group, diff --git a/hooks/useStakeRates.ts b/hooks/useStakeRates.ts index e1486fd..22d37cf 100644 --- a/hooks/useStakeRates.ts +++ b/hooks/useStakeRates.ts @@ -14,19 +14,16 @@ const fetchRates = async () => { fetchAndParsePricesCsv(DATA_SOURCE.SOLBLAZE_CSV), fetchAndParsePricesCsv(DATA_SOURCE.LIDO_CSV), ]) - console.log('jitosol', jitoPrices) // may be null if the price range cannot be calculated const msolRange = getPriceRangeFromPeriod(msolPrices, PERIOD.DAYS_30) const jitoRange = getPriceRangeFromPeriod(jitoPrices, PERIOD.DAYS_30) const bsolRange = getPriceRangeFromPeriod(bsolPrices, PERIOD.DAYS_30) const lidoRange = getPriceRangeFromPeriod(lidoPrices, PERIOD.DAYS_30) - console.log('msol prices', msolPrices) const rateData: Record = {} if (msolRange) { - console.log('APY: ', calcYield(msolRange)?.apy) // 0.06707557862842384 => 6.71 % rateData.msol = calcYield(msolRange)?.apy } if (jitoRange) { diff --git a/utils/transactions.ts b/utils/transactions.ts index 65c757e..7aaf82b 100644 --- a/utils/transactions.ts +++ b/utils/transactions.ts @@ -50,8 +50,6 @@ export const unstakeAndClose = async ( } const stakeBalance = mangoAccount.getTokenBalanceUi(stakeBank) const borrowedSol = mangoAccount.getTokenBalance(solBank) - console.log('borrowedSol', borrowedSol) - console.log('unstake amount', amount) let swapAlts: AddressLookupTableAccount[] = [] if (borrowedSol.toNumber()) { @@ -101,12 +99,6 @@ export const unstakeAndClose = async ( amount, group.getMintDecimals(stakeBank.mint), ) - console.log( - 'amount, stakeBalance, nativeAmount', - amount, - floorToDecimal(stakeBalance, stakeBank.mintDecimals).toNumber(), - nativeWithdrawAmount.toNumber(), - ) const withdrawMax = amount == floorToDecimal(stakeBalance, stakeBank.mintDecimals).toNumber() const healthRemainingAccounts: PublicKey[] = withdrawMax @@ -201,7 +193,13 @@ export const stakeAndCreate = async ( } const depositHealthRemainingAccounts: PublicKey[] = mangoAccount - ? client.buildHealthRemainingAccounts(group, [mangoAccount], [], [], []) + ? client.buildHealthRemainingAccounts( + group, + [mangoAccount], + [stakeBank], + [], + [], + ) : [stakeBank.publicKey, stakeBank.oracle] const depositTokenIxs = await createDepositIx( client,