@lavarage/sdk 6.7.0 → 6.7.2

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.mjs CHANGED
@@ -2927,7 +2927,7 @@ var borrowerOperationsAbi = [
2927
2927
  ],
2928
2928
  name: "sell",
2929
2929
  outputs: [],
2930
- stateMutability: "nonpayable",
2930
+ stateMutability: "payable",
2931
2931
  type: "function"
2932
2932
  },
2933
2933
  {
@@ -3188,7 +3188,9 @@ var tokenHolderAbi = [
3188
3188
  { internalType: "uint256", name: "maxLendPerToken", type: "uint256" },
3189
3189
  { internalType: "uint256", name: "interestRate", type: "uint256" },
3190
3190
  { internalType: "bool", name: "active", type: "bool" },
3191
- { internalType: "uint256", name: "minAmount", type: "uint256" }
3191
+ { internalType: "uint256", name: "minAmount", type: "uint256" },
3192
+ { internalType: "uint256", name: "maxExposure", type: "uint256" },
3193
+ { internalType: "uint256", name: "currentExposure", type: "uint256" }
3192
3194
  ],
3193
3195
  stateMutability: "view",
3194
3196
  type: "function"
@@ -3279,7 +3281,9 @@ var tokenHolderAbi = [
3279
3281
  { internalType: "uint256", name: "maxLendPerToken", type: "uint256" },
3280
3282
  { internalType: "uint256", name: "interestRate", type: "uint256" },
3281
3283
  { internalType: "bool", name: "active", type: "bool" },
3282
- { internalType: "uint256", name: "minAmount", type: "uint256" }
3284
+ { internalType: "uint256", name: "minAmount", type: "uint256" },
3285
+ { internalType: "uint256", name: "maxExposure", type: "uint256" },
3286
+ { internalType: "uint256", name: "currentExposure", type: "uint256" }
3283
3287
  ],
3284
3288
  internalType: "struct Collateral",
3285
3289
  name: "collateral",
@@ -3395,6 +3399,218 @@ var tokenHolderAbi = [
3395
3399
  outputs: [],
3396
3400
  stateMutability: "nonpayable",
3397
3401
  type: "function"
3402
+ },
3403
+ {
3404
+ inputs: [{ internalType: "uint256", name: "", type: "uint256" }],
3405
+ name: "activeLoanIds",
3406
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
3407
+ stateMutability: "view",
3408
+ type: "function"
3409
+ },
3410
+ {
3411
+ inputs: [],
3412
+ name: "getActiveLoanCount",
3413
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
3414
+ stateMutability: "view",
3415
+ type: "function"
3416
+ },
3417
+ {
3418
+ inputs: [
3419
+ { internalType: "uint256", name: "startIndex", type: "uint256" },
3420
+ { internalType: "uint256", name: "batchSize", type: "uint256" }
3421
+ ],
3422
+ name: "getActiveLoansBatch",
3423
+ outputs: [
3424
+ {
3425
+ components: [
3426
+ { internalType: "uint256", name: "id", type: "uint256" },
3427
+ { internalType: "uint256", name: "amount", type: "uint256" },
3428
+ {
3429
+ components: [
3430
+ {
3431
+ internalType: "address",
3432
+ name: "collateralAddress",
3433
+ type: "address"
3434
+ },
3435
+ {
3436
+ internalType: "uint256",
3437
+ name: "maxLendPerToken",
3438
+ type: "uint256"
3439
+ },
3440
+ {
3441
+ internalType: "uint256",
3442
+ name: "interestRate",
3443
+ type: "uint256"
3444
+ },
3445
+ { internalType: "bool", name: "active", type: "bool" },
3446
+ { internalType: "uint256", name: "minAmount", type: "uint256" },
3447
+ { internalType: "uint256", name: "maxExposure", type: "uint256" },
3448
+ {
3449
+ internalType: "uint256",
3450
+ name: "currentExposure",
3451
+ type: "uint256"
3452
+ }
3453
+ ],
3454
+ internalType: "struct Collateral",
3455
+ name: "collateral",
3456
+ type: "tuple"
3457
+ },
3458
+ {
3459
+ internalType: "uint256",
3460
+ name: "collateralAmount",
3461
+ type: "uint256"
3462
+ },
3463
+ { internalType: "uint256", name: "timestamp", type: "uint256" },
3464
+ { internalType: "address", name: "borrower", type: "address" },
3465
+ { internalType: "uint256", name: "userPaid", type: "uint256" }
3466
+ ],
3467
+ internalType: "struct Loan[]",
3468
+ name: "",
3469
+ type: "tuple[]"
3470
+ }
3471
+ ],
3472
+ stateMutability: "view",
3473
+ type: "function"
3474
+ },
3475
+ {
3476
+ inputs: [{ internalType: "address", name: "borrower", type: "address" }],
3477
+ name: "getLoansByBorrower",
3478
+ outputs: [
3479
+ {
3480
+ components: [
3481
+ { internalType: "uint256", name: "id", type: "uint256" },
3482
+ { internalType: "uint256", name: "amount", type: "uint256" },
3483
+ {
3484
+ components: [
3485
+ {
3486
+ internalType: "address",
3487
+ name: "collateralAddress",
3488
+ type: "address"
3489
+ },
3490
+ {
3491
+ internalType: "uint256",
3492
+ name: "maxLendPerToken",
3493
+ type: "uint256"
3494
+ },
3495
+ {
3496
+ internalType: "uint256",
3497
+ name: "interestRate",
3498
+ type: "uint256"
3499
+ },
3500
+ { internalType: "bool", name: "active", type: "bool" },
3501
+ { internalType: "uint256", name: "minAmount", type: "uint256" },
3502
+ { internalType: "uint256", name: "maxExposure", type: "uint256" },
3503
+ {
3504
+ internalType: "uint256",
3505
+ name: "currentExposure",
3506
+ type: "uint256"
3507
+ }
3508
+ ],
3509
+ internalType: "struct Collateral",
3510
+ name: "collateral",
3511
+ type: "tuple"
3512
+ },
3513
+ {
3514
+ internalType: "uint256",
3515
+ name: "collateralAmount",
3516
+ type: "uint256"
3517
+ },
3518
+ { internalType: "uint256", name: "timestamp", type: "uint256" },
3519
+ { internalType: "address", name: "borrower", type: "address" },
3520
+ { internalType: "uint256", name: "userPaid", type: "uint256" }
3521
+ ],
3522
+ internalType: "struct Loan[]",
3523
+ name: "",
3524
+ type: "tuple[]"
3525
+ }
3526
+ ],
3527
+ stateMutability: "view",
3528
+ type: "function"
3529
+ },
3530
+ {
3531
+ inputs: [
3532
+ { internalType: "address", name: "collateralAddress", type: "address" }
3533
+ ],
3534
+ name: "getCollateralExposure",
3535
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
3536
+ stateMutability: "view",
3537
+ type: "function"
3538
+ },
3539
+ {
3540
+ inputs: [
3541
+ { internalType: "address", name: "collateralAddress", type: "address" }
3542
+ ],
3543
+ name: "getAvailableExposure",
3544
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
3545
+ stateMutability: "view",
3546
+ type: "function"
3547
+ },
3548
+ {
3549
+ inputs: [
3550
+ { internalType: "address", name: "collateralAddress", type: "address" },
3551
+ { internalType: "uint256", name: "_interestRate", type: "uint256" },
3552
+ { internalType: "uint256", name: "maxLendPerToken", type: "uint256" },
3553
+ { internalType: "uint256", name: "minAmount", type: "uint256" },
3554
+ { internalType: "uint256", name: "maxExposure", type: "uint256" }
3555
+ ],
3556
+ name: "addCollateral",
3557
+ outputs: [],
3558
+ stateMutability: "nonpayable",
3559
+ type: "function"
3560
+ },
3561
+ {
3562
+ inputs: [
3563
+ { internalType: "address", name: "collateralAddress", type: "address" },
3564
+ { internalType: "uint256", name: "newMaxExposure", type: "uint256" }
3565
+ ],
3566
+ name: "updateMaxExposure",
3567
+ outputs: [],
3568
+ stateMutability: "nonpayable",
3569
+ type: "function"
3570
+ },
3571
+ {
3572
+ anonymous: false,
3573
+ inputs: [
3574
+ {
3575
+ indexed: false,
3576
+ internalType: "address",
3577
+ name: "collateralAddress",
3578
+ type: "address"
3579
+ },
3580
+ {
3581
+ indexed: false,
3582
+ internalType: "uint256",
3583
+ name: "currentExposure",
3584
+ type: "uint256"
3585
+ }
3586
+ ],
3587
+ name: "ExposureUpdated",
3588
+ type: "event"
3589
+ },
3590
+ {
3591
+ anonymous: false,
3592
+ inputs: [
3593
+ {
3594
+ indexed: false,
3595
+ internalType: "address",
3596
+ name: "collateralAddress",
3597
+ type: "address"
3598
+ },
3599
+ {
3600
+ indexed: false,
3601
+ internalType: "uint256",
3602
+ name: "oldMaxExposure",
3603
+ type: "uint256"
3604
+ },
3605
+ {
3606
+ indexed: false,
3607
+ internalType: "uint256",
3608
+ name: "newMaxExposure",
3609
+ type: "uint256"
3610
+ }
3611
+ ],
3612
+ name: "MaxExposureUpdated",
3613
+ type: "event"
3398
3614
  }
3399
3615
  ];
