From 40b0d19397df3757e0e2b3e7487747e51cf56779 Mon Sep 17 00:00:00 2001 From: Mohan Date: Mon, 4 Nov 2024 19:21:50 +0530 Subject: [PATCH] (bond) fix: user unable to deposit sol (wsol) (#129) * feat: add solMaxInLamport to useWsolDeposit hook and improve liquidity checks * fix: reorder solMaxInLamport in useWsolDeposit hook and remove debug logs * feat: add log * feat: enhance WsolDeposit form labels and add extra information * fix: update extra information in WsolDeposit form labels for clarity * fix: fix SOL amount * fix: refactor sol input handling in useWsolDeposit hook --------- Co-authored-by: Aleksandr Kuperman --- .../Bonding/TokenManagement/WsolDeposit.jsx | 4 +++- .../TokenManagement/hooks/useWsolDeposit.jsx | 14 ++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/bond/components/BondingProducts/Bonding/TokenManagement/WsolDeposit.jsx b/apps/bond/components/BondingProducts/Bonding/TokenManagement/WsolDeposit.jsx index 66ca6192..bb044581 100644 --- a/apps/bond/components/BondingProducts/Bonding/TokenManagement/WsolDeposit.jsx +++ b/apps/bond/components/BondingProducts/Bonding/TokenManagement/WsolDeposit.jsx @@ -81,14 +81,16 @@ export const WsolDeposit = () => { name="sol" label="SOL (WSOL)" rules={[{ required: true, message: 'Please input a valid amount of SOL' }]} + extra="The amount of SOL or WSOL, whichever is greater." > diff --git a/apps/bond/components/BondingProducts/Bonding/TokenManagement/hooks/useWsolDeposit.jsx b/apps/bond/components/BondingProducts/Bonding/TokenManagement/hooks/useWsolDeposit.jsx index 08c1fa00..67d3b1f8 100644 --- a/apps/bond/components/BondingProducts/Bonding/TokenManagement/hooks/useWsolDeposit.jsx +++ b/apps/bond/components/BondingProducts/Bonding/TokenManagement/hooks/useWsolDeposit.jsx @@ -169,7 +169,13 @@ export const useWsolDeposit = () => { const { whirlpoolTokenA, whirlpoolTokenB } = await getWhirlpoolData(); - const quote = await getDepositIncreaseLiquidityQuote({ sol, slippage }); + 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 @@ -243,7 +249,7 @@ export const useWsolDeposit = () => { } else { // Check if the user has enough WSOL const wsolAmount = await getOlasAmount(connection, svmWalletPublicKey, whirlpoolTokenA.mint); - const noEnoughWsol = DecimalUtil.fromBN(solMax).greaterThan(DecimalUtil.fromBN(wsolAmount)); + const noEnoughWsol = solInputInLamport > wsolAmount; if (noEnoughWsol) { isWrapRequired = true; @@ -262,7 +268,7 @@ export const useWsolDeposit = () => { const transaction = createSolTransferTransaction( svmWalletPublicKey, tokenOwnerAccountA, - quote.tokenMaxA, + solInputInLamport, ); try { @@ -283,7 +289,7 @@ export const useWsolDeposit = () => { try { await program.methods - .deposit(quote.liquidityAmount, quote.tokenMaxA, quote.tokenMaxB) + .deposit(quote.liquidityAmount, solInputInLamportInBn, quote.tokenMaxB) .accounts({ position: POSITION, positionMint: POSITION_MINT,