@strkfarm/sdk 2.0.0-dev.13 → 2.0.0-dev.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strkfarm/sdk",
3
- "version": "2.0.0-dev.13",
3
+ "version": "2.0.0-dev.15",
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",
@@ -8,4 +8,5 @@ export * from './universal-strategy';
8
8
  export * from './universal-lst-muliplier-strategy';
9
9
  export * from './vesu-extended-strategy/vesu-extended-strategy';
10
10
  export * from './vesu-extended-strategy/utils/config.runtime';
11
- export * from './vesu-extended-strategy/utils/helper';
11
+ export * from './vesu-extended-strategy/utils/helper';
12
+ export * from './vesu-extended-strategy/types/transaction-metadata';
@@ -415,30 +415,45 @@ export class ExtendedAdapter extends BaseAdapter<
415
415
  }
416
416
  }
417
417
 
418
- async withdrawFromExtended(amount: Web3Number): Promise<boolean> {
418
+ async withdrawFromExtended(amount: Web3Number): Promise<{
419
+ status: boolean;
420
+ receivedTxnHash: boolean;
421
+ }> {
419
422
  try {
420
423
  if (!this.client) {
421
424
  logger.error("Client not initialized");
422
- return false;
425
+ return {
426
+ status: false,
427
+ receivedTxnHash: false,
428
+ }
423
429
  }
424
430
  if (amount.lessThanOrEqualTo(0)) {
425
431
  logger.error(
426
432
  `Invalid withdrawal amount: ${amount.toNumber()}. Amount must be positive.`
427
433
  );
428
- return false;
434
+ return {
435
+ status: false,
436
+ receivedTxnHash: false,
437
+ }
429
438
  }
430
439
  if (amount.lessThanOrEqualTo(this.minimumExtendedMovementAmount)) {
431
440
  logger.warn(
432
441
  `Withdrawal amount ${amount.toNumber()} is below minimum Extended movement amount ${this.minimumExtendedMovementAmount}. Skipping withdrawal.`
433
442
  );
434
- return false;
443
+ return {
444
+ status: false,
445
+ receivedTxnHash: false,
446
+ }
435
447
  }
436
448
  const holdings = await this.getExtendedDepositAmount();
437
449
  if (!holdings) {
438
450
  logger.error(
439
451
  "Cannot get holdings - unable to validate withdrawal amount"
440
452
  );
441
- return false;
453
+ return {
454
+ status: false,
455
+ receivedTxnHash: false,
456
+ }
442
457
  }
443
458
 
444
459
  const availableForWithdrawal = parseFloat(
@@ -451,7 +466,10 @@ export class ExtendedAdapter extends BaseAdapter<
451
466
  logger.error(
452
467
  `Invalid availableForWithdrawal: ${holdings.availableForWithdrawal}. Expected a finite, non-negative number.`
453
468
  );
454
- return false;
469
+ return {
470
+ status: false,
471
+ receivedTxnHash: false,
472
+ }
455
473
  }
456
474
 
457
475
  const withdrawalAmount = amount.toNumber();
@@ -459,7 +477,10 @@ export class ExtendedAdapter extends BaseAdapter<
459
477
  logger.error(
460
478
  `Withdrawal amount ${withdrawalAmount} exceeds available balance ${availableForWithdrawal}`
461
479
  );
462
- return false;
480
+ return {
481
+ status: false,
482
+ receivedTxnHash: false,
483
+ }
463
484
  }
464
485
 
465
486
  logger.info(
@@ -475,16 +496,24 @@ export class ExtendedAdapter extends BaseAdapter<
475
496
  withdrawalRequest.data,
476
497
  AssetOperationType.WITHDRAWAL
477
498
  );
478
- return withdrawalStatus;
499
+ return {
500
+ status: true,
501
+ receivedTxnHash: withdrawalStatus,
502
+ }
479
503
  }
480
-
481
504
  logger.error(
482
505
  `Withdrawal request failed with status: ${withdrawalRequest.status}`
483
506
  );
484
- return false;
507
+ return {
508
+ status: false,
509
+ receivedTxnHash: false,
510
+ }
485
511
  } catch (error) {
486
512
  logger.error(`Error creating Withdraw Call: ${error}`);
487
- return false;
513
+ return {
514
+ status: false,
515
+ receivedTxnHash: false,
516
+ }
488
517
  }
489
518
  }
490
519
 
@@ -5,4 +5,5 @@ export * from "./vesu-supply-only-adapter";
5
5
  export * from "./vesu-multiply-adapter";
6
6
  export * from "./extended-adapter";
7
7
  export * from "./adapter-utils";
8
- export * from "./unused-balance-adapter";
8
+ export * from "./unused-balance-adapter";
9
+ export * from "./avnu-adapter";
@@ -1,13 +1,17 @@
1
1
  import { Web3Number } from "@/dataTypes";
2
- import { TokenInfo } from "@/interfaces";
3
2
  import { ExtendedAdapter } from "@/strategies/universal-adapters/extended-adapter";
4
3
  import { VesuMultiplyAdapter } from "../../universal-adapters/vesu-multiply-adapter";
5
4
  import { Call } from "starknet";
