@strkfarm/sdk 2.0.0-staging.20 → 2.0.0-staging.21

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.
@@ -92270,6 +92270,40 @@ spurious results.`);
92270
92270
  async getUserRealizedAPY(blockIdentifier, sinceBlocks) {
92271
92271
  throw new Error("Not implemented");
92272
92272
  }
92273
+ /**
92274
+ * Calculate lifetime earnings for a user based on provided data from client
92275
+ * Formula: lifetimeEarnings = currentValue + totalWithdrawals - totalDeposits
92276
+ *
92277
+ * @param userTVL - The user's current TVL (SingleTokenInfo with amount, usdValue, tokenInfo)
92278
+ * @param investmentFlows - Array of investment flow transactions from client
92279
+ * @returns Object containing lifetime earnings, current value, and total deposits/withdrawals
92280
+ */
92281
+ getLifetimeEarnings(userTVL, investmentFlows) {
92282
+ const tokenDecimals = userTVL.tokenInfo.decimals;
92283
+ let totalDeposits = Web3Number.fromWei("0", tokenDecimals);
92284
+ let totalWithdrawals = Web3Number.fromWei("0", tokenDecimals);
92285
+ for (const flow of investmentFlows) {
92286
+ const amount = Web3Number.fromWei(flow.amount, tokenDecimals);
92287
+ if (flow.type === "deposit") {
92288
+ totalDeposits = totalDeposits.plus(amount);
92289
+ } else if (flow.type === "withdraw" || flow.type === "redeem") {
92290
+ totalWithdrawals = totalWithdrawals.plus(amount);
92291
+ }
92292
+ }
92293
+ const lifetimeEarnings = userTVL.amount.plus(totalWithdrawals).minus(totalDeposits);
92294
+ return {
92295
+ tokenInfo: {
92296
+ tokenInfo: userTVL.tokenInfo,
92297
+ amount: lifetimeEarnings,
92298
+ usdValue: 0
92299
+ // Lifetime earnings are not converted to USD
92300
+ },
92301
+ lifetimeEarnings,
92302
+ currentValue: userTVL.amount,
92303
+ totalDeposits,
92304
+ totalWithdrawals
92305
+ };
92306
+ }
92273
92307
  };
92274
92308
 
92275
92309
  // src/node/headless.browser.ts
@@ -104000,6 +104034,13 @@ spurious results.`);
104000
104034
  ) / 1e4;
104001
104035
  return apyForGivenBlocks * (365 * 24 * 3600) / timeDiffSeconds;
104002
104036
  }
