@defisaver/positions-sdk 2.0.14-dev-portfolio → 2.0.14-dev-portfolio2
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/config/contracts.d.ts +14 -0
- package/cjs/config/contracts.js +1 -1
- package/cjs/contracts.d.ts +145 -0
- package/cjs/liquityV2/index.d.ts +27 -0
- package/cjs/liquityV2/index.js +136 -162
- package/cjs/morphoBlue/index.js +4 -3
- package/cjs/portfolio/index.js +39 -0
- package/esm/config/contracts.d.ts +14 -0
- package/esm/config/contracts.js +1 -1
- package/esm/contracts.d.ts +145 -0
- package/esm/liquityV2/index.d.ts +27 -0
- package/esm/liquityV2/index.js +137 -165
- package/esm/morphoBlue/index.js +4 -3
- package/esm/portfolio/index.js +40 -1
- package/package.json +1 -1
- package/src/config/contracts.ts +1 -1
- package/src/liquityV2/index.ts +226 -164
- package/src/morphoBlue/index.ts +4 -3
- package/src/portfolio/index.ts +39 -0
package/esm/liquityV2/index.js
CHANGED
|
@@ -9,13 +9,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
11
|
import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
|
|
12
|
-
import { createViemContractFromConfigFunc, LiquityV2LegacyViewContractViem, LiquityV2ViewContractViem, } from '../contracts';
|
|
13
|
-
import { NetworkNumber } from '../types/common';
|
|
12
|
+
import { createViemContractFromConfigFunc, LiquityV2LegacyViewContractViem, LiquityV2sBoldVaultViem, LiquityV2ViewContractViem, } from '../contracts';
|
|
13
|
+
import { NetworkNumber, } from '../types/common';
|
|
14
14
|
import { LIQUITY_V2_TROVE_STATUS_ENUM, LiquityV2Versions, } from '../types';
|
|
15
15
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
16
16
|
import { getLiquityV2AggregatedPositionData } from '../helpers/liquityV2Helpers';
|
|
17
|
-
import { compareAddresses, ethToWeth, MAXUINT, } from '../services/utils';
|
|
18
|
-
import { ZERO_ADDRESS } from '../constants';
|
|
17
|
+
import { compareAddresses, ethToWeth, getEthAmountForDecimals, MAXUINT, } from '../services/utils';
|
|
18
|
+
import { SECONDS_PER_YEAR, ZERO_ADDRESS } from '../constants';
|
|
19
19
|
import { LiquityV2Markets } from '../markets';
|
|
20
20
|
import { getViemProvider } from '../services/viem';
|
|
21
21
|
const getLiquityV2ViewContract = (provider, network, isLegacy) => {
|
|
@@ -286,164 +286,136 @@ export const getLiquityV2ClaimableCollateral = (collSurplusPoolAddress, account,
|
|
|
286
286
|
const claimableCollateral = yield collSurplusPoolContract.read.getCollateral([account]);
|
|
287
287
|
return claimableCollateral.toString();
|
|
288
288
|
});
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
//
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
// aggWeightedDebtSum: aggWeightedDebtSum.toString(),
|
|
423
|
-
// lastAggUpdateTime: lastAggUpdateTime.toString(),
|
|
424
|
-
// P: P.toString(),
|
|
425
|
-
// currentScale: currentScale.toString(),
|
|
426
|
-
// yieldGainsPending: yieldGainsPending.toString(),
|
|
427
|
-
// totalBoldDeposits: totalBoldDeposits.toString(),
|
|
428
|
-
// };
|
|
429
|
-
//
|
|
430
|
-
// const stabilityPoolApy = calculateStabilityPoolApy(stabilityPoolYieldParams);
|
|
431
|
-
//
|
|
432
|
-
// const stakedBOLDBalanceForUser = getEthAmountForDecimals(compoundedBoldDeposit.toString(), 18);
|
|
433
|
-
// const stabilityRewardCollForUser = getEthAmountForDecimals(stabilityRewardColl.toString(), 18);
|
|
434
|
-
// const stabilityRewardYieldForUser = getEthAmountForDecimals(stabilityRewardYield.toString(), 18);
|
|
435
|
-
//
|
|
436
|
-
// const accountData = {
|
|
437
|
-
// totalBOLDDeposited: getEthAmountForDecimals(totalBoldDeposits.toString(), 18),
|
|
438
|
-
// stakedBOLDBalance: stakedBOLDBalanceForUser,
|
|
439
|
-
// stabilityRewardColl: stabilityRewardCollForUser,
|
|
440
|
-
// stabilityRewardYield: stabilityRewardYieldForUser,
|
|
441
|
-
// showStakingBalances: !!(+stakedBOLDBalanceForUser || +stabilityRewardCollForUser || +stabilityRewardYieldForUser),
|
|
442
|
-
// debtTokenBalance: getEthAmountForDecimals(debtTokenBalance.toString(), debtTokenInfo.decimals),
|
|
443
|
-
// };
|
|
444
|
-
//
|
|
445
|
-
//
|
|
446
|
-
// const yBoldApy = await getYBoldApyApi();
|
|
447
|
-
//
|
|
448
|
-
// return yBoldApy;
|
|
449
|
-
// };
|
|
289
|
+
const stabilityPoolAddrForMarket = {
|
|
290
|
+
[LiquityV2Versions.LiquityV2Eth]: '0x5721cbbd64fc7Ae3Ef44A0A3F9a790A9264Cf9BF',
|
|
291
|
+
[LiquityV2Versions.LiquityV2WstEth]: '0x9502b7c397e9aa22fe9db7ef7daf21cd2aebe56b',
|
|
292
|
+
[LiquityV2Versions.LiquityV2REth]: '0xd442e41019b7f5c4dd78f50dc03726c446148695',
|
|
293
|
+
[LiquityV2Versions.LiquityV2EthLegacy]: '0x',
|
|
294
|
+
[LiquityV2Versions.LiquityV2REthLegacy]: '0x',
|
|
295
|
+
[LiquityV2Versions.LiquityV2WstEthLegacy]: '0x',
|
|
296
|
+
};
|
|
297
|
+
const activePoolAddrForMarket = {
|
|
298
|
+
[LiquityV2Versions.LiquityV2Eth]: '0xeB5A8C825582965f1d84606E078620a84ab16AfE',
|
|
299
|
+
[LiquityV2Versions.LiquityV2WstEth]: '0x531a8f99c70d6a56a7cee02d6b4281650d7919a0',
|
|
300
|
+
[LiquityV2Versions.LiquityV2REth]: '0x9074d72cc82dad1e13e454755aa8f144c479532f',
|
|
301
|
+
[LiquityV2Versions.LiquityV2EthLegacy]: '0x',
|
|
302
|
+
[LiquityV2Versions.LiquityV2WstEthLegacy]: '0x',
|
|
303
|
+
[LiquityV2Versions.LiquityV2REthLegacy]: '0x',
|
|
304
|
+
};
|
|
305
|
+
function ceilDiv(a, b) {
|
|
306
|
+
return new Dec(a).add(new Dec(b).sub(1)).div(b).toString();
|
|
307
|
+
}
|
|
308
|
+
const SP_YIELD_SPLIT = new Dec(75).mul(Math.pow(10, 16)).toString(); // 75%
|
|
309
|
+
const calcPendingSPYield = (aggWeightedDebtSum, lastAggUpdateTime, currentTime) => {
|
|
310
|
+
const a = new Dec(aggWeightedDebtSum).mul(new Dec(currentTime).sub(new Dec(lastAggUpdateTime))).toString();
|
|
311
|
+
const b = new Dec(SECONDS_PER_YEAR).mul(1000).mul(1e18).toString();
|
|
312
|
+
return new Dec(ceilDiv(a, b)).mul(SP_YIELD_SPLIT).div(1e18).toString();
|
|
313
|
+
};
|
|
314
|
+
const calculateStabilityPoolApy = (spYieldGainParams) => {
|
|
315
|
+
const { aggWeightedDebtSum, totalBoldDeposits, lastAggUpdateTime, yieldGainsPending, } = spYieldGainParams;
|
|
316
|
+
if (new Dec(totalBoldDeposits).eq(0)) {
|
|
317
|
+
return '0';
|
|
318
|
+
}
|
|
319
|
+
const now = Date.now().toString();
|
|
320
|
+
const lastAggUpdateTimeScaled = new Dec(lastAggUpdateTime).mul(1000).toString();
|
|
321
|
+
const pendingSPYield = new Dec(calcPendingSPYield(aggWeightedDebtSum, lastAggUpdateTimeScaled, now)).add(yieldGainsPending).toString();
|
|
322
|
+
const annualizedYield = new Dec(pendingSPYield).mul(SECONDS_PER_YEAR).mul(1000).div(new Dec(now).minus(lastAggUpdateTimeScaled))
|
|
323
|
+
.toString();
|
|
324
|
+
return new Dec(annualizedYield).div(totalBoldDeposits).mul(100).toString();
|
|
325
|
+
};
|
|
326
|
+
const getYBoldApyApi = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
327
|
+
const url = 'https://ydaemon.yearn.fi/1/vaults/0x23346B04a7f55b8760E5860AA5A77383D63491cD?strategiesDetails=withDetails&strategiesCondition=inQueue';
|
|
328
|
+
const yBoldData = yield fetch(url)
|
|
329
|
+
.then(res => res.json())
|
|
330
|
+
.catch(console.error);
|
|
331
|
+
return new Dec(yBoldData.apr.netAPR).mul(100).toString();
|
|
332
|
+
});
|
|
333
|
+
const calculateSPApy = (spYieldGainParams, spAPYs) => {
|
|
334
|
+
const { WETH, wsETH, rETH, } = spYieldGainParams;
|
|
335
|
+
const apy = new Dec(WETH).mul(spAPYs.apyEth).add(new Dec(wsETH).mul(spAPYs.apyWstEth)).add(new Dec(rETH).mul(spAPYs.apyREth))
|
|
336
|
+
.toString();
|
|
337
|
+
return apy;
|
|
338
|
+
};
|
|
339
|
+
export const getLiquityV2Staking = (provider, network, market, user) => __awaiter(void 0, void 0, void 0, function* () {
|
|
340
|
+
const stabilityPoolView = createViemContractFromConfigFunc('LiquityV2StabilityPool', stabilityPoolAddrForMarket[market])(provider, network);
|
|
341
|
+
const activePoolView = createViemContractFromConfigFunc('LiquityV2ActivePool', activePoolAddrForMarket[market])(provider, network);
|
|
342
|
+
const debtTokenInfo = getAssetInfo(LiquityV2Markets(network)[market].debtToken, network);
|
|
343
|
+
const debtTokenContract = createViemContractFromConfigFunc('Erc20', debtTokenInfo.address)(provider, network);
|
|
344
|
+
const [stabilityRewardColl, stabilityRewardYield, compoundedBoldDeposit, totalBoldDeposits, P, currentScale, yieldGainsPending, debtTokenBalance, aggWeightedDebtSum, lastAggUpdateTime,] = yield Promise.all([
|
|
345
|
+
stabilityPoolView.read.getDepositorCollGain([user]),
|
|
346
|
+
stabilityPoolView.read.getDepositorYieldGain([user]),
|
|
347
|
+
stabilityPoolView.read.getCompoundedBoldDeposit([user]),
|
|
348
|
+
stabilityPoolView.read.getTotalBoldDeposits(),
|
|
349
|
+
stabilityPoolView.read.P(),
|
|
350
|
+
stabilityPoolView.read.currentScale(),
|
|
351
|
+
stabilityPoolView.read.getYieldGainsPending(),
|
|
352
|
+
debtTokenContract.read.balanceOf([user]),
|
|
353
|
+
activePoolView.read.aggWeightedDebtSum(),
|
|
354
|
+
activePoolView.read.lastAggUpdateTime(),
|
|
355
|
+
]);
|
|
356
|
+
const stabilityPoolYieldParams = {
|
|
357
|
+
aggWeightedDebtSum: aggWeightedDebtSum.toString(),
|
|
358
|
+
lastAggUpdateTime: lastAggUpdateTime.toString(),
|
|
359
|
+
P: P.toString(),
|
|
360
|
+
currentScale: currentScale.toString(),
|
|
361
|
+
yieldGainsPending: yieldGainsPending.toString(),
|
|
362
|
+
totalBoldDeposits: totalBoldDeposits.toString(),
|
|
363
|
+
};
|
|
364
|
+
const stabilityPoolApy = calculateStabilityPoolApy(stabilityPoolYieldParams);
|
|
365
|
+
const stakedBOLDBalanceForUser = getEthAmountForDecimals(compoundedBoldDeposit.toString(), 18);
|
|
366
|
+
const stabilityRewardCollForUser = getEthAmountForDecimals(stabilityRewardColl.toString(), 18);
|
|
367
|
+
const stabilityRewardYieldForUser = getEthAmountForDecimals(stabilityRewardYield.toString(), 18);
|
|
368
|
+
return {
|
|
369
|
+
totalBOLDDeposited: getEthAmountForDecimals(totalBoldDeposits.toString(), 18),
|
|
370
|
+
stakedBOLDBalance: stakedBOLDBalanceForUser,
|
|
371
|
+
stabilityRewardColl: stabilityRewardCollForUser,
|
|
372
|
+
stabilityRewardYield: stabilityRewardYieldForUser,
|
|
373
|
+
showStakingBalances: !!(+stakedBOLDBalanceForUser || +stabilityRewardCollForUser || +stabilityRewardYieldForUser),
|
|
374
|
+
debtTokenBalance: getEthAmountForDecimals(debtTokenBalance.toString(), debtTokenInfo.decimals),
|
|
375
|
+
stabilityPoolApy,
|
|
376
|
+
};
|
|
377
|
+
});
|
|
378
|
+
export const getLiquitySAndYBold = (provider, network, markets, user) => __awaiter(void 0, void 0, void 0, function* () {
|
|
379
|
+
const sBold = LiquityV2sBoldVaultViem(provider, network);
|
|
380
|
+
const yBold = createViemContractFromConfigFunc('Erc4626', '0x9F4330700a36B29952869fac9b33f45EEdd8A3d8')(provider, network);
|
|
381
|
+
const stYBold = createViemContractFromConfigFunc('Erc4626', '0x23346B04a7f55b8760E5860AA5A77383D63491cD')(provider, network);
|
|
382
|
+
const spAPYs = {
|
|
383
|
+
apyEth: markets[LiquityV2Versions.LiquityV2Eth].data.stabilityPoolApy,
|
|
384
|
+
apyWstEth: markets[LiquityV2Versions.LiquityV2WstEth].data.stabilityPoolApy,
|
|
385
|
+
apyREth: markets[LiquityV2Versions.LiquityV2REth].data.stabilityPoolApy,
|
|
386
|
+
};
|
|
387
|
+
const [sBoldTotalAssets, sBoldConvertToShares, sBoldMaxWithdraw, wethApy, wsETHApy, rETHApy, yBoldTotalAssets, yBoldMaxWithdraw, stYBoldConvertToShares, yBoldApy, sBoldBalance, yBoldBalance, stYBoldBalance,] = yield Promise.all([
|
|
388
|
+
sBold.read.totalAssets(),
|
|
389
|
+
sBold.read.convertToShares([BigInt(1e18)]),
|
|
390
|
+
sBold.read.maxWithdraw([user]),
|
|
391
|
+
sBold.read.sps([BigInt(0)]),
|
|
392
|
+
sBold.read.sps([BigInt(1)]),
|
|
393
|
+
sBold.read.sps([BigInt(2)]),
|
|
394
|
+
yBold.read.totalAssets(),
|
|
395
|
+
yBold.read.maxWithdraw([user]),
|
|
396
|
+
stYBold.read.convertToShares([BigInt(1e18)]),
|
|
397
|
+
getYBoldApyApi(),
|
|
398
|
+
sBold.read.balanceOf([user]),
|
|
399
|
+
yBold.read.balanceOf([user]),
|
|
400
|
+
stYBold.read.balanceOf([user]),
|
|
401
|
+
]);
|
|
402
|
+
const spMarketRes = {
|
|
403
|
+
WETH: new Dec(wethApy[1]).div(10000).toString(),
|
|
404
|
+
wsETH: new Dec(wsETHApy[1]).div(10000).toString(),
|
|
405
|
+
rETH: new Dec(rETHApy[1]).div(10000).toString(),
|
|
406
|
+
};
|
|
407
|
+
const spApy = calculateSPApy(spMarketRes, spAPYs);
|
|
408
|
+
return {
|
|
409
|
+
spApy,
|
|
410
|
+
yBoldApy,
|
|
411
|
+
totalBoldDepositedSBold: assetAmountInEth(sBoldTotalAssets.toString(), 'sBOLD'),
|
|
412
|
+
boldRateSBold: assetAmountInEth(sBoldConvertToShares.toString(), 'sBOLD'),
|
|
413
|
+
maxWithdrawSBold: assetAmountInEth(sBoldMaxWithdraw.toString(), 'sBOLD'),
|
|
414
|
+
totalBoldDepositedYBold: assetAmountInEth(yBoldTotalAssets.toString(), 'yBOLD'),
|
|
415
|
+
boldRateYBold: assetAmountInEth(stYBoldConvertToShares.toString(), 'yBOLD'),
|
|
416
|
+
maxWithdrawYBold: assetAmountInEth(yBoldMaxWithdraw.toString(), 'yBOLD'),
|
|
417
|
+
sBoldBalance: assetAmountInEth(sBoldBalance.toString(), 'sBOLD'),
|
|
418
|
+
yBoldBalance: assetAmountInEth(yBoldBalance.toString(), 'yBOLD'),
|
|
419
|
+
stYBoldBalance: assetAmountInEth(stYBoldBalance.toString(), 'yBOLD'),
|
|
420
|
+
};
|
|
421
|
+
});
|
package/esm/morphoBlue/index.js
CHANGED
|
@@ -155,15 +155,16 @@ export function _getMorphoBlueAccountData(provider, network, account, selectedMa
|
|
|
155
155
|
]));
|
|
156
156
|
const usedAssets = {};
|
|
157
157
|
const loanTokenInfo = marketInfo.assetsData[marketInfo.loanToken];
|
|
158
|
+
const loanTokenSupplied = assetAmountInEth(loanInfo.suppliedInAssets.toString(), marketInfo.loanToken);
|
|
158
159
|
const loanTokenBorrowed = assetAmountInEth(loanInfo.borrowedInAssets.toString(), marketInfo.loanToken);
|
|
159
160
|
usedAssets[marketInfo.loanToken] = {
|
|
160
161
|
symbol: loanTokenInfo.symbol,
|
|
161
|
-
supplied:
|
|
162
|
+
supplied: loanTokenSupplied,
|
|
162
163
|
borrowed: loanTokenBorrowed,
|
|
163
|
-
isSupplied:
|
|
164
|
+
isSupplied: new Dec(loanInfo.suppliedInAssets.toString()).gt(0),
|
|
164
165
|
isBorrowed: new Dec(loanInfo.borrowedInAssets.toString()).gt(0),
|
|
165
166
|
collateral: false,
|
|
166
|
-
suppliedUsd:
|
|
167
|
+
suppliedUsd: new Dec(loanTokenSupplied).mul(loanTokenInfo.price).toString(),
|
|
167
168
|
borrowedUsd: new Dec(loanTokenBorrowed).mul(loanTokenInfo.price).toString(),
|
|
168
169
|
};
|
|
169
170
|
const collateralTokenInfo = marketInfo.assetsData[marketInfo.collateralToken];
|
package/esm/portfolio/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
11
|
import { NetworkNumber } from '../types/common';
|
|
12
|
-
import { AaveMarkets, CompoundMarkets, CrvUsdMarkets, EulerV2Markets, LlamaLendMarkets, MorphoBlueMarkets, SparkMarkets, } from '../markets';
|
|
12
|
+
import { AaveMarkets, CompoundMarkets, CrvUsdMarkets, EulerV2Markets, LiquityV2Markets, LlamaLendMarkets, MorphoBlueMarkets, SparkMarkets, } from '../markets';
|
|
13
13
|
import { _getMorphoBlueAccountData, _getMorphoBlueMarketData, getMorphoEarn } from '../morphoBlue';
|
|
14
14
|
import { AaveVersions, CompoundVersions, } from '../types';
|
|
15
15
|
import { _getCompoundV3AccountData, _getCompoundV3MarketsData } from '../compoundV3';
|
|
@@ -24,6 +24,7 @@ import { _getAaveV2AccountData, _getAaveV2MarketsData } from '../aaveV2';
|
|
|
24
24
|
import { _getCompoundV2AccountData, _getCompoundV2MarketsData } from '../compoundV2';
|
|
25
25
|
import { getViemProvider } from '../services/viem';
|
|
26
26
|
import { _getLiquityTroveInfo, getLiquityStakingData } from '../liquity';
|
|
27
|
+
import { getLiquityV2Staking, _getLiquityV2MarketData, getLiquitySAndYBold } from '../liquityV2';
|
|
27
28
|
import { _getAllUserEarnPositionsWithFTokens, _getUserPositionsPortfolio } from '../fluid';
|
|
28
29
|
import { getEulerV2SubAccounts } from '../helpers/eulerHelpers';
|
|
29
30
|
import { getUmbrellaData } from '../umbrella';
|
|
@@ -45,6 +46,8 @@ export function getPortfolioData(provider, network, defaultProvider, addresses,
|
|
|
45
46
|
const compoundV2Markets = [CompoundVersions.CompoundV2].map((version) => CompoundMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
|
|
46
47
|
const crvUsdMarkets = Object.values(CrvUsdMarkets(network)).filter((market) => market.chainIds.includes(network));
|
|
47
48
|
const llamaLendMarkets = [NetworkNumber.Eth, NetworkNumber.Arb].includes(network) ? Object.values(LlamaLendMarkets(network)).filter((market) => market.chainIds.includes(network)) : [];
|
|
49
|
+
const liquityV2Markets = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)) : [];
|
|
50
|
+
const liquityV2MarketsStaking = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)).filter(market => !market.isLegacy) : [];
|
|
48
51
|
const client = getViemProvider(provider, network, {
|
|
49
52
|
batch: {
|
|
50
53
|
multicall: {
|
|
@@ -69,6 +72,7 @@ export function getPortfolioData(provider, network, defaultProvider, addresses,
|
|
|
69
72
|
const compoundV2MarketsData = {};
|
|
70
73
|
const crvUsdMarketsData = {};
|
|
71
74
|
const llamaLendMarketsData = {};
|
|
75
|
+
const liquityV2MarketsData = {};
|
|
72
76
|
const markets = {
|
|
73
77
|
morphoMarketsData,
|
|
74
78
|
compoundV3MarketsData,
|
|
@@ -79,6 +83,7 @@ export function getPortfolioData(provider, network, defaultProvider, addresses,
|
|
|
79
83
|
compoundV2MarketsData,
|
|
80
84
|
crvUsdMarketsData,
|
|
81
85
|
llamaLendMarketsData,
|
|
86
|
+
liquityV2MarketsData,
|
|
82
87
|
};
|
|
83
88
|
const positions = {};
|
|
84
89
|
const stakingPositions = {};
|
|
@@ -113,6 +118,7 @@ export function getPortfolioData(provider, network, defaultProvider, addresses,
|
|
|
113
118
|
aaveV2: {},
|
|
114
119
|
compoundV2: {},
|
|
115
120
|
liquity: {},
|
|
121
|
+
liquityV2: {},
|
|
116
122
|
fluid: {
|
|
117
123
|
error: '',
|
|
118
124
|
data: {},
|
|
@@ -166,6 +172,10 @@ export function getPortfolioData(provider, network, defaultProvider, addresses,
|
|
|
166
172
|
const marketData = yield _getLlamaLendGlobalData(client, network, market);
|
|
167
173
|
llamaLendMarketsData[market.value] = marketData;
|
|
168
174
|
})),
|
|
175
|
+
...liquityV2Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
const marketData = yield _getLiquityV2MarketData(client, network, market);
|
|
177
|
+
liquityV2MarketsData[market.value] = marketData;
|
|
178
|
+
})),
|
|
169
179
|
// === INDEPENDENT USER DATA (doesn't depend on market data) ===
|
|
170
180
|
...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
171
181
|
if (!isMainnet)
|
|
@@ -240,6 +250,21 @@ export function getPortfolioData(provider, network, defaultProvider, addresses,
|
|
|
240
250
|
stakingPositions[address.toLowerCase()].umbrella = { error: `Error fetching Umbrella staking data for address ${address}`, data: null };
|
|
241
251
|
}
|
|
242
252
|
})),
|
|
253
|
+
// Liquity V2 staking
|
|
254
|
+
...liquityV2MarketsStaking.map(market => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
255
|
+
try {
|
|
256
|
+
if (!isMainnet) {
|
|
257
|
+
stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: '', data: null };
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const liquityV2StakingData = yield getLiquityV2Staking(client, network, market.value, address);
|
|
261
|
+
stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: '', data: liquityV2StakingData };
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
console.error(`Error fetching Liquity V2 staking data for address ${address}, market ${market.value}:`, error);
|
|
265
|
+
stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: `Error fetching Liquity V2 staking data for address ${address}`, data: null };
|
|
266
|
+
}
|
|
267
|
+
}))).flat(),
|
|
243
268
|
// === REWARDS DATA (independent of market data) ===
|
|
244
269
|
// Batch King rewards
|
|
245
270
|
(() => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -529,6 +554,20 @@ export function getPortfolioData(provider, network, defaultProvider, addresses,
|
|
|
529
554
|
positions[address.toLowerCase()].llamaLend[market.value] = { error: `Error fetching LlamaLend account data for address ${address} on market ${market.value}`, data: null };
|
|
530
555
|
}
|
|
531
556
|
}))).flat(),
|
|
557
|
+
// liquity sBold/yBold and staking options
|
|
558
|
+
...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
559
|
+
try {
|
|
560
|
+
if (!isMainnet) {
|
|
561
|
+
stakingPositions[address.toLowerCase()].liquityV2SBoldYBold = { error: '', data: null };
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
const data = yield getLiquitySAndYBold(client, network, stakingPositions[address.toLowerCase()].liquityV2, address);
|
|
565
|
+
stakingPositions[address.toLowerCase()].liquityV2SBoldYBold = { error: '', data };
|
|
566
|
+
}
|
|
567
|
+
catch (error) {
|
|
568
|
+
console.error(`Error fetching SBold/YBold data for address ${address}:`, error);
|
|
569
|
+
}
|
|
570
|
+
})),
|
|
532
571
|
]);
|
|
533
572
|
return {
|
|
534
573
|
positions,
|
package/package.json
CHANGED
package/src/config/contracts.ts
CHANGED
|
@@ -1191,7 +1191,7 @@ export const LiquityV2ActivePool = {
|
|
|
1191
1191
|
"networks": {}
|
|
1192
1192
|
} as const;
|
|
1193
1193
|
export const LiquityV2sBoldVault = {
|
|
1194
|
-
"abi": [{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"convertToShares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"sps","outputs":[{"internalType":"address","name":"sp","type":"address"},{"internalType":"uint96","name":"weight","type":"uint96"},{"internalType":"address","name":"coll","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}],
|
|
1194
|
+
"abi": [{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"convertToShares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"sps","outputs":[{"internalType":"address","name":"sp","type":"address"},{"internalType":"uint96","name":"weight","type":"uint96"},{"internalType":"address","name":"coll","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}],
|
|
1195
1195
|
"networks": {
|
|
1196
1196
|
"1": {
|
|
1197
1197
|
"address": "0x50bd66d59911f5e086ec87ae43c811e0d059dd11"
|