@defisaver/positions-sdk 2.0.15-dev.0 → 2.1.0
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.d.ts +3 -0
- package/cjs/aaveV3/index.js +66 -47
- package/cjs/aaveV3/merit.d.ts +7 -0
- package/cjs/aaveV3/merit.js +95 -0
- package/cjs/aaveV3/merkl.d.ts +9 -0
- package/cjs/aaveV3/merkl.js +88 -0
- package/cjs/compoundV2/index.js +13 -7
- package/cjs/compoundV3/index.js +8 -3
- 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 +108 -34
- package/cjs/helpers/aaveHelpers/index.js +0 -1
- package/cjs/helpers/compoundHelpers/index.d.ts +5 -7
- package/cjs/helpers/compoundHelpers/index.js +31 -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.d.ts +0 -2
- package/cjs/liquityV2/index.js +19 -54
- 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 +19 -0
- package/cjs/staking/eligibility.js +67 -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 +3 -8
- package/cjs/types/common.d.ts +18 -4
- package/cjs/types/common.js +12 -1
- package/cjs/types/euler.d.ts +3 -3
- package/cjs/types/fluid.d.ts +3 -5
- package/cjs/types/index.d.ts +2 -0
- package/cjs/types/index.js +2 -0
- package/cjs/types/liquityV2.d.ts +3 -3
- package/cjs/types/llamaLend.d.ts +3 -1
- package/cjs/types/merit.d.ts +9 -0
- package/cjs/types/merit.js +2 -0
- package/cjs/types/merkl.d.ts +75 -0
- package/cjs/types/merkl.js +14 -0
- 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.d.ts +3 -0
- package/esm/aaveV3/index.js +65 -47
- package/esm/aaveV3/merit.d.ts +7 -0
- package/esm/aaveV3/merit.js +90 -0
- package/esm/aaveV3/merkl.d.ts +9 -0
- package/esm/aaveV3/merkl.js +82 -0
- package/esm/compoundV2/index.js +13 -7
- package/esm/compoundV3/index.js +8 -3
- 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 +109 -35
- package/esm/helpers/aaveHelpers/index.js +0 -1
- package/esm/helpers/compoundHelpers/index.d.ts +5 -7
- package/esm/helpers/compoundHelpers/index.js +34 -14
- 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.d.ts +0 -2
- package/esm/liquityV2/index.js +18 -51
- 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 +19 -0
- package/esm/staking/eligibility.js +58 -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 +3 -8
- package/esm/types/common.d.ts +18 -4
- package/esm/types/common.js +11 -0
- package/esm/types/euler.d.ts +3 -3
- package/esm/types/fluid.d.ts +3 -5
- package/esm/types/index.d.ts +2 -0
- package/esm/types/index.js +2 -0
- package/esm/types/liquityV2.d.ts +3 -3
- package/esm/types/llamaLend.d.ts +3 -1
- package/esm/types/merit.d.ts +9 -0
- package/esm/types/merit.js +1 -0
- package/esm/types/merkl.d.ts +75 -0
- package/esm/types/merkl.js +11 -0
- 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 +516 -488
- package/src/aaveV3/merit.ts +94 -0
- package/src/aaveV3/merkl.ts +74 -0
- 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 +1638 -1568
- package/src/helpers/aaveHelpers/index.ts +169 -170
- package/src/helpers/compoundHelpers/index.ts +283 -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 -454
- 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 +61 -0
- package/src/staking/index.ts +2 -1
- package/src/staking/staking.ts +169 -194
- package/src/types/aave.ts +189 -194
- package/src/types/common.ts +105 -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 +14 -12
- 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/merit.ts +2 -0
- package/src/types/merkl.ts +71 -0
- package/src/types/morphoBlue.ts +194 -194
- package/src/types/portfolio.ts +60 -60
- package/src/types/spark.ts +135 -137
package/esm/liquityV2/index.js
CHANGED
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
11
|
import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
|
|
12
12
|
import { createViemContractFromConfigFunc, LiquityV2LegacyViewContractViem, LiquityV2ViewContractViem, } from '../contracts';
|
|
13
|
-
import { NetworkNumber } from '../types/common';
|
|
13
|
+
import { IncentiveKind, NetworkNumber, } from '../types/common';
|
|
14
14
|
import { LIQUITY_V2_TROVE_STATUS_ENUM, LiquityV2Versions, } from '../types';
|
|
15
15
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
16
16
|
import { getLiquityV2AggregatedPositionData } from '../helpers/liquityV2Helpers';
|
|
@@ -58,6 +58,8 @@ export const _getLiquityV2MarketData = (provider, network, selectedMarket) => __
|
|
|
58
58
|
canBeBorrowed: true,
|
|
59
59
|
leftToBorrowGlobal,
|
|
60
60
|
leftToWithdrawGlobal: '0',
|
|
61
|
+
supplyIncentives: [],
|
|
62
|
+
borrowIncentives: [],
|
|
61
63
|
};
|
|
62
64
|
assetsData[collateralToken] = {
|
|
63
65
|
symbol: collateralToken,
|
|
@@ -69,10 +71,16 @@ export const _getLiquityV2MarketData = (provider, network, selectedMarket) => __
|
|
|
69
71
|
canBeBorrowed: false,
|
|
70
72
|
leftToBorrowGlobal: '0',
|
|
71
73
|
leftToWithdrawGlobal,
|
|
74
|
+
supplyIncentives: [],
|
|
75
|
+
borrowIncentives: [],
|
|
72
76
|
};
|
|
73
77
|
if (STAKING_ASSETS.includes(collateralToken)) {
|
|
74
|
-
assetsData[collateralToken].
|
|
75
|
-
|
|
78
|
+
assetsData[collateralToken].supplyIncentives.push({
|
|
79
|
+
apy: yield getStakingApy(collateralToken),
|
|
80
|
+
token: collateralToken,
|
|
81
|
+
incentiveKind: IncentiveKind.Staking,
|
|
82
|
+
description: `Native ${collateralToken} yield.`,
|
|
83
|
+
});
|
|
76
84
|
}
|
|
77
85
|
return {
|
|
78
86
|
assetsData,
|
|
@@ -182,40 +190,12 @@ const getAllMarketsUnbackedDebts = (markets, isLegacy, provider, network) => __a
|
|
|
182
190
|
})));
|
|
183
191
|
return Object.fromEntries(allMarketsUnbackedDebt);
|
|
184
192
|
});
|
|
185
|
-
|
|
186
|
-
// Sanity check to avoid division by 0. Very unlikely to ever happen.
|
|
187
|
-
const selectedMarketTotalBorrow = new Dec(markets[selectedMarket].assetsData[LiquityV2Markets(NetworkNumber.Eth)[selectedMarket].debtToken].totalBorrow);
|
|
188
|
-
if (selectedMarketTotalBorrow.eq(0))
|
|
189
|
-
return new Dec(0).toString();
|
|
193
|
+
const calculateDebtInFrontLiquityV2 = (markets, selectedMarket, allMarketsUnbackedDebts, interestRateDebtInFront) => {
|
|
190
194
|
const selectedMarketUnbackedDebt = new Dec(allMarketsUnbackedDebts[selectedMarket]);
|
|
191
195
|
const { isLegacy } = LiquityV2Markets(NetworkNumber.Eth)[selectedMarket];
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
// - First add up all the unbacked debt from other branches, as that will be the only debt that will be redeemed on the fist redemption call
|
|
196
|
-
// - Perform split the same way as we would do when totalUnbackedDebt == 0, this would represent the second call to the redemption function
|
|
197
|
-
if (selectedMarketUnbackedDebt.eq(0)) {
|
|
198
|
-
// Special case if the branch debt in front is 0, it means that all debt in front is unbacked debt from other branches.
|
|
199
|
-
if (new Dec(interestRateDebtInFront).eq(0))
|
|
200
|
-
return totalUnbackedDebt.toString();
|
|
201
|
-
// Then calculate how much of that estimated amount would go to each branch
|
|
202
|
-
// Second redemption call - calculate proportional redemption based on updated total debt
|
|
203
|
-
const amountBeingRedeemedOnEachMarketByTotalBorrow = Object.entries(markets).map(([version, market]) => {
|
|
204
|
-
const { isLegacy: isLegacyMarket } = LiquityV2Markets(NetworkNumber.Eth)[version];
|
|
205
|
-
if (version === selectedMarket && isLegacyMarket !== isLegacy)
|
|
206
|
-
return new Dec(interestRateDebtInFront);
|
|
207
|
-
const { assetsData } = market;
|
|
208
|
-
const { debtToken } = LiquityV2Markets(NetworkNumber.Eth)[version];
|
|
209
|
-
// For other markets, subtract their unbacked debt as it will be cleared in first redemption call
|
|
210
|
-
const marketUnbackedDebt = new Dec(allMarketsUnbackedDebts[version]);
|
|
211
|
-
const totalBorrow = new Dec(assetsData[debtToken].totalBorrow).sub(marketUnbackedDebt);
|
|
212
|
-
const amountToRedeem = new Dec(interestRateDebtInFront).mul(totalBorrow).div(selectedMarketTotalBorrow);
|
|
213
|
-
return Dec.min(amountToRedeem, totalBorrow);
|
|
214
|
-
});
|
|
215
|
-
const redemptionAmount = amountBeingRedeemedOnEachMarketByTotalBorrow.reduce((acc, val) => acc.plus(val), new Dec(0));
|
|
216
|
-
return totalUnbackedDebt.plus(redemptionAmount).toString();
|
|
217
|
-
}
|
|
218
|
-
const amountBeingRedeemedOnEachMarketByUnbackedDebt = Object.entries(markets).map(([version, market]) => {
|
|
196
|
+
if (selectedMarketUnbackedDebt.eq(0))
|
|
197
|
+
return interestRateDebtInFront;
|
|
198
|
+
const amountBeingReedemedOnEachMarket = Object.entries(markets).map(([version, market]) => {
|
|
219
199
|
const { isLegacy: isLegacyMarket } = LiquityV2Markets(NetworkNumber.Eth)[version];
|
|
220
200
|
if (version === selectedMarket && isLegacyMarket !== isLegacy)
|
|
221
201
|
return new Dec(interestRateDebtInFront);
|
|
@@ -223,24 +203,11 @@ export const calculateDebtInFrontLiquityV2 = (markets, selectedMarket, allMarket
|
|
|
223
203
|
const { debtToken } = LiquityV2Markets(NetworkNumber.Eth)[version];
|
|
224
204
|
const unbackedDebt = new Dec(allMarketsUnbackedDebts[version]);
|
|
225
205
|
const totalBorrow = new Dec(assetsData[debtToken].totalBorrow);
|
|
226
|
-
const
|
|
227
|
-
return Dec.min(
|
|
206
|
+
const amountToReedem = new Dec(interestRateDebtInFront).mul(unbackedDebt).div(selectedMarketUnbackedDebt);
|
|
207
|
+
return Dec.min(amountToReedem, totalBorrow);
|
|
228
208
|
});
|
|
229
|
-
return
|
|
209
|
+
return amountBeingReedemedOnEachMarket.reduce((acc, val) => acc.plus(val), new Dec(0)).toString();
|
|
230
210
|
};
|
|
231
|
-
// @dev The amount redeemed on each branch depends on the unbacked debt of every branch (the difference between total borrow and stability pool deposits).
|
|
232
|
-
// When new debt is generated on the selected market, the unbacked debt will increase, resulting in a higher redemption amount on that branch.
|
|
233
|
-
// This function accepts the new debt that's about to be generated (e.g., trove creation) and estimates the debt in front based on the new state.
|
|
234
|
-
export const getDebtInFrontForInterestRateIncludingNewDebtLiquityV2 = (newDebt, markets, selectedMarket, provider, network, interestRate) => __awaiter(void 0, void 0, void 0, function* () {
|
|
235
|
-
const marketsWithNewDebt = structuredClone(markets);
|
|
236
|
-
const selectedMarketDebtToken = LiquityV2Markets(network)[selectedMarket].debtToken;
|
|
237
|
-
const currentTotalBorrow = new Dec(marketsWithNewDebt[selectedMarket].assetsData[selectedMarketDebtToken].totalBorrow);
|
|
238
|
-
marketsWithNewDebt[selectedMarket].assetsData[selectedMarketDebtToken].totalBorrow = currentTotalBorrow.add(newDebt).toString();
|
|
239
|
-
const { isLegacy } = LiquityV2Markets(NetworkNumber.Eth)[selectedMarket];
|
|
240
|
-
const allMarketsUnbackedDebts = yield getAllMarketsUnbackedDebts(marketsWithNewDebt, isLegacy, provider, network);
|
|
241
|
-
const interestRateDebtInFront = new Dec(yield getDebtInFrontForInterestRateSingleMarketLiquityV2(provider, network, isLegacy, LiquityV2Markets(network)[selectedMarket].marketAddress, interestRate));
|
|
242
|
-
return calculateDebtInFrontLiquityV2(marketsWithNewDebt, selectedMarket, allMarketsUnbackedDebts, interestRateDebtInFront.toString());
|
|
243
|
-
});
|
|
244
211
|
const getDebtInFrontLiquityV2 = (markets, selectedMarket, provider, network, viewContract, troveId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
245
212
|
const { isLegacy } = LiquityV2Markets(NetworkNumber.Eth)[selectedMarket];
|
|
246
213
|
const allMarketsUnbackedDebts = yield getAllMarketsUnbackedDebts(markets, isLegacy, provider, network);
|
package/esm/llamaLend/index.js
CHANGED
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
11
|
import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
|
|
12
12
|
import { LlamaLendStatus, } from '../types';
|
|
13
|
-
import { NetworkNumber, } from '../types/common';
|
|
13
|
+
import { IncentiveKind, NetworkNumber, } from '../types/common';
|
|
14
14
|
import { LlamaLendViewContractViem } from '../contracts';
|
|
15
15
|
import { getLlamaLendAggregatedData } from '../helpers/llamaLendHelpers';
|
|
16
16
|
import { getEthAmountForDecimals, wethToEth } from '../services/utils';
|
|
@@ -89,6 +89,8 @@ export const _getLlamaLendGlobalData = (provider, network, selectedMarket) => __
|
|
|
89
89
|
borrowRate,
|
|
90
90
|
canBeSupplied: true,
|
|
91
91
|
canBeBorrowed: true,
|
|
92
|
+
supplyIncentives: [],
|
|
93
|
+
borrowIncentives: [],
|
|
92
94
|
};
|
|
93
95
|
assetsData[collAsset] = {
|
|
94
96
|
symbol: collAsset,
|
|
@@ -98,10 +100,16 @@ export const _getLlamaLendGlobalData = (provider, network, selectedMarket) => __
|
|
|
98
100
|
borrowRate: '0',
|
|
99
101
|
canBeSupplied: true,
|
|
100
102
|
canBeBorrowed: false,
|
|
103
|
+
supplyIncentives: [],
|
|
104
|
+
borrowIncentives: [],
|
|
101
105
|
};
|
|
102
106
|
if (STAKING_ASSETS.includes(collAsset)) {
|
|
103
|
-
assetsData[collAsset].
|
|
104
|
-
|
|
107
|
+
assetsData[collAsset].supplyIncentives.push({
|
|
108
|
+
apy: yield getStakingApy(collAsset),
|
|
109
|
+
token: collAsset,
|
|
110
|
+
incentiveKind: IncentiveKind.Staking,
|
|
111
|
+
description: `Native ${collAsset} yield.`,
|
|
112
|
+
});
|
|
105
113
|
}
|
|
106
114
|
return {
|
|
107
115
|
A: data.A.toString(),
|
package/esm/morphoBlue/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
11
|
import { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
12
|
-
import { NetworkNumber, } from '../types/common';
|
|
12
|
+
import { IncentiveKind, NetworkNumber, } from '../types/common';
|
|
13
13
|
import { DFSFeedRegistryContractViem, FeedRegistryContractViem, MorphoBlueViewContractViem, } from '../contracts';
|
|
14
14
|
import { USD_QUOTE, WAD } from '../constants';
|
|
15
15
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
@@ -77,10 +77,18 @@ export function _getMorphoBlueMarketData(provider, network, selectedMarket) {
|
|
|
77
77
|
totalBorrow: new Dec(marketInfo.totalBorrowAssets.toString()).div(scale).toString(),
|
|
78
78
|
canBeSupplied: true,
|
|
79
79
|
canBeBorrowed: true,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
supplyIncentives: [{
|
|
81
|
+
token: 'MORPHO',
|
|
82
|
+
apy: morphoSupplyApy,
|
|
83
|
+
incentiveKind: IncentiveKind.Reward,
|
|
84
|
+
description: 'Eligible for protocol-level MORPHO incentives.',
|
|
85
|
+
}],
|
|
86
|
+
borrowIncentives: [{
|
|
87
|
+
token: 'MORPHO',
|
|
88
|
+
apy: morphoBorrowApy,
|
|
89
|
+
incentiveKind: IncentiveKind.Reward,
|
|
90
|
+
description: 'Eligible for protocol-level MORPHO incentives.',
|
|
91
|
+
}],
|
|
84
92
|
};
|
|
85
93
|
assetsData[wethToEth(collateralTokenInfo.symbol)] = {
|
|
86
94
|
symbol: wethToEth(collateralTokenInfo.symbol),
|
|
@@ -90,10 +98,16 @@ export function _getMorphoBlueMarketData(provider, network, selectedMarket) {
|
|
|
90
98
|
borrowRate: '0',
|
|
91
99
|
canBeSupplied: true,
|
|
92
100
|
canBeBorrowed: false,
|
|
101
|
+
supplyIncentives: [],
|
|
102
|
+
borrowIncentives: [],
|
|
93
103
|
};
|
|
94
104
|
if (STAKING_ASSETS.includes(collateralTokenInfo.symbol)) {
|
|
95
|
-
assetsData[collateralTokenInfo.symbol].
|
|
96
|
-
|
|
105
|
+
assetsData[collateralTokenInfo.symbol].supplyIncentives = [{
|
|
106
|
+
apy: yield getStakingApy(collateralTokenInfo.symbol),
|
|
107
|
+
token: collateralTokenInfo.symbol,
|
|
108
|
+
incentiveKind: IncentiveKind.Staking,
|
|
109
|
+
description: `Native ${collateralTokenInfo.symbol} yield.`,
|
|
110
|
+
}];
|
|
97
111
|
}
|
|
98
112
|
return {
|
|
99
113
|
id: marketInfo.id,
|
package/esm/spark/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
11
|
import { assetAmountInEth, assetAmountInWei, getAssetInfo } from '@defisaver/tokens';
|
|
12
|
-
import { NetworkNumber, } from '../types/common';
|
|
12
|
+
import { IncentiveKind, NetworkNumber, } from '../types/common';
|
|
13
13
|
import { ethToWeth, wethToEth, wethToEthByAddress, } from '../services/utils';
|
|
14
14
|
import { calculateNetApy, getStakingApy, STAKING_ASSETS, } from '../staking';
|
|
15
15
|
import { SparkViewContractViem, SparkIncentiveDataProviderContractViem, createViemContractFromConfigFunc, } from '../contracts';
|
|
@@ -116,36 +116,32 @@ export const _getSparkMarketsData = (provider, network, selectedMarket) => __awa
|
|
|
116
116
|
collateralFactor: new Dec(market.ltv).div(10000).toString(),
|
|
117
117
|
priceSource: market.priceSource,
|
|
118
118
|
},
|
|
119
|
+
supplyIncentives: [],
|
|
120
|
+
borrowIncentives: [],
|
|
119
121
|
});
|
|
120
122
|
})));
|
|
121
123
|
yield Promise.all(assetsData.map((market) => __awaiter(void 0, void 0, void 0, function* () {
|
|
122
124
|
/* eslint-disable no-param-reassign */
|
|
123
125
|
const rewardForMarket = rewardInfo[market.underlyingTokenAddress];
|
|
124
126
|
if (STAKING_ASSETS.includes(market.symbol)) {
|
|
125
|
-
|
|
126
|
-
market.incentiveSupplyToken = market.symbol;
|
|
127
|
-
if (!market.supplyIncentives) {
|
|
128
|
-
market.supplyIncentives = [];
|
|
129
|
-
}
|
|
127
|
+
const yieldApy = yield getStakingApy(market.symbol);
|
|
130
128
|
market.supplyIncentives.push({
|
|
131
|
-
apy:
|
|
129
|
+
apy: yieldApy,
|
|
132
130
|
token: market.symbol,
|
|
131
|
+
incentiveKind: IncentiveKind.Staking,
|
|
132
|
+
description: `Native ${market.symbol} yield.`,
|
|
133
133
|
});
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
134
|
+
if (market.canBeBorrowed) {
|
|
135
|
+
if (!market.borrowIncentives) {
|
|
136
|
+
market.borrowIncentives = [];
|
|
137
|
+
}
|
|
138
|
+
market.borrowIncentives.push({
|
|
139
|
+
apy: new Dec(yieldApy).mul(-1).toString(),
|
|
140
|
+
token: market.symbol,
|
|
141
|
+
incentiveKind: IncentiveKind.Reward,
|
|
142
|
+
description: `Due to the native yield of ${market.symbol}, the value of the debt would increase over time.`,
|
|
143
|
+
});
|
|
144
144
|
}
|
|
145
|
-
market.borrowIncentives.push({
|
|
146
|
-
apy: market.incentiveBorrowApy,
|
|
147
|
-
token: market.incentiveBorrowToken,
|
|
148
|
-
});
|
|
149
145
|
}
|
|
150
146
|
if (!rewardForMarket)
|
|
151
147
|
return;
|
|
@@ -153,7 +149,6 @@ export const _getSparkMarketsData = (provider, network, selectedMarket) => __awa
|
|
|
153
149
|
if (supplyRewardData) {
|
|
154
150
|
if (supplyRewardData.emissionEndTimestamp * 1000 < Date.now())
|
|
155
151
|
return;
|
|
156
|
-
market.incentiveSupplyToken = supplyRewardData.rewardTokenSymbol;
|
|
157
152
|
const supplyEmissionPerSecond = supplyRewardData.emissionPerSecond;
|
|
158
153
|
const supplyRewardPrice = new Dec(supplyRewardData.rewardPriceFeed).div(Math.pow(10, supplyRewardData.priceFeedDecimals))
|
|
159
154
|
.toString();
|
|
@@ -163,13 +158,11 @@ export const _getSparkMarketsData = (provider, network, selectedMarket) => __awa
|
|
|
163
158
|
.div(market.price)
|
|
164
159
|
.div(market.totalSupply)
|
|
165
160
|
.toString();
|
|
166
|
-
market.incentiveSupplyApy = new Dec(market.incentiveSupplyApy || '0').add(rewardApy).toString();
|
|
167
|
-
if (!market.supplyIncentives) {
|
|
168
|
-
market.supplyIncentives = [];
|
|
169
|
-
}
|
|
170
161
|
market.supplyIncentives.push({
|
|
171
162
|
token: supplyRewardData.rewardTokenSymbol,
|
|
172
163
|
apy: rewardApy,
|
|
164
|
+
incentiveKind: IncentiveKind.Reward,
|
|
165
|
+
description: 'Eligible for protocol-level incentives.',
|
|
173
166
|
});
|
|
174
167
|
}
|
|
175
168
|
});
|
|
@@ -177,7 +170,6 @@ export const _getSparkMarketsData = (provider, network, selectedMarket) => __awa
|
|
|
177
170
|
if (borrowRewardData) {
|
|
178
171
|
if (borrowRewardData.emissionEndTimestamp * 1000 < Date.now())
|
|
179
172
|
return;
|
|
180
|
-
market.incentiveBorrowToken = borrowRewardData.rewardTokenSymbol;
|
|
181
173
|
const supplyEmissionPerSecond = borrowRewardData.emissionPerSecond;
|
|
182
174
|
const supplyRewardPrice = new Dec(borrowRewardData.rewardPriceFeed).div(Math.pow(10, borrowRewardData.priceFeedDecimals))
|
|
183
175
|
.toString();
|
|
@@ -187,13 +179,11 @@ export const _getSparkMarketsData = (provider, network, selectedMarket) => __awa
|
|
|
187
179
|
.div(market.price)
|
|
188
180
|
.div(market.totalBorrowVar)
|
|
189
181
|
.toString();
|
|
190
|
-
market.incentiveBorrowApy = new Dec(market.incentiveBorrowApy || '0').add(rewardApy).toString();
|
|
191
|
-
if (!market.borrowIncentives) {
|
|
192
|
-
market.borrowIncentives = [];
|
|
193
|
-
}
|
|
194
182
|
market.borrowIncentives.push({
|
|
195
183
|
token: borrowRewardData.rewardTokenSymbol,
|
|
196
184
|
apy: rewardApy,
|
|
185
|
+
incentiveKind: IncentiveKind.Reward,
|
|
186
|
+
description: 'Eligible for protocol-level incentives.',
|
|
197
187
|
});
|
|
198
188
|
}
|
|
199
189
|
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IncentiveEligibilityId, MMUsedAssets } from '../types/common';
|
|
2
|
+
export declare const isEligibleForEthenaUSDeRewards: (usedAssets: MMUsedAssets) => {
|
|
3
|
+
isEligible: boolean;
|
|
4
|
+
eligibleUSDAmount: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const isEligibleForAaveV3ArbitrumEthSupply: (usedAssets: MMUsedAssets) => {
|
|
7
|
+
isEligible: boolean;
|
|
8
|
+
eligibleUSDAmount: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const isEligibleForAaveV3ArbitrumETHLSBorrow: (usedAssets: MMUsedAssets) => {
|
|
11
|
+
isEligible: boolean;
|
|
12
|
+
eligibleUSDAmount: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const EligibilityMapping: {
|
|
15
|
+
[key in IncentiveEligibilityId]: (usedAssets: MMUsedAssets) => {
|
|
16
|
+
isEligible: boolean;
|
|
17
|
+
eligibleUSDAmount: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import Dec from 'decimal.js';
|
|
2
|
+
import { IncentiveEligibilityId } from '../types/common';
|
|
3
|
+
export const isEligibleForEthenaUSDeRewards = (usedAssets) => {
|
|
4
|
+
var _a, _b;
|
|
5
|
+
const USDeUSDAmountSupplied = ((_a = usedAssets.USDe) === null || _a === void 0 ? void 0 : _a.suppliedUsd) || '0';
|
|
6
|
+
const sUSDeUSDAmountSupplied = ((_b = usedAssets.sUSDe) === null || _b === void 0 ? void 0 : _b.suppliedUsd) || '0';
|
|
7
|
+
const anythingElseSupplied = Object.values(usedAssets).some((asset) => asset.symbol !== 'USDe' && asset.symbol !== 'sUSDe' && asset.isSupplied);
|
|
8
|
+
if (anythingElseSupplied)
|
|
9
|
+
return { isEligible: false, eligibleUSDAmount: '0' };
|
|
10
|
+
const totalAmountSupplied = new Dec(USDeUSDAmountSupplied).add(sUSDeUSDAmountSupplied).toString();
|
|
11
|
+
const percentageInUSDe = new Dec(USDeUSDAmountSupplied).div(totalAmountSupplied).toNumber();
|
|
12
|
+
if (percentageInUSDe < 0.45 || percentageInUSDe > 0.55)
|
|
13
|
+
return { isEligible: false, eligibleUSDAmount: '0' }; // 45% - 55% of total amount supplied must be in USDe
|
|
14
|
+
const percentageInSUSDe = new Dec(sUSDeUSDAmountSupplied).div(totalAmountSupplied).toNumber();
|
|
15
|
+
if (percentageInSUSDe < 0.45 || percentageInSUSDe > 0.55)
|
|
16
|
+
return { isEligible: false, eligibleUSDAmount: '0' }; // 45% - 55% of total amount supplied must be in sUSDe
|
|
17
|
+
const allowedBorrowAssets = ['USDC', 'USDT', 'USDS'];
|
|
18
|
+
const anythingBorrowedNotAllowed = Object.values(usedAssets).some((asset) => asset.isBorrowed && !allowedBorrowAssets.includes(asset.symbol));
|
|
19
|
+
if (anythingBorrowedNotAllowed)
|
|
20
|
+
return { isEligible: false, eligibleUSDAmount: '0' };
|
|
21
|
+
const totalAmountBorrowed = Object.values(usedAssets).reduce((acc, asset) => {
|
|
22
|
+
if (asset.isBorrowed) {
|
|
23
|
+
return acc.add(asset.borrowedUsd);
|
|
24
|
+
}
|
|
25
|
+
return acc;
|
|
26
|
+
}, new Dec(0)).toString();
|
|
27
|
+
const borrowPercentage = new Dec(totalAmountBorrowed).div(totalAmountSupplied).toNumber();
|
|
28
|
+
if (borrowPercentage < 0.5)
|
|
29
|
+
return { isEligible: false, eligibleUSDAmount: '0' }; // must be looped at least once
|
|
30
|
+
const halfAmountSupplied = new Dec(totalAmountSupplied).div(2).toString();
|
|
31
|
+
const USDeAmountEligibleForRewards = Dec.min(USDeUSDAmountSupplied, halfAmountSupplied).toString(); // rewards are given to amount of USDe supplied up to half of total amount supplied
|
|
32
|
+
return { isEligible: true, eligibleUSDAmount: USDeAmountEligibleForRewards };
|
|
33
|
+
};
|
|
34
|
+
export const isEligibleForAaveV3ArbitrumEthSupply = (usedAssets) => {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
const ETHAmountSupplied = ((_a = usedAssets.ETH) === null || _a === void 0 ? void 0 : _a.suppliedUsd) || '0';
|
|
37
|
+
const ETHAmountBorrowed = ((_b = usedAssets.ETH) === null || _b === void 0 ? void 0 : _b.borrowedUsd) || '0';
|
|
38
|
+
const delta = new Dec(ETHAmountSupplied).sub(ETHAmountBorrowed).toString();
|
|
39
|
+
return { isEligible: true, eligibleUSDAmount: Dec.max(delta, 0).toString() };
|
|
40
|
+
};
|
|
41
|
+
export const isEligibleForAaveV3ArbitrumETHLSBorrow = (usedAssets) => {
|
|
42
|
+
var _a;
|
|
43
|
+
const allowedBorrowAssets = ['ETH'];
|
|
44
|
+
const anythingBorrowedNotAllowed = Object.values(usedAssets).some((asset) => asset.isBorrowed && !allowedBorrowAssets.includes(asset.symbol));
|
|
45
|
+
if (anythingBorrowedNotAllowed)
|
|
46
|
+
return { isEligible: false, eligibleUSDAmount: '0' };
|
|
47
|
+
const allowedSupplyAssets = ['wstETH', 'ezETH', 'weETH', 'rsETH'];
|
|
48
|
+
const anythingSuppliedNotAllowed = Object.values(usedAssets).some((asset) => asset.isSupplied && !allowedSupplyAssets.includes(asset.symbol));
|
|
49
|
+
if (anythingSuppliedNotAllowed)
|
|
50
|
+
return { isEligible: false, eligibleUSDAmount: '0' };
|
|
51
|
+
const ETHAmountBorrowed = ((_a = usedAssets.ETH) === null || _a === void 0 ? void 0 : _a.borrowedUsd) || '0';
|
|
52
|
+
return { isEligible: true, eligibleUSDAmount: ETHAmountBorrowed };
|
|
53
|
+
};
|
|
54
|
+
export const EligibilityMapping = {
|
|
55
|
+
[IncentiveEligibilityId.AaveV3EthenaLiquidLeverage]: isEligibleForEthenaUSDeRewards,
|
|
56
|
+
[IncentiveEligibilityId.AaveV3ArbitrumEthSupply]: isEligibleForAaveV3ArbitrumEthSupply,
|
|
57
|
+
[IncentiveEligibilityId.AaveV3ArbitrumETHLSBorrow]: isEligibleForAaveV3ArbitrumETHLSBorrow,
|
|
58
|
+
};
|
package/esm/staking/index.d.ts
CHANGED
package/esm/staking/index.js
CHANGED
package/esm/staking/staking.d.ts
CHANGED
|
@@ -3,15 +3,9 @@ import { MMAssetsData, MMUsedAssets } from '../types/common';
|
|
|
3
3
|
export declare const STAKING_ASSETS: string[];
|
|
4
4
|
export declare const getStakingApy: ((asset: string) => Promise<string>) & memoize.Memoized<(asset: string) => Promise<string>>;
|
|
5
5
|
export declare const calculateInterestEarned: (principal: string, interest: string, type: string, apy?: boolean) => number;
|
|
6
|
-
export declare const
|
|
7
|
-
isEligible: boolean;
|
|
8
|
-
eligibleUSDAmount: string;
|
|
9
|
-
};
|
|
10
|
-
export declare const calculateNetApy: ({ usedAssets, assetsData, isMorpho, isAave, }: {
|
|
6
|
+
export declare const calculateNetApy: ({ usedAssets, assetsData, }: {
|
|
11
7
|
usedAssets: MMUsedAssets;
|
|
12
8
|
assetsData: MMAssetsData;
|
|
13
|
-
isMorpho?: boolean;
|
|
14
|
-
isAave?: boolean;
|
|
15
9
|
}) => {
|
|
16
10
|
netApy: string;
|
|
17
11
|
totalInterestUsd: string;
|
package/esm/staking/staking.js
CHANGED
|
@@ -11,6 +11,7 @@ import Dec from 'decimal.js';
|
|
|
11
11
|
import memoize from 'memoizee';
|
|
12
12
|
import { BLOCKS_IN_A_YEAR } from '../constants';
|
|
13
13
|
import { DEFAULT_TIMEOUT } from '../services/utils';
|
|
14
|
+
import { EligibilityMapping } from './eligibility';
|
|
14
15
|
const getSsrApy = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
16
|
try {
|
|
16
17
|
const res = yield fetch('https://fe.defisaver.com/api/sky/data', { signal: AbortSignal.timeout(DEFAULT_TIMEOUT) });
|
|
@@ -128,74 +129,48 @@ export const calculateInterestEarned = (principal, interest, type, apy = false)
|
|
|
128
129
|
}
|
|
129
130
|
return (+principal * (Math.pow(((1 + (+interest / 100) / BLOCKS_IN_A_YEAR)), (BLOCKS_IN_A_YEAR * interval)))) - +principal; // eslint-disable-line
|
|
130
131
|
};
|
|
131
|
-
export const
|
|
132
|
-
var _a, _b;
|
|
133
|
-
const USDeUSDAmountSupplied = ((_a = usedAssets.USDe) === null || _a === void 0 ? void 0 : _a.suppliedUsd) || '0';
|
|
134
|
-
const sUSDeUSDAmountSupplied = ((_b = usedAssets.sUSDe) === null || _b === void 0 ? void 0 : _b.suppliedUsd) || '0';
|
|
135
|
-
const anythingElseSupplied = Object.values(usedAssets).some((asset) => asset.symbol !== 'USDe' && asset.symbol !== 'sUSDe' && asset.isSupplied);
|
|
136
|
-
if (anythingElseSupplied)
|
|
137
|
-
return { isEligible: false, eligibleUSDAmount: '0' };
|
|
138
|
-
const totalAmountSupplied = new Dec(USDeUSDAmountSupplied).add(sUSDeUSDAmountSupplied).toString();
|
|
139
|
-
const percentageInUSDe = new Dec(USDeUSDAmountSupplied).div(totalAmountSupplied).toNumber();
|
|
140
|
-
if (percentageInUSDe < 0.45 || percentageInUSDe > 0.55)
|
|
141
|
-
return { isEligible: false, eligibleUSDAmount: '0' }; // 45% - 55% of total amount supplied must be in USDe
|
|
142
|
-
const percentageInSUSDe = new Dec(sUSDeUSDAmountSupplied).div(totalAmountSupplied).toNumber();
|
|
143
|
-
if (percentageInSUSDe < 0.45 || percentageInSUSDe > 0.55)
|
|
144
|
-
return { isEligible: false, eligibleUSDAmount: '0' }; // 45% - 55% of total amount supplied must be in sUSDe
|
|
145
|
-
const allowedBorrowAssets = ['USDC', 'USDT', 'USDS'];
|
|
146
|
-
const anythingBorrowedNotAllowed = Object.values(usedAssets).some((asset) => asset.isBorrowed && !allowedBorrowAssets.includes(asset.symbol));
|
|
147
|
-
if (anythingBorrowedNotAllowed)
|
|
148
|
-
return { isEligible: false, eligibleUSDAmount: '0' };
|
|
149
|
-
const totalAmountBorrowed = Object.values(usedAssets).reduce((acc, asset) => {
|
|
150
|
-
if (asset.isBorrowed) {
|
|
151
|
-
return acc.add(asset.borrowedUsd);
|
|
152
|
-
}
|
|
153
|
-
return acc;
|
|
154
|
-
}, new Dec(0)).toString();
|
|
155
|
-
const borrowPercentage = new Dec(totalAmountBorrowed).div(totalAmountSupplied).toNumber();
|
|
156
|
-
if (borrowPercentage < 0.5)
|
|
157
|
-
return { isEligible: false, eligibleUSDAmount: '0' }; // must be looped at least once
|
|
158
|
-
const halfAmountSupplied = new Dec(totalAmountSupplied).div(2).toString();
|
|
159
|
-
const USDeAmountEligibleForRewards = Dec.min(USDeUSDAmountSupplied, halfAmountSupplied).toString(); // rewards are given to amount of USDe supplied up to half of total amount supplied
|
|
160
|
-
return { isEligible: true, eligibleUSDAmount: USDeAmountEligibleForRewards };
|
|
161
|
-
};
|
|
162
|
-
export const calculateNetApy = ({ usedAssets, assetsData, isMorpho = false, isAave = false, }) => {
|
|
163
|
-
const { isEligible, eligibleUSDAmount } = isAave ? isEligibleForEthenaUSDeRewards(usedAssets) : { isEligible: true, eligibleUSDAmount: '0' };
|
|
132
|
+
export const calculateNetApy = ({ usedAssets, assetsData, }) => {
|
|
164
133
|
const sumValues = Object.values(usedAssets).reduce((_acc, usedAsset) => {
|
|
165
|
-
var _a, _b;
|
|
166
134
|
const acc = Object.assign({}, _acc);
|
|
167
135
|
const assetData = assetsData[usedAsset.symbol];
|
|
168
136
|
if (usedAsset.isSupplied) {
|
|
169
137
|
const amount = usedAsset.suppliedUsd;
|
|
170
138
|
acc.suppliedUsd = new Dec(acc.suppliedUsd).add(amount).toString();
|
|
171
|
-
const rate =
|
|
172
|
-
? usedAsset.supplyRate === '0' ? assetData.supplyRateP2P : usedAsset.supplyRate
|
|
173
|
-
: assetData.supplyRate;
|
|
139
|
+
const rate = assetData.supplyRate;
|
|
174
140
|
const supplyInterest = calculateInterestEarned(amount, rate, 'year', true);
|
|
175
141
|
acc.supplyInterest = new Dec(acc.supplyInterest).add(supplyInterest.toString()).toString();
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
142
|
+
for (const supplyIncentive of assetData.supplyIncentives) {
|
|
143
|
+
const { apy, eligibilityId } = supplyIncentive;
|
|
144
|
+
const eligibilityCheck = eligibilityId ? EligibilityMapping[eligibilityId] : null;
|
|
145
|
+
if (eligibilityCheck) {
|
|
146
|
+
const { isEligible, eligibleUSDAmount } = eligibilityCheck(usedAssets);
|
|
147
|
+
const incentiveInterest = isEligible ? calculateInterestEarned(eligibleUSDAmount, apy, 'year', true) : '0';
|
|
148
|
+
acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const incentiveInterest = calculateInterestEarned(amount, apy, 'year', true);
|
|
152
|
+
acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
|
|
153
|
+
}
|
|
185
154
|
}
|
|
186
155
|
}
|
|
187
156
|
if (usedAsset.isBorrowed) {
|
|
188
157
|
const amount = usedAsset.borrowedUsd;
|
|
189
158
|
acc.borrowedUsd = new Dec(acc.borrowedUsd).add(amount).toString();
|
|
190
|
-
const rate =
|
|
191
|
-
? usedAsset.borrowRate === '0' ? assetData.borrowRateP2P : usedAsset.borrowRate
|
|
192
|
-
: ((usedAsset === null || usedAsset === void 0 ? void 0 : usedAsset.interestMode) === '1' ? usedAsset.stableBorrowRate : assetData.borrowRate);
|
|
159
|
+
const rate = assetData.borrowRate;
|
|
193
160
|
const borrowInterest = calculateInterestEarned(amount, rate, 'year', true);
|
|
194
161
|
acc.borrowInterest = new Dec(acc.borrowInterest).sub(borrowInterest.toString()).toString();
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const
|
|
198
|
-
|
|
162
|
+
for (const borrowIncentive of assetData.borrowIncentives) {
|
|
163
|
+
const { apy, eligibilityId } = borrowIncentive;
|
|
164
|
+
const eligibilityCheck = eligibilityId ? EligibilityMapping[eligibilityId] : null;
|
|
165
|
+
if (eligibilityCheck) {
|
|
166
|
+
const { isEligible, eligibleUSDAmount } = eligibilityCheck(usedAssets);
|
|
167
|
+
const incentiveInterest = isEligible ? calculateInterestEarned(eligibleUSDAmount, apy, 'year', true) : '0';
|
|
168
|
+
acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
const incentiveInterest = calculateInterestEarned(amount, apy, 'year', true);
|
|
172
|
+
acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
|
|
173
|
+
}
|
|
199
174
|
}
|
|
200
175
|
}
|
|
201
176
|
return acc;
|
package/esm/types/aave.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MMAssetData, MMPositionData, MMUsedAsset, NetworkNumber } from './common';
|
|
1
|
+
import { IncentiveData, MMAssetData, MMPositionData, MMUsedAsset, NetworkNumber } from './common';
|
|
2
2
|
export declare enum AaveVersions {
|
|
3
3
|
AaveV1 = "v1",
|
|
4
4
|
AaveV2 = "v2default",
|
|
@@ -62,11 +62,6 @@ export interface AaveV2AssetData extends AaveAssetData {
|
|
|
62
62
|
priceInEth: string;
|
|
63
63
|
isFrozen: boolean;
|
|
64
64
|
}
|
|
65
|
-
export interface IncentiveData {
|
|
66
|
-
token: string;
|
|
67
|
-
apy: string;
|
|
68
|
-
incentiveKind?: 'staking' | 'reward';
|
|
69
|
-
}
|
|
70
65
|
export interface AaveV3AssetData extends AaveAssetData {
|
|
71
66
|
isIsolated: boolean;
|
|
72
67
|
isSiloed: boolean;
|
|
@@ -80,8 +75,8 @@ export interface AaveV3AssetData extends AaveAssetData {
|
|
|
80
75
|
isFlashLoanEnabled: boolean;
|
|
81
76
|
assetId: string | number | null;
|
|
82
77
|
liquidationBonus: string;
|
|
83
|
-
supplyIncentives
|
|
84
|
-
borrowIncentives
|
|
78
|
+
supplyIncentives: IncentiveData[];
|
|
79
|
+
borrowIncentives: IncentiveData[];
|
|
85
80
|
}
|
|
86
81
|
export type EModeCategoriesData = Record<number, EModeCategoryData>;
|
|
87
82
|
export type AaveAssetsData<T> = {
|
package/esm/types/common.d.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
export declare enum IncentiveKind {
|
|
2
|
+
Staking = "staking",
|
|
3
|
+
Reward = "reward"
|
|
4
|
+
}
|
|
5
|
+
export declare enum IncentiveEligibilityId {
|
|
6
|
+
AaveV3EthenaLiquidLeverage = "0x8772bb231f3af13ead41d7ecf6abd60f5f716ec8BORROW_BL",
|
|
7
|
+
AaveV3ArbitrumEthSupply = "0x5d16261c6715a653248269861bbacf68a9774cde",
|
|
8
|
+
AaveV3ArbitrumETHLSBorrow = "0x0c84331e39d6658Cd6e6b9ba04736cC4c4734351"
|
|
9
|
+
}
|
|
10
|
+
export interface IncentiveData {
|
|
11
|
+
token: string;
|
|
12
|
+
apy: string;
|
|
13
|
+
incentiveKind?: IncentiveKind;
|
|
14
|
+
description?: string;
|
|
15
|
+
eligibilityId?: IncentiveEligibilityId;
|
|
16
|
+
}
|
|
1
17
|
export type EthAddress = HexString;
|
|
2
18
|
export type Blockish = number | 'latest';
|
|
3
19
|
export type AssetSymbol = string;
|
|
@@ -24,12 +40,10 @@ export interface MMAssetData {
|
|
|
24
40
|
canBeBorrowed: boolean;
|
|
25
41
|
canBeSupplied: boolean;
|
|
26
42
|
totalBorrow: string;
|
|
27
|
-
incentiveBorrowApy?: string;
|
|
28
|
-
incentiveBorrowToken?: string;
|
|
29
|
-
incentiveSupplyApy?: string;
|
|
30
|
-
incentiveSupplyToken?: string;
|
|
31
43
|
borrowRateP2P?: string;
|
|
32
44
|
supplyRateP2P?: string;
|
|
45
|
+
supplyIncentives: IncentiveData[];
|
|
46
|
+
borrowIncentives: IncentiveData[];
|
|
33
47
|
}
|
|
34
48
|
export interface MMAssetsData {
|
|
35
49
|
[token: string]: MMAssetData;
|
package/esm/types/common.js
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
export var IncentiveKind;
|
|
2
|
+
(function (IncentiveKind) {
|
|
3
|
+
IncentiveKind["Staking"] = "staking";
|
|
4
|
+
IncentiveKind["Reward"] = "reward";
|
|
5
|
+
})(IncentiveKind || (IncentiveKind = {}));
|
|
6
|
+
export var IncentiveEligibilityId;
|
|
7
|
+
(function (IncentiveEligibilityId) {
|
|
8
|
+
IncentiveEligibilityId["AaveV3EthenaLiquidLeverage"] = "0x8772bb231f3af13ead41d7ecf6abd60f5f716ec8BORROW_BL";
|
|
9
|
+
IncentiveEligibilityId["AaveV3ArbitrumEthSupply"] = "0x5d16261c6715a653248269861bbacf68a9774cde";
|
|
10
|
+
IncentiveEligibilityId["AaveV3ArbitrumETHLSBorrow"] = "0x0c84331e39d6658Cd6e6b9ba04736cC4c4734351";
|
|
11
|
+
})(IncentiveEligibilityId || (IncentiveEligibilityId = {}));
|
|
1
12
|
export var NetworkNumber;
|
|
2
13
|
(function (NetworkNumber) {
|
|
3
14
|
NetworkNumber[NetworkNumber["Eth"] = 1] = "Eth";
|
package/esm/types/euler.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, MMPositionData, NetworkNumber } from './common';
|
|
1
|
+
import { EthAddress, IncentiveData, MMPositionData, NetworkNumber } from './common';
|
|
2
2
|
export declare enum EulerV2Versions {
|
|
3
3
|
eUSDC2 = "eUSDC-2",
|
|
4
4
|
eWETH2 = "eWETH-2"
|
|
@@ -42,8 +42,8 @@ export interface EulerV2AssetData {
|
|
|
42
42
|
borrowCap: string;
|
|
43
43
|
canBeBorrowed: boolean;
|
|
44
44
|
canBeSupplied: boolean;
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
supplyIncentives: IncentiveData[];
|
|
46
|
+
borrowIncentives: IncentiveData[];
|
|
47
47
|
totalBorrow: string;
|
|
48
48
|
collateralFactor: string;
|
|
49
49
|
borrowRate: string;
|
package/esm/types/fluid.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, NetworkNumber } from './common';
|
|
1
|
+
import { EthAddress, IncentiveData, NetworkNumber } from './common';
|
|
2
2
|
export interface FluidMarketInfo {
|
|
3
3
|
chainIds: number[];
|
|
4
4
|
label: string;
|
|
@@ -181,10 +181,8 @@ export interface FluidAssetData {
|
|
|
181
181
|
symbol: string;
|
|
182
182
|
address: string;
|
|
183
183
|
price: string;
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
incentiveBorrowApy?: string;
|
|
187
|
-
incentiveBorrowToken?: string;
|
|
184
|
+
supplyIncentives: IncentiveData[];
|
|
185
|
+
borrowIncentives: IncentiveData[];
|
|
188
186
|
totalSupply: string;
|
|
189
187
|
totalBorrow: string;
|
|
190
188
|
canBeSupplied: boolean;
|