@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.
- package/cjs/aaveV3/index.d.ts +12 -2
- package/cjs/aaveV3/sgho.d.ts +16 -2
- package/cjs/aaveV4/lend.d.ts +43 -2
- package/cjs/claiming/aaveV3.d.ts +2 -2
- package/cjs/claiming/ethena.d.ts +1 -2
- package/cjs/claiming/king.d.ts +1 -2
- package/cjs/claiming/spark.d.ts +2 -2
- package/cjs/fluid/index.d.ts +49 -5
- package/cjs/liquity/index.d.ts +12 -2
- package/cjs/liquityV2/index.d.ts +23 -8
- package/cjs/liquityV2/index.js +19 -37
- package/cjs/markets/morphoBlue/index.d.ts +2 -0
- package/cjs/markets/morphoBlue/index.js +18 -1
- package/cjs/portfolio/index.d.ts +8 -16
- package/cjs/portfolio/index.js +520 -458
- package/cjs/savings/index.d.ts +2 -8
- package/cjs/savings/index.js +4 -33
- package/cjs/types/aave.d.ts +2 -98
- package/cjs/types/aaveV4.d.ts +0 -44
- package/cjs/types/compound.d.ts +2 -26
- package/cjs/types/curveUsd.d.ts +1 -9
- package/cjs/types/fluid.d.ts +0 -13
- package/cjs/types/index.d.ts +0 -1
- package/cjs/types/index.js +0 -1
- package/cjs/types/liquity.d.ts +0 -12
- package/cjs/types/liquityV2.d.ts +0 -24
- package/cjs/types/llamaLend.d.ts +1 -12
- package/cjs/types/morphoBlue.d.ts +1 -2
- package/cjs/types/morphoBlue.js +1 -0
- package/cjs/types/portfolio.d.ts +5 -125
- package/cjs/types/savings/index.d.ts +1 -9
- package/cjs/types/spark.d.ts +1 -21
- package/cjs/umbrella/index.d.ts +3 -2
- package/esm/aaveV3/index.d.ts +12 -2
- package/esm/aaveV3/sgho.d.ts +16 -2
- package/esm/aaveV4/lend.d.ts +43 -2
- package/esm/claiming/aaveV3.d.ts +2 -2
- package/esm/claiming/aaveV3.js +1 -1
- package/esm/claiming/ethena.d.ts +1 -2
- package/esm/claiming/king.d.ts +1 -2
- package/esm/claiming/spark.d.ts +2 -2
- package/esm/claiming/spark.js +1 -1
- package/esm/fluid/index.d.ts +49 -5
- package/esm/liquity/index.d.ts +12 -2
- package/esm/liquityV2/index.d.ts +23 -8
- package/esm/liquityV2/index.js +18 -35
- package/esm/markets/morphoBlue/index.d.ts +2 -0
- package/esm/markets/morphoBlue/index.js +16 -0
- package/esm/portfolio/index.d.ts +8 -16
- package/esm/portfolio/index.js +522 -458
- package/esm/savings/index.d.ts +2 -8
- package/esm/savings/index.js +3 -31
- package/esm/types/aave.d.ts +2 -98
- package/esm/types/aaveV4.d.ts +0 -44
- package/esm/types/compound.d.ts +2 -26
- package/esm/types/curveUsd.d.ts +1 -9
- package/esm/types/fluid.d.ts +0 -13
- package/esm/types/index.d.ts +0 -1
- package/esm/types/index.js +0 -1
- package/esm/types/liquity.d.ts +0 -12
- package/esm/types/liquityV2.d.ts +0 -24
- package/esm/types/llamaLend.d.ts +1 -12
- package/esm/types/morphoBlue.d.ts +1 -2
- package/esm/types/morphoBlue.js +1 -0
- package/esm/types/portfolio.d.ts +5 -125
- package/esm/types/savings/index.d.ts +1 -9
- package/esm/types/spark.d.ts +1 -21
- package/esm/umbrella/index.d.ts +3 -2
- package/package.json +2 -2
- package/src/aaveV3/index.ts +1 -2
- package/src/aaveV3/sgho.ts +17 -2
- package/src/aaveV4/lend.ts +48 -2
- package/src/claiming/aaveV3.ts +2 -4
- package/src/claiming/ethena.ts +5 -5
- package/src/claiming/king.ts +3 -3
- package/src/claiming/spark.ts +4 -6
- package/src/fluid/index.ts +3 -4
- package/src/liquity/index.ts +2 -2
- package/src/liquityV2/index.ts +22 -48
- package/src/markets/morphoBlue/index.ts +16 -0
- package/src/portfolio/index.ts +331 -306
- package/src/savings/index.ts +4 -41
- package/src/types/aave.ts +1 -104
- package/src/types/aaveV4.ts +0 -49
- package/src/types/compound.ts +2 -38
- package/src/types/curveUsd.ts +1 -17
- package/src/types/fluid.ts +0 -14
- package/src/types/index.ts +0 -1
- package/src/types/liquity.ts +1 -13
- package/src/types/liquityV2.ts +1 -26
- package/src/types/llamaLend.ts +1 -19
- package/src/types/morphoBlue.ts +1 -3
- package/src/types/portfolio.ts +5 -151
- package/src/types/savings/index.ts +1 -12
- package/src/types/spark.ts +1 -25
- package/src/umbrella/index.ts +1 -2
- package/cjs/portfolio/lendingProtocols.d.ts +0 -184
- package/cjs/portfolio/lendingProtocols.js +0 -196
- package/esm/portfolio/lendingProtocols.d.ts +0 -184
- package/esm/portfolio/lendingProtocols.js +0 -189
- package/src/portfolio/lendingProtocols.ts +0 -281
|
@@ -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,189 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import Dec from 'decimal.js';
|
|
11
|
-
import { NetworkNumber } from '../types/common';
|
|
12
|
-
import { AaveMarkets, AaveV4Spokes, CompoundMarkets, CrvUsdMarkets, LlamaLendMarkets, MorphoBlueMarkets, MorphoMidnightMarkets, SparkMarkets, } from '../markets';
|
|
13
|
-
import { AaveVersions, CompoundVersions, } from '../types';
|
|
14
|
-
import { _getAaveV3AccountData, _getAaveV3MarketData } from '../aaveV3';
|
|
15
|
-
import { _getAaveV4AccountData, _getAaveV4SpokeData } from '../aaveV4';
|
|
16
|
-
import { _getAaveV2AccountData, _getAaveV2MarketsData } from '../aaveV2';
|
|
17
|
-
import { _getCompoundV2AccountData, _getCompoundV2MarketsData } from '../compoundV2';
|
|
18
|
-
import { _getCompoundV3AccountData, _getCompoundV3MarketsData } from '../compoundV3';
|
|
19
|
-
import { _getCurveUsdGlobalData, _getCurveUsdUserData } from '../curveUsd';
|
|
20
|
-
import { _getLlamaLendGlobalData, _getLlamaLendUserData } from '../llamaLend';
|
|
21
|
-
import { _getMorphoBlueAccountData, _getMorphoBluePortfolioMarketData } from '../morphoBlue';
|
|
22
|
-
import { _getMorphoMidnightAccountData, _getMorphoMidnightMarketData } from '../morphoMidnight';
|
|
23
|
-
import { _getSparkAccountData, _getSparkMarketsData } from '../spark';
|
|
24
|
-
import { ZERO_ADDRESS } from '../constants';
|
|
25
|
-
/**
|
|
26
|
-
* A market's data, or a throw that the caller's catch turns into the position's error entry: read against a missing
|
|
27
|
-
* market, a position would otherwise come back empty and read as "no position".
|
|
28
|
-
*/
|
|
29
|
-
export const requireMarket = (marketsData, market) => {
|
|
30
|
-
const marketData = marketsData[market];
|
|
31
|
-
if (!marketData)
|
|
32
|
-
throw new Error(`Market data for ${market} is not available`);
|
|
33
|
-
return marketData;
|
|
34
|
-
};
|
|
35
|
-
/** requireMarket for one protocol's key, typed by that key's market data. */
|
|
36
|
-
const requireMarketOf = (marketsData, key, market) => {
|
|
37
|
-
// TypeScript reads marketsData[key][market] as any protocol's market data; the key's own is what is stored there.
|
|
38
|
-
const marketData = marketsData[key][market];
|
|
39
|
-
if (!marketData)
|
|
40
|
-
throw new Error(`Market data for ${market} is not available`);
|
|
41
|
-
return marketData;
|
|
42
|
-
};
|
|
43
|
-
/** A protocol's entry with its reads, typed by its own market and position types. */
|
|
44
|
-
const lendingProtocol = (key, protocol) => {
|
|
45
|
-
/** Every market of the protocol into `markets`; resolves to the ones that failed (left out), with their errors. */
|
|
46
|
-
const readMarkets = (context, markets) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
-
const protocolMarkets = markets[protocol.marketsKey];
|
|
48
|
-
const failed = {};
|
|
49
|
-
yield Promise.all(protocol.markets(context.network).map((market) => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
-
try {
|
|
51
|
-
protocolMarkets[market.value] = yield protocol.readMarket(context, market);
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
console.error(`Error fetching ${protocol.marketsKey} for market ${market.value}:`, error);
|
|
55
|
-
failed[market.value] = `Error fetching ${protocol.marketsKey} for market ${market.value}`;
|
|
56
|
-
}
|
|
57
|
-
})));
|
|
58
|
-
return failed;
|
|
59
|
-
});
|
|
60
|
-
/**
|
|
61
|
-
* Every address's position on every market into `positions`, each read once its market is in: an entry with the data
|
|
62
|
-
* where the address holds a position, an entry with an error where the read or its market failed, none otherwise.
|
|
63
|
-
*/
|
|
64
|
-
const readPositions = (context, addresses, marketsData, positions) => protocol.markets(context.network).flatMap((market) => addresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
-
// Keyed by the protocol's market type in PortfolioPositionsDataForAddress; written here by market.value.
|
|
66
|
-
const byMarket = positions[address.toLowerCase()][key];
|
|
67
|
-
try {
|
|
68
|
-
const marketData = requireMarketOf(yield marketsData, protocol.marketsKey, market.value);
|
|
69
|
-
const position = yield protocol.readPosition(context, address, market, marketData);
|
|
70
|
-
if (position && protocol.holds(position))
|
|
71
|
-
byMarket[market.value] = { error: '', data: position };
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
console.error(`Error fetching ${protocol.label} account data for address ${address} on market ${market.value}:`, error);
|
|
75
|
-
byMarket[market.value] = { error: `Error fetching ${protocol.label} account data for address ${address} on market ${market.value}`, data: null };
|
|
76
|
-
}
|
|
77
|
-
})));
|
|
78
|
-
return {
|
|
79
|
-
key, marketsKey: protocol.marketsKey, markets: protocol.markets, readMarkets, readPositions,
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
const onNetwork = (network, markets) => markets.filter((market) => market.chainIds.includes(network));
|
|
83
|
-
const suppliesAnything = (position) => new Dec(position.suppliedUsd).gt(0);
|
|
84
|
-
const suppliesOrBorrowsAnything = (position) => new Dec(position.suppliedUsd).gt(0) || new Dec(position.borrowedUsd).gt(0);
|
|
85
|
-
export const aaveV3Lending = lendingProtocol('aaveV3', {
|
|
86
|
-
marketsKey: 'aaveV3MarketsData',
|
|
87
|
-
label: 'AaveV3',
|
|
88
|
-
markets: (network) => onNetwork(network, [AaveVersions.AaveV3, AaveVersions.AaveV3Lido, AaveVersions.AaveV3Etherfi].map((version) => AaveMarkets(network)[version])),
|
|
89
|
-
readMarket: ({ client, network }, market) => _getAaveV3MarketData(client, network, market),
|
|
90
|
-
readPosition: ({ client, network }, address, market, marketData) => _getAaveV3AccountData(client, network, address, Object.assign({ selectedMarket: market }, marketData)),
|
|
91
|
-
holds: suppliesAnything,
|
|
92
|
-
});
|
|
93
|
-
export const aaveV4Lending = lendingProtocol('aaveV4', {
|
|
94
|
-
marketsKey: 'aaveV4SpokesData',
|
|
95
|
-
label: 'AaveV4',
|
|
96
|
-
markets: (network) => onNetwork(network, Object.values(AaveV4Spokes(network))),
|
|
97
|
-
readMarket: ({ client, network }, spoke) => _getAaveV4SpokeData(client, network, spoke),
|
|
98
|
-
readPosition: ({ client, network }, address, _spoke, spokeData) => _getAaveV4AccountData(client, network, spokeData, address),
|
|
99
|
-
holds: suppliesAnything,
|
|
100
|
-
});
|
|
101
|
-
export const morphoBlueLending = lendingProtocol('morphoBlue', {
|
|
102
|
-
marketsKey: 'morphoMarketsData',
|
|
103
|
-
label: 'MorphoBlue',
|
|
104
|
-
markets: (network) => onNetwork(network, Object.values(MorphoBlueMarkets(network))),
|
|
105
|
-
readMarket: ({ client, network }, market) => _getMorphoBluePortfolioMarketData(client, network, market),
|
|
106
|
-
readPosition: ({ client, network }, address, market, marketData) => _getMorphoBlueAccountData(client, network, address, market, marketData),
|
|
107
|
-
holds: suppliesAnything,
|
|
108
|
-
});
|
|
109
|
-
export const morphoMidnightLending = lendingProtocol('morphoMidnight', {
|
|
110
|
-
marketsKey: 'morphoMidnightMarketsData',
|
|
111
|
-
label: 'MorphoMidnight',
|
|
112
|
-
markets: (network) => onNetwork(network, Object.values(MorphoMidnightMarkets(network))),
|
|
113
|
-
readMarket: ({ client, network }, market) => _getMorphoMidnightMarketData(client, network, market),
|
|
114
|
-
// Markets are created lazily on the first position, so an uncreated one can hold no position.
|
|
115
|
-
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) {
|
|
116
|
-
return (marketData.isCreated
|
|
117
|
-
? _getMorphoMidnightAccountData(client, network, address, market, marketData)
|
|
118
|
-
: undefined);
|
|
119
|
-
}),
|
|
120
|
-
holds: suppliesAnything,
|
|
121
|
-
});
|
|
122
|
-
export const compoundV3Lending = lendingProtocol('compoundV3', {
|
|
123
|
-
marketsKey: 'compoundV3MarketsData',
|
|
124
|
-
label: 'CompoundV3',
|
|
125
|
-
markets: (network) => onNetwork(network, Object.values(CompoundMarkets(network)).filter((market) => market.value !== CompoundVersions.CompoundV2)),
|
|
126
|
-
readMarket: ({ client, defaultClient, network }, market) => _getCompoundV3MarketsData(client, network, market, defaultClient),
|
|
127
|
-
readPosition: ({ client, network }, address, market, marketData) => _getCompoundV3AccountData(client, network, address, ZERO_ADDRESS, { selectedMarket: market, assetsData: marketData.assetsData }),
|
|
128
|
-
holds: suppliesAnything,
|
|
129
|
-
});
|
|
130
|
-
export const sparkLending = lendingProtocol('spark', {
|
|
131
|
-
marketsKey: 'sparkMarketsData',
|
|
132
|
-
label: 'Spark',
|
|
133
|
-
markets: (network) => onNetwork(network, Object.values(SparkMarkets(network))),
|
|
134
|
-
readMarket: ({ client, network }, market) => _getSparkMarketsData(client, network, market),
|
|
135
|
-
readPosition: ({ client, network }, address, market, marketData) => _getSparkAccountData(client, network, address, {
|
|
136
|
-
selectedMarket: market, assetsData: marketData.assetsData, eModeCategoriesData: marketData.eModeCategoriesData,
|
|
137
|
-
}),
|
|
138
|
-
holds: suppliesAnything,
|
|
139
|
-
});
|
|
140
|
-
export const aaveV2Lending = lendingProtocol('aaveV2', {
|
|
141
|
-
marketsKey: 'aaveV2MarketsData',
|
|
142
|
-
label: 'AaveV2',
|
|
143
|
-
markets: (network) => onNetwork(network, [AaveMarkets(network)[AaveVersions.AaveV2]]),
|
|
144
|
-
readMarket: ({ client, network }, market) => _getAaveV2MarketsData(client, network, market),
|
|
145
|
-
readPosition: ({ client, network }, address, market, marketData) => _getAaveV2AccountData(client, network, address, marketData.assetsData, market),
|
|
146
|
-
holds: suppliesAnything,
|
|
147
|
-
});
|
|
148
|
-
export const compoundV2Lending = lendingProtocol('compoundV2', {
|
|
149
|
-
marketsKey: 'compoundV2MarketsData',
|
|
150
|
-
label: 'CompoundV2',
|
|
151
|
-
markets: (network) => onNetwork(network, [CompoundMarkets(network)[CompoundVersions.CompoundV2]]),
|
|
152
|
-
readMarket: ({ client, network }) => _getCompoundV2MarketsData(client, network),
|
|
153
|
-
readPosition: ({ client, network }, address, _market, marketData) => _getCompoundV2AccountData(client, network, address, marketData.assetsData),
|
|
154
|
-
holds: suppliesAnything,
|
|
155
|
-
});
|
|
156
|
-
export const crvUsdLending = lendingProtocol('crvUsd', {
|
|
157
|
-
marketsKey: 'crvUsdMarketsData',
|
|
158
|
-
label: 'Curve USD',
|
|
159
|
-
markets: (network) => onNetwork(network, Object.values(CrvUsdMarkets(network))),
|
|
160
|
-
readMarket: ({ client, network }, market) => _getCurveUsdGlobalData(client, network, market),
|
|
161
|
-
// The market's borrow rate is passed in, so the read does not fetch it again.
|
|
162
|
-
readPosition: ({ client, network }, address, market, marketData) => _getCurveUsdUserData(client, network, address, market, marketData.activeBand, marketData.borrowRate),
|
|
163
|
-
holds: suppliesOrBorrowsAnything,
|
|
164
|
-
});
|
|
165
|
-
export const llamaLendLending = lendingProtocol('llamaLend', {
|
|
166
|
-
marketsKey: 'llamaLendMarketsData',
|
|
167
|
-
label: 'LlamaLend',
|
|
168
|
-
markets: (network) => ([NetworkNumber.Eth, NetworkNumber.Arb].includes(network) ? onNetwork(network, Object.values(LlamaLendMarkets(network))) : []),
|
|
169
|
-
readMarket: ({ client, network }, market) => _getLlamaLendGlobalData(client, network, market),
|
|
170
|
-
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) {
|
|
171
|
-
return (Object.assign(Object.assign({}, yield _getLlamaLendUserData(client, network, address, market, marketData)), { borrowRate: marketData.borrowRate }));
|
|
172
|
-
}),
|
|
173
|
-
holds: suppliesOrBorrowsAnything,
|
|
174
|
-
});
|
|
175
|
-
/** Every lending protocol read through its entry, in the order positions list them. */
|
|
176
|
-
export const LENDING_PROTOCOLS = [
|
|
177
|
-
aaveV3Lending,
|
|
178
|
-
aaveV4Lending,
|
|
179
|
-
morphoBlueLending,
|
|
180
|
-
morphoMidnightLending,
|
|
181
|
-
compoundV3Lending,
|
|
182
|
-
sparkLending,
|
|
183
|
-
aaveV2Lending,
|
|
184
|
-
compoundV2Lending,
|
|
185
|
-
crvUsdLending,
|
|
186
|
-
llamaLendLending,
|
|
187
|
-
];
|
|
188
|
-
export const EVERY_POSITION_KEY_IS_READ = true;
|
|
189
|
-
export const EVERY_MARKETS_KEY_IS_READ = true;
|
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
import Dec from 'decimal.js';
|
|
2
|
-
import { Client } from 'viem';
|
|
3
|
-
import { EthAddress, NetworkNumber } from '../types/common';
|
|
4
|
-
import {
|
|
5
|
-
AaveMarkets,
|
|
6
|
-
AaveV4Spokes,
|
|
7
|
-
CompoundMarkets,
|
|
8
|
-
CrvUsdMarkets,
|
|
9
|
-
LlamaLendMarkets,
|
|
10
|
-
MorphoBlueMarkets,
|
|
11
|
-
MorphoMidnightMarkets,
|
|
12
|
-
SparkMarkets,
|
|
13
|
-
} from '../markets';
|
|
14
|
-
import {
|
|
15
|
-
AaveMarketInfo,
|
|
16
|
-
AaveV4SpokeInfo,
|
|
17
|
-
AaveVersions,
|
|
18
|
-
CompoundMarketData,
|
|
19
|
-
CompoundVersions,
|
|
20
|
-
CrvUSDMarketData,
|
|
21
|
-
LlamaLendMarketData,
|
|
22
|
-
MorphoBlueMarketData,
|
|
23
|
-
MorphoMidnightMarketData,
|
|
24
|
-
PortfolioMarketsData,
|
|
25
|
-
PortfolioPositionsData,
|
|
26
|
-
PortfolioPositionsDataForAddress,
|
|
27
|
-
PortfolioProtocolData,
|
|
28
|
-
SparkMarketData,
|
|
29
|
-
} from '../types';
|
|
30
|
-
import { _getAaveV3AccountData, _getAaveV3MarketData } from '../aaveV3';
|
|
31
|
-
import { _getAaveV4AccountData, _getAaveV4SpokeData } from '../aaveV4';
|
|
32
|
-
import { _getAaveV2AccountData, _getAaveV2MarketsData } from '../aaveV2';
|
|
33
|
-
import { _getCompoundV2AccountData, _getCompoundV2MarketsData } from '../compoundV2';
|
|
34
|
-
import { _getCompoundV3AccountData, _getCompoundV3MarketsData } from '../compoundV3';
|
|
35
|
-
import { _getCurveUsdGlobalData, _getCurveUsdUserData } from '../curveUsd';
|
|
36
|
-
import { _getLlamaLendGlobalData, _getLlamaLendUserData } from '../llamaLend';
|
|
37
|
-
import { _getMorphoBlueAccountData, _getMorphoBluePortfolioMarketData } from '../morphoBlue';
|
|
38
|
-
import { _getMorphoMidnightAccountData, _getMorphoMidnightMarketData } from '../morphoMidnight';
|
|
39
|
-
import { _getSparkAccountData, _getSparkMarketsData } from '../spark';
|
|
40
|
-
import { ZERO_ADDRESS } from '../constants';
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* The lending protocols the portfolio reads the same way — a market's data, then each address's position on it — one
|
|
44
|
-
* entry each. Adding such a protocol is its types (its key in PortfolioPositionsDataForAddress and in
|
|
45
|
-
* PortfolioMarketsData) and its entry in LENDING_PROTOCOLS; the portfolio reads, errors and options follow. Maker,
|
|
46
|
-
* Liquity, Fluid and Liquity V2 have shapes of their own and are read by their own code in ./index.ts.
|
|
47
|
-
*/
|
|
48
|
-
|
|
49
|
-
/** What a position read gets. */
|
|
50
|
-
export interface PortfolioReadContext {
|
|
51
|
-
client: Client;
|
|
52
|
-
network: NetworkNumber;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** What a market read gets: also the default client, on Ethereum (Compound V3 reads its prices there). */
|
|
56
|
-
export interface PortfolioMarketsReadContext extends PortfolioReadContext {
|
|
57
|
-
defaultClient: Client;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
type PositionKey = keyof PortfolioPositionsDataForAddress;
|
|
61
|
-
type MarketsKey = keyof PortfolioMarketsData;
|
|
62
|
-
type PositionsOf<K extends PositionKey> = NonNullable<PortfolioPositionsDataForAddress[K]>;
|
|
63
|
-
|
|
64
|
-
/** The data of one of a protocol's positions: what positions[address][K][market] holds as `{ error, data }`. */
|
|
65
|
-
export type LendingPositionData<K extends PositionKey> =
|
|
66
|
-
NonNullable<PositionsOf<K>[keyof PositionsOf<K>]> extends PortfolioProtocolData<infer D> ? D : never;
|
|
67
|
-
|
|
68
|
-
export interface LendingProtocol<K extends PositionKey, M extends MarketsKey, Market extends { value: string }> {
|
|
69
|
-
/** Its key in PortfolioMarketsData. */
|
|
70
|
-
marketsKey: M;
|
|
71
|
-
/** Its name in error messages. */
|
|
72
|
-
label: string;
|
|
73
|
-
/** Its markets on a network; none where it is not deployed. */
|
|
74
|
-
markets: (network: NetworkNumber) => Market[];
|
|
75
|
-
readMarket: (context: PortfolioMarketsReadContext, market: Market) => Promise<PortfolioMarketsData[M][string]>;
|
|
76
|
-
/** An address's position on a market; undefined when the market can hold none. */
|
|
77
|
-
readPosition: (
|
|
78
|
-
context: PortfolioReadContext,
|
|
79
|
-
address: EthAddress,
|
|
80
|
-
market: Market,
|
|
81
|
-
marketData: PortfolioMarketsData[M][string],
|
|
82
|
-
) => Promise<LendingPositionData<K> | undefined>;
|
|
83
|
-
/** Whether there is a position to list: an address without one gets no entry for that market. */
|
|
84
|
-
holds: (position: LendingPositionData<K>) => boolean;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* A market's data, or a throw that the caller's catch turns into the position's error entry: read against a missing
|
|
89
|
-
* market, a position would otherwise come back empty and read as "no position".
|
|
90
|
-
*/
|
|
91
|
-
export const requireMarket = <T>(marketsData: Record<string, T>, market: string): T => {
|
|
92
|
-
const marketData = marketsData[market];
|
|
93
|
-
if (!marketData) throw new Error(`Market data for ${market} is not available`);
|
|
94
|
-
return marketData;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
/** requireMarket for one protocol's key, typed by that key's market data. */
|
|
98
|
-
const requireMarketOf = <M extends MarketsKey>(marketsData: PortfolioMarketsData, key: M, market: string): PortfolioMarketsData[M][string] => {
|
|
99
|
-
// TypeScript reads marketsData[key][market] as any protocol's market data; the key's own is what is stored there.
|
|
100
|
-
const marketData = (marketsData[key] as Record<string, PortfolioMarketsData[M][string] | undefined>)[market];
|
|
101
|
-
if (!marketData) throw new Error(`Market data for ${market} is not available`);
|
|
102
|
-
return marketData;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
/** A protocol's entry with its reads, typed by its own market and position types. */
|
|
106
|
-
const lendingProtocol = <K extends PositionKey, M extends MarketsKey, Market extends { value: string }>(
|
|
107
|
-
key: K,
|
|
108
|
-
protocol: LendingProtocol<K, M, Market>,
|
|
109
|
-
) => {
|
|
110
|
-
/** Every market of the protocol into `markets`; resolves to the ones that failed (left out), with their errors. */
|
|
111
|
-
const readMarkets = async (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData): Promise<Record<string, string>> => {
|
|
112
|
-
const protocolMarkets = markets[protocol.marketsKey];
|
|
113
|
-
const failed: Record<string, string> = {};
|
|
114
|
-
await Promise.all(protocol.markets(context.network).map(async (market) => {
|
|
115
|
-
try {
|
|
116
|
-
protocolMarkets[market.value] = await protocol.readMarket(context, market);
|
|
117
|
-
} catch (error) {
|
|
118
|
-
console.error(`Error fetching ${protocol.marketsKey} for market ${market.value}:`, error);
|
|
119
|
-
failed[market.value] = `Error fetching ${protocol.marketsKey} for market ${market.value}`;
|
|
120
|
-
}
|
|
121
|
-
}));
|
|
122
|
-
return failed;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Every address's position on every market into `positions`, each read once its market is in: an entry with the data
|
|
127
|
-
* where the address holds a position, an entry with an error where the read or its market failed, none otherwise.
|
|
128
|
-
*/
|
|
129
|
-
const readPositions = (
|
|
130
|
-
context: PortfolioReadContext,
|
|
131
|
-
addresses: EthAddress[],
|
|
132
|
-
marketsData: Promise<PortfolioMarketsData>,
|
|
133
|
-
positions: PortfolioPositionsData,
|
|
134
|
-
): Promise<void>[] => protocol.markets(context.network).flatMap((market) => addresses.map(async (address) => {
|
|
135
|
-
// Keyed by the protocol's market type in PortfolioPositionsDataForAddress; written here by market.value.
|
|
136
|
-
const byMarket = positions[address.toLowerCase() as EthAddress][key] as Record<string, PortfolioProtocolData<LendingPositionData<K>>>;
|
|
137
|
-
try {
|
|
138
|
-
const marketData = requireMarketOf(await marketsData, protocol.marketsKey, market.value);
|
|
139
|
-
const position = await protocol.readPosition(context, address, market, marketData);
|
|
140
|
-
if (position && protocol.holds(position)) byMarket[market.value] = { error: '', data: position };
|
|
141
|
-
} catch (error) {
|
|
142
|
-
console.error(`Error fetching ${protocol.label} account data for address ${address} on market ${market.value}:`, error);
|
|
143
|
-
byMarket[market.value] = { error: `Error fetching ${protocol.label} account data for address ${address} on market ${market.value}`, data: null };
|
|
144
|
-
}
|
|
145
|
-
}));
|
|
146
|
-
|
|
147
|
-
return {
|
|
148
|
-
key, marketsKey: protocol.marketsKey, markets: protocol.markets, readMarkets, readPositions,
|
|
149
|
-
};
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
const onNetwork = <Market extends { chainIds: NetworkNumber[] }>(network: NetworkNumber, markets: Market[]) => markets.filter((market) => market.chainIds.includes(network));
|
|
153
|
-
|
|
154
|
-
const suppliesAnything = (position: { suppliedUsd: string }) => new Dec(position.suppliedUsd).gt(0);
|
|
155
|
-
const suppliesOrBorrowsAnything = (position: { suppliedUsd: string, borrowedUsd: string }) => new Dec(position.suppliedUsd).gt(0) || new Dec(position.borrowedUsd).gt(0);
|
|
156
|
-
|
|
157
|
-
export const aaveV3Lending = lendingProtocol('aaveV3', {
|
|
158
|
-
marketsKey: 'aaveV3MarketsData',
|
|
159
|
-
label: 'AaveV3',
|
|
160
|
-
markets: (network): AaveMarketInfo[] => onNetwork(network, [AaveVersions.AaveV3, AaveVersions.AaveV3Lido, AaveVersions.AaveV3Etherfi].map((version) => AaveMarkets(network)[version])),
|
|
161
|
-
readMarket: ({ client, network }, market) => _getAaveV3MarketData(client, network, market),
|
|
162
|
-
readPosition: ({ client, network }, address, market, marketData) => _getAaveV3AccountData(client, network, address, { selectedMarket: market, ...marketData }),
|
|
163
|
-
holds: suppliesAnything,
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
export const aaveV4Lending = lendingProtocol('aaveV4', {
|
|
167
|
-
marketsKey: 'aaveV4SpokesData',
|
|
168
|
-
label: 'AaveV4',
|
|
169
|
-
markets: (network): AaveV4SpokeInfo[] => onNetwork(network, Object.values(AaveV4Spokes(network))),
|
|
170
|
-
readMarket: ({ client, network }, spoke) => _getAaveV4SpokeData(client, network, spoke),
|
|
171
|
-
readPosition: ({ client, network }, address, _spoke, spokeData) => _getAaveV4AccountData(client, network, spokeData, address),
|
|
172
|
-
holds: suppliesAnything,
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
export const morphoBlueLending = lendingProtocol('morphoBlue', {
|
|
176
|
-
marketsKey: 'morphoMarketsData',
|
|
177
|
-
label: 'MorphoBlue',
|
|
178
|
-
markets: (network): MorphoBlueMarketData[] => onNetwork(network, Object.values(MorphoBlueMarkets(network))),
|
|
179
|
-
readMarket: ({ client, network }, market) => _getMorphoBluePortfolioMarketData(client, network, market),
|
|
180
|
-
readPosition: ({ client, network }, address, market, marketData) => _getMorphoBlueAccountData(client, network, address, market, marketData),
|
|
181
|
-
holds: suppliesAnything,
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
export const morphoMidnightLending = lendingProtocol('morphoMidnight', {
|
|
185
|
-
marketsKey: 'morphoMidnightMarketsData',
|
|
186
|
-
label: 'MorphoMidnight',
|
|
187
|
-
markets: (network): MorphoMidnightMarketData[] => onNetwork(network, Object.values(MorphoMidnightMarkets(network))),
|
|
188
|
-
readMarket: ({ client, network }, market) => _getMorphoMidnightMarketData(client, network, market),
|
|
189
|
-
// Markets are created lazily on the first position, so an uncreated one can hold no position.
|
|
190
|
-
readPosition: async ({ client, network }, address, market, marketData) => (marketData.isCreated
|
|
191
|
-
? _getMorphoMidnightAccountData(client, network, address, market, marketData)
|
|
192
|
-
: undefined),
|
|
193
|
-
holds: suppliesAnything,
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
export const compoundV3Lending = lendingProtocol('compoundV3', {
|
|
197
|
-
marketsKey: 'compoundV3MarketsData',
|
|
198
|
-
label: 'CompoundV3',
|
|
199
|
-
markets: (network): CompoundMarketData[] => onNetwork(network, Object.values(CompoundMarkets(network)).filter((market) => market.value !== CompoundVersions.CompoundV2)),
|
|
200
|
-
readMarket: ({ client, defaultClient, network }, market) => _getCompoundV3MarketsData(client, network, market, defaultClient),
|
|
201
|
-
readPosition: ({ client, network }, address, market, marketData) => _getCompoundV3AccountData(client, network, address, ZERO_ADDRESS, { selectedMarket: market, assetsData: marketData.assetsData }),
|
|
202
|
-
holds: suppliesAnything,
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
export const sparkLending = lendingProtocol('spark', {
|
|
206
|
-
marketsKey: 'sparkMarketsData',
|
|
207
|
-
label: 'Spark',
|
|
208
|
-
markets: (network): SparkMarketData[] => onNetwork(network, Object.values(SparkMarkets(network))),
|
|
209
|
-
readMarket: ({ client, network }, market) => _getSparkMarketsData(client, network, market),
|
|
210
|
-
readPosition: ({ client, network }, address, market, marketData) => _getSparkAccountData(client, network, address, {
|
|
211
|
-
selectedMarket: market, assetsData: marketData.assetsData, eModeCategoriesData: marketData.eModeCategoriesData,
|
|
212
|
-
}),
|
|
213
|
-
holds: suppliesAnything,
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
export const aaveV2Lending = lendingProtocol('aaveV2', {
|
|
217
|
-
marketsKey: 'aaveV2MarketsData',
|
|
218
|
-
label: 'AaveV2',
|
|
219
|
-
markets: (network): AaveMarketInfo[] => onNetwork(network, [AaveMarkets(network)[AaveVersions.AaveV2]]),
|
|
220
|
-
readMarket: ({ client, network }, market) => _getAaveV2MarketsData(client, network, market),
|
|
221
|
-
readPosition: ({ client, network }, address, market, marketData) => _getAaveV2AccountData(client, network, address, marketData.assetsData, market),
|
|
222
|
-
holds: suppliesAnything,
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
export const compoundV2Lending = lendingProtocol('compoundV2', {
|
|
226
|
-
marketsKey: 'compoundV2MarketsData',
|
|
227
|
-
label: 'CompoundV2',
|
|
228
|
-
markets: (network): CompoundMarketData[] => onNetwork(network, [CompoundMarkets(network)[CompoundVersions.CompoundV2]]),
|
|
229
|
-
readMarket: ({ client, network }) => _getCompoundV2MarketsData(client, network),
|
|
230
|
-
readPosition: ({ client, network }, address, _market, marketData) => _getCompoundV2AccountData(client, network, address, marketData.assetsData),
|
|
231
|
-
holds: suppliesAnything,
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
export const crvUsdLending = lendingProtocol('crvUsd', {
|
|
235
|
-
marketsKey: 'crvUsdMarketsData',
|
|
236
|
-
label: 'Curve USD',
|
|
237
|
-
markets: (network): CrvUSDMarketData[] => onNetwork(network, Object.values(CrvUsdMarkets(network))),
|
|
238
|
-
readMarket: ({ client, network }, market) => _getCurveUsdGlobalData(client, network, market),
|
|
239
|
-
// The market's borrow rate is passed in, so the read does not fetch it again.
|
|
240
|
-
readPosition: ({ client, network }, address, market, marketData) => _getCurveUsdUserData(client, network, address, market, marketData.activeBand, marketData.borrowRate),
|
|
241
|
-
holds: suppliesOrBorrowsAnything,
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
export const llamaLendLending = lendingProtocol('llamaLend', {
|
|
245
|
-
marketsKey: 'llamaLendMarketsData',
|
|
246
|
-
label: 'LlamaLend',
|
|
247
|
-
markets: (network): LlamaLendMarketData[] => ([NetworkNumber.Eth, NetworkNumber.Arb].includes(network) ? onNetwork(network, Object.values(LlamaLendMarkets(network))) : []),
|
|
248
|
-
readMarket: ({ client, network }, market) => _getLlamaLendGlobalData(client, network, market),
|
|
249
|
-
readPosition: async ({ client, network }, address, market, marketData) => ({
|
|
250
|
-
...await _getLlamaLendUserData(client, network, address, market, marketData),
|
|
251
|
-
borrowRate: marketData.borrowRate,
|
|
252
|
-
}),
|
|
253
|
-
holds: suppliesOrBorrowsAnything,
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
/** Every lending protocol read through its entry, in the order positions list them. */
|
|
257
|
-
export const LENDING_PROTOCOLS = [
|
|
258
|
-
aaveV3Lending,
|
|
259
|
-
aaveV4Lending,
|
|
260
|
-
morphoBlueLending,
|
|
261
|
-
morphoMidnightLending,
|
|
262
|
-
compoundV3Lending,
|
|
263
|
-
sparkLending,
|
|
264
|
-
aaveV2Lending,
|
|
265
|
-
compoundV2Lending,
|
|
266
|
-
crvUsdLending,
|
|
267
|
-
llamaLendLending,
|
|
268
|
-
] as const;
|
|
269
|
-
|
|
270
|
-
export type LendingKey = typeof LENDING_PROTOCOLS[number]['key'];
|
|
271
|
-
|
|
272
|
-
/** The keys ./index.ts reads with code of its own. */
|
|
273
|
-
export type SpecialPositionKey = 'maker' | 'liquity' | 'fluid' | 'liquityV2';
|
|
274
|
-
type SpecialMarketsKey = 'liquityV2MarketsData';
|
|
275
|
-
|
|
276
|
-
// Every position key and every markets key is read by an entry here or by its own code in ./index.ts: one added to
|
|
277
|
-
// PortfolioPositionsDataForAddress or PortfolioMarketsData with neither is a compile error on these lines, naming it.
|
|
278
|
-
type UnreadPositionKey = Exclude<PositionKey, LendingKey | SpecialPositionKey>;
|
|
279
|
-
type UnreadMarketsKey = Exclude<MarketsKey, typeof LENDING_PROTOCOLS[number]['marketsKey'] | SpecialMarketsKey>;
|
|
280
|
-
export const EVERY_POSITION_KEY_IS_READ: [UnreadPositionKey] extends [never] ? true : UnreadPositionKey = true;
|
|
281
|
-
export const EVERY_MARKETS_KEY_IS_READ: [UnreadMarketsKey] extends [never] ? true : UnreadMarketsKey = true;
|