@1delta/margin-fetcher 0.0.333 → 0.0.334
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/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +779 -51
- package/dist/index.js.map +1 -1
- package/dist/lending/public-data/fetchLenderAll.d.ts.map +1 -1
- package/dist/lending/public-data/fetchLenderExt.d.ts.map +1 -1
- package/dist/lending/public-data/teller/convertPublic.d.ts +32 -0
- package/dist/lending/public-data/teller/convertPublic.d.ts.map +1 -0
- package/dist/lending/public-data/teller/fetchPublic.d.ts +16 -0
- package/dist/lending/public-data/teller/fetchPublic.d.ts.map +1 -0
- package/dist/lending/public-data/teller/index.d.ts +5 -0
- package/dist/lending/public-data/teller/index.d.ts.map +1 -0
- package/dist/lending/public-data/teller/math.d.ts +18 -0
- package/dist/lending/public-data/teller/math.d.ts.map +1 -0
- package/dist/lending/public-data/teller/types.d.ts +33 -0
- package/dist/lending/public-data/teller/types.d.ts.map +1 -0
- package/dist/lending/user-data/abis.d.ts.map +1 -1
- package/dist/lending/user-data/fetch-balances/parse.d.ts.map +1 -1
- package/dist/lending/user-data/fetch-balances/prepare.d.ts.map +1 -1
- package/dist/lending/user-data/teller/index.d.ts +3 -0
- package/dist/lending/user-data/teller/index.d.ts.map +1 -0
- package/dist/lending/user-data/teller/userCallBuild.d.ts +31 -0
- package/dist/lending/user-data/teller/userCallBuild.d.ts.map +1 -0
- package/dist/lending/user-data/teller/userCallParse.d.ts +22 -0
- package/dist/lending/user-data/teller/userCallParse.d.ts.map +1 -0
- package/dist/prices/oracle-prices/fetchOraclePrices.d.ts +2 -2
- package/dist/prices/oracle-prices/fetchOraclePrices.d.ts.map +1 -1
- package/dist/prices/oracle-prices/fetchers/index.d.ts +1 -0
- package/dist/prices/oracle-prices/fetchers/index.d.ts.map +1 -1
- package/dist/prices/oracle-prices/fetchers/teller.d.ts +413 -0
- package/dist/prices/oracle-prices/fetchers/teller.d.ts.map +1 -0
- package/dist/types/lenderTypes.d.ts +1 -1
- package/dist/types/lenderTypes.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { parseAbi, keccak256, encodeAbiParameters, formatEther, BaseError, encodeFunctionData, formatUnits, isAddress, getAddress, decodeFunctionResult, decodeAbiParameters, AbiEncodingLengthMismatchError, concatHex, pad, InvalidAddressError, stringToHex, boolToHex, integerRegex, numberToHex, bytesRegex, BytesSizeMismatchError, arrayRegex, UnsupportedPackedAbiType } from './chunk-Z3MGRQJR.js';
|
|
2
2
|
import './chunk-BYTNVMX7.js';
|
|
3
3
|
import './chunk-PR4QN5HX.js';
|
|
4
|
-
import { Lender, LIQUITY_FAMILY_LENDERS, isAaveType, isCompoundV3, isMultiMarket, isSiloV2Type, isSiloV3Type, isDolomite, isEulerType, isAaveV4Type, isInit, isMorphoType, isCompoundV2Type, isVenusType, isSumerType, AAVE_V3_LENDERS, AAVE_V2_LENDERS, isAaveV2Type, isAaveV32Type, isAaveV3Type, isFluid, isGearboxV3, isMidnight, isTerm, isExactly, isLiquityFamily, isRiver, isYLDR, isCompoundV3Type, isLista, isTectonicType, isKineticType, isBenqiType } from '@1delta/lender-registry';
|
|
4
|
+
import { Lender, LIQUITY_FAMILY_LENDERS, isAaveType, isCompoundV3, isMultiMarket, isSiloV2Type, isSiloV3Type, isDolomite, isEulerType, isAaveV4Type, isInit, isMorphoType, isCompoundV2Type, isVenusType, isSumerType, AAVE_V3_LENDERS, AAVE_V2_LENDERS, isAaveV2Type, isAaveV32Type, isAaveV3Type, isFluid, isGearboxV3, isMidnight, isTerm, isExactly, isLiquityFamily, isRiver, isTeller, isYLDR, isCompoundV3Type, isLista, isTectonicType, isKineticType, isBenqiType } from '@1delta/lender-registry';
|
|
5
5
|
export { isAaveType, isAaveV2Type, isAaveV32Type, isAaveV3Type, isCompoundV3, isCompoundV3Type, isInit, isMorphoType, isMultiMarket, isYLDR } from '@1delta/lender-registry';
|
|
6
|
-
import { fetchTokenLists, fetchTokenList, aavePools, compoundV3Pools, initConfig, morphoPools, compoundV2Pools, eulerVaults, siloMarkets, siloV2LenderKey, siloMarketsV3, siloV3LenderKey, aaveV4Spokes, aaveV4SpokeLenderKey, fluidResolvers, gearboxResolvers, dolomiteConfigs, midnightConfig, termConfig, termMarketsByChain, exactlyConfig, liquityLendersByChain, riverLendersByChain, aaveReserves, compoundV3Reserves, liquityConfigFor, liquityBranchesByChain, riverConfigFor, riverChainData, morphoTypeMarkets, resolveMidnightApiBase, resolveTermApiBase, getSiloV2MarketEntry, getSiloV3MarketEntry, dolomiteEmode, aaveTokens, morphoTypeVaults, eulerConfigs, gearboxMarketCompressor, gearboxMarketConfigurators, gearboxV3LenderKey, midnightMarketsByChain, parseAaveV4SpokeLenderKey, gearboxAccountCompressor, compoundV2Tokens, exactlyMarketsByChain, aaveOracles, aaveOraclesConfig, compoundV2Oracles, compoundV2TokenArray, compoundV2OraclesConfig, compoundV3OraclesData, compoundV3BaseData, compoundV2Reserves, aaveV4Oracles } from '@1delta/data-sdk';
|
|
6
|
+
import { fetchTokenLists, fetchTokenList, aavePools, compoundV3Pools, initConfig, morphoPools, compoundV2Pools, eulerVaults, siloMarkets, siloV2LenderKey, siloMarketsV3, siloV3LenderKey, aaveV4Spokes, aaveV4SpokeLenderKey, fluidResolvers, gearboxResolvers, dolomiteConfigs, midnightConfig, termConfig, termMarketsByChain, exactlyConfig, liquityLendersByChain, riverLendersByChain, tellerConfigByChain, tellerPoolsByChain, aaveReserves, compoundV3Reserves, liquityConfigFor, liquityBranchesByChain, riverConfigFor, riverChainData, morphoTypeMarkets, resolveMidnightApiBase, resolveTermApiBase, getSiloV2MarketEntry, getSiloV3MarketEntry, dolomiteEmode, aaveTokens, morphoTypeVaults, eulerConfigs, gearboxMarketCompressor, gearboxMarketConfigurators, gearboxV3LenderKey, midnightMarketsByChain, parseAaveV4SpokeLenderKey, gearboxAccountCompressor, compoundV2Tokens, exactlyMarketsByChain, aaveOracles, aaveOraclesConfig, compoundV2Oracles, compoundV2TokenArray, compoundV2OraclesConfig, compoundV3OraclesData, compoundV3BaseData, compoundV2Reserves, aaveV4Oracles } from '@1delta/data-sdk';
|
|
7
7
|
import lodash from 'lodash';
|
|
8
8
|
import { getEvmClient, multicallRetryUniversal, getEvmChain, getEvmClientUniversal } from '@1delta/providers';
|
|
9
|
-
import { LiquityTroveManagerAbi, LiquityActivePoolAbi, LiquityStabilityPoolAbi, LiquityPriceFeedAbi, LiquitySortedTrovesAbi, RiverTroveManagerAbi, RiverStabilityPoolAbi, MetaMorphoAbi, ExactlyPreviewerAbi, ExactlyAuditorAbi, FluidLendingResolverAbi, FluidVaultResolverAbi, FluidLiquidityResolverAbi, MoolahVaultAbi, MorphoLensAbi, AaveV4SpokeAbi, AaveV4OracleAbi, AaveV4HubAbi, DolomiteMarginAbi, GearboxMarketCompressorV310Abi, MorphoBlueAbi, MidnightAbi, TermRepoTokenAbi, TermRepoServicerAbi, TermRepoCollateralManagerAbi, LiquityTroveNFTAbi, LiquityCollSurplusPoolAbi, GearboxCreditAccountCompressorV310Abi, TermPriceConsumerAbi } from '@1delta/abis';
|
|
9
|
+
import { LiquityTroveManagerAbi, LiquityActivePoolAbi, LiquityStabilityPoolAbi, LiquityPriceFeedAbi, LiquitySortedTrovesAbi, RiverTroveManagerAbi, RiverStabilityPoolAbi, MetaMorphoAbi, ExactlyPreviewerAbi, ExactlyAuditorAbi, LenderCommitmentGroupAbi, TellerMarketRegistryAbi, TellerV2Abi, FluidLendingResolverAbi, FluidVaultResolverAbi, FluidLiquidityResolverAbi, MoolahVaultAbi, MorphoLensAbi, AaveV4SpokeAbi, AaveV4OracleAbi, AaveV4HubAbi, DolomiteMarginAbi, GearboxMarketCompressorV310Abi, MorphoBlueAbi, MidnightAbi, TermRepoTokenAbi, TermRepoServicerAbi, TermRepoCollateralManagerAbi, LiquityTroveNFTAbi, LiquityCollSurplusPoolAbi, TellerCollateralManagerAbi, GearboxCreditAccountCompressorV310Abi, TermPriceConsumerAbi } from '@1delta/abis';
|
|
10
10
|
export { MorphoLensAbi } from '@1delta/abis';
|
|
11
11
|
import { prepareDebitDataMulticall, prepareLenderDebitMulticall, parseDebitDataResult, parseLenderDebitResult, getPermit2ContractAddress, getCompoundV3CometAddress as getCompoundV3CometAddress$1, getMorphoAddress, getAaveCollateralTokenAddress, getSiloHalfForUnderlying, InitMarginAddresses, getLstAcceptedInputs } from '@1delta/calldata-sdk';
|
|
12
12
|
import { proxyNativeFetch } from '@1delta/proxy-fetch';
|
|
@@ -7516,6 +7516,9 @@ var getLendersForChain = (c) => {
|
|
|
7516
7516
|
for (const l of riverLendersByChain(c)) {
|
|
7517
7517
|
lenders.push(l);
|
|
7518
7518
|
}
|
|
7519
|
+
if (tellerConfigByChain(c)?.tellerV2 && tellerPoolsByChain(c).length > 0) {
|
|
7520
|
+
lenders.push(Lender.TELLER);
|
|
7521
|
+
}
|
|
7519
7522
|
return lenders.filter((l) => !isExcludedLender(l));
|
|
7520
7523
|
};
|
|
7521
7524
|
var filterLendersByProtocol = (allLenders, protocolList) => {
|
|
@@ -7531,7 +7534,7 @@ var filterLendersByProtocol = (allLenders, protocolList) => {
|
|
|
7531
7534
|
(b) => protocolList.includes(b)
|
|
7532
7535
|
);
|
|
7533
7536
|
return allLenders.filter(
|
|
7534
|
-
(lender) => protocolList.includes(lender) || hasMorpho && lender?.startsWith("MORPHO_BLUE") || hasMoolah && lender?.startsWith("LISTA_DAO") || hasFluid && lender?.startsWith("FLUID") || hasGearboxV3 && lender?.startsWith("GEARBOX_V3") || hasDolomite && lender?.startsWith("DOLOMITE") || liquityBases.some((b) => lender?.startsWith(b)) || protocolList.includes(Lender.RIVER) && lender?.startsWith("RIVER")
|
|
7537
|
+
(lender) => protocolList.includes(lender) || hasMorpho && lender?.startsWith("MORPHO_BLUE") || hasMoolah && lender?.startsWith("LISTA_DAO") || hasFluid && lender?.startsWith("FLUID") || hasGearboxV3 && lender?.startsWith("GEARBOX_V3") || hasDolomite && lender?.startsWith("DOLOMITE") || liquityBases.some((b) => lender?.startsWith(b)) || protocolList.includes(Lender.RIVER) && lender?.startsWith("RIVER") || protocolList.includes(Lender.TELLER) && lender?.startsWith("TELLER")
|
|
7535
7538
|
);
|
|
7536
7539
|
};
|
|
7537
7540
|
var getAavesForChain = () => {
|
|
@@ -11165,8 +11168,8 @@ async function fetchListaBrokerUserData(chainId, account, marketKeys, nowSecs =
|
|
|
11165
11168
|
const brokers = await resolveListaBrokers(chainId, marketKeys, getClient);
|
|
11166
11169
|
const ids = Object.keys(brokers);
|
|
11167
11170
|
const out = {};
|
|
11168
|
-
const
|
|
11169
|
-
BROKER_USER_CACHE[
|
|
11171
|
+
const cacheKey4 = `${chainId}:${account.toLowerCase()}`;
|
|
11172
|
+
BROKER_USER_CACHE[cacheKey4] = out;
|
|
11170
11173
|
if (ids.length === 0) return out;
|
|
11171
11174
|
try {
|
|
11172
11175
|
const client = getClient(chainId);
|
|
@@ -21049,7 +21052,7 @@ function createMidnightBookSource(chainId, fetchImpl = fetch) {
|
|
|
21049
21052
|
var MIDNIGHT_BOOK_LEVELS = 20;
|
|
21050
21053
|
var LKG_TTL_SEC = 30 * 60;
|
|
21051
21054
|
var lastGood = /* @__PURE__ */ new Map();
|
|
21052
|
-
async function fetchTopAndBookWithFallback(source, chainId, marketId,
|
|
21055
|
+
async function fetchTopAndBookWithFallback(source, chainId, marketId, nowSec7) {
|
|
21053
21056
|
const key = `${chainId}:${marketId}`;
|
|
21054
21057
|
let fresh = null;
|
|
21055
21058
|
if (source.getTopAndBook) {
|
|
@@ -21059,11 +21062,11 @@ async function fetchTopAndBookWithFallback(source, chainId, marketId, nowSec5) {
|
|
|
21059
21062
|
if (top) fresh = { top, book: { bids: [], asks: [] } };
|
|
21060
21063
|
}
|
|
21061
21064
|
if (fresh) {
|
|
21062
|
-
lastGood.set(key, { top: fresh.top, book: fresh.book, at:
|
|
21065
|
+
lastGood.set(key, { top: fresh.top, book: fresh.book, at: nowSec7 });
|
|
21063
21066
|
return { top: fresh.top, book: fresh.book };
|
|
21064
21067
|
}
|
|
21065
21068
|
const cached = lastGood.get(key);
|
|
21066
|
-
if (cached &&
|
|
21069
|
+
if (cached && nowSec7 - cached.at <= LKG_TTL_SEC) {
|
|
21067
21070
|
return { top: cached.top, book: cached.book };
|
|
21068
21071
|
}
|
|
21069
21072
|
return { top: null, book: null };
|
|
@@ -21071,17 +21074,17 @@ async function fetchTopAndBookWithFallback(source, chainId, marketId, nowSec5) {
|
|
|
21071
21074
|
async function fetchMidnightMarkets(chainId, source = createMidnightBookSource(chainId)) {
|
|
21072
21075
|
const markets = midnightMarketsByChain(chainId);
|
|
21073
21076
|
if (markets.length === 0) return [];
|
|
21074
|
-
const
|
|
21077
|
+
const nowSec7 = Math.floor(Date.now() / 1e3);
|
|
21075
21078
|
return Promise.all(
|
|
21076
21079
|
markets.map(async (config) => {
|
|
21077
|
-
if (Number(config.maturity) <=
|
|
21080
|
+
if (Number(config.maturity) <= nowSec7) {
|
|
21078
21081
|
return { config, top: null, book: null };
|
|
21079
21082
|
}
|
|
21080
21083
|
const { top, book } = await fetchTopAndBookWithFallback(
|
|
21081
21084
|
source,
|
|
21082
21085
|
chainId,
|
|
21083
21086
|
config.marketId,
|
|
21084
|
-
|
|
21087
|
+
nowSec7
|
|
21085
21088
|
);
|
|
21086
21089
|
return { config, top, book };
|
|
21087
21090
|
})
|
|
@@ -21618,7 +21621,7 @@ function createTermBookSource(chainId, fetchImpl = fetch) {
|
|
|
21618
21621
|
var TERM_BOOK_LEVELS = 20;
|
|
21619
21622
|
var LKG_TTL_SEC2 = 30 * 60;
|
|
21620
21623
|
var lastGood2 = /* @__PURE__ */ new Map();
|
|
21621
|
-
async function fetchTopAndBookWithFallback2(source, chainId, config,
|
|
21624
|
+
async function fetchTopAndBookWithFallback2(source, chainId, config, nowSec7) {
|
|
21622
21625
|
const key = `${chainId}:${config.termRepoId}`;
|
|
21623
21626
|
let fresh = null;
|
|
21624
21627
|
if (source.getTopAndBook) {
|
|
@@ -21628,11 +21631,11 @@ async function fetchTopAndBookWithFallback2(source, chainId, config, nowSec5) {
|
|
|
21628
21631
|
if (top) fresh = { top, book: { bids: [], asks: [] } };
|
|
21629
21632
|
}
|
|
21630
21633
|
if (fresh) {
|
|
21631
|
-
lastGood2.set(key, { top: fresh.top, book: fresh.book, at:
|
|
21634
|
+
lastGood2.set(key, { top: fresh.top, book: fresh.book, at: nowSec7 });
|
|
21632
21635
|
return { top: fresh.top, book: fresh.book };
|
|
21633
21636
|
}
|
|
21634
21637
|
const cached = lastGood2.get(key);
|
|
21635
|
-
if (cached &&
|
|
21638
|
+
if (cached && nowSec7 - cached.at <= LKG_TTL_SEC2) {
|
|
21636
21639
|
return { top: cached.top, book: cached.book };
|
|
21637
21640
|
}
|
|
21638
21641
|
return { top: null, book: null };
|
|
@@ -21640,17 +21643,17 @@ async function fetchTopAndBookWithFallback2(source, chainId, config, nowSec5) {
|
|
|
21640
21643
|
async function fetchTermMarkets(chainId, source = createTermBookSource(chainId)) {
|
|
21641
21644
|
const markets = termMarketsByChain(chainId);
|
|
21642
21645
|
if (markets.length === 0) return [];
|
|
21643
|
-
const
|
|
21646
|
+
const nowSec7 = Math.floor(Date.now() / 1e3);
|
|
21644
21647
|
return Promise.all(
|
|
21645
21648
|
markets.map(async (config) => {
|
|
21646
|
-
if (Number(config.maturity) <=
|
|
21649
|
+
if (Number(config.maturity) <= nowSec7) {
|
|
21647
21650
|
return { config, top: null, book: null };
|
|
21648
21651
|
}
|
|
21649
21652
|
const { top, book } = await fetchTopAndBookWithFallback2(
|
|
21650
21653
|
source,
|
|
21651
21654
|
chainId,
|
|
21652
21655
|
config,
|
|
21653
|
-
|
|
21656
|
+
nowSec7
|
|
21654
21657
|
);
|
|
21655
21658
|
return { config, top, book };
|
|
21656
21659
|
})
|
|
@@ -22658,6 +22661,367 @@ function convertRiverMarketsToResponse(raw, chainId, prices = {}, _additionalYie
|
|
|
22658
22661
|
}
|
|
22659
22662
|
return out;
|
|
22660
22663
|
}
|
|
22664
|
+
var READS_PER_POOL = 6;
|
|
22665
|
+
var READS_PER_MARKET = 2;
|
|
22666
|
+
async function fetchTellerMarkets(chainId) {
|
|
22667
|
+
const pools = tellerPoolsByChain(chainId);
|
|
22668
|
+
if (pools.length === 0) return { chainId, pools: [] };
|
|
22669
|
+
const marketRegistry = tellerConfigByChain(chainId)?.marketRegistry;
|
|
22670
|
+
const calls = pools.flatMap((p) => {
|
|
22671
|
+
const onePrincipal = 10n ** BigInt(p.principalDecimals);
|
|
22672
|
+
return [
|
|
22673
|
+
{ address: p.pool, name: "getPrincipalAmountAvailableToBorrow", params: [] },
|
|
22674
|
+
{ address: p.pool, name: "totalPrincipalTokensCommitted", params: [] },
|
|
22675
|
+
{ address: p.pool, name: "getMinInterestRate", params: [0n] },
|
|
22676
|
+
{
|
|
22677
|
+
address: p.pool,
|
|
22678
|
+
name: "calculateCollateralRequiredToBorrowPrincipal",
|
|
22679
|
+
params: [onePrincipal]
|
|
22680
|
+
},
|
|
22681
|
+
{ address: p.pool, name: "getMaxLoanDuration", params: [] },
|
|
22682
|
+
{ address: p.pool, name: "getMarketId", params: [] }
|
|
22683
|
+
];
|
|
22684
|
+
});
|
|
22685
|
+
let results = [];
|
|
22686
|
+
try {
|
|
22687
|
+
results = await multicallRetryUniversal({
|
|
22688
|
+
chain: chainId,
|
|
22689
|
+
calls,
|
|
22690
|
+
abi: LenderCommitmentGroupAbi,
|
|
22691
|
+
allowFailure: true
|
|
22692
|
+
});
|
|
22693
|
+
} catch {
|
|
22694
|
+
return { chainId, pools: [] };
|
|
22695
|
+
}
|
|
22696
|
+
const big4 = (i) => {
|
|
22697
|
+
const r = results[i];
|
|
22698
|
+
if (typeof r === "bigint") return r;
|
|
22699
|
+
if (typeof r === "number") return BigInt(r);
|
|
22700
|
+
if (typeof r === "string" && r !== "0x") {
|
|
22701
|
+
try {
|
|
22702
|
+
return BigInt(r);
|
|
22703
|
+
} catch {
|
|
22704
|
+
return null;
|
|
22705
|
+
}
|
|
22706
|
+
}
|
|
22707
|
+
return null;
|
|
22708
|
+
};
|
|
22709
|
+
const num6 = (i) => {
|
|
22710
|
+
const b = big4(i);
|
|
22711
|
+
return b === null ? null : Number(b);
|
|
22712
|
+
};
|
|
22713
|
+
const pool0 = pools.map((config, i) => {
|
|
22714
|
+
const base = i * READS_PER_POOL;
|
|
22715
|
+
return {
|
|
22716
|
+
config,
|
|
22717
|
+
available: big4(base),
|
|
22718
|
+
committed: big4(base + 1),
|
|
22719
|
+
minRateBps: num6(base + 2),
|
|
22720
|
+
collateralPerPrincipal: big4(base + 3),
|
|
22721
|
+
maxLoanDuration: num6(base + 4),
|
|
22722
|
+
marketId: big4(base + 5)
|
|
22723
|
+
};
|
|
22724
|
+
});
|
|
22725
|
+
const attByMarket = /* @__PURE__ */ new Map();
|
|
22726
|
+
if (marketRegistry) {
|
|
22727
|
+
const uniqueMarkets = [
|
|
22728
|
+
...new Set(
|
|
22729
|
+
pool0.map((p) => p.marketId != null ? p.marketId.toString() : null).filter((m) => m != null)
|
|
22730
|
+
)
|
|
22731
|
+
];
|
|
22732
|
+
if (uniqueMarkets.length > 0) {
|
|
22733
|
+
const mCalls = uniqueMarkets.flatMap((m) => [
|
|
22734
|
+
{
|
|
22735
|
+
address: marketRegistry,
|
|
22736
|
+
name: "getMarketAttestationRequirements",
|
|
22737
|
+
params: [BigInt(m)]
|
|
22738
|
+
},
|
|
22739
|
+
{ address: marketRegistry, name: "isMarketOpen", params: [BigInt(m)] }
|
|
22740
|
+
]);
|
|
22741
|
+
try {
|
|
22742
|
+
const mRes = await multicallRetryUniversal({
|
|
22743
|
+
chain: chainId,
|
|
22744
|
+
calls: mCalls,
|
|
22745
|
+
abi: TellerMarketRegistryAbi,
|
|
22746
|
+
allowFailure: true
|
|
22747
|
+
});
|
|
22748
|
+
uniqueMarkets.forEach((m, i) => {
|
|
22749
|
+
const att = mRes[i * READS_PER_MARKET];
|
|
22750
|
+
const open = mRes[i * READS_PER_MARKET + 1];
|
|
22751
|
+
const borrowerRequired = (att?.borrowerAttestationRequired ?? att?.[1]) === true;
|
|
22752
|
+
attByMarket.set(m, {
|
|
22753
|
+
requiresBorrowerAttestation: borrowerRequired,
|
|
22754
|
+
marketOpen: open === false ? false : true
|
|
22755
|
+
});
|
|
22756
|
+
});
|
|
22757
|
+
} catch {
|
|
22758
|
+
}
|
|
22759
|
+
}
|
|
22760
|
+
}
|
|
22761
|
+
const out = pool0.map((p) => {
|
|
22762
|
+
const att = p.marketId != null ? attByMarket.get(p.marketId.toString()) : void 0;
|
|
22763
|
+
return {
|
|
22764
|
+
...p,
|
|
22765
|
+
requiresBorrowerAttestation: att?.requiresBorrowerAttestation,
|
|
22766
|
+
marketOpen: att?.marketOpen
|
|
22767
|
+
};
|
|
22768
|
+
});
|
|
22769
|
+
return { chainId, pools: out };
|
|
22770
|
+
}
|
|
22771
|
+
|
|
22772
|
+
// src/lending/public-data/teller/math.ts
|
|
22773
|
+
function tellerBpsToPercent(bps) {
|
|
22774
|
+
if (!bps) return 0;
|
|
22775
|
+
return bps / 100;
|
|
22776
|
+
}
|
|
22777
|
+
function tellerToHuman(raw, decimals) {
|
|
22778
|
+
if (!raw) return 0;
|
|
22779
|
+
return Number(raw) / 10 ** decimals;
|
|
22780
|
+
}
|
|
22781
|
+
function tellerImpliedLtv(collateralPerPrincipal, collateralDecimals, principalPrice, collateralPrice) {
|
|
22782
|
+
if (!collateralPerPrincipal || principalPrice <= 0 || collateralPrice <= 0) return 0;
|
|
22783
|
+
const collHuman = Number(collateralPerPrincipal) / 10 ** collateralDecimals;
|
|
22784
|
+
const collateralValue = collHuman * collateralPrice;
|
|
22785
|
+
if (collateralValue <= 0) return 0;
|
|
22786
|
+
const ltv = principalPrice / collateralValue;
|
|
22787
|
+
return ltv > 0 && ltv < 1 ? ltv : ltv >= 1 ? 1 : 0;
|
|
22788
|
+
}
|
|
22789
|
+
|
|
22790
|
+
// src/lending/public-data/teller/convertPublic.ts
|
|
22791
|
+
function tellerLenderKey(pool) {
|
|
22792
|
+
const body = pool.startsWith("0x") ? pool.slice(2) : pool;
|
|
22793
|
+
return "TELLER_" + body.toUpperCase();
|
|
22794
|
+
}
|
|
22795
|
+
function tellerPoolFromLenderKey(lender) {
|
|
22796
|
+
if (!lender.startsWith("TELLER_")) return void 0;
|
|
22797
|
+
const body = lender.slice("TELLER_".length);
|
|
22798
|
+
return body.length === 40 ? "0x" + body.toLowerCase() : void 0;
|
|
22799
|
+
}
|
|
22800
|
+
function currencyFor6(address, decimals, symbol, tokens) {
|
|
22801
|
+
const lower = address.toLowerCase();
|
|
22802
|
+
return tokens[lower] ?? { address: lower, symbol, name: symbol, decimals };
|
|
22803
|
+
}
|
|
22804
|
+
function priceFor(address, chainId, tokens, prices) {
|
|
22805
|
+
const lower = address.toLowerCase();
|
|
22806
|
+
const token = tokens[lower];
|
|
22807
|
+
const key = toOracleKey(token?.assetGroup) || toGenericPriceKey(lower, chainId);
|
|
22808
|
+
return prices[key] ?? 0;
|
|
22809
|
+
}
|
|
22810
|
+
function convertTellerMarketsToResponse(raw, chainId, prices = {}, _additionalYields = {
|
|
22811
|
+
intrinsicYields: {},
|
|
22812
|
+
lenderRewards: {},
|
|
22813
|
+
loaded: true
|
|
22814
|
+
}, tokens = {}) {
|
|
22815
|
+
const out = {};
|
|
22816
|
+
const proto = tellerConfigByChain(chainId);
|
|
22817
|
+
for (const p of raw?.pools ?? []) {
|
|
22818
|
+
const cfg = p.config;
|
|
22819
|
+
const lenderKey = tellerLenderKey(cfg.pool);
|
|
22820
|
+
const principalAddr = cfg.principal.toLowerCase();
|
|
22821
|
+
const collateralAddr = cfg.collateral.toLowerCase();
|
|
22822
|
+
const principalPrice = priceFor(principalAddr, chainId, tokens, prices);
|
|
22823
|
+
const collateralPrice = priceFor(collateralAddr, chainId, tokens, prices);
|
|
22824
|
+
const borrowLiquidity = tellerToHuman(p.available, cfg.principalDecimals);
|
|
22825
|
+
const totalDeposits = tellerToHuman(p.committed, cfg.principalDecimals);
|
|
22826
|
+
const totalDebt = Math.max(0, totalDeposits - borrowLiquidity);
|
|
22827
|
+
const utilization = totalDeposits > 0 ? totalDebt / totalDeposits : 0;
|
|
22828
|
+
const borrowApr = tellerBpsToPercent(p.minRateBps);
|
|
22829
|
+
const depositApr = utilization * borrowApr;
|
|
22830
|
+
const ltv = tellerImpliedLtv(
|
|
22831
|
+
p.collateralPerPrincipal,
|
|
22832
|
+
cfg.collateralDecimals,
|
|
22833
|
+
principalPrice,
|
|
22834
|
+
collateralPrice
|
|
22835
|
+
);
|
|
22836
|
+
const durationSecs = p.maxLoanDuration ?? cfg.maxLoanDuration ?? 0;
|
|
22837
|
+
const terms = [
|
|
22838
|
+
{
|
|
22839
|
+
// Rolling duration → use the max duration as the (stable) term id.
|
|
22840
|
+
termId: durationSecs,
|
|
22841
|
+
durationSecs,
|
|
22842
|
+
durationDays: durationSecs / 86400,
|
|
22843
|
+
apr: borrowApr,
|
|
22844
|
+
depositApr,
|
|
22845
|
+
available: borrowLiquidity
|
|
22846
|
+
}
|
|
22847
|
+
];
|
|
22848
|
+
const entry = { data: {} };
|
|
22849
|
+
const loanUid = createMarketUid(chainId, lenderKey, principalAddr);
|
|
22850
|
+
entry.data[loanUid] = {
|
|
22851
|
+
marketUid: loanUid,
|
|
22852
|
+
name: cfg.principalSymbol,
|
|
22853
|
+
poolId: cfg.pool.toLowerCase(),
|
|
22854
|
+
underlying: principalAddr,
|
|
22855
|
+
asset: currencyFor6(
|
|
22856
|
+
principalAddr,
|
|
22857
|
+
cfg.principalDecimals,
|
|
22858
|
+
cfg.principalSymbol,
|
|
22859
|
+
tokens
|
|
22860
|
+
),
|
|
22861
|
+
totalDeposits,
|
|
22862
|
+
totalDebtStable: totalDebt,
|
|
22863
|
+
totalDebt: 0,
|
|
22864
|
+
totalLiquidity: borrowLiquidity,
|
|
22865
|
+
borrowLiquidity,
|
|
22866
|
+
totalLiquidityUSD: borrowLiquidity * principalPrice,
|
|
22867
|
+
borrowLiquidityUSD: borrowLiquidity * principalPrice,
|
|
22868
|
+
totalDepositsUSD: totalDeposits * principalPrice,
|
|
22869
|
+
totalDebtStableUSD: totalDebt * principalPrice,
|
|
22870
|
+
totalDebtUSD: 0,
|
|
22871
|
+
utilization,
|
|
22872
|
+
depositRate: depositApr,
|
|
22873
|
+
// Teller has NO floating leg — the fixed borrow APR sits on the stable slot
|
|
22874
|
+
// (fixed-rate convention: Exactly/Term/Lista), variable stays 0.
|
|
22875
|
+
variableBorrowRate: 0,
|
|
22876
|
+
stableBorrowRate: borrowApr,
|
|
22877
|
+
rateModel: "fixedTerm",
|
|
22878
|
+
intrinsicYield: 0,
|
|
22879
|
+
rewards: void 0,
|
|
22880
|
+
decimals: cfg.principalDecimals,
|
|
22881
|
+
config: {
|
|
22882
|
+
0: {
|
|
22883
|
+
category: 0,
|
|
22884
|
+
// Principal token is the borrow asset, not collateral in this pool.
|
|
22885
|
+
borrowCollateralFactor: 0,
|
|
22886
|
+
collateralFactor: 0,
|
|
22887
|
+
borrowFactor: 1,
|
|
22888
|
+
liquidationPenalty: 0,
|
|
22889
|
+
closeFactor: 1,
|
|
22890
|
+
collateralDisabled: true,
|
|
22891
|
+
debtDisabled: false
|
|
22892
|
+
}
|
|
22893
|
+
},
|
|
22894
|
+
closeFactor: 1,
|
|
22895
|
+
collateralActive: false,
|
|
22896
|
+
// Open markets with live liquidity are borrowable; attestation-gated
|
|
22897
|
+
// markets stay borrowable here (flagged in the descriptor) — the per-user
|
|
22898
|
+
// gate runs at borrow time.
|
|
22899
|
+
borrowingEnabled: borrowLiquidity > 0 && p.marketOpen !== false,
|
|
22900
|
+
depositsEnabled: true,
|
|
22901
|
+
hasStable: false,
|
|
22902
|
+
variableBorrowDisabled: true,
|
|
22903
|
+
isActive: p.marketOpen !== false,
|
|
22904
|
+
isFrozen: p.marketOpen === false
|
|
22905
|
+
};
|
|
22906
|
+
const collUid = createMarketUid(chainId, lenderKey, collateralAddr);
|
|
22907
|
+
entry.data[collUid] = {
|
|
22908
|
+
marketUid: collUid,
|
|
22909
|
+
name: "Collateral " + cfg.collateralSymbol,
|
|
22910
|
+
poolId: cfg.pool.toLowerCase(),
|
|
22911
|
+
underlying: collateralAddr,
|
|
22912
|
+
asset: currencyFor6(
|
|
22913
|
+
collateralAddr,
|
|
22914
|
+
cfg.collateralDecimals,
|
|
22915
|
+
cfg.collateralSymbol,
|
|
22916
|
+
tokens
|
|
22917
|
+
),
|
|
22918
|
+
totalDeposits: 0,
|
|
22919
|
+
totalDebtStable: 0,
|
|
22920
|
+
totalDebt: 0,
|
|
22921
|
+
totalLiquidity: 0,
|
|
22922
|
+
borrowLiquidity: 0,
|
|
22923
|
+
totalLiquidityUSD: 0,
|
|
22924
|
+
borrowLiquidityUSD: 0,
|
|
22925
|
+
totalDepositsUSD: 0,
|
|
22926
|
+
totalDebtStableUSD: 0,
|
|
22927
|
+
totalDebtUSD: 0,
|
|
22928
|
+
utilization: 0,
|
|
22929
|
+
depositRate: 0,
|
|
22930
|
+
variableBorrowRate: 0,
|
|
22931
|
+
stableBorrowRate: 0,
|
|
22932
|
+
intrinsicYield: 0,
|
|
22933
|
+
rewards: void 0,
|
|
22934
|
+
decimals: cfg.collateralDecimals,
|
|
22935
|
+
config: {
|
|
22936
|
+
0: {
|
|
22937
|
+
category: 0,
|
|
22938
|
+
borrowCollateralFactor: ltv,
|
|
22939
|
+
collateralFactor: ltv,
|
|
22940
|
+
borrowFactor: 1,
|
|
22941
|
+
// Time-based liquidation → no price-based penalty parameter.
|
|
22942
|
+
liquidationPenalty: 0,
|
|
22943
|
+
closeFactor: 1,
|
|
22944
|
+
collateralDisabled: false,
|
|
22945
|
+
debtDisabled: true
|
|
22946
|
+
}
|
|
22947
|
+
},
|
|
22948
|
+
closeFactor: 1,
|
|
22949
|
+
collateralActive: true,
|
|
22950
|
+
borrowingEnabled: false,
|
|
22951
|
+
depositsEnabled: true,
|
|
22952
|
+
hasStable: false,
|
|
22953
|
+
isActive: true,
|
|
22954
|
+
isFrozen: false
|
|
22955
|
+
};
|
|
22956
|
+
const implications = [
|
|
22957
|
+
"Fixed-term, fixed-APR loan: the rate is locked at borrow time for a duration you choose (up to the pool max).",
|
|
22958
|
+
"TIME-based liquidation only \u2014 collateral is seized if a payment is missed past the market window. There is NO price-based liquidation and NO margin call.",
|
|
22959
|
+
"Closing is a FULL repayment: it repays principal + interest and releases ALL collateral in one tx (no partial collateral withdrawal; a partial repay keeps the collateral escrowed)."
|
|
22960
|
+
];
|
|
22961
|
+
if (p.requiresBorrowerAttestation)
|
|
22962
|
+
implications.push(
|
|
22963
|
+
"This market requires borrower ATTESTATION \u2014 the borrower must be whitelisted by the market owner before borrowing."
|
|
22964
|
+
);
|
|
22965
|
+
if (p.marketOpen === false)
|
|
22966
|
+
implications.push("This market is currently CLOSED (not borrowable).");
|
|
22967
|
+
entry.params = {
|
|
22968
|
+
market: {
|
|
22969
|
+
lender: lenderKey,
|
|
22970
|
+
name: cfg.name ?? `Teller ${cfg.principalSymbol} / ${cfg.collateralSymbol}`,
|
|
22971
|
+
loanDecimals: cfg.principalDecimals,
|
|
22972
|
+
collateralDecimals: cfg.collateralDecimals,
|
|
22973
|
+
// Pool address doubles as the market id (it IS the lender-key body).
|
|
22974
|
+
id: cfg.pool.toLowerCase(),
|
|
22975
|
+
lltv: ltv.toString(),
|
|
22976
|
+
oracle: zeroAddress,
|
|
22977
|
+
irm: zeroAddress,
|
|
22978
|
+
collateralAddress: collateralAddr,
|
|
22979
|
+
loanAddress: principalAddr,
|
|
22980
|
+
terms,
|
|
22981
|
+
// Canonical cross-protocol fixed-term descriptor. Teller: rolling
|
|
22982
|
+
// duration (≤ maxLoanDuration), pool-fronted fixed APR, early repay =
|
|
22983
|
+
// NONE (full early repay is pro-rata, penalty-free), overdue handling is
|
|
22984
|
+
// time-based default/seizure (no late-penalty APR).
|
|
22985
|
+
fixedTerm: {
|
|
22986
|
+
model: "teller",
|
|
22987
|
+
maturity: void 0,
|
|
22988
|
+
fees: {},
|
|
22989
|
+
earlyRepay: { kind: "none" },
|
|
22990
|
+
provider: { kind: "pool", address: cfg.pool.toLowerCase() }
|
|
22991
|
+
},
|
|
22992
|
+
// --- Teller descriptor (addresses + config the calldata/worker
|
|
22993
|
+
// resolvers consume; mirrors river's `river` / exactly's extras) ---
|
|
22994
|
+
teller: {
|
|
22995
|
+
pool: cfg.pool.toLowerCase(),
|
|
22996
|
+
// On-chain marketId is authoritative; fall back to the config seed.
|
|
22997
|
+
marketId: p.marketId != null ? p.marketId.toString() : cfg.marketId,
|
|
22998
|
+
maxLoanDuration: durationSecs,
|
|
22999
|
+
// Permissioning: some markets only let PRE-ATTESTED borrowers open
|
|
23000
|
+
// loans (the borrow builder enforces per-user; this flags it for the
|
|
23001
|
+
// UI/allocator). `marketOpen` = MarketRegistry.isMarketOpen.
|
|
23002
|
+
requiresBorrowerAttestation: p.requiresBorrowerAttestation,
|
|
23003
|
+
marketOpen: p.marketOpen,
|
|
23004
|
+
/** Human-readable caveats for the UI to surface (see above). */
|
|
23005
|
+
implications,
|
|
23006
|
+
minInterestRateBps: p.minRateBps ?? void 0,
|
|
23007
|
+
interestRateLowerBound: cfg.interestRateLowerBound ?? void 0,
|
|
23008
|
+
interestRateUpperBound: cfg.interestRateUpperBound ?? void 0,
|
|
23009
|
+
principalAvailable: p.available !== null ? p.available.toString() : void 0,
|
|
23010
|
+
collateralPerPrincipal: p.collateralPerPrincipal !== null ? p.collateralPerPrincipal.toString() : void 0,
|
|
23011
|
+
addresses: {
|
|
23012
|
+
tellerV2: proto?.tellerV2,
|
|
23013
|
+
collateralManager: proto?.collateralManager,
|
|
23014
|
+
smartCommitmentForwarder: proto?.smartCommitmentForwarder,
|
|
23015
|
+
marketRegistry: proto?.marketRegistry
|
|
23016
|
+
}
|
|
23017
|
+
}
|
|
23018
|
+
}
|
|
23019
|
+
};
|
|
23020
|
+
entry.chainId = chainId;
|
|
23021
|
+
out[lenderKey] = entry;
|
|
23022
|
+
}
|
|
23023
|
+
return out;
|
|
23024
|
+
}
|
|
22661
23025
|
|
|
22662
23026
|
// src/lending/public-data/silo-v2/fetchPublic.ts
|
|
22663
23027
|
var BASE_URL2 = "https://api-v3.silo.finance";
|
|
@@ -23265,6 +23629,7 @@ async function getLenderDataFromApi(lender, chainId, prices, additionalYields, i
|
|
|
23265
23629
|
if (isExactly(lender)) return await fetchExactlyMarkets(chainId);
|
|
23266
23630
|
if (isLiquityFamily(lender)) return await fetchLiquityMarkets(lender, chainId);
|
|
23267
23631
|
if (isRiver(lender)) return await fetchRiverMarkets(lender, chainId);
|
|
23632
|
+
if (isTeller(lender)) return await fetchTellerMarkets(chainId);
|
|
23268
23633
|
return {};
|
|
23269
23634
|
}
|
|
23270
23635
|
function convertLenderDataFromApi(lender, chainId, data, prices, additionalYields, list = {}) {
|
|
@@ -23310,6 +23675,14 @@ function convertLenderDataFromApi(lender, chainId, data, prices, additionalYield
|
|
|
23310
23675
|
additionalYields,
|
|
23311
23676
|
list
|
|
23312
23677
|
);
|
|
23678
|
+
if (isTeller(lender))
|
|
23679
|
+
return convertTellerMarketsToResponse(
|
|
23680
|
+
data,
|
|
23681
|
+
chainId,
|
|
23682
|
+
prices,
|
|
23683
|
+
additionalYields,
|
|
23684
|
+
list
|
|
23685
|
+
);
|
|
23313
23686
|
return {};
|
|
23314
23687
|
}
|
|
23315
23688
|
var getLenderPublicDataViaApi = async (chainId, lenders, prices, additionalYields, tokenList = async () => {
|
|
@@ -23498,6 +23871,7 @@ function lenderApiOnly(lender, chainId) {
|
|
|
23498
23871
|
if (isExactly(lender)) return true;
|
|
23499
23872
|
if (isLiquityFamily(lender)) return true;
|
|
23500
23873
|
if (isRiver(lender)) return true;
|
|
23874
|
+
if (isTeller(lender)) return true;
|
|
23501
23875
|
return false;
|
|
23502
23876
|
}
|
|
23503
23877
|
function lenderApiWithOnChainFallback(lender, chainId) {
|
|
@@ -24406,6 +24780,103 @@ var buildRiverUserCall = (chainId, lender, account) => {
|
|
|
24406
24780
|
});
|
|
24407
24781
|
return calls;
|
|
24408
24782
|
};
|
|
24783
|
+
var TELLER_CALLS_PER_BID = 4;
|
|
24784
|
+
var CACHE_TTL_MS2 = 5 * 6e4;
|
|
24785
|
+
var discoveryCache2 = /* @__PURE__ */ new Map();
|
|
24786
|
+
var cacheKey2 = (chainId, account) => `${chainId}:${account.toLowerCase()}`;
|
|
24787
|
+
var getCachedTellerBids = (chainId, account) => {
|
|
24788
|
+
const hit = discoveryCache2.get(cacheKey2(chainId, account));
|
|
24789
|
+
if (!hit || Date.now() - hit.at > CACHE_TTL_MS2) return void 0;
|
|
24790
|
+
return hit;
|
|
24791
|
+
};
|
|
24792
|
+
var nowSec4 = () => Math.floor(Date.now() / 1e3);
|
|
24793
|
+
var toBigints = (arr) => {
|
|
24794
|
+
if (!Array.isArray(arr)) return [];
|
|
24795
|
+
const out = [];
|
|
24796
|
+
for (const x of arr) {
|
|
24797
|
+
try {
|
|
24798
|
+
out.push(BigInt(x).toString());
|
|
24799
|
+
} catch {
|
|
24800
|
+
}
|
|
24801
|
+
}
|
|
24802
|
+
return out;
|
|
24803
|
+
};
|
|
24804
|
+
var buildTellerUserCall = async (chainId, _lender, account) => {
|
|
24805
|
+
const proto = tellerConfigByChain(chainId);
|
|
24806
|
+
const pools = tellerPoolsByChain(chainId);
|
|
24807
|
+
if (!proto?.tellerV2 || !proto?.collateralManager || pools.length === 0) {
|
|
24808
|
+
return [];
|
|
24809
|
+
}
|
|
24810
|
+
let ids = [];
|
|
24811
|
+
try {
|
|
24812
|
+
const res = await multicallRetryUniversal({
|
|
24813
|
+
chain: chainId,
|
|
24814
|
+
calls: [
|
|
24815
|
+
{
|
|
24816
|
+
address: proto.tellerV2,
|
|
24817
|
+
name: "getBorrowerActiveLoanIds",
|
|
24818
|
+
params: [account]
|
|
24819
|
+
}
|
|
24820
|
+
],
|
|
24821
|
+
abi: TellerV2Abi,
|
|
24822
|
+
allowFailure: true
|
|
24823
|
+
});
|
|
24824
|
+
ids = toBigints(res?.[0]);
|
|
24825
|
+
} catch {
|
|
24826
|
+
return [];
|
|
24827
|
+
}
|
|
24828
|
+
if (ids.length === 0) {
|
|
24829
|
+
discoveryCache2.set(cacheKey2(chainId, account), { bids: [], at: Date.now() });
|
|
24830
|
+
return [];
|
|
24831
|
+
}
|
|
24832
|
+
const poolByAddr = /* @__PURE__ */ new Map();
|
|
24833
|
+
for (const p of pools) poolByAddr.set(p.pool.toLowerCase(), p);
|
|
24834
|
+
let lenders = [];
|
|
24835
|
+
try {
|
|
24836
|
+
lenders = await multicallRetryUniversal({
|
|
24837
|
+
chain: chainId,
|
|
24838
|
+
calls: ids.map((id) => ({
|
|
24839
|
+
address: proto.tellerV2,
|
|
24840
|
+
name: "getLoanLender",
|
|
24841
|
+
params: [id]
|
|
24842
|
+
})),
|
|
24843
|
+
abi: TellerV2Abi,
|
|
24844
|
+
allowFailure: true
|
|
24845
|
+
});
|
|
24846
|
+
} catch {
|
|
24847
|
+
return [];
|
|
24848
|
+
}
|
|
24849
|
+
const kept = [];
|
|
24850
|
+
ids.forEach((id, i) => {
|
|
24851
|
+
const r = lenders[i];
|
|
24852
|
+
const lenderAddr = typeof r === "string" ? r.toLowerCase() : "";
|
|
24853
|
+
const pool = poolByAddr.get(lenderAddr);
|
|
24854
|
+
if (pool) kept.push({ bidId: id, pool });
|
|
24855
|
+
});
|
|
24856
|
+
discoveryCache2.set(cacheKey2(chainId, account), { bids: kept, at: Date.now() });
|
|
24857
|
+
if (kept.length === 0) return [];
|
|
24858
|
+
const ts = nowSec4();
|
|
24859
|
+
const calls = [];
|
|
24860
|
+
for (const b of kept) {
|
|
24861
|
+
calls.push({ address: proto.tellerV2, name: "bids", params: [b.bidId] });
|
|
24862
|
+
calls.push({
|
|
24863
|
+
address: proto.tellerV2,
|
|
24864
|
+
name: "calculateAmountOwed",
|
|
24865
|
+
params: [b.bidId, ts]
|
|
24866
|
+
});
|
|
24867
|
+
calls.push({
|
|
24868
|
+
address: proto.collateralManager,
|
|
24869
|
+
name: "getCollateralAmount",
|
|
24870
|
+
params: [b.bidId, b.pool.collateral]
|
|
24871
|
+
});
|
|
24872
|
+
calls.push({
|
|
24873
|
+
address: proto.tellerV2,
|
|
24874
|
+
name: "isLoanDefaulted",
|
|
24875
|
+
params: [b.bidId]
|
|
24876
|
+
});
|
|
24877
|
+
}
|
|
24878
|
+
return calls;
|
|
24879
|
+
};
|
|
24409
24880
|
|
|
24410
24881
|
// src/lending/user-data/fetch-balances/prepare.ts
|
|
24411
24882
|
async function buildUserCall(chainId, lender, account, params, getClient) {
|
|
@@ -24427,6 +24898,7 @@ async function buildUserCall(chainId, lender, account, params, getClient) {
|
|
|
24427
24898
|
if (isLiquityFamily(lender))
|
|
24428
24899
|
return buildLiquityUserCall(chainId, lender, account);
|
|
24429
24900
|
if (isRiver(lender)) return buildRiverUserCall(chainId, lender, account);
|
|
24901
|
+
if (isTeller(lender)) return buildTellerUserCall(chainId, lender, account);
|
|
24430
24902
|
if (isCompoundV3Type(lender))
|
|
24431
24903
|
return buildCompoundV3UserCall(chainId, lender, account);
|
|
24432
24904
|
if (isEulerType(lender))
|
|
@@ -24453,10 +24925,11 @@ function organizeUserQueries(queries) {
|
|
|
24453
24925
|
const exactly = queries.filter((q) => isExactly(q.lender));
|
|
24454
24926
|
const liquity = queries.filter((q) => isLiquityFamily(q.lender));
|
|
24455
24927
|
const river = queries.filter((q) => isRiver(q.lender));
|
|
24456
|
-
|
|
24928
|
+
const teller = queries.filter((q) => isTeller(q.lender));
|
|
24929
|
+
if (morphos.length === 0 && gearbox.length === 0 && midnight.length === 0 && term.length === 0 && exactly.length === 0 && liquity.length === 0 && river.length === 0 && teller.length === 0)
|
|
24457
24930
|
return queries;
|
|
24458
24931
|
const others = queries.filter(
|
|
24459
|
-
(q) => !isMorphoType(q.lender) && !isGearboxV3(q.lender) && !isMidnight(q.lender) && !isTerm(q.lender) && !isExactly(q.lender) && !isLiquityFamily(q.lender) && !isRiver(q.lender)
|
|
24932
|
+
(q) => !isMorphoType(q.lender) && !isGearboxV3(q.lender) && !isMidnight(q.lender) && !isTerm(q.lender) && !isExactly(q.lender) && !isLiquityFamily(q.lender) && !isRiver(q.lender) && !isTeller(q.lender)
|
|
24460
24933
|
);
|
|
24461
24934
|
const morphoBlue = morphos.filter((q) => q.lender.startsWith("MORPHO_BLUE"));
|
|
24462
24935
|
const moolah = morphos.filter((q) => q.lender.startsWith("LISTA_DAO"));
|
|
@@ -24517,6 +24990,14 @@ function organizeUserQueries(queries) {
|
|
|
24517
24990
|
assets: void 0
|
|
24518
24991
|
});
|
|
24519
24992
|
}
|
|
24993
|
+
if (teller.length > 0) {
|
|
24994
|
+
result.push({
|
|
24995
|
+
lender: Lender.TELLER,
|
|
24996
|
+
account: teller[0].account,
|
|
24997
|
+
params: teller.map((p) => p.lender),
|
|
24998
|
+
assets: void 0
|
|
24999
|
+
});
|
|
25000
|
+
}
|
|
24520
25001
|
if (liquity.length > 0) {
|
|
24521
25002
|
for (const base of LIQUITY_FAMILY_LENDERS) {
|
|
24522
25003
|
const members = liquity.filter((q) => q.lender.startsWith(base));
|
|
@@ -26968,7 +27449,7 @@ var getTermUserDataConverter = (_lender, chainId, account, meta) => {
|
|
|
26968
27449
|
totalCalls
|
|
26969
27450
|
];
|
|
26970
27451
|
};
|
|
26971
|
-
var
|
|
27452
|
+
var nowSec5 = () => Math.floor(Date.now() / 1e3);
|
|
26972
27453
|
function sumPreview(positions) {
|
|
26973
27454
|
return positions.reduce((acc, p) => acc + p.previewValue, 0n);
|
|
26974
27455
|
}
|
|
@@ -26990,7 +27471,7 @@ var getExactlyUserDataConverter = (_lender, chainId, account, meta) => {
|
|
|
26990
27471
|
const res = data[0];
|
|
26991
27472
|
if (!res || res === "0x" || !Array.isArray(res)) return void 0;
|
|
26992
27473
|
const markets = res;
|
|
26993
|
-
const now =
|
|
27474
|
+
const now = nowSec5();
|
|
26994
27475
|
const out = {};
|
|
26995
27476
|
for (const m of markets) {
|
|
26996
27477
|
const lenderKey = exactlyLenderKey(m.market);
|
|
@@ -27475,6 +27956,148 @@ var getRiverUserDataConverter = (lender, chainId, account, meta) => {
|
|
|
27475
27956
|
];
|
|
27476
27957
|
};
|
|
27477
27958
|
|
|
27959
|
+
// src/lending/user-data/teller/userCallParse.ts
|
|
27960
|
+
var nowSec6 = () => Math.floor(Date.now() / 1e3);
|
|
27961
|
+
var big3 = (v) => {
|
|
27962
|
+
try {
|
|
27963
|
+
if (typeof v === "bigint") return v;
|
|
27964
|
+
if (typeof v === "number" || typeof v === "string") return BigInt(v);
|
|
27965
|
+
} catch {
|
|
27966
|
+
}
|
|
27967
|
+
return 0n;
|
|
27968
|
+
};
|
|
27969
|
+
var field8 = (res, name, idx) => res?.[name] ?? res?.[idx];
|
|
27970
|
+
var getTellerUserDataConverter = (_lender, chainId, account, meta) => {
|
|
27971
|
+
const discovery = getCachedTellerBids(chainId, account);
|
|
27972
|
+
const kept = discovery?.bids ?? [];
|
|
27973
|
+
const expected = kept.length * TELLER_CALLS_PER_BID;
|
|
27974
|
+
return [
|
|
27975
|
+
(data) => {
|
|
27976
|
+
if (expected === 0 || !data || data.length < expected) return void 0;
|
|
27977
|
+
const now = nowSec6();
|
|
27978
|
+
const perPool = {};
|
|
27979
|
+
kept.forEach((b, i) => {
|
|
27980
|
+
const base = i * TELLER_CALLS_PER_BID;
|
|
27981
|
+
const bidRes = data[base];
|
|
27982
|
+
const owed = data[base + 1];
|
|
27983
|
+
const collAmount = big3(data[base + 2]);
|
|
27984
|
+
const defaulted = !!data[base + 3];
|
|
27985
|
+
if (!bidRes) return;
|
|
27986
|
+
const pool = b.pool;
|
|
27987
|
+
const lenderKey = tellerLenderKey(pool.pool);
|
|
27988
|
+
const metaMap = meta?.[lenderKey];
|
|
27989
|
+
if (!metaMap) return;
|
|
27990
|
+
const principalAddr = pool.principal.toLowerCase();
|
|
27991
|
+
const collAddr = pool.collateral.toLowerCase();
|
|
27992
|
+
const loanUid = createMarketUid(chainId, lenderKey, principalAddr);
|
|
27993
|
+
const collUid = createMarketUid(chainId, lenderKey, collAddr);
|
|
27994
|
+
const loanMeta = metaMap[loanUid];
|
|
27995
|
+
const collMeta = metaMap[collUid];
|
|
27996
|
+
const principalDecimals = loanMeta?.asset?.decimals ?? pool.principalDecimals;
|
|
27997
|
+
const collDecimals = collMeta?.asset?.decimals ?? pool.collateralDecimals;
|
|
27998
|
+
const loanDisplay = loanMeta ? getDisplayPrice(loanMeta) : 0;
|
|
27999
|
+
const loanOracle = loanMeta ? getOraclePrice(loanMeta) : 0;
|
|
28000
|
+
const loanHist = loanMeta?.price?.priceUsd24h ?? loanDisplay;
|
|
28001
|
+
const collDisplay = collMeta ? getDisplayPrice(collMeta) : 0;
|
|
28002
|
+
const collOracle = collMeta ? getOraclePrice(collMeta) : 0;
|
|
28003
|
+
const collHist = collMeta?.price?.priceUsd24h ?? collDisplay;
|
|
28004
|
+
const owedPrincipal = big3(field8(owed, "principal", 0));
|
|
28005
|
+
const owedInterest = big3(field8(owed, "interest", 1));
|
|
28006
|
+
const owedTotal = owedPrincipal + owedInterest;
|
|
28007
|
+
if (owedTotal === 0n && collAmount === 0n) return;
|
|
28008
|
+
const loanDetails = field8(bidRes, "loanDetails", 5);
|
|
28009
|
+
const terms = field8(bidRes, "terms", 6);
|
|
28010
|
+
const acceptedTs = Number(big3(field8(loanDetails, "acceptedTimestamp", 4)));
|
|
28011
|
+
const loanDuration = Number(big3(field8(loanDetails, "loanDuration", 6)));
|
|
28012
|
+
const aprBps = Number(big3(field8(terms, "APR", 2)));
|
|
28013
|
+
const maturity = acceptedTs > 0 ? acceptedTs + loanDuration : void 0;
|
|
28014
|
+
const isMatured = defaulted || maturity !== void 0 && maturity < now;
|
|
28015
|
+
const collStr = parseRawAmount(collAmount.toString(), collDecimals);
|
|
28016
|
+
const collNum = Number(collStr);
|
|
28017
|
+
const debtStr = parseRawAmount(owedTotal.toString(), principalDecimals);
|
|
28018
|
+
const debtNum = Number(debtStr);
|
|
28019
|
+
const interestStr = parseRawAmount(
|
|
28020
|
+
owedInterest.toString(),
|
|
28021
|
+
principalDecimals
|
|
28022
|
+
);
|
|
28023
|
+
const bucket = perPool[lenderKey] ??= {
|
|
28024
|
+
positions: {},
|
|
28025
|
+
modes: {},
|
|
28026
|
+
hist: {},
|
|
28027
|
+
metaMap
|
|
28028
|
+
};
|
|
28029
|
+
bucket.positions[b.bidId] = {
|
|
28030
|
+
[collUid]: {
|
|
28031
|
+
marketUid: collUid,
|
|
28032
|
+
underlying: collAddr,
|
|
28033
|
+
deposits: collStr,
|
|
28034
|
+
debt: "0",
|
|
28035
|
+
debtStable: "0",
|
|
28036
|
+
depositsUSD: collNum * collDisplay,
|
|
28037
|
+
debtUSD: 0,
|
|
28038
|
+
debtStableUSD: 0,
|
|
28039
|
+
depositsUSDOracle: collNum * collOracle,
|
|
28040
|
+
debtUSDOracle: 0,
|
|
28041
|
+
debtStableUSDOracle: 0,
|
|
28042
|
+
stableBorrowRate: "0",
|
|
28043
|
+
collateralEnabled: true,
|
|
28044
|
+
claimableRewards: 0
|
|
28045
|
+
},
|
|
28046
|
+
[loanUid]: {
|
|
28047
|
+
marketUid: loanUid,
|
|
28048
|
+
underlying: principalAddr,
|
|
28049
|
+
deposits: "0",
|
|
28050
|
+
debt: "0",
|
|
28051
|
+
// Fixed-term debt → stable slot (Exactly/Lista convention).
|
|
28052
|
+
debtStable: debtStr,
|
|
28053
|
+
depositsUSD: 0,
|
|
28054
|
+
debtUSD: 0,
|
|
28055
|
+
debtStableUSD: debtNum * loanDisplay,
|
|
28056
|
+
depositsUSDOracle: 0,
|
|
28057
|
+
debtUSDOracle: 0,
|
|
28058
|
+
debtStableUSDOracle: debtNum * loanOracle,
|
|
28059
|
+
stableBorrowRate: String(aprBps / 100),
|
|
28060
|
+
collateralEnabled: false,
|
|
28061
|
+
claimableRewards: 0,
|
|
28062
|
+
// Fixed-term loan detail — `loanId = bidId` is the repayLoanFull target.
|
|
28063
|
+
term: {
|
|
28064
|
+
loanId: b.bidId,
|
|
28065
|
+
isDynamic: false,
|
|
28066
|
+
debt: debtStr,
|
|
28067
|
+
apr: aprBps / 100,
|
|
28068
|
+
maturity,
|
|
28069
|
+
accruedInterest: interestStr,
|
|
28070
|
+
isMatured
|
|
28071
|
+
}
|
|
28072
|
+
}
|
|
28073
|
+
};
|
|
28074
|
+
bucket.modes[b.bidId] = 0;
|
|
28075
|
+
bucket.hist[b.bidId] = {
|
|
28076
|
+
totalDeposits24h: collNum * collHist,
|
|
28077
|
+
totalDebt24h: debtNum * loanHist
|
|
28078
|
+
};
|
|
28079
|
+
});
|
|
28080
|
+
const out = {};
|
|
28081
|
+
for (const [lenderKey, bucket] of Object.entries(perPool)) {
|
|
28082
|
+
if (Object.keys(bucket.positions).length === 0) continue;
|
|
28083
|
+
const userData = createMultiAccountTypeUserState(
|
|
28084
|
+
{
|
|
28085
|
+
chainId,
|
|
28086
|
+
account,
|
|
28087
|
+
lendingPositions: bucket.positions,
|
|
28088
|
+
modes: bucket.modes
|
|
28089
|
+
},
|
|
28090
|
+
bucket.metaMap,
|
|
28091
|
+
bucket.hist
|
|
28092
|
+
);
|
|
28093
|
+
if (userData && userData.data.length > 0) out[lenderKey] = userData;
|
|
28094
|
+
}
|
|
28095
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
28096
|
+
},
|
|
28097
|
+
expected
|
|
28098
|
+
];
|
|
28099
|
+
};
|
|
28100
|
+
|
|
27478
28101
|
// src/lending/user-data/fetch-balances/parse.ts
|
|
27479
28102
|
function getUserDataConverter(lender, chainId, account, params, meta) {
|
|
27480
28103
|
if (isAaveV4Type(lender))
|
|
@@ -27505,6 +28128,8 @@ function getUserDataConverter(lender, chainId, account, params, meta) {
|
|
|
27505
28128
|
return getLiquityUserDataConverter(lender, chainId, account, meta);
|
|
27506
28129
|
if (isRiver(lender))
|
|
27507
28130
|
return getRiverUserDataConverter(lender, chainId, account, meta);
|
|
28131
|
+
if (isTeller(lender))
|
|
28132
|
+
return getTellerUserDataConverter(lender, chainId, account, meta);
|
|
27508
28133
|
if (isCompoundV3Type(lender))
|
|
27509
28134
|
return getCompoundV3UserDataConverter(
|
|
27510
28135
|
lender,
|
|
@@ -32276,6 +32901,8 @@ var getAbi2 = (lender) => {
|
|
|
32276
32901
|
];
|
|
32277
32902
|
if (isRiver(lender))
|
|
32278
32903
|
return [...RiverTroveManagerAbi, ...RiverStabilityPoolAbi];
|
|
32904
|
+
if (isTeller(lender))
|
|
32905
|
+
return [...TellerV2Abi, ...TellerCollateralManagerAbi];
|
|
32279
32906
|
if (isInit(lender)) return InitLensAbi;
|
|
32280
32907
|
if (isEulerType(lender)) return accountLensAbi;
|
|
32281
32908
|
if (isCompoundV2Type(lender))
|
|
@@ -32829,7 +33456,7 @@ var MORPHO_API_CHAIN_IDS = {
|
|
|
32829
33456
|
[Chain.UNICHAIN]: 130
|
|
32830
33457
|
};
|
|
32831
33458
|
var FETCH_TIMEOUT_MS = 3e3;
|
|
32832
|
-
var
|
|
33459
|
+
var CACHE_TTL_MS3 = 2e3;
|
|
32833
33460
|
var buildSubgraphQuery = (account) => `
|
|
32834
33461
|
{
|
|
32835
33462
|
account(id: "${account.toLowerCase()}") {
|
|
@@ -32884,11 +33511,11 @@ async function fetchJsonWithProxyFallback(url, body, proxyConfig) {
|
|
|
32884
33511
|
}
|
|
32885
33512
|
var inflight = /* @__PURE__ */ new Map();
|
|
32886
33513
|
var resolved = /* @__PURE__ */ new Map();
|
|
32887
|
-
function
|
|
33514
|
+
function cacheKey3(chainId, account) {
|
|
32888
33515
|
return `${chainId}:${account.toLowerCase()}`;
|
|
32889
33516
|
}
|
|
32890
33517
|
async function dedupedFetch(chainId, account, loader) {
|
|
32891
|
-
const key =
|
|
33518
|
+
const key = cacheKey3(chainId, account);
|
|
32892
33519
|
const now = Date.now();
|
|
32893
33520
|
const cached = resolved.get(key);
|
|
32894
33521
|
if (cached && cached.expiresAt > now) {
|
|
@@ -32897,7 +33524,7 @@ async function dedupedFetch(chainId, account, loader) {
|
|
|
32897
33524
|
const existing = inflight.get(key);
|
|
32898
33525
|
if (existing) return existing;
|
|
32899
33526
|
const promise = loader().then((value) => {
|
|
32900
|
-
resolved.set(key, { value, expiresAt: Date.now() +
|
|
33527
|
+
resolved.set(key, { value, expiresAt: Date.now() + CACHE_TTL_MS3 });
|
|
32901
33528
|
return value;
|
|
32902
33529
|
}).finally(() => {
|
|
32903
33530
|
inflight.delete(key);
|
|
@@ -33029,8 +33656,8 @@ function calculateOverallNetApr(totalDepositsUSD, totalDebtUSD, avgDepositApr, a
|
|
|
33029
33656
|
return (totalDepositsUSD * avgDepositApr - totalDebtUSD * avgBorrowApr) / Math.abs(totalNetWorth) * (totalNetWorth > 0 ? 1 : -1);
|
|
33030
33657
|
}
|
|
33031
33658
|
function calculateWeightedAprs(items) {
|
|
33032
|
-
const wa = (
|
|
33033
|
-
items.filter((i) => i[weightField] !== 0).map((i) => ({ value: i[
|
|
33659
|
+
const wa = (field9, weightField) => calculateWeightedAverage(
|
|
33660
|
+
items.filter((i) => i[weightField] !== 0).map((i) => ({ value: i[field9], weight: Math.abs(i[weightField]) }))
|
|
33034
33661
|
);
|
|
33035
33662
|
return {
|
|
33036
33663
|
apr: wa("apr", "nav"),
|
|
@@ -34769,8 +35396,8 @@ var TIMEOUT_MS = 8e3;
|
|
|
34769
35396
|
var slisBnbFetcher = {
|
|
34770
35397
|
label: "SLISBNB",
|
|
34771
35398
|
fetch: async () => {
|
|
34772
|
-
const
|
|
34773
|
-
const url = `${HISTORY_URL}?name=slisBNBRate&cycle=1&startTime=${
|
|
35399
|
+
const nowSec7 = Math.floor(Date.now() / 1e3);
|
|
35400
|
+
const url = `${HISTORY_URL}?name=slisBNBRate&cycle=1&startTime=${nowSec7 - LOOKBACK_SECONDS}&endTime=${nowSec7}`;
|
|
34774
35401
|
const controller = new AbortController();
|
|
34775
35402
|
const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);
|
|
34776
35403
|
try {
|
|
@@ -39050,6 +39677,84 @@ var riverFetcher = {
|
|
|
39050
39677
|
parse: parseRiverResults,
|
|
39051
39678
|
getAbi: getRiverAbi
|
|
39052
39679
|
};
|
|
39680
|
+
function getTellerCalls(chainId) {
|
|
39681
|
+
const pools = tellerPoolsByChain(chainId);
|
|
39682
|
+
if (pools.length === 0) return [];
|
|
39683
|
+
const results = [];
|
|
39684
|
+
for (const p of pools) {
|
|
39685
|
+
if (!p.pool || !p.principal || !p.collateral) continue;
|
|
39686
|
+
const onePrincipal = 10n ** BigInt(p.principalDecimals);
|
|
39687
|
+
const calls = [
|
|
39688
|
+
{
|
|
39689
|
+
address: p.pool,
|
|
39690
|
+
name: "calculateCollateralTokensAmountEquivalentToPrincipalTokens",
|
|
39691
|
+
params: [onePrincipal]
|
|
39692
|
+
}
|
|
39693
|
+
];
|
|
39694
|
+
results.push({
|
|
39695
|
+
calls,
|
|
39696
|
+
meta: {
|
|
39697
|
+
pool: p.pool.toLowerCase(),
|
|
39698
|
+
principal: p.principal.toLowerCase(),
|
|
39699
|
+
principalDecimals: p.principalDecimals,
|
|
39700
|
+
collateral: p.collateral.toLowerCase(),
|
|
39701
|
+
collateralDecimals: p.collateralDecimals
|
|
39702
|
+
},
|
|
39703
|
+
lender: tellerLenderKey(p.pool)
|
|
39704
|
+
});
|
|
39705
|
+
}
|
|
39706
|
+
return results;
|
|
39707
|
+
}
|
|
39708
|
+
function parseTellerResults(data, meta, context) {
|
|
39709
|
+
const { chainId, usdPrices, tokenList } = context;
|
|
39710
|
+
const entries = [];
|
|
39711
|
+
const principal = meta.principal;
|
|
39712
|
+
const collateral = meta.collateral;
|
|
39713
|
+
const lenderKey = tellerLenderKey(meta.pool);
|
|
39714
|
+
const principalOracleKey = tokenList?.[principal]?.assetGroup ?? `${chainId}-${principal}`;
|
|
39715
|
+
const principalUSD = usdPrices[principalOracleKey] ?? usdPrices[principal];
|
|
39716
|
+
if (!principalUSD) return entries;
|
|
39717
|
+
entries.push({
|
|
39718
|
+
asset: principal,
|
|
39719
|
+
price: 1,
|
|
39720
|
+
priceUSD: principalUSD,
|
|
39721
|
+
marketUid: createMarketUid(chainId, lenderKey, principal),
|
|
39722
|
+
targetLender: lenderKey,
|
|
39723
|
+
description: "Teller principal asset",
|
|
39724
|
+
staticBase: true,
|
|
39725
|
+
baseAsset: principal
|
|
39726
|
+
});
|
|
39727
|
+
const rawCollateral = data?.[0];
|
|
39728
|
+
if (rawCollateral == null || rawCollateral === "0x") return entries;
|
|
39729
|
+
let equivalent;
|
|
39730
|
+
try {
|
|
39731
|
+
equivalent = BigInt(rawCollateral);
|
|
39732
|
+
} catch {
|
|
39733
|
+
return entries;
|
|
39734
|
+
}
|
|
39735
|
+
if (equivalent <= 0n) return entries;
|
|
39736
|
+
const collateralDecimals = meta.collateralDecimals ?? tokenList?.[collateral]?.decimals ?? 18;
|
|
39737
|
+
const priceCollateralInPrincipal = 10 ** collateralDecimals / Number(equivalent);
|
|
39738
|
+
if (!(priceCollateralInPrincipal > 0)) return entries;
|
|
39739
|
+
entries.push({
|
|
39740
|
+
asset: collateral,
|
|
39741
|
+
price: priceCollateralInPrincipal,
|
|
39742
|
+
// raw: collateral price in principal terms
|
|
39743
|
+
priceUSD: priceCollateralInPrincipal * principalUSD,
|
|
39744
|
+
marketUid: createMarketUid(chainId, lenderKey, collateral),
|
|
39745
|
+
targetLender: lenderKey,
|
|
39746
|
+
baseAsset: principal
|
|
39747
|
+
});
|
|
39748
|
+
return entries;
|
|
39749
|
+
}
|
|
39750
|
+
function getTellerAbi() {
|
|
39751
|
+
return LenderCommitmentGroupAbi;
|
|
39752
|
+
}
|
|
39753
|
+
var tellerFetcher = {
|
|
39754
|
+
getCalls: getTellerCalls,
|
|
39755
|
+
parse: parseTellerResults,
|
|
39756
|
+
getAbi: getTellerAbi
|
|
39757
|
+
};
|
|
39053
39758
|
var CompoundV2OracleAbi = [
|
|
39054
39759
|
{
|
|
39055
39760
|
inputs: [{ internalType: "address", name: "cToken", type: "address" }],
|
|
@@ -40665,6 +41370,11 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
40665
41370
|
() => riverFetcher.getCalls(chainId),
|
|
40666
41371
|
getCallsErrors
|
|
40667
41372
|
) : [];
|
|
41373
|
+
const tellerResults = isActive("teller") ? safeGetCalls(
|
|
41374
|
+
"teller",
|
|
41375
|
+
() => tellerFetcher.getCalls(chainId),
|
|
41376
|
+
getCallsErrors
|
|
41377
|
+
) : [];
|
|
40668
41378
|
const siloV2Results = isActive("silov2") ? safeGetCalls(
|
|
40669
41379
|
"siloV2",
|
|
40670
41380
|
() => siloV2Fetcher.getCalls(chainId),
|
|
@@ -40762,6 +41472,12 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
40762
41472
|
riverFetcher.parse,
|
|
40763
41473
|
getRiverAbi()
|
|
40764
41474
|
);
|
|
41475
|
+
const tellerGroup = buildGroup(
|
|
41476
|
+
"teller",
|
|
41477
|
+
tellerResults,
|
|
41478
|
+
tellerFetcher.parse,
|
|
41479
|
+
getTellerAbi()
|
|
41480
|
+
);
|
|
40765
41481
|
const siloV2Group = buildGroup(
|
|
40766
41482
|
"siloV2",
|
|
40767
41483
|
siloV2Results,
|
|
@@ -40805,6 +41521,7 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
40805
41521
|
termGroup,
|
|
40806
41522
|
liquityGroup,
|
|
40807
41523
|
riverGroup,
|
|
41524
|
+
tellerGroup,
|
|
40808
41525
|
siloV2Group,
|
|
40809
41526
|
siloV3Group,
|
|
40810
41527
|
fluidGroup,
|
|
@@ -40845,6 +41562,7 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
40845
41562
|
termData,
|
|
40846
41563
|
liquityData,
|
|
40847
41564
|
riverData,
|
|
41565
|
+
tellerData,
|
|
40848
41566
|
morphoGqlEntries,
|
|
40849
41567
|
siloV2GqlEntries,
|
|
40850
41568
|
siloV3GqlEntries
|
|
@@ -40961,6 +41679,14 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
40961
41679
|
allowFailure,
|
|
40962
41680
|
rpcOverrides
|
|
40963
41681
|
),
|
|
41682
|
+
executeGroup(
|
|
41683
|
+
tellerGroup,
|
|
41684
|
+
chainId,
|
|
41685
|
+
chainBatchSize,
|
|
41686
|
+
retries,
|
|
41687
|
+
allowFailure,
|
|
41688
|
+
rpcOverrides
|
|
41689
|
+
),
|
|
40964
41690
|
morphoGqlPromise,
|
|
40965
41691
|
siloV2GqlPromise,
|
|
40966
41692
|
siloV3GqlPromise
|
|
@@ -41012,6 +41738,7 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
41012
41738
|
{ group: gearboxV3Group, data: gearboxV3Data },
|
|
41013
41739
|
{ group: dolomiteGroup, data: dolomiteData },
|
|
41014
41740
|
{ group: midnightGroup, data: midnightData },
|
|
41741
|
+
{ group: tellerGroup, data: tellerData },
|
|
41015
41742
|
...siloV2GqlEntries != null ? [] : [{ group: siloV2Group, data: siloV2Data }],
|
|
41016
41743
|
...siloV3GqlEntries != null ? [] : [{ group: siloV3Group, data: siloV3Data }],
|
|
41017
41744
|
// In hybrid mode the on-chain multicall ran too — surface its errors.
|
|
@@ -41210,6 +41937,7 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
41210
41937
|
parseTrackers(morphoGroup, morphoData.results, false);
|
|
41211
41938
|
}
|
|
41212
41939
|
parseTrackers(midnightGroup, midnightData.results, false);
|
|
41940
|
+
parseTrackers(tellerGroup, tellerData.results, false);
|
|
41213
41941
|
const totalFailedCalls = trackerDiags.reduce(
|
|
41214
41942
|
(sum, d) => sum + d.failedCalls,
|
|
41215
41943
|
0
|
|
@@ -41375,10 +42103,10 @@ function createAssetArrayPerChain() {
|
|
|
41375
42103
|
return assetsPerChain;
|
|
41376
42104
|
}
|
|
41377
42105
|
var RELEVANT_LENDING_ASSETS = () => createAssetArrayPerChain();
|
|
41378
|
-
function createSimpleArrayPerChain(fork,
|
|
42106
|
+
function createSimpleArrayPerChain(fork, field9 = void 0) {
|
|
41379
42107
|
let pools = {};
|
|
41380
42108
|
Object.entries(fork ?? {}).forEach(([b2, data]) => {
|
|
41381
|
-
Object.entries(
|
|
42109
|
+
Object.entries(field9 ? data[field9] : data).forEach(
|
|
41382
42110
|
([chainId, address]) => {
|
|
41383
42111
|
if (!pools[chainId]) pools[chainId] = [];
|
|
41384
42112
|
pools[chainId] = uniq2([...pools[chainId], { address, pool: b2 }]);
|
|
@@ -43587,9 +44315,9 @@ query EvkByAssets($assets: [Bytes!]!) {
|
|
|
43587
44315
|
`;
|
|
43588
44316
|
var ZERO = 0n;
|
|
43589
44317
|
var RAY_TO_PERCENT3 = 1e25;
|
|
43590
|
-
function readAddress2(
|
|
43591
|
-
if (!
|
|
43592
|
-
return
|
|
44318
|
+
function readAddress2(field9) {
|
|
44319
|
+
if (!field9) return void 0;
|
|
44320
|
+
return field9.toLowerCase();
|
|
43593
44321
|
}
|
|
43594
44322
|
function parseVaultFee(v) {
|
|
43595
44323
|
if (v.performanceFee == null) return 0;
|
|
@@ -50609,23 +51337,23 @@ var priceGmMarkets = async (chainId, multicallRetry, markets, prices) => {
|
|
|
50609
51337
|
const indexMax = price(prices, m.indexToken)?.max;
|
|
50610
51338
|
if (Array.isArray(dsRes) && longMax != null && shortMax != null) {
|
|
50611
51339
|
const base = i * SLOTS;
|
|
50612
|
-
const
|
|
51340
|
+
const big4 = (j) => typeof dsRes[base + j] === "bigint" ? dsRes[base + j] : 0n;
|
|
50613
51341
|
const cap = computeDepositCapacityUsd(
|
|
50614
|
-
[info?.longTokenAmount, longMax,
|
|
50615
|
-
[info?.shortTokenAmount, shortMax,
|
|
51342
|
+
[info?.longTokenAmount, longMax, big4(0), big4(2)],
|
|
51343
|
+
[info?.shortTokenAmount, shortMax, big4(1), big4(3)]
|
|
50616
51344
|
);
|
|
50617
51345
|
if (cap != null) value.depositCapacityUsd = cap;
|
|
50618
51346
|
if (indexMax != null) {
|
|
50619
51347
|
const divisor = m.longToken.toLowerCase() === m.shortToken.toLowerCase() ? 2n : 1n;
|
|
50620
|
-
const reservedUsdLong = (
|
|
50621
|
-
const reservedUsdShort = (
|
|
51348
|
+
const reservedUsdLong = (big4(4) + big4(5)) / divisor * indexMax;
|
|
51349
|
+
const reservedUsdShort = (big4(6) + big4(7)) / divisor;
|
|
50622
51350
|
const liq = computeLiquidityUsd(
|
|
50623
51351
|
info?.longTokenUsd,
|
|
50624
51352
|
info?.shortTokenUsd,
|
|
50625
51353
|
reservedUsdLong,
|
|
50626
51354
|
reservedUsdShort,
|
|
50627
|
-
|
|
50628
|
-
|
|
51355
|
+
big4(8),
|
|
51356
|
+
big4(9)
|
|
50629
51357
|
);
|
|
50630
51358
|
if (liq != null)
|
|
50631
51359
|
value.liquidityUsd = Math.max(0, Math.min(liq, value.tvlUsd));
|
|
@@ -50824,21 +51552,21 @@ var fetchGmxExecutionFees = async (chainId, multicallRetry, gasPriceWei) => {
|
|
|
50824
51552
|
} catch {
|
|
50825
51553
|
return void 0;
|
|
50826
51554
|
}
|
|
50827
|
-
const
|
|
50828
|
-
const base =
|
|
50829
|
-
const mult =
|
|
51555
|
+
const big4 = (i) => typeof res[i] === "bigint" ? res[i] : 0n;
|
|
51556
|
+
const base = big4(0);
|
|
51557
|
+
const mult = big4(1);
|
|
50830
51558
|
if (base === 0n && mult === 0n) return void 0;
|
|
50831
51559
|
const PRECISION = 10n ** 30n;
|
|
50832
51560
|
const adjusted = (opGas) => base + opGas * mult / PRECISION;
|
|
50833
51561
|
const fee = (opGas) => (adjusted(opGas) * gasPriceWei).toString();
|
|
50834
|
-
const glvExtra =
|
|
51562
|
+
const glvExtra = big4(6) * GLV_NOMINAL_MARKET_COUNT;
|
|
50835
51563
|
return {
|
|
50836
51564
|
chainId,
|
|
50837
51565
|
gasPriceWei: gasPriceWei.toString(),
|
|
50838
|
-
deposit: fee(
|
|
50839
|
-
withdrawal: fee(
|
|
50840
|
-
glvDeposit: fee(
|
|
50841
|
-
glvWithdrawal: fee(
|
|
51566
|
+
deposit: fee(big4(2)),
|
|
51567
|
+
withdrawal: fee(big4(3)),
|
|
51568
|
+
glvDeposit: fee(big4(4) + glvExtra),
|
|
51569
|
+
glvWithdrawal: fee(big4(5) + glvExtra)
|
|
50842
51570
|
};
|
|
50843
51571
|
};
|
|
50844
51572
|
|
|
@@ -52044,6 +52772,6 @@ async function fetchTokenBalances(chainId, account, tokens, options = {}) {
|
|
|
52044
52772
|
return parseTokenBalanceResult(rawResult, prepared.query);
|
|
52045
52773
|
}
|
|
52046
52774
|
|
|
52047
|
-
export { ApiBookSource, DEFAULT_MIDNIGHT_API, EMPTY_BALANCE, GMX_API_HOSTS, GMX_READ_CONTRACTS, GMX_SUPPORTED_CHAINS, HYPERCORE_VAULT_REGISTRY, IDLE_MARKET_ID, INTERFACE_IDS, LAGOON_API_URL, LAGOON_CHAIN_IDS, MORPHO_LENS, MaxParamThresholds, STABLECOIN_SYMBOLS, STCELO_MANAGER_ADDRESS, TermSubgraphSource, UPSHIFT_CHAIN_IDS, UPSHIFT_VAULTS_URL, VAULT_SHARE_PRICE_PROBE, VOLATILE_VAULT_OVERRIDES, YEARN_CHAIN_IDS, YEARN_YDAEMON_BASE, accountDepositListKey, accountWithdrawalListKey, appendSnapshot, applyPositionDelta, attachPricesToFlashLiquidity, buildFluidFTokensCall, buildLiquityUserCall, buildLoopResult, buildMorphoTypeCall, buildMorphoTypeUserCallWithLens, buildPortfolioTotals, buildSumerAccumulators, buildSummaries, buildVaultLookup, calculateLeverage, calculateNetApr, calculateOverallNetApr, calculateWeightedAverage, classifyVault, computeBorrowDelta2 as computeBorrowDelta, computeCloseTradeDeltas, computeCollateralSwapDeltas, computeDebtSwapDeltas, computeDepositDelta2 as computeDepositDelta, computeEModeAnalysis, computeOpenTradeDeltas, computePostTradeMetrics, computeRepayDelta2 as computeRepayDelta, computeSumerBorrowDelta, computeSumerDepositDelta, computeSumerRepayDelta, computeSumerWaterfall, computeSumerWithdrawDelta, computeVaultApr, computeWithdrawDelta2 as computeWithdrawDelta, computeZapTradeDeltas, convertExactlyMarketsToResponse, convertLenderUserDataResult, convertLiquityMarketsToResponse, convertRiverMarketsToResponse, convertTermMarketsToResponse, createMarketUid, createMidnightBookSource, createMulticallRpcCall, createRawRpcCalls, createTermBookSource, decodeListaMarkets, decodeMarkets, decodePackedListaUserDataset, decodePackedMorphoUserDataset, detectInterfaceKinds, encodeBalanceFetcherCalldata, exactlyLenderKey, exactlyMarketFromLenderKey, exactlyPairLtv, exactlyPenaltyRateToAprPercent, exactlyWadRateToPercent, fetchDolomiteAccountNumbers, fetchEulerEarnVaults, fetchEulerEarnVaultsFromSubgraph, fetchEulerSubAccountIndexes, fetchExactlyMarkets, fetchFlashLiquidityForChain, fetchFluidFTokens, fetchGeneralYields, fetchGeneralYieldsByMarketUid, fetchGmxExecutionFees, fetchGmxTickerPrices, fetchGmxVaults, fetchHypercoreVaults, fetchLagoonApiVaults, fetchLagoonVaults, fetchLiquityMarkets, fetchListaVaultsFromChain, fetchMorphoUserBalances, fetchMorphoUserPositionMarkets, fetchMorphoVaults, fetchMorphoVaultsFromApi, fetchMorphoVaultsFromChain, fetchOraclePrices, fetchPendlePrices, fetchRiverMarkets, fetchSiloVaults, fetchTermMarkets, fetchTokenBalances, fetchTokenMetadata, fetchUpshiftApiVaults, fetchUpshiftVaults, fetchYearnApiVaults, fetchYearnVaults, filterActiveLenders, filterLendersByProtocol, fuseLenderData, generateLendingPools, getAavesForChain, getAssetConfig, getBalanceForMarketUid, getBorrowCapacity, getCachedLiquityTroves, getCoreValidators, getFluidFTokensConverter, getGmxApiHost, getGmxReadContracts, getGmxUserPositions, getHealthFactor, getHypercoreUserPositions, getHypercoreVaultRegistry, getLenderAssets, getLenderPublicData, getLenderPublicDataAll, getLenderPublicDataViaApi, getLenderUserDataMulti, getLenderUserDataResult, getLendersForChain, getLstDelegation, getLstValidators, getLstWithdrawalRegistry, getLstWithdrawalRequests, getMaxAmountClose, getMaxAmountCollateralSwap, getMaxAmountDebtSwap, getMaxAmountOpen, getMergedUserData, getMorphoTypeMarketConverter, getResolvedDolomiteAccountNumbers, getStCeloValidatorGroups, getSubAccountAddress, getSubAccountIndex, getVaultPublicDataAll, getVaultWithdrawalRequests, hasEulerEarnVaultSubgraph, hasLagoonVaults, hasMorphoPositionIndex, hasMorphoUserApi, hasMorphoUserSubgraph, hasUpshiftVaults, hasYearnVaults, isStablecoinSymbol, isYearnV3, keysFromMaps, liquityCandidateTroveIds, liquityKeyParts, liquityLenderKey, multicall3Abi, nanTo, needsLenderApproval, needsTokenApproval, noOpResult, normalizeToBytes, parseBalanceFetcherResult, parseMergedResult, parseMulticallRpcResponses, parseRawRpcBatchResponses, parseRawRpcResponses, parseTokenBalanceResult, positivePart2 as positivePart, prepareLenderUserDataRpcCalls, prepareMergedMulticallParams, prepareMergedRpcCalls, prepareMulticallInputs, prepareTokenBalanceRpcCalls, priceGlvVaults, priceGmMarkets, readVaultSharePrices, resolveStCeloDepositGroup, riverKeyParts, riverLenderKey, selectAssetGroupPrices, stampVaultClassification, termLenderKey, tickToAprNumber, tickToPrice, unflattenLenderData };
|
|
52775
|
+
export { ApiBookSource, DEFAULT_MIDNIGHT_API, EMPTY_BALANCE, GMX_API_HOSTS, GMX_READ_CONTRACTS, GMX_SUPPORTED_CHAINS, HYPERCORE_VAULT_REGISTRY, IDLE_MARKET_ID, INTERFACE_IDS, LAGOON_API_URL, LAGOON_CHAIN_IDS, MORPHO_LENS, MaxParamThresholds, STABLECOIN_SYMBOLS, STCELO_MANAGER_ADDRESS, TELLER_CALLS_PER_BID, TermSubgraphSource, UPSHIFT_CHAIN_IDS, UPSHIFT_VAULTS_URL, VAULT_SHARE_PRICE_PROBE, VOLATILE_VAULT_OVERRIDES, YEARN_CHAIN_IDS, YEARN_YDAEMON_BASE, accountDepositListKey, accountWithdrawalListKey, appendSnapshot, applyPositionDelta, attachPricesToFlashLiquidity, buildFluidFTokensCall, buildLiquityUserCall, buildLoopResult, buildMorphoTypeCall, buildMorphoTypeUserCallWithLens, buildPortfolioTotals, buildSumerAccumulators, buildSummaries, buildTellerUserCall, buildVaultLookup, calculateLeverage, calculateNetApr, calculateOverallNetApr, calculateWeightedAverage, classifyVault, computeBorrowDelta2 as computeBorrowDelta, computeCloseTradeDeltas, computeCollateralSwapDeltas, computeDebtSwapDeltas, computeDepositDelta2 as computeDepositDelta, computeEModeAnalysis, computeOpenTradeDeltas, computePostTradeMetrics, computeRepayDelta2 as computeRepayDelta, computeSumerBorrowDelta, computeSumerDepositDelta, computeSumerRepayDelta, computeSumerWaterfall, computeSumerWithdrawDelta, computeVaultApr, computeWithdrawDelta2 as computeWithdrawDelta, computeZapTradeDeltas, convertExactlyMarketsToResponse, convertLenderUserDataResult, convertLiquityMarketsToResponse, convertRiverMarketsToResponse, convertTellerMarketsToResponse, convertTermMarketsToResponse, createMarketUid, createMidnightBookSource, createMulticallRpcCall, createRawRpcCalls, createTermBookSource, decodeListaMarkets, decodeMarkets, decodePackedListaUserDataset, decodePackedMorphoUserDataset, detectInterfaceKinds, encodeBalanceFetcherCalldata, exactlyLenderKey, exactlyMarketFromLenderKey, exactlyPairLtv, exactlyPenaltyRateToAprPercent, exactlyWadRateToPercent, fetchDolomiteAccountNumbers, fetchEulerEarnVaults, fetchEulerEarnVaultsFromSubgraph, fetchEulerSubAccountIndexes, fetchExactlyMarkets, fetchFlashLiquidityForChain, fetchFluidFTokens, fetchGeneralYields, fetchGeneralYieldsByMarketUid, fetchGmxExecutionFees, fetchGmxTickerPrices, fetchGmxVaults, fetchHypercoreVaults, fetchLagoonApiVaults, fetchLagoonVaults, fetchLiquityMarkets, fetchListaVaultsFromChain, fetchMorphoUserBalances, fetchMorphoUserPositionMarkets, fetchMorphoVaults, fetchMorphoVaultsFromApi, fetchMorphoVaultsFromChain, fetchOraclePrices, fetchPendlePrices, fetchRiverMarkets, fetchSiloVaults, fetchTellerMarkets, fetchTermMarkets, fetchTokenBalances, fetchTokenMetadata, fetchUpshiftApiVaults, fetchUpshiftVaults, fetchYearnApiVaults, fetchYearnVaults, filterActiveLenders, filterLendersByProtocol, fuseLenderData, generateLendingPools, getAavesForChain, getAssetConfig, getBalanceForMarketUid, getBorrowCapacity, getCachedLiquityTroves, getCachedTellerBids, getCoreValidators, getFluidFTokensConverter, getGmxApiHost, getGmxReadContracts, getGmxUserPositions, getHealthFactor, getHypercoreUserPositions, getHypercoreVaultRegistry, getLenderAssets, getLenderPublicData, getLenderPublicDataAll, getLenderPublicDataViaApi, getLenderUserDataMulti, getLenderUserDataResult, getLendersForChain, getLstDelegation, getLstValidators, getLstWithdrawalRegistry, getLstWithdrawalRequests, getMaxAmountClose, getMaxAmountCollateralSwap, getMaxAmountDebtSwap, getMaxAmountOpen, getMergedUserData, getMorphoTypeMarketConverter, getResolvedDolomiteAccountNumbers, getStCeloValidatorGroups, getSubAccountAddress, getSubAccountIndex, getVaultPublicDataAll, getVaultWithdrawalRequests, hasEulerEarnVaultSubgraph, hasLagoonVaults, hasMorphoPositionIndex, hasMorphoUserApi, hasMorphoUserSubgraph, hasUpshiftVaults, hasYearnVaults, isStablecoinSymbol, isYearnV3, keysFromMaps, liquityCandidateTroveIds, liquityKeyParts, liquityLenderKey, multicall3Abi, nanTo, needsLenderApproval, needsTokenApproval, noOpResult, normalizeToBytes, parseBalanceFetcherResult, parseMergedResult, parseMulticallRpcResponses, parseRawRpcBatchResponses, parseRawRpcResponses, parseTokenBalanceResult, positivePart2 as positivePart, prepareLenderUserDataRpcCalls, prepareMergedMulticallParams, prepareMergedRpcCalls, prepareMulticallInputs, prepareTokenBalanceRpcCalls, priceGlvVaults, priceGmMarkets, readVaultSharePrices, resolveStCeloDepositGroup, riverKeyParts, riverLenderKey, selectAssetGroupPrices, stampVaultClassification, tellerBpsToPercent, tellerImpliedLtv, tellerLenderKey, tellerPoolFromLenderKey, termLenderKey, tickToAprNumber, tickToPrice, unflattenLenderData };
|
|
52048
52776
|
//# sourceMappingURL=index.js.map
|
|
52049
52777
|
//# sourceMappingURL=index.js.map
|