@latticexyz/entrykit 2.2.22-fc522a899c932f53675e624805e97a4eeefca9e8 → 2.2.22

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.
@@ -139,8 +139,11 @@ var debug2 = debug.extend("quarry");
139
139
 
140
140
  // src/quarry/transports/userOpExecutor.ts
141
141
  import { setBalance } from "viem/actions";
142
- function userOpExecutor({ executor }) {
143
- return () => {
142
+ function userOpExecutor({
143
+ executor,
144
+ fallbackDefaultTransport
145
+ }) {
146
+ return (opts) => {
144
147
  debug2("using a local user op executor", executor.account.address);
145
148
  if (executor.chain.id === 31337) {
146
149
  debug2("setting executor balance");
@@ -175,7 +178,9 @@ function userOpExecutor({ executor }) {
175
178
  if (method === "eth_estimateUserOperationGas") {
176
179
  return await estimateUserOperationGas(params);
177
180
  }
178
- throw new Error(`userOpExecutor: method "${method}" not supported`);
181
+ debug2(`userOpExecutor: method "${method}" not overridden, falling back to fallback transport`);
182
+ const { request: fallbackRequest } = fallbackDefaultTransport(opts);
183
+ return fallbackRequest({ method, params });
179
184
  };
180
185
  return createTransport({
181
186
  key: "userOpExecutor",
@@ -187,20 +192,27 @@ function userOpExecutor({ executor }) {
187
192
  }
188
193
 
189
194
  // src/getBundlerTransport.ts
195
+ import { wiresaw } from "@latticexyz/common/internal";
190
196
  function getBundlerTransport(chain) {
197
+ if ("wiresaw" in chain.rpcUrls) {
198
+ return wiresaw();
199
+ }
191
200
  const bundlerHttpUrl = chain.rpcUrls.bundler?.http[0];
192
- const bundlerTransport = bundlerHttpUrl ? http(bundlerHttpUrl) : chain.id === 31337 ? userOpExecutor({
193
- executor: createClient({
194
- chain,
195
- transport: fallback([webSocket(), http()]),
196
- account: privateKeyToAccount(keccak256(stringToHex("local user op executor"))),
197
- pollingInterval: 10
198
- }).extend(transactionQueue())
199
- }) : null;
200
- if (!bundlerTransport) {
201
- throw new Error(`Chain ${chain.id} config did not include a bundler RPC URL.`);
201
+ if (bundlerHttpUrl) {
202
+ return http(bundlerHttpUrl);
202
203
  }
203
- return bundlerTransport;
204
+ if (chain.id === 31337) {
205
+ return userOpExecutor({
206
+ executor: createClient({
207
+ chain,
208
+ transport: fallback([webSocket(), http()]),
209
+ account: privateKeyToAccount(keccak256(stringToHex("local user op executor"))),
210
+ pollingInterval: 10
211
+ }).extend(transactionQueue()),
212
+ fallbackDefaultTransport: http()
213
+ });
214
+ }
215
+ throw new Error(`Chain ${chain.id} config did not include a bundler RPC URL.`);
204
216
  }
205
217
 
206
218
  // src/EntryKitConfigProvider.tsx
@@ -550,39 +562,13 @@ import { useEffect as useEffect15, useMemo as useMemo4, useRef as useRef5, useSt
550
562
  import { twMerge as twMerge18 } from "tailwind-merge";
551
563
 
552
564
  // src/onboarding/usePrerequisites.ts
553
- import { useClient as useClient6, useConfig } from "wagmi";
554
- import { getBalanceQueryOptions as getBalanceQueryOptions2 } from "wagmi/query";
555
- import { queryOptions as queryOptions6, skipToken as skipToken6, useQuery as useQuery7, useQueryClient } from "@tanstack/react-query";
565
+ import { useClient as useClient7, useConfig as useConfig2 } from "wagmi";
566
+ import { queryOptions as queryOptions7, useQuery as useQuery8, useQueryClient as useQueryClient2 } from "@tanstack/react-query";
556
567
 
557
- // src/getPaymaster.ts
558
- function getPaymaster(chain) {
559
- const contracts = chain.contracts ?? {};
560
- if ("quarryPaymaster" in contracts && contracts.quarryPaymaster != null) {
561
- if ("address" in contracts.quarryPaymaster) {
562
- return {
563
- type: "quarry",
564
- address: contracts.quarryPaymaster.address,
565
- isGasPass: !!chain.rpcUrls.quarryPassIssuer?.http?.[0]
566
- };
567
- }
568
- }
569
- if ("paymaster" in contracts && contracts.paymaster != null) {
570
- if ("address" in contracts.paymaster) {
571
- return {
572
- type: "simple",
573
- address: contracts.paymaster.address
574
- };
575
- }
576
- }
577
- }
578
-
579
- // src/onboarding/quarry/useAllowance.ts
568
+ // src/onboarding/quarry/useSpender.ts
580
569
  import { useClient } from "wagmi";
581
570
  import { queryOptions, skipToken, useQuery as useQuery2 } from "@tanstack/react-query";
582
571
 
583
- // src/quarry/getAllowance.ts
584
- import { numberToHex as numberToHex2 } from "viem";
585
-
586
572
  // src/quarry/common.ts
587
573
  import { defineStore } from "@latticexyz/store";
588
574
  import { parseAbi } from "viem";
@@ -659,64 +645,36 @@ var paymasterConfig = defineStore({
659
645
  });
660
646
  var paymasterTables = paymasterConfig.namespaces.root.tables;
661
647
 
662
- // src/quarry/getAllowance.ts
663
- import { getRecord, getStaticDataLocation } from "@latticexyz/store/internal";
664
- import { getKeyTuple } from "@latticexyz/protocol-parser/internal";
665
- import { setStorageAt } from "viem/actions";
666
- async function getAllowance({ client, userAddress }) {
667
- const paymaster = getPaymaster(client.chain);
668
- if (paymaster?.type !== "quarry") return null;
669
- const record = await getRecord(client, {
670
- address: paymaster.address,
671
- table: paymasterTables.Allowance,
672
- key: { user: userAddress },
673
- blockTag: "pending"
674
- });
675
- return record.allowance;
676
- }
677
- async function setAllowanceSlot({ client, userAddress, allowance }) {
678
- const paymaster = getPaymaster(client.chain);
679
- if (paymaster?.type !== "quarry") return;
680
- const slot = getStaticDataLocation(
681
- paymasterTables.Allowance.tableId,
682
- getKeyTuple(paymasterTables.Allowance, { user: userAddress })
683
- );
684
- await setStorageAt(
685
- client.extend(() => ({ mode: "anvil" })),
686
- {
687
- address: paymaster.address,
688
- index: slot,
689
- value: numberToHex2(allowance, { size: 32 })
690
- }
691
- );
692
- }
648
+ // src/onboarding/quarry/getSpender.ts
649
+ import { getRecord } from "@latticexyz/store/internal";
693
650
 
694
- // src/onboarding/quarry/useAllowance.ts
695
- function getAllowanceQueryOptions({
696
- client,
697
- userAddress
698
- }) {
699
- return queryOptions({
700
- queryKey: ["getAllowance", client?.uid, userAddress],
701
- queryFn: client && userAddress ? () => getAllowance({ client, userAddress }) : skipToken
702
- });
703
- }
704
- function useAllowance(userAddress) {
705
- const { chainId } = useEntryKitConfig();
706
- const client = useClient({ chainId });
707
- return useQuery2(getAllowanceQueryOptions({ client, userAddress }));
651
+ // src/getPaymaster.ts
652
+ function getPaymaster(chain) {
653
+ const contracts = chain.contracts ?? {};
654
+ if ("quarryPaymaster" in contracts && contracts.quarryPaymaster != null) {
655
+ if ("address" in contracts.quarryPaymaster) {
656
+ return {
657
+ type: "quarry",
658
+ address: contracts.quarryPaymaster.address,
659
+ isGasPass: !!chain.rpcUrls.quarryPassIssuer?.http?.[0]
660
+ };
661
+ }
662
+ }
663
+ if ("paymaster" in contracts && contracts.paymaster != null) {
664
+ if ("address" in contracts.paymaster) {
665
+ return {
666
+ type: "simple",
667
+ address: contracts.paymaster.address
668
+ };
669
+ }
670
+ }
708
671
  }
709
672
 
710
- // src/onboarding/quarry/useSpender.ts
711
- import { useClient as useClient2 } from "wagmi";
712
- import { queryOptions as queryOptions2, skipToken as skipToken2, useQuery as useQuery3 } from "@tanstack/react-query";
713
-
714
673
  // src/onboarding/quarry/getSpender.ts
715
- import { getRecord as getRecord2 } from "@latticexyz/store/internal";
716
674
  async function getSpender({ client, userAddress, sessionAddress }) {
717
675
  const paymaster = getPaymaster(client.chain);
718
676
  if (paymaster?.type !== "quarry") return null;
719
- const record = await getRecord2(client, {
677
+ const record = await getRecord(client, {
720
678
  address: paymaster.address,
721
679
  table: paymasterTables.Spender,
722
680
  key: { spender: sessionAddress },
@@ -731,18 +689,18 @@ function getSpenderQueryOptions({
731
689
  userAddress,
732
690
  sessionAddress
733
691
  }) {
734
- return queryOptions2({
692
+ return queryOptions({
735
693
  queryKey: ["getSpender", client?.uid, userAddress, sessionAddress],
736
- queryFn: client && userAddress && sessionAddress ? () => getSpender({ client, userAddress, sessionAddress }) : skipToken2
694
+ queryFn: client && userAddress && sessionAddress ? () => getSpender({ client, userAddress, sessionAddress }) : skipToken
737
695
  });
738
696
  }
739
697
 
740
698
  // src/onboarding/useDelegation.ts
741
- import { useClient as useClient3 } from "wagmi";
742
- import { queryOptions as queryOptions3, skipToken as skipToken3, useQuery as useQuery4 } from "@tanstack/react-query";
699
+ import { useClient as useClient2 } from "wagmi";
700
+ import { queryOptions as queryOptions2, skipToken as skipToken2, useQuery as useQuery3 } from "@tanstack/react-query";
743
701
 
744
702
  // src/onboarding/getDelegation.ts
745
- import { getRecord as getRecord3 } from "@latticexyz/store/internal";
703
+ import { getRecord as getRecord2 } from "@latticexyz/store/internal";
746
704
 
747
705
  // src/common.ts
748
706
  import { resourceToHex } from "@latticexyz/common";
@@ -766,7 +724,7 @@ async function getDelegation({
766
724
  // TODO: move everything to latest instead of pending
767
725
  blockTag = "pending"
768
726
  }) {
769
- const record = await getRecord3(client, {
727
+ const record = await getRecord2(client, {
770
728
  address: worldAddress,
771
729
  table: worldTables.UserDelegationControl,
772
730
  key: { delegator: userAddress, delegatee: sessionAddress },
@@ -782,15 +740,15 @@ function getDelegationQueryOptions({
782
740
  userAddress,
783
741
  sessionAddress
784
742
  }) {
785
- return queryOptions3({
743
+ return queryOptions2({
786
744
  queryKey: ["getDelegation", client?.uid, worldAddress, userAddress, sessionAddress],
787
- queryFn: client && userAddress && sessionAddress ? () => getDelegation({ client, worldAddress, userAddress, sessionAddress }) : skipToken3
745
+ queryFn: client && userAddress && sessionAddress ? () => getDelegation({ client, worldAddress, userAddress, sessionAddress }) : skipToken2
788
746
  });
789
747
  }
790
748
 
791
749
  // src/useSessionAccount.ts
792
- import { useClient as useClient4 } from "wagmi";
793
- import { queryOptions as queryOptions4, skipToken as skipToken4, useQuery as useQuery5 } from "@tanstack/react-query";
750
+ import { useClient as useClient3 } from "wagmi";
751
+ import { queryOptions as queryOptions3, skipToken as skipToken3, useQuery as useQuery4 } from "@tanstack/react-query";
794
752
 
795
753
  // src/getSessionAccount.ts
796
754
  import { toSimpleSmartAccount } from "permissionless/accounts";
@@ -854,15 +812,73 @@ function getSessionAccountQueryOptions({
854
812
  client,
855
813
  userAddress
856
814
  }) {
857
- return queryOptions4({
815
+ return queryOptions3({
858
816
  queryKey: ["getSessionAccount", client?.uid, userAddress],
859
- queryFn: client && userAddress ? () => getSessionAccount({ client, userAddress }) : skipToken4,
817
+ queryFn: client && userAddress ? () => getSessionAccount({ client, userAddress }) : skipToken3,
860
818
  staleTime: Infinity,
861
819
  // TODO: replace with function to retry only connection errors
862
820
  retry: false
863
821
  });
864
822
  }
865
823
 
824
+ // src/useFunds.ts
825
+ import { useClient as useClient6, useConfig } from "wagmi";
826
+ import { getBalanceQueryOptions as getBalanceQueryOptions2 } from "wagmi/query";
827
+ import { queryOptions as queryOptions6, useQuery as useQuery7, useQueryClient } from "@tanstack/react-query";
828
+
829
+ // src/onboarding/quarry/useAllowance.ts
830
+ import { useClient as useClient4 } from "wagmi";
831
+ import { queryOptions as queryOptions4, skipToken as skipToken4, useQuery as useQuery5 } from "@tanstack/react-query";
832
+
833
+ // src/quarry/getAllowance.ts
834
+ import { numberToHex as numberToHex2 } from "viem";
835
+ import { getRecord as getRecord3, getStaticDataLocation } from "@latticexyz/store/internal";
836
+ import { getKeyTuple } from "@latticexyz/protocol-parser/internal";
837
+ import { setStorageAt } from "viem/actions";
838
+ async function getAllowance({ client, userAddress }) {
839
+ const paymaster = getPaymaster(client.chain);
840
+ if (paymaster?.type !== "quarry") return null;
841
+ const record = await getRecord3(client, {
842
+ address: paymaster.address,
843
+ table: paymasterTables.Allowance,
844
+ key: { user: userAddress },
845
+ blockTag: "pending"
846
+ });
847
+ return record.allowance;
848
+ }
849
+ async function setAllowanceSlot({ client, userAddress, allowance }) {
850
+ const paymaster = getPaymaster(client.chain);
851
+ if (paymaster?.type !== "quarry") return;
852
+ const slot = getStaticDataLocation(
853
+ paymasterTables.Allowance.tableId,
854
+ getKeyTuple(paymasterTables.Allowance, { user: userAddress })
855
+ );
856
+ await setStorageAt(
857
+ client.extend(() => ({ mode: "anvil" })),
858
+ {
859
+ address: paymaster.address,
860
+ index: slot,
861
+ value: numberToHex2(allowance, { size: 32 })
862
+ }
863
+ );
864
+ }
865
+
866
+ // src/onboarding/quarry/useAllowance.ts
867
+ function getAllowanceQueryOptions({
868
+ client,
869
+ userAddress
870
+ }) {
871
+ return queryOptions4({
872
+ queryKey: ["getAllowance", client?.uid, userAddress],
873
+ queryFn: client && userAddress ? () => getAllowance({ client, userAddress }) : skipToken4
874
+ });
875
+ }
876
+ function useAllowance(userAddress) {
877
+ const { chainId } = useEntryKitConfig();
878
+ const client = useClient4({ chainId });
879
+ return useQuery5(getAllowanceQueryOptions({ client, userAddress }));
880
+ }
881
+
866
882
  // src/onboarding/quarry/useBalance.ts
867
883
  import { useClient as useClient5 } from "wagmi";
868
884
  import { queryOptions as queryOptions5, skipToken as skipToken5, useQuery as useQuery6 } from "@tanstack/react-query";
@@ -897,6 +913,43 @@ function useBalance(userAddress) {
897
913
  return useQuery6(getBalanceQueryOptions({ client, userAddress }));
898
914
  }
899
915
 
916
+ // src/useFunds.ts
917
+ function getFundsQueryOptions({
918
+ queryClient,
919
+ config,
920
+ client,
921
+ userAddress
922
+ }) {
923
+ return queryOptions6({
924
+ queryKey: ["getFunds", client?.uid, userAddress],
925
+ queryFn: async () => {
926
+ if (!client) throw new Error("Viem client not ready.");
927
+ if (!userAddress) throw new Error("User not connected.");
928
+ const {
929
+ account: { address: sessionAddress }
930
+ } = await queryClient.fetchQuery(getSessionAccountQueryOptions({ client, userAddress }));
931
+ const [sessionBalance, paymasterAllowance, paymasterBalance] = await Promise.all([
932
+ queryClient.fetchQuery(getBalanceQueryOptions2(config, { chainId: client.chain.id, address: sessionAddress })),
933
+ queryClient.fetchQuery(getAllowanceQueryOptions({ client, userAddress })),
934
+ queryClient.fetchQuery(getBalanceQueryOptions({ client, userAddress }))
935
+ ]);
936
+ return {
937
+ sessionBalance: sessionBalance?.value ?? null,
938
+ paymasterAllowance,
939
+ paymasterBalance
940
+ };
941
+ },
942
+ retry: false
943
+ });
944
+ }
945
+ function useFunds(userAddress) {
946
+ const queryClient = useQueryClient();
947
+ const config = useConfig();
948
+ const { chainId } = useEntryKitConfig();
949
+ const client = useClient6({ chainId });
950
+ return useQuery7(getFundsQueryOptions({ queryClient, config, client, userAddress }), queryClient);
951
+ }
952
+
900
953
  // src/onboarding/usePrerequisites.ts
901
954
  function getPrequisitesQueryOptions({
902
955
  queryClient,
@@ -905,26 +958,23 @@ function getPrequisitesQueryOptions({
905
958
  userAddress,
906
959
  worldAddress
907
960
  }) {
908
- return queryOptions6({
961
+ return queryOptions7({
909
962
  queryKey: ["getPrerequisites", client?.uid, userAddress],
910
- queryFn: client && userAddress ? async () => {
911
- const paymaster = getPaymaster(client.chain);
963
+ queryFn: async () => {
964
+ if (!client) throw new Error("Viem client not ready.");
965
+ if (!userAddress) throw new Error("User not connected.");
912
966
  const {
913
967
  account: { address: sessionAddress }
914
968
  } = await queryClient.fetchQuery(getSessionAccountQueryOptions({ client, userAddress }));
915
- const [sessionBalance, allowance, spender, quarryBalance, hasDelegation] = await Promise.all([
916
- !paymaster ? queryClient.fetchQuery(
917
- getBalanceQueryOptions2(config, { chainId: client.chain.id, address: sessionAddress })
918
- ) : null,
919
- paymaster?.type === "quarry" ? queryClient.fetchQuery(getAllowanceQueryOptions({ client, userAddress })) : null,
920
- paymaster?.type === "quarry" ? queryClient.fetchQuery(getSpenderQueryOptions({ client, userAddress, sessionAddress })) : null,
921
- paymaster?.type === "quarry" ? queryClient.fetchQuery(getBalanceQueryOptions({ client, userAddress })) : null,
969
+ const [funds, spender, hasDelegation] = await Promise.all([
970
+ queryClient.fetchQuery(getFundsQueryOptions({ queryClient, config, client, userAddress })),
971
+ queryClient.fetchQuery(getSpenderQueryOptions({ client, userAddress, sessionAddress })),
922
972
  queryClient.fetchQuery(getDelegationQueryOptions({ client, worldAddress, userAddress, sessionAddress }))
923
973
  ]);
924
- const hasAllowance = allowance == null || allowance > 0n;
974
+ const hasAllowance = funds.paymasterAllowance == null || funds.paymasterAllowance > 0n;
925
975
  const isSpender = spender == null ? true : spender;
926
- const hasGasBalance = sessionBalance == null || sessionBalance.value > 0n;
927
- const hasQuarryGasBalance = quarryBalance == null || quarryBalance > 0n;
976
+ const hasGasBalance = funds.sessionBalance == null || funds.sessionBalance > 0n;
977
+ const hasQuarryGasBalance = funds.paymasterBalance == null || funds.paymasterBalance > 0n;
928
978
  return {
929
979
  sessionAddress,
930
980
  hasAllowance,
@@ -935,16 +985,16 @@ function getPrequisitesQueryOptions({
935
985
  // we intentionally don't enforce an allowance/gas balance here
936
986
  complete: isSpender && hasDelegation
937
987
  };
938
- } : skipToken6,
988
+ },
939
989
  retry: false
940
990
  });
941
991
  }
942
992
  function usePrerequisites(userAddress) {
943
- const queryClient = useQueryClient();
944
- const config = useConfig();
993
+ const queryClient = useQueryClient2();
994
+ const config = useConfig2();
945
995
  const { chainId, worldAddress } = useEntryKitConfig();
946
- const client = useClient6({ chainId });
947
- const prereqs = useQuery7(
996
+ const client = useClient7({ chainId });
997
+ const prereqs = useQuery8(
948
998
  getPrequisitesQueryOptions({
949
999
  queryClient,
950
1000
  config,
@@ -961,10 +1011,10 @@ function usePrerequisites(userAddress) {
961
1011
  import { useDisconnect } from "wagmi";
962
1012
 
963
1013
  // src/useENS.ts
964
- import { useQuery as useQuery8 } from "@tanstack/react-query";
1014
+ import { useQuery as useQuery9 } from "@tanstack/react-query";
965
1015
  function useENS(address) {
966
1016
  const normalizedAddress = address?.toLowerCase();
967
- return useQuery8({
1017
+ return useQuery9({
968
1018
  enabled: !!normalizedAddress,
969
1019
  queryKey: ["ens", normalizedAddress],
970
1020
  queryFn: async () => {
@@ -1088,7 +1138,7 @@ import { parseEther as parseEther3 } from "viem";
1088
1138
 
1089
1139
  // src/onboarding/quarry/useClaimGasPass.ts
1090
1140
  import { parseEther as parseEther2 } from "viem";
1091
- import { useMutation, useQueryClient as useQueryClient2 } from "@tanstack/react-query";
1141
+ import { useMutation, useQueryClient as useQueryClient3 } from "@tanstack/react-query";
1092
1142
 
1093
1143
  // src/quarry/transports/quarryPassIssuer.ts
1094
1144
  import { http as http2 } from "viem";
@@ -1117,11 +1167,11 @@ async function claimGasPass({ chain, userAddress }) {
1117
1167
  }
1118
1168
 
1119
1169
  // src/onboarding/quarry/useClaimGasPass.ts
1120
- import { useClient as useClient7 } from "wagmi";
1170
+ import { useClient as useClient8 } from "wagmi";
1121
1171
  function useClaimGasPass() {
1122
- const queryClient = useQueryClient2();
1172
+ const queryClient = useQueryClient3();
1123
1173
  const { chain } = useEntryKitConfig();
1124
- const client = useClient7({ chainId: chain.id });
1174
+ const client = useClient8({ chainId: chain.id });
1125
1175
  const mutationKey = ["claimGasPass", chain.id];
1126
1176
  return useMutation({
1127
1177
  retry: 0,
@@ -1135,6 +1185,7 @@ function useClaimGasPass() {
1135
1185
  }
1136
1186
  await Promise.all([
1137
1187
  queryClient.invalidateQueries({ queryKey: ["getAllowance"] }),
1188
+ queryClient.invalidateQueries({ queryKey: ["getFunds"] }),
1138
1189
  queryClient.invalidateQueries({ queryKey: ["getPrerequisites"] })
1139
1190
  ]);
1140
1191
  }
@@ -1241,7 +1292,7 @@ import { useEffect as useEffect7 } from "react";
1241
1292
 
1242
1293
  // src/onboarding/useSetupSession.ts
1243
1294
  import { encodeFunctionData } from "viem";
1244
- import { useMutation as useMutation2, useQueryClient as useQueryClient3 } from "@tanstack/react-query";
1295
+ import { useMutation as useMutation2, useQueryClient as useQueryClient4 } from "@tanstack/react-query";
1245
1296
  import { getAction as getAction4 } from "viem/utils";
1246
1297
  import { sendUserOperation as sendUserOperation2, waitForUserOperationReceipt } from "viem/account-abstraction";
1247
1298
  import { waitForTransactionReceipt as waitForTransactionReceipt2 } from "viem/actions";
@@ -1252,7 +1303,7 @@ function defineCall(call) {
1252
1303
  }
1253
1304
 
1254
1305
  // src/onboarding/useSetupSession.ts
1255
- import { useClient as useClient8 } from "wagmi";
1306
+ import { useClient as useClient9 } from "wagmi";
1256
1307
  import { resourceToHex as resourceToHex2 } from "@latticexyz/common";
1257
1308
  import IBaseWorldAbi from "@latticexyz/world/out/IBaseWorld.sol/IBaseWorld.abi.json";
1258
1309
 
@@ -1334,9 +1385,9 @@ async function callWithSignature({
1334
1385
  // src/onboarding/useSetupSession.ts
1335
1386
  import { systemsConfig as worldSystemsConfig } from "@latticexyz/world/mud.config";
1336
1387
  function useSetupSession({ userClient }) {
1337
- const queryClient = useQueryClient3();
1388
+ const queryClient = useQueryClient4();
1338
1389
  const { chainId, worldAddress } = useEntryKitConfig();
1339
- const client = useClient8({ chainId });
1390
+ const client = useClient9({ chainId });
1340
1391
  const mutationKey = ["setupSession", client?.chain.id, userClient.account.address];
1341
1392
  return useMutation2({
1342
1393
  retry: 0,
@@ -1443,12 +1494,11 @@ function useSetupSession({ userClient }) {
1443
1494
  }
1444
1495
 
1445
1496
  // src/useSessionClient.ts
1446
- import { useClient as useClient9 } from "wagmi";
1497
+ import { useClient as useClient10 } from "wagmi";
1447
1498
  import {
1448
- queryOptions as queryOptions7,
1449
- skipToken as skipToken7,
1450
- useQuery as useQuery9,
1451
- useQueryClient as useQueryClient4
1499
+ queryOptions as queryOptions8,
1500
+ useQuery as useQuery10,
1501
+ useQueryClient as useQueryClient5
1452
1502
  } from "@tanstack/react-query";
1453
1503
 
1454
1504
  // src/getSessionClient.ts
@@ -1485,7 +1535,7 @@ function createFeeEstimator(client) {
1485
1535
  if (client.chain.id === 31337) {
1486
1536
  return async () => ({ maxFeePerGas: 100000n, maxPriorityFeePerGas: 0n });
1487
1537
  }
1488
- if ([690, 17069, 17420, 695569].includes(client.chain.id)) {
1538
+ if ([690, 17069, 695569].includes(client.chain.id)) {
1489
1539
  return () => getAction5(client, estimateFeesPerGas, "estimateFeesPerGas")({ chain: client.chain });
1490
1540
  }
1491
1541
  }
@@ -1532,9 +1582,10 @@ function getSessionClientQueryOptions({
1532
1582
  userAddress,
1533
1583
  worldAddress
1534
1584
  }) {
1535
- return queryOptions7({
1585
+ return queryOptions8({
1536
1586
  queryKey: ["getSessionClient", client?.uid, userAddress, worldAddress],
1537
- queryFn: userAddress ? async () => {
1587
+ queryFn: async () => {
1588
+ if (!userAddress) throw new Error("User not connected.");
1538
1589
  const { account: sessionAccount, signer: sessionSigner } = await queryClient.fetchQuery(
1539
1590
  getSessionAccountQueryOptions({ client, userAddress })
1540
1591
  );
@@ -1544,17 +1595,17 @@ function getSessionClientQueryOptions({
1544
1595
  userAddress,
1545
1596
  worldAddress
1546
1597
  });
1547
- } : skipToken7,
1598
+ },
1548
1599
  staleTime: Infinity,
1549
1600
  // TODO: replace with function to retry only connection errors
1550
1601
  retry: false
1551
1602
  });
1552
1603
  }
1553
1604
  function useSessionClient(userAddress) {
1554
- const queryClient = useQueryClient4();
1605
+ const queryClient = useQueryClient5();
1555
1606
  const { chainId, worldAddress } = useEntryKitConfig();
1556
- const client = useClient9({ chainId });
1557
- return useQuery9(
1607
+ const client = useClient10({ chainId });
1608
+ return useQuery10(
1558
1609
  getSessionClientQueryOptions({
1559
1610
  queryClient,
1560
1611
  client,
@@ -1623,7 +1674,7 @@ function Session({ isActive, isExpanded, userClient, registerSpender, registerDe
1623
1674
  // src/onboarding/GasBalance.tsx
1624
1675
  import { useEffect as useEffect9, useState as useState2 } from "react";
1625
1676
  import { parseEther as parseEther4 } from "viem";
1626
- import { useQueryClient as useQueryClient6 } from "@tanstack/react-query";
1677
+ import { useQueryClient as useQueryClient7 } from "@tanstack/react-query";
1627
1678
  import { useBalance as useBalance2, useWatchBlockNumber } from "wagmi";
1628
1679
 
1629
1680
  // src/data/relayChains.json
@@ -1907,13 +1958,13 @@ var relayChains_default = {
1907
1958
  };
1908
1959
 
1909
1960
  // src/onboarding/useSetBalance.ts
1910
- import { useQueryClient as useQueryClient5, useMutation as useMutation3 } from "@tanstack/react-query";
1961
+ import { useQueryClient as useQueryClient6, useMutation as useMutation3 } from "@tanstack/react-query";
1911
1962
  import { setBalance as setBalance2 } from "viem/actions";
1912
- import { useClient as useClient10 } from "wagmi";
1963
+ import { useClient as useClient11 } from "wagmi";
1913
1964
  function useSetBalance() {
1914
- const queryClient = useQueryClient5();
1965
+ const queryClient = useQueryClient6();
1915
1966
  const { chainId } = useEntryKitConfig();
1916
- const client = useClient10({ chainId });
1967
+ const client = useClient11({ chainId });
1917
1968
  return useMutation3({
1918
1969
  retry: 0,
1919
1970
  mutationKey: ["setBalance", chainId],
@@ -1922,6 +1973,7 @@ function useSetBalance() {
1922
1973
  await setBalance2({ ...client, mode: "anvil" }, params);
1923
1974
  await Promise.all([
1924
1975
  queryClient.invalidateQueries({ queryKey: ["balance"] }),
1976
+ queryClient.invalidateQueries({ queryKey: ["getFunds"] }),
1925
1977
  queryClient.invalidateQueries({ queryKey: ["getPrerequisites"] })
1926
1978
  ]);
1927
1979
  return null;
@@ -1991,7 +2043,7 @@ function CheckIcon(props) {
1991
2043
  // src/onboarding/GasBalance.tsx
1992
2044
  import { Fragment, jsx as jsx19, jsxs as jsxs14 } from "react/jsx-runtime";
1993
2045
  function GasBalance({ isActive, isExpanded, sessionAddress }) {
1994
- const queryClient = useQueryClient6();
2046
+ const queryClient = useQueryClient7();
1995
2047
  const { chain } = useEntryKitConfig();
1996
2048
  const [copied, setCopied] = useState2(false);
1997
2049
  const balance = useShowQueryError(useBalance2({ chainId: chain.id, address: sessionAddress }));
@@ -2006,6 +2058,7 @@ function GasBalance({ isActive, isExpanded, sessionAddress }) {
2006
2058
  };
2007
2059
  useEffect9(() => {
2008
2060
  if (balance.data != null && prevBalance?.value === 0n && balance.data.value > 0n) {
2061
+ queryClient.invalidateQueries({ queryKey: ["getFunds"] });
2009
2062
  queryClient.invalidateQueries({ queryKey: ["getPrerequisites"] });
2010
2063
  }
2011
2064
  }, [balance.data, prevBalance, setBalance3, sessionAddress, queryClient]);
@@ -2079,7 +2132,7 @@ function GasBalance({ isActive, isExpanded, sessionAddress }) {
2079
2132
 
2080
2133
  // src/onboarding/quarry/GasBalance.tsx
2081
2134
  import { useEffect as useEffect14 } from "react";
2082
- import { useQueryClient as useQueryClient9 } from "@tanstack/react-query";
2135
+ import { useQueryClient as useQueryClient10 } from "@tanstack/react-query";
2083
2136
 
2084
2137
  // src/onboarding/deposit/DepositFormContainer.tsx
2085
2138
  import { useState as useState4 } from "react";
@@ -2088,7 +2141,7 @@ import { useChains as useChains4, useChainId } from "wagmi";
2088
2141
  // src/onboarding/deposit/DepositViaTransferForm.tsx
2089
2142
  import { useAccount as useAccount4, useWriteContract, usePrepareTransactionRequest, usePublicClient } from "wagmi";
2090
2143
  import { encodeFunctionData as encodeFunctionData2 } from "viem";
2091
- import { useMutation as useMutation4, useQuery as useQuery12 } from "@tanstack/react-query";
2144
+ import { useMutation as useMutation4, useQuery as useQuery13 } from "@tanstack/react-query";
2092
2145
 
2093
2146
  // src/onboarding/deposit/DepositForm.tsx
2094
2147
  import { useEffect as useEffect11, useRef as useRef4 } from "react";
@@ -2216,12 +2269,12 @@ import {
2216
2269
  createClient as createClient2,
2217
2270
  LogLevel
2218
2271
  } from "@reservoir0x/relay-sdk";
2219
- import { useQuery as useQuery10 } from "@tanstack/react-query";
2272
+ import { useQuery as useQuery11 } from "@tanstack/react-query";
2220
2273
  function useRelay() {
2221
2274
  const { chain } = useEntryKitConfig();
2222
2275
  const appOrigin = location.host;
2223
2276
  const baseApiUrl = chain.testnet ? TESTNET_RELAY_API : MAINNET_RELAY_API;
2224
- return useQuery10({
2277
+ return useQuery11({
2225
2278
  queryKey: ["relayChains", baseApiUrl, appOrigin],
2226
2279
  queryFn: async () => {
2227
2280
  debug("fetching relay chains from", baseApiUrl);
@@ -2245,13 +2298,13 @@ function useRelay() {
2245
2298
  // src/onboarding/deposit/useChainBalances.ts
2246
2299
  import { useAccount, useConfig as useWagmiConfig } from "wagmi";
2247
2300
  import { getBalance as getBalance2 } from "wagmi/actions";
2248
- import { useQuery as useQuery11, skipToken as skipToken8 } from "@tanstack/react-query";
2301
+ import { useQuery as useQuery12, skipToken as skipToken6 } from "@tanstack/react-query";
2249
2302
  import { isNotNull } from "@latticexyz/common/utils";
2250
2303
  function useChainBalances({ chains }) {
2251
2304
  const { address: userAddress } = useAccount();
2252
2305
  const wagmiConfig = useWagmiConfig();
2253
2306
  const chainIds = chains.map((chain) => chain.id);
2254
- return useQuery11({
2307
+ return useQuery12({
2255
2308
  queryKey: ["chainBalances", chainIds, userAddress],
2256
2309
  queryFn: userAddress ? async () => {
2257
2310
  const chainBalances = await Promise.allSettled(
@@ -2261,7 +2314,7 @@ function useChainBalances({ chains }) {
2261
2314
  })
2262
2315
  );
2263
2316
  return chainBalances.map((result) => result.status === "fulfilled" ? result.value : null).filter(isNotNull);
2264
- } : skipToken8,
2317
+ } : skipToken6,
2265
2318
  refetchInterval: 1e3 * 60,
2266
2319
  retry: 1
2267
2320
  });
@@ -2600,7 +2653,7 @@ function DepositViaTransferForm({ amount, setAmount, sourceChain, setSourceChain
2600
2653
  if (!userAddress) {
2601
2654
  throw new Error("User address not found");
2602
2655
  }
2603
- const { data: gasPrice } = useQuery12({
2656
+ const { data: gasPrice } = useQuery13({
2604
2657
  queryKey: ["gasPrice", sourceChain.id],
2605
2658
  queryFn: async () => {
2606
2659
  if (!publicClient) throw new Error("Public client not available");
@@ -2691,7 +2744,7 @@ function DepositViaTransferForm({ amount, setAmount, sourceChain, setSourceChain
2691
2744
  // src/onboarding/deposit/DepositViaRelayForm.tsx
2692
2745
  import { encodeFunctionData as encodeFunctionData3 } from "viem";
2693
2746
  import { useAccount as useAccount5, useWalletClient } from "wagmi";
2694
- import { useMutation as useMutation5, useQuery as useQuery13 } from "@tanstack/react-query";
2747
+ import { useMutation as useMutation5, useQuery as useQuery14 } from "@tanstack/react-query";
2695
2748
  import { jsx as jsx31 } from "react/jsx-runtime";
2696
2749
  var ETH_ADDRESS = "0x0000000000000000000000000000000000000000";
2697
2750
  function DepositViaRelayForm({ amount, setAmount, sourceChain, setSourceChainId }) {
@@ -2702,7 +2755,7 @@ function DepositViaRelayForm({ amount, setAmount, sourceChain, setSourceChainId
2702
2755
  const { addDeposit } = useDeposits();
2703
2756
  const { data: relay } = useRelay();
2704
2757
  const relayClient = relay?.client;
2705
- const quote = useQuery13({
2758
+ const quote = useQuery14({
2706
2759
  queryKey: ["relayBridgeQuote", sourceChain.id, amount?.toString()],
2707
2760
  queryFn: async () => {
2708
2761
  if (!relayClient) throw new Error("No Relay client found.");
@@ -2812,10 +2865,10 @@ function DepositViaRelayForm({ amount, setAmount, sourceChain, setSourceChainId
2812
2865
 
2813
2866
  // src/onboarding/deposit/Deposits.tsx
2814
2867
  import { useEffect as useEffect13 } from "react";
2815
- import { useQuery as useQuery16, useQueryClient as useQueryClient7 } from "@tanstack/react-query";
2868
+ import { useQuery as useQuery17, useQueryClient as useQueryClient8 } from "@tanstack/react-query";
2816
2869
 
2817
2870
  // src/onboarding/deposit/TransferDepositStatus.tsx
2818
- import { useQuery as useQuery14 } from "@tanstack/react-query";
2871
+ import { useQuery as useQuery15 } from "@tanstack/react-query";
2819
2872
 
2820
2873
  // src/onboarding/deposit/DepositStatus.tsx
2821
2874
  import { useEffect as useEffect12, useState as useState3 } from "react";
@@ -2898,7 +2951,7 @@ function TransferDepositStatus({
2898
2951
  }) {
2899
2952
  const chains = useChains2();
2900
2953
  const chain = chains.find((chain2) => chain2.id === chainL1Id);
2901
- const receipt = useQuery14({
2954
+ const receipt = useQuery15({
2902
2955
  queryKey: ["transferDepositStatus", hash],
2903
2956
  queryFn: () => receiptPromise
2904
2957
  });
@@ -2966,7 +3019,7 @@ function TransferDepositStatus({
2966
3019
  }
2967
3020
 
2968
3021
  // src/onboarding/deposit/RelayDepositStatus.tsx
2969
- import { useQuery as useQuery15 } from "@tanstack/react-query";
3022
+ import { useQuery as useQuery16 } from "@tanstack/react-query";
2970
3023
  import { useChains as useChains3 } from "wagmi";
2971
3024
  import { Fragment as Fragment5, jsx as jsx35, jsxs as jsxs21 } from "react/jsx-runtime";
2972
3025
  function RelayDepositStatus({
@@ -2981,7 +3034,7 @@ function RelayDepositStatus({
2981
3034
  const chains = useChains3();
2982
3035
  const chainL1 = chains.find((chain) => chain.id === chainL1Id);
2983
3036
  const chainL2 = chains.find((chain) => chain.id === chainL2Id);
2984
- const deposit = useQuery15({
3037
+ const deposit = useQuery16({
2985
3038
  queryKey: ["relayDepositPromise", chainL1Id, chainL2Id, amount.toString(), start.toISOString()],
2986
3039
  queryFn: () => depositPromise
2987
3040
  });
@@ -3022,15 +3075,15 @@ function RelayDepositStatus({
3022
3075
  }
3023
3076
 
3024
3077
  // src/onboarding/deposit/Deposits.tsx
3025
- import { useAccount as useAccount6, useClient as useClient11 } from "wagmi";
3078
+ import { useAccount as useAccount6, useClient as useClient12 } from "wagmi";
3026
3079
  import { jsx as jsx36 } from "react/jsx-runtime";
3027
3080
  function Deposits() {
3028
- const queryClient = useQueryClient7();
3081
+ const queryClient = useQueryClient8();
3029
3082
  const { chainId } = useEntryKitConfig();
3030
- const client = useClient11({ chainId });
3083
+ const client = useClient12({ chainId });
3031
3084
  const { address: userAddress } = useAccount6();
3032
3085
  const { deposits, removeDeposit } = useDeposits();
3033
- const { data: isComplete } = useQuery16({
3086
+ const { data: isComplete } = useQuery17({
3034
3087
  queryKey: ["depositsComplete", deposits.map((deposit) => deposit.uid)],
3035
3088
  queryFn: async () => {
3036
3089
  if (!deposits.length) return false;
@@ -3104,18 +3157,18 @@ function ArrowLeftIcon(props) {
3104
3157
  // src/onboarding/quarry/WithdrawGasBalanceButton.tsx
3105
3158
  import { getAction as getAction6 } from "viem/utils";
3106
3159
  import { waitForTransactionReceipt as waitForTransactionReceipt3 } from "viem/actions";
3107
- import { useAccount as useAccount7, useClient as useClient12, useSwitchChain as useSwitchChain3, useWriteContract as useWriteContract2 } from "wagmi";
3160
+ import { useAccount as useAccount7, useClient as useClient13, useSwitchChain as useSwitchChain3, useWriteContract as useWriteContract2 } from "wagmi";
3108
3161
  import { twMerge as twMerge17 } from "tailwind-merge";
3109
3162
  import { useMutation as useMutation6 } from "@tanstack/react-query";
3110
- import { useQueryClient as useQueryClient8 } from "@tanstack/react-query";
3163
+ import { useQueryClient as useQueryClient9 } from "@tanstack/react-query";
3111
3164
  import { jsx as jsx39, jsxs as jsxs23 } from "react/jsx-runtime";
3112
3165
  function WithdrawGasBalanceButton({ userAddress }) {
3113
3166
  const { writeContractAsync } = useWriteContract2();
3114
3167
  const { switchChain } = useSwitchChain3();
3115
3168
  const { chain, chainId } = useEntryKitConfig();
3116
3169
  const { chainId: userChainId } = useAccount7();
3117
- const queryClient = useQueryClient8();
3118
- const client = useClient12({ chainId });
3170
+ const queryClient = useQueryClient9();
3171
+ const client = useClient13({ chainId });
3119
3172
  const paymaster = getPaymaster(chain);
3120
3173
  const balance = useShowQueryError(useBalance(userAddress));
3121
3174
  const shouldSwitchChain = chainId != null && chainId !== userChainId;
@@ -3136,6 +3189,7 @@ function WithdrawGasBalanceButton({ userAddress }) {
3136
3189
  await getAction6(client, waitForTransactionReceipt3, "waitForTransactionReceipt")({ hash });
3137
3190
  await Promise.all([
3138
3191
  queryClient.invalidateQueries({ queryKey: ["balance"] }),
3192
+ queryClient.invalidateQueries({ queryKey: ["getFunds"] }),
3139
3193
  queryClient.invalidateQueries({ queryKey: ["getPrerequisites"] })
3140
3194
  ]);
3141
3195
  } catch (error2) {
@@ -3185,7 +3239,7 @@ function WithdrawGasBalanceButton({ userAddress }) {
3185
3239
  // src/onboarding/quarry/GasBalance.tsx
3186
3240
  import { jsx as jsx40, jsxs as jsxs24 } from "react/jsx-runtime";
3187
3241
  function GasBalance2({ isActive, isExpanded, isFocused, setFocused, userAddress }) {
3188
- const queryClient = useQueryClient9();
3242
+ const queryClient = useQueryClient10();
3189
3243
  const balance = useShowQueryError(useBalance(userAddress));
3190
3244
  const prevBalance = usePrevious(balance.data || 0n);
3191
3245
  useEffect14(() => {
@@ -3614,7 +3668,7 @@ function AccountButton() {
3614
3668
  "hover:bg-orange-400",
3615
3669
  "active:bg-orange-600"
3616
3670
  ),
3617
- "aria-busy": accountModalOpen,
3671
+ "aria-busy": accountModalOpen || prereqs.isPending,
3618
3672
  onClick: openAccountModal,
3619
3673
  children: [
3620
3674
  /* @__PURE__ */ jsxs29("span", { className: "pointer-events-none inline-grid place-items-center -ml-3", children: [
@@ -3658,8 +3712,9 @@ function useSessionClientReady() {
3658
3712
  const userAddress = userClient.data?.account.address;
3659
3713
  const prerequisites = usePrerequisites(userAddress);
3660
3714
  const sessionClient = useSessionClient(userAddress);
3661
- if (!userClient.isSuccess) return { ...userClient, data: void 0 };
3662
- if (!prerequisites.isSuccess || !prerequisites.data.complete) return { ...prerequisites, data: void 0 };
3715
+ if (!prerequisites.isSuccess || !prerequisites.data.complete) {
3716
+ return { ...prerequisites, data: void 0 };
3717
+ }
3663
3718
  return sessionClient;
3664
3719
  }
3665
3720
 
@@ -4087,9 +4142,11 @@ export {
4087
4142
  EntryKitProvider,
4088
4143
  createWagmiConfig,
4089
4144
  defineConfig,
4145
+ getFundsQueryOptions,
4090
4146
  internal_validateSigner,
4091
4147
  useAccountModal,
4092
4148
  useEntryKitConfig,
4149
+ useFunds,
4093
4150
  useSessionClientReady as useSessionClient
4094
4151
  };
4095
4152
  //# sourceMappingURL=internal.js.map