@strkfarm/sdk 1.0.14 → 1.0.16

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.
package/dist/index.d.ts CHANGED
@@ -1,28 +1,9 @@
1
+ import * as starknet from 'starknet';
1
2
  import { RpcProvider, BlockIdentifier, Contract, Account } from 'starknet';
2
3
  import BigNumber from 'bignumber.js';
3
4
  import * as util from 'util';
4
5
  import TelegramBot from 'node-telegram-bot-api';
5
6
 
6
- interface TokenInfo {
7
- name: string;
8
- symbol: string;
9
- address: string;
10
- decimals: number;
11
- coingeckId?: string;
12
- }
13
- declare enum Network {
14
- mainnet = "mainnet",
15
- sepolia = "sepolia",
16
- devnet = "devnet"
17
- }
18
- interface IConfig {
19
- provider: RpcProvider;
20
- network: Network;
21
- stage: 'production' | 'staging';
22
- heartbeatUrl?: string;
23
- }
24
- declare function getMainnetConfig(rpcUrl?: string, blockIdentifier?: BlockIdentifier): IConfig;
25
-
26
7
  declare class Web3Number extends BigNumber {
27
8
  decimals: number;
28
9
  constructor(value: string | number, decimals: number);
@@ -49,11 +30,46 @@ declare class ContractAddr {
49
30
  static eqString(a: string, b: string): boolean;
50
31
  }
51
32
 
33
+ interface TokenInfo {
34
+ name: string;
35
+ symbol: string;
36
+ address: string;
37
+ decimals: number;
38
+ coingeckId?: string;
39
+ }
40
+ declare enum Network {
41
+ mainnet = "mainnet",
42
+ sepolia = "sepolia",
43
+ devnet = "devnet"
44
+ }
45
+ interface IConfig {
46
+ provider: RpcProvider;
47
+ network: Network;
48
+ stage: 'production' | 'staging';
49
+ heartbeatUrl?: string;
50
+ }
51
+ interface IProtocol {
52
+ name: string;
53
+ logo: string;
54
+ }
55
+ interface IStrategyMetadata {
56
+ name: string;
57
+ description: string;
58
+ address: ContractAddr;
59
+ type: 'ERC4626' | 'ERC721' | 'Other';
60
+ depositTokens: TokenInfo[];
61
+ protocols: IProtocol[];
62
+ }
63
+ declare function getMainnetConfig(rpcUrl?: string, blockIdentifier?: BlockIdentifier): IConfig;
64
+
52
65
  interface PriceInfo {
53
66
  price: number;
54
67
  timestamp: Date;
55
68
  }
56
- declare class Pricer {
69
+ declare abstract class PricerBase {
70
+ getPrice(tokenSymbol: string): Promise<PriceInfo>;
71
+ }
72
+ declare class Pricer implements PricerBase {
57
73
  readonly config: IConfig;
58
74
  readonly tokens: TokenInfo[];
59
75
  protected prices: {
@@ -72,7 +88,7 @@ declare class Pricer {
72
88
  start(): void;
73
89
  isStale(timestamp: Date, tokenName: string): boolean;
74
90
  assertNotStale(timestamp: Date, tokenName: string): void;
75
- getPrice(tokenName: string): Promise<PriceInfo>;
91
+ getPrice(tokenSymbol: string): Promise<PriceInfo>;
76
92
  protected _loadPrices(onUpdate?: (tokenSymbol: string) => void): void;
77
93
  _getPrice(token: TokenInfo, defaultMethod?: string): Promise<number>;
78
94
  _getPriceCoinbase(token: TokenInfo): Promise<number>;
@@ -225,6 +241,7 @@ declare class FatalError extends Error {
225
241
  declare class Global {
226
242
  static fatalError(message: string, err?: Error): void;
227
243
  static httpError(url: string, err: Error, message?: string): void;
244
+ static getDefaultTokens(): TokenInfo[];
228
245
  static getTokens(): Promise<TokenInfo[]>;
229
246
  static assert(condition: any, message: string): void;
230
247
  }
@@ -258,6 +275,178 @@ declare class AutoCompounderSTRK {
258
275
  }>;
259
276
  }
260
277
 
278
+ interface Change {
279
+ pool_id: ContractAddr;
280
+ changeAmt: Web3Number;
281
+ finalAmt: Web3Number;
282
+ isDeposit: boolean;
283
+ }
284
+ interface PoolInfoFull {
285
+ pool_id: ContractAddr;
286
+ pool_name: string | undefined;
287
+ max_weight: number;
288
+ current_weight: number;
289
+ v_token: ContractAddr;
290
+ amount: Web3Number;
291
+ usdValue: Web3Number;
292
+ APY: {
293
+ baseApy: number;
294
+ defiSpringApy: number;
295
+ netApy: number;
296
+ };
297
+ currentUtilization: number;
298
+ maxUtilization: number;
299
+ }
300
+ /**
301
+ * Represents a VesuRebalance strategy.
302
+ * This class implements an automated rebalancing strategy for Vesu pools,
303
+ * managing deposits and withdrawals while optimizing yield through STRK rewards.
304
+ */
305
+ declare class VesuRebalance {
306
+ /** Configuration object for the strategy */
307
+ readonly config: IConfig;
308
+ /** Contract address of the strategy */
309
+ readonly address: ContractAddr;
310
+ /** Pricer instance for token price calculations */
311
+ readonly pricer: PricerBase;
312
+ /** Metadata containing strategy information */
313
+ readonly metadata: IStrategyMetadata;
314
+ /** Contract instance for interacting with the strategy */
315
+ readonly contract: Contract;
316
+ readonly BASE_WEIGHT = 10000;
317
+ /**
318
+ * Creates a new VesuRebalance strategy instance.
319
+ * @param config - Configuration object containing provider and other settings
320
+ * @param pricer - Pricer instance for token price calculations
321
+ * @param metadata - Strategy metadata including deposit tokens and address
322
+ * @throws {Error} If more than one deposit token is specified
323
+ */
324
+ constructor(config: IConfig, pricer: PricerBase, metadata: IStrategyMetadata);
325
+ /**
326
+ * Creates a deposit call to the strategy contract.
327
+ * @param assets - Amount of assets to deposit
328
+ * @param receiver - Address that will receive the strategy tokens
329
+ * @returns Populated contract call for deposit
330
+ */
331
+ depositCall(assets: Web3Number, receiver: ContractAddr): starknet.Call[];
332
+ /**
333
+ * Creates a withdrawal call to the strategy contract.
334
+ * @param assets - Amount of assets to withdraw
335
+ * @param receiver - Address that will receive the withdrawn assets
336
+ * @param owner - Address that owns the strategy tokens
337
+ * @returns Populated contract call for withdrawal
338
+ */
339
+ withdrawCall(assets: Web3Number, receiver: ContractAddr, owner: ContractAddr): starknet.Call[];
340
+ /**
341
+ * Returns the underlying asset token of the strategy.
342
+ * @returns The deposit token supported by this strategy
343
+ */
344
+ asset(): TokenInfo;
345
+ /**
346
+ * Returns the number of decimals used by the strategy token.
347
+ * @returns Number of decimals (same as the underlying token)
348
+ */
349
+ decimals(): number;
350
+ /**
351
+ * Calculates the Total Value Locked (TVL) for a specific user.
352
+ * @param user - Address of the user
353
+ * @returns Object containing the amount in token units and USD value
354
+ */
355
+ getUserTVL(user: ContractAddr): Promise<{
356
+ amount: Web3Number;
357
+ usdValue: number;
358
+ }>;
359
+ /**
360
+ * Calculates the total TVL of the strategy.
361
+ * @returns Object containing the total amount in token units and USD value
362
+ */
363
+ getTVL(): Promise<{
364
+ amount: Web3Number;
365
+ usdValue: number;
366
+ }>;
367
+ /**
368
+ * Retrieves the list of allowed pools and their detailed information from multiple sources:
369
+ * 1. Contract's allowed pools
370
+ * 2. Vesu positions API for current positions
371
+ * 3. Vesu pools API for APY and utilization data
372
+ *
373
+ * @returns {Promise<{
374
+ * data: Array<PoolInfoFull>,
375
+ * isErrorPositionsAPI: boolean
376
+ * }>} Object containing:
377
+ * - data: Array of pool information including IDs, weights, amounts, APYs and utilization
378
+ * - isErrorPositionsAPI: Boolean indicating if there was an error fetching position data
379
+ */
380
+ getPools(): Promise<{
381
+ data: {
382
+ pool_id: ContractAddr;
383
+ pool_name: any;
384
+ max_weight: number;
385
+ current_weight: number;
386
+ v_token: ContractAddr;
387
+ amount: Web3Number;
388
+ usdValue: Web3Number;
389
+ APY: {
390
+ baseApy: number;
391
+ defiSpringApy: number;
392
+ netApy: number;
393
+ };
394
+ currentUtilization: number;
395
+ maxUtilization: number;
396
+ }[];
397
+ isErrorPositionsAPI: boolean;
398
+ isErrorPoolsAPI: boolean;
399
+ isError: boolean;
400
+ }>;
401
+ /**
402
+ * Calculates the weighted average APY across all pools based on USD value.
403
+ * @returns {Promise<number>} The weighted average APY across all pools
404
+ */
405
+ netAPY(): Promise<number>;
406
+ /**
407
+ * Calculates the weighted average APY across all pools based on USD value.
408
+ * @returns {Promise<number>} The weighted average APY across all pools
409
+ */
410
+ netAPYGivenPools(pools: PoolInfoFull[]): number;
411
+ /**
412
+ * Calculates optimal position changes to maximize APY while respecting max weights.
413
+ * The algorithm:
414
+ * 1. Sorts pools by APY (highest first)
415
+ * 2. Calculates target amounts based on max weights
416
+ * 3. For each pool that needs more funds:
417
+ * - Takes funds from lowest APY pools that are over their target
418
+ * 4. Validates that total assets remain constant
419
+ *
420
+ * @returns {Promise<{
421
+ * changes: Change[],
422
+ * finalPools: PoolInfoFull[],
423
+ * isAnyPoolOverMaxWeight: boolean
424
+ * }>} Object containing:
425
+ * - changes: Array of position changes
426
+ * - finalPools: Array of pool information after rebalance
427
+ * @throws Error if rebalance is not possible while maintaining constraints
428
+ */
429
+ getRebalancedPositions(): Promise<{
430
+ changes: never[];
431
+ finalPools: never[];
432
+ isAnyPoolOverMaxWeight?: undefined;
433
+ } | {
434
+ changes: Change[];
435
+ finalPools: PoolInfoFull[];
436
+ isAnyPoolOverMaxWeight: boolean;
437
+ }>;
438
+ /**
439
+ * Creates a rebalance Call object for the strategy contract
440
+ * @param pools - Array of pool information including IDs, weights, amounts, APYs and utilization
441
+ * @returns Populated contract call for rebalance
442
+ */
443
+ getRebalanceCall(pools: Awaited<ReturnType<typeof this.getRebalancedPositions>>['changes'], isOverWeightAdjustment: boolean): Promise<starknet.Call | null>;
444
+ }
445
+ /**
446
+ * Represents the Vesu Rebalance Strategies.
447
+ */
448
+ declare const VesuRebalanceStrategies: IStrategyMetadata[];
449
+
261
450
  declare class TelegramNotif {
262
451
  private subscribers;
263
452
  readonly bot: TelegramBot;
@@ -266,6 +455,27 @@ declare class TelegramNotif {
266
455
  sendMessage(msg: string): void;
267
456
  }
268
457
 
458
+ type RequiredFields<T> = {
459
+ [K in keyof T]-?: T[K];
460
+ };
461
+ type RequiredKeys<T> = {
462
+ [K in keyof T]-?: {} extends Pick<T, K> ? never : K;
463
+ }[keyof T];
464
+ declare function assert(condition: boolean, message: string): void;
465
+
466
+ declare class PricerRedis extends Pricer {
467
+ private redisClient;
468
+ constructor(config: IConfig, tokens: TokenInfo[]);
469
+ /** Reads prices from Pricer._loadPrices and uses a callback to set prices in redis */
470
+ startWithRedis(redisUrl: string): Promise<void>;
471
+ close(): Promise<void>;
472
+ initRedis(redisUrl: string): Promise<void>;
473
+ /** sets current local price in redis */
474
+ private _setRedisPrices;
475
+ /** Returns price from redis */
476
+ getPrice(tokenSymbol: string): Promise<PriceInfo>;
477
+ }
478
+
269
479
  /**
270
480
  * @description Config to manage storage of files on disk
271
481
  * @param SECRET_FILE_FOLDER - Folder to store secret files (default: ~/.starknet-store)
@@ -315,7 +525,7 @@ declare class Store {
315
525
  private encryptor;
316
526
  constructor(config: IConfig, storeConfig: StoreConfig);
317
527
  static logPassword(password: string): void;
318
- getAccount(accountKey: string, txVersion?: "0x2"): Account;
528
+ getAccount(accountKey: string, txVersion?: "0x2" | "0x3"): Account;
319
529
  addAccount(accountKey: string, address: string, pk: string): void;
320
530
  private getAccountFilePath;
321
531
  private getAllAccounts;
@@ -344,24 +554,4 @@ declare class PasswordJsonCryptoUtil {
344
554
  decrypt(encryptedData: string, password: string): any;
345
555
  }
346
556
 
347
- type RequiredFields<T> = {
348
- [K in keyof T]-?: T[K];
349
- };
350
- type RequiredKeys<T> = {
351
- [K in keyof T]-?: {} extends Pick<T, K> ? never : K;
352
- }[keyof T];
353
-
354
- declare class PricerRedis extends Pricer {
355
- private redisClient;
356
- constructor(config: IConfig, tokens: TokenInfo[]);
357
- /** Reads prices from Pricer._loadPrices and uses a callback to set prices in redis */
358
- startWithRedis(redisUrl: string): Promise<void>;
359
- close(): Promise<void>;
360
- initRedis(redisUrl: string): Promise<void>;
361
- /** sets current local price in redis */
362
- private _setRedisPrices;
363
- /** Returns price from redis */
364
- getPrice(tokenSymbol: string): Promise<PriceInfo>;
365
- }
366
-
367
- export { type AccountInfo, type AllAccountsStore, AutoCompounderSTRK, ContractAddr, FatalError, Global, type IConfig, ILending, type ILendingMetadata, type ILendingPosition, Initializable, type LendingToken, MarginType, Network, PasswordJsonCryptoUtil, Pragma, type PriceInfo, Pricer, PricerRedis, type RequiredFields, type RequiredKeys, type RequiredStoreConfig, Store, type StoreConfig, TelegramNotif, type TokenInfo, Web3Number, ZkLend, getDefaultStoreConfig, getMainnetConfig, logger };
557
+ export { type AccountInfo, type AllAccountsStore, AutoCompounderSTRK, ContractAddr, FatalError, Global, type IConfig, ILending, type ILendingMetadata, type ILendingPosition, type IProtocol, type IStrategyMetadata, Initializable, type LendingToken, MarginType, Network, PasswordJsonCryptoUtil, Pragma, type PriceInfo, Pricer, PricerBase, PricerRedis, type RequiredFields, type RequiredKeys, type RequiredStoreConfig, Store, type StoreConfig, TelegramNotif, type TokenInfo, VesuRebalance, VesuRebalanceStrategies, Web3Number, ZkLend, assert, getDefaultStoreConfig, getMainnetConfig, logger };