@defisaver/positions-sdk 2.1.150 → 2.1.151-midnight-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/claiming/compV3.js +0 -1
- package/cjs/config/contracts.d.ts +4 -0
- package/cjs/config/contracts.js +4 -0
- package/cjs/helpers/morphoMidnightHelpers/tenor.d.ts +6 -2
- package/cjs/helpers/morphoMidnightHelpers/tenor.js +5 -1
- package/cjs/markets/index.d.ts +1 -1
- package/cjs/markets/index.js +2 -1
- package/cjs/markets/morphoMidnight/index.d.ts +44 -10
- package/cjs/markets/morphoMidnight/index.js +380 -59
- package/cjs/morphoMidnight/index.js +11 -1
- package/cjs/types/morphoMidnight.d.ts +35 -4
- package/cjs/types/morphoMidnight.js +23 -0
- package/esm/claiming/compV3.js +0 -1
- package/esm/config/contracts.d.ts +4 -0
- package/esm/config/contracts.js +4 -0
- package/esm/helpers/morphoMidnightHelpers/tenor.d.ts +6 -2
- package/esm/helpers/morphoMidnightHelpers/tenor.js +6 -2
- package/esm/markets/index.d.ts +1 -1
- package/esm/markets/index.js +1 -1
- package/esm/markets/morphoMidnight/index.d.ts +44 -10
- package/esm/markets/morphoMidnight/index.js +356 -58
- package/esm/morphoMidnight/index.js +11 -1
- package/esm/types/morphoMidnight.d.ts +35 -4
- package/esm/types/morphoMidnight.js +23 -0
- package/package.json +1 -1
- package/src/claiming/compV3.ts +0 -1
- package/src/config/contracts.ts +4 -0
- package/src/helpers/morphoMidnightHelpers/tenor.ts +6 -2
- package/src/markets/index.ts +1 -0
- package/src/markets/morphoMidnight/index.ts +446 -60
- package/src/morphoMidnight/index.ts +8 -1
- package/src/types/morphoMidnight.ts +37 -3
|
@@ -67,8 +67,13 @@ export function _getMorphoMidnightMarketData(provider, network, selectedMarket)
|
|
|
67
67
|
supplyIncentives: [],
|
|
68
68
|
borrowIncentives: [],
|
|
69
69
|
};
|
|
70
|
+
// `collaterals` is the full on-chain set, so `i` is the index `prices` is keyed by. Hidden entries
|
|
71
|
+
// (curator vaults, the loan token itself) are skipped rather than filtered out beforehand, which would
|
|
72
|
+
// shift every later collateral onto the wrong price.
|
|
70
73
|
const collateralSymbols = [];
|
|
71
74
|
collaterals.forEach((coll, i) => {
|
|
75
|
+
if (coll.hidden)
|
|
76
|
+
return;
|
|
72
77
|
const collInfo = getAssetInfoByAddress(coll.token, network);
|
|
73
78
|
const collSym = wethToEth(collInfo.symbol);
|
|
74
79
|
collateralSymbols.push(collSym);
|
|
@@ -131,8 +136,11 @@ export function _getMorphoMidnightAccountData(provider, network, account, select
|
|
|
131
136
|
suppliedUsd: new Dec(credit).mul(loanTokenData.price).toString(),
|
|
132
137
|
borrowedUsd: new Dec(debt).mul(loanTokenData.price).toString(),
|
|
133
138
|
};
|
|
134
|
-
// positionInfo.collateral is index-aligned with the market's collateral set (0 where
|
|
139
|
+
// positionInfo.collateral is index-aligned with the market's full on-chain collateral set (0 where
|
|
140
|
+
// unused), so hidden entries are skipped in place rather than filtered out first.
|
|
135
141
|
collaterals.forEach((coll, i) => {
|
|
142
|
+
if (coll.hidden)
|
|
143
|
+
return;
|
|
136
144
|
const collInfo = getAssetInfoByAddress(coll.token, network);
|
|
137
145
|
const collSym = wethToEth(collInfo.symbol);
|
|
138
146
|
const rawAmount = positionInfo.collateral[i] ? positionInfo.collateral[i].toString() : '0';
|
|
@@ -212,6 +220,8 @@ export const _getMorphoMidnightAccountBalances = (provider, network, block, addr
|
|
|
212
220
|
};
|
|
213
221
|
const collateral = {};
|
|
214
222
|
collaterals.forEach((coll, i) => {
|
|
223
|
+
if (coll.hidden)
|
|
224
|
+
return;
|
|
215
225
|
const collInfo = getAssetInfoByAddress(coll.token, network);
|
|
216
226
|
const rawAmount = positionInfo.collateral[i] ? positionInfo.collateral[i].toString() : '0';
|
|
217
227
|
collateral[addressMapping ? collInfo.address.toLowerCase() : wethToEth(collInfo.symbol)] = assetAmountInEth(rawAmount, wethToEth(collInfo.symbol));
|
|
@@ -31,7 +31,27 @@ export declare enum MorphoMidnightVersions {
|
|
|
31
31
|
MorphoMidnightTenorCbETHWETH_20261030_Base = "morphomidnighttenorcbethweth_20261030_base",
|
|
32
32
|
MorphoMidnightTenorCbETHWETH_20261127_Base = "morphomidnighttenorcbethweth_20261127_base",
|
|
33
33
|
MorphoMidnightTenorCbETHWETH_20261225_Base = "morphomidnighttenorcbethweth_20261225_base",
|
|
34
|
-
MorphoMidnightTenorCbETHWETH_20270129_Base = "morphomidnighttenorcbethweth_20270129_base"
|
|
34
|
+
MorphoMidnightTenorCbETHWETH_20270129_Base = "morphomidnighttenorcbethweth_20270129_base",
|
|
35
|
+
MorphoMidnightWBTCUSDC_860_20260925_Eth = "morphomidnightwbtcusdc_860_20260925_eth",
|
|
36
|
+
MorphoMidnightWBTCUSDC_860_20261030_Eth = "morphomidnightwbtcusdc_860_20261030_eth",
|
|
37
|
+
MorphoMidnightWBTCUSDC_860_20261127_Eth = "morphomidnightwbtcusdc_860_20261127_eth",
|
|
38
|
+
MorphoMidnightWBTCUSDC_860_20261225_Eth = "morphomidnightwbtcusdc_860_20261225_eth",
|
|
39
|
+
MorphoMidnightWBTCUSDC_860_20270129_Eth = "morphomidnightwbtcusdc_860_20270129_eth",
|
|
40
|
+
MorphoMidnightWBTCUSDC_860_20270226_Eth = "morphomidnightwbtcusdc_860_20270226_eth",
|
|
41
|
+
MorphoMidnightWBTCUSDC_860_20270326_Eth = "morphomidnightwbtcusdc_860_20270326_eth",
|
|
42
|
+
MorphoMidnightCbBTCUSDC_860_20260925_Eth = "morphomidnightcbbtcusdc_860_20260925_eth",
|
|
43
|
+
MorphoMidnightCbBTCUSDC_860_20261030_Eth = "morphomidnightcbbtcusdc_860_20261030_eth",
|
|
44
|
+
MorphoMidnightCbBTCUSDC_860_20261127_Eth = "morphomidnightcbbtcusdc_860_20261127_eth",
|
|
45
|
+
MorphoMidnightCbBTCUSDC_860_20261225_Eth = "morphomidnightcbbtcusdc_860_20261225_eth",
|
|
46
|
+
MorphoMidnightCbBTCUSDC_860_20270129_Eth = "morphomidnightcbbtcusdc_860_20270129_eth",
|
|
47
|
+
MorphoMidnightCbBTCUSDC_860_20270226_Eth = "morphomidnightcbbtcusdc_860_20270226_eth",
|
|
48
|
+
MorphoMidnightCbBTCUSDC_860_20270326_Eth = "morphomidnightcbbtcusdc_860_20270326_eth",
|
|
49
|
+
MorphoMidnightTenorWETHUSDC_20260925_Eth = "morphomidnighttenorwethusdc_20260925_eth",
|
|
50
|
+
MorphoMidnightTenorStrUSDUSDC_20260925_Eth = "morphomidnighttenorstrusdusdc_20260925_eth",
|
|
51
|
+
MorphoMidnightTenorWsrUSDUSDC_20260925_Eth = "morphomidnighttenorwsrusdusdc_20260925_eth",
|
|
52
|
+
MorphoMidnightTenorUSD3USDC_20260925_Eth = "morphomidnighttenorusd3usdc_20260925_eth",
|
|
53
|
+
MorphoMidnightTenorReUSDUSDC_20260925_Eth = "morphomidnighttenorreusdusdc_20260925_eth",
|
|
54
|
+
MorphoMidnightTenorSiUSDUSDC_20260925_Eth = "morphomidnighttenorsiusdusdc_20260925_eth"
|
|
35
55
|
}
|
|
36
56
|
export type MorphoMidnightCurator = 'Morpho' | 'Tenor';
|
|
37
57
|
export interface MorphoMidnightCollateralParams {
|
|
@@ -39,6 +59,13 @@ export interface MorphoMidnightCollateralParams {
|
|
|
39
59
|
lltv: number | string;
|
|
40
60
|
liquidationCursor: number | string;
|
|
41
61
|
oracle: EthAddress;
|
|
62
|
+
/**
|
|
63
|
+
* A collateral the market carries on-chain but the app never surfaces: a curator's own vault share
|
|
64
|
+
* token (Tenor's collateral vaults) or the loan token itself (Morpho's mainnet ladders list USDC at
|
|
65
|
+
* 98% next to the real collateral). It is not an asset the app deals in — nothing renders, prices or
|
|
66
|
+
* supplies it — but it stays in `collaterals` because the market id is the hash of the full set.
|
|
67
|
+
*/
|
|
68
|
+
hidden?: boolean;
|
|
42
69
|
}
|
|
43
70
|
export interface MorphoMidnightMarketData {
|
|
44
71
|
chainIds: NetworkNumber[];
|
|
@@ -48,11 +75,15 @@ export interface MorphoMidnightMarketData {
|
|
|
48
75
|
value: MorphoMidnightVersions;
|
|
49
76
|
midnight: EthAddress;
|
|
50
77
|
loanToken: EthAddress;
|
|
51
|
-
collaterals: MorphoMidnightCollateralParams[];
|
|
52
78
|
/**
|
|
53
|
-
*
|
|
79
|
+
* Every collateral the market carries on-chain, in the chain's own order — which is what the id is
|
|
80
|
+
* hashed from, so neither the set nor the order may be rearranged. Entries the app does not deal in
|
|
81
|
+
* are flagged `hidden` rather than kept in a second list: their on-chain position varies per market
|
|
82
|
+
* (Morpho's mainnet cbBTC ladder lists USDC first, its WBTC ladder second), so a separate list can
|
|
83
|
+
* only be re-joined by guessing, and every positional read — `MarketInfo.prices[i]`,
|
|
84
|
+
* `PositionInfo.collateral[i]`, the collateral index a supply call takes — indexes into *this* array.
|
|
54
85
|
*/
|
|
55
|
-
|
|
86
|
+
collaterals: MorphoMidnightCollateralParams[];
|
|
56
87
|
maturity: number;
|
|
57
88
|
rcfThreshold: number | string;
|
|
58
89
|
enterGate: EthAddress;
|
|
@@ -36,6 +36,29 @@ export var MorphoMidnightVersions;
|
|
|
36
36
|
MorphoMidnightVersions["MorphoMidnightTenorCbETHWETH_20261127_Base"] = "morphomidnighttenorcbethweth_20261127_base";
|
|
37
37
|
MorphoMidnightVersions["MorphoMidnightTenorCbETHWETH_20261225_Base"] = "morphomidnighttenorcbethweth_20261225_base";
|
|
38
38
|
MorphoMidnightVersions["MorphoMidnightTenorCbETHWETH_20270129_Base"] = "morphomidnighttenorcbethweth_20270129_base";
|
|
39
|
+
// ETHEREUM
|
|
40
|
+
// Sourced from the official listing at https://markets.morpho.org/fixed?chains=1
|
|
41
|
+
MorphoMidnightVersions["MorphoMidnightWBTCUSDC_860_20260925_Eth"] = "morphomidnightwbtcusdc_860_20260925_eth";
|
|
42
|
+
MorphoMidnightVersions["MorphoMidnightWBTCUSDC_860_20261030_Eth"] = "morphomidnightwbtcusdc_860_20261030_eth";
|
|
43
|
+
MorphoMidnightVersions["MorphoMidnightWBTCUSDC_860_20261127_Eth"] = "morphomidnightwbtcusdc_860_20261127_eth";
|
|
44
|
+
MorphoMidnightVersions["MorphoMidnightWBTCUSDC_860_20261225_Eth"] = "morphomidnightwbtcusdc_860_20261225_eth";
|
|
45
|
+
MorphoMidnightVersions["MorphoMidnightWBTCUSDC_860_20270129_Eth"] = "morphomidnightwbtcusdc_860_20270129_eth";
|
|
46
|
+
MorphoMidnightVersions["MorphoMidnightWBTCUSDC_860_20270226_Eth"] = "morphomidnightwbtcusdc_860_20270226_eth";
|
|
47
|
+
MorphoMidnightVersions["MorphoMidnightWBTCUSDC_860_20270326_Eth"] = "morphomidnightwbtcusdc_860_20270326_eth";
|
|
48
|
+
MorphoMidnightVersions["MorphoMidnightCbBTCUSDC_860_20260925_Eth"] = "morphomidnightcbbtcusdc_860_20260925_eth";
|
|
49
|
+
MorphoMidnightVersions["MorphoMidnightCbBTCUSDC_860_20261030_Eth"] = "morphomidnightcbbtcusdc_860_20261030_eth";
|
|
50
|
+
MorphoMidnightVersions["MorphoMidnightCbBTCUSDC_860_20261127_Eth"] = "morphomidnightcbbtcusdc_860_20261127_eth";
|
|
51
|
+
MorphoMidnightVersions["MorphoMidnightCbBTCUSDC_860_20261225_Eth"] = "morphomidnightcbbtcusdc_860_20261225_eth";
|
|
52
|
+
MorphoMidnightVersions["MorphoMidnightCbBTCUSDC_860_20270129_Eth"] = "morphomidnightcbbtcusdc_860_20270129_eth";
|
|
53
|
+
MorphoMidnightVersions["MorphoMidnightCbBTCUSDC_860_20270226_Eth"] = "morphomidnightcbbtcusdc_860_20270226_eth";
|
|
54
|
+
MorphoMidnightVersions["MorphoMidnightCbBTCUSDC_860_20270326_Eth"] = "morphomidnightcbbtcusdc_860_20270326_eth";
|
|
55
|
+
// Tenor-hosted Midnight markets (same core, different order book)
|
|
56
|
+
MorphoMidnightVersions["MorphoMidnightTenorWETHUSDC_20260925_Eth"] = "morphomidnighttenorwethusdc_20260925_eth";
|
|
57
|
+
MorphoMidnightVersions["MorphoMidnightTenorStrUSDUSDC_20260925_Eth"] = "morphomidnighttenorstrusdusdc_20260925_eth";
|
|
58
|
+
MorphoMidnightVersions["MorphoMidnightTenorWsrUSDUSDC_20260925_Eth"] = "morphomidnighttenorwsrusdusdc_20260925_eth";
|
|
59
|
+
MorphoMidnightVersions["MorphoMidnightTenorUSD3USDC_20260925_Eth"] = "morphomidnighttenorusd3usdc_20260925_eth";
|
|
60
|
+
MorphoMidnightVersions["MorphoMidnightTenorReUSDUSDC_20260925_Eth"] = "morphomidnighttenorreusdusdc_20260925_eth";
|
|
61
|
+
MorphoMidnightVersions["MorphoMidnightTenorSiUSDUSDC_20260925_Eth"] = "morphomidnighttenorsiusdusdc_20260925_eth";
|
|
39
62
|
})(MorphoMidnightVersions || (MorphoMidnightVersions = {}));
|
|
40
63
|
/**
|
|
41
64
|
* How much weight `borrowRate` / `debtBase` / `debtInterest` carry on a given position. They fall back to
|
package/package.json
CHANGED
package/src/claiming/compV3.ts
CHANGED
|
@@ -9,7 +9,6 @@ import { ClaimType } from '../types/claiming';
|
|
|
9
9
|
// Not decodable by name, since the error lives in CometRewards' ABI and we call through CompV3View.
|
|
10
10
|
const NOT_SUPPORTED_ERROR_SIG = '0x9c58e3b6';
|
|
11
11
|
|
|
12
|
-
// Only an actual on-chain revert counts - viem reports transport failures as ContractFunctionExecutionError too.
|
|
13
12
|
const isMarketWithoutRewardsConfig = (err: unknown) => {
|
|
14
13
|
if (!(err instanceof BaseError)) return false;
|
|
15
14
|
const revert = err.walk((e) => e instanceof ContractFunctionRevertedError);
|
package/src/config/contracts.ts
CHANGED
|
@@ -1128,6 +1128,10 @@ export const MorphoBlueView = {
|
|
|
1128
1128
|
export const MidnightView = {
|
|
1129
1129
|
"abi": [{"inputs":[{"internalType":"bytes32","name":"_id","type":"bytes32"}],"name":"getMarketInfo","outputs":[{"components":[{"internalType":"bytes32","name":"id","type":"bytes32"},{"internalType":"uint128","name":"totalUnits","type":"uint128"},{"internalType":"uint128","name":"lossFactor","type":"uint128"},{"internalType":"uint128","name":"withdrawable","type":"uint128"},{"internalType":"uint128","name":"continuousFeeCredit","type":"uint128"},{"internalType":"uint16[7]","name":"settlementFees","type":"uint16[7]"},{"internalType":"uint32","name":"continuousFee","type":"uint32"},{"internalType":"uint8","name":"tickSpacing","type":"uint8"},{"internalType":"uint256[]","name":"prices","type":"uint256[]"}],"internalType":"struct MidnightView.MarketInfo","name":"info","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_id","type":"bytes32"},{"internalType":"address","name":"_user","type":"address"}],"name":"getPositionInfo","outputs":[{"components":[{"internalType":"uint128","name":"credit","type":"uint128"},{"internalType":"uint128","name":"pendingFee","type":"uint128"},{"internalType":"uint128","name":"debt","type":"uint128"},{"internalType":"uint128","name":"collateralBitmap","type":"uint128"},{"internalType":"uint128[]","name":"collateral","type":"uint128[]"},{"internalType":"uint256","name":"ratio","type":"uint256"}],"internalType":"struct MidnightView.PositionInfo","name":"pos","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_id","type":"bytes32"},{"internalType":"address","name":"_user","type":"address"}],"name":"getRatio","outputs":[{"internalType":"uint256","name":"ratio","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"address","name":"midnight","type":"address"},{"internalType":"address","name":"loanToken","type":"address"},{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"},{"internalType":"uint256","name":"liquidationCursor","type":"uint256"},{"internalType":"address","name":"oracle","type":"address"}],"internalType":"struct CollateralParams[]","name":"collateralParams","type":"tuple[]"},{"internalType":"uint256","name":"maturity","type":"uint256"},{"internalType":"uint256","name":"rcfThreshold","type":"uint256"},{"internalType":"address","name":"enterGate","type":"address"},{"internalType":"address","name":"liquidatorGate","type":"address"}],"internalType":"struct Market","name":"_market","type":"tuple"}],"name":"toId","outputs":[{"internalType":"bytes32","name":"id","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_id","type":"bytes32"}],"name":"toMarket","outputs":[{"components":[{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"address","name":"midnight","type":"address"},{"internalType":"address","name":"loanToken","type":"address"},{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"},{"internalType":"uint256","name":"liquidationCursor","type":"uint256"},{"internalType":"address","name":"oracle","type":"address"}],"internalType":"struct CollateralParams[]","name":"collateralParams","type":"tuple[]"},{"internalType":"uint256","name":"maturity","type":"uint256"},{"internalType":"uint256","name":"rcfThreshold","type":"uint256"},{"internalType":"address","name":"enterGate","type":"address"},{"internalType":"address","name":"liquidatorGate","type":"address"}],"internalType":"struct Market","name":"market","type":"tuple"}],"stateMutability":"view","type":"function"}],
|
|
1130
1130
|
"networks": {
|
|
1131
|
+
"1": {
|
|
1132
|
+
"address": "0xB64FBf011343961D9AC4A04b714414E35ebE6BE0",
|
|
1133
|
+
"createdBlock": 25938908,
|
|
1134
|
+
},
|
|
1131
1135
|
"8453": {
|
|
1132
1136
|
"address": "0x3aa272f329E8B562A3bA56Bb6979a44D23A28839",
|
|
1133
1137
|
"createdBlock": 48932293,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
MorphoMidnightParsedBook,
|
|
9
9
|
NetworkNumber,
|
|
10
10
|
} from '../../types';
|
|
11
|
-
import { isTenorMidnightMarket,
|
|
11
|
+
import { isTenorMidnightMarket, midnightCoreAddress } from '../../markets/morphoMidnight';
|
|
12
12
|
import type {
|
|
13
13
|
MorphoMidnightBorrowQuote,
|
|
14
14
|
MorphoMidnightPaybackQuote,
|
|
@@ -83,11 +83,15 @@ interface TenorOfferFill {
|
|
|
83
83
|
/**
|
|
84
84
|
* Tenor's offer JSON is flat (market fields live on the offer). Morpho's is nested, and that nested
|
|
85
85
|
* shape is what the app encodes for `Midnight.take`. Map Tenor into that shape so recipes stay on one encoder.
|
|
86
|
+
*
|
|
87
|
+
* The core address is the one field Tenor's offer does not carry, so it is derived from the offer's own
|
|
88
|
+
* `chain_id` rather than the caller's network — an offer names the chain it was made on, and taking it
|
|
89
|
+
* against another chain's core would address a market that does not exist.
|
|
86
90
|
*/
|
|
87
91
|
export const tenorOfferToApiOffer = (offer: TenorOffer) => ({
|
|
88
92
|
market: {
|
|
89
93
|
chain_id: offer.chain_id,
|
|
90
|
-
midnight:
|
|
94
|
+
midnight: midnightCoreAddress(Number(offer.chain_id) as NetworkNumber),
|
|
91
95
|
loan_token: offer.loan_token_address,
|
|
92
96
|
collaterals: offer.collaterals || [],
|
|
93
97
|
maturity: offer.maturity,
|
package/src/markets/index.ts
CHANGED
|
@@ -19,6 +19,7 @@ export { CrvUsdMarkets } from './curveUsd';
|
|
|
19
19
|
export { MorphoBlueMarkets, findMorphoBlueMarket } from './morphoBlue';
|
|
20
20
|
export {
|
|
21
21
|
MorphoMidnightMarkets, findMorphoMidnightMarket, isTenorMidnightMarket, morphoMidnightMarketCollateralParams,
|
|
22
|
+
morphoMidnightVisibleCollaterals,
|
|
22
23
|
} from './morphoMidnight';
|
|
23
24
|
export { LlamaLendMarkets } from './llamaLend';
|
|
24
25
|
export { LiquityV2Markets, findLiquityV2MarketByAddress } from './liquityV2';
|