@defisaver/positions-sdk 2.0.15-dev → 2.0.15-dev-3
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/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,11 @@
|
|
|
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 EligibilityMapping: {
|
|
7
|
+
[key in IncentiveEligibilityId]: (usedAssets: MMUsedAssets) => {
|
|
8
|
+
isEligible: boolean;
|
|
9
|
+
eligibleUSDAmount: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
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 EligibilityMapping = {
|
|
35
|
+
[IncentiveEligibilityId.AaveV3EthenaLiquidLeverage]: isEligibleForEthenaUSDeRewards,
|
|
36
|
+
};
|
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,12 +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
|
-
description?: string;
|
|
70
|
-
}
|
|
71
65
|
export interface AaveV3AssetData extends AaveAssetData {
|
|
72
66
|
isIsolated: boolean;
|
|
73
67
|
isSiloed: boolean;
|
package/esm/types/common.d.ts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
export declare enum IncentiveKind {
|
|
2
|
+
Staking = "staking",
|
|
3
|
+
Reward = "reward"
|
|
4
|
+
}
|
|
5
|
+
export declare enum IncentiveEligibilityId {
|
|
6
|
+
AaveV3EthenaLiquidLeverage = "0x8772bb231f3af13ead41d7ecf6abd60f5f716ec8BORROW_BL"
|
|
7
|
+
}
|
|
8
|
+
export interface IncentiveData {
|
|
9
|
+
token: string;
|
|
10
|
+
apy: string;
|
|
11
|
+
incentiveKind?: IncentiveKind;
|
|
12
|
+
description?: string;
|
|
13
|
+
eligibilityId?: IncentiveEligibilityId;
|
|
14
|
+
}
|
|
1
15
|
export type EthAddress = HexString;
|
|
2
16
|
export type Blockish = number | 'latest';
|
|
3
17
|
export type AssetSymbol = string;
|
|
@@ -24,12 +38,10 @@ export interface MMAssetData {
|
|
|
24
38
|
canBeBorrowed: boolean;
|
|
25
39
|
canBeSupplied: boolean;
|
|
26
40
|
totalBorrow: string;
|
|
27
|
-
incentiveBorrowApy?: string;
|
|
28
|
-
incentiveBorrowToken?: string;
|
|
29
|
-
incentiveSupplyApy?: string;
|
|
30
|
-
incentiveSupplyToken?: string;
|
|
31
41
|
borrowRateP2P?: string;
|
|
32
42
|
supplyRateP2P?: string;
|
|
43
|
+
supplyIncentives: IncentiveData[];
|
|
44
|
+
borrowIncentives: IncentiveData[];
|
|
33
45
|
}
|
|
34
46
|
export interface MMAssetsData {
|
|
35
47
|
[token: string]: MMAssetData;
|
package/esm/types/common.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
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 || (IncentiveEligibilityId = {}));
|
|
1
10
|
export var NetworkNumber;
|
|
2
11
|
(function (NetworkNumber) {
|
|
3
12
|
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;
|
package/esm/types/liquityV2.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, NetworkNumber } from './common';
|
|
1
|
+
import { EthAddress, IncentiveData, NetworkNumber } from './common';
|
|
2
2
|
export declare enum LiquityV2Versions {
|
|
3
3
|
LiquityV2Eth = "liquityv2eth",
|
|
4
4
|
LiquityV2WstEth = "liquityv2wsteth",
|
|
@@ -37,14 +37,14 @@ export interface LiquityV2AssetData {
|
|
|
37
37
|
symbol: string;
|
|
38
38
|
address: string;
|
|
39
39
|
price: string;
|
|
40
|
-
incentiveSupplyApy?: string;
|
|
41
|
-
incentiveSupplyToken?: string;
|
|
42
40
|
totalSupply: string;
|
|
43
41
|
totalBorrow: string;
|
|
44
42
|
canBeSupplied: boolean;
|
|
45
43
|
canBeBorrowed: boolean;
|
|
46
44
|
leftToBorrowGlobal: string;
|
|
47
45
|
leftToWithdrawGlobal: string;
|
|
46
|
+
supplyIncentives: IncentiveData[];
|
|
47
|
+
borrowIncentives: IncentiveData[];
|
|
48
48
|
}
|
|
49
49
|
export type LiquityV2AssetsData = {
|
|
50
50
|
[key: string]: LiquityV2AssetData;
|
package/esm/types/llamaLend.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, NetworkNumber } from './common';
|
|
1
|
+
import { EthAddress, IncentiveData, NetworkNumber } from './common';
|
|
2
2
|
import { BandData, UserBandData } from './curveUsd';
|
|
3
3
|
export declare enum LLVersionsEth {
|
|
4
4
|
LLWstethCrvusd = "llamaLendwstETHcrvUSD",
|
|
@@ -74,6 +74,8 @@ export interface LlamaLendAssetData {
|
|
|
74
74
|
canBeSupplied?: boolean;
|
|
75
75
|
canBeBorrowed?: boolean;
|
|
76
76
|
shares?: string;
|
|
77
|
+
supplyIncentives: IncentiveData[];
|
|
78
|
+
borrowIncentives: IncentiveData[];
|
|
77
79
|
}
|
|
78
80
|
export type LlamaLendAssetsData = {
|
|
79
81
|
[key: string]: LlamaLendAssetData;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, MMUsedAssets, NetworkNumber } from './common';
|
|
1
|
+
import { EthAddress, IncentiveData, MMUsedAssets, NetworkNumber } from './common';
|
|
2
2
|
export declare enum MorphoBlueVersions {
|
|
3
3
|
MorphoBlueWstEthUSDC = "morphobluewstethusdc",// wstETH/USDC
|
|
4
4
|
MorphoBlueSDAIUSDC = "morphobluesdaiusdc",// sDAI/USDC
|
|
@@ -81,10 +81,8 @@ export interface MorphoBlueAssetData {
|
|
|
81
81
|
price: string;
|
|
82
82
|
supplyRate: string;
|
|
83
83
|
borrowRate: string;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
incentiveBorrowApy?: string;
|
|
87
|
-
incentiveBorrowToken?: string;
|
|
84
|
+
supplyIncentives: IncentiveData[];
|
|
85
|
+
borrowIncentives: IncentiveData[];
|
|
88
86
|
totalSupply?: string;
|
|
89
87
|
totalBorrow?: string;
|
|
90
88
|
canBeSupplied?: boolean;
|
package/esm/types/spark.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { EthAddress, MMAssetData, MMPositionData, MMUsedAsset, NetworkNumber } from './common';
|
|
2
|
-
import { IncentiveData } from './aave';
|
|
3
2
|
export declare enum SparkVersions {
|
|
4
3
|
SparkV1 = "v1default"
|
|
5
4
|
}
|
|
@@ -48,8 +47,6 @@ export interface SparkAssetData extends MMAssetData {
|
|
|
48
47
|
eModeCategory: number;
|
|
49
48
|
eModeCategoryData: SparkEModeCategoryData;
|
|
50
49
|
liquidationRatio: string;
|
|
51
|
-
supplyIncentives?: IncentiveData[];
|
|
52
|
-
borrowIncentives?: IncentiveData[];
|
|
53
50
|
}
|
|
54
51
|
export interface SparkAssetsData {
|
|
55
52
|
[token: string]: SparkAssetData;
|