@defisaver/positions-sdk 2.1.161-portfolio-api-2-dev → 2.1.162-npm-token-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 (101) hide show
  1. package/cjs/aaveV3/index.d.ts +12 -2
  2. package/cjs/aaveV3/index.js +7 -1
  3. package/cjs/aaveV3/sgho.d.ts +16 -2
  4. package/cjs/claiming/aaveV3.d.ts +2 -2
  5. package/cjs/claiming/ethena.d.ts +1 -2
  6. package/cjs/claiming/king.d.ts +1 -2
  7. package/cjs/claiming/spark.d.ts +2 -2
  8. package/cjs/fluid/index.d.ts +49 -5
  9. package/cjs/helpers/aaveHelpers/index.d.ts +9 -1
  10. package/cjs/helpers/aaveHelpers/index.js +23 -6
  11. package/cjs/liquity/index.d.ts +12 -2
  12. package/cjs/liquityV2/index.d.ts +23 -3
  13. package/cjs/portfolio/index.d.ts +5 -5
  14. package/cjs/portfolio/index.js +36 -51
  15. package/cjs/savings/index.js +5 -2
  16. package/cjs/savings/morphoVaults/index.d.ts +1 -1
  17. package/cjs/savings/morphoVaults/index.js +56 -18
  18. package/cjs/savings/morphoVaults/options.d.ts +2 -0
  19. package/cjs/savings/morphoVaults/options.js +61 -1
  20. package/cjs/spark/index.js +1 -0
  21. package/cjs/types/aave.d.ts +3 -98
  22. package/cjs/types/compound.d.ts +2 -26
  23. package/cjs/types/curveUsd.d.ts +1 -9
  24. package/cjs/types/fluid.d.ts +0 -13
  25. package/cjs/types/index.d.ts +0 -1
  26. package/cjs/types/index.js +0 -1
  27. package/cjs/types/liquity.d.ts +0 -12
  28. package/cjs/types/liquityV2.d.ts +0 -24
  29. package/cjs/types/llamaLend.d.ts +1 -12
  30. package/cjs/types/morphoBlue.d.ts +0 -2
  31. package/cjs/types/portfolio.d.ts +10 -88
  32. package/cjs/types/savings/morphoVaults.d.ts +10 -2
  33. package/cjs/types/savings/morphoVaults.js +9 -1
  34. package/cjs/types/spark.d.ts +1 -21
  35. package/cjs/umbrella/index.d.ts +3 -2
  36. package/esm/aaveV3/index.d.ts +12 -2
  37. package/esm/aaveV3/index.js +7 -1
  38. package/esm/aaveV3/sgho.d.ts +16 -2
  39. package/esm/claiming/aaveV3.d.ts +2 -2
  40. package/esm/claiming/aaveV3.js +1 -1
  41. package/esm/claiming/ethena.d.ts +1 -2
  42. package/esm/claiming/king.d.ts +1 -2
  43. package/esm/claiming/spark.d.ts +2 -2
  44. package/esm/claiming/spark.js +1 -1
  45. package/esm/fluid/index.d.ts +49 -5
  46. package/esm/helpers/aaveHelpers/index.d.ts +9 -1
  47. package/esm/helpers/aaveHelpers/index.js +20 -5
  48. package/esm/liquity/index.d.ts +12 -2
  49. package/esm/liquityV2/index.d.ts +23 -3
  50. package/esm/portfolio/index.d.ts +5 -5
  51. package/esm/portfolio/index.js +36 -51
  52. package/esm/savings/index.js +5 -2
  53. package/esm/savings/morphoVaults/index.d.ts +1 -1
  54. package/esm/savings/morphoVaults/index.js +57 -19
  55. package/esm/savings/morphoVaults/options.d.ts +2 -0
  56. package/esm/savings/morphoVaults/options.js +61 -1
  57. package/esm/spark/index.js +1 -0
  58. package/esm/types/aave.d.ts +3 -98
  59. package/esm/types/compound.d.ts +2 -26
  60. package/esm/types/curveUsd.d.ts +1 -9
  61. package/esm/types/fluid.d.ts +0 -13
  62. package/esm/types/index.d.ts +0 -1
  63. package/esm/types/index.js +0 -1
  64. package/esm/types/liquity.d.ts +0 -12
  65. package/esm/types/liquityV2.d.ts +0 -24
  66. package/esm/types/llamaLend.d.ts +1 -12
  67. package/esm/types/morphoBlue.d.ts +0 -2
  68. package/esm/types/portfolio.d.ts +10 -88
  69. package/esm/types/savings/morphoVaults.d.ts +10 -2
  70. package/esm/types/savings/morphoVaults.js +8 -0
  71. package/esm/types/spark.d.ts +1 -21
  72. package/esm/umbrella/index.d.ts +3 -2
  73. package/package.json +3 -2
  74. package/src/aaveV3/index.ts +7 -3
  75. package/src/aaveV3/sgho.ts +17 -2
  76. package/src/claiming/aaveV3.ts +2 -4
  77. package/src/claiming/ethena.ts +5 -5
  78. package/src/claiming/king.ts +3 -3
  79. package/src/claiming/spark.ts +4 -6
  80. package/src/fluid/index.ts +3 -4
  81. package/src/helpers/aaveHelpers/index.ts +24 -7
  82. package/src/liquity/index.ts +2 -2
  83. package/src/liquityV2/index.ts +3 -3
  84. package/src/portfolio/index.ts +57 -76
  85. package/src/savings/index.ts +5 -2
  86. package/src/savings/morphoVaults/index.ts +73 -21
  87. package/src/savings/morphoVaults/options.ts +67 -1
  88. package/src/spark/index.ts +1 -0
  89. package/src/types/aave.ts +2 -104
  90. package/src/types/compound.ts +2 -38
  91. package/src/types/curveUsd.ts +1 -17
  92. package/src/types/fluid.ts +0 -14
  93. package/src/types/index.ts +1 -2
  94. package/src/types/liquity.ts +1 -13
  95. package/src/types/liquityV2.ts +1 -26
  96. package/src/types/llamaLend.ts +1 -19
  97. package/src/types/morphoBlue.ts +0 -3
  98. package/src/types/portfolio.ts +11 -111
  99. package/src/types/savings/morphoVaults.ts +11 -1
  100. package/src/types/spark.ts +1 -25
  101. package/src/umbrella/index.ts +1 -2
