@strkfarm/sdk 2.0.0-dev.3 → 2.0.0-dev.30

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 (75) hide show
  1. package/dist/cli.js +190 -36
  2. package/dist/cli.mjs +188 -34
  3. package/dist/index.browser.global.js +78478 -45620
  4. package/dist/index.browser.mjs +19583 -9901
  5. package/dist/index.d.ts +3763 -1424
  6. package/dist/index.js +20980 -11063
  7. package/dist/index.mjs +20948 -11087
  8. package/package.json +1 -1
  9. package/src/data/avnu.abi.json +840 -0
  10. package/src/data/ekubo-price-fethcer.abi.json +265 -0
  11. package/src/dataTypes/_bignumber.ts +13 -4
  12. package/src/dataTypes/bignumber.browser.ts +6 -1
  13. package/src/dataTypes/bignumber.node.ts +5 -1
  14. package/src/dataTypes/index.ts +3 -2
  15. package/src/dataTypes/mynumber.ts +141 -0
  16. package/src/global.ts +76 -41
  17. package/src/index.browser.ts +2 -1
  18. package/src/interfaces/common.tsx +175 -3
  19. package/src/modules/ExtendedWrapperSDk/types.ts +28 -5
  20. package/src/modules/ExtendedWrapperSDk/wrapper.ts +275 -59
  21. package/src/modules/apollo-client-config.ts +28 -0
  22. package/src/modules/avnu.ts +4 -4
  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/pragma.ts +23 -8
  28. package/src/modules/pricer-from-api.ts +156 -15
  29. package/src/modules/pricer-lst.ts +1 -1
  30. package/src/modules/pricer.ts +40 -4
  31. package/src/modules/pricerBase.ts +2 -1
  32. package/src/node/deployer.ts +36 -1
  33. package/src/node/pricer-redis.ts +2 -1
  34. package/src/strategies/base-strategy.ts +78 -10
  35. package/src/strategies/ekubo-cl-vault.tsx +906 -347
  36. package/src/strategies/factory.ts +159 -0
  37. package/src/strategies/index.ts +7 -1
  38. package/src/strategies/registry.ts +239 -0
  39. package/src/strategies/sensei.ts +335 -7
  40. package/src/strategies/svk-strategy.ts +97 -27
  41. package/src/strategies/types.ts +4 -0
  42. package/src/strategies/universal-adapters/adapter-utils.ts +2 -1
  43. package/src/strategies/universal-adapters/avnu-adapter.ts +180 -265
  44. package/src/strategies/universal-adapters/baseAdapter.ts +263 -251
  45. package/src/strategies/universal-adapters/common-adapter.ts +206 -203
  46. package/src/strategies/universal-adapters/extended-adapter.ts +490 -316
  47. package/src/strategies/universal-adapters/index.ts +11 -8
  48. package/src/strategies/universal-adapters/svk-troves-adapter.ts +364 -0
  49. package/src/strategies/universal-adapters/token-transfer-adapter.ts +200 -0
  50. package/src/strategies/universal-adapters/usdc<>usdce-adapter.ts +200 -0
  51. package/src/strategies/universal-adapters/vesu-adapter.ts +120 -82
  52. package/src/strategies/universal-adapters/vesu-modify-position-adapter.ts +476 -0
  53. package/src/strategies/universal-adapters/vesu-multiply-adapter.ts +1067 -704
  54. package/src/strategies/universal-adapters/vesu-position-common.ts +251 -0
  55. package/src/strategies/universal-adapters/vesu-supply-only-adapter.ts +18 -3
  56. package/src/strategies/universal-lst-muliplier-strategy.tsx +397 -204
  57. package/src/strategies/universal-strategy.tsx +1426 -1173
  58. package/src/strategies/vesu-extended-strategy/services/executionService.ts +2233 -0
  59. package/src/strategies/vesu-extended-strategy/services/extended-vesu-state-manager.ts +4087 -0
  60. package/src/strategies/vesu-extended-strategy/services/ltv-imbalance-rebalance-math.ts +783 -0
  61. package/src/strategies/vesu-extended-strategy/services/operationService.ts +38 -16
  62. package/src/strategies/vesu-extended-strategy/types/transaction-metadata.ts +88 -0
  63. package/src/strategies/vesu-extended-strategy/utils/config.runtime.ts +1 -0
  64. package/src/strategies/vesu-extended-strategy/utils/constants.ts +5 -6
  65. package/src/strategies/vesu-extended-strategy/utils/helper.ts +259 -103
  66. package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +688 -817
  67. package/src/strategies/vesu-rebalance.tsx +255 -152
  68. package/src/utils/cacheClass.ts +11 -2
  69. package/src/utils/health-factor-math.ts +4 -1
  70. package/src/utils/index.ts +3 -1
  71. package/src/utils/logger.browser.ts +22 -4
  72. package/src/utils/logger.node.ts +259 -24
  73. package/src/utils/starknet-call-parser.ts +1036 -0
  74. package/src/utils/strategy-utils.ts +61 -0
  75. package/src/strategies/universal-adapters/unused-balance-adapter.ts +0 -109
