@wagmi/core 0.5.5 → 0.5.7

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 (54) hide show
  1. package/chains/dist/wagmi-core-chains.cjs.dev.js +2 -2
  2. package/chains/dist/wagmi-core-chains.cjs.prod.js +2 -2
  3. package/chains/dist/wagmi-core-chains.esm.js +2 -2
  4. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +10 -6
  5. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +10 -6
  6. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +10 -6
  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-868f0ac6.cjs.prod.js → chains-789e0c2e.cjs.prod.js} +2 -1
  17. package/dist/{chains-5ceae8b1.esm.js → chains-8c76af1b.esm.js} +3 -2
  18. package/dist/{chains-4fdb21bc.cjs.dev.js → chains-ec1de502.cjs.dev.js} +2 -1
  19. package/dist/debounce-0862bf88.esm.js +18 -0
  20. package/dist/debounce-2d836dc9.cjs.prod.js +20 -0
  21. package/dist/debounce-46ac0312.cjs.dev.js +20 -0
  22. package/dist/declarations/src/client.d.ts +16 -2
  23. package/dist/declarations/src/constants/rpcs.d.ts +1 -1
  24. package/dist/declarations/src/errors.d.ts +23 -2
  25. package/dist/declarations/src/index.d.ts +1 -1
  26. package/dist/declarations/src/internal.d.ts +1 -0
  27. package/dist/declarations/src/utils/debounce.d.ts +1 -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/{getProvider-316a5d3f.cjs.dev.js → getProvider-1b3eeda8.cjs.dev.js} +117 -35
  31. package/dist/{getProvider-51ad330f.cjs.prod.js → getProvider-ad4ce6a4.cjs.prod.js} +117 -35
  32. package/dist/{getProvider-a6708613.esm.js → getProvider-f1dfc7e3.esm.js} +116 -36
  33. package/dist/{rpcs-6e1b1718.esm.js → rpcs-8d636858.esm.js} +1 -0
  34. package/dist/{rpcs-3326627e.cjs.dev.js → rpcs-d2cd65f1.cjs.dev.js} +1 -0
  35. package/dist/{rpcs-45537550.cjs.prod.js → rpcs-edec227e.cjs.prod.js} +1 -0
  36. package/dist/wagmi-core.cjs.dev.js +112 -37
  37. package/dist/wagmi-core.cjs.prod.js +112 -37
  38. package/dist/wagmi-core.esm.js +109 -35
  39. package/internal/dist/wagmi-core-internal.cjs.d.ts +1 -0
  40. package/internal/dist/wagmi-core-internal.cjs.dev.js +9 -0
  41. package/internal/dist/wagmi-core-internal.cjs.js +7 -0
  42. package/internal/dist/wagmi-core-internal.cjs.prod.js +9 -0
  43. package/internal/dist/wagmi-core-internal.esm.js +1 -0
  44. package/internal/package.json +4 -0
  45. package/package.json +7 -1
  46. package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.dev.js +1 -1
  47. package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.prod.js +1 -1
  48. package/providers/alchemy/dist/wagmi-core-providers-alchemy.esm.js +1 -1
  49. package/providers/coinbaseNode/dist/wagmi-core-providers-coinbaseNode.cjs.d.ts +11 -0
  50. package/providers/coinbaseNode/dist/wagmi-core-providers-coinbaseNode.cjs.js +16 -0
  51. package/providers/infura/dist/wagmi-core-providers-infura.cjs.dev.js +1 -1
  52. package/providers/infura/dist/wagmi-core-providers-infura.cjs.prod.js +1 -1
  53. package/providers/infura/dist/wagmi-core-providers-infura.esm.js +1 -1
  54. package/dist/declarations/src/utils/warn.d.ts +0 -1
@@ -2,13 +2,14 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var getProvider = require('./getProvider-51ad330f.cjs.prod.js');
5
+ var getProvider = require('./getProvider-ad4ce6a4.cjs.prod.js');
6
6
  var ethers = require('ethers');
7
7
  var ethers$1 = require('ethers/lib/ethers');
8
8
  var utils = require('ethers/lib/utils');
9
+ var chains = require('./chains-789e0c2e.cjs.prod.js');
9
10
  var shallow = require('zustand/shallow');
