@suilend/sdk 13.8.0-next.g33ed981 → 13.8.0-next.gd1e5f5b
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/lib/initialize.d.ts +2 -15
- package/lib/initialize.js +11 -42
- package/package.json +1 -1
- package/parsers/lendingMarket.d.ts +1 -2
- package/parsers/lendingMarket.js +2 -9
- package/utils/simulate.d.ts +5 -15
- package/utils/simulate.js +9 -10
package/lib/initialize.d.ts
CHANGED
|
@@ -158,7 +158,6 @@ export type InitializePriceInputs = {
|
|
|
158
158
|
export declare const getInitializePriceInputs: (lendingMarkets: {
|
|
159
159
|
reserves: Reserve<string>[];
|
|
160
160
|
}[], nowMs: number) => InitializePriceInputs;
|
|
161
|
-
type ConfidenceByCoinType = simulate.ConfidenceByCoinType;
|
|
162
161
|
export declare const initializeSuilendAll: (suiGrpcClient: SuiGrpcClient, markets: InitializeSuilendMarket[], fallbackPythEndpoint?: string, options?: InitializeSuilendOptions) => Promise<{
|
|
163
162
|
lendingMarket: {
|
|
164
163
|
version: bigint;
|
|
@@ -411,10 +410,6 @@ export declare const initializeSuilendAll: (suiGrpcClient: SuiGrpcClient, market
|
|
|
411
410
|
description: string;
|
|
412
411
|
totalDeposits: BigNumber;
|
|
413
412
|
}>;
|
|
414
|
-
confidenceByCoinType: Map<string, {
|
|
415
|
-
readonly share: simulate.ConfidenceShare | undefined;
|
|
416
|
-
readonly kBps: BigNumber;
|
|
417
|
-
}>;
|
|
418
413
|
reserveCoinTypes: string[];
|
|
419
414
|
reserveCoinMetadataMap: Record<string, import("@suilend/sui-core").Token>;
|
|
420
415
|
rewardCoinTypes: string[];
|
|
@@ -674,10 +669,6 @@ export declare const initializeSuilendWithRewardsAll: (suiGrpcClient: SuiGrpcCli
|
|
|
674
669
|
description: string;
|
|
675
670
|
totalDeposits: BigNumber;
|
|
676
671
|
}>;
|
|
677
|
-
confidenceByCoinType: Map<string, {
|
|
678
|
-
readonly share: simulate.ConfidenceShare | undefined;
|
|
679
|
-
readonly kBps: BigNumber;
|
|
680
|
-
}>;
|
|
681
672
|
reserveCoinTypes: string[];
|
|
682
673
|
reserveCoinMetadataMap: Record<string, import("@suilend/sui-core").Token>;
|
|
683
674
|
rewardCoinTypes: string[];
|
|
@@ -936,10 +927,6 @@ export declare const initializeSuilend: (suiGrpcClient: SuiGrpcClient, suilendCl
|
|
|
936
927
|
description: string;
|
|
937
928
|
totalDeposits: BigNumber;
|
|
938
929
|
}>;
|
|
939
|
-
confidenceByCoinType: Map<string, {
|
|
940
|
-
readonly share: simulate.ConfidenceShare | undefined;
|
|
941
|
-
readonly kBps: BigNumber;
|
|
942
|
-
}>;
|
|
943
930
|
reserveCoinTypes: string[];
|
|
944
931
|
reserveCoinMetadataMap: Record<string, import("@suilend/sui-core").Token>;
|
|
945
932
|
rewardCoinTypes: string[];
|
|
@@ -965,7 +952,7 @@ export type OwnedObligations = {
|
|
|
965
952
|
obligationErrors: Record<string, unknown>;
|
|
966
953
|
};
|
|
967
954
|
export declare const fetchOwnedObligations: (suiGrpcClient: SuiGrpcClient, address: string) => Promise<OwnedObligations>;
|
|
968
|
-
export declare const parseOwnedObligations: (owned: OwnedObligations, suilendClient: SuilendClient, refreshedRawReserves: Reserve<string>[], reserveMap: Record<string, ParsedReserve
|
|
955
|
+
export declare const parseOwnedObligations: (owned: OwnedObligations, suilendClient: SuilendClient, refreshedRawReserves: Reserve<string>[], reserveMap: Record<string, ParsedReserve>) => {
|
|
969
956
|
strategyOwnerCaps: StrategyOwnerCap[];
|
|
970
957
|
strategyObligations: {
|
|
971
958
|
id: string;
|
|
@@ -1487,7 +1474,7 @@ export declare const parseOwnedObligations: (owned: OwnedObligations, suilendCli
|
|
|
1487
1474
|
minPriceBorrowLimit: BigNumber;
|
|
1488
1475
|
}[];
|
|
1489
1476
|
};
|
|
1490
|
-
export declare const initializeObligations: (suiGrpcClient: SuiGrpcClient, suilendClient: SuilendClient, refreshedRawReserves: Reserve<string>[], reserveMap: Record<string, ParsedReserve>, address?: string
|
|
1477
|
+
export declare const initializeObligations: (suiGrpcClient: SuiGrpcClient, suilendClient: SuilendClient, refreshedRawReserves: Reserve<string>[], reserveMap: Record<string, ParsedReserve>, address?: string) => Promise<{
|
|
1491
1478
|
strategyOwnerCaps: StrategyOwnerCap[];
|
|
1492
1479
|
strategyObligations: {
|
|
1493
1480
|
id: string;
|
package/lib/initialize.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { normalizeStructTag, parseStructTag } from "@mysten/sui/utils";
|
|
2
2
|
import BigNumber from "bignumber.js";
|
|
3
|
-
import pLimit from "p-limit";
|
|
4
3
|
import { NORMALIZED_ALKIMI_COINTYPE, NORMALIZED_AUSD_COINTYPE, NORMALIZED_BLUE_COINTYPE, NORMALIZED_BUCK_COINTYPE, NORMALIZED_DEEP_COINTYPE, NORMALIZED_DMC_COINTYPE, NORMALIZED_FUD_COINTYPE, NORMALIZED_HAEDAL_COINTYPE, NORMALIZED_HIPPO_COINTYPE, NORMALIZED_IKA_COINTYPE, NORMALIZED_KOBAN_COINTYPE, NORMALIZED_LBTC_COINTYPE, NORMALIZED_NS_COINTYPE, NORMALIZED_SEND_COINTYPE, NORMALIZED_SEND_POINTS_S1_COINTYPE, NORMALIZED_SEND_POINTS_S2_COINTYPE, NORMALIZED_SOL_COINTYPE, NORMALIZED_SUI_COINTYPE, NORMALIZED_UP_COINTYPE, NORMALIZED_USDB_COINTYPE, NORMALIZED_USDC_COINTYPE, NORMALIZED_USDsui_COINTYPE, NORMALIZED_WAL_COINTYPE, NORMALIZED_WBTC_COINTYPE, NORMALIZED_WETH_COINTYPE, NORMALIZED_XAUm_COINTYPE, NORMALIZED_eEARN_COINTYPE, NORMALIZED_eTHIRD_COINTYPE, NORMALIZED_flSUI_COINTYPE, NORMALIZED_fpSUI_COINTYPE, NORMALIZED_fudSUI_COINTYPE, NORMALIZED_iSUI_COINTYPE, NORMALIZED_jugSUI_COINTYPE, NORMALIZED_kSUI_COINTYPE, NORMALIZED_mSUI_COINTYPE, NORMALIZED_mUSD_COINTYPE, NORMALIZED_oshiSUI_COINTYPE, NORMALIZED_sSUI_COINTYPE, NORMALIZED_sdeUSD_COINTYPE, NORMALIZED_stratSUI_COINTYPE, NORMALIZED_suiETH_COINTYPE, NORMALIZED_suiUSDT_COINTYPE, NORMALIZED_suiUSDe_COINTYPE, NORMALIZED_suiWBTC_COINTYPE, NORMALIZED_trevinSUI_COINTYPE, NORMALIZED_upSUI_COINTYPE, NORMALIZED_wUSDC_COINTYPE, NORMALIZED_wUSDT_COINTYPE, NORMALIZED_xBTC_COINTYPE, NORMALIZED_yapSUI_COINTYPE, TEMPORARY_PYTH_PRICE_FEED_COINTYPES, getCoinMetadataMapPartial, getPrices, isSendPoints, isSteammPoints, } from "@suilend/sui-core";
|
|
5
4
|
import { phantom } from "../_generated/_framework/reified.js";
|
|
6
5
|
import { PACKAGE_ID } from "../_generated/suilend/index.js";
|
|
@@ -311,34 +310,7 @@ const fillRewardPriceMap = (rewardPriceMap, reservelessActiveRewardCoinTypes, ca
|
|
|
311
310
|
}
|
|
312
311
|
return rewardPriceMap;
|
|
313
312
|
};
|
|
314
|
-
const
|
|
315
|
-
const confidenceReadLimit = pLimit(8);
|
|
316
|
-
const configConfidenceMultiplierBps = (suiGrpcClient, bagId) => {
|
|
317
|
-
const cached = kBpsByConfigBagId.get(bagId);
|
|
318
|
-
if (cached)
|
|
319
|
-
return cached;
|
|
320
|
-
const read = confidenceReadLimit(() => SuilendClient.getReserveConfidenceMultiplierBps(suiGrpcClient, bagId));
|
|
321
|
-
kBpsByConfigBagId.set(bagId, read);
|
|
322
|
-
read.catch(() => kBpsByConfigBagId.delete(bagId));
|
|
323
|
-
return read;
|
|
324
|
-
};
|
|
325
|
-
const reserveConfidenceMultipliers = (suiGrpcClient, reserves) => Promise.all(reserves.map(async (reserve) => {
|
|
326
|
-
const { id: bagId, size } = reserve.config.element
|
|
327
|
-
.additionalFields;
|
|
328
|
-
const kBps = BigInt(size) === BigInt(0)
|
|
329
|
-
? new BigNumber(0)
|
|
330
|
-
: await configConfidenceMultiplierBps(suiGrpcClient, bagId);
|
|
331
|
-
return [normalizeStructTag(reserve.coinType), kBps];
|
|
332
|
-
})).then((entries) => new Map(entries));
|
|
333
|
-
const reserveConfidenceByCoinType = async (suiGrpcClient, reserves, kBpsByCoinType) => new Map(await Promise.all(reserves.map(async (reserve) => {
|
|
334
|
-
const coinType = normalizeStructTag(reserve.coinType);
|
|
335
|
-
const kBps = kBpsByCoinType.get(coinType) ?? new BigNumber(0);
|
|
336
|
-
const share = kBps.isZero() || simulate.isRefreshedFromFeed(reserve)
|
|
337
|
-
? undefined
|
|
338
|
-
: await confidenceReadLimit(() => SuilendClient.getReserveConfidenceShare(suiGrpcClient, reserve.id));
|
|
339
|
-
return [coinType, { share, kBps }];
|
|
340
|
-
})));
|
|
341
|
-
const initializeSuilendMarkets = async (suiGrpcClient, markets, fallbackPythEndpoint, options, includeRewards) => {
|
|
313
|
+
const initializeSuilendMarkets = async (markets, fallbackPythEndpoint, options, includeRewards) => {
|
|
342
314
|
const nowMs = Date.now();
|
|
343
315
|
const nowS = Math.floor(nowMs / 1000);
|
|
344
316
|
const fetchPrices = options?.fetchPrices ?? getPrices;
|
|
@@ -358,7 +330,7 @@ const initializeSuilendMarkets = async (suiGrpcClient, markets, fallbackPythEndp
|
|
|
358
330
|
});
|
|
359
331
|
const coinTypesByMarket = reservesByMarket.map(({ withoutTemporaryPythPriceFeeds, withTemporaryPythPriceFeeds }) => marketCoinTypes([...withoutTemporaryPythPriceFeeds, ...withTemporaryPythPriceFeeds], nowMs));
|
|
360
332
|
const reservelessActiveRewardCoinTypesByMarket = coinTypesByMarket.map(reservelessActiveRewardCoinTypes);
|
|
361
|
-
const [[refreshedWithoutTemporaryByMarket, fabricatedPriceCoinTypesByMarket], coinMetadataByMarket, rewardUsdPrices,
|
|
333
|
+
const [[refreshedWithoutTemporaryByMarket, fabricatedPriceCoinTypesByMarket], coinMetadataByMarket, rewardUsdPrices,] = await Promise.all([
|
|
362
334
|
Promise.all([
|
|
363
335
|
resolvePythConnection(options?.pythConnection, fallbackPythEndpoint, options?.pythConnectionConfig).then((pythConnection) => refreshReservesForInitializeAll(reservesByMarket.map((r) => r.withoutTemporaryPythPriceFeeds), pythConnection, options?.tolerateMissingPriceFeeds)),
|
|
364
336
|
priceTemporaryPythFeedReservesAll(reservesByMarket.map((r) => r.withTemporaryPythPriceFeeds), fetchPrices),
|
|
@@ -374,7 +346,6 @@ const initializeSuilendMarkets = async (suiGrpcClient, markets, fallbackPythEndp
|
|
|
374
346
|
return {};
|
|
375
347
|
})
|
|
376
348
|
: Promise.resolve({}),
|
|
377
|
-
Promise.all(markets.map(({ suilendClient }) => reserveConfidenceMultipliers(suiGrpcClient, suilendClient.lendingMarket.reserves))),
|
|
378
349
|
]);
|
|
379
350
|
const prepared = markets.map(({ suilendClient, lendingMarketMetadata }, index) => {
|
|
380
351
|
const refreshedRawReserves = [
|
|
@@ -408,7 +379,6 @@ const initializeSuilendMarkets = async (suiGrpcClient, markets, fallbackPythEndp
|
|
|
408
379
|
...coinTypesByMarket[index],
|
|
409
380
|
};
|
|
410
381
|
});
|
|
411
|
-
const confidenceByMarket = await Promise.all(prepared.map(({ refreshedRawReserves }, index) => reserveConfidenceByCoinType(suiGrpcClient, refreshedRawReserves, kBpsByMarket[index])));
|
|
412
382
|
const initialized = prepared.map(({ suilendClient, lendingMarketMetadata, refreshedRawReserves, unpricedCoinTypes, uniqueReserveCoinTypes, uniqueRewardCoinTypes, uniqueActiveRewardsCoinTypes, }, index) => {
|
|
413
383
|
const { coinMetadataMap, reserveCoinMetadataMap, rewardCoinMetadataMap } = coinMetadataByMarket[index];
|
|
414
384
|
// const walReserve = refreshedRawReserves.find(
|
|
@@ -421,7 +391,7 @@ const initializeSuilendMarkets = async (suiGrpcClient, markets, fallbackPythEndp
|
|
|
421
391
|
// (walReserve.price.value as bigint) = walPrice;
|
|
422
392
|
// (walReserve.smoothedPrice.value as bigint) = walPrice;
|
|
423
393
|
// }
|
|
424
|
-
const lendingMarket = parseLendingMarket(suilendClient.lendingMarket, refreshedRawReserves, coinMetadataMap, nowS, lendingMarketMetadata
|
|
394
|
+
const lendingMarket = parseLendingMarket(suilendClient.lendingMarket, refreshedRawReserves, coinMetadataMap, nowS, lendingMarketMetadata);
|
|
425
395
|
const reserveOrder = resolveReserveOrder(lendingMarket.id, lendingMarketMetadata);
|
|
426
396
|
if (reserveOrder) {
|
|
427
397
|
lendingMarket.reserves = sortReservesByOrder(lendingMarket.reserves, reserveOrder);
|
|
@@ -433,7 +403,6 @@ const initializeSuilendMarkets = async (suiGrpcClient, markets, fallbackPythEndp
|
|
|
433
403
|
refreshedRawReserves,
|
|
434
404
|
unpricedCoinTypes,
|
|
435
405
|
reserveMap,
|
|
436
|
-
confidenceByCoinType: confidenceByMarket[index],
|
|
437
406
|
reserveCoinTypes: uniqueReserveCoinTypes,
|
|
438
407
|
reserveCoinMetadataMap,
|
|
439
408
|
rewardCoinTypes: uniqueRewardCoinTypes,
|
|
@@ -447,11 +416,11 @@ const initializeSuilendMarkets = async (suiGrpcClient, markets, fallbackPythEndp
|
|
|
447
416
|
return { initialized, rewardPriceMaps };
|
|
448
417
|
};
|
|
449
418
|
export const initializeSuilendAll = async (suiGrpcClient, markets, fallbackPythEndpoint, options) => {
|
|
450
|
-
const { initialized } = await initializeSuilendMarkets(
|
|
419
|
+
const { initialized } = await initializeSuilendMarkets(markets, fallbackPythEndpoint, options, false);
|
|
451
420
|
return initialized;
|
|
452
421
|
};
|
|
453
422
|
export const initializeSuilendWithRewardsAll = async (suiGrpcClient, markets, fallbackPythEndpoint, options) => {
|
|
454
|
-
const { initialized, rewardPriceMaps } = await initializeSuilendMarkets(
|
|
423
|
+
const { initialized, rewardPriceMaps } = await initializeSuilendMarkets(markets, fallbackPythEndpoint, options, true);
|
|
455
424
|
return initialized.map((market, index) => ({
|
|
456
425
|
...market,
|
|
457
426
|
rewardPriceMap: rewardPriceMaps[index],
|
|
@@ -549,9 +518,9 @@ const obligationIdsOf = ({ strategyOwnerCaps, obligationOwnerCaps, }) => [
|
|
|
549
518
|
...strategyOwnerCaps.map((soc) => soc.obligationId),
|
|
550
519
|
...obligationOwnerCaps.map((ownerCap) => ownerCap.obligationId),
|
|
551
520
|
];
|
|
552
|
-
const parseMarketObligations = (rawObligations, { strategyOwnerCaps, obligationOwnerCaps }, refreshedRawReserves, reserveMap
|
|
521
|
+
const parseMarketObligations = (rawObligations, { strategyOwnerCaps, obligationOwnerCaps }, refreshedRawReserves, reserveMap) => {
|
|
553
522
|
const obligations = rawObligations
|
|
554
|
-
.map((rawObligation) => simulate.refreshObligation(rawObligation, refreshedRawReserves
|
|
523
|
+
.map((rawObligation) => simulate.refreshObligation(rawObligation, refreshedRawReserves))
|
|
555
524
|
.map((refreshedObligation) => parseObligation(refreshedObligation, reserveMap, strategyOwnerCaps.some((soc) => soc.obligationId === refreshedObligation.id)))
|
|
556
525
|
.sort((a, b) => +b.netValueUsd.minus(a.netValueUsd));
|
|
557
526
|
const strategyObligations = obligations.filter((o) => strategyOwnerCaps.some((soc) => soc.obligationId === o.id));
|
|
@@ -599,7 +568,7 @@ export const fetchOwnedObligations = async (suiGrpcClient, address) => {
|
|
|
599
568
|
obligationErrors,
|
|
600
569
|
};
|
|
601
570
|
};
|
|
602
|
-
export const parseOwnedObligations = (owned, suilendClient, refreshedRawReserves, reserveMap
|
|
571
|
+
export const parseOwnedObligations = (owned, suilendClient, refreshedRawReserves, reserveMap) => {
|
|
603
572
|
const marketCaps = selectMarketCaps(owned, suilendClient);
|
|
604
573
|
const obligationsById = new Map(owned.obligations.map((obligation) => [obligation.id, obligation]));
|
|
605
574
|
const rawObligations = obligationIdsOf(marketCaps).map((obligationId) => {
|
|
@@ -610,9 +579,9 @@ export const parseOwnedObligations = (owned, suilendClient, refreshedRawReserves
|
|
|
610
579
|
throw owned.obligationErrors[obligationId];
|
|
611
580
|
throw new Error(`Obligation ${obligationId} is not in the owned obligations`);
|
|
612
581
|
});
|
|
613
|
-
return parseMarketObligations(rawObligations, marketCaps, refreshedRawReserves, reserveMap
|
|
582
|
+
return parseMarketObligations(rawObligations, marketCaps, refreshedRawReserves, reserveMap);
|
|
614
583
|
};
|
|
615
|
-
export const initializeObligations = async (suiGrpcClient, suilendClient, refreshedRawReserves, reserveMap, address
|
|
584
|
+
export const initializeObligations = async (suiGrpcClient, suilendClient, refreshedRawReserves, reserveMap, address) => {
|
|
616
585
|
if (!address)
|
|
617
586
|
return {
|
|
618
587
|
strategyOwnerCaps: [],
|
|
@@ -622,5 +591,5 @@ export const initializeObligations = async (suiGrpcClient, suilendClient, refres
|
|
|
622
591
|
};
|
|
623
592
|
const marketCaps = selectMarketCaps(await listOwnedCaps(suiGrpcClient, address, hasStrategies(suilendClient)), suilendClient);
|
|
624
593
|
const rawObligations = await SuilendClient.getObligations(obligationIdsOf(marketCaps), suilendClient.lendingMarket.$typeArgs, suiGrpcClient);
|
|
625
|
-
return parseMarketObligations(rawObligations, marketCaps, refreshedRawReserves, reserveMap
|
|
594
|
+
return parseMarketObligations(rawObligations, marketCaps, refreshedRawReserves, reserveMap);
|
|
626
595
|
};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sdk","version":"13.8.0-next.
|
|
1
|
+
{"name":"@suilend/sdk","version":"13.8.0-next.gd1e5f5b","private":false,"description":"A TypeScript SDK for interacting with the Suilend program","author":"Suilend","license":"MIT","main":"./index.js","exports":{".":"./index.js","./client":"./client.js","./mmt":"./mmt.js","./strategies":"./strategies.js","./api/events":"./api/events.js","./api":"./api/index.js","./lib/constants":"./lib/constants.js","./lib":"./lib/index.js","./lib/initialize":"./lib/initialize.js","./lib/liquidityMining":"./lib/liquidityMining.js","./lib/proCompatible":"./lib/proCompatible.js","./lib/pyth":"./lib/pyth.js","./lib/strategyOwnerCap":"./lib/strategyOwnerCap.js","./lib/transactions":"./lib/transactions.js","./lib/types":"./lib/types.js","./margin":"./margin/index.js","./parsers/apiReserveAssetDataEvent":"./parsers/apiReserveAssetDataEvent.js","./parsers":"./parsers/index.js","./parsers/lendingMarket":"./parsers/lendingMarket.js","./parsers/obligation":"./parsers/obligation.js","./parsers/rateLimiter":"./parsers/rateLimiter.js","./parsers/reserve":"./parsers/reserve.js","./swap":"./swap/index.js","./swap/quote":"./swap/quote.js","./swap/transaction":"./swap/transaction.js","./utils/events":"./utils/events.js","./utils/feedId":"./utils/feedId.js","./utils":"./utils/index.js","./utils/interpolate":"./utils/interpolate.js","./utils/obligation":"./utils/obligation.js","./utils/priceGuard":"./utils/priceGuard.js","./utils/simulate":"./utils/simulate.js","./_generated/_envs":"./_generated/_envs/index.js","./_generated/_envs/mainnet":"./_generated/_envs/mainnet.js","./_generated/_framework/env":"./_generated/_framework/env.js","./_generated/_framework/reified":"./_generated/_framework/reified.js","./_generated/_framework/util":"./_generated/_framework/util.js","./_generated/_framework/vector":"./_generated/_framework/vector.js","./_generated/suilend":"./_generated/suilend/index.js","./margin/margin/admin_cap":"./margin/margin/admin_cap.js","./margin/margin/market":"./margin/margin/market.js","./margin/margin/permissions":"./margin/margin/permissions.js","./margin/margin/position":"./margin/margin/position.js","./margin/margin/router":"./margin/margin/router.js","./margin/margin/version":"./margin/margin/version.js","./margin/utils":"./margin/utils/index.js","./_generated/suilend/cell/structs":"./_generated/suilend/cell/structs.js","./_generated/suilend/decimal/structs":"./_generated/suilend/decimal/structs.js","./_generated/suilend/lending-market/functions":"./_generated/suilend/lending-market/functions.js","./_generated/suilend/lending-market/structs":"./_generated/suilend/lending-market/structs.js","./_generated/suilend/lending-market-registry/functions":"./_generated/suilend/lending-market-registry/functions.js","./_generated/suilend/liquidity-mining/structs":"./_generated/suilend/liquidity-mining/structs.js","./_generated/suilend/obligation/structs":"./_generated/suilend/obligation/structs.js","./_generated/suilend/rate-limiter/functions":"./_generated/suilend/rate-limiter/functions.js","./_generated/suilend/rate-limiter/structs":"./_generated/suilend/rate-limiter/structs.js","./_generated/suilend/reserve/structs":"./_generated/suilend/reserve/structs.js","./_generated/suilend/reserve-config/functions":"./_generated/suilend/reserve-config/functions.js","./_generated/suilend/reserve-config/structs":"./_generated/suilend/reserve-config/structs.js","./_generated/_dependencies/pyth-2/price-identifier/structs":"./_generated/_dependencies/pyth-2/price-identifier/structs.js","./_generated/_dependencies/std/ascii/structs":"./_generated/_dependencies/std/ascii/structs.js","./_generated/_dependencies/std/option/structs":"./_generated/_dependencies/std/option/structs.js","./_generated/_dependencies/std/type-name/structs":"./_generated/_dependencies/std/type-name/structs.js","./_generated/_dependencies/sui/bag/structs":"./_generated/_dependencies/sui/bag/structs.js","./_generated/_dependencies/sui/balance/structs":"./_generated/_dependencies/sui/balance/structs.js","./_generated/_dependencies/sui/object/structs":"./_generated/_dependencies/sui/object/structs.js","./_generated/_dependencies/sui/object-table/structs":"./_generated/_dependencies/sui/object-table/structs.js","./margin/margin/deps/std/type_name":"./margin/margin/deps/std/type_name.js","./margin/margin/deps/sui/vec_set":"./margin/margin/deps/sui/vec_set.js","./margin/margin/deps/suilend/lending_market":"./margin/margin/deps/suilend/lending_market.js"},"types":"./index.d.ts","scripts":{"codegen":"node ./codegen.js","codegen:install":"node ./install-codegen.js","build":"rm -rf ./dist && tsc && node ./fix-esm-imports.js","typecheck":"tsc --noEmit && tsc --noEmit -p tsconfig.test.json","test":"vitest run","lint:ci":"yarn run typecheck","prettier":"prettier --write src/ tests/","release":"yarn run build && node ./release.js && cd ./dist && npm publish --access public"},"repository":{"type":"git","url":"git+https://github.com/fireflyprotocol/lending-mono.git","directory":"ts/sdks/sdk"},"dependencies":{"@bluefin-exchange/bluefin7k-aggregator-sdk":"7.7.0","@cetusprotocol/aggregator-sdk":"1.7.3","@flowx-finance/sdk":"2.1.0","@pythnetwork/hermes-client":"3.1.0","@pythnetwork/pyth-sui-js":"4.0.0","@suilend/springsui-sdk":"4.1.0","bignumber.js":"11.1.5","bn.js":"5.2.5","crypto-js":"4.2.0","lodash":"4.18.1","p-limit":"7.3.3","uuid":"14.0.2"},"devDependencies":{"@mysten/bcs":"2.1.2","@mysten/sui":"2.35.0","@suilend/sui-core":"2.2.0","@tsconfig/recommended":"1.0.13","@types/bn.js":"5.2.0","@types/lodash":"4.17.26","@types/node":"26.6.5","fast-check":"4.10.2","prettier":"3.9.10","ts-node":"10.9.2","typescript":"6.0.3","vite":"8.3.4","vitest":"5.0.4"},"peerDependencies":{"@mysten/bcs":"^2.1.1","@mysten/sui":">=2.31.3 <3","@suilend/sui-core":"^2.0.1"},"type":"module"}
|
|
@@ -3,9 +3,8 @@ import BigNumber from "bignumber.js";
|
|
|
3
3
|
import { LendingMarket } from "../_generated/suilend/lending-market/structs";
|
|
4
4
|
import { Reserve } from "../_generated/suilend/reserve/structs";
|
|
5
5
|
import { LendingMarketMetadata } from "../lib";
|
|
6
|
-
import * as simulate from "../utils/simulate";
|
|
7
6
|
export type ParsedLendingMarket = ReturnType<typeof parseLendingMarket>;
|
|
8
|
-
export declare const parseLendingMarket: (lendingMarket: LendingMarket<string>, reserves: Reserve<string>[], coinMetadataMap: Record<string, SuiClientTypes.CoinMetadata>, nowS: number, lendingMarketMetadata?: LendingMarketMetadata
|
|
7
|
+
export declare const parseLendingMarket: (lendingMarket: LendingMarket<string>, reserves: Reserve<string>[], coinMetadataMap: Record<string, SuiClientTypes.CoinMetadata>, nowS: number, lendingMarketMetadata?: LendingMarketMetadata) => {
|
|
9
8
|
version: bigint;
|
|
10
9
|
reserves: {
|
|
11
10
|
config: {
|
package/parsers/lendingMarket.js
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
import { normalizeStructTag } from "@mysten/sui/utils";
|
|
2
1
|
import BigNumber from "bignumber.js";
|
|
3
|
-
import * as simulate from "../utils/simulate.js";
|
|
4
2
|
import { parseRateLimiter } from "./rateLimiter.js";
|
|
5
3
|
import { parseReserve } from "./reserve.js";
|
|
6
|
-
export const parseLendingMarket = (lendingMarket, reserves, coinMetadataMap, nowS, lendingMarketMetadata
|
|
4
|
+
export const parseLendingMarket = (lendingMarket, reserves, coinMetadataMap, nowS, lendingMarketMetadata) => {
|
|
7
5
|
const id = lendingMarket.id;
|
|
8
6
|
const type = lendingMarket.$typeArgs[0];
|
|
9
7
|
const version = lendingMarket.version;
|
|
10
|
-
const
|
|
11
|
-
simulate.normalizeConfidenceByCoinType(confidenceByCoinType);
|
|
12
|
-
const parsedReserves = reserves.map((reserve) => {
|
|
13
|
-
const confidence = simulate.resolveConfidence(normalizedConfidence?.get(normalizeStructTag(reserve.coinType)), reserve);
|
|
14
|
-
return parseReserve(reserve, coinMetadataMap, confidence?.share, confidence?.kBps);
|
|
15
|
-
});
|
|
8
|
+
const parsedReserves = reserves.map((reserve) => parseReserve(reserve, coinMetadataMap));
|
|
16
9
|
const obligations = lendingMarket.obligations;
|
|
17
10
|
const parsedRateLimiter = parseRateLimiter(lendingMarket.rateLimiter, nowS);
|
|
18
11
|
const feeReceiver = lendingMarket.feeReceiver;
|
package/utils/simulate.d.ts
CHANGED
|
@@ -156,19 +156,6 @@ export type ConfidenceShare = BigNumber & {
|
|
|
156
156
|
};
|
|
157
157
|
/** Mirrors reserve.move's `record_confidence`: a zero spot records a zero share. */
|
|
158
158
|
export declare const confidenceShare: (conf: BigNumber, spot: BigNumber) => ConfidenceShare;
|
|
159
|
-
export type ConfidenceByCoinType = Map<string, {
|
|
160
|
-
share: ConfidenceShare | undefined;
|
|
161
|
-
kBps: BigNumber;
|
|
162
|
-
}>;
|
|
163
|
-
export declare const normalizeConfidenceByCoinType: (confidenceByCoinType: ConfidenceByCoinType) => ConfidenceByCoinType;
|
|
164
|
-
export declare const isRefreshedFromFeed: (reserve: Reserve<string>) => boolean;
|
|
165
|
-
export declare const resolveConfidence: (entry: {
|
|
166
|
-
share: ConfidenceShare | undefined;
|
|
167
|
-
kBps: BigNumber;
|
|
168
|
-
} | undefined, reserve: Reserve<string>) => {
|
|
169
|
-
share: ConfidenceShare;
|
|
170
|
-
kBps: BigNumber;
|
|
171
|
-
} | undefined;
|
|
172
159
|
/**
|
|
173
160
|
* Pure computation half of `refreshObligation`: same math, but returns fresh
|
|
174
161
|
* deposits/borrows/reward-manager arrays and the five USD aggregates instead
|
|
@@ -178,8 +165,11 @@ export declare const resolveConfidence: (entry: {
|
|
|
178
165
|
* shallow-copied), silently corrupting `unrefreshedObligation` for anyone still
|
|
179
166
|
* holding a reference to it.
|
|
180
167
|
*/
|
|
181
|
-
export declare function computeObligationRefresh(obligation: Obligation<string>, refreshedReserves: Reserve<string>[], nowMs: number, confidenceByCoinType?:
|
|
182
|
-
|
|
168
|
+
export declare function computeObligationRefresh(obligation: Obligation<string>, refreshedReserves: Reserve<string>[], nowMs: number, confidenceByCoinType?: Map<string, {
|
|
169
|
+
share: ConfidenceShare | undefined;
|
|
170
|
+
kBps: BigNumber;
|
|
171
|
+
}>): ObligationRefresh;
|
|
172
|
+
export declare const refreshObligation: (unrefreshedObligation: Obligation<string>, refreshedReserves: Reserve<string>[]) => Obligation<string>;
|
|
183
173
|
export declare const numberToDecimal: (value: number) => Decimal;
|
|
184
174
|
export declare const stringToDecimal: (value: string) => Decimal;
|
|
185
175
|
export declare const decimalToBigNumber: (value: Decimal) => BigNumber;
|
package/utils/simulate.js
CHANGED
|
@@ -355,15 +355,10 @@ export const computeCloseLtv = (config) => new BigNumber(config.closeLtvPct / 10
|
|
|
355
355
|
/** Mirrors reserve.move's `record_confidence`: a zero spot records a zero share. */
|
|
356
356
|
export const confidenceShare = (conf, spot) => (spot.isZero() ? new BigNumber(0) : conf.dividedBy(spot));
|
|
357
357
|
const ZERO_SHARE = confidenceShare(new BigNumber(0), new BigNumber(0));
|
|
358
|
-
|
|
359
|
-
normalizeStructTag(coinType),
|
|
360
|
-
entry,
|
|
361
|
-
]));
|
|
362
|
-
export const isRefreshedFromFeed = (reserve) => "feedConfidence" in reserve;
|
|
363
|
-
export const resolveConfidence = (entry, reserve) => {
|
|
358
|
+
const resolveConfidence = (entry, reserve) => {
|
|
364
359
|
if (entry === undefined)
|
|
365
360
|
return undefined;
|
|
366
|
-
const refreshedFromFeed =
|
|
361
|
+
const refreshedFromFeed = "feedConfidence" in reserve;
|
|
367
362
|
const feedConf = feedConfidenceOf(reserve);
|
|
368
363
|
const share = (feedConf !== undefined
|
|
369
364
|
? confidenceShare(feedConf, unclampedSpot(reserve))
|
|
@@ -395,7 +390,11 @@ export function computeObligationRefresh(obligation, refreshedReserves, nowMs,
|
|
|
395
390
|
// precedence because it comes from the same update as its price. A reserve
|
|
396
391
|
// with no entry here gets plain min/max(price, smoothedPrice) bounds.
|
|
397
392
|
confidenceByCoinType) {
|
|
398
|
-
const normalizedConfidence = confidenceByCoinType &&
|
|
393
|
+
const normalizedConfidence = confidenceByCoinType &&
|
|
394
|
+
new Map([...confidenceByCoinType].map(([coinType, entry]) => [
|
|
395
|
+
normalizeStructTag(coinType),
|
|
396
|
+
entry,
|
|
397
|
+
]));
|
|
399
398
|
const userRewardManagers = [...obligation.userRewardManagers];
|
|
400
399
|
let depositValueUsd = new BigNumber(0);
|
|
401
400
|
let allowedBorrowValueUsd = new BigNumber(0);
|
|
@@ -476,8 +475,8 @@ confidenceByCoinType) {
|
|
|
476
475
|
weightedBorrowedValueUpperBoundUsd,
|
|
477
476
|
};
|
|
478
477
|
}
|
|
479
|
-
export const refreshObligation = (unrefreshedObligation, refreshedReserves
|
|
480
|
-
const refresh = computeObligationRefresh(unrefreshedObligation, refreshedReserves, Date.now()
|
|
478
|
+
export const refreshObligation = (unrefreshedObligation, refreshedReserves) => {
|
|
479
|
+
const refresh = computeObligationRefresh(unrefreshedObligation, refreshedReserves, Date.now());
|
|
481
480
|
return {
|
|
482
481
|
...unrefreshedObligation,
|
|
483
482
|
deposits: refresh.deposits,
|