@liquidium/client 0.5.0 → 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.d.cts CHANGED
@@ -1107,9 +1107,9 @@ interface Pool {
1107
1107
  decimals: bigint;
1108
1108
  /** Whether new pool activity is currently frozen. */
1109
1109
  frozen: boolean;
1110
- /** Total supplied amount in base units. */
1110
+ /** Current supplied amount in base units after applying the lending index. */
1111
1111
  totalSupply: bigint;
1112
- /** Total borrowed amount in base units. */
1112
+ /** Current borrowed amount in base units after applying the borrow index. */
1113
1113
  totalDebt: bigint;
1114
1114
  /** Currently available liquidity in base units. */
1115
1115
  availableLiquidity: bigint;
@@ -1334,10 +1334,11 @@ declare class PositionsModule {
1334
1334
  */
1335
1335
  getPosition(profileId: string, poolId: string): Promise<Position | null>;
1336
1336
  /**
1337
- * Lists all positions for a profile.
1337
+ * Lists visible positions for a profile. Supply balances below their pool's
1338
+ * same-asset dust threshold are hidden without removing active debt.
1338
1339
  *
1339
1340
  * @param profileId - The Liquidium profile principal text.
1340
- * @returns All positions currently associated with the requested profile.
1341
+ * @returns Visible positions currently associated with the requested profile.
1341
1342
  */
1342
1343
  listPositions(profileId: string): Promise<Position[]>;
1343
1344
  /**
@@ -1370,6 +1371,10 @@ declare class PositionsModule {
1370
1371
  * Returns the per-reserve breakdown of a profile's supplies and borrows,
1371
1372
  * joined with pool metadata, rates, and current USD prices.
1372
1373
  *
1374
+ * Supplied-only reserves below their pool's same-asset dust threshold are
1375
+ * omitted. Reserves with active debt remain, with their supplied amount and
1376
+ * earned interest set to zero when the supplied balance is below the threshold.
1377
+ *
1373
1378
  * USD values are scaled to 27 decimals.
1374
1379
  *
1375
1380
  * @param profileId - The Liquidium profile principal text.
package/dist/index.d.ts CHANGED
@@ -1107,9 +1107,9 @@ interface Pool {
1107
1107
  decimals: bigint;
1108
1108
  /** Whether new pool activity is currently frozen. */
1109
1109
  frozen: boolean;
1110
- /** Total supplied amount in base units. */
1110
+ /** Current supplied amount in base units after applying the lending index. */
1111
1111
  totalSupply: bigint;
1112
- /** Total borrowed amount in base units. */
1112
+ /** Current borrowed amount in base units after applying the borrow index. */
1113
1113
  totalDebt: bigint;
1114
1114
  /** Currently available liquidity in base units. */
1115
1115
  availableLiquidity: bigint;
@@ -1334,10 +1334,11 @@ declare class PositionsModule {
1334
1334
  */
1335
1335
  getPosition(profileId: string, poolId: string): Promise<Position | null>;
1336
1336
  /**
1337
- * Lists all positions for a profile.
1337
+ * Lists visible positions for a profile. Supply balances below their pool's
1338
+ * same-asset dust threshold are hidden without removing active debt.
1338
1339
  *
1339
1340
  * @param profileId - The Liquidium profile principal text.
1340
- * @returns All positions currently associated with the requested profile.
1341
+ * @returns Visible positions currently associated with the requested profile.
1341
1342
  */
1342
1343
  listPositions(profileId: string): Promise<Position[]>;
1343
1344
  /**
@@ -1370,6 +1371,10 @@ declare class PositionsModule {
1370
1371
  * Returns the per-reserve breakdown of a profile's supplies and borrows,
1371
1372
  * joined with pool metadata, rates, and current USD prices.
1372
1373
  *
1374
+ * Supplied-only reserves below their pool's same-asset dust threshold are
1375
+ * omitted. Reserves with active debt remain, with their supplied amount and
1376
+ * earned interest set to zero when the supplied balance is below the threshold.
1377
+ *
1373
1378
  * USD values are scaled to 27 decimals.
1374
1379
  *
1375
1380
  * @param profileId - The Liquidium profile principal text.
package/dist/index.js CHANGED
@@ -5007,8 +5007,8 @@ var DECIMAL_BASE = 10;
5007
5007
  var PAIR_SEPARATOR = "_";
5008
5008
  var USDT_SYMBOL = "USDT";
5009
5009
  function mapDecodedPoolToPool(pool, rate) {
5010
- const totalSupply = pool.total_supply_at_last_sync;
5011
- const totalDebt = pool.total_debt_at_last_sync;
5010
+ const totalSupply = pool.total_supply_at_last_sync * pool.lending_index / RATE_SCALE;
5011
+ const totalDebt = pool.total_debt_at_last_sync * pool.borrow_index / RATE_SCALE;
5012
5012
  const availableLiquidity = totalSupply > totalDebt ? totalSupply - totalDebt : 0n;
5013
5013
  return {
5014
5014
  id: pool.principal.toString(),
@@ -5303,23 +5303,38 @@ var PositionsModule = class {
5303
5303
  }
5304
5304
  }
5305
5305
  /**
5306
- * Lists all positions for a profile.
5306
+ * Lists visible positions for a profile. Supply balances below their pool's
5307
+ * same-asset dust threshold are hidden without removing active debt.
5307
5308
  *
5308
5309
  * @param profileId - The Liquidium profile principal text.
5309
- * @returns All positions currently associated with the requested profile.
5310
+ * @returns Visible positions currently associated with the requested profile.
5310
5311
  */
5311
5312
  async listPositions(profileId) {
5312
5313
  try {
5313
5314
  const actor = createFlexibleLendingActor(this.canisterContext);
5314
5315
  const profilePrincipal = Principal.fromText(profileId);
5315
- const stats = await actor.get_profile_stats(profilePrincipal);
5316
+ const [stats, pools] = await Promise.all([
5317
+ actor.get_profile_stats(profilePrincipal),
5318
+ actor.list_pools()
5319
+ ]);
5316
5320
  const decodedStats = decodeFlexibleUserStats(stats);
5321
+ const dustThresholdsByPoolId = new Map(
5322
+ pools.map((pool) => [
5323
+ pool.principal.toText(),
5324
+ pool.same_asset_borrowing_dust_threshold
5325
+ ])
5326
+ );
5317
5327
  const positionViews = await Promise.all(
5318
5328
  decodedStats.positions.map(
5319
5329
  (position) => actor.get_position(profilePrincipal, position.pool_id)
5320
5330
  )
5321
5331
  );
5322
- return positionViews.map((result) => result[0]).filter((view) => view !== void 0).map(decodeFlexiblePositionView).filter((view) => view !== null).map(mapDecodedPositionViewToPosition);
5332
+ return positionViews.map((result) => result[0]).filter((view) => view !== void 0).map(decodeFlexiblePositionView).filter((view) => view !== null).map(mapDecodedPositionViewToPosition).map(
5333
+ (position) => getPositionWithSuppliedDustHidden(
5334
+ position,
5335
+ dustThresholdsByPoolId.get(position.poolId)
5336
+ )
5337
+ ).filter((position) => position !== null);
5323
5338
  } catch (error) {
5324
5339
  if (error instanceof LiquidiumError) {
5325
5340
  throw error;
@@ -5405,6 +5420,10 @@ var PositionsModule = class {
5405
5420
  * Returns the per-reserve breakdown of a profile's supplies and borrows,
5406
5421
  * joined with pool metadata, rates, and current USD prices.
5407
5422
  *
5423
+ * Supplied-only reserves below their pool's same-asset dust threshold are
5424
+ * omitted. Reserves with active debt remain, with their supplied amount and
5425
+ * earned interest set to zero when the supplied balance is below the threshold.
5426
+ *
5408
5427
  * USD values are scaled to 27 decimals.
5409
5428
  *
5410
5429
  * @param profileId - The Liquidium profile principal text.
@@ -5485,6 +5504,16 @@ var PositionsModule = class {
5485
5504
  return { amount: position.deposited, decimals: position.depositedDecimals };
5486
5505
  }
5487
5506
  };
5507
+ function getPositionWithSuppliedDustHidden(position, dustThreshold) {
5508
+ if (dustThreshold === void 0 || position.deposited >= dustThreshold) {
5509
+ return position;
5510
+ }
5511
+ const hasDebt = position.borrowed > 0n || position.debtInterest > 0n;
5512
+ if (!hasDebt) {
5513
+ return null;
5514
+ }
5515
+ return { ...position, deposited: 0n, earnedInterest: 0n };
5516
+ }
5488
5517
  function nativeAmountToUsdScaled(amount, nativeDecimals, priceUsd) {
5489
5518
  if (amount <= 0n || priceUsd <= 0) {
5490
5519
  return 0n;