@defisaver/positions-sdk 2.1.141 → 2.1.142
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/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 +1 -0
- package/cjs/fluid/index.js +28 -8
- package/cjs/fluid/merkl.d.ts +31 -0
- package/cjs/fluid/merkl.js +99 -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/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/common.d.ts +2 -1
- package/cjs/types/common.js +1 -0
- package/cjs/types/merkl.d.ts +8 -0
- package/esm/aaveV3/merkl.js +11 -10
- package/esm/aaveV4/merkl.js +5 -6
- 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 +1 -0
- package/esm/fluid/index.js +23 -7
- package/esm/fluid/merkl.d.ts +31 -0
- package/esm/fluid/merkl.js +93 -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/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/common.d.ts +2 -1
- package/esm/types/common.js +1 -0
- package/esm/types/merkl.d.ts +8 -0
- package/package.json +1 -1
- package/src/aaveV3/merkl.ts +7 -7
- package/src/aaveV4/merkl.ts +5 -5
- package/src/compoundV3/index.ts +6 -1
- package/src/compoundV3/merkl.ts +76 -0
- package/src/fluid/index.ts +29 -7
- package/src/fluid/merkl.ts +99 -0
- package/src/morphoBlue/index.ts +24 -9
- package/src/morphoBlue/merkl.ts +121 -0
- package/src/services/merkl.ts +31 -0
- package/src/staking/eligibility.ts +10 -0
- package/src/types/common.ts +1 -0
- package/src/types/merkl.ts +6 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.addMorphoBlueMerklRewardsToMarketInfo = exports.getMorphoBlueMerklOpportunities = exports.addMorphoBlueMerklOpportunitiesToMarketInfo = exports.MorphoBlueMerklOpportunityType = void 0;
|
|
13
|
+
const moneymarket_1 = require("../moneymarket");
|
|
14
|
+
const merkl_1 = require("../services/merkl");
|
|
15
|
+
const types_1 = require("../types");
|
|
16
|
+
/**
|
|
17
|
+
* Merkl tags Morpho Blue market-level reward campaigns via the opportunity `type` field:
|
|
18
|
+
* - MORPHOSUPPLY → reward for supplying the market's loan asset
|
|
19
|
+
* - MORPHOCOLLATERAL → reward for depositing the market's collateral asset
|
|
20
|
+
* - MORPHOBORROW → reward for borrowing the market's loan asset
|
|
21
|
+
* (MORPHOVAULT/ERC20LOGPROCESSOR are MetaMorpho vault campaigns and MORPHOSUPPLY_SINGLETOKEN is
|
|
22
|
+
* token-wide rather than market-scoped, so none of them belong on per-market data.)
|
|
23
|
+
*
|
|
24
|
+
* A campaign identifies its market via `identifier` — the first 20 bytes of the 32-byte Morpho
|
|
25
|
+
* market id, formatted as a checksummed address. Whitelist-gated campaigns append a marker to that
|
|
26
|
+
* identifier (e.g. `0x54cf…c46WHITELIST_CAMPAIGN`); their rewards only accrue to whitelisted
|
|
27
|
+
* addresses, so they are skipped rather than advertised to every user.
|
|
28
|
+
*/
|
|
29
|
+
var MorphoBlueMerklOpportunityType;
|
|
30
|
+
(function (MorphoBlueMerklOpportunityType) {
|
|
31
|
+
MorphoBlueMerklOpportunityType["Supply"] = "MORPHOSUPPLY";
|
|
32
|
+
MorphoBlueMerklOpportunityType["Collateral"] = "MORPHOCOLLATERAL";
|
|
33
|
+
MorphoBlueMerklOpportunityType["Borrow"] = "MORPHOBORROW";
|
|
34
|
+
})(MorphoBlueMerklOpportunityType || (exports.MorphoBlueMerklOpportunityType = MorphoBlueMerklOpportunityType = {}));
|
|
35
|
+
const MERKL_DESCRIPTION_MARKER = 'through Merkl';
|
|
36
|
+
// '0x' + first 20 bytes of the market id
|
|
37
|
+
const MARKET_ID_PREFIX_LENGTH = 42;
|
|
38
|
+
const buildMerklIncentive = (opportunity) => {
|
|
39
|
+
var _a, _b, _c, _d, _e, _f;
|
|
40
|
+
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) || '';
|
|
41
|
+
return {
|
|
42
|
+
apy: (0, moneymarket_1.aprToApy)(opportunity.apr),
|
|
43
|
+
token,
|
|
44
|
+
incentiveKind: types_1.IncentiveKind.Reward,
|
|
45
|
+
description: `Eligible for ${token} rewards through Merkl.${opportunity.description ? `\n${opportunity.description}` : ''}`,
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
const withoutMerklIncentives = (incentives = []) => incentives
|
|
49
|
+
.filter(({ description }) => !(description === null || description === void 0 ? void 0 : description.includes(MERKL_DESCRIPTION_MARKER)));
|
|
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
|
+
const addMorphoBlueMerklOpportunitiesToMarketInfo = (marketInfo, selectedMarket, chainId, opportunities) => {
|
|
56
|
+
const marketIdPrefix = (selectedMarket.marketId || '').slice(0, MARKET_ID_PREFIX_LENGTH).toLowerCase();
|
|
57
|
+
const collateralAsset = marketInfo.assetsData[marketInfo.collateralToken];
|
|
58
|
+
const loanAsset = marketInfo.assetsData[marketInfo.loanToken];
|
|
59
|
+
if (marketIdPrefix.length !== MARKET_ID_PREFIX_LENGTH || !collateralAsset || !loanAsset)
|
|
60
|
+
return marketInfo;
|
|
61
|
+
const relevant = opportunities.filter((o) => {
|
|
62
|
+
var _a;
|
|
63
|
+
return o.chainId === chainId
|
|
64
|
+
&& o.status === types_1.OpportunityStatus.LIVE
|
|
65
|
+
&& Object.values(MorphoBlueMerklOpportunityType).includes(o.type)
|
|
66
|
+
// a suffixed identifier marks a whitelist-gated campaign — skip those
|
|
67
|
+
&& ((_a = o.identifier) === null || _a === void 0 ? void 0 : _a.length) === MARKET_ID_PREFIX_LENGTH
|
|
68
|
+
&& o.identifier.toLowerCase() === marketIdPrefix;
|
|
69
|
+
});
|
|
70
|
+
if (!relevant.length)
|
|
71
|
+
return marketInfo;
|
|
72
|
+
const incentivesByType = (type) => relevant.filter((o) => o.type === type).map(buildMerklIncentive);
|
|
73
|
+
const collateralSupply = incentivesByType(MorphoBlueMerklOpportunityType.Collateral);
|
|
74
|
+
const loanSupply = incentivesByType(MorphoBlueMerklOpportunityType.Supply);
|
|
75
|
+
const loanBorrow = incentivesByType(MorphoBlueMerklOpportunityType.Borrow);
|
|
76
|
+
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] }) }) });
|
|
77
|
+
};
|
|
78
|
+
exports.addMorphoBlueMerklOpportunitiesToMarketInfo = addMorphoBlueMerklOpportunitiesToMarketInfo;
|
|
79
|
+
/**
|
|
80
|
+
* Fetches live market-scoped Morpho Blue campaigns for all chains. Never throws — on any failure
|
|
81
|
+
* it returns an empty list, so Merkl being down can't break market data.
|
|
82
|
+
*/
|
|
83
|
+
const getMorphoBlueMerklOpportunities = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
|
+
try {
|
|
85
|
+
return yield (0, merkl_1.fetchAllMerklOpportunities)({
|
|
86
|
+
mainProtocolId: 'morpho',
|
|
87
|
+
type: Object.values(MorphoBlueMerklOpportunityType).join(','),
|
|
88
|
+
status: types_1.OpportunityStatus.LIVE,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
console.error('Failed to fetch Morpho Blue Merkl campaigns', e);
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
exports.getMorphoBlueMerklOpportunities = getMorphoBlueMerklOpportunities;
|
|
97
|
+
/**
|
|
98
|
+
* Fetches live Merkl campaigns and appends the ones for the market to its `assetsData` incentive
|
|
99
|
+
* arrays. Never throws — on any failure the market info is returned unchanged.
|
|
100
|
+
*/
|
|
101
|
+
const addMorphoBlueMerklRewardsToMarketInfo = (marketInfo, selectedMarket, network) => __awaiter(void 0, void 0, void 0, function* () { return (0, exports.addMorphoBlueMerklOpportunitiesToMarketInfo)(marketInfo, selectedMarket, network, yield (0, exports.getMorphoBlueMerklOpportunities)()); });
|
|
102
|
+
exports.addMorphoBlueMerklRewardsToMarketInfo = addMorphoBlueMerklRewardsToMarketInfo;
|
|
@@ -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,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.fetchAllMerklOpportunities = void 0;
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
const MERKL_OPPORTUNITIES_URL = 'https://fe.defisaver.com/api/merkl/opportunities';
|
|
15
|
+
/**
|
|
16
|
+
* Fetches every page matching the query. Merkl returns 20 opportunities by default, so omitting
|
|
17
|
+
* `items` and advancing `page` avoids imposing a client-side maximum on the result set.
|
|
18
|
+
*/
|
|
19
|
+
const fetchAllMerklOpportunities = (query) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
const opportunities = [];
|
|
21
|
+
let page = 0;
|
|
22
|
+
let pageOpportunities;
|
|
23
|
+
do {
|
|
24
|
+
const searchParams = new URLSearchParams(Object.assign(Object.assign({}, query), { page: page.toString() }));
|
|
25
|
+
const res = yield fetch(`${MERKL_OPPORTUNITIES_URL}?${searchParams}`, {
|
|
26
|
+
signal: AbortSignal.timeout(utils_1.LONGER_TIMEOUT),
|
|
27
|
+
});
|
|
28
|
+
if (!res.ok)
|
|
29
|
+
throw new Error(`Failed to fetch Merkl opportunities page ${page}`);
|
|
30
|
+
const data = yield res.json(); // eslint-disable-line no-await-in-loop
|
|
31
|
+
if (!Array.isArray(data))
|
|
32
|
+
throw new Error(`Invalid Merkl opportunities response on page ${page}`);
|
|
33
|
+
pageOpportunities = data;
|
|
34
|
+
opportunities.push(...pageOpportunities);
|
|
35
|
+
page += 1;
|
|
36
|
+
} while (pageOpportunities.length > 0);
|
|
37
|
+
return opportunities;
|
|
38
|
+
});
|
|
39
|
+
exports.fetchAllMerklOpportunities = fetchAllMerklOpportunities;
|
|
@@ -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;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.EligibilityMapping = exports.isEligibleForAaveV3ArbitrumETHLSBorrow = exports.isEligibleForAaveV3ArbitrumEthSupply = exports.isEligibleForEthenaGHORewards = exports.isEligibleForEthenaUSDeRewards = void 0;
|
|
6
|
+
exports.EligibilityMapping = exports.isEligibleForCompoundV3PufEthWethBorrow = exports.isEligibleForAaveV3ArbitrumETHLSBorrow = exports.isEligibleForAaveV3ArbitrumEthSupply = exports.isEligibleForEthenaGHORewards = exports.isEligibleForEthenaUSDeRewards = void 0;
|
|
7
7
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
8
|
const common_1 = require("../types/common");
|
|
9
9
|
const isEligibleForEthenaPairRewards = (usedAssets, { healthRatio }, { baseSymbol, pairSymbol, allowedBorrowAssets, maxHealthRatio, rewardSymbol, }) => {
|
|
@@ -70,10 +70,20 @@ const isEligibleForAaveV3ArbitrumETHLSBorrow = (usedAssets) => {
|
|
|
70
70
|
return { isEligible: true, eligibleUSDAmount: ETHAmountBorrowed };
|
|
71
71
|
};
|
|
72
72
|
exports.isEligibleForAaveV3ArbitrumETHLSBorrow = isEligibleForAaveV3ArbitrumETHLSBorrow;
|
|
73
|
+
// "Borrow WETH with pufETH collateral" — rewards are calculated as min(collateral * 80% LTV, borrow amount)
|
|
74
|
+
const isEligibleForCompoundV3PufEthWethBorrow = (usedAssets) => {
|
|
75
|
+
var _a, _b;
|
|
76
|
+
const collateralUsd = ((_a = usedAssets.pufETH) === null || _a === void 0 ? void 0 : _a.suppliedUsd) || '0';
|
|
77
|
+
const borrowedUsd = ((_b = usedAssets.ETH) === null || _b === void 0 ? void 0 : _b.borrowedUsd) || '0';
|
|
78
|
+
const eligibleUSDAmount = decimal_js_1.default.min(new decimal_js_1.default(collateralUsd).mul('0.8'), borrowedUsd).toString();
|
|
79
|
+
return { isEligible: new decimal_js_1.default(eligibleUSDAmount).gt(0), eligibleUSDAmount };
|
|
80
|
+
};
|
|
81
|
+
exports.isEligibleForCompoundV3PufEthWethBorrow = isEligibleForCompoundV3PufEthWethBorrow;
|
|
73
82
|
exports.EligibilityMapping = {
|
|
74
83
|
[common_1.IncentiveEligibilityId.AaveV3EthenaLiquidLeverage]: exports.isEligibleForEthenaUSDeRewards,
|
|
75
84
|
[common_1.IncentiveEligibilityId.AaveV3ArbitrumEthSupply]: exports.isEligibleForAaveV3ArbitrumEthSupply,
|
|
76
85
|
[common_1.IncentiveEligibilityId.AaveV3ArbitrumETHLSBorrow]: exports.isEligibleForAaveV3ArbitrumETHLSBorrow,
|
|
77
86
|
[common_1.IncentiveEligibilityId.AaveV3EthenaLiquidLeveragePlasma]: exports.isEligibleForEthenaUSDeRewards,
|
|
78
87
|
[common_1.IncentiveEligibilityId.AaveV3EthenaLiquidLeveragePlasmaGHO]: exports.isEligibleForEthenaGHORewards,
|
|
88
|
+
[common_1.IncentiveEligibilityId.CompoundV3PufEthWethBorrow]: exports.isEligibleForCompoundV3PufEthWethBorrow,
|
|
79
89
|
};
|
package/cjs/types/common.d.ts
CHANGED
|
@@ -11,7 +11,8 @@ export declare enum IncentiveEligibilityId {
|
|
|
11
11
|
AaveV3ArbitrumEthSupply = "0x5d16261c6715a653248269861bbacf68a9774cde",
|
|
12
12
|
AaveV3ArbitrumETHLSBorrow = "0x0c84331e39d6658Cd6e6b9ba04736cC4c4734351",
|
|
13
13
|
AaveV3EthenaLiquidLeveragePlasma = "0x2E8f1FA9c73F9d975B46BDFe40C92b6dDEFA3f31BORROW_BL",
|
|
14
|
-
AaveV3EthenaLiquidLeveragePlasmaGHO = "2b2f6fefcd3df634"
|
|
14
|
+
AaveV3EthenaLiquidLeveragePlasmaGHO = "2b2f6fefcd3df634",
|
|
15
|
+
CompoundV3PufEthWethBorrow = "e6e49b79e83041f9"
|
|
15
16
|
}
|
|
16
17
|
export declare enum LeverageType {
|
|
17
18
|
Long = "long",
|
package/cjs/types/common.js
CHANGED
|
@@ -18,6 +18,7 @@ var IncentiveEligibilityId;
|
|
|
18
18
|
IncentiveEligibilityId["AaveV3ArbitrumETHLSBorrow"] = "0x0c84331e39d6658Cd6e6b9ba04736cC4c4734351";
|
|
19
19
|
IncentiveEligibilityId["AaveV3EthenaLiquidLeveragePlasma"] = "0x2E8f1FA9c73F9d975B46BDFe40C92b6dDEFA3f31BORROW_BL";
|
|
20
20
|
IncentiveEligibilityId["AaveV3EthenaLiquidLeveragePlasmaGHO"] = "2b2f6fefcd3df634";
|
|
21
|
+
IncentiveEligibilityId["CompoundV3PufEthWethBorrow"] = "e6e49b79e83041f9";
|
|
21
22
|
})(IncentiveEligibilityId || (exports.IncentiveEligibilityId = IncentiveEligibilityId = {}));
|
|
22
23
|
var LeverageType;
|
|
23
24
|
(function (LeverageType) {
|
package/cjs/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
|
package/esm/aaveV3/merkl.js
CHANGED
|
@@ -8,7 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { aprToApy } from '../moneymarket';
|
|
11
|
-
import {
|
|
11
|
+
import { fetchAllMerklOpportunities } from '../services/merkl';
|
|
12
|
+
import { wethToEth } from '../services/utils';
|
|
12
13
|
import { OpportunityAction, OpportunityStatus, } from '../types';
|
|
13
14
|
export const getAaveUnderlyingSymbol = (_symbol = '') => {
|
|
14
15
|
let symbol = _symbol
|
|
@@ -35,21 +36,21 @@ export const formatAaveAsset = (_symbol) => {
|
|
|
35
36
|
};
|
|
36
37
|
export const getMerkleCampaigns = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
38
|
try {
|
|
38
|
-
const
|
|
39
|
-
|
|
39
|
+
const opportunities = yield fetchAllMerklOpportunities({
|
|
40
|
+
mainProtocolId: 'aave',
|
|
41
|
+
status: OpportunityStatus.LIVE,
|
|
40
42
|
});
|
|
41
|
-
if (!res.ok)
|
|
42
|
-
throw new Error('Failed to fetch Merkle campaigns');
|
|
43
|
-
const opportunities = yield res.json();
|
|
44
43
|
const relevantOpportunities = opportunities
|
|
45
44
|
.filter((o) => o.chainId === chainId)
|
|
46
45
|
.filter((o) => o.status === OpportunityStatus.LIVE);
|
|
47
46
|
return relevantOpportunities.reduce((acc, opportunity) => {
|
|
48
|
-
var _a, _b;
|
|
49
|
-
const rewardToken = opportunity.rewardsRecord.breakdowns[0].token;
|
|
47
|
+
var _a, _b, _c, _d, _e;
|
|
48
|
+
const rewardToken = (_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;
|
|
49
|
+
if (!rewardToken)
|
|
50
|
+
return acc;
|
|
50
51
|
const description = `Eligible for ${formatAaveAsset(rewardToken.symbol)} rewards through Merkl. ${opportunity.description ? `\n${opportunity.description}` : ''}`;
|
|
51
52
|
if (opportunity.action === OpportunityAction.LEND && opportunity.explorerAddress) {
|
|
52
|
-
const supplyAToken = (
|
|
53
|
+
const supplyAToken = (_d = opportunity.explorerAddress) === null || _d === void 0 ? void 0 : _d.toLowerCase();
|
|
53
54
|
if (!acc[supplyAToken])
|
|
54
55
|
acc[supplyAToken] = {};
|
|
55
56
|
acc[supplyAToken].supply = {
|
|
@@ -61,7 +62,7 @@ export const getMerkleCampaigns = (chainId) => __awaiter(void 0, void 0, void 0,
|
|
|
61
62
|
};
|
|
62
63
|
}
|
|
63
64
|
if (opportunity.action === OpportunityAction.BORROW && opportunity.explorerAddress) {
|
|
64
|
-
const borrowAToken = (
|
|
65
|
+
const borrowAToken = (_e = opportunity.explorerAddress) === null || _e === void 0 ? void 0 : _e.toLowerCase();
|
|
65
66
|
if (!acc[borrowAToken])
|
|
66
67
|
acc[borrowAToken] = {};
|
|
67
68
|
acc[borrowAToken].borrow = {
|
package/esm/aaveV4/merkl.js
CHANGED
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { aprToApy } from '../moneymarket';
|
|
11
|
-
import {
|
|
11
|
+
import { fetchAllMerklOpportunities } from '../services/merkl';
|
|
12
12
|
import { IncentiveKind, IncentiveSide, OpportunityAction, OpportunityStatus, } from '../types';
|
|
13
13
|
/**
|
|
14
14
|
* Merkl tags Aave V4 reward campaigns by scope via the `type` field:
|
|
@@ -63,12 +63,11 @@ export const buildAaveV4MerklRewardMap = (opportunities, chainId) => {
|
|
|
63
63
|
};
|
|
64
64
|
export const getAaveV4MerkleCampaigns = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
65
|
try {
|
|
66
|
-
const
|
|
67
|
-
|
|
66
|
+
const opportunities = yield fetchAllMerklOpportunities({
|
|
67
|
+
mainProtocolId: 'aave',
|
|
68
|
+
type: 'AAVE_V4_HUB_SUPPLY,AAVE_V4_HUB_BORROW,AAVE_V4_SPOKE_SUPPLY,AAVE_V4_SPOKE_BORROW',
|
|
69
|
+
status: OpportunityStatus.LIVE,
|
|
68
70
|
});
|
|
69
|
-
if (!res.ok)
|
|
70
|
-
throw new Error('Failed to fetch Aave V4 Merkle campaigns');
|
|
71
|
-
const opportunities = yield res.json();
|
|
72
71
|
return buildAaveV4MerklRewardMap(opportunities, chainId);
|
|
73
72
|
}
|
|
74
73
|
catch (e) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
2
|
import { CompoundMarketData, CompoundV3AssetsData, CompoundV3MarketsData, CompoundV3PositionData } from '../types';
|
|
3
3
|
import { Blockish, EthAddress, EthereumProvider, NetworkNumber, PositionBalances } from '../types/common';
|
|
4
|
+
export { getCompoundV3MerklOpportunities, attachCompoundV3MerklIncentives } from './merkl';
|
|
4
5
|
export declare const _getCompoundV3MarketsData: (provider: Client, network: NetworkNumber, selectedMarket: CompoundMarketData, defaultProvider: Client) => Promise<CompoundV3MarketsData>;
|
|
5
6
|
export declare const getCompoundV3MarketsData: (provider: EthereumProvider, network: NetworkNumber, selectedMarket: CompoundMarketData, defaultProvider: EthereumProvider) => Promise<CompoundV3MarketsData>;
|
|
6
7
|
export declare const EMPTY_COMPOUND_V3_DATA: {
|
package/esm/compoundV3/index.js
CHANGED
|
@@ -19,6 +19,8 @@ import { formatBaseData, formatMarketData, getCompoundV3AggregatedData, getIncen
|
|
|
19
19
|
import { CompoundMarkets } from '../markets/compound';
|
|
20
20
|
import { getEthPrice, getCompPrice, getUSDCPrice, getWstETHPrice, } from '../services/priceService';
|
|
21
21
|
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
22
|
+
import { attachCompoundV3MerklIncentives, getCompoundV3MerklOpportunities } from './merkl';
|
|
23
|
+
export { getCompoundV3MerklOpportunities, attachCompoundV3MerklIncentives } from './merkl';
|
|
22
24
|
const getSupportedAssetsAddressesForMarket = (selectedMarket, network) => selectedMarket.collAssets.map(asset => getAssetInfo(ethToWeth(asset), network)).map(addr => addr.address.toLowerCase());
|
|
23
25
|
const getBaseAssetPriceFunction = (asset) => {
|
|
24
26
|
switch (asset) {
|
|
@@ -32,12 +34,13 @@ const getBaseAssetPriceFunction = (asset) => {
|
|
|
32
34
|
};
|
|
33
35
|
export const _getCompoundV3MarketsData = (provider, network, selectedMarket, defaultProvider) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
36
|
const contract = CompV3ViewContractViem(provider, network);
|
|
35
|
-
const [baseAssetPrice, compPrice, baseTokenInfo, collInfos, govInfo] = yield Promise.all([
|
|
37
|
+
const [baseAssetPrice, compPrice, baseTokenInfo, collInfos, govInfo, merklOpportunities] = yield Promise.all([
|
|
36
38
|
getBaseAssetPriceFunction(selectedMarket.baseAsset)(defaultProvider),
|
|
37
39
|
getCompPrice(defaultProvider),
|
|
38
40
|
contract.read.getFullBaseTokenInfo([selectedMarket.baseMarketAddress]),
|
|
39
41
|
contract.read.getFullCollInfos([selectedMarket.baseMarketAddress]),
|
|
40
42
|
contract.read.getGovernanceInfoFull([selectedMarket.baseMarketAddress]),
|
|
43
|
+
getCompoundV3MerklOpportunities(),
|
|
41
44
|
]);
|
|
42
45
|
const { isSupplyPaused, isWithdrawPaused } = govInfo;
|
|
43
46
|
const supportedAssetsAddresses = getSupportedAssetsAddressesForMarket(selectedMarket, network);
|
|
@@ -57,6 +60,7 @@ export const _getCompoundV3MarketsData = (provider, network, selectedMarket, def
|
|
|
57
60
|
const base = formatBaseData(baseTokenInfo, network, baseAssetPrice, isSupplyPaused, isWithdrawPaused);
|
|
58
61
|
const payload = {};
|
|
59
62
|
const baseObj = Object.assign(Object.assign({}, base), (yield getIncentiveApys(base, compPrice)));
|
|
63
|
+
attachCompoundV3MerklIncentives(baseObj, colls, selectedMarket.baseMarketAddress, network, merklOpportunities);
|
|
60
64
|
const allAssets = [baseObj, ...colls];
|
|
61
65
|
allAssets
|
|
62
66
|
.sort((a, b) => {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CompoundV3AssetData, MerklOpportunity, NetworkNumber } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Merkl tags Compound V3 reward campaigns with COMPOUND_V3_* opportunity types (e.g.
|
|
4
|
+
* COMPOUND_V3_BORROW_FROM_COLLATERAL) and identifies the comet via `explorerAddress`. Campaign
|
|
5
|
+
* identifiers are opaque hashes, passed through as `eligibilityId` so conditional campaigns —
|
|
6
|
+
* like borrow-from-collateral ones, whose reward is min(collateral * LTV, borrow amount) — can
|
|
7
|
+
* be gated and sized by a curated check in EligibilityMapping; unknown ids apply
|
|
8
|
+
* unconditionally, mirroring Aave V3.
|
|
9
|
+
*/
|
|
10
|
+
export declare const getCompoundV3MerklOpportunities: () => Promise<MerklOpportunity[]>;
|
|
11
|
+
/**
|
|
12
|
+
* Appends the comet's Merkl campaigns to its assets' incentive arrays (mutating them, like the
|
|
13
|
+
* staking incentives are attached). BORROW campaigns land on the base asset — the only borrowable
|
|
14
|
+
* one — while LEND campaigns land on the asset the campaign's first token resolves to.
|
|
15
|
+
*/
|
|
16
|
+
export declare const attachCompoundV3MerklIncentives: (baseAsset: CompoundV3AssetData, collAssets: CompoundV3AssetData[], baseMarketAddress: string, chainId: NetworkNumber, opportunities: MerklOpportunity[]) => void;
|
|
@@ -0,0 +1,72 @@
|
|
|
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 { getAssetInfoByAddress } from '@defisaver/tokens';
|
|
11
|
+
import { aprToApy } from '../moneymarket';
|
|
12
|
+
import { fetchAllMerklOpportunities } from '../services/merkl';
|
|
13
|
+
import { compareAddresses, wethToEth } from '../services/utils';
|
|
14
|
+
import { IncentiveKind, OpportunityAction, OpportunityStatus, } from '../types';
|
|
15
|
+
/**
|
|
16
|
+
* Merkl tags Compound V3 reward campaigns with COMPOUND_V3_* opportunity types (e.g.
|
|
17
|
+
* COMPOUND_V3_BORROW_FROM_COLLATERAL) and identifies the comet via `explorerAddress`. Campaign
|
|
18
|
+
* identifiers are opaque hashes, passed through as `eligibilityId` so conditional campaigns —
|
|
19
|
+
* like borrow-from-collateral ones, whose reward is min(collateral * LTV, borrow amount) — can
|
|
20
|
+
* be gated and sized by a curated check in EligibilityMapping; unknown ids apply
|
|
21
|
+
* unconditionally, mirroring Aave V3.
|
|
22
|
+
*/
|
|
23
|
+
export const getCompoundV3MerklOpportunities = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
try {
|
|
25
|
+
return yield fetchAllMerklOpportunities({
|
|
26
|
+
mainProtocolId: 'compound-v3',
|
|
27
|
+
status: OpportunityStatus.LIVE,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
console.error('Failed to fetch Compound V3 Merkl campaigns', e);
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
});
|
|
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
|
+
eligibilityId: opportunity.identifier,
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Appends the comet's Merkl campaigns to its assets' incentive arrays (mutating them, like the
|
|
48
|
+
* staking incentives are attached). BORROW campaigns land on the base asset — the only borrowable
|
|
49
|
+
* one — while LEND campaigns land on the asset the campaign's first token resolves to.
|
|
50
|
+
*/
|
|
51
|
+
export const attachCompoundV3MerklIncentives = (baseAsset, collAssets, baseMarketAddress, chainId, opportunities) => {
|
|
52
|
+
opportunities
|
|
53
|
+
.filter((o) => o.chainId === chainId
|
|
54
|
+
&& o.status === OpportunityStatus.LIVE
|
|
55
|
+
&& typeof o.type === 'string' && o.type.startsWith('COMPOUND_V3')
|
|
56
|
+
&& o.explorerAddress && compareAddresses(o.explorerAddress, baseMarketAddress))
|
|
57
|
+
.forEach((o) => {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
const incentive = buildMerklIncentive(o);
|
|
60
|
+
if (o.action === OpportunityAction.BORROW) {
|
|
61
|
+
baseAsset.borrowIncentives.push(incentive);
|
|
62
|
+
}
|
|
63
|
+
else if (o.action === OpportunityAction.LEND) {
|
|
64
|
+
const campaignTokenAddress = (_b = (_a = o.tokens) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.address;
|
|
65
|
+
if (!campaignTokenAddress)
|
|
66
|
+
return;
|
|
67
|
+
const campaignSymbol = wethToEth(getAssetInfoByAddress(campaignTokenAddress, chainId).symbol);
|
|
68
|
+
const target = [baseAsset, ...collAssets].find((asset) => asset.symbol === campaignSymbol);
|
|
69
|
+
target === null || target === void 0 ? void 0 : target.supplyIncentives.push(incentive);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
};
|
package/esm/fluid/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Client, PublicClient } from 'viem';
|
|
2
2
|
import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
|
|
3
3
|
import { FluidAssetsData, FluidMarketData, FluidMarketInfo, FluidUsedAssets, FluidVaultData, InnerFluidMarketData } from '../types';
|
|
4
|
+
export { FluidMerklOpportunityType, buildFluidMerklRewardMap, getFluidMerklCampaigns, attachFluidMerklIncentives, } from './merkl';
|
|
4
5
|
export declare const EMPTY_USED_ASSET: {
|
|
5
6
|
isSupplied: boolean;
|
|
6
7
|
isBorrowed: boolean;
|
package/esm/fluid/index.js
CHANGED
|
@@ -19,6 +19,8 @@ import { USD_QUOTE, ZERO_ADDRESS } from '../constants';
|
|
|
19
19
|
import { getChainlinkAssetAddress, getSyrupUSDTChainLinkPriceCalls, getSyrupUSDTPrice, getWeETHChainLinkPriceCalls, getWeETHPrice, getWsrETHChainLinkPriceCalls, getWsrETHPrice, getWstETHChainLinkPriceCalls, getWstETHPrice, getWstETHPriceFluid, getWstUSRChainLinkPriceCalls, getWstUSRPrice, parseSyrupUSDTPriceCalls, parseWeETHPriceCalls, parseWrsETHPriceCalls, parseWstETHPriceCalls, parseWstUSRPriceCalls, } from '../services/priceService';
|
|
20
20
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
21
21
|
import { getViemProvider } from '../services/viem';
|
|
22
|
+
import { attachFluidMerklIncentives, getFluidMerklCampaigns } from './merkl';
|
|
23
|
+
export { FluidMerklOpportunityType, buildFluidMerklRewardMap, getFluidMerklCampaigns, attachFluidMerklIncentives, } from './merkl';
|
|
22
24
|
export const EMPTY_USED_ASSET = {
|
|
23
25
|
isSupplied: false,
|
|
24
26
|
isBorrowed: false,
|
|
@@ -1100,8 +1102,12 @@ const parseUserData = (userPositionData, vaultData) => {
|
|
|
1100
1102
|
};
|
|
1101
1103
|
export const _getFluidMarketData = (provider, network, market) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1102
1104
|
const view = FluidViewContractViem(provider, network);
|
|
1103
|
-
const data = yield
|
|
1104
|
-
|
|
1105
|
+
const [data, merklCampaigns] = yield Promise.all([
|
|
1106
|
+
view.read.getVaultData([market.marketAddress]),
|
|
1107
|
+
getFluidMerklCampaigns(network),
|
|
1108
|
+
]);
|
|
1109
|
+
const marketData = yield parseMarketData(provider, data, network);
|
|
1110
|
+
return marketData ? attachFluidMerklIncentives(marketData, merklCampaigns) : marketData;
|
|
1105
1111
|
});
|
|
1106
1112
|
export const getFluidMarketData = (provider, network, market) => __awaiter(void 0, void 0, void 0, function* () { return _getFluidMarketData(getViemProvider(provider, network), network, market); });
|
|
1107
1113
|
export const _getFluidVaultIdsForUser = (provider, network, user) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -1118,11 +1124,15 @@ export const _getFluidPosition = (provider, network, vaultId, extractedState) =>
|
|
|
1118
1124
|
export const getFluidPosition = (provider, network, vaultId, extractedState) => __awaiter(void 0, void 0, void 0, function* () { return _getFluidPosition(getViemProvider(provider, network), network, vaultId, extractedState); });
|
|
1119
1125
|
export const _getFluidPositionWithMarket = (provider, network, vaultId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1120
1126
|
const view = FluidViewContractViem(provider, network);
|
|
1121
|
-
const data = yield
|
|
1122
|
-
|
|
1123
|
-
|
|
1127
|
+
const [data, merklCampaigns] = yield Promise.all([
|
|
1128
|
+
view.read.getPositionByNftId([BigInt(vaultId)]),
|
|
1129
|
+
getFluidMerklCampaigns(network),
|
|
1130
|
+
]);
|
|
1131
|
+
const parsedMarketData = yield parseMarketData(provider, data[1], network);
|
|
1132
|
+
if (!parsedMarketData) {
|
|
1124
1133
|
return;
|
|
1125
1134
|
}
|
|
1135
|
+
const marketData = attachFluidMerklIncentives(parsedMarketData, merklCampaigns);
|
|
1126
1136
|
const userData = parseUserData(data[0], marketData);
|
|
1127
1137
|
return {
|
|
1128
1138
|
userData,
|
|
@@ -1133,8 +1143,14 @@ export const getFluidPositionWithMarket = (provider, network, vaultId) => __awai
|
|
|
1133
1143
|
export const _getAllFluidMarketDataChunked = (network, provider) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1134
1144
|
const versions = getFluidVersionsDataForNetwork(network);
|
|
1135
1145
|
const view = FluidViewContractViem(provider, network);
|
|
1136
|
-
const data = yield Promise.all(
|
|
1137
|
-
|
|
1146
|
+
const [data, merklCampaigns] = yield Promise.all([
|
|
1147
|
+
Promise.all(versions.map((version) => view.read.getVaultData([version.marketAddress]))),
|
|
1148
|
+
getFluidMerklCampaigns(network),
|
|
1149
|
+
]);
|
|
1150
|
+
return Promise.all(data.map((item) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1151
|
+
const marketData = yield parseMarketData(provider, item, network);
|
|
1152
|
+
return marketData ? attachFluidMerklIncentives(marketData, merklCampaigns) : marketData;
|
|
1153
|
+
})));
|
|
1138
1154
|
});
|
|
1139
1155
|
export const getAllFluidMarketDataChunked = (network, provider) => __awaiter(void 0, void 0, void 0, function* () { return _getAllFluidMarketDataChunked(network, getViemProvider(provider, network, { batch: { multicall: true } })); });
|
|
1140
1156
|
export const _getFluidTokenData = (provider, network, token) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { FluidMarketData, FluidMerklRewardMap, MerklOpportunity, NetworkNumber } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Merkl tags Fluid vault-scoped reward campaigns via the opportunity `type` field:
|
|
4
|
+
* - FLUIDVAULT_COLLATERAL → reward for supplying collateral to the vault
|
|
5
|
+
* - FLUIDVAULT_BORROW → reward for borrowing from the vault
|
|
6
|
+
* (ERC20LOGPROCESSOR campaigns target fToken earn positions rather than vaults, so they don't
|
|
7
|
+
* belong on vault market data.)
|
|
8
|
+
*
|
|
9
|
+
* A campaign identifies its vault via `identifier` — the vault address. Conditional campaigns
|
|
10
|
+
* append a marker to it (e.g. `0x5668…eeaBORROW_BL`, excluding holders who borrow the reward
|
|
11
|
+
* asset elsewhere); those are still attached, with the full identifier passed through as
|
|
12
|
+
* `eligibilityId` so a curated check in EligibilityMapping can gate them in net APY — unknown
|
|
13
|
+
* ids apply unconditionally, mirroring Aave V3. Whitelist-gated campaigns only accrue to
|
|
14
|
+
* whitelisted addresses, so they are skipped rather than advertised to every user.
|
|
15
|
+
*/
|
|
16
|
+
export declare enum FluidMerklOpportunityType {
|
|
17
|
+
Collateral = "FLUIDVAULT_COLLATERAL",
|
|
18
|
+
Borrow = "FLUIDVAULT_BORROW"
|
|
19
|
+
}
|
|
20
|
+
export declare const buildFluidMerklRewardMap: (opportunities: MerklOpportunity[], chainId: NetworkNumber) => FluidMerklRewardMap;
|
|
21
|
+
/**
|
|
22
|
+
* Fetches live vault-scoped Fluid campaigns for the chain, keyed by vault address. Never throws —
|
|
23
|
+
* on any failure it returns an empty map, so Merkl being down can't break market data.
|
|
24
|
+
*/
|
|
25
|
+
export declare const getFluidMerklCampaigns: (chainId: NetworkNumber) => Promise<FluidMerklRewardMap>;
|
|
26
|
+
/**
|
|
27
|
+
* Appends the vault's Merkl campaigns to its assets' incentive arrays — supply rewards on every
|
|
28
|
+
* suppliable asset and borrow rewards on every borrowable one. Smart collateral/debt vaults hold
|
|
29
|
+
* the position across both pair tokens, so the pro-rata reward APY applies to each side's value.
|
|
30
|
+
*/
|
|
31
|
+
export declare const attachFluidMerklIncentives: (marketData: FluidMarketData, campaigns: FluidMerklRewardMap) => FluidMarketData;
|
|
@@ -0,0 +1,93 @@
|
|
|
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 Fluid vault-scoped reward campaigns via the opportunity `type` field:
|
|
15
|
+
* - FLUIDVAULT_COLLATERAL → reward for supplying collateral to the vault
|
|
16
|
+
* - FLUIDVAULT_BORROW → reward for borrowing from the vault
|
|
17
|
+
* (ERC20LOGPROCESSOR campaigns target fToken earn positions rather than vaults, so they don't
|
|
18
|
+
* belong on vault market data.)
|
|
19
|
+
*
|
|
20
|
+
* A campaign identifies its vault via `identifier` — the vault address. Conditional campaigns
|
|
21
|
+
* append a marker to it (e.g. `0x5668…eeaBORROW_BL`, excluding holders who borrow the reward
|
|
22
|
+
* asset elsewhere); those are still attached, with the full identifier passed through as
|
|
23
|
+
* `eligibilityId` so a curated check in EligibilityMapping can gate them in net APY — unknown
|
|
24
|
+
* ids apply unconditionally, mirroring Aave V3. Whitelist-gated campaigns only accrue to
|
|
25
|
+
* whitelisted addresses, so they are skipped rather than advertised to every user.
|
|
26
|
+
*/
|
|
27
|
+
export var FluidMerklOpportunityType;
|
|
28
|
+
(function (FluidMerklOpportunityType) {
|
|
29
|
+
FluidMerklOpportunityType["Collateral"] = "FLUIDVAULT_COLLATERAL";
|
|
30
|
+
FluidMerklOpportunityType["Borrow"] = "FLUIDVAULT_BORROW";
|
|
31
|
+
})(FluidMerklOpportunityType || (FluidMerklOpportunityType = {}));
|
|
32
|
+
// '0x' + 20-byte vault address; conditional campaigns append a marker after it
|
|
33
|
+
const VAULT_ADDRESS_LENGTH = 42;
|
|
34
|
+
const buildMerklIncentive = (opportunity) => {
|
|
35
|
+
var _a, _b, _c, _d, _e, _f;
|
|
36
|
+
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) || '';
|
|
37
|
+
return {
|
|
38
|
+
apy: aprToApy(opportunity.apr),
|
|
39
|
+
token,
|
|
40
|
+
incentiveKind: IncentiveKind.Reward,
|
|
41
|
+
description: `Eligible for ${token} rewards through Merkl.${opportunity.description ? `\n${opportunity.description}` : ''}`,
|
|
42
|
+
eligibilityId: opportunity.identifier,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export const buildFluidMerklRewardMap = (opportunities, chainId) => {
|
|
46
|
+
const result = {};
|
|
47
|
+
opportunities
|
|
48
|
+
.filter((o) => o.chainId === chainId)
|
|
49
|
+
.filter((o) => o.status === OpportunityStatus.LIVE)
|
|
50
|
+
.filter((o) => Object.values(FluidMerklOpportunityType).includes(o.type))
|
|
51
|
+
.filter((o) => { var _a; return !((_a = o.identifier) === null || _a === void 0 ? void 0 : _a.includes('WHITELIST')); })
|
|
52
|
+
.forEach((o) => {
|
|
53
|
+
var _a;
|
|
54
|
+
const vaultAddress = (_a = o.identifier) === null || _a === void 0 ? void 0 : _a.slice(0, VAULT_ADDRESS_LENGTH).toLowerCase();
|
|
55
|
+
if (!vaultAddress || vaultAddress.length !== VAULT_ADDRESS_LENGTH)
|
|
56
|
+
return;
|
|
57
|
+
if (!result[vaultAddress])
|
|
58
|
+
result[vaultAddress] = { supply: [], borrow: [] };
|
|
59
|
+
result[vaultAddress][o.type === FluidMerklOpportunityType.Borrow ? 'borrow' : 'supply'].push(buildMerklIncentive(o));
|
|
60
|
+
});
|
|
61
|
+
return result;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Fetches live vault-scoped Fluid campaigns for the chain, keyed by vault address. Never throws —
|
|
65
|
+
* on any failure it returns an empty map, so Merkl being down can't break market data.
|
|
66
|
+
*/
|
|
67
|
+
export const getFluidMerklCampaigns = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
try {
|
|
69
|
+
const opportunities = yield fetchAllMerklOpportunities({
|
|
70
|
+
mainProtocolId: 'fluid',
|
|
71
|
+
type: Object.values(FluidMerklOpportunityType).join(','),
|
|
72
|
+
status: OpportunityStatus.LIVE,
|
|
73
|
+
});
|
|
74
|
+
return buildFluidMerklRewardMap(opportunities, chainId);
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
console.error('Failed to fetch Fluid Merkl campaigns', e);
|
|
78
|
+
return {};
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
/**
|
|
82
|
+
* Appends the vault's Merkl campaigns to its assets' incentive arrays — supply rewards on every
|
|
83
|
+
* suppliable asset and borrow rewards on every borrowable one. Smart collateral/debt vaults hold
|
|
84
|
+
* the position across both pair tokens, so the pro-rata reward APY applies to each side's value.
|
|
85
|
+
*/
|
|
86
|
+
export const attachFluidMerklIncentives = (marketData, campaigns) => {
|
|
87
|
+
var _a;
|
|
88
|
+
const vaultCampaigns = campaigns[(_a = marketData.marketData.marketAddress) === null || _a === void 0 ? void 0 : _a.toLowerCase()];
|
|
89
|
+
if (!vaultCampaigns || (!vaultCampaigns.supply.length && !vaultCampaigns.borrow.length))
|
|
90
|
+
return marketData;
|
|
91
|
+
const assetsData = Object.fromEntries(Object.entries(marketData.assetsData).map(([symbol, asset]) => [symbol, Object.assign(Object.assign({}, asset), { supplyIncentives: asset.canBeSupplied ? [...asset.supplyIncentives, ...vaultCampaigns.supply] : asset.supplyIncentives, borrowIncentives: asset.canBeBorrowed ? [...asset.borrowIncentives, ...vaultCampaigns.borrow] : asset.borrowIncentives })]));
|
|
92
|
+
return Object.assign(Object.assign({}, marketData), { assetsData });
|
|
93
|
+
};
|