@defisaver/positions-sdk 2.0.15-dev → 2.0.15-dev-2
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/.mocharc.json +4 -4
- package/.nvmrc +1 -1
- package/README.md +64 -64
- package/cjs/aaveV2/index.js +9 -5
- package/cjs/aaveV3/index.js +50 -40
- package/cjs/aaveV3/merit.d.ts +17 -0
- package/cjs/aaveV3/merit.js +95 -0
- package/cjs/aaveV3/{rewards.d.ts → merkl.d.ts} +7 -2
- package/cjs/aaveV3/{rewards.js → merkl.js} +30 -14
- package/cjs/compoundV2/index.js +13 -7
- package/cjs/compoundV3/index.js +7 -2
- package/cjs/config/contracts.d.ts +6510 -1851
- package/cjs/config/contracts.js +33 -12
- package/cjs/contracts.d.ts +178 -0
- package/cjs/eulerV2/index.js +11 -2
- package/cjs/fluid/index.js +105 -34
- package/cjs/helpers/aaveHelpers/index.js +0 -1
- package/cjs/helpers/compoundHelpers/index.d.ts +3 -5
- package/cjs/helpers/compoundHelpers/index.js +15 -11
- package/cjs/helpers/eulerHelpers/index.d.ts +0 -5
- package/cjs/helpers/eulerHelpers/index.js +2 -31
- package/cjs/helpers/fluidHelpers/index.js +2 -0
- package/cjs/helpers/liquityV2Helpers/index.js +3 -2
- package/cjs/helpers/morphoBlueHelpers/index.js +66 -66
- package/cjs/liquityV2/index.js +10 -2
- package/cjs/llamaLend/index.js +10 -2
- package/cjs/morphoBlue/index.js +20 -6
- package/cjs/spark/index.js +20 -30
- package/cjs/staking/eligibility.d.ts +11 -0
- package/cjs/staking/eligibility.js +43 -0
- package/cjs/staking/index.d.ts +1 -0
- package/cjs/staking/index.js +1 -0
- package/cjs/staking/staking.d.ts +1 -7
- package/cjs/staking/staking.js +29 -55
- package/cjs/types/aave.d.ts +1 -7
- package/cjs/types/common.d.ts +16 -4
- package/cjs/types/common.js +10 -1
- package/cjs/types/euler.d.ts +3 -3
- package/cjs/types/fluid.d.ts +3 -5
- package/cjs/types/liquityV2.d.ts +3 -3
- package/cjs/types/llamaLend.d.ts +3 -1
- package/cjs/types/morphoBlue.d.ts +3 -5
- package/cjs/types/spark.d.ts +0 -3
- package/esm/aaveV2/index.js +9 -5
- package/esm/aaveV3/index.js +48 -38
- package/esm/aaveV3/merit.d.ts +17 -0
- package/esm/aaveV3/merit.js +90 -0
- package/esm/aaveV3/{rewards.d.ts → merkl.d.ts} +7 -2
- package/esm/aaveV3/{rewards.js → merkl.js} +28 -13
- package/esm/compoundV2/index.js +13 -7
- package/esm/compoundV3/index.js +7 -2
- package/esm/config/contracts.d.ts +6510 -1851
- package/esm/config/contracts.js +33 -12
- package/esm/contracts.d.ts +178 -0
- package/esm/eulerV2/index.js +11 -2
- package/esm/fluid/index.js +106 -35
- package/esm/helpers/aaveHelpers/index.js +0 -1
- package/esm/helpers/compoundHelpers/index.d.ts +3 -5
- package/esm/helpers/compoundHelpers/index.js +16 -12
- package/esm/helpers/eulerHelpers/index.d.ts +0 -5
- package/esm/helpers/eulerHelpers/index.js +2 -30
- package/esm/helpers/fluidHelpers/index.js +2 -0
- package/esm/helpers/liquityV2Helpers/index.js +3 -2
- package/esm/helpers/morphoBlueHelpers/index.js +66 -66
- package/esm/liquityV2/index.js +11 -3
- package/esm/llamaLend/index.js +11 -3
- package/esm/morphoBlue/index.js +21 -7
- package/esm/spark/index.js +21 -31
- package/esm/staking/eligibility.d.ts +11 -0
- package/esm/staking/eligibility.js +36 -0
- package/esm/staking/index.d.ts +1 -0
- package/esm/staking/index.js +1 -0
- package/esm/staking/staking.d.ts +1 -7
- package/esm/staking/staking.js +28 -53
- package/esm/types/aave.d.ts +1 -7
- package/esm/types/common.d.ts +16 -4
- package/esm/types/common.js +9 -0
- package/esm/types/euler.d.ts +3 -3
- package/esm/types/fluid.d.ts +3 -5
- package/esm/types/liquityV2.d.ts +3 -3
- package/esm/types/llamaLend.d.ts +3 -1
- package/esm/types/morphoBlue.d.ts +3 -5
- package/esm/types/spark.d.ts +0 -3
- package/package.json +47 -47
- package/src/aaveV2/index.ts +239 -236
- package/src/aaveV3/index.ts +511 -493
- package/src/aaveV3/merit.ts +98 -0
- package/src/aaveV3/{rewards.ts → merkl.ts} +141 -125
- package/src/compoundV2/index.ts +244 -240
- package/src/compoundV3/index.ts +274 -270
- package/src/config/contracts.ts +1129 -1108
- package/src/constants/index.ts +6 -6
- package/src/contracts.ts +107 -107
- package/src/curveUsd/index.ts +250 -250
- package/src/eulerV2/index.ts +324 -314
- package/src/exchange/index.ts +25 -25
- package/src/fluid/index.ts +1636 -1568
- package/src/helpers/aaveHelpers/index.ts +169 -170
- package/src/helpers/compoundHelpers/index.ts +267 -261
- package/src/helpers/curveUsdHelpers/index.ts +40 -40
- package/src/helpers/eulerHelpers/index.ts +222 -259
- package/src/helpers/fluidHelpers/index.ts +326 -324
- package/src/helpers/index.ts +10 -10
- package/src/helpers/liquityV2Helpers/index.ts +82 -80
- package/src/helpers/llamaLendHelpers/index.ts +53 -53
- package/src/helpers/makerHelpers/index.ts +52 -52
- package/src/helpers/morphoBlueHelpers/index.ts +390 -390
- package/src/helpers/sparkHelpers/index.ts +155 -155
- package/src/index.ts +45 -45
- package/src/liquity/index.ts +104 -104
- package/src/liquityV2/index.ts +418 -408
- package/src/llamaLend/index.ts +305 -296
- package/src/maker/index.ts +223 -223
- package/src/markets/aave/index.ts +116 -116
- package/src/markets/aave/marketAssets.ts +49 -49
- package/src/markets/compound/index.ts +227 -227
- package/src/markets/compound/marketsAssets.ts +90 -90
- package/src/markets/curveUsd/index.ts +69 -69
- package/src/markets/euler/index.ts +26 -26
- package/src/markets/fluid/index.ts +2456 -2456
- package/src/markets/index.ts +25 -25
- package/src/markets/liquityV2/index.ts +102 -102
- package/src/markets/llamaLend/contractAddresses.ts +141 -141
- package/src/markets/llamaLend/index.ts +235 -235
- package/src/markets/morphoBlue/index.ts +895 -895
- package/src/markets/spark/index.ts +29 -29
- package/src/markets/spark/marketAssets.ts +11 -11
- package/src/moneymarket/moneymarketCommonService.ts +80 -80
- package/src/morphoBlue/index.ts +236 -222
- package/src/portfolio/index.ts +285 -285
- package/src/services/priceService.ts +159 -159
- package/src/services/utils.ts +63 -63
- package/src/services/viem.ts +32 -32
- package/src/setup.ts +8 -8
- package/src/spark/index.ts +444 -456
- package/src/staking/eligibility.ts +37 -0
- package/src/staking/index.ts +2 -1
- package/src/staking/staking.ts +169 -194
- package/src/types/aave.ts +189 -195
- package/src/types/common.ts +103 -88
- package/src/types/compound.ts +136 -136
- package/src/types/curveUsd.ts +121 -121
- package/src/types/euler.ts +175 -174
- package/src/types/fluid.ts +448 -450
- package/src/types/index.ts +11 -11
- package/src/types/liquity.ts +30 -30
- package/src/types/liquityV2.ts +126 -126
- package/src/types/llamaLend.ts +159 -157
- package/src/types/maker.ts +63 -63
- package/src/types/morphoBlue.ts +194 -194
- package/src/types/portfolio.ts +60 -60
- package/src/types/spark.ts +135 -137
package/esm/aaveV3/index.js
CHANGED
|
@@ -15,9 +15,10 @@ import { AAVE_V3 } from '../markets/aave';
|
|
|
15
15
|
import { aprToApy, calculateBorrowingAssetLimit } from '../moneymarket';
|
|
16
16
|
import { ethToWeth, isEnabledOnBitmap, isLayer2Network, wethToEth, wethToEthByAddress, } from '../services/utils';
|
|
17
17
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
18
|
-
import { NetworkNumber, } from '../types/common';
|
|
18
|
+
import { IncentiveKind, NetworkNumber, } from '../types/common';
|
|
19
19
|
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
20
|
-
import {
|
|
20
|
+
import { getMeritCampaigns } from './merit';
|
|
21
|
+
import { getAaveUnderlyingSymbol, getMerkleCampaigns } from './merkl';
|
|
21
22
|
export const aaveV3EmodeCategoriesMapping = (extractedState, usedAssets) => {
|
|
22
23
|
const { eModeCategoriesData } = extractedState;
|
|
23
24
|
const usedAssetsValues = Object.values(usedAssets);
|
|
@@ -52,12 +53,13 @@ export function _getAaveV3MarketData(provider_1, network_1, market_1) {
|
|
|
52
53
|
const marketAddress = market.providerAddress;
|
|
53
54
|
const networksWithIncentives = [NetworkNumber.Eth, NetworkNumber.Arb, NetworkNumber.Opt, NetworkNumber.Linea];
|
|
54
55
|
// eslint-disable-next-line prefer-const
|
|
55
|
-
let [loanInfo, eModesInfo, isBorrowAllowed, rewardInfo, merkleRewardsMap] = yield Promise.all([
|
|
56
|
+
let [loanInfo, eModesInfo, isBorrowAllowed, rewardInfo, merkleRewardsMap, meritRewardsMap] = yield Promise.all([
|
|
56
57
|
loanInfoContract.read.getFullTokensInfo([marketAddress, _addresses], setViemBlockNumber(blockNumber)),
|
|
57
58
|
loanInfoContract.read.getAllEmodes([marketAddress], setViemBlockNumber(blockNumber)),
|
|
58
59
|
loanInfoContract.read.isBorrowAllowed([marketAddress], setViemBlockNumber(blockNumber)), // Used on L2s check for PriceOracleSentinel (mainnet will always return true)
|
|
59
60
|
networksWithIncentives.includes(network) ? aaveIncentivesContract.read.getReservesIncentivesData([marketAddress], setViemBlockNumber(blockNumber)) : null,
|
|
60
61
|
getMerkleCampaigns(network),
|
|
62
|
+
getMeritCampaigns(network, market.value),
|
|
61
63
|
]);
|
|
62
64
|
isBorrowAllowed = isLayer2Network(network) ? isBorrowAllowed : true;
|
|
63
65
|
const eModeCategoriesData = {};
|
|
@@ -139,58 +141,76 @@ export function _getAaveV3MarketData(provider_1, network_1, market_1) {
|
|
|
139
141
|
isolationModeBorrowingEnabled: tokenMarket.isolationModeBorrowingEnabled,
|
|
140
142
|
isFlashLoanEnabled: tokenMarket.isFlashLoanEnabled,
|
|
141
143
|
aTokenAddress: tokenMarket.aTokenAddress,
|
|
144
|
+
vTokenAddress: tokenMarket.debtTokenAddress,
|
|
142
145
|
supplyIncentives: [],
|
|
143
146
|
borrowIncentives: [],
|
|
144
147
|
});
|
|
145
148
|
})));
|
|
146
149
|
// Get incentives data
|
|
147
150
|
yield Promise.all(assetsData.map((_market, index) => __awaiter(this, void 0, void 0, function* () {
|
|
148
|
-
var _a;
|
|
151
|
+
var _a, _b;
|
|
149
152
|
/* eslint-disable no-param-reassign */
|
|
150
153
|
// @ts-ignore
|
|
151
154
|
const rewardForMarket = rewardInfo === null || rewardInfo === void 0 ? void 0 : rewardInfo[_market.underlyingTokenAddress];
|
|
152
155
|
const isStakingAsset = STAKING_ASSETS.includes(_market.symbol);
|
|
153
156
|
if (isStakingAsset) {
|
|
154
|
-
|
|
155
|
-
_market.incentiveSupplyToken = _market.symbol;
|
|
157
|
+
const yieldApy = yield getStakingApy(_market.symbol);
|
|
156
158
|
_market.supplyIncentives.push({
|
|
157
|
-
apy:
|
|
159
|
+
apy: yieldApy,
|
|
158
160
|
token: _market.symbol,
|
|
159
|
-
incentiveKind:
|
|
161
|
+
incentiveKind: IncentiveKind.Staking,
|
|
160
162
|
description: `Native ${_market.symbol} yield.`,
|
|
161
163
|
});
|
|
162
164
|
if (_market.canBeBorrowed) {
|
|
163
165
|
// when borrowing assets whose value increases over time
|
|
164
|
-
_market.incentiveBorrowApy = new Dec(_market.incentiveSupplyApy).mul(-1).toString();
|
|
165
|
-
_market.incentiveBorrowToken = _market.symbol;
|
|
166
166
|
_market.borrowIncentives.push({
|
|
167
|
-
apy:
|
|
168
|
-
token: _market.
|
|
169
|
-
incentiveKind:
|
|
167
|
+
apy: new Dec(yieldApy).mul(-1).toString(),
|
|
168
|
+
token: _market.symbol,
|
|
169
|
+
incentiveKind: IncentiveKind.Reward,
|
|
170
170
|
description: `Due to the native yield of ${_market.symbol}, the value of the debt would increase over time.`,
|
|
171
171
|
});
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
const aTokenAddress = _market.aTokenAddress.toLowerCase(); // DEV: Should aTokenAddress be in AaveV3AssetData type?
|
|
175
175
|
if ((_a = merkleRewardsMap[aTokenAddress]) === null || _a === void 0 ? void 0 : _a.supply) {
|
|
176
|
-
const {
|
|
176
|
+
const { apy, rewardTokenSymbol, description, identifier, } = merkleRewardsMap[aTokenAddress].supply;
|
|
177
177
|
_market.supplyIncentives.push({
|
|
178
|
-
apy
|
|
178
|
+
apy,
|
|
179
179
|
token: rewardTokenSymbol,
|
|
180
|
-
incentiveKind:
|
|
180
|
+
incentiveKind: IncentiveKind.Reward,
|
|
181
|
+
description,
|
|
182
|
+
eligibilityId: identifier,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
const vTokenAddress = _market.vTokenAddress.toLowerCase(); // DEV: Should vTokenAddress be in AaveV3AssetData type?
|
|
186
|
+
if ((_b = merkleRewardsMap[vTokenAddress]) === null || _b === void 0 ? void 0 : _b.borrow) {
|
|
187
|
+
const { apy, rewardTokenSymbol, description, identifier, } = merkleRewardsMap[vTokenAddress].borrow;
|
|
188
|
+
_market.borrowIncentives.push({
|
|
189
|
+
apy,
|
|
190
|
+
token: rewardTokenSymbol,
|
|
191
|
+
incentiveKind: IncentiveKind.Reward,
|
|
192
|
+
description,
|
|
193
|
+
eligibilityId: identifier,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
if (meritRewardsMap.supply[_market.symbol]) {
|
|
197
|
+
const { apy, rewardTokenSymbol, description } = meritRewardsMap.supply[_market.symbol];
|
|
198
|
+
_market.supplyIncentives.push({
|
|
199
|
+
apy,
|
|
200
|
+
token: rewardTokenSymbol,
|
|
201
|
+
incentiveKind: IncentiveKind.Reward,
|
|
202
|
+
description,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
if (meritRewardsMap.borrow[_market.symbol]) {
|
|
206
|
+
const { apy, rewardTokenSymbol, description } = meritRewardsMap.borrow[_market.symbol];
|
|
207
|
+
_market.borrowIncentives.push({
|
|
208
|
+
apy,
|
|
209
|
+
token: rewardTokenSymbol,
|
|
210
|
+
incentiveKind: IncentiveKind.Reward,
|
|
181
211
|
description,
|
|
182
212
|
});
|
|
183
213
|
}
|
|
184
|
-
// const aTokenDebtAddress = '0xTODO';
|
|
185
|
-
// if (merkleRewardsMap[aTokenDebtAddress]?.supply) {
|
|
186
|
-
// const { apr, rewardTokenSymbol, description } = merkleRewardsMap[aTokenDebtAddress].supply;
|
|
187
|
-
// _market.borrowIncentives.push({
|
|
188
|
-
// apy: aprToApy(apr),
|
|
189
|
-
// token: rewardTokenSymbol,
|
|
190
|
-
// incentiveKind: 'reward',
|
|
191
|
-
// description,
|
|
192
|
-
// });
|
|
193
|
-
// }
|
|
194
214
|
if (!rewardForMarket)
|
|
195
215
|
return;
|
|
196
216
|
// @ts-ignore
|
|
@@ -198,10 +218,7 @@ export function _getAaveV3MarketData(provider_1, network_1, market_1) {
|
|
|
198
218
|
if (supplyRewardData) {
|
|
199
219
|
if (+(supplyRewardData.emissionEndTimestamp.toString()) * 1000 < Date.now())
|
|
200
220
|
return;
|
|
201
|
-
_market.incentiveSupplyToken = supplyRewardData.rewardTokenSymbol;
|
|
202
221
|
// reward token is aave asset
|
|
203
|
-
if (supplyRewardData.rewardTokenSymbol.startsWith('a') && supplyRewardData.rewardTokenSymbol.includes(_market.symbol))
|
|
204
|
-
_market.incentiveSupplyToken = _market.symbol;
|
|
205
222
|
const supplyEmissionPerSecond = supplyRewardData.emissionPerSecond;
|
|
206
223
|
const supplyRewardPrice = new Dec(supplyRewardData.rewardPriceFeed).div(Math.pow(10, +supplyRewardData.priceFeedDecimals))
|
|
207
224
|
.toString();
|
|
@@ -211,12 +228,10 @@ export function _getAaveV3MarketData(provider_1, network_1, market_1) {
|
|
|
211
228
|
.div(_market.price)
|
|
212
229
|
.div(_market.totalSupply)
|
|
213
230
|
.toString();
|
|
214
|
-
_market.incentiveSupplyApy = new Dec(_market.incentiveSupplyApy || '0').add(rewardApy)
|
|
215
|
-
.toString();
|
|
216
231
|
_market.supplyIncentives.push({
|
|
217
232
|
token: getAaveUnderlyingSymbol(supplyRewardData.rewardTokenSymbol),
|
|
218
233
|
apy: rewardApy,
|
|
219
|
-
incentiveKind:
|
|
234
|
+
incentiveKind: IncentiveKind.Reward,
|
|
220
235
|
description: 'Eligible for protocol-level incentives.',
|
|
221
236
|
});
|
|
222
237
|
}
|
|
@@ -226,9 +241,6 @@ export function _getAaveV3MarketData(provider_1, network_1, market_1) {
|
|
|
226
241
|
if (borrowRewardData) {
|
|
227
242
|
if (+(borrowRewardData.emissionEndTimestamp.toString()) * 1000 < Date.now())
|
|
228
243
|
return;
|
|
229
|
-
_market.incentiveBorrowToken = borrowRewardData.rewardTokenSymbol;
|
|
230
|
-
if (borrowRewardData.rewardTokenSymbol.startsWith('a') && borrowRewardData.rewardTokenSymbol.includes(_market.symbol))
|
|
231
|
-
_market.incentiveBorrowToken = _market.symbol;
|
|
232
244
|
const supplyEmissionPerSecond = borrowRewardData.emissionPerSecond;
|
|
233
245
|
const supplyRewardPrice = new Dec(borrowRewardData.rewardPriceFeed).div(Math.pow(10, +borrowRewardData.priceFeedDecimals))
|
|
234
246
|
.toString();
|
|
@@ -238,12 +250,10 @@ export function _getAaveV3MarketData(provider_1, network_1, market_1) {
|
|
|
238
250
|
.div(_market.price)
|
|
239
251
|
.div(_market.totalBorrowVar)
|
|
240
252
|
.toString();
|
|
241
|
-
_market.incentiveBorrowApy = new Dec(_market.incentiveBorrowApy || '0').add(rewardApy)
|
|
242
|
-
.toString();
|
|
243
253
|
_market.borrowIncentives.push({
|
|
244
254
|
token: getAaveUnderlyingSymbol(borrowRewardData.rewardTokenSymbol),
|
|
245
255
|
apy: rewardApy,
|
|
246
|
-
incentiveKind:
|
|
256
|
+
incentiveKind: IncentiveKind.Reward,
|
|
247
257
|
description: 'Eligible for protocol-level incentives.',
|
|
248
258
|
});
|
|
249
259
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { NetworkNumber } from '../types/common';
|
|
2
|
+
import { AaveVersions } from '../types';
|
|
3
|
+
type RewardInfo = {
|
|
4
|
+
apy: string;
|
|
5
|
+
rewardTokenSymbol: string;
|
|
6
|
+
description: string;
|
|
7
|
+
};
|
|
8
|
+
type MeritTokenRewardMap = {
|
|
9
|
+
supply: Record<string, RewardInfo>;
|
|
10
|
+
borrow: Record<string, RewardInfo>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Fetches merit rewards data from Aave API
|
|
14
|
+
*/
|
|
15
|
+
export declare const fetchMeritRewardsData: () => Promise<Record<string, number | null>>;
|
|
16
|
+
export declare const getMeritCampaigns: (chainId: NetworkNumber, market: AaveVersions) => Promise<MeritTokenRewardMap>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
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 { DEFAULT_TIMEOUT } from '../services/utils';
|
|
11
|
+
import { NetworkNumber } from '../types/common';
|
|
12
|
+
import { aprToApy } from '../moneymarket';
|
|
13
|
+
import { AaveVersions } from '../types';
|
|
14
|
+
/**
|
|
15
|
+
* Maps API keys to reward data & actions - hardcoded and needs to be maintained actively.
|
|
16
|
+
* Mapping based on Aave interface implementation: https://github.com/aave/interface/blob/main/src/hooks/useMeritIncentives.ts
|
|
17
|
+
* Active campaigns found here: https://apps.aavechan.com/merit
|
|
18
|
+
*/
|
|
19
|
+
const MERIT_DATA_MAP = {
|
|
20
|
+
[NetworkNumber.Eth]: {
|
|
21
|
+
[AaveVersions.AaveV3]: {
|
|
22
|
+
'ethereum-supply-ethx': { rewardTokenSymbol: 'SD', action: 'supply', supplyTokens: ['ETHx'] },
|
|
23
|
+
'ethereum-supply-rlusd': { rewardTokenSymbol: 'aEthRLUSD', action: 'supply', supplyTokens: ['RLUSD'] },
|
|
24
|
+
// Campaign disabled here as it's present on Merkl API:
|
|
25
|
+
// 'ethereum-borrow-eurc': { rewardTokenSymbol: 'aEthEURC', action: 'borrow', borrowTokens: ['EURC'] },
|
|
26
|
+
},
|
|
27
|
+
[AaveVersions.AaveV3Lido]: {},
|
|
28
|
+
[AaveVersions.AaveV3Etherfi]: {},
|
|
29
|
+
},
|
|
30
|
+
[NetworkNumber.Arb]: {
|
|
31
|
+
[AaveVersions.AaveV3]: {},
|
|
32
|
+
},
|
|
33
|
+
[NetworkNumber.Opt]: {
|
|
34
|
+
[AaveVersions.AaveV3]: {},
|
|
35
|
+
},
|
|
36
|
+
[NetworkNumber.Base]: {
|
|
37
|
+
[AaveVersions.AaveV3]: {
|
|
38
|
+
'base-borrow-usdc': { rewardTokenSymbol: 'USDC', action: 'borrow', borrowTokens: ['USDC'] },
|
|
39
|
+
'base-borrow-gho': { rewardTokenSymbol: 'GHO', action: 'borrow', borrowTokens: ['GHO'] },
|
|
40
|
+
'base-borrow-eurc': { rewardTokenSymbol: 'EURC', action: 'borrow', borrowTokens: ['EURC'] },
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
[NetworkNumber.Linea]: {
|
|
44
|
+
[AaveVersions.AaveV3]: {},
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Fetches merit rewards data from Aave API
|
|
49
|
+
*/
|
|
50
|
+
export const fetchMeritRewardsData = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
|
+
try {
|
|
52
|
+
const response = yield fetch('https://apps.aavechan.com/api/merit/aprs', {
|
|
53
|
+
signal: AbortSignal.timeout(DEFAULT_TIMEOUT),
|
|
54
|
+
});
|
|
55
|
+
const data = yield response.json();
|
|
56
|
+
return data.currentAPR.actionsAPR;
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.error('Failed to fetch merit rewards data:', error);
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
export const getMeritCampaigns = (chainId, market) => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
+
var _a;
|
|
65
|
+
const meritData = yield fetchMeritRewardsData();
|
|
66
|
+
const relevantCampaigns = {
|
|
67
|
+
supply: {},
|
|
68
|
+
borrow: {},
|
|
69
|
+
};
|
|
70
|
+
Object.entries(((_a = MERIT_DATA_MAP[chainId]) === null || _a === void 0 ? void 0 : _a[market]) || {})
|
|
71
|
+
.filter(([key, rewardData]) => !!meritData[key])
|
|
72
|
+
.forEach(([key, rewardData]) => {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
const apr = meritData[key];
|
|
75
|
+
if (!apr)
|
|
76
|
+
return;
|
|
77
|
+
const reward = {
|
|
78
|
+
rewardTokenSymbol: rewardData.rewardTokenSymbol,
|
|
79
|
+
apy: aprToApy(apr).toString(),
|
|
80
|
+
description: `Eligible for Merit rewards in ${rewardData.rewardTokenSymbol}. ${rewardData.message ? `\n${rewardData.message}` : ''}`,
|
|
81
|
+
};
|
|
82
|
+
(_a = rewardData.supplyTokens) === null || _a === void 0 ? void 0 : _a.forEach(token => {
|
|
83
|
+
relevantCampaigns.supply[token] = reward;
|
|
84
|
+
});
|
|
85
|
+
(_b = rewardData.borrowTokens) === null || _b === void 0 ? void 0 : _b.forEach(token => {
|
|
86
|
+
relevantCampaigns.borrow[token] = reward;
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
return relevantCampaigns;
|
|
90
|
+
});
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { EthAddress, NetworkNumber } from '../types/common';
|
|
2
2
|
type RewardInfo = {
|
|
3
|
-
|
|
4
|
-
rewardToken: EthAddress;
|
|
3
|
+
apy: string;
|
|
5
4
|
rewardTokenSymbol: string;
|
|
6
5
|
description: string;
|
|
6
|
+
identifier: string;
|
|
7
7
|
};
|
|
8
8
|
type MerkleRewardMap = Record<EthAddress, {
|
|
9
9
|
supply?: RewardInfo;
|
|
10
10
|
borrow?: RewardInfo;
|
|
11
11
|
}>;
|
|
12
12
|
export declare const getAaveUnderlyingSymbol: (_symbol?: string) => any;
|
|
13
|
+
/**
|
|
14
|
+
* aEthLidoUSDC -> aUSDC
|
|
15
|
+
* USDC -> USDC
|
|
16
|
+
*/
|
|
17
|
+
export declare const formatAaveAsset: (_symbol: string) => string;
|
|
13
18
|
export declare const getMerkleCampaigns: (chainId: NetworkNumber) => Promise<MerkleRewardMap>;
|
|
14
19
|
export {};
|
|
@@ -7,6 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
import { aprToApy } from '../moneymarket';
|
|
10
11
|
import { DEFAULT_TIMEOUT, wethToEth } from '../services/utils';
|
|
11
12
|
var OpportunityAction;
|
|
12
13
|
(function (OpportunityAction) {
|
|
@@ -32,6 +33,16 @@ export const getAaveUnderlyingSymbol = (_symbol = '') => {
|
|
|
32
33
|
symbol = symbol.slice(1);
|
|
33
34
|
return wethToEth(symbol);
|
|
34
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* aEthLidoUSDC -> aUSDC
|
|
38
|
+
* USDC -> USDC
|
|
39
|
+
*/
|
|
40
|
+
export const formatAaveAsset = (_symbol) => {
|
|
41
|
+
if (_symbol.startsWith('a')) {
|
|
42
|
+
return `a${getAaveUnderlyingSymbol(_symbol)}`;
|
|
43
|
+
}
|
|
44
|
+
return _symbol;
|
|
45
|
+
};
|
|
35
46
|
export const getMerkleCampaigns = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
47
|
try {
|
|
37
48
|
const res = yield fetch('https://api.merkl.xyz/v4/opportunities?mainProtocolId=aave', {
|
|
@@ -42,29 +53,33 @@ export const getMerkleCampaigns = (chainId) => __awaiter(void 0, void 0, void 0,
|
|
|
42
53
|
const opportunities = yield res.json();
|
|
43
54
|
const relevantOpportunities = opportunities
|
|
44
55
|
.filter((o) => o.chainId === chainId)
|
|
45
|
-
.filter((o) => o.
|
|
56
|
+
.filter((o) => o.status === OpportunityStatus.LIVE);
|
|
46
57
|
return relevantOpportunities.reduce((acc, opportunity) => {
|
|
58
|
+
var _a, _b;
|
|
47
59
|
const rewardToken = opportunity.rewardsRecord.breakdowns[0].token;
|
|
48
|
-
|
|
49
|
-
|
|
60
|
+
const description = `Eligible for ${formatAaveAsset(rewardToken.symbol)} rewards through Merkl. ${opportunity.description ? `\n${opportunity.description}` : ''}`;
|
|
61
|
+
if (opportunity.action === OpportunityAction.LEND && opportunity.explorerAddress) {
|
|
62
|
+
const supplyAToken = (_a = opportunity.explorerAddress) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
50
63
|
if (!acc[supplyAToken])
|
|
51
64
|
acc[supplyAToken] = {};
|
|
52
65
|
acc[supplyAToken].supply = {
|
|
53
|
-
|
|
54
|
-
rewardToken: rewardToken.address,
|
|
55
|
-
rewardTokenSymbol:
|
|
56
|
-
description
|
|
66
|
+
apy: aprToApy(opportunity.apr),
|
|
67
|
+
// rewardToken: rewardToken.address,
|
|
68
|
+
rewardTokenSymbol: rewardToken.symbol,
|
|
69
|
+
description,
|
|
70
|
+
identifier: opportunity.identifier,
|
|
57
71
|
};
|
|
58
72
|
}
|
|
59
|
-
if (opportunity.action === OpportunityAction.BORROW) {
|
|
60
|
-
const borrowAToken = opportunity.explorerAddress.toLowerCase();
|
|
73
|
+
if (opportunity.action === OpportunityAction.BORROW && opportunity.explorerAddress) {
|
|
74
|
+
const borrowAToken = (_b = opportunity.explorerAddress) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
|
61
75
|
if (!acc[borrowAToken])
|
|
62
76
|
acc[borrowAToken] = {};
|
|
63
77
|
acc[borrowAToken].borrow = {
|
|
64
|
-
|
|
65
|
-
rewardToken: rewardToken.address,
|
|
66
|
-
rewardTokenSymbol:
|
|
67
|
-
description
|
|
78
|
+
apy: aprToApy(opportunity.apr),
|
|
79
|
+
// rewardToken: rewardToken.address,
|
|
80
|
+
rewardTokenSymbol: rewardToken.symbol,
|
|
81
|
+
description,
|
|
82
|
+
identifier: opportunity.identifier,
|
|
68
83
|
};
|
|
69
84
|
}
|
|
70
85
|
return acc;
|
package/esm/compoundV2/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import Dec from 'decimal.js';
|
|
|
12
12
|
import { BLOCKS_IN_A_YEAR } from '../constants';
|
|
13
13
|
import { aprToApy } from '../moneymarket';
|
|
14
14
|
import { compareAddresses, handleWbtcLegacy, wethToEth } from '../services/utils';
|
|
15
|
+
import { IncentiveKind, } from '../types/common';
|
|
15
16
|
import { CompoundLoanInfoContractViem, ComptrollerContractViem } from '../contracts';
|
|
16
17
|
import { compoundV2CollateralAssets } from '../markets';
|
|
17
18
|
import { getCompoundV2AggregatedData } from '../helpers/compoundHelpers';
|
|
@@ -33,9 +34,6 @@ export const _getCompoundV2MarketsData = (provider, network) => __awaiter(void 0
|
|
|
33
34
|
const compBorrowSpeeds = market.compBorrowSpeeds.toString();
|
|
34
35
|
const assetPrice = market.price.toString();
|
|
35
36
|
const pricePrecisionDiff = 18 - getAssetInfo(getAssetInfoByAddress(cAddresses[i]).underlyingAsset).decimals;
|
|
36
|
-
// compSupplySpeeds/compBorrowSpeeds is per block per market (borrow & supply are separate markets)
|
|
37
|
-
const incentiveSupplyApy = aprToApy((100 * BLOCKS_IN_A_YEAR * +compSupplySpeeds * +compPrice) / +assetPrice / +totalSupply).toString();
|
|
38
|
-
const incentiveBorrowApy = aprToApy((100 * BLOCKS_IN_A_YEAR * +compBorrowSpeeds * +compPrice) / +assetPrice / +totalBorrow).toString();
|
|
39
37
|
if (cAddresses[i].toLowerCase() === '0xc11b1268c1a384e55c48c2391d8d480264a3a7f4'.toLowerCase()) {
|
|
40
38
|
symbol = 'WBTC Legacy';
|
|
41
39
|
isWbtcLegacy = true;
|
|
@@ -45,10 +43,18 @@ export const _getCompoundV2MarketsData = (provider, network) => __awaiter(void 0
|
|
|
45
43
|
underlyingTokenAddress: market.underlyingTokenAddress,
|
|
46
44
|
supplyRate: aprToApy(new Dec(BLOCKS_IN_A_YEAR).times(market.supplyRate.toString()).div(1e16).toString()).toString(),
|
|
47
45
|
borrowRate: aprToApy(new Dec(BLOCKS_IN_A_YEAR).times(market.borrowRate.toString()).div(1e16).toString()).toString(),
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
supplyIncentives: [{
|
|
47
|
+
token: 'COMP',
|
|
48
|
+
apy: aprToApy((100 * BLOCKS_IN_A_YEAR * +compSupplySpeeds * +compPrice) / +assetPrice / +totalSupply).toString(),
|
|
49
|
+
incentiveKind: IncentiveKind.Reward,
|
|
50
|
+
description: 'Eligible for protocol-level COMP incentives.',
|
|
51
|
+
}],
|
|
52
|
+
borrowIncentives: [{
|
|
53
|
+
token: 'COMP',
|
|
54
|
+
apy: aprToApy((100 * BLOCKS_IN_A_YEAR * +compBorrowSpeeds * +compPrice) / +assetPrice / +totalBorrow).toString(),
|
|
55
|
+
incentiveKind: IncentiveKind.Reward,
|
|
56
|
+
description: 'Eligible for protocol-level COMP incentives.',
|
|
57
|
+
}],
|
|
52
58
|
collateralFactor: new Dec(market.collateralFactor.toString()).div(1e18).toString(),
|
|
53
59
|
marketLiquidity: assetAmountInEth(market.marketLiquidity.toString(), handleWbtcLegacy(symbol)),
|
|
54
60
|
utilization: new Dec(market.totalBorrow.toString()).div(totalSupply).times(100).toString(),
|
package/esm/compoundV3/index.js
CHANGED
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
11
|
import { assetAmountInEth, getAssetInfo, getAssetInfoByAddress, } from '@defisaver/tokens';
|
|
12
12
|
import { CompV3ViewContractViem } from '../contracts';
|
|
13
|
+
import { IncentiveKind, } from '../types/common';
|
|
13
14
|
import { getStakingApy, STAKING_ASSETS, } from '../staking';
|
|
14
15
|
import { ethToWeth, wethToEth } from '../services/utils';
|
|
15
16
|
import { ZERO_ADDRESS } from '../constants';
|
|
@@ -43,8 +44,12 @@ export const _getCompoundV3MarketsData = (provider, network, selectedMarket, def
|
|
|
43
44
|
.map((coll) => formatMarketData(coll, network, baseAssetPrice));
|
|
44
45
|
for (const coll of colls) {
|
|
45
46
|
if (STAKING_ASSETS.includes(coll.symbol)) {
|
|
46
|
-
coll.
|
|
47
|
-
|
|
47
|
+
coll.supplyIncentives.push({
|
|
48
|
+
apy: yield getStakingApy(coll.symbol),
|
|
49
|
+
token: coll.symbol,
|
|
50
|
+
incentiveKind: IncentiveKind.Staking,
|
|
51
|
+
description: `Native ${coll.symbol} yield.`,
|
|
52
|
+
});
|
|
48
53
|
}
|
|
49
54
|
}
|
|
50
55
|
const base = formatBaseData(baseTokenInfo, network, baseAssetPrice);
|