@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
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Use IntelliSense to learn about possible attributes.
|
|
3
|
+
// Hover to view descriptions of existing attributes.
|
|
4
|
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
+
"version": "0.2.0",
|
|
6
|
+
"configurations": [
|
|
7
|
+
{
|
|
8
|
+
"name": "Attach by Process ID",
|
|
9
|
+
"processId": "${command:PickProcess}",
|
|
10
|
+
"request": "attach",
|
|
11
|
+
"skipFiles": [
|
|
12
|
+
"<node_internals>/**"
|
|
13
|
+
],
|
|
14
|
+
"type": "node"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"workbench.colorCustomizations": {
|
|
3
|
+
"activityBar.activeBackground": "#f2255a",
|
|
4
|
+
"activityBar.background": "#f2255a",
|
|
5
|
+
"activityBar.foreground": "#e7e7e7",
|
|
6
|
+
"activityBar.inactiveForeground": "#e7e7e799",
|
|
7
|
+
"activityBarBadge.background": "#40d30d",
|
|
8
|
+
"activityBarBadge.foreground": "#15202b",
|
|
9
|
+
"commandCenter.border": "#e7e7e799",
|
|
10
|
+
"sash.hoverBorder": "#f2255a",
|
|
11
|
+
"statusBar.background": "#d70d41",
|
|
12
|
+
"statusBar.foreground": "#e7e7e7",
|
|
13
|
+
"statusBarItem.hoverBackground": "#f2255a",
|
|
14
|
+
"statusBarItem.remoteBackground": "#d70d41",
|
|
15
|
+
"statusBarItem.remoteForeground": "#e7e7e7",
|
|
16
|
+
"titleBar.activeBackground": "#d70d41",
|
|
17
|
+
"titleBar.activeForeground": "#e7e7e7",
|
|
18
|
+
"titleBar.inactiveBackground": "#d70d4199",
|
|
19
|
+
"titleBar.inactiveForeground": "#e7e7e799"
|
|
20
|
+
},
|
|
21
|
+
"peacock.color": "#d70d41"
|
|
22
|
+
}
|
package/cjs/aaveV2/index.js
CHANGED
|
@@ -66,7 +66,7 @@ const getAaveV2MarketsData = (web3, network, selectedMarket, mainnetWeb3) => __a
|
|
|
66
66
|
}));
|
|
67
67
|
const stEthMarket = markets.find(({ symbol }) => symbol === 'stETH');
|
|
68
68
|
if (stEthMarket) {
|
|
69
|
-
stEthMarket.incentiveSupplyApy = yield (0, staking_1.
|
|
69
|
+
stEthMarket.incentiveSupplyApy = yield (0, staking_1.getStETHApy)(mainnetWeb3);
|
|
70
70
|
stEthMarket.incentiveSupplyToken = 'stETH';
|
|
71
71
|
}
|
|
72
72
|
const payload = {};
|
package/cjs/aaveV3/index.js
CHANGED
|
@@ -184,6 +184,7 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
184
184
|
},
|
|
185
185
|
})), { symbol, isIsolated: new decimal_js_1.default(tokenMarket.debtCeilingForIsolationMode).gt(0), debtCeilingForIsolationMode: new decimal_js_1.default(tokenMarket.debtCeilingForIsolationMode).div(100).toString(), isSiloed: tokenMarket.isSiloedForBorrowing, isolationModeTotalDebt: new decimal_js_1.default(tokenMarket.isolationModeTotalDebt).div(100).toString(), assetId: Number(tokenMarket.assetId), underlyingTokenAddress: tokenMarket.underlyingTokenAddress, supplyRate: (0, moneymarket_1.aprToApy)(new decimal_js_1.default(tokenMarket.supplyRate.toString()).div(1e25).toString()), borrowRate: (0, moneymarket_1.aprToApy)(new decimal_js_1.default(tokenMarket.borrowRateVariable.toString()).div(1e25).toString()), borrowRateDiscounted: (0, moneymarket_1.aprToApy)(nativeAsset ? new decimal_js_1.default(tokenMarket.borrowRateVariable.toString()).div(1e25).mul(1 - parseFloat(discountRateOnBorrow)).toString() : '0'), borrowRateStable: (0, moneymarket_1.aprToApy)(new decimal_js_1.default(tokenMarket.borrowRateStable.toString()).div(1e25).toString()), collateralFactor: new decimal_js_1.default(tokenMarket.collateralFactor.toString()).div(10000).toString(), liquidationRatio: new decimal_js_1.default(tokenMarket.liquidationRatio.toString()).div(10000).toString(), marketLiquidity, utilization: new decimal_js_1.default(tokenMarket.totalBorrow.toString()).times(100).div(new decimal_js_1.default(tokenMarket.totalSupply.toString())).toString(), usageAsCollateralEnabled: tokenMarket.usageAsCollateralEnabled, supplyCap: tokenMarket.supplyCap, borrowCap, totalSupply: (0, tokens_1.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: (0, tokens_1.assetAmountInEth)(tokenMarket.totalBorrow.toString(), symbol), totalBorrowVar: (0, tokens_1.assetAmountInEth)(tokenMarket.totalBorrowVar.toString(), symbol), price: new decimal_js_1.default(tokenMarket.price.toString()).div(1e8).toString(), isolationModeBorrowingEnabled: tokenMarket.isolationModeBorrowingEnabled, isFlashLoanEnabled: tokenMarket.isFlashLoanEnabled, aTokenAddress: tokenMarket.aTokenAddress }));
|
|
186
186
|
})));
|
|
187
|
+
// Get incentives data
|
|
187
188
|
yield Promise.all(assetsData.map((_market) => __awaiter(this, void 0, void 0, function* () {
|
|
188
189
|
/* eslint-disable no-param-reassign */
|
|
189
190
|
const rewardForMarket = rewardInfo === null || rewardInfo === void 0 ? void 0 : rewardInfo[_market.underlyingTokenAddress];
|
|
@@ -191,53 +192,82 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
191
192
|
if (isStakingAsset) {
|
|
192
193
|
_market.incentiveSupplyApy = yield (0, staking_1.getStakingApy)(_market.symbol, defaultWeb3);
|
|
193
194
|
_market.incentiveSupplyToken = _market.symbol;
|
|
195
|
+
if (!_market.supplyIncentives) {
|
|
196
|
+
_market.supplyIncentives = [];
|
|
197
|
+
}
|
|
198
|
+
_market.supplyIncentives.push({
|
|
199
|
+
apy: _market.incentiveSupplyApy || '0',
|
|
200
|
+
token: _market.symbol,
|
|
201
|
+
});
|
|
194
202
|
}
|
|
195
203
|
if (_market.canBeBorrowed && _market.incentiveSupplyApy) {
|
|
196
|
-
_market.incentiveBorrowApy =
|
|
204
|
+
_market.incentiveBorrowApy = _market.incentiveSupplyApy;
|
|
197
205
|
_market.incentiveBorrowToken = _market.incentiveSupplyToken;
|
|
206
|
+
if (!_market.borrowIncentives) {
|
|
207
|
+
_market.borrowIncentives = [];
|
|
208
|
+
}
|
|
209
|
+
_market.borrowIncentives.push({
|
|
210
|
+
apy: _market.incentiveBorrowApy,
|
|
211
|
+
token: _market.incentiveBorrowToken,
|
|
212
|
+
});
|
|
198
213
|
}
|
|
199
214
|
if (!rewardForMarket)
|
|
200
215
|
return;
|
|
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
|
-
|
|
232
|
-
|
|
233
|
-
.
|
|
234
|
-
.
|
|
235
|
-
|
|
236
|
-
.
|
|
237
|
-
.
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
216
|
+
rewardForMarket.aIncentiveData.rewardsTokenInformation.forEach(supplyRewardData => {
|
|
217
|
+
if (supplyRewardData) {
|
|
218
|
+
if (+supplyRewardData.emissionEndTimestamp * 1000 < Date.now())
|
|
219
|
+
return;
|
|
220
|
+
_market.incentiveSupplyToken = supplyRewardData.rewardTokenSymbol;
|
|
221
|
+
// reward token is aave asset
|
|
222
|
+
if (supplyRewardData.rewardTokenSymbol.startsWith('a') && supplyRewardData.rewardTokenSymbol.includes(_market.symbol))
|
|
223
|
+
_market.incentiveSupplyToken = _market.symbol;
|
|
224
|
+
const supplyEmissionPerSecond = supplyRewardData.emissionPerSecond;
|
|
225
|
+
const supplyRewardPrice = new decimal_js_1.default(supplyRewardData.rewardPriceFeed).div(Math.pow(10, +supplyRewardData.priceFeedDecimals))
|
|
226
|
+
.toString();
|
|
227
|
+
const rewardApy = new decimal_js_1.default(supplyEmissionPerSecond).div((Math.pow(10, +supplyRewardData.rewardTokenDecimals)) / 100)
|
|
228
|
+
.mul(365 * 24 * 3600)
|
|
229
|
+
.mul(supplyRewardPrice)
|
|
230
|
+
.div(_market.price)
|
|
231
|
+
.div(_market.totalSupply)
|
|
232
|
+
.toString();
|
|
233
|
+
_market.incentiveSupplyApy = new decimal_js_1.default(_market.incentiveSupplyApy || '0').add(rewardApy)
|
|
234
|
+
.toString();
|
|
235
|
+
if (!_market.supplyIncentives) {
|
|
236
|
+
_market.supplyIncentives = [];
|
|
237
|
+
}
|
|
238
|
+
_market.supplyIncentives.push({
|
|
239
|
+
token: supplyRewardData.rewardTokenSymbol,
|
|
240
|
+
apy: rewardApy,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
rewardForMarket.vIncentiveData.rewardsTokenInformation.forEach(borrowRewardData => {
|
|
245
|
+
if (borrowRewardData) {
|
|
246
|
+
if (+borrowRewardData.emissionEndTimestamp * 1000 < Date.now())
|
|
247
|
+
return;
|
|
248
|
+
_market.incentiveBorrowToken = borrowRewardData.rewardTokenSymbol;
|
|
249
|
+
if (borrowRewardData.rewardTokenSymbol.startsWith('a') && borrowRewardData.rewardTokenSymbol.includes(_market.symbol))
|
|
250
|
+
_market.incentiveBorrowToken = _market.symbol;
|
|
251
|
+
const supplyEmissionPerSecond = borrowRewardData.emissionPerSecond;
|
|
252
|
+
const supplyRewardPrice = new decimal_js_1.default(borrowRewardData.rewardPriceFeed).div(Math.pow(10, +borrowRewardData.priceFeedDecimals))
|
|
253
|
+
.toString();
|
|
254
|
+
const rewardApy = new decimal_js_1.default(supplyEmissionPerSecond).div((Math.pow(10, +borrowRewardData.rewardTokenDecimals)) / 100)
|
|
255
|
+
.mul(365 * 24 * 3600)
|
|
256
|
+
.mul(supplyRewardPrice)
|
|
257
|
+
.div(_market.price)
|
|
258
|
+
.div(_market.totalBorrowVar)
|
|
259
|
+
.toString();
|
|
260
|
+
_market.incentiveBorrowApy = new decimal_js_1.default(_market.incentiveBorrowApy || '0').add(rewardApy)
|
|
261
|
+
.toString();
|
|
262
|
+
if (!_market.borrowIncentives) {
|
|
263
|
+
_market.borrowIncentives = [];
|
|
264
|
+
}
|
|
265
|
+
_market.borrowIncentives.push({
|
|
266
|
+
token: borrowRewardData.rewardTokenSymbol,
|
|
267
|
+
apy: rewardApy,
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
});
|
|
241
271
|
})));
|
|
242
272
|
const payload = {};
|
|
243
273
|
// Sort by market size
|
package/cjs/compoundV2/index.js
CHANGED
|
@@ -19,11 +19,11 @@ const constants_1 = require("../constants");
|
|
|
19
19
|
const moneymarket_1 = require("../moneymarket");
|
|
20
20
|
const utils_1 = require("../services/utils");
|
|
21
21
|
const contracts_1 = require("../contracts");
|
|
22
|
-
const
|
|
22
|
+
const markets_1 = require("../markets");
|
|
23
23
|
const compoundHelpers_1 = require("../helpers/compoundHelpers");
|
|
24
24
|
const compAddress = '0xc00e94cb662c3520282e6f5717214004a7f26888';
|
|
25
25
|
const getCompoundV2MarketsData = (web3, network) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
-
const cAddresses =
|
|
26
|
+
const cAddresses = markets_1.compoundV2CollateralAssets.map(a => a.address);
|
|
27
27
|
const loanInfoContract = (0, contracts_1.CompoundLoanInfoContract)(web3, network);
|
|
28
28
|
const loanInfo = yield loanInfoContract.methods.getFullTokensInfo(cAddresses).call();
|
|
29
29
|
const compPrice = loanInfo.find(m => (0, utils_1.compareAddresses)(m.underlyingTokenAddress, compAddress)).price.toString();
|
|
@@ -135,15 +135,15 @@ const getCompoundV2AccountData = (web3, network, address, assetsData) => __await
|
|
|
135
135
|
throw new Error('No address provided');
|
|
136
136
|
let payload = Object.assign(Object.assign({}, exports.EMPTY_COMPOUND_DATA), { lastUpdated: Date.now() });
|
|
137
137
|
const loanInfoContract = (0, contracts_1.CompoundLoanInfoContract)(web3, network);
|
|
138
|
-
const loanInfo = yield loanInfoContract.methods.getTokenBalances(address,
|
|
138
|
+
const loanInfo = yield loanInfoContract.methods.getTokenBalances(address, markets_1.compoundV2CollateralAssets.map(a => a.address)).call();
|
|
139
139
|
const collateralAssetsAddresses = yield (0, exports.getCollateralAssetsAddresses)(web3, network, address);
|
|
140
140
|
const usedAssets = {};
|
|
141
141
|
loanInfo.balances.forEach((weiAmount, i) => {
|
|
142
|
-
const asset =
|
|
143
|
-
? `${
|
|
144
|
-
:
|
|
142
|
+
const asset = markets_1.compoundV2CollateralAssets[i].symbol === 'cWBTC Legacy'
|
|
143
|
+
? `${markets_1.compoundV2CollateralAssets[i].underlyingAsset} Legacy`
|
|
144
|
+
: markets_1.compoundV2CollateralAssets[i].underlyingAsset;
|
|
145
145
|
const amount = (0, tokens_1.assetAmountInEth)(weiAmount.toString(), asset);
|
|
146
|
-
const collateral = !!collateralAssetsAddresses.find(a => (0, utils_1.compareAddresses)(a,
|
|
146
|
+
const collateral = !!collateralAssetsAddresses.find(a => (0, utils_1.compareAddresses)(a, markets_1.compoundV2CollateralAssets[i].address));
|
|
147
147
|
if (weiAmount.toString() === '0' && !collateral)
|
|
148
148
|
return;
|
|
149
149
|
if (!usedAssets[asset])
|
|
@@ -153,9 +153,9 @@ const getCompoundV2AccountData = (web3, network, address, assetsData) => __await
|
|
|
153
153
|
loanInfo.borrows.forEach((weiAmount, i) => {
|
|
154
154
|
if (weiAmount.toString() === '0')
|
|
155
155
|
return;
|
|
156
|
-
const asset =
|
|
157
|
-
? `${
|
|
158
|
-
:
|
|
156
|
+
const asset = markets_1.compoundV2CollateralAssets[i].symbol === 'cWBTC Legacy'
|
|
157
|
+
? `${markets_1.compoundV2CollateralAssets[i].underlyingAsset} Legacy`
|
|
158
|
+
: markets_1.compoundV2CollateralAssets[i].underlyingAsset;
|
|
159
159
|
const amount = (0, tokens_1.assetAmountInEth)(weiAmount.toString(), asset);
|
|
160
160
|
if (!usedAssets[asset])
|
|
161
161
|
usedAssets[asset] = {};
|
|
@@ -93,7 +93,7 @@ const getMorphoAaveV2MarketsData = (web3, network, mainnetWeb3) => __awaiter(voi
|
|
|
93
93
|
});
|
|
94
94
|
const stEthMarket = assetsData.find(({ symbol }) => symbol === 'stETH');
|
|
95
95
|
if (stEthMarket) {
|
|
96
|
-
stEthMarket.incentiveSupplyApy = yield (0, staking_1.
|
|
96
|
+
stEthMarket.incentiveSupplyApy = yield (0, staking_1.getStETHApy)(mainnetWeb3);
|
|
97
97
|
stEthMarket.incentiveSupplyToken = 'stETH';
|
|
98
98
|
}
|
|
99
99
|
const payload = {};
|
package/cjs/spark/index.js
CHANGED
|
@@ -129,45 +129,79 @@ const getSparkMarketsData = (web3, network, selectedMarket, mainnetWeb3) => __aw
|
|
|
129
129
|
if (staking_1.STAKING_ASSETS.includes(market.symbol)) {
|
|
130
130
|
market.incentiveSupplyApy = yield (0, staking_1.getStakingApy)(market.symbol, mainnetWeb3);
|
|
131
131
|
market.incentiveSupplyToken = market.symbol;
|
|
132
|
+
if (!market.supplyIncentives) {
|
|
133
|
+
market.supplyIncentives = [];
|
|
134
|
+
}
|
|
135
|
+
market.supplyIncentives.push({
|
|
136
|
+
apy: market.incentiveSupplyApy || '0',
|
|
137
|
+
token: market.symbol,
|
|
138
|
+
});
|
|
132
139
|
}
|
|
133
140
|
if (market.symbol === 'sDAI') {
|
|
134
141
|
market.incentiveSupplyApy = yield (0, dsrService_1.getDsrApy)(web3, network);
|
|
135
142
|
market.incentiveSupplyToken = 'sDAI';
|
|
136
143
|
}
|
|
137
144
|
if (market.canBeBorrowed && market.incentiveSupplyApy) {
|
|
138
|
-
market.incentiveBorrowApy =
|
|
145
|
+
market.incentiveBorrowApy = market.incentiveSupplyApy;
|
|
139
146
|
market.incentiveBorrowToken = market.incentiveSupplyToken;
|
|
147
|
+
if (!market.borrowIncentives) {
|
|
148
|
+
market.borrowIncentives = [];
|
|
149
|
+
}
|
|
150
|
+
market.borrowIncentives.push({
|
|
151
|
+
apy: market.incentiveBorrowApy,
|
|
152
|
+
token: market.incentiveBorrowToken,
|
|
153
|
+
});
|
|
140
154
|
}
|
|
141
155
|
if (!rewardForMarket)
|
|
142
156
|
return;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
.
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
.
|
|
170
|
-
|
|
157
|
+
rewardForMarket.aIncentiveData.rewardsTokenInformation.forEach(supplyRewardData => {
|
|
158
|
+
if (supplyRewardData) {
|
|
159
|
+
if (supplyRewardData.emissionEndTimestamp * 1000 < Date.now())
|
|
160
|
+
return;
|
|
161
|
+
market.incentiveSupplyToken = supplyRewardData.rewardTokenSymbol;
|
|
162
|
+
const supplyEmissionPerSecond = supplyRewardData.emissionPerSecond;
|
|
163
|
+
const supplyRewardPrice = new decimal_js_1.default(supplyRewardData.rewardPriceFeed).div(Math.pow(10, supplyRewardData.priceFeedDecimals))
|
|
164
|
+
.toString();
|
|
165
|
+
const rewardApy = new decimal_js_1.default(supplyEmissionPerSecond).div((Math.pow(10, supplyRewardData.rewardTokenDecimals)) / 100)
|
|
166
|
+
.mul(365 * 24 * 3600)
|
|
167
|
+
.mul(supplyRewardPrice)
|
|
168
|
+
.div(market.price)
|
|
169
|
+
.div(market.totalSupply)
|
|
170
|
+
.toString();
|
|
171
|
+
market.incentiveSupplyApy = new decimal_js_1.default(market.incentiveSupplyApy || '0').add(rewardApy).toString();
|
|
172
|
+
if (!market.supplyIncentives) {
|
|
173
|
+
market.supplyIncentives = [];
|
|
174
|
+
}
|
|
175
|
+
market.supplyIncentives.push({
|
|
176
|
+
token: supplyRewardData.rewardTokenSymbol,
|
|
177
|
+
apy: rewardApy,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
rewardForMarket.vIncentiveData.rewardsTokenInformation.forEach(borrowRewardData => {
|
|
182
|
+
if (borrowRewardData) {
|
|
183
|
+
if (borrowRewardData.emissionEndTimestamp * 1000 < Date.now())
|
|
184
|
+
return;
|
|
185
|
+
market.incentiveBorrowToken = borrowRewardData.rewardTokenSymbol;
|
|
186
|
+
const supplyEmissionPerSecond = borrowRewardData.emissionPerSecond;
|
|
187
|
+
const supplyRewardPrice = new decimal_js_1.default(borrowRewardData.rewardPriceFeed).div(Math.pow(10, borrowRewardData.priceFeedDecimals))
|
|
188
|
+
.toString();
|
|
189
|
+
const rewardApy = new decimal_js_1.default(supplyEmissionPerSecond).div((Math.pow(10, borrowRewardData.rewardTokenDecimals)) / 100)
|
|
190
|
+
.mul(365 * 24 * 3600)
|
|
191
|
+
.mul(supplyRewardPrice)
|
|
192
|
+
.div(market.price)
|
|
193
|
+
.div(market.totalBorrowVar)
|
|
194
|
+
.toString();
|
|
195
|
+
market.incentiveBorrowApy = new decimal_js_1.default(market.incentiveBorrowApy || '0').add(rewardApy).toString();
|
|
196
|
+
if (!market.borrowIncentives) {
|
|
197
|
+
market.borrowIncentives = [];
|
|
198
|
+
}
|
|
199
|
+
market.borrowIncentives.push({
|
|
200
|
+
token: borrowRewardData.rewardTokenSymbol,
|
|
201
|
+
apy: rewardApy,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
});
|
|
171
205
|
/* eslint-enable no-param-reassign */
|
|
172
206
|
})));
|
|
173
207
|
const payload = {};
|
package/cjs/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/cjs/staking/staking.js
CHANGED
|
@@ -12,13 +12,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getStETHByWstETHMultiple = exports.getStETHByWstETH = exports.getWstETHByStETH = exports.calculateNetApy = exports.calculateInterestEarned = exports.getStakingApy = exports.STAKING_ASSETS = exports.getSsrApy = exports.getDsrApy = exports.
|
|
15
|
+
exports.getStETHByWstETHMultiple = exports.getStETHByWstETH = exports.getWstETHByStETH = exports.calculateNetApy = exports.calculateInterestEarned = exports.getStakingApy = exports.STAKING_ASSETS = exports.getSsrApy = exports.getDsrApy = exports.getREthApy = exports.getCbETHApy = exports.getStETHApy = void 0;
|
|
16
16
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
17
17
|
const contracts_1 = require("../contracts");
|
|
18
18
|
const common_1 = require("../types/common");
|
|
19
19
|
const constants_1 = require("../constants");
|
|
20
20
|
const multicall_1 = require("../multicall");
|
|
21
|
-
const
|
|
21
|
+
const moneymarket_1 = require("../moneymarket");
|
|
22
|
+
const getStETHApy = (web3, fromBlock = 17900000, blockNumber = 'latest') => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
23
|
try {
|
|
23
24
|
const tokenRebasedEvents = yield (0, contracts_1.LidoContract)(web3, common_1.NetworkNumber.Eth).getPastEvents('TokenRebased', { fromBlock, toBlock: blockNumber });
|
|
24
25
|
tokenRebasedEvents.sort((a, b) => b.blockNumber - a.blockNumber); // sort from highest to lowest block number
|
|
@@ -30,17 +31,17 @@ const getStETHApr = (web3, fromBlock = 17900000, blockNumber = 'latest') => __aw
|
|
|
30
31
|
.div(event.timeElapsed.toString()).mul(100)
|
|
31
32
|
.toNumber();
|
|
32
33
|
});
|
|
33
|
-
return aprs.reduce((a, b) => a + b, 0) / aprs.length;
|
|
34
|
+
return (0, moneymarket_1.aprToApy)(aprs.reduce((a, b) => a + b, 0) / aprs.length);
|
|
34
35
|
}
|
|
35
36
|
catch (e) {
|
|
36
37
|
console.warn('Failed to fetch stETH APY from events, falling back to Lido API');
|
|
37
38
|
const res = yield fetch('https://eth-api.lido.fi/v1/protocol/steth/apr/sma');
|
|
38
39
|
const data = yield res.json();
|
|
39
|
-
return data.data.smaApr;
|
|
40
|
+
return (0, moneymarket_1.aprToApy)(data.data.smaApr);
|
|
40
41
|
}
|
|
41
42
|
});
|
|
42
|
-
exports.
|
|
43
|
-
const
|
|
43
|
+
exports.getStETHApy = getStETHApy;
|
|
44
|
+
const getCbETHApy = (web3, blockNumber = 'latest') => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
45
|
let currentBlock = blockNumber;
|
|
45
46
|
if (blockNumber === 'latest')
|
|
46
47
|
currentBlock = yield web3.eth.getBlockNumber();
|
|
@@ -55,10 +56,10 @@ const getCbETHApr = (web3, blockNumber = 'latest') => __awaiter(void 0, void 0,
|
|
|
55
56
|
.mul(constants_1.BLOCKS_IN_A_YEAR / blockDiff)
|
|
56
57
|
.mul(100)
|
|
57
58
|
.toString();
|
|
58
|
-
return apr;
|
|
59
|
+
return (0, moneymarket_1.aprToApy)(apr);
|
|
59
60
|
});
|
|
60
|
-
exports.
|
|
61
|
-
const
|
|
61
|
+
exports.getCbETHApy = getCbETHApy;
|
|
62
|
+
const getREthApy = (web3, blockNumber = 'latest') => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
63
|
let currentBlock = blockNumber;
|
|
63
64
|
if (blockNumber === 'latest')
|
|
64
65
|
currentBlock = yield web3.eth.getBlockNumber();
|
|
@@ -73,9 +74,9 @@ const getREthApr = (web3, blockNumber = 'latest') => __awaiter(void 0, void 0, v
|
|
|
73
74
|
.mul(constants_1.BLOCKS_IN_A_YEAR / blockDiff)
|
|
74
75
|
.mul(100)
|
|
75
76
|
.toString();
|
|
76
|
-
return apr;
|
|
77
|
+
return (0, moneymarket_1.aprToApy)(apr);
|
|
77
78
|
});
|
|
78
|
-
exports.
|
|
79
|
+
exports.getREthApy = getREthApy;
|
|
79
80
|
const getDsrApy = (web3, blockNumber = 'latest') => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
81
|
const potContract = (0, contracts_1.PotContract)(web3, common_1.NetworkNumber.Eth);
|
|
81
82
|
return new decimal_js_1.default(yield potContract.methods.dsr().call())
|
|
@@ -93,7 +94,6 @@ const getSsrApy = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
93
94
|
});
|
|
94
95
|
exports.getSsrApy = getSsrApy;
|
|
95
96
|
const getSuperOETHApy = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
96
|
-
console.log('getSuperOETHApy');
|
|
97
97
|
const res = yield fetch('https://origin.squids.live/origin-squid/graphql', {
|
|
98
98
|
method: 'POST',
|
|
99
99
|
headers: {
|
|
@@ -113,18 +113,21 @@ const getSuperOETHApy = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
113
113
|
const getApyFromDfsApi = (asset) => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
114
|
const res = yield fetch(`https://app.defisaver.com/api/staking/apy?asset=${asset}`);
|
|
115
115
|
const data = yield res.json();
|
|
116
|
+
// if our server returns apr, transform it into apy
|
|
117
|
+
if (['weETH'].includes(asset)) {
|
|
118
|
+
return (0, moneymarket_1.aprToApy)(data.apy);
|
|
119
|
+
}
|
|
116
120
|
return data.apy;
|
|
117
121
|
});
|
|
118
122
|
exports.STAKING_ASSETS = ['cbETH', 'wstETH', 'cbETH', 'rETH', 'sDAI', 'weETH', 'sUSDe', 'osETH', 'ezETH', 'ETHx', 'rsETH', 'pufETH', 'wrsETH', 'wsuperOETHb', 'sUSDS'];
|
|
119
123
|
const getStakingApy = (asset, web3, blockNumber = 'latest', fromBlock = undefined) => {
|
|
120
|
-
console.log('getStakingApy', asset, blockNumber, fromBlock);
|
|
121
124
|
try {
|
|
122
125
|
if (asset === 'stETH' || asset === 'wstETH')
|
|
123
|
-
return (0, exports.
|
|
126
|
+
return (0, exports.getStETHApy)(web3, fromBlock, blockNumber);
|
|
124
127
|
if (asset === 'cbETH')
|
|
125
|
-
return (0, exports.
|
|
128
|
+
return (0, exports.getCbETHApy)(web3, blockNumber);
|
|
126
129
|
if (asset === 'rETH')
|
|
127
|
-
return (0, exports.
|
|
130
|
+
return (0, exports.getREthApy)(web3, blockNumber);
|
|
128
131
|
if (asset === 'sDAI')
|
|
129
132
|
return (0, exports.getDsrApy)(web3);
|
|
130
133
|
if (asset === 'sUSDe')
|
package/cjs/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/cjs/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/esm/aaveV2/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, getAssetInfo } from '@defisaver/tokens';
|
|
12
|
-
import { calculateNetApy,
|
|
12
|
+
import { calculateNetApy, getStETHApy } from '../staking';
|
|
13
13
|
import { ethToWeth, wethToEth, wethToEthByAddress } from '../services/utils';
|
|
14
14
|
import { AaveLoanInfoV2Contract, createContractWrapper } from '../contracts';
|
|
15
15
|
import { aprToApy, calculateBorrowingAssetLimit } from '../moneymarket';
|
|
@@ -60,7 +60,7 @@ export const getAaveV2MarketsData = (web3, network, selectedMarket, mainnetWeb3)
|
|
|
60
60
|
}));
|
|
61
61
|
const stEthMarket = markets.find(({ symbol }) => symbol === 'stETH');
|
|
62
62
|
if (stEthMarket) {
|
|
63
|
-
stEthMarket.incentiveSupplyApy = yield
|
|
63
|
+
stEthMarket.incentiveSupplyApy = yield getStETHApy(mainnetWeb3);
|
|
64
64
|
stEthMarket.incentiveSupplyToken = 'stETH';
|
|
65
65
|
}
|
|
66
66
|
const payload = {};
|