|
@@ -311,9 +311,12 @@ export class CopyExecutor {
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- // First remove all liquidity
|
|
|
|
|
|
|
+ // Remove all liquidity with shouldClaimAndClose=true.
|
|
|
|
|
+ // This removes liquidity, claims fees, AND closes the position account
|
|
|
|
|
+ // in one step — no separate closePosition call needed.
|
|
|
|
|
+ let followerTx: string
|
|
|
try {
|
|
try {
|
|
|
- await copyRemoveLiquidity(
|
|
|
|
|
|
|
+ followerTx = await copyRemoveLiquidity(
|
|
|
this.connection,
|
|
this.connection,
|
|
|
this.follower,
|
|
this.follower,
|
|
|
new PublicKey(followerInfo.positionAddress),
|
|
new PublicKey(followerInfo.positionAddress),
|
|
@@ -321,18 +324,19 @@ export class CopyExecutor {
|
|
|
10000,
|
|
10000,
|
|
|
this.settings
|
|
this.settings
|
|
|
)
|
|
)
|
|
|
- } catch {
|
|
|
|
|
- // Liquidity might already be removed
|
|
|
|
|
|
|
+ } catch (removeErr) {
|
|
|
|
|
+ // If remove fails (e.g. position already empty), try direct close
|
|
|
|
|
+ console.log(
|
|
|
|
|
+ `[Executor] Remove liquidity failed (${removeErr}), trying direct close...`
|
|
|
|
|
+ )
|
|
|
|
|
+ followerTx = await copyClosePosition(
|
|
|
|
|
+ this.connection,
|
|
|
|
|
+ this.follower,
|
|
|
|
|
+ new PublicKey(followerInfo.positionAddress),
|
|
|
|
|
+ new PublicKey(followerInfo.lbPairAddress)
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Then close the position
|
|
|
|
|
- const followerTx = await copyClosePosition(
|
|
|
|
|
- this.connection,
|
|
|
|
|
- this.follower,
|
|
|
|
|
- new PublicKey(followerInfo.positionAddress),
|
|
|
|
|
- new PublicKey(followerInfo.lbPairAddress)
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
await closeFollowerPosition(followerInfo.positionAddress)
|
|
await closeFollowerPosition(followerInfo.positionAddress)
|
|
|
await updateCopyTradeStatus(copyTrade.id, 'SUCCESS', {
|
|
await updateCopyTradeStatus(copyTrade.id, 'SUCCESS', {
|
|
|
followerTxSignature: followerTx,
|
|
followerTxSignature: followerTx,
|