@defisaver/positions-sdk 2.1.127-dev → 2.1.127-midnight-1-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/config/contracts.d.ts +249 -0
- package/cjs/config/contracts.js +11 -1
- package/cjs/contracts.d.ts +1510 -0
- package/cjs/contracts.js +3 -2
- package/cjs/helpers/index.d.ts +1 -0
- package/cjs/helpers/index.js +2 -1
- package/cjs/helpers/morphoBlueHelpers/index.js +0 -1
- package/cjs/helpers/morphoMidnightHelpers/index.d.ts +50 -0
- package/cjs/helpers/morphoMidnightHelpers/index.js +170 -0
- package/cjs/index.d.ts +2 -1
- package/cjs/index.js +3 -1
- package/cjs/markets/index.d.ts +1 -0
- package/cjs/markets/index.js +4 -1
- package/cjs/markets/morphoMidnight/index.d.ts +16 -0
- package/cjs/markets/morphoMidnight/index.js +159 -0
- package/cjs/morphoBlue/index.d.ts +6 -8
- package/cjs/morphoBlue/index.js +40 -69
- package/cjs/morphoMidnight/index.d.ts +14 -0
- package/cjs/morphoMidnight/index.js +244 -0
- package/cjs/portfolio/discovery.js +4 -0
- package/cjs/portfolio/index.js +45 -1
- package/cjs/services/viem.d.ts +11 -11
- package/cjs/types/index.d.ts +1 -0
- package/cjs/types/index.js +1 -0
- package/cjs/types/morphoBlue.d.ts +0 -9
- package/cjs/types/morphoMidnight.d.ts +94 -0
- package/cjs/types/morphoMidnight.js +15 -0
- package/cjs/types/portfolio.d.ts +4 -0
- package/esm/config/contracts.d.ts +249 -0
- package/esm/config/contracts.js +9 -0
- package/esm/contracts.d.ts +1510 -0
- package/esm/contracts.js +1 -0
- package/esm/helpers/index.d.ts +1 -0
- package/esm/helpers/index.js +1 -0
- package/esm/helpers/morphoBlueHelpers/index.js +0 -1
- package/esm/helpers/morphoMidnightHelpers/index.d.ts +50 -0
- package/esm/helpers/morphoMidnightHelpers/index.js +159 -0
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -1
- package/esm/markets/index.d.ts +1 -0
- package/esm/markets/index.js +1 -0
- package/esm/markets/morphoMidnight/index.d.ts +16 -0
- package/esm/markets/morphoMidnight/index.js +148 -0
- package/esm/morphoBlue/index.d.ts +6 -8
- package/esm/morphoBlue/index.js +39 -62
- package/esm/morphoMidnight/index.d.ts +14 -0
- package/esm/morphoMidnight/index.js +231 -0
- package/esm/portfolio/discovery.js +5 -1
- package/esm/portfolio/index.js +47 -3
- package/esm/services/viem.d.ts +11 -11
- package/esm/types/index.d.ts +1 -0
- package/esm/types/index.js +1 -0
- package/esm/types/morphoBlue.d.ts +0 -9
- package/esm/types/morphoMidnight.d.ts +94 -0
- package/esm/types/morphoMidnight.js +12 -0
- package/esm/types/portfolio.d.ts +4 -0
- package/package.json +1 -1
- package/src/config/contracts.ts +9 -0
- package/src/contracts.ts +1 -0
- package/src/helpers/index.ts +1 -0
- package/src/helpers/morphoBlueHelpers/index.ts +0 -1
- package/src/helpers/morphoMidnightHelpers/index.ts +219 -0
- package/src/index.ts +2 -0
- package/src/markets/index.ts +1 -0
- package/src/markets/morphoMidnight/index.ts +161 -0
- package/src/morphoBlue/index.ts +44 -101
- package/src/morphoMidnight/index.ts +261 -0
- package/src/portfolio/discovery.ts +6 -0
- package/src/portfolio/index.ts +46 -2
- package/src/types/index.ts +1 -0
- package/src/types/morphoBlue.ts +0 -11
- package/src/types/morphoMidnight.ts +110 -0
- package/src/types/portfolio.ts +4 -0
package/esm/contracts.js
CHANGED
|
@@ -94,6 +94,7 @@ export const getYearnV3VaultContractViem = (client, address) => {
|
|
|
94
94
|
});
|
|
95
95
|
};
|
|
96
96
|
export const MorphoBlueViewContractViem = createViemContractFromConfigFunc('MorphoBlueView');
|
|
97
|
+
export const MorphoMidnightViewContractViem = createViemContractFromConfigFunc('MidnightView');
|
|
97
98
|
export const AaveLoanInfoV2ContractViem = createViemContractFromConfigFunc('AaveLoanInfoV2');
|
|
98
99
|
export const AaveV3ViewContractViem = createViemContractFromConfigFunc('AaveV3View');
|
|
99
100
|
export const AaveIncentiveDataProviderV3ContractViem = createViemContractFromConfigFunc('AaveUiIncentiveDataProviderV3');
|
package/esm/helpers/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * as sparkHelpers from './sparkHelpers';
|
|
|
4
4
|
export * as curveUsdHelpers from './curveUsdHelpers';
|
|
5
5
|
export * as makerHelpers from './makerHelpers';
|
|
6
6
|
export * as morphoBlueHelpers from './morphoBlueHelpers';
|
|
7
|
+
export * as morphoMidnightHelpers from './morphoMidnightHelpers';
|
|
7
8
|
export * as llamaLendHelpers from './llamaLendHelpers';
|
|
8
9
|
export * as liquityV2Helpers from './liquityV2Helpers';
|
|
9
10
|
export * as eulerV2Helpers from './eulerHelpers';
|
package/esm/helpers/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export * as sparkHelpers from './sparkHelpers';
|
|
|
4
4
|
export * as curveUsdHelpers from './curveUsdHelpers';
|
|
5
5
|
export * as makerHelpers from './makerHelpers';
|
|
6
6
|
export * as morphoBlueHelpers from './morphoBlueHelpers';
|
|
7
|
+
export * as morphoMidnightHelpers from './morphoMidnightHelpers';
|
|
7
8
|
export * as llamaLendHelpers from './llamaLendHelpers';
|
|
8
9
|
export * as liquityV2Helpers from './liquityV2Helpers';
|
|
9
10
|
export * as eulerV2Helpers from './eulerHelpers';
|
|
@@ -348,7 +348,6 @@ export const getRewardsForMarket = (marketId_1, ...args_1) => __awaiter(void 0,
|
|
|
348
348
|
query: REWARDS_QUERY,
|
|
349
349
|
variables: { marketId, chainId: network },
|
|
350
350
|
}),
|
|
351
|
-
signal: AbortSignal.timeout(LONGER_TIMEOUT),
|
|
352
351
|
});
|
|
353
352
|
const data = yield response.json();
|
|
354
353
|
const marketData = (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.marketById;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import Dec from 'decimal.js';
|
|
2
|
+
import { MMUsedAssets } from '../../types/common';
|
|
3
|
+
import { MorphoMidnightAggregatedPositionData, MorphoMidnightAssetsData, MorphoMidnightMarketInfo } from '../../types';
|
|
4
|
+
/**
|
|
5
|
+
* Aggregate a Morpho Midnight position. Midnight markets are multi-collateral, so the borrow limit is
|
|
6
|
+
* the sum of each collateral's USD value times its own lltv (Aave-v4 style), rather than a single pair.
|
|
7
|
+
*
|
|
8
|
+
* Note on amounts: `borrowedUsd` is derived from the position's `debt`, which is the face value owed at
|
|
9
|
+
* maturity (principal + fixed interest). Health is therefore measured against the full maturity debt,
|
|
10
|
+
* matching how MidnightView computes `ratio`. Fixed-rate APY is not derived on-chain in MVP, so
|
|
11
|
+
* `netApy` reflects the `'0'` rates in `assetsData` (see the module getter).
|
|
12
|
+
*/
|
|
13
|
+
export declare const getMorphoMidnightAggregatedPositionData: ({ usedAssets, assetsData, marketInfo, }: {
|
|
14
|
+
usedAssets: MMUsedAssets;
|
|
15
|
+
assetsData: MorphoMidnightAssetsData;
|
|
16
|
+
marketInfo: MorphoMidnightMarketInfo;
|
|
17
|
+
}) => MorphoMidnightAggregatedPositionData;
|
|
18
|
+
export interface MorphoMidnightBorrowInfo {
|
|
19
|
+
borrowRate: string;
|
|
20
|
+
debtBase: string;
|
|
21
|
+
debtInterest: string;
|
|
22
|
+
debtTotal: string;
|
|
23
|
+
}
|
|
24
|
+
export interface MorphoMidnightBorrowQuote {
|
|
25
|
+
bestPrice: string;
|
|
26
|
+
worstPrice: string;
|
|
27
|
+
estBorrowRate: string;
|
|
28
|
+
maxRate: string;
|
|
29
|
+
newUnits: string;
|
|
30
|
+
maxUnits: string;
|
|
31
|
+
availableAssets: string;
|
|
32
|
+
availableUnits: string;
|
|
33
|
+
takeableOffers: any[];
|
|
34
|
+
}
|
|
35
|
+
export declare const midnightTimeToMaturityDays: (maturity: number, atSeconds?: number) => number;
|
|
36
|
+
export declare const midnightApyFromPrice: (price: Dec.Value, ttmDays: Dec.Value) => string;
|
|
37
|
+
/**
|
|
38
|
+
* Current borrower rate + debt breakdown from the Midnight transactions API. On-chain we can only read the
|
|
39
|
+
* total debt at maturity (`units`); the base-vs-interest split and the effective borrow rate require the
|
|
40
|
+
* fill history. Per fill the rate is (units / seller_assets)^(365 / ttmAtFill) − 1, weighted by base amount.
|
|
41
|
+
* The caller swallows errors — a missing rate must never block position rendering.
|
|
42
|
+
*/
|
|
43
|
+
export declare const getMorphoMidnightUserBorrowInfo: (account: string, marketId: string, maturity: number, loanTokenSymbol: string) => Promise<MorphoMidnightBorrowInfo>;
|
|
44
|
+
/**
|
|
45
|
+
* Estimate the borrow rate + slippage cap for a prospective borrow by quoting the Midnight order book.
|
|
46
|
+
* `assetsRaw` (and the returned `newUnits`/`maxUnits`) are raw loan-token base units — callers convert to/from
|
|
47
|
+
* human amounts. `maxUnits` (from the slippage-adjusted worst price) is the cap sent on-chain to protect the
|
|
48
|
+
* user if better offers get filled first. Throws if the book can't fill the amount (caller handles).
|
|
49
|
+
*/
|
|
50
|
+
export declare const getMorphoMidnightBorrowQuote: (marketId: string, assetsRaw: string, slippagePercent: Dec.Value, maturity: number) => Promise<MorphoMidnightBorrowQuote>;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import Dec from 'decimal.js';
|
|
11
|
+
import { assetAmountInEth } from '@defisaver/tokens';
|
|
12
|
+
import { calcLeverageLiqPrice, getAssetsTotal, getExposure, isLeveragedPos, } from '../../moneymarket';
|
|
13
|
+
import { calculateNetApy } from '../../staking';
|
|
14
|
+
import { LeverageType, } from '../../types/common';
|
|
15
|
+
import { SECONDS_PER_DAY, WAD } from '../../constants';
|
|
16
|
+
import { LONGER_TIMEOUT } from '../../services/utils';
|
|
17
|
+
/**
|
|
18
|
+
* Aggregate a Morpho Midnight position. Midnight markets are multi-collateral, so the borrow limit is
|
|
19
|
+
* the sum of each collateral's USD value times its own lltv (Aave-v4 style), rather than a single pair.
|
|
20
|
+
*
|
|
21
|
+
* Note on amounts: `borrowedUsd` is derived from the position's `debt`, which is the face value owed at
|
|
22
|
+
* maturity (principal + fixed interest). Health is therefore measured against the full maturity debt,
|
|
23
|
+
* matching how MidnightView computes `ratio`. Fixed-rate APY is not derived on-chain in MVP, so
|
|
24
|
+
* `netApy` reflects the `'0'` rates in `assetsData` (see the module getter).
|
|
25
|
+
*/
|
|
26
|
+
export const getMorphoMidnightAggregatedPositionData = ({ usedAssets, assetsData, marketInfo, }) => {
|
|
27
|
+
var _a;
|
|
28
|
+
const payload = {};
|
|
29
|
+
payload.suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
|
|
30
|
+
payload.suppliedCollateralUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ suppliedUsd }) => suppliedUsd);
|
|
31
|
+
payload.borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
|
|
32
|
+
// borrowLimit = Σ collateralUsd_i * lltv_i (per-collateral lltv carried on assetsData)
|
|
33
|
+
payload.borrowLimitUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd }) => { var _a; return new Dec(suppliedUsd).mul(((_a = assetsData[symbol]) === null || _a === void 0 ? void 0 : _a.lltv) || 0); });
|
|
34
|
+
payload.liquidationLimitUsd = payload.borrowLimitUsd;
|
|
35
|
+
const leftToBorrowUsd = new Dec(payload.borrowLimitUsd).sub(payload.borrowedUsd);
|
|
36
|
+
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
37
|
+
const loanTokenPrice = ((_a = assetsData[marketInfo.loanToken]) === null || _a === void 0 ? void 0 : _a.price) || '0';
|
|
38
|
+
payload.leftToBorrow = new Dec(loanTokenPrice).eq(0) ? '0' : new Dec(payload.leftToBorrowUsd).div(loanTokenPrice).toString();
|
|
39
|
+
const { netApy, incentiveUsd, totalInterestUsd } = calculateNetApy({ usedAssets, assetsData: assetsData });
|
|
40
|
+
payload.netApy = netApy;
|
|
41
|
+
payload.incentiveUsd = incentiveUsd;
|
|
42
|
+
payload.totalInterestUsd = totalInterestUsd;
|
|
43
|
+
payload.ltv = new Dec(payload.suppliedCollateralUsd).eq(0) ? '0' : new Dec(payload.borrowedUsd).div(payload.suppliedCollateralUsd).toString();
|
|
44
|
+
payload.ratio = new Dec(payload.borrowedUsd).eq(0) ? '0' : new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString();
|
|
45
|
+
payload.healthRatio = new Dec(payload.borrowedUsd).eq(0) ? 'Infinity' : new Dec(payload.liquidationLimitUsd).div(payload.borrowedUsd).toDP(4).toString();
|
|
46
|
+
const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
|
|
47
|
+
payload.leveragedType = leveragedType;
|
|
48
|
+
payload.liquidationPrice = '';
|
|
49
|
+
if (leveragedType !== '') {
|
|
50
|
+
payload.leveragedAsset = leveragedAsset;
|
|
51
|
+
let assetPrice = assetsData[leveragedAsset].price;
|
|
52
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
53
|
+
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
54
|
+
const borrowedAssetPrice = assetsData[borrowedAsset.symbol].price;
|
|
55
|
+
const leveragedAssetPrice = assetsData[leveragedAsset].price;
|
|
56
|
+
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
57
|
+
if (isReverse) {
|
|
58
|
+
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
59
|
+
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
60
|
+
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
64
|
+
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
68
|
+
}
|
|
69
|
+
payload.minCollRatio = new Dec(payload.borrowLimitUsd).eq(0) ? '0' : new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
70
|
+
payload.collLiquidationRatio = new Dec(payload.liquidationLimitUsd).eq(0) ? '0' : new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
71
|
+
payload.exposure = getExposure(payload.borrowedUsd, payload.suppliedUsd);
|
|
72
|
+
return payload;
|
|
73
|
+
};
|
|
74
|
+
// ── Off-chain order-book rate helpers ──────────────────────────────────────────────────────────────
|
|
75
|
+
// notion: https://app.notion.com/p/defisaver/Estimate-borrow-rate-and-slippage-before-execution-3a70be682adc80c783c8c11fdb761dd2
|
|
76
|
+
// the borrow rate is not exposed on-chain (MidnightView only stores total debt at maturity in `units`).
|
|
77
|
+
// derive the rate + interest from Morpho's public keyless Midnight API
|
|
78
|
+
// Quote prices are WAD-scaled
|
|
79
|
+
// loan-per-unit ratios (< 1 for a discounted fixed-term borrow); annualizing them yields the borrow APY.
|
|
80
|
+
const MIDNIGHT_API_BASE = 'https://api.morpho.org/v0/midnight';
|
|
81
|
+
const nowInSeconds = () => Math.floor(Date.now() / 1000);
|
|
82
|
+
// Days remaining until maturity, optionally measured at a past timestamp (for historical fills).
|
|
83
|
+
export const midnightTimeToMaturityDays = (maturity, atSeconds = nowInSeconds()) => new Dec(maturity).sub(atSeconds).div(SECONDS_PER_DAY).toNumber();
|
|
84
|
+
// Annualize a fixed-term discount price into an APY percent: (1 / price)^(365 / ttmDays) − 1.
|
|
85
|
+
// `price` is loan-per-unit (assets received / units owed), so 1/price ≥ 1.
|
|
86
|
+
export const midnightApyFromPrice = (price, ttmDays) => {
|
|
87
|
+
const p = new Dec(price);
|
|
88
|
+
const ttm = new Dec(ttmDays);
|
|
89
|
+
if (p.lte(0) || ttm.lte(0))
|
|
90
|
+
return '0';
|
|
91
|
+
return new Dec(1).div(p).pow(new Dec(365).div(ttm)).sub(1)
|
|
92
|
+
.mul(100)
|
|
93
|
+
.toString();
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Current borrower rate + debt breakdown from the Midnight transactions API. On-chain we can only read the
|
|
97
|
+
* total debt at maturity (`units`); the base-vs-interest split and the effective borrow rate require the
|
|
98
|
+
* fill history. Per fill the rate is (units / seller_assets)^(365 / ttmAtFill) − 1, weighted by base amount.
|
|
99
|
+
* The caller swallows errors — a missing rate must never block position rendering.
|
|
100
|
+
*/
|
|
101
|
+
export const getMorphoMidnightUserBorrowInfo = (account, marketId, maturity, loanTokenSymbol) => __awaiter(void 0, void 0, void 0, function* () {
|
|
102
|
+
const res = yield fetch(`${MIDNIGHT_API_BASE}/users/${account}/transactions`, { signal: AbortSignal.timeout(LONGER_TIMEOUT) });
|
|
103
|
+
const json = yield res.json();
|
|
104
|
+
const borrows = ((json === null || json === void 0 ? void 0 : json.data) || []).filter((t) => { var _a; return t.event_type === 'borrow' && ((_a = t.market_id) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === marketId.toLowerCase(); });
|
|
105
|
+
let sumSeller = new Dec(0); // Σ seller_assets (base), raw
|
|
106
|
+
let sumUnits = new Dec(0); // Σ units (debt at maturity), raw
|
|
107
|
+
let weightedApy = new Dec(0); // Σ seller_assets × APYᵢ
|
|
108
|
+
borrows.forEach((t) => {
|
|
109
|
+
var _a, _b;
|
|
110
|
+
const sellerAssets = new Dec(((_a = t.data) === null || _a === void 0 ? void 0 : _a.seller_assets) || 0);
|
|
111
|
+
const units = new Dec(((_b = t.data) === null || _b === void 0 ? void 0 : _b.units) || 0);
|
|
112
|
+
if (sellerAssets.lte(0) || units.lte(0))
|
|
113
|
+
return;
|
|
114
|
+
const ttmDays = midnightTimeToMaturityDays(maturity, t.created_at);
|
|
115
|
+
const apy = midnightApyFromPrice(sellerAssets.div(units), ttmDays); // price = seller_assets / units
|
|
116
|
+
sumSeller = sumSeller.add(sellerAssets);
|
|
117
|
+
sumUnits = sumUnits.add(units);
|
|
118
|
+
weightedApy = weightedApy.add(sellerAssets.mul(apy));
|
|
119
|
+
});
|
|
120
|
+
const borrowRate = sumSeller.lte(0) ? '0' : weightedApy.div(sumSeller).toString();
|
|
121
|
+
const debtBase = assetAmountInEth(sumSeller.toFixed(0), loanTokenSymbol);
|
|
122
|
+
const debtTotal = assetAmountInEth(sumUnits.toFixed(0), loanTokenSymbol);
|
|
123
|
+
const debtInterest = Dec.max(new Dec(debtTotal).sub(debtBase), 0).toString();
|
|
124
|
+
return {
|
|
125
|
+
borrowRate, debtBase, debtInterest, debtTotal,
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
/**
|
|
129
|
+
* Estimate the borrow rate + slippage cap for a prospective borrow by quoting the Midnight order book.
|
|
130
|
+
* `assetsRaw` (and the returned `newUnits`/`maxUnits`) are raw loan-token base units — callers convert to/from
|
|
131
|
+
* human amounts. `maxUnits` (from the slippage-adjusted worst price) is the cap sent on-chain to protect the
|
|
132
|
+
* user if better offers get filled first. Throws if the book can't fill the amount (caller handles).
|
|
133
|
+
*/
|
|
134
|
+
export const getMorphoMidnightBorrowQuote = (marketId, assetsRaw, slippagePercent, maturity) => __awaiter(void 0, void 0, void 0, function* () {
|
|
135
|
+
const url = `${MIDNIGHT_API_BASE}/books/${marketId}/bids/quote?assets=${assetsRaw}&slippage=${slippagePercent}`;
|
|
136
|
+
const res = yield fetch(url, { signal: AbortSignal.timeout(LONGER_TIMEOUT) });
|
|
137
|
+
const json = yield res.json();
|
|
138
|
+
const d = json === null || json === void 0 ? void 0 : json.data;
|
|
139
|
+
if (!(d === null || d === void 0 ? void 0 : d.average_best_price))
|
|
140
|
+
throw new Error('Morpho Midnight quote unavailable');
|
|
141
|
+
const bestPrice = new Dec(d.average_best_price).div(WAD).toString();
|
|
142
|
+
const worstPrice = new Dec(d.average_worst_price).div(WAD).toString();
|
|
143
|
+
const ttmDays = midnightTimeToMaturityDays(maturity);
|
|
144
|
+
const estBorrowRate = midnightApyFromPrice(bestPrice, ttmDays);
|
|
145
|
+
const maxRate = new Dec(estBorrowRate).add(slippagePercent).toString();
|
|
146
|
+
const newUnits = new Dec(bestPrice).lte(0) ? '0' : new Dec(assetsRaw).div(bestPrice).toFixed(0);
|
|
147
|
+
const maxUnits = new Dec(worstPrice).lte(0) ? '0' : new Dec(assetsRaw).div(worstPrice).toFixed(0);
|
|
148
|
+
return {
|
|
149
|
+
bestPrice,
|
|
150
|
+
worstPrice,
|
|
151
|
+
estBorrowRate,
|
|
152
|
+
maxRate,
|
|
153
|
+
newUnits,
|
|
154
|
+
maxUnits,
|
|
155
|
+
availableAssets: d.available_assets,
|
|
156
|
+
availableUnits: d.available_units,
|
|
157
|
+
takeableOffers: d.takeable_offers || [],
|
|
158
|
+
};
|
|
159
|
+
});
|
package/esm/index.d.ts
CHANGED
|
@@ -16,10 +16,11 @@ import * as markets from './markets';
|
|
|
16
16
|
import * as helpers from './helpers';
|
|
17
17
|
import * as exchange from './exchange';
|
|
18
18
|
import * as morphoBlue from './morphoBlue';
|
|
19
|
+
import * as morphoMidnight from './morphoMidnight';
|
|
19
20
|
import * as llamaLend from './llamaLend';
|
|
20
21
|
import * as eulerV2 from './eulerV2';
|
|
21
22
|
import * as portfolio from './portfolio';
|
|
22
23
|
import * as claiming from './claiming';
|
|
23
24
|
import * as savings from './savings';
|
|
24
25
|
export * from './types';
|
|
25
|
-
export { aaveV2, aaveV3, aaveV4, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, fluid, portfolio, claiming, savings, };
|
|
26
|
+
export { aaveV2, aaveV3, aaveV4, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, morphoMidnight, llamaLend, eulerV2, fluid, portfolio, claiming, savings, };
|
package/esm/index.js
CHANGED
|
@@ -16,10 +16,11 @@ import * as markets from './markets';
|
|
|
16
16
|
import * as helpers from './helpers';
|
|
17
17
|
import * as exchange from './exchange';
|
|
18
18
|
import * as morphoBlue from './morphoBlue';
|
|
19
|
+
import * as morphoMidnight from './morphoMidnight';
|
|
19
20
|
import * as llamaLend from './llamaLend';
|
|
20
21
|
import * as eulerV2 from './eulerV2';
|
|
21
22
|
import * as portfolio from './portfolio';
|
|
22
23
|
import * as claiming from './claiming';
|
|
23
24
|
import * as savings from './savings';
|
|
24
25
|
export * from './types';
|
|
25
|
-
export { aaveV2, aaveV3, aaveV4, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, fluid, portfolio, claiming, savings, };
|
|
26
|
+
export { aaveV2, aaveV3, aaveV4, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, morphoMidnight, llamaLend, eulerV2, fluid, portfolio, claiming, savings, };
|
package/esm/markets/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { CompoundMarkets, compoundV2CollateralAssets, v3ETHCollAssets, v3USDbCCo
|
|
|
3
3
|
export { SparkMarkets } from './spark';
|
|
4
4
|
export { CrvUsdMarkets } from './curveUsd';
|
|
5
5
|
export { MorphoBlueMarkets, findMorphoBlueMarket } from './morphoBlue';
|
|
6
|
+
export { MorphoMidnightMarkets, findMorphoMidnightMarket } from './morphoMidnight';
|
|
6
7
|
export { LlamaLendMarkets } from './llamaLend';
|
|
7
8
|
export { LiquityV2Markets, findLiquityV2MarketByAddress } from './liquityV2';
|
|
8
9
|
export { EulerV2Markets } from './euler';
|
package/esm/markets/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { CompoundMarkets, compoundV2CollateralAssets, v3ETHCollAssets, v3USDbCCo
|
|
|
3
3
|
export { SparkMarkets } from './spark';
|
|
4
4
|
export { CrvUsdMarkets } from './curveUsd';
|
|
5
5
|
export { MorphoBlueMarkets, findMorphoBlueMarket } from './morphoBlue';
|
|
6
|
+
export { MorphoMidnightMarkets, findMorphoMidnightMarket } from './morphoMidnight';
|
|
6
7
|
export { LlamaLendMarkets } from './llamaLend';
|
|
7
8
|
export { LiquityV2Markets, findLiquityV2MarketByAddress } from './liquityV2';
|
|
8
9
|
export { EulerV2Markets } from './euler';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { MorphoMidnightMarketData, NetworkNumber } from '../../types';
|
|
2
|
+
export declare const MORPHO_MIDNIGHT_CBBTC_USDC_860_20260731: (networkId?: NetworkNumber) => MorphoMidnightMarketData;
|
|
3
|
+
export declare const MORPHO_MIDNIGHT_CBBTC_USDC_860_20260828: (networkId?: NetworkNumber) => MorphoMidnightMarketData;
|
|
4
|
+
export declare const MORPHO_MIDNIGHT_CBBTC_USDC_860_20260925: (networkId?: NetworkNumber) => MorphoMidnightMarketData;
|
|
5
|
+
export declare const MORPHO_MIDNIGHT_CBBTC_USDC_860_20261030: (networkId?: NetworkNumber) => MorphoMidnightMarketData;
|
|
6
|
+
export declare const MORPHO_MIDNIGHT_CBBTC_USDC_860_20261127: (networkId?: NetworkNumber) => MorphoMidnightMarketData;
|
|
7
|
+
export declare const MORPHO_MIDNIGHT_CBBTC_USDC_860_20261225: (networkId?: NetworkNumber) => MorphoMidnightMarketData;
|
|
8
|
+
export declare const MorphoMidnightMarkets: (networkId: NetworkNumber) => {
|
|
9
|
+
readonly morphomidnightcbbtcusdc_860_20260731_base: MorphoMidnightMarketData;
|
|
10
|
+
readonly morphomidnightcbbtcusdc_860_20260828_base: MorphoMidnightMarketData;
|
|
11
|
+
readonly morphomidnightcbbtcusdc_860_20260925_base: MorphoMidnightMarketData;
|
|
12
|
+
readonly morphomidnightcbbtcusdc_860_20261030_base: MorphoMidnightMarketData;
|
|
13
|
+
readonly morphomidnightcbbtcusdc_860_20261127_base: MorphoMidnightMarketData;
|
|
14
|
+
readonly morphomidnightcbbtcusdc_860_20261225_base: MorphoMidnightMarketData;
|
|
15
|
+
};
|
|
16
|
+
export declare const findMorphoMidnightMarket: (marketId: string, network?: NetworkNumber) => MorphoMidnightMarketData | undefined;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { MorphoMidnightVersions, NetworkNumber } from '../../types';
|
|
2
|
+
// Morpho Midnight core contract on Base (same for every market).
|
|
3
|
+
const MIDNIGHT_BASE = '0xAdedD8ab6dE832766Fedf0FaC4992E5C4D3EA18A';
|
|
4
|
+
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|
5
|
+
// Curated Morpho Midnight markets. Each market is fixed-term: it is uniquely identified on-chain by
|
|
6
|
+
// `marketId` (bytes32), derived from the static struct below via MidnightView.toId. Because markets
|
|
7
|
+
// churn as maturities roll, this list is hand-maintained for the pairs/maturities the app supports.
|
|
8
|
+
// Sourced from the official listing at https://markets.morpho.org/fixed/base (see its sitemap.xml) —
|
|
9
|
+
// currently a single USDC/cbBTC pair offered on a monthly maturity ladder; new maturities are added
|
|
10
|
+
// there progressively. Every `marketId` here is verified against MidnightView.toId(marketStruct) in
|
|
11
|
+
// tests/morphoMidnight.ts.
|
|
12
|
+
// BASE — USDC/cbBTC, 86% LLTV, monthly maturity ladder
|
|
13
|
+
export const MORPHO_MIDNIGHT_CBBTC_USDC_860_20260731 = (networkId = NetworkNumber.Base) => ({
|
|
14
|
+
chainIds: [NetworkNumber.Base],
|
|
15
|
+
label: 'Morpho Midnight cbBTC/USDC',
|
|
16
|
+
shortLabel: 'cbBTC/USDC',
|
|
17
|
+
url: 'cbbtc-usdc-20260731',
|
|
18
|
+
value: MorphoMidnightVersions.MorphoMidnightCbBTCUSDC_860_20260731_Base,
|
|
19
|
+
midnight: MIDNIGHT_BASE,
|
|
20
|
+
loanToken: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC
|
|
21
|
+
collaterals: [{
|
|
22
|
+
token: '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf', // cbBTC
|
|
23
|
+
lltv: 0.86,
|
|
24
|
+
liquidationCursor: '300000000000000000',
|
|
25
|
+
oracle: '0x663BECd10daE6C4A3Dcd89F1d76c1174199639B9',
|
|
26
|
+
}],
|
|
27
|
+
maturity: 1785510000, // 2026-07-31T15:00:00Z
|
|
28
|
+
rcfThreshold: '3000000000',
|
|
29
|
+
enterGate: ZERO_ADDRESS,
|
|
30
|
+
liquidatorGate: ZERO_ADDRESS,
|
|
31
|
+
marketId: '0x168e31250e0008b50d2255a5ab85e0265acd6c12e4f9a1336134b36a65a47937',
|
|
32
|
+
protocolName: 'morpho-midnight',
|
|
33
|
+
});
|
|
34
|
+
export const MORPHO_MIDNIGHT_CBBTC_USDC_860_20260828 = (networkId = NetworkNumber.Base) => ({
|
|
35
|
+
chainIds: [NetworkNumber.Base],
|
|
36
|
+
label: 'Morpho Midnight cbBTC/USDC',
|
|
37
|
+
shortLabel: 'cbBTC/USDC',
|
|
38
|
+
url: 'cbbtc-usdc-20260828',
|
|
39
|
+
value: MorphoMidnightVersions.MorphoMidnightCbBTCUSDC_860_20260828_Base,
|
|
40
|
+
midnight: MIDNIGHT_BASE,
|
|
41
|
+
loanToken: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC
|
|
42
|
+
collaterals: [{
|
|
43
|
+
token: '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf', // cbBTC
|
|
44
|
+
lltv: 0.86,
|
|
45
|
+
liquidationCursor: '300000000000000000',
|
|
46
|
+
oracle: '0x663BECd10daE6C4A3Dcd89F1d76c1174199639B9',
|
|
47
|
+
}],
|
|
48
|
+
maturity: 1787929200, // 2026-08-28T15:00:00Z
|
|
49
|
+
rcfThreshold: '3000000000',
|
|
50
|
+
enterGate: ZERO_ADDRESS,
|
|
51
|
+
liquidatorGate: ZERO_ADDRESS,
|
|
52
|
+
marketId: '0x05959752fdeff325962b9d263edb421efc6e2186a49360dba6c32e86ebf6c84c',
|
|
53
|
+
protocolName: 'morpho-midnight',
|
|
54
|
+
});
|
|
55
|
+
export const MORPHO_MIDNIGHT_CBBTC_USDC_860_20260925 = (networkId = NetworkNumber.Base) => ({
|
|
56
|
+
chainIds: [NetworkNumber.Base],
|
|
57
|
+
label: 'Morpho Midnight cbBTC/USDC',
|
|
58
|
+
shortLabel: 'cbBTC/USDC',
|
|
59
|
+
url: 'cbbtc-usdc-20260925',
|
|
60
|
+
value: MorphoMidnightVersions.MorphoMidnightCbBTCUSDC_860_20260925_Base,
|
|
61
|
+
midnight: MIDNIGHT_BASE,
|
|
62
|
+
loanToken: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC
|
|
63
|
+
collaterals: [{
|
|
64
|
+
token: '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf', // cbBTC
|
|
65
|
+
lltv: 0.86,
|
|
66
|
+
liquidationCursor: '300000000000000000',
|
|
67
|
+
oracle: '0x663BECd10daE6C4A3Dcd89F1d76c1174199639B9',
|
|
68
|
+
}],
|
|
69
|
+
maturity: 1790348400, // 2026-09-25T15:00:00Z
|
|
70
|
+
rcfThreshold: '3000000000',
|
|
71
|
+
enterGate: ZERO_ADDRESS,
|
|
72
|
+
liquidatorGate: ZERO_ADDRESS,
|
|
73
|
+
marketId: '0x549cd072daf99328554f3a6d2d4d6f4a07f1c59369e891e6391946f9cf75f221',
|
|
74
|
+
protocolName: 'morpho-midnight',
|
|
75
|
+
});
|
|
76
|
+
export const MORPHO_MIDNIGHT_CBBTC_USDC_860_20261030 = (networkId = NetworkNumber.Base) => ({
|
|
77
|
+
chainIds: [NetworkNumber.Base],
|
|
78
|
+
label: 'Morpho Midnight cbBTC/USDC',
|
|
79
|
+
shortLabel: 'cbBTC/USDC',
|
|
80
|
+
url: 'cbbtc-usdc-20261030',
|
|
81
|
+
value: MorphoMidnightVersions.MorphoMidnightCbBTCUSDC_860_20261030_Base,
|
|
82
|
+
midnight: MIDNIGHT_BASE,
|
|
83
|
+
loanToken: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC
|
|
84
|
+
collaterals: [{
|
|
85
|
+
token: '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf', // cbBTC
|
|
86
|
+
lltv: 0.86,
|
|
87
|
+
liquidationCursor: '300000000000000000',
|
|
88
|
+
oracle: '0x663BECd10daE6C4A3Dcd89F1d76c1174199639B9',
|
|
89
|
+
}],
|
|
90
|
+
maturity: 1793372400, // 2026-10-30T15:00:00Z
|
|
91
|
+
rcfThreshold: '3000000000',
|
|
92
|
+
enterGate: ZERO_ADDRESS,
|
|
93
|
+
liquidatorGate: ZERO_ADDRESS,
|
|
94
|
+
marketId: '0x43d6120738c57b2bc5835901f8250fdf7fc8054efbb006c6ccba61ec898e5ed9',
|
|
95
|
+
protocolName: 'morpho-midnight',
|
|
96
|
+
});
|
|
97
|
+
export const MORPHO_MIDNIGHT_CBBTC_USDC_860_20261127 = (networkId = NetworkNumber.Base) => ({
|
|
98
|
+
chainIds: [NetworkNumber.Base],
|
|
99
|
+
label: 'Morpho Midnight cbBTC/USDC',
|
|
100
|
+
shortLabel: 'cbBTC/USDC',
|
|
101
|
+
url: 'cbbtc-usdc-20261127',
|
|
102
|
+
value: MorphoMidnightVersions.MorphoMidnightCbBTCUSDC_860_20261127_Base,
|
|
103
|
+
midnight: MIDNIGHT_BASE,
|
|
104
|
+
loanToken: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC
|
|
105
|
+
collaterals: [{
|
|
106
|
+
token: '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf', // cbBTC
|
|
107
|
+
lltv: 0.86,
|
|
108
|
+
liquidationCursor: '300000000000000000',
|
|
109
|
+
oracle: '0x663BECd10daE6C4A3Dcd89F1d76c1174199639B9',
|
|
110
|
+
}],
|
|
111
|
+
maturity: 1795791600, // 2026-11-27T15:00:00Z
|
|
112
|
+
rcfThreshold: '3000000000',
|
|
113
|
+
enterGate: ZERO_ADDRESS,
|
|
114
|
+
liquidatorGate: ZERO_ADDRESS,
|
|
115
|
+
marketId: '0xe1878eec035b601f301484e63a49a428f8e008e2bf57a2fd88a3fc3a4c1b1acd',
|
|
116
|
+
protocolName: 'morpho-midnight',
|
|
117
|
+
});
|
|
118
|
+
export const MORPHO_MIDNIGHT_CBBTC_USDC_860_20261225 = (networkId = NetworkNumber.Base) => ({
|
|
119
|
+
chainIds: [NetworkNumber.Base],
|
|
120
|
+
label: 'Morpho Midnight cbBTC/USDC',
|
|
121
|
+
shortLabel: 'cbBTC/USDC',
|
|
122
|
+
url: 'cbbtc-usdc-20261225',
|
|
123
|
+
value: MorphoMidnightVersions.MorphoMidnightCbBTCUSDC_860_20261225_Base,
|
|
124
|
+
midnight: MIDNIGHT_BASE,
|
|
125
|
+
loanToken: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC
|
|
126
|
+
collaterals: [{
|
|
127
|
+
token: '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf', // cbBTC
|
|
128
|
+
lltv: 0.86,
|
|
129
|
+
liquidationCursor: '300000000000000000',
|
|
130
|
+
oracle: '0x663BECd10daE6C4A3Dcd89F1d76c1174199639B9',
|
|
131
|
+
}],
|
|
132
|
+
maturity: 1798210800, // 2026-12-25T15:00:00Z
|
|
133
|
+
rcfThreshold: '3000000000',
|
|
134
|
+
enterGate: ZERO_ADDRESS,
|
|
135
|
+
liquidatorGate: ZERO_ADDRESS,
|
|
136
|
+
marketId: '0x9593c3a6dba45b6106af8dc8b45ba8c505d90d3d68a3d33f7c278dd921b637da',
|
|
137
|
+
protocolName: 'morpho-midnight',
|
|
138
|
+
});
|
|
139
|
+
export const MorphoMidnightMarkets = (networkId) => ({
|
|
140
|
+
// BASE
|
|
141
|
+
[MorphoMidnightVersions.MorphoMidnightCbBTCUSDC_860_20260731_Base]: MORPHO_MIDNIGHT_CBBTC_USDC_860_20260731(networkId),
|
|
142
|
+
[MorphoMidnightVersions.MorphoMidnightCbBTCUSDC_860_20260828_Base]: MORPHO_MIDNIGHT_CBBTC_USDC_860_20260828(networkId),
|
|
143
|
+
[MorphoMidnightVersions.MorphoMidnightCbBTCUSDC_860_20260925_Base]: MORPHO_MIDNIGHT_CBBTC_USDC_860_20260925(networkId),
|
|
144
|
+
[MorphoMidnightVersions.MorphoMidnightCbBTCUSDC_860_20261030_Base]: MORPHO_MIDNIGHT_CBBTC_USDC_860_20261030(networkId),
|
|
145
|
+
[MorphoMidnightVersions.MorphoMidnightCbBTCUSDC_860_20261127_Base]: MORPHO_MIDNIGHT_CBBTC_USDC_860_20261127(networkId),
|
|
146
|
+
[MorphoMidnightVersions.MorphoMidnightCbBTCUSDC_860_20261225_Base]: MORPHO_MIDNIGHT_CBBTC_USDC_860_20261225(networkId),
|
|
147
|
+
});
|
|
148
|
+
export const findMorphoMidnightMarket = (marketId, network = NetworkNumber.Base) => Object.values(MorphoMidnightMarkets(network)).find((market) => market.marketId.toLowerCase() === marketId.toLowerCase());
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
2
|
import { Blockish, EthAddress, EthereumProvider, NetworkNumber, PositionBalances } from '../types/common';
|
|
3
|
-
import {
|
|
4
|
-
export declare const addMorphoBlueRewardsToMarketInfo: (marketInfo: MorphoBlueMarketInfo, rewards: MorphoBlueMarketRewards) => MorphoBlueMarketInfo;
|
|
3
|
+
import { MorphoBlueMarketData, MorphoBlueMarketInfo, MorphoBluePositionData } from '../types';
|
|
5
4
|
export declare function _getMorphoBlueMarketData(provider: Client, network: NetworkNumber, selectedMarket: MorphoBlueMarketData): Promise<MorphoBlueMarketInfo>;
|
|
6
|
-
export declare function _getMorphoBluePortfolioMarketData(provider: Client, network: NetworkNumber, selectedMarket: MorphoBlueMarketData): Promise<MorphoBlueMarketInfo>;
|
|
7
5
|
export declare function getMorphoBlueMarketData(provider: EthereumProvider, network: NetworkNumber, selectedMarket: MorphoBlueMarketData): Promise<MorphoBlueMarketInfo>;
|
|
8
|
-
export declare function getMorphoBluePortfolioMarketData(provider: EthereumProvider, network: NetworkNumber, selectedMarket: MorphoBlueMarketData): Promise<MorphoBlueMarketInfo>;
|
|
9
|
-
export declare const getMorphoBluePositionDataWithMarketInfo: (data: MorphoBluePositionData, marketInfo: MorphoBlueMarketInfo) => MorphoBluePositionData;
|
|
10
|
-
export declare const getMorphoEarnDataWithMarketInfo: (data: MorphoBlueEarnData, marketInfo: MorphoBlueMarketInfo) => MorphoBlueEarnData;
|
|
11
|
-
export declare function getMorphoBlueMarketRewards(network: NetworkNumber, selectedMarket: MorphoBlueMarketData): Promise<MorphoBlueMarketRewards>;
|
|
12
6
|
export declare const _getMorphoBlueAccountBalances: (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, selectedMarket: MorphoBlueMarketData) => Promise<PositionBalances>;
|
|
13
7
|
export declare const getMorphoBlueAccountBalances: (provider: EthereumProvider, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, selectedMarket: MorphoBlueMarketData) => Promise<PositionBalances>;
|
|
14
8
|
export declare function _getMorphoBlueAccountData(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<MorphoBluePositionData>;
|
|
15
9
|
export declare function getMorphoBlueAccountData(provider: EthereumProvider, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<MorphoBluePositionData>;
|
|
16
|
-
export declare function getMorphoEarn(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<
|
|
10
|
+
export declare function getMorphoEarn(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<{
|
|
11
|
+
apy: string;
|
|
12
|
+
amount: string;
|
|
13
|
+
amountUsd: string;
|
|
14
|
+
}>;
|
package/esm/morphoBlue/index.js
CHANGED
|
@@ -18,20 +18,7 @@ import { getBorrowRate, getMorphoBlueAggregatedPositionData, getRewardsForMarket
|
|
|
18
18
|
import { getChainlinkAssetAddress } from '../services/priceService';
|
|
19
19
|
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
20
20
|
const HARDCODED_USD_STABLE_PRICE = '100000000'; // $1 with 8 decimals
|
|
21
|
-
|
|
22
|
-
token: 'MORPHO',
|
|
23
|
-
apy,
|
|
24
|
-
incentiveKind: IncentiveKind.Reward,
|
|
25
|
-
description: 'Eligible for protocol-level MORPHO incentives.',
|
|
26
|
-
}];
|
|
27
|
-
export const addMorphoBlueRewardsToMarketInfo = (marketInfo, rewards) => (Object.assign(Object.assign({}, marketInfo), { assetsData: Object.assign(Object.assign({}, marketInfo.assetsData), { [marketInfo.loanToken]: Object.assign(Object.assign({}, marketInfo.assetsData[marketInfo.loanToken]), { supplyIncentives: [
|
|
28
|
-
...marketInfo.assetsData[marketInfo.loanToken].supplyIncentives.filter(({ token }) => token !== 'MORPHO'),
|
|
29
|
-
...getMorphoRewardIncentives(rewards.supplyApy),
|
|
30
|
-
], borrowIncentives: [
|
|
31
|
-
...marketInfo.assetsData[marketInfo.loanToken].borrowIncentives.filter(({ token }) => token !== 'MORPHO'),
|
|
32
|
-
...getMorphoRewardIncentives(rewards.borrowApy),
|
|
33
|
-
] }) }) }));
|
|
34
|
-
function getMorphoBlueMarketDataInternal(provider, network, selectedMarket) {
|
|
21
|
+
export function _getMorphoBlueMarketData(provider, network, selectedMarket) {
|
|
35
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
23
|
const { loanToken, collateralToken, oracle, irm, lltv, oracleType, } = selectedMarket;
|
|
37
24
|
const lltvInWei = new Dec(lltv).mul(WAD).toString();
|
|
@@ -63,6 +50,16 @@ function getMorphoBlueMarketDataInternal(provider, network, selectedMarket) {
|
|
|
63
50
|
marketInfo = _marketInfo;
|
|
64
51
|
loanTokenPrice = loanTokenPriceRound[1].toString();
|
|
65
52
|
}
|
|
53
|
+
let morphoSupplyApy = '0';
|
|
54
|
+
let morphoBorrowApy = '0';
|
|
55
|
+
try {
|
|
56
|
+
const { supplyApy: _morphoSupplyApy, borrowApy: _morphoBorrowApy } = yield getRewardsForMarket(selectedMarket.marketId, network);
|
|
57
|
+
morphoSupplyApy = _morphoSupplyApy;
|
|
58
|
+
morphoBorrowApy = _morphoBorrowApy;
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
console.error(e);
|
|
62
|
+
}
|
|
66
63
|
const supplyRate = getSupplyRate(marketInfo.totalSupplyAssets.toString(), marketInfo.totalBorrowAssets.toString(), marketInfo.borrowRate.toString(), marketInfo.fee.toString());
|
|
67
64
|
const compoundedBorrowRate = getBorrowRate(marketInfo.borrowRate.toString(), marketInfo.totalBorrowShares.toString());
|
|
68
65
|
const utillization = new Dec(marketInfo.totalBorrowAssets.toString()).div(marketInfo.totalSupplyAssets.toString()).mul(100).toString();
|
|
@@ -81,8 +78,18 @@ function getMorphoBlueMarketDataInternal(provider, network, selectedMarket) {
|
|
|
81
78
|
totalBorrow: new Dec(marketInfo.totalBorrowAssets.toString()).div(scale).toString(),
|
|
82
79
|
canBeSupplied: true,
|
|
83
80
|
canBeBorrowed: true,
|
|
84
|
-
supplyIncentives: [
|
|
85
|
-
|
|
81
|
+
supplyIncentives: [{
|
|
82
|
+
token: 'MORPHO',
|
|
83
|
+
apy: morphoSupplyApy,
|
|
84
|
+
incentiveKind: IncentiveKind.Reward,
|
|
85
|
+
description: 'Eligible for protocol-level MORPHO incentives.',
|
|
86
|
+
}],
|
|
87
|
+
borrowIncentives: [{
|
|
88
|
+
token: 'MORPHO',
|
|
89
|
+
apy: morphoBorrowApy,
|
|
90
|
+
incentiveKind: IncentiveKind.Reward,
|
|
91
|
+
description: 'Eligible for protocol-level MORPHO incentives.',
|
|
92
|
+
}],
|
|
86
93
|
};
|
|
87
94
|
assetsData[wethToEth(collateralTokenInfo.symbol)] = {
|
|
88
95
|
symbol: wethToEth(collateralTokenInfo.symbol),
|
|
@@ -117,54 +124,11 @@ function getMorphoBlueMarketDataInternal(provider, network, selectedMarket) {
|
|
|
117
124
|
};
|
|
118
125
|
});
|
|
119
126
|
}
|
|
120
|
-
export function _getMorphoBlueMarketData(provider, network, selectedMarket) {
|
|
121
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
-
const marketInfo = yield getMorphoBlueMarketDataInternal(provider, network, selectedMarket);
|
|
123
|
-
try {
|
|
124
|
-
const rewards = yield getRewardsForMarket(selectedMarket.marketId, network);
|
|
125
|
-
return addMorphoBlueRewardsToMarketInfo(marketInfo, rewards);
|
|
126
|
-
}
|
|
127
|
-
catch (error) {
|
|
128
|
-
console.error(error);
|
|
129
|
-
return addMorphoBlueRewardsToMarketInfo(marketInfo, { supplyApy: '0', borrowApy: '0' });
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
export function _getMorphoBluePortfolioMarketData(provider, network, selectedMarket) {
|
|
134
|
-
return getMorphoBlueMarketDataInternal(provider, network, selectedMarket);
|
|
135
|
-
}
|
|
136
127
|
export function getMorphoBlueMarketData(provider, network, selectedMarket) {
|
|
137
128
|
return __awaiter(this, void 0, void 0, function* () {
|
|
138
129
|
return _getMorphoBlueMarketData(getViemProvider(provider, network), network, selectedMarket);
|
|
139
130
|
});
|
|
140
131
|
}
|
|
141
|
-
export function getMorphoBluePortfolioMarketData(provider, network, selectedMarket) {
|
|
142
|
-
return _getMorphoBluePortfolioMarketData(getViemProvider(provider, network), network, selectedMarket);
|
|
143
|
-
}
|
|
144
|
-
export const getMorphoBluePositionDataWithMarketInfo = (data, marketInfo) => (Object.assign(Object.assign({}, data), getMorphoBlueAggregatedPositionData({
|
|
145
|
-
usedAssets: data.usedAssets,
|
|
146
|
-
assetsData: marketInfo.assetsData,
|
|
147
|
-
marketInfo,
|
|
148
|
-
})));
|
|
149
|
-
export const getMorphoEarnDataWithMarketInfo = (data, marketInfo) => {
|
|
150
|
-
const loanTokenInfo = marketInfo.assetsData[marketInfo.loanToken];
|
|
151
|
-
const usedAssets = {
|
|
152
|
-
[marketInfo.loanToken]: {
|
|
153
|
-
symbol: loanTokenInfo.symbol,
|
|
154
|
-
supplied: data.amount,
|
|
155
|
-
borrowed: '0',
|
|
156
|
-
isSupplied: new Dec(data.amount).gt(0),
|
|
157
|
-
isBorrowed: false,
|
|
158
|
-
collateral: false,
|
|
159
|
-
suppliedUsd: data.amountUsd,
|
|
160
|
-
borrowedUsd: '0',
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
return Object.assign(Object.assign({}, data), { apy: calculateNetApy({ usedAssets, assetsData: marketInfo.assetsData }).netApy });
|
|
164
|
-
};
|
|
165
|
-
export function getMorphoBlueMarketRewards(network, selectedMarket) {
|
|
166
|
-
return getRewardsForMarket(selectedMarket.marketId, network);
|
|
167
|
-
}
|
|
168
132
|
export const _getMorphoBlueAccountBalances = (provider, network, block, addressMapping, address, selectedMarket) => __awaiter(void 0, void 0, void 0, function* () {
|
|
169
133
|
let balances = {
|
|
170
134
|
collateral: {},
|
|
@@ -252,10 +216,23 @@ export function getMorphoEarn(provider, network, account, selectedMarket, market
|
|
|
252
216
|
const loanTokenInfo = marketInfo.assetsData[marketInfo.loanToken];
|
|
253
217
|
const loanTokenSupplied = assetAmountInEth(loanInfo.suppliedInAssets.toString(), marketInfo.loanToken);
|
|
254
218
|
const loanTokenSuppliedUsd = new Dec(loanTokenSupplied).mul(loanTokenInfo.price).toString();
|
|
255
|
-
|
|
256
|
-
|
|
219
|
+
const usedAssets = {
|
|
220
|
+
[marketInfo.loanToken]: {
|
|
221
|
+
symbol: loanTokenInfo.symbol,
|
|
222
|
+
supplied: loanTokenSupplied,
|
|
223
|
+
borrowed: '0',
|
|
224
|
+
isSupplied: new Dec(loanInfo.suppliedInAssets.toString()).gt(0),
|
|
225
|
+
isBorrowed: false,
|
|
226
|
+
collateral: false,
|
|
227
|
+
suppliedUsd: loanTokenSuppliedUsd,
|
|
228
|
+
borrowedUsd: '0',
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
const { netApy } = calculateNetApy({ usedAssets, assetsData: marketInfo.assetsData });
|
|
232
|
+
return {
|
|
233
|
+
apy: netApy,
|
|
257
234
|
amount: loanTokenSupplied,
|
|
258
235
|
amountUsd: loanTokenSuppliedUsd,
|
|
259
|
-
}
|
|
236
|
+
};
|
|
260
237
|
});
|
|
261
238
|
}
|