@wagmi/core 0.6.12 → 0.7.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 (184) hide show
  1. package/chains/package.json +2 -2
  2. package/connectors/coinbaseWallet/package.json +2 -2
  3. package/connectors/metaMask/package.json +2 -2
  4. package/connectors/mock/package.json +2 -2
  5. package/connectors/walletConnect/package.json +2 -2
  6. package/dist/{declarations/src/connectors/base.d.ts → base-5bd9b5ed.d.ts} +8 -5
  7. package/dist/chains.d.ts +3 -0
  8. package/dist/chains.js +29 -0
  9. package/dist/chunk-2EDVJWOA.js +3496 -0
  10. package/dist/chunk-4DNFSL2K.js +376 -0
  11. package/dist/chunk-MQXBDTVK.js +29 -0
  12. package/dist/{declarations/src/connectors → connectors}/coinbaseWallet.d.ts +10 -6
  13. package/dist/connectors/coinbaseWallet.js +215 -0
  14. package/dist/{declarations/src/connectors → connectors}/metaMask.d.ts +11 -4
  15. package/dist/connectors/metaMask.js +115 -0
  16. package/dist/connectors/mock/index.d.ts +78 -0
  17. package/dist/connectors/mock/index.js +190 -0
  18. package/dist/{declarations/src/connectors → connectors}/walletConnect.d.ts +9 -5
  19. package/dist/connectors/walletConnect.js +160 -0
  20. package/dist/{declarations/src/types/contracts.d.ts → contracts-fb6a6ff0.d.ts} +122 -17
  21. package/dist/{declarations/src/types/index.d.ts → index-bacc1c49.d.ts} +83 -15
  22. package/dist/index.d.ts +1738 -0
  23. package/dist/index.js +165 -0
  24. package/dist/{declarations/src/connectors/injected.d.ts → injected-6980e5c3.d.ts} +9 -6
  25. package/dist/internal.d.ts +8 -0
  26. package/dist/internal.js +8 -0
  27. package/dist/providers/alchemy.d.ts +11 -0
  28. package/dist/providers/alchemy.js +32 -0
  29. package/dist/providers/infura.d.ts +11 -0
  30. package/dist/providers/infura.js +32 -0
  31. package/dist/providers/jsonRpc.d.ts +14 -0
  32. package/dist/providers/jsonRpc.js +44 -0
  33. package/dist/providers/public.d.ts +8 -0
  34. package/dist/providers/public.js +30 -0
  35. package/internal/package.json +2 -2
  36. package/package.json +40 -51
  37. package/providers/alchemy/package.json +2 -2
  38. package/providers/infura/package.json +2 -2
  39. package/providers/jsonRpc/package.json +2 -2
  40. package/providers/public/package.json +2 -2
  41. package/chains/dist/wagmi-core-chains.cjs.d.ts +0 -1
  42. package/chains/dist/wagmi-core-chains.cjs.dev.js +0 -26
  43. package/chains/dist/wagmi-core-chains.cjs.js +0 -7
  44. package/chains/dist/wagmi-core-chains.cjs.prod.js +0 -26
  45. package/chains/dist/wagmi-core-chains.esm.js +0 -2
  46. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.d.ts +0 -1
  47. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +0 -274
  48. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.js +0 -7
  49. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +0 -274
  50. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +0 -252
  51. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.d.ts +0 -1
  52. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.dev.js +0 -153
  53. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.js +0 -7
  54. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.prod.js +0 -153
  55. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.esm.js +0 -149
  56. package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.d.ts +0 -1
  57. package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.dev.js +0 -262
  58. package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.js +0 -7
  59. package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.prod.js +0 -262
  60. package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +0 -253
  61. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.d.ts +0 -1
  62. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.dev.js +0 -228
  63. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.js +0 -7
  64. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.prod.js +0 -228
  65. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +0 -206
  66. package/dist/chains-73cc6c23.cjs.prod.js +0 -526
  67. package/dist/chains-8fce19d8.esm.js +0 -502
  68. package/dist/chains-fe1f4131.cjs.dev.js +0 -526
  69. package/dist/debounce-0862bf88.esm.js +0 -18
  70. package/dist/debounce-2d836dc9.cjs.prod.js +0 -20
  71. package/dist/debounce-46ac0312.cjs.dev.js +0 -20
  72. package/dist/declarations/src/actions/accounts/connect.d.ts +0 -18
  73. package/dist/declarations/src/actions/accounts/disconnect.d.ts +0 -1
  74. package/dist/declarations/src/actions/accounts/fetchBalance.d.ts +0 -19
  75. package/dist/declarations/src/actions/accounts/fetchSigner.d.ts +0 -7
  76. package/dist/declarations/src/actions/accounts/getAccount.d.ts +0 -36
  77. package/dist/declarations/src/actions/accounts/getNetwork.d.ts +0 -8
  78. package/dist/declarations/src/actions/accounts/index.d.ts +0 -12
  79. package/dist/declarations/src/actions/accounts/signMessage.d.ts +0 -7
  80. package/dist/declarations/src/actions/accounts/signTypedData.d.ts +0 -23
  81. package/dist/declarations/src/actions/accounts/switchNetwork.d.ts +0 -6
  82. package/dist/declarations/src/actions/accounts/watchAccount.d.ts +0 -12
  83. package/dist/declarations/src/actions/accounts/watchNetwork.d.ts +0 -10
  84. package/dist/declarations/src/actions/accounts/watchSigner.d.ts +0 -5
  85. package/dist/declarations/src/actions/contracts/fetchToken.d.ts +0 -21
  86. package/dist/declarations/src/actions/contracts/getContract.d.ts +0 -113
  87. package/dist/declarations/src/actions/contracts/index.d.ts +0 -11
  88. package/dist/declarations/src/actions/contracts/multicall.d.ts +0 -17
  89. package/dist/declarations/src/actions/contracts/prepareWriteContract.d.ts +0 -47
  90. package/dist/declarations/src/actions/contracts/readContract.d.ts +0 -15
  91. package/dist/declarations/src/actions/contracts/readContracts.d.ts +0 -28
  92. package/dist/declarations/src/actions/contracts/watchContractEvent.d.ts +0 -28
  93. package/dist/declarations/src/actions/contracts/watchMulticall.d.ts +0 -10
  94. package/dist/declarations/src/actions/contracts/watchReadContract.d.ts +0 -7
  95. package/dist/declarations/src/actions/contracts/watchReadContracts.d.ts +0 -10
  96. package/dist/declarations/src/actions/contracts/writeContract.d.ts +0 -72
  97. package/dist/declarations/src/actions/ens/fetchEnsAddress.d.ts +0 -9
  98. package/dist/declarations/src/actions/ens/fetchEnsAvatar.d.ts +0 -8
  99. package/dist/declarations/src/actions/ens/fetchEnsName.d.ts +0 -9
  100. package/dist/declarations/src/actions/ens/fetchEnsResolver.d.ts +0 -9
  101. package/dist/declarations/src/actions/ens/index.d.ts +0 -4
  102. package/dist/declarations/src/actions/index.d.ts +0 -6
  103. package/dist/declarations/src/actions/network-status/fetchBlockNumber.d.ts +0 -5
  104. package/dist/declarations/src/actions/network-status/fetchFeeData.d.ts +0 -16
  105. package/dist/declarations/src/actions/network-status/index.d.ts +0 -3
  106. package/dist/declarations/src/actions/network-status/watchBlockNumber.d.ts +0 -7
  107. package/dist/declarations/src/actions/providers/getProvider.d.ts +0 -7
  108. package/dist/declarations/src/actions/providers/getWebSocketProvider.d.ts +0 -7
  109. package/dist/declarations/src/actions/providers/index.d.ts +0 -4
  110. package/dist/declarations/src/actions/providers/watchProvider.d.ts +0 -4
  111. package/dist/declarations/src/actions/providers/watchWebSocketProvider.d.ts +0 -4
  112. package/dist/declarations/src/actions/transactions/fetchTransaction.d.ts +0 -21
  113. package/dist/declarations/src/actions/transactions/index.d.ts +0 -4
  114. package/dist/declarations/src/actions/transactions/prepareSendTransaction.d.ts +0 -37
  115. package/dist/declarations/src/actions/transactions/sendTransaction.d.ts +0 -48
  116. package/dist/declarations/src/actions/transactions/waitForTransaction.d.ts +0 -18
  117. package/dist/declarations/src/chains.d.ts +0 -1
  118. package/dist/declarations/src/client.d.ts +0 -91
  119. package/dist/declarations/src/connectors/index.d.ts +0 -2
  120. package/dist/declarations/src/connectors/mock/connector.d.ts +0 -34
  121. package/dist/declarations/src/connectors/mock/index.d.ts +0 -2
  122. package/dist/declarations/src/connectors/mock/provider.d.ts +0 -41
  123. package/dist/declarations/src/constants/abis.d.ts +0 -941
  124. package/dist/declarations/src/constants/blockExplorers.d.ts +0 -9
  125. package/dist/declarations/src/constants/chains.d.ts +0 -64
  126. package/dist/declarations/src/constants/index.d.ts +0 -7
  127. package/dist/declarations/src/constants/rpcs.d.ts +0 -11
  128. package/dist/declarations/src/constants/units.d.ts +0 -1
  129. package/dist/declarations/src/errors.d.ts +0 -134
  130. package/dist/declarations/src/index.d.ts +0 -14
  131. package/dist/declarations/src/internal.d.ts +0 -3
  132. package/dist/declarations/src/providers/alchemy.d.ts +0 -6
  133. package/dist/declarations/src/providers/infura.d.ts +0 -6
  134. package/dist/declarations/src/providers/jsonRpc.d.ts +0 -10
  135. package/dist/declarations/src/providers/public.d.ts +0 -4
  136. package/dist/declarations/src/storage.d.ts +0 -12
  137. package/dist/declarations/src/types/utils.d.ts +0 -103
  138. package/dist/declarations/src/utils/assertActiveChain.d.ts +0 -5
  139. package/dist/declarations/src/utils/configureChains.d.ts +0 -26
  140. package/dist/declarations/src/utils/debounce.d.ts +0 -1
  141. package/dist/declarations/src/utils/deepEqual.d.ts +0 -2
  142. package/dist/declarations/src/utils/getInjectedName.d.ts +0 -2
  143. package/dist/declarations/src/utils/index.d.ts +0 -11
  144. package/dist/declarations/src/utils/logger.d.ts +0 -1
  145. package/dist/declarations/src/utils/minimizeContractInterface.d.ts +0 -5
  146. package/dist/declarations/src/utils/normalizeChainId.d.ts +0 -1
  147. package/dist/declarations/src/utils/normalizeFunctionName.d.ts +0 -17
  148. package/dist/declarations/src/utils/parseContractResult.d.ts +0 -7
  149. package/dist/getProvider-3b1af4e6.cjs.dev.js +0 -1143
  150. package/dist/getProvider-84f303a1.cjs.prod.js +0 -1143
  151. package/dist/getProvider-97db849e.esm.js +0 -1105
  152. package/dist/rpcs-38f4faba.cjs.prod.js +0 -57
  153. package/dist/rpcs-52ea3d8d.cjs.dev.js +0 -57
  154. package/dist/rpcs-d533516e.esm.js +0 -51
  155. package/dist/wagmi-core.cjs.d.ts +0 -1
  156. package/dist/wagmi-core.cjs.dev.js +0 -2683
  157. package/dist/wagmi-core.cjs.js +0 -7
  158. package/dist/wagmi-core.cjs.prod.js +0 -2683
  159. package/dist/wagmi-core.esm.js +0 -2599
  160. package/internal/dist/wagmi-core-internal.cjs.d.ts +0 -1
  161. package/internal/dist/wagmi-core-internal.cjs.dev.js +0 -9
  162. package/internal/dist/wagmi-core-internal.cjs.js +0 -7
  163. package/internal/dist/wagmi-core-internal.cjs.prod.js +0 -9
  164. package/internal/dist/wagmi-core-internal.esm.js +0 -1
  165. package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.d.ts +0 -1
  166. package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.dev.js +0 -36
  167. package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.js +0 -7
  168. package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.prod.js +0 -36
  169. package/providers/alchemy/dist/wagmi-core-providers-alchemy.esm.js +0 -32
  170. package/providers/infura/dist/wagmi-core-providers-infura.cjs.d.ts +0 -1
  171. package/providers/infura/dist/wagmi-core-providers-infura.cjs.dev.js +0 -36
  172. package/providers/infura/dist/wagmi-core-providers-infura.cjs.js +0 -7
  173. package/providers/infura/dist/wagmi-core-providers-infura.cjs.prod.js +0 -36
  174. package/providers/infura/dist/wagmi-core-providers-infura.esm.js +0 -32
  175. package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.d.ts +0 -1
  176. package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.dev.js +0 -46
  177. package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.js +0 -7
  178. package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.prod.js +0 -46
  179. package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.esm.js +0 -42
  180. package/providers/public/dist/wagmi-core-providers-public.cjs.d.ts +0 -1
  181. package/providers/public/dist/wagmi-core-providers-public.cjs.dev.js +0 -32
  182. package/providers/public/dist/wagmi-core-providers-public.cjs.js +0 -7
  183. package/providers/public/dist/wagmi-core-providers-public.cjs.prod.js +0 -32
  184. package/providers/public/dist/wagmi-core-providers-public.esm.js +0 -28
