@tokemak/queries 0.0.17 → 0.0.19

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.cjs CHANGED
@@ -8633,7 +8633,7 @@ var getAutopoolUserActivity = async ({
8633
8633
  first: vars?.first || 1e3,
8634
8634
  skip: vars?.skip || 0
8635
8635
  }),
8636
- "userAutopoolBalanceChanges",
8636
+ "userSpecificAutopoolBalanceChanges",
8637
8637
  {
8638
8638
  first: 1e3,
8639
8639
  maxPages: 100
@@ -8850,26 +8850,21 @@ var getAutopoolHistory = async (autopool) => {
8850
8850
  address: autopool?.poolAddress,
8851
8851
  timestamp: import_constants12.TOKEMAK_LAUNCH_TIMESTAMP
8852
8852
  });
8853
- const vaultId = autopool?.poolAddress.toLowerCase();
8854
8853
  const formattedData = autopoolDayDatas.map((dayData) => {
8855
8854
  return {
8856
8855
  ...dayData,
8857
- vaultId,
8858
- vault: {
8859
- id: vaultId
8860
- },
8861
- date: new Date(dayData.timestamp * 1e3),
8862
- baseAsset: autopool?.baseAsset
8856
+ date: new Date(dayData.timestamp * 1e3)
8863
8857
  };
8864
8858
  });
8865
8859
  const filledData = fillMissingDates(formattedData);
8866
- return { [vaultId]: filledData };
8860
+ return filledData;
8867
8861
  } catch (e) {
8868
8862
  console.log(e);
8869
8863
  }
8870
8864
  };
8871
8865
 
8872
8866
  // functions/getAutopoolUserHistory.ts
