@turtleclub/hooks 0.5.0-beta.8 → 0.5.0-beta.9

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
@@ -866,13 +866,180 @@ var widgetQueries = createQueryKeys8("widget", {
866
866
  })
867
867
  });
868
868
 
869
- // src/v2/supported-chains/queries.ts
869
+ // src/v2/streams/queries.ts
870
870
  import { createQueryKeys as createQueryKeys9 } from "@lukemorales/query-key-factory";
871
871
 
872
- // src/v2/supported-chains/schema.ts
872
+ // src/v2/streams/schemas.ts
873
873
  import { z as z10 } from "zod";
874
- var supportedChainsResponseSchema = z10.object({
875
- chains: z10.array(chainSchema)
874
+ var snapshotSchema = z10.object({
875
+ amountDistributed: z10.string(),
876
+ createdAt: z10.string().datetime(),
877
+ rootHash: z10.string().nullable(),
878
+ timestamp: z10.string().datetime(),
879
+ updatedAt: z10.string().datetime(),
880
+ userCount: z10.number().optional()
881
+ });
882
+ var customArgsTokensPerUsdSchema = z10.object({
883
+ tokensPerUSD: z10.string(),
884
+ targetChainId: z10.number(),
885
+ targetTokenAddress: z10.string()
886
+ });
887
+ var customArgsAprSchema = z10.object({
888
+ apr: z10.string(),
889
+ targetChainId: z10.number(),
890
+ targetTokenAddress: z10.string()
891
+ });
892
+ var streamSchema = z10.object({
893
+ admin: z10.string(),
894
+ chainId: z10.number(),
895
+ chargedFee: z10.string(),
896
+ contractAddress: z10.string(),
897
+ createdAt: z10.string().datetime(),
898
+ customArgs: z10.union([customArgsTokensPerUsdSchema, customArgsAprSchema]),
899
+ deletedAt: z10.string().datetime().nullable(),
900
+ endTimestamp: z10.string().datetime(),
901
+ finalizationTimestamp: z10.string().datetime(),
902
+ id: z10.string().uuid(),
903
+ isPaused: z10.boolean(),
904
+ lastSnapshot: snapshotSchema.nullable(),
905
+ orgId: z10.string().uuid(),
906
+ rewardToken: z10.string(),
907
+ snapshots: z10.array(snapshotSchema).optional(),
908
+ startTimestamp: z10.string().datetime(),
909
+ strategy: z10.string(),
910
+ totalAmount: z10.string(),
911
+ type: z10.number(),
912
+ updatedAt: z10.string().datetime(),
913
+ userId: z10.string().uuid()
914
+ });
915
+ var getStreamsOutputSchema = z10.object({
916
+ streams: z10.array(streamSchema)
917
+ });
918
+ var getStreamsSupportedChainsOutputSchema = z10.object({
919
+ success: z10.boolean(),
920
+ chains: z10.array(
921
+ z10.object({
922
+ id: z10.string(),
923
+ name: z10.string(),
924
+ slug: z10.string(),
925
+ chainId: z10.number(),
926
+ logoUrl: z10.string(),
927
+ ecosystem: z10.string(),
928
+ status: z10.string(),
929
+ explorerUrl: z10.string(),
930
+ campaignFactory: z10.string()
931
+ // Address as string
932
+ })
933
+ )
934
+ });
935
+ var streamSignatureRequestInputSchema = z10.object({
936
+ campaignType: z10.number(),
937
+ chainId: z10.number(),
938
+ customArgs: z10.intersection(
939
+ z10.object({
940
+ targetChainId: z10.number(),
941
+ targetTokenAddress: z10.string()
942
+ }),
943
+ z10.union([z10.object({ tokensPerUsd: z10.string() }), z10.object({ apr: z10.string() })])
944
+ ),
945
+ endTimestamp: z10.string(),
946
+ finalizationTimestamp: z10.string(),
947
+ rewardToken: z10.string(),
948
+ startTimestamp: z10.string(),
949
+ totalAmount: z10.string(),
950
+ walletAddress: z10.string()
951
+ });
952
+ var streamSignatureRequestOutputSchema = z10.object({
953
+ success: z10.boolean(),
954
+ message: z10.string(),
955
+ txParams: z10.object({
956
+ chainId: z10.number(),
957
+ sender: z10.string(),
958
+ params: z10.object({
959
+ params: z10.object({
960
+ UserId: z10.array(z10.number()),
961
+ OrgId: z10.array(z10.number()),
962
+ CampaignType: z10.number(),
963
+ RewardToken: z10.string(),
964
+ TotalAmount: z10.number(),
965
+ FeeBps: z10.number(),
966
+ StartTimestamp: z10.number(),
967
+ EndTimestamp: z10.number(),
968
+ FinalizationTimestamp: z10.number(),
969
+ CampaignData: z10.string()
970
+ }),
971
+ signature: z10.string(),
972
+ salt: z10.string(),
973
+ deadline: z10.number()
974
+ })
975
+ })
976
+ });
977
+ var getStreamsQuerySchema = z10.object({
978
+ streamId: z10.string().optional(),
979
+ userId: z10.string().optional(),
980
+ organizationId: z10.string().optional(),
981
+ withSnapshots: z10.boolean().optional(),
982
+ usersCount: z10.boolean().optional()
983
+ });
984
+
985
+ // src/v2/streams/api.ts
986
+ async function getStreams(query) {
987
+ const params = new URLSearchParams();
988
+ if (query?.streamId) params.set("id", query.streamId);
989
+ if (query?.userId) params.set("userId", query.userId);
990
+ if (query?.organizationId) params.set("organizationId", query.organizationId);
991
+ if (query?.withSnapshots) params.append("withSnapshots", "true");
992
+ if (query?.usersCount && query?.withSnapshots) params.append("usersCount", "true");
993
+ const queryString = params.toString();
994
+ const endpoint = `/streams${queryString ? `?${queryString}` : ""}`;
995
+ const data = await apiClient.fetch(endpoint, { method: "GET" });
996
+ const result = getStreamsOutputSchema.safeParse(data);
997
+ if (!result.success) {
998
+ throw new Error(`Failed to parse streams: ${result.error.message}`);
999
+ }
1000
+ return result.data.streams;
1001
+ }
1002
+ async function getStreamsSupportedChains() {
1003
+ const endpoint = "/streams/supported_chains";
1004
+ const data = await apiClient.fetch(endpoint, { method: "GET" });
1005
+ const result = getStreamsSupportedChainsOutputSchema.safeParse(data);
1006
+ if (!result.success) {
1007
+ throw new Error(`Failed to parse supported chains: ${result.error.message}`);
1008
+ }
1009
+ return result.data.chains;
1010
+ }
1011
+ async function requestStreamSignature(organizationId, input) {
1012
+ const endpoint = `/streams/request_signature/${organizationId}`;
1013
+ const data = await apiClient.fetch(endpoint, {
1014
+ method: "POST",
1015
+ body: input
1016
+ });
1017
+ const result = streamSignatureRequestOutputSchema.safeParse(data);
1018
+ if (!result.success) {
1019
+ throw new Error(`Failed to parse signature response: ${result.error.message}`);
1020
+ }
1021
+ return result.data;
1022
+ }
1023
+
1024
+ // src/v2/streams/queries.ts
1025
+ var streamsQueries = createQueryKeys9("streams", {
1026
+ list: (query) => ({
1027
+ queryKey: [query ?? "all"],
1028
+ queryFn: () => getStreams(query)
1029
+ }),
1030
+ supportedChains: {
1031
+ queryKey: null,
1032
+ queryFn: () => getStreamsSupportedChains()
1033
+ }
1034
+ });
1035
+
1036
+ // src/v2/supported-chains/queries.ts
1037
+ import { createQueryKeys as createQueryKeys10 } from "@lukemorales/query-key-factory";
1038
+
1039
+ // src/v2/supported-chains/schema.ts
1040
+ import { z as z11 } from "zod";
1041
+ var supportedChainsResponseSchema = z11.object({
1042
+ chains: z11.array(chainSchema)
876
1043
  });
877
1044
 
878
1045
  // src/v2/supported-chains/api.ts
@@ -890,7 +1057,7 @@ async function getSupportedChains(options) {
890
1057
  }
891
1058
 
892
1059
  // src/v2/supported-chains/queries.ts
893
- var supportedChainsQueries = createQueryKeys9("supportedChains", {
1060
+ var supportedChainsQueries = createQueryKeys10("supportedChains", {
894
1061
  all: {
895
1062
  queryKey: null,
896
1063
  queryFn: () => getSupportedChains()
@@ -898,18 +1065,18 @@ var supportedChainsQueries = createQueryKeys9("supportedChains", {
898
1065
  });
899
1066
 
900
1067
  // src/v2/supported-tokens/queries.ts
901
- import { createQueryKeys as createQueryKeys10 } from "@lukemorales/query-key-factory";
1068
+ import { createQueryKeys as createQueryKeys11 } from "@lukemorales/query-key-factory";
902
1069
 
903
1070
  // src/v2/supported-tokens/schema.ts
904
- import { z as z11 } from "zod";
1071
+ import { z as z12 } from "zod";
905
1072
  var supportedTokenSchema = tokenSchema.extend({
906
- active: z11.boolean()
1073
+ active: z12.boolean()
907
1074
  });
908
- var supportedTokensResponseSchema = z11.object({
909
- tokens: z11.array(supportedTokenSchema),
910
- total: z11.number().optional(),
911
- limit: z11.number().optional(),
912
- page: z11.number().optional()
1075
+ var supportedTokensResponseSchema = z12.object({
1076
+ tokens: z12.array(supportedTokenSchema),
1077
+ total: z12.number().optional(),
1078
+ limit: z12.number().optional(),
1079
+ page: z12.number().optional()
913
1080
  });
914
1081
 
915
1082
  // src/v2/supported-tokens/api.ts
@@ -933,7 +1100,7 @@ async function getSupportedTokens(filters, options) {
933
1100
  }
934
1101
 
935
1102
  // src/v2/supported-tokens/queries.ts
936
- var supportedTokensQueries = createQueryKeys10("supportedTokens", {
1103
+ var supportedTokensQueries = createQueryKeys11("supportedTokens", {
937
1104
  list: (filters) => ({
938
1105
  queryKey: [filters],
939
1106
  queryFn: () => getSupportedTokens(filters)
@@ -941,72 +1108,72 @@ var supportedTokensQueries = createQueryKeys10("supportedTokens", {
941
1108
  });
942
1109
 
943
1110
  // src/v2/users/queries.ts
944
- import { createQueryKeys as createQueryKeys11 } from "@lukemorales/query-key-factory";
1111
+ import { createQueryKeys as createQueryKeys12 } from "@lukemorales/query-key-factory";
945
1112
 
946
1113
  // src/v2/users/schemas.ts
947
- import { z as z12 } from "zod";
948
- var walletDataSchema = z12.object({
949
- address: z12.string(),
950
- totalAmountInUSD: z12.string(),
951
- tokens: z12.array(tokenSchema)
952
- });
953
- var holdingsDataSchema = z12.object({
954
- totalAmountInUSD: z12.string(),
955
- chains: z12.array(chainSchema).nullish(),
956
- wallets: z12.array(walletDataSchema).nullish()
957
- });
958
- var userEarningsSchema = z12.object({
959
- productId: z12.string().uuid(),
960
- value: z12.number(),
961
- referralsEarnings: z12.number().nullish(),
962
- rewardName: z12.string().nullish(),
963
- rewardType: z12.string().nullish()
964
- });
965
- var portfolioSchema = z12.object({
966
- productsEarnings: z12.array(userEarningsSchema),
1114
+ import { z as z13 } from "zod";
1115
+ var walletDataSchema = z13.object({
1116
+ address: z13.string(),
1117
+ totalAmountInUSD: z13.string(),
1118
+ tokens: z13.array(tokenSchema)
1119
+ });
1120
+ var holdingsDataSchema = z13.object({
1121
+ totalAmountInUSD: z13.string(),
1122
+ chains: z13.array(chainSchema).nullish(),
1123
+ wallets: z13.array(walletDataSchema).nullish()
1124
+ });
1125
+ var userEarningsSchema = z13.object({
1126
+ productId: z13.string().uuid(),
1127
+ value: z13.number(),
1128
+ referralsEarnings: z13.number().nullish(),
1129
+ rewardName: z13.string().nullish(),
1130
+ rewardType: z13.string().nullish()
1131
+ });
1132
+ var portfolioSchema = z13.object({
1133
+ productsEarnings: z13.array(userEarningsSchema),
967
1134
  holdings: holdingsDataSchema.nullish()
968
1135
  });
969
- var holdingInfoSchema = z12.object({
970
- amount: z12.number(),
971
- usdValue: z12.number(),
1136
+ var holdingInfoSchema = z13.object({
1137
+ amount: z13.number(),
1138
+ usdValue: z13.number(),
972
1139
  token: tokenSchema.nullish()
973
1140
  });
974
- var walletInfoSchema = z12.object({
975
- address: z12.string().nullish(),
976
- ecosystem: z12.string().nullish(),
977
- isMain: z12.boolean().nullish(),
978
- holdings: z12.array(holdingInfoSchema).nullish()
979
- });
980
- var userWithDetailsSchema = z12.object({
981
- id: z12.string(),
982
- email: z12.string().nullable(),
983
- username: z12.string().nullish(),
984
- firstName: z12.string().nullish(),
985
- lastName: z12.string().nullish(),
986
- avatarUrl: z12.string().nullish(),
987
- telegramHandle: z12.string().nullish(),
988
- xUsername: z12.string().nullish(),
989
- role: z12.string(),
990
- createdAt: z12.string(),
991
- updatedAt: z12.string(),
992
- tags: z12.array(z12.string()).nullish(),
993
- wallets: z12.array(walletInfoSchema).nullish()
994
- });
995
- var getUserTurtlePortfolioInputSchema = z12.object({
996
- userId: z12.string().uuid()
997
- });
998
- var getUserTurtlePortfolioOutputSchema = z12.object({
1141
+ var walletInfoSchema = z13.object({
1142
+ address: z13.string().nullish(),
1143
+ ecosystem: z13.string().nullish(),
1144
+ isMain: z13.boolean().nullish(),
1145
+ holdings: z13.array(holdingInfoSchema).nullish()
1146
+ });
1147
+ var userWithDetailsSchema = z13.object({
1148
+ id: z13.string(),
1149
+ email: z13.string().nullable(),
1150
+ username: z13.string().nullish(),
1151
+ firstName: z13.string().nullish(),
1152
+ lastName: z13.string().nullish(),
1153
+ avatarUrl: z13.string().nullish(),
1154
+ telegramHandle: z13.string().nullish(),
1155
+ xUsername: z13.string().nullish(),
1156
+ role: z13.string(),
1157
+ createdAt: z13.string(),
1158
+ updatedAt: z13.string(),
1159
+ tags: z13.array(z13.string()).nullish(),
1160
+ wallets: z13.array(walletInfoSchema).nullish()
1161
+ });
1162
+ var getUserTurtlePortfolioInputSchema = z13.object({
1163
+ userId: z13.string().uuid()
1164
+ });
1165
+ var getUserTurtlePortfolioOutputSchema = z13.object({
999
1166
  portfolio: portfolioSchema
1000
1167
  });
1001
- var getUserTurtlePortfolioPathSchema = z12.object({
1002
- userId: z12.string().uuid()
1168
+ var getUserTurtlePortfolioPathSchema = z13.object({
1169
+ userId: z13.string().uuid()
1003
1170
  });
1004
- var getUserByIdInputSchema = z12.object({
1005
- userId: z12.string().uuid()
1171
+ var getUserByIdInputSchema = z13.object({
1172
+ userId: z13.string().uuid()
1006
1173
  });
1007
- var getUserByIdOutputSchema = z12.object({
1174
+ var getUserByIdOutputSchema = z13.object({
1008
1175
  user: userWithDetailsSchema.nullable(),
1009
- error: z12.string().optional()
1176
+ error: z13.string().optional()
1010
1177
  });
1011
1178
 
1012
1179
  // src/v2/users/api.ts
@@ -1037,7 +1204,7 @@ async function getUserPortfolio(input) {
1037
1204
  }
1038
1205
 
1039
1206
  // src/v2/users/queries.ts
1040
- var usersQueries = createQueryKeys11("users", {
1207
+ var usersQueries = createQueryKeys12("users", {
1041
1208
  byId: (input) => ({
1042
1209
  queryKey: [input.userId],
1043
1210
  queryFn: () => getUserById(input)
@@ -1062,6 +1229,13 @@ var queryDefaults = {
1062
1229
  refetchOnWindowFocus: false
1063
1230
  // Don't refetch on tab focus
1064
1231
  };
1232
+ function createQueryOptions(queryConfig, options) {
1233
+ return {
1234
+ ...queryDefaults,
1235
+ ...queryConfig,
1236
+ ...options
1237
+ };
1238
+ }
1065
1239
 
1066
1240
  // src/v2/earn-opportunities/hooks.ts
1067
1241
  function useEarnOpportunities() {
@@ -1293,33 +1467,33 @@ var BalanceSourcePriority = /* @__PURE__ */ ((BalanceSourcePriority2) => {
1293
1467
  })(BalanceSourcePriority || {});
1294
1468
 
1295
1469
  // src/v2/balance/schema.ts
1296
- import { z as z13 } from "zod";
1297
- var portfolioTokenSchema = z13.object({
1298
- id: z13.string(),
1299
- address: z13.string(),
1300
- name: z13.string(),
1301
- symbol: z13.string(),
1302
- decimals: z13.number(),
1303
- isNative: z13.boolean(),
1304
- logoUrl: z13.string().nullable(),
1305
- amount: z13.string(),
1470
+ import { z as z14 } from "zod";
1471
+ var portfolioTokenSchema = z14.object({
1472
+ id: z14.string(),
1473
+ address: z14.string(),
1474
+ name: z14.string(),
1475
+ symbol: z14.string(),
1476
+ decimals: z14.number(),
1477
+ isNative: z14.boolean(),
1478
+ logoUrl: z14.string().nullable(),
1479
+ amount: z14.string(),
1306
1480
  // Portfolio-specific field (decimal format)
1307
- price: z13.string().nullable().transform((val) => val ? parseFloat(val) : null),
1481
+ price: z14.string().nullable().transform((val) => val ? parseFloat(val) : null),
1308
1482
  // Portfolio-specific field
1309
1483
  // Chain with optional fields to match Portfolio API response
1310
1484
  chain: chainSchema.partial().required({ chainId: true })
1311
1485
  });
1312
- var portfolioWalletSchema = z13.object({
1313
- id: z13.string().optional(),
1314
- address: z13.string(),
1315
- blockchain: z13.string().optional(),
1316
- tokens: z13.array(portfolioTokenSchema)
1486
+ var portfolioWalletSchema = z14.object({
1487
+ id: z14.string().optional(),
1488
+ address: z14.string(),
1489
+ blockchain: z14.string().optional(),
1490
+ tokens: z14.array(portfolioTokenSchema)
1317
1491
  });
1318
- var portfolioHoldingsSchema = z13.object({
1319
- wallets: z13.array(portfolioWalletSchema)
1492
+ var portfolioHoldingsSchema = z14.object({
1493
+ wallets: z14.array(portfolioWalletSchema)
1320
1494
  });
1321
- var portfolioBalanceResponseSchema = z13.object({
1322
- portfolio: z13.object({
1495
+ var portfolioBalanceResponseSchema = z14.object({
1496
+ portfolio: z14.object({
1323
1497
  holdings: portfolioHoldingsSchema
1324
1498
  })
1325
1499
  });
@@ -1340,8 +1514,8 @@ async function getPortfolioBalance(address, options) {
1340
1514
  }
1341
1515
 
1342
1516
  // src/v2/balance/queries.ts
1343
- import { createQueryKeys as createQueryKeys12 } from "@lukemorales/query-key-factory";
1344
- var balanceQueries = createQueryKeys12("balance", {
1517
+ import { createQueryKeys as createQueryKeys13 } from "@lukemorales/query-key-factory";
1518
+ var balanceQueries = createQueryKeys13("balance", {
1345
1519
  // Portfolio balance by address
1346
1520
  portfolio: (address) => ({
1347
1521
  queryKey: [address],
@@ -1789,6 +1963,21 @@ function useGeocheck(options = {}) {
1789
1963
  });
1790
1964
  }
1791
1965
 
1966
+ // src/v2/streams/hooks.ts
1967
+ import { useQuery as useQuery12, useMutation as useMutation3 } from "@tanstack/react-query";
1968
+ function useStreams({ query, ...options } = {}) {
1969
+ return useQuery12(createQueryOptions(streamsQueries.list(query), options));
1970
+ }
1971
+ function useStreamSupportedChains(options) {
1972
+ return useQuery12(createQueryOptions(streamsQueries.supportedChains, options));
1973
+ }
1974
+ function useRequestStreamSignature(options) {
1975
+ return useMutation3({
1976
+ mutationFn: ({ organizationId, data }) => requestStreamSignature(organizationId, data),
1977
+ ...options
1978
+ });
1979
+ }
1980
+
1792
1981
  // src/v2/swap/useSwapRoute.ts
1793
1982
  import { useMemo as useMemo8 } from "react";
1794
1983
 
@@ -1888,9 +2077,9 @@ function useSwapRoute(isEnabled, userAddress, distributorId, options, referralCo
1888
2077
  }
1889
2078
 
1890
2079
  // src/v2/users/hooks.ts
1891
- import { useQuery as useQuery12 } from "@tanstack/react-query";
2080
+ import { useQuery as useQuery13 } from "@tanstack/react-query";
1892
2081
  function useUserById({ userId, enabled = true }) {
1893
- return useQuery12({
2082
+ return useQuery13({
1894
2083
  ...usersQueries.byId({ userId }),
1895
2084
  ...queryDefaults,
1896
2085
  enabled
@@ -1898,7 +2087,7 @@ function useUserById({ userId, enabled = true }) {
1898
2087
  }
1899
2088
  function useUserPortfolio({ userId, enabled = true }) {
1900
2089
  const input = { userId };
1901
- return useQuery12({
2090
+ return useQuery13({
1902
2091
  ...usersQueries.portfolio(input),
1903
2092
  ...queryDefaults,
1904
2093
  enabled
@@ -1935,6 +2124,7 @@ var queries = mergeQueryKeys(
1935
2124
  productsQueries,
1936
2125
  ensoBalancesQueries,
1937
2126
  widgetQueries,
2127
+ streamsQueries,
1938
2128
  supportedChainsQueries,
1939
2129
  supportedTokensQueries,
1940
2130
  usersQueries
@@ -1984,6 +2174,11 @@ export {
1984
2174
  getPortfolioBalance,
1985
2175
  getProducts,
1986
2176
  getSourcePriority,
2177
+ getStreams,
2178
+ getStreamsOutputSchema,
2179
+ getStreamsQuerySchema,
2180
+ getStreamsSupportedChains,
2181
+ getStreamsSupportedChainsOutputSchema,
1987
2182
  getSupportedChains,
1988
2183
  getSupportedTokens,
1989
2184
  getUserById,
@@ -2012,10 +2207,16 @@ export {
2012
2207
  productSchema,
2013
2208
  productsQueries,
2014
2209
  queries,
2210
+ requestStreamSignature,
2015
2211
  routeToken,
2016
2212
  routerStep,
2017
2213
  routerSubstep,
2214
+ snapshotSchema,
2018
2215
  stepTx,
2216
+ streamSchema,
2217
+ streamSignatureRequestInputSchema,
2218
+ streamSignatureRequestOutputSchema,
2219
+ streamsQueries,
2019
2220
  supportedChainsQueries,
2020
2221
  supportedChainsResponseSchema,
2021
2222
  supportedTokenSchema,
@@ -2041,6 +2242,9 @@ export {
2041
2242
  usePortfolioBalance,
2042
2243
  useProduct,
2043
2244
  useProducts,
2245
+ useRequestStreamSignature,
2246
+ useStreamSupportedChains,
2247
+ useStreams,
2044
2248
  useSupportedChains,
2045
2249
  useSupportedTokens,
2046
2250
  useSwapRoute,