@lavarage/sdk 7.5.5 → 7.5.7

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/docs-readme.md ADDED
@@ -0,0 +1,5 @@
1
+ # Lavarage SDK
2
+
3
+ TypeScript SDK for interacting with the Lavarage DeFi protocol.
4
+
5
+ Select a module from the sidebar to get started.
package/evm.ts CHANGED
@@ -17,10 +17,30 @@ import {
17
17
 
18
18
  /**
19
19
  * Creates an unsigned transaction to open a trading position on EVM chain
20
+ * @group EVM
21
+ * @category Trading
20
22
  * @param provider - Ethers provider
21
23
  * @param borrowerOpsContractAddress - BorrowerOperations contract address
22
24
  * @param params - Trading parameters
23
25
  * @returns Unsigned transaction object
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const tx = await openPositionEvm(
30
+ * provider,
31
+ * "0x123...", // contract address
32
+ * {
33
+ * buyingCode: "0x...", // 1inch swap data
34
+ * tokenCollateral: "0x456...", // USDC address
35
+ * borrowAmount: ethers.parseEther("2"),
36
+ * tokenHolder: "0x789...",
37
+ * inchRouter: "0xabc...",
38
+ * buyerContribution: ethers.parseEther("1") // 1 ETH margin
39
+ * }
40
+ * );
41
+ *
42
+ * const receipt = await signer.sendTransaction(tx);
43
+ * ```
24
44
  */
25
45
  export const openPositionEvm = async (
26
46
  provider: Provider,
@@ -80,10 +100,29 @@ export const openPositionEvm = async (
80
100
 
81
101
  /**
82
102
  * Creates an unsigned transaction to close a trading position on EVM chain
103
+ * @group EVM
104
+ * @category Trading
83
105
  * @param provider - Ethers provider
84
106
  * @param borrowerOpsContractAddress - BorrowerOperations contract address
85
107
  * @param params - Trading parameters
86
108
  * @returns Unsigned transaction object
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * const tx = await closePositionEvm(
113
+ * provider,
114
+ * "0x123...", // contract address
115
+ * {
116
+ * loanId: 1,
117
+ * sellingCode: "0x...", // 1inch swap data for selling
118
+ * tokenHolder: "0x789...",
119
+ * inchRouter: "0xabc...",
120
+ * integratorFeeAddress: "0xdef..." // optional
121
+ * }
122
+ * );
123
+ *
124
+ * const receipt = await signer.sendTransaction(tx);
125
+ * ```
87
126
  */
88
127
  export const closePositionEvm = async (
89
128
  provider: Provider,
@@ -132,9 +171,25 @@ export const closePositionEvm = async (
132
171
 
133
172
  /**
134
173
  * Get all positions from active loans
174
+ * @group EVM
175
+ * @category Queries
135
176
  * @param provider - Ethers provider
136
177
  * @param tokenHolderContractAddress - TokenHolder contract address
137
178
  * @returns Array of active positions
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * const positions = await getPositionsEvm(
183
+ * provider,
184
+ * "0x123..." // TokenHolder address
185
+ * );
186
+ *
187
+ * console.log(`Found ${positions.length} active positions`);
188
+ *
189
+ * positions.forEach(pos => {
190
+ * console.log(`Loan #${pos.loanId}: ${pos.collateralAmount} collateral`);
191
+ * });
192
+ * ```
138
193
  */
139
194
  export async function getPositionsEvm(
140
195
  provider: Provider,
@@ -176,10 +231,27 @@ export async function getPositionsEvm(
176
231
 
177
232
  /**
178
233
  * Get closed positions from events
234
+ * @group EVM
235
+ * @category Queries
179
236
  * @param provider - Ethers provider
180
237
  * @param borrowerOpsContractAddress - BorrowerOperations contract address
181
238
  * @param fromBlock - Block to start searching from
182
239
  * @returns Array of Sell events representing closed positions
240
+ *
241
+ * @example
242
+ * ```typescript
243
+ * const closedPositions = await getClosedPositionsEvm(
244
+ * provider,
245
+ * "0x123...", // BorrowerOps address
246
+ * 50000000 // optional: custom start block
247
+ * );
248
+ *
249
+ * console.log(`Found ${closedPositions.length} closed positions`);
250
+ *
251
+ * // Check profit/loss
252
+ * closedPositions.forEach(pos => {
253
+ * console.log(`Loan #${pos.loanId}: ${pos.profit > 0 ? 'Profit' : 'Loss'}`);
254
+ * });
183
255
  */
184
256
  export async function getClosedPositionsEvm(
185
257
  provider: Provider,
@@ -226,10 +298,28 @@ export async function getClosedPositionsEvm(
226
298
 
227
299
  /**
228
300
  * Get liquidated positions from events
301
+ * @group EVM
302
+ * @category Queries
229
303
  * @param provider - Ethers provider
230
304
  * @param borrowerOpsContractAddress - BorrowerOperations contract address
231
305
  * @param fromBlock - Block to start searching from
232
306
  * @returns Array of Liquidation events representing liquidated positions
307
+ * @example
308
+ * ```typescript
309
+ * const liquidations = await getLiquidatedPositionsEvm(
310
+ * provider,
311
+ * "0x123...", // BorrowerOps address
312
+ * 50000000 // optional: custom start block
313
+ * );
314
+ *
315
+ * console.log(`Found ${liquidations.length} liquidated positions`);
316
+ *
317
+ * // Analyze liquidation data
318
+ * liquidations.forEach(liq => {
319
+ * console.log(`Loan #${liq.loanId}: liquidated ${liq.closingPositionSize}`);
320
+ * console.log(`Liquidator repaid: ${liq.liquidatorRepaidAmount}`);
321
+ * });
322
+ * ```
233
323
  */
234
324
  export async function getLiquidatedPositionsEvm(
235
325
  provider: Provider,
@@ -281,10 +371,26 @@ export async function getLiquidatedPositionsEvm(
281
371
 
282
372
  /**
283
373
  * Get a loan by its ID from TokenHolder contract
374
+ * @group EVM
375
+ * @category Queries
284
376
  * @param provider - Ethers provider
285
377
  * @param tokenHolderContractAddress - Address of the TokenHolder contract
286
378
  * @param loanId - ID of the loan to retrieve
287
379
  * @returns Loan object
380
+ *
381
+ * @example
382
+ * ```typescript
383
+ * const loan = await getLoanEvm(
384
+ * provider,
385
+ * "0x123...", // TokenHolder address
386
+ * 42 // loan ID
387
+ * );
388
+ *
389
+ * console.log(`Loan #${loan.id}`);
390
+ * console.log(`Borrower: ${loan.borrower}`);
391
+ * console.log(`Amount: ${loan.amount}`);
392
+ * console.log(`Collateral: ${loan.collateralAmount}`);
393
+ * ```
288
394
  */
289
395
  export async function getLoanEvm(
290
396
  provider: Provider,
@@ -301,10 +407,27 @@ export async function getLoanEvm(
301
407
 
302
408
  /**
303
409
  * Get all active loans for a user
410
+ * @group EVM
411
+ * @category Queries
304
412
  * @param provider - Ethers provider
305
413
  * @param tokenHolderContractAddress - Address of the TokenHolder contract
306
414
  * @param userAddress - Address of the user to get loans for
307
415
  * @returns Array of loans belonging to the user
416
+ *
417
+ * @example
418
+ * ```typescript
419
+ * const userLoans = await getUserLoansEvm(
420
+ * provider,
421
+ * "0x123...", // TokenHolder address
422
+ * "0x456..." // user address
423
+ * );
424
+ *
425
+ * console.log(`User has ${userLoans.length} active loans`);
426
+ *
427
+ * userLoans.forEach(loan => {
428
+ * console.log(`Loan #${loan.id}: ${loan.amount} borrowed`);
429
+ * });
430
+ * ```
308
431
  */
309
432
  export async function getUserLoansEvm(
310
433
  provider: Provider,
@@ -332,10 +455,25 @@ export async function getUserLoansEvm(
332
455
 
333
456
  /**
334
457
  * Get collateral information for a specific token
458
+ * @group EVM
459
+ * @category Queries
335
460
  * @param provider - Ethers provider
336
461
  * @param tokenHolderContractAddress - Address of the TokenHolder contract
337
462
  * @param collateralAddress - Address of the collateral token
338
463
  * @returns Collateral object
464
+ *
465
+ * @example
466
+ * ```typescript
467
+ * const collateralInfo = await getCollateralInfoEvm(
468
+ * provider,
469
+ * "0x123...", // TokenHolder address
470
+ * "0x456..." // USDC or other collateral token address
471
+ * );
472
+ *
473
+ * console.log(`Collateral: ${collateralInfo.symbol}`);
474
+ * console.log(`Max LTV: ${collateralInfo.maxLTV}`);
475
+ * console.log(`Liquidation threshold: ${collateralInfo.liquidationThreshold}`);
476
+ * ```
339
477
  */
340
478
  export async function getCollateralInfoEvm(
341
479
  provider: Provider,
@@ -352,10 +490,27 @@ export async function getCollateralInfoEvm(
352
490
 
353
491
  /**
354
492
  * Get all available collateral information
493
+ * @group EVM
494
+ * @category Queries
355
495
  * @param provider - Ethers provider
356
496
  * @param tokenHolderContractAddress - Address of the TokenHolder contract
357
497
  * @param collateralAddresses - Array of collateral token addresses
358
498
  * @returns Array of active collaterals
499
+ *
500
+ * @example
501
+ * ```typescript
502
+ * const collaterals = await getOffersEvm(
503
+ * provider,
504
+ * "0x123...", // TokenHolder address
505
+ * ["0x456...", "0x789...", "0xabc..."] // token addresses to check
506
+ * );
507
+ *
508
+ * console.log(`Found ${collaterals.length} available collaterals`);
509
+ *
510
+ * collaterals.forEach(({ address, collateral }) => {
511
+ * console.log(`Token ${address}: LTV ${collateral.maxLTV}%`);
512
+ * });
513
+ * ```
359
514
  */
360
515
  export async function getOffersEvm(
361
516
  provider: Provider,
@@ -384,9 +539,23 @@ export async function getOffersEvm(
384
539
 
385
540
  /**
386
541
  * Get the opening fee percentage
542
+ * @group EVM
543
+ * @category Queries
387
544
  * @param provider - Ethers provider
388
545
  * @param borrowerOpsContractAddress - BorrowerOperations contract address
389
546
  * @returns Opening fee as a BigNumber
547
+ *
548
+ * @example
549
+ * ```typescript
550
+ * const openingFee = await getOpeningFeeEvm(
551
+ * provider,
552
+ * "0x123..." // BorrowerOps address
553
+ * );
554
+ *
555
+ * // Convert to percentage (assuming 18 decimals)
556
+ * const feePercent = Number(openingFee) / 1e16; // e.g., 0.5%
557
+ * console.log(`Opening fee: ${feePercent}%`);
558
+ * ```
390
559
  */
391
560
  export async function getOpeningFeeEvm(
392
561
  provider: Provider,
@@ -402,9 +571,23 @@ export async function getOpeningFeeEvm(
402
571
 
403
572
  /**
404
573
  * Get the profit fee percentage
574
+ * @group EVM
575
+ * @category Queries
405
576
  * @param provider - Ethers provider
406
577
  * @param borrowerOpsContractAddress - BorrowerOperations contract address
407
578
  * @returns Profit fee as a BigNumber
579
+ *
580
+ * @example
581
+ * ```typescript
582
+ * const profitFee = await getProfitFeeEvm(
583
+ * provider,
584
+ * "0x123..." // BorrowerOps address
585
+ * );
586
+ *
587
+ * // Convert to percentage (assuming 18 decimals)
588
+ * const feePercent = Number(profitFee) / 1e16; // e.g., 1%
589
+ * console.log(`Profit fee: ${feePercent}%`);
590
+ * ```
408
591
  */
409
592
  export async function getProfitFeeEvm(
410
593
  provider: Provider,
@@ -420,9 +603,23 @@ export async function getProfitFeeEvm(
420
603
 
421
604
  /**
422
605
  * Get the token balance of the token holder contract
606
+ * @group EVM
607
+ * @category Queries
423
608
  * @param provider - Ethers provider
424
609
  * @param tokenHolderContractAddress - Address of the TokenHolder contract
425
610
  * @returns Token balance as a BigNumber
611
+ *
612
+ * @example
613
+ * ```typescript
614
+ * const balance = await getTokenBalanceEvm(
615
+ * provider,
616
+ * "0x123..." // TokenHolder address
617
+ * );
618
+ *
619
+ * // Format for display (assuming 18 decimals)
620
+ * const formatted = ethers.formatEther(balance);
621
+ * console.log(`Contract balance: ${formatted} ETH`);
622
+ * ```
426
623
  */
427
624
  export async function getTokenBalanceEvm(
428
625
  provider: Provider,
@@ -438,9 +635,26 @@ export async function getTokenBalanceEvm(
438
635
 
439
636
  /**
440
637
  * Get the active loan count
638
+ * @group EVM
639
+ * @category Queries
441
640
  * @param provider - Ethers provider
442
641
  * @param tokenHolderContractAddress - Address of the TokenHolder contract
443
642
  * @returns Number of active loans
643
+ *
644
+ * @example
645
+ * ```typescript
646
+ * const loanCount = await getActiveLoanCountEvm(
647
+ * provider,
648
+ * "0x123..." // TokenHolder address
649
+ * );
650
+ *
651
+ * console.log(`Total active loans: ${loanCount}`);
652
+ *
653
+ * // Use for statistics or monitoring
654
+ * if (loanCount > 1000n) {
655
+ * console.log("High activity detected");
656
+ * }
657
+ * ```
444
658
  */
445
659
  export async function getActiveLoanCountEvm(
446
660
  provider: Provider,
@@ -456,11 +670,30 @@ export async function getActiveLoanCountEvm(
456
670
 
457
671
  /**
458
672
  * Get a batch of active loans
673
+ * @group EVM
674
+ * @category Queries
459
675
  * @param provider - Ethers provider
460
676
  * @param tokenHolderContractAddress - Address of the TokenHolder contract
461
677
  * @param startIndex - Starting index in the activeLoanIds array
462
678
  * @param batchSize - Number of loans to retrieve
463
679
  * @returns Array of active loans
680
+ *
681
+ * @example
682
+ * ```typescript
683
+ * const loans = await getActiveLoansBatchEvm(
684
+ * provider,
685
+ * "0x123...", // TokenHolder address
686
+ * 0, // start from first loan
687
+ * 100 // get 100 loans
688
+ * );
689
+ *
690
+ * console.log(`Retrieved ${loans.length} loans`);
691
+ *
692
+ * // Process batch
693
+ * loans.forEach(loan => {
694
+ * console.log(`Loan #${loan.id}: ${loan.borrower}`);
695
+ * });
696
+ * ```
464
697
  */
465
698
  export async function getActiveLoansBatchEvm(
466
699
  provider: Provider,
@@ -478,10 +711,27 @@ export async function getActiveLoansBatchEvm(
478
711
 
479
712
  /**
480
713
  * Get all loans for a specific borrower
714
+ * @group EVM
715
+ * @category Queries
481
716
  * @param provider - Ethers provider
482
717
  * @param tokenHolderContractAddress - Address of the TokenHolder contract
483
718
  * @param borrowerAddress - Address of the borrower
484
719
  * @returns Array of loans belonging to the borrower
720
+ *
721
+ * @example
722
+ * ```typescript
723
+ * const userLoans = await getLoansByBorrowerEvm(
724
+ * provider,
725
+ * "0x123...", // TokenHolder address
726
+ * "0x456..." // borrower address
727
+ * );
728
+ *
729
+ * console.log(`Borrower has ${userLoans.length} loans`);
730
+ *
731
+ * userLoans.forEach(loan => {
732
+ * console.log(`Loan #${loan.id}: ${loan.collateralAmount} collateral`);
733
+ * });
734
+ * ```
485
735
  */
486
736
  export async function getLoansByBorrowerEvm(
487
737
  provider: Provider,
@@ -498,10 +748,29 @@ export async function getLoansByBorrowerEvm(
498
748
 
499
749
  /**
500
750
  * Get current exposure for a collateral
751
+ * @group EVM
752
+ * @category Queries
501
753
  * @param provider - Ethers provider
502
754
  * @param tokenHolderContractAddress - Address of the TokenHolder contract
503
755
  * @param collateralAddress - Address of the collateral token
504
756
  * @returns Current exposure as a BigNumber
757
+ *
758
+ * @example
759
+ * ```typescript
760
+ * const exposure = await getCollateralExposureEvm(
761
+ * provider,
762
+ * "0x123...", // TokenHolder address
763
+ * "0x456..." // collateral token address
764
+ * );
765
+ *
766
+ * console.log(`Current exposure: ${ethers.formatEther(exposure)}`);
767
+ *
768
+ * // Check if near limit
769
+ * const maxExposure = 1000000n;
770
+ * if (exposure > maxExposure * 90n / 100n) {
771
+ * console.log("Warning: 90% exposure reached");
772
+ * }
773
+ * ```
505
774
  */
506
775
  export async function getCollateralExposureEvm(
507
776
  provider: Provider,
@@ -518,10 +787,29 @@ export async function getCollateralExposureEvm(
518
787
 
519
788
  /**
520
789
  * Get available exposure for a collateral
790
+ * @group EVM
791
+ * @category Queries
521
792
  * @param provider - Ethers provider
522
793
  * @param tokenHolderContractAddress - Address of the TokenHolder contract
523
794
  * @param collateralAddress - Address of the collateral token
524
795
  * @returns Available exposure as a BigNumber
796
+ *
797
+ * @example
798
+ * ```typescript
799
+ * const available = await getAvailableExposureEvm(
800
+ * provider,
801
+ * "0x123...", // TokenHolder address
802
+ * "0x456..." // collateral token address
803
+ * );
804
+ *
805
+ * console.log(`Available exposure: ${ethers.formatEther(available)}`);
806
+ *
807
+ * // Check if can open new position
808
+ * const newPositionSize = ethers.parseEther("10");
809
+ * if (available >= newPositionSize) {
810
+ * console.log("Sufficient exposure available");
811
+ * }
812
+ * ```
525
813
  */
526
814
  export async function getAvailableExposureEvm(
527
815
  provider: Provider,
@@ -581,6 +869,8 @@ export const liquidatePositionEvm = async (
581
869
 
582
870
  /**
583
871
  * Update max lend per token for multiple collaterals in batch
872
+ * @group EVM
873
+ * @category Operations
584
874
  * @param provider - Ethers provider
585
875
  * @param tokenHolderContractAddress - Address of the TokenHolder contract
586
876
  * @param collateralAddresses - Array of collateral token addresses
@@ -588,6 +878,24 @@ export const liquidatePositionEvm = async (
588
878
  * @param gasLimit - Optional gas limit
589
879
  * @param gasPrice - Optional gas price
590
880
  * @returns Unsigned transaction object
881
+ *
882
+ * @example
883
+ * ```typescript
884
+ * const tx = await updateMaxLendPerTokenBatchEvm(
885
+ * provider,
886
+ * "0x123...", // TokenHolder address
887
+ * {
888
+ * collateralAddresses: ["0x456...", "0x789..."],
889
+ * newMaxLendPerTokens: [
890
+ * ethers.parseEther("1000"),
891
+ * ethers.parseEther("500")
892
+ * ]
893
+ * }
894
+ * );
895
+ *
896
+ * const receipt = await signer.sendTransaction(tx);
897
+ * console.log("Max lend limits updated");
898
+ * ```
591
899
  */
592
900
  export const updateMaxLendPerTokenBatchEvm = async (
593
901
  provider: Provider,