@strkfarm/sdk 1.0.18 → 1.0.20

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,19 +1,26 @@
1
1
  import BigNumber from 'bignumber.js';
2
2
  import * as starknet from 'starknet';
3
- import { RpcProvider, BlockIdentifier, Contract, Account } from 'starknet';
3
+ import { RpcProvider, BlockIdentifier, Contract, Uint256, Call, Account } from 'starknet';
4
+ import { Quote } from '@avnu/avnu-sdk';
4
5
  import * as util from 'util';
5
6
  import TelegramBot from 'node-telegram-bot-api';
6
7
 
7
- declare class Web3Number extends BigNumber {
8
+ declare class _Web3Number<T extends _Web3Number<T>> extends BigNumber {
8
9
  decimals: number;
9
10
  constructor(value: string | number, decimals: number);
10
- static fromWei(weiNumber: string | number, decimals: number): Web3Number;
11
11
  toWei(): string;
12
- multipliedBy(value: string | number): Web3Number;
13
- dividedBy(value: string | number): Web3Number;
14
- plus(value: string | number): Web3Number;
15
- minus(n: number | string, base?: number): Web3Number;
12
+ multipliedBy(value: string | number | T): T;
13
+ dividedBy(value: string | number | T): T;
14
+ plus(value: string | number | T): T;
15
+ minus(n: number | string | T, base?: number): T;
16
+ protected construct(value: string | number, decimals: number): T;
16
17
  toString(base?: number | undefined): string;
18
+ toJSON(): string;
19
+ valueOf(): string;
20
+ }
21
+
22
+ declare class Web3Number extends _Web3Number<Web3Number> {
23
+ static fromWei(weiNumber: string | number, decimals: number): Web3Number;
17
24
  }
18
25
 
19
26
  /**
@@ -28,15 +35,18 @@ declare class ContractAddr {
28
35
  eqString(other: string): boolean;
29
36
  static standardise(address: string | bigint): string;
30
37
  static eqString(a: string, b: string): boolean;
38
+ toString(): string;
31
39
  }
32
40
 
33
41
  declare enum RiskType {
34
- MARKET_RISK = "MARKET_RISK",
35
- IMPERMANENT_LOSS = "IMPERMANENT_LOSS",
36
- LIQUIDITY_RISK = "LIQUIDITY_RISK",
37
- SMART_CONTRACT_RISK = "SMART_CONTRACT_RISK",
38
- TECHNICAL_RISK = "TECHNICAL_RISK",
39
- COUNTERPARTY_RISK = "COUNTERPARTY_RISK"
42
+ MARKET_RISK = "Market Risk",
43
+ IMPERMANENT_LOSS = "Impermanent Loss Risk",
44
+ LIQUIDATION_RISK = "Liquidation Risk",
45
+ LOW_LIQUIDITY_RISK = "Low Liquidity Risk",
46
+ SMART_CONTRACT_RISK = "Smart Contract Risk",
47
+ ORACLE_RISK = "Oracle Risk",
48
+ TECHNICAL_RISK = "Technical Risk",
49
+ COUNTERPARTY_RISK = "Counterparty Risk"
40
50
  }
41
51
  interface RiskFactor {
42
52
  type: RiskType;
@@ -46,7 +56,7 @@ interface RiskFactor {
46
56
  interface TokenInfo {
47
57
  name: string;
48
58
  symbol: string;
49
- address: string;
59
+ address: ContractAddr;
50
60
  decimals: number;
51
61
  logo: string;
52
62
  coingeckId?: string;
@@ -75,7 +85,7 @@ declare enum FlowChartColors {
75
85
  * @property risk.riskFactor.factor - The risk factors that are considered for the strategy.
76
86
  * @property risk.riskFactor.factor - The value of the risk factor from 0 to 10, 0 being the lowest and 10 being the highest.
77
87
  */
78
- interface IStrategyMetadata {
88
+ interface IStrategyMetadata<T> {
79
89
  name: string;
80
90
  description: string;
81
91
  address: ContractAddr;
@@ -88,6 +98,7 @@ interface IStrategyMetadata {
88
98
  riskFactor: RiskFactor[];
89
99
  netRisk: number;
90
100
  };
101
+ additionalInfo: T;
91
102
  }
92
103
  interface IInvestmentFlow {
93
104
  title: string;
@@ -99,6 +110,9 @@ interface IInvestmentFlow {
99
110
  style?: any;
100
111
  }
101
112
  declare function getMainnetConfig(rpcUrl?: string, blockIdentifier?: BlockIdentifier): IConfig;
113
+ declare const getRiskExplaination: (riskType: RiskType) => "The risk of the market moving against the position." | "The temporary loss of value experienced by liquidity providers in AMMs when asset prices diverge compared to simply holding them." | "The risk of losing funds due to the position being liquidated." | "The risk of low liquidity in the pool, which can lead to high slippages or reduced in-abilities to quickly exit the position." | "The risk of the oracle being manipulated or incorrect." | "The risk of the smart contract being vulnerable to attacks." | "The risk of technical issues e.g. backend failure." | "The risk of the counterparty defaulting e.g. bad debt on lending platforms.";
114
+ declare const getRiskColor: (risk: RiskFactor) => "green" | "yellow" | "red";
115
+ declare const getNoRiskTags: (risks: RiskFactor[]) => string[];
102
116
 
103
117
  interface ILendingMetadata {
104
118
  name: string;
@@ -234,6 +248,36 @@ declare class PricerFromApi extends PricerBase {
234
248
  }>;
235
249
  }
236
250
 
251
+ declare class ERC20 {
252
+ readonly config: IConfig;
253
+ constructor(config: IConfig);
254
+ contract(addr: string | ContractAddr): Contract;
255
+ balanceOf(token: string | ContractAddr, address: string | ContractAddr, tokenDecimals: number): Promise<Web3Number>;
256
+ }
257
+
258
+ interface Route {
259
+ token_from: string;
260
+ token_to: string;
261
+ exchange_address: string;
262
+ percent: number;
263
+ additional_swap_params: string[];
264
+ }
265
+ interface SwapInfo {
266
+ token_from_address: string;
267
+ token_from_amount: Uint256;
268
+ token_to_address: string;
269
+ token_to_amount: Uint256;
270
+ token_to_min_amount: Uint256;
271
+ beneficiary: string;
272
+ integrator_fee_amount_bps: number;
273
+ integrator_fee_recipient: string;
274
+ routes: Route[];
275
+ }
276
+ declare class AvnuWrapper {
277
+ getQuotes(fromToken: string, toToken: string, amountWei: string, taker: string): Promise<Quote>;
278
+ getSwapInfo(quote: Quote, taker: string, integratorFeeBps: number, integratorFeeRecipient: string, minAmount: string): Promise<SwapInfo>;
279
+ }
280
+
237
281
  declare const logger: {
238
282
  verbose(message: string): void;
239
283
  assert(condition?: boolean, ...data: any[]): void;
@@ -292,6 +336,7 @@ declare class Global {
292
336
  static getDefaultTokens(): TokenInfo[];
293
337
  static getTokens(): Promise<TokenInfo[]>;
294
338
  static assert(condition: any, message: string): void;
339
+ static getTokenInfoFromAddr(addr: ContractAddr): Promise<TokenInfo>;
295
340
  }
296
341
 
297
342
  declare class AutoCompounderSTRK {
@@ -323,12 +368,40 @@ declare class AutoCompounderSTRK {
323
368
  }>;
324
369
  }
325
370
 
371
+ interface SingleActionAmount {
372
+ tokenInfo: TokenInfo;
373
+ amount: Web3Number;
374
+ }
375
+ interface SingleTokenInfo extends SingleActionAmount {
376
+ usdValue: number;
377
+ }
378
+ interface DualActionAmount {
379
+ token0: SingleActionAmount;
380
+ token1: SingleActionAmount;
381
+ }
382
+ interface DualTokenInfo {
383
+ netUsdValue: number;
384
+ token0: SingleTokenInfo;
385
+ token1: SingleTokenInfo;
386
+ }
387
+ declare class BaseStrategy<TVLInfo, ActionInfo> {
388
+ readonly config: IConfig;
389
+ constructor(config: IConfig);
390
+ getUserTVL(user: ContractAddr): Promise<TVLInfo>;
391
+ getTVL(): Promise<TVLInfo>;
392
+ depositCall(amountInfo: ActionInfo, receiver: ContractAddr): Call[];
393
+ withdrawCall(amountInfo: ActionInfo, receiver: ContractAddr, owner: ContractAddr): Call[];
394
+ }
395
+
326
396
  interface Change {
327
397
  pool_id: ContractAddr;
328
398
  changeAmt: Web3Number;
329
399
  finalAmt: Web3Number;
330
400
  isDeposit: boolean;
331
401
  }
402
+ interface VesuRebalanceSettings {
403
+ feeBps: number;
404
+ }
332
405
  interface PoolInfoFull {
333
406
  pool_id: ContractAddr;
334
407
  pool_name: string | undefined;
@@ -350,15 +423,13 @@ interface PoolInfoFull {
350
423
  * This class implements an automated rebalancing strategy for Vesu pools,
351
424
  * managing deposits and withdrawals while optimizing yield through STRK rewards.
352
425
  */
353
- declare class VesuRebalance {
354
- /** Configuration object for the strategy */
355
- readonly config: IConfig;
426
+ declare class VesuRebalance extends BaseStrategy<SingleTokenInfo, SingleActionAmount> {
356
427
  /** Contract address of the strategy */
357
428
  readonly address: ContractAddr;
358
429
  /** Pricer instance for token price calculations */
359
430
  readonly pricer: PricerBase;
360
431
  /** Metadata containing strategy information */
361
- readonly metadata: IStrategyMetadata;
432
+ readonly metadata: IStrategyMetadata<VesuRebalanceSettings>;
362
433
  /** Contract instance for interacting with the strategy */
363
434
  readonly contract: Contract;
364
435
  readonly BASE_WEIGHT = 10000;
@@ -369,14 +440,14 @@ declare class VesuRebalance {
369
440
  * @param metadata - Strategy metadata including deposit tokens and address
370
441
  * @throws {Error} If more than one deposit token is specified
371
442
  */
372
- constructor(config: IConfig, pricer: PricerBase, metadata: IStrategyMetadata);
443
+ constructor(config: IConfig, pricer: PricerBase, metadata: IStrategyMetadata<VesuRebalanceSettings>);
373
444
  /**
374
445
  * Creates a deposit call to the strategy contract.
375
446
  * @param assets - Amount of assets to deposit
376
447
  * @param receiver - Address that will receive the strategy tokens
377
448
  * @returns Populated contract call for deposit
378
449
  */
379
- depositCall(assets: Web3Number, receiver: ContractAddr): starknet.Call[];
450
+ depositCall(amountInfo: SingleActionAmount, receiver: ContractAddr): starknet.Call[];
380
451
  /**
381
452
  * Creates a withdrawal call to the strategy contract.
382
453
  * @param assets - Amount of assets to withdraw
@@ -384,7 +455,7 @@ declare class VesuRebalance {
384
455
  * @param owner - Address that owns the strategy tokens
385
456
  * @returns Populated contract call for withdrawal
386
457
  */
387
- withdrawCall(assets: Web3Number, receiver: ContractAddr, owner: ContractAddr): starknet.Call[];
458
+ withdrawCall(amountInfo: SingleActionAmount, receiver: ContractAddr, owner: ContractAddr): starknet.Call[];
388
459
  /**
389
460
  * Returns the underlying asset token of the strategy.
390
461
  * @returns The deposit token supported by this strategy
@@ -401,6 +472,7 @@ declare class VesuRebalance {
401
472
  * @returns Object containing the amount in token units and USD value
402
473
  */
403
474
  getUserTVL(user: ContractAddr): Promise<{
475
+ tokenInfo: TokenInfo;
404
476
  amount: Web3Number;
405
477
  usdValue: number;
406
478
  }>;
@@ -409,9 +481,11 @@ declare class VesuRebalance {
409
481
  * @returns Object containing the total amount in token units and USD value
410
482
  */
411
483
  getTVL(): Promise<{
484
+ tokenInfo: TokenInfo;
412
485
  amount: Web3Number;
413
486
  usdValue: number;
414
487
  }>;
488
+ static getAllPossibleVerifiedPools(asset: ContractAddr): Promise<any>;
415
489
  /**
416
490
  * Retrieves the list of allowed pools and their detailed information from multiple sources:
417
491
  * 1. Contract's allowed pools
@@ -494,7 +568,108 @@ declare class VesuRebalance {
494
568
  /**
495
569
  * Represents the Vesu Rebalance Strategies.
496
570
  */
497
- declare const VesuRebalanceStrategies: IStrategyMetadata[];
571
+ declare const VesuRebalanceStrategies: IStrategyMetadata<VesuRebalanceSettings>[];
572
+
573
+ interface EkuboPoolKey {
574
+ token0: ContractAddr;
575
+ token1: ContractAddr;
576
+ fee: string;
577
+ tick_spacing: string;
578
+ extension: string;
579
+ }
580
+ interface EkuboBounds {
581
+ lowerTick: bigint;
582
+ upperTick: bigint;
583
+ }
584
+ /**
585
+ * Settings for the CLVaultStrategy
586
+ *
587
+ * @property newBounds - The new bounds for the strategy
588
+ * @property newBounds.lower - relative to the current tick
589
+ * @property newBounds.upper - relative to the current tick
590
+ */
591
+ interface CLVaultStrategySettings {
592
+ newBounds: {
593
+ lower: number;
594
+ upper: number;
595
+ };
596
+ lstContract: ContractAddr;
597
+ }
598
+ declare class EkuboCLVault extends BaseStrategy<DualTokenInfo, DualActionAmount> {
599
+ /** Contract address of the strategy */
600
+ readonly address: ContractAddr;
601
+ /** Pricer instance for token price calculations */
602
+ readonly pricer: PricerBase;
603
+ /** Metadata containing strategy information */
604
+ readonly metadata: IStrategyMetadata<CLVaultStrategySettings>;
605
+ /** Contract instance for interacting with the strategy */
606
+ readonly contract: Contract;
607
+ readonly BASE_WEIGHT = 10000;
608
+ readonly ekuboPositionsContract: Contract;
609
+ readonly ekuboMathContract: Contract;
610
+ readonly lstContract: Contract;
611
+ poolKey: EkuboPoolKey | undefined;
612
+ readonly avnu: AvnuWrapper;
613
+ /**
614
+ * Creates a new VesuRebalance strategy instance.
615
+ * @param config - Configuration object containing provider and other settings
616
+ * @param pricer - Pricer instance for token price calculations
617
+ * @param metadata - Strategy metadata including deposit tokens and address
618
+ * @throws {Error} If more than one deposit token is specified
619
+ */
620
+ constructor(config: IConfig, pricer: PricerBase, metadata: IStrategyMetadata<CLVaultStrategySettings>);
621
+ depositCall(amountInfo: DualActionAmount, receiver: ContractAddr): Call[];
622
+ withdrawCall(amountInfo: DualActionAmount, receiver: ContractAddr, owner: ContractAddr): Call[];
623
+ rebalanceCall(newBounds: EkuboBounds, swapParams: SwapInfo): Call[];
624
+ handleUnusedCall(swapParams: SwapInfo): Call[];
625
+ handleFeesCall(): Call[];
626
+ getUserTVL(user: ContractAddr): Promise<DualTokenInfo>;
627
+ getTVL(): Promise<DualTokenInfo>;
628
+ getUncollectedFees(): Promise<DualTokenInfo>;
629
+ getCurrentNFTID(): Promise<number>;
630
+ truePrice(): Promise<number>;
631
+ getCurrentPrice(): Promise<{
632
+ price: number;
633
+ tick: number;
634
+ }>;
635
+ private _getCurrentPrice;
636
+ getCurrentBounds(): Promise<EkuboBounds>;
637
+ static div2Power128(num: BigInt): number;
638
+ static priceToTick(price: number, isRoundDown: boolean, tickSpacing: number): {
639
+ mag: number;
640
+ sign: number;
641
+ };
642
+ getPoolKey(): Promise<EkuboPoolKey>;
643
+ getNewBounds(): Promise<EkuboBounds>;
644
+ /**
645
+ * Computes the expected amounts to fully utilize amount in
646
+ * to add liquidity to the pool
647
+ * @param amount0: amount of token0
648
+ * @param amount1: amount of token1
649
+ * @returns {amount0, amount1}
650
+ */
651
+ private _getExpectedAmountsForLiquidity;
652
+ private _solveExpectedAmountsEq;
653
+ getSwapInfoToHandleUnused(considerRebalance?: boolean): Promise<SwapInfo>;
654
+ static tickToi129(tick: number): {
655
+ mag: number;
656
+ sign: number;
657
+ };
658
+ static priceToSqrtRatio(price: number): bigint;
659
+ static i129ToNumber(i129: {
660
+ mag: bigint;
661
+ sign: number;
662
+ }): bigint;
663
+ static tickToPrice(tick: bigint): number;
664
+ getLiquidityToAmounts(liquidity: Web3Number, bounds: EkuboBounds): Promise<{
665
+ amount0: Web3Number;
666
+ amount1: Web3Number;
667
+ }>;
668
+ }
669
+ /**
670
+ * Represents the Vesu Rebalance Strategies.
671
+ */
672
+ declare const EkuboCLVaultStrategies: IStrategyMetadata<CLVaultStrategySettings>[];
498
673
 
499
674
  declare class TelegramNotif {
500
675
  private subscribers;
@@ -525,6 +700,8 @@ declare class PricerRedis extends Pricer {
525
700
  getPrice(tokenSymbol: string): Promise<PriceInfo>;
526
701
  }
527
702
 
703
+ declare function getAPIUsingHeadlessBrowser(url: string): Promise<any>;
704
+
528
705
  /**
529
706
  * @description Config to manage storage of files on disk
530
707
  * @param SECRET_FILE_FOLDER - Folder to store secret files (default: ~/.starknet-store)
@@ -603,4 +780,4 @@ declare class PasswordJsonCryptoUtil {
603
780
  decrypt(encryptedData: string, password: string): any;
604
781
  }
605
782
 
606
- export { type AccountInfo, type AllAccountsStore, AutoCompounderSTRK, ContractAddr, FatalError, FlowChartColors, Global, type IConfig, type IInvestmentFlow, ILending, type ILendingMetadata, type ILendingPosition, type IProtocol, type IStrategyMetadata, Initializable, type LendingToken, MarginType, Network, PasswordJsonCryptoUtil, Pragma, type PriceInfo, Pricer, PricerFromApi, PricerRedis, type RequiredFields, type RequiredKeys, type RequiredStoreConfig, type RiskFactor, RiskType, Store, type StoreConfig, TelegramNotif, type TokenInfo, VesuRebalance, VesuRebalanceStrategies, Web3Number, ZkLend, assert, getDefaultStoreConfig, getMainnetConfig, logger };
783
+ export { type AccountInfo, type AllAccountsStore, AutoCompounderSTRK, AvnuWrapper, type CLVaultStrategySettings, ContractAddr, ERC20, type EkuboBounds, EkuboCLVault, EkuboCLVaultStrategies, type EkuboPoolKey, FatalError, FlowChartColors, Global, type IConfig, type IInvestmentFlow, ILending, type ILendingMetadata, type ILendingPosition, type IProtocol, type IStrategyMetadata, Initializable, type LendingToken, MarginType, Network, PasswordJsonCryptoUtil, Pragma, type PriceInfo, Pricer, PricerFromApi, PricerRedis, type RequiredFields, type RequiredKeys, type RequiredStoreConfig, type RiskFactor, RiskType, type Route, Store, type StoreConfig, type SwapInfo, TelegramNotif, type TokenInfo, VesuRebalance, VesuRebalanceStrategies, Web3Number, ZkLend, assert, getAPIUsingHeadlessBrowser, getDefaultStoreConfig, getMainnetConfig, getNoRiskTags, getRiskColor, getRiskExplaination, logger };