@wagmi/core 0.5.3 → 0.5.6

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 (47) hide show
  1. package/chains/dist/wagmi-core-chains.cjs.dev.js +3 -2
  2. package/chains/dist/wagmi-core-chains.cjs.prod.js +3 -2
  3. package/chains/dist/wagmi-core-chains.esm.js +2 -2
  4. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +3 -3
  5. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +3 -3
  6. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +3 -3
  7. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.dev.js +3 -3
  8. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.prod.js +3 -3
  9. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.esm.js +3 -3
  10. package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.dev.js +3 -3
  11. package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.prod.js +3 -3
  12. package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +3 -3
  13. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.dev.js +3 -3
  14. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.prod.js +3 -3
  15. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +3 -3
  16. package/dist/{chains-3916cd7d.cjs.prod.js → chains-4fdb21bc.cjs.dev.js} +32 -2
  17. package/dist/{chains-bd8ad853.cjs.dev.js → chains-868f0ac6.cjs.prod.js} +32 -2
  18. package/dist/{chains-505e1070.esm.js → chains-a22bcfea.esm.js} +32 -3
  19. package/dist/declarations/src/actions/contracts/prepareWriteContract.d.ts +1 -1
  20. package/dist/declarations/src/chains.d.ts +1 -1
  21. package/dist/declarations/src/client.d.ts +5 -1
  22. package/dist/declarations/src/constants/blockExplorers.d.ts +1 -1
  23. package/dist/declarations/src/constants/chains.d.ts +3 -0
  24. package/dist/declarations/src/constants/rpcs.d.ts +1 -1
  25. package/dist/declarations/src/errors.d.ts +23 -2
  26. package/dist/declarations/src/index.d.ts +2 -2
  27. package/dist/declarations/src/types/index.d.ts +2 -0
  28. package/dist/declarations/src/utils/index.d.ts +2 -1
  29. package/dist/declarations/src/utils/logger.d.ts +1 -0
  30. package/dist/declarations/src/utils/minimizeContractInterface.d.ts +5 -0
  31. package/dist/{getProvider-a1ad435d.cjs.prod.js → getProvider-3a26f086.cjs.dev.js} +61 -17
  32. package/dist/{getProvider-e3d84eba.esm.js → getProvider-a3c8cf52.esm.js} +60 -18
  33. package/dist/{getProvider-e2217cb6.cjs.dev.js → getProvider-b220fed1.cjs.prod.js} +61 -17
  34. package/dist/{rpcs-3cf5a783.cjs.dev.js → rpcs-3326627e.cjs.dev.js} +1 -0
  35. package/dist/{rpcs-afd1cc09.cjs.prod.js → rpcs-45537550.cjs.prod.js} +1 -0
  36. package/dist/{rpcs-e837abf2.esm.js → rpcs-6e1b1718.esm.js} +1 -0
  37. package/dist/wagmi-core.cjs.dev.js +117 -35
  38. package/dist/wagmi-core.cjs.prod.js +117 -35
  39. package/dist/wagmi-core.esm.js +115 -35
  40. package/package.json +2 -2
  41. package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.dev.js +1 -1
  42. package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.prod.js +1 -1
  43. package/providers/alchemy/dist/wagmi-core-providers-alchemy.esm.js +1 -1
  44. package/providers/infura/dist/wagmi-core-providers-infura.cjs.dev.js +1 -1
  45. package/providers/infura/dist/wagmi-core-providers-infura.cjs.prod.js +1 -1
  46. package/providers/infura/dist/wagmi-core-providers-infura.esm.js +1 -1
  47. package/dist/declarations/src/utils/warn.d.ts +0 -1
