@defisaver/positions-sdk 2.0.15-dev-2 → 2.0.15-dev-4

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.
@@ -60,7 +60,7 @@ const _getCompoundV3MarketsData = (provider, network, selectedMarket, defaultPro
60
60
  }
61
61
  const base = (0, compoundHelpers_1.formatBaseData)(baseTokenInfo, network, baseAssetPrice);
62
62
  const payload = {};
63
- const baseObj = Object.assign(Object.assign({}, base), (0, compoundHelpers_1.getIncentiveApys)(base, compPrice));
63
+ const baseObj = Object.assign(Object.assign({}, base), (yield (0, compoundHelpers_1.getIncentiveApys)(base, compPrice)));
64
64
  const allAssets = [baseObj, ...colls];
65
65
  allAssets
66
66
  .sort((a, b) => {
@@ -2,10 +2,10 @@ import { BaseAdditionalAssetData, CompoundAggregatedPositionData, CompoundMarket
2
2
  import { EthAddress, EthereumProvider, IncentiveData, NetworkNumber } from '../../types/common';
3
3
  export declare const formatMarketData: (data: any, network: NetworkNumber, baseAssetPrice: string) => CompoundV3AssetData;
4
4
  export declare const formatBaseData: (data: any, network: NetworkNumber, baseAssetPrice: string) => CompoundV3AssetData & BaseAdditionalAssetData;
5
- export declare const getIncentiveApys: (baseData: CompoundV3AssetData & BaseAdditionalAssetData, compPrice: string) => {
5
+ export declare const getIncentiveApys: (baseData: CompoundV3AssetData & BaseAdditionalAssetData, compPrice: string) => Promise<{
6
6
  supplyIncentives: IncentiveData[];
7
7
  borrowIncentives: IncentiveData[];
8
- };
8
+ }>;
9
9
  export declare const getCompoundV2AggregatedData: ({ usedAssets, assetsData, ...rest }: {
10
10
  usedAssets: CompoundV2UsedAssets;
11
11
  assetsData: CompoundV2AssetsData;
@@ -53,19 +53,28 @@ const formatBaseData = (data, network, baseAssetPrice) => {
53
53
  totalBorrow, marketLiquidity: new decimal_js_1.default(totalSupply).minus(totalBorrow).toString(), symbol: (0, utils_1.wethToEth)(assetInfo.symbol), priceInBaseAsset: (0, utils_1.getEthAmountForDecimals)(data.price, 8), price: baseAssetPrice, collateralFactor: '0', liquidationRatio: '0', canBeBorrowed: true, canBeSupplied: true, supplyCap: '0', rewardSupplySpeed: (0, utils_1.getEthAmountForDecimals)(data.baseTrackingSupplyRewardsSpeed, 15), rewardBorrowSpeed: (0, utils_1.getEthAmountForDecimals)(data.baseTrackingBorrowRewardsSpeed, 15), minDebt: (0, utils_1.getEthAmountForDecimals)(data.baseBorrowMin, assetInfo.decimals), isBase: true }));
54
54
  };
55
55
  exports.formatBaseData = formatBaseData;
56
- const getIncentiveApys = (baseData, compPrice) => ({
57
- supplyIncentives: [{
58
- token: 'COMP',
59
- apy: (0, moneymarket_1.aprToApy)((100 * constants_1.SECONDS_PER_YEAR * +baseData.rewardSupplySpeed * +compPrice) / +baseData.price / +baseData.totalSupply).toString(),
60
- incentiveKind: common_1.IncentiveKind.Reward,
61
- description: 'Eligible for protocol-level COMP incentives.',
62
- }],
63
- borrowIncentives: [{
64
- token: 'COMP',
65
- apy: (0, moneymarket_1.aprToApy)((100 * constants_1.SECONDS_PER_YEAR * +baseData.rewardBorrowSpeed * +compPrice) / +baseData.price / +baseData.totalBorrow).toString(),
66
- incentiveKind: common_1.IncentiveKind.Reward,
67
- description: 'Eligible for protocol-level COMP incentives.',
68
- }],
56
+ const getIncentiveApys = (baseData, compPrice) => __awaiter(void 0, void 0, void 0, function* () {
57
+ return ({
58
+ supplyIncentives: [{
59
+ token: 'COMP',
60
+ apy: (0, moneymarket_1.aprToApy)((100 * constants_1.SECONDS_PER_YEAR * +baseData.rewardSupplySpeed * +compPrice) / +baseData.price / +baseData.totalSupply).toString(),
61
+ incentiveKind: common_1.IncentiveKind.Reward,
62
+ description: 'Eligible for protocol-level COMP incentives.',
63
+ },
64
+ ...(0, utils_1.addToArrayIf)(staking_1.STAKING_ASSETS.includes(baseData.symbol), {
65
+ apy: yield (0, staking_1.getStakingApy)(baseData.symbol),
66
+ token: baseData.symbol,
67
+ incentiveKind: common_1.IncentiveKind.Staking,
68
+ description: `Native ${baseData.symbol} yield.`,
69
+ }),
70
+ ],
71
+ borrowIncentives: [Object.assign({ token: 'COMP', apy: (0, moneymarket_1.aprToApy)((100 * constants_1.SECONDS_PER_YEAR * +baseData.rewardBorrowSpeed * +compPrice) / +baseData.price / +baseData.totalBorrow).toString(), incentiveKind: common_1.IncentiveKind.Reward, description: 'Eligible for protocol-level COMP incentives.' }, (0, utils_1.addToArrayIf)(staking_1.STAKING_ASSETS.includes(baseData.symbol), {
72
+ apy: new decimal_js_1.default(yield (0, staking_1.getStakingApy)(baseData.symbol)).mul(-1).toString(),
73
+ token: baseData.symbol,
74
+ incentiveKind: common_1.IncentiveKind.Staking,
75
+ description: `Native ${baseData.symbol} yield.`,
76
+ }))],
77
+ });
69
78
  });
70
79
  exports.getIncentiveApys = getIncentiveApys;
71
80
  const getCompoundV2AggregatedData = (_a) => {
@@ -172,11 +172,11 @@ const calculateNetApy = ({ usedAssets, assetsData, }) => {
172
172
  if (eligibilityCheck) {
173
173
  const { isEligible, eligibleUSDAmount } = eligibilityCheck(usedAssets);
174
174
  const incentiveInterest = isEligible ? (0, exports.calculateInterestEarned)(eligibleUSDAmount, apy, 'year', true) : '0';
175
- acc.incentiveUsd = new decimal_js_1.default(acc.incentiveUsd).sub(incentiveInterest).toString();
175
+ acc.incentiveUsd = new decimal_js_1.default(acc.incentiveUsd).add(incentiveInterest).toString();
176
176
  }
177
177
  else {
178
178
  const incentiveInterest = (0, exports.calculateInterestEarned)(amount, apy, 'year', true);
179
- acc.incentiveUsd = new decimal_js_1.default(acc.incentiveUsd).sub(incentiveInterest).toString();
179
+ acc.incentiveUsd = new decimal_js_1.default(acc.incentiveUsd).add(incentiveInterest).toString();
180
180
  }
181
181
  }
182
182
  }
@@ -54,7 +54,7 @@ export const _getCompoundV3MarketsData = (provider, network, selectedMarket, def
54
54
  }
55
55
  const base = formatBaseData(baseTokenInfo, network, baseAssetPrice);
56
56
  const payload = {};
57
- const baseObj = Object.assign(Object.assign({}, base), getIncentiveApys(base, compPrice));
57
+ const baseObj = Object.assign(Object.assign({}, base), (yield getIncentiveApys(base, compPrice)));
58
58
  const allAssets = [baseObj, ...colls];
59
59
  allAssets
60
60
  .sort((a, b) => {
@@ -2,10 +2,10 @@ import { BaseAdditionalAssetData, CompoundAggregatedPositionData, CompoundMarket
2
2
  import { EthAddress, EthereumProvider, IncentiveData, NetworkNumber } from '../../types/common';
3
3
  export declare const formatMarketData: (data: any, network: NetworkNumber, baseAssetPrice: string) => CompoundV3AssetData;
4
4
  export declare const formatBaseData: (data: any, network: NetworkNumber, baseAssetPrice: string) => CompoundV3AssetData & BaseAdditionalAssetData;
5
- export declare const getIncentiveApys: (baseData: CompoundV3AssetData & BaseAdditionalAssetData, compPrice: string) => {
5
+ export declare const getIncentiveApys: (baseData: CompoundV3AssetData & BaseAdditionalAssetData, compPrice: string) => Promise<{
6
6
  supplyIncentives: IncentiveData[];
7
7
  borrowIncentives: IncentiveData[];
8
- };
8
+ }>;
9
9
  export declare const getCompoundV2AggregatedData: ({ usedAssets, assetsData, ...rest }: {
10
10
  usedAssets: CompoundV2UsedAssets;
11
11
  assetsData: CompoundV2AssetsData;
@@ -21,10 +21,10 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  import Dec from 'decimal.js';
22
22
  import { assetAmountInWei, getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
23
23
  import { CompoundVersions, } from '../../types';
24
- import { getEthAmountForDecimals, handleWbtcLegacy, wethToEth } from '../../services/utils';
24
+ import { addToArrayIf, getEthAmountForDecimals, handleWbtcLegacy, wethToEth, } from '../../services/utils';
25
25
  import { BLOCKS_IN_A_YEAR, borrowOperations, SECONDS_PER_YEAR } from '../../constants';
26
26
  import { aprToApy, calcLeverageLiqPrice, calculateBorrowingAssetLimit, getAssetsTotal, isLeveragedPos, } from '../../moneymarket';
27
- import { calculateNetApy } from '../../staking';
27
+ import { calculateNetApy, getStakingApy, STAKING_ASSETS } from '../../staking';
28
28
  import { IncentiveKind, NetworkNumber, } from '../../types/common';
29
29
  import { CompoundLoanInfoContractViem, CompV3ViewContractViem } from '../../contracts';
30
30
  import { getViemProvider } from '../../services/viem';
@@ -45,19 +45,28 @@ export const formatBaseData = (data, network, baseAssetPrice) => {
45
45
  totalSupply,
46
46
  totalBorrow, marketLiquidity: new Dec(totalSupply).minus(totalBorrow).toString(), symbol: wethToEth(assetInfo.symbol), priceInBaseAsset: getEthAmountForDecimals(data.price, 8), price: baseAssetPrice, collateralFactor: '0', liquidationRatio: '0', canBeBorrowed: true, canBeSupplied: true, supplyCap: '0', rewardSupplySpeed: getEthAmountForDecimals(data.baseTrackingSupplyRewardsSpeed, 15), rewardBorrowSpeed: getEthAmountForDecimals(data.baseTrackingBorrowRewardsSpeed, 15), minDebt: getEthAmountForDecimals(data.baseBorrowMin, assetInfo.decimals), isBase: true }));
47
47
  };
48
- export const getIncentiveApys = (baseData, compPrice) => ({
49
- supplyIncentives: [{
50
- token: 'COMP',
51
- apy: aprToApy((100 * SECONDS_PER_YEAR * +baseData.rewardSupplySpeed * +compPrice) / +baseData.price / +baseData.totalSupply).toString(),
52
- incentiveKind: IncentiveKind.Reward,
53
- description: 'Eligible for protocol-level COMP incentives.',
54
- }],
55
- borrowIncentives: [{
56
- token: 'COMP',
57
- apy: aprToApy((100 * SECONDS_PER_YEAR * +baseData.rewardBorrowSpeed * +compPrice) / +baseData.price / +baseData.totalBorrow).toString(),
58
- incentiveKind: IncentiveKind.Reward,
59
- description: 'Eligible for protocol-level COMP incentives.',
60
- }],
48
+ export const getIncentiveApys = (baseData, compPrice) => __awaiter(void 0, void 0, void 0, function* () {
49
+ return ({
50
+ supplyIncentives: [{
51
+ token: 'COMP',
52
+ apy: aprToApy((100 * SECONDS_PER_YEAR * +baseData.rewardSupplySpeed * +compPrice) / +baseData.price / +baseData.totalSupply).toString(),
53
+ incentiveKind: IncentiveKind.Reward,
54
+ description: 'Eligible for protocol-level COMP incentives.',
55
+ },
56
+ ...addToArrayIf(STAKING_ASSETS.includes(baseData.symbol), {
57
+ apy: yield getStakingApy(baseData.symbol),
58
+ token: baseData.symbol,
59
+ incentiveKind: IncentiveKind.Staking,
60
+ description: `Native ${baseData.symbol} yield.`,
61
+ }),
62
+ ],
63
+ borrowIncentives: [Object.assign({ token: 'COMP', apy: aprToApy((100 * SECONDS_PER_YEAR * +baseData.rewardBorrowSpeed * +compPrice) / +baseData.price / +baseData.totalBorrow).toString(), incentiveKind: IncentiveKind.Reward, description: 'Eligible for protocol-level COMP incentives.' }, addToArrayIf(STAKING_ASSETS.includes(baseData.symbol), {
64
+ apy: new Dec(yield getStakingApy(baseData.symbol)).mul(-1).toString(),
65
+ token: baseData.symbol,
66
+ incentiveKind: IncentiveKind.Staking,
67
+ description: `Native ${baseData.symbol} yield.`,
68
+ }))],
69
+ });
61
70
  });
62
71
  export const getCompoundV2AggregatedData = (_a) => {
63
72
  var { usedAssets, assetsData } = _a, rest = __rest(_a, ["usedAssets", "assetsData"]);
@@ -165,11 +165,11 @@ export const calculateNetApy = ({ usedAssets, assetsData, }) => {
165
165
  if (eligibilityCheck) {
166
166
  const { isEligible, eligibleUSDAmount } = eligibilityCheck(usedAssets);
167
167
  const incentiveInterest = isEligible ? calculateInterestEarned(eligibleUSDAmount, apy, 'year', true) : '0';
168
- acc.incentiveUsd = new Dec(acc.incentiveUsd).sub(incentiveInterest).toString();
168
+ acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
169
169
  }
170
170
  else {
171
171
  const incentiveInterest = calculateInterestEarned(amount, apy, 'year', true);
172
- acc.incentiveUsd = new Dec(acc.incentiveUsd).sub(incentiveInterest).toString();
172
+ acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
173
173
  }
174
174
  }
175
175
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/positions-sdk",
3
- "version": "2.0.15-dev-2",
3
+ "version": "2.0.15-dev-4",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -70,7 +70,7 @@ export const _getCompoundV3MarketsData = async (provider: Client, network: Netwo
70
70
 
71
71
  const payload: CompoundV3AssetsData = {};
72
72
 
73
- const baseObj = { ...base, ...getIncentiveApys(base, compPrice) };
73
+ const baseObj = { ...base, ...(await getIncentiveApys(base, compPrice)) };
74
74
  const allAssets = [baseObj, ...colls];
75
75
 
76
76
  allAssets
@@ -3,12 +3,14 @@ import { assetAmountInWei, getAssetInfo, getAssetInfoByAddress } from '@defisave
3
3
  import {
4
4
  BaseAdditionalAssetData, CompoundAggregatedPositionData, CompoundMarketData, CompoundV2AssetsData, CompoundV2UsedAssets, CompoundV3AssetData, CompoundV3AssetsData, CompoundV3UsedAssets, CompoundVersions,
5
5
  } from '../../types';
6
- import { getEthAmountForDecimals, handleWbtcLegacy, wethToEth } from '../../services/utils';
6
+ import {
7
+ addToArrayIf, getEthAmountForDecimals, handleWbtcLegacy, wethToEth,
8
+ } from '../../services/utils';
7
9
  import { BLOCKS_IN_A_YEAR, borrowOperations, SECONDS_PER_YEAR } from '../../constants';
8
10
  import {
9
11
  aprToApy, calcLeverageLiqPrice, calculateBorrowingAssetLimit, getAssetsTotal, isLeveragedPos,
10
12
  } from '../../moneymarket';
11
- import { calculateNetApy } from '../../staking';
13
+ import { calculateNetApy, getStakingApy, STAKING_ASSETS } from '../../staking';
12
14
  import {
13
15
  EthAddress, EthereumProvider, IncentiveData, IncentiveKind, NetworkNumber,
14
16
  } from '../../types/common';
@@ -78,24 +80,37 @@ export const formatBaseData = (data: any, network: NetworkNumber, baseAssetPrice
78
80
  });
79
81
  };
80
82
 
81
- export const getIncentiveApys = (
83
+ export const getIncentiveApys = async (
82
84
  baseData: CompoundV3AssetData & BaseAdditionalAssetData,
83
85
  compPrice: string,
84
- ): {
86
+ ): Promise<{
85
87
  supplyIncentives: IncentiveData[],
86
88
  borrowIncentives: IncentiveData[],
87
- } => ({
89
+ }> => ({
88
90
  supplyIncentives: [{
89
91
  token: 'COMP',
90
92
  apy: aprToApy((100 * SECONDS_PER_YEAR * +baseData.rewardSupplySpeed * +compPrice) / +baseData.price / +baseData.totalSupply).toString(),
91
93
  incentiveKind: IncentiveKind.Reward,
92
94
  description: 'Eligible for protocol-level COMP incentives.',
93
- }],
95
+ },
96
+ ...addToArrayIf(STAKING_ASSETS.includes(baseData.symbol), {
97
+ apy: await getStakingApy(baseData.symbol),
98
+ token: baseData.symbol,
99
+ incentiveKind: IncentiveKind.Staking,
100
+ description: `Native ${baseData.symbol} yield.`,
101
+ }),
102
+ ],
94
103
  borrowIncentives: [{
95
104
  token: 'COMP',
96
105
  apy: aprToApy((100 * SECONDS_PER_YEAR * +baseData.rewardBorrowSpeed * +compPrice) / +baseData.price / +baseData.totalBorrow).toString(),
97
106
  incentiveKind: IncentiveKind.Reward,
98
107
  description: 'Eligible for protocol-level COMP incentives.',
108
+ ...addToArrayIf(STAKING_ASSETS.includes(baseData.symbol), {
109
+ apy: new Dec(await getStakingApy(baseData.symbol)).mul(-1).toString(),
110
+ token: baseData.symbol,
111
+ incentiveKind: IncentiveKind.Staking,
112
+ description: `Native ${baseData.symbol} yield.`,
113
+ }),
99
114
  }],
100
115
  });
101
116
 
@@ -145,10 +145,10 @@ export const calculateNetApy = ({
145
145
  if (eligibilityCheck) {
146
146
  const { isEligible, eligibleUSDAmount } = eligibilityCheck(usedAssets);
147
147
  const incentiveInterest = isEligible ? calculateInterestEarned(eligibleUSDAmount, apy, 'year', true) : '0';
148
- acc.incentiveUsd = new Dec(acc.incentiveUsd).sub(incentiveInterest).toString();
148
+ acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
149
149
  } else {
150
150
  const incentiveInterest = calculateInterestEarned(amount, apy, 'year', true);
151
- acc.incentiveUsd = new Dec(acc.incentiveUsd).sub(incentiveInterest).toString();
151
+ acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
152
152
  }
153
153
  }
154
154
  }