Skip to content

Commit

Permalink
Remove liq param from ClosePosition function (#473)
Browse files Browse the repository at this point in the history
* Remove liq param from ClosePosition function

* Docs

* Tweak
  • Loading branch information
wjthieme authored Nov 7, 2024
1 parent 7c6b988 commit 81d64fe
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ To close a position and withdraw all liquidity, follow these steps:
const { instructions, quote, feesQuote, rewardsQuote } = await closePositionInstructions(
rpc,
positionMint,
param,
slippageTolerance,
wallet
slippageTolerance,
wallet
);
```
7. **Submit Transaction**: Include the generated instructions in a Solana transaction and send it to the network using the Solana SDK.
Expand Down
21 changes: 6 additions & 15 deletions ts-sdk/whirlpool/src/decreaseLiquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ export type ClosePositionInstructions = DecreaseLiquidityInstructions & {
*
* @param {SolanaRpc} rpc - A Solana RPC client for fetching accounts and pool data.
* @param {Address} positionMintAddress - The mint address of the NFT that represents ownership of the position to be closed.
* @param {DecreaseLiquidityQuoteParam} param - The parameters for removing liquidity (liquidity, tokenA, or tokenB).
* @param {number} [slippageToleranceBps=SLIPPAGE_TOLERANCE_BPS] - The acceptable slippage tolerance in basis points.
* @param {TransactionSigner} [authority=FUNDER] - The account authorizing the transaction.
*
Expand All @@ -297,12 +296,10 @@ export type ClosePositionInstructions = DecreaseLiquidityInstructions & {
*
* const positionMint = "POSITION_MINT";
*
* const param = { liquidity: 500_000n };
*
* const { instructions, quote, feesQuote, rewardsQuote } = await closePositionInstructions(
* devnetRpc,
* positionMint,
* param,
* 100,
* wallet
* );
Expand All @@ -314,7 +311,6 @@ export async function closePositionInstructions(
GetMinimumBalanceForRentExemptionApi
>,
positionMintAddress: Address,
param: DecreaseLiquidityQuoteParam,
slippageToleranceBps: number = SLIPPAGE_TOLERANCE_BPS,
authority: TransactionSigner = FUNDER,
): Promise<ClosePositionInstructions> {
Expand Down Expand Up @@ -348,7 +344,7 @@ export async function closePositionInstructions(
const transferFeeB = getCurrentTransferFee(mintB, currentEpoch.epoch);

const quote = getDecreaseLiquidityQuote(
param,
{ liquidity: position.data.liquidity },
whirlpool.data,
position.data,
slippageToleranceBps,
Expand Down Expand Up @@ -431,18 +427,13 @@ export async function closePositionInstructions(
requiredMints.push(whirlpool.data.tokenMintA);
requiredMints.push(whirlpool.data.tokenMintB);
}
if (rewardsQuote.rewards[0].rewardsOwed > 0n) {
requiredMints.push(whirlpool.data.rewardInfos[0].mint);
}
if (rewardsQuote.rewards[1].rewardsOwed > 0n) {
requiredMints.push(whirlpool.data.rewardInfos[1].mint);
}
if (rewardsQuote.rewards[2].rewardsOwed > 0n) {
requiredMints.push(whirlpool.data.rewardInfos[2].mint);

for (let i = 0; i < rewardsQuote.rewards.length; i++) {
if (rewardsQuote.rewards[i].rewardsOwed > 0n) {
requiredMints.push(whirlpool.data.rewardInfos[i].mint);
}
}

// FIXME: this creates the accounts even if they are not actually needed
// (no rewards, fees, to decrease liquidity, etc.)
const { createInstructions, cleanupInstructions, tokenAccountAddresses } =
await prepareTokenAccountsInstructions(rpc, authority, requiredMints);

Expand Down
13 changes: 5 additions & 8 deletions ts-sdk/whirlpool/src/harvest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,11 @@ export async function harvestPositionInstructions(
requiredMints.push(whirlpool.data.tokenMintA);
requiredMints.push(whirlpool.data.tokenMintB);
}
if (rewardsQuote.rewards[0].rewardsOwed > 0n) {
requiredMints.push(whirlpool.data.rewardInfos[0].mint);
}
if (rewardsQuote.rewards[1].rewardsOwed > 0n) {
requiredMints.push(whirlpool.data.rewardInfos[1].mint);
}
if (rewardsQuote.rewards[2].rewardsOwed > 0n) {
requiredMints.push(whirlpool.data.rewardInfos[2].mint);

for (let i = 0; i < rewardsQuote.rewards.length; i++) {
if (rewardsQuote.rewards[i].rewardsOwed > 0n) {
requiredMints.push(whirlpool.data.rewardInfos[i].mint);
}
}

const { createInstructions, cleanupInstructions, tokenAccountAddresses } =
Expand Down
1 change: 0 additions & 1 deletion ts-sdk/whirlpool/tests/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ describe("e2e", () => {
const { instructions, quote, feesQuote } = await closePositionInstructions(
rpc,
positionMint,
{ liquidity: 1000000000n },
);
await sendTransaction(instructions);

Expand Down

0 comments on commit 81d64fe

Please sign in to comment.