8867
+ var import_utils57 = require("@tokemak/utils");
8873
8868
  var getAutopoolUserHistory = async ({
8874
8869
  userAddress,
8875
8870
  autopool,
@@ -8885,17 +8880,63 @@ var getAutopoolUserHistory = async ({
8885
8880
  timestamp: import_constants13.TOKEMAK_LAUNCH_TIMESTAMP,
8886
8881
  vaultAddress: autopool?.poolAddress
8887
8882
  });
8888
- const autopoolHistory = await getAutopoolHistory(autopool);
8889
- if (!autopoolHistory) {
8883
+ const autopoolDayData = await getAutopoolHistory(autopool);
8884
+ if (!autopoolDayData) {
8890
8885
  throw new Error("No autopool history found");
8891
8886
  }
8892
- const processedHistory = processUserHistory({
8893
- address: userAddress,
8894
- autopoolsHistory: autopoolHistory,
8895
- events: userActivity.events,
8896
- userHistory: userVaultDayDatas
8887
+ const formattedUserVaultDayDatas = userVaultDayDatas.map((dayData) => {
8888
+ if (!dayData.timestamp) {
8889
+ throw new Error("Missing timestamp in userVaultDayData");
8890
+ }
8891
+ return {
8892
+ ...dayData,
8893
+ date: new Date(Number(dayData.timestamp) * 1e3),
8894
+ timestamp: dayData.timestamp.toString()
8895
+ };
8896
+ });
8897
+ const filledMissingDates = fillMissingDates(formattedUserVaultDayDatas);
8898
+ if (filledMissingDates.length > 0) {
8899
+ const firstEntry = filledMissingDates[0];
8900
+ const dayBefore = new Date(firstEntry.date);
8901
+ dayBefore.setDate(dayBefore.getDate() - 1);
8902
+ const dayBeforeTimestamp = Math.floor(
8903
+ dayBefore.getTime() / 1e3
8904
+ ).toString();
8905
+ const dayBeforeEntry = {
8906
+ ...firstEntry,
8907
+ date: dayBefore,
8908
+ timestamp: dayBeforeTimestamp,
8909
+ totalShares: 0
8910
+ };
8911
+ filledMissingDates.unshift(dayBeforeEntry);
8912
+ }
8913
+ const matchedData = filledMissingDates.map((userVaultDayData) => {
8914
+ const matchingAutopoolDayData = autopoolDayData.find(
8915
+ (autopoolDay) => autopoolDay.date.toDateString() === userVaultDayData.date.toDateString()
8916
+ );
8917
+ const userPortionOfVault = (0, import_utils57.formatEtherNum)(userVaultDayData.totalShares) / (0, import_utils57.formatEtherNum)(matchingAutopoolDayData?.totalSupply);
8918
+ const userNav = userPortionOfVault * (0, import_utils57.formatUnitsNum)(
8919
+ BigInt(matchingAutopoolDayData?.nav || 0),
8920
+ autopool?.baseAsset.decimals
8921
+ );
8922
+ const eventsForDay = userActivity.events?.filter((event) => {
8923
+ const eventDate = new Date(Number(event.timestamp) * 1e3);
8924
+ const windowStart = new Date(
8925
+ userVaultDayData.date.getTime() - 24 * 60 * 60 * 1e3
8926
+ );
8927
+ const windowEnd = userVaultDayData.date;
8928
+ const matches = eventDate.getTime() > windowStart.getTime() && eventDate.getTime() <= windowEnd.getTime();
8929
+ return matches;
8930
+ });
8931
+ return {
8932
+ date: userVaultDayData.date,
8933
+ timestamp: userVaultDayData.timestamp,
8934
+ baseAsset: autopool?.baseAsset.symbol,
8935
+ nav: userNav,
8936
+ events: eventsForDay
8937
+ };
8897
8938
  });
8898
- return processedHistory;
8939
+ return matchedData;
8899
8940
  }
8900
8941
  return [];
8901
8942
  } catch (e) {
package/dist/index.d.ts CHANGED
@@ -3318,42 +3318,28 @@ declare const getAutopoolUserHistory: ({ userAddress, autopool, userActivity, }:
3318
3318
  userAddress: Address;
3319
3319
  autopool: IAutopool;
3320
3320
  userActivity: IUserActivity;
3321
- }) => Promise<EnhancedUserHistoryEntry[]>;
3321
+ }) => Promise<{
3322
+ date: Date;
3323
+ timestamp: any;
3324
+ baseAsset: string;
3325
+ nav: number;
3326
+ events: {
3327
+ timestamp: number;
3328
+ shareChange: string;
3329
+ assetChange: string;
3330
+ vaultAddress: string;
3331
+ eventType: EventType;
3332
+ }[];
3333
+ }[]>;
3322
3334
 
3323
3335
  declare const getAutopoolHistory: (autopool: IAutopool) => Promise<{
3324
- [x: string]: {
3325
- vaultId: string;
3326
- vault: {
3327
- id: string;
3328
- };
3329
- date: Date;
3330
- baseAsset: {
3331
- price: number;
3332
- address: viem.Address;
3333
- chainId: number;
3334
- decimals: number;
3335
- logoURI: string;
3336
- name: string;
3337
- symbol: string;
3338
- audits?: string;
3339
- extensions?: {
3340
- bridgeMainnetAdapter?: viem.Address;
3341
- bridgeInfo?: {
3342
- [chainId: number]: {
3343
- tokenAddress: viem.Address;
3344
- };
3345
- };
3346
- rebasing?: boolean;
3347
- parentAsset?: string;
3348
- };
3349
- };
3350
- __typename?: "AutopoolDayData";
3351
- totalSupply: any;
3352
- nav: any;
3353
- timestamp: any;
3354
- id: string;
3355
- }[];
3356
- } | undefined>;
3336
+ date: Date;
3337
+ __typename?: "AutopoolDayData";
3338
+ totalSupply: any;
3339
+ nav: any;
3340
+ timestamp: any;
3341
+ id: string;
3342
+ }[] | undefined>;
3357
3343
  type IAutopoolHistory = Awaited<ReturnType<typeof getAutopoolHistory>>;
