@1delta/margin-fetcher 0.0.180 → 0.0.182
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/README.md +197 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +61 -34
- package/dist/index.js.map +1 -1
- package/dist/lending/public-data/compound-v2/convert/sumer.d.ts +1 -1
- package/dist/lending/public-data/fetchLenderAll.d.ts +1 -1
- package/dist/lending/public-data/fetchLenderAll.d.ts.map +1 -1
- package/dist/lending/public-data/fetchLenderExt.d.ts +1 -1
- package/dist/lending/public-data/fetchLenderExt.d.ts.map +1 -1
- package/dist/lending/public-data/morpho/convertPublic.d.ts.map +1 -1
- package/dist/lending/public-data/morpho/fetchPublic.d.ts +2 -2
- package/dist/lending/public-data/morpho/fetchPublic.d.ts.map +1 -1
- package/dist/lending/user-data/morpho/userCallParse.d.ts.map +1 -1
- package/dist/lending/user-data/utils/createEulerMultiAccountTypeUserState.d.ts.map +1 -1
- package/dist/lending/user-data/utils/createGeneralUserState.d.ts +1 -1
- package/dist/lending/user-data/utils/createGeneralUserState.d.ts.map +1 -1
- package/dist/lending/user-data/utils/createMultiAccountStyleUserState.d.ts.map +1 -1
- package/dist/lending/user-data/utils/createSumerUserState.d.ts.map +1 -1
- package/dist/lending/user-data/utils/types.d.ts +8 -1
- package/dist/lending/user-data/utils/types.d.ts.map +1 -1
- package/dist/types/apiReturnType.d.ts +1 -1
- package/dist/types/lender/aave-v3-types.d.ts +1 -1
- package/dist/types/lender/compound-v2-types.d.ts +1 -1
- package/dist/types/lender/init-types.d.ts +1 -1
- package/dist/types/lender/morpho-types.d.ts +3 -0
- package/dist/types/lender/morpho-types.d.ts.map +1 -1
- package/dist/types/lenderTypes.d.ts +6 -0
- package/dist/types/lenderTypes.d.ts.map +1 -1
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# @1delta/margin-fetcher
|
|
2
|
+
|
|
3
|
+
Multi-protocol lending data fetcher supporting Morpho Blue, Aave V2/V3, Compound V2/V3, Euler, Init, and Lista DAO. Provides public market data (rates, TVL, configs) and per-user position data (balances, shares, collateral) in a unified format.
|
|
4
|
+
|
|
5
|
+
## How Morpho Blue Works
|
|
6
|
+
|
|
7
|
+
### Protocol overview
|
|
8
|
+
|
|
9
|
+
Morpho Blue is an **isolated-market** lending protocol. Unlike pooled protocols (Aave, Compound) where all assets share a single pool, each Morpho market is a **standalone pair** defined by five parameters:
|
|
10
|
+
|
|
11
|
+
| Parameter | Description |
|
|
12
|
+
|-----------|-------------|
|
|
13
|
+
| `loanToken` | The asset that can be supplied and borrowed |
|
|
14
|
+
| `collateralToken` | The asset deposited as collateral |
|
|
15
|
+
| `oracle` | Price oracle for the pair |
|
|
16
|
+
| `irm` | Interest Rate Model contract |
|
|
17
|
+
| `lltv` | Liquidation Loan-To-Value ratio (18-decimal WAD) |
|
|
18
|
+
|
|
19
|
+
These five parameters are hashed into a `uniqueKey` (bytes32) that identifies the market on-chain.
|
|
20
|
+
|
|
21
|
+
### Interest rate model
|
|
22
|
+
|
|
23
|
+
Morpho uses an **adaptive curve IRM** that adjusts rates based on utilization relative to a 90% target:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
utilization = totalBorrowAssets / totalSupplyAssets
|
|
27
|
+
|
|
28
|
+
If utilization > 90%: rateAtTarget increases over time (via exponential adjustment)
|
|
29
|
+
If utilization < 90%: rateAtTarget decreases over time
|
|
30
|
+
|
|
31
|
+
borrowRate = curve(rateAtTarget, utilization)
|
|
32
|
+
supplyRate = borrowRate * utilization * (1 - fee)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The curve uses a steepness factor of 4x, meaning at full utilization the rate is 4x the rate-at-target. Rates are stored as per-second WAD values and compounded continuously.
|
|
36
|
+
|
|
37
|
+
Key constants:
|
|
38
|
+
- **Target utilization**: 90%
|
|
39
|
+
- **Curve steepness**: 4x
|
|
40
|
+
- **Min rate at target**: ~0.1% APY
|
|
41
|
+
- **Max rate at target**: ~200% APY
|
|
42
|
+
- **Adjustment speed**: 50x/year (exponential)
|
|
43
|
+
|
|
44
|
+
### Share-based accounting
|
|
45
|
+
|
|
46
|
+
Positions are tracked via **shares** rather than raw assets. This allows interest to accrue without storage updates per-user:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
assets = shares * (totalAssets + 1) / (totalShares + VIRTUAL_SHARES)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Where `VIRTUAL_SHARES = 1e6` prevents share inflation attacks.
|
|
53
|
+
|
|
54
|
+
### Market data representation
|
|
55
|
+
|
|
56
|
+
Each Morpho market produces **two entries** in the normalized output:
|
|
57
|
+
|
|
58
|
+
1. **Loan entry** — the borrowable asset
|
|
59
|
+
- Has `borrowingEnabled: true`, `collateralActive: false`
|
|
60
|
+
- Contains deposit/borrow APRs, total supply/debt, liquidity
|
|
61
|
+
- Rewards (MORPHO token incentives) attached here
|
|
62
|
+
|
|
63
|
+
2. **Collateral entry** — the collateral asset
|
|
64
|
+
- Has `borrowingEnabled: false`, `collateralActive: true`
|
|
65
|
+
- LTV factors derived from the market's `lltv`
|
|
66
|
+
- No interest rates (collateral doesn't earn yield in Morpho)
|
|
67
|
+
|
|
68
|
+
### Whitelisted vs unlisted markets
|
|
69
|
+
|
|
70
|
+
Morpho markets can be **whitelisted** (curated, visible in the Morpho UI) or **unlisted** (removed from curation). The `includeUnlistedMorphoMarkets` flag controls whether unlisted markets are fetched from the API. Unlisted markets are tagged with `isListed: false` on the `MorphoMarket` params.
|
|
71
|
+
|
|
72
|
+
## Architecture
|
|
73
|
+
|
|
74
|
+
### Data fetching strategy
|
|
75
|
+
|
|
76
|
+
The fetcher uses a **hybrid approach** that routes each lender to either an API or on-chain path:
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
getLenderPublicDataAll(chainId, lenders, ...)
|
|
80
|
+
├── lenderCanUseApi(lender, chainId)?
|
|
81
|
+
│ ├── YES → getLenderPublicDataViaApi() → Morpho GraphQL API
|
|
82
|
+
│ └── NO → getLenderPublicData() → On-chain multicall via Morpho Lens
|
|
83
|
+
└── Promise.all([onChain, api]) → merged result
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**Morpho Blue uses the API** on most chains. On-chain fallback is used for chains without API support (OP Mainnet, Soneium, Hemi, Berachain, Sei).
|
|
87
|
+
|
|
88
|
+
### API path (GraphQL)
|
|
89
|
+
|
|
90
|
+
Fetches from `https://blue-api.morpho.org/graphql`:
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
fetchMorphoMarkets(chainId, includeUnlisted)
|
|
94
|
+
→ GraphQL query (paginated: 200/page, 2 pages for Ethereum mainnet)
|
|
95
|
+
→ GetMarketsResponse
|
|
96
|
+
→ convertMarketsToMorphoResponse()
|
|
97
|
+
→ { [marketId]: MorphoGeneralPublicResponse }
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The API provides pre-computed APYs, USD values, and reward data. APY→APR conversion is applied during normalization.
|
|
101
|
+
|
|
102
|
+
### On-chain path (Morpho Lens)
|
|
103
|
+
|
|
104
|
+
Uses a custom lens contract that returns compact binary-encoded market data:
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
buildMorphoCall(chainId)
|
|
108
|
+
→ multicall to MORPHO_LENS.getMarketDataCompact(morpho, marketHashes[])
|
|
109
|
+
→ chunks of 50 markets per call (calldata size limit)
|
|
110
|
+
→ raw bytes response
|
|
111
|
+
|
|
112
|
+
getMorphoMarketDataConverter()
|
|
113
|
+
→ decodeMarkets(bytes) // 256-byte records → Market[]
|
|
114
|
+
→ MathLib.getBorrowApy(...) // compute rates from rateAtTarget + utilization
|
|
115
|
+
→ MathLib.getSupplyApy(...)
|
|
116
|
+
→ { [marketId]: MorphoGeneralPublicResponse }
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
#### Binary encoding (256 bytes per market)
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
Offset Size Field
|
|
123
|
+
0 20 loanToken (address)
|
|
124
|
+
20 20 collateralToken (address)
|
|
125
|
+
40 20 oracle (address)
|
|
126
|
+
60 20 irm (address)
|
|
127
|
+
80 16 lltv (uint128)
|
|
128
|
+
96 32 price (uint256) — collateral/loan exchange rate in WAD
|
|
129
|
+
128 32 rateAtTarget (uint256) — per-second interest rate
|
|
130
|
+
160 16 totalSupplyAssets (uint128)
|
|
131
|
+
176 16 totalSupplyShares (uint128)
|
|
132
|
+
192 16 totalBorrowAssets (uint128)
|
|
133
|
+
208 16 totalBorrowShares (uint128)
|
|
134
|
+
224 16 lastUpdate (uint128) — timestamp
|
|
135
|
+
240 16 fee (uint128)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### User data path
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
buildMorphoUserCallWithLens(chainId, account, lender, marketIds)
|
|
142
|
+
→ MORPHO_LENS.getUserDataCompact(marketHashes[], account, morpho)
|
|
143
|
+
→ chunks of 100 markets per call
|
|
144
|
+
|
|
145
|
+
decodePackedMorphoUserDataset(hex)
|
|
146
|
+
→ [uint16 count] + [130-byte records × count]
|
|
147
|
+
→ BalanceInfo[] { index, supplyShares, borrowShares, supplyAssets, borrowAssets, collateral }
|
|
148
|
+
|
|
149
|
+
getMorphoUserDataConverterWithLens()
|
|
150
|
+
→ map balances to market IDs via index
|
|
151
|
+
→ separate loan positions (supply/borrow) from collateral positions
|
|
152
|
+
→ format to UserData with USD values
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## File structure
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
src/lending/
|
|
159
|
+
├── public-data/
|
|
160
|
+
│ ├── fetchLenderAll.ts # Hybrid router (API vs on-chain)
|
|
161
|
+
│ ├── fetchLender.ts # On-chain multicall dispatcher
|
|
162
|
+
│ ├── fetchLenderExt.ts # API dispatcher
|
|
163
|
+
│ └── morpho/
|
|
164
|
+
│ ├── fetchPublic.ts # GraphQL query + fetch logic
|
|
165
|
+
│ ├── convertPublic.ts # API response → normalized format
|
|
166
|
+
│ ├── publicCallBuild.ts # Morpho Lens call builder
|
|
167
|
+
│ ├── getMarketsFromChain.ts # On-chain response → normalized format
|
|
168
|
+
│ └── utils/
|
|
169
|
+
│ ├── evmParser.ts # Binary decoder (256-byte records)
|
|
170
|
+
│ ├── mathLib.ts # WAD math, rate calculations
|
|
171
|
+
│ └── parsers.ts # LTV parsing, number formatting
|
|
172
|
+
├── user-data/
|
|
173
|
+
│ └── morpho/
|
|
174
|
+
│ ├── userCallBuild.ts # User position call builder
|
|
175
|
+
│ ├── decoder.ts # User data binary decoder
|
|
176
|
+
│ ├── userCallParse.ts # Balance → UserData conversion
|
|
177
|
+
│ ├── morphoLib.ts # Share ↔ asset conversion
|
|
178
|
+
│ └── types.ts # Parameter position enums
|
|
179
|
+
└── ...
|
|
180
|
+
|
|
181
|
+
src/types/lender/
|
|
182
|
+
└── morpho-types.ts # GetMarketsResponse, MorphoMarket, MorphoGeneralPublicResponse
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Lista DAO extension
|
|
186
|
+
|
|
187
|
+
Lista is a Morpho Blue fork with additional per-market fields. Uses a 357-byte binary record instead of 256:
|
|
188
|
+
|
|
189
|
+
| Extra field | Type | Description |
|
|
190
|
+
|-------------|------|-------------|
|
|
191
|
+
| `minLoan` | uint128 | Minimum loan amount |
|
|
192
|
+
| `hasWhitelist` | bool | Whether the market has access control |
|
|
193
|
+
| `loanProvider` | address | Yield source for loan token |
|
|
194
|
+
| `collateralProvider` | address | Yield source for collateral |
|
|
195
|
+
| `broker` | address | Authorized broker contract |
|
|
196
|
+
|
|
197
|
+
User data also includes per-market whitelist flags prepended before the balance records.
|
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export type { SumerPositionInput, GroupAccumulator, } from './lending/margin/bas
|
|
|
16
16
|
export type { LenderYieldComplete, LenderCrossPoolMeta, LenderToLenderCrossPoolMeta, CompoundV2Metadata, AaveMetadata, InitMetadata, EulerV2Metadata, ProtocolParams, } from './lending/user-data/utils/types';
|
|
17
17
|
export { computeSumerWaterfall, buildSumerAccumulators, applyPositionDelta, } from './lending/margin/base/sumer/waterfall';
|
|
18
18
|
export { computeSumerDepositDelta, computeSumerWithdrawDelta, computeSumerBorrowDelta, computeSumerRepayDelta, } from './lending/margin/base/sumer';
|
|
19
|
+
export { fetchEulerSubAccountIndexes, getSubAccountAddress, getSubAccountIndex, } from './lending/user-data/euler/userCallBuild';
|
|
19
20
|
export { MorphoLensAbi } from '@1delta/abis';
|
|
20
21
|
export { type PreparedCall, type RawRpcCall, type RawRpcBatch, type MulticallRpcBatch, createRawRpcCalls, createMulticallRpcCall, multicall3Abi, } from './utils/rpcCall';
|
|
21
22
|
export { type RawRpcResponse, parseRawRpcResponses, parseRawRpcBatchResponses, parseMulticallRpcResponses, } from './utils/rpcParse';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EACzB,sBAAsB,EACtB,uBAAuB,EACvB,2BAA2B,EAC3B,6BAA6B,EAC7B,KAAK,wBAAwB,EAC7B,qBAAqB,EACrB,iBAAiB,EACjB,KAAK,sBAAsB,EAC3B,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,4BAA4B,EAC5B,KAAK,6BAA6B,EAClC,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,sBAAsB,EACtB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,WAAW,EACX,6BAA6B,EAC7B,4BAA4B,EAC5B,mBAAmB,EACnB,+BAA+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yBAAyB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,4BAA4B,GAClC,MAAM,SAAS,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parseAbi, formatEther, BaseError, encodeFunctionData, formatUnits, decodeFunctionResult, decodeAbiParameters, AbiEncodingLengthMismatchError, concatHex, isAddress, InvalidAddressError, pad, stringToHex, boolToHex, integerRegex, numberToHex, bytesRegex, BytesSizeMismatchError, arrayRegex, UnsupportedPackedAbiType } from './chunk-ZVIJSUIM.js';
|
|
2
2
|
import './chunk-BYTNVMX7.js';
|
|
3
3
|
import './chunk-PR4QN5HX.js';
|
|
4
|
-
import { Lender, isAaveType, isCompoundV3, isMultiMarket, isInit, isCompoundV2Type, isVenusType,
|
|
4
|
+
import { Lender, isAaveType, isCompoundV3, isMultiMarket, isInit, isMorphoType, isCompoundV2Type, isVenusType, isSumerType, AAVE_V3_LENDERS, AAVE_V2_LENDERS, isAaveV2Type, isAaveV32Type, isAaveV3Type, isEulerType, isYLDR, isCompoundV3Type, isTectonicType, isBenqiType, isLista } from '@1delta/lender-registry';
|
|
5
5
|
export { isAaveType, isAaveV2Type, isAaveV32Type, isAaveV3Type, isCompoundV3, isCompoundV3Type, isInit, isMorphoType, isMultiMarket, isYLDR } from '@1delta/lender-registry';
|
|
6
6
|
import lodash from 'lodash';
|
|
7
7
|
import { getEvmChain, multicallRetry, getEvmClient, getEvmClientUniversal } from '@1delta/providers';
|
|
@@ -10909,7 +10909,7 @@ var apyToApr2 = (apy) => {
|
|
|
10909
10909
|
|
|
10910
10910
|
// src/lending/user-data/utils/oraclePrice.ts
|
|
10911
10911
|
function getOraclePrice(meta) {
|
|
10912
|
-
const oracleUSD = meta?.oraclePrice?.
|
|
10912
|
+
const oracleUSD = meta?.oraclePrice?.oraclePriceUsd;
|
|
10913
10913
|
if (oracleUSD != null && oracleUSD > 0) return oracleUSD;
|
|
10914
10914
|
return meta?.price?.priceUsd ?? 1;
|
|
10915
10915
|
}
|
|
@@ -10918,12 +10918,19 @@ function getDisplayPrice(meta) {
|
|
|
10918
10918
|
}
|
|
10919
10919
|
|
|
10920
10920
|
// src/lending/user-data/utils/types.ts
|
|
10921
|
+
function buildUnderlyingInfo(meta) {
|
|
10922
|
+
return {
|
|
10923
|
+
asset: meta.asset,
|
|
10924
|
+
oraclePrice: meta.oraclePrice,
|
|
10925
|
+
prices: meta.price
|
|
10926
|
+
};
|
|
10927
|
+
}
|
|
10921
10928
|
function getMarketUidsFromMeta(meta) {
|
|
10922
10929
|
return Object.keys(meta);
|
|
10923
10930
|
}
|
|
10924
10931
|
|
|
10925
10932
|
// src/lending/user-data/utils/createGeneralUserState.ts
|
|
10926
|
-
function createBaseTypeUserState(payload, lenderData, totalDeposits24h = 0, totalDebt24h = 0) {
|
|
10933
|
+
function createBaseTypeUserState(payload, lenderData, totalDeposits24h = 0, totalDebt24h = 0, lender) {
|
|
10927
10934
|
let assetKeys = getMarketUidsFromMeta(lenderData);
|
|
10928
10935
|
const { chainId, account } = payload;
|
|
10929
10936
|
const mode = String(payload.userEMode ?? 0);
|
|
@@ -11043,7 +11050,8 @@ function createBaseTypeUserState(payload, lenderData, totalDeposits24h = 0, tota
|
|
|
11043
11050
|
Math.min(withdrawableUSD / price, Number(pos.deposits))
|
|
11044
11051
|
);
|
|
11045
11052
|
}
|
|
11046
|
-
|
|
11053
|
+
const isCollateralOnlyMorpho = lender && isMorphoType(lender) && !flags?.borrowingEnabled;
|
|
11054
|
+
if (withdrawLiquidity != null && !isCollateralOnlyMorpho) {
|
|
11047
11055
|
withdrawable = String(Math.min(Number(withdrawable), withdrawLiquidity));
|
|
11048
11056
|
}
|
|
11049
11057
|
let borrowable;
|
|
@@ -11058,6 +11066,7 @@ function createBaseTypeUserState(payload, lenderData, totalDeposits24h = 0, tota
|
|
|
11058
11066
|
}
|
|
11059
11067
|
pos.withdrawable = withdrawable;
|
|
11060
11068
|
pos.borrowable = borrowable;
|
|
11069
|
+
pos.underlyingInfo = buildUnderlyingInfo(lenderData[marketUid]);
|
|
11061
11070
|
} else if ((deposits > 0 || debt > 0) && flags?.borrowingEnabled && !flags?.isFrozen && !config?.debtDisabled) {
|
|
11062
11071
|
let borrowable = String(Math.max(creditLine / bf, 0) / price);
|
|
11063
11072
|
if (borrowLiquidity != null) {
|
|
@@ -11074,7 +11083,8 @@ function createBaseTypeUserState(payload, lenderData, totalDeposits24h = 0, tota
|
|
|
11074
11083
|
collateralEnabled: false,
|
|
11075
11084
|
claimableRewards: 0,
|
|
11076
11085
|
withdrawable: "0",
|
|
11077
|
-
borrowable
|
|
11086
|
+
borrowable,
|
|
11087
|
+
underlyingInfo: buildUnderlyingInfo(lenderData[marketUid])
|
|
11078
11088
|
};
|
|
11079
11089
|
}
|
|
11080
11090
|
}
|
|
@@ -11814,6 +11824,7 @@ function createSumerUserState(payload, lenderData, totalDeposits24h = 0, totalDe
|
|
|
11814
11824
|
}
|
|
11815
11825
|
pos.withdrawable = withdrawable;
|
|
11816
11826
|
pos.borrowable = borrowable;
|
|
11827
|
+
pos.underlyingInfo = buildUnderlyingInfo(lenderData[marketUid]);
|
|
11817
11828
|
} else if ((deposits > 0 || debt > 0) && flags?.borrowingEnabled && !flags?.isFrozen && !config?.debtDisabled) {
|
|
11818
11829
|
let borrowable = String(Math.max(creditLine / bf, 0) / price);
|
|
11819
11830
|
if (borrowLiquidity != null) {
|
|
@@ -11830,7 +11841,8 @@ function createSumerUserState(payload, lenderData, totalDeposits24h = 0, totalDe
|
|
|
11830
11841
|
collateralEnabled: false,
|
|
11831
11842
|
claimableRewards: 0,
|
|
11832
11843
|
withdrawable: "0",
|
|
11833
|
-
borrowable
|
|
11844
|
+
borrowable,
|
|
11845
|
+
underlyingInfo: buildUnderlyingInfo(lenderData[marketUid])
|
|
11834
11846
|
};
|
|
11835
11847
|
}
|
|
11836
11848
|
}
|
|
@@ -11969,6 +11981,7 @@ function createMultiAccountTypeUserState(payload, lenderData, histData) {
|
|
|
11969
11981
|
}
|
|
11970
11982
|
pos.withdrawable = withdrawable;
|
|
11971
11983
|
pos.borrowable = borrowable;
|
|
11984
|
+
pos.underlyingInfo = buildUnderlyingInfo(lenderData[marketUid]);
|
|
11972
11985
|
} else if ((deposits > 0 || debt > 0) && flags?.borrowingEnabled && !flags?.isFrozen && !config?.debtDisabled) {
|
|
11973
11986
|
let borrowable = String(Math.max(creditLine / bf, 0) / price);
|
|
11974
11987
|
if (borrowLiquidity != null) {
|
|
@@ -11983,7 +11996,8 @@ function createMultiAccountTypeUserState(payload, lenderData, histData) {
|
|
|
11983
11996
|
collateralEnabled: false,
|
|
11984
11997
|
claimableRewards: 0,
|
|
11985
11998
|
withdrawable: "0",
|
|
11986
|
-
borrowable
|
|
11999
|
+
borrowable,
|
|
12000
|
+
underlyingInfo: buildUnderlyingInfo(lenderData[marketUid])
|
|
11987
12001
|
};
|
|
11988
12002
|
}
|
|
11989
12003
|
}
|
|
@@ -12072,9 +12086,10 @@ function convertMarketsToMorphoResponse(response, chainId, additionalYields = {
|
|
|
12072
12086
|
oracleAddress,
|
|
12073
12087
|
loanAsset,
|
|
12074
12088
|
collateralAsset,
|
|
12075
|
-
state
|
|
12089
|
+
state,
|
|
12090
|
+
whitelisted
|
|
12076
12091
|
} = market;
|
|
12077
|
-
if (collateralAsset && loanAsset && oracleAddress && oracleAddress !== zeroAddress) {
|
|
12092
|
+
if (collateralAsset && collateralAsset.symbol && loanAsset && loanAsset.symbol && oracleAddress && oracleAddress !== zeroAddress) {
|
|
12078
12093
|
const m = "MORPHO_BLUE_" + uniqueKey.slice(2).toUpperCase();
|
|
12079
12094
|
if (!data[m]) data[m] = { data: {} };
|
|
12080
12095
|
const loanRewards = [];
|
|
@@ -12187,7 +12202,8 @@ function convertMarketsToMorphoResponse(response, chainId, additionalYields = {
|
|
|
12187
12202
|
oracle: oracleAddress,
|
|
12188
12203
|
irm: irmAddress,
|
|
12189
12204
|
collateralAddress: collateralAssetAddress,
|
|
12190
|
-
loanAddress: loanAssetAddress
|
|
12205
|
+
loanAddress: loanAssetAddress,
|
|
12206
|
+
isListed: whitelisted
|
|
12191
12207
|
}
|
|
12192
12208
|
};
|
|
12193
12209
|
data[m].chainId = chainId;
|
|
@@ -12197,13 +12213,12 @@ function convertMarketsToMorphoResponse(response, chainId, additionalYields = {
|
|
|
12197
12213
|
}
|
|
12198
12214
|
|
|
12199
12215
|
// src/lending/public-data/morpho/fetchPublic.ts
|
|
12200
|
-
var query = (first, skip, chainId) => `
|
|
12216
|
+
var query = (first, skip, chainId, includeUnlisted = false) => `
|
|
12201
12217
|
query GetMarkets {
|
|
12202
12218
|
markets(first: ${first}, skip: ${skip}, where: {
|
|
12203
|
-
chainId_in: [${chainId}]
|
|
12204
|
-
whitelisted: true
|
|
12219
|
+
chainId_in: [${chainId}]${includeUnlisted ? "" : ",\n whitelisted: true"}
|
|
12205
12220
|
},
|
|
12206
|
-
orderBy: SupplyAssetsUsd,
|
|
12221
|
+
orderBy: SupplyAssetsUsd,
|
|
12207
12222
|
orderDirection: Desc
|
|
12208
12223
|
) {
|
|
12209
12224
|
items {
|
|
@@ -12211,6 +12226,7 @@ query GetMarkets {
|
|
|
12211
12226
|
irmAddress
|
|
12212
12227
|
oracleAddress
|
|
12213
12228
|
lltv
|
|
12229
|
+
whitelisted
|
|
12214
12230
|
loanAsset {
|
|
12215
12231
|
address
|
|
12216
12232
|
name
|
|
@@ -12248,10 +12264,10 @@ query GetMarkets {
|
|
|
12248
12264
|
}
|
|
12249
12265
|
`;
|
|
12250
12266
|
var BASE_URL = "https://blue-api.morpho.org/graphql";
|
|
12251
|
-
async function fetchMorphoMarkets(chainId) {
|
|
12267
|
+
async function fetchMorphoMarkets(chainId, includeUnlisted = false) {
|
|
12252
12268
|
if (chainId !== Chain.ETHEREUM_MAINNET) {
|
|
12253
12269
|
const requestBody = {
|
|
12254
|
-
query: query(200, 0, chainId),
|
|
12270
|
+
query: query(200, 0, chainId, includeUnlisted),
|
|
12255
12271
|
variables: {}
|
|
12256
12272
|
};
|
|
12257
12273
|
const response = await fetch(BASE_URL, {
|
|
@@ -12270,11 +12286,11 @@ async function fetchMorphoMarkets(chainId) {
|
|
|
12270
12286
|
return data.data;
|
|
12271
12287
|
}
|
|
12272
12288
|
const requestBody0 = {
|
|
12273
|
-
query: query(200, 0, chainId),
|
|
12289
|
+
query: query(200, 0, chainId, includeUnlisted),
|
|
12274
12290
|
variables: {}
|
|
12275
12291
|
};
|
|
12276
12292
|
const requestBody1 = {
|
|
12277
|
-
query: query(200, 200, chainId),
|
|
12293
|
+
query: query(200, 200, chainId, includeUnlisted),
|
|
12278
12294
|
variables: {}
|
|
12279
12295
|
};
|
|
12280
12296
|
const [data0, data1] = await Promise.all([
|
|
@@ -17954,8 +17970,8 @@ var getLenderPublicData = async (chainId, lenders, prices, additionalYields, mul
|
|
|
17954
17970
|
}
|
|
17955
17971
|
return lenderData;
|
|
17956
17972
|
};
|
|
17957
|
-
async function getLenderDataFromApi(lender, chainId, prices, additionalYields) {
|
|
17958
|
-
if (isMorphoType(lender)) return await fetchMorphoMarkets(chainId);
|
|
17973
|
+
async function getLenderDataFromApi(lender, chainId, prices, additionalYields, includeUnlisted = false) {
|
|
17974
|
+
if (isMorphoType(lender)) return await fetchMorphoMarkets(chainId, includeUnlisted);
|
|
17959
17975
|
return {};
|
|
17960
17976
|
}
|
|
17961
17977
|
function convertLenderDataFromApi(lender, chainId, data, prices, additionalYields, list = {}) {
|
|
@@ -17965,11 +17981,11 @@ function convertLenderDataFromApi(lender, chainId, data, prices, additionalYield
|
|
|
17965
17981
|
}
|
|
17966
17982
|
var getLenderPublicDataViaApi = async (chainId, lenders, prices, additionalYields, tokenList = async () => {
|
|
17967
17983
|
return {};
|
|
17968
|
-
}) => {
|
|
17984
|
+
}, includeUnlisted = false) => {
|
|
17969
17985
|
let promises = [];
|
|
17970
17986
|
for (const lender of lenders) {
|
|
17971
17987
|
promises.push(
|
|
17972
|
-
getLenderDataFromApi(lender, chainId)
|
|
17988
|
+
getLenderDataFromApi(lender, chainId, prices, additionalYields, includeUnlisted)
|
|
17973
17989
|
);
|
|
17974
17990
|
}
|
|
17975
17991
|
const [list, ...results] = await Promise.all([tokenList(), ...promises]);
|
|
@@ -18008,7 +18024,6 @@ var getLenderPublicDataViaApi = async (chainId, lenders, prices, additionalYield
|
|
|
18008
18024
|
};
|
|
18009
18025
|
function lenderCanUseApi(lender, chainId) {
|
|
18010
18026
|
if (lender === Lender.MORPHO_BLUE) {
|
|
18011
|
-
if (chainId === Chain.OP_MAINNET) return false;
|
|
18012
18027
|
if (chainId === Chain.SONEIUM) return false;
|
|
18013
18028
|
if (chainId === Chain.HEMI_NETWORK) return false;
|
|
18014
18029
|
if (chainId === Chain.BERACHAIN) return false;
|
|
@@ -18017,7 +18032,7 @@ function lenderCanUseApi(lender, chainId) {
|
|
|
18017
18032
|
}
|
|
18018
18033
|
return false;
|
|
18019
18034
|
}
|
|
18020
|
-
var getLenderPublicDataAll = async (chainId, lenders, prices, additionalYields, multicallRetry3, tokenList) => {
|
|
18035
|
+
var getLenderPublicDataAll = async (chainId, lenders, prices, additionalYields, multicallRetry3, tokenList, includeUnlistedMorphoMarkets = false) => {
|
|
18021
18036
|
const lendersApi = lenders.filter((l) => lenderCanUseApi(l, chainId));
|
|
18022
18037
|
const lendersOnChain = lenders.filter((l) => !lenderCanUseApi(l, chainId));
|
|
18023
18038
|
const onChain = getLenderPublicData(
|
|
@@ -18033,7 +18048,8 @@ var getLenderPublicDataAll = async (chainId, lenders, prices, additionalYields,
|
|
|
18033
18048
|
lendersApi,
|
|
18034
18049
|
prices,
|
|
18035
18050
|
additionalYields,
|
|
18036
|
-
tokenList
|
|
18051
|
+
tokenList,
|
|
18052
|
+
includeUnlistedMorphoMarkets
|
|
18037
18053
|
);
|
|
18038
18054
|
const [onChainRes, apiRes] = await Promise.all([onChain, api]);
|
|
18039
18055
|
return { ...onChainRes, ...apiRes };
|
|
@@ -19099,7 +19115,8 @@ var getMorphoUserDataConverterWithlens = (lender, chainId, account, markets, met
|
|
|
19099
19115
|
payload,
|
|
19100
19116
|
metaMap?.[lenderKey],
|
|
19101
19117
|
addedDeposits,
|
|
19102
|
-
addedDebt
|
|
19118
|
+
addedDebt,
|
|
19119
|
+
lenderKey
|
|
19103
19120
|
);
|
|
19104
19121
|
datas[lenderKey] = userData;
|
|
19105
19122
|
});
|
|
@@ -19162,7 +19179,8 @@ var getListaUserDataConverterWithlens = (lender, chainId, account, markets, meta
|
|
|
19162
19179
|
payload,
|
|
19163
19180
|
metaMap?.[lenderKey],
|
|
19164
19181
|
addedDeposits,
|
|
19165
|
-
addedDebt
|
|
19182
|
+
addedDebt,
|
|
19183
|
+
lenderKey
|
|
19166
19184
|
);
|
|
19167
19185
|
datas[lenderKey] = {
|
|
19168
19186
|
...payload,
|
|
@@ -19369,6 +19387,7 @@ function createEulerMultiAccountTypeUserState(payload, lenderData, histData) {
|
|
|
19369
19387
|
const price = getOraclePrice(lenderData[marketUid]);
|
|
19370
19388
|
const bcf = config?.borrowCollateralFactor ?? 1;
|
|
19371
19389
|
const bf = config?.borrowFactor ?? 1;
|
|
19390
|
+
const vaultAddr = lenderData[marketUid]?.params?.metadata?.vault;
|
|
19372
19391
|
const pos = payload.lendingPositions[subAccountIndex]?.[marketUid];
|
|
19373
19392
|
if (pos) {
|
|
19374
19393
|
let withdrawable;
|
|
@@ -19390,6 +19409,8 @@ function createEulerMultiAccountTypeUserState(payload, lenderData, histData) {
|
|
|
19390
19409
|
let borrowable;
|
|
19391
19410
|
if (!flags?.borrowingEnabled || flags?.isFrozen || config?.debtDisabled) {
|
|
19392
19411
|
borrowable = "0";
|
|
19412
|
+
} else if (debt > 0 && vaultAddr !== controller) {
|
|
19413
|
+
borrowable = "0";
|
|
19393
19414
|
} else {
|
|
19394
19415
|
const borrowableUSD = Math.max(creditLine / bf, 0);
|
|
19395
19416
|
borrowable = String(borrowableUSD / price);
|
|
@@ -19399,7 +19420,10 @@ function createEulerMultiAccountTypeUserState(payload, lenderData, histData) {
|
|
|
19399
19420
|
}
|
|
19400
19421
|
pos.withdrawable = withdrawable;
|
|
19401
19422
|
pos.borrowable = borrowable;
|
|
19402
|
-
|
|
19423
|
+
pos.underlyingInfo = buildUnderlyingInfo(
|
|
19424
|
+
lenderData[marketUid]
|
|
19425
|
+
);
|
|
19426
|
+
} else if ((deposits > 0 || debt > 0) && flags?.borrowingEnabled && !flags?.isFrozen && !config?.debtDisabled && (debt === 0 || vaultAddr === controller)) {
|
|
19403
19427
|
let borrowable = String(Math.max(creditLine / bf, 0) / price);
|
|
19404
19428
|
if (borrowLiquidity != null) {
|
|
19405
19429
|
borrowable = String(Math.min(Number(borrowable), borrowLiquidity));
|
|
@@ -19419,18 +19443,21 @@ function createEulerMultiAccountTypeUserState(payload, lenderData, histData) {
|
|
|
19419
19443
|
collateralEnabled: false,
|
|
19420
19444
|
isAllowed: false,
|
|
19421
19445
|
withdrawable: "0",
|
|
19422
|
-
borrowable
|
|
19446
|
+
borrowable,
|
|
19447
|
+
underlyingInfo: buildUnderlyingInfo(lenderData[marketUid])
|
|
19423
19448
|
};
|
|
19424
19449
|
}
|
|
19425
19450
|
}
|
|
19426
19451
|
data.push({
|
|
19427
19452
|
accountId: subAccountIndex,
|
|
19428
|
-
health: balanceData2.debt === 0 ? null : balanceData2.adjustedDebt > 0 ? balanceData2.
|
|
19453
|
+
health: balanceData2.debt === 0 ? null : balanceData2.adjustedDebt > 0 ? balanceData2.collateral / balanceData2.adjustedDebt : balanceData2.collateral / balanceData2.debt,
|
|
19429
19454
|
borrowCapacityUSD: creditLine,
|
|
19430
19455
|
userConfig,
|
|
19431
19456
|
balanceData: balanceData2,
|
|
19432
19457
|
aprData: aprData2,
|
|
19433
|
-
positions: Object.values(
|
|
19458
|
+
positions: Object.values(
|
|
19459
|
+
payload.lendingPositions[subAccountIndex]
|
|
19460
|
+
)
|
|
19434
19461
|
});
|
|
19435
19462
|
}
|
|
19436
19463
|
return {
|
|
@@ -24652,7 +24679,7 @@ function resolveDebitDataKey(chainId, lender, tokenAddress, cToken) {
|
|
|
24652
24679
|
function needsLenderApproval(params) {
|
|
24653
24680
|
const { lender, lenderDebitData, tokenAddress, amount, chainId, cToken } = params;
|
|
24654
24681
|
if (!lenderDebitData) return true;
|
|
24655
|
-
if (isInit(lender)) {
|
|
24682
|
+
if (isInit(lender) || isMorphoType(lender)) {
|
|
24656
24683
|
const entry2 = Object.values(lenderDebitData)[0];
|
|
24657
24684
|
if (!entry2 || entry2.amount === void 0) return true;
|
|
24658
24685
|
return entry2.amount === 0n;
|
|
@@ -24664,7 +24691,7 @@ function needsLenderApproval(params) {
|
|
|
24664
24691
|
const requiredShares = toCompoundV2Shares(entry, amount);
|
|
24665
24692
|
return entry.amount < requiredShares;
|
|
24666
24693
|
}
|
|
24667
|
-
if (isCompoundV3(lender)
|
|
24694
|
+
if (isCompoundV3(lender)) {
|
|
24668
24695
|
return entry.amount === 0n;
|
|
24669
24696
|
}
|
|
24670
24697
|
return entry.amount < amount;
|
|
@@ -31729,6 +31756,6 @@ async function fetchTokenBalances(chainId, account, tokens, options = {}) {
|
|
|
31729
31756
|
return parseTokenBalanceResult(rawResult, prepared.query);
|
|
31730
31757
|
}
|
|
31731
31758
|
|
|
31732
|
-
export { EMPTY_BALANCE, MORPHO_LENS, MaxParamThresholds, applyPositionDelta, attachPricesToFlashLiquidity, buildLoopResult, buildMorphoTypeCall, buildMorphoTypeUserCallWithLens, buildPortfolioTotals, buildSumerAccumulators, buildSummaries, calculateLeverage, calculateNetApr, calculateOverallNetApr, calculateWeightedAverage, computeBorrowDelta2 as computeBorrowDelta, computeCloseTradeDeltas, computeCollateralSwapDeltas, computeDebtSwapDeltas, computeDepositDelta2 as computeDepositDelta, computeEModeAnalysis, computeOpenTradeDeltas, computePostTradeMetrics, computeRepayDelta2 as computeRepayDelta, computeSumerBorrowDelta, computeSumerDepositDelta, computeSumerRepayDelta, computeSumerWaterfall, computeSumerWithdrawDelta, computeWithdrawDelta2 as computeWithdrawDelta, computeZapTradeDeltas, convertLenderUserDataResult, createMarketUid, createMulticallRpcCall, createRawRpcCalls, decodeListaMarkets, decodeMarkets, decodePackedListaUserDataset, decodePackedMorphoUserDataset, encodeBalanceFetcherCalldata, fetchDefillamaData, fetchDefillamaHistData, fetchFlashLiquidityForChain, fetchGeneralYields, fetchGeneralYieldsByMarketUid, fetchMainPrices, fetchOraclePrices, fetchPendlePrices, fetchTokenBalances, fetchTokenMetadata, filterActiveLenders, filterLendersByProtocol, fuseLenderData, generateLendingPairs, generateLendingPools, getAavesForChain, getAssetConfig, getBalanceForMarketUid, getBorrowCapacity, getHealthFactor, getLenderAssets, getLenderPublicData, getLenderPublicDataAll, getLenderPublicDataViaApi, getLenderUserDataMulti, getLenderUserDataResult, getLendersForChain, getMaxAmountOpen, getMergedUserData, getMorphoTypeMarketConverter, getTopPairs, keysFromMaps, multicall3Abi, nanTo, needsLenderApproval, needsTokenApproval, noOpResult, normalizeToBytes, parseBalanceFetcherResult, parseMergedResult, parseMulticallRpcResponses, parseRawRpcBatchResponses, parseRawRpcResponses, parseTokenBalanceResult, positivePart2 as positivePart, prepareLenderUserDataRpcCalls, prepareMergedMulticallParams, prepareMergedRpcCalls, prepareMulticallInputs, prepareTokenBalanceRpcCalls, selectAssetGroupPrices, unflattenLenderData };
|
|
31759
|
+
export { EMPTY_BALANCE, MORPHO_LENS, MaxParamThresholds, applyPositionDelta, attachPricesToFlashLiquidity, buildLoopResult, buildMorphoTypeCall, buildMorphoTypeUserCallWithLens, buildPortfolioTotals, buildSumerAccumulators, buildSummaries, calculateLeverage, calculateNetApr, calculateOverallNetApr, calculateWeightedAverage, computeBorrowDelta2 as computeBorrowDelta, computeCloseTradeDeltas, computeCollateralSwapDeltas, computeDebtSwapDeltas, computeDepositDelta2 as computeDepositDelta, computeEModeAnalysis, computeOpenTradeDeltas, computePostTradeMetrics, computeRepayDelta2 as computeRepayDelta, computeSumerBorrowDelta, computeSumerDepositDelta, computeSumerRepayDelta, computeSumerWaterfall, computeSumerWithdrawDelta, computeWithdrawDelta2 as computeWithdrawDelta, computeZapTradeDeltas, convertLenderUserDataResult, createMarketUid, createMulticallRpcCall, createRawRpcCalls, decodeListaMarkets, decodeMarkets, decodePackedListaUserDataset, decodePackedMorphoUserDataset, encodeBalanceFetcherCalldata, fetchDefillamaData, fetchDefillamaHistData, fetchEulerSubAccountIndexes, fetchFlashLiquidityForChain, fetchGeneralYields, fetchGeneralYieldsByMarketUid, fetchMainPrices, fetchOraclePrices, fetchPendlePrices, fetchTokenBalances, fetchTokenMetadata, filterActiveLenders, filterLendersByProtocol, fuseLenderData, generateLendingPairs, generateLendingPools, getAavesForChain, getAssetConfig, getBalanceForMarketUid, getBorrowCapacity, getHealthFactor, getLenderAssets, getLenderPublicData, getLenderPublicDataAll, getLenderPublicDataViaApi, getLenderUserDataMulti, getLenderUserDataResult, getLendersForChain, getMaxAmountOpen, getMergedUserData, getMorphoTypeMarketConverter, getSubAccountAddress, getSubAccountIndex, getTopPairs, keysFromMaps, multicall3Abi, nanTo, needsLenderApproval, needsTokenApproval, noOpResult, normalizeToBytes, parseBalanceFetcherResult, parseMergedResult, parseMulticallRpcResponses, parseRawRpcBatchResponses, parseRawRpcResponses, parseTokenBalanceResult, positivePart2 as positivePart, prepareLenderUserDataRpcCalls, prepareMergedMulticallParams, prepareMergedRpcCalls, prepareMulticallInputs, prepareTokenBalanceRpcCalls, selectAssetGroupPrices, unflattenLenderData };
|
|
31733
31760
|
//# sourceMappingURL=index.js.map
|
|
31734
31761
|
//# sourceMappingURL=index.js.map
|