@defisaver/positions-sdk 0.0.166 → 0.0.168
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/.vscode/launch.json +17 -0
- package/.vscode/settings.json +22 -0
- package/cjs/aaveV2/index.js +1 -1
- package/cjs/aaveV3/index.js +71 -41
- package/cjs/compoundV2/index.js +10 -10
- package/cjs/morphoAaveV2/index.js +1 -1
- package/cjs/spark/index.js +63 -29
- package/cjs/staking/staking.d.ts +4 -4
- package/cjs/staking/staking.js +19 -16
- package/cjs/types/aave.d.ts +6 -0
- package/cjs/types/spark.d.ts +3 -0
- package/esm/aaveV2/index.js +2 -2
- package/esm/aaveV3/index.js +71 -41
- package/esm/compoundV2/index.js +1 -1
- package/esm/morphoAaveV2/index.js +2 -2
- package/esm/spark/index.js +63 -29
- package/esm/staking/staking.d.ts +4 -4
- package/esm/staking/staking.js +15 -12
- package/esm/types/aave.d.ts +6 -0
- package/esm/types/spark.d.ts +3 -0
- package/package.json +1 -1
- package/src/aaveV2/index.ts +2 -2
- package/src/aaveV3/index.ts +69 -35
- package/src/compoundV2/index.ts +2 -2
- package/src/morphoAaveV2/index.ts +2 -2
- package/src/spark/index.ts +64 -27
- package/src/staking/staking.ts +15 -13
- package/src/types/aave.ts +7 -0
- package/src/types/spark.ts +4 -1
package/esm/aaveV3/index.js
CHANGED
|
@@ -175,6 +175,7 @@ export function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
175
175
|
},
|
|
176
176
|
})), { symbol, isIsolated: new Dec(tokenMarket.debtCeilingForIsolationMode).gt(0), debtCeilingForIsolationMode: new Dec(tokenMarket.debtCeilingForIsolationMode).div(100).toString(), isSiloed: tokenMarket.isSiloedForBorrowing, isolationModeTotalDebt: new Dec(tokenMarket.isolationModeTotalDebt).div(100).toString(), assetId: Number(tokenMarket.assetId), underlyingTokenAddress: tokenMarket.underlyingTokenAddress, supplyRate: aprToApy(new Dec(tokenMarket.supplyRate.toString()).div(1e25).toString()), borrowRate: aprToApy(new Dec(tokenMarket.borrowRateVariable.toString()).div(1e25).toString()), borrowRateDiscounted: aprToApy(nativeAsset ? new Dec(tokenMarket.borrowRateVariable.toString()).div(1e25).mul(1 - parseFloat(discountRateOnBorrow)).toString() : '0'), borrowRateStable: aprToApy(new Dec(tokenMarket.borrowRateStable.toString()).div(1e25).toString()), collateralFactor: new Dec(tokenMarket.collateralFactor.toString()).div(10000).toString(), liquidationRatio: new Dec(tokenMarket.liquidationRatio.toString()).div(10000).toString(), marketLiquidity, utilization: new Dec(tokenMarket.totalBorrow.toString()).times(100).div(new Dec(tokenMarket.totalSupply.toString())).toString(), usageAsCollateralEnabled: tokenMarket.usageAsCollateralEnabled, supplyCap: tokenMarket.supplyCap, borrowCap, totalSupply: assetAmountInEth(tokenMarket.totalSupply.toString(), symbol), isInactive: !tokenMarket.isActive, isFrozen: tokenMarket.isFrozen, isPaused: tokenMarket.isPaused, canBeBorrowed: tokenMarket.isActive && !tokenMarket.isPaused && !tokenMarket.isFrozen && tokenMarket.borrowingEnabled && isBorrowAllowed, canBeSupplied: !nativeAsset && tokenMarket.isActive && !tokenMarket.isPaused && !tokenMarket.isFrozen, canBeWithdrawn: tokenMarket.isActive && !tokenMarket.isPaused, canBePayBacked: tokenMarket.isActive && !tokenMarket.isPaused, disabledStableBorrowing: !tokenMarket.stableBorrowRateEnabled, totalBorrow: assetAmountInEth(tokenMarket.totalBorrow.toString(), symbol), totalBorrowVar: assetAmountInEth(tokenMarket.totalBorrowVar.toString(), symbol), price: new Dec(tokenMarket.price.toString()).div(1e8).toString(), isolationModeBorrowingEnabled: tokenMarket.isolationModeBorrowingEnabled, isFlashLoanEnabled: tokenMarket.isFlashLoanEnabled, aTokenAddress: tokenMarket.aTokenAddress }));
|
|
177
177
|
})));
|
|
178
|
+
// Get incentives data
|
|
178
179
|
yield Promise.all(assetsData.map((_market) => __awaiter(this, void 0, void 0, function* () {
|
|
179
180
|
/* eslint-disable no-param-reassign */
|
|
180
181
|
const rewardForMarket = rewardInfo === null || rewardInfo === void 0 ? void 0 : rewardInfo[_market.underlyingTokenAddress];
|
|
@@ -182,53 +183,82 @@ export function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
182
183
|
if (isStakingAsset) {
|
|
183
184
|
_market.incentiveSupplyApy = yield getStakingApy(_market.symbol, defaultWeb3);
|
|
184
185
|
_market.incentiveSupplyToken = _market.symbol;
|
|
186
|
+
if (!_market.supplyIncentives) {
|
|
187
|
+
_market.supplyIncentives = [];
|
|
188
|
+
}
|
|
189
|
+
_market.supplyIncentives.push({
|
|
190
|
+
apy: _market.incentiveSupplyApy || '0',
|
|
191
|
+
token: _market.symbol,
|
|
192
|
+
});
|
|
185
193
|
}
|
|
186
194
|
if (_market.canBeBorrowed && _market.incentiveSupplyApy) {
|
|
187
|
-
_market.incentiveBorrowApy =
|
|
195
|
+
_market.incentiveBorrowApy = _market.incentiveSupplyApy;
|
|
188
196
|
_market.incentiveBorrowToken = _market.incentiveSupplyToken;
|
|
197
|
+
if (!_market.borrowIncentives) {
|
|
198
|
+
_market.borrowIncentives = [];
|
|
199
|
+
}
|
|
200
|
+
_market.borrowIncentives.push({
|
|
201
|
+
apy: _market.incentiveBorrowApy,
|
|
202
|
+
token: _market.incentiveBorrowToken,
|
|
203
|
+
});
|
|
189
204
|
}
|
|
190
205
|
if (!rewardForMarket)
|
|
191
206
|
return;
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
.
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
.
|
|
225
|
-
.
|
|
226
|
-
|
|
227
|
-
.
|
|
228
|
-
.
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
207
|
+
rewardForMarket.aIncentiveData.rewardsTokenInformation.forEach(supplyRewardData => {
|
|
208
|
+
if (supplyRewardData) {
|
|
209
|
+
if (+supplyRewardData.emissionEndTimestamp * 1000 < Date.now())
|
|
210
|
+
return;
|
|
211
|
+
_market.incentiveSupplyToken = supplyRewardData.rewardTokenSymbol;
|
|
212
|
+
// reward token is aave asset
|
|
213
|
+
if (supplyRewardData.rewardTokenSymbol.startsWith('a') && supplyRewardData.rewardTokenSymbol.includes(_market.symbol))
|
|
214
|
+
_market.incentiveSupplyToken = _market.symbol;
|
|
215
|
+
const supplyEmissionPerSecond = supplyRewardData.emissionPerSecond;
|
|
216
|
+
const supplyRewardPrice = new Dec(supplyRewardData.rewardPriceFeed).div(Math.pow(10, +supplyRewardData.priceFeedDecimals))
|
|
217
|
+
.toString();
|
|
218
|
+
const rewardApy = new Dec(supplyEmissionPerSecond).div((Math.pow(10, +supplyRewardData.rewardTokenDecimals)) / 100)
|
|
219
|
+
.mul(365 * 24 * 3600)
|
|
220
|
+
.mul(supplyRewardPrice)
|
|
221
|
+
.div(_market.price)
|
|
222
|
+
.div(_market.totalSupply)
|
|
223
|
+
.toString();
|
|
224
|
+
_market.incentiveSupplyApy = new Dec(_market.incentiveSupplyApy || '0').add(rewardApy)
|
|
225
|
+
.toString();
|
|
226
|
+
if (!_market.supplyIncentives) {
|
|
227
|
+
_market.supplyIncentives = [];
|
|
228
|
+
}
|
|
229
|
+
_market.supplyIncentives.push({
|
|
230
|
+
token: supplyRewardData.rewardTokenSymbol,
|
|
231
|
+
apy: rewardApy,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
rewardForMarket.vIncentiveData.rewardsTokenInformation.forEach(borrowRewardData => {
|
|
236
|
+
if (borrowRewardData) {
|
|
237
|
+
if (+borrowRewardData.emissionEndTimestamp * 1000 < Date.now())
|
|
238
|
+
return;
|
|
239
|
+
_market.incentiveBorrowToken = borrowRewardData.rewardTokenSymbol;
|
|
240
|
+
if (borrowRewardData.rewardTokenSymbol.startsWith('a') && borrowRewardData.rewardTokenSymbol.includes(_market.symbol))
|
|
241
|
+
_market.incentiveBorrowToken = _market.symbol;
|
|
242
|
+
const supplyEmissionPerSecond = borrowRewardData.emissionPerSecond;
|
|
243
|
+
const supplyRewardPrice = new Dec(borrowRewardData.rewardPriceFeed).div(Math.pow(10, +borrowRewardData.priceFeedDecimals))
|
|
244
|
+
.toString();
|
|
245
|
+
const rewardApy = new Dec(supplyEmissionPerSecond).div((Math.pow(10, +borrowRewardData.rewardTokenDecimals)) / 100)
|
|
246
|
+
.mul(365 * 24 * 3600)
|
|
247
|
+
.mul(supplyRewardPrice)
|
|
248
|
+
.div(_market.price)
|
|
249
|
+
.div(_market.totalBorrowVar)
|
|
250
|
+
.toString();
|
|
251
|
+
_market.incentiveBorrowApy = new Dec(_market.incentiveBorrowApy || '0').add(rewardApy)
|
|
252
|
+
.toString();
|
|
253
|
+
if (!_market.borrowIncentives) {
|
|
254
|
+
_market.borrowIncentives = [];
|
|
255
|
+
}
|
|
256
|
+
_market.borrowIncentives.push({
|
|
257
|
+
token: borrowRewardData.rewardTokenSymbol,
|
|
258
|
+
apy: rewardApy,
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
});
|
|
232
262
|
})));
|
|
233
263
|
const payload = {};
|
|
234
264
|
// Sort by market size
|
package/esm/compoundV2/index.js
CHANGED
|
@@ -13,7 +13,7 @@ import { BLOCKS_IN_A_YEAR } from '../constants';
|
|
|
13
13
|
import { aprToApy } from '../moneymarket';
|
|
14
14
|
import { compareAddresses, handleWbtcLegacy, wethToEth } from '../services/utils';
|
|
15
15
|
import { CompoundLoanInfoContract, ComptrollerContract } from '../contracts';
|
|
16
|
-
import { compoundV2CollateralAssets } from '../markets
|
|
16
|
+
import { compoundV2CollateralAssets } from '../markets';
|
|
17
17
|
import { getCompoundV2AggregatedData } from '../helpers/compoundHelpers';
|
|
18
18
|
const compAddress = '0xc00e94cb662c3520282e6f5717214004a7f26888';
|
|
19
19
|
export const getCompoundV2MarketsData = (web3, network) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
11
11
|
import Dec from 'decimal.js';
|
|
12
12
|
import { wethToEthByAddress } from '../services/utils';
|
|
13
|
-
import {
|
|
13
|
+
import { getStETHApy } from '../staking';
|
|
14
14
|
import { MorphoAaveV2ViewContract } from '../contracts';
|
|
15
15
|
import { AaveVersions, } from '../types';
|
|
16
16
|
import { aprToApy, calculateBorrowingAssetLimit } from '../moneymarket';
|
|
@@ -87,7 +87,7 @@ export const getMorphoAaveV2MarketsData = (web3, network, mainnetWeb3) => __awai
|
|
|
87
87
|
});
|
|
88
88
|
const stEthMarket = assetsData.find(({ symbol }) => symbol === 'stETH');
|
|
89
89
|
if (stEthMarket) {
|
|
90
|
-
stEthMarket.incentiveSupplyApy = yield
|
|
90
|
+
stEthMarket.incentiveSupplyApy = yield getStETHApy(mainnetWeb3);
|
|
91
91
|
stEthMarket.incentiveSupplyToken = 'stETH';
|
|
92
92
|
}
|
|
93
93
|
const payload = {};
|
package/esm/spark/index.js
CHANGED
|
@@ -122,45 +122,79 @@ export const getSparkMarketsData = (web3, network, selectedMarket, mainnetWeb3)
|
|
|
122
122
|
if (STAKING_ASSETS.includes(market.symbol)) {
|
|
123
123
|
market.incentiveSupplyApy = yield getStakingApy(market.symbol, mainnetWeb3);
|
|
124
124
|
market.incentiveSupplyToken = market.symbol;
|
|
125
|
+
if (!market.supplyIncentives) {
|
|
126
|
+
market.supplyIncentives = [];
|
|
127
|
+
}
|
|
128
|
+
market.supplyIncentives.push({
|
|
129
|
+
apy: market.incentiveSupplyApy || '0',
|
|
130
|
+
token: market.symbol,
|
|
131
|
+
});
|
|
125
132
|
}
|
|
126
133
|
if (market.symbol === 'sDAI') {
|
|
127
134
|
market.incentiveSupplyApy = yield getDsrApy(web3, network);
|
|
128
135
|
market.incentiveSupplyToken = 'sDAI';
|
|
129
136
|
}
|
|
130
137
|
if (market.canBeBorrowed && market.incentiveSupplyApy) {
|
|
131
|
-
market.incentiveBorrowApy =
|
|
138
|
+
market.incentiveBorrowApy = market.incentiveSupplyApy;
|
|
132
139
|
market.incentiveBorrowToken = market.incentiveSupplyToken;
|
|
140
|
+
if (!market.borrowIncentives) {
|
|
141
|
+
market.borrowIncentives = [];
|
|
142
|
+
}
|
|
143
|
+
market.borrowIncentives.push({
|
|
144
|
+
apy: market.incentiveBorrowApy,
|
|
145
|
+
token: market.incentiveBorrowToken,
|
|
146
|
+
});
|
|
133
147
|
}
|
|
134
148
|
if (!rewardForMarket)
|
|
135
149
|
return;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
.
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
.
|
|
163
|
-
|
|
150
|
+
rewardForMarket.aIncentiveData.rewardsTokenInformation.forEach(supplyRewardData => {
|
|
151
|
+
if (supplyRewardData) {
|
|
152
|
+
if (supplyRewardData.emissionEndTimestamp * 1000 < Date.now())
|
|
153
|
+
return;
|
|
154
|
+
market.incentiveSupplyToken = supplyRewardData.rewardTokenSymbol;
|
|
155
|
+
const supplyEmissionPerSecond = supplyRewardData.emissionPerSecond;
|
|
156
|
+
const supplyRewardPrice = new Dec(supplyRewardData.rewardPriceFeed).div(Math.pow(10, supplyRewardData.priceFeedDecimals))
|
|
157
|
+
.toString();
|
|
158
|
+
const rewardApy = new Dec(supplyEmissionPerSecond).div((Math.pow(10, supplyRewardData.rewardTokenDecimals)) / 100)
|
|
159
|
+
.mul(365 * 24 * 3600)
|
|
160
|
+
.mul(supplyRewardPrice)
|
|
161
|
+
.div(market.price)
|
|
162
|
+
.div(market.totalSupply)
|
|
163
|
+
.toString();
|
|
164
|
+
market.incentiveSupplyApy = new Dec(market.incentiveSupplyApy || '0').add(rewardApy).toString();
|
|
165
|
+
if (!market.supplyIncentives) {
|
|
166
|
+
market.supplyIncentives = [];
|
|
167
|
+
}
|
|
168
|
+
market.supplyIncentives.push({
|
|
169
|
+
token: supplyRewardData.rewardTokenSymbol,
|
|
170
|
+
apy: rewardApy,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
rewardForMarket.vIncentiveData.rewardsTokenInformation.forEach(borrowRewardData => {
|
|
175
|
+
if (borrowRewardData) {
|
|
176
|
+
if (borrowRewardData.emissionEndTimestamp * 1000 < Date.now())
|
|
177
|
+
return;
|
|
178
|
+
market.incentiveBorrowToken = borrowRewardData.rewardTokenSymbol;
|
|
179
|
+
const supplyEmissionPerSecond = borrowRewardData.emissionPerSecond;
|
|
180
|
+
const supplyRewardPrice = new Dec(borrowRewardData.rewardPriceFeed).div(Math.pow(10, borrowRewardData.priceFeedDecimals))
|
|
181
|
+
.toString();
|
|
182
|
+
const rewardApy = new Dec(supplyEmissionPerSecond).div((Math.pow(10, borrowRewardData.rewardTokenDecimals)) / 100)
|
|
183
|
+
.mul(365 * 24 * 3600)
|
|
184
|
+
.mul(supplyRewardPrice)
|
|
185
|
+
.div(market.price)
|
|
186
|
+
.div(market.totalBorrowVar)
|
|
187
|
+
.toString();
|
|
188
|
+
market.incentiveBorrowApy = new Dec(market.incentiveBorrowApy || '0').add(rewardApy).toString();
|
|
189
|
+
if (!market.borrowIncentives) {
|
|
190
|
+
market.borrowIncentives = [];
|
|
191
|
+
}
|
|
192
|
+
market.borrowIncentives.push({
|
|
193
|
+
token: borrowRewardData.rewardTokenSymbol,
|
|
194
|
+
apy: rewardApy,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
});
|
|
164
198
|
/* eslint-enable no-param-reassign */
|
|
165
199
|
})));
|
|
166
200
|
const payload = {};
|
package/esm/staking/staking.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import Web3 from 'web3';
|
|
2
2
|
import { MMAssetsData, MMUsedAssets } from '../types/common';
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
3
|
+
export declare const getStETHApy: (web3: Web3, fromBlock?: number, blockNumber?: 'latest' | number) => Promise<string>;
|
|
4
|
+
export declare const getCbETHApy: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
|
|
5
|
+
export declare const getREthApy: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
|
|
6
6
|
export declare const getDsrApy: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
|
|
7
7
|
export declare const getSsrApy: () => Promise<string>;
|
|
8
8
|
export declare const STAKING_ASSETS: string[];
|
|
9
|
-
export declare const getStakingApy: (asset: string, web3: Web3, blockNumber?: 'latest' | number, fromBlock?: number | undefined) => Promise<any> |
|
|
9
|
+
export declare const getStakingApy: (asset: string, web3: Web3, blockNumber?: 'latest' | number, fromBlock?: number | undefined) => "0" | Promise<any> | undefined;
|
|
10
10
|
export declare const calculateInterestEarned: (principal: string, interest: string, type: string, apy?: boolean) => number;
|
|
11
11
|
export declare const calculateNetApy: (usedAssets: MMUsedAssets, assetsData: MMAssetsData, isMorpho?: boolean) => {
|
|
12
12
|
netApy: string;
|
package/esm/staking/staking.js
CHANGED
|
@@ -12,7 +12,8 @@ import { CbEthContract, LidoContract, PotContract, REthContract, wstETHContract,
|
|
|
12
12
|
import { NetworkNumber } from '../types/common';
|
|
13
13
|
import { BLOCKS_IN_A_YEAR, SECONDS_PER_YEAR, AVG_BLOCK_TIME } from '../constants';
|
|
14
14
|
import { multicall } from '../multicall';
|
|
15
|
-
|
|
15
|
+
import { aprToApy } from '../moneymarket';
|
|
16
|
+
export const getStETHApy = (web3, fromBlock = 17900000, blockNumber = 'latest') => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
17
|
try {
|
|
17
18
|
const tokenRebasedEvents = yield LidoContract(web3, NetworkNumber.Eth).getPastEvents('TokenRebased', { fromBlock, toBlock: blockNumber });
|
|
18
19
|
tokenRebasedEvents.sort((a, b) => b.blockNumber - a.blockNumber); // sort from highest to lowest block number
|
|
@@ -24,16 +25,16 @@ export const getStETHApr = (web3, fromBlock = 17900000, blockNumber = 'latest')
|
|
|
24
25
|
.div(event.timeElapsed.toString()).mul(100)
|
|
25
26
|
.toNumber();
|
|
26
27
|
});
|
|
27
|
-
return aprs.reduce((a, b) => a + b, 0) / aprs.length;
|
|
28
|
+
return aprToApy(aprs.reduce((a, b) => a + b, 0) / aprs.length);
|
|
28
29
|
}
|
|
29
30
|
catch (e) {
|
|
30
31
|
console.warn('Failed to fetch stETH APY from events, falling back to Lido API');
|
|
31
32
|
const res = yield fetch('https://eth-api.lido.fi/v1/protocol/steth/apr/sma');
|
|
32
33
|
const data = yield res.json();
|
|
33
|
-
return data.data.smaApr;
|
|
34
|
+
return aprToApy(data.data.smaApr);
|
|
34
35
|
}
|
|
35
36
|
});
|
|
36
|
-
export const
|
|
37
|
+
export const getCbETHApy = (web3, blockNumber = 'latest') => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
38
|
let currentBlock = blockNumber;
|
|
38
39
|
if (blockNumber === 'latest')
|
|
39
40
|
currentBlock = yield web3.eth.getBlockNumber();
|
|
@@ -48,9 +49,9 @@ export const getCbETHApr = (web3, blockNumber = 'latest') => __awaiter(void 0, v
|
|
|
48
49
|
.mul(BLOCKS_IN_A_YEAR / blockDiff)
|
|
49
50
|
.mul(100)
|
|
50
51
|
.toString();
|
|
51
|
-
return apr;
|
|
52
|
+
return aprToApy(apr);
|
|
52
53
|
});
|
|
53
|
-
export const
|
|
54
|
+
export const getREthApy = (web3, blockNumber = 'latest') => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
55
|
let currentBlock = blockNumber;
|
|
55
56
|
if (blockNumber === 'latest')
|
|
56
57
|
currentBlock = yield web3.eth.getBlockNumber();
|
|
@@ -65,7 +66,7 @@ export const getREthApr = (web3, blockNumber = 'latest') => __awaiter(void 0, vo
|
|
|
65
66
|
.mul(BLOCKS_IN_A_YEAR / blockDiff)
|
|
66
67
|
.mul(100)
|
|
67
68
|
.toString();
|
|
68
|
-
return apr;
|
|
69
|
+
return aprToApy(apr);
|
|
69
70
|
});
|
|
70
71
|
export const getDsrApy = (web3, blockNumber = 'latest') => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
72
|
const potContract = PotContract(web3, NetworkNumber.Eth);
|
|
@@ -82,7 +83,6 @@ export const getSsrApy = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
82
83
|
return new Dec(data.data.skyData[0].sky_savings_rate_apy).mul(100).toString();
|
|
83
84
|
});
|
|
84
85
|
const getSuperOETHApy = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
85
|
-
console.log('getSuperOETHApy');
|
|
86
86
|
const res = yield fetch('https://origin.squids.live/origin-squid/graphql', {
|
|
87
87
|
method: 'POST',
|
|
88
88
|
headers: {
|
|
@@ -102,18 +102,21 @@ const getSuperOETHApy = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
102
102
|
const getApyFromDfsApi = (asset) => __awaiter(void 0, void 0, void 0, function* () {
|
|
103
103
|
const res = yield fetch(`https://app.defisaver.com/api/staking/apy?asset=${asset}`);
|
|
104
104
|
const data = yield res.json();
|
|
105
|
+
// if our server returns apr, transform it into apy
|
|
106
|
+
if (['weETH'].includes(asset)) {
|
|
107
|
+
return aprToApy(data.apy);
|
|
108
|
+
}
|
|
105
109
|
return data.apy;
|
|
106
110
|
});
|
|
107
111
|
export const STAKING_ASSETS = ['cbETH', 'wstETH', 'cbETH', 'rETH', 'sDAI', 'weETH', 'sUSDe', 'osETH', 'ezETH', 'ETHx', 'rsETH', 'pufETH', 'wrsETH', 'wsuperOETHb', 'sUSDS'];
|
|
108
112
|
export const getStakingApy = (asset, web3, blockNumber = 'latest', fromBlock = undefined) => {
|
|
109
|
-
console.log('getStakingApy', asset, blockNumber, fromBlock);
|
|
110
113
|
try {
|
|
111
114
|
if (asset === 'stETH' || asset === 'wstETH')
|
|
112
|
-
return
|
|
115
|
+
return getStETHApy(web3, fromBlock, blockNumber);
|
|
113
116
|
if (asset === 'cbETH')
|
|
114
|
-
return
|
|
117
|
+
return getCbETHApy(web3, blockNumber);
|
|
115
118
|
if (asset === 'rETH')
|
|
116
|
-
return
|
|
119
|
+
return getREthApy(web3, blockNumber);
|
|
117
120
|
if (asset === 'sDAI')
|
|
118
121
|
return getDsrApy(web3);
|
|
119
122
|
if (asset === 'sUSDe')
|
package/esm/types/aave.d.ts
CHANGED
|
@@ -73,6 +73,10 @@ export interface AaveV2AssetData extends AaveAssetData {
|
|
|
73
73
|
}
|
|
74
74
|
export interface MorphoAaveV2AssetData extends AaveV2AssetData {
|
|
75
75
|
}
|
|
76
|
+
export interface IncentiveData {
|
|
77
|
+
token: string;
|
|
78
|
+
apy: string;
|
|
79
|
+
}
|
|
76
80
|
export interface AaveV3AssetData extends AaveAssetData {
|
|
77
81
|
isIsolated: boolean;
|
|
78
82
|
isSiloed: boolean;
|
|
@@ -88,6 +92,8 @@ export interface AaveV3AssetData extends AaveAssetData {
|
|
|
88
92
|
isPaused: boolean;
|
|
89
93
|
isFlashLoanEnabled: boolean;
|
|
90
94
|
assetId: string | null;
|
|
95
|
+
supplyIncentives?: IncentiveData[];
|
|
96
|
+
borrowIncentives?: IncentiveData[];
|
|
91
97
|
}
|
|
92
98
|
export type EModeCategoriesData = Record<number, EModeCategoryData>;
|
|
93
99
|
export interface MorphoAaveV3AssetData extends Omit<AaveV3AssetData, 'nativeAsset' | 'discountData' | 'borrowRateDiscounted'> {
|
package/esm/types/spark.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MMAssetData, MMPositionData, MMUsedAsset, NetworkNumber } from './common';
|
|
2
|
+
import { IncentiveData } from './aave';
|
|
2
3
|
export declare enum SparkVersions {
|
|
3
4
|
SparkV1 = "v1default"
|
|
4
5
|
}
|
|
@@ -47,6 +48,8 @@ export interface SparkAssetData extends MMAssetData {
|
|
|
47
48
|
eModeCategory: number;
|
|
48
49
|
eModeCategoryData: SparkEModeCategoryData;
|
|
49
50
|
liquidationRatio: string;
|
|
51
|
+
supplyIncentives?: IncentiveData[];
|
|
52
|
+
borrowIncentives?: IncentiveData[];
|
|
50
53
|
}
|
|
51
54
|
export interface SparkAssetsData {
|
|
52
55
|
[token: string]: SparkAssetData;
|
package/package.json
CHANGED
package/src/aaveV2/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
|
|
|
4
4
|
import {
|
|
5
5
|
Blockish, EthAddress, NetworkNumber, PositionBalances,
|
|
6
6
|
} from '../types/common';
|
|
7
|
-
import { calculateNetApy,
|
|
7
|
+
import { calculateNetApy, getStETHApy } from '../staking';
|
|
8
8
|
import { ethToWeth, wethToEth, wethToEthByAddress } from '../services/utils';
|
|
9
9
|
import { AaveLoanInfoV2Contract, createContractWrapper } from '../contracts';
|
|
10
10
|
import { aprToApy, calculateBorrowingAssetLimit } from '../moneymarket';
|
|
@@ -60,7 +60,7 @@ export const getAaveV2MarketsData = async (web3: Web3, network: NetworkNumber, s
|
|
|
60
60
|
|
|
61
61
|
const stEthMarket = markets.find(({ symbol }) => symbol === 'stETH');
|
|
62
62
|
if (stEthMarket) {
|
|
63
|
-
stEthMarket.incentiveSupplyApy = await
|
|
63
|
+
stEthMarket.incentiveSupplyApy = await getStETHApy(mainnetWeb3);
|
|
64
64
|
stEthMarket.incentiveSupplyToken = 'stETH';
|
|
65
65
|
}
|
|
66
66
|
|
package/src/aaveV3/index.ts
CHANGED
|
@@ -276,6 +276,7 @@ export async function getAaveV3MarketData(web3: Web3, network: NetworkNumber, ma
|
|
|
276
276
|
}));
|
|
277
277
|
|
|
278
278
|
|
|
279
|
+
// Get incentives data
|
|
279
280
|
await Promise.all(assetsData.map(async (_market: AaveV3AssetData) => {
|
|
280
281
|
/* eslint-disable no-param-reassign */
|
|
281
282
|
const rewardForMarket: IUiIncentiveDataProviderV3.AggregatedReserveIncentiveDataStructOutput | undefined = rewardInfo?.[_market.underlyingTokenAddress as any];
|
|
@@ -283,48 +284,81 @@ export async function getAaveV3MarketData(web3: Web3, network: NetworkNumber, ma
|
|
|
283
284
|
if (isStakingAsset) {
|
|
284
285
|
_market.incentiveSupplyApy = await getStakingApy(_market.symbol, defaultWeb3);
|
|
285
286
|
_market.incentiveSupplyToken = _market.symbol;
|
|
287
|
+
if (!_market.supplyIncentives) {
|
|
288
|
+
_market.supplyIncentives = [];
|
|
289
|
+
}
|
|
290
|
+
_market.supplyIncentives.push({
|
|
291
|
+
apy: _market.incentiveSupplyApy || '0',
|
|
292
|
+
token: _market.symbol,
|
|
293
|
+
});
|
|
286
294
|
}
|
|
287
295
|
|
|
288
296
|
if (_market.canBeBorrowed && _market.incentiveSupplyApy) {
|
|
289
|
-
_market.incentiveBorrowApy =
|
|
297
|
+
_market.incentiveBorrowApy = _market.incentiveSupplyApy;
|
|
290
298
|
_market.incentiveBorrowToken = _market.incentiveSupplyToken;
|
|
299
|
+
if (!_market.borrowIncentives) {
|
|
300
|
+
_market.borrowIncentives = [];
|
|
301
|
+
}
|
|
302
|
+
_market.borrowIncentives.push({
|
|
303
|
+
apy: _market.incentiveBorrowApy,
|
|
304
|
+
token: _market.incentiveBorrowToken!!,
|
|
305
|
+
});
|
|
291
306
|
}
|
|
292
307
|
|
|
293
308
|
if (!rewardForMarket) return;
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
.
|
|
324
|
-
.
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
309
|
+
rewardForMarket.aIncentiveData.rewardsTokenInformation.forEach(supplyRewardData => {
|
|
310
|
+
if (supplyRewardData) {
|
|
311
|
+
if (+supplyRewardData.emissionEndTimestamp * 1000 < Date.now()) return;
|
|
312
|
+
_market.incentiveSupplyToken = supplyRewardData.rewardTokenSymbol;
|
|
313
|
+
// reward token is aave asset
|
|
314
|
+
if (supplyRewardData.rewardTokenSymbol.startsWith('a') && supplyRewardData.rewardTokenSymbol.includes(_market.symbol)) _market.incentiveSupplyToken = _market.symbol;
|
|
315
|
+
const supplyEmissionPerSecond = supplyRewardData.emissionPerSecond;
|
|
316
|
+
const supplyRewardPrice = new Dec(supplyRewardData.rewardPriceFeed).div(10 ** +supplyRewardData.priceFeedDecimals)
|
|
317
|
+
.toString();
|
|
318
|
+
const rewardApy = new Dec(supplyEmissionPerSecond).div((10 ** +supplyRewardData.rewardTokenDecimals) / 100)
|
|
319
|
+
.mul(365 * 24 * 3600)
|
|
320
|
+
.mul(supplyRewardPrice)
|
|
321
|
+
.div(_market.price)
|
|
322
|
+
.div(_market.totalSupply)
|
|
323
|
+
.toString();
|
|
324
|
+
_market.incentiveSupplyApy = new Dec(_market.incentiveSupplyApy || '0').add(rewardApy)
|
|
325
|
+
.toString();
|
|
326
|
+
|
|
327
|
+
if (!_market.supplyIncentives) {
|
|
328
|
+
_market.supplyIncentives = [];
|
|
329
|
+
}
|
|
330
|
+
_market.supplyIncentives.push({
|
|
331
|
+
token: supplyRewardData.rewardTokenSymbol,
|
|
332
|
+
apy: rewardApy,
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
rewardForMarket.vIncentiveData.rewardsTokenInformation.forEach(borrowRewardData => {
|
|
337
|
+
if (borrowRewardData) {
|
|
338
|
+
if (+borrowRewardData.emissionEndTimestamp * 1000 < Date.now()) return;
|
|
339
|
+
_market.incentiveBorrowToken = borrowRewardData.rewardTokenSymbol;
|
|
340
|
+
if (borrowRewardData.rewardTokenSymbol.startsWith('a') && borrowRewardData.rewardTokenSymbol.includes(_market.symbol)) _market.incentiveBorrowToken = _market.symbol;
|
|
341
|
+
const supplyEmissionPerSecond = borrowRewardData.emissionPerSecond;
|
|
342
|
+
const supplyRewardPrice = new Dec(borrowRewardData.rewardPriceFeed).div(10 ** +borrowRewardData.priceFeedDecimals)
|
|
343
|
+
.toString();
|
|
344
|
+
const rewardApy = new Dec(supplyEmissionPerSecond).div((10 ** +borrowRewardData.rewardTokenDecimals) / 100)
|
|
345
|
+
.mul(365 * 24 * 3600)
|
|
346
|
+
.mul(supplyRewardPrice)
|
|
347
|
+
.div(_market.price)
|
|
348
|
+
.div(_market.totalBorrowVar)
|
|
349
|
+
.toString();
|
|
350
|
+
_market.incentiveBorrowApy = new Dec(_market.incentiveBorrowApy || '0').add(rewardApy)
|
|
351
|
+
.toString();
|
|
352
|
+
|
|
353
|
+
if (!_market.borrowIncentives) {
|
|
354
|
+
_market.borrowIncentives = [];
|
|
355
|
+
}
|
|
356
|
+
_market.borrowIncentives.push({
|
|
357
|
+
token: borrowRewardData.rewardTokenSymbol,
|
|
358
|
+
apy: rewardApy,
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
});
|
|
328
362
|
}));
|
|
329
363
|
|
|
330
364
|
const payload: AaveV3AssetsData = {};
|
package/src/compoundV2/index.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
Blockish, EthAddress, NetworkNumber, PositionBalances,
|
|
9
9
|
} from '../types/common';
|
|
10
10
|
import { CompoundLoanInfoContract, ComptrollerContract } from '../contracts';
|
|
11
|
-
import { compoundV2CollateralAssets } from '../markets
|
|
11
|
+
import { compoundV2CollateralAssets } from '../markets';
|
|
12
12
|
import {
|
|
13
13
|
CompoundV2AssetsData, CompoundV2MarketsData, CompoundV2PositionData, CompoundV2UsedAsset, CompoundV2UsedAssets,
|
|
14
14
|
} from '../types';
|
|
@@ -217,4 +217,4 @@ export const getCompoundV2FullPositionData = async (web3: Web3, network: Network
|
|
|
217
217
|
const marketData = await getCompoundV2MarketsData(web3, network);
|
|
218
218
|
const positionData = await getCompoundV2AccountData(web3, network, address, marketData.assetsData);
|
|
219
219
|
return positionData;
|
|
220
|
-
};
|
|
220
|
+
};
|
|
@@ -5,7 +5,7 @@ import { wethToEthByAddress } from '../services/utils';
|
|
|
5
5
|
import {
|
|
6
6
|
Blockish, EthAddress, NetworkNumber, PositionBalances,
|
|
7
7
|
} from '../types/common';
|
|
8
|
-
import {
|
|
8
|
+
import { getStETHApy } from '../staking';
|
|
9
9
|
import { MorphoAaveV2ViewContract } from '../contracts';
|
|
10
10
|
import {
|
|
11
11
|
AavePositionData,
|
|
@@ -103,7 +103,7 @@ export const getMorphoAaveV2MarketsData = async (web3: Web3, network: NetworkNum
|
|
|
103
103
|
|
|
104
104
|
const stEthMarket = assetsData.find(({ symbol }) => symbol === 'stETH');
|
|
105
105
|
if (stEthMarket) {
|
|
106
|
-
stEthMarket.incentiveSupplyApy = await
|
|
106
|
+
stEthMarket.incentiveSupplyApy = await getStETHApy(mainnetWeb3);
|
|
107
107
|
stEthMarket.incentiveSupplyToken = 'stETH';
|
|
108
108
|
}
|
|
109
109
|
|