@defisaver/positions-sdk 2.1.167 → 2.1.168
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/cjs/aaveV2/index.js +8 -29
- package/cjs/aaveV3/index.js +2 -31
- package/cjs/aaveV4/index.d.ts +25 -0
- package/cjs/aaveV4/index.js +4 -1
- package/cjs/compoundV2/index.d.ts +1 -1
- package/cjs/compoundV2/index.js +2 -2
- package/cjs/curveUsd/index.d.ts +1 -1
- package/cjs/curveUsd/index.js +6 -1
- package/cjs/fluid/index.js +13 -12
- package/cjs/helpers/aaveBalances.d.ts +5 -0
- package/cjs/helpers/aaveBalances.js +51 -0
- package/cjs/helpers/fluidBalances.d.ts +6 -0
- package/cjs/helpers/fluidBalances.js +36 -0
- package/cjs/liquityV2/index.d.ts +8 -0
- package/cjs/liquityV2/index.js +3 -3
- package/cjs/llamaLend/index.d.ts +1 -1
- package/cjs/llamaLend/index.js +6 -1
- package/cjs/morphoMidnight/index.d.ts +1 -1
- package/cjs/morphoMidnight/index.js +6 -1
- package/cjs/portfolio/index.d.ts +1 -0
- package/cjs/portfolio/index.js +3 -0
- package/cjs/portfolio/lendingSummaries.d.ts +7 -0
- package/cjs/portfolio/lendingSummaries.js +262 -0
- package/cjs/portfolio/lendingSummaryTransport.d.ts +8 -0
- package/cjs/portfolio/lendingSummaryTransport.js +109 -0
- package/cjs/spark/index.js +2 -31
- package/cjs/types/index.d.ts +1 -0
- package/cjs/types/index.js +1 -0
- package/cjs/types/lendingSummary.d.ts +34 -0
- package/cjs/types/lendingSummary.js +2 -0
- package/esm/aaveV2/index.js +11 -32
- package/esm/aaveV3/index.js +3 -32
- package/esm/aaveV4/index.d.ts +25 -0
- package/esm/aaveV4/index.js +3 -1
- package/esm/compoundV2/index.d.ts +1 -1
- package/esm/compoundV2/index.js +2 -2
- package/esm/curveUsd/index.d.ts +1 -1
- package/esm/curveUsd/index.js +6 -1
- package/esm/fluid/index.js +13 -12
- package/esm/helpers/aaveBalances.d.ts +5 -0
- package/esm/helpers/aaveBalances.js +45 -0
- package/esm/helpers/fluidBalances.d.ts +6 -0
- package/esm/helpers/fluidBalances.js +28 -0
- package/esm/liquityV2/index.d.ts +8 -0
- package/esm/liquityV2/index.js +1 -1
- package/esm/llamaLend/index.d.ts +1 -1
- package/esm/llamaLend/index.js +6 -1
- package/esm/morphoMidnight/index.d.ts +1 -1
- package/esm/morphoMidnight/index.js +6 -1
- package/esm/portfolio/index.d.ts +1 -0
- package/esm/portfolio/index.js +1 -0
- package/esm/portfolio/lendingSummaries.d.ts +7 -0
- package/esm/portfolio/lendingSummaries.js +256 -0
- package/esm/portfolio/lendingSummaryTransport.d.ts +8 -0
- package/esm/portfolio/lendingSummaryTransport.js +104 -0
- package/esm/spark/index.js +4 -33
- package/esm/types/index.d.ts +1 -0
- package/esm/types/index.js +1 -0
- package/esm/types/lendingSummary.d.ts +34 -0
- package/esm/types/lendingSummary.js +1 -0
- package/package.json +1 -1
- package/src/aaveV2/index.ts +8 -48
- package/src/aaveV3/index.ts +2 -48
- package/src/aaveV4/index.ts +6 -1
- package/src/compoundV2/index.ts +2 -2
- package/src/curveUsd/index.ts +6 -1
- package/src/fluid/index.ts +13 -12
- package/src/helpers/aaveBalances.ts +41 -0
- package/src/helpers/fluidBalances.ts +34 -0
- package/src/liquityV2/index.ts +1 -1
- package/src/llamaLend/index.ts +6 -1
- package/src/morphoMidnight/index.ts +6 -1
- package/src/portfolio/index.ts +2 -0
- package/src/portfolio/lendingSummaries.ts +216 -0
- package/src/portfolio/lendingSummaryTransport.ts +84 -0
- package/src/spark/index.ts +3 -49
- package/src/types/index.ts +2 -1
- package/src/types/lendingSummary.ts +41 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { decodeFunctionData, decodeFunctionResult, encodeFunctionData, encodeFunctionResult, multicall3Abi, } from 'viem';
|
|
11
|
+
const errorText = (error) => {
|
|
12
|
+
const detail = error;
|
|
13
|
+
return `${(detail === null || detail === void 0 ? void 0 : detail.message) || String(error)} ${(detail === null || detail === void 0 ? void 0 : detail.code) || ''} ${(detail === null || detail === void 0 ? void 0 : detail.status) || ''}`;
|
|
14
|
+
};
|
|
15
|
+
const logRangeLimit = (error) => /block range|too many (results|logs)|query returned|response.*size|range.*limit/i.test(errorText(error));
|
|
16
|
+
const oversized = (error) => /413|request.*(large|size)|response.*(large|size)|out of gas|gas (required|limit)|exceeds.*gas|execution.*limit/i.test(errorText(error));
|
|
17
|
+
export const isLendingSummaryRateLimit = (error) => !oversized(error) && !logRangeLimit(error) && /429|rate.?limit|too many requests|compute units|limit exceeded/i.test(errorText(error));
|
|
18
|
+
/** One limiter for all reads, including split multicalls. No retries after cancellation/429. */
|
|
19
|
+
export function lendingSummaryTransport(provider, signal, blockNumber, maxCalldataBytes = 32000) {
|
|
20
|
+
let pinnedBlock = blockNumber;
|
|
21
|
+
let active = 0;
|
|
22
|
+
let rateLimit;
|
|
23
|
+
const waiting = [];
|
|
24
|
+
const check = () => {
|
|
25
|
+
if (signal === null || signal === void 0 ? void 0 : signal.aborted)
|
|
26
|
+
throw new Error('Lending summary cancelled');
|
|
27
|
+
// Keep the provider's original error code/message, including plain RPC error objects.
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-throw-literal
|
|
29
|
+
if (rateLimit !== undefined)
|
|
30
|
+
throw rateLimit;
|
|
31
|
+
};
|
|
32
|
+
const send = (args) => __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
if (active >= 4)
|
|
34
|
+
yield new Promise(resolve => { waiting.push(resolve); });
|
|
35
|
+
else
|
|
36
|
+
active++;
|
|
37
|
+
try {
|
|
38
|
+
check();
|
|
39
|
+
return yield provider.request(args);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (isLendingSummaryRateLimit(error))
|
|
43
|
+
rateLimit = error;
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
const next = waiting.shift();
|
|
48
|
+
if (next)
|
|
49
|
+
next();
|
|
50
|
+
else
|
|
51
|
+
active--;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
const request = (args) => __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
var _a;
|
|
56
|
+
check();
|
|
57
|
+
const params = [...(args.params || [])];
|
|
58
|
+
if (pinnedBlock !== undefined) {
|
|
59
|
+
const block = `0x${pinnedBlock.toString(16)}`;
|
|
60
|
+
if (args.method === 'eth_blockNumber')
|
|
61
|
+
return block;
|
|
62
|
+
if (['eth_call', 'eth_getCode'].includes(args.method))
|
|
63
|
+
params[1] = block;
|
|
64
|
+
}
|
|
65
|
+
const call = params[0];
|
|
66
|
+
const isMulticall = args.method === 'eth_call' && ((_a = call === null || call === void 0 ? void 0 : call.data) === null || _a === void 0 ? void 0 : _a.startsWith('0x82ad56cb'));
|
|
67
|
+
const splitMulticall = (error) => __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const { args: [calls] } = decodeFunctionData({ abi: multicall3Abi, data: call.data });
|
|
69
|
+
if (!calls || calls.length < 2)
|
|
70
|
+
throw error;
|
|
71
|
+
// Sequential halves keep the same concurrency bound and retain per-call failures.
|
|
72
|
+
const results = [];
|
|
73
|
+
for (const half of [calls.slice(0, Math.ceil(calls.length / 2)), calls.slice(Math.ceil(calls.length / 2))]) {
|
|
74
|
+
const data = encodeFunctionData({ abi: multicall3Abi, functionName: 'aggregate3', args: [half] });
|
|
75
|
+
const encoded = yield request(Object.assign(Object.assign({}, args), { params: [Object.assign(Object.assign({}, call), { data }), ...params.slice(1)] }));
|
|
76
|
+
results.push(...decodeFunctionResult({ abi: multicall3Abi, functionName: 'aggregate3', data: encoded }));
|
|
77
|
+
}
|
|
78
|
+
return encodeFunctionResult({ abi: multicall3Abi, functionName: 'aggregate3', result: results });
|
|
79
|
+
});
|
|
80
|
+
// Viem's batch size counts inner calls only. Also bound the fully encoded calldata.
|
|
81
|
+
if (isMulticall && (call.data.length - 2) / 2 > maxCalldataBytes)
|
|
82
|
+
return splitMulticall(new Error('Single call exceeds summary calldata limit'));
|
|
83
|
+
try {
|
|
84
|
+
return yield send(Object.assign(Object.assign({}, args), { params }));
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
check();
|
|
88
|
+
if (args.method === 'eth_getLogs' && logRangeLimit(error)) {
|
|
89
|
+
const from = BigInt(call.fromBlock);
|
|
90
|
+
const to = BigInt(call.toBlock);
|
|
91
|
+
if (from >= to)
|
|
92
|
+
throw error;
|
|
93
|
+
const middle = (from + to) / BigInt(2);
|
|
94
|
+
const first = yield request(Object.assign(Object.assign({}, args), { params: [Object.assign(Object.assign({}, call), { toBlock: `0x${middle.toString(16)}` })] }));
|
|
95
|
+
const last = yield request(Object.assign(Object.assign({}, args), { params: [Object.assign(Object.assign({}, call), { fromBlock: `0x${(middle + BigInt(1)).toString(16)}` })] }));
|
|
96
|
+
return [...first, ...last];
|
|
97
|
+
}
|
|
98
|
+
if (!isMulticall || !oversized(error))
|
|
99
|
+
throw error;
|
|
100
|
+
return splitMulticall(error);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
return { provider: { request }, isRateLimited: () => rateLimit !== undefined, pinBlock: (value) => { pinnedBlock = value; } };
|
|
104
|
+
}
|
package/esm/spark/index.js
CHANGED
|
@@ -9,14 +9,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
11
|
import { assetAmountInEth, assetAmountInWei, getAssetInfo } from '@defisaver/tokens';
|
|
12
|
+
import { getAaveLikeBalances } from '../helpers/aaveBalances';
|
|
12
13
|
import { IncentiveKind, } from '../types/common';
|
|
13
|
-
import { ethToWeth,
|
|
14
|
+
import { ethToWeth, } from '../services/utils';
|
|
14
15
|
import { calculateNetApy, getStakingApy, STAKING_ASSETS, } from '../staking';
|
|
15
16
|
import { SparkViewContractViem, SparkIncentiveDataProviderContractViem, createViemContractFromConfigFunc, } from '../contracts';
|
|
16
17
|
import { sparkGetAggregatedPositionData, sparkIsInIsolationMode } from '../helpers/sparkHelpers';
|
|
17
18
|
import { aprToApy, calculateBorrowingAssetLimit } from '../moneymarket';
|
|
18
19
|
import { SPARK_V1 } from '../markets/spark';
|
|
19
|
-
import { getViemProvider
|
|
20
|
+
import { getViemProvider } from '../services/viem';
|
|
20
21
|
export const sparkEmodeCategoriesMapping = (extractedState, usedAssets) => {
|
|
21
22
|
const { assetsData } = extractedState;
|
|
22
23
|
const usedAssetsValues = Object.values(usedAssets);
|
|
@@ -228,37 +229,7 @@ export const EMPTY_SPARK_DATA = {
|
|
|
228
229
|
exposure: 'N/A',
|
|
229
230
|
};
|
|
230
231
|
export const _getSparkAccountBalances = (provider, network, block, addressMapping, address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
231
|
-
|
|
232
|
-
collateral: {},
|
|
233
|
-
debt: {},
|
|
234
|
-
};
|
|
235
|
-
if (!address) {
|
|
236
|
-
return balances;
|
|
237
|
-
}
|
|
238
|
-
const loanInfoContract = SparkViewContractViem(provider, network, block);
|
|
239
|
-
const market = SPARK_V1(network);
|
|
240
|
-
const marketAddress = market.providerAddress;
|
|
241
|
-
// @ts-ignore
|
|
242
|
-
const protocolDataProviderContract = createViemContractFromConfigFunc(market.protocolData, market.protocolDataAddress)(provider, network);
|
|
243
|
-
// @ts-ignore
|
|
244
|
-
const reserveTokens = yield protocolDataProviderContract.read.getAllReservesTokens(setViemBlockNumber(block));
|
|
245
|
-
const symbols = reserveTokens.map(({ symbol }) => symbol);
|
|
246
|
-
const _addresses = reserveTokens.map(({ tokenAddress }) => tokenAddress);
|
|
247
|
-
// split addresses in half to avoid gas limit by multicall
|
|
248
|
-
const middleAddressIndex = Math.floor(_addresses.length / 2);
|
|
249
|
-
const [tokenBalances1, tokenBalances2] = yield Promise.all([
|
|
250
|
-
loanInfoContract.read.getTokenBalances([marketAddress, address, _addresses.slice(0, middleAddressIndex)], setViemBlockNumber(block)),
|
|
251
|
-
loanInfoContract.read.getTokenBalances([marketAddress, address, _addresses.slice(middleAddressIndex, _addresses.length)], setViemBlockNumber(block)),
|
|
252
|
-
]);
|
|
253
|
-
const loanInfo = [...tokenBalances1, ...tokenBalances2];
|
|
254
|
-
loanInfo.forEach((tokenInfo, i) => {
|
|
255
|
-
const asset = wethToEth(symbols[i]);
|
|
256
|
-
const assetAddr = wethToEthByAddress(_addresses[i], network).toLowerCase();
|
|
257
|
-
balances = {
|
|
258
|
-
collateral: Object.assign(Object.assign({}, balances.collateral), { [addressMapping ? assetAddr : asset]: tokenInfo.balance.toString() }),
|
|
259
|
-
debt: Object.assign(Object.assign({}, balances.debt), { [addressMapping ? assetAddr : asset]: new Dec(tokenInfo.borrowsStable.toString()).add(tokenInfo.borrowsVariable.toString()).toString() }),
|
|
260
|
-
};
|
|
261
|
-
});
|
|
232
|
+
const balances = yield getAaveLikeBalances(provider, network, block, addressMapping, address, SPARK_V1(network), 'SparkView');
|
|
262
233
|
return balances;
|
|
263
234
|
});
|
|
264
235
|
export const getSparkAccountBalances = (provider, network, block, addressMapping, address) => __awaiter(void 0, void 0, void 0, function* () { return _getSparkAccountBalances(getViemProvider(provider, network, { batch: { multicall: true } }), network, block, addressMapping, address); });
|
package/esm/types/index.d.ts
CHANGED
package/esm/types/index.js
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { EthAddress, NetworkNumber } from './common';
|
|
2
|
+
export type LendingSummaryPosition = {
|
|
3
|
+
id: string;
|
|
4
|
+
protocol: string;
|
|
5
|
+
/** Estimated decimal USD values; null means unavailable, never a verified zero. */
|
|
6
|
+
suppliedUsd: string | null;
|
|
7
|
+
debtUsd: string | null;
|
|
8
|
+
};
|
|
9
|
+
export type WalletLendingSummary = {
|
|
10
|
+
status: 'complete' | 'partial' | 'failed';
|
|
11
|
+
positions: LendingSummaryPosition[];
|
|
12
|
+
protocols: string[];
|
|
13
|
+
/** Sum of known supply values; check valuationComplete before ranking by value. */
|
|
14
|
+
suppliedUsd: string;
|
|
15
|
+
valuationComplete: boolean;
|
|
16
|
+
errors: string[];
|
|
17
|
+
};
|
|
18
|
+
/** Resolve distinct token addresses to USD prices keyed by lowercase address.
|
|
19
|
+
* Native tokens use their wrapped address. Missing/invalid prices remain unavailable.
|
|
20
|
+
* Prices are current market estimates; balances may come from a historical/fork snapshot.
|
|
21
|
+
*/
|
|
22
|
+
export type LendingSummaryPriceResolver = (network: NetworkNumber, tokens: EthAddress[], signal?: AbortSignal) => Promise<Record<string, string>>;
|
|
23
|
+
export type LendingSummaryOptions = {
|
|
24
|
+
resolvePrices: LendingSummaryPriceResolver;
|
|
25
|
+
signal?: AbortSignal;
|
|
26
|
+
/** Defaults to a snapshot of the provider's latest block. */
|
|
27
|
+
blockNumber?: bigint;
|
|
28
|
+
/** Use the smaller 2 KB calldata limit required by simulation providers. */
|
|
29
|
+
isSim?: boolean;
|
|
30
|
+
};
|
|
31
|
+
export type WalletLendingSummaries = {
|
|
32
|
+
summaries: Record<string, WalletLendingSummary>;
|
|
33
|
+
rateLimited: boolean;
|
|
34
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
package/src/aaveV2/index.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
2
|
import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
|
|
3
3
|
import { Client } from 'viem';
|
|
4
|
+
import { getAaveLikeBalances } from '../helpers/aaveBalances';
|
|
4
5
|
import {
|
|
5
6
|
Blockish, EthAddress, EthereumProvider, IncentiveKind, NetworkNumber, PositionBalances,
|
|
6
7
|
} from '../types/common';
|
|
7
8
|
import { calculateNetApy, getStakingApy } from '../staking';
|
|
8
|
-
import { ethToWeth, wethToEth
|
|
9
|
-
import { AaveLoanInfoV2ContractViem
|
|
9
|
+
import { ethToWeth, wethToEth } from '../services/utils';
|
|
10
|
+
import { AaveLoanInfoV2ContractViem } from '../contracts';
|
|
10
11
|
import { aprToApy, calculateBorrowingAssetLimit } from '../moneymarket';
|
|
11
12
|
import {
|
|
12
13
|
AaveMarketInfo, AaveV2AssetData, AaveV2AssetsData, AaveV2PositionData, AaveV2UsedAsset, AaveV2UsedAssets,
|
|
@@ -89,52 +90,11 @@ export const _getAaveV2MarketsData = async (provider: Client, network: NetworkNu
|
|
|
89
90
|
export const getAaveV2MarketsData = async (provider: EthereumProvider, network: NetworkNumber, selectedMarket: AaveMarketInfo) => _getAaveV2MarketsData(getViemProvider(provider, network), network, selectedMarket);
|
|
90
91
|
|
|
91
92
|
export const _getAaveV2AccountBalances = async (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress): Promise<PositionBalances> => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (!address) {
|
|
98
|
-
return balances;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const market = AAVE_V2;
|
|
102
|
-
|
|
103
|
-
const loanInfoContract = AaveLoanInfoV2ContractViem(provider, network, block);
|
|
104
|
-
|
|
105
|
-
const marketAddress = market.providerAddress;
|
|
106
|
-
// @ts-ignore
|
|
107
|
-
const protocolDataProviderContract = createViemContractFromConfigFunc(market.protocolData, market.protocolDataAddress)(provider, network);
|
|
108
|
-
|
|
109
|
-
// @ts-ignore
|
|
110
|
-
const reserveTokens = await protocolDataProviderContract.read.getAllReservesTokens(setViemBlockNumber(block)) as { symbol: string, tokenAddress: EthAddress }[];
|
|
111
|
-
const symbols = reserveTokens.map(({ symbol }: { symbol: string }) => symbol);
|
|
112
|
-
const _addresses = reserveTokens.map(({ tokenAddress }: { tokenAddress: EthAddress }) => tokenAddress);
|
|
113
|
-
|
|
114
|
-
const loanInfo = await loanInfoContract.read.getTokenBalances([marketAddress, address, _addresses as EthAddress[]], setViemBlockNumber(block));
|
|
115
|
-
|
|
116
|
-
loanInfo.forEach((_tokenInfo: any, i: number) => {
|
|
117
|
-
const asset = wethToEth(symbols[i]);
|
|
118
|
-
const assetAddr = wethToEthByAddress(_addresses[i], network).toLowerCase();
|
|
119
|
-
const tokenInfo = { ..._tokenInfo };
|
|
120
|
-
|
|
121
|
-
// known bug: stETH leaves 1 wei on every transfer
|
|
122
|
-
if (asset === 'stETH' && tokenInfo.balance.toString() === '1') {
|
|
123
|
-
tokenInfo.balance = '0';
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
balances = {
|
|
127
|
-
collateral: {
|
|
128
|
-
...balances.collateral,
|
|
129
|
-
[addressMapping ? assetAddr : asset]: tokenInfo.balance.toString(),
|
|
130
|
-
},
|
|
131
|
-
debt: {
|
|
132
|
-
...balances.debt,
|
|
133
|
-
[addressMapping ? assetAddr : asset]: new Dec(tokenInfo.borrowsStable.toString()).add(tokenInfo.borrowsVariable.toString()).toString(),
|
|
134
|
-
},
|
|
135
|
-
};
|
|
136
|
-
});
|
|
137
|
-
|
|
93
|
+
const balances = await getAaveLikeBalances(provider, network, block, addressMapping, address, AAVE_V2, 'AaveLoanInfoV2');
|
|
94
|
+
if (!address) return balances;
|
|
95
|
+
// Preserve the legacy getter's stETH transfer-dust convention.
|
|
96
|
+
const key = addressMapping ? getAssetInfo('stETH', network).address.toLowerCase() : 'stETH';
|
|
97
|
+
if (balances.collateral?.[key] === '1') balances.collateral[key] = '0';
|
|
138
98
|
return balances;
|
|
139
99
|
};
|
|
140
100
|
|
package/src/aaveV3/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { assetAmountInEth, assetAmountInWei, getAssetInfo } from '@defisaver/tokens';
|
|
2
2
|
import { Client } from 'viem';
|
|
3
3
|
import Dec from 'decimal.js';
|
|
4
|
+
import { getAaveLikeBalances } from '../helpers/aaveBalances';
|
|
4
5
|
import {
|
|
5
6
|
AaveIncentiveDataProviderV3ContractViem,
|
|
6
7
|
AaveIncentivesControllerViem,
|
|
@@ -17,7 +18,6 @@ import {
|
|
|
17
18
|
isEnabledOnBitmap,
|
|
18
19
|
isLayer2Network,
|
|
19
20
|
wethToEth,
|
|
20
|
-
wethToEthByAddress,
|
|
21
21
|
} from '../services/utils';
|
|
22
22
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
23
23
|
import {
|
|
@@ -384,53 +384,7 @@ export const EMPTY_AAVE_DATA = {
|
|
|
384
384
|
};
|
|
385
385
|
|
|
386
386
|
export const _getAaveV3AccountBalances = async (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress): Promise<PositionBalances> => {
|
|
387
|
-
|
|
388
|
-
collateral: {},
|
|
389
|
-
debt: {},
|
|
390
|
-
};
|
|
391
|
-
|
|
392
|
-
if (!address) {
|
|
393
|
-
return balances;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
const loanInfoContract = AaveV3ViewContractViem(provider, network, block);
|
|
397
|
-
|
|
398
|
-
const market = AAVE_V3(network);
|
|
399
|
-
const marketAddress = market.providerAddress;
|
|
400
|
-
// @ts-ignore
|
|
401
|
-
const protocolDataProviderContract = createViemContractFromConfigFunc(market.protocolData, market.protocolDataAddress)(provider, network);
|
|
402
|
-
|
|
403
|
-
// @ts-ignore
|
|
404
|
-
const reserveTokens = await protocolDataProviderContract.read.getAllReservesTokens(setViemBlockNumber(block)) as { symbol: string, tokenAddress: EthAddress }[];
|
|
405
|
-
const symbols = reserveTokens.map(({ symbol }: { symbol: string }) => symbol);
|
|
406
|
-
const _addresses = reserveTokens.map(({ tokenAddress }: { tokenAddress: EthAddress }) => tokenAddress);
|
|
407
|
-
|
|
408
|
-
// split addresses in half to avoid gas limit by multicall
|
|
409
|
-
const middleAddressIndex = Math.floor(_addresses.length / 2);
|
|
410
|
-
|
|
411
|
-
const [tokenBalances1, tokenBalances2] = await Promise.all([
|
|
412
|
-
loanInfoContract.read.getTokenBalances([marketAddress, address, _addresses.slice(0, middleAddressIndex)], setViemBlockNumber(block)),
|
|
413
|
-
loanInfoContract.read.getTokenBalances([marketAddress, address, _addresses.slice(middleAddressIndex, _addresses.length)], setViemBlockNumber(block)),
|
|
414
|
-
]);
|
|
415
|
-
|
|
416
|
-
const loanInfo = [...tokenBalances1, ...tokenBalances2];
|
|
417
|
-
|
|
418
|
-
loanInfo.forEach((tokenInfo: any, i: number) => {
|
|
419
|
-
const asset = wethToEth(symbols[i]);
|
|
420
|
-
const assetAddr = wethToEthByAddress(_addresses[i], network).toLowerCase();
|
|
421
|
-
|
|
422
|
-
balances = {
|
|
423
|
-
collateral: {
|
|
424
|
-
...balances.collateral,
|
|
425
|
-
[addressMapping ? assetAddr : asset]: tokenInfo.balance.toString(),
|
|
426
|
-
},
|
|
427
|
-
debt: {
|
|
428
|
-
...balances.debt,
|
|
429
|
-
[addressMapping ? assetAddr : asset]: new Dec(tokenInfo.borrowsStable.toString()).add(tokenInfo.borrowsVariable.toString()).toString(),
|
|
430
|
-
},
|
|
431
|
-
};
|
|
432
|
-
});
|
|
433
|
-
|
|
387
|
+
const balances = await getAaveLikeBalances(provider, network, block, addressMapping, address, AAVE_V3(network), 'AaveV3View');
|
|
434
388
|
return balances;
|
|
435
389
|
};
|
|
436
390
|
|
package/src/aaveV4/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
2
|
import Dec from 'decimal.js';
|
|
3
3
|
import { assetAmountInEth, assetAmountInWei, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
4
|
-
import { getViemProvider } from '../services/viem';
|
|
4
|
+
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
5
5
|
import {
|
|
6
6
|
AaveV4AccountData,
|
|
7
7
|
AaveV4HubAssetOnChainData,
|
|
@@ -275,6 +275,11 @@ export async function _getAaveV4AccountData(provider: Client, network: NetworkNu
|
|
|
275
275
|
};
|
|
276
276
|
}
|
|
277
277
|
|
|
278
|
+
/** Shared raw read; no spoke metadata or market enrichment. */
|
|
279
|
+
export const _getAaveV4LoanBalances = (provider: Client, network: NetworkNumber, block: Blockish, address: EthAddress, spoke: EthAddress) => (
|
|
280
|
+
AaveV4ViewContractViem(provider, network, block).read.getLoanData([spoke, address], setViemBlockNumber(block))
|
|
281
|
+
);
|
|
282
|
+
|
|
278
283
|
/**
|
|
279
284
|
* Lightweight existence check for Loan Shifter / UI discovery.
|
|
280
285
|
* Reads only `getLoanData(spoke, user)` and returns whether any reserve has
|
package/src/compoundV2/index.ts
CHANGED
|
@@ -116,7 +116,7 @@ const getAllMarketAddresses = async (provider: Client, network: NetworkNumber, b
|
|
|
116
116
|
};
|
|
117
117
|
|
|
118
118
|
|
|
119
|
-
export const _getCompoundV2AccountBalances = async (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress): Promise<PositionBalances> => {
|
|
119
|
+
export const _getCompoundV2AccountBalances = async (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, tokens?: EthAddress[]): Promise<PositionBalances> => {
|
|
120
120
|
let balances: PositionBalances = {
|
|
121
121
|
collateral: {},
|
|
122
122
|
debt: {},
|
|
@@ -126,7 +126,7 @@ export const _getCompoundV2AccountBalances = async (provider: Client, network: N
|
|
|
126
126
|
return balances;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
const assets = await getAllMarketAddresses(provider, network, block);
|
|
129
|
+
const assets = tokens || await getAllMarketAddresses(provider, network, block);
|
|
130
130
|
const assetInfo = assets.map(a => getAssetInfoByAddress(a, network));
|
|
131
131
|
const loanInfoContract = CompoundLoanInfoContractViem(provider, network, block);
|
|
132
132
|
const loanInfo = await loanInfoContract.read.getTokenBalances([address, assets], setViemBlockNumber(block));
|
package/src/curveUsd/index.ts
CHANGED
|
@@ -128,7 +128,7 @@ const getStatusForUser = (bandRange: string[], activeBand: string, crvUSDSupplie
|
|
|
128
128
|
return CrvUSDStatus.Nonexistant;
|
|
129
129
|
};
|
|
130
130
|
|
|
131
|
-
export const _getCrvUsdAccountBalances = async (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, controllerAddress: EthAddress): Promise<PositionBalances> => {
|
|
131
|
+
export const _getCrvUsdAccountBalances = async (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, controllerAddress: EthAddress, includeDeposited = false): Promise<PositionBalances> => {
|
|
132
132
|
let balances: PositionBalances = {
|
|
133
133
|
collateral: {},
|
|
134
134
|
debt: {},
|
|
@@ -152,6 +152,11 @@ export const _getCrvUsdAccountBalances = async (provider: Client, network: Netwo
|
|
|
152
152
|
},
|
|
153
153
|
};
|
|
154
154
|
|
|
155
|
+
if (includeDeposited) {
|
|
156
|
+
balances.deposited = {
|
|
157
|
+
[addressMapping ? getAssetInfo(wethToEth(selectedMarket.baseAsset), network).address.toLowerCase() : wethToEth(selectedMarket.baseAsset)]: data.curveUsdCollateralAmount.toString(),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
155
160
|
return balances;
|
|
156
161
|
};
|
|
157
162
|
|
package/src/fluid/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
assetAmountInEth, AssetData, getAssetInfo, getAssetInfoByAddress,
|
|
4
4
|
} from '@defisaver/tokens';
|
|
5
5
|
import { Client, PublicClient } from 'viem';
|
|
6
|
+
import { fluidTokenAmount } from '../helpers/fluidBalances';
|
|
6
7
|
import {
|
|
7
8
|
EthAddress, EthereumProvider, IncentiveKind, NetworkNumber,
|
|
8
9
|
} from '../types/common';
|
|
@@ -1178,8 +1179,8 @@ const parseT1UserData = (userPositionData: FluidUserPositionStructOutputStruct,
|
|
|
1178
1179
|
const debtAsset = getAssetInfo(marketData.debtAsset0);
|
|
1179
1180
|
|
|
1180
1181
|
// for T2 and T4 - this is the number of shares
|
|
1181
|
-
const supplied =
|
|
1182
|
-
const borrowed =
|
|
1182
|
+
const supplied = fluidTokenAmount(userPositionData.supply, collAsset.decimals);
|
|
1183
|
+
const borrowed = fluidTokenAmount(userPositionData.borrow, debtAsset.decimals);
|
|
1183
1184
|
|
|
1184
1185
|
const collUsedAsset: FluidUsedAsset = {
|
|
1185
1186
|
...EMPTY_USED_ASSET,
|
|
@@ -1234,10 +1235,10 @@ const parseT2UserData = (userPositionData: FluidUserPositionStructOutputStruct,
|
|
|
1234
1235
|
const debtAsset = getAssetInfo(marketData.debtAsset0);
|
|
1235
1236
|
|
|
1236
1237
|
const supplyShares = getEthAmountForDecimals(userPositionData.supply.toString(), 18); // this is supplied in coll shares
|
|
1237
|
-
const borrowed =
|
|
1238
|
+
const borrowed = fluidTokenAmount(userPositionData.borrow, debtAsset.decimals); // this is actual token borrow
|
|
1238
1239
|
|
|
1239
|
-
const supplied0 =
|
|
1240
|
-
const supplied1 =
|
|
1240
|
+
const supplied0 = fluidTokenAmount(userPositionData.supply, collAsset0.decimals, assetsData[collAsset0.symbol].tokenPerSupplyShare!);
|
|
1241
|
+
const supplied1 = fluidTokenAmount(userPositionData.supply, collAsset1.decimals, assetsData[collAsset1.symbol].tokenPerSupplyShare!);
|
|
1241
1242
|
|
|
1242
1243
|
const collUsedAsset0: Partial<FluidUsedAsset> = {
|
|
1243
1244
|
symbol: collAsset0.symbol,
|
|
@@ -1302,11 +1303,11 @@ const parseT3UserData = (userPositionData: FluidUserPositionStructOutputStruct,
|
|
|
1302
1303
|
const debtAsset0 = getAssetInfo(marketData.debtAsset0);
|
|
1303
1304
|
const debtAsset1 = getAssetInfo(marketData.debtAsset1);
|
|
1304
1305
|
|
|
1305
|
-
const supplied =
|
|
1306
|
+
const supplied = fluidTokenAmount(userPositionData.supply, collAsset.decimals); // this is actual token supply
|
|
1306
1307
|
const borrowShares = getEthAmountForDecimals(userPositionData.borrow.toString(), 18); // this is actual token borrow
|
|
1307
1308
|
|
|
1308
|
-
const borrowed0 =
|
|
1309
|
-
const borrowed1 =
|
|
1309
|
+
const borrowed0 = fluidTokenAmount(userPositionData.borrow, debtAsset0.decimals, assetsData[debtAsset0.symbol].tokenPerBorrowShare!);
|
|
1310
|
+
const borrowed1 = fluidTokenAmount(userPositionData.borrow, debtAsset1.decimals, assetsData[debtAsset1.symbol].tokenPerBorrowShare!);
|
|
1310
1311
|
|
|
1311
1312
|
const collUsedAsset: Partial<FluidUsedAsset> = {
|
|
1312
1313
|
symbol: collAsset.symbol,
|
|
@@ -1374,11 +1375,11 @@ const parseT4UserData = (userPositionData: FluidUserPositionStructOutputStruct,
|
|
|
1374
1375
|
const supplyShares = getEthAmountForDecimals(userPositionData.supply.toString(), 18); // this is actual token supply
|
|
1375
1376
|
const borrowShares = getEthAmountForDecimals(userPositionData.borrow.toString(), 18); // this is actual token borrow
|
|
1376
1377
|
|
|
1377
|
-
const supplied0 =
|
|
1378
|
-
const supplied1 =
|
|
1378
|
+
const supplied0 = fluidTokenAmount(userPositionData.supply, collAsset0.decimals, assetsData[collAsset0.symbol].tokenPerSupplyShare!);
|
|
1379
|
+
const supplied1 = fluidTokenAmount(userPositionData.supply, collAsset1.decimals, assetsData[collAsset1.symbol].tokenPerSupplyShare!);
|
|
1379
1380
|
|
|
1380
|
-
const borrowed0 =
|
|
1381
|
-
const borrowed1 =
|
|
1381
|
+
const borrowed0 = fluidTokenAmount(userPositionData.borrow, debtAsset0.decimals, assetsData[debtAsset0.symbol].tokenPerBorrowShare!);
|
|
1382
|
+
const borrowed1 = fluidTokenAmount(userPositionData.borrow, debtAsset1.decimals, assetsData[debtAsset1.symbol].tokenPerBorrowShare!);
|
|
1382
1383
|
|
|
1383
1384
|
const collUsedAsset0: Partial<FluidUsedAsset> = {
|
|
1384
1385
|
symbol: collAsset0.symbol,
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import Dec from 'decimal.js';
|
|
2
|
+
import { getAssetInfoByAddress } from '@defisaver/tokens';
|
|
3
|
+
import { Client } from 'viem';
|
|
4
|
+
import { AaveMarketInfo, SparkMarketData } from '../types';
|
|
5
|
+
import {
|
|
6
|
+
Blockish, EthAddress, NetworkNumber, PositionBalances,
|
|
7
|
+
} from '../types/common';
|
|
8
|
+
import { createViemContractFromConfigFunc } from '../contracts';
|
|
9
|
+
import { setViemBlockNumber } from '../services/viem';
|
|
10
|
+
import { wethToEth, wethToEthByAddress } from '../services/utils';
|
|
11
|
+
|
|
12
|
+
/** Raw token balances shared by Aave/Spark getters and lending previews. */
|
|
13
|
+
export async function getAaveLikeBalances(
|
|
14
|
+
client: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean,
|
|
15
|
+
address: EthAddress, market: Pick<AaveMarketInfo | SparkMarketData, 'providerAddress' | 'protocolData' | 'protocolDataAddress'>,
|
|
16
|
+
view: 'AaveLoanInfoV2' | 'AaveV3View' | 'SparkView', tokens?: EthAddress[],
|
|
17
|
+
): Promise<PositionBalances> {
|
|
18
|
+
const balances: PositionBalances = { collateral: {}, debt: {} };
|
|
19
|
+
if (!address) return balances;
|
|
20
|
+
let reserves: { tokenAddress: EthAddress; symbol: string }[];
|
|
21
|
+
if (tokens) reserves = tokens.map(tokenAddress => ({ tokenAddress, symbol: getAssetInfoByAddress(tokenAddress, network).symbol }));
|
|
22
|
+
else {
|
|
23
|
+
if (!market.protocolData) throw new Error('Missing protocol data provider');
|
|
24
|
+
reserves = [...await createViemContractFromConfigFunc(market.protocolData, market.protocolDataAddress as EthAddress)(client, network)
|
|
25
|
+
.read.getAllReservesTokens(setViemBlockNumber(block))];
|
|
26
|
+
}
|
|
27
|
+
const addresses = reserves.map(token => token.tokenAddress);
|
|
28
|
+
const contract = createViemContractFromConfigFunc(view)(client, network, block);
|
|
29
|
+
const middle = tokens ? Math.ceil(addresses.length / 2) : Math.floor(addresses.length / 2);
|
|
30
|
+
// Preserve legacy V2 single-call and V3/Spark two-call behavior.
|
|
31
|
+
const parts = !tokens && view === 'AaveLoanInfoV2' ? [addresses] : [addresses.slice(0, middle), addresses.slice(middle)];
|
|
32
|
+
const data = (await Promise.all((tokens ? parts.filter(part => part.length) : parts)
|
|
33
|
+
.map(part => contract.read.getTokenBalances([market.providerAddress, address, part], setViemBlockNumber(block))))).flat();
|
|
34
|
+
data.forEach((token, i) => {
|
|
35
|
+
// The views leave token.token unset; input order identifies the reserve.
|
|
36
|
+
const key = addressMapping ? wethToEthByAddress(reserves[i].tokenAddress, network).toLowerCase() : wethToEth(reserves[i].symbol);
|
|
37
|
+
balances.collateral![key] = token.balance.toString();
|
|
38
|
+
balances.debt![key] = new Dec(token.borrowsStable.toString()).add(token.borrowsVariable.toString()).toString();
|
|
39
|
+
});
|
|
40
|
+
return balances;
|
|
41
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import Dec from 'decimal.js';
|
|
2
|
+
import { getAssetInfoByAddress } from '@defisaver/tokens';
|
|
3
|
+
import { FluidUserPositionStructOutputStruct, FluidVaultDataStructOutputStruct } from '../types';
|
|
4
|
+
import { NetworkNumber, PositionBalances } from '../types/common';
|
|
5
|
+
|
|
6
|
+
/** Convert raw tokens, or raw 18-decimal shares with a human-readable token/share ratio. */
|
|
7
|
+
export const fluidTokenAmount = (amount: bigint, decimals: number, perShare?: string): string => (
|
|
8
|
+
new Dec(amount.toString()).div(new Dec(10).pow(perShare === undefined ? decimals : 18)).mul(perShare ?? 1).toString()
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
/** The same token/share conversion used by the full Fluid user parsers, without prices or yield. */
|
|
12
|
+
export function parseFluidBalances(position: FluidUserPositionStructOutputStruct, vault: FluidVaultDataStructOutputStruct, network: NetworkNumber): PositionBalances {
|
|
13
|
+
const type = Number(vault.vaultType);
|
|
14
|
+
if (![10000, 20000, 30000, 40000].includes(type)) throw new Error('Unsupported Fluid vault');
|
|
15
|
+
const side = (amount: bigint, tokens: string[], ratios: bigint[] | undefined) => {
|
|
16
|
+
const balances: Record<string, string> = {};
|
|
17
|
+
tokens.forEach((address, i) => {
|
|
18
|
+
const token = getAssetInfoByAddress(address, network);
|
|
19
|
+
if (!Number.isFinite(token.decimals) || !token.symbol) throw new Error('Fluid token metadata unavailable');
|
|
20
|
+
const perShare = ratios ? fluidTokenAmount(ratios[i], token.decimals) : undefined;
|
|
21
|
+
const value = fluidTokenAmount(amount, token.decimals, perShare);
|
|
22
|
+
balances[token.symbol] = new Dec(balances[token.symbol] || 0).add(value).toString();
|
|
23
|
+
});
|
|
24
|
+
return balances;
|
|
25
|
+
};
|
|
26
|
+
const smartSupply = type === 20000 || type === 40000;
|
|
27
|
+
const smartDebt = type === 30000 || type === 40000;
|
|
28
|
+
return {
|
|
29
|
+
collateral: side(position.supply, smartSupply ? [vault.supplyToken0, vault.supplyToken1] : [vault.supplyToken0],
|
|
30
|
+
smartSupply ? [vault.dexSupplyData.token0PerSupplyShare, vault.dexSupplyData.token1PerSupplyShare] : undefined),
|
|
31
|
+
debt: side(position.borrow, smartDebt ? [vault.borrowToken0, vault.borrowToken1] : [vault.borrowToken0],
|
|
32
|
+
smartDebt ? [vault.dexBorrowData.token0PerBorrowShare, vault.dexBorrowData.token1PerBorrowShare] : undefined),
|
|
33
|
+
};
|
|
34
|
+
}
|
package/src/liquityV2/index.ts
CHANGED
|
@@ -152,7 +152,7 @@ const getUserTroves = async (
|
|
|
152
152
|
return getUserTroves(provider, network, isLegacy, account, marketAddress, newStartIndex, newStartIndex + 100, existingTroves);
|
|
153
153
|
};
|
|
154
154
|
|
|
155
|
-
const nftContractCreationBlockMapping = {
|
|
155
|
+
export const nftContractCreationBlockMapping = {
|
|
156
156
|
[LiquityV2Versions.LiquityV2Eth]: 22516079,
|
|
157
157
|
[LiquityV2Versions.LiquityV2WstEth]: 22516099,
|
|
158
158
|
[LiquityV2Versions.LiquityV2REth]: 22516118,
|
package/src/llamaLend/index.ts
CHANGED
|
@@ -168,7 +168,7 @@ const getStatusForUser = (bandRange: string[], activeBand: string, debtSupplied:
|
|
|
168
168
|
return LlamaLendStatus.Nonexistant;
|
|
169
169
|
};
|
|
170
170
|
|
|
171
|
-
export const _getLlamaLendAccountBalances = async (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, controllerAddress: EthAddress): Promise<PositionBalances> => {
|
|
171
|
+
export const _getLlamaLendAccountBalances = async (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, controllerAddress: EthAddress, includeDeposited = false): Promise<PositionBalances> => {
|
|
172
172
|
let balances: PositionBalances = {
|
|
173
173
|
collateral: {},
|
|
174
174
|
debt: {},
|
|
@@ -192,6 +192,11 @@ export const _getLlamaLendAccountBalances = async (provider: Client, network: Ne
|
|
|
192
192
|
},
|
|
193
193
|
};
|
|
194
194
|
|
|
195
|
+
if (includeDeposited) {
|
|
196
|
+
balances.deposited = {
|
|
197
|
+
[addressMapping ? getAssetInfo(wethToEth(selectedMarket.baseAsset), network).address.toLowerCase() : wethToEth(selectedMarket.baseAsset)]: data.debtTokenCollateralAmount.toString(),
|
|
198
|
+
};
|
|
199
|
+
}
|
|
195
200
|
return balances;
|
|
196
201
|
};
|
|
197
202
|
|
|
@@ -222,7 +222,7 @@ export async function getMorphoMidnightAccountData(provider: EthereumProvider, n
|
|
|
222
222
|
return _getMorphoMidnightAccountData(getViemProvider(provider, network), network, account, selectedMarket, marketInfo);
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
-
export const _getMorphoMidnightAccountBalances = async (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, selectedMarket: MorphoMidnightMarketData): Promise<PositionBalances> => {
|
|
225
|
+
export const _getMorphoMidnightAccountBalances = async (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, selectedMarket: MorphoMidnightMarketData, includeCredit = false): Promise<PositionBalances> => {
|
|
226
226
|
const balances: PositionBalances = { collateral: {}, debt: {} };
|
|
227
227
|
if (!address) return balances;
|
|
228
228
|
|
|
@@ -244,6 +244,11 @@ export const _getMorphoMidnightAccountBalances = async (provider: Client, networ
|
|
|
244
244
|
});
|
|
245
245
|
balances.collateral = collateral;
|
|
246
246
|
|
|
247
|
+
if (includeCredit) {
|
|
248
|
+
balances.deposited = {
|
|
249
|
+
[addressMapping ? loanTokenInfo.address.toLowerCase() : wethToEth(loanTokenInfo.symbol)]: assetAmountInEth(positionInfo.credit.toString(), wethToEth(loanTokenInfo.symbol)),
|
|
250
|
+
};
|
|
251
|
+
}
|
|
247
252
|
return balances;
|
|
248
253
|
};
|
|
249
254
|
|