@defisaver/positions-sdk 2.1.144-dev → 2.1.144
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/fluid/index.js +6 -2
- package/cjs/helpers/fluidHelpers/index.js +5 -4
- package/cjs/staking/eligibility.d.ts +15 -1
- package/cjs/staking/eligibility.js +12 -1
- package/cjs/staking/staking.js +18 -22
- package/esm/fluid/index.js +6 -2
- package/esm/helpers/fluidHelpers/index.js +6 -5
- package/esm/staking/eligibility.d.ts +15 -1
- package/esm/staking/eligibility.js +10 -0
- package/esm/staking/staking.js +19 -23
- package/package.json +1 -1
- package/src/fluid/index.ts +6 -2
- package/src/helpers/fluidHelpers/index.ts +6 -5
- package/src/staking/eligibility.ts +29 -2
- package/src/staking/staking.ts +20 -22
package/cjs/fluid/index.js
CHANGED
|
@@ -1282,8 +1282,12 @@ const getAllUserEarnPositionsWithFTokens = (provider, network, user) => __awaite
|
|
|
1282
1282
|
exports.getAllUserEarnPositionsWithFTokens = getAllUserEarnPositionsWithFTokens;
|
|
1283
1283
|
const _getUserPositions = (provider, network, user) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1284
1284
|
const view = (0, contracts_1.FluidViewContractViem)(provider, network);
|
|
1285
|
-
const data = yield
|
|
1286
|
-
|
|
1285
|
+
const [data, merklCampaigns] = yield Promise.all([
|
|
1286
|
+
view.read.getUserPositions([user]),
|
|
1287
|
+
(0, merkl_1.getFluidMerklCampaigns)(network),
|
|
1288
|
+
]);
|
|
1289
|
+
const parsedMarketData = (yield Promise.all(data[1].map((vaultData) => __awaiter(void 0, void 0, void 0, function* () { return parseMarketData(provider, vaultData, network); }))))
|
|
1290
|
+
.map(marketData => (marketData ? (0, merkl_1.attachFluidMerklIncentives)(marketData, merklCampaigns) : marketData));
|
|
1287
1291
|
const userData = data[0].map((position, i) => (parsedMarketData[i] && Object.assign({}, parseUserData(position, parsedMarketData[i]))));
|
|
1288
1292
|
return parsedMarketData.map((market, i) => ({
|
|
1289
1293
|
marketData: market,
|
|
@@ -23,10 +23,11 @@ const getUniqueFluidMerklIncentives = (assetsData, side) => {
|
|
|
23
23
|
};
|
|
24
24
|
exports.getUniqueFluidMerklIncentives = getUniqueFluidMerklIncentives;
|
|
25
25
|
const getMerklIncentiveInterest = (incentives, principal, usedAssets) => incentives.reduce((total, { apy, eligibilityId }) => {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
:
|
|
26
|
+
const { isEligible, eligibleUSDAmount } = (0, staking_1.getIncentiveEligibility)({
|
|
27
|
+
incentive: { eligibilityId },
|
|
28
|
+
usedAssets,
|
|
29
|
+
defaultEligibleUSDAmount: principal,
|
|
30
|
+
});
|
|
30
31
|
const incentiveInterest = isEligible ? (0, staking_1.calculateInterestEarned)(eligibleUSDAmount, apy, 'year', true) : 0;
|
|
31
32
|
return new decimal_js_1.default(total).add(incentiveInterest).toString();
|
|
32
33
|
}, '0');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IncentiveEligibilityId, MMUsedAssets } from '../types/common';
|
|
1
|
+
import { IncentiveData, IncentiveEligibilityId, MMUsedAssets } from '../types/common';
|
|
2
2
|
export declare const isEligibleForEthenaUSDeRewards: (usedAssets: MMUsedAssets, { healthRatio }: {
|
|
3
3
|
healthRatio: string;
|
|
4
4
|
}) => {
|
|
@@ -29,3 +29,17 @@ export declare const EligibilityMapping: {
|
|
|
29
29
|
eligibleUSDAmount: string;
|
|
30
30
|
};
|
|
31
31
|
};
|
|
32
|
+
export type IncentiveEligibilityResult = {
|
|
33
|
+
isEligible: boolean;
|
|
34
|
+
eligibleUSDAmount: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Resolves an incentive's position-specific eligibility and rewarded USD principal. Incentives
|
|
38
|
+
* without a curated eligibility rule apply to the full side amount supplied by the caller.
|
|
39
|
+
*/
|
|
40
|
+
export declare const getIncentiveEligibility: ({ incentive, usedAssets, defaultEligibleUSDAmount, optionalData, }: {
|
|
41
|
+
incentive: Pick<IncentiveData, "eligibilityId">;
|
|
42
|
+
usedAssets: MMUsedAssets;
|
|
43
|
+
defaultEligibleUSDAmount: string;
|
|
44
|
+
optionalData?: any;
|
|
45
|
+
}) => IncentiveEligibilityResult;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.EligibilityMapping = exports.isEligibleForCompoundV3PufEthWethBorrow = exports.isEligibleForAaveV3ArbitrumETHLSBorrow = exports.isEligibleForAaveV3ArbitrumEthSupply = exports.isEligibleForEthenaGHORewards = exports.isEligibleForEthenaUSDeRewards = void 0;
|
|
6
|
+
exports.getIncentiveEligibility = exports.EligibilityMapping = exports.isEligibleForCompoundV3PufEthWethBorrow = exports.isEligibleForAaveV3ArbitrumETHLSBorrow = exports.isEligibleForAaveV3ArbitrumEthSupply = exports.isEligibleForEthenaGHORewards = exports.isEligibleForEthenaUSDeRewards = void 0;
|
|
7
7
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
8
|
const common_1 = require("../types/common");
|
|
9
9
|
const isEligibleForEthenaPairRewards = (usedAssets, { healthRatio }, { baseSymbol, pairSymbol, allowedBorrowAssets, maxHealthRatio, rewardSymbol, }) => {
|
|
@@ -87,3 +87,14 @@ exports.EligibilityMapping = {
|
|
|
87
87
|
[common_1.IncentiveEligibilityId.AaveV3EthenaLiquidLeveragePlasmaGHO]: exports.isEligibleForEthenaGHORewards,
|
|
88
88
|
[common_1.IncentiveEligibilityId.CompoundV3PufEthWethBorrow]: exports.isEligibleForCompoundV3PufEthWethBorrow,
|
|
89
89
|
};
|
|
90
|
+
/**
|
|
91
|
+
* Resolves an incentive's position-specific eligibility and rewarded USD principal. Incentives
|
|
92
|
+
* without a curated eligibility rule apply to the full side amount supplied by the caller.
|
|
93
|
+
*/
|
|
94
|
+
const getIncentiveEligibility = ({ incentive, usedAssets, defaultEligibleUSDAmount, optionalData, }) => {
|
|
95
|
+
const eligibilityCheck = incentive.eligibilityId ? exports.EligibilityMapping[incentive.eligibilityId] : null;
|
|
96
|
+
return eligibilityCheck
|
|
97
|
+
? eligibilityCheck(usedAssets, optionalData)
|
|
98
|
+
: { isEligible: true, eligibleUSDAmount: defaultEligibleUSDAmount };
|
|
99
|
+
};
|
|
100
|
+
exports.getIncentiveEligibility = getIncentiveEligibility;
|
package/cjs/staking/staking.js
CHANGED
|
@@ -201,17 +201,15 @@ const calculateNetApy = ({ usedAssets, assetsData, optionalData, }) => {
|
|
|
201
201
|
acc.supplyInterest = new decimal_js_1.default(acc.supplyInterest).add(supplyInterest.toString()).toString();
|
|
202
202
|
if (assetData.supplyIncentives) {
|
|
203
203
|
for (const supplyIncentive of assetData.supplyIncentives) {
|
|
204
|
-
const { apy
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
acc.incentiveUsd = new decimal_js_1.default(acc.incentiveUsd).add(incentiveInterest).toString();
|
|
214
|
-
}
|
|
204
|
+
const { apy } = supplyIncentive;
|
|
205
|
+
const { isEligible, eligibleUSDAmount } = (0, eligibility_1.getIncentiveEligibility)({
|
|
206
|
+
incentive: supplyIncentive,
|
|
207
|
+
usedAssets,
|
|
208
|
+
defaultEligibleUSDAmount: amount,
|
|
209
|
+
optionalData,
|
|
210
|
+
});
|
|
211
|
+
const incentiveInterest = isEligible ? (0, exports.calculateInterestEarned)(eligibleUSDAmount, apy, 'year', true) : '0';
|
|
212
|
+
acc.incentiveUsd = new decimal_js_1.default(acc.incentiveUsd).add(incentiveInterest).toString();
|
|
215
213
|
}
|
|
216
214
|
}
|
|
217
215
|
}
|
|
@@ -223,17 +221,15 @@ const calculateNetApy = ({ usedAssets, assetsData, optionalData, }) => {
|
|
|
223
221
|
acc.borrowInterest = new decimal_js_1.default(acc.borrowInterest).sub(borrowInterest.toString()).toString();
|
|
224
222
|
if (assetData.borrowIncentives) {
|
|
225
223
|
for (const borrowIncentive of assetData.borrowIncentives) {
|
|
226
|
-
const { apy
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
acc.incentiveUsd = new decimal_js_1.default(acc.incentiveUsd).add(incentiveInterest).toString();
|
|
236
|
-
}
|
|
224
|
+
const { apy } = borrowIncentive;
|
|
225
|
+
const { isEligible, eligibleUSDAmount } = (0, eligibility_1.getIncentiveEligibility)({
|
|
226
|
+
incentive: borrowIncentive,
|
|
227
|
+
usedAssets,
|
|
228
|
+
defaultEligibleUSDAmount: amount,
|
|
229
|
+
optionalData,
|
|
230
|
+
});
|
|
231
|
+
const incentiveInterest = isEligible ? (0, exports.calculateInterestEarned)(eligibleUSDAmount, apy, 'year', true) : '0';
|
|
232
|
+
acc.incentiveUsd = new decimal_js_1.default(acc.incentiveUsd).add(incentiveInterest).toString();
|
|
237
233
|
}
|
|
238
234
|
}
|
|
239
235
|
}
|
package/esm/fluid/index.js
CHANGED
|
@@ -1256,8 +1256,12 @@ export const _getAllUserEarnPositionsWithFTokens = (provider, network, user) =>
|
|
|
1256
1256
|
export const getAllUserEarnPositionsWithFTokens = (provider, network, user) => __awaiter(void 0, void 0, void 0, function* () { return _getAllUserEarnPositionsWithFTokens(getViemProvider(provider, network), network, user); });
|
|
1257
1257
|
export const _getUserPositions = (provider, network, user) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1258
1258
|
const view = FluidViewContractViem(provider, network);
|
|
1259
|
-
const data = yield
|
|
1260
|
-
|
|
1259
|
+
const [data, merklCampaigns] = yield Promise.all([
|
|
1260
|
+
view.read.getUserPositions([user]),
|
|
1261
|
+
getFluidMerklCampaigns(network),
|
|
1262
|
+
]);
|
|
1263
|
+
const parsedMarketData = (yield Promise.all(data[1].map((vaultData) => __awaiter(void 0, void 0, void 0, function* () { return parseMarketData(provider, vaultData, network); }))))
|
|
1264
|
+
.map(marketData => (marketData ? attachFluidMerklIncentives(marketData, merklCampaigns) : marketData));
|
|
1261
1265
|
const userData = data[0].map((position, i) => (parsedMarketData[i] && Object.assign({}, parseUserData(position, parsedMarketData[i]))));
|
|
1262
1266
|
return parsedMarketData.map((market, i) => ({
|
|
1263
1267
|
marketData: market,
|
|
@@ -2,7 +2,7 @@ import Dec from 'decimal.js';
|
|
|
2
2
|
import { assetAmountInEth } from '@defisaver/tokens';
|
|
3
3
|
import { FluidVaultType, IncentiveSource, } from '../../types';
|
|
4
4
|
import { calcLeverageLiqPrice, getAssetsTotal, getExposure, isLeveragedPos, } from '../../moneymarket';
|
|
5
|
-
import { calculateInterestEarned, calculateNetApy,
|
|
5
|
+
import { calculateInterestEarned, calculateNetApy, getIncentiveEligibility } from '../../staking';
|
|
6
6
|
import { IncentiveSide, LeverageType } from '../../types/common';
|
|
7
7
|
import { getEthAmountForDecimals } from '../../services/utils';
|
|
8
8
|
export const getUniqueFluidMerklIncentives = (assetsData, side) => {
|
|
@@ -16,10 +16,11 @@ export const getUniqueFluidMerklIncentives = (assetsData, side) => {
|
|
|
16
16
|
])).values()];
|
|
17
17
|
};
|
|
18
18
|
const getMerklIncentiveInterest = (incentives, principal, usedAssets) => incentives.reduce((total, { apy, eligibilityId }) => {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
:
|
|
19
|
+
const { isEligible, eligibleUSDAmount } = getIncentiveEligibility({
|
|
20
|
+
incentive: { eligibilityId },
|
|
21
|
+
usedAssets,
|
|
22
|
+
defaultEligibleUSDAmount: principal,
|
|
23
|
+
});
|
|
23
24
|
const incentiveInterest = isEligible ? calculateInterestEarned(eligibleUSDAmount, apy, 'year', true) : 0;
|
|
24
25
|
return new Dec(total).add(incentiveInterest).toString();
|
|
25
26
|
}, '0');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IncentiveEligibilityId, MMUsedAssets } from '../types/common';
|
|
1
|
+
import { IncentiveData, IncentiveEligibilityId, MMUsedAssets } from '../types/common';
|
|
2
2
|
export declare const isEligibleForEthenaUSDeRewards: (usedAssets: MMUsedAssets, { healthRatio }: {
|
|
3
3
|
healthRatio: string;
|
|
4
4
|
}) => {
|
|
@@ -29,3 +29,17 @@ export declare const EligibilityMapping: {
|
|
|
29
29
|
eligibleUSDAmount: string;
|
|
30
30
|
};
|
|
31
31
|
};
|
|
32
|
+
export type IncentiveEligibilityResult = {
|
|
33
|
+
isEligible: boolean;
|
|
34
|
+
eligibleUSDAmount: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Resolves an incentive's position-specific eligibility and rewarded USD principal. Incentives
|
|
38
|
+
* without a curated eligibility rule apply to the full side amount supplied by the caller.
|
|
39
|
+
*/
|
|
40
|
+
export declare const getIncentiveEligibility: ({ incentive, usedAssets, defaultEligibleUSDAmount, optionalData, }: {
|
|
41
|
+
incentive: Pick<IncentiveData, "eligibilityId">;
|
|
42
|
+
usedAssets: MMUsedAssets;
|
|
43
|
+
defaultEligibleUSDAmount: string;
|
|
44
|
+
optionalData?: any;
|
|
45
|
+
}) => IncentiveEligibilityResult;
|
|
@@ -76,3 +76,13 @@ export const EligibilityMapping = {
|
|
|
76
76
|
[IncentiveEligibilityId.AaveV3EthenaLiquidLeveragePlasmaGHO]: isEligibleForEthenaGHORewards,
|
|
77
77
|
[IncentiveEligibilityId.CompoundV3PufEthWethBorrow]: isEligibleForCompoundV3PufEthWethBorrow,
|
|
78
78
|
};
|
|
79
|
+
/**
|
|
80
|
+
* Resolves an incentive's position-specific eligibility and rewarded USD principal. Incentives
|
|
81
|
+
* without a curated eligibility rule apply to the full side amount supplied by the caller.
|
|
82
|
+
*/
|
|
83
|
+
export const getIncentiveEligibility = ({ incentive, usedAssets, defaultEligibleUSDAmount, optionalData, }) => {
|
|
84
|
+
const eligibilityCheck = incentive.eligibilityId ? EligibilityMapping[incentive.eligibilityId] : null;
|
|
85
|
+
return eligibilityCheck
|
|
86
|
+
? eligibilityCheck(usedAssets, optionalData)
|
|
87
|
+
: { isEligible: true, eligibleUSDAmount: defaultEligibleUSDAmount };
|
|
88
|
+
};
|
package/esm/staking/staking.js
CHANGED
|
@@ -12,7 +12,7 @@ import memoize from 'memoizee';
|
|
|
12
12
|
import { NetworkNumber, } from '../types/common';
|
|
13
13
|
import { BLOCKS_IN_A_YEAR } from '../constants';
|
|
14
14
|
import { DEFAULT_TIMEOUT } from '../services/utils';
|
|
15
|
-
import {
|
|
15
|
+
import { getIncentiveEligibility } from './eligibility';
|
|
16
16
|
const getSsrApy = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
17
|
try {
|
|
18
18
|
const res = yield fetch('https://fe.defisaver.com/api/sky/data', { signal: AbortSignal.timeout(DEFAULT_TIMEOUT) });
|
|
@@ -194,17 +194,15 @@ export const calculateNetApy = ({ usedAssets, assetsData, optionalData, }) => {
|
|
|
194
194
|
acc.supplyInterest = new Dec(acc.supplyInterest).add(supplyInterest.toString()).toString();
|
|
195
195
|
if (assetData.supplyIncentives) {
|
|
196
196
|
for (const supplyIncentive of assetData.supplyIncentives) {
|
|
197
|
-
const { apy
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
|
|
207
|
-
}
|
|
197
|
+
const { apy } = supplyIncentive;
|
|
198
|
+
const { isEligible, eligibleUSDAmount } = getIncentiveEligibility({
|
|
199
|
+
incentive: supplyIncentive,
|
|
200
|
+
usedAssets,
|
|
201
|
+
defaultEligibleUSDAmount: amount,
|
|
202
|
+
optionalData,
|
|
203
|
+
});
|
|
204
|
+
const incentiveInterest = isEligible ? calculateInterestEarned(eligibleUSDAmount, apy, 'year', true) : '0';
|
|
205
|
+
acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
|
|
208
206
|
}
|
|
209
207
|
}
|
|
210
208
|
}
|
|
@@ -216,17 +214,15 @@ export const calculateNetApy = ({ usedAssets, assetsData, optionalData, }) => {
|
|
|
216
214
|
acc.borrowInterest = new Dec(acc.borrowInterest).sub(borrowInterest.toString()).toString();
|
|
217
215
|
if (assetData.borrowIncentives) {
|
|
218
216
|
for (const borrowIncentive of assetData.borrowIncentives) {
|
|
219
|
-
const { apy
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
|
|
229
|
-
}
|
|
217
|
+
const { apy } = borrowIncentive;
|
|
218
|
+
const { isEligible, eligibleUSDAmount } = getIncentiveEligibility({
|
|
219
|
+
incentive: borrowIncentive,
|
|
220
|
+
usedAssets,
|
|
221
|
+
defaultEligibleUSDAmount: amount,
|
|
222
|
+
optionalData,
|
|
223
|
+
});
|
|
224
|
+
const incentiveInterest = isEligible ? calculateInterestEarned(eligibleUSDAmount, apy, 'year', true) : '0';
|
|
225
|
+
acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
|
|
230
226
|
}
|
|
231
227
|
}
|
|
232
228
|
}
|
package/package.json
CHANGED
package/src/fluid/index.ts
CHANGED
|
@@ -1689,9 +1689,13 @@ export const getAllUserEarnPositionsWithFTokens = async (
|
|
|
1689
1689
|
export const _getUserPositions = async (provider: PublicClient, network: NetworkNumber, user: EthAddress) => {
|
|
1690
1690
|
const view = FluidViewContractViem(provider, network);
|
|
1691
1691
|
|
|
1692
|
-
const data = await
|
|
1692
|
+
const [data, merklCampaigns] = await Promise.all([
|
|
1693
|
+
view.read.getUserPositions([user]),
|
|
1694
|
+
getFluidMerklCampaigns(network),
|
|
1695
|
+
]);
|
|
1693
1696
|
|
|
1694
|
-
const parsedMarketData = (await Promise.all(data[1].map(async (vaultData) => parseMarketData(provider, vaultData, network))))
|
|
1697
|
+
const parsedMarketData = (await Promise.all(data[1].map(async (vaultData) => parseMarketData(provider, vaultData, network))))
|
|
1698
|
+
.map(marketData => (marketData ? attachFluidMerklIncentives(marketData, merklCampaigns) : marketData));
|
|
1695
1699
|
|
|
1696
1700
|
const userData = data[0].map((position, i) => (parsedMarketData[i] && { ...parseUserData(position, parsedMarketData[i]) }));
|
|
1697
1701
|
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
import {
|
|
13
13
|
calcLeverageLiqPrice, getAssetsTotal, getExposure, isLeveragedPos,
|
|
14
14
|
} from '../../moneymarket';
|
|
15
|
-
import { calculateInterestEarned, calculateNetApy,
|
|
15
|
+
import { calculateInterestEarned, calculateNetApy, getIncentiveEligibility } from '../../staking';
|
|
16
16
|
import { IncentiveSide, LeverageType, MMAssetsData } from '../../types/common';
|
|
17
17
|
import { getEthAmountForDecimals } from '../../services/utils';
|
|
18
18
|
|
|
@@ -33,10 +33,11 @@ const getMerklIncentiveInterest = (
|
|
|
33
33
|
principal: string,
|
|
34
34
|
usedAssets: FluidUsedAssets,
|
|
35
35
|
) => incentives.reduce((total, { apy, eligibilityId }) => {
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
:
|
|
36
|
+
const { isEligible, eligibleUSDAmount } = getIncentiveEligibility({
|
|
37
|
+
incentive: { eligibilityId },
|
|
38
|
+
usedAssets,
|
|
39
|
+
defaultEligibleUSDAmount: principal,
|
|
40
|
+
});
|
|
40
41
|
const incentiveInterest = isEligible ? calculateInterestEarned(eligibleUSDAmount, apy, 'year', true) : 0;
|
|
41
42
|
|
|
42
43
|
return new Dec(total).add(incentiveInterest).toString();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
|
-
import { IncentiveEligibilityId, MMUsedAssets } from '../types/common';
|
|
2
|
+
import { IncentiveData, IncentiveEligibilityId, MMUsedAssets } from '../types/common';
|
|
3
3
|
|
|
4
4
|
type EthenaPairEligibilityConfig = {
|
|
5
5
|
baseSymbol: string;
|
|
@@ -113,4 +113,31 @@ export const EligibilityMapping: { [key in IncentiveEligibilityId]: (usedAssets:
|
|
|
113
113
|
[IncentiveEligibilityId.AaveV3EthenaLiquidLeveragePlasma]: isEligibleForEthenaUSDeRewards,
|
|
114
114
|
[IncentiveEligibilityId.AaveV3EthenaLiquidLeveragePlasmaGHO]: isEligibleForEthenaGHORewards,
|
|
115
115
|
[IncentiveEligibilityId.CompoundV3PufEthWethBorrow]: isEligibleForCompoundV3PufEthWethBorrow,
|
|
116
|
-
};
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export type IncentiveEligibilityResult = {
|
|
119
|
+
isEligible: boolean;
|
|
120
|
+
eligibleUSDAmount: string;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Resolves an incentive's position-specific eligibility and rewarded USD principal. Incentives
|
|
125
|
+
* without a curated eligibility rule apply to the full side amount supplied by the caller.
|
|
126
|
+
*/
|
|
127
|
+
export const getIncentiveEligibility = ({
|
|
128
|
+
incentive,
|
|
129
|
+
usedAssets,
|
|
130
|
+
defaultEligibleUSDAmount,
|
|
131
|
+
optionalData,
|
|
132
|
+
}: {
|
|
133
|
+
incentive: Pick<IncentiveData, 'eligibilityId'>;
|
|
134
|
+
usedAssets: MMUsedAssets;
|
|
135
|
+
defaultEligibleUSDAmount: string;
|
|
136
|
+
optionalData?: any;
|
|
137
|
+
}): IncentiveEligibilityResult => {
|
|
138
|
+
const eligibilityCheck = incentive.eligibilityId ? EligibilityMapping[incentive.eligibilityId] : null;
|
|
139
|
+
|
|
140
|
+
return eligibilityCheck
|
|
141
|
+
? eligibilityCheck(usedAssets, optionalData)
|
|
142
|
+
: { isEligible: true, eligibleUSDAmount: defaultEligibleUSDAmount };
|
|
143
|
+
};
|
package/src/staking/staking.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from '../types/common';
|
|
8
8
|
import { BLOCKS_IN_A_YEAR } from '../constants';
|
|
9
9
|
import { DEFAULT_TIMEOUT } from '../services/utils';
|
|
10
|
-
import {
|
|
10
|
+
import { getIncentiveEligibility } from './eligibility';
|
|
11
11
|
|
|
12
12
|
const getSsrApy = async () => {
|
|
13
13
|
try {
|
|
@@ -153,16 +153,15 @@ export const calculateNetApy = ({
|
|
|
153
153
|
|
|
154
154
|
if (assetData.supplyIncentives) {
|
|
155
155
|
for (const supplyIncentive of assetData.supplyIncentives) {
|
|
156
|
-
const { apy
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
156
|
+
const { apy } = supplyIncentive;
|
|
157
|
+
const { isEligible, eligibleUSDAmount } = getIncentiveEligibility({
|
|
158
|
+
incentive: supplyIncentive,
|
|
159
|
+
usedAssets,
|
|
160
|
+
defaultEligibleUSDAmount: amount,
|
|
161
|
+
optionalData,
|
|
162
|
+
});
|
|
163
|
+
const incentiveInterest = isEligible ? calculateInterestEarned(eligibleUSDAmount, apy, 'year', true) : '0';
|
|
164
|
+
acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
|
|
166
165
|
}
|
|
167
166
|
}
|
|
168
167
|
}
|
|
@@ -176,16 +175,15 @@ export const calculateNetApy = ({
|
|
|
176
175
|
|
|
177
176
|
if (assetData.borrowIncentives) {
|
|
178
177
|
for (const borrowIncentive of assetData.borrowIncentives) {
|
|
179
|
-
const { apy
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
178
|
+
const { apy } = borrowIncentive;
|
|
179
|
+
const { isEligible, eligibleUSDAmount } = getIncentiveEligibility({
|
|
180
|
+
incentive: borrowIncentive,
|
|
181
|
+
usedAssets,
|
|
182
|
+
defaultEligibleUSDAmount: amount,
|
|
183
|
+
optionalData,
|
|
184
|
+
});
|
|
185
|
+
const incentiveInterest = isEligible ? calculateInterestEarned(eligibleUSDAmount, apy, 'year', true) : '0';
|
|
186
|
+
acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
|
|
189
187
|
}
|
|
190
188
|
}
|
|
191
189
|
}
|
|
@@ -204,4 +202,4 @@ export const calculateNetApy = ({
|
|
|
204
202
|
const netApy = new Dec(totalInterestUsd).div(balance).times(100).toString();
|
|
205
203
|
|
|
206
204
|
return { netApy, totalInterestUsd, incentiveUsd };
|
|
207
|
-
};
|
|
205
|
+
};
|