@defisaver/positions-sdk 2.1.127-midnight-13-dev → 2.1.127-midnight-15-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/aaveV3/merkl.js +10 -9
- package/cjs/aaveV4/merkl.js +5 -6
- package/cjs/claiming/aaveV3.d.ts +2 -1
- package/cjs/claiming/aaveV3.js +13 -4
- package/cjs/compoundV3/index.d.ts +1 -0
- package/cjs/compoundV3/index.js +8 -2
- package/cjs/compoundV3/merkl.d.ts +16 -0
- package/cjs/compoundV3/merkl.js +77 -0
- package/cjs/fluid/index.d.ts +9 -0
- package/cjs/fluid/index.js +36 -10
- package/cjs/fluid/merkl.d.ts +32 -0
- package/cjs/fluid/merkl.js +103 -0
- package/cjs/helpers/fluidHelpers/index.d.ts +3 -1
- package/cjs/helpers/fluidHelpers/index.js +37 -4
- package/cjs/helpers/liquityV2Helpers/index.d.ts +2 -1
- package/cjs/helpers/liquityV2Helpers/index.js +3 -2
- package/cjs/helpers/morphoMidnightHelpers/headroom.d.ts +48 -0
- package/cjs/helpers/morphoMidnightHelpers/headroom.js +52 -0
- package/cjs/helpers/morphoMidnightHelpers/index.d.ts +2 -1
- package/cjs/helpers/morphoMidnightHelpers/index.js +10 -6
- package/cjs/liquityV2/index.js +3 -4
- package/cjs/moneymarket/moneymarketCommonService.js +2 -0
- package/cjs/morphoBlue/index.d.ts +1 -0
- package/cjs/morphoBlue/index.js +16 -10
- package/cjs/morphoBlue/merkl.d.ts +35 -0
- package/cjs/morphoBlue/merkl.js +102 -0
- package/cjs/morphoMidnight/index.js +22 -25
- package/cjs/portfolio/index.js +5 -5
- package/cjs/services/merkl.d.ts +6 -0
- package/cjs/services/merkl.js +39 -0
- package/cjs/staking/eligibility.d.ts +4 -0
- package/cjs/staking/eligibility.js +11 -1
- package/cjs/types/claiming.d.ts +12 -1
- package/cjs/types/claiming.js +2 -0
- package/cjs/types/common.d.ts +6 -1
- package/cjs/types/common.js +6 -1
- package/cjs/types/fluid.d.ts +2 -0
- package/cjs/types/liquityV2.d.ts +3 -0
- package/cjs/types/merkl.d.ts +8 -0
- package/cjs/types/morphoMidnight.d.ts +1 -4
- package/cjs/types/morphoMidnight.js +0 -3
- package/esm/aaveV3/merkl.js +11 -10
- package/esm/aaveV4/merkl.js +5 -6
- package/esm/claiming/aaveV3.d.ts +2 -1
- package/esm/claiming/aaveV3.js +12 -4
- package/esm/compoundV3/index.d.ts +1 -0
- package/esm/compoundV3/index.js +5 -1
- package/esm/compoundV3/merkl.d.ts +16 -0
- package/esm/compoundV3/merkl.js +72 -0
- package/esm/fluid/index.d.ts +9 -0
- package/esm/fluid/index.js +31 -9
- package/esm/fluid/merkl.d.ts +32 -0
- package/esm/fluid/merkl.js +95 -0
- package/esm/helpers/fluidHelpers/index.d.ts +3 -1
- package/esm/helpers/fluidHelpers/index.js +38 -6
- package/esm/helpers/liquityV2Helpers/index.d.ts +2 -1
- package/esm/helpers/liquityV2Helpers/index.js +3 -2
- package/esm/helpers/morphoMidnightHelpers/headroom.d.ts +48 -0
- package/esm/helpers/morphoMidnightHelpers/headroom.js +45 -0
- package/esm/helpers/morphoMidnightHelpers/index.d.ts +2 -1
- package/esm/helpers/morphoMidnightHelpers/index.js +7 -4
- package/esm/liquityV2/index.js +3 -4
- package/esm/moneymarket/moneymarketCommonService.js +2 -0
- package/esm/morphoBlue/index.d.ts +1 -0
- package/esm/morphoBlue/index.js +11 -9
- package/esm/morphoBlue/merkl.d.ts +35 -0
- package/esm/morphoBlue/merkl.js +96 -0
- package/esm/morphoMidnight/index.js +23 -26
- package/esm/portfolio/index.js +6 -6
- package/esm/services/merkl.d.ts +6 -0
- package/esm/services/merkl.js +35 -0
- package/esm/staking/eligibility.d.ts +4 -0
- package/esm/staking/eligibility.js +9 -0
- package/esm/types/claiming.d.ts +12 -1
- package/esm/types/claiming.js +2 -0
- package/esm/types/common.d.ts +6 -1
- package/esm/types/common.js +5 -0
- package/esm/types/fluid.d.ts +2 -0
- package/esm/types/liquityV2.d.ts +3 -0
- package/esm/types/merkl.d.ts +8 -0
- package/esm/types/morphoMidnight.d.ts +1 -4
- package/esm/types/morphoMidnight.js +0 -3
- package/package.json +1 -1
- package/src/aaveV3/merkl.ts +7 -7
- package/src/aaveV4/merkl.ts +5 -5
- package/src/claiming/aaveV3.ts +19 -7
- package/src/compoundV3/index.ts +6 -1
- package/src/compoundV3/merkl.ts +76 -0
- package/src/fluid/index.ts +37 -9
- package/src/fluid/merkl.ts +102 -0
- package/src/helpers/fluidHelpers/index.ts +68 -6
- package/src/helpers/liquityV2Helpers/index.ts +4 -1
- package/src/helpers/morphoMidnightHelpers/headroom.ts +82 -0
- package/src/helpers/morphoMidnightHelpers/index.ts +11 -7
- package/src/liquityV2/index.ts +4 -3
- package/src/moneymarket/moneymarketCommonService.ts +2 -0
- package/src/morphoBlue/index.ts +24 -9
- package/src/morphoBlue/merkl.ts +121 -0
- package/src/morphoMidnight/index.ts +25 -27
- package/src/portfolio/index.ts +6 -6
- package/src/services/merkl.ts +31 -0
- package/src/staking/eligibility.ts +10 -0
- package/src/types/claiming.ts +13 -0
- package/src/types/common.ts +6 -0
- package/src/types/fluid.ts +3 -1
- package/src/types/liquityV2.ts +3 -0
- package/src/types/merkl.ts +6 -0
- package/src/types/morphoMidnight.ts +0 -3
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { aprToApy } from '../moneymarket';
|
|
2
|
+
import { fetchAllMerklOpportunities } from '../services/merkl';
|
|
3
|
+
import {
|
|
4
|
+
IncentiveData,
|
|
5
|
+
IncentiveKind,
|
|
6
|
+
MerklOpportunity,
|
|
7
|
+
MorphoBlueMarketData,
|
|
8
|
+
MorphoBlueMarketInfo,
|
|
9
|
+
NetworkNumber,
|
|
10
|
+
OpportunityStatus,
|
|
11
|
+
} from '../types';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Merkl tags Morpho Blue market-level reward campaigns via the opportunity `type` field:
|
|
15
|
+
* - MORPHOSUPPLY → reward for supplying the market's loan asset
|
|
16
|
+
* - MORPHOCOLLATERAL → reward for depositing the market's collateral asset
|
|
17
|
+
* - MORPHOBORROW → reward for borrowing the market's loan asset
|
|
18
|
+
* (MORPHOVAULT/ERC20LOGPROCESSOR are MetaMorpho vault campaigns and MORPHOSUPPLY_SINGLETOKEN is
|
|
19
|
+
* token-wide rather than market-scoped, so none of them belong on per-market data.)
|
|
20
|
+
*
|
|
21
|
+
* A campaign identifies its market via `identifier` — the first 20 bytes of the 32-byte Morpho
|
|
22
|
+
* market id, formatted as a checksummed address. Whitelist-gated campaigns append a marker to that
|
|
23
|
+
* identifier (e.g. `0x54cf…c46WHITELIST_CAMPAIGN`); their rewards only accrue to whitelisted
|
|
24
|
+
* addresses, so they are skipped rather than advertised to every user.
|
|
25
|
+
*/
|
|
26
|
+
export enum MorphoBlueMerklOpportunityType {
|
|
27
|
+
Supply = 'MORPHOSUPPLY',
|
|
28
|
+
Collateral = 'MORPHOCOLLATERAL',
|
|
29
|
+
Borrow = 'MORPHOBORROW',
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const MERKL_DESCRIPTION_MARKER = 'through Merkl';
|
|
33
|
+
|
|
34
|
+
// '0x' + first 20 bytes of the market id
|
|
35
|
+
const MARKET_ID_PREFIX_LENGTH = 42;
|
|
36
|
+
|
|
37
|
+
const buildMerklIncentive = (opportunity: MerklOpportunity): IncentiveData => {
|
|
38
|
+
const token = opportunity.rewardsRecord?.breakdowns?.[0]?.token?.symbol || opportunity.tokens?.[0]?.symbol || '';
|
|
39
|
+
return {
|
|
40
|
+
apy: aprToApy(opportunity.apr),
|
|
41
|
+
token,
|
|
42
|
+
incentiveKind: IncentiveKind.Reward,
|
|
43
|
+
description: `Eligible for ${token} rewards through Merkl.${opportunity.description ? `\n${opportunity.description}` : ''}`,
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const withoutMerklIncentives = (incentives: IncentiveData[] = []) => incentives
|
|
48
|
+
.filter(({ description }) => !description?.includes(MERKL_DESCRIPTION_MARKER));
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Appends the given live Merkl campaigns for the market to its `assetsData` incentive arrays
|
|
52
|
+
* (collateral supply / loan supply / loan borrow). Existing Merkl incentives are replaced rather
|
|
53
|
+
* than duplicated, so re-applying on refreshed data is safe.
|
|
54
|
+
*/
|
|
55
|
+
export const addMorphoBlueMerklOpportunitiesToMarketInfo = (
|
|
56
|
+
marketInfo: MorphoBlueMarketInfo,
|
|
57
|
+
selectedMarket: MorphoBlueMarketData,
|
|
58
|
+
chainId: NetworkNumber,
|
|
59
|
+
opportunities: MerklOpportunity[],
|
|
60
|
+
): MorphoBlueMarketInfo => {
|
|
61
|
+
const marketIdPrefix = (selectedMarket.marketId || '').slice(0, MARKET_ID_PREFIX_LENGTH).toLowerCase();
|
|
62
|
+
const collateralAsset = marketInfo.assetsData[marketInfo.collateralToken];
|
|
63
|
+
const loanAsset = marketInfo.assetsData[marketInfo.loanToken];
|
|
64
|
+
if (marketIdPrefix.length !== MARKET_ID_PREFIX_LENGTH || !collateralAsset || !loanAsset) return marketInfo;
|
|
65
|
+
|
|
66
|
+
const relevant = opportunities.filter((o) => o.chainId === chainId
|
|
67
|
+
&& o.status === OpportunityStatus.LIVE
|
|
68
|
+
&& Object.values(MorphoBlueMerklOpportunityType).includes(o.type as MorphoBlueMerklOpportunityType)
|
|
69
|
+
// a suffixed identifier marks a whitelist-gated campaign — skip those
|
|
70
|
+
&& o.identifier?.length === MARKET_ID_PREFIX_LENGTH
|
|
71
|
+
&& o.identifier.toLowerCase() === marketIdPrefix);
|
|
72
|
+
if (!relevant.length) return marketInfo;
|
|
73
|
+
|
|
74
|
+
const incentivesByType = (type: MorphoBlueMerklOpportunityType) => relevant.filter((o) => o.type === type).map(buildMerklIncentive);
|
|
75
|
+
const collateralSupply = incentivesByType(MorphoBlueMerklOpportunityType.Collateral);
|
|
76
|
+
const loanSupply = incentivesByType(MorphoBlueMerklOpportunityType.Supply);
|
|
77
|
+
const loanBorrow = incentivesByType(MorphoBlueMerklOpportunityType.Borrow);
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
...marketInfo,
|
|
81
|
+
assetsData: {
|
|
82
|
+
...marketInfo.assetsData,
|
|
83
|
+
[marketInfo.collateralToken]: {
|
|
84
|
+
...collateralAsset,
|
|
85
|
+
supplyIncentives: [...withoutMerklIncentives(collateralAsset.supplyIncentives), ...collateralSupply],
|
|
86
|
+
},
|
|
87
|
+
[marketInfo.loanToken]: {
|
|
88
|
+
...loanAsset,
|
|
89
|
+
supplyIncentives: [...withoutMerklIncentives(loanAsset.supplyIncentives), ...loanSupply],
|
|
90
|
+
borrowIncentives: [...withoutMerklIncentives(loanAsset.borrowIncentives), ...loanBorrow],
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Fetches live market-scoped Morpho Blue campaigns for all chains. Never throws — on any failure
|
|
98
|
+
* it returns an empty list, so Merkl being down can't break market data.
|
|
99
|
+
*/
|
|
100
|
+
export const getMorphoBlueMerklOpportunities = async (): Promise<MerklOpportunity[]> => {
|
|
101
|
+
try {
|
|
102
|
+
return await fetchAllMerklOpportunities({
|
|
103
|
+
mainProtocolId: 'morpho',
|
|
104
|
+
type: Object.values(MorphoBlueMerklOpportunityType).join(','),
|
|
105
|
+
status: OpportunityStatus.LIVE,
|
|
106
|
+
});
|
|
107
|
+
} catch (e) {
|
|
108
|
+
console.error('Failed to fetch Morpho Blue Merkl campaigns', e);
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Fetches live Merkl campaigns and appends the ones for the market to its `assetsData` incentive
|
|
115
|
+
* arrays. Never throws — on any failure the market info is returned unchanged.
|
|
116
|
+
*/
|
|
117
|
+
export const addMorphoBlueMerklRewardsToMarketInfo = async (
|
|
118
|
+
marketInfo: MorphoBlueMarketInfo,
|
|
119
|
+
selectedMarket: MorphoBlueMarketData,
|
|
120
|
+
network: NetworkNumber,
|
|
121
|
+
): Promise<MorphoBlueMarketInfo> => addMorphoBlueMerklOpportunitiesToMarketInfo(marketInfo, selectedMarket, network, await getMorphoBlueMerklOpportunities());
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
import { USD_QUOTE } from '../constants';
|
|
14
14
|
import { calculateNetApy } from '../staking';
|
|
15
15
|
import { isMainnetNetwork, wethToEth } from '../services/utils';
|
|
16
|
-
import { getMorphoMidnightAggregatedPositionData, getMorphoMidnightUserBorrowInfo
|
|
16
|
+
import { getMorphoMidnightAggregatedPositionData, getMorphoMidnightUserBorrowInfo } from '../helpers/morphoMidnightHelpers';
|
|
17
17
|
import { getChainlinkAssetAddress } from '../services/priceService';
|
|
18
18
|
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
19
19
|
|
|
@@ -166,34 +166,32 @@ export async function _getMorphoMidnightAccountData(provider: Client, network: N
|
|
|
166
166
|
let borrowInfoStatus = MorphoMidnightBorrowInfoStatus.Available;
|
|
167
167
|
let assetsDataForApy = marketInfo.assetsData;
|
|
168
168
|
if (new Dec(positionInfo.debt.toString()).gt(0)) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
// No entry for the position: the API does not know it yet, rather than it having no principal.
|
|
191
|
-
borrowInfoStatus = MorphoMidnightBorrowInfoStatus.Pending;
|
|
192
|
-
}
|
|
193
|
-
} catch (err) {
|
|
194
|
-
// Positions API unreachable — the fallback above still renders, and the next call may succeed.
|
|
169
|
+
try {
|
|
170
|
+
// Curator-agnostic: `/users/:account/positions` is indexed off the Midnight singleton, so it carries
|
|
171
|
+
// Tenor-curated markets too. Only the *book* differs by curator, and that is quoted elsewhere.
|
|
172
|
+
const borrowInfo = await getMorphoMidnightUserBorrowInfo(account, marketId, marketInfo.loanToken);
|
|
173
|
+
if (new Dec(borrowInfo.debtTotal).gt(0)) {
|
|
174
|
+
borrowRate = borrowInfo.borrowRate;
|
|
175
|
+
debtBase = borrowInfo.debtBase;
|
|
176
|
+
debtInterest = borrowInfo.debtInterest;
|
|
177
|
+
usedAssets[marketInfo.loanToken].borrowRate = borrowRate;
|
|
178
|
+
// Reflect the real borrow cost in netApy without mutating the shared marketInfo.assetsData.
|
|
179
|
+
assetsDataForApy = {
|
|
180
|
+
...marketInfo.assetsData,
|
|
181
|
+
[marketInfo.loanToken]: { ...loanTokenData, borrowRate },
|
|
182
|
+
};
|
|
183
|
+
const describesChainDebt = new Dec(borrowInfo.debtTotal).eq(debt);
|
|
184
|
+
const ratePriced = new Dec(borrowRate).gt(0) || new Dec(debtInterest).lte(0);
|
|
185
|
+
borrowInfoStatus = describesChainDebt && ratePriced
|
|
186
|
+
? MorphoMidnightBorrowInfoStatus.Available
|
|
187
|
+
: MorphoMidnightBorrowInfoStatus.Pending;
|
|
188
|
+
} else {
|
|
189
|
+
// No entry for the position: the API does not know it yet, rather than it having no principal.
|
|
195
190
|
borrowInfoStatus = MorphoMidnightBorrowInfoStatus.Pending;
|
|
196
191
|
}
|
|
192
|
+
} catch (err) {
|
|
193
|
+
// Positions API unreachable — the fallback above still renders, and the next call may succeed.
|
|
194
|
+
borrowInfoStatus = MorphoMidnightBorrowInfoStatus.Pending;
|
|
197
195
|
}
|
|
198
196
|
}
|
|
199
197
|
|
package/src/portfolio/index.ts
CHANGED
|
@@ -44,7 +44,7 @@ import { _getLiquityTroveInfo, getLiquityStakingData } from '../liquity';
|
|
|
44
44
|
import { _getLiquityV2MarketData, getLiquitySAndYBold, getLiquityV2Staking } from '../liquityV2';
|
|
45
45
|
import { _getAllUserEarnPositionsWithFTokens, _getUserPositionsPortfolio } from '../fluid';
|
|
46
46
|
import { getUmbrellaData } from '../umbrella';
|
|
47
|
-
import {
|
|
47
|
+
import { getMerklUnclaimedRewards, getUnclaimedRewardsForAllMarkets } from '../claiming/aaveV3';
|
|
48
48
|
import { getCompoundV3Rewards } from '../claiming/compV3';
|
|
49
49
|
import { fetchSparkAirdropRewards, fetchSparkRewards } from '../claiming/spark';
|
|
50
50
|
import { getKingRewards } from '../claiming/king';
|
|
@@ -151,7 +151,7 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
151
151
|
};
|
|
152
152
|
|
|
153
153
|
rewardsData[address.toLowerCase() as EthAddress] = {
|
|
154
|
-
|
|
154
|
+
merkl: {},
|
|
155
155
|
aaveV3: {},
|
|
156
156
|
compV3: {},
|
|
157
157
|
spark: {},
|
|
@@ -364,11 +364,11 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
364
364
|
})).flat(),
|
|
365
365
|
...addresses.map(async (address) => {
|
|
366
366
|
try {
|
|
367
|
-
const
|
|
368
|
-
rewardsData[address.toLowerCase() as EthAddress].
|
|
367
|
+
const merklData = await getMerklUnclaimedRewards(address, network);
|
|
368
|
+
rewardsData[address.toLowerCase() as EthAddress].merkl = { error: '', data: merklData };
|
|
369
369
|
} catch (error) {
|
|
370
|
-
console.error(`Error fetching
|
|
371
|
-
rewardsData[address.toLowerCase() as EthAddress].
|
|
370
|
+
console.error(`Error fetching Merkl rewards data for address ${address}:`, error);
|
|
371
|
+
rewardsData[address.toLowerCase() as EthAddress].merkl = { error: `Error fetching Merkl rewards data for address ${address}`, data: null };
|
|
372
372
|
}
|
|
373
373
|
}),
|
|
374
374
|
...aaveV3Markets.map(market => addresses.map(async (address) => {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { MerklOpportunity } from '../types';
|
|
2
|
+
import { LONGER_TIMEOUT } from './utils';
|
|
3
|
+
|
|
4
|
+
const MERKL_OPPORTUNITIES_URL = 'https://fe.defisaver.com/api/merkl/opportunities';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Fetches every page matching the query. Merkl returns 20 opportunities by default, so omitting
|
|
8
|
+
* `items` and advancing `page` avoids imposing a client-side maximum on the result set.
|
|
9
|
+
*/
|
|
10
|
+
export const fetchAllMerklOpportunities = async (query: Record<string, string>): Promise<MerklOpportunity[]> => {
|
|
11
|
+
const opportunities: MerklOpportunity[] = [];
|
|
12
|
+
let page = 0;
|
|
13
|
+
let pageOpportunities: MerklOpportunity[];
|
|
14
|
+
|
|
15
|
+
do {
|
|
16
|
+
const searchParams = new URLSearchParams({ ...query, page: page.toString() });
|
|
17
|
+
const res = await fetch(`${MERKL_OPPORTUNITIES_URL}?${searchParams}`, { // eslint-disable-line no-await-in-loop
|
|
18
|
+
signal: AbortSignal.timeout(LONGER_TIMEOUT),
|
|
19
|
+
});
|
|
20
|
+
if (!res.ok) throw new Error(`Failed to fetch Merkl opportunities page ${page}`);
|
|
21
|
+
|
|
22
|
+
const data = await res.json(); // eslint-disable-line no-await-in-loop
|
|
23
|
+
if (!Array.isArray(data)) throw new Error(`Invalid Merkl opportunities response on page ${page}`);
|
|
24
|
+
|
|
25
|
+
pageOpportunities = data as MerklOpportunity[];
|
|
26
|
+
opportunities.push(...pageOpportunities);
|
|
27
|
+
page += 1;
|
|
28
|
+
} while (pageOpportunities.length > 0);
|
|
29
|
+
|
|
30
|
+
return opportunities;
|
|
31
|
+
};
|
|
@@ -97,10 +97,20 @@ export const isEligibleForAaveV3ArbitrumETHLSBorrow = (usedAssets: MMUsedAssets)
|
|
|
97
97
|
return { isEligible: true, eligibleUSDAmount: ETHAmountBorrowed };
|
|
98
98
|
};
|
|
99
99
|
|
|
100
|
+
// "Borrow WETH with pufETH collateral" — rewards are calculated as min(collateral * 80% LTV, borrow amount)
|
|
101
|
+
export const isEligibleForCompoundV3PufEthWethBorrow = (usedAssets: MMUsedAssets) => {
|
|
102
|
+
const collateralUsd = usedAssets.pufETH?.suppliedUsd || '0';
|
|
103
|
+
const borrowedUsd = usedAssets.ETH?.borrowedUsd || '0';
|
|
104
|
+
const eligibleUSDAmount = Dec.min(new Dec(collateralUsd).mul('0.8'), borrowedUsd).toString();
|
|
105
|
+
|
|
106
|
+
return { isEligible: new Dec(eligibleUSDAmount).gt(0), eligibleUSDAmount };
|
|
107
|
+
};
|
|
108
|
+
|
|
100
109
|
export const EligibilityMapping: { [key in IncentiveEligibilityId]: (usedAssets: MMUsedAssets, optionalData: any) => { isEligible: boolean; eligibleUSDAmount: string } } = {
|
|
101
110
|
[IncentiveEligibilityId.AaveV3EthenaLiquidLeverage]: isEligibleForEthenaUSDeRewards,
|
|
102
111
|
[IncentiveEligibilityId.AaveV3ArbitrumEthSupply]: isEligibleForAaveV3ArbitrumEthSupply,
|
|
103
112
|
[IncentiveEligibilityId.AaveV3ArbitrumETHLSBorrow]: isEligibleForAaveV3ArbitrumETHLSBorrow,
|
|
104
113
|
[IncentiveEligibilityId.AaveV3EthenaLiquidLeveragePlasma]: isEligibleForEthenaUSDeRewards,
|
|
105
114
|
[IncentiveEligibilityId.AaveV3EthenaLiquidLeveragePlasmaGHO]: isEligibleForEthenaGHORewards,
|
|
115
|
+
[IncentiveEligibilityId.CompoundV3PufEthWethBorrow]: isEligibleForCompoundV3PufEthWethBorrow,
|
|
106
116
|
};
|
package/src/types/claiming.ts
CHANGED
|
@@ -5,6 +5,8 @@ export enum ClaimType {
|
|
|
5
5
|
AAVE_REWARDS = 'AAVE_REWARDS',
|
|
6
6
|
/** Merit rewards from AAVE (various tokens) */
|
|
7
7
|
AAVE_MERIT_REWARDS = 'AAVE_MERIT_REWARDS',
|
|
8
|
+
/** Rewards distributed through Merkl across supported protocols */
|
|
9
|
+
MERKL_REWARDS = 'MERKL_REWARDS',
|
|
8
10
|
/** Rewards from Compound V3 (only in COMP) */
|
|
9
11
|
COMPOUND_V3_COMP = 'COMPOUND_V3_COMP',
|
|
10
12
|
/** Rewards from Spark (wstETH only for now) */
|
|
@@ -47,6 +49,16 @@ export type AaveMeritRewardsClaimableToken = _ClaimableTokenPartial & {
|
|
|
47
49
|
};
|
|
48
50
|
};
|
|
49
51
|
|
|
52
|
+
export type MerklRewardsClaimableToken = _ClaimableTokenPartial & {
|
|
53
|
+
claimType: ClaimType.MERKL_REWARDS;
|
|
54
|
+
additionalClaimFields: {
|
|
55
|
+
accumulated: string;
|
|
56
|
+
proof: string[];
|
|
57
|
+
decimals: string;
|
|
58
|
+
unclaimed: string;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
50
62
|
export type SparkRewardsClaimableToken = _ClaimableTokenPartial & {
|
|
51
63
|
claimType: ClaimType.SPARK_REWARDS;
|
|
52
64
|
additionalClaimFields: {
|
|
@@ -102,6 +114,7 @@ export type UniswapAirdropClaimableToken = _ClaimableTokenPartial & {
|
|
|
102
114
|
export type ClaimableToken =
|
|
103
115
|
AaveRewardsClaimableToken
|
|
104
116
|
| AaveMeritRewardsClaimableToken
|
|
117
|
+
| MerklRewardsClaimableToken
|
|
105
118
|
| CompoundV3CompClaimableToken
|
|
106
119
|
| SparkRewardsClaimableToken
|
|
107
120
|
| KingRewardsClaimableToken
|
package/src/types/common.ts
CHANGED
|
@@ -8,12 +8,17 @@ export enum IncentiveSide {
|
|
|
8
8
|
Borrow = 'borrow',
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
export enum IncentiveSource {
|
|
12
|
+
Merkl = 'merkl',
|
|
13
|
+
}
|
|
14
|
+
|
|
11
15
|
export enum IncentiveEligibilityId {
|
|
12
16
|
AaveV3EthenaLiquidLeverage = '0x0dC599DBB180E64E42b87332FDeC3a551445ea44BORROW_BL',
|
|
13
17
|
AaveV3ArbitrumEthSupply = '0x5d16261c6715a653248269861bbacf68a9774cde',
|
|
14
18
|
AaveV3ArbitrumETHLSBorrow = '0x0c84331e39d6658Cd6e6b9ba04736cC4c4734351',
|
|
15
19
|
AaveV3EthenaLiquidLeveragePlasma = '0x2E8f1FA9c73F9d975B46BDFe40C92b6dDEFA3f31BORROW_BL',
|
|
16
20
|
AaveV3EthenaLiquidLeveragePlasmaGHO = '2b2f6fefcd3df634',
|
|
21
|
+
CompoundV3PufEthWethBorrow = 'e6e49b79e83041f9',
|
|
17
22
|
}
|
|
18
23
|
|
|
19
24
|
export enum LeverageType {
|
|
@@ -28,6 +33,7 @@ export interface IncentiveData {
|
|
|
28
33
|
token: string,
|
|
29
34
|
apy: string,
|
|
30
35
|
incentiveKind?: IncentiveKind;
|
|
36
|
+
source?: IncentiveSource;
|
|
31
37
|
description?: string;
|
|
32
38
|
eligibilityId?: IncentiveEligibilityId;
|
|
33
39
|
}
|
package/src/types/fluid.ts
CHANGED
|
@@ -340,6 +340,8 @@ export interface FluidAggregatedVaultData {
|
|
|
340
340
|
leftToBorrowUsd: string,
|
|
341
341
|
netApy: string,
|
|
342
342
|
incentiveUsd: string,
|
|
343
|
+
merklSupplyIncentives: IncentiveData[],
|
|
344
|
+
merklBorrowIncentives: IncentiveData[],
|
|
343
345
|
ratio: string,
|
|
344
346
|
collRatio: string,
|
|
345
347
|
minRatio: string,
|
|
@@ -484,4 +486,4 @@ export interface FluidFTokenDataStructOutput {
|
|
|
484
486
|
supplyRate: bigint;
|
|
485
487
|
rewardsRate: bigint;
|
|
486
488
|
withdrawable: bigint;
|
|
487
|
-
}
|
|
489
|
+
}
|
package/src/types/liquityV2.ts
CHANGED
|
@@ -94,6 +94,7 @@ export interface LiquityV2AggregatedTroveData {
|
|
|
94
94
|
suppliedUsd: string,
|
|
95
95
|
borrowedUsd: string,
|
|
96
96
|
borrowLimitUsd: string,
|
|
97
|
+
liquidationLimitUsd: string,
|
|
97
98
|
leftToBorrowUsd: string,
|
|
98
99
|
netApy: string,
|
|
99
100
|
incentiveUsd: string,
|
|
@@ -112,9 +113,11 @@ export interface LiquityV2TroveData {
|
|
|
112
113
|
ratio: string,
|
|
113
114
|
collRatio: string,
|
|
114
115
|
liqRatio: string,
|
|
116
|
+
borrowLimitRatio: string,
|
|
115
117
|
interestRate: string,
|
|
116
118
|
leftToBorrowUsd: string,
|
|
117
119
|
borrowLimitUsd: string,
|
|
120
|
+
liquidationLimitUsd: string,
|
|
118
121
|
suppliedUsd: string,
|
|
119
122
|
borrowedUsd: string,
|
|
120
123
|
netApy: string,
|
package/src/types/merkl.ts
CHANGED
|
@@ -72,6 +72,12 @@ export type MerkleRewardMap = Record<EthAddress, { supply?: MerkleRewardInfo; bo
|
|
|
72
72
|
|
|
73
73
|
export type AaveV4MerklScopedReward = { [side in IncentiveSide]?: IncentiveData };
|
|
74
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Fluid vault-scoped Merkl campaigns keyed by lowercase vault address — `supply` rewards apply to
|
|
77
|
+
* the vault's collateral side, `borrow` rewards to its debt side.
|
|
78
|
+
*/
|
|
79
|
+
export type FluidMerklRewardMap = Record<string, { supply: IncentiveData[], borrow: IncentiveData[] }>;
|
|
80
|
+
|
|
75
81
|
/**
|
|
76
82
|
* Aave V4 Merkl reward campaigns split by scope:
|
|
77
83
|
* - `hub`: keyed by `${hubAddress}_${underlyingAddress}` (both lowercase) — rewards for supplying/borrowing via a hub
|
|
@@ -142,13 +142,10 @@ export interface MorphoMidnightAggregatedPositionData {
|
|
|
142
142
|
* - `Pending` — the indexer has not caught up with the chain yet: it does not know the position, or its
|
|
143
143
|
* split describes a different debt. Refetching resolves it; `getMorphoMidnightUserBorrowInfo` failing
|
|
144
144
|
* outright lands here too, since the next call may well succeed.
|
|
145
|
-
* - `Unavailable` — no source covers this market, so refetching changes nothing. See
|
|
146
|
-
* `morphoMidnightMarketReportsBorrowInfo`.
|
|
147
145
|
*/
|
|
148
146
|
export enum MorphoMidnightBorrowInfoStatus {
|
|
149
147
|
Available = 'available',
|
|
150
148
|
Pending = 'pending',
|
|
151
|
-
Unavailable = 'unavailable',
|
|
152
149
|
}
|
|
153
150
|
|
|
154
151
|
// Fixed-rate/YTM (derived from entry price + orderbook) is intentionally absent in MVP:
|