3400
3616
 
@@ -3465,25 +3681,30 @@ function getPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 42960
3465
3681
  );
3466
3682
  const filter = contract.filters.Buy();
3467
3683
  const events = yield contract.queryFilter(filter, fromBlock);
3468
- return events.map((event) => {
3469
- const {
3470
- buyer,
3471
- tokenCollateral,
3472
- loanId,
3473
- openingPositionSize,
3474
- collateralAmount,
3475
- initialMargin
3476
- } = event.args;
3477
- return {
3478
- trader: buyer,
3479
- tokenCollateral,
3480
- loanId,
3481
- openingPositionSize,
3482
- collateralAmount,
3483
- initialMargin,
3484
- transactionHash: event.transactionHash
3485
- };
3486
- });
3684
+ return Promise.all(
3685
+ events.map((event) => __async(this, null, function* () {
3686
+ const {
3687
+ buyer,
3688
+ tokenCollateral,
3689
+ loanId,
3690
+ openingPositionSize,
3691
+ collateralAmount,
3692
+ initialMargin
3693
+ } = event.args;
3694
+ const block = yield provider.getBlock(event.blockNumber);
3695
+ const timestamp = Number(block == null ? void 0 : block.timestamp) || 0;
3696
+ return {
3697
+ trader: buyer,
3698
+ tokenCollateral,
3699
+ loanId,
3700
+ openingPositionSize,
3701
+ collateralAmount,
3702
+ initialMargin,
3703
+ transactionHash: event.transactionHash,
3704
+ timestamp
3705
+ };
3706
+ }))
3707
+ );
3487
3708
  });