10
- var rpcs = require('./rpcs-45537550.cjs.prod.js');
11
- var chains = require('./chains-868f0ac6.cjs.prod.js');
11
+ var debounce = require('./debounce-2d836dc9.cjs.prod.js');
12
+ var rpcs = require('./rpcs-edec227e.cjs.prod.js');
12
13
  require('zustand/middleware');
13
14
  require('zustand/vanilla');
14
15
  require('eventemitter3');
@@ -176,6 +177,12 @@ function deepEqual(a, b) {
176
177
  return a !== a && b !== b;
177
178
  }
178
179
 
180
+ function logWarn(message) {
181
+ var _getClient, _getClient$config$log, _getClient$config$log2;
182
+
183
+ (_getClient = getProvider.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);
184
+ }
185
+
179
186
  function minimizeContractInterface(_ref) {
180
187
  let {
181
188
  contractInterface,
@@ -356,7 +363,7 @@ async function deprecatedWriteContract(_ref) {
356
363
  });
357
364
  const contractWithSigner = contract.connect(signer);
358
365
  const contractFunction = contractWithSigner[functionName];
359
- if (!contractFunction) console.warn("\"".concat(functionName, "\" does not exist in interface for contract \"").concat(addressOrName, "\""));
366
+ if (!contractFunction) logWarn("\"".concat(functionName, "\" does not exist in interface for contract \"").concat(addressOrName, "\""));
360
367
  return await contractFunction(...params);
361
368
  } catch (error) {
362
369
  if (error.code === 4001) throw new getProvider.UserRejectedRequestError(error);
@@ -468,9 +475,9 @@ function getWebSocketProvider() {
468
475
  chainId
469
476
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
470
477
  const client = getProvider.getClient();
471
- if (chainId && typeof client.config.webSocketProvider === 'function') return client.config.webSocketProvider({
478
+ if (chainId) return client.getWebSocketProvider({
472
479
  chainId
473
- });
480
+ }) || client.webSocketProvider;
474
481
  return client.webSocketProvider;
475
482
  }
476
483
 
@@ -521,7 +528,7 @@ async function readContract(_ref) {
521
528
  });
522
529
  const params = [...(Array.isArray(args) ? args : args ? [args] : []), ...(overrides ? [overrides] : [])];
523
530
  const contractFunction = contract[functionName];
524
- if (!contractFunction) console.warn("\"".concat(functionName, "\" is not in the interface for contract \"").concat(addressOrName, "\""));
531
+ if (!contractFunction) logWarn("\"".concat(functionName, "\" is not in the interface for contract \"").concat(addressOrName, "\""));
525
532
  const response = await (contractFunction === null || contractFunction === void 0 ? void 0 : contractFunction(...params));
526
533
  return response;
527
534
  }
@@ -566,13 +573,23 @@ async function multicall(_ref) {
566
573
  contractInterface
567
574
  });
568
575
  const params = Array.isArray(args) ? args : args ? [args] : [];
569
- const callData = contract.interface.encodeFunctionData(functionName, params);
570
- if (!contract[functionName]) console.warn("\"".concat(functionName, "\" is not in the interface for contract \"").concat(addressOrName, "\""));
571
- return {
572
- target: addressOrName,
573
- allowFailure,
574
- callData
575
- };
576
+
577
+ try {
578
+ const callData = contract.interface.encodeFunctionData(functionName, params);
579
+ if (!contract[functionName]) logWarn("\"".concat(functionName, "\" is not in the interface for contract \"").concat(addressOrName, "\""));
580
+ return {
581
+ target: addressOrName,
582
+ allowFailure,
583
+ callData
584
+ };
585
+ } catch (err) {
586
+ if (!allowFailure) throw err;
587
+ return {
588
+ target: addressOrName,
589
+ allowFailure,
590
+ callData: '0x'
591
+ };
592
+ }
576
593
  });
577
594
  const params = [...[calls], ...(overrides ? [overrides] : [])];
578
595
  const results = await multicallContract.aggregate3(...params);
@@ -581,34 +598,62 @@ async function multicall(_ref) {
581
598
  returnData,
582
599
  success
583
600
  } = _ref3;
584
- if (!success) return null;
585
601
  const {
586
602
  addressOrName,
587
603
  contractInterface,
588
- functionName
604
+ functionName,
605
+ args
589
606
  } = contracts[i];
