@defisaver/positions-sdk 2.1.151 → 2.1.152-shifter-v2-dev-dev

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.
Files changed (55) hide show
  1. package/cjs/claiming/compV3.js +0 -1
  2. package/cjs/config/contracts.d.ts +4 -0
  3. package/cjs/config/contracts.js +4 -0
  4. package/cjs/fluid/index.d.ts +2 -0
  5. package/cjs/fluid/index.js +36 -1
  6. package/cjs/helpers/morphoMidnightHelpers/tenor.d.ts +6 -2
  7. package/cjs/helpers/morphoMidnightHelpers/tenor.js +5 -1
  8. package/cjs/maker/index.d.ts +7 -2
  9. package/cjs/maker/index.js +27 -10
  10. package/cjs/markets/index.d.ts +2 -1
  11. package/cjs/markets/index.js +4 -1
  12. package/cjs/markets/maker/index.d.ts +1 -0
  13. package/cjs/markets/maker/index.js +13 -0
  14. package/cjs/markets/morphoMidnight/index.d.ts +92 -10
  15. package/cjs/markets/morphoMidnight/index.js +519 -60
  16. package/cjs/morphoMidnight/index.js +11 -1
  17. package/cjs/portfolio/index.d.ts +5 -1
  18. package/cjs/portfolio/index.js +287 -0
  19. package/cjs/types/morphoMidnight.d.ts +57 -4
  20. package/cjs/types/morphoMidnight.js +45 -0
  21. package/cjs/types/portfolio.d.ts +26 -10
  22. package/esm/claiming/compV3.js +0 -1
  23. package/esm/config/contracts.d.ts +4 -0
  24. package/esm/config/contracts.js +4 -0
  25. package/esm/fluid/index.d.ts +2 -0
  26. package/esm/fluid/index.js +33 -0
  27. package/esm/helpers/morphoMidnightHelpers/tenor.d.ts +6 -2
  28. package/esm/helpers/morphoMidnightHelpers/tenor.js +6 -2
  29. package/esm/maker/index.d.ts +7 -2
  30. package/esm/maker/index.js +26 -11
  31. package/esm/markets/index.d.ts +2 -1
  32. package/esm/markets/index.js +2 -1
  33. package/esm/markets/maker/index.d.ts +1 -0
  34. package/esm/markets/maker/index.js +10 -0
  35. package/esm/markets/morphoMidnight/index.d.ts +92 -10
  36. package/esm/markets/morphoMidnight/index.js +473 -59
  37. package/esm/morphoMidnight/index.js +11 -1
  38. package/esm/portfolio/index.d.ts +5 -1
  39. package/esm/portfolio/index.js +289 -3
  40. package/esm/types/morphoMidnight.d.ts +57 -4
  41. package/esm/types/morphoMidnight.js +45 -0
  42. package/esm/types/portfolio.d.ts +26 -10
  43. package/package.json +1 -1
  44. package/src/claiming/compV3.ts +0 -1
  45. package/src/config/contracts.ts +4 -0
  46. package/src/fluid/index.ts +40 -0
  47. package/src/helpers/morphoMidnightHelpers/tenor.ts +6 -2
  48. package/src/maker/index.ts +56 -28
  49. package/src/markets/index.ts +3 -1
  50. package/src/markets/maker/index.ts +10 -0
  51. package/src/markets/morphoMidnight/index.ts +724 -61
  52. package/src/morphoMidnight/index.ts +8 -1
  53. package/src/portfolio/index.ts +270 -2
  54. package/src/types/morphoMidnight.ts +59 -3
  55. package/src/types/portfolio.ts +31 -12
@@ -1830,3 +1830,43 @@ export const _getUserPositionsPortfolio = async (provider: PublicClient, network
1830
1830
  userData: userData[i],
1831
1831
  })).filter(md => md.marketData !== undefined);
1832
1832
  };
