From 135f13cda9396d3c358286840adddc03be685815 Mon Sep 17 00:00:00 2001 From: mohandast52 Date: Mon, 4 Nov 2024 19:11:25 +0530 Subject: [PATCH] fix: refactor sol input handling in useWsolDeposit hook --- .../TokenManagement/hooks/useWsolDeposit.jsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/apps/bond/components/BondingProducts/Bonding/TokenManagement/hooks/useWsolDeposit.jsx b/apps/bond/components/BondingProducts/Bonding/TokenManagement/hooks/useWsolDeposit.jsx index cc35663a..67d3b1f8 100644 --- a/apps/bond/components/BondingProducts/Bonding/TokenManagement/hooks/useWsolDeposit.jsx +++ b/apps/bond/components/BondingProducts/Bonding/TokenManagement/hooks/useWsolDeposit.jsx @@ -152,11 +152,7 @@ export const useWsolDeposit = () => { ); const liquidity = quote.liquidityAmount.toString(); - return { - solMax, - olasMax, - liquidity - }; + return { solMax, olasMax, liquidity }; }; const checkIfNoEnoughOlas = async (whirlpoolTokenB, olasMax) => { @@ -173,9 +169,14 @@ export const useWsolDeposit = () => { const { whirlpoolTokenA, whirlpoolTokenB } = await getWhirlpoolData(); - const solInputInLamport = BigInt(sol); - const quote = await getDepositIncreaseLiquidityQuote({ sol, slippage }); - const { solMax, olasMax, solMaxInLamport } = await getDepositTransformedQuote(quote); + const solInputInLamportInBn = DecimalUtil.toBN(new Decimal(sol), 9); + const solInputInLamport = BigInt(solInputInLamportInBn.toString()); + + const quote = await getDepositIncreaseLiquidityQuote({ + sol, + slippage, + }); + const { solMax, olasMax } = await getDepositTransformedQuote(quote); // OLAS associated token account MUST always exist when the person bonds const tokenOwnerAccountB = await getAssociatedTokenAddress( @@ -288,7 +289,7 @@ export const useWsolDeposit = () => { try { await program.methods - .deposit(quote.liquidityAmount, solInputInLamport, quote.tokenMaxB) + .deposit(quote.liquidityAmount, solInputInLamportInBn, quote.tokenMaxB) .accounts({ position: POSITION, positionMint: POSITION_MINT,