@defisaver/positions-sdk 2.1.103 → 2.1.105

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.
Files changed (53) hide show
  1. package/cjs/aaveV4/index.d.ts +1 -0
  2. package/cjs/aaveV4/index.js +8 -3
  3. package/cjs/aaveV4/merkl.d.ts +8 -0
  4. package/cjs/aaveV4/merkl.js +90 -0
  5. package/cjs/claiming/aaveV3.d.ts +1 -1
  6. package/cjs/claiming/aaveV3.js +3 -4
  7. package/cjs/claiming/index.d.ts +1 -2
  8. package/cjs/claiming/index.js +1 -3
  9. package/cjs/config/contracts.d.ts +0 -214
  10. package/cjs/config/contracts.js +1 -6
  11. package/cjs/helpers/morphoBlueHelpers/index.d.ts +0 -1
  12. package/cjs/helpers/morphoBlueHelpers/index.js +27 -32
  13. package/cjs/portfolio/index.js +0 -27
  14. package/cjs/types/aaveV4.d.ts +10 -0
  15. package/cjs/types/claiming.d.ts +1 -13
  16. package/cjs/types/claiming.js +0 -2
  17. package/cjs/types/merkl.d.ts +14 -1
  18. package/cjs/types/morphoBlue.d.ts +2 -3
  19. package/esm/aaveV4/index.d.ts +1 -0
  20. package/esm/aaveV4/index.js +6 -2
  21. package/esm/aaveV4/merkl.d.ts +8 -0
  22. package/esm/aaveV4/merkl.js +85 -0
  23. package/esm/claiming/aaveV3.d.ts +1 -1
  24. package/esm/claiming/aaveV3.js +3 -4
  25. package/esm/claiming/index.d.ts +1 -2
  26. package/esm/claiming/index.js +1 -2
  27. package/esm/config/contracts.d.ts +0 -214
  28. package/esm/config/contracts.js +0 -4
  29. package/esm/helpers/morphoBlueHelpers/index.d.ts +0 -1
  30. package/esm/helpers/morphoBlueHelpers/index.js +27 -31
  31. package/esm/portfolio/index.js +0 -27
  32. package/esm/types/aaveV4.d.ts +10 -0
  33. package/esm/types/claiming.d.ts +1 -13
  34. package/esm/types/claiming.js +0 -2
  35. package/esm/types/merkl.d.ts +14 -1
  36. package/esm/types/morphoBlue.d.ts +2 -3
  37. package/package.json +1 -1
  38. package/src/aaveV4/index.ts +7 -2
  39. package/src/aaveV4/merkl.ts +92 -0
  40. package/src/claiming/aaveV3.ts +2 -3
  41. package/src/claiming/index.ts +0 -2
  42. package/src/config/contracts.ts +0 -4
  43. package/src/helpers/morphoBlueHelpers/index.ts +29 -32
  44. package/src/portfolio/index.ts +0 -25
  45. package/src/types/aaveV4.ts +10 -0
  46. package/src/types/claiming.ts +0 -15
  47. package/src/types/merkl.ts +14 -2
  48. package/src/types/morphoBlue.ts +2 -3
  49. package/cjs/claiming/morphoBlue.d.ts +0 -5
  50. package/cjs/claiming/morphoBlue.js +0 -113
  51. package/esm/claiming/morphoBlue.d.ts +0 -5
  52. package/esm/claiming/morphoBlue.js +0 -105
  53. package/src/claiming/morphoBlue.ts +0 -119
