@wagmi/core 0.5.5 → 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 (27) hide show
  1. package/chains/dist/wagmi-core-chains.esm.js +1 -1
  2. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +1 -1
  3. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +1 -1
  4. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +2 -2
  5. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.dev.js +1 -1
  6. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.prod.js +1 -1
  7. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.esm.js +2 -2
  8. package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.dev.js +1 -1
  9. package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.prod.js +1 -1
  10. package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +2 -2
  11. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.dev.js +1 -1
  12. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.prod.js +1 -1
  13. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +2 -2
  14. package/dist/{chains-5ceae8b1.esm.js → chains-a22bcfea.esm.js} +1 -1
  15. package/dist/declarations/src/client.d.ts +5 -1
  16. package/dist/declarations/src/errors.d.ts +23 -2
  17. package/dist/declarations/src/index.d.ts +1 -1
  18. package/dist/declarations/src/utils/index.d.ts +1 -1
  19. package/dist/declarations/src/utils/logger.d.ts +1 -0
  20. package/dist/{getProvider-316a5d3f.cjs.dev.js → getProvider-3a26f086.cjs.dev.js} +58 -16
  21. package/dist/{getProvider-a6708613.esm.js → getProvider-a3c8cf52.esm.js} +58 -18
  22. package/dist/{getProvider-51ad330f.cjs.prod.js → getProvider-b220fed1.cjs.prod.js} +58 -16
  23. package/dist/wagmi-core.cjs.dev.js +99 -32
  24. package/dist/wagmi-core.cjs.prod.js +99 -32
  25. package/dist/wagmi-core.esm.js +96 -30
  26. package/package.json +1 -1
  27. 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-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-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
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
9
  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
10
  import 'zustand/middleware';
10
11
  import 'zustand/vanilla';
11
12
  import 'eventemitter3';
@@ -169,6 +170,12 @@ 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
+
172
179
  function minimizeContractInterface(_ref) {
173
180
  let {
174
181
  contractInterface,
@@ -349,7 +356,7 @@ async function deprecatedWriteContract(_ref) {
349
356
  });
350
357
  const contractWithSigner = contract.connect(signer);
351
358
  const contractFunction = contractWithSigner[functionName];
352
- 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, "\""));
353
360
  return await contractFunction(...params);
354
361
  } catch (error) {
355
362
  if (error.code === 4001) throw new UserRejectedRequestError(error);
@@ -514,7 +521,7 @@ async function readContract(_ref) {
514
521
  });
515
522
  const params = [...(Array.isArray(args) ? args : args ? [args] : []), ...(overrides ? [overrides] : [])];
516
523
  const contractFunction = contract[functionName];
517
- 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, "\""));
518
525
  const response = await (contractFunction === null || contractFunction === void 0 ? void 0 : contractFunction(...params));
519
526
  return response;
520
527
  }
@@ -559,13 +566,23 @@ async function multicall(_ref) {
559
566
  contractInterface
560
567
  });
561
568
  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
- };
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
+ }
569
586
  });
570
587
  const params = [...[calls], ...(overrides ? [overrides] : [])];
571
588
  const results = await multicallContract.aggregate3(...params);
@@ -574,34 +591,62 @@ async function multicall(_ref) {
574
591
  returnData,
575
592
  success
576
593
  } = _ref3;
577
- if (!success) return null;
578
594
  const {
579
595
  addressOrName,
580
596
  contractInterface,
581
- functionName
597
+ functionName,
598
+ args
582
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
+ }
583
624
 
584
625
  if (returnData === '0x') {
585
- const err = new ContractMethodNoResultError({
626
+ const error = new ContractMethodNoResultError({
586
627
  addressOrName,
628
+ args,
587
629
  chainId: chain.id,
588
630
  functionName
589
631
  });
590
- if (!allowFailure) throw err;
591
- console.warn(err.message);
632
+ if (!allowFailure) throw error;
633
+ logWarn(error.message);
592
634
  return null;
593
635
  }
594
636
 
595
- const contract = getContract({
596
- addressOrName,
597
- contractInterface
598
- });
599
-
600
637
  try {
601
638
  const result = contract.interface.decodeFunctionResult(functionName, returnData);
602
639
  return Array.isArray(result) && result.length === 1 ? result[0] : result;
603
640
  } catch (err) {
604
- 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);
605
650
  return null;
606
651
  }
607
652
  });
@@ -624,7 +669,8 @@ async function readContracts(_ref) {
624
669
  [chainId]: [...(contracts[chainId] || []), contract]
625
670
  };
626
671
  }, {});
627
- const promises = Object.entries(contractsByChainId).map(_ref2 => {
672
+
673
+ const promises = () => Object.entries(contractsByChainId).map(_ref2 => {
628
674
  let [chainId, contracts] = _ref2;
629
675
  return multicall({
630
676
  allowFailure,
@@ -635,11 +681,11 @@ async function readContracts(_ref) {
635
681
  });
636
682
 
637
683
  if (allowFailure) {
638
- return (await Promise.allSettled(promises)).map(result => {
684
+ return (await Promise.allSettled(promises())).map(result => {
639
685
  if (result.status === 'fulfilled') return result.value;
640
686
 
641
687
  if (result.reason instanceof ChainDoesNotSupportMulticallError) {
642
- console.warn(result.reason.message);
688
+ logWarn(result.reason.message);
643
689
  throw result.reason;
644
690
  }
645
691
 
@@ -647,18 +693,38 @@ async function readContracts(_ref) {
647
693
  }).flat();
648
694
  }
649
695
 
650
- return (await Promise.all(promises)).flat();
696
+ return (await Promise.all(promises())).flat();
651
697
  } catch (err) {
698
+ if (err instanceof ContractResultDecodeError) throw err;
652
699
  if (err instanceof ContractMethodNoResultError) throw err;
653
- const promises = contracts.map(contract => readContract({ ...contract,
700
+ if (err instanceof ContractMethodRevertedError) throw err;
701
+
702
+ const promises = () => contracts.map(contract => readContract({ ...contract,
654
703
  overrides
655
704
  }));
656
705
 
657
706
  if (allowFailure) {
658
- 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
+ });
659
725
  }
660
726
 
661
- return await Promise.all(promises);
727
+ return await Promise.all(promises());
662
728
  }
663
729
  }
664
730
 
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.6",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/wagmi-dev/wagmi.git",
@@ -1 +0,0 @@
1
- export declare function warn(message: string, id?: string): void;