@defisaver/positions-sdk 2.1.9 → 2.1.11
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/.mocharc.json +4 -4
- package/.nvmrc +1 -1
- package/README.md +64 -64
- package/cjs/helpers/morphoBlueHelpers/index.js +66 -66
- package/cjs/helpers/sparkHelpers/index.d.ts +4 -4
- package/cjs/helpers/sparkHelpers/index.js +12 -12
- package/cjs/markets/aave/marketAssets.js +1 -1
- package/cjs/portfolio/index.js +1 -1
- package/cjs/spark/index.d.ts +3 -1
- package/cjs/spark/index.js +26 -26
- package/cjs/staking/staking.js +5 -1
- package/cjs/types/spark.d.ts +3 -4
- package/esm/helpers/morphoBlueHelpers/index.js +66 -66
- package/esm/helpers/sparkHelpers/index.d.ts +4 -4
- package/esm/helpers/sparkHelpers/index.js +13 -13
- package/esm/markets/aave/marketAssets.js +1 -1
- package/esm/portfolio/index.js +1 -1
- package/esm/spark/index.d.ts +3 -1
- package/esm/spark/index.js +27 -27
- package/esm/staking/staking.js +5 -1
- package/esm/types/spark.d.ts +3 -4
- package/package.json +47 -47
- package/src/aaveV2/index.ts +240 -240
- package/src/aaveV3/index.ts +614 -614
- package/src/aaveV3/merit.ts +97 -97
- package/src/aaveV3/merkl.ts +74 -74
- package/src/claiming/aaveV3.ts +154 -154
- package/src/claiming/compV3.ts +22 -22
- package/src/claiming/index.ts +12 -12
- package/src/claiming/king.ts +66 -66
- package/src/claiming/morphoBlue.ts +118 -118
- package/src/claiming/spark.ts +225 -225
- package/src/compoundV2/index.ts +244 -244
- package/src/compoundV3/index.ts +274 -274
- package/src/config/contracts.ts +1251 -1251
- package/src/constants/index.ts +10 -10
- package/src/contracts.ts +120 -120
- package/src/curveUsd/index.ts +254 -254
- package/src/eulerV2/index.ts +324 -324
- package/src/exchange/index.ts +25 -25
- package/src/fluid/index.ts +1668 -1668
- package/src/helpers/aaveHelpers/index.ts +187 -187
- package/src/helpers/compoundHelpers/index.ts +283 -283
- package/src/helpers/curveUsdHelpers/index.ts +40 -40
- package/src/helpers/eulerHelpers/index.ts +222 -222
- package/src/helpers/fluidHelpers/index.ts +326 -326
- package/src/helpers/index.ts +10 -10
- package/src/helpers/liquityV2Helpers/index.ts +82 -82
- package/src/helpers/llamaLendHelpers/index.ts +53 -53
- package/src/helpers/makerHelpers/index.ts +52 -52
- package/src/helpers/morphoBlueHelpers/index.ts +396 -396
- package/src/helpers/sparkHelpers/index.ts +158 -155
- package/src/index.ts +47 -47
- package/src/liquity/index.ts +159 -159
- package/src/liquityV2/index.ts +657 -657
- package/src/llamaLend/index.ts +305 -305
- package/src/maker/index.ts +223 -223
- package/src/markets/aave/index.ts +116 -116
- package/src/markets/aave/marketAssets.ts +54 -54
- package/src/markets/compound/index.ts +238 -238
- package/src/markets/compound/marketsAssets.ts +97 -97
- package/src/markets/curveUsd/index.ts +69 -69
- package/src/markets/euler/index.ts +26 -26
- package/src/markets/fluid/index.ts +2460 -2460
- package/src/markets/index.ts +25 -25
- package/src/markets/liquityV2/index.ts +102 -102
- package/src/markets/llamaLend/contractAddresses.ts +141 -141
- package/src/markets/llamaLend/index.ts +235 -235
- package/src/markets/morphoBlue/index.ts +895 -895
- package/src/markets/spark/index.ts +29 -29
- package/src/markets/spark/marketAssets.ts +12 -12
- package/src/moneymarket/moneymarketCommonService.ts +80 -80
- package/src/morphoBlue/index.ts +274 -274
- package/src/portfolio/index.ts +570 -570
- package/src/services/priceService.ts +159 -159
- package/src/services/utils.ts +115 -115
- package/src/services/viem.ts +34 -34
- package/src/setup.ts +8 -8
- package/src/spark/index.ts +456 -445
- package/src/staking/eligibility.ts +53 -53
- package/src/staking/index.ts +1 -1
- package/src/staking/staking.ts +172 -170
- package/src/types/aave.ts +189 -189
- package/src/types/claiming.ts +109 -109
- package/src/types/common.ts +107 -107
- package/src/types/compound.ts +136 -136
- package/src/types/curveUsd.ts +123 -123
- package/src/types/euler.ts +175 -175
- package/src/types/fluid.ts +452 -452
- package/src/types/index.ts +13 -13
- package/src/types/liquity.ts +30 -30
- package/src/types/liquityV2.ts +126 -126
- package/src/types/llamaLend.ts +159 -159
- package/src/types/maker.ts +63 -63
- package/src/types/merit.ts +1 -1
- package/src/types/merkl.ts +70 -70
- package/src/types/morphoBlue.ts +194 -194
- package/src/types/portfolio.ts +60 -60
- package/src/types/spark.ts +133 -135
- package/src/umbrella/index.ts +69 -69
- package/src/umbrella/umbrellaUtils.ts +29 -29
- package/CLAUDE.md +0 -32
|
@@ -118,73 +118,73 @@ export const getApyAfterValuesEstimation = (selectedMarket, actions, provider, n
|
|
|
118
118
|
return { borrowRate, supplyRate };
|
|
119
119
|
});
|
|
120
120
|
const API_URL = 'https://blue-api.morpho.org/graphql';
|
|
121
|
-
const MARKET_QUERY = `
|
|
122
|
-
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
123
|
-
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
124
|
-
reallocatableLiquidityAssets
|
|
125
|
-
targetBorrowUtilization
|
|
126
|
-
loanAsset {
|
|
127
|
-
address
|
|
128
|
-
decimals
|
|
129
|
-
priceUsd
|
|
130
|
-
}
|
|
131
|
-
state {
|
|
132
|
-
liquidityAssets
|
|
133
|
-
borrowAssets
|
|
134
|
-
supplyAssets
|
|
135
|
-
}
|
|
136
|
-
publicAllocatorSharedLiquidity {
|
|
137
|
-
assets
|
|
138
|
-
vault {
|
|
139
|
-
address
|
|
140
|
-
name
|
|
141
|
-
}
|
|
142
|
-
allocationMarket {
|
|
143
|
-
uniqueKey
|
|
144
|
-
loanAsset {
|
|
145
|
-
address
|
|
146
|
-
}
|
|
147
|
-
collateralAsset {
|
|
148
|
-
address
|
|
149
|
-
}
|
|
150
|
-
irmAddress
|
|
151
|
-
oracle {
|
|
152
|
-
address
|
|
153
|
-
}
|
|
154
|
-
lltv
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
loanAsset {
|
|
158
|
-
address
|
|
159
|
-
}
|
|
160
|
-
collateralAsset {
|
|
161
|
-
address
|
|
162
|
-
}
|
|
163
|
-
oracle {
|
|
164
|
-
address
|
|
165
|
-
}
|
|
166
|
-
irmAddress
|
|
167
|
-
lltv
|
|
168
|
-
}
|
|
169
|
-
}
|
|
121
|
+
const MARKET_QUERY = `
|
|
122
|
+
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
123
|
+
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
124
|
+
reallocatableLiquidityAssets
|
|
125
|
+
targetBorrowUtilization
|
|
126
|
+
loanAsset {
|
|
127
|
+
address
|
|
128
|
+
decimals
|
|
129
|
+
priceUsd
|
|
130
|
+
}
|
|
131
|
+
state {
|
|
132
|
+
liquidityAssets
|
|
133
|
+
borrowAssets
|
|
134
|
+
supplyAssets
|
|
135
|
+
}
|
|
136
|
+
publicAllocatorSharedLiquidity {
|
|
137
|
+
assets
|
|
138
|
+
vault {
|
|
139
|
+
address
|
|
140
|
+
name
|
|
141
|
+
}
|
|
142
|
+
allocationMarket {
|
|
143
|
+
uniqueKey
|
|
144
|
+
loanAsset {
|
|
145
|
+
address
|
|
146
|
+
}
|
|
147
|
+
collateralAsset {
|
|
148
|
+
address
|
|
149
|
+
}
|
|
150
|
+
irmAddress
|
|
151
|
+
oracle {
|
|
152
|
+
address
|
|
153
|
+
}
|
|
154
|
+
lltv
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
loanAsset {
|
|
158
|
+
address
|
|
159
|
+
}
|
|
160
|
+
collateralAsset {
|
|
161
|
+
address
|
|
162
|
+
}
|
|
163
|
+
oracle {
|
|
164
|
+
address
|
|
165
|
+
}
|
|
166
|
+
irmAddress
|
|
167
|
+
lltv
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
170
|
`;
|
|
171
|
-
const REWARDS_QUERY = `
|
|
172
|
-
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
173
|
-
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
174
|
-
uniqueKey
|
|
175
|
-
state {
|
|
176
|
-
rewards {
|
|
177
|
-
amountPerSuppliedToken
|
|
178
|
-
supplyApr
|
|
179
|
-
amountPerBorrowedToken
|
|
180
|
-
borrowApr
|
|
181
|
-
asset {
|
|
182
|
-
address
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
171
|
+
const REWARDS_QUERY = `
|
|
172
|
+
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
173
|
+
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
174
|
+
uniqueKey
|
|
175
|
+
state {
|
|
176
|
+
rewards {
|
|
177
|
+
amountPerSuppliedToken
|
|
178
|
+
supplyApr
|
|
179
|
+
amountPerBorrowedToken
|
|
180
|
+
borrowApr
|
|
181
|
+
asset {
|
|
182
|
+
address
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
188
|
`;
|
|
189
189
|
/**
|
|
190
190
|
* Get reallocatable liquidity to a given market and target borrow utilization
|
|
@@ -7,19 +7,19 @@ export declare const sparkIsInIsolationMode: ({ usedAssets, assetsData }: {
|
|
|
7
7
|
export declare const sparkGetCollSuppliedAssets: ({ usedAssets }: {
|
|
8
8
|
usedAssets: SparkUsedAssets;
|
|
9
9
|
}) => import("../../types").SparkUsedAsset[];
|
|
10
|
-
export declare const sparkGetSuppliableAssets: ({ usedAssets, eModeCategory,
|
|
10
|
+
export declare const sparkGetSuppliableAssets: ({ usedAssets, eModeCategory, assetsData, selectedMarket, network, ...rest }: SparkHelperCommon) => {
|
|
11
11
|
symbol: string;
|
|
12
12
|
canBeCollateral: boolean;
|
|
13
13
|
}[];
|
|
14
|
-
export declare const sparkGetSuppliableAsCollAssets: ({ usedAssets, eModeCategory,
|
|
14
|
+
export declare const sparkGetSuppliableAsCollAssets: ({ usedAssets, eModeCategory, assetsData, selectedMarket, network, ...rest }: SparkHelperCommon) => {
|
|
15
15
|
symbol: string;
|
|
16
16
|
canBeCollateral: boolean;
|
|
17
17
|
}[];
|
|
18
|
-
export declare const sparkGetEmodeMutableProps: ({ eModeCategory, assetsData, }: SparkHelperCommon, _asset: string) => {
|
|
18
|
+
export declare const sparkGetEmodeMutableProps: ({ eModeCategory, eModeCategoriesData, assetsData, }: SparkHelperCommon, _asset: string) => {
|
|
19
19
|
liquidationRatio: string;
|
|
20
20
|
collateralFactor: string;
|
|
21
21
|
};
|
|
22
|
-
export declare const sparkGetAggregatedPositionData: ({ usedAssets, eModeCategory,
|
|
22
|
+
export declare const sparkGetAggregatedPositionData: ({ usedAssets, eModeCategory, eModeCategoriesData, assetsData, selectedMarket, network, ...rest }: SparkHelperCommon) => SparkAggregatedPositionData;
|
|
23
23
|
export declare const getApyAfterValuesEstimation: (selectedMarket: SparkMarketData, actions: [{
|
|
24
24
|
action: string;
|
|
25
25
|
amount: string;
|
|
@@ -22,7 +22,7 @@ import Dec from 'decimal.js';
|
|
|
22
22
|
import { assetAmountInWei, getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
23
23
|
import { aprToApy, calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos, } from '../../moneymarket';
|
|
24
24
|
import { calculateNetApy } from '../../staking';
|
|
25
|
-
import { ethToWeth, wethToEth } from '../../services/utils';
|
|
25
|
+
import { ethToWeth, getNativeAssetFromWrapped, wethToEth } from '../../services/utils';
|
|
26
26
|
import { SparkViewContractViem } from '../../contracts';
|
|
27
27
|
import { NetworkNumber } from '../../types/common';
|
|
28
28
|
import { borrowOperations } from '../../constants';
|
|
@@ -30,8 +30,8 @@ import { getViemProvider } from '../../services/viem';
|
|
|
30
30
|
export const sparkIsInIsolationMode = ({ usedAssets, assetsData }) => Object.values(usedAssets).some(({ symbol, collateral }) => collateral && assetsData[symbol].isIsolated);
|
|
31
31
|
export const sparkGetCollSuppliedAssets = ({ usedAssets }) => Object.values(usedAssets).filter(({ isSupplied, collateral }) => isSupplied && collateral);
|
|
32
32
|
export const sparkGetSuppliableAssets = (_a) => {
|
|
33
|
-
var { usedAssets, eModeCategory,
|
|
34
|
-
const data = Object.assign({ usedAssets, eModeCategory,
|
|
33
|
+
var { usedAssets, eModeCategory, assetsData, selectedMarket, network } = _a, rest = __rest(_a, ["usedAssets", "eModeCategory", "assetsData", "selectedMarket", "network"]);
|
|
34
|
+
const data = Object.assign({ usedAssets, eModeCategory, assetsData, selectedMarket, network }, rest);
|
|
35
35
|
const collAccountAssets = sparkGetCollSuppliedAssets(data);
|
|
36
36
|
const marketAssets = Object.values(assetsData);
|
|
37
37
|
if (sparkIsInIsolationMode(data)) {
|
|
@@ -41,25 +41,25 @@ export const sparkGetSuppliableAssets = (_a) => {
|
|
|
41
41
|
return marketAssets.filter(d => d.canBeSupplied).map(({ symbol, isIsolated }) => ({ symbol, canBeCollateral: !isIsolated }));
|
|
42
42
|
};
|
|
43
43
|
export const sparkGetSuppliableAsCollAssets = (_a) => {
|
|
44
|
-
var { usedAssets, eModeCategory,
|
|
45
|
-
return sparkGetSuppliableAssets(Object.assign({ usedAssets, eModeCategory,
|
|
44
|
+
var { usedAssets, eModeCategory, assetsData, selectedMarket, network } = _a, rest = __rest(_a, ["usedAssets", "eModeCategory", "assetsData", "selectedMarket", "network"]);
|
|
45
|
+
return sparkGetSuppliableAssets(Object.assign({ usedAssets, eModeCategory, assetsData, selectedMarket, network }, rest)).filter(({ canBeCollateral }) => canBeCollateral);
|
|
46
46
|
};
|
|
47
|
-
export const sparkGetEmodeMutableProps = ({ eModeCategory, assetsData, }, _asset) => {
|
|
48
|
-
|
|
49
|
-
const asset = wethToEth(_asset);
|
|
47
|
+
export const sparkGetEmodeMutableProps = ({ eModeCategory, eModeCategoriesData, assetsData, }, _asset) => {
|
|
48
|
+
const asset = getNativeAssetFromWrapped(_asset);
|
|
50
49
|
const assetData = assetsData[asset];
|
|
50
|
+
const eModeCategoryData = (eModeCategoriesData === null || eModeCategoriesData === void 0 ? void 0 : eModeCategoriesData[eModeCategory]) || { collateralAssets: [], collateralFactor: '0', liquidationRatio: '0' };
|
|
51
51
|
if (eModeCategory === 0
|
|
52
|
-
||
|
|
53
|
-
|| new Dec(
|
|
52
|
+
|| !eModeCategoryData.collateralAssets.includes(asset)
|
|
53
|
+
|| new Dec(eModeCategoryData.collateralFactor || 0).eq(0)) {
|
|
54
54
|
const { liquidationRatio, collateralFactor } = assetData;
|
|
55
55
|
return ({ liquidationRatio, collateralFactor });
|
|
56
56
|
}
|
|
57
|
-
const { liquidationRatio, collateralFactor } =
|
|
57
|
+
const { liquidationRatio, collateralFactor } = eModeCategoryData;
|
|
58
58
|
return ({ liquidationRatio, collateralFactor });
|
|
59
59
|
};
|
|
60
60
|
export const sparkGetAggregatedPositionData = (_a) => {
|
|
61
|
-
var { usedAssets, eModeCategory,
|
|
62
|
-
const data = Object.assign({ usedAssets, eModeCategory,
|
|
61
|
+
var { usedAssets, eModeCategory, eModeCategoriesData, assetsData, selectedMarket, network } = _a, rest = __rest(_a, ["usedAssets", "eModeCategory", "eModeCategoriesData", "assetsData", "selectedMarket", "network"]);
|
|
62
|
+
const data = Object.assign({ usedAssets, eModeCategory, eModeCategoriesData, assetsData, selectedMarket, network }, rest);
|
|
63
63
|
const payload = {};
|
|
64
64
|
payload.suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
|
|
65
65
|
payload.suppliedCollateralUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ suppliedUsd }) => suppliedUsd);
|
|
@@ -15,7 +15,7 @@ export const aaveV3AssetsDefaultMarketOpt = [
|
|
|
15
15
|
export const aaveV3AssetsDefaultMarketArb = ['DAI', 'LINK', 'USDC.e', 'WBTC', 'ETH', 'USDT', 'AAVE', 'EURS', 'wstETH', 'MAI', 'rETH', 'LUSD', 'USDC', 'FRAX', 'ARB', 'weETH', 'GHO', 'ezETH', 'rsETH', 'tBTC'];
|
|
16
16
|
export const aaveV3AssetsDefaultMarketBase = ['ETH', 'cbETH', 'USDbC', 'wstETH', 'USDC', 'weETH', 'cbBTC', 'ezETH', 'GHO', 'wrsETH', 'LBTC', 'EURC', 'AAVE', 'tBTC'];
|
|
17
17
|
export const aaveV3AssetsDefaultMarketLinea = ['ETH', 'USDC', 'weETH', 'ezETH', 'USDT', 'wstETH', 'wrsETH', 'WBTC'];
|
|
18
|
-
export const aaveV3AssetsDefaultMarketPlasma = ['ETH', 'USDT', 'sUSDe', 'USDe', 'weETH', 'XAUt'];
|
|
18
|
+
export const aaveV3AssetsDefaultMarketPlasma = ['ETH', 'USDT', 'sUSDe', 'USDe', 'weETH', 'XAUt', 'PT USDe Jan', 'PT sUSDe Jan', 'wrsETH', 'wstETH'];
|
|
19
19
|
// @dev Keep assets in array, do not assign directly, so we can parse it and edit it programmatically with `scripts/updateMarkets`
|
|
20
20
|
export const aaveV3AssetsDefaultMarket = {
|
|
21
21
|
[NetworkNumber.Eth]: aaveV3AssetsDefaultMarketEth,
|
package/esm/portfolio/index.js
CHANGED
|
@@ -446,7 +446,7 @@ export function getPortfolioData(provider, network, defaultProvider, addresses,
|
|
|
446
446
|
}))).flat(),
|
|
447
447
|
...sparkMarkets.map((market) => allAddresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
448
448
|
try {
|
|
449
|
-
const accData = yield _getSparkAccountData(client, network, address, { selectedMarket: market, assetsData: sparkMarketsData[market.value].assetsData });
|
|
449
|
+
const accData = yield _getSparkAccountData(client, network, address, { selectedMarket: market, assetsData: sparkMarketsData[market.value].assetsData, eModeCategoriesData: sparkMarketsData[market.value].eModeCategoriesData });
|
|
450
450
|
if (new Dec(accData.suppliedUsd).gt(0))
|
|
451
451
|
positions[address.toLowerCase()].spark[market.value] = { error: '', data: accData };
|
|
452
452
|
}
|
package/esm/spark/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
2
|
import { Blockish, EthAddress, EthereumProvider, NetworkNumber, PositionBalances } from '../types/common';
|
|
3
|
-
import { SparkEModeCategoryDataMapping, SparkAssetsData, SparkMarketData, SparkMarketsData, SparkPositionData, SparkUsedAssets } from '../types';
|
|
3
|
+
import { SparkEModeCategoryDataMapping, SparkAssetsData, SparkMarketData, SparkMarketsData, SparkPositionData, SparkUsedAssets, EModeCategoriesData } from '../types';
|
|
4
4
|
export declare const sparkEmodeCategoriesMapping: (extractedState: {
|
|
5
5
|
assetsData: SparkAssetsData;
|
|
6
6
|
}, usedAssets: SparkUsedAssets) => {
|
|
@@ -32,9 +32,11 @@ export declare const getSparkAccountBalances: (provider: EthereumProvider, netwo
|
|
|
32
32
|
export declare const _getSparkAccountData: (provider: Client, network: NetworkNumber, address: EthAddress, extractedState: {
|
|
33
33
|
selectedMarket: SparkMarketData;
|
|
34
34
|
assetsData: SparkAssetsData;
|
|
35
|
+
eModeCategoriesData: EModeCategoriesData;
|
|
35
36
|
}) => Promise<SparkPositionData>;
|
|
36
37
|
export declare const getSparkAccountData: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, extractedState: {
|
|
37
38
|
selectedMarket: SparkMarketData;
|
|
38
39
|
assetsData: SparkAssetsData;
|
|
40
|
+
eModeCategoriesData: EModeCategoriesData;
|
|
39
41
|
}) => Promise<SparkPositionData>;
|
|
40
42
|
export declare const getSparkFullPositionData: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, market: SparkMarketData) => Promise<SparkPositionData>;
|
package/esm/spark/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
11
|
import { assetAmountInEth, assetAmountInWei, getAssetInfo } from '@defisaver/tokens';
|
|
12
|
-
import { IncentiveKind,
|
|
12
|
+
import { IncentiveKind, } from '../types/common';
|
|
13
13
|
import { ethToWeth, wethToEth, wethToEthByAddress, } from '../services/utils';
|
|
14
14
|
import { calculateNetApy, getStakingApy, STAKING_ASSETS, } from '../staking';
|
|
15
15
|
import { SparkViewContractViem, SparkIncentiveDataProviderContractViem, createViemContractFromConfigFunc, } from '../contracts';
|
|
@@ -22,7 +22,6 @@ export const sparkEmodeCategoriesMapping = (extractedState, usedAssets) => {
|
|
|
22
22
|
const usedAssetsValues = Object.values(usedAssets);
|
|
23
23
|
const categoriesMapping = {};
|
|
24
24
|
Object.values(assetsData).forEach((a) => {
|
|
25
|
-
var _a;
|
|
26
25
|
const borrowingOnlyFromCategory = a.eModeCategory === 0
|
|
27
26
|
? true
|
|
28
27
|
: !usedAssetsValues.filter(u => u.isBorrowed && u.eModeCategory !== a.eModeCategory).length;
|
|
@@ -33,8 +32,6 @@ export const sparkEmodeCategoriesMapping = (extractedState, usedAssets) => {
|
|
|
33
32
|
enteringTerms,
|
|
34
33
|
canEnterCategory: !enteringTerms.includes(false),
|
|
35
34
|
id: a.eModeCategory,
|
|
36
|
-
data: a.eModeCategoryData,
|
|
37
|
-
assets: a.eModeCategory === 0 ? [] : [...(((_a = categoriesMapping[a.eModeCategory]) === null || _a === void 0 ? void 0 : _a.assets) || []), a.symbol],
|
|
38
35
|
enabledData: {
|
|
39
36
|
ratio: afterEnteringCategory.ratio,
|
|
40
37
|
liqRatio: afterEnteringCategory.liqRatio,
|
|
@@ -49,18 +46,17 @@ export const _getSparkMarketsData = (provider, network, selectedMarket) => __awa
|
|
|
49
46
|
const marketAddress = selectedMarket.providerAddress;
|
|
50
47
|
const loanInfoContract = SparkViewContractViem(provider, network);
|
|
51
48
|
const sparkIncentivesContract = SparkIncentiveDataProviderContractViem(provider, network);
|
|
52
|
-
|
|
49
|
+
// eslint-disable-next-line prefer-const
|
|
50
|
+
let [loanInfo, rewardInfo] = yield Promise.all([
|
|
53
51
|
loanInfoContract.read.getFullTokensInfo([marketAddress, selectedMarket.assets.map(a => getAssetInfo(ethToWeth(a)).address)]),
|
|
54
|
-
|
|
52
|
+
sparkIncentivesContract.read.getReservesIncentivesData([marketAddress]),
|
|
55
53
|
]);
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}, {});
|
|
63
|
-
}
|
|
54
|
+
rewardInfo = rewardInfo.reduce((all, market) => {
|
|
55
|
+
// eslint-disable-next-line no-param-reassign
|
|
56
|
+
all[market.underlyingAsset] = market;
|
|
57
|
+
return all;
|
|
58
|
+
}, {});
|
|
59
|
+
const eModeCategoriesData = {};
|
|
64
60
|
const assetsData = yield Promise.all(loanInfo
|
|
65
61
|
.map((market, i) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
62
|
const symbol = selectedMarket.assets[i];
|
|
@@ -75,6 +71,15 @@ export const _getSparkMarketsData = (provider, network, selectedMarket) => __awa
|
|
|
75
71
|
if (new Dec(marketLiquidity).lt(0)) {
|
|
76
72
|
marketLiquidity = '0';
|
|
77
73
|
}
|
|
74
|
+
eModeCategoriesData[+market.emodeCategory.toString()] = {
|
|
75
|
+
id: +market.emodeCategory.toString(),
|
|
76
|
+
label: market.label,
|
|
77
|
+
liquidationBonus: new Dec(market.liquidationBonus).div(10000).toString(),
|
|
78
|
+
liquidationRatio: new Dec(market.liquidationThreshold).div(10000).toString(),
|
|
79
|
+
collateralFactor: new Dec(market.ltv).div(10000).toString(),
|
|
80
|
+
collateralAssets: eModeCategoriesData[+market.emodeCategory.toString()] ? [...eModeCategoriesData[+market.emodeCategory.toString()].collateralAssets, selectedMarket.assets[i]] : [selectedMarket.assets[i]],
|
|
81
|
+
borrowAssets: eModeCategoriesData[+market.emodeCategory.toString()] ? [...eModeCategoriesData[+market.emodeCategory.toString()].borrowAssets, selectedMarket.assets[i]] : [selectedMarket.assets[i]],
|
|
82
|
+
};
|
|
78
83
|
return ({
|
|
79
84
|
symbol: selectedMarket.assets[i],
|
|
80
85
|
isIsolated: new Dec(market.debtCeilingForIsolationMode.toString()).gt(0),
|
|
@@ -109,13 +114,6 @@ export const _getSparkMarketsData = (provider, network, selectedMarket) => __awa
|
|
|
109
114
|
isolationModeBorrowingEnabled: market.isolationModeBorrowingEnabled,
|
|
110
115
|
isFlashLoanEnabled: market.isFlashLoanEnabled,
|
|
111
116
|
aTokenAddress: market.aTokenAddress,
|
|
112
|
-
eModeCategoryData: {
|
|
113
|
-
label: market.label,
|
|
114
|
-
liquidationBonus: new Dec(market.liquidationBonus).div(10000).toString(),
|
|
115
|
-
liquidationRatio: new Dec(market.liquidationThreshold).div(10000).toString(),
|
|
116
|
-
collateralFactor: new Dec(market.ltv).div(10000).toString(),
|
|
117
|
-
priceSource: market.priceSource,
|
|
118
|
-
},
|
|
119
117
|
supplyIncentives: [],
|
|
120
118
|
borrowIncentives: [],
|
|
121
119
|
});
|
|
@@ -147,7 +145,7 @@ export const _getSparkMarketsData = (provider, network, selectedMarket) => __awa
|
|
|
147
145
|
return;
|
|
148
146
|
rewardForMarket.aIncentiveData.rewardsTokenInformation.forEach(supplyRewardData => {
|
|
149
147
|
if (supplyRewardData) {
|
|
150
|
-
if (supplyRewardData.emissionEndTimestamp * 1000 < Date.now())
|
|
148
|
+
if (+(supplyRewardData.emissionEndTimestamp.toString()) * 1000 < Date.now())
|
|
151
149
|
return;
|
|
152
150
|
const supplyEmissionPerSecond = supplyRewardData.emissionPerSecond;
|
|
153
151
|
const supplyRewardPrice = new Dec(supplyRewardData.rewardPriceFeed).div(Math.pow(10, supplyRewardData.priceFeedDecimals))
|
|
@@ -168,7 +166,7 @@ export const _getSparkMarketsData = (provider, network, selectedMarket) => __awa
|
|
|
168
166
|
});
|
|
169
167
|
rewardForMarket.vIncentiveData.rewardsTokenInformation.forEach(borrowRewardData => {
|
|
170
168
|
if (borrowRewardData) {
|
|
171
|
-
if (borrowRewardData.emissionEndTimestamp * 1000 < Date.now())
|
|
169
|
+
if (+(borrowRewardData.emissionEndTimestamp.toString()) * 1000 < Date.now())
|
|
172
170
|
return;
|
|
173
171
|
const supplyEmissionPerSecond = borrowRewardData.emissionPerSecond;
|
|
174
172
|
const supplyRewardPrice = new Dec(borrowRewardData.rewardPriceFeed).div(Math.pow(10, borrowRewardData.priceFeedDecimals))
|
|
@@ -189,7 +187,7 @@ export const _getSparkMarketsData = (provider, network, selectedMarket) => __awa
|
|
|
189
187
|
});
|
|
190
188
|
/* eslint-enable no-param-reassign */
|
|
191
189
|
})));
|
|
192
|
-
const
|
|
190
|
+
const filteredAssetsData = {};
|
|
193
191
|
// Sort by market size
|
|
194
192
|
assetsData
|
|
195
193
|
.sort((a, b) => {
|
|
@@ -198,9 +196,11 @@ export const _getSparkMarketsData = (provider, network, selectedMarket) => __awa
|
|
|
198
196
|
return new Dec(bMarket).minus(aMarket).toNumber();
|
|
199
197
|
})
|
|
200
198
|
.forEach((assetData, i) => {
|
|
201
|
-
|
|
199
|
+
filteredAssetsData[assetData.symbol] = Object.assign(Object.assign({}, assetData), { sortIndex: i });
|
|
202
200
|
});
|
|
203
|
-
|
|
201
|
+
eModeCategoriesData[0].collateralAssets = Object.values(filteredAssetsData).map(a => a.symbol);
|
|
202
|
+
eModeCategoriesData[0].borrowAssets = Object.values(filteredAssetsData).map(a => a.symbol);
|
|
203
|
+
return { assetsData: filteredAssetsData, eModeCategoriesData };
|
|
204
204
|
});
|
|
205
205
|
export const getSparkMarketsData = (provider, network, selectedMarket) => __awaiter(void 0, void 0, void 0, function* () { return _getSparkMarketsData(getViemProvider(provider, network), network, selectedMarket); });
|
|
206
206
|
export const EMPTY_SPARK_DATA = {
|
|
@@ -336,6 +336,6 @@ export const _getSparkAccountData = (provider, network, address, extractedState)
|
|
|
336
336
|
export const getSparkAccountData = (provider, network, address, extractedState) => __awaiter(void 0, void 0, void 0, function* () { return _getSparkAccountData(getViemProvider(provider, network), network, address, extractedState); });
|
|
337
337
|
export const getSparkFullPositionData = (provider, network, address, market) => __awaiter(void 0, void 0, void 0, function* () {
|
|
338
338
|
const marketData = yield getSparkMarketsData(provider, network, market);
|
|
339
|
-
const positionData = yield getSparkAccountData(provider, network, address, { assetsData: marketData.assetsData, selectedMarket: market });
|
|
339
|
+
const positionData = yield getSparkAccountData(provider, network, address, { assetsData: marketData.assetsData, selectedMarket: market, eModeCategoriesData: marketData.eModeCategoriesData });
|
|
340
340
|
return positionData;
|
|
341
341
|
});
|
package/esm/staking/staking.js
CHANGED
|
@@ -61,7 +61,7 @@ const getApyFromDfsApi = (asset) => __awaiter(void 0, void 0, void 0, function*
|
|
|
61
61
|
return '0';
|
|
62
62
|
}
|
|
63
63
|
});
|
|
64
|
-
export const STAKING_ASSETS = ['cbETH', 'wstETH', 'cbETH', 'rETH', 'sDAI', 'weETH', 'sUSDe', 'osETH', 'ezETH', 'ETHx', 'rsETH', 'pufETH', 'wrsETH', 'wsuperOETHb', 'sUSDS', 'tETH', 'PT sUSDe Sep', 'PT USDe Sep', 'PT sUSDe Nov', 'PT USDe Nov'];
|
|
64
|
+
export const STAKING_ASSETS = ['cbETH', 'wstETH', 'cbETH', 'rETH', 'sDAI', 'weETH', 'sUSDe', 'osETH', 'ezETH', 'ETHx', 'rsETH', 'pufETH', 'wrsETH', 'wsuperOETHb', 'sUSDS', 'tETH', 'PT sUSDe Sep', 'PT USDe Sep', 'PT sUSDe Nov', 'PT USDe Nov', 'PT USDe Jan', 'PT sUSDe Jan', 'wrsETH', 'wstETH'];
|
|
65
65
|
export const getStakingApy = memoize((asset) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
66
|
try {
|
|
67
67
|
if (asset === 'stETH' || asset === 'wstETH')
|
|
@@ -110,6 +110,10 @@ export const getStakingApy = memoize((asset) => __awaiter(void 0, void 0, void 0
|
|
|
110
110
|
return yield getApyFromDfsApi('PT sUSDe Nov');
|
|
111
111
|
if (asset === 'PT USDe Nov')
|
|
112
112
|
return yield getApyFromDfsApi('PT USDe Nov');
|
|
113
|
+
if (asset === 'PT USDe Jan')
|
|
114
|
+
return yield getApyFromDfsApi('PT USDe Jan');
|
|
115
|
+
if (asset === 'PT sUSDe Jan')
|
|
116
|
+
return yield getApyFromDfsApi('PT sUSDe Jan');
|
|
113
117
|
}
|
|
114
118
|
catch (e) {
|
|
115
119
|
console.error(`Failed to fetch APY for ${asset}`);
|
package/esm/types/spark.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EModeCategoriesData } from './aave';
|
|
1
2
|
import { EthAddress, MMAssetData, MMPositionData, MMUsedAsset, NetworkNumber } from './common';
|
|
2
3
|
export declare enum SparkVersions {
|
|
3
4
|
SparkV1 = "v1default"
|
|
@@ -13,8 +14,6 @@ export interface SparkEModeCategoryDataMapping {
|
|
|
13
14
|
enteringTerms: boolean[];
|
|
14
15
|
canEnterCategory: boolean;
|
|
15
16
|
id: number;
|
|
16
|
-
data: SparkEModeCategoryData;
|
|
17
|
-
assets: string[];
|
|
18
17
|
enabledData: {
|
|
19
18
|
ratio: string;
|
|
20
19
|
liqRatio: string;
|
|
@@ -45,7 +44,6 @@ export interface SparkAssetData extends MMAssetData {
|
|
|
45
44
|
usageAsCollateralEnabled: boolean;
|
|
46
45
|
isIsolated: boolean;
|
|
47
46
|
eModeCategory: number;
|
|
48
|
-
eModeCategoryData: SparkEModeCategoryData;
|
|
49
47
|
liquidationRatio: string;
|
|
50
48
|
}
|
|
51
49
|
export interface SparkAssetsData {
|
|
@@ -53,6 +51,7 @@ export interface SparkAssetsData {
|
|
|
53
51
|
}
|
|
54
52
|
export type SparkMarketsData = {
|
|
55
53
|
assetsData: SparkAssetsData;
|
|
54
|
+
eModeCategoriesData: EModeCategoriesData;
|
|
56
55
|
};
|
|
57
56
|
export interface SparkUsedAsset extends MMUsedAsset {
|
|
58
57
|
stableBorrowRate: string;
|
|
@@ -71,7 +70,7 @@ export interface SparkUsedAssets {
|
|
|
71
70
|
export interface SparkHelperCommon {
|
|
72
71
|
usedAssets: SparkUsedAssets;
|
|
73
72
|
eModeCategory: number;
|
|
74
|
-
|
|
73
|
+
eModeCategoriesData?: EModeCategoriesData;
|
|
75
74
|
assetsData: SparkAssetsData;
|
|
76
75
|
selectedMarket?: SparkMarketData;
|
|
77
76
|
network?: NetworkNumber;
|
package/package.json
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@defisaver/positions-sdk",
|
|
3
|
-
"version": "2.1.
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "./cjs/index.js",
|
|
6
|
-
"module": "./esm/index.js",
|
|
7
|
-
"types": "./esm/index.d.ts",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"build:esm": "rm -rf esm && tsc -p tsconfig.esm.json",
|
|
10
|
-
"build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json",
|
|
11
|
-
"build": "npm run lint && npm run build:cjs && npm run build:esm",
|
|
12
|
-
"dev": "tsc -p tsconfig.json --watch",
|
|
13
|
-
"lint": "eslint src/ --fix",
|
|
14
|
-
"lint-check": "eslint src/",
|
|
15
|
-
"test": "mocha tests/*",
|
|
16
|
-
"test-single": "mocha ./tests/$npm_config_name.ts",
|
|
17
|
-
"test:debugger": "mocha --inspect-brk tests/*",
|
|
18
|
-
"version-bump": "git commit -am \"Version bump to $(npm version patch | cut -c 2-)\""
|
|
19
|
-
},
|
|
20
|
-
"keywords": [],
|
|
21
|
-
"author": "",
|
|
22
|
-
"license": "ISC",
|
|
23
|
-
"dependencies": {
|
|
24
|
-
"@defisaver/tokens": "^1.7.
|
|
25
|
-
"@types/lodash": "^4.17.15",
|
|
26
|
-
"@types/memoizee": "^0.4.12",
|
|
27
|
-
"decimal.js": "^10.6.0",
|
|
28
|
-
"lodash": "^4.17.21",
|
|
29
|
-
"memoizee": "^0.4.17",
|
|
30
|
-
"viem": "^2.37.9"
|
|
31
|
-
},
|
|
32
|
-
"devDependencies": {
|
|
33
|
-
"@defisaver/eslint-config": "^1.0.1",
|
|
34
|
-
"@metamask/eth-json-rpc-middleware": "^15.0.1",
|
|
35
|
-
"@metamask/eth-json-rpc-provider": "^4.1.6",
|
|
36
|
-
"@types/chai": "^5.0.0",
|
|
37
|
-
"@types/mocha": "^10.0.9",
|
|
38
|
-
"chai": "^4.3.8",
|
|
39
|
-
"dotenv": "^16.3.1",
|
|
40
|
-
"eslint": "^8.49.0",
|
|
41
|
-
"eslint-plugin-import": "^2.31.0",
|
|
42
|
-
"mocha": "^10.2.0",
|
|
43
|
-
"nock": "^14.0.0",
|
|
44
|
-
"ts-node": "^10.9.2",
|
|
45
|
-
"typescript": "^5.2.2"
|
|
46
|
-
}
|
|
47
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@defisaver/positions-sdk",
|
|
3
|
+
"version": "2.1.11",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./cjs/index.js",
|
|
6
|
+
"module": "./esm/index.js",
|
|
7
|
+
"types": "./esm/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build:esm": "rm -rf esm && tsc -p tsconfig.esm.json",
|
|
10
|
+
"build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json",
|
|
11
|
+
"build": "npm run lint && npm run build:cjs && npm run build:esm",
|
|
12
|
+
"dev": "tsc -p tsconfig.json --watch",
|
|
13
|
+
"lint": "eslint src/ --fix",
|
|
14
|
+
"lint-check": "eslint src/",
|
|
15
|
+
"test": "mocha tests/*",
|
|
16
|
+
"test-single": "mocha ./tests/$npm_config_name.ts",
|
|
17
|
+
"test:debugger": "mocha --inspect-brk tests/*",
|
|
18
|
+
"version-bump": "git commit -am \"Version bump to $(npm version patch | cut -c 2-)\""
|
|
19
|
+
},
|
|
20
|
+
"keywords": [],
|
|
21
|
+
"author": "",
|
|
22
|
+
"license": "ISC",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@defisaver/tokens": "^1.7.7",
|
|
25
|
+
"@types/lodash": "^4.17.15",
|
|
26
|
+
"@types/memoizee": "^0.4.12",
|
|
27
|
+
"decimal.js": "^10.6.0",
|
|
28
|
+
"lodash": "^4.17.21",
|
|
29
|
+
"memoizee": "^0.4.17",
|
|
30
|
+
"viem": "^2.37.9"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@defisaver/eslint-config": "^1.0.1",
|
|
34
|
+
"@metamask/eth-json-rpc-middleware": "^15.0.1",
|
|
35
|
+
"@metamask/eth-json-rpc-provider": "^4.1.6",
|
|
36
|
+
"@types/chai": "^5.0.0",
|
|
37
|
+
"@types/mocha": "^10.0.9",
|
|
38
|
+
"chai": "^4.3.8",
|
|
39
|
+
"dotenv": "^16.3.1",
|
|
40
|
+
"eslint": "^8.49.0",
|
|
41
|
+
"eslint-plugin-import": "^2.31.0",
|
|
42
|
+
"mocha": "^10.2.0",
|
|
43
|
+
"nock": "^14.0.0",
|
|
44
|
+
"ts-node": "^10.9.2",
|
|
45
|
+
"typescript": "^5.2.2"
|
|
46
|
+
}
|
|
47
|
+
}
|