@defisaver/positions-sdk 2.1.131 → 2.1.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.
@@ -64,9 +64,15 @@ function _getAaveV3MarketData(provider_1, network_1, market_1) {
64
64
  const aaveIncentivesContract = (0, contracts_1.AaveIncentiveDataProviderV3ContractViem)(provider, network);
65
65
  const marketAddress = market.providerAddress;
66
66
  const networksWithIncentives = [common_1.NetworkNumber.Eth, common_1.NetworkNumber.Arb, common_1.NetworkNumber.Opt, common_1.NetworkNumber.Linea, common_1.NetworkNumber.Plasma];
67
+ // Limit each view call to 10 tokens, run chunks concurrently, then combine their results into loanInfo.
68
+ const addressesPerRequest = 10;
69
+ const addressChunks = _addresses.length > addressesPerRequest
70
+ ? Array.from({ length: Math.ceil(_addresses.length / addressesPerRequest) }, (_, index) => _addresses.slice(index * addressesPerRequest, (index + 1) * addressesPerRequest))
71
+ : [_addresses];
72
+ const loanInfoPromise = Promise.all(addressChunks.map((addresses) => loanInfoContract.read.getFullTokensInfo([marketAddress, addresses], (0, viem_1.setViemBlockNumber)(blockNumber)))).then((loanInfoChunks) => loanInfoChunks.flat());
67
73
  // eslint-disable-next-line prefer-const
68
74
  let [loanInfo, eModesInfo, rewardInfo, merkleRewardsMap, meritRewardsMap] = yield Promise.all([
69
- loanInfoContract.read.getFullTokensInfo([marketAddress, _addresses], (0, viem_1.setViemBlockNumber)(blockNumber)),
75
+ loanInfoPromise,
70
76
  loanInfoContract.read.getAllEmodes([marketAddress], (0, viem_1.setViemBlockNumber)(blockNumber)),
71
77
  networksWithIncentives.includes(network) ? aaveIncentivesContract.read.getReservesIncentivesData([marketAddress], (0, viem_1.setViemBlockNumber)(blockNumber)) : null,
72
78
  (0, merkl_1.getMerkleCampaigns)(network),
@@ -30,7 +30,7 @@ const getAndFormatBands = (provider, network, selectedMarket, _minBand, _maxBand
30
30
  // getBandsData uses a lot of gas to get all of the bands at once, so we use pagination and fetch 200 bands at a time
31
31
  let i = minBand;
32
32
  while (i < maxBand) {
33
- i += 200;
33
+ i += 20;
34
34
  if (i > maxBand) {
35
35
  pivots.push(maxBand);
36
36
  }
@@ -31,7 +31,7 @@ const getAndFormatBands = (provider, network, selectedMarket, _minBand, _maxBand
31
31
  // getBandsData uses a lot of gas to get all of the bands at once, so we use pagination and fetch 200 bands at a time
32
32
  let i = minBand;
33
33
  while (i < maxBand) {
34
- i += 200;
34
+ i += 20;
35
35
  if (i > maxBand) {
36
36
  pivots.push(maxBand);
37
37
  }
@@ -71,7 +71,7 @@ function getPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1)
71
71
  const liquityV2Markets = [common_1.NetworkNumber.Eth].includes(network) ? Object.values((0, markets_1.LiquityV2Markets)(network)) : [];
72
72
  const liquityV2MarketsStaking = [common_1.NetworkNumber.Eth].includes(network) ? Object.values((0, markets_1.LiquityV2Markets)(network)).filter(market => !market.isLegacy) : [];
73
73
  const aaveV4Spokes = Object.values((0, markets_1.AaveV4Spokes)(network)).filter((market) => market.chainIds.includes(network));
74
- const args = [network, { batch: { multicall: { batchSize: isSim ? 500000 : 2500000 } } }];
74
+ const args = [network, { batch: { multicall: { batchSize: isSim ? 1000 : 2500000 } } }];
75
75
  const client = (0, viem_1.getViemProvider)(provider, ...args);
76
76
  const defaultClient = (0, viem_1.getViemProvider)(defaultProvider, ...args);
77
77
  const morphoMarketsData = {};
@@ -53,9 +53,15 @@ export function _getAaveV3MarketData(provider_1, network_1, market_1) {
53
53
  const aaveIncentivesContract = AaveIncentiveDataProviderV3ContractViem(provider, network);
54
54
  const marketAddress = market.providerAddress;
55
55
  const networksWithIncentives = [NetworkNumber.Eth, NetworkNumber.Arb, NetworkNumber.Opt, NetworkNumber.Linea, NetworkNumber.Plasma];
56
+ // Limit each view call to 10 tokens, run chunks concurrently, then combine their results into loanInfo.
57
+ const addressesPerRequest = 10;
58
+ const addressChunks = _addresses.length > addressesPerRequest
59
+ ? Array.from({ length: Math.ceil(_addresses.length / addressesPerRequest) }, (_, index) => _addresses.slice(index * addressesPerRequest, (index + 1) * addressesPerRequest))
60
+ : [_addresses];
61
+ const loanInfoPromise = Promise.all(addressChunks.map((addresses) => loanInfoContract.read.getFullTokensInfo([marketAddress, addresses], setViemBlockNumber(blockNumber)))).then((loanInfoChunks) => loanInfoChunks.flat());
56
62
  // eslint-disable-next-line prefer-const
57
63
  let [loanInfo, eModesInfo, rewardInfo, merkleRewardsMap, meritRewardsMap] = yield Promise.all([
58
- loanInfoContract.read.getFullTokensInfo([marketAddress, _addresses], setViemBlockNumber(blockNumber)),
64
+ loanInfoPromise,
59
65
  loanInfoContract.read.getAllEmodes([marketAddress], setViemBlockNumber(blockNumber)),
60
66
  networksWithIncentives.includes(network) ? aaveIncentivesContract.read.getReservesIncentivesData([marketAddress], setViemBlockNumber(blockNumber)) : null,
61
67
  getMerkleCampaigns(network),
@@ -24,7 +24,7 @@ const getAndFormatBands = (provider, network, selectedMarket, _minBand, _maxBand
24
24
  // getBandsData uses a lot of gas to get all of the bands at once, so we use pagination and fetch 200 bands at a time
25
25
  let i = minBand;
26
26
  while (i < maxBand) {
27
- i += 200;
27
+ i += 20;
28
28
  if (i > maxBand) {
29
29
  pivots.push(maxBand);
30
30
  }
@@ -25,7 +25,7 @@ const getAndFormatBands = (provider, network, selectedMarket, _minBand, _maxBand
25
25
  // getBandsData uses a lot of gas to get all of the bands at once, so we use pagination and fetch 200 bands at a time
26
26
  let i = minBand;
27
27
  while (i < maxBand) {
28
- i += 200;
28
+ i += 20;
29
29
  if (i > maxBand) {
30
30
  pivots.push(maxBand);
31
31
  }
@@ -51,7 +51,7 @@ export function getPortfolioData(provider_1, network_1, defaultProvider_1, addre
51
51
  const liquityV2Markets = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)) : [];
52
52
  const liquityV2MarketsStaking = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)).filter(market => !market.isLegacy) : [];
53
53
  const aaveV4Spokes = Object.values(AaveV4Spokes(network)).filter((market) => market.chainIds.includes(network));
54
- const args = [network, { batch: { multicall: { batchSize: isSim ? 500000 : 2500000 } } }];
54
+ const args = [network, { batch: { multicall: { batchSize: isSim ? 1000 : 2500000 } } }];
55
55
  const client = getViemProvider(provider, ...args);
56
56
  const defaultClient = getViemProvider(defaultProvider, ...args);
57
57
  const morphoMarketsData = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/positions-sdk",
3
- "version": "2.1.131",
3
+ "version": "2.1.132",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -84,9 +84,21 @@ export async function _getAaveV3MarketData(provider: Client, network: NetworkNum
84
84
  const aaveIncentivesContract = AaveIncentiveDataProviderV3ContractViem(provider, network);
85
85
  const marketAddress = market.providerAddress;
86
86
  const networksWithIncentives = [NetworkNumber.Eth, NetworkNumber.Arb, NetworkNumber.Opt, NetworkNumber.Linea, NetworkNumber.Plasma];
87
+ // Limit each view call to 10 tokens, run chunks concurrently, then combine their results into loanInfo.
88
+ const addressesPerRequest = 10;
89
+ const addressChunks: EthAddress[][] = _addresses.length > addressesPerRequest
90
+ ? Array.from(
91
+ { length: Math.ceil(_addresses.length / addressesPerRequest) },
92
+ (_, index) => _addresses.slice(index * addressesPerRequest, (index + 1) * addressesPerRequest) as EthAddress[],
93
+ )
94
+ : [_addresses as EthAddress[]];
95
+ const loanInfoPromise = Promise.all(addressChunks.map((addresses) => loanInfoContract.read.getFullTokensInfo(
96
+ [marketAddress, addresses],
97
+ setViemBlockNumber(blockNumber),
98
+ ))).then((loanInfoChunks) => loanInfoChunks.flat());
87
99
  // eslint-disable-next-line prefer-const
88
100
  let [loanInfo, eModesInfo, rewardInfo, merkleRewardsMap, meritRewardsMap] = await Promise.all([
89
- loanInfoContract.read.getFullTokensInfo([marketAddress, _addresses as EthAddress[]], setViemBlockNumber(blockNumber)),
101
+ loanInfoPromise,
90
102
  loanInfoContract.read.getAllEmodes([marketAddress], setViemBlockNumber(blockNumber)),
91
103
  networksWithIncentives.includes(network) ? aaveIncentivesContract.read.getReservesIncentivesData([marketAddress], setViemBlockNumber(blockNumber)) : null,
92
104
  getMerkleCampaigns(network),
@@ -24,7 +24,7 @@ const getAndFormatBands = async (provider: Client, network: NetworkNumber, selec
24
24
  // getBandsData uses a lot of gas to get all of the bands at once, so we use pagination and fetch 200 bands at a time
25
25
  let i = minBand;
26
26
  while (i < maxBand) {
27
- i += 200;
27
+ i += 20;
28
28
  if (i > maxBand) {
29
29
  pivots.push(maxBand);
30
30
  } else {
@@ -24,7 +24,7 @@ const getAndFormatBands = async (provider: Client, network: NetworkNumber, selec
24
24
  // getBandsData uses a lot of gas to get all of the bands at once, so we use pagination and fetch 200 bands at a time
25
25
  let i = minBand;
26
26
  while (i < maxBand) {
27
- i += 200;
27
+ i += 20;
28
28
  if (i > maxBand) {
29
29
  pivots.push(maxBand);
30
30
  } else {
@@ -75,7 +75,8 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
75
75
  const liquityV2MarketsStaking = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)).filter(market => !market.isLegacy) : [];
76
76
  const aaveV4Spokes = Object.values(AaveV4Spokes(network)).filter((market) => market.chainIds.includes(network));
77
77
 
78
- const args: [NetworkNumber, any?] = [network, { batch: { multicall: { batchSize: isSim ? 500_000 : 2_500_000 } } }];
78
+
79
+ const args: [NetworkNumber, any?] = [network, { batch: { multicall: { batchSize: isSim ? 1_000 : 2_500_000 } } }];
79
80
  const client = getViemProvider(provider, ...args);
80
81
  const defaultClient = getViemProvider(defaultProvider, ...args);
81
82