@1delta/margin-fetcher 0.0.161 → 0.0.163
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/TakaraMarketState.d.ts +73 -0
- package/dist/abis/compound-v2/TakaraMarketState.d.ts.map +1 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +392 -19
- package/dist/index.js.map +1 -1
- package/dist/lending/margin/e-mode/index.d.ts +24 -0
- package/dist/lending/margin/e-mode/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/convert/standard.d.ts +45 -0
- package/dist/lending/public-data/compound-v2/convert/standard.d.ts.map +1 -0
- package/dist/lending/public-data/compound-v2/convert/sumer.d.ts +49 -0
- package/dist/lending/public-data/compound-v2/convert/sumer.d.ts.map +1 -0
- package/dist/lending/public-data/compound-v2/convert/takara.d.ts +43 -0
- package/dist/lending/public-data/compound-v2/convert/takara.d.ts.map +1 -0
- package/dist/lending/public-data/compound-v2/convert/types.d.ts +30 -0
- package/dist/lending/public-data/compound-v2/convert/types.d.ts.map +1 -0
- package/dist/lending/public-data/compound-v2/getters/takara.d.ts +33 -0
- package/dist/lending/public-data/compound-v2/getters/takara.d.ts.map +1 -0
- package/dist/lending/public-data/compound-v2/publicCallBuild.d.ts +77 -1
- 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/user-data/utils/createGeneralUserState.d.ts.map +1 -1
- package/dist/prices/oracle-prices/fetchOraclePrices.d.ts +0 -5
- package/dist/prices/oracle-prices/fetchOraclePrices.d.ts.map +1 -1
- package/dist/prices/oracle-prices/index.d.ts +3 -2
- package/dist/prices/oracle-prices/index.d.ts.map +1 -1
- package/dist/prices/oracle-prices/selectAssetGroupPrices.d.ts +10 -0
- package/dist/prices/oracle-prices/selectAssetGroupPrices.d.ts.map +1 -0
- package/dist/prices/oracle-prices/types.d.ts +59 -0
- package/dist/prices/oracle-prices/types.d.ts.map +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export declare const TakaraMarketStateAbi: readonly [{
|
|
2
|
+
readonly inputs: readonly [];
|
|
3
|
+
readonly name: "getActiveMarketsInfo";
|
|
4
|
+
readonly outputs: readonly [{
|
|
5
|
+
readonly components: readonly [{
|
|
6
|
+
readonly internalType: "uint256";
|
|
7
|
+
readonly name: "tvl";
|
|
8
|
+
readonly type: "uint256";
|
|
9
|
+
}, {
|
|
10
|
+
readonly internalType: "uint256";
|
|
11
|
+
readonly name: "ltv";
|
|
12
|
+
readonly type: "uint256";
|
|
13
|
+
}, {
|
|
14
|
+
readonly internalType: "uint256";
|
|
15
|
+
readonly name: "exchangeRateCurrent";
|
|
16
|
+
readonly type: "uint256";
|
|
17
|
+
}, {
|
|
18
|
+
readonly internalType: "uint256";
|
|
19
|
+
readonly name: "reserveFactorMantissa";
|
|
20
|
+
readonly type: "uint256";
|
|
21
|
+
}, {
|
|
22
|
+
readonly internalType: "uint256";
|
|
23
|
+
readonly name: "totalSupply";
|
|
24
|
+
readonly type: "uint256";
|
|
25
|
+
}, {
|
|
26
|
+
readonly internalType: "bool";
|
|
27
|
+
readonly name: "isListed";
|
|
28
|
+
readonly type: "bool";
|
|
29
|
+
}, {
|
|
30
|
+
readonly internalType: "uint256";
|
|
31
|
+
readonly name: "totalBorrows";
|
|
32
|
+
readonly type: "uint256";
|
|
33
|
+
}, {
|
|
34
|
+
readonly internalType: "uint256";
|
|
35
|
+
readonly name: "supplyRatePerBlock";
|
|
36
|
+
readonly type: "uint256";
|
|
37
|
+
}, {
|
|
38
|
+
readonly internalType: "uint256";
|
|
39
|
+
readonly name: "borrowRatePerBlock";
|
|
40
|
+
readonly type: "uint256";
|
|
41
|
+
}, {
|
|
42
|
+
readonly internalType: "uint256";
|
|
43
|
+
readonly name: "blocksPerYear";
|
|
44
|
+
readonly type: "uint256";
|
|
45
|
+
}, {
|
|
46
|
+
readonly internalType: "uint256";
|
|
47
|
+
readonly name: "timestampsPerYear";
|
|
48
|
+
readonly type: "uint256";
|
|
49
|
+
}, {
|
|
50
|
+
readonly internalType: "address";
|
|
51
|
+
readonly name: "token";
|
|
52
|
+
readonly type: "address";
|
|
53
|
+
}, {
|
|
54
|
+
readonly internalType: "address";
|
|
55
|
+
readonly name: "underlying";
|
|
56
|
+
readonly type: "address";
|
|
57
|
+
}, {
|
|
58
|
+
readonly internalType: "string";
|
|
59
|
+
readonly name: "symbol";
|
|
60
|
+
readonly type: "string";
|
|
61
|
+
}, {
|
|
62
|
+
readonly internalType: "string";
|
|
63
|
+
readonly name: "underlyingSymbol";
|
|
64
|
+
readonly type: "string";
|
|
65
|
+
}];
|
|
66
|
+
readonly internalType: "struct MarketState.MarketsInfo[]";
|
|
67
|
+
readonly name: "";
|
|
68
|
+
readonly type: "tuple[]";
|
|
69
|
+
}];
|
|
70
|
+
readonly stateMutability: "view";
|
|
71
|
+
readonly type: "function";
|
|
72
|
+
}];
|
|
73
|
+
//# sourceMappingURL=TakaraMarketState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TakaraMarketState.d.ts","sourceRoot":"","sources":["../../../src/abis/compound-v2/TakaraMarketState.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2DvB,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,16 +2,18 @@ export { getLenderPublicData, getLenderPublicDataViaApi, getLenderPublicDataAll,
|
|
|
2
2
|
export { type LendingPair, generateLendingPairs, getTopPairs, } from './lending-pairs';
|
|
3
3
|
export { type PoolWithMeta, generateLendingPools, unflattenLenderData, } from './lending-pools';
|
|
4
4
|
export { fetchGeneralYields } from './yields';
|
|
5
|
-
export { fetchDefillamaData, fetchDefillamaHistData, fetchMainPrices, fetchPendlePrices, fetchOraclePrices,
|
|
5
|
+
export { fetchDefillamaData, fetchDefillamaHistData, fetchMainPrices, fetchPendlePrices, fetchOraclePrices, selectAssetGroupPrices, type TokenListInput, type FetchOraclePricesOptions, type OraclePriceEntry, type StructuredOraclePrices, type USDPriceMap, type MorphoMarketOverrides, type ListaMarketOverrides, } from './prices';
|
|
6
6
|
export { getLendersForChain, filterLendersByProtocol, getAavesForChain, getLenderAssets, isCompoundV3, isCompoundV3Type, isInit, isMorphoType, isAaveV3Type, isAaveV2Type, isYLDR, isAaveV32Type, isAaveType, isMultiMarket, createMarketUid, } from './utils';
|
|
7
7
|
export { fetchFlashLiquidityForChain, attachPricesToFlashLiquidity, } from './flash-liquidity';
|
|
8
8
|
export { type GenericCurrency, type GenericTokenList, type ParsedResponse, type ChainLinkResponse, type LenderRewardsMap, type NumberMap, type FullLenderRewardsMap, type AdditionalYields, type TokenList, type LenderUserQuery, type UserLendingPosition, type LenderUserResponse, type AaveV2UserReserveResponse, type AaveV3UserReserveResponse, type MorphoUserReserveResponse, type CompoundV3UserReserveResponse, type AaveV3Public, type LenderPublicBase, type LenderYields, type LenderTotalAmounts, type LenderConfigMap, type LenderConfigData, type ModeBase, type EModeData, type AaveV2Public, type CompoundV3Public, type UserApr, type InitUserReserveResponse, type InitPublic, type LenderData, type PoolData, type ConfigEntry, } from './types';
|
|
9
9
|
export { computeDepositDelta, computeWithdrawDelta, computeBorrowDelta, computeRepayDelta, getHealthFactor, getBorrowCapacity, getAssetConfig, computePostTradeMetrics, EMPTY_BALANCE, } from './lending/margin/base';
|
|
10
10
|
export type { PostTradeMetrics } from './lending/margin/base';
|
|
11
11
|
export { computeOpenTradeDeltas, computeCloseTradeDeltas, computeCollateralSwapDeltas, computeDebtSwapDeltas, computeZapTradeDeltas, positivePart, nanTo, keysFromMaps, noOpResult, buildLoopResult, } from './lending/margin/loop';
|
|
12
|
-
export
|
|
12
|
+
export { computeEModeAnalysis } from './lending/margin/e-mode';
|
|
13
|
+
export type { EModeResult, EModeAssets } from './lending/margin/e-mode';
|
|
14
|
+
export type { LoopPostTradeMetrics, LendingMode } from './lending/margin/loop';
|
|
13
15
|
export { computeSumerDepositDelta, computeSumerWithdrawDelta, computeSumerBorrowDelta, computeSumerRepayDelta, computeSumerWaterfall, buildSumerAccumulators, applyPositionDelta, } from './lending/margin/sumer';
|
|
14
|
-
export type { SumerPositionInput, GroupAccumulator } from './lending/margin/sumer';
|
|
16
|
+
export type { SumerPositionInput, GroupAccumulator, } from './lending/margin/sumer';
|
|
15
17
|
export { MorphoLensAbi } from '@1delta/abis';
|
|
16
18
|
export { type PreparedCall, type RawRpcCall, type RawRpcBatch, type MulticallRpcBatch, createRawRpcCalls, createMulticallRpcCall, multicall3Abi, } from './utils/rpcCall';
|
|
17
19
|
export { type RawRpcResponse, parseRawRpcResponses, parseRawRpcBatchResponses, parseMulticallRpcResponses, } from './utils/rpcParse';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EACzB,sBAAsB,EACtB,uBAAuB,EACvB,2BAA2B,EAC3B,6BAA6B,EAC7B,KAAK,wBAAwB,EAC7B,sBAAsB,EACtB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,WAAW,EACX,6BAA6B,EAC7B,4BAA4B,EAC5B,mBAAmB,EACnB,+BAA+B,EAC/B,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,4BAA4B,EAE5B,cAAc,EACd,oBAAoB,EACpB,cAAc,EACd,mBAAmB,EAEnB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EAEnB,wBAAwB,EACxB,eAAe,EACf,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,WAAW,CAAA;AAClB,OAAO,EACL,KAAK,WAAW,EAChB,oBAAoB,EACpB,WAAW,GACZ,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,KAAK,YAAY,EACjB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
|
package/dist/index.js
CHANGED
|
@@ -6361,7 +6361,8 @@ var ENABLED_COMPOUNDS = [
|
|
|
6361
6361
|
Lender.MOONWELL,
|
|
6362
6362
|
Lender.ENCLABS,
|
|
6363
6363
|
Lender.ENCLABS_LST,
|
|
6364
|
-
Lender.SUMER
|
|
6364
|
+
Lender.SUMER,
|
|
6365
|
+
Lender.TAKARA
|
|
6365
6366
|
];
|
|
6366
6367
|
var getLendersForChain = (c) => {
|
|
6367
6368
|
let lenders = [];
|
|
@@ -10973,7 +10974,7 @@ function createBaseTypeUserState(payload, lenderData, totalDeposits24h = 0, tota
|
|
|
10973
10974
|
chainId,
|
|
10974
10975
|
data: [
|
|
10975
10976
|
{
|
|
10976
|
-
health: balanceData2.debt === 0 ? null : balanceData2.adjustedDebt > 0 ? balanceData2.
|
|
10977
|
+
health: balanceData2.debt === 0 ? null : balanceData2.adjustedDebt > 0 ? balanceData2.collateral / balanceData2.adjustedDebt : balanceData2.collateral / balanceData2.debt,
|
|
10977
10978
|
borrowCapacityUSD: creditLine,
|
|
10978
10979
|
accountId: "0",
|
|
10979
10980
|
balanceData: balanceData2,
|
|
@@ -12418,7 +12419,7 @@ var VENUS_LENS = {
|
|
|
12418
12419
|
};
|
|
12419
12420
|
var SUMER_LENS = {
|
|
12420
12421
|
[Chain.BNB_SMART_CHAIN_MAINNET]: "0xB7ea94340e65CC68d1274aE483dfBE593fD6f21e",
|
|
12421
|
-
|
|
12422
|
+
[Chain.ETHEREUM_MAINNET]: "0x3375B2EF9C4D2c6434d39BBE5234c5101218500d",
|
|
12422
12423
|
[Chain.ARBITRUM_ONE]: "0xbdBCf25E9187350b9102E316b707B1B2c7E51492",
|
|
12423
12424
|
[Chain.BASE]: "0x2B43fBb7D1171bCfA31c9685f24A417dC8757064",
|
|
12424
12425
|
[Chain.BERACHAIN]: "0x85D682FA4115f6a1Ed91170E705A50D532e3B6BD",
|
|
@@ -12434,13 +12435,17 @@ var ENCLABS_LENS = {
|
|
|
12434
12435
|
[Chain.SONIC_MAINNET]: "0x3567B16050cB90236997eF47B1941502e85d65f3",
|
|
12435
12436
|
[Chain.PLASMA_MAINNET]: "0xE67B5097b8dC55aCECaB82102A3042078f016550"
|
|
12436
12437
|
};
|
|
12438
|
+
var TAKARA_LENS = {
|
|
12439
|
+
[Chain.SEI_NETWORK]: "0xCe434378adacC51d54312c872113D687Ac19B516"
|
|
12440
|
+
};
|
|
12437
12441
|
var COMPOUND_V2_LENS = {
|
|
12438
12442
|
[Lender.VENUS]: VENUS_LENS,
|
|
12439
12443
|
[Lender.VENUS_ETH]: VENUS_LENS,
|
|
12440
12444
|
[Lender.MOONWELL]: MOONWELL_LENS,
|
|
12441
12445
|
[Lender.ENCLABS]: ENCLABS_LENS,
|
|
12442
12446
|
[Lender.ENCLABS_LST]: ENCLABS_LENS,
|
|
12443
|
-
[Lender.SUMER]: SUMER_LENS
|
|
12447
|
+
[Lender.SUMER]: SUMER_LENS,
|
|
12448
|
+
[Lender.TAKARA]: TAKARA_LENS
|
|
12444
12449
|
};
|
|
12445
12450
|
function getCompoundV2Comptroller(chainId, lender = Lender.VENUS) {
|
|
12446
12451
|
return compoundV2Pools()?.[lender]?.[chainId];
|
|
@@ -12963,8 +12968,81 @@ function normalizeSumerGroups(parsed) {
|
|
|
12963
12968
|
}));
|
|
12964
12969
|
}
|
|
12965
12970
|
|
|
12971
|
+
// src/abis/compound-v2/TakaraMarketState.ts
|
|
12972
|
+
var TakaraMarketStateAbi = [
|
|
12973
|
+
{
|
|
12974
|
+
inputs: [],
|
|
12975
|
+
name: "getActiveMarketsInfo",
|
|
12976
|
+
outputs: [
|
|
12977
|
+
{
|
|
12978
|
+
components: [
|
|
12979
|
+
{ internalType: "uint256", name: "tvl", type: "uint256" },
|
|
12980
|
+
{ internalType: "uint256", name: "ltv", type: "uint256" },
|
|
12981
|
+
{
|
|
12982
|
+
internalType: "uint256",
|
|
12983
|
+
name: "exchangeRateCurrent",
|
|
12984
|
+
type: "uint256"
|
|
12985
|
+
},
|
|
12986
|
+
{
|
|
12987
|
+
internalType: "uint256",
|
|
12988
|
+
name: "reserveFactorMantissa",
|
|
12989
|
+
type: "uint256"
|
|
12990
|
+
},
|
|
12991
|
+
{ internalType: "uint256", name: "totalSupply", type: "uint256" },
|
|
12992
|
+
{ internalType: "bool", name: "isListed", type: "bool" },
|
|
12993
|
+
{ internalType: "uint256", name: "totalBorrows", type: "uint256" },
|
|
12994
|
+
{
|
|
12995
|
+
internalType: "uint256",
|
|
12996
|
+
name: "supplyRatePerBlock",
|
|
12997
|
+
type: "uint256"
|
|
12998
|
+
},
|
|
12999
|
+
{
|
|
13000
|
+
internalType: "uint256",
|
|
13001
|
+
name: "borrowRatePerBlock",
|
|
13002
|
+
type: "uint256"
|
|
13003
|
+
},
|
|
13004
|
+
{
|
|
13005
|
+
internalType: "uint256",
|
|
13006
|
+
name: "blocksPerYear",
|
|
13007
|
+
type: "uint256"
|
|
13008
|
+
},
|
|
13009
|
+
{
|
|
13010
|
+
internalType: "uint256",
|
|
13011
|
+
name: "timestampsPerYear",
|
|
13012
|
+
type: "uint256"
|
|
13013
|
+
},
|
|
13014
|
+
{ internalType: "address", name: "token", type: "address" },
|
|
13015
|
+
{ internalType: "address", name: "underlying", type: "address" },
|
|
13016
|
+
{ internalType: "string", name: "symbol", type: "string" },
|
|
13017
|
+
{
|
|
13018
|
+
internalType: "string",
|
|
13019
|
+
name: "underlyingSymbol",
|
|
13020
|
+
type: "string"
|
|
13021
|
+
}
|
|
13022
|
+
],
|
|
13023
|
+
internalType: "struct MarketState.MarketsInfo[]",
|
|
13024
|
+
name: "",
|
|
13025
|
+
type: "tuple[]"
|
|
13026
|
+
}
|
|
13027
|
+
],
|
|
13028
|
+
stateMutability: "view",
|
|
13029
|
+
type: "function"
|
|
13030
|
+
}
|
|
13031
|
+
];
|
|
13032
|
+
|
|
12966
13033
|
// src/lending/public-data/compound-v2/publicCallBuild.ts
|
|
12967
13034
|
var buildCompoundV2StyleLenderReserveCall = (chainId, lender) => {
|
|
13035
|
+
if (lender === Lender.TAKARA) {
|
|
13036
|
+
const lens = getCompoundV2Lens(chainId, lender);
|
|
13037
|
+
return [
|
|
13038
|
+
{
|
|
13039
|
+
abi: TakaraMarketStateAbi,
|
|
13040
|
+
address: lens,
|
|
13041
|
+
name: "getActiveMarketsInfo",
|
|
13042
|
+
params: []
|
|
13043
|
+
}
|
|
13044
|
+
];
|
|
13045
|
+
}
|
|
12968
13046
|
const tokens = getCompoundV2Tokens(chainId, lender);
|
|
12969
13047
|
const getCTokenCall = getCall(lender, chainId);
|
|
12970
13048
|
const calls = tokens.map((tk) => getCTokenCall(tk.cToken));
|
|
@@ -13175,9 +13253,70 @@ function parseMoonwellMarket(input, token) {
|
|
|
13175
13253
|
};
|
|
13176
13254
|
}
|
|
13177
13255
|
|
|
13178
|
-
// src/lending/public-data/compound-v2/
|
|
13256
|
+
// src/lending/public-data/compound-v2/getters/takara.ts
|
|
13257
|
+
function toBigInt2(value) {
|
|
13258
|
+
if (typeof value === "bigint") return value;
|
|
13259
|
+
if (typeof value === "number") return BigInt(value);
|
|
13260
|
+
if (typeof value === "string") return BigInt(value);
|
|
13261
|
+
if (value && typeof value === "object") {
|
|
13262
|
+
const v = value;
|
|
13263
|
+
if (typeof v._hex === "string") return BigInt(v._hex);
|
|
13264
|
+
if (typeof v.toString === "function") return BigInt(v.toString());
|
|
13265
|
+
}
|
|
13266
|
+
throw new Error(`Cannot convert value to bigint: ${String(value)}`);
|
|
13267
|
+
}
|
|
13268
|
+
function field2(src, key, index) {
|
|
13269
|
+
if (src == null) throw new Error("Source is null/undefined");
|
|
13270
|
+
if (key in src) return src[key];
|
|
13271
|
+
if (Array.isArray(src)) return src[index];
|
|
13272
|
+
return src[key];
|
|
13273
|
+
}
|
|
13274
|
+
function computeApy(rateRaw, timestampsPerYear) {
|
|
13275
|
+
const rate = Number(formatEther(rateRaw));
|
|
13276
|
+
const tpy = Number(timestampsPerYear);
|
|
13277
|
+
if (tpy === 0 || rate === 0) return 0;
|
|
13278
|
+
const dailyRate = rate * tpy / 365;
|
|
13279
|
+
return (Math.pow(dailyRate + 1, 365) - 1) * 100;
|
|
13280
|
+
}
|
|
13281
|
+
function toBool2(value) {
|
|
13282
|
+
if (typeof value === "boolean") return value;
|
|
13283
|
+
if (typeof value === "bigint") return value !== 0n;
|
|
13284
|
+
if (typeof value === "number") return value !== 0;
|
|
13285
|
+
return Boolean(value);
|
|
13286
|
+
}
|
|
13287
|
+
function parseTakaraMarketsInfo(input) {
|
|
13288
|
+
return {
|
|
13289
|
+
tvl: toBigInt2(field2(input, "tvl", 0)),
|
|
13290
|
+
ltv: toBigInt2(field2(input, "ltv", 1)),
|
|
13291
|
+
exchangeRateCurrent: toBigInt2(field2(input, "exchangeRateCurrent", 2)),
|
|
13292
|
+
reserveFactorMantissa: toBigInt2(field2(input, "reserveFactorMantissa", 3)),
|
|
13293
|
+
totalSupply: toBigInt2(field2(input, "totalSupply", 4)),
|
|
13294
|
+
isListed: toBool2(field2(input, "isListed", 5)),
|
|
13295
|
+
totalBorrows: toBigInt2(field2(input, "totalBorrows", 6)),
|
|
13296
|
+
supplyRatePerBlock: toBigInt2(field2(input, "supplyRatePerBlock", 7)),
|
|
13297
|
+
borrowRatePerBlock: toBigInt2(field2(input, "borrowRatePerBlock", 8)),
|
|
13298
|
+
blocksPerYear: toBigInt2(field2(input, "blocksPerYear", 9)),
|
|
13299
|
+
timestampsPerYear: toBigInt2(field2(input, "timestampsPerYear", 10)),
|
|
13300
|
+
token: String(field2(input, "token", 11)),
|
|
13301
|
+
underlying: String(field2(input, "underlying", 12)),
|
|
13302
|
+
symbol: String(field2(input, "symbol", 13)),
|
|
13303
|
+
underlyingSymbol: String(field2(input, "underlyingSymbol", 14))
|
|
13304
|
+
};
|
|
13305
|
+
}
|
|
13306
|
+
function getTakaraRates(info) {
|
|
13307
|
+
const supplyApy = computeApy(info.supplyRatePerBlock, info.timestampsPerYear);
|
|
13308
|
+
const borrowApy = computeApy(info.borrowRatePerBlock, info.timestampsPerYear);
|
|
13309
|
+
return {
|
|
13310
|
+
depositRate: apyToApr(supplyApy / 100) * 100,
|
|
13311
|
+
variableBorrowRate: apyToApr(borrowApy / 100) * 100
|
|
13312
|
+
};
|
|
13313
|
+
}
|
|
13314
|
+
|
|
13315
|
+
// src/lending/public-data/compound-v2/convert/types.ts
|
|
13179
13316
|
var PRICE_DECIMALS = 18;
|
|
13180
13317
|
var RESERVE_MANTISSA_DECIMALS = 18;
|
|
13318
|
+
|
|
13319
|
+
// src/lending/public-data/compound-v2/convert/standard.ts
|
|
13181
13320
|
function convertSingleEntry(opts) {
|
|
13182
13321
|
const {
|
|
13183
13322
|
entryRaw,
|
|
@@ -13242,16 +13381,11 @@ function convertSingleEntry(opts) {
|
|
|
13242
13381
|
},
|
|
13243
13382
|
hasStable: false,
|
|
13244
13383
|
underlying: asset.address,
|
|
13245
|
-
// rewards placeholder (kept as-is / commented in original)
|
|
13246
|
-
// compSupplySpeed: parseRawAmount(currentEntry?.venusSupplySpeed?.toString(), 5),
|
|
13247
|
-
// compBorrowSpeed: parseRawAmount(currentEntry?.venusBorrowSpeed?.toString(), 5),
|
|
13248
13384
|
isActive: Boolean(currentEntry?.isListed) && !allPaused,
|
|
13249
13385
|
isFrozen: pausedActions[0 /* MINT */] && pausedActions[2 /* BORROW */],
|
|
13250
13386
|
rewards: {},
|
|
13251
13387
|
collateralActive,
|
|
13252
13388
|
borrowingEnabled,
|
|
13253
|
-
// borrowCap example left commented as in original:
|
|
13254
|
-
// borrowCap: parseRawAmount(currentEntry?.borrowCap?.toString(), decs),
|
|
13255
13389
|
params: {
|
|
13256
13390
|
metadata: {
|
|
13257
13391
|
cToken,
|
|
@@ -13261,6 +13395,8 @@ function convertSingleEntry(opts) {
|
|
|
13261
13395
|
}
|
|
13262
13396
|
};
|
|
13263
13397
|
}
|
|
13398
|
+
|
|
13399
|
+
// src/lending/public-data/compound-v2/convert/sumer.ts
|
|
13264
13400
|
function convertSumerEntry(opts) {
|
|
13265
13401
|
const {
|
|
13266
13402
|
entryRaw,
|
|
@@ -13352,7 +13488,103 @@ function convertSumerEntry(opts) {
|
|
|
13352
13488
|
}
|
|
13353
13489
|
};
|
|
13354
13490
|
}
|
|
13491
|
+
|
|
13492
|
+
// src/lending/public-data/compound-v2/convert/takara.ts
|
|
13493
|
+
function convertTakaraEntry(opts) {
|
|
13494
|
+
const { entryRaw, asset, chainId, lender, prices, additionalYields, cToken } = opts;
|
|
13495
|
+
const info = parseTakaraMarketsInfo(entryRaw);
|
|
13496
|
+
const rates = getTakaraRates(info);
|
|
13497
|
+
const price = prices[asset.assetGroup] ?? 0;
|
|
13498
|
+
const collateralFactor = Number(
|
|
13499
|
+
parseRawAmount(info.ltv.toString(), RESERVE_MANTISSA_DECIMALS)
|
|
13500
|
+
);
|
|
13501
|
+
const totalSupplyUSD = Number(
|
|
13502
|
+
parseRawAmount(info.totalSupply.toString(), PRICE_DECIMALS)
|
|
13503
|
+
);
|
|
13504
|
+
const totalDebtUSD = Number(
|
|
13505
|
+
parseRawAmount(info.totalBorrows.toString(), PRICE_DECIMALS)
|
|
13506
|
+
);
|
|
13507
|
+
const liquidityUSD = Number(
|
|
13508
|
+
parseRawAmount(info.tvl.toString(), PRICE_DECIMALS)
|
|
13509
|
+
);
|
|
13510
|
+
const totalDeposits = price > 0 ? totalSupplyUSD / price : 0;
|
|
13511
|
+
const totalDebt = price > 0 ? totalDebtUSD / price : 0;
|
|
13512
|
+
const liquidity = price > 0 ? liquidityUSD / price : 0;
|
|
13513
|
+
const poolId = asset.address;
|
|
13514
|
+
const marketUid = createMarketUid(chainId, lender, cToken);
|
|
13515
|
+
return {
|
|
13516
|
+
marketUid,
|
|
13517
|
+
poolId,
|
|
13518
|
+
asset,
|
|
13519
|
+
depositRate: rates.depositRate,
|
|
13520
|
+
variableBorrowRate: rates.variableBorrowRate,
|
|
13521
|
+
stableBorrowRate: 0,
|
|
13522
|
+
totalLiquidity: liquidity,
|
|
13523
|
+
totalLiquidityUSD: liquidityUSD,
|
|
13524
|
+
totalDebt,
|
|
13525
|
+
totalDebtUSD,
|
|
13526
|
+
totalDeposits,
|
|
13527
|
+
totalDepositsUSD: totalSupplyUSD,
|
|
13528
|
+
totalDebtStable: 0,
|
|
13529
|
+
totalDebtStableUSD: 0,
|
|
13530
|
+
intrinsicYield: additionalYields.intrinsicYields[asset.assetGroup] ?? 0,
|
|
13531
|
+
config: {
|
|
13532
|
+
[LENDER_MODE_NO_MODE]: {
|
|
13533
|
+
category: LENDER_MODE_NO_MODE,
|
|
13534
|
+
borrowCollateralFactor: collateralFactor,
|
|
13535
|
+
collateralFactor,
|
|
13536
|
+
borrowFactor: 1,
|
|
13537
|
+
collateralDisabled: false,
|
|
13538
|
+
debtDisabled: false
|
|
13539
|
+
}
|
|
13540
|
+
},
|
|
13541
|
+
hasStable: false,
|
|
13542
|
+
underlying: asset.address,
|
|
13543
|
+
isActive: info.isListed,
|
|
13544
|
+
isFrozen: false,
|
|
13545
|
+
rewards: {},
|
|
13546
|
+
collateralActive: info.isListed,
|
|
13547
|
+
borrowingEnabled: info.isListed,
|
|
13548
|
+
params: {
|
|
13549
|
+
metadata: {
|
|
13550
|
+
cToken,
|
|
13551
|
+
exchangeRate: info.exchangeRateCurrent.toString(),
|
|
13552
|
+
cTokenDecimals: 8
|
|
13553
|
+
}
|
|
13554
|
+
}
|
|
13555
|
+
};
|
|
13556
|
+
}
|
|
13557
|
+
|
|
13558
|
+
// src/lending/public-data/compound-v2/publicCallParse.ts
|
|
13355
13559
|
var getCompoundV2DataConverter = (lender, chainId, prices, additionalYields, tokenList = {}) => {
|
|
13560
|
+
if (lender === Lender.TAKARA) {
|
|
13561
|
+
return [
|
|
13562
|
+
(data) => {
|
|
13563
|
+
if (data.length !== 1) return void 0;
|
|
13564
|
+
const marketsArray = data[0];
|
|
13565
|
+
const out = { data: {}, chainId };
|
|
13566
|
+
for (const entryRaw of marketsArray) {
|
|
13567
|
+
const info = parseTakaraMarketsInfo(entryRaw);
|
|
13568
|
+
const underlying = info.underlying.toLowerCase();
|
|
13569
|
+
const asset = tokenList[underlying];
|
|
13570
|
+
if (!asset) continue;
|
|
13571
|
+
const poolId = underlying;
|
|
13572
|
+
out.data[poolId] = convertTakaraEntry({
|
|
13573
|
+
entryRaw,
|
|
13574
|
+
asset,
|
|
13575
|
+
chainId,
|
|
13576
|
+
lender,
|
|
13577
|
+
prices,
|
|
13578
|
+
additionalYields,
|
|
13579
|
+
cToken: info.token
|
|
13580
|
+
});
|
|
13581
|
+
}
|
|
13582
|
+
return out;
|
|
13583
|
+
},
|
|
13584
|
+
1
|
|
13585
|
+
// single call
|
|
13586
|
+
];
|
|
13587
|
+
}
|
|
13356
13588
|
const compoundV2Tokens2 = getCompoundV2Tokens(chainId, lender);
|
|
13357
13589
|
const tokenCount = compoundV2Tokens2.length;
|
|
13358
13590
|
const isSumer = isSumerType(lender);
|
|
@@ -14336,6 +14568,7 @@ var getAbi = (lender) => {
|
|
|
14336
14568
|
if (isInit(lender)) return InitLensAbi;
|
|
14337
14569
|
if (isMorphoType(lender)) return MorphoLensAbi;
|
|
14338
14570
|
if (isSumerType(lender)) return [...SumerLensAbi, ...SumerComptrollerAbi];
|
|
14571
|
+
if (lender === Lender.TAKARA) return [...TakaraMarketStateAbi];
|
|
14339
14572
|
if (isCompoundV2Type(lender)) return VenusLensAbi;
|
|
14340
14573
|
return [];
|
|
14341
14574
|
};
|
|
@@ -26139,18 +26372,80 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
26139
26372
|
}
|
|
26140
26373
|
return result;
|
|
26141
26374
|
}
|
|
26142
|
-
|
|
26143
|
-
|
|
26375
|
+
var DEFAULT_PRIORITY = {
|
|
26376
|
+
chainPriority: [
|
|
26377
|
+
Chain.ETHEREUM_MAINNET,
|
|
26378
|
+
Chain.BNB_SMART_CHAIN_MAINNET,
|
|
26379
|
+
Chain.ARBITRUM_ONE,
|
|
26380
|
+
Chain.BASE,
|
|
26381
|
+
Chain.AVALANCHE_C_CHAIN
|
|
26382
|
+
],
|
|
26383
|
+
lenderPriority: [Lender.AAVE_V3, "COMPOUND_V3"],
|
|
26384
|
+
lowPriorityLenders: [Lender.ZEROLEND, Lender.AVALON, Lender.MORPHO_BLUE],
|
|
26385
|
+
excludedLenders: {
|
|
26386
|
+
// paused
|
|
26387
|
+
"8217": ["KLAP"],
|
|
26388
|
+
// shutdown
|
|
26389
|
+
"100": ["AGAVE"],
|
|
26390
|
+
// invalid values
|
|
26391
|
+
"1": [Lender.ZEROLEND_STABLECOINS_RWA, Lender.ZEROLEND_ETH_LRTS],
|
|
26392
|
+
"534352": ["LORE"],
|
|
26393
|
+
"167000": [Lender.TAKOTAKO, Lender.TAKOTAKO_ETH],
|
|
26394
|
+
"56": [Lender.AVALON_USDX],
|
|
26395
|
+
// broken
|
|
26396
|
+
"169": [Lender.ZEROLEND]
|
|
26397
|
+
},
|
|
26398
|
+
lenderPriorityPerChain: {
|
|
26399
|
+
[Chain.BNB_SMART_CHAIN_MAINNET]: [Lender.AAVE_V3, Lender.VENUS],
|
|
26400
|
+
[Chain.XDC_NETWORK]: [Lender.PRIME_FI, Lender.FATHOM],
|
|
26401
|
+
[Chain.HYPEREVM]: [Lender.HYPERLEND, Lender.HYPURRFI]
|
|
26402
|
+
},
|
|
26403
|
+
lowPriorityLendersPerChain: {},
|
|
26404
|
+
excludedLendersPerChain: {}
|
|
26405
|
+
};
|
|
26406
|
+
function computePriority(lender, chainId, cfg) {
|
|
26407
|
+
const NOT_FOUND = 1e3;
|
|
26408
|
+
const excluded = cfg.excludedLenders[chainId];
|
|
26409
|
+
if (excluded?.some((p) => lender.startsWith(p))) return -1;
|
|
26410
|
+
const excludedPerChain = cfg.excludedLendersPerChain[chainId];
|
|
26411
|
+
if (excludedPerChain?.some((p) => lender.startsWith(p))) return -1;
|
|
26412
|
+
const lowPerChain = cfg.lowPriorityLendersPerChain[chainId];
|
|
26413
|
+
const isLow = lowPerChain ? lowPerChain.some((p) => lender.startsWith(p)) : cfg.lowPriorityLenders.some((p) => lender.startsWith(p));
|
|
26414
|
+
if (isLow) return 2e6;
|
|
26415
|
+
const lenderPriority = cfg.lenderPriorityPerChain[chainId] ?? cfg.lenderPriority;
|
|
26416
|
+
const lenderIdx = lenderPriority.findIndex((p) => lender.startsWith(p));
|
|
26417
|
+
const lenderScore = lenderIdx >= 0 ? lenderIdx : NOT_FOUND;
|
|
26418
|
+
const chainIdx = cfg.chainPriority.indexOf(chainId);
|
|
26419
|
+
const chainScore = chainIdx >= 0 ? chainIdx : NOT_FOUND;
|
|
26420
|
+
return lenderScore * 1e4 + chainScore;
|
|
26421
|
+
}
|
|
26422
|
+
function selectAssetGroupPrices(structuredPrices, lists = {}, tvlMap = {}, priorityCfg = DEFAULT_PRIORITY) {
|
|
26423
|
+
const candidates = [];
|
|
26144
26424
|
for (const [chainId, lenders] of Object.entries(structuredPrices)) {
|
|
26145
26425
|
const tokenList = lists[chainId] ?? {};
|
|
26146
|
-
for (const [
|
|
26426
|
+
for (const [lender, entries] of Object.entries(lenders)) {
|
|
26427
|
+
const prio = computePriority(lender, chainId, priorityCfg);
|
|
26428
|
+
if (prio < 0) continue;
|
|
26429
|
+
const tvl = tvlMap[lender] ?? 0;
|
|
26147
26430
|
for (const entry of entries) {
|
|
26148
|
-
|
|
26149
|
-
|
|
26150
|
-
|
|
26431
|
+
if (entry.priceUSD <= 0) continue;
|
|
26432
|
+
const oracleKey = tokenList[entry.asset]?.assetGroup ?? `${chainId}-${entry.asset.toLowerCase()}`;
|
|
26433
|
+
candidates.push({
|
|
26434
|
+
oracleKey,
|
|
26435
|
+
priceUSD: entry.priceUSD,
|
|
26436
|
+
priority: prio,
|
|
26437
|
+
tvl
|
|
26438
|
+
});
|
|
26151
26439
|
}
|
|
26152
26440
|
}
|
|
26153
26441
|
}
|
|
26442
|
+
candidates.sort((a, b) => a.priority - b.priority || b.tvl - a.tvl);
|
|
26443
|
+
const flatPrices = {};
|
|
26444
|
+
for (const c of candidates) {
|
|
26445
|
+
if (!(c.oracleKey in flatPrices)) {
|
|
26446
|
+
flatPrices[c.oracleKey] = c.priceUSD;
|
|
26447
|
+
}
|
|
26448
|
+
}
|
|
26154
26449
|
return flatPrices;
|
|
26155
26450
|
}
|
|
26156
26451
|
var { uniq: uniq2 } = lodash;
|
|
@@ -26186,10 +26481,10 @@ function createAssetArrayPerChain() {
|
|
|
26186
26481
|
return assetsPerChain;
|
|
26187
26482
|
}
|
|
26188
26483
|
var RELEVANT_LENDING_ASSETS = () => createAssetArrayPerChain();
|
|
26189
|
-
function createSimpleArrayPerChain(fork,
|
|
26484
|
+
function createSimpleArrayPerChain(fork, field3 = void 0) {
|
|
26190
26485
|
let pools = {};
|
|
26191
26486
|
Object.entries(fork ?? {}).forEach(([b2, data]) => {
|
|
26192
|
-
Object.entries(
|
|
26487
|
+
Object.entries(field3 ? data[field3] : data).forEach(
|
|
26193
26488
|
([chainId, address]) => {
|
|
26194
26489
|
if (!pools[chainId]) pools[chainId] = [];
|
|
26195
26490
|
pools[chainId] = uniq2([...pools[chainId], { address, pool: b2 }]);
|
|
@@ -26545,6 +26840,84 @@ function attachPricesToFlashLiquidity(chainId, liq, prices, list = {}) {
|
|
|
26545
26840
|
return liqCopy;
|
|
26546
26841
|
}
|
|
26547
26842
|
|
|
26843
|
+
// src/lending/margin/e-mode/index.ts
|
|
26844
|
+
function computeEModeSwitchHealth(positions, lenderMeta, currentCollateral, currentAdjustedDebt, currentMode, targetMode) {
|
|
26845
|
+
if (currentAdjustedDebt === 0) return null;
|
|
26846
|
+
if (targetMode === currentMode) return currentCollateral / currentAdjustedDebt;
|
|
26847
|
+
let collateralNew = currentCollateral;
|
|
26848
|
+
let debtNew = currentAdjustedDebt;
|
|
26849
|
+
for (let i = 0; i < positions.length; i++) {
|
|
26850
|
+
const pos = positions[i];
|
|
26851
|
+
const meta = lenderMeta[pos.marketUid];
|
|
26852
|
+
if (!meta?.configs) continue;
|
|
26853
|
+
const configs = meta.configs;
|
|
26854
|
+
if (pos.depositsUSD > 0) {
|
|
26855
|
+
const oldFactor = configs[currentMode]?.collateralFactor ?? 0;
|
|
26856
|
+
const newFactor = configs[targetMode]?.collateralFactor ?? 0;
|
|
26857
|
+
collateralNew += pos.depositsUSD * (newFactor - oldFactor);
|
|
26858
|
+
}
|
|
26859
|
+
const totalDebtUSD = pos.debtUSD + pos.debtStableUSD;
|
|
26860
|
+
if (totalDebtUSD > 0) {
|
|
26861
|
+
const hasTargetConfig = Boolean(configs[targetMode]);
|
|
26862
|
+
const oldFactor = configs[currentMode]?.borrowFactor ?? 1;
|
|
26863
|
+
const newFactor = hasTargetConfig ? configs[targetMode]?.borrowFactor ?? 1 : 1e10;
|
|
26864
|
+
debtNew += totalDebtUSD * (newFactor - oldFactor);
|
|
26865
|
+
}
|
|
26866
|
+
}
|
|
26867
|
+
const hf = collateralNew / debtNew;
|
|
26868
|
+
return hf > 0 ? hf : 0;
|
|
26869
|
+
}
|
|
26870
|
+
function getSupportedAssets(lenderMeta, targetMode) {
|
|
26871
|
+
const collateral = [];
|
|
26872
|
+
const borrow = [];
|
|
26873
|
+
for (const [marketUid, meta] of Object.entries(lenderMeta)) {
|
|
26874
|
+
const config = meta.configs?.[targetMode];
|
|
26875
|
+
if (!config) continue;
|
|
26876
|
+
if (!config.collateralDisabled) collateral.push(marketUid);
|
|
26877
|
+
if (!config.debtDisabled) borrow.push(marketUid);
|
|
26878
|
+
}
|
|
26879
|
+
return { collateral, borrow };
|
|
26880
|
+
}
|
|
26881
|
+
function canSwitchToEMode(positions, lenderMeta, targetMode, healthFactor) {
|
|
26882
|
+
if (healthFactor !== null && healthFactor <= 1) return false;
|
|
26883
|
+
for (let i = 0; i < positions.length; i++) {
|
|
26884
|
+
const pos = positions[i];
|
|
26885
|
+
const totalDebt = pos.debtUSD + pos.debtStableUSD;
|
|
26886
|
+
if (totalDebt <= 0) continue;
|
|
26887
|
+
const config = lenderMeta[pos.marketUid]?.configs?.[targetMode];
|
|
26888
|
+
if (!config || config.debtDisabled) return false;
|
|
26889
|
+
}
|
|
26890
|
+
return true;
|
|
26891
|
+
}
|
|
26892
|
+
function computeEModeAnalysis(subAccount, lenderMeta, eModes) {
|
|
26893
|
+
const { positions, balanceData: balanceData2, userConfig } = subAccount;
|
|
26894
|
+
const currentMode = userConfig.selectedMode;
|
|
26895
|
+
return Object.values(eModes).map((eMode) => {
|
|
26896
|
+
const healthFactor = computeEModeSwitchHealth(
|
|
26897
|
+
positions,
|
|
26898
|
+
lenderMeta,
|
|
26899
|
+
balanceData2.collateral,
|
|
26900
|
+
balanceData2.adjustedDebt,
|
|
26901
|
+
currentMode,
|
|
26902
|
+
eMode.category
|
|
26903
|
+
);
|
|
26904
|
+
const supportedAssets = getSupportedAssets(lenderMeta, eMode.category);
|
|
26905
|
+
const canSwitch = canSwitchToEMode(
|
|
26906
|
+
positions,
|
|
26907
|
+
lenderMeta,
|
|
26908
|
+
eMode.category,
|
|
26909
|
+
healthFactor
|
|
26910
|
+
);
|
|
26911
|
+
return {
|
|
26912
|
+
category: eMode.category,
|
|
26913
|
+
label: eMode.label,
|
|
26914
|
+
healthFactor,
|
|
26915
|
+
supportedAssets,
|
|
26916
|
+
canSwitch
|
|
26917
|
+
};
|
|
26918
|
+
});
|
|
26919
|
+
}
|
|
26920
|
+
|
|
26548
26921
|
// src/lending/margin/sumer/deposit.ts
|
|
26549
26922
|
function computeSumerDepositDelta(amount, price, targetMarketUid, balanceData2, positions, createNewSubAccount = false, apr, yieldParams) {
|
|
26550
26923
|
const base = createNewSubAccount ? EMPTY_BALANCE : balanceData2;
|
|
@@ -27182,6 +27555,6 @@ async function fetchTokenBalances(chainId, account, tokens, options = {}) {
|
|
|
27182
27555
|
return parseTokenBalanceResult(rawResult, prepared.query);
|
|
27183
27556
|
}
|
|
27184
27557
|
|
|
27185
|
-
export { EMPTY_BALANCE, MORPHO_LENS, applyPositionDelta, attachPricesToFlashLiquidity, buildLoopResult, buildMorphoTypeCall, buildMorphoTypeUserCallWithLens, buildPortfolioTotals, buildSumerAccumulators, buildSummaries, calculateLeverage, calculateNetApr, calculateOverallNetApr, calculateWeightedAverage, computeBorrowDelta, computeCloseTradeDeltas, computeCollateralSwapDeltas, computeDebtSwapDeltas, computeDepositDelta, computeOpenTradeDeltas, computePostTradeMetrics, computeRepayDelta, computeSumerBorrowDelta, computeSumerDepositDelta, computeSumerRepayDelta, computeSumerWaterfall, computeSumerWithdrawDelta, computeWithdrawDelta, computeZapTradeDeltas, convertLenderUserDataResult, createMarketUid, createMulticallRpcCall, createRawRpcCalls, decodeListaMarkets, decodeMarkets, decodePackedListaUserDataset, decodePackedMorphoUserDataset, encodeBalanceFetcherCalldata, fetchDefillamaData, fetchDefillamaHistData, fetchFlashLiquidityForChain, fetchGeneralYields, fetchMainPrices, fetchOraclePrices, fetchPendlePrices, fetchTokenBalances, fetchTokenMetadata, filterActiveLenders, filterLendersByProtocol,
|
|
27558
|
+
export { EMPTY_BALANCE, MORPHO_LENS, applyPositionDelta, attachPricesToFlashLiquidity, buildLoopResult, buildMorphoTypeCall, buildMorphoTypeUserCallWithLens, buildPortfolioTotals, buildSumerAccumulators, buildSummaries, calculateLeverage, calculateNetApr, calculateOverallNetApr, calculateWeightedAverage, computeBorrowDelta, computeCloseTradeDeltas, computeCollateralSwapDeltas, computeDebtSwapDeltas, computeDepositDelta, computeEModeAnalysis, computeOpenTradeDeltas, computePostTradeMetrics, computeRepayDelta, computeSumerBorrowDelta, computeSumerDepositDelta, computeSumerRepayDelta, computeSumerWaterfall, computeSumerWithdrawDelta, computeWithdrawDelta, computeZapTradeDeltas, convertLenderUserDataResult, createMarketUid, createMulticallRpcCall, createRawRpcCalls, decodeListaMarkets, decodeMarkets, decodePackedListaUserDataset, decodePackedMorphoUserDataset, encodeBalanceFetcherCalldata, fetchDefillamaData, fetchDefillamaHistData, fetchFlashLiquidityForChain, fetchGeneralYields, fetchMainPrices, fetchOraclePrices, fetchPendlePrices, fetchTokenBalances, fetchTokenMetadata, filterActiveLenders, filterLendersByProtocol, 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, selectAssetGroupPrices, unflattenLenderData };
|
|
27186
27559
|
//# sourceMappingURL=index.js.map
|
|
27187
27560
|
//# sourceMappingURL=index.js.map
|