@defisaver/positions-sdk 0.0.201-fluid-dev-8 → 0.0.201-fluid-dev-10
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 -4
- package/.nvmrc +1 -1
- package/README.md +69 -69
- package/cjs/fluid/index.d.ts +25 -2
- package/cjs/fluid/index.js +1 -1
- package/cjs/helpers/morphoBlueHelpers/index.js +66 -66
- package/cjs/markets/fluid/index.js +11 -11
- package/esm/fluid/index.d.ts +25 -2
- package/esm/fluid/index.js +1 -1
- package/esm/helpers/morphoBlueHelpers/index.js +66 -66
- package/esm/markets/fluid/index.js +11 -11
- package/package.json +51 -51
- package/src/aaveV2/index.ts +227 -227
- package/src/aaveV3/index.ts +625 -625
- package/src/assets/index.ts +60 -60
- package/src/chickenBonds/index.ts +123 -123
- package/src/compoundV2/index.ts +220 -220
- package/src/compoundV3/index.ts +291 -291
- package/src/config/contracts.js +1122 -1122
- package/src/constants/index.ts +6 -6
- package/src/contracts.ts +134 -134
- package/src/curveUsd/index.ts +229 -229
- package/src/eulerV2/index.ts +303 -303
- package/src/exchange/index.ts +17 -17
- package/src/fluid/index.ts +343 -343
- package/src/helpers/aaveHelpers/index.ts +198 -198
- package/src/helpers/chickenBondsHelpers/index.ts +23 -23
- package/src/helpers/compoundHelpers/index.ts +246 -246
- package/src/helpers/curveUsdHelpers/index.ts +40 -40
- package/src/helpers/eulerHelpers/index.ts +232 -232
- package/src/helpers/fluidHelpers/index.ts +53 -53
- package/src/helpers/index.ts +11 -11
- package/src/helpers/liquityV2Helpers/index.ts +79 -79
- package/src/helpers/llamaLendHelpers/index.ts +53 -53
- package/src/helpers/makerHelpers/index.ts +94 -94
- package/src/helpers/morphoBlueHelpers/index.ts +365 -365
- package/src/helpers/sparkHelpers/index.ts +150 -150
- package/src/index.ts +52 -52
- package/src/liquity/index.ts +116 -116
- package/src/liquityV2/index.ts +227 -227
- package/src/llamaLend/index.ts +275 -275
- package/src/maker/index.ts +117 -117
- package/src/markets/aave/index.ts +152 -152
- package/src/markets/aave/marketAssets.ts +44 -44
- package/src/markets/compound/index.ts +213 -213
- package/src/markets/compound/marketsAssets.ts +82 -82
- package/src/markets/curveUsd/index.ts +69 -69
- package/src/markets/euler/index.ts +26 -26
- package/src/markets/fluid/index.ts +2010 -2010
- package/src/markets/index.ts +27 -27
- package/src/markets/liquityV2/index.ts +43 -43
- package/src/markets/llamaLend/contractAddresses.ts +141 -141
- package/src/markets/llamaLend/index.ts +235 -235
- package/src/markets/morphoBlue/index.ts +895 -895
- package/src/markets/spark/index.ts +29 -29
- package/src/markets/spark/marketAssets.ts +10 -10
- package/src/moneymarket/moneymarketCommonService.ts +80 -80
- package/src/morphoAaveV2/index.ts +256 -256
- package/src/morphoAaveV3/index.ts +631 -631
- package/src/morphoBlue/index.ts +202 -202
- package/src/multicall/index.ts +33 -33
- package/src/services/dsrService.ts +15 -15
- package/src/services/priceService.ts +91 -91
- package/src/services/utils.ts +59 -59
- package/src/setup.ts +8 -8
- package/src/spark/index.ts +461 -461
- package/src/staking/staking.ts +220 -220
- package/src/types/aave.ts +271 -271
- package/src/types/chickenBonds.ts +45 -45
- package/src/types/common.ts +84 -84
- package/src/types/compound.ts +131 -131
- package/src/types/curveUsd.ts +118 -118
- package/src/types/euler.ts +171 -171
- package/src/types/fluid.ts +264 -264
- package/src/types/index.ts +11 -11
- package/src/types/liquity.ts +30 -30
- package/src/types/liquityV2.ts +118 -118
- package/src/types/llamaLend.ts +155 -155
- package/src/types/maker.ts +50 -50
- package/src/types/morphoBlue.ts +192 -192
- package/src/types/spark.ts +131 -131
|
@@ -1188,7 +1188,7 @@ export const WBTC_USDC_12_ARB = (networkId = NetworkNumber.Eth) => ({
|
|
|
1188
1188
|
chainIds: [NetworkNumber.Arb],
|
|
1189
1189
|
label: 'WBTC / USDC Market 12',
|
|
1190
1190
|
shortLabel: 'WBTC/USDC',
|
|
1191
|
-
value: FluidArbitrumVersion.
|
|
1191
|
+
value: FluidArbitrumVersion.WBTC_USDC_12_ARB,
|
|
1192
1192
|
url: 'wbtc_usdc_12_arb',
|
|
1193
1193
|
marketAddress: '0xE16A6f5359ABB1f61cE71e25dD0932e3E00B00eB',
|
|
1194
1194
|
hasSmartCollateral: false,
|
|
@@ -1206,7 +1206,7 @@ export const WBTC_USDT_13_ARB = (networkId = NetworkNumber.Eth) => ({
|
|
|
1206
1206
|
chainIds: [NetworkNumber.Arb],
|
|
1207
1207
|
label: 'WBTC / USDT Market 13',
|
|
1208
1208
|
shortLabel: 'WBTC/USDT',
|
|
1209
|
-
value: FluidArbitrumVersion.
|
|
1209
|
+
value: FluidArbitrumVersion.WBTC_USDT_13_ARB,
|
|
1210
1210
|
url: 'wbtc_usdc_13_arb',
|
|
1211
1211
|
marketAddress: '0x82B27fA821419F5689381b565a8B0786aA2548De',
|
|
1212
1212
|
hasSmartCollateral: false,
|
|
@@ -1260,7 +1260,7 @@ export const WBTC_ETH_18_ARB = (networkId = NetworkNumber.Eth) => ({
|
|
|
1260
1260
|
chainIds: [NetworkNumber.Arb],
|
|
1261
1261
|
label: 'WBTC / ETH Market 18',
|
|
1262
1262
|
shortLabel: 'WBTC/ETH',
|
|
1263
|
-
value: FluidArbitrumVersion.
|
|
1263
|
+
value: FluidArbitrumVersion.WBTC_ETH_18_ARB,
|
|
1264
1264
|
url: 'wbtc_eth_18_arb',
|
|
1265
1265
|
marketAddress: '0xBc345229C1b52e4c30530C614BB487323BA38Da5',
|
|
1266
1266
|
hasSmartCollateral: false,
|
|
@@ -1278,7 +1278,7 @@ export const ETH_WBTC_19_ARB = (networkId = NetworkNumber.Eth) => ({
|
|
|
1278
1278
|
chainIds: [NetworkNumber.Arb],
|
|
1279
1279
|
label: 'ETH / WBTC Market 19',
|
|
1280
1280
|
shortLabel: 'ETH/WBTC',
|
|
1281
|
-
value: FluidArbitrumVersion.
|
|
1281
|
+
value: FluidArbitrumVersion.ETH_WBTC_19_ARB,
|
|
1282
1282
|
url: 'eth_wbtc_19_arb',
|
|
1283
1283
|
marketAddress: '0xF2c8F54447cbd591C396b0Dd7ac15FAF552d0FA4',
|
|
1284
1284
|
hasSmartCollateral: false,
|
|
@@ -1296,7 +1296,7 @@ export const WSTETH_WBTC_20_ARB = (networkId = NetworkNumber.Eth) => ({
|
|
|
1296
1296
|
chainIds: [NetworkNumber.Arb],
|
|
1297
1297
|
label: 'wstETH / WBTC Market 20',
|
|
1298
1298
|
shortLabel: 'wstETH/WBTC',
|
|
1299
|
-
value: FluidArbitrumVersion.
|
|
1299
|
+
value: FluidArbitrumVersion.WSTETH_WBTC_20_ARB,
|
|
1300
1300
|
url: 'wsteth_wbtc_20_arb',
|
|
1301
1301
|
marketAddress: '0x92643E964CA4b2c165a95CA919b0A819acA6D5F1',
|
|
1302
1302
|
hasSmartCollateral: false,
|
|
@@ -1314,7 +1314,7 @@ export const WEETH_WBTC_21_ARB = (networkId = NetworkNumber.Eth) => ({
|
|
|
1314
1314
|
chainIds: [NetworkNumber.Arb],
|
|
1315
1315
|
label: 'weETH / WBTC Market 21',
|
|
1316
1316
|
shortLabel: 'weETH/WBTC',
|
|
1317
|
-
value: FluidArbitrumVersion.
|
|
1317
|
+
value: FluidArbitrumVersion.WEETH_WBTC_21_ARB,
|
|
1318
1318
|
url: 'weeth_wbtc_21_arb',
|
|
1319
1319
|
marketAddress: '0x6F72895Cf6904489Bcd862c941c3D02a3eE4f03e',
|
|
1320
1320
|
hasSmartCollateral: false,
|
|
@@ -1332,7 +1332,7 @@ export const USDC_ETH_USDC_ETH_22_ARB = (networkId = NetworkNumber.Eth) => ({
|
|
|
1332
1332
|
chainIds: [NetworkNumber.Arb],
|
|
1333
1333
|
label: 'weETH / WBTC Market 22',
|
|
1334
1334
|
shortLabel: 'weETH/WBTC',
|
|
1335
|
-
value: FluidArbitrumVersion.
|
|
1335
|
+
value: FluidArbitrumVersion.USDC_ETH_USDC_ETH_22_ARB,
|
|
1336
1336
|
url: 'usdc_eth_usdc_eth_22_arb',
|
|
1337
1337
|
marketAddress: '0x3A0b7c8840D74D39552EF53F586dD8c3d1234C40',
|
|
1338
1338
|
hasSmartCollateral: false,
|
|
@@ -1350,7 +1350,7 @@ export const ETH_USDC_USDT_23_ARB = (networkId = NetworkNumber.Eth) => ({
|
|
|
1350
1350
|
chainIds: [NetworkNumber.Arb],
|
|
1351
1351
|
label: 'ETH / USDC-USDT Market 23',
|
|
1352
1352
|
shortLabel: 'ETH/USDC-USDT',
|
|
1353
|
-
value: FluidArbitrumVersion.
|
|
1353
|
+
value: FluidArbitrumVersion.ETH_USDC_USDT_23_ARB,
|
|
1354
1354
|
url: 'eth_usdc_usdt_23_arb',
|
|
1355
1355
|
marketAddress: '0xaD439b9D61b25af1ca4Cd211E3eCb9AfBaAEd84a',
|
|
1356
1356
|
hasSmartCollateral: false,
|
|
@@ -1368,7 +1368,7 @@ export const WSTETH_USDC_USDT_24_ARB = (networkId = NetworkNumber.Eth) => ({
|
|
|
1368
1368
|
chainIds: [NetworkNumber.Arb],
|
|
1369
1369
|
label: 'wstETH / USDC-USDT Market 23',
|
|
1370
1370
|
shortLabel: 'wstETH/USDC-USDT',
|
|
1371
|
-
value: FluidArbitrumVersion.
|
|
1371
|
+
value: FluidArbitrumVersion.WSTETH_USDC_USDT_24_ARB,
|
|
1372
1372
|
url: 'wsteth_usdc_usdt_23_arb',
|
|
1373
1373
|
marketAddress: '0x991416539E9DA46db233bCcbaEA38C4f852776D4',
|
|
1374
1374
|
hasSmartCollateral: false,
|
|
@@ -1386,7 +1386,7 @@ export const WEETH_USDC_USDT_25_ARB = (networkId = NetworkNumber.Eth) => ({
|
|
|
1386
1386
|
chainIds: [NetworkNumber.Arb],
|
|
1387
1387
|
label: 'weETH / USDC-USDT Market 25',
|
|
1388
1388
|
shortLabel: 'weETH/USDC-USDT',
|
|
1389
|
-
value: FluidArbitrumVersion.
|
|
1389
|
+
value: FluidArbitrumVersion.WEETH_USDC_USDT_25_ARB,
|
|
1390
1390
|
url: 'weeth_usdc_usdt_25_arb',
|
|
1391
1391
|
marketAddress: '0x03271C337c86a6Fd89625A2820e48621DC2a128b',
|
|
1392
1392
|
hasSmartCollateral: false,
|
|
@@ -1404,7 +1404,7 @@ export const WBTC_USDC_USDT_26_ARB = (networkId = NetworkNumber.Eth) => ({
|
|
|
1404
1404
|
chainIds: [NetworkNumber.Arb],
|
|
1405
1405
|
label: 'WBTC / USDC-USDT Market 26',
|
|
1406
1406
|
shortLabel: 'WBTC/USDC-USDT',
|
|
1407
|
-
value: FluidArbitrumVersion.
|
|
1407
|
+
value: FluidArbitrumVersion.WBTC_USDC_USDT_26_ARB,
|
|
1408
1408
|
url: 'wbtc_usdc_usdt_26_arb',
|
|
1409
1409
|
marketAddress: '0xF74cb9D69ada3559903149CFD60fD57cEAF95F30',
|
|
1410
1410
|
hasSmartCollateral: false,
|
package/package.json
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@defisaver/positions-sdk",
|
|
3
|
-
"version": "0.0.201-fluid-dev-
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "./cjs/index.js",
|
|
6
|
-
"module": "./esm/index.js",
|
|
7
|
-
"types": "./esm/index.d.ts",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"build:esm": "rm -rf esm && tsc -p tsconfig.esm.json",
|
|
10
|
-
"build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.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
|
-
"lint": "eslint src/ --fix",
|
|
14
|
-
"lint-check": "eslint src/",
|
|
15
|
-
"generate-contracts": "node scripts/generateContracts.js",
|
|
16
|
-
"test": "mocha tests/*",
|
|
17
|
-
"test-single": "mocha ./tests/$npm_config_name.ts",
|
|
18
|
-
"test:debugger": "mocha --inspect-brk tests/*",
|
|
19
|
-
"build-test": "npm run build && npm run test",
|
|
20
|
-
"version-bump": "git commit -am \"Version bump to $(npm version patch | cut -c 2-)\""
|
|
21
|
-
},
|
|
22
|
-
"keywords": [],
|
|
23
|
-
"author": "",
|
|
24
|
-
"license": "ISC",
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"@types/lodash": "^4.17.15",
|
|
27
|
-
"@defisaver/tokens": "^1.5.55",
|
|
28
|
-
"@ethersproject/bignumber": "^5.7.0",
|
|
29
|
-
"@morpho-org/morpho-aave-v3-sdk": "^1.5.3",
|
|
30
|
-
"decimal.js": "^10.4.3",
|
|
31
|
-
"lodash": "^4.17.21"
|
|
32
|
-
},
|
|
33
|
-
"devDependencies": {
|
|
34
|
-
"@defisaver/eslint-config": "^1.0.1",
|
|
35
|
-
"@types/chai": "^5.0.0",
|
|
36
|
-
"@types/mocha": "^10.0.9",
|
|
37
|
-
"@types/web3": "^1.0.20",
|
|
38
|
-
"chai": "^4.3.8",
|
|
39
|
-
"dotenv": "^16.3.1",
|
|
40
|
-
"eslint": "^8.49.0",
|
|
41
|
-
"eslint-plugin-import": "^2.31.0",
|
|
42
|
-
"mocha": "^10.2.0",
|
|
43
|
-
"ts-node": "^10.9.2",
|
|
44
|
-
"typechain": "^8.3.1",
|
|
45
|
-
"typechain-target-web3-v1-3mihai3": "^6.0.2",
|
|
46
|
-
"typescript": "^5.2.2"
|
|
47
|
-
},
|
|
48
|
-
"peerDependencies": {
|
|
49
|
-
"web3": "^1.10.2"
|
|
50
|
-
}
|
|
51
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@defisaver/positions-sdk",
|
|
3
|
+
"version": "0.0.201-fluid-dev-10",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./cjs/index.js",
|
|
6
|
+
"module": "./esm/index.js",
|
|
7
|
+
"types": "./esm/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build:esm": "rm -rf esm && tsc -p tsconfig.esm.json",
|
|
10
|
+
"build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.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
|
+
"lint": "eslint src/ --fix",
|
|
14
|
+
"lint-check": "eslint src/",
|
|
15
|
+
"generate-contracts": "node scripts/generateContracts.js",
|
|
16
|
+
"test": "mocha tests/*",
|
|
17
|
+
"test-single": "mocha ./tests/$npm_config_name.ts",
|
|
18
|
+
"test:debugger": "mocha --inspect-brk tests/*",
|
|
19
|
+
"build-test": "npm run build && npm run test",
|
|
20
|
+
"version-bump": "git commit -am \"Version bump to $(npm version patch | cut -c 2-)\""
|
|
21
|
+
},
|
|
22
|
+
"keywords": [],
|
|
23
|
+
"author": "",
|
|
24
|
+
"license": "ISC",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@types/lodash": "^4.17.15",
|
|
27
|
+
"@defisaver/tokens": "^1.5.55",
|
|
28
|
+
"@ethersproject/bignumber": "^5.7.0",
|
|
29
|
+
"@morpho-org/morpho-aave-v3-sdk": "^1.5.3",
|
|
30
|
+
"decimal.js": "^10.4.3",
|
|
31
|
+
"lodash": "^4.17.21"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@defisaver/eslint-config": "^1.0.1",
|
|
35
|
+
"@types/chai": "^5.0.0",
|
|
36
|
+
"@types/mocha": "^10.0.9",
|
|
37
|
+
"@types/web3": "^1.0.20",
|
|
38
|
+
"chai": "^4.3.8",
|
|
39
|
+
"dotenv": "^16.3.1",
|
|
40
|
+
"eslint": "^8.49.0",
|
|
41
|
+
"eslint-plugin-import": "^2.31.0",
|
|
42
|
+
"mocha": "^10.2.0",
|
|
43
|
+
"ts-node": "^10.9.2",
|
|
44
|
+
"typechain": "^8.3.1",
|
|
45
|
+
"typechain-target-web3-v1-3mihai3": "^6.0.2",
|
|
46
|
+
"typescript": "^5.2.2"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"web3": "^1.10.2"
|
|
50
|
+
}
|
|
51
|
+
}
|
package/src/aaveV2/index.ts
CHANGED
|
@@ -1,227 +1,227 @@
|
|
|
1
|
-
import Web3 from 'web3';
|
|
2
|
-
import Dec from 'decimal.js';
|
|
3
|
-
import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
|
|
4
|
-
import {
|
|
5
|
-
Blockish, EthAddress, NetworkNumber, PositionBalances,
|
|
6
|
-
} from '../types/common';
|
|
7
|
-
import { calculateNetApy, getStETHApy } from '../staking';
|
|
8
|
-
import { ethToWeth, wethToEth, wethToEthByAddress } from '../services/utils';
|
|
9
|
-
import { AaveLoanInfoV2Contract, createContractWrapper } from '../contracts';
|
|
10
|
-
import { aprToApy, calculateBorrowingAssetLimit } from '../moneymarket';
|
|
11
|
-
import {
|
|
12
|
-
AaveMarketInfo, AaveV2AssetData, AaveV2AssetsData, AaveV2PositionData, AaveV2UsedAsset, AaveV2UsedAssets,
|
|
13
|
-
} from '../types';
|
|
14
|
-
import { EMPTY_AAVE_DATA } from '../aaveV3';
|
|
15
|
-
import { AAVE_V2 } from '../markets/aave';
|
|
16
|
-
import { aaveAnyGetAggregatedPositionData } from '../helpers/aaveHelpers';
|
|
17
|
-
import { getEthPrice } from '../services/priceService';
|
|
18
|
-
|
|
19
|
-
export const getAaveV2MarketsData = async (web3: Web3, network: NetworkNumber, selectedMarket: AaveMarketInfo, mainnetWeb3: Web3) => {
|
|
20
|
-
const ethPrice = await getEthPrice(web3);
|
|
21
|
-
const _addresses = selectedMarket.assets.map(a => getAssetInfo(ethToWeth(a)).address);
|
|
22
|
-
const loanInfoContract = AaveLoanInfoV2Contract(web3, network);
|
|
23
|
-
const marketAddress = selectedMarket.providerAddress;
|
|
24
|
-
const loanInfo = await loanInfoContract.methods.getFullTokensInfo(marketAddress, _addresses).call();
|
|
25
|
-
const markets = loanInfo
|
|
26
|
-
.map((market, i) => ({
|
|
27
|
-
symbol: selectedMarket.assets[i],
|
|
28
|
-
underlyingTokenAddress: market.underlyingTokenAddress,
|
|
29
|
-
supplyRate: aprToApy(new Dec(market.supplyRate.toString()).div(1e25).toString()),
|
|
30
|
-
borrowRate: aprToApy(new Dec(market.borrowRateVariable.toString()).div(1e25).toString()),
|
|
31
|
-
borrowRateStable: aprToApy(new Dec(market.borrowRateStable.toString()).div(1e25).toString()),
|
|
32
|
-
collateralFactor: new Dec(market.collateralFactor.toString()).div(10000).toString(),
|
|
33
|
-
liquidationRatio: new Dec(market.liquidationRatio.toString()).div(10000).toString(),
|
|
34
|
-
marketLiquidity: assetAmountInEth(new Dec(market.totalSupply.toString())
|
|
35
|
-
.sub(market.totalBorrow.toString())
|
|
36
|
-
.toString(), selectedMarket.assets[i]),
|
|
37
|
-
utilization: new Dec(market.totalBorrow.toString())
|
|
38
|
-
.div(new Dec(market.totalSupply.toString()))
|
|
39
|
-
.times(100)
|
|
40
|
-
.toString(),
|
|
41
|
-
usageAsCollateralEnabled: market.usageAsCollateralEnabled,
|
|
42
|
-
supplyCap: '0',
|
|
43
|
-
borrowCap: '0', // v2 doesnt have borrow cap but adding it for compatability with v3
|
|
44
|
-
totalSupply: assetAmountInEth(market.totalSupply.toString(), selectedMarket.assets[i]),
|
|
45
|
-
isInactive: !market.isActive,
|
|
46
|
-
isFrozen: market.isFrozen,
|
|
47
|
-
canBeBorrowed: market.isActive && market.borrowingEnabled && !market.isFrozen,
|
|
48
|
-
canBeSupplied: market.isActive && !market.isFrozen,
|
|
49
|
-
canBeWithdrawn: market.isActive,
|
|
50
|
-
canBePayBacked: market.isActive,
|
|
51
|
-
disabledStableBorrowing: !market.stableBorrowRateEnabled,
|
|
52
|
-
totalBorrow: assetAmountInEth(market.totalBorrow.toString(), selectedMarket.assets[i]),
|
|
53
|
-
totalBorrowVar: assetAmountInEth(market.totalBorrowVar.toString(), selectedMarket.assets[i]),
|
|
54
|
-
priceInEth: new Dec(market.price.toString()).div(1e18).toString(),
|
|
55
|
-
incentiveSupplyToken: 'AAVE',
|
|
56
|
-
incentiveBorrowToken: 'AAVE',
|
|
57
|
-
incentiveSupplyApy: '0',
|
|
58
|
-
price: new Dec(market.price.toString()).div(1e18).mul(ethPrice).toString(),
|
|
59
|
-
}));
|
|
60
|
-
|
|
61
|
-
const stEthMarket = markets.find(({ symbol }) => symbol === 'stETH');
|
|
62
|
-
if (stEthMarket) {
|
|
63
|
-
stEthMarket.incentiveSupplyApy = await getStETHApy(mainnetWeb3);
|
|
64
|
-
stEthMarket.incentiveSupplyToken = 'stETH';
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const payload: AaveV2AssetsData = {};
|
|
68
|
-
// Sort by market size
|
|
69
|
-
markets
|
|
70
|
-
.sort((a, b) => {
|
|
71
|
-
const aMarket = new Dec(a.price).times(a.totalSupply).toString();
|
|
72
|
-
const bMarket = new Dec(b.price).times(b.totalSupply).toString();
|
|
73
|
-
|
|
74
|
-
return new Dec(bMarket).minus(aMarket).toNumber();
|
|
75
|
-
})
|
|
76
|
-
.forEach((assetData: AaveV2AssetData, i) => {
|
|
77
|
-
payload[assetData.symbol] = { ...assetData, sortIndex: i };
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
return { assetsData: payload };
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export const getAaveV2AccountBalances = async (web3: Web3, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress): Promise<PositionBalances> => {
|
|
84
|
-
let balances: PositionBalances = {
|
|
85
|
-
collateral: {},
|
|
86
|
-
debt: {},
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
if (!address) {
|
|
90
|
-
return balances;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const market = AAVE_V2;
|
|
94
|
-
|
|
95
|
-
const loanInfoContract = AaveLoanInfoV2Contract(web3, network, block);
|
|
96
|
-
|
|
97
|
-
const marketAddress = market.providerAddress;
|
|
98
|
-
// @ts-ignore
|
|
99
|
-
const protocolDataProviderContract = createContractWrapper(web3, network, market.protocolData, market.protocolDataAddress);
|
|
100
|
-
|
|
101
|
-
const reserveTokens = await protocolDataProviderContract.methods.getAllReservesTokens().call({}, block);
|
|
102
|
-
const symbols = reserveTokens.map(({ symbol }: { symbol: string }) => symbol);
|
|
103
|
-
const _addresses = reserveTokens.map(({ tokenAddress }: { tokenAddress: EthAddress }) => tokenAddress);
|
|
104
|
-
|
|
105
|
-
const loanInfo = await loanInfoContract.methods.getTokenBalances(marketAddress, address, _addresses).call({}, block);
|
|
106
|
-
|
|
107
|
-
loanInfo.forEach((_tokenInfo: any, i: number) => {
|
|
108
|
-
const asset = wethToEth(symbols[i]);
|
|
109
|
-
const assetAddr = wethToEthByAddress(_addresses[i], network).toLowerCase();
|
|
110
|
-
const tokenInfo = { ..._tokenInfo };
|
|
111
|
-
|
|
112
|
-
// known bug: stETH leaves 1 wei on every transfer
|
|
113
|
-
if (asset === 'stETH' && tokenInfo.balance.toString() === '1') {
|
|
114
|
-
tokenInfo.balance = '0';
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
balances = {
|
|
118
|
-
collateral: {
|
|
119
|
-
...balances.collateral,
|
|
120
|
-
[addressMapping ? assetAddr : asset]: tokenInfo.balance.toString(),
|
|
121
|
-
},
|
|
122
|
-
debt: {
|
|
123
|
-
...balances.debt,
|
|
124
|
-
[addressMapping ? assetAddr : asset]: new Dec(tokenInfo.borrowsStable.toString()).add(tokenInfo.borrowsVariable.toString()).toString(),
|
|
125
|
-
},
|
|
126
|
-
};
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
return balances;
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
export const getAaveV2AccountData = async (web3: Web3, network: NetworkNumber, address: string, assetsData: AaveV2AssetsData, market: AaveMarketInfo): Promise<AaveV2PositionData> => {
|
|
133
|
-
if (!address) throw new Error('Address is required');
|
|
134
|
-
|
|
135
|
-
let payload: AaveV2PositionData = {
|
|
136
|
-
...EMPTY_AAVE_DATA,
|
|
137
|
-
lastUpdated: Date.now(),
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const loanInfoContract = AaveLoanInfoV2Contract(web3, network);
|
|
141
|
-
const marketAddress = market.providerAddress;
|
|
142
|
-
const _addresses = market.assets.map(a => getAssetInfo(ethToWeth(a)).address);
|
|
143
|
-
const loanInfo = await loanInfoContract.methods.getTokenBalances(marketAddress, address, _addresses).call();
|
|
144
|
-
const usedAssets = {} as AaveV2UsedAssets;
|
|
145
|
-
loanInfo.forEach((_tokenInfo, i) => {
|
|
146
|
-
const asset = market.assets[i];
|
|
147
|
-
const tokenInfo = { ..._tokenInfo };
|
|
148
|
-
|
|
149
|
-
// known bug: stETH leaves 1 wei on every transfer
|
|
150
|
-
if (asset === 'stETH' && tokenInfo.balance.toString() === '1') tokenInfo.balance = '0';
|
|
151
|
-
|
|
152
|
-
const isSupplied = tokenInfo.balance.toString() !== '0';
|
|
153
|
-
const isBorrowed = tokenInfo.borrowsStable.toString() !== '0' || tokenInfo.borrowsVariable.toString() !== '0';
|
|
154
|
-
if (!isSupplied && !isBorrowed) return;
|
|
155
|
-
|
|
156
|
-
const supplied = assetAmountInEth(tokenInfo.balance.toString(), asset);
|
|
157
|
-
const borrowedStable = assetAmountInEth(tokenInfo.borrowsStable.toString(), asset);
|
|
158
|
-
const borrowedVariable = assetAmountInEth(tokenInfo.borrowsVariable.toString(), asset);
|
|
159
|
-
const enabledAsCollateral = assetsData[asset].usageAsCollateralEnabled ? tokenInfo.enabledAsCollateral : false;
|
|
160
|
-
let interestMode;
|
|
161
|
-
if (borrowedVariable === '0' && borrowedStable !== '0') {
|
|
162
|
-
interestMode = '1';
|
|
163
|
-
} else if (borrowedVariable !== '0' && borrowedStable === '0') {
|
|
164
|
-
interestMode = '2';
|
|
165
|
-
} else {
|
|
166
|
-
interestMode = 'both';
|
|
167
|
-
}
|
|
168
|
-
if (!usedAssets[asset]) usedAssets[asset] = {} as AaveV2UsedAsset;
|
|
169
|
-
usedAssets[asset] = {
|
|
170
|
-
...usedAssets[asset],
|
|
171
|
-
symbol: asset,
|
|
172
|
-
supplied,
|
|
173
|
-
suppliedUsd: new Dec(supplied).mul(assetsData[asset].price).toString(),
|
|
174
|
-
isSupplied,
|
|
175
|
-
collateral: enabledAsCollateral,
|
|
176
|
-
stableBorrowRate: aprToApy(new Dec(tokenInfo.stableBorrowRate).div(1e25).toString()),
|
|
177
|
-
borrowedStable,
|
|
178
|
-
borrowedVariable,
|
|
179
|
-
borrowedUsdStable: new Dec(borrowedStable).mul(assetsData[asset].price).toString(),
|
|
180
|
-
borrowedUsdVariable: new Dec(borrowedVariable).mul(assetsData[asset].price).toString(),
|
|
181
|
-
borrowed: new Dec(borrowedStable).add(borrowedVariable).toString(),
|
|
182
|
-
borrowedUsd: new Dec(new Dec(borrowedVariable).add(borrowedStable)).mul(assetsData[asset].price).toString(),
|
|
183
|
-
isBorrowed,
|
|
184
|
-
interestMode,
|
|
185
|
-
};
|
|
186
|
-
});
|
|
187
|
-
payload = {
|
|
188
|
-
...payload,
|
|
189
|
-
usedAssets,
|
|
190
|
-
...aaveAnyGetAggregatedPositionData({
|
|
191
|
-
usedAssets, assetsData, eModeCategory: 0, selectedMarket: market,
|
|
192
|
-
}),
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
payload.ratio = payload.borrowedUsd && payload.borrowedUsd !== '0'
|
|
196
|
-
? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString()
|
|
197
|
-
: '0';
|
|
198
|
-
payload.minRatio = '100';
|
|
199
|
-
payload.collRatio = payload.borrowedUsd && payload.borrowedUsd !== '0'
|
|
200
|
-
? new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString()
|
|
201
|
-
: '0';
|
|
202
|
-
|
|
203
|
-
// Calculate borrow limits per asset
|
|
204
|
-
Object.values(payload.usedAssets).forEach((item) => {
|
|
205
|
-
if (item.isBorrowed) {
|
|
206
|
-
// eslint-disable-next-line no-param-reassign
|
|
207
|
-
item.stableLimit = calculateBorrowingAssetLimit(item.borrowedUsdStable, payload.borrowLimitUsd);
|
|
208
|
-
// eslint-disable-next-line no-param-reassign
|
|
209
|
-
item.variableLimit = calculateBorrowingAssetLimit(item.borrowedUsdVariable, payload.borrowLimitUsd);
|
|
210
|
-
// eslint-disable-next-line no-param-reassign
|
|
211
|
-
item.limit = calculateBorrowingAssetLimit(item.borrowedUsd, payload.borrowLimitUsd);
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
const { netApy, incentiveUsd, totalInterestUsd } = calculateNetApy({ usedAssets, assetsData });
|
|
216
|
-
payload.netApy = netApy;
|
|
217
|
-
payload.incentiveUsd = incentiveUsd;
|
|
218
|
-
payload.totalInterestUsd = totalInterestUsd;
|
|
219
|
-
|
|
220
|
-
return payload;
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
export const getAaveV2FullPositionData = async (web3: Web3, network: NetworkNumber, address: string, market: AaveMarketInfo, mainnetWeb3: Web3): Promise<AaveV2PositionData> => {
|
|
224
|
-
const marketData = await getAaveV2MarketsData(web3, network, market, mainnetWeb3);
|
|
225
|
-
const positionData = await getAaveV2AccountData(web3, network, address, marketData.assetsData, market);
|
|
226
|
-
return positionData;
|
|
227
|
-
};
|
|
1
|
+
import Web3 from 'web3';
|
|
2
|
+
import Dec from 'decimal.js';
|
|
3
|
+
import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
|
|
4
|
+
import {
|
|
5
|
+
Blockish, EthAddress, NetworkNumber, PositionBalances,
|
|
6
|
+
} from '../types/common';
|
|
7
|
+
import { calculateNetApy, getStETHApy } from '../staking';
|
|
8
|
+
import { ethToWeth, wethToEth, wethToEthByAddress } from '../services/utils';
|
|
9
|
+
import { AaveLoanInfoV2Contract, createContractWrapper } from '../contracts';
|
|
10
|
+
import { aprToApy, calculateBorrowingAssetLimit } from '../moneymarket';
|
|
11
|
+
import {
|
|
12
|
+
AaveMarketInfo, AaveV2AssetData, AaveV2AssetsData, AaveV2PositionData, AaveV2UsedAsset, AaveV2UsedAssets,
|
|
13
|
+
} from '../types';
|
|
14
|
+
import { EMPTY_AAVE_DATA } from '../aaveV3';
|
|
15
|
+
import { AAVE_V2 } from '../markets/aave';
|
|
16
|
+
import { aaveAnyGetAggregatedPositionData } from '../helpers/aaveHelpers';
|
|
17
|
+
import { getEthPrice } from '../services/priceService';
|
|
18
|
+
|
|
19
|
+
export const getAaveV2MarketsData = async (web3: Web3, network: NetworkNumber, selectedMarket: AaveMarketInfo, mainnetWeb3: Web3) => {
|
|
20
|
+
const ethPrice = await getEthPrice(web3);
|
|
21
|
+
const _addresses = selectedMarket.assets.map(a => getAssetInfo(ethToWeth(a)).address);
|
|
22
|
+
const loanInfoContract = AaveLoanInfoV2Contract(web3, network);
|
|
23
|
+
const marketAddress = selectedMarket.providerAddress;
|
|
24
|
+
const loanInfo = await loanInfoContract.methods.getFullTokensInfo(marketAddress, _addresses).call();
|
|
25
|
+
const markets = loanInfo
|
|
26
|
+
.map((market, i) => ({
|
|
27
|
+
symbol: selectedMarket.assets[i],
|
|
28
|
+
underlyingTokenAddress: market.underlyingTokenAddress,
|
|
29
|
+
supplyRate: aprToApy(new Dec(market.supplyRate.toString()).div(1e25).toString()),
|
|
30
|
+
borrowRate: aprToApy(new Dec(market.borrowRateVariable.toString()).div(1e25).toString()),
|
|
31
|
+
borrowRateStable: aprToApy(new Dec(market.borrowRateStable.toString()).div(1e25).toString()),
|
|
32
|
+
collateralFactor: new Dec(market.collateralFactor.toString()).div(10000).toString(),
|
|
33
|
+
liquidationRatio: new Dec(market.liquidationRatio.toString()).div(10000).toString(),
|
|
34
|
+
marketLiquidity: assetAmountInEth(new Dec(market.totalSupply.toString())
|
|
35
|
+
.sub(market.totalBorrow.toString())
|
|
36
|
+
.toString(), selectedMarket.assets[i]),
|
|
37
|
+
utilization: new Dec(market.totalBorrow.toString())
|
|
38
|
+
.div(new Dec(market.totalSupply.toString()))
|
|
39
|
+
.times(100)
|
|
40
|
+
.toString(),
|
|
41
|
+
usageAsCollateralEnabled: market.usageAsCollateralEnabled,
|
|
42
|
+
supplyCap: '0',
|
|
43
|
+
borrowCap: '0', // v2 doesnt have borrow cap but adding it for compatability with v3
|
|
44
|
+
totalSupply: assetAmountInEth(market.totalSupply.toString(), selectedMarket.assets[i]),
|
|
45
|
+
isInactive: !market.isActive,
|
|
46
|
+
isFrozen: market.isFrozen,
|
|
47
|
+
canBeBorrowed: market.isActive && market.borrowingEnabled && !market.isFrozen,
|
|
48
|
+
canBeSupplied: market.isActive && !market.isFrozen,
|
|
49
|
+
canBeWithdrawn: market.isActive,
|
|
50
|
+
canBePayBacked: market.isActive,
|
|
51
|
+
disabledStableBorrowing: !market.stableBorrowRateEnabled,
|
|
52
|
+
totalBorrow: assetAmountInEth(market.totalBorrow.toString(), selectedMarket.assets[i]),
|
|
53
|
+
totalBorrowVar: assetAmountInEth(market.totalBorrowVar.toString(), selectedMarket.assets[i]),
|
|
54
|
+
priceInEth: new Dec(market.price.toString()).div(1e18).toString(),
|
|
55
|
+
incentiveSupplyToken: 'AAVE',
|
|
56
|
+
incentiveBorrowToken: 'AAVE',
|
|
57
|
+
incentiveSupplyApy: '0',
|
|
58
|
+
price: new Dec(market.price.toString()).div(1e18).mul(ethPrice).toString(),
|
|
59
|
+
}));
|
|
60
|
+
|
|
61
|
+
const stEthMarket = markets.find(({ symbol }) => symbol === 'stETH');
|
|
62
|
+
if (stEthMarket) {
|
|
63
|
+
stEthMarket.incentiveSupplyApy = await getStETHApy(mainnetWeb3);
|
|
64
|
+
stEthMarket.incentiveSupplyToken = 'stETH';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const payload: AaveV2AssetsData = {};
|
|
68
|
+
// Sort by market size
|
|
69
|
+
markets
|
|
70
|
+
.sort((a, b) => {
|
|
71
|
+
const aMarket = new Dec(a.price).times(a.totalSupply).toString();
|
|
72
|
+
const bMarket = new Dec(b.price).times(b.totalSupply).toString();
|
|
73
|
+
|
|
74
|
+
return new Dec(bMarket).minus(aMarket).toNumber();
|
|
75
|
+
})
|
|
76
|
+
.forEach((assetData: AaveV2AssetData, i) => {
|
|
77
|
+
payload[assetData.symbol] = { ...assetData, sortIndex: i };
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return { assetsData: payload };
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const getAaveV2AccountBalances = async (web3: Web3, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress): Promise<PositionBalances> => {
|
|
84
|
+
let balances: PositionBalances = {
|
|
85
|
+
collateral: {},
|
|
86
|
+
debt: {},
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
if (!address) {
|
|
90
|
+
return balances;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const market = AAVE_V2;
|
|
94
|
+
|
|
95
|
+
const loanInfoContract = AaveLoanInfoV2Contract(web3, network, block);
|
|
96
|
+
|
|
97
|
+
const marketAddress = market.providerAddress;
|
|
98
|
+
// @ts-ignore
|
|
99
|
+
const protocolDataProviderContract = createContractWrapper(web3, network, market.protocolData, market.protocolDataAddress);
|
|
100
|
+
|
|
101
|
+
const reserveTokens = await protocolDataProviderContract.methods.getAllReservesTokens().call({}, block);
|
|
102
|
+
const symbols = reserveTokens.map(({ symbol }: { symbol: string }) => symbol);
|
|
103
|
+
const _addresses = reserveTokens.map(({ tokenAddress }: { tokenAddress: EthAddress }) => tokenAddress);
|
|
104
|
+
|
|
105
|
+
const loanInfo = await loanInfoContract.methods.getTokenBalances(marketAddress, address, _addresses).call({}, block);
|
|
106
|
+
|
|
107
|
+
loanInfo.forEach((_tokenInfo: any, i: number) => {
|
|
108
|
+
const asset = wethToEth(symbols[i]);
|
|
109
|
+
const assetAddr = wethToEthByAddress(_addresses[i], network).toLowerCase();
|
|
110
|
+
const tokenInfo = { ..._tokenInfo };
|
|
111
|
+
|
|
112
|
+
// known bug: stETH leaves 1 wei on every transfer
|
|
113
|
+
if (asset === 'stETH' && tokenInfo.balance.toString() === '1') {
|
|
114
|
+
tokenInfo.balance = '0';
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
balances = {
|
|
118
|
+
collateral: {
|
|
119
|
+
...balances.collateral,
|
|
120
|
+
[addressMapping ? assetAddr : asset]: tokenInfo.balance.toString(),
|
|
121
|
+
},
|
|
122
|
+
debt: {
|
|
123
|
+
...balances.debt,
|
|
124
|
+
[addressMapping ? assetAddr : asset]: new Dec(tokenInfo.borrowsStable.toString()).add(tokenInfo.borrowsVariable.toString()).toString(),
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
return balances;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export const getAaveV2AccountData = async (web3: Web3, network: NetworkNumber, address: string, assetsData: AaveV2AssetsData, market: AaveMarketInfo): Promise<AaveV2PositionData> => {
|
|
133
|
+
if (!address) throw new Error('Address is required');
|
|
134
|
+
|
|
135
|
+
let payload: AaveV2PositionData = {
|
|
136
|
+
...EMPTY_AAVE_DATA,
|
|
137
|
+
lastUpdated: Date.now(),
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const loanInfoContract = AaveLoanInfoV2Contract(web3, network);
|
|
141
|
+
const marketAddress = market.providerAddress;
|
|
142
|
+
const _addresses = market.assets.map(a => getAssetInfo(ethToWeth(a)).address);
|
|
143
|
+
const loanInfo = await loanInfoContract.methods.getTokenBalances(marketAddress, address, _addresses).call();
|
|
144
|
+
const usedAssets = {} as AaveV2UsedAssets;
|
|
145
|
+
loanInfo.forEach((_tokenInfo, i) => {
|
|
146
|
+
const asset = market.assets[i];
|
|
147
|
+
const tokenInfo = { ..._tokenInfo };
|
|
148
|
+
|
|
149
|
+
// known bug: stETH leaves 1 wei on every transfer
|
|
150
|
+
if (asset === 'stETH' && tokenInfo.balance.toString() === '1') tokenInfo.balance = '0';
|
|
151
|
+
|
|
152
|
+
const isSupplied = tokenInfo.balance.toString() !== '0';
|
|
153
|
+
const isBorrowed = tokenInfo.borrowsStable.toString() !== '0' || tokenInfo.borrowsVariable.toString() !== '0';
|
|
154
|
+
if (!isSupplied && !isBorrowed) return;
|
|
155
|
+
|
|
156
|
+
const supplied = assetAmountInEth(tokenInfo.balance.toString(), asset);
|
|
157
|
+
const borrowedStable = assetAmountInEth(tokenInfo.borrowsStable.toString(), asset);
|
|
158
|
+
const borrowedVariable = assetAmountInEth(tokenInfo.borrowsVariable.toString(), asset);
|
|
159
|
+
const enabledAsCollateral = assetsData[asset].usageAsCollateralEnabled ? tokenInfo.enabledAsCollateral : false;
|
|
160
|
+
let interestMode;
|
|
161
|
+
if (borrowedVariable === '0' && borrowedStable !== '0') {
|
|
162
|
+
interestMode = '1';
|
|
163
|
+
} else if (borrowedVariable !== '0' && borrowedStable === '0') {
|
|
164
|
+
interestMode = '2';
|
|
165
|
+
} else {
|
|
166
|
+
interestMode = 'both';
|
|
167
|
+
}
|
|
168
|
+
if (!usedAssets[asset]) usedAssets[asset] = {} as AaveV2UsedAsset;
|
|
169
|
+
usedAssets[asset] = {
|
|
170
|
+
...usedAssets[asset],
|
|
171
|
+
symbol: asset,
|
|
172
|
+
supplied,
|
|
173
|
+
suppliedUsd: new Dec(supplied).mul(assetsData[asset].price).toString(),
|
|
174
|
+
isSupplied,
|
|
175
|
+
collateral: enabledAsCollateral,
|
|
176
|
+
stableBorrowRate: aprToApy(new Dec(tokenInfo.stableBorrowRate).div(1e25).toString()),
|
|
177
|
+
borrowedStable,
|
|
178
|
+
borrowedVariable,
|
|
179
|
+
borrowedUsdStable: new Dec(borrowedStable).mul(assetsData[asset].price).toString(),
|
|
180
|
+
borrowedUsdVariable: new Dec(borrowedVariable).mul(assetsData[asset].price).toString(),
|
|
181
|
+
borrowed: new Dec(borrowedStable).add(borrowedVariable).toString(),
|
|
182
|
+
borrowedUsd: new Dec(new Dec(borrowedVariable).add(borrowedStable)).mul(assetsData[asset].price).toString(),
|
|
183
|
+
isBorrowed,
|
|
184
|
+
interestMode,
|
|
185
|
+
};
|
|
186
|
+
});
|
|
187
|
+
payload = {
|
|
188
|
+
...payload,
|
|
189
|
+
usedAssets,
|
|
190
|
+
...aaveAnyGetAggregatedPositionData({
|
|
191
|
+
usedAssets, assetsData, eModeCategory: 0, selectedMarket: market,
|
|
192
|
+
}),
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
payload.ratio = payload.borrowedUsd && payload.borrowedUsd !== '0'
|
|
196
|
+
? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString()
|
|
197
|
+
: '0';
|
|
198
|
+
payload.minRatio = '100';
|
|
199
|
+
payload.collRatio = payload.borrowedUsd && payload.borrowedUsd !== '0'
|
|
200
|
+
? new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString()
|
|
201
|
+
: '0';
|
|
202
|
+
|
|
203
|
+
// Calculate borrow limits per asset
|
|
204
|
+
Object.values(payload.usedAssets).forEach((item) => {
|
|
205
|
+
if (item.isBorrowed) {
|
|
206
|
+
// eslint-disable-next-line no-param-reassign
|
|
207
|
+
item.stableLimit = calculateBorrowingAssetLimit(item.borrowedUsdStable, payload.borrowLimitUsd);
|
|
208
|
+
// eslint-disable-next-line no-param-reassign
|
|
209
|
+
item.variableLimit = calculateBorrowingAssetLimit(item.borrowedUsdVariable, payload.borrowLimitUsd);
|
|
210
|
+
// eslint-disable-next-line no-param-reassign
|
|
211
|
+
item.limit = calculateBorrowingAssetLimit(item.borrowedUsd, payload.borrowLimitUsd);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
const { netApy, incentiveUsd, totalInterestUsd } = calculateNetApy({ usedAssets, assetsData });
|
|
216
|
+
payload.netApy = netApy;
|
|
217
|
+
payload.incentiveUsd = incentiveUsd;
|
|
218
|
+
payload.totalInterestUsd = totalInterestUsd;
|
|
219
|
+
|
|
220
|
+
return payload;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export const getAaveV2FullPositionData = async (web3: Web3, network: NetworkNumber, address: string, market: AaveMarketInfo, mainnetWeb3: Web3): Promise<AaveV2PositionData> => {
|
|
224
|
+
const marketData = await getAaveV2MarketsData(web3, network, market, mainnetWeb3);
|
|
225
|
+
const positionData = await getAaveV2AccountData(web3, network, address, marketData.assetsData, market);
|
|
226
|
+
return positionData;
|
|
227
|
+
};
|