@1delta/margin-fetcher 5.0.131 → 5.0.132
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.js +57 -8
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -29279,6 +29279,10 @@ function convertResupplyMarketsToResponse(raw, chainId, prices = {}, _additional
|
|
|
29279
29279
|
const maxLtv = p.maxLTV !== null ? Number(p.maxLTV) / LTV_PRECISION : 0;
|
|
29280
29280
|
const liquidationPenalty = p.liquidationFee !== null ? Number(p.liquidationFee) / LTV_PRECISION : 0;
|
|
29281
29281
|
const mintFeePct = p.mintFee !== null ? Number(p.mintFee) / LTV_PRECISION * 100 : 0;
|
|
29282
|
+
const debtWeight = Math.max(
|
|
29283
|
+
1,
|
|
29284
|
+
collPrice / debtPrice * (1 + mintFeePct / 100)
|
|
29285
|
+
);
|
|
29282
29286
|
const borrowApr = ratePerSecToApr(p.liveRatePerSec ?? p.ratePerSec);
|
|
29283
29287
|
const collateralIntrinsicApr = ratePerSecToApr(p.underlyingSupplyRatePerSec);
|
|
29284
29288
|
const entry2 = { data: {} };
|
|
@@ -29382,7 +29386,7 @@ function convertResupplyMarketsToResponse(raw, chainId, prices = {}, _additional
|
|
|
29382
29386
|
label: marketLabel,
|
|
29383
29387
|
borrowCollateralFactor: 0,
|
|
29384
29388
|
collateralFactor: 0,
|
|
29385
|
-
borrowFactor:
|
|
29389
|
+
borrowFactor: debtWeight,
|
|
29386
29390
|
liquidationPenalty,
|
|
29387
29391
|
closeFactor: 1,
|
|
29388
29392
|
collateralDisabled: true,
|
|
@@ -32020,10 +32024,17 @@ function organizeUserQueries(queries) {
|
|
|
32020
32024
|
const siloV2 = queries.filter((q) => isSiloV2Type(q.lender));
|
|
32021
32025
|
const siloV3 = queries.filter((q) => isSiloV3Type(q.lender));
|
|
32022
32026
|
const frankencoin = queries.filter((q) => isFrankencoin(q.lender));
|
|
32023
|
-
|
|
32027
|
+
const byFamily = (pred, family) => [queries.filter((q) => pred(q.lender)), family];
|
|
32028
|
+
const familyGroups = [
|
|
32029
|
+
byFamily(isResupply, Lender.RESUPPLY),
|
|
32030
|
+
byFamily(isInverse, Lender.INVERSE),
|
|
32031
|
+
byFamily(isFraxlend, Lender.FRAXLEND),
|
|
32032
|
+
byFamily(isCurvance, Lender.CURVANCE)
|
|
32033
|
+
];
|
|
32034
|
+
if (morphos.length === 0 && gearbox.length === 0 && midnight.length === 0 && term.length === 0 && exactly.length === 0 && liquity.length === 0 && river.length === 0 && teller.length === 0 && termMax.length === 0 && usdd.length === 0 && sky.length === 0 && frankencoin.length === 0 && llamaLend.length === 0 && siloV2.length === 0 && siloV3.length === 0 && familyGroups.every(([g]) => g.length === 0))
|
|
32024
32035
|
return queries;
|
|
32025
32036
|
const others = queries.filter(
|
|
32026
|
-
(q) => !isMorphoType(q.lender) && !isGearboxV3(q.lender) && !isMidnight(q.lender) && !isTerm(q.lender) && !isExactly(q.lender) && !isLiquityFamily(q.lender) && !isRiver(q.lender) && !isTeller(q.lender) && !isTermMax(q.lender) && !isDssType(q.lender) && !isFrankencoin(q.lender) && !isLlamaLend(q.lender) && !isSiloV2Type(q.lender) && !isSiloV3Type(q.lender)
|
|
32037
|
+
(q) => !isMorphoType(q.lender) && !isGearboxV3(q.lender) && !isMidnight(q.lender) && !isTerm(q.lender) && !isExactly(q.lender) && !isLiquityFamily(q.lender) && !isRiver(q.lender) && !isTeller(q.lender) && !isTermMax(q.lender) && !isDssType(q.lender) && !isFrankencoin(q.lender) && !isLlamaLend(q.lender) && !isSiloV2Type(q.lender) && !isSiloV3Type(q.lender) && !isResupply(q.lender) && !isInverse(q.lender) && !isFraxlend(q.lender) && !isCurvance(q.lender)
|
|
32027
32038
|
);
|
|
32028
32039
|
const morphoBlue = morphos.filter((q) => q.lender.startsWith("MORPHO_BLUE"));
|
|
32029
32040
|
const moolah = morphos.filter((q) => q.lender.startsWith("LISTA_DAO"));
|
|
@@ -32124,6 +32135,15 @@ function organizeUserQueries(queries) {
|
|
|
32124
32135
|
assets: void 0
|
|
32125
32136
|
});
|
|
32126
32137
|
}
|
|
32138
|
+
for (const [group, family] of familyGroups) {
|
|
32139
|
+
if (group.length === 0) continue;
|
|
32140
|
+
result.push({
|
|
32141
|
+
lender: family,
|
|
32142
|
+
account: group[0].account,
|
|
32143
|
+
params: group.map((p) => p.lender),
|
|
32144
|
+
assets: void 0
|
|
32145
|
+
});
|
|
32146
|
+
}
|
|
32127
32147
|
if (llamaLend.length > 0) {
|
|
32128
32148
|
result.push({
|
|
32129
32149
|
lender: Lender.LLAMALEND,
|
|
@@ -34309,6 +34329,11 @@ var DISCOVERY_TTL_MS2 = 6e4;
|
|
|
34309
34329
|
var SNAPSHOT_CHUNK = 12;
|
|
34310
34330
|
var rosterCache5 = /* @__PURE__ */ new Map();
|
|
34311
34331
|
var discoveryCache4 = /* @__PURE__ */ new Map();
|
|
34332
|
+
var familyDiscoveryInflight = /* @__PURE__ */ new Map();
|
|
34333
|
+
var resupplyQueryScope = (lender) => {
|
|
34334
|
+
const parts = resupplyKeyParts(lender);
|
|
34335
|
+
return parts ? { family: parts.lender, pair: parts.pair } : { family: lender };
|
|
34336
|
+
};
|
|
34312
34337
|
var rosterKey2 = (chainId, lender, block = "head") => `${chainId}:${lender}:${block}`;
|
|
34313
34338
|
var discoveryKey2 = (chainId, lender, account, block = "head") => `${chainId}:${lender}:${account.toLowerCase()}:${block}`;
|
|
34314
34339
|
var getCachedResupplyDiscovery = (chainId, lender, account, opts) => discoveryCache4.get(discoveryKey2(chainId, lender, account, blockKey(opts)));
|
|
@@ -34393,7 +34418,8 @@ var discoverPositions = async (chainId, pairs, account, opts) => {
|
|
|
34393
34418
|
return active;
|
|
34394
34419
|
};
|
|
34395
34420
|
var buildResupplyUserCall = async (chainId, lender, account, opts) => {
|
|
34396
|
-
const
|
|
34421
|
+
const { family, pair: scopedPair } = resupplyQueryScope(lender);
|
|
34422
|
+
const cfg = resupplyConfigFor(family, chainId);
|
|
34397
34423
|
const key4 = discoveryKey2(chainId, lender, account, blockKey(opts));
|
|
34398
34424
|
const stash = (positions2) => discoveryCache4.set(key4, { positions: positions2, at: Date.now() });
|
|
34399
34425
|
if (!cfg?.registry) {
|
|
@@ -34404,7 +34430,7 @@ var buildResupplyUserCall = async (chainId, lender, account, opts) => {
|
|
|
34404
34430
|
try {
|
|
34405
34431
|
roster = await fetchRoster2(
|
|
34406
34432
|
chainId,
|
|
34407
|
-
|
|
34433
|
+
family,
|
|
34408
34434
|
cfg.registry,
|
|
34409
34435
|
cfg.pairAllowlist,
|
|
34410
34436
|
opts
|
|
@@ -34417,7 +34443,28 @@ var buildResupplyUserCall = async (chainId, lender, account, opts) => {
|
|
|
34417
34443
|
return [];
|
|
34418
34444
|
}
|
|
34419
34445
|
const cachedDiscovery = discoveryCache4.get(key4);
|
|
34420
|
-
|
|
34446
|
+
let positions;
|
|
34447
|
+
if (cachedDiscovery && Date.now() - cachedDiscovery.at < DISCOVERY_TTL_MS2) {
|
|
34448
|
+
positions = cachedDiscovery.positions;
|
|
34449
|
+
} else {
|
|
34450
|
+
const famKey = discoveryKey2(chainId, family, account, blockKey(opts));
|
|
34451
|
+
const famCached = discoveryCache4.get(famKey);
|
|
34452
|
+
let all;
|
|
34453
|
+
if (famCached && Date.now() - famCached.at < DISCOVERY_TTL_MS2) {
|
|
34454
|
+
all = famCached.positions;
|
|
34455
|
+
} else {
|
|
34456
|
+
let inflight7 = familyDiscoveryInflight.get(famKey);
|
|
34457
|
+
if (!inflight7) {
|
|
34458
|
+
inflight7 = discoverPositions(chainId, roster.pairs, account, opts).then((found) => {
|
|
34459
|
+
discoveryCache4.set(famKey, { positions: found, at: Date.now() });
|
|
34460
|
+
return found;
|
|
34461
|
+
}).finally(() => familyDiscoveryInflight.delete(famKey));
|
|
34462
|
+
familyDiscoveryInflight.set(famKey, inflight7);
|
|
34463
|
+
}
|
|
34464
|
+
all = await inflight7;
|
|
34465
|
+
}
|
|
34466
|
+
positions = scopedPair ? all.filter((p) => p.pair.toLowerCase() === scopedPair) : all;
|
|
34467
|
+
}
|
|
34421
34468
|
stash(positions);
|
|
34422
34469
|
if (positions.length === 0) return [];
|
|
34423
34470
|
return positions.flatMap(({ pair, collateral }) => [
|
|
@@ -34430,6 +34477,7 @@ var buildResupplyUserCall = async (chainId, lender, account, opts) => {
|
|
|
34430
34477
|
function __resetResupplyUserCaches() {
|
|
34431
34478
|
rosterCache5.clear();
|
|
34432
34479
|
discoveryCache4.clear();
|
|
34480
|
+
familyDiscoveryInflight.clear();
|
|
34433
34481
|
}
|
|
34434
34482
|
|
|
34435
34483
|
// src/lending/user-data/fraxlend/lens.ts
|
|
@@ -39224,7 +39272,8 @@ function sharesToAmount(shares, totalAmount, totalShares) {
|
|
|
39224
39272
|
return q * totalShares < shares * totalAmount ? q + 1n : q;
|
|
39225
39273
|
}
|
|
39226
39274
|
var getResupplyUserDataConverter = (lender, chainId, account, meta, opts) => {
|
|
39227
|
-
const
|
|
39275
|
+
const { family } = resupplyQueryScope(lender);
|
|
39276
|
+
const cfg = resupplyConfigFor(family, chainId);
|
|
39228
39277
|
const discovery = getCachedResupplyDiscovery(chainId, lender, account, opts);
|
|
39229
39278
|
const positions = discovery?.positions ?? [];
|
|
39230
39279
|
const expected = cfg && positions.length > 0 ? positions.length * RESUPPLY_CALLS_PER_PAIR : 0;
|
|
@@ -39243,7 +39292,7 @@ var getResupplyUserDataConverter = (lender, chainId, account, meta, opts) => {
|
|
|
39243
39292
|
const totalBorrowAmount = tupleAt(accounting, 1);
|
|
39244
39293
|
const totalBorrowShares = tupleAt(accounting, 2);
|
|
39245
39294
|
const sharePrice = isFailedCall(data[base + 1]) ? 0n : big18(data[base + 1]);
|
|
39246
|
-
const lenderKey = resupplyLenderKey(
|
|
39295
|
+
const lenderKey = resupplyLenderKey(family, chainId, pair);
|
|
39247
39296
|
const metaMap = meta?.[lenderKey];
|
|
39248
39297
|
if (!metaMap) return;
|
|
39249
39298
|
const debt = sharesToAmount(
|