3358
3344
 
3359
3345
  export { AggregatedDayData, AutopoolCategory, AutopoolsApr, BASE_ASSETS, BATCH_SIZE, BaseAsset, BaseAssetWithUsd, BaseDataEntry, ChainAutopoolsAprResponse, ChainSTokeRewardsType, ChainSTokeType, ChainSTokeVotes, Currencies, CurveLP, ETH_BASE_ASSETS, EUR_BASE_ASSETS, EnhancedUserHistoryEntry, EventType, ExtraReward, FillData, GetLayerzeroStatusConfig, HistoricalTokenPrices, IAutopool, IAutopoolHistory, 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, UserActivityTotalsType, UserAutopoolsVotes, UserDayDataEntry, UserSTokeVotes, VaultAddedMapping, aggregateSTokeRewardsDayData, arraysToObject, calculateRebalanceStats, convertBaseAssetToTokenPrices, convertBaseAssetToTokenPricesAndDenom, fetchChainDataMap, fetchChainRebalances, fillMissingDates, findClosestDateEntry, findClosestEntry, findClosestTimestampEntry, formatDateRange, getAddressFromSystemRegistry, getAllowance, getAmountDeposited, getAmountWithdrawn, getAutopilotRouter, getAutopoolCategory, getAutopoolDayData, getAutopoolHistory, getAutopoolInfo, getAutopoolRebalances, getAutopoolUser, getAutopoolUserActivity, getAutopoolUserHistory, 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
@@ -8592,7 +8592,7 @@ var getAutopoolUserActivity = async ({
8592
8592
  first: vars?.first || 1e3,
8593
8593
  skip: vars?.skip || 0
8594
8594
  }),
8595
- "userAutopoolBalanceChanges",
8595
+ "userSpecificAutopoolBalanceChanges",
8596
8596
  {
8597
8597
  first: 1e3,
8598
8598
  maxPages: 100
@@ -8813,26 +8813,21 @@ var getAutopoolHistory = async (autopool) => {
8813
8813
  address: autopool?.poolAddress,
8814
8814
  timestamp: TOKEMAK_LAUNCH_TIMESTAMP3
8815
8815
  });
8816
- const vaultId = autopool?.poolAddress.toLowerCase();
8817
8816
  const formattedData = autopoolDayDatas.map((dayData) => {
8818
8817
  return {
8819
8818
  ...dayData,
8820
- vaultId,
8821
- vault: {
8822
- id: vaultId
8823
- },
8824
- date: new Date(dayData.timestamp * 1e3),
8825
- baseAsset: autopool?.baseAsset
8819
+ date: new Date(dayData.timestamp * 1e3)
8826
8820
  };
8827
8821
  });
8828
8822
  const filledData = fillMissingDates(formattedData);
8829
- return { [vaultId]: filledData };
8823
+ return filledData;
8830
8824
  } catch (e) {
8831
8825
  console.log(e);
8832
8826
  }
8833
8827
  };
8834
8828
 
8835
8829
  // functions/getAutopoolUserHistory.ts