@@ -1,33 +1,19 @@
1
- import { AaveV2MarketData, AaveV2PositionData, AaveV3MarketData, AaveV3PositionData, AaveVersions, StakeAaveData, UmbrellaStakingData } from './aave';
2
- import { AaveV4AccountData, AaveV4SpokeData, AaveV4SpokesType } from './aaveV4';
3
- import { AaveRewardsClaimableToken, EthenaAirdropClaimableToken, KingRewardsClaimableToken, MerklRewardsClaimableToken, SparkAirdropClaimableToken, SparkRewardsClaimableToken, UniswapAirdropClaimableToken } from './claiming';
1
+ import { AaveV2PositionData, AaveV3PositionData, AaveVersions } from './aave';
2
+ import { AaveV4AccountData, AaveV4SpokesType } from './aaveV4';
4
3
  import { EthAddress } from './common';
5
- import { CompoundV2MarketsData, CompoundV2PositionData, CompoundV3MarketsData, CompoundV3PositionData, CompoundVersions } from './compound';
6
- import { CrvUSDGlobalMarketData, CrvUSDUserData, CrvUSDVersions } from './curveUsd';
7
- import { FluidEarnPositionData, FluidVaultData } from './fluid';
8
- import { LiquityStakingData, LiquityTroveInfo } from './liquity';
9
- import { LiquityV2MarketData, LiquityV2SBoldYBoldData, LiquityV2StakingData, LiquityV2Versions } from './liquityV2';
10
- import { LlamaLendGlobalMarketData, LlamaLendUserData, LlamaLendVersionsType } from './llamaLend';
4
+ import { CompoundV2PositionData, CompoundV3PositionData, CompoundVersions } from './compound';
5
+ import { CrvUSDUserData, CrvUSDVersions } from './curveUsd';
6
+ import { FluidVaultData } from './fluid';
7
+ import { LiquityTroveInfo } from './liquity';
8
+ import { LlamaLendUserData, LlamaLendVersionsType } from './llamaLend';
11
9
  import { CdpData } from './maker';
12
- import { MorphoBlueEarnData, MorphoBlueMarketInfo, MorphoBluePositionData, MorphoBlueVersions } from './morphoBlue';
13
- import { MorphoMidnightMarketInfo, MorphoMidnightPositionData, MorphoMidnightVersions } from './morphoMidnight';
14
- import { SparkMarketsData, SparkPositionData, SparkVersions } from './spark';
10
+ import { MorphoBluePositionData, MorphoBlueVersions } from './morphoBlue';
11
+ import { MorphoMidnightPositionData, MorphoMidnightVersions } from './morphoMidnight';
12
+ import { SparkPositionData, SparkVersions } from './spark';
15
13
  export interface PortfolioProtocolData<T> {
16
14
  error: string;
17
15
  data: T | null;
18
16
  }
