@1delta/margin-fetcher 0.0.198 → 0.0.200

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.
@@ -1,5 +1,6 @@
1
1
  export { genericFactoryAbi } from "./genericFactory.js";
2
2
  export { vaultLensAbi } from "./vaultLens.js";
3
+ export { priceLensAbi } from "./priceLens.js";
3
4
  export { eVaultAbi } from "./eVault.js";
4
5
  export { evcAbi } from "./evc.js";
5
6
  export { orchestratorAbi } from "./orchestrator.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/abis/euler/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/abis/euler/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,58 @@
1
+ export declare const priceLensAbi: readonly [{
2
+ readonly inputs: readonly [{
3
+ readonly name: "vault";
4
+ readonly type: "address";
5
+ }];
6
+ readonly name: "getVaultPrice";
7
+ readonly outputs: readonly [{
8
+ readonly components: readonly [{
9
+ readonly name: "asset";
10
+ readonly type: "address";
11
+ }, {
12
+ readonly name: "unitOfAccount";
13
+ readonly type: "address";
14
+ }, {
15
+ readonly name: "unitOfAccountDecimals";
16
+ readonly type: "uint8";
17
+ }, {
18
+ readonly name: "amountOutMid";
19
+ readonly type: "uint256";
20
+ }, {
21
+ readonly name: "queryFailure";
22
+ readonly type: "bool";
23
+ }];
24
+ readonly name: "result";
25
+ readonly type: "tuple";
26
+ }];
27
+ readonly stateMutability: "view";
28
+ readonly type: "function";
29
+ }, {
30
+ readonly inputs: readonly [{
31
+ readonly name: "vaults";
32
+ readonly type: "address[]";
33
+ }];
34
+ readonly name: "getVaultPrices";
35
+ readonly outputs: readonly [{
36
+ readonly components: readonly [{
37
+ readonly name: "asset";
38
+ readonly type: "address";
39
+ }, {
40
+ readonly name: "unitOfAccount";
41
+ readonly type: "address";
42
+ }, {
43
+ readonly name: "unitOfAccountDecimals";
44
+ readonly type: "uint8";
45
+ }, {
46
+ readonly name: "amountOutMid";
47
+ readonly type: "uint256";
48
+ }, {
49
+ readonly name: "queryFailure";
50
+ readonly type: "bool";
51
+ }];
52
+ readonly name: "results";
53
+ readonly type: "tuple[]";
54
+ }];
55
+ readonly stateMutability: "view";
56
+ readonly type: "function";
57
+ }];
58
+ //# sourceMappingURL=priceLens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"priceLens.d.ts","sourceRoot":"","sources":["../../../src/abis/euler/priceLens.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuCf,CAAA"}
package/dist/index.js CHANGED
@@ -30520,13 +30520,20 @@ async function fetchMorphoGraphQLPrices(chainId) {
30520
30520
  const allMarkets = [];
30521
30521
  for (const result of results) {
30522
30522
  const items = result?.data?.markets?.items;
30523
- if (!Array.isArray(items)) return null;
30523
+ if (!Array.isArray(items)) {
30524
+ console.warn(`[morpho-gql] chain ${chainId}: unexpected API shape, items is not an array`);
30525
+ return null;
30526
+ }
30524
30527
  allMarkets.push(...items);
30525
30528
  }
30526
- if (allMarkets.length === 0) return null;
30529
+ if (allMarkets.length === 0) {
30530
+ console.warn(`[morpho-gql] chain ${chainId}: API returned 0 markets`);
30531
+ return null;
30532
+ }
30527
30533
  const entries = [];
30528
30534
  for (const market of allMarkets) {
30529
- if (!market.collateralAsset) continue;
30535
+ if (!market.collateralAsset?.address || !market.loanAsset?.address)
30536
+ continue;
30530
30537
  const oracle = market.oracleAddress;
30531
30538
  const loanAsset = market.loanAsset.address.toLowerCase();
30532
30539
  const collateralAsset = market.collateralAsset.address.toLowerCase();
@@ -30540,27 +30547,58 @@ async function fetchMorphoGraphQLPrices(chainId) {
30540
30547
  market.loanAsset.decimals,
30541
30548
  market.collateralAsset.decimals
30542
30549
  ) : 0;
30543
- if (collateralPriceUSD != null && collateralPriceUSD > 0) {
30550
+ if (loanPriceUSD != null && loanPriceUSD > 0) {
30551
+ const collateralUSD = oracleRatio > 0 ? oracleRatio * loanPriceUSD : collateralPriceUSD ?? 0;
30552
+ if (collateralUSD > 0) {
30553
+ entries.push({
30554
+ asset: collateralAsset,
30555
+ price: oracleRatio,
30556
+ // Raw: collateral price in loan asset terms
30557
+ priceUSD: collateralUSD,
30558
+ marketUid: createMarketUid(chainId, lenderKey, collateralAsset),
30559
+ targetLender: lenderKey
30560
+ });
30561
+ }
30562
+ } else if (collateralPriceUSD != null && collateralPriceUSD > 0) {
30544
30563
  entries.push({
30545
30564
  asset: collateralAsset,
30546
- price: oracleRatio || collateralPriceUSD,
30565
+ price: oracleRatio,
30566
+ // Raw oracle ratio
30547
30567
  priceUSD: collateralPriceUSD,
30548
30568
  marketUid: createMarketUid(chainId, lenderKey, collateralAsset),
30549
30569
  targetLender: lenderKey
30550
30570
  });
30551
30571
  }
30552
- if (loanPriceUSD != null && loanPriceUSD > 0) {
30572
+ if (collateralPriceUSD != null && collateralPriceUSD > 0) {
30573
+ const loanUSD = oracleRatio > 0 ? collateralPriceUSD / oracleRatio : loanPriceUSD ?? 0;
30574
+ if (loanUSD > 0) {
30575
+ entries.push({
30576
+ asset: loanAsset,
30577
+ price: oracleRatio > 0 ? 1 / oracleRatio : 0,
30578
+ // Raw: loan price in collateral terms
30579
+ priceUSD: loanUSD,
30580
+ marketUid: createMarketUid(chainId, lenderKey, loanAsset),
30581
+ targetLender: lenderKey
30582
+ });
30583
+ }
30584
+ } else if (loanPriceUSD != null && loanPriceUSD > 0) {
30553
30585
  entries.push({
30554
30586
  asset: loanAsset,
30555
- price: oracleRatio > 0 ? 1 / oracleRatio : loanPriceUSD,
30587
+ price: oracleRatio > 0 ? 1 / oracleRatio : 0,
30588
+ // Raw oracle ratio
30556
30589
  priceUSD: loanPriceUSD,
30557
30590
  marketUid: createMarketUid(chainId, lenderKey, loanAsset),
30558
30591
  targetLender: lenderKey
30559
30592
  });
30560
30593
  }
30561
30594
  }
30562
- return entries.length > 0 ? entries : null;
30563
- } catch {
30595
+ if (entries.length === 0) {
30596
+ console.warn(`[morpho-gql] chain ${chainId}: ${allMarkets.length} markets fetched but 0 price entries produced`);
30597
+ return null;
30598
+ }
30599
+ return entries;
30600
+ } catch (err) {
30601
+ console.warn(`[morpho-gql] chain ${chainId}: API error, falling back to on-chain`, err);
30564
30602
  return null;
30565
30603
  }
30566
30604
  }
@@ -30835,17 +30873,88 @@ var listaFetcher = {
30835
30873
  getAbi: getListaAbi
30836
30874
  };
30837
30875
 
30876
+ // src/abis/euler/priceLens.ts
30877
+ var priceLensAbi = [
30878
+ {
30879
+ inputs: [{ name: "vault", type: "address" }],
30880
+ name: "getVaultPrice",
30881
+ outputs: [
30882
+ {
30883
+ components: [
30884
+ { name: "asset", type: "address" },
30885
+ { name: "unitOfAccount", type: "address" },
30886
+ { name: "unitOfAccountDecimals", type: "uint8" },
30887
+ { name: "amountOutMid", type: "uint256" },
30888
+ { name: "queryFailure", type: "bool" }
30889
+ ],
30890
+ name: "result",
30891
+ type: "tuple"
30892
+ }
30893
+ ],
30894
+ stateMutability: "view",
30895
+ type: "function"
30896
+ },
30897
+ {
30898
+ inputs: [{ name: "vaults", type: "address[]" }],
30899
+ name: "getVaultPrices",
30900
+ outputs: [
30901
+ {
30902
+ components: [
30903
+ { name: "asset", type: "address" },
30904
+ { name: "unitOfAccount", type: "address" },
30905
+ { name: "unitOfAccountDecimals", type: "uint8" },
30906
+ { name: "amountOutMid", type: "uint256" },
30907
+ { name: "queryFailure", type: "bool" }
30908
+ ],
30909
+ name: "results",
30910
+ type: "tuple[]"
30911
+ }
30912
+ ],
30913
+ stateMutability: "view",
30914
+ type: "function"
30915
+ }
30916
+ ];
30917
+
30838
30918
  // src/prices/oracle-prices/fetchers/euler.ts
30839
30919
  var MAX_VIRTUAL_ADDRESS = 65535;
30840
30920
  function isUsdUnitOfAccount(addr) {
30841
30921
  const numeric = parseInt(addr, 16);
30842
30922
  return numeric <= MAX_VIRTUAL_ADDRESS;
30843
30923
  }
30924
+ var PRICE_LENS_ADDRESS = "0x6392892f3C57c658d2c748fc64c6fe57680E889F";
30925
+ var PRICE_LENS_CHAINS = [
30926
+ "1",
30927
+ // Ethereum
30928
+ "56",
30929
+ // BSC
30930
+ "130",
30931
+ // Unichain
30932
+ "143",
30933
+ // Monad
30934
+ "146",
30935
+ // Sonic
30936
+ "999",
30937
+ // HyperEVM
30938
+ "8453",
30939
+ // Base
30940
+ "9745",
30941
+ // Plasma
30942
+ "42161",
30943
+ // Arbitrum
30944
+ "43114",
30945
+ // Avalanche
30946
+ "59144",
30947
+ // Linea
30948
+ "80094"
30949
+ // Berachain
30950
+ ];
30951
+ var eulerCombinedAbi = [...priceLensAbi, ...vaultLensAbi];
30844
30952
  function getEulerV2Calls(chainId) {
30845
30953
  if (!ENABLED_EULER_V2_CHAINS.includes(chainId)) return [];
30846
30954
  const configs = eulerConfigs() ?? {};
30847
30955
  const vaults = eulerVaults() ?? {};
30848
30956
  const results = [];
30957
+ const usePriceLens = PRICE_LENS_CHAINS.includes(chainId);
30849
30958
  for (const [lender, chainVaults] of Object.entries(vaults)) {
30850
30959
  const vaultList = chainVaults[chainId] ?? [];
30851
30960
  const config = configs[lender]?.[chainId];
@@ -30853,14 +30962,23 @@ function getEulerV2Calls(chainId) {
30853
30962
  const calls = [];
30854
30963
  const meta = [];
30855
30964
  for (const entry of vaultList) {
30856
- calls.push({
30857
- address: config.vaultLens,
30858
- name: "getVaultInfoFull",
30859
- params: [entry.vault]
30860
- });
30965
+ if (usePriceLens) {
30966
+ calls.push({
30967
+ address: PRICE_LENS_ADDRESS,
30968
+ name: "getVaultPrice",
30969
+ params: [entry.vault]
30970
+ });
30971
+ } else {
30972
+ calls.push({
30973
+ address: config.vaultLens,
30974
+ name: "getVaultInfoFull",
30975
+ params: [entry.vault]
30976
+ });
30977
+ }
30861
30978
  meta.push({
30862
30979
  vault: entry.vault.toLowerCase(),
30863
- lender
30980
+ lender,
30981
+ usePriceLens
30864
30982
  });
30865
30983
  }
30866
30984
  if (calls.length > 0) {
@@ -30875,14 +30993,27 @@ function parseEulerV2Results(data, meta, context) {
30875
30993
  const queryMeta = meta[index];
30876
30994
  if (!queryMeta || !result) return;
30877
30995
  try {
30878
- const priceInfo = result.liabilityPriceInfo;
30879
- if (!priceInfo || priceInfo.queryFailure) return;
30880
- const amountOutMid = BigInt(priceInfo.amountOutMid);
30996
+ let amountOutMid;
30997
+ let unitOfAccountDecimals;
30998
+ let unitOfAccount;
30999
+ let asset;
31000
+ if (queryMeta.usePriceLens) {
31001
+ if (result.queryFailure) return;
31002
+ amountOutMid = BigInt(result.amountOutMid);
31003
+ unitOfAccountDecimals = BigInt(result.unitOfAccountDecimals);
31004
+ unitOfAccount = result.unitOfAccount.toLowerCase();
31005
+ asset = result.asset.toLowerCase();
31006
+ } else {
31007
+ const priceInfo = result.liabilityPriceInfo;
31008
+ if (!priceInfo || priceInfo.queryFailure) return;
31009
+ amountOutMid = BigInt(priceInfo.amountOutMid);
31010
+ unitOfAccountDecimals = BigInt(result.unitOfAccountDecimals);
31011
+ unitOfAccount = result.unitOfAccount.toLowerCase();
31012
+ asset = result.asset.toLowerCase();
31013
+ }
30881
31014
  if (amountOutMid === 0n) return;
30882
- const unitOfAccountDecimals = BigInt(result.unitOfAccountDecimals);
30883
31015
  const priceInUoA = Number(amountOutMid) / Number(10n ** unitOfAccountDecimals);
30884
31016
  if (isNaN(priceInUoA) || priceInUoA === 0) return;
30885
- const unitOfAccount = result.unitOfAccount.toLowerCase();
30886
31017
  let priceUSD;
30887
31018
  if (isUsdUnitOfAccount(unitOfAccount)) {
30888
31019
  priceUSD = priceInUoA;
@@ -30892,12 +31023,15 @@ function parseEulerV2Results(data, meta, context) {
30892
31023
  priceUSD = priceInUoA * uoaUSD;
30893
31024
  }
30894
31025
  if (isNaN(priceUSD) || priceUSD === 0) return;
30895
- const asset = result.asset.toLowerCase();
30896
31026
  entries.push({
30897
31027
  asset,
30898
31028
  price: priceInUoA,
30899
31029
  priceUSD,
30900
- marketUid: createMarketUid(context.chainId, queryMeta.lender, queryMeta.vault)
31030
+ marketUid: createMarketUid(
31031
+ context.chainId,
31032
+ queryMeta.lender,
31033
+ queryMeta.vault
31034
+ )
30901
31035
  });
30902
31036
  } catch {
30903
31037
  }
@@ -30905,7 +31039,7 @@ function parseEulerV2Results(data, meta, context) {
30905
31039
  return entries;
30906
31040
  }
30907
31041
  function getEulerV2Abi() {
30908
- return vaultLensAbi;
31042
+ return eulerCombinedAbi;
30909
31043
  }
30910
31044
  var eulerV2Fetcher = {
30911
31045
  getCalls: getEulerV2Calls,
@@ -31086,7 +31220,7 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
31086
31220
  "eulerV2",
31087
31221
  eulerResults,
31088
31222
  eulerV2Fetcher.parse,
31089
- vaultLensAbi
31223
+ getEulerV2Abi()
31090
31224
  );
31091
31225
  const morphoGroup = buildGroup(
31092
31226
  "morpho",
@@ -31103,7 +31237,7 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
31103
31237
  morphoGroup
31104
31238
  ];
31105
31239
  const totalCalls = allGroups.reduce((s, g) => s + g.calls.length, 0);
31106
- if (totalCalls === 0) {
31240
+ if (totalCalls === 0 && !isActive("morpho")) {
31107
31241
  const diag2 = {
31108
31242
  chainId,
31109
31243
  totalCalls: 0,
@@ -31169,6 +31303,9 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
31169
31303
  ),
31170
31304
  morphoGqlPromise
31171
31305
  ]);
31306
+ if (morphoGqlEntries == null && isActive("morpho")) {
31307
+ console.warn(`[prices] chain ${chainId}: Morpho GraphQL returned null, falling back to on-chain (${morphoGroup.trackers.length} trackers)`);
31308
+ }
31172
31309
  const morphoData = morphoGqlEntries != null ? { results: [], error: void 0 } : await executeGroup(
31173
31310
  morphoGroup,
31174
31311
  chainId,
@@ -31413,7 +31550,7 @@ function selectAssetGroupPrices(structuredPrices, lists = {}, tvlMap = {}, prior
31413
31550
  if (prio < 0) continue;
31414
31551
  const tvl = tvlMap[lender] ?? 0;
31415
31552
  for (const entry of entries) {
31416
- if (entry.priceUSD <= 0) continue;
31553
+ if (!entry?.asset || entry.priceUSD <= 0) continue;
31417
31554
  const oracleKey = tokenList[entry.asset]?.assetGroup ?? `${chainId}-${entry.asset.toLowerCase()}`;
31418
31555
  candidates.push({
31419
31556
  oracleKey,