607
+ const contract = getContract({
608
+ addressOrName,
609
+ contractInterface
610
+ });
611
+
612
+ if (!success) {
613
+ let error;
614
+
615
+ try {
616
+ contract.interface.decodeFunctionResult(functionName, returnData);
617
+ } catch (err) {
618
+ error = new getProvider.ContractMethodRevertedError({
619
+ addressOrName,
620
+ args,
621
+ chainId: chain.id,
622
+ functionName,
623
+ errorMessage: err.message
624
+ });
625
+ if (!allowFailure) throw error;
626
+ logWarn(error.message);
627
+ }
628
+
629
+ return null;
630
+ }
590
631
 
591
632
  if (returnData === '0x') {
592
- const err = new getProvider.ContractMethodNoResultError({
633
+ const error = new getProvider.ContractMethodNoResultError({
593
634
  addressOrName,
635
+ args,
594
636
  chainId: chain.id,
595
637
  functionName
596
638
  });
597
- if (!allowFailure) throw err;
598
- console.warn(err.message);
639
+ if (!allowFailure) throw error;
640
+ logWarn(error.message);
599
641
  return null;
600
642
  }
601
643
 
602
- const contract = getContract({
603
- addressOrName,
604
- contractInterface
605
- });
606
-
607
644
  try {
608
645
  const result = contract.interface.decodeFunctionResult(functionName, returnData);
609
646
  return Array.isArray(result) && result.length === 1 ? result[0] : result;
610
647
  } catch (err) {
611
- if (!allowFailure) throw err;
648
+ const error = new getProvider.ContractResultDecodeError({
649
+ addressOrName,
650
+ args,
651
+ chainId: chain.id,
652
+ functionName,
653
+ errorMessage: err.message
654
+ });
655
+ if (!allowFailure) throw error;
656
+ logWarn(error.message);
612
657
  return null;
613
658
  }
614
659
  });
@@ -631,7 +676,8 @@ async function readContracts(_ref) {
631
676
  [chainId]: [...(contracts[chainId] || []), contract]
632
677
  };
633
678
  }, {});