104037
+ /**
104038
+ * Calculate lifetime earnings for a user
104039
+ * Not yet implemented for Ekubo CL Vault strategy
104040
+ */
104041
+ getLifetimeEarnings(userTVL, investmentFlows) {
104042
+ throw new Error("getLifetimeEarnings is not implemented yet for this strategy");
104043
+ }
104003
104044
  /**
104004
104045
  * Calculates realized APY based on TVL per share growth, always valued in USDC.
104005
104046
  * This is a vault-level metric (same for all users) and works for all strategies,
@@ -115656,6 +115697,13 @@ spurious results.`);
115656
115697
  this.setCache(CACHE_KEY, price);
115657
115698
  return price;
115658
115699
  }
115700
+ /**
115701
+ * Calculate lifetime earnings for a user
115702
+ * Not yet implemented for Sensei Vault strategy
115703
+ */
115704
+ getLifetimeEarnings(userTVL, investmentFlows) {
115705
+ throw new Error("getLifetimeEarnings is not implemented yet for this strategy");
115706
+ }
115659
115707
  async netAPY() {
115660
115708
  try {
115661
115709
  const { pools } = await VesuAdapter.getVesuPools();
@@ -4846,6 +4846,40 @@ var BaseStrategy = class extends CacheClass {
4846
4846
  async getUserRealizedAPY(blockIdentifier, sinceBlocks) {
4847
4847
  throw new Error("Not implemented");
4848
4848
  }
4849
+ /**
4850
+ * Calculate lifetime earnings for a user based on provided data from client
4851
+ * Formula: lifetimeEarnings = currentValue + totalWithdrawals - totalDeposits
4852
+ *
4853
+ * @param userTVL - The user's current TVL (SingleTokenInfo with amount, usdValue, tokenInfo)
4854
+ * @param investmentFlows - Array of investment flow transactions from client
4855
+ * @returns Object containing lifetime earnings, current value, and total deposits/withdrawals
4856
+ */
4857
+ getLifetimeEarnings(userTVL, investmentFlows) {
4858
+ const tokenDecimals = userTVL.tokenInfo.decimals;
4859
+ let totalDeposits = Web3Number.fromWei("0", tokenDecimals);
4860
+ let totalWithdrawals = Web3Number.fromWei("0", tokenDecimals);
4861
+ for (const flow of investmentFlows) {
4862
+ const amount = Web3Number.fromWei(flow.amount, tokenDecimals);
4863
+ if (flow.type === "deposit") {
4864
+ totalDeposits = totalDeposits.plus(amount);
4865
+ } else if (flow.type === "withdraw" || flow.type === "redeem") {
4866
+ totalWithdrawals = totalWithdrawals.plus(amount);
4867
+ }
4868
+ }
4869
+ const lifetimeEarnings = userTVL.amount.plus(totalWithdrawals).minus(totalDeposits);
4870
+ return {
4871
+ tokenInfo: {
4872
+ tokenInfo: userTVL.tokenInfo,
4873
+ amount: lifetimeEarnings,
4874
+ usdValue: 0
4875
+ // Lifetime earnings are not converted to USD
4876
+ },
4877
+ lifetimeEarnings,
4878
+ currentValue: userTVL.amount,
4879
+ totalDeposits,
4880
+ totalWithdrawals
4881
+ };
4882
+ }
4849
4883
  };
4850
4884
 
4851
4885
  // src/node/headless.browser.ts
@@ -16589,6 +16623,13 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
16589
16623
  ) / 1e4;
16590
16624
  return apyForGivenBlocks * (365 * 24 * 3600) / timeDiffSeconds;
16591
16625
  }