@@ -1,11 +1,12 @@
1
- import { g as getClient, C as ConnectorAlreadyConnectedError, a as ConnectorNotFoundError, b as ChainMismatchError, U as UserRejectedRequestError, c as ContractMethodDoesNotExistError, d as getProvider, P as ProviderChainsNotFound, e as ChainDoesNotSupportMulticallError, f as ContractMethodNoResultError, n as normalizeChainId, S as SwitchChainNotSupportedError } from './getProvider-e3d84eba.esm.js';
2
- export { A as AddChainError, e as ChainDoesNotSupportMulticallError, b as ChainMismatchError, k as ChainNotConfiguredError, i as Client, j as Connector, C as ConnectorAlreadyConnectedError, a as ConnectorNotFoundError, c as ContractMethodDoesNotExistError, f as ContractMethodNoResultError, I as InjectedConnector, P as ProviderChainsNotFound, l as ProviderRpcError, R as ResourceUnavailableError, m as RpcError, o as SwitchChainError, S as SwitchChainNotSupportedError, U as UserRejectedRequestError, h as createClient, p as createStorage, d as getProvider, q as noopStorage, n as normalizeChainId } from './getProvider-e3d84eba.esm.js';
1
+ import { g as getClient, C as ConnectorAlreadyConnectedError, a as ConnectorNotFoundError, b as ChainMismatchError, U as UserRejectedRequestError, c as ContractMethodDoesNotExistError, d as getProvider, P as ProviderChainsNotFound, e as ChainDoesNotSupportMulticallError, f as ContractMethodRevertedError, h as ContractMethodNoResultError, i as ContractResultDecodeError, n as normalizeChainId, S as SwitchChainNotSupportedError } from './getProvider-a3c8cf52.esm.js';
2
+ export { A as AddChainError, e as ChainDoesNotSupportMulticallError, b as ChainMismatchError, m as ChainNotConfiguredError, k as Client, l as Connector, C as ConnectorAlreadyConnectedError, a as ConnectorNotFoundError, c as ContractMethodDoesNotExistError, h as ContractMethodNoResultError, f as ContractMethodRevertedError, i as ContractResultDecodeError, I as InjectedConnector, P as ProviderChainsNotFound, o as ProviderRpcError, R as ResourceUnavailableError, p as RpcError, q as SwitchChainError, S as SwitchChainNotSupportedError, U as UserRejectedRequestError, j as createClient, r as createStorage, d as getProvider, s as noopStorage, n as normalizeChainId } from './getProvider-a3c8cf52.esm.js';
3
3
  import { providers, Contract as Contract$1 } from 'ethers';
4
4
  import { Contract, logger } from 'ethers/lib/ethers';
5
- import { formatUnits, getAddress, isAddress, Logger } from 'ethers/lib/utils';
5
+ import { FormatTypes, formatUnits, getAddress, isAddress, Logger } from 'ethers/lib/utils';
6
+ import { m as mainnet } from './chains-a22bcfea.esm.js';
7
+ export { a as allChains, c as chain, b as chainId, d as defaultChains, e as defaultL2Chains, f as etherscanBlockExplorers } from './chains-a22bcfea.esm.js';
6
8
  import shallow from 'zustand/shallow';
7
- export { a as alchemyRpcUrls, i as infuraRpcUrls, p as publicRpcUrls } from './rpcs-e837abf2.esm.js';
8
- export { a as allChains, c as chain, b as chainId, d as defaultChains, e as defaultL2Chains, f as etherscanBlockExplorers } from './chains-505e1070.esm.js';
9
+ export { a as alchemyRpcUrls, i as infuraRpcUrls, p as publicRpcUrls } from './rpcs-6e1b1718.esm.js';
9
10
  import 'zustand/middleware';
10
11
  import 'zustand/vanilla';
11
12
  import 'eventemitter3';
@@ -169,6 +170,22 @@ function deepEqual(a, b) {
169
170
  return a !== a && b !== b;
170
171
  }
171
172
 
173
+ function logWarn(message) {
174
+ var _getClient, _getClient$config$log, _getClient$config$log2;
175
+
176
+ (_getClient = getClient()) === null || _getClient === void 0 ? void 0 : (_getClient$config$log = _getClient.config.logger) === null || _getClient$config$log === void 0 ? void 0 : (_getClient$config$log2 = _getClient$config$log.warn) === null || _getClient$config$log2 === void 0 ? void 0 : _getClient$config$log2.call(_getClient$config$log, message);
177
+ }
178
+
179
+ function minimizeContractInterface(_ref) {
180
+ let {
181
+ contractInterface,
182
+ functionName
183
+ } = _ref;
184
+ const abi = Contract.getInterface(contractInterface).format(FormatTypes.full);
185
+ const minimizedInterface = Array.isArray(abi) ? abi : [abi];
186
+ return minimizedInterface.filter(i => i.includes(functionName));
187
+ }
188
+
172
189
  function isPlainArray(value) {
173
190
  return Array.isArray(value) && Object.keys(value).length === value.length;
174
191
  }
@@ -339,7 +356,7 @@ async function deprecatedWriteContract(_ref) {
339
356
  });
