@defisaver/positions-sdk 2.1.127-midnight-8-dev → 2.1.127-midnight-10-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/aaveV4/index.js +26 -10
- package/cjs/aaveV4/merkl.d.ts +2 -1
- package/cjs/aaveV4/merkl.js +42 -35
- package/cjs/config/contracts.d.ts +0 -938
- package/cjs/config/contracts.js +2 -8
- package/cjs/contracts.d.ts +0 -23433
- package/cjs/contracts.js +2 -3
- package/cjs/helpers/aaveV4Helpers/index.d.ts +7 -1
- package/cjs/helpers/aaveV4Helpers/index.js +22 -10
- package/cjs/helpers/index.d.ts +0 -1
- package/cjs/helpers/index.js +1 -2
- package/cjs/helpers/morphoMidnightHelpers/index.d.ts +4 -57
- package/cjs/helpers/morphoMidnightHelpers/index.js +15 -72
- package/cjs/helpers/morphoMidnightHelpers/rate.d.ts +4 -0
- package/cjs/helpers/morphoMidnightHelpers/rate.js +14 -1
- package/cjs/helpers/morphoMidnightHelpers/tenor.d.ts +8 -4
- package/cjs/helpers/morphoMidnightHelpers/tenor.js +12 -14
- package/cjs/index.d.ts +1 -2
- package/cjs/index.js +1 -3
- package/cjs/markets/index.d.ts +0 -1
- package/cjs/markets/index.js +1 -3
- package/cjs/markets/morphoBlue/index.d.ts +6 -0
- package/cjs/markets/morphoBlue/index.js +53 -2
- package/cjs/portfolio/discovery.d.ts +1 -1
- package/cjs/portfolio/discovery.js +1 -1
- package/cjs/portfolio/index.js +0 -32
- package/cjs/services/utils.d.ts +1 -0
- package/cjs/services/utils.js +3 -1
- package/cjs/staking/staking.js +1 -2
- package/cjs/types/aaveV4.d.ts +5 -0
- package/cjs/types/common.d.ts +4 -0
- package/cjs/types/common.js +6 -1
- package/cjs/types/index.d.ts +0 -1
- package/cjs/types/index.js +0 -1
- package/cjs/types/merkl.d.ts +3 -4
- package/cjs/types/morphoBlue.d.ts +3 -0
- package/cjs/types/morphoBlue.js +3 -0
- package/cjs/types/portfolio.d.ts +0 -4
- package/esm/aaveV4/index.js +27 -11
- package/esm/aaveV4/merkl.d.ts +2 -1
- package/esm/aaveV4/merkl.js +41 -35
- package/esm/config/contracts.d.ts +0 -938
- package/esm/config/contracts.js +0 -6
- package/esm/contracts.d.ts +0 -23433
- package/esm/contracts.js +0 -1
- package/esm/helpers/aaveV4Helpers/index.d.ts +7 -1
- package/esm/helpers/aaveV4Helpers/index.js +21 -10
- package/esm/helpers/index.d.ts +0 -1
- package/esm/helpers/index.js +0 -1
- package/esm/helpers/morphoMidnightHelpers/index.d.ts +4 -57
- package/esm/helpers/morphoMidnightHelpers/index.js +14 -73
- package/esm/helpers/morphoMidnightHelpers/rate.d.ts +4 -0
- package/esm/helpers/morphoMidnightHelpers/rate.js +12 -0
- package/esm/helpers/morphoMidnightHelpers/tenor.d.ts +8 -4
- package/esm/helpers/morphoMidnightHelpers/tenor.js +12 -13
- package/esm/index.d.ts +1 -2
- package/esm/index.js +1 -2
- package/esm/markets/index.d.ts +0 -1
- package/esm/markets/index.js +0 -1
- package/esm/markets/morphoBlue/index.d.ts +6 -0
- package/esm/markets/morphoBlue/index.js +48 -0
- package/esm/portfolio/discovery.d.ts +1 -1
- package/esm/portfolio/discovery.js +1 -1
- package/esm/portfolio/index.js +1 -33
- package/esm/services/utils.d.ts +1 -0
- package/esm/services/utils.js +1 -0
- package/esm/staking/staking.js +1 -2
- package/esm/types/aaveV4.d.ts +5 -0
- package/esm/types/common.d.ts +4 -0
- package/esm/types/common.js +5 -0
- package/esm/types/index.d.ts +0 -1
- package/esm/types/index.js +0 -1
- package/esm/types/merkl.d.ts +3 -4
- package/esm/types/morphoBlue.d.ts +3 -0
- package/esm/types/morphoBlue.js +3 -0
- package/esm/types/portfolio.d.ts +0 -4
- package/package.json +1 -1
- package/src/aaveV4/index.ts +29 -11
- package/src/aaveV4/merkl.ts +41 -32
- package/src/config/contracts.ts +0 -6
- package/src/contracts.ts +0 -1
- package/src/helpers/aaveV4Helpers/index.ts +22 -9
- package/src/helpers/index.ts +0 -1
- package/src/helpers/morphoMidnightHelpers/index.ts +16 -69
- package/src/helpers/morphoMidnightHelpers/rate.ts +25 -0
- package/src/helpers/morphoMidnightHelpers/tenor.ts +12 -16
- package/src/index.ts +0 -2
- package/src/markets/index.ts +0 -1
- package/src/markets/morphoBlue/index.ts +49 -1
- package/src/portfolio/discovery.ts +1 -1
- package/src/portfolio/index.ts +0 -33
- package/src/services/utils.ts +2 -0
- package/src/staking/staking.ts +1 -2
- package/src/types/aaveV4.ts +5 -0
- package/src/types/common.ts +5 -0
- package/src/types/index.ts +0 -1
- package/src/types/merkl.ts +3 -3
- package/src/types/morphoBlue.ts +3 -0
- package/src/types/portfolio.ts +0 -4
- package/cjs/eulerV2/index.d.ts +0 -47
- package/cjs/eulerV2/index.js +0 -225
- package/cjs/helpers/eulerHelpers/index.d.ts +0 -22
- package/cjs/helpers/eulerHelpers/index.js +0 -231
- package/cjs/markets/euler/index.d.ts +0 -8
- package/cjs/markets/euler/index.js +0 -30
- package/cjs/types/euler.d.ts +0 -153
- package/cjs/types/euler.js +0 -14
- package/esm/eulerV2/index.d.ts +0 -47
- package/esm/eulerV2/index.js +0 -215
- package/esm/helpers/eulerHelpers/index.d.ts +0 -22
- package/esm/helpers/eulerHelpers/index.js +0 -218
- package/esm/markets/euler/index.d.ts +0 -8
- package/esm/markets/euler/index.js +0 -24
- package/esm/types/euler.d.ts +0 -153
- package/esm/types/euler.js +0 -11
- package/src/eulerV2/index.ts +0 -331
- package/src/helpers/eulerHelpers/index.ts +0 -232
- package/src/markets/euler/index.ts +0 -27
- package/src/types/euler.ts +0 -178
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
AaveV4UsedReserveAssets,
|
|
18
18
|
EthereumProvider,
|
|
19
19
|
IncentiveData,
|
|
20
|
+
IncentiveSide,
|
|
20
21
|
LeverageType,
|
|
21
22
|
NetworkNumber,
|
|
22
23
|
} from '../../types';
|
|
@@ -93,14 +94,26 @@ export const calcUserRiskPremiumBps = (usedAssets: AaveV4UsedReserveAssets, asse
|
|
|
93
94
|
|
|
94
95
|
/**
|
|
95
96
|
* `spokeXIncentives`/`hubXIncentives` are each the intrinsic `base` list with at most one Merkl
|
|
96
|
-
* reward appended (see attachAaveV4MerklIncentives).
|
|
97
|
-
*
|
|
97
|
+
* reward appended (see attachAaveV4MerklIncentives). Merkl regularly publishes the same reward
|
|
98
|
+
* stream at both scopes (a spoke campaign and a hub campaign covering the same borrows, e.g. USDC
|
|
99
|
+
* borrowed from the Prime Hub via the Bluechip Spoke), so the scopes must never be summed — the
|
|
100
|
+
* more specific spoke reward wins and the hub reward only applies when no spoke campaign exists,
|
|
101
|
+
* which is also what every per-asset APY badge (and Aave's own UI) shows.
|
|
98
102
|
*/
|
|
99
|
-
const mergeScopedIncentives = (base: IncentiveData[] = [], spokeScoped?: IncentiveData[], hubScoped?: IncentiveData[]): IncentiveData[] =>
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
...
|
|
103
|
-
|
|
103
|
+
const mergeScopedIncentives = (base: IncentiveData[] = [], spokeScoped?: IncentiveData[], hubScoped?: IncentiveData[]): IncentiveData[] => {
|
|
104
|
+
const spokeExtras = spokeScoped ? spokeScoped.slice(base.length) : [];
|
|
105
|
+
const hubExtras = hubScoped ? hubScoped.slice(base.length) : [];
|
|
106
|
+
return [...base, ...(spokeExtras.length ? spokeExtras : hubExtras)];
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The incentives that actually accrue to a position on this reserve for the given side: the
|
|
111
|
+
* intrinsic (staking) incentives plus the single applicable Merkl reward. Display surfaces should
|
|
112
|
+
* use this rather than picking a scoped list directly, so badges always match the net APY math.
|
|
113
|
+
*/
|
|
114
|
+
export const getAaveV4ApplicableIncentives = (assetData: AaveV4ReserveAssetData, side: IncentiveSide): IncentiveData[] => (side === IncentiveSide.Supply
|
|
115
|
+
? mergeScopedIncentives(assetData.supplyIncentives, assetData.spokeSupplyIncentives, assetData.hubSupplyIncentives)
|
|
116
|
+
: mergeScopedIncentives(assetData.borrowIncentives, assetData.spokeBorrowIncentives, assetData.hubBorrowIncentives));
|
|
104
117
|
|
|
105
118
|
export const calculateNetApyAaveV4 = ({
|
|
106
119
|
usedAssets,
|
|
@@ -123,7 +136,7 @@ export const calculateNetApyAaveV4 = ({
|
|
|
123
136
|
const supplyInterest = calculateInterestEarned(amount, assetData.supplyRate, 'year', true);
|
|
124
137
|
acc.supplyInterest = new Dec(acc.supplyInterest).add(supplyInterest.toString()).toString();
|
|
125
138
|
|
|
126
|
-
const supplyIncentives =
|
|
139
|
+
const supplyIncentives = getAaveV4ApplicableIncentives(assetData, IncentiveSide.Supply);
|
|
127
140
|
for (const supplyIncentive of supplyIncentives) {
|
|
128
141
|
const incentiveInterest = calculateInterestEarned(amount, supplyIncentive.apy, 'year', true);
|
|
129
142
|
acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
|
|
@@ -141,7 +154,7 @@ export const calculateNetApyAaveV4 = ({
|
|
|
141
154
|
const borrowInterest = calculateInterestEarned(amount, userBorrowRate, 'year', true);
|
|
142
155
|
acc.borrowInterest = new Dec(acc.borrowInterest).sub(borrowInterest.toString()).toString();
|
|
143
156
|
|
|
144
|
-
const borrowIncentives =
|
|
157
|
+
const borrowIncentives = getAaveV4ApplicableIncentives(assetData, IncentiveSide.Borrow);
|
|
145
158
|
for (const borrowIncentive of borrowIncentives) {
|
|
146
159
|
const incentiveInterest = calculateInterestEarned(amount, borrowIncentive.apy, 'year', true);
|
|
147
160
|
acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
|
package/src/helpers/index.ts
CHANGED
|
@@ -7,6 +7,5 @@ export * as morphoBlueHelpers from './morphoBlueHelpers';
|
|
|
7
7
|
export * as morphoMidnightHelpers from './morphoMidnightHelpers';
|
|
8
8
|
export * as llamaLendHelpers from './llamaLendHelpers';
|
|
9
9
|
export * as liquityV2Helpers from './liquityV2Helpers';
|
|
10
|
-
export * as eulerV2Helpers from './eulerHelpers';
|
|
11
10
|
export * as fluidHelpers from './fluidHelpers';
|
|
12
11
|
export * as aaveV4Helpers from './aaveV4Helpers';
|
|
@@ -20,7 +20,7 @@ import { WAD } from '../../constants';
|
|
|
20
20
|
import { LONGER_TIMEOUT } from '../../services/utils';
|
|
21
21
|
import { isTenorMidnightMarket } from '../../markets/morphoMidnight';
|
|
22
22
|
import {
|
|
23
|
-
buildMidnightParsedBook, midnightApyFromPrice,
|
|
23
|
+
buildMidnightParsedBook, midnightApyFromPrice, midnightBoundPrice, midnightTimeToMaturityDays,
|
|
24
24
|
} from './rate';
|
|
25
25
|
import {
|
|
26
26
|
getTenorBorrowQuote, getTenorMarketBook, getTenorPaybackQuote, getTenorPaybackUnitsQuote,
|
|
@@ -30,8 +30,10 @@ export {
|
|
|
30
30
|
buildMidnightParsedBook,
|
|
31
31
|
midnightApyFromPrice,
|
|
32
32
|
midnightBookBestFirst,
|
|
33
|
+
midnightBoundPrice,
|
|
33
34
|
midnightPriceFromApy,
|
|
34
35
|
midnightTimeToMaturityDays,
|
|
36
|
+
MIDNIGHT_DEFAULT_RATE_SLIPPAGE,
|
|
35
37
|
} from './rate';
|
|
36
38
|
export {
|
|
37
39
|
tenorBookKeyFor,
|
|
@@ -332,26 +334,6 @@ const fetchMorphoMidnightQuote = async (
|
|
|
332
334
|
};
|
|
333
335
|
};
|
|
334
336
|
|
|
335
|
-
/**
|
|
336
|
-
* Quote a prospective borrow against the Midnight order book: the estimated rate, the debt units it adds,
|
|
337
|
-
* and the `maxUnits` cap sent on-chain to protect the user if better offers get filled first. `assetsRaw`
|
|
338
|
-
* (and the returned `newUnits`/`maxUnits`) are raw loan-token base units — callers convert to/from human
|
|
339
|
-
* amounts. Throws if the book can't fill the amount (caller handles).
|
|
340
|
-
*
|
|
341
|
-
* Two ways to set the cap:
|
|
342
|
-
* - `maxBorrowRate` — an absolute APY ceiling, honoured **exactly**: the cap price is derived locally via
|
|
343
|
-
* `midnightPriceFromApy`. Prefer this when a user pins a max rate.
|
|
344
|
-
* - otherwise `slippagePercent`, the API's own knob. Note it is a **price**-level slippage, not APY points:
|
|
345
|
-
* near maturity the annualisation factor (365 / ttmDays) multiplies it heavily, so on a 22-day market a
|
|
346
|
-
* slippage of 0.5 permitted an APY ~9pp above the estimate, not 0.5pp. It also saturates at the book's
|
|
347
|
-
* cheapest bid. `maxRate` therefore reports what the cap actually permits, derived from the cap price.
|
|
348
|
-
*
|
|
349
|
-
* A `maxBorrowRate` below `estBorrowRate` yields `maxUnits < newUnits` — the borrow would revert on-chain.
|
|
350
|
-
* Compare the two before submitting and tell the user their ceiling is under the market rate.
|
|
351
|
-
*
|
|
352
|
-
* Tenor-hosted markets (see `isTenorMidnightMarket`) are quoted against Tenor's router instead of Morpho's
|
|
353
|
-
* book API. Slippage is applied locally to `maxUnits`; `taker` is the position owner (the smart wallet).
|
|
354
|
-
*/
|
|
355
337
|
export const getMorphoMidnightBorrowQuote = async (
|
|
356
338
|
marketId: string,
|
|
357
339
|
assetsRaw: string,
|
|
@@ -359,21 +341,20 @@ export const getMorphoMidnightBorrowQuote = async (
|
|
|
359
341
|
maturity: number,
|
|
360
342
|
maxBorrowRate?: Dec.Value,
|
|
361
343
|
taker?: string,
|
|
344
|
+
rateSlippagePercent?: Dec.Value,
|
|
362
345
|
): Promise<MorphoMidnightBorrowQuote> => {
|
|
363
346
|
if (isTenorMidnightMarket(marketId)) {
|
|
364
|
-
return getTenorBorrowQuote(marketId, assetsRaw, slippagePercent, maturity, maxBorrowRate, taker);
|
|
347
|
+
return getTenorBorrowQuote(marketId, assetsRaw, slippagePercent, maturity, maxBorrowRate, taker, rateSlippagePercent);
|
|
365
348
|
}
|
|
366
349
|
|
|
367
350
|
const quote = await fetchMorphoMidnightQuote(marketId, 'bids', { assets: assetsRaw }, slippagePercent);
|
|
368
|
-
const { bestPrice
|
|
351
|
+
const { bestPrice } = quote;
|
|
369
352
|
const ttmDays = midnightTimeToMaturityDays(maturity);
|
|
370
353
|
const estBorrowRate = midnightApyFromPrice(bestPrice, ttmDays);
|
|
371
354
|
|
|
372
355
|
// Price the cap sits at, and the rate that price represents — one derivation, so `maxRate` and
|
|
373
356
|
// `maxUnits` can never disagree about what the user is protected at.
|
|
374
|
-
const capPrice =
|
|
375
|
-
? midnightPriceFromApy(maxBorrowRate, ttmDays)
|
|
376
|
-
: worstPrice;
|
|
357
|
+
const capPrice = midnightBoundPrice(estBorrowRate, ttmDays, 'ceiling', maxBorrowRate, rateSlippagePercent);
|
|
377
358
|
const maxRate = midnightApyFromPrice(capPrice, ttmDays);
|
|
378
359
|
const newUnits = new Dec(bestPrice).lte(0) ? '0' : new Dec(assetsRaw).div(bestPrice).toFixed(0);
|
|
379
360
|
const maxUnits = new Dec(capPrice).lte(0) ? '0' : new Dec(assetsRaw).div(capPrice).toFixed(0);
|
|
@@ -387,24 +368,6 @@ export const getMorphoMidnightBorrowQuote = async (
|
|
|
387
368
|
};
|
|
388
369
|
};
|
|
389
370
|
|
|
390
|
-
/**
|
|
391
|
-
* Quote a prospective payback against the ask side of the Midnight order book: the rate the repayment
|
|
392
|
-
* retires debt at, the debt units it buys, and the `minUnits` floor sent on-chain to protect the user if
|
|
393
|
-
* the cheap offers get taken first. `assetsRaw` is the amount **spent** (raw loan-token base units) —
|
|
394
|
-
* matching `MidnightPaybackFromOrders`, whose `amount` is what leaves the wallet; the units bought, and
|
|
395
|
-
* therefore the debt retired, exceed it because a unit costs less than one loan token before maturity.
|
|
396
|
-
* Throws if the book can't fill the amount (caller handles).
|
|
397
|
-
*
|
|
398
|
-
* The mirror image of the borrow quote in every respect. A repayer wants a *high* rate, i.e. cheap units,
|
|
399
|
-
* so the guard is a floor rather than a ceiling:
|
|
400
|
-
* - `minPaybackRate` — an absolute APY floor, honoured **exactly** via `midnightPriceFromApy`. Prefer
|
|
401
|
-
* this when a user pins a min rate.
|
|
402
|
-
* - otherwise `slippagePercent`, the API's own price-level knob, whose APY effect is amplified by the
|
|
403
|
-
* annualisation factor near maturity. `minRate` reports what the floor actually permits.
|
|
404
|
-
*
|
|
405
|
-
* A `minPaybackRate` above `estPaybackRate` yields `minUnits > newUnits` — the payback would revert
|
|
406
|
-
* on-chain. Compare the two before submitting and tell the user their floor is over the market rate.
|
|
407
|
-
*/
|
|
408
371
|
export const getMorphoMidnightPaybackQuote = async (
|
|
409
372
|
marketId: string,
|
|
410
373
|
assetsRaw: string,
|
|
@@ -412,19 +375,18 @@ export const getMorphoMidnightPaybackQuote = async (
|
|
|
412
375
|
maturity: number,
|
|
413
376
|
minPaybackRate?: Dec.Value,
|
|
414
377
|
taker?: string,
|
|
378
|
+
rateSlippagePercent?: Dec.Value,
|
|
415
379
|
): Promise<MorphoMidnightPaybackQuote> => {
|
|
416
380
|
if (isTenorMidnightMarket(marketId)) {
|
|
417
|
-
return getTenorPaybackQuote(marketId, assetsRaw, slippagePercent, maturity, minPaybackRate, taker);
|
|
381
|
+
return getTenorPaybackQuote(marketId, assetsRaw, slippagePercent, maturity, minPaybackRate, taker, rateSlippagePercent);
|
|
418
382
|
}
|
|
419
383
|
|
|
420
384
|
const quote = await fetchMorphoMidnightQuote(marketId, 'asks', { assets: assetsRaw }, slippagePercent);
|
|
421
|
-
const { bestPrice
|
|
385
|
+
const { bestPrice } = quote;
|
|
422
386
|
const ttmDays = midnightTimeToMaturityDays(maturity);
|
|
423
387
|
const estPaybackRate = midnightApyFromPrice(bestPrice, ttmDays);
|
|
424
388
|
|
|
425
|
-
const capPrice =
|
|
426
|
-
? midnightPriceFromApy(minPaybackRate, ttmDays)
|
|
427
|
-
: worstPrice;
|
|
389
|
+
const capPrice = midnightBoundPrice(estPaybackRate, ttmDays, 'floor', minPaybackRate, rateSlippagePercent);
|
|
428
390
|
const minRate = midnightApyFromPrice(capPrice, ttmDays);
|
|
429
391
|
// Rounded down on both counts: `newUnits` must not overstate the debt the user sees retired, and a
|
|
430
392
|
// `minUnits` rounded up would be a stricter floor than asked for and revert a payback that was fine.
|
|
@@ -440,21 +402,7 @@ export const getMorphoMidnightPaybackQuote = async (
|
|
|
440
402
|
};
|
|
441
403
|
};
|
|
442
404
|
|
|
443
|
-
|
|
444
|
-
* Payback quoted against a **units** target instead of a spend: "retire exactly these debt units, and tell
|
|
445
|
-
* me what that costs". The sibling of `getMorphoMidnightPaybackQuote` in every other respect — same ask
|
|
446
|
-
* side, same rate floor, same offer list — but with the two amounts swapped, so the on-chain guard becomes
|
|
447
|
-
* a ceiling on assets spent rather than a floor on units bought.
|
|
448
|
-
*
|
|
449
|
-
* This is what a **full close** must be sized with. Retiring N units costs less than N loan tokens before
|
|
450
|
-
* maturity, so quoting the close as a spend of the debt's face value asks the book for more depth than the
|
|
451
|
-
* close needs (and can be refused for liquidity that is in fact there), and caps the taker's spend at more
|
|
452
|
-
* than the position is worth. Callers that cannot refund an overspend — a taker calling the bundler
|
|
453
|
-
* directly, rather than through an action contract that sweeps the remainder back — need this quote.
|
|
454
|
-
*
|
|
455
|
-
* A `minPaybackRate` above `estPaybackRate` yields `maxAssets < newAssets`: the ceiling is under what the
|
|
456
|
-
* buy costs and it would revert on-chain, the mirror of the assets-target quote's `minUnits > newUnits`.
|
|
457
|
-
*/
|
|
405
|
+
|
|
458
406
|
export const getMorphoMidnightPaybackUnitsQuote = async (
|
|
459
407
|
marketId: string,
|
|
460
408
|
unitsRaw: string,
|
|
@@ -462,19 +410,18 @@ export const getMorphoMidnightPaybackUnitsQuote = async (
|
|
|
462
410
|
maturity: number,
|
|
463
411
|
minPaybackRate?: Dec.Value,
|
|
464
412
|
taker?: string,
|
|
413
|
+
rateSlippagePercent?: Dec.Value,
|
|
465
414
|
): Promise<MorphoMidnightPaybackUnitsQuote> => {
|
|
466
415
|
if (isTenorMidnightMarket(marketId)) {
|
|
467
|
-
return getTenorPaybackUnitsQuote(marketId, unitsRaw, slippagePercent, maturity, minPaybackRate, taker);
|
|
416
|
+
return getTenorPaybackUnitsQuote(marketId, unitsRaw, slippagePercent, maturity, minPaybackRate, taker, rateSlippagePercent);
|
|
468
417
|
}
|
|
469
418
|
|
|
470
419
|
const quote = await fetchMorphoMidnightQuote(marketId, 'asks', { units: unitsRaw }, slippagePercent);
|
|
471
|
-
const { bestPrice
|
|
420
|
+
const { bestPrice } = quote;
|
|
472
421
|
const ttmDays = midnightTimeToMaturityDays(maturity);
|
|
473
422
|
const estPaybackRate = midnightApyFromPrice(bestPrice, ttmDays);
|
|
474
423
|
|
|
475
|
-
const capPrice =
|
|
476
|
-
? midnightPriceFromApy(minPaybackRate, ttmDays)
|
|
477
|
-
: worstPrice;
|
|
424
|
+
const capPrice = midnightBoundPrice(estPaybackRate, ttmDays, 'floor', minPaybackRate, rateSlippagePercent);
|
|
478
425
|
const minRate = midnightApyFromPrice(capPrice, ttmDays);
|
|
479
426
|
// Rounded UP on both counts — the mirror of the assets-target quote's ROUND_DOWN. Here the figures are
|
|
480
427
|
// what the taker SPENDS, so a value rounded down understates the cost by a base unit and would leave the
|
|
@@ -29,6 +29,31 @@ export const midnightPriceFromApy = (ratePercent: Dec.Value, ttmDays: Dec.Value)
|
|
|
29
29
|
return new Dec(1).div(new Dec(1).add(rate.div(100)).pow(ttm.div(365))).toString();
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
+
export const MIDNIGHT_DEFAULT_RATE_SLIPPAGE = 0.1;
|
|
33
|
+
|
|
34
|
+
const MIDNIGHT_MIN_FLOOR_RATIO = 0.5;
|
|
35
|
+
|
|
36
|
+
/** Which side of the estimate a guard sits on: a ceiling for borrows, a floor for paybacks. */
|
|
37
|
+
export type MidnightRateBoundKind = 'ceiling' | 'floor';
|
|
38
|
+
|
|
39
|
+
export const midnightBoundPrice = (
|
|
40
|
+
estRate: Dec.Value,
|
|
41
|
+
ttmDays: Dec.Value,
|
|
42
|
+
kind: MidnightRateBoundKind,
|
|
43
|
+
boundRate?: Dec.Value,
|
|
44
|
+
rateSlippagePercent: Dec.Value = MIDNIGHT_DEFAULT_RATE_SLIPPAGE,
|
|
45
|
+
): string => {
|
|
46
|
+
if (boundRate !== undefined && new Dec(boundRate).gt(0)) return midnightPriceFromApy(boundRate, ttmDays);
|
|
47
|
+
|
|
48
|
+
const est = new Dec(estRate);
|
|
49
|
+
const slippage = new Dec(rateSlippagePercent);
|
|
50
|
+
const bound = kind === 'ceiling'
|
|
51
|
+
? est.add(slippage)
|
|
52
|
+
: Dec.max(est.sub(slippage), est.mul(MIDNIGHT_MIN_FLOOR_RATIO));
|
|
53
|
+
|
|
54
|
+
return midnightPriceFromApy(bound, ttmDays);
|
|
55
|
+
};
|
|
56
|
+
|
|
32
57
|
export const midnightBookBestFirst = (side: MorphoMidnightBookSide): 1 | -1 => (side === 'asks' ? -1 : 1);
|
|
33
58
|
|
|
34
59
|
export const buildMidnightParsedBook = (
|
|
@@ -17,7 +17,7 @@ import type {
|
|
|
17
17
|
import {
|
|
18
18
|
buildMidnightParsedBook,
|
|
19
19
|
midnightApyFromPrice,
|
|
20
|
-
|
|
20
|
+
midnightBoundPrice,
|
|
21
21
|
midnightTimeToMaturityDays,
|
|
22
22
|
} from './rate';
|
|
23
23
|
|
|
@@ -43,18 +43,6 @@ const tenorFillPrice = (assets: Dec.Value, units: Dec.Value): string => (
|
|
|
43
43
|
new Dec(units).lte(0) ? '0' : new Dec(assets).div(units).toString()
|
|
44
44
|
);
|
|
45
45
|
|
|
46
|
-
export const tenorCapPrice = (
|
|
47
|
-
bestPrice: string,
|
|
48
|
-
slippagePercent: Dec.Value,
|
|
49
|
-
direction: 1 | -1,
|
|
50
|
-
ttmDays: Dec.Value,
|
|
51
|
-
boundRate?: Dec.Value,
|
|
52
|
-
): string => {
|
|
53
|
-
if (boundRate !== undefined && new Dec(boundRate).gt(0)) return midnightPriceFromApy(boundRate, ttmDays);
|
|
54
|
-
const band = new Dec(1).add(new Dec(slippagePercent || 0).div(100).mul(direction));
|
|
55
|
-
return Dec.max(0, new Dec(bestPrice).mul(band)).toString();
|
|
56
|
-
};
|
|
57
|
-
|
|
58
46
|
interface TenorOfferCollateral {
|
|
59
47
|
token: string;
|
|
60
48
|
lltv: string | number;
|
|
@@ -286,6 +274,11 @@ const fetchTenorQuote = async ({
|
|
|
286
274
|
|
|
287
275
|
const TENOR_NO_AVAILABLE_UNITS = '0';
|
|
288
276
|
|
|
277
|
+
/**
|
|
278
|
+
* Tenor's router takes no slippage of its own — it prices the fill and hands back the offers. `slippagePercent`
|
|
279
|
+
* is therefore accepted only to keep the signature aligned with the Morpho-hosted quote that `index.ts`
|
|
280
|
+
* forwards to positionally; the guard comes from `rateSlippagePercent` via `midnightBoundPrice`.
|
|
281
|
+
*/
|
|
289
282
|
export const getTenorBorrowQuote = async (
|
|
290
283
|
marketId: string,
|
|
291
284
|
assetsRaw: string,
|
|
@@ -293,6 +286,7 @@ export const getTenorBorrowQuote = async (
|
|
|
293
286
|
maturity: number,
|
|
294
287
|
maxBorrowRate?: Dec.Value,
|
|
295
288
|
taker?: string,
|
|
289
|
+
rateSlippagePercent?: Dec.Value,
|
|
296
290
|
network: NetworkNumber = NetworkNumber.Base,
|
|
297
291
|
): Promise<MorphoMidnightBorrowQuote> => {
|
|
298
292
|
if (!isTenorMidnightMarket(marketId)) {
|
|
@@ -310,7 +304,7 @@ export const getTenorBorrowQuote = async (
|
|
|
310
304
|
const bestPrice = tenorFillPrice(assetsRaw, quote.units);
|
|
311
305
|
const estBorrowRate = midnightApyFromPrice(bestPrice, ttmDays);
|
|
312
306
|
|
|
313
|
-
const capPrice =
|
|
307
|
+
const capPrice = midnightBoundPrice(estBorrowRate, ttmDays, 'ceiling', maxBorrowRate, rateSlippagePercent);
|
|
314
308
|
const maxRate = midnightApyFromPrice(capPrice, ttmDays);
|
|
315
309
|
const maxUnits = new Dec(capPrice).lte(0) ? '0' : new Dec(assetsRaw).div(capPrice).toFixed(0);
|
|
316
310
|
|
|
@@ -334,6 +328,7 @@ export const getTenorPaybackQuote = async (
|
|
|
334
328
|
maturity: number,
|
|
335
329
|
minPaybackRate?: Dec.Value,
|
|
336
330
|
taker?: string,
|
|
331
|
+
rateSlippagePercent?: Dec.Value,
|
|
337
332
|
network: NetworkNumber = NetworkNumber.Base,
|
|
338
333
|
): Promise<MorphoMidnightPaybackQuote> => {
|
|
339
334
|
if (!isTenorMidnightMarket(marketId)) {
|
|
@@ -351,7 +346,7 @@ export const getTenorPaybackQuote = async (
|
|
|
351
346
|
const bestPrice = tenorFillPrice(assetsRaw, quote.units);
|
|
352
347
|
const estPaybackRate = midnightApyFromPrice(bestPrice, ttmDays);
|
|
353
348
|
|
|
354
|
-
const capPrice =
|
|
349
|
+
const capPrice = midnightBoundPrice(estPaybackRate, ttmDays, 'floor', minPaybackRate, rateSlippagePercent);
|
|
355
350
|
const minRate = midnightApyFromPrice(capPrice, ttmDays);
|
|
356
351
|
const minUnits = new Dec(capPrice).lte(0) ? '0' : new Dec(assetsRaw).div(capPrice).toFixed(0, Dec.ROUND_DOWN);
|
|
357
352
|
|
|
@@ -375,6 +370,7 @@ export const getTenorPaybackUnitsQuote = async (
|
|
|
375
370
|
maturity: number,
|
|
376
371
|
minPaybackRate?: Dec.Value,
|
|
377
372
|
taker?: string,
|
|
373
|
+
rateSlippagePercent?: Dec.Value,
|
|
378
374
|
network: NetworkNumber = NetworkNumber.Base,
|
|
379
375
|
): Promise<MorphoMidnightPaybackUnitsQuote> => {
|
|
380
376
|
if (!isTenorMidnightMarket(marketId)) {
|
|
@@ -393,7 +389,7 @@ export const getTenorPaybackUnitsQuote = async (
|
|
|
393
389
|
const bestPrice = tenorFillPrice(newAssets, unitsRaw);
|
|
394
390
|
const estPaybackRate = midnightApyFromPrice(bestPrice, ttmDays);
|
|
395
391
|
|
|
396
|
-
const capPrice =
|
|
392
|
+
const capPrice = midnightBoundPrice(estPaybackRate, ttmDays, 'floor', minPaybackRate, rateSlippagePercent);
|
|
397
393
|
const minRate = midnightApyFromPrice(capPrice, ttmDays);
|
|
398
394
|
const maxAssets = new Dec(unitsRaw).mul(capPrice).toFixed(0, Dec.ROUND_UP);
|
|
399
395
|
|
package/src/index.ts
CHANGED
|
@@ -19,7 +19,6 @@ import * as exchange from './exchange';
|
|
|
19
19
|
import * as morphoBlue from './morphoBlue';
|
|
20
20
|
import * as morphoMidnight from './morphoMidnight';
|
|
21
21
|
import * as llamaLend from './llamaLend';
|
|
22
|
-
import * as eulerV2 from './eulerV2';
|
|
23
22
|
import * as portfolio from './portfolio';
|
|
24
23
|
import * as claiming from './claiming';
|
|
25
24
|
import * as savings from './savings';
|
|
@@ -45,7 +44,6 @@ export {
|
|
|
45
44
|
morphoBlue,
|
|
46
45
|
morphoMidnight,
|
|
47
46
|
llamaLend,
|
|
48
|
-
eulerV2,
|
|
49
47
|
fluid,
|
|
50
48
|
portfolio,
|
|
51
49
|
claiming,
|
package/src/markets/index.ts
CHANGED
|
@@ -22,7 +22,6 @@ export {
|
|
|
22
22
|
} from './morphoMidnight';
|
|
23
23
|
export { LlamaLendMarkets } from './llamaLend';
|
|
24
24
|
export { LiquityV2Markets, findLiquityV2MarketByAddress } from './liquityV2';
|
|
25
|
-
export { EulerV2Markets } from './euler';
|
|
26
25
|
export {
|
|
27
26
|
FluidMarkets,
|
|
28
27
|
getFluidVersionsDataForNetwork,
|
|
@@ -997,6 +997,36 @@ export const MORPHO_BLUE_WEETH_USDC_770 = (networkId: NetworkNumber = NetworkNum
|
|
|
997
997
|
marketId: '0x34377fc4f617c51818e92c79df31ff270c6a91bc94ad32e367fdf59b9f4ac5dd',
|
|
998
998
|
protocolName: 'morpho-blue',
|
|
999
999
|
});
|
|
1000
|
+
export const MORPHO_BLUE_WEETH_USDC_860 = (networkId: NetworkNumber = NetworkNumber.Eth): MorphoBlueMarketData => ({
|
|
1001
|
+
chainIds: [NetworkNumber.Eth],
|
|
1002
|
+
label: 'Morpho',
|
|
1003
|
+
shortLabel: 'weETH/USDC',
|
|
1004
|
+
value: MorphoBlueVersions.MorphoBlueWeEthUSDC_860,
|
|
1005
|
+
url: 'weethusdc-61765602',
|
|
1006
|
+
loanToken: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
|
|
1007
|
+
collateralToken: '0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee',
|
|
1008
|
+
oracle: '0x5635a2F38c5dFd1d8fDB176d9CB5AEFA07bf6A68',
|
|
1009
|
+
oracleType: MorphoBlueOracleType.MARKET_RATE,
|
|
1010
|
+
irm: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
|
|
1011
|
+
lltv: 0.86,
|
|
1012
|
+
marketId: '0x61765602144e91e5ac9f9e98b8584eae308f9951596fd7f5e0f59f21cd2bf664',
|
|
1013
|
+
protocolName: 'morpho-blue',
|
|
1014
|
+
});
|
|
1015
|
+
export const MORPHO_BLUE_WEETH_USDC_860_85252BB8 = (networkId: NetworkNumber = NetworkNumber.Eth): MorphoBlueMarketData => ({
|
|
1016
|
+
chainIds: [NetworkNumber.Eth],
|
|
1017
|
+
label: 'Morpho',
|
|
1018
|
+
shortLabel: 'weETH/USDC',
|
|
1019
|
+
value: MorphoBlueVersions.MorphoBlueWeEthUSDC_860_85252bb8,
|
|
1020
|
+
url: 'weethusdc-85252bb8',
|
|
1021
|
+
loanToken: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
|
|
1022
|
+
collateralToken: '0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee',
|
|
1023
|
+
oracle: '0xa3A7A3ceFee206f9d7Fe00eC3C83324ED4228411',
|
|
1024
|
+
oracleType: MorphoBlueOracleType.MARKET_RATE,
|
|
1025
|
+
irm: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
|
|
1026
|
+
lltv: 0.86,
|
|
1027
|
+
marketId: '0x85252bb8485c99bba46fe149c7dd2aad83672640f53c630890673cf1848ba16e',
|
|
1028
|
+
protocolName: 'morpho-blue',
|
|
1029
|
+
});
|
|
1000
1030
|
export const MORPHO_BLUE_ETH_USDC_860_94B823E6 = (networkId: NetworkNumber = NetworkNumber.Eth): MorphoBlueMarketData => ({
|
|
1001
1031
|
chainIds: [NetworkNumber.Eth],
|
|
1002
1032
|
label: 'Morpho',
|
|
@@ -1102,6 +1132,21 @@ export const MORPHO_BLUE_WEETH_USDT_860 = (networkId: NetworkNumber = NetworkNum
|
|
|
1102
1132
|
marketId: '0xc2c53d2b868e163da71de14a5113cc2743fc9b5ad7488334720ed2846566a8f6',
|
|
1103
1133
|
protocolName: 'morpho-blue',
|
|
1104
1134
|
});
|
|
1135
|
+
export const MORPHO_BLUE_WEETH_USDT_860_A6A4C1F1 = (networkId: NetworkNumber = NetworkNumber.Eth): MorphoBlueMarketData => ({
|
|
1136
|
+
chainIds: [NetworkNumber.Eth],
|
|
1137
|
+
label: 'Morpho',
|
|
1138
|
+
shortLabel: 'weETH/USDT',
|
|
1139
|
+
value: MorphoBlueVersions.MorphoBlueWeEthUSDT_860_a6a4c1f1,
|
|
1140
|
+
url: 'weethusdt-a6a4c1f1',
|
|
1141
|
+
loanToken: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
|
|
1142
|
+
collateralToken: '0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee',
|
|
1143
|
+
oracle: '0xa3A7A3ceFee206f9d7Fe00eC3C83324ED4228411',
|
|
1144
|
+
oracleType: MorphoBlueOracleType.MARKET_RATE,
|
|
1145
|
+
irm: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
|
|
1146
|
+
lltv: 0.86,
|
|
1147
|
+
marketId: '0xa6a4c1f15490a1ff39d9de3a366b408dd5647a436d8b179726d3e0562aff1292',
|
|
1148
|
+
protocolName: 'morpho-blue',
|
|
1149
|
+
});
|
|
1105
1150
|
export const MORPHO_BLUE_SYRUPUSDT_USDT_915 = (networkId: NetworkNumber = NetworkNumber.Eth): MorphoBlueMarketData => ({
|
|
1106
1151
|
chainIds: [NetworkNumber.Eth],
|
|
1107
1152
|
label: 'Morpho',
|
|
@@ -1865,6 +1910,8 @@ export const MorphoBlueMarkets = (networkId: NetworkNumber) => ({
|
|
|
1865
1910
|
[MorphoBlueVersions.MorphoBlueWstEthUSDT_860]: MORPHO_BLUE_WSTETH_USDT_860(networkId),
|
|
1866
1911
|
[MorphoBlueVersions.MorphoBlueSyrupUSDCRLUSD_915]: MORPHO_BLUE_SYRUPUSDC_RLUSD_915(networkId),
|
|
1867
1912
|
[MorphoBlueVersions.MorphoBlueWeEthUSDC_770]: MORPHO_BLUE_WEETH_USDC_770(networkId),
|
|
1913
|
+
[MorphoBlueVersions.MorphoBlueWeEthUSDC_860]: MORPHO_BLUE_WEETH_USDC_860(networkId),
|
|
1914
|
+
[MorphoBlueVersions.MorphoBlueWeEthUSDC_860_85252bb8]: MORPHO_BLUE_WEETH_USDC_860_85252BB8(networkId),
|
|
1868
1915
|
[MorphoBlueVersions.MorphoBlueEthUSDC_860_94b823e6]: MORPHO_BLUE_ETH_USDC_860_94B823E6(networkId),
|
|
1869
1916
|
[MorphoBlueVersions.MorphoBlueUSD3USDC_915]: MORPHO_BLUE_USD3_USDC_915(networkId),
|
|
1870
1917
|
[MorphoBlueVersions.MorphoBlueStUSDSUSDC_860]: MORPHO_BLUE_STUSDS_USDC_860(networkId),
|
|
@@ -1872,6 +1919,7 @@ export const MorphoBlueMarkets = (networkId: NetworkNumber) => ({
|
|
|
1872
1919
|
[MorphoBlueVersions.MorphoBlueWBTCEth_915]: MORPHO_BLUE_WBTC_ETH_915(networkId),
|
|
1873
1920
|
[MorphoBlueVersions.MorphoBlueCbBTCEth_915_12dbf493]: MORPHO_BLUE_CBBTC_ETH_915_12DBF493(networkId),
|
|
1874
1921
|
[MorphoBlueVersions.MorphoBlueWeEthUSDT_860]: MORPHO_BLUE_WEETH_USDT_860(networkId),
|
|
1922
|
+
[MorphoBlueVersions.MorphoBlueWeEthUSDT_860_a6a4c1f1]: MORPHO_BLUE_WEETH_USDT_860_A6A4C1F1(networkId),
|
|
1875
1923
|
[MorphoBlueVersions.MorphoBlueSyrupUSDTUSDT_915]: MORPHO_BLUE_SYRUPUSDT_USDT_915(networkId),
|
|
1876
1924
|
[MorphoBlueVersions.MorphoBlueCbBTCPYUSD_860]: MORPHO_BLUE_CBBTC_PYUSD_860(networkId),
|
|
1877
1925
|
[MorphoBlueVersions.MorphoBlueWeEthUSDT_770]: MORPHO_BLUE_WEETH_USDT_770(networkId),
|
|
@@ -1930,4 +1978,4 @@ export const findMorphoBlueMarket = (collateralToken: string, loanToken: string,
|
|
|
1930
1978
|
}
|
|
1931
1979
|
}
|
|
1932
1980
|
return null;
|
|
1933
|
-
};
|
|
1981
|
+
};
|
|
@@ -37,7 +37,7 @@ const hasAnyBalance = (balances: PositionBalances): boolean => (
|
|
|
37
37
|
* Uses one shared, multicall-batched viem client (same pattern as getPortfolioData) so all
|
|
38
38
|
* per-market reads collapse into a handful of RPC round trips.
|
|
39
39
|
*
|
|
40
|
-
* Not covered: Maker, Liquity, Liquity V2, Fluid
|
|
40
|
+
* Not covered: Maker, Liquity, Liquity V2, Fluid — these already expose cheap,
|
|
41
41
|
* user-scoped discovery entry points elsewhere in the SDK (e.g. _getUserCdps, _getUserPositionsPortfolio).
|
|
42
42
|
*/
|
|
43
43
|
export async function getUserPositionsExistence(
|
package/src/portfolio/index.ts
CHANGED
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
AaveV4Spokes,
|
|
6
6
|
CompoundMarkets,
|
|
7
7
|
CrvUsdMarkets,
|
|
8
|
-
EulerV2Markets,
|
|
9
8
|
LiquityV2Markets,
|
|
10
9
|
LlamaLendMarkets,
|
|
11
10
|
MorphoBlueMarkets,
|
|
@@ -24,7 +23,6 @@ import {
|
|
|
24
23
|
CompoundV3MarketsData,
|
|
25
24
|
CompoundVersions,
|
|
26
25
|
CrvUSDGlobalMarketData,
|
|
27
|
-
EulerV2FullMarketData,
|
|
28
26
|
LiquityV2MarketData,
|
|
29
27
|
LlamaLendGlobalMarketData,
|
|
30
28
|
MorphoBlueMarketInfo,
|
|
@@ -34,7 +32,6 @@ import {
|
|
|
34
32
|
} from '../types';
|
|
35
33
|
import { _getCompoundV3AccountData, _getCompoundV3MarketsData } from '../compoundV3';
|
|
36
34
|
import { _getSparkAccountData, _getSparkMarketsData } from '../spark';
|
|
37
|
-
import { _getEulerV2AccountData, _getEulerV2MarketsData } from '../eulerV2';
|
|
38
35
|
import { _getCurveUsdGlobalData, _getCurveUsdUserData } from '../curveUsd';
|
|
39
36
|
import { _getLlamaLendGlobalData, _getLlamaLendUserData } from '../llamaLend';
|
|
40
37
|
import { _getAaveV3AccountData, _getAaveV3MarketData, getStakeAaveData } from '../aaveV3';
|
|
@@ -46,7 +43,6 @@ import { getViemProvider } from '../services/viem';
|
|
|
46
43
|
import { _getLiquityTroveInfo, getLiquityStakingData } from '../liquity';
|
|
47
44
|
import { _getLiquityV2MarketData, getLiquitySAndYBold, getLiquityV2Staking } from '../liquityV2';
|
|
48
45
|
import { _getAllUserEarnPositionsWithFTokens, _getUserPositionsPortfolio } from '../fluid';
|
|
49
|
-
import { getEulerV2SubAccounts } from '../helpers/eulerHelpers';
|
|
50
46
|
import { getUmbrellaData } from '../umbrella';
|
|
51
47
|
import { getMeritUnclaimedRewards, getUnclaimedRewardsForAllMarkets } from '../claiming/aaveV3';
|
|
52
48
|
import { getCompoundV3Rewards } from '../claiming/compV3';
|
|
@@ -69,7 +65,6 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
69
65
|
const morphoMidnightMarkets = Object.values(MorphoMidnightMarkets(network)).filter((market) => market.chainIds.includes(network));
|
|
70
66
|
const compoundV3Markets = Object.values(CompoundMarkets(network)).filter((market) => market.chainIds.includes(network) && market.value !== CompoundVersions.CompoundV2);
|
|
71
67
|
const sparkMarkets = Object.values(SparkMarkets(network)).filter((market) => market.chainIds.includes(network));
|
|
72
|
-
const eulerV2Markets = Object.values(EulerV2Markets(network)).filter((market) => market.chainIds.includes(network));
|
|
73
68
|
const aaveV3Markets = [AaveVersions.AaveV3, AaveVersions.AaveV3Lido, AaveVersions.AaveV3Etherfi].map((version) => AaveMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
|
|
74
69
|
const aaveV2Markets = [AaveVersions.AaveV2].map((version) => AaveMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
|
|
75
70
|
const compoundV2Markets = [CompoundVersions.CompoundV2].map((version) => CompoundMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
|
|
@@ -88,7 +83,6 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
88
83
|
const morphoMidnightMarketsData: Record<string, MorphoMidnightMarketInfo> = {};
|
|
89
84
|
const compoundV3MarketsData: Record<string, CompoundV3MarketsData> = {};
|
|
90
85
|
const sparkMarketsData: Record<string, SparkMarketsData> = {};
|
|
91
|
-
const eulerV2MarketsData: Record<string, EulerV2FullMarketData> = {};
|
|
92
86
|
const aaveV3MarketsData: Record<string, AaveV3MarketData> = {};
|
|
93
87
|
const makerCdps: Record<string, CdpInfo[]> = {};
|
|
94
88
|
const aaveV2MarketsData: Record<string, AaveV2MarketData> = {};
|
|
@@ -103,7 +97,6 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
103
97
|
morphoMidnightMarketsData,
|
|
104
98
|
compoundV3MarketsData,
|
|
105
99
|
sparkMarketsData,
|
|
106
|
-
eulerV2MarketsData,
|
|
107
100
|
aaveV3MarketsData,
|
|
108
101
|
aaveV2MarketsData,
|
|
109
102
|
compoundV2MarketsData,
|
|
@@ -126,7 +119,6 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
126
119
|
morphoMidnight: {},
|
|
127
120
|
compoundV3: {},
|
|
128
121
|
spark: {},
|
|
129
|
-
eulerV2: {},
|
|
130
122
|
maker: {},
|
|
131
123
|
aaveV2: {},
|
|
132
124
|
compoundV2: {},
|
|
@@ -187,10 +179,6 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
187
179
|
const marketData = await _getSparkMarketsData(client, network, market);
|
|
188
180
|
sparkMarketsData[market.value] = marketData;
|
|
189
181
|
}),
|
|
190
|
-
...eulerV2Markets.map(async (market) => {
|
|
191
|
-
const marketData = await _getEulerV2MarketsData(client, network, market);
|
|
192
|
-
eulerV2MarketsData[market.value] = marketData;
|
|
193
|
-
}),
|
|
194
182
|
...aaveV3Markets.map(async (market) => {
|
|
195
183
|
const marketData = await _getAaveV3MarketData(client, network, market);
|
|
196
184
|
aaveV3MarketsData[market.value] = marketData;
|
|
@@ -547,27 +535,6 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
547
535
|
positions[address.toLowerCase() as EthAddress].spark[market.value] = { error: `Error fetching Spark account data for address ${address} on market ${market.value}`, data: null };
|
|
548
536
|
}
|
|
549
537
|
})).flat(),
|
|
550
|
-
...eulerV2Markets.map((market) => addresses.map((address) => {
|
|
551
|
-
const eulerV2SubAccounts = getEulerV2SubAccounts(address);
|
|
552
|
-
const eulerV2Addresses = [address, ...eulerV2SubAccounts];
|
|
553
|
-
return Promise.all(eulerV2Addresses.map(async (eulerAddress) => {
|
|
554
|
-
try {
|
|
555
|
-
const accData = await _getEulerV2AccountData(client, network, eulerAddress, eulerAddress, { selectedMarket: market, ...eulerV2MarketsData[market.value] });
|
|
556
|
-
if (new Dec(accData.suppliedUsd).gt(0) || new Dec(accData.borrowedUsd).gt(0)) {
|
|
557
|
-
if (!positions[address.toLowerCase() as EthAddress].eulerV2[market.value]) {
|
|
558
|
-
positions[address.toLowerCase() as EthAddress].eulerV2[market.value] = {};
|
|
559
|
-
}
|
|
560
|
-
positions[address.toLowerCase() as EthAddress].eulerV2[market.value]![eulerAddress.toLowerCase() as EthAddress] = { error: '', data: accData };
|
|
561
|
-
}
|
|
562
|
-
} catch (error) {
|
|
563
|
-
console.error(`Error fetching EulerV2 account data for address ${eulerAddress} on market ${market.value}:`, error);
|
|
564
|
-
if (!positions[address.toLowerCase() as EthAddress].eulerV2[market.value]) {
|
|
565
|
-
positions[address.toLowerCase() as EthAddress].eulerV2[market.value] = {};
|
|
566
|
-
}
|
|
567
|
-
positions[address.toLowerCase() as EthAddress].eulerV2[market.value]![eulerAddress.toLowerCase() as EthAddress] = { error: `Error fetching EulerV2 account data for address ${eulerAddress} on market ${market.value}`, data: null };
|
|
568
|
-
}
|
|
569
|
-
}));
|
|
570
|
-
}).flat()).flat(),
|
|
571
538
|
...addresses.map(async (address) => makerCdps[address.toLowerCase() as EthAddress]?.map(async (cdpInfo) => {
|
|
572
539
|
try {
|
|
573
540
|
const cdpData = await _getMakerCdpData(client, network, cdpInfo);
|
package/src/services/utils.ts
CHANGED
|
@@ -20,6 +20,8 @@ export const isAddress = (address: string) => typeof address === 'string' && (ne
|
|
|
20
20
|
|
|
21
21
|
export const compareAddresses = (addr1 = '', addr2 = '') => addr1.toLowerCase() === addr2.toLowerCase();
|
|
22
22
|
|
|
23
|
+
export const shortenAddress = (address = '', start = 8, end = 4) => `${address.substring(0, start)}...${address.slice(-end)}`;
|
|
24
|
+
|
|
23
25
|
export const getWeiAmountForDecimals = (amount: string | number, decimals: number) => new Dec(amount).mul(10 ** decimals).floor().toString();
|
|
24
26
|
|
|
25
27
|
export const getEthAmountForDecimals = (amount: string | number, decimals: string | number) => new Dec(amount).div(10 ** +decimals).toString();
|
package/src/staking/staking.ts
CHANGED
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
import { BLOCKS_IN_A_YEAR } from '../constants';
|
|
9
9
|
import { DEFAULT_TIMEOUT } from '../services/utils';
|
|
10
10
|
import { EligibilityMapping } from './eligibility';
|
|
11
|
-
import { EulerV2UsedAsset } from '../types';
|
|
12
11
|
|
|
13
12
|
const getSsrApy = async () => {
|
|
14
13
|
try {
|
|
@@ -143,7 +142,7 @@ export const calculateNetApy = ({
|
|
|
143
142
|
}: { usedAssets: MMUsedAssets, assetsData: MMAssetsData, optionalData?: any }) => {
|
|
144
143
|
const sumValues = Object.values(usedAssets).reduce((_acc, usedAsset) => {
|
|
145
144
|
const acc = { ..._acc };
|
|
146
|
-
const assetData = assetsData[usedAsset.symbol]
|
|
145
|
+
const assetData = assetsData[usedAsset.symbol];
|
|
147
146
|
|
|
148
147
|
if (usedAsset.isSupplied) {
|
|
149
148
|
const amount = usedAsset.suppliedUsd;
|
package/src/types/aaveV4.ts
CHANGED
|
@@ -52,6 +52,11 @@ export interface AaveV4SpokeInfo {
|
|
|
52
52
|
value: AaveV4SpokesType,
|
|
53
53
|
url: string,
|
|
54
54
|
address: EthAddress,
|
|
55
|
+
/**
|
|
56
|
+
* Known hub addresses, used only to prefetch hub data in parallel with the spoke data.
|
|
57
|
+
* The on-chain reserves are the source of truth — hubs found there but missing here are
|
|
58
|
+
* fetched dynamically, so this list going stale can't break spoke loading.
|
|
59
|
+
*/
|
|
55
60
|
hubs: EthAddress[],
|
|
56
61
|
}
|
|
57
62
|
|
package/src/types/common.ts
CHANGED
|
@@ -3,6 +3,11 @@ export enum IncentiveKind {
|
|
|
3
3
|
Reward = 'reward',
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
+
export enum IncentiveSide {
|
|
7
|
+
Supply = 'supply',
|
|
8
|
+
Borrow = 'borrow',
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
export enum IncentiveEligibilityId {
|
|
7
12
|
AaveV3EthenaLiquidLeverage = '0x0dC599DBB180E64E42b87332FDeC3a551445ea44BORROW_BL',
|
|
8
13
|
AaveV3ArbitrumEthSupply = '0x5d16261c6715a653248269861bbacf68a9774cde',
|
package/src/types/index.ts
CHANGED