16626
+ /**
16627
+ * Calculate lifetime earnings for a user
16628
+ * Not yet implemented for Ekubo CL Vault strategy
16629
+ */
16630
+ getLifetimeEarnings(userTVL, investmentFlows) {
16631
+ throw new Error("getLifetimeEarnings is not implemented yet for this strategy");
16632
+ }
16592
16633
  /**
16593
16634
  * Calculates realized APY based on TVL per share growth, always valued in USDC.
16594
16635
  * This is a vault-level metric (same for all users) and works for all strategies,
@@ -28252,6 +28293,13 @@ var SenseiVault = class _SenseiVault extends BaseStrategy {
28252
28293
  this.setCache(CACHE_KEY, price);
28253
28294
  return price;
28254
28295
  }
28296
+ /**
28297
+ * Calculate lifetime earnings for a user
28298
+ * Not yet implemented for Sensei Vault strategy
28299
+ */
28300
+ getLifetimeEarnings(userTVL, investmentFlows) {
28301
+ throw new Error("getLifetimeEarnings is not implemented yet for this strategy");
28302
+ }
28255
28303
  async netAPY() {
28256
28304
  try {
28257
28305
  const { pools } = await VesuAdapter.getVesuPools();
package/dist/index.d.ts CHANGED
@@ -615,6 +615,26 @@ declare class BaseStrategy<TVLInfo, ActionInfo> extends CacheClass {
615
615
  netAPY(blockIdentifier?: BlockIdentifier, sinceBlocks?: number, timeperiod?: "24h" | "7d" | "30d" | "3m"): Promise<number | NetAPYDetails>;
616
616
  getPendingRewards(): Promise<HarvestInfo[]>;
617
617
  getUserRealizedAPY(blockIdentifier?: BlockIdentifier, sinceBlocks?: number): Promise<number>;
618
+ /**
619
+ * Calculate lifetime earnings for a user based on provided data from client
620
+ * Formula: lifetimeEarnings = currentValue + totalWithdrawals - totalDeposits
621
+ *
622
+ * @param userTVL - The user's current TVL (SingleTokenInfo with amount, usdValue, tokenInfo)
623
+ * @param investmentFlows - Array of investment flow transactions from client
624
+ * @returns Object containing lifetime earnings, current value, and total deposits/withdrawals
625
+ */
626
+ getLifetimeEarnings(userTVL: SingleTokenInfo, investmentFlows: Array<{
627
+ amount: string;
628
+ type: string;
629
+ timestamp: number;
630
+ tx_hash: string;
631
+ }>): {
632
+ tokenInfo: SingleTokenInfo;
633
+ lifetimeEarnings: Web3Number;
634
+ currentValue: Web3Number;
635
+ totalDeposits: Web3Number;
636
+ totalWithdrawals: Web3Number;
637
+ };
618
638
  }
619
639
 
620
640
  interface PoolProps {
@@ -908,6 +928,16 @@ declare class EkuboCLVault extends BaseStrategy<DualTokenInfo, DualActionAmount>
908
928
  history: FeeHistory[];
909
929
  }>;
910
930
  netSharesBasedTrueAPY(blockIdentifier?: BlockIdentifier, sinceBlocks?: number): Promise<number>;
931
+ /**
932
+ * Calculate lifetime earnings for a user
933
+ * Not yet implemented for Ekubo CL Vault strategy
934
+ */
935
+ getLifetimeEarnings(userTVL: SingleTokenInfo, investmentFlows: Array<{
936
+ amount: string;
937
+ type: string;
938
+ timestamp: number;
939
+ tx_hash: string;
940
+ }>): any;
911
941
  /**
912
942
  * Calculates realized APY based on TVL per share growth, always valued in USDC.
913
943
  * This is a vault-level metric (same for all users) and works for all strategies,
@@ -1109,6 +1139,16 @@ declare class SenseiVault extends BaseStrategy<SingleTokenInfo, SingleActionAmou
1109
1139
  }>;
1110
1140
  getSecondaryTokenPriceRelativeToMain(retry?: number): Promise<number>;
1111
1141
  getSettings: () => Promise<starknet.CallResult>;
1142
+ /**
1143
+ * Calculate lifetime earnings for a user
1144
+ * Not yet implemented for Sensei Vault strategy
1145
+ */
1146
+ getLifetimeEarnings(userTVL: SingleTokenInfo, investmentFlows: Array<{
1147
+ amount: string;
1148
+ type: string;
1149
+ timestamp: number;
1150
+ tx_hash: string;
1151
+ }>): any;
1112
1152
  netAPY(): Promise<number>;
1113
1153
  /**
1114
1154
  * Calculates user realized APY based on position growth accounting for deposits and withdrawals.
package/dist/index.js CHANGED
@@ -4882,6 +4882,40 @@ var BaseStrategy = class extends CacheClass {
4882
4882
  async getUserRealizedAPY(blockIdentifier, sinceBlocks) {
4883
4883
  throw new Error("Not implemented");
4884
4884
  }
4885
+ /**
4886
+ * Calculate lifetime earnings for a user based on provided data from client
4887
+ * Formula: lifetimeEarnings = currentValue + totalWithdrawals - totalDeposits
4888
+ *
4889
+ * @param userTVL - The user's current TVL (SingleTokenInfo with amount, usdValue, tokenInfo)
4890
+ * @param investmentFlows - Array of investment flow transactions from client
4891
+ * @returns Object containing lifetime earnings, current value, and total deposits/withdrawals
4892
+ */
4893
+ getLifetimeEarnings(userTVL, investmentFlows) {
4894
+ const tokenDecimals = userTVL.tokenInfo.decimals;
4895
+ let totalDeposits = Web3Number.fromWei("0", tokenDecimals);
4896
+ let totalWithdrawals = Web3Number.fromWei("0", tokenDecimals);
4897
+ for (const flow of investmentFlows) {
4898
+ const amount = Web3Number.fromWei(flow.amount, tokenDecimals);
4899
+ if (flow.type === "deposit") {
4900
+ totalDeposits = totalDeposits.plus(amount);
4901
+ } else if (flow.type === "withdraw" || flow.type === "redeem") {
4902
+ totalWithdrawals = totalWithdrawals.plus(amount);
4903
+ }
4904
+ }
4905
+ const lifetimeEarnings = userTVL.amount.plus(totalWithdrawals).minus(totalDeposits);
4906
+ return {
4907
+ tokenInfo: {
4908
+ tokenInfo: userTVL.tokenInfo,
4909
+ amount: lifetimeEarnings,
4910
+ usdValue: 0
4911
+ // Lifetime earnings are not converted to USD
4912
+ },
4913
+ lifetimeEarnings,
4914
+ currentValue: userTVL.amount,
4915
+ totalDeposits,
4916
+ totalWithdrawals
4917
+ };
4918
+ }
4885
4919
  };
4886
4920
 
4887
4921
  // src/node/headless.browser.ts
@@ -16621,6 +16655,13 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
16621
16655
  ) / 1e4;
