@strkfarm/sdk 1.0.31 → 1.0.33

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.
@@ -2089,7 +2089,7 @@ var AutoCompounderSTRK = class {
2089
2089
  }
2090
2090
  };
2091
2091
 
2092
- // src/strategies/vesu-rebalance.ts
2092
+ // src/strategies/vesu-rebalance.tsx
2093
2093
  import { CairoCustomEnum, Contract as Contract5, num as num3, uint256 as uint2563 } from "starknet";
2094
2094
 
2095
2095
  // src/data/vesu-rebalance.abi.json
@@ -12697,7 +12697,7 @@ var vesu_pools_default = {
12697
12697
  ]
12698
12698
  };
12699
12699
 
12700
- // src/strategies/vesu-rebalance.ts
12700
+ // src/strategies/vesu-rebalance.tsx
12701
12701
  var VesuRebalance = class _VesuRebalance extends BaseStrategy {
12702
12702
  // 10000 bps = 100%
12703
12703
  /**
@@ -13198,7 +13198,7 @@ var VesuRebalanceStrategies = [{
13198
13198
  // },
13199
13199
  }];
13200
13200
 
13201
- // src/strategies/ekubo-cl-vault.ts
13201
+ // src/strategies/ekubo-cl-vault.tsx
13202
13202
  import { Contract as Contract6, num as num4, uint256 as uint2564 } from "starknet";
13203
13203
 
13204
13204
  // src/data/cl-vault.abi.json
@@ -18100,7 +18100,8 @@ var erc4626_abi_default = [
18100
18100
  }
18101
18101
  ];
18102
18102
 
18103
- // src/strategies/ekubo-cl-vault.ts
18103
+ // src/strategies/ekubo-cl-vault.tsx
18104
+ import { jsx, jsxs } from "react/jsx-runtime";
18104
18105
  var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
18105
18106
  /**
18106
18107
  * Creates a new VesuRebalance strategy instance.
@@ -18629,11 +18630,10 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
18629
18630
  * @returns Array of contract calls needed for rebalancing
18630
18631
  * @throws Error if max retries reached without successful rebalance
18631
18632
  */
18632
- async rebalanceIter(swapInfo, acc, estimateCall, retry = 0, adjustmentFactor = 1, isToken0Deficit = true) {
18633
- const MAX_RETRIES = 20;
18634
- const MIN_ADJUSTMENT = 1e-3;
18633
+ async rebalanceIter(swapInfo, acc, estimateCall, isSellTokenToken0 = true, retry = 0, lowerLimit = 0n, upperLimit = 0n) {
18634
+ const MAX_RETRIES = 40;
18635
18635
  logger.verbose(
18636
- `Rebalancing ${this.metadata.name}: retry=${retry}, adjustment=${adjustmentFactor}%, token0Deficit=${isToken0Deficit}`
18636
+ `Rebalancing ${this.metadata.name}: retry=${retry}, lowerLimit=${lowerLimit}, upperLimit=${upperLimit}, isSellTokenToken0=${isSellTokenToken0}`
18637
18637
  );
18638
18638
  const fromAmount = uint2564.uint256ToBN(swapInfo.token_from_amount);
18639
18639
  logger.verbose(
@@ -18648,38 +18648,69 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
18648
18648
  logger.error(`Rebalance failed after ${MAX_RETRIES} retries`);
18649
18649
  throw err;
18650
18650
  }
18651
- if (adjustmentFactor < MIN_ADJUSTMENT) {
18652
- logger.error("Adjustment factor too small, likely oscillating");
18653
- throw new Error("Failed to converge on valid swap amount");
18654
- }
18655
18651
  logger.error(`Rebalance attempt ${retry + 1} failed, adjusting swap amount...`);
18656
18652
  const newSwapInfo = { ...swapInfo };
18657
18653
  const currentAmount = Web3Number.fromWei(fromAmount.toString(), 18);
18654
+ logger.verbose(`Current amount: ${currentAmount.toString()}`);
18658
18655
  if (err.message.includes("invalid token0 balance") || err.message.includes("invalid token0 amount")) {
18659
- logger.verbose("Reducing swap amount - excess token0");
18660
- newSwapInfo.token_from_amount = uint2564.bnToUint256(
18661
- currentAmount.multipliedBy((100 - adjustmentFactor) / 100).toWei()
18662
- );
18663
- adjustmentFactor = isToken0Deficit ? adjustmentFactor * 2 : adjustmentFactor / 2;
18664
- isToken0Deficit = true;
18665
- } else if (err.message.includes("invalid token1 balance") || err.message.includes("invalid token1 amount")) {
18666
- logger.verbose("Increasing swap amount - excess token1");
18667
- newSwapInfo.token_from_amount = uint2564.bnToUint256(
18668
- currentAmount.multipliedBy((100 + adjustmentFactor) / 100).toWei()
18669
- );
18670
- adjustmentFactor = isToken0Deficit ? adjustmentFactor / 2 : adjustmentFactor * 2;
18671
- isToken0Deficit = false;
18656
+ if (!isSellTokenToken0) {
18657
+ logger.verbose("Reducing swap amount - excess token0");
18658
+ let nextAmount = (fromAmount + lowerLimit) / 2n;
18659
+ upperLimit = fromAmount;
18660
+ if (nextAmount <= lowerLimit) {
18661
+ logger.error("Convergence failed: nextAmount <= lowerLimit");
18662
+ throw err;
18663
+ }
18664
+ newSwapInfo.token_from_amount = uint2564.bnToUint256(nextAmount);
18665
+ } else {
18666
+ logger.verbose("Increasing swap amount - deficit token0");
18667
+ let nextAmount = (fromAmount + upperLimit) / 2n;
18668
+ if (upperLimit == 0n) {
18669
+ nextAmount = fromAmount * 2n;
18670
+ }
18671
+ lowerLimit = fromAmount;
18672
+ if (upperLimit != 0n && nextAmount >= upperLimit) {
18673
+ logger.error("Convergence failed: nextAmount >= upperLimit");
18674
+ throw err;
18675
+ }
18676
+ newSwapInfo.token_from_amount = uint2564.bnToUint256(nextAmount);
18677
+ }
18678
+ } else if (err.message.includes("invalid token1 amount") || err.message.includes("invalid token1 balance")) {
18679
+ if (isSellTokenToken0) {
18680
+ logger.verbose("Reducing swap amount - excess token1");
18681
+ let nextAmount = (fromAmount + lowerLimit) / 2n;
18682
+ upperLimit = fromAmount;
18683
+ if (nextAmount <= lowerLimit) {
18684
+ logger.error("Convergence failed: nextAmount <= lowerLimit");
18685
+ throw err;
18686
+ }
18687
+ newSwapInfo.token_from_amount = uint2564.bnToUint256(nextAmount);
18688
+ } else {
18689
+ logger.verbose("Increasing swap amount - deficit token1");
18690
+ let nextAmount = (fromAmount + upperLimit) / 2n;
18691
+ if (upperLimit == 0n) {
18692
+ nextAmount = fromAmount * 2n;
18693
+ }
18694
+ lowerLimit = fromAmount;
18695
+ if (upperLimit != 0n && nextAmount >= upperLimit) {
18696
+ logger.error("Convergence failed: nextAmount >= upperLimit");
18697
+ throw err;
18698
+ }
18699
+ newSwapInfo.token_from_amount = uint2564.bnToUint256(nextAmount);
18700
+ }
18672
18701
  } else {
18673
18702
  logger.error("Unexpected error:", err);
18703
+ throw err;
18674
18704
  }
18675
18705
  newSwapInfo.token_to_min_amount = uint2564.bnToUint256("0");
18676
18706
  return this.rebalanceIter(
18677
18707
  newSwapInfo,
18678
18708
  acc,
18679
18709
  estimateCall,
18710
+ isSellTokenToken0,
18680
18711
  retry + 1,
18681
- adjustmentFactor,
18682
- isToken0Deficit
18712
+ lowerLimit,
18713
+ upperLimit
18683
18714
  );
18684
18715
  }
18685
18716
  }
@@ -18814,7 +18845,13 @@ var _riskFactor2 = [
18814
18845
  var AUDIT_URL2 = "https://assets.strkfarm.com/strkfarm/audit_report_vesu_and_ekubo_strats.pdf";
18815
18846
  var EkuboCLVaultStrategies = [{
18816
18847
  name: "Ekubo xSTRK/STRK",
18817
- description: _description2.replace("{{POOL_NAME}}", "xSTRK/STRK"),
18848
+ description: /* @__PURE__ */ jsxs("div", { children: [
18849
+ /* @__PURE__ */ jsx("p", { children: _description2.replace("{{POOL_NAME}}", "xSTRK/STRK") }),
18850
+ /* @__PURE__ */ jsxs("ul", { style: { marginLeft: "20px", listStyle: "circle", fontSize: "12px" }, children: [
18851
+ /* @__PURE__ */ jsx("li", { style: { marginTop: "10px" }, children: "During withdrawal, you may receive either or both tokens depending on market conditions and prevailing prices." }),
18852
+ /* @__PURE__ */ jsx("li", { style: { marginTop: "10px" }, children: "Sometimes you might see a negative APY \u2014 this is usually not a big deal. It happens when xSTRK's price drops on DEXes, but things typically bounce back within a few days or a week." })
18853
+ ] })
18854
+ ] }),
18818
18855
  address: ContractAddr.from("0x01f083b98674bc21effee29ef443a00c7b9a500fd92cf30341a3da12c73f2324"),
18819
18856
  type: "Other",
18820
18857
  // must be same order as poolKey token0 and token1
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import BigNumber from 'bignumber.js';
2
2
  import * as starknet from 'starknet';
3
3
  import { RpcProvider, BlockIdentifier, Contract, Uint256, Call, Account } from 'starknet';
4
+ import React from 'react';
4
5
  import { Quote } from '@avnu/avnu-sdk';
5
6
  import * as util from 'util';
6
7
  import TelegramBot from 'node-telegram-bot-api';
@@ -90,7 +91,7 @@ declare enum FlowChartColors {
90
91
  */
91
92
  interface IStrategyMetadata<T> {
92
93
  name: string;
93
- description: string;
94
+ description: string | React.ReactNode;
94
95
  address: ContractAddr;
95
96
  type: 'ERC4626' | 'ERC721' | 'Other';
96
97
  depositTokens: TokenInfo[];
@@ -716,7 +717,7 @@ declare class EkuboCLVault extends BaseStrategy<DualTokenInfo, DualActionAmount>
716
717
  * @returns Array of contract calls needed for rebalancing
717
718
  * @throws Error if max retries reached without successful rebalance
718
719
  */
719
- rebalanceIter(swapInfo: SwapInfo, acc: Account, estimateCall: (swapInfo: SwapInfo) => Promise<Call[]>, retry?: number, adjustmentFactor?: number, isToken0Deficit?: boolean): Promise<Call[]>;
720
+ rebalanceIter(swapInfo: SwapInfo, acc: Account, estimateCall: (swapInfo: SwapInfo) => Promise<Call[]>, isSellTokenToken0?: boolean, retry?: number, lowerLimit?: bigint, upperLimit?: bigint): Promise<Call[]>;
720
721
  static tickToi129(tick: number): {
721
722
  mag: number;
722
723
  sign: number;
package/dist/index.js CHANGED
@@ -2178,7 +2178,7 @@ var AutoCompounderSTRK = class {
2178
2178
  }
2179
2179
  };
2180
2180
 
2181
- // src/strategies/vesu-rebalance.ts
2181
+ // src/strategies/vesu-rebalance.tsx
2182
2182
  var import_starknet8 = require("starknet");
2183
2183
 
2184
2184
  // src/data/vesu-rebalance.abi.json
@@ -12786,7 +12786,7 @@ var vesu_pools_default = {
12786
12786
  ]
12787
12787
  };
12788
12788
 
12789
- // src/strategies/vesu-rebalance.ts
12789
+ // src/strategies/vesu-rebalance.tsx
12790
12790
  var VesuRebalance = class _VesuRebalance extends BaseStrategy {
12791
12791
  // 10000 bps = 100%
12792
12792
  /**
@@ -13287,7 +13287,7 @@ var VesuRebalanceStrategies = [{
13287
13287
  // },
13288
13288
  }];
13289
13289
 
13290
- // src/strategies/ekubo-cl-vault.ts
13290
+ // src/strategies/ekubo-cl-vault.tsx
13291
13291
  var import_starknet9 = require("starknet");
13292
13292
 
13293
13293
  // src/data/cl-vault.abi.json
@@ -18189,7 +18189,8 @@ var erc4626_abi_default = [
18189
18189
  }
18190
18190
  ];
18191
18191
 
18192
- // src/strategies/ekubo-cl-vault.ts
18192
+ // src/strategies/ekubo-cl-vault.tsx
18193
+ var import_jsx_runtime = require("react/jsx-runtime");
18193
18194
  var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
18194
18195
  /**
18195
18196
  * Creates a new VesuRebalance strategy instance.
@@ -18718,11 +18719,10 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
18718
18719
  * @returns Array of contract calls needed for rebalancing
18719
18720
  * @throws Error if max retries reached without successful rebalance
18720
18721
  */
18721
- async rebalanceIter(swapInfo, acc, estimateCall, retry = 0, adjustmentFactor = 1, isToken0Deficit = true) {
18722
- const MAX_RETRIES = 20;
18723
- const MIN_ADJUSTMENT = 1e-3;
18722
+ async rebalanceIter(swapInfo, acc, estimateCall, isSellTokenToken0 = true, retry = 0, lowerLimit = 0n, upperLimit = 0n) {
18723
+ const MAX_RETRIES = 40;
18724
18724
  logger.verbose(
18725
- `Rebalancing ${this.metadata.name}: retry=${retry}, adjustment=${adjustmentFactor}%, token0Deficit=${isToken0Deficit}`
18725
+ `Rebalancing ${this.metadata.name}: retry=${retry}, lowerLimit=${lowerLimit}, upperLimit=${upperLimit}, isSellTokenToken0=${isSellTokenToken0}`
18726
18726
  );
18727
18727
  const fromAmount = import_starknet9.uint256.uint256ToBN(swapInfo.token_from_amount);
18728
18728
  logger.verbose(
@@ -18737,38 +18737,69 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
18737
18737
  logger.error(`Rebalance failed after ${MAX_RETRIES} retries`);
18738
18738
  throw err;
18739
18739
  }
18740
- if (adjustmentFactor < MIN_ADJUSTMENT) {
18741
- logger.error("Adjustment factor too small, likely oscillating");
18742
- throw new Error("Failed to converge on valid swap amount");
18743
- }
18744
18740
  logger.error(`Rebalance attempt ${retry + 1} failed, adjusting swap amount...`);
18745
18741
  const newSwapInfo = { ...swapInfo };
18746
18742
  const currentAmount = Web3Number.fromWei(fromAmount.toString(), 18);
18743
+ logger.verbose(`Current amount: ${currentAmount.toString()}`);
18747
18744
  if (err.message.includes("invalid token0 balance") || err.message.includes("invalid token0 amount")) {
18748
- logger.verbose("Reducing swap amount - excess token0");
18749
- newSwapInfo.token_from_amount = import_starknet9.uint256.bnToUint256(
18750
- currentAmount.multipliedBy((100 - adjustmentFactor) / 100).toWei()
18751
- );
18752
- adjustmentFactor = isToken0Deficit ? adjustmentFactor * 2 : adjustmentFactor / 2;
18753
- isToken0Deficit = true;
18754
- } else if (err.message.includes("invalid token1 balance") || err.message.includes("invalid token1 amount")) {
18755
- logger.verbose("Increasing swap amount - excess token1");
18756
- newSwapInfo.token_from_amount = import_starknet9.uint256.bnToUint256(
18757
- currentAmount.multipliedBy((100 + adjustmentFactor) / 100).toWei()
18758
- );
18759
- adjustmentFactor = isToken0Deficit ? adjustmentFactor / 2 : adjustmentFactor * 2;
18760
- isToken0Deficit = false;
18745
+ if (!isSellTokenToken0) {
18746
+ logger.verbose("Reducing swap amount - excess token0");
18747
+ let nextAmount = (fromAmount + lowerLimit) / 2n;
18748
+ upperLimit = fromAmount;
18749
+ if (nextAmount <= lowerLimit) {
18750
+ logger.error("Convergence failed: nextAmount <= lowerLimit");
18751
+ throw err;
18752
+ }
18753
+ newSwapInfo.token_from_amount = import_starknet9.uint256.bnToUint256(nextAmount);
18754
+ } else {
18755
+ logger.verbose("Increasing swap amount - deficit token0");
18756
+ let nextAmount = (fromAmount + upperLimit) / 2n;
18757
+ if (upperLimit == 0n) {
18758
+ nextAmount = fromAmount * 2n;
18759
+ }
18760
+ lowerLimit = fromAmount;
18761
+ if (upperLimit != 0n && nextAmount >= upperLimit) {
18762
+ logger.error("Convergence failed: nextAmount >= upperLimit");
18763
+ throw err;
18764
+ }
18765
+ newSwapInfo.token_from_amount = import_starknet9.uint256.bnToUint256(nextAmount);
18766
+ }
18767
+ } else if (err.message.includes("invalid token1 amount") || err.message.includes("invalid token1 balance")) {
18768
+ if (isSellTokenToken0) {
18769
+ logger.verbose("Reducing swap amount - excess token1");
18770
+ let nextAmount = (fromAmount + lowerLimit) / 2n;
18771
+ upperLimit = fromAmount;
18772
+ if (nextAmount <= lowerLimit) {
18773
+ logger.error("Convergence failed: nextAmount <= lowerLimit");
18774
+ throw err;
18775
+ }
18776
+ newSwapInfo.token_from_amount = import_starknet9.uint256.bnToUint256(nextAmount);
18777
+ } else {
18778
+ logger.verbose("Increasing swap amount - deficit token1");
18779
+ let nextAmount = (fromAmount + upperLimit) / 2n;
18780
+ if (upperLimit == 0n) {
18781
+ nextAmount = fromAmount * 2n;
18782
+ }
18783
+ lowerLimit = fromAmount;
18784
+ if (upperLimit != 0n && nextAmount >= upperLimit) {
18785
+ logger.error("Convergence failed: nextAmount >= upperLimit");
18786
+ throw err;
18787
+ }
18788
+ newSwapInfo.token_from_amount = import_starknet9.uint256.bnToUint256(nextAmount);
18789
+ }
18761
18790
  } else {
18762
18791
  logger.error("Unexpected error:", err);
18792
+ throw err;
18763
18793
  }
18764
18794
  newSwapInfo.token_to_min_amount = import_starknet9.uint256.bnToUint256("0");
18765
18795
  return this.rebalanceIter(
18766
18796
  newSwapInfo,
18767
18797
  acc,
18768
18798
  estimateCall,
18799
+ isSellTokenToken0,
18769
18800
  retry + 1,
18770
- adjustmentFactor,
18771
- isToken0Deficit
18801
+ lowerLimit,
18802
+ upperLimit
18772
18803
  );
18773
18804
  }
18774
18805
  }
@@ -18903,7 +18934,13 @@ var _riskFactor2 = [
18903
18934
  var AUDIT_URL2 = "https://assets.strkfarm.com/strkfarm/audit_report_vesu_and_ekubo_strats.pdf";
18904
18935
  var EkuboCLVaultStrategies = [{
18905
18936
  name: "Ekubo xSTRK/STRK",
18906
- description: _description2.replace("{{POOL_NAME}}", "xSTRK/STRK"),
18937
+ description: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
18938
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: _description2.replace("{{POOL_NAME}}", "xSTRK/STRK") }),
18939
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("ul", { style: { marginLeft: "20px", listStyle: "circle", fontSize: "12px" }, children: [
18940
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { style: { marginTop: "10px" }, children: "During withdrawal, you may receive either or both tokens depending on market conditions and prevailing prices." }),
18941
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { style: { marginTop: "10px" }, children: "Sometimes you might see a negative APY \u2014 this is usually not a big deal. It happens when xSTRK's price drops on DEXes, but things typically bounce back within a few days or a week." })
18942
+ ] })
18943
+ ] }),
18907
18944
  address: ContractAddr.from("0x01f083b98674bc21effee29ef443a00c7b9a500fd92cf30341a3da12c73f2324"),
18908
18945
  type: "Other",
18909
18946
  // must be same order as poolKey token0 and token1
package/dist/index.mjs CHANGED
@@ -2109,7 +2109,7 @@ var AutoCompounderSTRK = class {
2109
2109
  }
2110
2110
  };
2111
2111
 
2112
- // src/strategies/vesu-rebalance.ts
2112
+ // src/strategies/vesu-rebalance.tsx
2113
2113
  import { CairoCustomEnum, Contract as Contract5, num as num3, uint256 as uint2563 } from "starknet";
2114
2114
 
2115
2115
  // src/data/vesu-rebalance.abi.json
@@ -12717,7 +12717,7 @@ var vesu_pools_default = {
12717
12717
  ]
12718
12718
  };