1833
+
1834
+
1835
+ export const _getAllFluidMarketDataPortfolio = async (provider: PublicClient, network: NetworkNumber): Promise<Record<string, FluidMarketData>> => {
1836
+ const versions = getFluidVersionsDataForNetwork(network);
1837
+ if (versions.length === 0) return {};
1838
+
1839
+ const view = FluidViewContractViem(provider, network);
1840
+ const vaultsData = await Promise.all(versions.map((version) => view.read.getVaultData([version.marketAddress])));
1841
+
1842
+ const tokens = Array.from(new Set(vaultsData.map((vaultData) => {
1843
+ const vaultTokens = [getAssetInfoByAddress(vaultData.supplyToken0, network).symbol, getAssetInfoByAddress(vaultData.borrowToken0, network).symbol];
1844
+ if (vaultData.supplyToken1 && !compareAddresses(ZERO_ADDRESS, vaultData.supplyToken1)) vaultTokens.push(getAssetInfoByAddress(vaultData.supplyToken1, network).symbol);
1845
+ if (vaultData.borrowToken1 && !compareAddresses(ZERO_ADDRESS, vaultData.borrowToken1)) vaultTokens.push(getAssetInfoByAddress(vaultData.borrowToken1, network).symbol);
1846
+ return vaultTokens;
1847
+ }).flat()));
1848
+
1849
+ // ETH and WBTC needed for other tokens prices
1850
+ if (!tokens.includes('ETH')) tokens.push('ETH');
1851
+ if (!tokens.includes('WBTC')) tokens.push('WBTC');
1852
+
1853
+ const [tokenPrices, merklCampaigns] = await Promise.all([
1854
+ getTokensPricesForPortfolio(tokens, provider, network),
1855
+ getFluidMerklCampaigns(network),
1856
+ ]);
1857
+
1858
+ const parsedMarketsData = await Promise.all(vaultsData.map(async (vaultData) => parseMarketData(provider, vaultData, network, tokenPrices)));
1859
+
1860
+ const marketsData: Record<string, FluidMarketData> = {};
1861
+ parsedMarketsData.forEach((marketData, i) => {
1862
+ if (!marketData) return;
1863
+ marketsData[versions[i].value] = attachFluidMerklIncentives(marketData, merklCampaigns);
1864
+ });
1865
+
1866
+ return marketsData;
1867
+ };
1868
+
1869
+ export const getAllFluidMarketDataPortfolio = async (
1870
+ provider: EthereumProvider,
1871
+ network: NetworkNumber,
1872
+ ): Promise<Record<string, FluidMarketData>> => _getAllFluidMarketDataPortfolio(getViemProvider(provider, network, { batch: { multicall: true } }), network);
@@ -8,7 +8,7 @@ import {
8
8
  MorphoMidnightParsedBook,
9
9
  NetworkNumber,
10
10
  } from '../../types';
