@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/esm/contracts.js
CHANGED
|
@@ -80,3 +80,12 @@ export const LiquityActivePoolContractViem = createViemContractFromConfigFunc('L
|
|
|
80
80
|
export const LiquityV2ViewContractViem = createViemContractFromConfigFunc('LiquityV2View');
|
|
81
81
|
export const LiquityV2LegacyViewContractViem = createViemContractFromConfigFunc('LiquityV2LegacyView');
|
|
82
82
|
export const FluidViewContractViem = createViemContractFromConfigFunc('FluidView');
|
|
83
|
+
export const AaveIncentivesControllerViem = createViemContractFromConfigFunc('AaveIncentivesController');
|
|
84
|
+
export const AaveUmbrellaViewViem = createViemContractFromConfigFunc('AaveUmbrellaView');
|
|
85
|
+
export const LiquityLQTYStakingViem = createViemContractFromConfigFunc('LiquityLQTYStaking');
|
|
86
|
+
export const LiquityStabilityPoolViem = createViemContractFromConfigFunc('LiquityStabilityPool');
|
|
87
|
+
export const UUPSViem = createViemContractFromConfigFunc('UUPS');
|
|
88
|
+
export const SparkRewardsControllerViem = createViemContractFromConfigFunc('SparkRewardsController');
|
|
89
|
+
export const AaveRewardsControllerViem = createViemContractFromConfigFunc('AaveRewardsController');
|
|
90
|
+
export const LiquityV2sBoldVaultViem = createViemContractFromConfigFunc('LiquityV2sBoldVault');
|
|
91
|
+
export const StkAAVEViem = createViemContractFromConfigFunc('StkAAVE');
|
package/esm/index.d.ts
CHANGED
|
@@ -18,5 +18,6 @@ import * as morphoBlue from './morphoBlue';
|
|
|
18
18
|
import * as llamaLend from './llamaLend';
|
|
19
19
|
import * as eulerV2 from './eulerV2';
|
|
20
20
|
import * as portfolio from './portfolio';
|
|
21
|
+
import * as claiming from './claiming';
|
|
21
22
|
export * from './types';
|
|
22
|
-
export { aaveV2, aaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, fluid, portfolio, };
|
|
23
|
+
export { aaveV2, aaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, fluid, portfolio, claiming, };
|
package/esm/index.js
CHANGED
|
@@ -18,5 +18,6 @@ import * as morphoBlue from './morphoBlue';
|
|
|
18
18
|
import * as llamaLend from './llamaLend';
|
|
19
19
|
import * as eulerV2 from './eulerV2';
|
|
20
20
|
import * as portfolio from './portfolio';
|
|
21
|
+
import * as claiming from './claiming';
|
|
21
22
|
export * from './types';
|
|
22
|
-
export { aaveV2, aaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, fluid, portfolio, };
|
|
23
|
+
export { aaveV2, aaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, fluid, portfolio, claiming, };
|
package/esm/liquity/index.d.ts
CHANGED
|
@@ -8,3 +8,14 @@ export declare const getLiquityAccountBalances: (provider: EthereumProvider, net
|
|
|
8
8
|
export declare const getDebtInFront: (provider: EthereumProvider, address: EthAddress) => Promise<string>;
|
|
9
9
|
export declare const _getLiquityTroveInfo: (provider: Client, network: NetworkNumber, address: EthAddress) => Promise<LiquityTroveInfo>;
|
|
10
10
|
export declare const getLiquityTroveInfo: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress) => Promise<LiquityTroveInfo>;
|
|
11
|
+
export declare const getLiquityStakingData: (provider: Client, network: NetworkNumber, address: EthAddress) => Promise<{
|
|
12
|
+
totalLUSDDeposited: string;
|
|
13
|
+
totalLQTYStaked: string;
|
|
14
|
+
stakedLQTY: string;
|
|
15
|
+
stakedLUSDBalance: string;
|
|
16
|
+
rewardETH: string;
|
|
17
|
+
rewardLUSD: string;
|
|
18
|
+
stabilityRewardETH: string;
|
|
19
|
+
stabilityRewardLQTY: string;
|
|
20
|
+
showStakingBalances: boolean;
|
|
21
|
+
}>;
|
package/esm/liquity/index.js
CHANGED
|
@@ -10,10 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
11
|
import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
|
|
12
12
|
import { NetworkNumber, } from '../types/common';
|
|
13
|
-
import { LiquityActivePoolContractViem, LiquityCollSurplusPoolContractViem, LiquityPriceFeedContractViem, LiquityTroveManagerContractViem, LiquityViewContractViem, } from '../contracts';
|
|
13
|
+
import { LiquityActivePoolContractViem, LiquityCollSurplusPoolContractViem, LiquityLQTYStakingViem, LiquityPriceFeedContractViem, LiquityStabilityPoolViem, LiquityTroveManagerContractViem, LiquityViewContractViem, } from '../contracts';
|
|
14
14
|
import { LIQUITY_TROVE_STATUS_ENUM } from '../types';
|
|
15
15
|
import { ZERO_ADDRESS } from '../constants';
|
|
16
16
|
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
17
|
+
import { getEthAmountForDecimals } from '../services/utils';
|
|
17
18
|
export const LIQUITY_NORMAL_MODE_RATIO = 110; // MCR
|
|
18
19
|
export const LIQUITY_RECOVERY_MODE_RATIO = 150; // CCR
|
|
19
20
|
export const _getLiquityAccountBalances = (provider, network, block, addressMapping, address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -85,3 +86,39 @@ export const _getLiquityTroveInfo = (provider, network, address) => __awaiter(vo
|
|
|
85
86
|
return payload;
|
|
86
87
|
});
|
|
87
88
|
export const getLiquityTroveInfo = (provider, network, address) => __awaiter(void 0, void 0, void 0, function* () { return _getLiquityTroveInfo(getViemProvider(provider, network, { batch: { multicall: true } }), network, address); });
|
|
89
|
+
export const getLiquityStakingData = (provider, network, address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
+
const lqtyStakingView = LiquityLQTYStakingViem(provider, network);
|
|
91
|
+
const stabilityPoolView = LiquityStabilityPoolViem(provider, network);
|
|
92
|
+
const [stakes, pendingETHGain, pendingLUSDGain, totalLQTYStakes, stabilityPoolETHGain, stabilityPoolLQTYGain, compoundedLUSDDeposit, totalLUSDDeposits,] = yield Promise.all([
|
|
93
|
+
lqtyStakingView.read.stakes([address]),
|
|
94
|
+
lqtyStakingView.read.getPendingETHGain([address]),
|
|
95
|
+
lqtyStakingView.read.getPendingLUSDGain([address]),
|
|
96
|
+
lqtyStakingView.read.totalLQTYStaked(),
|
|
97
|
+
stabilityPoolView.read.getDepositorETHGain([address]),
|
|
98
|
+
stabilityPoolView.read.getDepositorLQTYGain([address]),
|
|
99
|
+
stabilityPoolView.read.getCompoundedLUSDDeposit([address]),
|
|
100
|
+
stabilityPoolView.read.getTotalLUSDDeposits(),
|
|
101
|
+
]);
|
|
102
|
+
const totalLUSDDeposited = getEthAmountForDecimals(totalLUSDDeposits, 18);
|
|
103
|
+
const totalLQTYStaked = getEthAmountForDecimals(totalLQTYStakes, 18);
|
|
104
|
+
const stakedLQTY = getEthAmountForDecimals(stakes, 18);
|
|
105
|
+
const stakedLUSDBalance = getEthAmountForDecimals(compoundedLUSDDeposit, 18);
|
|
106
|
+
const rewardETH = getEthAmountForDecimals(pendingETHGain, 18);
|
|
107
|
+
const rewardLUSD = getEthAmountForDecimals(pendingLUSDGain, 18);
|
|
108
|
+
const stabilityRewardETH = getEthAmountForDecimals(stabilityPoolETHGain, 18);
|
|
109
|
+
const stabilityRewardLQTY = getEthAmountForDecimals(stabilityPoolLQTYGain, 18);
|
|
110
|
+
const showStakingBalances = !!(+stakedLQTY || +stakedLUSDBalance
|
|
111
|
+
|| +rewardETH || +rewardLUSD
|
|
112
|
+
|| +stabilityRewardETH || +stabilityRewardLQTY);
|
|
113
|
+
return {
|
|
114
|
+
totalLUSDDeposited,
|
|
115
|
+
totalLQTYStaked,
|
|
116
|
+
stakedLQTY,
|
|
117
|
+
stakedLUSDBalance,
|
|
118
|
+
rewardETH,
|
|
119
|
+
rewardLUSD,
|
|
120
|
+
stabilityRewardETH,
|
|
121
|
+
stabilityRewardLQTY,
|
|
122
|
+
showStakingBalances,
|
|
123
|
+
};
|
|
124
|
+
});
|
package/esm/liquityV2/index.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { Client, PublicClient } from 'viem';
|
|
2
2
|
import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
|
|
3
3
|
import { LiquityV2AssetsData, LiquityV2MarketData, LiquityV2MarketInfo, LiquityV2TroveData, LiquityV2Versions } from '../types';
|
|
4
|
+
export type SPYieldGainParameters = {
|
|
5
|
+
P: string;
|
|
6
|
+
aggWeightedDebtSum: string;
|
|
7
|
+
currentScale: string;
|
|
8
|
+
lastAggUpdateTime: string;
|
|
9
|
+
totalBoldDeposits: string;
|
|
10
|
+
yieldGainsPending: string;
|
|
11
|
+
};
|
|
4
12
|
export declare const _getLiquityV2MarketData: (provider: Client, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo) => Promise<LiquityV2MarketData>;
|
|
5
13
|
export declare const getLiquityV2MarketData: (provider: EthereumProvider, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo) => Promise<LiquityV2MarketData>;
|
|
6
14
|
export declare const _getLiquityV2UserTroveIds: (provider: PublicClient, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, troveNFTAddress: EthAddress, limitBlocksForEventFetching: boolean, account: EthAddress) => Promise<{
|
package/esm/liquityV2/index.js
CHANGED
|
@@ -14,7 +14,7 @@ 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';
|
|
17
|
+
import { compareAddresses, ethToWeth, MAXUINT, } from '../services/utils';
|
|
18
18
|
import { ZERO_ADDRESS } from '../constants';
|
|
19
19
|
import { LiquityV2Markets } from '../markets';
|
|
20
20
|
import { getViemProvider } from '../services/viem';
|
|
@@ -286,3 +286,164 @@ export const getLiquityV2ClaimableCollateral = (collSurplusPoolAddress, account,
|
|
|
286
286
|
const claimableCollateral = yield collSurplusPoolContract.read.getCollateral([account]);
|
|
287
287
|
return claimableCollateral.toString();
|
|
288
288
|
});
|
|
289
|
+
// const stabilityPoolAddrForMarket: Record<LiquityV2Versions, EthAddress> = {
|
|
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: Record<LiquityV2Versions, EthAddress> = {
|
|
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
|
+
//
|
|
306
|
+
// function ceilDiv(a: string, b: string) {
|
|
307
|
+
// return new Dec(a).add(new Dec(b).sub(1)).div(b).toString();
|
|
308
|
+
// }
|
|
309
|
+
// const SP_YIELD_SPLIT = new Dec(75).mul(10 ** 16).toString(); // 75%
|
|
310
|
+
//
|
|
311
|
+
// const calcPendingSPYield = (
|
|
312
|
+
// aggWeightedDebtSum: string,
|
|
313
|
+
// lastAggUpdateTime: string,
|
|
314
|
+
// currentTime: string,
|
|
315
|
+
// ) => {
|
|
316
|
+
// const a = new Dec(aggWeightedDebtSum).mul(
|
|
317
|
+
// new Dec(currentTime).sub(new Dec(lastAggUpdateTime)),
|
|
318
|
+
// ).toString();
|
|
319
|
+
// const b = new Dec(SECONDS_PER_YEAR).mul(1000).mul(1e18).toString();
|
|
320
|
+
// return new Dec(ceilDiv(a, b)).mul(SP_YIELD_SPLIT).div(1e18).toString();
|
|
321
|
+
// };
|
|
322
|
+
//
|
|
323
|
+
//
|
|
324
|
+
// const calculateStabilityPoolApy = (
|
|
325
|
+
// spYieldGainParams: SPYieldGainParameters,
|
|
326
|
+
// ) => {
|
|
327
|
+
// const {
|
|
328
|
+
// aggWeightedDebtSum, totalBoldDeposits, lastAggUpdateTime, yieldGainsPending,
|
|
329
|
+
// } = spYieldGainParams;
|
|
330
|
+
//
|
|
331
|
+
// if (new Dec(totalBoldDeposits).eq(0)) {
|
|
332
|
+
// return '0';
|
|
333
|
+
// }
|
|
334
|
+
//
|
|
335
|
+
// const now = Date.now().toString();
|
|
336
|
+
// const lastAggUpdateTimeScaled = new Dec(lastAggUpdateTime).mul(1000).toString();
|
|
337
|
+
//
|
|
338
|
+
// const pendingSPYield = new Dec(calcPendingSPYield(
|
|
339
|
+
// aggWeightedDebtSum,
|
|
340
|
+
// lastAggUpdateTimeScaled,
|
|
341
|
+
// now,
|
|
342
|
+
// )).add(yieldGainsPending).toString();
|
|
343
|
+
//
|
|
344
|
+
// const annualizedYield = new Dec(pendingSPYield).mul(SECONDS_PER_YEAR).mul(1000).div(new Dec(now).minus(lastAggUpdateTimeScaled))
|
|
345
|
+
// .toString();
|
|
346
|
+
// return new Dec(annualizedYield).div(totalBoldDeposits).mul(100).toString();
|
|
347
|
+
// };
|
|
348
|
+
//
|
|
349
|
+
// const getYBoldApyApi = async () => {
|
|
350
|
+
// const url = 'https://ydaemon.yearn.fi/1/vaults/0x23346B04a7f55b8760E5860AA5A77383D63491cD?strategiesDetails=withDetails&strategiesCondition=inQueue';
|
|
351
|
+
//
|
|
352
|
+
// const yBoldData = await fetch(url)
|
|
353
|
+
// .then(res => res.json())
|
|
354
|
+
// .catch(console.error);
|
|
355
|
+
//
|
|
356
|
+
// return new Dec(yBoldData.apr.netAPR).mul(100).toString();
|
|
357
|
+
// };
|
|
358
|
+
//
|
|
359
|
+
// export const getLiquityV2Staking = async (provider: Client, network: NetworkNumber, market: LiquityV2Versions, user: EthAddress) => {
|
|
360
|
+
// const stabilityPoolView = createViemContractFromConfigFunc('LiquityV2StabilityPool', stabilityPoolAddrForMarket[market])(provider, network);
|
|
361
|
+
// const activePoolView = createViemContractFromConfigFunc('LiquityV2ActivePool', activePoolAddrForMarket[market])(provider, network);
|
|
362
|
+
//
|
|
363
|
+
// const sBold = LiquityV2sBoldVaultViem(provider, network);
|
|
364
|
+
// const yBold = createViemContractFromConfigFunc('Erc4626', '0x9F4330700a36B29952869fac9b33f45EEdd8A3d8')(provider, network);
|
|
365
|
+
// const stYBold = createViemContractFromConfigFunc('Erc4626', '0x23346B04a7f55b8760E5860AA5A77383D63491cD')(provider, network);
|
|
366
|
+
//
|
|
367
|
+
// const debtTokenInfo = getAssetInfo(LiquityV2Markets(network)[market].debtToken);
|
|
368
|
+
// const debtTokenContract = createViemContractFromConfigFunc('Erc20', debtTokenInfo.address)(provider, network);
|
|
369
|
+
//
|
|
370
|
+
// const [
|
|
371
|
+
// stabilityRewardColl,
|
|
372
|
+
// stabilityRewardYield,
|
|
373
|
+
// compoundedBoldDeposit,
|
|
374
|
+
// totalBoldDeposits,
|
|
375
|
+
// P,
|
|
376
|
+
// currentScale,
|
|
377
|
+
// yieldGainsPending,
|
|
378
|
+
// debtTokenBalance,
|
|
379
|
+
//
|
|
380
|
+
// aggWeightedDebtSum,
|
|
381
|
+
// lastAggUpdateTime,
|
|
382
|
+
//
|
|
383
|
+
// sBoldTotalAssets,
|
|
384
|
+
// sBoldConvertToShares,
|
|
385
|
+
// sBoldMaxWithdraw,
|
|
386
|
+
//
|
|
387
|
+
// wethApy,
|
|
388
|
+
// wsETHApy,
|
|
389
|
+
// rETHApy,
|
|
390
|
+
//
|
|
391
|
+
// yBoldTotalAssets,
|
|
392
|
+
// yBoldMaxWithdraw,
|
|
393
|
+
// stYBoldConvertToShares,
|
|
394
|
+
// ] = await Promise.all([
|
|
395
|
+
// stabilityPoolView.read.getDepositorCollGain([user]),
|
|
396
|
+
// stabilityPoolView.read.getDepositorYieldGain([user]),
|
|
397
|
+
// stabilityPoolView.read.getCompoundedBoldDeposit([user]),
|
|
398
|
+
// stabilityPoolView.read.getTotalBoldDeposits(),
|
|
399
|
+
// stabilityPoolView.read.P(),
|
|
400
|
+
// stabilityPoolView.read.currentScale(),
|
|
401
|
+
// stabilityPoolView.read.getYieldGainsPending(),
|
|
402
|
+
// debtTokenContract.read.balanceOf([user]),
|
|
403
|
+
//
|
|
404
|
+
// activePoolView.read.aggWeightedDebtSum(),
|
|
405
|
+
// activePoolView.read.lastAggUpdateTime(),
|
|
406
|
+
//
|
|
407
|
+
// sBold.read.totalAssets(),
|
|
408
|
+
// sBold.read.convertToShares([BigInt(1e18)]),
|
|
409
|
+
// sBold.read.maxWithdraw([user]),
|
|
410
|
+
//
|
|
411
|
+
// sBold.read.sps([BigInt(0)]),
|
|
412
|
+
// sBold.read.sps([BigInt(1)]),
|
|
413
|
+
// sBold.read.sps([BigInt(2)]),
|
|
414
|
+
//
|
|
415
|
+
// yBold.read.totalAssets(),
|
|
416
|
+
// yBold.read.maxWithdraw([user]),
|
|
417
|
+
// stYBold.read.convertToShares([BigInt(1e18)]),
|
|
418
|
+
// ]);
|
|
419
|
+
//
|
|
420
|
+
//
|
|
421
|
+
// const stabilityPoolYieldParams: SPYieldGainParameters = {
|
|
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
|
+
// };
|
|
@@ -7,7 +7,7 @@ export const aaveV1AssetsDefaultMarket = [
|
|
|
7
7
|
export const aaveV2AssetsDefaultMarket = ['USDT', 'WBTC', 'ETH', 'YFI', 'ZRX', 'UNI', 'AAVE', 'BAT', 'BUSD', 'DAI', 'ENJ', 'KNCL', 'LINK', 'MANA', 'MKR', 'REN', 'SNX', 'SUSD', 'TUSD', 'USDC', 'CRV', 'GUSD', 'BAL', 'xSUSHI', 'RENFIL', 'RAI', 'AMPL', 'USDP', 'DPI', 'FRAX', 'FEI', 'stETH', 'ENS', 'UST', 'CVX', '1INCH', 'LUSD'];
|
|
8
8
|
export const aaveV3AssetsDefaultMarketEth = [
|
|
9
9
|
'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',
|
|
10
|
-
'eUSDe', 'PT USDe July', 'PT eUSDe Aug', 'EURC', 'FBTC', 'PT sUSDe Sep', 'PT USDe Sep', 'tETH', 'ezETH', 'XAUt', 'PT sUSDe Nov',
|
|
10
|
+
'eUSDe', 'PT USDe July', 'PT eUSDe Aug', 'EURC', 'FBTC', 'PT sUSDe Sep', 'PT USDe Sep', 'tETH', 'ezETH', 'XAUt', 'PT sUSDe Nov', 'PT USDe Nov',
|
|
11
11
|
];
|
|
12
12
|
export const aaveV3AssetsDefaultMarketOpt = [
|
|
13
13
|
'DAI', 'USDC.e', 'USDT', 'SUSD', 'AAVE', 'LINK', 'WBTC', 'ETH', 'OP', 'wstETH', 'LUSD', 'MAI', 'rETH', 'USDC',
|
|
@@ -4,7 +4,7 @@ export const compoundV2CollateralAssets = [
|
|
|
4
4
|
'cETH', 'cDAI', 'cBAT', 'cZRX', 'cUSDC', 'cWBTC Legacy', 'cWBTC', 'cUSDT',
|
|
5
5
|
'cTUSD', 'cLINK', 'cUSDP', 'cUNI', 'cCOMP', 'cMKR', 'cSUSHI', 'cAAVE', 'cYFI',
|
|
6
6
|
].map((symbol) => getAssetInfo(symbol));
|
|
7
|
-
export const v3USDCCollAssetsEth = ['COMP', 'WBTC', 'ETH', 'UNI', 'LINK', 'wstETH', 'cbBTC', 'tBTC', 'weETH', 'deUSD', 'sdeUSD'];
|
|
7
|
+
export const v3USDCCollAssetsEth = ['COMP', 'WBTC', 'ETH', 'UNI', 'LINK', 'wstETH', 'cbBTC', 'tBTC', 'weETH', 'deUSD', 'sdeUSD', 'rsETH'];
|
|
8
8
|
export const v3USDCCollAssetsArb = ['ARB', 'ETH', 'GMX', 'WBTC', 'wstETH', 'ezETH', 'wUSDM'];
|
|
9
9
|
export const v3USDCCollAssetsBase = ['cbETH', 'ETH', 'wstETH', 'cbBTC', 'tBTC'];
|
|
10
10
|
export const v3USDCCollAssetsOpt = ['ETH', 'OP', 'WBTC', 'wstETH'];
|
|
@@ -46,7 +46,7 @@ export const v3USDbCCollAssets = {
|
|
|
46
46
|
[NetworkNumber.Base]: v3USDbCCollAssetsBase,
|
|
47
47
|
[NetworkNumber.Linea]: [],
|
|
48
48
|
};
|
|
49
|
-
export const v3USDTCollAssetsEth = ['COMP', 'ETH', 'WBTC', 'UNI', 'LINK', 'wstETH', 'cbBTC', 'tBTC', 'sFRAX', 'mETH', 'weETH', 'sdeUSD', 'deUSD'];
|
|
49
|
+
export const v3USDTCollAssetsEth = ['COMP', 'ETH', 'WBTC', 'UNI', 'LINK', 'wstETH', 'cbBTC', 'tBTC', 'wUSDM', 'sFRAX', 'mETH', 'weETH', 'sdeUSD', 'deUSD'];
|
|
50
50
|
export const v3USDTCollAssetsArb = ['ETH', 'WBTC', 'wstETH', 'ARB', 'GMX'];
|
|
51
51
|
export const v3USDTCollAssetsOpt = ['ETH', 'WBTC', 'OP', 'wstETH'];
|
|
52
52
|
// @dev Keep assets in array, do not assign directly, so we can parse it and edit it programmatically with `scripts/updateMarkets`
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NetworkNumber } from '../../types/common';
|
|
2
|
-
export const sparkAssetsDefaultMarketEth = ['DAI', 'sDAI', 'USDC', 'ETH', 'wstETH', 'WBTC', 'GNO', 'rETH', 'USDT', 'weETH', 'cbBTC', 'sUSDS', 'USDS', 'LBTC', 'tBTC', 'ezETH', 'rsETH'];
|
|
2
|
+
export const sparkAssetsDefaultMarketEth = ['DAI', 'sDAI', 'USDC', 'ETH', 'wstETH', 'WBTC', 'GNO', 'rETH', 'USDT', 'weETH', 'cbBTC', 'sUSDS', 'USDS', 'LBTC', 'tBTC', 'ezETH', 'rsETH', 'PYUSD'];
|
|
3
3
|
// @dev Keep assets in array, do not assign directly, so we can parse it and edit it programmatically with `scripts/updateMarkets`
|
|
4
4
|
export const sparkAssetsDefaultMarket = {
|
|
5
5
|
[NetworkNumber.Eth]: sparkAssetsDefaultMarketEth,
|
|
@@ -7,3 +7,8 @@ export declare const _getMorphoBlueAccountBalances: (provider: Client, network:
|
|
|
7
7
|
export declare const getMorphoBlueAccountBalances: (provider: EthereumProvider, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, selectedMarket: MorphoBlueMarketData) => Promise<PositionBalances>;
|
|
8
8
|
export declare function _getMorphoBlueAccountData(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<MorphoBluePositionData>;
|
|
9
9
|
export declare function getMorphoBlueAccountData(provider: EthereumProvider, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<MorphoBluePositionData>;
|
|
10
|
+
export declare function getMorphoEarn(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<{
|
|
11
|
+
apy: string;
|
|
12
|
+
amount: string;
|
|
13
|
+
amountUsd: string;
|
|
14
|
+
}>;
|
package/esm/morphoBlue/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
|
12
12
|
import { NetworkNumber, } from '../types/common';
|
|
13
13
|
import { DFSFeedRegistryContractViem, FeedRegistryContractViem, MorphoBlueViewContractViem, } from '../contracts';
|
|
14
14
|
import { USD_QUOTE, WAD } from '../constants';
|
|
15
|
-
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
15
|
+
import { calculateNetApy, getStakingApy, STAKING_ASSETS } from '../staking';
|
|
16
16
|
import { isMainnetNetwork, wethToEth } from '../services/utils';
|
|
17
17
|
import { getBorrowRate, getMorphoBlueAggregatedPositionData, getRewardsForMarket, getSupplyRate, } from '../helpers/morphoBlueHelpers';
|
|
18
18
|
import { getChainlinkAssetAddress } from '../services/priceService';
|
|
@@ -155,16 +155,15 @@ 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);
|
|
159
158
|
const loanTokenBorrowed = assetAmountInEth(loanInfo.borrowedInAssets.toString(), marketInfo.loanToken);
|
|
160
159
|
usedAssets[marketInfo.loanToken] = {
|
|
161
160
|
symbol: loanTokenInfo.symbol,
|
|
162
|
-
supplied:
|
|
161
|
+
supplied: '0',
|
|
163
162
|
borrowed: loanTokenBorrowed,
|
|
164
|
-
isSupplied:
|
|
163
|
+
isSupplied: false,
|
|
165
164
|
isBorrowed: new Dec(loanInfo.borrowedInAssets.toString()).gt(0),
|
|
166
165
|
collateral: false,
|
|
167
|
-
suppliedUsd:
|
|
166
|
+
suppliedUsd: '0',
|
|
168
167
|
borrowedUsd: new Dec(loanTokenBorrowed).mul(loanTokenInfo.price).toString(),
|
|
169
168
|
};
|
|
170
169
|
const collateralTokenInfo = marketInfo.assetsData[marketInfo.collateralToken];
|
|
@@ -187,3 +186,37 @@ export function getMorphoBlueAccountData(provider, network, account, selectedMar
|
|
|
187
186
|
return _getMorphoBlueAccountData(getViemProvider(provider, network), network, account, selectedMarket, marketInfo);
|
|
188
187
|
});
|
|
189
188
|
}
|
|
189
|
+
export function getMorphoEarn(provider, network, account, selectedMarket, marketInfo) {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
const { loanToken, collateralToken, oracle, irm, lltv, } = selectedMarket;
|
|
192
|
+
const lltvInWei = new Dec(lltv).mul(WAD).toString();
|
|
193
|
+
const viewContract = MorphoBlueViewContractViem(provider, network);
|
|
194
|
+
const loanInfo = (yield viewContract.read.getUserInfo([
|
|
195
|
+
{
|
|
196
|
+
loanToken, collateralToken, oracle, irm, lltv: BigInt(lltvInWei),
|
|
197
|
+
},
|
|
198
|
+
account
|
|
199
|
+
]));
|
|
200
|
+
const loanTokenInfo = marketInfo.assetsData[marketInfo.loanToken];
|
|
201
|
+
const loanTokenSupplied = assetAmountInEth(loanInfo.suppliedInAssets.toString(), marketInfo.loanToken);
|
|
202
|
+
const loanTokenSuppliedUsd = new Dec(loanTokenSupplied).mul(loanTokenInfo.price).toString();
|
|
203
|
+
const usedAssets = {
|
|
204
|
+
[marketInfo.loanToken]: {
|
|
205
|
+
symbol: loanTokenInfo.symbol,
|
|
206
|
+
supplied: loanTokenSupplied,
|
|
207
|
+
borrowed: '0',
|
|
208
|
+
isSupplied: new Dec(loanInfo.suppliedInAssets.toString()).gt(0),
|
|
209
|
+
isBorrowed: false,
|
|
210
|
+
collateral: false,
|
|
211
|
+
suppliedUsd: loanTokenSuppliedUsd,
|
|
212
|
+
borrowedUsd: '0',
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
const { netApy } = calculateNetApy({ usedAssets, assetsData: marketInfo.assetsData });
|
|
216
|
+
return {
|
|
217
|
+
apy: netApy,
|
|
218
|
+
amount: loanTokenSupplied,
|
|
219
|
+
amountUsd: loanTokenSuppliedUsd,
|
|
220
|
+
};
|
|
221
|
+
});
|
|
222
|
+
}
|
package/esm/portfolio/index.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
|
|
2
2
|
import { PortfolioPositionsData } from '../types';
|
|
3
|
-
export declare function getPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], summerFiAddresses: EthAddress[]): Promise<
|
|
3
|
+
export declare function getPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], summerFiAddresses: EthAddress[]): Promise<{
|
|
4
|
+
positions: PortfolioPositionsData;
|
|
5
|
+
stakingPositions: any;
|
|
6
|
+
rewardsData: any;
|
|
7
|
+
markets: any;
|
|
8
|
+
}>;
|