@defisaver/positions-sdk 0.0.11 → 0.0.13

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.
Files changed (79) hide show
  1. package/cjs/config/contracts.d.ts +183 -71
  2. package/cjs/config/contracts.js +16 -0
  3. package/cjs/markets/curveUsd/index.d.ts +2 -0
  4. package/cjs/markets/curveUsd/index.js +14 -1
  5. package/cjs/types/aave.d.ts +1 -1
  6. package/cjs/types/contracts/generated/CrvUSDtBTCAmm.d.ts +139 -0
  7. package/cjs/types/contracts/generated/CrvUSDtBTCAmm.js +5 -0
  8. package/cjs/types/contracts/generated/CrvUSDtBTCController.d.ts +204 -0
  9. package/cjs/types/contracts/generated/CrvUSDtBTCController.js +5 -0
  10. package/cjs/types/contracts/generated/index.d.ts +2 -0
  11. package/cjs/types/curveUsd.d.ts +2 -1
  12. package/cjs/types/curveUsd.js +1 -0
  13. package/cjs/types/spark.d.ts +1 -3
  14. package/esm/config/contracts.d.ts +183 -71
  15. package/esm/config/contracts.js +16 -0
  16. package/esm/markets/curveUsd/index.d.ts +2 -0
  17. package/esm/markets/curveUsd/index.js +12 -0
  18. package/esm/types/aave.d.ts +1 -1
  19. package/esm/types/contracts/generated/CrvUSDtBTCAmm.d.ts +139 -0
  20. package/esm/types/contracts/generated/CrvUSDtBTCAmm.js +4 -0
  21. package/esm/types/contracts/generated/CrvUSDtBTCController.d.ts +204 -0
  22. package/esm/types/contracts/generated/CrvUSDtBTCController.js +4 -0
  23. package/esm/types/contracts/generated/index.d.ts +2 -0
  24. package/esm/types/curveUsd.d.ts +2 -1
  25. package/esm/types/curveUsd.js +1 -0
  26. package/esm/types/spark.d.ts +1 -3
  27. package/package.json +40 -40
  28. package/src/aaveV2/index.ts +220 -220
  29. package/src/aaveV3/index.ts +550 -550
  30. package/src/assets/index.ts +60 -60
  31. package/src/chickenBonds/index.ts +123 -123
  32. package/src/compoundV2/index.ts +206 -206
  33. package/src/compoundV3/index.ts +269 -269
  34. package/src/config/contracts.js +635 -619
  35. package/src/constants/index.ts +3 -3
  36. package/src/contracts.ts +100 -100
  37. package/src/curveUsd/index.ts +228 -228
  38. package/src/exchange/index.ts +17 -17
  39. package/src/helpers/aaveHelpers/index.ts +134 -134
  40. package/src/helpers/chickenBondsHelpers/index.ts +23 -23
  41. package/src/helpers/compoundHelpers/index.ts +181 -181
  42. package/src/helpers/curveUsdHelpers/index.ts +32 -32
  43. package/src/helpers/index.ts +5 -5
  44. package/src/helpers/makerHelpers/index.ts +94 -94
  45. package/src/helpers/sparkHelpers/index.ts +106 -106
  46. package/src/index.ts +40 -40
  47. package/src/liquity/index.ts +103 -103
  48. package/src/maker/index.ts +101 -101
  49. package/src/markets/aave/index.ts +80 -80
  50. package/src/markets/aave/marketAssets.ts +32 -32
  51. package/src/markets/compound/index.ts +85 -85
  52. package/src/markets/compound/marketsAssets.ts +35 -35
  53. package/src/markets/curveUsd/index.ts +56 -42
  54. package/src/markets/index.ts +3 -3
  55. package/src/markets/spark/index.ts +29 -29
  56. package/src/markets/spark/marketAssets.ts +9 -9
  57. package/src/moneymarket/moneymarketCommonService.ts +75 -75
  58. package/src/morpho/markets.ts +39 -39
  59. package/src/morphoAaveV2/index.ts +254 -254
  60. package/src/morphoAaveV3/index.ts +614 -614
  61. package/src/multicall/index.ts +22 -22
  62. package/src/services/dsrService.ts +15 -15
  63. package/src/services/priceService.ts +21 -21
  64. package/src/services/utils.ts +34 -34
  65. package/src/spark/index.ts +413 -413
  66. package/src/staking/staking.ts +167 -167
  67. package/src/types/aave.ts +256 -256
  68. package/src/types/chickenBonds.ts +45 -45
  69. package/src/types/common.ts +83 -83
  70. package/src/types/compound.ts +121 -121
  71. package/src/types/contracts/generated/CrvUSDtBTCAmm.ts +286 -0
  72. package/src/types/contracts/generated/CrvUSDtBTCController.ts +397 -0
  73. package/src/types/contracts/generated/index.ts +2 -0
  74. package/src/types/curveUsd.ts +111 -110
  75. package/src/types/index.ts +6 -6
  76. package/src/types/liquity.ts +29 -29
  77. package/src/types/maker.ts +50 -50
  78. package/src/types/spark.ts +106 -106
  79. package/yarn-error.log +64 -0