11
- import { isTenorMidnightMarket, MIDNIGHT_BASE } from '../../markets/morphoMidnight';
11
+ import { isTenorMidnightMarket, midnightCoreAddress } from '../../markets/morphoMidnight';
12
12
  import type {
13
13
  MorphoMidnightBorrowQuote,
14
14
  MorphoMidnightPaybackQuote,
@@ -83,11 +83,15 @@ interface TenorOfferFill {
83
83
  /**
84
84
  * Tenor's offer JSON is flat (market fields live on the offer). Morpho's is nested, and that nested
85
85
  * shape is what the app encodes for `Midnight.take`. Map Tenor into that shape so recipes stay on one encoder.
86
+ *
87
+ * The core address is the one field Tenor's offer does not carry, so it is derived from the offer's own
88
+ * `chain_id` rather than the caller's network — an offer names the chain it was made on, and taking it
89
+ * against another chain's core would address a market that does not exist.
86
90
  */
87
91
  export const tenorOfferToApiOffer = (offer: TenorOffer) => ({
88
92
  market: {
89
93
  chain_id: offer.chain_id,
90
- midnight: MIDNIGHT_BASE,
94
+ midnight: midnightCoreAddress(Number(offer.chain_id) as NetworkNumber),
91
95
  loan_token: offer.loan_token_address,
92
96
  collaterals: offer.collaterals || [],
93
97
  maturity: offer.maturity,
@@ -1,15 +1,17 @@
1
1
  import Dec from 'decimal.js';
2
2
  import {
3
- assetAmountInEth, bytesToString, getAssetInfo, ilkToAsset,
3
+ assetAmountInEth, bytesToString, getAssetInfo, ilkToAsset, stringToBytes,
4
4
  } from '@defisaver/tokens';
5
5
  import { Client, PublicClient } from 'viem';
6
6
  import {
7
- Blockish, EthAddress, EthereumProvider, NetworkNumber, PositionBalances,
7
+ Blockish, EthAddress, EthereumProvider, HexString, NetworkNumber, PositionBalances,
8
8
  } from '../types/common';
9
9
  import {
10
10
  getConfigContractAddress, McdDogContractViem, McdGetCdpsContractViem, McdJugContractViem, McdSpotterContractViem, McdVatContractViem, McdViewContractViem,
11
11
  } from '../contracts';
12
- import { CdpData, CdpInfo, CdpType } from '../types';
12
+ import {
13
+ CdpData, CdpInfo, CdpType, IlkInfo,
14
+ } from '../types';
13
15
  import { wethToEth } from '../services/utils';
14
16
  import { parseCollateralInfo } from '../helpers/makerHelpers';
15
17
  import { getViemProvider, setViemBlockNumber } from '../services/viem';
@@ -129,44 +131,70 @@ export const getUserCdps = async (
129
131
  userAddress: EthAddress,
130
132
  ): Promise<CdpInfo[]> => _getUserCdps(getViemProvider(provider, network), network, userAddress);
131
133
 
132
- export const _getMakerCdpData = async (provider: Client, network: NetworkNumber, cdp: CdpInfo): Promise<CdpData> => {
134
+ export const _getMakerIlksData = async (provider: Client, network: NetworkNumber, ilkLabels: string[]): Promise<Record<string, IlkInfo>> => {
133
135
  const vatContract = McdVatContractViem(provider, network);
134
136
  const spotterContract = McdSpotterContractViem(provider, network);
135
137
  const dogContract = McdDogContractViem(provider, network);
136
138
  const jugContract = McdJugContractViem(provider, network);
137
139
 
140
+ const par = await spotterContract.read.par();
141
+
142
+ const ilksInfo = await Promise.all(ilkLabels.map(async (ilkLabel) => {
143
+ const ilk = stringToBytes(ilkLabel) as HexString;
144
+ const [
145
+ [_, mat],
146
+ [artGlobal, rate, spot, line],
147
+ [duty],
148
+ futureRate,
149
+ chop,
150
+ ] = await Promise.all([
151
+ spotterContract.read.ilks([ilk]),
152
+ vatContract.read.ilks([ilk]),
153
+ jugContract.read.ilks([ilk]),
154
+ jugContract.read.drip([ilk]),
155
+ dogContract.read.chop([ilk]),
156
+ ]);
157
+
158
+ return parseCollateralInfo(
159
+ ilk,
160
+ par.toString(),
161
+ mat.toString(),
162
+ artGlobal.toString(),
163
+ rate.toString(),
164
+ spot.toString(),
165
+ line.toString(),
166
+ duty.toString(),
167
+ futureRate.toString(),
168
+ chop.toString(),
169
+ );
170
+ }));
171
+
172
+ return Object.fromEntries(ilksInfo.map((ilkInfo) => [ilkInfo.ilkLabel, ilkInfo]));
173
+ };
174
+
175
+ export const getMakerIlksData = async (
176
+ provider: EthereumProvider,
177
+ network: NetworkNumber,
178
+ ilkLabels: string[],
179
+ ): Promise<Record<string, IlkInfo>> => _getMakerIlksData(getViemProvider(provider, network, { batch: { multicall: true } }), network, ilkLabels);
180
+
181
+ /**
182
+ * @param ilkInfo optional precomputed ilk data (from `_getMakerIlksData`); when provided the per-ilk reads are skipped
183
+ */
184
+ export const _getMakerCdpData = async (provider: Client, network: NetworkNumber, cdp: CdpInfo, ilkInfo?: IlkInfo): Promise<CdpData> => {
185
+ const vatContract = McdVatContractViem(provider, network);
186
+
138
187
  const [
139
188
  [ink, art],
140
189
  coll,
141
- par,
142
- [_, mat],
143
- [artGlobal, rate, spot, line],
144
- [duty],
145
- futureRate,
146
- chop,
190
+ fetchedIlkInfo,
147
191
  ] = await Promise.all([
148
192
  vatContract.read.urns([cdp.ilk, cdp.urn]),
149
193
  vatContract.read.gem([cdp.ilk, cdp.urn]),
150
- spotterContract.read.par(),
151
- spotterContract.read.ilks([cdp.ilk]),
152
- vatContract.read.ilks([cdp.ilk]),
153
- jugContract.read.ilks([cdp.ilk]),
154
- jugContract.read.drip([cdp.ilk]),
155
- dogContract.read.chop([cdp.ilk]),
194
+ ilkInfo || _getMakerIlksData(provider, network, [cdp.ilkLabel]).then((ilks) => ilks[cdp.ilkLabel]),
156
195
  ]);
157
196
 
158
- const collInfo = parseCollateralInfo(
159
- cdp.ilk,
160
- par.toString(),
161
- mat.toString(),
162
- artGlobal.toString(),
163
- rate.toString(),
164
- spot.toString(),
165
- line.toString(),
166
- duty.toString(),
167
- futureRate.toString(),
168
- chop.toString(),
169
- );
197
+ const collInfo = fetchedIlkInfo;
170
198
 
171
199
  const collateral = assetAmountInEth(ink.toString(), `MCD-${cdp.asset}`);
172
200
 
@@ -19,6 +19,7 @@ export { CrvUsdMarkets } from './curveUsd';
19
19
  export { MorphoBlueMarkets, findMorphoBlueMarket } from './morphoBlue';
20
20
  export {
21
21
  MorphoMidnightMarkets, findMorphoMidnightMarket, isTenorMidnightMarket, morphoMidnightMarketCollateralParams,
22
+ morphoMidnightVisibleCollaterals,
22
23
  } from './morphoMidnight';
23
24
  export { LlamaLendMarkets } from './llamaLend';
24
25
  export { LiquityV2Markets, findLiquityV2MarketByAddress } from './liquityV2';
@@ -29,4 +30,5 @@ export {
29
30
  getFTokenAddress,
30
31
  getFluidMarketInfoByAddress,
31
32
  } from './fluid';
32
- export { AaveV4Spokes, findAaveV4SpokeByAddress } from './aaveV4';
33
+ export { AaveV4Spokes, findAaveV4SpokeByAddress } from './aaveV4';
34
+ export { MakerActiveIlks } from './maker';
@@ -0,0 +1,10 @@
1
+ export const MakerActiveIlks: string[] = [
2
+ 'ETH-A',
3
+ 'ETH-B',
4
+ 'ETH-C',
5
+ 'WSTETH-A',
6
+ 'WSTETH-B',
7
+ 'WBTC-A',
8
+ 'WBTC-B',
9
+ 'WBTC-C',
10
+ ];