@strkfarm/sdk 2.0.0-dev.4 → 2.0.0-dev.40

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.
Files changed (77) hide show
  1. package/dist/cli.js +190 -36
  2. package/dist/cli.mjs +188 -34
  3. package/dist/index.browser.global.js +116018 -90768
  4. package/dist/index.browser.mjs +12769 -10876
  5. package/dist/index.d.ts +2222 -1947
  6. package/dist/index.js +13171 -11077
  7. package/dist/index.mjs +13076 -11004
  8. package/package.json +3 -3
  9. package/src/data/avnu.abi.json +840 -0
  10. package/src/data/ekubo-price-fethcer.abi.json +265 -0
  11. package/src/data/redeem-request-nft.abi.json +752 -0
  12. package/src/data/universal-vault.abi.json +8 -7
  13. package/src/dataTypes/_bignumber.ts +13 -4
  14. package/src/dataTypes/bignumber.browser.ts +10 -1
  15. package/src/dataTypes/bignumber.node.ts +10 -1
  16. package/src/dataTypes/index.ts +3 -2
  17. package/src/dataTypes/mynumber.ts +141 -0
  18. package/src/global.ts +96 -41
  19. package/src/index.browser.ts +2 -1
  20. package/src/interfaces/common.tsx +212 -5
  21. package/src/modules/apollo-client-config.ts +28 -0
  22. package/src/modules/avnu.ts +21 -12
  23. package/src/modules/ekubo-pricer.ts +79 -0
  24. package/src/modules/ekubo-quoter.ts +48 -30
  25. package/src/modules/erc20.ts +17 -0
  26. package/src/modules/harvests.ts +43 -29
  27. package/src/modules/index.ts +1 -1
  28. package/src/modules/pragma.ts +23 -8
  29. package/src/modules/pricer-from-api.ts +156 -15
  30. package/src/modules/pricer-lst.ts +1 -1
  31. package/src/modules/pricer.ts +40 -4
  32. package/src/modules/pricerBase.ts +2 -1
  33. package/src/node/deployer.ts +36 -1
  34. package/src/node/pricer-redis.ts +2 -1
  35. package/src/strategies/base-strategy.ts +168 -16
  36. package/src/strategies/constants.ts +8 -3
  37. package/src/strategies/ekubo-cl-vault.tsx +1044 -351
  38. package/src/strategies/factory.ts +199 -0
  39. package/src/strategies/index.ts +5 -3
  40. package/src/strategies/registry.ts +262 -0
  41. package/src/strategies/sensei.ts +353 -9
  42. package/src/strategies/svk-strategy.ts +125 -30
  43. package/src/strategies/token-boosted-xstrk-carry-strategy.tsx +1225 -0
  44. package/src/strategies/types.ts +4 -0
  45. package/src/strategies/universal-adapters/adapter-utils.ts +4 -1
  46. package/src/strategies/universal-adapters/avnu-adapter.ts +196 -272
  47. package/src/strategies/universal-adapters/baseAdapter.ts +263 -251
  48. package/src/strategies/universal-adapters/common-adapter.ts +206 -203
  49. package/src/strategies/universal-adapters/index.ts +10 -8
  50. package/src/strategies/universal-adapters/svk-troves-adapter.ts +511 -0
  51. package/src/strategies/universal-adapters/token-transfer-adapter.ts +200 -0
  52. package/src/strategies/universal-adapters/vesu-adapter.ts +120 -82
  53. package/src/strategies/universal-adapters/vesu-modify-position-adapter.ts +525 -0
  54. package/src/strategies/universal-adapters/vesu-multiply-adapter.ts +1098 -712
  55. package/src/strategies/universal-adapters/vesu-position-common.ts +258 -0
  56. package/src/strategies/universal-adapters/vesu-supply-only-adapter.ts +18 -3
  57. package/src/strategies/universal-lst-muliplier-strategy.tsx +551 -405
  58. package/src/strategies/universal-strategy.tsx +1487 -1173
  59. package/src/strategies/vesu-rebalance.tsx +252 -152
  60. package/src/strategies/yoloVault.ts +1084 -0
  61. package/src/utils/cacheClass.ts +11 -2
  62. package/src/utils/health-factor-math.ts +33 -1
  63. package/src/utils/index.ts +3 -1
  64. package/src/utils/logger.browser.ts +22 -4
  65. package/src/utils/logger.node.ts +259 -24
  66. package/src/utils/starknet-call-parser.ts +1036 -0
  67. package/src/utils/strategy-utils.ts +61 -0
  68. package/src/modules/ExtendedWrapperSDk/index.ts +0 -62
  69. package/src/modules/ExtendedWrapperSDk/types.ts +0 -311
  70. package/src/modules/ExtendedWrapperSDk/wrapper.ts +0 -395
  71. package/src/strategies/universal-adapters/extended-adapter.ts +0 -661
  72. package/src/strategies/universal-adapters/unused-balance-adapter.ts +0 -109
  73. package/src/strategies/vesu-extended-strategy/services/operationService.ts +0 -34
  74. package/src/strategies/vesu-extended-strategy/utils/config.runtime.ts +0 -77
  75. package/src/strategies/vesu-extended-strategy/utils/constants.ts +0 -49
  76. package/src/strategies/vesu-extended-strategy/utils/helper.ts +0 -372
  77. package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +0 -1140
@@ -11,8 +11,16 @@ import {
11
11
  Protocols,
12
12
  RiskFactor,
13
13
  RiskType,
14
+ StrategyTag,
14
15
  TokenInfo,
15
16
  VaultPosition,
17
+ AuditStatus,
18
+ SourceCodeType,
19
+ AccessControlType,
20
+ InstantWithdrawalVault,
21
+ VaultType,
22
+ StrategyLiveStatus,
23
+ UnwrapLabsCurator,
16
24
  } from "@/interfaces";
17
25
  import { PricerBase } from "@/modules/pricerBase";
18
26
  import { assert } from "@/utils";
@@ -30,18 +38,25 @@ import EkuboMathAbi from "@/data/ekubo-math.abi.json";
30
38
  import ERC4626Abi from "@/data/erc4626.abi.json";
31
39
  import { Global } from "@/global";
32
40
  import { AvnuWrapper, ERC20, SwapInfo } from "@/modules";
33
- import { APYInfo, BaseStrategy, SingleTokenInfo } from "./base-strategy";
41
+ import {
42
+ APYInfo,
43
+ BaseStrategy,
44
+ SingleTokenInfo,
45
+ UserPositionCard,
46
+ UserPositionCardsInput,
47
+ } from "./base-strategy";
34
48
  import { DualActionAmount } from "./base-strategy";
35
49
  import { DualTokenInfo } from "./base-strategy";
36
50
  import { log } from "winston";
37
51
  import { EkuboHarvests, HarvestInfo } from "@/modules/harvests";
38
52
  import { logger } from "@/utils/logger";
39
- import { COMMON_CONTRACTS } from "./constants";
40
53
  import { DepegRiskLevel, ImpermanentLossLevel, MarketRiskLevel, SmartContractRiskLevel } from "@/interfaces/risks";
41
- import { gql } from "@apollo/client";
54
+ import { from, gql } from "@apollo/client";
42
55
  import apolloClient from "@/modules/apollo-client";
43
56
  import { binarySearch } from "@/utils/math-utils";
44
57
  import { PositionInfo } from "./universal-adapters/baseAdapter";
58
+ import { Quote } from "@avnu/avnu-sdk";
59
+ import { MY_ACCESS_CONTROL } from "./constants";
45
60
 