5
+ import { TransactionResult } from "../types/transaction-metadata";
6
+
6
7
  export abstract class Operations {
8
+
7
9
  abstract shouldMoveAssets(
8
10
  extendedAmount: Web3Number,
9
11
  vesuAmount: Web3Number
10
- ): Promise<Call[]>;
12
+ ): Promise<TransactionResult[]>;
13
+
14
+
11
15
  abstract shouldInvest(): Promise<{
12
16
  shouldInvest: boolean;
13
17
  vesuAmount: Web3Number;
@@ -15,20 +19,26 @@ export abstract class Operations {
15
19
  extendedLeverage: number;
16
20
  vesuLeverage: number;
17
21
  }>;
22
+
23
+ /**
24
+ * Move assets between protocols.
25
+ * Returns transaction calls and metadata for DB tracking.
26
+ */
18
27
  abstract moveAssets(
19
28
  params: { from: string; to: string; amount: Web3Number },
20
29
  extendedAdapter: ExtendedAdapter,
21
30
  vesuAdapter: VesuMultiplyAdapter
22
- ): Promise<{
23
- calls: Call[];
24
- status: boolean;
25
- }>;
26
- abstract handleDeposit(): Promise<{
31
+ ): Promise<TransactionResult>;
32
+ /**
33
+ * Handle deposit operation.
34
+ * Returns transaction calls and metadata for DB tracking.
35
+ */
36
+ abstract handleDeposit(): Promise<TransactionResult<{
27
37
  extendedAmountInBTC: Web3Number;
28
- calls: Call[];
29
- }>;
30
- abstract handleWithdraw(amount: Web3Number): Promise<{
31
- calls: Call[];
32
- status: boolean;
33
- }> ;
38
+ }>>;
39
+ /**
40
+ * Handle withdrawal operation.
41
+ * Returns transaction calls and metadata for DB tracking.
42
+ */
43
+ abstract handleWithdraw(amount: Web3Number): Promise<TransactionResult[]>;
34
44
  }
@@ -0,0 +1,25 @@
1
+ import { Call } from "starknet";
2
+
3
+ /**
4
+ * Transaction metadata that SDK generates and risk engine stores in DB.
5
+ * This metadata is used to track transaction lifecycle without coupling SDK to DB.
6
+ */
7
+ export interface TransactionMetadata {
8
+ protocolFrom: string;
9
+ protocolTo: string;
10
+ transactionType: 'DEPOSIT' | 'WITHDRAWAL' | 'NONE';
11
+ usdAmount: string;
12
+ status: 'COMPLETED' | 'FAILED' | 'PENDING';
13
+ }
14
+
15
+ /**
16
+ * Enhanced return type for operations that generate transactions.
17
+ * Includes both the calls (for execution) and metadata (for DB storage).
18
+ */
19
+ export interface TransactionResult<T = any> {
20
+ calls: Call[];
21
+ status: boolean;
22
+ transactionMetadata: TransactionMetadata;
23
+ }
24
+
25
+
@@ -317,6 +317,46 @@ export const calculateAmountDepositOnExtendedWhenIncurringLosses = async (
317
317
  }
318
318
  };
319
319
 
320
+ /**
321
+ * calculate the amount of collateral to deposit to maintain the ltv
322
+ * The formula is:
323
+ * ((debt * debtPrice * targetHF) - (collateral * collateralPrice * ltv)) / ltv
324
+ * @param collateralAmount in collateral units
325
+ * @param debtAmount in debt units
326
+ * @param debtPrice in usd
327
+ * @param maxLtv
328
+ * @param collateralPrice in usd
329
+ * @param targetHF
330
+ * @returns deltaCollateralAmountUnits in collateral units
331
+ * null if there is an error
332
+ */
333
+ export const calculateWBTCAmountToMaintainLTV = (
334
+ collateralAmount: Web3Number,
335
+ debtAmount: Web3Number,
336
+ debtPrice: number,
337
+ maxLtv: number = MAX_LIQUIDATION_RATIO,
338
+ collateralPrice: number,
339
+ targetHF: number = TARGET_HF,
340
+ ) =>{
341
+ try {
342
+ const numerator1 = (collateralAmount)
343
+ .multipliedBy(collateralPrice)
344
+ .multipliedBy(maxLtv)
345
+ const numerator2 = debtAmount
346
+ .multipliedBy(debtPrice)
347
+ .multipliedBy(targetHF);
348
+ const denominator = maxLtv;
349
+ const collateralAmountToMaintainLTV = numerator2.minus(numerator1).dividedBy(denominator);
350
+ let deltaCollateralAmountUnits = new Web3Number(
351
+ collateralAmountToMaintainLTV.dividedBy(collateralPrice).toFixed(WBTC_TOKEN_DECIMALS),
352
+ WBTC_TOKEN_DECIMALS
353
+ );
354
+ return {deltaCollateralAmountUnits};
355
+ } catch (err) {
356
+ return { deltaCollateralAmountUnits: null };
357
+ }
358
+ }
359
+
320
360
  export const calculateExposureDelta = (
321
361
  exposure_extended: number,
322
362
  exposure_vesu: number