@defisaver/positions-sdk 2.1.1 → 2.1.3
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 +1 -0
- package/cjs/aaveV3/index.d.ts +12 -0
- package/cjs/aaveV3/index.js +93 -1
- package/cjs/claiming/aaveV3.d.ts +5 -0
- package/cjs/claiming/aaveV3.js +139 -0
- package/cjs/claiming/compV3.d.ts +15 -0
- package/cjs/claiming/compV3.js +34 -0
- package/cjs/claiming/index.d.ts +6 -0
- package/cjs/claiming/index.js +46 -0
- package/cjs/claiming/king.d.ts +4 -0
- package/cjs/claiming/king.js +72 -0
- package/cjs/claiming/morphoBlue.d.ts +5 -0
- package/cjs/claiming/morphoBlue.js +113 -0
- package/cjs/claiming/spark.d.ts +6 -0
- package/cjs/claiming/spark.js +188 -0
- package/cjs/config/contracts.d.ts +2681 -0
- package/cjs/config/contracts.js +103 -2
- package/cjs/constants/index.d.ts +4 -0
- package/cjs/constants/index.js +6 -2
- package/cjs/contracts.d.ts +3027 -23
- package/cjs/contracts.js +10 -1
- package/cjs/helpers/aaveHelpers/index.d.ts +4 -0
- package/cjs/helpers/aaveHelpers/index.js +25 -8
- package/cjs/helpers/morphoBlueHelpers/index.d.ts +1 -0
- package/cjs/helpers/morphoBlueHelpers/index.js +7 -1
- package/cjs/index.d.ts +2 -1
- package/cjs/index.js +3 -1
- package/cjs/liquity/index.d.ts +11 -0
- package/cjs/liquity/index.js +39 -1
- package/cjs/liquityV2/index.d.ts +35 -0
- package/cjs/liquityV2/index.js +142 -1
- package/cjs/morphoBlue/index.d.ts +5 -0
- package/cjs/morphoBlue/index.js +35 -0
- package/cjs/portfolio/index.d.ts +6 -1
- package/cjs/portfolio/index.js +293 -10
- package/cjs/services/utils.d.ts +5 -0
- package/cjs/services/utils.js +33 -1
- package/cjs/services/viem.d.ts +12 -12
- package/cjs/spark/index.js +1 -0
- package/cjs/staking/eligibility.d.ts +4 -2
- package/cjs/staking/eligibility.js +3 -4
- package/cjs/staking/staking.d.ts +2 -1
- package/cjs/staking/staking.js +3 -3
- package/cjs/types/claiming.d.ts +93 -0
- package/cjs/types/claiming.js +27 -0
- package/cjs/types/common.d.ts +1 -1
- package/cjs/types/common.js +1 -1
- package/cjs/umbrella/index.d.ts +5 -0
- package/cjs/umbrella/index.js +50 -0
- package/cjs/umbrella/umbrellaUtils.d.ts +22 -0
- package/cjs/umbrella/umbrellaUtils.js +34 -0
- package/esm/aaveV2/index.js +1 -0
- package/esm/aaveV3/index.d.ts +12 -0
- package/esm/aaveV3/index.js +91 -1
- package/esm/claiming/aaveV3.d.ts +5 -0
- package/esm/claiming/aaveV3.js +132 -0
- package/esm/claiming/compV3.d.ts +15 -0
- package/esm/claiming/compV3.js +30 -0
- package/esm/claiming/index.d.ts +6 -0
- package/esm/claiming/index.js +6 -0
- package/esm/claiming/king.d.ts +4 -0
- package/esm/claiming/king.js +64 -0
- package/esm/claiming/morphoBlue.d.ts +5 -0
- package/esm/claiming/morphoBlue.js +105 -0
- package/esm/claiming/spark.d.ts +6 -0
- package/esm/claiming/spark.js +179 -0
- package/esm/config/contracts.d.ts +2681 -0
- package/esm/config/contracts.js +102 -1
- package/esm/constants/index.d.ts +4 -0
- package/esm/constants/index.js +5 -1
- package/esm/contracts.d.ts +3027 -23
- package/esm/contracts.js +9 -0
- package/esm/helpers/aaveHelpers/index.d.ts +4 -0
- package/esm/helpers/aaveHelpers/index.js +23 -7
- package/esm/helpers/morphoBlueHelpers/index.d.ts +1 -0
- package/esm/helpers/morphoBlueHelpers/index.js +6 -1
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -1
- package/esm/liquity/index.d.ts +11 -0
- package/esm/liquity/index.js +38 -1
- package/esm/liquityV2/index.d.ts +35 -0
- package/esm/liquityV2/index.js +142 -3
- package/esm/morphoBlue/index.d.ts +5 -0
- package/esm/morphoBlue/index.js +35 -1
- package/esm/portfolio/index.d.ts +6 -1
- package/esm/portfolio/index.js +298 -15
- package/esm/services/utils.d.ts +5 -0
- package/esm/services/utils.js +31 -0
- package/esm/services/viem.d.ts +12 -12
- package/esm/spark/index.js +1 -0
- package/esm/staking/eligibility.d.ts +4 -2
- package/esm/staking/eligibility.js +3 -4
- package/esm/staking/staking.d.ts +2 -1
- package/esm/staking/staking.js +3 -3
- package/esm/types/claiming.d.ts +93 -0
- package/esm/types/claiming.js +24 -0
- package/esm/types/common.d.ts +1 -1
- package/esm/types/common.js +1 -1
- package/esm/umbrella/index.d.ts +5 -0
- package/esm/umbrella/index.js +46 -0
- package/esm/umbrella/umbrellaUtils.d.ts +22 -0
- package/esm/umbrella/umbrellaUtils.js +28 -0
- package/package.json +1 -1
- package/src/aaveV2/index.ts +2 -1
- package/src/aaveV3/index.ts +100 -2
- package/src/claiming/aaveV3.ts +155 -0
- package/src/claiming/compV3.ts +23 -0
- package/src/claiming/index.ts +13 -0
- package/src/claiming/king.ts +66 -0
- package/src/claiming/morphoBlue.ts +119 -0
- package/src/claiming/spark.ts +226 -0
- package/src/config/contracts.ts +104 -4
- package/src/constants/index.ts +5 -1
- package/src/contracts.ts +14 -1
- package/src/helpers/aaveHelpers/index.ts +24 -7
- package/src/helpers/morphoBlueHelpers/index.ts +7 -2
- package/src/index.ts +2 -0
- package/src/liquity/index.ts +57 -2
- package/src/liquityV2/index.ts +244 -4
- package/src/morphoBlue/index.ts +40 -2
- package/src/portfolio/index.ts +300 -15
- package/src/services/utils.ts +37 -1
- package/src/spark/index.ts +2 -1
- package/src/staking/eligibility.ts +3 -4
- package/src/staking/staking.ts +4 -4
- package/src/types/claiming.ts +109 -0
- package/src/types/common.ts +1 -1
- package/src/umbrella/index.ts +70 -0
- package/src/umbrella/umbrellaUtils.ts +30 -0
package/esm/portfolio/index.js
CHANGED
|
@@ -9,23 +9,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
11
|
import { NetworkNumber } from '../types/common';
|
|
12
|
-
import { AaveMarkets, CompoundMarkets, CrvUsdMarkets, EulerV2Markets, LlamaLendMarkets, MorphoBlueMarkets, SparkMarkets, } from '../markets';
|
|
13
|
-
import { _getMorphoBlueAccountData, _getMorphoBlueMarketData } from '../morphoBlue';
|
|
12
|
+
import { AaveMarkets, CompoundMarkets, CrvUsdMarkets, EulerV2Markets, LiquityV2Markets, LlamaLendMarkets, MorphoBlueMarkets, SparkMarkets, } from '../markets';
|
|
13
|
+
import { _getMorphoBlueAccountData, _getMorphoBlueMarketData, getMorphoEarn } from '../morphoBlue';
|
|
14
14
|
import { AaveVersions, CompoundVersions, } from '../types';
|
|
15
15
|
import { _getCompoundV3AccountData, _getCompoundV3MarketsData } from '../compoundV3';
|
|
16
16
|
import { _getSparkAccountData, _getSparkMarketsData } from '../spark';
|
|
17
17
|
import { _getEulerV2AccountData, _getEulerV2MarketsData } from '../eulerV2';
|
|
18
18
|
import { _getCurveUsdGlobalData, _getCurveUsdUserData } from '../curveUsd';
|
|
19
19
|
import { _getLlamaLendGlobalData, _getLlamaLendUserData } from '../llamaLend';
|
|
20
|
-
import { _getAaveV3AccountData, _getAaveV3MarketData } from '../aaveV3';
|
|
20
|
+
import { _getAaveV3AccountData, _getAaveV3MarketData, getStakeAaveData } from '../aaveV3';
|
|
21
21
|
import { ZERO_ADDRESS } from '../constants';
|
|
22
22
|
import { _getMakerCdpData, _getUserCdps } from '../maker';
|
|
23
23
|
import { _getAaveV2AccountData, _getAaveV2MarketsData } from '../aaveV2';
|
|
24
24
|
import { _getCompoundV2AccountData, _getCompoundV2MarketsData } from '../compoundV2';
|
|
25
25
|
import { getViemProvider } from '../services/viem';
|
|
26
|
-
import { _getLiquityTroveInfo } from '../liquity';
|
|
27
|
-
import {
|
|
26
|
+
import { _getLiquityTroveInfo, getLiquityStakingData } from '../liquity';
|
|
27
|
+
import { _getLiquityV2MarketData, getLiquitySAndYBold, getLiquityV2Staking } from '../liquityV2';
|
|
28
|
+
import { _getAllUserEarnPositionsWithFTokens, _getUserPositionsPortfolio } from '../fluid';
|
|
28
29
|
import { getEulerV2SubAccounts } from '../helpers/eulerHelpers';
|
|
30
|
+
import { getUmbrellaData } from '../umbrella';
|
|
31
|
+
import { getMeritUnclaimedRewards, getUnclaimedRewardsForAllMarkets } from '../claiming/aaveV3';
|
|
32
|
+
import { getCompoundV3Rewards } from '../claiming/compV3';
|
|
33
|
+
import { fetchSparkAirdropRewards, fetchSparkRewards } from '../claiming/spark';
|
|
34
|
+
import { fetchMorphoBlueRewards } from '../claiming/morphoBlue';
|
|
35
|
+
import { getKingRewards } from '../claiming/king';
|
|
29
36
|
export function getPortfolioData(provider, network, defaultProvider, addresses, summerFiAddresses) {
|
|
30
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
38
|
const isMainnet = network === NetworkNumber.Eth;
|
|
@@ -39,6 +46,8 @@ export function getPortfolioData(provider, network, defaultProvider, addresses,
|
|
|
39
46
|
const compoundV2Markets = [CompoundVersions.CompoundV2].map((version) => CompoundMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
|
|
40
47
|
const crvUsdMarkets = Object.values(CrvUsdMarkets(network)).filter((market) => market.chainIds.includes(network));
|
|
41
48
|
const llamaLendMarkets = [NetworkNumber.Eth, NetworkNumber.Arb].includes(network) ? Object.values(LlamaLendMarkets(network)).filter((market) => market.chainIds.includes(network)) : [];
|
|
49
|
+
const liquityV2Markets = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)) : [];
|
|
50
|
+
const liquityV2MarketsStaking = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)).filter(market => !market.isLegacy) : [];
|
|
42
51
|
const client = getViemProvider(provider, network, {
|
|
43
52
|
batch: {
|
|
44
53
|
multicall: {
|
|
@@ -63,7 +72,22 @@ export function getPortfolioData(provider, network, defaultProvider, addresses,
|
|
|
63
72
|
const compoundV2MarketsData = {};
|
|
64
73
|
const crvUsdMarketsData = {};
|
|
65
74
|
const llamaLendMarketsData = {};
|
|
75
|
+
const liquityV2MarketsData = {};
|
|
76
|
+
const markets = {
|
|
77
|
+
morphoMarketsData,
|
|
78
|
+
compoundV3MarketsData,
|
|
79
|
+
sparkMarketsData,
|
|
80
|
+
eulerV2MarketsData,
|
|
81
|
+
aaveV3MarketsData,
|
|
82
|
+
aaveV2MarketsData,
|
|
83
|
+
compoundV2MarketsData,
|
|
84
|
+
crvUsdMarketsData,
|
|
85
|
+
llamaLendMarketsData,
|
|
86
|
+
liquityV2MarketsData,
|
|
87
|
+
};
|
|
66
88
|
const positions = {};
|
|
89
|
+
const stakingPositions = {};
|
|
90
|
+
const rewardsData = {};
|
|
67
91
|
const allAddresses = [...addresses, ...summerFiAddresses];
|
|
68
92
|
for (const address of allAddresses) {
|
|
69
93
|
positions[address.toLowerCase()] = {
|
|
@@ -84,7 +108,34 @@ export function getPortfolioData(provider, network, defaultProvider, addresses,
|
|
|
84
108
|
},
|
|
85
109
|
};
|
|
86
110
|
}
|
|
111
|
+
// TODO: check default values, probably needed when fetching portfolio on unsupported networks
|
|
112
|
+
for (const address of addresses) {
|
|
113
|
+
stakingPositions[address.toLowerCase()] = {
|
|
114
|
+
aaveV3: {},
|
|
115
|
+
morphoBlue: {},
|
|
116
|
+
compoundV3: {},
|
|
117
|
+
spark: {},
|
|
118
|
+
aaveV2: {},
|
|
119
|
+
compoundV2: {},
|
|
120
|
+
liquity: {},
|
|
121
|
+
liquityV2: {},
|
|
122
|
+
fluid: {
|
|
123
|
+
error: '',
|
|
124
|
+
data: {},
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
rewardsData[address.toLowerCase()] = {
|
|
128
|
+
aaveV3merit: {},
|
|
129
|
+
aaveV3: {},
|
|
130
|
+
compV3: {},
|
|
131
|
+
spark: {},
|
|
132
|
+
spk: {},
|
|
133
|
+
king: {},
|
|
134
|
+
morpho: {},
|
|
135
|
+
};
|
|
136
|
+
}
|
|
87
137
|
yield Promise.allSettled([
|
|
138
|
+
// === MARKET DATA (needs to be fetched first) ===
|
|
88
139
|
...morphoMarkets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
89
140
|
const marketData = yield _getMorphoBlueMarketData(client, network, market);
|
|
90
141
|
morphoMarketsData[market.value] = marketData;
|
|
@@ -105,12 +156,6 @@ export function getPortfolioData(provider, network, defaultProvider, addresses,
|
|
|
105
156
|
const marketData = yield _getAaveV3MarketData(client, network, market);
|
|
106
157
|
aaveV3MarketsData[market.value] = marketData;
|
|
107
158
|
})),
|
|
108
|
-
...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
109
|
-
if (!isMainnet)
|
|
110
|
-
return; // Maker CDPs are only available on mainnet
|
|
111
|
-
const makerCdp = yield _getUserCdps(client, network, address);
|
|
112
|
-
makerCdps[address.toLowerCase()] = makerCdp;
|
|
113
|
-
})),
|
|
114
159
|
...aaveV2Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
115
160
|
const marketData = yield _getAaveV2MarketsData(client, network, market);
|
|
116
161
|
aaveV2MarketsData[market.value] = marketData;
|
|
@@ -127,6 +172,17 @@ export function getPortfolioData(provider, network, defaultProvider, addresses,
|
|
|
127
172
|
const marketData = yield _getLlamaLendGlobalData(client, network, market);
|
|
128
173
|
llamaLendMarketsData[market.value] = marketData;
|
|
129
174
|
})),
|
|
175
|
+
...liquityV2Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
const marketData = yield _getLiquityV2MarketData(client, network, market);
|
|
177
|
+
liquityV2MarketsData[market.value] = marketData;
|
|
178
|
+
})),
|
|
179
|
+
// === INDEPENDENT USER DATA (doesn't depend on market data) ===
|
|
180
|
+
...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
if (!isMainnet)
|
|
182
|
+
return; // Maker CDPs are only available on mainnet
|
|
183
|
+
const makerCdp = yield _getUserCdps(client, network, address);
|
|
184
|
+
makerCdps[address.toLowerCase()] = makerCdp;
|
|
185
|
+
})),
|
|
130
186
|
...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
131
187
|
try {
|
|
132
188
|
if (!isFluidSupported)
|
|
@@ -146,6 +202,190 @@ export function getPortfolioData(provider, network, defaultProvider, addresses,
|
|
|
146
202
|
};
|
|
147
203
|
}
|
|
148
204
|
})),
|
|
205
|
+
// === STAKING DATA (independent of market data) ===
|
|
206
|
+
...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
207
|
+
try {
|
|
208
|
+
if (!isFluidSupported)
|
|
209
|
+
return;
|
|
210
|
+
stakingPositions[address.toLowerCase()].fluid = yield _getAllUserEarnPositionsWithFTokens(client, network, address);
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
console.error(`Error fetching Fluid lend data for address ${address}:`, error);
|
|
214
|
+
stakingPositions[address.toLowerCase()].fluid = { error: `Error fetching Fluid lend data for address ${address}`, data: null };
|
|
215
|
+
}
|
|
216
|
+
})),
|
|
217
|
+
...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
218
|
+
try {
|
|
219
|
+
if (!isMainnet)
|
|
220
|
+
return;
|
|
221
|
+
stakingPositions[address.toLowerCase()].liquity = yield getLiquityStakingData(client, network, address);
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
console.error(`Error fetching Liquity staking data for address ${address}:`, error);
|
|
225
|
+
stakingPositions[address.toLowerCase()].liquity = { error: `Error fetching Liquity staking data for address ${address}`, data: null };
|
|
226
|
+
}
|
|
227
|
+
})),
|
|
228
|
+
...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
229
|
+
try {
|
|
230
|
+
if (!isMainnet)
|
|
231
|
+
return;
|
|
232
|
+
stakingPositions[address.toLowerCase()].aaveV3 = yield getStakeAaveData(client, network, address);
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
console.error(`Error fetching Aave V3 staking data for address ${address}:`, error);
|
|
236
|
+
stakingPositions[address.toLowerCase()].aaveV3 = { error: `Error fetching Aave V3 staking data for address ${address}`, data: null };
|
|
237
|
+
}
|
|
238
|
+
})),
|
|
239
|
+
...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
240
|
+
try {
|
|
241
|
+
if (!isMainnet)
|
|
242
|
+
return;
|
|
243
|
+
stakingPositions[address.toLowerCase()].umbrella = yield getUmbrellaData(client, network, address);
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
console.error(`Error fetching Umbrella staking data for address ${address}:`, error);
|
|
247
|
+
stakingPositions[address.toLowerCase()].umbrella = { error: `Error fetching Umbrella staking data for address ${address}`, data: null };
|
|
248
|
+
}
|
|
249
|
+
})),
|
|
250
|
+
// Liquity V2 staking
|
|
251
|
+
...liquityV2MarketsStaking.map(market => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
252
|
+
try {
|
|
253
|
+
if (!isMainnet) {
|
|
254
|
+
stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: '', data: null };
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const liquityV2StakingData = yield getLiquityV2Staking(client, network, market.value, address);
|
|
258
|
+
stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: '', data: liquityV2StakingData };
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
console.error(`Error fetching Liquity V2 staking data for address ${address}, market ${market.value}:`, error);
|
|
262
|
+
stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: `Error fetching Liquity V2 staking data for address ${address}`, data: null };
|
|
263
|
+
}
|
|
264
|
+
}))).flat(),
|
|
265
|
+
// === REWARDS DATA (independent of market data) ===
|
|
266
|
+
// Batch King rewards
|
|
267
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
268
|
+
try {
|
|
269
|
+
if (!isMainnet) {
|
|
270
|
+
for (const address of addresses) {
|
|
271
|
+
rewardsData[address.toLowerCase()].king = { error: '', data: [] };
|
|
272
|
+
}
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
const kingRewards = yield getKingRewards(client, network, addresses);
|
|
276
|
+
for (const address of addresses) {
|
|
277
|
+
const lowerAddress = address.toLowerCase();
|
|
278
|
+
rewardsData[lowerAddress].king = {
|
|
279
|
+
error: '',
|
|
280
|
+
data: kingRewards[lowerAddress] || [],
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
catch (error) {
|
|
285
|
+
console.error('Error fetching King rewards data in batch:', error);
|
|
286
|
+
for (const address of addresses) {
|
|
287
|
+
rewardsData[address.toLowerCase()].king = {
|
|
288
|
+
error: 'Error fetching King rewards data in batch',
|
|
289
|
+
data: null,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}))(),
|
|
294
|
+
...sparkMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
295
|
+
try {
|
|
296
|
+
if (!isMainnet) {
|
|
297
|
+
rewardsData[address.toLowerCase()].spark[market.value] = { error: '', data: [] };
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
const sparkData = yield fetchSparkRewards(client, network, address, market.providerAddress);
|
|
301
|
+
rewardsData[address.toLowerCase()].spark[market.value] = { error: '', data: sparkData };
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
console.error(`Error fetching Spark rewards data for address ${address}, market ${market.value}:`, error);
|
|
305
|
+
rewardsData[address.toLowerCase()].spark[market.value] = { error: `Error fetching Spark rewards data for address ${address}`, data: null };
|
|
306
|
+
}
|
|
307
|
+
}))).flat(),
|
|
308
|
+
// CompV3 rewards
|
|
309
|
+
...compoundV3Markets.map(market => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
310
|
+
try {
|
|
311
|
+
const compV3Rewards = yield getCompoundV3Rewards(client, network, address, market.baseMarketAddress);
|
|
312
|
+
rewardsData[address.toLowerCase()].compV3[market.value] = { error: '', data: compV3Rewards };
|
|
313
|
+
}
|
|
314
|
+
catch (error) {
|
|
315
|
+
console.error(`Error fetching Compound V3 rewards data for address ${address}:`, error);
|
|
316
|
+
rewardsData[address.toLowerCase()].compV3[market.value] = { error: `Error fetching Compound V3 rewards data for address ${address}`, data: null };
|
|
317
|
+
}
|
|
318
|
+
}))).flat(),
|
|
319
|
+
...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
320
|
+
try {
|
|
321
|
+
const aaveMeritData = yield getMeritUnclaimedRewards(address, network);
|
|
322
|
+
rewardsData[address.toLowerCase()].aaveV3merit = { error: '', data: aaveMeritData };
|
|
323
|
+
}
|
|
324
|
+
catch (error) {
|
|
325
|
+
console.error(`Error fetching Aave V3 Merit rewards data for address ${address}:`, error);
|
|
326
|
+
rewardsData[address.toLowerCase()].aaveV3merit = { error: `Error fetching Aave V3 Merit rewards data for address ${address}`, data: null };
|
|
327
|
+
}
|
|
328
|
+
})),
|
|
329
|
+
...aaveV3Markets.map(market => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
330
|
+
try {
|
|
331
|
+
const aaveData = yield getUnclaimedRewardsForAllMarkets(client, network, address, market.providerAddress);
|
|
332
|
+
rewardsData[address.toLowerCase()].aaveV3[market.value] = { error: '', data: aaveData };
|
|
333
|
+
}
|
|
334
|
+
catch (error) {
|
|
335
|
+
console.error(`Error fetching Aave V3 Merit rewards data for address ${address}:`, error);
|
|
336
|
+
rewardsData[address.toLowerCase()].aaveV3 = { error: `Error fetching Aave V3 rewards data for address ${address}`, data: null };
|
|
337
|
+
}
|
|
338
|
+
}))).flat(),
|
|
339
|
+
// Batch Morpho Blue rewards
|
|
340
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
341
|
+
try {
|
|
342
|
+
const morphoRewards = yield fetchMorphoBlueRewards(client, network, addresses);
|
|
343
|
+
for (const address of addresses) {
|
|
344
|
+
const lowerAddress = address.toLowerCase();
|
|
345
|
+
rewardsData[lowerAddress].morpho = {
|
|
346
|
+
error: '',
|
|
347
|
+
data: morphoRewards[lowerAddress] || [],
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
catch (error) {
|
|
352
|
+
console.error('Error fetching Morpho Blue rewards data in batch:', error);
|
|
353
|
+
for (const address of addresses) {
|
|
354
|
+
rewardsData[address.toLowerCase()].morpho = {
|
|
355
|
+
error: 'Error fetching Morpho Blue rewards data in batch',
|
|
356
|
+
data: null,
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}))(),
|
|
361
|
+
// Batch Spark Airdrop rewards
|
|
362
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
363
|
+
try {
|
|
364
|
+
if (!isMainnet) {
|
|
365
|
+
for (const address of addresses) {
|
|
366
|
+
rewardsData[address.toLowerCase()].spk = { error: '', data: [] };
|
|
367
|
+
}
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
const sparkAirdropRewards = yield fetchSparkAirdropRewards(client, network, addresses);
|
|
371
|
+
for (const address of addresses) {
|
|
372
|
+
const lowerAddress = address.toLowerCase();
|
|
373
|
+
rewardsData[lowerAddress].spk = {
|
|
374
|
+
error: '',
|
|
375
|
+
data: sparkAirdropRewards[lowerAddress] || [],
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
catch (error) {
|
|
380
|
+
console.error('Error fetching Spark Airdrop rewards data in batch:', error);
|
|
381
|
+
for (const address of addresses) {
|
|
382
|
+
rewardsData[address.toLowerCase()].spk = {
|
|
383
|
+
error: 'Error fetching Spark Airdrop rewards data in batch',
|
|
384
|
+
data: null,
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}))(),
|
|
149
389
|
]);
|
|
150
390
|
yield Promise.all([
|
|
151
391
|
...aaveV3Markets.map((market) => allAddresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -161,9 +401,32 @@ export function getPortfolioData(provider, network, defaultProvider, addresses,
|
|
|
161
401
|
}))).flat(),
|
|
162
402
|
...morphoMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
163
403
|
try {
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
404
|
+
const [accDataPromise, earnDataPromise] = yield Promise.allSettled([
|
|
405
|
+
_getMorphoBlueAccountData(client, network, address, market, morphoMarketsData[market.value]),
|
|
406
|
+
getMorphoEarn(client, network, address, market, morphoMarketsData[market.value]),
|
|
407
|
+
]);
|
|
408
|
+
if (accDataPromise.status === 'rejected') {
|
|
409
|
+
console.error(`Error fetching MorphoBlue account data for address ${address} on market ${market.value}:`, accDataPromise.reason);
|
|
410
|
+
positions[address.toLowerCase()].morphoBlue[market.value] = { error: `Error fetching MorphoBlue account data for address ${address} on market ${market.value}`, data: null };
|
|
411
|
+
}
|
|
412
|
+
if (earnDataPromise.status === 'rejected') {
|
|
413
|
+
console.error(`Error fetching MorphoBlue account data for address ${address} on market ${market.value}:`, earnDataPromise.reason);
|
|
414
|
+
positions[address.toLowerCase()].morphoBlue[market.value] = { error: `Error fetching MorphoBlue account data for address ${address} on market ${market.value}`, data: null };
|
|
415
|
+
}
|
|
416
|
+
if (accDataPromise.status !== 'rejected') {
|
|
417
|
+
const accData = accDataPromise.value;
|
|
418
|
+
if (new Dec(accData.suppliedUsd).gt(0))
|
|
419
|
+
positions[address.toLowerCase()].morphoBlue[market.value] = { error: '', data: accData };
|
|
420
|
+
}
|
|
421
|
+
if (earnDataPromise.status !== 'rejected') {
|
|
422
|
+
const earnData = earnDataPromise.value;
|
|
423
|
+
if (earnData && new Dec(earnData.amount).gt(0)) {
|
|
424
|
+
stakingPositions[address.toLowerCase()].morphoBlue[market.value] = {
|
|
425
|
+
error: '',
|
|
426
|
+
data: earnData,
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
}
|
|
167
430
|
}
|
|
168
431
|
catch (error) {
|
|
169
432
|
console.error(`Error fetching MorphoBlue account data for address ${address} on market ${market.value}:`, error);
|
|
@@ -288,7 +551,27 @@ export function getPortfolioData(provider, network, defaultProvider, addresses,
|
|
|
288
551
|
positions[address.toLowerCase()].llamaLend[market.value] = { error: `Error fetching LlamaLend account data for address ${address} on market ${market.value}`, data: null };
|
|
289
552
|
}
|
|
290
553
|
}))).flat(),
|
|
554
|
+
// liquity sBold/yBold and staking options
|
|
555
|
+
...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
556
|
+
try {
|
|
557
|
+
if (!isMainnet) {
|
|
558
|
+
stakingPositions[address.toLowerCase()].liquityV2SBoldYBold = { error: '', data: null };
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
const data = yield getLiquitySAndYBold(client, network, stakingPositions[address.toLowerCase()].liquityV2, address);
|
|
562
|
+
stakingPositions[address.toLowerCase()].liquityV2SBoldYBold = { error: '', data };
|
|
563
|
+
}
|
|
564
|
+
catch (error) {
|
|
565
|
+
console.error(`Error fetching SBold/YBold data for address ${address}:`, error);
|
|
566
|
+
stakingPositions[address.toLowerCase()].liquityV2SBoldYBold = { error: `Error fetching sBold/yBold data for address ${address}`, data: null };
|
|
567
|
+
}
|
|
568
|
+
})),
|
|
291
569
|
]);
|
|
292
|
-
return
|
|
570
|
+
return {
|
|
571
|
+
positions,
|
|
572
|
+
stakingPositions,
|
|
573
|
+
rewardsData,
|
|
574
|
+
markets,
|
|
575
|
+
};
|
|
293
576
|
});
|
|
294
577
|
}
|
package/esm/services/utils.d.ts
CHANGED
|
@@ -25,3 +25,8 @@ export declare const MAXUINT: string;
|
|
|
25
25
|
export declare const isMaxuint: (amount: string) => boolean;
|
|
26
26
|
export declare const isMainnetNetwork: (network: NetworkNumber) => network is NetworkNumber.Eth;
|
|
27
27
|
export declare const DEFAULT_TIMEOUT = 2000;
|
|
28
|
+
/**
|
|
29
|
+
* Converts web3 hybrid response (that can be used as objects and arrays, so has duplicated values) to objects.
|
|
30
|
+
* @param value
|
|
31
|
+
*/
|
|
32
|
+
export declare const convertHybridArraysToObjects: (value: any) => any;
|
package/esm/services/utils.js
CHANGED
|
@@ -38,3 +38,34 @@ export const MAXUINT = '11579208923731619542357098500868790785326998466564056403
|
|
|
38
38
|
export const isMaxuint = (amount) => compareAddresses(MAXUINT, amount);
|
|
39
39
|
export const isMainnetNetwork = (network) => network === NetworkNumber.Eth;
|
|
40
40
|
export const DEFAULT_TIMEOUT = 2000; // 2 seconds
|
|
41
|
+
/**
|
|
42
|
+
* Converts web3 hybrid response (that can be used as objects and arrays, so has duplicated values) to objects.
|
|
43
|
+
* @param value
|
|
44
|
+
*/
|
|
45
|
+
export const convertHybridArraysToObjects = (value) => {
|
|
46
|
+
if (Array.isArray(value)) {
|
|
47
|
+
const keys = Object.keys(value);
|
|
48
|
+
const hasNamedKeys = keys.some((key) => Number.isNaN(Number(key)));
|
|
49
|
+
// If array has named keys, treat it as an object and keep only those
|
|
50
|
+
if (hasNamedKeys) {
|
|
51
|
+
const result = {};
|
|
52
|
+
for (const [key, val] of Object.entries(value)) {
|
|
53
|
+
if (Number.isNaN(Number(key))) {
|
|
54
|
+
result[key] = convertHybridArraysToObjects(val);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
// Else, treat as a regular array
|
|
60
|
+
return value.map(convertHybridArraysToObjects);
|
|
61
|
+
}
|
|
62
|
+
// If it's an object (but not an array), recurse into its values
|
|
63
|
+
if (value && typeof value === 'object') {
|
|
64
|
+
const result = {};
|
|
65
|
+
for (const [key, val] of Object.entries(value)) {
|
|
66
|
+
result[key] = convertHybridArraysToObjects(val);
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
return value;
|
|
71
|
+
};
|
package/esm/services/viem.d.ts
CHANGED
|
@@ -795,9 +795,9 @@ export declare const getViemProvider: (provider: EthereumProvider, network: Netw
|
|
|
795
795
|
s: import("viem").Hex;
|
|
796
796
|
value: bigint;
|
|
797
797
|
v: bigint;
|
|
798
|
+
nonce: number;
|
|
798
799
|
type: "legacy";
|
|
799
800
|
gas: bigint;
|
|
800
|
-
nonce: number;
|
|
801
801
|
maxFeePerBlobGas?: undefined | undefined;
|
|
802
802
|
gasPrice: bigint;
|
|
803
803
|
maxFeePerGas?: undefined | undefined;
|
|
@@ -820,9 +820,9 @@ export declare const getViemProvider: (provider: EthereumProvider, network: Netw
|
|
|
820
820
|
s: import("viem").Hex;
|
|
821
821
|
value: bigint;
|
|
822
822
|
v: bigint;
|
|
823
|
+
nonce: number;
|
|
823
824
|
type: "eip2930";
|
|
824
825
|
gas: bigint;
|
|
825
|
-
nonce: number;
|
|
826
826
|
maxFeePerBlobGas?: undefined | undefined;
|
|
827
827
|
gasPrice: bigint;
|
|
828
828
|
maxFeePerGas?: undefined | undefined;
|
|
@@ -845,9 +845,9 @@ export declare const getViemProvider: (provider: EthereumProvider, network: Netw
|
|
|
845
845
|
s: import("viem").Hex;
|
|
846
846
|
value: bigint;
|
|
847
847
|
v: bigint;
|
|
848
|
+
nonce: number;
|
|
848
849
|
type: "eip1559";
|
|
849
850
|
gas: bigint;
|
|
850
|
-
nonce: number;
|
|
851
851
|
maxFeePerBlobGas?: undefined | undefined;
|
|
852
852
|
gasPrice?: undefined | undefined;
|
|
853
853
|
maxFeePerGas: bigint;
|
|
@@ -870,9 +870,9 @@ export declare const getViemProvider: (provider: EthereumProvider, network: Netw
|
|
|
870
870
|
s: import("viem").Hex;
|
|
871
871
|
value: bigint;
|
|
872
872
|
v: bigint;
|
|
873
|
+
nonce: number;
|
|
873
874
|
type: "eip4844";
|
|
874
875
|
gas: bigint;
|
|
875
|
-
nonce: number;
|
|
876
876
|
maxFeePerBlobGas: bigint;
|
|
877
877
|
gasPrice?: undefined | undefined;
|
|
878
878
|
maxFeePerGas: bigint;
|
|
@@ -895,9 +895,9 @@ export declare const getViemProvider: (provider: EthereumProvider, network: Netw
|
|
|
895
895
|
s: import("viem").Hex;
|
|
896
896
|
value: bigint;
|
|
897
897
|
v: bigint;
|
|
898
|
+
nonce: number;
|
|
898
899
|
type: "eip7702";
|
|
899
900
|
gas: bigint;
|
|
900
|
-
nonce: number;
|
|
901
901
|
maxFeePerBlobGas?: undefined | undefined;
|
|
902
902
|
gasPrice?: undefined | undefined;
|
|
903
903
|
maxFeePerGas: bigint;
|
|
@@ -945,9 +945,9 @@ export declare const getViemProvider: (provider: EthereumProvider, network: Netw
|
|
|
945
945
|
s: import("viem").Hex;
|
|
946
946
|
value: bigint;
|
|
947
947
|
v: bigint;
|
|
948
|
+
nonce: number;
|
|
948
949
|
type: "legacy";
|
|
949
950
|
gas: bigint;
|
|
950
|
-
nonce: number;
|
|
951
951
|
maxFeePerBlobGas?: undefined | undefined;
|
|
952
952
|
gasPrice: bigint;
|
|
953
953
|
maxFeePerGas?: undefined | undefined;
|
|
@@ -970,9 +970,9 @@ export declare const getViemProvider: (provider: EthereumProvider, network: Netw
|
|
|
970
970
|
s: import("viem").Hex;
|
|
971
971
|
value: bigint;
|
|
972
972
|
v: bigint;
|
|
973
|
+
nonce: number;
|
|
973
974
|
type: "eip2930";
|
|
974
975
|
gas: bigint;
|
|
975
|
-
nonce: number;
|
|
976
976
|
maxFeePerBlobGas?: undefined | undefined;
|
|
977
977
|
gasPrice: bigint;
|
|
978
978
|
maxFeePerGas?: undefined | undefined;
|
|
@@ -995,9 +995,9 @@ export declare const getViemProvider: (provider: EthereumProvider, network: Netw
|
|
|
995
995
|
s: import("viem").Hex;
|
|
996
996
|
value: bigint;
|
|
997
997
|
v: bigint;
|
|
998
|
+
nonce: number;
|
|
998
999
|
type: "eip1559";
|
|
999
1000
|
gas: bigint;
|
|
1000
|
-
nonce: number;
|
|
1001
1001
|
maxFeePerBlobGas?: undefined | undefined;
|
|
1002
1002
|
gasPrice?: undefined | undefined;
|
|
1003
1003
|
maxFeePerGas: bigint;
|
|
@@ -1020,9 +1020,9 @@ export declare const getViemProvider: (provider: EthereumProvider, network: Netw
|
|
|
1020
1020
|
s: import("viem").Hex;
|
|
1021
1021
|
value: bigint;
|
|
1022
1022
|
v: bigint;
|
|
1023
|
+
nonce: number;
|
|
1023
1024
|
type: "eip4844";
|
|
1024
1025
|
gas: bigint;
|
|
1025
|
-
nonce: number;
|
|
1026
1026
|
maxFeePerBlobGas: bigint;
|
|
1027
1027
|
gasPrice?: undefined | undefined;
|
|
1028
1028
|
maxFeePerGas: bigint;
|
|
@@ -1045,9 +1045,9 @@ export declare const getViemProvider: (provider: EthereumProvider, network: Netw
|
|
|
1045
1045
|
s: import("viem").Hex;
|
|
1046
1046
|
value: bigint;
|
|
1047
1047
|
v: bigint;
|
|
1048
|
+
nonce: number;
|
|
1048
1049
|
type: "eip7702";
|
|
1049
1050
|
gas: bigint;
|
|
1050
|
-
nonce: number;
|
|
1051
1051
|
maxFeePerBlobGas?: undefined | undefined;
|
|
1052
1052
|
gasPrice?: undefined | undefined;
|
|
1053
1053
|
maxFeePerGas: bigint;
|
|
@@ -4320,7 +4320,7 @@ export declare const getViemProvider: (provider: EthereumProvider, network: Netw
|
|
|
4320
4320
|
authorizationList: import("viem").TransactionSerializableEIP7702["authorizationList"];
|
|
4321
4321
|
} ? "eip7702" : never) | (request["type"] extends string | undefined ? Extract<request["type"], string> : never)>) ? T_25 extends "eip7702" ? import("viem").TransactionRequestEIP7702 : never : never : never)>> & {
|
|
4322
4322
|
chainId?: number | undefined;
|
|
4323
|
-
}, (request["parameters"] extends readonly import("viem").PrepareTransactionRequestParameterType[] ? request["parameters"][number] : "
|
|
4323
|
+
}, (request["parameters"] extends readonly import("viem").PrepareTransactionRequestParameterType[] ? request["parameters"][number] : "nonce" | "type" | "gas" | "blobVersionedHashes" | "fees" | "chainId") extends infer T_26 ? T_26 extends (request["parameters"] extends readonly import("viem").PrepareTransactionRequestParameterType[] ? request["parameters"][number] : "nonce" | "type" | "gas" | "blobVersionedHashes" | "fees" | "chainId") ? T_26 extends "fees" ? "gasPrice" | "maxFeePerGas" | "maxPriorityFeePerGas" : T_26 : never : never> & (unknown extends request["kzg"] ? {} : Pick<request, "kzg">) extends infer T ? { [K in keyof T]: (import("viem").UnionRequiredBy<Extract<import("viem").UnionOmit<import("viem").ExtractChainFormatterParameters<import("viem").DeriveChain<undefined, chainOverride>, "transactionRequest", import("viem").TransactionRequest>, "from"> & (import("viem").DeriveChain<undefined, chainOverride> extends infer T_1 ? T_1 extends import("viem").DeriveChain<undefined, chainOverride> ? T_1 extends import("viem").Chain ? {
|
|
4324
4324
|
chain: T_1;
|
|
4325
4325
|
} : {
|
|
4326
4326
|
chain?: undefined;
|
|
@@ -7572,7 +7572,7 @@ export declare const getViemProvider: (provider: EthereumProvider, network: Netw
|
|
|
7572
7572
|
authorizationList: import("viem").TransactionSerializableEIP7702["authorizationList"];
|
|
7573
7573
|
} ? "eip7702" : never) | (request["type"] extends string | undefined ? Extract<request["type"], string> : never)>) ? T_12 extends "eip7702" ? import("viem").TransactionRequestEIP7702 : never : never : never)>> & {
|
|
7574
7574
|
chainId?: number | undefined;
|
|
7575
|
-
}, (request["parameters"] extends readonly import("viem").PrepareTransactionRequestParameterType[] ? request["parameters"][number] : "
|
|
7575
|
+
}, (request["parameters"] extends readonly import("viem").PrepareTransactionRequestParameterType[] ? request["parameters"][number] : "nonce" | "type" | "gas" | "blobVersionedHashes" | "fees" | "chainId") extends infer T_13 ? T_13 extends (request["parameters"] extends readonly import("viem").PrepareTransactionRequestParameterType[] ? request["parameters"][number] : "nonce" | "type" | "gas" | "blobVersionedHashes" | "fees" | "chainId") ? T_13 extends "fees" ? "gasPrice" | "maxFeePerGas" | "maxPriorityFeePerGas" : T_13 : never : never> & (unknown extends request["kzg"] ? {} : Pick<request, "kzg">))[K]; } : never>;
|
|
7576
7576
|
readContract: <const abi extends import("viem").Abi | readonly unknown[], functionName extends import("viem").ContractFunctionName<abi, "pure" | "view">, const args extends import("viem").ContractFunctionArgs<abi, "pure" | "view", functionName>>(args: import("viem").ReadContractParameters<abi, functionName, args>) => Promise<import("viem").ReadContractReturnType<abi, functionName, args>>;
|
|
7577
7577
|
sendRawTransaction: (args: import("viem").SendRawTransactionParameters) => Promise<import("viem").SendRawTransactionReturnType>;
|
|
7578
7578
|
simulate: <const calls extends readonly unknown[]>(args: import("viem").SimulateBlocksParameters<calls>) => Promise<import("viem").SimulateBlocksReturnType<calls>>;
|
package/esm/spark/index.js
CHANGED
|
@@ -235,6 +235,7 @@ export const _getSparkAccountBalances = (provider, network, block, addressMappin
|
|
|
235
235
|
const marketAddress = market.providerAddress;
|
|
236
236
|
// @ts-ignore
|
|
237
237
|
const protocolDataProviderContract = createViemContractFromConfigFunc(market.protocolData, market.protocolDataAddress)(provider, network);
|
|
238
|
+
// @ts-ignore
|
|
238
239
|
const reserveTokens = yield protocolDataProviderContract.read.getAllReservesTokens(setViemBlockNumber(block));
|
|
239
240
|
const symbols = reserveTokens.map(({ symbol }) => symbol);
|
|
240
241
|
const _addresses = reserveTokens.map(({ tokenAddress }) => tokenAddress);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { IncentiveEligibilityId, MMUsedAssets } from '../types/common';
|
|
2
|
-
export declare const isEligibleForEthenaUSDeRewards: (usedAssets: MMUsedAssets
|
|
2
|
+
export declare const isEligibleForEthenaUSDeRewards: (usedAssets: MMUsedAssets, { healthRatio }: {
|
|
3
|
+
healthRatio: string;
|
|
4
|
+
}) => {
|
|
3
5
|
isEligible: boolean;
|
|
4
6
|
eligibleUSDAmount: string;
|
|
5
7
|
};
|
|
@@ -12,7 +14,7 @@ export declare const isEligibleForAaveV3ArbitrumETHLSBorrow: (usedAssets: MMUsed
|
|
|
12
14
|
eligibleUSDAmount: string;
|
|
13
15
|
};
|
|
14
16
|
export declare const EligibilityMapping: {
|
|
15
|
-
[key in IncentiveEligibilityId]: (usedAssets: MMUsedAssets) => {
|
|
17
|
+
[key in IncentiveEligibilityId]: (usedAssets: MMUsedAssets, optionalData: any) => {
|
|
16
18
|
isEligible: boolean;
|
|
17
19
|
eligibleUSDAmount: string;
|
|
18
20
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
2
|
import { IncentiveEligibilityId } from '../types/common';
|
|
3
|
-
export const isEligibleForEthenaUSDeRewards = (usedAssets) => {
|
|
3
|
+
export const isEligibleForEthenaUSDeRewards = (usedAssets, { healthRatio }) => {
|
|
4
4
|
var _a, _b;
|
|
5
5
|
const USDeUSDAmountSupplied = ((_a = usedAssets.USDe) === null || _a === void 0 ? void 0 : _a.suppliedUsd) || '0';
|
|
6
6
|
const sUSDeUSDAmountSupplied = ((_b = usedAssets.sUSDe) === null || _b === void 0 ? void 0 : _b.suppliedUsd) || '0';
|
|
@@ -24,9 +24,8 @@ export const isEligibleForEthenaUSDeRewards = (usedAssets) => {
|
|
|
24
24
|
}
|
|
25
25
|
return acc;
|
|
26
26
|
}, new Dec(0)).toString();
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return { isEligible: false, eligibleUSDAmount: '0' }; // must be looped at least once
|
|
27
|
+
if (new Dec(healthRatio).gte(2.5))
|
|
28
|
+
return { isEligible: false, eligibleUSDAmount: '0' }; // health ratio must be below 2.5
|
|
30
29
|
const halfAmountSupplied = new Dec(totalAmountSupplied).div(2).toString();
|
|
31
30
|
const USDeAmountEligibleForRewards = Dec.min(USDeUSDAmountSupplied, halfAmountSupplied).toString(); // rewards are given to amount of USDe supplied up to half of total amount supplied
|
|
32
31
|
return { isEligible: true, eligibleUSDAmount: USDeAmountEligibleForRewards };
|
package/esm/staking/staking.d.ts
CHANGED
|
@@ -3,9 +3,10 @@ import { MMAssetsData, MMUsedAssets } from '../types/common';
|
|
|
3
3
|
export declare const STAKING_ASSETS: string[];
|
|
4
4
|
export declare const getStakingApy: ((asset: string) => Promise<string>) & memoize.Memoized<(asset: string) => Promise<string>>;
|
|
5
5
|
export declare const calculateInterestEarned: (principal: string, interest: string, type: string, apy?: boolean) => number;
|
|
6
|
-
export declare const calculateNetApy: ({ usedAssets, assetsData, }: {
|
|
6
|
+
export declare const calculateNetApy: ({ usedAssets, assetsData, optionalData, }: {
|
|
7
7
|
usedAssets: MMUsedAssets;
|
|
8
8
|
assetsData: MMAssetsData;
|
|
9
|
+
optionalData?: any;
|
|
9
10
|
}) => {
|
|
10
11
|
netApy: string;
|
|
11
12
|
totalInterestUsd: string;
|
package/esm/staking/staking.js
CHANGED
|
@@ -129,7 +129,7 @@ export const calculateInterestEarned = (principal, interest, type, apy = false)
|
|
|
129
129
|
}
|
|
130
130
|
return (+principal * (Math.pow(((1 + (+interest / 100) / BLOCKS_IN_A_YEAR)), (BLOCKS_IN_A_YEAR * interval)))) - +principal; // eslint-disable-line
|
|
131
131
|
};
|
|
132
|
-
export const calculateNetApy = ({ usedAssets, assetsData, }) => {
|
|
132
|
+
export const calculateNetApy = ({ usedAssets, assetsData, optionalData, }) => {
|
|
133
133
|
const sumValues = Object.values(usedAssets).reduce((_acc, usedAsset) => {
|
|
134
134
|
var _a;
|
|
135
135
|
const acc = Object.assign({}, _acc);
|
|
@@ -144,7 +144,7 @@ export const calculateNetApy = ({ usedAssets, assetsData, }) => {
|
|
|
144
144
|
const { apy, eligibilityId } = supplyIncentive;
|
|
145
145
|
const eligibilityCheck = eligibilityId ? EligibilityMapping[eligibilityId] : null;
|
|
146
146
|
if (eligibilityCheck) {
|
|
147
|
-
const { isEligible, eligibleUSDAmount } = eligibilityCheck(usedAssets);
|
|
147
|
+
const { isEligible, eligibleUSDAmount } = eligibilityCheck(usedAssets, optionalData);
|
|
148
148
|
const incentiveInterest = isEligible ? calculateInterestEarned(eligibleUSDAmount, apy, 'year', true) : '0';
|
|
149
149
|
acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
|
|
150
150
|
}
|
|
@@ -164,7 +164,7 @@ export const calculateNetApy = ({ usedAssets, assetsData, }) => {
|
|
|
164
164
|
const { apy, eligibilityId } = borrowIncentive;
|
|
165
165
|
const eligibilityCheck = eligibilityId ? EligibilityMapping[eligibilityId] : null;
|
|
166
166
|
if (eligibilityCheck) {
|
|
167
|
-
const { isEligible, eligibleUSDAmount } = eligibilityCheck(usedAssets);
|
|
167
|
+
const { isEligible, eligibleUSDAmount } = eligibilityCheck(usedAssets, optionalData);
|
|
168
168
|
const incentiveInterest = isEligible ? calculateInterestEarned(eligibleUSDAmount, apy, 'year', true) : '0';
|
|
169
169
|
acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
|
|
170
170
|
}
|