Skip to content

Commit

Permalink
(bond) fix: user unable to deposit sol (wsol) (#129)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
mohandast52 and kupermind authored Nov 4, 2024
1 parent 6204d48 commit 40b0d19
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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."
>
<InputNumber min={0} className="full-width" onChange={onWsolAndSlippageChange} />
</Form.Item>

<Form.Item
name="olas"
label="OLAS"
label="Max OLAS"
rules={[{ required: true, message: 'Please input a valid amount of OLAS' }]}
extra="The max amount of OLAS accounting for the slippage value."
>
<InputNumber disabled className="full-width" />
</Form.Item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -262,7 +268,7 @@ export const useWsolDeposit = () => {
const transaction = createSolTransferTransaction(
svmWalletPublicKey,
tokenOwnerAccountA,
quote.tokenMaxA,
solInputInLamport,
);

try {
Expand All @@ -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,
Expand Down

0 comments on commit 40b0d19

Please sign in to comment.