@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
@@ -1,8 +1,9 @@
1
1
  import { ContractAddr, Web3Number } from "@/dataTypes";
2
2
  import { IConfig, TokenInfo, VaultPosition } from "@/interfaces";
3
3
  import { CacheClass } from "@/utils/cacheClass";
4
- import { Call } from "starknet";
5
4
  import { PositionInfo } from "./universal-adapters";
5
+ import { Call, BlockIdentifier } from "starknet";
6
+ import { HarvestInfo } from "@/modules/harvests";
6
7
 
7
8
  export interface SingleActionAmount {
8
9
  tokenInfo: TokenInfo,
@@ -28,33 +29,87 @@ export interface DualTokenInfo {
28
29
  token1: SingleTokenInfo
29
30
  }
30
31
 
32
+ export type StrategyInputMode = "single" | "dual";
33
+ export type InputModeFromAction<T> = T extends DualActionAmount ? "dual" : "single";
34
+
35
+ export interface NetAPYSplit {
36
+ apy: number;
37
+ id: string;
38
+ }
39
+
40
+ export interface NetAPYDetails {
41
+ net: number;
42
+ splits: NetAPYSplit[];
43
+ }
44
+
45
+ export type UserPositionCardSubValueColor = "default" | "positive" | "negative" | "info";
46
+
47
+ export interface UserPositionCard {
48
+ title: string;
49
+ value: string;
50
+ tooltip?: string;
51
+ subValue?: string;
52
+ subValueColor?: UserPositionCardSubValueColor;
53
+ }
54
+
55
+ export interface UserPositionCardsInput {
56
+ user: ContractAddr;
57
+ investmentFlows?: Array<{ amount: string; type: string; timestamp: number; tx_hash: string }>;
58
+ usualTimeToEarnings?: string | null;
59
+ usualTimeToEarningsDescription?: string | null;
60
+ }
61
+
31
62
  interface CacheData {
32
63
  timestamp: number;
33
64
  ttl: number;
34
65
  data: any;
35
66
  }
36
- export class BaseStrategy<TVLInfo, ActionInfo> extends CacheClass {
37
- readonly config: IConfig;
38
- readonly cache: Map<string, CacheData> = new Map();
67
+ export class BaseStrategy<
68
+ TVLInfo,
69
+ DepositActionInfo,
70
+ WithdrawActionInfo = DepositActionInfo,
71
+ > extends CacheClass {
72
+ readonly config: IConfig;
73
+ readonly cache: Map<string, CacheData> = new Map();
74
+ private readonly _depositInputMode: InputModeFromAction<DepositActionInfo>;
75
+ private readonly _withdrawInputMode: InputModeFromAction<WithdrawActionInfo>;
39
76
 
40
- constructor(config: IConfig) {
77
+ constructor(
78
+ config: IConfig,
79
+ inputModes?: {
80
+ depositInputMode?: InputModeFromAction<DepositActionInfo>;
81
+ withdrawInputMode?: InputModeFromAction<WithdrawActionInfo>;
82
+ }
83
+ ) {
41
84
  super();
42
85
  this.config = config;
86
+ this._depositInputMode = (inputModes?.depositInputMode ??
87
+ ("single" as InputModeFromAction<DepositActionInfo>));
88
+ this._withdrawInputMode = (inputModes?.withdrawInputMode ??
89
+ ("single" as InputModeFromAction<WithdrawActionInfo>));
90
+ }
91
+
92
+ depositInputMode(): InputModeFromAction<DepositActionInfo> {
93
+ return this._depositInputMode;
94
+ }
95
+
96
+ withdrawInputMode(): InputModeFromAction<WithdrawActionInfo> {
97
+ return this._withdrawInputMode;
43
98
  }
44
99
 
45
- async getUserTVL(user: ContractAddr): Promise<TVLInfo> {
100
+ async getUserTVL(user: ContractAddr, blockIdentifier?: BlockIdentifier): Promise<TVLInfo> {
46
101
  throw new Error("Not implemented");
47
102
  }
48
103
 
49
104
  async getTVL(): Promise<TVLInfo> {
50
105
  throw new Error("Not implemented");
51
- }
106
+ }
52
107
 
53
- async depositCall(amountInfo: ActionInfo, receiver: ContractAddr): Promise<Call[]> {
108
+ async depositCall(amountInfo: DepositActionInfo, receiver: ContractAddr): Promise<Call[]> {
54
109
  throw new Error("Not implemented");
55
110
  }
56
111
 
57
- async withdrawCall(amountInfo: ActionInfo, receiver: ContractAddr, owner: ContractAddr): Promise<Call[]> {
112
+ async withdrawCall(amountInfo: WithdrawActionInfo, receiver: ContractAddr, owner: ContractAddr): Promise<Call[]> {
58
113
  throw new Error("Not implemented");
59
114
  }
60
115
 
@@ -62,19 +117,116 @@ export class BaseStrategy<TVLInfo, ActionInfo> extends CacheClass {
62
117
  throw new Error("Not implemented");
63
118
  }
64
119
 
65
- async getUnusedBalance(): Promise<SingleTokenInfo> {
120
+ async netAPY(
121
+ blockIdentifier?: BlockIdentifier,
122
+ sinceBlocks?: number,
123
+ timeperiod?: "24h" | "7d" | "30d" | "3m"
124
+ ): Promise<number | string | NetAPYDetails> {
66
125
  throw new Error("Not implemented");
67
126
  }
68
127
 
69
- async netAPY(): Promise<APYInfo> {
70
- throw new Error("Not implemented");
128
+ async getPendingRewards(): Promise<HarvestInfo[]> {
129
+ return [];
71
130
  }
72
131
 
73
- async getAUM(): Promise<{net: SingleTokenInfo, prevAum: Web3Number, splits: PositionInfo[]}> {
132
+ async getUserRealizedAPY(
133
+ blockIdentifier?: BlockIdentifier,
134
+ sinceBlocks?: number
135
+ ): Promise<number> {
74
136
  throw new Error("Not implemented");
75
137
  }
76
138
 
77
- async getHealthFactors(): Promise<number[]> {
78
- throw new Error("Not implemented");
139
+ async getUserPositionCards(_input: UserPositionCardsInput): Promise<UserPositionCard[]> {
140
+ throw new Error("Not implemented");
79
141
  }
80
- }
142
+
143
+ async getMaxTVL() : Promise<Web3Number> {
144
+ // Can throw an error as well if needed, RN returning 0
145
+ return new Web3Number('0', 18)
146
+ }
147
+
148
+ protected formatTokenAmountForCard(amount: Web3Number, tokenInfo: TokenInfo): string {
149
+ const displayDecimals = tokenInfo.displayDecimals ?? 2;
150
+ const fixed = Number(amount.toFixed(displayDecimals));
151
+ const normalized = Number.isFinite(fixed) ? fixed : 0;
152
+ return `${normalized.toLocaleString("en-US", {
153
+ maximumFractionDigits: displayDecimals,
154
+ minimumFractionDigits: 0,
155
+ })} ${tokenInfo.symbol}`;
156
+ }
157
+
158
+ protected formatPercentForCard(value: number): string {
159
+ if (!Number.isFinite(value)) return "N/A";
160
+ return `${(value * 100).toFixed(2)}%`;
161
+ }
162
+
163
+ protected formatUSDForCard(value: number): string {
164
+ if (!Number.isFinite(value)) return "$0.00";
165
+ return new Intl.NumberFormat("en-US", {
166
+ style: "currency",
167
+ currency: "USD",
168
+ maximumFractionDigits: 2,
169
+ }).format(value);
170
+ }
171
+
172
+ protected getSubValueColorFromSignedNumber(value: number): UserPositionCardSubValueColor {
173
+ if (!Number.isFinite(value)) return "default";
174
+ if (value > 0) return "positive";
175
+ if (value < 0) return "negative";
176
+ return "default";
177
+ }
178
+
179
+ /**
180
+ * Calculate lifetime earnings for a user based on provided data from client
181
+ * Formula: lifetimeEarnings = currentValue + totalWithdrawals - totalDeposits
182
+ *
183
+ * @param userTVL - The user's current TVL (SingleTokenInfo with amount, usdValue, tokenInfo)
184
+ * @param investmentFlows - Array of investment flow transactions from client
185
+ * @returns Object containing lifetime earnings, current value, and total deposits/withdrawals
186
+ */
187
+ getLifetimeEarnings(
188
+ userTVL: SingleTokenInfo,
189
+ investmentFlows: Array<{ amount: string; type: string; timestamp: number; tx_hash: string }>
190
+ ): {
191
+ tokenInfo: SingleTokenInfo;
192
+ lifetimeEarnings: Web3Number;
193
+ currentValue: Web3Number;
194
+ totalDeposits: Web3Number;
195
+ totalWithdrawals: Web3Number;
196
+ } {
197
+ // Get token decimals from userTVL
198
+ const tokenDecimals = userTVL.tokenInfo.decimals;
199
+
200
+ // Initialize totals
201
+ let totalDeposits = Web3Number.fromWei("0", tokenDecimals);
202
+ let totalWithdrawals = Web3Number.fromWei("0", tokenDecimals);
203
+
204
+ // Process investment flows
205
+ for (const flow of investmentFlows) {
206
+ const amount = Web3Number.fromWei(flow.amount, tokenDecimals);
207
+
208
+ if (flow.type === 'deposit') {
209
+ totalDeposits = totalDeposits.plus(amount);
210
+ } else if (flow.type === 'withdraw' || flow.type === 'redeem') {
211
+ totalWithdrawals = totalWithdrawals.plus(amount);
212
+ }
213
+ }
214
+
215
+ // Calculate lifetime earnings: current value + withdrawals - deposits
216
+ const lifetimeEarnings = userTVL.amount
217
+ .plus(totalWithdrawals)
218
+ .minus(totalDeposits);
219
+
220
+ return {
221
+ tokenInfo: {
222
+ tokenInfo: userTVL.tokenInfo,
223
+ amount: lifetimeEarnings,
224
+ usdValue: 0, // Lifetime earnings are not converted to USD
225
+ },
226
+ lifetimeEarnings,
227
+ currentValue: userTVL.amount,
228
+ totalDeposits,
229
+ totalWithdrawals,
230
+ };
231
+ }
232
+ }
@@ -1,12 +1,17 @@
1
1
  import { ContractAddr } from "@/dataTypes";
2
2
 
3
- export const COMMON_CONTRACTS = [{
3
+ export const MY_ACCESS_CONTROL = {
4
4
  address: ContractAddr.from("0x0636a3f51cc37f5729e4da4b1de6a8549a28f3c0d5bf3b17f150971e451ff9c2"),
5
5
  name: "Access Controller",
6
6
  sourceCodeUrl: "https://github.com/strkfarm/strkfarm-contracts/blob/main/src/components/accessControl.cairo",
7
- }];
7
+ };
8
+
9
+ export const COMMON_CONTRACTS = [MY_ACCESS_CONTROL];
8
10
 
9
11
  export const ENDPOINTS = {
10
12
  VESU_BASE: "https://proxy.api.troves.fi/vesu",
11
13
  VESU_BASE_STAGING: "https://proxy.api.troves.fi/vesu-staging"
12
- }
14
+ }
15
+
16
+
17
+ export const MAX_AVNU_RETRY_DELAY = Number(process.env.MAX_AVNU_RETRY_DELAY ?? 100);