@defisaver/positions-sdk 2.1.1 → 2.1.3
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 +1 -0
- package/cjs/aaveV3/index.d.ts +12 -0
- package/cjs/aaveV3/index.js +93 -1
- package/cjs/claiming/aaveV3.d.ts +5 -0
- package/cjs/claiming/aaveV3.js +139 -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 +5 -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 +2681 -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 +3027 -23
- package/cjs/contracts.js +10 -1
- package/cjs/helpers/aaveHelpers/index.d.ts +4 -0
- package/cjs/helpers/aaveHelpers/index.js +25 -8
- package/cjs/helpers/morphoBlueHelpers/index.d.ts +1 -0
- package/cjs/helpers/morphoBlueHelpers/index.js +7 -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 +35 -0
- package/cjs/liquityV2/index.js +142 -1
- package/cjs/morphoBlue/index.d.ts +5 -0
- package/cjs/morphoBlue/index.js +35 -0
- package/cjs/portfolio/index.d.ts +6 -1
- package/cjs/portfolio/index.js +293 -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/eligibility.d.ts +4 -2
- package/cjs/staking/eligibility.js +3 -4
- package/cjs/staking/staking.d.ts +2 -1
- package/cjs/staking/staking.js +3 -3
- package/cjs/types/claiming.d.ts +93 -0
- package/cjs/types/claiming.js +27 -0
- package/cjs/types/common.d.ts +1 -1
- package/cjs/types/common.js +1 -1
- 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 +5 -0
- package/esm/claiming/aaveV3.js +132 -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 +5 -0
- package/esm/claiming/morphoBlue.js +105 -0
- package/esm/claiming/spark.d.ts +6 -0
- package/esm/claiming/spark.js +179 -0
- package/esm/config/contracts.d.ts +2681 -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 +3027 -23
- package/esm/contracts.js +9 -0
- package/esm/helpers/aaveHelpers/index.d.ts +4 -0
- package/esm/helpers/aaveHelpers/index.js +23 -7
- package/esm/helpers/morphoBlueHelpers/index.d.ts +1 -0
- package/esm/helpers/morphoBlueHelpers/index.js +6 -1
- 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 +35 -0
- package/esm/liquityV2/index.js +142 -3
- package/esm/morphoBlue/index.d.ts +5 -0
- package/esm/morphoBlue/index.js +35 -1
- package/esm/portfolio/index.d.ts +6 -1
- package/esm/portfolio/index.js +298 -15
- 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/eligibility.d.ts +4 -2
- package/esm/staking/eligibility.js +3 -4
- package/esm/staking/staking.d.ts +2 -1
- package/esm/staking/staking.js +3 -3
- package/esm/types/claiming.d.ts +93 -0
- package/esm/types/claiming.js +24 -0
- package/esm/types/common.d.ts +1 -1
- package/esm/types/common.js +1 -1
- 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 +1 -1
- package/src/aaveV2/index.ts +2 -1
- package/src/aaveV3/index.ts +100 -2
- package/src/claiming/aaveV3.ts +155 -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 +104 -4
- package/src/constants/index.ts +5 -1
- package/src/contracts.ts +14 -1
- package/src/helpers/aaveHelpers/index.ts +24 -7
- package/src/helpers/morphoBlueHelpers/index.ts +7 -2
- package/src/index.ts +2 -0
- package/src/liquity/index.ts +57 -2
- package/src/liquityV2/index.ts +244 -4
- package/src/morphoBlue/index.ts +40 -2
- package/src/portfolio/index.ts +300 -15
- package/src/services/utils.ts +37 -1
- package/src/spark/index.ts +2 -1
- package/src/staking/eligibility.ts +3 -4
- package/src/staking/staking.ts +4 -4
- package/src/types/claiming.ts +109 -0
- package/src/types/common.ts +1 -1
- 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');
|
|
@@ -77,13 +77,6 @@ export const aaveAnyGetAggregatedPositionData = (_a) => {
|
|
|
77
77
|
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
78
78
|
payload.ratio = +payload.suppliedUsd ? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
79
79
|
payload.collRatio = +payload.suppliedUsd ? new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
80
|
-
const { netApy, incentiveUsd, totalInterestUsd } = calculateNetApy({
|
|
81
|
-
usedAssets,
|
|
82
|
-
assetsData,
|
|
83
|
-
});
|
|
84
|
-
payload.netApy = netApy;
|
|
85
|
-
payload.incentiveUsd = incentiveUsd;
|
|
86
|
-
payload.totalInterestUsd = totalInterestUsd;
|
|
87
80
|
payload.liqRatio = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).toString();
|
|
88
81
|
payload.liqPercent = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
89
82
|
const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
|
|
@@ -103,6 +96,14 @@ export const aaveAnyGetAggregatedPositionData = (_a) => {
|
|
|
103
96
|
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
104
97
|
payload.healthRatio = new Dec(payload.liquidationLimitUsd).div(payload.borrowedUsd).toDP(4).toString();
|
|
105
98
|
payload.minHealthRatio = new Dec(payload.liquidationLimitUsd).div(payload.borrowLimitUsd).toDP(4).toString();
|
|
99
|
+
const { netApy, incentiveUsd, totalInterestUsd } = calculateNetApy({
|
|
100
|
+
usedAssets,
|
|
101
|
+
assetsData,
|
|
102
|
+
optionalData: { healthRatio: payload.healthRatio },
|
|
103
|
+
});
|
|
104
|
+
payload.netApy = netApy;
|
|
105
|
+
payload.incentiveUsd = incentiveUsd;
|
|
106
|
+
payload.totalInterestUsd = totalInterestUsd;
|
|
106
107
|
return payload;
|
|
107
108
|
};
|
|
108
109
|
const getApyAfterValuesEstimationInner = (selectedMarket, actions, client, network) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -140,3 +141,18 @@ const getApyAfterValuesEstimationInner = (selectedMarket, actions, client, netwo
|
|
|
140
141
|
return rates;
|
|
141
142
|
});
|
|
142
143
|
export const getApyAfterValuesEstimation = (selectedMarket, actions, provider, network) => __awaiter(void 0, void 0, void 0, function* () { return getApyAfterValuesEstimationInner(selectedMarket, actions, getViemProvider(provider, network), network); });
|
|
144
|
+
/**
|
|
145
|
+
* won't cover all cases
|
|
146
|
+
*/
|
|
147
|
+
export const getAaveUnderlyingSymbol = (_symbol = '') => {
|
|
148
|
+
let symbol = _symbol
|
|
149
|
+
.replace(/^aEthLido/, '')
|
|
150
|
+
.replace(/^aEthEtherFi/, '')
|
|
151
|
+
.replace(/^aEth/, '')
|
|
152
|
+
.replace(/^aArb/, '')
|
|
153
|
+
.replace(/^aOpt/, '')
|
|
154
|
+
.replace(/^aBas/, '');
|
|
155
|
+
if (symbol.startsWith('a'))
|
|
156
|
+
symbol = symbol.slice(1);
|
|
157
|
+
return wethToEth(symbol);
|
|
158
|
+
};
|
|
@@ -14,7 +14,7 @@ import { calculateNetApy } from '../../staking';
|
|
|
14
14
|
import { NetworkNumber, } from '../../types/common';
|
|
15
15
|
import { borrowOperations, SECONDS_PER_YEAR, WAD } from '../../constants';
|
|
16
16
|
import { MorphoBlueViewContractViem } from '../../contracts';
|
|
17
|
-
import { compareAddresses, DEFAULT_TIMEOUT } from '../../services/utils';
|
|
17
|
+
import { compareAddresses, DEFAULT_TIMEOUT, wethToEth } from '../../services/utils';
|
|
18
18
|
import { getViemProvider } from '../../services/viem';
|
|
19
19
|
export const getMorphoBlueAggregatedPositionData = ({ usedAssets, assetsData, marketInfo }) => {
|
|
20
20
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -348,3 +348,8 @@ export const getRewardsForMarket = (marketId_1, ...args_1) => __awaiter(void 0,
|
|
|
348
348
|
const borrowAprPercent = new Dec(borrowApr).mul(100).toString();
|
|
349
349
|
return { supplyApy: aprToApy(supplyAprPercent), borrowApy: aprToApy(borrowAprPercent) };
|
|
350
350
|
});
|
|
351
|
+
export const getMorphoUnderlyingSymbol = (_symbol) => {
|
|
352
|
+
if (_symbol === 'MORPHO Legacy')
|
|
353
|
+
return 'MORPHO';
|
|
354
|
+
return wethToEth(_symbol);
|
|
355
|
+
};
|
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<{
|
|
@@ -29,3 +37,30 @@ export declare const getLiquityV2TroveData: (provider: EthereumProvider, network
|
|
|
29
37
|
allMarketsData: Record<LiquityV2Versions, LiquityV2MarketData>;
|
|
30
38
|
}, fetchDebtInFront?: boolean) => Promise<LiquityV2TroveData>;
|
|
31
39
|
export declare const getLiquityV2ClaimableCollateral: (collSurplusPoolAddress: EthAddress, account: EthAddress, provider: EthereumProvider, network: NetworkNumber) => Promise<string>;
|
|
40
|
+
export type sBoldYieldParameters = {
|
|
41
|
+
WETH: string;
|
|
42
|
+
wsETH: string;
|
|
43
|
+
rETH: string;
|
|
44
|
+
};
|
|
45
|
+
export declare const getLiquityV2Staking: (provider: Client, network: NetworkNumber, market: LiquityV2Versions, user: EthAddress) => Promise<{
|
|
46
|
+
totalBOLDDeposited: string;
|
|
47
|
+
stakedBOLDBalance: string;
|
|
48
|
+
stabilityRewardColl: string;
|
|
49
|
+
stabilityRewardYield: string;
|
|
50
|
+
showStakingBalances: boolean;
|
|
51
|
+
debtTokenBalance: string;
|
|
52
|
+
stabilityPoolApy: string;
|
|
53
|
+
}>;
|
|
54
|
+
export declare const getLiquitySAndYBold: (provider: Client, network: NetworkNumber, markets: any, user: EthAddress) => Promise<{
|
|
55
|
+
spApy: string;
|
|
56
|
+
yBoldApy: string;
|
|
57
|
+
totalBoldDepositedSBold: string;
|
|
58
|
+
boldRateSBold: string;
|
|
59
|
+
maxWithdrawSBold: string;
|
|
60
|
+
totalBoldDepositedYBold: string;
|
|
61
|
+
boldRateYBold: string;
|
|
62
|
+
maxWithdrawYBold: string;
|
|
63
|
+
sBoldBalance: string;
|
|
64
|
+
yBoldBalance: string;
|
|
65
|
+
stYBoldBalance: string;
|
|
66
|
+
}>;
|
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';
|
|
12
|
+
import { createViemContractFromConfigFunc, LiquityV2LegacyViewContractViem, LiquityV2sBoldVaultViem, LiquityV2ViewContractViem, } from '../contracts';
|
|
13
13
|
import { IncentiveKind, 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) => {
|
|
@@ -294,3 +294,142 @@ export const getLiquityV2ClaimableCollateral = (collSurplusPoolAddress, account,
|
|
|
294
294
|
const claimableCollateral = yield collSurplusPoolContract.read.getCollateral([account]);
|
|
295
295
|
return claimableCollateral.toString();
|
|
296
296
|
});
|
|
297
|
+
const stabilityPoolAddrForMarket = {
|
|
298
|
+
[LiquityV2Versions.LiquityV2Eth]: '0x5721cbbd64fc7Ae3Ef44A0A3F9a790A9264Cf9BF',
|
|
299
|
+
[LiquityV2Versions.LiquityV2WstEth]: '0x9502b7c397e9aa22fe9db7ef7daf21cd2aebe56b',
|
|
300
|
+
[LiquityV2Versions.LiquityV2REth]: '0xd442e41019b7f5c4dd78f50dc03726c446148695',
|
|
301
|
+
[LiquityV2Versions.LiquityV2EthLegacy]: ZERO_ADDRESS,
|
|
302
|
+
[LiquityV2Versions.LiquityV2REthLegacy]: ZERO_ADDRESS,
|
|
303
|
+
[LiquityV2Versions.LiquityV2WstEthLegacy]: ZERO_ADDRESS,
|
|
304
|
+
};
|
|
305
|
+
const activePoolAddrForMarket = {
|
|
306
|
+
[LiquityV2Versions.LiquityV2Eth]: '0xeB5A8C825582965f1d84606E078620a84ab16AfE',
|
|
307
|
+
[LiquityV2Versions.LiquityV2WstEth]: '0x531a8f99c70d6a56a7cee02d6b4281650d7919a0',
|
|
308
|
+
[LiquityV2Versions.LiquityV2REth]: '0x9074d72cc82dad1e13e454755aa8f144c479532f',
|
|
309
|
+
[LiquityV2Versions.LiquityV2EthLegacy]: ZERO_ADDRESS,
|
|
310
|
+
[LiquityV2Versions.LiquityV2WstEthLegacy]: ZERO_ADDRESS,
|
|
311
|
+
[LiquityV2Versions.LiquityV2REthLegacy]: ZERO_ADDRESS,
|
|
312
|
+
};
|
|
313
|
+
function ceilDiv(a, b) {
|
|
314
|
+
return new Dec(a).add(new Dec(b).sub(1)).div(b).toString();
|
|
315
|
+
}
|
|
316
|
+
const SP_YIELD_SPLIT = new Dec(75).mul(Math.pow(10, 16)).toString(); // 75%
|
|
317
|
+
const calcPendingSPYield = (aggWeightedDebtSum, lastAggUpdateTime, currentTime) => {
|
|
318
|
+
const a = new Dec(aggWeightedDebtSum).mul(new Dec(currentTime).sub(new Dec(lastAggUpdateTime))).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
|
+
const calculateStabilityPoolApy = (spYieldGainParams) => {
|
|
323
|
+
const { aggWeightedDebtSum, totalBoldDeposits, lastAggUpdateTime, yieldGainsPending, } = spYieldGainParams;
|
|
324
|
+
if (new Dec(totalBoldDeposits).eq(0)) {
|
|
325
|
+
return '0';
|
|
326
|
+
}
|
|
327
|
+
const now = Date.now().toString();
|
|
328
|
+
const lastAggUpdateTimeScaled = new Dec(lastAggUpdateTime).mul(1000).toString();
|
|
329
|
+
const pendingSPYield = new Dec(calcPendingSPYield(aggWeightedDebtSum, lastAggUpdateTimeScaled, now)).add(yieldGainsPending).toString();
|
|
330
|
+
const annualizedYield = new Dec(pendingSPYield).mul(SECONDS_PER_YEAR).mul(1000).div(new Dec(now).minus(lastAggUpdateTimeScaled))
|
|
331
|
+
.toString();
|
|
332
|
+
return new Dec(annualizedYield).div(totalBoldDeposits).mul(100).toString();
|
|
333
|
+
};
|
|
334
|
+
const getYBoldApyApi = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
335
|
+
try {
|
|
336
|
+
const url = 'https://ydaemon.yearn.fi/1/vaults/0x23346B04a7f55b8760E5860AA5A77383D63491cD?strategiesDetails=withDetails&strategiesCondition=inQueue';
|
|
337
|
+
const yBoldData = yield fetch(url)
|
|
338
|
+
.then(res => res.json())
|
|
339
|
+
.catch(console.error);
|
|
340
|
+
return new Dec(yBoldData.apr.netAPR).mul(100).toString();
|
|
341
|
+
}
|
|
342
|
+
catch (error) {
|
|
343
|
+
console.error('External API Failure: YBold ', error);
|
|
344
|
+
return '0';
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
const calculateSPApy = (spYieldGainParams, spAPYs) => {
|
|
348
|
+
const { WETH, wsETH, rETH, } = spYieldGainParams;
|
|
349
|
+
const apy = new Dec(WETH).mul(spAPYs.apyEth).add(new Dec(wsETH).mul(spAPYs.apyWstEth)).add(new Dec(rETH).mul(spAPYs.apyREth))
|
|
350
|
+
.toString();
|
|
351
|
+
return apy;
|
|
352
|
+
};
|
|
353
|
+
export const getLiquityV2Staking = (provider, network, market, user) => __awaiter(void 0, void 0, void 0, function* () {
|
|
354
|
+
const stabilityPoolView = createViemContractFromConfigFunc('LiquityV2StabilityPool', stabilityPoolAddrForMarket[market])(provider, network);
|
|
355
|
+
const activePoolView = createViemContractFromConfigFunc('LiquityV2ActivePool', activePoolAddrForMarket[market])(provider, network);
|
|
356
|
+
const debtTokenInfo = getAssetInfo(LiquityV2Markets(network)[market].debtToken, network);
|
|
357
|
+
const debtTokenContract = createViemContractFromConfigFunc('Erc20', debtTokenInfo.address)(provider, network);
|
|
358
|
+
const [stabilityRewardColl, stabilityRewardYield, compoundedBoldDeposit, totalBoldDeposits, P, currentScale, yieldGainsPending, debtTokenBalance, aggWeightedDebtSum, lastAggUpdateTime,] = yield Promise.all([
|
|
359
|
+
stabilityPoolView.read.getDepositorCollGain([user]),
|
|
360
|
+
stabilityPoolView.read.getDepositorYieldGain([user]),
|
|
361
|
+
stabilityPoolView.read.getCompoundedBoldDeposit([user]),
|
|
362
|
+
stabilityPoolView.read.getTotalBoldDeposits(),
|
|
363
|
+
stabilityPoolView.read.P(),
|
|
364
|
+
stabilityPoolView.read.currentScale(),
|
|
365
|
+
stabilityPoolView.read.getYieldGainsPending(),
|
|
366
|
+
debtTokenContract.read.balanceOf([user]),
|
|
367
|
+
activePoolView.read.aggWeightedDebtSum(),
|
|
368
|
+
activePoolView.read.lastAggUpdateTime(),
|
|
369
|
+
]);
|
|
370
|
+
const stabilityPoolYieldParams = {
|
|
371
|
+
aggWeightedDebtSum: aggWeightedDebtSum.toString(),
|
|
372
|
+
lastAggUpdateTime: lastAggUpdateTime.toString(),
|
|
373
|
+
P: P.toString(),
|
|
374
|
+
currentScale: currentScale.toString(),
|
|
375
|
+
yieldGainsPending: yieldGainsPending.toString(),
|
|
376
|
+
totalBoldDeposits: totalBoldDeposits.toString(),
|
|
377
|
+
};
|
|
378
|
+
const stabilityPoolApy = calculateStabilityPoolApy(stabilityPoolYieldParams);
|
|
379
|
+
const stakedBOLDBalanceForUser = getEthAmountForDecimals(compoundedBoldDeposit.toString(), 18);
|
|
380
|
+
const stabilityRewardCollForUser = getEthAmountForDecimals(stabilityRewardColl.toString(), 18);
|
|
381
|
+
const stabilityRewardYieldForUser = getEthAmountForDecimals(stabilityRewardYield.toString(), 18);
|
|
382
|
+
return {
|
|
383
|
+
totalBOLDDeposited: getEthAmountForDecimals(totalBoldDeposits.toString(), 18),
|
|
384
|
+
stakedBOLDBalance: stakedBOLDBalanceForUser,
|
|
385
|
+
stabilityRewardColl: stabilityRewardCollForUser,
|
|
386
|
+
stabilityRewardYield: stabilityRewardYieldForUser,
|
|
387
|
+
showStakingBalances: !!(+stakedBOLDBalanceForUser || +stabilityRewardCollForUser || +stabilityRewardYieldForUser),
|
|
388
|
+
debtTokenBalance: getEthAmountForDecimals(debtTokenBalance.toString(), debtTokenInfo.decimals),
|
|
389
|
+
stabilityPoolApy,
|
|
390
|
+
};
|
|
391
|
+
});
|
|
392
|
+
export const getLiquitySAndYBold = (provider, network, markets, user) => __awaiter(void 0, void 0, void 0, function* () {
|
|
393
|
+
const sBold = LiquityV2sBoldVaultViem(provider, network);
|
|
394
|
+
const yBold = createViemContractFromConfigFunc('Erc4626', '0x9F4330700a36B29952869fac9b33f45EEdd8A3d8')(provider, network);
|
|
395
|
+
const stYBold = createViemContractFromConfigFunc('Erc4626', '0x23346B04a7f55b8760E5860AA5A77383D63491cD')(provider, network);
|
|
396
|
+
const spAPYs = {
|
|
397
|
+
apyEth: markets[LiquityV2Versions.LiquityV2Eth].data.stabilityPoolApy,
|
|
398
|
+
apyWstEth: markets[LiquityV2Versions.LiquityV2WstEth].data.stabilityPoolApy,
|
|
399
|
+
apyREth: markets[LiquityV2Versions.LiquityV2REth].data.stabilityPoolApy,
|
|
400
|
+
};
|
|
401
|
+
const [sBoldTotalAssets, sBoldConvertToShares, sBoldMaxWithdraw, wethApy, wsETHApy, rETHApy, yBoldTotalAssets, yBoldMaxWithdraw, stYBoldConvertToShares, yBoldApy, sBoldBalance, yBoldBalance, stYBoldBalance,] = yield Promise.all([
|
|
402
|
+
sBold.read.totalAssets(),
|
|
403
|
+
sBold.read.convertToShares([BigInt(1e18)]),
|
|
404
|
+
sBold.read.maxWithdraw([user]),
|
|
405
|
+
sBold.read.sps([BigInt(0)]),
|
|
406
|
+
sBold.read.sps([BigInt(1)]),
|
|
407
|
+
sBold.read.sps([BigInt(2)]),
|
|
408
|
+
yBold.read.totalAssets(),
|
|
409
|
+
yBold.read.maxWithdraw([user]),
|
|
410
|
+
stYBold.read.convertToShares([BigInt(1e18)]),
|
|
411
|
+
getYBoldApyApi(),
|
|
412
|
+
sBold.read.balanceOf([user]),
|
|
413
|
+
yBold.read.balanceOf([user]),
|
|
414
|
+
stYBold.read.balanceOf([user]),
|
|
415
|
+
]);
|
|
416
|
+
const spMarketRes = {
|
|
417
|
+
WETH: new Dec(wethApy[1]).div(10000).toString(),
|
|
418
|
+
wsETH: new Dec(wsETHApy[1]).div(10000).toString(),
|
|
419
|
+
rETH: new Dec(rETHApy[1]).div(10000).toString(),
|
|
420
|
+
};
|
|
421
|
+
const spApy = calculateSPApy(spMarketRes, spAPYs);
|
|
422
|
+
return {
|
|
423
|
+
spApy,
|
|
424
|
+
yBoldApy,
|
|
425
|
+
totalBoldDepositedSBold: assetAmountInEth(sBoldTotalAssets.toString(), 'sBOLD'),
|
|
426
|
+
boldRateSBold: assetAmountInEth(sBoldConvertToShares.toString(), 'sBOLD'),
|
|
427
|
+
maxWithdrawSBold: assetAmountInEth(sBoldMaxWithdraw.toString(), 'sBOLD'),
|
|
428
|
+
totalBoldDepositedYBold: assetAmountInEth(yBoldTotalAssets.toString(), 'yBOLD'),
|
|
429
|
+
boldRateYBold: assetAmountInEth(stYBoldConvertToShares.toString(), 'yBOLD'),
|
|
430
|
+
maxWithdrawYBold: assetAmountInEth(yBoldMaxWithdraw.toString(), 'yBOLD'),
|
|
431
|
+
sBoldBalance: assetAmountInEth(sBoldBalance.toString(), 'sBOLD'),
|
|
432
|
+
yBoldBalance: assetAmountInEth(yBoldBalance.toString(), 'yBOLD'),
|
|
433
|
+
stYBoldBalance: assetAmountInEth(stYBoldBalance.toString(), 'yBOLD'),
|
|
434
|
+
};
|
|
435
|
+
});
|
|
@@ -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 { IncentiveKind, 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';
|
|
@@ -201,3 +201,37 @@ export function getMorphoBlueAccountData(provider, network, account, selectedMar
|
|
|
201
201
|
return _getMorphoBlueAccountData(getViemProvider(provider, network), network, account, selectedMarket, marketInfo);
|
|
202
202
|
});
|
|
203
203
|
}
|
|
204
|
+
export function getMorphoEarn(provider, network, account, selectedMarket, marketInfo) {
|
|
205
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
206
|
+
const { loanToken, collateralToken, oracle, irm, lltv, } = selectedMarket;
|
|
207
|
+
const lltvInWei = new Dec(lltv).mul(WAD).toString();
|
|
208
|
+
const viewContract = MorphoBlueViewContractViem(provider, network);
|
|
209
|
+
const loanInfo = (yield viewContract.read.getUserInfo([
|
|
210
|
+
{
|
|
211
|
+
loanToken, collateralToken, oracle, irm, lltv: BigInt(lltvInWei),
|
|
212
|
+
},
|
|
213
|
+
account
|
|
214
|
+
]));
|
|
215
|
+
const loanTokenInfo = marketInfo.assetsData[marketInfo.loanToken];
|
|
216
|
+
const loanTokenSupplied = assetAmountInEth(loanInfo.suppliedInAssets.toString(), marketInfo.loanToken);
|
|
217
|
+
const loanTokenSuppliedUsd = new Dec(loanTokenSupplied).mul(loanTokenInfo.price).toString();
|
|
218
|
+
const usedAssets = {
|
|
219
|
+
[marketInfo.loanToken]: {
|
|
220
|
+
symbol: loanTokenInfo.symbol,
|
|
221
|
+
supplied: loanTokenSupplied,
|
|
222
|
+
borrowed: '0',
|
|
223
|
+
isSupplied: new Dec(loanInfo.suppliedInAssets.toString()).gt(0),
|
|
224
|
+
isBorrowed: false,
|
|
225
|
+
collateral: false,
|
|
226
|
+
suppliedUsd: loanTokenSuppliedUsd,
|
|
227
|
+
borrowedUsd: '0',
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
const { netApy } = calculateNetApy({ usedAssets, assetsData: marketInfo.assetsData });
|
|
231
|
+
return {
|
|
232
|
+
apy: netApy,
|
|
233
|
+
amount: loanTokenSupplied,
|
|
234
|
+
amountUsd: loanTokenSuppliedUsd,
|
|
235
|
+
};
|
|
236
|
+
});
|
|
237
|
+
}
|
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
|
+
}>;
|