@defisaver/positions-sdk 2.1.169-portfolio-api-dev → 2.1.169

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/sgho.d.ts +16 -2
  3. package/cjs/aaveV4/lend.d.ts +43 -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/liquity/index.d.ts +12 -2
  10. package/cjs/liquityV2/index.d.ts +23 -8
  11. package/cjs/liquityV2/index.js +19 -37
  12. package/cjs/markets/morphoBlue/index.d.ts +2 -0
  13. package/cjs/markets/morphoBlue/index.js +18 -1
  14. package/cjs/portfolio/index.d.ts +8 -16
  15. package/cjs/portfolio/index.js +520 -458
  16. package/cjs/savings/index.d.ts +2 -8
  17. package/cjs/savings/index.js +4 -33
  18. package/cjs/types/aave.d.ts +2 -98
  19. package/cjs/types/aaveV4.d.ts +0 -44
  20. package/cjs/types/compound.d.ts +2 -26
  21. package/cjs/types/curveUsd.d.ts +1 -9
  22. package/cjs/types/fluid.d.ts +0 -13
  23. package/cjs/types/index.d.ts +0 -1
  24. package/cjs/types/index.js +0 -1
  25. package/cjs/types/liquity.d.ts +0 -12
  26. package/cjs/types/liquityV2.d.ts +0 -24
  27. package/cjs/types/llamaLend.d.ts +1 -12
  28. package/cjs/types/morphoBlue.d.ts +1 -2
  29. package/cjs/types/morphoBlue.js +1 -0
  30. package/cjs/types/portfolio.d.ts +5 -125
  31. package/cjs/types/savings/index.d.ts +1 -9
  32. package/cjs/types/spark.d.ts +1 -21
  33. package/cjs/umbrella/index.d.ts +3 -2
  34. package/esm/aaveV3/index.d.ts +12 -2
  35. package/esm/aaveV3/sgho.d.ts +16 -2
  36. package/esm/aaveV4/lend.d.ts +43 -2
  37. package/esm/claiming/aaveV3.d.ts +2 -2
  38. package/esm/claiming/aaveV3.js +1 -1
  39. package/esm/claiming/ethena.d.ts +1 -2
  40. package/esm/claiming/king.d.ts +1 -2
  41. package/esm/claiming/spark.d.ts +2 -2
  42. package/esm/claiming/spark.js +1 -1
  43. package/esm/fluid/index.d.ts +49 -5
  44. package/esm/liquity/index.d.ts +12 -2
  45. package/esm/liquityV2/index.d.ts +23 -8
  46. package/esm/liquityV2/index.js +18 -35
  47. package/esm/markets/morphoBlue/index.d.ts +2 -0
  48. package/esm/markets/morphoBlue/index.js +16 -0
  49. package/esm/portfolio/index.d.ts +8 -16
  50. package/esm/portfolio/index.js +522 -458
  51. package/esm/savings/index.d.ts +2 -8
  52. package/esm/savings/index.js +3 -31
  53. package/esm/types/aave.d.ts +2 -98
  54. package/esm/types/aaveV4.d.ts +0 -44
  55. package/esm/types/compound.d.ts +2 -26
  56. package/esm/types/curveUsd.d.ts +1 -9
  57. package/esm/types/fluid.d.ts +0 -13
  58. package/esm/types/index.d.ts +0 -1
  59. package/esm/types/index.js +0 -1
  60. package/esm/types/liquity.d.ts +0 -12
  61. package/esm/types/liquityV2.d.ts +0 -24
  62. package/esm/types/llamaLend.d.ts +1 -12
  63. package/esm/types/morphoBlue.d.ts +1 -2
  64. package/esm/types/morphoBlue.js +1 -0
  65. package/esm/types/portfolio.d.ts +5 -125
  66. package/esm/types/savings/index.d.ts +1 -9
  67. package/esm/types/spark.d.ts +1 -21
  68. package/esm/umbrella/index.d.ts +3 -2
  69. package/package.json +2 -2
  70. package/src/aaveV3/index.ts +1 -2
  71. package/src/aaveV3/sgho.ts +17 -2
  72. package/src/aaveV4/lend.ts +48 -2
  73. package/src/claiming/aaveV3.ts +2 -4
  74. package/src/claiming/ethena.ts +5 -5
  75. package/src/claiming/king.ts +3 -3
  76. package/src/claiming/spark.ts +4 -6
  77. package/src/fluid/index.ts +3 -4
  78. package/src/liquity/index.ts +2 -2
  79. package/src/liquityV2/index.ts +22 -48
  80. package/src/markets/morphoBlue/index.ts +16 -0
  81. package/src/portfolio/index.ts +331 -306
  82. package/src/savings/index.ts +4 -41
  83. package/src/types/aave.ts +1 -104
  84. package/src/types/aaveV4.ts +0 -49
  85. package/src/types/compound.ts +2 -38
  86. package/src/types/curveUsd.ts +1 -17
  87. package/src/types/fluid.ts +0 -14
  88. package/src/types/index.ts +0 -1
  89. package/src/types/liquity.ts +1 -13
  90. package/src/types/liquityV2.ts +1 -26
  91. package/src/types/llamaLend.ts +1 -19
  92. package/src/types/morphoBlue.ts +1 -3
  93. package/src/types/portfolio.ts +5 -151
  94. package/src/types/savings/index.ts +1 -12
  95. package/src/types/spark.ts +1 -25
  96. package/src/umbrella/index.ts +1 -2
  97. package/cjs/portfolio/lendingProtocols.d.ts +0 -184
  98. package/cjs/portfolio/lendingProtocols.js +0 -196
  99. package/esm/portfolio/lendingProtocols.d.ts +0 -184
  100. package/esm/portfolio/lendingProtocols.js +0 -189
  101. package/src/portfolio/lendingProtocols.ts +0 -281