340
357
  const contractWithSigner = contract.connect(signer);
341
358
  const contractFunction = contractWithSigner[functionName];
342
- if (!contractFunction) console.warn("\"".concat(functionName, "\" does not exist in interface for contract \"").concat(addressOrName, "\""));
359
+ if (!contractFunction) logWarn("\"".concat(functionName, "\" does not exist in interface for contract \"").concat(addressOrName, "\""));
343
360
  return await contractFunction(...params);
344
361
  } catch (error) {
345
362
  if (error.code === 4001) throw new UserRejectedRequestError(error);
@@ -402,7 +419,7 @@ async function prepareWriteContract(_ref) {
402
419
  addressOrName,
403
420
  args,
404
421
  chainId,
405
- contractInterface,
422
+ contractInterface: contractInterface_,
406
423
  functionName,
407
424
  overrides,
408
425
  signer: signer_
@@ -411,7 +428,7 @@ async function prepareWriteContract(_ref) {
411
428
  if (!signer) throw new ConnectorNotFoundError();
412
429
  const contract = getContract({
413
430
  addressOrName,
414
- contractInterface,
431
+ contractInterface: contractInterface_,
415
432
  signerOrProvider: signer
416
433
  });
417
434
  const populateTransactionFn = contract.populateTransaction[functionName];
@@ -423,6 +440,10 @@ async function prepareWriteContract(_ref) {
423
440
  });
424
441
  }
425
442
 
443
+ const contractInterface = minimizeContractInterface({
444
+ contractInterface: contract.interface,
445
+ functionName
446
+ });
426
447
  const params = [...(Array.isArray(args) ? args : args ? [args] : []), ...(overrides ? [overrides] : [])];
427
448
  const unsignedTransaction = await populateTransactionFn(...params);
428
449
  const gasLimit = unsignedTransaction.gasLimit || (await signer.estimateGas(unsignedTransaction));
@@ -500,7 +521,7 @@ async function readContract(_ref) {
500
521
  });
501
522
  const params = [...(Array.isArray(args) ? args : args ? [args] : []), ...(overrides ? [overrides] : [])];
502
523
  const contractFunction = contract[functionName];
503
- if (!contractFunction) console.warn("\"".concat(functionName, "\" is not in the interface for contract \"").concat(addressOrName, "\""));
524
+ if (!contractFunction) logWarn("\"".concat(functionName, "\" is not in the interface for contract \"").concat(addressOrName, "\""));
504
525
  const response = await (contractFunction === null || contractFunction === void 0 ? void 0 : contractFunction(...params));
505
526
  return response;
506
527
  }
@@ -545,13 +566,23 @@ async function multicall(_ref) {
545
566
  contractInterface
546
567
  });
547
568
  const params = Array.isArray(args) ? args : args ? [args] : [];
548
- const callData = contract.interface.encodeFunctionData(functionName, params);
549
- if (!contract[functionName]) console.warn("\"".concat(functionName, "\" is not in the interface for contract \"").concat(addressOrName, "\""));
550
- return {
551
- target: addressOrName,
552
- allowFailure,
553
- callData
554
- };
569
+
570
+ try {
571
+ const callData = contract.interface.encodeFunctionData(functionName, params);
572
+ if (!contract[functionName]) logWarn("\"".concat(functionName, "\" is not in the interface for contract \"").concat(addressOrName, "\""));
573
+ return {
574
+ target: addressOrName,
575
+ allowFailure,
576
+ callData
577
+ };
578
+ } catch (err) {
579
+ if (!allowFailure) throw err;
580
+ return {
581
+ target: addressOrName,
582
+ allowFailure,
583
+ callData: '0x'
584
+ };
585
+ }
555
586
  });
556
587
  const params = [...[calls], ...(overrides ? [overrides] : [])];
557
588
  const results = await multicallContract.aggregate3(...params);
@@ -560,34 +591,62 @@ async function multicall(_ref) {
560
591
  returnData,
561
592
  success
562
593
  } = _ref3;
563
- if (!success) return null;
564
594
  const {
565
595
  addressOrName,
566
596
  contractInterface,
567
- functionName
597
+ functionName,
598
+ args
568
599
  } = contracts[i];
