@tokemak/queries 0.0.12 → 0.0.13

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 CHANGED
@@ -591,7 +591,8 @@ declare const getChainAutopools: (wagmiConfig: Config, { chainId, prices, }: {
591
591
  symbol: string;
592
592
  logoURI?: string | undefined;
593
593
  description?: string;
594
- type?: "Core" | "Ecosystem" | "Institutional" | undefined;
594
+ type?: "Ecosystem" | "Institutional" | "Flagship" | undefined;
595
+ inactive?: boolean;
595
596
  tvl: number;
596
597
  totalAssets: {
597
598
  denom: number;
@@ -702,6 +703,7 @@ declare const getChainAutopools: (wagmiConfig: Config, { chainId, prices, }: {
702
703
  id: any;
703
704
  } | null;
704
705
  }[] | null | undefined;
706
+ autopoolRewarderDisabled: boolean;
705
707
  createdAt: Date;
706
708
  baseAsset: {
707
709
  price: number;
@@ -800,11 +802,9 @@ declare const getChainAutopools: (wagmiConfig: Config, { chainId, prices, }: {
800
802
  }[];
801
803
  chain: _tokemak_tokenlist.INetwork | undefined;
802
804
  apr: {
803
- base: any;
804
- boosted: number;
805
+ base: number;
805
806
  extraAprs: ExtraReward[];
806
- combined: any;
807
- hasBoostedApr: boolean;
807
+ combined: number;
808
808
  hasExtraAprs: boolean;
809
809
  };
810
810
  dailyEarnings: {
@@ -983,7 +983,8 @@ declare const getAutopools: (wagmiConfig: Config$1, { prices, includeTestnet, }:
983
983
  symbol: string;
984
984
  logoURI?: string | undefined;
985
985
  description?: string;
986
- type?: "Core" | "Ecosystem" | "Institutional" | undefined;
986
+ type?: "Ecosystem" | "Institutional" | "Flagship" | undefined;
987
+ inactive?: boolean;
987
988
  tvl: number;
988
989
  totalAssets: {
989
990
  denom: number;
@@ -1094,6 +1095,7 @@ declare const getAutopools: (wagmiConfig: Config$1, { prices, includeTestnet, }:
1094
1095
  id: any;
1095
1096
  } | null;
1096
1097
  }[] | null | undefined;
1098
+ autopoolRewarderDisabled: boolean;
1097
1099
  createdAt: Date;
1098
1100
  baseAsset: {
1099
1101
  price: number;
@@ -1192,11 +1194,9 @@ declare const getAutopools: (wagmiConfig: Config$1, { prices, includeTestnet, }:
1192
1194
  }[];
1193
1195
  chain: _tokemak_tokenlist.INetwork | undefined;
1194
1196
  apr: {
1195
- base: any;
1196
- boosted: number;
1197
+ base: number;
1197
1198
  extraAprs: ExtraReward[];
1198
- combined: any;
1199
- hasBoostedApr: boolean;
1199
+ combined: number;
1200
1200
  hasExtraAprs: boolean;
1201
1201
  };
1202
1202
  dailyEarnings: {
@@ -1694,15 +1694,17 @@ type UserActivityTotalsType = {
1694
1694
  chainId: SupportedChainIds;
1695
1695
  };
1696
1696
  };
1697
+ type EventType = "Deposit" | "Withdrawal" | "Stake" | "Unstake" | "Unknown";
1697
1698
  declare const getChainUserActivity: (address?: Address, chainId?: SupportedChainIds) => Promise<{
1698
1699
  events: {
1699
1700
  timestamp: number;
1700
1701
  shareChange: string;
1701
1702
  assetChange: string;
1702
1703
  vaultAddress: string;
1704
+ eventType: EventType;
1703
1705
  }[];
1704
1706
  totals: UserActivityTotalsType;
1705
- } | undefined>;
1707
+ }>;
1706
1708
 
1707
1709
  type IUserReward = {
1708
1710
  payload: {
@@ -2307,7 +2309,6 @@ declare const getUserAutopools: ({ address, includeTestnet, autopools, userActiv
2307
2309
  nav: Currencies;
2308
2310
  };
2309
2311
  useDenomination: boolean;
2310
- baseApr: any;
2311
2312
  blendedApr: number;
2312
2313
  rewardsClaimed: any;
2313
2314
  lastDeposit: string | undefined;
@@ -3053,6 +3054,8 @@ type IRebalance = {
3053
3054
  blockNumber: number;
3054
3055
  chainId: number;
3055
3056
  valueInUsd: number;
3057
+ valueInAsset: number;
3058
+ autopool: string;
3056
3059
  };
3057
3060
  type RawRebalance = {
3058
3061
  timestamp: number;
@@ -3064,6 +3067,7 @@ type RawRebalance = {
3064
3067
  };
3065
3068
  tokenOutValueInEth: string;
3066
3069
  tokenOutValueBaseAsset: string;
3070
+ autopool: string;
3067
3071
  };
3068
3072
  declare const fetchChainRebalances: (chainId: number) => Promise<RawRebalance[]>;
3069
3073
  declare const getRebalanceValueUsd: (rebalance: RawRebalance, chainId: number, wagmiConfig: Config$1) => Promise<number | null>;
@@ -3093,4 +3097,53 @@ declare const updateRebalanceStats: (wagmiConfig: Config$1, { currentRebalances,
3093
3097
  rebalances: IRebalance[];
3094
3098
  }>;
3095
3099
 
3096
- export { AggregatedDayData, AutopoolCategory, BASE_ASSETS, BATCH_SIZE, BaseAsset, BaseDataEntry, ChainSTokeRewardsType, ChainSTokeType, ChainSTokeVotes, Currencies, CurveLP, ETH_BASE_ASSETS, EUR_BASE_ASSETS, EnhancedUserHistoryEntry, ExtraReward, FillData, GetLayerzeroStatusConfig, IAutopool, IAutopools, IAutopoolsHistory, IRebalance, IStoke, IStokeRewards, ISushiLP, ITopAutopoolHolder, ITopAutopoolHolders, IUserActivity, IUserAutopool, IUserAutopools, IUserAutopoolsRewards, IUserExtraRewards, IUserReward, LayerzeroStatus, MessageStatus, Order, PRICED_TOKENS, PoolRewardsBalanceDayData, QuoteAndPriceBaseConfig, QuoteAndPriceBaseResult, QuoteResult, RawRebalance, STokeVotes, SendParam, SwapQuoteParams, SwapQuoteResponse, TokenPrices, USD_BASE_ASSETS, UserActivity, UserAutopoolsVotes, UserDayDataEntry, UserSTokeVotes, VaultAddedMapping, aggregateSTokeRewardsDayData, arraysToObject, calculateRebalanceStats, convertBaseAssetToTokenPrices, convertBaseAssetToTokenPricesAndDenom, fetchChainDataMap, fetchChainRebalances, fillMissingDates, findClosestDateEntry, findClosestEntry, findClosestTimestampEntry, formatDateRange, getAddressFromSystemRegistry, getAllowance, getAmountDeposited, getAmountWithdrawn, getAutopilotRouter, getAutopoolCategory, getAutopoolDayData, getAutopoolInfo, getAutopoolRebalances, getAutopools, getAutopoolsHistory, getAutopoolsRebalances, getBridgeFee, getChainAutopools, getChainCycleRolloverBlockNumber, getChainSToke, getChainSTokeRewards, getChainSubgraphStatus, getChainUserActivity, getChainUserAutopools, getChainUserSToke, getChainUserSTokeRewards, getChainUserSTokeVotes, getChainsForEnv, getCurrentCycleId, getCurveLP, getCycleV1, getDefillamaPrice, getDynamicSwap, getEthPrice, getEthPriceAtBlock, getExchangeNames, getGenStratAprs, getLayerzeroStatus, getMutlipleAutopoolRebalances, getPoolStats, getPoolsAndDestinations, getPoolsAndDestinationsReturnType, getProtocolStats, getRebalanceStats, getRebalanceValueUsd, getRewardsPayloadV1, getSToke, getSTokeChainsForEnv, getSTokeRewards, getSTokeVotes, getSubgraphStatus, getSushiLP, getSwapQuote, getSystemConfig, getTimestampDaysFromStart, getTokePrice, getTokenList, getTokenPrice, getTokenPrices, getTopAutopoolHolders, getUserActivity, getUserAutoEthRewards, getUserAutopool, getUserAutopools, getUserAutopoolsHistory, getUserAutopoolsRewards, getUserCurveLP, getUserRewardsV1, getUserSToke, getUserSTokeVotes, getUserSushiLP, getUserTokenBalances, getUserV1, mergeArrays, mergeArraysWithKey, mergeStringArrays, minAmountDepositedBaseConfig, minAmountDepositedFunctionConfig, minAmountWithdrawnBaseConfig, minAmountWithdrawnFunctionConfig, modifyAutopoolName, nestedArrayToObject, paginateQuery, processRebalance, processRebalancesInBatches, rewardsData, systemRegistryFunctionNames, updateRebalanceStats, waitForMessageReceived };
3100
+ type BaseAssetWithUsd = BaseAsset | "USD";
3101
+ type HistoricalPriceEntry = {
3102
+ timestamp: number;
3103
+ date: Date;
3104
+ price: string;
3105
+ };
3106
+ declare const getBlobHistoricalTokenPrices: (tokenSymbol: string) => Promise<HistoricalPriceEntry[]>;
3107
+ declare const getHistoricalTokenPrices: () => Promise<HistoricalTokenPrices[]>;
3108
+ type HistoricalTokenPrices = {
3109
+ timestamp: number;
3110
+ date: Date;
3111
+ prices: {
3112
+ [key in BaseAssetWithUsd]: {
3113
+ [key in BaseAssetWithUsd]: number;
3114
+ };
3115
+ };
3116
+ };
3117
+
3118
+ interface RewardDetails {
3119
+ rewarderAddress: Address;
3120
+ }
3121
+ interface Reward {
3122
+ rewardApy: number;
3123
+ rewardSource: string;
3124
+ rewardToken: Address;
3125
+ rewardTokenSymbol: string;
3126
+ details: RewardDetails;
3127
+ }
3128
+ interface AutopoolsApr {
3129
+ id: Address;
3130
+ symbol: string;
3131
+ name: string;
3132
+ baseAssetId: Address;
3133
+ baseAssetSymbol: string;
3134
+ autopoolRewarderDisabled: boolean;
3135
+ baseApy: number;
3136
+ tvlUsd: number;
3137
+ rewards: Reward[];
3138
+ }
3139
+ interface ChainAutopoolsAprResponse {
3140
+ chainId: string;
3141
+ timestamp: string;
3142
+ processedCount: number;
3143
+ autopools: AutopoolsApr[];
3144
+ }
3145
+ declare const getChainAutopoolsApr: (chainId: number) => Promise<ChainAutopoolsAprResponse | undefined>;
3146
+
3147
+ declare const getBlobData: (blobName: string) => Promise<any>;
3148
+
3149
+ export { AggregatedDayData, AutopoolCategory, AutopoolsApr, BASE_ASSETS, BATCH_SIZE, BaseAsset, BaseAssetWithUsd, BaseDataEntry, ChainAutopoolsAprResponse, ChainSTokeRewardsType, ChainSTokeType, ChainSTokeVotes, Currencies, CurveLP, ETH_BASE_ASSETS, EUR_BASE_ASSETS, EnhancedUserHistoryEntry, ExtraReward, FillData, GetLayerzeroStatusConfig, HistoricalTokenPrices, IAutopool, IAutopools, IAutopoolsHistory, IRebalance, IStoke, IStokeRewards, ISushiLP, ITopAutopoolHolder, ITopAutopoolHolders, IUserActivity, IUserAutopool, IUserAutopools, IUserAutopoolsRewards, IUserExtraRewards, IUserReward, LayerzeroStatus, MessageStatus, Order, PRICED_TOKENS, PoolRewardsBalanceDayData, QuoteAndPriceBaseConfig, QuoteAndPriceBaseResult, QuoteResult, RawRebalance, Reward, RewardDetails, STokeVotes, SendParam, SwapQuoteParams, SwapQuoteResponse, TokenPrices, USD_BASE_ASSETS, UserActivity, UserAutopoolsVotes, UserDayDataEntry, UserSTokeVotes, VaultAddedMapping, aggregateSTokeRewardsDayData, arraysToObject, calculateRebalanceStats, convertBaseAssetToTokenPrices, convertBaseAssetToTokenPricesAndDenom, fetchChainDataMap, fetchChainRebalances, fillMissingDates, findClosestDateEntry, findClosestEntry, findClosestTimestampEntry, formatDateRange, getAddressFromSystemRegistry, getAllowance, getAmountDeposited, getAmountWithdrawn, getAutopilotRouter, getAutopoolCategory, getAutopoolDayData, getAutopoolInfo, getAutopoolRebalances, getAutopools, getAutopoolsHistory, getAutopoolsRebalances, getBlobData, getBlobHistoricalTokenPrices, getBridgeFee, getChainAutopools, getChainAutopoolsApr, getChainCycleRolloverBlockNumber, getChainSToke, getChainSTokeRewards, getChainSubgraphStatus, getChainUserActivity, getChainUserAutopools, getChainUserSToke, getChainUserSTokeRewards, getChainUserSTokeVotes, getChainsForEnv, getCurrentCycleId, getCurveLP, getCycleV1, getDefillamaPrice, getDynamicSwap, getEthPrice, getEthPriceAtBlock, getExchangeNames, getGenStratAprs, getHistoricalTokenPrices, getLayerzeroStatus, getMutlipleAutopoolRebalances, getPoolStats, getPoolsAndDestinations, getPoolsAndDestinationsReturnType, getProtocolStats, getRebalanceStats, getRebalanceValueUsd, getRewardsPayloadV1, getSToke, getSTokeChainsForEnv, getSTokeRewards, getSTokeVotes, getSubgraphStatus, getSushiLP, getSwapQuote, getSystemConfig, getTimestampDaysFromStart, getTokePrice, getTokenList, getTokenPrice, getTokenPrices, getTopAutopoolHolders, getUserActivity, getUserAutoEthRewards, getUserAutopool, getUserAutopools, getUserAutopoolsHistory, getUserAutopoolsRewards, getUserCurveLP, getUserRewardsV1, getUserSToke, getUserSTokeVotes, getUserSushiLP, getUserTokenBalances, getUserV1, mergeArrays, mergeArraysWithKey, mergeStringArrays, minAmountDepositedBaseConfig, minAmountDepositedFunctionConfig, minAmountWithdrawnBaseConfig, minAmountWithdrawnFunctionConfig, modifyAutopoolName, nestedArrayToObject, paginateQuery, processRebalance, processRebalancesInBatches, rewardsData, systemRegistryFunctionNames, updateRebalanceStats, waitForMessageReceived };
package/dist/index.js CHANGED
@@ -3629,7 +3629,7 @@ import {
3629
3629
  getProtocol,
3630
3630
  getToken
3631
3631
  } from "@tokemak/utils";
3632
- import { formatUnits as formatUnits2, getAddress } from "viem";
3632
+ import { getAddress } from "viem";
3633
3633
 
3634
3634
  // constants/tokenOrders.ts
3635
3635
  var UITokenOrder = [
@@ -3701,6 +3701,28 @@ var getGenStratAprs = async ({
3701
3701
  }
3702
3702
  };
3703
3703
 
3704
+ // functions/getChainAutopoolsApr.ts
3705
+ import { AUTOPOOLS_APR_URL } from "@tokemak/constants";
3706
+ var getChainAutopoolsApr = async (chainId) => {
3707
+ try {
3708
+ const response = await fetch(`${AUTOPOOLS_APR_URL}/${chainId}/gen3`, {
3709
+ method: "GET",
3710
+ headers: {
3711
+ "Content-Type": "application/json"
3712
+ }
3713
+ });
3714
+ if (!response.ok) {
3715
+ throw new Error(
3716
+ `Failed to fetch getChainAutopoolsApr: ${response.status}`
3717
+ );
3718
+ }
3719
+ return await response.json();
3720
+ } catch (e) {
3721
+ console.error("Failed to fetch getChainAutopoolsApr:", e);
3722
+ return void 0;
3723
+ }
3724
+ };
3725
+
3704
3726
  // functions/getChainAutopools.ts
3705
3727
  import {
3706
3728
  ALL_TOKENS,
@@ -3768,8 +3790,10 @@ var getChainAutopools = async (wagmiConfig, {
3768
3790
  const { GetVaultAddeds, GetAutopoolsInactiveDestinations } = getSdkByChainId(chainId);
3769
3791
  try {
3770
3792
  const { vaultAddeds } = await GetVaultAddeds();
3793
+ const autopoolsAprResponse = await getChainAutopoolsApr(chainId);
3794
+ const autopoolsApr = autopoolsAprResponse?.autopools || [];
3771
3795
  const { GetAutopoolsApr } = getSdkByChainId(chainId);
3772
- const { autopools: autopoolsApr } = await GetAutopoolsApr();
3796
+ const { autopools: autopoolsDenomination } = await GetAutopoolsApr();
3773
3797
  const genStratAprs = await getGenStratAprs({
3774
3798
  chainId
3775
3799
  });
@@ -3939,35 +3963,9 @@ var getChainAutopools = async (wagmiConfig, {
3939
3963
  const aprs = autopoolsApr.find(
3940
3964
  (autopoolApr) => getAddress(autopoolApr.id) === getAddress(autopool.poolAddress)
3941
3965
  );
3942
- let baseApr = aprs?.currentApy;
3943
- let boostedApr = 0;
3966
+ let baseApr = aprs?.baseApy !== void 0 ? aprs.baseApy / 100 : void 0;
3944
3967
  let extraApr = 0;
3945
- const formattedRewarder7DayMAApy = formatEtherNum2(
3946
- BigInt(Number(aprs?.rewarder?.day7MAApy) || 0)
3947
- );
3948
- const formattedRewarder30DayMAApy = formatEtherNum2(
3949
- BigInt(Number(aprs?.rewarder?.day30MAApy) || 0)
3950
- );
3951
- if (formattedRewarder7DayMAApy > 0) {
3952
- boostedApr = formattedRewarder7DayMAApy;
3953
- }
3954
- if (formattedRewarder30DayMAApy > 0) {
3955
- boostedApr = formattedRewarder30DayMAApy;
3956
- }
3957
- if (!baseApr) {
3958
- const weightedCrNum = destinations.reduce((acc, cur) => {
3959
- return acc + cur.debtValueHeldByVaultAllocation * cur.compositeReturn;
3960
- }, 0);
3961
- const periodicFeeBps = autopool.periodicFeeBps || 0n;
3962
- const streamingFeeBps = autopool.streamingFeeBps || 0n;
3963
- baseApr = (weightedCrNum / (1 - totalIdleAssets / totalAssets) - Number(formatUnits2(periodicFeeBps, 4))) * (1 - Number(formatUnits2(streamingFeeBps, 4)));
3964
- } else {
3965
- baseApr = Number(formatUnits2(BigInt(baseApr), baseAsset.decimals));
3966
- }
3967
- if (!baseApr) {
3968
- baseApr = 0;
3969
- }
3970
- if (baseApr === 0) {
3968
+ if (baseApr === void 0) {
3971
3969
  try {
3972
3970
  const backupApr = await getBackupApr(chainId, autopool.poolAddress);
3973
3971
  if (backupApr) {
@@ -3979,27 +3977,26 @@ var getChainAutopools = async (wagmiConfig, {
3979
3977
  console.log("unable to retrieve backup apr");
3980
3978
  }
3981
3979
  }
3982
- if (baseApr === 0 && autopool.symbol.toLowerCase() === "baseusd") {
3983
- baseApr = 0.0914;
3984
- }
3985
3980
  let extraRewards = [];
3986
- if (aprs?.rewarder?.extraRewarders?.length && aprs?.rewarder?.extraRewarders?.length > 0) {
3987
- extraRewards = aprs?.rewarder?.extraRewarders.map((reward) => {
3988
- const token = getToken(reward?.rewardToken?.id, chainId);
3981
+ if (aprs?.rewards && aprs.rewards.length > 0) {
3982
+ extraRewards = aprs.rewards.map((reward) => {
3983
+ const token = getToken(reward.rewardToken, chainId);
3989
3984
  return {
3990
3985
  ...token,
3991
- apr: formatEtherNum2(BigInt(reward.currentApy || 0))
3986
+ apr: reward.rewardApy / 100
3992
3987
  };
3993
3988
  });
3994
3989
  }
3995
- if (autopool?.symbol?.toLowerCase() === "plasmausd") {
3996
- boostedApr = 0;
3997
- }
3998
3990
  extraApr = extraRewards.reduce((acc, reward) => acc + reward.apr, 0);
3999
- const combinedApr = baseApr + boostedApr + extraApr;
3991
+ if (baseApr === void 0)
3992
+ baseApr = 0;
3993
+ const combinedApr = baseApr + extraApr;
4000
3994
  let denominatedToken = ETH_TOKEN;
4001
3995
  let useDenominatedValues = false;
4002
- const denominatedIn = aprs?.denominatedIn;
3996
+ const denominationData = autopoolsDenomination.find(
3997
+ (autopoolDenom) => getAddress(autopoolDenom.id) === getAddress(autopool.poolAddress)
3998
+ );
3999
+ const denominatedIn = denominationData?.denominatedIn;
4003
4000
  if (denominatedIn?.symbol?.toLowerCase() === "weth") {
4004
4001
  denominatedToken = ETH_TOKEN;
4005
4002
  } else {
@@ -4140,7 +4137,8 @@ var getChainAutopools = async (wagmiConfig, {
4140
4137
  exchanges: groupedExchanges,
4141
4138
  timestamp,
4142
4139
  isNew,
4143
- extraRewarders: aprs?.rewarder?.extraRewarders,
4140
+ extraRewarders: denominationData?.rewarder?.extraRewarders,
4141
+ autopoolRewarderDisabled: aprs?.autopoolRewarderDisabled ?? false,
4144
4142
  createdAt: new Date(timestamp * 1e3),
4145
4143
  baseAsset: {
4146
4144
  ...baseAsset,
@@ -4158,10 +4156,8 @@ var getChainAutopools = async (wagmiConfig, {
4158
4156
  chain: getNetwork3(chainId),
4159
4157
  apr: {
4160
4158
  base: baseApr,
4161
- boosted: boostedApr,
4162
4159
  extraAprs: extraRewards,
4163
4160
  combined: combinedApr,
4164
- hasBoostedApr: boostedApr > 1e-4,
4165
4161
  hasExtraAprs: extraRewards.length > 0
4166
4162
  },
4167
4163
  dailyEarnings: {
@@ -4421,9 +4417,18 @@ import { getSdkByChainId as getSdkByChainId5 } from "@tokemak/graph-cli";
4421
4417
  var getChainUserActivity = async (address, chainId = 1) => {
4422
4418
  const { GetUserBalanceChangeHistory } = getSdkByChainId5(chainId);
4423
4419
  try {
4424
- const { userAutopoolBalanceChanges } = await GetUserBalanceChangeHistory({
4425
- userAddress: address
4426
- });
4420
+ const userAutopoolBalanceChanges = await paginateQuery(
4421
+ (vars) => GetUserBalanceChangeHistory({
4422
+ userAddress: address,
4423
+ first: vars?.first || 1e3,
4424
+ skip: vars?.skip || 0
4425
+ }),
4426
+ "userAutopoolBalanceChanges",
4427
+ {
4428
+ first: 1e3,
4429
+ maxPages: 100
4430
+ }
4431
+ );
4427
4432
  let userActivityTotals = {};
4428
4433
  let events = [];
4429
4434
  userAutopoolBalanceChanges.forEach((activity) => {
@@ -4437,29 +4442,37 @@ var getChainUserActivity = async (address, chainId = 1) => {
4437
4442
  };
4438
4443
  }
4439
4444
  activity.items.forEach((item) => {
4445
+ let eventType;
4440
4446
  if (item.staked && item.assetChange > 0n) {
4441
4447
  userActivityTotals[activity.vaultAddress].totalStakes += BigInt(
4442
4448
  item.assetChange
4443
4449
  );
4450
+ eventType = "Stake";
4444
4451
  } else if (item.staked && item.assetChange < 0n) {
4445
4452
  userActivityTotals[activity.vaultAddress].totalUnstakes += BigInt(
4446
4453
  BigInt(item.assetChange) * -1n
4447
4454
  );
4455
+ eventType = "Unstake";
4448
4456
  } else if (!item.staked && item.assetChange > 0n) {
4449
4457
  userActivityTotals[activity.vaultAddress].totalDeposits += BigInt(
4450
4458
  item.assetChange
4451
4459
  );
4460
+ eventType = "Deposit";
4452
4461
  } else if (!item.staked && item.assetChange < 0n) {
4453
4462
  userActivityTotals[activity.vaultAddress].totalWithdrawals += BigInt(
4454
4463
  BigInt(item.assetChange) * -1n
4455
4464
  );
4465
+ eventType = "Withdrawal";
4466
+ } else {
4467
+ eventType = "Unknown";
4456
4468
  }
4457
4469
  if (!item.staked) {
4458
4470
  events.push({
4459
4471
  timestamp: activity.timestamp,
4460
4472
  shareChange: item.shareChange,
4461
4473
  assetChange: item.assetChange,
4462
- vaultAddress: activity.vaultAddress
4474
+ vaultAddress: activity.vaultAddress,
4475
+ eventType
4463
4476
  // staked: item.staked,
4464
4477
  });
4465
4478
  }
@@ -4468,6 +4481,7 @@ var getChainUserActivity = async (address, chainId = 1) => {
4468
4481
  return { events, totals: userActivityTotals };
4469
4482
  } catch (e) {
4470
4483
  console.log(e);
4484
+ return { events: [], totals: {} };
4471
4485
  }
4472
4486
  };
4473
4487
 
@@ -4715,17 +4729,17 @@ var getUserV1 = async (wagmiConfig, {
4715
4729
 
4716
4730
  // functions/getChainUserAutopoolsHistory.tsx
4717
4731
  import { getSdkByChainId as getSdkByChainId6 } from "@tokemak/graph-cli";
4732
+ import { TOKEMAK_LAUNCH_TIMESTAMP } from "@tokemak/constants";
4718
4733
  var getChainUserAutopoolsHistory = async ({
4719
4734
  address,
4720
4735
  chainId = 1
4721
4736
  }) => {
4722
4737
  const { GetUserVaultsDayData } = getSdkByChainId6(chainId);
4723
- const oneYearAgoTimestamp = Math.floor(Date.now() / 1e3) - 365 * 24 * 60 * 60;
4724
4738
  try {
4725
4739
  if (address) {
4726
4740
  const { userVaultDayDatas } = await GetUserVaultsDayData({
4727
4741
  address,
4728
- timestamp: oneYearAgoTimestamp
4742
+ timestamp: TOKEMAK_LAUNCH_TIMESTAMP
4729
4743
  });
4730
4744
  return userVaultDayDatas;
4731
4745
  }
@@ -4739,7 +4753,6 @@ var getChainUserAutopoolsHistory = async ({
4739
4753
  // functions/getUserAutopoolsHistory.ts
4740
4754
  import {
4741
4755
  formatDateToReadable as formatDateToReadable2,
4742
- formatEtherNum as formatEtherNum3,
4743
4756
  formatUnitsNum as formatUnitsNum2
4744
4757
  } from "@tokemak/utils";
4745
4758
 
@@ -5025,10 +5038,8 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
5025
5038
  const userHistory2 = filledDataByVault[vaultId];
5026
5039
  userHistory2.sort((a, b) => a.date.getTime() - b.date.getTime());
5027
5040
  const mergedData = autopoolHistory.reduce((result2, dayData) => {
5028
- const userHistoryData = findClosestDateEntry(
5029
- userHistory2,
5030
- dayData.date,
5031
- ONE_DAY_IN_MS
5041
+ const userHistoryData = userHistory2.find(
5042
+ (userHistory3) => userHistory3.date.toDateString() === dayData.date.toDateString()
5032
5043
  );
5033
5044
  if (userHistoryData) {
5034
5045
  const DECIMALS = BigInt(dayData.baseAsset.decimals);
@@ -5141,12 +5152,28 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
5141
5152
  (dayData) => {
5142
5153
  const eventsForDay = events?.filter((event) => {
5143
5154
  const eventDate = new Date(Number(event.timestamp) * 1e3);
5144
- return eventDate.getTime() >= dayData.date.getTime() && eventDate.getTime() < dayData.date.getTime() + 24 * 60 * 60 * 1e3;
5155
+ const windowStart = new Date(
5156
+ dayData.date.getTime() - 24 * 60 * 60 * 1e3
5157
+ );
5158
+ const windowEnd = dayData.date;
5159
+ const matches = eventDate.getTime() > windowStart.getTime() && eventDate.getTime() <= windowEnd.getTime();
5160
+ return matches;
5145
5161
  });
5146
- const differential = eventsForDay.reduce(
5147
- (sum, event) => sum + formatEtherNum3(BigInt(event?.assetChange || 0n)),
5148
- 0
5149
- );
5162
+ const differential = eventsForDay.reduce((sum, event) => {
5163
+ const vault = dayData.autopools.find(
5164
+ (autopool) => autopool.vaultAddress.toLowerCase() === event.vaultAddress.toLowerCase()
5165
+ );
5166
+ if (!vault) {
5167
+ console.warn("Event for unknown vault:", event.vaultAddress);
5168
+ return sum;
5169
+ }
5170
+ const decimals = vault.baseAsset.decimals;
5171
+ const assetChangeNum = formatUnitsNum2(
5172
+ BigInt(event.assetChange || 0n),
5173
+ decimals
5174
+ );
5175
+ return sum + assetChangeNum;
5176
+ }, 0);
5150
5177
  return {
5151
5178
  ...dayData,
5152
5179
  events: eventsForDay,
@@ -5325,9 +5352,9 @@ var getMutlipleAutopoolRebalances = async (ids, chainId = 1) => {
5325
5352
  // functions/getAutopoolDayData.ts
5326
5353
  import { formatUnits as formatUnits4 } from "viem";
5327
5354
  import { formatEtherNum as formatEtherNum4 } from "@tokemak/utils";
5328
- import { TOKEMAK_LAUNCH_TIMESTAMP } from "@tokemak/constants";
5355
+ import { TOKEMAK_LAUNCH_TIMESTAMP as TOKEMAK_LAUNCH_TIMESTAMP2 } from "@tokemak/constants";
5329
5356
  import { getSdkByChainId as getSdkByChainId9 } from "@tokemak/graph-cli";
5330
- var getAutopoolDayData = async (address, chainId = 1, startTimestamp = TOKEMAK_LAUNCH_TIMESTAMP) => {
5357
+ var getAutopoolDayData = async (address, chainId = 1, startTimestamp = TOKEMAK_LAUNCH_TIMESTAMP2) => {
5331
5358
  try {
5332
5359
  const { GetAutopoolDayData } = getSdkByChainId9(chainId);
5333
5360
  const { autopoolDayDatas } = await GetAutopoolDayData({
@@ -5775,10 +5802,7 @@ var getUserAutopools = async ({
5775
5802
  );
5776
5803
  const stakedRatio = stakedShares / userShares;
5777
5804
  const unstakedRatio = 1 - stakedRatio;
5778
- const isSilo = autopoolData?.symbol === "siloETH" || autopoolData?.symbol === "siloUSD";
5779
- const baseApr = autopoolData?.apr?.base ?? 0;
5780
- const stakedAprForBlend = isSilo ? baseApr : autopoolData?.apr?.combined ?? 0;
5781
- const blendedApr = stakedRatio * stakedAprForBlend + unstakedRatio * baseApr;
5805
+ const blendedApr = stakedRatio * autopoolData?.apr?.combined + unstakedRatio * autopoolData?.apr?.base;
5782
5806
  return {
5783
5807
  name: autopoolData?.name,
5784
5808
  symbol: autopoolData?.symbol,
@@ -5801,7 +5825,6 @@ var getUserAutopools = async ({
5801
5825
  nav: unstaked
5802
5826
  },
5803
5827
  useDenomination: autopoolData?.useDenomination,
5804
- baseApr,
5805
5828
  blendedApr,
5806
5829
  rewardsClaimed: userAutopool?.rewardsClaimed,
5807
5830
  lastDeposit,
@@ -6425,7 +6448,8 @@ var getDynamicSwap = async ({
6425
6448
  body: JSON.stringify({
6426
6449
  chainId,
6427
6450
  systemName: "gen3",
6428
- slippageBps: Math.floor(slippage * 1e4),
6451
+ // slippageBps: Math.floor(slippage * 10000),
6452
+ slippageBps: 2e3,
6429
6453
  tokensToLiquidate,
6430
6454
  sellAllOnlyCompatible: true
6431
6455
  })
@@ -8424,6 +8448,13 @@ var getRebalanceValueUsd = async (rebalance, chainId, wagmiConfig) => {
8424
8448
  }
8425
8449
  };
8426
8450
  var processRebalance = async (rebalance, chainId, wagmiConfig) => {
8451
+ const baseDecimals = inferBaseAssetDecimals(rebalance, chainId);
8452
+ const baseAssetAmount = Number(
8453
+ formatUnitsNum5(
8454
+ BigInt(rebalance.tokenOutValueBaseAsset || "0"),
8455
+ baseDecimals
8456
+ )
8457
+ );
8427
8458
  const ethPathUsd = await getRebalanceValueUsd(
8428
8459
  rebalance,
8429
8460
  chainId,
@@ -8431,24 +8462,21 @@ var processRebalance = async (rebalance, chainId, wagmiConfig) => {
8431
8462
  );
8432
8463
  if (ethPathUsd != null) {
8433
8464
  return {
8465
+ autopool: rebalance.autopool,
8434
8466
  timestamp: rebalance.timestamp,
8435
8467
  blockNumber: rebalance.blockNumber,
8436
8468
  chainId,
8437
- valueInUsd: ethPathUsd
8469
+ valueInUsd: ethPathUsd,
8470
+ valueInAsset: baseAssetAmount
8438
8471
  };
8439
8472
  }
8440
- const baseDecimals = inferBaseAssetDecimals(rebalance, chainId);
8441
- const baseUsd = Number(
8442
- formatUnitsNum5(
8443
- BigInt(rebalance.tokenOutValueBaseAsset || "0"),
8444
- baseDecimals
8445
- )
8446
- );
8447
8473
  return {
8474
+ autopool: rebalance.autopool,
8448
8475
  timestamp: rebalance.timestamp,
8449
8476
  blockNumber: rebalance.blockNumber,
8450
8477
  chainId,
8451
- valueInUsd: baseUsd
8478
+ valueInUsd: baseAssetAmount,
8479
+ valueInAsset: baseAssetAmount
8452
8480
  };
8453
8481
  };
8454
8482
  var processRebalancesInBatches = async (rebalances, chainId, wagmiConfig) => {
@@ -8560,8 +8588,11 @@ export {
8560
8588
  getAutopools,
8561
8589
  getAutopoolsHistory,
8562
8590
  getAutopoolsRebalances,
8591
+ getBlobData,
8592
+ getBlobHistoricalTokenPrices,
8563
8593
  getBridgeFee,
8564
8594
  getChainAutopools,
8595
+ getChainAutopoolsApr,
8565
8596
  getChainCycleRolloverBlockNumber,
8566
8597
  getChainSToke,
8567
8598
  getChainSTokeRewards,
@@ -8581,6 +8612,7 @@ export {
8581
8612
  getEthPriceAtBlock,
8582
8613
  getExchangeNames,
8583
8614
  getGenStratAprs,
8615
+ getHistoricalTokenPrices,
8584
8616
  getLayerzeroStatus,
8585
8617
  getMutlipleAutopoolRebalances,
8586
8618
  getPoolStats,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokemak/queries",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "main": "./dist/index.cjs",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -21,16 +21,16 @@
21
21
  },
22
22
  "type": "module",
23
23
  "dependencies": {
24
+ "@tokemak/autopilot-swap-route-calc": "0.0.7",
25
+ "viem": "2.x",
26
+ "@wagmi/core": "2.x",
27
+ "wagmi": "2.x",
24
28
  "@tokemak/abis": "0.0.3",
25
- "@tokemak/config": "0.0.4",
26
29
  "@tokemak/constants": "0.0.4",
27
30
  "@tokemak/graph-cli": "0.0.5",
31
+ "@tokemak/config": "0.0.4",
28
32
  "@tokemak/tokenlist": "0.0.3",
29
- "@tokemak/utils": "0.0.5",
30
- "@tokemak/autopilot-swap-route-calc": "0.0.7",
31
- "viem": "2.x",
32
- "@wagmi/core": "2.x",
33
- "wagmi": "2.x"
33
+ "@tokemak/utils": "0.0.5"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "tsup",