@liquidium/client 0.5.1 → 0.5.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.cjs CHANGED
@@ -5305,23 +5305,38 @@ var PositionsModule = class {
5305
5305
  }
5306
5306
  }
5307
5307
  /**
5308
- * Lists all positions for a profile.
5308
+ * Lists visible positions for a profile. Supply balances below their pool's
5309
+ * same-asset dust threshold are hidden without removing active debt.
5309
5310
  *
5310
5311
  * @param profileId - The Liquidium profile principal text.
5311
- * @returns All positions currently associated with the requested profile.
5312
+ * @returns Visible positions currently associated with the requested profile.
5312
5313
  */
5313
5314
  async listPositions(profileId) {
5314
5315
  try {
5315
5316
  const actor = createFlexibleLendingActor(this.canisterContext);
5316
5317
  const profilePrincipal = principal.Principal.fromText(profileId);
5317
- const stats = await actor.get_profile_stats(profilePrincipal);
5318
+ const [stats, pools] = await Promise.all([
5319
+ actor.get_profile_stats(profilePrincipal),
5320
+ actor.list_pools()
5321
+ ]);
5318
5322
  const decodedStats = decodeFlexibleUserStats(stats);
5323
+ const dustThresholdsByPoolId = new Map(
5324
+ pools.map((pool) => [
5325
+ pool.principal.toText(),
5326
+ pool.same_asset_borrowing_dust_threshold
5327
+ ])
5328
+ );
5319
5329
  const positionViews = await Promise.all(
5320
5330
  decodedStats.positions.map(
5321
5331
  (position) => actor.get_position(profilePrincipal, position.pool_id)
5322
5332
  )
5323
5333
  );
5324
- return positionViews.map((result) => result[0]).filter((view) => view !== void 0).map(decodeFlexiblePositionView).filter((view) => view !== null).map(mapDecodedPositionViewToPosition);
5334
+ return positionViews.map((result) => result[0]).filter((view) => view !== void 0).map(decodeFlexiblePositionView).filter((view) => view !== null).map(mapDecodedPositionViewToPosition).map(
5335
+ (position) => getPositionWithSuppliedDustHidden(
5336
+ position,
5337
+ dustThresholdsByPoolId.get(position.poolId)
5338
+ )
5339
+ ).filter((position) => position !== null);
5325
5340
  } catch (error) {
5326
5341
  if (error instanceof LiquidiumError) {
5327
5342
  throw error;
@@ -5407,6 +5422,10 @@ var PositionsModule = class {
5407
5422
  * Returns the per-reserve breakdown of a profile's supplies and borrows,
5408
5423
  * joined with pool metadata, rates, and current USD prices.
5409
5424
  *
5425
+ * Supplied-only reserves below their pool's same-asset dust threshold are
5426
+ * omitted. Reserves with active debt remain, with their supplied amount and
5427
+ * earned interest set to zero when the supplied balance is below the threshold.
5428
+ *
5410
5429
  * USD values are scaled to 27 decimals.
5411
5430
  *
5412
5431
  * @param profileId - The Liquidium profile principal text.
@@ -5487,6 +5506,16 @@ var PositionsModule = class {
5487
5506
  return { amount: position.deposited, decimals: position.depositedDecimals };
5488
5507
  }
5489
5508
  };
5509
+ function getPositionWithSuppliedDustHidden(position, dustThreshold) {
5510
+ if (dustThreshold === void 0 || position.deposited >= dustThreshold) {
5511
+ return position;
5512
+ }
5513
+ const hasDebt = position.borrowed > 0n || position.debtInterest > 0n;
5514
+ if (!hasDebt) {
5515
+ return null;
5516
+ }
5517
+ return { ...position, deposited: 0n, earnedInterest: 0n };
5518
+ }
5490
5519
  function nativeAmountToUsdScaled(amount, nativeDecimals, priceUsd) {
5491
5520
  if (amount <= 0n || priceUsd <= 0) {
5492
5521
  return 0n;