@1delta/margin-fetcher 0.0.156 → 0.0.159
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/dist/abis/compound-v2/SumerLens.d.ts +331 -0
- package/dist/abis/compound-v2/SumerLens.d.ts.map +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1824 -447
- package/dist/index.js.map +1 -1
- package/dist/lending/index.d.ts +2 -0
- package/dist/lending/index.d.ts.map +1 -1
- package/dist/lending/margin/base/borrow.d.ts +10 -0
- package/dist/lending/margin/base/borrow.d.ts.map +1 -0
- package/dist/lending/margin/base/deposit.d.ts +10 -0
- package/dist/lending/margin/base/deposit.d.ts.map +1 -0
- package/dist/lending/margin/base/index.d.ts +7 -0
- package/dist/lending/margin/base/index.d.ts.map +1 -0
- package/dist/lending/margin/base/repay.d.ts +10 -0
- package/dist/lending/margin/base/repay.d.ts.map +1 -0
- package/dist/lending/margin/base/utils.d.ts +17 -0
- package/dist/lending/margin/base/utils.d.ts.map +1 -0
- package/dist/lending/margin/base/withdraw.d.ts +10 -0
- package/dist/lending/margin/base/withdraw.d.ts.map +1 -0
- package/dist/lending/margin/base/yield/getIntrinsicYieldChange.d.ts +22 -0
- package/dist/lending/margin/base/yield/getIntrinsicYieldChange.d.ts.map +1 -0
- package/dist/lending/margin/base/yield/getOrganicYieldChange.d.ts +22 -0
- package/dist/lending/margin/base/yield/getOrganicYieldChange.d.ts.map +1 -0
- package/dist/lending/margin/base/yield/getRewardYieldChange.d.ts +28 -0
- package/dist/lending/margin/base/yield/getRewardYieldChange.d.ts.map +1 -0
- package/dist/lending/margin/base/yield/index.d.ts +4 -0
- package/dist/lending/margin/base/yield/index.d.ts.map +1 -0
- package/dist/lending/margin/loop/compute/computeCloseDeltas.d.ts +8 -0
- package/dist/lending/margin/loop/compute/computeCloseDeltas.d.ts.map +1 -0
- package/dist/lending/margin/loop/compute/computeCollateralSwapDeltas.d.ts +8 -0
- package/dist/lending/margin/loop/compute/computeCollateralSwapDeltas.d.ts.map +1 -0
- package/dist/lending/margin/loop/compute/computeDebtSwapDeltas.d.ts +8 -0
- package/dist/lending/margin/loop/compute/computeDebtSwapDeltas.d.ts.map +1 -0
- package/dist/lending/margin/loop/compute/computeOpenDeltas.d.ts +8 -0
- package/dist/lending/margin/loop/compute/computeOpenDeltas.d.ts.map +1 -0
- package/dist/lending/margin/loop/compute/computeZapDeltas.d.ts +8 -0
- package/dist/lending/margin/loop/compute/computeZapDeltas.d.ts.map +1 -0
- package/dist/lending/margin/loop/compute/index.d.ts +6 -0
- package/dist/lending/margin/loop/compute/index.d.ts.map +1 -0
- package/dist/lending/margin/loop/index.d.ts +5 -0
- package/dist/lending/margin/loop/index.d.ts.map +1 -0
- package/dist/lending/margin/loop/types.d.ts +28 -0
- package/dist/lending/margin/loop/types.d.ts.map +1 -0
- package/dist/lending/margin/loop/utils.d.ts +11 -0
- package/dist/lending/margin/loop/utils.d.ts.map +1 -0
- package/dist/lending/margin/loop/yield/getIntrinsicYieldChange.d.ts +6 -0
- package/dist/lending/margin/loop/yield/getIntrinsicYieldChange.d.ts.map +1 -0
- package/dist/lending/margin/loop/yield/getOraganicYieldChange.d.ts +6 -0
- package/dist/lending/margin/loop/yield/getOraganicYieldChange.d.ts.map +1 -0
- package/dist/lending/margin/loop/yield/getRewardYieldChange.d.ts +22 -0
- package/dist/lending/margin/loop/yield/getRewardYieldChange.d.ts.map +1 -0
- package/dist/lending/margin/loop/yield/index.d.ts +4 -0
- package/dist/lending/margin/loop/yield/index.d.ts.map +1 -0
- package/dist/lending/public-data/addresses/compoundV2.d.ts.map +1 -1
- package/dist/lending/public-data/compound-v2/getters/sumer.d.ts +103 -0
- package/dist/lending/public-data/compound-v2/getters/sumer.d.ts.map +1 -0
- package/dist/lending/public-data/compound-v2/publicCallBuild.d.ts.map +1 -1
- package/dist/lending/public-data/compound-v2/publicCallParse.d.ts.map +1 -1
- package/dist/lending/public-data/fetchLender.d.ts.map +1 -1
- package/dist/lending/public-data/morpho/getMarketsFromChain.d.ts.map +1 -1
- package/dist/lending/user-data/abis.d.ts +1163 -46
- package/dist/lending/user-data/abis.d.ts.map +1 -1
- package/dist/lending/user-data/compound-v2/userCallParse.d.ts.map +1 -1
- package/dist/lending/user-data/fetchUserData.d.ts +3 -3
- package/dist/lending/user-data/fetchUserData.d.ts.map +1 -1
- package/dist/lending/user-data/init/userCallBuild.d.ts +0 -4
- package/dist/lending/user-data/init/userCallBuild.d.ts.map +1 -1
- package/dist/lending/user-data/init/userCallParse.d.ts.map +1 -1
- package/dist/lending/user-data/morpho/decoder.d.ts +1 -1
- package/dist/lending/user-data/morpho/decoder.d.ts.map +1 -1
- package/dist/lending/user-data/morpho/userCallParse.d.ts.map +1 -1
- package/dist/lending/user-data/utils/createSumerUserState.d.ts +6 -0
- package/dist/lending/user-data/utils/createSumerUserState.d.ts.map +1 -0
- package/dist/lending/user-data/utils/index.d.ts +1 -0
- package/dist/lending/user-data/utils/index.d.ts.map +1 -1
- package/dist/lending/user-data/utils/types.d.ts +10 -0
- package/dist/lending/user-data/utils/types.d.ts.map +1 -1
- package/dist/lending-pairs/computeLendingPairs.d.ts.map +1 -1
- package/dist/token/fetchTokenBalance.d.ts +5 -2
- package/dist/token/fetchTokenBalance.d.ts.map +1 -1
- package/dist/types/apiReturnType.d.ts +1 -1
- package/dist/types/apiReturnType.d.ts.map +1 -1
- package/dist/types/lender/aave-v2-types.d.ts +1 -1
- package/dist/types/lender/aave-v2-types.d.ts.map +1 -1
- package/dist/types/lender/compound-v2-types.d.ts +2 -2
- package/dist/types/lender/compound-v2-types.d.ts.map +1 -1
- package/dist/types/lender/morpho-types.d.ts +1 -1
- package/dist/types/lender/morpho-types.d.ts.map +1 -1
- package/dist/types/lenderTypes.d.ts +1 -1
- package/dist/types/lenderTypes.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +5 -3
- package/dist/abis/morpho/blue.d.ts +0 -76
- package/dist/abis/morpho/blue.d.ts.map +0 -1
- package/dist/abis/morpho/lens.d.ts +0 -128
- package/dist/abis/morpho/lens.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -4,6 +4,9 @@ import './chunk-PR4QN5HX.js';
|
|
|
4
4
|
import { Lender, AAVE_V3_LENDERS, AAVE_V2_LENDERS, AAVE_V32_LENDERS, COMPOUND_V2_LENDERS, VENUS_LENDERS } from '@1delta/lender-registry';
|
|
5
5
|
import lodash from 'lodash';
|
|
6
6
|
import { getEvmChain, multicallRetry, getEvmClient, getEvmClientUniversal } from '@1delta/providers';
|
|
7
|
+
import { MorphoLensAbi, MorphoBlueAbi } from '@1delta/abis';
|
|
8
|
+
export { MorphoLensAbi } from '@1delta/abis';
|
|
9
|
+
import { InitMarginAddresses } from '@1delta/calldata-sdk';
|
|
7
10
|
import { BALANCER_V2_FORKS, BALANCER_V3_FORKS, UNISWAP_V4_FORKS, FLASH_LOAN_IDS } from '@1delta/dex-registry';
|
|
8
11
|
|
|
9
12
|
// src/abis/aave-v2/ProtocolDataProvider.ts
|
|
@@ -6263,7 +6266,8 @@ globalThis[GLOBAL_LENDER_DATA_KEY] = {
|
|
|
6263
6266
|
compoundV3Oracles: {},
|
|
6264
6267
|
morphoOracles: {},
|
|
6265
6268
|
morphoTypeOracles: {},
|
|
6266
|
-
morphoTypeMarkets: {}
|
|
6269
|
+
morphoTypeMarkets: {},
|
|
6270
|
+
aaveWethGateway: {}
|
|
6267
6271
|
};
|
|
6268
6272
|
function getGlobalData2() {
|
|
6269
6273
|
return globalThis[GLOBAL_LENDER_DATA_KEY];
|
|
@@ -6282,7 +6286,6 @@ var compoundV3Pools = () => getGlobalData2()?.compoundV3Pools;
|
|
|
6282
6286
|
var morphoPools = () => getGlobalData2()?.morphoPools;
|
|
6283
6287
|
var compoundV3BaseData = () => getGlobalData2()?.compoundV3BaseData;
|
|
6284
6288
|
var compoundV2Pools = () => getGlobalData2()?.compoundV2Pools;
|
|
6285
|
-
var compoundV2Tokens = () => getGlobalData2()?.compoundV2Tokens;
|
|
6286
6289
|
var compoundV2TokenArray = () => getGlobalData2()?.compoundV2TokenArray;
|
|
6287
6290
|
var initConfig = () => getGlobalData2()?.initConfig;
|
|
6288
6291
|
var getListUrl = (chainId) => `https://raw.githubusercontent.com/1delta-DAO/token-lists/main/${chainId}.json`;
|
|
@@ -6349,12 +6352,16 @@ function isCompoundV2Type(lender) {
|
|
|
6349
6352
|
function isVenusType(lender) {
|
|
6350
6353
|
return VENUS_LENDERS.includes(lender);
|
|
6351
6354
|
}
|
|
6355
|
+
function isSumerType(lender) {
|
|
6356
|
+
return lender === Lender.SUMER;
|
|
6357
|
+
}
|
|
6352
6358
|
var ENABLED_COMPOUNDS = [
|
|
6353
6359
|
Lender.VENUS,
|
|
6354
6360
|
Lender.VENUS_ETH,
|
|
6355
6361
|
Lender.MOONWELL,
|
|
6356
6362
|
Lender.ENCLABS,
|
|
6357
|
-
Lender.ENCLABS_LST
|
|
6363
|
+
Lender.ENCLABS_LST,
|
|
6364
|
+
Lender.SUMER
|
|
6358
6365
|
];
|
|
6359
6366
|
var getLendersForChain = (c) => {
|
|
6360
6367
|
let lenders = [];
|
|
@@ -7733,11 +7740,11 @@ var addressesInitCore = {
|
|
|
7733
7740
|
}
|
|
7734
7741
|
};
|
|
7735
7742
|
function getInitPools(chainId, lender) {
|
|
7736
|
-
const
|
|
7737
|
-
if (!
|
|
7738
|
-
return
|
|
7739
|
-
poolId,
|
|
7740
|
-
underlying:
|
|
7743
|
+
const entries = initConfig()?.[lender]?.[chainId];
|
|
7744
|
+
if (!entries) return [];
|
|
7745
|
+
return entries.map((entry) => ({
|
|
7746
|
+
poolId: entry.pool,
|
|
7747
|
+
underlying: entry.underlying
|
|
7741
7748
|
}));
|
|
7742
7749
|
}
|
|
7743
7750
|
function getInitUnderlyingToPoolMap(chainId, lender) {
|
|
@@ -8115,7 +8122,7 @@ var getAaveV2ReservesDataConverter = (lender, chainId, prices, additionalYields,
|
|
|
8115
8122
|
stableBorrowRate: formatAaveRawApyToApr(
|
|
8116
8123
|
reserveData?.[5 /* stableBorrowRate */]?.toString()
|
|
8117
8124
|
),
|
|
8118
|
-
|
|
8125
|
+
intrinsicYield: additionalYields?.intrinsicYields[oracleKey] ?? 0,
|
|
8119
8126
|
// rewards
|
|
8120
8127
|
rewards: lender === Lender.MERIDIAN && chainId === Chain.TAIKO_ALETHIA && additionalYields?.lenderRewards ? {
|
|
8121
8128
|
TAIKO: {
|
|
@@ -8275,7 +8282,7 @@ var getAaveV3ReservesDataConverter = (lender, chainId, prices, additionalYields,
|
|
|
8275
8282
|
stableBorrowRate: formatAaveRawApyToApr(
|
|
8276
8283
|
reserveData?.[7 /* stableBorrowRate */]?.toString()
|
|
8277
8284
|
),
|
|
8278
|
-
|
|
8285
|
+
intrinsicYield: additionalYields.intrinsicYields[toOracleKey(assetMeta?.assetGroup)] ?? 0,
|
|
8279
8286
|
// rewards
|
|
8280
8287
|
rewards: {}
|
|
8281
8288
|
};
|
|
@@ -8475,7 +8482,7 @@ function parseYLDRCall(chainId, lender, additionalYields, prices, tokenList) {
|
|
|
8475
8482
|
reserveData?.[4 /* variableBorrowRate */]?.toString()
|
|
8476
8483
|
),
|
|
8477
8484
|
stableBorrowRate: 0,
|
|
8478
|
-
|
|
8485
|
+
intrinsicYield: additionalYields.intrinsicYields[oracleKey] ?? 0,
|
|
8479
8486
|
// rewards
|
|
8480
8487
|
rewards: {},
|
|
8481
8488
|
decimals: Number(
|
|
@@ -8612,7 +8619,7 @@ function parseAave32(chainId, lender, prices, additionalYields, tokenList) {
|
|
|
8612
8619
|
stableBorrowRate: formatAaveRawApyToApr(
|
|
8613
8620
|
reserveData?.[7 /* stableBorrowRate */]?.toString()
|
|
8614
8621
|
),
|
|
8615
|
-
|
|
8622
|
+
intrinsicYield: additionalYields.intrinsicYields[toOracleKey(assetMeta?.assetGroup)] ?? 0,
|
|
8616
8623
|
// rewards
|
|
8617
8624
|
rewards: {}
|
|
8618
8625
|
};
|
|
@@ -8742,7 +8749,7 @@ var getInitReservesDataConverter = (lender, chainId, prices, additionalYields, t
|
|
|
8742
8749
|
),
|
|
8743
8750
|
stableBorrowRate: 0,
|
|
8744
8751
|
collateralActive: true,
|
|
8745
|
-
|
|
8752
|
+
intrinsicYield: additionalYields.intrinsicYields[oracleKey] ?? 0,
|
|
8746
8753
|
rewards: {},
|
|
8747
8754
|
config: {},
|
|
8748
8755
|
borrowingEnabled: totalDebt !== "0",
|
|
@@ -8854,7 +8861,7 @@ var getCompoundV3ReservesDataConverter = (lender, chainId, prices, additionalYie
|
|
|
8854
8861
|
variableBorrowRate: 0,
|
|
8855
8862
|
stableBorrowRate: 0,
|
|
8856
8863
|
depositRate: 0,
|
|
8857
|
-
|
|
8864
|
+
intrinsicYield: additionalYields.intrinsicYields[oracleKey] ?? 0,
|
|
8858
8865
|
utilization: 0,
|
|
8859
8866
|
// debt and liquidity are zero
|
|
8860
8867
|
totalDebt: 0,
|
|
@@ -8941,7 +8948,7 @@ var getCompoundV3ReservesDataConverter = (lender, chainId, prices, additionalYie
|
|
|
8941
8948
|
collateralActive: false,
|
|
8942
8949
|
isActive: true,
|
|
8943
8950
|
isFrozen: false,
|
|
8944
|
-
|
|
8951
|
+
intrinsicYield: additionalYields.intrinsicYields[oracleKeyBase] ?? 0
|
|
8945
8952
|
}
|
|
8946
8953
|
};
|
|
8947
8954
|
return { data: { ...result, ...baseData }, chainId };
|
|
@@ -10921,9 +10928,9 @@ function createBaseTypeUserState(payload, lenderData, totalDeposits24h = 0, tota
|
|
|
10921
10928
|
rewardApr: safeDivide(rewardDepositAccrual + rewardBorrowAccrual, nav),
|
|
10922
10929
|
rewardDepositApr: safeDivide(rewardDepositAccrual, deposits),
|
|
10923
10930
|
rewardBorrowApr: safeDivide(rewardBorrowAccrual, debt),
|
|
10924
|
-
|
|
10925
|
-
|
|
10926
|
-
|
|
10931
|
+
intrinsicApr: safeDivide(stakingDepositAccrual - stakingBorrowAccrual, nav),
|
|
10932
|
+
intrinsicDepositApr: safeDivide(stakingDepositAccrual, deposits),
|
|
10933
|
+
intrinsicBorrowApr: safeDivide(stakingBorrowAccrual, debt)
|
|
10927
10934
|
};
|
|
10928
10935
|
const userConfig = { selectedMode: mode, id: account, isWhitelisted };
|
|
10929
10936
|
const creditLine = Math.max(
|
|
@@ -10978,6 +10985,209 @@ function createBaseTypeUserState(payload, lenderData, totalDeposits24h = 0, tota
|
|
|
10978
10985
|
};
|
|
10979
10986
|
}
|
|
10980
10987
|
|
|
10988
|
+
// src/lending/user-data/utils/createSumerUserState.ts
|
|
10989
|
+
function computeSumerWaterfall(groups, accum) {
|
|
10990
|
+
let total = 0;
|
|
10991
|
+
for (const g of groups) {
|
|
10992
|
+
const a = accum[g.groupId];
|
|
10993
|
+
if (!a) continue;
|
|
10994
|
+
let cDep = a.cDep;
|
|
10995
|
+
let sDep = a.sDep;
|
|
10996
|
+
let sDebt = a.sDebt;
|
|
10997
|
+
let cDebt = a.cDebt;
|
|
10998
|
+
if (cDep > 0 && sDebt > 0 && g.intraMintRate > 0) {
|
|
10999
|
+
const absorbed = Math.min(cDep * g.intraMintRate, sDebt);
|
|
11000
|
+
total += absorbed;
|
|
11001
|
+
sDebt -= absorbed;
|
|
11002
|
+
cDep -= absorbed / g.intraMintRate;
|
|
11003
|
+
}
|
|
11004
|
+
if (cDep > 0 && cDebt > 0 && g.intraCRate > 0) {
|
|
11005
|
+
const absorbed = Math.min(cDep * g.intraCRate, cDebt);
|
|
11006
|
+
total += absorbed;
|
|
11007
|
+
cDebt -= absorbed;
|
|
11008
|
+
cDep -= absorbed / g.intraCRate;
|
|
11009
|
+
}
|
|
11010
|
+
if (sDep > 0 && sDebt > 0 && g.intraSuRate > 0) {
|
|
11011
|
+
const absorbed = Math.min(sDep * g.intraSuRate, sDebt);
|
|
11012
|
+
total += absorbed;
|
|
11013
|
+
sDebt -= absorbed;
|
|
11014
|
+
sDep -= absorbed / g.intraSuRate;
|
|
11015
|
+
}
|
|
11016
|
+
if (sDep > 0 && cDebt > 0 && g.intraSuRate > 0) {
|
|
11017
|
+
const absorbed = Math.min(sDep * g.intraSuRate, cDebt);
|
|
11018
|
+
total += absorbed;
|
|
11019
|
+
cDebt -= absorbed;
|
|
11020
|
+
sDep -= absorbed / g.intraSuRate;
|
|
11021
|
+
}
|
|
11022
|
+
total += cDep * g.interCRate + sDep * g.interSuRate;
|
|
11023
|
+
}
|
|
11024
|
+
return total;
|
|
11025
|
+
}
|
|
11026
|
+
function createSumerUserState(payload, lenderData, totalDeposits24h = 0, totalDebt24h = 0) {
|
|
11027
|
+
const assetKeys = getMarketUidsFromMeta(lenderData);
|
|
11028
|
+
const { chainId, account } = payload;
|
|
11029
|
+
const isWhitelisted = !Boolean(payload?.notWhitelisted ?? false);
|
|
11030
|
+
const groupRatesMap = {};
|
|
11031
|
+
const gAccum = {};
|
|
11032
|
+
const gAccumAll = {};
|
|
11033
|
+
let depositInterest = 0;
|
|
11034
|
+
let borrowInterest = 0;
|
|
11035
|
+
let rewardDepositAccrual = 0;
|
|
11036
|
+
let rewardBorrowAccrual = 0;
|
|
11037
|
+
let stakingDepositAccrual = 0;
|
|
11038
|
+
let stakingBorrowAccrual = 0;
|
|
11039
|
+
let deposits = 0;
|
|
11040
|
+
let debt = 0;
|
|
11041
|
+
let rewardsPerAsset = {};
|
|
11042
|
+
for (let i = 0; i < assetKeys.length; i++) {
|
|
11043
|
+
const marketUid = assetKeys[i];
|
|
11044
|
+
if (!lenderData?.[marketUid] || !payload.lendingPositions["0"][marketUid])
|
|
11045
|
+
continue;
|
|
11046
|
+
const { depositsUSD, debtStableUSD, debtUSD, collateralEnabled } = payload.lendingPositions["0"][marketUid];
|
|
11047
|
+
const {
|
|
11048
|
+
depositRate,
|
|
11049
|
+
intrinsicYield,
|
|
11050
|
+
variableBorrowRate,
|
|
11051
|
+
stableBorrowRate,
|
|
11052
|
+
rewards,
|
|
11053
|
+
flags,
|
|
11054
|
+
sumerMeta
|
|
11055
|
+
} = lenderData[marketUid];
|
|
11056
|
+
deposits += depositsUSD;
|
|
11057
|
+
debt += debtStableUSD;
|
|
11058
|
+
debt += debtUSD;
|
|
11059
|
+
Object.entries(rewards ?? {}).forEach(
|
|
11060
|
+
([key, rewardData]) => {
|
|
11061
|
+
rewardDepositAccrual += rewardData.depositRate * depositsUSD;
|
|
11062
|
+
rewardBorrowAccrual += rewardData.variableBorrowRate * debtUSD + (rewardData.stableBorrowRate ?? 0) * debtStableUSD;
|
|
11063
|
+
const rewDepo = rewardData.depositRate * depositsUSD;
|
|
11064
|
+
const rewDebt = rewardData.variableBorrowRate * debtUSD + (rewardData.stableBorrowRate ?? 0) * (debtStableUSD ?? 0);
|
|
11065
|
+
if (!rewardsPerAsset[key])
|
|
11066
|
+
rewardsPerAsset[key] = { depositApr: 0, borrowApr: 0 };
|
|
11067
|
+
if (rewDepo > 0) rewardsPerAsset[key].depositApr += rewDepo;
|
|
11068
|
+
if (rewDebt > 0) rewardsPerAsset[key].borrowApr += rewDebt;
|
|
11069
|
+
}
|
|
11070
|
+
);
|
|
11071
|
+
stakingDepositAccrual += (intrinsicYield ?? 0) * depositsUSD;
|
|
11072
|
+
stakingBorrowAccrual += (intrinsicYield ?? 0) * (debtStableUSD + debtUSD);
|
|
11073
|
+
if (sumerMeta) {
|
|
11074
|
+
const gId = sumerMeta.groupId;
|
|
11075
|
+
if (!groupRatesMap[gId]) groupRatesMap[gId] = sumerMeta;
|
|
11076
|
+
if (!gAccum[gId])
|
|
11077
|
+
gAccum[gId] = { cDep: 0, sDep: 0, cDebt: 0, sDebt: 0 };
|
|
11078
|
+
if (!gAccumAll[gId])
|
|
11079
|
+
gAccumAll[gId] = { cDep: 0, sDep: 0, cDebt: 0, sDebt: 0 };
|
|
11080
|
+
const totalDebtForPos = debtUSD + debtStableUSD;
|
|
11081
|
+
if (sumerMeta.isCToken) {
|
|
11082
|
+
if (flags?.collateralActive && collateralEnabled)
|
|
11083
|
+
gAccum[gId].cDep += depositsUSD;
|
|
11084
|
+
if (flags?.collateralActive) gAccumAll[gId].cDep += depositsUSD;
|
|
11085
|
+
gAccum[gId].cDebt += totalDebtForPos;
|
|
11086
|
+
gAccumAll[gId].cDebt += totalDebtForPos;
|
|
11087
|
+
} else {
|
|
11088
|
+
if (flags?.collateralActive && collateralEnabled)
|
|
11089
|
+
gAccum[gId].sDep += depositsUSD;
|
|
11090
|
+
if (flags?.collateralActive) gAccumAll[gId].sDep += depositsUSD;
|
|
11091
|
+
gAccum[gId].sDebt += totalDebtForPos;
|
|
11092
|
+
gAccumAll[gId].sDebt += totalDebtForPos;
|
|
11093
|
+
}
|
|
11094
|
+
}
|
|
11095
|
+
depositInterest += depositRate * depositsUSD;
|
|
11096
|
+
borrowInterest += debtStableUSD * stableBorrowRate + debtUSD * variableBorrowRate;
|
|
11097
|
+
}
|
|
11098
|
+
const borrowDiscountedCollateral = computeSumerWaterfall(
|
|
11099
|
+
Object.values(groupRatesMap),
|
|
11100
|
+
gAccum
|
|
11101
|
+
);
|
|
11102
|
+
const borrowDiscountedCollateralAllActive = computeSumerWaterfall(
|
|
11103
|
+
Object.values(groupRatesMap),
|
|
11104
|
+
gAccumAll
|
|
11105
|
+
);
|
|
11106
|
+
const nav = deposits - debt;
|
|
11107
|
+
const balanceData2 = {
|
|
11108
|
+
borrowDiscountedCollateral,
|
|
11109
|
+
borrowDiscountedCollateralAllActive,
|
|
11110
|
+
collateral: borrowDiscountedCollateral,
|
|
11111
|
+
collateralAllActive: borrowDiscountedCollateralAllActive,
|
|
11112
|
+
deposits,
|
|
11113
|
+
debt,
|
|
11114
|
+
adjustedDebt: debt,
|
|
11115
|
+
nav,
|
|
11116
|
+
deposits24h: totalDeposits24h,
|
|
11117
|
+
debt24h: totalDebt24h,
|
|
11118
|
+
nav24h: totalDeposits24h - totalDebt24h,
|
|
11119
|
+
...payload.rewards ? { rewards: payload.rewards } : {}
|
|
11120
|
+
};
|
|
11121
|
+
const aprData2 = {
|
|
11122
|
+
apr: safeDivide(depositInterest - borrowInterest, nav),
|
|
11123
|
+
borrowApr: safeDivide(borrowInterest, debt),
|
|
11124
|
+
depositApr: safeDivide(depositInterest, deposits),
|
|
11125
|
+
rewards: divideAccrualsToAprs(rewardsPerAsset, nav, deposits, debt),
|
|
11126
|
+
rewardApr: safeDivide(rewardDepositAccrual + rewardBorrowAccrual, nav),
|
|
11127
|
+
rewardDepositApr: safeDivide(rewardDepositAccrual, deposits),
|
|
11128
|
+
rewardBorrowApr: safeDivide(rewardBorrowAccrual, debt),
|
|
11129
|
+
intrinsicApr: safeDivide(stakingDepositAccrual - stakingBorrowAccrual, nav),
|
|
11130
|
+
intrinsicDepositApr: safeDivide(stakingDepositAccrual, deposits),
|
|
11131
|
+
intrinsicBorrowApr: safeDivide(stakingBorrowAccrual, debt)
|
|
11132
|
+
};
|
|
11133
|
+
const userConfig = { selectedMode: 0, id: account, isWhitelisted };
|
|
11134
|
+
const creditLine = Math.max(
|
|
11135
|
+
0,
|
|
11136
|
+
borrowDiscountedCollateral - balanceData2.adjustedDebt
|
|
11137
|
+
);
|
|
11138
|
+
for (let i = 0; i < assetKeys.length; i++) {
|
|
11139
|
+
const marketUid = assetKeys[i];
|
|
11140
|
+
const pos = payload.lendingPositions["0"][marketUid];
|
|
11141
|
+
if (!pos || !lenderData?.[marketUid]) continue;
|
|
11142
|
+
const {
|
|
11143
|
+
configs,
|
|
11144
|
+
flags,
|
|
11145
|
+
price: priceInfo,
|
|
11146
|
+
sumerMeta: sm
|
|
11147
|
+
} = lenderData[marketUid];
|
|
11148
|
+
const config = configs?.[sm?.groupId ?? 0];
|
|
11149
|
+
const price = priceInfo?.priceUsd ?? 1;
|
|
11150
|
+
const bcf = config?.borrowCollateralFactor ?? 1;
|
|
11151
|
+
const bf = config?.borrowFactor ?? 1;
|
|
11152
|
+
let withdrawable;
|
|
11153
|
+
if (!pos.collateralEnabled || config?.collateralDisabled) {
|
|
11154
|
+
withdrawable = String(pos.deposits);
|
|
11155
|
+
} else if (balanceData2.debt === 0) {
|
|
11156
|
+
withdrawable = String(pos.deposits);
|
|
11157
|
+
} else {
|
|
11158
|
+
const withdrawableUSD = Math.max(creditLine / bcf, 0);
|
|
11159
|
+
withdrawable = String(
|
|
11160
|
+
Math.min(withdrawableUSD / price, Number(pos.deposits))
|
|
11161
|
+
);
|
|
11162
|
+
}
|
|
11163
|
+
let borrowable;
|
|
11164
|
+
if (!flags?.borrowingEnabled || flags?.isFrozen || config?.debtDisabled) {
|
|
11165
|
+
borrowable = "0";
|
|
11166
|
+
} else {
|
|
11167
|
+
const borrowableUSD = Math.max(creditLine / bf, 0);
|
|
11168
|
+
borrowable = String(borrowableUSD / price);
|
|
11169
|
+
}
|
|
11170
|
+
pos.withdrawable = withdrawable;
|
|
11171
|
+
pos.borrowable = borrowable;
|
|
11172
|
+
}
|
|
11173
|
+
return {
|
|
11174
|
+
lender: "",
|
|
11175
|
+
account,
|
|
11176
|
+
chainId,
|
|
11177
|
+
data: [
|
|
11178
|
+
{
|
|
11179
|
+
health: balanceData2.debt === 0 ? null : balanceData2.adjustedDebt > 0 ? balanceData2.borrowDiscountedCollateral / balanceData2.adjustedDebt : balanceData2.collateral / balanceData2.debt,
|
|
11180
|
+
borrowCapacityUSD: creditLine,
|
|
11181
|
+
accountId: "0",
|
|
11182
|
+
balanceData: balanceData2,
|
|
11183
|
+
aprData: aprData2,
|
|
11184
|
+
userConfig,
|
|
11185
|
+
positions: Object.values(payload.lendingPositions["0"])
|
|
11186
|
+
}
|
|
11187
|
+
]
|
|
11188
|
+
};
|
|
11189
|
+
}
|
|
11190
|
+
|
|
10981
11191
|
// src/lending/user-data/utils/createMultiAccountStyleUserState.ts
|
|
10982
11192
|
function createMultiAccountTypeUserState(payload, lenderData, histData) {
|
|
10983
11193
|
const positionKeys = Object.keys(payload.lendingPositions ?? {});
|
|
@@ -11052,9 +11262,9 @@ function createMultiAccountTypeUserState(payload, lenderData, histData) {
|
|
|
11052
11262
|
rewardApr: safeDivide(rewardDepositAccrual + rewardBorrowAccrual, nav),
|
|
11053
11263
|
rewardDepositApr: safeDivide(rewardDepositAccrual, deposits),
|
|
11054
11264
|
rewardBorrowApr: safeDivide(rewardBorrowAccrual, debt),
|
|
11055
|
-
|
|
11056
|
-
|
|
11057
|
-
|
|
11265
|
+
intrinsicApr: safeDivide(stakingDepositAccrual - stakingBorrowAccrual, nav),
|
|
11266
|
+
intrinsicDepositApr: safeDivide(stakingDepositAccrual, deposits),
|
|
11267
|
+
intrinsicBorrowApr: safeDivide(stakingBorrowAccrual, debt),
|
|
11058
11268
|
rewards: {}
|
|
11059
11269
|
};
|
|
11060
11270
|
const creditLine = Math.max(0, borrowDiscountedCollateral - adjustedDebt);
|
|
@@ -11197,7 +11407,7 @@ function convertMarketsToMorphoResponse(response, chainId, additionalYields = {
|
|
|
11197
11407
|
depositRate: apyToApr2(Number(state.supplyApy)) * 100,
|
|
11198
11408
|
variableBorrowRate: apyToApr2(Number(state.borrowApy)) * 100,
|
|
11199
11409
|
stableBorrowRate: 0,
|
|
11200
|
-
|
|
11410
|
+
intrinsicYield: additionalYields.intrinsicYields[meta?.assetGroup] ?? 0,
|
|
11201
11411
|
rewards: Object.keys(loanRewards).length > 0 ? loanRewards : void 0,
|
|
11202
11412
|
decimals: loanAsset.decimals,
|
|
11203
11413
|
config: {
|
|
@@ -11241,7 +11451,7 @@ function convertMarketsToMorphoResponse(response, chainId, additionalYields = {
|
|
|
11241
11451
|
depositRate: 0,
|
|
11242
11452
|
variableBorrowRate: 0,
|
|
11243
11453
|
stableBorrowRate: 0,
|
|
11244
|
-
|
|
11454
|
+
intrinsicYield: additionalYields.intrinsicYields[metaCollateral?.assetGroup] ?? 0,
|
|
11245
11455
|
rewards: void 0,
|
|
11246
11456
|
decimals: collateralAsset.decimals,
|
|
11247
11457
|
config: {
|
|
@@ -11877,7 +12087,7 @@ function getListaMarketDataConverter(lender, chainId, prices, additionalYields =
|
|
|
11877
12087
|
depositRate: depositApr,
|
|
11878
12088
|
variableBorrowRate: borrowApr,
|
|
11879
12089
|
stableBorrowRate: 0,
|
|
11880
|
-
|
|
12090
|
+
intrinsicYield: additionalYields.intrinsicYields[meta?.assetGroup] ?? 0,
|
|
11881
12091
|
rewards: Object.keys(loanRewards).length > 0 ? loanRewards : void 0,
|
|
11882
12092
|
decimals: loanDecimals,
|
|
11883
12093
|
config: {
|
|
@@ -11915,7 +12125,7 @@ function getListaMarketDataConverter(lender, chainId, prices, additionalYields =
|
|
|
11915
12125
|
depositRate: 0,
|
|
11916
12126
|
variableBorrowRate: 0,
|
|
11917
12127
|
stableBorrowRate: 0,
|
|
11918
|
-
|
|
12128
|
+
intrinsicYield: additionalYields.intrinsicYields[metaCollateral?.assetGroup] ?? 0,
|
|
11919
12129
|
rewards: void 0,
|
|
11920
12130
|
decimals: collateralDecimals,
|
|
11921
12131
|
config: {
|
|
@@ -12013,7 +12223,7 @@ function getMorphoMarketDataConverter(lender, chainId, prices, additionalYields
|
|
|
12013
12223
|
decoded.forEach((market, i) => {
|
|
12014
12224
|
const uniqueKey = markets[i];
|
|
12015
12225
|
const { lltv, irm, oracle, loanToken, collateralToken, ...state } = market;
|
|
12016
|
-
if (collateralToken && loanToken && oracle) {
|
|
12226
|
+
if (collateralToken && loanToken && oracle && collateralToken !== zeroAddress && loanToken !== zeroAddress) {
|
|
12017
12227
|
const m = "MORPHO_BLUE_" + uniqueKey.slice(2).toUpperCase();
|
|
12018
12228
|
if (!data[m]) data[m] = { data: {} };
|
|
12019
12229
|
const loanRewards = {};
|
|
@@ -12076,7 +12286,7 @@ function getMorphoMarketDataConverter(lender, chainId, prices, additionalYields
|
|
|
12076
12286
|
depositRate: depositApr,
|
|
12077
12287
|
variableBorrowRate: borrowApr,
|
|
12078
12288
|
stableBorrowRate: 0,
|
|
12079
|
-
|
|
12289
|
+
intrinsicYield: additionalYields.intrinsicYields[meta?.assetGroup] ?? 0,
|
|
12080
12290
|
rewards: Object.keys(loanRewards).length > 0 ? loanRewards : void 0,
|
|
12081
12291
|
decimals: loanDecimals,
|
|
12082
12292
|
config: {
|
|
@@ -12115,7 +12325,7 @@ function getMorphoMarketDataConverter(lender, chainId, prices, additionalYields
|
|
|
12115
12325
|
depositRate: 0,
|
|
12116
12326
|
variableBorrowRate: 0,
|
|
12117
12327
|
stableBorrowRate: 0,
|
|
12118
|
-
|
|
12328
|
+
intrinsicYield: additionalYields.intrinsicYields[metaCollateral?.assetGroup] ?? 0,
|
|
12119
12329
|
rewards: void 0,
|
|
12120
12330
|
decimals: collateralDecimals,
|
|
12121
12331
|
config: {
|
|
@@ -12155,137 +12365,6 @@ function getMorphoMarketDataConverter(lender, chainId, prices, additionalYields
|
|
|
12155
12365
|
markets.length > 0 ? Math.ceil(markets.length / MARKET_CHUNK_SIZE) : 0
|
|
12156
12366
|
];
|
|
12157
12367
|
}
|
|
12158
|
-
|
|
12159
|
-
// src/abis/morpho/lens.ts
|
|
12160
|
-
var MorphoLensAbi = [
|
|
12161
|
-
{
|
|
12162
|
-
inputs: [
|
|
12163
|
-
{
|
|
12164
|
-
internalType: "bytes32[]",
|
|
12165
|
-
name: "marketsIds",
|
|
12166
|
-
type: "bytes32[]"
|
|
12167
|
-
},
|
|
12168
|
-
{
|
|
12169
|
-
internalType: "address",
|
|
12170
|
-
name: "user",
|
|
12171
|
-
type: "address"
|
|
12172
|
-
},
|
|
12173
|
-
{
|
|
12174
|
-
internalType: "address",
|
|
12175
|
-
name: "morpho",
|
|
12176
|
-
type: "address"
|
|
12177
|
-
}
|
|
12178
|
-
],
|
|
12179
|
-
name: "getUserDataCompact",
|
|
12180
|
-
outputs: [
|
|
12181
|
-
{
|
|
12182
|
-
internalType: "bytes",
|
|
12183
|
-
name: "data",
|
|
12184
|
-
type: "bytes"
|
|
12185
|
-
}
|
|
12186
|
-
],
|
|
12187
|
-
stateMutability: "view",
|
|
12188
|
-
type: "function"
|
|
12189
|
-
},
|
|
12190
|
-
{
|
|
12191
|
-
name: "getMarketDataCompact",
|
|
12192
|
-
type: "function",
|
|
12193
|
-
stateMutability: "view",
|
|
12194
|
-
inputs: [
|
|
12195
|
-
{ type: "address", name: "morpho" },
|
|
12196
|
-
{ type: "bytes32[]", name: "marketsIds" }
|
|
12197
|
-
],
|
|
12198
|
-
outputs: [{ type: "bytes", name: "data" }]
|
|
12199
|
-
},
|
|
12200
|
-
{
|
|
12201
|
-
inputs: [
|
|
12202
|
-
{
|
|
12203
|
-
internalType: "bytes32[]",
|
|
12204
|
-
name: "marketsIds",
|
|
12205
|
-
type: "bytes32[]"
|
|
12206
|
-
},
|
|
12207
|
-
{
|
|
12208
|
-
internalType: "address",
|
|
12209
|
-
name: "user",
|
|
12210
|
-
type: "address"
|
|
12211
|
-
},
|
|
12212
|
-
{
|
|
12213
|
-
internalType: "address",
|
|
12214
|
-
name: "morpho",
|
|
12215
|
-
type: "address"
|
|
12216
|
-
}
|
|
12217
|
-
],
|
|
12218
|
-
name: "getUserDataCompact",
|
|
12219
|
-
outputs: [
|
|
12220
|
-
{
|
|
12221
|
-
internalType: "bytes",
|
|
12222
|
-
name: "data",
|
|
12223
|
-
type: "bytes"
|
|
12224
|
-
}
|
|
12225
|
-
],
|
|
12226
|
-
stateMutability: "view",
|
|
12227
|
-
type: "function"
|
|
12228
|
-
},
|
|
12229
|
-
{
|
|
12230
|
-
name: "getMoolahMarketDataCompact",
|
|
12231
|
-
type: "function",
|
|
12232
|
-
stateMutability: "view",
|
|
12233
|
-
inputs: [
|
|
12234
|
-
{ type: "address", name: "morpho" },
|
|
12235
|
-
{ type: "bytes32[]", name: "marketsIds" }
|
|
12236
|
-
],
|
|
12237
|
-
outputs: [{ type: "bytes", name: "data" }]
|
|
12238
|
-
},
|
|
12239
|
-
{
|
|
12240
|
-
inputs: [
|
|
12241
|
-
{
|
|
12242
|
-
internalType: "bytes32[]",
|
|
12243
|
-
name: "marketsIds",
|
|
12244
|
-
type: "bytes32[]"
|
|
12245
|
-
},
|
|
12246
|
-
{
|
|
12247
|
-
internalType: "address",
|
|
12248
|
-
name: "user",
|
|
12249
|
-
type: "address"
|
|
12250
|
-
},
|
|
12251
|
-
{
|
|
12252
|
-
internalType: "address",
|
|
12253
|
-
name: "morpho",
|
|
12254
|
-
type: "address"
|
|
12255
|
-
}
|
|
12256
|
-
],
|
|
12257
|
-
name: "getListaUserDataCompact",
|
|
12258
|
-
outputs: [
|
|
12259
|
-
{
|
|
12260
|
-
internalType: "bytes",
|
|
12261
|
-
name: "data",
|
|
12262
|
-
type: "bytes"
|
|
12263
|
-
}
|
|
12264
|
-
],
|
|
12265
|
-
stateMutability: "view",
|
|
12266
|
-
type: "function"
|
|
12267
|
-
},
|
|
12268
|
-
{
|
|
12269
|
-
name: "getMoolahMarketDataCompact",
|
|
12270
|
-
type: "function",
|
|
12271
|
-
stateMutability: "view",
|
|
12272
|
-
inputs: [
|
|
12273
|
-
{ type: "address", name: "morpho" },
|
|
12274
|
-
{ type: "bytes32[]", name: "marketsIds" }
|
|
12275
|
-
],
|
|
12276
|
-
outputs: [{ type: "bytes", name: "data" }]
|
|
12277
|
-
},
|
|
12278
|
-
{
|
|
12279
|
-
name: "getListaMarketDataCompact",
|
|
12280
|
-
type: "function",
|
|
12281
|
-
stateMutability: "view",
|
|
12282
|
-
inputs: [
|
|
12283
|
-
{ type: "address", name: "morpho" },
|
|
12284
|
-
{ type: "bytes32[]", name: "marketsIds" }
|
|
12285
|
-
],
|
|
12286
|
-
outputs: [{ type: "bytes", name: "data" }]
|
|
12287
|
-
}
|
|
12288
|
-
];
|
|
12289
12368
|
var VENUS_LENS_VBNB = "0xf15A9c5aaDc327B383945D5821C7aC08Cdac7430";
|
|
12290
12369
|
var VENUS_LENS = {
|
|
12291
12370
|
[Chain.BNB_SMART_CHAIN_MAINNET]: "0xA179d2f1Fd53D15Bc790bE91d5fF4a0108E29621",
|
|
@@ -12296,6 +12375,15 @@ var VENUS_LENS = {
|
|
|
12296
12375
|
[Chain.OP_MAINNET]: "0x142160A2E699e33af337741f157D96aAd6bC72aA",
|
|
12297
12376
|
[Chain.UNICHAIN]: "0xe192aeDBDBd235DBF33Ea1444f2B908Ea3E78419"
|
|
12298
12377
|
};
|
|
12378
|
+
var SUMER_LENS = {
|
|
12379
|
+
[Chain.BNB_SMART_CHAIN_MAINNET]: "0xB7ea94340e65CC68d1274aE483dfBE593fD6f21e",
|
|
12380
|
+
// [Chain.ETHEREUM_MAINNET]: '',
|
|
12381
|
+
[Chain.ARBITRUM_ONE]: "0xbdBCf25E9187350b9102E316b707B1B2c7E51492",
|
|
12382
|
+
[Chain.BASE]: "0x2B43fBb7D1171bCfA31c9685f24A417dC8757064",
|
|
12383
|
+
[Chain.BERACHAIN]: "0x85D682FA4115f6a1Ed91170E705A50D532e3B6BD",
|
|
12384
|
+
[Chain.CORE_BLOCKCHAIN_MAINNET]: "0x894fc5177d8e670A4EF4C0aDA2FC5C04861b46Ab",
|
|
12385
|
+
[Chain.HEMI_NETWORK]: "0x6f064Eca024f7065b09372FEe1f8a3854843decA"
|
|
12386
|
+
};
|
|
12299
12387
|
var MOONWELL_LENS = {
|
|
12300
12388
|
[Chain.OP_MAINNET]: "0xD6C66868f937f00604d0FB860241970D6CC2CBfE",
|
|
12301
12389
|
[Chain.BASE]: "0x6834770aba6c2028f448e3259ddee4bcb879d459",
|
|
@@ -12310,14 +12398,12 @@ var COMPOUND_V2_LENS = {
|
|
|
12310
12398
|
[Lender.VENUS_ETH]: VENUS_LENS,
|
|
12311
12399
|
[Lender.MOONWELL]: MOONWELL_LENS,
|
|
12312
12400
|
[Lender.ENCLABS]: ENCLABS_LENS,
|
|
12313
|
-
[Lender.ENCLABS_LST]: ENCLABS_LENS
|
|
12401
|
+
[Lender.ENCLABS_LST]: ENCLABS_LENS,
|
|
12402
|
+
[Lender.SUMER]: SUMER_LENS
|
|
12314
12403
|
};
|
|
12315
12404
|
function getCompoundV2Comptroller(chainId, lender = Lender.VENUS) {
|
|
12316
12405
|
return compoundV2Pools()?.[lender]?.[chainId];
|
|
12317
12406
|
}
|
|
12318
|
-
function getCompoundV2CollateralTokens(chainId, lender = Lender.VENUS) {
|
|
12319
|
-
return compoundV2Tokens()?.[lender]?.[chainId];
|
|
12320
|
-
}
|
|
12321
12407
|
function getCompoundV2Lens(chainId, lender) {
|
|
12322
12408
|
return COMPOUND_V2_LENS[lender]?.[chainId];
|
|
12323
12409
|
}
|
|
@@ -12465,40 +12551,266 @@ var VenusLensLegacyAbi = [
|
|
|
12465
12551
|
}
|
|
12466
12552
|
];
|
|
12467
12553
|
|
|
12468
|
-
// src/
|
|
12469
|
-
var
|
|
12470
|
-
|
|
12471
|
-
|
|
12472
|
-
|
|
12473
|
-
|
|
12474
|
-
|
|
12475
|
-
|
|
12476
|
-
|
|
12477
|
-
|
|
12478
|
-
return (tk) => chainId === Chain.BNB_SMART_CHAIN_MAINNET && tk === "0xa07c5b74c9b40447a954e1466938b865b6bbea36" ? {
|
|
12479
|
-
abi: VenusLensLegacyAbi,
|
|
12480
|
-
address: VENUS_LENS_VBNB,
|
|
12481
|
-
name: "vTokenMetadata",
|
|
12482
|
-
params: [tk]
|
|
12483
|
-
} : {
|
|
12484
|
-
address: lens,
|
|
12485
|
-
name: "vTokenMetadata",
|
|
12486
|
-
params: [tk]
|
|
12487
|
-
};
|
|
12488
|
-
}
|
|
12489
|
-
if (lender === Lender.MOONWELL) {
|
|
12490
|
-
return (tk) => ({
|
|
12491
|
-
address: lens,
|
|
12492
|
-
name: "getMarketInfo",
|
|
12493
|
-
params: [tk]
|
|
12494
|
-
});
|
|
12495
|
-
}
|
|
12496
|
-
return (tk) => ({
|
|
12497
|
-
address: lens,
|
|
12554
|
+
// src/abis/compound-v2/SumerLens.ts
|
|
12555
|
+
var SumerLensAbi = [
|
|
12556
|
+
{
|
|
12557
|
+
inputs: [
|
|
12558
|
+
{
|
|
12559
|
+
internalType: "contract ICToken",
|
|
12560
|
+
name: "cToken",
|
|
12561
|
+
type: "address"
|
|
12562
|
+
}
|
|
12563
|
+
],
|
|
12498
12564
|
name: "cTokenMetadata",
|
|
12499
|
-
|
|
12500
|
-
|
|
12501
|
-
|
|
12565
|
+
outputs: [
|
|
12566
|
+
{
|
|
12567
|
+
components: [
|
|
12568
|
+
{ internalType: "address", name: "cToken", type: "address" },
|
|
12569
|
+
{
|
|
12570
|
+
internalType: "uint256",
|
|
12571
|
+
name: "exchangeRateCurrent",
|
|
12572
|
+
type: "uint256"
|
|
12573
|
+
},
|
|
12574
|
+
{
|
|
12575
|
+
internalType: "uint256",
|
|
12576
|
+
name: "supplyRatePerBlock",
|
|
12577
|
+
type: "uint256"
|
|
12578
|
+
},
|
|
12579
|
+
{
|
|
12580
|
+
internalType: "uint256",
|
|
12581
|
+
name: "borrowRatePerBlock",
|
|
12582
|
+
type: "uint256"
|
|
12583
|
+
},
|
|
12584
|
+
{
|
|
12585
|
+
internalType: "uint256",
|
|
12586
|
+
name: "reserveFactorMantissa",
|
|
12587
|
+
type: "uint256"
|
|
12588
|
+
},
|
|
12589
|
+
{ internalType: "uint256", name: "totalBorrows", type: "uint256" },
|
|
12590
|
+
{ internalType: "uint256", name: "totalReserves", type: "uint256" },
|
|
12591
|
+
{ internalType: "uint256", name: "totalSupply", type: "uint256" },
|
|
12592
|
+
{ internalType: "uint256", name: "totalCash", type: "uint256" },
|
|
12593
|
+
{ internalType: "bool", name: "isListed", type: "bool" },
|
|
12594
|
+
{
|
|
12595
|
+
internalType: "address",
|
|
12596
|
+
name: "underlyingAssetAddress",
|
|
12597
|
+
type: "address"
|
|
12598
|
+
},
|
|
12599
|
+
{ internalType: "uint256", name: "cTokenDecimals", type: "uint256" },
|
|
12600
|
+
{
|
|
12601
|
+
internalType: "uint256",
|
|
12602
|
+
name: "underlyingDecimals",
|
|
12603
|
+
type: "uint256"
|
|
12604
|
+
},
|
|
12605
|
+
{ internalType: "bool", name: "isCToken", type: "bool" },
|
|
12606
|
+
{ internalType: "bool", name: "isCEther", type: "bool" },
|
|
12607
|
+
{ internalType: "uint256", name: "borrowCap", type: "uint256" },
|
|
12608
|
+
{ internalType: "uint256", name: "depositCap", type: "uint256" },
|
|
12609
|
+
{
|
|
12610
|
+
internalType: "uint256",
|
|
12611
|
+
name: "heteroLiquidationIncentive",
|
|
12612
|
+
type: "uint256"
|
|
12613
|
+
},
|
|
12614
|
+
{
|
|
12615
|
+
internalType: "uint256",
|
|
12616
|
+
name: "homoLiquidationIncentive",
|
|
12617
|
+
type: "uint256"
|
|
12618
|
+
},
|
|
12619
|
+
{
|
|
12620
|
+
internalType: "uint256",
|
|
12621
|
+
name: "sutokenLiquidationIncentive",
|
|
12622
|
+
type: "uint256"
|
|
12623
|
+
},
|
|
12624
|
+
{ internalType: "uint8", name: "groupId", type: "uint8" },
|
|
12625
|
+
{ internalType: "uint256", name: "intraRate", type: "uint256" },
|
|
12626
|
+
{ internalType: "uint256", name: "interRate", type: "uint256" },
|
|
12627
|
+
{ internalType: "uint256", name: "mintRate", type: "uint256" },
|
|
12628
|
+
{ internalType: "uint256", name: "discountRate", type: "uint256" },
|
|
12629
|
+
{ internalType: "bool", name: "interMintAllowed", type: "bool" }
|
|
12630
|
+
],
|
|
12631
|
+
internalType: "struct SumerLens.CTokenMetadata",
|
|
12632
|
+
name: "",
|
|
12633
|
+
type: "tuple"
|
|
12634
|
+
}
|
|
12635
|
+
],
|
|
12636
|
+
stateMutability: "nonpayable",
|
|
12637
|
+
type: "function"
|
|
12638
|
+
},
|
|
12639
|
+
{
|
|
12640
|
+
inputs: [
|
|
12641
|
+
{
|
|
12642
|
+
internalType: "contract ICToken[]",
|
|
12643
|
+
name: "cTokens",
|
|
12644
|
+
type: "address[]"
|
|
12645
|
+
}
|
|
12646
|
+
],
|
|
12647
|
+
name: "cTokenMetadataAll",
|
|
12648
|
+
outputs: [
|
|
12649
|
+
{
|
|
12650
|
+
components: [
|
|
12651
|
+
{ internalType: "address", name: "cToken", type: "address" },
|
|
12652
|
+
{
|
|
12653
|
+
internalType: "uint256",
|
|
12654
|
+
name: "exchangeRateCurrent",
|
|
12655
|
+
type: "uint256"
|
|
12656
|
+
},
|
|
12657
|
+
{
|
|
12658
|
+
internalType: "uint256",
|
|
12659
|
+
name: "supplyRatePerBlock",
|
|
12660
|
+
type: "uint256"
|
|
12661
|
+
},
|
|
12662
|
+
{
|
|
12663
|
+
internalType: "uint256",
|
|
12664
|
+
name: "borrowRatePerBlock",
|
|
12665
|
+
type: "uint256"
|
|
12666
|
+
},
|
|
12667
|
+
{
|
|
12668
|
+
internalType: "uint256",
|
|
12669
|
+
name: "reserveFactorMantissa",
|
|
12670
|
+
type: "uint256"
|
|
12671
|
+
},
|
|
12672
|
+
{ internalType: "uint256", name: "totalBorrows", type: "uint256" },
|
|
12673
|
+
{ internalType: "uint256", name: "totalReserves", type: "uint256" },
|
|
12674
|
+
{ internalType: "uint256", name: "totalSupply", type: "uint256" },
|
|
12675
|
+
{ internalType: "uint256", name: "totalCash", type: "uint256" },
|
|
12676
|
+
{ internalType: "bool", name: "isListed", type: "bool" },
|
|
12677
|
+
{
|
|
12678
|
+
internalType: "address",
|
|
12679
|
+
name: "underlyingAssetAddress",
|
|
12680
|
+
type: "address"
|
|
12681
|
+
},
|
|
12682
|
+
{ internalType: "uint256", name: "cTokenDecimals", type: "uint256" },
|
|
12683
|
+
{
|
|
12684
|
+
internalType: "uint256",
|
|
12685
|
+
name: "underlyingDecimals",
|
|
12686
|
+
type: "uint256"
|
|
12687
|
+
},
|
|
12688
|
+
{ internalType: "bool", name: "isCToken", type: "bool" },
|
|
12689
|
+
{ internalType: "bool", name: "isCEther", type: "bool" },
|
|
12690
|
+
{ internalType: "uint256", name: "borrowCap", type: "uint256" },
|
|
12691
|
+
{ internalType: "uint256", name: "depositCap", type: "uint256" },
|
|
12692
|
+
{
|
|
12693
|
+
internalType: "uint256",
|
|
12694
|
+
name: "heteroLiquidationIncentive",
|
|
12695
|
+
type: "uint256"
|
|
12696
|
+
},
|
|
12697
|
+
{
|
|
12698
|
+
internalType: "uint256",
|
|
12699
|
+
name: "homoLiquidationIncentive",
|
|
12700
|
+
type: "uint256"
|
|
12701
|
+
},
|
|
12702
|
+
{
|
|
12703
|
+
internalType: "uint256",
|
|
12704
|
+
name: "sutokenLiquidationIncentive",
|
|
12705
|
+
type: "uint256"
|
|
12706
|
+
},
|
|
12707
|
+
{ internalType: "uint8", name: "groupId", type: "uint8" },
|
|
12708
|
+
{ internalType: "uint256", name: "intraRate", type: "uint256" },
|
|
12709
|
+
{ internalType: "uint256", name: "interRate", type: "uint256" },
|
|
12710
|
+
{ internalType: "uint256", name: "mintRate", type: "uint256" },
|
|
12711
|
+
{ internalType: "uint256", name: "discountRate", type: "uint256" },
|
|
12712
|
+
{ internalType: "bool", name: "interMintAllowed", type: "bool" }
|
|
12713
|
+
],
|
|
12714
|
+
internalType: "struct SumerLens.CTokenMetadata[]",
|
|
12715
|
+
name: "",
|
|
12716
|
+
type: "tuple[]"
|
|
12717
|
+
}
|
|
12718
|
+
],
|
|
12719
|
+
stateMutability: "nonpayable",
|
|
12720
|
+
type: "function"
|
|
12721
|
+
},
|
|
12722
|
+
{
|
|
12723
|
+
inputs: [
|
|
12724
|
+
{
|
|
12725
|
+
internalType: "contract ICToken",
|
|
12726
|
+
name: "cToken",
|
|
12727
|
+
type: "address"
|
|
12728
|
+
},
|
|
12729
|
+
{
|
|
12730
|
+
internalType: "address payable",
|
|
12731
|
+
name: "account",
|
|
12732
|
+
type: "address"
|
|
12733
|
+
}
|
|
12734
|
+
],
|
|
12735
|
+
name: "cTokenBalances",
|
|
12736
|
+
outputs: [
|
|
12737
|
+
{
|
|
12738
|
+
components: [
|
|
12739
|
+
{ internalType: "address", name: "cToken", type: "address" },
|
|
12740
|
+
{ internalType: "bool", name: "isCToken", type: "bool" },
|
|
12741
|
+
{ internalType: "bool", name: "isCEther", type: "bool" },
|
|
12742
|
+
{ internalType: "uint256", name: "balanceOf", type: "uint256" },
|
|
12743
|
+
{
|
|
12744
|
+
internalType: "uint256",
|
|
12745
|
+
name: "borrowBalanceCurrent",
|
|
12746
|
+
type: "uint256"
|
|
12747
|
+
},
|
|
12748
|
+
{
|
|
12749
|
+
internalType: "uint256",
|
|
12750
|
+
name: "balanceOfUnderlying",
|
|
12751
|
+
type: "uint256"
|
|
12752
|
+
},
|
|
12753
|
+
{ internalType: "uint256", name: "tokenBalance", type: "uint256" },
|
|
12754
|
+
{
|
|
12755
|
+
internalType: "uint256",
|
|
12756
|
+
name: "tokenAllowance",
|
|
12757
|
+
type: "uint256"
|
|
12758
|
+
}
|
|
12759
|
+
],
|
|
12760
|
+
internalType: "struct SumerLens.CTokenBalances",
|
|
12761
|
+
name: "",
|
|
12762
|
+
type: "tuple"
|
|
12763
|
+
}
|
|
12764
|
+
],
|
|
12765
|
+
stateMutability: "nonpayable",
|
|
12766
|
+
type: "function"
|
|
12767
|
+
}
|
|
12768
|
+
];
|
|
12769
|
+
var SumerComptrollerAbi = [
|
|
12770
|
+
{
|
|
12771
|
+
inputs: [
|
|
12772
|
+
{ internalType: "uint8", name: "groupId", type: "uint8" }
|
|
12773
|
+
],
|
|
12774
|
+
name: "assetGroup",
|
|
12775
|
+
outputs: [
|
|
12776
|
+
{
|
|
12777
|
+
components: [
|
|
12778
|
+
{ internalType: "uint8", name: "groupId", type: "uint8" },
|
|
12779
|
+
{
|
|
12780
|
+
internalType: "uint16",
|
|
12781
|
+
name: "intraCRatePercent",
|
|
12782
|
+
type: "uint16"
|
|
12783
|
+
},
|
|
12784
|
+
{
|
|
12785
|
+
internalType: "uint16",
|
|
12786
|
+
name: "intraMintRatePercent",
|
|
12787
|
+
type: "uint16"
|
|
12788
|
+
},
|
|
12789
|
+
{
|
|
12790
|
+
internalType: "uint16",
|
|
12791
|
+
name: "intraSuRatePercent",
|
|
12792
|
+
type: "uint16"
|
|
12793
|
+
},
|
|
12794
|
+
{
|
|
12795
|
+
internalType: "uint16",
|
|
12796
|
+
name: "interCRatePercent",
|
|
12797
|
+
type: "uint16"
|
|
12798
|
+
},
|
|
12799
|
+
{
|
|
12800
|
+
internalType: "uint16",
|
|
12801
|
+
name: "interSuRatePercent",
|
|
12802
|
+
type: "uint16"
|
|
12803
|
+
}
|
|
12804
|
+
],
|
|
12805
|
+
internalType: "struct IComptroller.CompactAssetGroup",
|
|
12806
|
+
name: "",
|
|
12807
|
+
type: "tuple"
|
|
12808
|
+
}
|
|
12809
|
+
],
|
|
12810
|
+
stateMutability: "view",
|
|
12811
|
+
type: "function"
|
|
12812
|
+
}
|
|
12813
|
+
];
|
|
12502
12814
|
|
|
12503
12815
|
// src/lending/public-data/compound-v2/getters/types.ts
|
|
12504
12816
|
var CAction = /* @__PURE__ */ ((CAction2) => {
|
|
@@ -12514,6 +12826,158 @@ var CAction = /* @__PURE__ */ ((CAction2) => {
|
|
|
12514
12826
|
return CAction2;
|
|
12515
12827
|
})(CAction || {});
|
|
12516
12828
|
|
|
12829
|
+
// src/lending/public-data/compound-v2/getters/sumer.ts
|
|
12830
|
+
function readSumerCTokenMetadata(meta, token) {
|
|
12831
|
+
return {
|
|
12832
|
+
cToken: meta.cToken ?? "",
|
|
12833
|
+
exchangeRateCurrent: meta.exchangeRateCurrent ?? 0n,
|
|
12834
|
+
supplyRatePerBlock: meta.supplyRatePerBlock ?? 0n,
|
|
12835
|
+
borrowRatePerBlock: meta.borrowRatePerBlock ?? 0n,
|
|
12836
|
+
reserveFactorMantissa: meta.reserveFactorMantissa ?? 0n,
|
|
12837
|
+
totalBorrows: meta.totalBorrows ?? 0n,
|
|
12838
|
+
totalReserves: meta.totalReserves ?? 0n,
|
|
12839
|
+
totalSupply: meta.totalSupply ?? 0n,
|
|
12840
|
+
totalCash: meta.totalCash ?? 0n,
|
|
12841
|
+
isListed: meta.isListed ?? true,
|
|
12842
|
+
// use intraRate as the default collateralFactorMantissa for backward compat
|
|
12843
|
+
collateralFactorMantissa: meta.intraRate ?? 0n,
|
|
12844
|
+
underlyingAssetAddress: meta.underlyingAssetAddress ?? "",
|
|
12845
|
+
cTokenDecimals: meta.cTokenDecimals ?? 0n,
|
|
12846
|
+
underlyingDecimals: meta.underlyingDecimals ?? 0n,
|
|
12847
|
+
isCToken: meta.isCToken ?? true,
|
|
12848
|
+
isCEther: meta.isCEther ?? false,
|
|
12849
|
+
borrowCap: meta.borrowCap ?? 0n,
|
|
12850
|
+
depositCap: meta.depositCap ?? 0n,
|
|
12851
|
+
// group-based collateral factors
|
|
12852
|
+
groupId: Number(meta.groupId ?? 0),
|
|
12853
|
+
intraRate: meta.intraRate ?? 0n,
|
|
12854
|
+
interRate: meta.interRate ?? 0n,
|
|
12855
|
+
mintRate: meta.mintRate ?? 0n,
|
|
12856
|
+
discountRate: meta.discountRate ?? 0n,
|
|
12857
|
+
interMintAllowed: meta.interMintAllowed ?? false,
|
|
12858
|
+
// liquidation incentives
|
|
12859
|
+
heteroLiquidationIncentive: meta.heteroLiquidationIncentive ?? 0n,
|
|
12860
|
+
homoLiquidationIncentive: meta.homoLiquidationIncentive ?? 0n,
|
|
12861
|
+
sutokenLiquidationIncentive: meta.sutokenLiquidationIncentive ?? 0n,
|
|
12862
|
+
// no pausedActions bitmap in Sumer — default to not paused
|
|
12863
|
+
pausedActions: {
|
|
12864
|
+
[0 /* MINT */]: false,
|
|
12865
|
+
[1 /* REDEEM */]: false,
|
|
12866
|
+
[2 /* BORROW */]: false,
|
|
12867
|
+
[3 /* REPAY */]: false,
|
|
12868
|
+
[4 /* SEIZE */]: false,
|
|
12869
|
+
[5 /* LIQUIDATE */]: false,
|
|
12870
|
+
[6 /* TRANSFER */]: false,
|
|
12871
|
+
[7 /* ENTER_MARKET */]: false,
|
|
12872
|
+
[8 /* EXIT_MARKET */]: false
|
|
12873
|
+
},
|
|
12874
|
+
// borrow is allowed if listed (no explicit pause field)
|
|
12875
|
+
isBorrowAllowed: meta.isListed ?? true,
|
|
12876
|
+
depositRate: apyToApr(
|
|
12877
|
+
calculateRateForCompoundType(
|
|
12878
|
+
(meta.supplyRatePerBlock ?? 0n).toString(),
|
|
12879
|
+
token.chainId,
|
|
12880
|
+
0 /* BLOCK */
|
|
12881
|
+
) / 100
|
|
12882
|
+
) * 100,
|
|
12883
|
+
variableBorrowRate: apyToApr(
|
|
12884
|
+
calculateRateForCompoundType(
|
|
12885
|
+
(meta.borrowRatePerBlock ?? 0n).toString(),
|
|
12886
|
+
token.chainId,
|
|
12887
|
+
0 /* BLOCK */
|
|
12888
|
+
) / 100
|
|
12889
|
+
) * 100
|
|
12890
|
+
};
|
|
12891
|
+
}
|
|
12892
|
+
function parseSumerAssetGroup(raw) {
|
|
12893
|
+
if (!raw || typeof raw === "string") {
|
|
12894
|
+
return {
|
|
12895
|
+
groupId: 0,
|
|
12896
|
+
intraCRatePercent: 0,
|
|
12897
|
+
intraMintRatePercent: 0,
|
|
12898
|
+
intraSuRatePercent: 0,
|
|
12899
|
+
interCRatePercent: 0,
|
|
12900
|
+
interSuRatePercent: 0
|
|
12901
|
+
};
|
|
12902
|
+
}
|
|
12903
|
+
return {
|
|
12904
|
+
groupId: Number(raw.groupId ?? raw[0] ?? 0) || 0,
|
|
12905
|
+
intraCRatePercent: Number(raw.intraCRatePercent ?? raw[1] ?? 0) || 0,
|
|
12906
|
+
intraMintRatePercent: Number(raw.intraMintRatePercent ?? raw[2] ?? 0) || 0,
|
|
12907
|
+
intraSuRatePercent: Number(raw.intraSuRatePercent ?? raw[3] ?? 0) || 0,
|
|
12908
|
+
interCRatePercent: Number(raw.interCRatePercent ?? raw[4] ?? 0) || 0,
|
|
12909
|
+
interSuRatePercent: Number(raw.interSuRatePercent ?? raw[5] ?? 0) || 0
|
|
12910
|
+
};
|
|
12911
|
+
}
|
|
12912
|
+
var SUMER_GROUP_COUNT = 5;
|
|
12913
|
+
var SUMER_PERCENT_DIVISOR = 1e4;
|
|
12914
|
+
function normalizeSumerGroups(parsed) {
|
|
12915
|
+
return parsed.map((g) => ({
|
|
12916
|
+
groupId: g.groupId,
|
|
12917
|
+
intraCRate: g.intraCRatePercent / SUMER_PERCENT_DIVISOR,
|
|
12918
|
+
intraMintRate: g.intraMintRatePercent / SUMER_PERCENT_DIVISOR,
|
|
12919
|
+
intraSuRate: g.intraSuRatePercent / SUMER_PERCENT_DIVISOR,
|
|
12920
|
+
interCRate: g.interCRatePercent / SUMER_PERCENT_DIVISOR,
|
|
12921
|
+
interSuRate: g.interSuRatePercent / SUMER_PERCENT_DIVISOR
|
|
12922
|
+
}));
|
|
12923
|
+
}
|
|
12924
|
+
|
|
12925
|
+
// src/lending/public-data/compound-v2/publicCallBuild.ts
|
|
12926
|
+
var buildCompoundV2StyleLenderReserveCall = (chainId, lender) => {
|
|
12927
|
+
const tokens = getCompoundV2Tokens(chainId, lender);
|
|
12928
|
+
const getCTokenCall = getCall(lender, chainId);
|
|
12929
|
+
const calls = tokens.map((tk) => getCTokenCall(tk.cToken));
|
|
12930
|
+
if (isSumerType(lender)) {
|
|
12931
|
+
const comptroller = getCompoundV2Comptroller(chainId, lender);
|
|
12932
|
+
if (comptroller) {
|
|
12933
|
+
for (let groupId = 0; groupId < SUMER_GROUP_COUNT; groupId++) {
|
|
12934
|
+
calls.push({
|
|
12935
|
+
abi: SumerComptrollerAbi,
|
|
12936
|
+
address: comptroller,
|
|
12937
|
+
name: "assetGroup",
|
|
12938
|
+
params: [groupId]
|
|
12939
|
+
});
|
|
12940
|
+
}
|
|
12941
|
+
}
|
|
12942
|
+
}
|
|
12943
|
+
return calls;
|
|
12944
|
+
};
|
|
12945
|
+
function getCall(lender, chainId) {
|
|
12946
|
+
const lens = getCompoundV2Lens(chainId, lender);
|
|
12947
|
+
if (isVenusType(lender)) {
|
|
12948
|
+
return (tk) => chainId === Chain.BNB_SMART_CHAIN_MAINNET && tk === "0xa07c5b74c9b40447a954e1466938b865b6bbea36" ? {
|
|
12949
|
+
abi: VenusLensLegacyAbi,
|
|
12950
|
+
address: VENUS_LENS_VBNB,
|
|
12951
|
+
name: "vTokenMetadata",
|
|
12952
|
+
params: [tk]
|
|
12953
|
+
} : {
|
|
12954
|
+
address: lens,
|
|
12955
|
+
name: "vTokenMetadata",
|
|
12956
|
+
params: [tk]
|
|
12957
|
+
};
|
|
12958
|
+
}
|
|
12959
|
+
if (lender === Lender.MOONWELL) {
|
|
12960
|
+
return (tk) => ({
|
|
12961
|
+
address: lens,
|
|
12962
|
+
name: "getMarketInfo",
|
|
12963
|
+
params: [tk]
|
|
12964
|
+
});
|
|
12965
|
+
}
|
|
12966
|
+
if (isSumerType(lender)) {
|
|
12967
|
+
return (tk) => ({
|
|
12968
|
+
abi: SumerLensAbi,
|
|
12969
|
+
address: lens,
|
|
12970
|
+
name: "cTokenMetadata",
|
|
12971
|
+
params: [tk]
|
|
12972
|
+
});
|
|
12973
|
+
}
|
|
12974
|
+
return (tk) => ({
|
|
12975
|
+
address: lens,
|
|
12976
|
+
name: "cTokenMetadata",
|
|
12977
|
+
params: [tk]
|
|
12978
|
+
});
|
|
12979
|
+
}
|
|
12980
|
+
|
|
12517
12981
|
// src/lending/public-data/compound-v2/getters/venus.ts
|
|
12518
12982
|
function readVTokenMetadata(meta, token) {
|
|
12519
12983
|
const pick = (...values) => values.find((v) => v !== void 0);
|
|
@@ -12723,7 +13187,7 @@ function convertSingleEntry(opts) {
|
|
|
12723
13187
|
totalDepositsUSD: totalSupplyUnderlying * price,
|
|
12724
13188
|
totalDebtStable: 0,
|
|
12725
13189
|
totalDebtStableUSD: 0,
|
|
12726
|
-
|
|
13190
|
+
intrinsicYield: additionalYields.intrinsicYields[asset.assetGroup] ?? 0,
|
|
12727
13191
|
config: {
|
|
12728
13192
|
[LENDER_MODE_NO_MODE]: {
|
|
12729
13193
|
category: LENDER_MODE_NO_MODE,
|
|
@@ -12756,15 +13220,116 @@ function convertSingleEntry(opts) {
|
|
|
12756
13220
|
}
|
|
12757
13221
|
};
|
|
12758
13222
|
}
|
|
13223
|
+
function convertSumerEntry(opts) {
|
|
13224
|
+
const { entryRaw, asset, chainId, lender, prices, additionalYields, cToken, groups } = opts;
|
|
13225
|
+
const decs = asset.decimals;
|
|
13226
|
+
const currentEntry = readSumerCTokenMetadata(entryRaw, asset);
|
|
13227
|
+
const exchangeRateRaw = currentEntry.exchangeRateCurrent ?? 0n;
|
|
13228
|
+
const exchangeRateCurrent = parseRawAmount(
|
|
13229
|
+
exchangeRateRaw.toString(),
|
|
13230
|
+
PRICE_DECIMALS
|
|
13231
|
+
);
|
|
13232
|
+
const totalSupplyUnderlying = Number(parseRawAmount(currentEntry.totalSupply?.toString(), decs)) * Number(exchangeRateCurrent);
|
|
13233
|
+
const totalDebt = Number(
|
|
13234
|
+
parseRawAmount(currentEntry.totalBorrows?.toString(), decs)
|
|
13235
|
+
);
|
|
13236
|
+
const liquidity = totalSupplyUnderlying - totalDebt;
|
|
13237
|
+
const price = prices[asset.assetGroup] ?? 0;
|
|
13238
|
+
const poolId = asset.address;
|
|
13239
|
+
const collateralActive = Boolean(currentEntry.isListed);
|
|
13240
|
+
const borrowingEnabled = Boolean(currentEntry.isBorrowAllowed);
|
|
13241
|
+
const marketUid = createMarketUid(chainId, lender, cToken);
|
|
13242
|
+
const groupId = currentEntry.groupId;
|
|
13243
|
+
const intraRate = Number(
|
|
13244
|
+
parseRawAmount(currentEntry.intraRate?.toString(), RESERVE_MANTISSA_DECIMALS)
|
|
13245
|
+
);
|
|
13246
|
+
const interRate = Number(
|
|
13247
|
+
parseRawAmount(currentEntry.interRate?.toString(), RESERVE_MANTISSA_DECIMALS)
|
|
13248
|
+
);
|
|
13249
|
+
const config = {};
|
|
13250
|
+
for (let gId = 0; gId < SUMER_GROUP_COUNT; gId++) {
|
|
13251
|
+
const isOwnGroup = gId === groupId;
|
|
13252
|
+
const cf = isOwnGroup ? intraRate : interRate;
|
|
13253
|
+
config[gId] = {
|
|
13254
|
+
category: gId,
|
|
13255
|
+
borrowCollateralFactor: cf,
|
|
13256
|
+
collateralFactor: cf,
|
|
13257
|
+
borrowFactor: 1,
|
|
13258
|
+
collateralDisabled: !collateralActive,
|
|
13259
|
+
debtDisabled: !borrowingEnabled
|
|
13260
|
+
};
|
|
13261
|
+
}
|
|
13262
|
+
return {
|
|
13263
|
+
marketUid,
|
|
13264
|
+
poolId,
|
|
13265
|
+
asset,
|
|
13266
|
+
depositRate: currentEntry.depositRate,
|
|
13267
|
+
variableBorrowRate: currentEntry.variableBorrowRate,
|
|
13268
|
+
stableBorrowRate: 0,
|
|
13269
|
+
totalLiquidity: liquidity,
|
|
13270
|
+
totalLiquidityUSD: liquidity * price,
|
|
13271
|
+
totalDebt,
|
|
13272
|
+
totalDebtUSD: totalDebt * price,
|
|
13273
|
+
totalDeposits: totalSupplyUnderlying,
|
|
13274
|
+
totalDepositsUSD: totalSupplyUnderlying * price,
|
|
13275
|
+
totalDebtStable: 0,
|
|
13276
|
+
totalDebtStableUSD: 0,
|
|
13277
|
+
stakingYield: additionalYields.intrinsicYields[asset.assetGroup] ?? 0,
|
|
13278
|
+
config,
|
|
13279
|
+
hasStable: false,
|
|
13280
|
+
underlying: asset.address,
|
|
13281
|
+
isActive: Boolean(currentEntry.isListed),
|
|
13282
|
+
isFrozen: false,
|
|
13283
|
+
rewards: {},
|
|
13284
|
+
collateralActive,
|
|
13285
|
+
borrowingEnabled,
|
|
13286
|
+
params: {
|
|
13287
|
+
metadata: {
|
|
13288
|
+
cToken,
|
|
13289
|
+
exchangeRate: exchangeRateRaw.toString(),
|
|
13290
|
+
cTokenDecimals: Number(currentEntry.cTokenDecimals?.toString()),
|
|
13291
|
+
groupId,
|
|
13292
|
+
sumer: {
|
|
13293
|
+
isCToken: Boolean(currentEntry.isCToken),
|
|
13294
|
+
...groups[groupId] ?? groups[0]
|
|
13295
|
+
}
|
|
13296
|
+
}
|
|
13297
|
+
}
|
|
13298
|
+
};
|
|
13299
|
+
}
|
|
12759
13300
|
var getCompoundV2DataConverter = (lender, chainId, prices, additionalYields, tokenList = {}) => {
|
|
12760
13301
|
const compoundV2Tokens2 = getCompoundV2Tokens(chainId, lender);
|
|
12761
|
-
const
|
|
13302
|
+
const tokenCount = compoundV2Tokens2.length;
|
|
13303
|
+
const isSumer = isSumerType(lender);
|
|
13304
|
+
const expectedNumberOfCalls = isSumer ? tokenCount + SUMER_GROUP_COUNT : tokenCount;
|
|
12762
13305
|
const reader = getReader(lender);
|
|
12763
13306
|
return [
|
|
12764
13307
|
(data) => {
|
|
12765
13308
|
if (data.length !== expectedNumberOfCalls) return void 0;
|
|
12766
13309
|
const out = { data: {}, chainId };
|
|
12767
|
-
|
|
13310
|
+
if (isSumer) {
|
|
13311
|
+
const groupData = data.slice(tokenCount);
|
|
13312
|
+
const groups = normalizeSumerGroups(groupData.map(parseSumerAssetGroup));
|
|
13313
|
+
for (let i = 0; i < tokenCount; i++) {
|
|
13314
|
+
const { underlying, cToken } = compoundV2Tokens2[i];
|
|
13315
|
+
if (!cToken || !underlying) continue;
|
|
13316
|
+
const poolId = underlying;
|
|
13317
|
+
const asset = tokenList[poolId];
|
|
13318
|
+
const entryRaw = data[i];
|
|
13319
|
+
out.data[poolId] = convertSumerEntry({
|
|
13320
|
+
entryRaw,
|
|
13321
|
+
asset,
|
|
13322
|
+
chainId,
|
|
13323
|
+
lender,
|
|
13324
|
+
prices,
|
|
13325
|
+
additionalYields,
|
|
13326
|
+
cToken,
|
|
13327
|
+
groups
|
|
13328
|
+
});
|
|
13329
|
+
}
|
|
13330
|
+
return out;
|
|
13331
|
+
}
|
|
13332
|
+
for (let i = 0; i < tokenCount; i++) {
|
|
12768
13333
|
const { underlying, cToken } = compoundV2Tokens2[i];
|
|
12769
13334
|
if (!cToken || !underlying) continue;
|
|
12770
13335
|
const poolId = underlying;
|
|
@@ -12793,6 +13358,9 @@ function getReader(lender) {
|
|
|
12793
13358
|
if (lender === Lender.MOONWELL) {
|
|
12794
13359
|
return (x, t) => parseMoonwellMarket(x, t);
|
|
12795
13360
|
}
|
|
13361
|
+
if (isSumerType(lender)) {
|
|
13362
|
+
return (x, t) => readSumerCTokenMetadata(x, t);
|
|
13363
|
+
}
|
|
12796
13364
|
}
|
|
12797
13365
|
|
|
12798
13366
|
// src/abis/compound-v2/VenusLens.ts
|
|
@@ -13711,6 +14279,7 @@ var getAbi = (lender) => {
|
|
|
13711
14279
|
if (isCompoundV3(lender)) return [...IrgetterAbi, ...CometAbi, ...CometExtAbi];
|
|
13712
14280
|
if (isInit(lender)) return InitLensAbi;
|
|
13713
14281
|
if (isMorphoType(lender)) return MorphoLensAbi;
|
|
14282
|
+
if (isSumerType(lender)) return [...SumerLensAbi, ...SumerComptrollerAbi];
|
|
13714
14283
|
if (isCompoundV2Type(lender)) return VenusLensAbi;
|
|
13715
14284
|
return [];
|
|
13716
14285
|
};
|
|
@@ -14159,24 +14728,26 @@ var buildAaveV3UserCall = (chainId, lender, account) => {
|
|
|
14159
14728
|
}
|
|
14160
14729
|
return calls;
|
|
14161
14730
|
};
|
|
14162
|
-
|
|
14163
|
-
// src/lending/user-data/init/userCallBuild.ts
|
|
14164
|
-
var initBrokerAddresses = {
|
|
14165
|
-
[Chain.MANTLE]: "0xc08BFef7E778f3519D79E96780b77066F5d4FCC0"
|
|
14166
|
-
};
|
|
14167
|
-
function getInitFlashAggregatorAddress(chainId) {
|
|
14168
|
-
if (!chainId) return void 0;
|
|
14169
|
-
return initBrokerAddresses[chainId];
|
|
14170
|
-
}
|
|
14171
14731
|
var buildInitUserCall = (chainId, lender, account) => {
|
|
14172
14732
|
const lensContract = getInitLensAddress(chainId);
|
|
14173
|
-
const
|
|
14174
|
-
const
|
|
14175
|
-
|
|
14176
|
-
|
|
14177
|
-
|
|
14178
|
-
|
|
14179
|
-
|
|
14733
|
+
const calls = [];
|
|
14734
|
+
const legacyBroker = InitMarginAddresses.getLegacyFlashAggregator(chainId);
|
|
14735
|
+
if (legacyBroker) {
|
|
14736
|
+
calls.push({
|
|
14737
|
+
address: lensContract,
|
|
14738
|
+
name: "getUserPositionData",
|
|
14739
|
+
params: [account, legacyBroker]
|
|
14740
|
+
});
|
|
14741
|
+
}
|
|
14742
|
+
const currentBroker = InitMarginAddresses.getFlashAggregator(chainId);
|
|
14743
|
+
if (currentBroker) {
|
|
14744
|
+
calls.push({
|
|
14745
|
+
address: lensContract,
|
|
14746
|
+
name: "getUserPositionData",
|
|
14747
|
+
params: [account, currentBroker]
|
|
14748
|
+
});
|
|
14749
|
+
}
|
|
14750
|
+
return calls;
|
|
14180
14751
|
};
|
|
14181
14752
|
|
|
14182
14753
|
// src/lending/user-data/compound-v3/userCallBuild.ts
|
|
@@ -18407,114 +18978,13 @@ var YLDRAbi = [
|
|
|
18407
18978
|
},
|
|
18408
18979
|
{
|
|
18409
18980
|
internalType: "uint256",
|
|
18410
|
-
name: "liquidityRate",
|
|
18411
|
-
type: "uint256"
|
|
18412
|
-
},
|
|
18413
|
-
{
|
|
18414
|
-
internalType: "bool",
|
|
18415
|
-
name: "usageAsCollateralEnabled",
|
|
18416
|
-
type: "bool"
|
|
18417
|
-
}
|
|
18418
|
-
],
|
|
18419
|
-
stateMutability: "view",
|
|
18420
|
-
type: "function"
|
|
18421
|
-
}
|
|
18422
|
-
];
|
|
18423
|
-
|
|
18424
|
-
// src/abis/morpho/blue.ts
|
|
18425
|
-
var MorphoBlueAbi = [
|
|
18426
|
-
{
|
|
18427
|
-
inputs: [
|
|
18428
|
-
{
|
|
18429
|
-
internalType: "Id",
|
|
18430
|
-
name: "",
|
|
18431
|
-
type: "bytes32"
|
|
18432
|
-
},
|
|
18433
|
-
{
|
|
18434
|
-
internalType: "address",
|
|
18435
|
-
name: "",
|
|
18436
|
-
type: "address"
|
|
18437
|
-
}
|
|
18438
|
-
],
|
|
18439
|
-
name: "position",
|
|
18440
|
-
outputs: [
|
|
18441
|
-
{
|
|
18442
|
-
internalType: "uint256",
|
|
18443
|
-
name: "supplyShares",
|
|
18444
|
-
type: "uint256"
|
|
18445
|
-
},
|
|
18446
|
-
{
|
|
18447
|
-
internalType: "uint128",
|
|
18448
|
-
name: "borrowShares",
|
|
18449
|
-
type: "uint128"
|
|
18450
|
-
},
|
|
18451
|
-
{
|
|
18452
|
-
internalType: "uint128",
|
|
18453
|
-
name: "collateral",
|
|
18454
|
-
type: "uint128"
|
|
18455
|
-
}
|
|
18456
|
-
],
|
|
18457
|
-
stateMutability: "view",
|
|
18458
|
-
type: "function"
|
|
18459
|
-
},
|
|
18460
|
-
{
|
|
18461
|
-
inputs: [
|
|
18462
|
-
{
|
|
18463
|
-
internalType: "bytes32[]",
|
|
18464
|
-
name: "slots",
|
|
18465
|
-
type: "bytes32[]"
|
|
18466
|
-
}
|
|
18467
|
-
],
|
|
18468
|
-
name: "extSloads",
|
|
18469
|
-
outputs: [
|
|
18470
|
-
{
|
|
18471
|
-
internalType: "bytes32[]",
|
|
18472
|
-
name: "res",
|
|
18473
|
-
type: "bytes32[]"
|
|
18474
|
-
}
|
|
18475
|
-
],
|
|
18476
|
-
stateMutability: "view",
|
|
18477
|
-
type: "function"
|
|
18478
|
-
},
|
|
18479
|
-
{
|
|
18480
|
-
inputs: [
|
|
18481
|
-
{
|
|
18482
|
-
internalType: "Id",
|
|
18483
|
-
name: "",
|
|
18484
|
-
type: "bytes32"
|
|
18485
|
-
}
|
|
18486
|
-
],
|
|
18487
|
-
name: "market",
|
|
18488
|
-
outputs: [
|
|
18489
|
-
{
|
|
18490
|
-
internalType: "uint128",
|
|
18491
|
-
name: "totalSupplyAssets",
|
|
18492
|
-
type: "uint128"
|
|
18493
|
-
},
|
|
18494
|
-
{
|
|
18495
|
-
internalType: "uint128",
|
|
18496
|
-
name: "totalSupplyShares",
|
|
18497
|
-
type: "uint128"
|
|
18498
|
-
},
|
|
18499
|
-
{
|
|
18500
|
-
internalType: "uint128",
|
|
18501
|
-
name: "totalBorrowAssets",
|
|
18502
|
-
type: "uint128"
|
|
18503
|
-
},
|
|
18504
|
-
{
|
|
18505
|
-
internalType: "uint128",
|
|
18506
|
-
name: "totalBorrowShares",
|
|
18507
|
-
type: "uint128"
|
|
18508
|
-
},
|
|
18509
|
-
{
|
|
18510
|
-
internalType: "uint128",
|
|
18511
|
-
name: "lastUpdate",
|
|
18512
|
-
type: "uint128"
|
|
18981
|
+
name: "liquidityRate",
|
|
18982
|
+
type: "uint256"
|
|
18513
18983
|
},
|
|
18514
18984
|
{
|
|
18515
|
-
internalType: "
|
|
18516
|
-
name: "
|
|
18517
|
-
type: "
|
|
18985
|
+
internalType: "bool",
|
|
18986
|
+
name: "usageAsCollateralEnabled",
|
|
18987
|
+
type: "bool"
|
|
18518
18988
|
}
|
|
18519
18989
|
],
|
|
18520
18990
|
stateMutability: "view",
|
|
@@ -18780,104 +19250,108 @@ function createAaveV3Entry(i, data, key, meta) {
|
|
|
18780
19250
|
addedDebt: (Number(currentVariableDebt) + Number(currentStableDebt)) * priceHist
|
|
18781
19251
|
};
|
|
18782
19252
|
}
|
|
18783
|
-
|
|
18784
|
-
|
|
19253
|
+
function parseSingleBrokerData(data, validOwner, brokerAddress, lender, chainId, metaMap) {
|
|
19254
|
+
const indexes = data[0 /* posMeta */].map((e, i) => ({ e, i })).filter((a) => a.e.owner.toLowerCase() === validOwner).map((a) => a.i);
|
|
19255
|
+
const histData = {};
|
|
19256
|
+
const modes = {};
|
|
19257
|
+
let allPools = {};
|
|
19258
|
+
const result = Object.assign(
|
|
19259
|
+
{},
|
|
19260
|
+
...indexes.map((index) => {
|
|
19261
|
+
const entry = data[0 /* posMeta */][index];
|
|
19262
|
+
const mode = entry.mode;
|
|
19263
|
+
const id = entry.posId.toString();
|
|
19264
|
+
modes[id] = mode;
|
|
19265
|
+
const collatData = Object.assign(
|
|
19266
|
+
{},
|
|
19267
|
+
...data[1 /* collaterals */][index].map(
|
|
19268
|
+
(c) => {
|
|
19269
|
+
const pool = c.pool.toLowerCase();
|
|
19270
|
+
allPools[pool] = c.underlying.toLowerCase();
|
|
19271
|
+
const key = createMarketUid(chainId, lender, pool);
|
|
19272
|
+
const metaEntity = metaMap?.[key];
|
|
19273
|
+
const decimals = metaEntity.asset?.decimals ?? 18;
|
|
19274
|
+
const depositsRaw = c.amount.toString();
|
|
19275
|
+
return {
|
|
19276
|
+
[pool]: {
|
|
19277
|
+
deposits: parseRawAmount(depositsRaw, decimals)
|
|
19278
|
+
}
|
|
19279
|
+
};
|
|
19280
|
+
}
|
|
19281
|
+
)
|
|
19282
|
+
);
|
|
19283
|
+
const debtData = Object.assign(
|
|
19284
|
+
{},
|
|
19285
|
+
...data[2 /* debts */][index].map(
|
|
19286
|
+
(c) => {
|
|
19287
|
+
const pool = c.pool.toLowerCase();
|
|
19288
|
+
allPools[pool] = c.underlying.toLowerCase();
|
|
19289
|
+
const key = createMarketUid(chainId, lender, pool);
|
|
19290
|
+
const metaEntity = metaMap?.[key];
|
|
19291
|
+
const decimals = metaEntity.asset?.decimals ?? 18;
|
|
19292
|
+
return {
|
|
19293
|
+
[pool]: {
|
|
19294
|
+
debt: parseRawAmount(c.amount.toString(), decimals)
|
|
19295
|
+
}
|
|
19296
|
+
};
|
|
19297
|
+
}
|
|
19298
|
+
)
|
|
19299
|
+
);
|
|
19300
|
+
return {
|
|
19301
|
+
[id]: Object.assign(
|
|
19302
|
+
{},
|
|
19303
|
+
...Object.entries(allPools).map(
|
|
19304
|
+
([pool, underlying]) => {
|
|
19305
|
+
const key = createMarketUid(chainId, lender, pool);
|
|
19306
|
+
const metaEntity = metaMap?.[key];
|
|
19307
|
+
const price = metaEntity?.price?.priceUsd ?? 1;
|
|
19308
|
+
const priceHist = metaEntity?.price?.priceUsd24h ?? price;
|
|
19309
|
+
if (!histData[id])
|
|
19310
|
+
histData[id] = {
|
|
19311
|
+
totalDebt24h: 0,
|
|
19312
|
+
totalDeposits24h: 0
|
|
19313
|
+
};
|
|
19314
|
+
const debt = debtData[pool]?.debt ?? 0;
|
|
19315
|
+
const deposits = collatData[pool]?.deposits ?? 0;
|
|
19316
|
+
histData[id].totalDebt24h += Number(debt) * priceHist;
|
|
19317
|
+
histData[id].totalDeposits24h += Number(deposits) * priceHist;
|
|
19318
|
+
return {
|
|
19319
|
+
[key]: {
|
|
19320
|
+
marketUid: key,
|
|
19321
|
+
underlying,
|
|
19322
|
+
deposits,
|
|
19323
|
+
debt,
|
|
19324
|
+
debtStable: "0",
|
|
19325
|
+
debtStableUSD: 0,
|
|
19326
|
+
depositsUSD: price * Number(deposits),
|
|
19327
|
+
debtUSD: price * Number(debt),
|
|
19328
|
+
collateralEnabled: true,
|
|
19329
|
+
isAllowed: entry.approved.toLowerCase() === brokerAddress.toLowerCase()
|
|
19330
|
+
}
|
|
19331
|
+
};
|
|
19332
|
+
}
|
|
19333
|
+
)
|
|
19334
|
+
)
|
|
19335
|
+
};
|
|
19336
|
+
})
|
|
19337
|
+
);
|
|
19338
|
+
return { result, modes, histData };
|
|
19339
|
+
}
|
|
18785
19340
|
var getInitUserDataConverter = (lender, chainId, account, metaMap) => {
|
|
18786
19341
|
const validOwner = account.toLowerCase();
|
|
18787
|
-
const
|
|
18788
|
-
const
|
|
19342
|
+
const legacyBroker = InitMarginAddresses.getLegacyFlashAggregator(chainId) ?? "";
|
|
19343
|
+
const currentBroker = InitMarginAddresses.getFlashAggregator(chainId) ?? "";
|
|
19344
|
+
const expectedNumberOfCalls = 2;
|
|
18789
19345
|
return [
|
|
18790
19346
|
(_data) => {
|
|
18791
19347
|
if (_data.length !== expectedNumberOfCalls) {
|
|
18792
19348
|
return void 0;
|
|
18793
19349
|
}
|
|
18794
|
-
const [
|
|
18795
|
-
const
|
|
18796
|
-
|
|
18797
|
-
|
|
18798
|
-
|
|
18799
|
-
const modes = {};
|
|
18800
|
-
let allPools = {};
|
|
18801
|
-
const result = Object.assign(
|
|
18802
|
-
{},
|
|
18803
|
-
...indexes.map((index) => {
|
|
18804
|
-
const entry = data[0 /* posMeta */][index];
|
|
18805
|
-
const mode = entry.mode;
|
|
18806
|
-
const id = entry.posId.toString();
|
|
18807
|
-
modes[id] = mode;
|
|
18808
|
-
const collatData = Object.assign(
|
|
18809
|
-
{},
|
|
18810
|
-
...data[1 /* collaterals */][index].map(
|
|
18811
|
-
(c) => {
|
|
18812
|
-
const pool = c.pool.toLowerCase();
|
|
18813
|
-
allPools[pool] = c.underlying.toLowerCase();
|
|
18814
|
-
const key = createMarketUid(chainId, lender, pool);
|
|
18815
|
-
const metaEntity = metaMap?.[key];
|
|
18816
|
-
const decimals = metaEntity.asset?.decimals ?? 18;
|
|
18817
|
-
const depositsRaw = c.amount.toString();
|
|
18818
|
-
return {
|
|
18819
|
-
[pool]: {
|
|
18820
|
-
deposits: parseRawAmount(depositsRaw, decimals)
|
|
18821
|
-
}
|
|
18822
|
-
};
|
|
18823
|
-
}
|
|
18824
|
-
)
|
|
18825
|
-
);
|
|
18826
|
-
const debtData = Object.assign(
|
|
18827
|
-
{},
|
|
18828
|
-
...data[2 /* debts */][index].map(
|
|
18829
|
-
(c) => {
|
|
18830
|
-
const pool = c.pool.toLowerCase();
|
|
18831
|
-
allPools[pool] = c.underlying.toLowerCase();
|
|
18832
|
-
const key = createMarketUid(chainId, lender, pool);
|
|
18833
|
-
const metaEntity = metaMap?.[key];
|
|
18834
|
-
const decimals = metaEntity.asset?.decimals ?? 18;
|
|
18835
|
-
return {
|
|
18836
|
-
[pool]: {
|
|
18837
|
-
debt: parseRawAmount(c.amount.toString(), decimals)
|
|
18838
|
-
}
|
|
18839
|
-
};
|
|
18840
|
-
}
|
|
18841
|
-
)
|
|
18842
|
-
);
|
|
18843
|
-
return {
|
|
18844
|
-
[id]: Object.assign(
|
|
18845
|
-
{},
|
|
18846
|
-
...Object.entries(allPools).map(
|
|
18847
|
-
([pool, underlying]) => {
|
|
18848
|
-
const key = createMarketUid(chainId, lender, pool);
|
|
18849
|
-
const metaEntity = metaMap?.[key];
|
|
18850
|
-
const price = metaEntity?.price?.priceUsd ?? 1;
|
|
18851
|
-
const priceHist = metaEntity?.price?.priceUsd24h ?? price;
|
|
18852
|
-
if (!histData[id])
|
|
18853
|
-
histData[id] = {
|
|
18854
|
-
totalDebt24h: 0,
|
|
18855
|
-
totalDeposits24h: 0
|
|
18856
|
-
};
|
|
18857
|
-
const debt = debtData[pool]?.debt ?? 0;
|
|
18858
|
-
const deposits = collatData[pool]?.deposits ?? 0;
|
|
18859
|
-
histData[id].totalDebt24h += Number(debt) * priceHist;
|
|
18860
|
-
histData[id].totalDeposits24h += Number(deposits) * priceHist;
|
|
18861
|
-
return {
|
|
18862
|
-
[key]: {
|
|
18863
|
-
marketUid: key,
|
|
18864
|
-
underlying,
|
|
18865
|
-
deposits,
|
|
18866
|
-
debt,
|
|
18867
|
-
debtStable: "0",
|
|
18868
|
-
debtStableUSD: 0,
|
|
18869
|
-
depositsUSD: price * Number(deposits),
|
|
18870
|
-
debtUSD: price * Number(debt),
|
|
18871
|
-
collateralEnabled: true,
|
|
18872
|
-
isAllowed: entry.approved.toLowerCase() === brokerAddress.toLowerCase()
|
|
18873
|
-
}
|
|
18874
|
-
};
|
|
18875
|
-
}
|
|
18876
|
-
)
|
|
18877
|
-
)
|
|
18878
|
-
};
|
|
18879
|
-
})
|
|
18880
|
-
);
|
|
19350
|
+
const legacy = parseSingleBrokerData(_data[0], validOwner, legacyBroker, lender, chainId, metaMap);
|
|
19351
|
+
const current = parseSingleBrokerData(_data[1], validOwner, currentBroker, lender, chainId, metaMap);
|
|
19352
|
+
const result = { ...legacy.result, ...current.result };
|
|
19353
|
+
const modes = { ...legacy.modes, ...current.modes };
|
|
19354
|
+
const histData = { ...legacy.histData, ...current.histData };
|
|
18881
19355
|
const payload = {
|
|
18882
19356
|
chainId,
|
|
18883
19357
|
lendingPositions: result,
|
|
@@ -19147,8 +19621,6 @@ function decodePackedListaUserDataset(hex, marketsCount) {
|
|
|
19147
19621
|
collateral
|
|
19148
19622
|
});
|
|
19149
19623
|
}
|
|
19150
|
-
console.log("whitelistFlags", whitelistFlags);
|
|
19151
|
-
console.log("balances", balances);
|
|
19152
19624
|
return {
|
|
19153
19625
|
whitelistFlags,
|
|
19154
19626
|
balances
|
|
@@ -19181,9 +19653,9 @@ var aprData = {
|
|
|
19181
19653
|
rewardApr: 0,
|
|
19182
19654
|
rewardDepositApr: 0,
|
|
19183
19655
|
rewardBorrowApr: 0,
|
|
19184
|
-
|
|
19185
|
-
|
|
19186
|
-
|
|
19656
|
+
intrinsicApr: 0,
|
|
19657
|
+
intrinsicDepositApr: 0,
|
|
19658
|
+
intrinsicBorrowApr: 0
|
|
19187
19659
|
};
|
|
19188
19660
|
var userDataEmpty = (account, chainId, notWhitelisted = false) => {
|
|
19189
19661
|
return {
|
|
@@ -19280,9 +19752,11 @@ var getListaUserDataConverterWithlens = (lender, chainId, account, markets, meta
|
|
|
19280
19752
|
let datas = {};
|
|
19281
19753
|
let whitelistedFlags = {};
|
|
19282
19754
|
for (let i = 0; i < data.length; i++) {
|
|
19755
|
+
const chunkStart = i * CHUNK_SIZE;
|
|
19756
|
+
const chunkMarketCount = Math.min(CHUNK_SIZE, markets.length - chunkStart);
|
|
19283
19757
|
const { balances, whitelistFlags } = decodePackedListaUserDataset(
|
|
19284
19758
|
data[i],
|
|
19285
|
-
|
|
19759
|
+
chunkMarketCount
|
|
19286
19760
|
);
|
|
19287
19761
|
whitelistFlags.forEach((flag, index) => {
|
|
19288
19762
|
whitelistedFlags[markets[mapMarketToChunk(index, i)]] = flag;
|
|
@@ -19477,7 +19951,8 @@ var getCompoundV2UserDataConverter = (lender, chainId, account, metaMap) => {
|
|
|
19477
19951
|
lendingPositions: { "0": lendingPositions },
|
|
19478
19952
|
rewards: {}
|
|
19479
19953
|
};
|
|
19480
|
-
const
|
|
19954
|
+
const createState = isSumerType(lender) ? createSumerUserState : createBaseTypeUserState;
|
|
19955
|
+
const userData = createState(
|
|
19481
19956
|
payload,
|
|
19482
19957
|
metaMap,
|
|
19483
19958
|
totalDeposits24h,
|
|
@@ -19555,7 +20030,7 @@ var generateLendingPools = (lenderData, prices, histPrices) => {
|
|
|
19555
20030
|
if (!byMarket.has(key)) byMarket.set(key, []);
|
|
19556
20031
|
byMarket.get(key).push({
|
|
19557
20032
|
...pool,
|
|
19558
|
-
apr: pool.depositRate + (pool.
|
|
20033
|
+
apr: pool.depositRate + (pool.intrinsicYield ?? 0),
|
|
19559
20034
|
utilitzation: (Number(pool.totalDebt) + Number(pool.totalDebtStable ?? 0)) / Number(pool.totalDeposits),
|
|
19560
20035
|
exposure: []
|
|
19561
20036
|
});
|
|
@@ -19725,7 +20200,7 @@ var prepareLenderUserDataRpcCalls = (chainId, queriesRaw, batchSize = MULTICALL_
|
|
|
19725
20200
|
return {
|
|
19726
20201
|
batches,
|
|
19727
20202
|
preparedCalls,
|
|
19728
|
-
queries,
|
|
20203
|
+
queries: queriesRaw,
|
|
19729
20204
|
rpcCalls
|
|
19730
20205
|
};
|
|
19731
20206
|
};
|
|
@@ -19899,7 +20374,7 @@ function buildPortfolioTotals(userDataResult) {
|
|
|
19899
20374
|
lenderDebtWeight += balanceData2.debt;
|
|
19900
20375
|
}
|
|
19901
20376
|
totalNav24h += balanceData2.nav24h ?? 0;
|
|
19902
|
-
totalRewardApr += aprData2.rewardApr + aprData2.rewardDepositApr + aprData2.rewardBorrowApr + aprData2.
|
|
20377
|
+
totalRewardApr += aprData2.rewardApr + aprData2.rewardDepositApr + aprData2.rewardBorrowApr + aprData2.intrinsicApr;
|
|
19903
20378
|
}
|
|
19904
20379
|
totalDepositsUSD += lenderDeposits;
|
|
19905
20380
|
totalDebtUSD += lenderDebt;
|
|
@@ -19970,7 +20445,7 @@ function aggregateLenderData(lender, userData) {
|
|
|
19970
20445
|
weight: balanceData2.deposits
|
|
19971
20446
|
});
|
|
19972
20447
|
}
|
|
19973
|
-
totalRewardApr += aprData2.rewardApr + aprData2.rewardDepositApr + aprData2.rewardBorrowApr + aprData2.
|
|
20448
|
+
totalRewardApr += aprData2.rewardApr + aprData2.rewardDepositApr + aprData2.rewardBorrowApr + aprData2.intrinsicApr;
|
|
19974
20449
|
if (health !== null && health > 0) {
|
|
19975
20450
|
healthSum += health;
|
|
19976
20451
|
healthCount++;
|
|
@@ -20118,6 +20593,872 @@ function fuseLenderData(userDataResult, summary) {
|
|
|
20118
20593
|
return entries;
|
|
20119
20594
|
}
|
|
20120
20595
|
|
|
20596
|
+
// src/lending/margin/base/utils.ts
|
|
20597
|
+
var EMPTY_BALANCE = {
|
|
20598
|
+
rewards: void 0,
|
|
20599
|
+
borrowDiscountedCollateral: 0,
|
|
20600
|
+
borrowDiscountedCollateralAllActive: 0,
|
|
20601
|
+
collateral: 0,
|
|
20602
|
+
collateralAllActive: 0,
|
|
20603
|
+
deposits: 0,
|
|
20604
|
+
debt: 0,
|
|
20605
|
+
adjustedDebt: 0,
|
|
20606
|
+
nav: 0,
|
|
20607
|
+
deposits24h: 0,
|
|
20608
|
+
debt24h: 0,
|
|
20609
|
+
nav24h: 0
|
|
20610
|
+
};
|
|
20611
|
+
var positivePart = (x) => x > 0 ? x : 0;
|
|
20612
|
+
function getHealthFactor(collateral, adjustedDebt) {
|
|
20613
|
+
if (adjustedDebt === 0) return Infinity;
|
|
20614
|
+
const raw = collateral / adjustedDebt;
|
|
20615
|
+
return Number.isNaN(raw) ? 0 : Math.round(raw * 1e4) / 1e4;
|
|
20616
|
+
}
|
|
20617
|
+
function getBorrowCapacity(bd) {
|
|
20618
|
+
return bd.borrowDiscountedCollateral - bd.adjustedDebt;
|
|
20619
|
+
}
|
|
20620
|
+
function getAssetConfig(config, modeId) {
|
|
20621
|
+
const entry = config[modeId];
|
|
20622
|
+
if (!entry) {
|
|
20623
|
+
throw new Error(`No config found for modeId ${modeId}`);
|
|
20624
|
+
}
|
|
20625
|
+
return entry;
|
|
20626
|
+
}
|
|
20627
|
+
function computePostTradeMetrics(balanceData2, postTrade) {
|
|
20628
|
+
const healthFactor = getHealthFactor(balanceData2.collateral, balanceData2.adjustedDebt);
|
|
20629
|
+
const healthFactorPost = postTrade.adjustedDebt === 0 ? Infinity : positivePart(getHealthFactor(postTrade.collateral, postTrade.adjustedDebt));
|
|
20630
|
+
return {
|
|
20631
|
+
healthFactor,
|
|
20632
|
+
healthFactorPost,
|
|
20633
|
+
borrowCapacity: getBorrowCapacity(balanceData2),
|
|
20634
|
+
borrowCapacityPost: getBorrowCapacity(postTrade),
|
|
20635
|
+
balanceDataPost: postTrade
|
|
20636
|
+
};
|
|
20637
|
+
}
|
|
20638
|
+
|
|
20639
|
+
// src/lending/margin/base/yield/getOrganicYieldChange.ts
|
|
20640
|
+
function getOrganicYieldDeposit(amountUSD, cashFlowDeposits, cashFlowDebt, deposits, debt, yieldParams) {
|
|
20641
|
+
const totalCashFlowDeposits = cashFlowDeposits + amountUSD * yieldParams.depositRate;
|
|
20642
|
+
const newCollat = deposits + amountUSD;
|
|
20643
|
+
return [
|
|
20644
|
+
Math.abs(debt) < 0.01 ? 0 : cashFlowDebt / debt,
|
|
20645
|
+
totalCashFlowDeposits / newCollat,
|
|
20646
|
+
(totalCashFlowDeposits - cashFlowDebt) / (newCollat - debt)
|
|
20647
|
+
];
|
|
20648
|
+
}
|
|
20649
|
+
function getOrganicYieldBorrow(amountUSD, irMode, cashFlowDeposits, cashFlowDebt, deposits, debt, yieldParams) {
|
|
20650
|
+
const totalCashFlowDebt = cashFlowDebt + amountUSD * (irMode === 1 ? yieldParams.stableBorrowRate : yieldParams.variableBorrowRate);
|
|
20651
|
+
const newDebt = debt + amountUSD;
|
|
20652
|
+
return [
|
|
20653
|
+
totalCashFlowDebt / newDebt,
|
|
20654
|
+
Math.abs(deposits) < 0.01 ? 0 : cashFlowDeposits / deposits,
|
|
20655
|
+
(cashFlowDeposits - totalCashFlowDebt) / (deposits - newDebt)
|
|
20656
|
+
];
|
|
20657
|
+
}
|
|
20658
|
+
function getOrganicYieldWithdraw(amountUSD, cashFlowDeposits, cashFlowDebt, deposits, debt, yieldParams) {
|
|
20659
|
+
const totalCashFlowDeposits = cashFlowDeposits - amountUSD * yieldParams.depositRate;
|
|
20660
|
+
const newCollat = deposits - amountUSD;
|
|
20661
|
+
return [
|
|
20662
|
+
Math.abs(debt) < 0.01 ? 0 : cashFlowDebt / debt,
|
|
20663
|
+
totalCashFlowDeposits / newCollat,
|
|
20664
|
+
(totalCashFlowDeposits - cashFlowDebt) / (newCollat - debt)
|
|
20665
|
+
];
|
|
20666
|
+
}
|
|
20667
|
+
function getOrganicYieldRepay(amountUSD, irMode, cashFlowDeposits, cashFlowDebt, deposits, debt, yieldParams) {
|
|
20668
|
+
const totalCashFlowDebt = cashFlowDebt - amountUSD * (irMode === 1 ? yieldParams.stableBorrowRate : yieldParams.variableBorrowRate);
|
|
20669
|
+
const newDebt = debt - amountUSD;
|
|
20670
|
+
return [
|
|
20671
|
+
Math.abs(newDebt) < 0.01 ? 0 : totalCashFlowDebt / newDebt,
|
|
20672
|
+
Math.abs(deposits) < 0.01 ? 0 : cashFlowDeposits / deposits,
|
|
20673
|
+
(cashFlowDeposits - totalCashFlowDebt) / (deposits - newDebt)
|
|
20674
|
+
];
|
|
20675
|
+
}
|
|
20676
|
+
|
|
20677
|
+
// src/lending/margin/base/yield/getIntrinsicYieldChange.ts
|
|
20678
|
+
function getIntrinsicYieldDeposit(amountUSD, cashFlowDeposits, cashFlowDebt, deposits, debt, yieldParams) {
|
|
20679
|
+
const totalCashFlowDeposits = cashFlowDeposits + amountUSD * yieldParams.intrinsicYield;
|
|
20680
|
+
const newCollat = deposits + amountUSD;
|
|
20681
|
+
return [
|
|
20682
|
+
Math.abs(debt) < 0.01 ? 0 : cashFlowDebt / debt,
|
|
20683
|
+
totalCashFlowDeposits / newCollat,
|
|
20684
|
+
(totalCashFlowDeposits - cashFlowDebt) / (newCollat - debt)
|
|
20685
|
+
];
|
|
20686
|
+
}
|
|
20687
|
+
function getIntrinsicYieldBorrow(amountUSD, cashFlowDeposits, cashFlowDebt, deposits, debt, yieldParams) {
|
|
20688
|
+
const totalCashFlowDebt = cashFlowDebt + amountUSD * yieldParams.intrinsicYield;
|
|
20689
|
+
const newDebt = debt + amountUSD;
|
|
20690
|
+
return [
|
|
20691
|
+
totalCashFlowDebt / newDebt,
|
|
20692
|
+
Math.abs(deposits) < 0.01 ? 0 : cashFlowDeposits / deposits,
|
|
20693
|
+
(cashFlowDeposits - totalCashFlowDebt) / (deposits - newDebt)
|
|
20694
|
+
];
|
|
20695
|
+
}
|
|
20696
|
+
function getIntrinsicYieldWithdraw(amountUSD, cashFlowDeposits, cashFlowDebt, deposits, debt, yieldParams) {
|
|
20697
|
+
const totalCashFlowDeposits = cashFlowDeposits - amountUSD * yieldParams.intrinsicYield;
|
|
20698
|
+
const newCollat = deposits - amountUSD;
|
|
20699
|
+
return [
|
|
20700
|
+
Math.abs(debt) < 0.01 ? 0 : cashFlowDebt / debt,
|
|
20701
|
+
totalCashFlowDeposits / newCollat,
|
|
20702
|
+
(totalCashFlowDeposits - cashFlowDebt) / (newCollat - debt)
|
|
20703
|
+
];
|
|
20704
|
+
}
|
|
20705
|
+
function getIntrinsicYieldRepay(amountUSD, cashFlowDeposits, cashFlowDebt, deposits, debt, yieldParams) {
|
|
20706
|
+
const totalCashFlowDebt = cashFlowDebt - amountUSD * yieldParams.intrinsicYield;
|
|
20707
|
+
const newDebt = debt - amountUSD;
|
|
20708
|
+
return [
|
|
20709
|
+
Math.abs(newDebt) < 0.01 ? 0 : totalCashFlowDebt / newDebt,
|
|
20710
|
+
Math.abs(deposits) < 0.01 ? 0 : cashFlowDeposits / deposits,
|
|
20711
|
+
(cashFlowDeposits - totalCashFlowDebt) / (deposits - newDebt)
|
|
20712
|
+
];
|
|
20713
|
+
}
|
|
20714
|
+
|
|
20715
|
+
// src/lending/margin/base/yield/getRewardYieldChange.ts
|
|
20716
|
+
function getRewardYieldDeposit(amountUSD, cashFlowDeposits, cashFlowDebt, deposits, debt, yieldParams) {
|
|
20717
|
+
const rewards = yieldParams?.rewards;
|
|
20718
|
+
if (!rewards) return {};
|
|
20719
|
+
const data = {};
|
|
20720
|
+
for (const key of Object.keys(rewards)) {
|
|
20721
|
+
const _flowOut = amountUSD * (rewards[key]?.depositRate ?? 0);
|
|
20722
|
+
const totalCashFlowDeposits = cashFlowDeposits + _flowOut;
|
|
20723
|
+
const newCollat = deposits + amountUSD;
|
|
20724
|
+
data[key] = {
|
|
20725
|
+
borrowApr: Math.abs(debt) < 0.01 ? 0 : cashFlowDebt / debt,
|
|
20726
|
+
depositApr: totalCashFlowDeposits / newCollat,
|
|
20727
|
+
apr: (cashFlowDeposits + cashFlowDebt + _flowOut) / (newCollat - debt)
|
|
20728
|
+
};
|
|
20729
|
+
}
|
|
20730
|
+
return data;
|
|
20731
|
+
}
|
|
20732
|
+
function getRewardYieldBorrow(amountUSD, irMode, cashFlowDeposits, cashFlowDebt, deposits, debt, yieldParams) {
|
|
20733
|
+
const rewards = yieldParams?.rewards;
|
|
20734
|
+
if (!rewards) return {};
|
|
20735
|
+
const data = {};
|
|
20736
|
+
for (const key of Object.keys(rewards)) {
|
|
20737
|
+
const _flowIn = amountUSD * ((irMode === 1 ? rewards[key]?.stableBorrowRate : rewards[key]?.variableBorrowRate) ?? 0);
|
|
20738
|
+
const totalCashFlowDebt = cashFlowDebt + _flowIn;
|
|
20739
|
+
const newDebt = debt + amountUSD;
|
|
20740
|
+
data[key] = {
|
|
20741
|
+
borrowApr: totalCashFlowDebt / newDebt,
|
|
20742
|
+
depositApr: Math.abs(deposits) < 0.01 ? 0 : cashFlowDeposits / deposits,
|
|
20743
|
+
apr: (cashFlowDeposits + cashFlowDebt + _flowIn) / (deposits - newDebt)
|
|
20744
|
+
};
|
|
20745
|
+
}
|
|
20746
|
+
return data;
|
|
20747
|
+
}
|
|
20748
|
+
function getRewardYieldWithdraw(amountUSD, cashFlowDeposits, cashFlowDebt, deposits, debt, yieldParams) {
|
|
20749
|
+
const rewards = yieldParams?.rewards;
|
|
20750
|
+
if (!rewards) return {};
|
|
20751
|
+
const data = {};
|
|
20752
|
+
for (const key of Object.keys(rewards)) {
|
|
20753
|
+
const _flowIn = amountUSD * (rewards[key]?.depositRate ?? 0);
|
|
20754
|
+
const totalCashFlowDeposits = cashFlowDeposits - _flowIn;
|
|
20755
|
+
const newCollat = deposits - amountUSD;
|
|
20756
|
+
data[key] = {
|
|
20757
|
+
borrowApr: Math.abs(debt) < 0.01 ? 0 : cashFlowDebt / debt,
|
|
20758
|
+
depositApr: totalCashFlowDeposits / newCollat,
|
|
20759
|
+
apr: (cashFlowDeposits + cashFlowDebt - _flowIn) / (newCollat - debt)
|
|
20760
|
+
};
|
|
20761
|
+
}
|
|
20762
|
+
return data;
|
|
20763
|
+
}
|
|
20764
|
+
function getRewardYieldRepay(amountUSD, irMode, cashFlowDeposits, cashFlowDebt, deposits, debt, yieldParams) {
|
|
20765
|
+
const rewards = yieldParams?.rewards;
|
|
20766
|
+
if (!rewards) return {};
|
|
20767
|
+
const data = {};
|
|
20768
|
+
for (const key of Object.keys(rewards)) {
|
|
20769
|
+
const _flowOut = amountUSD * ((irMode === 1 ? rewards[key]?.stableBorrowRate : rewards[key]?.variableBorrowRate) ?? 0);
|
|
20770
|
+
const totalCashFlowDebt = cashFlowDebt - _flowOut;
|
|
20771
|
+
const newDebt = debt - amountUSD;
|
|
20772
|
+
data[key] = {
|
|
20773
|
+
borrowApr: Math.abs(newDebt) < 0.01 ? 0 : totalCashFlowDebt / newDebt,
|
|
20774
|
+
depositApr: Math.abs(deposits) < 0.01 ? 0 : cashFlowDeposits / deposits,
|
|
20775
|
+
apr: (cashFlowDeposits + cashFlowDebt - _flowOut) / (deposits - newDebt)
|
|
20776
|
+
};
|
|
20777
|
+
}
|
|
20778
|
+
return data;
|
|
20779
|
+
}
|
|
20780
|
+
|
|
20781
|
+
// src/lending/margin/base/deposit.ts
|
|
20782
|
+
function computeDepositDelta(amount, price, balanceData2, config, modeId, createNewSubAccount = false, apr, yieldParams) {
|
|
20783
|
+
const { borrowCollateralFactor, collateralFactor } = getAssetConfig(config, modeId);
|
|
20784
|
+
const base = createNewSubAccount ? EMPTY_BALANCE : balanceData2;
|
|
20785
|
+
const dollarAmount = amount * price;
|
|
20786
|
+
const postTrade = {
|
|
20787
|
+
...base,
|
|
20788
|
+
borrowDiscountedCollateral: base.borrowDiscountedCollateral + borrowCollateralFactor * dollarAmount,
|
|
20789
|
+
collateral: base.collateral + collateralFactor * dollarAmount,
|
|
20790
|
+
deposits: base.deposits + dollarAmount,
|
|
20791
|
+
nav: base.nav + dollarAmount
|
|
20792
|
+
};
|
|
20793
|
+
const result = computePostTradeMetrics(base, postTrade);
|
|
20794
|
+
if (apr && yieldParams) {
|
|
20795
|
+
const cashFlowDeposits = base.deposits * apr.depositApr;
|
|
20796
|
+
const cashFlowDebt = base.debt * apr.borrowApr;
|
|
20797
|
+
const rewardFlowDeposits = base.deposits * (apr.rewardDepositApr ?? 0);
|
|
20798
|
+
const rewardFlowDebt = base.debt * (apr.rewardBorrowApr ?? 0);
|
|
20799
|
+
const intrinsicFlowDeposits = base.deposits * apr.intrinsicDepositApr;
|
|
20800
|
+
const intrinsicFlowDebt = base.debt * apr.intrinsicBorrowApr;
|
|
20801
|
+
const newApr = { ...apr };
|
|
20802
|
+
[newApr.borrowApr, newApr.depositApr, newApr.apr] = getOrganicYieldDeposit(
|
|
20803
|
+
dollarAmount,
|
|
20804
|
+
cashFlowDeposits,
|
|
20805
|
+
cashFlowDebt,
|
|
20806
|
+
base.deposits,
|
|
20807
|
+
base.debt,
|
|
20808
|
+
yieldParams
|
|
20809
|
+
);
|
|
20810
|
+
newApr.rewards = getRewardYieldDeposit(
|
|
20811
|
+
dollarAmount,
|
|
20812
|
+
rewardFlowDeposits,
|
|
20813
|
+
rewardFlowDebt,
|
|
20814
|
+
base.deposits,
|
|
20815
|
+
base.debt,
|
|
20816
|
+
yieldParams
|
|
20817
|
+
);
|
|
20818
|
+
[newApr.intrinsicBorrowApr, newApr.intrinsicDepositApr, newApr.intrinsicApr] = getIntrinsicYieldDeposit(
|
|
20819
|
+
dollarAmount,
|
|
20820
|
+
intrinsicFlowDeposits,
|
|
20821
|
+
intrinsicFlowDebt,
|
|
20822
|
+
base.deposits,
|
|
20823
|
+
base.debt,
|
|
20824
|
+
yieldParams
|
|
20825
|
+
);
|
|
20826
|
+
result.aprDataPost = newApr;
|
|
20827
|
+
}
|
|
20828
|
+
return result;
|
|
20829
|
+
}
|
|
20830
|
+
|
|
20831
|
+
// src/lending/margin/base/withdraw.ts
|
|
20832
|
+
function computeWithdrawDelta(amount, price, balanceData2, config, modeId, apr, yieldParams) {
|
|
20833
|
+
const { borrowCollateralFactor, collateralFactor } = getAssetConfig(config, modeId);
|
|
20834
|
+
const dollarAmount = amount * price;
|
|
20835
|
+
const postTrade = {
|
|
20836
|
+
...balanceData2,
|
|
20837
|
+
borrowDiscountedCollateral: balanceData2.borrowDiscountedCollateral - borrowCollateralFactor * dollarAmount,
|
|
20838
|
+
collateral: balanceData2.collateral - collateralFactor * dollarAmount,
|
|
20839
|
+
deposits: balanceData2.deposits - dollarAmount,
|
|
20840
|
+
nav: balanceData2.nav - dollarAmount
|
|
20841
|
+
};
|
|
20842
|
+
const result = computePostTradeMetrics(balanceData2, postTrade);
|
|
20843
|
+
if (apr && yieldParams) {
|
|
20844
|
+
const cashFlowDeposits = balanceData2.deposits * apr.depositApr;
|
|
20845
|
+
const cashFlowDebt = balanceData2.debt * apr.borrowApr;
|
|
20846
|
+
const rewardFlowDeposits = balanceData2.deposits * (apr.rewardDepositApr ?? 0);
|
|
20847
|
+
const rewardFlowDebt = balanceData2.debt * (apr.rewardBorrowApr ?? 0);
|
|
20848
|
+
const intrinsicFlowDeposits = balanceData2.deposits * apr.intrinsicDepositApr;
|
|
20849
|
+
const intrinsicFlowDebt = balanceData2.debt * apr.intrinsicBorrowApr;
|
|
20850
|
+
const newApr = { ...apr };
|
|
20851
|
+
[newApr.borrowApr, newApr.depositApr, newApr.apr] = getOrganicYieldWithdraw(
|
|
20852
|
+
dollarAmount,
|
|
20853
|
+
cashFlowDeposits,
|
|
20854
|
+
cashFlowDebt,
|
|
20855
|
+
balanceData2.deposits,
|
|
20856
|
+
balanceData2.debt,
|
|
20857
|
+
yieldParams
|
|
20858
|
+
);
|
|
20859
|
+
newApr.rewards = getRewardYieldWithdraw(
|
|
20860
|
+
dollarAmount,
|
|
20861
|
+
rewardFlowDeposits,
|
|
20862
|
+
rewardFlowDebt,
|
|
20863
|
+
balanceData2.deposits,
|
|
20864
|
+
balanceData2.debt,
|
|
20865
|
+
yieldParams
|
|
20866
|
+
);
|
|
20867
|
+
[newApr.intrinsicBorrowApr, newApr.intrinsicDepositApr, newApr.intrinsicApr] = getIntrinsicYieldWithdraw(
|
|
20868
|
+
dollarAmount,
|
|
20869
|
+
intrinsicFlowDeposits,
|
|
20870
|
+
intrinsicFlowDebt,
|
|
20871
|
+
balanceData2.deposits,
|
|
20872
|
+
balanceData2.debt,
|
|
20873
|
+
yieldParams
|
|
20874
|
+
);
|
|
20875
|
+
result.aprDataPost = newApr;
|
|
20876
|
+
}
|
|
20877
|
+
return result;
|
|
20878
|
+
}
|
|
20879
|
+
|
|
20880
|
+
// src/lending/margin/base/borrow.ts
|
|
20881
|
+
function computeBorrowDelta(amount, price, balanceData2, config, modeId, apr, yieldParams, irMode) {
|
|
20882
|
+
const { borrowFactor } = getAssetConfig(config, modeId);
|
|
20883
|
+
const dollarAmount = amount * price;
|
|
20884
|
+
const postTrade = {
|
|
20885
|
+
...balanceData2,
|
|
20886
|
+
debt: balanceData2.debt + dollarAmount,
|
|
20887
|
+
adjustedDebt: balanceData2.adjustedDebt + borrowFactor * dollarAmount,
|
|
20888
|
+
nav: balanceData2.nav - dollarAmount
|
|
20889
|
+
};
|
|
20890
|
+
const result = computePostTradeMetrics(balanceData2, postTrade);
|
|
20891
|
+
if (apr && yieldParams) {
|
|
20892
|
+
const mode = irMode ?? 2;
|
|
20893
|
+
const cashFlowDeposits = balanceData2.deposits * apr.depositApr;
|
|
20894
|
+
const cashFlowDebt = balanceData2.debt * apr.borrowApr;
|
|
20895
|
+
const rewardFlowDeposits = balanceData2.deposits * (apr.rewardDepositApr ?? 0);
|
|
20896
|
+
const rewardFlowDebt = balanceData2.debt * (apr.rewardBorrowApr ?? 0);
|
|
20897
|
+
const intrinsicFlowDeposits = balanceData2.deposits * apr.intrinsicDepositApr;
|
|
20898
|
+
const intrinsicFlowDebt = balanceData2.debt * apr.intrinsicBorrowApr;
|
|
20899
|
+
const newApr = { ...apr };
|
|
20900
|
+
[newApr.borrowApr, newApr.depositApr, newApr.apr] = getOrganicYieldBorrow(
|
|
20901
|
+
dollarAmount,
|
|
20902
|
+
mode,
|
|
20903
|
+
cashFlowDeposits,
|
|
20904
|
+
cashFlowDebt,
|
|
20905
|
+
balanceData2.deposits,
|
|
20906
|
+
balanceData2.debt,
|
|
20907
|
+
yieldParams
|
|
20908
|
+
);
|
|
20909
|
+
newApr.rewards = getRewardYieldBorrow(
|
|
20910
|
+
dollarAmount,
|
|
20911
|
+
mode,
|
|
20912
|
+
rewardFlowDeposits,
|
|
20913
|
+
rewardFlowDebt,
|
|
20914
|
+
balanceData2.deposits,
|
|
20915
|
+
balanceData2.debt,
|
|
20916
|
+
yieldParams
|
|
20917
|
+
);
|
|
20918
|
+
[newApr.intrinsicBorrowApr, newApr.intrinsicDepositApr, newApr.intrinsicApr] = getIntrinsicYieldBorrow(
|
|
20919
|
+
dollarAmount,
|
|
20920
|
+
intrinsicFlowDeposits,
|
|
20921
|
+
intrinsicFlowDebt,
|
|
20922
|
+
balanceData2.deposits,
|
|
20923
|
+
balanceData2.debt,
|
|
20924
|
+
yieldParams
|
|
20925
|
+
);
|
|
20926
|
+
result.aprDataPost = newApr;
|
|
20927
|
+
}
|
|
20928
|
+
return result;
|
|
20929
|
+
}
|
|
20930
|
+
|
|
20931
|
+
// src/lending/margin/base/repay.ts
|
|
20932
|
+
function computeRepayDelta(amount, price, balanceData2, config, modeId, apr, yieldParams, irMode) {
|
|
20933
|
+
const { borrowFactor } = getAssetConfig(config, modeId);
|
|
20934
|
+
const dollarAmount = amount * price;
|
|
20935
|
+
const postTrade = {
|
|
20936
|
+
...balanceData2,
|
|
20937
|
+
debt: balanceData2.debt - dollarAmount,
|
|
20938
|
+
adjustedDebt: Math.max(0, balanceData2.adjustedDebt - borrowFactor * dollarAmount),
|
|
20939
|
+
nav: balanceData2.nav + dollarAmount
|
|
20940
|
+
};
|
|
20941
|
+
const result = computePostTradeMetrics(balanceData2, postTrade);
|
|
20942
|
+
if (apr && yieldParams) {
|
|
20943
|
+
const mode = irMode ?? 2;
|
|
20944
|
+
const cashFlowDeposits = balanceData2.deposits * apr.depositApr;
|
|
20945
|
+
const cashFlowDebt = balanceData2.debt * apr.borrowApr;
|
|
20946
|
+
const rewardFlowDeposits = balanceData2.deposits * (apr.rewardDepositApr ?? 0);
|
|
20947
|
+
const rewardFlowDebt = balanceData2.debt * (apr.rewardBorrowApr ?? 0);
|
|
20948
|
+
const intrinsicFlowDeposits = balanceData2.deposits * apr.intrinsicDepositApr;
|
|
20949
|
+
const intrinsicFlowDebt = balanceData2.debt * apr.intrinsicBorrowApr;
|
|
20950
|
+
const newApr = { ...apr };
|
|
20951
|
+
[newApr.borrowApr, newApr.depositApr, newApr.apr] = getOrganicYieldRepay(
|
|
20952
|
+
dollarAmount,
|
|
20953
|
+
mode,
|
|
20954
|
+
cashFlowDeposits,
|
|
20955
|
+
cashFlowDebt,
|
|
20956
|
+
balanceData2.deposits,
|
|
20957
|
+
balanceData2.debt,
|
|
20958
|
+
yieldParams
|
|
20959
|
+
);
|
|
20960
|
+
newApr.rewards = getRewardYieldRepay(
|
|
20961
|
+
dollarAmount,
|
|
20962
|
+
mode,
|
|
20963
|
+
rewardFlowDeposits,
|
|
20964
|
+
rewardFlowDebt,
|
|
20965
|
+
balanceData2.deposits,
|
|
20966
|
+
balanceData2.debt,
|
|
20967
|
+
yieldParams
|
|
20968
|
+
);
|
|
20969
|
+
[newApr.intrinsicBorrowApr, newApr.intrinsicDepositApr, newApr.intrinsicApr] = getIntrinsicYieldRepay(
|
|
20970
|
+
dollarAmount,
|
|
20971
|
+
intrinsicFlowDeposits,
|
|
20972
|
+
intrinsicFlowDebt,
|
|
20973
|
+
balanceData2.deposits,
|
|
20974
|
+
balanceData2.debt,
|
|
20975
|
+
yieldParams
|
|
20976
|
+
);
|
|
20977
|
+
result.aprDataPost = newApr;
|
|
20978
|
+
}
|
|
20979
|
+
return result;
|
|
20980
|
+
}
|
|
20981
|
+
|
|
20982
|
+
// src/lending/margin/loop/utils.ts
|
|
20983
|
+
var positivePart2 = (n) => n < 0 ? 0 : n;
|
|
20984
|
+
function nanTo(possiblyNaN, replacement = Infinity) {
|
|
20985
|
+
return isNaN(possiblyNaN) ? replacement : possiblyNaN;
|
|
20986
|
+
}
|
|
20987
|
+
function getHealthFactor2(collateral, adjustedDebt) {
|
|
20988
|
+
if (adjustedDebt === 0) return Infinity;
|
|
20989
|
+
const raw = collateral / adjustedDebt;
|
|
20990
|
+
return Math.round((isNaN(raw) ? 0 : raw) * 1e4) / 1e4;
|
|
20991
|
+
}
|
|
20992
|
+
function keysFromMaps(a, b) {
|
|
20993
|
+
const set = /* @__PURE__ */ new Set();
|
|
20994
|
+
if (a) for (const k of Object.keys(a)) set.add(k);
|
|
20995
|
+
if (b) for (const k of Object.keys(b)) set.add(k);
|
|
20996
|
+
return [...set];
|
|
20997
|
+
}
|
|
20998
|
+
function noOpResult(balance, apr) {
|
|
20999
|
+
const hf = getHealthFactor2(balance.collateral, balance.adjustedDebt);
|
|
21000
|
+
return {
|
|
21001
|
+
balanceDataPost: balance,
|
|
21002
|
+
aprDataPost: apr,
|
|
21003
|
+
healthFactor: hf,
|
|
21004
|
+
healthFactorPost: hf,
|
|
21005
|
+
borrowCapacity: balance.collateral - balance.adjustedDebt,
|
|
21006
|
+
borrowCapacityPost: balance.collateral - balance.adjustedDebt
|
|
21007
|
+
};
|
|
21008
|
+
}
|
|
21009
|
+
function buildLoopResult(balance, newBalance, apr, newApr, useAllActive = false) {
|
|
21010
|
+
const collateralPost = useAllActive ? newBalance.collateralAllActive : newBalance.collateral;
|
|
21011
|
+
return {
|
|
21012
|
+
balanceDataPost: newBalance,
|
|
21013
|
+
aprDataPost: newApr,
|
|
21014
|
+
healthFactor: getHealthFactor2(balance.collateral, balance.adjustedDebt),
|
|
21015
|
+
healthFactorPost: newBalance.adjustedDebt === 0 ? Infinity : positivePart2(getHealthFactor2(collateralPost, newBalance.adjustedDebt)),
|
|
21016
|
+
borrowCapacity: balance.collateral - balance.adjustedDebt,
|
|
21017
|
+
borrowCapacityPost: newBalance.collateral - newBalance.adjustedDebt
|
|
21018
|
+
};
|
|
21019
|
+
}
|
|
21020
|
+
|
|
21021
|
+
// src/lending/margin/loop/yield/getOraganicYieldChange.ts
|
|
21022
|
+
function getOrganicYieldOpen(amountInUSD, amountOutUSD, irModeIn, cashFlowDeposits, cashFlowDebt, deposits, debt, yieldIn, yieldOut) {
|
|
21023
|
+
const _flowIn = amountInUSD * (irModeIn === 1 ? yieldIn.stableBorrowRate : yieldIn.variableBorrowRate);
|
|
21024
|
+
const _flowOut = amountOutUSD * yieldOut.depositRate;
|
|
21025
|
+
const totalCashFlowDebt = cashFlowDebt + _flowIn;
|
|
21026
|
+
const totalCashFlowDeposits = cashFlowDeposits + _flowOut;
|
|
21027
|
+
const newCollat = deposits + amountOutUSD;
|
|
21028
|
+
const newDebt = debt + amountInUSD;
|
|
21029
|
+
return [
|
|
21030
|
+
totalCashFlowDebt / newDebt,
|
|
21031
|
+
totalCashFlowDeposits / newCollat,
|
|
21032
|
+
(totalCashFlowDeposits - totalCashFlowDebt) / (newCollat - newDebt)
|
|
21033
|
+
];
|
|
21034
|
+
}
|
|
21035
|
+
function getOrganicYieldClose(amountInUSD, amountOutUSD, irModeOut, cashFlowDeposits, cashFlowDebt, deposits, debt, yieldIn, yieldOut) {
|
|
21036
|
+
const _flowIn = amountInUSD * yieldIn.depositRate;
|
|
21037
|
+
const _flowOut = amountOutUSD * (irModeOut === 1 ? yieldOut.stableBorrowRate : yieldOut.variableBorrowRate);
|
|
21038
|
+
const totalCashFlowDebt = cashFlowDebt - _flowOut;
|
|
21039
|
+
const totalCashFlowDeposits = cashFlowDeposits - _flowIn;
|
|
21040
|
+
const newCollat = deposits - amountInUSD;
|
|
21041
|
+
const newDebt = debt - amountOutUSD;
|
|
21042
|
+
return [
|
|
21043
|
+
Math.abs(newDebt) < 0.01 ? 0 : totalCashFlowDebt / newDebt,
|
|
21044
|
+
totalCashFlowDeposits / newCollat,
|
|
21045
|
+
(totalCashFlowDeposits - totalCashFlowDebt) / (newCollat - newDebt)
|
|
21046
|
+
];
|
|
21047
|
+
}
|
|
21048
|
+
function getOrganicYieldDebtSwap(amountInUSD, amountOutUSD, irModeIn, irModeOut, cashFlowDeposits, cashFlowDebt, deposits, debt, yieldIn, yieldOut) {
|
|
21049
|
+
const _flowIn = amountInUSD * (irModeIn === 1 ? yieldIn.stableBorrowRate : yieldIn.variableBorrowRate);
|
|
21050
|
+
const _flowOut = amountOutUSD * (irModeOut === 1 ? yieldOut.stableBorrowRate : yieldOut.variableBorrowRate);
|
|
21051
|
+
const totalCashFlowDebt = cashFlowDebt + _flowIn - _flowOut;
|
|
21052
|
+
const newDebt = debt - amountOutUSD + amountInUSD;
|
|
21053
|
+
return [
|
|
21054
|
+
Math.abs(newDebt) < 0.01 ? 0 : totalCashFlowDebt / newDebt,
|
|
21055
|
+
cashFlowDeposits / deposits,
|
|
21056
|
+
(cashFlowDeposits - totalCashFlowDebt) / (deposits - newDebt)
|
|
21057
|
+
];
|
|
21058
|
+
}
|
|
21059
|
+
function getOrganicYieldCollateralSwap(amountInUSD, amountOutUSD, cashFlowDeposits, cashFlowDebt, deposits, debt, yieldIn, yieldOut) {
|
|
21060
|
+
const _flowIn = amountInUSD * yieldIn.depositRate;
|
|
21061
|
+
const _flowOut = amountOutUSD * yieldOut.depositRate;
|
|
21062
|
+
const totalCashFlowDeposits = cashFlowDeposits + _flowOut - _flowIn;
|
|
21063
|
+
const newCollat = deposits + amountOutUSD - amountInUSD;
|
|
21064
|
+
return [
|
|
21065
|
+
Math.abs(debt) < 0.01 ? 0 : cashFlowDebt / debt,
|
|
21066
|
+
totalCashFlowDeposits / newCollat,
|
|
21067
|
+
(totalCashFlowDeposits - cashFlowDebt) / (newCollat - debt)
|
|
21068
|
+
];
|
|
21069
|
+
}
|
|
21070
|
+
|
|
21071
|
+
// src/lending/margin/loop/yield/getRewardYieldChange.ts
|
|
21072
|
+
function getRewardYieldOpen(amountInUSD, amountOutUSD, irModeIn, cashFlowDeposits, cashFlowDebt, deposits, debt, yieldIn, yieldOut) {
|
|
21073
|
+
const rewardsIn = yieldIn?.rewards;
|
|
21074
|
+
const rewardsOut = yieldOut?.rewards;
|
|
21075
|
+
if (!rewardsIn || !rewardsOut) return {};
|
|
21076
|
+
const data = {};
|
|
21077
|
+
for (const key of keysFromMaps(rewardsIn, rewardsOut)) {
|
|
21078
|
+
const _flowIn = amountInUSD * ((irModeIn === 1 ? rewardsIn[key]?.stableBorrowRate : rewardsIn[key]?.variableBorrowRate) ?? 0);
|
|
21079
|
+
const _flowOut = amountOutUSD * (rewardsOut[key]?.depositRate ?? 0);
|
|
21080
|
+
const totalCashFlowDebt = cashFlowDebt + _flowIn;
|
|
21081
|
+
const totalCashFlowDeposits = cashFlowDeposits + _flowOut;
|
|
21082
|
+
const newCollat = deposits + amountOutUSD;
|
|
21083
|
+
const newDebt = debt + amountInUSD;
|
|
21084
|
+
data[key] = {
|
|
21085
|
+
borrowApr: totalCashFlowDebt / newDebt,
|
|
21086
|
+
depositApr: totalCashFlowDeposits / newCollat,
|
|
21087
|
+
apr: (cashFlowDeposits + cashFlowDebt + _flowIn + _flowOut) / (newCollat - newDebt)
|
|
21088
|
+
};
|
|
21089
|
+
}
|
|
21090
|
+
return data;
|
|
21091
|
+
}
|
|
21092
|
+
function getRewardYieldClose(amountInUSD, amountOutUSD, irModeOut, cashFlowDeposits, cashFlowDebt, deposits, debt, yieldIn, yieldOut) {
|
|
21093
|
+
const rewardsIn = yieldIn?.rewards;
|
|
21094
|
+
const rewardsOut = yieldOut?.rewards;
|
|
21095
|
+
if (!rewardsIn || !rewardsOut) return {};
|
|
21096
|
+
const data = {};
|
|
21097
|
+
for (const key of keysFromMaps(rewardsIn, rewardsOut)) {
|
|
21098
|
+
const _flowIn = amountInUSD * (rewardsIn[key]?.depositRate ?? 0);
|
|
21099
|
+
const _flowOut = amountOutUSD * ((irModeOut === 1 ? rewardsOut[key]?.stableBorrowRate : rewardsOut[key]?.variableBorrowRate) ?? 0);
|
|
21100
|
+
const totalCashFlowDebt = cashFlowDebt - _flowOut;
|
|
21101
|
+
const totalCashFlowDeposits = cashFlowDeposits - _flowIn;
|
|
21102
|
+
const newCollat = deposits - amountInUSD;
|
|
21103
|
+
const newDebt = debt - amountOutUSD;
|
|
21104
|
+
data[key] = {
|
|
21105
|
+
borrowApr: Math.abs(newDebt) < 0.01 ? 0 : totalCashFlowDebt / newDebt,
|
|
21106
|
+
depositApr: totalCashFlowDeposits / newCollat,
|
|
21107
|
+
apr: (cashFlowDeposits + cashFlowDebt - _flowIn - _flowOut) / (newCollat - newDebt)
|
|
21108
|
+
};
|
|
21109
|
+
}
|
|
21110
|
+
return data;
|
|
21111
|
+
}
|
|
21112
|
+
function getRewardYieldDebtSwap(amountInUSD, amountOutUSD, irModeIn, irModeOut, cashFlowDeposits, cashFlowDebt, deposits, debt, yieldIn, yieldOut) {
|
|
21113
|
+
const rewardsIn = yieldIn?.rewards;
|
|
21114
|
+
const rewardsOut = yieldOut?.rewards;
|
|
21115
|
+
if (!rewardsIn || !rewardsOut) return {};
|
|
21116
|
+
const data = {};
|
|
21117
|
+
for (const key of keysFromMaps(rewardsIn, rewardsOut)) {
|
|
21118
|
+
const _flowIn = amountInUSD * ((irModeIn === 1 ? rewardsIn[key]?.stableBorrowRate : rewardsIn[key]?.variableBorrowRate) ?? 0);
|
|
21119
|
+
const _flowOut = amountOutUSD * ((irModeOut === 1 ? rewardsOut[key]?.stableBorrowRate : rewardsOut[key]?.variableBorrowRate) ?? 0);
|
|
21120
|
+
const totalCashFlowDebt = cashFlowDebt + _flowIn - _flowOut;
|
|
21121
|
+
const newDebt = debt - amountOutUSD + amountInUSD;
|
|
21122
|
+
data[key] = {
|
|
21123
|
+
borrowApr: Math.abs(newDebt) < 0.01 ? 0 : totalCashFlowDebt / newDebt,
|
|
21124
|
+
depositApr: cashFlowDeposits / deposits,
|
|
21125
|
+
apr: (cashFlowDeposits + totalCashFlowDebt) / (deposits - newDebt)
|
|
21126
|
+
};
|
|
21127
|
+
}
|
|
21128
|
+
return data;
|
|
21129
|
+
}
|
|
21130
|
+
function getRewardYieldCollateralSwap(amountInUSD, amountOutUSD, cashFlowDeposits, cashFlowDebt, deposits, debt, yieldIn, yieldOut) {
|
|
21131
|
+
const rewardsIn = yieldIn?.rewards;
|
|
21132
|
+
const rewardsOut = yieldOut?.rewards;
|
|
21133
|
+
if (!rewardsIn || !rewardsOut) return {};
|
|
21134
|
+
const data = {};
|
|
21135
|
+
for (const key of keysFromMaps(rewardsIn, rewardsOut)) {
|
|
21136
|
+
const _flowIn = amountInUSD * (rewardsIn[key]?.depositRate ?? 0);
|
|
21137
|
+
const _flowOut = amountOutUSD * (rewardsOut[key]?.depositRate ?? 0);
|
|
21138
|
+
const totalCashFlowDeposits = cashFlowDeposits + _flowOut - _flowIn;
|
|
21139
|
+
const newCollat = deposits + amountOutUSD - amountInUSD;
|
|
21140
|
+
data[key] = {
|
|
21141
|
+
borrowApr: Math.abs(debt) < 0.01 ? 0 : cashFlowDebt / debt,
|
|
21142
|
+
depositApr: totalCashFlowDeposits / newCollat,
|
|
21143
|
+
apr: (totalCashFlowDeposits + cashFlowDebt) / (newCollat - debt)
|
|
21144
|
+
};
|
|
21145
|
+
}
|
|
21146
|
+
return data;
|
|
21147
|
+
}
|
|
21148
|
+
|
|
21149
|
+
// src/lending/margin/loop/yield/getIntrinsicYieldChange.ts
|
|
21150
|
+
function getIntrinsicYieldOpen(amountInUSD, amountOutUSD, cashFlowDeposits, cashFlowDebt, deposits, debt, yieldIn, yieldOut) {
|
|
21151
|
+
const _flowIn = amountInUSD * yieldIn.intrinsicYield;
|
|
21152
|
+
const _flowOut = amountOutUSD * yieldOut.intrinsicYield;
|
|
21153
|
+
const totalCashFlowDebt = cashFlowDebt + _flowIn;
|
|
21154
|
+
const totalCashFlowDeposits = cashFlowDeposits + _flowOut;
|
|
21155
|
+
const newCollat = deposits + amountOutUSD;
|
|
21156
|
+
const newDebt = debt + amountInUSD;
|
|
21157
|
+
return [
|
|
21158
|
+
totalCashFlowDebt / newDebt,
|
|
21159
|
+
totalCashFlowDeposits / newCollat,
|
|
21160
|
+
(totalCashFlowDeposits - totalCashFlowDebt) / (newCollat - newDebt)
|
|
21161
|
+
];
|
|
21162
|
+
}
|
|
21163
|
+
function getIntrinsicYieldClose(amountInUSD, amountOutUSD, cashFlowDeposits, cashFlowDebt, deposits, debt, yieldIn, yieldOut) {
|
|
21164
|
+
const _flowIn = amountInUSD * yieldIn.intrinsicYield;
|
|
21165
|
+
const _flowOut = amountOutUSD * yieldOut.intrinsicYield;
|
|
21166
|
+
const totalCashFlowDebt = cashFlowDebt - _flowOut;
|
|
21167
|
+
const totalCashFlowDeposits = cashFlowDeposits - _flowIn;
|
|
21168
|
+
const newCollat = deposits - amountInUSD;
|
|
21169
|
+
const newDebt = debt - amountOutUSD;
|
|
21170
|
+
return [
|
|
21171
|
+
Math.abs(newDebt) < 0.01 ? 0 : totalCashFlowDebt / newDebt,
|
|
21172
|
+
totalCashFlowDeposits / newCollat,
|
|
21173
|
+
(totalCashFlowDeposits - totalCashFlowDebt) / (newCollat - newDebt)
|
|
21174
|
+
];
|
|
21175
|
+
}
|
|
21176
|
+
function getIntrinsicYieldDebtSwap(amountInUSD, amountOutUSD, cashFlowDeposits, cashFlowDebt, deposits, debt, yieldIn, yieldOut) {
|
|
21177
|
+
const _flowIn = amountInUSD * yieldIn.intrinsicYield;
|
|
21178
|
+
const _flowOut = amountOutUSD * yieldOut.intrinsicYield;
|
|
21179
|
+
const totalCashFlowDebt = cashFlowDebt + _flowIn - _flowOut;
|
|
21180
|
+
const newDebt = debt - amountOutUSD + amountInUSD;
|
|
21181
|
+
return [
|
|
21182
|
+
Math.abs(newDebt) < 0.01 ? 0 : totalCashFlowDebt / newDebt,
|
|
21183
|
+
cashFlowDeposits / deposits,
|
|
21184
|
+
(cashFlowDeposits - totalCashFlowDebt) / (deposits - newDebt)
|
|
21185
|
+
];
|
|
21186
|
+
}
|
|
21187
|
+
function getIntrinsicYieldCollateralSwap(amountInUSD, amountOutUSD, cashFlowDeposits, cashFlowDebt, deposits, debt, yieldIn, yieldOut) {
|
|
21188
|
+
const _flowIn = amountInUSD * yieldIn.intrinsicYield;
|
|
21189
|
+
const _flowOut = amountOutUSD * yieldOut.intrinsicYield;
|
|
21190
|
+
const totalCashFlowDeposits = cashFlowDeposits + _flowOut - _flowIn;
|
|
21191
|
+
const newCollat = deposits + amountOutUSD - amountInUSD;
|
|
21192
|
+
return [
|
|
21193
|
+
Math.abs(debt) < 0.01 ? 0 : cashFlowDebt / debt,
|
|
21194
|
+
totalCashFlowDeposits / newCollat,
|
|
21195
|
+
(totalCashFlowDeposits - cashFlowDebt) / (newCollat - debt)
|
|
21196
|
+
];
|
|
21197
|
+
}
|
|
21198
|
+
|
|
21199
|
+
// src/lending/margin/loop/compute/computeCloseDeltas.ts
|
|
21200
|
+
function computeCloseTradeDeltas(dollarIn, dollarOut, targetMode, yieldParamsIn, yieldParamsOut, balance, apr, bfOut, ltvIn, collateralLtvIn) {
|
|
21201
|
+
if (dollarIn === 0 || dollarOut === 0) return noOpResult(balance, apr);
|
|
21202
|
+
const cashFlowDeposits = balance.deposits * apr.depositApr;
|
|
21203
|
+
const cashFlowDebt = balance.debt * apr.borrowApr;
|
|
21204
|
+
const rewardFlowDeposits = balance.deposits * (apr.rewardDepositApr ?? 0);
|
|
21205
|
+
const rewardFlowDebt = balance.debt * (apr.rewardBorrowApr ?? 0);
|
|
21206
|
+
const intrinsicFlowDeposits = balance.deposits * apr.intrinsicDepositApr;
|
|
21207
|
+
const intrinsicFlowDebt = balance.debt * apr.intrinsicBorrowApr;
|
|
21208
|
+
const newBalance = { ...balance };
|
|
21209
|
+
const newApr = { ...apr };
|
|
21210
|
+
newBalance.debt = positivePart2(newBalance.debt - dollarOut);
|
|
21211
|
+
newBalance.borrowDiscountedCollateral = positivePart2(
|
|
21212
|
+
newBalance.borrowDiscountedCollateral - ltvIn * dollarIn
|
|
21213
|
+
);
|
|
21214
|
+
newBalance.collateral = positivePart2(
|
|
21215
|
+
newBalance.collateral - collateralLtvIn * dollarIn
|
|
21216
|
+
);
|
|
21217
|
+
newBalance.deposits = positivePart2(newBalance.deposits - dollarIn);
|
|
21218
|
+
newBalance.adjustedDebt = positivePart2(
|
|
21219
|
+
newBalance.adjustedDebt - bfOut * dollarOut
|
|
21220
|
+
);
|
|
21221
|
+
newBalance.nav += dollarOut - dollarIn;
|
|
21222
|
+
[newApr.borrowApr, newApr.depositApr, newApr.apr] = getOrganicYieldClose(
|
|
21223
|
+
dollarIn,
|
|
21224
|
+
dollarOut,
|
|
21225
|
+
targetMode,
|
|
21226
|
+
cashFlowDeposits,
|
|
21227
|
+
cashFlowDebt,
|
|
21228
|
+
balance.deposits,
|
|
21229
|
+
balance.debt,
|
|
21230
|
+
yieldParamsIn,
|
|
21231
|
+
yieldParamsOut
|
|
21232
|
+
);
|
|
21233
|
+
newApr.rewards = getRewardYieldClose(
|
|
21234
|
+
dollarIn,
|
|
21235
|
+
dollarOut,
|
|
21236
|
+
targetMode,
|
|
21237
|
+
rewardFlowDeposits,
|
|
21238
|
+
rewardFlowDebt,
|
|
21239
|
+
balance.deposits,
|
|
21240
|
+
balance.debt,
|
|
21241
|
+
yieldParamsIn,
|
|
21242
|
+
yieldParamsOut
|
|
21243
|
+
);
|
|
21244
|
+
[newApr.intrinsicBorrowApr, newApr.intrinsicDepositApr, newApr.intrinsicApr] = getIntrinsicYieldClose(
|
|
21245
|
+
dollarIn,
|
|
21246
|
+
dollarOut,
|
|
21247
|
+
intrinsicFlowDeposits,
|
|
21248
|
+
intrinsicFlowDebt,
|
|
21249
|
+
balance.deposits,
|
|
21250
|
+
balance.debt,
|
|
21251
|
+
yieldParamsIn,
|
|
21252
|
+
yieldParamsOut
|
|
21253
|
+
);
|
|
21254
|
+
return buildLoopResult(balance, newBalance, apr, newApr);
|
|
21255
|
+
}
|
|
21256
|
+
|
|
21257
|
+
// src/lending/margin/loop/compute/computeCollateralSwapDeltas.ts
|
|
21258
|
+
function computeCollateralSwapDeltas(dollarIn, dollarOut, yieldParamsIn, yieldParamsOut, balance, apr, ltvIn, collateralLtvIn, ltvOut, collateralLtvOut) {
|
|
21259
|
+
if (dollarIn === 0 || dollarOut === 0) return noOpResult(balance, apr);
|
|
21260
|
+
const cashFlowDeposits = balance.deposits * apr.depositApr;
|
|
21261
|
+
const cashFlowDebt = balance.debt * apr.borrowApr;
|
|
21262
|
+
const rewardFlowDeposits = balance.deposits * (apr.rewardDepositApr ?? 0);
|
|
21263
|
+
const rewardFlowDebt = balance.debt * (apr.rewardBorrowApr ?? 0);
|
|
21264
|
+
const intrinsicFlowDeposits = balance.deposits * apr.intrinsicDepositApr;
|
|
21265
|
+
const intrinsicFlowDebt = balance.debt * apr.intrinsicBorrowApr;
|
|
21266
|
+
const newBalance = { ...balance };
|
|
21267
|
+
const newApr = { ...apr };
|
|
21268
|
+
newBalance.borrowDiscountedCollateral += ltvOut * dollarOut - ltvIn * dollarIn;
|
|
21269
|
+
newBalance.deposits += dollarOut - dollarIn;
|
|
21270
|
+
newBalance.collateral += collateralLtvOut * dollarOut - collateralLtvIn * dollarIn;
|
|
21271
|
+
newBalance.nav += dollarOut - dollarIn;
|
|
21272
|
+
[newApr.borrowApr, newApr.depositApr, newApr.apr] = getOrganicYieldCollateralSwap(
|
|
21273
|
+
dollarIn,
|
|
21274
|
+
dollarOut,
|
|
21275
|
+
cashFlowDeposits,
|
|
21276
|
+
cashFlowDebt,
|
|
21277
|
+
balance.deposits,
|
|
21278
|
+
balance.debt,
|
|
21279
|
+
yieldParamsIn,
|
|
21280
|
+
yieldParamsOut
|
|
21281
|
+
);
|
|
21282
|
+
newApr.rewards = getRewardYieldCollateralSwap(
|
|
21283
|
+
dollarIn,
|
|
21284
|
+
dollarOut,
|
|
21285
|
+
rewardFlowDeposits,
|
|
21286
|
+
rewardFlowDebt,
|
|
21287
|
+
balance.deposits,
|
|
21288
|
+
balance.debt,
|
|
21289
|
+
yieldParamsIn,
|
|
21290
|
+
yieldParamsOut
|
|
21291
|
+
);
|
|
21292
|
+
[newApr.intrinsicBorrowApr, newApr.intrinsicDepositApr, newApr.intrinsicApr] = getIntrinsicYieldCollateralSwap(
|
|
21293
|
+
dollarIn,
|
|
21294
|
+
dollarOut,
|
|
21295
|
+
intrinsicFlowDeposits,
|
|
21296
|
+
intrinsicFlowDebt,
|
|
21297
|
+
balance.deposits,
|
|
21298
|
+
balance.debt,
|
|
21299
|
+
yieldParamsIn,
|
|
21300
|
+
yieldParamsOut
|
|
21301
|
+
);
|
|
21302
|
+
return buildLoopResult(balance, newBalance, apr, newApr);
|
|
21303
|
+
}
|
|
21304
|
+
|
|
21305
|
+
// src/lending/margin/loop/compute/computeDebtSwapDeltas.ts
|
|
21306
|
+
function computeDebtSwapDeltas(dollarIn, dollarOut, sourceMode, targetMode, yieldParamsIn, yieldParamsOut, balance, apr, bfInFactor, bfOutFactor) {
|
|
21307
|
+
if (dollarIn === 0 || dollarOut === 0) return noOpResult(balance, apr);
|
|
21308
|
+
const cashFlowDeposits = balance.deposits * apr.depositApr;
|
|
21309
|
+
const cashFlowDebt = balance.debt * apr.borrowApr;
|
|
21310
|
+
const rewardFlowDeposits = balance.deposits * (apr.rewardDepositApr ?? 0);
|
|
21311
|
+
const rewardFlowDebt = balance.debt * apr.rewardBorrowApr;
|
|
21312
|
+
const intrinsicFlowDeposits = balance.deposits * apr.intrinsicDepositApr;
|
|
21313
|
+
const intrinsicFlowDebt = balance.debt * apr.intrinsicBorrowApr;
|
|
21314
|
+
const newBalance = { ...balance };
|
|
21315
|
+
const newApr = { ...apr };
|
|
21316
|
+
newBalance.debt += dollarOut - dollarIn;
|
|
21317
|
+
newBalance.adjustedDebt += bfOutFactor * dollarOut - bfInFactor * dollarIn;
|
|
21318
|
+
newBalance.nav += dollarOut - dollarIn;
|
|
21319
|
+
[newApr.borrowApr, newApr.depositApr, newApr.apr] = getOrganicYieldDebtSwap(
|
|
21320
|
+
dollarIn,
|
|
21321
|
+
dollarOut,
|
|
21322
|
+
sourceMode,
|
|
21323
|
+
targetMode,
|
|
21324
|
+
cashFlowDeposits,
|
|
21325
|
+
cashFlowDebt,
|
|
21326
|
+
balance.deposits,
|
|
21327
|
+
balance.debt,
|
|
21328
|
+
yieldParamsIn,
|
|
21329
|
+
yieldParamsOut
|
|
21330
|
+
);
|
|
21331
|
+
newApr.rewards = getRewardYieldDebtSwap(
|
|
21332
|
+
dollarIn,
|
|
21333
|
+
dollarOut,
|
|
21334
|
+
sourceMode,
|
|
21335
|
+
targetMode,
|
|
21336
|
+
rewardFlowDeposits,
|
|
21337
|
+
rewardFlowDebt,
|
|
21338
|
+
balance.deposits,
|
|
21339
|
+
balance.debt,
|
|
21340
|
+
yieldParamsIn,
|
|
21341
|
+
yieldParamsOut
|
|
21342
|
+
);
|
|
21343
|
+
[newApr.intrinsicBorrowApr, newApr.intrinsicDepositApr, newApr.intrinsicApr] = getIntrinsicYieldDebtSwap(
|
|
21344
|
+
dollarIn,
|
|
21345
|
+
dollarOut,
|
|
21346
|
+
intrinsicFlowDeposits,
|
|
21347
|
+
intrinsicFlowDebt,
|
|
21348
|
+
balance.deposits,
|
|
21349
|
+
balance.debt,
|
|
21350
|
+
yieldParamsIn,
|
|
21351
|
+
yieldParamsOut
|
|
21352
|
+
);
|
|
21353
|
+
return buildLoopResult(balance, newBalance, apr, newApr);
|
|
21354
|
+
}
|
|
21355
|
+
|
|
21356
|
+
// src/lending/margin/loop/compute/computeOpenDeltas.ts
|
|
21357
|
+
function computeOpenTradeDeltas(dollarIn, dollarOut, sourceMode, yieldParamsIn, yieldParamsOut, balance, apr, bfIn, collateralLtvOut, borrowLtvOut, useAllActive = false) {
|
|
21358
|
+
if (dollarIn === 0 || dollarOut === 0) return noOpResult(balance, apr);
|
|
21359
|
+
const cashFlowDeposits = balance.deposits * apr.depositApr;
|
|
21360
|
+
const cashFlowDebt = balance.debt * apr.borrowApr;
|
|
21361
|
+
const rewardFlowDeposits = balance.deposits * (apr.rewardDepositApr ?? 0);
|
|
21362
|
+
const rewardFlowDebt = balance.debt * (apr.rewardBorrowApr ?? 0);
|
|
21363
|
+
const intrinsicFlowDeposits = balance.deposits * apr.intrinsicDepositApr;
|
|
21364
|
+
const intrinsicFlowDebt = balance.debt * apr.intrinsicBorrowApr;
|
|
21365
|
+
const newBalance = { ...balance };
|
|
21366
|
+
const newApr = { ...apr };
|
|
21367
|
+
newBalance.debt += dollarIn;
|
|
21368
|
+
newBalance.borrowDiscountedCollateral += borrowLtvOut * dollarOut;
|
|
21369
|
+
newBalance.borrowDiscountedCollateralAllActive += borrowLtvOut * dollarOut;
|
|
21370
|
+
newBalance.collateral += collateralLtvOut * dollarOut;
|
|
21371
|
+
newBalance.collateralAllActive += collateralLtvOut * dollarOut;
|
|
21372
|
+
newBalance.deposits += dollarOut;
|
|
21373
|
+
newBalance.adjustedDebt += bfIn * dollarIn;
|
|
21374
|
+
newBalance.nav += dollarOut - dollarIn;
|
|
21375
|
+
[newApr.borrowApr, newApr.depositApr, newApr.apr] = getOrganicYieldOpen(
|
|
21376
|
+
dollarIn,
|
|
21377
|
+
dollarOut,
|
|
21378
|
+
sourceMode,
|
|
21379
|
+
cashFlowDeposits,
|
|
21380
|
+
cashFlowDebt,
|
|
21381
|
+
balance.deposits,
|
|
21382
|
+
balance.debt,
|
|
21383
|
+
yieldParamsIn,
|
|
21384
|
+
yieldParamsOut
|
|
21385
|
+
);
|
|
21386
|
+
newApr.rewards = getRewardYieldOpen(
|
|
21387
|
+
dollarIn,
|
|
21388
|
+
dollarOut,
|
|
21389
|
+
sourceMode,
|
|
21390
|
+
rewardFlowDeposits,
|
|
21391
|
+
rewardFlowDebt,
|
|
21392
|
+
balance.deposits,
|
|
21393
|
+
balance.debt,
|
|
21394
|
+
yieldParamsIn,
|
|
21395
|
+
yieldParamsOut
|
|
21396
|
+
);
|
|
21397
|
+
[newApr.intrinsicBorrowApr, newApr.intrinsicDepositApr, newApr.intrinsicApr] = getIntrinsicYieldOpen(
|
|
21398
|
+
dollarIn,
|
|
21399
|
+
dollarOut,
|
|
21400
|
+
intrinsicFlowDeposits,
|
|
21401
|
+
intrinsicFlowDebt,
|
|
21402
|
+
balance.deposits,
|
|
21403
|
+
balance.debt,
|
|
21404
|
+
yieldParamsIn,
|
|
21405
|
+
yieldParamsOut
|
|
21406
|
+
);
|
|
21407
|
+
return buildLoopResult(balance, newBalance, apr, newApr, useAllActive);
|
|
21408
|
+
}
|
|
21409
|
+
|
|
21410
|
+
// src/lending/margin/loop/compute/computeZapDeltas.ts
|
|
21411
|
+
function computeZapTradeDeltas(dollarIn, dollarOut, sourceMode, yieldParamsIn, yieldParamsOut, balance, apr, bfIn, collateralLtvOut, borrowLtvOut) {
|
|
21412
|
+
if (dollarIn === 0 || dollarOut === 0) return noOpResult(balance, apr);
|
|
21413
|
+
const cashFlowDeposits = balance.deposits * apr.depositApr;
|
|
21414
|
+
const cashFlowDebt = balance.debt * apr.borrowApr;
|
|
21415
|
+
const rewardFlowDeposits = balance.deposits * (apr.rewardDepositApr ?? 0);
|
|
21416
|
+
const rewardFlowDebt = balance.debt * (apr.rewardBorrowApr ?? 0);
|
|
21417
|
+
const intrinsicFlowDeposits = balance.deposits * apr.intrinsicDepositApr;
|
|
21418
|
+
const intrinsicFlowDebt = balance.debt * apr.intrinsicBorrowApr;
|
|
21419
|
+
const newBalance = { ...balance };
|
|
21420
|
+
const newApr = { ...apr };
|
|
21421
|
+
newBalance.debt += dollarIn;
|
|
21422
|
+
newBalance.borrowDiscountedCollateral += borrowLtvOut * dollarOut;
|
|
21423
|
+
newBalance.collateral += collateralLtvOut * dollarOut;
|
|
21424
|
+
newBalance.deposits += dollarOut;
|
|
21425
|
+
newBalance.adjustedDebt += bfIn * dollarIn;
|
|
21426
|
+
newBalance.nav += dollarOut - dollarIn;
|
|
21427
|
+
[newApr.borrowApr, newApr.depositApr, newApr.apr] = getOrganicYieldOpen(
|
|
21428
|
+
dollarIn,
|
|
21429
|
+
dollarOut,
|
|
21430
|
+
sourceMode,
|
|
21431
|
+
cashFlowDeposits,
|
|
21432
|
+
cashFlowDebt,
|
|
21433
|
+
balance.deposits,
|
|
21434
|
+
balance.debt,
|
|
21435
|
+
yieldParamsIn,
|
|
21436
|
+
yieldParamsOut
|
|
21437
|
+
);
|
|
21438
|
+
newApr.rewards = getRewardYieldOpen(
|
|
21439
|
+
dollarIn,
|
|
21440
|
+
dollarOut,
|
|
21441
|
+
sourceMode,
|
|
21442
|
+
rewardFlowDeposits,
|
|
21443
|
+
rewardFlowDebt,
|
|
21444
|
+
balance.deposits,
|
|
21445
|
+
balance.debt,
|
|
21446
|
+
yieldParamsIn,
|
|
21447
|
+
yieldParamsOut
|
|
21448
|
+
);
|
|
21449
|
+
[newApr.intrinsicBorrowApr, newApr.intrinsicDepositApr, newApr.intrinsicApr] = getIntrinsicYieldOpen(
|
|
21450
|
+
dollarIn,
|
|
21451
|
+
dollarOut,
|
|
21452
|
+
intrinsicFlowDeposits,
|
|
21453
|
+
intrinsicFlowDebt,
|
|
21454
|
+
balance.deposits,
|
|
21455
|
+
balance.debt,
|
|
21456
|
+
yieldParamsIn,
|
|
21457
|
+
yieldParamsOut
|
|
21458
|
+
);
|
|
21459
|
+
return buildLoopResult(balance, newBalance, apr, newApr);
|
|
21460
|
+
}
|
|
21461
|
+
|
|
20121
21462
|
// src/assets/liquidityThresholds.ts
|
|
20122
21463
|
var DEFAULT_LIQUIDITY_THRESHOLDS = {
|
|
20123
21464
|
minDepositsUSD: 25e3,
|
|
@@ -20220,6 +21561,17 @@ var getMaxLeverage = (lender, longData, shortData) => {
|
|
|
20220
21561
|
const bf = shortData.config[configId]?.borrowFactor;
|
|
20221
21562
|
return 1 / (1 - cf2 / bf);
|
|
20222
21563
|
}
|
|
21564
|
+
if (isSumerType(lender)) {
|
|
21565
|
+
const shortEntries = Object.entries(shortData?.config ?? {});
|
|
21566
|
+
if (shortEntries.length === 0) return 1;
|
|
21567
|
+
const shortGroupId = Number(
|
|
21568
|
+
shortEntries.sort(
|
|
21569
|
+
([, a], [, b]) => b.borrowCollateralFactor - a.borrowCollateralFactor
|
|
21570
|
+
)[0][0]
|
|
21571
|
+
);
|
|
21572
|
+
const cf2 = longData?.config?.[shortGroupId]?.borrowCollateralFactor ?? 0;
|
|
21573
|
+
return cf2 > 0 && cf2 < 1 ? 1 / (1 - cf2) : 1;
|
|
21574
|
+
}
|
|
20223
21575
|
const cf = longData?.config?.[LENDER_MODE_NO_MODE2]?.borrowCollateralFactor ?? 0.8;
|
|
20224
21576
|
return 1 / (1 - cf);
|
|
20225
21577
|
};
|
|
@@ -20267,8 +21619,8 @@ function generateLendingPairs(lenderData, prices, histPrices) {
|
|
|
20267
21619
|
const borrowRate = baseYields.stableBorrowRate >= baseYields.variableBorrowRate ? baseYields.stableBorrowRate : baseYields.variableBorrowRate;
|
|
20268
21620
|
borrowRewards += borrowRate;
|
|
20269
21621
|
}
|
|
20270
|
-
const depositApr = long.depositRate + long.
|
|
20271
|
-
const borrowApr = short.variableBorrowRate + short.
|
|
21622
|
+
const depositApr = long.depositRate + long.intrinsicYield;
|
|
21623
|
+
const borrowApr = short.variableBorrowRate + short.intrinsicYield;
|
|
20272
21624
|
const [assetGroupLong, keyLong] = getPriceKey2(long.asset);
|
|
20273
21625
|
const [assetGroupShort, keyShort] = getPriceKey2(short.asset);
|
|
20274
21626
|
const priceLong = prices[keyLong] ?? 0;
|
|
@@ -21080,7 +22432,7 @@ var yearnKatanaFetcher = {
|
|
|
21080
22432
|
Object.entries(res).forEach(([addr, data]) => {
|
|
21081
22433
|
const key = addressToAssetYearn[addr.toLowerCase()];
|
|
21082
22434
|
if (key) {
|
|
21083
|
-
const apr = ((data.apr.netAPR ?? 0) + (data.apr.extra
|
|
22435
|
+
const apr = ((data.apr.netAPR ?? 0) + (data.apr.extra?.extrinsicYield ?? 0) + (data.apr.extra?.katanaNativeYield ?? 0)) * 100;
|
|
21084
22436
|
map[key] = apr;
|
|
21085
22437
|
}
|
|
21086
22438
|
});
|
|
@@ -25447,31 +26799,56 @@ function parseTokenBalanceResult(rawResult, query2) {
|
|
|
25447
26799
|
}
|
|
25448
26800
|
return result;
|
|
25449
26801
|
}
|
|
26802
|
+
async function rpcFetchWithRetry(rpcUrls, body, maxRetries2) {
|
|
26803
|
+
let lastError;
|
|
26804
|
+
for (let attempt = 0; attempt <= maxRetries2; attempt++) {
|
|
26805
|
+
const url = rpcUrls[attempt % rpcUrls.length];
|
|
26806
|
+
try {
|
|
26807
|
+
const res = await fetch(url, {
|
|
26808
|
+
method: "POST",
|
|
26809
|
+
headers: { "Content-Type": "application/json" },
|
|
26810
|
+
body
|
|
26811
|
+
});
|
|
26812
|
+
if (!res.ok) {
|
|
26813
|
+
lastError = new Error(`RPC ${res.status} ${res.statusText}`);
|
|
26814
|
+
continue;
|
|
26815
|
+
}
|
|
26816
|
+
const json = await res.json();
|
|
26817
|
+
if (json.error) {
|
|
26818
|
+
lastError = new Error(`RPC error: ${JSON.stringify(json.error)}`);
|
|
26819
|
+
continue;
|
|
26820
|
+
}
|
|
26821
|
+
return json.result ?? "0x";
|
|
26822
|
+
} catch (e) {
|
|
26823
|
+
lastError = e instanceof Error ? e : new Error(String(e));
|
|
26824
|
+
}
|
|
26825
|
+
}
|
|
26826
|
+
throw lastError ?? new Error("All RPC attempts failed");
|
|
26827
|
+
}
|
|
25450
26828
|
async function fetchTokenBalances(chainId, account, tokens, options = {}) {
|
|
25451
|
-
const { blockTag = "latest", rpcUrl } = options;
|
|
26829
|
+
const { blockTag = "latest", rpcUrl, rpcUrls, maxRetries: maxRetries2 = 3 } = options;
|
|
25452
26830
|
const prepared = prepareTokenBalanceRpcCalls(chainId, account, tokens, blockTag);
|
|
25453
|
-
|
|
25454
|
-
|
|
25455
|
-
|
|
25456
|
-
|
|
25457
|
-
|
|
25458
|
-
|
|
25459
|
-
|
|
25460
|
-
|
|
25461
|
-
|
|
25462
|
-
|
|
25463
|
-
|
|
25464
|
-
|
|
25465
|
-
if (!response.ok) {
|
|
25466
|
-
throw new Error(`RPC request failed: ${response.status} ${response.statusText}`);
|
|
25467
|
-
}
|
|
25468
|
-
const result = await response.json();
|
|
25469
|
-
if (result.error) {
|
|
25470
|
-
throw new Error(`RPC error: ${JSON.stringify(result.error)}`);
|
|
26831
|
+
let urls;
|
|
26832
|
+
if (rpcUrls?.length) {
|
|
26833
|
+
urls = rpcUrls;
|
|
26834
|
+
} else if (rpcUrl) {
|
|
26835
|
+
urls = [rpcUrl];
|
|
26836
|
+
} else {
|
|
26837
|
+
const chain = getEvmChain(chainId);
|
|
26838
|
+
const defaultUrl = chain.rpcUrls?.default?.http?.[0];
|
|
26839
|
+
if (!defaultUrl) {
|
|
26840
|
+
throw new Error(`No RPC URL available for chain ${chainId}`);
|
|
26841
|
+
}
|
|
26842
|
+
urls = [defaultUrl];
|
|
25471
26843
|
}
|
|
25472
|
-
|
|
26844
|
+
const rawResult = await rpcFetchWithRetry(
|
|
26845
|
+
urls,
|
|
26846
|
+
JSON.stringify(prepared.call),
|
|
26847
|
+
maxRetries2
|
|
26848
|
+
);
|
|
26849
|
+
return parseTokenBalanceResult(rawResult, prepared.query);
|
|
25473
26850
|
}
|
|
25474
26851
|
|
|
25475
|
-
export {
|
|
26852
|
+
export { EMPTY_BALANCE, MORPHO_LENS, attachPricesToFlashLiquidity, buildLoopResult, buildMorphoTypeCall, buildMorphoTypeUserCallWithLens, buildPortfolioTotals, buildSummaries, calculateLeverage, calculateNetApr, calculateOverallNetApr, calculateWeightedAverage, computeBorrowDelta, computeCloseTradeDeltas, computeCollateralSwapDeltas, computeDebtSwapDeltas, computeDepositDelta, computeOpenTradeDeltas, computePostTradeMetrics, computeRepayDelta, computeWithdrawDelta, computeZapTradeDeltas, convertLenderUserDataResult, createMarketUid, createMulticallRpcCall, createRawRpcCalls, decodeListaMarkets, decodeMarkets, decodePackedListaUserDataset, decodePackedMorphoUserDataset, encodeBalanceFetcherCalldata, fetchDefillamaData, fetchDefillamaHistData, fetchFlashLiquidityForChain, fetchGeneralYields, fetchMainPrices, fetchOraclePrices, fetchPendlePrices, fetchTokenBalances, fetchTokenMetadata, filterActiveLenders, filterLendersByProtocol, flattenToUSDPriceMap, fuseLenderData, generateLendingPairs, generateLendingPools, getAavesForChain, getAssetConfig, getBorrowCapacity, getHealthFactor, getLenderAssets, getLenderPublicData, getLenderPublicDataAll, getLenderPublicDataViaApi, getLenderUserDataMulti, getLenderUserDataResult, getLendersForChain, getMorphoTypeMarketConverter, getTopPairs, isAaveType, isAaveV2Type, isAaveV32Type, isAaveV3Type, isCompoundV3, isCompoundV3Type, isInit, isMorphoType, isMultiMarket, isYLDR, keysFromMaps, multicall3Abi, nanTo, noOpResult, normalizeToBytes, parseBalanceFetcherResult, parseMulticallRpcResponses, parseRawRpcBatchResponses, parseRawRpcResponses, parseTokenBalanceResult, positivePart2 as positivePart, prepareLenderUserDataRpcCalls, prepareMulticallInputs, prepareTokenBalanceRpcCalls, unflattenLenderData };
|
|
25476
26853
|
//# sourceMappingURL=index.js.map
|
|
25477
26854
|
//# sourceMappingURL=index.js.map
|