@@ -0,0 +1,3496 @@
1
+ import {
2
+ defaultChains,
3
+ mainnet
4
+ } from "./chunk-4DNFSL2K.js";
5
+ import {
6
+ __privateAdd,
7
+ __privateGet,
8
+ __privateMethod,
9
+ __privateSet
10
+ } from "./chunk-MQXBDTVK.js";
11
+
12
+ // src/client.ts
13
+ import { persist, subscribeWithSelector } from "zustand/middleware";
14
+ import { default as create } from "zustand/vanilla";
15
+
16
+ // src/connectors/injected.ts
17
+ import { providers as providers2 } from "ethers";
18
+ import { getAddress, hexValue } from "ethers/lib/utils.js";
19
+
20
+ // src/utils/configureChains.ts
21
+ import { providers } from "ethers";
22
+ function configureChains(defaultChains2, providers4, {
23
+ minQuorum = 1,
24
+ pollingInterval = 4e3,
25
+ targetQuorum = 1,
26
+ stallTimeout
27
+ } = {}) {
28
+ if (!defaultChains2.length)
29
+ throw new Error("must have at least one chain");
30
+ if (targetQuorum < minQuorum)
31
+ throw new Error("quorum cannot be lower than minQuorum");
32
+ let chains = [];
33
+ const providers_ = {};
34
+ const webSocketProviders_ = {};
35
+ for (const chain2 of defaultChains2) {
36
+ let configExists = false;
37
+ for (const provider of providers4) {
38
+ const apiConfig = provider(chain2);
39
+ if (!apiConfig)
40
+ continue;
41
+ configExists = true;
42
+ if (!chains.some(({ id }) => id === chain2.id)) {
43
+ chains = [...chains, apiConfig.chain];
44
+ }
45
+ providers_[chain2.id] = [
46
+ ...providers_[chain2.id] || [],
47
+ apiConfig.provider
48
+ ];
49
+ if (apiConfig.webSocketProvider) {
50
+ webSocketProviders_[chain2.id] = [
51
+ ...webSocketProviders_[chain2.id] || [],
52
+ apiConfig.webSocketProvider
53
+ ];
54
+ }
55
+ }
56
+ if (!configExists) {
57
+ throw new Error(
58
+ [
59
+ `Could not find valid provider configuration for chain "${chain2.name}".
60
+ `,
61
+ "You may need to add `jsonRpcProvider` to `configureChains` with the chain's RPC URLs.",
62
+ "Read more: https://wagmi.sh/docs/providers/jsonRpc"
63
+ ].join("\n")
64
+ );
65
+ }
66
+ }
67
+ return {
68
+ chains,
69
+ provider: ({ chainId: chainId2 }) => {
70
+ const activeChain = chains.find((x) => x.id === chainId2) ?? defaultChains2[0];
71
+ const chainProviders = providers_[activeChain.id];
72
+ if (!chainProviders || !chainProviders[0])
73
+ throw new Error(`No providers configured for chain "${activeChain.id}"`);
74
+ let provider;
75
+ if (chainProviders.length === 1) {
76
+ provider = chainProviders[0]();
77
+ } else {
78
+ provider = fallbackProvider(targetQuorum, minQuorum, chainProviders, {
79
+ stallTimeout
80
+ });
81
+ }
82
+ if (activeChain.id === 42220) {
83
+ provider.formatter.formats.block = {
84
+ ...provider.formatter.formats.block,
85
+ difficulty: () => 0,
86
+ gasLimit: () => 0
87
+ };
88
+ }
89
+ return Object.assign(provider, {
90
+ chains,
91
+ pollingInterval
92
+ });
93
+ },
94
+ webSocketProvider: ({ chainId: chainId2 }) => {
95
+ const activeChain = chains.find((x) => x.id === chainId2) ?? defaultChains2[0];
96
+ const chainWebSocketProviders = webSocketProviders_[activeChain.id];
97
+ if (!chainWebSocketProviders)
98
+ return void 0;
99
+ const provider = chainWebSocketProviders[0]?.();
100
+ if (provider && activeChain.id === 42220) {
101
+ provider.formatter.formats.block = {
102
+ ...provider.formatter.formats.block,
103
+ difficulty: () => 0,
104
+ gasLimit: () => 0
105
+ };
106
+ }
107
+ return Object.assign(provider || {}, {
108
+ chains
109
+ });
110
+ }
111
+ };
112
+ }
113
+ function fallbackProvider(targetQuorum, minQuorum, providers_, { stallTimeout }) {
114
+ try {
115
+ return new providers.FallbackProvider(
116
+ providers_.map((chainProvider, index) => {
117
+ const provider = chainProvider();
118
+ return {
119
+ provider,
120
+ priority: provider.priority ?? index,
121
+ stallTimeout: provider.stallTimeout ?? stallTimeout,
122
+ weight: provider.weight
123
+ };
124
+ }),
125
+ targetQuorum
126
+ );
127
+ } catch (error) {
128
+ if (error?.message?.includes(
129
+ "quorum will always fail; larger than total weight"
130
+ )) {
131
+ if (targetQuorum === minQuorum)
132
+ throw error;
133
+ return fallbackProvider(targetQuorum - 1, minQuorum, providers_, {
134
+ stallTimeout
135
+ });
136
+ }
137
+ throw error;
138
+ }
139
+ }
140
+
141
+ // src/utils/assertActiveChain.ts
142
+ function assertActiveChain({
143
+ chainId: chainId2,
144
+ signer
145
+ }) {
146
+ const { chain: activeChain, chains } = getNetwork();
147
+ const activeChainId = activeChain?.id;
148
+ if (activeChainId && chainId2 !== activeChainId) {
149
+ throw new ChainMismatchError({
150
+ activeChain: chains.find((x) => x.id === activeChainId)?.name ?? `Chain ${activeChainId}`,
151
+ targetChain: chains.find((x) => x.id === chainId2)?.name ?? `Chain ${chainId2}`
152
+ });
153
+ }
154
+ if (signer) {
155
+ const signerChainId = signer.provider?.network?.chainId;
156
+ if (signerChainId && chainId2 !== signerChainId) {
157
+ const connector = getClient().connector;
158
+ throw new ChainNotConfiguredError({
159
+ chainId: chainId2,
160
+ connectorId: connector?.id ?? "unknown"
161
+ });
162
+ }
163
+ }
164
+ }
165
+
166
+ // src/utils/debounce.ts
167
+ function debounce(fn, waitTime = 0) {
168
+ let timeout;
169
+ return function(...args) {
170
+ if (!waitTime)
171
+ return fn(...args);
172
+ if (timeout)
173
+ clearTimeout(timeout);
174
+ timeout = setTimeout(function() {
175
+ timeout = null;
176
+ fn(...args);
177
+ }, waitTime);
178
+ };
179
+ }
180
+
181
+ // src/utils/deepEqual.ts
182
+ function deepEqual(a, b) {
183
+ if (a === b)
184
+ return true;
185
+ if (a && b && typeof a === "object" && typeof b === "object") {
186
+ if (a.constructor !== b.constructor)
187
+ return false;
188
+ let length;
189
+ let i;
190
+ if (Array.isArray(a) && Array.isArray(b)) {
191
+ length = a.length;
192
+ if (length != b.length)
193
+ return false;
194
+ for (i = length; i-- !== 0; )
195
+ if (!deepEqual(a[i], b[i]))
196
+ return false;
197
+ return true;
198
+ }
199
+ if (a.valueOf !== Object.prototype.valueOf)
200
+ return a.valueOf() === b.valueOf();
201
+ if (a.toString !== Object.prototype.toString)
202
+ return a.toString() === b.toString();
203
+ const keys = Object.keys(a);
204
+ length = keys.length;
205
+ if (length !== Object.keys(b).length)
206
+ return false;
207
+ for (i = length; i-- !== 0; )
208
+ if (!Object.prototype.hasOwnProperty.call(b, keys[i]))
209
+ return false;
210
+ for (i = length; i-- !== 0; ) {
211
+ const key = keys[i];
212
+ if (key && !deepEqual(a[key], b[key]))
213
+ return false;
214
+ }
215
+ return true;
216
+ }
217
+ return a !== a && b !== b;
218
+ }
219
+
220
+ // src/utils/normalizeFunctionName.ts
221
+ import { BigNumber } from "ethers";
222
+ import { FunctionFragment, isAddress } from "ethers/lib/utils.js";
223
+ function normalizeFunctionName({
224
+ contract,
225
+ functionName,
226
+ args = []
227
+ }) {
228
+ if (functionName in contract.functions)
229
+ return functionName;
230
+ const argsLength = args?.length ?? 0;
231
+ const overloadFunctions = Object.keys(contract.functions).filter((x) => x.startsWith(`${functionName}(`)).map((x) => ({ name: x, fragment: FunctionFragment.fromString(x) })).filter((x) => argsLength === x.fragment.inputs.length);
232
+ for (const overloadFunction of overloadFunctions) {
233
+ const matched = args.every((arg, index) => {
234
+ const abiParameter = overloadFunction.fragment.inputs[index];
235
+ return isArgOfType(arg, abiParameter);
236
+ });
237
+ if (matched)
238
+ return overloadFunction.name;
239
+ }
240
+ return functionName;
241
+ }
242
+ function isArgOfType(arg, abiParameter) {
243
+ const argType = typeof arg;
244
+ const abiParameterType = abiParameter.type;
245
+ switch (abiParameterType) {
246
+ case "address":
247
+ return isAddress(arg);
248
+ case "bool":
249
+ return argType === "boolean";
250
+ case "function":
251
+ return argType === "string";
252
+ case "string":
253
+ return argType === "string";
254
+ default: {
255
+ if (abiParameterType === "tuple" && "components" in abiParameter)
256
+ return Object.values(abiParameter.components).every(
257
+ (component, index) => {
258
+ return isArgOfType(
259
+ Object.values(arg)[index],
260
+ component
261
+ );
262
+ }
263
+ );
264
+ if (/^u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/.test(
265
+ abiParameterType
266
+ ))
267
+ return argType === "number" || argType === "bigint" || BigNumber.isBigNumber(arg);
268
+ if (/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/.test(abiParameterType))
269
+ return argType === "string" || arg instanceof Uint8Array;
270
+ if (/[a-z]+[1-9]{0,3}(\[[0-9]{0,}\])+$/.test(abiParameterType)) {
271
+ return Array.isArray(arg) && arg.every(
272
+ (x) => isArgOfType(x, {
273
+ ...abiParameter,
274
+ type: abiParameterType.replace(/(\[[0-9]{0,}\])$/, "")
275
+ })
276
+ );
277
+ }
278
+ return false;
279
+ }
280
+ }
281
+ }
282
+
283
+ // src/utils/getInjectedName.ts
284
+ function getInjectedName(ethereum) {
285
+ if (!ethereum)
286
+ return "Injected";
287
+ const getName = (provider) => {
288
+ if (provider.isAvalanche)
289
+ return "Core Wallet";
290
+ if (provider.isBitKeep)
291
+ return "BitKeep";
292
+ if (provider.isBraveWallet)
293
+ return "Brave Wallet";
294
+ if (provider.isCoinbaseWallet)
295
+ return "Coinbase Wallet";
296
+ if (provider.isExodus)
297
+ return "Exodus";
298
+ if (provider.isFrame)
299
+ return "Frame";
300
+ if (provider.isKuCoinWallet)
301
+ return "KuCoin Wallet";
302
+ if (provider.isMathWallet)
303
+ return "MathWallet";
304
+ if (provider.isOneInchIOSWallet || provider.isOneInchAndroidWallet)
305
+ return "1inch Wallet";
306
+ if (provider.isOpera)
307
+ return "Opera";
308
+ if (provider.isPortal)
309
+ return "Ripio Portal";
310
+ if (provider.isTally)
311
+ return "Tally";
312
+ if (provider.isTokenPocket)
313
+ return "TokenPocket";
314
+ if (provider.isTokenary)
315
+ return "Tokenary";
316
+ if (provider.isTrust || provider.isTrustWallet)
317
+ return "Trust Wallet";
318
+ if (provider.isMetaMask)
319
+ return "MetaMask";
320
+ };
321
+ if (ethereum.providers?.length) {
322
+ const nameSet = /* @__PURE__ */ new Set();
323
+ let unknownCount = 1;
324
+ for (const provider of ethereum.providers) {
325
+ let name = getName(provider);
326
+ if (!name) {
327
+ name = `Unknown Wallet #${unknownCount}`;
328
+ unknownCount += 1;
329
+ }
330
+ nameSet.add(name);
331
+ }
332
+ const names = [...nameSet];
333
+ if (names.length)
334
+ return names;
335
+ return names[0] ?? "Injected";
336
+ }
337
+ return getName(ethereum) ?? "Injected";
338
+ }
339
+
340
+ // src/utils/logger.ts
341
+ function logWarn(message) {
342
+ getClient()?.config.logger?.warn?.(message);
343
+ }
344
+
345
+ // src/utils/minimizeContractInterface.ts
346
+ import { Contract as Contract2 } from "ethers";
347
+ import { FormatTypes } from "ethers/lib/utils.js";
348
+ function minimizeContractInterface(config) {
349
+ try {
350
+ const minimizedAbi = config.abi.filter(
351
+ (x) => x.type === "function" && x.name === config.functionName
352
+ );
353
+ if (minimizedAbi.length === 0)
354
+ throw new Error("Invalid ABI");
355
+ return minimizedAbi;
356
+ } catch (error) {
357
+ const abi = Contract2.getInterface(config.abi).format(
358
+ FormatTypes.full
359
+ );
360
+ const minimizedInterface = Array.isArray(abi) ? abi : [abi];
361
+ return minimizedInterface.filter((i) => i.includes(config.functionName));
362
+ }
363
+ }
364
+
365
+ // src/utils/normalizeChainId.ts
366
+ function normalizeChainId(chainId2) {
367
+ if (typeof chainId2 === "string")
368
+ return Number.parseInt(
369
+ chainId2,
370
+ chainId2.trim().substring(0, 2) === "0x" ? 16 : 10
371
+ );
372
+ if (typeof chainId2 === "bigint")
373
+ return Number(chainId2);
374
+ return chainId2;
375
+ }
376
+
377
+ // src/utils/parseContractResult.ts
378
+ import { Contract as Contract3 } from "ethers";
379
+ function isPlainArray(value) {
380
+ return Array.isArray(value) && Object.keys(value).length === value.length;
381
+ }
382
+ function parseContractResult({
383
+ abi,
384
+ data,
385
+ functionName
386
+ }) {
387
+ if (data && isPlainArray(data)) {
388
+ const iface = Contract3.getInterface(abi);
389
+ const fragment = iface.getFunction(functionName);
390
+ const isTuple = (fragment.outputs?.length || 0) > 1;
391
+ const data_ = isTuple ? data : [data];
392
+ const encodedResult = iface.encodeFunctionResult(functionName, data_);
393
+ const decodedResult = iface.decodeFunctionResult(
394
+ functionName,
395
+ encodedResult
396
+ );
397
+ return isTuple ? decodedResult : decodedResult[0];
398
+ }
399
+ return data;
400
+ }
401
+
402
+ // src/connectors/base.ts
403
+ import { default as EventEmitter } from "eventemitter3";
404
+
405
+ // src/constants/abis.ts
406
+ var erc20ABI = [
407
+ {
408
+ type: "event",
409
+ name: "Approval",
410
+ inputs: [
411
+ {
412
+ indexed: true,
413
+ name: "owner",
414
+ type: "address"
415
+ },
416
+ {
417
+ indexed: true,
418
+ name: "spender",
419
+ type: "address"
420
+ },
421
+ {
422
+ indexed: false,
423
+ name: "value",
424
+ type: "uint256"
425
+ }
426
+ ]
427
+ },
428
+ {
429
+ type: "event",
430
+ name: "Transfer",
431
+ inputs: [
432
+ {
433
+ indexed: true,
434
+ name: "from",
435
+ type: "address"
436
+ },
437
+ {
438
+ indexed: true,
439
+ name: "to",
440
+ type: "address"
441
+ },
442
+ {
443
+ indexed: false,
444
+ name: "value",
445
+ type: "uint256"
446
+ }
447
+ ]
448
+ },
449
+ {
450
+ type: "function",
451
+ name: "allowance",
452
+ stateMutability: "view",
453
+ inputs: [
454
+ {
455
+ name: "owner",
456
+ type: "address"
457
+ },
458
+ {
459
+ name: "spender",
460
+ type: "address"
461
+ }
462
+ ],
463
+ outputs: [
464
+ {
465
+ name: "",
466
+ type: "uint256"
467
+ }
468
+ ]
469
+ },
470
+ {
471
+ type: "function",
472
+ name: "approve",
473
+ stateMutability: "nonpayable",
474
+ inputs: [
475
+ {
476
+ name: "spender",
477
+ type: "address"
478
+ },
479
+ {
480
+ name: "amount",
481
+ type: "uint256"
482
+ }
483
+ ],
484
+ outputs: [
485
+ {
486
+ name: "",
487
+ type: "bool"
488
+ }
489
+ ]
490
+ },
491
+ {
492
+ type: "function",
493
+ name: "balanceOf",
494
+ stateMutability: "view",
495
+ inputs: [
496
+ {
497
+ name: "account",
498
+ type: "address"
499
+ }
500
+ ],
501
+ outputs: [
502
+ {
503
+ name: "",
504
+ type: "uint256"
505
+ }
506
+ ]
507
+ },
508
+ {
509
+ type: "function",
510
+ name: "decimals",
511
+ stateMutability: "view",
512
+ inputs: [],
513
+ outputs: [
514
+ {
515
+ name: "",
516
+ type: "uint8"
517
+ }
518
+ ]
519
+ },
520
+ {
521
+ type: "function",
522
+ name: "name",
523
+ stateMutability: "view",
524
+ inputs: [],
525
+ outputs: [
526
+ {
527
+ name: "",
528
+ type: "string"
529
+ }
530
+ ]
531
+ },
532
+ {
533
+ type: "function",
534
+ name: "symbol",
535
+ stateMutability: "view",
536
+ inputs: [],
537
+ outputs: [
538
+ {
539
+ name: "",
540
+ type: "string"
541
+ }
542
+ ]
543
+ },
544
+ {
545
+ type: "function",
546
+ name: "totalSupply",
547
+ stateMutability: "view",
548
+ inputs: [],
549
+ outputs: [
550
+ {
551
+ name: "",
552
+ type: "uint256"
553
+ }
554
+ ]
555
+ },
556
+ {
557
+ type: "function",
558
+ name: "transfer",
559
+ stateMutability: "nonpayable",
560
+ inputs: [
561
+ {
562
+ name: "recipient",
563
+ type: "address"
564
+ },
565
+ {
566
+ name: "amount",
567
+ type: "uint256"
568
+ }
569
+ ],
570
+ outputs: [
571
+ {
572
+ name: "",
573
+ type: "bool"
574
+ }
575
+ ]
576
+ },
577
+ {
578
+ type: "function",
579
+ name: "transferFrom",
580
+ stateMutability: "nonpayable",
581
+ inputs: [
582
+ {
583
+ name: "sender",
584
+ type: "address"
585
+ },
586
+ {
587
+ name: "recipient",
588
+ type: "address"
589
+ },
590
+ {
591
+ name: "amount",
592
+ type: "uint256"
593
+ }
594
+ ],
595
+ outputs: [
596
+ {
597
+ name: "",
598
+ type: "bool"
599
+ }
600
+ ]
601
+ }
602
+ ];
603
+ var erc20ABI_bytes32 = [
604
+ {
605
+ type: "event",
606
+ name: "Approval",
607
+ inputs: [
608
+ {
609
+ indexed: true,
610
+ name: "owner",
611
+ type: "address"
612
+ },
613
+ {
614
+ indexed: true,
615
+ name: "spender",
616
+ type: "address"
617
+ },
618
+ {
619
+ indexed: false,
620
+ name: "value",
621
+ type: "uint256"
622
+ }
623
+ ]
624
+ },
625
+ {
626
+ type: "event",
627
+ name: "Transfer",
628
+ inputs: [
629
+ {
630
+ indexed: true,
631
+ name: "from",
632
+ type: "address"
633
+ },
634
+ {
635
+ indexed: true,
636
+ name: "to",
637
+ type: "address"
638
+ },
639
+ {
640
+ indexed: false,
641
+ name: "value",
642
+ type: "uint256"
643
+ }
644
+ ]
645
+ },
646
+ {
647
+ type: "function",
648
+ name: "allowance",
649
+ stateMutability: "view",
650
+ inputs: [
651
+ {
652
+ name: "owner",
653
+ type: "address"
654
+ },
655
+ {
656
+ name: "spender",
657
+ type: "address"
658
+ }
659
+ ],
660
+ outputs: [
661
+ {
662
+ name: "",
663
+ type: "uint256"
664
+ }
665
+ ]
666
+ },
667
+ {
668
+ type: "function",
669
+ name: "approve",
670
+ stateMutability: "nonpayable",
671
+ inputs: [
672
+ {
673
+ name: "spender",
674
+ type: "address"
675
+ },
676
+ {
677
+ name: "amount",
678
+ type: "uint256"
679
+ }
680
+ ],
681
+ outputs: [
682
+ {
683
+ name: "",
684
+ type: "bool"
685
+ }
686
+ ]
687
+ },
688
+ {
689
+ type: "function",
690
+ name: "balanceOf",
691
+ stateMutability: "view",
692
+ inputs: [
693
+ {
694
+ name: "account",
695
+ type: "address"
696
+ }
697
+ ],
698
+ outputs: [
699
+ {
700
+ name: "",
701
+ type: "uint256"
702
+ }
703
+ ]
704
+ },
705
+ {
706
+ type: "function",
707
+ name: "decimals",
708
+ stateMutability: "view",
709
+ inputs: [],
710
+ outputs: [
711
+ {
712
+ name: "",
713
+ type: "uint8"
714
+ }
715
+ ]
716
+ },
717
+ {
718
+ type: "function",
719
+ name: "name",
720
+ stateMutability: "view",
721
+ inputs: [],
722
+ outputs: [
723
+ {
724
+ name: "",
725
+ type: "bytes32"
726
+ }
727
+ ]
728
+ },
729
+ {
730
+ type: "function",
731
+ name: "symbol",
732
+ stateMutability: "view",
733
+ inputs: [],
734
+ outputs: [
735
+ {
736
+ name: "",
737
+ type: "bytes32"
738
+ }
739
+ ]
740
+ },
741
+ {
742
+ type: "function",
743
+ name: "totalSupply",
744
+ stateMutability: "view",
745
+ inputs: [],
746
+ outputs: [
747
+ {
748
+ name: "",
749
+ type: "uint256"
750
+ }
751
+ ]
752
+ },
753
+ {
754
+ type: "function",
755
+ name: "transfer",
756
+ stateMutability: "nonpayable",
757
+ inputs: [
758
+ {
759
+ name: "recipient",
760
+ type: "address"
761
+ },
762
+ {
763
+ name: "amount",
764
+ type: "uint256"
765
+ }
766
+ ],
767
+ outputs: [
768
+ {
769
+ name: "",
770
+ type: "bool"
771
+ }
772
+ ]
773
+ },
774
+ {
775
+ type: "function",
776
+ name: "transferFrom",
777
+ stateMutability: "nonpayable",
778
+ inputs: [
779
+ {
780
+ name: "sender",
781
+ type: "address"
782
+ },
783
+ {
784
+ name: "recipient",
785
+ type: "address"
786
+ },
787
+ {
788
+ name: "amount",
789
+ type: "uint256"
790
+ }
791
+ ],
792
+ outputs: [
793
+ {
794
+ name: "",
795
+ type: "bool"
796
+ }
797
+ ]
798
+ }
799
+ ];
800
+ var erc721ABI = [
801
+ {
802
+ type: "event",
803
+ name: "Approval",
804
+ inputs: [
805
+ {
806
+ indexed: true,
807
+ name: "owner",
808
+ type: "address"
809
+ },
810
+ {
811
+ indexed: true,
812
+ name: "spender",
813
+ type: "address"
814
+ },
815
+ {
816
+ indexed: true,
817
+ name: "tokenId",
818
+ type: "uint256"
819
+ }
820
+ ]
821
+ },
822
+ {
823
+ type: "event",
824
+ name: "ApprovalForAll",
825
+ inputs: [
826
+ {
827
+ indexed: true,
828
+ name: "owner",
829
+ type: "address"
830
+ },
831
+ {
832
+ indexed: true,
833
+ name: "operator",
834
+ type: "address"
835
+ },
836
+ {
837
+ indexed: false,
838
+ name: "approved",
839
+ type: "bool"
840
+ }
841
+ ]
842
+ },
843
+ {
844
+ type: "event",
845
+ name: "Transfer",
846
+ inputs: [
847
+ {
848
+ indexed: true,
849
+ name: "from",
850
+ type: "address"
851
+ },
852
+ {
853
+ indexed: true,
854
+ name: "to",
855
+ type: "address"
856
+ },
857
+ {
858
+ indexed: true,
859
+ name: "tokenId",
860
+ type: "uint256"
861
+ }
862
+ ]
863
+ },
864
+ {
865
+ type: "function",
866
+ name: "approve",
867
+ stateMutability: "payable",
868
+ inputs: [
869
+ {
870
+ name: "spender",
871
+ type: "address"
872
+ },
873
+ {
874
+ name: "tokenId",
875
+ type: "uint256"
876
+ }
877
+ ],
878
+ outputs: []
879
+ },
880
+ {
881
+ type: "function",
882
+ name: "balanceOf",
883
+ stateMutability: "view",
884
+ inputs: [
885
+ {
886
+ name: "account",
887
+ type: "address"
888
+ }
889
+ ],
890
+ outputs: [
891
+ {
892
+ name: "",
893
+ type: "uint256"
894
+ }
895
+ ]
896
+ },
897
+ {
898
+ type: "function",
899
+ name: "getApproved",
900
+ stateMutability: "view",
901
+ inputs: [
902
+ {
903
+ name: "tokenId",
904
+ type: "uint256"
905
+ }
906
+ ],
907
+ outputs: [
908
+ {
909
+ name: "",
910
+ type: "address"
911
+ }
912
+ ]
913
+ },
914
+ {
915
+ type: "function",
916
+ name: "isApprovedForAll",
917
+ stateMutability: "view",
918
+ inputs: [
919
+ {
920
+ name: "owner",
921
+ type: "address"
922
+ },
923
+ {
924
+ name: "operator",
925
+ type: "address"
926
+ }
927
+ ],
928
+ outputs: [
929
+ {
930
+ name: "",
931
+ type: "bool"
932
+ }
933
+ ]
934
+ },
935
+ {
936
+ type: "function",
937
+ name: "name",
938
+ stateMutability: "view",
939
+ inputs: [],
940
+ outputs: [
941
+ {
942
+ name: "",
943
+ type: "string"
944
+ }
945
+ ]
946
+ },
947
+ {
948
+ type: "function",
949
+ name: "ownerOf",
950
+ stateMutability: "view",
951
+ inputs: [
952
+ {
953
+ name: "tokenId",
954
+ type: "uint256"
955
+ }
956
+ ],
957
+ outputs: [
958
+ {
959
+ name: "owner",
960
+ type: "address"
961
+ }
962
+ ]
963
+ },
964
+ {
965
+ type: "function",
966
+ name: "safeTransferFrom",
967
+ stateMutability: "payable",
968
+ inputs: [
969
+ {
970
+ name: "from",
971
+ type: "address"
972
+ },
973
+ {
974
+ name: "to",
975
+ type: "address"
976
+ },
977
+ {
978
+ name: "tokenId",
979
+ type: "uint256"
980
+ }
981
+ ],
982
+ outputs: []
983
+ },
984
+ {
985
+ type: "function",
986
+ name: "safeTransferFrom",
987
+ stateMutability: "nonpayable",
988
+ inputs: [
989
+ {
990
+ name: "from",
991
+ type: "address"
992
+ },
993
+ {
994
+ name: "to",
995
+ type: "address"
996
+ },
997
+ {
998
+ name: "id",
999
+ type: "uint256"
1000
+ },
1001
+ {
1002
+ name: "data",
1003
+ type: "bytes"
1004
+ }
1005
+ ],
1006
+ outputs: []
1007
+ },
1008
+ {
1009
+ type: "function",
1010
+ name: "setApprovalForAll",
1011
+ stateMutability: "nonpayable",
1012
+ inputs: [
1013
+ {
1014
+ name: "operator",
1015
+ type: "address"
1016
+ },
1017
+ {
1018
+ name: "approved",
1019
+ type: "bool"
1020
+ }
1021
+ ],
1022
+ outputs: []
1023
+ },
1024
+ {
1025
+ type: "function",
1026
+ name: "symbol",
1027
+ stateMutability: "view",
1028
+ inputs: [],
1029
+ outputs: [
1030
+ {
1031
+ name: "",
1032
+ type: "string"
1033
+ }
1034
+ ]
1035
+ },
1036
+ {
1037
+ type: "function",
1038
+ name: "tokenByIndex",
1039
+ stateMutability: "view",
1040
+ inputs: [
1041
+ {
1042
+ name: "index",
1043
+ type: "uint256"
1044
+ }
1045
+ ],
1046
+ outputs: [
1047
+ {
1048
+ name: "",
1049
+ type: "uint256"
1050
+ }
1051
+ ]
1052
+ },
1053
+ {
1054
+ type: "function",
1055
+ name: "tokenByIndex",
1056
+ stateMutability: "view",
1057
+ inputs: [
1058
+ {
1059
+ name: "owner",
1060
+ type: "address"
1061
+ },
1062
+ {
1063
+ name: "index",
1064
+ type: "uint256"
1065
+ }
1066
+ ],
1067
+ outputs: [
1068
+ {
1069
+ name: "tokenId",
1070
+ type: "uint256"
1071
+ }
1072
+ ]
1073
+ },
1074
+ {
1075
+ type: "function",
1076
+ name: "tokenURI",
1077
+ stateMutability: "view",
1078
+ inputs: [
1079
+ {
1080
+ name: "tokenId",
1081
+ type: "uint256"
1082
+ }
1083
+ ],
1084
+ outputs: [
1085
+ {
1086
+ name: "",
1087
+ type: "string"
1088
+ }
1089
+ ]
1090
+ },
1091
+ {
1092
+ type: "function",
1093
+ name: "totalSupply",
1094
+ stateMutability: "view",
1095
+ inputs: [],
1096
+ outputs: [
1097
+ {
1098
+ name: "",
1099
+ type: "uint256"
1100
+ }
1101
+ ]
1102
+ },
1103
+ {
1104
+ type: "function",
1105
+ name: "transferFrom",
1106
+ stateMutability: "payable",
1107
+ inputs: [
1108
+ {
1109
+ name: "sender",
1110
+ type: "address"
1111
+ },
1112
+ {
1113
+ name: "recipient",
1114
+ type: "address"
1115
+ },
1116
+ {
1117
+ name: "tokeId",
1118
+ type: "uint256"
1119
+ }
1120
+ ],
1121
+ outputs: []
1122
+ }
1123
+ ];
1124
+ var multicallABI = [
1125
+ {
1126
+ inputs: [
1127
+ {
1128
+ components: [
1129
+ {
1130
+ name: "target",
1131
+ type: "address"
1132
+ },
1133
+ {
1134
+ name: "allowFailure",
1135
+ type: "bool"
1136
+ },
1137
+ {
1138
+ name: "callData",
1139
+ type: "bytes"
1140
+ }
1141
+ ],
1142
+ name: "calls",
1143
+ type: "tuple[]"
1144
+ }
1145
+ ],
1146
+ name: "aggregate3",
1147
+ outputs: [
1148
+ {
1149
+ components: [
1150
+ {
1151
+ name: "success",
1152
+ type: "bool"
1153
+ },
1154
+ {
1155
+ name: "returnData",
1156
+ type: "bytes"
1157
+ }
1158
+ ],
1159
+ name: "returnData",
1160
+ type: "tuple[]"
1161
+ }
1162
+ ],
1163
+ stateMutability: "view",
1164
+ type: "function"
1165
+ }
1166
+ ];
1167
+ var erc4626ABI = [
1168
+ {
1169
+ anonymous: false,
1170
+ inputs: [
1171
+ {
1172
+ indexed: true,
1173
+ name: "owner",
1174
+ type: "address"
1175
+ },
1176
+ {
1177
+ indexed: true,
1178
+ name: "spender",
1179
+ type: "address"
1180
+ },
1181
+ {
1182
+ indexed: false,
1183
+ name: "value",
1184
+ type: "uint256"
1185
+ }
1186
+ ],
1187
+ name: "Approval",
1188
+ type: "event"
1189
+ },
1190
+ {
1191
+ anonymous: false,
1192
+ inputs: [
1193
+ {
1194
+ indexed: true,
1195
+ name: "sender",
1196
+ type: "address"
1197
+ },
1198
+ {
1199
+ indexed: true,
1200
+ name: "receiver",
1201
+ type: "address"
1202
+ },
1203
+ {
1204
+ indexed: false,
1205
+ name: "assets",
1206
+ type: "uint256"
1207
+ },
1208
+ {
1209
+ indexed: false,
1210
+ name: "shares",
1211
+ type: "uint256"
1212
+ }
1213
+ ],
1214
+ name: "Deposit",
1215
+ type: "event"
1216
+ },
1217
+ {
1218
+ anonymous: false,
1219
+ inputs: [
1220
+ {
1221
+ indexed: true,
1222
+ name: "from",
1223
+ type: "address"
1224
+ },
1225
+ {
1226
+ indexed: true,
1227
+ name: "to",
1228
+ type: "address"
1229
+ },
1230
+ {
1231
+ indexed: false,
1232
+ name: "value",
1233
+ type: "uint256"
1234
+ }
1235
+ ],
1236
+ name: "Transfer",
1237
+ type: "event"
1238
+ },
1239
+ {
1240
+ anonymous: false,
1241
+ inputs: [
1242
+ {
1243
+ indexed: true,
1244
+ name: "sender",
1245
+ type: "address"
1246
+ },
1247
+ {
1248
+ indexed: true,
1249
+ name: "receiver",
1250
+ type: "address"
1251
+ },
1252
+ {
1253
+ indexed: true,
1254
+ name: "owner",
1255
+ type: "address"
1256
+ },
1257
+ {
1258
+ indexed: false,
1259
+ name: "assets",
1260
+ type: "uint256"
1261
+ },
1262
+ {
1263
+ indexed: false,
1264
+ name: "shares",
1265
+ type: "uint256"
1266
+ }
1267
+ ],
1268
+ name: "Withdraw",
1269
+ type: "event"
1270
+ },
1271
+ {
1272
+ inputs: [
1273
+ {
1274
+ name: "owner",
1275
+ type: "address"
1276
+ },
1277
+ {
1278
+ name: "spender",
1279
+ type: "address"
1280
+ }
1281
+ ],
1282
+ name: "allowance",
1283
+ outputs: [
1284
+ {
1285
+ name: "",
1286
+ type: "uint256"
1287
+ }
1288
+ ],
1289
+ stateMutability: "view",
1290
+ type: "function"
1291
+ },
1292
+ {
1293
+ inputs: [
1294
+ {
1295
+ name: "spender",
1296
+ type: "address"
1297
+ },
1298
+ {
1299
+ name: "amount",
1300
+ type: "uint256"
1301
+ }
1302
+ ],
1303
+ name: "approve",
1304
+ outputs: [
1305
+ {
1306
+ name: "",
1307
+ type: "bool"
1308
+ }
1309
+ ],
1310
+ stateMutability: "nonpayable",
1311
+ type: "function"
1312
+ },
1313
+ {
1314
+ inputs: [],
1315
+ name: "asset",
1316
+ outputs: [
1317
+ {
1318
+ name: "assetTokenAddress",
1319
+ type: "address"
1320
+ }
1321
+ ],
1322
+ stateMutability: "view",
1323
+ type: "function"
1324
+ },
1325
+ {
1326
+ inputs: [
1327
+ {
1328
+ name: "account",
1329
+ type: "address"
1330
+ }
1331
+ ],
1332
+ name: "balanceOf",
1333
+ outputs: [
1334
+ {
1335
+ name: "",
1336
+ type: "uint256"
1337
+ }
1338
+ ],
1339
+ stateMutability: "view",
1340
+ type: "function"
1341
+ },
1342
+ {
1343
+ inputs: [
1344
+ {
1345
+ name: "shares",
1346
+ type: "uint256"
1347
+ }
1348
+ ],
1349
+ name: "convertToAssets",
1350
+ outputs: [
1351
+ {
1352
+ name: "assets",
1353
+ type: "uint256"
1354
+ }
1355
+ ],
1356
+ stateMutability: "view",
1357
+ type: "function"
1358
+ },
1359
+ {
1360
+ inputs: [
1361
+ {
1362
+ name: "assets",
1363
+ type: "uint256"
1364
+ }
1365
+ ],
1366
+ name: "convertToShares",
1367
+ outputs: [
1368
+ {
1369
+ name: "shares",
1370
+ type: "uint256"
1371
+ }
1372
+ ],
1373
+ stateMutability: "view",
1374
+ type: "function"
1375
+ },
1376
+ {
1377
+ inputs: [
1378
+ {
1379
+ name: "assets",
1380
+ type: "uint256"
1381
+ },
1382
+ {
1383
+ name: "receiver",
1384
+ type: "address"
1385
+ }
1386
+ ],
1387
+ name: "deposit",
1388
+ outputs: [
1389
+ {
1390
+ name: "shares",
1391
+ type: "uint256"
1392
+ }
1393
+ ],
1394
+ stateMutability: "nonpayable",
1395
+ type: "function"
1396
+ },
1397
+ {
1398
+ inputs: [
1399
+ {
1400
+ name: "caller",
1401
+ type: "address"
1402
+ }
1403
+ ],
1404
+ name: "maxDeposit",
1405
+ outputs: [
1406
+ {
1407
+ name: "maxAssets",
1408
+ type: "uint256"
1409
+ }
1410
+ ],
1411
+ stateMutability: "view",
1412
+ type: "function"
1413
+ },
1414
+ {
1415
+ inputs: [
1416
+ {
1417
+ name: "caller",
1418
+ type: "address"
1419
+ }
1420
+ ],
1421
+ name: "maxMint",
1422
+ outputs: [
1423
+ {
1424
+ name: "maxShares",
1425
+ type: "uint256"
1426
+ }
1427
+ ],
1428
+ stateMutability: "view",
1429
+ type: "function"
1430
+ },
1431
+ {
1432
+ inputs: [
1433
+ {
1434
+ name: "owner",
1435
+ type: "address"
1436
+ }
1437
+ ],
1438
+ name: "maxRedeem",
1439
+ outputs: [
1440
+ {
1441
+ name: "maxShares",
1442
+ type: "uint256"
1443
+ }
1444
+ ],
1445
+ stateMutability: "view",
1446
+ type: "function"
1447
+ },
1448
+ {
1449
+ inputs: [
1450
+ {
1451
+ name: "owner",
1452
+ type: "address"
1453
+ }
1454
+ ],
1455
+ name: "maxWithdraw",
1456
+ outputs: [
1457
+ {
1458
+ name: "maxAssets",
1459
+ type: "uint256"
1460
+ }
1461
+ ],
1462
+ stateMutability: "view",
1463
+ type: "function"
1464
+ },
1465
+ {
1466
+ inputs: [
1467
+ {
1468
+ name: "shares",
1469
+ type: "uint256"
1470
+ },
1471
+ {
1472
+ name: "receiver",
1473
+ type: "address"
1474
+ }
1475
+ ],
1476
+ name: "mint",
1477
+ outputs: [
1478
+ {
1479
+ name: "assets",
1480
+ type: "uint256"
1481
+ }
1482
+ ],
1483
+ stateMutability: "nonpayable",
1484
+ type: "function"
1485
+ },
1486
+ {
1487
+ inputs: [
1488
+ {
1489
+ name: "assets",
1490
+ type: "uint256"
1491
+ }
1492
+ ],
1493
+ name: "previewDeposit",
1494
+ outputs: [
1495
+ {
1496
+ name: "shares",
1497
+ type: "uint256"
1498
+ }
1499
+ ],
1500
+ stateMutability: "view",
1501
+ type: "function"
1502
+ },
1503
+ {
1504
+ inputs: [
1505
+ {
1506
+ name: "shares",
1507
+ type: "uint256"
1508
+ }
1509
+ ],
1510
+ name: "previewMint",
1511
+ outputs: [
1512
+ {
1513
+ name: "assets",
1514
+ type: "uint256"
1515
+ }
1516
+ ],
1517
+ stateMutability: "view",
1518
+ type: "function"
1519
+ },
1520
+ {
1521
+ inputs: [
1522
+ {
1523
+ name: "shares",
1524
+ type: "uint256"
1525
+ }
1526
+ ],
1527
+ name: "previewRedeem",
1528
+ outputs: [
1529
+ {
1530
+ name: "assets",
1531
+ type: "uint256"
1532
+ }
1533
+ ],
1534
+ stateMutability: "view",
1535
+ type: "function"
1536
+ },
1537
+ {
1538
+ inputs: [
1539
+ {
1540
+ name: "assets",
1541
+ type: "uint256"
1542
+ }
1543
+ ],
1544
+ name: "previewWithdraw",
1545
+ outputs: [
1546
+ {
1547
+ name: "shares",
1548
+ type: "uint256"
1549
+ }
1550
+ ],
1551
+ stateMutability: "view",
1552
+ type: "function"
1553
+ },
1554
+ {
1555
+ inputs: [
1556
+ {
1557
+ name: "shares",
1558
+ type: "uint256"
1559
+ },
1560
+ {
1561
+ name: "receiver",
1562
+ type: "address"
1563
+ },
1564
+ {
1565
+ name: "owner",
1566
+ type: "address"
1567
+ }
1568
+ ],
1569
+ name: "redeem",
1570
+ outputs: [
1571
+ {
1572
+ name: "assets",
1573
+ type: "uint256"
1574
+ }
1575
+ ],
1576
+ stateMutability: "nonpayable",
1577
+ type: "function"
1578
+ },
1579
+ {
1580
+ inputs: [],
1581
+ name: "totalAssets",
1582
+ outputs: [
1583
+ {
1584
+ name: "totalManagedAssets",
1585
+ type: "uint256"
1586
+ }
1587
+ ],
1588
+ stateMutability: "view",
1589
+ type: "function"
1590
+ },
1591
+ {
1592
+ inputs: [],
1593
+ name: "totalSupply",
1594
+ outputs: [
1595
+ {
1596
+ name: "",
1597
+ type: "uint256"
1598
+ }
1599
+ ],
1600
+ stateMutability: "view",
1601
+ type: "function"
1602
+ },
1603
+ {
1604
+ inputs: [
1605
+ {
1606
+ name: "to",
1607
+ type: "address"
1608
+ },
1609
+ {
1610
+ name: "amount",
1611
+ type: "uint256"
1612
+ }
1613
+ ],
1614
+ name: "transfer",
1615
+ outputs: [
1616
+ {
1617
+ name: "",
1618
+ type: "bool"
1619
+ }
1620
+ ],
1621
+ stateMutability: "nonpayable",
1622
+ type: "function"
1623
+ },
1624
+ {
1625
+ inputs: [
1626
+ {
1627
+ name: "from",
1628
+ type: "address"
1629
+ },
1630
+ {
1631
+ name: "to",
1632
+ type: "address"
1633
+ },
1634
+ {
1635
+ name: "amount",
1636
+ type: "uint256"
1637
+ }
1638
+ ],
1639
+ name: "transferFrom",
1640
+ outputs: [
1641
+ {
1642
+ name: "",
1643
+ type: "bool"
1644
+ }
1645
+ ],
1646
+ stateMutability: "nonpayable",
1647
+ type: "function"
1648
+ },
1649
+ {
1650
+ inputs: [
1651
+ {
1652
+ name: "assets",
1653
+ type: "uint256"
1654
+ },
1655
+ {
1656
+ name: "receiver",
1657
+ type: "address"
1658
+ },
1659
+ {
1660
+ name: "owner",
1661
+ type: "address"
1662
+ }
1663
+ ],
1664
+ name: "withdraw",
1665
+ outputs: [
1666
+ {
1667
+ name: "shares",
1668
+ type: "uint256"
1669
+ }
1670
+ ],
1671
+ stateMutability: "nonpayable",
1672
+ type: "function"
1673
+ }
1674
+ ];
1675
+
1676
+ // src/constants/units.ts
1677
+ var units = [
1678
+ "wei",
1679
+ "kwei",
1680
+ "mwei",
1681
+ "gwei",
1682
+ "szabo",
1683
+ "finney",
1684
+ "ether"
1685
+ ];
1686
+
1687
+ // src/connectors/base.ts
1688
+ var Connector = class extends EventEmitter {
1689
+ constructor({
1690
+ chains = defaultChains,
1691
+ options
1692
+ }) {
1693
+ super();
1694
+ this.chains = chains;
1695
+ this.options = options;
1696
+ }
1697
+ getBlockExplorerUrls(chain2) {
1698
+ const { default: blockExplorer, ...blockExplorers } = chain2.blockExplorers ?? {};
1699
+ if (blockExplorer)
1700
+ return [
1701
+ blockExplorer.url,
1702
+ ...Object.values(blockExplorers).map((x) => x.url)
1703
+ ];
1704
+ }
1705
+ isChainUnsupported(chainId2) {
1706
+ return !this.chains.some((x) => x.id === chainId2);
1707
+ }
1708
+ };
1709
+
1710
+ // src/connectors/injected.ts
1711
+ var _provider, _switchingChains;
1712
+ var InjectedConnector = class extends Connector {
1713
+ constructor({
1714
+ chains,
1715
+ options: options_
1716
+ } = {}) {
1717
+ const options = {
1718
+ shimDisconnect: true,
1719
+ shimChainChangedDisconnect: true,
1720
+ ...options_
1721
+ };
1722
+ super({ chains, options });
1723
+ this.ready = typeof window != "undefined" && !!window.ethereum;
1724
+ __privateAdd(this, _provider, void 0);
1725
+ __privateAdd(this, _switchingChains, void 0);
1726
+ this.shimDisconnectKey = "injected.shimDisconnect";
1727
+ this.onAccountsChanged = (accounts) => {
1728
+ if (accounts.length === 0)
1729
+ this.emit("disconnect");
1730
+ else
1731
+ this.emit("change", {
1732
+ account: getAddress(accounts[0])
1733
+ });
1734
+ };
1735
+ this.onChainChanged = (chainId2) => {
1736
+ const id = normalizeChainId(chainId2);
1737
+ const unsupported = this.isChainUnsupported(id);
1738
+ this.emit("change", { chain: { id, unsupported } });
1739
+ };
1740
+ this.onDisconnect = () => {
1741
+ if (this.options?.shimChainChangedDisconnect && __privateGet(this, _switchingChains)) {
1742
+ __privateSet(this, _switchingChains, false);
1743
+ return;
1744
+ }
1745
+ this.emit("disconnect");
1746
+ if (this.options?.shimDisconnect)
1747
+ getClient().storage?.removeItem(this.shimDisconnectKey);
1748
+ };
1749
+ let name = "Injected";
1750
+ const overrideName = options.name;
1751
+ if (typeof overrideName === "string")
1752
+ name = overrideName;
1753
+ else if (typeof window !== "undefined") {
1754
+ const detectedName = getInjectedName(window.ethereum);
1755
+ if (overrideName)
1756
+ name = overrideName(detectedName);
1757
+ else
1758
+ name = typeof detectedName === "string" ? detectedName : detectedName[0];
1759
+ }
1760
+ this.id = "injected";
1761
+ this.name = name;
1762
+ }
1763
+ async connect({ chainId: chainId2 } = {}) {
1764
+ try {
1765
+ const provider = await this.getProvider();
1766
+ if (!provider)
1767
+ throw new ConnectorNotFoundError();
1768
+ if (provider.on) {
1769
+ provider.on("accountsChanged", this.onAccountsChanged);
1770
+ provider.on("chainChanged", this.onChainChanged);
1771
+ provider.on("disconnect", this.onDisconnect);
1772
+ }
1773
+ this.emit("message", { type: "connecting" });
1774
+ const account = await this.getAccount();
1775
+ let id = await this.getChainId();
1776
+ let unsupported = this.isChainUnsupported(id);
1777
+ if (chainId2 && id !== chainId2) {
1778
+ const chain2 = await this.switchChain(chainId2);
1779
+ id = chain2.id;
1780
+ unsupported = this.isChainUnsupported(id);
1781
+ }
1782
+ if (this.options?.shimDisconnect)
1783
+ getClient().storage?.setItem(this.shimDisconnectKey, true);
1784
+ return { account, chain: { id, unsupported }, provider };
1785
+ } catch (error) {
1786
+ if (this.isUserRejectedRequestError(error))
1787
+ throw new UserRejectedRequestError(error);
1788
+ if (error.code === -32002)
1789
+ throw new ResourceUnavailableError(error);
1790
+ throw error;
1791
+ }
1792
+ }
1793
+ async disconnect() {
1794
+ const provider = await this.getProvider();
1795
+ if (!provider?.removeListener)
1796
+ return;
1797
+ provider.removeListener("accountsChanged", this.onAccountsChanged);
1798
+ provider.removeListener("chainChanged", this.onChainChanged);
1799
+ provider.removeListener("disconnect", this.onDisconnect);
1800
+ if (this.options?.shimDisconnect)
1801
+ getClient().storage?.removeItem(this.shimDisconnectKey);
1802
+ }
1803
+ async getAccount() {
1804
+ const provider = await this.getProvider();
1805
+ if (!provider)
1806
+ throw new ConnectorNotFoundError();
1807
+ const accounts = await provider.request({
1808
+ method: "eth_requestAccounts"
1809
+ });
1810
+ return getAddress(accounts[0]);
1811
+ }
1812
+ async getChainId() {
1813
+ const provider = await this.getProvider();
1814
+ if (!provider)
1815
+ throw new ConnectorNotFoundError();
1816
+ return provider.request({ method: "eth_chainId" }).then(normalizeChainId);
1817
+ }
1818
+ async getProvider() {
1819
+ if (typeof window !== "undefined" && !!window.ethereum)
1820
+ __privateSet(this, _provider, window.ethereum);
1821
+ return __privateGet(this, _provider);
1822
+ }
1823
+ async getSigner({ chainId: chainId2 } = {}) {
1824
+ const [provider, account] = await Promise.all([
1825
+ this.getProvider(),
1826
+ this.getAccount()
1827
+ ]);
1828
+ return new providers2.Web3Provider(
1829
+ provider,
1830
+ chainId2
1831
+ ).getSigner(account);
1832
+ }
1833
+ async isAuthorized() {
1834
+ try {
1835
+ if (this.options?.shimDisconnect && !getClient().storage?.getItem(this.shimDisconnectKey))
1836
+ return false;
1837
+ const provider = await this.getProvider();
1838
+ if (!provider)
1839
+ throw new ConnectorNotFoundError();
1840
+ const accounts = await provider.request({
1841
+ method: "eth_accounts"
1842
+ });
1843
+ const account = accounts[0];
1844
+ return !!account;
1845
+ } catch {
1846
+ return false;
1847
+ }
1848
+ }
1849
+ async switchChain(chainId2) {
1850
+ if (this.options?.shimChainChangedDisconnect)
1851
+ __privateSet(this, _switchingChains, true);
1852
+ const provider = await this.getProvider();
1853
+ if (!provider)
1854
+ throw new ConnectorNotFoundError();
1855
+ const id = hexValue(chainId2);
1856
+ try {
1857
+ await provider.request({
1858
+ method: "wallet_switchEthereumChain",
1859
+ params: [{ chainId: id }]
1860
+ });
1861
+ return this.chains.find((x) => x.id === chainId2) ?? {
1862
+ id: chainId2,
1863
+ name: `Chain ${id}`,
1864
+ network: `${id}`,
1865
+ rpcUrls: { default: "" }
1866
+ };
1867
+ } catch (error) {
1868
+ const chain2 = this.chains.find((x) => x.id === chainId2);
1869
+ if (!chain2)
1870
+ throw new ChainNotConfiguredError({ chainId: chainId2, connectorId: this.id });
1871
+ if (error.code === 4902 || error?.data?.originalError?.code === 4902) {
1872
+ try {
1873
+ await provider.request({
1874
+ method: "wallet_addEthereumChain",
1875
+ params: [
1876
+ {
1877
+ chainId: id,
1878
+ chainName: chain2.name,
1879
+ nativeCurrency: chain2.nativeCurrency,
1880
+ rpcUrls: [chain2.rpcUrls.public ?? chain2.rpcUrls.default],
1881
+ blockExplorerUrls: this.getBlockExplorerUrls(chain2)
1882
+ }
1883
+ ]
1884
+ });
1885
+ return chain2;
1886
+ } catch (addError) {
1887
+ if (this.isUserRejectedRequestError(addError))
1888
+ throw new UserRejectedRequestError(error);
1889
+ throw new AddChainError();
1890
+ }
1891
+ }
1892
+ if (this.isUserRejectedRequestError(error))
1893
+ throw new UserRejectedRequestError(error);
1894
+ throw new SwitchChainError(error);
1895
+ }
1896
+ }
1897
+ async watchAsset({
1898
+ address,
1899
+ decimals = 18,
1900
+ image,
1901
+ symbol
1902
+ }) {
1903
+ const provider = await this.getProvider();
1904
+ if (!provider)
1905
+ throw new ConnectorNotFoundError();
1906
+ return provider.request({
1907
+ method: "wallet_watchAsset",
1908
+ params: {
1909
+ type: "ERC20",
1910
+ options: {
1911
+ address,
1912
+ decimals,
1913
+ image,
1914
+ symbol
1915
+ }
1916
+ }
1917
+ });
1918
+ }
1919
+ isUserRejectedRequestError(error) {
1920
+ return error.code === 4001;
1921
+ }
1922
+ };
1923
+ _provider = new WeakMap();
1924
+ _switchingChains = new WeakMap();
1925
+
1926
+ // src/storage.ts
1927
+ var noopStorage = {
1928
+ getItem: (_key) => "",
1929
+ setItem: (_key, _value) => null,
1930
+ removeItem: (_key) => null
1931
+ };
1932
+ function createStorage({
1933
+ storage,
1934
+ key: prefix = "wagmi"
1935
+ }) {
1936
+ return {
1937
+ ...storage,
1938
+ getItem: (key, defaultState = null) => {
1939
+ const value = storage.getItem(`${prefix}.${key}`);
1940
+ try {
1941
+ return value ? JSON.parse(value) : defaultState;
1942
+ } catch (error) {
1943
+ console.warn(error);
1944
+ return defaultState;
1945
+ }
1946
+ },
1947
+ setItem: (key, value) => {
1948
+ if (value === null) {
1949
+ storage.removeItem(`${prefix}.${key}`);
1950
+ } else {
1951
+ try {
1952
+ storage.setItem(`${prefix}.${key}`, JSON.stringify(value));
1953
+ } catch (err) {
1954
+ console.error(err);
1955
+ }
1956
+ }
1957
+ },
1958
+ removeItem: (key) => storage.removeItem(`${prefix}.${key}`)
1959
+ };
1960
+ }
1961
+
1962
+ // src/client.ts
1963
+ var storeKey = "store";
1964
+ var _isAutoConnecting, _lastUsedConnector, _addEffects, addEffects_fn;
1965
+ var Client = class {
1966
+ constructor({
1967
+ autoConnect = false,
1968
+ connectors = [new InjectedConnector()],
1969
+ provider,
1970
+ storage = createStorage({
1971
+ storage: typeof window !== "undefined" ? window.localStorage : noopStorage
1972
+ }),
1973
+ logger = {
1974
+ warn: console.warn
1975
+ },
1976
+ webSocketProvider
1977
+ }) {
1978
+ __privateAdd(this, _addEffects);
1979
+ this.providers = /* @__PURE__ */ new Map();
1980
+ this.webSocketProviders = /* @__PURE__ */ new Map();
1981
+ __privateAdd(this, _isAutoConnecting, void 0);
1982
+ __privateAdd(this, _lastUsedConnector, void 0);
1983
+ this.config = {
1984
+ autoConnect,
1985
+ connectors,
1986
+ logger,
1987
+ provider,
1988
+ storage,
1989
+ webSocketProvider
1990
+ };
1991
+ let status = "disconnected";
1992
+ let chainId2;
1993
+ if (autoConnect) {
1994
+ try {
1995
+ const rawState = storage.getItem(storeKey, "");
1996
+ const data = JSON.parse(rawState || "{}")?.state?.data;
1997
+ status = data?.account ? "reconnecting" : "connecting";
1998
+ chainId2 = data?.chain?.id;
1999
+ } catch (_error) {
2000
+ }
2001
+ }
2002
+ this.store = create(
2003
+ subscribeWithSelector(
2004
+ persist(
2005
+ () => ({
2006
+ connectors: typeof connectors === "function" ? connectors() : connectors,
2007
+ provider: this.getProvider({ chainId: chainId2 }),
2008
+ status,
2009
+ webSocketProvider: this.getWebSocketProvider({ chainId: chainId2 })
2010
+ }),
2011
+ {
2012
+ name: storeKey,
2013
+ getStorage: () => storage,
2014
+ partialize: (state) => ({
2015
+ ...autoConnect && {
2016
+ data: {
2017
+ account: state?.data?.account,
2018
+ chain: state?.data?.chain
2019
+ }
2020
+ },
2021
+ chains: state?.chains
2022
+ }),
2023
+ version: 1
2024
+ }
2025
+ )
2026
+ )
2027
+ );
2028
+ this.storage = storage;
2029
+ __privateSet(this, _lastUsedConnector, storage?.getItem("wallet"));
2030
+ __privateMethod(this, _addEffects, addEffects_fn).call(this);
2031
+ if (autoConnect && typeof window !== "undefined")
2032
+ setTimeout(async () => await this.autoConnect(), 0);
2033
+ }
2034
+ get chains() {
2035
+ return this.store.getState().chains;
2036
+ }
2037
+ get connectors() {
2038
+ return this.store.getState().connectors;
2039
+ }
2040
+ get connector() {
2041
+ return this.store.getState().connector;
2042
+ }
2043
+ get data() {
2044
+ return this.store.getState().data;
2045
+ }
2046
+ get error() {
2047
+ return this.store.getState().error;
2048
+ }
2049
+ get lastUsedChainId() {
2050
+ return this.data?.chain?.id;
2051
+ }
2052
+ get provider() {
2053
+ return this.store.getState().provider;
2054
+ }
2055
+ get status() {
2056
+ return this.store.getState().status;
2057
+ }
2058
+ get subscribe() {
2059
+ return this.store.subscribe;
2060
+ }
2061
+ get webSocketProvider() {
2062
+ return this.store.getState().webSocketProvider;
2063
+ }
2064
+ setState(updater) {
2065
+ const newState = typeof updater === "function" ? updater(this.store.getState()) : updater;
2066
+ this.store.setState(newState, true);
2067
+ }
2068
+ clearState() {
2069
+ this.setState((x) => ({
2070
+ ...x,
2071
+ chains: void 0,
2072
+ connector: void 0,
2073
+ data: void 0,
2074
+ error: void 0,
2075
+ status: "disconnected"
2076
+ }));
2077
+ }
2078
+ async destroy() {
2079
+ if (this.connector)
2080
+ await this.connector.disconnect?.();
2081
+ __privateSet(this, _isAutoConnecting, false);
2082
+ this.clearState();
2083
+ this.store.destroy();
2084
+ }
2085
+ async autoConnect() {
2086
+ if (__privateGet(this, _isAutoConnecting))
2087
+ return;
2088
+ __privateSet(this, _isAutoConnecting, true);
2089
+ this.setState((x) => ({
2090
+ ...x,
2091
+ status: x.data?.account ? "reconnecting" : "connecting"
2092
+ }));
2093
+ const sorted = __privateGet(this, _lastUsedConnector) ? [...this.connectors].sort(
2094
+ (x) => x.id === __privateGet(this, _lastUsedConnector) ? -1 : 1
2095
+ ) : this.connectors;
2096
+ let connected = false;
2097
+ for (const connector of sorted) {
2098
+ if (!connector.ready || !connector.isAuthorized)
2099
+ continue;
2100
+ const isAuthorized = await connector.isAuthorized();
2101
+ if (!isAuthorized)
2102
+ continue;
2103
+ const data = await connector.connect();
2104
+ this.setState((x) => ({
2105
+ ...x,
2106
+ connector,
2107
+ chains: connector?.chains,
2108
+ data,
2109
+ status: "connected"
2110
+ }));
2111
+ connected = true;
2112
+ break;
2113
+ }
2114
+ if (!connected)
2115
+ this.setState((x) => ({
2116
+ ...x,
2117
+ data: void 0,
2118
+ status: "disconnected"
2119
+ }));
2120
+ __privateSet(this, _isAutoConnecting, false);
2121
+ return this.data;
2122
+ }
2123
+ getProvider({ bust, chainId: chainId2 } = {}) {
2124
+ let provider_ = this.providers.get(chainId2 ?? -1);
2125
+ if (provider_ && !bust)
2126
+ return provider_;
2127
+ const { provider } = this.config;
2128
+ provider_ = typeof provider === "function" ? provider({ chainId: chainId2 }) : provider;
2129
+ this.providers.set(chainId2 ?? -1, provider_);
2130
+ return provider_;
2131
+ }
2132
+ getWebSocketProvider({
2133
+ bust,
2134
+ chainId: chainId2
2135
+ } = {}) {
2136
+ let webSocketProvider_ = this.webSocketProviders.get(chainId2 ?? -1);
2137
+ if (webSocketProvider_ && !bust)
2138
+ return webSocketProvider_;
2139
+ const { webSocketProvider } = this.config;
2140
+ webSocketProvider_ = typeof webSocketProvider === "function" ? webSocketProvider({ chainId: chainId2 }) : webSocketProvider;
2141
+ if (webSocketProvider_)
2142
+ this.webSocketProviders.set(chainId2 ?? -1, webSocketProvider_);
2143
+ return webSocketProvider_;
2144
+ }
2145
+ setLastUsedConnector(lastUsedConnector = null) {
2146
+ this.storage?.setItem("wallet", lastUsedConnector);
2147
+ }
2148
+ };
2149
+ _isAutoConnecting = new WeakMap();
2150
+ _lastUsedConnector = new WeakMap();
2151
+ _addEffects = new WeakSet();
2152
+ addEffects_fn = function() {
2153
+ const onChange = (data) => {
2154
+ this.setState((x) => ({
2155
+ ...x,
2156
+ data: { ...x.data, ...data }
2157
+ }));
2158
+ };
2159
+ const onDisconnect = () => {
2160
+ this.clearState();
2161
+ };
2162
+ const onError = (error) => {
2163
+ this.setState((x) => ({ ...x, error }));
2164
+ };
2165
+ this.store.subscribe(
2166
+ ({ connector }) => connector,
2167
+ (connector, prevConnector) => {
2168
+ prevConnector?.off?.("change", onChange);
2169
+ prevConnector?.off?.("disconnect", onDisconnect);
2170
+ prevConnector?.off?.("error", onError);
2171
+ if (!connector)
2172
+ return;
2173
+ connector.on?.("change", onChange);
2174
+ connector.on?.("disconnect", onDisconnect);
2175
+ connector.on?.("error", onError);
2176
+ }
2177
+ );
2178
+ const { provider, webSocketProvider } = this.config;
2179
+ const subscribeProvider = typeof provider === "function";
2180
+ const subscribeWebSocketProvider = typeof webSocketProvider === "function";
2181
+ if (subscribeProvider || subscribeWebSocketProvider)
2182
+ this.store.subscribe(
2183
+ ({ data }) => data?.chain?.id,
2184
+ (chainId2) => {
2185
+ this.setState((x) => ({
2186
+ ...x,
2187
+ provider: this.getProvider({ bust: true, chainId: chainId2 }),
2188
+ webSocketProvider: this.getWebSocketProvider({
2189
+ bust: true,
2190
+ chainId: chainId2
2191
+ })
2192
+ }));
2193
+ }
2194
+ );
2195
+ };
2196
+ var client;
2197
+ function createClient(config) {
2198
+ const client_ = new Client(config);
2199
+ client = client_;
2200
+ return client_;
2201
+ }
2202
+ function getClient() {
2203
+ if (!client) {
2204
+ throw new Error(
2205
+ "No wagmi client found. Ensure you have set up a client: https://wagmi.sh/docs/client"
2206
+ );
2207
+ }
2208
+ return client;
2209
+ }
2210
+
2211
+ // src/actions/accounts/connect.ts
2212
+ async function connect({
2213
+ chainId: chainId2,
2214
+ connector
2215
+ }) {
2216
+ const client2 = getClient();
2217
+ const activeConnector = client2.connector;
2218
+ if (connector.id === activeConnector?.id)
2219
+ throw new ConnectorAlreadyConnectedError();
2220
+ try {
2221
+ client2.setState((x) => ({ ...x, status: "connecting" }));
2222
+ const data = await connector.connect({ chainId: chainId2 });
2223
+ client2.setLastUsedConnector(connector.id);
2224
+ client2.setState((x) => ({
2225
+ ...x,
2226
+ connector,
2227
+ chains: connector?.chains,
2228
+ data,
2229
+ status: "connected"
2230
+ }));
2231
+ client2.storage.setItem("connected", true);
2232
+ return { ...data, connector };
2233
+ } catch (err) {
2234
+ client2.setState((x) => {
2235
+ return {
2236
+ ...x,
2237
+ status: x.connector ? "connected" : "disconnected"
2238
+ };
2239
+ });
2240
+ throw err;
2241
+ }
2242
+ }
2243
+
2244
+ // src/actions/accounts/disconnect.ts
2245
+ async function disconnect() {
2246
+ const client2 = getClient();
2247
+ if (client2.connector)
2248
+ await client2.connector.disconnect();
2249
+ client2.clearState();
2250
+ client2.storage.removeItem("connected");
2251
+ }
2252
+
2253
+ // src/actions/accounts/fetchBalance.ts
2254
+ import { formatUnits as formatUnits2, parseBytes32String as parseBytes32String2 } from "ethers/lib/utils.js";
2255
+
2256
+ // src/actions/contracts/fetchToken.ts
2257
+ import { formatUnits, parseBytes32String } from "ethers/lib/utils.js";
2258
+ async function fetchToken({
2259
+ address,
2260
+ chainId: chainId2,
2261
+ formatUnits: units2 = "ether"
2262
+ }) {
2263
+ async function fetchToken_({ abi }) {
2264
+ const erc20Config = { address, abi, chainId: chainId2 };
2265
+ const [decimals, name, symbol, totalSupply] = await readContracts({
2266
+ allowFailure: false,
2267
+ contracts: [
2268
+ { ...erc20Config, functionName: "decimals" },
2269
+ { ...erc20Config, functionName: "name" },
2270
+ { ...erc20Config, functionName: "symbol" },
2271
+ { ...erc20Config, functionName: "totalSupply" }
2272
+ ]
2273
+ });
2274
+ return {
2275
+ address,
2276
+ decimals,
2277
+ name,
2278
+ symbol,
2279
+ totalSupply: {
2280
+ formatted: formatUnits(totalSupply, units2),
2281
+ value: totalSupply
2282
+ }
2283
+ };
2284
+ }
2285
+ try {
2286
+ return await fetchToken_({ abi: erc20ABI });
2287
+ } catch (err) {
2288
+ if (err instanceof ContractResultDecodeError) {
2289
+ const { name, symbol, ...rest } = await fetchToken_({
2290
+ abi: erc20ABI_bytes32
2291
+ });
2292
+ return {
2293
+ name: parseBytes32String(name),
2294
+ symbol: parseBytes32String(symbol),
2295
+ ...rest
2296
+ };
2297
+ }
2298
+ throw err;
2299
+ }
2300
+ }
2301
+
2302
+ // src/actions/contracts/getContract.ts
2303
+ import {
2304
+ Contract as EthersContract
2305
+ } from "ethers";
2306
+ function getContract({
2307
+ address,
2308
+ abi,
2309
+ signerOrProvider
2310
+ }) {
2311
+ return new EthersContract(
2312
+ address,
2313
+ abi,
2314
+ signerOrProvider
2315
+ );
2316
+ }
2317
+
2318
+ // src/actions/contracts/prepareWriteContract.ts
2319
+ async function prepareWriteContract({
2320
+ abi,
2321
+ address,
2322
+ args,
2323
+ chainId: chainId2,
2324
+ functionName,
2325
+ overrides,
2326
+ signer: signer_
2327
+ }) {
2328
+ const signer = signer_ ?? await fetchSigner({ chainId: chainId2 });
2329
+ if (!signer)
2330
+ throw new ConnectorNotFoundError();
2331
+ if (chainId2)
2332
+ assertActiveChain({ chainId: chainId2, signer });
2333
+ const contract = getContract({
2334
+ address,
2335
+ abi,
2336
+ signerOrProvider: signer
2337
+ });
2338
+ const normalizedFunctionName = normalizeFunctionName({
2339
+ contract,
2340
+ functionName,
2341
+ args
2342
+ });
2343
+ const populateTransactionFn = contract.populateTransaction[normalizedFunctionName];
2344
+ if (!populateTransactionFn)
2345
+ throw new ContractMethodDoesNotExistError({
2346
+ address,
2347
+ functionName: normalizedFunctionName
2348
+ });
2349
+ const params = [...args ?? [], ...overrides ? [overrides] : []];
2350
+ const unsignedTransaction = await populateTransactionFn(
2351
+ ...params
2352
+ );
2353
+ const gasLimit = unsignedTransaction.gasLimit || await signer.estimateGas(unsignedTransaction);
2354
+ const minimizedAbi = minimizeContractInterface({
2355
+ abi,
2356
+ functionName
2357
+ });
2358
+ return {
2359
+ abi: minimizedAbi,
2360
+ address,
2361
+ chainId: chainId2,
2362
+ functionName,
2363
+ mode: "prepared",
2364
+ request: {
2365
+ ...unsignedTransaction,
2366
+ gasLimit
2367
+ }
2368
+ };
2369
+ }
2370
+
2371
+ // src/actions/providers/getProvider.ts
2372
+ function getProvider({
2373
+ chainId: chainId2
2374
+ } = {}) {
2375
+ const client2 = getClient();
2376
+ if (chainId2)
2377
+ return client2.getProvider({ chainId: chainId2 }) || client2.provider;
2378
+ return client2.provider;
2379
+ }
2380
+
2381
+ // src/actions/providers/getWebSocketProvider.ts
2382
+ function getWebSocketProvider({
2383
+ chainId: chainId2
2384
+ } = {}) {
2385
+ const client2 = getClient();
2386
+ if (chainId2)
2387
+ return client2.getWebSocketProvider({ chainId: chainId2 }) || client2.webSocketProvider;
2388
+ return client2.webSocketProvider;
2389
+ }
2390
+
2391
+ // src/actions/providers/watchProvider.ts
2392
+ function watchProvider(args, callback) {
2393
+ const client2 = getClient();
2394
+ const handleChange = async () => callback(getProvider(args));
2395
+ const unsubscribe = client2.subscribe(({ provider }) => provider, handleChange);
2396
+ return unsubscribe;
2397
+ }
2398
+
2399
+ // src/actions/providers/watchWebSocketProvider.ts
2400
+ function watchWebSocketProvider(args, callback) {
2401
+ const client2 = getClient();
2402
+ const handleChange = async () => callback(getWebSocketProvider(args));
2403
+ const unsubscribe = client2.subscribe(
2404
+ ({ webSocketProvider }) => webSocketProvider,
2405
+ handleChange
2406
+ );
2407
+ return unsubscribe;
2408
+ }
2409
+
2410
+ // src/actions/contracts/multicall.ts
2411
+ async function multicall({
2412
+ allowFailure = true,
2413
+ chainId: chainId2,
2414
+ contracts,
2415
+ overrides
2416
+ }) {
2417
+ const provider = getProvider({ chainId: chainId2 });
2418
+ if (!provider.chains)
2419
+ throw new ProviderChainsNotFound();
2420
+ const chain2 = provider.chains.find((chain3) => chain3.id === chainId2) || provider.chains[0];
2421
+ if (!chain2)
2422
+ throw new ProviderChainsNotFound();
2423
+ if (!chain2?.multicall)
2424
+ throw new ChainDoesNotSupportMulticallError({ chain: chain2 });
2425
+ if (typeof overrides?.blockTag === "number" && overrides?.blockTag < chain2.multicall.blockCreated)
2426
+ throw new ChainDoesNotSupportMulticallError({
2427
+ blockNumber: overrides?.blockTag,
2428
+ chain: chain2
2429
+ });
2430
+ const multicallContract = getContract({
2431
+ address: chain2.multicall.address,
2432
+ abi: multicallABI,
2433
+ signerOrProvider: provider
2434
+ });
2435
+ const calls = contracts.map(
2436
+ ({ address, abi, functionName, ...config }) => {
2437
+ const { args } = config || {};
2438
+ const contract = getContract({ address, abi });
2439
+ const params2 = args ?? [];
2440
+ const normalizedFunctionName = normalizeFunctionName({
2441
+ contract,
2442
+ functionName,
2443
+ args
2444
+ });
2445
+ try {
2446
+ const contractFunction = contract[normalizedFunctionName];
2447
+ if (!contractFunction)
2448
+ logWarn(
2449
+ `"${normalizedFunctionName}" is not in the interface for contract "${address}"`
2450
+ );
2451
+ const callData = contract.interface.encodeFunctionData(
2452
+ normalizedFunctionName,
2453
+ params2
2454
+ );
2455
+ return {
2456
+ target: address,
2457
+ allowFailure,
2458
+ callData
2459
+ };
2460
+ } catch (err) {
2461
+ if (!allowFailure)
2462
+ throw err;
2463
+ return {
2464
+ target: address,
2465
+ allowFailure,
2466
+ callData: "0x"
2467
+ };
2468
+ }
2469
+ }
2470
+ );
2471
+ const params = [...[calls], ...overrides ? [overrides] : []];
2472
+ const results = await multicallContract.aggregate3(
2473
+ ...params
2474
+ );
2475
+ return results.map(({ returnData, success }, i) => {
2476
+ const { address, abi, args, functionName } = contracts[i];
2477
+ const contract = getContract({
2478
+ address,
2479
+ abi
2480
+ });
2481
+ const normalizedFunctionName = normalizeFunctionName({
2482
+ contract,
2483
+ functionName,
2484
+ args
2485
+ });
2486
+ if (!success) {
2487
+ let error;
2488
+ try {
2489
+ contract.interface.decodeFunctionResult(
2490
+ normalizedFunctionName,
2491
+ returnData
2492
+ );
2493
+ } catch (err) {
2494
+ error = new ContractMethodRevertedError({
2495
+ address,
2496
+ args,
2497
+ chainId: chain2.id,
2498
+ functionName: normalizedFunctionName,
2499
+ errorMessage: err.message
2500
+ });
2501
+ if (!allowFailure)
2502
+ throw error;
2503
+ logWarn(error.message);
2504
+ }
2505
+ return null;
2506
+ }
2507
+ if (returnData === "0x") {
2508
+ const error = new ContractMethodNoResultError({
2509
+ address,
2510
+ args,
2511
+ chainId: chain2.id,
2512
+ functionName: normalizedFunctionName
2513
+ });
2514
+ if (!allowFailure)
2515
+ throw error;
2516
+ logWarn(error.message);
2517
+ return null;
2518
+ }
2519
+ try {
2520
+ const result = contract.interface.decodeFunctionResult(
2521
+ normalizedFunctionName,
2522
+ returnData
2523
+ );
2524
+ return Array.isArray(result) && result.length === 1 ? result[0] : result;
2525
+ } catch (err) {
2526
+ const error = new ContractResultDecodeError({
2527
+ address,
2528
+ args,
2529
+ chainId: chain2.id,
2530
+ functionName: normalizedFunctionName,
2531
+ errorMessage: err.message
2532
+ });
2533
+ if (!allowFailure)
2534
+ throw error;
2535
+ logWarn(error.message);
2536
+ return null;
2537
+ }
2538
+ });
2539
+ }
2540
+
2541
+ // src/actions/contracts/readContract.ts
2542
+ async function readContract({
2543
+ address,
2544
+ args,
2545
+ chainId: chainId2,
2546
+ abi,
2547
+ functionName,
2548
+ overrides
2549
+ }) {
2550
+ const provider = getProvider({ chainId: chainId2 });
2551
+ const contract = getContract({
2552
+ address,
2553
+ abi,
2554
+ signerOrProvider: provider
2555
+ });
2556
+ const normalizedFunctionName = normalizeFunctionName({
2557
+ contract,
2558
+ functionName,
2559
+ args
2560
+ });
2561
+ const contractFunction = contract[normalizedFunctionName];
2562
+ if (!contractFunction)
2563
+ throw new ContractMethodDoesNotExistError({
2564
+ address,
2565
+ functionName: normalizedFunctionName
2566
+ });
2567
+ const params = [...args ?? [], ...overrides ? [overrides] : []];
2568
+ return contractFunction?.(...params);
2569
+ }
2570
+
2571
+ // src/actions/contracts/readContracts.ts
2572
+ async function readContracts({
2573
+ allowFailure = true,
2574
+ contracts,
2575
+ overrides
2576
+ }) {
2577
+ try {
2578
+ const provider = getProvider();
2579
+ const contractsByChainId = contracts.reduce((contracts2, contract, index) => {
2580
+ const chainId2 = contract.chainId ?? provider.network.chainId;
2581
+ return {
2582
+ ...contracts2,
2583
+ [chainId2]: [...contracts2[chainId2] || [], { contract, index }]
2584
+ };
2585
+ }, {});
2586
+ const promises = () => Object.entries(contractsByChainId).map(
2587
+ ([chainId2, contracts2]) => multicall({
2588
+ allowFailure,
2589
+ chainId: parseInt(chainId2),
2590
+ contracts: contracts2.map(({ contract }) => contract),
2591
+ overrides
2592
+ })
2593
+ );
2594
+ let results;
2595
+ if (allowFailure) {
2596
+ results = (await Promise.allSettled(promises())).map((result) => {
2597
+ if (result.status === "fulfilled")
2598
+ return result.value;
2599
+ if (result.reason instanceof ChainDoesNotSupportMulticallError) {
2600
+ logWarn(result.reason.message);
2601
+ throw result.reason;
2602
+ }
2603
+ return null;
2604
+ }).flat();
2605
+ } else {
2606
+ results = (await Promise.all(promises())).flat();
2607
+ }
2608
+ const resultIndexes = Object.values(contractsByChainId).map((contracts2) => contracts2.map(({ index }) => index)).flat();
2609
+ return results.reduce((results2, result, index) => {
2610
+ results2[resultIndexes[index]] = result;
2611
+ return results2;
2612
+ }, []);
2613
+ } catch (err) {
2614
+ if (err instanceof ContractResultDecodeError)
2615
+ throw err;
2616
+ if (err instanceof ContractMethodNoResultError)
2617
+ throw err;
2618
+ if (err instanceof ContractMethodRevertedError)
2619
+ throw err;
2620
+ const promises = () => contracts.map(
2621
+ (contract) => readContract({ ...contract, overrides })
2622
+ );
2623
+ if (allowFailure)
2624
+ return (await Promise.allSettled(promises())).map((result, i) => {
2625
+ if (result.status === "fulfilled")
2626
+ return result.value;
2627
+ const { address, args, chainId: chainId2, functionName } = contracts[i];
2628
+ const error = new ContractMethodRevertedError({
2629
+ address,
2630
+ functionName,
2631
+ chainId: chainId2 ?? mainnet.id,
2632
+ args,
2633
+ errorMessage: result.reason
2634
+ });
2635
+ logWarn(error.message);
2636
+ return null;
2637
+ });
2638
+ return await Promise.all(promises());
2639
+ }
2640
+ }
2641
+
2642
+ // src/actions/contracts/watchContractEvent.ts
2643
+ import shallow from "zustand/shallow";
2644
+ function watchContractEvent({
2645
+ address,
2646
+ abi,
2647
+ chainId: chainId2,
2648
+ eventName,
2649
+ once
2650
+ }, callback) {
2651
+ const handler = (...event) => callback(...event);
2652
+ let contract;
2653
+ const watchEvent = async () => {
2654
+ if (contract)
2655
+ contract?.off(eventName, handler);
2656
+ const signerOrProvider = getWebSocketProvider({ chainId: chainId2 }) || getProvider({ chainId: chainId2 });
2657
+ contract = getContract({
2658
+ address,
2659
+ abi,
2660
+ signerOrProvider
2661
+ });
2662
+ if (once)
2663
+ contract.once(eventName, handler);
2664
+ else
2665
+ contract.on(eventName, handler);
2666
+ };
2667
+ watchEvent();
2668
+ const client2 = getClient();
2669
+ const unsubscribe = client2.subscribe(
2670
+ ({ provider, webSocketProvider }) => ({
2671
+ provider,
2672
+ webSocketProvider
2673
+ }),
2674
+ watchEvent,
2675
+ { equalityFn: shallow }
2676
+ );
2677
+ return () => {
2678
+ contract?.off(eventName, handler);
2679
+ unsubscribe();
2680
+ };
2681
+ }
2682
+
2683
+ // src/actions/network-status/watchBlockNumber.ts
2684
+ import shallow2 from "zustand/shallow";
2685
+
2686
+ // src/actions/network-status/fetchBlockNumber.ts
2687
+ async function fetchBlockNumber({
2688
+ chainId: chainId2
2689
+ } = {}) {
2690
+ const provider = getProvider({ chainId: chainId2 });
2691
+ const blockNumber = await provider.getBlockNumber();
2692
+ return blockNumber;
2693
+ }
2694
+
2695
+ // src/actions/network-status/watchBlockNumber.ts
2696
+ function watchBlockNumber(args, callback) {
2697
+ const debouncedCallback = debounce(callback, 1);
2698
+ let previousProvider;
2699
+ const createListener = (provider) => {
2700
+ if (previousProvider) {
2701
+ previousProvider?.off("block", debouncedCallback);
2702
+ }
2703
+ provider.on("block", debouncedCallback);
2704
+ previousProvider = provider;
2705
+ };
2706
+ const provider_ = getWebSocketProvider({ chainId: args.chainId }) ?? getProvider({ chainId: args.chainId });
2707
+ if (args.listen)
2708
+ createListener(provider_);
2709
+ let active = true;
2710
+ const client2 = getClient();
2711
+ const unsubscribe = client2.subscribe(
2712
+ ({ provider, webSocketProvider }) => ({ provider, webSocketProvider }),
2713
+ async ({ provider, webSocketProvider }) => {
2714
+ const provider_2 = webSocketProvider ?? provider;
2715
+ if (args.listen && !args.chainId && provider_2) {
2716
+ createListener(provider_2);
2717
+ }
2718
+ const blockNumber = await fetchBlockNumber({ chainId: args.chainId });
2719
+ if (!active)
2720
+ return;
2721
+ callback(blockNumber);
2722
+ },
2723
+ {
2724
+ equalityFn: shallow2
2725
+ }
2726
+ );
2727
+ return () => {
2728
+ active = false;
2729
+ unsubscribe();
2730
+ provider_?.off("block", debouncedCallback);
2731
+ previousProvider?.off("block", debouncedCallback);
2732
+ };
2733
+ }
2734
+
2735
+ // src/actions/contracts/watchMulticall.ts
2736
+ function watchMulticall(config, callback) {
2737
+ const client2 = getClient();
2738
+ const handleChange = async () => callback(await multicall(config));
2739
+ const unwatch = config.listenToBlock ? watchBlockNumber({ listen: true }, handleChange) : void 0;
2740
+ const unsubscribe = client2.subscribe(({ provider }) => provider, handleChange);
2741
+ return () => {
2742
+ unsubscribe();
2743
+ unwatch?.();
2744
+ };
2745
+ }
2746
+
2747
+ // src/actions/contracts/watchReadContract.ts
2748
+ function watchReadContract(config, callback) {
2749
+ const client2 = getClient();
2750
+ const handleChange = async () => callback(await readContract(config));
2751
+ const unwatch = config.listenToBlock ? watchBlockNumber({ listen: true }, handleChange) : void 0;
2752
+ const unsubscribe = client2.subscribe(({ provider }) => provider, handleChange);
2753
+ return () => {
2754
+ unsubscribe();
2755
+ unwatch?.();
2756
+ };
2757
+ }
2758
+
2759
+ // src/actions/contracts/watchReadContracts.ts
2760
+ function watchReadContracts(config, callback) {
2761
+ const client2 = getClient();
2762
+ const handleChange = async () => callback(await readContracts(config));
2763
+ const unwatch = config.listenToBlock ? watchBlockNumber({ listen: true }, handleChange) : void 0;
2764
+ const unsubscribe = client2.subscribe(({ provider }) => provider, handleChange);
2765
+ return () => {
2766
+ unsubscribe();
2767
+ unwatch?.();
2768
+ };
2769
+ }
2770
+
2771
+ // src/actions/transactions/fetchTransaction.ts
2772
+ async function fetchTransaction({
2773
+ chainId: chainId2,
2774
+ hash
2775
+ }) {
2776
+ const provider = getProvider({ chainId: chainId2 });
2777
+ return provider.getTransaction(hash);
2778
+ }
2779
+
2780
+ // src/actions/transactions/prepareSendTransaction.ts
2781
+ import { isAddress as isAddress2 } from "ethers/lib/utils.js";
2782
+
2783
+ // src/actions/ens/fetchEnsAddress.ts
2784
+ import { getAddress as getAddress2 } from "ethers/lib/utils.js";
2785
+ async function fetchEnsAddress({
2786
+ chainId: chainId2,
2787
+ name
2788
+ }) {
2789
+ const provider = getProvider({ chainId: chainId2 });
2790
+ const address = await provider.resolveName(name);
2791
+ try {
2792
+ return address ? getAddress2(address) : null;
2793
+ } catch (_error) {
2794
+ return null;
2795
+ }
2796
+ }
2797
+
2798
+ // src/actions/ens/fetchEnsAvatar.ts
2799
+ async function fetchEnsAvatar({
2800
+ address,
2801
+ chainId: chainId2
2802
+ }) {
2803
+ const provider = getProvider({ chainId: chainId2 });
2804
+ const avatar = await provider.getAvatar(address);
2805
+ return avatar;
2806
+ }
2807
+
2808
+ // src/actions/ens/fetchEnsName.ts
2809
+ import { getAddress as getAddress3 } from "ethers/lib/utils";
2810
+ async function fetchEnsName({
2811
+ address,
2812
+ chainId: chainId2
2813
+ }) {
2814
+ const provider = getProvider({ chainId: chainId2 });
2815
+ return provider.lookupAddress(getAddress3(address));
2816
+ }
2817
+
2818
+ // src/actions/ens/fetchEnsResolver.ts
2819
+ async function fetchEnsResolver({
2820
+ chainId: chainId2,
2821
+ name
2822
+ }) {
2823
+ const provider = getProvider({ chainId: chainId2 });
2824
+ const resolver = await provider.getResolver(name);
2825
+ return resolver;
2826
+ }
2827
+
2828
+ // src/actions/transactions/prepareSendTransaction.ts
2829
+ async function prepareSendTransaction({
2830
+ chainId: chainId2,
2831
+ request,
2832
+ signer: signer_
2833
+ }) {
2834
+ const signer = signer_ ?? await fetchSigner({ chainId: chainId2 });
2835
+ if (!signer)
2836
+ throw new ConnectorNotFoundError();
2837
+ if (chainId2)
2838
+ assertActiveChain({ chainId: chainId2, signer });
2839
+ const [to, gasLimit] = await Promise.all([
2840
+ isAddress2(request.to) ? Promise.resolve(request.to) : fetchEnsAddress({ name: request.to }),
2841
+ request.gasLimit ? Promise.resolve(request.gasLimit) : signer.estimateGas(request)
2842
+ ]);
2843
+ if (!to)
2844
+ throw new Error("Could not resolve ENS name");
2845
+ return {
2846
+ ...chainId2 ? { chainId: chainId2 } : {},
2847
+ request: { ...request, gasLimit, to },
2848
+ mode: "prepared"
2849
+ };
2850
+ }
2851
+
2852
+ // src/actions/transactions/sendTransaction.ts
2853
+ async function sendTransaction({
2854
+ chainId: chainId2,
2855
+ mode,
2856
+ request
2857
+ }) {
2858
+ const signer = await fetchSigner();
2859
+ if (!signer)
2860
+ throw new ConnectorNotFoundError();
2861
+ if (mode === "prepared") {
2862
+ if (!request.gasLimit)
2863
+ throw new Error("`gasLimit` is required");
2864
+ if (!request.to)
2865
+ throw new Error("`to` is required");
2866
+ }
2867
+ if (chainId2)
2868
+ assertActiveChain({ chainId: chainId2, signer });
2869
+ try {
2870
+ const uncheckedSigner = signer.connectUnchecked?.();
2871
+ const { hash, wait } = await (uncheckedSigner ?? signer).sendTransaction(
2872
+ request
2873
+ );
2874
+ return { hash, wait };
2875
+ } catch (error) {
2876
+ if (error.code === 4001)
2877
+ throw new UserRejectedRequestError(error);
2878
+ throw error;
2879
+ }
2880
+ }
2881
+
2882
+ // src/actions/transactions/waitForTransaction.ts
2883
+ async function waitForTransaction({
2884
+ chainId: chainId2,
2885
+ confirmations,
2886
+ hash,
2887
+ timeout,
2888
+ wait: wait_
2889
+ }) {
2890
+ let promise;
2891
+ if (hash) {
2892
+ const provider = getProvider({ chainId: chainId2 });
2893
+ promise = provider.waitForTransaction(hash, confirmations, timeout);
2894
+ } else if (wait_)
2895
+ promise = wait_(confirmations);
2896
+ else
2897
+ throw new Error("hash or wait is required");
2898
+ return promise;
2899
+ }
2900
+
2901
+ // src/actions/contracts/writeContract.ts
2902
+ async function writeContract({
2903
+ address,
2904
+ args,
2905
+ chainId: chainId2,
2906
+ abi,
2907
+ functionName,
2908
+ mode,
2909
+ overrides,
2910
+ request: request_
2911
+ }) {
2912
+ const signer = await fetchSigner();
2913
+ if (!signer)
2914
+ throw new ConnectorNotFoundError();
2915
+ if (chainId2)
2916
+ assertActiveChain({ chainId: chainId2, signer });
2917
+ if (mode === "prepared") {
2918
+ if (!request_)
2919
+ throw new Error("`request` is required");
2920
+ }
2921
+ const request = mode === "recklesslyUnprepared" ? (await prepareWriteContract({
2922
+ address,
2923
+ args,
2924
+ chainId: chainId2,
2925
+ abi,
2926
+ functionName,
2927
+ overrides
2928
+ })).request : request_;
2929
+ const transaction = await sendTransaction({
2930
+ request,
2931
+ mode: "prepared"
2932
+ });
2933
+ return transaction;
2934
+ }
2935
+
2936
+ // src/actions/accounts/fetchBalance.ts
2937
+ async function fetchBalance({
2938
+ address,
2939
+ chainId: chainId2,
2940
+ formatUnits: unit,
2941
+ token
2942
+ }) {
2943
+ const client2 = getClient();
2944
+ const provider = getProvider({ chainId: chainId2 });
2945
+ if (token) {
2946
+ const fetchContractBalance = async ({ abi }) => {
2947
+ const erc20Config = { abi, address: token, chainId: chainId2 };
2948
+ const [value2, decimals, symbol] = await readContracts({
2949
+ allowFailure: false,
2950
+ contracts: [
2951
+ {
2952
+ ...erc20Config,
2953
+ functionName: "balanceOf",
2954
+ args: [address]
2955
+ },
2956
+ { ...erc20Config, functionName: "decimals" },
2957
+ { ...erc20Config, functionName: "symbol" }
2958
+ ]
2959
+ });
2960
+ return {
2961
+ decimals,
2962
+ formatted: formatUnits2(value2 ?? "0", unit ?? decimals),
2963
+ symbol,
2964
+ value: value2
2965
+ };
2966
+ };
2967
+ try {
2968
+ return await fetchContractBalance({ abi: erc20ABI });
2969
+ } catch (err) {
2970
+ if (err instanceof ContractResultDecodeError) {
2971
+ const { symbol, ...rest } = await fetchContractBalance({
2972
+ abi: erc20ABI_bytes32
2973
+ });
2974
+ return {
2975
+ symbol: parseBytes32String2(symbol),
2976
+ ...rest
2977
+ };
2978
+ }
2979
+ throw err;
2980
+ }
2981
+ }
2982
+ const chains = [...client2.provider.chains || [], ...client2.chains ?? []];
2983
+ const value = await provider.getBalance(address);
2984
+ const chain2 = chains.find((x) => x.id === provider.network.chainId);
2985
+ return {
2986
+ decimals: chain2?.nativeCurrency?.decimals ?? 18,
2987
+ formatted: formatUnits2(value ?? "0", unit ?? "ether"),
2988
+ symbol: chain2?.nativeCurrency?.symbol ?? "ETH",
2989
+ value
2990
+ };
2991
+ }
2992
+
2993
+ // src/actions/accounts/fetchSigner.ts
2994
+ async function fetchSigner({
2995
+ chainId: chainId2
2996
+ } = {}) {
2997
+ const client2 = getClient();
2998
+ const signer = await client2.connector?.getSigner?.({ chainId: chainId2 }) || null;
2999
+ return signer;
3000
+ }
3001
+
3002
+ // src/actions/accounts/getAccount.ts
3003
+ function getAccount() {
3004
+ const { data, connector, status } = getClient();
3005
+ switch (status) {
3006
+ case "connected":
3007
+ return {
3008
+ address: data?.account,
3009
+ connector,
3010
+ isConnected: true,
3011
+ isConnecting: false,
3012
+ isDisconnected: false,
3013
+ isReconnecting: false,
3014
+ status
3015
+ };
3016
+ case "reconnecting":
3017
+ return {
3018
+ address: data?.account,
3019
+ connector,
3020
+ isConnected: !!data?.account,
3021
+ isConnecting: false,
3022
+ isDisconnected: false,
3023
+ isReconnecting: true,
3024
+ status
3025
+ };
3026
+ case "connecting":
3027
+ return {
3028
+ address: void 0,
3029
+ connector: void 0,
3030
+ isConnected: false,
3031
+ isConnecting: true,
3032
+ isDisconnected: false,
3033
+ isReconnecting: false,
3034
+ status
3035
+ };
3036
+ case "disconnected":
3037
+ return {
3038
+ address: void 0,
3039
+ connector: void 0,
3040
+ isConnected: false,
3041
+ isConnecting: false,
3042
+ isDisconnected: true,
3043
+ isReconnecting: false,
3044
+ status
3045
+ };
3046
+ }
3047
+ }
3048
+
3049
+ // src/actions/accounts/getNetwork.ts
3050
+ function getNetwork() {
3051
+ const client2 = getClient();
3052
+ const chainId2 = client2.data?.chain?.id;
3053
+ const activeChains = client2.chains ?? [];
3054
+ const activeChain = [...client2.provider.chains || [], ...activeChains].find(
3055
+ (x) => x.id === chainId2
3056
+ ) ?? {
3057
+ id: chainId2,
3058
+ name: `Chain ${chainId2}`,
3059
+ network: `${chainId2}`,
3060
+ rpcUrls: { default: "" }
3061
+ };
3062
+ return {
3063
+ chain: chainId2 ? {
3064
+ ...activeChain,
3065
+ ...client2.data?.chain,
3066
+ id: chainId2
3067
+ } : void 0,
3068
+ chains: activeChains
3069
+ };
3070
+ }
3071
+
3072
+ // src/actions/accounts/signMessage.ts
3073
+ async function signMessage(args) {
3074
+ try {
3075
+ const signer = await fetchSigner();
3076
+ if (!signer)
3077
+ throw new ConnectorNotFoundError();
3078
+ return await signer.signMessage(
3079
+ args.message
3080
+ );
3081
+ } catch (error) {
3082
+ if (error.code === 4001)
3083
+ throw new UserRejectedRequestError(error);
3084
+ throw error;
3085
+ }
3086
+ }
3087
+
3088
+ // src/actions/accounts/signTypedData.ts
3089
+ async function signTypedData({
3090
+ domain,
3091
+ types,
3092
+ value
3093
+ }) {
3094
+ const signer = await fetchSigner();
3095
+ if (!signer)
3096
+ throw new ConnectorNotFoundError();
3097
+ const { chainId: chainId_ } = domain;
3098
+ const chainId2 = chainId_ ? normalizeChainId(chainId_) : void 0;
3099
+ if (chainId2)
3100
+ assertActiveChain({ chainId: chainId2, signer });
3101
+ return signer._signTypedData(
3102
+ domain,
3103
+ types,
3104
+ value
3105
+ );
3106
+ }
3107
+
3108
+ // src/actions/accounts/switchNetwork.ts
3109
+ async function switchNetwork({
3110
+ chainId: chainId2
3111
+ }) {
3112
+ const { connector } = getClient();
3113
+ if (!connector)
3114
+ throw new ConnectorNotFoundError();
3115
+ if (!connector.switchChain)
3116
+ throw new SwitchChainNotSupportedError({
3117
+ connector
3118
+ });
3119
+ return connector.switchChain(chainId2);
3120
+ }
3121
+
3122
+ // src/actions/accounts/watchAccount.ts
3123
+ import shallow3 from "zustand/shallow";
3124
+ function watchAccount(callback, { selector = (x) => x } = {}) {
3125
+ const client2 = getClient();
3126
+ const handleChange = () => callback(getAccount());
3127
+ const unsubscribe = client2.subscribe(
3128
+ ({ data, connector, status }) => selector({
3129
+ address: data?.account,
3130
+ connector,
3131
+ status
3132
+ }),
3133
+ handleChange,
3134
+ {
3135
+ equalityFn: shallow3
3136
+ }
3137
+ );
3138
+ return unsubscribe;
3139
+ }
3140
+
3141
+ // src/actions/accounts/watchNetwork.ts
3142
+ import shallow4 from "zustand/shallow";
3143
+ function watchNetwork(callback, { selector = (x) => x } = {}) {
3144
+ const client2 = getClient();
3145
+ const handleChange = () => callback(getNetwork());
3146
+ const unsubscribe = client2.subscribe(
3147
+ ({ data, chains }) => selector({ chainId: data?.chain?.id, chains }),
3148
+ handleChange,
3149
+ {
3150
+ equalityFn: shallow4
3151
+ }
3152
+ );
3153
+ return unsubscribe;
3154
+ }
3155
+
3156
+ // src/actions/accounts/watchSigner.ts
3157
+ import shallow5 from "zustand/shallow";
3158
+ function watchSigner({ chainId: chainId2 }, callback) {
3159
+ const client2 = getClient();
3160
+ const handleChange = async () => callback(await fetchSigner({ chainId: chainId2 }));
3161
+ const unsubscribe = client2.subscribe(
3162
+ ({ data, connector }) => ({
3163
+ account: data?.account,
3164
+ chainId: data?.chain?.id,
3165
+ connector
3166
+ }),
3167
+ handleChange,
3168
+ {
3169
+ equalityFn: shallow5
3170
+ }
3171
+ );
3172
+ return unsubscribe;
3173
+ }
3174
+
3175
+ // src/actions/network-status/fetchFeeData.ts
3176
+ import { formatUnits as formatUnits3 } from "ethers/lib/utils.js";
3177
+ async function fetchFeeData({
3178
+ chainId: chainId2,
3179
+ formatUnits: units2 = "wei"
3180
+ } = {}) {
3181
+ const provider = getProvider({ chainId: chainId2 });
3182
+ const feeData = await provider.getFeeData();
3183
+ const formatted = {
3184
+ gasPrice: feeData.gasPrice ? formatUnits3(feeData.gasPrice, units2) : null,
3185
+ maxFeePerGas: feeData.maxFeePerGas ? formatUnits3(feeData.maxFeePerGas, units2) : null,
3186
+ maxPriorityFeePerGas: feeData.maxPriorityFeePerGas ? formatUnits3(feeData.maxPriorityFeePerGas, units2) : null
3187
+ };
3188
+ return { ...feeData, formatted };
3189
+ }
3190
+
3191
+ // src/errors.ts
3192
+ var RpcError2 = class extends Error {
3193
+ constructor(code, message, internal, data) {
3194
+ if (!Number.isInteger(code))
3195
+ throw new Error('"code" must be an integer.');
3196
+ if (!message || typeof message !== "string")
3197
+ throw new Error('"message" must be a nonempty string.');
3198
+ super(message);
3199
+ this.code = code;
3200
+ this.data = data;
3201
+ this.internal = internal;
3202
+ }
3203
+ };
3204
+ var ProviderRpcError4 = class extends RpcError2 {
3205
+ constructor(code, message, internal, data) {
3206
+ if (!(Number.isInteger(code) && code >= 1e3 && code <= 4999))
3207
+ throw new Error(
3208
+ '"code" must be an integer such that: 1000 <= code <= 4999'
3209
+ );
3210
+ super(code, message, internal, data);
3211
+ }
3212
+ };
3213
+ var AddChainError = class extends Error {
3214
+ constructor() {
3215
+ super(...arguments);
3216
+ this.name = "AddChainError";
3217
+ this.message = "Error adding chain";
3218
+ }
3219
+ };
3220
+ var ChainDoesNotSupportMulticallError = class extends Error {
3221
+ constructor({ blockNumber, chain: chain2 }) {
3222
+ super(
3223
+ `Chain "${chain2.name}" does not support multicall${blockNumber ? ` on block ${blockNumber}` : ""}.`
3224
+ );
3225
+ this.name = "ChainDoesNotSupportMulticall";
3226
+ }
3227
+ };
3228
+ var ChainMismatchError = class extends Error {
3229
+ constructor({
3230
+ activeChain,
3231
+ targetChain
3232
+ }) {
3233
+ super(
3234
+ `Chain mismatch: Expected "${targetChain}", received "${activeChain}".`
3235
+ );
3236
+ this.name = "ChainMismatchError";
3237
+ }
3238
+ };
3239
+ var ChainNotConfiguredError = class extends Error {
3240
+ constructor({
3241
+ chainId: chainId2,
3242
+ connectorId
3243
+ }) {
3244
+ super(`Chain "${chainId2}" not configured for connector "${connectorId}".`);
3245
+ this.name = "ChainNotConfigured";
3246
+ }
3247
+ };
3248
+ var ConnectorAlreadyConnectedError = class extends Error {
3249
+ constructor() {
3250
+ super(...arguments);
3251
+ this.name = "ConnectorAlreadyConnectedError";
3252
+ this.message = "Connector already connected";
3253
+ }
3254
+ };
3255
+ var ConnectorNotFoundError = class extends Error {
3256
+ constructor() {
3257
+ super(...arguments);
3258
+ this.name = "ConnectorNotFoundError";
3259
+ this.message = "Connector not found";
3260
+ }
3261
+ };
3262
+ var ContractMethodDoesNotExistError = class extends Error {
3263
+ constructor({
3264
+ address,
3265
+ chainId: chainId2,
3266
+ functionName
3267
+ }) {
3268
+ const { chains, network } = getProvider();
3269
+ const chain2 = chains?.find(({ id }) => id === (chainId2 || network.chainId));
3270
+ const blockExplorer = chain2?.blockExplorers?.default;
3271
+ super(
3272
+ [
3273
+ `Function "${functionName}" on contract "${address}" does not exist.`,
3274
+ ...blockExplorer ? [
3275
+ "",
3276
+ `${blockExplorer?.name}: ${blockExplorer?.url}/address/${address}#readContract`
3277
+ ] : []
3278
+ ].join("\n")
3279
+ );
3280
+ this.name = "ContractMethodDoesNotExistError";
3281
+ }
3282
+ };
3283
+ var ContractMethodNoResultError = class extends Error {
3284
+ constructor({
3285
+ address,
3286
+ args,
3287
+ chainId: chainId2,
3288
+ functionName
3289
+ }) {
3290
+ super(
3291
+ [
3292
+ "Contract read returned an empty response. This could be due to any of the following:",
3293
+ `- The contract does not have the function "${functionName}",`,
3294
+ "- The parameters passed to the contract function may be invalid, or",
3295
+ "- The address is not a contract.",
3296
+ "",
3297
+ `Config:`,
3298
+ JSON.stringify(
3299
+ {
3300
+ address,
3301
+ abi: "...",
3302
+ functionName,
3303
+ chainId: chainId2,
3304
+ args
3305
+ },
3306
+ null,
3307
+ 2
3308
+ )
3309
+ ].join("\n")
3310
+ );
3311
+ this.name = "ContractMethodNoResultError";
3312
+ }
3313
+ };
3314
+ var ContractMethodRevertedError = class extends Error {
3315
+ constructor({
3316
+ address,
3317
+ args,
3318
+ chainId: chainId2,
3319
+ functionName,
3320
+ errorMessage
3321
+ }) {
3322
+ super(
3323
+ [
3324
+ "Contract method reverted with an error.",
3325
+ "",
3326
+ `Config:`,
3327
+ JSON.stringify(
3328
+ {
3329
+ address,
3330
+ abi: "...",
3331
+ functionName,
3332
+ chainId: chainId2,
3333
+ args
3334
+ },
3335
+ null,
3336
+ 2
3337
+ ),
3338
+ "",
3339
+ `Details: ${errorMessage}`
3340
+ ].join("\n")
3341
+ );
3342
+ this.name = "ContractMethodRevertedError";
3343
+ }
3344
+ };
3345
+ var ContractResultDecodeError = class extends Error {
3346
+ constructor({
3347
+ address,
3348
+ args,
3349
+ chainId: chainId2,
3350
+ functionName,
3351
+ errorMessage
3352
+ }) {
3353
+ super(
3354
+ [
3355
+ "Failed to decode contract function result.",
3356
+ "",
3357
+ `Config:`,
3358
+ JSON.stringify(
3359
+ {
3360
+ address,
3361
+ abi: "...",
3362
+ functionName,
3363
+ chainId: chainId2,
3364
+ args
3365
+ },
3366
+ null,
3367
+ 2
3368
+ ),
3369
+ "",
3370
+ `Details: ${errorMessage}`
3371
+ ].join("\n")
3372
+ );
3373
+ this.name = "ContractResultDecodeError";
3374
+ }
3375
+ };
3376
+ var ProviderChainsNotFound = class extends Error {
3377
+ constructor() {
3378
+ super(...arguments);
3379
+ this.name = "ProviderChainsNotFound";
3380
+ this.message = [
3381
+ "No chains were found on the wagmi provider. Some functions that require a chain may not work.",
3382
+ "",
3383
+ "It is recommended to add a list of chains to the provider in `createClient`.",
3384
+ "",
3385
+ "Example:",
3386
+ "",
3387
+ "```",
3388
+ "import { getDefaultProvider } from 'ethers'",
3389
+ "import { chain, createClient } from 'wagmi'",
3390
+ "",
3391
+ "createClient({",
3392
+ " provider: Object.assign(getDefaultProvider(), { chains: [chain.mainnet] })",
3393
+ "})",
3394
+ "```"
3395
+ ].join("\n");
3396
+ }
3397
+ };
3398
+ var ResourceUnavailableError = class extends RpcError2 {
3399
+ constructor(error) {
3400
+ super(-32002, "Resource unavailable", error);
3401
+ this.name = "ResourceUnavailable";
3402
+ }
3403
+ };
3404
+ var SwitchChainError = class extends ProviderRpcError4 {
3405
+ constructor(error) {
3406
+ super(4902, "Error switching chain", error);
3407
+ this.name = "SwitchChainError";
3408
+ }
3409
+ };
3410
+ var SwitchChainNotSupportedError = class extends Error {
3411
+ constructor({ connector }) {
3412
+ super(`"${connector.name}" does not support programmatic chain switching.`);
3413
+ this.name = "SwitchChainNotSupportedError";
3414
+ }
3415
+ };
3416
+ var UserRejectedRequestError = class extends ProviderRpcError4 {
3417
+ constructor(error) {
3418
+ super(4001, "User rejected request", error);
3419
+ this.name = "UserRejectedRequestError";
3420
+ }
3421
+ };
3422
+
3423
+ export {
3424
+ RpcError2 as RpcError,
3425
+ ProviderRpcError4 as ProviderRpcError,
3426
+ AddChainError,
3427
+ ChainDoesNotSupportMulticallError,
3428
+ ChainMismatchError,
3429
+ ChainNotConfiguredError,
3430
+ ConnectorAlreadyConnectedError,
3431
+ ConnectorNotFoundError,
3432
+ ContractMethodDoesNotExistError,
3433
+ ContractMethodNoResultError,
3434
+ ContractMethodRevertedError,
3435
+ ContractResultDecodeError,
3436
+ ProviderChainsNotFound,
3437
+ ResourceUnavailableError,
3438
+ SwitchChainError,
3439
+ SwitchChainNotSupportedError,
3440
+ UserRejectedRequestError,
3441
+ configureChains,
3442
+ debounce,
3443
+ deepEqual,
3444
+ minimizeContractInterface,
3445
+ normalizeChainId,
3446
+ parseContractResult,
3447
+ erc20ABI,
3448
+ erc721ABI,
3449
+ erc4626ABI,
3450
+ units,
3451
+ Connector,
3452
+ InjectedConnector,
3453
+ noopStorage,
3454
+ createStorage,
3455
+ Client,
3456
+ createClient,
3457
+ getClient,
3458
+ connect,
3459
+ disconnect,
3460
+ fetchToken,
3461
+ getContract,
3462
+ prepareWriteContract,
3463
+ getProvider,
3464
+ getWebSocketProvider,
3465
+ watchProvider,
3466
+ watchWebSocketProvider,
3467
+ multicall,
3468
+ readContract,
3469
+ readContracts,
3470
+ watchContractEvent,
3471
+ fetchBlockNumber,
3472
+ watchBlockNumber,
3473
+ watchMulticall,
3474
+ watchReadContract,
3475
+ watchReadContracts,
3476
+ fetchTransaction,
3477
+ fetchEnsAddress,
3478
+ fetchEnsAvatar,
3479
+ fetchEnsName,
3480
+ fetchEnsResolver,
3481
+ prepareSendTransaction,
3482
+ sendTransaction,
3483
+ waitForTransaction,
3484
+ writeContract,
3485
+ fetchBalance,
3486
+ fetchSigner,
3487
+ getAccount,
3488
+ getNetwork,
3489
+ signMessage,
3490
+ signTypedData,
3491
+ switchNetwork,
3492
+ watchAccount,
3493
+ watchNetwork,
3494
+ watchSigner,
3495
+ fetchFeeData
3496
+ };