@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.cjs +35 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -4
- package/dist/index.d.ts +9 -4
- package/dist/index.js +35 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5009,8 +5009,8 @@ var DECIMAL_BASE = 10;
|
|
|
5009
5009
|
var PAIR_SEPARATOR = "_";
|
|
5010
5010
|
var USDT_SYMBOL = "USDT";
|
|
5011
5011
|
function mapDecodedPoolToPool(pool, rate) {
|
|
5012
|
-
const totalSupply = pool.total_supply_at_last_sync;
|
|
5013
|
-
const totalDebt = pool.total_debt_at_last_sync;
|
|
5012
|
+
const totalSupply = pool.total_supply_at_last_sync * pool.lending_index / RATE_SCALE;
|
|
5013
|
+
const totalDebt = pool.total_debt_at_last_sync * pool.borrow_index / RATE_SCALE;
|
|
5014
5014
|
const availableLiquidity = totalSupply > totalDebt ? totalSupply - totalDebt : 0n;
|
|
5015
5015
|
return {
|
|
5016
5016
|
id: pool.principal.toString(),
|
|
@@ -5305,23 +5305,38 @@ var PositionsModule = class {
|
|
|
5305
5305
|
}
|
|
5306
5306
|
}
|
|
5307
5307
|
/**
|
|
5308
|
-
* Lists
|
|
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
|
|
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
|
|
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;
|