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