@defisaver/positions-sdk 2.1.127-midnight-14-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 -0
- package/cjs/helpers/morphoMidnightHelpers/index.js +10 -4
- 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/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/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 -0
- package/esm/helpers/morphoMidnightHelpers/index.js +7 -3
- 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/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/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 -3
- 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/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
|
@@ -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
|
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
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { getAssetInfoByAddress } from '@defisaver/tokens';
|
|
2
|
+
import { aprToApy } from '../moneymarket';
|
|
3
|
+
import { fetchAllMerklOpportunities } from '../services/merkl';
|
|
4
|
+
import { compareAddresses, wethToEth } from '../services/utils';
|
|
5
|
+
import {
|
|
6
|
+
CompoundV3AssetData,
|
|
7
|
+
IncentiveData,
|
|
8
|
+
IncentiveEligibilityId,
|
|
9
|
+
IncentiveKind,
|
|
10
|
+
MerklOpportunity,
|
|
11
|
+
NetworkNumber,
|
|
12
|
+
OpportunityAction,
|
|
13
|
+
OpportunityStatus,
|
|
14
|
+
} from '../types';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Merkl tags Compound V3 reward campaigns with COMPOUND_V3_* opportunity types (e.g.
|
|
18
|
+
* COMPOUND_V3_BORROW_FROM_COLLATERAL) and identifies the comet via `explorerAddress`. Campaign
|
|
19
|
+
* identifiers are opaque hashes, passed through as `eligibilityId` so conditional campaigns —
|
|
20
|
+
* like borrow-from-collateral ones, whose reward is min(collateral * LTV, borrow amount) — can
|
|
21
|
+
* be gated and sized by a curated check in EligibilityMapping; unknown ids apply
|
|
22
|
+
* unconditionally, mirroring Aave V3.
|
|
23
|
+
*/
|
|
24
|
+
export const getCompoundV3MerklOpportunities = async (): Promise<MerklOpportunity[]> => {
|
|
25
|
+
try {
|
|
26
|
+
return await fetchAllMerklOpportunities({
|
|
27
|
+
mainProtocolId: 'compound-v3',
|
|
28
|
+
status: OpportunityStatus.LIVE,
|
|
29
|
+
});
|
|
30
|
+
} catch (e) {
|
|
31
|
+
console.error('Failed to fetch Compound V3 Merkl campaigns', e);
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const buildMerklIncentive = (opportunity: MerklOpportunity): IncentiveData => {
|
|
37
|
+
const token = opportunity.rewardsRecord?.breakdowns?.[0]?.token?.symbol || opportunity.tokens?.[0]?.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 as IncentiveEligibilityId,
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Appends the comet's Merkl campaigns to its assets' incentive arrays (mutating them, like the
|
|
49
|
+
* staking incentives are attached). BORROW campaigns land on the base asset — the only borrowable
|
|
50
|
+
* one — while LEND campaigns land on the asset the campaign's first token resolves to.
|
|
51
|
+
*/
|
|
52
|
+
export const attachCompoundV3MerklIncentives = (
|
|
53
|
+
baseAsset: CompoundV3AssetData,
|
|
54
|
+
collAssets: CompoundV3AssetData[],
|
|
55
|
+
baseMarketAddress: string,
|
|
56
|
+
chainId: NetworkNumber,
|
|
57
|
+
opportunities: MerklOpportunity[],
|
|
58
|
+
): void => {
|
|
59
|
+
opportunities
|
|
60
|
+
.filter((o) => o.chainId === chainId
|
|
61
|
+
&& o.status === OpportunityStatus.LIVE
|
|
62
|
+
&& typeof o.type === 'string' && o.type.startsWith('COMPOUND_V3')
|
|
63
|
+
&& o.explorerAddress && compareAddresses(o.explorerAddress, baseMarketAddress))
|
|
64
|
+
.forEach((o) => {
|
|
65
|
+
const incentive = buildMerklIncentive(o);
|
|
66
|
+
if (o.action === OpportunityAction.BORROW) {
|
|
67
|
+
baseAsset.borrowIncentives.push(incentive);
|
|
68
|
+
} else if (o.action === OpportunityAction.LEND) {
|
|
69
|
+
const campaignTokenAddress = o.tokens?.[0]?.address;
|
|
70
|
+
if (!campaignTokenAddress) return;
|
|
71
|
+
const campaignSymbol = wethToEth(getAssetInfoByAddress(campaignTokenAddress, chainId).symbol);
|
|
72
|
+
const target = [baseAsset, ...collAssets].find((asset) => asset.symbol === campaignSymbol);
|
|
73
|
+
target?.supplyIncentives.push(incentive);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
};
|
package/src/fluid/index.ts
CHANGED
|
@@ -66,6 +66,14 @@ import {
|
|
|
66
66
|
} from '../services/priceService';
|
|
67
67
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
68
68
|
import { getViemProvider } from '../services/viem';
|
|
69
|
+
import { attachFluidMerklIncentives, getFluidMerklCampaigns } from './merkl';
|
|
70
|
+
|
|
71
|
+
export {
|
|
72
|
+
FluidMerklOpportunityType,
|
|
73
|
+
buildFluidMerklRewardMap,
|
|
74
|
+
getFluidMerklCampaigns,
|
|
75
|
+
attachFluidMerklIncentives,
|
|
76
|
+
} from './merkl';
|
|
69
77
|
|
|
70
78
|
export const EMPTY_USED_ASSET = {
|
|
71
79
|
isSupplied: false,
|
|
@@ -1146,6 +1154,8 @@ export const EMPTY_FLUID_DATA = {
|
|
|
1146
1154
|
minRatio: '0',
|
|
1147
1155
|
netApy: '0',
|
|
1148
1156
|
incentiveUsd: '0',
|
|
1157
|
+
merklSupplyIncentives: [],
|
|
1158
|
+
merklBorrowIncentives: [],
|
|
1149
1159
|
totalInterestUsd: '0',
|
|
1150
1160
|
isSubscribedToAutomation: false,
|
|
1151
1161
|
automationResubscribeRequired: false,
|
|
@@ -1442,9 +1452,13 @@ const parseUserData = (userPositionData: FluidUserPositionStructOutputStruct, va
|
|
|
1442
1452
|
export const _getFluidMarketData = async (provider: PublicClient, network: NetworkNumber, market: FluidMarketInfo) => {
|
|
1443
1453
|
const view = FluidViewContractViem(provider, network);
|
|
1444
1454
|
|
|
1445
|
-
const data = await
|
|
1455
|
+
const [data, merklCampaigns] = await Promise.all([
|
|
1456
|
+
view.read.getVaultData([market.marketAddress]),
|
|
1457
|
+
getFluidMerklCampaigns(network),
|
|
1458
|
+
]);
|
|
1446
1459
|
|
|
1447
|
-
|
|
1460
|
+
const marketData = await parseMarketData(provider, data, network);
|
|
1461
|
+
return marketData ? attachFluidMerklIncentives(marketData, merklCampaigns) : marketData;
|
|
1448
1462
|
};
|
|
1449
1463
|
|
|
1450
1464
|
export const getFluidMarketData = async (
|
|
@@ -1500,11 +1514,15 @@ export const getFluidPosition = async (
|
|
|
1500
1514
|
|
|
1501
1515
|
export const _getFluidPositionWithMarket = async (provider: PublicClient, network: NetworkNumber, vaultId: string) => {
|
|
1502
1516
|
const view = FluidViewContractViem(provider, network);
|
|
1503
|
-
const data = await
|
|
1504
|
-
|
|
1505
|
-
|
|
1517
|
+
const [data, merklCampaigns] = await Promise.all([
|
|
1518
|
+
view.read.getPositionByNftId([BigInt(vaultId)]),
|
|
1519
|
+
getFluidMerklCampaigns(network),
|
|
1520
|
+
]);
|
|
1521
|
+
const parsedMarketData = await parseMarketData(provider, data[1], network);
|
|
1522
|
+
if (!parsedMarketData) {
|
|
1506
1523
|
return;
|
|
1507
1524
|
}
|
|
1525
|
+
const marketData = attachFluidMerklIncentives(parsedMarketData, merklCampaigns);
|
|
1508
1526
|
const userData = parseUserData(data[0], marketData);
|
|
1509
1527
|
|
|
1510
1528
|
return {
|
|
@@ -1522,8 +1540,14 @@ export const getFluidPositionWithMarket = async (
|
|
|
1522
1540
|
export const _getAllFluidMarketDataChunked = async (network: NetworkNumber, provider: PublicClient) => {
|
|
1523
1541
|
const versions = getFluidVersionsDataForNetwork(network);
|
|
1524
1542
|
const view = FluidViewContractViem(provider, network);
|
|
1525
|
-
const data = await Promise.all(
|
|
1526
|
-
|
|
1543
|
+
const [data, merklCampaigns] = await Promise.all([
|
|
1544
|
+
Promise.all(versions.map((version) => view.read.getVaultData([version.marketAddress]))),
|
|
1545
|
+
getFluidMerklCampaigns(network),
|
|
1546
|
+
]);
|
|
1547
|
+
return Promise.all(data.map(async (item) => {
|
|
1548
|
+
const marketData = await parseMarketData(provider, item, network);
|
|
1549
|
+
return marketData ? attachFluidMerklIncentives(marketData, merklCampaigns) : marketData;
|
|
1550
|
+
}));
|
|
1527
1551
|
};
|
|
1528
1552
|
|
|
1529
1553
|
export const getAllFluidMarketDataChunked = async (
|
|
@@ -1787,9 +1811,13 @@ export const _getUserPositionsPortfolio = async (provider: PublicClient, network
|
|
|
1787
1811
|
if (!tokens.includes('ETH')) tokens.push('ETH');
|
|
1788
1812
|
if (!tokens.includes('WBTC')) tokens.push('WBTC');
|
|
1789
1813
|
|
|
1790
|
-
const tokenPrices = await
|
|
1814
|
+
const [tokenPrices, merklCampaigns] = await Promise.all([
|
|
1815
|
+
getTokensPricesForPortfolio(tokens, provider, network),
|
|
1816
|
+
getFluidMerklCampaigns(network),
|
|
1817
|
+
]);
|
|
1791
1818
|
|
|
1792
|
-
const parsedMarketData = (await Promise.all(data[1].map(async (vaultData) => parseMarketData(provider, vaultData, network, tokenPrices))))
|
|
1819
|
+
const parsedMarketData = (await Promise.all(data[1].map(async (vaultData) => parseMarketData(provider, vaultData, network, tokenPrices))))
|
|
1820
|
+
.map(marketData => (marketData ? attachFluidMerklIncentives(marketData, merklCampaigns) : marketData));
|
|
1793
1821
|
|
|
1794
1822
|
const userData = data[0].map((position, i) => (parsedMarketData[i] && { ...parseUserData(position, parsedMarketData[i]) }));
|
|
1795
1823
|
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import memoize from 'memoizee';
|
|
2
|
+
import { aprToApy } from '../moneymarket';
|
|
3
|
+
import { fetchAllMerklOpportunities } from '../services/merkl';
|
|
4
|
+
import {
|
|
5
|
+
FluidMarketData,
|
|
6
|
+
FluidMerklRewardMap,
|
|
7
|
+
IncentiveData,
|
|
8
|
+
IncentiveEligibilityId,
|
|
9
|
+
IncentiveKind,
|
|
10
|
+
IncentiveSource,
|
|
11
|
+
MerklOpportunity,
|
|
12
|
+
NetworkNumber,
|
|
13
|
+
OpportunityStatus,
|
|
14
|
+
} from '../types';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Merkl tags Fluid vault-scoped reward campaigns via the opportunity `type` field:
|
|
18
|
+
* - FLUIDVAULT_COLLATERAL → reward for supplying collateral to the vault
|
|
19
|
+
* - FLUIDVAULT_BORROW → reward for borrowing from the vault
|
|
20
|
+
* (ERC20LOGPROCESSOR campaigns target fToken earn positions rather than vaults, so they don't
|
|
21
|
+
* belong on vault market data.)
|
|
22
|
+
*
|
|
23
|
+
* A campaign identifies its vault via `identifier` — the vault address. Conditional campaigns
|
|
24
|
+
* append a marker to it (e.g. `0x5668…eeaBORROW_BL`, excluding holders who borrow the reward
|
|
25
|
+
* asset elsewhere); those are still attached, with the full identifier passed through as
|
|
26
|
+
* `eligibilityId` so a curated check in EligibilityMapping can gate them in net APY — unknown
|
|
27
|
+
* ids apply unconditionally, mirroring Aave V3. Whitelist-gated campaigns only accrue to
|
|
28
|
+
* whitelisted addresses, so they are skipped rather than advertised to every user.
|
|
29
|
+
*/
|
|
30
|
+
export enum FluidMerklOpportunityType {
|
|
31
|
+
Collateral = 'FLUIDVAULT_COLLATERAL',
|
|
32
|
+
Borrow = 'FLUIDVAULT_BORROW',
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// '0x' + 20-byte vault address; conditional campaigns append a marker after it
|
|
36
|
+
const VAULT_ADDRESS_LENGTH = 42;
|
|
37
|
+
|
|
38
|
+
const buildMerklIncentive = (opportunity: MerklOpportunity): IncentiveData => {
|
|
39
|
+
const token = opportunity.rewardsRecord?.breakdowns?.[0]?.token?.symbol || opportunity.tokens?.[0]?.symbol || '';
|
|
40
|
+
return {
|
|
41
|
+
apy: aprToApy(opportunity.apr),
|
|
42
|
+
token,
|
|
43
|
+
incentiveKind: IncentiveKind.Reward,
|
|
44
|
+
source: IncentiveSource.Merkl,
|
|
45
|
+
description: `Eligible for ${token} rewards through Merkl.${opportunity.description ? `\n${opportunity.description}` : ''}`,
|
|
46
|
+
eligibilityId: opportunity.identifier as IncentiveEligibilityId,
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const buildFluidMerklRewardMap = (opportunities: MerklOpportunity[], chainId: NetworkNumber): FluidMerklRewardMap => {
|
|
51
|
+
const result: FluidMerklRewardMap = {};
|
|
52
|
+
|
|
53
|
+
opportunities
|
|
54
|
+
.filter((o) => o.chainId === chainId)
|
|
55
|
+
.filter((o) => o.status === OpportunityStatus.LIVE)
|
|
56
|
+
.filter((o) => Object.values(FluidMerklOpportunityType).includes(o.type as FluidMerklOpportunityType))
|
|
57
|
+
.filter((o) => !o.identifier?.includes('WHITELIST'))
|
|
58
|
+
.forEach((o) => {
|
|
59
|
+
const vaultAddress = o.identifier?.slice(0, VAULT_ADDRESS_LENGTH).toLowerCase();
|
|
60
|
+
if (!vaultAddress || vaultAddress.length !== VAULT_ADDRESS_LENGTH) return;
|
|
61
|
+
if (!result[vaultAddress]) result[vaultAddress] = { supply: [], borrow: [] };
|
|
62
|
+
result[vaultAddress][o.type === FluidMerklOpportunityType.Borrow ? 'borrow' : 'supply'].push(buildMerklIncentive(o));
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return result;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Fetches live vault-scoped Fluid campaigns for the chain, keyed by vault address. Never throws —
|
|
70
|
+
* on any failure it returns an empty map, so Merkl being down can't break market data.
|
|
71
|
+
*/
|
|
72
|
+
export const getFluidMerklCampaigns = memoize(async (chainId: NetworkNumber): Promise<FluidMerklRewardMap> => {
|
|
73
|
+
try {
|
|
74
|
+
const opportunities = await fetchAllMerklOpportunities({
|
|
75
|
+
mainProtocolId: 'fluid',
|
|
76
|
+
type: Object.values(FluidMerklOpportunityType).join(','),
|
|
77
|
+
status: OpportunityStatus.LIVE,
|
|
78
|
+
});
|
|
79
|
+
return buildFluidMerklRewardMap(opportunities, chainId);
|
|
80
|
+
} catch (e) {
|
|
81
|
+
console.error('Failed to fetch Fluid Merkl campaigns', e);
|
|
82
|
+
return {};
|
|
83
|
+
}
|
|
84
|
+
}, { promise: true, maxAge: 60 * 1000 });
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Appends the vault's Merkl campaigns to its assets' incentive arrays — supply rewards on every
|
|
88
|
+
* suppliable asset and borrow rewards on every borrowable one. Smart collateral/debt vaults hold
|
|
89
|
+
* the position across both pair tokens, so the pro-rata reward APY applies to each side's value.
|
|
90
|
+
*/
|
|
91
|
+
export const attachFluidMerklIncentives = (marketData: FluidMarketData, campaigns: FluidMerklRewardMap): FluidMarketData => {
|
|
92
|
+
const vaultCampaigns = campaigns[marketData.marketData.marketAddress?.toLowerCase()];
|
|
93
|
+
if (!vaultCampaigns || (!vaultCampaigns.supply.length && !vaultCampaigns.borrow.length)) return marketData;
|
|
94
|
+
|
|
95
|
+
const assetsData = Object.fromEntries(Object.entries(marketData.assetsData).map(([symbol, asset]) => [symbol, {
|
|
96
|
+
...asset,
|
|
97
|
+
supplyIncentives: asset.canBeSupplied ? [...asset.supplyIncentives, ...vaultCampaigns.supply] : asset.supplyIncentives,
|
|
98
|
+
borrowIncentives: asset.canBeBorrowed ? [...asset.borrowIncentives, ...vaultCampaigns.borrow] : asset.borrowIncentives,
|
|
99
|
+
}]));
|
|
100
|
+
|
|
101
|
+
return { ...marketData, assetsData };
|
|
102
|
+
};
|