@wagmi/core 0.7.8 → 0.8.0

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.
Files changed (36) hide show
  1. package/dist/{base-a32d0b91.d.ts → base-a82112a9.d.ts} +1 -1
  2. package/dist/chains.d.ts +1 -3
  3. package/dist/chains.js +13 -1
  4. package/dist/chunk-6KG5TOAU.js +42 -0
  5. package/dist/{chunk-HEIMP7HQ.js → chunk-F4A7FMUQ.js} +1166 -1126
  6. package/dist/chunk-J6DUE3KA.js +0 -0
  7. package/dist/chunk-VCRGL4ZG.js +191 -0
  8. package/dist/connectors/coinbaseWallet.d.ts +2 -2
  9. package/dist/connectors/coinbaseWallet.js +8 -5
  10. package/dist/connectors/metaMask.d.ts +4 -3
  11. package/dist/connectors/metaMask.js +2 -2
  12. package/dist/connectors/mock/index.d.ts +3 -2
  13. package/dist/connectors/mock/index.js +6 -185
  14. package/dist/connectors/walletConnect.d.ts +2 -2
  15. package/dist/connectors/walletConnect.js +8 -4
  16. package/dist/{index-58cffc47.d.ts → index-971cda79.d.ts} +2 -103
  17. package/dist/index.d.ts +51 -46
  18. package/dist/index.js +9 -20
  19. package/dist/{injected-82510902.d.ts → injected-610c34b6.d.ts} +3 -2
  20. package/dist/{internal.d.ts → internal/index.d.ts} +3 -2
  21. package/dist/internal/index.js +8 -0
  22. package/dist/internal/test.d.ts +12 -0
  23. package/dist/internal/test.js +142 -0
  24. package/dist/providers/alchemy.d.ts +2 -1
  25. package/dist/providers/alchemy.js +2 -2
  26. package/dist/providers/infura.d.ts +2 -1
  27. package/dist/providers/infura.js +2 -2
  28. package/dist/providers/jsonRpc.d.ts +2 -1
  29. package/dist/providers/jsonRpc.js +2 -2
  30. package/dist/providers/public.d.ts +2 -1
  31. package/dist/providers/public.js +2 -2
  32. package/internal/package.json +1 -1
  33. package/internal/test/package.json +4 -0
  34. package/package.json +12 -7
  35. package/dist/chunk-4DNFSL2K.js +0 -376
  36. package/dist/internal.js +0 -8
