@defisaver/positions-sdk 0.0.20 → 0.0.22
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/README.md +63 -0
- package/cjs/aaveV2/index.js +9 -4
- package/cjs/aaveV3/index.js +9 -4
- package/cjs/compoundV2/index.d.ts +1 -0
- package/cjs/compoundV2/index.js +15 -8
- package/cjs/config/contracts.d.ts +373 -201
- package/cjs/config/contracts.js +22 -0
- package/cjs/helpers/aaveHelpers/index.js +0 -5
- package/cjs/helpers/compoundHelpers/index.js +2 -2
- package/cjs/markets/compound/index.d.ts +2 -0
- package/cjs/markets/compound/index.js +60 -13
- package/cjs/markets/compound/marketsAssets.d.ts +7 -1
- package/cjs/markets/compound/marketsAssets.js +12 -2
- package/cjs/morphoAaveV2/index.js +4 -3
- package/cjs/morphoAaveV3/index.js +9 -4
- package/cjs/spark/index.js +9 -4
- package/cjs/types/aave.d.ts +0 -5
- package/cjs/types/compound.d.ts +6 -4
- package/cjs/types/compound.js +1 -0
- package/cjs/types/contracts/generated/CUSDCev3.d.ts +441 -0
- package/cjs/types/contracts/generated/CUSDCev3.js +5 -0
- package/cjs/types/contracts/generated/CompV3USDCBulkerArb.d.ts +41 -0
- package/cjs/types/contracts/generated/CompV3USDCBulkerArb.js +5 -0
- package/cjs/types/contracts/generated/index.d.ts +2 -0
- package/esm/aaveV2/index.js +11 -6
- package/esm/aaveV3/index.js +11 -6
- package/esm/compoundV2/index.d.ts +1 -0
- package/esm/compoundV2/index.js +13 -7
- package/esm/config/contracts.d.ts +373 -201
- package/esm/config/contracts.js +22 -0
- package/esm/helpers/aaveHelpers/index.js +0 -5
- package/esm/helpers/compoundHelpers/index.js +2 -2
- package/esm/markets/compound/index.d.ts +2 -0
- package/esm/markets/compound/index.js +59 -13
- package/esm/markets/compound/marketsAssets.d.ts +7 -1
- package/esm/markets/compound/marketsAssets.js +11 -1
- package/esm/morphoAaveV2/index.js +4 -3
- package/esm/morphoAaveV3/index.js +9 -4
- package/esm/spark/index.js +11 -6
- package/esm/types/aave.d.ts +0 -5
- package/esm/types/compound.d.ts +6 -4
- package/esm/types/compound.js +1 -0
- package/esm/types/contracts/generated/CUSDCev3.d.ts +441 -0
- package/esm/types/contracts/generated/CUSDCev3.js +4 -0
- package/esm/types/contracts/generated/CompV3USDCBulkerArb.d.ts +41 -0
- package/esm/types/contracts/generated/CompV3USDCBulkerArb.js +4 -0
- package/esm/types/contracts/generated/index.d.ts +2 -0
- package/package.json +40 -40
- package/src/aaveV2/index.ts +226 -220
- package/src/aaveV3/index.ts +561 -554
- package/src/assets/index.ts +60 -60
- package/src/chickenBonds/index.ts +123 -123
- package/src/compoundV2/index.ts +219 -206
- package/src/compoundV3/index.ts +275 -275
- package/src/config/contracts.js +673 -651
- package/src/constants/index.ts +3 -3
- package/src/contracts.ts +100 -100
- package/src/curveUsd/index.ts +228 -228
- package/src/exchange/index.ts +17 -17
- package/src/helpers/aaveHelpers/index.ts +134 -141
- package/src/helpers/chickenBondsHelpers/index.ts +23 -23
- package/src/helpers/compoundHelpers/index.ts +181 -181
- package/src/helpers/curveUsdHelpers/index.ts +32 -32
- package/src/helpers/index.ts +5 -5
- package/src/helpers/makerHelpers/index.ts +94 -94
- package/src/helpers/sparkHelpers/index.ts +106 -106
- package/src/index.ts +40 -40
- package/src/liquity/index.ts +116 -116
- package/src/maker/index.ts +101 -101
- package/src/markets/aave/index.ts +80 -80
- package/src/markets/aave/marketAssets.ts +32 -32
- package/src/markets/compound/index.ts +141 -85
- package/src/markets/compound/marketsAssets.ts +46 -35
- package/src/markets/curveUsd/index.ts +69 -69
- package/src/markets/index.ts +3 -3
- package/src/markets/spark/index.ts +29 -29
- package/src/markets/spark/marketAssets.ts +9 -9
- package/src/moneymarket/moneymarketCommonService.ts +75 -75
- package/src/morpho/markets.ts +39 -39
- package/src/morphoAaveV2/index.ts +255 -254
- package/src/morphoAaveV3/index.ts +619 -614
- package/src/multicall/index.ts +22 -22
- package/src/services/dsrService.ts +15 -15
- package/src/services/priceService.ts +21 -21
- package/src/services/utils.ts +34 -34
- package/src/spark/index.ts +421 -413
- package/src/staking/staking.ts +167 -167
- package/src/types/aave.ts +256 -261
- package/src/types/chickenBonds.ts +45 -45
- package/src/types/common.ts +83 -83
- package/src/types/compound.ts +128 -122
- package/src/types/contracts/generated/CUSDCev3.ts +685 -0
- package/src/types/contracts/generated/CompV3USDCBulkerArb.ts +85 -0
- package/src/types/contracts/generated/index.ts +2 -0
- package/src/types/curveUsd.ts +112 -112
- package/src/types/index.ts +6 -6
- package/src/types/liquity.ts +30 -30
- package/src/types/maker.ts +50 -50
- package/src/types/spark.ts +106 -106
package/src/aaveV2/index.ts
CHANGED
|
@@ -1,221 +1,227 @@
|
|
|
1
|
-
import Web3 from 'web3';
|
|
2
|
-
import Dec from 'decimal.js';
|
|
3
|
-
import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '../
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} from '../
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
.
|
|
40
|
-
.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
stEthMarket.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
return
|
|
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, getStETHApr } from '../staking';
|
|
8
|
+
import { ethToWeth, wethToEth, wethToEthByAddress } from '../services/utils';
|
|
9
|
+
import { AaveLoanInfoV2Contract, createContractWrapper } from '../contracts';
|
|
10
|
+
import { 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(mainnetWeb3);
|
|
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: new Dec(market.supplyRate.toString()).div(1e25).toString(),
|
|
30
|
+
borrowRate: new Dec(market.borrowRateVariable.toString()).div(1e25).toString(),
|
|
31
|
+
borrowRateStable: 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 getStETHApr(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: 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;
|
|
221
227
|
};
|