@defisaver/positions-sdk 2.1.158-morpho-batch-dev → 2.1.159

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.
@@ -108,6 +108,9 @@ function _getMorphoMidnightMarketData(provider, network, selectedMarket) {
108
108
  const utillization = new decimal_js_1.default(totalUnits).eq(0) ? '0' : new decimal_js_1.default(totalDebt).div(totalUnits).mul(100).toString();
109
109
  return {
110
110
  id: marketInfo.id,
111
+ // Markets are created lazily on the first position, and `getMarketInfo` answers an uncreated id with
112
+ // a zeroed struct rather than a revert — only the echoed id says whether the market exists yet.
113
+ isCreated: marketInfo.id.toLowerCase() !== constants_1.ZERO_BYTES32,
111
114
  loanToken: loanSym,
112
115
  collaterals: collateralSymbols,
113
116
  maturity: selectedMarket.maturity,
@@ -485,7 +485,11 @@ function getPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1)
485
485
  }
486
486
  }))).flat(),
487
487
  ...morphoMidnightMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
488
+ var _a;
488
489
  try {
490
+ // Markets are created lazily on the first position, so an uncreated one can hold no position.
491
+ if (!((_a = morphoMidnightMarketsData[market.value]) === null || _a === void 0 ? void 0 : _a.isCreated))
492
+ return;
489
493
  const accData = yield (0, morphoMidnight_1._getMorphoMidnightAccountData)(client, network, address, market, morphoMidnightMarketsData[market.value]);
490
494
  if (new decimal_js_1.default(accData.suppliedUsd).gt(0))
491
495
  positions[address.toLowerCase()].morphoMidnight[market.value] = { error: '', data: accData };
@@ -98,7 +98,7 @@ exports.fetchMorphoVaultsLiquidity = fetchMorphoVaultsLiquidity;
98
98
  const getBatchedViemProvider = (provider, network) => (0, viem_1.getViemProvider)(provider, network, {
99
99
  batch: {
100
100
  multicall: {
101
- batchSize: 2500000,
101
+ batchSize: 250000,
102
102
  },
103
103
  },
104
104
  });
@@ -133,6 +133,7 @@ export type MorphoMidnightAssetsData = {
133
133
  };
134
134
  export interface MorphoMidnightMarketInfo {
135
135
  id: string;
136
+ isCreated: boolean;
136
137
  loanToken: string;
137
138
  collaterals: string[];
138
139
  maturity: number;
@@ -12,7 +12,7 @@ import { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
12
12
  import { NetworkNumber, } from '../types/common';
13
13
  import { DFSFeedRegistryContractViem, FeedRegistryContractViem, MorphoMidnightViewContractViem, } from '../contracts';
14
14
  import { MorphoMidnightBorrowInfoStatus, } from '../types';
15
- import { USD_QUOTE } from '../constants';
15
+ import { USD_QUOTE, ZERO_BYTES32 } from '../constants';
16
16
  import { calculateNetApy } from '../staking';
17
17
  import { isMainnetNetwork, wethToEth } from '../services/utils';
18
18
  import { getMorphoMidnightAggregatedPositionData, getMorphoMidnightUserBorrowInfo } from '../helpers/morphoMidnightHelpers';
@@ -97,6 +97,9 @@ export function _getMorphoMidnightMarketData(provider, network, selectedMarket)
97
97
  const utillization = new Dec(totalUnits).eq(0) ? '0' : new Dec(totalDebt).div(totalUnits).mul(100).toString();
98
98
  return {
99
99
  id: marketInfo.id,
100
+ // Markets are created lazily on the first position, and `getMarketInfo` answers an uncreated id with
101
+ // a zeroed struct rather than a revert — only the echoed id says whether the market exists yet.
102
+ isCreated: marketInfo.id.toLowerCase() !== ZERO_BYTES32,
100
103
  loanToken: loanSym,
101
104
  collaterals: collateralSymbols,
102
105
  maturity: selectedMarket.maturity,
@@ -465,7 +465,11 @@ export function getPortfolioData(provider_1, network_1, defaultProvider_1, addre
465
465
  }
466
466
  }))).flat(),
467
467
  ...morphoMidnightMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
