@defisaver/positions-sdk 2.0.13 → 2.0.14-dev-portfolio
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/CLAUDE.md +32 -0
- package/cjs/aaveV2/index.js +1 -0
- package/cjs/aaveV3/index.d.ts +12 -0
- package/cjs/aaveV3/index.js +93 -1
- package/cjs/claiming/aaveV3.d.ts +9 -0
- package/cjs/claiming/aaveV3.js +148 -0
- package/cjs/claiming/compV3.d.ts +15 -0
- package/cjs/claiming/compV3.js +34 -0
- package/cjs/claiming/index.d.ts +6 -0
- package/cjs/claiming/index.js +46 -0
- package/cjs/claiming/king.d.ts +4 -0
- package/cjs/claiming/king.js +72 -0
- package/cjs/claiming/morphoBlue.d.ts +6 -0
- package/cjs/claiming/morphoBlue.js +113 -0
- package/cjs/claiming/spark.d.ts +6 -0
- package/cjs/claiming/spark.js +188 -0
- package/cjs/config/contracts.d.ts +2667 -0
- package/cjs/config/contracts.js +103 -2
- package/cjs/constants/index.d.ts +4 -0
- package/cjs/constants/index.js +6 -2
- package/cjs/contracts.d.ts +2882 -23
- package/cjs/contracts.js +10 -1
- package/cjs/index.d.ts +2 -1
- package/cjs/index.js +3 -1
- package/cjs/liquity/index.d.ts +11 -0
- package/cjs/liquity/index.js +39 -1
- package/cjs/liquityV2/index.d.ts +8 -0
- package/cjs/liquityV2/index.js +161 -0
- package/cjs/markets/aave/marketAssets.js +1 -1
- package/cjs/markets/compound/marketsAssets.js +2 -2
- package/cjs/markets/spark/marketAssets.js +1 -1
- package/cjs/morphoBlue/index.d.ts +5 -0
- package/cjs/morphoBlue/index.js +38 -4
- package/cjs/portfolio/index.d.ts +6 -1
- package/cjs/portfolio/index.js +256 -10
- package/cjs/services/utils.d.ts +5 -0
- package/cjs/services/utils.js +33 -1
- package/cjs/services/viem.d.ts +12 -12
- package/cjs/spark/index.js +1 -0
- package/cjs/staking/staking.js +3 -1
- package/cjs/types/claiming.d.ts +93 -0
- package/cjs/types/claiming.js +27 -0
- package/cjs/umbrella/index.d.ts +5 -0
- package/cjs/umbrella/index.js +50 -0
- package/cjs/umbrella/umbrellaUtils.d.ts +22 -0
- package/cjs/umbrella/umbrellaUtils.js +34 -0
- package/esm/aaveV2/index.js +1 -0
- package/esm/aaveV3/index.d.ts +12 -0
- package/esm/aaveV3/index.js +91 -1
- package/esm/claiming/aaveV3.d.ts +9 -0
- package/esm/claiming/aaveV3.js +139 -0
- package/esm/claiming/compV3.d.ts +15 -0
- package/esm/claiming/compV3.js +30 -0
- package/esm/claiming/index.d.ts +6 -0
- package/esm/claiming/index.js +6 -0
- package/esm/claiming/king.d.ts +4 -0
- package/esm/claiming/king.js +64 -0
- package/esm/claiming/morphoBlue.d.ts +6 -0
- package/esm/claiming/morphoBlue.js +104 -0
- package/esm/claiming/spark.d.ts +6 -0
- package/esm/claiming/spark.js +179 -0
- package/esm/config/contracts.d.ts +2667 -0
- package/esm/config/contracts.js +102 -1
- package/esm/constants/index.d.ts +4 -0
- package/esm/constants/index.js +5 -1
- package/esm/contracts.d.ts +2882 -23
- package/esm/contracts.js +9 -0
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -1
- package/esm/liquity/index.d.ts +11 -0
- package/esm/liquity/index.js +38 -1
- package/esm/liquityV2/index.d.ts +8 -0
- package/esm/liquityV2/index.js +162 -1
- package/esm/markets/aave/marketAssets.js +1 -1
- package/esm/markets/compound/marketsAssets.js +2 -2
- package/esm/markets/spark/marketAssets.js +1 -1
- package/esm/morphoBlue/index.d.ts +5 -0
- package/esm/morphoBlue/index.js +38 -5
- package/esm/portfolio/index.d.ts +6 -1
- package/esm/portfolio/index.js +260 -14
- package/esm/services/utils.d.ts +5 -0
- package/esm/services/utils.js +31 -0
- package/esm/services/viem.d.ts +12 -12
- package/esm/spark/index.js +1 -0
- package/esm/staking/staking.js +3 -1
- package/esm/types/claiming.d.ts +93 -0
- package/esm/types/claiming.js +24 -0
- package/esm/umbrella/index.d.ts +5 -0
- package/esm/umbrella/index.js +46 -0
- package/esm/umbrella/umbrellaUtils.d.ts +22 -0
- package/esm/umbrella/umbrellaUtils.js +28 -0
- package/package.json +2 -2
- package/src/aaveV2/index.ts +2 -1
- package/src/aaveV3/index.ts +100 -2
- package/src/claiming/aaveV3.ts +163 -0
- package/src/claiming/compV3.ts +23 -0
- package/src/claiming/index.ts +13 -0
- package/src/claiming/king.ts +66 -0
- package/src/claiming/morphoBlue.ts +119 -0
- package/src/claiming/spark.ts +226 -0
- package/src/config/contracts.ts +105 -5
- package/src/constants/index.ts +5 -1
- package/src/contracts.ts +14 -1
- package/src/index.ts +2 -0
- package/src/liquity/index.ts +57 -2
- package/src/liquityV2/index.ts +177 -2
- package/src/markets/aave/marketAssets.ts +1 -1
- package/src/markets/compound/marketsAssets.ts +2 -2
- package/src/markets/spark/marketAssets.ts +1 -1
- package/src/morphoBlue/index.ts +43 -6
- package/src/portfolio/index.ts +263 -15
- package/src/services/utils.ts +37 -1
- package/src/spark/index.ts +2 -1
- package/src/staking/staking.ts +2 -1
- package/src/types/claiming.ts +109 -0
- package/src/umbrella/index.ts +70 -0
- package/src/umbrella/umbrellaUtils.ts +30 -0
package/src/contracts.ts
CHANGED
|
@@ -105,4 +105,17 @@ export const LiquityActivePoolContractViem = createViemContractFromConfigFunc('L
|
|
|
105
105
|
export const LiquityV2ViewContractViem = createViemContractFromConfigFunc('LiquityV2View');
|
|
106
106
|
export const LiquityV2LegacyViewContractViem = createViemContractFromConfigFunc('LiquityV2LegacyView');
|
|
107
107
|
|
|
108
|
-
export const FluidViewContractViem = createViemContractFromConfigFunc('FluidView');
|
|
108
|
+
export const FluidViewContractViem = createViemContractFromConfigFunc('FluidView');
|
|
109
|
+
|
|
110
|
+
export const AaveIncentivesControllerViem = createViemContractFromConfigFunc('AaveIncentivesController');
|
|
111
|
+
export const AaveUmbrellaViewViem = createViemContractFromConfigFunc('AaveUmbrellaView');
|
|
112
|
+
|
|
113
|
+
export const LiquityLQTYStakingViem = createViemContractFromConfigFunc('LiquityLQTYStaking');
|
|
114
|
+
export const LiquityStabilityPoolViem = createViemContractFromConfigFunc('LiquityStabilityPool');
|
|
115
|
+
|
|
116
|
+
export const UUPSViem = createViemContractFromConfigFunc('UUPS');
|
|
117
|
+
export const SparkRewardsControllerViem = createViemContractFromConfigFunc('SparkRewardsController');
|
|
118
|
+
|
|
119
|
+
export const AaveRewardsControllerViem = createViemContractFromConfigFunc('AaveRewardsController');
|
|
120
|
+
export const LiquityV2sBoldVaultViem = createViemContractFromConfigFunc('LiquityV2sBoldVault');
|
|
121
|
+
export const StkAAVEViem = createViemContractFromConfigFunc('StkAAVE');
|
package/src/index.ts
CHANGED
|
@@ -19,6 +19,7 @@ import * as morphoBlue from './morphoBlue';
|
|
|
19
19
|
import * as llamaLend from './llamaLend';
|
|
20
20
|
import * as eulerV2 from './eulerV2';
|
|
21
21
|
import * as portfolio from './portfolio';
|
|
22
|
+
import * as claiming from './claiming';
|
|
22
23
|
|
|
23
24
|
export * from './types';
|
|
24
25
|
|
|
@@ -42,4 +43,5 @@ export {
|
|
|
42
43
|
eulerV2,
|
|
43
44
|
fluid,
|
|
44
45
|
portfolio,
|
|
46
|
+
claiming,
|
|
45
47
|
};
|
package/src/liquity/index.ts
CHANGED
|
@@ -5,11 +5,18 @@ import {
|
|
|
5
5
|
Blockish, EthAddress, EthereumProvider, NetworkNumber, PositionBalances,
|
|
6
6
|
} from '../types/common';
|
|
7
7
|
import {
|
|
8
|
-
LiquityActivePoolContractViem,
|
|
8
|
+
LiquityActivePoolContractViem,
|
|
9
|
+
LiquityCollSurplusPoolContractViem,
|
|
10
|
+
LiquityLQTYStakingViem,
|
|
11
|
+
LiquityPriceFeedContractViem,
|
|
12
|
+
LiquityStabilityPoolViem,
|
|
13
|
+
LiquityTroveManagerContractViem,
|
|
14
|
+
LiquityViewContractViem,
|
|
9
15
|
} from '../contracts';
|
|
10
16
|
import { LIQUITY_TROVE_STATUS_ENUM, LiquityTroveInfo } from '../types';
|
|
11
17
|
import { ZERO_ADDRESS } from '../constants';
|
|
12
18
|
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
19
|
+
import { getEthAmountForDecimals } from '../services/utils';
|
|
13
20
|
|
|
14
21
|
export const LIQUITY_NORMAL_MODE_RATIO = 110; // MCR
|
|
15
22
|
export const LIQUITY_RECOVERY_MODE_RATIO = 150; // CCR
|
|
@@ -102,4 +109,52 @@ export const _getLiquityTroveInfo = async (provider: Client, network: NetworkNum
|
|
|
102
109
|
return payload;
|
|
103
110
|
};
|
|
104
111
|
|
|
105
|
-
export const getLiquityTroveInfo = async (provider: EthereumProvider, network: NetworkNumber, address: EthAddress): Promise<LiquityTroveInfo> => _getLiquityTroveInfo(getViemProvider(provider, network, { batch: { multicall: true } }), network, address);
|
|
112
|
+
export const getLiquityTroveInfo = async (provider: EthereumProvider, network: NetworkNumber, address: EthAddress): Promise<LiquityTroveInfo> => _getLiquityTroveInfo(getViemProvider(provider, network, { batch: { multicall: true } }), network, address);
|
|
113
|
+
|
|
114
|
+
export const getLiquityStakingData = async (provider: Client, network: NetworkNumber, address: EthAddress) => {
|
|
115
|
+
const lqtyStakingView = LiquityLQTYStakingViem(provider, network);
|
|
116
|
+
const stabilityPoolView = LiquityStabilityPoolViem(provider, network);
|
|
117
|
+
const [
|
|
118
|
+
stakes,
|
|
119
|
+
pendingETHGain,
|
|
120
|
+
pendingLUSDGain,
|
|
121
|
+
totalLQTYStakes,
|
|
122
|
+
stabilityPoolETHGain,
|
|
123
|
+
stabilityPoolLQTYGain,
|
|
124
|
+
compoundedLUSDDeposit,
|
|
125
|
+
totalLUSDDeposits,
|
|
126
|
+
] = await Promise.all([
|
|
127
|
+
lqtyStakingView.read.stakes([address]),
|
|
128
|
+
lqtyStakingView.read.getPendingETHGain([address]),
|
|
129
|
+
lqtyStakingView.read.getPendingLUSDGain([address]),
|
|
130
|
+
lqtyStakingView.read.totalLQTYStaked(),
|
|
131
|
+
stabilityPoolView.read.getDepositorETHGain([address]),
|
|
132
|
+
stabilityPoolView.read.getDepositorLQTYGain([address]),
|
|
133
|
+
stabilityPoolView.read.getCompoundedLUSDDeposit([address]),
|
|
134
|
+
stabilityPoolView.read.getTotalLUSDDeposits(),
|
|
135
|
+
]);
|
|
136
|
+
const totalLUSDDeposited = getEthAmountForDecimals(totalLUSDDeposits as string, 18);
|
|
137
|
+
const totalLQTYStaked = getEthAmountForDecimals(totalLQTYStakes as string, 18);
|
|
138
|
+
const stakedLQTY = getEthAmountForDecimals(stakes as string, 18);
|
|
139
|
+
const stakedLUSDBalance = getEthAmountForDecimals(compoundedLUSDDeposit as string, 18);
|
|
140
|
+
const rewardETH = getEthAmountForDecimals(pendingETHGain as string, 18);
|
|
141
|
+
const rewardLUSD = getEthAmountForDecimals(pendingLUSDGain as string, 18);
|
|
142
|
+
const stabilityRewardETH = getEthAmountForDecimals(stabilityPoolETHGain as string, 18);
|
|
143
|
+
const stabilityRewardLQTY = getEthAmountForDecimals(stabilityPoolLQTYGain as string, 18);
|
|
144
|
+
|
|
145
|
+
const showStakingBalances = !!(+stakedLQTY || +stakedLUSDBalance
|
|
146
|
+
|| +rewardETH || +rewardLUSD
|
|
147
|
+
|| +stabilityRewardETH || +stabilityRewardLQTY);
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
totalLUSDDeposited,
|
|
151
|
+
totalLQTYStaked,
|
|
152
|
+
stakedLQTY,
|
|
153
|
+
stakedLUSDBalance,
|
|
154
|
+
rewardETH,
|
|
155
|
+
rewardLUSD,
|
|
156
|
+
stabilityRewardETH,
|
|
157
|
+
stabilityRewardLQTY,
|
|
158
|
+
showStakingBalances,
|
|
159
|
+
};
|
|
160
|
+
};
|
package/src/liquityV2/index.ts
CHANGED
|
@@ -2,7 +2,9 @@ import Dec from 'decimal.js';
|
|
|
2
2
|
import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
|
|
3
3
|
import { Client, PublicClient } from 'viem';
|
|
4
4
|
import {
|
|
5
|
-
createViemContractFromConfigFunc,
|
|
5
|
+
createViemContractFromConfigFunc,
|
|
6
|
+
LiquityV2LegacyViewContractViem,
|
|
7
|
+
LiquityV2ViewContractViem,
|
|
6
8
|
} from '../contracts';
|
|
7
9
|
import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
|
|
8
10
|
import {
|
|
@@ -12,11 +14,22 @@ import {
|
|
|
12
14
|
} from '../types';
|
|
13
15
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
14
16
|
import { getLiquityV2AggregatedPositionData } from '../helpers/liquityV2Helpers';
|
|
15
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
compareAddresses, ethToWeth, MAXUINT,
|
|
19
|
+
} from '../services/utils';
|
|
16
20
|
import { ZERO_ADDRESS } from '../constants';
|
|
17
21
|
import { LiquityV2Markets } from '../markets';
|
|
18
22
|
import { getViemProvider } from '../services/viem';
|
|
19
23
|
|
|
24
|
+
export type SPYieldGainParameters = {
|
|
25
|
+
P: string;
|
|
26
|
+
aggWeightedDebtSum: string;
|
|
27
|
+
currentScale: string;
|
|
28
|
+
lastAggUpdateTime: string;
|
|
29
|
+
totalBoldDeposits: string;
|
|
30
|
+
yieldGainsPending: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
20
33
|
const getLiquityV2ViewContract = (provider: Client, network: NetworkNumber, isLegacy: boolean) => {
|
|
21
34
|
if (isLegacy) return LiquityV2LegacyViewContractViem(provider, network);
|
|
22
35
|
return LiquityV2ViewContractViem(provider, network);
|
|
@@ -406,3 +419,165 @@ export const getLiquityV2ClaimableCollateral = async (collSurplusPoolAddress: Et
|
|
|
406
419
|
const claimableCollateral = await collSurplusPoolContract.read.getCollateral([account]);
|
|
407
420
|
return claimableCollateral.toString();
|
|
408
421
|
};
|
|
422
|
+
|
|
423
|
+
// const stabilityPoolAddrForMarket: Record<LiquityV2Versions, EthAddress> = {
|
|
424
|
+
// [LiquityV2Versions.LiquityV2Eth]: '0x5721cbbd64fc7Ae3Ef44A0A3F9a790A9264Cf9BF',
|
|
425
|
+
// [LiquityV2Versions.LiquityV2WstEth]: '0x9502b7c397e9aa22fe9db7ef7daf21cd2aebe56b',
|
|
426
|
+
// [LiquityV2Versions.LiquityV2REth]: '0xd442e41019b7f5c4dd78f50dc03726c446148695',
|
|
427
|
+
// [LiquityV2Versions.LiquityV2EthLegacy]: '0x',
|
|
428
|
+
// [LiquityV2Versions.LiquityV2REthLegacy]: '0x',
|
|
429
|
+
// [LiquityV2Versions.LiquityV2WstEthLegacy]: '0x',
|
|
430
|
+
// };
|
|
431
|
+
// const activePoolAddrForMarket: Record<LiquityV2Versions, EthAddress> = {
|
|
432
|
+
// [LiquityV2Versions.LiquityV2Eth]: '0xeB5A8C825582965f1d84606E078620a84ab16AfE',
|
|
433
|
+
// [LiquityV2Versions.LiquityV2WstEth]: '0x531a8f99c70d6a56a7cee02d6b4281650d7919a0',
|
|
434
|
+
// [LiquityV2Versions.LiquityV2REth]: '0x9074d72cc82dad1e13e454755aa8f144c479532f',
|
|
435
|
+
// [LiquityV2Versions.LiquityV2EthLegacy]: '0x',
|
|
436
|
+
// [LiquityV2Versions.LiquityV2WstEthLegacy]: '0x',
|
|
437
|
+
// [LiquityV2Versions.LiquityV2REthLegacy]: '0x',
|
|
438
|
+
// };
|
|
439
|
+
//
|
|
440
|
+
// function ceilDiv(a: string, b: string) {
|
|
441
|
+
// return new Dec(a).add(new Dec(b).sub(1)).div(b).toString();
|
|
442
|
+
// }
|
|
443
|
+
// const SP_YIELD_SPLIT = new Dec(75).mul(10 ** 16).toString(); // 75%
|
|
444
|
+
//
|
|
445
|
+
// const calcPendingSPYield = (
|
|
446
|
+
// aggWeightedDebtSum: string,
|
|
447
|
+
// lastAggUpdateTime: string,
|
|
448
|
+
// currentTime: string,
|
|
449
|
+
// ) => {
|
|
450
|
+
// const a = new Dec(aggWeightedDebtSum).mul(
|
|
451
|
+
// new Dec(currentTime).sub(new Dec(lastAggUpdateTime)),
|
|
452
|
+
// ).toString();
|
|
453
|
+
// const b = new Dec(SECONDS_PER_YEAR).mul(1000).mul(1e18).toString();
|
|
454
|
+
// return new Dec(ceilDiv(a, b)).mul(SP_YIELD_SPLIT).div(1e18).toString();
|
|
455
|
+
// };
|
|
456
|
+
//
|
|
457
|
+
//
|
|
458
|
+
// const calculateStabilityPoolApy = (
|
|
459
|
+
// spYieldGainParams: SPYieldGainParameters,
|
|
460
|
+
// ) => {
|
|
461
|
+
// const {
|
|
462
|
+
// aggWeightedDebtSum, totalBoldDeposits, lastAggUpdateTime, yieldGainsPending,
|
|
463
|
+
// } = spYieldGainParams;
|
|
464
|
+
//
|
|
465
|
+
// if (new Dec(totalBoldDeposits).eq(0)) {
|
|
466
|
+
// return '0';
|
|
467
|
+
// }
|
|
468
|
+
//
|
|
469
|
+
// const now = Date.now().toString();
|
|
470
|
+
// const lastAggUpdateTimeScaled = new Dec(lastAggUpdateTime).mul(1000).toString();
|
|
471
|
+
//
|
|
472
|
+
// const pendingSPYield = new Dec(calcPendingSPYield(
|
|
473
|
+
// aggWeightedDebtSum,
|
|
474
|
+
// lastAggUpdateTimeScaled,
|
|
475
|
+
// now,
|
|
476
|
+
// )).add(yieldGainsPending).toString();
|
|
477
|
+
//
|
|
478
|
+
// const annualizedYield = new Dec(pendingSPYield).mul(SECONDS_PER_YEAR).mul(1000).div(new Dec(now).minus(lastAggUpdateTimeScaled))
|
|
479
|
+
// .toString();
|
|
480
|
+
// return new Dec(annualizedYield).div(totalBoldDeposits).mul(100).toString();
|
|
481
|
+
// };
|
|
482
|
+
//
|
|
483
|
+
// const getYBoldApyApi = async () => {
|
|
484
|
+
// const url = 'https://ydaemon.yearn.fi/1/vaults/0x23346B04a7f55b8760E5860AA5A77383D63491cD?strategiesDetails=withDetails&strategiesCondition=inQueue';
|
|
485
|
+
//
|
|
486
|
+
// const yBoldData = await fetch(url)
|
|
487
|
+
// .then(res => res.json())
|
|
488
|
+
// .catch(console.error);
|
|
489
|
+
//
|
|
490
|
+
// return new Dec(yBoldData.apr.netAPR).mul(100).toString();
|
|
491
|
+
// };
|
|
492
|
+
//
|
|
493
|
+
// export const getLiquityV2Staking = async (provider: Client, network: NetworkNumber, market: LiquityV2Versions, user: EthAddress) => {
|
|
494
|
+
// const stabilityPoolView = createViemContractFromConfigFunc('LiquityV2StabilityPool', stabilityPoolAddrForMarket[market])(provider, network);
|
|
495
|
+
// const activePoolView = createViemContractFromConfigFunc('LiquityV2ActivePool', activePoolAddrForMarket[market])(provider, network);
|
|
496
|
+
//
|
|
497
|
+
// const sBold = LiquityV2sBoldVaultViem(provider, network);
|
|
498
|
+
// const yBold = createViemContractFromConfigFunc('Erc4626', '0x9F4330700a36B29952869fac9b33f45EEdd8A3d8')(provider, network);
|
|
499
|
+
// const stYBold = createViemContractFromConfigFunc('Erc4626', '0x23346B04a7f55b8760E5860AA5A77383D63491cD')(provider, network);
|
|
500
|
+
//
|
|
501
|
+
// const debtTokenInfo = getAssetInfo(LiquityV2Markets(network)[market].debtToken);
|
|
502
|
+
// const debtTokenContract = createViemContractFromConfigFunc('Erc20', debtTokenInfo.address)(provider, network);
|
|
503
|
+
//
|
|
504
|
+
// const [
|
|
505
|
+
// stabilityRewardColl,
|
|
506
|
+
// stabilityRewardYield,
|
|
507
|
+
// compoundedBoldDeposit,
|
|
508
|
+
// totalBoldDeposits,
|
|
509
|
+
// P,
|
|
510
|
+
// currentScale,
|
|
511
|
+
// yieldGainsPending,
|
|
512
|
+
// debtTokenBalance,
|
|
513
|
+
//
|
|
514
|
+
// aggWeightedDebtSum,
|
|
515
|
+
// lastAggUpdateTime,
|
|
516
|
+
//
|
|
517
|
+
// sBoldTotalAssets,
|
|
518
|
+
// sBoldConvertToShares,
|
|
519
|
+
// sBoldMaxWithdraw,
|
|
520
|
+
//
|
|
521
|
+
// wethApy,
|
|
522
|
+
// wsETHApy,
|
|
523
|
+
// rETHApy,
|
|
524
|
+
//
|
|
525
|
+
// yBoldTotalAssets,
|
|
526
|
+
// yBoldMaxWithdraw,
|
|
527
|
+
// stYBoldConvertToShares,
|
|
528
|
+
// ] = await Promise.all([
|
|
529
|
+
// stabilityPoolView.read.getDepositorCollGain([user]),
|
|
530
|
+
// stabilityPoolView.read.getDepositorYieldGain([user]),
|
|
531
|
+
// stabilityPoolView.read.getCompoundedBoldDeposit([user]),
|
|
532
|
+
// stabilityPoolView.read.getTotalBoldDeposits(),
|
|
533
|
+
// stabilityPoolView.read.P(),
|
|
534
|
+
// stabilityPoolView.read.currentScale(),
|
|
535
|
+
// stabilityPoolView.read.getYieldGainsPending(),
|
|
536
|
+
// debtTokenContract.read.balanceOf([user]),
|
|
537
|
+
//
|
|
538
|
+
// activePoolView.read.aggWeightedDebtSum(),
|
|
539
|
+
// activePoolView.read.lastAggUpdateTime(),
|
|
540
|
+
//
|
|
541
|
+
// sBold.read.totalAssets(),
|
|
542
|
+
// sBold.read.convertToShares([BigInt(1e18)]),
|
|
543
|
+
// sBold.read.maxWithdraw([user]),
|
|
544
|
+
//
|
|
545
|
+
// sBold.read.sps([BigInt(0)]),
|
|
546
|
+
// sBold.read.sps([BigInt(1)]),
|
|
547
|
+
// sBold.read.sps([BigInt(2)]),
|
|
548
|
+
//
|
|
549
|
+
// yBold.read.totalAssets(),
|
|
550
|
+
// yBold.read.maxWithdraw([user]),
|
|
551
|
+
// stYBold.read.convertToShares([BigInt(1e18)]),
|
|
552
|
+
// ]);
|
|
553
|
+
//
|
|
554
|
+
//
|
|
555
|
+
// const stabilityPoolYieldParams: SPYieldGainParameters = {
|
|
556
|
+
// aggWeightedDebtSum: aggWeightedDebtSum.toString(),
|
|
557
|
+
// lastAggUpdateTime: lastAggUpdateTime.toString(),
|
|
558
|
+
// P: P.toString(),
|
|
559
|
+
// currentScale: currentScale.toString(),
|
|
560
|
+
// yieldGainsPending: yieldGainsPending.toString(),
|
|
561
|
+
// totalBoldDeposits: totalBoldDeposits.toString(),
|
|
562
|
+
// };
|
|
563
|
+
//
|
|
564
|
+
// const stabilityPoolApy = calculateStabilityPoolApy(stabilityPoolYieldParams);
|
|
565
|
+
//
|
|
566
|
+
// const stakedBOLDBalanceForUser = getEthAmountForDecimals(compoundedBoldDeposit.toString(), 18);
|
|
567
|
+
// const stabilityRewardCollForUser = getEthAmountForDecimals(stabilityRewardColl.toString(), 18);
|
|
568
|
+
// const stabilityRewardYieldForUser = getEthAmountForDecimals(stabilityRewardYield.toString(), 18);
|
|
569
|
+
//
|
|
570
|
+
// const accountData = {
|
|
571
|
+
// totalBOLDDeposited: getEthAmountForDecimals(totalBoldDeposits.toString(), 18),
|
|
572
|
+
// stakedBOLDBalance: stakedBOLDBalanceForUser,
|
|
573
|
+
// stabilityRewardColl: stabilityRewardCollForUser,
|
|
574
|
+
// stabilityRewardYield: stabilityRewardYieldForUser,
|
|
575
|
+
// showStakingBalances: !!(+stakedBOLDBalanceForUser || +stabilityRewardCollForUser || +stabilityRewardYieldForUser),
|
|
576
|
+
// debtTokenBalance: getEthAmountForDecimals(debtTokenBalance.toString(), debtTokenInfo.decimals),
|
|
577
|
+
// };
|
|
578
|
+
//
|
|
579
|
+
//
|
|
580
|
+
// const yBoldApy = await getYBoldApyApi();
|
|
581
|
+
//
|
|
582
|
+
// return yBoldApy;
|
|
583
|
+
// };
|
|
@@ -10,7 +10,7 @@ export const aaveV2AssetsDefaultMarket = ['USDT', 'WBTC', 'ETH', 'YFI', 'ZRX', '
|
|
|
10
10
|
|
|
11
11
|
export const aaveV3AssetsDefaultMarketEth = [
|
|
12
12
|
'ETH', 'wstETH', 'WBTC', 'USDC', 'DAI', 'LINK', 'AAVE', 'cbETH', 'USDT', 'rETH', 'LUSD', 'CRV', 'MKR', 'SNX', 'BAL', 'UNI', 'LDO', 'ENS', '1INCH', 'FRAX', 'GHO', 'RPL', 'sDAI', 'STG', 'KNC', 'FXS', 'crvUSD', 'PYUSD', 'weETH', 'osETH', 'USDe', 'ETHx', 'sUSDe', 'tBTC', 'cbBTC', 'USDS', 'rsETH', 'LBTC', 'eBTC', 'RLUSD', 'PT eUSDe May', 'PT sUSDe July', 'USDtb',
|
|
13
|
-
'eUSDe', 'PT USDe July', 'PT eUSDe Aug', 'EURC', 'FBTC', 'PT sUSDe Sep', 'PT USDe Sep', 'tETH', 'ezETH', 'XAUt', 'PT sUSDe Nov',
|
|
13
|
+
'eUSDe', 'PT USDe July', 'PT eUSDe Aug', 'EURC', 'FBTC', 'PT sUSDe Sep', 'PT USDe Sep', 'tETH', 'ezETH', 'XAUt', 'PT sUSDe Nov', 'PT USDe Nov',
|
|
14
14
|
];
|
|
15
15
|
export const aaveV3AssetsDefaultMarketOpt = [
|
|
16
16
|
'DAI', 'USDC.e', 'USDT', 'SUSD', 'AAVE', 'LINK', 'WBTC', 'ETH', 'OP', 'wstETH', 'LUSD', 'MAI', 'rETH', 'USDC',
|
|
@@ -6,7 +6,7 @@ export const compoundV2CollateralAssets: AssetData[] = [
|
|
|
6
6
|
'cTUSD', 'cLINK', 'cUSDP', 'cUNI', 'cCOMP', 'cMKR', 'cSUSHI', 'cAAVE', 'cYFI',
|
|
7
7
|
].map((symbol) => getAssetInfo(symbol));
|
|
8
8
|
|
|
9
|
-
export const v3USDCCollAssetsEth = ['COMP', 'WBTC', 'ETH', 'UNI', 'LINK', 'wstETH', 'cbBTC', 'tBTC', 'weETH', 'deUSD', 'sdeUSD'];
|
|
9
|
+
export const v3USDCCollAssetsEth = ['COMP', 'WBTC', 'ETH', 'UNI', 'LINK', 'wstETH', 'cbBTC', 'tBTC', 'weETH', 'deUSD', 'sdeUSD', 'rsETH'];
|
|
10
10
|
export const v3USDCCollAssetsArb = ['ARB', 'ETH', 'GMX', 'WBTC', 'wstETH', 'ezETH', 'wUSDM'];
|
|
11
11
|
export const v3USDCCollAssetsBase = ['cbETH', 'ETH', 'wstETH', 'cbBTC', 'tBTC'];
|
|
12
12
|
export const v3USDCCollAssetsOpt = ['ETH', 'OP', 'WBTC', 'wstETH'];
|
|
@@ -56,7 +56,7 @@ export const v3USDbCCollAssets = {
|
|
|
56
56
|
[NetworkNumber.Linea]: [],
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
export const v3USDTCollAssetsEth = ['COMP', 'ETH', 'WBTC', 'UNI', 'LINK', 'wstETH', 'cbBTC', 'tBTC', 'sFRAX', 'mETH', 'weETH', 'sdeUSD', 'deUSD'];
|
|
59
|
+
export const v3USDTCollAssetsEth = ['COMP', 'ETH', 'WBTC', 'UNI', 'LINK', 'wstETH', 'cbBTC', 'tBTC', 'wUSDM', 'sFRAX', 'mETH', 'weETH', 'sdeUSD', 'deUSD'];
|
|
60
60
|
export const v3USDTCollAssetsArb = ['ETH', 'WBTC', 'wstETH', 'ARB', 'GMX'];
|
|
61
61
|
export const v3USDTCollAssetsOpt = ['ETH', 'WBTC', 'OP', 'wstETH'];
|
|
62
62
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NetworkNumber } from '../../types/common';
|
|
2
2
|
|
|
3
|
-
export const sparkAssetsDefaultMarketEth = ['DAI', 'sDAI', 'USDC', 'ETH', 'wstETH', 'WBTC', 'GNO', 'rETH', 'USDT', 'weETH', 'cbBTC', 'sUSDS', 'USDS', 'LBTC', 'tBTC', 'ezETH', 'rsETH'];
|
|
3
|
+
export const sparkAssetsDefaultMarketEth = ['DAI', 'sDAI', 'USDC', 'ETH', 'wstETH', 'WBTC', 'GNO', 'rETH', 'USDT', 'weETH', 'cbBTC', 'sUSDS', 'USDS', 'LBTC', 'tBTC', 'ezETH', 'rsETH', 'PYUSD'];
|
|
4
4
|
|
|
5
5
|
// @dev Keep assets in array, do not assign directly, so we can parse it and edit it programmatically with `scripts/updateMarkets`
|
|
6
6
|
export const sparkAssetsDefaultMarket = {
|
package/src/morphoBlue/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import Dec from 'decimal.js';
|
|
|
2
2
|
import { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
3
3
|
import { Client } from 'viem';
|
|
4
4
|
import {
|
|
5
|
-
Blockish, EthAddress, EthereumProvider, MMUsedAssets, NetworkNumber, PositionBalances,
|
|
5
|
+
Blockish, EthAddress, EthereumProvider, MMAssetsData, MMUsedAssets, NetworkNumber, PositionBalances,
|
|
6
6
|
} from '../types/common';
|
|
7
7
|
import {
|
|
8
8
|
DFSFeedRegistryContractViem, FeedRegistryContractViem, MorphoBlueViewContractViem,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
MorphoBlueAssetsData, MorphoBlueMarketData, MorphoBlueMarketInfo, MorphoBluePositionData,
|
|
12
12
|
} from '../types';
|
|
13
13
|
import { USD_QUOTE, WAD } from '../constants';
|
|
14
|
-
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
14
|
+
import { calculateNetApy, getStakingApy, STAKING_ASSETS } from '../staking';
|
|
15
15
|
import { isMainnetNetwork, wethToEth } from '../services/utils';
|
|
16
16
|
import {
|
|
17
17
|
getBorrowRate, getMorphoBlueAggregatedPositionData, getRewardsForMarket, getSupplyRate,
|
|
@@ -184,16 +184,15 @@ export async function _getMorphoBlueAccountData(provider: Client, network: Netwo
|
|
|
184
184
|
const usedAssets: MMUsedAssets = {};
|
|
185
185
|
|
|
186
186
|
const loanTokenInfo = marketInfo.assetsData[marketInfo.loanToken];
|
|
187
|
-
const loanTokenSupplied = assetAmountInEth(loanInfo.suppliedInAssets.toString(), marketInfo.loanToken);
|
|
188
187
|
const loanTokenBorrowed = assetAmountInEth(loanInfo.borrowedInAssets.toString(), marketInfo.loanToken);
|
|
189
188
|
usedAssets[marketInfo.loanToken] = {
|
|
190
189
|
symbol: loanTokenInfo.symbol,
|
|
191
|
-
supplied:
|
|
190
|
+
supplied: '0',
|
|
192
191
|
borrowed: loanTokenBorrowed,
|
|
193
|
-
isSupplied:
|
|
192
|
+
isSupplied: false,
|
|
194
193
|
isBorrowed: new Dec(loanInfo.borrowedInAssets.toString()).gt(0),
|
|
195
194
|
collateral: false,
|
|
196
|
-
suppliedUsd:
|
|
195
|
+
suppliedUsd: '0',
|
|
197
196
|
borrowedUsd: new Dec(loanTokenBorrowed).mul(loanTokenInfo.price).toString(),
|
|
198
197
|
};
|
|
199
198
|
|
|
@@ -220,4 +219,42 @@ export async function _getMorphoBlueAccountData(provider: Client, network: Netwo
|
|
|
220
219
|
|
|
221
220
|
export async function getMorphoBlueAccountData(provider: EthereumProvider, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<MorphoBluePositionData> {
|
|
222
221
|
return _getMorphoBlueAccountData(getViemProvider(provider, network), network, account, selectedMarket, marketInfo);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export async function getMorphoEarn(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<{ apy: string, amount: string, amountUsd: string }> {
|
|
225
|
+
const {
|
|
226
|
+
loanToken, collateralToken, oracle, irm, lltv,
|
|
227
|
+
} = selectedMarket;
|
|
228
|
+
const lltvInWei = new Dec(lltv).mul(WAD).toString();
|
|
229
|
+
|
|
230
|
+
const viewContract = MorphoBlueViewContractViem(provider, network);
|
|
231
|
+
const loanInfo = (await viewContract.read.getUserInfo([
|
|
232
|
+
{
|
|
233
|
+
loanToken, collateralToken, oracle, irm, lltv: BigInt(lltvInWei),
|
|
234
|
+
},
|
|
235
|
+
account]));
|
|
236
|
+
|
|
237
|
+
const loanTokenInfo = marketInfo.assetsData[marketInfo.loanToken];
|
|
238
|
+
const loanTokenSupplied = assetAmountInEth(loanInfo.suppliedInAssets.toString(), marketInfo.loanToken);
|
|
239
|
+
const loanTokenSuppliedUsd = new Dec(loanTokenSupplied).mul(loanTokenInfo.price).toString();
|
|
240
|
+
const usedAssets: MMUsedAssets = {
|
|
241
|
+
[marketInfo.loanToken]: {
|
|
242
|
+
symbol: loanTokenInfo.symbol,
|
|
243
|
+
supplied: loanTokenSupplied,
|
|
244
|
+
borrowed: '0',
|
|
245
|
+
isSupplied: new Dec(loanInfo.suppliedInAssets.toString()).gt(0),
|
|
246
|
+
isBorrowed: false,
|
|
247
|
+
collateral: false,
|
|
248
|
+
suppliedUsd: loanTokenSuppliedUsd,
|
|
249
|
+
borrowedUsd: '0',
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const { netApy } = calculateNetApy({ usedAssets, assetsData: marketInfo.assetsData as unknown as MMAssetsData });
|
|
254
|
+
|
|
255
|
+
return {
|
|
256
|
+
apy: netApy,
|
|
257
|
+
amount: loanTokenSupplied,
|
|
258
|
+
amountUsd: loanTokenSuppliedUsd,
|
|
259
|
+
};
|
|
223
260
|
}
|