@@ -1,207 +1,207 @@
1
- import { assetAmountInEth, getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
2
- import Dec from 'decimal.js';
3
- import Web3 from 'web3';
4
- import { BLOCKS_IN_A_YEAR } from '../constants';
5
- import { aprToApy } from '../moneymarket';
6
- import { compareAddresses, handleWbtcLegacy, wethToEth } from '../services/utils';
7
- import {
8
- Blockish, EthAddress, NetworkNumber, PositionBalances,
9
- } from '../types/common';
10
- import { CompoundLoanInfoContract, ComptrollerContract } from '../contracts';
11
- import { compoundV2CollateralAssets } from '../markets/compound/marketsAssets';
12
- import {
13
- CompoundV2AssetsData, CompoundV2MarketsData, CompoundV2PositionData, CompoundV2UsedAsset, CompoundV2UsedAssets,
14
- } from '../types';
15
- import { getCompoundV2AggregatedData } from '../helpers/compoundHelpers';
16
-
17
- const compAddress = '0xc00e94cb662c3520282e6f5717214004a7f26888';
18
-
19
- export const getCompoundV2MarketsData = async (web3: Web3, network: NetworkNumber): Promise<CompoundV2MarketsData> => {
20
- const cAddresses = compoundV2CollateralAssets.map(a => a.address);
21
-
22
- const loanInfoContract = CompoundLoanInfoContract(web3, network);
23
- const loanInfo = await loanInfoContract.methods.getFullTokensInfo(cAddresses).call();
24
-
25
- const compPrice = loanInfo.find(m => compareAddresses(m.underlyingTokenAddress, compAddress))!.price.toString();
26
-
27
- const assetsData = loanInfo
28
- .map((market, i) => {
29
- let symbol = getAssetInfoByAddress(cAddresses[i]).underlyingAsset;
30
- let isWbtcLegacy = false;
31
- const totalSupply = new Dec(market.totalSupply.toString()).div(1e18).times(market.exchangeRate.toString());
32
- const totalBorrow = market.totalBorrow.toString();
33
- const borrowCap = market.borrowCap.toString();
34
- const compSupplySpeeds = market.compSupplySpeeds.toString();
35
- const compBorrowSpeeds = market.compBorrowSpeeds.toString();
36
- const assetPrice = market.price.toString();
37
-
38
- const pricePrecisionDiff = 18 - getAssetInfo(getAssetInfoByAddress(cAddresses[i]).underlyingAsset).decimals;
39
-
40
- // compSupplySpeeds/compBorrowSpeeds is per block per market (borrow & supply are separate markets)
41
- const incentiveSupplyApy = aprToApy((100 * BLOCKS_IN_A_YEAR * +compSupplySpeeds * +compPrice) / +assetPrice / +totalSupply).toString();
42
- const incentiveBorrowApy = aprToApy((100 * BLOCKS_IN_A_YEAR * +compBorrowSpeeds * +compPrice) / +assetPrice / +totalBorrow).toString();
43
-
44
- if (cAddresses[i].toLowerCase() === '0xc11b1268c1a384e55c48c2391d8d480264a3a7f4'.toLowerCase()) {
45
- symbol = 'WBTC Legacy';
46
- isWbtcLegacy = true;
47
- }
48
- return {
49
- symbol,
50
- underlyingTokenAddress: market.underlyingTokenAddress,
51
- supplyRate: aprToApy(new Dec(BLOCKS_IN_A_YEAR).times(market.supplyRate.toString()).div(1e16).toString()).toString(),
52
- borrowRate: aprToApy(new Dec(BLOCKS_IN_A_YEAR).times(market.borrowRate.toString()).div(1e16).toString()).toString(),
53
- incentiveSupplyToken: 'COMP',
54
- incentiveBorrowToken: 'COMP',
55
- incentiveSupplyApy,
56
- incentiveBorrowApy,
57
- collateralFactor: new Dec(market.collateralFactor.toString()).div(1e18).toString(),
58
- marketLiquidity: assetAmountInEth(market.marketLiquidity.toString(), handleWbtcLegacy(symbol)),
59
- utilization: new Dec(market.totalBorrow.toString()).div(totalSupply).times(100).toString(),
60
- totalSupply: assetAmountInEth(totalSupply, handleWbtcLegacy(symbol)),
61
- totalBorrow: assetAmountInEth(totalBorrow, handleWbtcLegacy(symbol)),
62
- exchangeRate: new Dec(market.exchangeRate.toString()).div(1e28).toString(),
63
- borrowCap: assetAmountInEth(borrowCap, handleWbtcLegacy(symbol)),
64
- canBeBorrowed: market.canBorrow,
65
- canBeSupplied: market.canMint,
66
- price: new Dec(market.price.toString()).div(10 ** (18 + pricePrecisionDiff)).toString(),
67
- };
68
- });
69
-
70
- const payload = {} as CompoundV2AssetsData;
71
- // Sort by market size
72
- assetsData
73
- .sort((a, b) => {
74
- const aMarket = new Dec(a.price).times(a.totalSupply).toString();
75
- const bMarket = new Dec(b.price).times(b.totalSupply).toString();
76
-
77
- return new Dec(bMarket).minus(aMarket).toNumber();
78
- })
79
- .forEach((market, i) => { payload[market.symbol] = { ...market, sortIndex: i }; });
80
-
81
- return { assetsData: payload };
82
- };
83
-
84
- export const EMPTY_COMPOUND_DATA = {
85
- usedAssets: {},
86
- suppliedUsd: '0',
87
- borrowedUsd: '0',
88
- borrowLimitUsd: '0',
89
- leftToBorrowUsd: '0',
90
- ratio: '0',
91
- minRatio: '0',
92
- netApy: '0',
93
- incentiveUsd: '0',
94
- totalInterestUsd: '0',
95
- borrowStableSupplyUnstable: false,
96
- };
97
-
98
- export const getCollateralAssetsAddresses = async (web3: Web3, network: NetworkNumber, account: string) => {
99
- const contract = ComptrollerContract(web3, network);
100
-
101
- return contract.methods.getAssetsIn(account).call();
102
- };
103
-
104
- export const getCompoundV2AccountBalances = async (web3: Web3, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress): Promise<PositionBalances> => {
105
- let balances: PositionBalances = {
106
- collateral: {},
107
- debt: {},
108
- };
109
-
110
- if (!address) {
111
- return balances;
112
- }
113
-
114
- const loanInfoContract = CompoundLoanInfoContract(web3, network, block);
115
- const loanInfo = await loanInfoContract.methods.getTokenBalances(address, compoundV2CollateralAssets.map(a => a.address)).call({}, block);
116
-
117
- loanInfo.balances.forEach((weiAmount: any, i: number) => {
118
- const asset = wethToEth(compoundV2CollateralAssets[i].symbol === 'cWBTC Legacy'
119
- ? `${compoundV2CollateralAssets[i].underlyingAsset} Legacy`
120
- : compoundV2CollateralAssets[i].underlyingAsset);
121
-
122
- balances = {
123
- collateral: {
124
- ...balances.collateral,
125
- [addressMapping ? getAssetInfo(asset, network).address.toLowerCase() : asset]: weiAmount.toString(),
126
- },
127
- };
128
- });
129
- loanInfo.borrows.forEach((weiAmount: any, i: number) => {
130
- const asset = wethToEth(compoundV2CollateralAssets[i].symbol === 'cWBTC Legacy'
131
- ? `${compoundV2CollateralAssets[i].underlyingAsset} Legacy`
132
- : compoundV2CollateralAssets[i].underlyingAsset);
133
-
134
- balances = {
135
- ...balances,
136
- debt: {
137
- ...balances.debt,
138
- [addressMapping ? getAssetInfo(asset, network).address.toLowerCase() : asset]: weiAmount.toString(),
139
- },
140
- };
141
- });
142
-
143
- return balances;
144
- };
145
-
146
- export const getCompoundV2AccountData = async (web3: Web3, network: NetworkNumber, address: string, assetsData: CompoundV2AssetsData): Promise<CompoundV2PositionData> => {
147
- if (!address) throw new Error('No address provided');
148
-
149
- let payload = { ...EMPTY_COMPOUND_DATA, lastUpdated: Date.now() };
150
-
151
- const loanInfoContract = CompoundLoanInfoContract(web3, network);
152
- const loanInfo = await loanInfoContract.methods.getTokenBalances(address, compoundV2CollateralAssets.map(a => a.address)).call();
153
- const collateralAssetsAddresses = await getCollateralAssetsAddresses(web3, network, address);
154
-
155
- const usedAssets = {} as CompoundV2UsedAssets;
156
-
157
- loanInfo.balances.forEach((weiAmount: string, i: number) => {
158
- const asset = compoundV2CollateralAssets[i].symbol === 'cWBTC Legacy'
159
- ? `${compoundV2CollateralAssets[i].underlyingAsset} Legacy`
160
- : compoundV2CollateralAssets[i].underlyingAsset;
161
- const amount = assetAmountInEth(weiAmount.toString(), asset);
162
- const collateral = !!collateralAssetsAddresses.find(a => compareAddresses(a, compoundV2CollateralAssets[i].address));
163
- if (weiAmount.toString() === '0' && !collateral) return;
164
- if (!usedAssets[asset]) usedAssets[asset] = {} as CompoundV2UsedAsset;
165
- usedAssets[asset] = {
166
- ...usedAssets[asset],
167
- symbol: asset,
168
- supplied: amount,
169
- suppliedUsd: new Dec(amount).mul(assetsData[handleWbtcLegacy(asset)].price).toString(),
170
- isSupplied: +amount > 0,
171
- collateral,
172
- };
173
- });
174
-
175
- loanInfo.borrows.forEach((weiAmount, i) => {
176
- if (weiAmount.toString() === '0') return;
177
- const asset = compoundV2CollateralAssets[i].symbol === 'cWBTC Legacy'
178
- ? `${compoundV2CollateralAssets[i].underlyingAsset} Legacy`
179
- : compoundV2CollateralAssets[i].underlyingAsset;
180
- const amount = assetAmountInEth(weiAmount.toString(), asset);
181
- if (!usedAssets[asset]) usedAssets[asset] = {} as CompoundV2UsedAsset;
182
- usedAssets[asset] = {
183
- ...usedAssets[asset],
184
- symbol: asset,
185
- borrowed: amount,
186
- borrowedUsd: new Dec(amount).mul(assetsData[handleWbtcLegacy(asset)].price).toString(),
187
- isBorrowed: true,
188
- collateral: !!usedAssets[asset].collateral,
189
- };
190
- });
191
-
192
- payload = {
193
- ...payload,
194
- usedAssets,
195
- ...getCompoundV2AggregatedData({
196
- usedAssets, assetsData,
197
- }),
198
- };
199
-
200
- return payload;
201
- };
202
-
203
- export const getCompoundV2FullPositionData = async (web3: Web3, network: NetworkNumber, address: string): Promise<CompoundV2PositionData> => {
204
- const marketData = await getCompoundV2MarketsData(web3, network);
205
- const positionData = await getCompoundV2AccountData(web3, network, address, marketData.assetsData);
206
- return positionData;
1
+ import { assetAmountInEth, getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
2
+ import Dec from 'decimal.js';
3
+ import Web3 from 'web3';
4
+ import { BLOCKS_IN_A_YEAR } from '../constants';
5
+ import { aprToApy } from '../moneymarket';
6
+ import { compareAddresses, handleWbtcLegacy, wethToEth } from '../services/utils';
7
+ import {
8
+ Blockish, EthAddress, NetworkNumber, PositionBalances,
9
+ } from '../types/common';
10
+ import { CompoundLoanInfoContract, ComptrollerContract } from '../contracts';
11
+ import { compoundV2CollateralAssets } from '../markets/compound/marketsAssets';
12
+ import {
13
+ CompoundV2AssetsData, CompoundV2MarketsData, CompoundV2PositionData, CompoundV2UsedAsset, CompoundV2UsedAssets,
14
+ } from '../types';
15
+ import { getCompoundV2AggregatedData } from '../helpers/compoundHelpers';
16
+
17
+ const compAddress = '0xc00e94cb662c3520282e6f5717214004a7f26888';
18
+
19
+ export const getCompoundV2MarketsData = async (web3: Web3, network: NetworkNumber): Promise<CompoundV2MarketsData> => {
20
+ const cAddresses = compoundV2CollateralAssets.map(a => a.address);
21
+
22
+ const loanInfoContract = CompoundLoanInfoContract(web3, network);
23
+ const loanInfo = await loanInfoContract.methods.getFullTokensInfo(cAddresses).call();
24
+
25
+ const compPrice = loanInfo.find(m => compareAddresses(m.underlyingTokenAddress, compAddress))!.price.toString();
26
+
27
+ const assetsData = loanInfo
28
+ .map((market, i) => {
29
+ let symbol = getAssetInfoByAddress(cAddresses[i]).underlyingAsset;
30
+ let isWbtcLegacy = false;
31
+ const totalSupply = new Dec(market.totalSupply.toString()).div(1e18).times(market.exchangeRate.toString());
32
+ const totalBorrow = market.totalBorrow.toString();
33
+ const borrowCap = market.borrowCap.toString();
34
+ const compSupplySpeeds = market.compSupplySpeeds.toString();
35
+ const compBorrowSpeeds = market.compBorrowSpeeds.toString();
36
+ const assetPrice = market.price.toString();
37
+
38
+ const pricePrecisionDiff = 18 - getAssetInfo(getAssetInfoByAddress(cAddresses[i]).underlyingAsset).decimals;
39
+
40
+ // compSupplySpeeds/compBorrowSpeeds is per block per market (borrow & supply are separate markets)
41
+ const incentiveSupplyApy = aprToApy((100 * BLOCKS_IN_A_YEAR * +compSupplySpeeds * +compPrice) / +assetPrice / +totalSupply).toString();
42
+ const incentiveBorrowApy = aprToApy((100 * BLOCKS_IN_A_YEAR * +compBorrowSpeeds * +compPrice) / +assetPrice / +totalBorrow).toString();
43
+
44
+ if (cAddresses[i].toLowerCase() === '0xc11b1268c1a384e55c48c2391d8d480264a3a7f4'.toLowerCase()) {
45
+ symbol = 'WBTC Legacy';
46
+ isWbtcLegacy = true;
47
+ }
48
+ return {
49
+ symbol,
50
+ underlyingTokenAddress: market.underlyingTokenAddress,
51
+ supplyRate: aprToApy(new Dec(BLOCKS_IN_A_YEAR).times(market.supplyRate.toString()).div(1e16).toString()).toString(),
52
+ borrowRate: aprToApy(new Dec(BLOCKS_IN_A_YEAR).times(market.borrowRate.toString()).div(1e16).toString()).toString(),
53
+ incentiveSupplyToken: 'COMP',
54
+ incentiveBorrowToken: 'COMP',
55
+ incentiveSupplyApy,
56
+ incentiveBorrowApy,
57
+ collateralFactor: new Dec(market.collateralFactor.toString()).div(1e18).toString(),
58
+ marketLiquidity: assetAmountInEth(market.marketLiquidity.toString(), handleWbtcLegacy(symbol)),
59
+ utilization: new Dec(market.totalBorrow.toString()).div(totalSupply).times(100).toString(),
60
+ totalSupply: assetAmountInEth(totalSupply, handleWbtcLegacy(symbol)),
61
+ totalBorrow: assetAmountInEth(totalBorrow, handleWbtcLegacy(symbol)),
62
+ exchangeRate: new Dec(market.exchangeRate.toString()).div(1e28).toString(),
63
+ borrowCap: assetAmountInEth(borrowCap, handleWbtcLegacy(symbol)),
64
+ canBeBorrowed: market.canBorrow,
65
+ canBeSupplied: market.canMint,
66
+ price: new Dec(market.price.toString()).div(10 ** (18 + pricePrecisionDiff)).toString(),
67
+ };
68
+ });
69
+
70
+ const payload = {} as CompoundV2AssetsData;
71
+ // Sort by market size
72
+ assetsData
73
+ .sort((a, b) => {
74
+ const aMarket = new Dec(a.price).times(a.totalSupply).toString();
75
+ const bMarket = new Dec(b.price).times(b.totalSupply).toString();
76
+
77
+ return new Dec(bMarket).minus(aMarket).toNumber();
78
+ })
79
+ .forEach((market, i) => { payload[market.symbol] = { ...market, sortIndex: i }; });
80
+
81
+ return { assetsData: payload };
82
+ };
83
+
84
+ export const EMPTY_COMPOUND_DATA = {
85
+ usedAssets: {},
86
+ suppliedUsd: '0',
87
+ borrowedUsd: '0',
88
+ borrowLimitUsd: '0',
89
+ leftToBorrowUsd: '0',
90
+ ratio: '0',
91
+ minRatio: '0',
92
+ netApy: '0',
93
+ incentiveUsd: '0',
94
+ totalInterestUsd: '0',
95
+ borrowStableSupplyUnstable: false,
96
+ };
97
+
98
+ export const getCollateralAssetsAddresses = async (web3: Web3, network: NetworkNumber, account: string) => {
99
+ const contract = ComptrollerContract(web3, network);
100
+
101
+ return contract.methods.getAssetsIn(account).call();
102
+ };
103
+
104
+ export const getCompoundV2AccountBalances = async (web3: Web3, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress): Promise<PositionBalances> => {
105
+ let balances: PositionBalances = {
106
+ collateral: {},
107
+ debt: {},
108
+ };
109
+
110
+ if (!address) {
111
+ return balances;
112
+ }
113
+
114
+ const loanInfoContract = CompoundLoanInfoContract(web3, network, block);
115
+ const loanInfo = await loanInfoContract.methods.getTokenBalances(address, compoundV2CollateralAssets.map(a => a.address)).call({}, block);
116
+
117
+ loanInfo.balances.forEach((weiAmount: any, i: number) => {
118
+ const asset = wethToEth(compoundV2CollateralAssets[i].symbol === 'cWBTC Legacy'
119
+ ? `${compoundV2CollateralAssets[i].underlyingAsset} Legacy`
120
+ : compoundV2CollateralAssets[i].underlyingAsset);
121
+
122
+ balances = {
123
+ collateral: {
124
+ ...balances.collateral,
125
+ [addressMapping ? getAssetInfo(asset, network).address.toLowerCase() : asset]: weiAmount.toString(),
126
+ },
127
+ };
128
+ });
129
+ loanInfo.borrows.forEach((weiAmount: any, i: number) => {
130
+ const asset = wethToEth(compoundV2CollateralAssets[i].symbol === 'cWBTC Legacy'
131
+ ? `${compoundV2CollateralAssets[i].underlyingAsset} Legacy`
132
+ : compoundV2CollateralAssets[i].underlyingAsset);
133
+
134
+ balances = {
135
+ ...balances,
136
+ debt: {
137
+ ...balances.debt,
138
+ [addressMapping ? getAssetInfo(asset, network).address.toLowerCase() : asset]: weiAmount.toString(),
139
+ },
140
+ };
141
+ });
142
+
143
+ return balances;
144
+ };
145
+
146
+ export const getCompoundV2AccountData = async (web3: Web3, network: NetworkNumber, address: string, assetsData: CompoundV2AssetsData): Promise<CompoundV2PositionData> => {
147
+ if (!address) throw new Error('No address provided');
148
+
149
+ let payload = { ...EMPTY_COMPOUND_DATA, lastUpdated: Date.now() };
150
+
151
+ const loanInfoContract = CompoundLoanInfoContract(web3, network);
152
+ const loanInfo = await loanInfoContract.methods.getTokenBalances(address, compoundV2CollateralAssets.map(a => a.address)).call();
153
+ const collateralAssetsAddresses = await getCollateralAssetsAddresses(web3, network, address);
154
+
155
+ const usedAssets = {} as CompoundV2UsedAssets;
156
+
157
+ loanInfo.balances.forEach((weiAmount: string, i: number) => {
158
+ const asset = compoundV2CollateralAssets[i].symbol === 'cWBTC Legacy'
159
+ ? `${compoundV2CollateralAssets[i].underlyingAsset} Legacy`
160
+ : compoundV2CollateralAssets[i].underlyingAsset;
161
+ const amount = assetAmountInEth(weiAmount.toString(), asset);
162
+ const collateral = !!collateralAssetsAddresses.find(a => compareAddresses(a, compoundV2CollateralAssets[i].address));
163
+ if (weiAmount.toString() === '0' && !collateral) return;
164
+ if (!usedAssets[asset]) usedAssets[asset] = {} as CompoundV2UsedAsset;
165
+ usedAssets[asset] = {
166
+ ...usedAssets[asset],
167
+ symbol: asset,
168
+ supplied: amount,
169
+ suppliedUsd: new Dec(amount).mul(assetsData[handleWbtcLegacy(asset)].price).toString(),
170
+ isSupplied: +amount > 0,
171
+ collateral,
172
+ };
173
+ });
174
+
175
+ loanInfo.borrows.forEach((weiAmount, i) => {
176
+ if (weiAmount.toString() === '0') return;
177
+ const asset = compoundV2CollateralAssets[i].symbol === 'cWBTC Legacy'
178
+ ? `${compoundV2CollateralAssets[i].underlyingAsset} Legacy`
179
+ : compoundV2CollateralAssets[i].underlyingAsset;
180
+ const amount = assetAmountInEth(weiAmount.toString(), asset);
181
+ if (!usedAssets[asset]) usedAssets[asset] = {} as CompoundV2UsedAsset;
182
+ usedAssets[asset] = {
183
+ ...usedAssets[asset],
184
+ symbol: asset,
185
+ borrowed: amount,
186
+ borrowedUsd: new Dec(amount).mul(assetsData[handleWbtcLegacy(asset)].price).toString(),
187
+ isBorrowed: true,
188
+ collateral: !!usedAssets[asset].collateral,
189
+ };
190
+ });
191
+
192
+ payload = {
193
+ ...payload,
194
+ usedAssets,
195
+ ...getCompoundV2AggregatedData({
196
+ usedAssets, assetsData,
197
+ }),
198
+ };
199
+
200
+ return payload;
201
+ };
202
+
203
+ export const getCompoundV2FullPositionData = async (web3: Web3, network: NetworkNumber, address: string): Promise<CompoundV2PositionData> => {
204
+ const marketData = await getCompoundV2MarketsData(web3, network);
205
+ const positionData = await getCompoundV2AccountData(web3, network, address, marketData.assetsData);
206
+ return positionData;
207
207
  };