@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.
- package/cjs/claiming/compV3.js +0 -1
- package/cjs/config/contracts.d.ts +4 -0
- package/cjs/config/contracts.js +4 -0
- package/cjs/fluid/index.d.ts +2 -0
- package/cjs/fluid/index.js +36 -1
- package/cjs/helpers/morphoMidnightHelpers/tenor.d.ts +6 -2
- package/cjs/helpers/morphoMidnightHelpers/tenor.js +5 -1
- package/cjs/maker/index.d.ts +7 -2
- package/cjs/maker/index.js +27 -10
- package/cjs/markets/index.d.ts +2 -1
- package/cjs/markets/index.js +4 -1
- package/cjs/markets/maker/index.d.ts +1 -0
- package/cjs/markets/maker/index.js +13 -0
- package/cjs/markets/morphoMidnight/index.d.ts +92 -10
- package/cjs/markets/morphoMidnight/index.js +519 -60
- package/cjs/morphoMidnight/index.js +11 -1
- package/cjs/portfolio/index.d.ts +5 -1
- package/cjs/portfolio/index.js +287 -0
- package/cjs/types/morphoMidnight.d.ts +57 -4
- package/cjs/types/morphoMidnight.js +45 -0
- package/cjs/types/portfolio.d.ts +26 -10
- package/esm/claiming/compV3.js +0 -1
- package/esm/config/contracts.d.ts +4 -0
- package/esm/config/contracts.js +4 -0
- package/esm/fluid/index.d.ts +2 -0
- package/esm/fluid/index.js +33 -0
- package/esm/helpers/morphoMidnightHelpers/tenor.d.ts +6 -2
- package/esm/helpers/morphoMidnightHelpers/tenor.js +6 -2
- package/esm/maker/index.d.ts +7 -2
- package/esm/maker/index.js +26 -11
- package/esm/markets/index.d.ts +2 -1
- package/esm/markets/index.js +2 -1
- package/esm/markets/maker/index.d.ts +1 -0
- package/esm/markets/maker/index.js +10 -0
- package/esm/markets/morphoMidnight/index.d.ts +92 -10
- package/esm/markets/morphoMidnight/index.js +473 -59
- package/esm/morphoMidnight/index.js +11 -1
- package/esm/portfolio/index.d.ts +5 -1
- package/esm/portfolio/index.js +289 -3
- package/esm/types/morphoMidnight.d.ts +57 -4
- package/esm/types/morphoMidnight.js +45 -0
- package/esm/types/portfolio.d.ts +26 -10
- package/package.json +1 -1
- package/src/claiming/compV3.ts +0 -1
- package/src/config/contracts.ts +4 -0
- package/src/fluid/index.ts +40 -0
- package/src/helpers/morphoMidnightHelpers/tenor.ts +6 -2
- package/src/maker/index.ts +56 -28
- package/src/markets/index.ts +3 -1
- package/src/markets/maker/index.ts +10 -0
- package/src/markets/morphoMidnight/index.ts +724 -61
- package/src/morphoMidnight/index.ts +8 -1
- package/src/portfolio/index.ts +270 -2
- package/src/types/morphoMidnight.ts +59 -3
- package/src/types/portfolio.ts +31 -12
package/src/fluid/index.ts
CHANGED
|
@@ -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,
|
|
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:
|
|
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,
|
package/src/maker/index.ts
CHANGED
|
@@ -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 {
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
|
package/src/markets/index.ts
CHANGED
|
@@ -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';
|