468
+ var _a;
468
469
  try {
470
+ // Markets are created lazily on the first position, so an uncreated one can hold no position.
471
+ if (!((_a = morphoMidnightMarketsData[market.value]) === null || _a === void 0 ? void 0 : _a.isCreated))
472
+ return;
469
473
  const accData = yield _getMorphoMidnightAccountData(client, network, address, market, morphoMidnightMarketsData[market.value]);
470
474
  if (new Dec(accData.suppliedUsd).gt(0))
471
475
  positions[address.toLowerCase()].morphoMidnight[market.value] = { error: '', data: accData };
@@ -56,7 +56,7 @@ export const fetchMorphoVaultsLiquidity = (network, vaults) => __awaiter(void 0,
56
56
  const getBatchedViemProvider = (provider, network) => getViemProvider(provider, network, {
57
57
  batch: {
58
58
  multicall: {
59
- batchSize: 2500000,
59
+ batchSize: 250000,
60
60
  },
61
61
  },
62
62
  });
@@ -133,6 +133,7 @@ export type MorphoMidnightAssetsData = {
133
133
  };
134
134
  export interface MorphoMidnightMarketInfo {
135
135
  id: string;
136
+ isCreated: boolean;
136
137
  loanToken: string;
137
138
  collaterals: string[];
138
139
  maturity: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/positions-sdk",
3
- "version": "2.1.158-morpho-batch-dev",
3
+ "version": "2.1.159",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -10,7 +10,7 @@ import {
10
10
  import {
11
11
  MorphoMidnightAssetsData, MorphoMidnightBorrowInfoStatus, MorphoMidnightMarketData, MorphoMidnightMarketInfo, MorphoMidnightPositionData,
12
12
  } from '../types';
13
- import { USD_QUOTE } from '../constants';
13
+ import { USD_QUOTE, ZERO_BYTES32 } from '../constants';
14
14
  import { calculateNetApy } from '../staking';
15
15
  import { isMainnetNetwork, wethToEth } from '../services/utils';
16
16
  import { getMorphoMidnightAggregatedPositionData, getMorphoMidnightUserBorrowInfo } from '../helpers/morphoMidnightHelpers';
@@ -102,6 +102,9 @@ export async function _getMorphoMidnightMarketData(provider: Client, network: Ne
102
102
 
103
103
  return {
104
104
  id: marketInfo.id,
105
+ // Markets are created lazily on the first position, and `getMarketInfo` answers an uncreated id with
106
+ // a zeroed struct rather than a revert — only the echoed id says whether the market exists yet.
107
+ isCreated: marketInfo.id.toLowerCase() !== ZERO_BYTES32,
105
108
  loanToken: loanSym,
106
109
  collaterals: collateralSymbols,
107
110
  maturity: selectedMarket.maturity,
@@ -479,6 +479,8 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
479
479
  })).flat(),
480
480
  ...morphoMidnightMarkets.map((market) => addresses.map(async (address) => {
481
481
  try {
482
+ // Markets are created lazily on the first position, so an uncreated one can hold no position.
483
+ if (!morphoMidnightMarketsData[market.value]?.isCreated) return;
482
484
  const accData = await _getMorphoMidnightAccountData(client, network, address, market, morphoMidnightMarketsData[market.value]);
483
485
  if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].morphoMidnight[market.value] = { error: '', data: accData };
484
486
  } catch (error) {
@@ -59,7 +59,7 @@ export const fetchMorphoVaultsLiquidity = async (network: NetworkNumber, vaults:
59
59
  const getBatchedViemProvider = (provider: EthereumProvider, network: NetworkNumber) => getViemProvider(provider, network, {
60
60
  batch: {
61
61
  multicall: {
62
- batchSize: 2500000,
62
+ batchSize: 250_000,
63
63
  },
64
64
  },
65
65
  });
@@ -147,6 +147,7 @@ export type MorphoMidnightAssetsData = { [key: string]: MorphoMidnightAssetData
147
147
 
148
148
  export interface MorphoMidnightMarketInfo {
149
149
  id: string,
150
+ isCreated: boolean, // markets are created lazily on first position; until then the view returns a zeroed struct (id = 0x0, no prices)
150
151
  loanToken: string,
151
152
  collaterals: string[], // collateral symbols, index-aligned with the market's collateral set
152
153
  maturity: number, // unix timestamp (seconds)