12719
12719
 
12720
- // src/strategies/vesu-rebalance.ts
12720
+ // src/strategies/vesu-rebalance.tsx
12721
12721
  var VesuRebalance = class _VesuRebalance extends BaseStrategy {
12722
12722
  // 10000 bps = 100%
12723
12723
  /**
@@ -13218,7 +13218,7 @@ var VesuRebalanceStrategies = [{
13218
13218
  // },
13219
13219
  }];
13220
13220
 
13221
- // src/strategies/ekubo-cl-vault.ts
13221
+ // src/strategies/ekubo-cl-vault.tsx
13222
13222
  import { Contract as Contract6, num as num4, uint256 as uint2564 } from "starknet";
13223
13223
 
13224
13224
  // src/data/cl-vault.abi.json
@@ -18120,7 +18120,8 @@ var erc4626_abi_default = [
18120
18120
  }
18121
18121
  ];
18122
18122
 
18123
- // src/strategies/ekubo-cl-vault.ts
18123
+ // src/strategies/ekubo-cl-vault.tsx
18124
+ import { jsx, jsxs } from "react/jsx-runtime";
18124
18125
  var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
18125
18126
  /**
18126
18127
  * Creates a new VesuRebalance strategy instance.
@@ -18649,11 +18650,10 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
18649
18650
  * @returns Array of contract calls needed for rebalancing
18650
18651
  * @throws Error if max retries reached without successful rebalance
18651
18652
  */
18652
- async rebalanceIter(swapInfo, acc, estimateCall, retry = 0, adjustmentFactor = 1, isToken0Deficit = true) {
18653
- const MAX_RETRIES = 20;
18654
- const MIN_ADJUSTMENT = 1e-3;
18653
+ async rebalanceIter(swapInfo, acc, estimateCall, isSellTokenToken0 = true, retry = 0, lowerLimit = 0n, upperLimit = 0n) {
18654
+ const MAX_RETRIES = 40;
18655
18655
  logger.verbose(
18656
- `Rebalancing ${this.metadata.name}: retry=${retry}, adjustment=${adjustmentFactor}%, token0Deficit=${isToken0Deficit}`
18656
+ `Rebalancing ${this.metadata.name}: retry=${retry}, lowerLimit=${lowerLimit}, upperLimit=${upperLimit}, isSellTokenToken0=${isSellTokenToken0}`
18657
18657
  );
18658
18658
  const fromAmount = uint2564.uint256ToBN(swapInfo.token_from_amount);
18659
18659
  logger.verbose(
@@ -18668,38 +18668,69 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
18668
18668
  logger.error(`Rebalance failed after ${MAX_RETRIES} retries`);
18669
18669
  throw err;
18670
18670
  }
18671
- if (adjustmentFactor < MIN_ADJUSTMENT) {
18672
- logger.error("Adjustment factor too small, likely oscillating");
18673
- throw new Error("Failed to converge on valid swap amount");
18674
- }
18675
18671
  logger.error(`Rebalance attempt ${retry + 1} failed, adjusting swap amount...`);
18676
18672
  const newSwapInfo = { ...swapInfo };
18677
18673
  const currentAmount = Web3Number.fromWei(fromAmount.toString(), 18);
18674
+ logger.verbose(`Current amount: ${currentAmount.toString()}`);
18678
18675
  if (err.message.includes("invalid token0 balance") || err.message.includes("invalid token0 amount")) {
18679
- logger.verbose("Reducing swap amount - excess token0");
18680
- newSwapInfo.token_from_amount = uint2564.bnToUint256(
18681
- currentAmount.multipliedBy((100 - adjustmentFactor) / 100).toWei()
18682
- );
18683
- adjustmentFactor = isToken0Deficit ? adjustmentFactor * 2 : adjustmentFactor / 2;
18684
- isToken0Deficit = true;
18685
- } else if (err.message.includes("invalid token1 balance") || err.message.includes("invalid token1 amount")) {
18686
- logger.verbose("Increasing swap amount - excess token1");
18687
- newSwapInfo.token_from_amount = uint2564.bnToUint256(
18688
- currentAmount.multipliedBy((100 + adjustmentFactor) / 100).toWei()
18689
- );
18690
- adjustmentFactor = isToken0Deficit ? adjustmentFactor / 2 : adjustmentFactor * 2;
18691
- isToken0Deficit = false;
18676
+ if (!isSellTokenToken0) {
18677
+ logger.verbose("Reducing swap amount - excess token0");
18678
+ let nextAmount = (fromAmount + lowerLimit) / 2n;
18679
+ upperLimit = fromAmount;
18680
+ if (nextAmount <= lowerLimit) {
18681
+ logger.error("Convergence failed: nextAmount <= lowerLimit");
18682
+ throw err;
18683
+ }
18684
+ newSwapInfo.token_from_amount = uint2564.bnToUint256(nextAmount);
18685
+ } else {
18686
+ logger.verbose("Increasing swap amount - deficit token0");
18687
+ let nextAmount = (fromAmount + upperLimit) / 2n;
18688
+ if (upperLimit == 0n) {
18689
+ nextAmount = fromAmount * 2n;
18690
+ }
18691
+ lowerLimit = fromAmount;
18692
+ if (upperLimit != 0n && nextAmount >= upperLimit) {
18693
+ logger.error("Convergence failed: nextAmount >= upperLimit");
18694
+ throw err;
18695
+ }
18696
+ newSwapInfo.token_from_amount = uint2564.bnToUint256(nextAmount);
18697
+ }
18698
+ } else if (err.message.includes("invalid token1 amount") || err.message.includes("invalid token1 balance")) {
18699
+ if (isSellTokenToken0) {
18700
+ logger.verbose("Reducing swap amount - excess token1");
18701
+ let nextAmount = (fromAmount + lowerLimit) / 2n;
18702
+ upperLimit = fromAmount;
18703
+ if (nextAmount <= lowerLimit) {
18704
+ logger.error("Convergence failed: nextAmount <= lowerLimit");
18705
+ throw err;
18706
+ }
18707
+ newSwapInfo.token_from_amount = uint2564.bnToUint256(nextAmount);
18708
+ } else {
18709
+ logger.verbose("Increasing swap amount - deficit token1");
18710
+ let nextAmount = (fromAmount + upperLimit) / 2n;
18711
+ if (upperLimit == 0n) {
18712
+ nextAmount = fromAmount * 2n;
18713
+ }
18714
+ lowerLimit = fromAmount;
18715
+ if (upperLimit != 0n && nextAmount >= upperLimit) {
18716
+ logger.error("Convergence failed: nextAmount >= upperLimit");
18717
+ throw err;
18718
+ }
18719
+ newSwapInfo.token_from_amount = uint2564.bnToUint256(nextAmount);
18720
+ }
18692
18721
  } else {
18693
18722
  logger.error("Unexpected error:", err);
18723
+ throw err;
18694
18724
  }
18695
18725
  newSwapInfo.token_to_min_amount = uint2564.bnToUint256("0");
18696
18726
  return this.rebalanceIter(
18697
18727
  newSwapInfo,
18698
18728
  acc,
18699
18729
  estimateCall,
18730
+ isSellTokenToken0,
18700
18731
  retry + 1,
18701
- adjustmentFactor,
18702
- isToken0Deficit
18732
+ lowerLimit,
18733
+ upperLimit
18703
18734
  );
18704
18735
  }
18705
18736
  }
@@ -18834,7 +18865,13 @@ var _riskFactor2 = [
18834
18865
  var AUDIT_URL2 = "https://assets.strkfarm.com/strkfarm/audit_report_vesu_and_ekubo_strats.pdf";
18835
18866
  var EkuboCLVaultStrategies = [{
18836
18867
  name: "Ekubo xSTRK/STRK",
18837
- description: _description2.replace("{{POOL_NAME}}", "xSTRK/STRK"),
18868
+ description: /* @__PURE__ */ jsxs("div", { children: [
18869
+ /* @__PURE__ */ jsx("p", { children: _description2.replace("{{POOL_NAME}}", "xSTRK/STRK") }),
18870
+ /* @__PURE__ */ jsxs("ul", { style: { marginLeft: "20px", listStyle: "circle", fontSize: "12px" }, children: [
18871
+ /* @__PURE__ */ jsx("li", { style: { marginTop: "10px" }, children: "During withdrawal, you may receive either or both tokens depending on market conditions and prevailing prices." }),
18872
+ /* @__PURE__ */ jsx("li", { style: { marginTop: "10px" }, children: "Sometimes you might see a negative APY \u2014 this is usually not a big deal. It happens when xSTRK's price drops on DEXes, but things typically bounce back within a few days or a week." })
18873
+ ] })
18874
+ ] }),
18838
18875
  address: ContractAddr.from("0x01f083b98674bc21effee29ef443a00c7b9a500fd92cf30341a3da12c73f2324"),
18839
18876
  type: "Other",
18840
18877
  // must be same order as poolKey token0 and token1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strkfarm/sdk",
3
- "version": "1.0.31",
3
+ "version": "1.0.33",
4
4
  "description": "STRKFarm TS SDK (Meant for our internal use, but feel free to use it)",
5
5
  "typings": "dist/index.d.ts",
6
6
  "types": "dist/index.d.ts",
@@ -41,6 +41,7 @@
41
41
  "devDependencies": {
42
42
  "@types/jest": "^29.5.12",
43
43
  "@types/node-telegram-bot-api": "^0.64.7",
44
+ "@types/react": "^19.1.2",
44
45
  "jest": "^29.7.0",
45
46
  "jest-environment-jsdom": "^29.7.0",
46
47
  "ts-jest": "^29.1.5",
@@ -49,6 +50,9 @@
49
50
  "typedoc": "^0.26.3",
50
51
  "typescript": "^5.5.3"
51
52
  },
53
+ "peerDependencies": {
54
+ "react": "19.1.0"
55
+ },
52
56
  "dependencies": {
53
57
  "@avnu/avnu-sdk": "^3.0.2",
54
58
  "axios": "^1.7.2",
@@ -1,5 +1,6 @@
1
1
  import { ContractAddr, Web3Number } from "@/dataTypes"
2
2
  import { BlockIdentifier, RpcProvider } from "starknet"
3
+ import React from 'react';
3
4
 
4
5
  export enum RiskType {
5
6
  MARKET_RISK = 'Market Risk',
@@ -62,7 +63,7 @@ export enum FlowChartColors {
62
63
  */
63
64
  export interface IStrategyMetadata<T> {
64
65
  name: string,
65
- description: string,
66
+ description: string | React.ReactNode,
66
67
  address: ContractAddr,
67
68
  type: 'ERC4626' | 'ERC721' | 'Other',
68
69
  depositTokens: TokenInfo[],