16622
16656
  return apyForGivenBlocks * (365 * 24 * 3600) / timeDiffSeconds;
16623
16657
  }
16658
+ /**
16659
+ * Calculate lifetime earnings for a user
16660
+ * Not yet implemented for Ekubo CL Vault strategy
16661
+ */
16662
+ getLifetimeEarnings(userTVL, investmentFlows) {
16663
+ throw new Error("getLifetimeEarnings is not implemented yet for this strategy");
16664
+ }
16624
16665
  /**
16625
16666
  * Calculates realized APY based on TVL per share growth, always valued in USDC.
16626
16667
  * This is a vault-level metric (same for all users) and works for all strategies,
@@ -28385,6 +28426,13 @@ var SenseiVault = class _SenseiVault extends BaseStrategy {
28385
28426
  this.setCache(CACHE_KEY, price);
28386
28427
  return price;
28387
28428
  }
28429
+ /**
28430
+ * Calculate lifetime earnings for a user
28431
+ * Not yet implemented for Sensei Vault strategy
28432
+ */
28433
+ getLifetimeEarnings(userTVL, investmentFlows) {
28434
+ throw new Error("getLifetimeEarnings is not implemented yet for this strategy");
28435
+ }
28388
28436
  async netAPY() {
28389
28437
  try {
28390
28438
  const { pools } = await VesuAdapter.getVesuPools();
package/dist/index.mjs CHANGED
@@ -4748,6 +4748,40 @@ var BaseStrategy = class extends CacheClass {
4748
4748
  async getUserRealizedAPY(blockIdentifier, sinceBlocks) {
4749
4749
  throw new Error("Not implemented");
4750
4750
  }
4751
+ /**
4752
+ * Calculate lifetime earnings for a user based on provided data from client
4753
+ * Formula: lifetimeEarnings = currentValue + totalWithdrawals - totalDeposits
4754
+ *
4755
+ * @param userTVL - The user's current TVL (SingleTokenInfo with amount, usdValue, tokenInfo)
4756
+ * @param investmentFlows - Array of investment flow transactions from client
4757
+ * @returns Object containing lifetime earnings, current value, and total deposits/withdrawals
4758
+ */
4759
+ getLifetimeEarnings(userTVL, investmentFlows) {
4760
+ const tokenDecimals = userTVL.tokenInfo.decimals;
4761
+ let totalDeposits = Web3Number.fromWei("0", tokenDecimals);
4762
+ let totalWithdrawals = Web3Number.fromWei("0", tokenDecimals);
4763
+ for (const flow of investmentFlows) {
4764
+ const amount = Web3Number.fromWei(flow.amount, tokenDecimals);
4765
+ if (flow.type === "deposit") {
4766
+ totalDeposits = totalDeposits.plus(amount);
4767
+ } else if (flow.type === "withdraw" || flow.type === "redeem") {
4768
+ totalWithdrawals = totalWithdrawals.plus(amount);
4769
+ }
4770
+ }
4771
+ const lifetimeEarnings = userTVL.amount.plus(totalWithdrawals).minus(totalDeposits);
4772
+ return {
4773
+ tokenInfo: {
4774
+ tokenInfo: userTVL.tokenInfo,
4775
+ amount: lifetimeEarnings,
4776
+ usdValue: 0
4777
+ // Lifetime earnings are not converted to USD
4778
+ },
4779
+ lifetimeEarnings,
4780
+ currentValue: userTVL.amount,
4781
+ totalDeposits,
4782
+ totalWithdrawals
4783
+ };
4784
+ }
4751
4785
  };
4752
4786
 
4753
4787
  // src/node/headless.browser.ts
@@ -16491,6 +16525,13 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
16491
16525
  ) / 1e4;
16492
16526
  return apyForGivenBlocks * (365 * 24 * 3600) / timeDiffSeconds;
16493
16527
  }
