@1delta/margin-fetcher 0.0.239 → 0.0.242

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.js CHANGED
@@ -1,4 +1,4 @@
1
- import { parseAbi, formatEther, BaseError, encodeFunctionData, formatUnits, decodeFunctionResult, decodeAbiParameters, AbiEncodingLengthMismatchError, concatHex, isAddress, InvalidAddressError, pad, stringToHex, boolToHex, integerRegex, numberToHex, bytesRegex, BytesSizeMismatchError, arrayRegex, UnsupportedPackedAbiType } from './chunk-ZVIJSUIM.js';
1
+ import { parseAbi, formatEther, BaseError, encodeFunctionData, formatUnits, decodeFunctionResult, decodeAbiParameters, AbiEncodingLengthMismatchError, concatHex, isAddress, InvalidAddressError, pad, stringToHex, boolToHex, integerRegex, numberToHex, bytesRegex, BytesSizeMismatchError, arrayRegex, UnsupportedPackedAbiType } from './chunk-KQ6K6D2V.js';
2
2
  import './chunk-BYTNVMX7.js';
3
3
  import './chunk-PR4QN5HX.js';
4
4
  import { Lender, isAaveType, isCompoundV3, isMultiMarket, isSiloV2Type, isSiloV3Type, isAaveV4Type, isInit, isMorphoType, isCompoundV2Type, isVenusType, isSumerType, AAVE_V3_LENDERS, AAVE_V2_LENDERS, isAaveV2Type, isAaveV32Type, isAaveV3Type, isEulerType, isFluid, isYLDR, isCompoundV3Type, isLista, isTectonicType, isBenqiType } from '@1delta/lender-registry';
@@ -7997,7 +7997,7 @@ var buildCompoundV3StyleLenderReserveCall = (chainId, lender) => {
7997
7997
  return calls;
7998
7998
  };
7999
7999
 
