@lavarage/sdk 6.7.4 → 6.7.6

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.mts CHANGED
@@ -2717,13 +2717,12 @@ declare const closePositionEvm: (provider: Provider, borrowerOpsContractAddress:
2717
2717
  gasPrice?: string | number;
2718
2718
  }) => Promise<ContractTransaction>;
2719
2719
  /**
2720
- * Get all positions from events
2720
+ * Get all positions from active loans
2721
2721
  * @param provider - Ethers provider
2722
- * @param borrowerOpsContractAddress - BorrowerOperations contract address
2723
- * @param fromBlock - Block to start searching from
2724
- * @returns Array of Buy events representing positions
2722
+ * @param tokenHolderContractAddress - TokenHolder contract address
2723
+ * @returns Array of active positions
2725
2724
  */
2726
- declare function getPositionsEvm(provider: Provider, borrowerOpsContractAddress: string, fromBlock?: number): Promise<BuyEvent[]>;
2725
+ declare function getPositionsEvm(provider: Provider, tokenHolderContractAddress: string): Promise<BuyEvent[]>;
2727
2726
  /**
2728
2727
  * Get closed positions from events
2729
2728
  * @param provider - Ethers provider
package/dist/index.d.ts CHANGED
@@ -2717,13 +2717,12 @@ declare const closePositionEvm: (provider: Provider, borrowerOpsContractAddress:
2717
2717
  gasPrice?: string | number;
2718
2718
  }) => Promise<ContractTransaction>;
2719
2719
  /**
2720
- * Get all positions from events
2720
+ * Get all positions from active loans
2721
2721
  * @param provider - Ethers provider
2722
- * @param borrowerOpsContractAddress - BorrowerOperations contract address
2723
- * @param fromBlock - Block to start searching from
2724
- * @returns Array of Buy events representing positions
2722
+ * @param tokenHolderContractAddress - TokenHolder contract address
2723
+ * @returns Array of active positions
2725
2724
  */
2726
- declare function getPositionsEvm(provider: Provider, borrowerOpsContractAddress: string, fromBlock?: number): Promise<BuyEvent[]>;
2725
+ declare function getPositionsEvm(provider: Provider, tokenHolderContractAddress: string): Promise<BuyEvent[]>;
2727
2726
  /**
2728
2727
  * Get closed positions from events
2729
2728
  * @param provider - Ethers provider
package/dist/index.js CHANGED
@@ -3715,45 +3715,34 @@ var closePositionEvm = (_0, _1, _2) => __async(void 0, [_0, _1, _2], function* (
3715
3715
  Object.keys(txOptions).length > 0 ? txOptions : {}
3716
3716
  );
3717
3717
  });
3718
- function getPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 42960845) {
3718
+ function getPositionsEvm(provider, tokenHolderContractAddress) {
3719
3719
  return __async(this, null, function* () {
3720
3720
  const contract = new import_ethers.Contract(
3721
- borrowerOpsContractAddress,
3722
- borrowerOperationsAbi,
3721
+ tokenHolderContractAddress,
3722
+ tokenHolderAbi,
3723
3723
  provider
3724
3724
  );
3725
- const currentBlock = yield provider.getBlockNumber();
3726
- const filter = contract.filters.Buy();
3727
- const allEvents = [];
3728
- for (let start = fromBlock; start <= currentBlock; start += 1e4) {
3729
- const end = Math.min(start + 9999, currentBlock);
3730
- const events = yield contract.queryFilter(filter, start, end);
3731
- allEvents.push(...events);
3725
+ const activeLoanCount = yield contract.getActiveLoanCount();
3726
+ const batchSize = 100;
3727
+ const positions = [];
3728
+ for (let i = 0; i < activeLoanCount; i += batchSize) {
3729
+ const currentBatchSize = Math.min(Number(activeLoanCount) - i, batchSize);
3730
+ const loans = yield contract.getActiveLoansBatch(i, currentBatchSize);
3731
+ for (const loan of loans) {
3732
+ positions.push({
3733
+ trader: loan.borrower,
3734
+ tokenCollateral: loan.collateral.collateralAddress,
3735
+ loanId: loan.id,
3736
+ openingPositionSize: loan.amount + loan.userPaid,
3737
+ collateralAmount: loan.collateralAmount,
3738
+ initialMargin: loan.userPaid,
3739
+ transactionHash: "",
3740
+ // Not available from loan data
3741
+ timestamp: Number(loan.timestamp)
3742
+ });
3743
+ }
3732
3744
  }
3733
- return Promise.all(
3734
- allEvents.map((event) => __async(this, null, function* () {
3735
- const {
3736
- buyer,
3737
- tokenCollateral,
3738
- loanId,
3739
- openingPositionSize,
3740
- collateralAmount,
3741
- initialMargin
3742
- } = event.args;
3743
- const block = yield provider.getBlock(event.blockNumber);
3744
- const timestamp = Number(block == null ? void 0 : block.timestamp) || 0;
3745
- return {
3746
- trader: buyer,
3747
- tokenCollateral,
3748
- loanId,
3749
- openingPositionSize,
3750
- collateralAmount,
3751
- initialMargin,
3752
- transactionHash: event.transactionHash,
3753
- timestamp
3754
- };
3755
- }))
3756
- );
3745
+ return positions;
3757
3746
  });
3758
3747
  }
3759
3748
  function getClosedPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 42960845) {