@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
@@ -2,13 +2,13 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var getProvider = require('./getProvider-e2217cb6.cjs.dev.js');
5
+ var getProvider = require('./getProvider-3a26f086.cjs.dev.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-4fdb21bc.cjs.dev.js');
9
10
  var shallow = require('zustand/shallow');
10
- var rpcs = require('./rpcs-3cf5a783.cjs.dev.js');
11
- var chains = require('./chains-bd8ad853.cjs.dev.js');
11
+ var rpcs = require('./rpcs-3326627e.cjs.dev.js');
12
12
  require('zustand/middleware');
13
13
  require('zustand/vanilla');
14
14
  require('eventemitter3');
@@ -176,6 +176,22 @@ function deepEqual(a, b) {
176
176
  return a !== a && b !== b;
177
177
  }
178
178
 
179
+ function logWarn(message) {
180
+ var _getClient, _getClient$config$log, _getClient$config$log2;
181
+
182
+ (_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);
183
+ }
184
+
185
+ function minimizeContractInterface(_ref) {
186
+ let {
187
+ contractInterface,
188
+ functionName
189
+ } = _ref;
190
+ const abi = ethers$1.Contract.getInterface(contractInterface).format(utils.FormatTypes.full);
191
+ const minimizedInterface = Array.isArray(abi) ? abi : [abi];
192
+ return minimizedInterface.filter(i => i.includes(functionName));
193
+ }
194
+
179
195
  function isPlainArray(value) {
180
196
  return Array.isArray(value) && Object.keys(value).length === value.length;
181
197
  }
@@ -346,7 +362,7 @@ async function deprecatedWriteContract(_ref) {
346
362
  });
347
363
  const contractWithSigner = contract.connect(signer);
348
364
  const contractFunction = contractWithSigner[functionName];
349
- if (!contractFunction) console.warn("\"".concat(functionName, "\" does not exist in interface for contract \"").concat(addressOrName, "\""));
365
+ if (!contractFunction) logWarn("\"".concat(functionName, "\" does not exist in interface for contract \"").concat(addressOrName, "\""));
350
366
  return await contractFunction(...params);
351
367
  } catch (error) {
352
368
  if (error.code === 4001) throw new getProvider.UserRejectedRequestError(error);
@@ -409,7 +425,7 @@ async function prepareWriteContract(_ref) {
409
425
  addressOrName,
410
426
  args,
411
427
  chainId,
412
- contractInterface,
428
+ contractInterface: contractInterface_,
413
429
  functionName,
414
430
  overrides,
415
431
  signer: signer_
@@ -418,7 +434,7 @@ async function prepareWriteContract(_ref) {
418
434
  if (!signer) throw new getProvider.ConnectorNotFoundError();
419
435
  const contract = getContract({
420
436
  addressOrName,
421
- contractInterface,
437
+ contractInterface: contractInterface_,
422
438
  signerOrProvider: signer
423
439
  });
424
440
  const populateTransactionFn = contract.populateTransaction[functionName];
@@ -430,6 +446,10 @@ async function prepareWriteContract(_ref) {
430
446
  });
431
447
  }
432
448
 
449
+ const contractInterface = minimizeContractInterface({
450
+ contractInterface: contract.interface,
451
+ functionName
452
+ });
433
453
  const params = [...(Array.isArray(args) ? args : args ? [args] : []), ...(overrides ? [overrides] : [])];
434
454
  const unsignedTransaction = await populateTransactionFn(...params);
435
455
  const gasLimit = unsignedTransaction.gasLimit || (await signer.estimateGas(unsignedTransaction));
@@ -507,7 +527,7 @@ async function readContract(_ref) {
507
527
  });
508
528
  const params = [...(Array.isArray(args) ? args : args ? [args] : []), ...(overrides ? [overrides] : [])];
509
529
  const contractFunction = contract[functionName];
510
- if (!contractFunction) console.warn("\"".concat(functionName, "\" is not in the interface for contract \"").concat(addressOrName, "\""));
530
+ if (!contractFunction) logWarn("\"".concat(functionName, "\" is not in the interface for contract \"").concat(addressOrName, "\""));
511
531
  const response = await (contractFunction === null || contractFunction === void 0 ? void 0 : contractFunction(...params));
512
532
  return response;
513
533
  }
@@ -552,13 +572,23 @@ async function multicall(_ref) {
552
572
  contractInterface
553
573
  });
554
574
  const params = Array.isArray(args) ? args : args ? [args] : [];
