@defisaver/positions-sdk 2.1.104 → 2.1.106-sgho-dev

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/aaveV3/index.d.ts +3 -0
  2. package/cjs/aaveV3/index.js +7 -2
  3. package/cjs/aaveV3/sgho.d.ts +18 -0
  4. package/cjs/aaveV3/sgho.js +95 -0
  5. package/cjs/aaveV4/index.js +53 -20
  6. package/cjs/claiming/aaveV3.d.ts +1 -1
  7. package/cjs/claiming/aaveV3.js +3 -4
  8. package/cjs/claiming/index.d.ts +1 -2
  9. package/cjs/claiming/index.js +1 -3
  10. package/cjs/config/contracts.d.ts +0 -214
  11. package/cjs/config/contracts.js +1 -6
  12. package/cjs/helpers/morphoBlueHelpers/index.d.ts +0 -1
  13. package/cjs/helpers/morphoBlueHelpers/index.js +27 -32
  14. package/cjs/portfolio/index.js +0 -27
  15. package/cjs/types/aaveV4.d.ts +9 -0
  16. package/cjs/types/claiming.d.ts +1 -13
  17. package/cjs/types/claiming.js +0 -2
  18. package/cjs/types/morphoBlue.d.ts +2 -3
  19. package/esm/aaveV3/index.d.ts +3 -0
  20. package/esm/aaveV3/index.js +5 -1
  21. package/esm/aaveV3/sgho.d.ts +18 -0
  22. package/esm/aaveV3/sgho.js +88 -0
  23. package/esm/aaveV4/index.js +53 -20
  24. package/esm/claiming/aaveV3.d.ts +1 -1
  25. package/esm/claiming/aaveV3.js +3 -4
  26. package/esm/claiming/index.d.ts +1 -2
  27. package/esm/claiming/index.js +1 -2
  28. package/esm/config/contracts.d.ts +0 -214
  29. package/esm/config/contracts.js +0 -4
  30. package/esm/helpers/morphoBlueHelpers/index.d.ts +0 -1
  31. package/esm/helpers/morphoBlueHelpers/index.js +27 -31
  32. package/esm/portfolio/index.js +0 -27
  33. package/esm/types/aaveV4.d.ts +9 -0
  34. package/esm/types/claiming.d.ts +1 -13
  35. package/esm/types/claiming.js +0 -2
  36. package/esm/types/morphoBlue.d.ts +2 -3
  37. package/package.json +2 -2
  38. package/src/aaveV3/index.ts +7 -1
  39. package/src/aaveV3/sgho.ts +100 -0
  40. package/src/aaveV4/index.ts +48 -20
  41. package/src/claiming/aaveV3.ts +2 -3
  42. package/src/claiming/index.ts +0 -2
  43. package/src/config/contracts.ts +0 -4
  44. package/src/helpers/morphoBlueHelpers/index.ts +29 -32
  45. package/src/portfolio/index.ts +0 -25
  46. package/src/types/aaveV4.ts +9 -0
  47. package/src/types/claiming.ts +0 -15
  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
@@ -8,8 +8,6 @@ export declare enum ClaimType {
8
8
  COMPOUND_V3_COMP = "COMPOUND_V3_COMP",
9
9
  /** Rewards from Spark (wstETH only for now) */
10
10
  SPARK_REWARDS = "SPARK_REWARDS",
11
- /** Rewards from Morpho */
12
- MORPHO = "MORPHO",
13
11
  /** Rewards from King (prev LTR^2 - received for weETH holding) */
14
12
  KING_REWARDS = "KING_REWARDS",
15
13
  /** Spark Airdrop */
@@ -57,16 +55,6 @@ export type KingRewardsClaimableToken = _ClaimableTokenPartial & {
57
55
  merkleProofs: string[];
58
56
  };
59
57
  };