3488
3709
  }
3489
3710
  function getClosedPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 42960845) {
@@ -3495,17 +3716,22 @@ function getClosedPositionsEvm(provider, borrowerOpsContractAddress, fromBlock =
3495
3716
  );
3496
3717
  const filter = contract.filters.Sell();
3497
3718
  const events = yield contract.queryFilter(filter, fromBlock);
3498
- return events.map((event) => {
3499
- const { buyer, tokenCollateral, loanId, closingPositionSize, profit } = event.args;
3500
- return {
3501
- trader: buyer,
3502
- tokenCollateral,
3503
- loanId,
3504
- closingPositionSize,
3505
- profit,
3506
- transactionHash: event.transactionHash
3507
- };
3508
- });
3719
+ return Promise.all(
3720
+ events.map((event) => __async(this, null, function* () {
3721
+ const { buyer, tokenCollateral, loanId, closingPositionSize, profit } = event.args;
3722
+ const block = yield provider.getBlock(event.blockNumber);
3723
+ const timestamp = block ? Number(block.timestamp) : 0;
3724
+ return {
3725
+ trader: buyer,
3726
+ tokenCollateral,
3727
+ loanId,
3728
+ closingPositionSize,
3729
+ profit,
3730
+ transactionHash: event.transactionHash,
3731
+ timestamp
3732
+ };
3733
+ }))
3734
+ );
3509
3735
  });
3510
3736
  }
3511
3737
  function getLiquidatedPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 42960845) {
@@ -3517,23 +3743,28 @@ function getLiquidatedPositionsEvm(provider, borrowerOpsContractAddress, fromBlo
3517
3743
  );
3518
3744
  const filter = contract.filters.Liquidation();
3519
3745
  const events = yield contract.queryFilter(filter, fromBlock);
3520
- return events.map((event) => {
3521
- const {
3522
- borrower,
3523
- tokenCollateral,
3524
- loanId,
3525
- closingPositionSize,
3526
- liquidatorRepaidAmount
3527
- } = event.args;
3528
- return {
3529
- trader: borrower,
3530
- tokenCollateral,
3531
- loanId,
3532
- closingPositionSize,
3533
- liquidatorRepaidAmount,
3534
- transactionHash: event.transactionHash
3535
- };
3536
- });
3746
+ return Promise.all(
3747
+ events.map((event) => __async(this, null, function* () {
3748
+ const {
3749
+ borrower,
3750
+ tokenCollateral,
3751
+ loanId,
3752
+ closingPositionSize,
3753
+ liquidatorRepaidAmount
3754
+ } = event.args;
3755
+ const block = yield provider.getBlock(event.blockNumber);
3756
+ const timestamp = block ? Number(block.timestamp) : 0;
3757
+ return {
3758
+ trader: borrower,
3759
+ tokenCollateral,
3760
+ loanId,
3761
+ closingPositionSize,
3762
+ liquidatorRepaidAmount,
3763
+ transactionHash: event.transactionHash,
3764
+ timestamp
3765
+ };
3766
+ }))
3767
+ );
3537
3768
  });
3538
3769
  }
