@1delta/margin-fetcher 0.0.317 → 0.0.318
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 +106 -6
- package/dist/index.js.map +1 -1
- package/dist/lending/public-data/midnight/apiClient.d.ts +1 -1
- package/dist/lending/public-data/midnight/apiClient.d.ts.map +1 -1
- package/dist/lending/user-data/midnight/userCallParse.d.ts.map +1 -1
- package/dist/prices/oracle-prices/fetchOraclePrices.d.ts +1 -1
- package/dist/prices/oracle-prices/fetchOraclePrices.d.ts.map +1 -1
- package/dist/prices/oracle-prices/fetchers/index.d.ts +1 -0
- package/dist/prices/oracle-prices/fetchers/index.d.ts.map +1 -1
- package/dist/prices/oracle-prices/fetchers/midnight.d.ts +86 -0
- package/dist/prices/oracle-prices/fetchers/midnight.d.ts.map +1 -0
- package/dist/prices/oracle-prices/index.d.ts +1 -0
- package/dist/prices/oracle-prices/index.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import './chunk-BYTNVMX7.js';
|
|
|
3
3
|
import './chunk-PR4QN5HX.js';
|
|
4
4
|
import { Lender, isAaveType, isCompoundV3, isMultiMarket, isSiloV2Type, isSiloV3Type, isDolomite, isEulerType, isAaveV4Type, isInit, isMorphoType, isCompoundV2Type, isVenusType, isSumerType, AAVE_V3_LENDERS, AAVE_V2_LENDERS, isAaveV2Type, isAaveV32Type, isAaveV3Type, isFluid, isGearboxV3, isMidnight, isYLDR, isCompoundV3Type, isLista, isTectonicType, isKineticType, isBenqiType } from '@1delta/lender-registry';
|
|
5
5
|
export { isAaveType, isAaveV2Type, isAaveV32Type, isAaveV3Type, isCompoundV3, isCompoundV3Type, isInit, isMorphoType, isMultiMarket, isYLDR } from '@1delta/lender-registry';
|
|
6
|
-
import { aavePools, compoundV3Pools, initConfig, morphoPools, compoundV2Pools, eulerVaults, siloMarkets, siloV2LenderKey, siloMarketsV3, siloV3LenderKey, aaveV4Spokes, aaveV4SpokeLenderKey, fluidResolvers, gearboxResolvers, dolomiteConfigs, midnightConfig, aaveReserves, compoundV3Reserves, morphoTypeMarkets, getSiloV2MarketEntry, getSiloV3MarketEntry, dolomiteEmode, aaveTokens, morphoTypeVaults, eulerConfigs, gearboxMarketCompressor, gearboxMarketConfigurators, gearboxV3LenderKey, midnightMarketsByChain, parseAaveV4SpokeLenderKey, gearboxAccountCompressor, compoundV2Tokens, aaveOracles, aaveOraclesConfig, compoundV2Oracles, compoundV2TokenArray, compoundV2OraclesConfig, compoundV3OraclesData, compoundV3BaseData, compoundV2Reserves, fetchTokenLists, fetchTokenList, aaveV4Oracles } from '@1delta/data-sdk';
|
|
6
|
+
import { aavePools, compoundV3Pools, initConfig, morphoPools, compoundV2Pools, eulerVaults, siloMarkets, siloV2LenderKey, siloMarketsV3, siloV3LenderKey, aaveV4Spokes, aaveV4SpokeLenderKey, fluidResolvers, gearboxResolvers, dolomiteConfigs, midnightConfig, aaveReserves, compoundV3Reserves, morphoTypeMarkets, getSiloV2MarketEntry, getSiloV3MarketEntry, dolomiteEmode, aaveTokens, morphoTypeVaults, eulerConfigs, gearboxMarketCompressor, gearboxMarketConfigurators, gearboxV3LenderKey, midnightMarketsByChain, parseAaveV4SpokeLenderKey, gearboxAccountCompressor, compoundV2Tokens, aaveOracles, aaveOraclesConfig, compoundV2Oracles, compoundV2TokenArray, compoundV2OraclesConfig, compoundV3OraclesData, compoundV3BaseData, compoundV2Reserves, fetchTokenLists, fetchTokenList, aaveV4Oracles, resolveMidnightApiBase } from '@1delta/data-sdk';
|
|
7
7
|
import lodash from 'lodash';
|
|
8
8
|
import { getEvmClient, getEvmChain, getEvmClientUniversal, multicallRetryUniversal } from '@1delta/providers';
|
|
9
9
|
import { MetaMorphoAbi, FluidLendingResolverAbi, FluidVaultResolverAbi, MoolahVaultAbi, MorphoLensAbi, AaveV4SpokeAbi, AaveV4OracleAbi, AaveV4HubAbi, DolomiteMarginAbi, GearboxMarketCompressorV310Abi, MorphoBlueAbi, MidnightAbi, GearboxCreditAccountCompressorV310Abi } from '@1delta/abis';
|
|
@@ -20754,12 +20754,10 @@ var getLenderPublicData = async (chainId, lenders, prices, additionalYields, mul
|
|
|
20754
20754
|
}
|
|
20755
20755
|
return lenderData;
|
|
20756
20756
|
};
|
|
20757
|
-
var DEFAULT_MIDNIGHT_API = "https://api.morpho.org/v0/midnight";
|
|
20758
20757
|
var warn = (...args) => {
|
|
20759
20758
|
};
|
|
20760
20759
|
function midnightApiBaseUrl(chainId) {
|
|
20761
|
-
|
|
20762
|
-
return (base && base.length > 0 ? base : DEFAULT_MIDNIGHT_API).replace(/\/+$/, "");
|
|
20760
|
+
return resolveMidnightApiBase(chainId);
|
|
20763
20761
|
}
|
|
20764
20762
|
var toBig2 = (v) => {
|
|
20765
20763
|
try {
|
|
@@ -24814,7 +24812,6 @@ function normalizeUnderlying3(token) {
|
|
|
24814
24812
|
const lower = token.toLowerCase();
|
|
24815
24813
|
return Object.values(WETH_BY_CHAIN).includes(lower) ? zeroAddress : lower;
|
|
24816
24814
|
}
|
|
24817
|
-
var MIDNIGHT_UNIT_DECIMALS = 18;
|
|
24818
24815
|
function toBigInt10(v) {
|
|
24819
24816
|
if (v === void 0 || v === null || v === "0x") return 0n;
|
|
24820
24817
|
if (typeof v === "bigint") return v;
|
|
@@ -24857,7 +24854,7 @@ var getMidnightUserDataConverter = (_lender, chainId, account, meta) => {
|
|
|
24857
24854
|
const loanOraclePrice = loanMeta ? getOraclePrice(loanMeta) : 0;
|
|
24858
24855
|
const loanPriceHist = loanMeta?.price?.priceUsd24h ?? loanDisplayPrice;
|
|
24859
24856
|
const debtUnits = readDebtUnits(positionResult);
|
|
24860
|
-
const debtStr = parseRawAmount(debtUnits.toString(),
|
|
24857
|
+
const debtStr = parseRawAmount(debtUnits.toString(), market.loanDecimals);
|
|
24861
24858
|
const debtNum = Number(debtStr);
|
|
24862
24859
|
const posData = {};
|
|
24863
24860
|
let anyBalance = debtUnits > 0n;
|
|
@@ -34228,6 +34225,86 @@ var morphoFetcher = {
|
|
|
34228
34225
|
parse: parseMorphoResults,
|
|
34229
34226
|
getAbi: getMorphoAbi
|
|
34230
34227
|
};
|
|
34228
|
+
function getMidnightCalls(chainId) {
|
|
34229
|
+
const markets = midnightMarketsByChain(chainId);
|
|
34230
|
+
if (markets.length === 0) return [];
|
|
34231
|
+
const results = [];
|
|
34232
|
+
for (const market of markets) {
|
|
34233
|
+
if (!market.marketId || !market.loanToken) continue;
|
|
34234
|
+
const legs = [];
|
|
34235
|
+
const calls = [];
|
|
34236
|
+
for (const c of market.collateralParams ?? []) {
|
|
34237
|
+
if (!c.oracle || !c.token) continue;
|
|
34238
|
+
legs.push({
|
|
34239
|
+
collateralAsset: c.token.toLowerCase(),
|
|
34240
|
+
collateralDecimals: c.decimals,
|
|
34241
|
+
oracle: c.oracle
|
|
34242
|
+
});
|
|
34243
|
+
calls.push({ address: c.oracle, name: "price", params: [] });
|
|
34244
|
+
}
|
|
34245
|
+
if (legs.length === 0) continue;
|
|
34246
|
+
results.push({
|
|
34247
|
+
calls,
|
|
34248
|
+
meta: {
|
|
34249
|
+
marketId: market.marketId,
|
|
34250
|
+
loanAsset: market.loanToken.toLowerCase(),
|
|
34251
|
+
loanDecimals: market.loanDecimals,
|
|
34252
|
+
legs
|
|
34253
|
+
},
|
|
34254
|
+
lender: midnightLenderKey(market.marketId)
|
|
34255
|
+
});
|
|
34256
|
+
}
|
|
34257
|
+
return results;
|
|
34258
|
+
}
|
|
34259
|
+
function parseMidnightResults(data, meta, context) {
|
|
34260
|
+
const { chainId, usdPrices, tokenList } = context;
|
|
34261
|
+
const entries = [];
|
|
34262
|
+
const loanAsset = meta.loanAsset;
|
|
34263
|
+
const loanDecimals = meta.loanDecimals ?? tokenList?.[loanAsset]?.decimals ?? 18;
|
|
34264
|
+
const loanOracleKey = tokenList?.[loanAsset]?.assetGroup ?? `${chainId}-${loanAsset}`;
|
|
34265
|
+
const loanAssetUSD = usdPrices[loanOracleKey] ?? usdPrices[loanAsset];
|
|
34266
|
+
if (!loanAssetUSD) return entries;
|
|
34267
|
+
const lenderKey = midnightLenderKey(meta.marketId);
|
|
34268
|
+
entries.push({
|
|
34269
|
+
asset: loanAsset,
|
|
34270
|
+
price: 1,
|
|
34271
|
+
priceUSD: loanAssetUSD,
|
|
34272
|
+
marketUid: createMarketUid(chainId, lenderKey, loanAsset),
|
|
34273
|
+
targetLender: lenderKey,
|
|
34274
|
+
description: "Midnight loan asset",
|
|
34275
|
+
staticBase: true,
|
|
34276
|
+
baseAsset: loanAsset
|
|
34277
|
+
});
|
|
34278
|
+
meta.legs.forEach((leg, i) => {
|
|
34279
|
+
const rawPrice = data[i];
|
|
34280
|
+
if (!rawPrice || rawPrice === "0x") return;
|
|
34281
|
+
const collateralDecimals = leg.collateralDecimals ?? tokenList?.[leg.collateralAsset]?.decimals ?? 18;
|
|
34282
|
+
const priceDebtToCollateral = formatMorphoPrice(
|
|
34283
|
+
rawPrice.toString(),
|
|
34284
|
+
loanDecimals,
|
|
34285
|
+
collateralDecimals
|
|
34286
|
+
);
|
|
34287
|
+
if (isNaN(priceDebtToCollateral) || priceDebtToCollateral === 0) return;
|
|
34288
|
+
entries.push({
|
|
34289
|
+
asset: leg.collateralAsset,
|
|
34290
|
+
price: priceDebtToCollateral,
|
|
34291
|
+
// raw: collateral price in loan asset terms
|
|
34292
|
+
priceUSD: priceDebtToCollateral * loanAssetUSD,
|
|
34293
|
+
marketUid: createMarketUid(chainId, lenderKey, leg.collateralAsset),
|
|
34294
|
+
targetLender: lenderKey,
|
|
34295
|
+
baseAsset: loanAsset
|
|
34296
|
+
});
|
|
34297
|
+
});
|
|
34298
|
+
return entries;
|
|
34299
|
+
}
|
|
34300
|
+
function getMidnightAbi() {
|
|
34301
|
+
return ProxyOracleAbi;
|
|
34302
|
+
}
|
|
34303
|
+
var midnightFetcher = {
|
|
34304
|
+
getCalls: getMidnightCalls,
|
|
34305
|
+
parse: parseMidnightResults,
|
|
34306
|
+
getAbi: getMidnightAbi
|
|
34307
|
+
};
|
|
34231
34308
|
var CompoundV2OracleAbi = [
|
|
34232
34309
|
{
|
|
34233
34310
|
inputs: [{ internalType: "address", name: "cToken", type: "address" }],
|
|
@@ -35822,6 +35899,11 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
35822
35899
|
}),
|
|
35823
35900
|
getCallsErrors
|
|
35824
35901
|
) : [];
|
|
35902
|
+
const midnightResults = isActive("midnight") ? safeGetCalls(
|
|
35903
|
+
"midnight",
|
|
35904
|
+
() => midnightFetcher.getCalls(chainId),
|
|
35905
|
+
getCallsErrors
|
|
35906
|
+
) : [];
|
|
35825
35907
|
const siloV2Results = isActive("silov2") ? safeGetCalls(
|
|
35826
35908
|
"siloV2",
|
|
35827
35909
|
() => siloV2Fetcher.getCalls(chainId),
|
|
@@ -35889,6 +35971,12 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
35889
35971
|
morphoFetcher.parse,
|
|
35890
35972
|
ProxyOracleAbi
|
|
35891
35973
|
);
|
|
35974
|
+
const midnightGroup = buildGroup(
|
|
35975
|
+
"midnight",
|
|
35976
|
+
midnightResults,
|
|
35977
|
+
midnightFetcher.parse,
|
|
35978
|
+
ProxyOracleAbi
|
|
35979
|
+
);
|
|
35892
35980
|
const siloV2Group = buildGroup(
|
|
35893
35981
|
"siloV2",
|
|
35894
35982
|
siloV2Results,
|
|
@@ -35927,6 +36015,7 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
35927
36015
|
eulerGroup,
|
|
35928
36016
|
aaveV4Group,
|
|
35929
36017
|
morphoGroup,
|
|
36018
|
+
midnightGroup,
|
|
35930
36019
|
siloV2Group,
|
|
35931
36020
|
siloV3Group,
|
|
35932
36021
|
fluidGroup,
|
|
@@ -35962,6 +36051,7 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
35962
36051
|
fluidData,
|
|
35963
36052
|
gearboxV3Data,
|
|
35964
36053
|
dolomiteData,
|
|
36054
|
+
midnightData,
|
|
35965
36055
|
morphoGqlEntries,
|
|
35966
36056
|
siloV2GqlEntries,
|
|
35967
36057
|
siloV3GqlEntries
|
|
@@ -36038,6 +36128,14 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
36038
36128
|
allowFailure,
|
|
36039
36129
|
rpcOverrides
|
|
36040
36130
|
),
|
|
36131
|
+
executeGroup(
|
|
36132
|
+
midnightGroup,
|
|
36133
|
+
chainId,
|
|
36134
|
+
chainBatchSize,
|
|
36135
|
+
retries,
|
|
36136
|
+
allowFailure,
|
|
36137
|
+
rpcOverrides
|
|
36138
|
+
),
|
|
36041
36139
|
morphoGqlPromise,
|
|
36042
36140
|
siloV2GqlPromise,
|
|
36043
36141
|
siloV3GqlPromise
|
|
@@ -36088,6 +36186,7 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
36088
36186
|
{ group: fluidGroup, data: fluidData },
|
|
36089
36187
|
{ group: gearboxV3Group, data: gearboxV3Data },
|
|
36090
36188
|
{ group: dolomiteGroup, data: dolomiteData },
|
|
36189
|
+
{ group: midnightGroup, data: midnightData },
|
|
36091
36190
|
...siloV2GqlEntries != null ? [] : [{ group: siloV2Group, data: siloV2Data }],
|
|
36092
36191
|
...siloV3GqlEntries != null ? [] : [{ group: siloV3Group, data: siloV3Data }],
|
|
36093
36192
|
// In hybrid mode the on-chain multicall ran too — surface its errors.
|
|
@@ -36281,6 +36380,7 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
36281
36380
|
}
|
|
36282
36381
|
parseTrackers(morphoGroup, morphoData.results, false);
|
|
36283
36382
|
}
|
|
36383
|
+
parseTrackers(midnightGroup, midnightData.results, false);
|
|
36284
36384
|
const totalFailedCalls = trackerDiags.reduce(
|
|
36285
36385
|
(sum, d) => sum + d.failedCalls,
|
|
36286
36386
|
0
|