@@ -1,31 +1,18 @@
1
1
  import {
2
- AaveV2MarketData, AaveV2PositionData, AaveV3MarketData, AaveV3PositionData, AaveVersions, StakeAaveData, UmbrellaStakingData,
2
+ AaveV2MarketData, AaveV2PositionData, AaveV3MarketData, AaveV3PositionData, AaveVersions,
3
3
  } from './aave';
4
4
  import { AaveV4AccountData, AaveV4SpokeData, AaveV4SpokesType } from './aaveV4';
5
- import {
6
- AaveRewardsClaimableToken,
7
- EthenaAirdropClaimableToken,
8
- KingRewardsClaimableToken,
9
- MerklRewardsClaimableToken,
10
- SparkAirdropClaimableToken,
11
- SparkRewardsClaimableToken,
12
- UniswapAirdropClaimableToken,
13
- } from './claiming';
14
5
  import { EthAddress } from './common';
15
6
  import {
16
7
  CompoundV2MarketsData, CompoundV2PositionData, CompoundV3MarketsData, CompoundV3PositionData, CompoundVersions,
17
8
  } from './compound';
18
9
  import { CrvUSDGlobalMarketData, CrvUSDUserData, CrvUSDVersions } from './curveUsd';
19
- import { FluidEarnPositionData, FluidMarketData, FluidVaultData } from './fluid';
20
- import { LiquityStakingData, LiquityTroveInfo } from './liquity';
21
- import {
22
- LiquityV2MarketData, LiquityV2SBoldYBoldData, LiquityV2StakingData, LiquityV2TroveData, LiquityV2Versions,
23
- } from './liquityV2';
10
+ import { FluidMarketData, FluidVaultData } from './fluid';
11
+ import { LiquityTroveInfo } from './liquity';
12
+ import { LiquityV2MarketData, LiquityV2TroveData, LiquityV2Versions } from './liquityV2';
24
13
  import { LlamaLendGlobalMarketData, LlamaLendUserData, LlamaLendVersionsType } from './llamaLend';
25
14
  import { CdpData, IlkInfo } from './maker';
26
- import {
27
- MorphoBlueEarnData, MorphoBlueMarketInfo, MorphoBluePositionData, MorphoBlueVersions,
28
- } from './morphoBlue';
15
+ import { MorphoBlueMarketInfo, MorphoBluePositionData, MorphoBlueVersions } from './morphoBlue';
29
16
  import { MorphoMidnightMarketInfo, MorphoMidnightPositionData, MorphoMidnightVersions } from './morphoMidnight';
30
17
  import { SparkMarketsData, SparkPositionData, SparkVersions } from './spark';
31
18
 
@@ -34,35 +21,6 @@ export interface PortfolioProtocolData<T> {
34
21
  data: T | null,
35
22
  }
36
23
 
