@strkfarm/sdk 1.0.32 → 1.0.34

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.
@@ -113,7 +113,7 @@ var FatalError = class extends Error {
113
113
  var defaultTokens = [{
114
114
  name: "Starknet",
115
115
  symbol: "STRK",
116
- logo: "https://assets.coingecko.com/coins/images/26433/small/starknet.png",
116
+ logo: "https://assets.strkfarm.com/integrations/tokens/strk.svg",
117
117
  address: ContractAddr.from("0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"),
118
118
  decimals: 18,
119
119
  coingeckId: "starknet",
@@ -121,7 +121,7 @@ var defaultTokens = [{
121
121
  }, {
122
122
  name: "xSTRK",
123
123
  symbol: "xSTRK",
124
- logo: "https://dashboard.endur.fi/endur-fi.svg",
124
+ logo: "https://assets.strkfarm.com/integrations/tokens/xstrk.svg",
125
125
  address: ContractAddr.from("0x028d709c875c0ceac3dce7065bec5328186dc89fe254527084d1689910954b0a"),
126
126
  decimals: 18,
127
127
  coingeckId: void 0,
@@ -129,7 +129,7 @@ var defaultTokens = [{
129
129
  }, {
130
130
  name: "ETH",
131
131
  symbol: "ETH",
132
- logo: "https://opbnb.bscscan.com/token/images/ether.svg",
132
+ logo: "https://assets.strkfarm.com/integrations/tokens/eth.svg",
133
133
  address: ContractAddr.from("0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"),
134
134
  decimals: 18,
135
135
  coingeckId: void 0,
@@ -137,7 +137,7 @@ var defaultTokens = [{
137
137
  }, {
138
138
  name: "USDC",
139
139
  symbol: "USDC",
140
- logo: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
140
+ logo: "https://assets.strkfarm.com/integrations/tokens/usdc.svg",
141
141
  address: ContractAddr.from("0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8"),
142
142
  decimals: 6,
143
143
  coingeckId: void 0,
@@ -145,7 +145,7 @@ var defaultTokens = [{
145
145
  }, {
146
146
  name: "USDT",
147
147
  symbol: "USDT",
148
- logo: "https://assets.coingecko.com/coins/images/325/small/Tether.png",
148
+ logo: "https://assets.strkfarm.com/integrations/tokens/usdc.svg",
149
149
  address: ContractAddr.from("0x68f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8"),
150
150
  decimals: 6,
151
151
  coingeckId: void 0,
@@ -153,7 +153,7 @@ var defaultTokens = [{
153
153
  }, {
154
154
  name: "WBTC",
155
155
  symbol: "WBTC",
156
- logo: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/logo.png",
156
+ logo: "https://assets.strkfarm.com/integrations/tokens/wbtc.svg",
157
157
  address: ContractAddr.from("0x3fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac"),
158
158
  decimals: 8,
159
159
  coingeckId: void 0,
@@ -177,7 +177,7 @@ var Global = class _Global {
177
177
  }
178
178
  static async getTokens() {
179
179
  if (tokens.length) return tokens;
180
- const data = await axios.get("https://starknet.api.avnu.fi/v1/starknet/tokens");
180
+ const data = await axios.get("https://assets.strkfarm.com/integrations/tokens.json");
181
181
  const tokensData = data.data.content;
182
182
  tokensData.forEach((token) => {
183
183
  if (!token.tags.includes("AVNU") || !token.tags.includes("Verified")) {
@@ -18630,11 +18630,10 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
18630
18630
  * @returns Array of contract calls needed for rebalancing
18631
18631
  * @throws Error if max retries reached without successful rebalance
18632
18632
  */
18633
- async rebalanceIter(swapInfo, acc, estimateCall, retry = 0, adjustmentFactor = 1, isToken0Deficit = true) {
18634
- const MAX_RETRIES = 20;
18635
- const MIN_ADJUSTMENT = 1e-3;
18633
+ async rebalanceIter(swapInfo, acc, estimateCall, isSellTokenToken0 = true, retry = 0, lowerLimit = 0n, upperLimit = 0n) {
18634
+ const MAX_RETRIES = 40;
18636
18635
  logger.verbose(
18637
- `Rebalancing ${this.metadata.name}: retry=${retry}, adjustment=${adjustmentFactor}%, token0Deficit=${isToken0Deficit}`
18636
+ `Rebalancing ${this.metadata.name}: retry=${retry}, lowerLimit=${lowerLimit}, upperLimit=${upperLimit}, isSellTokenToken0=${isSellTokenToken0}`
18638
18637
  );
18639
18638
  const fromAmount = uint2564.uint256ToBN(swapInfo.token_from_amount);
18640
18639
  logger.verbose(
@@ -18649,38 +18648,69 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
18649
18648
  logger.error(`Rebalance failed after ${MAX_RETRIES} retries`);
18650
18649
  throw err;
18651
18650
  }
18652
- if (adjustmentFactor < MIN_ADJUSTMENT) {
18653
- logger.error("Adjustment factor too small, likely oscillating");
18654
- throw new Error("Failed to converge on valid swap amount");
18655
- }
18656
18651
  logger.error(`Rebalance attempt ${retry + 1} failed, adjusting swap amount...`);
18657
18652
  const newSwapInfo = { ...swapInfo };
18658
18653
  const currentAmount = Web3Number.fromWei(fromAmount.toString(), 18);
18654
+ logger.verbose(`Current amount: ${currentAmount.toString()}`);
18659
18655
  if (err.message.includes("invalid token0 balance") || err.message.includes("invalid token0 amount")) {
18660
- logger.verbose("Reducing swap amount - excess token0");
18661
- newSwapInfo.token_from_amount = uint2564.bnToUint256(
18662
- currentAmount.multipliedBy((100 - adjustmentFactor) / 100).toWei()
18663
- );
18664
- adjustmentFactor = isToken0Deficit ? adjustmentFactor * 2 : adjustmentFactor / 2;
18665
- isToken0Deficit = true;
18666
- } else if (err.message.includes("invalid token1 balance") || err.message.includes("invalid token1 amount")) {
18667
- logger.verbose("Increasing swap amount - excess token1");
18668
- newSwapInfo.token_from_amount = uint2564.bnToUint256(
18669
- currentAmount.multipliedBy((100 + adjustmentFactor) / 100).toWei()
18670
- );
18671
- adjustmentFactor = isToken0Deficit ? adjustmentFactor / 2 : adjustmentFactor * 2;
18672
- 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
+ }
18673
18701
  } else {
18674
18702
  logger.error("Unexpected error:", err);
18703
+ throw err;
18675
18704
  }
18676
18705
  newSwapInfo.token_to_min_amount = uint2564.bnToUint256("0");
18677
18706
  return this.rebalanceIter(
18678
18707
  newSwapInfo,
18679
18708
  acc,
18680
18709
  estimateCall,
18710
+ isSellTokenToken0,
18681
18711
  retry + 1,
18682
- adjustmentFactor,
18683
- isToken0Deficit
18712
+ lowerLimit,
18713
+ upperLimit
18684
18714
  );
18685
18715
  }
18686
18716
  }
package/dist/index.d.ts CHANGED
@@ -717,7 +717,7 @@ declare class EkuboCLVault extends BaseStrategy<DualTokenInfo, DualActionAmount>
717
717
  * @returns Array of contract calls needed for rebalancing
718
718
  * @throws Error if max retries reached without successful rebalance
719
719
  */
720
- 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[]>;
721
721
  static tickToi129(tick: number): {
722
722
  mag: number;
723
723
  sign: number;
package/dist/index.js CHANGED
@@ -194,7 +194,7 @@ var FatalError = class extends Error {
194
194
  var defaultTokens = [{
195
195
  name: "Starknet",
196
196
  symbol: "STRK",
197
- logo: "https://assets.coingecko.com/coins/images/26433/small/starknet.png",
197
+ logo: "https://assets.strkfarm.com/integrations/tokens/strk.svg",
198
198
  address: ContractAddr.from("0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"),
199
199
  decimals: 18,
200
200
  coingeckId: "starknet",
@@ -202,7 +202,7 @@ var defaultTokens = [{
202
202
  }, {
203
203
  name: "xSTRK",
204
204
  symbol: "xSTRK",
205
- logo: "https://dashboard.endur.fi/endur-fi.svg",
205
+ logo: "https://assets.strkfarm.com/integrations/tokens/xstrk.svg",
206
206
  address: ContractAddr.from("0x028d709c875c0ceac3dce7065bec5328186dc89fe254527084d1689910954b0a"),
207
207
  decimals: 18,
208
208
  coingeckId: void 0,
@@ -210,7 +210,7 @@ var defaultTokens = [{
210
210
  }, {
211
211
  name: "ETH",
212
212
  symbol: "ETH",
213
- logo: "https://opbnb.bscscan.com/token/images/ether.svg",
213
+ logo: "https://assets.strkfarm.com/integrations/tokens/eth.svg",
214
214
  address: ContractAddr.from("0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"),
215
215
  decimals: 18,
216
216
  coingeckId: void 0,
@@ -218,7 +218,7 @@ var defaultTokens = [{
218
218
  }, {
219
219
  name: "USDC",
220
220
  symbol: "USDC",
221
- logo: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
221
+ logo: "https://assets.strkfarm.com/integrations/tokens/usdc.svg",
222
222
  address: ContractAddr.from("0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8"),
223
223
  decimals: 6,
224
224
  coingeckId: void 0,
@@ -226,7 +226,7 @@ var defaultTokens = [{
226
226
  }, {
227
227
  name: "USDT",
228
228
  symbol: "USDT",
229
- logo: "https://assets.coingecko.com/coins/images/325/small/Tether.png",
229
+ logo: "https://assets.strkfarm.com/integrations/tokens/usdc.svg",
230
230
  address: ContractAddr.from("0x68f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8"),
231
231
  decimals: 6,
232
232
  coingeckId: void 0,
@@ -234,7 +234,7 @@ var defaultTokens = [{
234
234
  }, {
235
235
  name: "WBTC",
236
236
  symbol: "WBTC",
237
- logo: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/logo.png",
237
+ logo: "https://assets.strkfarm.com/integrations/tokens/wbtc.svg",
238
238
  address: ContractAddr.from("0x3fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac"),
239
239
  decimals: 8,
240
240
  coingeckId: void 0,
@@ -258,7 +258,7 @@ var Global = class _Global {
258
258
  }
259
259
  static async getTokens() {
260
260
  if (tokens.length) return tokens;
261
- const data = await import_axios.default.get("https://starknet.api.avnu.fi/v1/starknet/tokens");
261
+ const data = await import_axios.default.get("https://assets.strkfarm.com/integrations/tokens.json");
262
262
  const tokensData = data.data.content;
263
263
  tokensData.forEach((token) => {
264
264
  if (!token.tags.includes("AVNU") || !token.tags.includes("Verified")) {
@@ -18719,11 +18719,10 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
18719
18719
  * @returns Array of contract calls needed for rebalancing
18720
18720
  * @throws Error if max retries reached without successful rebalance
18721
18721
  */
18722
- async rebalanceIter(swapInfo, acc, estimateCall, retry = 0, adjustmentFactor = 1, isToken0Deficit = true) {
18723
- const MAX_RETRIES = 20;
18724
- const MIN_ADJUSTMENT = 1e-3;
18722
+ async rebalanceIter(swapInfo, acc, estimateCall, isSellTokenToken0 = true, retry = 0, lowerLimit = 0n, upperLimit = 0n) {
18723
+ const MAX_RETRIES = 40;
18725
18724
  logger.verbose(
18726
- `Rebalancing ${this.metadata.name}: retry=${retry}, adjustment=${adjustmentFactor}%, token0Deficit=${isToken0Deficit}`
18725
+ `Rebalancing ${this.metadata.name}: retry=${retry}, lowerLimit=${lowerLimit}, upperLimit=${upperLimit}, isSellTokenToken0=${isSellTokenToken0}`
18727
18726
  );
18728
18727
  const fromAmount = import_starknet9.uint256.uint256ToBN(swapInfo.token_from_amount);
18729
18728
  logger.verbose(
@@ -18738,38 +18737,69 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
18738
18737
  logger.error(`Rebalance failed after ${MAX_RETRIES} retries`);
18739
18738
  throw err;
18740
18739
  }
18741
- if (adjustmentFactor < MIN_ADJUSTMENT) {
18742
- logger.error("Adjustment factor too small, likely oscillating");
18743
- throw new Error("Failed to converge on valid swap amount");
18744
- }
18745
18740
  logger.error(`Rebalance attempt ${retry + 1} failed, adjusting swap amount...`);
18746
18741
  const newSwapInfo = { ...swapInfo };
18747
18742
  const currentAmount = Web3Number.fromWei(fromAmount.toString(), 18);
18743
+ logger.verbose(`Current amount: ${currentAmount.toString()}`);
18748
18744
  if (err.message.includes("invalid token0 balance") || err.message.includes("invalid token0 amount")) {
18749
- logger.verbose("Reducing swap amount - excess token0");
18750
- newSwapInfo.token_from_amount = import_starknet9.uint256.bnToUint256(
18751
- currentAmount.multipliedBy((100 - adjustmentFactor) / 100).toWei()
18752
- );
18753
- adjustmentFactor = isToken0Deficit ? adjustmentFactor * 2 : adjustmentFactor / 2;
18754
- isToken0Deficit = true;
18755
- } else if (err.message.includes("invalid token1 balance") || err.message.includes("invalid token1 amount")) {
18756
- logger.verbose("Increasing swap amount - excess token1");
18757
- newSwapInfo.token_from_amount = import_starknet9.uint256.bnToUint256(
18758
- currentAmount.multipliedBy((100 + adjustmentFactor) / 100).toWei()
18759
- );
18760
- adjustmentFactor = isToken0Deficit ? adjustmentFactor / 2 : adjustmentFactor * 2;
18761
- 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
+ }
18762
18790
  } else {
18763
18791
  logger.error("Unexpected error:", err);
18792
+ throw err;
18764
18793
  }
18765
18794
  newSwapInfo.token_to_min_amount = import_starknet9.uint256.bnToUint256("0");
18766
18795
  return this.rebalanceIter(
18767
18796
  newSwapInfo,
18768
18797
  acc,
18769
18798
  estimateCall,
18799
+ isSellTokenToken0,
18770
18800
  retry + 1,
18771
- adjustmentFactor,
18772
- isToken0Deficit
18801
+ lowerLimit,
18802
+ upperLimit
18773
18803
  );
18774
18804
  }
18775
18805
  }
package/dist/index.mjs CHANGED
@@ -125,7 +125,7 @@ var FatalError = class extends Error {
125
125
  var defaultTokens = [{
126
126
  name: "Starknet",
127
127
  symbol: "STRK",
128
- logo: "https://assets.coingecko.com/coins/images/26433/small/starknet.png",
128
+ logo: "https://assets.strkfarm.com/integrations/tokens/strk.svg",
129
129
  address: ContractAddr.from("0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"),
130
130
  decimals: 18,
131
131
  coingeckId: "starknet",
@@ -133,7 +133,7 @@ var defaultTokens = [{
133
133
  }, {
134
134
  name: "xSTRK",
135
135
  symbol: "xSTRK",
136
- logo: "https://dashboard.endur.fi/endur-fi.svg",
136
+ logo: "https://assets.strkfarm.com/integrations/tokens/xstrk.svg",
137
137
  address: ContractAddr.from("0x028d709c875c0ceac3dce7065bec5328186dc89fe254527084d1689910954b0a"),
138
138
  decimals: 18,
139
139
  coingeckId: void 0,
@@ -141,7 +141,7 @@ var defaultTokens = [{
141
141
  }, {
142
142
  name: "ETH",
143
143
  symbol: "ETH",
144
- logo: "https://opbnb.bscscan.com/token/images/ether.svg",
144
+ logo: "https://assets.strkfarm.com/integrations/tokens/eth.svg",
145
145
  address: ContractAddr.from("0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"),
146
146
  decimals: 18,
147
147
  coingeckId: void 0,
@@ -149,7 +149,7 @@ var defaultTokens = [{
149
149
  }, {
150
150
  name: "USDC",
151
151
  symbol: "USDC",
152
- logo: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
152
+ logo: "https://assets.strkfarm.com/integrations/tokens/usdc.svg",
153
153
  address: ContractAddr.from("0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8"),
154
154
  decimals: 6,
155
155
  coingeckId: void 0,
@@ -157,7 +157,7 @@ var defaultTokens = [{
157
157
  }, {
158
158
  name: "USDT",
159
159
  symbol: "USDT",
160
- logo: "https://assets.coingecko.com/coins/images/325/small/Tether.png",
160
+ logo: "https://assets.strkfarm.com/integrations/tokens/usdc.svg",
161
161
  address: ContractAddr.from("0x68f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8"),
162
162
  decimals: 6,
163
163
  coingeckId: void 0,
@@ -165,7 +165,7 @@ var defaultTokens = [{
165
165
  }, {
166
166
  name: "WBTC",
167
167
  symbol: "WBTC",
168
- logo: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/logo.png",
168
+ logo: "https://assets.strkfarm.com/integrations/tokens/wbtc.svg",
169
169
  address: ContractAddr.from("0x3fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac"),
170
170
  decimals: 8,
171
171
  coingeckId: void 0,
@@ -189,7 +189,7 @@ var Global = class _Global {
189
189
  }
190
190
  static async getTokens() {
191
191
  if (tokens.length) return tokens;
192
- const data = await axios.get("https://starknet.api.avnu.fi/v1/starknet/tokens");
192
+ const data = await axios.get("https://assets.strkfarm.com/integrations/tokens.json");
193
193
  const tokensData = data.data.content;
194
194
  tokensData.forEach((token) => {
195
195
  if (!token.tags.includes("AVNU") || !token.tags.includes("Verified")) {
@@ -18650,11 +18650,10 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
18650
18650
  * @returns Array of contract calls needed for rebalancing
18651
18651
  * @throws Error if max retries reached without successful rebalance
18652
18652
  */
18653
- async rebalanceIter(swapInfo, acc, estimateCall, retry = 0, adjustmentFactor = 1, isToken0Deficit = true) {
18654
- const MAX_RETRIES = 20;
18655
- const MIN_ADJUSTMENT = 1e-3;
18653
+ async rebalanceIter(swapInfo, acc, estimateCall, isSellTokenToken0 = true, retry = 0, lowerLimit = 0n, upperLimit = 0n) {
18654
+ const MAX_RETRIES = 40;
18656
18655
  logger.verbose(
18657
- `Rebalancing ${this.metadata.name}: retry=${retry}, adjustment=${adjustmentFactor}%, token0Deficit=${isToken0Deficit}`
18656
+ `Rebalancing ${this.metadata.name}: retry=${retry}, lowerLimit=${lowerLimit}, upperLimit=${upperLimit}, isSellTokenToken0=${isSellTokenToken0}`
18658
18657
  );
18659
18658
  const fromAmount = uint2564.uint256ToBN(swapInfo.token_from_amount);
18660
18659
  logger.verbose(
@@ -18669,38 +18668,69 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
18669
18668
  logger.error(`Rebalance failed after ${MAX_RETRIES} retries`);
18670
18669
  throw err;
18671
18670
  }
18672
- if (adjustmentFactor < MIN_ADJUSTMENT) {
18673
- logger.error("Adjustment factor too small, likely oscillating");
18674
- throw new Error("Failed to converge on valid swap amount");
18675
- }
18676
18671
  logger.error(`Rebalance attempt ${retry + 1} failed, adjusting swap amount...`);
18677
18672
  const newSwapInfo = { ...swapInfo };
18678
18673
  const currentAmount = Web3Number.fromWei(fromAmount.toString(), 18);
18674
+ logger.verbose(`Current amount: ${currentAmount.toString()}`);
18679
18675
  if (err.message.includes("invalid token0 balance") || err.message.includes("invalid token0 amount")) {
18680
- logger.verbose("Reducing swap amount - excess token0");
18681
- newSwapInfo.token_from_amount = uint2564.bnToUint256(
18682
- currentAmount.multipliedBy((100 - adjustmentFactor) / 100).toWei()
18683
- );
18684
- adjustmentFactor = isToken0Deficit ? adjustmentFactor * 2 : adjustmentFactor / 2;
18685
- isToken0Deficit = true;
18686
- } else if (err.message.includes("invalid token1 balance") || err.message.includes("invalid token1 amount")) {
18687
- logger.verbose("Increasing swap amount - excess token1");
18688
- newSwapInfo.token_from_amount = uint2564.bnToUint256(
18689
- currentAmount.multipliedBy((100 + adjustmentFactor) / 100).toWei()
18690
- );
18691
- adjustmentFactor = isToken0Deficit ? adjustmentFactor / 2 : adjustmentFactor * 2;
18692
- 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
+ }
18693
18721
  } else {
18694
18722
  logger.error("Unexpected error:", err);
18723
+ throw err;
18695
18724
  }
18696
18725
  newSwapInfo.token_to_min_amount = uint2564.bnToUint256("0");
18697
18726
  return this.rebalanceIter(
18698
18727
  newSwapInfo,
18699
18728
  acc,
18700
18729
  estimateCall,
18730
+ isSellTokenToken0,
18701
18731
  retry + 1,
18702
- adjustmentFactor,
18703
- isToken0Deficit
18732
+ lowerLimit,
18733
+ upperLimit
18704
18734
  );
18705
18735
  }
18706
18736
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strkfarm/sdk",
3
- "version": "1.0.32",
3
+ "version": "1.0.34",
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",
package/src/global.ts CHANGED
@@ -49,7 +49,7 @@ export class FatalError extends Error {
49
49
  const defaultTokens: TokenInfo[] = [{
50
50
  name: 'Starknet',
51
51
  symbol: 'STRK',
52
- logo: 'https://assets.coingecko.com/coins/images/26433/small/starknet.png',
52
+ logo: 'https://assets.strkfarm.com/integrations/tokens/strk.svg',
53
53
  address: ContractAddr.from('0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d'),
54
54
  decimals: 18,
55
55
  coingeckId: 'starknet',
@@ -57,7 +57,7 @@ const defaultTokens: TokenInfo[] = [{
57
57
  }, {
58
58
  name: 'xSTRK',
59
59
  symbol: 'xSTRK',
60
- logo: 'https://dashboard.endur.fi/endur-fi.svg',
60
+ logo: 'https://assets.strkfarm.com/integrations/tokens/xstrk.svg',
61
61
  address: ContractAddr.from('0x028d709c875c0ceac3dce7065bec5328186dc89fe254527084d1689910954b0a'),
62
62
  decimals: 18,
63
63
  coingeckId: undefined,
@@ -65,7 +65,7 @@ const defaultTokens: TokenInfo[] = [{
65
65
  }, {
66
66
  name: 'ETH',
67
67
  symbol: 'ETH',
68
- logo: 'https://opbnb.bscscan.com/token/images/ether.svg',
68
+ logo: 'https://assets.strkfarm.com/integrations/tokens/eth.svg',
69
69
  address: ContractAddr.from('0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7'),
70
70
  decimals: 18,
71
71
  coingeckId: undefined,
@@ -73,7 +73,7 @@ const defaultTokens: TokenInfo[] = [{
73
73
  }, {
74
74
  name: 'USDC',
75
75
  symbol: 'USDC',
76
- logo: 'https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png',
76
+ logo: 'https://assets.strkfarm.com/integrations/tokens/usdc.svg',
77
77
  address: ContractAddr.from('0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8'),
78
78
  decimals: 6,
79
79
  coingeckId: undefined,
@@ -81,7 +81,7 @@ const defaultTokens: TokenInfo[] = [{
81
81
  }, {
82
82
  name: 'USDT',
83
83
  symbol: 'USDT',
84
- logo: 'https://assets.coingecko.com/coins/images/325/small/Tether.png',
84
+ logo: 'https://assets.strkfarm.com/integrations/tokens/usdc.svg',
85
85
  address: ContractAddr.from('0x68f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8'),
86
86
  decimals: 6,
87
87
  coingeckId: undefined,
@@ -89,7 +89,7 @@ const defaultTokens: TokenInfo[] = [{
89
89
  }, {
90
90
  name: 'WBTC',
91
91
  symbol: 'WBTC',
92
- logo: 'https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/logo.png',
92
+ logo: 'https://assets.strkfarm.com/integrations/tokens/wbtc.svg',
93
93
  address: ContractAddr.from('0x3fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac'),
94
94
  decimals: 8,
95
95
  coingeckId: undefined,
@@ -122,7 +122,7 @@ export class Global {
122
122
  if (tokens.length) return tokens;
123
123
 
124
124
  // fetch from avnu API
125
- const data = await axios.get('https://starknet.api.avnu.fi/v1/starknet/tokens');
125
+ const data = await axios.get('https://assets.strkfarm.com/integrations/tokens.json');
126
126
  const tokensData = data.data.content;
127
127
 
128
128
  // Array of the following is returned