@defisaver/positions-sdk 0.0.84 → 0.0.86
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 +4 -4
- package/cjs/aaveV3/index.js +2 -2
- package/cjs/markets/morphoBlue/index.d.ts +10 -0
- package/cjs/markets/morphoBlue/index.js +95 -9
- package/cjs/moneymarket/moneymarketCommonService.d.ts +1 -1
- package/cjs/moneymarket/moneymarketCommonService.js +1 -1
- package/cjs/morphoAaveV2/index.js +6 -6
- package/cjs/morphoAaveV3/index.js +2 -2
- package/cjs/spark/index.js +4 -4
- package/cjs/staking/staking.d.ts +0 -1
- package/cjs/staking/staking.js +9 -19
- package/cjs/types/morphoBlue.d.ts +8 -2
- package/cjs/types/morphoBlue.js +6 -0
- package/esm/aaveV2/index.js +5 -5
- package/esm/aaveV3/index.js +3 -3
- package/esm/markets/morphoBlue/index.d.ts +10 -0
- package/esm/markets/morphoBlue/index.js +89 -8
- package/esm/moneymarket/moneymarketCommonService.d.ts +1 -1
- package/esm/moneymarket/moneymarketCommonService.js +1 -1
- package/esm/morphoAaveV2/index.js +7 -7
- package/esm/morphoAaveV3/index.js +3 -3
- package/esm/spark/index.js +5 -5
- package/esm/staking/staking.d.ts +0 -1
- package/esm/staking/staking.js +8 -17
- package/esm/types/morphoBlue.d.ts +8 -2
- package/esm/types/morphoBlue.js +6 -0
- package/package.json +1 -2
- package/src/aaveV2/index.ts +5 -5
- package/src/aaveV3/index.ts +7 -8
- package/src/markets/morphoBlue/index.ts +89 -8
- package/src/moneymarket/moneymarketCommonService.ts +1 -1
- package/src/morphoAaveV2/index.ts +7 -7
- package/src/morphoAaveV3/index.ts +4 -4
- package/src/spark/index.ts +6 -6
- package/src/staking/staking.ts +8 -20
- package/src/types/morphoBlue.ts +6 -0
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
AavePositionData,
|
|
12
12
|
AaveVersions, MorphoAaveV2AssetData, MorphoAaveV2AssetsData, MorphoAaveV2MarketData, MorphoAaveV2PositionData,
|
|
13
13
|
} from '../types';
|
|
14
|
-
import { calculateBorrowingAssetLimit } from '../moneymarket';
|
|
14
|
+
import { aprToApy, calculateBorrowingAssetLimit } from '../moneymarket';
|
|
15
15
|
import { EMPTY_AAVE_DATA } from '../aaveV3';
|
|
16
16
|
import { aaveAnyGetAggregatedPositionData } from '../helpers/aaveHelpers';
|
|
17
17
|
import { getEthPrice } from '../services/priceService';
|
|
@@ -39,8 +39,8 @@ export const getMorphoAaveV2MarketsData = async (web3: Web3, network: NetworkNum
|
|
|
39
39
|
|
|
40
40
|
const morphoReward = morphoRewardsData?.markets?.[aaveInfo.aTokenAddress.toLowerCase()];
|
|
41
41
|
|
|
42
|
-
const supplyRateP2P = new Dec(market.p2pSupplyRate).div(1e25).toString();
|
|
43
|
-
const borrowRateP2P = new Dec(market.p2pBorrowRate).div(1e25).toString();
|
|
42
|
+
const supplyRateP2P = aprToApy(new Dec(market.p2pSupplyRate).div(1e25).toString());
|
|
43
|
+
const borrowRateP2P = aprToApy(new Dec(market.p2pBorrowRate).div(1e25).toString());
|
|
44
44
|
const hasDelta = new Dec(borrowRateP2P).minus(supplyRateP2P).gte(0.3);
|
|
45
45
|
|
|
46
46
|
return {
|
|
@@ -51,9 +51,9 @@ export const getMorphoAaveV2MarketsData = async (web3: Web3, network: NetworkNum
|
|
|
51
51
|
priceInEth: new Dec(aaveInfo.price).div(1e18).toString(),
|
|
52
52
|
price: new Dec(aaveInfo.price).div(1e18).times(ethPrice).toString(),
|
|
53
53
|
|
|
54
|
-
supplyRate: new Dec(market.poolSupplyRate).div(1e25).toString(),
|
|
54
|
+
supplyRate: aprToApy(new Dec(market.poolSupplyRate).div(1e25).toString()),
|
|
55
55
|
supplyRateP2P,
|
|
56
|
-
borrowRate: new Dec(market.poolBorrowRate).div(1e25).toString(),
|
|
56
|
+
borrowRate: aprToApy(new Dec(market.poolBorrowRate).div(1e25).toString()),
|
|
57
57
|
borrowRateP2P,
|
|
58
58
|
|
|
59
59
|
totalSupply: assetAmountInEth(aaveInfo.totalSupply, symbol),
|
|
@@ -216,8 +216,8 @@ export const getMorphoAaveV2AccountData = async (web3: Web3, network: NetworkNum
|
|
|
216
216
|
borrowedUsdVariable: borrowedUsd,
|
|
217
217
|
isSupplied: new Dec(supplied).gt(0),
|
|
218
218
|
isBorrowed: new Dec(borrowed).gt(0),
|
|
219
|
-
supplyRate: new Dec(market.userSupplyRate).div(1e25).toString(),
|
|
220
|
-
borrowRate: new Dec(market.userBorrowRate).div(1e25).toString(),
|
|
219
|
+
supplyRate: aprToApy(new Dec(market.userSupplyRate).div(1e25).toString()),
|
|
220
|
+
borrowRate: aprToApy(new Dec(market.userBorrowRate).div(1e25).toString()),
|
|
221
221
|
limit: '0',
|
|
222
222
|
|
|
223
223
|
collateral: true, // Morpho doesn't have all these, keeping it for compatability
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
MorphoAaveV3AssetData, MorphoAaveV3AssetsData, MorphoAaveV3MarketData, MorphoAaveV3MarketInfo, MorphoAaveV3PositionData,
|
|
25
25
|
} from '../types';
|
|
26
26
|
import { getDsrApy } from '../services/dsrService';
|
|
27
|
-
import { calculateBorrowingAssetLimit } from '../moneymarket';
|
|
27
|
+
import { aprToApy, calculateBorrowingAssetLimit } from '../moneymarket';
|
|
28
28
|
import { EMPTY_AAVE_DATA } from '../aaveV3';
|
|
29
29
|
import { aaveAnyGetAggregatedPositionData } from '../helpers/aaveHelpers';
|
|
30
30
|
import { MORPHO_AAVE_V3_ETH } from '../markets/aave';
|
|
@@ -229,9 +229,9 @@ export const getMorphoAaveV3MarketsData = async (web3: Web3, network: NetworkNum
|
|
|
229
229
|
underlyingTokenAddress: address,
|
|
230
230
|
price: new Dec(marketData.price.toString()).div(1e8).toString(), // is actually price in USD
|
|
231
231
|
|
|
232
|
-
supplyRate: new Dec(marketData.supplyRate.toString()).div(1e25).toString(),
|
|
232
|
+
supplyRate: aprToApy(new Dec(marketData.supplyRate.toString()).div(1e25).toString()),
|
|
233
233
|
supplyRateP2P: marketData.p2pSupplyAPY,
|
|
234
|
-
borrowRate: new Dec(marketData.borrowRateVariable.toString()).div(1e25).toString(),
|
|
234
|
+
borrowRate: aprToApy(new Dec(marketData.borrowRateVariable.toString()).div(1e25).toString()),
|
|
235
235
|
borrowRateP2P: marketData.p2pBorrowAPY,
|
|
236
236
|
totalSupply: assetAmountInEth(marketData.totalSupply.toString(), symbol),
|
|
237
237
|
totalBorrow: assetAmountInEth(marketData.totalBorrow.toString(), symbol),
|
|
@@ -617,4 +617,4 @@ export const getMorphoAaveV3FullPositionData = async (web3: Web3, network: Netwo
|
|
|
617
617
|
const marketData = await getMorphoAaveV3MarketsData(web3, network, market, mainnetWeb3);
|
|
618
618
|
const positionData = await getMorphoAaveV3AccountData(web3, network, address, marketData.assetsData, delegator, market);
|
|
619
619
|
return positionData;
|
|
620
|
-
};
|
|
620
|
+
};
|
package/src/spark/index.ts
CHANGED
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
} from '../types';
|
|
30
30
|
import { multicall } from '../multicall';
|
|
31
31
|
import { sparkGetAggregatedPositionData, sparkIsInIsolationMode } from '../helpers/sparkHelpers';
|
|
32
|
-
import { calculateBorrowingAssetLimit } from '../moneymarket';
|
|
32
|
+
import { aprToApy, calculateBorrowingAssetLimit } from '../moneymarket';
|
|
33
33
|
import { SPARK_V1 } from '../markets/spark';
|
|
34
34
|
|
|
35
35
|
export const sparkEmodeCategoriesMapping = (extractedState: { assetsData: SparkAssetsData }, usedAssets: SparkUsedAssets) => {
|
|
@@ -110,9 +110,9 @@ export const getSparkMarketsData = async (web3: Web3, network: NetworkNumber, se
|
|
|
110
110
|
isolationModeTotalDebt: new Dec(market.isolationModeTotalDebt).div(100).toString(),
|
|
111
111
|
assetId: Number(market.assetId),
|
|
112
112
|
underlyingTokenAddress: market.underlyingTokenAddress,
|
|
113
|
-
supplyRate: new Dec(market.supplyRate.toString()).div(1e25).toString(),
|
|
114
|
-
borrowRate: new Dec(market.borrowRateVariable.toString()).div(1e25).toString(),
|
|
115
|
-
borrowRateStable: new Dec(market.borrowRateStable.toString()).div(1e25).toString(),
|
|
113
|
+
supplyRate: aprToApy(new Dec(market.supplyRate.toString()).div(1e25).toString()),
|
|
114
|
+
borrowRate: aprToApy(new Dec(market.borrowRateVariable.toString()).div(1e25).toString()),
|
|
115
|
+
borrowRateStable: aprToApy(new Dec(market.borrowRateStable.toString()).div(1e25).toString()),
|
|
116
116
|
collateralFactor: new Dec(market.collateralFactor.toString()).div(10000).toString(),
|
|
117
117
|
liquidationRatio: new Dec(market.liquidationRatio.toString()).div(10000).toString(),
|
|
118
118
|
marketLiquidity,
|
|
@@ -374,7 +374,7 @@ export const getSparkAccountData = async (web3: Web3, network: NetworkNumber, ad
|
|
|
374
374
|
suppliedUsd: new Dec(supplied).mul(assetsData[asset].price).toString(),
|
|
375
375
|
isSupplied,
|
|
376
376
|
collateral: enabledAsCollateral,
|
|
377
|
-
stableBorrowRate: new Dec(tokenInfo.stableBorrowRate).div(1e25).toString(),
|
|
377
|
+
stableBorrowRate: aprToApy(new Dec(tokenInfo.stableBorrowRate).div(1e25).toString()),
|
|
378
378
|
borrowedStable,
|
|
379
379
|
borrowedVariable,
|
|
380
380
|
borrowedUsdStable: new Dec(borrowedStable).mul(assetsData[asset].price).toString(),
|
|
@@ -431,4 +431,4 @@ export const getSparkFullPositionData = async (web3: Web3, network: NetworkNumbe
|
|
|
431
431
|
const marketData = await getSparkMarketsData(web3, network, market, mainnetWeb3);
|
|
432
432
|
const positionData = await getSparkAccountData(web3, network, address, { assetsData: marketData.assetsData, selectedMarket: market });
|
|
433
433
|
return positionData;
|
|
434
|
-
};
|
|
434
|
+
};
|
package/src/staking/staking.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
2
|
import Web3 from 'web3';
|
|
3
|
-
import { StakeWiseSDK, Network } from '@stakewise/v3-sdk';
|
|
4
3
|
import {
|
|
5
4
|
CbEthContract, LidoContract, PotContract, REthContract, wstETHContract,
|
|
6
5
|
} from '../contracts';
|
|
@@ -78,25 +77,13 @@ export const getDsrApy = async (web3: Web3, blockNumber: 'latest' | number = 'la
|
|
|
78
77
|
.toString();
|
|
79
78
|
};
|
|
80
79
|
|
|
81
|
-
|
|
82
|
-
const res = await fetch(
|
|
80
|
+
const getApyFromDfsApi = async (asset: string) => {
|
|
81
|
+
const res = await fetch(`https://app.defisaver.com/api/staking/apy?asset=${asset}`);
|
|
83
82
|
const data = await res.json();
|
|
84
83
|
return data.apy;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const getWeEthApr = async () => {
|
|
88
|
-
const res = await fetch('https://app.defisaver.com/api/staking/apy?asset=weETH');
|
|
89
|
-
const data = await res.json();
|
|
90
|
-
return data.apy;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const getOsETHApy = async () => {
|
|
94
|
-
const sdk = new StakeWiseSDK({ network: Network.Mainnet });
|
|
95
|
-
const apy = await sdk.osToken.getAPY();
|
|
96
|
-
return apy;
|
|
97
|
-
};
|
|
84
|
+
}
|
|
98
85
|
|
|
99
|
-
export const STAKING_ASSETS = ['cbETH', 'wstETH', 'cbETH', 'rETH', 'sDAI', 'weETH', 'sUSDe', 'osETH'];
|
|
86
|
+
export const STAKING_ASSETS = ['cbETH', 'wstETH', 'cbETH', 'rETH', 'sDAI', 'weETH', 'sUSDe', 'osETH', 'ezETH'];
|
|
100
87
|
|
|
101
88
|
export const getStakingApy = (asset: string, web3: Web3, blockNumber: 'latest' | number = 'latest', fromBlock: number | undefined = undefined) => {
|
|
102
89
|
try {
|
|
@@ -104,9 +91,10 @@ export const getStakingApy = (asset: string, web3: Web3, blockNumber: 'latest' |
|
|
|
104
91
|
if (asset === 'cbETH') return getCbETHApr(web3, blockNumber);
|
|
105
92
|
if (asset === 'rETH') return getREthApr(web3, blockNumber);
|
|
106
93
|
if (asset === 'sDAI') return getDsrApy(web3);
|
|
107
|
-
if (asset === 'sUSDe') return
|
|
108
|
-
if (asset === 'weETH') return
|
|
109
|
-
if (asset === '
|
|
94
|
+
if (asset === 'sUSDe') return getApyFromDfsApi('sUSDe');
|
|
95
|
+
if (asset === 'weETH') return getApyFromDfsApi('weETH');
|
|
96
|
+
if (asset === 'ezETH') return getApyFromDfsApi('ezETH')
|
|
97
|
+
if (asset === 'osETH') return getApyFromDfsApi('osETH');
|
|
110
98
|
} catch (e) {
|
|
111
99
|
console.error(`Failed to fetch APY for ${asset}`);
|
|
112
100
|
return '0';
|
package/src/types/morphoBlue.ts
CHANGED
|
@@ -35,11 +35,17 @@ export enum MorphoBlueVersions {
|
|
|
35
35
|
|
|
36
36
|
// BASE
|
|
37
37
|
MorphoBlueCbEthUSDC_860_Base = 'morphobluecbethusdc_860_base',
|
|
38
|
+
MorphoBlueWstEthEth_945_Base = 'morphobluewstetheth_945_base',
|
|
39
|
+
MorphoBlueWstEthEth_965_Base = 'morphobluewstetheth_965_base',
|
|
40
|
+
MorphoBlueWstEthUSDC_860_Base = 'morphobluewstethusdc_860_base',
|
|
41
|
+
MorphoBlueCbEthEth_965_Base = 'morphobluecbetheth_965_base',
|
|
42
|
+
MorphoBlueEthUSDC_860_Base = 'morphoblueethusdc_860_base',
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
export enum MorphoBlueOracleType {
|
|
41
46
|
MARKET_RATE = 'Market rate',
|
|
42
47
|
LIDO_RATE = 'Lido rate',
|
|
48
|
+
ETHENA_RATE = 'Ethena rate',
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
export interface MorphoBlueMarketData {
|