60
- export type MorphoClaimableToken = _ClaimableTokenPartial & {
61
- claimType: ClaimType.MORPHO;
62
- additionalClaimFields: {
63
- originalAmount: string;
64
- merkleProofs: string[];
65
- distributor: EthAddress;
66
- isLegacy: boolean;
67
- txData: string;
68
- };
69
- };
70
58
  export type CompoundV3CompClaimableToken = _ClaimableTokenPartial & {
71
59
  claimType: ClaimType.COMPOUND_V3_COMP;
72
60
  additionalClaimFields: {
@@ -93,5 +81,5 @@ export type SparkWstEthRewardsClaimableToken = _ClaimableTokenPartial & {
93
81
  export type EthenaAirdropClaimableToken = _ClaimableTokenPartial & {
94
82
  claimType: ClaimType.ETHENA_AIRDROP;
95
83
  };
96
- export type ClaimableToken = AaveRewardsClaimableToken | AaveMeritRewardsClaimableToken | CompoundV3CompClaimableToken | MorphoClaimableToken | SparkRewardsClaimableToken | KingRewardsClaimableToken | SparkAirdropClaimableToken | SparkWstEthRewardsClaimableToken | EthenaAirdropClaimableToken;
84
+ export type ClaimableToken = AaveRewardsClaimableToken | AaveMeritRewardsClaimableToken | CompoundV3CompClaimableToken | SparkRewardsClaimableToken | KingRewardsClaimableToken | SparkAirdropClaimableToken | SparkWstEthRewardsClaimableToken | EthenaAirdropClaimableToken;
97
85
  export {};
@@ -8,8 +8,6 @@ export var ClaimType;
8
8
  ClaimType["COMPOUND_V3_COMP"] = "COMPOUND_V3_COMP";
9
9
  /** Rewards from Spark (wstETH only for now) */
10
10
  ClaimType["SPARK_REWARDS"] = "SPARK_REWARDS";
11
- /** Rewards from Morpho */
12
- ClaimType["MORPHO"] = "MORPHO";
13
11
  /** Rewards from King (prev LTR^2 - received for weETH holding) */
14
12
  ClaimType["KING_REWARDS"] = "KING_REWARDS";
15
13
  /** Spark Airdrop */
@@ -189,12 +189,12 @@ export interface MorphoBlueAllocationMarket {
189
189
  };
190
190
  irmAddress: string;
191
191
  lltv: string;
192
- uniqueKey: string;
192
+ marketId: string;
193
193
  }
194
194
  export interface MorphoBluePublicAllocatorItem {
195
195
  vault: MorphoBlueVault;
196
196
  assets: string;
197
- allocationMarket: MorphoBlueAllocationMarket;
197
+ withdrawMarket: MorphoBlueAllocationMarket;
198
198
  }
199
199
  export interface MorphoBlueAllocatorMarketState {
200
200
  borrowAssets: string;
@@ -202,7 +202,6 @@ export interface MorphoBlueAllocatorMarketState {
202
202
  }
203
203
  export interface MorphoBlueRealloactionMarketData {
204
204
  reallocatableLiquidityAssets: string;
205
- targetBorrowUtilization: string;
206
205
  publicAllocatorSharedLiquidity: MorphoBluePublicAllocatorItem[];
207
206
  state: MorphoBlueAllocatorMarketState;
208
207
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/positions-sdk",
3
- "version": "2.1.104",
3
+ "version": "2.1.106-sgho-dev",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -21,7 +21,7 @@
21
21
  "author": "",
22
22
  "license": "ISC",
23
23
  "dependencies": {
24
- "@defisaver/tokens": "^1.7.35",
24
+ "@defisaver/tokens": "1.7.35-sgho-dev",
25
25
  "@types/lodash": "^4.17.15",
26
26
  "@types/memoizee": "^0.4.12",
27
27
  "decimal.js": "^10.6.0",
@@ -44,6 +44,7 @@ import {
44
44
  import { getViemProvider, setViemBlockNumber } from '../services/viem';
45
45
  import { getMeritCampaigns } from './merit';
46
46
  import { getAaveUnderlyingSymbol, getMerkleCampaigns } from './merkl';
47
+ import { getSghoData } from './sgho';
47
48
  import { SECONDS_PER_YEAR } from '../constants';
48
49
 
49
50
  export const aaveV3EmodeCategoriesMapping = (extractedState: any, usedAssets: AaveV3UsedAssets) => {
@@ -604,13 +605,14 @@ export const getStakeAaveData = async (provider: Client, network: NetworkNumber,
604
605
  const stkGHO = createViemContractFromConfigFunc('Erc20', stkGhoAddress as HexString)(provider, network);
605
606
 
606
607
 
607
- const [aaveRewardsBalance, emissionsPerSecond, stkAAVEBalance, stkAAVETotalSupply, stkGHOBalance, ghoMeritApy] = await Promise.all([
608
+ const [aaveRewardsBalance, emissionsPerSecond, stkAAVEBalance, stkAAVETotalSupply, stkGHOBalance, ghoMeritApy, sgho] = await Promise.all([
608
609
  AaveIncentivesController.read.getRewardsBalance([REWARDABLE_ASSETS, address]),
609
610
  stkAAVE.read.assets([stkAaveAddress]),
610
611
  stkAAVE.read.balanceOf([address]),
611
612
  stkAAVE.read.totalSupply(),
612
613
  stkGHO.read.balanceOf([address]),
613
614
  fetchYearlyMeritApyForStakingGho(),
615
+ getSghoData(network, address),
614
616
  ]);
615
617
 
616
618
 
@@ -625,6 +627,7 @@ export const getStakeAaveData = async (provider: Client, network: NetworkNumber,
625
627
  stkGhoBalance: assetAmountInEth(stkGHOBalance.toString(), 'GHO'),
626
628
  ghoMeritApy,
627
629
  stkAaveApy,
630
+ sgho,
628
631
  };
629
632
  };
630
633
 
@@ -632,3 +635,6 @@ export {
632
635
  getMeritCampaigns,
633
636
  getMerkleCampaigns,
634
637
  };
638
+
639
+ export { getSghoData } from './sgho';
640
+ export type { SghoData, SghoUserData } from './sgho';
@@ -0,0 +1,100 @@
1
+ import Dec from 'decimal.js';
2
+ import { EthAddress, NetworkNumber } from '../types/common';
3
+ import { DEFAULT_TIMEOUT } from '../services/utils';
4
+ import { ZERO_ADDRESS } from '../constants';
5
+
6
+ export interface SghoUserData {
7
+ shares: string;
8
+ balance: string;
9
+ maxDeposit: string;
10
+ maxWithdraw: string;
11
+ underlyingBalance: string;
12
+ }
13
+
14
+ export interface SghoData {
15
+ totalAssets: string;
16
+ totalSupply: string;
17
+ supplyCap: string;
18
+ /** Target savings rate as an APY percent (e.g. "4.25" for 4.25%). */
19
+ targetRate: string;
20
+ paused: boolean;
21
+ user: SghoUserData;
22
+ }
23
+
24
+ const EMPTY_SGHO_DATA: SghoData = {
25
+ totalAssets: '0',
26
+ totalSupply: '0',
27
+ supplyCap: '0',
28
+ targetRate: '0',
29
+ paused: false,
30
+ user: {
31
+ shares: '0',
32
+ balance: '0',
33
+ maxDeposit: '0',
34
+ maxWithdraw: '0',
35
+ underlyingBalance: '0',
36
+ },
37
+ };
38
+
39
+ const SGHO_VAULT_QUERY = `query SghoVault($request: SghoVaultRequest!) {
40
+ value: sghoVault(request: $request) {
41
+ totalAssets { amount { value } }
42
+ totalSupply { value }
43
+ supplyCap { amount { value } }
44
+ targetRate { value }
45
+ paused
46
+ user {
47
+ shares { amount { value } }
48
+ balance { amount { value } }
49
+ maxDeposit { amount { value } }
50
+ maxWithdraw { amount { value } }
51
+ underlyingBalance { amount { value } }
52
+ }
53
+ }
54
+ }`;
55
+
56
+ const tokenAmountValue = (entry: any): string => entry?.amount?.value?.toString() || '0';
57
+ const decimalValue = (entry: any): string => entry?.value?.toString() || '0';
58
+ // Aave returns the rate as a ratio (e.g. 0.0425); consumers display/compound it as a percent (4.25).
59
+ const percentValue = (entry: any): string => (entry?.value != null ? new Dec(entry.value).mul(100).toString() : '0');
60
+
61
+ export const getSghoData = async (
62
+ network: NetworkNumber,
63
+ address: EthAddress = ZERO_ADDRESS,
64
+ ): Promise<SghoData> => {
65
+ if (network !== NetworkNumber.Eth) return EMPTY_SGHO_DATA;
66
+ try {
67
+ const res = await fetch('https://api.v3.aave.com/graphql', {
68
+ method: 'POST',
69
+ headers: { 'Content-Type': 'application/json' },
70
+ body: JSON.stringify({
71
+ operationName: 'SghoVault',
72
+ query: SGHO_VAULT_QUERY,
73
+ variables: { request: { chainId: 1, user: address } },
74
+ }),
75
+ signal: AbortSignal.timeout(DEFAULT_TIMEOUT),
76
+ });
77
+ if (!res.ok) throw new Error(`Aave SghoVault request failed: ${res.status}`);
78
+ const body = await res.json();
79
+ const data = body?.data?.value;
80
+ if (!data) throw new Error('Aave SghoVault response missing data');
81
+
82
+ return {
83
+ totalAssets: tokenAmountValue(data.totalAssets),
84
+ totalSupply: decimalValue(data.totalSupply),
85
+ supplyCap: tokenAmountValue(data.supplyCap),
86
+ targetRate: percentValue(data.targetRate),
87
+ paused: !!data.paused,
88
+ user: {
89
+ shares: tokenAmountValue(data?.user?.shares),
90
+ balance: tokenAmountValue(data?.user?.balance),
91
+ maxDeposit: tokenAmountValue(data?.user?.maxDeposit),
92
+ maxWithdraw: tokenAmountValue(data?.user?.maxWithdraw),
93
+ underlyingBalance: tokenAmountValue(data?.user?.underlyingBalance),
94
+ },
95
+ };
96
+ } catch (e) {
97
+ console.error('External API Failure: Failed to fetch Aave sGHO vault data', e);
98
+ return EMPTY_SGHO_DATA;
99
+ }
100
+ };
@@ -50,6 +50,9 @@ const fetchHubData = async (viewContract: ReturnType<typeof AaveV4ViewContractVi
50
50
 
51
51
  const formatReserveAsset = async (reserveAsset: AaveV4ReserveAssetOnChain, hubAsset: AaveV4HubAssetOnChainData, reserveId: number, oracleDecimals: number, network: NetworkNumber): Promise<AaveV4ReserveAssetData> => {
52
52
  const assetInfo = getAssetInfoByAddress(reserveAsset.underlying, network);
53
+ // `@defisaver/tokens` returns a placeholder ('?', decimals NaN) when the underlying is not in the
54
+ // tokens package. Flag it so consumers can render it read-only instead of feeding NaN into amounts.
55
+ const isUnsupported = assetInfo.symbol === '?';
53
56
  const symbol = wethToEth(assetInfo.symbol);
54
57
  const hubInfo = getAaveV4HubByAddress(network, reserveAsset.hub);
55
58
  if (!hubInfo) {
@@ -101,11 +104,23 @@ const formatReserveAsset = async (reserveAsset: AaveV4ReserveAssetOnChain, hubAs
101
104
  const supplyApr = borrowApr.mul(hubUtilization).mul(premiumMultiplier).mul(new Dec(1).minus(liquidityFee));
102
105
  const utilization = hubUtilization.times(100).toString();
103
106
 
107
+ // For unsupported assets `symbol` is '?' (decimals NaN in `@defisaver/tokens`), so the
108
+ // symbol-based conversion would produce NaN. Fall back to the on-chain `decimals` so the reserve
109
+ // still shows correct amounts (and feeds correct USD/ratio/liquidation math) in read-only mode.
110
+ const toEth = (raw: string | number | bigint) => {
111
+ const rawStr = raw.toString();
112
+ if (isMaxUint(rawStr)) return rawStr;
113
+ if (isUnsupported) return new Dec(rawStr || 0).div(new Dec(10).pow(reserveAsset.decimals)).toString();
114
+ return assetAmountInEth(rawStr, symbol);
115
+ };
116
+
104
117
  const hubLiquidityRaw = hubAsset.liquidity;
105
- const hubLiquidity = isMaxUint(hubLiquidityRaw.toString()) ? hubLiquidityRaw.toString() : assetAmountInEth(hubLiquidityRaw.toString(), symbol);
118
+ const hubLiquidity = toEth(hubLiquidityRaw.toString());
106
119
 
107
120
  return ({
108
121
  symbol,
122
+ decimals: reserveAsset.decimals,
123
+ isUnsupported,
109
124
  underlying: reserveAsset.underlying,
110
125
  hub: hubInfo.address,
111
126
  hubName: hubInfo?.label,
@@ -119,12 +134,12 @@ const formatReserveAsset = async (reserveAsset: AaveV4ReserveAssetOnChain, hubAs
119
134
  liquidationFee: new Dec(reserveAsset.liquidationFee).div(10000).toNumber(),
120
135
  maxLiquidationBonus: new Dec(reserveAsset.maxLiquidationBonus).div(10000).toNumber(),
121
136
  price: new Dec(reserveAsset.price).div(new Dec(10).pow(oracleDecimals)).toString(),
122
- totalSupplied: isMaxUint(totalSuppliedRaw.toString()) ? totalSuppliedRaw.toString() : assetAmountInEth(totalSuppliedRaw.toString(), symbol),
123
- totalDrawn: isMaxUint(totalDrawnRaw.toString()) ? totalDrawnRaw.toString() : assetAmountInEth(totalDrawnRaw.toString(), symbol),
124
- totalPremium: isMaxUint(totalPremiumRaw.toString()) ? totalPremiumRaw.toString() : assetAmountInEth(totalPremiumRaw.toString(), symbol),
125
- totalDebt: isMaxUint(totalDebtRaw.toString()) ? totalDebtRaw.toString() : assetAmountInEth(totalDebtRaw.toString(), symbol),
126
- supplyCap: isMaxUint(supplyCapRaw.toString()) ? supplyCapRaw.toString() : assetAmountInEth(supplyCapRaw.toString(), symbol),
127
- borrowCap: isMaxUint(borrowCapRaw.toString()) ? borrowCapRaw.toString() : assetAmountInEth(borrowCapRaw.toString(), symbol),
137
+ totalSupplied: toEth(totalSuppliedRaw.toString()),
138
+ totalDrawn: toEth(totalDrawnRaw.toString()),
139
+ totalPremium: toEth(totalPremiumRaw.toString()),
140
+ totalDebt: toEth(totalDebtRaw.toString()),
141
+ supplyCap: toEth(supplyCapRaw.toString()),
142
+ borrowCap: toEth(borrowCapRaw.toString()),
128
143
  spokeActive: reserveAsset.spokeActive,
129
144
  spokeHalted: reserveAsset.spokeHalted,
130
145
  drawnRate: drawnRate.toString(),
@@ -132,10 +147,10 @@ const formatReserveAsset = async (reserveAsset: AaveV4ReserveAssetOnChain, hubAs
132
147
  supplyRate: aprToApy(supplyApr.toString()),
133
148
  supplyIncentives,
134
149
  borrowIncentives,
135
- canBeBorrowed: reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused && !reserveAsset.frozen && reserveAsset.borrowable,
136
- canBeSupplied: reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused && !reserveAsset.frozen,
137
- canBeWithdrawn: reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused,
138
- canBePayBacked: reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused,
150
+ canBeBorrowed: !isUnsupported && reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused && !reserveAsset.frozen && reserveAsset.borrowable,
151
+ canBeSupplied: !isUnsupported && reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused && !reserveAsset.frozen,
152
+ canBeWithdrawn: !isUnsupported && reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused,
153
+ canBePayBacked: !isUnsupported && reserveAsset.spokeActive && !reserveAsset.spokeHalted && !reserveAsset.paused,
139
154
  utilization,
140
155
  hubLiquidity,
141
156
  premiumMultiplier: premiumMultiplier.toString(),
@@ -182,17 +197,29 @@ export async function _getAaveV4AccountData(provider: Client, network: NetworkNu
182
197
  const healthFactorFromContract = new Dec(loanData.healthFactor.toString());
183
198
  const healthFactor = isMaxUint(healthFactorFromContract.toString()) ? 'Infinity' : healthFactorFromContract.div(1e18).toString();
184
199
  const usedAssets = loanData.reserves.reduce((acc: AaveV4UsedReserveAssets, usedReserveAsset) => {
185
- const identifier = `${wethToEth(getAssetInfoByAddress(usedReserveAsset.underlying, network).symbol)}-${+usedReserveAsset.reserveId.toString()}`;
200
+ const assetInfo = getAssetInfoByAddress(usedReserveAsset.underlying, network);
201
+ const isUnsupported = assetInfo.symbol === '?';
202
+ const symbol = wethToEth(assetInfo.symbol);
203
+ const identifier = `${symbol}-${+usedReserveAsset.reserveId.toString()}`;
186
204
  const reserveData = spokeData.assetsData[identifier];
187
- const price = reserveData.price;
188
- const supplied = isMaxUint(usedReserveAsset.supplied.toString()) ? usedReserveAsset.supplied.toString() : assetAmountInEth(usedReserveAsset.supplied.toString(), reserveData.symbol);
189
- const drawn = isMaxUint(usedReserveAsset.drawn.toString()) ? usedReserveAsset.drawn.toString() : assetAmountInEth(usedReserveAsset.drawn.toString(), reserveData.symbol);
190
- const premium = isMaxUint(usedReserveAsset.premium.toString()) ? usedReserveAsset.premium.toString() : assetAmountInEth(usedReserveAsset.premium.toString(), reserveData.symbol);
191
- const borrowed = isMaxUint(usedReserveAsset.totalDebt.toString()) ? usedReserveAsset.totalDebt.toString() : assetAmountInEth(usedReserveAsset.totalDebt.toString(), reserveData.symbol);
205
+ const price = reserveData?.price ?? '0';
206
+ // For unsupported assets the symbol-based conversion yields NaN, so use the on-chain decimals
207
+ // from the reserve data instead. If the reserve is missing entirely we can't convert, so fall
208
+ // back to '0' and keep the entry read-only.
209
+ const toEth = (raw: string) => {
210
+ if (isMaxUint(raw)) return raw;
211
+ if (!reserveData) return '0';
212
+ if (isUnsupported) return new Dec(raw || 0).div(new Dec(10).pow(reserveData.decimals)).toString();
213
+ return assetAmountInEth(raw, reserveData.symbol);
214
+ };
215
+ const supplied = toEth(usedReserveAsset.supplied.toString());
216
+ const drawn = toEth(usedReserveAsset.drawn.toString());
217
+ const premium = toEth(usedReserveAsset.premium.toString());
218
+ const borrowed = toEth(usedReserveAsset.totalDebt.toString());
192
219
  acc[identifier] = {
193
- symbol: reserveData.symbol,
194
- hubName: reserveData.hubName,
195
- assetId: reserveData.assetId,
220
+ symbol: reserveData?.symbol ?? symbol,
221
+ hubName: reserveData?.hubName ?? '',
222
+ assetId: reserveData?.assetId ?? 0,
196
223
  reserveId: +usedReserveAsset.reserveId.toString(),
197
224
  supplied,
198
225
  suppliedUsd: new Dec(supplied).mul(price).toString(),
@@ -206,6 +233,7 @@ export async function _getAaveV4AccountData(provider: Client, network: NetworkNu
206
233
  isBorrowed: usedReserveAsset.isBorrowing,
207
234
  collateral: usedReserveAsset.isUsingAsCollateral,
208
235
  collateralFactor: new Dec(usedReserveAsset.collateralFactor).div(10000).toNumber(),
236
+ isUnsupported: isUnsupported || !reserveData,
209
237
  };
210
238
  return acc;
211
239
  }, {});
@@ -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 {
@@ -85,6 +85,8 @@ export interface AaveV4ReserveAssetOnChain {
85
85
 
86
86
  export interface AaveV4ReserveAssetData {
87
87
  symbol: string,
88
+ /** Underlying token decimals as reported on-chain (independent of `@defisaver/tokens`). */
89
+ decimals: number,
88
90
  underlying: EthAddress,
89
91
  hub: EthAddress,
90
92
  hubName: string,
@@ -130,6 +132,11 @@ export interface AaveV4ReserveAssetData {
130
132
  hubLiquidity: string,
131
133
  premiumMultiplier: string;
132
134
  liquidityFee: string;
135
+ /**
136
+ * True when the underlying token is missing from `@defisaver/tokens` (placeholder `?` asset).
137
+ * The reserve is kept for read-only display, but amounts are zeroed and all actions are disabled.
138
+ */
139
+ isUnsupported?: boolean;
133
140
  }
134
141
 
135
142
  export type AaveV4AssetsData = Record<string, AaveV4ReserveAssetData>;
@@ -151,6 +158,8 @@ export interface AaveV4UsedReserveAsset {
151
158
  isBorrowed: boolean,
152
159
  collateral: boolean,
153
160
  collateralFactor: number,
161
+ /** True when the underlying token is missing from `@defisaver/tokens` (placeholder `?` asset). */
162
+ isUnsupported?: boolean,
154
163
  }
155
164
 
156
165
  export interface AaveV4AggregatedPositionData {