@@ -1,7 +1,7 @@
1
1
  import {
2
- defaultChains,
2
+ goerli,
3
3
  mainnet
4
- } from "./chunk-4DNFSL2K.js";
4
+ } from "./chunk-6KG5TOAU.js";
5
5
  import {
6
6
  __privateAdd,
7
7
  __privateGet,
@@ -19,36 +19,36 @@ import { getAddress, hexValue } from "ethers/lib/utils.js";
19
19
 
20
20
  // src/utils/configureChains.ts
21
21
  import { providers } from "ethers";
22
- function configureChains(defaultChains2, providers3, {
22
+ function configureChains(defaultChains, providers3, {
23
23
  minQuorum = 1,
24
24
  pollingInterval = 4e3,
25
25
  targetQuorum = 1,
26
26
  stallTimeout
27
27
  } = {}) {
28
- if (!defaultChains2.length)
28
+ if (!defaultChains.length)
29
29
  throw new Error("must have at least one chain");
30
30
  if (targetQuorum < minQuorum)
31
31
  throw new Error("quorum cannot be lower than minQuorum");
32
32
  let chains = [];
33
33
  const providers_ = {};
34
34
  const webSocketProviders_ = {};
35
- for (const chain2 of defaultChains2) {
35
+ for (const chain of defaultChains) {
36
36
  let configExists = false;
37
37
  for (const provider of providers3) {
38
- const apiConfig = provider(chain2);
38
+ const apiConfig = provider(chain);
39
39
  if (!apiConfig)
40
40
  continue;
41
41
  configExists = true;
42
- if (!chains.some(({ id }) => id === chain2.id)) {
42
+ if (!chains.some(({ id }) => id === chain.id)) {
43
43
  chains = [...chains, apiConfig.chain];
44
44
  }
45
- providers_[chain2.id] = [
46
- ...providers_[chain2.id] || [],
45
+ providers_[chain.id] = [
46
+ ...providers_[chain.id] || [],
47
47
  apiConfig.provider
48
48
  ];
49
49
  if (apiConfig.webSocketProvider) {
50
- webSocketProviders_[chain2.id] = [
51
- ...webSocketProviders_[chain2.id] || [],
50
+ webSocketProviders_[chain.id] = [
51
+ ...webSocketProviders_[chain.id] || [],
52
52
  apiConfig.webSocketProvider
53
53
  ];
54
54
  }
@@ -56,7 +56,7 @@ function configureChains(defaultChains2, providers3, {
56
56
  if (!configExists) {
57
57
  throw new Error(
58
58
  [
59
- `Could not find valid provider configuration for chain "${chain2.name}".
59
+ `Could not find valid provider configuration for chain "${chain.name}".
60
60
  `,
61
61
  "You may need to add `jsonRpcProvider` to `configureChains` with the chain's RPC URLs.",
62
62
  "Read more: https://wagmi.sh/react/providers/jsonRpc"
@@ -66,8 +66,8 @@ function configureChains(defaultChains2, providers3, {
66
66
  }
67
67
  return {
68
68
  chains,
69
- provider: ({ chainId: chainId2 }) => {
70
- const activeChain = chains.find((x) => x.id === chainId2) ?? defaultChains2[0];
69
+ provider: ({ chainId }) => {
70
+ const activeChain = chains.find((x) => x.id === chainId) ?? defaultChains[0];
71
71
  const chainProviders = providers_[activeChain.id];
72
72
  if (!chainProviders || !chainProviders[0])
73
73
  throw new Error(`No providers configured for chain "${activeChain.id}"`);
@@ -91,8 +91,8 @@ function configureChains(defaultChains2, providers3, {
91
91
  pollingInterval
92
92
  });
93
93
  },
94
- webSocketProvider: ({ chainId: chainId2 }) => {
95
- const activeChain = chains.find((x) => x.id === chainId2) ?? defaultChains2[0];
94
+ webSocketProvider: ({ chainId }) => {
95
+ const activeChain = chains.find((x) => x.id === chainId) ?? defaultChains[0];
96
96
  const chainWebSocketProviders = webSocketProviders_[activeChain.id];
97
97
  if (!chainWebSocketProviders)
98
98
  return void 0;
@@ -140,23 +140,23 @@ function fallbackProvider(targetQuorum, minQuorum, providers_, { stallTimeout })
140
140
 
141
141
  // src/utils/assertActiveChain.ts
142
142
  function assertActiveChain({
143
- chainId: chainId2,
143
+ chainId,
144
144
  signer
145
145
  }) {
146
146
  const { chain: activeChain, chains } = getNetwork();
147
147
  const activeChainId = activeChain?.id;
148
- if (activeChainId && chainId2 !== activeChainId) {
148
+ if (activeChainId && chainId !== activeChainId) {
149
149
  throw new ChainMismatchError({
150
150
  activeChain: chains.find((x) => x.id === activeChainId)?.name ?? `Chain ${activeChainId}`,
151
- targetChain: chains.find((x) => x.id === chainId2)?.name ?? `Chain ${chainId2}`
151
+ targetChain: chains.find((x) => x.id === chainId)?.name ?? `Chain ${chainId}`
152
152
  });
153
153
  }
154
154
  if (signer) {
155
155
  const signerChainId = signer.provider?.network?.chainId;
156
- if (signerChainId && chainId2 !== signerChainId) {
156
+ if (signerChainId && chainId !== signerChainId) {
157
157
  const connector = getClient().connector;
158
158
  throw new ChainNotConfiguredError({
159
- chainId: chainId2,
159
+ chainId,
160
160
  connectorId: connector?.id ?? "unknown"
161
161
  });
162
162
  }
@@ -398,15 +398,15 @@ function minimizeContractInterface(config) {
398
398
  }
399
399
 
400
400
  // src/utils/normalizeChainId.ts
401
- function normalizeChainId(chainId2) {
402
- if (typeof chainId2 === "string")
401
+ function normalizeChainId(chainId) {
402
+ if (typeof chainId === "string")
403
403
  return Number.parseInt(
404
- chainId2,
405
- chainId2.trim().substring(0, 2) === "0x" ? 16 : 10
404
+ chainId,
405
+ chainId.trim().substring(0, 2) === "0x" ? 16 : 10
406
406
  );
407
- if (typeof chainId2 === "bigint")
408
- return Number(chainId2);
409
- return chainId2;
407
+ if (typeof chainId === "bigint")
408
+ return Number(chainId);
409
+ return chainId;
410
410
  }
411
411
 
412
412
  // src/utils/parseContractResult.ts
@@ -490,215 +490,597 @@ function serialize(value, replacer, indent, circularReplacer) {
490
490
 
491
491
  // src/connectors/base.ts
492
492
  import { default as EventEmitter } from "eventemitter3";
493
+ var Connector = class extends EventEmitter {
494
+ constructor({
495
+ chains = [mainnet, goerli],
496
+ options
497
+ }) {
498
+ super();
499
+ this.chains = chains;
500
+ this.options = options;
501
+ }
502
+ getBlockExplorerUrls(chain) {
503
+ const { default: blockExplorer, ...blockExplorers } = chain.blockExplorers ?? {};
504
+ if (blockExplorer)
505
+ return [
506
+ blockExplorer.url,
507
+ ...Object.values(blockExplorers).map((x) => x.url)
508
+ ];
509
+ }
510
+ isChainUnsupported(chainId) {
511
+ return !this.chains.some((x) => x.id === chainId);
512
+ }
513
+ };
493
514
 
494
- // src/constants/abis.ts
495
- var erc20ABI = [
496
- {
497
- type: "event",
498
- name: "Approval",
499
- inputs: [
500
- {
501
- indexed: true,
502
- name: "owner",
503
- type: "address"
504
- },
505
- {
506
- indexed: true,
507
- name: "spender",
508
- type: "address"
509
- },
510
- {
511
- indexed: false,
512
- name: "value",
513
- type: "uint256"
514
- }
515
- ]
516
- },
517
- {
518
- type: "event",
519
- name: "Transfer",
520
- inputs: [
521
- {
522
- indexed: true,
523
- name: "from",
524
- type: "address"
525
- },
526
- {
527
- indexed: true,
528
- name: "to",
529
- type: "address"
530
- },
531
- {
532
- indexed: false,
533
- name: "value",
534
- type: "uint256"
515
+ // src/connectors/injected.ts
516
+ var _provider, _switchingChains;
517
+ var InjectedConnector = class extends Connector {
518
+ constructor({
519
+ chains,
520
+ options: options_
521
+ } = {}) {
522
+ const options = {
523
+ shimDisconnect: true,
524
+ shimChainChangedDisconnect: true,
525
+ getProvider: () => typeof window !== "undefined" ? window.ethereum : void 0,
526
+ ...options_
527
+ };
528
+ super({ chains, options });
529
+ __privateAdd(this, _provider, void 0);
530
+ __privateAdd(this, _switchingChains, void 0);
531
+ this.shimDisconnectKey = "injected.shimDisconnect";
532
+ this.onAccountsChanged = (accounts) => {
533
+ if (accounts.length === 0)
534
+ this.emit("disconnect");
535
+ else
536
+ this.emit("change", {
537
+ account: getAddress(accounts[0])
538
+ });
539
+ };
540
+ this.onChainChanged = (chainId) => {
541
+ const id = normalizeChainId(chainId);
542
+ const unsupported = this.isChainUnsupported(id);
543
+ this.emit("change", { chain: { id, unsupported } });
544
+ };
545
+ this.onDisconnect = () => {
546
+ if (this.options.shimChainChangedDisconnect && __privateGet(this, _switchingChains)) {
547
+ __privateSet(this, _switchingChains, false);
548
+ return;
535
549
  }
536
- ]
537
- },
538
- {
539
- type: "function",
540
- name: "allowance",
541
- stateMutability: "view",
542
- inputs: [
543
- {
544
- name: "owner",
545
- type: "address"
546
- },
547
- {
548
- name: "spender",
549
- type: "address"
550
+ this.emit("disconnect");
551
+ if (this.options.shimDisconnect)
552
+ getClient().storage?.removeItem(this.shimDisconnectKey);
553
+ };
554
+ const provider = options.getProvider();
555
+ if (typeof options.name === "string")
556
+ this.name = options.name;
557
+ else if (provider) {
558
+ const detectedName = getInjectedName(provider);
559
+ if (options.name)
560
+ this.name = options.name(detectedName);
561
+ else {
562
+ if (typeof detectedName === "string")
563
+ this.name = detectedName;
564
+ else
565
+ this.name = detectedName[0];
550
566
  }
551
- ],
552
- outputs: [
553
- {
554
- name: "",
555
- type: "uint256"
567
+ } else
568
+ this.name = "Injected";
569
+ this.id = "injected";
570
+ this.ready = !!provider;
571
+ }
572
+ async connect({ chainId } = {}) {
573
+ try {
574
+ const provider = await this.getProvider();
575
+ if (!provider)
576
+ throw new ConnectorNotFoundError();
577
+ if (provider.on) {
578
+ provider.on("accountsChanged", this.onAccountsChanged);
579
+ provider.on("chainChanged", this.onChainChanged);
580
+ provider.on("disconnect", this.onDisconnect);
556
581
  }
557
- ]
558
- },
559
- {
560
- type: "function",
561
- name: "approve",
562
- stateMutability: "nonpayable",
563
- inputs: [
564
- {
565
- name: "spender",
566
- type: "address"
567
- },
568
- {
569
- name: "amount",
570
- type: "uint256"
582
+ this.emit("message", { type: "connecting" });
583
+ const accounts = await provider.request({
584
+ method: "eth_requestAccounts"
585
+ });
586
+ const account = getAddress(accounts[0]);
587
+ let id = await this.getChainId();
588
+ let unsupported = this.isChainUnsupported(id);
589
+ if (chainId && id !== chainId) {
590
+ const chain = await this.switchChain(chainId);
591
+ id = chain.id;
592
+ unsupported = this.isChainUnsupported(id);
571
593
  }
572
- ],
573
- outputs: [
574
- {
575
- name: "",
576
- type: "bool"
594
+ if (this.options.shimDisconnect)
595
+ getClient().storage?.setItem(this.shimDisconnectKey, true);
596
+ return { account, chain: { id, unsupported }, provider };
597
+ } catch (error) {
598
+ if (this.isUserRejectedRequestError(error))
599
+ throw new UserRejectedRequestError(error);
600
+ if (error.code === -32002)
601
+ throw new ResourceUnavailableError(error);
602
+ throw error;
603
+ }
604
+ }
605
+ async disconnect() {
606
+ const provider = await this.getProvider();
607
+ if (!provider?.removeListener)
608
+ return;
609
+ provider.removeListener("accountsChanged", this.onAccountsChanged);
610
+ provider.removeListener("chainChanged", this.onChainChanged);
611
+ provider.removeListener("disconnect", this.onDisconnect);
612
+ if (this.options.shimDisconnect)
613
+ getClient().storage?.removeItem(this.shimDisconnectKey);
614
+ }
615
+ async getAccount() {
616
+ const provider = await this.getProvider();
617
+ if (!provider)
618
+ throw new ConnectorNotFoundError();
619
+ const accounts = await provider.request({
620
+ method: "eth_accounts"
621
+ });
622
+ return getAddress(accounts[0]);
623
+ }
624
+ async getChainId() {
625
+ const provider = await this.getProvider();
626
+ if (!provider)
627
+ throw new ConnectorNotFoundError();
628
+ return provider.request({ method: "eth_chainId" }).then(normalizeChainId);
629
+ }
630
+ async getProvider() {
631
+ const provider = this.options.getProvider();
632
+ if (provider)
633
+ __privateSet(this, _provider, provider);
634
+ return __privateGet(this, _provider);
635
+ }
636
+ async getSigner({ chainId } = {}) {
637
+ const [provider, account] = await Promise.all([
638
+ this.getProvider(),
639
+ this.getAccount()
640
+ ]);
641
+ return new providers2.Web3Provider(
642
+ provider,
643
+ chainId
644
+ ).getSigner(account);
645
+ }
646
+ async isAuthorized() {
647
+ try {
648
+ if (this.options.shimDisconnect && !getClient().storage?.getItem(this.shimDisconnectKey))
649
+ return false;
650
+ const provider = await this.getProvider();
651
+ if (!provider)
652
+ throw new ConnectorNotFoundError();
653
+ const account = await this.getAccount();
654
+ return !!account;
655
+ } catch {
656
+ return false;
657
+ }
658
+ }
659
+ async switchChain(chainId) {
660
+ if (this.options.shimChainChangedDisconnect)
661
+ __privateSet(this, _switchingChains, true);
662
+ const provider = await this.getProvider();
663
+ if (!provider)
664
+ throw new ConnectorNotFoundError();
665
+ const id = hexValue(chainId);
666
+ try {
667
+ await provider.request({
668
+ method: "wallet_switchEthereumChain",
669
+ params: [{ chainId: id }]
670
+ });
671
+ return this.chains.find((x) => x.id === chainId) ?? {
672
+ id: chainId,
673
+ name: `Chain ${id}`,
674
+ network: `${id}`,
675
+ nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
676
+ rpcUrls: { default: { http: [""] } }
677
+ };
678
+ } catch (error) {
679
+ const chain = this.chains.find((x) => x.id === chainId);
680
+ if (!chain)
681
+ throw new ChainNotConfiguredError({ chainId, connectorId: this.id });
682
+ if (error.code === 4902 || error?.data?.originalError?.code === 4902) {
683
+ try {
684
+ await provider.request({
685
+ method: "wallet_addEthereumChain",
686
+ params: [
687
+ {
688
+ chainId: id,
689
+ chainName: chain.name,
690
+ nativeCurrency: chain.nativeCurrency,
691
+ rpcUrls: [
692
+ chain.rpcUrls.public?.http[0] ?? chain.rpcUrls.default.http[0] ?? ""
693
+ ],
694
+ blockExplorerUrls: this.getBlockExplorerUrls(chain)
695
+ }
696
+ ]
697
+ });
698
+ return chain;
699
+ } catch (addError) {
700
+ if (this.isUserRejectedRequestError(addError))
701
+ throw new UserRejectedRequestError(error);
702
+ throw new AddChainError();
703
+ }
577
704
  }
578
- ]
579
- },
580
- {
581
- type: "function",
582
- name: "balanceOf",
583
- stateMutability: "view",
584
- inputs: [
585
- {
586
- name: "account",
587
- type: "address"
588
- }
589
- ],
590
- outputs: [
591
- {
592
- name: "",
593
- type: "uint256"
594
- }
595
- ]
596
- },
597
- {
598
- type: "function",
599
- name: "decimals",
600
- stateMutability: "view",
601
- inputs: [],
602
- outputs: [
603
- {
604
- name: "",
605
- type: "uint8"
606
- }
607
- ]
608
- },
609
- {
610
- type: "function",
611
- name: "name",
612
- stateMutability: "view",
613
- inputs: [],
614
- outputs: [
615
- {
616
- name: "",
617
- type: "string"
618
- }
619
- ]
620
- },
621
- {
622
- type: "function",
623
- name: "symbol",
624
- stateMutability: "view",
625
- inputs: [],
626
- outputs: [
627
- {
628
- name: "",
629
- type: "string"
630
- }
631
- ]
632
- },
633
- {
634
- type: "function",
635
- name: "totalSupply",
636
- stateMutability: "view",
637
- inputs: [],
638
- outputs: [
639
- {
640
- name: "",
641
- type: "uint256"
642
- }
643
- ]
644
- },
645
- {
646
- type: "function",
647
- name: "transfer",
648
- stateMutability: "nonpayable",
649
- inputs: [
650
- {
651
- name: "recipient",
652
- type: "address"
653
- },
654
- {
655
- name: "amount",
656
- type: "uint256"
705
+ if (this.isUserRejectedRequestError(error))
706
+ throw new UserRejectedRequestError(error);
707
+ throw new SwitchChainError(error);
708
+ }
709
+ }
710
+ async watchAsset({
711
+ address,
712
+ decimals = 18,
713
+ image,
714
+ symbol
715
+ }) {
716
+ const provider = await this.getProvider();
717
+ if (!provider)
718
+ throw new ConnectorNotFoundError();
719
+ return provider.request({
720
+ method: "wallet_watchAsset",
721
+ params: {
722
+ type: "ERC20",
723
+ options: {
724
+ address,
725
+ decimals,
726
+ image,
727
+ symbol
728
+ }
657
729
  }
658
- ],
659
- outputs: [
660
- {
661
- name: "",
662
- type: "bool"
730
+ });
731
+ }
732
+ isUserRejectedRequestError(error) {
733
+ return error.code === 4001;
734
+ }
735
+ };
736
+ _provider = new WeakMap();
737
+ _switchingChains = new WeakMap();
738
+
739
+ // src/storage.ts
740
+ var noopStorage = {
741
+ getItem: (_key) => "",
742
+ setItem: (_key, _value) => null,
743
+ removeItem: (_key) => null
744
+ };
745
+ function createStorage({
746
+ deserialize: deserialize2 = deserialize,
747
+ key: prefix = "wagmi",
748
+ serialize: serialize2 = serialize,
749
+ storage
750
+ }) {
751
+ return {
752
+ ...storage,
753
+ getItem: (key, defaultState = null) => {
754
+ const value = storage.getItem(`${prefix}.${key}`);
755
+ try {
756
+ return value ? deserialize2(value) : defaultState;
757
+ } catch (error) {
758
+ console.warn(error);
759
+ return defaultState;
663
760
  }
664
- ]
665
- },
666
- {
667
- type: "function",
668
- name: "transferFrom",
669
- stateMutability: "nonpayable",
670
- inputs: [
671
- {
672
- name: "sender",
673
- type: "address"
674
- },
675
- {
676
- name: "recipient",
677
- type: "address"
678
- },
679
- {
680
- name: "amount",
681
- type: "uint256"
761
+ },
762
+ setItem: (key, value) => {
763
+ if (value === null) {
764
+ storage.removeItem(`${prefix}.${key}`);
765
+ } else {
766
+ try {
767
+ storage.setItem(`${prefix}.${key}`, serialize2(value));
768
+ } catch (err) {
769
+ console.error(err);
770
+ }
682
771
  }
683
- ],
684
- outputs: [
685
- {
686
- name: "",
687
- type: "bool"
772
+ },
773
+ removeItem: (key) => storage.removeItem(`${prefix}.${key}`)
774
+ };
775
+ }
776
+
777
+ // src/client.ts
778
+ var storeKey = "store";
779
+ var _isAutoConnecting, _lastUsedConnector, _addEffects, addEffects_fn;
780
+ var Client = class {
781
+ constructor({
782
+ autoConnect = false,
783
+ connectors = [new InjectedConnector()],
784
+ provider,
785
+ storage = createStorage({
786
+ storage: typeof window !== "undefined" ? window.localStorage : noopStorage
787
+ }),
788
+ logger = {
789
+ warn: console.warn
790
+ },
791
+ webSocketProvider
792
+ }) {
793
+ __privateAdd(this, _addEffects);
794
+ this.providers = /* @__PURE__ */ new Map();
795
+ this.webSocketProviders = /* @__PURE__ */ new Map();
796
+ __privateAdd(this, _isAutoConnecting, void 0);
797
+ __privateAdd(this, _lastUsedConnector, void 0);
798
+ this.config = {
799
+ autoConnect,
800
+ connectors,
801
+ logger,
802
+ provider,
803
+ storage,
804
+ webSocketProvider
805
+ };
806
+ let status = "disconnected";
807
+ let chainId;
808
+ if (autoConnect) {
809
+ try {
810
+ const rawState = storage.getItem(storeKey, "");
811
+ const data = JSON.parse(rawState || "{}")?.state?.data;
812
+ status = data?.account ? "reconnecting" : "connecting";
813
+ chainId = data?.chain?.id;
814
+ } catch (_error) {
688
815
  }
689
- ]
816
+ }
817
+ this.store = create(
818
+ subscribeWithSelector(
819
+ persist(
820
+ () => ({
821
+ connectors: typeof connectors === "function" ? connectors() : connectors,
822
+ provider: this.getProvider({ chainId }),
823
+ status,
824
+ webSocketProvider: this.getWebSocketProvider({ chainId })
825
+ }),
826
+ {
827
+ deserialize: (state) => state,
828
+ name: storeKey,
829
+ getStorage: () => storage,
830
+ partialize: (state) => ({
831
+ ...autoConnect && {
832
+ data: {
833
+ account: state?.data?.account,
834
+ chain: state?.data?.chain
835
+ }
836
+ },
837
+ chains: state?.chains
838
+ }),
839
+ serialize: (state) => state,
840
+ version: 2
841
+ }
842
+ )
843
+ )
844
+ );
845
+ this.storage = storage;
846
+ __privateSet(this, _lastUsedConnector, storage?.getItem("wallet"));
847
+ __privateMethod(this, _addEffects, addEffects_fn).call(this);
848
+ if (autoConnect && typeof window !== "undefined")
849
+ setTimeout(async () => await this.autoConnect(), 0);
690
850
  }
691
- ];
692
- var erc20ABI_bytes32 = [
693
- {
694
- type: "event",
695
- name: "Approval",
696
- inputs: [
697
- {
698
- indexed: true,
699
- name: "owner",
700
- type: "address"
701
- },
851
+ get chains() {
852
+ return this.store.getState().chains;
853
+ }
854
+ get connectors() {
855
+ return this.store.getState().connectors;
856
+ }
857
+ get connector() {
858
+ return this.store.getState().connector;
859
+ }
860
+ get data() {
861
+ return this.store.getState().data;
862
+ }
863
+ get error() {
864
+ return this.store.getState().error;
865
+ }
866
+ get lastUsedChainId() {
867
+ return this.data?.chain?.id;
868
+ }
869
+ get provider() {
870
+ return this.store.getState().provider;
871
+ }
872
+ get status() {
873
+ return this.store.getState().status;
874
+ }
875
+ get subscribe() {
876
+ return this.store.subscribe;
877
+ }
878
+ get webSocketProvider() {
879
+ return this.store.getState().webSocketProvider;
880
+ }
881
+ setState(updater) {
882
+ const newState = typeof updater === "function" ? updater(this.store.getState()) : updater;
883
+ this.store.setState(newState, true);
884
+ }
885
+ clearState() {
886
+ this.setState((x) => ({
887
+ ...x,
888
+ chains: void 0,
889
+ connector: void 0,
890
+ data: void 0,
891
+ error: void 0,
892
+ status: "disconnected"
893
+ }));
894
+ }
895
+ async destroy() {
896
+ if (this.connector)
897
+ await this.connector.disconnect?.();
898
+ __privateSet(this, _isAutoConnecting, false);
899
+ this.clearState();
900
+ this.store.destroy();
901
+ }
902
+ async autoConnect() {
903
+ if (__privateGet(this, _isAutoConnecting))
904
+ return;
905
+ __privateSet(this, _isAutoConnecting, true);
906
+ this.setState((x) => ({
907
+ ...x,
908
+ status: x.data?.account ? "reconnecting" : "connecting"
909
+ }));
910
+ const sorted = __privateGet(this, _lastUsedConnector) ? [...this.connectors].sort(
911
+ (x) => x.id === __privateGet(this, _lastUsedConnector) ? -1 : 1
912
+ ) : this.connectors;
913
+ let connected = false;
914
+ for (const connector of sorted) {
915
+ if (!connector.ready || !connector.isAuthorized)
916
+ continue;
917
+ const isAuthorized = await connector.isAuthorized();
918
+ if (!isAuthorized)
919
+ continue;
920
+ const data = await connector.connect();
921
+ this.setState((x) => ({
922
+ ...x,
923
+ connector,
924
+ chains: connector?.chains,
925
+ data,
926
+ status: "connected"
927
+ }));
928
+ connected = true;
929
+ break;
930
+ }
931
+ if (!connected)
932
+ this.setState((x) => ({
933
+ ...x,
934
+ data: void 0,
935
+ status: "disconnected"
936
+ }));
937
+ __privateSet(this, _isAutoConnecting, false);
938
+ return this.data;
939
+ }
940
+ getProvider({ bust, chainId } = {}) {
941
+ let provider_ = this.providers.get(chainId ?? -1);
942
+ if (provider_ && !bust)
943
+ return provider_;
944
+ const { provider } = this.config;
945
+ provider_ = typeof provider === "function" ? provider({ chainId }) : provider;
946
+ this.providers.set(chainId ?? -1, provider_);
947
+ return provider_;
948
+ }
949
+ getWebSocketProvider({
950
+ bust,
951
+ chainId
952
+ } = {}) {
953
+ let webSocketProvider_ = this.webSocketProviders.get(chainId ?? -1);
954
+ if (webSocketProvider_ && !bust)
955
+ return webSocketProvider_;
956
+ const { webSocketProvider } = this.config;
957
+ webSocketProvider_ = typeof webSocketProvider === "function" ? webSocketProvider({ chainId }) : webSocketProvider;
958
+ if (webSocketProvider_)
959
+ this.webSocketProviders.set(chainId ?? -1, webSocketProvider_);
960
+ return webSocketProvider_;
961
+ }
962
+ setLastUsedConnector(lastUsedConnector = null) {
963
+ this.storage?.setItem("wallet", lastUsedConnector);
964
+ }
965
+ };
966
+ _isAutoConnecting = new WeakMap();
967
+ _lastUsedConnector = new WeakMap();
968
+ _addEffects = new WeakSet();
969
+ addEffects_fn = function() {
970
+ const onChange = (data) => {
971
+ this.setState((x) => ({
972
+ ...x,
973
+ data: { ...x.data, ...data }
974
+ }));
975
+ };
976
+ const onDisconnect = () => {
977
+ this.clearState();
978
+ };
979
+ const onError = (error) => {
980
+ this.setState((x) => ({ ...x, error }));
981
+ };
982
+ this.store.subscribe(
983
+ ({ connector }) => connector,
984
+ (connector, prevConnector) => {
985
+ prevConnector?.off?.("change", onChange);
986
+ prevConnector?.off?.("disconnect", onDisconnect);
987
+ prevConnector?.off?.("error", onError);
988
+ if (!connector)
989
+ return;
990
+ connector.on?.("change", onChange);
991
+ connector.on?.("disconnect", onDisconnect);
992
+ connector.on?.("error", onError);
993
+ }
994
+ );
995
+ const { provider, webSocketProvider } = this.config;
996
+ const subscribeProvider = typeof provider === "function";
997
+ const subscribeWebSocketProvider = typeof webSocketProvider === "function";
998
+ if (subscribeProvider || subscribeWebSocketProvider)
999
+ this.store.subscribe(
1000
+ ({ data }) => data?.chain?.id,
1001
+ (chainId) => {
1002
+ this.setState((x) => ({
1003
+ ...x,
1004
+ provider: this.getProvider({ bust: true, chainId }),
1005
+ webSocketProvider: this.getWebSocketProvider({
1006
+ bust: true,
1007
+ chainId
1008
+ })
1009
+ }));
1010
+ }
1011
+ );
1012
+ };
1013
+ var client;
1014
+ function createClient(config) {
1015
+ const client_ = new Client(config);
1016
+ client = client_;
1017
+ return client_;
1018
+ }
1019
+ function getClient() {
1020
+ if (!client) {
1021
+ throw new Error(
1022
+ "No wagmi client found. Ensure you have set up a client: https://wagmi.sh/react/client"
1023
+ );
1024
+ }
1025
+ return client;
1026
+ }
1027
+
1028
+ // src/actions/accounts/connect.ts
1029
+ async function connect({
1030
+ chainId,
1031
+ connector
1032
+ }) {
1033
+ const client2 = getClient();
1034
+ const activeConnector = client2.connector;
1035
+ if (activeConnector && connector.id === activeConnector.id)
1036
+ throw new ConnectorAlreadyConnectedError();
1037
+ try {
1038
+ client2.setState((x) => ({ ...x, status: "connecting" }));
1039
+ const data = await connector.connect({ chainId });
1040
+ client2.setLastUsedConnector(connector.id);
1041
+ client2.setState((x) => ({
1042
+ ...x,
1043
+ connector,
1044
+ chains: connector?.chains,
1045
+ data,
1046
+ status: "connected"
1047
+ }));
1048
+ client2.storage.setItem("connected", true);
1049
+ return { ...data, connector };
1050
+ } catch (err) {
1051
+ client2.setState((x) => {
1052
+ return {
1053
+ ...x,
1054
+ status: x.connector ? "connected" : "disconnected"
1055
+ };
1056
+ });
1057
+ throw err;
1058
+ }
1059
+ }
1060
+
1061
+ // src/actions/accounts/disconnect.ts
1062
+ async function disconnect() {
1063
+ const client2 = getClient();
1064
+ if (client2.connector)
1065
+ await client2.connector.disconnect();
1066
+ client2.clearState();
1067
+ client2.storage.removeItem("connected");
1068
+ }
1069
+
1070
+ // src/actions/accounts/fetchBalance.ts
1071
+ import { formatUnits as formatUnits3, parseBytes32String as parseBytes32String2 } from "ethers/lib/utils.js";
1072
+
1073
+ // src/constants/abis.ts
1074
+ var erc20ABI = [
1075
+ {
1076
+ type: "event",
1077
+ name: "Approval",
1078
+ inputs: [
1079
+ {
1080
+ indexed: true,
1081
+ name: "owner",
1082
+ type: "address"
1083
+ },
702
1084
  {
703
1085
  indexed: true,
704
1086
  name: "spender",
@@ -811,7 +1193,7 @@ var erc20ABI_bytes32 = [
811
1193
  outputs: [
812
1194
  {
813
1195
  name: "",
814
- type: "bytes32"
1196
+ type: "string"
815
1197
  }
816
1198
  ]
817
1199
  },
@@ -823,7 +1205,7 @@ var erc20ABI_bytes32 = [
823
1205
  outputs: [
824
1206
  {
825
1207
  name: "",
826
- type: "bytes32"
1208
+ type: "string"
827
1209
  }
828
1210
  ]
829
1211
  },
@@ -886,7 +1268,7 @@ var erc20ABI_bytes32 = [
886
1268
  ]
887
1269
  }
888
1270
  ];
889
- var erc721ABI = [
1271
+ var erc20ABI_bytes32 = [
890
1272
  {
891
1273
  type: "event",
892
1274
  name: "Approval",
@@ -902,53 +1284,250 @@ var erc721ABI = [
902
1284
  type: "address"
903
1285
  },
904
1286
  {
905
- indexed: true,
906
- name: "tokenId",
1287
+ indexed: false,
1288
+ name: "value",
907
1289
  type: "uint256"
908
1290
  }
909
1291
  ]
910
1292
  },
911
1293
  {
912
1294
  type: "event",
913
- name: "ApprovalForAll",
1295
+ name: "Transfer",
914
1296
  inputs: [
915
1297
  {
916
1298
  indexed: true,
917
- name: "owner",
1299
+ name: "from",
918
1300
  type: "address"
919
1301
  },
920
1302
  {
921
1303
  indexed: true,
922
- name: "operator",
1304
+ name: "to",
923
1305
  type: "address"
924
1306
  },
925
1307
  {
926
1308
  indexed: false,
927
- name: "approved",
928
- type: "bool"
1309
+ name: "value",
1310
+ type: "uint256"
929
1311
  }
930
1312
  ]
931
1313
  },
932
1314
  {
933
- type: "event",
934
- name: "Transfer",
1315
+ type: "function",
1316
+ name: "allowance",
1317
+ stateMutability: "view",
935
1318
  inputs: [
936
1319
  {
937
- indexed: true,
938
- name: "from",
1320
+ name: "owner",
939
1321
  type: "address"
940
1322
  },
941
1323
  {
942
- indexed: true,
943
- name: "to",
1324
+ name: "spender",
944
1325
  type: "address"
945
- },
946
- {
947
- indexed: true,
948
- name: "tokenId",
949
- type: "uint256"
950
1326
  }
951
- ]
1327
+ ],
1328
+ outputs: [
1329
+ {
1330
+ name: "",
1331
+ type: "uint256"
1332
+ }
1333
+ ]
1334
+ },
1335
+ {
1336
+ type: "function",
1337
+ name: "approve",
1338
+ stateMutability: "nonpayable",
1339
+ inputs: [
1340
+ {
1341
+ name: "spender",
1342
+ type: "address"
1343
+ },
1344
+ {
1345
+ name: "amount",
1346
+ type: "uint256"
1347
+ }
1348
+ ],
1349
+ outputs: [
1350
+ {
1351
+ name: "",
1352
+ type: "bool"
1353
+ }
1354
+ ]
1355
+ },
1356
+ {
1357
+ type: "function",
1358
+ name: "balanceOf",
1359
+ stateMutability: "view",
1360
+ inputs: [
1361
+ {
1362
+ name: "account",
1363
+ type: "address"
1364
+ }
1365
+ ],
1366
+ outputs: [
1367
+ {
1368
+ name: "",
1369
+ type: "uint256"
1370
+ }
1371
+ ]
1372
+ },
1373
+ {
1374
+ type: "function",
1375
+ name: "decimals",
1376
+ stateMutability: "view",
1377
+ inputs: [],
1378
+ outputs: [
1379
+ {
1380
+ name: "",
1381
+ type: "uint8"
1382
+ }
1383
+ ]
1384
+ },
1385
+ {
1386
+ type: "function",
1387
+ name: "name",
1388
+ stateMutability: "view",
1389
+ inputs: [],
1390
+ outputs: [
1391
+ {
1392
+ name: "",
1393
+ type: "bytes32"
1394
+ }
1395
+ ]
1396
+ },
1397
+ {
1398
+ type: "function",
1399
+ name: "symbol",
1400
+ stateMutability: "view",
1401
+ inputs: [],
1402
+ outputs: [
1403
+ {
1404
+ name: "",
1405
+ type: "bytes32"
1406
+ }
1407
+ ]
1408
+ },
1409
+ {
1410
+ type: "function",
1411
+ name: "totalSupply",
1412
+ stateMutability: "view",
1413
+ inputs: [],
1414
+ outputs: [
1415
+ {
1416
+ name: "",
1417
+ type: "uint256"
1418
+ }
1419
+ ]
1420
+ },
1421
+ {
1422
+ type: "function",
1423
+ name: "transfer",
1424
+ stateMutability: "nonpayable",
1425
+ inputs: [
1426
+ {
1427
+ name: "recipient",
1428
+ type: "address"
1429
+ },
1430
+ {
1431
+ name: "amount",
1432
+ type: "uint256"
1433
+ }
1434
+ ],
1435
+ outputs: [
1436
+ {
1437
+ name: "",
1438
+ type: "bool"
1439
+ }
1440
+ ]
1441
+ },
1442
+ {
1443
+ type: "function",
1444
+ name: "transferFrom",
1445
+ stateMutability: "nonpayable",
1446
+ inputs: [
1447
+ {
1448
+ name: "sender",
1449
+ type: "address"
1450
+ },
1451
+ {
1452
+ name: "recipient",
1453
+ type: "address"
1454
+ },
1455
+ {
1456
+ name: "amount",
1457
+ type: "uint256"
1458
+ }
1459
+ ],
1460
+ outputs: [
1461
+ {
1462
+ name: "",
1463
+ type: "bool"
1464
+ }
1465
+ ]
1466
+ }
1467
+ ];
1468
+ var erc721ABI = [
1469
+ {
1470
+ type: "event",
1471
+ name: "Approval",
1472
+ inputs: [
1473
+ {
1474
+ indexed: true,
1475
+ name: "owner",
1476
+ type: "address"
1477
+ },
1478
+ {
1479
+ indexed: true,
1480
+ name: "spender",
1481
+ type: "address"
1482
+ },
1483
+ {
1484
+ indexed: true,
1485
+ name: "tokenId",
1486
+ type: "uint256"
1487
+ }
1488
+ ]
1489
+ },
1490
+ {
1491
+ type: "event",
1492
+ name: "ApprovalForAll",
1493
+ inputs: [
1494
+ {
1495
+ indexed: true,
1496
+ name: "owner",
1497
+ type: "address"
1498
+ },
1499
+ {
1500
+ indexed: true,
1501
+ name: "operator",
1502
+ type: "address"
1503
+ },
1504
+ {
1505
+ indexed: false,
1506
+ name: "approved",
1507
+ type: "bool"
1508
+ }
1509
+ ]
1510
+ },
1511
+ {
1512
+ type: "event",
1513
+ name: "Transfer",
1514
+ inputs: [
1515
+ {
1516
+ indexed: true,
1517
+ name: "from",
1518
+ type: "address"
1519
+ },
1520
+ {
1521
+ indexed: true,
1522
+ name: "to",
1523
+ type: "address"
1524
+ },
1525
+ {
1526
+ indexed: true,
1527
+ name: "tokenId",
1528
+ type: "uint256"
1529
+ }
1530
+ ]
952
1531
  },
953
1532
  {
954
1533
  type: "function",
@@ -1612,754 +2191,176 @@ var erc4626ABI = [
1612
2191
  name: "shares",
1613
2192
  type: "uint256"
1614
2193
  }
1615
- ],
1616
- name: "previewRedeem",
1617
- outputs: [
1618
- {
1619
- name: "assets",
1620
- type: "uint256"
1621
- }
1622
- ],
1623
- stateMutability: "view",
1624
- type: "function"
1625
- },
1626
- {
1627
- inputs: [
1628
- {
1629
- name: "assets",
1630
- type: "uint256"
1631
- }
1632
- ],
1633
- name: "previewWithdraw",
1634
- outputs: [
1635
- {
1636
- name: "shares",
1637
- type: "uint256"
1638
- }
1639
- ],
1640
- stateMutability: "view",
1641
- type: "function"
1642
- },
1643
- {
1644
- inputs: [
1645
- {
1646
- name: "shares",
1647
- type: "uint256"
1648
- },
1649
- {
1650
- name: "receiver",
1651
- type: "address"
1652
- },
1653
- {
1654
- name: "owner",
1655
- type: "address"
1656
- }
1657
- ],
1658
- name: "redeem",
1659
- outputs: [
1660
- {
1661
- name: "assets",
1662
- type: "uint256"
1663
- }
1664
- ],
1665
- stateMutability: "nonpayable",
1666
- type: "function"
1667
- },
1668
- {
1669
- inputs: [],
1670
- name: "totalAssets",
1671
- outputs: [
1672
- {
1673
- name: "totalManagedAssets",
1674
- type: "uint256"
1675
- }
1676
- ],
1677
- stateMutability: "view",
1678
- type: "function"
1679
- },
1680
- {
1681
- inputs: [],
1682
- name: "totalSupply",
1683
- outputs: [
1684
- {
1685
- name: "",
1686
- type: "uint256"
1687
- }
1688
- ],
1689
- stateMutability: "view",
1690
- type: "function"
1691
- },
1692
- {
1693
- inputs: [
1694
- {
1695
- name: "to",
1696
- type: "address"
1697
- },
1698
- {
1699
- name: "amount",
1700
- type: "uint256"
1701
- }
1702
- ],
1703
- name: "transfer",
1704
- outputs: [
1705
- {
1706
- name: "",
1707
- type: "bool"
1708
- }
1709
- ],
1710
- stateMutability: "nonpayable",
1711
- type: "function"
1712
- },
1713
- {
1714
- inputs: [
1715
- {
1716
- name: "from",
1717
- type: "address"
1718
- },
1719
- {
1720
- name: "to",
1721
- type: "address"
1722
- },
1723
- {
1724
- name: "amount",
1725
- type: "uint256"
1726
- }
1727
- ],
1728
- name: "transferFrom",
1729
- outputs: [
1730
- {
1731
- name: "",
1732
- type: "bool"
1733
- }
1734
- ],
1735
- stateMutability: "nonpayable",
1736
- type: "function"
1737
- },
1738
- {
1739
- inputs: [
1740
- {
1741
- name: "assets",
1742
- type: "uint256"
1743
- },
1744
- {
1745
- name: "receiver",
1746
- type: "address"
1747
- },
1748
- {
1749
- name: "owner",
1750
- type: "address"
1751
- }
1752
- ],
1753
- name: "withdraw",
1754
- outputs: [
1755
- {
1756
- name: "shares",
1757
- type: "uint256"
1758
- }
1759
- ],
1760
- stateMutability: "nonpayable",
1761
- type: "function"
1762
- }
1763
- ];
1764
-
1765
- // src/constants/units.ts
1766
- var units = [
1767
- "wei",
1768
- "kwei",
1769
- "mwei",
1770
- "gwei",
1771
- "szabo",
1772
- "finney",
1773
- "ether"
1774
- ];
1775
-
1776
- // src/connectors/base.ts
1777
- var Connector = class extends EventEmitter {
1778
- constructor({
1779
- chains = defaultChains,
1780
- options
1781
- }) {
1782
- super();
1783
- this.chains = chains;
1784
- this.options = options;
1785
- }
1786
- getBlockExplorerUrls(chain2) {
1787
- const { default: blockExplorer, ...blockExplorers } = chain2.blockExplorers ?? {};
1788
- if (blockExplorer)
1789
- return [
1790
- blockExplorer.url,
1791
- ...Object.values(blockExplorers).map((x) => x.url)
1792
- ];
1793
- }
1794
- isChainUnsupported(chainId2) {
1795
- return !this.chains.some((x) => x.id === chainId2);
1796
- }
1797
- };
1798
-
1799
- // src/connectors/injected.ts
1800
- var _provider, _switchingChains;
1801
- var InjectedConnector = class extends Connector {
1802
- constructor({
1803
- chains,
1804
- options: options_
1805
- } = {}) {
1806
- const options = {
1807
- shimDisconnect: true,
1808
- shimChainChangedDisconnect: true,
1809
- getProvider: () => typeof window !== "undefined" ? window.ethereum : void 0,
1810
- ...options_
1811
- };
1812
- super({ chains, options });
1813
- __privateAdd(this, _provider, void 0);
1814
- __privateAdd(this, _switchingChains, void 0);
1815
- this.shimDisconnectKey = "injected.shimDisconnect";
1816
- this.onAccountsChanged = (accounts) => {
1817
- if (accounts.length === 0)
1818
- this.emit("disconnect");
1819
- else
1820
- this.emit("change", {
1821
- account: getAddress(accounts[0])
1822
- });
1823
- };
1824
- this.onChainChanged = (chainId2) => {
1825
- const id = normalizeChainId(chainId2);
1826
- const unsupported = this.isChainUnsupported(id);
1827
- this.emit("change", { chain: { id, unsupported } });
1828
- };
1829
- this.onDisconnect = () => {
1830
- if (this.options.shimChainChangedDisconnect && __privateGet(this, _switchingChains)) {
1831
- __privateSet(this, _switchingChains, false);
1832
- return;
1833
- }
1834
- this.emit("disconnect");
1835
- if (this.options.shimDisconnect)
1836
- getClient().storage?.removeItem(this.shimDisconnectKey);
1837
- };
1838
- const provider = options.getProvider();
1839
- if (typeof options.name === "string")
1840
- this.name = options.name;
1841
- else if (provider) {
1842
- const detectedName = getInjectedName(provider);
1843
- if (options.name)
1844
- this.name = options.name(detectedName);
1845
- else {
1846
- if (typeof detectedName === "string")
1847
- this.name = detectedName;
1848
- else
1849
- this.name = detectedName[0];
1850
- }
1851
- } else
1852
- this.name = "Injected";
1853
- this.id = "injected";
1854
- this.ready = !!provider;
1855
- }
1856
- async connect({ chainId: chainId2 } = {}) {
1857
- try {
1858
- const provider = await this.getProvider();
1859
- if (!provider)
1860
- throw new ConnectorNotFoundError();
1861
- if (provider.on) {
1862
- provider.on("accountsChanged", this.onAccountsChanged);
1863
- provider.on("chainChanged", this.onChainChanged);
1864
- provider.on("disconnect", this.onDisconnect);
1865
- }
1866
- this.emit("message", { type: "connecting" });
1867
- const accounts = await provider.request({
1868
- method: "eth_requestAccounts"
1869
- });
1870
- const account = getAddress(accounts[0]);
1871
- let id = await this.getChainId();
1872
- let unsupported = this.isChainUnsupported(id);
1873
- if (chainId2 && id !== chainId2) {
1874
- const chain2 = await this.switchChain(chainId2);
1875
- id = chain2.id;
1876
- unsupported = this.isChainUnsupported(id);
1877
- }
1878
- if (this.options.shimDisconnect)
1879
- getClient().storage?.setItem(this.shimDisconnectKey, true);
1880
- return { account, chain: { id, unsupported }, provider };
1881
- } catch (error) {
1882
- if (this.isUserRejectedRequestError(error))
1883
- throw new UserRejectedRequestError(error);
1884
- if (error.code === -32002)
1885
- throw new ResourceUnavailableError(error);
1886
- throw error;
1887
- }
1888
- }
1889
- async disconnect() {
1890
- const provider = await this.getProvider();
1891
- if (!provider?.removeListener)
1892
- return;
1893
- provider.removeListener("accountsChanged", this.onAccountsChanged);
1894
- provider.removeListener("chainChanged", this.onChainChanged);
1895
- provider.removeListener("disconnect", this.onDisconnect);
1896
- if (this.options.shimDisconnect)
1897
- getClient().storage?.removeItem(this.shimDisconnectKey);
1898
- }
1899
- async getAccount() {
1900
- const provider = await this.getProvider();
1901
- if (!provider)
1902
- throw new ConnectorNotFoundError();
1903
- const accounts = await provider.request({
1904
- method: "eth_accounts"
1905
- });
1906
- return getAddress(accounts[0]);
1907
- }
1908
- async getChainId() {
1909
- const provider = await this.getProvider();
1910
- if (!provider)
1911
- throw new ConnectorNotFoundError();
1912
- return provider.request({ method: "eth_chainId" }).then(normalizeChainId);
1913
- }
1914
- async getProvider() {
1915
- const provider = this.options.getProvider();
1916
- if (provider)
1917
- __privateSet(this, _provider, provider);
1918
- return __privateGet(this, _provider);
1919
- }
1920
- async getSigner({ chainId: chainId2 } = {}) {
1921
- const [provider, account] = await Promise.all([
1922
- this.getProvider(),
1923
- this.getAccount()
1924
- ]);
1925
- return new providers2.Web3Provider(
1926
- provider,
1927
- chainId2
1928
- ).getSigner(account);
1929
- }
1930
- async isAuthorized() {
1931
- try {
1932
- if (this.options.shimDisconnect && !getClient().storage?.getItem(this.shimDisconnectKey))
1933
- return false;
1934
- const provider = await this.getProvider();
1935
- if (!provider)
1936
- throw new ConnectorNotFoundError();
1937
- const account = await this.getAccount();
1938
- return !!account;
1939
- } catch {
1940
- return false;
1941
- }
1942
- }
1943
- async switchChain(chainId2) {
1944
- if (this.options.shimChainChangedDisconnect)
1945
- __privateSet(this, _switchingChains, true);
1946
- const provider = await this.getProvider();
1947
- if (!provider)
1948
- throw new ConnectorNotFoundError();
1949
- const id = hexValue(chainId2);
1950
- try {
1951
- await provider.request({
1952
- method: "wallet_switchEthereumChain",
1953
- params: [{ chainId: id }]
1954
- });
1955
- return this.chains.find((x) => x.id === chainId2) ?? {
1956
- id: chainId2,
1957
- name: `Chain ${id}`,
1958
- network: `${id}`,
1959
- rpcUrls: { default: "" }
1960
- };
1961
- } catch (error) {
1962
- const chain2 = this.chains.find((x) => x.id === chainId2);
1963
- if (!chain2)
1964
- throw new ChainNotConfiguredError({ chainId: chainId2, connectorId: this.id });
1965
- if (error.code === 4902 || error?.data?.originalError?.code === 4902) {
1966
- try {
1967
- await provider.request({
1968
- method: "wallet_addEthereumChain",
1969
- params: [
1970
- {
1971
- chainId: id,
1972
- chainName: chain2.name,
1973
- nativeCurrency: chain2.nativeCurrency,
1974
- rpcUrls: [chain2.rpcUrls.public ?? chain2.rpcUrls.default],
1975
- blockExplorerUrls: this.getBlockExplorerUrls(chain2)
1976
- }
1977
- ]
1978
- });
1979
- return chain2;
1980
- } catch (addError) {
1981
- if (this.isUserRejectedRequestError(addError))
1982
- throw new UserRejectedRequestError(error);
1983
- throw new AddChainError();
1984
- }
1985
- }
1986
- if (this.isUserRejectedRequestError(error))
1987
- throw new UserRejectedRequestError(error);
1988
- throw new SwitchChainError(error);
1989
- }
1990
- }
1991
- async watchAsset({
1992
- address,
1993
- decimals = 18,
1994
- image,
1995
- symbol
1996
- }) {
1997
- const provider = await this.getProvider();
1998
- if (!provider)
1999
- throw new ConnectorNotFoundError();
2000
- return provider.request({
2001
- method: "wallet_watchAsset",
2002
- params: {
2003
- type: "ERC20",
2004
- options: {
2005
- address,
2006
- decimals,
2007
- image,
2008
- symbol
2009
- }
2010
- }
2011
- });
2012
- }
2013
- isUserRejectedRequestError(error) {
2014
- return error.code === 4001;
2015
- }
2016
- };
2017
- _provider = new WeakMap();
2018
- _switchingChains = new WeakMap();
2019
-
2020
- // src/storage.ts
2021
- var noopStorage = {
2022
- getItem: (_key) => "",
2023
- setItem: (_key, _value) => null,
2024
- removeItem: (_key) => null
2025
- };
2026
- function createStorage({
2027
- deserialize: deserialize2 = deserialize,
2028
- key: prefix = "wagmi",
2029
- serialize: serialize2 = serialize,
2030
- storage
2031
- }) {
2032
- return {
2033
- ...storage,
2034
- getItem: (key, defaultState = null) => {
2035
- const value = storage.getItem(`${prefix}.${key}`);
2036
- try {
2037
- return value ? deserialize2(value) : defaultState;
2038
- } catch (error) {
2039
- console.warn(error);
2040
- return defaultState;
2041
- }
2042
- },
2043
- setItem: (key, value) => {
2044
- if (value === null) {
2045
- storage.removeItem(`${prefix}.${key}`);
2046
- } else {
2047
- try {
2048
- storage.setItem(`${prefix}.${key}`, serialize2(value));
2049
- } catch (err) {
2050
- console.error(err);
2051
- }
2052
- }
2053
- },
2054
- removeItem: (key) => storage.removeItem(`${prefix}.${key}`)
2055
- };
2056
- }
2057
-
2058
- // src/client.ts
2059
- var storeKey = "store";
2060
- var _isAutoConnecting, _lastUsedConnector, _addEffects, addEffects_fn;
2061
- var Client = class {
2062
- constructor({
2063
- autoConnect = false,
2064
- connectors = [new InjectedConnector()],
2065
- provider,
2066
- storage = createStorage({
2067
- storage: typeof window !== "undefined" ? window.localStorage : noopStorage
2068
- }),
2069
- logger = {
2070
- warn: console.warn
2071
- },
2072
- webSocketProvider
2073
- }) {
2074
- __privateAdd(this, _addEffects);
2075
- this.providers = /* @__PURE__ */ new Map();
2076
- this.webSocketProviders = /* @__PURE__ */ new Map();
2077
- __privateAdd(this, _isAutoConnecting, void 0);
2078
- __privateAdd(this, _lastUsedConnector, void 0);
2079
- this.config = {
2080
- autoConnect,
2081
- connectors,
2082
- logger,
2083
- provider,
2084
- storage,
2085
- webSocketProvider
2086
- };
2087
- let status = "disconnected";
2088
- let chainId2;
2089
- if (autoConnect) {
2090
- try {
2091
- const rawState = storage.getItem(storeKey, "");
2092
- const data = JSON.parse(rawState || "{}")?.state?.data;
2093
- status = data?.account ? "reconnecting" : "connecting";
2094
- chainId2 = data?.chain?.id;
2095
- } catch (_error) {
2096
- }
2097
- }
2098
- this.store = create(
2099
- subscribeWithSelector(
2100
- persist(
2101
- () => ({
2102
- connectors: typeof connectors === "function" ? connectors() : connectors,
2103
- provider: this.getProvider({ chainId: chainId2 }),
2104
- status,
2105
- webSocketProvider: this.getWebSocketProvider({ chainId: chainId2 })
2106
- }),
2107
- {
2108
- deserialize: (state) => state,
2109
- name: storeKey,
2110
- getStorage: () => storage,
2111
- partialize: (state) => ({
2112
- ...autoConnect && {
2113
- data: {
2114
- account: state?.data?.account,
2115
- chain: state?.data?.chain
2116
- }
2117
- },
2118
- chains: state?.chains
2119
- }),
2120
- serialize: (state) => state,
2121
- version: 2
2122
- }
2123
- )
2124
- )
2125
- );
2126
- this.storage = storage;
2127
- __privateSet(this, _lastUsedConnector, storage?.getItem("wallet"));
2128
- __privateMethod(this, _addEffects, addEffects_fn).call(this);
2129
- if (autoConnect && typeof window !== "undefined")
2130
- setTimeout(async () => await this.autoConnect(), 0);
2131
- }
2132
- get chains() {
2133
- return this.store.getState().chains;
2134
- }
2135
- get connectors() {
2136
- return this.store.getState().connectors;
2137
- }
2138
- get connector() {
2139
- return this.store.getState().connector;
2140
- }
2141
- get data() {
2142
- return this.store.getState().data;
2143
- }
2144
- get error() {
2145
- return this.store.getState().error;
2146
- }
2147
- get lastUsedChainId() {
2148
- return this.data?.chain?.id;
2149
- }
2150
- get provider() {
2151
- return this.store.getState().provider;
2152
- }
2153
- get status() {
2154
- return this.store.getState().status;
2155
- }
2156
- get subscribe() {
2157
- return this.store.subscribe;
2158
- }
2159
- get webSocketProvider() {
2160
- return this.store.getState().webSocketProvider;
2161
- }
2162
- setState(updater) {
2163
- const newState = typeof updater === "function" ? updater(this.store.getState()) : updater;
2164
- this.store.setState(newState, true);
2165
- }
2166
- clearState() {
2167
- this.setState((x) => ({
2168
- ...x,
2169
- chains: void 0,
2170
- connector: void 0,
2171
- data: void 0,
2172
- error: void 0,
2173
- status: "disconnected"
2174
- }));
2175
- }
2176
- async destroy() {
2177
- if (this.connector)
2178
- await this.connector.disconnect?.();
2179
- __privateSet(this, _isAutoConnecting, false);
2180
- this.clearState();
2181
- this.store.destroy();
2182
- }
2183
- async autoConnect() {
2184
- if (__privateGet(this, _isAutoConnecting))
2185
- return;
2186
- __privateSet(this, _isAutoConnecting, true);
2187
- this.setState((x) => ({
2188
- ...x,
2189
- status: x.data?.account ? "reconnecting" : "connecting"
2190
- }));
2191
- const sorted = __privateGet(this, _lastUsedConnector) ? [...this.connectors].sort(
2192
- (x) => x.id === __privateGet(this, _lastUsedConnector) ? -1 : 1
2193
- ) : this.connectors;
2194
- let connected = false;
2195
- for (const connector of sorted) {
2196
- if (!connector.ready || !connector.isAuthorized)
2197
- continue;
2198
- const isAuthorized = await connector.isAuthorized();
2199
- if (!isAuthorized)
2200
- continue;
2201
- const data = await connector.connect();
2202
- this.setState((x) => ({
2203
- ...x,
2204
- connector,
2205
- chains: connector?.chains,
2206
- data,
2207
- status: "connected"
2208
- }));
2209
- connected = true;
2210
- break;
2211
- }
2212
- if (!connected)
2213
- this.setState((x) => ({
2214
- ...x,
2215
- data: void 0,
2216
- status: "disconnected"
2217
- }));
2218
- __privateSet(this, _isAutoConnecting, false);
2219
- return this.data;
2220
- }
2221
- getProvider({ bust, chainId: chainId2 } = {}) {
2222
- let provider_ = this.providers.get(chainId2 ?? -1);
2223
- if (provider_ && !bust)
2224
- return provider_;
2225
- const { provider } = this.config;
2226
- provider_ = typeof provider === "function" ? provider({ chainId: chainId2 }) : provider;
2227
- this.providers.set(chainId2 ?? -1, provider_);
2228
- return provider_;
2229
- }
2230
- getWebSocketProvider({
2231
- bust,
2232
- chainId: chainId2
2233
- } = {}) {
2234
- let webSocketProvider_ = this.webSocketProviders.get(chainId2 ?? -1);
2235
- if (webSocketProvider_ && !bust)
2236
- return webSocketProvider_;
2237
- const { webSocketProvider } = this.config;
2238
- webSocketProvider_ = typeof webSocketProvider === "function" ? webSocketProvider({ chainId: chainId2 }) : webSocketProvider;
2239
- if (webSocketProvider_)
2240
- this.webSocketProviders.set(chainId2 ?? -1, webSocketProvider_);
2241
- return webSocketProvider_;
2242
- }
2243
- setLastUsedConnector(lastUsedConnector = null) {
2244
- this.storage?.setItem("wallet", lastUsedConnector);
2245
- }
2246
- };
2247
- _isAutoConnecting = new WeakMap();
2248
- _lastUsedConnector = new WeakMap();
2249
- _addEffects = new WeakSet();
2250
- addEffects_fn = function() {
2251
- const onChange = (data) => {
2252
- this.setState((x) => ({
2253
- ...x,
2254
- data: { ...x.data, ...data }
2255
- }));
2256
- };
2257
- const onDisconnect = () => {
2258
- this.clearState();
2259
- };
2260
- const onError = (error) => {
2261
- this.setState((x) => ({ ...x, error }));
2262
- };
2263
- this.store.subscribe(
2264
- ({ connector }) => connector,
2265
- (connector, prevConnector) => {
2266
- prevConnector?.off?.("change", onChange);
2267
- prevConnector?.off?.("disconnect", onDisconnect);
2268
- prevConnector?.off?.("error", onError);
2269
- if (!connector)
2270
- return;
2271
- connector.on?.("change", onChange);
2272
- connector.on?.("disconnect", onDisconnect);
2273
- connector.on?.("error", onError);
2274
- }
2275
- );
2276
- const { provider, webSocketProvider } = this.config;
2277
- const subscribeProvider = typeof provider === "function";
2278
- const subscribeWebSocketProvider = typeof webSocketProvider === "function";
2279
- if (subscribeProvider || subscribeWebSocketProvider)
2280
- this.store.subscribe(
2281
- ({ data }) => data?.chain?.id,
2282
- (chainId2) => {
2283
- this.setState((x) => ({
2284
- ...x,
2285
- provider: this.getProvider({ bust: true, chainId: chainId2 }),
2286
- webSocketProvider: this.getWebSocketProvider({
2287
- bust: true,
2288
- chainId: chainId2
2289
- })
2290
- }));
2291
- }
2292
- );
2293
- };
2294
- var client;
2295
- function createClient(config) {
2296
- const client_ = new Client(config);
2297
- client = client_;
2298
- return client_;
2299
- }
2300
- function getClient() {
2301
- if (!client) {
2302
- throw new Error(
2303
- "No wagmi client found. Ensure you have set up a client: https://wagmi.sh/react/client"
2304
- );
2305
- }
2306
- return client;
2307
- }
2308
-
2309
- // src/actions/accounts/connect.ts
2310
- async function connect({
2311
- chainId: chainId2,
2312
- connector
2313
- }) {
2314
- const client2 = getClient();
2315
- const activeConnector = client2.connector;
2316
- if (activeConnector && connector.id === activeConnector.id)
2317
- throw new ConnectorAlreadyConnectedError();
2318
- try {
2319
- client2.setState((x) => ({ ...x, status: "connecting" }));
2320
- const data = await connector.connect({ chainId: chainId2 });
2321
- client2.setLastUsedConnector(connector.id);
2322
- client2.setState((x) => ({
2323
- ...x,
2324
- connector,
2325
- chains: connector?.chains,
2326
- data,
2327
- status: "connected"
2328
- }));
2329
- client2.storage.setItem("connected", true);
2330
- return { ...data, connector };
2331
- } catch (err) {
2332
- client2.setState((x) => {
2333
- return {
2334
- ...x,
2335
- status: x.connector ? "connected" : "disconnected"
2336
- };
2337
- });
2338
- throw err;
2194
+ ],
2195
+ name: "previewRedeem",
2196
+ outputs: [
2197
+ {
2198
+ name: "assets",
2199
+ type: "uint256"
2200
+ }
2201
+ ],
2202
+ stateMutability: "view",
2203
+ type: "function"
2204
+ },
2205
+ {
2206
+ inputs: [
2207
+ {
2208
+ name: "assets",
2209
+ type: "uint256"
2210
+ }
2211
+ ],
2212
+ name: "previewWithdraw",
2213
+ outputs: [
2214
+ {
2215
+ name: "shares",
2216
+ type: "uint256"
2217
+ }
2218
+ ],
2219
+ stateMutability: "view",
2220
+ type: "function"
2221
+ },
2222
+ {
2223
+ inputs: [
2224
+ {
2225
+ name: "shares",
2226
+ type: "uint256"
2227
+ },
2228
+ {
2229
+ name: "receiver",
2230
+ type: "address"
2231
+ },
2232
+ {
2233
+ name: "owner",
2234
+ type: "address"
2235
+ }
2236
+ ],
2237
+ name: "redeem",
2238
+ outputs: [
2239
+ {
2240
+ name: "assets",
2241
+ type: "uint256"
2242
+ }
2243
+ ],
2244
+ stateMutability: "nonpayable",
2245
+ type: "function"
2246
+ },
2247
+ {
2248
+ inputs: [],
2249
+ name: "totalAssets",
2250
+ outputs: [
2251
+ {
2252
+ name: "totalManagedAssets",
2253
+ type: "uint256"
2254
+ }
2255
+ ],
2256
+ stateMutability: "view",
2257
+ type: "function"
2258
+ },
2259
+ {
2260
+ inputs: [],
2261
+ name: "totalSupply",
2262
+ outputs: [
2263
+ {
2264
+ name: "",
2265
+ type: "uint256"
2266
+ }
2267
+ ],
2268
+ stateMutability: "view",
2269
+ type: "function"
2270
+ },
2271
+ {
2272
+ inputs: [
2273
+ {
2274
+ name: "to",
2275
+ type: "address"
2276
+ },
2277
+ {
2278
+ name: "amount",
2279
+ type: "uint256"
2280
+ }
2281
+ ],
2282
+ name: "transfer",
2283
+ outputs: [
2284
+ {
2285
+ name: "",
2286
+ type: "bool"
2287
+ }
2288
+ ],
2289
+ stateMutability: "nonpayable",
2290
+ type: "function"
2291
+ },
2292
+ {
2293
+ inputs: [
2294
+ {
2295
+ name: "from",
2296
+ type: "address"
2297
+ },
2298
+ {
2299
+ name: "to",
2300
+ type: "address"
2301
+ },
2302
+ {
2303
+ name: "amount",
2304
+ type: "uint256"
2305
+ }
2306
+ ],
2307
+ name: "transferFrom",
2308
+ outputs: [
2309
+ {
2310
+ name: "",
2311
+ type: "bool"
2312
+ }
2313
+ ],
2314
+ stateMutability: "nonpayable",
2315
+ type: "function"
2316
+ },
2317
+ {
2318
+ inputs: [
2319
+ {
2320
+ name: "assets",
2321
+ type: "uint256"
2322
+ },
2323
+ {
2324
+ name: "receiver",
2325
+ type: "address"
2326
+ },
2327
+ {
2328
+ name: "owner",
2329
+ type: "address"
2330
+ }
2331
+ ],
2332
+ name: "withdraw",
2333
+ outputs: [
2334
+ {
2335
+ name: "shares",
2336
+ type: "uint256"
2337
+ }
2338
+ ],
2339
+ stateMutability: "nonpayable",
2340
+ type: "function"
2339
2341
  }
2340
- }
2341
-
2342
- // src/actions/accounts/disconnect.ts
2343
- async function disconnect() {
2344
- const client2 = getClient();
2345
- if (client2.connector)
2346
- await client2.connector.disconnect();
2347
- client2.clearState();
2348
- client2.storage.removeItem("connected");
2349
- }
2342
+ ];
2350
2343
 
2351
- // src/actions/accounts/fetchBalance.ts
2352
- import { formatUnits as formatUnits2, parseBytes32String as parseBytes32String2 } from "ethers/lib/utils.js";
2344
+ // src/constants/units.ts
2345
+ var units = [
2346
+ "wei",
2347
+ "kwei",
2348
+ "mwei",
2349
+ "gwei",
2350
+ "szabo",
2351
+ "finney",
2352
+ "ether"
2353
+ ];
2353
2354
 
2354
2355
  // src/actions/contracts/fetchToken.ts
2355
2356
  import { formatUnits, parseBytes32String } from "ethers/lib/utils.js";
2356
2357
  async function fetchToken({
2357
2358
  address,
2358
- chainId: chainId2,
2359
+ chainId,
2359
2360
  formatUnits: units2 = "ether"
2360
2361
  }) {
2361
2362
  async function fetchToken_({ abi }) {
2362
- const erc20Config = { address, abi, chainId: chainId2 };
2363
+ const erc20Config = { address, abi, chainId };
2363
2364
  const [decimals, name, symbol, totalSupply] = await readContracts({
2364
2365
  allowFailure: false,
2365
2366
  contracts: [
@@ -2416,16 +2417,16 @@ async function prepareWriteContract({
2416
2417
  abi,
2417
2418
  address,
2418
2419
  args,
2419
- chainId: chainId2,
2420
+ chainId,
2420
2421
  functionName,
2421
2422
  overrides,
2422
2423
  signer: signer_
2423
2424
  }) {
2424
- const signer = signer_ ?? await fetchSigner({ chainId: chainId2 });
2425
+ const signer = signer_ ?? await fetchSigner({ chainId });
2425
2426
  if (!signer)
2426
2427
  throw new ConnectorNotFoundError();
2427
- if (chainId2)
2428
- assertActiveChain({ chainId: chainId2, signer });
2428
+ if (chainId)
2429
+ assertActiveChain({ chainId, signer });
2429
2430
  const contract = getContract({
2430
2431
  address,
2431
2432
  abi,
@@ -2454,7 +2455,7 @@ async function prepareWriteContract({
2454
2455
  return {
2455
2456
  abi: minimizedAbi,
2456
2457
  address,
2457
- chainId: chainId2,
2458
+ chainId,
2458
2459
  functionName,
2459
2460
  mode: "prepared",
2460
2461
  request: {
@@ -2466,21 +2467,21 @@ async function prepareWriteContract({
2466
2467
 
2467
2468
  // src/actions/providers/getProvider.ts
2468
2469
  function getProvider({
2469
- chainId: chainId2
2470
+ chainId
2470
2471
  } = {}) {
2471
2472
  const client2 = getClient();
2472
- if (chainId2)
2473
- return client2.getProvider({ chainId: chainId2 }) || client2.provider;
2473
+ if (chainId)
2474
+ return client2.getProvider({ chainId }) || client2.provider;
2474
2475
  return client2.provider;
2475
2476
  }
2476
2477
 
2477
2478
  // src/actions/providers/getWebSocketProvider.ts
2478
2479
  function getWebSocketProvider({
2479
- chainId: chainId2
2480
+ chainId
2480
2481
  } = {}) {
2481
2482
  const client2 = getClient();
2482
- if (chainId2)
2483
- return client2.getWebSocketProvider({ chainId: chainId2 }) || client2.webSocketProvider;
2483
+ if (chainId)
2484
+ return client2.getWebSocketProvider({ chainId }) || client2.webSocketProvider;
2484
2485
  return client2.webSocketProvider;
2485
2486
  }
2486
2487
 
@@ -2506,25 +2507,25 @@ function watchWebSocketProvider(args, callback) {
2506
2507
  // src/actions/contracts/multicall.ts
2507
2508
  async function multicall({
2508
2509
  allowFailure = true,
2509
- chainId: chainId2,
2510
+ chainId,
2510
2511
  contracts,
2511
2512
  overrides
2512
2513
  }) {
2513
- const provider = getProvider({ chainId: chainId2 });
2514
+ const provider = getProvider({ chainId });
2514
2515
  if (!provider.chains)
2515
2516
  throw new ProviderChainsNotFound();
2516
- const chain2 = provider.chains.find((chain3) => chain3.id === chainId2) || provider.chains[0];
2517
- if (!chain2)
2517
+ const chain = provider.chains.find((chain2) => chain2.id === chainId) || provider.chains[0];
2518
+ if (!chain)
2518
2519
  throw new ProviderChainsNotFound();
2519
- if (!chain2?.multicall)
2520
- throw new ChainDoesNotSupportMulticallError({ chain: chain2 });
2521
- if (typeof overrides?.blockTag === "number" && overrides?.blockTag < chain2.multicall.blockCreated)
2520
+ if (!chain?.contracts?.multicall3)
2521
+ throw new ChainDoesNotSupportMulticallError({ chain });
2522
+ if (typeof overrides?.blockTag === "number" && overrides?.blockTag < (chain.contracts.multicall3.blockCreated ?? 0))
2522
2523
  throw new ChainDoesNotSupportMulticallError({
2523
2524
  blockNumber: overrides?.blockTag,
2524
- chain: chain2
2525
+ chain
2525
2526
  });
2526
2527
  const multicallContract = getContract({
2527
- address: chain2.multicall.address,
2528
+ address: chain.contracts.multicall3.address,
2528
2529
  abi: multicallABI,
2529
2530
  signerOrProvider: provider
2530
2531
  });
@@ -2590,7 +2591,7 @@ async function multicall({
2590
2591
  error = new ContractMethodRevertedError({
2591
2592
  address,
2592
2593
  args,
2593
- chainId: chain2.id,
2594
+ chainId: chain.id,
2594
2595
  functionName: normalizedFunctionName,
2595
2596
  errorMessage: err.message
2596
2597
  });
@@ -2604,7 +2605,7 @@ async function multicall({
2604
2605
  const error = new ContractMethodNoResultError({
2605
2606
  address,
2606
2607
  args,
2607
- chainId: chain2.id,
2608
+ chainId: chain.id,
2608
2609
  functionName: normalizedFunctionName
2609
2610
  });
2610
2611
  if (!allowFailure)
@@ -2622,7 +2623,7 @@ async function multicall({
2622
2623
  const error = new ContractResultDecodeError({
2623
2624
  address,
2624
2625
  args,
2625
- chainId: chain2.id,
2626
+ chainId: chain.id,
2626
2627
  functionName: normalizedFunctionName,
2627
2628
  errorMessage: err.message
2628
2629
  });
@@ -2638,12 +2639,12 @@ async function multicall({
2638
2639
  async function readContract({
2639
2640
  address,
2640
2641
  args,
2641
- chainId: chainId2,
2642
+ chainId,
2642
2643
  abi,
2643
2644
  functionName,
2644
2645
  overrides
2645
2646
  }) {
2646
- const provider = getProvider({ chainId: chainId2 });
2647
+ const provider = getProvider({ chainId });
2647
2648
  const contract = getContract({
2648
2649
  address,
2649
2650
  abi,
@@ -2673,16 +2674,16 @@ async function readContracts({
2673
2674
  try {
2674
2675
  const provider = getProvider();
2675
2676
  const contractsByChainId = contracts.reduce((contracts2, contract, index) => {
2676
- const chainId2 = contract.chainId ?? provider.network.chainId;
2677
+ const chainId = contract.chainId ?? provider.network.chainId;
2677
2678
  return {
2678
2679
  ...contracts2,
2679
- [chainId2]: [...contracts2[chainId2] || [], { contract, index }]
2680
+ [chainId]: [...contracts2[chainId] || [], { contract, index }]
2680
2681
  };
2681
2682
  }, {});
2682
2683
  const promises = () => Object.entries(contractsByChainId).map(
2683
- ([chainId2, contracts2]) => multicall({
2684
+ ([chainId, contracts2]) => multicall({
2684
2685
  allowFailure,
2685
- chainId: parseInt(chainId2),
2686
+ chainId: parseInt(chainId),
2686
2687
  contracts: contracts2.map(({ contract }) => contract),
2687
2688
  overrides
2688
2689
  })
@@ -2721,11 +2722,11 @@ async function readContracts({
2721
2722
  return (await Promise.allSettled(promises())).map((result, i) => {
2722
2723
  if (result.status === "fulfilled")
2723
2724
  return result.value;
2724
- const { address, args, chainId: chainId2, functionName } = contracts[i];
2725
+ const { address, args, chainId, functionName } = contracts[i];
2725
2726
  const error = new ContractMethodRevertedError({
2726
2727
  address,
2727
2728
  functionName,
2728
- chainId: chainId2 ?? mainnet.id,
2729
+ chainId: chainId ?? 1,
2729
2730
  args,
2730
2731
  errorMessage: result.reason
2731
2732
  });
@@ -2741,7 +2742,7 @@ import shallow from "zustand/shallow";
2741
2742
  function watchContractEvent({
2742
2743
  address,
2743
2744
  abi,
2744
- chainId: chainId2,
2745
+ chainId,
2745
2746
  eventName,
2746
2747
  once
2747
2748
  }, callback) {
@@ -2750,7 +2751,7 @@ function watchContractEvent({
2750
2751
  const watchEvent = async () => {
2751
2752
  if (contract)
2752
2753
  contract?.off(eventName, handler);
2753
- const signerOrProvider = getWebSocketProvider({ chainId: chainId2 }) || getProvider({ chainId: chainId2 });
2754
+ const signerOrProvider = getWebSocketProvider({ chainId }) || getProvider({ chainId });
2754
2755
  contract = getContract({
2755
2756
  address,
2756
2757
  abi,
@@ -2782,9 +2783,9 @@ import shallow2 from "zustand/shallow";
2782
2783
 
2783
2784
  // src/actions/network-status/fetchBlockNumber.ts
2784
2785
  async function fetchBlockNumber({
2785
- chainId: chainId2
2786
+ chainId
2786
2787
  } = {}) {
2787
- const provider = getProvider({ chainId: chainId2 });
2788
+ const provider = getProvider({ chainId });
2788
2789
  const blockNumber = await provider.getBlockNumber();
2789
2790
  return blockNumber;
2790
2791
  }
@@ -2867,10 +2868,10 @@ function watchReadContracts(config, callback) {
2867
2868
 
2868
2869
  // src/actions/transactions/fetchTransaction.ts
2869
2870
  async function fetchTransaction({
2870
- chainId: chainId2,
2871
+ chainId,
2871
2872
  hash
2872
2873
  }) {
2873
- const provider = getProvider({ chainId: chainId2 });
2874
+ const provider = getProvider({ chainId });
2874
2875
  return provider.getTransaction(hash);
2875
2876
  }
2876
2877
 
@@ -2880,10 +2881,10 @@ import { isAddress as isAddress2 } from "ethers/lib/utils.js";
2880
2881
  // src/actions/ens/fetchEnsAddress.ts
2881
2882
  import { getAddress as getAddress2 } from "ethers/lib/utils.js";
2882
2883
  async function fetchEnsAddress({
2883
- chainId: chainId2,
2884
+ chainId,
2884
2885
  name
2885
2886
  }) {
2886
- const provider = getProvider({ chainId: chainId2 });
2887
+ const provider = getProvider({ chainId });
2887
2888
  const address = await provider.resolveName(name);
2888
2889
  try {
2889
2890
  return address ? getAddress2(address) : null;
@@ -2895,9 +2896,9 @@ async function fetchEnsAddress({
2895
2896
  // src/actions/ens/fetchEnsAvatar.ts
2896
2897
  async function fetchEnsAvatar({
2897
2898
  address,
2898
- chainId: chainId2
2899
+ chainId
2899
2900
  }) {
2900
- const provider = getProvider({ chainId: chainId2 });
2901
+ const provider = getProvider({ chainId });
2901
2902
  const avatar = await provider.getAvatar(address);
2902
2903
  return avatar;
2903
2904
  }
@@ -2906,33 +2907,33 @@ async function fetchEnsAvatar({
2906
2907
  import { getAddress as getAddress3 } from "ethers/lib/utils.js";
2907
2908
  async function fetchEnsName({
2908
2909
  address,
2909
- chainId: chainId2
2910
+ chainId
2910
2911
  }) {
2911
- const provider = getProvider({ chainId: chainId2 });
2912
+ const provider = getProvider({ chainId });
2912
2913
  return provider.lookupAddress(getAddress3(address));
2913
2914
  }
2914
2915
 
2915
2916
  // src/actions/ens/fetchEnsResolver.ts
2916
2917
  async function fetchEnsResolver({
2917
- chainId: chainId2,
2918
+ chainId,
2918
2919
  name
2919
2920
  }) {
2920
- const provider = getProvider({ chainId: chainId2 });
2921
+ const provider = getProvider({ chainId });
2921
2922
  const resolver = await provider.getResolver(name);
2922
2923
  return resolver;
2923
2924
  }
2924
2925
 
2925
2926
  // src/actions/transactions/prepareSendTransaction.ts
2926
2927
  async function prepareSendTransaction({
2927
- chainId: chainId2,
2928
+ chainId,
2928
2929
  request,
2929
2930
  signer: signer_
2930
2931
  }) {
2931
- const signer = signer_ ?? await fetchSigner({ chainId: chainId2 });
2932
+ const signer = signer_ ?? await fetchSigner({ chainId });
2932
2933
  if (!signer)
2933
2934
  throw new ConnectorNotFoundError();
2934
- if (chainId2)
2935
- assertActiveChain({ chainId: chainId2, signer });
2935
+ if (chainId)
2936
+ assertActiveChain({ chainId, signer });
2936
2937
  const [to, gasLimit] = await Promise.all([
2937
2938
  isAddress2(request.to) ? Promise.resolve(request.to) : fetchEnsAddress({ name: request.to }),
2938
2939
  request.gasLimit ? Promise.resolve(request.gasLimit) : signer.estimateGas(request)
@@ -2940,7 +2941,7 @@ async function prepareSendTransaction({
2940
2941
  if (!to)
2941
2942
  throw new Error("Could not resolve ENS name");
2942
2943
  return {
2943
- ...chainId2 ? { chainId: chainId2 } : {},
2944
+ ...chainId ? { chainId } : {},
2944
2945
  request: { ...request, gasLimit, to },
2945
2946
  mode: "prepared"
2946
2947
  };
@@ -2948,7 +2949,7 @@ async function prepareSendTransaction({
2948
2949
 
2949
2950
  // src/actions/transactions/sendTransaction.ts
2950
2951
  async function sendTransaction({
2951
- chainId: chainId2,
2952
+ chainId,
2952
2953
  mode,
2953
2954
  request
2954
2955
  }) {
@@ -2961,8 +2962,8 @@ async function sendTransaction({
2961
2962
  if (!request.to)
2962
2963
  throw new Error("`to` is required");
2963
2964
  }
2964
- if (chainId2)
2965
- assertActiveChain({ chainId: chainId2, signer });
2965
+ if (chainId)
2966
+ assertActiveChain({ chainId, signer });
2966
2967
  try {
2967
2968
  const uncheckedSigner = signer.connectUnchecked?.();
2968
2969
  const { hash, wait } = await (uncheckedSigner ?? signer).sendTransaction(
@@ -2976,30 +2977,80 @@ async function sendTransaction({
2976
2977
  }
2977
2978
  }
2978
2979
 
2980
+ // src/actions/transactions/waitForTransaction.ts
2981
+ import { toUtf8String } from "ethers/lib/utils.js";
2982
+
2983
+ // src/actions/network-status/fetchFeeData.ts
2984
+ import { formatUnits as formatUnits2 } from "ethers/lib/utils.js";
2985
+ async function fetchFeeData({
2986
+ chainId,
2987
+ formatUnits: units2 = "wei"
2988
+ } = {}) {
2989
+ const provider = getProvider({ chainId });
2990
+ const feeData = await provider.getFeeData();
2991
+ const formatted = {
2992
+ gasPrice: feeData.gasPrice ? formatUnits2(feeData.gasPrice, units2) : null,
2993
+ maxFeePerGas: feeData.maxFeePerGas ? formatUnits2(feeData.maxFeePerGas, units2) : null,
2994
+ maxPriorityFeePerGas: feeData.maxPriorityFeePerGas ? formatUnits2(feeData.maxPriorityFeePerGas, units2) : null
2995
+ };
2996
+ return { ...feeData, formatted };
2997
+ }
2998
+
2979
2999
  // src/actions/transactions/waitForTransaction.ts
2980
3000
  async function waitForTransaction({
2981
- chainId: chainId2,
2982
- confirmations,
3001
+ chainId,
3002
+ confirmations = 1,
2983
3003
  hash,
2984
- timeout,
2985
- wait: wait_
3004
+ onSpeedUp,
3005
+ timeout = 0
2986
3006
  }) {
2987
- let promise;
2988
- if (hash) {
2989
- const provider = getProvider({ chainId: chainId2 });
2990
- promise = provider.waitForTransaction(hash, confirmations, timeout);
2991
- } else if (wait_)
2992
- promise = wait_(confirmations);
2993
- else
2994
- throw new Error("hash or wait is required");
2995
- return promise;
3007
+ const provider = getProvider({ chainId });
3008
+ const [blockNumber, transaction] = await Promise.all([
3009
+ fetchBlockNumber(),
3010
+ fetchTransaction({ hash })
3011
+ ]);
3012
+ let replaceable = null;
3013
+ if (confirmations !== 0 && transaction?.to) {
3014
+ replaceable = {
3015
+ data: transaction.data,
3016
+ from: transaction.from,
3017
+ nonce: transaction.nonce,
3018
+ startBlock: blockNumber,
3019
+ to: transaction.to,
3020
+ value: transaction.value
3021
+ };
3022
+ }
3023
+ try {
3024
+ const receipt = await provider._waitForTransaction(
3025
+ hash,
3026
+ confirmations,
3027
+ timeout,
3028
+ replaceable
3029
+ );
3030
+ if (receipt.status === 0) {
3031
+ const code = await provider.call(receipt, receipt.blockNumber);
3032
+ const reason = toUtf8String(`0x${code.substring(138)}`);
3033
+ throw new Error(reason);
3034
+ }
3035
+ return receipt;
3036
+ } catch (err) {
3037
+ if (err?.reason === "repriced") {
3038
+ onSpeedUp?.(err.replacement);
3039
+ return waitForTransaction({
3040
+ hash: err.replacement?.hash,
3041
+ confirmations,
3042
+ timeout
3043
+ });
3044
+ }
3045
+ throw err;
3046
+ }
2996
3047
  }
2997
3048
 
2998
3049
  // src/actions/contracts/writeContract.ts
2999
3050
  async function writeContract({
3000
3051
  address,
3001
3052
  args,
3002
- chainId: chainId2,
3053
+ chainId,
3003
3054
  abi,
3004
3055
  functionName,
3005
3056
  mode,
@@ -3009,8 +3060,8 @@ async function writeContract({
3009
3060
  const signer = await fetchSigner();
3010
3061
  if (!signer)
3011
3062
  throw new ConnectorNotFoundError();
3012
- if (chainId2)
3013
- assertActiveChain({ chainId: chainId2, signer });
3063
+ if (chainId)
3064
+ assertActiveChain({ chainId, signer });
3014
3065
  if (mode === "prepared") {
3015
3066
  if (!request_)
3016
3067
  throw new Error("`request` is required");
@@ -3018,7 +3069,7 @@ async function writeContract({
3018
3069
  const request = mode === "recklesslyUnprepared" ? (await prepareWriteContract({
3019
3070
  address,
3020
3071
  args,
3021
- chainId: chainId2,
3072
+ chainId,
3022
3073
  abi,
3023
3074
  functionName,
3024
3075
  overrides
@@ -3033,15 +3084,15 @@ async function writeContract({
3033
3084
  // src/actions/accounts/fetchBalance.ts
3034
3085
  async function fetchBalance({
3035
3086
  address,
3036
- chainId: chainId2,
3087
+ chainId,
3037
3088
  formatUnits: unit,
3038
3089
  token
3039
3090
  }) {
3040
3091
  const client2 = getClient();
3041
- const provider = getProvider({ chainId: chainId2 });
3092
+ const provider = getProvider({ chainId });
3042
3093
  if (token) {
3043
3094
  const fetchContractBalance = async ({ abi }) => {
3044
- const erc20Config = { abi, address: token, chainId: chainId2 };
3095
+ const erc20Config = { abi, address: token, chainId };
3045
3096
  const [value2, decimals, symbol] = await readContracts({
3046
3097
  allowFailure: false,
3047
3098
  contracts: [
@@ -3056,7 +3107,7 @@ async function fetchBalance({
3056
3107
  });
3057
3108
  return {
3058
3109
  decimals,
3059
- formatted: formatUnits2(value2 ?? "0", unit ?? decimals),
3110
+ formatted: formatUnits3(value2 ?? "0", unit ?? decimals),
3060
3111
  symbol,
3061
3112
  value: value2
3062
3113
  };
@@ -3078,21 +3129,21 @@ async function fetchBalance({
3078
3129
  }
3079
3130
  const chains = [...client2.provider.chains || [], ...client2.chains ?? []];
3080
3131
  const value = await provider.getBalance(address);
3081
- const chain2 = chains.find((x) => x.id === provider.network.chainId);
3132
+ const chain = chains.find((x) => x.id === provider.network.chainId);
3082
3133
  return {
3083
- decimals: chain2?.nativeCurrency?.decimals ?? 18,
3084
- formatted: formatUnits2(value ?? "0", unit ?? "ether"),
3085
- symbol: chain2?.nativeCurrency?.symbol ?? "ETH",
3134
+ decimals: chain?.nativeCurrency.decimals ?? 18,
3135
+ formatted: formatUnits3(value ?? "0", unit ?? "ether"),
3136
+ symbol: chain?.nativeCurrency.symbol ?? "ETH",
3086
3137
  value
3087
3138
  };
3088
3139
  }
3089
3140
 
3090
3141
  // src/actions/accounts/fetchSigner.ts
3091
3142
  async function fetchSigner({
3092
- chainId: chainId2
3143
+ chainId
3093
3144
  } = {}) {
3094
3145
  const client2 = getClient();
3095
- const signer = await client2.connector?.getSigner?.({ chainId: chainId2 }) || null;
3146
+ const signer = await client2.connector?.getSigner?.({ chainId }) || null;
3096
3147
  return signer;
3097
3148
  }
3098
3149
 
@@ -3146,21 +3197,24 @@ function getAccount() {
3146
3197
  // src/actions/accounts/getNetwork.ts
3147
3198
  function getNetwork() {
3148
3199
  const client2 = getClient();
3149
- const chainId2 = client2.data?.chain?.id;
3200
+ const chainId = client2.data?.chain?.id;
3150
3201
  const activeChains = client2.chains ?? [];
3151
3202
  const activeChain = [...client2.provider.chains || [], ...activeChains].find(
3152
- (x) => x.id === chainId2
3203
+ (x) => x.id === chainId
3153
3204
  ) ?? {
3154
- id: chainId2,
3155
- name: `Chain ${chainId2}`,
3156
- network: `${chainId2}`,
3157
- rpcUrls: { default: "" }
3205
+ id: chainId,
3206
+ name: `Chain ${chainId}`,
3207
+ network: `${chainId}`,
3208
+ nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
3209
+ rpcUrls: {
3210
+ default: { http: [""] }
3211
+ }
3158
3212
  };
3159
3213
  return {
3160
- chain: chainId2 ? {
3214
+ chain: chainId ? {
3161
3215
  ...activeChain,
3162
3216
  ...client2.data?.chain,
3163
- id: chainId2
3217
+ id: chainId
3164
3218
  } : void 0,
3165
3219
  chains: activeChains
3166
3220
  };
@@ -3192,9 +3246,9 @@ async function signTypedData({
3192
3246
  if (!signer)
3193
3247
  throw new ConnectorNotFoundError();
3194
3248
  const { chainId: chainId_ } = domain;
3195
- const chainId2 = chainId_ ? normalizeChainId(chainId_) : void 0;
3196
- if (chainId2)
3197
- assertActiveChain({ chainId: chainId2, signer });
3249
+ const chainId = chainId_ ? normalizeChainId(chainId_) : void 0;
3250
+ if (chainId)
3251
+ assertActiveChain({ chainId, signer });
3198
3252
  return signer._signTypedData(
3199
3253
  domain,
3200
3254
  types,
@@ -3204,7 +3258,7 @@ async function signTypedData({
3204
3258
 
3205
3259
  // src/actions/accounts/switchNetwork.ts
3206
3260
  async function switchNetwork({
3207
- chainId: chainId2
3261
+ chainId
3208
3262
  }) {
3209
3263
  const { connector } = getClient();
3210
3264
  if (!connector)
@@ -3213,7 +3267,7 @@ async function switchNetwork({
3213
3267
  throw new SwitchChainNotSupportedError({
3214
3268
  connector
3215
3269
  });
3216
- return connector.switchChain(chainId2);
3270
+ return connector.switchChain(chainId);
3217
3271
  }
3218
3272
 
3219
3273
  // src/actions/accounts/watchAccount.ts
@@ -3252,9 +3306,9 @@ function watchNetwork(callback, { selector = (x) => x } = {}) {
3252
3306
 
3253
3307
  // src/actions/accounts/watchSigner.ts
3254
3308
  import shallow5 from "zustand/shallow";
3255
- function watchSigner({ chainId: chainId2 }, callback) {
3309
+ function watchSigner({ chainId }, callback) {
3256
3310
  const client2 = getClient();
3257
- const handleChange = async () => callback(await fetchSigner({ chainId: chainId2 }));
3311
+ const handleChange = async () => callback(await fetchSigner({ chainId }));
3258
3312
  const unsubscribe = client2.subscribe(
3259
3313
  ({ data, connector }) => ({
3260
3314
  account: data?.account,
@@ -3269,42 +3323,28 @@ function watchSigner({ chainId: chainId2 }, callback) {
3269
3323
  return unsubscribe;
3270
3324
  }
3271
3325
 
3272
- // src/actions/network-status/fetchFeeData.ts
3273
- import { formatUnits as formatUnits3 } from "ethers/lib/utils.js";
3274
- async function fetchFeeData({
3275
- chainId: chainId2,
3276
- formatUnits: units2 = "wei"
3277
- } = {}) {
3278
- const provider = getProvider({ chainId: chainId2 });
3279
- const feeData = await provider.getFeeData();
3280
- const formatted = {
3281
- gasPrice: feeData.gasPrice ? formatUnits3(feeData.gasPrice, units2) : null,
3282
- maxFeePerGas: feeData.maxFeePerGas ? formatUnits3(feeData.maxFeePerGas, units2) : null,
3283
- maxPriorityFeePerGas: feeData.maxPriorityFeePerGas ? formatUnits3(feeData.maxPriorityFeePerGas, units2) : null
3284
- };
3285
- return { ...feeData, formatted };
3286
- }
3287
-
3288
3326
  // src/errors.ts
3289
3327
  var RpcError = class extends Error {
3290
- constructor(code, message, internal, data) {
3328
+ constructor(message, options) {
3329
+ const { cause, code, data } = options;
3291
3330
  if (!Number.isInteger(code))
3292
3331
  throw new Error('"code" must be an integer.');
3293
3332
  if (!message || typeof message !== "string")
3294
3333
  throw new Error('"message" must be a nonempty string.');
3295
3334
  super(message);
3335
+ this.cause = cause;
3296
3336
  this.code = code;
3297
3337
  this.data = data;
3298
- this.internal = internal;
3299
3338
  }
3300
3339
  };
3301
3340
  var ProviderRpcError = class extends RpcError {
3302
- constructor(code, message, internal, data) {
3341
+ constructor(message, options) {
3342
+ const { cause, code, data } = options;
3303
3343
  if (!(Number.isInteger(code) && code >= 1e3 && code <= 4999))
3304
3344
  throw new Error(
3305
3345
  '"code" must be an integer such that: 1000 <= code <= 4999'
3306
3346
  );
3307
- super(code, message, internal, data);
3347
+ super(message, { cause, code, data });
3308
3348
  }
3309
3349
  };
3310
3350
  var AddChainError = class extends Error {
@@ -3315,9 +3355,9 @@ var AddChainError = class extends Error {
3315
3355
  }
3316
3356
  };
3317
3357
  var ChainDoesNotSupportMulticallError = class extends Error {
3318
- constructor({ blockNumber, chain: chain2 }) {
3358
+ constructor({ blockNumber, chain }) {
3319
3359
  super(
3320
- `Chain "${chain2.name}" does not support multicall${blockNumber ? ` on block ${blockNumber}` : ""}.`
3360
+ `Chain "${chain.name}" does not support multicall${blockNumber ? ` on block ${blockNumber}` : ""}.`
3321
3361
  );
3322
3362
  this.name = "ChainDoesNotSupportMulticall";
3323
3363
  }
@@ -3335,10 +3375,10 @@ var ChainMismatchError = class extends Error {
3335
3375
  };
3336
3376
  var ChainNotConfiguredError = class extends Error {
3337
3377
  constructor({
3338
- chainId: chainId2,
3378
+ chainId,
3339
3379
  connectorId
3340
3380
  }) {
3341
- super(`Chain "${chainId2}" not configured for connector "${connectorId}".`);
3381
+ super(`Chain "${chainId}" not configured for connector "${connectorId}".`);
3342
3382
  this.name = "ChainNotConfigured";
3343
3383
  }
3344
3384
  };
@@ -3359,12 +3399,12 @@ var ConnectorNotFoundError = class extends Error {
3359
3399
  var ContractMethodDoesNotExistError = class extends Error {
3360
3400
  constructor({
3361
3401
  address,
3362
- chainId: chainId2,
3402
+ chainId,
3363
3403
  functionName
3364
3404
  }) {
3365
3405
  const { chains, network } = getProvider();
3366
- const chain2 = chains?.find(({ id }) => id === (chainId2 || network.chainId));
3367
- const blockExplorer = chain2?.blockExplorers?.default;
3406
+ const chain = chains?.find(({ id }) => id === (chainId || network.chainId));
3407
+ const blockExplorer = chain?.blockExplorers?.default;
3368
3408
  super(
3369
3409
  [
3370
3410
  `Function "${functionName}" on contract "${address}" does not exist.`,
@@ -3381,7 +3421,7 @@ var ContractMethodNoResultError = class extends Error {
3381
3421
  constructor({
3382
3422
  address,
3383
3423
  args,
3384
- chainId: chainId2,
3424
+ chainId,
3385
3425
  functionName
3386
3426
  }) {
3387
3427
  super(
@@ -3397,7 +3437,7 @@ var ContractMethodNoResultError = class extends Error {
3397
3437
  address,
3398
3438
  abi: "...",
3399
3439
  functionName,
3400
- chainId: chainId2,
3440
+ chainId,
3401
3441
  args
3402
3442
  },
3403
3443
  null,
@@ -3412,7 +3452,7 @@ var ContractMethodRevertedError = class extends Error {
3412
3452
  constructor({
3413
3453
  address,
3414
3454
  args,
3415
- chainId: chainId2,
3455
+ chainId,
3416
3456
  functionName,
3417
3457
  errorMessage
3418
3458
  }) {
@@ -3426,7 +3466,7 @@ var ContractMethodRevertedError = class extends Error {
3426
3466
  address,
3427
3467
  abi: "...",
3428
3468
  functionName,
3429
- chainId: chainId2,
3469
+ chainId,
3430
3470
  args
3431
3471
  },
3432
3472
  null,
@@ -3443,7 +3483,7 @@ var ContractResultDecodeError = class extends Error {
3443
3483
  constructor({
3444
3484
  address,
3445
3485
  args,
3446
- chainId: chainId2,
3486
+ chainId,
3447
3487
  functionName,
3448
3488
  errorMessage
3449
3489
  }) {
@@ -3457,7 +3497,7 @@ var ContractResultDecodeError = class extends Error {
3457
3497
  address,
3458
3498
  abi: "...",
3459
3499
  functionName,
3460
- chainId: chainId2,
3500
+ chainId,
3461
3501
  args
3462
3502
  },
3463
3503
  null,
@@ -3493,14 +3533,14 @@ var ProviderChainsNotFound = class extends Error {
3493
3533
  }
3494
3534
  };
3495
3535
  var ResourceUnavailableError = class extends RpcError {
3496
- constructor(error) {
3497
- super(-32002, "Resource unavailable", error);
3536
+ constructor(cause) {
3537
+ super("Resource unavailable", { cause, code: -32002 });
3498
3538
  this.name = "ResourceUnavailable";
3499
3539
  }
3500
3540
  };
3501
3541
  var SwitchChainError = class extends ProviderRpcError {
3502
- constructor(error) {
3503
- super(4902, "Error switching chain", error);
3542
+ constructor(cause) {
3543
+ super("Error switching chain", { cause, code: 4902 });
3504
3544
  this.name = "SwitchChainError";
3505
3545
  }
3506
3546
  };
@@ -3511,8 +3551,8 @@ var SwitchChainNotSupportedError = class extends Error {
3511
3551
  }
3512
3552
  };
3513
3553
  var UserRejectedRequestError = class extends ProviderRpcError {
3514
- constructor(error) {
3515
- super(4001, "User rejected request", error);
3554
+ constructor(cause) {
3555
+ super("User rejected request", { cause, code: 4001 });
3516
3556
  this.name = "UserRejectedRequestError";
3517
3557
  }
3518
3558
  };
@@ -3543,10 +3583,6 @@ export {
3543
3583
  normalizeChainId,
3544
3584
  parseContractResult,
3545
3585
  serialize,
3546
- erc20ABI,
3547
- erc721ABI,
3548
- erc4626ABI,
3549
- units,
3550
3586
  Connector,
3551
3587
  InjectedConnector,
3552
3588
  noopStorage,
@@ -3556,6 +3592,10 @@ export {
3556
3592
  getClient,
3557
3593
  connect,
3558
3594
  disconnect,
3595
+ erc20ABI,
3596
+ erc721ABI,
3597
+ erc4626ABI,
3598
+ units,
3559
3599
  fetchToken,
3560
3600
  getContract,
3561
3601
  prepareWriteContract,
@@ -3579,6 +3619,7 @@ export {
3579
3619
  fetchEnsResolver,
3580
3620
  prepareSendTransaction,
3581
3621
  sendTransaction,
3622
+ fetchFeeData,
3582
3623
  waitForTransaction,
3583
3624
  writeContract,
3584
3625
  fetchBalance,
@@ -3590,6 +3631,5 @@ export {
3590
3631
  switchNetwork,
3591
3632
  watchAccount,
3592
3633
  watchNetwork,
3593
- watchSigner,
3594
- fetchFeeData
3634
+ watchSigner
3595
3635
  };