37
- /** A failed fetch of a protocol that, when it succeeds, getPortfolioData returns unwrapped rather than as `{ error, data }`. */
38
- export interface PortfolioProtocolError {
39
- error: string,
40
- data: null,
41
- }
42
-
43
- /** What getPortfolioData reads besides markets. */
44
- export interface PortfolioDataOptions {
45
- /** positions (lending); default true. With false it comes back as {} and no lending position is read. */
46
- positions?: boolean,
47
- /** stakingPositions; default true. With false it comes back as {} and no staking source is read. */
48
- staking?: boolean,
49
- /** rewardsData; default true. With false it comes back as {} and no rewards source is read. */
50
- rewards?: boolean,
51
- /**
52
- * Liquity V2 troves in positions[address].liquityV2; default false, as the DeFi Saver app reads them on its own.
53
- * Mainnet only: elsewhere liquityV2 is {}. Needs positions.
54
- */
55
- liquityV2?: boolean,
56
- }
57
-
58
- /** One Liquity V2 market's troves of an address, by trove id — with an error when the ids or any trove failed to load. */
59
- export interface PortfolioLiquityV2Troves {
60
- error: string,
61
- data: {
62
- [troveId: string]: LiquityV2TroveData;
63
- },
64
- }
65
-
66
24
  export interface PortfolioPositionsDataForAddress {
67
25
  aaveV3: {
68
26
  [key in AaveVersions]?: PortfolioProtocolData<AaveV3PositionData>;
@@ -104,71 +62,11 @@ export interface PortfolioPositionsDataForAddress {
104
62
  aaveV4: {
105
63
  [key in AaveV4SpokesType]?: PortfolioProtocolData<AaveV4AccountData>;
106
64
  };
107
- /** Only with the liquityV2 option. Every trove the address holds, by market. */
108
- liquityV2?: {
109
- [key in LiquityV2Versions]?: PortfolioLiquityV2Troves;
110
- };
111
65
  }
112
66
 
113
67
  export interface PortfolioPositionsData {
114
68
  [key: EthAddress]: PortfolioPositionsDataForAddress;
115
69
  }
116
-
117
- /**
118
- * The staking positions getPortfolioData returns for an address. The shapes are uneven, and the DeFi Saver app
119
- * parses them as they are: a protocol read once per address comes back unwrapped on success, as
120
- * `{ error, data: null }` on failure, and as {} (or Fluid's `{ error: '', data: {} }`) on a network it is not read on.
121
- */
122
- export interface PortfolioStakingPositionsDataForAddress {
123
- /** stkAAVE, stkGHO and sGHO; mainnet only. */
124
- aaveV3: StakeAaveData | PortfolioProtocolError | {};
125
- /** Morpho Blue supply without a borrow (Earn), by market; only markets with a deposit or an error. */
126
- morphoBlue: {
127
- [key in MorphoBlueVersions]?: PortfolioProtocolData<MorphoBlueEarnData>;
128
- };
129
- // Never filled; kept so the shape does not change under the app.
130
- compoundV3: Record<string, never>;
131
- spark: Record<string, never>;
132
- aaveV2: Record<string, never>;
133
- compoundV2: Record<string, never>;
134
- /** LQTY staking and the LUSD stability pool; mainnet only. */
135
- liquity: LiquityStakingData | PortfolioProtocolError | {};
136
- /** Stability pool deposits, by market; mainnet only, legacy markets left out. */
137
- liquityV2: {
138
- [key in LiquityV2Versions]?: PortfolioProtocolData<LiquityV2StakingData>;
139
- };
140
- /** Fluid lending (fToken) deposits; `{ error: '', data: {} }` on a network without Fluid. */
141
- fluid: FluidEarnPositionData[] | PortfolioProtocolError | { error: string, data: Record<string, never> };
142
- /** Umbrella stakes; absent off mainnet. */
143
- umbrella?: UmbrellaStakingData | PortfolioProtocolError;
144
- /** sBOLD, yBOLD and stYBOLD; data is null off mainnet. */
145
- liquityV2SBoldYBold: PortfolioProtocolData<LiquityV2SBoldYBoldData>;
146
- }
147
-
148
- // A Record rather than an interface: the app casts getPortfolioData's result to its own Record<string, …> type, and an
149
- // interface with an address index signature is not comparable to one.
150
- export type PortfolioStakingPositionsData = Record<EthAddress, PortfolioStakingPositionsDataForAddress>;
151
-
152
- /** The claimable rewards getPortfolioData returns for an address. Off mainnet only Merkl and Aave V3 are read. */
153
- export interface PortfolioRewardsDataForAddress {
154
- merkl: PortfolioProtocolData<MerklRewardsClaimableToken[]>;
155
- aaveV3: {
156
- [key in AaveVersions]?: PortfolioProtocolData<AaveRewardsClaimableToken[]>;
157
- };
158
- spark: {
159
- [key in SparkVersions]?: PortfolioProtocolData<SparkRewardsClaimableToken[]>;
160
- };
161
- /** The SPK airdrop. */
162
- spk: PortfolioProtocolData<SparkAirdropClaimableToken[]>;
163
- king: PortfolioProtocolData<KingRewardsClaimableToken[]>;
164
- /** {} off mainnet. */
165
- ethena: PortfolioProtocolData<EthenaAirdropClaimableToken[]> | {};
166
- uniswap: PortfolioProtocolData<UniswapAirdropClaimableToken[]>;
167
- }
168
-
169
- export type PortfolioRewardsData = Record<EthAddress, PortfolioRewardsDataForAddress>;
170
-
171
- /** The `markets` getPortfolioData returns: every market it read, by protocol, keyed by market or spoke. */
172
70
  export interface PortfolioMarketsData {
173
71
  morphoMarketsData: Record<string, MorphoBlueMarketInfo>;
174
72
  morphoMidnightMarketsData: Record<string, MorphoMidnightMarketInfo>;
@@ -181,50 +79,6 @@ export interface PortfolioMarketsData {
181
79
  llamaLendMarketsData: Record<string, LlamaLendGlobalMarketData>;
182
80
  liquityV2MarketsData: Record<string, LiquityV2MarketData>;
183
81
  aaveV4SpokesData: Record<string, AaveV4SpokeData>;
184
- }
185
-
186
- /**
187
- * The `markets` getShifterPortfolioData returns: the portfolio's markets, plus Fluid's and Maker's, which the shifter
188
- * offers as destinations. Kept apart from PortfolioMarketsData, which getPortfolioData does not fill these into.
189
- */
190
- export interface ShifterPortfolioMarketsData extends PortfolioMarketsData {
191
82
  fluidMarketsData: Record<string, FluidMarketData>;
192
83
  makerMarketsData: Record<string, IlkInfo>;
193
84
  }
194
-
195
- /** The markets that could not be read, by their key in PortfolioMarketsData, then by market or spoke: the error. */
196
- export type PortfolioMarketsErrors = {
197
- [key in keyof PortfolioMarketsData]?: Record<string, string>;
198
- };
199
-
200
- /**
201
- * What the portfolio fetch could not read and has no `{ error, data }` entry of its own to report it in. A key is
202
- * present only when something under it failed; {} when everything was read.
203
- */
204
- export interface PortfolioErrors {
205
- /** Markets missing from `markets`; every position on such a market is an entry with an error. */
206
- markets?: PortfolioMarketsErrors;
207
- /** Addresses whose Maker vault list could not be read: their `maker` is {}, which would otherwise read as "no vaults". */
208
- makerCdps?: Record<EthAddress, string>;
209
- }
210
-
211
- /** getPortfolioMarketsData's result. */
212
- export interface PortfolioMarketsResult {
213
- /** Every market read; one that failed is missing and named in `errors`. */
214
- markets: PortfolioMarketsData;
215
- errors: PortfolioMarketsErrors;
216
- }
217
-
218
- /** getPortfolioUserData's result: what is read per address. */
219
- export interface PortfolioUserData {
220
- positions: PortfolioPositionsData;
221
- stakingPositions: PortfolioStakingPositionsData;
222
- rewardsData: PortfolioRewardsData;
223
- errors: Pick<PortfolioErrors, 'makerCdps'>;
224
- }
225
-
226
- /** getPortfolioData's result. */
227
- export interface PortfolioData extends Omit<PortfolioUserData, 'errors'> {
228
- markets: PortfolioMarketsData;
229
- errors: PortfolioErrors;
230
- }
@@ -23,15 +23,4 @@ export interface SavingsVaultData {
23
23
  optionType: string,
24
24
  }
25
25
 
26
- /** The key of every savings vault getSavingsData reads. */
27
- export type SavingsVaultKey = MorphoVaultType | YearnVaultType | MakerDsrType | SkySavingsType | SparkSavingsVaultType | SummerVaultType | YearnV3VaultType;
28
-
29
- export type SavingsData = Partial<Record<SavingsVaultKey, SavingsVaultData>>;
30
-
31
- /** Why each vault that was read for a network came back without data. */
32
- export type SavingsErrors = Partial<Record<SavingsVaultKey, string>>;
33
-
34
- export interface SavingsDataWithErrors {
35
- data: SavingsData,
36
- errors: SavingsErrors,
37
- }
26
+ export type SavingsData = Partial<Record<MorphoVaultType | YearnVaultType | MakerDsrType | SkySavingsType | SparkSavingsVaultType | SummerVaultType | YearnV3VaultType, SavingsVaultData>>;
@@ -57,22 +57,6 @@ export interface SparkAssetData extends MMAssetData {
57
57
  eModeCategory: number,
58
58
  liquidationBonus: string,
59
59
  liquidationRatio: string,
60
- // Set by _getSparkMarketsData. Optional, so objects built by hand still type-check.
61
- debtCeilingForIsolationMode?: string,
62
- isSiloed?: boolean,
63
- isolationModeTotalDebt?: string,
64
- isolationModeBorrowingEnabled?: boolean,
65
- assetId?: number,
66
- borrowRateStable?: string,
67
- supplyCap?: string,
68
- isInactive?: boolean,
69
- isFrozen?: boolean,
70
- isPaused?: boolean,
71
- canBeWithdrawn?: boolean,
72
- canBePayBacked?: boolean,
73
- disabledStableBorrowing?: boolean,
74
- isFlashLoanEnabled?: boolean,
75
- aTokenAddress?: EthAddress,
76
60
  }
77
61
 
78
62
  export interface SparkAssetsData {
@@ -132,15 +116,7 @@ export interface SparkAggregatedPositionData {
132
116
  exposure: string,
133
117
  }
134
118
 
135
- /**
136
- * Fields sparkGetAggregatedPositionData adds to every Spark position at runtime, on top of those declared below.
137
- * Optional, so code that builds a position by hand keeps compiling.
138
- */
139
- export type SparkPositionAggregatedFields = Partial<Omit<SparkAggregatedPositionData,
140
- | keyof MMPositionData | 'ratio' | 'collRatio' | 'suppliedUsd' | 'borrowedUsd' | 'borrowLimitUsd'
141
- | 'suppliedCollateralUsd' | 'incentiveUsd' | 'totalInterestUsd'>>;
142
-
143
- export interface SparkPositionData extends MMPositionData, SparkPositionAggregatedFields {
119
+ export interface SparkPositionData extends MMPositionData {
144
120
  ratio: string,
145
121
  minRatio: string,
146
122
  collRatio: string,
@@ -1,14 +1,13 @@
1
1
  import { Client } from 'viem';
2
2
  import { AaveUmbrellaViewViem, AaveV3ViewContractViem } from '../contracts';
3
3
  import { EthAddress, NetworkNumber } from '../types/common';
4
- import { UmbrellaStakingData } from '../types/aave';
5
4
  import { compareAddresses, convertHybridArraysToObjects, getEthAmountForDecimals } from '../services/utils';
6
5
  import { findMatching, tokenEntries } from './umbrellaUtils';
7
6
 
8
7
  const umbrella = '0xD400fc38ED4732893174325693a63C30ee3881a8';
9
8
  const aaveOracle = '0x54586bE62E3c3580375aE3723C145253060Ca0C2';
10
9
 
11
- export const getUmbrellaData = async (provider: Client, network: NetworkNumber, address: EthAddress): Promise<UmbrellaStakingData> => {
10
+ export const getUmbrellaData = async (provider: Client, network: NetworkNumber, address: EthAddress) => {
12
11
  const umbrellaView = AaveUmbrellaViewViem(provider, network);
13
12
  const aaveV3View = AaveV3ViewContractViem(provider, network);
14
13
  const [tokensAggregatedData, additionalUmbrellaStakingData, userAggregatedData] = await Promise.all([
@@ -1,184 +0,0 @@
1
- import { Client } from 'viem';
2
- import { EthAddress, NetworkNumber } from '../types/common';
3
- import { AaveMarketInfo, AaveV4SpokeInfo, CompoundMarketData, CrvUSDMarketData, LlamaLendMarketData, MorphoBlueMarketData, MorphoMidnightMarketData, PortfolioMarketsData, PortfolioPositionsData, PortfolioPositionsDataForAddress, PortfolioProtocolData, SparkMarketData } from '../types';
4
- /**
5
- * The lending protocols the portfolio reads the same way — a market's data, then each address's position on it — one
6
- * entry each. Adding such a protocol is its types (its key in PortfolioPositionsDataForAddress and in
7
- * PortfolioMarketsData) and its entry in LENDING_PROTOCOLS; the portfolio reads, errors and options follow. Maker,
8
- * Liquity, Fluid and Liquity V2 have shapes of their own and are read by their own code in ./index.ts.
9
- */
10
- /** What a position read gets. */
11
- export interface PortfolioReadContext {
12
- client: Client;
13
- network: NetworkNumber;
14
- }
15
- /** What a market read gets: also the default client, on Ethereum (Compound V3 reads its prices there). */
16
- export interface PortfolioMarketsReadContext extends PortfolioReadContext {
17
- defaultClient: Client;
18
- }
19
- type PositionKey = keyof PortfolioPositionsDataForAddress;
20
- type MarketsKey = keyof PortfolioMarketsData;
21
- type PositionsOf<K extends PositionKey> = NonNullable<PortfolioPositionsDataForAddress[K]>;
22
- /** The data of one of a protocol's positions: what positions[address][K][market] holds as `{ error, data }`. */
23
- export type LendingPositionData<K extends PositionKey> = NonNullable<PositionsOf<K>[keyof PositionsOf<K>]> extends PortfolioProtocolData<infer D> ? D : never;
24
- export interface LendingProtocol<K extends PositionKey, M extends MarketsKey, Market extends {
25
- value: string;
26
- }> {
27
- /** Its key in PortfolioMarketsData. */
28
- marketsKey: M;
29
- /** Its name in error messages. */
30
- label: string;
31
- /** Its markets on a network; none where it is not deployed. */
32
- markets: (network: NetworkNumber) => Market[];
33
- readMarket: (context: PortfolioMarketsReadContext, market: Market) => Promise<PortfolioMarketsData[M][string]>;
34
- /** An address's position on a market; undefined when the market can hold none. */
35
- readPosition: (context: PortfolioReadContext, address: EthAddress, market: Market, marketData: PortfolioMarketsData[M][string]) => Promise<LendingPositionData<K> | undefined>;
36
- /** Whether there is a position to list: an address without one gets no entry for that market. */
37
- holds: (position: LendingPositionData<K>) => boolean;
38
- }
39
- /**
40
- * A market's data, or a throw that the caller's catch turns into the position's error entry: read against a missing
41
- * market, a position would otherwise come back empty and read as "no position".
42
- */
43
- export declare const requireMarket: <T>(marketsData: Record<string, T>, market: string) => T;
44
- export declare const aaveV3Lending: {
45
- key: "aaveV3";
46
- marketsKey: "aaveV3MarketsData";
47
- markets: (network: NetworkNumber) => AaveMarketInfo[];
48
- readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
49
- readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
50
- };
51
- export declare const aaveV4Lending: {
52
- key: "aaveV4";
53
- marketsKey: "aaveV4SpokesData";
54
- markets: (network: NetworkNumber) => AaveV4SpokeInfo[];
55
- readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
56
- readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
57
- };
58
- export declare const morphoBlueLending: {
59
- key: "morphoBlue";
60
- marketsKey: "morphoMarketsData";
61
- markets: (network: NetworkNumber) => MorphoBlueMarketData[];
62
- readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
63
- readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
64
- };
65
- export declare const morphoMidnightLending: {
66
- key: "morphoMidnight";
67
- marketsKey: "morphoMidnightMarketsData";
68
- markets: (network: NetworkNumber) => MorphoMidnightMarketData[];
69
- readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
70
- readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
71
- };
72
- export declare const compoundV3Lending: {
73
- key: "compoundV3";
74
- marketsKey: "compoundV3MarketsData";
75
- markets: (network: NetworkNumber) => CompoundMarketData[];
76
- readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
77
- readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
78
- };
79
- export declare const sparkLending: {
80
- key: "spark";
81
- marketsKey: "sparkMarketsData";
82
- markets: (network: NetworkNumber) => SparkMarketData[];
83
- readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
84
- readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
85
- };
86
- export declare const aaveV2Lending: {
87
- key: "aaveV2";
88
- marketsKey: "aaveV2MarketsData";
89
- markets: (network: NetworkNumber) => AaveMarketInfo[];
90
- readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
91
- readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
92
- };
93
- export declare const compoundV2Lending: {
94
- key: "compoundV2";
95
- marketsKey: "compoundV2MarketsData";
96
- markets: (network: NetworkNumber) => CompoundMarketData[];
97
- readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
98
- readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
99
- };
100
- export declare const crvUsdLending: {
101
- key: "crvUsd";
102
- marketsKey: "crvUsdMarketsData";
103
- markets: (network: NetworkNumber) => CrvUSDMarketData[];
104
- readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
105
- readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
106
- };
107
- export declare const llamaLendLending: {
108
- key: "llamaLend";
109
- marketsKey: "llamaLendMarketsData";
110
- markets: (network: NetworkNumber) => LlamaLendMarketData[];
111
- readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
112
- readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
113
- };
114
- /** Every lending protocol read through its entry, in the order positions list them. */
115
- export declare const LENDING_PROTOCOLS: readonly [{
116
- key: "aaveV3";
117
- marketsKey: "aaveV3MarketsData";
118
- markets: (network: NetworkNumber) => AaveMarketInfo[];
119
- readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
120
- readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
121
- }, {
122
- key: "aaveV4";
123
- marketsKey: "aaveV4SpokesData";
124
- markets: (network: NetworkNumber) => AaveV4SpokeInfo[];
125
- readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
126
- readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
127
- }, {
128
- key: "morphoBlue";
129
- marketsKey: "morphoMarketsData";
130
- markets: (network: NetworkNumber) => MorphoBlueMarketData[];
131
- readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
132
- readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
133
- }, {
134
- key: "morphoMidnight";
135
- marketsKey: "morphoMidnightMarketsData";
136
- markets: (network: NetworkNumber) => MorphoMidnightMarketData[];
137
- readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
138
- readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
139
- }, {
140
- key: "compoundV3";
141
- marketsKey: "compoundV3MarketsData";
142
- markets: (network: NetworkNumber) => CompoundMarketData[];
143
- readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
144
- readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
145
- }, {
146
- key: "spark";
147
- marketsKey: "sparkMarketsData";
148
- markets: (network: NetworkNumber) => SparkMarketData[];
149
- readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
150
- readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
151
- }, {
152
- key: "aaveV2";
153
- marketsKey: "aaveV2MarketsData";
154
- markets: (network: NetworkNumber) => AaveMarketInfo[];
155
- readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
156
- readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
157
- }, {
158
- key: "compoundV2";
159
- marketsKey: "compoundV2MarketsData";
160
- markets: (network: NetworkNumber) => CompoundMarketData[];
161
- readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
162
- readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
163
- }, {
164
- key: "crvUsd";
165
- marketsKey: "crvUsdMarketsData";
166
- markets: (network: NetworkNumber) => CrvUSDMarketData[];
167
- readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
168
- readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
169
- }, {
170
- key: "llamaLend";
171
- marketsKey: "llamaLendMarketsData";
172
- markets: (network: NetworkNumber) => LlamaLendMarketData[];
173
- readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
174
- readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
175
- }];
176
- export type LendingKey = typeof LENDING_PROTOCOLS[number]['key'];
177
- /** The keys ./index.ts reads with code of its own. */
178
- export type SpecialPositionKey = 'maker' | 'liquity' | 'fluid' | 'liquityV2';
179
- type SpecialMarketsKey = 'liquityV2MarketsData';
180
- type UnreadPositionKey = Exclude<PositionKey, LendingKey | SpecialPositionKey>;
181
- type UnreadMarketsKey = Exclude<MarketsKey, typeof LENDING_PROTOCOLS[number]['marketsKey'] | SpecialMarketsKey>;
182
- export declare const EVERY_POSITION_KEY_IS_READ: [UnreadPositionKey] extends [never] ? true : UnreadPositionKey;
183
- export declare const EVERY_MARKETS_KEY_IS_READ: [UnreadMarketsKey] extends [never] ? true : UnreadMarketsKey;
184
- export {};
@@ -1,196 +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.EVERY_MARKETS_KEY_IS_READ = exports.EVERY_POSITION_KEY_IS_READ = exports.LENDING_PROTOCOLS = exports.llamaLendLending = exports.crvUsdLending = exports.compoundV2Lending = exports.aaveV2Lending = exports.sparkLending = exports.compoundV3Lending = exports.morphoMidnightLending = exports.morphoBlueLending = exports.aaveV4Lending = exports.aaveV3Lending = exports.requireMarket = void 0;
16
- const decimal_js_1 = __importDefault(require("decimal.js"));
17
- const common_1 = require("../types/common");
18
- const markets_1 = require("../markets");
19
- const types_1 = require("../types");
20
- const aaveV3_1 = require("../aaveV3");
21
- const aaveV4_1 = require("../aaveV4");
22
- const aaveV2_1 = require("../aaveV2");
23
- const compoundV2_1 = require("../compoundV2");
24
- const compoundV3_1 = require("../compoundV3");
25
- const curveUsd_1 = require("../curveUsd");
26
- const llamaLend_1 = require("../llamaLend");
27
- const morphoBlue_1 = require("../morphoBlue");
28
- const morphoMidnight_1 = require("../morphoMidnight");
29
- const spark_1 = require("../spark");
30
- const constants_1 = require("../constants");
31
- /**
32
- * A market's data, or a throw that the caller's catch turns into the position's error entry: read against a missing
33
- * market, a position would otherwise come back empty and read as "no position".
34
- */
35
- const requireMarket = (marketsData, market) => {
36
- const marketData = marketsData[market];
37
- if (!marketData)
38
- throw new Error(`Market data for ${market} is not available`);
39
- return marketData;
40
- };
41
- exports.requireMarket = requireMarket;
42
- /** requireMarket for one protocol's key, typed by that key's market data. */
43
- const requireMarketOf = (marketsData, key, market) => {
44
- // TypeScript reads marketsData[key][market] as any protocol's market data; the key's own is what is stored there.
45
- const marketData = marketsData[key][market];
46
- if (!marketData)
47
- throw new Error(`Market data for ${market} is not available`);
48
- return marketData;
49
- };
50
- /** A protocol's entry with its reads, typed by its own market and position types. */
51
- const lendingProtocol = (key, protocol) => {
52
- /** Every market of the protocol into `markets`; resolves to the ones that failed (left out), with their errors. */
53
- const readMarkets = (context, markets) => __awaiter(void 0, void 0, void 0, function* () {
54
- const protocolMarkets = markets[protocol.marketsKey];
55
- const failed = {};
56
- yield Promise.all(protocol.markets(context.network).map((market) => __awaiter(void 0, void 0, void 0, function* () {
57
- try {
58
- protocolMarkets[market.value] = yield protocol.readMarket(context, market);
59
- }
60
- catch (error) {
61
- console.error(`Error fetching ${protocol.marketsKey} for market ${market.value}:`, error);
62
- failed[market.value] = `Error fetching ${protocol.marketsKey} for market ${market.value}`;
63
- }
64
- })));
65
- return failed;
66
- });
67
- /**
68
- * Every address's position on every market into `positions`, each read once its market is in: an entry with the data
69
- * where the address holds a position, an entry with an error where the read or its market failed, none otherwise.
70
- */
71
- const readPositions = (context, addresses, marketsData, positions) => protocol.markets(context.network).flatMap((market) => addresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
72
- // Keyed by the protocol's market type in PortfolioPositionsDataForAddress; written here by market.value.
73
- const byMarket = positions[address.toLowerCase()][key];
74
- try {
75
- const marketData = requireMarketOf(yield marketsData, protocol.marketsKey, market.value);
76
- const position = yield protocol.readPosition(context, address, market, marketData);
77
- if (position && protocol.holds(position))
78
- byMarket[market.value] = { error: '', data: position };
79
- }
80
- catch (error) {
81
- console.error(`Error fetching ${protocol.label} account data for address ${address} on market ${market.value}:`, error);
82
- byMarket[market.value] = { error: `Error fetching ${protocol.label} account data for address ${address} on market ${market.value}`, data: null };
83
- }
84
- })));
85
- return {
86
- key, marketsKey: protocol.marketsKey, markets: protocol.markets, readMarkets, readPositions,
87
- };
88
- };
89
- const onNetwork = (network, markets) => markets.filter((market) => market.chainIds.includes(network));
90
- const suppliesAnything = (position) => new decimal_js_1.default(position.suppliedUsd).gt(0);
91
- const suppliesOrBorrowsAnything = (position) => new decimal_js_1.default(position.suppliedUsd).gt(0) || new decimal_js_1.default(position.borrowedUsd).gt(0);
92
- exports.aaveV3Lending = lendingProtocol('aaveV3', {
93
- marketsKey: 'aaveV3MarketsData',
94
- label: 'AaveV3',
95
- markets: (network) => onNetwork(network, [types_1.AaveVersions.AaveV3, types_1.AaveVersions.AaveV3Lido, types_1.AaveVersions.AaveV3Etherfi].map((version) => (0, markets_1.AaveMarkets)(network)[version])),
96
- readMarket: ({ client, network }, market) => (0, aaveV3_1._getAaveV3MarketData)(client, network, market),
97
- readPosition: ({ client, network }, address, market, marketData) => (0, aaveV3_1._getAaveV3AccountData)(client, network, address, Object.assign({ selectedMarket: market }, marketData)),
98
- holds: suppliesAnything,
99
- });
100
- exports.aaveV4Lending = lendingProtocol('aaveV4', {
101
- marketsKey: 'aaveV4SpokesData',
102
- label: 'AaveV4',
103
- markets: (network) => onNetwork(network, Object.values((0, markets_1.AaveV4Spokes)(network))),
104
- readMarket: ({ client, network }, spoke) => (0, aaveV4_1._getAaveV4SpokeData)(client, network, spoke),
105
- readPosition: ({ client, network }, address, _spoke, spokeData) => (0, aaveV4_1._getAaveV4AccountData)(client, network, spokeData, address),
106
- holds: suppliesAnything,
107
- });
108
- exports.morphoBlueLending = lendingProtocol('morphoBlue', {
109
- marketsKey: 'morphoMarketsData',
110
- label: 'MorphoBlue',
111
- markets: (network) => onNetwork(network, Object.values((0, markets_1.MorphoBlueMarkets)(network))),
112
- readMarket: ({ client, network }, market) => (0, morphoBlue_1._getMorphoBluePortfolioMarketData)(client, network, market),
113
- readPosition: ({ client, network }, address, market, marketData) => (0, morphoBlue_1._getMorphoBlueAccountData)(client, network, address, market, marketData),
114
- holds: suppliesAnything,
115
- });
116
- exports.morphoMidnightLending = lendingProtocol('morphoMidnight', {
117
- marketsKey: 'morphoMidnightMarketsData',
118
- label: 'MorphoMidnight',
119
- markets: (network) => onNetwork(network, Object.values((0, markets_1.MorphoMidnightMarkets)(network))),
120
- readMarket: ({ client, network }, market) => (0, morphoMidnight_1._getMorphoMidnightMarketData)(client, network, market),
121
- // Markets are created lazily on the first position, so an uncreated one can hold no position.
122
- readPosition: (_a, address_1, market_1, marketData_1) => __awaiter(void 0, [_a, address_1, market_1, marketData_1], void 0, function* ({ client, network }, address, market, marketData) {
123
- return (marketData.isCreated
124
- ? (0, morphoMidnight_1._getMorphoMidnightAccountData)(client, network, address, market, marketData)
125
- : undefined);
126
- }),
127
- holds: suppliesAnything,
128
- });
129
- exports.compoundV3Lending = lendingProtocol('compoundV3', {
130
- marketsKey: 'compoundV3MarketsData',
131
- label: 'CompoundV3',
132
- markets: (network) => onNetwork(network, Object.values((0, markets_1.CompoundMarkets)(network)).filter((market) => market.value !== types_1.CompoundVersions.CompoundV2)),
133
- readMarket: ({ client, defaultClient, network }, market) => (0, compoundV3_1._getCompoundV3MarketsData)(client, network, market, defaultClient),
134
- readPosition: ({ client, network }, address, market, marketData) => (0, compoundV3_1._getCompoundV3AccountData)(client, network, address, constants_1.ZERO_ADDRESS, { selectedMarket: market, assetsData: marketData.assetsData }),
135
- holds: suppliesAnything,
136
- });
137
- exports.sparkLending = lendingProtocol('spark', {
138
- marketsKey: 'sparkMarketsData',
139
- label: 'Spark',
140
- markets: (network) => onNetwork(network, Object.values((0, markets_1.SparkMarkets)(network))),
141
- readMarket: ({ client, network }, market) => (0, spark_1._getSparkMarketsData)(client, network, market),
142
- readPosition: ({ client, network }, address, market, marketData) => (0, spark_1._getSparkAccountData)(client, network, address, {
143
- selectedMarket: market, assetsData: marketData.assetsData, eModeCategoriesData: marketData.eModeCategoriesData,
144
- }),
145
- holds: suppliesAnything,
146
- });
147
- exports.aaveV2Lending = lendingProtocol('aaveV2', {
148
- marketsKey: 'aaveV2MarketsData',
149
- label: 'AaveV2',
150
- markets: (network) => onNetwork(network, [(0, markets_1.AaveMarkets)(network)[types_1.AaveVersions.AaveV2]]),
151
- readMarket: ({ client, network }, market) => (0, aaveV2_1._getAaveV2MarketsData)(client, network, market),
152
- readPosition: ({ client, network }, address, market, marketData) => (0, aaveV2_1._getAaveV2AccountData)(client, network, address, marketData.assetsData, market),
153
- holds: suppliesAnything,
154
- });
155
- exports.compoundV2Lending = lendingProtocol('compoundV2', {
156
- marketsKey: 'compoundV2MarketsData',
157
- label: 'CompoundV2',
158
- markets: (network) => onNetwork(network, [(0, markets_1.CompoundMarkets)(network)[types_1.CompoundVersions.CompoundV2]]),
159
- readMarket: ({ client, network }) => (0, compoundV2_1._getCompoundV2MarketsData)(client, network),
160
- readPosition: ({ client, network }, address, _market, marketData) => (0, compoundV2_1._getCompoundV2AccountData)(client, network, address, marketData.assetsData),
161
- holds: suppliesAnything,
162
- });
163
- exports.crvUsdLending = lendingProtocol('crvUsd', {
164
- marketsKey: 'crvUsdMarketsData',
165
- label: 'Curve USD',
166
- markets: (network) => onNetwork(network, Object.values((0, markets_1.CrvUsdMarkets)(network))),
167
- readMarket: ({ client, network }, market) => (0, curveUsd_1._getCurveUsdGlobalData)(client, network, market),
168
- // The market's borrow rate is passed in, so the read does not fetch it again.
169
- readPosition: ({ client, network }, address, market, marketData) => (0, curveUsd_1._getCurveUsdUserData)(client, network, address, market, marketData.activeBand, marketData.borrowRate),
170
- holds: suppliesOrBorrowsAnything,
171
- });
172
- exports.llamaLendLending = lendingProtocol('llamaLend', {
173
- marketsKey: 'llamaLendMarketsData',
174
- label: 'LlamaLend',
175
- markets: (network) => ([common_1.NetworkNumber.Eth, common_1.NetworkNumber.Arb].includes(network) ? onNetwork(network, Object.values((0, markets_1.LlamaLendMarkets)(network))) : []),
176
- readMarket: ({ client, network }, market) => (0, llamaLend_1._getLlamaLendGlobalData)(client, network, market),
177
- readPosition: (_a, address_1, market_1, marketData_1) => __awaiter(void 0, [_a, address_1, market_1, marketData_1], void 0, function* ({ client, network }, address, market, marketData) {
178
- return (Object.assign(Object.assign({}, yield (0, llamaLend_1._getLlamaLendUserData)(client, network, address, market, marketData)), { borrowRate: marketData.borrowRate }));
179
- }),
180
- holds: suppliesOrBorrowsAnything,
181
- });
182
- /** Every lending protocol read through its entry, in the order positions list them. */
183
- exports.LENDING_PROTOCOLS = [
184
- exports.aaveV3Lending,
185
- exports.aaveV4Lending,
186
- exports.morphoBlueLending,
187
- exports.morphoMidnightLending,
188
- exports.compoundV3Lending,
189
- exports.sparkLending,
190
- exports.aaveV2Lending,
191
- exports.compoundV2Lending,
192
- exports.crvUsdLending,
193
- exports.llamaLendLending,
194
- ];
195
- exports.EVERY_POSITION_KEY_IS_READ = true;
196
- exports.EVERY_MARKETS_KEY_IS_READ = true;