19
- /** A failed fetch of a protocol that, when it succeeds, getPortfolioData returns unwrapped rather than as `{ error, data }`. */
20
- export interface PortfolioProtocolError {
21
- error: string;
22
- data: null;
23
- }
24
- /** What getPortfolioData reads besides positions and markets. Both default to true. */
25
- export interface PortfolioDataOptions {
26
- /** stakingPositions; with false it comes back as {} and no staking source is read. */
27
- staking?: boolean;
28
- /** rewardsData; with false it comes back as {} and no rewards source is read. */
29
- rewards?: boolean;
30
- }
31
17
  export interface PortfolioPositionsDataForAddress {
32
18
  aaveV3: {
33
19
  [key in AaveVersions]?: PortfolioProtocolData<AaveV3PositionData>;
@@ -73,67 +59,3 @@ export interface PortfolioPositionsDataForAddress {
73
59
  export interface PortfolioPositionsData {
74
60
  [key: EthAddress]: PortfolioPositionsDataForAddress;
75
61
  }
76
- /**
77
- * The staking positions getPortfolioData returns for an address. The shapes are uneven, and the DeFi Saver app
78
- * parses them as they are: a protocol read once per address comes back unwrapped on success, as
79
- * `{ error, data: null }` on failure, and as {} (or Fluid's `{ error: '', data: {} }`) on a network it is not read on.
80
- */
81
- export interface PortfolioStakingPositionsDataForAddress {
82
- /** stkAAVE, stkGHO and sGHO; mainnet only. */
83
- aaveV3: StakeAaveData | PortfolioProtocolError | {};
84
- /** Morpho Blue supply without a borrow (Earn), by market; only markets with a deposit or an error. */
85
- morphoBlue: {
86
- [key in MorphoBlueVersions]?: PortfolioProtocolData<MorphoBlueEarnData>;
87
- };
88
- compoundV3: Record<string, never>;
89
- spark: Record<string, never>;
90
- aaveV2: Record<string, never>;
91
- compoundV2: Record<string, never>;
92
- /** LQTY staking and the LUSD stability pool; mainnet only. */
93
- liquity: LiquityStakingData | PortfolioProtocolError | {};
94
- /** Stability pool deposits, by market; mainnet only, legacy markets left out. */
95
- liquityV2: {
96
- [key in LiquityV2Versions]?: PortfolioProtocolData<LiquityV2StakingData>;
97
- };
98
- /** Fluid lending (fToken) deposits; `{ error: '', data: {} }` on a network without Fluid. */
99
- fluid: FluidEarnPositionData[] | PortfolioProtocolError | {
100
- error: string;
101
- data: Record<string, never>;
102
- };
103
- /** Umbrella stakes; absent off mainnet. */
104
- umbrella?: UmbrellaStakingData | PortfolioProtocolError;
105
- /** sBOLD, yBOLD and stYBOLD; data is null off mainnet. */
106
- liquityV2SBoldYBold: PortfolioProtocolData<LiquityV2SBoldYBoldData>;
107
- }
108
- export type PortfolioStakingPositionsData = Record<EthAddress, PortfolioStakingPositionsDataForAddress>;
109
- /** The claimable rewards getPortfolioData returns for an address. Off mainnet only Merkl and Aave V3 are read. */
110
- export interface PortfolioRewardsDataForAddress {
111
- merkl: PortfolioProtocolData<MerklRewardsClaimableToken[]>;
112
- aaveV3: {
113
- [key in AaveVersions]?: PortfolioProtocolData<AaveRewardsClaimableToken[]>;
114
- };
115
- spark: {
116
- [key in SparkVersions]?: PortfolioProtocolData<SparkRewardsClaimableToken[]>;
117
- };
118
- /** The SPK airdrop. */
119
- spk: PortfolioProtocolData<SparkAirdropClaimableToken[]>;
120
- king: PortfolioProtocolData<KingRewardsClaimableToken[]>;
121
- /** {} off mainnet. */
122
- ethena: PortfolioProtocolData<EthenaAirdropClaimableToken[]> | {};
123
- uniswap: PortfolioProtocolData<UniswapAirdropClaimableToken[]>;
124
- }
125
- export type PortfolioRewardsData = Record<EthAddress, PortfolioRewardsDataForAddress>;
126
- /** The `markets` getPortfolioData returns: every market it read, by protocol, keyed by market or spoke. */
127
- export interface PortfolioMarketsData {
128
- morphoMarketsData: Record<string, MorphoBlueMarketInfo>;
129
- morphoMidnightMarketsData: Record<string, MorphoMidnightMarketInfo>;
130
- compoundV3MarketsData: Record<string, CompoundV3MarketsData>;
131
- sparkMarketsData: Record<string, SparkMarketsData>;
132
- aaveV3MarketsData: Record<string, AaveV3MarketData>;
133
- aaveV2MarketsData: Record<string, AaveV2MarketData>;
134
- compoundV2MarketsData: Record<string, CompoundV2MarketsData>;
135
- crvUsdMarketsData: Record<string, CrvUSDGlobalMarketData>;
136
- llamaLendMarketsData: Record<string, LlamaLendGlobalMarketData>;
137
- liquityV2MarketsData: Record<string, LiquityV2MarketData>;
138
- aaveV4SpokesData: Record<string, AaveV4SpokeData>;
139
- }
@@ -1,4 +1,4 @@
1
- import { EthAddress } from '../common';
1
+ import { EthAddress, NetworkNumber } from '../common';
2
2
  export declare enum MorphoVaultType {
3
3
  MorphoVaultFlagshipEth = "morpho_vault_flagship_eth",
4
4
  MorphoVaultGauntletUSDCCore = "morpho_vault_gauntlet_usdc_core",
@@ -17,13 +17,21 @@ export declare enum MorphoVaultType {
17
17
  MorphoVaultSteakhousePYUSD = "morpho_vault_steakhouse_pyusd",
18
18
  MorphoVaultSmokehouseUSDT = "morpho_vault_smokehouse_usdt",
19
19
  MorphoVaultSmokehouseUSDC = "morpho_vault_smokehouse_usdc",
20
- MorphoVaultSmokehouseDAI = "morpho_vault_smokehouse_dai"
20
+ MorphoVaultSmokehouseDAI = "morpho_vault_smokehouse_dai",
21
+ MorphoVaultGauntletUSDGPremium = "morpho_vault_gauntlet_usdg_premium",
22
+ MorphoVaultSteakhouseUSDGPro = "morpho_vault_steakhouse_usdg_pro"
23
+ }
24
+ export declare enum MorphoVaultVersion {
25
+ V1 = 1,
26
+ V2 = 2
21
27
  }
22
28
  export interface MorphoVault {
23
29
  type: MorphoVaultType;
24
30
  name: string;
25
31
  address: EthAddress;
26
32
  asset: string;
33
+ network: NetworkNumber;
34
+ version: MorphoVaultVersion;
27
35
  deploymentBlock: number;
28
36
  isLegacy: boolean;
29
37
  }
@@ -20,4 +20,12 @@ export var MorphoVaultType;
20
20
  MorphoVaultType["MorphoVaultSmokehouseUSDT"] = "morpho_vault_smokehouse_usdt";
21
21
  MorphoVaultType["MorphoVaultSmokehouseUSDC"] = "morpho_vault_smokehouse_usdc";
22
22
  MorphoVaultType["MorphoVaultSmokehouseDAI"] = "morpho_vault_smokehouse_dai";
23
+ // Vault V2
24
+ MorphoVaultType["MorphoVaultGauntletUSDGPremium"] = "morpho_vault_gauntlet_usdg_premium";
25
+ MorphoVaultType["MorphoVaultSteakhouseUSDGPro"] = "morpho_vault_steakhouse_usdg_pro";
23
26
  })(MorphoVaultType || (MorphoVaultType = {}));
27
+ export var MorphoVaultVersion;
28
+ (function (MorphoVaultVersion) {
29
+ MorphoVaultVersion[MorphoVaultVersion["V1"] = 1] = "V1";
30
+ MorphoVaultVersion[MorphoVaultVersion["V2"] = 2] = "V2";
31
+ })(MorphoVaultVersion || (MorphoVaultVersion = {}));
@@ -46,21 +46,6 @@ export interface SparkAssetData extends MMAssetData {
46
46
  eModeCategory: number;
47
47
  liquidationBonus: string;
48
48
  liquidationRatio: string;
49
- debtCeilingForIsolationMode?: string;
50
- isSiloed?: boolean;
51
- isolationModeTotalDebt?: string;
52
- isolationModeBorrowingEnabled?: boolean;
53
- assetId?: number;
54
- borrowRateStable?: string;
55
- supplyCap?: string;
56
- isInactive?: boolean;
57
- isFrozen?: boolean;
58
- isPaused?: boolean;
59
- canBeWithdrawn?: boolean;
60
- canBePayBacked?: boolean;
61
- disabledStableBorrowing?: boolean;
62
- isFlashLoanEnabled?: boolean;
63
- aTokenAddress?: EthAddress;
64
49
  }
65
50
  export interface SparkAssetsData {
66
51
  [token: string]: SparkAssetData;
@@ -115,12 +100,7 @@ export interface SparkAggregatedPositionData {
115
100
  minHealthRatio: string;
116
101
  exposure: string;
117
102
  }
118
- /**
119
- * Fields sparkGetAggregatedPositionData adds to every Spark position at runtime, on top of those declared below.
120
- * Optional, so code that builds a position by hand keeps compiling.
121
- */
122
- export type SparkPositionAggregatedFields = Partial<Omit<SparkAggregatedPositionData, keyof MMPositionData | 'ratio' | 'collRatio' | 'suppliedUsd' | 'borrowedUsd' | 'borrowLimitUsd' | 'suppliedCollateralUsd' | 'incentiveUsd' | 'totalInterestUsd'>>;
123
- export interface SparkPositionData extends MMPositionData, SparkPositionAggregatedFields {
103
+ export interface SparkPositionData extends MMPositionData {
124
104
  ratio: string;
125
105
  minRatio: string;
126
106
  collRatio: string;
@@ -1,4 +1,5 @@
1
1
  import { Client } from 'viem';
2
2
  import { EthAddress, NetworkNumber } from '../types/common';
3
- import { UmbrellaStakingData } from '../types/aave';
4
- export declare const getUmbrellaData: (provider: Client, network: NetworkNumber, address: EthAddress) => Promise<UmbrellaStakingData>;
3
+ export declare const getUmbrellaData: (provider: Client, network: NetworkNumber, address: EthAddress) => Promise<{
4
+ [k: string]: any;
5
+ }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/positions-sdk",
3
- "version": "2.1.161-portfolio-api-2-dev",
3
+ "version": "2.1.162-npm-token-dev",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -18,7 +18,8 @@
18
18
  "version-bump": "git commit -am \"Version bump to $(npm version patch | cut -c 2-)\""
19
19
  },
20
20
  "keywords": [],
21
- "author": "",
21
+ "author": "DeFi Saver",
22
+ "repository": "https://github.com/defisaver/defisaver-positions-sdk",
22
23
  "license": "ISC",
23
24
  "dependencies": {
24
25
  "@defisaver/tokens": "^1.7.45",
@@ -30,7 +30,6 @@ import {
30
30
  EModeCategoriesData,
31
31
  EModeCategoryData,
32
32
  EModeCategoryDataMapping,
33
- StakeAaveData,
34
33
  } from '../types';
35
34
  import {
36
35
  Blockish,
@@ -62,7 +61,10 @@ export const aaveV3EmodeCategoriesMapping = (extractedState: any, usedAssets: Aa
62
61
  ...extractedState, usedAssets, eModeCategory: e.id,
63
62
  });
64
63
  const willStayOverCollateralized = new Dec(afterEnteringCategory.ratio === 'NaN' ? '0' : afterEnteringCategory.ratio).eq(0) || new Dec(afterEnteringCategory.ratio).gt(afterEnteringCategory.liqPercent);
65
- const enteringTerms = [borrowingOnlyFromCategory, willStayOverCollateralized];
64
+ const collateralOnlyFromCategory = e.id === 0 || !e.isolated
65
+ ? true
66
+ : !usedAssetsValues.filter(u => u.isSupplied && u.collateral && !e.collateralAssets.includes(u.symbol)).length;
67
+ const enteringTerms = [borrowingOnlyFromCategory, willStayOverCollateralized, collateralOnlyFromCategory];
66
68
  categoriesMapping[e.id] = {
67
69
  enteringTerms,
68
70
  canEnterCategory: !enteringTerms.includes(false),
@@ -119,6 +121,7 @@ export async function _getAaveV3MarketData(provider: Client, network: NetworkNum
119
121
  borrowableBitmap: eModesInfo[i].borrowableBitmap.toString(),
120
122
  collateralBitmap: eModesInfo[i].collateralBitmap.toString(),
121
123
  ltvzeroBitmap: eModesInfo[i].ltvzeroBitmap.toString(),
124
+ isolated: eModesInfo[i].isolated ?? false,
122
125
  borrowAssets: [],
123
126
  collateralAssets: [],
124
127
  ltvZeroAssets: [],
@@ -346,6 +349,7 @@ export async function _getAaveV3MarketData(provider: Client, network: NetworkNum
346
349
  collateralAssets: assetsData.map((a) => a.symbol),
347
350
  borrowAssets: assetsData.map((a) => a.symbol),
348
351
  ltvZeroAssets: [],
352
+ isolated: false,
349
353
  };
350
354
 
351
355
  return { assetsData: payload, eModeCategoriesData };
@@ -609,7 +613,7 @@ export const fetchYearlyMeritApyForStakingGho = async () => {
609
613
  }
610
614
  };
611
615
 
612
- export const getStakeAaveData = async (provider: Client, network: NetworkNumber, address: EthAddress): Promise<StakeAaveData> => {
616
+ export const getStakeAaveData = async (provider: Client, network: NetworkNumber, address: EthAddress) => {
613
617
  const stkGhoAddress = getAssetInfo('stkGHO').address as HexString;
614
618
  const stkAaveAddress = getAssetInfo('stkAAVE').address as HexString;
615
619
 
@@ -1,10 +1,25 @@
1
1
  import Dec from 'decimal.js';
2
2
  import { EthAddress, NetworkNumber } from '../types/common';
3
- import { SghoData } from '../types/aave';
4
3
  import { DEFAULT_TIMEOUT } from '../services/utils';
5
4
  import { ZERO_ADDRESS } from '../constants';
6
5
 
7
- export type { SghoData, SghoUserData } from '../types/aave';
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
+ }
8
23
 
9
24
  const EMPTY_SGHO_DATA: SghoData = {
10
25
  totalAssets: '0',
@@ -1,9 +1,7 @@
1
1
  import { Client } from 'viem';
2
2
  import Dec from 'decimal.js';
3
3
  import { EthAddress, NetworkNumber } from '../types';
4
- import {
5
- AaveRewardsClaimableToken, ClaimableToken, ClaimType, MerklRewardsClaimableToken,
6
- } from '../types/claiming';
4
+ import { ClaimableToken, ClaimType, MerklRewardsClaimableToken } from '../types/claiming';
7
5
  import {
8
6
  AaveIncentiveDataProviderV3ContractViem,
9
7
  AaveRewardsControllerViem,
@@ -39,7 +37,7 @@ export async function getUnclaimedRewardsForAllMarkets(
39
37
  network: NetworkNumber,
40
38
  walletAddress: EthAddress,
41
39
  marketAddress: EthAddress,
42
- ): Promise<AaveRewardsClaimableToken[]> {
40
+ ): Promise<ClaimableToken[]> {
43
41
  const contract = AaveIncentiveDataProviderV3ContractViem(provider, network);
44
42
  const tokensData = await contract.read.getUserReservesIncentivesData([marketAddress, walletAddress]);
45
43
  const allTokensDataArrays = tokensData.reduce((acc: any[], val) => {
@@ -2,7 +2,7 @@ import { getAssetInfo } from '@defisaver/tokens';
2
2
  import Dec from 'decimal.js';
3
3
  import { getAddress } from 'viem';
4
4
  import { EthAddress } from '../types/common';
5
- import { ClaimType, EthenaAirdropClaimableToken } from '../types/claiming';
5
+ import { ClaimType } from '../types/claiming';
6
6
  import { getEthAmountForDecimals } from '../services/utils';
7
7
 
8
8
  export const fetchEthenaAirdropReward = async (address: EthAddress) => {
@@ -23,11 +23,11 @@ export const fetchEthenaAirdropReward = async (address: EthAddress) => {
23
23
  }
24
24
  };
25
25
 
26
- export const fetchEthenaAirdropRewards = async (walletAddresses: EthAddress[]): Promise<Record<string, EthenaAirdropClaimableToken[]>> => {
26
+ export const fetchEthenaAirdropRewards = async (walletAddresses: EthAddress[]): Promise<Record<string, any[]>> => {
27
27
  const apiDataPromises = walletAddresses.map(address => fetchEthenaAirdropReward(address));
28
28
  const apiDataArray = await Promise.all(apiDataPromises);
29
29
 
30
- const results: Record<string, EthenaAirdropClaimableToken[]> = {};
30
+ const results: Record<string, any[]> = {};
31
31
  for (let i = 0; i < walletAddresses.length; i++) {
32
32
  const walletAddress = walletAddresses[i];
33
33
  const data = apiDataArray[i];
@@ -36,7 +36,7 @@ export const fetchEthenaAirdropRewards = async (walletAddresses: EthAddress[]):
36
36
  continue;
37
37
  }
38
38
 
39
- const processedRewards: EthenaAirdropClaimableToken[] = [];
39
+ const processedRewards = [];
40
40
  const assetInfo = getAssetInfo('sENA');
41
41
 
42
42
  const amount = getEthAmountForDecimals(data.events[0].awardAmount, assetInfo.decimals);
@@ -47,7 +47,7 @@ export const fetchEthenaAirdropRewards = async (walletAddresses: EthAddress[]):
47
47
  underlyingSymbol: assetInfo.symbol,
48
48
  amount,
49
49
  claimType: ClaimType.ETHENA_AIRDROP,
50
- tokenAddress: assetInfo.address as EthAddress,
50
+ tokenAddress: assetInfo.address,
51
51
  walletAddress,
52
52
  label: 'Ethena Airdrop',
53
53
  });
@@ -3,7 +3,7 @@ import { assetAmountInEth } from '@defisaver/tokens';
3
3
  import { Client } from 'viem';
4
4
  import { UUPSViem } from '../contracts';
5
5
  import { EthAddress, HexString, NetworkNumber } from '../types/common';
6
- import { ClaimType, KingRewardsClaimableToken } from '../types/claiming';
6
+ import { ClaimType } from '../types/claiming';
7
7
 
8
8
  export const fetchKingRewards = async (walletAddress: EthAddress) => {
9
9
  try {
@@ -19,7 +19,7 @@ export const fetchKingRewards = async (walletAddress: EthAddress) => {
19
19
  }
20
20
  };
21
21
 
22
- export const getKingRewards = async (provider: Client, network: NetworkNumber, walletAddresses: EthAddress[]): Promise<Record<string, KingRewardsClaimableToken[]>> => {
22
+ export const getKingRewards = async (provider: Client, network: NetworkNumber, walletAddresses: EthAddress[]) => {
23
23
  // Fetch all API data in parallel (these are external API calls, can't be batched with multicall)
24
24
  const apiDataPromises = walletAddresses.map(address => fetchKingRewards(address));
25
25
  const apiDataArray = await Promise.all(apiDataPromises);
@@ -31,7 +31,7 @@ export const getKingRewards = async (provider: Client, network: NetworkNumber, w
31
31
  const cumulativeResults = await Promise.all(cumulativePromises);
32
32
 
33
33
  // Process results
34
- const results: Record<string, KingRewardsClaimableToken[]> = {};
34
+ const results: Record<string, any[]> = {};
35
35
 
36
36
  for (let i = 0; i < walletAddresses.length; i++) {
37
37
  const walletAddress = walletAddresses[i];
@@ -7,9 +7,7 @@ import {
7
7
  SparkRewardsControllerViem,
8
8
  } from '../contracts';
9
9
  import { EthAddress, NetworkNumber } from '../types/common';
10
- import {
11
- ClaimType, SparkAirdropClaimableToken, SparkAirdropType, SparkRewardsClaimableToken,
12
- } from '../types/claiming';
10
+ import { ClaimType, SparkAirdropType, SparkRewardsClaimableToken } from '../types/claiming';
13
11
  import { compareAddresses, getEthAmountForDecimals } from '../services/utils';
14
12
 
15
13
  const IGNITION_REWARDS = '0xCBA0C0a2a0B6Bb11233ec4EA85C5bFfea33e724d';
@@ -52,7 +50,7 @@ export const fetchSparkAirdropRewards = async (
52
50
  provider: Client,
53
51
  network: NetworkNumber,
54
52
  walletAddresses: EthAddress[],
55
- ): Promise<Record<string, SparkAirdropClaimableToken[]>> => {
53
+ ) => {
56
54
  // Fetch all API data in parallel (these are external API calls, can't be batched with multicall)
57
55
  const apiDataPromises = walletAddresses.map(address => fetchSpkAirdropRewards(address));
58
56
  const apiDataArray = await Promise.all(apiDataPromises);
@@ -94,7 +92,7 @@ export const fetchSparkAirdropRewards = async (
94
92
  const cumulativeClaimedAmounts = await getCumulativeClaimedSpkAirdrop(provider, network, contractCallsData);
95
93
 
96
94
  // Process results
97
- const results: Record<string, SparkAirdropClaimableToken[]> = {};
95
+ const results: Record<string, any[]> = {};
98
96
  let contractCallIndex = 0;
99
97
 
100
98
  for (const { walletAddress, data } of allClaimData) {
@@ -103,7 +101,7 @@ export const fetchSparkAirdropRewards = async (
103
101
  continue;
104
102
  }
105
103
 
106
- const processedRewards: SparkAirdropClaimableToken[] = [];
104
+ const processedRewards = [];
107
105
  for (let i = 0; i < data.length; i++) {
108
106
  const rewardInfo = data[i];
109
107
  const assetInfo = getAssetInfoByAddress(rewardInfo.token_address);
@@ -10,7 +10,6 @@ import {
10
10
  FluidAggregatedVaultData,
11
11
  FluidAssetData,
12
12
  FluidAssetsData,
13
- FluidEarnPositionData,
14
13
  FluidFTokenDataStructOutput,
15
14
  FluidMarketData,
16
15
  FluidMarketInfo,
@@ -1598,7 +1597,7 @@ export const getFluidTokenData = async (
1598
1597
  token: string,
1599
1598
  ) => _getFluidTokenData(getViemProvider(provider, network), network, token);
1600
1599
 
1601
- const parseFDepositTokenData = (fTokenData: FluidFTokenDataStructOutput, userPosition: FluidUserEarnPositionStructOutput, apiData: any, fTokenAddress?: string): FluidEarnPositionData => {
1600
+ const parseFDepositTokenData = (fTokenData: FluidFTokenDataStructOutput, userPosition: FluidUserEarnPositionStructOutput, apiData: any, fTokenAddress?: string) => {
1602
1601
  const decimals = fTokenData.decimals.toString();
1603
1602
  const depositRate = new Dec(getEthAmountForDecimals(fTokenData.convertToShares.toString(), decimals)).toString();
1604
1603
  const withdrawRate = new Dec(getEthAmountForDecimals(fTokenData.convertToAssets.toString(), decimals)).toString();
@@ -1646,7 +1645,7 @@ export const getFluidDepositData = async (
1646
1645
  address: EthAddress,
1647
1646
  ) => _getFluidDepositData(getViemProvider(provider, network), network, token, address);
1648
1647
 
1649
- export const _getAllUserEarnPositionsWithFTokens = async (provider: Client, network: NetworkNumber, user: EthAddress): Promise<FluidEarnPositionData[]> => {
1648
+ export const _getAllUserEarnPositionsWithFTokens = async (provider: Client, network: NetworkNumber, user: EthAddress) => {
1650
1649
  const view = FluidViewContractViem(provider, network);
1651
1650
  const [
1652
1651
  [userPositions, fTokensData],
@@ -1665,7 +1664,7 @@ export const _getAllUserEarnPositionsWithFTokens = async (provider: Client, netw
1665
1664
  rewardsData = await rewardsApiResponse.json();
1666
1665
  }
1667
1666
 
1668
- const parsedRes = fTokensData.reduce<FluidEarnPositionData[]>((acc, fTokenData, i) => {
1667
+ const parsedRes = fTokensData.reduce<ReturnType<typeof parseFDepositTokenData>[]>((acc, fTokenData, i) => {
1669
1668
  const userPosition = userPositions[i];
1670
1669
  const deposited = userPosition?.underlyingAssets;
1671
1670
 
@@ -2,7 +2,7 @@ import Dec from 'decimal.js';
2
2
  import { assetAmountInWei, getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
3
3
  import { Client } from 'viem';
4
4
  import {
5
- AaveAssetData, AaveHelperCommon, AaveMarketInfo, AaveV3AggregatedPositionData, AaveV3AssetsData, AaveV3UsedAsset, AaveV3UsedAssets, AaveVersions,
5
+ AaveAssetData, AaveHelperCommon, AaveMarketInfo, AaveV3AggregatedPositionData, AaveV3AssetsData, AaveV3UsedAsset, AaveV3UsedAssets, AaveVersions, EModeCategoriesData,
6
6
  } from '../../types';
7
7
  import { getNativeAssetFromWrapped, getWrappedNativeAssetFromUnwrapped } from '../../services/utils';
8
8
  import {
@@ -24,6 +24,13 @@ export const isAaveV3 = ({ selectedMarket }: { selectedMarket: Partial<AaveMarke
24
24
  export const aaveV3IsInIsolationMode = ({ usedAssets, assetsData }: { usedAssets: AaveV3UsedAssets, assetsData: AaveV3AssetsData }) => Object.values(usedAssets).some(({ symbol, collateral }) => collateral && assetsData[symbol].isIsolated);
25
25
  export const aaveV3IsInSiloedMode = ({ usedAssets, assetsData }: { usedAssets: AaveV3UsedAssets, assetsData: AaveV3AssetsData }) => Object.values(usedAssets).some(({ symbol, debt }) => debt && assetsData[symbol].isSiloed);
26
26
 
27
+ export const aaveV3IsEmodeIsolated = ({ eModeCategory, eModeCategoriesData }: { eModeCategory: number, eModeCategoriesData?: EModeCategoriesData }) => eModeCategory !== 0 && !!eModeCategoriesData?.[eModeCategory]?.isolated;
28
+
29
+ export const aaveV3CanBeCollateralInEmode = ({ eModeCategory, eModeCategoriesData }: { eModeCategory: number, eModeCategoriesData?: EModeCategoriesData }, _asset: string) => {
30
+ if (!aaveV3IsEmodeIsolated({ eModeCategory, eModeCategoriesData })) return true;
31
+ return eModeCategoriesData![eModeCategory].collateralAssets.includes(getNativeAssetFromWrapped(_asset));
32
+ };
33
+
27
34
  export const aaveAnyGetCollSuppliedAssets = ({ usedAssets }: { usedAssets: AaveV3UsedAssets }) => Object.values(usedAssets)
28
35
  .filter(({ isSupplied, collateral }: { isSupplied: boolean, collateral: boolean }) => isSupplied && collateral);
29
36
 
@@ -37,14 +44,18 @@ export const aaveAnyGetSuppliableAssets = ({
37
44
  const collAccountAssets = aaveAnyGetCollSuppliedAssets(data);
38
45
  const marketAssets = Object.values(assetsData) as AaveAssetData[];
39
46
 
40
- if (collAccountAssets.length === 0 || !isAaveV3(data)) return marketAssets.filter(({ canBeSupplied }) => canBeSupplied).map(({ symbol }) => ({ symbol, canBeCollateral: true }));
47
+ if (!isAaveV3(data)) return marketAssets.filter(({ canBeSupplied }) => canBeSupplied).map(({ symbol }) => ({ symbol, canBeCollateral: true }));
48
+
49
+ const canBeCollateralInEmode = (symbol: string) => aaveV3CanBeCollateralInEmode(data, symbol);
50
+
51
+ if (collAccountAssets.length === 0) return marketAssets.filter(({ canBeSupplied }) => canBeSupplied).map(({ symbol }) => ({ symbol, canBeCollateral: canBeCollateralInEmode(symbol) }));
41
52
 
42
53
  if (aaveV3IsInIsolationMode(data)) {
43
54
  const collAsset = collAccountAssets[0].symbol;
44
- return marketAssets.filter(d => d.canBeSupplied).map(({ symbol }) => ({ symbol, canBeCollateral: symbol === collAsset }));
55
+ return marketAssets.filter(d => d.canBeSupplied).map(({ symbol }) => ({ symbol, canBeCollateral: symbol === collAsset && canBeCollateralInEmode(symbol) }));
45
56
  }
46
57
 
47
- return marketAssets.filter(d => d.canBeSupplied).map(({ symbol, isIsolated }) => ({ symbol, canBeCollateral: !isIsolated }));
58
+ return marketAssets.filter(d => d.canBeSupplied).map(({ symbol, isIsolated }) => ({ symbol, canBeCollateral: !isIsolated && canBeCollateralInEmode(symbol) }));
48
59
  };
49
60
 
50
61
  export const aaveAnyGetSuppliableAsCollAssets = ({
@@ -62,8 +73,8 @@ export const aaveAnyGetEmodeMutableProps = (
62
73
  const asset = getNativeAssetFromWrapped(_asset);
63
74
 
64
75
  const assetData = assetsData[asset];
65
- const eModeCategoryData: { collateralAssets: string[], collateralFactor: string, liquidationRatio: string, ltvZeroAssets: string[] } = eModeCategoriesData?.[eModeCategory] || {
66
- collateralAssets: [], ltvZeroAssets: [], collateralFactor: '0', liquidationRatio: '0',
76
+ const eModeCategoryData: { collateralAssets: string[], collateralFactor: string, liquidationRatio: string, ltvZeroAssets: string[], isolated?: boolean } = eModeCategoriesData?.[eModeCategory] || {
77
+ collateralAssets: [], ltvZeroAssets: [], collateralFactor: '0', liquidationRatio: '0', isolated: false,
67
78
  };
68
79
 
69
80
  if (
@@ -72,6 +83,9 @@ export const aaveAnyGetEmodeMutableProps = (
72
83
  || new Dec(eModeCategoryData.collateralFactor || 0).eq(0)
73
84
  ) {
74
85
  const { liquidationRatio, collateralFactor } = assetData;
86
+ if (eModeCategory !== 0 && eModeCategoryData.isolated && !eModeCategoryData.collateralAssets.includes(asset)) {
87
+ return ({ liquidationRatio, collateralFactor: '0' });
88
+ }
75
89
  return ({ liquidationRatio, collateralFactor });
76
90
  }
77
91
  if (eModeCategoryData.ltvZeroAssets.includes(asset)) return ({ liquidationRatio: '0', collateralFactor: '0' });
@@ -118,7 +132,10 @@ export const aaveAnyGetUserReserveLtvAndLltv = (
118
132
  || !eModeCategoryData.collateralAssets.includes(asset)
119
133
  || new Dec(eModeCategoryData.collateralFactor || 0).eq(0)
120
134
  ) {
121
- return { ltv: assetData.collateralFactor, lltv: assetData.liquidationRatio };
135
+ const ltv = eModeCategory !== 0 && eModeCategoryData?.isolated && !eModeCategoryData.collateralAssets.includes(asset)
136
+ ? '0'
137
+ : assetData.collateralFactor;
138
+ return { ltv, lltv: assetData.liquidationRatio };
122
139
  }
123
140
 
124
141
  const ltv = eModeCategoryData.ltvZeroAssets.includes(asset) ? '0' : eModeCategoryData.collateralFactor;
@@ -13,7 +13,7 @@ import {
13
13
  LiquityTroveManagerContractViem,
14
14
  LiquityViewContractViem,
15
15
  } from '../contracts';
16
- import { LIQUITY_TROVE_STATUS_ENUM, LiquityStakingData, LiquityTroveInfo } from '../types';
16
+ import { LIQUITY_TROVE_STATUS_ENUM, LiquityTroveInfo } from '../types';
17
17
  import { ZERO_ADDRESS } from '../constants';
18
18
  import { getViemProvider, setViemBlockNumber } from '../services/viem';
19
19
  import { getEthAmountForDecimals } from '../services/utils';
@@ -113,7 +113,7 @@ export const _getLiquityTroveInfo = async (provider: Client, network: NetworkNum
113
113
 
114
114
  export const getLiquityTroveInfo = async (provider: EthereumProvider, network: NetworkNumber, address: EthAddress): Promise<LiquityTroveInfo> => _getLiquityTroveInfo(getViemProvider(provider, network, { batch: { multicall: true } }), network, address);
115
115
 
116
- export const getLiquityStakingData = async (provider: Client, network: NetworkNumber, address: EthAddress): Promise<LiquityStakingData> => {
116
+ export const getLiquityStakingData = async (provider: Client, network: NetworkNumber, address: EthAddress) => {
117
117
  const lqtyStakingView = LiquityLQTYStakingViem(provider, network);
118
118
  const stabilityPoolView = LiquityStabilityPoolViem(provider, network);
119
119
  const [
@@ -12,7 +12,7 @@ import {
12
12
  } from '../types/common';
13
13
  import {
14
14
  LIQUITY_V2_TROVE_STATUS_ENUM,
15
- LiquityV2AssetsData, LiquityV2MarketData, LiquityV2MarketInfo, LiquityV2SBoldYBoldData, LiquityV2StakingData, LiquityV2TroveData, LiquityV2UsedAssets,
15
+ LiquityV2AssetsData, LiquityV2MarketData, LiquityV2MarketInfo, LiquityV2TroveData, LiquityV2UsedAssets,
16
16
  LiquityV2Versions,
17
17
  } from '../types';
18
18
  import { getStakingApy, STAKING_ASSETS } from '../staking';
@@ -579,7 +579,7 @@ const calculateSPApy = (
579
579
  return apy;
580
580
  };
581
581
 
582
- export const getLiquityV2Staking = async (provider: Client, network: NetworkNumber, market: LiquityV2Versions, user: EthAddress): Promise<LiquityV2StakingData> => {
582
+ export const getLiquityV2Staking = async (provider: Client, network: NetworkNumber, market: LiquityV2Versions, user: EthAddress) => {
583
583
  const stabilityPoolView = createViemContractFromConfigFunc('LiquityV2StabilityPool', stabilityPoolAddrForMarket[market])(provider, network);
584
584
  const activePoolView = createViemContractFromConfigFunc('LiquityV2ActivePool', activePoolAddrForMarket[market])(provider, network);
585
585
 
@@ -638,7 +638,7 @@ export const getLiquityV2Staking = async (provider: Client, network: NetworkNumb
638
638
  };
639
639
  };
640
640
 
641
- export const getLiquitySAndYBold = async (provider: Client, network: NetworkNumber, markets: any, user: EthAddress): Promise<LiquityV2SBoldYBoldData> => {
641
+ export const getLiquitySAndYBold = async (provider: Client, network: NetworkNumber, markets: any, user: EthAddress) => {
642
642
  const sBold = LiquityV2sBoldVaultViem(provider, network);
643
643
  const yBold = createViemContractFromConfigFunc('Erc4626', '0x9F4330700a36B29952869fac9b33f45EEdd8A3d8')(provider, network);
644
644
  const stYBold = createViemContractFromConfigFunc('Erc4626', '0x23346B04a7f55b8760E5860AA5A77383D63491cD')(provider, network);