634
- const promises = Object.entries(contractsByChainId).map(_ref2 => {
679
+
680
+ const promises = () => Object.entries(contractsByChainId).map(_ref2 => {
635
681
  let [chainId, contracts] = _ref2;
636
682
  return multicall({
637
683
  allowFailure,
@@ -642,11 +688,11 @@ async function readContracts(_ref) {
642
688
  });
643
689
 
644
690
  if (allowFailure) {
645
- return (await Promise.allSettled(promises)).map(result => {
691
+ return (await Promise.allSettled(promises())).map(result => {
646
692
  if (result.status === 'fulfilled') return result.value;
647
693
 
648
694
  if (result.reason instanceof getProvider.ChainDoesNotSupportMulticallError) {
649
- console.warn(result.reason.message);
695
+ logWarn(result.reason.message);
650
696
  throw result.reason;
651
697
  }
652
698
 
@@ -654,18 +700,38 @@ async function readContracts(_ref) {
654
700
  }).flat();
655
701
  }
656
702
 
657
- return (await Promise.all(promises)).flat();
703
+ return (await Promise.all(promises())).flat();
658
704
  } catch (err) {
705
+ if (err instanceof getProvider.ContractResultDecodeError) throw err;
659
706
  if (err instanceof getProvider.ContractMethodNoResultError) throw err;
660
- const promises = contracts.map(contract => readContract({ ...contract,
707
+ if (err instanceof getProvider.ContractMethodRevertedError) throw err;
708
+
709
+ const promises = () => contracts.map(contract => readContract({ ...contract,
661
710
  overrides
662
711
  }));
663
712
 
664
713
  if (allowFailure) {
665
- return (await Promise.allSettled(promises)).map(result => result.status === 'fulfilled' ? result.value : null);
714
+ return (await Promise.allSettled(promises())).map((result, i) => {
715
+ if (result.status === 'fulfilled') return result.value;
716
+ const {
717
+ addressOrName,
718
+ functionName,
719
+ chainId,
720
+ args
721
+ } = contracts[i];
722
+ const error = new getProvider.ContractMethodRevertedError({
723
+ addressOrName,
724
+ functionName,
725
+ chainId: chainId !== null && chainId !== void 0 ? chainId : chains.mainnet.id,
726
+ args,
727
+ errorMessage: result.reason
728
+ });
729
+ logWarn(error.message);
730
+ return null;
731
+ });
666
732
  }
667
733
 
668
- return await Promise.all(promises);
734
+ return await Promise.all(promises());
669
735
  }
670
736
  }
671
737
 
@@ -737,13 +803,20 @@ function watchBlockNumber(args, callback) {
737
803
  let previousProvider;
738
804
 
739
805
  const createListener = provider => {
806
+ // We need to debounce the listener as we want to opt-out
807
+ // of the behavior where ethers emits a "block" event for
808
+ // every block that was missed in between the `pollingInterval`.
809
+ // We are setting a wait time of 1 as emitting an event in
810
+ // ethers takes ~0.1ms.
811
+ const debouncedCallback = debounce.debounce(callback, 1);
812
+
740
813
  if (previousProvider) {
741
814
  var _previousProvider;
742
815
 
743
- (_previousProvider = previousProvider) === null || _previousProvider === void 0 ? void 0 : _previousProvider.off('block', callback);
816
+ (_previousProvider = previousProvider) === null || _previousProvider === void 0 ? void 0 : _previousProvider.off('block', debouncedCallback);
744
817
  }
745
818
 
746
- provider.on('block', callback);
819
+ provider.on('block', debouncedCallback);
747
820
  previousProvider = provider;
748
821
  };
749
822
 
@@ -1469,6 +1542,8 @@ exports.ConnectorAlreadyConnectedError = getProvider.ConnectorAlreadyConnectedEr
1469
1542
  exports.ConnectorNotFoundError = getProvider.ConnectorNotFoundError;
1470
1543
  exports.ContractMethodDoesNotExistError = getProvider.ContractMethodDoesNotExistError;
1471
1544
  exports.ContractMethodNoResultError = getProvider.ContractMethodNoResultError;
1545
+ exports.ContractMethodRevertedError = getProvider.ContractMethodRevertedError;
1546
+ exports.ContractResultDecodeError = getProvider.ContractResultDecodeError;
1472
1547
  exports.InjectedConnector = getProvider.InjectedConnector;
1473
1548
  exports.ProviderChainsNotFound = getProvider.ProviderChainsNotFound;
1474
1549
  exports.ProviderRpcError = getProvider.ProviderRpcError;
@@ -1482,15 +1557,15 @@ exports.createStorage = getProvider.createStorage;
1482
1557
  exports.getProvider = getProvider.getProvider;
1483
1558
  exports.noopStorage = getProvider.noopStorage;
1484
1559
  exports.normalizeChainId = getProvider.normalizeChainId;
1485
- exports.alchemyRpcUrls = rpcs.alchemyRpcUrls;
1486
- exports.infuraRpcUrls = rpcs.infuraRpcUrls;
1487
- exports.publicRpcUrls = rpcs.publicRpcUrls;
1488
1560
  exports.allChains = chains.allChains;
1489
1561
  exports.chain = chains.chain;
1490
1562
  exports.chainId = chains.chainId;
1491
1563
  exports.defaultChains = chains.defaultChains;
1492
1564
  exports.defaultL2Chains = chains.defaultL2Chains;
1493
1565
  exports.etherscanBlockExplorers = chains.etherscanBlockExplorers;
1566
+ exports.alchemyRpcUrls = rpcs.alchemyRpcUrls;
1567
+ exports.infuraRpcUrls = rpcs.infuraRpcUrls;
1568
+ exports.publicRpcUrls = rpcs.publicRpcUrls;
1494
1569
  exports.configureChains = configureChains;
1495
1570
  exports.connect = connect;
1496
1571
  exports.deepEqual = deepEqual;
@@ -1,11 +1,13 @@
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-a6708613.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-a6708613.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-f1dfc7e3.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-f1dfc7e3.esm.js';
3
3
  import { providers, Contract as Contract$1 } from 'ethers';
4
4
  import { Contract, logger } from 'ethers/lib/ethers';
5
5
  import { FormatTypes, formatUnits, getAddress, isAddress, Logger } from 'ethers/lib/utils';
6
+ import { m as mainnet } from './chains-8c76af1b.esm.js';
7
+ export { a as allChains, c as chain, b as chainId, d as defaultChains, e as defaultL2Chains, f as etherscanBlockExplorers } from './chains-8c76af1b.esm.js';
6
8
  import shallow from 'zustand/shallow';
7
- export { a as alchemyRpcUrls, i as infuraRpcUrls, p as publicRpcUrls } from './rpcs-6e1b1718.esm.js';
8
- export { a as allChains, c as chain, b as chainId, d as defaultChains, e as defaultL2Chains, f as etherscanBlockExplorers } from './chains-5ceae8b1.esm.js';
9
+ import { d as debounce } from './debounce-0862bf88.esm.js';
10
+ export { a as alchemyRpcUrls, i as infuraRpcUrls, p as publicRpcUrls } from './rpcs-8d636858.esm.js';
9
11
  import 'zustand/middleware';
10
12
  import 'zustand/vanilla';
11
13
  import 'eventemitter3';
@@ -169,6 +171,12 @@ function deepEqual(a, b) {
169
171
  return a !== a && b !== b;
170
172
  }
171
173
 
174
+ function logWarn(message) {
175
+ var _getClient, _getClient$config$log, _getClient$config$log2;
176
+
177
+ (_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);
178
+ }
179
+
172
180
  function minimizeContractInterface(_ref) {
173
181
  let {
174
182
  contractInterface,
@@ -349,7 +357,7 @@ async function deprecatedWriteContract(_ref) {
349
357
  });
350
358
  const contractWithSigner = contract.connect(signer);
351
359
  const contractFunction = contractWithSigner[functionName];
352
- if (!contractFunction) console.warn("\"".concat(functionName, "\" does not exist in interface for contract \"").concat(addressOrName, "\""));
360
+ if (!contractFunction) logWarn("\"".concat(functionName, "\" does not exist in interface for contract \"").concat(addressOrName, "\""));
353
361
  return await contractFunction(...params);
354
362
  } catch (error) {
355
363
  if (error.code === 4001) throw new UserRejectedRequestError(error);
@@ -461,9 +469,9 @@ function getWebSocketProvider() {
461
469
  chainId
462
470
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
463
471
  const client = getClient();
464
- if (chainId && typeof client.config.webSocketProvider === 'function') return client.config.webSocketProvider({
472
+ if (chainId) return client.getWebSocketProvider({
465
473
  chainId
466
- });
474
+ }) || client.webSocketProvider;
467
475
  return client.webSocketProvider;
468
476
  }
469
477
 
@@ -514,7 +522,7 @@ async function readContract(_ref) {
514
522
  });
515
523
  const params = [...(Array.isArray(args) ? args : args ? [args] : []), ...(overrides ? [overrides] : [])];
516
524
  const contractFunction = contract[functionName];
517
- if (!contractFunction) console.warn("\"".concat(functionName, "\" is not in the interface for contract \"").concat(addressOrName, "\""));
525
+ if (!contractFunction) logWarn("\"".concat(functionName, "\" is not in the interface for contract \"").concat(addressOrName, "\""));
518
526
  const response = await (contractFunction === null || contractFunction === void 0 ? void 0 : contractFunction(...params));
519
527
  return response;
520
528
  }
@@ -559,13 +567,23 @@ async function multicall(_ref) {
559
567
  contractInterface
560
568
  });
561
569
  const params = Array.isArray(args) ? args : args ? [args] : [];
562
- const callData = contract.interface.encodeFunctionData(functionName, params);
563
- if (!contract[functionName]) console.warn("\"".concat(functionName, "\" is not in the interface for contract \"").concat(addressOrName, "\""));
564
- return {
565
- target: addressOrName,
566
- allowFailure,
567
- callData
568
- };
570
+
571
+ try {
572
+ const callData = contract.interface.encodeFunctionData(functionName, params);
573
+ if (!contract[functionName]) logWarn("\"".concat(functionName, "\" is not in the interface for contract \"").concat(addressOrName, "\""));
574
+ return {
575
+ target: addressOrName,
576
+ allowFailure,
577
+ callData
578
+ };
579
+ } catch (err) {
580
+ if (!allowFailure) throw err;
581
+ return {
582
+ target: addressOrName,
583
+ allowFailure,
584
+ callData: '0x'
585
+ };
586
+ }
569
587
  });
570
588
  const params = [...[calls], ...(overrides ? [overrides] : [])];
571
589
  const results = await multicallContract.aggregate3(...params);
@@ -574,34 +592,62 @@ async function multicall(_ref) {
574
592
  returnData,
575
593
  success
576
594
  } = _ref3;
577
- if (!success) return null;
578
595
  const {
579
596
  addressOrName,
580
597
  contractInterface,
581
- functionName
598
+ functionName,
599
+ args
582
600
  } = contracts[i];
601
+ const contract = getContract({
602
+ addressOrName,
603
+ contractInterface
604
+ });
605
+
606
+ if (!success) {
607
+ let error;
608
+
609
+ try {
610
+ contract.interface.decodeFunctionResult(functionName, returnData);
611
+ } catch (err) {
612
+ error = new ContractMethodRevertedError({
613
+ addressOrName,
614
+ args,
615
+ chainId: chain.id,
616
+ functionName,
617
+ errorMessage: err.message
618
+ });
619
+ if (!allowFailure) throw error;
620
+ logWarn(error.message);
621
+ }
622
+
623
+ return null;
624
+ }
583
625
 
584
626
  if (returnData === '0x') {
585
- const err = new ContractMethodNoResultError({
627
+ const error = new ContractMethodNoResultError({
586
628
  addressOrName,
629
+ args,
587
630
  chainId: chain.id,
588
631
  functionName
589
632
  });
590
- if (!allowFailure) throw err;
591
- console.warn(err.message);
633
+ if (!allowFailure) throw error;
634
+ logWarn(error.message);
592
635
  return null;
593
636
  }
594
637
 
595
- const contract = getContract({
596
- addressOrName,
597
- contractInterface
598
- });
599
-
600
638
  try {
601
639
  const result = contract.interface.decodeFunctionResult(functionName, returnData);
602
640
  return Array.isArray(result) && result.length === 1 ? result[0] : result;
603
641
  } catch (err) {
604
- if (!allowFailure) throw err;
642
+ const error = new ContractResultDecodeError({
643
+ addressOrName,
644
+ args,
645
+ chainId: chain.id,
646
+ functionName,
647
+ errorMessage: err.message
648
+ });
649
+ if (!allowFailure) throw error;
650
+ logWarn(error.message);
605
651
  return null;
606
652
  }
607
653
  });
@@ -624,7 +670,8 @@ async function readContracts(_ref) {
624
670
  [chainId]: [...(contracts[chainId] || []), contract]
625
671
  };
626
672
  }, {});
627
- const promises = Object.entries(contractsByChainId).map(_ref2 => {
673
+
674
+ const promises = () => Object.entries(contractsByChainId).map(_ref2 => {
628
675
  let [chainId, contracts] = _ref2;
629
676
  return multicall({
630
677
  allowFailure,
@@ -635,11 +682,11 @@ async function readContracts(_ref) {
635
682
  });
636
683
 
637
684
  if (allowFailure) {
638
- return (await Promise.allSettled(promises)).map(result => {
685
+ return (await Promise.allSettled(promises())).map(result => {
639
686
  if (result.status === 'fulfilled') return result.value;
640
687
 
641
688
  if (result.reason instanceof ChainDoesNotSupportMulticallError) {
642
- console.warn(result.reason.message);
689
+ logWarn(result.reason.message);
643
690
  throw result.reason;
644
691
  }
645
692
 
@@ -647,18 +694,38 @@ async function readContracts(_ref) {
647
694
  }).flat();
648
695
  }
649
696
 
650
- return (await Promise.all(promises)).flat();
697
+ return (await Promise.all(promises())).flat();
651
698
  } catch (err) {
699
+ if (err instanceof ContractResultDecodeError) throw err;
652
700
  if (err instanceof ContractMethodNoResultError) throw err;
653
- const promises = contracts.map(contract => readContract({ ...contract,
701
+ if (err instanceof ContractMethodRevertedError) throw err;
702
+
703
+ const promises = () => contracts.map(contract => readContract({ ...contract,
654
704
  overrides
655
705
  }));
656
706
 
657
707
  if (allowFailure) {
658
- return (await Promise.allSettled(promises)).map(result => result.status === 'fulfilled' ? result.value : null);
708
+ return (await Promise.allSettled(promises())).map((result, i) => {
709
+ if (result.status === 'fulfilled') return result.value;
710
+ const {
711
+ addressOrName,
712
+ functionName,
713
+ chainId,
714
+ args
715
+ } = contracts[i];
716
+ const error = new ContractMethodRevertedError({
717
+ addressOrName,
718
+ functionName,
719
+ chainId: chainId !== null && chainId !== void 0 ? chainId : mainnet.id,
720
+ args,
721
+ errorMessage: result.reason
722
+ });
723
+ logWarn(error.message);
724
+ return null;
725
+ });
659
726
  }
660
727
 
661
- return await Promise.all(promises);
728
+ return await Promise.all(promises());
662
729
  }
663
730
  }
664
731
 
@@ -730,13 +797,20 @@ function watchBlockNumber(args, callback) {
730
797
  let previousProvider;
731
798
 
732
799
  const createListener = provider => {
800
+ // We need to debounce the listener as we want to opt-out
801
+ // of the behavior where ethers emits a "block" event for
802
+ // every block that was missed in between the `pollingInterval`.
803
+ // We are setting a wait time of 1 as emitting an event in
804
+ // ethers takes ~0.1ms.
805
+ const debouncedCallback = debounce(callback, 1);
806
+
733
807
  if (previousProvider) {
734
808
  var _previousProvider;
735
809
 
736
- (_previousProvider = previousProvider) === null || _previousProvider === void 0 ? void 0 : _previousProvider.off('block', callback);
810
+ (_previousProvider = previousProvider) === null || _previousProvider === void 0 ? void 0 : _previousProvider.off('block', debouncedCallback);
737
811
  }
738
812
 
739
- provider.on('block', callback);
813
+ provider.on('block', debouncedCallback);
740
814
  previousProvider = provider;
741
815
  };
742
816
 
@@ -0,0 +1 @@
1
+ export * from "../../dist/declarations/src/internal";
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var debounce = require('../../dist/debounce-46ac0312.cjs.dev.js');
6
+
7
+
8
+
9
+ exports.debounce = debounce.debounce;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./wagmi-core-internal.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./wagmi-core-internal.cjs.dev.js");
7
+ }
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var debounce = require('../../dist/debounce-2d836dc9.cjs.prod.js');
6
+
7
+
8
+
9
+ exports.debounce = debounce.debounce;
@@ -0,0 +1 @@
1
+ export { d as debounce } from '../../dist/debounce-0862bf88.esm.js';
@@ -0,0 +1,4 @@
1
+ {
2
+ "main": "dist/wagmi-core-internal.cjs.js",
3
+ "module": "dist/wagmi-core-internal.esm.js"
4
+ }
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.5",
5
+ "version": "0.5.7",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/wagmi-dev/wagmi.git",
@@ -49,6 +49,10 @@
49
49
  "module": "./connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js",
50
50
  "default": "./connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.js"
51
51
  },
52
+ "./internal": {
53
+ "module": "./internal/dist/wagmi-core-internal.esm.js",
54
+ "default": "./internal/dist/wagmi-core-internal.cjs.js"
55
+ },
52
56
  "./providers/alchemy": {
53
57
  "module": "./providers/alchemy/dist/wagmi-core-providers-alchemy.esm.js",
54
58
  "default": "./providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.js"
@@ -70,6 +74,7 @@
70
74
  "files": [
71
75
  "/chains",
72
76
  "/connectors",
77
+ "/internal",
73
78
  "/providers",
74
79
  "/dist"
75
80
  ],
@@ -81,6 +86,7 @@
81
86
  "connectors/metaMask.ts",
82
87
  "connectors/walletConnect.ts",
83
88
  "connectors/mock/index.ts",
89
+ "internal.ts",
84
90
  "providers/alchemy.ts",
85
91
  "providers/public.ts",
86
92
  "providers/infura.ts",
@@ -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-3326627e.cjs.dev.js');
6
+ var rpcs = require('../../../dist/rpcs-d2cd65f1.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-45537550.cjs.prod.js');
6
+ var rpcs = require('../../../dist/rpcs-edec227e.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-6e1b1718.esm.js';
2
+ import { d as defaultAlchemyApiKey } from '../../../dist/rpcs-8d636858.esm.js';
3
3
 
4
4
  function alchemyProvider() {
5
5
  let {
@@ -0,0 +1,11 @@
1
+ // are you seeing an error that a default export doesn't exist but your source file has a default export?
2
+ // you should run `yarn` or `yarn preconstruct dev` if preconstruct dev isn't in your postinstall hook
3
+
4
+ // curious why you need to?
5
+ // this file exists so that you can import from the entrypoint normally
6
+ // except that it points to your source file and you don't need to run build constantly
7
+ // which means we need to re-export all of the modules from your source file
8
+ // and since export * doesn't include default exports, we need to read your source file
9
+ // to check for a default export and re-export it if it exists
10
+ // it's not ideal, but it works pretty well ¯\_(ツ)_/¯
11
+ export * from "../../../src/providers/coinbaseNode";