@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,96 @@
|
|
|
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 { aprToApy } from '../moneymarket';
|
|
11
|
+
import { fetchAllMerklOpportunities } from '../services/merkl';
|
|
12
|
+
import { IncentiveKind, OpportunityStatus, } from '../types';
|
|
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 var MorphoBlueMerklOpportunityType;
|
|
27
|
+
(function (MorphoBlueMerklOpportunityType) {
|
|
28
|
+
MorphoBlueMerklOpportunityType["Supply"] = "MORPHOSUPPLY";
|
|
29
|
+
MorphoBlueMerklOpportunityType["Collateral"] = "MORPHOCOLLATERAL";
|
|
30
|
+
MorphoBlueMerklOpportunityType["Borrow"] = "MORPHOBORROW";
|
|
31
|
+
})(MorphoBlueMerklOpportunityType || (MorphoBlueMerklOpportunityType = {}));
|
|
32
|
+
const MERKL_DESCRIPTION_MARKER = 'through Merkl';
|
|
33
|
+
// '0x' + first 20 bytes of the market id
|
|
34
|
+
const MARKET_ID_PREFIX_LENGTH = 42;
|
|
35
|
+
const buildMerklIncentive = (opportunity) => {
|
|
36
|
+
var _a, _b, _c, _d, _e, _f;
|
|
37
|
+
const token = ((_d = (_c = (_b = (_a = opportunity.rewardsRecord) === null || _a === void 0 ? void 0 : _a.breakdowns) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.token) === null || _d === void 0 ? void 0 : _d.symbol) || ((_f = (_e = opportunity.tokens) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.symbol) || '';
|
|
38
|
+
return {
|
|
39
|
+
apy: aprToApy(opportunity.apr),
|
|
40
|
+
token,
|
|
41
|
+
incentiveKind: IncentiveKind.Reward,
|
|
42
|
+
description: `Eligible for ${token} rewards through Merkl.${opportunity.description ? `\n${opportunity.description}` : ''}`,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
const withoutMerklIncentives = (incentives = []) => incentives
|
|
46
|
+
.filter(({ description }) => !(description === null || description === void 0 ? void 0 : description.includes(MERKL_DESCRIPTION_MARKER)));
|
|
47
|
+
/**
|
|
48
|
+
* Appends the given live Merkl campaigns for the market to its `assetsData` incentive arrays
|
|
49
|
+
* (collateral supply / loan supply / loan borrow). Existing Merkl incentives are replaced rather
|
|
50
|
+
* than duplicated, so re-applying on refreshed data is safe.
|
|
51
|
+
*/
|
|
52
|
+
export const addMorphoBlueMerklOpportunitiesToMarketInfo = (marketInfo, selectedMarket, chainId, opportunities) => {
|
|
53
|
+
const marketIdPrefix = (selectedMarket.marketId || '').slice(0, MARKET_ID_PREFIX_LENGTH).toLowerCase();
|
|
54
|
+
const collateralAsset = marketInfo.assetsData[marketInfo.collateralToken];
|
|
55
|
+
const loanAsset = marketInfo.assetsData[marketInfo.loanToken];
|
|
56
|
+
if (marketIdPrefix.length !== MARKET_ID_PREFIX_LENGTH || !collateralAsset || !loanAsset)
|
|
57
|
+
return marketInfo;
|
|
58
|
+
const relevant = opportunities.filter((o) => {
|
|
59
|
+
var _a;
|
|
60
|
+
return o.chainId === chainId
|
|
61
|
+
&& o.status === OpportunityStatus.LIVE
|
|
62
|
+
&& Object.values(MorphoBlueMerklOpportunityType).includes(o.type)
|
|
63
|
+
// a suffixed identifier marks a whitelist-gated campaign — skip those
|
|
64
|
+
&& ((_a = o.identifier) === null || _a === void 0 ? void 0 : _a.length) === MARKET_ID_PREFIX_LENGTH
|
|
65
|
+
&& o.identifier.toLowerCase() === marketIdPrefix;
|
|
66
|
+
});
|
|
67
|
+
if (!relevant.length)
|
|
68
|
+
return marketInfo;
|
|
69
|
+
const incentivesByType = (type) => relevant.filter((o) => o.type === type).map(buildMerklIncentive);
|
|
70
|
+
const collateralSupply = incentivesByType(MorphoBlueMerklOpportunityType.Collateral);
|
|
71
|
+
const loanSupply = incentivesByType(MorphoBlueMerklOpportunityType.Supply);
|
|
72
|
+
const loanBorrow = incentivesByType(MorphoBlueMerklOpportunityType.Borrow);
|
|
73
|
+
return Object.assign(Object.assign({}, marketInfo), { assetsData: Object.assign(Object.assign({}, marketInfo.assetsData), { [marketInfo.collateralToken]: Object.assign(Object.assign({}, collateralAsset), { supplyIncentives: [...withoutMerklIncentives(collateralAsset.supplyIncentives), ...collateralSupply] }), [marketInfo.loanToken]: Object.assign(Object.assign({}, loanAsset), { supplyIncentives: [...withoutMerklIncentives(loanAsset.supplyIncentives), ...loanSupply], borrowIncentives: [...withoutMerklIncentives(loanAsset.borrowIncentives), ...loanBorrow] }) }) });
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Fetches live market-scoped Morpho Blue campaigns for all chains. Never throws — on any failure
|
|
77
|
+
* it returns an empty list, so Merkl being down can't break market data.
|
|
78
|
+
*/
|
|
79
|
+
export const getMorphoBlueMerklOpportunities = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
+
try {
|
|
81
|
+
return yield fetchAllMerklOpportunities({
|
|
82
|
+
mainProtocolId: 'morpho',
|
|
83
|
+
type: Object.values(MorphoBlueMerklOpportunityType).join(','),
|
|
84
|
+
status: OpportunityStatus.LIVE,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
console.error('Failed to fetch Morpho Blue Merkl campaigns', e);
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
/**
|
|
93
|
+
* Fetches live Merkl campaigns and appends the ones for the market to its `assetsData` incentive
|
|
94
|
+
* arrays. Never throws — on any failure the market info is returned unchanged.
|
|
95
|
+
*/
|
|
96
|
+
export const addMorphoBlueMerklRewardsToMarketInfo = (marketInfo, selectedMarket, network) => __awaiter(void 0, void 0, void 0, function* () { return addMorphoBlueMerklOpportunitiesToMarketInfo(marketInfo, selectedMarket, network, yield getMorphoBlueMerklOpportunities()); });
|
|
@@ -15,7 +15,7 @@ import { MorphoMidnightBorrowInfoStatus, } from '../types';
|
|
|
15
15
|
import { USD_QUOTE } from '../constants';
|
|
16
16
|
import { calculateNetApy } from '../staking';
|
|
17
17
|
import { isMainnetNetwork, wethToEth } from '../services/utils';
|
|
18
|
-
import { getMorphoMidnightAggregatedPositionData, getMorphoMidnightUserBorrowInfo
|
|
18
|
+
import { getMorphoMidnightAggregatedPositionData, getMorphoMidnightUserBorrowInfo } from '../helpers/morphoMidnightHelpers';
|
|
19
19
|
import { getChainlinkAssetAddress } from '../services/priceService';
|
|
20
20
|
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
21
21
|
const HARDCODED_USD_STABLE_PRICE = '100000000'; // $1 with 8 decimals
|
|
@@ -158,35 +158,32 @@ export function _getMorphoMidnightAccountData(provider, network, account, select
|
|
|
158
158
|
let borrowInfoStatus = MorphoMidnightBorrowInfoStatus.Available;
|
|
159
159
|
let assetsDataForApy = marketInfo.assetsData;
|
|
160
160
|
if (new Dec(positionInfo.debt.toString()).gt(0)) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
? MorphoMidnightBorrowInfoStatus.Available
|
|
178
|
-
: MorphoMidnightBorrowInfoStatus.Pending;
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
// No entry for the position: the API does not know it yet, rather than it having no principal.
|
|
182
|
-
borrowInfoStatus = MorphoMidnightBorrowInfoStatus.Pending;
|
|
183
|
-
}
|
|
161
|
+
try {
|
|
162
|
+
// Curator-agnostic: `/users/:account/positions` is indexed off the Midnight singleton, so it carries
|
|
163
|
+
// Tenor-curated markets too. Only the *book* differs by curator, and that is quoted elsewhere.
|
|
164
|
+
const borrowInfo = yield getMorphoMidnightUserBorrowInfo(account, marketId, marketInfo.loanToken);
|
|
165
|
+
if (new Dec(borrowInfo.debtTotal).gt(0)) {
|
|
166
|
+
borrowRate = borrowInfo.borrowRate;
|
|
167
|
+
debtBase = borrowInfo.debtBase;
|
|
168
|
+
debtInterest = borrowInfo.debtInterest;
|
|
169
|
+
usedAssets[marketInfo.loanToken].borrowRate = borrowRate;
|
|
170
|
+
// Reflect the real borrow cost in netApy without mutating the shared marketInfo.assetsData.
|
|
171
|
+
assetsDataForApy = Object.assign(Object.assign({}, marketInfo.assetsData), { [marketInfo.loanToken]: Object.assign(Object.assign({}, loanTokenData), { borrowRate }) });
|
|
172
|
+
const describesChainDebt = new Dec(borrowInfo.debtTotal).eq(debt);
|
|
173
|
+
const ratePriced = new Dec(borrowRate).gt(0) || new Dec(debtInterest).lte(0);
|
|
174
|
+
borrowInfoStatus = describesChainDebt && ratePriced
|
|
175
|
+
? MorphoMidnightBorrowInfoStatus.Available
|
|
176
|
+
: MorphoMidnightBorrowInfoStatus.Pending;
|
|
184
177
|
}
|
|
185
|
-
|
|
186
|
-
//
|
|
178
|
+
else {
|
|
179
|
+
// No entry for the position: the API does not know it yet, rather than it having no principal.
|
|
187
180
|
borrowInfoStatus = MorphoMidnightBorrowInfoStatus.Pending;
|
|
188
181
|
}
|
|
189
182
|
}
|
|
183
|
+
catch (err) {
|
|
184
|
+
// Positions API unreachable — the fallback above still renders, and the next call may succeed.
|
|
185
|
+
borrowInfoStatus = MorphoMidnightBorrowInfoStatus.Pending;
|
|
186
|
+
}
|
|
190
187
|
}
|
|
191
188
|
return Object.assign({ usedAssets,
|
|
192
189
|
credit,
|
package/esm/portfolio/index.js
CHANGED
|
@@ -27,7 +27,7 @@ import { _getLiquityTroveInfo, getLiquityStakingData } from '../liquity';
|
|
|
27
27
|
import { _getLiquityV2MarketData, getLiquitySAndYBold, getLiquityV2Staking } from '../liquityV2';
|
|
28
28
|
import { _getAllUserEarnPositionsWithFTokens, _getUserPositionsPortfolio } from '../fluid';
|
|
29
29
|
import { getUmbrellaData } from '../umbrella';
|
|
30
|
-
import {
|
|
30
|
+
import { getMerklUnclaimedRewards, getUnclaimedRewardsForAllMarkets } from '../claiming/aaveV3';
|
|
31
31
|
import { getCompoundV3Rewards } from '../claiming/compV3';
|
|
32
32
|
import { fetchSparkAirdropRewards, fetchSparkRewards } from '../claiming/spark';
|
|
33
33
|
import { getKingRewards } from '../claiming/king';
|
|
@@ -120,7 +120,7 @@ export function getPortfolioData(provider_1, network_1, defaultProvider_1, addre
|
|
|
120
120
|
},
|
|
121
121
|
};
|
|
122
122
|
rewardsData[address.toLowerCase()] = {
|
|
123
|
-
|
|
123
|
+
merkl: {},
|
|
124
124
|
aaveV3: {},
|
|
125
125
|
compV3: {},
|
|
126
126
|
spark: {},
|
|
@@ -345,12 +345,12 @@ export function getPortfolioData(provider_1, network_1, defaultProvider_1, addre
|
|
|
345
345
|
}))).flat(),
|
|
346
346
|
...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
347
347
|
try {
|
|
348
|
-
const
|
|
349
|
-
rewardsData[address.toLowerCase()].
|
|
348
|
+
const merklData = yield getMerklUnclaimedRewards(address, network);
|
|
349
|
+
rewardsData[address.toLowerCase()].merkl = { error: '', data: merklData };
|
|
350
350
|
}
|
|
351
351
|
catch (error) {
|
|
352
|
-
console.error(`Error fetching
|
|
353
|
-
rewardsData[address.toLowerCase()].
|
|
352
|
+
console.error(`Error fetching Merkl rewards data for address ${address}:`, error);
|
|
353
|
+
rewardsData[address.toLowerCase()].merkl = { error: `Error fetching Merkl rewards data for address ${address}`, data: null };
|
|
354
354
|
}
|
|
355
355
|
})),
|
|
356
356
|
...aaveV3Markets.map(market => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { MerklOpportunity } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Fetches every page matching the query. Merkl returns 20 opportunities by default, so omitting
|
|
4
|
+
* `items` and advancing `page` avoids imposing a client-side maximum on the result set.
|
|
5
|
+
*/
|
|
6
|
+
export declare const fetchAllMerklOpportunities: (query: Record<string, string>) => Promise<MerklOpportunity[]>;
|
|
@@ -0,0 +1,35 @@
|
|
|
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 { LONGER_TIMEOUT } from './utils';
|
|
11
|
+
const MERKL_OPPORTUNITIES_URL = 'https://fe.defisaver.com/api/merkl/opportunities';
|
|
12
|
+
/**
|
|
13
|
+
* Fetches every page matching the query. Merkl returns 20 opportunities by default, so omitting
|
|
14
|
+
* `items` and advancing `page` avoids imposing a client-side maximum on the result set.
|
|
15
|
+
*/
|
|
16
|
+
export const fetchAllMerklOpportunities = (query) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const opportunities = [];
|
|
18
|
+
let page = 0;
|
|
19
|
+
let pageOpportunities;
|
|
20
|
+
do {
|
|
21
|
+
const searchParams = new URLSearchParams(Object.assign(Object.assign({}, query), { page: page.toString() }));
|
|
22
|
+
const res = yield fetch(`${MERKL_OPPORTUNITIES_URL}?${searchParams}`, {
|
|
23
|
+
signal: AbortSignal.timeout(LONGER_TIMEOUT),
|
|
24
|
+
});
|
|
25
|
+
if (!res.ok)
|
|
26
|
+
throw new Error(`Failed to fetch Merkl opportunities page ${page}`);
|
|
27
|
+
const data = yield res.json(); // eslint-disable-line no-await-in-loop
|
|
28
|
+
if (!Array.isArray(data))
|
|
29
|
+
throw new Error(`Invalid Merkl opportunities response on page ${page}`);
|
|
30
|
+
pageOpportunities = data;
|
|
31
|
+
opportunities.push(...pageOpportunities);
|
|
32
|
+
page += 1;
|
|
33
|
+
} while (pageOpportunities.length > 0);
|
|
34
|
+
return opportunities;
|
|
35
|
+
});
|
|
@@ -19,6 +19,10 @@ export declare const isEligibleForAaveV3ArbitrumETHLSBorrow: (usedAssets: MMUsed
|
|
|
19
19
|
isEligible: boolean;
|
|
20
20
|
eligibleUSDAmount: string;
|
|
21
21
|
};
|
|
22
|
+
export declare const isEligibleForCompoundV3PufEthWethBorrow: (usedAssets: MMUsedAssets) => {
|
|
23
|
+
isEligible: boolean;
|
|
24
|
+
eligibleUSDAmount: string;
|
|
25
|
+
};
|
|
22
26
|
export declare const EligibilityMapping: {
|
|
23
27
|
[key in IncentiveEligibilityId]: (usedAssets: MMUsedAssets, optionalData: any) => {
|
|
24
28
|
isEligible: boolean;
|
|
@@ -60,10 +60,19 @@ export const isEligibleForAaveV3ArbitrumETHLSBorrow = (usedAssets) => {
|
|
|
60
60
|
const ETHAmountBorrowed = ((_a = usedAssets.ETH) === null || _a === void 0 ? void 0 : _a.borrowedUsd) || '0';
|
|
61
61
|
return { isEligible: true, eligibleUSDAmount: ETHAmountBorrowed };
|
|
62
62
|
};
|
|
63
|
+
// "Borrow WETH with pufETH collateral" — rewards are calculated as min(collateral * 80% LTV, borrow amount)
|
|
64
|
+
export const isEligibleForCompoundV3PufEthWethBorrow = (usedAssets) => {
|
|
65
|
+
var _a, _b;
|
|
66
|
+
const collateralUsd = ((_a = usedAssets.pufETH) === null || _a === void 0 ? void 0 : _a.suppliedUsd) || '0';
|
|
67
|
+
const borrowedUsd = ((_b = usedAssets.ETH) === null || _b === void 0 ? void 0 : _b.borrowedUsd) || '0';
|
|
68
|
+
const eligibleUSDAmount = Dec.min(new Dec(collateralUsd).mul('0.8'), borrowedUsd).toString();
|
|
69
|
+
return { isEligible: new Dec(eligibleUSDAmount).gt(0), eligibleUSDAmount };
|
|
70
|
+
};
|
|
63
71
|
export const EligibilityMapping = {
|
|
64
72
|
[IncentiveEligibilityId.AaveV3EthenaLiquidLeverage]: isEligibleForEthenaUSDeRewards,
|
|
65
73
|
[IncentiveEligibilityId.AaveV3ArbitrumEthSupply]: isEligibleForAaveV3ArbitrumEthSupply,
|
|
66
74
|
[IncentiveEligibilityId.AaveV3ArbitrumETHLSBorrow]: isEligibleForAaveV3ArbitrumETHLSBorrow,
|
|
67
75
|
[IncentiveEligibilityId.AaveV3EthenaLiquidLeveragePlasma]: isEligibleForEthenaUSDeRewards,
|
|
68
76
|
[IncentiveEligibilityId.AaveV3EthenaLiquidLeveragePlasmaGHO]: isEligibleForEthenaGHORewards,
|
|
77
|
+
[IncentiveEligibilityId.CompoundV3PufEthWethBorrow]: isEligibleForCompoundV3PufEthWethBorrow,
|
|
69
78
|
};
|
package/esm/types/claiming.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export declare enum ClaimType {
|
|
|
4
4
|
AAVE_REWARDS = "AAVE_REWARDS",
|
|
5
5
|
/** Merit rewards from AAVE (various tokens) */
|
|
6
6
|
AAVE_MERIT_REWARDS = "AAVE_MERIT_REWARDS",
|
|
7
|
+
/** Rewards distributed through Merkl across supported protocols */
|
|
8
|
+
MERKL_REWARDS = "MERKL_REWARDS",
|
|
7
9
|
/** Rewards from Compound V3 (only in COMP) */
|
|
8
10
|
COMPOUND_V3_COMP = "COMPOUND_V3_COMP",
|
|
9
11
|
/** Rewards from Spark (wstETH only for now) */
|
|
@@ -43,6 +45,15 @@ export type AaveMeritRewardsClaimableToken = _ClaimableTokenPartial & {
|
|
|
43
45
|
unclaimed: string;
|
|
44
46
|
};
|
|
45
47
|
};
|
|
48
|
+
export type MerklRewardsClaimableToken = _ClaimableTokenPartial & {
|
|
49
|
+
claimType: ClaimType.MERKL_REWARDS;
|
|
50
|
+
additionalClaimFields: {
|
|
51
|
+
accumulated: string;
|
|
52
|
+
proof: string[];
|
|
53
|
+
decimals: string;
|
|
54
|
+
unclaimed: string;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
46
57
|
export type SparkRewardsClaimableToken = _ClaimableTokenPartial & {
|
|
47
58
|
claimType: ClaimType.SPARK_REWARDS;
|
|
48
59
|
additionalClaimFields: {
|
|
@@ -91,5 +102,5 @@ export type UniswapAirdropClaimableToken = _ClaimableTokenPartial & {
|
|
|
91
102
|
proof: string[];
|
|
92
103
|
};
|
|
93
104
|
};
|
|
94
|
-
export type ClaimableToken = AaveRewardsClaimableToken | AaveMeritRewardsClaimableToken | CompoundV3CompClaimableToken | SparkRewardsClaimableToken | KingRewardsClaimableToken | SparkAirdropClaimableToken | SparkWstEthRewardsClaimableToken | EthenaAirdropClaimableToken;
|
|
105
|
+
export type ClaimableToken = AaveRewardsClaimableToken | AaveMeritRewardsClaimableToken | MerklRewardsClaimableToken | CompoundV3CompClaimableToken | SparkRewardsClaimableToken | KingRewardsClaimableToken | SparkAirdropClaimableToken | SparkWstEthRewardsClaimableToken | EthenaAirdropClaimableToken;
|
|
95
106
|
export {};
|
package/esm/types/claiming.js
CHANGED
|
@@ -4,6 +4,8 @@ export var ClaimType;
|
|
|
4
4
|
ClaimType["AAVE_REWARDS"] = "AAVE_REWARDS";
|
|
5
5
|
/** Merit rewards from AAVE (various tokens) */
|
|
6
6
|
ClaimType["AAVE_MERIT_REWARDS"] = "AAVE_MERIT_REWARDS";
|
|
7
|
+
/** Rewards distributed through Merkl across supported protocols */
|
|
8
|
+
ClaimType["MERKL_REWARDS"] = "MERKL_REWARDS";
|
|
7
9
|
/** Rewards from Compound V3 (only in COMP) */
|
|
8
10
|
ClaimType["COMPOUND_V3_COMP"] = "COMPOUND_V3_COMP";
|
|
9
11
|
/** Rewards from Spark (wstETH only for now) */
|
package/esm/types/common.d.ts
CHANGED
|
@@ -6,12 +6,16 @@ export declare enum IncentiveSide {
|
|
|
6
6
|
Supply = "supply",
|
|
7
7
|
Borrow = "borrow"
|
|
8
8
|
}
|
|
9
|
+
export declare enum IncentiveSource {
|
|
10
|
+
Merkl = "merkl"
|
|
11
|
+
}
|
|
9
12
|
export declare enum IncentiveEligibilityId {
|
|
10
13
|
AaveV3EthenaLiquidLeverage = "0x0dC599DBB180E64E42b87332FDeC3a551445ea44BORROW_BL",
|
|
11
14
|
AaveV3ArbitrumEthSupply = "0x5d16261c6715a653248269861bbacf68a9774cde",
|
|
12
15
|
AaveV3ArbitrumETHLSBorrow = "0x0c84331e39d6658Cd6e6b9ba04736cC4c4734351",
|
|
13
16
|
AaveV3EthenaLiquidLeveragePlasma = "0x2E8f1FA9c73F9d975B46BDFe40C92b6dDEFA3f31BORROW_BL",
|
|
14
|
-
AaveV3EthenaLiquidLeveragePlasmaGHO = "2b2f6fefcd3df634"
|
|
17
|
+
AaveV3EthenaLiquidLeveragePlasmaGHO = "2b2f6fefcd3df634",
|
|
18
|
+
CompoundV3PufEthWethBorrow = "e6e49b79e83041f9"
|
|
15
19
|
}
|
|
16
20
|
export declare enum LeverageType {
|
|
17
21
|
Long = "long",
|
|
@@ -24,6 +28,7 @@ export interface IncentiveData {
|
|
|
24
28
|
token: string;
|
|
25
29
|
apy: string;
|
|
26
30
|
incentiveKind?: IncentiveKind;
|
|
31
|
+
source?: IncentiveSource;
|
|
27
32
|
description?: string;
|
|
28
33
|
eligibilityId?: IncentiveEligibilityId;
|
|
29
34
|
}
|
package/esm/types/common.js
CHANGED
|
@@ -8,6 +8,10 @@ export var IncentiveSide;
|
|
|
8
8
|
IncentiveSide["Supply"] = "supply";
|
|
9
9
|
IncentiveSide["Borrow"] = "borrow";
|
|
10
10
|
})(IncentiveSide || (IncentiveSide = {}));
|
|
11
|
+
export var IncentiveSource;
|
|
12
|
+
(function (IncentiveSource) {
|
|
13
|
+
IncentiveSource["Merkl"] = "merkl";
|
|
14
|
+
})(IncentiveSource || (IncentiveSource = {}));
|
|
11
15
|
export var IncentiveEligibilityId;
|
|
12
16
|
(function (IncentiveEligibilityId) {
|
|
13
17
|
IncentiveEligibilityId["AaveV3EthenaLiquidLeverage"] = "0x0dC599DBB180E64E42b87332FDeC3a551445ea44BORROW_BL";
|
|
@@ -15,6 +19,7 @@ export var IncentiveEligibilityId;
|
|
|
15
19
|
IncentiveEligibilityId["AaveV3ArbitrumETHLSBorrow"] = "0x0c84331e39d6658Cd6e6b9ba04736cC4c4734351";
|
|
16
20
|
IncentiveEligibilityId["AaveV3EthenaLiquidLeveragePlasma"] = "0x2E8f1FA9c73F9d975B46BDFe40C92b6dDEFA3f31BORROW_BL";
|
|
17
21
|
IncentiveEligibilityId["AaveV3EthenaLiquidLeveragePlasmaGHO"] = "2b2f6fefcd3df634";
|
|
22
|
+
IncentiveEligibilityId["CompoundV3PufEthWethBorrow"] = "e6e49b79e83041f9";
|
|
18
23
|
})(IncentiveEligibilityId || (IncentiveEligibilityId = {}));
|
|
19
24
|
export var LeverageType;
|
|
20
25
|
(function (LeverageType) {
|
package/esm/types/fluid.d.ts
CHANGED
|
@@ -319,6 +319,8 @@ export interface FluidAggregatedVaultData {
|
|
|
319
319
|
leftToBorrowUsd: string;
|
|
320
320
|
netApy: string;
|
|
321
321
|
incentiveUsd: string;
|
|
322
|
+
merklSupplyIncentives: IncentiveData[];
|
|
323
|
+
merklBorrowIncentives: IncentiveData[];
|
|
322
324
|
ratio: string;
|
|
323
325
|
collRatio: string;
|
|
324
326
|
minRatio: string;
|
package/esm/types/liquityV2.d.ts
CHANGED
|
@@ -84,6 +84,7 @@ export interface LiquityV2AggregatedTroveData {
|
|
|
84
84
|
suppliedUsd: string;
|
|
85
85
|
borrowedUsd: string;
|
|
86
86
|
borrowLimitUsd: string;
|
|
87
|
+
liquidationLimitUsd: string;
|
|
87
88
|
leftToBorrowUsd: string;
|
|
88
89
|
netApy: string;
|
|
89
90
|
incentiveUsd: string;
|
|
@@ -101,9 +102,11 @@ export interface LiquityV2TroveData {
|
|
|
101
102
|
ratio: string;
|
|
102
103
|
collRatio: string;
|
|
103
104
|
liqRatio: string;
|
|
105
|
+
borrowLimitRatio: string;
|
|
104
106
|
interestRate: string;
|
|
105
107
|
leftToBorrowUsd: string;
|
|
106
108
|
borrowLimitUsd: string;
|
|
109
|
+
liquidationLimitUsd: string;
|
|
107
110
|
suppliedUsd: string;
|
|
108
111
|
borrowedUsd: string;
|
|
109
112
|
netApy: string;
|
package/esm/types/merkl.d.ts
CHANGED
|
@@ -76,6 +76,14 @@ export type MerkleRewardMap = Record<EthAddress, {
|
|
|
76
76
|
export type AaveV4MerklScopedReward = {
|
|
77
77
|
[side in IncentiveSide]?: IncentiveData;
|
|
78
78
|
};
|
|
79
|
+
/**
|
|
80
|
+
* Fluid vault-scoped Merkl campaigns keyed by lowercase vault address — `supply` rewards apply to
|
|
81
|
+
* the vault's collateral side, `borrow` rewards to its debt side.
|
|
82
|
+
*/
|
|
83
|
+
export type FluidMerklRewardMap = Record<string, {
|
|
84
|
+
supply: IncentiveData[];
|
|
85
|
+
borrow: IncentiveData[];
|
|
86
|
+
}>;
|
|
79
87
|
/**
|
|
80
88
|
* Aave V4 Merkl reward campaigns split by scope:
|
|
81
89
|
* - `hub`: keyed by `${hubAddress}_${underlyingAddress}` (both lowercase) — rewards for supplying/borrowing via a hub
|
|
@@ -123,13 +123,10 @@ export interface MorphoMidnightAggregatedPositionData {
|
|
|
123
123
|
* - `Pending` — the indexer has not caught up with the chain yet: it does not know the position, or its
|
|
124
124
|
* split describes a different debt. Refetching resolves it; `getMorphoMidnightUserBorrowInfo` failing
|
|
125
125
|
* outright lands here too, since the next call may well succeed.
|
|
126
|
-
* - `Unavailable` — no source covers this market, so refetching changes nothing. See
|
|
127
|
-
* `morphoMidnightMarketReportsBorrowInfo`.
|
|
128
126
|
*/
|
|
129
127
|
export declare enum MorphoMidnightBorrowInfoStatus {
|
|
130
128
|
Available = "available",
|
|
131
|
-
Pending = "pending"
|
|
132
|
-
Unavailable = "unavailable"
|
|
129
|
+
Pending = "pending"
|
|
133
130
|
}
|
|
134
131
|
export interface MorphoMidnightPositionData extends MorphoMidnightAggregatedPositionData {
|
|
135
132
|
usedAssets: MMUsedAssets;
|
|
@@ -36,12 +36,9 @@ export var MorphoMidnightVersions;
|
|
|
36
36
|
* - `Pending` — the indexer has not caught up with the chain yet: it does not know the position, or its
|
|
37
37
|
* split describes a different debt. Refetching resolves it; `getMorphoMidnightUserBorrowInfo` failing
|
|
38
38
|
* outright lands here too, since the next call may well succeed.
|
|
39
|
-
* - `Unavailable` — no source covers this market, so refetching changes nothing. See
|
|
40
|
-
* `morphoMidnightMarketReportsBorrowInfo`.
|
|
41
39
|
*/
|
|
42
40
|
export var MorphoMidnightBorrowInfoStatus;
|
|
43
41
|
(function (MorphoMidnightBorrowInfoStatus) {
|
|
44
42
|
MorphoMidnightBorrowInfoStatus["Available"] = "available";
|
|
45
43
|
MorphoMidnightBorrowInfoStatus["Pending"] = "pending";
|
|
46
|
-
MorphoMidnightBorrowInfoStatus["Unavailable"] = "unavailable";
|
|
47
44
|
})(MorphoMidnightBorrowInfoStatus || (MorphoMidnightBorrowInfoStatus = {}));
|
package/package.json
CHANGED
package/src/aaveV3/merkl.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { aprToApy } from '../moneymarket';
|
|
2
|
-
import {
|
|
2
|
+
import { fetchAllMerklOpportunities } from '../services/merkl';
|
|
3
|
+
import { wethToEth } from '../services/utils';
|
|
3
4
|
import {
|
|
4
5
|
MerkleRewardMap, MerklOpportunity, OpportunityAction, OpportunityStatus,
|
|
5
6
|
EthAddress, NetworkNumber,
|
|
@@ -31,16 +32,16 @@ export const formatAaveAsset = (_symbol: string) => {
|
|
|
31
32
|
|
|
32
33
|
export const getMerkleCampaigns = async (chainId: NetworkNumber): Promise<MerkleRewardMap> => {
|
|
33
34
|
try {
|
|
34
|
-
const
|
|
35
|
-
|
|
35
|
+
const opportunities = await fetchAllMerklOpportunities({
|
|
36
|
+
mainProtocolId: 'aave',
|
|
37
|
+
status: OpportunityStatus.LIVE,
|
|
36
38
|
});
|
|
37
|
-
if (!res.ok) throw new Error('Failed to fetch Merkle campaigns');
|
|
38
|
-
const opportunities = await res.json() as MerklOpportunity[];
|
|
39
39
|
const relevantOpportunities = opportunities
|
|
40
40
|
.filter((o: MerklOpportunity) => o.chainId === chainId)
|
|
41
41
|
.filter((o: MerklOpportunity) => o.status === OpportunityStatus.LIVE);
|
|
42
42
|
return relevantOpportunities.reduce((acc, opportunity) => {
|
|
43
|
-
const rewardToken = opportunity.rewardsRecord
|
|
43
|
+
const rewardToken = opportunity.rewardsRecord?.breakdowns?.[0]?.token;
|
|
44
|
+
if (!rewardToken) return acc;
|
|
44
45
|
const description = `Eligible for ${formatAaveAsset(rewardToken.symbol)} rewards through Merkl. ${opportunity.description ? `\n${opportunity.description}` : ''}`;
|
|
45
46
|
if (opportunity.action === OpportunityAction.LEND && opportunity.explorerAddress) {
|
|
46
47
|
const supplyAToken = opportunity.explorerAddress?.toLowerCase() as EthAddress;
|
|
@@ -71,4 +72,3 @@ export const getMerkleCampaigns = async (chainId: NetworkNumber): Promise<Merkle
|
|
|
71
72
|
return {};
|
|
72
73
|
}
|
|
73
74
|
};
|
|
74
|
-
|
package/src/aaveV4/merkl.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { aprToApy } from '../moneymarket';
|
|
2
|
-
import {
|
|
2
|
+
import { fetchAllMerklOpportunities } from '../services/merkl';
|
|
3
3
|
import {
|
|
4
4
|
AaveV4MerklRewardMap,
|
|
5
5
|
AaveV4ReserveAssetData,
|
|
@@ -67,11 +67,11 @@ export const buildAaveV4MerklRewardMap = (opportunities: MerklOpportunity[], cha
|
|
|
67
67
|
|
|
68
68
|
export const getAaveV4MerkleCampaigns = async (chainId: NetworkNumber): Promise<AaveV4MerklRewardMap> => {
|
|
69
69
|
try {
|
|
70
|
-
const
|
|
71
|
-
|
|
70
|
+
const opportunities = await fetchAllMerklOpportunities({
|
|
71
|
+
mainProtocolId: 'aave',
|
|
72
|
+
type: 'AAVE_V4_HUB_SUPPLY,AAVE_V4_HUB_BORROW,AAVE_V4_SPOKE_SUPPLY,AAVE_V4_SPOKE_BORROW',
|
|
73
|
+
status: OpportunityStatus.LIVE,
|
|
72
74
|
});
|
|
73
|
-
if (!res.ok) throw new Error('Failed to fetch Aave V4 Merkle campaigns');
|
|
74
|
-
const opportunities = await res.json() as MerklOpportunity[];
|
|
75
75
|
return buildAaveV4MerklRewardMap(opportunities, chainId);
|
|
76
76
|
} catch (e) {
|
|
77
77
|
console.error('Failed to fetch Aave V4 Merkle campaigns', e);
|
package/src/claiming/aaveV3.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
2
|
import Dec from 'decimal.js';
|
|
3
3
|
import { EthAddress, NetworkNumber } from '../types';
|
|
4
|
-
import { ClaimableToken, ClaimType } from '../types/claiming';
|
|
4
|
+
import { ClaimableToken, ClaimType, MerklRewardsClaimableToken } from '../types/claiming';
|
|
5
5
|
import {
|
|
6
6
|
AaveIncentiveDataProviderV3ContractViem,
|
|
7
7
|
AaveRewardsControllerViem,
|
|
@@ -103,18 +103,18 @@ export async function getUnclaimedRewardsForAllMarkets(
|
|
|
103
103
|
return mapAaveRewardsToClaimableTokens(Object.values(totalUnclaimedPerRewardToken), marketAddress, walletAddress);
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
export async function
|
|
106
|
+
export async function getMerklUnclaimedRewards(account: EthAddress, network: NetworkNumber): Promise<MerklRewardsClaimableToken[]> {
|
|
107
107
|
let data;
|
|
108
108
|
try {
|
|
109
109
|
const res = await fetch(`https://fe.defisaver.com/api/merkl/get-user-rewards/${account}?chainId=${network}`,
|
|
110
110
|
{ signal: AbortSignal.timeout(LONGER_TIMEOUT) });
|
|
111
111
|
data = await res.json();
|
|
112
112
|
} catch (error) {
|
|
113
|
-
console.error('External API Failure:
|
|
113
|
+
console.error('External API Failure: Merkl rewards', error);
|
|
114
114
|
data = [];
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
const claimableTokens:
|
|
117
|
+
const claimableTokens: MerklRewardsClaimableToken[] = [];
|
|
118
118
|
|
|
119
119
|
// Merkl (or our proxy, on a non-2xx) can return a non-array error body; `fetch` doesn't throw on
|
|
120
120
|
// HTTP errors, so guard before iterating. Mirrors the app-side getMeritUnclaimedRewards.
|
|
@@ -137,12 +137,12 @@ export async function getMeritUnclaimedRewards(account: EthAddress, network: Net
|
|
|
137
137
|
const unclaimed = getEthAmountForDecimals(unclaimedAmount, token.decimals);
|
|
138
138
|
|
|
139
139
|
claimableTokens.push({
|
|
140
|
-
claimType: ClaimType.
|
|
140
|
+
claimType: ClaimType.MERKL_REWARDS,
|
|
141
141
|
amount: unclaimed,
|
|
142
142
|
symbol: token.symbol,
|
|
143
143
|
tokenAddress: token.address,
|
|
144
144
|
walletAddress: account,
|
|
145
|
-
label: '
|
|
145
|
+
label: 'Merkl Rewards',
|
|
146
146
|
underlyingSymbol: getAaveUnderlyingSymbol(token.symbol),
|
|
147
147
|
additionalClaimFields: {
|
|
148
148
|
accumulated: amount,
|
|
@@ -155,4 +155,16 @@ export async function getMeritUnclaimedRewards(account: EthAddress, network: Net
|
|
|
155
155
|
});
|
|
156
156
|
|
|
157
157
|
return claimableTokens;
|
|
158
|
-
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export async function getMeritUnclaimedRewards(account: EthAddress, network: NetworkNumber): Promise<ClaimableToken[]> {
|
|
161
|
+
const rewards = await getMerklUnclaimedRewards(account, network);
|
|
162
|
+
|
|
163
|
+
return rewards
|
|
164
|
+
.filter(reward => reward.symbol.startsWith('a'))
|
|
165
|
+
.map(reward => ({
|
|
166
|
+
...reward,
|
|
167
|
+
claimType: ClaimType.AAVE_MERIT_REWARDS,
|
|
168
|
+
label: 'AAVE Merit Rewards',
|
|
169
|
+
}));
|
|
170
|
+
}
|
package/src/compoundV3/index.ts
CHANGED
|
@@ -24,6 +24,9 @@ import {
|
|
|
24
24
|
getEthPrice, getCompPrice, getUSDCPrice, getWstETHPrice,
|
|
25
25
|
} from '../services/priceService';
|
|
26
26
|
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
27
|
+
import { attachCompoundV3MerklIncentives, getCompoundV3MerklOpportunities } from './merkl';
|
|
28
|
+
|
|
29
|
+
export { getCompoundV3MerklOpportunities, attachCompoundV3MerklIncentives } from './merkl';
|
|
27
30
|
|
|
28
31
|
const getSupportedAssetsAddressesForMarket = (selectedMarket: CompoundMarketData, network: NetworkNumber) => selectedMarket.collAssets.map(asset => getAssetInfo(ethToWeth(asset), network)).map(addr => addr.address.toLowerCase());
|
|
29
32
|
|
|
@@ -41,12 +44,13 @@ const getBaseAssetPriceFunction = (asset: string) => {
|
|
|
41
44
|
export const _getCompoundV3MarketsData = async (provider: Client, network: NetworkNumber, selectedMarket: CompoundMarketData, defaultProvider: Client): Promise<CompoundV3MarketsData> => {
|
|
42
45
|
const contract = CompV3ViewContractViem(provider, network);
|
|
43
46
|
|
|
44
|
-
const [baseAssetPrice, compPrice, baseTokenInfo, collInfos, govInfo] = await Promise.all([
|
|
47
|
+
const [baseAssetPrice, compPrice, baseTokenInfo, collInfos, govInfo, merklOpportunities] = await Promise.all([
|
|
45
48
|
getBaseAssetPriceFunction(selectedMarket.baseAsset)(defaultProvider),
|
|
46
49
|
getCompPrice(defaultProvider),
|
|
47
50
|
contract.read.getFullBaseTokenInfo([selectedMarket.baseMarketAddress]),
|
|
48
51
|
contract.read.getFullCollInfos([selectedMarket.baseMarketAddress]),
|
|
49
52
|
contract.read.getGovernanceInfoFull([selectedMarket.baseMarketAddress]),
|
|
53
|
+
getCompoundV3MerklOpportunities(),
|
|
50
54
|
]);
|
|
51
55
|
|
|
52
56
|
const { isSupplyPaused, isWithdrawPaused } = govInfo;
|
|
@@ -72,6 +76,7 @@ export const _getCompoundV3MarketsData = async (provider: Client, network: Netwo
|
|
|
72
76
|
const payload: CompoundV3AssetsData = {};
|
|
73
77
|
|
|
74
78
|
const baseObj = { ...base, ...(await getIncentiveApys(base, compPrice)) };
|
|
79
|
+
attachCompoundV3MerklIncentives(baseObj, colls, selectedMarket.baseMarketAddress, network, merklOpportunities);
|
|
75
80
|
const allAssets = [baseObj, ...colls];
|
|
76
81
|
|
|
77
82
|
allAssets
|