555
- const callData = contract.interface.encodeFunctionData(functionName, params);
556
- if (!contract[functionName]) console.warn("\"".concat(functionName, "\" is not in the interface for contract \"").concat(addressOrName, "\""));
557
- return {
558
- target: addressOrName,
559
- allowFailure,
560
- callData
561
- };
575
+
576
+ try {
577
+ const callData = contract.interface.encodeFunctionData(functionName, params);
578
+ if (!contract[functionName]) logWarn("\"".concat(functionName, "\" is not in the interface for contract \"").concat(addressOrName, "\""));
579
+ return {
580
+ target: addressOrName,
581
+ allowFailure,
582
+ callData
583
+ };
584
+ } catch (err) {
585
+ if (!allowFailure) throw err;
586
+ return {
587
+ target: addressOrName,
588
+ allowFailure,
589
+ callData: '0x'
590
+ };
591
+ }
562
592
  });
563
593
  const params = [...[calls], ...(overrides ? [overrides] : [])];
564
594
  const results = await multicallContract.aggregate3(...params);
@@ -567,34 +597,62 @@ async function multicall(_ref) {
567
597
  returnData,
568
598
  success
569
599
  } = _ref3;
570
- if (!success) return null;
571
600
  const {
572
601
  addressOrName,
573
602
  contractInterface,
574
- functionName
603
+ functionName,
604
+ args
575
605
  } = contracts[i];
606
+ const contract = getContract({
607
+ addressOrName,
608
+ contractInterface
609
+ });
610
+
611
+ if (!success) {
612
+ let error;
613
+
614
+ try {
615
+ contract.interface.decodeFunctionResult(functionName, returnData);
616
+ } catch (err) {
617
+ error = new getProvider.ContractMethodRevertedError({
618
+ addressOrName,
619
+ args,
620
+ chainId: chain.id,
621
+ functionName,
622
+ errorMessage: err.message
623
+ });
624
+ if (!allowFailure) throw error;
625
+ logWarn(error.message);
626
+ }
627
+
628
+ return null;
629
+ }
576
630
 
577
631
  if (returnData === '0x') {
578
- const err = new getProvider.ContractMethodNoResultError({
632
+ const error = new getProvider.ContractMethodNoResultError({
579
633
  addressOrName,
634
+ args,
580
635
  chainId: chain.id,
581
636
  functionName
582
637
  });
583
- if (!allowFailure) throw err;
584
- console.warn(err.message);
638
+ if (!allowFailure) throw error;
639
+ logWarn(error.message);
585
640
  return null;
586
641
  }
587
642
 
588
- const contract = getContract({
589
- addressOrName,
590
- contractInterface
591
- });
592
-
593
643
  try {
594
644
  const result = contract.interface.decodeFunctionResult(functionName, returnData);
595
645
  return Array.isArray(result) && result.length === 1 ? result[0] : result;
596
646
  } catch (err) {
597
- if (!allowFailure) throw err;
647
+ const error = new getProvider.ContractResultDecodeError({
648
+ addressOrName,
649
+ args,
650
+ chainId: chain.id,
651
+ functionName,
652
+ errorMessage: err.message
653
+ });
654
+ if (!allowFailure) throw error;
655
+ logWarn(error.message);
598
656
  return null;
599
657
  }
600
658
  });
@@ -617,7 +675,8 @@ async function readContracts(_ref) {
617
675
  [chainId]: [...(contracts[chainId] || []), contract]
618
676
  };
619
677
  }, {});