@@ -0,0 +1,92 @@
1
+ import { aprToApy } from '../moneymarket';
2
+ import { DEFAULT_TIMEOUT } from '../services/utils';
3
+ import {
4
+ AaveV4MerklRewardMap,
5
+ AaveV4ReserveAssetData,
6
+ IncentiveData,
7
+ IncentiveKind,
8
+ MerklOpportunity,
9
+ OpportunityAction,
10
+ OpportunityStatus,
11
+ } from '../types';
12
+ import { NetworkNumber } from '../types/common';
13
+
14
+ /**
15
+ * Merkl tags Aave V4 reward campaigns by scope via the `type` field:
16
+ * - AAVE_V4_HUB_SUPPLY / AAVE_V4_HUB_BORROW → reward tied to a hub (matched per underlying token)
17
+ * - AAVE_V4_SPOKE_SUPPLY / AAVE_V4_SPOKE_BORROW → reward tied to a spoke (matched per spoke contract + underlying)
18
+ * Hub campaigns identify the underlying via `tokens[0]`; spoke campaigns identify the spoke via `explorerAddress`.
19
+ */
20
+
21
+ const spokeKey = (spokeAddress: string, underlying: string) => `${spokeAddress.toLowerCase()}_${underlying.toLowerCase()}`;
22
+
23
+ const buildIncentive = (opportunity: MerklOpportunity): IncentiveData => {
24
+ const rewardToken = opportunity.rewardsRecord?.breakdowns?.[0]?.token;
25
+ const token = rewardToken?.symbol || opportunity.tokens?.[0]?.symbol || '';
26
+ return {
27
+ apy: aprToApy(opportunity.apr),
28
+ token,
29
+ incentiveKind: IncentiveKind.Reward,
30
+ description: `Eligible for ${token} rewards through Merkl.${opportunity.description ? `\n${opportunity.description}` : ''}`,
31
+ };
32
+ };
33
+
34
+ export const getAaveV4MerkleCampaigns = async (chainId: NetworkNumber): Promise<AaveV4MerklRewardMap> => {
35
+ const result: AaveV4MerklRewardMap = { hub: {}, spoke: {} };
36
+ try {
37
+ const res = await fetch('https://api-merkl.angle.money/v4/opportunities?mainProtocolId=aave', {
38
+ signal: AbortSignal.timeout(DEFAULT_TIMEOUT),
39
+ });
40
+ if (!res.ok) throw new Error('Failed to fetch Aave V4 Merkle campaigns');
41
+ const opportunities = await res.json() as MerklOpportunity[];
42
+
43
+ opportunities
44
+ .filter((o) => o.chainId === chainId)
45
+ .filter((o) => o.status === OpportunityStatus.LIVE)
46
+ .filter((o) => typeof o.type === 'string' && o.type.startsWith('AAVE_V4_'))
47
+ .forEach((o) => {
48
+ const underlying = o.tokens?.[0]?.address?.toLowerCase();
49
+ if (!underlying) return;
50
+
51
+ const side: 'supply' | 'borrow' = o.action === OpportunityAction.BORROW ? 'borrow' : 'supply';
52
+ const incentive = buildIncentive(o);
53
+
54
+ if (o.type.includes('HUB')) {
55
+ if (!result.hub[underlying]) result.hub[underlying] = {};
56
+ result.hub[underlying][side] = incentive;
57
+ } else if (o.type.includes('SPOKE')) {
58
+ const spokeAddress = o.explorerAddress?.toLowerCase();
59
+ if (!spokeAddress) return;
60
+ const key = spokeKey(spokeAddress, underlying);
61
+ if (!result.spoke[key]) result.spoke[key] = {};
62
+ result.spoke[key][side] = incentive;
63
+ }
64
+ });
65
+
66
+ return result;
67
+ } catch (e) {
68
+ console.error('Failed to fetch Aave V4 Merkle campaigns', e);
69
+ return result;
70
+ }
71
+ };
72
+
73
+ /**
74
+ * Returns a copy of the asset with scope-specific incentive arrays pre-combined with the asset's
75
+ * intrinsic (staking) incentives, so each surface can render base yield + the rewards that apply to it.
76
+ */
77
+ export const attachAaveV4MerklIncentives = (asset: AaveV4ReserveAssetData, spokeAddress: string, campaigns: AaveV4MerklRewardMap): AaveV4ReserveAssetData => {
78
+ const underlying = asset.underlying?.toLowerCase();
79
+ const baseSupply = asset.supplyIncentives || [];
80
+ const baseBorrow = asset.borrowIncentives || [];
81
+
82
+ const spokeScoped = (spokeAddress && underlying) ? campaigns.spoke[spokeKey(spokeAddress, underlying)] : undefined;
83
+ const hubScoped = underlying ? campaigns.hub[underlying] : undefined;
84
+
85
+ return {
86
+ ...asset,
87
+ spokeSupplyIncentives: spokeScoped?.supply ? [...baseSupply, spokeScoped.supply] : baseSupply,
88
+ spokeBorrowIncentives: spokeScoped?.borrow ? [...baseBorrow, spokeScoped.borrow] : baseBorrow,
89
+ hubSupplyIncentives: hubScoped?.supply ? [...baseSupply, hubScoped.supply] : baseSupply,
90
+ hubBorrowIncentives: hubScoped?.borrow ? [...baseBorrow, hubScoped.borrow] : baseBorrow,
91
+ };
92
+ };
@@ -103,7 +103,7 @@ export async function getUnclaimedRewardsForAllMarkets(
103
103
  return mapAaveRewardsToClaimableTokens(Object.values(totalUnclaimedPerRewardToken), marketAddress, walletAddress);
104
104
  }