16528
+ /**
16529
+ * Calculate lifetime earnings for a user
16530
+ * Not yet implemented for Ekubo CL Vault strategy
16531
+ */
16532
+ getLifetimeEarnings(userTVL, investmentFlows) {
16533
+ throw new Error("getLifetimeEarnings is not implemented yet for this strategy");
16534
+ }
16494
16535
  /**
16495
16536
  * Calculates realized APY based on TVL per share growth, always valued in USDC.
16496
16537
  * This is a vault-level metric (same for all users) and works for all strategies,
@@ -28255,6 +28296,13 @@ var SenseiVault = class _SenseiVault extends BaseStrategy {
28255
28296
  this.setCache(CACHE_KEY, price);
28256
28297
  return price;
28257
28298
  }
28299
+ /**
28300
+ * Calculate lifetime earnings for a user
28301
+ * Not yet implemented for Sensei Vault strategy
28302
+ */
28303
+ getLifetimeEarnings(userTVL, investmentFlows) {
28304
+ throw new Error("getLifetimeEarnings is not implemented yet for this strategy");
28305
+ }
28258
28306
  async netAPY() {
28259
28307
  try {
28260
28308
  const { pools } = await VesuAdapter.getVesuPools();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strkfarm/sdk",
3
- "version": "2.0.0-staging.20",
3
+ "version": "2.0.0-staging.21",
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",
@@ -85,4 +85,58 @@ export class BaseStrategy<TVLInfo, ActionInfo> extends CacheClass {
85
85
  ): Promise<number> {
86
86
  throw new Error("Not implemented");
87
87
  }
88
+
89
+ /**
90
+ * Calculate lifetime earnings for a user based on provided data from client
91
+ * Formula: lifetimeEarnings = currentValue + totalWithdrawals - totalDeposits
92
+ *
93
+ * @param userTVL - The user's current TVL (SingleTokenInfo with amount, usdValue, tokenInfo)
94
+ * @param investmentFlows - Array of investment flow transactions from client
95
+ * @returns Object containing lifetime earnings, current value, and total deposits/withdrawals
96
+ */
97
+ getLifetimeEarnings(
98
+ userTVL: SingleTokenInfo,
99
+ investmentFlows: Array<{ amount: string; type: string; timestamp: number; tx_hash: string }>
100
+ ): {
101
+ tokenInfo: SingleTokenInfo;
102
+ lifetimeEarnings: Web3Number;
103
+ currentValue: Web3Number;
104
+ totalDeposits: Web3Number;
105
+ totalWithdrawals: Web3Number;
106
+ } {
107
+ // Get token decimals from userTVL
108
+ const tokenDecimals = userTVL.tokenInfo.decimals;
109
+
110
+ // Initialize totals
111
+ let totalDeposits = Web3Number.fromWei("0", tokenDecimals);
112
+ let totalWithdrawals = Web3Number.fromWei("0", tokenDecimals);
113
+
114
+ // Process investment flows
115
+ for (const flow of investmentFlows) {
116
+ const amount = Web3Number.fromWei(flow.amount, tokenDecimals);
117
+
118
+ if (flow.type === 'deposit') {
119
+ totalDeposits = totalDeposits.plus(amount);
120
+ } else if (flow.type === 'withdraw' || flow.type === 'redeem') {
121
+ totalWithdrawals = totalWithdrawals.plus(amount);
122
+ }
123
+ }
124
+
125
+ // Calculate lifetime earnings: current value + withdrawals - deposits
126
+ const lifetimeEarnings = userTVL.amount
127
+ .plus(totalWithdrawals)
128
+ .minus(totalDeposits);
129
+
130
+ return {
131
+ tokenInfo: {
132
+ tokenInfo: userTVL.tokenInfo,
133
+ amount: lifetimeEarnings,
134
+ usdValue: 0, // Lifetime earnings are not converted to USD
135
+ },
136
+ lifetimeEarnings,
137
+ currentValue: userTVL.amount,
138
+ totalDeposits,
139
+ totalWithdrawals,
140
+ };
141
+ }
88
142
  }
@@ -36,7 +36,7 @@ import EkuboMathAbi from "@/data/ekubo-math.abi.json";
36
36
  import ERC4626Abi from "@/data/erc4626.abi.json";
37
37
  import { Global } from "@/global";
38
38
  import { AvnuWrapper, ERC20, SwapInfo } from "@/modules";
39
- import { BaseStrategy } from "./base-strategy";
39
+ import { BaseStrategy, SingleTokenInfo } from "./base-strategy";
40
40
  import { DualActionAmount } from "./base-strategy";
41
41
  import { DualTokenInfo } from "./base-strategy";
42
42
  import { log } from "winston";
@@ -488,6 +488,17 @@ export class EkuboCLVault extends BaseStrategy<
488
488
  return (apyForGivenBlocks * (365 * 24 * 3600)) / timeDiffSeconds;
489
489
  }