@@ -4,6 +4,7 @@ import { readFileSync, existsSync, writeFileSync } from 'fs'
4
4
  import { IConfig } from '../interfaces';
5
5
  import { Store, getDefaultStoreConfig } from '../utils/store';
6
6
  import { add } from 'winston';
7
+ import { logger } from '@/utils';
7
8
 
8
9
  function getContracts() {
9
10
  const PATH = './contracts.json'
@@ -207,13 +208,47 @@ async function executeTransactions(
207
208
  return tx;
208
209
  }
209
210
 
211
+ async function myWaitForTransaction(
212
+ transaction_hash: string,
213
+ provider: RpcProvider,
214
+ retry = 0
215
+ ) {
216
+ const MAX_RETRIES = 60;
217
+ logger.verbose(`Waiting for transaction: ${transaction_hash}, retry: ${retry}`);
218
+ try {
219
+ const status = await provider.getTransactionStatus(transaction_hash);
220
+ logger.verbose(`Transaction status: ${JSON.stringify(status.execution_status)}`);
221
+ if (status.execution_status == TransactionExecutionStatus.SUCCEEDED) {
222
+ return true;
223
+ }
224
+ if (status.execution_status == TransactionExecutionStatus.REVERTED) {
225
+ throw new Error(`Transaction reverted: ${transaction_hash}`);
226
+ }
227
+ if (retry > MAX_RETRIES) {
228
+ throw new Error(`Transaction not found: ${transaction_hash}`);
229
+ }
230
+ await new Promise(resolve => setTimeout(resolve, 1000));
231
+ return myWaitForTransaction(transaction_hash, provider, retry + 1);
232
+ } catch (error) {
233
+ if (error instanceof Error && error.message.includes('Transaction reverted')) {
234
+ throw new Error(`Transaction reverted: ${transaction_hash}`);
235
+ }
236
+ if (retry > MAX_RETRIES) {
237
+ throw error;
238
+ }
239
+ await new Promise(resolve => setTimeout(resolve, 1000));
240
+ return myWaitForTransaction(transaction_hash, provider, retry + 1);
241
+ }
242
+ }
243
+
210
244
  const Deployer = {
211
245
  getAccount,
212
246
  myDeclare,
213
247
  deployContract,
214
248
  prepareMultiDeployContracts,
215
249
  executeDeployCalls,
216
- executeTransactions
250
+ executeTransactions,
251
+ myWaitForTransaction
217
252
  }
218
253
 
219
254
  export default Deployer;
@@ -4,6 +4,7 @@ import { PriceInfo, Pricer } from '@/modules/pricer';
4
4
  import { createClient } from 'redis';
5
5
  import type { RedisClientType } from 'redis'
6
6
  import { logger } from "@/utils/logger";
7
+ import { BlockIdentifier } from "starknet";
7
8
 
8
9
  export class PricerRedis extends Pricer {
9
10
  private redisClient: RedisClientType | null = null;
@@ -51,7 +52,7 @@ export class PricerRedis extends Pricer {
51
52
  }
52
53
 
53
54
  /** Returns price from redis */
54
- async getPrice(tokenSymbol: string) {
55
+ async getPrice(tokenSymbol: string, blockNumber?: BlockIdentifier) {
55
56
  const STALE_TIME = 60000;
56
57
  if (!this.redisClient) {
57
58
  throw new FatalError(`Redis client not initialised`);
@@ -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,6 +29,16 @@ export interface DualTokenInfo {
28
29
  token1: SingleTokenInfo
29
30
  }
30
31
 
32
+ export interface NetAPYSplit {
33
+ apy: number;
34
+ id: string;
35
+ }
36
+
37
+ export interface NetAPYDetails {
38
+ net: number;
39
+ splits: NetAPYSplit[];
40
+ }
41
+
31
42
  interface CacheData {
32
43
  timestamp: number;
33
44
  ttl: number;
@@ -42,13 +53,13 @@ export class BaseStrategy<TVLInfo, ActionInfo> extends CacheClass {
42
53
  this.config = config;
43
54
  }
44
55
 
45
- async getUserTVL(user: ContractAddr): Promise<TVLInfo> {
56
+ async getUserTVL(user: ContractAddr, blockIdentifier?: BlockIdentifier): Promise<TVLInfo> {
46
57
  throw new Error("Not implemented");
47
58
  }
48
59
 
49
60
  async getTVL(): Promise<TVLInfo> {
50
61
  throw new Error("Not implemented");
51
- }
62
+ }
52
63
 
53
64
  async depositCall(amountInfo: ActionInfo, receiver: ContractAddr): Promise<Call[]> {
54
65
  throw new Error("Not implemented");
@@ -62,19 +73,76 @@ export class BaseStrategy<TVLInfo, ActionInfo> extends CacheClass {
62
73
  throw new Error("Not implemented");
63
74
  }
64
75
 
65
- async getUnusedBalance(): Promise<SingleTokenInfo> {
76
+ async netAPY(
77
+ blockIdentifier?: BlockIdentifier,
78
+ sinceBlocks?: number,
79
+ timeperiod?: "24h" | "7d" | "30d" | "3m"
80
+ ): Promise<number | NetAPYDetails> {
66
81
  throw new Error("Not implemented");
67
82
  }
68
83
 
69
- async netAPY(): Promise<APYInfo> {
70
- throw new Error("Not implemented");
84
+ async getPendingRewards(): Promise<HarvestInfo[]> {
85
+ return [];
71
86
  }
72
87
 
73
- async getAUM(): Promise<{net: SingleTokenInfo, prevAum: Web3Number, splits: PositionInfo[]}> {
88
+ async getUserRealizedAPY(
89
+ blockIdentifier?: BlockIdentifier,
90
+ sinceBlocks?: number
91
+ ): Promise<number> {
74
92
  throw new Error("Not implemented");
75
93
  }
76
94
 
77
- async getHealthFactors(): Promise<number[]> {
78
- throw new Error("Not implemented");
95
+ /**
96
+ * Calculate lifetime earnings for a user based on provided data from client
97
+ * Formula: lifetimeEarnings = currentValue + totalWithdrawals - totalDeposits
98
+ *
99
+ * @param userTVL - The user's current TVL (SingleTokenInfo with amount, usdValue, tokenInfo)
100
+ * @param investmentFlows - Array of investment flow transactions from client
101
+ * @returns Object containing lifetime earnings, current value, and total deposits/withdrawals
102
+ */
103
+ getLifetimeEarnings(
104
+ userTVL: SingleTokenInfo,
105
+ investmentFlows: Array<{ amount: string; type: string; timestamp: number; tx_hash: string }>
106
+ ): {
107
+ tokenInfo: SingleTokenInfo;
108
+ lifetimeEarnings: Web3Number;
109
+ currentValue: Web3Number;
110
+ totalDeposits: Web3Number;
111
+ totalWithdrawals: Web3Number;
112
+ } {
113
+ // Get token decimals from userTVL
114
+ const tokenDecimals = userTVL.tokenInfo.decimals;
115
+
116
+ // Initialize totals
117
+ let totalDeposits = Web3Number.fromWei("0", tokenDecimals);
118
+ let totalWithdrawals = Web3Number.fromWei("0", tokenDecimals);
119
+
120
+ // Process investment flows
121
+ for (const flow of investmentFlows) {
122
+ const amount = Web3Number.fromWei(flow.amount, tokenDecimals);
123
+
124
+ if (flow.type === 'deposit') {
125
+ totalDeposits = totalDeposits.plus(amount);
126
+ } else if (flow.type === 'withdraw' || flow.type === 'redeem') {
127
+ totalWithdrawals = totalWithdrawals.plus(amount);
128
+ }
129
+ }
130
+
131
+ // Calculate lifetime earnings: current value + withdrawals - deposits
132
+ const lifetimeEarnings = userTVL.amount
133
+ .plus(totalWithdrawals)
134
+ .minus(totalDeposits);
135
+
136
+ return {
137
+ tokenInfo: {
138
+ tokenInfo: userTVL.tokenInfo,
139
+ amount: lifetimeEarnings,
140
+ usdValue: 0, // Lifetime earnings are not converted to USD
141
+ },
142
+ lifetimeEarnings,
143
+ currentValue: userTVL.amount,
144
+ totalDeposits,
145
+ totalWithdrawals,
146
+ };
79
147
  }
80
- }
148
+ }