600
+ const contract = getContract({
601
+ addressOrName,
602
+ contractInterface
603
+ });
604
+
605
+ if (!success) {
606
+ let error;
607
+
608
+ try {
609
+ contract.interface.decodeFunctionResult(functionName, returnData);
610
+ } catch (err) {
611
+ error = new ContractMethodRevertedError({
612
+ addressOrName,
613
+ args,
614
+ chainId: chain.id,
615
+ functionName,
616
+ errorMessage: err.message
617
+ });
618
+ if (!allowFailure) throw error;
619
+ logWarn(error.message);
620
+ }
621
+
622
+ return null;
623
+ }
569
624
 
570
625
  if (returnData === '0x') {
571
- const err = new ContractMethodNoResultError({
626
+ const error = new ContractMethodNoResultError({
572
627
  addressOrName,
628
+ args,
573
629
  chainId: chain.id,
574
630
  functionName
575
631
  });
576
- if (!allowFailure) throw err;
577
- console.warn(err.message);
632
+ if (!allowFailure) throw error;
633
+ logWarn(error.message);
578
634
  return null;
579
635
  }
580
636
 
581
- const contract = getContract({
582
- addressOrName,
583
- contractInterface
584
- });
585
-
586
637
  try {
587
638
  const result = contract.interface.decodeFunctionResult(functionName, returnData);
588
639
  return Array.isArray(result) && result.length === 1 ? result[0] : result;
589
640
  } catch (err) {
590
- if (!allowFailure) throw err;
641
+ const error = new ContractResultDecodeError({
642
+ addressOrName,
643
+ args,
644
+ chainId: chain.id,
645
+ functionName,
646
+ errorMessage: err.message
647
+ });
648
+ if (!allowFailure) throw error;
649
+ logWarn(error.message);
591
650
  return null;
592
651
  }
593
652
  });
@@ -610,7 +669,8 @@ async function readContracts(_ref) {
610
669
  [chainId]: [...(contracts[chainId] || []), contract]
611
670
  };
612
671
  }, {});
