@defisaver/positions-sdk 0.0.147 → 0.0.149
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mocharc.json +4 -0
- package/.nvmrc +1 -0
- package/README.md +6 -0
- package/cjs/aaveV3/index.js +16 -4
- package/cjs/markets/aave/marketAssets.js +1 -3
- package/cjs/markets/compound/marketsAssets.js +2 -2
- package/cjs/moneymarket/moneymarketCommonService.js +5 -1
- package/esm/aaveV3/index.js +16 -4
- package/esm/markets/aave/marketAssets.js +1 -3
- package/esm/markets/compound/marketsAssets.js +2 -2
- package/esm/moneymarket/moneymarketCommonService.js +5 -1
- package/package.json +9 -6
- package/src/aaveV3/index.ts +12 -4
- package/src/markets/aave/marketAssets.ts +1 -3
- package/src/markets/compound/marketsAssets.ts +2 -2
- package/src/moneymarket/moneymarketCommonService.ts +5 -1
package/.mocharc.json
ADDED
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
v20.17.0
|
package/README.md
CHANGED
|
@@ -61,3 +61,9 @@ const userData = await getCompoundV3AccountData(
|
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
More examples found [here](https://github.com/defisaver/defisaver-positions-sdk/tree/main/tests)
|
|
64
|
+
|
|
65
|
+
## Testing
|
|
66
|
+
|
|
67
|
+
`npm run test` - Run all tests
|
|
68
|
+
|
|
69
|
+
`npm run test-single --name=your_test_name` - Run single test for specified name e.g. for MyTest.js test name is MyTest
|
package/cjs/aaveV3/index.js
CHANGED
|
@@ -136,7 +136,7 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
136
136
|
}
|
|
137
137
|
const [{ 0: ghoDiscountedPerDiscountToken }, { 0: discountRate }, { 0: minDiscountTokenBalance }, { 0: minGhoBalanceForDiscount }, { 0: facilitatorsList },] = multiRes;
|
|
138
138
|
let rewardInfo = null;
|
|
139
|
-
const networksWithIncentives = [common_1.NetworkNumber.Arb, common_1.NetworkNumber.Opt];
|
|
139
|
+
const networksWithIncentives = [common_1.NetworkNumber.Eth, common_1.NetworkNumber.Arb, common_1.NetworkNumber.Opt];
|
|
140
140
|
if (networksWithIncentives.includes(network)) {
|
|
141
141
|
rewardInfo = yield aaveIncentivesContract.methods.getReservesIncentivesData(marketAddress).call();
|
|
142
142
|
rewardInfo = rewardInfo.reduce((all, _market) => {
|
|
@@ -187,7 +187,8 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
187
187
|
yield Promise.all(assetsData.map((_market) => __awaiter(this, void 0, void 0, function* () {
|
|
188
188
|
/* eslint-disable no-param-reassign */
|
|
189
189
|
const rewardForMarket = rewardInfo === null || rewardInfo === void 0 ? void 0 : rewardInfo[_market.underlyingTokenAddress];
|
|
190
|
-
|
|
190
|
+
const isStakingAsset = staking_1.STAKING_ASSETS.includes(_market.symbol);
|
|
191
|
+
if (isStakingAsset) {
|
|
191
192
|
_market.incentiveSupplyApy = yield (0, staking_1.getStakingApy)(_market.symbol, defaultWeb3);
|
|
192
193
|
_market.incentiveSupplyToken = _market.symbol;
|
|
193
194
|
}
|
|
@@ -199,31 +200,42 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
199
200
|
return;
|
|
200
201
|
const supplyRewardData = rewardForMarket.aIncentiveData.rewardsTokenInformation[0];
|
|
201
202
|
if (supplyRewardData) {
|
|
203
|
+
if (isStakingAsset && _market.incentiveSupplyToken !== supplyRewardData.rewardTokenSymbol)
|
|
204
|
+
return;
|
|
202
205
|
if (+supplyRewardData.emissionEndTimestamp * 1000 < Date.now())
|
|
203
206
|
return;
|
|
204
207
|
_market.incentiveSupplyToken = supplyRewardData.rewardTokenSymbol;
|
|
208
|
+
// reward token is aave asset
|
|
209
|
+
if (supplyRewardData.rewardTokenSymbol.startsWith('a') && supplyRewardData.rewardTokenSymbol.includes(_market.symbol))
|
|
210
|
+
_market.incentiveSupplyToken = _market.symbol;
|
|
205
211
|
const supplyEmissionPerSecond = supplyRewardData.emissionPerSecond;
|
|
206
212
|
const supplyRewardPrice = new decimal_js_1.default(supplyRewardData.rewardPriceFeed).div(Math.pow(10, +supplyRewardData.priceFeedDecimals)).toString();
|
|
207
|
-
|
|
213
|
+
const rewardApy = new decimal_js_1.default(supplyEmissionPerSecond).div((Math.pow(10, +supplyRewardData.rewardTokenDecimals)) / 100)
|
|
208
214
|
.mul(365 * 24 * 3600)
|
|
209
215
|
.mul(supplyRewardPrice)
|
|
210
216
|
.div(_market.price)
|
|
211
217
|
.div(_market.totalSupply)
|
|
212
218
|
.toString();
|
|
219
|
+
_market.incentiveSupplyApy = new decimal_js_1.default(_market.incentiveSupplyApy || '0').add(rewardApy).toString();
|
|
213
220
|
}
|
|
214
221
|
const borrowRewardData = rewardForMarket.vIncentiveData.rewardsTokenInformation[0];
|
|
215
222
|
if (borrowRewardData) {
|
|
223
|
+
if (isStakingAsset && _market.incentiveSupplyToken !== borrowRewardData.rewardTokenSymbol)
|
|
224
|
+
return;
|
|
216
225
|
if (+borrowRewardData.emissionEndTimestamp * 1000 < Date.now())
|
|
217
226
|
return;
|
|
218
227
|
_market.incentiveBorrowToken = borrowRewardData.rewardTokenSymbol;
|
|
228
|
+
if (supplyRewardData.rewardTokenSymbol.startsWith('a') && supplyRewardData.rewardTokenSymbol.includes(_market.symbol))
|
|
229
|
+
_market.incentiveBorrowToken = _market.symbol;
|
|
219
230
|
const supplyEmissionPerSecond = borrowRewardData.emissionPerSecond;
|
|
220
231
|
const supplyRewardPrice = new decimal_js_1.default(borrowRewardData.rewardPriceFeed).div(Math.pow(10, +borrowRewardData.priceFeedDecimals)).toString();
|
|
221
|
-
|
|
232
|
+
const rewardApy = new decimal_js_1.default(supplyEmissionPerSecond).div((Math.pow(10, +borrowRewardData.rewardTokenDecimals)) / 100)
|
|
222
233
|
.mul(365 * 24 * 3600)
|
|
223
234
|
.mul(supplyRewardPrice)
|
|
224
235
|
.div(_market.price)
|
|
225
236
|
.div(_market.totalBorrowVar)
|
|
226
237
|
.toString();
|
|
238
|
+
_market.incentiveBorrowApy = new decimal_js_1.default(_market.incentiveSupplyApy || '0').add(rewardApy).toString();
|
|
227
239
|
}
|
|
228
240
|
/* eslint-enable no-param-reassign */
|
|
229
241
|
})));
|
|
@@ -9,9 +9,7 @@ exports.aaveV1AssetsDefaultMarket = [
|
|
|
9
9
|
].map((symbol) => (0, tokens_1.getAssetInfo)(symbol));
|
|
10
10
|
exports.aaveV2AssetsDefaultMarket = ['USDT', 'WBTC', 'ETH', 'YFI', 'ZRX', 'UNI', 'AAVE', 'BAT', 'BUSD', 'DAI', 'ENJ', 'KNCL', 'LINK', 'MANA', 'MKR', 'REN', 'SNX', 'SUSD', 'TUSD', 'USDC', 'CRV', 'GUSD', 'BAL', 'xSUSHI', 'RENFIL', 'RAI', 'AMPL', 'USDP', 'DPI', 'FRAX', 'FEI', 'stETH', 'ENS', 'UST', 'CVX', '1INCH', 'LUSD'];
|
|
11
11
|
exports.morphoAaveV2AssetDefaultMarket = ['DAI', 'ETH', 'USDC', 'USDT', 'WBTC', 'stETH', 'CRV'];
|
|
12
|
-
exports.morphoAaveV3AssetEthMarket = [
|
|
13
|
-
'ETH', 'wstETH', 'USDC', 'WBTC', 'rETH', 'cbETH', 'USDT',
|
|
14
|
-
];
|
|
12
|
+
exports.morphoAaveV3AssetEthMarket = ['ETH', 'wstETH', 'DAI', 'USDC', 'WBTC', 'rETH', 'cbETH', 'sDAI', 'USDT'];
|
|
15
13
|
exports.aaveV3AssetsDefaultMarketEth = ['ETH', 'wstETH', 'WBTC', 'USDC', 'DAI', 'LINK', 'AAVE', 'cbETH', 'USDT', 'rETH', 'LUSD', 'CRV', 'MKR', 'SNX', 'BAL', 'UNI', 'LDO', 'ENS', '1INCH', 'FRAX', 'GHO', 'RPL', 'sDAI', 'STG', 'KNC', 'FXS', 'crvUSD', 'PYUSD', 'weETH', 'osETH', 'USDe', 'ETHx', 'sUSDe', 'tBTC', 'cbBTC', 'USDS'];
|
|
16
14
|
exports.aaveV3AssetsDefaultMarketOpt = [
|
|
17
15
|
'DAI', 'USDC.e', 'USDT', 'SUSD', 'AAVE', 'LINK', 'WBTC', 'ETH', 'OP', 'wstETH', 'LUSD', 'MAI', 'rETH', 'USDC',
|
|
@@ -26,8 +26,8 @@ exports.v3USDCeCollAssets = {
|
|
|
26
26
|
[common_1.NetworkNumber.Arb]: exports.v3USDCeCollAssetsArb,
|
|
27
27
|
[common_1.NetworkNumber.Base]: [],
|
|
28
28
|
};
|
|
29
|
-
exports.v3ETHCollAssetsEth = ['cbETH', 'wstETH', 'rETH', 'rsETH', 'weETH', 'osETH', 'WBTC', 'ezETH'];
|
|
30
|
-
exports.v3ETHCollAssetsBase = ['cbETH', 'ezETH', 'USDC', '
|
|
29
|
+
exports.v3ETHCollAssetsEth = ['cbETH', 'wstETH', 'rETH', 'rsETH', 'weETH', 'osETH', 'WBTC', 'ezETH', 'cbBTC', 'rswETH'];
|
|
30
|
+
exports.v3ETHCollAssetsBase = ['cbETH', 'ezETH', 'wstETH', 'USDC', 'weETH', 'wrsETH', 'cbBTC'];
|
|
31
31
|
exports.v3ETHCollAssetsArb = ['weETH', 'rETH', 'wstETH', 'WBTC', 'rsETH', 'ezETH', 'USDC', 'USDT'];
|
|
32
32
|
exports.v3ETHCollAssetsOpt = ['rETH', 'wstETH', 'WBTC', 'ezETH', 'USDC', 'USDT', 'weETH', 'wrsETH'];
|
|
33
33
|
// @dev Keep assets in array, do not assign directly, so we can parse it and edit it programmatically with `scripts/updateMarkets`
|
|
@@ -79,5 +79,9 @@ const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
|
79
79
|
};
|
|
80
80
|
};
|
|
81
81
|
exports.isLeveragedPos = isLeveragedPos;
|
|
82
|
-
const aprToApy = (interest, frequency = constants_1.BLOCKS_IN_A_YEAR) => new decimal_js_1.default(interest).div(100).div(frequency).plus(1)
|
|
82
|
+
const aprToApy = (interest, frequency = constants_1.BLOCKS_IN_A_YEAR) => new decimal_js_1.default(interest).div(100).div(frequency).plus(1)
|
|
83
|
+
.pow(frequency)
|
|
84
|
+
.minus(1)
|
|
85
|
+
.times(100)
|
|
86
|
+
.toString();
|
|
83
87
|
exports.aprToApy = aprToApy;
|
package/esm/aaveV3/index.js
CHANGED
|
@@ -127,7 +127,7 @@ export function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
127
127
|
}
|
|
128
128
|
const [{ 0: ghoDiscountedPerDiscountToken }, { 0: discountRate }, { 0: minDiscountTokenBalance }, { 0: minGhoBalanceForDiscount }, { 0: facilitatorsList },] = multiRes;
|
|
129
129
|
let rewardInfo = null;
|
|
130
|
-
const networksWithIncentives = [NetworkNumber.Arb, NetworkNumber.Opt];
|
|
130
|
+
const networksWithIncentives = [NetworkNumber.Eth, NetworkNumber.Arb, NetworkNumber.Opt];
|
|
131
131
|
if (networksWithIncentives.includes(network)) {
|
|
132
132
|
rewardInfo = yield aaveIncentivesContract.methods.getReservesIncentivesData(marketAddress).call();
|
|
133
133
|
rewardInfo = rewardInfo.reduce((all, _market) => {
|
|
@@ -178,7 +178,8 @@ export function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
178
178
|
yield Promise.all(assetsData.map((_market) => __awaiter(this, void 0, void 0, function* () {
|
|
179
179
|
/* eslint-disable no-param-reassign */
|
|
180
180
|
const rewardForMarket = rewardInfo === null || rewardInfo === void 0 ? void 0 : rewardInfo[_market.underlyingTokenAddress];
|
|
181
|
-
|
|
181
|
+
const isStakingAsset = STAKING_ASSETS.includes(_market.symbol);
|
|
182
|
+
if (isStakingAsset) {
|
|
182
183
|
_market.incentiveSupplyApy = yield getStakingApy(_market.symbol, defaultWeb3);
|
|
183
184
|
_market.incentiveSupplyToken = _market.symbol;
|
|
184
185
|
}
|
|
@@ -190,31 +191,42 @@ export function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
190
191
|
return;
|
|
191
192
|
const supplyRewardData = rewardForMarket.aIncentiveData.rewardsTokenInformation[0];
|
|
192
193
|
if (supplyRewardData) {
|
|
194
|
+
if (isStakingAsset && _market.incentiveSupplyToken !== supplyRewardData.rewardTokenSymbol)
|
|
195
|
+
return;
|
|
193
196
|
if (+supplyRewardData.emissionEndTimestamp * 1000 < Date.now())
|
|
194
197
|
return;
|
|
195
198
|
_market.incentiveSupplyToken = supplyRewardData.rewardTokenSymbol;
|
|
199
|
+
// reward token is aave asset
|
|
200
|
+
if (supplyRewardData.rewardTokenSymbol.startsWith('a') && supplyRewardData.rewardTokenSymbol.includes(_market.symbol))
|
|
201
|
+
_market.incentiveSupplyToken = _market.symbol;
|
|
196
202
|
const supplyEmissionPerSecond = supplyRewardData.emissionPerSecond;
|
|
197
203
|
const supplyRewardPrice = new Dec(supplyRewardData.rewardPriceFeed).div(Math.pow(10, +supplyRewardData.priceFeedDecimals)).toString();
|
|
198
|
-
|
|
204
|
+
const rewardApy = new Dec(supplyEmissionPerSecond).div((Math.pow(10, +supplyRewardData.rewardTokenDecimals)) / 100)
|
|
199
205
|
.mul(365 * 24 * 3600)
|
|
200
206
|
.mul(supplyRewardPrice)
|
|
201
207
|
.div(_market.price)
|
|
202
208
|
.div(_market.totalSupply)
|
|
203
209
|
.toString();
|
|
210
|
+
_market.incentiveSupplyApy = new Dec(_market.incentiveSupplyApy || '0').add(rewardApy).toString();
|
|
204
211
|
}
|
|
205
212
|
const borrowRewardData = rewardForMarket.vIncentiveData.rewardsTokenInformation[0];
|
|
206
213
|
if (borrowRewardData) {
|
|
214
|
+
if (isStakingAsset && _market.incentiveSupplyToken !== borrowRewardData.rewardTokenSymbol)
|
|
215
|
+
return;
|
|
207
216
|
if (+borrowRewardData.emissionEndTimestamp * 1000 < Date.now())
|
|
208
217
|
return;
|
|
209
218
|
_market.incentiveBorrowToken = borrowRewardData.rewardTokenSymbol;
|
|
219
|
+
if (supplyRewardData.rewardTokenSymbol.startsWith('a') && supplyRewardData.rewardTokenSymbol.includes(_market.symbol))
|
|
220
|
+
_market.incentiveBorrowToken = _market.symbol;
|
|
210
221
|
const supplyEmissionPerSecond = borrowRewardData.emissionPerSecond;
|
|
211
222
|
const supplyRewardPrice = new Dec(borrowRewardData.rewardPriceFeed).div(Math.pow(10, +borrowRewardData.priceFeedDecimals)).toString();
|
|
212
|
-
|
|
223
|
+
const rewardApy = new Dec(supplyEmissionPerSecond).div((Math.pow(10, +borrowRewardData.rewardTokenDecimals)) / 100)
|
|
213
224
|
.mul(365 * 24 * 3600)
|
|
214
225
|
.mul(supplyRewardPrice)
|
|
215
226
|
.div(_market.price)
|
|
216
227
|
.div(_market.totalBorrowVar)
|
|
217
228
|
.toString();
|
|
229
|
+
_market.incentiveBorrowApy = new Dec(_market.incentiveSupplyApy || '0').add(rewardApy).toString();
|
|
218
230
|
}
|
|
219
231
|
/* eslint-enable no-param-reassign */
|
|
220
232
|
})));
|
|
@@ -6,9 +6,7 @@ export const aaveV1AssetsDefaultMarket = [
|
|
|
6
6
|
].map((symbol) => getAssetInfo(symbol));
|
|
7
7
|
export const aaveV2AssetsDefaultMarket = ['USDT', 'WBTC', 'ETH', 'YFI', 'ZRX', 'UNI', 'AAVE', 'BAT', 'BUSD', 'DAI', 'ENJ', 'KNCL', 'LINK', 'MANA', 'MKR', 'REN', 'SNX', 'SUSD', 'TUSD', 'USDC', 'CRV', 'GUSD', 'BAL', 'xSUSHI', 'RENFIL', 'RAI', 'AMPL', 'USDP', 'DPI', 'FRAX', 'FEI', 'stETH', 'ENS', 'UST', 'CVX', '1INCH', 'LUSD'];
|
|
8
8
|
export const morphoAaveV2AssetDefaultMarket = ['DAI', 'ETH', 'USDC', 'USDT', 'WBTC', 'stETH', 'CRV'];
|
|
9
|
-
export const morphoAaveV3AssetEthMarket = [
|
|
10
|
-
'ETH', 'wstETH', 'USDC', 'WBTC', 'rETH', 'cbETH', 'USDT',
|
|
11
|
-
];
|
|
9
|
+
export const morphoAaveV3AssetEthMarket = ['ETH', 'wstETH', 'DAI', 'USDC', 'WBTC', 'rETH', 'cbETH', 'sDAI', 'USDT'];
|
|
12
10
|
export const aaveV3AssetsDefaultMarketEth = ['ETH', 'wstETH', 'WBTC', 'USDC', 'DAI', 'LINK', 'AAVE', 'cbETH', 'USDT', 'rETH', 'LUSD', 'CRV', 'MKR', 'SNX', 'BAL', 'UNI', 'LDO', 'ENS', '1INCH', 'FRAX', 'GHO', 'RPL', 'sDAI', 'STG', 'KNC', 'FXS', 'crvUSD', 'PYUSD', 'weETH', 'osETH', 'USDe', 'ETHx', 'sUSDe', 'tBTC', 'cbBTC', 'USDS'];
|
|
13
11
|
export const aaveV3AssetsDefaultMarketOpt = [
|
|
14
12
|
'DAI', 'USDC.e', 'USDT', 'SUSD', 'AAVE', 'LINK', 'WBTC', 'ETH', 'OP', 'wstETH', 'LUSD', 'MAI', 'rETH', 'USDC',
|
|
@@ -23,8 +23,8 @@ export const v3USDCeCollAssets = {
|
|
|
23
23
|
[NetworkNumber.Arb]: v3USDCeCollAssetsArb,
|
|
24
24
|
[NetworkNumber.Base]: [],
|
|
25
25
|
};
|
|
26
|
-
export const v3ETHCollAssetsEth = ['cbETH', 'wstETH', 'rETH', 'rsETH', 'weETH', 'osETH', 'WBTC', 'ezETH'];
|
|
27
|
-
export const v3ETHCollAssetsBase = ['cbETH', 'ezETH', 'USDC', '
|
|
26
|
+
export const v3ETHCollAssetsEth = ['cbETH', 'wstETH', 'rETH', 'rsETH', 'weETH', 'osETH', 'WBTC', 'ezETH', 'cbBTC', 'rswETH'];
|
|
27
|
+
export const v3ETHCollAssetsBase = ['cbETH', 'ezETH', 'wstETH', 'USDC', 'weETH', 'wrsETH', 'cbBTC'];
|
|
28
28
|
export const v3ETHCollAssetsArb = ['weETH', 'rETH', 'wstETH', 'WBTC', 'rsETH', 'ezETH', 'USDC', 'USDT'];
|
|
29
29
|
export const v3ETHCollAssetsOpt = ['rETH', 'wstETH', 'WBTC', 'ezETH', 'USDC', 'USDT', 'weETH', 'wrsETH'];
|
|
30
30
|
// @dev Keep assets in array, do not assign directly, so we can parse it and edit it programmatically with `scripts/updateMarkets`
|
|
@@ -67,4 +67,8 @@ export const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
|
67
67
|
leveragedAsset: '',
|
|
68
68
|
};
|
|
69
69
|
};
|
|
70
|
-
export const aprToApy = (interest, frequency = BLOCKS_IN_A_YEAR) => new Dec(interest).div(100).div(frequency).plus(1)
|
|
70
|
+
export const aprToApy = (interest, frequency = BLOCKS_IN_A_YEAR) => new Dec(interest).div(100).div(frequency).plus(1)
|
|
71
|
+
.pow(frequency)
|
|
72
|
+
.minus(1)
|
|
73
|
+
.times(100)
|
|
74
|
+
.toString();
|
package/package.json
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defisaver/positions-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.149",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
7
7
|
"types": "./esm/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build:esm": "rm -rf esm && tsc -p tsconfig.json",
|
|
10
|
-
"build:cjs": "rm -rf cjs && tsc -p tsconfig.
|
|
11
|
-
"build": "npm run generate-contracts && npm run build:cjs && npm run build:esm",
|
|
12
|
-
"dev": "npm run generate-contracts && tsc -p tsconfig.
|
|
9
|
+
"build:esm": "rm -rf esm && tsc -p tsconfig.esm.json",
|
|
10
|
+
"build:cjs": "rm -rf cjs && tsc -p tsconfig.json",
|
|
11
|
+
"build": "npm run lint && npm run generate-contracts && npm run build:cjs && npm run build:esm",
|
|
12
|
+
"dev": "npm run generate-contracts && tsc -p tsconfig.json --watch",
|
|
13
13
|
"lint": "eslint src/ --fix",
|
|
14
|
+
"lint-check": "eslint src/",
|
|
14
15
|
"generate-contracts": "node scripts/generateContracts.js",
|
|
15
16
|
"test": "mocha tests/*",
|
|
17
|
+
"test-single": "mocha ./tests/$npm_config_name.js",
|
|
16
18
|
"test:debugger": "mocha --inspect-brk tests/*",
|
|
17
|
-
"build-test": "npm run build &&
|
|
19
|
+
"build-test": "npm run build && npm run test"
|
|
18
20
|
},
|
|
19
21
|
"keywords": [],
|
|
20
22
|
"author": "",
|
|
@@ -31,6 +33,7 @@
|
|
|
31
33
|
"dotenv": "^16.3.1",
|
|
32
34
|
"eslint": "^8.49.0",
|
|
33
35
|
"mocha": "^10.2.0",
|
|
36
|
+
"ts-node": "^10.9.2",
|
|
34
37
|
"typechain": "^8.3.1",
|
|
35
38
|
"typechain-target-web3-v1-3mihai3": "^6.0.2",
|
|
36
39
|
"typescript": "^5.2.2"
|
package/src/aaveV3/index.ts
CHANGED
|
@@ -178,7 +178,7 @@ export async function getAaveV3MarketData(web3: Web3, network: NetworkNumber, ma
|
|
|
178
178
|
] = multiRes;
|
|
179
179
|
|
|
180
180
|
let rewardInfo: IUiIncentiveDataProviderV3.AggregatedReserveIncentiveDataStructOutput[] | null = null;
|
|
181
|
-
const networksWithIncentives = [NetworkNumber.Arb, NetworkNumber.Opt];
|
|
181
|
+
const networksWithIncentives = [NetworkNumber.Eth, NetworkNumber.Arb, NetworkNumber.Opt];
|
|
182
182
|
if (networksWithIncentives.includes(network)) {
|
|
183
183
|
rewardInfo = await aaveIncentivesContract.methods.getReservesIncentivesData(marketAddress).call();
|
|
184
184
|
rewardInfo = rewardInfo.reduce((all: any, _market: AaveV3IncentiveData) => {
|
|
@@ -279,7 +279,8 @@ export async function getAaveV3MarketData(web3: Web3, network: NetworkNumber, ma
|
|
|
279
279
|
await Promise.all(assetsData.map(async (_market: AaveV3AssetData) => {
|
|
280
280
|
/* eslint-disable no-param-reassign */
|
|
281
281
|
const rewardForMarket: IUiIncentiveDataProviderV3.AggregatedReserveIncentiveDataStructOutput | undefined = rewardInfo?.[_market.underlyingTokenAddress as any];
|
|
282
|
-
|
|
282
|
+
const isStakingAsset = STAKING_ASSETS.includes(_market.symbol);
|
|
283
|
+
if (isStakingAsset) {
|
|
283
284
|
_market.incentiveSupplyApy = await getStakingApy(_market.symbol, defaultWeb3);
|
|
284
285
|
_market.incentiveSupplyToken = _market.symbol;
|
|
285
286
|
}
|
|
@@ -292,29 +293,36 @@ export async function getAaveV3MarketData(web3: Web3, network: NetworkNumber, ma
|
|
|
292
293
|
if (!rewardForMarket) return;
|
|
293
294
|
const supplyRewardData = rewardForMarket.aIncentiveData.rewardsTokenInformation[0];
|
|
294
295
|
if (supplyRewardData) {
|
|
296
|
+
if (isStakingAsset && _market.incentiveSupplyToken !== supplyRewardData.rewardTokenSymbol) return;
|
|
295
297
|
if (+supplyRewardData.emissionEndTimestamp * 1000 < Date.now()) return;
|
|
296
298
|
_market.incentiveSupplyToken = supplyRewardData.rewardTokenSymbol;
|
|
299
|
+
// reward token is aave asset
|
|
300
|
+
if (supplyRewardData.rewardTokenSymbol.startsWith('a') && supplyRewardData.rewardTokenSymbol.includes(_market.symbol)) _market.incentiveSupplyToken = _market.symbol;
|
|
297
301
|
const supplyEmissionPerSecond = supplyRewardData.emissionPerSecond;
|
|
298
302
|
const supplyRewardPrice = new Dec(supplyRewardData.rewardPriceFeed).div(10 ** +supplyRewardData.priceFeedDecimals).toString();
|
|
299
|
-
|
|
303
|
+
const rewardApy = new Dec(supplyEmissionPerSecond).div((10 ** +supplyRewardData.rewardTokenDecimals) / 100)
|
|
300
304
|
.mul(365 * 24 * 3600)
|
|
301
305
|
.mul(supplyRewardPrice)
|
|
302
306
|
.div(_market.price)
|
|
303
307
|
.div(_market.totalSupply)
|
|
304
308
|
.toString();
|
|
309
|
+
_market.incentiveSupplyApy = new Dec(_market.incentiveSupplyApy || '0').add(rewardApy).toString();
|
|
305
310
|
}
|
|
306
311
|
const borrowRewardData = rewardForMarket.vIncentiveData.rewardsTokenInformation[0];
|
|
307
312
|
if (borrowRewardData) {
|
|
313
|
+
if (isStakingAsset && _market.incentiveSupplyToken !== borrowRewardData.rewardTokenSymbol) return;
|
|
308
314
|
if (+borrowRewardData.emissionEndTimestamp * 1000 < Date.now()) return;
|
|
309
315
|
_market.incentiveBorrowToken = borrowRewardData.rewardTokenSymbol;
|
|
316
|
+
if (supplyRewardData.rewardTokenSymbol.startsWith('a') && supplyRewardData.rewardTokenSymbol.includes(_market.symbol)) _market.incentiveBorrowToken = _market.symbol;
|
|
310
317
|
const supplyEmissionPerSecond = borrowRewardData.emissionPerSecond;
|
|
311
318
|
const supplyRewardPrice = new Dec(borrowRewardData.rewardPriceFeed).div(10 ** +borrowRewardData.priceFeedDecimals).toString();
|
|
312
|
-
|
|
319
|
+
const rewardApy = new Dec(supplyEmissionPerSecond).div((10 ** +borrowRewardData.rewardTokenDecimals) / 100)
|
|
313
320
|
.mul(365 * 24 * 3600)
|
|
314
321
|
.mul(supplyRewardPrice)
|
|
315
322
|
.div(_market.price)
|
|
316
323
|
.div(_market.totalBorrowVar)
|
|
317
324
|
.toString();
|
|
325
|
+
_market.incentiveBorrowApy = new Dec(_market.incentiveSupplyApy || '0').add(rewardApy).toString();
|
|
318
326
|
}
|
|
319
327
|
/* eslint-enable no-param-reassign */
|
|
320
328
|
}));
|
|
@@ -9,9 +9,7 @@ export const aaveV1AssetsDefaultMarket = [
|
|
|
9
9
|
export const aaveV2AssetsDefaultMarket = ['USDT', 'WBTC', 'ETH', 'YFI', 'ZRX', 'UNI', 'AAVE', 'BAT', 'BUSD', 'DAI', 'ENJ', 'KNCL', 'LINK', 'MANA', 'MKR', 'REN', 'SNX', 'SUSD', 'TUSD', 'USDC', 'CRV', 'GUSD', 'BAL', 'xSUSHI', 'RENFIL', 'RAI', 'AMPL', 'USDP', 'DPI', 'FRAX', 'FEI', 'stETH', 'ENS', 'UST', 'CVX', '1INCH', 'LUSD'];
|
|
10
10
|
export const morphoAaveV2AssetDefaultMarket = ['DAI', 'ETH', 'USDC', 'USDT', 'WBTC', 'stETH', 'CRV'];
|
|
11
11
|
|
|
12
|
-
export const morphoAaveV3AssetEthMarket = [
|
|
13
|
-
'ETH', 'wstETH', 'USDC', 'WBTC', 'rETH', 'cbETH', 'USDT',
|
|
14
|
-
];
|
|
12
|
+
export const morphoAaveV3AssetEthMarket = ['ETH', 'wstETH', 'DAI', 'USDC', 'WBTC', 'rETH', 'cbETH', 'sDAI', 'USDT'];
|
|
15
13
|
|
|
16
14
|
export const aaveV3AssetsDefaultMarketEth = ['ETH', 'wstETH', 'WBTC', 'USDC', 'DAI', 'LINK', 'AAVE', 'cbETH', 'USDT', 'rETH', 'LUSD', 'CRV', 'MKR', 'SNX', 'BAL', 'UNI', 'LDO', 'ENS', '1INCH', 'FRAX', 'GHO', 'RPL', 'sDAI', 'STG', 'KNC', 'FXS', 'crvUSD', 'PYUSD', 'weETH', 'osETH', 'USDe', 'ETHx', 'sUSDe', 'tBTC', 'cbBTC', 'USDS'];
|
|
17
15
|
export const aaveV3AssetsDefaultMarketOpt = [
|
|
@@ -29,8 +29,8 @@ export const v3USDCeCollAssets = {
|
|
|
29
29
|
[NetworkNumber.Base]: [],
|
|
30
30
|
} as const;
|
|
31
31
|
|
|
32
|
-
export const v3ETHCollAssetsEth = ['cbETH', 'wstETH', 'rETH', 'rsETH', 'weETH', 'osETH', 'WBTC', 'ezETH'];
|
|
33
|
-
export const v3ETHCollAssetsBase = ['cbETH', 'ezETH', 'USDC', '
|
|
32
|
+
export const v3ETHCollAssetsEth = ['cbETH', 'wstETH', 'rETH', 'rsETH', 'weETH', 'osETH', 'WBTC', 'ezETH', 'cbBTC', 'rswETH'];
|
|
33
|
+
export const v3ETHCollAssetsBase = ['cbETH', 'ezETH', 'wstETH', 'USDC', 'weETH', 'wrsETH', 'cbBTC'];
|
|
34
34
|
export const v3ETHCollAssetsArb = ['weETH', 'rETH', 'wstETH', 'WBTC', 'rsETH', 'ezETH', 'USDC', 'USDT'];
|
|
35
35
|
export const v3ETHCollAssetsOpt = ['rETH', 'wstETH', 'WBTC', 'ezETH', 'USDC', 'USDT', 'weETH', 'wrsETH'];
|
|
36
36
|
|
|
@@ -73,4 +73,8 @@ export const isLeveragedPos = (usedAssets: MMUsedAssets, dustLimit = 5) => {
|
|
|
73
73
|
};
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
-
export const aprToApy = (interest:string | number, frequency = BLOCKS_IN_A_YEAR) => new Dec(interest).div(100).div(frequency).plus(1)
|
|
76
|
+
export const aprToApy = (interest:string | number, frequency = BLOCKS_IN_A_YEAR) => new Dec(interest).div(100).div(frequency).plus(1)
|
|
77
|
+
.pow(frequency)
|
|
78
|
+
.minus(1)
|
|
79
|
+
.times(100)
|
|
80
|
+
.toString();
|