@liquidium/client 0.6.0 → 0.7.0
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 +228 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +149 -26
- package/dist/index.d.ts +149 -26
- package/dist/index.js +221 -24
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1053,8 +1053,11 @@ function normalizeEvmAddress(address) {
|
|
|
1053
1053
|
// src/core/utils/time.ts
|
|
1054
1054
|
var MILLISECONDS_PER_SECOND = 1e3;
|
|
1055
1055
|
var SIGNATURE_VALIDITY_5_MINUTES_IN_SECONDS = 5n * 60n;
|
|
1056
|
+
function getCurrentUnixTimestampSeconds() {
|
|
1057
|
+
return BigInt(Math.floor(Date.now() / MILLISECONDS_PER_SECOND));
|
|
1058
|
+
}
|
|
1056
1059
|
function computeExpiryTimestampFromNow(signatureValidityInSeconds = SIGNATURE_VALIDITY_5_MINUTES_IN_SECONDS) {
|
|
1057
|
-
return
|
|
1060
|
+
return getCurrentUnixTimestampSeconds() + signatureValidityInSeconds;
|
|
1058
1061
|
}
|
|
1059
1062
|
|
|
1060
1063
|
// src/core/utils/variant.ts
|
|
@@ -1274,6 +1277,31 @@ var AccountsModule = class {
|
|
|
1274
1277
|
throw mapCanisterCallErrorToLiquidiumError("get_wallet_profile", error);
|
|
1275
1278
|
}
|
|
1276
1279
|
}
|
|
1280
|
+
/**
|
|
1281
|
+
* Checks whether a profile is registered with the protocol.
|
|
1282
|
+
*
|
|
1283
|
+
* Production profile registration always links an initial wallet, and the
|
|
1284
|
+
* protocol prevents removal of a profile's final wallet. This method uses
|
|
1285
|
+
* that invariant because the current canister API has no direct existence
|
|
1286
|
+
* query.
|
|
1287
|
+
*
|
|
1288
|
+
* @param profileId - The Liquidium profile principal text.
|
|
1289
|
+
* @returns `true` when the profile has at least one linked wallet.
|
|
1290
|
+
*/
|
|
1291
|
+
async profileExists(profileId) {
|
|
1292
|
+
try {
|
|
1293
|
+
const profilePrincipal = parseProfilePrincipal(profileId);
|
|
1294
|
+
const wallets = await createLendingActor(
|
|
1295
|
+
this.canisterContext
|
|
1296
|
+
).get_profile_wallets(profilePrincipal);
|
|
1297
|
+
return wallets.length > 0;
|
|
1298
|
+
} catch (error) {
|
|
1299
|
+
if (error instanceof LiquidiumError) {
|
|
1300
|
+
throw error;
|
|
1301
|
+
}
|
|
1302
|
+
throw mapCanisterCallErrorToLiquidiumError("get_profile_wallets", error);
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1277
1305
|
/**
|
|
1278
1306
|
* Returns the current nonce for a wallet address.
|
|
1279
1307
|
*
|
|
@@ -1379,6 +1407,17 @@ var AccountsModule = class {
|
|
|
1379
1407
|
function normalizeProfileAccount(account) {
|
|
1380
1408
|
return normalizeEvmAddress(account);
|
|
1381
1409
|
}
|
|
1410
|
+
function parseProfilePrincipal(profileId) {
|
|
1411
|
+
try {
|
|
1412
|
+
return Principal.fromText(profileId);
|
|
1413
|
+
} catch (error) {
|
|
1414
|
+
throw new LiquidiumError(
|
|
1415
|
+
LiquidiumErrorCode.VALIDATION_ERROR,
|
|
1416
|
+
`Invalid profile id: ${profileId}`,
|
|
1417
|
+
error
|
|
1418
|
+
);
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1382
1421
|
function createInitializeAccountMessage(expiryTimestamp, nonce) {
|
|
1383
1422
|
return `Liquidium: Initialize Account
|
|
1384
1423
|
|
|
@@ -1742,19 +1781,24 @@ var SdkApiQueryParam = {
|
|
|
1742
1781
|
to: "to"
|
|
1743
1782
|
};
|
|
1744
1783
|
var ACTIVITIES = `${SDK_API_V2_PATH}/activities`;
|
|
1784
|
+
var HISTORY_ACTIVITIES = `${SDK_API_V2_PATH}/history/activities`;
|
|
1745
1785
|
var HISTORY_USERS = `${SDK_API_V2_PATH}/history/users`;
|
|
1746
1786
|
var INFLOW = `${SDK_API_V2_PATH}/inflow`;
|
|
1747
1787
|
var SIMPLE_LOANS = `${SDK_API_V1_PATH}/instant-loans`;
|
|
1748
|
-
function buildHistoryUserTransactionsPath(
|
|
1749
|
-
const base = `${HISTORY_USERS}/${encodeURIComponent(
|
|
1788
|
+
function buildHistoryUserTransactionsPath(profileId, query) {
|
|
1789
|
+
const base = `${HISTORY_USERS}/${encodeURIComponent(profileId)}/transactions`;
|
|
1750
1790
|
const qs = query.toString();
|
|
1751
1791
|
return qs ? `${base}?${qs}` : base;
|
|
1752
1792
|
}
|
|
1753
|
-
function buildHistoryUserLiquidationsPath(
|
|
1754
|
-
const base = `${HISTORY_USERS}/${encodeURIComponent(
|
|
1793
|
+
function buildHistoryUserLiquidationsPath(profileId, query) {
|
|
1794
|
+
const base = `${HISTORY_USERS}/${encodeURIComponent(profileId)}/liquidations`;
|
|
1755
1795
|
const qs = query.toString();
|
|
1756
1796
|
return qs ? `${base}?${qs}` : base;
|
|
1757
1797
|
}
|
|
1798
|
+
function buildProtocolActivityPath(query) {
|
|
1799
|
+
const qs = query.toString();
|
|
1800
|
+
return qs ? `${HISTORY_ACTIVITIES}?${qs}` : HISTORY_ACTIVITIES;
|
|
1801
|
+
}
|
|
1758
1802
|
function buildActivitiesPath(request) {
|
|
1759
1803
|
const query = new URLSearchParams({
|
|
1760
1804
|
[SdkApiQueryParam.profileId]: request.profileId
|
|
@@ -2053,6 +2097,9 @@ function mapActivityTopUp(wire) {
|
|
|
2053
2097
|
}
|
|
2054
2098
|
|
|
2055
2099
|
// src/modules/history/history.ts
|
|
2100
|
+
var MIN_HISTORY_LIMIT = 1;
|
|
2101
|
+
var MAX_USER_HISTORY_LIMIT = 200;
|
|
2102
|
+
var MAX_PROTOCOL_ACTIVITY_LIMIT = 100;
|
|
2056
2103
|
var HistoryModule = class {
|
|
2057
2104
|
constructor(apiClient) {
|
|
2058
2105
|
this.apiClient = apiClient;
|
|
@@ -2070,11 +2117,11 @@ var HistoryModule = class {
|
|
|
2070
2117
|
/**
|
|
2071
2118
|
* Returns transaction history for a user.
|
|
2072
2119
|
*
|
|
2073
|
-
* @param
|
|
2120
|
+
* @param profileId - The Liquidium profile principal text.
|
|
2074
2121
|
* @param filters - Optional pool, operation, state, time range, and pagination filters.
|
|
2075
2122
|
* @returns Paginated user history entries.
|
|
2076
2123
|
*/
|
|
2077
|
-
async getUserTransactionHistory(
|
|
2124
|
+
async getUserTransactionHistory(profileId, filters = {}) {
|
|
2078
2125
|
const apiClient = this.requireApi();
|
|
2079
2126
|
const query = new URLSearchParams();
|
|
2080
2127
|
if (filters.cursor) {
|
|
@@ -2102,9 +2149,10 @@ var HistoryModule = class {
|
|
|
2102
2149
|
query.set(SdkApiQueryParam.to, filters.to);
|
|
2103
2150
|
}
|
|
2104
2151
|
if (filters.limit !== void 0) {
|
|
2152
|
+
validateHistoryLimit(filters.limit, MAX_USER_HISTORY_LIMIT);
|
|
2105
2153
|
query.set(SdkApiQueryParam.limit, String(filters.limit));
|
|
2106
2154
|
}
|
|
2107
|
-
const requestPath = buildHistoryUserTransactionsPath(
|
|
2155
|
+
const requestPath = buildHistoryUserTransactionsPath(profileId, query);
|
|
2108
2156
|
const response = await apiClient.get(requestPath);
|
|
2109
2157
|
return {
|
|
2110
2158
|
items: response.items.map(mapUserTransactionHistoryEntry),
|
|
@@ -2114,11 +2162,11 @@ var HistoryModule = class {
|
|
|
2114
2162
|
/**
|
|
2115
2163
|
* Returns liquidation history for a user.
|
|
2116
2164
|
*
|
|
2117
|
-
* @param
|
|
2165
|
+
* @param profileId - The Liquidium profile principal text.
|
|
2118
2166
|
* @param filters - Optional pool, time range, and pagination filters.
|
|
2119
2167
|
* @returns Paginated liquidation history entries.
|
|
2120
2168
|
*/
|
|
2121
|
-
async getLiquidationHistory(
|
|
2169
|
+
async getLiquidationHistory(profileId, filters = {}) {
|
|
2122
2170
|
const apiClient = this.requireApi();
|
|
2123
2171
|
const query = new URLSearchParams();
|
|
2124
2172
|
if (filters.cursor) {
|
|
@@ -2137,16 +2185,52 @@ var HistoryModule = class {
|
|
|
2137
2185
|
query.set(SdkApiQueryParam.to, filters.to);
|
|
2138
2186
|
}
|
|
2139
2187
|
if (filters.limit !== void 0) {
|
|
2188
|
+
validateHistoryLimit(filters.limit, MAX_USER_HISTORY_LIMIT);
|
|
2140
2189
|
query.set(SdkApiQueryParam.limit, String(filters.limit));
|
|
2141
2190
|
}
|
|
2142
|
-
const requestPath = buildHistoryUserLiquidationsPath(
|
|
2191
|
+
const requestPath = buildHistoryUserLiquidationsPath(profileId, query);
|
|
2143
2192
|
const response = await apiClient.get(requestPath);
|
|
2144
2193
|
return {
|
|
2145
2194
|
items: response.items.map(mapUserLiquidationHistoryEntry),
|
|
2146
2195
|
nextCursor: response.nextCursor
|
|
2147
2196
|
};
|
|
2148
2197
|
}
|
|
2198
|
+
/**
|
|
2199
|
+
* Returns recent protocol-wide lending activity across all users.
|
|
2200
|
+
*
|
|
2201
|
+
* @param filters - Optional pool, operation, and limit filters.
|
|
2202
|
+
* @returns Recent confirmed lending activity entries.
|
|
2203
|
+
*/
|
|
2204
|
+
async getProtocolActivity(filters = {}) {
|
|
2205
|
+
const apiClient = this.requireApi();
|
|
2206
|
+
const query = new URLSearchParams();
|
|
2207
|
+
if (filters.poolId) {
|
|
2208
|
+
query.set(SdkApiQueryParam.poolId, filters.poolId);
|
|
2209
|
+
}
|
|
2210
|
+
if (filters.operations?.length) {
|
|
2211
|
+
query.set(SdkApiQueryParam.operations, filters.operations.join(","));
|
|
2212
|
+
}
|
|
2213
|
+
if (filters.limit !== void 0) {
|
|
2214
|
+
validateHistoryLimit(filters.limit, MAX_PROTOCOL_ACTIVITY_LIMIT);
|
|
2215
|
+
query.set(SdkApiQueryParam.limit, String(filters.limit));
|
|
2216
|
+
}
|
|
2217
|
+
const requestPath = buildProtocolActivityPath(query);
|
|
2218
|
+
const response = await apiClient.get(requestPath);
|
|
2219
|
+
return response.items.map(mapProtocolActivityEntry);
|
|
2220
|
+
}
|
|
2149
2221
|
};
|
|
2222
|
+
function mapProtocolActivityEntry(item) {
|
|
2223
|
+
return {
|
|
2224
|
+
id: item.id,
|
|
2225
|
+
operation: item.operation,
|
|
2226
|
+
poolId: item.poolId,
|
|
2227
|
+
asset: item.asset,
|
|
2228
|
+
decimals: item.decimals,
|
|
2229
|
+
amount: parseBigInt(item.amount, "protocol activity amount"),
|
|
2230
|
+
timestamp: item.timestamp,
|
|
2231
|
+
txids: item.txids
|
|
2232
|
+
};
|
|
2233
|
+
}
|
|
2150
2234
|
function mapUserTransactionHistoryEntry(item) {
|
|
2151
2235
|
return {
|
|
2152
2236
|
id: item.id,
|
|
@@ -2169,7 +2253,12 @@ function mapUserLiquidationHistoryEntry(item) {
|
|
|
2169
2253
|
amount: parseBigInt(item.amount, "history user amount"),
|
|
2170
2254
|
poolId: item.poolId,
|
|
2171
2255
|
timestamp: item.timestamp,
|
|
2172
|
-
status:
|
|
2256
|
+
status: {
|
|
2257
|
+
operation: "liquidation",
|
|
2258
|
+
state: "completed",
|
|
2259
|
+
confirmations: null,
|
|
2260
|
+
requiredConfirmations: null
|
|
2261
|
+
},
|
|
2173
2262
|
txids: item.txids
|
|
2174
2263
|
};
|
|
2175
2264
|
}
|
|
@@ -2194,6 +2283,15 @@ function validateHistoryStateFilter(state) {
|
|
|
2194
2283
|
);
|
|
2195
2284
|
}
|
|
2196
2285
|
}
|
|
2286
|
+
function validateHistoryLimit(limit, maximumLimit) {
|
|
2287
|
+
if (Number.isInteger(limit) && limit >= MIN_HISTORY_LIMIT && limit <= maximumLimit) {
|
|
2288
|
+
return;
|
|
2289
|
+
}
|
|
2290
|
+
throw new LiquidiumError(
|
|
2291
|
+
LiquidiumErrorCode.VALIDATION_ERROR,
|
|
2292
|
+
`History limit must be an integer between ${MIN_HISTORY_LIMIT} and ${maximumLimit}`
|
|
2293
|
+
);
|
|
2294
|
+
}
|
|
2197
2295
|
|
|
2198
2296
|
// src/core/utils/inflow-subaccount.ts
|
|
2199
2297
|
var INFLOW_DEPOSIT_PREFIX = 1;
|
|
@@ -5149,9 +5247,78 @@ function mapOutflowTypeToStatusOperation(outflowType) {
|
|
|
5149
5247
|
return outflowType;
|
|
5150
5248
|
}
|
|
5151
5249
|
|
|
5250
|
+
// src/core/asset-metadata.ts
|
|
5251
|
+
var ASSET_METADATA = {
|
|
5252
|
+
[Asset.BTC]: {
|
|
5253
|
+
symbol: Asset.BTC,
|
|
5254
|
+
displayName: "Bitcoin"
|
|
5255
|
+
},
|
|
5256
|
+
[Asset.ETH]: {
|
|
5257
|
+
symbol: Asset.ETH,
|
|
5258
|
+
displayName: "Ethereum"
|
|
5259
|
+
},
|
|
5260
|
+
[Asset.ICP]: {
|
|
5261
|
+
symbol: Asset.ICP,
|
|
5262
|
+
displayName: "Internet Computer"
|
|
5263
|
+
},
|
|
5264
|
+
[Asset.USDC]: {
|
|
5265
|
+
symbol: Asset.USDC,
|
|
5266
|
+
displayName: "USD Coin"
|
|
5267
|
+
},
|
|
5268
|
+
[Asset.USDT]: {
|
|
5269
|
+
symbol: Asset.USDT,
|
|
5270
|
+
displayName: "Tether USD"
|
|
5271
|
+
}
|
|
5272
|
+
};
|
|
5273
|
+
function getAssetMetadata(asset) {
|
|
5274
|
+
return ASSET_METADATA[asset];
|
|
5275
|
+
}
|
|
5276
|
+
|
|
5152
5277
|
// src/core/rates.ts
|
|
5153
5278
|
var RATE_SCALE = 1000000000000000000000000000n;
|
|
5154
5279
|
var RATE_DECIMALS = BigInt(RATE_SCALE.toString().length - 1);
|
|
5280
|
+
var INTEREST_YEAR_365_DAYS_SECONDS = 31536000n;
|
|
5281
|
+
var SUPPLY_COMPOUNDING_INTERVAL_15_SECONDS = 15n;
|
|
5282
|
+
function estimateBorrowApy(borrowApr) {
|
|
5283
|
+
return estimateCompoundedApy(borrowApr, 1n);
|
|
5284
|
+
}
|
|
5285
|
+
function estimateSupplyApy(supplyApr) {
|
|
5286
|
+
return estimateCompoundedApy(
|
|
5287
|
+
supplyApr,
|
|
5288
|
+
SUPPLY_COMPOUNDING_INTERVAL_15_SECONDS
|
|
5289
|
+
);
|
|
5290
|
+
}
|
|
5291
|
+
function estimateCompoundedApy(apr, compoundingIntervalSeconds) {
|
|
5292
|
+
if (apr < 0n) {
|
|
5293
|
+
throw new RangeError("APR cannot be negative");
|
|
5294
|
+
}
|
|
5295
|
+
if (apr === 0n) {
|
|
5296
|
+
return 0n;
|
|
5297
|
+
}
|
|
5298
|
+
const periodsPerYear = INTEREST_YEAR_365_DAYS_SECONDS / compoundingIntervalSeconds;
|
|
5299
|
+
const ratePerPeriod = apr * compoundingIntervalSeconds / INTEREST_YEAR_365_DAYS_SECONDS;
|
|
5300
|
+
const annualGrowth = fixedPointPow(
|
|
5301
|
+
RATE_SCALE + ratePerPeriod,
|
|
5302
|
+
periodsPerYear
|
|
5303
|
+
);
|
|
5304
|
+
return annualGrowth - RATE_SCALE;
|
|
5305
|
+
}
|
|
5306
|
+
function fixedPointPow(base, exponent) {
|
|
5307
|
+
let remainingExponent = exponent;
|
|
5308
|
+
let currentBase = base;
|
|
5309
|
+
let result = RATE_SCALE;
|
|
5310
|
+
while (remainingExponent > 0n) {
|
|
5311
|
+
if (remainingExponent % 2n === 1n) {
|
|
5312
|
+
result = fixedPointMultiply(result, currentBase);
|
|
5313
|
+
}
|
|
5314
|
+
currentBase = fixedPointMultiply(currentBase, currentBase);
|
|
5315
|
+
remainingExponent /= 2n;
|
|
5316
|
+
}
|
|
5317
|
+
return result;
|
|
5318
|
+
}
|
|
5319
|
+
function fixedPointMultiply(left, right) {
|
|
5320
|
+
return (left * right + RATE_SCALE / 2n) / RATE_SCALE;
|
|
5321
|
+
}
|
|
5155
5322
|
|
|
5156
5323
|
// src/core/utils/asset-decimals.ts
|
|
5157
5324
|
var ASSET_NATIVE_DECIMALS = {
|
|
@@ -5178,12 +5345,14 @@ var DECIMAL_BASE = 10;
|
|
|
5178
5345
|
var PAIR_SEPARATOR = "_";
|
|
5179
5346
|
var USDT_SYMBOL = "USDT";
|
|
5180
5347
|
function mapDecodedPoolToPool(pool, rate) {
|
|
5348
|
+
const assetMetadata = getAssetMetadata(pool.asset);
|
|
5181
5349
|
const totalSupply = pool.total_supply_at_last_sync * pool.lending_index / RATE_SCALE;
|
|
5182
5350
|
const totalDebt = pool.total_debt_at_last_sync * pool.borrow_index / RATE_SCALE;
|
|
5183
5351
|
const availableLiquidity = totalSupply > totalDebt ? totalSupply - totalDebt : 0n;
|
|
5184
5352
|
return {
|
|
5185
5353
|
id: pool.principal.toString(),
|
|
5186
5354
|
asset: pool.asset,
|
|
5355
|
+
displayName: assetMetadata.displayName,
|
|
5187
5356
|
chain: pool.chain,
|
|
5188
5357
|
decimals: getAssetNativeDecimals(pool.asset),
|
|
5189
5358
|
frozen: pool.frozen,
|
|
@@ -5199,7 +5368,9 @@ function mapDecodedPoolToPool(pool, rate) {
|
|
|
5199
5368
|
reserveFactor: pool.reserve_factor,
|
|
5200
5369
|
rateDecimals: RATE_DECIMALS,
|
|
5201
5370
|
lendingRate: rate[1],
|
|
5371
|
+
estimatedLendingApy: estimateSupplyApy(rate[1]),
|
|
5202
5372
|
borrowingRate: rate[0],
|
|
5373
|
+
estimatedBorrowingApy: estimateBorrowApy(rate[0]),
|
|
5203
5374
|
utilizationRate: rate[2],
|
|
5204
5375
|
baseRate: pool.base_rate,
|
|
5205
5376
|
optimalUtilizationRate: pool.optimal_utilization_rate,
|
|
@@ -5233,7 +5404,9 @@ function mapGetPoolRateResponseToPoolRate(rate) {
|
|
|
5233
5404
|
return {
|
|
5234
5405
|
rateDecimals: RATE_DECIMALS,
|
|
5235
5406
|
borrowRate: rate[0],
|
|
5407
|
+
estimatedBorrowApy: estimateBorrowApy(rate[0]),
|
|
5236
5408
|
lendRate: rate[1],
|
|
5409
|
+
estimatedLendApy: estimateSupplyApy(rate[1]),
|
|
5237
5410
|
utilizationRate: rate[2]
|
|
5238
5411
|
};
|
|
5239
5412
|
}
|
|
@@ -5287,15 +5460,32 @@ var MarketModule = class {
|
|
|
5287
5460
|
}
|
|
5288
5461
|
}
|
|
5289
5462
|
/**
|
|
5290
|
-
* Returns the
|
|
5463
|
+
* Returns the current cached asset prices reported by the protocol.
|
|
5291
5464
|
*
|
|
5292
|
-
* @returns The
|
|
5465
|
+
* @returns The current protocol price map keyed by market asset symbol.
|
|
5293
5466
|
*/
|
|
5294
5467
|
async getAssetPrices() {
|
|
5468
|
+
return (await this.getAssetPriceSnapshot()).prices;
|
|
5469
|
+
}
|
|
5470
|
+
/**
|
|
5471
|
+
* Returns protocol prices with the time at which the SDK completed the fetch.
|
|
5472
|
+
*
|
|
5473
|
+
* `fetchedAt` is an SDK retrieval time, not an oracle observation timestamp.
|
|
5474
|
+
* The current lending canister price response does not expose the underlying
|
|
5475
|
+
* oracle timestamp.
|
|
5476
|
+
*
|
|
5477
|
+
* @returns Protocol prices and their SDK fetch timestamp.
|
|
5478
|
+
*/
|
|
5479
|
+
async getAssetPriceSnapshot() {
|
|
5295
5480
|
try {
|
|
5296
|
-
|
|
5481
|
+
const prices = mapGetPricesResponseToAssetPrices(
|
|
5297
5482
|
await createLendingActor(this.canisterContext).get_prices()
|
|
5298
5483
|
);
|
|
5484
|
+
const fetchedAtUnixSeconds = getCurrentUnixTimestampSeconds();
|
|
5485
|
+
return {
|
|
5486
|
+
prices,
|
|
5487
|
+
fetchedAt: fetchedAtUnixSeconds
|
|
5488
|
+
};
|
|
5299
5489
|
} catch (error) {
|
|
5300
5490
|
if (error instanceof LiquidiumError) {
|
|
5301
5491
|
throw error;
|
|
@@ -5397,6 +5587,10 @@ function decodeSupportedFlexiblePools(rawPools) {
|
|
|
5397
5587
|
return decodedPools;
|
|
5398
5588
|
}
|
|
5399
5589
|
|
|
5590
|
+
// src/modules/positions/health-factor.ts
|
|
5591
|
+
var HEALTH_FACTOR_SCALE = 1000n;
|
|
5592
|
+
var HEALTH_FACTOR_DECIMALS = 3n;
|
|
5593
|
+
|
|
5400
5594
|
// src/modules/positions/mappers.ts
|
|
5401
5595
|
var USD_VALUE_SCALE_DECIMALS = 27n;
|
|
5402
5596
|
function mapDecodedPositionViewToPosition(view) {
|
|
@@ -5525,11 +5719,13 @@ var PositionsModule = class {
|
|
|
5525
5719
|
const [healthFactor, userStatsRecord] = await createFlexibleLendingActor(
|
|
5526
5720
|
this.canisterContext
|
|
5527
5721
|
).get_health_factor(Principal.fromText(profileId));
|
|
5722
|
+
const userStats = mapDecodedUserStatsToUserStats(
|
|
5723
|
+
decodeFlexibleUserStats(userStatsRecord)
|
|
5724
|
+
);
|
|
5528
5725
|
return {
|
|
5529
|
-
healthFactor,
|
|
5530
|
-
|
|
5531
|
-
|
|
5532
|
-
)
|
|
5726
|
+
healthFactor: userStats.debt === 0n ? null : healthFactor,
|
|
5727
|
+
healthFactorDecimals: HEALTH_FACTOR_DECIMALS,
|
|
5728
|
+
userStats
|
|
5533
5729
|
};
|
|
5534
5730
|
} catch (error) {
|
|
5535
5731
|
if (error instanceof LiquidiumError) {
|
|
@@ -5569,7 +5765,7 @@ var PositionsModule = class {
|
|
|
5569
5765
|
* @returns Derived position summary for the requested profile.
|
|
5570
5766
|
*/
|
|
5571
5767
|
async getUserPositionSummary(profileId) {
|
|
5572
|
-
const { healthFactor, userStats } = await this.getHealthFactor(profileId);
|
|
5768
|
+
const { healthFactor, healthFactorDecimals, userStats } = await this.getHealthFactor(profileId);
|
|
5573
5769
|
const collateral = userStats.collateral;
|
|
5574
5770
|
const debt = userStats.debt;
|
|
5575
5771
|
const maxBorrowableUsd = userStats.borrowingPower.maxBorrowableUsd;
|
|
@@ -5585,7 +5781,8 @@ var PositionsModule = class {
|
|
|
5585
5781
|
currentLtvBps,
|
|
5586
5782
|
weightedMaxLtvBps: userStats.borrowingPower.weightedMaxLtv,
|
|
5587
5783
|
weightedLiquidationThresholdBps: userStats.weightedLiquidationThreshold,
|
|
5588
|
-
healthFactor
|
|
5784
|
+
healthFactor,
|
|
5785
|
+
healthFactorDecimals
|
|
5589
5786
|
};
|
|
5590
5787
|
}
|
|
5591
5788
|
/**
|
|
@@ -6869,9 +7066,9 @@ function isSimpleLoanDepositExpired(input) {
|
|
|
6869
7066
|
if (input.expiryTimestamp === null) {
|
|
6870
7067
|
return false;
|
|
6871
7068
|
}
|
|
6872
|
-
return input.expiryTimestamp <=
|
|
7069
|
+
return input.expiryTimestamp <= getCurrentUnixTimestampSeconds2();
|
|
6873
7070
|
}
|
|
6874
|
-
function
|
|
7071
|
+
function getCurrentUnixTimestampSeconds2() {
|
|
6875
7072
|
return BigInt(Math.floor(Date.now() / MILLISECONDS_PER_SECOND3));
|
|
6876
7073
|
}
|
|
6877
7074
|
function deriveDepositExpiryTimestamp(input) {
|
|
@@ -7472,6 +7669,6 @@ function resolveEvmReadClient(config) {
|
|
|
7472
7669
|
});
|
|
7473
7670
|
}
|
|
7474
7671
|
|
|
7475
|
-
export { AccountsModule, ActivitiesModule, ActivityFilter, Asset, CK_ETH_DEPOSIT_CONTRACT_ADDRESS, Chain, Environment, EvmSupplyApprovalStrategy, HistoryModule, LendingModule, LiquidiumAccountType, LiquidiumClient, LiquidiumError, LiquidiumErrorCode, MIN_BORROW_AMOUNTS_BY_ASSET, MIN_DEPOSIT_AMOUNTS_BY_ASSET, MIN_WITHDRAW_AMOUNTS_BY_ASSET, MarketModule, OutflowType, PositionsModule, QuoteModule, QuoteValidationErrorCode, QuoteWarningCode, RATE_DECIMALS, RATE_SCALE, SimpleLoanCreatedError, SimpleLoansModule, SupplyAction, SupplyPlanType, USDC_CONTRACT_ADDRESS, USDT_CONTRACT_ADDRESS, WalletActionKind, WalletExecutionKind, createTransferErc20Transaction, executeWith, getMinimumBorrowAmount, getMinimumDepositAmount, getMinimumWithdrawAmount, intFromPublicId, isAssetIdentifier, publicIdFromInt };
|
|
7672
|
+
export { ASSET_METADATA, AccountsModule, ActivitiesModule, ActivityFilter, Asset, CK_ETH_DEPOSIT_CONTRACT_ADDRESS, Chain, Environment, EvmSupplyApprovalStrategy, HEALTH_FACTOR_DECIMALS, HEALTH_FACTOR_SCALE, HistoryModule, INTEREST_YEAR_365_DAYS_SECONDS, LendingModule, LiquidiumAccountType, LiquidiumClient, LiquidiumError, LiquidiumErrorCode, MIN_BORROW_AMOUNTS_BY_ASSET, MIN_DEPOSIT_AMOUNTS_BY_ASSET, MIN_WITHDRAW_AMOUNTS_BY_ASSET, MarketModule, OutflowType, PositionsModule, QuoteModule, QuoteValidationErrorCode, QuoteWarningCode, RATE_DECIMALS, RATE_SCALE, SUPPLY_COMPOUNDING_INTERVAL_15_SECONDS, SimpleLoanCreatedError, SimpleLoansModule, SupplyAction, SupplyPlanType, USDC_CONTRACT_ADDRESS, USDT_CONTRACT_ADDRESS, WalletActionKind, WalletExecutionKind, createTransferErc20Transaction, estimateBorrowApy, estimateSupplyApy, executeWith, getAssetMetadata, getMinimumBorrowAmount, getMinimumDepositAmount, getMinimumWithdrawAmount, intFromPublicId, isAssetIdentifier, publicIdFromInt };
|
|
7476
7673
|
//# sourceMappingURL=index.js.map
|
|
7477
7674
|
//# sourceMappingURL=index.js.map
|