@hawksightco/hawk-sdk 1.3.225 → 1.3.227

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -484,7 +484,8 @@ class Transactions {
484
484
  return mainInstructions;
485
485
  }
486
486
  catch (error) {
487
- if (error instanceof Error && error.message.includes('No liquidity to remove')) {
487
+ if (error instanceof Error &&
488
+ error.message.includes('No liquidity to remove')) {
488
489
  console.warn('No liquidity to remove, closing position instead.');
489
490
  const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
490
491
  const index = userPositions.findIndex(v => v.publicKey.equals(params.position));
@@ -634,8 +635,13 @@ class Transactions {
634
635
  return [result];
635
636
  }
636
637
  // ≥70 bins: multi-tx chunked withdraw
637
- const resolved = yield this._resolveWithdrawPoolData({ connection, lbPair });
638
- const amountBps = params.shouldClaimAndClose ? new bn_js_1.default(10000) : params.amountBps;
638
+ const resolved = yield this._resolveWithdrawPoolData({
639
+ connection,
640
+ lbPair,
641
+ });
642
+ const amountBps = params.shouldClaimAndClose
643
+ ? new bn_js_1.default(10000)
644
+ : params.amountBps;
639
645
  // Chunk into ≤149-bin ranges
640
646
  const CHUNK_SIZE = 149;
641
647
  const chunks = [];
@@ -663,7 +669,7 @@ class Transactions {
663
669
  * Call once, then pass the result to _buildWithdrawInstructions for each chunk.
664
670
  */
665
671
  _resolveWithdrawPoolData(_a) {
666
- return __awaiter(this, arguments, void 0, function* ({ connection, lbPair }) {
672
+ return __awaiter(this, arguments, void 0, function* ({ connection, lbPair, }) {
667
673
  // Create DLMM pool first — this also initializes MeteoraDLMM._program
668
674
  // so we don't need a separate MeteoraDLMM.program() call (which fetches a dummy pool).
669
675
  const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, lbPair, this.ix);
@@ -671,12 +677,22 @@ class Transactions {
671
677
  const lbPairState = dlmmPool.dlmm.lbPair;
672
678
  const tokenXMint = lbPairState.tokenXMint;
673
679
  const tokenYMint = lbPairState.tokenYMint;
674
- const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [tokenXMint, tokenYMint]);
680
+ const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [
681
+ tokenXMint,
682
+ tokenYMint,
683
+ ]);
675
684
  const tokenXProgram = tokenProgramMap[tokenXMint.toString()];
676
685
  const tokenYProgram = tokenProgramMap[tokenYMint.toString()];
677
686
  const remainingAccountsInfo = yield (0, functions_1.fetchRemainingAccountsInfo)(connection, tokenXMint, tokenYMint, tokenXProgram, tokenYProgram);
678
687
  const lbPairInfo = yield program.account.lbPair.fetch(lbPair);
679
- return { tokenXMint, tokenYMint, tokenXProgram, tokenYProgram, remainingAccountsInfo, lbPairInfo };
688
+ return {
689
+ tokenXMint,
690
+ tokenYMint,
691
+ tokenXProgram,
692
+ tokenYProgram,
693
+ remainingAccountsInfo,
694
+ lbPairInfo,
695
+ };
680
696
  });
681
697
  }
682
698
  /**
@@ -689,7 +705,8 @@ class Transactions {
689
705
  const mainInstructions = [];
690
706
  let userTokenX, userTokenY;
691
707
  const userPda = (0, functions_1.generateUserPda)(params.userWallet);
692
- if (params.pdaTokenType === types_1.TokenType.ATA || params.pdaTokenType === undefined) {
708
+ if (params.pdaTokenType === types_1.TokenType.ATA ||
709
+ params.pdaTokenType === undefined) {
693
710
  userTokenX = (0, functions_1.generateAta)(userPda, params.tokenXMint, params.tokenXProgram);
694
711
  userTokenY = (0, functions_1.generateAta)(userPda, params.tokenYMint, params.tokenYProgram);
695
712
  mainInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(params.userWallet, userTokenX, userPda, params.tokenXMint, params.tokenXProgram));
@@ -849,11 +866,18 @@ class Transactions {
849
866
  const totalBins = upperBinId - lowerBinId + 1;
850
867
  // ≤149 bins: single-tx path
851
868
  if (totalBins <= 149) {
852
- const result = yield this.meteoraClaim({ connection, params, fetch: undefined });
869
+ const result = yield this.meteoraClaim({
870
+ connection,
871
+ params,
872
+ fetch: undefined,
873
+ });
853
874
  return [result];
854
875
  }
855
876
  // ≥150 bins: multi-tx chunked claim
856
- const resolved = yield this._resolveWithdrawPoolData({ connection, lbPair });
877
+ const resolved = yield this._resolveWithdrawPoolData({
878
+ connection,
879
+ lbPair,
880
+ });
857
881
  // Chunk into ≤149-bin ranges
858
882
  const CHUNK_SIZE = 149;
859
883
  const chunks = [];
@@ -1123,7 +1147,7 @@ class Transactions {
1123
1147
  // Re-deposit fees (TODO: How to re-deposit reward tokens that is not X or Y token?)
1124
1148
  // Get slippage amount that returns a 10 bin slippage (meteora defaults to 3 bins if not provided)
1125
1149
  const binStep = yield dlmmPool.dlmm.lbPair.binStep;
1126
- let slippageAmount = Math.round(10 * (binStep / 100) * 100) / 100; // 2 decimal places round
1150
+ const slippageAmount = Math.round(10 * (binStep / 100) * 100) / 100; // 2 decimal places round
1127
1151
  const addLiquidityBuilder = yield dlmmPool.addLiquidityByStrategy(connection, params.userWallet, addresses_1.HS_AUTHORITY, {
1128
1152
  positionPubKey: params.position,
1129
1153
  user: userPda,
@@ -1199,7 +1223,7 @@ class Transactions {
1199
1223
  shouldClaimAndClose: false, // Do NOT close position
1200
1224
  }, hsToMeteora_1.meteoraToHawksightAutomationIxs);
1201
1225
  // Configure fee destination based on useAta
1202
- if (!!params.useAta) {
1226
+ if (params.useAta) {
1203
1227
  removeLiquidityBuilder.replaceClaimFeeTokenToATA();
1204
1228
  removeLiquidityBuilder.replaceClaimRewardToATA();
1205
1229
  }
@@ -1210,7 +1234,7 @@ class Transactions {
1210
1234
  // Step 2: Add liquidity back to the SAME position with specified distribution
1211
1235
  // Get slippage amount (10 bin slippage like compound)
1212
1236
  const binStep = dlmmPool.dlmm.lbPair.binStep;
1213
- let slippageAmount = Math.round(10 * (binStep / 100) * 100) / 100;
1237
+ const slippageAmount = Math.round(10 * (binStep / 100) * 100) / 100;
1214
1238
  const addLiquidityBuilder = yield dlmmPool.addLiquidityByStrategy(connection, params.userWallet, addresses_1.HS_AUTHORITY, {
1215
1239
  positionPubKey: params.position,
1216
1240
  user: userPda,
@@ -1274,7 +1298,7 @@ class Transactions {
1274
1298
  bps: new bn_js_1.default(10000),
1275
1299
  shouldClaimAndClose: false,
1276
1300
  }, hsToMeteora_1.meteoraToHawksightAutomationIxs);
1277
- if (!!params.useAta) {
1301
+ if (params.useAta) {
1278
1302
  removeLiquidityBuilder.replaceClaimFeeTokenToATA();
1279
1303
  removeLiquidityBuilder.replaceClaimRewardToATA();
1280
1304
  }
@@ -1287,7 +1311,10 @@ class Transactions {
1287
1311
  const activeBinId = lbPairState.activeId;
1288
1312
  const tokenXMint = lbPairState.tokenXMint;
1289
1313
  const tokenYMint = lbPairState.tokenYMint;
1290
- const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [tokenXMint, tokenYMint]);
1314
+ const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [
1315
+ tokenXMint,
1316
+ tokenYMint,
1317
+ ]);
1291
1318
  const tokenXProgram = tokenProgramMap[tokenXMint.toString()];
1292
1319
  const tokenYProgram = tokenProgramMap[tokenYMint.toString()];
1293
1320
  const relativeLower = position.lowerBinId - activeBinId;
@@ -1307,10 +1334,12 @@ class Transactions {
1307
1334
  upperRange: relativeUpper,
1308
1335
  },
1309
1336
  strategyType: types_3.StrategyTypeMap[params.distribution],
1310
- checkRange: params.checkRange ? {
1311
- lowerRange: params.checkRange.lowerRange,
1312
- upperRange: params.checkRange.upperRange,
1313
- } : undefined,
1337
+ checkRange: params.checkRange
1338
+ ? {
1339
+ lowerRange: params.checkRange.lowerRange,
1340
+ upperRange: params.checkRange.upperRange,
1341
+ }
1342
+ : undefined,
1314
1343
  });
1315
1344
  const mainInstructions = [
1316
1345
  ...removeLiquidityBuilder.createAtaIxs,
@@ -1396,13 +1425,20 @@ class Transactions {
1396
1425
  const binCount = upperBinId - lowerBinId + 1;
1397
1426
  // For ≤149 bins, delegate to existing single-TX claimAutomationIx
1398
1427
  if (binCount <= 149) {
1399
- const singleResult = yield this.claimAutomationIx({ connection, params, fetch: undefined });
1428
+ const singleResult = yield this.claimAutomationIx({
1429
+ connection,
1430
+ params,
1431
+ fetch: undefined,
1432
+ });
1400
1433
  return [singleResult];
1401
1434
  }
1402
1435
  // ≥150 bins: chunked multi-TX approach
1403
1436
  // Resolve pool data (tokens, programs, remaining accounts)
1404
- const resolved = yield this._resolveWithdrawPoolData({ connection, lbPair });
1405
- const { tokenXMint, tokenYMint, tokenXProgram, tokenYProgram, remainingAccountsInfo, lbPairInfo } = resolved;
1437
+ const resolved = yield this._resolveWithdrawPoolData({
1438
+ connection,
1439
+ lbPair,
1440
+ });
1441
+ const { tokenXMint, tokenYMint, tokenXProgram, tokenYProgram, remainingAccountsInfo, lbPairInfo, } = resolved;
1406
1442
  // Get reward infos from lbPair state
1407
1443
  const rewardInfos = lbPairInfo.rewardInfos;
1408
1444
  // Chunk [lowerBinId, upperBinId] into ≤149-bin pieces
@@ -1511,7 +1547,11 @@ class Transactions {
1511
1547
  const binCount = upperBinId - lowerBinId + 1;
1512
1548
  // For ≤70 bins, delegate to existing single-TX compoundAutomationIx
1513
1549
  if (binCount <= 70) {
1514
- const singleResult = yield this.compoundAutomationIx({ connection, params, fetch: undefined });
1550
+ const singleResult = yield this.compoundAutomationIx({
1551
+ connection,
1552
+ params,
1553
+ fetch: undefined,
1554
+ });
1515
1555
  return [singleResult];
1516
1556
  }
1517
1557
  // ≥150 bins: chunked multi-TX approach
@@ -1531,11 +1571,14 @@ class Transactions {
1531
1571
  const tokenXMint = lbPairState.tokenXMint;
1532
1572
  const tokenYMint = lbPairState.tokenYMint;
1533
1573
  const rewardInfos = lbPairState.rewardInfos;
1534
- const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [tokenXMint, tokenYMint]);
1574
+ const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [
1575
+ tokenXMint,
1576
+ tokenYMint,
1577
+ ]);
1535
1578
  const tokenXProgram = tokenProgramMap[tokenXMint.toString()];
1536
1579
  const tokenYProgram = tokenProgramMap[tokenYMint.toString()];
1537
1580
  const remainingAccountsInfo = yield (0, functions_1.fetchRemainingAccountsInfo)(connection, tokenXMint, tokenYMint, tokenXProgram, tokenYProgram);
1538
- const lbPairInfo = yield (program.account.lbPair.fetch(lbPair));
1581
+ const lbPairInfo = yield program.account.lbPair.fetch(lbPair);
1539
1582
  // =========================================================================
1540
1583
  // Phase 1: Chunked claim (to ATA for re-deposit)
1541
1584
  // =========================================================================
@@ -1605,9 +1648,18 @@ class Transactions {
1605
1648
  // Phase 2: Chunked re-deposit back into the same position
1606
1649
  // =========================================================================
1607
1650
  const distributionToStrategyType = {
1608
- 'SPOT': liquidityStrategy_1.StrategyType.SPOT, 'SPOT-IMBALANCED': liquidityStrategy_1.StrategyType.SPOT, 'SPOT-ONE-SIDE': liquidityStrategy_1.StrategyType.SPOT, 'SPOT-BALANCED': liquidityStrategy_1.StrategyType.SPOT,
1609
- 'CURVE': liquidityStrategy_1.StrategyType.CURVE, 'CURVE-IMBALANCED': liquidityStrategy_1.StrategyType.CURVE, 'CURVE-ONE-SIDE': liquidityStrategy_1.StrategyType.CURVE, 'CURVE-BALANCED': liquidityStrategy_1.StrategyType.CURVE,
1610
- 'BID-ASK': liquidityStrategy_1.StrategyType.BID_ASK, 'BID-ASK-IMBALANCED': liquidityStrategy_1.StrategyType.BID_ASK, 'BID-ASK-ONE-SIDE': liquidityStrategy_1.StrategyType.BID_ASK, 'BID-ASK-BALANCED': liquidityStrategy_1.StrategyType.BID_ASK,
1651
+ SPOT: liquidityStrategy_1.StrategyType.SPOT,
1652
+ 'SPOT-IMBALANCED': liquidityStrategy_1.StrategyType.SPOT,
1653
+ 'SPOT-ONE-SIDE': liquidityStrategy_1.StrategyType.SPOT,
1654
+ 'SPOT-BALANCED': liquidityStrategy_1.StrategyType.SPOT,
1655
+ CURVE: liquidityStrategy_1.StrategyType.CURVE,
1656
+ 'CURVE-IMBALANCED': liquidityStrategy_1.StrategyType.CURVE,
1657
+ 'CURVE-ONE-SIDE': liquidityStrategy_1.StrategyType.CURVE,
1658
+ 'CURVE-BALANCED': liquidityStrategy_1.StrategyType.CURVE,
1659
+ 'BID-ASK': liquidityStrategy_1.StrategyType.BID_ASK,
1660
+ 'BID-ASK-IMBALANCED': liquidityStrategy_1.StrategyType.BID_ASK,
1661
+ 'BID-ASK-ONE-SIDE': liquidityStrategy_1.StrategyType.BID_ASK,
1662
+ 'BID-ASK-BALANCED': liquidityStrategy_1.StrategyType.BID_ASK,
1611
1663
  };
1612
1664
  const strategyType = (_c = distributionToStrategyType[(_b = params.distribution) !== null && _b !== void 0 ? _b : 'SPOT-IMBALANCED']) !== null && _c !== void 0 ? _c : liquidityStrategy_1.StrategyType.SPOT;
1613
1665
  const { binId: activeId } = yield dlmmPool.dlmm.getActiveBin();
@@ -1678,7 +1730,7 @@ class Transactions {
1678
1730
  bps: new bn_js_1.default(10000),
1679
1731
  shouldClaimAndClose: true,
1680
1732
  }, hsToMeteora_1.meteoraToHawksightAutomationIxs);
1681
- if (!!params.useAta) {
1733
+ if (params.useAta) {
1682
1734
  removeLiquidityBuilder.replaceClaimFeeTokenToATA();
1683
1735
  removeLiquidityBuilder.replaceClaimRewardToATA();
1684
1736
  }
@@ -1756,7 +1808,7 @@ class Transactions {
1756
1808
  bps: new bn_js_1.default(10000),
1757
1809
  shouldClaimAndClose: true,
1758
1810
  }, hsToMeteora_1.meteoraToHawksightAutomationIxs);
1759
- if (!!params.useAta) {
1811
+ if (params.useAta) {
1760
1812
  removeLiquidityBuilder.replaceClaimFeeTokenToATA();
1761
1813
  removeLiquidityBuilder.replaceClaimRewardToATA();
1762
1814
  }
@@ -1825,7 +1877,13 @@ class Transactions {
1825
1877
  // --- Validate and normalize layers ---
1826
1878
  let layers;
1827
1879
  if (params.distribution && !params.layers) {
1828
- layers = [{ distribution: params.distribution, percentageX: 100, percentageY: 100 }];
1880
+ layers = [
1881
+ {
1882
+ distribution: params.distribution,
1883
+ percentageX: 100,
1884
+ percentageY: 100,
1885
+ },
1886
+ ];
1829
1887
  }
1830
1888
  else if (params.layers && !params.distribution) {
1831
1889
  layers = params.layers;
@@ -1859,11 +1917,16 @@ class Transactions {
1859
1917
  const tokenXMint = lbPairState.tokenXMint;
1860
1918
  const tokenYMint = lbPairState.tokenYMint;
1861
1919
  const rewardInfos = lbPairState.rewardInfos;
1862
- const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [tokenXMint, tokenYMint]);
1920
+ const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [
1921
+ tokenXMint,
1922
+ tokenYMint,
1923
+ ]);
1863
1924
  const tokenXProgram = tokenProgramMap[tokenXMint.toString()];
1864
1925
  const tokenYProgram = tokenProgramMap[tokenYMint.toString()];
1865
1926
  const remainingAccountsInfo = yield (0, functions_1.fetchRemainingAccountsInfo)(connection, tokenXMint, tokenYMint, tokenXProgram, tokenYProgram);
1866
- const pdaTokenTypeForClaimables = params.useAta ? types_1.TokenType.ATA : types_1.TokenType.STA;
1927
+ const pdaTokenTypeForClaimables = params.useAta
1928
+ ? types_1.TokenType.ATA
1929
+ : types_1.TokenType.STA;
1867
1930
  // Estimate total X/Y from position data (liquidity + fees)
1868
1931
  const estimatedTotalX = new bn_js_1.default(userPosition.positionData.totalXAmount).add(userPosition.positionData.feeX);
1869
1932
  const estimatedTotalY = new bn_js_1.default(userPosition.positionData.totalYAmount).add(userPosition.positionData.feeY);
@@ -1874,7 +1937,10 @@ class Transactions {
1874
1937
  userWallet: params.userWallet,
1875
1938
  lbPair,
1876
1939
  position: params.currentPosition,
1877
- tokenXMint, tokenYMint, tokenXProgram, tokenYProgram,
1940
+ tokenXMint,
1941
+ tokenYMint,
1942
+ tokenXProgram,
1943
+ tokenYProgram,
1878
1944
  fromBinId: currentLowerBinId,
1879
1945
  toBinId: currentUpperBinId,
1880
1946
  bpsToRemove: 10000,
@@ -1887,9 +1953,12 @@ class Transactions {
1887
1953
  userWallet: params.userWallet,
1888
1954
  lbPair,
1889
1955
  position: params.currentPosition,
1890
- tokenMintX: tokenXMint, tokenMintY: tokenYMint,
1891
- tokenProgramX: tokenXProgram, tokenProgramY: tokenYProgram,
1892
- lowerBinId: currentLowerBinId, upperBinId: currentUpperBinId,
1956
+ tokenMintX: tokenXMint,
1957
+ tokenMintY: tokenYMint,
1958
+ tokenProgramX: tokenXProgram,
1959
+ tokenProgramY: tokenYProgram,
1960
+ lowerBinId: currentLowerBinId,
1961
+ upperBinId: currentUpperBinId,
1893
1962
  pdaTokenType: pdaTokenTypeForClaimables,
1894
1963
  remainingAccountsInfo,
1895
1964
  });
@@ -1910,7 +1979,8 @@ class Transactions {
1910
1979
  rewardMint: rewardInfo.mint,
1911
1980
  rewardVault: rewardInfo.vault,
1912
1981
  tokenProgram: rewardTokenProgram,
1913
- lowerBinId: currentLowerBinId, upperBinId: currentUpperBinId,
1982
+ lowerBinId: currentLowerBinId,
1983
+ upperBinId: currentUpperBinId,
1914
1984
  pdaTokenType: types_1.TokenType.STA,
1915
1985
  remainingAccountsInfo: rewardRemainingAccountsInfo,
1916
1986
  });
@@ -1945,7 +2015,9 @@ class Transactions {
1945
2015
  optionalTokenXAmount = undefined; // sweep remaining
1946
2016
  }
1947
2017
  else {
1948
- optionalTokenXAmount = estimatedTotalX.mul(new bn_js_1.default(layer.percentageX)).div(new bn_js_1.default(100));
2018
+ optionalTokenXAmount = estimatedTotalX
2019
+ .mul(new bn_js_1.default(layer.percentageX))
2020
+ .div(new bn_js_1.default(100));
1949
2021
  }
1950
2022
  if (layer.percentageY === 0) {
1951
2023
  optionalTokenYAmount = new bn_js_1.default(0);
@@ -1954,7 +2026,9 @@ class Transactions {
1954
2026
  optionalTokenYAmount = undefined; // sweep remaining
1955
2027
  }
1956
2028
  else {
1957
- optionalTokenYAmount = estimatedTotalY.mul(new bn_js_1.default(layer.percentageY)).div(new bn_js_1.default(100));
2029
+ optionalTokenYAmount = estimatedTotalY
2030
+ .mul(new bn_js_1.default(layer.percentageY))
2031
+ .div(new bn_js_1.default(100));
1958
2032
  }
1959
2033
  return { optionalTokenXAmount, optionalTokenYAmount };
1960
2034
  };
@@ -1969,7 +2043,10 @@ class Transactions {
1969
2043
  relativeLowerBinId: params.relativeBinRange.lowerRange,
1970
2044
  relativeUpperBinId: params.relativeBinRange.upperRange,
1971
2045
  strategyType: firstStrategyType,
1972
- checkRange: { minBinId: params.checkRange.lowerRange, maxBinId: params.checkRange.upperRange },
2046
+ checkRange: {
2047
+ minBinId: params.checkRange.lowerRange,
2048
+ maxBinId: params.checkRange.upperRange,
2049
+ },
1973
2050
  targetActiveBin: (_b = params.targetActiveBin) !== null && _b !== void 0 ? _b : undefined,
1974
2051
  userTokenXAmount: firstAmounts.optionalTokenXAmount,
1975
2052
  userTokenYAmount: firstAmounts.optionalTokenYAmount,
@@ -1990,7 +2067,10 @@ class Transactions {
1990
2067
  userWallet: params.userWallet,
1991
2068
  lbPair,
1992
2069
  position: params.newPosition,
1993
- tokenXMint, tokenYMint, tokenXProgram, tokenYProgram,
2070
+ tokenXMint,
2071
+ tokenYMint,
2072
+ tokenXProgram,
2073
+ tokenYProgram,
1994
2074
  activeId: effectiveActiveId,
1995
2075
  maxActiveBinSlippage: 0,
1996
2076
  strategyParametersMinBinId: absLower,
@@ -2046,7 +2126,10 @@ class Transactions {
2046
2126
  const tokenYMint = lbPairState.tokenYMint;
2047
2127
  const rewardInfos = lbPairState.rewardInfos;
2048
2128
  // Get token programs for each mint
2049
- const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [tokenXMint, tokenYMint]);
2129
+ const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [
2130
+ tokenXMint,
2131
+ tokenYMint,
2132
+ ]);
2050
2133
  const tokenXProgram = tokenProgramMap[tokenXMint.toString()];
2051
2134
  const tokenYProgram = tokenProgramMap[tokenYMint.toString()];
2052
2135
  // Get position width
@@ -2058,7 +2141,9 @@ class Transactions {
2058
2141
  // Fetch remainingAccountsInfo for Token2022 transfer hooks (if any)
2059
2142
  const remainingAccountsInfo = yield (0, functions_1.fetchRemainingAccountsInfo)(connection, tokenXMint, tokenYMint, tokenXProgram, tokenYProgram);
2060
2143
  // Whether to compound during rebalance, or nope.
2061
- const pdaTokenTypeForClaimables = params.useAta ? types_1.TokenType.ATA : types_1.TokenType.STA;
2144
+ const pdaTokenTypeForClaimables = params.useAta
2145
+ ? types_1.TokenType.ATA
2146
+ : types_1.TokenType.STA;
2062
2147
  const transactions = [];
2063
2148
  // =========================================================================
2064
2149
  // Group 1 consists of remove liquidity, claim fees/rewards, close position,
@@ -2294,7 +2379,10 @@ class Transactions {
2294
2379
  const currentUpperBinId = userPosition.positionData.upperBinId;
2295
2380
  const tokenXMint = lbPairState.tokenXMint;
2296
2381
  const tokenYMint = lbPairState.tokenYMint;
2297
- const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [tokenXMint, tokenYMint]);
2382
+ const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [
2383
+ tokenXMint,
2384
+ tokenYMint,
2385
+ ]);
2298
2386
  const tokenXProgram = tokenProgramMap[tokenXMint.toString()];
2299
2387
  const tokenYProgram = tokenProgramMap[tokenYMint.toString()];
2300
2388
  const remainingAccountsInfo = yield (0, functions_1.fetchRemainingAccountsInfo)(connection, tokenXMint, tokenYMint, tokenXProgram, tokenYProgram);
@@ -2324,9 +2412,18 @@ class Transactions {
2324
2412
  totalYAmount: acc.totalYAmount.add(new bn_js_1.default(bin.positionYAmount)),
2325
2413
  }), { totalXAmount: new bn_js_1.default(0), totalYAmount: new bn_js_1.default(0) });
2326
2414
  const distributionToStrategyType = {
2327
- 'SPOT': liquidityStrategy_1.StrategyType.SPOT, 'SPOT-IMBALANCED': liquidityStrategy_1.StrategyType.SPOT, 'SPOT-ONE-SIDE': liquidityStrategy_1.StrategyType.SPOT, 'SPOT-BALANCED': liquidityStrategy_1.StrategyType.SPOT,
2328
- 'CURVE': liquidityStrategy_1.StrategyType.CURVE, 'CURVE-IMBALANCED': liquidityStrategy_1.StrategyType.CURVE, 'CURVE-ONE-SIDE': liquidityStrategy_1.StrategyType.CURVE, 'CURVE-BALANCED': liquidityStrategy_1.StrategyType.CURVE,
2329
- 'BID-ASK': liquidityStrategy_1.StrategyType.BID_ASK, 'BID-ASK-IMBALANCED': liquidityStrategy_1.StrategyType.BID_ASK, 'BID-ASK-ONE-SIDE': liquidityStrategy_1.StrategyType.BID_ASK, 'BID-ASK-BALANCED': liquidityStrategy_1.StrategyType.BID_ASK,
2415
+ SPOT: liquidityStrategy_1.StrategyType.SPOT,
2416
+ 'SPOT-IMBALANCED': liquidityStrategy_1.StrategyType.SPOT,
2417
+ 'SPOT-ONE-SIDE': liquidityStrategy_1.StrategyType.SPOT,
2418
+ 'SPOT-BALANCED': liquidityStrategy_1.StrategyType.SPOT,
2419
+ CURVE: liquidityStrategy_1.StrategyType.CURVE,
2420
+ 'CURVE-IMBALANCED': liquidityStrategy_1.StrategyType.CURVE,
2421
+ 'CURVE-ONE-SIDE': liquidityStrategy_1.StrategyType.CURVE,
2422
+ 'CURVE-BALANCED': liquidityStrategy_1.StrategyType.CURVE,
2423
+ 'BID-ASK': liquidityStrategy_1.StrategyType.BID_ASK,
2424
+ 'BID-ASK-IMBALANCED': liquidityStrategy_1.StrategyType.BID_ASK,
2425
+ 'BID-ASK-ONE-SIDE': liquidityStrategy_1.StrategyType.BID_ASK,
2426
+ 'BID-ASK-BALANCED': liquidityStrategy_1.StrategyType.BID_ASK,
2330
2427
  };
2331
2428
  const strategyType = (_b = distributionToStrategyType[params.distribution]) !== null && _b !== void 0 ? _b : liquidityStrategy_1.StrategyType.SPOT;
2332
2429
  // Deposit using chunked rebalanceLiquidityAutomation (handles >70 bins)
@@ -2419,16 +2516,30 @@ class Transactions {
2419
2516
  const tokenXMint = lbPairState.tokenXMint;
2420
2517
  const tokenYMint = lbPairState.tokenYMint;
2421
2518
  const rewardInfos = lbPairState.rewardInfos;
2422
- const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [tokenXMint, tokenYMint]);
2519
+ const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [
2520
+ tokenXMint,
2521
+ tokenYMint,
2522
+ ]);
2423
2523
  const tokenXProgram = tokenProgramMap[tokenXMint.toString()];
2424
2524
  const tokenYProgram = tokenProgramMap[tokenYMint.toString()];
2425
2525
  const remainingAccountsInfo = yield (0, functions_1.fetchRemainingAccountsInfo)(connection, tokenXMint, tokenYMint, tokenXProgram, tokenYProgram);
2426
- const pdaTokenTypeForClaimables = params.useAta ? types_1.TokenType.ATA : types_1.TokenType.STA;
2526
+ const pdaTokenTypeForClaimables = params.useAta
2527
+ ? types_1.TokenType.ATA
2528
+ : types_1.TokenType.STA;
2427
2529
  const { binId: activeId } = yield dlmmPool.dlmm.getActiveBin();
2428
2530
  const distributionToStrategyType = {
2429
- 'SPOT': liquidityStrategy_1.StrategyType.SPOT, 'SPOT-IMBALANCED': liquidityStrategy_1.StrategyType.SPOT, 'SPOT-ONE-SIDE': liquidityStrategy_1.StrategyType.SPOT, 'SPOT-BALANCED': liquidityStrategy_1.StrategyType.SPOT,
2430
- 'CURVE': liquidityStrategy_1.StrategyType.CURVE, 'CURVE-IMBALANCED': liquidityStrategy_1.StrategyType.CURVE, 'CURVE-ONE-SIDE': liquidityStrategy_1.StrategyType.CURVE, 'CURVE-BALANCED': liquidityStrategy_1.StrategyType.CURVE,
2431
- 'BID-ASK': liquidityStrategy_1.StrategyType.BID_ASK, 'BID-ASK-IMBALANCED': liquidityStrategy_1.StrategyType.BID_ASK, 'BID-ASK-ONE-SIDE': liquidityStrategy_1.StrategyType.BID_ASK, 'BID-ASK-BALANCED': liquidityStrategy_1.StrategyType.BID_ASK,
2531
+ SPOT: liquidityStrategy_1.StrategyType.SPOT,
2532
+ 'SPOT-IMBALANCED': liquidityStrategy_1.StrategyType.SPOT,
2533
+ 'SPOT-ONE-SIDE': liquidityStrategy_1.StrategyType.SPOT,
2534
+ 'SPOT-BALANCED': liquidityStrategy_1.StrategyType.SPOT,
2535
+ CURVE: liquidityStrategy_1.StrategyType.CURVE,
2536
+ 'CURVE-IMBALANCED': liquidityStrategy_1.StrategyType.CURVE,
2537
+ 'CURVE-ONE-SIDE': liquidityStrategy_1.StrategyType.CURVE,
2538
+ 'CURVE-BALANCED': liquidityStrategy_1.StrategyType.CURVE,
2539
+ 'BID-ASK': liquidityStrategy_1.StrategyType.BID_ASK,
2540
+ 'BID-ASK-IMBALANCED': liquidityStrategy_1.StrategyType.BID_ASK,
2541
+ 'BID-ASK-ONE-SIDE': liquidityStrategy_1.StrategyType.BID_ASK,
2542
+ 'BID-ASK-BALANCED': liquidityStrategy_1.StrategyType.BID_ASK,
2432
2543
  };
2433
2544
  const strategyType = (_b = distributionToStrategyType[params.distribution]) !== null && _b !== void 0 ? _b : liquidityStrategy_1.StrategyType.SPOT;
2434
2545
  // =========================================================================
@@ -2440,7 +2551,10 @@ class Transactions {
2440
2551
  userWallet: params.userWallet,
2441
2552
  lbPair,
2442
2553
  position: params.currentPosition,
2443
- tokenXMint, tokenYMint, tokenXProgram, tokenYProgram,
2554
+ tokenXMint,
2555
+ tokenYMint,
2556
+ tokenXProgram,
2557
+ tokenYProgram,
2444
2558
  fromBinId: currentLowerBinId,
2445
2559
  toBinId: currentUpperBinId,
2446
2560
  bpsToRemove: 10000,
@@ -2452,9 +2566,12 @@ class Transactions {
2452
2566
  userWallet: params.userWallet,
2453
2567
  lbPair,
2454
2568
  position: params.currentPosition,
2455
- tokenMintX: tokenXMint, tokenMintY: tokenYMint,
2456
- tokenProgramX: tokenXProgram, tokenProgramY: tokenYProgram,
2457
- lowerBinId: currentLowerBinId, upperBinId: currentUpperBinId,
2569
+ tokenMintX: tokenXMint,
2570
+ tokenMintY: tokenYMint,
2571
+ tokenProgramX: tokenXProgram,
2572
+ tokenProgramY: tokenYProgram,
2573
+ lowerBinId: currentLowerBinId,
2574
+ upperBinId: currentUpperBinId,
2458
2575
  pdaTokenType: pdaTokenTypeForClaimables,
2459
2576
  remainingAccountsInfo,
2460
2577
  });
@@ -2474,7 +2591,8 @@ class Transactions {
2474
2591
  rewardMint: rewardInfo.mint,
2475
2592
  rewardVault: rewardInfo.vault,
2476
2593
  tokenProgram: rewardTokenProgram,
2477
- lowerBinId: currentLowerBinId, upperBinId: currentUpperBinId,
2594
+ lowerBinId: currentLowerBinId,
2595
+ upperBinId: currentUpperBinId,
2478
2596
  pdaTokenType: types_1.TokenType.STA,
2479
2597
  remainingAccountsInfo: rewardRemainingAccountsInfo,
2480
2598
  });
@@ -2535,7 +2653,10 @@ class Transactions {
2535
2653
  userWallet: params.userWallet,
2536
2654
  lbPair,
2537
2655
  position: params.newPosition,
2538
- tokenXMint, tokenYMint, tokenXProgram, tokenYProgram,
2656
+ tokenXMint,
2657
+ tokenYMint,
2658
+ tokenXProgram,
2659
+ tokenYProgram,
2539
2660
  lowerBinId: newLowerBinId,
2540
2661
  upperBinId: newUpperBinId,
2541
2662
  strategyType,
@@ -2606,13 +2727,21 @@ class Transactions {
2606
2727
  const currentBinCount = currentUpperBinId - currentLowerBinId + 1;
2607
2728
  // For ≤70 bins, delegate to existing rebalanceSmallPositionAutomation
2608
2729
  if (currentBinCount <= 70 && params.width <= 70) {
2609
- return this.rebalanceSmallPositionAutomation({ connection, params, fetch: undefined });
2730
+ return this.rebalanceSmallPositionAutomation({
2731
+ connection,
2732
+ params,
2733
+ fetch: undefined,
2734
+ });
2610
2735
  }
2611
2736
  // For ≤149 target bins, use phased approach (separate withdraw/deposit TXs).
2612
2737
  // Only the target width is constrained (deposit must fit in one 149-bin chunk).
2613
2738
  // The withdraw TX handles any current position size via full-range removeLiquidity.
2614
2739
  if (params.width <= 149) {
2615
- return this.rebalancePhasedPositionAutomation({ connection, params, fetch: undefined });
2740
+ return this.rebalancePhasedPositionAutomation({
2741
+ connection,
2742
+ params,
2743
+ fetch: undefined,
2744
+ });
2616
2745
  }
2617
2746
  // ≥150 bins: multi-TX chunked approach
2618
2747
  const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, lbPair, this.ix);
@@ -2632,21 +2761,35 @@ class Transactions {
2632
2761
  const tokenXMint = lbPairState.tokenXMint;
2633
2762
  const tokenYMint = lbPairState.tokenYMint;
2634
2763
  const rewardInfos = lbPairState.rewardInfos;
2635
- const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [tokenXMint, tokenYMint]);
2764
+ const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [
2765
+ tokenXMint,
2766
+ tokenYMint,
2767
+ ]);
2636
2768
  const tokenXProgram = tokenProgramMap[tokenXMint.toString()];
2637
2769
  const tokenYProgram = tokenProgramMap[tokenYMint.toString()];
2638
2770
  const remainingAccountsInfo = yield (0, functions_1.fetchRemainingAccountsInfo)(connection, tokenXMint, tokenYMint, tokenXProgram, tokenYProgram);
2639
- const lbPairInfo = yield (program.account.lbPair.fetch(lbPair));
2771
+ const lbPairInfo = yield program.account.lbPair.fetch(lbPair);
2640
2772
  // Whether to compound during rebalance, or nope.
2641
- const pdaTokenTypeForClaimables = params.useAta ? types_1.TokenType.ATA : types_1.TokenType.STA;
2773
+ const pdaTokenTypeForClaimables = params.useAta
2774
+ ? types_1.TokenType.ATA
2775
+ : types_1.TokenType.STA;
2642
2776
  // =========================================================================
2643
2777
  // Merged approach: withdraw + init/extend + deposit per TX (~74-bins each)
2644
2778
  // =========================================================================
2645
2779
  const { binId: activeId } = yield dlmmPool.dlmm.getActiveBin();
2646
2780
  const distributionToStrategyType = {
2647
- 'SPOT': liquidityStrategy_1.StrategyType.SPOT, 'SPOT-IMBALANCED': liquidityStrategy_1.StrategyType.SPOT, 'SPOT-ONE-SIDE': liquidityStrategy_1.StrategyType.SPOT, 'SPOT-BALANCED': liquidityStrategy_1.StrategyType.SPOT,
2648
- 'CURVE': liquidityStrategy_1.StrategyType.CURVE, 'CURVE-IMBALANCED': liquidityStrategy_1.StrategyType.CURVE, 'CURVE-ONE-SIDE': liquidityStrategy_1.StrategyType.CURVE, 'CURVE-BALANCED': liquidityStrategy_1.StrategyType.CURVE,
2649
- 'BID-ASK': liquidityStrategy_1.StrategyType.BID_ASK, 'BID-ASK-IMBALANCED': liquidityStrategy_1.StrategyType.BID_ASK, 'BID-ASK-ONE-SIDE': liquidityStrategy_1.StrategyType.BID_ASK, 'BID-ASK-BALANCED': liquidityStrategy_1.StrategyType.BID_ASK,
2781
+ SPOT: liquidityStrategy_1.StrategyType.SPOT,
2782
+ 'SPOT-IMBALANCED': liquidityStrategy_1.StrategyType.SPOT,
2783
+ 'SPOT-ONE-SIDE': liquidityStrategy_1.StrategyType.SPOT,
2784
+ 'SPOT-BALANCED': liquidityStrategy_1.StrategyType.SPOT,
2785
+ CURVE: liquidityStrategy_1.StrategyType.CURVE,
2786
+ 'CURVE-IMBALANCED': liquidityStrategy_1.StrategyType.CURVE,
2787
+ 'CURVE-ONE-SIDE': liquidityStrategy_1.StrategyType.CURVE,
2788
+ 'CURVE-BALANCED': liquidityStrategy_1.StrategyType.CURVE,
2789
+ 'BID-ASK': liquidityStrategy_1.StrategyType.BID_ASK,
2790
+ 'BID-ASK-IMBALANCED': liquidityStrategy_1.StrategyType.BID_ASK,
2791
+ 'BID-ASK-ONE-SIDE': liquidityStrategy_1.StrategyType.BID_ASK,
2792
+ 'BID-ASK-BALANCED': liquidityStrategy_1.StrategyType.BID_ASK,
2650
2793
  };
2651
2794
  const strategyType = (_b = distributionToStrategyType[params.distribution]) !== null && _b !== void 0 ? _b : liquidityStrategy_1.StrategyType.SPOT;
2652
2795
  const binStep = new bn_js_1.default(dlmmPool.dlmm.lbPair.binStep);
@@ -2673,7 +2816,7 @@ class Transactions {
2673
2816
  activeId,
2674
2817
  totalXAmount,
2675
2818
  totalYAmount,
2676
- chunkSize: 73
2819
+ chunkSize: 73,
2677
2820
  });
2678
2821
  // Wrap each instruction array with createTransactionMeta
2679
2822
  const transactions = [];
@@ -2730,7 +2873,10 @@ class Transactions {
2730
2873
  const lbPairState = dlmmPool.dlmm.lbPair;
2731
2874
  const tokenXMint = lbPairState.tokenXMint;
2732
2875
  const tokenYMint = lbPairState.tokenYMint;
2733
- const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [tokenXMint, tokenYMint]);
2876
+ const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [
2877
+ tokenXMint,
2878
+ tokenYMint,
2879
+ ]);
2734
2880
  const tokenXProgram = tokenProgramMap[tokenXMint.toString()];
2735
2881
  const tokenYProgram = tokenProgramMap[tokenYMint.toString()];
2736
2882
  // Fetch transfer hook accounts for token X and Y (Token2022 support)
@@ -2743,8 +2889,14 @@ class Transactions {
2743
2889
  // Always add TransferHookX and TransferHookY slices (even if length=0)
2744
2890
  const xSlice = baseRemainingAccountsInfo.slices.find(s => s.accountsType === types_1.RemainingAccountsType.TransferHookX);
2745
2891
  const ySlice = baseRemainingAccountsInfo.slices.find(s => s.accountsType === types_1.RemainingAccountsType.TransferHookY);
2746
- combinedSlices.push({ accountsType: types_1.RemainingAccountsType.TransferHookX, length: (_b = xSlice === null || xSlice === void 0 ? void 0 : xSlice.length) !== null && _b !== void 0 ? _b : 0 });
2747
- combinedSlices.push({ accountsType: types_1.RemainingAccountsType.TransferHookY, length: (_c = ySlice === null || ySlice === void 0 ? void 0 : ySlice.length) !== null && _c !== void 0 ? _c : 0 });
2892
+ combinedSlices.push({
2893
+ accountsType: types_1.RemainingAccountsType.TransferHookX,
2894
+ length: (_b = xSlice === null || xSlice === void 0 ? void 0 : xSlice.length) !== null && _b !== void 0 ? _b : 0,
2895
+ });
2896
+ combinedSlices.push({
2897
+ accountsType: types_1.RemainingAccountsType.TransferHookY,
2898
+ length: (_c = ySlice === null || ySlice === void 0 ? void 0 : ySlice.length) !== null && _c !== void 0 ? _c : 0,
2899
+ });
2748
2900
  // Add transfer hook accounts from base (for X and Y)
2749
2901
  combinedAccounts.push(...baseRemainingAccountsInfo.accounts);
2750
2902
  const remainingAccountsInfo = {
@@ -2752,12 +2904,16 @@ class Transactions {
2752
2904
  accounts: combinedAccounts,
2753
2905
  };
2754
2906
  return {
2755
- instructions: [yield this.ix.meteoraDlmm.rebalanceLiquidityAutomation({
2907
+ instructions: [
2908
+ yield this.ix.meteoraDlmm.rebalanceLiquidityAutomation({
2756
2909
  connection,
2757
2910
  userWallet: params.userWallet,
2758
2911
  position: params.position,
2759
2912
  lbPair: params.lbPair,
2760
- tokenXMint, tokenYMint, tokenXProgram, tokenYProgram,
2913
+ tokenXMint,
2914
+ tokenYMint,
2915
+ tokenXProgram,
2916
+ tokenYProgram,
2761
2917
  activeId: params.activeId,
2762
2918
  pdaTokenType: types_1.TokenType.ATA,
2763
2919
  maxActiveBinSlippage: 0,
@@ -2771,7 +2927,8 @@ class Transactions {
2771
2927
  addLiquidityParams: params.addLiquidityParams,
2772
2928
  shrinkMode: types_3.ShrinkMode.NoShrinkBoth,
2773
2929
  remainingAccountsInfo,
2774
- })],
2930
+ }),
2931
+ ],
2775
2932
  labels: ['rebalance_liquidity'],
2776
2933
  };
2777
2934
  });
@@ -2938,7 +3095,7 @@ class Transactions {
2938
3095
  // Add liquidity via rebalanceLiquidityAutomation
2939
3096
  // Use u64::MAX for maxDeposit amounts so they don't cap the deposit.
2940
3097
  // The on-chain program uses ATA balance for actual amounts; these are just safety ceilings.
2941
- const U64_MAX = new bn_js_1.default("18446744073709551615");
3098
+ const U64_MAX = new bn_js_1.default('18446744073709551615');
2942
3099
  const depositIx = yield this.ix.meteoraDlmm.rebalanceLiquidityAutomation({
2943
3100
  connection,
2944
3101
  userWallet,
@@ -2958,7 +3115,8 @@ class Transactions {
2958
3115
  minWithdrawYAmount: new bn_js_1.default(0),
2959
3116
  maxDepositYAmount: U64_MAX,
2960
3117
  removeLiquidityParams: [],
2961
- addLiquidityParams: [{
3118
+ addLiquidityParams: [
3119
+ {
2962
3120
  minDeltaId: chunk.minDeltaId.toNumber(),
2963
3121
  maxDeltaId: chunk.maxDeltaId.toNumber(),
2964
3122
  x0: onChainParams.x0,
@@ -2967,7 +3125,8 @@ class Transactions {
2967
3125
  deltaY: onChainParams.deltaY,
2968
3126
  bitFlag: onChainParams.bitFlag,
2969
3127
  favorXInActiveId,
2970
- }],
3128
+ },
3129
+ ],
2971
3130
  });
2972
3131
  instructions.push(depositIx);
2973
3132
  txInstructions.push(instructions);
@@ -3068,7 +3227,7 @@ class Transactions {
3068
3227
  // === Withdraw from old position ===
3069
3228
  if (i < oldChunks.length) {
3070
3229
  const chunk = oldChunks[i];
3071
- const isLastOldChunk = (i === oldChunks.length - 1);
3230
+ const isLastOldChunk = i === oldChunks.length - 1;
3072
3231
  const removeLiquidityIx = yield this.ix.meteoraDlmm.removeLiquidityByRange2Automation({
3073
3232
  connection,
3074
3233
  userWallet,
@@ -3157,7 +3316,8 @@ class Transactions {
3157
3316
  minWithdrawYAmount: new bn_js_1.default(0),
3158
3317
  maxDepositYAmount: chunk.maxAmountY,
3159
3318
  removeLiquidityParams: [],
3160
- addLiquidityParams: [{
3319
+ addLiquidityParams: [
3320
+ {
3161
3321
  minDeltaId: chunk.minDeltaId.toNumber(),
3162
3322
  maxDeltaId: chunk.maxDeltaId.toNumber(),
3163
3323
  x0: onChainParams.x0,
@@ -3166,7 +3326,8 @@ class Transactions {
3166
3326
  deltaY: onChainParams.deltaY,
3167
3327
  bitFlag: onChainParams.bitFlag,
3168
3328
  favorXInActiveId,
3169
- }],
3329
+ },
3330
+ ],
3170
3331
  });
3171
3332
  instructions.push(depositIx);
3172
3333
  }
@@ -3212,7 +3373,7 @@ class Transactions {
3212
3373
  }
3213
3374
  relativeOpenAutomationIx(_a) {
3214
3375
  return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
3215
- const { userWallet, pool, position, relativeBinRange, checkRange, distribution, targetActiveBin, fuelAccount, pdaTokenType, userTokenXAmount, userTokenYAmount } = params;
3376
+ const { userWallet, pool, position, relativeBinRange, checkRange, distribution, targetActiveBin, fuelAccount, pdaTokenType, userTokenXAmount, userTokenYAmount, } = params;
3216
3377
  const openParams = {
3217
3378
  userWallet,
3218
3379
  lbPair: pool,
@@ -3309,8 +3470,7 @@ class Transactions {
3309
3470
  catch (error) {
3310
3471
  throw new Error(`Failed to generate bin IDs for position (lowerBinId: ${position.lowerBinId}, upperBinId: ${position.upperBinId}): ${error}`);
3311
3472
  }
3312
- const totalLiquidity = position.liquidityShares
3313
- .reduce((acc, bn) => acc.add(bn), new bn_js_1.default(0));
3473
+ const totalLiquidity = position.liquidityShares.reduce((acc, bn) => acc.add(bn), new bn_js_1.default(0));
3314
3474
  let mainInstructions;
3315
3475
  if (totalLiquidity.gt(new bn_js_1.default(0))) {
3316
3476
  let removeLiquidityBuilder;
@@ -3330,9 +3490,7 @@ class Transactions {
3330
3490
  throw new Error(`Failed to generate remove liquidity from position tx ${params.position}: ${error}`);
3331
3491
  }
3332
3492
  try {
3333
- mainInstructions = [
3334
- ...removeLiquidityBuilder.mainIxs,
3335
- ];
3493
+ mainInstructions = [...removeLiquidityBuilder.mainIxs];
3336
3494
  }
3337
3495
  catch (error) {
3338
3496
  throw new Error(`Failed to build main instructions: ${error}`);
@@ -3343,7 +3501,10 @@ class Transactions {
3343
3501
  const tokenXMint = lbPairState.tokenXMint;
3344
3502
  const tokenYMint = lbPairState.tokenYMint;
3345
3503
  const rewardInfos = lbPairState.rewardInfos;
3346
- const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [tokenXMint, tokenYMint]);
3504
+ const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [
3505
+ tokenXMint,
3506
+ tokenYMint,
3507
+ ]);
3347
3508
  const tokenXProgram = tokenProgramMap[tokenXMint.toString()];
3348
3509
  const tokenYProgram = tokenProgramMap[tokenYMint.toString()];
3349
3510
  const remainingAccountsInfo = yield (0, functions_1.fetchRemainingAccountsInfo)(connection, tokenXMint, tokenYMint, tokenXProgram, tokenYProgram);
@@ -3433,7 +3594,7 @@ class Transactions {
3433
3594
  const iyfProgram = addresses_1.IYF_MAIN;
3434
3595
  const hawksightAuthority = addresses_1.HS_AUTHORITY;
3435
3596
  const { params: _params, data: chunkData } = this.removeLiquidityByRange2Info(ixs);
3436
- let { position: _position, lbPair, binArrayBitmapExtension, reserveX, reserveY, tokenXMint, tokenYMint, sender, tokenXProgram, tokenYProgram, memoProgram, eventAuthority, program: meteoraDlmmProgram, binArrays: _binArrays, } = _params;
3597
+ const { position: _position, lbPair, binArrayBitmapExtension, reserveX, reserveY, tokenXMint, tokenYMint, sender, tokenXProgram, tokenYProgram, memoProgram, eventAuthority, program: meteoraDlmmProgram, binArrays: _binArrays, } = _params;
3437
3598
  // Reconstruct param data with full position range (not just first chunk)
3438
3599
  const fromBinIdBuf = Buffer.alloc(4);
3439
3600
  fromBinIdBuf.writeInt32LE(position.lowerBinId, 0);
@@ -3442,7 +3603,12 @@ class Transactions {
3442
3603
  const bpsBuf = Buffer.alloc(2);
3443
3604
  bpsBuf.writeUInt16LE(10000, 0);
3444
3605
  const remainingAccountsInfoBytes = chunkData.length > 10 ? chunkData.slice(10) : Buffer.alloc(0);
3445
- const data = Buffer.concat([fromBinIdBuf, toBinIdBuf, bpsBuf, remainingAccountsInfoBytes]);
3606
+ const data = Buffer.concat([
3607
+ fromBinIdBuf,
3608
+ toBinIdBuf,
3609
+ bpsBuf,
3610
+ remainingAccountsInfoBytes,
3611
+ ]);
3446
3612
  // Derive bin arrays for the full position range
3447
3613
  const binArrays = this.ix.pda.meteora.deriveBinArrays(lbPair.pubkey, position.lowerBinId, position.upperBinId);
3448
3614
  let ix;
@@ -3533,7 +3699,7 @@ class Transactions {
3533
3699
  }
3534
3700
  limitCloseAutomationIx2(_a) {
3535
3701
  return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
3536
- return errors_1.UniversalErrorHandler.catchErrorsAsync(`limitCloseAutomationIx2`, () => __awaiter(this, void 0, void 0, function* () {
3702
+ return errors_1.UniversalErrorHandler.catchErrorsAsync('limitCloseAutomationIx2', () => __awaiter(this, void 0, void 0, function* () {
3537
3703
  const program = yield errors_1.AppError.handleErrorAsync(() => __awaiter(this, void 0, void 0, function* () { return yield meteora_1.MeteoraDLMM.program(connection); }));
3538
3704
  const position = yield errors_1.AppError.handleErrorAsync(() => __awaiter(this, void 0, void 0, function* () { return yield program.account.positionV2.fetch(params.position); }));
3539
3705
  const dlmmPool = yield errors_1.AppError.handleErrorAsync(() => __awaiter(this, void 0, void 0, function* () { return yield meteora_1.MeteoraDLMM.create(connection, position.lbPair, this.ix); }));
@@ -3556,7 +3722,7 @@ class Transactions {
3556
3722
  const iyfProgram = addresses_1.IYF_MAIN;
3557
3723
  const hawksightAuthority = addresses_1.HS_AUTHORITY;
3558
3724
  const { params: _params, data: chunkData } = this.removeLiquidityByRange2Info(ixs);
3559
- let { position: _position, lbPair, binArrayBitmapExtension, reserveX, reserveY, tokenXMint, tokenYMint, sender, tokenXProgram, tokenYProgram, memoProgram, eventAuthority, program: meteoraDlmmProgram, binArrays: _binArrays, } = _params;
3725
+ const { position: _position, lbPair, binArrayBitmapExtension, reserveX, reserveY, tokenXMint, tokenYMint, sender, tokenXProgram, tokenYProgram, memoProgram, eventAuthority, program: meteoraDlmmProgram, binArrays: _binArrays, } = _params;
3560
3726
  // Reconstruct param data with full position range (not just first chunk)
3561
3727
  const fromBinIdBuf = Buffer.alloc(4);
3562
3728
  fromBinIdBuf.writeInt32LE(position.lowerBinId, 0);
@@ -3565,7 +3731,12 @@ class Transactions {
3565
3731
  const bpsBuf = Buffer.alloc(2);
3566
3732
  bpsBuf.writeUInt16LE(10000, 0);
3567
3733
  const remainingAccountsInfoBytes = chunkData.length > 10 ? chunkData.slice(10) : Buffer.alloc(0);
3568
- const data = Buffer.concat([fromBinIdBuf, toBinIdBuf, bpsBuf, remainingAccountsInfoBytes]);
3734
+ const data = Buffer.concat([
3735
+ fromBinIdBuf,
3736
+ toBinIdBuf,
3737
+ bpsBuf,
3738
+ remainingAccountsInfoBytes,
3739
+ ]);
3569
3740
  // Derive bin arrays for the full position range
3570
3741
  const binArrays = this.ix.pda.meteora.deriveBinArrays(lbPair.pubkey, position.lowerBinId, position.upperBinId);
3571
3742
  let ix;
@@ -3682,7 +3853,7 @@ class Transactions {
3682
3853
  };
3683
3854
  }
3684
3855
  }
3685
- throw new Error(`Unexpected error: Cannot find "RemoveLiquidityByRange" or "RemoveLiquidityByRange2" instruction from instructions`);
3856
+ throw new Error('Unexpected error: Cannot find "RemoveLiquidityByRange" or "RemoveLiquidityByRange2" instruction from instructions');
3686
3857
  }
3687
3858
  removeLiquidityByRange2Info(ixs) {
3688
3859
  for (const ix of ixs) {
@@ -3713,7 +3884,7 @@ class Transactions {
3713
3884
  };
3714
3885
  }
3715
3886
  }
3716
- throw new Error(`Unexpected error: Cannot find "RemoveLiquidityByRange" or "RemoveLiquidityByRange2" instruction from instructions`);
3887
+ throw new Error('Unexpected error: Cannot find "RemoveLiquidityByRange" or "RemoveLiquidityByRange2" instruction from instructions');
3717
3888
  }
3718
3889
  /**
3719
3890
  * Creates a large position with more than 69 bins.
@@ -3792,7 +3963,10 @@ class Transactions {
3792
3963
  }
3793
3964
  meteoraInitializeLargePosition(_a) {
3794
3965
  return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
3795
- const txInstructions = yield this._meteoraInitializeLargePosition({ connection, params });
3966
+ const txInstructions = yield this._meteoraInitializeLargePosition({
3967
+ connection,
3968
+ params,
3969
+ });
3796
3970
  const transactions = [];
3797
3971
  for (const instructions of txInstructions) {
3798
3972
  transactions.push(yield (0, functions_1.createTransactionMeta2)({
@@ -3878,7 +4052,7 @@ class Transactions {
3878
4052
  })).map(ix => {
3879
4053
  return {
3880
4054
  instruction: ix,
3881
- label: `Initialize bin arrays for bins ${chunk.lowerBinId} to ${chunk.upperBinId}`
4055
+ label: `Initialize bin arrays for bins ${chunk.lowerBinId} to ${chunk.upperBinId}`,
3882
4056
  };
3883
4057
  });
3884
4058
  instructions.push(...initBinArraysIx);
@@ -3903,7 +4077,8 @@ class Transactions {
3903
4077
  minWithdrawYAmount: new bn_js_1.default(0),
3904
4078
  maxDepositYAmount: chunk.maxAmountY,
3905
4079
  removeLiquidityParams: [], // No removal
3906
- addLiquidityParams: [{
4080
+ addLiquidityParams: [
4081
+ {
3907
4082
  minDeltaId: chunk.minDeltaId.toNumber(),
3908
4083
  maxDeltaId: chunk.maxDeltaId.toNumber(),
3909
4084
  x0: onChainParams.x0,
@@ -3912,11 +4087,12 @@ class Transactions {
3912
4087
  deltaY: onChainParams.deltaY,
3913
4088
  bitFlag: onChainParams.bitFlag,
3914
4089
  favorXInActiveId,
3915
- }],
4090
+ },
4091
+ ],
3916
4092
  });
3917
4093
  instructions.push({
3918
4094
  instruction: depositIx,
3919
- label: `Deposit liquidity to bins ${chunk.lowerBinId} to ${chunk.upperBinId} via rebalanceLiquidity`
4095
+ label: `Deposit liquidity to bins ${chunk.lowerBinId} to ${chunk.upperBinId} via rebalanceLiquidity`,
3920
4096
  });
3921
4097
  txInstructions.push(instructions);
3922
4098
  }
@@ -3978,17 +4154,31 @@ class Transactions {
3978
4154
  const lbPairState = dlmmPool.dlmm.lbPair;
3979
4155
  const tokenXMint = lbPairState.tokenXMint;
3980
4156
  const tokenYMint = lbPairState.tokenYMint;
3981
- const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [tokenXMint, tokenYMint]);
4157
+ const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [
4158
+ tokenXMint,
4159
+ tokenYMint,
4160
+ ]);
3982
4161
  const tokenXProgram = tokenProgramMap[tokenXMint.toString()];
3983
4162
  const tokenYProgram = tokenProgramMap[tokenYMint.toString()];
3984
4163
  // Convert Distribution to liquidityStrategy.StrategyType
3985
4164
  const distributionToStrategyType = {
3986
- 'SPOT': liquidityStrategy_1.StrategyType.SPOT, 'SPOT-IMBALANCED': liquidityStrategy_1.StrategyType.SPOT, 'SPOT-ONE-SIDE': liquidityStrategy_1.StrategyType.SPOT, 'SPOT-BALANCED': liquidityStrategy_1.StrategyType.SPOT,
3987
- 'CURVE': liquidityStrategy_1.StrategyType.CURVE, 'CURVE-IMBALANCED': liquidityStrategy_1.StrategyType.CURVE, 'CURVE-ONE-SIDE': liquidityStrategy_1.StrategyType.CURVE, 'CURVE-BALANCED': liquidityStrategy_1.StrategyType.CURVE,
3988
- 'BID-ASK': liquidityStrategy_1.StrategyType.BID_ASK, 'BID-ASK-IMBALANCED': liquidityStrategy_1.StrategyType.BID_ASK, 'BID-ASK-ONE-SIDE': liquidityStrategy_1.StrategyType.BID_ASK, 'BID-ASK-BALANCED': liquidityStrategy_1.StrategyType.BID_ASK,
4165
+ SPOT: liquidityStrategy_1.StrategyType.SPOT,
4166
+ 'SPOT-IMBALANCED': liquidityStrategy_1.StrategyType.SPOT,
4167
+ 'SPOT-ONE-SIDE': liquidityStrategy_1.StrategyType.SPOT,
4168
+ 'SPOT-BALANCED': liquidityStrategy_1.StrategyType.SPOT,
4169
+ CURVE: liquidityStrategy_1.StrategyType.CURVE,
4170
+ 'CURVE-IMBALANCED': liquidityStrategy_1.StrategyType.CURVE,
4171
+ 'CURVE-ONE-SIDE': liquidityStrategy_1.StrategyType.CURVE,
4172
+ 'CURVE-BALANCED': liquidityStrategy_1.StrategyType.CURVE,
4173
+ 'BID-ASK': liquidityStrategy_1.StrategyType.BID_ASK,
4174
+ 'BID-ASK-IMBALANCED': liquidityStrategy_1.StrategyType.BID_ASK,
4175
+ 'BID-ASK-ONE-SIDE': liquidityStrategy_1.StrategyType.BID_ASK,
4176
+ 'BID-ASK-BALANCED': liquidityStrategy_1.StrategyType.BID_ASK,
3989
4177
  };
3990
4178
  const strategyType = (_b = distributionToStrategyType[params.distribution]) !== null && _b !== void 0 ? _b : liquidityStrategy_1.StrategyType.SPOT;
3991
- const txInstructions = yield this._meteoraDepositToLargePosition({ connection, params: {
4179
+ const txInstructions = yield this._meteoraDepositToLargePosition({
4180
+ connection,
4181
+ params: {
3992
4182
  userWallet: params.userWallet,
3993
4183
  lbPair,
3994
4184
  position: params.position,
@@ -4002,7 +4192,8 @@ class Transactions {
4002
4192
  totalYAmount: params.totalYAmount,
4003
4193
  strategyType,
4004
4194
  pdaTokenType: params.pdaTokenType,
4005
- } });
4195
+ },
4196
+ });
4006
4197
  const transactions = [];
4007
4198
  for (let i = 0; i < txInstructions.length; i++) {
4008
4199
  transactions.push(yield (0, functions_1.createTransactionMeta2)({
@@ -4050,15 +4241,24 @@ class Transactions {
4050
4241
  payer: params.userWallet,
4051
4242
  addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
4052
4243
  mainInstructions: [...mainInstructions],
4053
- })
4244
+ }),
4054
4245
  ];
4055
4246
  }
4056
4247
  // ≥150 bins: multi-tx path
4057
4248
  // Convert Distribution string to liquidityStrategy.StrategyType number for chunked deposit
4058
4249
  const distributionToStrategyType = {
4059
- 'SPOT': liquidityStrategy_1.StrategyType.SPOT, 'SPOT-IMBALANCED': liquidityStrategy_1.StrategyType.SPOT, 'SPOT-ONE-SIDE': liquidityStrategy_1.StrategyType.SPOT, 'SPOT-BALANCED': liquidityStrategy_1.StrategyType.SPOT,
4060
- 'CURVE': liquidityStrategy_1.StrategyType.CURVE, 'CURVE-IMBALANCED': liquidityStrategy_1.StrategyType.CURVE, 'CURVE-ONE-SIDE': liquidityStrategy_1.StrategyType.CURVE, 'CURVE-BALANCED': liquidityStrategy_1.StrategyType.CURVE,
4061
- 'BID-ASK': liquidityStrategy_1.StrategyType.BID_ASK, 'BID-ASK-IMBALANCED': liquidityStrategy_1.StrategyType.BID_ASK, 'BID-ASK-ONE-SIDE': liquidityStrategy_1.StrategyType.BID_ASK, 'BID-ASK-BALANCED': liquidityStrategy_1.StrategyType.BID_ASK,
4250
+ SPOT: liquidityStrategy_1.StrategyType.SPOT,
4251
+ 'SPOT-IMBALANCED': liquidityStrategy_1.StrategyType.SPOT,
4252
+ 'SPOT-ONE-SIDE': liquidityStrategy_1.StrategyType.SPOT,
4253
+ 'SPOT-BALANCED': liquidityStrategy_1.StrategyType.SPOT,
4254
+ CURVE: liquidityStrategy_1.StrategyType.CURVE,
4255
+ 'CURVE-IMBALANCED': liquidityStrategy_1.StrategyType.CURVE,
4256
+ 'CURVE-ONE-SIDE': liquidityStrategy_1.StrategyType.CURVE,
4257
+ 'CURVE-BALANCED': liquidityStrategy_1.StrategyType.CURVE,
4258
+ 'BID-ASK': liquidityStrategy_1.StrategyType.BID_ASK,
4259
+ 'BID-ASK-IMBALANCED': liquidityStrategy_1.StrategyType.BID_ASK,
4260
+ 'BID-ASK-ONE-SIDE': liquidityStrategy_1.StrategyType.BID_ASK,
4261
+ 'BID-ASK-BALANCED': liquidityStrategy_1.StrategyType.BID_ASK,
4062
4262
  };
4063
4263
  const strategyType = (_b = distributionToStrategyType[params.distribution]) !== null && _b !== void 0 ? _b : liquidityStrategy_1.StrategyType.SPOT;
4064
4264
  // Step 1: Initialize position
@@ -4077,7 +4277,10 @@ class Transactions {
4077
4277
  const lbPairState = dlmmPool.dlmm.lbPair;
4078
4278
  const tokenXMint = lbPairState.tokenXMint;
4079
4279
  const tokenYMint = lbPairState.tokenYMint;
4080
- const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [tokenXMint, tokenYMint]);
4280
+ const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [
4281
+ tokenXMint,
4282
+ tokenYMint,
4283
+ ]);
4081
4284
  const tokenXProgram = tokenProgramMap[tokenXMint.toString()];
4082
4285
  const tokenYProgram = tokenProgramMap[tokenYMint.toString()];
4083
4286
  // Step 3: Build deposit instructions
@@ -4104,15 +4307,17 @@ class Transactions {
4104
4307
  const initIdempotent = (mint, label) => {
4105
4308
  return {
4106
4309
  instruction: (0, functions_1.createAtaIdempotentIxs)({
4107
- accounts: [{
4310
+ accounts: [
4311
+ {
4108
4312
  payer: params.userWallet,
4109
4313
  mint,
4110
4314
  owner: params.userWallet,
4111
4315
  programId: tokenProgramMap[mint.toString()],
4112
- }]
4316
+ },
4317
+ ],
4113
4318
  })[0],
4114
4319
  label: `Idempotently initialize zero-amount ATA for ${label} mint`,
4115
- class: `initZeroAmountAtaLabeled`,
4320
+ class: 'initZeroAmountAtaLabeled',
4116
4321
  };
4117
4322
  };
4118
4323
  const initAtaIxs = [];
@@ -4190,6 +4395,248 @@ class Transactions {
4190
4395
  return transactions;
4191
4396
  });
4192
4397
  }
4398
+ _meteoraDepositHybridToLargePosition(_a) {
4399
+ return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
4400
+ const MAX_BINS_PER_TX = 149;
4401
+ const { userWallet, lbPair, position, tokenXMint, tokenYMint, tokenXProgram, tokenYProgram, lowerBinId, upperBinId, totalXAmount, totalYAmount, layers, pdaTokenType, } = params;
4402
+ const favorXInActiveId = totalYAmount.isZero() && !totalXAmount.isZero();
4403
+ const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, lbPair, this.ix);
4404
+ const { binId: activeId } = yield dlmmPool.dlmm.getActiveBin();
4405
+ const binStep = new bn_js_1.default(dlmmPool.dlmm.lbPair.binStep);
4406
+ const minDeltaId = new bn_js_1.default(lowerBinId - activeId);
4407
+ const maxDeltaId = new bn_js_1.default(upperBinId - activeId);
4408
+ const strategyResults = (0, liquidityStrategy_1.distributionToHybridStrategy)({
4409
+ hybridDistribution: layers,
4410
+ amountX: totalXAmount,
4411
+ amountY: totalYAmount,
4412
+ minDeltaId,
4413
+ maxDeltaId,
4414
+ binStep,
4415
+ activeId: new bn_js_1.default(activeId),
4416
+ });
4417
+ const chunks = (0, liquidityStrategy_1.chunkHybridDepositParameters)(strategyResults, minDeltaId, maxDeltaId, new bn_js_1.default(activeId), binStep, MAX_BINS_PER_TX, favorXInActiveId);
4418
+ const txInstructions = [];
4419
+ const depositInstructions = [];
4420
+ const deposits = [];
4421
+ deposits.push({ mint: tokenXMint, amount: totalXAmount });
4422
+ deposits.push({ mint: tokenYMint, amount: totalYAmount });
4423
+ const wrapSolIx = (0, functions_1.wrapSolIfMintIsWsolLabeled)(userWallet, userWallet, deposits);
4424
+ depositInstructions.push(...wrapSolIx);
4425
+ if (deposits.length > 0) {
4426
+ depositInstructions.push(yield this.ix.iyfMain.depositMultipleTokenWithToken2022WithLabel({
4427
+ connection,
4428
+ payer: userWallet,
4429
+ deposit: deposits,
4430
+ pdaTokenType,
4431
+ }));
4432
+ }
4433
+ let depositIncluded = false;
4434
+ if (wrapSolIx.length > 0) {
4435
+ depositIncluded = true;
4436
+ txInstructions.push(depositInstructions);
4437
+ }
4438
+ for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) {
4439
+ const chunk = chunks[chunkIndex];
4440
+ const mergedLayer = chunk.layers.reduce((acc, l) => ({
4441
+ x0: acc.x0.add(l.params.x0),
4442
+ y0: acc.y0.add(l.params.y0),
4443
+ deltaX: acc.deltaX.add(l.params.deltaX),
4444
+ deltaY: acc.deltaY.add(l.params.deltaY),
4445
+ }), { x0: new bn_js_1.default(0), y0: new bn_js_1.default(0), deltaX: new bn_js_1.default(0), deltaY: new bn_js_1.default(0) });
4446
+ const onChainParams = (0, liquidityStrategy_1.buildBitFlagAndNegateStrategyParameters)(mergedLayer.x0, mergedLayer.y0, mergedLayer.deltaX, mergedLayer.deltaY);
4447
+ const mergedBinsAmounts = (0, liquidityStrategy_1.toAmountIntoBins)(new bn_js_1.default(activeId), chunk.minDeltaId, chunk.maxDeltaId, mergedLayer.deltaX, mergedLayer.deltaY, mergedLayer.x0, mergedLayer.y0, binStep, favorXInActiveId);
4448
+ const chunkMaxX = mergedBinsAmounts.reduce((s, b) => s.add(b.amountX), new bn_js_1.default(0));
4449
+ const chunkMaxY = mergedBinsAmounts.reduce((s, b) => s.add(b.amountY), new bn_js_1.default(0));
4450
+ const instructions = [];
4451
+ if (!depositIncluded) {
4452
+ depositIncluded = true;
4453
+ instructions.push(...depositInstructions);
4454
+ }
4455
+ const initBinArraysIx = (yield this.ix.meteoraDlmm.meteoraDlmmInitializeBinArrayDefault({
4456
+ connection,
4457
+ userWallet,
4458
+ lbPair,
4459
+ lowerBinId: chunk.lowerBinId,
4460
+ upperBinId: chunk.upperBinId,
4461
+ })).map(ix => ({
4462
+ instruction: ix,
4463
+ label: `Initialize bin arrays for bins ${chunk.lowerBinId} to ${chunk.upperBinId}`,
4464
+ }));
4465
+ instructions.push(...initBinArraysIx);
4466
+ const depositIx = yield this.ix.meteoraDlmm.rebalanceLiquidity({
4467
+ connection,
4468
+ userWallet,
4469
+ position,
4470
+ lbPair,
4471
+ tokenXMint,
4472
+ tokenYMint,
4473
+ tokenXProgram,
4474
+ tokenYProgram,
4475
+ activeId,
4476
+ pdaTokenType,
4477
+ maxActiveBinSlippage: 0,
4478
+ shouldClaimFee: false,
4479
+ shouldClaimReward: false,
4480
+ minWithdrawXAmount: new bn_js_1.default(0),
4481
+ maxDepositXAmount: chunkMaxX,
4482
+ minWithdrawYAmount: new bn_js_1.default(0),
4483
+ maxDepositYAmount: chunkMaxY,
4484
+ removeLiquidityParams: [],
4485
+ addLiquidityParams: [
4486
+ {
4487
+ minDeltaId: chunk.minDeltaId.toNumber(),
4488
+ maxDeltaId: chunk.maxDeltaId.toNumber(),
4489
+ x0: onChainParams.x0,
4490
+ y0: onChainParams.y0,
4491
+ deltaX: onChainParams.deltaX,
4492
+ deltaY: onChainParams.deltaY,
4493
+ bitFlag: onChainParams.bitFlag,
4494
+ favorXInActiveId,
4495
+ },
4496
+ ],
4497
+ });
4498
+ instructions.push({
4499
+ instruction: depositIx,
4500
+ label: `Hybrid deposit to bins ${chunk.lowerBinId} to ${chunk.upperBinId} via rebalanceLiquidity`,
4501
+ });
4502
+ txInstructions.push(instructions);
4503
+ }
4504
+ return txInstructions;
4505
+ });
4506
+ }
4507
+ meteoraDepositHybridToLargePosition(_a) {
4508
+ return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
4509
+ const txInstructions = yield this._meteoraDepositHybridToLargePosition({
4510
+ connection,
4511
+ params,
4512
+ });
4513
+ const transactions = [];
4514
+ for (const ixGroup of txInstructions) {
4515
+ transactions.push(yield (0, functions_1.createTransactionMeta2)({
4516
+ payer: params.userWallet,
4517
+ addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
4518
+ mainInstructions: ixGroup,
4519
+ }));
4520
+ }
4521
+ return transactions;
4522
+ });
4523
+ }
4524
+ meteoraCreatePositionAndDepositHybridToLargePosition(_a) {
4525
+ return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
4526
+ const lowerBinId = params.binRange.lowerRange;
4527
+ const upperBinId = params.binRange.upperRange;
4528
+ const initTxs = yield this._meteoraInitializeLargePosition({
4529
+ connection,
4530
+ params: {
4531
+ userWallet: params.userWallet,
4532
+ lbPair: params.pool,
4533
+ position: params.position,
4534
+ lowerBinId,
4535
+ upperBinId,
4536
+ },
4537
+ });
4538
+ const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, params.pool, this.ix);
4539
+ const lbPairState = dlmmPool.dlmm.lbPair;
4540
+ const tokenXMint = lbPairState.tokenXMint;
4541
+ const tokenYMint = lbPairState.tokenYMint;
4542
+ const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [
4543
+ tokenXMint,
4544
+ tokenYMint,
4545
+ ]);
4546
+ const tokenXProgram = tokenProgramMap[tokenXMint.toString()];
4547
+ const tokenYProgram = tokenProgramMap[tokenYMint.toString()];
4548
+ const depositTxs = yield this._meteoraDepositHybridToLargePosition({
4549
+ connection,
4550
+ params: {
4551
+ userWallet: params.userWallet,
4552
+ lbPair: params.pool,
4553
+ position: params.position,
4554
+ tokenXMint,
4555
+ tokenYMint,
4556
+ tokenXProgram,
4557
+ tokenYProgram,
4558
+ lowerBinId,
4559
+ upperBinId,
4560
+ totalXAmount: params.totalXAmount,
4561
+ totalYAmount: params.totalYAmount,
4562
+ layers: params.layers,
4563
+ pdaTokenType: params.pdaTokenType,
4564
+ },
4565
+ });
4566
+ const initIdempotent = (mint, label) => ({
4567
+ instruction: (0, functions_1.createAtaIdempotentIxs)({
4568
+ accounts: [
4569
+ {
4570
+ payer: params.userWallet,
4571
+ mint,
4572
+ owner: params.userWallet,
4573
+ programId: tokenProgramMap[mint.toString()],
4574
+ },
4575
+ ],
4576
+ })[0],
4577
+ label: `Idempotently initialize zero-amount ATA for ${label} mint`,
4578
+ class: 'initZeroAmountAtaLabeled',
4579
+ });
4580
+ const initAtaIxs = [];
4581
+ if (params.totalXAmount.isZero()) {
4582
+ initAtaIxs.push(initIdempotent(tokenXMint, 'X'));
4583
+ }
4584
+ else if (params.totalYAmount.isZero()) {
4585
+ initAtaIxs.push(initIdempotent(tokenYMint, 'Y'));
4586
+ }
4587
+ const wrapSolIxs = [];
4588
+ const depositToPdaIxs = [];
4589
+ // Moving wrap SOL instruction from depositTxs to initTxs
4590
+ for (let i = 0; i < depositTxs.length; i++) {
4591
+ for (let j = depositTxs[i].length - 1; j >= 0; j--) {
4592
+ const labelledIx = depositTxs[i][j];
4593
+ const classification = labelledIx.class;
4594
+ if (classification === 'wrapSolToWsolLabeled') {
4595
+ wrapSolIxs.push(labelledIx);
4596
+ depositTxs[i].splice(j, 1);
4597
+ }
4598
+ if (classification === 'depositMultipleTokenWithToken2022WithLabel') {
4599
+ depositToPdaIxs.push(labelledIx);
4600
+ depositTxs[i].splice(j, 1);
4601
+ }
4602
+ if (depositTxs[i].length === 0) {
4603
+ depositTxs.splice(i, 1);
4604
+ break;
4605
+ }
4606
+ }
4607
+ }
4608
+ // Add wrap SOL instructions to the end of the last init transaction (correct order)
4609
+ initTxs[initTxs.length - 1].push(...initAtaIxs, ...wrapSolIxs.reverse(), ...depositToPdaIxs.reverse());
4610
+ // Assemble — merge init's last TX into deposit's first TX if init has >1 TX
4611
+ const assembled = [];
4612
+ if (initTxs.length > 1) {
4613
+ for (let i = 0; i < initTxs.length - 1; i++) {
4614
+ assembled.push(initTxs[i]);
4615
+ }
4616
+ const lastInitTx = initTxs[initTxs.length - 1];
4617
+ const firstDepositTx = depositTxs[0];
4618
+ assembled.push([...lastInitTx, ...firstDepositTx]);
4619
+ for (let i = 1; i < depositTxs.length; i++) {
4620
+ assembled.push(depositTxs[i]);
4621
+ }
4622
+ }
4623
+ else {
4624
+ assembled.push(initTxs[0]);
4625
+ for (const tx of depositTxs) {
4626
+ assembled.push(tx);
4627
+ }
4628
+ }
4629
+ const transactions = [];
4630
+ for (const ixGroup of assembled) {
4631
+ transactions.push(yield (0, functions_1.createTransactionMeta2)({
4632
+ payer: params.userWallet,
4633
+ addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
4634
+ mainInstructions: ixGroup,
4635
+ }));
4636
+ }
4637
+ return transactions;
4638
+ });
4639
+ }
4193
4640
  /**
4194
4641
  * Deposit liquidity to a Meteora DLMM position (up to 128 bins) with optional position initialization.
4195
4642
  *
@@ -4224,7 +4671,7 @@ class Transactions {
4224
4671
  if (initializePosition) {
4225
4672
  if (totalBins <= MAX_INIT_WIDTH) {
4226
4673
  // Simple case: <= 70 bins - use initializePositionAndAddLiquidityByStrategy
4227
- const initPositionAndAddLiquidityIxsObj = (yield dlmmPool.initializePositionAndAddLiquidityByStrategy(connection, userWallet, userWallet, {
4674
+ const initPositionAndAddLiquidityIxsObj = yield dlmmPool.initializePositionAndAddLiquidityByStrategy(connection, userWallet, userWallet, {
4228
4675
  positionPubKey: position,
4229
4676
  totalXAmount,
4230
4677
  totalYAmount,
@@ -4239,7 +4686,7 @@ class Transactions {
4239
4686
  opt: {
4240
4687
  pdaTokenType,
4241
4688
  },
4242
- }, hsToMeteora_1.meteoraToHawksight));
4689
+ }, hsToMeteora_1.meteoraToHawksight);
4243
4690
  const initPositionAndAddLiquidityIxs = [
4244
4691
  // Step 1: Init wSOL token account for user wallet (if X or Y token is wSOL)
4245
4692
  ...initPositionAndAddLiquidityIxsObj.wrapSolIxs.map(ix => {
@@ -4314,7 +4761,7 @@ class Transactions {
4314
4761
  });
4315
4762
  instructions.push({
4316
4763
  instruction: initializePositionIx,
4317
- label: `Initialize position for bins ${initWidth}`
4764
+ label: `Initialize position for bins ${initWidth}`,
4318
4765
  });
4319
4766
  // Step 2b: Extend position to cover all bins
4320
4767
  let currentUpperBinId = lowerBinId + initWidth - 1;
@@ -4331,12 +4778,12 @@ class Transactions {
4331
4778
  });
4332
4779
  instructions.push({
4333
4780
  instruction: extendIx,
4334
- label: `Extend position by ${binsToAdd} bins to cover up to bin ${currentUpperBinId + binsToAdd}`
4781
+ label: `Extend position by ${binsToAdd} bins to cover up to bin ${currentUpperBinId + binsToAdd}`,
4335
4782
  });
4336
4783
  currentUpperBinId += binsToAdd;
4337
4784
  }
4338
4785
  // Step 2c: Add liquidity to the full position
4339
- const addLiquidityIxsObj = (yield dlmmPool.addLiquidityByStrategy(connection, userWallet, userWallet, {
4786
+ const addLiquidityIxsObj = yield dlmmPool.addLiquidityByStrategy(connection, userWallet, userWallet, {
4340
4787
  positionPubKey: position,
4341
4788
  totalXAmount,
4342
4789
  totalYAmount,
@@ -4349,7 +4796,7 @@ class Transactions {
4349
4796
  slippage,
4350
4797
  skipInputTokenCheck,
4351
4798
  pdaTokenType,
4352
- }, hsToMeteora_1.meteoraToHawksight));
4799
+ }, hsToMeteora_1.meteoraToHawksight);
4353
4800
  const addLiquidityIxs = [
4354
4801
  // Step 1: Init wSOL token account for user wallet (if X or Y token is wSOL)
4355
4802
  ...addLiquidityIxsObj.wrapSolIxs.map(ix => {
@@ -4368,14 +4815,15 @@ class Transactions {
4368
4815
  const initializeBinArraySighash = (0, functions_1.sighash)('initialize_bin_array');
4369
4816
  const ixSighash = ix.data.subarray(0, 8);
4370
4817
  const isInitBinArray = Buffer.from(ixSighash).equals(Buffer.from(initializeBinArraySighash));
4371
- if (!ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM) || ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM) && isInitBinArray)
4818
+ if (!ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM) ||
4819
+ (ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM) && isInitBinArray))
4372
4820
  return {
4373
4821
  instruction: ix,
4374
4822
  label: '',
4375
4823
  };
4376
4824
  return {
4377
4825
  instruction: ix,
4378
- label: `Add liquidity by strategy (meteora deposit)`
4826
+ label: 'Add liquidity by strategy (meteora deposit)'
4379
4827
  };
4380
4828
  }),
4381
4829
  ];
@@ -4393,7 +4841,7 @@ class Transactions {
4393
4841
  }
4394
4842
  else {
4395
4843
  // Just add liquidity to existing position
4396
- const addLiquidityIxsObj = (yield dlmmPool.addLiquidityByStrategy(connection, userWallet, userWallet, {
4844
+ const addLiquidityIxsObj = yield dlmmPool.addLiquidityByStrategy(connection, userWallet, userWallet, {
4397
4845
  positionPubKey: position,
4398
4846
  totalXAmount,
4399
4847
  totalYAmount,
@@ -4406,7 +4854,7 @@ class Transactions {
4406
4854
  slippage,
4407
4855
  skipInputTokenCheck,
4408
4856
  pdaTokenType,
4409
- }, hsToMeteora_1.meteoraToHawksight));
4857
+ }, hsToMeteora_1.meteoraToHawksight);
4410
4858
  const addLiquidityIxs = [
4411
4859
  // Step 1: Init wSOL token account for user wallet (if X or Y token is wSOL)
4412
4860
  ...addLiquidityIxsObj.wrapSolIxs.map(ix => {
@@ -4986,7 +5434,7 @@ class Transactions {
4986
5434
  const ownerFeeB = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, mintB);
4987
5435
  const [oracle] = web3.PublicKey.findProgramAddressSync([anchor.utils.bytes.utf8.encode('oracle'), whirlpool.toBuffer()], addresses_1.ORCA_WHIRLPOOL_PROGRAM);
4988
5436
  // TODO: Derive based on amountToSwap calculation
4989
- let aToB = params.aToB;
5437
+ const aToB = params.aToB;
4990
5438
  const tickArrays = whirlpools_sdk_1.SwapUtils.getTickArrayPublicKeys(whirlpoolData.tickCurrentIndex, whirlpoolData.tickSpacing, aToB, addresses_1.ORCA_WHIRLPOOL_PROGRAM, whirlpool);
4991
5439
  // Step 1: Init wSOL token account for user wallet (if X or Y token is wSOL)
4992
5440
  // const wrapSolIx = wrapSolIfMintIsWsol(params.userWallet, params.userWallet, [
@@ -5367,7 +5815,7 @@ class Transactions {
5367
5815
  associatedTokenProgram: addresses_1.ASSOCIATED_TOKEN_PROGRAM,
5368
5816
  })
5369
5817
  .instruction();
5370
- let orcaCloseIx = yield anchor_1.Anchor.instance()
5818
+ const orcaCloseIx = yield anchor_1.Anchor.instance()
5371
5819
  .iyfMain.methods.iyfExtensionExecute(extensionIx.data)
5372
5820
  .accounts({
5373
5821
  farm,
@@ -5539,11 +5987,11 @@ class Transactions {
5539
5987
  // Get the Raydium SDK instance
5540
5988
  const sdk = (0, RaydiumSDK_1.raydium)();
5541
5989
  // Get the pool keys (for lookup table account)
5542
- (0, functions_1.benchmark)({ name: `raydiumOpenPosition`, msg: `sdk.clmm.getClmmPoolKeys` });
5990
+ (0, functions_1.benchmark)({ name: 'raydiumOpenPosition', msg: 'sdk.clmm.getClmmPoolKeys' });
5543
5991
  const poolKeys = yield sdk.clmm.getClmmPoolKeys(params.poolState.toString());
5544
5992
  (0, functions_1.benchmark)({
5545
- name: `raydiumOpenPosition`,
5546
- msg: `sdk.clmm.getClmmPoolKeys`,
5993
+ name: 'raydiumOpenPosition',
5994
+ msg: 'sdk.clmm.getClmmPoolKeys',
5547
5995
  end: true,
5548
5996
  });
5549
5997
  const addressLookupTableAddresses = [];
@@ -5619,7 +6067,7 @@ class Transactions {
5619
6067
  ];
5620
6068
  return yield (0, functions_1.createTransactionMeta)({
5621
6069
  payer: params.userWallet,
5622
- description: `Open Raydium Position`,
6070
+ description: 'Open Raydium Position',
5623
6071
  addressLookupTableAddresses: [
5624
6072
  ...addresses_1.GLOBAL_ALT,
5625
6073
  ...addressLookupTableAddresses,
@@ -5647,13 +6095,13 @@ class Transactions {
5647
6095
  const sdk = (0, RaydiumSDK_1.raydium)();
5648
6096
  // Get the pool keys (for lookup table account)
5649
6097
  (0, functions_1.benchmark)({
5650
- name: `raydiumWithdrawAndClosePosition`,
5651
- msg: `sdk.clmm.getClmmPoolKeys`,
6098
+ name: 'raydiumWithdrawAndClosePosition',
6099
+ msg: 'sdk.clmm.getClmmPoolKeys',
5652
6100
  });
5653
6101
  const poolKeys = yield sdk.clmm.getClmmPoolKeys(fetch.positionInfo.poolId.toString());
5654
6102
  (0, functions_1.benchmark)({
5655
- name: `raydiumWithdrawAndClosePosition`,
5656
- msg: `sdk.clmm.getClmmPoolKeys`,
6103
+ name: 'raydiumWithdrawAndClosePosition',
6104
+ msg: 'sdk.clmm.getClmmPoolKeys',
5657
6105
  end: true,
5658
6106
  });
5659
6107
  const addressLookupTableAddresses = [];
@@ -5715,7 +6163,7 @@ class Transactions {
5715
6163
  ];
5716
6164
  return (0, functions_1.createTransactionMeta)({
5717
6165
  payer: params.userWallet,
5718
- description: `Close Raydium Position`,
6166
+ description: 'Close Raydium Position',
5719
6167
  addressLookupTableAddresses: [
5720
6168
  ...addresses_1.GLOBAL_ALT,
5721
6169
  ...addressLookupTableAddresses,
@@ -5734,7 +6182,7 @@ class Transactions {
5734
6182
  ];
5735
6183
  return (0, functions_1.createTransactionMeta)({
5736
6184
  payer: params.userWallet,
5737
- description: `Withdraw and close Raydium Position`,
6185
+ description: 'Withdraw and close Raydium Position',
5738
6186
  addressLookupTableAddresses: [
5739
6187
  ...addresses_1.GLOBAL_ALT,
5740
6188
  ...addressLookupTableAddresses,
@@ -5767,7 +6215,7 @@ class Transactions {
5767
6215
  ];
5768
6216
  return (0, functions_1.createTransactionMeta)({
5769
6217
  payer: params.userWallet,
5770
- description: `Close Raydium Position`,
6218
+ description: 'Close Raydium Position',
5771
6219
  addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
5772
6220
  mainInstructions,
5773
6221
  });
@@ -5793,13 +6241,13 @@ class Transactions {
5793
6241
  const sdk = (0, RaydiumSDK_1.raydium)();
5794
6242
  // Get the pool keys (for lookup table account)
5795
6243
  (0, functions_1.benchmark)({
5796
- name: `raydiumIncreaseLiquidity`,
5797
- msg: `sdk.clmm.getClmmPoolKeys`,
6244
+ name: 'raydiumIncreaseLiquidity',
6245
+ msg: 'sdk.clmm.getClmmPoolKeys',
5798
6246
  });
5799
6247
  const poolKeys = yield sdk.clmm.getClmmPoolKeys(fetch.positionInfo.poolId.toString());
5800
6248
  (0, functions_1.benchmark)({
5801
- name: `raydiumIncreaseLiquidity`,
5802
- msg: `sdk.clmm.getClmmPoolKeys`,
6249
+ name: 'raydiumIncreaseLiquidity',
6250
+ msg: 'sdk.clmm.getClmmPoolKeys',
5803
6251
  end: true,
5804
6252
  });
5805
6253
  const addressLookupTableAddresses = [];
@@ -5853,7 +6301,7 @@ class Transactions {
5853
6301
  ];
5854
6302
  return (0, functions_1.createTransactionMeta)({
5855
6303
  payer: params.userWallet,
5856
- description: `Raydium increase liquidity`,
6304
+ description: 'Raydium increase liquidity',
5857
6305
  addressLookupTableAddresses: [
5858
6306
  ...addresses_1.GLOBAL_ALT,
5859
6307
  ...addressLookupTableAddresses,
@@ -5880,13 +6328,13 @@ class Transactions {
5880
6328
  const sdk = (0, RaydiumSDK_1.raydium)();
5881
6329
  // Get the pool keys (for lookup table account)
5882
6330
  (0, functions_1.benchmark)({
5883
- name: `raydiumDecreaseLiquidity`,
5884
- msg: `sdk.clmm.getClmmPoolKeys`,
6331
+ name: 'raydiumDecreaseLiquidity',
6332
+ msg: 'sdk.clmm.getClmmPoolKeys',
5885
6333
  });
5886
6334
  const poolKeys = yield sdk.clmm.getClmmPoolKeys(fetch.positionInfo.poolId.toString());
5887
6335
  (0, functions_1.benchmark)({
5888
- name: `raydiumDecreaseLiquidity`,
5889
- msg: `sdk.clmm.getClmmPoolKeys`,
6336
+ name: 'raydiumDecreaseLiquidity',
6337
+ msg: 'sdk.clmm.getClmmPoolKeys',
5890
6338
  end: true,
5891
6339
  });
5892
6340
  const addressLookupTableAddresses = [];
@@ -5939,7 +6387,7 @@ class Transactions {
5939
6387
  ];
5940
6388
  return (0, functions_1.createTransactionMeta)({
5941
6389
  payer: params.userWallet,
5942
- description: `Raydium decrease liquidity`,
6390
+ description: 'Raydium decrease liquidity',
5943
6391
  addressLookupTableAddresses: [
5944
6392
  ...addresses_1.GLOBAL_ALT,
5945
6393
  ...addressLookupTableAddresses,
@@ -5983,7 +6431,8 @@ class Transactions {
5983
6431
  targetActiveBin: params.targetActiveBin,
5984
6432
  });
5985
6433
  // checkRange validation
5986
- if (activeId < params.checkRange.lowerRange || activeId > params.checkRange.upperRange) {
6434
+ if (activeId < params.checkRange.lowerRange ||
6435
+ activeId > params.checkRange.upperRange) {
5987
6436
  throw new Error(`Active bin ${activeId} outside checkRange [${params.checkRange.lowerRange}, ${params.checkRange.upperRange}]`);
5988
6437
  }
5989
6438
  const newLowerBinId = activeId + params.relativeBinRange.lowerRange;
@@ -5998,13 +6447,13 @@ class Transactions {
5998
6447
  if (currentWidth <= MAX_BINS_PER_WITHDRAW_CHUNK) {
5999
6448
  // Small/medium: single withdraw TX
6000
6449
  teardownTxGroups.push([
6001
- ...yield withdrawFn({
6450
+ ...(yield withdrawFn({
6002
6451
  position: params.currentPosition,
6003
6452
  minBinId: currentLowerBinId,
6004
6453
  maxBinId: currentUpperBinId,
6005
6454
  compound: params.compound,
6006
6455
  origin: CLASS,
6007
- }),
6456
+ })),
6008
6457
  {
6009
6458
  label: 'close_position',
6010
6459
  class: CLASS,
@@ -6024,13 +6473,13 @@ class Transactions {
6024
6473
  const chunk = withdrawChunks[i];
6025
6474
  const isLast = i === withdrawChunks.length - 1;
6026
6475
  const chunkIxs = [
6027
- ...yield withdrawFn({
6476
+ ...(yield withdrawFn({
6028
6477
  position: params.currentPosition,
6029
6478
  minBinId: chunk.lowerBinId,
6030
6479
  maxBinId: chunk.upperBinId,
6031
6480
  compound: params.compound,
6032
6481
  origin: CLASS,
6033
- }),
6482
+ })),
6034
6483
  ];
6035
6484
  if (isLast) {
6036
6485
  chunkIxs.push({
@@ -6112,20 +6561,34 @@ class Transactions {
6112
6561
  y0: acc.y0.add(l.y0),
6113
6562
  deltaX: acc.deltaX.add(l.deltaX),
6114
6563
  deltaY: acc.deltaY.add(l.deltaY),
6115
- }), { x0: new bn_js_1.default(0), y0: new bn_js_1.default(0), deltaX: new bn_js_1.default(0), deltaY: new bn_js_1.default(0) });
6564
+ }), {
6565
+ x0: new bn_js_1.default(0),
6566
+ y0: new bn_js_1.default(0),
6567
+ deltaX: new bn_js_1.default(0),
6568
+ deltaY: new bn_js_1.default(0),
6569
+ });
6116
6570
  const mergedP = (0, liquidityStrategy_1.buildBitFlagAndNegateStrategyParameters)(mergedLayer.x0, mergedLayer.y0, mergedLayer.deltaX, mergedLayer.deltaY);
6117
- const allAddLiquidityParams = [{
6571
+ const allAddLiquidityParams = [
6572
+ {
6118
6573
  minDeltaId,
6119
6574
  maxDeltaId,
6120
- x0: mergedP.x0, y0: mergedP.y0, deltaX: mergedP.deltaX, deltaY: mergedP.deltaY,
6575
+ x0: mergedP.x0,
6576
+ y0: mergedP.y0,
6577
+ deltaX: mergedP.deltaX,
6578
+ deltaY: mergedP.deltaY,
6121
6579
  bitFlag: mergedP.bitFlag,
6122
6580
  favorXInActiveId,
6123
- }];
6581
+ },
6582
+ ];
6124
6583
  const mergedBinsAmounts = (0, liquidityStrategy_1.toAmountIntoBins)(new bn_js_1.default(activeId), new bn_js_1.default(minDeltaId), new bn_js_1.default(maxDeltaId), mergedLayer.deltaX, mergedLayer.deltaY, mergedLayer.x0, mergedLayer.y0, binStep, favorXInActiveId);
6125
6584
  const totalMaxX = mergedBinsAmounts.reduce((s, b) => s.add(b.amountX), new bn_js_1.default(0));
6126
6585
  const totalMaxY = mergedBinsAmounts.reduce((s, b) => s.add(b.amountY), new bn_js_1.default(0));
6127
6586
  const binArrayInitIxs = yield this._initBinArraysForRange(connection, lbPair, dlmmPool, newLowerBinId, newUpperBinId);
6128
- const binArrayInitIxsLabeled = binArrayInitIxs.map(ix => ({ label: 'init_bin_array', class: CLASS, instruction: ix }));
6587
+ const binArrayInitIxsLabeled = binArrayInitIxs.map(ix => ({
6588
+ label: 'init_bin_array',
6589
+ class: CLASS,
6590
+ instruction: ix,
6591
+ }));
6129
6592
  const depositIx = yield depositFn({
6130
6593
  position: params.newPosition,
6131
6594
  shouldClaimFee: false,
@@ -6138,7 +6601,11 @@ class Transactions {
6138
6601
  });
6139
6602
  if (newWidth <= MAX_INIT_WIDTH) {
6140
6603
  // ≤70 bins: no extension needed, everything fits in one TX
6141
- rebuildTxGroups.push([...initExtendIxs, ...binArrayInitIxsLabeled, depositIx]);
6604
+ rebuildTxGroups.push([
6605
+ ...initExtendIxs,
6606
+ ...binArrayInitIxsLabeled,
6607
+ depositIx,
6608
+ ]);
6142
6609
  }
6143
6610
  else {
6144
6611
  // 71-149 bins: extension needed, split init+extend from deposit to stay within TX size limit
@@ -6157,21 +6624,35 @@ class Transactions {
6157
6624
  y0: acc.y0.add(l.params.y0),
6158
6625
  deltaX: acc.deltaX.add(l.params.deltaX),
6159
6626
  deltaY: acc.deltaY.add(l.params.deltaY),
6160
- }), { x0: new bn_js_1.default(0), y0: new bn_js_1.default(0), deltaX: new bn_js_1.default(0), deltaY: new bn_js_1.default(0) });
6627
+ }), {
6628
+ x0: new bn_js_1.default(0),
6629
+ y0: new bn_js_1.default(0),
6630
+ deltaX: new bn_js_1.default(0),
6631
+ deltaY: new bn_js_1.default(0),
6632
+ });
6161
6633
  const chunkMergedP = (0, liquidityStrategy_1.buildBitFlagAndNegateStrategyParameters)(chunkMergedLayer.x0, chunkMergedLayer.y0, chunkMergedLayer.deltaX, chunkMergedLayer.deltaY);
6162
- const chunkAddLiquidityParams = [{
6634
+ const chunkAddLiquidityParams = [
6635
+ {
6163
6636
  minDeltaId: chunk.minDeltaId.toNumber(),
6164
6637
  maxDeltaId: chunk.maxDeltaId.toNumber(),
6165
- x0: chunkMergedP.x0, y0: chunkMergedP.y0, deltaX: chunkMergedP.deltaX, deltaY: chunkMergedP.deltaY,
6638
+ x0: chunkMergedP.x0,
6639
+ y0: chunkMergedP.y0,
6640
+ deltaX: chunkMergedP.deltaX,
6641
+ deltaY: chunkMergedP.deltaY,
6166
6642
  bitFlag: chunkMergedP.bitFlag,
6167
6643
  favorXInActiveId,
6168
- }];
6644
+ },
6645
+ ];
6169
6646
  const chunkMergedBinsAmounts = (0, liquidityStrategy_1.toAmountIntoBins)(new bn_js_1.default(activeId), chunk.minDeltaId, chunk.maxDeltaId, chunkMergedLayer.deltaX, chunkMergedLayer.deltaY, chunkMergedLayer.x0, chunkMergedLayer.y0, binStep, favorXInActiveId);
6170
6647
  const chunkTotalMaxX = chunkMergedBinsAmounts.reduce((s, b) => s.add(b.amountX), new bn_js_1.default(0));
6171
6648
  const chunkTotalMaxY = chunkMergedBinsAmounts.reduce((s, b) => s.add(b.amountY), new bn_js_1.default(0));
6172
6649
  const binArrayInitIxs = yield this._initBinArraysForRange(connection, lbPair, dlmmPool, chunk.lowerBinId, chunk.upperBinId);
6173
6650
  rebuildTxGroups.push([
6174
- ...binArrayInitIxs.map(ix => ({ label: 'init_bin_array', class: CLASS, instruction: ix })),
6651
+ ...binArrayInitIxs.map(ix => ({
6652
+ label: 'init_bin_array',
6653
+ class: CLASS,
6654
+ instruction: ix,
6655
+ })),
6175
6656
  yield depositFn({
6176
6657
  position: params.newPosition,
6177
6658
  shouldClaimFee: false,
@@ -6252,26 +6733,26 @@ class Transactions {
6252
6733
  const withdrawTxGroups = [];
6253
6734
  if (positionWidth <= MAX_BINS_PER_WITHDRAW_CHUNK) {
6254
6735
  withdrawTxGroups.push([
6255
- ...yield withdrawFn({
6736
+ ...(yield withdrawFn({
6256
6737
  position: params.position,
6257
6738
  minBinId: lowerBinId,
6258
6739
  maxBinId: upperBinId,
6259
6740
  compound: params.compound,
6260
6741
  origin: CLASS,
6261
- }),
6742
+ })),
6262
6743
  ]);
6263
6744
  }
6264
6745
  else {
6265
6746
  const withdrawChunks = (0, liquidityStrategy_1.chunkBinRange)(lowerBinId, upperBinId, MAX_BINS_PER_WITHDRAW_CHUNK);
6266
6747
  for (const chunk of withdrawChunks) {
6267
6748
  withdrawTxGroups.push([
6268
- ...yield withdrawFn({
6749
+ ...(yield withdrawFn({
6269
6750
  position: params.position,
6270
6751
  minBinId: chunk.lowerBinId,
6271
6752
  maxBinId: chunk.upperBinId,
6272
6753
  compound: params.compound,
6273
6754
  origin: CLASS,
6274
- }),
6755
+ })),
6275
6756
  ]);
6276
6757
  }
6277
6758
  }
@@ -6299,15 +6780,25 @@ class Transactions {
6299
6780
  y0: acc.y0.add(l.y0),
6300
6781
  deltaX: acc.deltaX.add(l.deltaX),
6301
6782
  deltaY: acc.deltaY.add(l.deltaY),
6302
- }), { x0: new bn_js_1.default(0), y0: new bn_js_1.default(0), deltaX: new bn_js_1.default(0), deltaY: new bn_js_1.default(0) });
6783
+ }), {
6784
+ x0: new bn_js_1.default(0),
6785
+ y0: new bn_js_1.default(0),
6786
+ deltaX: new bn_js_1.default(0),
6787
+ deltaY: new bn_js_1.default(0),
6788
+ });
6303
6789
  const mergedP = (0, liquidityStrategy_1.buildBitFlagAndNegateStrategyParameters)(mergedLayer.x0, mergedLayer.y0, mergedLayer.deltaX, mergedLayer.deltaY);
6304
- const allAddLiquidityParams = [{
6790
+ const allAddLiquidityParams = [
6791
+ {
6305
6792
  minDeltaId,
6306
6793
  maxDeltaId,
6307
- x0: mergedP.x0, y0: mergedP.y0, deltaX: mergedP.deltaX, deltaY: mergedP.deltaY,
6794
+ x0: mergedP.x0,
6795
+ y0: mergedP.y0,
6796
+ deltaX: mergedP.deltaX,
6797
+ deltaY: mergedP.deltaY,
6308
6798
  bitFlag: mergedP.bitFlag,
6309
6799
  favorXInActiveId,
6310
- }];
6800
+ },
6801
+ ];
6311
6802
  const mergedBinsAmounts = (0, liquidityStrategy_1.toAmountIntoBins)(new bn_js_1.default(activeId), new bn_js_1.default(minDeltaId), new bn_js_1.default(maxDeltaId), mergedLayer.deltaX, mergedLayer.deltaY, mergedLayer.x0, mergedLayer.y0, binStep, favorXInActiveId);
6312
6803
  const totalMaxX = mergedBinsAmounts.reduce((s, b) => s.add(b.amountX), new bn_js_1.default(0));
6313
6804
  const totalMaxY = mergedBinsAmounts.reduce((s, b) => s.add(b.amountY), new bn_js_1.default(0));
@@ -6334,15 +6825,25 @@ class Transactions {
6334
6825
  y0: acc.y0.add(l.params.y0),
6335
6826
  deltaX: acc.deltaX.add(l.params.deltaX),
6336
6827
  deltaY: acc.deltaY.add(l.params.deltaY),
6337
- }), { x0: new bn_js_1.default(0), y0: new bn_js_1.default(0), deltaX: new bn_js_1.default(0), deltaY: new bn_js_1.default(0) });
6828
+ }), {
6829
+ x0: new bn_js_1.default(0),
6830
+ y0: new bn_js_1.default(0),
6831
+ deltaX: new bn_js_1.default(0),
6832
+ deltaY: new bn_js_1.default(0),
6833
+ });
6338
6834
  const chunkMergedP = (0, liquidityStrategy_1.buildBitFlagAndNegateStrategyParameters)(chunkMergedLayer.x0, chunkMergedLayer.y0, chunkMergedLayer.deltaX, chunkMergedLayer.deltaY);
6339
- const chunkAddLiquidityParams = [{
6835
+ const chunkAddLiquidityParams = [
6836
+ {
6340
6837
  minDeltaId: chunk.minDeltaId.toNumber(),
6341
6838
  maxDeltaId: chunk.maxDeltaId.toNumber(),
6342
- x0: chunkMergedP.x0, y0: chunkMergedP.y0, deltaX: chunkMergedP.deltaX, deltaY: chunkMergedP.deltaY,
6839
+ x0: chunkMergedP.x0,
6840
+ y0: chunkMergedP.y0,
6841
+ deltaX: chunkMergedP.deltaX,
6842
+ deltaY: chunkMergedP.deltaY,
6343
6843
  bitFlag: chunkMergedP.bitFlag,
6344
6844
  favorXInActiveId,
6345
- }];
6845
+ },
6846
+ ];
6346
6847
  const chunkMergedBinsAmounts = (0, liquidityStrategy_1.toAmountIntoBins)(new bn_js_1.default(activeId), chunk.minDeltaId, chunk.maxDeltaId, chunkMergedLayer.deltaX, chunkMergedLayer.deltaY, chunkMergedLayer.x0, chunkMergedLayer.y0, binStep, favorXInActiveId);
6347
6848
  const chunkTotalMaxX = chunkMergedBinsAmounts.reduce((s, b) => s.add(b.amountX), new bn_js_1.default(0));
6348
6849
  const chunkTotalMaxY = chunkMergedBinsAmounts.reduce((s, b) => s.add(b.amountY), new bn_js_1.default(0));
@@ -6602,7 +7103,7 @@ class Transactions {
6602
7103
  removeLiquidityParams: [],
6603
7104
  addLiquidityParams,
6604
7105
  maxActiveBinSlippage: 0,
6605
- })
7106
+ }),
6606
7107
  };
6607
7108
  });
6608
7109
  return {