@defisaver/positions-sdk 2.1.159-shifter-v2-dev → 2.1.160-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/aaveV2/index.js +0 -2
- package/cjs/constants/index.d.ts +1 -0
- package/cjs/constants/index.js +4 -1
- package/cjs/fluid/index.d.ts +0 -5
- package/cjs/fluid/index.js +1 -36
- package/cjs/helpers/aaveHelpers/index.js +0 -3
- package/cjs/helpers/aaveV4Helpers/index.js +0 -1
- package/cjs/helpers/compoundHelpers/index.js +0 -2
- package/cjs/helpers/curveUsdHelpers/index.js +0 -2
- package/cjs/helpers/fluidHelpers/index.js +0 -1
- package/cjs/helpers/liquityV2Helpers/index.js +0 -1
- package/cjs/helpers/llamaLendHelpers/index.js +0 -2
- package/cjs/helpers/makerHelpers/index.d.ts +1 -1
- package/cjs/helpers/makerHelpers/index.js +2 -2
- package/cjs/helpers/morphoBlueHelpers/index.js +3 -6
- package/cjs/helpers/morphoMidnightHelpers/index.js +0 -2
- package/cjs/helpers/sparkHelpers/index.js +0 -1
- package/cjs/liquity/index.js +1 -8
- package/cjs/maker/index.d.ts +2 -7
- package/cjs/maker/index.js +12 -32
- package/cjs/markets/index.d.ts +0 -1
- package/cjs/markets/index.js +1 -3
- package/cjs/portfolio/index.d.ts +1 -5
- package/cjs/portfolio/index.js +0 -272
- package/cjs/savings/morphoVaults/index.js +2 -2
- package/cjs/types/aave.d.ts +0 -2
- package/cjs/types/aaveV4.d.ts +0 -1
- package/cjs/types/compound.d.ts +0 -2
- package/cjs/types/fluid.d.ts +0 -1
- package/cjs/types/liquity.d.ts +0 -1
- package/cjs/types/liquityV2.d.ts +0 -2
- package/cjs/types/maker.d.ts +0 -1
- package/cjs/types/morphoBlue.d.ts +0 -2
- package/cjs/types/morphoMidnight.d.ts +0 -1
- package/cjs/types/portfolio.d.ts +10 -26
- package/cjs/types/spark.d.ts +0 -2
- package/esm/aaveV2/index.js +0 -2
- package/esm/constants/index.d.ts +1 -0
- package/esm/constants/index.js +3 -0
- package/esm/fluid/index.d.ts +0 -5
- package/esm/fluid/index.js +0 -33
- package/esm/helpers/aaveHelpers/index.js +0 -3
- package/esm/helpers/aaveV4Helpers/index.js +0 -1
- package/esm/helpers/compoundHelpers/index.js +0 -2
- package/esm/helpers/curveUsdHelpers/index.js +0 -2
- package/esm/helpers/fluidHelpers/index.js +0 -1
- package/esm/helpers/liquityV2Helpers/index.js +0 -1
- package/esm/helpers/llamaLendHelpers/index.js +0 -2
- package/esm/helpers/makerHelpers/index.d.ts +1 -1
- package/esm/helpers/makerHelpers/index.js +2 -2
- package/esm/helpers/morphoBlueHelpers/index.js +4 -7
- package/esm/helpers/morphoMidnightHelpers/index.js +0 -2
- package/esm/helpers/sparkHelpers/index.js +0 -1
- package/esm/liquity/index.js +1 -8
- package/esm/maker/index.d.ts +2 -7
- package/esm/maker/index.js +13 -31
- package/esm/markets/index.d.ts +0 -1
- package/esm/markets/index.js +0 -1
- package/esm/portfolio/index.d.ts +1 -5
- package/esm/portfolio/index.js +3 -274
- package/esm/savings/morphoVaults/index.js +2 -2
- package/esm/types/aave.d.ts +0 -2
- package/esm/types/aaveV4.d.ts +0 -1
- package/esm/types/compound.d.ts +0 -2
- package/esm/types/fluid.d.ts +0 -1
- package/esm/types/liquity.d.ts +0 -1
- package/esm/types/liquityV2.d.ts +0 -2
- package/esm/types/maker.d.ts +0 -1
- package/esm/types/morphoBlue.d.ts +0 -2
- package/esm/types/morphoMidnight.d.ts +0 -1
- package/esm/types/portfolio.d.ts +10 -26
- package/esm/types/spark.d.ts +0 -2
- package/package.json +1 -1
- package/src/aaveV2/index.ts +0 -2
- package/src/constants/index.ts +5 -1
- package/src/fluid/index.ts +0 -40
- package/src/helpers/aaveHelpers/index.ts +0 -3
- package/src/helpers/aaveV4Helpers/index.ts +0 -1
- package/src/helpers/compoundHelpers/index.ts +0 -2
- package/src/helpers/curveUsdHelpers/index.ts +0 -2
- package/src/helpers/fluidHelpers/index.ts +0 -1
- package/src/helpers/liquityV2Helpers/index.ts +0 -1
- package/src/helpers/llamaLendHelpers/index.ts +0 -2
- package/src/helpers/makerHelpers/index.ts +1 -2
- package/src/helpers/morphoBlueHelpers/index.ts +6 -7
- package/src/helpers/morphoMidnightHelpers/index.ts +0 -2
- package/src/helpers/sparkHelpers/index.ts +0 -1
- package/src/liquity/index.ts +1 -8
- package/src/maker/index.ts +29 -62
- package/src/markets/index.ts +1 -2
- package/src/portfolio/index.ts +2 -257
- package/src/savings/morphoVaults/index.ts +2 -3
- package/src/types/aave.ts +0 -3
- package/src/types/aaveV4.ts +0 -1
- package/src/types/compound.ts +0 -2
- package/src/types/fluid.ts +0 -1
- package/src/types/liquity.ts +0 -2
- package/src/types/liquityV2.ts +0 -2
- package/src/types/maker.ts +0 -2
- package/src/types/morphoBlue.ts +0 -2
- package/src/types/morphoMidnight.ts +0 -1
- package/src/types/portfolio.ts +12 -31
- package/src/types/spark.ts +0 -2
- package/cjs/markets/maker/index.d.ts +0 -1
- package/cjs/markets/maker/index.js +0 -13
- package/esm/markets/maker/index.d.ts +0 -1
- package/esm/markets/maker/index.js +0 -10
- package/src/markets/maker/index.ts +0 -10
package/esm/types/fluid.d.ts
CHANGED
package/esm/types/liquity.d.ts
CHANGED
package/esm/types/liquityV2.d.ts
CHANGED
|
@@ -94,7 +94,6 @@ export interface LiquityV2AggregatedTroveData {
|
|
|
94
94
|
liquidationPrice: string;
|
|
95
95
|
ratio: string;
|
|
96
96
|
collRatio: string;
|
|
97
|
-
safetyRatio: string;
|
|
98
97
|
exposure: string;
|
|
99
98
|
}
|
|
100
99
|
export interface LiquityV2TroveData {
|
|
@@ -102,7 +101,6 @@ export interface LiquityV2TroveData {
|
|
|
102
101
|
troveId: string;
|
|
103
102
|
ratio: string;
|
|
104
103
|
collRatio: string;
|
|
105
|
-
safetyRatio?: string;
|
|
106
104
|
liqRatio: string;
|
|
107
105
|
borrowLimitRatio: string;
|
|
108
106
|
interestRate: string;
|
package/esm/types/maker.d.ts
CHANGED
|
@@ -185,7 +185,6 @@ export interface MorphoBlueAggregatedPositionData {
|
|
|
185
185
|
totalInterestUsd: string;
|
|
186
186
|
ltv: string;
|
|
187
187
|
ratio: string;
|
|
188
|
-
safetyRatio: string;
|
|
189
188
|
leveragedType: LeverageType;
|
|
190
189
|
leveragedAsset?: string;
|
|
191
190
|
currentVolatilePairRatio?: string;
|
|
@@ -208,7 +207,6 @@ export interface MorphoBluePositionData {
|
|
|
208
207
|
totalInterestUsd: string;
|
|
209
208
|
ltv: string;
|
|
210
209
|
ratio: string;
|
|
211
|
-
safetyRatio?: string;
|
|
212
210
|
leveragedType: LeverageType;
|
|
213
211
|
leveragedAsset?: string;
|
|
214
212
|
currentVolatilePairRatio?: string;
|
package/esm/types/portfolio.d.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AaveV4AccountData,
|
|
1
|
+
import { AaveV2PositionData, AaveV3PositionData, AaveVersions } from './aave';
|
|
2
|
+
import { AaveV4AccountData, AaveV4SpokesType } from './aaveV4';
|
|
3
3
|
import { EthAddress } from './common';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { CompoundV2PositionData, CompoundV3PositionData, CompoundVersions } from './compound';
|
|
5
|
+
import { CrvUSDUserData, CrvUSDVersions } from './curveUsd';
|
|
6
|
+
import { FluidVaultData } from './fluid';
|
|
7
7
|
import { LiquityTroveInfo } from './liquity';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { SparkMarketsData, SparkPositionData, SparkVersions } from './spark';
|
|
8
|
+
import { LlamaLendUserData, LlamaLendVersionsType } from './llamaLend';
|
|
9
|
+
import { CdpData } from './maker';
|
|
10
|
+
import { MorphoBluePositionData, MorphoBlueVersions } from './morphoBlue';
|
|
11
|
+
import { MorphoMidnightPositionData, MorphoMidnightVersions } from './morphoMidnight';
|
|
12
|
+
import { SparkPositionData, SparkVersions } from './spark';
|
|
14
13
|
export interface PortfolioProtocolData<T> {
|
|
15
14
|
error: string;
|
|
16
15
|
data: T | null;
|
|
@@ -60,18 +59,3 @@ export interface PortfolioPositionsDataForAddress {
|
|
|
60
59
|
export interface PortfolioPositionsData {
|
|
61
60
|
[key: EthAddress]: PortfolioPositionsDataForAddress;
|
|
62
61
|
}
|
|
63
|
-
export interface PortfolioMarketsData {
|
|
64
|
-
morphoMarketsData: Record<string, MorphoBlueMarketInfo>;
|
|
65
|
-
morphoMidnightMarketsData: Record<string, MorphoMidnightMarketInfo>;
|
|
66
|
-
compoundV3MarketsData: Record<string, CompoundV3MarketsData>;
|
|
67
|
-
sparkMarketsData: Record<string, SparkMarketsData>;
|
|
68
|
-
aaveV3MarketsData: Record<string, AaveV3MarketData>;
|
|
69
|
-
aaveV2MarketsData: Record<string, AaveV2MarketData>;
|
|
70
|
-
compoundV2MarketsData: Record<string, CompoundV2MarketsData>;
|
|
71
|
-
crvUsdMarketsData: Record<string, CrvUSDGlobalMarketData>;
|
|
72
|
-
llamaLendMarketsData: Record<string, LlamaLendGlobalMarketData>;
|
|
73
|
-
liquityV2MarketsData: Record<string, LiquityV2MarketData>;
|
|
74
|
-
aaveV4SpokesData: Record<string, AaveV4SpokeData>;
|
|
75
|
-
fluidMarketsData: Record<string, FluidMarketData>;
|
|
76
|
-
makerMarketsData: Record<string, IlkInfo>;
|
|
77
|
-
}
|
package/esm/types/spark.d.ts
CHANGED
|
@@ -85,7 +85,6 @@ export interface SparkAggregatedPositionData {
|
|
|
85
85
|
leftToBorrowUsd: string;
|
|
86
86
|
ratio: string;
|
|
87
87
|
collRatio: string;
|
|
88
|
-
safetyRatio: string;
|
|
89
88
|
netApy: string;
|
|
90
89
|
incentiveUsd: string;
|
|
91
90
|
totalInterestUsd: string;
|
|
@@ -105,7 +104,6 @@ export interface SparkPositionData extends MMPositionData {
|
|
|
105
104
|
ratio: string;
|
|
106
105
|
minRatio: string;
|
|
107
106
|
collRatio: string;
|
|
108
|
-
safetyRatio?: string;
|
|
109
107
|
suppliedUsd: string;
|
|
110
108
|
borrowedUsd: string;
|
|
111
109
|
borrowLimitUsd: string;
|
package/package.json
CHANGED
package/src/aaveV2/index.ts
CHANGED
|
@@ -210,8 +210,6 @@ export const _getAaveV2AccountData = async (provider: Client, network: NetworkNu
|
|
|
210
210
|
payload.collRatio = payload.borrowedUsd && payload.borrowedUsd !== '0'
|
|
211
211
|
? new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString()
|
|
212
212
|
: '0';
|
|
213
|
-
// Aave v2 has no LTV-0 fallback (AaveV3View only), so its safety ratio is the plain ratio.
|
|
214
|
-
payload.safetyRatio = payload.ratio;
|
|
215
213
|
|
|
216
214
|
// Calculate borrow limits per asset
|
|
217
215
|
Object.values(payload.usedAssets).forEach((item) => {
|
package/src/constants/index.ts
CHANGED
|
@@ -9,4 +9,8 @@ export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|
|
9
9
|
export const ZERO_BYTES32 = '0x0000000000000000000000000000000000000000000000000000000000000000';
|
|
10
10
|
export const WAD = 1e18;
|
|
11
11
|
export const USD_QUOTE = '0x0000000000000000000000000000000000000348';
|
|
12
|
-
export const borrowOperations = ['borrow', 'payback'];
|
|
12
|
+
export const borrowOperations = ['borrow', 'payback'];
|
|
13
|
+
|
|
14
|
+
// Proxies Morpho's GraphQL API through the DFS backend, which attaches the private API key
|
|
15
|
+
// for better rate limits (DEV-13673)
|
|
16
|
+
export const MORPHO_API_URL = 'https://fe.defisaver.com/api/morpho/graphql';
|
package/src/fluid/index.ts
CHANGED
|
@@ -1830,43 +1830,3 @@ 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);
|
|
@@ -169,9 +169,6 @@ export const aaveAnyGetAggregatedPositionData = ({
|
|
|
169
169
|
},
|
|
170
170
|
);
|
|
171
171
|
payload.safetyRatioWithLtvZeroFallback = +payload.suppliedUsd ? new Dec(payload.borrowLimitWithLtvZeroFallbackUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
172
|
-
// Normalised safety ratio (100 = liquidation on every protocol): the automation ratio above, falling back
|
|
173
|
-
// to the regular ratio when the fallback carries its '0' placeholder.
|
|
174
|
-
payload.safetyRatio = +payload.safetyRatioWithLtvZeroFallback ? payload.safetyRatioWithLtvZeroFallback : payload.ratio;
|
|
175
172
|
payload.liqRatio = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).toString();
|
|
176
173
|
payload.liqPercent = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
177
174
|
const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
|
|
@@ -270,7 +270,6 @@ export const aaveV4GetAggregatedPositionData = ({
|
|
|
270
270
|
payload.ratio = +payload.suppliedUsd ? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
271
271
|
payload.minRatio = '100';
|
|
272
272
|
payload.collRatio = +payload.suppliedUsd ? new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
273
|
-
payload.safetyRatio = payload.ratio;
|
|
274
273
|
payload.liqRatio = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).toString();
|
|
275
274
|
payload.liqPercent = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
276
275
|
const { leveragedType, leveragedAsset } = isLeveragedPosAaveV4(usedAssets);
|
|
@@ -139,7 +139,6 @@ export const getCompoundV2AggregatedData = ({
|
|
|
139
139
|
payload.collRatio = payload.borrowedUsd && payload.borrowedUsd !== '0'
|
|
140
140
|
? new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString()
|
|
141
141
|
: '0';
|
|
142
|
-
payload.safetyRatio = payload.ratio;
|
|
143
142
|
|
|
144
143
|
// Calculate borrow limits per asset
|
|
145
144
|
Object.values(usedAssets).forEach((item) => {
|
|
@@ -186,7 +185,6 @@ export const getCompoundV3AggregatedData = ({
|
|
|
186
185
|
payload.incentiveUsd = incentiveUsd;
|
|
187
186
|
payload.totalInterestUsd = totalInterestUsd;
|
|
188
187
|
payload.minRatio = '100';
|
|
189
|
-
payload.safetyRatio = payload.ratio;
|
|
190
188
|
payload.liqRatio = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).toString();
|
|
191
189
|
payload.liqPercent = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
192
190
|
payload.minDebt = assetsData[selectedMarket.baseAsset].minDebt;
|
|
@@ -26,8 +26,6 @@ export const getCrvUsdAggregatedData = ({
|
|
|
26
26
|
|
|
27
27
|
// this is all approximation
|
|
28
28
|
payload.minAllowedRatio = mapRange(numOfBands, 4, 50, 115, 140); // collateral ratio
|
|
29
|
-
// Collateral ratio rebased so 100 sits on the band-derived minimum (normalised safety ratio, same scale as the other protocols).
|
|
30
|
-
payload.safetyRatio = loanExists && payload.minAllowedRatio ? new Dec(payload.ratio).div(payload.minAllowedRatio).mul(100).toString() : '0';
|
|
31
29
|
payload.collFactor = new Dec(1).div(payload.minAllowedRatio).mul(100).toString(); // collateral factor = 1 / collateral ratio
|
|
32
30
|
// only take in consideration collAsset
|
|
33
31
|
payload.borrowLimitUsd = usedAssets?.[selectedMarket.collAsset]?.isSupplied
|
|
@@ -143,7 +143,6 @@ borrowShares?: string,
|
|
|
143
143
|
payload.ratio = +payload.suppliedUsd ? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
144
144
|
payload.collRatio = +payload.suppliedUsd ? new Dec(payload.suppliedUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
145
145
|
payload.minRatio = marketData.minRatio;
|
|
146
|
-
payload.safetyRatio = payload.ratio;
|
|
147
146
|
const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
|
|
148
147
|
|
|
149
148
|
payload.leveragedType = leveragedType;
|
|
@@ -69,7 +69,6 @@ export const getLiquityV2AggregatedPositionData = ({
|
|
|
69
69
|
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
70
70
|
payload.ratio = (+payload.suppliedUsd && +payload.borrowedUsd) ? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
71
71
|
payload.collRatio = (+payload.suppliedUsd && +payload.borrowedUsd) ? new Dec(payload.suppliedUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
72
|
-
payload.safetyRatio = payload.ratio;
|
|
73
72
|
const { netApy, incentiveUsd, totalInterestUsd } = calculateNetApyLiquityV2(usedAssets, assetsData, interestRate);
|
|
74
73
|
payload.netApy = netApy;
|
|
75
74
|
payload.incentiveUsd = incentiveUsd;
|
|
@@ -38,8 +38,6 @@ export const getLlamaLendAggregatedData = ({
|
|
|
38
38
|
|
|
39
39
|
// this is all approximation
|
|
40
40
|
payload.minAllowedRatio = mapRange(numOfBands, 4, 50, 115, 140); // collateral ratio
|
|
41
|
-
// Collateral ratio rebased so 100 sits on the band-derived minimum (normalised safety ratio, same scale as the other protocols).
|
|
42
|
-
payload.safetyRatio = loanExists && payload.minAllowedRatio ? new Dec(payload.ratio).div(payload.minAllowedRatio).mul(100).toString() : '0';
|
|
43
41
|
payload.collFactor = new Dec(1).div(payload.minAllowedRatio).mul(100).toString(); // collateral factor = 1 / collateral ratio
|
|
44
42
|
// only take in consideration collAsset
|
|
45
43
|
payload.borrowLimitUsd = usedAssets?.[collAsset]?.isSupplied
|
|
@@ -10,7 +10,6 @@ export const parseCollateralInfo = (
|
|
|
10
10
|
_rate: string,
|
|
11
11
|
_spot: string,
|
|
12
12
|
_line: string,
|
|
13
|
-
_dust: string,
|
|
14
13
|
_duty: string,
|
|
15
14
|
_futureRate: string,
|
|
16
15
|
_chop: string,
|
|
@@ -21,7 +20,7 @@ export const parseCollateralInfo = (
|
|
|
21
20
|
const rate = new Dec(_rate).toString();
|
|
22
21
|
const spot = new Dec(_spot).div(1e27).toString();
|
|
23
22
|
const line = new Dec(_line).div(1e45).toString();
|
|
24
|
-
const dust = new Dec(
|
|
23
|
+
const dust = new Dec(_rate).div(1e45).toString();
|
|
25
24
|
const duty = new Dec(_duty).toString();
|
|
26
25
|
const futureRate = new Dec(_futureRate).toString();
|
|
27
26
|
const chop = new Dec(_chop).div(1e18).toString();
|
|
@@ -12,7 +12,9 @@ import {
|
|
|
12
12
|
MorphoBluePublicAllocatorItem,
|
|
13
13
|
MorphoBlueRealloactionMarketData,
|
|
14
14
|
} from '../../types';
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
borrowOperations, MORPHO_API_URL, SECONDS_PER_YEAR, WAD,
|
|
17
|
+
} from '../../constants';
|
|
16
18
|
import { MorphoBlueViewContractViem } from '../../contracts';
|
|
17
19
|
import { compareAddresses, LONGER_TIMEOUT, wethToEth } from '../../services/utils';
|
|
18
20
|
import { getViemProvider } from '../../services/viem';
|
|
@@ -52,8 +54,6 @@ export const getMorphoBlueAggregatedPositionData = ({ usedAssets, assetsData, ma
|
|
|
52
54
|
payload.ltv = new Dec(usedAssets[loanToken]?.borrowed || 0).div(oracle).div(usedAssets[collateralToken]?.supplied || 1).toString(); // default to 1 because can't div 0
|
|
53
55
|
payload.ratio = new Dec(usedAssets[collateralToken]?.supplied || 0).mul(oracle).div(usedAssets[loanToken]?.borrowed || 1).mul(100)
|
|
54
56
|
.toString();
|
|
55
|
-
// Borrow limit over debt, so 100 sits on the market's LLTV however low it is (`ratio` is the raw collateral ratio).
|
|
56
|
-
payload.safetyRatio = +payload.borrowedUsd > 0 ? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
57
57
|
|
|
58
58
|
const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
|
|
59
59
|
payload.leveragedType = leveragedType;
|
|
@@ -149,7 +149,6 @@ export const getApyAfterValuesEstimation = async (selectedMarket: MorphoBlueMark
|
|
|
149
149
|
return { borrowRate, supplyRate };
|
|
150
150
|
};
|
|
151
151
|
|
|
152
|
-
const API_URL = 'https://api.morpho.org/graphql';
|
|
153
152
|
// Morpho Blue ACRM (Adaptive Curve IRM) always targets 90% utilization — protocol constant
|
|
154
153
|
const ACRM_TARGET_UTILIZATION = '900000000000000000';
|
|
155
154
|
|
|
@@ -228,7 +227,7 @@ const REWARDS_QUERY = `
|
|
|
228
227
|
*/
|
|
229
228
|
export const getReallocatableLiquidity = async (marketId: string, network: NetworkNumber = NetworkNumber.Eth): Promise<{ reallocatableLiquidity: string, targetBorrowUtilization: string }> => {
|
|
230
229
|
try {
|
|
231
|
-
const response = await fetch(
|
|
230
|
+
const response = await fetch(MORPHO_API_URL, {
|
|
232
231
|
method: 'POST',
|
|
233
232
|
headers: { 'Content-Type': 'application/json' },
|
|
234
233
|
body: JSON.stringify({
|
|
@@ -293,7 +292,7 @@ export const getLiquidityToAllocate = (amountToBorrow: string, totalBorrow: stri
|
|
|
293
292
|
export const getReallocation = async (market: MorphoBlueMarketData, assetsData: MorphoBlueAssetsData, amountToBorrow: string, network: NetworkNumber = NetworkNumber.Eth): Promise<{ vaults: string[], withdrawals: (string | string[])[][][] }> => {
|
|
294
293
|
try {
|
|
295
294
|
const { marketId, loanToken } = market;
|
|
296
|
-
const response = await fetch(
|
|
295
|
+
const response = await fetch(MORPHO_API_URL, {
|
|
297
296
|
method: 'POST',
|
|
298
297
|
headers: { 'Content-Type': 'application/json' },
|
|
299
298
|
body: JSON.stringify({
|
|
@@ -384,7 +383,7 @@ export const getReallocation = async (market: MorphoBlueMarketData, assetsData:
|
|
|
384
383
|
};
|
|
385
384
|
|
|
386
385
|
export const getRewardsForMarket = async (marketId: string, network: NetworkNumber = NetworkNumber.Eth) => {
|
|
387
|
-
const response = await fetch(
|
|
386
|
+
const response = await fetch(MORPHO_API_URL, {
|
|
388
387
|
method: 'POST',
|
|
389
388
|
headers: { 'Content-Type': 'application/json' },
|
|
390
389
|
body: JSON.stringify({
|
|
@@ -102,8 +102,6 @@ export const getMorphoMidnightAggregatedPositionData = ({
|
|
|
102
102
|
payload.ltv = new Dec(payload.suppliedCollateralUsd).eq(0) ? '0' : new Dec(payload.borrowedUsd).div(payload.suppliedCollateralUsd).toString();
|
|
103
103
|
payload.ratio = new Dec(payload.borrowedUsd).eq(0) ? '0' : new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString();
|
|
104
104
|
payload.healthRatio = new Dec(payload.borrowedUsd).eq(0) ? 'Infinity' : new Dec(payload.liquidationLimitUsd).div(payload.borrowedUsd).toDP(4).toString();
|
|
105
|
-
// Borrow limit over debt, so 100 sits on the market's LLTV however low it is (`ratio` is the raw collateral ratio).
|
|
106
|
-
payload.safetyRatio = +payload.borrowedUsd > 0 ? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
107
105
|
|
|
108
106
|
const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
|
|
109
107
|
payload.leveragedType = leveragedType;
|
|
@@ -96,7 +96,6 @@ export const sparkGetAggregatedPositionData = ({
|
|
|
96
96
|
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
97
97
|
payload.ratio = +payload.suppliedUsd ? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
98
98
|
payload.collRatio = +payload.suppliedUsd ? new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
99
|
-
payload.safetyRatio = payload.ratio;
|
|
100
99
|
const { netApy, incentiveUsd, totalInterestUsd } = calculateNetApy({ usedAssets, assetsData });
|
|
101
100
|
payload.netApy = netApy;
|
|
102
101
|
payload.incentiveUsd = incentiveUsd;
|
package/src/liquity/index.ts
CHANGED
|
@@ -89,11 +89,6 @@ export const _getLiquityTroveInfo = async (provider: Client, network: NetworkNum
|
|
|
89
89
|
]);
|
|
90
90
|
|
|
91
91
|
const recoveryMode = troveInfo[6];
|
|
92
|
-
const minCollateralRatio = recoveryMode ? LIQUITY_RECOVERY_MODE_RATIO : LIQUITY_NORMAL_MODE_RATIO;
|
|
93
|
-
const collateral = assetAmountInEth(troveInfo[1].toString());
|
|
94
|
-
const debtInAsset = assetAmountInEth(troveInfo[2].toString());
|
|
95
|
-
const collRatio = +debtInAsset ? new Dec(collateral).mul(assetAmountInEth(assetPrice.toString())).div(debtInAsset).mul(100)
|
|
96
|
-
.toString() : '0';
|
|
97
92
|
|
|
98
93
|
const payload = {
|
|
99
94
|
troveStatus: LIQUITY_TROVE_STATUS_ENUM[+(troveInfo[0].toString())],
|
|
@@ -107,9 +102,7 @@ export const _getLiquityTroveInfo = async (provider: Client, network: NetworkNum
|
|
|
107
102
|
totalETH: totalETH.toString(),
|
|
108
103
|
totalLUSD: totalLUSD.toString(),
|
|
109
104
|
debtInFront: debtInFront.toString(),
|
|
110
|
-
minCollateralRatio,
|
|
111
|
-
// Collateral ratio rebased so 100 sits on the trove's minimum collateral ratio (normalised safety ratio).
|
|
112
|
-
safetyRatio: +minCollateralRatio > 0 ? new Dec(collRatio).div(minCollateralRatio).mul(100).toString() : '0',
|
|
105
|
+
minCollateralRatio: recoveryMode ? LIQUITY_RECOVERY_MODE_RATIO : LIQUITY_NORMAL_MODE_RATIO,
|
|
113
106
|
priceForRecovery: new Dec(recoveryMode ? LIQUITY_RECOVERY_MODE_RATIO : LIQUITY_NORMAL_MODE_RATIO).mul(totalLUSD).div(totalETH).div(100)
|
|
114
107
|
.toString(),
|
|
115
108
|
exposure: getExposure(assetAmountInEth(troveInfo[2].toString()), new Dec(assetAmountInEth(troveInfo[1].toString())).mul(assetPrice).toString()),
|
package/src/maker/index.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
2
|
import {
|
|
3
|
-
assetAmountInEth, bytesToString, getAssetInfo, ilkToAsset,
|
|
3
|
+
assetAmountInEth, bytesToString, getAssetInfo, ilkToAsset,
|
|
4
4
|
} from '@defisaver/tokens';
|
|
5
5
|
import { Client, PublicClient } from 'viem';
|
|
6
6
|
import {
|
|
7
|
-
Blockish, EthAddress, EthereumProvider,
|
|
7
|
+
Blockish, EthAddress, EthereumProvider, 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 {
|
|
13
|
-
CdpData, CdpInfo, CdpType, IlkInfo,
|
|
14
|
-
} from '../types';
|
|
12
|
+
import { CdpData, CdpInfo, CdpType } from '../types';
|
|
15
13
|
import { wethToEth } from '../services/utils';
|
|
16
14
|
import { parseCollateralInfo } from '../helpers/makerHelpers';
|
|
17
15
|
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
@@ -50,7 +48,7 @@ export const _getMakerAccountBalances = async (provider: PublicClient, network:
|
|
|
50
48
|
const [
|
|
51
49
|
par,
|
|
52
50
|
[_, mat],
|
|
53
|
-
[artGlobal, rate, spot, line
|
|
51
|
+
[artGlobal, rate, spot, line],
|
|
54
52
|
[duty],
|
|
55
53
|
futureRate,
|
|
56
54
|
chop,
|
|
@@ -71,7 +69,6 @@ export const _getMakerAccountBalances = async (provider: PublicClient, network:
|
|
|
71
69
|
rate.toString(),
|
|
72
70
|
spot.toString(),
|
|
73
71
|
line.toString(),
|
|
74
|
-
dust.toString(),
|
|
75
72
|
duty.toString(),
|
|
76
73
|
futureRate.toString(),
|
|
77
74
|
chop.toString(),
|
|
@@ -132,71 +129,44 @@ export const getUserCdps = async (
|
|
|
132
129
|
userAddress: EthAddress,
|
|
133
130
|
): Promise<CdpInfo[]> => _getUserCdps(getViemProvider(provider, network), network, userAddress);
|
|
134
131
|
|
|
135
|
-
export const
|
|
132
|
+
export const _getMakerCdpData = async (provider: Client, network: NetworkNumber, cdp: CdpInfo): Promise<CdpData> => {
|
|
136
133
|
const vatContract = McdVatContractViem(provider, network);
|
|
137
134
|
const spotterContract = McdSpotterContractViem(provider, network);
|
|
138
135
|
const dogContract = McdDogContractViem(provider, network);
|
|
139
136
|
const jugContract = McdJugContractViem(provider, network);
|
|
140
137
|
|
|
141
|
-
const par = await spotterContract.read.par();
|
|
142
|
-
|
|
143
|
-
const ilksInfo = await Promise.all(ilkLabels.map(async (ilkLabel) => {
|
|
144
|
-
const ilk = stringToBytes(ilkLabel) as HexString;
|
|
145
|
-
const [
|
|
146
|
-
[_, mat],
|
|
147
|
-
[artGlobal, rate, spot, line, dust],
|
|
148
|
-
[duty],
|
|
149
|
-
futureRate,
|
|
150
|
-
chop,
|
|
151
|
-
] = await Promise.all([
|
|
152
|
-
spotterContract.read.ilks([ilk]),
|
|
153
|
-
vatContract.read.ilks([ilk]),
|
|
154
|
-
jugContract.read.ilks([ilk]),
|
|
155
|
-
jugContract.read.drip([ilk]),
|
|
156
|
-
dogContract.read.chop([ilk]),
|
|
157
|
-
]);
|
|
158
|
-
|
|
159
|
-
return parseCollateralInfo(
|
|
160
|
-
ilk,
|
|
161
|
-
par.toString(),
|
|
162
|
-
mat.toString(),
|
|
163
|
-
artGlobal.toString(),
|
|
164
|
-
rate.toString(),
|
|
165
|
-
spot.toString(),
|
|
166
|
-
line.toString(),
|
|
167
|
-
dust.toString(),
|
|
168
|
-
duty.toString(),
|
|
169
|
-
futureRate.toString(),
|
|
170
|
-
chop.toString(),
|
|
171
|
-
);
|
|
172
|
-
}));
|
|
173
|
-
|
|
174
|
-
return Object.fromEntries(ilksInfo.map((ilkInfo) => [ilkInfo.ilkLabel, ilkInfo]));
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
export const getMakerIlksData = async (
|
|
178
|
-
provider: EthereumProvider,
|
|
179
|
-
network: NetworkNumber,
|
|
180
|
-
ilkLabels: string[],
|
|
181
|
-
): Promise<Record<string, IlkInfo>> => _getMakerIlksData(getViemProvider(provider, network, { batch: { multicall: true } }), network, ilkLabels);
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* @param ilkInfo optional precomputed ilk data (from `_getMakerIlksData`); when provided the per-ilk reads are skipped
|
|
185
|
-
*/
|
|
186
|
-
export const _getMakerCdpData = async (provider: Client, network: NetworkNumber, cdp: CdpInfo, ilkInfo?: IlkInfo): Promise<CdpData> => {
|
|
187
|
-
const vatContract = McdVatContractViem(provider, network);
|
|
188
|
-
|
|
189
138
|
const [
|
|
190
139
|
[ink, art],
|
|
191
140
|
coll,
|
|
192
|
-
|
|
141
|
+
par,
|
|
142
|
+
[_, mat],
|
|
143
|
+
[artGlobal, rate, spot, line],
|
|
144
|
+
[duty],
|
|
145
|
+
futureRate,
|
|
146
|
+
chop,
|
|
193
147
|
] = await Promise.all([
|
|
194
148
|
vatContract.read.urns([cdp.ilk, cdp.urn]),
|
|
195
149
|
vatContract.read.gem([cdp.ilk, cdp.urn]),
|
|
196
|
-
|
|
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]),
|
|
197
156
|
]);
|
|
198
157
|
|
|
199
|
-
const collInfo =
|
|
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
|
+
);
|
|
200
170
|
|
|
201
171
|
const collateral = assetAmountInEth(ink.toString(), `MCD-${cdp.asset}`);
|
|
202
172
|
|
|
@@ -210,8 +180,6 @@ export const _getMakerCdpData = async (provider: Client, network: NetworkNumber,
|
|
|
210
180
|
let ratio = new Dec(ink).times(collInfo.assetPrice).div(debt).times(100)
|
|
211
181
|
.toString();
|
|
212
182
|
if (new Dec(debt).eq(0)) ratio = '0';
|
|
213
|
-
// Collateral ratio rebased so 100 sits on the ilk's liquidation ratio (normalised safety ratio).
|
|
214
|
-
const safetyRatio = +collInfo.liqPercent > 0 ? new Dec(ratio).div(collInfo.liqPercent).mul(100).toString() : '0';
|
|
215
183
|
|
|
216
184
|
const debtTooLow = new Dec(debt).gt(0) && new Dec(assetAmountInEth(debt, 'DAI')).lt(collInfo.minDebt);
|
|
217
185
|
|
|
@@ -233,7 +201,6 @@ export const _getMakerCdpData = async (provider: Client, network: NetworkNumber,
|
|
|
233
201
|
debtAssetMarketPrice: '1',
|
|
234
202
|
liquidationPrice,
|
|
235
203
|
ratio,
|
|
236
|
-
safetyRatio,
|
|
237
204
|
liqRatio: collInfo.liqRatio.toString(),
|
|
238
205
|
liqPercent: parseFloat(collInfo.liqPercent.toString()),
|
|
239
206
|
assetPrice: collInfo.assetPrice,
|
package/src/markets/index.ts
CHANGED
|
@@ -30,5 +30,4 @@ export {
|
|
|
30
30
|
getFTokenAddress,
|
|
31
31
|
getFluidMarketInfoByAddress,
|
|
32
32
|
} from './fluid';
|
|
33
|
-
export { AaveV4Spokes, findAaveV4SpokeByAddress } from './aaveV4';
|
|
34
|
-
export { MakerActiveIlks } from './maker';
|
|
33
|
+
export { AaveV4Spokes, findAaveV4SpokeByAddress } from './aaveV4';
|