@tokemak/queries 0.0.18 → 0.0.20
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 +44 -18
- package/dist/index.d.ts +4 -3
- package/dist/index.js +41 -15
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -8619,17 +8619,22 @@ var updateRebalanceStats = async (wagmiConfig, {
|
|
|
8619
8619
|
|
|
8620
8620
|
// functions/getAutopoolUserActivity.ts
|
|
8621
8621
|
var import_graph_cli18 = require("@tokemak/graph-cli");
|
|
8622
|
+
var import_utils53 = require("@tokemak/utils");
|
|
8622
8623
|
var getAutopoolUserActivity = async ({
|
|
8623
|
-
|
|
8624
|
-
userAddress
|
|
8625
|
-
chainId = 1
|
|
8624
|
+
autopool,
|
|
8625
|
+
userAddress
|
|
8626
8626
|
}) => {
|
|
8627
|
-
|
|
8627
|
+
if (!autopool || !autopool.chain?.chainId) {
|
|
8628
|
+
throw new Error("Autopool not found");
|
|
8629
|
+
}
|
|
8630
|
+
const { GetUserAutopoolBalanceChangeHistory } = (0, import_graph_cli18.getSdkByChainId)(
|
|
8631
|
+
autopool.chain?.chainId
|
|
8632
|
+
);
|
|
8628
8633
|
try {
|
|
8629
8634
|
const userAutopoolBalanceChanges = await paginateQuery(
|
|
8630
8635
|
(vars) => GetUserAutopoolBalanceChangeHistory({
|
|
8631
8636
|
userAddress,
|
|
8632
|
-
vaultAddress:
|
|
8637
|
+
vaultAddress: autopool.poolAddress,
|
|
8633
8638
|
first: vars?.first || 1e3,
|
|
8634
8639
|
skip: vars?.skip || 0
|
|
8635
8640
|
}),
|
|
@@ -8648,7 +8653,7 @@ var getAutopoolUserActivity = async ({
|
|
|
8648
8653
|
totalWithdrawals: 0n,
|
|
8649
8654
|
totalStakes: 0n,
|
|
8650
8655
|
totalUnstakes: 0n,
|
|
8651
|
-
chainId
|
|
8656
|
+
chainId: autopool.chain?.chainId
|
|
8652
8657
|
};
|
|
8653
8658
|
}
|
|
8654
8659
|
activity.items.forEach((item) => {
|
|
@@ -8676,12 +8681,17 @@ var getAutopoolUserActivity = async ({
|
|
|
8676
8681
|
} else {
|
|
8677
8682
|
eventType = "Unknown";
|
|
8678
8683
|
}
|
|
8684
|
+
const netDeposits = (0, import_utils53.formatUnitsNum)(
|
|
8685
|
+
userActivityTotals[activity.vaultAddress].totalDeposits - userActivityTotals[activity.vaultAddress].totalWithdrawals,
|
|
8686
|
+
autopool.baseAsset.decimals
|
|
8687
|
+
);
|
|
8679
8688
|
if (!item.staked) {
|
|
8680
8689
|
events.push({
|
|
8681
8690
|
timestamp: activity.timestamp,
|
|
8682
8691
|
shareChange: item.shareChange,
|
|
8683
8692
|
assetChange: item.assetChange,
|
|
8684
8693
|
vaultAddress: activity.vaultAddress,
|
|
8694
|
+
netDeposits,
|
|
8685
8695
|
eventType
|
|
8686
8696
|
// staked: item.staked,
|
|
8687
8697
|
});
|
|
@@ -8699,7 +8709,7 @@ var getAutopoolUserActivity = async ({
|
|
|
8699
8709
|
var import_viem21 = require("viem");
|
|
8700
8710
|
var import_core23 = require("@wagmi/core");
|
|
8701
8711
|
var import_abis22 = require("@tokemak/abis");
|
|
8702
|
-
var
|
|
8712
|
+
var import_utils54 = require("@tokemak/utils");
|
|
8703
8713
|
var getAutopoolUser = async (config, {
|
|
8704
8714
|
autopool,
|
|
8705
8715
|
address,
|
|
@@ -8741,14 +8751,14 @@ var getAutopoolUser = async (config, {
|
|
|
8741
8751
|
args: [address],
|
|
8742
8752
|
chainId: autopool?.chain?.chainId
|
|
8743
8753
|
});
|
|
8744
|
-
const stakedShares = (0,
|
|
8754
|
+
const stakedShares = (0, import_utils54.formatEtherNum)(stakedPoolShares);
|
|
8745
8755
|
const staked = convertBaseAssetToTokenPricesAndDenom(
|
|
8746
8756
|
stakedShares * (autopool?.navPerShare.baseAsset || 0),
|
|
8747
8757
|
autopool?.baseAsset.price,
|
|
8748
8758
|
autopool?.denomination.price,
|
|
8749
8759
|
prices
|
|
8750
8760
|
);
|
|
8751
|
-
const unstakedShares = (0,
|
|
8761
|
+
const unstakedShares = (0, import_utils54.formatEtherNum)(unstakedPoolShares || 0n);
|
|
8752
8762
|
const unstaked = convertBaseAssetToTokenPricesAndDenom(
|
|
8753
8763
|
unstakedShares * (autopool?.navPerShare.baseAsset || 0),
|
|
8754
8764
|
autopool?.baseAsset.price,
|
|
@@ -8763,7 +8773,7 @@ var getAutopoolUser = async (config, {
|
|
|
8763
8773
|
prices
|
|
8764
8774
|
);
|
|
8765
8775
|
const totalDeposits = convertBaseAssetToTokenPricesAndDenom(
|
|
8766
|
-
(0,
|
|
8776
|
+
(0, import_utils54.formatUnitsNum)(
|
|
8767
8777
|
userActivity?.totals[autopool?.poolAddress]?.totalDeposits || 0n,
|
|
8768
8778
|
autopool?.baseAsset.decimals
|
|
8769
8779
|
),
|
|
@@ -8772,7 +8782,7 @@ var getAutopoolUser = async (config, {
|
|
|
8772
8782
|
prices
|
|
8773
8783
|
);
|
|
8774
8784
|
const totalWithdrawals = convertBaseAssetToTokenPricesAndDenom(
|
|
8775
|
-
(0,
|
|
8785
|
+
(0, import_utils54.formatUnitsNum)(
|
|
8776
8786
|
userActivity?.totals[autopool?.poolAddress]?.totalWithdrawals || 0n,
|
|
8777
8787
|
autopool?.baseAsset.decimals
|
|
8778
8788
|
),
|
|
@@ -8797,7 +8807,7 @@ var getAutopoolUser = async (config, {
|
|
|
8797
8807
|
);
|
|
8798
8808
|
let lastDeposit;
|
|
8799
8809
|
if (poolEvents && poolEvents?.length > 0) {
|
|
8800
|
-
lastDeposit = (0,
|
|
8810
|
+
lastDeposit = (0, import_utils54.convertTimestampToDate)(
|
|
8801
8811
|
poolEvents[poolEvents.length - 1].timestamp
|
|
8802
8812
|
).toLocaleDateString("en-US", {
|
|
8803
8813
|
day: "2-digit",
|
|
@@ -8864,6 +8874,7 @@ var getAutopoolHistory = async (autopool) => {
|
|
|
8864
8874
|
};
|
|
8865
8875
|
|
|
8866
8876
|
// functions/getAutopoolUserHistory.ts
|
|
8877
|
+
var import_utils58 = require("@tokemak/utils");
|
|
8867
8878
|
var getAutopoolUserHistory = async ({
|
|
8868
8879
|
userAddress,
|
|
8869
8880
|
autopool,
|
|
@@ -8909,27 +8920,42 @@ var getAutopoolUserHistory = async ({
|
|
|
8909
8920
|
};
|
|
8910
8921
|
filledMissingDates.unshift(dayBeforeEntry);
|
|
8911
8922
|
}
|
|
8923
|
+
let lastKnownNetDeposits = null;
|
|
8912
8924
|
const matchedData = filledMissingDates.map((userVaultDayData) => {
|
|
8913
8925
|
const matchingAutopoolDayData = autopoolDayData.find(
|
|
8914
8926
|
(autopoolDay) => autopoolDay.date.toDateString() === userVaultDayData.date.toDateString()
|
|
8915
8927
|
);
|
|
8916
|
-
const userPortionOfVault = userVaultDayData.totalShares / matchingAutopoolDayData?.totalSupply;
|
|
8917
|
-
const userNav = userPortionOfVault *
|
|
8928
|
+
const userPortionOfVault = (0, import_utils58.formatEtherNum)(userVaultDayData.totalShares) / (0, import_utils58.formatEtherNum)(matchingAutopoolDayData?.totalSupply);
|
|
8929
|
+
const userNav = userPortionOfVault * (0, import_utils58.formatUnitsNum)(
|
|
8930
|
+
BigInt(matchingAutopoolDayData?.nav || 0),
|
|
8931
|
+
autopool?.baseAsset.decimals
|
|
8932
|
+
);
|
|
8918
8933
|
const eventsForDay = userActivity.events?.filter((event) => {
|
|
8919
8934
|
const eventDate = new Date(Number(event.timestamp) * 1e3);
|
|
8920
|
-
const windowStart = new Date(
|
|
8921
|
-
|
|
8935
|
+
const windowStart = new Date(userVaultDayData.date.getTime());
|
|
8936
|
+
const windowEnd = new Date(
|
|
8937
|
+
userVaultDayData.date.getTime() + 24 * 60 * 60 * 1e3
|
|
8922
8938
|
);
|
|
8923
|
-
const windowEnd = userVaultDayData.date;
|
|
8924
8939
|
const matches = eventDate.getTime() > windowStart.getTime() && eventDate.getTime() <= windowEnd.getTime();
|
|
8925
8940
|
return matches;
|
|
8926
8941
|
});
|
|
8942
|
+
const lastEventForDay = eventsForDay && eventsForDay.length > 0 ? eventsForDay.sort(
|
|
8943
|
+
(a, b) => Number(b.timestamp) - Number(a.timestamp)
|
|
8944
|
+
)[0] : 0;
|
|
8945
|
+
let netDeposits = 0;
|
|
8946
|
+
if (lastEventForDay && "netDeposits" in lastEventForDay && typeof lastEventForDay.netDeposits === "number") {
|
|
8947
|
+
netDeposits = lastEventForDay.netDeposits;
|
|
8948
|
+
lastKnownNetDeposits = netDeposits;
|
|
8949
|
+
} else {
|
|
8950
|
+
netDeposits = lastKnownNetDeposits;
|
|
8951
|
+
}
|
|
8927
8952
|
return {
|
|
8928
8953
|
date: userVaultDayData.date,
|
|
8929
8954
|
timestamp: userVaultDayData.timestamp,
|
|
8930
8955
|
baseAsset: autopool?.baseAsset.symbol,
|
|
8931
8956
|
nav: userNav,
|
|
8932
|
-
events: eventsForDay
|
|
8957
|
+
events: eventsForDay,
|
|
8958
|
+
netDeposits
|
|
8933
8959
|
};
|
|
8934
8960
|
});
|
|
8935
8961
|
return matchedData;
|
package/dist/index.d.ts
CHANGED
|
@@ -3145,10 +3145,9 @@ declare const getChainAutopoolsApr: (chainId: number) => Promise<ChainAutopoolsA
|
|
|
3145
3145
|
|
|
3146
3146
|
declare const getBlobData: (blobName: string) => Promise<any>;
|
|
3147
3147
|
|
|
3148
|
-
declare const getAutopoolUserActivity: ({
|
|
3149
|
-
|
|
3148
|
+
declare const getAutopoolUserActivity: ({ autopool, userAddress, }: {
|
|
3149
|
+
autopool: IAutopool;
|
|
3150
3150
|
userAddress: Address;
|
|
3151
|
-
chainId?: SupportedChainIds;
|
|
3152
3151
|
}) => Promise<never[] | {
|
|
3153
3152
|
events: {
|
|
3154
3153
|
timestamp: number;
|
|
@@ -3156,6 +3155,7 @@ declare const getAutopoolUserActivity: ({ autopoolAddress, userAddress, chainId,
|
|
|
3156
3155
|
assetChange: string;
|
|
3157
3156
|
vaultAddress: string;
|
|
3158
3157
|
eventType: EventType;
|
|
3158
|
+
netDeposits?: number;
|
|
3159
3159
|
}[];
|
|
3160
3160
|
totals: UserActivityTotalsType;
|
|
3161
3161
|
}>;
|
|
@@ -3330,6 +3330,7 @@ declare const getAutopoolUserHistory: ({ userAddress, autopool, userActivity, }:
|
|
|
3330
3330
|
vaultAddress: string;
|
|
3331
3331
|
eventType: EventType;
|
|
3332
3332
|
}[];
|
|
3333
|
+
netDeposits: number | null;
|
|
3333
3334
|
}[]>;
|
|
3334
3335
|
|
|
3335
3336
|
declare const getAutopoolHistory: (autopool: IAutopool) => Promise<{
|
package/dist/index.js
CHANGED
|
@@ -8578,17 +8578,22 @@ var updateRebalanceStats = async (wagmiConfig, {
|
|
|
8578
8578
|
|
|
8579
8579
|
// functions/getAutopoolUserActivity.ts
|
|
8580
8580
|
import { getSdkByChainId as getSdkByChainId18 } from "@tokemak/graph-cli";
|
|
8581
|
+
import { formatUnitsNum as formatUnitsNum6 } from "@tokemak/utils";
|
|
8581
8582
|
var getAutopoolUserActivity = async ({
|
|
8582
|
-
|
|
8583
|
-
userAddress
|
|
8584
|
-
chainId = 1
|
|
8583
|
+
autopool,
|
|
8584
|
+
userAddress
|
|
8585
8585
|
}) => {
|
|
8586
|
-
|
|
8586
|
+
if (!autopool || !autopool.chain?.chainId) {
|
|
8587
|
+
throw new Error("Autopool not found");
|
|
8588
|
+
}
|
|
8589
|
+
const { GetUserAutopoolBalanceChangeHistory } = getSdkByChainId18(
|
|
8590
|
+
autopool.chain?.chainId
|
|
8591
|
+
);
|
|
8587
8592
|
try {
|
|
8588
8593
|
const userAutopoolBalanceChanges = await paginateQuery(
|
|
8589
8594
|
(vars) => GetUserAutopoolBalanceChangeHistory({
|
|
8590
8595
|
userAddress,
|
|
8591
|
-
vaultAddress:
|
|
8596
|
+
vaultAddress: autopool.poolAddress,
|
|
8592
8597
|
first: vars?.first || 1e3,
|
|
8593
8598
|
skip: vars?.skip || 0
|
|
8594
8599
|
}),
|
|
@@ -8607,7 +8612,7 @@ var getAutopoolUserActivity = async ({
|
|
|
8607
8612
|
totalWithdrawals: 0n,
|
|
8608
8613
|
totalStakes: 0n,
|
|
8609
8614
|
totalUnstakes: 0n,
|
|
8610
|
-
chainId
|
|
8615
|
+
chainId: autopool.chain?.chainId
|
|
8611
8616
|
};
|
|
8612
8617
|
}
|
|
8613
8618
|
activity.items.forEach((item) => {
|
|
@@ -8635,12 +8640,17 @@ var getAutopoolUserActivity = async ({
|
|
|
8635
8640
|
} else {
|
|
8636
8641
|
eventType = "Unknown";
|
|
8637
8642
|
}
|
|
8643
|
+
const netDeposits = formatUnitsNum6(
|
|
8644
|
+
userActivityTotals[activity.vaultAddress].totalDeposits - userActivityTotals[activity.vaultAddress].totalWithdrawals,
|
|
8645
|
+
autopool.baseAsset.decimals
|
|
8646
|
+
);
|
|
8638
8647
|
if (!item.staked) {
|
|
8639
8648
|
events.push({
|
|
8640
8649
|
timestamp: activity.timestamp,
|
|
8641
8650
|
shareChange: item.shareChange,
|
|
8642
8651
|
assetChange: item.assetChange,
|
|
8643
8652
|
vaultAddress: activity.vaultAddress,
|
|
8653
|
+
netDeposits,
|
|
8644
8654
|
eventType
|
|
8645
8655
|
// staked: item.staked,
|
|
8646
8656
|
});
|
|
@@ -8661,7 +8671,7 @@ import { autopoolEthAbi as autopoolEthAbi5 } from "@tokemak/abis";
|
|
|
8661
8671
|
import {
|
|
8662
8672
|
convertTimestampToDate as convertTimestampToDate4,
|
|
8663
8673
|
formatEtherNum as formatEtherNum14,
|
|
8664
|
-
formatUnitsNum as
|
|
8674
|
+
formatUnitsNum as formatUnitsNum7
|
|
8665
8675
|
} from "@tokemak/utils";
|
|
8666
8676
|
var getAutopoolUser = async (config, {
|
|
8667
8677
|
autopool,
|
|
@@ -8726,7 +8736,7 @@ var getAutopoolUser = async (config, {
|
|
|
8726
8736
|
prices
|
|
8727
8737
|
);
|
|
8728
8738
|
const totalDeposits = convertBaseAssetToTokenPricesAndDenom(
|
|
8729
|
-
|
|
8739
|
+
formatUnitsNum7(
|
|
8730
8740
|
userActivity?.totals[autopool?.poolAddress]?.totalDeposits || 0n,
|
|
8731
8741
|
autopool?.baseAsset.decimals
|
|
8732
8742
|
),
|
|
@@ -8735,7 +8745,7 @@ var getAutopoolUser = async (config, {
|
|
|
8735
8745
|
prices
|
|
8736
8746
|
);
|
|
8737
8747
|
const totalWithdrawals = convertBaseAssetToTokenPricesAndDenom(
|
|
8738
|
-
|
|
8748
|
+
formatUnitsNum7(
|
|
8739
8749
|
userActivity?.totals[autopool?.poolAddress]?.totalWithdrawals || 0n,
|
|
8740
8750
|
autopool?.baseAsset.decimals
|
|
8741
8751
|
),
|
|
@@ -8827,6 +8837,7 @@ var getAutopoolHistory = async (autopool) => {
|
|
|
8827
8837
|
};
|
|
8828
8838
|
|
|
8829
8839
|
// functions/getAutopoolUserHistory.ts
|
|
8840
|
+
import { formatEtherNum as formatEtherNum15, formatUnitsNum as formatUnitsNum8 } from "@tokemak/utils";
|
|
8830
8841
|
var getAutopoolUserHistory = async ({
|
|
8831
8842
|
userAddress,
|
|
8832
8843
|
autopool,
|
|
@@ -8872,27 +8883,42 @@ var getAutopoolUserHistory = async ({
|
|
|
8872
8883
|
};
|
|
8873
8884
|
filledMissingDates.unshift(dayBeforeEntry);
|
|
8874
8885
|
}
|
|
8886
|
+
let lastKnownNetDeposits = null;
|
|
8875
8887
|
const matchedData = filledMissingDates.map((userVaultDayData) => {
|
|
8876
8888
|
const matchingAutopoolDayData = autopoolDayData.find(
|
|
8877
8889
|
(autopoolDay) => autopoolDay.date.toDateString() === userVaultDayData.date.toDateString()
|
|
8878
8890
|
);
|
|
8879
|
-
const userPortionOfVault = userVaultDayData.totalShares / matchingAutopoolDayData?.totalSupply;
|
|
8880
|
-
const userNav = userPortionOfVault *
|
|
8891
|
+
const userPortionOfVault = formatEtherNum15(userVaultDayData.totalShares) / formatEtherNum15(matchingAutopoolDayData?.totalSupply);
|
|
8892
|
+
const userNav = userPortionOfVault * formatUnitsNum8(
|
|
8893
|
+
BigInt(matchingAutopoolDayData?.nav || 0),
|
|
8894
|
+
autopool?.baseAsset.decimals
|
|
8895
|
+
);
|
|
8881
8896
|
const eventsForDay = userActivity.events?.filter((event) => {
|
|
8882
8897
|
const eventDate = new Date(Number(event.timestamp) * 1e3);
|
|
8883
|
-
const windowStart = new Date(
|
|
8884
|
-
|
|
8898
|
+
const windowStart = new Date(userVaultDayData.date.getTime());
|
|
8899
|
+
const windowEnd = new Date(
|
|
8900
|
+
userVaultDayData.date.getTime() + 24 * 60 * 60 * 1e3
|
|
8885
8901
|
);
|
|
8886
|
-
const windowEnd = userVaultDayData.date;
|
|
8887
8902
|
const matches = eventDate.getTime() > windowStart.getTime() && eventDate.getTime() <= windowEnd.getTime();
|
|
8888
8903
|
return matches;
|
|
8889
8904
|
});
|
|
8905
|
+
const lastEventForDay = eventsForDay && eventsForDay.length > 0 ? eventsForDay.sort(
|
|
8906
|
+
(a, b) => Number(b.timestamp) - Number(a.timestamp)
|
|
8907
|
+
)[0] : 0;
|
|
8908
|
+
let netDeposits = 0;
|
|
8909
|
+
if (lastEventForDay && "netDeposits" in lastEventForDay && typeof lastEventForDay.netDeposits === "number") {
|
|
8910
|
+
netDeposits = lastEventForDay.netDeposits;
|
|
8911
|
+
lastKnownNetDeposits = netDeposits;
|
|
8912
|
+
} else {
|
|
8913
|
+
netDeposits = lastKnownNetDeposits;
|
|
8914
|
+
}
|
|
8890
8915
|
return {
|
|
8891
8916
|
date: userVaultDayData.date,
|
|
8892
8917
|
timestamp: userVaultDayData.timestamp,
|
|
8893
8918
|
baseAsset: autopool?.baseAsset.symbol,
|
|
8894
8919
|
nav: userNav,
|
|
8895
|
-
events: eventsForDay
|
|
8920
|
+
events: eventsForDay,
|
|
8921
|
+
netDeposits
|
|
8896
8922
|
};
|
|
8897
8923
|
});
|
|
8898
8924
|
return matchedData;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokemak/queries",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"main": "./dist/index.cjs",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
"@wagmi/core": "2.x",
|
|
27
27
|
"wagmi": "2.x",
|
|
28
28
|
"@tokemak/abis": "0.0.3",
|
|
29
|
-
"@tokemak/constants": "0.0.4",
|
|
30
|
-
"@tokemak/graph-cli": "0.0.10",
|
|
31
29
|
"@tokemak/config": "0.0.4",
|
|
32
30
|
"@tokemak/tokenlist": "0.0.3",
|
|
33
|
-
"@tokemak/
|
|
31
|
+
"@tokemak/constants": "0.0.4",
|
|
32
|
+
"@tokemak/utils": "0.0.5",
|
|
33
|
+
"@tokemak/graph-cli": "0.0.10"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "tsup",
|