490
490
 
491
+ /**
492
+ * Calculate lifetime earnings for a user
493
+ * Not yet implemented for Ekubo CL Vault strategy
494
+ */
495
+ getLifetimeEarnings(
496
+ userTVL: SingleTokenInfo,
497
+ investmentFlows: Array<{ amount: string; type: string; timestamp: number; tx_hash: string }>
498
+ ): any {
499
+ throw new Error("getLifetimeEarnings is not implemented yet for this strategy");
500
+ }
501
+
491
502
  /**
492
503
  * Calculates realized APY based on TVL per share growth, always valued in USDC.
493
504
  * This is a vault-level metric (same for all users) and works for all strategies,
@@ -238,6 +238,17 @@ export class SenseiVault extends BaseStrategy<
238
238
  return settings;
239
239
  };
240
240
 
241
+ /**
242
+ * Calculate lifetime earnings for a user
243
+ * Not yet implemented for Sensei Vault strategy
244
+ */
245
+ getLifetimeEarnings(
246
+ userTVL: SingleTokenInfo,
247
+ investmentFlows: Array<{ amount: string; type: string; timestamp: number; tx_hash: string }>
248
+ ): any {
249
+ throw new Error("getLifetimeEarnings is not implemented yet for this strategy");
250
+ }
251
+
241
252
  async netAPY(): Promise<number> {
242
253
  try {
243
254
  // Fetch Vesu pools and select the Re7 xSTRK pool
@@ -654,4 +665,4 @@ export const SenseiStrategies: IStrategyMetadata<SenseiVaultSettings>[] =
654
665
  toolTip: "This strategy holds xSTRK. Earn 3-4x Endur points on your xSTRK due to the leverage. Points can be found on endur.fi.",
655
666
  }]
656
667
  },
657
- ];
668
+ ];
@@ -1,7 +1,11 @@
1
1
  import { SingleTokenInfo, DualTokenInfo } from "../strategies/base-strategy";
2
2
  import { BaseStrategy } from "../strategies/base-strategy";
3
3
  import { AmountsInfo, StrategyCapabilities, TokenInfo } from "@/interfaces";
4
- import { Web3Number } from "@/dataTypes";
4
+ import { ContractAddr, Web3Number } from "@/dataTypes";
5
+ import { gql } from "@apollo/client";
6
+ import apolloClient from "@/modules/apollo-client";
7
+ import { num } from "starknet";
8
+ import { logger } from "./logger";
5
9
 
6
10
  /**
7
11
  * Convert SDK TVL info (SingleTokenInfo or DualTokenInfo) to client AmountsInfo format
@@ -54,4 +58,4 @@ export function detectCapabilities(
54
58
  export function isDualTokenStrategy(strategy: BaseStrategy<any, any>): boolean {
55
59
  // Check if strategy has matchInputAmounts (dual token strategies have this)
56
60
  return typeof (strategy as any).matchInputAmounts === "function";
57
- }
61
+ }