613
- const promises = Object.entries(contractsByChainId).map(_ref2 => {
672
+
673
+ const promises = () => Object.entries(contractsByChainId).map(_ref2 => {
614
674
  let [chainId, contracts] = _ref2;
615
675
  return multicall({
616
676
  allowFailure,
@@ -621,11 +681,11 @@ async function readContracts(_ref) {
621
681
  });
622
682
 
623
683
  if (allowFailure) {
624
- return (await Promise.allSettled(promises)).map(result => {
684
+ return (await Promise.allSettled(promises())).map(result => {
625
685
  if (result.status === 'fulfilled') return result.value;
626
686
 
627
687
  if (result.reason instanceof ChainDoesNotSupportMulticallError) {
628
- console.warn(result.reason.message);
688
+ logWarn(result.reason.message);
629
689
  throw result.reason;
630
690
  }
631
691
 
@@ -633,18 +693,38 @@ async function readContracts(_ref) {
633
693
  }).flat();
634
694
  }
635
695
 
636
- return (await Promise.all(promises)).flat();
696
+ return (await Promise.all(promises())).flat();
637
697
  } catch (err) {
698
+ if (err instanceof ContractResultDecodeError) throw err;
638
699
  if (err instanceof ContractMethodNoResultError) throw err;
639
- const promises = contracts.map(contract => readContract({ ...contract,
700
+ if (err instanceof ContractMethodRevertedError) throw err;
701
+
702
+ const promises = () => contracts.map(contract => readContract({ ...contract,
640
703
  overrides
641
704
  }));
642
705
 
643
706
  if (allowFailure) {
644
- return (await Promise.allSettled(promises)).map(result => result.status === 'fulfilled' ? result.value : null);
707
+ return (await Promise.allSettled(promises())).map((result, i) => {
708
+ if (result.status === 'fulfilled') return result.value;
709
+ const {
710
+ addressOrName,
711
+ functionName,
712
+ chainId,
713
+ args
714
+ } = contracts[i];
715
+ const error = new ContractMethodRevertedError({
716
+ addressOrName,
717
+ functionName,
718
+ chainId: chainId !== null && chainId !== void 0 ? chainId : mainnet.id,
719
+ args,
720
+ errorMessage: result.reason
721
+ });
722
+ logWarn(error.message);
723
+ return null;
724
+ });
645
725
  }
646
726
 
647
- return await Promise.all(promises);
727
+ return await Promise.all(promises());
648
728
  }
649
729
  }
650
730
 
@@ -1438,4 +1518,4 @@ async function fetchFeeData() {
1438
1518
  };
1439
1519
  }
1440
1520
 
1441
- export { configureChains, connect, deepEqual, deprecatedSendTransaction, deprecatedWriteContract, disconnect, erc20ABI, erc721ABI, fetchBalance, fetchBlockNumber, fetchEnsAddress, fetchEnsAvatar, fetchEnsName, fetchEnsResolver, fetchFeeData, fetchSigner, fetchToken, fetchTransaction, getAccount, getContract, getNetwork, getWebSocketProvider, parseContractResult, prepareSendTransaction, prepareWriteContract, readContract, readContracts, sendTransaction, signMessage, signTypedData, switchNetwork, units, waitForTransaction, watchAccount, watchBlockNumber, watchContractEvent, watchNetwork, watchProvider, watchReadContract, watchReadContracts, watchSigner, watchWebSocketProvider, writeContract };
1521
+ export { configureChains, connect, deepEqual, deprecatedSendTransaction, deprecatedWriteContract, disconnect, erc20ABI, erc721ABI, fetchBalance, fetchBlockNumber, fetchEnsAddress, fetchEnsAvatar, fetchEnsName, fetchEnsResolver, fetchFeeData, fetchSigner, fetchToken, fetchTransaction, getAccount, getContract, getNetwork, getWebSocketProvider, minimizeContractInterface, parseContractResult, prepareSendTransaction, prepareWriteContract, readContract, readContracts, sendTransaction, signMessage, signTypedData, switchNetwork, units, waitForTransaction, watchAccount, watchBlockNumber, watchContractEvent, watchNetwork, watchProvider, watchReadContract, watchReadContracts, watchSigner, watchWebSocketProvider, writeContract };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@wagmi/core",
3
3
  "description": "Vanilla JS library for Ethereum",
4
4
  "license": "WAGMIT",
5
- "version": "0.5.3",
5
+ "version": "0.5.6",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/wagmi-dev/wagmi.git",
@@ -107,7 +107,7 @@
107
107
  "devDependencies": {
108
108
  "@coinbase/wallet-sdk": "^3.4.1",
109
109
  "@walletconnect/ethereum-provider": "^1.7.8",
110
- "ethers": "^5.6.5"
110
+ "ethers": "^5.7.0"
111
111
  },
112
112
  "keywords": [
113
113
  "eth",
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var ethers = require('ethers');
6
- var rpcs = require('../../../dist/rpcs-3cf5a783.cjs.dev.js');
6
+ var rpcs = require('../../../dist/rpcs-3326627e.cjs.dev.js');
7
7
 
8
8
  function alchemyProvider() {
9
9
  let {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var ethers = require('ethers');
6
- var rpcs = require('../../../dist/rpcs-afd1cc09.cjs.prod.js');
6
+ var rpcs = require('../../../dist/rpcs-45537550.cjs.prod.js');
7
7
 
8
8
  function alchemyProvider() {
9
9
  let {
@@ -1,5 +1,5 @@
1
1
  import { providers } from 'ethers';
2
- import { d as defaultAlchemyApiKey } from '../../../dist/rpcs-e837abf2.esm.js';
2
+ import { d as defaultAlchemyApiKey } from '../../../dist/rpcs-6e1b1718.esm.js';
3
3
 
4
4
  function alchemyProvider() {
5
5
  let {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var ethers = require('ethers');
6
- var rpcs = require('../../../dist/rpcs-3cf5a783.cjs.dev.js');
6
+ var rpcs = require('../../../dist/rpcs-3326627e.cjs.dev.js');
7
7
 
8
8
  function infuraProvider() {
9
9
  let {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var ethers = require('ethers');
6
- var rpcs = require('../../../dist/rpcs-afd1cc09.cjs.prod.js');
6
+ var rpcs = require('../../../dist/rpcs-45537550.cjs.prod.js');
7
7
 
8
8
  function infuraProvider() {
9
9
  let {
@@ -1,5 +1,5 @@
1
1
  import { providers } from 'ethers';
2
- import { b as defaultInfuraApiKey } from '../../../dist/rpcs-e837abf2.esm.js';
2
+ import { b as defaultInfuraApiKey } from '../../../dist/rpcs-6e1b1718.esm.js';
3
3
 
4
4
  function infuraProvider() {
5
5
  let {
@@ -1 +0,0 @@
1
- export declare function warn(message: string, id?: string): void;