@defisaver/positions-sdk 0.0.166-dev2-liquity-v2 → 0.0.166-dev3
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/config/contracts.d.ts +32 -3
- package/cjs/config/contracts.js +3 -3
- package/cjs/contracts.d.ts +1 -1
- package/cjs/contracts.js +2 -2
- package/cjs/eulerV2/index.d.ts +41 -0
- package/cjs/eulerV2/index.js +214 -0
- package/cjs/helpers/eulerHelpers/index.d.ts +27 -0
- package/cjs/helpers/eulerHelpers/index.js +232 -0
- package/cjs/helpers/index.d.ts +1 -1
- package/cjs/helpers/index.js +2 -2
- package/cjs/index.d.ts +2 -2
- package/cjs/index.js +3 -3
- package/cjs/markets/euler/index.d.ts +8 -0
- package/cjs/markets/euler/index.js +30 -0
- package/cjs/markets/index.d.ts +1 -1
- package/cjs/markets/index.js +3 -3
- package/cjs/services/utils.d.ts +2 -0
- package/cjs/services/utils.js +4 -1
- package/cjs/types/contracts/generated/EulerV2View.d.ts +345 -0
- package/cjs/types/contracts/generated/index.d.ts +1 -1
- package/cjs/types/euler.d.ts +147 -0
- package/cjs/types/euler.js +14 -0
- package/cjs/types/index.d.ts +1 -1
- package/cjs/types/index.js +1 -1
- package/esm/config/contracts.d.ts +32 -3
- package/esm/config/contracts.js +3 -3
- package/esm/contracts.d.ts +1 -1
- package/esm/contracts.js +1 -1
- package/esm/eulerV2/index.d.ts +41 -0
- package/esm/eulerV2/index.js +206 -0
- package/esm/helpers/eulerHelpers/index.d.ts +27 -0
- package/esm/helpers/eulerHelpers/index.js +219 -0
- package/esm/helpers/index.d.ts +1 -1
- package/esm/helpers/index.js +1 -1
- package/esm/index.d.ts +2 -2
- package/esm/index.js +2 -2
- package/esm/markets/euler/index.d.ts +8 -0
- package/esm/markets/euler/index.js +24 -0
- package/esm/markets/index.d.ts +1 -1
- package/esm/markets/index.js +1 -1
- package/esm/services/utils.d.ts +2 -0
- package/esm/services/utils.js +2 -0
- package/esm/types/contracts/generated/EulerV2View.d.ts +345 -0
- package/esm/types/contracts/generated/index.d.ts +1 -1
- package/esm/types/euler.d.ts +147 -0
- package/esm/types/euler.js +11 -0
- package/esm/types/index.d.ts +1 -1
- package/esm/types/index.js +1 -1
- package/package.json +49 -49
- package/src/aaveV2/index.ts +227 -227
- package/src/aaveV3/index.ts +590 -590
- package/src/assets/index.ts +60 -60
- package/src/chickenBonds/index.ts +123 -123
- package/src/compoundV2/index.ts +219 -219
- package/src/compoundV3/index.ts +281 -281
- package/src/config/contracts.js +1040 -1040
- package/src/constants/index.ts +6 -6
- package/src/contracts.ts +130 -130
- package/src/curveUsd/index.ts +229 -229
- package/src/eulerV2/index.ts +297 -0
- package/src/exchange/index.ts +17 -17
- package/src/helpers/aaveHelpers/index.ts +194 -194
- 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 +231 -0
- package/src/helpers/index.ts +9 -9
- package/src/helpers/llamaLendHelpers/index.ts +53 -53
- package/src/helpers/makerHelpers/index.ts +94 -94
- package/src/helpers/morphoBlueHelpers/index.ts +115 -115
- package/src/helpers/sparkHelpers/index.ts +150 -150
- package/src/index.ts +48 -48
- package/src/liquity/index.ts +116 -116
- 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 +46 -46
- package/src/markets/compound/index.ts +173 -173
- package/src/markets/compound/marketsAssets.ts +64 -64
- package/src/markets/curveUsd/index.ts +69 -69
- package/src/markets/euler/index.ts +27 -0
- package/src/markets/index.ts +24 -23
- package/src/markets/llamaLend/contractAddresses.ts +141 -141
- package/src/markets/llamaLend/index.ts +235 -235
- package/src/markets/morphoBlue/index.ts +728 -728
- 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 +630 -630
- package/src/morphoBlue/index.ts +171 -171
- 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 +57 -54
- package/src/setup.ts +8 -8
- package/src/spark/index.ts +424 -424
- package/src/staking/staking.ts +218 -218
- package/src/types/aave.ts +262 -262
- package/src/types/chickenBonds.ts +45 -45
- package/src/types/common.ts +84 -84
- package/src/types/compound.ts +129 -129
- package/src/types/contracts/generated/EulerV2View.ts +446 -0
- package/src/types/contracts/generated/index.ts +1 -1
- package/src/types/curveUsd.ts +118 -118
- package/src/types/euler.ts +170 -0
- package/src/types/index.ts +10 -10
- package/src/types/liquity.ts +30 -30
- package/src/types/llamaLend.ts +155 -155
- package/src/types/maker.ts +50 -50
- package/src/types/morphoBlue.ts +146 -146
- package/src/types/spark.ts +127 -127
- package/cjs/helpers/liquityV2Helpers/index.d.ts +0 -12
- package/cjs/helpers/liquityV2Helpers/index.js +0 -61
- package/cjs/liquityV2/index.d.ts +0 -10
- package/cjs/liquityV2/index.js +0 -98
- package/cjs/markets/liquityV2/index.d.ts +0 -8
- package/cjs/markets/liquityV2/index.js +0 -34
- package/cjs/types/contracts/generated/LiquityV2View.d.ts +0 -222
- package/cjs/types/liquityV2.d.ts +0 -81
- package/cjs/types/liquityV2.js +0 -8
- package/esm/helpers/liquityV2Helpers/index.d.ts +0 -12
- package/esm/helpers/liquityV2Helpers/index.js +0 -53
- package/esm/liquityV2/index.d.ts +0 -10
- package/esm/liquityV2/index.js +0 -90
- package/esm/markets/liquityV2/index.d.ts +0 -8
- package/esm/markets/liquityV2/index.js +0 -28
- package/esm/types/contracts/generated/LiquityV2View.d.ts +0 -222
- package/esm/types/liquityV2.d.ts +0 -81
- package/esm/types/liquityV2.js +0 -5
- package/src/helpers/liquityV2Helpers/index.ts +0 -78
- package/src/liquityV2/index.ts +0 -115
- package/src/markets/liquityV2/index.ts +0 -31
- package/src/types/contracts/generated/LiquityV2View.ts +0 -280
- package/src/types/liquityV2.ts +0 -87
- /package/cjs/types/contracts/generated/{LiquityV2View.js → EulerV2View.js} +0 -0
- /package/esm/types/contracts/generated/{LiquityV2View.js → EulerV2View.js} +0 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import Web3 from 'web3';
|
|
2
|
+
import Dec from 'decimal.js';
|
|
3
|
+
import { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
4
|
+
import { NetworkNumber } from '../types/common';
|
|
5
|
+
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
6
|
+
import { compareAddresses, getEthAmountForDecimals, isMaxuint } from '../services/utils';
|
|
7
|
+
import {
|
|
8
|
+
EulerV2AssetData,
|
|
9
|
+
EulerV2AssetsData,
|
|
10
|
+
EulerV2FullMarketData,
|
|
11
|
+
EulerV2Market,
|
|
12
|
+
EulerV2MarketInfoData,
|
|
13
|
+
EulerV2PositionData,
|
|
14
|
+
EulerV2UsedAssets,
|
|
15
|
+
EulerV2VaultType,
|
|
16
|
+
} from '../types';
|
|
17
|
+
import {
|
|
18
|
+
getEulerV2AggregatedData,
|
|
19
|
+
getEulerV2BorrowRate,
|
|
20
|
+
getEulerV2SupplyRate,
|
|
21
|
+
getUtilizationRate,
|
|
22
|
+
} from '../helpers/eulerHelpers';
|
|
23
|
+
import { ZERO_ADDRESS } from '../constants';
|
|
24
|
+
import { EulerV2ViewContract } from '../contracts';
|
|
25
|
+
|
|
26
|
+
export const EMPTY_USED_ASSET = {
|
|
27
|
+
isSupplied: false,
|
|
28
|
+
isBorrowed: false,
|
|
29
|
+
supplied: '0',
|
|
30
|
+
suppliedUsd: '0',
|
|
31
|
+
borrowed: '0',
|
|
32
|
+
borrowedUsd: '0',
|
|
33
|
+
symbol: '',
|
|
34
|
+
collateral: false,
|
|
35
|
+
vaultAddress: '',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const UnitOfAccountUSD = '0x0000000000000000000000000000000000000348';
|
|
39
|
+
|
|
40
|
+
export const getEulerV2MarketsData = async (web3: Web3, network: NetworkNumber, selectedMarket: EulerV2Market, defaultWeb3: Web3): Promise<EulerV2FullMarketData> => {
|
|
41
|
+
const contract = EulerV2ViewContract(web3, network);
|
|
42
|
+
|
|
43
|
+
const data = await contract.methods.getVaultInfoFull(selectedMarket.marketAddress).call();
|
|
44
|
+
const isInUSD = compareAddresses(UnitOfAccountUSD, data.unitOfAccount);
|
|
45
|
+
|
|
46
|
+
const usdPrice = getEthAmountForDecimals(data.unitOfAccountInUsd, 8);
|
|
47
|
+
|
|
48
|
+
// parse collateral tokens
|
|
49
|
+
// imma use address as key for assetsData because there can be more collateral vaults with the same name
|
|
50
|
+
const colls: EulerV2AssetData[] = data.collaterals.map((collateral) => {
|
|
51
|
+
const decimals = collateral.decimals;
|
|
52
|
+
const assetInfo = getAssetInfoByAddress(collateral.assetAddr);
|
|
53
|
+
const borrowRate = getEulerV2BorrowRate(collateral.interestRate);
|
|
54
|
+
const utilizationRate = getUtilizationRate(collateral.totalBorrows, new Dec(collateral.totalBorrows).plus(collateral.cash).toString());
|
|
55
|
+
|
|
56
|
+
const supplyRate = getEulerV2SupplyRate(borrowRate, utilizationRate, collateral.interestFee);
|
|
57
|
+
|
|
58
|
+
const isEscrow = collateral.isEscrowed;
|
|
59
|
+
const isGoverned = !compareAddresses(collateral.governorAdmin, ZERO_ADDRESS);
|
|
60
|
+
|
|
61
|
+
const vaultType = isEscrow
|
|
62
|
+
? EulerV2VaultType.Escrow
|
|
63
|
+
: (
|
|
64
|
+
isGoverned ? EulerV2VaultType.Governed : EulerV2VaultType.Ungoverned
|
|
65
|
+
);
|
|
66
|
+
return ({
|
|
67
|
+
vaultAddress: collateral.vaultAddr,
|
|
68
|
+
assetAddress: collateral.assetAddr,
|
|
69
|
+
symbol: assetInfo.symbol,
|
|
70
|
+
vaultSymbol: collateral.vaultSymbol,
|
|
71
|
+
name: collateral.name,
|
|
72
|
+
vaultType,
|
|
73
|
+
decimals,
|
|
74
|
+
liquidationRatio: new Dec(collateral.liquidationLTV).div(10_000).toString(),
|
|
75
|
+
collateralFactor: new Dec(collateral.borrowLTV).div(10_000).toString(),
|
|
76
|
+
totalBorrow: getEthAmountForDecimals(collateral.totalBorrows, decimals), // parse
|
|
77
|
+
cash: getEthAmountForDecimals(collateral.cash, decimals),
|
|
78
|
+
supplyCap: isMaxuint(collateral.supplyCap) ? collateral.supplyCap : getEthAmountForDecimals(collateral.supplyCap, decimals),
|
|
79
|
+
borrowCap: '0',
|
|
80
|
+
price: isInUSD ? assetAmountInEth(collateral.assetPriceInUnit) : new Dec(assetAmountInEth(collateral.assetPriceInUnit)).mul(usdPrice).toString(), // 1e18 -> price in unitOfAccount (so it could be USD or any other token)
|
|
81
|
+
canBeBorrowed: false,
|
|
82
|
+
canBeSupplied: true,
|
|
83
|
+
borrowRate,
|
|
84
|
+
supplyRate,
|
|
85
|
+
utilization: new Dec(utilizationRate).mul(100).toString(),
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
for (const coll of colls) {
|
|
89
|
+
if (STAKING_ASSETS.includes(coll.symbol)) {
|
|
90
|
+
coll.incentiveSupplyApy = await getStakingApy(coll.symbol, defaultWeb3);
|
|
91
|
+
coll.incentiveSupplyToken = coll.symbol;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const isEscrow = data.collaterals.length === 0;
|
|
95
|
+
const isGoverned = !compareAddresses(data.governorAdmin, ZERO_ADDRESS);
|
|
96
|
+
|
|
97
|
+
const vaultType = isEscrow ? EulerV2VaultType.Escrow : (
|
|
98
|
+
isGoverned ? EulerV2VaultType.Governed : EulerV2VaultType.Ungoverned
|
|
99
|
+
);
|
|
100
|
+
const decimals = data.decimals;
|
|
101
|
+
|
|
102
|
+
// (1 + SPY/10**27) ** secondsPerYear - 1
|
|
103
|
+
|
|
104
|
+
const interestRate = data.interestRate;
|
|
105
|
+
|
|
106
|
+
const borrowRate = getEulerV2BorrowRate(interestRate);
|
|
107
|
+
|
|
108
|
+
const utilizationRate = getUtilizationRate(data.totalBorrows, data.totalAssets);
|
|
109
|
+
const supplyRate = getEulerV2SupplyRate(borrowRate, utilizationRate, data.interestFee);
|
|
110
|
+
|
|
111
|
+
const marketAsset = {
|
|
112
|
+
assetAddress: data.assetAddr,
|
|
113
|
+
vaultAddress: data.vaultAddr,
|
|
114
|
+
symbol: selectedMarket.asset,
|
|
115
|
+
vaultSymbol: selectedMarket.shortLabel,
|
|
116
|
+
decimals,
|
|
117
|
+
totalBorrow: getEthAmountForDecimals(data.totalBorrows, decimals), // parse
|
|
118
|
+
cash: getEthAmountForDecimals(data.cash, decimals),
|
|
119
|
+
supplyCap: isMaxuint(data.supplyCap) ? data.supplyCap : getEthAmountForDecimals(data.supplyCap, decimals),
|
|
120
|
+
borrowCap: isMaxuint(data.supplyCap) ? data.borrowCap : getEthAmountForDecimals(data.borrowCap, decimals),
|
|
121
|
+
price: isInUSD ? assetAmountInEth(data.assetPriceInUnit) : new Dec(assetAmountInEth(data.assetPriceInUnit)).mul(usdPrice).toString(), // 1e18 -> price in unitOfAccount (so it could be USD or any other token)
|
|
122
|
+
sortIndex: 0,
|
|
123
|
+
canBeBorrowed: true,
|
|
124
|
+
canBeSupplied: false,
|
|
125
|
+
borrowRate,
|
|
126
|
+
supplyRate,
|
|
127
|
+
collateralFactor: '0',
|
|
128
|
+
liquidationRatio: '0',
|
|
129
|
+
utilization: new Dec(utilizationRate).mul(100).toString(),
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const assetsData: EulerV2AssetsData = {
|
|
133
|
+
[data.vaultAddr.toLowerCase()]: marketAsset,
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
colls
|
|
137
|
+
.sort((coll1, coll2) => {
|
|
138
|
+
const aMarket = new Dec(coll1.price).times(coll1.totalBorrow).toString();
|
|
139
|
+
const bMarket = new Dec(coll2.price).times(coll2.totalBorrow).toString();
|
|
140
|
+
|
|
141
|
+
return new Dec(bMarket).minus(aMarket).toNumber();
|
|
142
|
+
})
|
|
143
|
+
.forEach((market, i) => {
|
|
144
|
+
assetsData[market.vaultAddress.toLowerCase()] = { ...market, sortIndex: i + 1 };
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const marketData: EulerV2MarketInfoData = {
|
|
148
|
+
name: data.name,
|
|
149
|
+
symbol: data.symbol,
|
|
150
|
+
decimals: data.decimals,
|
|
151
|
+
irm: data.irm,
|
|
152
|
+
creator: data.creator,
|
|
153
|
+
governorAdmin: data.governorAdmin,
|
|
154
|
+
unitOfAccount: data.unitOfAccount,
|
|
155
|
+
unitOfAccountUsdPrice: usdPrice,
|
|
156
|
+
isInUSD,
|
|
157
|
+
oracle: data.oracle,
|
|
158
|
+
collaterals: data.collaterals.map((collateral) => collateral.vaultAddr),
|
|
159
|
+
isEscrow,
|
|
160
|
+
isGoverned,
|
|
161
|
+
vaultType,
|
|
162
|
+
vaultAddress: data.vaultAddr,
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
marketData,
|
|
167
|
+
assetsData,
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// export const getEulerV2AccountBalances = async (
|
|
172
|
+
// web3: Web3,
|
|
173
|
+
// network: NetworkNumber,
|
|
174
|
+
// selectedMarket: EulerV2MarketData
|
|
175
|
+
// ): Promise<> => {
|
|
176
|
+
//
|
|
177
|
+
// }
|
|
178
|
+
|
|
179
|
+
export const EMPTY_EULER_V2_DATA = {
|
|
180
|
+
usedAssets: {},
|
|
181
|
+
suppliedUsd: '0',
|
|
182
|
+
borrowedUsd: '0',
|
|
183
|
+
borrowLimitUsd: '0',
|
|
184
|
+
leftToBorrowUsd: '0',
|
|
185
|
+
ratio: '0',
|
|
186
|
+
minRatio: '0',
|
|
187
|
+
netApy: '0',
|
|
188
|
+
incentiveUsd: '0',
|
|
189
|
+
totalInterestUsd: '0',
|
|
190
|
+
isSubscribedToAutomation: false,
|
|
191
|
+
automationResubscribeRequired: false,
|
|
192
|
+
borrowVault: '',
|
|
193
|
+
borrowAmountInUnit: '0',
|
|
194
|
+
inLockDownMode: false,
|
|
195
|
+
inPermitDisabledMode: false,
|
|
196
|
+
lastUpdated: Date.now(),
|
|
197
|
+
hasBorrowInDifferentVault: false,
|
|
198
|
+
addressSpaceTakenByAnotherAccount: false,
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
export const getEulerV2AccountData = async (
|
|
202
|
+
web3: Web3,
|
|
203
|
+
network: NetworkNumber,
|
|
204
|
+
address: string,
|
|
205
|
+
extractedState: ({
|
|
206
|
+
selectedMarket: EulerV2Market,
|
|
207
|
+
assetsData: EulerV2AssetsData,
|
|
208
|
+
marketData: EulerV2MarketInfoData,
|
|
209
|
+
}),
|
|
210
|
+
): Promise<EulerV2PositionData> => {
|
|
211
|
+
if (!address) throw new Error('No address provided');
|
|
212
|
+
|
|
213
|
+
const {
|
|
214
|
+
selectedMarket, assetsData, marketData,
|
|
215
|
+
} = extractedState;
|
|
216
|
+
|
|
217
|
+
let payload = {
|
|
218
|
+
...EMPTY_EULER_V2_DATA,
|
|
219
|
+
lastUpdated: Date.now(),
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const isInUSD = marketData.isInUSD;
|
|
223
|
+
|
|
224
|
+
const parsingDecimals = isInUSD ? 18 : getAssetInfoByAddress(marketData.unitOfAccount).decimals;
|
|
225
|
+
const contract = EulerV2ViewContract(web3, network);
|
|
226
|
+
|
|
227
|
+
const loanData = await contract.methods.getUserData(address).call();
|
|
228
|
+
const usedAssets: EulerV2UsedAssets = {};
|
|
229
|
+
// there is no user position check for a specific market, only global check
|
|
230
|
+
// but we need to make sure it works for the UI and show position only for the selected market
|
|
231
|
+
if (!compareAddresses(loanData.borrowVault, selectedMarket.marketAddress)) {
|
|
232
|
+
payload = {
|
|
233
|
+
...payload,
|
|
234
|
+
borrowVault: ZERO_ADDRESS,
|
|
235
|
+
borrowAmountInUnit: '0',
|
|
236
|
+
inLockDownMode: false,
|
|
237
|
+
inPermitDisabledMode: false,
|
|
238
|
+
hasBorrowInDifferentVault: !compareAddresses(loanData.borrowVault, ZERO_ADDRESS),
|
|
239
|
+
addressSpaceTakenByAnotherAccount: !compareAddresses(loanData.owner, address) && !compareAddresses(loanData.owner, ZERO_ADDRESS),
|
|
240
|
+
};
|
|
241
|
+
} else {
|
|
242
|
+
payload = {
|
|
243
|
+
...payload,
|
|
244
|
+
borrowVault: loanData.borrowVault,
|
|
245
|
+
borrowAmountInUnit: loanData.borrowAmountInUnit,
|
|
246
|
+
inLockDownMode: loanData.inLockDownMode,
|
|
247
|
+
inPermitDisabledMode: loanData.inPermitDisabledMode,
|
|
248
|
+
addressSpaceTakenByAnotherAccount: !compareAddresses(loanData.owner, address) && !compareAddresses(loanData.owner, ZERO_ADDRESS),
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const borrowedInUnit = getEthAmountForDecimals(loanData.borrowAmountInUnit, parsingDecimals);
|
|
252
|
+
const borrowedInAsset = getEthAmountForDecimals(loanData.borrowAmountInAsset, marketData.decimals);
|
|
253
|
+
const borrowVault = loanData.borrowVault;
|
|
254
|
+
|
|
255
|
+
if (borrowVault && !compareAddresses(ZERO_ADDRESS, borrowVault) && borrowedInUnit) {
|
|
256
|
+
const borrowInfo = assetsData[borrowVault.toLowerCase()];
|
|
257
|
+
usedAssets[borrowVault.toLowerCase()] = {
|
|
258
|
+
...EMPTY_USED_ASSET,
|
|
259
|
+
isBorrowed: true,
|
|
260
|
+
borrowed: borrowedInAsset,
|
|
261
|
+
borrowedUsd: isInUSD ? borrowedInUnit : new Dec(borrowedInUnit).mul(marketData.unitOfAccountUsdPrice).toString(),
|
|
262
|
+
vaultAddress: loanData.borrowVault,
|
|
263
|
+
symbol: borrowInfo.symbol,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
loanData.collaterals.forEach((collateral, i) => {
|
|
269
|
+
const key = collateral.collateralVault.toLowerCase();
|
|
270
|
+
const collInfo = assetsData[key];
|
|
271
|
+
|
|
272
|
+
if (!collInfo || !marketData.collaterals.map(a => a.toLowerCase()).includes(key)) return; // this is a token supplied but not being used as a collateral for the market
|
|
273
|
+
|
|
274
|
+
const suppliedInUnit = getEthAmountForDecimals(collateral.collateralAmountInUnit, parsingDecimals);
|
|
275
|
+
const suppliedInAsset = getEthAmountForDecimals(collateral.collateralAmountInAsset, collInfo.decimals);
|
|
276
|
+
const collateralAmountInUSD = getEthAmountForDecimals(collateral.collateralAmountInUSD, 18);
|
|
277
|
+
usedAssets[key] = {
|
|
278
|
+
...EMPTY_USED_ASSET,
|
|
279
|
+
collateral: true,
|
|
280
|
+
isSupplied: true,
|
|
281
|
+
supplied: suppliedInAsset,
|
|
282
|
+
suppliedUsd: collateralAmountInUSD,
|
|
283
|
+
vaultAddress: collateral.collateralVault,
|
|
284
|
+
symbol: collInfo.symbol,
|
|
285
|
+
};
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
payload = {
|
|
289
|
+
...payload,
|
|
290
|
+
usedAssets,
|
|
291
|
+
...getEulerV2AggregatedData({
|
|
292
|
+
usedAssets, assetsData, network,
|
|
293
|
+
}),
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
return payload;
|
|
297
|
+
};
|
package/src/exchange/index.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import Web3 from 'web3';
|
|
2
|
-
|
|
3
|
-
import { assetAmountInWei, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
4
|
-
import {
|
|
5
|
-
Blockish, NetworkNumber, PositionBalances,
|
|
6
|
-
} from '../types/common';
|
|
7
|
-
import { wethToEthByAddress } from '../services/utils';
|
|
8
|
-
|
|
9
|
-
export const getExchangeAccountBalances = async (web3: Web3, network: NetworkNumber, block: Blockish, addressMapping: boolean, subData: any): Promise<PositionBalances> => {
|
|
10
|
-
const fromToken = getAssetInfoByAddress(wethToEthByAddress(subData.fromToken, network), network);
|
|
11
|
-
|
|
12
|
-
return {
|
|
13
|
-
selling: {
|
|
14
|
-
[addressMapping ? fromToken.address.toLowerCase() : fromToken.symbol]: assetAmountInWei(subData.amount, fromToken.symbol),
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
};
|
|
1
|
+
import Web3 from 'web3';
|
|
2
|
+
|
|
3
|
+
import { assetAmountInWei, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
4
|
+
import {
|
|
5
|
+
Blockish, NetworkNumber, PositionBalances,
|
|
6
|
+
} from '../types/common';
|
|
7
|
+
import { wethToEthByAddress } from '../services/utils';
|
|
8
|
+
|
|
9
|
+
export const getExchangeAccountBalances = async (web3: Web3, network: NetworkNumber, block: Blockish, addressMapping: boolean, subData: any): Promise<PositionBalances> => {
|
|
10
|
+
const fromToken = getAssetInfoByAddress(wethToEthByAddress(subData.fromToken, network), network);
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
selling: {
|
|
14
|
+
[addressMapping ? fromToken.address.toLowerCase() : fromToken.symbol]: assetAmountInWei(subData.amount, fromToken.symbol),
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
};
|