@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/cjs/contracts.js
CHANGED
|
@@ -33,8 +33,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.
|
|
37
|
-
exports.AaveV4ViewContractViem = exports.SkySavingsContractView = exports.MakerDsrContractViem = exports.YearnViewContractViem = exports.StkAAVEViem = exports.LiquityV2sBoldVaultViem = exports.AaveRewardsControllerViem = void 0;
|
|
36
|
+
exports.UUPSViem = exports.LiquityStabilityPoolViem = exports.LiquityLQTYStakingViem = exports.AaveUmbrellaViewViem = exports.AaveIncentivesControllerViem = exports.FluidViewContractViem = exports.LiquityV2LegacyViewContractViem = exports.LiquityV2ViewContractViem = exports.LiquityActivePoolContractViem = exports.LiquityPriceFeedContractViem = exports.LiquityTroveManagerContractViem = exports.LiquityCollSurplusPoolContractViem = exports.LiquityViewContractViem = exports.BTCPriceFeedContractViem = exports.WeETHPriceFeedContractViem = exports.ComptrollerContractViem = exports.CompoundLoanInfoContractViem = exports.McdJugContractViem = exports.McdDogContractViem = exports.McdSpotterContractViem = exports.McdVatContractViem = exports.McdViewContractViem = exports.McdGetCdpsContractViem = exports.LlamaLendViewContractViem = exports.CrvUSDFactoryContractViem = exports.CrvUSDViewContractViem = exports.EulerV2ViewContractViem = exports.SparkIncentiveDataProviderContractViem = exports.SparkViewContractViem = exports.CompV3ViewContractViem = exports.WstETHPriceFeedContractViem = exports.USDCPriceFeedContractViem = exports.ETHPriceFeedContractViem = exports.COMPPriceFeedContractViem = exports.DFSFeedRegistryContractViem = exports.FeedRegistryContractViem = exports.AaveIncentiveDataProviderV3ContractViem = exports.AaveV3ViewContractViem = exports.AaveLoanInfoV2ContractViem = exports.MorphoMidnightViewContractViem = exports.MorphoBlueViewContractViem = exports.getYearnV3VaultContractViem = exports.getErc4626ContractViem = exports.getErc20ContractViem = exports.getSparkSavingsVaultContractViem = exports.getYearnVaultContractViem = exports.getMorphoVaultContractViem = exports.createViemContractFromConfigFunc = exports.getConfigContractAbi = exports.getConfigContractAddress = void 0;
|
|
37
|
+
exports.AaveV4ViewContractViem = exports.SkySavingsContractView = exports.MakerDsrContractViem = exports.YearnViewContractViem = exports.StkAAVEViem = exports.LiquityV2sBoldVaultViem = exports.AaveRewardsControllerViem = exports.SparkRewardsControllerViem = void 0;
|
|
38
38
|
const viem_1 = require("viem");
|
|
39
39
|
const configRaw = __importStar(require("./config/contracts"));
|
|
40
40
|
// @ts-ignore
|
|
@@ -140,6 +140,7 @@ const getYearnV3VaultContractViem = (client, address) => {
|
|
|
140
140
|
};
|
|
141
141
|
exports.getYearnV3VaultContractViem = getYearnV3VaultContractViem;
|
|
142
142
|
exports.MorphoBlueViewContractViem = (0, exports.createViemContractFromConfigFunc)('MorphoBlueView');
|
|
143
|
+
exports.MorphoMidnightViewContractViem = (0, exports.createViemContractFromConfigFunc)('MidnightView');
|
|
143
144
|
exports.AaveLoanInfoV2ContractViem = (0, exports.createViemContractFromConfigFunc)('AaveLoanInfoV2');
|
|
144
145
|
exports.AaveV3ViewContractViem = (0, exports.createViemContractFromConfigFunc)('AaveV3View');
|
|
145
146
|
exports.AaveIncentiveDataProviderV3ContractViem = (0, exports.createViemContractFromConfigFunc)('AaveUiIncentiveDataProviderV3');
|
package/cjs/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/cjs/helpers/index.js
CHANGED
|
@@ -33,13 +33,14 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.aaveV4Helpers = exports.fluidHelpers = exports.eulerV2Helpers = exports.liquityV2Helpers = exports.llamaLendHelpers = exports.morphoBlueHelpers = exports.makerHelpers = exports.curveUsdHelpers = exports.sparkHelpers = exports.compoundHelpers = exports.aaveHelpers = void 0;
|
|
36
|
+
exports.aaveV4Helpers = exports.fluidHelpers = exports.eulerV2Helpers = exports.liquityV2Helpers = exports.llamaLendHelpers = exports.morphoMidnightHelpers = exports.morphoBlueHelpers = exports.makerHelpers = exports.curveUsdHelpers = exports.sparkHelpers = exports.compoundHelpers = exports.aaveHelpers = void 0;
|
|
37
37
|
exports.aaveHelpers = __importStar(require("./aaveHelpers"));
|
|
38
38
|
exports.compoundHelpers = __importStar(require("./compoundHelpers"));
|
|
39
39
|
exports.sparkHelpers = __importStar(require("./sparkHelpers"));
|
|
40
40
|
exports.curveUsdHelpers = __importStar(require("./curveUsdHelpers"));
|
|
41
41
|
exports.makerHelpers = __importStar(require("./makerHelpers"));
|
|
42
42
|
exports.morphoBlueHelpers = __importStar(require("./morphoBlueHelpers"));
|
|
43
|
+
exports.morphoMidnightHelpers = __importStar(require("./morphoMidnightHelpers"));
|
|
43
44
|
exports.llamaLendHelpers = __importStar(require("./llamaLendHelpers"));
|
|
44
45
|
exports.liquityV2Helpers = __importStar(require("./liquityV2Helpers"));
|
|
45
46
|
exports.eulerV2Helpers = __importStar(require("./eulerHelpers"));
|
|
@@ -361,7 +361,6 @@ const getRewardsForMarket = (marketId_1, ...args_1) => __awaiter(void 0, [market
|
|
|
361
361
|
query: REWARDS_QUERY,
|
|
362
362
|
variables: { marketId, chainId: network },
|
|
363
363
|
}),
|
|
364
|
-
signal: AbortSignal.timeout(utils_1.LONGER_TIMEOUT),
|
|
365
364
|
});
|
|
366
365
|
const data = yield response.json();
|
|
367
366
|
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,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getMorphoMidnightBorrowQuote = exports.getMorphoMidnightUserBorrowInfo = exports.midnightApyFromPrice = exports.midnightTimeToMaturityDays = exports.getMorphoMidnightAggregatedPositionData = void 0;
|
|
16
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
17
|
+
const tokens_1 = require("@defisaver/tokens");
|
|
18
|
+
const moneymarket_1 = require("../../moneymarket");
|
|
19
|
+
const staking_1 = require("../../staking");
|
|
20
|
+
const common_1 = require("../../types/common");
|
|
21
|
+
const constants_1 = require("../../constants");
|
|
22
|
+
const utils_1 = require("../../services/utils");
|
|
23
|
+
/**
|
|
24
|
+
* Aggregate a Morpho Midnight position. Midnight markets are multi-collateral, so the borrow limit is
|
|
25
|
+
* the sum of each collateral's USD value times its own lltv (Aave-v4 style), rather than a single pair.
|
|
26
|
+
*
|
|
27
|
+
* Note on amounts: `borrowedUsd` is derived from the position's `debt`, which is the face value owed at
|
|
28
|
+
* maturity (principal + fixed interest). Health is therefore measured against the full maturity debt,
|
|
29
|
+
* matching how MidnightView computes `ratio`. Fixed-rate APY is not derived on-chain in MVP, so
|
|
30
|
+
* `netApy` reflects the `'0'` rates in `assetsData` (see the module getter).
|
|
31
|
+
*/
|
|
32
|
+
const getMorphoMidnightAggregatedPositionData = ({ usedAssets, assetsData, marketInfo, }) => {
|
|
33
|
+
var _a;
|
|
34
|
+
const payload = {};
|
|
35
|
+
payload.suppliedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
|
|
36
|
+
payload.suppliedCollateralUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ suppliedUsd }) => suppliedUsd);
|
|
37
|
+
payload.borrowedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
|
|
38
|
+
// borrowLimit = Σ collateralUsd_i * lltv_i (per-collateral lltv carried on assetsData)
|
|
39
|
+
payload.borrowLimitUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd }) => { var _a; return new decimal_js_1.default(suppliedUsd).mul(((_a = assetsData[symbol]) === null || _a === void 0 ? void 0 : _a.lltv) || 0); });
|
|
40
|
+
payload.liquidationLimitUsd = payload.borrowLimitUsd;
|
|
41
|
+
const leftToBorrowUsd = new decimal_js_1.default(payload.borrowLimitUsd).sub(payload.borrowedUsd);
|
|
42
|
+
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
43
|
+
const loanTokenPrice = ((_a = assetsData[marketInfo.loanToken]) === null || _a === void 0 ? void 0 : _a.price) || '0';
|
|
44
|
+
payload.leftToBorrow = new decimal_js_1.default(loanTokenPrice).eq(0) ? '0' : new decimal_js_1.default(payload.leftToBorrowUsd).div(loanTokenPrice).toString();
|
|
45
|
+
const { netApy, incentiveUsd, totalInterestUsd } = (0, staking_1.calculateNetApy)({ usedAssets, assetsData: assetsData });
|
|
46
|
+
payload.netApy = netApy;
|
|
47
|
+
payload.incentiveUsd = incentiveUsd;
|
|
48
|
+
payload.totalInterestUsd = totalInterestUsd;
|
|
49
|
+
payload.ltv = new decimal_js_1.default(payload.suppliedCollateralUsd).eq(0) ? '0' : new decimal_js_1.default(payload.borrowedUsd).div(payload.suppliedCollateralUsd).toString();
|
|
50
|
+
payload.ratio = new decimal_js_1.default(payload.borrowedUsd).eq(0) ? '0' : new decimal_js_1.default(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString();
|
|
51
|
+
payload.healthRatio = new decimal_js_1.default(payload.borrowedUsd).eq(0) ? 'Infinity' : new decimal_js_1.default(payload.liquidationLimitUsd).div(payload.borrowedUsd).toDP(4).toString();
|
|
52
|
+
const { leveragedType, leveragedAsset } = (0, moneymarket_1.isLeveragedPos)(usedAssets);
|
|
53
|
+
payload.leveragedType = leveragedType;
|
|
54
|
+
payload.liquidationPrice = '';
|
|
55
|
+
if (leveragedType !== '') {
|
|
56
|
+
payload.leveragedAsset = leveragedAsset;
|
|
57
|
+
let assetPrice = assetsData[leveragedAsset].price;
|
|
58
|
+
if (leveragedType === common_1.LeverageType.VolatilePair) {
|
|
59
|
+
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
60
|
+
const borrowedAssetPrice = assetsData[borrowedAsset.symbol].price;
|
|
61
|
+
const leveragedAssetPrice = assetsData[leveragedAsset].price;
|
|
62
|
+
const isReverse = new decimal_js_1.default(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
63
|
+
if (isReverse) {
|
|
64
|
+
payload.leveragedType = common_1.LeverageType.VolatilePairReverse;
|
|
65
|
+
payload.currentVolatilePairRatio = new decimal_js_1.default(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
66
|
+
assetPrice = new decimal_js_1.default(borrowedAssetPrice).div(assetPrice).toString();
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
assetPrice = new decimal_js_1.default(assetPrice).div(borrowedAssetPrice).toString();
|
|
70
|
+
payload.currentVolatilePairRatio = new decimal_js_1.default(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
payload.liquidationPrice = (0, moneymarket_1.calcLeverageLiqPrice)(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
74
|
+
}
|
|
75
|
+
payload.minCollRatio = new decimal_js_1.default(payload.borrowLimitUsd).eq(0) ? '0' : new decimal_js_1.default(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
76
|
+
payload.collLiquidationRatio = new decimal_js_1.default(payload.liquidationLimitUsd).eq(0) ? '0' : new decimal_js_1.default(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
77
|
+
payload.exposure = (0, moneymarket_1.getExposure)(payload.borrowedUsd, payload.suppliedUsd);
|
|
78
|
+
return payload;
|
|
79
|
+
};
|
|
80
|
+
exports.getMorphoMidnightAggregatedPositionData = getMorphoMidnightAggregatedPositionData;
|
|
81
|
+
// ── Off-chain order-book rate helpers ──────────────────────────────────────────────────────────────
|
|
82
|
+
// notion: https://app.notion.com/p/defisaver/Estimate-borrow-rate-and-slippage-before-execution-3a70be682adc80c783c8c11fdb761dd2
|
|
83
|
+
// the borrow rate is not exposed on-chain (MidnightView only stores total debt at maturity in `units`).
|
|
84
|
+
// derive the rate + interest from Morpho's public keyless Midnight API
|
|
85
|
+
// Quote prices are WAD-scaled
|
|
86
|
+
// loan-per-unit ratios (< 1 for a discounted fixed-term borrow); annualizing them yields the borrow APY.
|
|
87
|
+
const MIDNIGHT_API_BASE = 'https://api.morpho.org/v0/midnight';
|
|
88
|
+
const nowInSeconds = () => Math.floor(Date.now() / 1000);
|
|
89
|
+
// Days remaining until maturity, optionally measured at a past timestamp (for historical fills).
|
|
90
|
+
const midnightTimeToMaturityDays = (maturity, atSeconds = nowInSeconds()) => new decimal_js_1.default(maturity).sub(atSeconds).div(constants_1.SECONDS_PER_DAY).toNumber();
|
|
91
|
+
exports.midnightTimeToMaturityDays = midnightTimeToMaturityDays;
|
|
92
|
+
// Annualize a fixed-term discount price into an APY percent: (1 / price)^(365 / ttmDays) − 1.
|
|
93
|
+
// `price` is loan-per-unit (assets received / units owed), so 1/price ≥ 1.
|
|
94
|
+
const midnightApyFromPrice = (price, ttmDays) => {
|
|
95
|
+
const p = new decimal_js_1.default(price);
|
|
96
|
+
const ttm = new decimal_js_1.default(ttmDays);
|
|
97
|
+
if (p.lte(0) || ttm.lte(0))
|
|
98
|
+
return '0';
|
|
99
|
+
return new decimal_js_1.default(1).div(p).pow(new decimal_js_1.default(365).div(ttm)).sub(1)
|
|
100
|
+
.mul(100)
|
|
101
|
+
.toString();
|
|
102
|
+
};
|
|
103
|
+
exports.midnightApyFromPrice = midnightApyFromPrice;
|
|
104
|
+
/**
|
|
105
|
+
* Current borrower rate + debt breakdown from the Midnight transactions API. On-chain we can only read the
|
|
106
|
+
* total debt at maturity (`units`); the base-vs-interest split and the effective borrow rate require the
|
|
107
|
+
* fill history. Per fill the rate is (units / seller_assets)^(365 / ttmAtFill) − 1, weighted by base amount.
|
|
108
|
+
* The caller swallows errors — a missing rate must never block position rendering.
|
|
109
|
+
*/
|
|
110
|
+
const getMorphoMidnightUserBorrowInfo = (account, marketId, maturity, loanTokenSymbol) => __awaiter(void 0, void 0, void 0, function* () {
|
|
111
|
+
const res = yield fetch(`${MIDNIGHT_API_BASE}/users/${account}/transactions`, { signal: AbortSignal.timeout(utils_1.LONGER_TIMEOUT) });
|
|
112
|
+
const json = yield res.json();
|
|
113
|
+
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(); });
|
|
114
|
+
let sumSeller = new decimal_js_1.default(0); // Σ seller_assets (base), raw
|
|
115
|
+
let sumUnits = new decimal_js_1.default(0); // Σ units (debt at maturity), raw
|
|
116
|
+
let weightedApy = new decimal_js_1.default(0); // Σ seller_assets × APYᵢ
|
|
117
|
+
borrows.forEach((t) => {
|
|
118
|
+
var _a, _b;
|
|
119
|
+
const sellerAssets = new decimal_js_1.default(((_a = t.data) === null || _a === void 0 ? void 0 : _a.seller_assets) || 0);
|
|
120
|
+
const units = new decimal_js_1.default(((_b = t.data) === null || _b === void 0 ? void 0 : _b.units) || 0);
|
|
121
|
+
if (sellerAssets.lte(0) || units.lte(0))
|
|
122
|
+
return;
|
|
123
|
+
const ttmDays = (0, exports.midnightTimeToMaturityDays)(maturity, t.created_at);
|
|
124
|
+
const apy = (0, exports.midnightApyFromPrice)(sellerAssets.div(units), ttmDays); // price = seller_assets / units
|
|
125
|
+
sumSeller = sumSeller.add(sellerAssets);
|
|
126
|
+
sumUnits = sumUnits.add(units);
|
|
127
|
+
weightedApy = weightedApy.add(sellerAssets.mul(apy));
|
|
128
|
+
});
|
|
129
|
+
const borrowRate = sumSeller.lte(0) ? '0' : weightedApy.div(sumSeller).toString();
|
|
130
|
+
const debtBase = (0, tokens_1.assetAmountInEth)(sumSeller.toFixed(0), loanTokenSymbol);
|
|
131
|
+
const debtTotal = (0, tokens_1.assetAmountInEth)(sumUnits.toFixed(0), loanTokenSymbol);
|
|
132
|
+
const debtInterest = decimal_js_1.default.max(new decimal_js_1.default(debtTotal).sub(debtBase), 0).toString();
|
|
133
|
+
return {
|
|
134
|
+
borrowRate, debtBase, debtInterest, debtTotal,
|
|
135
|
+
};
|
|
136
|
+
});
|
|
137
|
+
exports.getMorphoMidnightUserBorrowInfo = getMorphoMidnightUserBorrowInfo;
|
|
138
|
+
/**
|
|
139
|
+
* Estimate the borrow rate + slippage cap for a prospective borrow by quoting the Midnight order book.
|
|
140
|
+
* `assetsRaw` (and the returned `newUnits`/`maxUnits`) are raw loan-token base units — callers convert to/from
|
|
141
|
+
* human amounts. `maxUnits` (from the slippage-adjusted worst price) is the cap sent on-chain to protect the
|
|
142
|
+
* user if better offers get filled first. Throws if the book can't fill the amount (caller handles).
|
|
143
|
+
*/
|
|
144
|
+
const getMorphoMidnightBorrowQuote = (marketId, assetsRaw, slippagePercent, maturity) => __awaiter(void 0, void 0, void 0, function* () {
|
|
145
|
+
const url = `${MIDNIGHT_API_BASE}/books/${marketId}/bids/quote?assets=${assetsRaw}&slippage=${slippagePercent}`;
|
|
146
|
+
const res = yield fetch(url, { signal: AbortSignal.timeout(utils_1.LONGER_TIMEOUT) });
|
|
147
|
+
const json = yield res.json();
|
|
148
|
+
const d = json === null || json === void 0 ? void 0 : json.data;
|
|
149
|
+
if (!(d === null || d === void 0 ? void 0 : d.average_best_price))
|
|
150
|
+
throw new Error('Morpho Midnight quote unavailable');
|
|
151
|
+
const bestPrice = new decimal_js_1.default(d.average_best_price).div(constants_1.WAD).toString();
|
|
152
|
+
const worstPrice = new decimal_js_1.default(d.average_worst_price).div(constants_1.WAD).toString();
|
|
153
|
+
const ttmDays = (0, exports.midnightTimeToMaturityDays)(maturity);
|
|
154
|
+
const estBorrowRate = (0, exports.midnightApyFromPrice)(bestPrice, ttmDays);
|
|
155
|
+
const maxRate = new decimal_js_1.default(estBorrowRate).add(slippagePercent).toString();
|
|
156
|
+
const newUnits = new decimal_js_1.default(bestPrice).lte(0) ? '0' : new decimal_js_1.default(assetsRaw).div(bestPrice).toFixed(0);
|
|
157
|
+
const maxUnits = new decimal_js_1.default(worstPrice).lte(0) ? '0' : new decimal_js_1.default(assetsRaw).div(worstPrice).toFixed(0);
|
|
158
|
+
return {
|
|
159
|
+
bestPrice,
|
|
160
|
+
worstPrice,
|
|
161
|
+
estBorrowRate,
|
|
162
|
+
maxRate,
|
|
163
|
+
newUnits,
|
|
164
|
+
maxUnits,
|
|
165
|
+
availableAssets: d.available_assets,
|
|
166
|
+
availableUnits: d.available_units,
|
|
167
|
+
takeableOffers: d.takeable_offers || [],
|
|
168
|
+
};
|
|
169
|
+
});
|
|
170
|
+
exports.getMorphoMidnightBorrowQuote = getMorphoMidnightBorrowQuote;
|
package/cjs/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/cjs/index.js
CHANGED
|
@@ -36,7 +36,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
36
36
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.savings = exports.claiming = exports.portfolio = exports.fluid = exports.eulerV2 = exports.llamaLend = exports.morphoBlue = exports.helpers = exports.markets = exports.moneymarket = exports.staking = exports.exchange = exports.maker = exports.liquityV2 = exports.liquity = exports.curveUsd = exports.spark = exports.compoundV3 = exports.compoundV2 = exports.aaveV4 = exports.aaveV3 = exports.aaveV2 = void 0;
|
|
39
|
+
exports.savings = exports.claiming = exports.portfolio = exports.fluid = exports.eulerV2 = exports.llamaLend = exports.morphoMidnight = exports.morphoBlue = exports.helpers = exports.markets = exports.moneymarket = exports.staking = exports.exchange = exports.maker = exports.liquityV2 = exports.liquity = exports.curveUsd = exports.spark = exports.compoundV3 = exports.compoundV2 = exports.aaveV4 = exports.aaveV3 = exports.aaveV2 = void 0;
|
|
40
40
|
require("./setup");
|
|
41
41
|
const fluid = __importStar(require("./fluid"));
|
|
42
42
|
exports.fluid = fluid;
|
|
@@ -72,6 +72,8 @@ const exchange = __importStar(require("./exchange"));
|
|
|
72
72
|
exports.exchange = exchange;
|
|
73
73
|
const morphoBlue = __importStar(require("./morphoBlue"));
|
|
74
74
|
exports.morphoBlue = morphoBlue;
|
|
75
|
+
const morphoMidnight = __importStar(require("./morphoMidnight"));
|
|
76
|
+
exports.morphoMidnight = morphoMidnight;
|
|
75
77
|
const llamaLend = __importStar(require("./llamaLend"));
|
|
76
78
|
exports.llamaLend = llamaLend;
|
|
77
79
|
const eulerV2 = __importStar(require("./eulerV2"));
|
package/cjs/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/cjs/markets/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findAaveV4SpokeByAddress = exports.AaveV4Spokes = exports.getFluidMarketInfoByAddress = exports.getFTokenAddress = exports.getFluidMarketInfoById = exports.getFluidVersionsDataForNetwork = exports.FluidMarkets = exports.EulerV2Markets = exports.findLiquityV2MarketByAddress = exports.LiquityV2Markets = exports.LlamaLendMarkets = exports.findMorphoBlueMarket = exports.MorphoBlueMarkets = exports.CrvUsdMarkets = exports.SparkMarkets = exports.v3USDTCollAssets = exports.v3USDCeCollAssets = exports.v3USDCCollAssets = exports.v3USDbCCollAssets = exports.v3ETHCollAssets = exports.compoundV2CollateralAssets = exports.CompoundMarkets = exports.getAaveV3MarketByMarketAddress = exports.aaveV3AssetsDefaultMarket = exports.aaveV2AssetsDefaultMarket = exports.aaveV1AssetsDefaultMarket = exports.AaveMarkets = void 0;
|
|
3
|
+
exports.findAaveV4SpokeByAddress = exports.AaveV4Spokes = exports.getFluidMarketInfoByAddress = exports.getFTokenAddress = exports.getFluidMarketInfoById = exports.getFluidVersionsDataForNetwork = exports.FluidMarkets = exports.EulerV2Markets = exports.findLiquityV2MarketByAddress = exports.LiquityV2Markets = exports.LlamaLendMarkets = exports.findMorphoMidnightMarket = exports.MorphoMidnightMarkets = exports.findMorphoBlueMarket = exports.MorphoBlueMarkets = exports.CrvUsdMarkets = exports.SparkMarkets = exports.v3USDTCollAssets = exports.v3USDCeCollAssets = exports.v3USDCCollAssets = exports.v3USDbCCollAssets = exports.v3ETHCollAssets = exports.compoundV2CollateralAssets = exports.CompoundMarkets = exports.getAaveV3MarketByMarketAddress = exports.aaveV3AssetsDefaultMarket = exports.aaveV2AssetsDefaultMarket = exports.aaveV1AssetsDefaultMarket = exports.AaveMarkets = void 0;
|
|
4
4
|
var aave_1 = require("./aave");
|
|
5
5
|
Object.defineProperty(exports, "AaveMarkets", { enumerable: true, get: function () { return aave_1.AaveMarkets; } });
|
|
6
6
|
Object.defineProperty(exports, "aaveV1AssetsDefaultMarket", { enumerable: true, get: function () { return aave_1.aaveV1AssetsDefaultMarket; } });
|
|
@@ -22,6 +22,9 @@ Object.defineProperty(exports, "CrvUsdMarkets", { enumerable: true, get: functio
|
|
|
22
22
|
var morphoBlue_1 = require("./morphoBlue");
|
|
23
23
|
Object.defineProperty(exports, "MorphoBlueMarkets", { enumerable: true, get: function () { return morphoBlue_1.MorphoBlueMarkets; } });
|
|
24
24
|
Object.defineProperty(exports, "findMorphoBlueMarket", { enumerable: true, get: function () { return morphoBlue_1.findMorphoBlueMarket; } });
|
|
25
|
+
var morphoMidnight_1 = require("./morphoMidnight");
|
|
26
|
+
Object.defineProperty(exports, "MorphoMidnightMarkets", { enumerable: true, get: function () { return morphoMidnight_1.MorphoMidnightMarkets; } });
|
|
27
|
+
Object.defineProperty(exports, "findMorphoMidnightMarket", { enumerable: true, get: function () { return morphoMidnight_1.findMorphoMidnightMarket; } });
|
|
25
28
|
var llamaLend_1 = require("./llamaLend");
|
|
26
29
|
Object.defineProperty(exports, "LlamaLendMarkets", { enumerable: true, get: function () { return llamaLend_1.LlamaLendMarkets; } });
|
|
27
30
|
var liquityV2_1 = require("./liquityV2");
|
|
@@ -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,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findMorphoMidnightMarket = exports.MorphoMidnightMarkets = exports.MORPHO_MIDNIGHT_CBBTC_USDC_860_20261225 = exports.MORPHO_MIDNIGHT_CBBTC_USDC_860_20261127 = exports.MORPHO_MIDNIGHT_CBBTC_USDC_860_20261030 = exports.MORPHO_MIDNIGHT_CBBTC_USDC_860_20260925 = exports.MORPHO_MIDNIGHT_CBBTC_USDC_860_20260828 = exports.MORPHO_MIDNIGHT_CBBTC_USDC_860_20260731 = void 0;
|
|
4
|
+
const types_1 = require("../../types");
|
|
5
|
+
// Morpho Midnight core contract on Base (same for every market).
|
|
6
|
+
const MIDNIGHT_BASE = '0xAdedD8ab6dE832766Fedf0FaC4992E5C4D3EA18A';
|
|
7
|
+
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|
8
|
+
// Curated Morpho Midnight markets. Each market is fixed-term: it is uniquely identified on-chain by
|
|
9
|
+
// `marketId` (bytes32), derived from the static struct below via MidnightView.toId. Because markets
|
|
10
|
+
// churn as maturities roll, this list is hand-maintained for the pairs/maturities the app supports.
|
|
11
|
+
// Sourced from the official listing at https://markets.morpho.org/fixed/base (see its sitemap.xml) —
|
|
12
|
+
// currently a single USDC/cbBTC pair offered on a monthly maturity ladder; new maturities are added
|
|
13
|
+
// there progressively. Every `marketId` here is verified against MidnightView.toId(marketStruct) in
|
|
14
|
+
// tests/morphoMidnight.ts.
|
|
15
|
+
// BASE — USDC/cbBTC, 86% LLTV, monthly maturity ladder
|
|
16
|
+
const MORPHO_MIDNIGHT_CBBTC_USDC_860_20260731 = (networkId = types_1.NetworkNumber.Base) => ({
|
|
17
|
+
chainIds: [types_1.NetworkNumber.Base],
|
|
18
|
+
label: 'Morpho Midnight cbBTC/USDC',
|
|
19
|
+
shortLabel: 'cbBTC/USDC',
|
|
20
|
+
url: 'cbbtc-usdc-20260731',
|
|
21
|
+
value: types_1.MorphoMidnightVersions.MorphoMidnightCbBTCUSDC_860_20260731_Base,
|
|
22
|
+
midnight: MIDNIGHT_BASE,
|
|
23
|
+
loanToken: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC
|
|
24
|
+
collaterals: [{
|
|
25
|
+
token: '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf', // cbBTC
|
|
26
|
+
lltv: 0.86,
|
|
27
|
+
liquidationCursor: '300000000000000000',
|
|
28
|
+
oracle: '0x663BECd10daE6C4A3Dcd89F1d76c1174199639B9',
|
|
29
|
+
}],
|
|
30
|
+
maturity: 1785510000, // 2026-07-31T15:00:00Z
|
|
31
|
+
rcfThreshold: '3000000000',
|
|
32
|
+
enterGate: ZERO_ADDRESS,
|
|
33
|
+
liquidatorGate: ZERO_ADDRESS,
|
|
34
|
+
marketId: '0x168e31250e0008b50d2255a5ab85e0265acd6c12e4f9a1336134b36a65a47937',
|
|
35
|
+
protocolName: 'morpho-midnight',
|
|
36
|
+
});
|
|
37
|
+
exports.MORPHO_MIDNIGHT_CBBTC_USDC_860_20260731 = MORPHO_MIDNIGHT_CBBTC_USDC_860_20260731;
|
|
38
|
+
const MORPHO_MIDNIGHT_CBBTC_USDC_860_20260828 = (networkId = types_1.NetworkNumber.Base) => ({
|
|
39
|
+
chainIds: [types_1.NetworkNumber.Base],
|
|
40
|
+
label: 'Morpho Midnight cbBTC/USDC',
|
|
41
|
+
shortLabel: 'cbBTC/USDC',
|
|
42
|
+
url: 'cbbtc-usdc-20260828',
|
|
43
|
+
value: types_1.MorphoMidnightVersions.MorphoMidnightCbBTCUSDC_860_20260828_Base,
|
|
44
|
+
midnight: MIDNIGHT_BASE,
|
|
45
|
+
loanToken: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC
|
|
46
|
+
collaterals: [{
|
|
47
|
+
token: '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf', // cbBTC
|
|
48
|
+
lltv: 0.86,
|
|
49
|
+
liquidationCursor: '300000000000000000',
|
|
50
|
+
oracle: '0x663BECd10daE6C4A3Dcd89F1d76c1174199639B9',
|
|
51
|
+
}],
|
|
52
|
+
maturity: 1787929200, // 2026-08-28T15:00:00Z
|
|
53
|
+
rcfThreshold: '3000000000',
|
|
54
|
+
enterGate: ZERO_ADDRESS,
|
|
55
|
+
liquidatorGate: ZERO_ADDRESS,
|
|
56
|
+
marketId: '0x05959752fdeff325962b9d263edb421efc6e2186a49360dba6c32e86ebf6c84c',
|
|
57
|
+
protocolName: 'morpho-midnight',
|
|
58
|
+
});
|
|
59
|
+
exports.MORPHO_MIDNIGHT_CBBTC_USDC_860_20260828 = MORPHO_MIDNIGHT_CBBTC_USDC_860_20260828;
|
|
60
|
+
const MORPHO_MIDNIGHT_CBBTC_USDC_860_20260925 = (networkId = types_1.NetworkNumber.Base) => ({
|
|
61
|
+
chainIds: [types_1.NetworkNumber.Base],
|
|
62
|
+
label: 'Morpho Midnight cbBTC/USDC',
|
|
63
|
+
shortLabel: 'cbBTC/USDC',
|
|
64
|
+
url: 'cbbtc-usdc-20260925',
|
|
65
|
+
value: types_1.MorphoMidnightVersions.MorphoMidnightCbBTCUSDC_860_20260925_Base,
|
|
66
|
+
midnight: MIDNIGHT_BASE,
|
|
67
|
+
loanToken: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC
|
|
68
|
+
collaterals: [{
|
|
69
|
+
token: '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf', // cbBTC
|
|
70
|
+
lltv: 0.86,
|
|
71
|
+
liquidationCursor: '300000000000000000',
|
|
72
|
+
oracle: '0x663BECd10daE6C4A3Dcd89F1d76c1174199639B9',
|
|
73
|
+
}],
|
|
74
|
+
maturity: 1790348400, // 2026-09-25T15:00:00Z
|
|
75
|
+
rcfThreshold: '3000000000',
|
|
76
|
+
enterGate: ZERO_ADDRESS,
|
|
77
|
+
liquidatorGate: ZERO_ADDRESS,
|
|
78
|
+
marketId: '0x549cd072daf99328554f3a6d2d4d6f4a07f1c59369e891e6391946f9cf75f221',
|
|
79
|
+
protocolName: 'morpho-midnight',
|
|
80
|
+
});
|
|
81
|
+
exports.MORPHO_MIDNIGHT_CBBTC_USDC_860_20260925 = MORPHO_MIDNIGHT_CBBTC_USDC_860_20260925;
|
|
82
|
+
const MORPHO_MIDNIGHT_CBBTC_USDC_860_20261030 = (networkId = types_1.NetworkNumber.Base) => ({
|
|
83
|
+
chainIds: [types_1.NetworkNumber.Base],
|
|
84
|
+
label: 'Morpho Midnight cbBTC/USDC',
|
|
85
|
+
shortLabel: 'cbBTC/USDC',
|
|
86
|
+
url: 'cbbtc-usdc-20261030',
|
|
87
|
+
value: types_1.MorphoMidnightVersions.MorphoMidnightCbBTCUSDC_860_20261030_Base,
|
|
88
|
+
midnight: MIDNIGHT_BASE,
|
|
89
|
+
loanToken: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC
|
|
90
|
+
collaterals: [{
|
|
91
|
+
token: '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf', // cbBTC
|
|
92
|
+
lltv: 0.86,
|
|
93
|
+
liquidationCursor: '300000000000000000',
|
|
94
|
+
oracle: '0x663BECd10daE6C4A3Dcd89F1d76c1174199639B9',
|
|
95
|
+
}],
|
|
96
|
+
maturity: 1793372400, // 2026-10-30T15:00:00Z
|
|
97
|
+
rcfThreshold: '3000000000',
|
|
98
|
+
enterGate: ZERO_ADDRESS,
|
|
99
|
+
liquidatorGate: ZERO_ADDRESS,
|
|
100
|
+
marketId: '0x43d6120738c57b2bc5835901f8250fdf7fc8054efbb006c6ccba61ec898e5ed9',
|
|
101
|
+
protocolName: 'morpho-midnight',
|
|
102
|
+
});
|
|
103
|
+
exports.MORPHO_MIDNIGHT_CBBTC_USDC_860_20261030 = MORPHO_MIDNIGHT_CBBTC_USDC_860_20261030;
|
|
104
|
+
const MORPHO_MIDNIGHT_CBBTC_USDC_860_20261127 = (networkId = types_1.NetworkNumber.Base) => ({
|
|
105
|
+
chainIds: [types_1.NetworkNumber.Base],
|
|
106
|
+
label: 'Morpho Midnight cbBTC/USDC',
|
|
107
|
+
shortLabel: 'cbBTC/USDC',
|
|
108
|
+
url: 'cbbtc-usdc-20261127',
|
|
109
|
+
value: types_1.MorphoMidnightVersions.MorphoMidnightCbBTCUSDC_860_20261127_Base,
|
|
110
|
+
midnight: MIDNIGHT_BASE,
|
|
111
|
+
loanToken: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC
|
|
112
|
+
collaterals: [{
|
|
113
|
+
token: '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf', // cbBTC
|
|
114
|
+
lltv: 0.86,
|
|
115
|
+
liquidationCursor: '300000000000000000',
|
|
116
|
+
oracle: '0x663BECd10daE6C4A3Dcd89F1d76c1174199639B9',
|
|
117
|
+
}],
|
|
118
|
+
maturity: 1795791600, // 2026-11-27T15:00:00Z
|
|
119
|
+
rcfThreshold: '3000000000',
|
|
120
|
+
enterGate: ZERO_ADDRESS,
|
|
121
|
+
liquidatorGate: ZERO_ADDRESS,
|
|
122
|
+
marketId: '0xe1878eec035b601f301484e63a49a428f8e008e2bf57a2fd88a3fc3a4c1b1acd',
|
|
123
|
+
protocolName: 'morpho-midnight',
|
|
124
|
+
});
|
|
125
|
+
exports.MORPHO_MIDNIGHT_CBBTC_USDC_860_20261127 = MORPHO_MIDNIGHT_CBBTC_USDC_860_20261127;
|
|
126
|
+
const MORPHO_MIDNIGHT_CBBTC_USDC_860_20261225 = (networkId = types_1.NetworkNumber.Base) => ({
|
|
127
|
+
chainIds: [types_1.NetworkNumber.Base],
|
|
128
|
+
label: 'Morpho Midnight cbBTC/USDC',
|
|
129
|
+
shortLabel: 'cbBTC/USDC',
|
|
130
|
+
url: 'cbbtc-usdc-20261225',
|
|
131
|
+
value: types_1.MorphoMidnightVersions.MorphoMidnightCbBTCUSDC_860_20261225_Base,
|
|
132
|
+
midnight: MIDNIGHT_BASE,
|
|
133
|
+
loanToken: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC
|
|
134
|
+
collaterals: [{
|
|
135
|
+
token: '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf', // cbBTC
|
|
136
|
+
lltv: 0.86,
|
|
137
|
+
liquidationCursor: '300000000000000000',
|
|
138
|
+
oracle: '0x663BECd10daE6C4A3Dcd89F1d76c1174199639B9',
|
|
139
|
+
}],
|
|
140
|
+
maturity: 1798210800, // 2026-12-25T15:00:00Z
|
|
141
|
+
rcfThreshold: '3000000000',
|
|
142
|
+
enterGate: ZERO_ADDRESS,
|
|
143
|
+
liquidatorGate: ZERO_ADDRESS,
|
|
144
|
+
marketId: '0x9593c3a6dba45b6106af8dc8b45ba8c505d90d3d68a3d33f7c278dd921b637da',
|
|
145
|
+
protocolName: 'morpho-midnight',
|
|
146
|
+
});
|
|
147
|
+
exports.MORPHO_MIDNIGHT_CBBTC_USDC_860_20261225 = MORPHO_MIDNIGHT_CBBTC_USDC_860_20261225;
|
|
148
|
+
const MorphoMidnightMarkets = (networkId) => ({
|
|
149
|
+
// BASE
|
|
150
|
+
[types_1.MorphoMidnightVersions.MorphoMidnightCbBTCUSDC_860_20260731_Base]: (0, exports.MORPHO_MIDNIGHT_CBBTC_USDC_860_20260731)(networkId),
|
|
151
|
+
[types_1.MorphoMidnightVersions.MorphoMidnightCbBTCUSDC_860_20260828_Base]: (0, exports.MORPHO_MIDNIGHT_CBBTC_USDC_860_20260828)(networkId),
|
|
152
|
+
[types_1.MorphoMidnightVersions.MorphoMidnightCbBTCUSDC_860_20260925_Base]: (0, exports.MORPHO_MIDNIGHT_CBBTC_USDC_860_20260925)(networkId),
|
|
153
|
+
[types_1.MorphoMidnightVersions.MorphoMidnightCbBTCUSDC_860_20261030_Base]: (0, exports.MORPHO_MIDNIGHT_CBBTC_USDC_860_20261030)(networkId),
|
|
154
|
+
[types_1.MorphoMidnightVersions.MorphoMidnightCbBTCUSDC_860_20261127_Base]: (0, exports.MORPHO_MIDNIGHT_CBBTC_USDC_860_20261127)(networkId),
|
|
155
|
+
[types_1.MorphoMidnightVersions.MorphoMidnightCbBTCUSDC_860_20261225_Base]: (0, exports.MORPHO_MIDNIGHT_CBBTC_USDC_860_20261225)(networkId),
|
|
156
|
+
});
|
|
157
|
+
exports.MorphoMidnightMarkets = MorphoMidnightMarkets;
|
|
158
|
+
const findMorphoMidnightMarket = (marketId, network = types_1.NetworkNumber.Base) => Object.values((0, exports.MorphoMidnightMarkets)(network)).find((market) => market.marketId.toLowerCase() === marketId.toLowerCase());
|
|
159
|
+
exports.findMorphoMidnightMarket = findMorphoMidnightMarket;
|
|
@@ -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
|
+
}>;
|