@wagmi/core 0.6.12 → 0.7.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/chains/package.json +2 -2
- package/connectors/coinbaseWallet/package.json +2 -2
- package/connectors/metaMask/package.json +2 -2
- package/connectors/mock/package.json +2 -2
- package/connectors/walletConnect/package.json +2 -2
- package/dist/{declarations/src/connectors/base.d.ts → base-5bd9b5ed.d.ts} +8 -5
- package/dist/chains.d.ts +3 -0
- package/dist/chains.js +29 -0
- package/dist/chunk-2EDVJWOA.js +3496 -0
- package/dist/chunk-4DNFSL2K.js +376 -0
- package/dist/chunk-MQXBDTVK.js +29 -0
- package/dist/{declarations/src/connectors → connectors}/coinbaseWallet.d.ts +10 -6
- package/dist/connectors/coinbaseWallet.js +215 -0
- package/dist/{declarations/src/connectors → connectors}/metaMask.d.ts +11 -4
- package/dist/connectors/metaMask.js +115 -0
- package/dist/connectors/mock/index.d.ts +78 -0
- package/dist/connectors/mock/index.js +190 -0
- package/dist/{declarations/src/connectors → connectors}/walletConnect.d.ts +9 -5
- package/dist/connectors/walletConnect.js +160 -0
- package/dist/{declarations/src/types/contracts.d.ts → contracts-fb6a6ff0.d.ts} +122 -17
- package/dist/{declarations/src/types/index.d.ts → index-bacc1c49.d.ts} +83 -15
- package/dist/index.d.ts +1738 -0
- package/dist/index.js +165 -0
- package/dist/{declarations/src/connectors/injected.d.ts → injected-6980e5c3.d.ts} +9 -6
- package/dist/internal.d.ts +8 -0
- package/dist/internal.js +8 -0
- package/dist/providers/alchemy.d.ts +11 -0
- package/dist/providers/alchemy.js +32 -0
- package/dist/providers/infura.d.ts +11 -0
- package/dist/providers/infura.js +32 -0
- package/dist/providers/jsonRpc.d.ts +14 -0
- package/dist/providers/jsonRpc.js +44 -0
- package/dist/providers/public.d.ts +8 -0
- package/dist/providers/public.js +30 -0
- package/internal/package.json +2 -2
- package/package.json +40 -51
- package/providers/alchemy/package.json +2 -2
- package/providers/infura/package.json +2 -2
- package/providers/jsonRpc/package.json +2 -2
- package/providers/public/package.json +2 -2
- package/chains/dist/wagmi-core-chains.cjs.d.ts +0 -1
- package/chains/dist/wagmi-core-chains.cjs.dev.js +0 -26
- package/chains/dist/wagmi-core-chains.cjs.js +0 -7
- package/chains/dist/wagmi-core-chains.cjs.prod.js +0 -26
- package/chains/dist/wagmi-core-chains.esm.js +0 -2
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.d.ts +0 -1
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +0 -274
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.js +0 -7
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +0 -274
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +0 -252
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.d.ts +0 -1
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.dev.js +0 -153
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.js +0 -7
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.prod.js +0 -153
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.esm.js +0 -149
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.d.ts +0 -1
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.dev.js +0 -262
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.js +0 -7
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.prod.js +0 -262
- package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +0 -253
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.d.ts +0 -1
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.dev.js +0 -228
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.js +0 -7
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.prod.js +0 -228
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +0 -206
- package/dist/chains-73cc6c23.cjs.prod.js +0 -526
- package/dist/chains-8fce19d8.esm.js +0 -502
- package/dist/chains-fe1f4131.cjs.dev.js +0 -526
- package/dist/debounce-0862bf88.esm.js +0 -18
- package/dist/debounce-2d836dc9.cjs.prod.js +0 -20
- package/dist/debounce-46ac0312.cjs.dev.js +0 -20
- package/dist/declarations/src/actions/accounts/connect.d.ts +0 -18
- package/dist/declarations/src/actions/accounts/disconnect.d.ts +0 -1
- package/dist/declarations/src/actions/accounts/fetchBalance.d.ts +0 -19
- package/dist/declarations/src/actions/accounts/fetchSigner.d.ts +0 -7
- package/dist/declarations/src/actions/accounts/getAccount.d.ts +0 -36
- package/dist/declarations/src/actions/accounts/getNetwork.d.ts +0 -8
- package/dist/declarations/src/actions/accounts/index.d.ts +0 -12
- package/dist/declarations/src/actions/accounts/signMessage.d.ts +0 -7
- package/dist/declarations/src/actions/accounts/signTypedData.d.ts +0 -23
- package/dist/declarations/src/actions/accounts/switchNetwork.d.ts +0 -6
- package/dist/declarations/src/actions/accounts/watchAccount.d.ts +0 -12
- package/dist/declarations/src/actions/accounts/watchNetwork.d.ts +0 -10
- package/dist/declarations/src/actions/accounts/watchSigner.d.ts +0 -5
- package/dist/declarations/src/actions/contracts/fetchToken.d.ts +0 -21
- package/dist/declarations/src/actions/contracts/getContract.d.ts +0 -113
- package/dist/declarations/src/actions/contracts/index.d.ts +0 -11
- package/dist/declarations/src/actions/contracts/multicall.d.ts +0 -17
- package/dist/declarations/src/actions/contracts/prepareWriteContract.d.ts +0 -47
- package/dist/declarations/src/actions/contracts/readContract.d.ts +0 -15
- package/dist/declarations/src/actions/contracts/readContracts.d.ts +0 -28
- package/dist/declarations/src/actions/contracts/watchContractEvent.d.ts +0 -28
- package/dist/declarations/src/actions/contracts/watchMulticall.d.ts +0 -10
- package/dist/declarations/src/actions/contracts/watchReadContract.d.ts +0 -7
- package/dist/declarations/src/actions/contracts/watchReadContracts.d.ts +0 -10
- package/dist/declarations/src/actions/contracts/writeContract.d.ts +0 -72
- package/dist/declarations/src/actions/ens/fetchEnsAddress.d.ts +0 -9
- package/dist/declarations/src/actions/ens/fetchEnsAvatar.d.ts +0 -8
- package/dist/declarations/src/actions/ens/fetchEnsName.d.ts +0 -9
- package/dist/declarations/src/actions/ens/fetchEnsResolver.d.ts +0 -9
- package/dist/declarations/src/actions/ens/index.d.ts +0 -4
- package/dist/declarations/src/actions/index.d.ts +0 -6
- package/dist/declarations/src/actions/network-status/fetchBlockNumber.d.ts +0 -5
- package/dist/declarations/src/actions/network-status/fetchFeeData.d.ts +0 -16
- package/dist/declarations/src/actions/network-status/index.d.ts +0 -3
- package/dist/declarations/src/actions/network-status/watchBlockNumber.d.ts +0 -7
- package/dist/declarations/src/actions/providers/getProvider.d.ts +0 -7
- package/dist/declarations/src/actions/providers/getWebSocketProvider.d.ts +0 -7
- package/dist/declarations/src/actions/providers/index.d.ts +0 -4
- package/dist/declarations/src/actions/providers/watchProvider.d.ts +0 -4
- package/dist/declarations/src/actions/providers/watchWebSocketProvider.d.ts +0 -4
- package/dist/declarations/src/actions/transactions/fetchTransaction.d.ts +0 -21
- package/dist/declarations/src/actions/transactions/index.d.ts +0 -4
- package/dist/declarations/src/actions/transactions/prepareSendTransaction.d.ts +0 -37
- package/dist/declarations/src/actions/transactions/sendTransaction.d.ts +0 -48
- package/dist/declarations/src/actions/transactions/waitForTransaction.d.ts +0 -18
- package/dist/declarations/src/chains.d.ts +0 -1
- package/dist/declarations/src/client.d.ts +0 -91
- package/dist/declarations/src/connectors/index.d.ts +0 -2
- package/dist/declarations/src/connectors/mock/connector.d.ts +0 -34
- package/dist/declarations/src/connectors/mock/index.d.ts +0 -2
- package/dist/declarations/src/connectors/mock/provider.d.ts +0 -41
- package/dist/declarations/src/constants/abis.d.ts +0 -941
- package/dist/declarations/src/constants/blockExplorers.d.ts +0 -9
- package/dist/declarations/src/constants/chains.d.ts +0 -64
- package/dist/declarations/src/constants/index.d.ts +0 -7
- package/dist/declarations/src/constants/rpcs.d.ts +0 -11
- package/dist/declarations/src/constants/units.d.ts +0 -1
- package/dist/declarations/src/errors.d.ts +0 -134
- package/dist/declarations/src/index.d.ts +0 -14
- package/dist/declarations/src/internal.d.ts +0 -3
- package/dist/declarations/src/providers/alchemy.d.ts +0 -6
- package/dist/declarations/src/providers/infura.d.ts +0 -6
- package/dist/declarations/src/providers/jsonRpc.d.ts +0 -10
- package/dist/declarations/src/providers/public.d.ts +0 -4
- package/dist/declarations/src/storage.d.ts +0 -12
- package/dist/declarations/src/types/utils.d.ts +0 -103
- package/dist/declarations/src/utils/assertActiveChain.d.ts +0 -5
- package/dist/declarations/src/utils/configureChains.d.ts +0 -26
- package/dist/declarations/src/utils/debounce.d.ts +0 -1
- package/dist/declarations/src/utils/deepEqual.d.ts +0 -2
- package/dist/declarations/src/utils/getInjectedName.d.ts +0 -2
- package/dist/declarations/src/utils/index.d.ts +0 -11
- package/dist/declarations/src/utils/logger.d.ts +0 -1
- package/dist/declarations/src/utils/minimizeContractInterface.d.ts +0 -5
- package/dist/declarations/src/utils/normalizeChainId.d.ts +0 -1
- package/dist/declarations/src/utils/normalizeFunctionName.d.ts +0 -17
- package/dist/declarations/src/utils/parseContractResult.d.ts +0 -7
- package/dist/getProvider-3b1af4e6.cjs.dev.js +0 -1143
- package/dist/getProvider-84f303a1.cjs.prod.js +0 -1143
- package/dist/getProvider-97db849e.esm.js +0 -1105
- package/dist/rpcs-38f4faba.cjs.prod.js +0 -57
- package/dist/rpcs-52ea3d8d.cjs.dev.js +0 -57
- package/dist/rpcs-d533516e.esm.js +0 -51
- package/dist/wagmi-core.cjs.d.ts +0 -1
- package/dist/wagmi-core.cjs.dev.js +0 -2683
- package/dist/wagmi-core.cjs.js +0 -7
- package/dist/wagmi-core.cjs.prod.js +0 -2683
- package/dist/wagmi-core.esm.js +0 -2599
- package/internal/dist/wagmi-core-internal.cjs.d.ts +0 -1
- package/internal/dist/wagmi-core-internal.cjs.dev.js +0 -9
- package/internal/dist/wagmi-core-internal.cjs.js +0 -7
- package/internal/dist/wagmi-core-internal.cjs.prod.js +0 -9
- package/internal/dist/wagmi-core-internal.esm.js +0 -1
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.d.ts +0 -1
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.dev.js +0 -36
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.js +0 -7
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.prod.js +0 -36
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.esm.js +0 -32
- package/providers/infura/dist/wagmi-core-providers-infura.cjs.d.ts +0 -1
- package/providers/infura/dist/wagmi-core-providers-infura.cjs.dev.js +0 -36
- package/providers/infura/dist/wagmi-core-providers-infura.cjs.js +0 -7
- package/providers/infura/dist/wagmi-core-providers-infura.cjs.prod.js +0 -36
- package/providers/infura/dist/wagmi-core-providers-infura.esm.js +0 -32
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.d.ts +0 -1
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.dev.js +0 -46
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.js +0 -7
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.prod.js +0 -46
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.esm.js +0 -42
- package/providers/public/dist/wagmi-core-providers-public.cjs.d.ts +0 -1
- package/providers/public/dist/wagmi-core-providers-public.cjs.dev.js +0 -32
- package/providers/public/dist/wagmi-core-providers-public.cjs.js +0 -7
- package/providers/public/dist/wagmi-core-providers-public.cjs.prod.js +0 -32
- package/providers/public/dist/wagmi-core-providers-public.esm.js +0 -28
package/dist/wagmi-core.esm.js
DELETED
|
@@ -1,2599 +0,0 @@
|
|
|
1
|
-
import { C as ChainMismatchError, g as getClient, a as ChainNotConfiguredError, b as ConnectorAlreadyConnectedError, c as ContractResultDecodeError, d as ConnectorNotFoundError, e as ContractMethodDoesNotExistError, f as getProvider, P as ProviderChainsNotFound, h as ChainDoesNotSupportMulticallError, i as ContractMethodRevertedError, j as ContractMethodNoResultError, U as UserRejectedRequestError, n as normalizeChainId, S as SwitchChainNotSupportedError } from './getProvider-97db849e.esm.js';
|
|
2
|
-
export { A as AddChainError, h as ChainDoesNotSupportMulticallError, C as ChainMismatchError, a as ChainNotConfiguredError, l as Client, m as Connector, b as ConnectorAlreadyConnectedError, d as ConnectorNotFoundError, e as ContractMethodDoesNotExistError, j as ContractMethodNoResultError, i as ContractMethodRevertedError, c 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, k as createClient, r as createStorage, f as getProvider, s as noopStorage, n as normalizeChainId } from './getProvider-97db849e.esm.js';
|
|
3
|
-
import { Contract, logger } from 'ethers/lib/ethers';
|
|
4
|
-
import { FunctionFragment, isAddress, FormatTypes, parseBytes32String, formatUnits, getAddress, Logger } from 'ethers/lib/utils';
|
|
5
|
-
import { providers, BigNumber, Contract as Contract$1 } from 'ethers';
|
|
6
|
-
import { m as mainnet } from './chains-8fce19d8.esm.js';
|
|
7
|
-
export { a as allChains, c as chain, b as chainId, d as defaultChains, e as defaultL2Chains, f as etherscanBlockExplorers } from './chains-8fce19d8.esm.js';
|
|
8
|
-
import shallow from 'zustand/shallow';
|
|
9
|
-
import { d as debounce } from './debounce-0862bf88.esm.js';
|
|
10
|
-
export { a as alchemyRpcUrls, i as infuraRpcUrls, p as publicRpcUrls } from './rpcs-d533516e.esm.js';
|
|
11
|
-
import 'zustand/middleware';
|
|
12
|
-
import 'zustand/vanilla';
|
|
13
|
-
import 'eventemitter3';
|
|
14
|
-
|
|
15
|
-
function configureChains(defaultChains, providers) {
|
|
16
|
-
let {
|
|
17
|
-
minQuorum = 1,
|
|
18
|
-
pollingInterval = 4_000,
|
|
19
|
-
targetQuorum = 1,
|
|
20
|
-
stallTimeout
|
|
21
|
-
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
22
|
-
if (!defaultChains.length) throw new Error('must have at least one chain');
|
|
23
|
-
if (targetQuorum < minQuorum) throw new Error('quorum cannot be lower than minQuorum');
|
|
24
|
-
let chains = [];
|
|
25
|
-
const providers_ = {};
|
|
26
|
-
const webSocketProviders_ = {};
|
|
27
|
-
|
|
28
|
-
for (const chain of defaultChains) {
|
|
29
|
-
let configExists = false;
|
|
30
|
-
|
|
31
|
-
for (const provider of providers) {
|
|
32
|
-
const apiConfig = provider(chain); // If no API configuration was found (ie. no RPC URL) for
|
|
33
|
-
// this provider, then we skip and check the next one.
|
|
34
|
-
|
|
35
|
-
if (!apiConfig) continue;
|
|
36
|
-
configExists = true;
|
|
37
|
-
|
|
38
|
-
if (!chains.some(_ref => {
|
|
39
|
-
let {
|
|
40
|
-
id
|
|
41
|
-
} = _ref;
|
|
42
|
-
return id === chain.id;
|
|
43
|
-
})) {
|
|
44
|
-
chains = [...chains, apiConfig.chain];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
providers_[chain.id] = [...(providers_[chain.id] || []), apiConfig.provider];
|
|
48
|
-
|
|
49
|
-
if (apiConfig.webSocketProvider) {
|
|
50
|
-
webSocketProviders_[chain.id] = [...(webSocketProviders_[chain.id] || []), apiConfig.webSocketProvider];
|
|
51
|
-
}
|
|
52
|
-
} // If no API configuration was found across the providers
|
|
53
|
-
// then we throw an error to the consumer.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (!configExists) {
|
|
57
|
-
throw new Error([`Could not find valid provider configuration for chain "${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'));
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
chains,
|
|
63
|
-
provider: _ref2 => {
|
|
64
|
-
let {
|
|
65
|
-
chainId
|
|
66
|
-
} = _ref2;
|
|
67
|
-
const activeChain = chains.find(x => x.id === chainId) ?? defaultChains[0];
|
|
68
|
-
const chainProviders = providers_[activeChain.id];
|
|
69
|
-
if (!chainProviders || !chainProviders[0]) throw new Error(`No providers configured for chain "${activeChain.id}"`);
|
|
70
|
-
let provider;
|
|
71
|
-
|
|
72
|
-
if (chainProviders.length === 1) {
|
|
73
|
-
provider = chainProviders[0]();
|
|
74
|
-
} else {
|
|
75
|
-
provider = fallbackProvider(targetQuorum, minQuorum, chainProviders, {
|
|
76
|
-
stallTimeout
|
|
77
|
-
});
|
|
78
|
-
} // Formatter workaround as Celo does not provide `gasLimit` or `difficulty` on eth_getBlockByNumber.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (activeChain.id === 42220) {
|
|
82
|
-
provider.formatter.formats.block = { ...provider.formatter.formats.block,
|
|
83
|
-
difficulty: () => 0,
|
|
84
|
-
gasLimit: () => 0
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return Object.assign(provider, {
|
|
89
|
-
chains,
|
|
90
|
-
pollingInterval
|
|
91
|
-
});
|
|
92
|
-
},
|
|
93
|
-
webSocketProvider: _ref3 => {
|
|
94
|
-
var _chainWebSocketProvid;
|
|
95
|
-
|
|
96
|
-
let {
|
|
97
|
-
chainId
|
|
98
|
-
} = _ref3;
|
|
99
|
-
const activeChain = chains.find(x => x.id === chainId) ?? defaultChains[0];
|
|
100
|
-
const chainWebSocketProviders = webSocketProviders_[activeChain.id];
|
|
101
|
-
if (!chainWebSocketProviders) return undefined;
|
|
102
|
-
const provider = (_chainWebSocketProvid = chainWebSocketProviders[0]) === null || _chainWebSocketProvid === void 0 ? void 0 : _chainWebSocketProvid.call(chainWebSocketProviders); // Formatter workaround as Celo does not provide `gasLimit` or `difficulty` on eth_getBlockByNumber.
|
|
103
|
-
|
|
104
|
-
if (provider && activeChain.id === 42220) {
|
|
105
|
-
provider.formatter.formats.block = { ...provider.formatter.formats.block,
|
|
106
|
-
difficulty: () => 0,
|
|
107
|
-
gasLimit: () => 0
|
|
108
|
-
};
|
|
109
|
-
} // WebSockets do not work with `fallbackProvider`
|
|
110
|
-
// Default to first available
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return Object.assign(provider || {}, {
|
|
114
|
-
chains
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function fallbackProvider(targetQuorum, minQuorum, providers_, _ref4) {
|
|
121
|
-
let {
|
|
122
|
-
stallTimeout
|
|
123
|
-
} = _ref4;
|
|
124
|
-
|
|
125
|
-
try {
|
|
126
|
-
return new providers.FallbackProvider(providers_.map((chainProvider, index) => {
|
|
127
|
-
const provider = chainProvider();
|
|
128
|
-
return {
|
|
129
|
-
provider,
|
|
130
|
-
priority: provider.priority ?? index,
|
|
131
|
-
stallTimeout: provider.stallTimeout ?? stallTimeout,
|
|
132
|
-
weight: provider.weight
|
|
133
|
-
};
|
|
134
|
-
}), targetQuorum);
|
|
135
|
-
} catch (error) {
|
|
136
|
-
var _error$message;
|
|
137
|
-
|
|
138
|
-
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')) {
|
|
139
|
-
if (targetQuorum === minQuorum) throw error;
|
|
140
|
-
return fallbackProvider(targetQuorum - 1, minQuorum, providers_, {
|
|
141
|
-
stallTimeout
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
throw error;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function assertActiveChain(_ref) {
|
|
150
|
-
let {
|
|
151
|
-
chainId,
|
|
152
|
-
signer
|
|
153
|
-
} = _ref;
|
|
154
|
-
// Check that active chain and target chain match
|
|
155
|
-
const {
|
|
156
|
-
chain: activeChain,
|
|
157
|
-
chains
|
|
158
|
-
} = getNetwork();
|
|
159
|
-
const activeChainId = activeChain === null || activeChain === void 0 ? void 0 : activeChain.id;
|
|
160
|
-
|
|
161
|
-
if (activeChainId && chainId !== activeChainId) {
|
|
162
|
-
var _chains$find, _chains$find2;
|
|
163
|
-
|
|
164
|
-
throw new ChainMismatchError({
|
|
165
|
-
activeChain: ((_chains$find = chains.find(x => x.id === activeChainId)) === null || _chains$find === void 0 ? void 0 : _chains$find.name) ?? `Chain ${activeChainId}`,
|
|
166
|
-
targetChain: ((_chains$find2 = chains.find(x => x.id === chainId)) === null || _chains$find2 === void 0 ? void 0 : _chains$find2.name) ?? `Chain ${chainId}`
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (signer) {
|
|
171
|
-
var _signer$provider, _signer$provider$netw;
|
|
172
|
-
|
|
173
|
-
// Check that signer's chain and target chain match
|
|
174
|
-
const signerChainId = (_signer$provider = signer.provider) === null || _signer$provider === void 0 ? void 0 : (_signer$provider$netw = _signer$provider.network) === null || _signer$provider$netw === void 0 ? void 0 : _signer$provider$netw.chainId;
|
|
175
|
-
|
|
176
|
-
if (signerChainId && chainId !== signerChainId) {
|
|
177
|
-
const connector = getClient().connector;
|
|
178
|
-
throw new ChainNotConfiguredError({
|
|
179
|
-
chainId,
|
|
180
|
-
connectorId: (connector === null || connector === void 0 ? void 0 : connector.id) ?? 'unknown'
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/** Forked from https://github.com/epoberezkin/fast-deep-equal */
|
|
187
|
-
function deepEqual(a, b) {
|
|
188
|
-
if (a === b) return true;
|
|
189
|
-
|
|
190
|
-
if (a && b && typeof a === 'object' && typeof b === 'object') {
|
|
191
|
-
if (a.constructor !== b.constructor) return false;
|
|
192
|
-
let length;
|
|
193
|
-
let i;
|
|
194
|
-
|
|
195
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
196
|
-
length = a.length;
|
|
197
|
-
if (length != b.length) return false;
|
|
198
|
-
|
|
199
|
-
for (i = length; i-- !== 0;) if (!deepEqual(a[i], b[i])) return false;
|
|
200
|
-
|
|
201
|
-
return true;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
|
|
205
|
-
if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
|
|
206
|
-
const keys = Object.keys(a);
|
|
207
|
-
length = keys.length;
|
|
208
|
-
if (length !== Object.keys(b).length) return false;
|
|
209
|
-
|
|
210
|
-
for (i = length; i-- !== 0;) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
|
|
211
|
-
|
|
212
|
-
for (i = length; i-- !== 0;) {
|
|
213
|
-
const key = keys[i];
|
|
214
|
-
if (key && !deepEqual(a[key], b[key])) return false;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
return true;
|
|
218
|
-
} // true if both NaN, false otherwise
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
return a !== a && b !== b;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Get normalized function name from contract
|
|
226
|
-
*
|
|
227
|
-
* @param contract — Contract
|
|
228
|
-
* @param functionName — Function name
|
|
229
|
-
* @param args — Function arguments (used to disambiguate overloaded functions)
|
|
230
|
-
*
|
|
231
|
-
* @returns Normalized function name
|
|
232
|
-
*/
|
|
233
|
-
|
|
234
|
-
function normalizeFunctionName(_ref) {
|
|
235
|
-
let {
|
|
236
|
-
contract,
|
|
237
|
-
functionName,
|
|
238
|
-
args = []
|
|
239
|
-
} = _ref;
|
|
240
|
-
// If `functionName` exists in contract, return it.
|
|
241
|
-
if (functionName in contract.functions) return functionName; // Otherwise, check if `functionName` is an overloaded function based on `args` shape.
|
|
242
|
-
|
|
243
|
-
const argsLength = (args === null || args === void 0 ? void 0 : args.length) ?? 0;
|
|
244
|
-
const overloadFunctions = Object.keys(contract.functions).filter(x => x.startsWith(`${functionName}(`)).map(x => ({
|
|
245
|
-
name: x,
|
|
246
|
-
fragment: FunctionFragment.fromString(x)
|
|
247
|
-
})).filter(x => argsLength === x.fragment.inputs.length);
|
|
248
|
-
|
|
249
|
-
for (const overloadFunction of overloadFunctions) {
|
|
250
|
-
const matched = args.every((arg, index) => {
|
|
251
|
-
const abiParameter = overloadFunction.fragment.inputs[index];
|
|
252
|
-
return isArgOfType(arg, abiParameter);
|
|
253
|
-
});
|
|
254
|
-
if (matched) return overloadFunction.name;
|
|
255
|
-
} // Wasn't able to find overload, just return function name.
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
return functionName;
|
|
259
|
-
}
|
|
260
|
-
function isArgOfType(arg, abiParameter) {
|
|
261
|
-
const argType = typeof arg;
|
|
262
|
-
const abiParameterType = abiParameter.type;
|
|
263
|
-
|
|
264
|
-
switch (abiParameterType) {
|
|
265
|
-
case 'address':
|
|
266
|
-
return isAddress(arg);
|
|
267
|
-
|
|
268
|
-
case 'bool':
|
|
269
|
-
return argType === 'boolean';
|
|
270
|
-
|
|
271
|
-
case 'function':
|
|
272
|
-
return argType === 'string';
|
|
273
|
-
|
|
274
|
-
case 'string':
|
|
275
|
-
return argType === 'string';
|
|
276
|
-
|
|
277
|
-
default:
|
|
278
|
-
{
|
|
279
|
-
if (abiParameterType === 'tuple' && 'components' in abiParameter) return Object.values(abiParameter.components).every((component, index) => {
|
|
280
|
-
return isArgOfType(Object.values(arg)[index], component);
|
|
281
|
-
}); // `(u)int<M>`: (un)signed integer type of `M` bits, `0 < M <= 256`, `M % 8 == 0`
|
|
282
|
-
// https://regexr.com/6v8hp
|
|
283
|
-
|
|
284
|
-
if (/^u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/.test(abiParameterType)) return argType === 'number' || argType === 'bigint' || BigNumber.isBigNumber(arg); // `bytes<M>`: binary type of `M` bytes, `0 < M <= 32`
|
|
285
|
-
// https://regexr.com/6va55
|
|
286
|
-
|
|
287
|
-
if (/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/.test(abiParameterType)) return argType === 'string' || arg instanceof Uint8Array; // fixed-length (`<type>[M]`) and dynamic (`<type>[]`) arrays
|
|
288
|
-
// https://regexr.com/6va6i
|
|
289
|
-
|
|
290
|
-
if (/[a-z]+[1-9]{0,3}(\[[0-9]{0,}\])+$/.test(abiParameterType)) {
|
|
291
|
-
return Array.isArray(arg) && arg.every(x => isArgOfType(x, { ...abiParameter,
|
|
292
|
-
// Pop off `[]` or `[M]` from end of type
|
|
293
|
-
type: abiParameterType.replace(/(\[[0-9]{0,}\])$/, '')
|
|
294
|
-
}));
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
return false;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
function logWarn(message) {
|
|
303
|
-
var _getClient, _getClient$config$log, _getClient$config$log2;
|
|
304
|
-
|
|
305
|
-
(_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);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
function minimizeContractInterface(config) {
|
|
309
|
-
try {
|
|
310
|
-
const minimizedAbi = config.abi.filter(x => x.type === 'function' && x.name === config.functionName);
|
|
311
|
-
if (minimizedAbi.length === 0) throw new Error('Invalid ABI');
|
|
312
|
-
return minimizedAbi;
|
|
313
|
-
} catch (error) {
|
|
314
|
-
const abi = Contract.getInterface(config.abi).format(FormatTypes.full);
|
|
315
|
-
const minimizedInterface = Array.isArray(abi) ? abi : [abi];
|
|
316
|
-
return minimizedInterface.filter(i => i.includes(config.functionName));
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
function isPlainArray(value) {
|
|
321
|
-
return Array.isArray(value) && Object.keys(value).length === value.length;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
function parseContractResult(_ref) {
|
|
325
|
-
let {
|
|
326
|
-
abi,
|
|
327
|
-
data,
|
|
328
|
-
functionName
|
|
329
|
-
} = _ref;
|
|
330
|
-
|
|
331
|
-
if (data && isPlainArray(data)) {
|
|
332
|
-
var _fragment$outputs;
|
|
333
|
-
|
|
334
|
-
const iface = Contract.getInterface(abi);
|
|
335
|
-
const fragment = iface.getFunction(functionName);
|
|
336
|
-
const isTuple = (((_fragment$outputs = fragment.outputs) === null || _fragment$outputs === void 0 ? void 0 : _fragment$outputs.length) || 0) > 1;
|
|
337
|
-
const data_ = isTuple ? data : [data];
|
|
338
|
-
const encodedResult = iface.encodeFunctionResult(functionName, data_);
|
|
339
|
-
const decodedResult = iface.decodeFunctionResult(functionName, encodedResult);
|
|
340
|
-
return isTuple ? decodedResult : decodedResult[0];
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
return data;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* [ERC-20 Token Standard](https://ethereum.org/en/developers/docs/standards/tokens/erc-20)
|
|
348
|
-
*/
|
|
349
|
-
const erc20ABI = [{
|
|
350
|
-
type: 'event',
|
|
351
|
-
name: 'Approval',
|
|
352
|
-
inputs: [{
|
|
353
|
-
indexed: true,
|
|
354
|
-
name: 'owner',
|
|
355
|
-
type: 'address'
|
|
356
|
-
}, {
|
|
357
|
-
indexed: true,
|
|
358
|
-
name: 'spender',
|
|
359
|
-
type: 'address'
|
|
360
|
-
}, {
|
|
361
|
-
indexed: false,
|
|
362
|
-
name: 'value',
|
|
363
|
-
type: 'uint256'
|
|
364
|
-
}]
|
|
365
|
-
}, {
|
|
366
|
-
type: 'event',
|
|
367
|
-
name: 'Transfer',
|
|
368
|
-
inputs: [{
|
|
369
|
-
indexed: true,
|
|
370
|
-
name: 'from',
|
|
371
|
-
type: 'address'
|
|
372
|
-
}, {
|
|
373
|
-
indexed: true,
|
|
374
|
-
name: 'to',
|
|
375
|
-
type: 'address'
|
|
376
|
-
}, {
|
|
377
|
-
indexed: false,
|
|
378
|
-
name: 'value',
|
|
379
|
-
type: 'uint256'
|
|
380
|
-
}]
|
|
381
|
-
}, {
|
|
382
|
-
type: 'function',
|
|
383
|
-
name: 'allowance',
|
|
384
|
-
stateMutability: 'view',
|
|
385
|
-
inputs: [{
|
|
386
|
-
name: 'owner',
|
|
387
|
-
type: 'address'
|
|
388
|
-
}, {
|
|
389
|
-
name: 'spender',
|
|
390
|
-
type: 'address'
|
|
391
|
-
}],
|
|
392
|
-
outputs: [{
|
|
393
|
-
name: '',
|
|
394
|
-
type: 'uint256'
|
|
395
|
-
}]
|
|
396
|
-
}, {
|
|
397
|
-
type: 'function',
|
|
398
|
-
name: 'approve',
|
|
399
|
-
stateMutability: 'nonpayable',
|
|
400
|
-
inputs: [{
|
|
401
|
-
name: 'spender',
|
|
402
|
-
type: 'address'
|
|
403
|
-
}, {
|
|
404
|
-
name: 'amount',
|
|
405
|
-
type: 'uint256'
|
|
406
|
-
}],
|
|
407
|
-
outputs: [{
|
|
408
|
-
name: '',
|
|
409
|
-
type: 'bool'
|
|
410
|
-
}]
|
|
411
|
-
}, {
|
|
412
|
-
type: 'function',
|
|
413
|
-
name: 'balanceOf',
|
|
414
|
-
stateMutability: 'view',
|
|
415
|
-
inputs: [{
|
|
416
|
-
name: 'account',
|
|
417
|
-
type: 'address'
|
|
418
|
-
}],
|
|
419
|
-
outputs: [{
|
|
420
|
-
name: '',
|
|
421
|
-
type: 'uint256'
|
|
422
|
-
}]
|
|
423
|
-
}, {
|
|
424
|
-
type: 'function',
|
|
425
|
-
name: 'decimals',
|
|
426
|
-
stateMutability: 'view',
|
|
427
|
-
inputs: [],
|
|
428
|
-
outputs: [{
|
|
429
|
-
name: '',
|
|
430
|
-
type: 'uint8'
|
|
431
|
-
}]
|
|
432
|
-
}, {
|
|
433
|
-
type: 'function',
|
|
434
|
-
name: 'name',
|
|
435
|
-
stateMutability: 'view',
|
|
436
|
-
inputs: [],
|
|
437
|
-
outputs: [{
|
|
438
|
-
name: '',
|
|
439
|
-
type: 'string'
|
|
440
|
-
}]
|
|
441
|
-
}, {
|
|
442
|
-
type: 'function',
|
|
443
|
-
name: 'symbol',
|
|
444
|
-
stateMutability: 'view',
|
|
445
|
-
inputs: [],
|
|
446
|
-
outputs: [{
|
|
447
|
-
name: '',
|
|
448
|
-
type: 'string'
|
|
449
|
-
}]
|
|
450
|
-
}, {
|
|
451
|
-
type: 'function',
|
|
452
|
-
name: 'totalSupply',
|
|
453
|
-
stateMutability: 'view',
|
|
454
|
-
inputs: [],
|
|
455
|
-
outputs: [{
|
|
456
|
-
name: '',
|
|
457
|
-
type: 'uint256'
|
|
458
|
-
}]
|
|
459
|
-
}, {
|
|
460
|
-
type: 'function',
|
|
461
|
-
name: 'transfer',
|
|
462
|
-
stateMutability: 'nonpayable',
|
|
463
|
-
inputs: [{
|
|
464
|
-
name: 'recipient',
|
|
465
|
-
type: 'address'
|
|
466
|
-
}, {
|
|
467
|
-
name: 'amount',
|
|
468
|
-
type: 'uint256'
|
|
469
|
-
}],
|
|
470
|
-
outputs: [{
|
|
471
|
-
name: '',
|
|
472
|
-
type: 'bool'
|
|
473
|
-
}]
|
|
474
|
-
}, {
|
|
475
|
-
type: 'function',
|
|
476
|
-
name: 'transferFrom',
|
|
477
|
-
stateMutability: 'nonpayable',
|
|
478
|
-
inputs: [{
|
|
479
|
-
name: 'sender',
|
|
480
|
-
type: 'address'
|
|
481
|
-
}, {
|
|
482
|
-
name: 'recipient',
|
|
483
|
-
type: 'address'
|
|
484
|
-
}, {
|
|
485
|
-
name: 'amount',
|
|
486
|
-
type: 'uint256'
|
|
487
|
-
}],
|
|
488
|
-
outputs: [{
|
|
489
|
-
name: '',
|
|
490
|
-
type: 'bool'
|
|
491
|
-
}]
|
|
492
|
-
}];
|
|
493
|
-
/**
|
|
494
|
-
* [bytes32-flavored ERC-20](https://docs.makerdao.com/smart-contract-modules/mkr-module#4.-gotchas-potential-source-of-user-error)
|
|
495
|
-
* for tokens (ie. Maker) that use bytes32 instead of string.
|
|
496
|
-
*/
|
|
497
|
-
|
|
498
|
-
const erc20ABI_bytes32 = [{
|
|
499
|
-
type: 'event',
|
|
500
|
-
name: 'Approval',
|
|
501
|
-
inputs: [{
|
|
502
|
-
indexed: true,
|
|
503
|
-
name: 'owner',
|
|
504
|
-
type: 'address'
|
|
505
|
-
}, {
|
|
506
|
-
indexed: true,
|
|
507
|
-
name: 'spender',
|
|
508
|
-
type: 'address'
|
|
509
|
-
}, {
|
|
510
|
-
indexed: false,
|
|
511
|
-
name: 'value',
|
|
512
|
-
type: 'uint256'
|
|
513
|
-
}]
|
|
514
|
-
}, {
|
|
515
|
-
type: 'event',
|
|
516
|
-
name: 'Transfer',
|
|
517
|
-
inputs: [{
|
|
518
|
-
indexed: true,
|
|
519
|
-
name: 'from',
|
|
520
|
-
type: 'address'
|
|
521
|
-
}, {
|
|
522
|
-
indexed: true,
|
|
523
|
-
name: 'to',
|
|
524
|
-
type: 'address'
|
|
525
|
-
}, {
|
|
526
|
-
indexed: false,
|
|
527
|
-
name: 'value',
|
|
528
|
-
type: 'uint256'
|
|
529
|
-
}]
|
|
530
|
-
}, {
|
|
531
|
-
type: 'function',
|
|
532
|
-
name: 'allowance',
|
|
533
|
-
stateMutability: 'view',
|
|
534
|
-
inputs: [{
|
|
535
|
-
name: 'owner',
|
|
536
|
-
type: 'address'
|
|
537
|
-
}, {
|
|
538
|
-
name: 'spender',
|
|
539
|
-
type: 'address'
|
|
540
|
-
}],
|
|
541
|
-
outputs: [{
|
|
542
|
-
name: '',
|
|
543
|
-
type: 'uint256'
|
|
544
|
-
}]
|
|
545
|
-
}, {
|
|
546
|
-
type: 'function',
|
|
547
|
-
name: 'approve',
|
|
548
|
-
stateMutability: 'nonpayable',
|
|
549
|
-
inputs: [{
|
|
550
|
-
name: 'spender',
|
|
551
|
-
type: 'address'
|
|
552
|
-
}, {
|
|
553
|
-
name: 'amount',
|
|
554
|
-
type: 'uint256'
|
|
555
|
-
}],
|
|
556
|
-
outputs: [{
|
|
557
|
-
name: '',
|
|
558
|
-
type: 'bool'
|
|
559
|
-
}]
|
|
560
|
-
}, {
|
|
561
|
-
type: 'function',
|
|
562
|
-
name: 'balanceOf',
|
|
563
|
-
stateMutability: 'view',
|
|
564
|
-
inputs: [{
|
|
565
|
-
name: 'account',
|
|
566
|
-
type: 'address'
|
|
567
|
-
}],
|
|
568
|
-
outputs: [{
|
|
569
|
-
name: '',
|
|
570
|
-
type: 'uint256'
|
|
571
|
-
}]
|
|
572
|
-
}, {
|
|
573
|
-
type: 'function',
|
|
574
|
-
name: 'decimals',
|
|
575
|
-
stateMutability: 'view',
|
|
576
|
-
inputs: [],
|
|
577
|
-
outputs: [{
|
|
578
|
-
name: '',
|
|
579
|
-
type: 'uint8'
|
|
580
|
-
}]
|
|
581
|
-
}, {
|
|
582
|
-
type: 'function',
|
|
583
|
-
name: 'name',
|
|
584
|
-
stateMutability: 'view',
|
|
585
|
-
inputs: [],
|
|
586
|
-
outputs: [{
|
|
587
|
-
name: '',
|
|
588
|
-
type: 'bytes32'
|
|
589
|
-
}]
|
|
590
|
-
}, {
|
|
591
|
-
type: 'function',
|
|
592
|
-
name: 'symbol',
|
|
593
|
-
stateMutability: 'view',
|
|
594
|
-
inputs: [],
|
|
595
|
-
outputs: [{
|
|
596
|
-
name: '',
|
|
597
|
-
type: 'bytes32'
|
|
598
|
-
}]
|
|
599
|
-
}, {
|
|
600
|
-
type: 'function',
|
|
601
|
-
name: 'totalSupply',
|
|
602
|
-
stateMutability: 'view',
|
|
603
|
-
inputs: [],
|
|
604
|
-
outputs: [{
|
|
605
|
-
name: '',
|
|
606
|
-
type: 'uint256'
|
|
607
|
-
}]
|
|
608
|
-
}, {
|
|
609
|
-
type: 'function',
|
|
610
|
-
name: 'transfer',
|
|
611
|
-
stateMutability: 'nonpayable',
|
|
612
|
-
inputs: [{
|
|
613
|
-
name: 'recipient',
|
|
614
|
-
type: 'address'
|
|
615
|
-
}, {
|
|
616
|
-
name: 'amount',
|
|
617
|
-
type: 'uint256'
|
|
618
|
-
}],
|
|
619
|
-
outputs: [{
|
|
620
|
-
name: '',
|
|
621
|
-
type: 'bool'
|
|
622
|
-
}]
|
|
623
|
-
}, {
|
|
624
|
-
type: 'function',
|
|
625
|
-
name: 'transferFrom',
|
|
626
|
-
stateMutability: 'nonpayable',
|
|
627
|
-
inputs: [{
|
|
628
|
-
name: 'sender',
|
|
629
|
-
type: 'address'
|
|
630
|
-
}, {
|
|
631
|
-
name: 'recipient',
|
|
632
|
-
type: 'address'
|
|
633
|
-
}, {
|
|
634
|
-
name: 'amount',
|
|
635
|
-
type: 'uint256'
|
|
636
|
-
}],
|
|
637
|
-
outputs: [{
|
|
638
|
-
name: '',
|
|
639
|
-
type: 'bool'
|
|
640
|
-
}]
|
|
641
|
-
}];
|
|
642
|
-
/**
|
|
643
|
-
* [ERC-721 Non-Fungible Token Standard](https://ethereum.org/en/developers/docs/standards/tokens/erc-721)
|
|
644
|
-
*/
|
|
645
|
-
|
|
646
|
-
const erc721ABI = [{
|
|
647
|
-
type: 'event',
|
|
648
|
-
name: 'Approval',
|
|
649
|
-
inputs: [{
|
|
650
|
-
indexed: true,
|
|
651
|
-
name: 'owner',
|
|
652
|
-
type: 'address'
|
|
653
|
-
}, {
|
|
654
|
-
indexed: true,
|
|
655
|
-
name: 'spender',
|
|
656
|
-
type: 'address'
|
|
657
|
-
}, {
|
|
658
|
-
indexed: true,
|
|
659
|
-
name: 'tokenId',
|
|
660
|
-
type: 'uint256'
|
|
661
|
-
}]
|
|
662
|
-
}, {
|
|
663
|
-
type: 'event',
|
|
664
|
-
name: 'ApprovalForAll',
|
|
665
|
-
inputs: [{
|
|
666
|
-
indexed: true,
|
|
667
|
-
name: 'owner',
|
|
668
|
-
type: 'address'
|
|
669
|
-
}, {
|
|
670
|
-
indexed: true,
|
|
671
|
-
name: 'operator',
|
|
672
|
-
type: 'address'
|
|
673
|
-
}, {
|
|
674
|
-
indexed: false,
|
|
675
|
-
name: 'approved',
|
|
676
|
-
type: 'bool'
|
|
677
|
-
}]
|
|
678
|
-
}, {
|
|
679
|
-
type: 'event',
|
|
680
|
-
name: 'Transfer',
|
|
681
|
-
inputs: [{
|
|
682
|
-
indexed: true,
|
|
683
|
-
name: 'from',
|
|
684
|
-
type: 'address'
|
|
685
|
-
}, {
|
|
686
|
-
indexed: true,
|
|
687
|
-
name: 'to',
|
|
688
|
-
type: 'address'
|
|
689
|
-
}, {
|
|
690
|
-
indexed: true,
|
|
691
|
-
name: 'tokenId',
|
|
692
|
-
type: 'uint256'
|
|
693
|
-
}]
|
|
694
|
-
}, {
|
|
695
|
-
type: 'function',
|
|
696
|
-
name: 'approve',
|
|
697
|
-
stateMutability: 'payable',
|
|
698
|
-
inputs: [{
|
|
699
|
-
name: 'spender',
|
|
700
|
-
type: 'address'
|
|
701
|
-
}, {
|
|
702
|
-
name: 'tokenId',
|
|
703
|
-
type: 'uint256'
|
|
704
|
-
}],
|
|
705
|
-
outputs: []
|
|
706
|
-
}, {
|
|
707
|
-
type: 'function',
|
|
708
|
-
name: 'balanceOf',
|
|
709
|
-
stateMutability: 'view',
|
|
710
|
-
inputs: [{
|
|
711
|
-
name: 'account',
|
|
712
|
-
type: 'address'
|
|
713
|
-
}],
|
|
714
|
-
outputs: [{
|
|
715
|
-
name: '',
|
|
716
|
-
type: 'uint256'
|
|
717
|
-
}]
|
|
718
|
-
}, {
|
|
719
|
-
type: 'function',
|
|
720
|
-
name: 'getApproved',
|
|
721
|
-
stateMutability: 'view',
|
|
722
|
-
inputs: [{
|
|
723
|
-
name: 'tokenId',
|
|
724
|
-
type: 'uint256'
|
|
725
|
-
}],
|
|
726
|
-
outputs: [{
|
|
727
|
-
name: '',
|
|
728
|
-
type: 'address'
|
|
729
|
-
}]
|
|
730
|
-
}, {
|
|
731
|
-
type: 'function',
|
|
732
|
-
name: 'isApprovedForAll',
|
|
733
|
-
stateMutability: 'view',
|
|
734
|
-
inputs: [{
|
|
735
|
-
name: 'owner',
|
|
736
|
-
type: 'address'
|
|
737
|
-
}, {
|
|
738
|
-
name: 'operator',
|
|
739
|
-
type: 'address'
|
|
740
|
-
}],
|
|
741
|
-
outputs: [{
|
|
742
|
-
name: '',
|
|
743
|
-
type: 'bool'
|
|
744
|
-
}]
|
|
745
|
-
}, {
|
|
746
|
-
type: 'function',
|
|
747
|
-
name: 'name',
|
|
748
|
-
stateMutability: 'view',
|
|
749
|
-
inputs: [],
|
|
750
|
-
outputs: [{
|
|
751
|
-
name: '',
|
|
752
|
-
type: 'string'
|
|
753
|
-
}]
|
|
754
|
-
}, {
|
|
755
|
-
type: 'function',
|
|
756
|
-
name: 'ownerOf',
|
|
757
|
-
stateMutability: 'view',
|
|
758
|
-
inputs: [{
|
|
759
|
-
name: 'tokenId',
|
|
760
|
-
type: 'uint256'
|
|
761
|
-
}],
|
|
762
|
-
outputs: [{
|
|
763
|
-
name: 'owner',
|
|
764
|
-
type: 'address'
|
|
765
|
-
}]
|
|
766
|
-
}, {
|
|
767
|
-
type: 'function',
|
|
768
|
-
name: 'safeTransferFrom',
|
|
769
|
-
stateMutability: 'payable',
|
|
770
|
-
inputs: [{
|
|
771
|
-
name: 'from',
|
|
772
|
-
type: 'address'
|
|
773
|
-
}, {
|
|
774
|
-
name: 'to',
|
|
775
|
-
type: 'address'
|
|
776
|
-
}, {
|
|
777
|
-
name: 'tokenId',
|
|
778
|
-
type: 'uint256'
|
|
779
|
-
}],
|
|
780
|
-
outputs: []
|
|
781
|
-
}, {
|
|
782
|
-
type: 'function',
|
|
783
|
-
name: 'safeTransferFrom',
|
|
784
|
-
stateMutability: 'nonpayable',
|
|
785
|
-
inputs: [{
|
|
786
|
-
name: 'from',
|
|
787
|
-
type: 'address'
|
|
788
|
-
}, {
|
|
789
|
-
name: 'to',
|
|
790
|
-
type: 'address'
|
|
791
|
-
}, {
|
|
792
|
-
name: 'id',
|
|
793
|
-
type: 'uint256'
|
|
794
|
-
}, {
|
|
795
|
-
name: 'data',
|
|
796
|
-
type: 'bytes'
|
|
797
|
-
}],
|
|
798
|
-
outputs: []
|
|
799
|
-
}, {
|
|
800
|
-
type: 'function',
|
|
801
|
-
name: 'setApprovalForAll',
|
|
802
|
-
stateMutability: 'nonpayable',
|
|
803
|
-
inputs: [{
|
|
804
|
-
name: 'operator',
|
|
805
|
-
type: 'address'
|
|
806
|
-
}, {
|
|
807
|
-
name: 'approved',
|
|
808
|
-
type: 'bool'
|
|
809
|
-
}],
|
|
810
|
-
outputs: []
|
|
811
|
-
}, {
|
|
812
|
-
type: 'function',
|
|
813
|
-
name: 'symbol',
|
|
814
|
-
stateMutability: 'view',
|
|
815
|
-
inputs: [],
|
|
816
|
-
outputs: [{
|
|
817
|
-
name: '',
|
|
818
|
-
type: 'string'
|
|
819
|
-
}]
|
|
820
|
-
}, {
|
|
821
|
-
type: 'function',
|
|
822
|
-
name: 'tokenByIndex',
|
|
823
|
-
stateMutability: 'view',
|
|
824
|
-
inputs: [{
|
|
825
|
-
name: 'index',
|
|
826
|
-
type: 'uint256'
|
|
827
|
-
}],
|
|
828
|
-
outputs: [{
|
|
829
|
-
name: '',
|
|
830
|
-
type: 'uint256'
|
|
831
|
-
}]
|
|
832
|
-
}, {
|
|
833
|
-
type: 'function',
|
|
834
|
-
name: 'tokenByIndex',
|
|
835
|
-
stateMutability: 'view',
|
|
836
|
-
inputs: [{
|
|
837
|
-
name: 'owner',
|
|
838
|
-
type: 'address'
|
|
839
|
-
}, {
|
|
840
|
-
name: 'index',
|
|
841
|
-
type: 'uint256'
|
|
842
|
-
}],
|
|
843
|
-
outputs: [{
|
|
844
|
-
name: 'tokenId',
|
|
845
|
-
type: 'uint256'
|
|
846
|
-
}]
|
|
847
|
-
}, {
|
|
848
|
-
type: 'function',
|
|
849
|
-
name: 'tokenURI',
|
|
850
|
-
stateMutability: 'view',
|
|
851
|
-
inputs: [{
|
|
852
|
-
name: 'tokenId',
|
|
853
|
-
type: 'uint256'
|
|
854
|
-
}],
|
|
855
|
-
outputs: [{
|
|
856
|
-
name: '',
|
|
857
|
-
type: 'string'
|
|
858
|
-
}]
|
|
859
|
-
}, {
|
|
860
|
-
type: 'function',
|
|
861
|
-
name: 'totalSupply',
|
|
862
|
-
stateMutability: 'view',
|
|
863
|
-
inputs: [],
|
|
864
|
-
outputs: [{
|
|
865
|
-
name: '',
|
|
866
|
-
type: 'uint256'
|
|
867
|
-
}]
|
|
868
|
-
}, {
|
|
869
|
-
type: 'function',
|
|
870
|
-
name: 'transferFrom',
|
|
871
|
-
stateMutability: 'payable',
|
|
872
|
-
inputs: [{
|
|
873
|
-
name: 'sender',
|
|
874
|
-
type: 'address'
|
|
875
|
-
}, {
|
|
876
|
-
name: 'recipient',
|
|
877
|
-
type: 'address'
|
|
878
|
-
}, {
|
|
879
|
-
name: 'tokeId',
|
|
880
|
-
type: 'uint256'
|
|
881
|
-
}],
|
|
882
|
-
outputs: []
|
|
883
|
-
}];
|
|
884
|
-
/**
|
|
885
|
-
* [Multicall3](https://github.com/mds1/multicall)
|
|
886
|
-
*/
|
|
887
|
-
|
|
888
|
-
const multicallABI = [{
|
|
889
|
-
inputs: [{
|
|
890
|
-
components: [{
|
|
891
|
-
name: 'target',
|
|
892
|
-
type: 'address'
|
|
893
|
-
}, {
|
|
894
|
-
name: 'allowFailure',
|
|
895
|
-
type: 'bool'
|
|
896
|
-
}, {
|
|
897
|
-
name: 'callData',
|
|
898
|
-
type: 'bytes'
|
|
899
|
-
}],
|
|
900
|
-
name: 'calls',
|
|
901
|
-
type: 'tuple[]'
|
|
902
|
-
}],
|
|
903
|
-
name: 'aggregate3',
|
|
904
|
-
outputs: [{
|
|
905
|
-
components: [{
|
|
906
|
-
name: 'success',
|
|
907
|
-
type: 'bool'
|
|
908
|
-
}, {
|
|
909
|
-
name: 'returnData',
|
|
910
|
-
type: 'bytes'
|
|
911
|
-
}],
|
|
912
|
-
name: 'returnData',
|
|
913
|
-
type: 'tuple[]'
|
|
914
|
-
}],
|
|
915
|
-
stateMutability: 'view',
|
|
916
|
-
type: 'function'
|
|
917
|
-
}];
|
|
918
|
-
/**
|
|
919
|
-
* [ERC-4626 Tokenized Vaults Standard](https://ethereum.org/en/developers/docs/standards/tokens/erc-4626)
|
|
920
|
-
*/
|
|
921
|
-
|
|
922
|
-
const erc4626ABI = [{
|
|
923
|
-
anonymous: false,
|
|
924
|
-
inputs: [{
|
|
925
|
-
indexed: true,
|
|
926
|
-
name: 'owner',
|
|
927
|
-
type: 'address'
|
|
928
|
-
}, {
|
|
929
|
-
indexed: true,
|
|
930
|
-
name: 'spender',
|
|
931
|
-
type: 'address'
|
|
932
|
-
}, {
|
|
933
|
-
indexed: false,
|
|
934
|
-
name: 'value',
|
|
935
|
-
type: 'uint256'
|
|
936
|
-
}],
|
|
937
|
-
name: 'Approval',
|
|
938
|
-
type: 'event'
|
|
939
|
-
}, {
|
|
940
|
-
anonymous: false,
|
|
941
|
-
inputs: [{
|
|
942
|
-
indexed: true,
|
|
943
|
-
name: 'sender',
|
|
944
|
-
type: 'address'
|
|
945
|
-
}, {
|
|
946
|
-
indexed: true,
|
|
947
|
-
name: 'receiver',
|
|
948
|
-
type: 'address'
|
|
949
|
-
}, {
|
|
950
|
-
indexed: false,
|
|
951
|
-
name: 'assets',
|
|
952
|
-
type: 'uint256'
|
|
953
|
-
}, {
|
|
954
|
-
indexed: false,
|
|
955
|
-
name: 'shares',
|
|
956
|
-
type: 'uint256'
|
|
957
|
-
}],
|
|
958
|
-
name: 'Deposit',
|
|
959
|
-
type: 'event'
|
|
960
|
-
}, {
|
|
961
|
-
anonymous: false,
|
|
962
|
-
inputs: [{
|
|
963
|
-
indexed: true,
|
|
964
|
-
name: 'from',
|
|
965
|
-
type: 'address'
|
|
966
|
-
}, {
|
|
967
|
-
indexed: true,
|
|
968
|
-
name: 'to',
|
|
969
|
-
type: 'address'
|
|
970
|
-
}, {
|
|
971
|
-
indexed: false,
|
|
972
|
-
name: 'value',
|
|
973
|
-
type: 'uint256'
|
|
974
|
-
}],
|
|
975
|
-
name: 'Transfer',
|
|
976
|
-
type: 'event'
|
|
977
|
-
}, {
|
|
978
|
-
anonymous: false,
|
|
979
|
-
inputs: [{
|
|
980
|
-
indexed: true,
|
|
981
|
-
name: 'sender',
|
|
982
|
-
type: 'address'
|
|
983
|
-
}, {
|
|
984
|
-
indexed: true,
|
|
985
|
-
name: 'receiver',
|
|
986
|
-
type: 'address'
|
|
987
|
-
}, {
|
|
988
|
-
indexed: true,
|
|
989
|
-
name: 'owner',
|
|
990
|
-
type: 'address'
|
|
991
|
-
}, {
|
|
992
|
-
indexed: false,
|
|
993
|
-
name: 'assets',
|
|
994
|
-
type: 'uint256'
|
|
995
|
-
}, {
|
|
996
|
-
indexed: false,
|
|
997
|
-
name: 'shares',
|
|
998
|
-
type: 'uint256'
|
|
999
|
-
}],
|
|
1000
|
-
name: 'Withdraw',
|
|
1001
|
-
type: 'event'
|
|
1002
|
-
}, {
|
|
1003
|
-
inputs: [{
|
|
1004
|
-
name: 'owner',
|
|
1005
|
-
type: 'address'
|
|
1006
|
-
}, {
|
|
1007
|
-
name: 'spender',
|
|
1008
|
-
type: 'address'
|
|
1009
|
-
}],
|
|
1010
|
-
name: 'allowance',
|
|
1011
|
-
outputs: [{
|
|
1012
|
-
name: '',
|
|
1013
|
-
type: 'uint256'
|
|
1014
|
-
}],
|
|
1015
|
-
stateMutability: 'view',
|
|
1016
|
-
type: 'function'
|
|
1017
|
-
}, {
|
|
1018
|
-
inputs: [{
|
|
1019
|
-
name: 'spender',
|
|
1020
|
-
type: 'address'
|
|
1021
|
-
}, {
|
|
1022
|
-
name: 'amount',
|
|
1023
|
-
type: 'uint256'
|
|
1024
|
-
}],
|
|
1025
|
-
name: 'approve',
|
|
1026
|
-
outputs: [{
|
|
1027
|
-
name: '',
|
|
1028
|
-
type: 'bool'
|
|
1029
|
-
}],
|
|
1030
|
-
stateMutability: 'nonpayable',
|
|
1031
|
-
type: 'function'
|
|
1032
|
-
}, {
|
|
1033
|
-
inputs: [],
|
|
1034
|
-
name: 'asset',
|
|
1035
|
-
outputs: [{
|
|
1036
|
-
name: 'assetTokenAddress',
|
|
1037
|
-
type: 'address'
|
|
1038
|
-
}],
|
|
1039
|
-
stateMutability: 'view',
|
|
1040
|
-
type: 'function'
|
|
1041
|
-
}, {
|
|
1042
|
-
inputs: [{
|
|
1043
|
-
name: 'account',
|
|
1044
|
-
type: 'address'
|
|
1045
|
-
}],
|
|
1046
|
-
name: 'balanceOf',
|
|
1047
|
-
outputs: [{
|
|
1048
|
-
name: '',
|
|
1049
|
-
type: 'uint256'
|
|
1050
|
-
}],
|
|
1051
|
-
stateMutability: 'view',
|
|
1052
|
-
type: 'function'
|
|
1053
|
-
}, {
|
|
1054
|
-
inputs: [{
|
|
1055
|
-
name: 'shares',
|
|
1056
|
-
type: 'uint256'
|
|
1057
|
-
}],
|
|
1058
|
-
name: 'convertToAssets',
|
|
1059
|
-
outputs: [{
|
|
1060
|
-
name: 'assets',
|
|
1061
|
-
type: 'uint256'
|
|
1062
|
-
}],
|
|
1063
|
-
stateMutability: 'view',
|
|
1064
|
-
type: 'function'
|
|
1065
|
-
}, {
|
|
1066
|
-
inputs: [{
|
|
1067
|
-
name: 'assets',
|
|
1068
|
-
type: 'uint256'
|
|
1069
|
-
}],
|
|
1070
|
-
name: 'convertToShares',
|
|
1071
|
-
outputs: [{
|
|
1072
|
-
name: 'shares',
|
|
1073
|
-
type: 'uint256'
|
|
1074
|
-
}],
|
|
1075
|
-
stateMutability: 'view',
|
|
1076
|
-
type: 'function'
|
|
1077
|
-
}, {
|
|
1078
|
-
inputs: [{
|
|
1079
|
-
name: 'assets',
|
|
1080
|
-
type: 'uint256'
|
|
1081
|
-
}, {
|
|
1082
|
-
name: 'receiver',
|
|
1083
|
-
type: 'address'
|
|
1084
|
-
}],
|
|
1085
|
-
name: 'deposit',
|
|
1086
|
-
outputs: [{
|
|
1087
|
-
name: 'shares',
|
|
1088
|
-
type: 'uint256'
|
|
1089
|
-
}],
|
|
1090
|
-
stateMutability: 'nonpayable',
|
|
1091
|
-
type: 'function'
|
|
1092
|
-
}, {
|
|
1093
|
-
inputs: [{
|
|
1094
|
-
name: 'caller',
|
|
1095
|
-
type: 'address'
|
|
1096
|
-
}],
|
|
1097
|
-
name: 'maxDeposit',
|
|
1098
|
-
outputs: [{
|
|
1099
|
-
name: 'maxAssets',
|
|
1100
|
-
type: 'uint256'
|
|
1101
|
-
}],
|
|
1102
|
-
stateMutability: 'view',
|
|
1103
|
-
type: 'function'
|
|
1104
|
-
}, {
|
|
1105
|
-
inputs: [{
|
|
1106
|
-
name: 'caller',
|
|
1107
|
-
type: 'address'
|
|
1108
|
-
}],
|
|
1109
|
-
name: 'maxMint',
|
|
1110
|
-
outputs: [{
|
|
1111
|
-
name: 'maxShares',
|
|
1112
|
-
type: 'uint256'
|
|
1113
|
-
}],
|
|
1114
|
-
stateMutability: 'view',
|
|
1115
|
-
type: 'function'
|
|
1116
|
-
}, {
|
|
1117
|
-
inputs: [{
|
|
1118
|
-
name: 'owner',
|
|
1119
|
-
type: 'address'
|
|
1120
|
-
}],
|
|
1121
|
-
name: 'maxRedeem',
|
|
1122
|
-
outputs: [{
|
|
1123
|
-
name: 'maxShares',
|
|
1124
|
-
type: 'uint256'
|
|
1125
|
-
}],
|
|
1126
|
-
stateMutability: 'view',
|
|
1127
|
-
type: 'function'
|
|
1128
|
-
}, {
|
|
1129
|
-
inputs: [{
|
|
1130
|
-
name: 'owner',
|
|
1131
|
-
type: 'address'
|
|
1132
|
-
}],
|
|
1133
|
-
name: 'maxWithdraw',
|
|
1134
|
-
outputs: [{
|
|
1135
|
-
name: 'maxAssets',
|
|
1136
|
-
type: 'uint256'
|
|
1137
|
-
}],
|
|
1138
|
-
stateMutability: 'view',
|
|
1139
|
-
type: 'function'
|
|
1140
|
-
}, {
|
|
1141
|
-
inputs: [{
|
|
1142
|
-
name: 'shares',
|
|
1143
|
-
type: 'uint256'
|
|
1144
|
-
}, {
|
|
1145
|
-
name: 'receiver',
|
|
1146
|
-
type: 'address'
|
|
1147
|
-
}],
|
|
1148
|
-
name: 'mint',
|
|
1149
|
-
outputs: [{
|
|
1150
|
-
name: 'assets',
|
|
1151
|
-
type: 'uint256'
|
|
1152
|
-
}],
|
|
1153
|
-
stateMutability: 'nonpayable',
|
|
1154
|
-
type: 'function'
|
|
1155
|
-
}, {
|
|
1156
|
-
inputs: [{
|
|
1157
|
-
name: 'assets',
|
|
1158
|
-
type: 'uint256'
|
|
1159
|
-
}],
|
|
1160
|
-
name: 'previewDeposit',
|
|
1161
|
-
outputs: [{
|
|
1162
|
-
name: 'shares',
|
|
1163
|
-
type: 'uint256'
|
|
1164
|
-
}],
|
|
1165
|
-
stateMutability: 'view',
|
|
1166
|
-
type: 'function'
|
|
1167
|
-
}, {
|
|
1168
|
-
inputs: [{
|
|
1169
|
-
name: 'shares',
|
|
1170
|
-
type: 'uint256'
|
|
1171
|
-
}],
|
|
1172
|
-
name: 'previewMint',
|
|
1173
|
-
outputs: [{
|
|
1174
|
-
name: 'assets',
|
|
1175
|
-
type: 'uint256'
|
|
1176
|
-
}],
|
|
1177
|
-
stateMutability: 'view',
|
|
1178
|
-
type: 'function'
|
|
1179
|
-
}, {
|
|
1180
|
-
inputs: [{
|
|
1181
|
-
name: 'shares',
|
|
1182
|
-
type: 'uint256'
|
|
1183
|
-
}],
|
|
1184
|
-
name: 'previewRedeem',
|
|
1185
|
-
outputs: [{
|
|
1186
|
-
name: 'assets',
|
|
1187
|
-
type: 'uint256'
|
|
1188
|
-
}],
|
|
1189
|
-
stateMutability: 'view',
|
|
1190
|
-
type: 'function'
|
|
1191
|
-
}, {
|
|
1192
|
-
inputs: [{
|
|
1193
|
-
name: 'assets',
|
|
1194
|
-
type: 'uint256'
|
|
1195
|
-
}],
|
|
1196
|
-
name: 'previewWithdraw',
|
|
1197
|
-
outputs: [{
|
|
1198
|
-
name: 'shares',
|
|
1199
|
-
type: 'uint256'
|
|
1200
|
-
}],
|
|
1201
|
-
stateMutability: 'view',
|
|
1202
|
-
type: 'function'
|
|
1203
|
-
}, {
|
|
1204
|
-
inputs: [{
|
|
1205
|
-
name: 'shares',
|
|
1206
|
-
type: 'uint256'
|
|
1207
|
-
}, {
|
|
1208
|
-
name: 'receiver',
|
|
1209
|
-
type: 'address'
|
|
1210
|
-
}, {
|
|
1211
|
-
name: 'owner',
|
|
1212
|
-
type: 'address'
|
|
1213
|
-
}],
|
|
1214
|
-
name: 'redeem',
|
|
1215
|
-
outputs: [{
|
|
1216
|
-
name: 'assets',
|
|
1217
|
-
type: 'uint256'
|
|
1218
|
-
}],
|
|
1219
|
-
stateMutability: 'nonpayable',
|
|
1220
|
-
type: 'function'
|
|
1221
|
-
}, {
|
|
1222
|
-
inputs: [],
|
|
1223
|
-
name: 'totalAssets',
|
|
1224
|
-
outputs: [{
|
|
1225
|
-
name: 'totalManagedAssets',
|
|
1226
|
-
type: 'uint256'
|
|
1227
|
-
}],
|
|
1228
|
-
stateMutability: 'view',
|
|
1229
|
-
type: 'function'
|
|
1230
|
-
}, {
|
|
1231
|
-
inputs: [],
|
|
1232
|
-
name: 'totalSupply',
|
|
1233
|
-
outputs: [{
|
|
1234
|
-
name: '',
|
|
1235
|
-
type: 'uint256'
|
|
1236
|
-
}],
|
|
1237
|
-
stateMutability: 'view',
|
|
1238
|
-
type: 'function'
|
|
1239
|
-
}, {
|
|
1240
|
-
inputs: [{
|
|
1241
|
-
name: 'to',
|
|
1242
|
-
type: 'address'
|
|
1243
|
-
}, {
|
|
1244
|
-
name: 'amount',
|
|
1245
|
-
type: 'uint256'
|
|
1246
|
-
}],
|
|
1247
|
-
name: 'transfer',
|
|
1248
|
-
outputs: [{
|
|
1249
|
-
name: '',
|
|
1250
|
-
type: 'bool'
|
|
1251
|
-
}],
|
|
1252
|
-
stateMutability: 'nonpayable',
|
|
1253
|
-
type: 'function'
|
|
1254
|
-
}, {
|
|
1255
|
-
inputs: [{
|
|
1256
|
-
name: 'from',
|
|
1257
|
-
type: 'address'
|
|
1258
|
-
}, {
|
|
1259
|
-
name: 'to',
|
|
1260
|
-
type: 'address'
|
|
1261
|
-
}, {
|
|
1262
|
-
name: 'amount',
|
|
1263
|
-
type: 'uint256'
|
|
1264
|
-
}],
|
|
1265
|
-
name: 'transferFrom',
|
|
1266
|
-
outputs: [{
|
|
1267
|
-
name: '',
|
|
1268
|
-
type: 'bool'
|
|
1269
|
-
}],
|
|
1270
|
-
stateMutability: 'nonpayable',
|
|
1271
|
-
type: 'function'
|
|
1272
|
-
}, {
|
|
1273
|
-
inputs: [{
|
|
1274
|
-
name: 'assets',
|
|
1275
|
-
type: 'uint256'
|
|
1276
|
-
}, {
|
|
1277
|
-
name: 'receiver',
|
|
1278
|
-
type: 'address'
|
|
1279
|
-
}, {
|
|
1280
|
-
name: 'owner',
|
|
1281
|
-
type: 'address'
|
|
1282
|
-
}],
|
|
1283
|
-
name: 'withdraw',
|
|
1284
|
-
outputs: [{
|
|
1285
|
-
name: 'shares',
|
|
1286
|
-
type: 'uint256'
|
|
1287
|
-
}],
|
|
1288
|
-
stateMutability: 'nonpayable',
|
|
1289
|
-
type: 'function'
|
|
1290
|
-
}];
|
|
1291
|
-
|
|
1292
|
-
// https://github.com/ethers-io/ethers.js/blob/master/packages/units/src.ts/index.ts#L10-L18
|
|
1293
|
-
const units = ['wei', 'kwei', 'mwei', 'gwei', 'szabo', 'finney', 'ether'];
|
|
1294
|
-
|
|
1295
|
-
async function connect(_ref) {
|
|
1296
|
-
let {
|
|
1297
|
-
chainId,
|
|
1298
|
-
connector
|
|
1299
|
-
} = _ref;
|
|
1300
|
-
const client = getClient();
|
|
1301
|
-
const activeConnector = client.connector;
|
|
1302
|
-
if (connector.id === (activeConnector === null || activeConnector === void 0 ? void 0 : activeConnector.id)) throw new ConnectorAlreadyConnectedError();
|
|
1303
|
-
|
|
1304
|
-
try {
|
|
1305
|
-
client.setState(x => ({ ...x,
|
|
1306
|
-
status: 'connecting'
|
|
1307
|
-
}));
|
|
1308
|
-
const data = await connector.connect({
|
|
1309
|
-
chainId
|
|
1310
|
-
});
|
|
1311
|
-
client.setLastUsedConnector(connector.id);
|
|
1312
|
-
client.setState(x => ({ ...x,
|
|
1313
|
-
connector,
|
|
1314
|
-
chains: connector === null || connector === void 0 ? void 0 : connector.chains,
|
|
1315
|
-
data,
|
|
1316
|
-
status: 'connected'
|
|
1317
|
-
}));
|
|
1318
|
-
client.storage.setItem('connected', true);
|
|
1319
|
-
return { ...data,
|
|
1320
|
-
connector
|
|
1321
|
-
};
|
|
1322
|
-
} catch (err) {
|
|
1323
|
-
client.setState(x => {
|
|
1324
|
-
return { ...x,
|
|
1325
|
-
// Keep existing connector connected in case of error
|
|
1326
|
-
status: x.connector ? 'connected' : 'disconnected'
|
|
1327
|
-
};
|
|
1328
|
-
});
|
|
1329
|
-
throw err;
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1332
|
-
|
|
1333
|
-
async function disconnect() {
|
|
1334
|
-
const client = getClient();
|
|
1335
|
-
if (client.connector) await client.connector.disconnect();
|
|
1336
|
-
client.clearState();
|
|
1337
|
-
client.storage.removeItem('connected');
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
async function fetchToken(_ref) {
|
|
1341
|
-
let {
|
|
1342
|
-
address,
|
|
1343
|
-
chainId,
|
|
1344
|
-
formatUnits: units = 'ether'
|
|
1345
|
-
} = _ref;
|
|
1346
|
-
|
|
1347
|
-
async function fetchToken_(_ref2) {
|
|
1348
|
-
let {
|
|
1349
|
-
abi
|
|
1350
|
-
} = _ref2;
|
|
1351
|
-
const erc20Config = {
|
|
1352
|
-
address,
|
|
1353
|
-
abi,
|
|
1354
|
-
chainId
|
|
1355
|
-
};
|
|
1356
|
-
const [decimals, name, symbol, totalSupply] = await readContracts({
|
|
1357
|
-
allowFailure: false,
|
|
1358
|
-
contracts: [{ ...erc20Config,
|
|
1359
|
-
functionName: 'decimals'
|
|
1360
|
-
}, { ...erc20Config,
|
|
1361
|
-
functionName: 'name'
|
|
1362
|
-
}, { ...erc20Config,
|
|
1363
|
-
functionName: 'symbol'
|
|
1364
|
-
}, { ...erc20Config,
|
|
1365
|
-
functionName: 'totalSupply'
|
|
1366
|
-
}]
|
|
1367
|
-
});
|
|
1368
|
-
return {
|
|
1369
|
-
address,
|
|
1370
|
-
decimals,
|
|
1371
|
-
name: name,
|
|
1372
|
-
// protect against `ResolvedConfig['BytesType']`
|
|
1373
|
-
symbol: symbol,
|
|
1374
|
-
// protect against `ResolvedConfig['BytesType']`
|
|
1375
|
-
totalSupply: {
|
|
1376
|
-
formatted: formatUnits(totalSupply, units),
|
|
1377
|
-
value: totalSupply
|
|
1378
|
-
}
|
|
1379
|
-
};
|
|
1380
|
-
}
|
|
1381
|
-
|
|
1382
|
-
try {
|
|
1383
|
-
return await fetchToken_({
|
|
1384
|
-
abi: erc20ABI
|
|
1385
|
-
});
|
|
1386
|
-
} catch (err) {
|
|
1387
|
-
// In the chance that there is an error upon decoding the contract result,
|
|
1388
|
-
// it could be likely that the contract data is represented as bytes32 instead
|
|
1389
|
-
// of a string.
|
|
1390
|
-
if (err instanceof ContractResultDecodeError) {
|
|
1391
|
-
const {
|
|
1392
|
-
name,
|
|
1393
|
-
symbol,
|
|
1394
|
-
...rest
|
|
1395
|
-
} = await fetchToken_({
|
|
1396
|
-
abi: erc20ABI_bytes32
|
|
1397
|
-
});
|
|
1398
|
-
return {
|
|
1399
|
-
name: parseBytes32String(name),
|
|
1400
|
-
symbol: parseBytes32String(symbol),
|
|
1401
|
-
...rest
|
|
1402
|
-
};
|
|
1403
|
-
}
|
|
1404
|
-
|
|
1405
|
-
throw err;
|
|
1406
|
-
}
|
|
1407
|
-
}
|
|
1408
|
-
|
|
1409
|
-
function getContract(_ref) {
|
|
1410
|
-
let {
|
|
1411
|
-
address,
|
|
1412
|
-
abi,
|
|
1413
|
-
signerOrProvider
|
|
1414
|
-
} = _ref;
|
|
1415
|
-
return new Contract$1(address, abi, signerOrProvider);
|
|
1416
|
-
} ////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
1417
|
-
// Contract
|
|
1418
|
-
// TODO: Add remaining properties
|
|
1419
|
-
|
|
1420
|
-
/**
|
|
1421
|
-
* @description Prepares the parameters required for a contract write transaction.
|
|
1422
|
-
*
|
|
1423
|
-
* Returns config to be passed through to `writeContract`.
|
|
1424
|
-
*
|
|
1425
|
-
* @example
|
|
1426
|
-
* import { prepareWriteContract, writeContract } from '@wagmi/core'
|
|
1427
|
-
*
|
|
1428
|
-
* const config = await prepareWriteContract({
|
|
1429
|
-
* address: '0x...',
|
|
1430
|
-
* abi: wagmiAbi,
|
|
1431
|
-
* functionName: 'mint',
|
|
1432
|
-
* })
|
|
1433
|
-
* const result = await writeContract(config)
|
|
1434
|
-
*/
|
|
1435
|
-
async function prepareWriteContract(_ref) {
|
|
1436
|
-
let {
|
|
1437
|
-
abi,
|
|
1438
|
-
address,
|
|
1439
|
-
args,
|
|
1440
|
-
chainId,
|
|
1441
|
-
functionName,
|
|
1442
|
-
overrides,
|
|
1443
|
-
signer: signer_
|
|
1444
|
-
} = _ref;
|
|
1445
|
-
const signer = signer_ ?? (await fetchSigner({
|
|
1446
|
-
chainId
|
|
1447
|
-
}));
|
|
1448
|
-
if (!signer) throw new ConnectorNotFoundError();
|
|
1449
|
-
if (chainId) assertActiveChain({
|
|
1450
|
-
chainId,
|
|
1451
|
-
signer
|
|
1452
|
-
});
|
|
1453
|
-
const contract = getContract({
|
|
1454
|
-
address,
|
|
1455
|
-
abi: abi,
|
|
1456
|
-
// TODO: Remove cast and still support `Narrow<TAbi>`
|
|
1457
|
-
signerOrProvider: signer
|
|
1458
|
-
});
|
|
1459
|
-
const normalizedFunctionName = normalizeFunctionName({
|
|
1460
|
-
contract,
|
|
1461
|
-
functionName,
|
|
1462
|
-
args
|
|
1463
|
-
});
|
|
1464
|
-
const populateTransactionFn = contract.populateTransaction[normalizedFunctionName];
|
|
1465
|
-
if (!populateTransactionFn) throw new ContractMethodDoesNotExistError({
|
|
1466
|
-
address,
|
|
1467
|
-
functionName: normalizedFunctionName
|
|
1468
|
-
});
|
|
1469
|
-
const params = [...(args ?? []), ...(overrides ? [overrides] : [])];
|
|
1470
|
-
const unsignedTransaction = await populateTransactionFn(...params);
|
|
1471
|
-
const gasLimit = unsignedTransaction.gasLimit || (await signer.estimateGas(unsignedTransaction));
|
|
1472
|
-
const minimizedAbi = minimizeContractInterface({
|
|
1473
|
-
abi: abi,
|
|
1474
|
-
// TODO: Remove cast and still support `Narrow<TAbi>`
|
|
1475
|
-
functionName
|
|
1476
|
-
});
|
|
1477
|
-
return {
|
|
1478
|
-
abi: minimizedAbi,
|
|
1479
|
-
address,
|
|
1480
|
-
chainId,
|
|
1481
|
-
// TODO: Remove cast
|
|
1482
|
-
functionName: functionName,
|
|
1483
|
-
mode: 'prepared',
|
|
1484
|
-
request: { ...unsignedTransaction,
|
|
1485
|
-
gasLimit
|
|
1486
|
-
}
|
|
1487
|
-
};
|
|
1488
|
-
}
|
|
1489
|
-
|
|
1490
|
-
function getWebSocketProvider() {
|
|
1491
|
-
let {
|
|
1492
|
-
chainId
|
|
1493
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1494
|
-
const client = getClient();
|
|
1495
|
-
if (chainId) return client.getWebSocketProvider({
|
|
1496
|
-
chainId
|
|
1497
|
-
}) || client.webSocketProvider;
|
|
1498
|
-
return client.webSocketProvider;
|
|
1499
|
-
}
|
|
1500
|
-
|
|
1501
|
-
function watchProvider(args, callback) {
|
|
1502
|
-
const client = getClient();
|
|
1503
|
-
|
|
1504
|
-
const handleChange = async () => callback(getProvider(args));
|
|
1505
|
-
|
|
1506
|
-
const unsubscribe = client.subscribe(_ref => {
|
|
1507
|
-
let {
|
|
1508
|
-
provider
|
|
1509
|
-
} = _ref;
|
|
1510
|
-
return provider;
|
|
1511
|
-
}, handleChange);
|
|
1512
|
-
return unsubscribe;
|
|
1513
|
-
}
|
|
1514
|
-
|
|
1515
|
-
function watchWebSocketProvider(args, callback) {
|
|
1516
|
-
const client = getClient();
|
|
1517
|
-
|
|
1518
|
-
const handleChange = async () => callback(getWebSocketProvider(args));
|
|
1519
|
-
|
|
1520
|
-
const unsubscribe = client.subscribe(_ref => {
|
|
1521
|
-
let {
|
|
1522
|
-
webSocketProvider
|
|
1523
|
-
} = _ref;
|
|
1524
|
-
return webSocketProvider;
|
|
1525
|
-
}, handleChange);
|
|
1526
|
-
return unsubscribe;
|
|
1527
|
-
}
|
|
1528
|
-
|
|
1529
|
-
async function multicall(_ref) {
|
|
1530
|
-
let {
|
|
1531
|
-
allowFailure = true,
|
|
1532
|
-
chainId,
|
|
1533
|
-
contracts,
|
|
1534
|
-
overrides
|
|
1535
|
-
} = _ref;
|
|
1536
|
-
const provider = getProvider({
|
|
1537
|
-
chainId
|
|
1538
|
-
});
|
|
1539
|
-
if (!provider.chains) throw new ProviderChainsNotFound();
|
|
1540
|
-
const chain = provider.chains.find(chain => chain.id === chainId) || provider.chains[0];
|
|
1541
|
-
if (!chain) throw new ProviderChainsNotFound();
|
|
1542
|
-
if (!(chain !== null && chain !== void 0 && chain.multicall)) throw new ChainDoesNotSupportMulticallError({
|
|
1543
|
-
chain
|
|
1544
|
-
});
|
|
1545
|
-
if (typeof (overrides === null || overrides === void 0 ? void 0 : overrides.blockTag) === 'number' && (overrides === null || overrides === void 0 ? void 0 : overrides.blockTag) < chain.multicall.blockCreated) throw new ChainDoesNotSupportMulticallError({
|
|
1546
|
-
blockNumber: overrides === null || overrides === void 0 ? void 0 : overrides.blockTag,
|
|
1547
|
-
chain
|
|
1548
|
-
});
|
|
1549
|
-
const multicallContract = getContract({
|
|
1550
|
-
address: chain.multicall.address,
|
|
1551
|
-
abi: multicallABI,
|
|
1552
|
-
signerOrProvider: provider
|
|
1553
|
-
});
|
|
1554
|
-
const calls = contracts.map(_ref2 => {
|
|
1555
|
-
let {
|
|
1556
|
-
address,
|
|
1557
|
-
abi,
|
|
1558
|
-
functionName,
|
|
1559
|
-
...config
|
|
1560
|
-
} = _ref2;
|
|
1561
|
-
const {
|
|
1562
|
-
args
|
|
1563
|
-
} = config || {};
|
|
1564
|
-
const contract = getContract({
|
|
1565
|
-
address,
|
|
1566
|
-
abi
|
|
1567
|
-
});
|
|
1568
|
-
const params = args ?? [];
|
|
1569
|
-
const normalizedFunctionName = normalizeFunctionName({
|
|
1570
|
-
contract,
|
|
1571
|
-
functionName,
|
|
1572
|
-
args
|
|
1573
|
-
});
|
|
1574
|
-
|
|
1575
|
-
try {
|
|
1576
|
-
const contractFunction = contract[normalizedFunctionName];
|
|
1577
|
-
if (!contractFunction) logWarn(`"${normalizedFunctionName}" is not in the interface for contract "${address}"`);
|
|
1578
|
-
const callData = contract.interface.encodeFunctionData(normalizedFunctionName, params);
|
|
1579
|
-
return {
|
|
1580
|
-
target: address,
|
|
1581
|
-
allowFailure,
|
|
1582
|
-
callData
|
|
1583
|
-
};
|
|
1584
|
-
} catch (err) {
|
|
1585
|
-
if (!allowFailure) throw err;
|
|
1586
|
-
return {
|
|
1587
|
-
target: address,
|
|
1588
|
-
allowFailure,
|
|
1589
|
-
callData: '0x'
|
|
1590
|
-
};
|
|
1591
|
-
}
|
|
1592
|
-
});
|
|
1593
|
-
const params = [...[calls], ...(overrides ? [overrides] : [])];
|
|
1594
|
-
const results = await multicallContract.aggregate3( // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1595
|
-
// @ts-ignore
|
|
1596
|
-
...params);
|
|
1597
|
-
return results.map((_ref3, i) => {
|
|
1598
|
-
let {
|
|
1599
|
-
returnData,
|
|
1600
|
-
success
|
|
1601
|
-
} = _ref3;
|
|
1602
|
-
const {
|
|
1603
|
-
address,
|
|
1604
|
-
abi,
|
|
1605
|
-
args,
|
|
1606
|
-
functionName
|
|
1607
|
-
} = contracts[i];
|
|
1608
|
-
const contract = getContract({
|
|
1609
|
-
address,
|
|
1610
|
-
abi: abi // TODO: Remove cast and still support `Narrow<TAbi>`
|
|
1611
|
-
|
|
1612
|
-
});
|
|
1613
|
-
const normalizedFunctionName = normalizeFunctionName({
|
|
1614
|
-
contract,
|
|
1615
|
-
functionName,
|
|
1616
|
-
args
|
|
1617
|
-
});
|
|
1618
|
-
|
|
1619
|
-
if (!success) {
|
|
1620
|
-
let error;
|
|
1621
|
-
|
|
1622
|
-
try {
|
|
1623
|
-
contract.interface.decodeFunctionResult(normalizedFunctionName, returnData);
|
|
1624
|
-
} catch (err) {
|
|
1625
|
-
error = new ContractMethodRevertedError({
|
|
1626
|
-
address,
|
|
1627
|
-
args,
|
|
1628
|
-
chainId: chain.id,
|
|
1629
|
-
functionName: normalizedFunctionName,
|
|
1630
|
-
errorMessage: err.message
|
|
1631
|
-
});
|
|
1632
|
-
if (!allowFailure) throw error;
|
|
1633
|
-
logWarn(error.message);
|
|
1634
|
-
}
|
|
1635
|
-
|
|
1636
|
-
return null;
|
|
1637
|
-
}
|
|
1638
|
-
|
|
1639
|
-
if (returnData === '0x') {
|
|
1640
|
-
const error = new ContractMethodNoResultError({
|
|
1641
|
-
address,
|
|
1642
|
-
args,
|
|
1643
|
-
chainId: chain.id,
|
|
1644
|
-
functionName: normalizedFunctionName
|
|
1645
|
-
});
|
|
1646
|
-
if (!allowFailure) throw error;
|
|
1647
|
-
logWarn(error.message);
|
|
1648
|
-
return null;
|
|
1649
|
-
}
|
|
1650
|
-
|
|
1651
|
-
try {
|
|
1652
|
-
const result = contract.interface.decodeFunctionResult(normalizedFunctionName, returnData);
|
|
1653
|
-
return Array.isArray(result) && result.length === 1 ? result[0] : result;
|
|
1654
|
-
} catch (err) {
|
|
1655
|
-
const error = new ContractResultDecodeError({
|
|
1656
|
-
address,
|
|
1657
|
-
args,
|
|
1658
|
-
chainId: chain.id,
|
|
1659
|
-
functionName: normalizedFunctionName,
|
|
1660
|
-
errorMessage: err.message
|
|
1661
|
-
});
|
|
1662
|
-
if (!allowFailure) throw error;
|
|
1663
|
-
logWarn(error.message);
|
|
1664
|
-
return null;
|
|
1665
|
-
}
|
|
1666
|
-
});
|
|
1667
|
-
}
|
|
1668
|
-
|
|
1669
|
-
async function readContract(_ref) {
|
|
1670
|
-
let {
|
|
1671
|
-
address,
|
|
1672
|
-
args,
|
|
1673
|
-
chainId,
|
|
1674
|
-
abi,
|
|
1675
|
-
functionName,
|
|
1676
|
-
overrides
|
|
1677
|
-
} = _ref;
|
|
1678
|
-
const provider = getProvider({
|
|
1679
|
-
chainId
|
|
1680
|
-
});
|
|
1681
|
-
const contract = getContract({
|
|
1682
|
-
address,
|
|
1683
|
-
abi: abi,
|
|
1684
|
-
// TODO: Remove cast and still support `Narrow<TAbi>`
|
|
1685
|
-
signerOrProvider: provider
|
|
1686
|
-
});
|
|
1687
|
-
const normalizedFunctionName = normalizeFunctionName({
|
|
1688
|
-
contract,
|
|
1689
|
-
functionName,
|
|
1690
|
-
args
|
|
1691
|
-
});
|
|
1692
|
-
const contractFunction = contract[normalizedFunctionName];
|
|
1693
|
-
if (!contractFunction) throw new ContractMethodDoesNotExistError({
|
|
1694
|
-
address,
|
|
1695
|
-
functionName: normalizedFunctionName
|
|
1696
|
-
});
|
|
1697
|
-
const params = [...(args ?? []), ...(overrides ? [overrides] : [])];
|
|
1698
|
-
return contractFunction === null || contractFunction === void 0 ? void 0 : contractFunction(...params);
|
|
1699
|
-
}
|
|
1700
|
-
|
|
1701
|
-
async function readContracts(_ref) {
|
|
1702
|
-
let {
|
|
1703
|
-
allowFailure = true,
|
|
1704
|
-
contracts,
|
|
1705
|
-
overrides
|
|
1706
|
-
} = _ref;
|
|
1707
|
-
|
|
1708
|
-
try {
|
|
1709
|
-
const provider = getProvider();
|
|
1710
|
-
const contractsByChainId = contracts.reduce((contracts, contract, index) => {
|
|
1711
|
-
const chainId = contract.chainId ?? provider.network.chainId;
|
|
1712
|
-
return { ...contracts,
|
|
1713
|
-
[chainId]: [...(contracts[chainId] || []), {
|
|
1714
|
-
contract,
|
|
1715
|
-
index
|
|
1716
|
-
}]
|
|
1717
|
-
};
|
|
1718
|
-
}, {});
|
|
1719
|
-
|
|
1720
|
-
const promises = () => Object.entries(contractsByChainId).map(_ref2 => {
|
|
1721
|
-
let [chainId, contracts] = _ref2;
|
|
1722
|
-
return multicall({
|
|
1723
|
-
allowFailure,
|
|
1724
|
-
chainId: parseInt(chainId),
|
|
1725
|
-
contracts: contracts.map(_ref3 => {
|
|
1726
|
-
let {
|
|
1727
|
-
contract
|
|
1728
|
-
} = _ref3;
|
|
1729
|
-
return contract;
|
|
1730
|
-
}),
|
|
1731
|
-
overrides
|
|
1732
|
-
});
|
|
1733
|
-
});
|
|
1734
|
-
|
|
1735
|
-
let results;
|
|
1736
|
-
|
|
1737
|
-
if (allowFailure) {
|
|
1738
|
-
results = (await Promise.allSettled(promises())).map(result => {
|
|
1739
|
-
if (result.status === 'fulfilled') return result.value;
|
|
1740
|
-
|
|
1741
|
-
if (result.reason instanceof ChainDoesNotSupportMulticallError) {
|
|
1742
|
-
logWarn(result.reason.message);
|
|
1743
|
-
throw result.reason;
|
|
1744
|
-
}
|
|
1745
|
-
|
|
1746
|
-
return null;
|
|
1747
|
-
}).flat();
|
|
1748
|
-
} else {
|
|
1749
|
-
results = (await Promise.all(promises())).flat();
|
|
1750
|
-
} // Reorder the contract results back to the order they were
|
|
1751
|
-
// provided in.
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
const resultIndexes = Object.values(contractsByChainId).map(contracts => contracts.map(_ref4 => {
|
|
1755
|
-
let {
|
|
1756
|
-
index
|
|
1757
|
-
} = _ref4;
|
|
1758
|
-
return index;
|
|
1759
|
-
})).flat();
|
|
1760
|
-
return results.reduce((results, result, index) => {
|
|
1761
|
-
results[resultIndexes[index]] = result;
|
|
1762
|
-
return results;
|
|
1763
|
-
}, []);
|
|
1764
|
-
} catch (err) {
|
|
1765
|
-
if (err instanceof ContractResultDecodeError) throw err;
|
|
1766
|
-
if (err instanceof ContractMethodNoResultError) throw err;
|
|
1767
|
-
if (err instanceof ContractMethodRevertedError) throw err;
|
|
1768
|
-
|
|
1769
|
-
const promises = () => contracts.map(contract => readContract({ ...contract,
|
|
1770
|
-
overrides
|
|
1771
|
-
}));
|
|
1772
|
-
|
|
1773
|
-
if (allowFailure) return (await Promise.allSettled(promises())).map((result, i) => {
|
|
1774
|
-
if (result.status === 'fulfilled') return result.value;
|
|
1775
|
-
const {
|
|
1776
|
-
address,
|
|
1777
|
-
args,
|
|
1778
|
-
chainId,
|
|
1779
|
-
functionName
|
|
1780
|
-
} = contracts[i];
|
|
1781
|
-
const error = new ContractMethodRevertedError({
|
|
1782
|
-
address,
|
|
1783
|
-
functionName,
|
|
1784
|
-
chainId: chainId ?? mainnet.id,
|
|
1785
|
-
args,
|
|
1786
|
-
errorMessage: result.reason
|
|
1787
|
-
});
|
|
1788
|
-
logWarn(error.message);
|
|
1789
|
-
return null;
|
|
1790
|
-
});
|
|
1791
|
-
return await Promise.all(promises());
|
|
1792
|
-
}
|
|
1793
|
-
}
|
|
1794
|
-
|
|
1795
|
-
function watchContractEvent(_ref, callback) {
|
|
1796
|
-
let {
|
|
1797
|
-
address,
|
|
1798
|
-
abi,
|
|
1799
|
-
chainId,
|
|
1800
|
-
eventName,
|
|
1801
|
-
once
|
|
1802
|
-
} = _ref;
|
|
1803
|
-
|
|
1804
|
-
const handler = function () {
|
|
1805
|
-
return callback(...arguments);
|
|
1806
|
-
};
|
|
1807
|
-
|
|
1808
|
-
let contract;
|
|
1809
|
-
|
|
1810
|
-
const watchEvent = async () => {
|
|
1811
|
-
var _contract;
|
|
1812
|
-
|
|
1813
|
-
if (contract) (_contract = contract) === null || _contract === void 0 ? void 0 : _contract.off(eventName, handler);
|
|
1814
|
-
const signerOrProvider = getWebSocketProvider({
|
|
1815
|
-
chainId
|
|
1816
|
-
}) || getProvider({
|
|
1817
|
-
chainId
|
|
1818
|
-
});
|
|
1819
|
-
contract = getContract({
|
|
1820
|
-
address,
|
|
1821
|
-
abi: abi,
|
|
1822
|
-
// TODO: Remove cast and still support `Narrow<TAbi>`
|
|
1823
|
-
signerOrProvider
|
|
1824
|
-
});
|
|
1825
|
-
if (once) contract.once(eventName, handler);else contract.on(eventName, handler);
|
|
1826
|
-
};
|
|
1827
|
-
|
|
1828
|
-
watchEvent();
|
|
1829
|
-
const client = getClient();
|
|
1830
|
-
const unsubscribe = client.subscribe(_ref2 => {
|
|
1831
|
-
let {
|
|
1832
|
-
provider,
|
|
1833
|
-
webSocketProvider
|
|
1834
|
-
} = _ref2;
|
|
1835
|
-
return {
|
|
1836
|
-
provider,
|
|
1837
|
-
webSocketProvider
|
|
1838
|
-
};
|
|
1839
|
-
}, watchEvent, {
|
|
1840
|
-
equalityFn: shallow
|
|
1841
|
-
});
|
|
1842
|
-
return () => {
|
|
1843
|
-
var _contract2;
|
|
1844
|
-
|
|
1845
|
-
(_contract2 = contract) === null || _contract2 === void 0 ? void 0 : _contract2.off(eventName, handler);
|
|
1846
|
-
unsubscribe();
|
|
1847
|
-
};
|
|
1848
|
-
}
|
|
1849
|
-
|
|
1850
|
-
async function fetchBlockNumber() {
|
|
1851
|
-
let {
|
|
1852
|
-
chainId
|
|
1853
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1854
|
-
const provider = getProvider({
|
|
1855
|
-
chainId
|
|
1856
|
-
});
|
|
1857
|
-
const blockNumber = await provider.getBlockNumber();
|
|
1858
|
-
return blockNumber;
|
|
1859
|
-
}
|
|
1860
|
-
|
|
1861
|
-
function watchBlockNumber(args, callback) {
|
|
1862
|
-
// We need to debounce the listener as we want to opt-out
|
|
1863
|
-
// of the behavior where ethers emits a "block" event for
|
|
1864
|
-
// every block that was missed in between the `pollingInterval`.
|
|
1865
|
-
// We are setting a wait time of 1 as emitting an event in
|
|
1866
|
-
// ethers takes ~0.1ms.
|
|
1867
|
-
const debouncedCallback = debounce(callback, 1);
|
|
1868
|
-
let previousProvider;
|
|
1869
|
-
|
|
1870
|
-
const createListener = provider => {
|
|
1871
|
-
if (previousProvider) {
|
|
1872
|
-
var _previousProvider;
|
|
1873
|
-
|
|
1874
|
-
(_previousProvider = previousProvider) === null || _previousProvider === void 0 ? void 0 : _previousProvider.off('block', debouncedCallback);
|
|
1875
|
-
}
|
|
1876
|
-
|
|
1877
|
-
provider.on('block', debouncedCallback);
|
|
1878
|
-
previousProvider = provider;
|
|
1879
|
-
};
|
|
1880
|
-
|
|
1881
|
-
const provider_ = getWebSocketProvider({
|
|
1882
|
-
chainId: args.chainId
|
|
1883
|
-
}) ?? getProvider({
|
|
1884
|
-
chainId: args.chainId
|
|
1885
|
-
});
|
|
1886
|
-
if (args.listen) createListener(provider_);
|
|
1887
|
-
let active = true;
|
|
1888
|
-
const client = getClient();
|
|
1889
|
-
const unsubscribe = client.subscribe(_ref => {
|
|
1890
|
-
let {
|
|
1891
|
-
provider,
|
|
1892
|
-
webSocketProvider
|
|
1893
|
-
} = _ref;
|
|
1894
|
-
return {
|
|
1895
|
-
provider,
|
|
1896
|
-
webSocketProvider
|
|
1897
|
-
};
|
|
1898
|
-
}, async _ref2 => {
|
|
1899
|
-
let {
|
|
1900
|
-
provider,
|
|
1901
|
-
webSocketProvider
|
|
1902
|
-
} = _ref2;
|
|
1903
|
-
const provider_ = webSocketProvider ?? provider;
|
|
1904
|
-
|
|
1905
|
-
if (args.listen && !args.chainId && provider_) {
|
|
1906
|
-
createListener(provider_);
|
|
1907
|
-
}
|
|
1908
|
-
|
|
1909
|
-
const blockNumber = await fetchBlockNumber({
|
|
1910
|
-
chainId: args.chainId
|
|
1911
|
-
});
|
|
1912
|
-
if (!active) return;
|
|
1913
|
-
callback(blockNumber);
|
|
1914
|
-
}, {
|
|
1915
|
-
equalityFn: shallow
|
|
1916
|
-
});
|
|
1917
|
-
return () => {
|
|
1918
|
-
var _previousProvider2;
|
|
1919
|
-
|
|
1920
|
-
active = false;
|
|
1921
|
-
unsubscribe();
|
|
1922
|
-
provider_ === null || provider_ === void 0 ? void 0 : provider_.off('block', debouncedCallback);
|
|
1923
|
-
(_previousProvider2 = previousProvider) === null || _previousProvider2 === void 0 ? void 0 : _previousProvider2.off('block', debouncedCallback);
|
|
1924
|
-
};
|
|
1925
|
-
}
|
|
1926
|
-
|
|
1927
|
-
function watchMulticall(config, callback) {
|
|
1928
|
-
const client = getClient();
|
|
1929
|
-
|
|
1930
|
-
const handleChange = async () => callback(await multicall(config));
|
|
1931
|
-
|
|
1932
|
-
const unwatch = config.listenToBlock ? watchBlockNumber({
|
|
1933
|
-
listen: true
|
|
1934
|
-
}, handleChange) : undefined;
|
|
1935
|
-
const unsubscribe = client.subscribe(_ref => {
|
|
1936
|
-
let {
|
|
1937
|
-
provider
|
|
1938
|
-
} = _ref;
|
|
1939
|
-
return provider;
|
|
1940
|
-
}, handleChange);
|
|
1941
|
-
return () => {
|
|
1942
|
-
unsubscribe();
|
|
1943
|
-
unwatch === null || unwatch === void 0 ? void 0 : unwatch();
|
|
1944
|
-
};
|
|
1945
|
-
}
|
|
1946
|
-
|
|
1947
|
-
function watchReadContract(config, callback) {
|
|
1948
|
-
const client = getClient();
|
|
1949
|
-
|
|
1950
|
-
const handleChange = async () => callback(await readContract(config));
|
|
1951
|
-
|
|
1952
|
-
const unwatch = config.listenToBlock ? watchBlockNumber({
|
|
1953
|
-
listen: true
|
|
1954
|
-
}, handleChange) : undefined;
|
|
1955
|
-
const unsubscribe = client.subscribe(_ref => {
|
|
1956
|
-
let {
|
|
1957
|
-
provider
|
|
1958
|
-
} = _ref;
|
|
1959
|
-
return provider;
|
|
1960
|
-
}, handleChange);
|
|
1961
|
-
return () => {
|
|
1962
|
-
unsubscribe();
|
|
1963
|
-
unwatch === null || unwatch === void 0 ? void 0 : unwatch();
|
|
1964
|
-
};
|
|
1965
|
-
}
|
|
1966
|
-
|
|
1967
|
-
function watchReadContracts(config, callback) {
|
|
1968
|
-
const client = getClient();
|
|
1969
|
-
|
|
1970
|
-
const handleChange = async () => callback(await readContracts(config));
|
|
1971
|
-
|
|
1972
|
-
const unwatch = config.listenToBlock ? watchBlockNumber({
|
|
1973
|
-
listen: true
|
|
1974
|
-
}, handleChange) : undefined;
|
|
1975
|
-
const unsubscribe = client.subscribe(_ref => {
|
|
1976
|
-
let {
|
|
1977
|
-
provider
|
|
1978
|
-
} = _ref;
|
|
1979
|
-
return provider;
|
|
1980
|
-
}, handleChange);
|
|
1981
|
-
return () => {
|
|
1982
|
-
unsubscribe();
|
|
1983
|
-
unwatch === null || unwatch === void 0 ? void 0 : unwatch();
|
|
1984
|
-
};
|
|
1985
|
-
}
|
|
1986
|
-
|
|
1987
|
-
/**
|
|
1988
|
-
* @description Fetches transaction for hash
|
|
1989
|
-
*
|
|
1990
|
-
* @example
|
|
1991
|
-
* import { fetchTransaction } from '@wagmi/core'
|
|
1992
|
-
*
|
|
1993
|
-
* const transaction = await fetchTransaction({
|
|
1994
|
-
* chainId: 1,
|
|
1995
|
-
* hash: '0x...',
|
|
1996
|
-
* })
|
|
1997
|
-
*/
|
|
1998
|
-
async function fetchTransaction(_ref) {
|
|
1999
|
-
let {
|
|
2000
|
-
chainId,
|
|
2001
|
-
hash
|
|
2002
|
-
} = _ref;
|
|
2003
|
-
const provider = getProvider({
|
|
2004
|
-
chainId
|
|
2005
|
-
});
|
|
2006
|
-
return provider.getTransaction(hash);
|
|
2007
|
-
}
|
|
2008
|
-
|
|
2009
|
-
async function fetchEnsAddress(_ref) {
|
|
2010
|
-
let {
|
|
2011
|
-
chainId,
|
|
2012
|
-
name
|
|
2013
|
-
} = _ref;
|
|
2014
|
-
const provider = getProvider({
|
|
2015
|
-
chainId
|
|
2016
|
-
});
|
|
2017
|
-
const address = await provider.resolveName(name);
|
|
2018
|
-
|
|
2019
|
-
try {
|
|
2020
|
-
return address ? getAddress(address) : null;
|
|
2021
|
-
} catch (_error) {
|
|
2022
|
-
return null;
|
|
2023
|
-
}
|
|
2024
|
-
}
|
|
2025
|
-
|
|
2026
|
-
async function fetchEnsAvatar(_ref) {
|
|
2027
|
-
let {
|
|
2028
|
-
addressOrName,
|
|
2029
|
-
chainId
|
|
2030
|
-
} = _ref;
|
|
2031
|
-
const provider = getProvider({
|
|
2032
|
-
chainId
|
|
2033
|
-
}); // TODO: Update with more advanced logic
|
|
2034
|
-
// https://github.com/ensdomains/ens-avatar
|
|
2035
|
-
|
|
2036
|
-
const avatar = await provider.getAvatar(addressOrName);
|
|
2037
|
-
return avatar;
|
|
2038
|
-
}
|
|
2039
|
-
|
|
2040
|
-
async function fetchEnsName(_ref) {
|
|
2041
|
-
let {
|
|
2042
|
-
address,
|
|
2043
|
-
chainId
|
|
2044
|
-
} = _ref;
|
|
2045
|
-
const provider = getProvider({
|
|
2046
|
-
chainId
|
|
2047
|
-
});
|
|
2048
|
-
return provider.lookupAddress(getAddress(address));
|
|
2049
|
-
}
|
|
2050
|
-
|
|
2051
|
-
async function fetchEnsResolver(_ref) {
|
|
2052
|
-
let {
|
|
2053
|
-
chainId,
|
|
2054
|
-
name
|
|
2055
|
-
} = _ref;
|
|
2056
|
-
const provider = getProvider({
|
|
2057
|
-
chainId
|
|
2058
|
-
});
|
|
2059
|
-
const resolver = await provider.getResolver(name);
|
|
2060
|
-
return resolver;
|
|
2061
|
-
}
|
|
2062
|
-
|
|
2063
|
-
/**
|
|
2064
|
-
* @description Prepares the parameters required for sending a transaction.
|
|
2065
|
-
*
|
|
2066
|
-
* Returns config to be passed through to `sendTransaction`.
|
|
2067
|
-
*
|
|
2068
|
-
* @example
|
|
2069
|
-
* import { prepareSendTransaction, sendTransaction } from '@wagmi/core'
|
|
2070
|
-
*
|
|
2071
|
-
* const config = await prepareSendTransaction({
|
|
2072
|
-
* request: {
|
|
2073
|
-
* to: 'moxey.eth',
|
|
2074
|
-
* value: parseEther('1'),
|
|
2075
|
-
* }
|
|
2076
|
-
* })
|
|
2077
|
-
* const result = await sendTransaction(config)
|
|
2078
|
-
*/
|
|
2079
|
-
async function prepareSendTransaction(_ref) {
|
|
2080
|
-
let {
|
|
2081
|
-
chainId,
|
|
2082
|
-
request,
|
|
2083
|
-
signer: signer_
|
|
2084
|
-
} = _ref;
|
|
2085
|
-
const signer = signer_ ?? (await fetchSigner({
|
|
2086
|
-
chainId
|
|
2087
|
-
}));
|
|
2088
|
-
if (!signer) throw new ConnectorNotFoundError();
|
|
2089
|
-
if (chainId) assertActiveChain({
|
|
2090
|
-
chainId,
|
|
2091
|
-
signer
|
|
2092
|
-
});
|
|
2093
|
-
const [to, gasLimit] = await Promise.all([isAddress(request.to) ? Promise.resolve(request.to) : fetchEnsAddress({
|
|
2094
|
-
name: request.to
|
|
2095
|
-
}), request.gasLimit ? Promise.resolve(request.gasLimit) : signer.estimateGas(request)]);
|
|
2096
|
-
if (!to) throw new Error('Could not resolve ENS name');
|
|
2097
|
-
return { ...(chainId ? {
|
|
2098
|
-
chainId
|
|
2099
|
-
} : {}),
|
|
2100
|
-
request: { ...request,
|
|
2101
|
-
gasLimit,
|
|
2102
|
-
to
|
|
2103
|
-
},
|
|
2104
|
-
mode: 'prepared'
|
|
2105
|
-
};
|
|
2106
|
-
}
|
|
2107
|
-
|
|
2108
|
-
/**
|
|
2109
|
-
* @description Function to send a transaction.
|
|
2110
|
-
*
|
|
2111
|
-
* It is recommended to pair this with the `prepareSendTransaction` function to avoid
|
|
2112
|
-
* [UX pitfalls](https://wagmi.sh/docs/prepare-hooks/intro#ux-pitfalls-without-prepare-hooks).
|
|
2113
|
-
*
|
|
2114
|
-
* @example
|
|
2115
|
-
* import { prepareSendTransaction, sendTransaction } from '@wagmi/core'
|
|
2116
|
-
*
|
|
2117
|
-
* const config = await prepareSendTransaction({
|
|
2118
|
-
* to: 'moxey.eth',
|
|
2119
|
-
* value: parseEther('1'),
|
|
2120
|
-
* })
|
|
2121
|
-
* const result = await sendTransaction(config)
|
|
2122
|
-
*/
|
|
2123
|
-
async function sendTransaction(_ref) {
|
|
2124
|
-
let {
|
|
2125
|
-
chainId,
|
|
2126
|
-
mode,
|
|
2127
|
-
request
|
|
2128
|
-
} = _ref;
|
|
2129
|
-
|
|
2130
|
-
/********************************************************************/
|
|
2131
|
-
|
|
2132
|
-
/** START: iOS App Link cautious code. */
|
|
2133
|
-
|
|
2134
|
-
/** Do not perform any async operations in this block. */
|
|
2135
|
-
|
|
2136
|
-
/** Ref: wagmi.sh/docs/prepare-hooks/intro#ios-app-link-constraints */
|
|
2137
|
-
|
|
2138
|
-
/********************************************************************/
|
|
2139
|
-
// `fetchSigner` isn't really "asynchronous" as we have already
|
|
2140
|
-
// initialized the provider upon user connection, so it will return
|
|
2141
|
-
// immediately.
|
|
2142
|
-
const signer = await fetchSigner();
|
|
2143
|
-
if (!signer) throw new ConnectorNotFoundError();
|
|
2144
|
-
|
|
2145
|
-
if (mode === 'prepared') {
|
|
2146
|
-
if (!request.gasLimit) throw new Error('`gasLimit` is required');
|
|
2147
|
-
if (!request.to) throw new Error('`to` is required');
|
|
2148
|
-
}
|
|
2149
|
-
|
|
2150
|
-
if (chainId) assertActiveChain({
|
|
2151
|
-
chainId,
|
|
2152
|
-
signer
|
|
2153
|
-
});
|
|
2154
|
-
|
|
2155
|
-
try {
|
|
2156
|
-
var _connectUnchecked, _ref2;
|
|
2157
|
-
|
|
2158
|
-
// Why don't we just use `signer.sendTransaction`?
|
|
2159
|
-
// The `signer.sendTransaction` method performs async
|
|
2160
|
-
// heavy operations (such as fetching block number)
|
|
2161
|
-
// which is not really needed for our case.
|
|
2162
|
-
// Having async heavy operations has side effects
|
|
2163
|
-
// when using it in a click handler (iOS deep linking issues,
|
|
2164
|
-
// delay to open wallet, etc).
|
|
2165
|
-
const uncheckedSigner = (_connectUnchecked = (_ref2 = signer).connectUnchecked) === null || _connectUnchecked === void 0 ? void 0 : _connectUnchecked.call(_ref2);
|
|
2166
|
-
const {
|
|
2167
|
-
hash,
|
|
2168
|
-
wait
|
|
2169
|
-
} = await (uncheckedSigner ?? signer).sendTransaction(request);
|
|
2170
|
-
/********************************************************************/
|
|
2171
|
-
|
|
2172
|
-
/** END: iOS App Link cautious code. */
|
|
2173
|
-
|
|
2174
|
-
/** Go nuts! */
|
|
2175
|
-
|
|
2176
|
-
/********************************************************************/
|
|
2177
|
-
|
|
2178
|
-
return {
|
|
2179
|
-
hash: hash,
|
|
2180
|
-
wait
|
|
2181
|
-
};
|
|
2182
|
-
} catch (error) {
|
|
2183
|
-
if (error.code === 4001) throw new UserRejectedRequestError(error);
|
|
2184
|
-
throw error;
|
|
2185
|
-
}
|
|
2186
|
-
}
|
|
2187
|
-
|
|
2188
|
-
async function waitForTransaction(_ref) {
|
|
2189
|
-
let {
|
|
2190
|
-
chainId,
|
|
2191
|
-
confirmations,
|
|
2192
|
-
hash,
|
|
2193
|
-
timeout,
|
|
2194
|
-
wait: wait_
|
|
2195
|
-
} = _ref;
|
|
2196
|
-
let promise;
|
|
2197
|
-
|
|
2198
|
-
if (hash) {
|
|
2199
|
-
const provider = getProvider({
|
|
2200
|
-
chainId
|
|
2201
|
-
});
|
|
2202
|
-
promise = provider.waitForTransaction(hash, confirmations, timeout);
|
|
2203
|
-
} else if (wait_) promise = wait_(confirmations);else throw new Error('hash or wait is required');
|
|
2204
|
-
|
|
2205
|
-
return promise;
|
|
2206
|
-
}
|
|
2207
|
-
|
|
2208
|
-
/**
|
|
2209
|
-
* @description Function to call a contract write method.
|
|
2210
|
-
*
|
|
2211
|
-
* It is recommended to pair this with the {@link prepareWriteContract} function
|
|
2212
|
-
* to avoid [UX pitfalls](https://wagmi.sh/docs/prepare-hooks/intro#ux-pitfalls-without-prepare-hooks).
|
|
2213
|
-
*
|
|
2214
|
-
* @example
|
|
2215
|
-
* import { prepareWriteContract, writeContract } from '@wagmi/core'
|
|
2216
|
-
*
|
|
2217
|
-
* const config = await prepareWriteContract({
|
|
2218
|
-
* address: '0x...',
|
|
2219
|
-
* abi: wagmiAbi,
|
|
2220
|
-
* functionName: 'mint',
|
|
2221
|
-
* })
|
|
2222
|
-
* const result = await writeContract(config)
|
|
2223
|
-
*/
|
|
2224
|
-
async function writeContract(_ref) {
|
|
2225
|
-
let {
|
|
2226
|
-
address,
|
|
2227
|
-
args,
|
|
2228
|
-
chainId,
|
|
2229
|
-
abi,
|
|
2230
|
-
functionName,
|
|
2231
|
-
mode,
|
|
2232
|
-
overrides,
|
|
2233
|
-
request: request_
|
|
2234
|
-
} = _ref;
|
|
2235
|
-
|
|
2236
|
-
/****************************************************************************/
|
|
2237
|
-
|
|
2238
|
-
/** START: iOS App Link cautious code. */
|
|
2239
|
-
|
|
2240
|
-
/** Do not perform any async operations in this block. */
|
|
2241
|
-
|
|
2242
|
-
/** Ref: https://wagmi.sh/docs/prepare-hooks/intro#ios-app-link-constraints */
|
|
2243
|
-
|
|
2244
|
-
/****************************************************************************/
|
|
2245
|
-
const signer = await fetchSigner();
|
|
2246
|
-
if (!signer) throw new ConnectorNotFoundError();
|
|
2247
|
-
if (chainId) assertActiveChain({
|
|
2248
|
-
chainId,
|
|
2249
|
-
signer
|
|
2250
|
-
});
|
|
2251
|
-
if (mode === 'prepared') if (!request_) throw new Error('`request` is required');
|
|
2252
|
-
const request = mode === 'recklesslyUnprepared' ? (await prepareWriteContract({
|
|
2253
|
-
address,
|
|
2254
|
-
args,
|
|
2255
|
-
chainId,
|
|
2256
|
-
abi: abi,
|
|
2257
|
-
// TODO: Remove cast and still support `Narrow<TAbi>`
|
|
2258
|
-
functionName,
|
|
2259
|
-
overrides
|
|
2260
|
-
})).request : request_;
|
|
2261
|
-
const transaction = await sendTransaction({
|
|
2262
|
-
request,
|
|
2263
|
-
mode: 'prepared'
|
|
2264
|
-
});
|
|
2265
|
-
/********************************************************************/
|
|
2266
|
-
|
|
2267
|
-
/** END: iOS App Link cautious code. */
|
|
2268
|
-
|
|
2269
|
-
/** Go nuts! */
|
|
2270
|
-
|
|
2271
|
-
/********************************************************************/
|
|
2272
|
-
|
|
2273
|
-
return transaction;
|
|
2274
|
-
}
|
|
2275
|
-
|
|
2276
|
-
async function fetchBalance(_ref) {
|
|
2277
|
-
var _chain$nativeCurrency, _chain$nativeCurrency2;
|
|
2278
|
-
|
|
2279
|
-
let {
|
|
2280
|
-
addressOrName,
|
|
2281
|
-
chainId,
|
|
2282
|
-
formatUnits: unit,
|
|
2283
|
-
token
|
|
2284
|
-
} = _ref;
|
|
2285
|
-
const client = getClient();
|
|
2286
|
-
const provider = getProvider({
|
|
2287
|
-
chainId
|
|
2288
|
-
});
|
|
2289
|
-
|
|
2290
|
-
if (token) {
|
|
2291
|
-
// Convert ENS name to address if required
|
|
2292
|
-
let resolvedAddress;
|
|
2293
|
-
if (isAddress(addressOrName)) resolvedAddress = addressOrName;else {
|
|
2294
|
-
const address = await provider.resolveName(addressOrName); // Same error `provider.getBalance` throws for invalid ENS name
|
|
2295
|
-
|
|
2296
|
-
if (!address) logger.throwError('ENS name not configured', Logger.errors.UNSUPPORTED_OPERATION, {
|
|
2297
|
-
operation: `resolveName(${JSON.stringify(addressOrName)})`
|
|
2298
|
-
});
|
|
2299
|
-
resolvedAddress = address;
|
|
2300
|
-
}
|
|
2301
|
-
|
|
2302
|
-
const fetchContractBalance = async _ref2 => {
|
|
2303
|
-
let {
|
|
2304
|
-
abi
|
|
2305
|
-
} = _ref2;
|
|
2306
|
-
const erc20Config = {
|
|
2307
|
-
abi,
|
|
2308
|
-
address: token,
|
|
2309
|
-
chainId
|
|
2310
|
-
};
|
|
2311
|
-
const [value, decimals, symbol] = await readContracts({
|
|
2312
|
-
allowFailure: false,
|
|
2313
|
-
contracts: [{ ...erc20Config,
|
|
2314
|
-
functionName: 'balanceOf',
|
|
2315
|
-
args: [resolvedAddress]
|
|
2316
|
-
}, { ...erc20Config,
|
|
2317
|
-
functionName: 'decimals'
|
|
2318
|
-
}, { ...erc20Config,
|
|
2319
|
-
functionName: 'symbol'
|
|
2320
|
-
}]
|
|
2321
|
-
});
|
|
2322
|
-
return {
|
|
2323
|
-
decimals,
|
|
2324
|
-
formatted: formatUnits(value ?? '0', unit ?? decimals),
|
|
2325
|
-
symbol: symbol,
|
|
2326
|
-
// protect against `ResolvedConfig['BytesType']`
|
|
2327
|
-
value
|
|
2328
|
-
};
|
|
2329
|
-
};
|
|
2330
|
-
|
|
2331
|
-
try {
|
|
2332
|
-
return await fetchContractBalance({
|
|
2333
|
-
abi: erc20ABI
|
|
2334
|
-
});
|
|
2335
|
-
} catch (err) {
|
|
2336
|
-
// In the chance that there is an error upon decoding the contract result,
|
|
2337
|
-
// it could be likely that the contract data is represented as bytes32 instead
|
|
2338
|
-
// of a string.
|
|
2339
|
-
if (err instanceof ContractResultDecodeError) {
|
|
2340
|
-
const {
|
|
2341
|
-
symbol,
|
|
2342
|
-
...rest
|
|
2343
|
-
} = await fetchContractBalance({
|
|
2344
|
-
abi: erc20ABI_bytes32
|
|
2345
|
-
});
|
|
2346
|
-
return {
|
|
2347
|
-
symbol: parseBytes32String(symbol),
|
|
2348
|
-
...rest
|
|
2349
|
-
};
|
|
2350
|
-
}
|
|
2351
|
-
|
|
2352
|
-
throw err;
|
|
2353
|
-
}
|
|
2354
|
-
}
|
|
2355
|
-
|
|
2356
|
-
const chains = [...(client.provider.chains || []), ...(client.chains ?? [])];
|
|
2357
|
-
const value = await provider.getBalance(addressOrName);
|
|
2358
|
-
const chain = chains.find(x => x.id === provider.network.chainId);
|
|
2359
|
-
return {
|
|
2360
|
-
decimals: (chain === null || chain === void 0 ? void 0 : (_chain$nativeCurrency = chain.nativeCurrency) === null || _chain$nativeCurrency === void 0 ? void 0 : _chain$nativeCurrency.decimals) ?? 18,
|
|
2361
|
-
formatted: formatUnits(value ?? '0', unit ?? 'ether'),
|
|
2362
|
-
symbol: (chain === null || chain === void 0 ? void 0 : (_chain$nativeCurrency2 = chain.nativeCurrency) === null || _chain$nativeCurrency2 === void 0 ? void 0 : _chain$nativeCurrency2.symbol) ?? 'ETH',
|
|
2363
|
-
value
|
|
2364
|
-
};
|
|
2365
|
-
}
|
|
2366
|
-
|
|
2367
|
-
async function fetchSigner() {
|
|
2368
|
-
var _client$connector, _client$connector$get;
|
|
2369
|
-
|
|
2370
|
-
let {
|
|
2371
|
-
chainId
|
|
2372
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2373
|
-
const client = getClient();
|
|
2374
|
-
const signer = (await ((_client$connector = client.connector) === null || _client$connector === void 0 ? void 0 : (_client$connector$get = _client$connector.getSigner) === null || _client$connector$get === void 0 ? void 0 : _client$connector$get.call(_client$connector, {
|
|
2375
|
-
chainId
|
|
2376
|
-
}))) || null;
|
|
2377
|
-
return signer;
|
|
2378
|
-
}
|
|
2379
|
-
|
|
2380
|
-
function getAccount() {
|
|
2381
|
-
const {
|
|
2382
|
-
data,
|
|
2383
|
-
connector,
|
|
2384
|
-
status
|
|
2385
|
-
} = getClient();
|
|
2386
|
-
|
|
2387
|
-
switch (status) {
|
|
2388
|
-
case 'connected':
|
|
2389
|
-
return {
|
|
2390
|
-
address: data === null || data === void 0 ? void 0 : data.account,
|
|
2391
|
-
connector: connector,
|
|
2392
|
-
isConnected: true,
|
|
2393
|
-
isConnecting: false,
|
|
2394
|
-
isDisconnected: false,
|
|
2395
|
-
isReconnecting: false,
|
|
2396
|
-
status
|
|
2397
|
-
};
|
|
2398
|
-
|
|
2399
|
-
case 'reconnecting':
|
|
2400
|
-
return {
|
|
2401
|
-
address: data === null || data === void 0 ? void 0 : data.account,
|
|
2402
|
-
connector,
|
|
2403
|
-
isConnected: !!(data !== null && data !== void 0 && data.account),
|
|
2404
|
-
isConnecting: false,
|
|
2405
|
-
isDisconnected: false,
|
|
2406
|
-
isReconnecting: true,
|
|
2407
|
-
status
|
|
2408
|
-
};
|
|
2409
|
-
|
|
2410
|
-
case 'connecting':
|
|
2411
|
-
return {
|
|
2412
|
-
address: undefined,
|
|
2413
|
-
connector: undefined,
|
|
2414
|
-
isConnected: false,
|
|
2415
|
-
isConnecting: true,
|
|
2416
|
-
isDisconnected: false,
|
|
2417
|
-
isReconnecting: false,
|
|
2418
|
-
status
|
|
2419
|
-
};
|
|
2420
|
-
|
|
2421
|
-
case 'disconnected':
|
|
2422
|
-
return {
|
|
2423
|
-
address: undefined,
|
|
2424
|
-
connector: undefined,
|
|
2425
|
-
isConnected: false,
|
|
2426
|
-
isConnecting: false,
|
|
2427
|
-
isDisconnected: true,
|
|
2428
|
-
isReconnecting: false,
|
|
2429
|
-
status
|
|
2430
|
-
};
|
|
2431
|
-
}
|
|
2432
|
-
}
|
|
2433
|
-
|
|
2434
|
-
function getNetwork() {
|
|
2435
|
-
var _client$data, _client$data$chain, _client$data2;
|
|
2436
|
-
|
|
2437
|
-
const client = getClient();
|
|
2438
|
-
const chainId = (_client$data = client.data) === null || _client$data === void 0 ? void 0 : (_client$data$chain = _client$data.chain) === null || _client$data$chain === void 0 ? void 0 : _client$data$chain.id;
|
|
2439
|
-
const activeChains = client.chains ?? [];
|
|
2440
|
-
const activeChain = [...(client.provider.chains || []), ...activeChains].find(x => x.id === chainId) ?? {
|
|
2441
|
-
id: chainId,
|
|
2442
|
-
name: `Chain ${chainId}`,
|
|
2443
|
-
network: `${chainId}`,
|
|
2444
|
-
rpcUrls: {
|
|
2445
|
-
default: ''
|
|
2446
|
-
}
|
|
2447
|
-
};
|
|
2448
|
-
return {
|
|
2449
|
-
chain: chainId ? { ...activeChain,
|
|
2450
|
-
...((_client$data2 = client.data) === null || _client$data2 === void 0 ? void 0 : _client$data2.chain),
|
|
2451
|
-
id: chainId
|
|
2452
|
-
} : undefined,
|
|
2453
|
-
chains: activeChains
|
|
2454
|
-
};
|
|
2455
|
-
}
|
|
2456
|
-
|
|
2457
|
-
async function signMessage(args) {
|
|
2458
|
-
try {
|
|
2459
|
-
const signer = await fetchSigner();
|
|
2460
|
-
if (!signer) throw new ConnectorNotFoundError();
|
|
2461
|
-
return await signer.signMessage(args.message);
|
|
2462
|
-
} catch (error) {
|
|
2463
|
-
if (error.code === 4001) throw new UserRejectedRequestError(error);
|
|
2464
|
-
throw error;
|
|
2465
|
-
}
|
|
2466
|
-
}
|
|
2467
|
-
|
|
2468
|
-
async function signTypedData(_ref) {
|
|
2469
|
-
let {
|
|
2470
|
-
domain,
|
|
2471
|
-
types,
|
|
2472
|
-
value
|
|
2473
|
-
} = _ref;
|
|
2474
|
-
const signer = await fetchSigner();
|
|
2475
|
-
if (!signer) throw new ConnectorNotFoundError();
|
|
2476
|
-
const {
|
|
2477
|
-
chainId: chainId_
|
|
2478
|
-
} = domain;
|
|
2479
|
-
const chainId = chainId_ ? normalizeChainId(chainId_) : undefined;
|
|
2480
|
-
if (chainId) assertActiveChain({
|
|
2481
|
-
chainId,
|
|
2482
|
-
signer
|
|
2483
|
-
}); // Method name may be changed in the future, see https://docs.ethers.io/v5/api/signer/#Signer-signTypedData
|
|
2484
|
-
|
|
2485
|
-
return signer._signTypedData(domain, types, value);
|
|
2486
|
-
}
|
|
2487
|
-
|
|
2488
|
-
async function switchNetwork(_ref) {
|
|
2489
|
-
let {
|
|
2490
|
-
chainId
|
|
2491
|
-
} = _ref;
|
|
2492
|
-
const {
|
|
2493
|
-
connector
|
|
2494
|
-
} = getClient();
|
|
2495
|
-
if (!connector) throw new ConnectorNotFoundError();
|
|
2496
|
-
if (!connector.switchChain) throw new SwitchChainNotSupportedError({
|
|
2497
|
-
connector
|
|
2498
|
-
});
|
|
2499
|
-
return connector.switchChain(chainId);
|
|
2500
|
-
}
|
|
2501
|
-
|
|
2502
|
-
function watchAccount(callback) {
|
|
2503
|
-
let {
|
|
2504
|
-
selector = x => x
|
|
2505
|
-
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2506
|
-
const client = getClient();
|
|
2507
|
-
|
|
2508
|
-
const handleChange = () => callback(getAccount());
|
|
2509
|
-
|
|
2510
|
-
const unsubscribe = client.subscribe(_ref => {
|
|
2511
|
-
let {
|
|
2512
|
-
data,
|
|
2513
|
-
connector,
|
|
2514
|
-
status
|
|
2515
|
-
} = _ref;
|
|
2516
|
-
return selector({
|
|
2517
|
-
address: data === null || data === void 0 ? void 0 : data.account,
|
|
2518
|
-
connector,
|
|
2519
|
-
status
|
|
2520
|
-
});
|
|
2521
|
-
}, handleChange, {
|
|
2522
|
-
equalityFn: shallow
|
|
2523
|
-
});
|
|
2524
|
-
return unsubscribe;
|
|
2525
|
-
}
|
|
2526
|
-
|
|
2527
|
-
function watchNetwork(callback) {
|
|
2528
|
-
let {
|
|
2529
|
-
selector = x => x
|
|
2530
|
-
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2531
|
-
const client = getClient();
|
|
2532
|
-
|
|
2533
|
-
const handleChange = () => callback(getNetwork());
|
|
2534
|
-
|
|
2535
|
-
const unsubscribe = client.subscribe(_ref => {
|
|
2536
|
-
var _data$chain;
|
|
2537
|
-
|
|
2538
|
-
let {
|
|
2539
|
-
data,
|
|
2540
|
-
chains
|
|
2541
|
-
} = _ref;
|
|
2542
|
-
return selector({
|
|
2543
|
-
chainId: data === null || data === void 0 ? void 0 : (_data$chain = data.chain) === null || _data$chain === void 0 ? void 0 : _data$chain.id,
|
|
2544
|
-
chains
|
|
2545
|
-
});
|
|
2546
|
-
}, handleChange, {
|
|
2547
|
-
equalityFn: shallow
|
|
2548
|
-
});
|
|
2549
|
-
return unsubscribe;
|
|
2550
|
-
}
|
|
2551
|
-
|
|
2552
|
-
function watchSigner(_ref, callback) {
|
|
2553
|
-
let {
|
|
2554
|
-
chainId
|
|
2555
|
-
} = _ref;
|
|
2556
|
-
const client = getClient();
|
|
2557
|
-
|
|
2558
|
-
const handleChange = async () => callback(await fetchSigner({
|
|
2559
|
-
chainId
|
|
2560
|
-
}));
|
|
2561
|
-
|
|
2562
|
-
const unsubscribe = client.subscribe(_ref2 => {
|
|
2563
|
-
var _data$chain;
|
|
2564
|
-
|
|
2565
|
-
let {
|
|
2566
|
-
data,
|
|
2567
|
-
connector
|
|
2568
|
-
} = _ref2;
|
|
2569
|
-
return {
|
|
2570
|
-
account: data === null || data === void 0 ? void 0 : data.account,
|
|
2571
|
-
chainId: data === null || data === void 0 ? void 0 : (_data$chain = data.chain) === null || _data$chain === void 0 ? void 0 : _data$chain.id,
|
|
2572
|
-
connector
|
|
2573
|
-
};
|
|
2574
|
-
}, handleChange, {
|
|
2575
|
-
equalityFn: shallow
|
|
2576
|
-
});
|
|
2577
|
-
return unsubscribe;
|
|
2578
|
-
}
|
|
2579
|
-
|
|
2580
|
-
async function fetchFeeData() {
|
|
2581
|
-
let {
|
|
2582
|
-
chainId,
|
|
2583
|
-
formatUnits: units = 'wei'
|
|
2584
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2585
|
-
const provider = getProvider({
|
|
2586
|
-
chainId
|
|
2587
|
-
});
|
|
2588
|
-
const feeData = await provider.getFeeData();
|
|
2589
|
-
const formatted = {
|
|
2590
|
-
gasPrice: feeData.gasPrice ? formatUnits(feeData.gasPrice, units) : null,
|
|
2591
|
-
maxFeePerGas: feeData.maxFeePerGas ? formatUnits(feeData.maxFeePerGas, units) : null,
|
|
2592
|
-
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas ? formatUnits(feeData.maxPriorityFeePerGas, units) : null
|
|
2593
|
-
};
|
|
2594
|
-
return { ...feeData,
|
|
2595
|
-
formatted
|
|
2596
|
-
};
|
|
2597
|
-
}
|
|
2598
|
-
|
|
2599
|
-
export { configureChains, connect, deepEqual, disconnect, erc20ABI, erc4626ABI, erc721ABI, fetchBalance, fetchBlockNumber, fetchEnsAddress, fetchEnsAvatar, fetchEnsName, fetchEnsResolver, fetchFeeData, fetchSigner, fetchToken, fetchTransaction, getAccount, getContract, getNetwork, getWebSocketProvider, minimizeContractInterface, multicall, parseContractResult, prepareSendTransaction, prepareWriteContract, readContract, readContracts, sendTransaction, signMessage, signTypedData, switchNetwork, units, waitForTransaction, watchAccount, watchBlockNumber, watchContractEvent, watchMulticall, watchNetwork, watchProvider, watchReadContract, watchReadContracts, watchSigner, watchWebSocketProvider, writeContract };
|