105
105
 
106
- export async function getMeritUnclaimedRewards(account: EthAddress, network: NetworkNumber, acceptMorpho: boolean = true): Promise<ClaimableToken[]> {
106
+ export async function getMeritUnclaimedRewards(account: EthAddress, network: NetworkNumber): Promise<ClaimableToken[]> {
107
107
  let data;
108
108
  try {
109
109
  const res = await fetch(`https://api-merkl.angle.money/v4/users/${account}/rewards?chainId=${network}`,
@@ -125,8 +125,7 @@ export async function getMeritUnclaimedRewards(account: EthAddress, network: Net
125
125
  proofs,
126
126
  } = reward;
127
127
 
128
- const isTokenMorpho = token.symbol === 'MORPHO';
129
- if (!token || !token.symbol || amount === '0' || (isTokenMorpho && !acceptMorpho)) return;
128
+ if (!token || !token.symbol || amount === '0') return;
130
129
 
131
130
  const unclaimedAmount = new Dec(amount).minus(claimed || 0).toString();
132
131
  if (unclaimedAmount === '0') return;
@@ -1,13 +1,11 @@
1
1
  import * as aaveV3Claim from './aaveV3';
2
2
  import * as compV3Claim from './compV3';
3
3
  import * as kingV3Claim from './king';
4
- import * as morphoBlueClaim from './morphoBlue';
5
4
  import * as sparkClaim from './spark';
6
5
 
7
6
  export {
8
7
  aaveV3Claim,
9
8
  compV3Claim,
10
9
  kingV3Claim,
11
- morphoBlueClaim,
12
10
  sparkClaim,
13
11
  };
@@ -1264,10 +1264,6 @@ export const SparkRewardsController = {
1264
1264
  }
1265
1265
  }
1266
1266
  } as const;
1267
- export const MorphoDistributor = {
1268
- "abi": [{"inputs":[{"internalType":"address","name":"initialOwner","type":"address"},{"internalType":"uint256","name":"initialTimelock","type":"uint256"},{"internalType":"bytes32","name":"initialRoot","type":"bytes32"},{"internalType":"bytes32","name":"initialIpfsHash","type":"bytes32"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"acceptRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"reward","type":"address"},{"internalType":"uint256","name":"claimable","type":"uint256"},{"internalType":"bytes32[]","name":"proof","type":"bytes32[]"}],"name":"claim","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"reward","type":"address"}],"name":"claimed","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ipfsHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isUpdater","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingRoot","outputs":[{"internalType":"bytes32","name":"root","type":"bytes32"},{"internalType":"bytes32","name":"ipfsHash","type":"bytes32"},{"internalType":"uint256","name":"validAt","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"revokePendingRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"root","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"setOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"newRoot","type":"bytes32"},{"internalType":"bytes32","name":"newIpfsHash","type":"bytes32"}],"name":"setRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"updater","type":"address"},{"internalType":"bool","name":"active","type":"bool"}],"name":"setRootUpdater","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newTimelock","type":"uint256"}],"name":"setTimelock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"newRoot","type":"bytes32"},{"internalType":"bytes32","name":"newIpfsHash","type":"bytes32"}],"name":"submitRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"timelock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}],
1269
- "networks": {}
1270
- } as const;
1271
1267
  export const AaveRewardsController = {
1272
1268
  "abi": [{"inputs":[{"internalType":"address[]","name":"assets","type":"address[]"},{"internalType":"address","name":"user","type":"address"}],"name":"getAllUserRewards","outputs":[{"internalType":"address[]","name":"rewardsList","type":"address[]"},{"internalType":"uint256[]","name":"unclaimedAmounts","type":"uint256[]"}],"stateMutability":"view","type":"function"}],
1273
1269
  "networks": {
@@ -146,12 +146,14 @@ export const getApyAfterValuesEstimation = async (selectedMarket: MorphoBlueMark
146
146
  return { borrowRate, supplyRate };
147
147
  };
148
148
 
149
- const API_URL = 'https://blue-api.morpho.org/graphql';
149
+ const API_URL = 'https://api.morpho.org/graphql';
150
+ // Morpho Blue ACRM (Adaptive Curve IRM) always targets 90% utilization — protocol constant
151
+ const ACRM_TARGET_UTILIZATION = '900000000000000000';
152
+
150
153
  const MARKET_QUERY = `
151
- query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
152
- marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
154
+ query MarketByUniqueKey($marketId: String!, $chainId: Int!) {
155
+ marketById(marketId: $marketId, chainId: $chainId) {
153
156
  reallocatableLiquidityAssets
154
- targetBorrowUtilization
155
157
  loanAsset {
156
158
  address
157
159
  decimals
@@ -168,8 +170,8 @@ const MARKET_QUERY = `
168
170
  address
169
171
  name
170
172
  }
171
- allocationMarket {
172
- uniqueKey
173
+ withdrawMarket {
174
+ marketId
173
175
  loanAsset {
174
176
  address
175
177
  }
@@ -193,15 +195,15 @@ const MARKET_QUERY = `
193
195
  address
194
196
  }
195
197
  irmAddress
196
- lltv
198
+ lltv
197
199
  }
198
200
  }
199
201
  `;
200
202
 
201
203
  const REWARDS_QUERY = `
202
- query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
203
- marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
204
- uniqueKey
204
+ query MarketByUniqueKey($marketId: String!, $chainId: Int!) {
205
+ marketById(marketId: $marketId, chainId: $chainId) {
206
+ marketId
205
207
  state {
206
208
  rewards {
207
209
  amountPerSuppliedToken
@@ -230,19 +232,19 @@ export const getReallocatableLiquidity = async (marketId: string, network: Netwo
230
232
  headers: { 'Content-Type': 'application/json' },
231
233
  body: JSON.stringify({
232
234
  query: MARKET_QUERY,
233
- variables: { uniqueKey: marketId, chainId: network },
235
+ variables: { marketId, chainId: network },
234
236
  }),
235
237
  signal: AbortSignal.timeout(LONGER_TIMEOUT),
236
238
  });
237
239
 
238
- const data: { data: { marketByUniqueKey: MorphoBlueRealloactionMarketData } } = await response.json();
239
- const marketData: MorphoBlueRealloactionMarketData = data?.data?.marketByUniqueKey;
240
+ const data: { data: { marketById: MorphoBlueRealloactionMarketData } } = await response.json();
241
+ const marketData: MorphoBlueRealloactionMarketData = data?.data?.marketById;
240
242
 
241
243
  if (!marketData) throw new Error('Market data not found');
242
244
 
243
245
  return {
244
246
  reallocatableLiquidity: marketData.reallocatableLiquidityAssets,
245
- targetBorrowUtilization: marketData.targetBorrowUtilization,
247
+ targetBorrowUtilization: ACRM_TARGET_UTILIZATION,
246
248
  };
247
249
  } catch (error) {
248
250
  console.error('External API Failure: Morpho blue reallocatable liquidity', error);
@@ -295,13 +297,13 @@ export const getReallocation = async (market: MorphoBlueMarketData, assetsData:
295
297
  headers: { 'Content-Type': 'application/json' },
296
298
  body: JSON.stringify({
297
299
  query: MARKET_QUERY,
298
- variables: { uniqueKey: marketId, chainId: network },
300
+ variables: { marketId, chainId: network },
299
301
  }),
300
302
  signal: AbortSignal.timeout(LONGER_TIMEOUT),
301
303
  });
302
304
 
303
- const data: { data: { marketByUniqueKey: MorphoBlueRealloactionMarketData } } = await response.json();
304
- const marketData: MorphoBlueRealloactionMarketData = data?.data?.marketByUniqueKey;
305
+ const data: { data: { marketById: MorphoBlueRealloactionMarketData } } = await response.json();
306
+ const marketData: MorphoBlueRealloactionMarketData = data?.data?.marketById;
305
307
 
306
308
  if (!marketData) throw new Error('Market data not found');
307
309
 
@@ -315,9 +317,9 @@ export const getReallocation = async (market: MorphoBlueMarketData, assetsData:
315
317
  const newUtil = new Dec(newTotalBorrowAssets).div(totalSupplyWei).toString();
316
318
  const newUtilScaled = new Dec(newUtil).mul(1e18).toString();
317
319
 
318
- if (new Dec(newUtilScaled).lt(marketData.targetBorrowUtilization)) return { vaults: [], withdrawals: [] };
320
+ if (new Dec(newUtilScaled).lt(ACRM_TARGET_UTILIZATION)) return { vaults: [], withdrawals: [] };
319
321
 
320
- const liquidityToAllocate = getLiquidityToAllocate(amountToBorrow, totalBorrowWei, totalSupplyWei, marketData.targetBorrowUtilization, marketData.reallocatableLiquidityAssets);
322
+ const liquidityToAllocate = getLiquidityToAllocate(amountToBorrow, totalBorrowWei, totalSupplyWei, ACRM_TARGET_UTILIZATION, marketData.reallocatableLiquidityAssets);
321
323
 
322
324
  const vaultTotalAssets = marketData.publicAllocatorSharedLiquidity.reduce(
323
325
  (acc: Record<string, string>, item: MorphoBluePublicAllocatorItem) => {
@@ -348,14 +350,14 @@ export const getReallocation = async (market: MorphoBlueMarketData, assetsData:
348
350
  totalReallocated = new Dec(totalReallocated).add(amountToTake).toString();
349
351
  const withdrawal: [string[], string, string] = [
350
352
  [
351
- item.allocationMarket.loanAsset.address,
352
- item.allocationMarket.collateralAsset?.address,
353
- item.allocationMarket.oracle?.address,
354
- item.allocationMarket.irmAddress,
355
- item.allocationMarket.lltv,
353
+ item.withdrawMarket.loanAsset.address,
354
+ item.withdrawMarket.collateralAsset?.address,
355
+ item.withdrawMarket.oracle?.address,
356
+ item.withdrawMarket.irmAddress,
357
+ item.withdrawMarket.lltv,
356
358
  ],
357
359
  amountToTake.toString(),
358
- item.allocationMarket.uniqueKey,
360
+ item.withdrawMarket.marketId,
359
361
  ];
360
362
  if (!withdrawalsPerVault[vaultAddress]) {
361
363
  withdrawalsPerVault[vaultAddress] = [];
@@ -386,12 +388,12 @@ export const getRewardsForMarket = async (marketId: string, network: NetworkNumb
386
388
  headers: { 'Content-Type': 'application/json' },
387
389
  body: JSON.stringify({
388
390
  query: REWARDS_QUERY,
389
- variables: { uniqueKey: marketId, chainId: network },
391
+ variables: { marketId, chainId: network },
390
392
  }),
391
393
  });
392
394
 
393
395
  const data = await response.json();
394
- const marketData = data?.data?.marketByUniqueKey;
396
+ const marketData = data?.data?.marketById;
395
397
  if (!marketData) throw new Error('Market data not found');
396
398
  const morphoAssetInfo = getAssetInfo('MORPHO');
397
399
  const { supplyApr, borrowApr } = marketData.state.rewards.find((reward: any) => compareAddresses(reward.asset.address, morphoAssetInfo.addresses[network])) || { supplyApr: '0', borrowApr: '0' };
@@ -399,8 +401,3 @@ export const getRewardsForMarket = async (marketId: string, network: NetworkNumb
399
401
  const borrowAprPercent = new Dec(borrowApr).mul(100).toString();
400
402
  return { supplyApy: aprToApy(supplyAprPercent), borrowApy: aprToApy(borrowAprPercent) };
401
403
  };
402
-
403
- export const getMorphoUnderlyingSymbol = (_symbol: string) => {
404
- if (_symbol === 'MORPHO Legacy') return 'MORPHO';
405
- return wethToEth(_symbol);
406
- };
@@ -48,7 +48,6 @@ import { getUmbrellaData } from '../umbrella';
48
48
  import { getMeritUnclaimedRewards, getUnclaimedRewardsForAllMarkets } from '../claiming/aaveV3';
49
49
  import { getCompoundV3Rewards } from '../claiming/compV3';
50
50
  import { fetchSparkAirdropRewards, fetchSparkRewards } from '../claiming/spark';
51
- import { fetchMorphoBlueRewards } from '../claiming/morphoBlue';
52
51
  import { getKingRewards } from '../claiming/king';
53
52
  import { fetchEthenaAirdropRewards } from '../claiming/ethena';
54
53
  import { _getAaveV4AccountData, _getAaveV4SpokeData } from '../aaveV4';
@@ -61,7 +60,6 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
61
60
  }> {
62
61
  const isMainnet = network === NetworkNumber.Eth;
63
62
  const isFluidSupported = [NetworkNumber.Eth, NetworkNumber.Arb, NetworkNumber.Base, NetworkNumber.Plasma].includes(network);
64
- const isMorphoRewardsSupported = [NetworkNumber.Eth, NetworkNumber.Base].includes(network);
65
63
 
66
64
  const morphoMarkets = Object.values(MorphoBlueMarkets(network)).filter((market) => market.chainIds.includes(network));
67
65
  const compoundV3Markets = Object.values(CompoundMarkets(network)).filter((market) => market.chainIds.includes(network) && market.value !== CompoundVersions.CompoundV2);
@@ -157,7 +155,6 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
157
155
  spark: {},
158
156
  spk: {},
159
157
  king: {},
160
- morpho: {},
161
158
  ethena: {},
162
159
  };
163
160
  }
@@ -354,28 +351,6 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
354
351
  rewardsData[address.toLowerCase() as EthAddress].aaveV3 = { error: `Error fetching Aave V3 rewards data for address ${address}`, data: null };
355
352
  }
356
353
  })).flat(),
357
- // Batch Morpho Blue rewards
358
- (async () => {
359
- if (!isMorphoRewardsSupported) return;
360
- try {
361
- const morphoRewards = await fetchMorphoBlueRewards(client, network, addresses);
362
- for (const address of addresses) {
363
- const lowerAddress = address.toLowerCase() as EthAddress;
364
- rewardsData[lowerAddress].morpho = {
365
- error: '',
366
- data: morphoRewards[lowerAddress] || [],
367
- };
368
- }
369
- } catch (error) {
370
- console.error('Error fetching Morpho Blue rewards data in batch:', error);
371
- for (const address of addresses) {
372
- rewardsData[address.toLowerCase() as EthAddress].morpho = {
373
- error: 'Error fetching Morpho Blue rewards data in batch',
374
- data: null,
375
- };
376
- }
377
- }
378
- })(),
379
354
  // Batch Spark Airdrop rewards
380
355
  (async () => {
381
356
  try {
@@ -111,6 +111,16 @@ export interface AaveV4ReserveAssetData {
111
111
  borrowRate: string,
112
112
  supplyIncentives: IncentiveData[];
113
113
  borrowIncentives: IncentiveData[];
114
+ /**
115
+ * Intrinsic incentives pre-combined with scope-specific Merkl rewards, ready to render per surface:
116
+ * - spoke* → spoke supply/borrow (Create page + dashboard market table)
117
+ * - hub* → hub supply/borrow (Lend page)
118
+ * `supplyIncentives`/`borrowIncentives` above remain intrinsic-only so the net-APY calc is unaffected.
119
+ */
120
+ spokeSupplyIncentives?: IncentiveData[];
121
+ spokeBorrowIncentives?: IncentiveData[];
122
+ hubSupplyIncentives?: IncentiveData[];
123
+ hubBorrowIncentives?: IncentiveData[];
114
124
  canBeBorrowed: boolean;
115
125
  canBeSupplied: boolean;
116
126
  canBeWithdrawn: boolean;
@@ -9,8 +9,6 @@ export enum ClaimType {
9
9
  COMPOUND_V3_COMP = 'COMPOUND_V3_COMP',
10
10
  /** Rewards from Spark (wstETH only for now) */
11
11
  SPARK_REWARDS = 'SPARK_REWARDS',
12
- /** Rewards from Morpho */
13
- MORPHO = 'MORPHO',
14
12
  /** Rewards from King (prev LTR^2 - received for weETH holding) */
15
13
  KING_REWARDS = 'KING_REWARDS',
16
14
  /** Spark Airdrop */
@@ -63,18 +61,6 @@ export type KingRewardsClaimableToken = _ClaimableTokenPartial & {
63
61
  };
64
62
  };
65
63
 
66
- export type MorphoClaimableToken = _ClaimableTokenPartial & {
67
- claimType: ClaimType.MORPHO,
68
- additionalClaimFields: {
69
- originalAmount: string,
70
- merkleProofs: string[];
71
- distributor: EthAddress;
72
- isLegacy: boolean;
73
- txData: string;
74
- }
75
- };
76
-
77
-
78
64
  export type CompoundV3CompClaimableToken = _ClaimableTokenPartial & {
79
65
  claimType: ClaimType.COMPOUND_V3_COMP,
80
66
  additionalClaimFields: {
@@ -106,7 +92,6 @@ export type ClaimableToken =
106
92
  AaveRewardsClaimableToken
107
93
  | AaveMeritRewardsClaimableToken
108
94
  | CompoundV3CompClaimableToken
109
- | MorphoClaimableToken
110
95
  | SparkRewardsClaimableToken
111
96
  | KingRewardsClaimableToken
112
97
  | SparkAirdropClaimableToken
@@ -1,4 +1,4 @@
1
- import { EthAddress } from './common';
1
+ import { EthAddress, IncentiveData } from './common';
2
2
 
3
3
  export enum OpportunityAction {
4
4
  LEND = 'LEND',
@@ -68,4 +68,16 @@ export type MerklOpportunity = {
68
68
  };
69
69
 
70
70
  export type MerkleRewardInfo = { apy: string; rewardTokenSymbol: string, description: string, identifier: string };
71
- export type MerkleRewardMap = Record<EthAddress, { supply?: MerkleRewardInfo; borrow?: MerkleRewardInfo }>;
71
+ export type MerkleRewardMap = Record<EthAddress, { supply?: MerkleRewardInfo; borrow?: MerkleRewardInfo }>;
72
+
73
+ export type AaveV4MerklScopedReward = { supply?: IncentiveData; borrow?: IncentiveData };
74
+
75
+ /**
76
+ * Aave V4 Merkl reward campaigns split by scope:
77
+ * - `hub`: keyed by underlying token address (lowercase) — rewards for supplying to a hub
78
+ * - `spoke`: keyed by `${spokeAddress}_${underlyingAddress}` (both lowercase) — rewards for supplying/borrowing on a spoke
79
+ */
80
+ export type AaveV4MerklRewardMap = {
81
+ hub: Record<string, AaveV4MerklScopedReward>;
82
+ spoke: Record<string, AaveV4MerklScopedReward>;
83
+ };
@@ -206,13 +206,13 @@ export interface MorphoBlueAllocationMarket {
206
206
  oracle: { address: string },
207
207
  irmAddress: string,
208
208
  lltv: string,
209
- uniqueKey: string,
209
+ marketId: string,
210
210
  }
211
211
 
212
212
  export interface MorphoBluePublicAllocatorItem {
213
213
  vault: MorphoBlueVault,
214
214
  assets: string,
215
- allocationMarket: MorphoBlueAllocationMarket,
215
+ withdrawMarket: MorphoBlueAllocationMarket,
216
216
  }
217
217
 
218
218
  export interface MorphoBlueAllocatorMarketState {
@@ -222,7 +222,6 @@ export interface MorphoBlueAllocatorMarketState {
222
222
 
223
223
  export interface MorphoBlueRealloactionMarketData {
224
224
  reallocatableLiquidityAssets: string,
225
- targetBorrowUtilization: string,
226
225
  publicAllocatorSharedLiquidity: MorphoBluePublicAllocatorItem[],
227
226
  state: MorphoBlueAllocatorMarketState,
228
227
  }
@@ -1,5 +0,0 @@
1
- import { Client } from 'viem';
2
- import { ClaimableToken } from '../types/claiming';
3
- import { EthAddress, NetworkNumber } from '../types/common';
4
- export declare const getMorphoBlueRewardsInfo: (address: EthAddress) => Promise<any>;
5
- export declare const fetchMorphoBlueRewards: (provider: Client, network: NetworkNumber, walletAddresses: EthAddress[]) => Promise<Record<string, ClaimableToken[]>>;
@@ -1,113 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.fetchMorphoBlueRewards = exports.getMorphoBlueRewardsInfo = void 0;
16
- const tokens_1 = require("@defisaver/tokens");
17
- const decimal_js_1 = __importDefault(require("decimal.js"));
18
- const claiming_1 = require("../types/claiming");
19
- const contracts_1 = require("../contracts");
20
- const morphoBlueHelpers_1 = require("../helpers/morphoBlueHelpers");
21
- const MORPHO_ALLOWED_CONTRACTS = [
22
- '0x330eefa8a787552DC5cAd3C3cA644844B1E61Ddb',
23
- '0x678dDC1d07eaa166521325394cDEb1E4c086DF43',
24
- '0x2efd4625d0c149ebadf118ec5446c6de24d916a4',
25
- ];
26
- const MORPHO_ALLOWED_TOKENS = [
27
- 'MORPHO',
28
- 'MORPHO Legacy',
29
- ];
30
- const getMorphoBlueRewardsInfo = (address) => __awaiter(void 0, void 0, void 0, function* () {
31
- if (!address)
32
- return { claimable: '0' };
33
- try {
34
- const res = yield fetch(`https://rewards.morpho.org/v1/users/${address}/distributions`, { signal: AbortSignal.timeout(3000) });
35
- if (!res.ok)
36
- throw new Error(yield res.text());
37
- return yield res.json();
38
- }
39
- catch (error) {
40
- console.error('External API Failure: Morpho Merit', error);
41
- return { claimable: '0' };
42
- }
43
- });
44
- exports.getMorphoBlueRewardsInfo = getMorphoBlueRewardsInfo;
45
- const fetchMorphoBlueRewards = (provider, network, walletAddresses) => __awaiter(void 0, void 0, void 0, function* () {
46
- var _a;
47
- // Fetch all API data in parallel (these are external API calls, can't be batched with multicall)
48
- const apiDataPromises = walletAddresses.map(address => (0, exports.getMorphoBlueRewardsInfo)(address));
49
- const apiDataArray = yield Promise.all(apiDataPromises);
50
- // Process API data to get claimable tokens for each wallet
51
- const allClaimableTokens = [];
52
- const contractCallsData = [];
53
- for (let i = 0; i < walletAddresses.length; i++) {
54
- const walletAddress = walletAddresses[i];
55
- const data = apiDataArray[i];
56
- const claimableTokens = ((_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.reduce((acc, reward) => {
57
- var _a, _b, _c;
58
- const token = (0, tokens_1.getAssetInfoByAddress)(reward.asset.address);
59
- if (!MORPHO_ALLOWED_CONTRACTS.includes((_a = reward === null || reward === void 0 ? void 0 : reward.distributor) === null || _a === void 0 ? void 0 : _a.address) || !MORPHO_ALLOWED_TOKENS.includes(token.symbol)) {
60
- return acc;
61
- }
62
- // Store contract call data for batching
63
- contractCallsData.push({
64
- walletAddress,
65
- tokenAddress: reward.asset.address,
66
- distributor: (_b = reward === null || reward === void 0 ? void 0 : reward.distributor) === null || _b === void 0 ? void 0 : _b.address,
67
- });
68
- return [
69
- ...acc,
70
- {
71
- symbol: token.symbol,
72
- underlyingSymbol: (0, morphoBlueHelpers_1.getMorphoUnderlyingSymbol)(token.symbol),
73
- tokenAddress: reward.asset.address,
74
- amount: (0, tokens_1.assetAmountInEth)(reward.claimable, token.symbol),
75
- walletAddress,
76
- label: token.symbol,
77
- claimType: claiming_1.ClaimType.MORPHO,
78
- additionalClaimFields: {
79
- originalAmount: reward.claimable,
80
- distributor: (_c = reward === null || reward === void 0 ? void 0 : reward.distributor) === null || _c === void 0 ? void 0 : _c.address,
81
- merkleProofs: reward === null || reward === void 0 ? void 0 : reward.proof,
82
- isLegacy: token.symbol === 'MORPHO Legacy',
83
- txData: reward === null || reward === void 0 ? void 0 : reward.tx_data,
84
- },
85
- }
86
- ];
87
- }, [])) || [];
88
- allClaimableTokens.push({ walletAddress, tokens: claimableTokens });
89
- }
90
- // Batch all contract calls using multicall
91
- const contractPromises = contractCallsData.map(({ walletAddress, tokenAddress, distributor }) => {
92
- const distributorContract = (0, contracts_1.createViemContractFromConfigFunc)('MorphoDistributor', distributor)(provider, network);
93
- return distributorContract.read.claimed([walletAddress, tokenAddress]);
94
- });
95
- const contractResults = yield Promise.all(contractPromises);
96
- // Process results
97
- const results = {};
98
- let contractCallIndex = 0;
99
- for (const { walletAddress, tokens } of allClaimableTokens) {
100
- const updatedTokens = [];
101
- for (let i = 0; i < tokens.length; i++) {
102
- const claimableToken = tokens[i];
103
- const claimed = (0, tokens_1.assetAmountInEth)(contractResults[contractCallIndex].toString(), claimableToken.underlyingSymbol);
104
- contractCallIndex++;
105
- const updatedToken = Object.assign({}, claimableToken);
106
- updatedToken.amount = new decimal_js_1.default(claimableToken.amount).sub(claimed).toString();
107
- updatedTokens.push(updatedToken);
108
- }
109
- results[walletAddress.toLowerCase()] = updatedTokens.filter((claimableToken) => new decimal_js_1.default(claimableToken.amount).gt(0));
110
- }
111
- return results;
112
- });
113
- exports.fetchMorphoBlueRewards = fetchMorphoBlueRewards;
@@ -1,5 +0,0 @@
1
- import { Client } from 'viem';
2
- import { ClaimableToken } from '../types/claiming';
3
- import { EthAddress, NetworkNumber } from '../types/common';
4
- export declare const getMorphoBlueRewardsInfo: (address: EthAddress) => Promise<any>;
5
- export declare const fetchMorphoBlueRewards: (provider: Client, network: NetworkNumber, walletAddresses: EthAddress[]) => Promise<Record<string, ClaimableToken[]>>;