@wagmi/core 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +28 -10
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +28 -10
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +28 -10
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.dev.js +20 -11
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.prod.js +20 -11
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.esm.js +15 -6
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.dev.js +7 -6
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.prod.js +7 -6
- package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +5 -4
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.dev.js +26 -8
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.prod.js +26 -8
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +24 -6
- package/dist/{base-5812b724.cjs.dev.js → base-3a506159.cjs.dev.js} +129 -67
- package/dist/{base-159de546.esm.js → base-997b4fec.esm.js} +98 -38
- package/dist/{base-59f3457e.cjs.prod.js → base-cb4198f3.cjs.prod.js} +129 -67
- package/dist/{client-f77a08e4.cjs.dev.js → client-08120ec7.cjs.dev.js} +35 -23
- package/dist/{client-4d8337e7.cjs.prod.js → client-332f5c43.cjs.prod.js} +35 -23
- package/dist/{client-5d456446.esm.js → client-d8d4f4fc.esm.js} +33 -21
- package/dist/declarations/src/actions/accounts/connect.d.ts +4 -4
- package/dist/declarations/src/actions/accounts/getAccount.d.ts +3 -3
- package/dist/declarations/src/actions/accounts/signTypedData.d.ts +15 -6
- package/dist/declarations/src/actions/accounts/watchAccount.d.ts +3 -3
- package/dist/declarations/src/actions/providers/getProvider.d.ts +3 -3
- package/dist/declarations/src/actions/providers/getWebSocketProvider.d.ts +3 -3
- package/dist/declarations/src/actions/providers/watchProvider.d.ts +3 -3
- package/dist/declarations/src/actions/providers/watchWebSocketProvider.d.ts +3 -3
- package/dist/declarations/src/chains/configureChains.d.ts +20 -0
- package/dist/declarations/src/chains/index.d.ts +2 -0
- package/dist/declarations/src/client.d.ts +11 -11
- package/dist/declarations/src/connectors/injected.d.ts +1 -1
- package/dist/declarations/src/constants/index.d.ts +1 -1
- package/dist/declarations/src/errors.d.ts +48 -4
- package/dist/declarations/src/index.d.ts +8 -6
- package/dist/declarations/src/providers/alchemy.d.ts +7 -0
- package/dist/declarations/src/providers/infura.d.ts +7 -0
- package/dist/declarations/src/providers/jsonRpc.d.ts +11 -0
- package/dist/declarations/src/providers/public.d.ts +6 -0
- package/dist/declarations/src/storage.d.ts +2 -2
- package/dist/declarations/src/types/index.d.ts +67 -27
- package/dist/rpcs-7cfbd91c.esm.js +30 -0
- package/dist/rpcs-9c4eb960.cjs.dev.js +35 -0
- package/dist/rpcs-b3c52116.cjs.prod.js +35 -0
- package/dist/wagmi-core.cjs.dev.js +126 -27
- package/dist/wagmi-core.cjs.prod.js +126 -27
- package/dist/wagmi-core.esm.js +124 -26
- package/package.json +29 -8
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.d.ts +1 -0
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.dev.js +38 -0
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.js +7 -0
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.prod.js +38 -0
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.esm.js +34 -0
- package/providers/alchemy/package.json +4 -0
- package/providers/infura/dist/wagmi-core-providers-infura.cjs.d.ts +1 -0
- package/providers/infura/dist/wagmi-core-providers-infura.cjs.dev.js +38 -0
- package/providers/infura/dist/wagmi-core-providers-infura.cjs.js +7 -0
- package/providers/infura/dist/wagmi-core-providers-infura.cjs.prod.js +38 -0
- package/providers/infura/dist/wagmi-core-providers-infura.esm.js +34 -0
- package/providers/infura/package.json +4 -0
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.d.ts +1 -0
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.dev.js +45 -0
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.js +7 -0
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.prod.js +45 -0
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.esm.js +41 -0
- package/providers/jsonRpc/package.json +4 -0
- package/providers/public/dist/wagmi-core-providers-public.cjs.d.ts +1 -0
- package/providers/public/dist/wagmi-core-providers-public.cjs.dev.js +34 -0
- package/providers/public/dist/wagmi-core-providers-public.cjs.js +7 -0
- package/providers/public/dist/wagmi-core-providers-public.cjs.prod.js +34 -0
- package/providers/public/dist/wagmi-core-providers-public.esm.js +30 -0
- package/providers/public/package.json +4 -0
- package/dist/classPrivateMethodGet-55c9909f.esm.js +0 -16
- package/dist/classPrivateMethodGet-976c8120.cjs.dev.js +0 -19
- package/dist/classPrivateMethodGet-d7330ed7.cjs.prod.js +0 -19
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var client = require('./client-
|
|
6
|
-
var base = require('./base-
|
|
5
|
+
var client = require('./client-08120ec7.cjs.dev.js');
|
|
6
|
+
var base = require('./base-3a506159.cjs.dev.js');
|
|
7
7
|
var ethers = require('ethers/lib/ethers');
|
|
8
8
|
var utils = require('ethers/lib/utils');
|
|
9
9
|
var ethers$1 = require('ethers');
|
|
10
|
-
require('./
|
|
10
|
+
var rpcs = require('./rpcs-9c4eb960.cjs.dev.js');
|
|
11
11
|
require('zustand/vanilla');
|
|
12
12
|
require('zustand/middleware');
|
|
13
13
|
require('eventemitter3');
|
|
@@ -15,7 +15,7 @@ require('eventemitter3');
|
|
|
15
15
|
// https://ethereum.org/en/developers/docs/standards/tokens/erc-20
|
|
16
16
|
const erc20ABI = ['event Approval(address indexed _owner, address indexed _spender, uint256 _value)', 'event Transfer(address indexed _from, address indexed _to, uint256 _value)', 'function allowance(address _owner, address _spender) public view returns (uint256 remaining)', 'function approve(address _spender, uint256 _value) public returns (bool success)', 'function balanceOf(address _owner) public view returns (uint256 balance)', 'function decimals() public view returns (uint8)', 'function name() public view returns (string)', 'function symbol() public view returns (string)', 'function totalSupply() public view returns (uint256)', 'function transfer(address _to, uint256 _value) public returns (bool success)', 'function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)']; // https://ethereum.org/en/developers/docs/standards/tokens/erc-721
|
|
17
17
|
|
|
18
|
-
const erc721ABI = ['event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId)
|
|
18
|
+
const erc721ABI = ['event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId)', 'event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved)', 'event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId)', 'function approve(address _approved, uint256 _tokenId) external payable', 'function balanceOf(address _owner) external view returns (uint256)', 'function getApproved(uint256 _tokenId) external view returns (address)', 'function isApprovedForAll(address _owner, address _operator) external view returns (bool)', 'function name() view returns (string memory)', 'function ownerOf(uint256 _tokenId) external view returns (address)', 'function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable', 'function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable', 'function setApprovalForAll(address _operator, bool _approved) external', 'function symbol() view returns (string memory)', 'function tokenByIndex(uint256 _index) view returns (uint256)', 'function tokenOfOwnerByIndex(address _owner, uint256 _index) view returns (uint256 tokenId)', 'function tokenURI(uint256 _tokenId) view returns (string memory)', 'function totalSupply() view returns (uint256)', 'function transferFrom(address _from, address _to, uint256 _tokenId) external payable'];
|
|
19
19
|
|
|
20
20
|
// https://github.com/ethers-io/ethers.js/blob/master/packages/units/src.ts/index.ts#L10-L18
|
|
21
21
|
const units = ['wei', 'kwei', 'mwei', 'gwei', 'szabo', 'finney', 'ether'];
|
|
@@ -162,6 +162,7 @@ function getNetwork() {
|
|
|
162
162
|
const activeChain = (_find = [...activeChains, ...base.allChains].find(x => x.id === chainId)) !== null && _find !== void 0 ? _find : {
|
|
163
163
|
id: chainId,
|
|
164
164
|
name: "Chain ".concat(chainId),
|
|
165
|
+
network: "".concat(chainId),
|
|
165
166
|
rpcUrls: {
|
|
166
167
|
default: ''
|
|
167
168
|
}
|
|
@@ -180,9 +181,8 @@ async function signMessage(args) {
|
|
|
180
181
|
const signer = await fetchSigner();
|
|
181
182
|
if (!signer) throw new base.ConnectorNotFoundError();
|
|
182
183
|
return await signer.signMessage(args.message);
|
|
183
|
-
} catch (
|
|
184
|
-
|
|
185
|
-
if (error_.code === 4001) error = new base.UserRejectedRequestError();
|
|
184
|
+
} catch (error) {
|
|
185
|
+
if (error.code === 4001) throw new base.UserRejectedRequestError(error);
|
|
186
186
|
throw error;
|
|
187
187
|
}
|
|
188
188
|
}
|
|
@@ -193,9 +193,8 @@ async function signTypedData(args) {
|
|
|
193
193
|
if (!signer) throw new base.ConnectorNotFoundError(); // Method name may be changed in the future, see https://docs.ethers.io/v5/api/signer/#Signer-signTypedData
|
|
194
194
|
|
|
195
195
|
return await signer._signTypedData(args.domain, args.types, args.value);
|
|
196
|
-
} catch (
|
|
197
|
-
|
|
198
|
-
if (error_.code === 4001) error = new base.UserRejectedRequestError();
|
|
196
|
+
} catch (error) {
|
|
197
|
+
if (error.code === 4001) throw new base.UserRejectedRequestError(error);
|
|
199
198
|
throw error;
|
|
200
199
|
}
|
|
201
200
|
}
|
|
@@ -371,17 +370,17 @@ async function fetchBlockNumber() {
|
|
|
371
370
|
function watchBlockNumber(args, callback) {
|
|
372
371
|
var _client$webSocketProv;
|
|
373
372
|
|
|
374
|
-
let
|
|
373
|
+
let previousProvider;
|
|
375
374
|
|
|
376
375
|
const createListener = provider => {
|
|
377
|
-
if (
|
|
378
|
-
var
|
|
376
|
+
if (previousProvider) {
|
|
377
|
+
var _previousProvider;
|
|
379
378
|
|
|
380
|
-
(
|
|
379
|
+
(_previousProvider = previousProvider) === null || _previousProvider === void 0 ? void 0 : _previousProvider.off('block', callback);
|
|
381
380
|
}
|
|
382
381
|
|
|
383
382
|
provider.on('block', callback);
|
|
384
|
-
|
|
383
|
+
previousProvider = provider;
|
|
385
384
|
};
|
|
386
385
|
|
|
387
386
|
const client$1 = client.getClient();
|
|
@@ -453,12 +452,11 @@ async function writeContract(contractConfig, functionName) {
|
|
|
453
452
|
const contract = getContract(contractConfig);
|
|
454
453
|
const contractWithSigner = contract.connect(signer);
|
|
455
454
|
const contractFunction = contractWithSigner[functionName];
|
|
456
|
-
if (!contractFunction) console.warn("\"".concat(functionName, "\" does not in interface for contract \"").concat(contractConfig.addressOrName, "\""));
|
|
455
|
+
if (!contractFunction) console.warn("\"".concat(functionName, "\" does not exist in interface for contract \"").concat(contractConfig.addressOrName, "\""));
|
|
457
456
|
const response = await contractFunction(...params);
|
|
458
457
|
return response;
|
|
459
|
-
} catch (
|
|
460
|
-
|
|
461
|
-
if (error_.code === 4001) error = new base.UserRejectedRequestError();
|
|
458
|
+
} catch (error) {
|
|
459
|
+
if (error.code === 4001) throw new base.UserRejectedRequestError(error);
|
|
462
460
|
throw error;
|
|
463
461
|
}
|
|
464
462
|
}
|
|
@@ -565,9 +563,8 @@ async function sendTransaction(args) {
|
|
|
565
563
|
if (!signer) throw new base.ConnectorNotFoundError();
|
|
566
564
|
const transaction = await signer.sendTransaction(args.request);
|
|
567
565
|
return transaction;
|
|
568
|
-
} catch (
|
|
569
|
-
|
|
570
|
-
if (error_.code === 4001) error = new base.UserRejectedRequestError();
|
|
566
|
+
} catch (error) {
|
|
567
|
+
if (error.code === 4001) throw new base.UserRejectedRequestError(error);
|
|
571
568
|
throw error;
|
|
572
569
|
}
|
|
573
570
|
}
|
|
@@ -592,31 +589,133 @@ async function waitForTransaction(_ref) {
|
|
|
592
589
|
return await promise;
|
|
593
590
|
}
|
|
594
591
|
|
|
592
|
+
function configureChains(defaultChains, providers) {
|
|
593
|
+
let {
|
|
594
|
+
minQuorum = 1,
|
|
595
|
+
targetQuorum = 1,
|
|
596
|
+
stallTimeout
|
|
597
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
598
|
+
if (targetQuorum < minQuorum) throw new Error('quorum cannot be lower than minQuorum');
|
|
599
|
+
let chains = [];
|
|
600
|
+
const providers_ = {};
|
|
601
|
+
const webSocketProviders_ = {};
|
|
602
|
+
|
|
603
|
+
for (const chain of defaultChains) {
|
|
604
|
+
let configExists = false;
|
|
605
|
+
|
|
606
|
+
for (const provider of providers) {
|
|
607
|
+
const apiConfig = provider(chain); // If no API configuration was found (ie. no RPC URL) for
|
|
608
|
+
// this provider, then we skip and check the next one.
|
|
609
|
+
|
|
610
|
+
if (!apiConfig) continue;
|
|
611
|
+
configExists = true;
|
|
612
|
+
|
|
613
|
+
if (!chains.some(_ref => {
|
|
614
|
+
let {
|
|
615
|
+
id
|
|
616
|
+
} = _ref;
|
|
617
|
+
return id === chain.id;
|
|
618
|
+
})) {
|
|
619
|
+
chains = [...chains, apiConfig.chain];
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
providers_[chain.id] = [...(providers_[chain.id] || []), apiConfig.provider];
|
|
623
|
+
|
|
624
|
+
if (apiConfig.webSocketProvider) {
|
|
625
|
+
webSocketProviders_[chain.id] = [...(webSocketProviders_[chain.id] || []), apiConfig.webSocketProvider];
|
|
626
|
+
}
|
|
627
|
+
} // If no API configuration was found across the providers
|
|
628
|
+
// then we throw an error to the consumer.
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
if (!configExists) {
|
|
632
|
+
throw new Error(["Could not find valid provider configuration for chain \"".concat(chain.name, "\".\n"), "You may need to add `jsonRpcProvider` to `configureChains` with the chain's RPC URLs.", 'Read more: https://wagmi.sh/docs/providers/jsonRpc'].join('\n'));
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
return {
|
|
637
|
+
chains,
|
|
638
|
+
provider: _ref2 => {
|
|
639
|
+
let {
|
|
640
|
+
chainId
|
|
641
|
+
} = _ref2;
|
|
642
|
+
const chainProviders = providers_[chainId && chains.some(x => x.id === chainId) ? chainId : defaultChains[0].id];
|
|
643
|
+
if (chainProviders.length === 1) return chainProviders[0]();
|
|
644
|
+
return fallbackProvider(targetQuorum, minQuorum, chainProviders, {
|
|
645
|
+
stallTimeout
|
|
646
|
+
});
|
|
647
|
+
},
|
|
648
|
+
webSocketProvider: _ref3 => {
|
|
649
|
+
let {
|
|
650
|
+
chainId
|
|
651
|
+
} = _ref3;
|
|
652
|
+
const chainWebSocketProviders = webSocketProviders_[chainId && chains.some(x => x.id === chainId) ? chainId : defaultChains[0].id];
|
|
653
|
+
if (!chainWebSocketProviders) return undefined;
|
|
654
|
+
if (chainWebSocketProviders.length === 1) return chainWebSocketProviders[0](); // WebSockets do not work with `fallbackProvider`
|
|
655
|
+
// Default to first available
|
|
656
|
+
|
|
657
|
+
return chainWebSocketProviders[0]();
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
function fallbackProvider(targetQuorum, minQuorum, providers_, _ref4) {
|
|
663
|
+
let {
|
|
664
|
+
stallTimeout
|
|
665
|
+
} = _ref4;
|
|
666
|
+
|
|
667
|
+
try {
|
|
668
|
+
return new ethers$1.providers.FallbackProvider(providers_.map((chainProvider, index) => {
|
|
669
|
+
var _provider$priority, _provider$stallTimeou;
|
|
670
|
+
|
|
671
|
+
const provider = chainProvider();
|
|
672
|
+
return {
|
|
673
|
+
provider,
|
|
674
|
+
priority: (_provider$priority = provider.priority) !== null && _provider$priority !== void 0 ? _provider$priority : index,
|
|
675
|
+
stallTimeout: (_provider$stallTimeou = provider.stallTimeout) !== null && _provider$stallTimeou !== void 0 ? _provider$stallTimeou : stallTimeout,
|
|
676
|
+
weight: provider.weight
|
|
677
|
+
};
|
|
678
|
+
}), targetQuorum);
|
|
679
|
+
} catch (error) {
|
|
680
|
+
var _error$message;
|
|
681
|
+
|
|
682
|
+
if (error !== null && error !== void 0 && (_error$message = error.message) !== null && _error$message !== void 0 && _error$message.includes('quorum will always fail; larger than total weight')) {
|
|
683
|
+
if (targetQuorum === minQuorum) throw error;
|
|
684
|
+
return fallbackProvider(targetQuorum - 1, minQuorum, providers_, {
|
|
685
|
+
stallTimeout
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
throw error;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
|
|
595
693
|
exports.Client = client.Client;
|
|
596
694
|
exports.InjectedConnector = client.InjectedConnector;
|
|
597
|
-
exports.WagmiClient = client.Client;
|
|
598
695
|
exports.createClient = client.createClient;
|
|
599
696
|
exports.createStorage = client.createStorage;
|
|
600
|
-
exports.createWagmiClient = client.createClient;
|
|
601
|
-
exports.createWagmiStorage = client.createStorage;
|
|
602
697
|
exports.noopStorage = client.noopStorage;
|
|
603
698
|
exports.AddChainError = base.AddChainError;
|
|
604
699
|
exports.ChainNotConfiguredError = base.ChainNotConfiguredError;
|
|
605
700
|
exports.Connector = base.Connector;
|
|
606
701
|
exports.ConnectorAlreadyConnectedError = base.ConnectorAlreadyConnectedError;
|
|
607
702
|
exports.ConnectorNotFoundError = base.ConnectorNotFoundError;
|
|
703
|
+
exports.ProviderRpcError = base.ProviderRpcError;
|
|
704
|
+
exports.ResourceUnavailableError = base.ResourceUnavailableError;
|
|
705
|
+
exports.RpcError = base.RpcError;
|
|
608
706
|
exports.SwitchChainError = base.SwitchChainError;
|
|
609
707
|
exports.SwitchChainNotSupportedError = base.SwitchChainNotSupportedError;
|
|
610
708
|
exports.UserRejectedRequestError = base.UserRejectedRequestError;
|
|
611
|
-
exports.alchemyRpcUrls = base.alchemyRpcUrls;
|
|
612
709
|
exports.allChains = base.allChains;
|
|
613
710
|
exports.chain = base.chain;
|
|
614
711
|
exports.chainId = base.chainId;
|
|
615
712
|
exports.defaultChains = base.defaultChains;
|
|
616
713
|
exports.defaultL2Chains = base.defaultL2Chains;
|
|
617
714
|
exports.etherscanBlockExplorers = base.etherscanBlockExplorers;
|
|
618
|
-
exports.infuraRpcUrls = base.infuraRpcUrls;
|
|
619
715
|
exports.normalizeChainId = base.normalizeChainId;
|
|
716
|
+
exports.alchemyRpcUrls = rpcs.alchemyRpcUrls;
|
|
717
|
+
exports.infuraRpcUrls = rpcs.infuraRpcUrls;
|
|
718
|
+
exports.configureChains = configureChains;
|
|
620
719
|
exports.connect = connect;
|
|
621
720
|
exports.disconnect = disconnect;
|
|
622
721
|
exports.erc20ABI = erc20ABI;
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var client = require('./client-
|
|
6
|
-
var base = require('./base-
|
|
5
|
+
var client = require('./client-332f5c43.cjs.prod.js');
|
|
6
|
+
var base = require('./base-cb4198f3.cjs.prod.js');
|
|
7
7
|
var ethers = require('ethers/lib/ethers');
|
|
8
8
|
var utils = require('ethers/lib/utils');
|
|
9
9
|
var ethers$1 = require('ethers');
|
|
10
|
-
require('./
|
|
10
|
+
var rpcs = require('./rpcs-b3c52116.cjs.prod.js');
|
|
11
11
|
require('zustand/vanilla');
|
|
12
12
|
require('zustand/middleware');
|
|
13
13
|
require('eventemitter3');
|
|
@@ -15,7 +15,7 @@ require('eventemitter3');
|
|
|
15
15
|
// https://ethereum.org/en/developers/docs/standards/tokens/erc-20
|
|
16
16
|
const erc20ABI = ['event Approval(address indexed _owner, address indexed _spender, uint256 _value)', 'event Transfer(address indexed _from, address indexed _to, uint256 _value)', 'function allowance(address _owner, address _spender) public view returns (uint256 remaining)', 'function approve(address _spender, uint256 _value) public returns (bool success)', 'function balanceOf(address _owner) public view returns (uint256 balance)', 'function decimals() public view returns (uint8)', 'function name() public view returns (string)', 'function symbol() public view returns (string)', 'function totalSupply() public view returns (uint256)', 'function transfer(address _to, uint256 _value) public returns (bool success)', 'function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)']; // https://ethereum.org/en/developers/docs/standards/tokens/erc-721
|
|
17
17
|
|
|
18
|
-
const erc721ABI = ['event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId)
|
|
18
|
+
const erc721ABI = ['event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId)', 'event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved)', 'event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId)', 'function approve(address _approved, uint256 _tokenId) external payable', 'function balanceOf(address _owner) external view returns (uint256)', 'function getApproved(uint256 _tokenId) external view returns (address)', 'function isApprovedForAll(address _owner, address _operator) external view returns (bool)', 'function name() view returns (string memory)', 'function ownerOf(uint256 _tokenId) external view returns (address)', 'function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable', 'function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable', 'function setApprovalForAll(address _operator, bool _approved) external', 'function symbol() view returns (string memory)', 'function tokenByIndex(uint256 _index) view returns (uint256)', 'function tokenOfOwnerByIndex(address _owner, uint256 _index) view returns (uint256 tokenId)', 'function tokenURI(uint256 _tokenId) view returns (string memory)', 'function totalSupply() view returns (uint256)', 'function transferFrom(address _from, address _to, uint256 _tokenId) external payable'];
|
|
19
19
|
|
|
20
20
|
// https://github.com/ethers-io/ethers.js/blob/master/packages/units/src.ts/index.ts#L10-L18
|
|
21
21
|
const units = ['wei', 'kwei', 'mwei', 'gwei', 'szabo', 'finney', 'ether'];
|
|
@@ -162,6 +162,7 @@ function getNetwork() {
|
|
|
162
162
|
const activeChain = (_find = [...activeChains, ...base.allChains].find(x => x.id === chainId)) !== null && _find !== void 0 ? _find : {
|
|
163
163
|
id: chainId,
|
|
164
164
|
name: "Chain ".concat(chainId),
|
|
165
|
+
network: "".concat(chainId),
|
|
165
166
|
rpcUrls: {
|
|
166
167
|
default: ''
|
|
167
168
|
}
|
|
@@ -180,9 +181,8 @@ async function signMessage(args) {
|
|
|
180
181
|
const signer = await fetchSigner();
|
|
181
182
|
if (!signer) throw new base.ConnectorNotFoundError();
|
|
182
183
|
return await signer.signMessage(args.message);
|
|
183
|
-
} catch (
|
|
184
|
-
|
|
185
|
-
if (error_.code === 4001) error = new base.UserRejectedRequestError();
|
|
184
|
+
} catch (error) {
|
|
185
|
+
if (error.code === 4001) throw new base.UserRejectedRequestError(error);
|
|
186
186
|
throw error;
|
|
187
187
|
}
|
|
188
188
|
}
|
|
@@ -193,9 +193,8 @@ async function signTypedData(args) {
|
|
|
193
193
|
if (!signer) throw new base.ConnectorNotFoundError(); // Method name may be changed in the future, see https://docs.ethers.io/v5/api/signer/#Signer-signTypedData
|
|
194
194
|
|
|
195
195
|
return await signer._signTypedData(args.domain, args.types, args.value);
|
|
196
|
-
} catch (
|
|
197
|
-
|
|
198
|
-
if (error_.code === 4001) error = new base.UserRejectedRequestError();
|
|
196
|
+
} catch (error) {
|
|
197
|
+
if (error.code === 4001) throw new base.UserRejectedRequestError(error);
|
|
199
198
|
throw error;
|
|
200
199
|
}
|
|
201
200
|
}
|
|
@@ -371,17 +370,17 @@ async function fetchBlockNumber() {
|
|
|
371
370
|
function watchBlockNumber(args, callback) {
|
|
372
371
|
var _client$webSocketProv;
|
|
373
372
|
|
|
374
|
-
let
|
|
373
|
+
let previousProvider;
|
|
375
374
|
|
|
376
375
|
const createListener = provider => {
|
|
377
|
-
if (
|
|
378
|
-
var
|
|
376
|
+
if (previousProvider) {
|
|
377
|
+
var _previousProvider;
|
|
379
378
|
|
|
380
|
-
(
|
|
379
|
+
(_previousProvider = previousProvider) === null || _previousProvider === void 0 ? void 0 : _previousProvider.off('block', callback);
|
|
381
380
|
}
|
|
382
381
|
|
|
383
382
|
provider.on('block', callback);
|
|
384
|
-
|
|
383
|
+
previousProvider = provider;
|
|
385
384
|
};
|
|
386
385
|
|
|
387
386
|
const client$1 = client.getClient();
|
|
@@ -453,12 +452,11 @@ async function writeContract(contractConfig, functionName) {
|
|
|
453
452
|
const contract = getContract(contractConfig);
|
|
454
453
|
const contractWithSigner = contract.connect(signer);
|
|
455
454
|
const contractFunction = contractWithSigner[functionName];
|
|
456
|
-
if (!contractFunction) console.warn("\"".concat(functionName, "\" does not in interface for contract \"").concat(contractConfig.addressOrName, "\""));
|
|
455
|
+
if (!contractFunction) console.warn("\"".concat(functionName, "\" does not exist in interface for contract \"").concat(contractConfig.addressOrName, "\""));
|
|
457
456
|
const response = await contractFunction(...params);
|
|
458
457
|
return response;
|
|
459
|
-
} catch (
|
|
460
|
-
|
|
461
|
-
if (error_.code === 4001) error = new base.UserRejectedRequestError();
|
|
458
|
+
} catch (error) {
|
|
459
|
+
if (error.code === 4001) throw new base.UserRejectedRequestError(error);
|
|
462
460
|
throw error;
|
|
463
461
|
}
|
|
464
462
|
}
|
|
@@ -565,9 +563,8 @@ async function sendTransaction(args) {
|
|
|
565
563
|
if (!signer) throw new base.ConnectorNotFoundError();
|
|
566
564
|
const transaction = await signer.sendTransaction(args.request);
|
|
567
565
|
return transaction;
|
|
568
|
-
} catch (
|
|
569
|
-
|
|
570
|
-
if (error_.code === 4001) error = new base.UserRejectedRequestError();
|
|
566
|
+
} catch (error) {
|
|
567
|
+
if (error.code === 4001) throw new base.UserRejectedRequestError(error);
|
|
571
568
|
throw error;
|
|
572
569
|
}
|
|
573
570
|
}
|
|
@@ -592,31 +589,133 @@ async function waitForTransaction(_ref) {
|
|
|
592
589
|
return await promise;
|
|
593
590
|
}
|
|
594
591
|
|
|
592
|
+
function configureChains(defaultChains, providers) {
|
|
593
|
+
let {
|
|
594
|
+
minQuorum = 1,
|
|
595
|
+
targetQuorum = 1,
|
|
596
|
+
stallTimeout
|
|
597
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
598
|
+
if (targetQuorum < minQuorum) throw new Error('quorum cannot be lower than minQuorum');
|
|
599
|
+
let chains = [];
|
|
600
|
+
const providers_ = {};
|
|
601
|
+
const webSocketProviders_ = {};
|
|
602
|
+
|
|
603
|
+
for (const chain of defaultChains) {
|
|
604
|
+
let configExists = false;
|
|
605
|
+
|
|
606
|
+
for (const provider of providers) {
|
|
607
|
+
const apiConfig = provider(chain); // If no API configuration was found (ie. no RPC URL) for
|
|
608
|
+
// this provider, then we skip and check the next one.
|
|
609
|
+
|
|
610
|
+
if (!apiConfig) continue;
|
|
611
|
+
configExists = true;
|
|
612
|
+
|
|
613
|
+
if (!chains.some(_ref => {
|
|
614
|
+
let {
|
|
615
|
+
id
|
|
616
|
+
} = _ref;
|
|
617
|
+
return id === chain.id;
|
|
618
|
+
})) {
|
|
619
|
+
chains = [...chains, apiConfig.chain];
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
providers_[chain.id] = [...(providers_[chain.id] || []), apiConfig.provider];
|
|
623
|
+
|
|
624
|
+
if (apiConfig.webSocketProvider) {
|
|
625
|
+
webSocketProviders_[chain.id] = [...(webSocketProviders_[chain.id] || []), apiConfig.webSocketProvider];
|
|
626
|
+
}
|
|
627
|
+
} // If no API configuration was found across the providers
|
|
628
|
+
// then we throw an error to the consumer.
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
if (!configExists) {
|
|
632
|
+
throw new Error(["Could not find valid provider configuration for chain \"".concat(chain.name, "\".\n"), "You may need to add `jsonRpcProvider` to `configureChains` with the chain's RPC URLs.", 'Read more: https://wagmi.sh/docs/providers/jsonRpc'].join('\n'));
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
return {
|
|
637
|
+
chains,
|
|
638
|
+
provider: _ref2 => {
|
|
639
|
+
let {
|
|
640
|
+
chainId
|
|
641
|
+
} = _ref2;
|
|
642
|
+
const chainProviders = providers_[chainId && chains.some(x => x.id === chainId) ? chainId : defaultChains[0].id];
|
|
643
|
+
if (chainProviders.length === 1) return chainProviders[0]();
|
|
644
|
+
return fallbackProvider(targetQuorum, minQuorum, chainProviders, {
|
|
645
|
+
stallTimeout
|
|
646
|
+
});
|
|
647
|
+
},
|
|
648
|
+
webSocketProvider: _ref3 => {
|
|
649
|
+
let {
|
|
650
|
+
chainId
|
|
651
|
+
} = _ref3;
|
|
652
|
+
const chainWebSocketProviders = webSocketProviders_[chainId && chains.some(x => x.id === chainId) ? chainId : defaultChains[0].id];
|
|
653
|
+
if (!chainWebSocketProviders) return undefined;
|
|
654
|
+
if (chainWebSocketProviders.length === 1) return chainWebSocketProviders[0](); // WebSockets do not work with `fallbackProvider`
|
|
655
|
+
// Default to first available
|
|
656
|
+
|
|
657
|
+
return chainWebSocketProviders[0]();
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
function fallbackProvider(targetQuorum, minQuorum, providers_, _ref4) {
|
|
663
|
+
let {
|
|
664
|
+
stallTimeout
|
|
665
|
+
} = _ref4;
|
|
666
|
+
|
|
667
|
+
try {
|
|
668
|
+
return new ethers$1.providers.FallbackProvider(providers_.map((chainProvider, index) => {
|
|
669
|
+
var _provider$priority, _provider$stallTimeou;
|
|
670
|
+
|
|
671
|
+
const provider = chainProvider();
|
|
672
|
+
return {
|
|
673
|
+
provider,
|
|
674
|
+
priority: (_provider$priority = provider.priority) !== null && _provider$priority !== void 0 ? _provider$priority : index,
|
|
675
|
+
stallTimeout: (_provider$stallTimeou = provider.stallTimeout) !== null && _provider$stallTimeou !== void 0 ? _provider$stallTimeou : stallTimeout,
|
|
676
|
+
weight: provider.weight
|
|
677
|
+
};
|
|
678
|
+
}), targetQuorum);
|
|
679
|
+
} catch (error) {
|
|
680
|
+
var _error$message;
|
|
681
|
+
|
|
682
|
+
if (error !== null && error !== void 0 && (_error$message = error.message) !== null && _error$message !== void 0 && _error$message.includes('quorum will always fail; larger than total weight')) {
|
|
683
|
+
if (targetQuorum === minQuorum) throw error;
|
|
684
|
+
return fallbackProvider(targetQuorum - 1, minQuorum, providers_, {
|
|
685
|
+
stallTimeout
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
throw error;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
|
|
595
693
|
exports.Client = client.Client;
|
|
596
694
|
exports.InjectedConnector = client.InjectedConnector;
|
|
597
|
-
exports.WagmiClient = client.Client;
|
|
598
695
|
exports.createClient = client.createClient;
|
|
599
696
|
exports.createStorage = client.createStorage;
|
|
600
|
-
exports.createWagmiClient = client.createClient;
|
|
601
|
-
exports.createWagmiStorage = client.createStorage;
|
|
602
697
|
exports.noopStorage = client.noopStorage;
|
|
603
698
|
exports.AddChainError = base.AddChainError;
|
|
604
699
|
exports.ChainNotConfiguredError = base.ChainNotConfiguredError;
|
|
605
700
|
exports.Connector = base.Connector;
|
|
606
701
|
exports.ConnectorAlreadyConnectedError = base.ConnectorAlreadyConnectedError;
|
|
607
702
|
exports.ConnectorNotFoundError = base.ConnectorNotFoundError;
|
|
703
|
+
exports.ProviderRpcError = base.ProviderRpcError;
|
|
704
|
+
exports.ResourceUnavailableError = base.ResourceUnavailableError;
|
|
705
|
+
exports.RpcError = base.RpcError;
|
|
608
706
|
exports.SwitchChainError = base.SwitchChainError;
|
|
609
707
|
exports.SwitchChainNotSupportedError = base.SwitchChainNotSupportedError;
|
|
610
708
|
exports.UserRejectedRequestError = base.UserRejectedRequestError;
|
|
611
|
-
exports.alchemyRpcUrls = base.alchemyRpcUrls;
|
|
612
709
|
exports.allChains = base.allChains;
|
|
613
710
|
exports.chain = base.chain;
|
|
614
711
|
exports.chainId = base.chainId;
|
|
615
712
|
exports.defaultChains = base.defaultChains;
|
|
616
713
|
exports.defaultL2Chains = base.defaultL2Chains;
|
|
617
714
|
exports.etherscanBlockExplorers = base.etherscanBlockExplorers;
|
|
618
|
-
exports.infuraRpcUrls = base.infuraRpcUrls;
|
|
619
715
|
exports.normalizeChainId = base.normalizeChainId;
|
|
716
|
+
exports.alchemyRpcUrls = rpcs.alchemyRpcUrls;
|
|
717
|
+
exports.infuraRpcUrls = rpcs.infuraRpcUrls;
|
|
718
|
+
exports.configureChains = configureChains;
|
|
620
719
|
exports.connect = connect;
|
|
621
720
|
exports.disconnect = disconnect;
|
|
622
721
|
exports.erc20ABI = erc20ABI;
|