@defisaver/positions-sdk 2.1.161-portfolio-api-1-dev → 2.1.161-portfolio-api-3-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.
- package/cjs/aaveV2/index.js +2 -0
- package/cjs/aaveV3/index.d.ts +41 -12
- package/cjs/aaveV3/index.js +237 -2
- package/cjs/aaveV3/sgho.d.ts +2 -16
- package/cjs/aaveV4/lend.d.ts +2 -43
- package/cjs/claiming/aaveV3.d.ts +2 -2
- package/cjs/claiming/ethena.d.ts +2 -1
- package/cjs/claiming/king.d.ts +2 -1
- package/cjs/claiming/spark.d.ts +2 -2
- package/cjs/curveUsd/index.d.ts +5 -2
- package/cjs/curveUsd/index.js +30 -15
- package/cjs/fluid/index.d.ts +10 -49
- package/cjs/fluid/index.js +36 -1
- package/cjs/helpers/aaveHelpers/index.d.ts +9 -1
- package/cjs/helpers/aaveHelpers/index.js +26 -6
- package/cjs/helpers/aaveV4Helpers/index.js +1 -0
- package/cjs/helpers/compoundHelpers/index.js +2 -0
- package/cjs/helpers/curveUsdHelpers/index.d.ts +3 -1
- package/cjs/helpers/curveUsdHelpers/index.js +15 -2
- package/cjs/helpers/fluidHelpers/index.js +1 -0
- package/cjs/helpers/liquityV2Helpers/index.js +1 -0
- package/cjs/helpers/llamaLendHelpers/index.js +1 -0
- package/cjs/helpers/makerHelpers/index.d.ts +1 -1
- package/cjs/helpers/makerHelpers/index.js +2 -2
- package/cjs/helpers/morphoBlueHelpers/index.js +2 -0
- package/cjs/helpers/morphoMidnightHelpers/index.js +2 -0
- package/cjs/helpers/sparkHelpers/index.js +1 -0
- package/cjs/liquity/index.d.ts +2 -12
- package/cjs/liquity/index.js +15 -2
- package/cjs/liquityV2/index.d.ts +8 -23
- package/cjs/liquityV2/index.js +37 -19
- package/cjs/maker/index.d.ts +7 -2
- package/cjs/maker/index.js +44 -12
- package/cjs/markets/index.d.ts +1 -0
- package/cjs/markets/index.js +3 -1
- package/cjs/markets/maker/index.d.ts +1 -0
- package/cjs/markets/maker/index.js +13 -0
- package/cjs/moneymarket/moneymarketCommonService.d.ts +9 -0
- package/cjs/moneymarket/moneymarketCommonService.js +13 -1
- package/cjs/portfolio/index.d.ts +17 -5
- package/cjs/portfolio/index.js +583 -381
- package/cjs/portfolio/lendingProtocols.d.ts +184 -0
- package/cjs/portfolio/lendingProtocols.js +196 -0
- package/cjs/savings/index.d.ts +8 -2
- package/cjs/savings/index.js +37 -5
- package/cjs/savings/morphoVaults/index.d.ts +1 -1
- package/cjs/savings/morphoVaults/index.js +56 -18
- package/cjs/savings/morphoVaults/options.d.ts +2 -0
- package/cjs/savings/morphoVaults/options.js +61 -1
- package/cjs/spark/index.js +1 -0
- package/cjs/staking/staking.d.ts +20 -0
- package/cjs/staking/staking.js +19 -1
- package/cjs/types/aave.d.ts +86 -0
- package/cjs/types/aaveV4.d.ts +45 -0
- package/cjs/types/compound.d.ts +2 -0
- package/cjs/types/curveUsd.d.ts +6 -0
- package/cjs/types/fluid.d.ts +14 -0
- package/cjs/types/index.d.ts +1 -0
- package/cjs/types/index.js +1 -0
- package/cjs/types/liquity.d.ts +16 -0
- package/cjs/types/liquityV2.d.ts +26 -0
- package/cjs/types/maker.d.ts +4 -0
- package/cjs/types/morphoBlue.d.ts +2 -0
- package/cjs/types/morphoMidnight.d.ts +1 -0
- package/cjs/types/portfolio.d.ts +127 -6
- package/cjs/types/savings/index.d.ts +9 -1
- package/cjs/types/savings/morphoVaults.d.ts +10 -2
- package/cjs/types/savings/morphoVaults.js +9 -1
- package/cjs/types/spark.d.ts +2 -0
- package/cjs/umbrella/index.d.ts +2 -3
- package/esm/aaveV2/index.js +2 -0
- package/esm/aaveV3/index.d.ts +41 -12
- package/esm/aaveV3/index.js +231 -2
- package/esm/aaveV3/sgho.d.ts +2 -16
- package/esm/aaveV4/lend.d.ts +2 -43
- package/esm/claiming/aaveV3.d.ts +2 -2
- package/esm/claiming/aaveV3.js +1 -1
- package/esm/claiming/ethena.d.ts +2 -1
- package/esm/claiming/king.d.ts +2 -1
- package/esm/claiming/spark.d.ts +2 -2
- package/esm/claiming/spark.js +1 -1
- package/esm/curveUsd/index.d.ts +5 -2
- package/esm/curveUsd/index.js +30 -15
- package/esm/fluid/index.d.ts +10 -49
- package/esm/fluid/index.js +33 -0
- package/esm/helpers/aaveHelpers/index.d.ts +9 -1
- package/esm/helpers/aaveHelpers/index.js +23 -5
- package/esm/helpers/aaveV4Helpers/index.js +1 -0
- package/esm/helpers/compoundHelpers/index.js +2 -0
- package/esm/helpers/curveUsdHelpers/index.d.ts +3 -1
- package/esm/helpers/curveUsdHelpers/index.js +16 -3
- package/esm/helpers/fluidHelpers/index.js +1 -0
- package/esm/helpers/liquityV2Helpers/index.js +1 -0
- package/esm/helpers/llamaLendHelpers/index.js +2 -1
- package/esm/helpers/makerHelpers/index.d.ts +1 -1
- package/esm/helpers/makerHelpers/index.js +2 -2
- package/esm/helpers/morphoBlueHelpers/index.js +2 -0
- package/esm/helpers/morphoMidnightHelpers/index.js +2 -0
- package/esm/helpers/sparkHelpers/index.js +1 -0
- package/esm/liquity/index.d.ts +2 -12
- package/esm/liquity/index.js +16 -3
- package/esm/liquityV2/index.d.ts +8 -23
- package/esm/liquityV2/index.js +35 -18
- package/esm/maker/index.d.ts +7 -2
- package/esm/maker/index.js +44 -14
- package/esm/markets/index.d.ts +1 -0
- package/esm/markets/index.js +1 -0
- package/esm/markets/maker/index.d.ts +1 -0
- package/esm/markets/maker/index.js +10 -0
- package/esm/moneymarket/moneymarketCommonService.d.ts +9 -0
- package/esm/moneymarket/moneymarketCommonService.js +11 -0
- package/esm/portfolio/index.d.ts +17 -5
- package/esm/portfolio/index.js +584 -385
- package/esm/portfolio/lendingProtocols.d.ts +184 -0
- package/esm/portfolio/lendingProtocols.js +189 -0
- package/esm/savings/index.d.ts +8 -2
- package/esm/savings/index.js +35 -4
- package/esm/savings/morphoVaults/index.d.ts +1 -1
- package/esm/savings/morphoVaults/index.js +57 -19
- package/esm/savings/morphoVaults/options.d.ts +2 -0
- package/esm/savings/morphoVaults/options.js +61 -1
- package/esm/spark/index.js +1 -0
- package/esm/staking/staking.d.ts +20 -0
- package/esm/staking/staking.js +17 -0
- package/esm/types/aave.d.ts +86 -0
- package/esm/types/aaveV4.d.ts +45 -0
- package/esm/types/compound.d.ts +2 -0
- package/esm/types/curveUsd.d.ts +6 -0
- package/esm/types/fluid.d.ts +14 -0
- package/esm/types/index.d.ts +1 -0
- package/esm/types/index.js +1 -0
- package/esm/types/liquity.d.ts +16 -0
- package/esm/types/liquityV2.d.ts +26 -0
- package/esm/types/maker.d.ts +4 -0
- package/esm/types/morphoBlue.d.ts +2 -0
- package/esm/types/morphoMidnight.d.ts +1 -0
- package/esm/types/portfolio.d.ts +127 -6
- package/esm/types/savings/index.d.ts +9 -1
- package/esm/types/savings/morphoVaults.d.ts +10 -2
- package/esm/types/savings/morphoVaults.js +8 -0
- package/esm/types/spark.d.ts +2 -0
- package/esm/umbrella/index.d.ts +2 -3
- package/package.json +3 -2
- package/src/aaveV2/index.ts +2 -0
- package/src/aaveV3/index.ts +293 -2
- package/src/aaveV3/sgho.ts +2 -17
- package/src/aaveV4/lend.ts +2 -48
- package/src/claiming/aaveV3.ts +4 -2
- package/src/claiming/ethena.ts +5 -5
- package/src/claiming/king.ts +3 -3
- package/src/claiming/spark.ts +6 -4
- package/src/curveUsd/index.ts +33 -16
- package/src/fluid/index.ts +44 -3
- package/src/helpers/aaveHelpers/index.ts +27 -7
- package/src/helpers/aaveV4Helpers/index.ts +1 -0
- package/src/helpers/compoundHelpers/index.ts +2 -0
- package/src/helpers/curveUsdHelpers/index.ts +23 -3
- package/src/helpers/fluidHelpers/index.ts +1 -0
- package/src/helpers/liquityV2Helpers/index.ts +1 -0
- package/src/helpers/llamaLendHelpers/index.ts +2 -1
- package/src/helpers/makerHelpers/index.ts +2 -1
- package/src/helpers/morphoBlueHelpers/index.ts +2 -0
- package/src/helpers/morphoMidnightHelpers/index.ts +2 -0
- package/src/helpers/sparkHelpers/index.ts +1 -0
- package/src/liquity/index.ts +19 -5
- package/src/liquityV2/index.ts +48 -22
- package/src/maker/index.ts +77 -30
- package/src/markets/index.ts +2 -1
- package/src/markets/maker/index.ts +10 -0
- package/src/moneymarket/moneymarketCommonService.ts +15 -0
- package/src/portfolio/index.ts +477 -248
- package/src/portfolio/lendingProtocols.ts +281 -0
- package/src/savings/index.ts +45 -5
- package/src/savings/morphoVaults/index.ts +73 -21
- package/src/savings/morphoVaults/options.ts +67 -1
- package/src/spark/index.ts +1 -0
- package/src/staking/staking.ts +28 -0
- package/src/types/aave.ts +90 -0
- package/src/types/aaveV4.ts +50 -0
- package/src/types/compound.ts +2 -0
- package/src/types/curveUsd.ts +7 -0
- package/src/types/fluid.ts +15 -0
- package/src/types/index.ts +2 -1
- package/src/types/liquity.ts +19 -1
- package/src/types/liquityV2.ts +28 -1
- package/src/types/maker.ts +6 -0
- package/src/types/morphoBlue.ts +2 -0
- package/src/types/morphoMidnight.ts +1 -0
- package/src/types/portfolio.ts +153 -7
- package/src/types/savings/index.ts +12 -1
- package/src/types/savings/morphoVaults.ts +11 -1
- package/src/types/spark.ts +2 -0
- package/src/umbrella/index.ts +2 -1
package/cjs/types/portfolio.d.ts
CHANGED
|
@@ -1,20 +1,47 @@
|
|
|
1
|
-
import { AaveV2MarketData, AaveV2PositionData, AaveV3MarketData, AaveV3PositionData, AaveVersions } from './aave';
|
|
1
|
+
import { AaveV2MarketData, AaveV2PositionData, AaveV3MarketData, AaveV3PositionData, AaveVersions, StakeAaveData, UmbrellaStakingData } from './aave';
|
|
2
2
|
import { AaveV4AccountData, AaveV4SpokeData, AaveV4SpokesType } from './aaveV4';
|
|
3
|
+
import { AaveRewardsClaimableToken, EthenaAirdropClaimableToken, KingRewardsClaimableToken, MerklRewardsClaimableToken, SparkAirdropClaimableToken, SparkRewardsClaimableToken, UniswapAirdropClaimableToken } from './claiming';
|
|
3
4
|
import { EthAddress } from './common';
|
|
4
5
|
import { CompoundV2MarketsData, CompoundV2PositionData, CompoundV3MarketsData, CompoundV3PositionData, CompoundVersions } from './compound';
|
|
5
6
|
import { CrvUSDGlobalMarketData, CrvUSDUserData, CrvUSDVersions } from './curveUsd';
|
|
6
|
-
import { FluidVaultData } from './fluid';
|
|
7
|
-
import { LiquityTroveInfo } from './liquity';
|
|
8
|
-
import { LiquityV2MarketData } from './liquityV2';
|
|
7
|
+
import { FluidEarnPositionData, FluidMarketData, FluidVaultData } from './fluid';
|
|
8
|
+
import { LiquityStakingData, LiquityTroveInfo } from './liquity';
|
|
9
|
+
import { LiquityV2MarketData, LiquityV2SBoldYBoldData, LiquityV2StakingData, LiquityV2TroveData, LiquityV2Versions } from './liquityV2';
|
|
9
10
|
import { LlamaLendGlobalMarketData, LlamaLendUserData, LlamaLendVersionsType } from './llamaLend';
|
|
10
|
-
import { CdpData } from './maker';
|
|
11
|
-
import { MorphoBlueMarketInfo, MorphoBluePositionData, MorphoBlueVersions } from './morphoBlue';
|
|
11
|
+
import { CdpData, IlkInfo } from './maker';
|
|
12
|
+
import { MorphoBlueEarnData, MorphoBlueMarketInfo, MorphoBluePositionData, MorphoBlueVersions } from './morphoBlue';
|
|
12
13
|
import { MorphoMidnightMarketInfo, MorphoMidnightPositionData, MorphoMidnightVersions } from './morphoMidnight';
|
|
13
14
|
import { SparkMarketsData, SparkPositionData, SparkVersions } from './spark';
|
|
14
15
|
export interface PortfolioProtocolData<T> {
|
|
15
16
|
error: string;
|
|
16
17
|
data: T | null;
|
|
17
18
|
}
|
|
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 markets. */
|
|
25
|
+
export interface PortfolioDataOptions {
|
|
26
|
+
/** positions (lending); default true. With false it comes back as {} and no lending position is read. */
|
|
27
|
+
positions?: boolean;
|
|
28
|
+
/** stakingPositions; default true. With false it comes back as {} and no staking source is read. */
|
|
29
|
+
staking?: boolean;
|
|
30
|
+
/** rewardsData; default true. With false it comes back as {} and no rewards source is read. */
|
|
31
|
+
rewards?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Liquity V2 troves in positions[address].liquityV2; default false, as the DeFi Saver app reads them on its own.
|
|
34
|
+
* Mainnet only: elsewhere liquityV2 is {}. Needs positions.
|
|
35
|
+
*/
|
|
36
|
+
liquityV2?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** One Liquity V2 market's troves of an address, by trove id — with an error when the ids or any trove failed to load. */
|
|
39
|
+
export interface PortfolioLiquityV2Troves {
|
|
40
|
+
error: string;
|
|
41
|
+
data: {
|
|
42
|
+
[troveId: string]: LiquityV2TroveData;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
18
45
|
export interface PortfolioPositionsDataForAddress {
|
|
19
46
|
aaveV3: {
|
|
20
47
|
[key in AaveVersions]?: PortfolioProtocolData<AaveV3PositionData>;
|
|
@@ -56,10 +83,64 @@ export interface PortfolioPositionsDataForAddress {
|
|
|
56
83
|
aaveV4: {
|
|
57
84
|
[key in AaveV4SpokesType]?: PortfolioProtocolData<AaveV4AccountData>;
|
|
58
85
|
};
|
|
86
|
+
/** Only with the liquityV2 option. Every trove the address holds, by market. */
|
|
87
|
+
liquityV2?: {
|
|
88
|
+
[key in LiquityV2Versions]?: PortfolioLiquityV2Troves;
|
|
89
|
+
};
|
|
59
90
|
}
|
|
60
91
|
export interface PortfolioPositionsData {
|
|
61
92
|
[key: EthAddress]: PortfolioPositionsDataForAddress;
|
|
62
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* The staking positions getPortfolioData returns for an address. The shapes are uneven, and the DeFi Saver app
|
|
96
|
+
* parses them as they are: a protocol read once per address comes back unwrapped on success, as
|
|
97
|
+
* `{ error, data: null }` on failure, and as {} (or Fluid's `{ error: '', data: {} }`) on a network it is not read on.
|
|
98
|
+
*/
|
|
99
|
+
export interface PortfolioStakingPositionsDataForAddress {
|
|
100
|
+
/** stkAAVE, stkGHO and sGHO; mainnet only. */
|
|
101
|
+
aaveV3: StakeAaveData | PortfolioProtocolError | {};
|
|
102
|
+
/** Morpho Blue supply without a borrow (Earn), by market; only markets with a deposit or an error. */
|
|
103
|
+
morphoBlue: {
|
|
104
|
+
[key in MorphoBlueVersions]?: PortfolioProtocolData<MorphoBlueEarnData>;
|
|
105
|
+
};
|
|
106
|
+
compoundV3: Record<string, never>;
|
|
107
|
+
spark: Record<string, never>;
|
|
108
|
+
aaveV2: Record<string, never>;
|
|
109
|
+
compoundV2: Record<string, never>;
|
|
110
|
+
/** LQTY staking and the LUSD stability pool; mainnet only. */
|
|
111
|
+
liquity: LiquityStakingData | PortfolioProtocolError | {};
|
|
112
|
+
/** Stability pool deposits, by market; mainnet only, legacy markets left out. */
|
|
113
|
+
liquityV2: {
|
|
114
|
+
[key in LiquityV2Versions]?: PortfolioProtocolData<LiquityV2StakingData>;
|
|
115
|
+
};
|
|
116
|
+
/** Fluid lending (fToken) deposits; `{ error: '', data: {} }` on a network without Fluid. */
|
|
117
|
+
fluid: FluidEarnPositionData[] | PortfolioProtocolError | {
|
|
118
|
+
error: string;
|
|
119
|
+
data: Record<string, never>;
|
|
120
|
+
};
|
|
121
|
+
/** Umbrella stakes; absent off mainnet. */
|
|
122
|
+
umbrella?: UmbrellaStakingData | PortfolioProtocolError;
|
|
123
|
+
/** sBOLD, yBOLD and stYBOLD; data is null off mainnet. */
|
|
124
|
+
liquityV2SBoldYBold: PortfolioProtocolData<LiquityV2SBoldYBoldData>;
|
|
125
|
+
}
|
|
126
|
+
export type PortfolioStakingPositionsData = Record<EthAddress, PortfolioStakingPositionsDataForAddress>;
|
|
127
|
+
/** The claimable rewards getPortfolioData returns for an address. Off mainnet only Merkl and Aave V3 are read. */
|
|
128
|
+
export interface PortfolioRewardsDataForAddress {
|
|
129
|
+
merkl: PortfolioProtocolData<MerklRewardsClaimableToken[]>;
|
|
130
|
+
aaveV3: {
|
|
131
|
+
[key in AaveVersions]?: PortfolioProtocolData<AaveRewardsClaimableToken[]>;
|
|
132
|
+
};
|
|
133
|
+
spark: {
|
|
134
|
+
[key in SparkVersions]?: PortfolioProtocolData<SparkRewardsClaimableToken[]>;
|
|
135
|
+
};
|
|
136
|
+
/** The SPK airdrop. */
|
|
137
|
+
spk: PortfolioProtocolData<SparkAirdropClaimableToken[]>;
|
|
138
|
+
king: PortfolioProtocolData<KingRewardsClaimableToken[]>;
|
|
139
|
+
/** {} off mainnet. */
|
|
140
|
+
ethena: PortfolioProtocolData<EthenaAirdropClaimableToken[]> | {};
|
|
141
|
+
uniswap: PortfolioProtocolData<UniswapAirdropClaimableToken[]>;
|
|
142
|
+
}
|
|
143
|
+
export type PortfolioRewardsData = Record<EthAddress, PortfolioRewardsDataForAddress>;
|
|
63
144
|
/** The `markets` getPortfolioData returns: every market it read, by protocol, keyed by market or spoke. */
|
|
64
145
|
export interface PortfolioMarketsData {
|
|
65
146
|
morphoMarketsData: Record<string, MorphoBlueMarketInfo>;
|
|
@@ -74,3 +155,43 @@ export interface PortfolioMarketsData {
|
|
|
74
155
|
liquityV2MarketsData: Record<string, LiquityV2MarketData>;
|
|
75
156
|
aaveV4SpokesData: Record<string, AaveV4SpokeData>;
|
|
76
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* The `markets` getShifterPortfolioData returns: the portfolio's markets, plus Fluid's and Maker's, which the shifter
|
|
160
|
+
* offers as destinations. Kept apart from PortfolioMarketsData, which getPortfolioData does not fill these into.
|
|
161
|
+
*/
|
|
162
|
+
export interface ShifterPortfolioMarketsData extends PortfolioMarketsData {
|
|
163
|
+
fluidMarketsData: Record<string, FluidMarketData>;
|
|
164
|
+
makerMarketsData: Record<string, IlkInfo>;
|
|
165
|
+
}
|
|
166
|
+
/** The markets that could not be read, by their key in PortfolioMarketsData, then by market or spoke: the error. */
|
|
167
|
+
export type PortfolioMarketsErrors = {
|
|
168
|
+
[key in keyof PortfolioMarketsData]?: Record<string, string>;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* What the portfolio fetch could not read and has no `{ error, data }` entry of its own to report it in. A key is
|
|
172
|
+
* present only when something under it failed; {} when everything was read.
|
|
173
|
+
*/
|
|
174
|
+
export interface PortfolioErrors {
|
|
175
|
+
/** Markets missing from `markets`; every position on such a market is an entry with an error. */
|
|
176
|
+
markets?: PortfolioMarketsErrors;
|
|
177
|
+
/** Addresses whose Maker vault list could not be read: their `maker` is {}, which would otherwise read as "no vaults". */
|
|
178
|
+
makerCdps?: Record<EthAddress, string>;
|
|
179
|
+
}
|
|
180
|
+
/** getPortfolioMarketsData's result. */
|
|
181
|
+
export interface PortfolioMarketsResult {
|
|
182
|
+
/** Every market read; one that failed is missing and named in `errors`. */
|
|
183
|
+
markets: PortfolioMarketsData;
|
|
184
|
+
errors: PortfolioMarketsErrors;
|
|
185
|
+
}
|
|
186
|
+
/** getPortfolioUserData's result: what is read per address. */
|
|
187
|
+
export interface PortfolioUserData {
|
|
188
|
+
positions: PortfolioPositionsData;
|
|
189
|
+
stakingPositions: PortfolioStakingPositionsData;
|
|
190
|
+
rewardsData: PortfolioRewardsData;
|
|
191
|
+
errors: Pick<PortfolioErrors, 'makerCdps'>;
|
|
192
|
+
}
|
|
193
|
+
/** getPortfolioData's result. */
|
|
194
|
+
export interface PortfolioData extends Omit<PortfolioUserData, 'errors'> {
|
|
195
|
+
markets: PortfolioMarketsData;
|
|
196
|
+
errors: PortfolioErrors;
|
|
197
|
+
}
|
|
@@ -20,4 +20,12 @@ export interface SavingsVaultData {
|
|
|
20
20
|
asset: string;
|
|
21
21
|
optionType: string;
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
/** The key of every savings vault getSavingsData reads. */
|
|
24
|
+
export type SavingsVaultKey = MorphoVaultType | YearnVaultType | MakerDsrType | SkySavingsType | SparkSavingsVaultType | SummerVaultType | YearnV3VaultType;
|
|
25
|
+
export type SavingsData = Partial<Record<SavingsVaultKey, SavingsVaultData>>;
|
|
26
|
+
/** Why each vault that was read for a network came back without data. */
|
|
27
|
+
export type SavingsErrors = Partial<Record<SavingsVaultKey, string>>;
|
|
28
|
+
export interface SavingsDataWithErrors {
|
|
29
|
+
data: SavingsData;
|
|
30
|
+
errors: SavingsErrors;
|
|
31
|
+
}
|
|
@@ -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
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MorphoVaultType = void 0;
|
|
3
|
+
exports.MorphoVaultVersion = exports.MorphoVaultType = void 0;
|
|
4
4
|
var MorphoVaultType;
|
|
5
5
|
(function (MorphoVaultType) {
|
|
6
6
|
MorphoVaultType["MorphoVaultFlagshipEth"] = "morpho_vault_flagship_eth";
|
|
@@ -23,4 +23,12 @@ var MorphoVaultType;
|
|
|
23
23
|
MorphoVaultType["MorphoVaultSmokehouseUSDT"] = "morpho_vault_smokehouse_usdt";
|
|
24
24
|
MorphoVaultType["MorphoVaultSmokehouseUSDC"] = "morpho_vault_smokehouse_usdc";
|
|
25
25
|
MorphoVaultType["MorphoVaultSmokehouseDAI"] = "morpho_vault_smokehouse_dai";
|
|
26
|
+
// Vault V2
|
|
27
|
+
MorphoVaultType["MorphoVaultGauntletUSDGPremium"] = "morpho_vault_gauntlet_usdg_premium";
|
|
28
|
+
MorphoVaultType["MorphoVaultSteakhouseUSDGPro"] = "morpho_vault_steakhouse_usdg_pro";
|
|
26
29
|
})(MorphoVaultType || (exports.MorphoVaultType = MorphoVaultType = {}));
|
|
30
|
+
var MorphoVaultVersion;
|
|
31
|
+
(function (MorphoVaultVersion) {
|
|
32
|
+
MorphoVaultVersion[MorphoVaultVersion["V1"] = 1] = "V1";
|
|
33
|
+
MorphoVaultVersion[MorphoVaultVersion["V2"] = 2] = "V2";
|
|
34
|
+
})(MorphoVaultVersion || (exports.MorphoVaultVersion = MorphoVaultVersion = {}));
|
package/cjs/types/spark.d.ts
CHANGED
|
@@ -100,6 +100,7 @@ export interface SparkAggregatedPositionData {
|
|
|
100
100
|
leftToBorrowUsd: string;
|
|
101
101
|
ratio: string;
|
|
102
102
|
collRatio: string;
|
|
103
|
+
safetyRatio: string;
|
|
103
104
|
netApy: string;
|
|
104
105
|
incentiveUsd: string;
|
|
105
106
|
totalInterestUsd: string;
|
|
@@ -124,6 +125,7 @@ export interface SparkPositionData extends MMPositionData, SparkPositionAggregat
|
|
|
124
125
|
ratio: string;
|
|
125
126
|
minRatio: string;
|
|
126
127
|
collRatio: string;
|
|
128
|
+
safetyRatio?: string;
|
|
127
129
|
suppliedUsd: string;
|
|
128
130
|
borrowedUsd: string;
|
|
129
131
|
borrowLimitUsd: string;
|
package/cjs/umbrella/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
2
|
import { EthAddress, NetworkNumber } from '../types/common';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}>;
|
|
3
|
+
import { UmbrellaStakingData } from '../types/aave';
|
|
4
|
+
export declare const getUmbrellaData: (provider: Client, network: NetworkNumber, address: EthAddress) => Promise<UmbrellaStakingData>;
|
package/esm/aaveV2/index.js
CHANGED
|
@@ -167,6 +167,8 @@ export const _getAaveV2AccountData = (provider, network, address, assetsData, ma
|
|
|
167
167
|
payload.collRatio = payload.borrowedUsd && payload.borrowedUsd !== '0'
|
|
168
168
|
? new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString()
|
|
169
169
|
: '0';
|
|
170
|
+
// Aave v2 has no LTV-0 fallback (AaveV3View only), so its safety ratio is the plain ratio.
|
|
171
|
+
payload.safetyRatio = payload.ratio;
|
|
170
172
|
// Calculate borrow limits per asset
|
|
171
173
|
Object.values(payload.usedAssets).forEach((item) => {
|
|
172
174
|
if (item.isBorrowed) {
|
package/esm/aaveV3/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
|
-
import { AaveMarketInfo, AaveV3MarketData, AaveV3PositionData, AaveV3UsedAssets, EModeCategoryDataMapping } from '../types';
|
|
2
|
+
import { AaveMarketInfo, AaveV3MarketData, AaveV3PositionData, AaveV3UsedAssets, EModeCategoryDataMapping, StakeAaveData } from '../types';
|
|
3
3
|
import { Blockish, EthAddress, EthereumProvider, NetworkNumber, PositionBalances } from '../types/common';
|
|
4
4
|
import { getMeritCampaigns } from './merit';
|
|
5
5
|
import { getMerkleCampaigns } from './merkl';
|
|
@@ -32,22 +32,51 @@ export declare const EMPTY_AAVE_DATA: {
|
|
|
32
32
|
};
|
|
33
33
|
export declare const _getAaveV3AccountBalances: (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress) => Promise<PositionBalances>;
|
|
34
34
|
export declare const getAaveV3AccountBalances: (provider: EthereumProvider, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress) => Promise<PositionBalances>;
|
|
35
|
+
export interface AaveV3ReserveTokenAddresses {
|
|
36
|
+
[symbol: string]: {
|
|
37
|
+
symbol: string;
|
|
38
|
+
underlyingAddress: EthAddress;
|
|
39
|
+
aTokenAddress: EthAddress;
|
|
40
|
+
stableDebtTokenAddress: EthAddress;
|
|
41
|
+
variableDebtTokenAddress: EthAddress;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export interface AaveV3HistoricalBalance {
|
|
45
|
+
block: number;
|
|
46
|
+
suppliedUsd: string;
|
|
47
|
+
borrowedUsd: string;
|
|
48
|
+
netUsd: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Fetches the aToken / stable-debt / variable-debt token addresses for every asset in the market.
|
|
52
|
+
* These are effectively immutable per reserve, so fetch once and reuse across all history points.
|
|
53
|
+
*/
|
|
54
|
+
export declare const _getAaveV3ReserveTokenAddresses: (provider: Client, network: NetworkNumber, market: AaveMarketInfo) => Promise<AaveV3ReserveTokenAddresses>;
|
|
55
|
+
export declare const getAaveV3ReserveTokenAddresses: (provider: EthereumProvider, network: NetworkNumber, market: AaveMarketInfo) => Promise<AaveV3ReserveTokenAddresses>;
|
|
56
|
+
/**
|
|
57
|
+
* Resolves the price oracle the market's addresses provider points at (at `block`, or latest).
|
|
58
|
+
* Aave can rotate the oracle over time, so a caller hoisting one address across many historical
|
|
59
|
+
* points must resolve it at both ends of its block range and only reuse it when the two agree —
|
|
60
|
+
* otherwise leave `oracleAddress` unset on _getAaveV3HistoricalBalance and it resolves per block.
|
|
61
|
+
*/
|
|
62
|
+
export declare const _getAaveV3OracleAddress: (provider: Client, network: NetworkNumber, market: AaveMarketInfo, block?: Blockish) => Promise<EthAddress>;
|
|
63
|
+
export declare const getAaveV3OracleAddress: (provider: EthereumProvider, network: NetworkNumber, market: AaveMarketInfo, block?: Blockish) => Promise<EthAddress>;
|
|
64
|
+
/**
|
|
65
|
+
* Computes a user's Aave v3 net USD balance (supplied collateral - borrowed debt) at a historical block,
|
|
66
|
+
* without touching the AaveV3View contract. Pass `reserveTokens` (from getAaveV3ReserveTokenAddresses)
|
|
67
|
+
* to avoid refetching token addresses for every point, and `oracleAddress` (from getAaveV3OracleAddress,
|
|
68
|
+
* verified identical at both ends of the sampled range) to collapse the point into a single multicall —
|
|
69
|
+
* with it the balances and all prices ride one request; without it the oracle is resolved at the block
|
|
70
|
+
* inside the balance multicall and the active assets are priced in a second one.
|
|
71
|
+
*/
|
|
72
|
+
export declare const _getAaveV3HistoricalBalance: (provider: Client, network: NetworkNumber, market: AaveMarketInfo, address: EthAddress, block: number, reserveTokens?: AaveV3ReserveTokenAddresses, oracleAddress?: EthAddress) => Promise<AaveV3HistoricalBalance>;
|
|
73
|
+
export declare const getAaveV3HistoricalBalance: (provider: EthereumProvider, network: NetworkNumber, market: AaveMarketInfo, address: EthAddress, block: number, reserveTokens?: AaveV3ReserveTokenAddresses, oracleAddress?: EthAddress) => Promise<AaveV3HistoricalBalance>;
|
|
35
74
|
export declare const _getAaveV3AccountData: (provider: Client, network: NetworkNumber, address: EthAddress, extractedState: any, blockNumber?: "latest" | number) => Promise<AaveV3PositionData>;
|
|
36
75
|
export declare const getAaveV3AccountData: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, extractedState: any, blockNumber?: "latest" | number) => Promise<AaveV3PositionData>;
|
|
37
76
|
export declare const getAaveV3FullPositionData: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, market: AaveMarketInfo) => Promise<AaveV3PositionData>;
|
|
38
77
|
export declare const REWARDABLE_ASSETS: readonly ["0x028171bCA77440897B824Ca71D1c56caC55b68A3", "0x6C3c78838c761c6Ac7bE9F59fe808ea2A6E4379d", "0xD37EE7e4f452C6638c96536e68090De8cBcdb583", "0x279AF5b99540c1A3A7E3CDd326e19659401eF99e", "0xBcca60bB61934080951369a648Fb03DF4F96263C", "0x619beb58998eD2278e08620f97007e1116D5D25b", "0x3Ed3B47Dd13EC9a98b44e6204A523E766B225811", "0x531842cEbbdD378f8ee36D171d6cC9C4fcf475Ec", "0x9ff58f4fFB29fA2266Ab25e75e2A8b3503311656", "0x9c39809Dec7F95F5e0713634a4D0701329B3b4d2", "0x030bA81f1c18d280636F32af80b9AAd02Cf0854e", "0xF63B34710400CAd3e044cFfDcAb00a0f32E33eCf", "0xa06bC25B5805d5F8d82847D191Cb4Af5A3e873E0", "0x0b8f12b1788BFdE65Aa1ca52E3e9F3Ba401be16D", "0x6C5024Cd4F8A59110119C56f8933403A539555EB", "0xdC6a3Ab17299D9C2A412B0e0a4C1f55446AE0817", "0x5165d24277cD063F5ac44Efd447B27025e888f37", "0x7EbD09022Be45AD993BAA1CEc61166Fcc8644d97", "0xF256CC7847E919FAc9B808cC216cAc87CCF2f47a", "0xfAFEDF95E21184E3d880bd56D4806c4b8d31c69A", "0xB9D7CB55f463405CDfBe4E90a6D2Df01C2B92BF1", "0x5BdB050A92CADcCfCDcCCBFC17204a1C9cC0Ab73", "0xc713e5E149D5D0715DcD1c156a020976e7E56B88", "0xba728eAd5e496BE00DCF66F650b6d7758eCB50f8", "0x101cc05f4A51C0319f570d5E146a8C625198e636", "0x01C0eb1f8c6F1C1bF74ae028697ce7AA2a8b0E92", "0xc9BC48c72154ef3e5425641a3c747242112a46AF", "0xB5385132EE8321977FfF44b60cDE9fE9AB0B4e6b", "0x272F97b7a56a387aE942350bBC7Df5700f8a4576", "0x13210D4Fe0d5402bd7Ecbc4B5bC5cFcA3b71adB0", "0x2e8f4bdbe3d47d7d7de490437aea9915d930f1a3", "0xfdb93b3b10936cf81fa59a02a7523b6e2149b2b7", "0xA361718326c15715591c299427c62086F69923D9", "0xbA429f7011c9fa04cDd46a2Da24dc0FF0aC6099c", "0xd4937682df3C8aEF4FE912A96A74121C0829E664", "0xfE8F19B17fFeF0fDbfe2671F248903055AFAA8Ca", "0x683923dB55Fead99A79Fa01A27EeC3cB19679cC3", "0xC2e10006AccAb7B45D9184FcF5b7EC7763f5BaAe", "0x8dAE6Cb04688C62d939ed9B68d32Bc62e49970b1", "0x00ad8eBF64F141f1C81e9f8f792d3d1631c6c684", "0x6F634c6135D2EBD550000ac92F494F9CB8183dAe", "0x4dDff5885a67E4EffeC55875a3977D7E60F82ae0"];
|
|
39
78
|
export declare const fetchYearlyMeritApyForStakingGho: () => Promise<string>;
|
|
40
|
-
export declare const getStakeAaveData: (provider: Client, network: NetworkNumber, address: EthAddress) => Promise<
|
|
41
|
-
activatedCooldown: string;
|
|
42
|
-
activatedCooldownAmount: string;
|
|
43
|
-
stkAaveRewardsBalance: string;
|
|
44
|
-
aaveRewardsBalance: string;
|
|
45
|
-
stkAaveBalance: string;
|
|
46
|
-
stkGhoBalance: string;
|
|
47
|
-
ghoMeritApy: string;
|
|
48
|
-
stkAaveApy: string;
|
|
49
|
-
sgho: import("./sgho").SghoData;
|
|
50
|
-
}>;
|
|
79
|
+
export declare const getStakeAaveData: (provider: Client, network: NetworkNumber, address: EthAddress) => Promise<StakeAaveData>;
|
|
51
80
|
export { getMeritCampaigns, getMerkleCampaigns, };
|
|
52
81
|
export { getSghoData } from './sgho';
|
|
53
82
|
export type { SghoData, SghoUserData } from './sgho';
|
package/esm/aaveV3/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { assetAmountInEth, assetAmountInWei, getAssetInfo } from '@defisaver/tokens';
|
|
11
11
|
import Dec from 'decimal.js';
|
|
12
|
-
import { AaveIncentiveDataProviderV3ContractViem, AaveIncentivesControllerViem, AaveV3ViewContractViem, createViemContractFromConfigFunc, StkAAVEViem, } from '../contracts';
|
|
12
|
+
import { AaveIncentiveDataProviderV3ContractViem, AaveIncentivesControllerViem, AaveV3ViewContractViem, createViemContractFromConfigFunc, getConfigContractAbi, StkAAVEViem, } from '../contracts';
|
|
13
13
|
import { aaveAnyGetAggregatedPositionData, aaveV3IsInIsolationMode, aaveV3IsInSiloedMode } from '../helpers/aaveHelpers';
|
|
14
14
|
import { AAVE_V3 } from '../markets/aave';
|
|
15
15
|
import { aprToApy, calculateBorrowingAssetLimit } from '../moneymarket';
|
|
@@ -31,7 +31,10 @@ export const aaveV3EmodeCategoriesMapping = (extractedState, usedAssets) => {
|
|
|
31
31
|
: !usedAssetsValues.filter(u => u.isBorrowed && !e.borrowAssets.includes(u.symbol)).length;
|
|
32
32
|
const afterEnteringCategory = aaveAnyGetAggregatedPositionData(Object.assign(Object.assign({}, extractedState), { usedAssets, eModeCategory: e.id }));
|
|
33
33
|
const willStayOverCollateralized = new Dec(afterEnteringCategory.ratio === 'NaN' ? '0' : afterEnteringCategory.ratio).eq(0) || new Dec(afterEnteringCategory.ratio).gt(afterEnteringCategory.liqPercent);
|
|
34
|
-
const
|
|
34
|
+
const collateralOnlyFromCategory = e.id === 0 || !e.isolated
|
|
35
|
+
? true
|
|
36
|
+
: !usedAssetsValues.filter(u => u.isSupplied && u.collateral && !e.collateralAssets.includes(u.symbol)).length;
|
|
37
|
+
const enteringTerms = [borrowingOnlyFromCategory, willStayOverCollateralized, collateralOnlyFromCategory];
|
|
35
38
|
categoriesMapping[e.id] = {
|
|
36
39
|
enteringTerms,
|
|
37
40
|
canEnterCategory: !enteringTerms.includes(false),
|
|
@@ -48,6 +51,7 @@ export const aaveV3EmodeCategoriesMapping = (extractedState, usedAssets) => {
|
|
|
48
51
|
};
|
|
49
52
|
export function _getAaveV3MarketData(provider_1, network_1, market_1) {
|
|
50
53
|
return __awaiter(this, arguments, void 0, function* (provider, network, market, blockNumber = 'latest') {
|
|
54
|
+
var _a;
|
|
51
55
|
const _addresses = market.assets.map(a => getAssetInfo(getWrappedNativeAssetFromUnwrapped(a), network).address);
|
|
52
56
|
const loanInfoContract = AaveV3ViewContractViem(provider, network);
|
|
53
57
|
const aaveIncentivesContract = AaveIncentiveDataProviderV3ContractViem(provider, network);
|
|
@@ -81,6 +85,7 @@ export function _getAaveV3MarketData(provider_1, network_1, market_1) {
|
|
|
81
85
|
borrowableBitmap: eModesInfo[i].borrowableBitmap.toString(),
|
|
82
86
|
collateralBitmap: eModesInfo[i].collateralBitmap.toString(),
|
|
83
87
|
ltvzeroBitmap: eModesInfo[i].ltvzeroBitmap.toString(),
|
|
88
|
+
isolated: (_a = eModesInfo[i].isolated) !== null && _a !== void 0 ? _a : false,
|
|
84
89
|
borrowAssets: [],
|
|
85
90
|
collateralAssets: [],
|
|
86
91
|
ltvZeroAssets: [],
|
|
@@ -296,6 +301,7 @@ export function _getAaveV3MarketData(provider_1, network_1, market_1) {
|
|
|
296
301
|
collateralAssets: assetsData.map((a) => a.symbol),
|
|
297
302
|
borrowAssets: assetsData.map((a) => a.symbol),
|
|
298
303
|
ltvZeroAssets: [],
|
|
304
|
+
isolated: false,
|
|
299
305
|
};
|
|
300
306
|
return { assetsData: payload, eModeCategoriesData };
|
|
301
307
|
});
|
|
@@ -362,6 +368,229 @@ export const _getAaveV3AccountBalances = (provider, network, block, addressMappi
|
|
|
362
368
|
return balances;
|
|
363
369
|
});
|
|
364
370
|
export const getAaveV3AccountBalances = (provider, network, block, addressMapping, address) => __awaiter(void 0, void 0, void 0, function* () { return _getAaveV3AccountBalances(getViemProvider(provider, network), network, block, addressMapping, address); });
|
|
371
|
+
/**
|
|
372
|
+
* Historical net-balance helpers that bypass the AaveV3View contract.
|
|
373
|
+
*
|
|
374
|
+
* The View contract (and therefore `getAaveV3AccountData` / `getAaveV3AccountBalances`) can only be
|
|
375
|
+
* queried from its deployment block onwards, so it cannot read balances for positions older than that.
|
|
376
|
+
* The aTokens/debt tokens, the ProtocolDataProvider and the Aave price oracle all exist from Aave v3
|
|
377
|
+
* launch, so reading `balanceOf` on those tokens + the oracle price directly reaches much further back
|
|
378
|
+
* and costs ~1 multicall per point. Used to build a position balance-history chart.
|
|
379
|
+
*/
|
|
380
|
+
// matches morphoVaults' batchSize; stays under the 500k portfolio discovery allows on simulation fork RPCs
|
|
381
|
+
const HISTORICAL_MULTICALL_BATCH_SIZE = 250000;
|
|
382
|
+
// Minimal Aave price oracle ABI (getAssetPrice returns the asset price in the market base currency).
|
|
383
|
+
const AAVE_ORACLE_ABI = [
|
|
384
|
+
{
|
|
385
|
+
inputs: [{ internalType: 'address', name: 'asset', type: 'address' }],
|
|
386
|
+
name: 'getAssetPrice',
|
|
387
|
+
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
|
388
|
+
stateMutability: 'view',
|
|
389
|
+
type: 'function',
|
|
390
|
+
},
|
|
391
|
+
];
|
|
392
|
+
/**
|
|
393
|
+
* Fetches the aToken / stable-debt / variable-debt token addresses for every asset in the market.
|
|
394
|
+
* These are effectively immutable per reserve, so fetch once and reuse across all history points.
|
|
395
|
+
*/
|
|
396
|
+
export const _getAaveV3ReserveTokenAddresses = (provider, network, market) => __awaiter(void 0, void 0, void 0, function* () {
|
|
397
|
+
const symbols = market.assets;
|
|
398
|
+
const underlyingAddresses = symbols.map((a) => getAssetInfo(getWrappedNativeAssetFromUnwrapped(a), network).address);
|
|
399
|
+
// @ts-ignore market.protocolData is a valid config key at runtime
|
|
400
|
+
const dataProviderAbi = getConfigContractAbi(market.protocolData, network);
|
|
401
|
+
const contracts = underlyingAddresses.map((underlying) => ({
|
|
402
|
+
address: market.protocolDataAddress,
|
|
403
|
+
abi: dataProviderAbi,
|
|
404
|
+
functionName: 'getReserveTokensAddresses',
|
|
405
|
+
args: [underlying],
|
|
406
|
+
}));
|
|
407
|
+
// @ts-ignore
|
|
408
|
+
const results = yield provider.multicall({ contracts, allowFailure: true, batchSize: HISTORICAL_MULTICALL_BATCH_SIZE });
|
|
409
|
+
const mapping = {};
|
|
410
|
+
results.forEach((res, i) => {
|
|
411
|
+
if (res.status !== 'success' || !res.result)
|
|
412
|
+
return;
|
|
413
|
+
// outputs order: [aTokenAddress, stableDebtTokenAddress, variableDebtTokenAddress]
|
|
414
|
+
const [aTokenAddress, stableDebtTokenAddress, variableDebtTokenAddress] = res.result;
|
|
415
|
+
mapping[symbols[i]] = {
|
|
416
|
+
symbol: symbols[i],
|
|
417
|
+
underlyingAddress: underlyingAddresses[i],
|
|
418
|
+
aTokenAddress,
|
|
419
|
+
stableDebtTokenAddress,
|
|
420
|
+
variableDebtTokenAddress,
|
|
421
|
+
};
|
|
422
|
+
});
|
|
423
|
+
return mapping;
|
|
424
|
+
});
|
|
425
|
+
export const getAaveV3ReserveTokenAddresses = (provider, network, market) => __awaiter(void 0, void 0, void 0, function* () { return _getAaveV3ReserveTokenAddresses(getViemProvider(provider, network, { batch: { multicall: true } }), network, market); });
|
|
426
|
+
/**
|
|
427
|
+
* Resolves the price oracle the market's addresses provider points at (at `block`, or latest).
|
|
428
|
+
* Aave can rotate the oracle over time, so a caller hoisting one address across many historical
|
|
429
|
+
* points must resolve it at both ends of its block range and only reuse it when the two agree —
|
|
430
|
+
* otherwise leave `oracleAddress` unset on _getAaveV3HistoricalBalance and it resolves per block.
|
|
431
|
+
*/
|
|
432
|
+
export const _getAaveV3OracleAddress = (provider_1, network_1, market_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, market_1, ...args_1], void 0, function* (provider, network, market, block = 'latest') {
|
|
433
|
+
// @ts-ignore market.provider is a valid config key at runtime
|
|
434
|
+
const providerAbi = getConfigContractAbi(market.provider, network);
|
|
435
|
+
// @ts-ignore readContract exists on the public client returned by getViemProvider
|
|
436
|
+
const oracleAddress = yield provider.readContract(Object.assign({ address: market.providerAddress, abi: providerAbi, functionName: 'getPriceOracle' }, setViemBlockNumber(block)));
|
|
437
|
+
if (!oracleAddress)
|
|
438
|
+
throw new Error(`AaveV3 oracle unavailable at block ${block}`);
|
|
439
|
+
return oracleAddress;
|
|
440
|
+
});
|
|
441
|
+
export const getAaveV3OracleAddress = (provider_1, network_1, market_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, market_1, ...args_1], void 0, function* (provider, network, market, block = 'latest') { return _getAaveV3OracleAddress(getViemProvider(provider, network, { batch: { multicall: true } }), network, market, block); });
|
|
442
|
+
// supply = aToken.balanceOf, debt = variableDebtToken.balanceOf + stableDebtToken.balanceOf — three reads per reserve
|
|
443
|
+
const getHistoricalBalanceContracts = (entries, address) => {
|
|
444
|
+
const erc20Abi = getConfigContractAbi('Erc20');
|
|
445
|
+
return entries.flatMap((e) => ([
|
|
446
|
+
{
|
|
447
|
+
address: e.aTokenAddress, abi: erc20Abi, functionName: 'balanceOf', args: [address],
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
address: e.variableDebtTokenAddress, abi: erc20Abi, functionName: 'balanceOf', args: [address],
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
address: e.stableDebtTokenAddress, abi: erc20Abi, functionName: 'balanceOf', args: [address],
|
|
454
|
+
},
|
|
455
|
+
]));
|
|
456
|
+
};
|
|
457
|
+
const getAssetPriceContract = (oracle, underlyingAddress) => ({
|
|
458
|
+
address: oracle,
|
|
459
|
+
abi: AAVE_ORACLE_ABI,
|
|
460
|
+
functionName: 'getAssetPrice',
|
|
461
|
+
args: [underlyingAddress],
|
|
462
|
+
});
|
|
463
|
+
/**
|
|
464
|
+
* Pairs each reserve with its three balance reads and keeps the assets the wallet actually held.
|
|
465
|
+
* Throws when every read failed — a totally failed fetch must not masquerade as a real $0 balance,
|
|
466
|
+
* so the caller can distinguish "fetch failed" (gap) from "position was empty" (genuine 0).
|
|
467
|
+
*/
|
|
468
|
+
const toActiveHistoricalAssets = (entries, balanceResults, block) => {
|
|
469
|
+
const anyBalanceRead = balanceResults.some((r) => (r === null || r === void 0 ? void 0 : r.status) === 'success');
|
|
470
|
+
if (!anyBalanceRead)
|
|
471
|
+
throw new Error(`AaveV3 historical balance: all balance reads failed at block ${block}`);
|
|
472
|
+
return entries.map((e, i) => {
|
|
473
|
+
const supplyRes = balanceResults[i * 3];
|
|
474
|
+
const varDebtRes = balanceResults[(i * 3) + 1];
|
|
475
|
+
const stableDebtRes = balanceResults[(i * 3) + 2];
|
|
476
|
+
const supplied = (supplyRes === null || supplyRes === void 0 ? void 0 : supplyRes.status) === 'success' ? supplyRes.result.toString() : '0';
|
|
477
|
+
const varDebt = (varDebtRes === null || varDebtRes === void 0 ? void 0 : varDebtRes.status) === 'success' ? varDebtRes.result.toString() : '0';
|
|
478
|
+
const stableDebt = (stableDebtRes === null || stableDebtRes === void 0 ? void 0 : stableDebtRes.status) === 'success' ? stableDebtRes.result.toString() : '0';
|
|
479
|
+
const debt = new Dec(varDebt).add(stableDebt).toString();
|
|
480
|
+
return Object.assign(Object.assign({}, e), { supplied, debt });
|
|
481
|
+
}).filter((a) => a.supplied !== '0' || a.debt !== '0');
|
|
482
|
+
};
|
|
483
|
+
/**
|
|
484
|
+
* Sums the active assets into the point's USD totals. Throws when every price read failed — the
|
|
485
|
+
* oracle couldn't serve this block (pruned state, or a hoisted oracle that wasn't deployed yet back
|
|
486
|
+
* then), and totalling it up anyway would return a fake near-$0 balance. A single asset's price
|
|
487
|
+
* failure still just skips that asset, matching the live data path.
|
|
488
|
+
*/
|
|
489
|
+
const sumHistoricalUsd = (activeAssets, priceResBySymbol, block) => {
|
|
490
|
+
const anyPriceRead = activeAssets.some((a) => { var _a; return ((_a = priceResBySymbol[a.symbol]) === null || _a === void 0 ? void 0 : _a.status) === 'success'; });
|
|
491
|
+
if (!anyPriceRead)
|
|
492
|
+
throw new Error(`AaveV3 historical balance: all price reads failed at block ${block}`);
|
|
493
|
+
let suppliedUsd = new Dec(0);
|
|
494
|
+
let borrowedUsd = new Dec(0);
|
|
495
|
+
activeAssets.forEach((a) => {
|
|
496
|
+
const priceRes = priceResBySymbol[a.symbol];
|
|
497
|
+
if ((priceRes === null || priceRes === void 0 ? void 0 : priceRes.status) !== 'success')
|
|
498
|
+
return;
|
|
499
|
+
const priceUsd = new Dec(priceRes.result.toString()).div(1e8); // Aave v3 base currency is USD with 8 decimals
|
|
500
|
+
if (a.supplied !== '0')
|
|
501
|
+
suppliedUsd = suppliedUsd.add(new Dec(assetAmountInEth(a.supplied, a.symbol)).mul(priceUsd));
|
|
502
|
+
if (a.debt !== '0')
|
|
503
|
+
borrowedUsd = borrowedUsd.add(new Dec(assetAmountInEth(a.debt, a.symbol)).mul(priceUsd));
|
|
504
|
+
});
|
|
505
|
+
return {
|
|
506
|
+
block,
|
|
507
|
+
suppliedUsd: suppliedUsd.toString(),
|
|
508
|
+
borrowedUsd: borrowedUsd.toString(),
|
|
509
|
+
netUsd: suppliedUsd.minus(borrowedUsd).toString(),
|
|
510
|
+
};
|
|
511
|
+
};
|
|
512
|
+
/**
|
|
513
|
+
* Fast path, ONE multicall: balances plus a price read for every reserve through the caller-hoisted
|
|
514
|
+
* oracle. Prices are read for all reserves because which assets are active isn't known until the
|
|
515
|
+
* balances come back — extra reads inside an already-paid multicall are nearly free.
|
|
516
|
+
*/
|
|
517
|
+
const fetchHistoricalPointWithOracle = (provider, entries, address, block, oracleAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
518
|
+
const balanceContracts = getHistoricalBalanceContracts(entries, address);
|
|
519
|
+
const priceContracts = entries.map((e) => getAssetPriceContract(oracleAddress, e.underlyingAddress));
|
|
520
|
+
// @ts-ignore
|
|
521
|
+
const results = yield provider.multicall({
|
|
522
|
+
contracts: [...balanceContracts, ...priceContracts], allowFailure: true, blockNumber: BigInt(block), batchSize: HISTORICAL_MULTICALL_BATCH_SIZE,
|
|
523
|
+
});
|
|
524
|
+
const activeAssets = toActiveHistoricalAssets(entries, results.slice(0, balanceContracts.length), block);
|
|
525
|
+
const priceResBySymbol = {};
|
|
526
|
+
results.slice(balanceContracts.length).forEach((res, i) => {
|
|
527
|
+
priceResBySymbol[entries[i].symbol] = res;
|
|
528
|
+
});
|
|
529
|
+
return { activeAssets, priceResBySymbol };
|
|
530
|
+
});
|
|
531
|
+
/**
|
|
532
|
+
* Fallback path, TWO multicalls: balances plus getPriceOracle (resolving the oracle that was active
|
|
533
|
+
* AT the block — Aave can rotate it over time), then prices for just the active assets. The oracle
|
|
534
|
+
* read has no fallback: if it fails (bad archive node, rate limit, ...) the failure must surface
|
|
535
|
+
* rather than silently returning $0 — the caller renders a gap instead of a misleading zero.
|
|
536
|
+
*/
|
|
537
|
+
const fetchHistoricalPointResolvingOracle = (provider, network, market, entries, address, block) => __awaiter(void 0, void 0, void 0, function* () {
|
|
538
|
+
const balanceContracts = getHistoricalBalanceContracts(entries, address);
|
|
539
|
+
// @ts-ignore market.provider is a valid config key at runtime
|
|
540
|
+
const providerAbi = getConfigContractAbi(market.provider, network);
|
|
541
|
+
const oracleContract = {
|
|
542
|
+
address: market.providerAddress,
|
|
543
|
+
abi: providerAbi,
|
|
544
|
+
functionName: 'getPriceOracle',
|
|
545
|
+
};
|
|
546
|
+
const blockNumber = BigInt(block);
|
|
547
|
+
// @ts-ignore
|
|
548
|
+
const results = yield provider.multicall({
|
|
549
|
+
contracts: [...balanceContracts, oracleContract], allowFailure: true, blockNumber, batchSize: HISTORICAL_MULTICALL_BATCH_SIZE,
|
|
550
|
+
});
|
|
551
|
+
const oracleRes = results[balanceContracts.length];
|
|
552
|
+
if ((oracleRes === null || oracleRes === void 0 ? void 0 : oracleRes.status) !== 'success' || !oracleRes.result)
|
|
553
|
+
throw new Error(`AaveV3 historical balance: oracle unavailable at block ${block}`);
|
|
554
|
+
const activeAssets = toActiveHistoricalAssets(entries, results.slice(0, balanceContracts.length), block);
|
|
555
|
+
if (!activeAssets.length)
|
|
556
|
+
return { activeAssets, priceResBySymbol: {} };
|
|
557
|
+
const priceContracts = activeAssets.map((a) => getAssetPriceContract(oracleRes.result, a.underlyingAddress));
|
|
558
|
+
// @ts-ignore
|
|
559
|
+
const priceResults = yield provider.multicall({
|
|
560
|
+
contracts: priceContracts, allowFailure: true, blockNumber, batchSize: HISTORICAL_MULTICALL_BATCH_SIZE,
|
|
561
|
+
});
|
|
562
|
+
const priceResBySymbol = {};
|
|
563
|
+
priceResults.forEach((res, i) => {
|
|
564
|
+
priceResBySymbol[activeAssets[i].symbol] = res;
|
|
565
|
+
});
|
|
566
|
+
return { activeAssets, priceResBySymbol };
|
|
567
|
+
});
|
|
568
|
+
/**
|
|
569
|
+
* Computes a user's Aave v3 net USD balance (supplied collateral - borrowed debt) at a historical block,
|
|
570
|
+
* without touching the AaveV3View contract. Pass `reserveTokens` (from getAaveV3ReserveTokenAddresses)
|
|
571
|
+
* to avoid refetching token addresses for every point, and `oracleAddress` (from getAaveV3OracleAddress,
|
|
572
|
+
* verified identical at both ends of the sampled range) to collapse the point into a single multicall —
|
|
573
|
+
* with it the balances and all prices ride one request; without it the oracle is resolved at the block
|
|
574
|
+
* inside the balance multicall and the active assets are priced in a second one.
|
|
575
|
+
*/
|
|
576
|
+
export const _getAaveV3HistoricalBalance = (provider, network, market, address, block, reserveTokens, oracleAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
577
|
+
const empty = {
|
|
578
|
+
block, suppliedUsd: '0', borrowedUsd: '0', netUsd: '0',
|
|
579
|
+
};
|
|
580
|
+
if (!address)
|
|
581
|
+
return empty;
|
|
582
|
+
const tokens = reserveTokens || (yield _getAaveV3ReserveTokenAddresses(provider, network, market));
|
|
583
|
+
const entries = Object.values(tokens);
|
|
584
|
+
if (!entries.length)
|
|
585
|
+
return empty;
|
|
586
|
+
const { activeAssets, priceResBySymbol } = oracleAddress
|
|
587
|
+
? yield fetchHistoricalPointWithOracle(provider, entries, address, block, oracleAddress)
|
|
588
|
+
: yield fetchHistoricalPointResolvingOracle(provider, network, market, entries, address, block);
|
|
589
|
+
if (!activeAssets.length)
|
|
590
|
+
return empty;
|
|
591
|
+
return sumHistoricalUsd(activeAssets, priceResBySymbol, block);
|
|
592
|
+
});
|
|
593
|
+
export const getAaveV3HistoricalBalance = (provider, network, market, address, block, reserveTokens, oracleAddress) => __awaiter(void 0, void 0, void 0, function* () { return _getAaveV3HistoricalBalance(getViemProvider(provider, network, { batch: { multicall: true } }), network, market, address, block, reserveTokens, oracleAddress); });
|
|
365
594
|
export const _getAaveV3AccountData = (provider_1, network_1, address_1, extractedState_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, address_1, extractedState_1, ...args_1], void 0, function* (provider, network, address, extractedState, blockNumber = 'latest') {
|
|
366
595
|
const { selectedMarket: market, assetsData, eModeCategoriesData, } = extractedState;
|
|
367
596
|
let payload = Object.assign(Object.assign({}, EMPTY_AAVE_DATA), { lastUpdated: Date.now() });
|
package/esm/aaveV3/sgho.d.ts
CHANGED
|
@@ -1,18 +1,4 @@
|
|
|
1
1
|
import { EthAddress, NetworkNumber } from '../types/common';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
balance: string;
|
|
5
|
-
maxDeposit: string;
|
|
6
|
-
maxWithdraw: string;
|
|
7
|
-
underlyingBalance: string;
|
|
8
|
-
}
|
|
9
|
-
export interface SghoData {
|
|
10
|
-
totalAssets: string;
|
|
11
|
-
totalSupply: string;
|
|
12
|
-
supplyCap: string;
|
|
13
|
-
/** Target savings rate as an APY percent (e.g. "4.25" for 4.25%). */
|
|
14
|
-
targetRate: string;
|
|
15
|
-
paused: boolean;
|
|
16
|
-
user: SghoUserData;
|
|
17
|
-
}
|
|
2
|
+
import { SghoData } from '../types/aave';
|
|
3
|
+
export type { SghoData, SghoUserData } from '../types/aave';
|
|
18
4
|
export declare const getSghoData: (network: NetworkNumber, address?: EthAddress) => Promise<SghoData>;
|