8000
- // ../../node_modules/.pnpm/viem@2.45.3_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10_zod@4.3.6/node_modules/viem/_esm/utils/abi/encodePacked.js
8000
+ // ../../node_modules/.pnpm/viem@2.45.3_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/utils/abi/encodePacked.js
8001
8001
  function encodePacked(types, values) {
8002
8002
  if (types.length !== values.length)
8003
8003
  throw new AbiEncodingLengthMismatchError({
@@ -8060,7 +8060,7 @@ function encode(type, value, isArray2 = false) {
8060
8060
  throw new UnsupportedPackedAbiType(type);
8061
8061
  }
8062
8062
 
8063
- // ../../node_modules/.pnpm/viem@2.45.3_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10_zod@4.3.6/node_modules/viem/_esm/errors/unit.js
8063
+ // ../../node_modules/.pnpm/viem@2.45.3_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/errors/unit.js
8064
8064
  var InvalidDecimalNumberError = class extends BaseError {
8065
8065
  constructor({ value }) {
8066
8066
  super(`Number \`${value}\` is not a valid decimal number.`, {
@@ -8069,7 +8069,7 @@ var InvalidDecimalNumberError = class extends BaseError {
8069
8069
  }
8070
8070
  };
8071
8071
 
8072
- // ../../node_modules/.pnpm/viem@2.45.3_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10_zod@4.3.6/node_modules/viem/_esm/utils/unit/parseUnits.js
8072
+ // ../../node_modules/.pnpm/viem@2.45.3_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/utils/unit/parseUnits.js
8073
8073
  function parseUnits(value, decimals) {
8074
8074
  if (!/^(-?)([0-9]*)\.?([0-9]*)$/.test(value))
8075
8075
  throw new InvalidDecimalNumberError({ value });
@@ -8104,7 +8104,7 @@ function parseUnits(value, decimals) {
8104
8104
  return BigInt(`${negative ? "-" : ""}${integer}${fraction}`);
8105
8105
  }
8106
8106
 
8107
- // ../../node_modules/.pnpm/viem@2.45.3_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10_zod@4.3.6/node_modules/viem/_esm/constants/address.js
8107
+ // ../../node_modules/.pnpm/viem@2.45.3_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/constants/address.js
8108
8108
  var zeroAddress = "0x0000000000000000000000000000000000000000";
8109
8109
 
8110
8110
  // src/utils/parsing.ts
@@ -19613,6 +19613,9 @@ query GetSilos {
19613
19613
  borrowedUsd
19614
19614
  liquidityUsd
19615
19615
  utilization
19616
+ collateralAssetsSupply
19617
+ collateralAssetsSupplyUsd
19618
+ liquidity
19616
19619
  solvencyOracleAddress
19617
19620
  maxLtvOracleAddress
19618
19621
  interestRateModelId
@@ -19651,6 +19654,9 @@ query GetSilos {
19651
19654
  borrowedUsd
19652
19655
  liquidityUsd
19653
19656
  utilization
19657
+ collateralAssetsSupply
19658
+ collateralAssetsSupplyUsd
19659
+ liquidity
19654
19660
  solvencyOracleAddress
19655
19661
  maxLtvOracleAddress
19656
19662
  interestRateModelId
@@ -19781,18 +19787,18 @@ function convertSiloMarketsToPublicResponse(apiItems, chainId, prices, additiona
19781
19787
  for (const { api, self, other } of sides) {
19782
19788
  const decimals = api.inputToken?.decimals ?? self.decimals;
19783
19789
  const tokenAddrLc = (api.inputTokenId ?? self.token).toLowerCase();
19784
- const totalDeposits = safeNumber(api.supply);
19790
+ const totalDeposits = api.collateralAssetsSupply != null ? safeNumber(api.collateralAssetsSupply) : safeNumber(api.supply);
19785
19791
  const totalDebt = safeNumber(api.borrowed);
19786
- const totalLiquidity = totalDeposits - totalDebt;
19787
- const utilization = totalDeposits > 0 ? totalDebt / totalDeposits : safeNumber(api.utilization);
19792
+ const totalLiquidity = api.liquidity != null ? safeNumber(api.liquidity) : Math.max(totalDeposits - totalDebt, 0);
19793
+ const utilization = api.utilization != null ? safeNumber(api.utilization) : totalDeposits > 0 ? totalDebt / totalDeposits : 0;
19788
19794
  const variableBorrowRatePct = safeNumber(api.borrowRate);
19789
19795
  const depositRatePct = safeNumber(api.depositRate);
19790
19796
  const assetMeta = tokenList[tokenAddrLc];
19791
19797
  const oracleKey = toOracleKey(assetMeta?.assetGroup ?? null) || toGenericPriceKey(tokenAddrLc, chainId);
19792
19798
  const fallbackPrice = prices[oracleKey] ?? 0;
19793
- const totalDepositsUSD = api.supplyUsd != null && api.supplyUsd > 0 ? api.supplyUsd : totalDeposits * fallbackPrice;
19799
+ const totalDepositsUSD = api.collateralAssetsSupplyUsd != null && api.collateralAssetsSupplyUsd > 0 ? api.collateralAssetsSupplyUsd : api.supplyUsd != null && api.supplyUsd > 0 ? api.supplyUsd : totalDeposits * fallbackPrice;
19794
19800
  const totalDebtUSD = api.borrowedUsd != null && api.borrowedUsd > 0 ? api.borrowedUsd : totalDebt * fallbackPrice;
19795
- const totalLiquidityUSD = Math.max(totalDepositsUSD - totalDebtUSD, 0);
19801
+ const totalLiquidityUSD = api.liquidityUsd != null && api.liquidityUsd > 0 ? api.liquidityUsd : Math.max(totalDepositsUSD - totalDebtUSD, 0);
19796
19802
  const otherApi = sides[0].api === api ? apiSide1 : apiSide0;
19797
19803
  const selfLt = bigintToLtv(api.lt ?? self.lt);
19798
19804
  const selfMaxLtv = bigintToLtv(api.maxLtv ?? self.maxLtv);
@@ -19917,18 +19923,18 @@ function convertSiloV3MarketsToPublicResponse(apiItems, chainId, prices, additio
19917
19923
  for (const { api, self, other } of sides) {
19918
19924
  const decimals = api.inputToken?.decimals ?? self.decimals;
19919
19925
  const tokenAddrLc = (api.inputTokenId ?? self.token).toLowerCase();
19920
- const totalDeposits = safeNumber2(api.supply);
19926
+ const totalDeposits = api.collateralAssetsSupply != null ? safeNumber2(api.collateralAssetsSupply) : safeNumber2(api.supply);
19921
19927
  const totalDebt = safeNumber2(api.borrowed);
19922
- const totalLiquidity = totalDeposits - totalDebt;
19923
- const utilization = totalDeposits > 0 ? totalDebt / totalDeposits : safeNumber2(api.utilization);
19928
+ const totalLiquidity = api.liquidity != null ? safeNumber2(api.liquidity) : Math.max(totalDeposits - totalDebt, 0);
19929
+ const utilization = api.utilization != null ? safeNumber2(api.utilization) : totalDeposits > 0 ? totalDebt / totalDeposits : 0;
19924
19930
  const variableBorrowRatePct = safeNumber2(api.borrowRate);
19925
19931
  const depositRatePct = safeNumber2(api.depositRate);
19926
19932
  const assetMeta = tokenList[tokenAddrLc];
19927
19933
  const oracleKey = toOracleKey(assetMeta?.assetGroup ?? null) || toGenericPriceKey(tokenAddrLc, chainId);
19928
19934
  const fallbackPrice = prices[oracleKey] ?? 0;
19929
- const totalDepositsUSD = api.supplyUsd != null && api.supplyUsd > 0 ? api.supplyUsd : totalDeposits * fallbackPrice;
19935
+ const totalDepositsUSD = api.collateralAssetsSupplyUsd != null && api.collateralAssetsSupplyUsd > 0 ? api.collateralAssetsSupplyUsd : api.supplyUsd != null && api.supplyUsd > 0 ? api.supplyUsd : totalDeposits * fallbackPrice;
19930
19936
  const totalDebtUSD = api.borrowedUsd != null && api.borrowedUsd > 0 ? api.borrowedUsd : totalDebt * fallbackPrice;
19931
- const totalLiquidityUSD = Math.max(totalDepositsUSD - totalDebtUSD, 0);
19937
+ const totalLiquidityUSD = api.liquidityUsd != null && api.liquidityUsd > 0 ? api.liquidityUsd : Math.max(totalDepositsUSD - totalDebtUSD, 0);
19932
19938
  const otherApi = sides[0].api === api ? apiSide1 : apiSide0;
19933
19939
  const selfLt = bigintToLtv2(api.lt ?? self.lt);
19934
19940
  const selfMaxLtv = bigintToLtv2(api.maxLtv ?? self.maxLtv);
@@ -29010,6 +29016,7 @@ async function getListsMulti(chainIds) {
29010
29016
 
29011
29017
  // src/yields/intrinsic/fetchers/lido.ts
29012
29018
  var WSTETH_URL = "https://eth-api.lido.fi/v1/protocol/steth/apr/sma";
29019
+ var DEFILLAMA_LIDO_URL = "https://yields.llama.fi/chart/747c1d2a-c668-4682-b9f9-296708a3dd90";
29013
29020
  var tETH = "Treehouse ETH::TETH";
29014
29021
  var robustFetchJson = async (url, { timeoutMs = 5e3, attempts = 3 } = {}) => {
29015
29022
  let lastErr;
@@ -29033,11 +29040,20 @@ var robustFetchJson = async (url, { timeoutMs = 5e3, attempts = 3 } = {}) => {
29033
29040
  }
29034
29041
  throw lastErr;
29035
29042
  };
29043
+ async function fetchLidoApr() {
29044
+ try {
29045
+ const res = await robustFetchJson(WSTETH_URL);
29046
+ return Number(res.data.aprs.at(-1).apr) * 0.9;
29047
+ } catch {
29048
+ const res = await robustFetchJson(DEFILLAMA_LIDO_URL);
29049
+ const latest = res.data.at(-1);
29050
+ return Number(latest.apyBase) * 0.9;
29051
+ }
29052
+ }
29036
29053
  var wstethFetcher = {
29037
29054
  label: "WSTETH",
29038
29055
  fetch: async () => {
29039
- const res = await robustFetchJson(WSTETH_URL);
29040
- const apr = Number(res.data.aprs.at(-1).apr) * 0.9;
29056
+ const apr = await fetchLidoApr();
29041
29057
  return {
29042
29058
  WSTETH: apr,
29043
29059
  [tETH]: apr
@@ -30018,6 +30034,28 @@ var savbtcFetcher = {
30018
30034
  fetch: async () => ({ [sAVBTC]: await fetchAvantApr("savbtc") })
30019
30035
  };
30020
30036
 
30037
+ // src/yields/intrinsic/fetchers/stS.ts
30038
+ var BEETS_URL = "https://backend-v3.beets-ftm-node.com/";
30039
+ var stS = "Beets Staked Sonic::STS";
30040
+ var stsFetcher = {
30041
+ label: "STS",
30042
+ fetch: async () => {
30043
+ const res = await fetch(BEETS_URL, {
30044
+ method: "POST",
30045
+ headers: {
30046
+ Accept: "application/json",
30047
+ "Content-Type": "application/json"
30048
+ },
30049
+ body: JSON.stringify({
30050
+ operationName: "GetStakedSonicData",
30051
+ query: "query GetStakedSonicData { stsGetGqlStakedSonicData { stakingApr } }"
30052
+ })
30053
+ }).then((r) => r.json());
30054
+ const apr = Number(res.data?.stsGetGqlStakedSonicData?.stakingApr) * 100;
30055
+ return { [stS]: apr };
30056
+ }
30057
+ };
30058
+
30021
30059
  // src/yields/intrinsic/index.ts
30022
30060
  async function fetchIntrinsicYields() {
30023
30061
  const wstethPromise = safeFetch(wstethFetcher.label, wstethFetcher.fetch);
@@ -30073,7 +30111,8 @@ async function fetchIntrinsicYields() {
30073
30111
  infinifiFetcher,
30074
30112
  savusdFetcher,
30075
30113
  savethFetcher,
30076
- savbtcFetcher
30114
+ savbtcFetcher,
30115
+ stsFetcher
30077
30116
  ];
30078
30117
  const results = await Promise.all([
30079
30118
  wstethPromise,
@@ -30504,6 +30543,7 @@ function morphoApiAvailable(chainId) {
30504
30543
  if (chainId === Chain.HEMI_NETWORK) return false;
30505
30544
  if (chainId === Chain.BERACHAIN) return false;
30506
30545
  if (chainId === Chain.SEI_NETWORK) return false;
30546
+ if (chainId === Chain.CELO_MAINNET) return false;
30507
30547
  return true;
30508
30548
  }
30509
30549
  function generateMarketId(oracle, loanAsset, collateralAsset) {