3539
3770
  function getLoanEvm(provider, tokenHolderContractAddress, loanId) {
@@ -3594,6 +3825,86 @@ function getOffersEvm(provider, tokenHolderContractAddress, collateralAddresses)
3594
3825
  return activeCollaterals;
3595
3826
  });
3596
3827
  }
3828
+ function getOpeningFeeEvm(provider, borrowerOpsContractAddress) {
3829
+ return __async(this, null, function* () {
3830
+ const contract = new Contract(
3831
+ borrowerOpsContractAddress,
3832
+ borrowerOperationsAbi,
3833
+ provider
3834
+ );
3835
+ return contract.openingFee();
3836
+ });
3837
+ }
3838
+ function getProfitFeeEvm(provider, borrowerOpsContractAddress) {
3839
+ return __async(this, null, function* () {
3840
+ const contract = new Contract(
3841
+ borrowerOpsContractAddress,
3842
+ borrowerOperationsAbi,
3843
+ provider
3844
+ );
3845
+ return contract.profitFee();
3846
+ });
3847
+ }
3848
+ function getTokenBalanceEvm(provider, tokenHolderContractAddress) {
3849
+ return __async(this, null, function* () {
3850
+ const contract = new Contract(
3851
+ tokenHolderContractAddress,
3852
+ tokenHolderAbi,
3853
+ provider
3854
+ );
3855
+ return contract.getBalance();
3856
+ });
3857
+ }
3858
+ function getActiveLoanCountEvm(provider, tokenHolderContractAddress) {
3859
+ return __async(this, null, function* () {
3860
+ const contract = new Contract(
3861
+ tokenHolderContractAddress,
3862
+ tokenHolderAbi,
3863
+ provider
3864
+ );
3865
+ return contract.getActiveLoanCount();
3866
+ });
3867
+ }
3868
+ function getActiveLoansBatchEvm(provider, tokenHolderContractAddress, startIndex, batchSize) {
3869
+ return __async(this, null, function* () {
3870
+ const contract = new Contract(
3871
+ tokenHolderContractAddress,
3872
+ tokenHolderAbi,
3873
+ provider
3874
+ );
3875
+ return contract.getActiveLoansBatch(startIndex, batchSize);
3876
+ });
3877
+ }
3878
+ function getLoansByBorrowerEvm(provider, tokenHolderContractAddress, borrowerAddress) {
3879
+ return __async(this, null, function* () {
3880
+ const contract = new Contract(
3881
+ tokenHolderContractAddress,
3882
+ tokenHolderAbi,
3883
+ provider
3884
+ );
3885
+ return contract.getLoansByBorrower(borrowerAddress);
3886
+ });
3887
+ }
3888
+ function getCollateralExposureEvm(provider, tokenHolderContractAddress, collateralAddress) {
3889
+ return __async(this, null, function* () {
3890
+ const contract = new Contract(
3891
+ tokenHolderContractAddress,
3892
+ tokenHolderAbi,
3893
+ provider
3894
+ );
3895
+ return contract.getCollateralExposure(collateralAddress);
3896
+ });
3897
+ }
3898
+ function getAvailableExposureEvm(provider, tokenHolderContractAddress, collateralAddress) {
3899
+ return __async(this, null, function* () {
3900
+ const contract = new Contract(
3901
+ tokenHolderContractAddress,
3902
+ tokenHolderAbi,
3903
+ provider
3904
+ );
3905
+ return contract.getAvailableExposure(collateralAddress);
3906
+ });
3907
+ }
3597
3908
 
3598
3909
  // index.ts
3599
3910
  function getPda(seed, programId) {
@@ -4739,20 +5050,28 @@ export {
4739
5050
  closeTradeV1,
4740
5051
  closeTradeV2,
4741
5052
  createTpDelegate,
5053
+ getActiveLoanCountEvm,
5054
+ getActiveLoansBatchEvm,
4742
5055
  getAllPositions,
5056
+ getAvailableExposureEvm,
4743
5057
  getClosedPositions,
4744
5058
  getClosedPositionsEvm,
5059
+ getCollateralExposureEvm,
4745
5060
  getCollateralInfoEvm,
4746
5061
  getDelegateAccounts,
4747
5062
  getLiquidatedPositions,
4748
5063
  getLiquidatedPositionsEvm,
4749
5064
  getLoanEvm,
5065
+ getLoansByBorrowerEvm,
4750
5066
  getOffers,
4751
5067
  getOffersEvm,
4752
5068
  getOpenPositions,
5069
+ getOpeningFeeEvm,
4753
5070
  getPda,
4754
5071
  getPositionAccountPDA,
4755
5072
  getPositionsEvm,
5073
+ getProfitFeeEvm,
5074
+ getTokenBalanceEvm,
4756
5075
  getUserLoansEvm,
4757
5076
  mergePositionV2,
4758
5077
  modifyTpDelegate,