8830
+ import { formatEtherNum as formatEtherNum15, formatUnitsNum as formatUnitsNum7 } from "@tokemak/utils";
8836
8831
  var getAutopoolUserHistory = async ({
8837
8832
  userAddress,
8838
8833
  autopool,
@@ -8848,17 +8843,63 @@ var getAutopoolUserHistory = async ({
8848
8843
  timestamp: TOKEMAK_LAUNCH_TIMESTAMP4,
8849
8844
  vaultAddress: autopool?.poolAddress
8850
8845
  });
8851
- const autopoolHistory = await getAutopoolHistory(autopool);
8852
- if (!autopoolHistory) {
8846
+ const autopoolDayData = await getAutopoolHistory(autopool);
8847
+ if (!autopoolDayData) {
8853
8848
  throw new Error("No autopool history found");
8854
8849
  }
8855
- const processedHistory = processUserHistory({
8856
- address: userAddress,
8857
- autopoolsHistory: autopoolHistory,
8858
- events: userActivity.events,
8859
- userHistory: userVaultDayDatas
8850
+ const formattedUserVaultDayDatas = userVaultDayDatas.map((dayData) => {
8851
+ if (!dayData.timestamp) {
8852
+ throw new Error("Missing timestamp in userVaultDayData");
8853
+ }
8854
+ return {
8855
+ ...dayData,
8856
+ date: new Date(Number(dayData.timestamp) * 1e3),
8857
+ timestamp: dayData.timestamp.toString()
8858
+ };
8859
+ });
8860
+ const filledMissingDates = fillMissingDates(formattedUserVaultDayDatas);
8861
+ if (filledMissingDates.length > 0) {
8862
+ const firstEntry = filledMissingDates[0];
8863
+ const dayBefore = new Date(firstEntry.date);
8864
+ dayBefore.setDate(dayBefore.getDate() - 1);
8865
+ const dayBeforeTimestamp = Math.floor(
8866
+ dayBefore.getTime() / 1e3
8867
+ ).toString();
8868
+ const dayBeforeEntry = {
8869
+ ...firstEntry,
8870
+ date: dayBefore,
8871
+ timestamp: dayBeforeTimestamp,
8872
+ totalShares: 0
8873
+ };
8874
+ filledMissingDates.unshift(dayBeforeEntry);
8875
+ }
8876
+ const matchedData = filledMissingDates.map((userVaultDayData) => {
8877
+ const matchingAutopoolDayData = autopoolDayData.find(
8878
+ (autopoolDay) => autopoolDay.date.toDateString() === userVaultDayData.date.toDateString()
8879
+ );
8880
+ const userPortionOfVault = formatEtherNum15(userVaultDayData.totalShares) / formatEtherNum15(matchingAutopoolDayData?.totalSupply);
8881
+ const userNav = userPortionOfVault * formatUnitsNum7(
8882
+ BigInt(matchingAutopoolDayData?.nav || 0),
8883
+ autopool?.baseAsset.decimals
8884
+ );
8885
+ const eventsForDay = userActivity.events?.filter((event) => {
8886
+ const eventDate = new Date(Number(event.timestamp) * 1e3);
8887
+ const windowStart = new Date(
8888
+ userVaultDayData.date.getTime() - 24 * 60 * 60 * 1e3
8889
+ );
8890
+ const windowEnd = userVaultDayData.date;
8891
+ const matches = eventDate.getTime() > windowStart.getTime() && eventDate.getTime() <= windowEnd.getTime();
8892
+ return matches;
8893
+ });
8894
+ return {
8895
+ date: userVaultDayData.date,
8896
+ timestamp: userVaultDayData.timestamp,
8897
+ baseAsset: autopool?.baseAsset.symbol,
8898
+ nav: userNav,
8899
+ events: eventsForDay
8900
+ };
8860
8901
  });
8861
- return processedHistory;
8902
+ return matchedData;
8862
8903
  }
8863
8904
  return [];
8864
8905
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokemak/queries",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "main": "./dist/index.cjs",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -25,12 +25,12 @@
25
25
  "viem": "2.x",
26
26
  "@wagmi/core": "2.x",
27
27
  "wagmi": "2.x",
28
- "@tokemak/abis": "0.0.3",
29
28
  "@tokemak/config": "0.0.4",
30
- "@tokemak/graph-cli": "0.0.9",
31
- "@tokemak/tokenlist": "0.0.3",
32
29
  "@tokemak/constants": "0.0.4",
33
- "@tokemak/utils": "0.0.5"
30
+ "@tokemak/abis": "0.0.3",
31
+ "@tokemak/tokenlist": "0.0.3",
32
+ "@tokemak/utils": "0.0.5",
33
+ "@tokemak/graph-cli": "0.0.10"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "tsup",