46
61
  export interface EkuboPoolKey {
47
62
  token0: ContractAddr;
@@ -118,7 +133,10 @@ export class EkuboCLVault extends BaseStrategy<
118
133
  pricer: PricerBase,
119
134
  metadata: IStrategyMetadata<CLVaultStrategySettings>
120
135
  ) {
121
- super(config);
136
+ super(config, {
137
+ depositInputMode: "dual",
138
+ withdrawInputMode: "dual"
139
+ });
122
140
  this.pricer = pricer;
123
141
 
124
142
  assert(
@@ -296,7 +314,10 @@ export class EkuboCLVault extends BaseStrategy<
296
314
  return [this.contract.populate("handle_fees", [])];
297
315
  }
298
316
 
299
- async getFeeHistory(timePeriod: '24h' | '7d' | '30d' | '3m' = '24h'): Promise<{
317
+ async getFeeHistory(
318
+ timePeriod: '24h' | '7d' | '30d' | '3m' | '6m' = '24h',
319
+ range?: { startTimestamp?: number; endTimestamp?: number }
320
+ ): Promise<{
300
321
  summary: DualTokenInfo,
301
322
  history: FeeHistory[]
302
323
  }> {
@@ -305,8 +326,15 @@ export class EkuboCLVault extends BaseStrategy<
305
326
  query ContractFeeEarnings(
306
327
  $timeframe: String!
307
328
  $contract: String!
329
+ $startTimestamp: Float
330
+ $endTimestamp: Float
308
331
  ) {
309
- contractFeeEarnings(timeframe: $timeframe, contract: $contract) {
332
+ contractFeeEarnings(
333
+ timeframe: $timeframe
334
+ contract: $contract
335
+ startTimestamp: $startTimestamp
336
+ endTimestamp: $endTimestamp
337
+ ) {
310
338
  contract
311
339
  dailyEarnings {
312
340
  date
@@ -319,7 +347,9 @@ export class EkuboCLVault extends BaseStrategy<
319
347
  `,
320
348
  variables: {
321
349
  timeframe: timePeriod,
322
- contract: this.address.address
350
+ contract: this.address.address,
351
+ startTimestamp: range?.startTimestamp,
352
+ endTimestamp: range?.endTimestamp
323
353
  },
324
354
  fetchPolicy: 'no-cache',
325
355
  });
@@ -418,22 +448,41 @@ export class EkuboCLVault extends BaseStrategy<
418
448
  const tvlBefore = await this._getTVL(blockBefore);
419
449
  const supplyBefore = await this.totalSupply(blockBefore);
420
450
  const priceBefore = await this.getCurrentPrice(blockBefore);
421
-
422
- const tvlInToken0Now = (tvlNow.amount0
423
- .multipliedBy(priceNow.price))
424
- .plus(tvlNow.amount1);
425
- const tvlPerShareNow = tvlInToken0Now
451
+ const poolKey = await this.getPoolKey(blockBefore);
452
+ logger.verbose(`priceBefore: ${priceBefore.price.toString()}`);
453
+ logger.verbose(`priceNow: ${priceNow.price.toString()}`);
454
+ logger.verbose(`tvlBefore: ${JSON.stringify(tvlBefore)}`);
455
+ logger.verbose(`tvlNow: ${JSON.stringify(tvlNow)}`);
456
+
457
+ const isQuoteTokenToken0 = this.metadata.additionalInfo.quoteAsset.address.eq(poolKey.token0);
458
+ logger.verbose(`isQuoteTokenToken0: ${isQuoteTokenToken0}`);
459
+ let tvlBeforeInBaseAsset = Web3Number.fromWei(0, this.metadata.additionalInfo.quoteAsset.decimals);
460
+ let tvlNowInBaseAsset = Web3Number.fromWei(0, this.metadata.additionalInfo.quoteAsset.decimals);
461
+ if (!isQuoteTokenToken0) {
462
+ tvlNowInBaseAsset = (tvlNow.amount0
463
+ .multipliedBy(priceNow.price))
464
+ .plus(tvlNow.amount1);
465
+ tvlBeforeInBaseAsset = (tvlBefore.amount0
466
+ .multipliedBy(priceBefore.price))
467
+ .plus(tvlBefore.amount1);
468
+ } else {
469
+ tvlNowInBaseAsset = (tvlNow.amount1
470
+ .multipliedBy(1 / priceNow.price))
471
+ .plus(tvlNow.amount0);
472
+ tvlBeforeInBaseAsset = (tvlBefore.amount1
473
+ .multipliedBy(1 / priceBefore.price))
474
+ .plus(tvlBefore.amount0);
475
+ }
476
+ const tvlPerShareNow = tvlNowInBaseAsset
426
477
  .multipliedBy(1e18)
427
478
  .dividedBy(adjustedSupplyNow.toString());
428
- const tvlInToken0Bf = (tvlBefore.amount0
429
- .multipliedBy(priceBefore.price))
430
- .plus(tvlBefore.amount1);
431
- const tvlPerShareBf = tvlInToken0Bf
479
+
480
+ const tvlPerShareBf = tvlBeforeInBaseAsset
432
481
  .multipliedBy(1e18)
433
482
  .dividedBy(supplyBefore.toString());
434
483
  const timeDiffSeconds = blockNowTime - blockBeforeInfo.timestamp;
435
- logger.verbose(`tvlInToken0Now: ${tvlInToken0Now.toString()}`);
436
- logger.verbose(`tvlInToken0Bf: ${tvlInToken0Bf.toString()}`);
484
+ logger.verbose(`tvlNowInBaseAsset: ${tvlNowInBaseAsset.toString()}`);
485
+ logger.verbose(`tvlBeforeInBaseAsset: ${tvlBeforeInBaseAsset.toString()}`);
437
486
  logger.verbose(`tvlPerShareNow: ${tvlPerShareNow.toString()}`);
438
487
  logger.verbose(`tvlPerShareBf: ${tvlPerShareBf.toString()}`);
439
488
  logger.verbose(`Price before: ${priceBefore.price.toString()}`);
@@ -451,6 +500,204 @@ export class EkuboCLVault extends BaseStrategy<
451
500
  return (apyForGivenBlocks * (365 * 24 * 3600)) / timeDiffSeconds;
452
501
  }
453
502
 
503
+ /**
504
+ * Calculate lifetime earnings for a user
505
+ * Not yet implemented for Ekubo CL Vault strategy
506
+ */
507
+ getLifetimeEarnings(
508
+ userTVL: SingleTokenInfo,
509
+ investmentFlows: Array<{ amount: string; type: string; timestamp: number; tx_hash: string }>
510
+ ): any {
511
+ throw new Error("getLifetimeEarnings is not implemented yet for this strategy");
512
+ }
513
+
514
+ /**
515
+ * Calculates realized APY based on TVL per share growth, always valued in USDC.
516
+ * This is a vault-level metric (same for all users) and works for all strategies,
517
+ * regardless of quote asset configuration.
518
+ */
519
+ async getUserRealizedAPY(
520
+ blockIdentifier: BlockIdentifier = "latest",
521
+ sinceBlocks = 600000
522
+ ): Promise<number> {
523
+ throw new Error("getUserRealizedAPY not implemented yet for Ekubo CL Vault strategy");
524
+
525
+ /*
526
+ logger.verbose(
527
+ `${EkuboCLVault.name}: getUserRealizedAPY => starting with blockIdentifier=${blockIdentifier}, sinceBlocks=${sinceBlocks}`
528
+ );
529
+
530
+ // TVL amounts (in token units) at current reference block
531
+ const tvlNow = await this._getTVL(blockIdentifier);
532
+ const supplyNow = await this.totalSupply(blockIdentifier);
533
+
534
+ // Determine current block number and timestamp
535
+ let blockNow =
536
+ typeof blockIdentifier == "number"
537
+ ? blockIdentifier
538
+ : (await this.config.provider.getBlockLatestAccepted()).block_number;
539
+ const blockNowTime =
540
+ typeof blockIdentifier == "number"
541
+ ? (await this.config.provider.getBlockWithTxs(blockIdentifier))
542
+ .timestamp
543
+ : new Date().getTime() / 1000;
544
+
545
+ // Look back window, but never before launch block
546
+ const blockBefore = Math.max(
547
+ Number(blockNow) - sinceBlocks,
548
+ this.metadata.launchBlock
549
+ );
550
+
551
+ // Adjust current supply by subtracting harvest reward shares (same idea as netSharesBasedTrueAPY)
552
+ const adjustedSupplyNow = supplyNow.minus(
553
+ await this.getHarvestRewardShares(blockBefore, Number(blockNow))
554
+ );
555
+
556
+ // Historical block info and TVL
557
+ const blockBeforeInfo = await this.config.provider.getBlockWithTxs(
558
+ blockBefore
559
+ );
560
+ const tvlBefore = await this._getTVL(blockBefore);
561
+ const supplyBefore = await this.totalSupply(blockBefore);
562
+
563
+ // Always value TVL in USDC using the pricer for both tokens at both blocks
564
+ const token0Info = this.metadata.depositTokens[0];
565
+ const token1Info = this.metadata.depositTokens[1];
566
+
567
+ const P0Now = await this.pricer.getPrice(
568
+ token0Info.symbol,
569
+ Number(blockNow)
570
+ );
571
+ const P1Now = await this.pricer.getPrice(
572
+ token1Info.symbol,
573
+ Number(blockNow)
574
+ );
575
+ const P0Before = await this.pricer.getPrice(
576
+ token0Info.symbol,
577
+ blockBefore
578
+ );
579
+ const P1Before = await this.pricer.getPrice(
580
+ token1Info.symbol,
581
+ blockBefore
582
+ );
583
+
584
+ // Convert token balances to USDC TVL using current and historical prices
585
+ const tvlNowUsdNumber =
586
+ Number(tvlNow.amount0.toFixed(13)) * P0Now.price +
587
+ Number(tvlNow.amount1.toFixed(13)) * P1Now.price;
588
+ const tvlBeforeUsdNumber =
589
+ Number(tvlBefore.amount0.toFixed(13)) * P0Before.price +
590
+ Number(tvlBefore.amount1.toFixed(13)) * P1Before.price;
591
+
592
+ // Represent USDC TVL as Web3Number with 6 decimals (USDC standard)
593
+ const tvlNowInUSDC = new Web3Number(
594
+ tvlNowUsdNumber.toFixed(13),
595
+ 6
596
+ );
597
+ const tvlBeforeInUSDC = new Web3Number(
598
+ tvlBeforeUsdNumber.toFixed(13),
599
+ 6
600
+ );
601
+
602
+ const tvlPerShareNow = tvlNowInUSDC
603
+ .multipliedBy(1e18)
604
+ .dividedBy(adjustedSupplyNow.toString());
605
+
606
+ const tvlPerShareBf = tvlBeforeInUSDC
607
+ .multipliedBy(1e18)
608
+ .dividedBy(supplyBefore.toString());
609
+
610
+ const timeDiffSeconds = blockNowTime - blockBeforeInfo.timestamp;
611
+
612
+ logger.verbose(
613
+ `${EkuboCLVault.name}: getUserRealizedAPY => token0=${token0Info.symbol}, token1=${token1Info.symbol}`
614
+ );
615
+ logger.verbose(
616
+ `${EkuboCLVault.name}: getUserRealizedAPY => P0Now=${P0Now.price}, P1Now=${P1Now.price}, P0Before=${P0Before.price}, P1Before=${P1Before.price}`
617
+ );
618
+ logger.verbose(
619
+ `${EkuboCLVault.name}: getUserRealizedAPY => raw tvlNow amounts: token0=${tvlNow.amount0.toString()}, token1=${tvlNow.amount1.toString()}`
620
+ );
621
+ logger.verbose(
622
+ `${EkuboCLVault.name}: getUserRealizedAPY => raw tvlBefore amounts: token0=${tvlBefore.amount0.toString()}, token1=${tvlBefore.amount1.toString()}`
623
+ );
624
+ logger.verbose(
625
+ `${EkuboCLVault.name}: getUserRealizedAPY => tvlNowUsdNumber=${tvlNowUsdNumber}, tvlBeforeUsdNumber=${tvlBeforeUsdNumber}`
626
+ );
627
+ logger.verbose(
628
+ `${EkuboCLVault.name}: getUserRealizedAPY => tvlNowInUSDC: ${tvlNowInUSDC.toString()}, tvlBeforeInUSDC: ${tvlBeforeInUSDC.toString()}`
629
+ );
630
+ logger.verbose(
631
+ `${EkuboCLVault.name}: getUserRealizedAPY => tvlPerShareNow: ${tvlPerShareNow.toString()}, tvlPerShareBf: ${tvlPerShareBf.toString()}`
632
+ );
633
+ logger.verbose(
634
+ `${EkuboCLVault.name}: getUserRealizedAPY => Supply before: ${supplyBefore.toString()}, Supply now (adjusted): ${adjustedSupplyNow.toString()}`
635
+ );
636
+ logger.verbose(
637
+ `${EkuboCLVault.name}: getUserRealizedAPY => Time diff in seconds: ${timeDiffSeconds}`
638
+ );
639
+
640
+ const apyForGivenBlocks =
641
+ Number(
642
+ tvlPerShareNow
643
+ .minus(tvlPerShareBf)
644
+ .multipliedBy(10000)
645
+ .dividedBy(tvlPerShareBf)
646
+ ) / 10000;
647
+
648
+ return (apyForGivenBlocks * (365 * 24 * 3600)) / timeDiffSeconds;
649
+ */
650
+ }
651
+
652
+ async getMaxTVL(): Promise<Web3Number> {
653
+ // This strategy doesn't have a maxTVL so returning 0 simply
654
+ return new Web3Number('0', 18);
655
+ }
656
+
657
+ async getUserPositionCards(input: UserPositionCardsInput): Promise<UserPositionCard[]> {
658
+ const quoteToken = this.metadata.additionalInfo.quoteAsset;
659
+ const [userTVL, quotePrice] = await Promise.all([
660
+ this.getUserTVL(input.user),
661
+ this.pricer.getPrice(quoteToken.symbol),
662
+ ]);
663
+
664
+ const token0IsQuote = userTVL.token0.tokenInfo.address.eq(quoteToken.address);
665
+ const token1IsQuote = userTVL.token1.tokenInfo.address.eq(quoteToken.address);
666
+ const token0QuoteAmount = token0IsQuote
667
+ ? userTVL.token0.amount.toNumber()
668
+ : userTVL.token0.usdValue / (quotePrice.price || 1);
669
+ const token1QuoteAmount = token1IsQuote
670
+ ? userTVL.token1.amount.toNumber()
671
+ : userTVL.token1.usdValue / (quotePrice.price || 1);
672
+ const totalQuoteAmount = token0QuoteAmount + token1QuoteAmount;
673
+ const quoteAmountDisplay = Number.isFinite(totalQuoteAmount)
674
+ ? totalQuoteAmount.toLocaleString("en-US", {
675
+ maximumFractionDigits: quoteToken.displayDecimals ?? 2,
676
+ minimumFractionDigits: 0,
677
+ })
678
+ : "0";
679
+ const allocationValue = `${this.formatTokenAmountForCard(userTVL.token0.amount, userTVL.token0.tokenInfo)} / ${this.formatTokenAmountForCard(userTVL.token1.amount, userTVL.token1.tokenInfo)}`;
680
+ const allocationSubValue = `${this.formatUSDForCard(userTVL.token0.usdValue)} / ${this.formatUSDForCard(userTVL.token1.usdValue)}`;
681
+
682
+ const cards: UserPositionCard[] = [
683
+ {
684
+ title: "Your Holdings",
685
+ tooltip: `${quoteToken.symbol} equivalent value of your Ekubo position`,
686
+ value: `${quoteAmountDisplay} ${quoteToken.symbol}`,
687
+ subValue: `≈ ${this.formatUSDForCard(userTVL.usdValue)}`,
688
+ subValueColor: "positive",
689
+ },
690
+ {
691
+ title: "Holding Allocation",
692
+ tooltip: "Split of your position between token0 and token1",
693
+ value: allocationValue,
694
+ subValue: `≈ ${allocationSubValue}`,
695
+ subValueColor: "default",
696
+ },
697
+ ];
698
+ return cards;
699
+ }
700
+
454
701
  async feeBasedAPY(
455
702
  timeperiod: '24h' | '7d' | '30d' | '3m' = '24h'
456
703
  ): Promise<number> {
@@ -485,20 +732,15 @@ export class EkuboCLVault extends BaseStrategy<
485
732
  blockIdentifier: BlockIdentifier = "latest",
486
733
  sinceBlocks = 600000,
487
734
  timeperiod: '24h' | '7d' | '30d' | '3m' = '24h' // temp thing for fee based APY
488
- ): Promise<APYInfo> {
489
- const isUSDCQouteToken = this.metadata.additionalInfo.quoteAsset.symbol === "USDC";
735
+ ): Promise<number> {
736
+ // ! switch to USDC later
737
+ const isUSDCQouteToken = this.metadata.additionalInfo.quoteAsset.symbol === "USDC.e" || this.metadata.additionalInfo.quoteAsset.symbol === "USDC";
490
738
  if (!isUSDCQouteToken) {
491
739
  // good for LSTs and stables
492
- return {
493
- net: await this.netSharesBasedTrueAPY(blockIdentifier, sinceBlocks),
494
- splits: []
495
- };
740
+ return await this.netSharesBasedTrueAPY(blockIdentifier, sinceBlocks);
496
741
  } else {
497
742
  // good for non-stables
498
- return {
499
- net: await this.feeBasedAPY(timeperiod),
500
- splits: []
501
- };
743
+ return await this.feeBasedAPY(timeperiod);
502
744
  }
503
745
  }
504
746
 
@@ -559,8 +801,14 @@ export class EkuboCLVault extends BaseStrategy<
559
801
  assets.amount1.toString(),
560
802
  token1Info.decimals
561
803
  );
562
- const P0 = await this.pricer.getPrice(token0Info.symbol);
563
- const P1 = await this.pricer.getPrice(token1Info.symbol);
804
+
805
+ // Convert blockIdentifier to block number for pricer if it's a number
806
+ const blockNumber = typeof blockIdentifier === 'number' || typeof blockIdentifier === 'bigint'
807
+ ? Number(blockIdentifier)
808
+ : undefined;
809
+
810
+ const P0 = await this.pricer.getPrice(token0Info.symbol, blockNumber);
811
+ const P1 = await this.pricer.getPrice(token1Info.symbol, blockNumber);
564
812
  const token0Usd = Number(amount0.toFixed(13)) * P0.price;
565
813
  const token1Usd = Number(amount1.toFixed(13)) * P1.price;
566
814
 
@@ -627,8 +875,26 @@ export class EkuboCLVault extends BaseStrategy<
627
875
  const P1 = await this.pricer.getPrice(token1Info.symbol);
628
876
  const token0Usd = Number(amount0.toFixed(13)) * P0.price;
629
877
  const token1Usd = Number(amount1.toFixed(13)) * P1.price;
878
+ const totalUsdValue = token0Usd + token1Usd;
879
+
880
+ if (
881
+ (totalUsdValue === 0 || token0Usd === 0 || token1Usd === 0 || amount0.eq(0) || amount1.eq(0)) &&
882
+ this.metadata.settings?.liveStatus === StrategyLiveStatus.ACTIVE
883
+ ) {
884
+ logger.warn(
885
+ `${this.metadata.name}:getTVL - Zero value detected: ` +
886
+ `usdValue=${totalUsdValue}, ` +
887
+ `amount0=${amount0.toString()}, ` +
888
+ `amount1=${amount1.toString()}, ` +
889
+ `token0Price=${P0.price}, ` +
890
+ `token1Price=${P1.price}, ` +
891
+ `token0Usd=${token0Usd}, ` +
892
+ `token1Usd=${token1Usd}`
893
+ );
894
+ }
895
+
630
896
  return {
631
- usdValue: token0Usd + token1Usd,
897
+ usdValue: totalUsdValue,
632
898
  token0: {
633
899
  tokenInfo: token0Info,
634
900
  amount: amount0,
@@ -1026,6 +1292,12 @@ export class EkuboCLVault extends BaseStrategy<
1026
1292
  amount1: availableAmount1.minus(y),
1027
1293
  ratio: 0,
1028
1294
  };
1295
+ } else if (ratio.eq(Infinity)) {
1296
+ return {
1297
+ amount0: availableAmount0,
1298
+ amount1: Web3Number.fromWei("0", availableAmount1.decimals),
1299
+ ratio: Infinity,
1300
+ };
1029
1301
  }
1030
1302
  return {
1031
1303
  amount0: availableAmount0.plus(x),
@@ -1075,7 +1347,12 @@ export class EkuboCLVault extends BaseStrategy<
1075
1347
  };
1076
1348
  }
1077
1349
 
1078
- async getSwapInfoToHandleUnused(considerRebalance: boolean = true, newBounds: EkuboBounds | null = null, maxIterations = 20, priceRatioPrecision = 4): Promise<SwapInfo> {
1350
+ async getSwapInfoToHandleUnused(
1351
+ considerRebalance: boolean = true,
1352
+ newBounds: EkuboBounds | null = null,
1353
+ maxIterations = 20, priceRatioPrecision = 4,
1354
+ getQuoteCallback: (tokenToSell: string, tokenToBuy: string, amountWei: string, beneficiary: string) => Promise<Quote> = this.avnu.getQuotes
1355
+ ): Promise<SwapInfo> {
1079
1356
  const poolKey = await this.getPoolKey();
1080
1357
 
1081
1358
  // fetch current unused balances of vault
@@ -1140,7 +1417,8 @@ export class EkuboCLVault extends BaseStrategy<
1140
1417
  token1Bal,
1141
1418
  ekuboBounds,
1142
1419
  maxIterations,
1143
- priceRatioPrecision
1420
+ priceRatioPrecision,
1421
+ getQuoteCallback
1144
1422
  );
1145
1423
  }
1146
1424
 
@@ -1186,6 +1464,7 @@ export class EkuboCLVault extends BaseStrategy<
1186
1464
  const tokenToSell = expectedAmounts.amount0.lessThan(token0Bal)
1187
1465
  ? poolKey.token0
1188
1466
  : poolKey.token1;
1467
+ logger.verbose(`getSwapParams => tokenToSell: ${tokenToSell.address}, expectedAmounts: ${expectedAmounts.amount0.toString()}, bal0: ${token0Bal.toString()}`);
1189
1468
  // The other token is the one to buy
1190
1469
  const tokenToBuy =
1191
1470
  tokenToSell == poolKey.token0 ? poolKey.token1 : poolKey.token0;
@@ -1210,13 +1489,13 @@ export class EkuboCLVault extends BaseStrategy<
1210
1489
  /**
1211
1490
  * @description Calculates swap info based on given amounts of token0 and token1
1212
1491
  * Use token0 and token1 balances to determine the expected amounts for new bounds
1213
- * @param poolKey
1214
- * @param token0Bal
1215
- * @param token1Bal
1492
+ * @param poolKey
1493
+ * @param token0Bal
1494
+ * @param token1Bal
1216
1495
  * @param bounds // new bounds
1217
- * @param maxIterations
1496
+ * @param maxIterations
1218
1497
  * @returns {Promise<SwapInfo>}
1219
- *
1498
+ *
1220
1499
  */
1221
1500
  async getSwapInfoGivenAmounts(
1222
1501
  poolKey: EkuboPoolKey,
@@ -1224,7 +1503,8 @@ export class EkuboCLVault extends BaseStrategy<
1224
1503
  token1Bal: Web3Number,
1225
1504
  bounds: EkuboBounds,
1226
1505
  maxIterations: number = 20,
1227
- priceRatioPrecision: number = 4
1506
+ priceRatioPrecision: number = 4,
1507
+ getQuoteCallback: (tokenToSell: string, tokenToBuy: string, amountWei: string, beneficiary: string) => Promise<Quote> = this.avnu.getQuotes
1228
1508
  ): Promise<SwapInfo> {
1229
1509
  logger.verbose(
1230
1510
  `${
@@ -1279,12 +1559,7 @@ export class EkuboCLVault extends BaseStrategy<
1279
1559
  }
1280
1560
 
1281
1561
  // Get a quote for swapping the calculated amount
1282
- const quote = await this.avnu.getQuotes(
1283
- tokenToSell.address,
1284
- tokenToBuy.address,
1285
- amountToSell.toWei(),
1286
- this.address.address
1287
- );
1562
+ const quote = await getQuoteCallback(tokenToSell.address, tokenToBuy.address, amountToSell.toWei(), this.address.address);
1288
1563
 
1289
1564
  // If all of the token is to be swapped, return the swap info directly
1290
1565
  if (remainingSellAmount.eq(0)) {
@@ -1394,8 +1669,11 @@ export class EkuboCLVault extends BaseStrategy<
1394
1669
  * @param retry - Current retry attempt number (default 0)
1395
1670
  * @param adjustmentFactor - Percentage to adjust swap amount by (default 1)
1396
1671
  * @param isToken0Deficit - Whether token0 balance needs increasing (default true)
1672
+ * @param MAX_RETRIES - Maximum number of retries (default 40)
1673
+ * @param sameErrorCount - For certain errors, we just retry with same amount again. This is the count of such retries (default { count: 0, error: null })
1674
+ * @param MAX_SAME_ERROR_COUNT - For certain errors, we just retry with same amount again. This limits such retries (default 10)
1397
1675
  * @returns Array of contract calls needed for rebalancing
1398
- * @throws Error if max retries reached without successful rebalance
1676
+ * @throws Error if max retries reached without successful rebalance or max same errors reached
1399
1677
  */
1400
1678
  async rebalanceIter(
1401
1679
  swapInfo: SwapInfo,
@@ -1405,15 +1683,23 @@ export class EkuboCLVault extends BaseStrategy<
1405
1683
  retry = 0,
1406
1684
  lowerLimit = 0n,
1407
1685
  upperLimit = 0n,
1408
- MAX_RETRIES = 40
1686
+ MAX_RETRIES = 40,
1687
+ sameErrorCount: { count: number, error: null | string } = { count: 0, error: null },
1688
+ MAX_SAME_ERROR_COUNT = 10
1409
1689
  ): Promise<Call[]> {
1410
1690
 
1411
1691
  logger.verbose(
1412
1692
  `Rebalancing ${this.metadata.name}: ` +
1413
- `retry=${retry}, lowerLimit=${lowerLimit}, upperLimit=${upperLimit}, isSellTokenToken0=${isSellTokenToken0}`
1693
+ `retry=${retry}, lowerLimit=${lowerLimit}, upperLimit=${upperLimit}, isSellTokenToken0=${isSellTokenToken0}, MAX_RETRIES=${MAX_RETRIES}, sameErrorCount=${sameErrorCount.error} (${sameErrorCount.count})`
1414
1694
  );
1415
1695
 
1696
+ if (sameErrorCount.count >= MAX_SAME_ERROR_COUNT) {
1697
+ logger.error(`Rebalance failed after ${MAX_SAME_ERROR_COUNT} same errors`);
1698
+ throw new Error(`Rebalance failed after ${MAX_SAME_ERROR_COUNT} same errors`);
1699
+ }
1700
+
1416
1701
  const fromAmount = uint256.uint256ToBN(swapInfo.token_from_amount);
1702
+ const fromTokenInfo = await Global.getTokenInfoFromAddr(ContractAddr.from(swapInfo.token_from_address));
1417
1703
  logger.verbose(
1418
1704
  `Selling ${fromAmount.toString()} of token ${swapInfo.token_from_address}`
1419
1705
  );
@@ -1433,8 +1719,8 @@ export class EkuboCLVault extends BaseStrategy<
1433
1719
  );
1434
1720
 
1435
1721
  const newSwapInfo = { ...swapInfo };
1436
- const currentAmount = Web3Number.fromWei(fromAmount.toString(), 18); // 18 is ok, as its toWei eventually anyways
1437
- logger.verbose(`Current amount: ${currentAmount.toString()}`);
1722
+ const currentAmount = Web3Number.fromWei(fromAmount.toString(), fromTokenInfo.decimals);
1723
+ logger.verbose(`Current amount: ${currentAmount.toString()}, lowerLimit: ${lowerLimit.toString()}, upperLimit: ${upperLimit.toString()}`);
1438
1724
  if (
1439
1725
  err.message.includes("invalid token0 balance") ||
1440
1726
  err.message.includes("invalid token0 amount")
@@ -1487,11 +1773,43 @@ export class EkuboCLVault extends BaseStrategy<
1487
1773
  }
1488
1774
  newSwapInfo.token_from_amount = uint256.bnToUint256(nextAmount);
1489
1775
  }
1776
+ } else if (err.message.includes("Residual tokens")) {
1777
+ logger.error("Residual tokens");
1778
+ if (sameErrorCount.error == "Residual tokens") {
1779
+ sameErrorCount.count++;
1780
+ } else {
1781
+ sameErrorCount.error = "Residual tokens";
1782
+ sameErrorCount.count = 1;
1783
+ }
1784
+ // dont do anything, just try again.
1785
+ } else if (err.message.includes("Insufficient tokens received")) {
1786
+ logger.error("Insufficient tokens received");
1787
+ if (sameErrorCount.error == "Insufficient tokens received") {
1788
+ sameErrorCount.count++;
1789
+ } else {
1790
+ sameErrorCount.error = "Insufficient tokens received";
1791
+ sameErrorCount.count = 1;
1792
+ }
1793
+ // dont do anything, just try again.
1794
+ } else if (err.message.includes("Could not reach the end of the program")) {
1795
+ logger.error("Could not reach the end of the program, may be the block is full (could be a temp/permanent gas issue)");
1796
+ if (sameErrorCount.error == "Could not reach the end of the program") {
1797
+ sameErrorCount.count++;
1798
+ } else {
1799
+ sameErrorCount.error = "Could not reach the end of the program";
1800
+ sameErrorCount.count = 1;
1801
+ }
1802
+ // just try again.
1490
1803
  } else {
1491
1804
  logger.error("Unexpected error:", err);
1492
1805
  throw err;
1493
1806
  }
1494
1807
  newSwapInfo.token_to_min_amount = uint256.bnToUint256("0");
1808
+
1809
+ // if (uint256.uint256ToBN(newSwapInfo.token_from_amount) == fromAmount && sameErrorCount.error == 'loop-stuck') {
1810
+ // logger.error("Swap amount did not change, cannot proceed");
1811
+ // sameErrorCount = { count: MAX_SAME_ERROR_COUNT, error: null };
1812
+ // }
1495
1813
  return this.rebalanceIter(
1496
1814
  newSwapInfo,
1497
1815
  acc,
@@ -1499,7 +1817,10 @@ export class EkuboCLVault extends BaseStrategy<
1499
1817
  isSellTokenToken0,
1500
1818
  retry + 1,
1501
1819
  lowerLimit,
1502
- upperLimit
1820
+ upperLimit,
1821
+ MAX_RETRIES,
1822
+ sameErrorCount,
1823
+ MAX_SAME_ERROR_COUNT
1503
1824
  );
1504
1825
  }
1505
1826
  }
@@ -1592,20 +1913,34 @@ export class EkuboCLVault extends BaseStrategy<
1592
1913
  };
1593
1914
  }
1594
1915
 
1595
- async harvest(acc: Account, maxIterations = 20, priceRatioPrecision = 4): Promise<Call[]> {
1916
+ async getPendingRewards(): Promise<HarvestInfo[]> {
1596
1917
  const ekuboHarvests = new EkuboHarvests(this.config);
1597
- const unClaimedRewards = await ekuboHarvests.getUnHarvestedRewards(
1598
- this.address
1599
- );
1918
+ return await ekuboHarvests.getUnHarvestedRewards(this.address);
1919
+ }
1920
+
1921
+ async harvest(acc: Account, maxIterations = 20, priceRatioPrecision = 4, minRewardAmount: Web3Number = new Web3Number(0, 18)): Promise<Call[]> {
1922
+ const _pendingRewards = await this.getPendingRewards();
1923
+ const pendingRewards = _pendingRewards.filter(claim => claim.actualReward.greaterThanOrEqualTo(minRewardAmount));
1924
+ if (pendingRewards.length == 0) {
1925
+ logger.verbose(`${EkuboCLVault.name}: harvest => no pending rewards found`);
1926
+ return [];
1927
+ }
1928
+ // get necessary info for the harvest
1600
1929
  const poolKey = await this.getPoolKey();
1601
1930
  const token0Info = await Global.getTokenInfoFromAddr(poolKey.token0);
1602
1931
  const token1Info = await Global.getTokenInfoFromAddr(poolKey.token1);
1603
1932
  const bounds = await this.getCurrentBounds();
1604
1933
  logger.verbose(
1605
- `${EkuboCLVault.name}: harvest => unClaimedRewards: ${unClaimedRewards.length}`
1934
+ `${EkuboCLVault.name}: harvest => unClaimedRewards: ${pendingRewards.length}`
1606
1935
  );
1936
+
1937
+ // execute the harvest
1607
1938
  const calls: Call[] = [];
1608
- for (let claim of unClaimedRewards) {
1939
+ // do one at a time.
1940
+ const chosenClaim = pendingRewards[0];
1941
+ logger.info(`${EkuboCLVault.name}: harvest => doing one at a time`);
1942
+ logger.info(`${EkuboCLVault.name}: harvest => chosenClaim -> Claim ID: ${chosenClaim.claim.id}, Amount: ${chosenClaim.claim.amount.toString()}, actualAmount: ${chosenClaim.actualReward.toString()}, addr: ${chosenClaim.claim.claimee.toString()}`);
1943
+ for (let claim of [chosenClaim]) {
1609
1944
  const fee = claim.claim.amount
1610
1945
  .multipliedBy(this.metadata.additionalInfo.feeBps)
1611
1946
  .dividedBy(10000);
@@ -1653,8 +1988,8 @@ export class EkuboCLVault extends BaseStrategy<
1653
1988
 
1654
1989
  /**
1655
1990
  * @description This funciton requires atleast one of the pool tokens to be reward token
1656
- * i.e. STRK.
1657
- * @param params
1991
+ * i.e. STRK.
1992
+ * @param params
1658
1993
  */
1659
1994
  async _handleRewardAndVaultTokenMatchHarvest(params: {
1660
1995
  claim: HarvestInfo;
@@ -1678,60 +2013,50 @@ export class EkuboCLVault extends BaseStrategy<
1678
2013
  logger.verbose(
1679
2014
  `${
1680
2015
  EkuboCLVault.name
1681
- }: harvest => token0Amt: ${token0Amt.toString()}, token1Amt: ${token1Amt.toString()}`
1682
- );
1683
-
1684
- // THis function cannot handle swapping of non-STRK pool,
1685
- // bcz atleast one of token0Amt or token1Amt are in STRK terms.
1686
- const swapInfo = await this.getSwapInfoGivenAmounts(
1687
- poolKey,
1688
- token0Amt,
1689
- token1Amt,
1690
- bounds,
1691
- maxIterations,
1692
- priceRatioPrecision
1693
- );
1694
- swapInfo.token_to_address = token0Info.address.address;
1695
- logger.verbose(
1696
- `${EkuboCLVault.name}: harvest => swapInfo: ${JSON.stringify(swapInfo)}`
2016
+ }: harvest => token0Amt: ${token0Amt.toFixed(18)}, token1Amt: ${token1Amt.toFixed(18)}`
1697
2017
  );
1698
2018
 
1699
2019
  logger.verbose(
1700
2020
  `${EkuboCLVault.name}: harvest => claim: ${JSON.stringify(claim)}`
1701
2021
  );
1702
- const harvestEstimateCall = async (swapInfo1: SwapInfo) => {
1703
- const swap1Amount = Web3Number.fromWei(
1704
- uint256.uint256ToBN(swapInfo1.token_from_amount).toString(),
1705
- 18 // cause its always STRK?
2022
+ const claimTokenInfo = await Global.getTokenInfoFromAddr(claim.token);
2023
+ const harvestEstimateCall = async (baseSwapInfo: SwapInfo) => {
2024
+ // - the base swap if actual swap from claim token to non-claim token
2025
+ // - the other swap is just claim token to claim token (e.g. STRK to STRK)
2026
+ // which is just dummy
2027
+ let baseSwapAmount = Web3Number.fromWei(
2028
+ uint256.uint256ToBN(baseSwapInfo.token_from_amount).toString(),
2029
+ claimTokenInfo.decimals
1706
2030
  ).minimum(
1707
- postFeeAmount.toFixed(18) // cause always strk
2031
+ postFeeAmount.toFixed(claimTokenInfo.decimals)
1708
2032
  ); // ensure we don't swap more than we have
1709
- swapInfo.token_from_amount = uint256.bnToUint256(swap1Amount.toWei());
1710
- swapInfo.token_to_min_amount = uint256.bnToUint256(
1711
- swap1Amount.multipliedBy(0).toWei() // placeholder
1712
- ); // 0.01% slippage
2033
+ if (baseSwapAmount.lt(0.0001)) {
2034
+ baseSwapAmount = new Web3Number(0, claimTokenInfo.decimals);
2035
+ }
2036
+ baseSwapInfo.token_from_amount = uint256.bnToUint256(baseSwapAmount.toWei());
1713
2037
 
2038
+ const isToken0ClaimToken = claim.token.eq(poolKey.token0);
1714
2039
  logger.verbose(
1715
- `${EkuboCLVault.name}: harvest => swap1Amount: ${swap1Amount}`
2040
+ `${EkuboCLVault.name}: harvest => isToken0ClaimToken: ${isToken0ClaimToken}, baseSwapAmount: ${baseSwapAmount}`
1716
2041
  );
1717
2042
 
1718
- const remainingAmount = postFeeAmount.minus(swap1Amount).maximum(0);
2043
+ const remainingAmount = postFeeAmount.minus(baseSwapAmount).maximum(0);
1719
2044
  logger.verbose(
1720
2045
  `${EkuboCLVault.name}: harvest => remainingAmount: ${remainingAmount}`
1721
2046
  );
1722
- const swapInfo2 = {
1723
- ...swapInfo,
1724
- token_from_amount: uint256.bnToUint256(remainingAmount.toWei()),
1725
- };
1726
- swapInfo2.token_to_address = token1Info.address.address;
2047
+
2048
+ // obv, same to same
2049
+ let dummySwapInfo = AvnuWrapper.buildZeroSwap(claim.token, this.address.address, claim.token);
2050
+ dummySwapInfo.token_from_amount = uint256.bnToUint256(remainingAmount.toWei());
2051
+
1727
2052
  logger.verbose(
1728
- `${EkuboCLVault.name}: harvest => swapInfo: ${JSON.stringify(
1729
- swapInfo
2053
+ `${EkuboCLVault.name}: harvest => dummySwapInfo: ${JSON.stringify(
2054
+ dummySwapInfo
1730
2055
  )}`
1731
2056
  );
1732
2057
  logger.verbose(
1733
- `${EkuboCLVault.name}: harvest => swapInfo2: ${JSON.stringify(
1734
- swapInfo2
2058
+ `${EkuboCLVault.name}: harvest => baseSwapInfo: ${JSON.stringify(
2059
+ baseSwapInfo
1735
2060
  )}`
1736
2061
  );
1737
2062
  const calldata = [
@@ -1742,18 +2067,41 @@ export class EkuboCLVault extends BaseStrategy<
1742
2067
  claimee: claim.claim.claimee.address,
1743
2068
  },
1744
2069
  claim.proof.map((p) => num.getDecimalString(p)),
1745
- swapInfo,
1746
- swapInfo2,
2070
+ isToken0ClaimToken ? dummySwapInfo : baseSwapInfo, // is token0 claim token, its just dummy swap
2071
+ isToken0ClaimToken ? baseSwapInfo : dummySwapInfo,
1747
2072
  ];
1748
- logger.verbose(
1749
- `${EkuboCLVault.name}: harvest => calldata: ${JSON.stringify(
1750
- calldata
1751
- )}`
1752
- );
1753
2073
  return [this.contract.populate("harvest", calldata)];
1754
2074
  };
2075
+
2076
+ // if token0 == claim token, then the base swapInfo is from claim token to token1
2077
+ // if token1 == claim token, then the base swapInfo is from claim token to token0
2078
+ const isToken0ClaimToken = claim.token.eq(poolKey.token0);
2079
+ let baseSwapInfo = AvnuWrapper.buildZeroSwap(claim.token, this.address.address, isToken0ClaimToken ? token1Info.address : token0Info.address);
2080
+ baseSwapInfo.token_from_amount = uint256.bnToUint256(postFeeAmount.toWei()); // we try to swap all to start with
2081
+
2082
+ // if token0 != claim token, then we swap from claim token to token0
2083
+ if (postFeeAmount.greaterThan(0) && !isToken0ClaimToken) {
2084
+ const avnuWrapper = new AvnuWrapper();
2085
+ const quote = await avnuWrapper.getQuotes(
2086
+ claim.token.address,
2087
+ token0Info.address.address,
2088
+ postFeeAmount.toWei(),
2089
+ this.address.address
2090
+ );
2091
+ baseSwapInfo = await avnuWrapper.getSwapInfo(quote, this.address.address, 0, this.address.address);
2092
+ } else if (postFeeAmount.greaterThan(0) && isToken0ClaimToken) {
2093
+ // if token0 == claim token, then we swap from claim token to token1
2094
+ const avnuWrapper = new AvnuWrapper();
2095
+ const quote = await avnuWrapper.getQuotes(
2096
+ claim.token.address,
2097
+ token1Info.address.address,
2098
+ postFeeAmount.toWei(),
2099
+ this.address.address
2100
+ );
2101
+ baseSwapInfo = await avnuWrapper.getSwapInfo(quote, this.address.address, 0, this.address.address);
2102
+ }
1755
2103
  const _callsFinal = await this.rebalanceIter(
1756
- swapInfo,
2104
+ baseSwapInfo,
1757
2105
  acc,
1758
2106
  harvestEstimateCall,
1759
2107
  claim.token.eq(poolKey.token0),
@@ -1772,9 +2120,9 @@ export class EkuboCLVault extends BaseStrategy<
1772
2120
 
1773
2121
  /**
1774
2122
  * @description This function handles harvesting of reward token that is not the same as any of the vault token
1775
- * i.e. STRK is not part of vault tokens like BTC/ETH
1776
- * @param params
1777
- * @returns
2123
+ * i.e. STRK is not part of vault tokens like BTC/ETH
2124
+ * @param params
2125
+ * @returns
1778
2126
  */
1779
2127
  async _handleRewardAndVaultTokenMismatchHarvest(params: {
1780
2128
  claim: HarvestInfo;
@@ -1812,7 +2160,7 @@ export class EkuboCLVault extends BaseStrategy<
1812
2160
  return [harvestCall];
1813
2161
  }
1814
2162
 
1815
- // given an amount (i.e. portion of reward to use to swap to token0), returns info on increasing or decreasing
2163
+ // given an amount (i.e. portion of reward to use to swap to token0), returns info on increasing or decreasing
1816
2164
  // amount for binary search
1817
2165
  async harvestMismatchEstimateCallFn(params: {
1818
2166
  postFeeAmount: Web3Number;
@@ -1823,39 +2171,47 @@ export class EkuboCLVault extends BaseStrategy<
1823
2171
  }) {
1824
2172
  const { postFeeAmount, claim, token0Info, token1Info, acc } = params;
1825
2173
  let harvestCall: Call | null = null;
2174
+ logger.verbose(`${EkuboCLVault.name}: harvestMismatchEstimateCallFn => postFeeAmount: ${postFeeAmount.toString()}`);
1826
2175
 
2176
+ let attempt = 0;
2177
+ let MAX_ATTEMPTS = 50;
1827
2178
  const binarySearchCallbackFn = async (mid: bigint) => {
2179
+ attempt++;
2180
+ logger.verbose(`${EkuboCLVault.name}: harvestMismatchEstimateCallFn => mid: ${mid}, attempt: ${attempt}/${MAX_ATTEMPTS}`);
1828
2181
  const rewardPart2 = BigInt(postFeeAmount.toWei()) - mid;
1829
2182
  const avnuWrapper = new AvnuWrapper();
1830
2183
  const beneficiary = this.address.address;
1831
2184
 
1832
2185
  // get quote for 1st part
1833
- const quote1 = await avnuWrapper.getQuotes(
2186
+ const quote1Prom = avnuWrapper.getQuotes(
1834
2187
  claim.token.address,
1835
2188
  token0Info.address.address,
1836
2189
  mid.toString(),
1837
2190
  beneficiary
1838
2191
  );
2192
+ const quote2Prom = avnuWrapper.getQuotes(
2193
+ claim.token.address,
2194
+ token1Info.address.address,
2195
+ rewardPart2.toString(),
2196
+ beneficiary
2197
+ );
2198
+ const [quote1, quote2] = await Promise.all([quote1Prom, quote2Prom]);
2199
+
1839
2200
  // default min amount is ok
1840
2201
  const swapInfo1 = await avnuWrapper.getSwapInfo(
1841
2202
  quote1,
1842
2203
  beneficiary,
1843
- 0,
2204
+ 0, // fee bps
1844
2205
  beneficiary
1845
2206
  );
1846
2207
 
1847
2208
  // get quote for 2nd part
1848
- const quote2 = await avnuWrapper.getQuotes(
1849
- claim.token.address,
1850
- token1Info.address.address,
1851
- rewardPart2.toString(),
1852
- beneficiary
1853
- );
2209
+
1854
2210
  // default min amount is ok
1855
2211
  const swapInfo2 = await avnuWrapper.getSwapInfo(
1856
2212
  quote2,
1857
2213
  beneficiary,
1858
- 0,
2214
+ 0, // fee bps
1859
2215
  beneficiary
1860
2216
  );
1861
2217
 
@@ -1874,27 +2230,36 @@ export class EkuboCLVault extends BaseStrategy<
1874
2230
  ];
1875
2231
  harvestCall = this.contract.populate("harvest", calldata)
1876
2232
  const gas = await acc.estimateInvokeFee(harvestCall);
2233
+ logger.verbose(`${EkuboCLVault.name}: harvestMismatchEstimateCallFn => gas: ${gas.overall_fee.toString()}, attempt: ${attempt}/${MAX_ATTEMPTS}`);
1877
2234
  return 'found';
1878
2235
  } catch (err: any) {
1879
2236
  if (err.message.includes('invalid token0 amount')) {
2237
+ logger.verbose(`${EkuboCLVault.name}: harvestMismatchEstimateCallFn => invalid token0 amount, attempt: ${attempt}/${MAX_ATTEMPTS}`);
1880
2238
  // too much token0 amount left, may be swap less to token0
1881
2239
  return 'go_low';
1882
2240
  } else if (err.message.includes('invalid token1 amount')) {
2241
+ logger.verbose(`${EkuboCLVault.name}: harvestMismatchEstimateCallFn => invalid token1 amount, attempt: ${attempt}/${MAX_ATTEMPTS}`);
1883
2242
  // too much token1 balance left, may be swap more to token0
1884
2243
  return 'go_high';
1885
2244
  }
2245
+ logger.verbose(`${EkuboCLVault.name}: harvestMismatchEstimateCallFn => error: ${err.message}, attempt: ${attempt}/${MAX_ATTEMPTS}`);
1886
2246
  return 'retry';
1887
2247
  }
1888
2248
  }
1889
2249
 
1890
2250
  // run the binary search
1891
2251
  await binarySearch(0n, BigInt(postFeeAmount.toWei()), binarySearchCallbackFn);
1892
-
2252
+
1893
2253
  return harvestCall;
1894
2254
  }
1895
2255
 
1896
2256
  async getInvestmentFlows() {
1897
- const netYield = await this.netAPY();
2257
+ // for LSTs, we use 30d, else 7d for the yield calculation
2258
+ // TODO Make the block compute more dynamic
2259
+ const blocksDiff = this.metadata.additionalInfo.lstContract
2260
+ ? 600000
2261
+ : 600000 / 4;
2262
+ const netYield = await this.netAPY("latest", blocksDiff, "7d" as any);
1898
2263
  const poolKey = await this.getPoolKey();
1899
2264
 
1900
2265
  const linkedFlow: IInvestmentFlow = {
@@ -1915,7 +2280,7 @@ export class EkuboCLVault extends BaseStrategy<
1915
2280
  id: "base",
1916
2281
  title: "Your Deposit",
1917
2282
  subItems: [
1918
- { key: `Net yield`, value: `${(netYield.net * 100).toFixed(2)}%` },
2283
+ { key: `Net yield`, value: `${(netYield * 100).toFixed(2)}%` },
1919
2284
  {
1920
2285
  key: `Performance Fee`,
1921
2286
  value: `${(this.metadata.additionalInfo.feeBps / 100).toFixed(2)}%`,
@@ -1931,8 +2296,8 @@ export class EkuboCLVault extends BaseStrategy<
1931
2296
  subItems: [
1932
2297
  {
1933
2298
  key: "Range selection",
1934
- value: (typeof this.metadata.additionalInfo.newBounds == 'string') ?
1935
- this.metadata.additionalInfo.newBounds :
2299
+ value: (typeof this.metadata.additionalInfo.newBounds == 'string') ?
2300
+ this.metadata.additionalInfo.newBounds :
1936
2301
  `${
1937
2302
  this.metadata.additionalInfo.newBounds.lower *
1938
2303
  Number(poolKey.tick_spacing)
@@ -2053,7 +2418,11 @@ function getLSTFAQs(lstSymbol: string): FAQ[] {
2053
2418
  ]
2054
2419
  }
2055
2420
 
2421
+ const vaultTypeDescription = 'Automatically collects fees and rebalances positions on Ekubo to optimize yield';
2422
+ const vaultType = VaultType.AUTOMATED_LP;
2423
+
2056
2424
  const xSTRKSTRK: IStrategyMetadata<CLVaultStrategySettings> = {
2425
+ id: "ekubo_cl_xstrkstrk",
2057
2426
  name: "Ekubo xSTRK/STRK",
2058
2427
  description: <></>,
2059
2428
  address: ContractAddr.from(
@@ -2061,6 +2430,10 @@ const xSTRKSTRK: IStrategyMetadata<CLVaultStrategySettings> = {
2061
2430
  ),
2062
2431
  launchBlock: 1209881,
2063
2432
  type: "Other",
2433
+ vaultType: {
2434
+ type: vaultType,
2435
+ description: vaultTypeDescription
2436
+ },
2064
2437
  // must be same order as poolKey token0 and token1
2065
2438
  depositTokens: [
2066
2439
  Global.getDefaultTokens().find((t) => t.symbol === "xSTRK")!,
@@ -2068,7 +2441,7 @@ const xSTRKSTRK: IStrategyMetadata<CLVaultStrategySettings> = {
2068
2441
  ],
2069
2442
  protocols: [_protocol],
2070
2443
  auditUrl: AUDIT_URL,
2071
- maxTVL: Web3Number.fromWei("0", 18),
2444
+ curator: UnwrapLabsCurator,
2072
2445
  risk: {
2073
2446
  riskFactor: _lstPoolRiskFactors,
2074
2447
  netRisk:
@@ -2078,6 +2451,7 @@ const xSTRKSTRK: IStrategyMetadata<CLVaultStrategySettings> = {
2078
2451
  },
2079
2452
  apyMethodology:
2080
2453
  "APY based on 30-day historical performance, including fees and rewards.",
2454
+ realizedApyMethodology: "The realizedAPY is based on past 14 days performance by the vault",
2081
2455
  additionalInfo: {
2082
2456
  newBounds: {
2083
2457
  lower: -1,
@@ -2094,270 +2468,589 @@ const xSTRKSTRK: IStrategyMetadata<CLVaultStrategySettings> = {
2094
2468
  },
2095
2469
  quoteAsset: Global.getDefaultTokens().find((t) => t.symbol === "STRK")!,
2096
2470
  },
2471
+ settings: {
2472
+ isAudited: true,
2473
+ isPaused: false,
2474
+ liveStatus: StrategyLiveStatus.ACTIVE,
2475
+ isInstantWithdrawal: true,
2476
+ hideNetEarnings: true,
2477
+ isTransactionHistDisabled: true,
2478
+ quoteToken: Global.getDefaultTokens().find((t) => t.symbol === "STRK")!,
2479
+ alerts: [
2480
+ {
2481
+ type: "info",
2482
+ text: (
2483
+ <p>
2484
+ Depending on the current position range and price, your
2485
+ input amounts are automatically adjusted to nearest
2486
+ required amounts. If you have insufficient tokens, you
2487
+ can acquire the required tokens on{" "}
2488
+ <a
2489
+ href="https://avnu.fi"
2490
+ target="_blank"
2491
+ rel="noopener noreferrer"
2492
+ >
2493
+ Avnu
2494
+ </a>
2495
+ </p>
2496
+ ),
2497
+ tab: "deposit"
2498
+ },
2499
+ {
2500
+ type: "info",
2501
+ text: (
2502
+ <>
2503
+ Depending on the current position range and price, you
2504
+ may receive both of the tokens or one of the tokens
2505
+ depending on the price
2506
+ </>
2507
+ ),
2508
+ tab: "withdraw"
2509
+ }
2510
+ ],
2511
+ tags: [StrategyTag.AUTOMATED_LP]
2512
+ },
2097
2513
  faqs: getLSTFAQs("xSTRK"),
2098
2514
  points: [{
2099
- multiplier: 1,
2515
+ multiplier: 15,
2100
2516
  logo: 'https://endur.fi/favicon.ico',
2101
2517
  toolTip: "This strategy holds xSTRK and STRK tokens. Earn 1x Endur points on your xSTRK portion of Liquidity. STRK portion will earn Endur's DEX Bonus points. Points can be found on endur.fi.",
2102
2518
  }],
2103
2519
  contractDetails: [],
2104
- investmentSteps: []
2520
+ investmentSteps: [],
2521
+ tags: [StrategyTag.AUTOMATED_LP],
2522
+ security: {
2523
+ auditStatus: AuditStatus.AUDITED,
2524
+ sourceCode: {
2525
+ type: SourceCodeType.OPEN_SOURCE,
2526
+ contractLink: "https://github.com/trovesfi/troves-contracts",
2527
+ },
2528
+ accessControl: {
2529
+ type: AccessControlType.ROLE_BASED_ACCESS,
2530
+ addresses: [MY_ACCESS_CONTROL.address],
2531
+ },
2532
+ },
2533
+ redemptionInfo: {
2534
+ instantWithdrawalVault: InstantWithdrawalVault.YES,
2535
+ redemptionsInfo: [],
2536
+ alerts: [],
2537
+ },
2538
+ usualTimeToEarnings: null,
2539
+ usualTimeToEarningsDescription: null,
2105
2540
  };
2106
2541
 
2107
- const lstStrategies: IStrategyMetadata<CLVaultStrategySettings>[] = [
2108
- xSTRKSTRK,
2109
- {
2110
- ...xSTRKSTRK,
2111
- name: "Ekubo xWBTC/WBTC",
2112
- description: <></>,
2113
- address: ContractAddr.from(
2114
- "0x2ea99b4971d3c277fa4a9b4beb7d4d7d169e683393a29eef263d5d57b4380a"
2115
- ),
2116
- launchBlock: 2338309,
2117
- // must be same order as poolKey token0 and token1
2118
- depositTokens: [
2119
- Global.getDefaultTokens().find((t) => t.symbol === "WBTC")!,
2120
- Global.getDefaultTokens().find((t) => t.symbol === "xWBTC")!,
2121
- ],
2122
- additionalInfo: {
2123
- ...xSTRKSTRK.additionalInfo,
2124
- quoteAsset: Global.getDefaultTokens().find((t) => t.symbol === "WBTC")!,
2125
- lstContract: Global.getDefaultTokens().find((t) => t.symbol === "xWBTC")!.address,
2542
+ // Helper to create common LST alerts
2543
+ const getLSTAlerts = () => [
2544
+ {
2545
+ tab: "deposit" as const,
2546
+ text: (
2547
+ <>
2548
+ To acquire the LST, please visit{" "}
2549
+ <a
2550
+ href="https://app.endur.fi"
2551
+ target="_blank"
2552
+ rel="noopener noreferrer"
2553
+ >
2554
+ endur.fi
2555
+ </a>
2556
+ </>
2557
+ ),
2558
+ type: "info" as const
2126
2559
  },
2127
- faqs: getLSTFAQs("xWBTC"),
2128
- points: [],
2129
- contractDetails: [],
2130
- investmentSteps: []
2131
- },
2132
- {
2133
- ...xSTRKSTRK,
2134
- name: "Ekubo xtBTC/tBTC",
2135
- description: <></>,
2136
- address: ContractAddr.from(
2137
- "0x785dc3dfc4e80ef2690a99512481e3ed3a5266180adda5a47e856245d68a4af"
2138
- ),
2139
- launchBlock: 2415667,
2140
- // must be same order as poolKey token0 and token1
2141
- depositTokens: [
2142
- Global.getDefaultTokens().find((t) => t.symbol === "xtBTC")!,
2143
- Global.getDefaultTokens().find((t) => t.symbol === "tBTC")!,
2144
- ],
2145
- additionalInfo: {
2146
- ...xSTRKSTRK.additionalInfo,
2147
- quoteAsset: Global.getDefaultTokens().find((t) => t.symbol === "tBTC")!,
2148
- lstContract: Global.getDefaultTokens().find((t) => t.symbol === "xtBTC")!.address,
2560
+ {
2561
+ type: "info" as const,
2562
+ text: (
2563
+ <p>
2564
+ Depending on the current position range and price, your input
2565
+ amounts are automatically adjusted to nearest required amounts.
2566
+ If you have insufficient tokens, you can acquire the required
2567
+ tokens on{" "}
2568
+ <a
2569
+ href="https://avnu.fi"
2570
+ target="_blank"
2571
+ rel="noopener noreferrer"
2572
+ >
2573
+ Avnu
2574
+ </a>
2575
+ </p>
2576
+ ),
2577
+ tab: "deposit" as const
2149
2578
  },
2150
- faqs: getLSTFAQs("xtBTC"),
2151
- points: [],
2152
- contractDetails: [],
2153
- investmentSteps: []
2154
- },
2155
- {
2579
+ {
2580
+ type: "info" as const,
2581
+ text: (
2582
+ <>
2583
+ Depending on the current position range and price, you may
2584
+ receive both of the tokens or one of the tokens depending on the
2585
+ price
2586
+ </>
2587
+ ),
2588
+ tab: "withdraw" as const
2589
+ }
2590
+ ];
2591
+
2592
+ // Helper to create LST strategy settings
2593
+ const createLSTSettings = (quoteTokenSymbol: string) => ({
2594
+ ...xSTRKSTRK.settings,
2595
+ isAudited: true,
2596
+ liveStatus: StrategyLiveStatus.ACTIVE,
2597
+ isInstantWithdrawal: true,
2598
+ hideNetEarnings: true,
2599
+ isTransactionHistDisabled: true,
2600
+ quoteToken: Global.getDefaultTokens().find(
2601
+ (t) => t.symbol === quoteTokenSymbol
2602
+ )!,
2603
+ alerts: getLSTAlerts(),
2604
+ tags: [StrategyTag.AUTOMATED_LP] as StrategyTag[],
2605
+ });
2606
+
2607
+ // Helper to create an LST strategy
2608
+ const createLSTStrategy = (params: {
2609
+ id: string;
2610
+ name: string;
2611
+ address: string;
2612
+ launchBlock: number;
2613
+ depositToken0Symbol: string;
2614
+ depositToken1Symbol: string;
2615
+ quoteTokenSymbol: string;
2616
+ lstSymbol: string;
2617
+ lstContractAddress?: string;
2618
+ }): IStrategyMetadata<CLVaultStrategySettings> => ({
2156
2619
  ...xSTRKSTRK,
2157
- name: "Ekubo xsBTC/solvBTC",
2620
+ id: params.id,
2621
+ name: params.name,
2158
2622
  description: <></>,
2159
- address: ContractAddr.from(
2160
- "0x3af1c7faa7c464cf2c494e988972ad1939f1103dbfb6e47e9bf0c47e49b14ef"
2161
- ),
2162
- launchBlock: 2344809,
2163
2623
  // must be same order as poolKey token0 and token1
2164
- depositTokens: [
2165
- Global.getDefaultTokens().find((t) => t.symbol === "xsBTC")!,
2166
- Global.getDefaultTokens().find((t) => t.symbol === "solvBTC")!,
2167
- ],
2168
- additionalInfo: {
2169
- ...xSTRKSTRK.additionalInfo,
2170
- quoteAsset: Global.getDefaultTokens().find((t) => t.symbol === "solvBTC")!,
2171
- lstContract: Global.getDefaultTokens().find((t) => t.symbol === "xsBTC")!.address,
2624
+ address: ContractAddr.from(params.address),
2625
+ launchBlock: params.launchBlock,
2626
+ vaultType: {
2627
+ type: vaultType,
2628
+ description: vaultTypeDescription
2172
2629
  },
2173
- faqs: getLSTFAQs("xsBTC"),
2174
- points: [],
2175
- contractDetails: [],
2176
- investmentSteps: []
2177
- },
2178
- {
2179
- ...xSTRKSTRK,
2180
- name: "Ekubo xLBTC/LBTC",
2181
- description: <></>,
2182
- address: ContractAddr.from(
2183
- "0x314c4653ab1aa01f5465773cb879f525d7e369a137bc3ae084761aee99a1712"
2184
- ),
2185
- launchBlock: 2412442,
2186
- // must be same order as poolKey token0 and token1
2187
2630
  depositTokens: [
2188
- Global.getDefaultTokens().find((t) => t.symbol === "LBTC")!,
2189
- Global.getDefaultTokens().find((t) => t.symbol === "xLBTC")!,
2631
+ Global.getDefaultTokens().find(
2632
+ (t) => t.symbol === params.depositToken0Symbol
2633
+ )!,
2634
+ Global.getDefaultTokens().find((t) => t.symbol === params.depositToken1Symbol)!
2190
2635
  ],
2636
+ realizedApyMethodology: "The realizedAPY is based on past 14 days performance by the vault",
2191
2637
  additionalInfo: {
2192
- ...xSTRKSTRK.additionalInfo,
2193
- quoteAsset: Global.getDefaultTokens().find((t) => t.symbol === "LBTC")!,
2194
- lstContract: Global.getDefaultTokens().find((t) => t.symbol === "xLBTC")!.address,
2638
+ ...xSTRKSTRK.additionalInfo,
2639
+ quoteAsset: Global.getDefaultTokens().find(
2640
+ (t) => t.symbol === params.quoteTokenSymbol
2641
+ )!,
2642
+ lstContract: params.lstContractAddress
2643
+ ? ContractAddr.from(params.lstContractAddress)
2644
+ : Global.getDefaultTokens().find((t) => t.symbol === params.lstSymbol)!
2645
+ .address
2195
2646
  },
2196
- faqs: getLSTFAQs("xLBTC"),
2647
+ settings: createLSTSettings(params.quoteTokenSymbol),
2648
+ faqs: getLSTFAQs(params.lstSymbol),
2197
2649
  points: [],
2198
2650
  contractDetails: [],
2199
- investmentSteps: []
2200
- }
2651
+ investmentSteps: [],
2652
+ tags: params.id.toLowerCase().includes('btc') ? [StrategyTag.BTC, StrategyTag.AUTOMATED_LP] : [StrategyTag.AUTOMATED_LP]
2653
+ });
2654
+
2655
+ const lstStrategies: IStrategyMetadata<CLVaultStrategySettings>[] = [
2656
+ xSTRKSTRK,
2657
+ createLSTStrategy({
2658
+ id: "ekubo_cl_xstrkbtcstrkbtc",
2659
+ name: "Ekubo xstrkBTC/strkBTC",
2660
+ address: "0x03d1d1932ef6882d4acf763dd0430f4abed3e2a9da28e028f1e2e8dd934b8bf7",
2661
+ launchBlock: 9651140,
2662
+ depositToken0Symbol: "xstrkBTC",
2663
+ depositToken1Symbol: "strkBTC",
2664
+ quoteTokenSymbol: "strkBTC",
2665
+ lstSymbol: "xstrkBTC",
2666
+ }),
2667
+ createLSTStrategy({
2668
+ id: "ekubo_cl_xwbtcwbtc",
2669
+ name: "Ekubo xWBTC/WBTC",
2670
+ address: "0x2ea99b4971d3c277fa4a9b4beb7d4d7d169e683393a29eef263d5d57b4380a",
2671
+ launchBlock: 2338309,
2672
+ depositToken0Symbol: "WBTC",
2673
+ depositToken1Symbol: "xWBTC",
2674
+ quoteTokenSymbol: "WBTC",
2675
+ lstSymbol: "xWBTC",
2676
+ }),
2677
+ createLSTStrategy({
2678
+ id: "ekubo_cl_xtbtctbtc",
2679
+ name: "Ekubo xtBTC/tBTC",
2680
+ address: "0x785dc3dfc4e80ef2690a99512481e3ed3a5266180adda5a47e856245d68a4af",
2681
+ launchBlock: 2415667,
2682
+ depositToken0Symbol: "xtBTC",
2683
+ depositToken1Symbol: "tBTC",
2684
+ quoteTokenSymbol: "tBTC",
2685
+ lstSymbol: "xtBTC",
2686
+ }),
2687
+ createLSTStrategy({
2688
+ id: "ekubo_cl_xsbtcsolvbtc",
2689
+ name: "Ekubo xsBTC/solvBTC",
2690
+ address: "0x3af1c7faa7c464cf2c494e988972ad1939f1103dbfb6e47e9bf0c47e49b14ef",
2691
+ launchBlock: 2344809,
2692
+ depositToken0Symbol: "xsBTC",
2693
+ depositToken1Symbol: "solvBTC",
2694
+ quoteTokenSymbol: "solvBTC",
2695
+ lstSymbol: "xsBTC",
2696
+ }),
2697
+ createLSTStrategy({
2698
+ id: "ekubo_cl_xlbtclbtc",
2699
+ name: "Ekubo xLBTC/LBTC",
2700
+ address: "0x314c4653ab1aa01f5465773cb879f525d7e369a137bc3ae084761aee99a1712",
2701
+ launchBlock: 2412442,
2702
+ depositToken0Symbol: "LBTC",
2703
+ depositToken1Symbol: "xLBTC",
2704
+ quoteTokenSymbol: "LBTC",
2705
+ lstSymbol: "xLBTC",
2706
+ })
2201
2707
  ];
2202
2708
 
2203
- const ETHUSDCRe7Strategy: IStrategyMetadata<CLVaultStrategySettings> = {
2204
- ...xSTRKSTRK,
2205
- name: "Ekubo ETH/USDC",
2206
- description: <></>,
2207
- address: ContractAddr.from(
2208
- "0x160d8fa4569ef6a12e6bf47cb943d7b5ebba8a41a69a14c1d943050ba5ff947"
2209
- ),
2210
- launchBlock: 1504232,
2211
- // must be same order as poolKey token0 and token1
2212
- depositTokens: [
2213
- Global.getDefaultTokens().find((t) => t.symbol === "ETH")!,
2214
- Global.getDefaultTokens().find((t) => t.symbol === "USDC")!
2215
- ],
2216
- apyMethodology:
2217
- "Annualized fee APY, calculated as fees earned in the last 7d divided by TVL",
2218
- additionalInfo: {
2219
- newBounds: "Managed by Re7",
2220
- truePrice: 1,
2221
- feeBps: 1000,
2222
- rebalanceConditions: {
2223
- customShouldRebalance: async (currentPrice: number) =>
2224
- currentPrice > 0.99 && currentPrice < 1.01,
2225
- minWaitHours: 6,
2226
- direction: "any"
2709
+ const getRe7Alerts = () => [
2710
+ {
2711
+ type: "info" as const,
2712
+ text: (
2713
+ <p>
2714
+ Depending on the current position range and price, your input
2715
+ amounts are automatically adjusted to nearest required amounts.
2716
+ If you have insufficient tokens, you can acquire the required
2717
+ tokens on{" "}
2718
+ <a
2719
+ href="https://avnu.fi"
2720
+ target="_blank"
2721
+ rel="noopener noreferrer"
2722
+ >
2723
+ Avnu
2724
+ </a>
2725
+ </p>
2726
+ ),
2727
+ tab: "deposit" as const
2227
2728
  },
2228
- quoteAsset: Global.getDefaultTokens().find((t) => t.symbol === "USDC")!,
2229
- },
2230
- faqs: [
2729
+ {
2730
+ type: "info" as const,
2731
+ text: (
2732
+ <>
2733
+ Depending on the current position range and price, you may
2734
+ receive both of the tokens or one of the tokens depending on the
2735
+ price
2736
+ </>
2737
+ ),
2738
+ tab: "withdraw" as const
2739
+ }
2740
+ ];
2741
+
2742
+ // Helper to create Re7 strategy settings
2743
+ const createRe7Settings = (quoteTokenSymbol: string, isBTC: boolean, isDeprecated: boolean) => ({
2744
+ ...xSTRKSTRK.settings,
2745
+ isAudited: true,
2746
+ liveStatus: isDeprecated ? StrategyLiveStatus.DEPRECATED : StrategyLiveStatus.ACTIVE,
2747
+ isInstantWithdrawal: true,
2748
+ hideNetEarnings: true,
2749
+ isTransactionHistDisabled: false,
2750
+ quoteToken: Global.getDefaultTokens().find(
2751
+ (t) => t.symbol === quoteTokenSymbol
2752
+ )!,
2753
+ alerts: getRe7Alerts(),
2754
+ tags: isBTC ? [StrategyTag.BTC, StrategyTag.AUTOMATED_LP] : [StrategyTag.AUTOMATED_LP] as StrategyTag[]
2755
+ });
2756
+
2757
+ // Helper to create Re7 FAQs
2758
+ const getRe7FAQs = () => [
2231
2759
  ...faqs,
2232
2760
  {
2233
- question: "Who is the curator of this strategy?",
2234
- answer:
2235
- <div>Re7 Labs is the curator of this strategy. Re7 Labs is a well-known Web3 asset management firm. This strategy is completely managed by them, including ownership of the vault. Troves is developer of the smart contracts and maintains infrastructure to help users access these strategies. You can find more information about them on their website <a href='https://www.re7labs.xyz' style={{textDecoration: "underline", marginLeft: "2px"}} target="_blank">here</a>.</div>
2761
+ question: "Who is the curator of this strategy?",
2762
+ answer: (
2763
+ <div>
2764
+ Re7 Labs is the curator of this strategy. Re7 Labs is a
2765
+ well-known Web3 asset management firm. This strategy is
2766
+ completely managed by them, including ownership of the vault.
2767
+ Troves is developer of the smart contracts and maintains
2768
+ infrastructure to help users access these strategies. You can
2769
+ find more information about them on their website{" "}
2770
+ <a
2771
+ href="https://www.re7labs.xyz"
2772
+ style={{
2773
+ textDecoration: "underline",
2774
+ marginLeft: "2px"
2775
+ }}
2776
+ target="_blank"
2777
+ >
2778
+ here
2779
+ </a>
2780
+ .
2781
+ </div>
2782
+ )
2236
2783
  },
2237
2784
  {
2238
- question: "How is the APY calculated?",
2239
- answer:
2240
- <div>It's an annualized fee APY, calculated as fees earned in the last 24h divided by TVL. Factors like impermanent loss are not considered.</div>
2241
- },
2242
- ],
2243
- risk: highRisk,
2244
- points: [],
2245
- curator: { name: "Re7 Labs", logo: "https://www.re7labs.xyz/favicon.ico" }
2785
+ question: "How is the APY calculated?",
2786
+ answer: (
2787
+ <div>
2788
+ It's an annualized fee APY, calculated as fees earned in the
2789
+ last 24h divided by TVL. Factors like impermanent loss are not
2790
+ considered.
2791
+ </div>
2792
+ )
2793
+ }
2794
+ ];
2795
+
2796
+ // Helper to create a Re7 strategy
2797
+ const createRe7Strategy = (
2798
+ id: string,
2799
+ name: string,
2800
+ address: string,
2801
+ launchBlock: number,
2802
+ depositToken0Symbol: string,
2803
+ depositToken1Symbol: string,
2804
+ quoteTokenSymbol: string,
2805
+ risk:
2806
+ | typeof highRisk
2807
+ | typeof mediumRisk
2808
+ | { riskFactor: RiskFactor[]; netRisk: number; notARisks: RiskType[] },
2809
+ isBTC: boolean
2810
+ ): IStrategyMetadata<CLVaultStrategySettings> => {
2811
+ const isDeprecated = name.toLowerCase().includes('usdc.e');
2812
+ return {
2813
+ ...xSTRKSTRK,
2814
+ id,
2815
+ name,
2816
+ description: <></>,
2817
+ address: ContractAddr.from(address),
2818
+ launchBlock,
2819
+ vaultType: {
2820
+ type: vaultType,
2821
+ description: vaultTypeDescription
2822
+ },
2823
+ depositTokens: [
2824
+ Global.getDefaultTokens().find(
2825
+ (t) => t.symbol === depositToken0Symbol
2826
+ )!,
2827
+ Global.getDefaultTokens().find((t) => t.symbol === depositToken1Symbol)!
2828
+ ],
2829
+ apyMethodology:
2830
+ "Annualized fee APY, calculated as fees earned in the last 7d divided by TVL",
2831
+ additionalInfo: {
2832
+ newBounds: "Managed by Re7",
2833
+ truePrice: 1,
2834
+ feeBps: 1000,
2835
+ rebalanceConditions: {
2836
+ customShouldRebalance: async (currentPrice: number) =>
2837
+ currentPrice > 0.99 && currentPrice < 1.01,
2838
+ minWaitHours: 6,
2839
+ direction: "any" as const
2840
+ },
2841
+ quoteAsset: Global.getDefaultTokens().find(
2842
+ (t) => t.symbol === quoteTokenSymbol
2843
+ )!
2844
+ },
2845
+ settings: createRe7Settings(quoteTokenSymbol, isBTC, isDeprecated),
2846
+ faqs: getRe7FAQs(),
2847
+ risk,
2848
+ points: [],
2849
+ curator: { name: "Re7 Labs", logo: "https://www.re7labs.xyz/favicon.ico" },
2850
+ tags: isBTC ? [StrategyTag.BTC, StrategyTag.AUTOMATED_LP] : [StrategyTag.AUTOMATED_LP] as StrategyTag[],
2851
+ discontinuationInfo: isDeprecated ? {
2852
+ info: "This strategy has been deprecated and is no longer accepting new deposits."
2853
+ } : undefined,
2854
+ security: {
2855
+ ...xSTRKSTRK.security,
2856
+ accessControl: {
2857
+ ...xSTRKSTRK.security.accessControl,
2858
+ addresses: [ContractAddr.from("0x707bf89863473548fb2844c9f3f96d83fe2394453259035a5791e4b1490642")],
2859
+ },
2860
+ },
2861
+ };
2862
+ };
2863
+
2864
+ const ETHUSDCRe7Strategy = createRe7Strategy(
2865
+ "ekubo_cl_ethusdc",
2866
+ "Ekubo ETH/USDC.e",
2867
+ "0x160d8fa4569ef6a12e6bf47cb943d7b5ebba8a41a69a14c1d943050ba5ff947",
2868
+ 1504232,
2869
+ "ETH",
2870
+ "USDC.e",
2871
+ "USDC.e",
2872
+ highRisk,
2873
+ false // isBTC
2874
+ );
2875
+
2876
+ const stableCoinRisk = {
2877
+ riskFactor: _stableCoinPoolRiskFactors,
2878
+ netRisk:
2879
+ _stableCoinPoolRiskFactors.reduce(
2880
+ (acc, curr) => acc + curr.value * curr.weight,
2881
+ 0
2882
+ ) /
2883
+ _stableCoinPoolRiskFactors.reduce((acc, curr) => acc + curr.weight, 0),
2884
+ notARisks: getNoRiskTags(_stableCoinPoolRiskFactors)
2246
2885
  };
2247
2886
 
2248
2887
  const RE7Strategies: IStrategyMetadata<CLVaultStrategySettings>[] = [
2249
- ETHUSDCRe7Strategy,
2250
- {
2251
- ...ETHUSDCRe7Strategy,
2252
- name: "Ekubo USDC/USDT",
2253
- description: <></>,
2254
- address: ContractAddr.from(
2255
- "0x3a4f8debaf12af97bb911099bc011d63d6c208d4c5ba8e15d7f437785b0aaa2"
2888
+ ETHUSDCRe7Strategy,
2889
+ createRe7Strategy(
2890
+ "ekubo_cl_usdcusdt",
2891
+ "Ekubo USDC.e/USDT",
2892
+ "0x3a4f8debaf12af97bb911099bc011d63d6c208d4c5ba8e15d7f437785b0aaa2",
2893
+ 1506139,
2894
+ "USDC.e",
2895
+ "USDT",
2896
+ "USDC.e",
2897
+ stableCoinRisk,
2898
+ false // isBTC
2256
2899
  ),
2257
- launchBlock: 1506139,
2258
- // must be same order as poolKey token0 and token1
2259
- depositTokens: [
2260
- Global.getDefaultTokens().find((t) => t.symbol === "USDC")!,
2261
- Global.getDefaultTokens().find((t) => t.symbol === "USDT")!
2262
- ],
2263
- risk: {
2264
- riskFactor: _stableCoinPoolRiskFactors,
2265
- netRisk:
2266
- _stableCoinPoolRiskFactors.reduce((acc, curr) => acc + curr.value * curr.weight, 0) /
2267
- _stableCoinPoolRiskFactors.reduce((acc, curr) => acc + curr.weight, 0),
2268
- notARisks: getNoRiskTags(_stableCoinPoolRiskFactors),
2269
- }
2270
- },
2271
- {
2272
- ...ETHUSDCRe7Strategy,
2273
- name: "Ekubo STRK/USDC",
2274
- description: <></>,
2275
- address: ContractAddr.from(
2276
- "0x351b36d0d9d8b40010658825adeeddb1397436cd41acd0ff6c6e23aaa8b5b30"
2900
+ createRe7Strategy(
2901
+ "ekubo_cl_strkusdc",
2902
+ "Ekubo STRK/USDC.e",
2903
+ "0x351b36d0d9d8b40010658825adeeddb1397436cd41acd0ff6c6e23aaa8b5b30",
2904
+ 1504079,
2905
+ "STRK",
2906
+ "USDC.e",
2907
+ "USDC.e",
2908
+ highRisk,
2909
+ false // isBTC
2277
2910
  ),
2278
- launchBlock: 1504079,
2279
- // must be same order as poolKey token0 and token1
2280
- depositTokens: [
2281
- Global.getDefaultTokens().find((t) => t.symbol === "STRK")!,
2282
- Global.getDefaultTokens().find((t) => t.symbol === "USDC")!
2283
- ],
2284
- risk: highRisk,
2285
- },
2286
- {
2287
- ...ETHUSDCRe7Strategy,
2288
- name: "Ekubo STRK/ETH",
2289
- description: <></>,
2290
- address: ContractAddr.from(
2291
- "0x4ce3024b0ee879009112d7b0e073f8a87153dd35b029347d4247ffe48d28f51"
2911
+ createRe7Strategy(
2912
+ "ekubo_cl_strketh",
2913
+ "Ekubo STRK/ETH",
2914
+ "0x4ce3024b0ee879009112d7b0e073f8a87153dd35b029347d4247ffe48d28f51",
2915
+ 1504149,
2916
+ "STRK",
2917
+ "ETH",
2918
+ "USDC",
2919
+ highRisk,
2920
+ false // isBTC
2292
2921
  ),
2293
- launchBlock: 1504149,
2294
- // must be same order as poolKey token0 and token1
2295
- depositTokens: [
2296
- Global.getDefaultTokens().find((t) => t.symbol === "STRK")!,
2297
- Global.getDefaultTokens().find((t) => t.symbol === "ETH")!
2298
- ],
2299
- risk: highRisk,
2300
- },
2301
- {
2302
- ...ETHUSDCRe7Strategy,
2303
- name: "Ekubo WBTC/USDC",
2304
- description: <></>,
2305
- address: ContractAddr.from(
2306
- "0x2bcaef2eb7706875a5fdc6853dd961a0590f850bc3a031c59887189b5e84ba1"
2922
+ createRe7Strategy(
2923
+ "ekubo_cl_wbtcusdc",
2924
+ "Ekubo WBTC/USDC.e",
2925
+ "0x2bcaef2eb7706875a5fdc6853dd961a0590f850bc3a031c59887189b5e84ba1",
2926
+ 1506144,
2927
+ "WBTC",
2928
+ "USDC.e",
2929
+ "USDC.e",
2930
+ mediumRisk,
2931
+ true // isBTC
2307
2932
  ),
2308
- launchBlock: 1506144,
2309
- // must be same order as poolKey token0 and token1
2310
- depositTokens: [
2311
- Global.getDefaultTokens().find((t) => t.symbol === "WBTC")!,
2312
- Global.getDefaultTokens().find((t) => t.symbol === "USDC")!
2313
- ],
2314
- risk: mediumRisk,
2315
- },
2316
- {
2317
- ...ETHUSDCRe7Strategy,
2318
- name: "Ekubo tBTC/USDC",
2319
- description: <></>,
2320
- address: ContractAddr.from(
2321
- "0x4aad891a2d4432fba06b6558631bb13f6bbd7f6f33ab8c3111e344889ea4456"
2933
+ // createRe7Strategy(
2934
+ // "ekubo_cl_tbtcusdce",
2935
+ // "Ekubo tBTC/USDC.e",
2936
+ // "0x4aad891a2d4432fba06b6558631bb13f6bbd7f6f33ab8c3111e344889ea4456",
2937
+ // 1501764,
2938
+ // "tBTC",
2939
+ // "USDC.e",
2940
+ // "USDC.e",
2941
+ // mediumRisk,
2942
+ // ),
2943
+ createRe7Strategy(
2944
+ "ekubo_cl_wbtceth",
2945
+ "Ekubo WBTC/ETH",
2946
+ "0x1c9232b8186d9317652f05055615f18a120c2ad9e5ee96c39e031c257fb945b",
2947
+ 1506145,
2948
+ "WBTC",
2949
+ "ETH",
2950
+ "USDC",
2951
+ mediumRisk,
2952
+ true // isBTC
2322
2953
  ),
2323
- launchBlock: 1501764,
2324
- // must be same order as poolKey token0 and token1
2325
- depositTokens: [
2326
- Global.getDefaultTokens().find((t) => t.symbol === "tBTC")!,
2327
- Global.getDefaultTokens().find((t) => t.symbol === "USDC")!
2328
- ],
2329
- risk: mediumRisk,
2330
- },
2331
- {
2332
- ...ETHUSDCRe7Strategy,
2333
- name: "Ekubo WBTC/ETH",
2334
- description: <></>,
2335
- address: ContractAddr.from(
2336
- "0x1c9232b8186d9317652f05055615f18a120c2ad9e5ee96c39e031c257fb945b"
2954
+ createRe7Strategy(
2955
+ "ekubo_cl_wbtcstrk",
2956
+ "Ekubo WBTC/STRK",
2957
+ "0x1248e385c23a929a015ec298a26560fa7745bbd6e41a886550e337b02714b1b",
2958
+ 1506147,
2959
+ "WBTC",
2960
+ "STRK",
2961
+ "USDC",
2962
+ highRisk,
2963
+ true // isBTC
2337
2964
  ),
2338
- launchBlock: 1506145,
2339
- // must be same order as poolKey token0 and token1
2340
- depositTokens: [
2341
- Global.getDefaultTokens().find((t) => t.symbol === "WBTC")!,
2342
- Global.getDefaultTokens().find((t) => t.symbol === "ETH")!
2343
- ],
2344
- risk: mediumRisk,
2345
- },
2346
- {
2347
- ...ETHUSDCRe7Strategy,
2348
- name: "Ekubo WBTC/STRK",
2349
- description: <></>,
2350
- address: ContractAddr.from(
2351
- "0x1248e385c23a929a015ec298a26560fa7745bbd6e41a886550e337b02714b1b"
2965
+ createRe7Strategy(
2966
+ "ekubo_cl_usdc_v2usdt",
2967
+ "Ekubo USDC/USDT",
2968
+ "0x5203a08b471e46bf33990ac83aff577bbe5a5d789e61de2c6531e3c4773d1c9",
2969
+ 3998018,
2970
+ "USDC",
2971
+ "USDT",
2972
+ "USDC",
2973
+ stableCoinRisk,
2974
+ false // isBTC
2975
+ ),
2976
+ createRe7Strategy(
2977
+ "ekubo_cl_ethusdc_v2",
2978
+ "Ekubo ETH/USDC",
2979
+ "0x4d00c7423b3c0fae3640f6099ac97acbfd8708f099e09bfe3a7a6a680399228",
2980
+ 3998025,
2981
+ "USDC",
2982
+ "ETH",
2983
+ "USDC",
2984
+ highRisk,
2985
+ false // isBTC
2986
+ ),
2987
+ createRe7Strategy(
2988
+ "ekubo_cl_strkusdc_v2",
2989
+ "Ekubo STRK/USDC",
2990
+ "0x4de22bd0a8eb4d0a18736e66dd36d20ba50bc106346bbfac3dbeaac1ab37ce1",
2991
+ 3998030,
2992
+ "USDC",
2993
+ "STRK",
2994
+ "USDC",
2995
+ highRisk,
2996
+ false // isBTC
2997
+ ),
2998
+ createRe7Strategy(
2999
+ "ekubo_cl_wbtcusdc_v2",
3000
+ "Ekubo WBTC/USDC",
3001
+ "0x76101c3b80af1103c9c6d541ca627f61b5ae7ae79d7fce96ccdf7bdb648450d",
3002
+ 3998034,
3003
+ "USDC",
3004
+ "WBTC",
3005
+ "USDC",
3006
+ mediumRisk,
3007
+ true // isBTC
3008
+ ),
3009
+ createRe7Strategy(
3010
+ "ekubo_cl_strkbtcusdc",
3011
+ "Ekubo strkBTC/USDC",
3012
+ "0x02dfe5af1665a7adf549008161c818eb18dcf89fc9518ab812294f2b691b2845",
3013
+ 9650986,
3014
+ "USDC",
3015
+ "strkBTC",
3016
+ "USDC",
3017
+ mediumRisk,
3018
+ true // isBTC
3019
+ ),
3020
+ createRe7Strategy(
3021
+ "ekubo_cl_strkbtcstrk",
3022
+ "Ekubo strkBTC/STRK",
3023
+ "0x04784e62a4847484528ba65f500b37a9347e88632e90d866e213f2c2651be828",
3024
+ 9650592,
3025
+ "STRK",
3026
+ "strkBTC",
3027
+ "USDC",
3028
+ mediumRisk,
3029
+ true // isBTC
3030
+ ),
3031
+ createRe7Strategy(
3032
+ "ekubo_cl_strkbtceth",
3033
+ "Ekubo strkBTC/ETH",
3034
+ "0x07118ecd7dece83462b0ac8302c682fb17c7e18b0be13d81867c5bf3f80933ef",
3035
+ 9650986,
3036
+ "ETH",
3037
+ "strkBTC",
3038
+ "USDC",
3039
+ mediumRisk,
3040
+ true // isBTC
3041
+ ),
3042
+ // wbtc/strkBTC
3043
+ createRe7Strategy(
3044
+ "ekubo_cl_wbtcstrkbtc",
3045
+ "Ekubo WBTC/strkBTC",
3046
+ "0x07e927222730899442b2438bfd6218ff8ac44bd7a3420646fca359b8392e42c1",
3047
+ 9650986,
3048
+ "WBTC",
3049
+ "strkBTC",
3050
+ "strkBTC",
3051
+ stableCoinRisk,
3052
+ true // isBTC
2352
3053
  ),
2353
- launchBlock: 1506147,
2354
- // must be same order as poolKey token0 and token1
2355
- depositTokens: [
2356
- Global.getDefaultTokens().find((t) => t.symbol === "WBTC")!,
2357
- Global.getDefaultTokens().find((t) => t.symbol === "STRK")!
2358
- ],
2359
- risk: highRisk,
2360
- }
2361
3054
  ];
2362
3055
 
2363
3056
  /**
@@ -2375,7 +3068,7 @@ EkuboCLVaultStrategies.forEach((s) => {
2375
3068
  address: s.address,
2376
3069
  name: "Vault",
2377
3070
  sourceCodeUrl: "https://github.com/strkfarm/strkfarm-contracts/tree/main/src/strategies/cl_vault"
2378
- },
3071
+ },
2379
3072
  // ...COMMON_CONTRACTS
2380
3073
  ];
2381
3074
  // set docs link
@@ -2419,4 +3112,4 @@ EkuboCLVaultStrategies.forEach((s) => {
2419
3112
  "Monitor and Rebalance position to optimize yield",
2420
3113
  "Harvest and re-invest any rewards every week (Auto-compound)",
2421
3114
  ]
2422
- });
3115
+ });