620
- const promises = Object.entries(contractsByChainId).map(_ref2 => {
678
+
679
+ const promises = () => Object.entries(contractsByChainId).map(_ref2 => {
621
680
  let [chainId, contracts] = _ref2;
622
681
  return multicall({
623
682
  allowFailure,
@@ -628,11 +687,11 @@ async function readContracts(_ref) {
628
687
  });
629
688
 
630
689
  if (allowFailure) {
631
- return (await Promise.allSettled(promises)).map(result => {
690
+ return (await Promise.allSettled(promises())).map(result => {
632
691
  if (result.status === 'fulfilled') return result.value;
633
692
 
634
693
  if (result.reason instanceof getProvider.ChainDoesNotSupportMulticallError) {
635
- console.warn(result.reason.message);
694
+ logWarn(result.reason.message);
636
695
  throw result.reason;
637
696
  }
638
697
 
@@ -640,18 +699,38 @@ async function readContracts(_ref) {
640
699
  }).flat();
641
700
  }
642
701
 
643
- return (await Promise.all(promises)).flat();
702
+ return (await Promise.all(promises())).flat();
644
703
  } catch (err) {
704
+ if (err instanceof getProvider.ContractResultDecodeError) throw err;
645
705
  if (err instanceof getProvider.ContractMethodNoResultError) throw err;
646
- const promises = contracts.map(contract => readContract({ ...contract,
706
+ if (err instanceof getProvider.ContractMethodRevertedError) throw err;
707
+
708
+ const promises = () => contracts.map(contract => readContract({ ...contract,
647
709
  overrides
648
710
  }));
649
711
 
650
712
  if (allowFailure) {
651
- return (await Promise.allSettled(promises)).map(result => result.status === 'fulfilled' ? result.value : null);
713
+ return (await Promise.allSettled(promises())).map((result, i) => {
714
+ if (result.status === 'fulfilled') return result.value;
715
+ const {
716
+ addressOrName,
717
+ functionName,
718
+ chainId,
719
+ args
720
+ } = contracts[i];
721
+ const error = new getProvider.ContractMethodRevertedError({
722
+ addressOrName,
723
+ functionName,
724
+ chainId: chainId !== null && chainId !== void 0 ? chainId : chains.mainnet.id,
725
+ args,
726
+ errorMessage: result.reason
727
+ });
728
+ logWarn(error.message);
729
+ return null;
730
+ });
652
731
  }
653
732
 
654
- return await Promise.all(promises);
733
+ return await Promise.all(promises());
655
734
  }
656
735
  }
657
736
 
@@ -1455,6 +1534,8 @@ exports.ConnectorAlreadyConnectedError = getProvider.ConnectorAlreadyConnectedEr
1455
1534
  exports.ConnectorNotFoundError = getProvider.ConnectorNotFoundError;
1456
1535
  exports.ContractMethodDoesNotExistError = getProvider.ContractMethodDoesNotExistError;
1457
1536
  exports.ContractMethodNoResultError = getProvider.ContractMethodNoResultError;
1537
+ exports.ContractMethodRevertedError = getProvider.ContractMethodRevertedError;
1538
+ exports.ContractResultDecodeError = getProvider.ContractResultDecodeError;
1458
1539
  exports.InjectedConnector = getProvider.InjectedConnector;
1459
1540
  exports.ProviderChainsNotFound = getProvider.ProviderChainsNotFound;
1460
1541
  exports.ProviderRpcError = getProvider.ProviderRpcError;
@@ -1468,15 +1549,15 @@ exports.createStorage = getProvider.createStorage;
1468
1549
  exports.getProvider = getProvider.getProvider;
1469
1550
  exports.noopStorage = getProvider.noopStorage;
1470
1551
  exports.normalizeChainId = getProvider.normalizeChainId;
1471
- exports.alchemyRpcUrls = rpcs.alchemyRpcUrls;
1472
- exports.infuraRpcUrls = rpcs.infuraRpcUrls;
1473
- exports.publicRpcUrls = rpcs.publicRpcUrls;
1474
1552
  exports.allChains = chains.allChains;
1475
1553
  exports.chain = chains.chain;
1476
1554
  exports.chainId = chains.chainId;
1477
1555
  exports.defaultChains = chains.defaultChains;
1478
1556
  exports.defaultL2Chains = chains.defaultL2Chains;
1479
1557
  exports.etherscanBlockExplorers = chains.etherscanBlockExplorers;
1558
+ exports.alchemyRpcUrls = rpcs.alchemyRpcUrls;
1559
+ exports.infuraRpcUrls = rpcs.infuraRpcUrls;
1560
+ exports.publicRpcUrls = rpcs.publicRpcUrls;
1480
1561
  exports.configureChains = configureChains;
1481
1562
  exports.connect = connect;
1482
1563
  exports.deepEqual = deepEqual;
@@ -1499,6 +1580,7 @@ exports.getAccount = getAccount;
1499
1580
  exports.getContract = getContract;
1500
1581
  exports.getNetwork = getNetwork;
1501
1582
  exports.getWebSocketProvider = getWebSocketProvider;
1583
+ exports.minimizeContractInterface = minimizeContractInterface;
1502
1584
  exports.parseContractResult = parseContractResult;
1503
1585
  exports.prepareSendTransaction = prepareSendTransaction;
1504
1586
  exports.prepareWriteContract = prepareWriteContract;
@@ -2,13 +2,13 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var getProvider = require('./getProvider-a1ad435d.cjs.prod.js');
5
+ var getProvider = require('./getProvider-b220fed1.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-868f0ac6.cjs.prod.js');
9
10
  var shallow = require('zustand/shallow');
10
- var rpcs = require('./rpcs-afd1cc09.cjs.prod.js');
11
- var chains = require('./chains-3916cd7d.cjs.prod.js');
11
+ var rpcs = require('./rpcs-45537550.cjs.prod.js');
12
12
  require('zustand/middleware');
13
13
  require('zustand/vanilla');
14
14
  require('eventemitter3');
@@ -176,6 +176,22 @@ function deepEqual(a, b) {
176
176
  return a !== a && b !== b;
177
177
  }
178
178
 
179
+ function logWarn(message) {
180
+ var _getClient, _getClient$config$log, _getClient$config$log2;
181
+
182
+ (_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);
183
+ }
184
+
185
+ function minimizeContractInterface(_ref) {
186
+ let {
187
+ contractInterface,
188
+ functionName
189
+ } = _ref;
190
+ const abi = ethers$1.Contract.getInterface(contractInterface).format(utils.FormatTypes.full);
191
+ const minimizedInterface = Array.isArray(abi) ? abi : [abi];
192
+ return minimizedInterface.filter(i => i.includes(functionName));
193
+ }
194
+
179
195
  function isPlainArray(value) {
180
196
  return Array.isArray(value) && Object.keys(value).length === value.length;
181
197
  }
@@ -346,7 +362,7 @@ async function deprecatedWriteContract(_ref) {
346
362
  });
347
363
  const contractWithSigner = contract.connect(signer);
348
364
  const contractFunction = contractWithSigner[functionName];
349
- if (!contractFunction) console.warn("\"".concat(functionName, "\" does not exist in interface for contract \"").concat(addressOrName, "\""));
365
+ if (!contractFunction) logWarn("\"".concat(functionName, "\" does not exist in interface for contract \"").concat(addressOrName, "\""));
350
366
  return await contractFunction(...params);
351
367
  } catch (error) {
352
368
  if (error.code === 4001) throw new getProvider.UserRejectedRequestError(error);
@@ -409,7 +425,7 @@ async function prepareWriteContract(_ref) {
409
425
  addressOrName,
410
426
  args,
411
427
  chainId,
412
- contractInterface,
428
+ contractInterface: contractInterface_,
413
429
  functionName,
414
430
  overrides,
415
431
  signer: signer_
@@ -418,7 +434,7 @@ async function prepareWriteContract(_ref) {
418
434
  if (!signer) throw new getProvider.ConnectorNotFoundError();
419
435
  const contract = getContract({
420
436
  addressOrName,
421
- contractInterface,
437
+ contractInterface: contractInterface_,
422
438
  signerOrProvider: signer
423
439
  });
424
440
  const populateTransactionFn = contract.populateTransaction[functionName];
@@ -430,6 +446,10 @@ async function prepareWriteContract(_ref) {
430
446
  });
431
447
  }
432
448
 
449
+ const contractInterface = minimizeContractInterface({
450
+ contractInterface: contract.interface,
451
+ functionName
452
+ });
433
453
  const params = [...(Array.isArray(args) ? args : args ? [args] : []), ...(overrides ? [overrides] : [])];
434
454
  const unsignedTransaction = await populateTransactionFn(...params);
435
455
  const gasLimit = unsignedTransaction.gasLimit || (await signer.estimateGas(unsignedTransaction));
@@ -507,7 +527,7 @@ async function readContract(_ref) {
507
527
  });
508
528
  const params = [...(Array.isArray(args) ? args : args ? [args] : []), ...(overrides ? [overrides] : [])];
509
529
  const contractFunction = contract[functionName];
510
- if (!contractFunction) console.warn("\"".concat(functionName, "\" is not in the interface for contract \"").concat(addressOrName, "\""));
530
+ if (!contractFunction) logWarn("\"".concat(functionName, "\" is not in the interface for contract \"").concat(addressOrName, "\""));
511
531
  const response = await (contractFunction === null || contractFunction === void 0 ? void 0 : contractFunction(...params));
512
532
  return response;
513
533
  }
@@ -552,13 +572,23 @@ async function multicall(_ref) {
552
572
  contractInterface
553
573
  });
554
574
  const params = Array.isArray(args) ? args : args ? [args] : [];
555
- const callData = contract.interface.encodeFunctionData(functionName, params);
556
- if (!contract[functionName]) console.warn("\"".concat(functionName, "\" is not in the interface for contract \"").concat(addressOrName, "\""));
557
- return {
558
- target: addressOrName,
559
- allowFailure,
560
- callData
561
- };
575
+
576
+ try {
577
+ const callData = contract.interface.encodeFunctionData(functionName, params);
578
+ if (!contract[functionName]) logWarn("\"".concat(functionName, "\" is not in the interface for contract \"").concat(addressOrName, "\""));
579
+ return {
580
+ target: addressOrName,
581
+ allowFailure,
582
+ callData
583
+ };
584
+ } catch (err) {
585
+ if (!allowFailure) throw err;
586
+ return {
587
+ target: addressOrName,
588
+ allowFailure,
589
+ callData: '0x'
590
+ };
591
+ }
562
592
  });
563
593
  const params = [...[calls], ...(overrides ? [overrides] : [])];
564
594
  const results = await multicallContract.aggregate3(...params);
@@ -567,34 +597,62 @@ async function multicall(_ref) {
567
597
  returnData,
568
598
  success
569
599
  } = _ref3;
570
- if (!success) return null;
571
600
  const {
572
601
  addressOrName,
573
602
  contractInterface,
574
- functionName
603
+ functionName,
604
+ args
575
605
  } = contracts[i];
606
+ const contract = getContract({
607
+ addressOrName,
608
+ contractInterface
609
+ });
610
+
611
+ if (!success) {
612
+ let error;
613
+
614
+ try {
615
+ contract.interface.decodeFunctionResult(functionName, returnData);
616
+ } catch (err) {
617
+ error = new getProvider.ContractMethodRevertedError({
618
+ addressOrName,
619
+ args,
620
+ chainId: chain.id,
621
+ functionName,
622
+ errorMessage: err.message
623
+ });
624
+ if (!allowFailure) throw error;
625
+ logWarn(error.message);
626
+ }
627
+
628
+ return null;
629
+ }
576
630
 
577
631
  if (returnData === '0x') {
578
- const err = new getProvider.ContractMethodNoResultError({
632
+ const error = new getProvider.ContractMethodNoResultError({
579
633
  addressOrName,
634
+ args,
580
635
  chainId: chain.id,
581
636
  functionName
582
637
  });
583
- if (!allowFailure) throw err;
584
- console.warn(err.message);
638
+ if (!allowFailure) throw error;
639
+ logWarn(error.message);
585
640
  return null;
586
641
  }
587
642
 
588
- const contract = getContract({
589
- addressOrName,
590
- contractInterface
591
- });
592
-
593
643
  try {
594
644
  const result = contract.interface.decodeFunctionResult(functionName, returnData);
595
645
  return Array.isArray(result) && result.length === 1 ? result[0] : result;
596
646
  } catch (err) {
597
- if (!allowFailure) throw err;
647
+ const error = new getProvider.ContractResultDecodeError({
648
+ addressOrName,
649
+ args,
650
+ chainId: chain.id,
651
+ functionName,
652
+ errorMessage: err.message
653
+ });
654
+ if (!allowFailure) throw error;
655
+ logWarn(error.message);
598
656
  return null;
599
657
  }
600
658
  });
@@ -617,7 +675,8 @@ async function readContracts(_ref) {
617
675
  [chainId]: [...(contracts[chainId] || []), contract]
618
676
  };
619
677
  }, {});
620
- const promises = Object.entries(contractsByChainId).map(_ref2 => {
678
+
679
+ const promises = () => Object.entries(contractsByChainId).map(_ref2 => {
621
680
  let [chainId, contracts] = _ref2;
622
681
  return multicall({
623
682
  allowFailure,
@@ -628,11 +687,11 @@ async function readContracts(_ref) {
628
687
  });
629
688
 
630
689
  if (allowFailure) {
631
- return (await Promise.allSettled(promises)).map(result => {
690
+ return (await Promise.allSettled(promises())).map(result => {
632
691
  if (result.status === 'fulfilled') return result.value;
633
692
 
634
693
  if (result.reason instanceof getProvider.ChainDoesNotSupportMulticallError) {
635
- console.warn(result.reason.message);
694
+ logWarn(result.reason.message);
636
695
  throw result.reason;
637
696
  }
638
697
 
@@ -640,18 +699,38 @@ async function readContracts(_ref) {
640
699
  }).flat();
641
700
  }
642
701
 
643
- return (await Promise.all(promises)).flat();
702
+ return (await Promise.all(promises())).flat();
644
703
  } catch (err) {
704
+ if (err instanceof getProvider.ContractResultDecodeError) throw err;
645
705
  if (err instanceof getProvider.ContractMethodNoResultError) throw err;
646
- const promises = contracts.map(contract => readContract({ ...contract,
706
+ if (err instanceof getProvider.ContractMethodRevertedError) throw err;
707
+
708
+ const promises = () => contracts.map(contract => readContract({ ...contract,
647
709
  overrides
648
710
  }));
649
711
 
650
712
  if (allowFailure) {
651
- return (await Promise.allSettled(promises)).map(result => result.status === 'fulfilled' ? result.value : null);
713
+ return (await Promise.allSettled(promises())).map((result, i) => {
714
+ if (result.status === 'fulfilled') return result.value;
715
+ const {
716
+ addressOrName,
717
+ functionName,
718
+ chainId,
719
+ args
720
+ } = contracts[i];
721
+ const error = new getProvider.ContractMethodRevertedError({
722
+ addressOrName,
723
+ functionName,
724
+ chainId: chainId !== null && chainId !== void 0 ? chainId : chains.mainnet.id,
725
+ args,
726
+ errorMessage: result.reason
727
+ });
728
+ logWarn(error.message);
729
+ return null;
730
+ });
652
731
  }
653
732
 
654
- return await Promise.all(promises);
733
+ return await Promise.all(promises());
655
734
  }
656
735
  }
657
736
 
@@ -1455,6 +1534,8 @@ exports.ConnectorAlreadyConnectedError = getProvider.ConnectorAlreadyConnectedEr
1455
1534
  exports.ConnectorNotFoundError = getProvider.ConnectorNotFoundError;
1456
1535
  exports.ContractMethodDoesNotExistError = getProvider.ContractMethodDoesNotExistError;
1457
1536
  exports.ContractMethodNoResultError = getProvider.ContractMethodNoResultError;
1537
+ exports.ContractMethodRevertedError = getProvider.ContractMethodRevertedError;
1538
+ exports.ContractResultDecodeError = getProvider.ContractResultDecodeError;
1458
1539
  exports.InjectedConnector = getProvider.InjectedConnector;
1459
1540
  exports.ProviderChainsNotFound = getProvider.ProviderChainsNotFound;
1460
1541
  exports.ProviderRpcError = getProvider.ProviderRpcError;
@@ -1468,15 +1549,15 @@ exports.createStorage = getProvider.createStorage;
1468
1549
  exports.getProvider = getProvider.getProvider;
1469
1550
  exports.noopStorage = getProvider.noopStorage;
1470
1551
  exports.normalizeChainId = getProvider.normalizeChainId;
1471
- exports.alchemyRpcUrls = rpcs.alchemyRpcUrls;
1472
- exports.infuraRpcUrls = rpcs.infuraRpcUrls;
1473
- exports.publicRpcUrls = rpcs.publicRpcUrls;
1474
1552
  exports.allChains = chains.allChains;
1475
1553
  exports.chain = chains.chain;
1476
1554
  exports.chainId = chains.chainId;
1477
1555
  exports.defaultChains = chains.defaultChains;
1478
1556
  exports.defaultL2Chains = chains.defaultL2Chains;
1479
1557
  exports.etherscanBlockExplorers = chains.etherscanBlockExplorers;
1558
+ exports.alchemyRpcUrls = rpcs.alchemyRpcUrls;
1559
+ exports.infuraRpcUrls = rpcs.infuraRpcUrls;
1560
+ exports.publicRpcUrls = rpcs.publicRpcUrls;
1480
1561
  exports.configureChains = configureChains;
1481
1562
  exports.connect = connect;
1482
1563
  exports.deepEqual = deepEqual;
@@ -1499,6 +1580,7 @@ exports.getAccount = getAccount;
1499
1580
  exports.getContract = getContract;
1500
1581
  exports.getNetwork = getNetwork;
1501
1582
  exports.getWebSocketProvider = getWebSocketProvider;
1583
+ exports.minimizeContractInterface = minimizeContractInterface;
1502
1584
  exports.parseContractResult = parseContractResult;
1503
1585
  exports.prepareSendTransaction = prepareSendTransaction;
1504
1586
  exports.prepareWriteContract = prepareWriteContract;