@defisaver/positions-sdk 2.1.103 → 2.1.105
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/aaveV4/index.d.ts +1 -0
- package/cjs/aaveV4/index.js +8 -3
- package/cjs/aaveV4/merkl.d.ts +8 -0
- package/cjs/aaveV4/merkl.js +90 -0
- package/cjs/claiming/aaveV3.d.ts +1 -1
- package/cjs/claiming/aaveV3.js +3 -4
- package/cjs/claiming/index.d.ts +1 -2
- package/cjs/claiming/index.js +1 -3
- package/cjs/config/contracts.d.ts +0 -214
- package/cjs/config/contracts.js +1 -6
- package/cjs/helpers/morphoBlueHelpers/index.d.ts +0 -1
- package/cjs/helpers/morphoBlueHelpers/index.js +27 -32
- package/cjs/portfolio/index.js +0 -27
- package/cjs/types/aaveV4.d.ts +10 -0
- package/cjs/types/claiming.d.ts +1 -13
- package/cjs/types/claiming.js +0 -2
- package/cjs/types/merkl.d.ts +14 -1
- package/cjs/types/morphoBlue.d.ts +2 -3
- package/esm/aaveV4/index.d.ts +1 -0
- package/esm/aaveV4/index.js +6 -2
- package/esm/aaveV4/merkl.d.ts +8 -0
- package/esm/aaveV4/merkl.js +85 -0
- package/esm/claiming/aaveV3.d.ts +1 -1
- package/esm/claiming/aaveV3.js +3 -4
- package/esm/claiming/index.d.ts +1 -2
- package/esm/claiming/index.js +1 -2
- package/esm/config/contracts.d.ts +0 -214
- package/esm/config/contracts.js +0 -4
- package/esm/helpers/morphoBlueHelpers/index.d.ts +0 -1
- package/esm/helpers/morphoBlueHelpers/index.js +27 -31
- package/esm/portfolio/index.js +0 -27
- package/esm/types/aaveV4.d.ts +10 -0
- package/esm/types/claiming.d.ts +1 -13
- package/esm/types/claiming.js +0 -2
- package/esm/types/merkl.d.ts +14 -1
- package/esm/types/morphoBlue.d.ts +2 -3
- package/package.json +1 -1
- package/src/aaveV4/index.ts +7 -2
- package/src/aaveV4/merkl.ts +92 -0
- package/src/claiming/aaveV3.ts +2 -3
- package/src/claiming/index.ts +0 -2
- package/src/config/contracts.ts +0 -4
- package/src/helpers/morphoBlueHelpers/index.ts +29 -32
- package/src/portfolio/index.ts +0 -25
- package/src/types/aaveV4.ts +10 -0
- package/src/types/claiming.ts +0 -15
- package/src/types/merkl.ts +14 -2
- package/src/types/morphoBlue.ts +2 -3
- package/cjs/claiming/morphoBlue.d.ts +0 -5
- package/cjs/claiming/morphoBlue.js +0 -113
- package/esm/claiming/morphoBlue.d.ts +0 -5
- package/esm/claiming/morphoBlue.js +0 -105
- package/src/claiming/morphoBlue.ts +0 -119
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.getRewardsForMarket = exports.getReallocation = exports.getLiquidityToAllocate = exports.getReallocatableLiquidity = exports.getApyAfterValuesEstimation = exports.getBorrowRate = exports.getSupplyRate = exports.getMorphoBlueAggregatedPositionData = void 0;
|
|
16
16
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
17
17
|
const tokens_1 = require("@defisaver/tokens");
|
|
18
18
|
const moneymarket_1 = require("../../moneymarket");
|
|
@@ -138,12 +138,13 @@ const getApyAfterValuesEstimation = (selectedMarket, actions, provider, network)
|
|
|
138
138
|
return { borrowRate, supplyRate };
|
|
139
139
|
});
|
|
140
140
|
exports.getApyAfterValuesEstimation = getApyAfterValuesEstimation;
|
|
141
|
-
const API_URL = 'https://
|
|
141
|
+
const API_URL = 'https://api.morpho.org/graphql';
|
|
142
|
+
// Morpho Blue ACRM (Adaptive Curve IRM) always targets 90% utilization — protocol constant
|
|
143
|
+
const ACRM_TARGET_UTILIZATION = '900000000000000000';
|
|
142
144
|
const MARKET_QUERY = `
|
|
143
|
-
query MarketByUniqueKey($
|
|
144
|
-
|
|
145
|
+
query MarketByUniqueKey($marketId: String!, $chainId: Int!) {
|
|
146
|
+
marketById(marketId: $marketId, chainId: $chainId) {
|
|
145
147
|
reallocatableLiquidityAssets
|
|
146
|
-
targetBorrowUtilization
|
|
147
148
|
loanAsset {
|
|
148
149
|
address
|
|
149
150
|
decimals
|
|
@@ -160,8 +161,8 @@ const MARKET_QUERY = `
|
|
|
160
161
|
address
|
|
161
162
|
name
|
|
162
163
|
}
|
|
163
|
-
|
|
164
|
-
|
|
164
|
+
withdrawMarket {
|
|
165
|
+
marketId
|
|
165
166
|
loanAsset {
|
|
166
167
|
address
|
|
167
168
|
}
|
|
@@ -185,14 +186,14 @@ const MARKET_QUERY = `
|
|
|
185
186
|
address
|
|
186
187
|
}
|
|
187
188
|
irmAddress
|
|
188
|
-
lltv
|
|
189
|
+
lltv
|
|
189
190
|
}
|
|
190
191
|
}
|
|
191
192
|
`;
|
|
192
193
|
const REWARDS_QUERY = `
|
|
193
|
-
query MarketByUniqueKey($
|
|
194
|
-
|
|
195
|
-
|
|
194
|
+
query MarketByUniqueKey($marketId: String!, $chainId: Int!) {
|
|
195
|
+
marketById(marketId: $marketId, chainId: $chainId) {
|
|
196
|
+
marketId
|
|
196
197
|
state {
|
|
197
198
|
rewards {
|
|
198
199
|
amountPerSuppliedToken
|
|
@@ -221,17 +222,17 @@ const getReallocatableLiquidity = (marketId_1, ...args_1) => __awaiter(void 0, [
|
|
|
221
222
|
headers: { 'Content-Type': 'application/json' },
|
|
222
223
|
body: JSON.stringify({
|
|
223
224
|
query: MARKET_QUERY,
|
|
224
|
-
variables: {
|
|
225
|
+
variables: { marketId, chainId: network },
|
|
225
226
|
}),
|
|
226
227
|
signal: AbortSignal.timeout(utils_1.LONGER_TIMEOUT),
|
|
227
228
|
});
|
|
228
229
|
const data = yield response.json();
|
|
229
|
-
const marketData = (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.
|
|
230
|
+
const marketData = (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.marketById;
|
|
230
231
|
if (!marketData)
|
|
231
232
|
throw new Error('Market data not found');
|
|
232
233
|
return {
|
|
233
234
|
reallocatableLiquidity: marketData.reallocatableLiquidityAssets,
|
|
234
|
-
targetBorrowUtilization:
|
|
235
|
+
targetBorrowUtilization: ACRM_TARGET_UTILIZATION,
|
|
235
236
|
};
|
|
236
237
|
}
|
|
237
238
|
catch (error) {
|
|
@@ -285,12 +286,12 @@ const getReallocation = (market_1, assetsData_1, amountToBorrow_1, ...args_1) =>
|
|
|
285
286
|
headers: { 'Content-Type': 'application/json' },
|
|
286
287
|
body: JSON.stringify({
|
|
287
288
|
query: MARKET_QUERY,
|
|
288
|
-
variables: {
|
|
289
|
+
variables: { marketId, chainId: network },
|
|
289
290
|
}),
|
|
290
291
|
signal: AbortSignal.timeout(utils_1.LONGER_TIMEOUT),
|
|
291
292
|
});
|
|
292
293
|
const data = yield response.json();
|
|
293
|
-
const marketData = (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.
|
|
294
|
+
const marketData = (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.marketById;
|
|
294
295
|
if (!marketData)
|
|
295
296
|
throw new Error('Market data not found');
|
|
296
297
|
const loanAssetInfo = (0, tokens_1.getAssetInfoByAddress)(loanToken, network);
|
|
@@ -300,9 +301,9 @@ const getReallocation = (market_1, assetsData_1, amountToBorrow_1, ...args_1) =>
|
|
|
300
301
|
const newTotalBorrowAssets = new decimal_js_1.default(totalBorrowWei).add(amountToBorrow).toString();
|
|
301
302
|
const newUtil = new decimal_js_1.default(newTotalBorrowAssets).div(totalSupplyWei).toString();
|
|
302
303
|
const newUtilScaled = new decimal_js_1.default(newUtil).mul(1e18).toString();
|
|
303
|
-
if (new decimal_js_1.default(newUtilScaled).lt(
|
|
304
|
+
if (new decimal_js_1.default(newUtilScaled).lt(ACRM_TARGET_UTILIZATION))
|
|
304
305
|
return { vaults: [], withdrawals: [] };
|
|
305
|
-
const liquidityToAllocate = (0, exports.getLiquidityToAllocate)(amountToBorrow, totalBorrowWei, totalSupplyWei,
|
|
306
|
+
const liquidityToAllocate = (0, exports.getLiquidityToAllocate)(amountToBorrow, totalBorrowWei, totalSupplyWei, ACRM_TARGET_UTILIZATION, marketData.reallocatableLiquidityAssets);
|
|
306
307
|
const vaultTotalAssets = marketData.publicAllocatorSharedLiquidity.reduce((acc, item) => {
|
|
307
308
|
const vaultAddress = item.vault.address;
|
|
308
309
|
acc[vaultAddress] = new decimal_js_1.default(acc[vaultAddress] || '0').add(item.assets).toString();
|
|
@@ -324,14 +325,14 @@ const getReallocation = (market_1, assetsData_1, amountToBorrow_1, ...args_1) =>
|
|
|
324
325
|
totalReallocated = new decimal_js_1.default(totalReallocated).add(amountToTake).toString();
|
|
325
326
|
const withdrawal = [
|
|
326
327
|
[
|
|
327
|
-
item.
|
|
328
|
-
(_b = item.
|
|
329
|
-
(_c = item.
|
|
330
|
-
item.
|
|
331
|
-
item.
|
|
328
|
+
item.withdrawMarket.loanAsset.address,
|
|
329
|
+
(_b = item.withdrawMarket.collateralAsset) === null || _b === void 0 ? void 0 : _b.address,
|
|
330
|
+
(_c = item.withdrawMarket.oracle) === null || _c === void 0 ? void 0 : _c.address,
|
|
331
|
+
item.withdrawMarket.irmAddress,
|
|
332
|
+
item.withdrawMarket.lltv,
|
|
332
333
|
],
|
|
333
334
|
amountToTake.toString(),
|
|
334
|
-
item.
|
|
335
|
+
item.withdrawMarket.marketId,
|
|
335
336
|
];
|
|
336
337
|
if (!withdrawalsPerVault[vaultAddress]) {
|
|
337
338
|
withdrawalsPerVault[vaultAddress] = [];
|
|
@@ -359,11 +360,11 @@ const getRewardsForMarket = (marketId_1, ...args_1) => __awaiter(void 0, [market
|
|
|
359
360
|
headers: { 'Content-Type': 'application/json' },
|
|
360
361
|
body: JSON.stringify({
|
|
361
362
|
query: REWARDS_QUERY,
|
|
362
|
-
variables: {
|
|
363
|
+
variables: { marketId, chainId: network },
|
|
363
364
|
}),
|
|
364
365
|
});
|
|
365
366
|
const data = yield response.json();
|
|
366
|
-
const marketData = (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.
|
|
367
|
+
const marketData = (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.marketById;
|
|
367
368
|
if (!marketData)
|
|
368
369
|
throw new Error('Market data not found');
|
|
369
370
|
const morphoAssetInfo = (0, tokens_1.getAssetInfo)('MORPHO');
|
|
@@ -373,9 +374,3 @@ const getRewardsForMarket = (marketId_1, ...args_1) => __awaiter(void 0, [market
|
|
|
373
374
|
return { supplyApy: (0, moneymarket_1.aprToApy)(supplyAprPercent), borrowApy: (0, moneymarket_1.aprToApy)(borrowAprPercent) };
|
|
374
375
|
});
|
|
375
376
|
exports.getRewardsForMarket = getRewardsForMarket;
|
|
376
|
-
const getMorphoUnderlyingSymbol = (_symbol) => {
|
|
377
|
-
if (_symbol === 'MORPHO Legacy')
|
|
378
|
-
return 'MORPHO';
|
|
379
|
-
return (0, utils_1.wethToEth)(_symbol);
|
|
380
|
-
};
|
|
381
|
-
exports.getMorphoUnderlyingSymbol = getMorphoUnderlyingSymbol;
|
package/cjs/portfolio/index.js
CHANGED
|
@@ -37,7 +37,6 @@ const umbrella_1 = require("../umbrella");
|
|
|
37
37
|
const aaveV3_2 = require("../claiming/aaveV3");
|
|
38
38
|
const compV3_1 = require("../claiming/compV3");
|
|
39
39
|
const spark_2 = require("../claiming/spark");
|
|
40
|
-
const morphoBlue_2 = require("../claiming/morphoBlue");
|
|
41
40
|
const king_1 = require("../claiming/king");
|
|
42
41
|
const ethena_1 = require("../claiming/ethena");
|
|
43
42
|
const aaveV4_1 = require("../aaveV4");
|
|
@@ -45,7 +44,6 @@ function getPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1)
|
|
|
45
44
|
return __awaiter(this, arguments, void 0, function* (provider, network, defaultProvider, addresses, isSim = false) {
|
|
46
45
|
const isMainnet = network === common_1.NetworkNumber.Eth;
|
|
47
46
|
const isFluidSupported = [common_1.NetworkNumber.Eth, common_1.NetworkNumber.Arb, common_1.NetworkNumber.Base, common_1.NetworkNumber.Plasma].includes(network);
|
|
48
|
-
const isMorphoRewardsSupported = [common_1.NetworkNumber.Eth, common_1.NetworkNumber.Base].includes(network);
|
|
49
47
|
const morphoMarkets = Object.values((0, markets_1.MorphoBlueMarkets)(network)).filter((market) => market.chainIds.includes(network));
|
|
50
48
|
const compoundV3Markets = Object.values((0, markets_1.CompoundMarkets)(network)).filter((market) => market.chainIds.includes(network) && market.value !== types_1.CompoundVersions.CompoundV2);
|
|
51
49
|
const sparkMarkets = Object.values((0, markets_1.SparkMarkets)(network)).filter((market) => market.chainIds.includes(network));
|
|
@@ -133,7 +131,6 @@ function getPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1)
|
|
|
133
131
|
spark: {},
|
|
134
132
|
spk: {},
|
|
135
133
|
king: {},
|
|
136
|
-
morpho: {},
|
|
137
134
|
ethena: {},
|
|
138
135
|
};
|
|
139
136
|
}
|
|
@@ -343,30 +340,6 @@ function getPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1)
|
|
|
343
340
|
rewardsData[address.toLowerCase()].aaveV3 = { error: `Error fetching Aave V3 rewards data for address ${address}`, data: null };
|
|
344
341
|
}
|
|
345
342
|
}))).flat(),
|
|
346
|
-
// Batch Morpho Blue rewards
|
|
347
|
-
(() => __awaiter(this, void 0, void 0, function* () {
|
|
348
|
-
if (!isMorphoRewardsSupported)
|
|
349
|
-
return;
|
|
350
|
-
try {
|
|
351
|
-
const morphoRewards = yield (0, morphoBlue_2.fetchMorphoBlueRewards)(client, network, addresses);
|
|
352
|
-
for (const address of addresses) {
|
|
353
|
-
const lowerAddress = address.toLowerCase();
|
|
354
|
-
rewardsData[lowerAddress].morpho = {
|
|
355
|
-
error: '',
|
|
356
|
-
data: morphoRewards[lowerAddress] || [],
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
catch (error) {
|
|
361
|
-
console.error('Error fetching Morpho Blue rewards data in batch:', error);
|
|
362
|
-
for (const address of addresses) {
|
|
363
|
-
rewardsData[address.toLowerCase()].morpho = {
|
|
364
|
-
error: 'Error fetching Morpho Blue rewards data in batch',
|
|
365
|
-
data: null,
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}))(),
|
|
370
343
|
// Batch Spark Airdrop rewards
|
|
371
344
|
(() => __awaiter(this, void 0, void 0, function* () {
|
|
372
345
|
try {
|
package/cjs/types/aaveV4.d.ts
CHANGED
|
@@ -100,6 +100,16 @@ export interface AaveV4ReserveAssetData {
|
|
|
100
100
|
borrowRate: string;
|
|
101
101
|
supplyIncentives: IncentiveData[];
|
|
102
102
|
borrowIncentives: IncentiveData[];
|
|
103
|
+
/**
|
|
104
|
+
* Intrinsic incentives pre-combined with scope-specific Merkl rewards, ready to render per surface:
|
|
105
|
+
* - spoke* → spoke supply/borrow (Create page + dashboard market table)
|
|
106
|
+
* - hub* → hub supply/borrow (Lend page)
|
|
107
|
+
* `supplyIncentives`/`borrowIncentives` above remain intrinsic-only so the net-APY calc is unaffected.
|
|
108
|
+
*/
|
|
109
|
+
spokeSupplyIncentives?: IncentiveData[];
|
|
110
|
+
spokeBorrowIncentives?: IncentiveData[];
|
|
111
|
+
hubSupplyIncentives?: IncentiveData[];
|
|
112
|
+
hubBorrowIncentives?: IncentiveData[];
|
|
103
113
|
canBeBorrowed: boolean;
|
|
104
114
|
canBeSupplied: boolean;
|
|
105
115
|
canBeWithdrawn: boolean;
|
package/cjs/types/claiming.d.ts
CHANGED
|
@@ -8,8 +8,6 @@ export declare enum ClaimType {
|
|
|
8
8
|
COMPOUND_V3_COMP = "COMPOUND_V3_COMP",
|
|
9
9
|
/** Rewards from Spark (wstETH only for now) */
|
|
10
10
|
SPARK_REWARDS = "SPARK_REWARDS",
|
|
11
|
-
/** Rewards from Morpho */
|
|
12
|
-
MORPHO = "MORPHO",
|
|
13
11
|
/** Rewards from King (prev LTR^2 - received for weETH holding) */
|
|
14
12
|
KING_REWARDS = "KING_REWARDS",
|
|
15
13
|
/** Spark Airdrop */
|
|
@@ -57,16 +55,6 @@ export type KingRewardsClaimableToken = _ClaimableTokenPartial & {
|
|
|
57
55
|
merkleProofs: string[];
|
|
58
56
|
};
|
|
59
57
|
};
|
|
60
|
-
export type MorphoClaimableToken = _ClaimableTokenPartial & {
|
|
61
|
-
claimType: ClaimType.MORPHO;
|
|
62
|
-
additionalClaimFields: {
|
|
63
|
-
originalAmount: string;
|
|
64
|
-
merkleProofs: string[];
|
|
65
|
-
distributor: EthAddress;
|
|
66
|
-
isLegacy: boolean;
|
|
67
|
-
txData: string;
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
58
|
export type CompoundV3CompClaimableToken = _ClaimableTokenPartial & {
|
|
71
59
|
claimType: ClaimType.COMPOUND_V3_COMP;
|
|
72
60
|
additionalClaimFields: {
|
|
@@ -93,5 +81,5 @@ export type SparkWstEthRewardsClaimableToken = _ClaimableTokenPartial & {
|
|
|
93
81
|
export type EthenaAirdropClaimableToken = _ClaimableTokenPartial & {
|
|
94
82
|
claimType: ClaimType.ETHENA_AIRDROP;
|
|
95
83
|
};
|
|
96
|
-
export type ClaimableToken = AaveRewardsClaimableToken | AaveMeritRewardsClaimableToken | CompoundV3CompClaimableToken |
|
|
84
|
+
export type ClaimableToken = AaveRewardsClaimableToken | AaveMeritRewardsClaimableToken | CompoundV3CompClaimableToken | SparkRewardsClaimableToken | KingRewardsClaimableToken | SparkAirdropClaimableToken | SparkWstEthRewardsClaimableToken | EthenaAirdropClaimableToken;
|
|
97
85
|
export {};
|
package/cjs/types/claiming.js
CHANGED
|
@@ -11,8 +11,6 @@ var ClaimType;
|
|
|
11
11
|
ClaimType["COMPOUND_V3_COMP"] = "COMPOUND_V3_COMP";
|
|
12
12
|
/** Rewards from Spark (wstETH only for now) */
|
|
13
13
|
ClaimType["SPARK_REWARDS"] = "SPARK_REWARDS";
|
|
14
|
-
/** Rewards from Morpho */
|
|
15
|
-
ClaimType["MORPHO"] = "MORPHO";
|
|
16
14
|
/** Rewards from King (prev LTR^2 - received for weETH holding) */
|
|
17
15
|
ClaimType["KING_REWARDS"] = "KING_REWARDS";
|
|
18
16
|
/** Spark Airdrop */
|
package/cjs/types/merkl.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress } from './common';
|
|
1
|
+
import { EthAddress, IncentiveData } from './common';
|
|
2
2
|
export declare enum OpportunityAction {
|
|
3
3
|
LEND = "LEND",
|
|
4
4
|
BORROW = "BORROW"
|
|
@@ -73,3 +73,16 @@ export type MerkleRewardMap = Record<EthAddress, {
|
|
|
73
73
|
supply?: MerkleRewardInfo;
|
|
74
74
|
borrow?: MerkleRewardInfo;
|
|
75
75
|
}>;
|
|
76
|
+
export type AaveV4MerklScopedReward = {
|
|
77
|
+
supply?: IncentiveData;
|
|
78
|
+
borrow?: IncentiveData;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Aave V4 Merkl reward campaigns split by scope:
|
|
82
|
+
* - `hub`: keyed by underlying token address (lowercase) — rewards for supplying to a hub
|
|
83
|
+
* - `spoke`: keyed by `${spokeAddress}_${underlyingAddress}` (both lowercase) — rewards for supplying/borrowing on a spoke
|
|
84
|
+
*/
|
|
85
|
+
export type AaveV4MerklRewardMap = {
|
|
86
|
+
hub: Record<string, AaveV4MerklScopedReward>;
|
|
87
|
+
spoke: Record<string, AaveV4MerklScopedReward>;
|
|
88
|
+
};
|
|
@@ -189,12 +189,12 @@ export interface MorphoBlueAllocationMarket {
|
|
|
189
189
|
};
|
|
190
190
|
irmAddress: string;
|
|
191
191
|
lltv: string;
|
|
192
|
-
|
|
192
|
+
marketId: string;
|
|
193
193
|
}
|
|
194
194
|
export interface MorphoBluePublicAllocatorItem {
|
|
195
195
|
vault: MorphoBlueVault;
|
|
196
196
|
assets: string;
|
|
197
|
-
|
|
197
|
+
withdrawMarket: MorphoBlueAllocationMarket;
|
|
198
198
|
}
|
|
199
199
|
export interface MorphoBlueAllocatorMarketState {
|
|
200
200
|
borrowAssets: string;
|
|
@@ -202,7 +202,6 @@ export interface MorphoBlueAllocatorMarketState {
|
|
|
202
202
|
}
|
|
203
203
|
export interface MorphoBlueRealloactionMarketData {
|
|
204
204
|
reallocatableLiquidityAssets: string;
|
|
205
|
-
targetBorrowUtilization: string;
|
|
206
205
|
publicAllocatorSharedLiquidity: MorphoBluePublicAllocatorItem[];
|
|
207
206
|
state: MorphoBlueAllocatorMarketState;
|
|
208
207
|
}
|
package/esm/aaveV4/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
2
|
import { AaveV4AccountData, AaveV4SpokeData, AaveV4SpokeInfo, EthAddress, EthereumProvider, NetworkNumber } from '../types';
|
|
3
3
|
export * as lend from './lend';
|
|
4
|
+
export { getAaveV4MerkleCampaigns } from './merkl';
|
|
4
5
|
export declare function _getAaveV4SpokeData(provider: Client, network: NetworkNumber, market: AaveV4SpokeInfo, blockNumber?: 'latest' | number): Promise<AaveV4SpokeData>;
|
|
5
6
|
export declare function getAaveV4SpokeData(provider: EthereumProvider, network: NetworkNumber, spoke: AaveV4SpokeInfo, blockNumber?: 'latest' | number): Promise<AaveV4SpokeData>;
|
|
6
7
|
export declare function _getAaveV4AccountData(provider: Client, network: NetworkNumber, spokeData: AaveV4SpokeData, address: EthAddress, blockNumber?: 'latest' | number): Promise<AaveV4AccountData>;
|
package/esm/aaveV4/index.js
CHANGED
|
@@ -17,7 +17,9 @@ import { isMaxUint, wethToEth } from '../services/utils';
|
|
|
17
17
|
import { aaveV4GetAggregatedPositionData, calcUserRiskPremiumBps } from '../helpers/aaveV4Helpers';
|
|
18
18
|
import { getAaveV4HubByAddress } from '../markets/aaveV4';
|
|
19
19
|
import { aprToApy } from '../moneymarket';
|
|
20
|
+
import { attachAaveV4MerklIncentives, getAaveV4MerkleCampaigns } from './merkl';
|
|
20
21
|
export * as lend from './lend';
|
|
22
|
+
export { getAaveV4MerkleCampaigns } from './merkl';
|
|
21
23
|
const fetchHubData = (viewContract, hubAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
24
|
const hubData = yield viewContract.read.getHubAllAssetsData([hubAddress]);
|
|
23
25
|
return {
|
|
@@ -129,15 +131,17 @@ export function _getAaveV4SpokeData(provider_1, network_1, market_1) {
|
|
|
129
131
|
return __awaiter(this, arguments, void 0, function* (provider, network, market, blockNumber = 'latest') {
|
|
130
132
|
const viewContract = AaveV4ViewContractViem(provider, network, blockNumber);
|
|
131
133
|
const hubsData = {};
|
|
132
|
-
const [spokeData] = yield Promise.all([
|
|
134
|
+
const [spokeData, merklCampaigns] = yield Promise.all([
|
|
133
135
|
viewContract.read.getSpokeDataFull([market.address]),
|
|
136
|
+
getAaveV4MerkleCampaigns(network),
|
|
134
137
|
...market.hubs.map((hubAddress) => __awaiter(this, void 0, void 0, function* () {
|
|
135
138
|
hubsData[hubAddress] = yield fetchHubData(viewContract, hubAddress);
|
|
136
139
|
})),
|
|
137
140
|
]);
|
|
138
141
|
const reserveAssetsArray = yield Promise.all(spokeData[1].map((reserveAssetOnChain, index) => __awaiter(this, void 0, void 0, function* () { return formatReserveAsset(reserveAssetOnChain, hubsData[reserveAssetOnChain.hub].assets[reserveAssetOnChain.assetId], index, +spokeData[0].oracleDecimals.toString(), network); })));
|
|
142
|
+
const enrichedAssets = reserveAssetsArray.map((asset) => attachAaveV4MerklIncentives(asset, market.address, merklCampaigns));
|
|
139
143
|
return {
|
|
140
|
-
assetsData:
|
|
144
|
+
assetsData: enrichedAssets.reduce((acc, reserveAsset) => {
|
|
141
145
|
acc[`${reserveAsset.symbol}-${reserveAsset.reserveId}`] = reserveAsset;
|
|
142
146
|
return acc;
|
|
143
147
|
}, {}),
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AaveV4MerklRewardMap, AaveV4ReserveAssetData } from '../types';
|
|
2
|
+
import { NetworkNumber } from '../types/common';
|
|
3
|
+
export declare const getAaveV4MerkleCampaigns: (chainId: NetworkNumber) => Promise<AaveV4MerklRewardMap>;
|
|
4
|
+
/**
|
|
5
|
+
* Returns a copy of the asset with scope-specific incentive arrays pre-combined with the asset's
|
|
6
|
+
* intrinsic (staking) incentives, so each surface can render base yield + the rewards that apply to it.
|
|
7
|
+
*/
|
|
8
|
+
export declare const attachAaveV4MerklIncentives: (asset: AaveV4ReserveAssetData, spokeAddress: string, campaigns: AaveV4MerklRewardMap) => AaveV4ReserveAssetData;
|
|
@@ -0,0 +1,85 @@
|
|
|
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 { DEFAULT_TIMEOUT } from '../services/utils';
|
|
12
|
+
import { IncentiveKind, OpportunityAction, OpportunityStatus, } from '../types';
|
|
13
|
+
/**
|
|
14
|
+
* Merkl tags Aave V4 reward campaigns by scope via the `type` field:
|
|
15
|
+
* - AAVE_V4_HUB_SUPPLY / AAVE_V4_HUB_BORROW → reward tied to a hub (matched per underlying token)
|
|
16
|
+
* - AAVE_V4_SPOKE_SUPPLY / AAVE_V4_SPOKE_BORROW → reward tied to a spoke (matched per spoke contract + underlying)
|
|
17
|
+
* Hub campaigns identify the underlying via `tokens[0]`; spoke campaigns identify the spoke via `explorerAddress`.
|
|
18
|
+
*/
|
|
19
|
+
const spokeKey = (spokeAddress, underlying) => `${spokeAddress.toLowerCase()}_${underlying.toLowerCase()}`;
|
|
20
|
+
const buildIncentive = (opportunity) => {
|
|
21
|
+
var _a, _b, _c, _d, _e;
|
|
22
|
+
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;
|
|
23
|
+
const token = (rewardToken === null || rewardToken === void 0 ? void 0 : rewardToken.symbol) || ((_e = (_d = opportunity.tokens) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.symbol) || '';
|
|
24
|
+
return {
|
|
25
|
+
apy: aprToApy(opportunity.apr),
|
|
26
|
+
token,
|
|
27
|
+
incentiveKind: IncentiveKind.Reward,
|
|
28
|
+
description: `Eligible for ${token} rewards through Merkl.${opportunity.description ? `\n${opportunity.description}` : ''}`,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export const getAaveV4MerkleCampaigns = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
const result = { hub: {}, spoke: {} };
|
|
33
|
+
try {
|
|
34
|
+
const res = yield fetch('https://api-merkl.angle.money/v4/opportunities?mainProtocolId=aave', {
|
|
35
|
+
signal: AbortSignal.timeout(DEFAULT_TIMEOUT),
|
|
36
|
+
});
|
|
37
|
+
if (!res.ok)
|
|
38
|
+
throw new Error('Failed to fetch Aave V4 Merkle campaigns');
|
|
39
|
+
const opportunities = yield res.json();
|
|
40
|
+
opportunities
|
|
41
|
+
.filter((o) => o.chainId === chainId)
|
|
42
|
+
.filter((o) => o.status === OpportunityStatus.LIVE)
|
|
43
|
+
.filter((o) => typeof o.type === 'string' && o.type.startsWith('AAVE_V4_'))
|
|
44
|
+
.forEach((o) => {
|
|
45
|
+
var _a, _b, _c, _d;
|
|
46
|
+
const underlying = (_c = (_b = (_a = o.tokens) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.address) === null || _c === void 0 ? void 0 : _c.toLowerCase();
|
|
47
|
+
if (!underlying)
|
|
48
|
+
return;
|
|
49
|
+
const side = o.action === OpportunityAction.BORROW ? 'borrow' : 'supply';
|
|
50
|
+
const incentive = buildIncentive(o);
|
|
51
|
+
if (o.type.includes('HUB')) {
|
|
52
|
+
if (!result.hub[underlying])
|
|
53
|
+
result.hub[underlying] = {};
|
|
54
|
+
result.hub[underlying][side] = incentive;
|
|
55
|
+
}
|
|
56
|
+
else if (o.type.includes('SPOKE')) {
|
|
57
|
+
const spokeAddress = (_d = o.explorerAddress) === null || _d === void 0 ? void 0 : _d.toLowerCase();
|
|
58
|
+
if (!spokeAddress)
|
|
59
|
+
return;
|
|
60
|
+
const key = spokeKey(spokeAddress, underlying);
|
|
61
|
+
if (!result.spoke[key])
|
|
62
|
+
result.spoke[key] = {};
|
|
63
|
+
result.spoke[key][side] = incentive;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
console.error('Failed to fetch Aave V4 Merkle campaigns', e);
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
/**
|
|
74
|
+
* Returns a copy of the asset with scope-specific incentive arrays pre-combined with the asset's
|
|
75
|
+
* intrinsic (staking) incentives, so each surface can render base yield + the rewards that apply to it.
|
|
76
|
+
*/
|
|
77
|
+
export const attachAaveV4MerklIncentives = (asset, spokeAddress, campaigns) => {
|
|
78
|
+
var _a;
|
|
79
|
+
const underlying = (_a = asset.underlying) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
80
|
+
const baseSupply = asset.supplyIncentives || [];
|
|
81
|
+
const baseBorrow = asset.borrowIncentives || [];
|
|
82
|
+
const spokeScoped = (spokeAddress && underlying) ? campaigns.spoke[spokeKey(spokeAddress, underlying)] : undefined;
|
|
83
|
+
const hubScoped = underlying ? campaigns.hub[underlying] : undefined;
|
|
84
|
+
return Object.assign(Object.assign({}, asset), { spokeSupplyIncentives: (spokeScoped === null || spokeScoped === void 0 ? void 0 : spokeScoped.supply) ? [...baseSupply, spokeScoped.supply] : baseSupply, spokeBorrowIncentives: (spokeScoped === null || spokeScoped === void 0 ? void 0 : spokeScoped.borrow) ? [...baseBorrow, spokeScoped.borrow] : baseBorrow, hubSupplyIncentives: (hubScoped === null || hubScoped === void 0 ? void 0 : hubScoped.supply) ? [...baseSupply, hubScoped.supply] : baseSupply, hubBorrowIncentives: (hubScoped === null || hubScoped === void 0 ? void 0 : hubScoped.borrow) ? [...baseBorrow, hubScoped.borrow] : baseBorrow });
|
|
85
|
+
};
|
package/esm/claiming/aaveV3.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ import { Client } from 'viem';
|
|
|
2
2
|
import { EthAddress, NetworkNumber } from '../types/common';
|
|
3
3
|
import { ClaimableToken } from '../types/claiming';
|
|
4
4
|
export declare function getUnclaimedRewardsForAllMarkets(provider: Client, network: NetworkNumber, walletAddress: EthAddress, marketAddress: EthAddress): Promise<ClaimableToken[]>;
|
|
5
|
-
export declare function getMeritUnclaimedRewards(account: EthAddress, network: NetworkNumber
|
|
5
|
+
export declare function getMeritUnclaimedRewards(account: EthAddress, network: NetworkNumber): Promise<ClaimableToken[]>;
|
package/esm/claiming/aaveV3.js
CHANGED
|
@@ -88,8 +88,8 @@ export function getUnclaimedRewardsForAllMarkets(provider, network, walletAddres
|
|
|
88
88
|
return mapAaveRewardsToClaimableTokens(Object.values(totalUnclaimedPerRewardToken), marketAddress, walletAddress);
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
|
-
export function getMeritUnclaimedRewards(
|
|
92
|
-
return __awaiter(this,
|
|
91
|
+
export function getMeritUnclaimedRewards(account, network) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
93
|
let data;
|
|
94
94
|
try {
|
|
95
95
|
const res = yield fetch(`https://api-merkl.angle.money/v4/users/${account}/rewards?chainId=${network}`, { signal: AbortSignal.timeout(3000) });
|
|
@@ -103,8 +103,7 @@ export function getMeritUnclaimedRewards(account_1, network_1) {
|
|
|
103
103
|
data.forEach((item) => {
|
|
104
104
|
item.rewards.forEach(reward => {
|
|
105
105
|
const { token, amount, claimed, proofs, } = reward;
|
|
106
|
-
|
|
107
|
-
if (!token || !token.symbol || amount === '0' || (isTokenMorpho && !acceptMorpho))
|
|
106
|
+
if (!token || !token.symbol || amount === '0')
|
|
108
107
|
return;
|
|
109
108
|
const unclaimedAmount = new Dec(amount).minus(claimed || 0).toString();
|
|
110
109
|
if (unclaimedAmount === '0')
|
package/esm/claiming/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as aaveV3Claim from './aaveV3';
|
|
2
2
|
import * as compV3Claim from './compV3';
|
|
3
3
|
import * as kingV3Claim from './king';
|
|
4
|
-
import * as morphoBlueClaim from './morphoBlue';
|
|
5
4
|
import * as sparkClaim from './spark';
|
|
6
|
-
export { aaveV3Claim, compV3Claim, kingV3Claim,
|
|
5
|
+
export { aaveV3Claim, compV3Claim, kingV3Claim, sparkClaim, };
|
package/esm/claiming/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as aaveV3Claim from './aaveV3';
|
|
2
2
|
import * as compV3Claim from './compV3';
|
|
3
3
|
import * as kingV3Claim from './king';
|
|
4
|
-
import * as morphoBlueClaim from './morphoBlue';
|
|
5
4
|
import * as sparkClaim from './spark';
|
|
6
|
-
export { aaveV3Claim, compV3Claim, kingV3Claim,
|
|
5
|
+
export { aaveV3Claim, compV3Claim, kingV3Claim, sparkClaim, };
|