@wagmi/core 0.5.8 → 0.6.1
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/dist/wagmi-core-chains.cjs.dev.js +2 -2
- package/chains/dist/wagmi-core-chains.cjs.prod.js +2 -2
- package/chains/dist/wagmi-core-chains.esm.js +2 -2
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +11 -12
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +11 -12
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +11 -12
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.dev.js +4 -3
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.prod.js +4 -3
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.esm.js +4 -3
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.dev.js +9 -13
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.prod.js +9 -13
- package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +9 -13
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.dev.js +9 -11
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.prod.js +9 -11
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +9 -11
- package/dist/{chains-8c76af1b.esm.js → chains-2970e5fa.esm.js} +17 -11
- package/dist/{chains-ec1de502.cjs.dev.js → chains-45d5aa86.cjs.prod.js} +17 -11
- package/dist/{chains-789e0c2e.cjs.prod.js → chains-524f4950.cjs.dev.js} +17 -11
- package/dist/declarations/src/actions/accounts/fetchBalance.d.ts +4 -4
- package/dist/declarations/src/actions/accounts/fetchSigner.d.ts +5 -1
- package/dist/declarations/src/actions/accounts/index.d.ts +1 -1
- package/dist/declarations/src/actions/accounts/signMessage.d.ts +3 -5
- package/dist/declarations/src/actions/accounts/signTypedData.d.ts +19 -20
- package/dist/declarations/src/actions/accounts/watchSigner.d.ts +5 -3
- package/dist/declarations/src/actions/contracts/fetchToken.d.ts +5 -5
- package/dist/declarations/src/actions/contracts/getContract.d.ts +111 -8
- package/dist/declarations/src/actions/contracts/index.d.ts +5 -4
- package/dist/declarations/src/actions/contracts/multicall.d.ts +11 -15
- package/dist/declarations/src/actions/contracts/prepareWriteContract.d.ts +26 -16
- package/dist/declarations/src/actions/contracts/readContract.d.ts +12 -14
- package/dist/declarations/src/actions/contracts/readContracts.d.ts +25 -16
- package/dist/declarations/src/actions/contracts/watchContractEvent.d.ts +22 -8
- package/dist/declarations/src/actions/contracts/watchMulticall.d.ts +10 -0
- package/dist/declarations/src/actions/contracts/watchReadContract.d.ts +4 -3
- package/dist/declarations/src/actions/contracts/watchReadContracts.d.ts +7 -3
- package/dist/declarations/src/actions/contracts/writeContract.d.ts +43 -23
- package/dist/declarations/src/actions/ens/fetchEnsAddress.d.ts +1 -1
- package/dist/declarations/src/actions/ens/fetchEnsName.d.ts +2 -1
- package/dist/declarations/src/actions/index.d.ts +3 -3
- package/dist/declarations/src/actions/transactions/index.d.ts +0 -1
- package/dist/declarations/src/actions/transactions/prepareSendTransaction.d.ts +5 -4
- package/dist/declarations/src/actions/transactions/sendTransaction.d.ts +3 -2
- package/dist/declarations/src/actions/transactions/waitForTransaction.d.ts +2 -1
- package/dist/declarations/src/connectors/base.d.ts +5 -4
- package/dist/declarations/src/connectors/coinbaseWallet.d.ts +5 -3
- package/dist/declarations/src/connectors/injected.d.ts +10 -9
- package/dist/declarations/src/connectors/metaMask.d.ts +1 -1
- package/dist/declarations/src/connectors/mock/connector.d.ts +1 -1
- package/dist/declarations/src/connectors/mock/provider.d.ts +1 -1
- package/dist/declarations/src/connectors/walletConnect.d.ts +2 -2
- package/dist/declarations/src/constants/abis.d.ts +421 -2
- package/dist/declarations/src/constants/blockExplorers.d.ts +1 -1
- package/dist/declarations/src/constants/index.d.ts +1 -2
- package/dist/declarations/src/errors.d.ts +8 -8
- package/dist/declarations/src/index.d.ts +4 -3
- package/dist/declarations/src/internal.d.ts +2 -0
- package/dist/declarations/src/types/contracts.d.ts +241 -0
- package/dist/declarations/src/types/index.d.ts +31 -9
- package/dist/declarations/src/types/utils.d.ts +103 -0
- package/dist/declarations/src/utils/assertActiveChain.d.ts +3 -0
- package/dist/declarations/src/utils/configureChains.d.ts +3 -5
- package/dist/declarations/src/utils/index.d.ts +2 -0
- package/dist/declarations/src/utils/minimizeContractInterface.d.ts +5 -5
- package/dist/declarations/src/utils/normalizeFunctionName.d.ts +17 -0
- package/dist/declarations/src/utils/parseContractResult.d.ts +4 -4
- package/dist/{getProvider-5b4b62c3.esm.js → getProvider-24ec6544.esm.js} +49 -50
- package/dist/{getProvider-1b3eeda8.cjs.dev.js → getProvider-ed469b94.cjs.prod.js} +48 -49
- package/dist/{getProvider-ad4ce6a4.cjs.prod.js → getProvider-f6f17fa1.cjs.dev.js} +48 -49
- package/dist/{rpcs-d2cd65f1.cjs.dev.js → rpcs-0d21dfe8.cjs.dev.js} +5 -5
- package/dist/{rpcs-8d636858.esm.js → rpcs-b4aa70b9.esm.js} +6 -6
- package/dist/{rpcs-edec227e.cjs.prod.js → rpcs-c62bf9b0.cjs.prod.js} +5 -5
- package/dist/wagmi-core.cjs.dev.js +847 -395
- package/dist/wagmi-core.cjs.prod.js +847 -395
- package/dist/wagmi-core.esm.js +849 -397
- package/package.json +3 -2
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.dev.js +2 -2
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.prod.js +2 -2
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.esm.js +2 -2
- package/providers/infura/dist/wagmi-core-providers-infura.cjs.dev.js +2 -2
- package/providers/infura/dist/wagmi-core-providers-infura.cjs.prod.js +2 -2
- package/providers/infura/dist/wagmi-core-providers-infura.esm.js +2 -2
- package/dist/declarations/src/actions/contracts/deprecatedWriteContract.d.ts +0 -16
- package/dist/declarations/src/actions/transactions/deprecatedSendTransaction.d.ts +0 -12
- package/dist/declarations/src/constants/multicall.d.ts +0 -25
- package/providers/coinbaseNode/dist/wagmi-core-providers-coinbaseNode.cjs.d.ts +0 -11
- package/providers/coinbaseNode/dist/wagmi-core-providers-coinbaseNode.cjs.js +0 -16
package/dist/wagmi-core.esm.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { A as AddChainError, f as ChainDoesNotSupportMulticallError,
|
|
3
|
-
import { providers, Contract as Contract$1 } from 'ethers';
|
|
1
|
+
import { C as ChainMismatchError, g as getClient, a as ConnectorAlreadyConnectedError, b as ContractResultDecodeError, c as ConnectorNotFoundError, d as ContractMethodDoesNotExistError, e as getProvider, P as ProviderChainsNotFound, f as ChainDoesNotSupportMulticallError, h as ContractMethodRevertedError, i as ContractMethodNoResultError, U as UserRejectedRequestError, n as normalizeChainId, S as SwitchChainNotSupportedError } from './getProvider-24ec6544.esm.js';
|
|
2
|
+
export { A as AddChainError, f as ChainDoesNotSupportMulticallError, C as ChainMismatchError, m as ChainNotConfiguredError, k as Client, l as Connector, a as ConnectorAlreadyConnectedError, c as ConnectorNotFoundError, d as ContractMethodDoesNotExistError, i as ContractMethodNoResultError, h as ContractMethodRevertedError, b as ContractResultDecodeError, I as InjectedConnector, P as ProviderChainsNotFound, o as ProviderRpcError, R as ResourceUnavailableError, p as RpcError, q as SwitchChainError, S as SwitchChainNotSupportedError, U as UserRejectedRequestError, j as createClient, r as createStorage, e as getProvider, s as noopStorage, n as normalizeChainId } from './getProvider-24ec6544.esm.js';
|
|
4
3
|
import { Contract, logger } from 'ethers/lib/ethers';
|
|
5
|
-
import { FormatTypes, parseBytes32String, formatUnits, getAddress,
|
|
6
|
-
import {
|
|
7
|
-
|
|
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-2970e5fa.esm.js';
|
|
7
|
+
export { a as allChains, c as chain, b as chainId, d as defaultChains, e as defaultL2Chains, f as etherscanBlockExplorers } from './chains-2970e5fa.esm.js';
|
|
8
8
|
import shallow from 'zustand/shallow';
|
|
9
9
|
import { d as debounce } from './debounce-0862bf88.esm.js';
|
|
10
|
-
export { a as alchemyRpcUrls, i as infuraRpcUrls, p as publicRpcUrls } from './rpcs-
|
|
10
|
+
export { a as alchemyRpcUrls, i as infuraRpcUrls, p as publicRpcUrls } from './rpcs-b4aa70b9.esm.js';
|
|
11
11
|
import 'zustand/middleware';
|
|
12
12
|
import 'zustand/vanilla';
|
|
13
13
|
import 'eventemitter3';
|
|
@@ -15,7 +15,7 @@ import 'eventemitter3';
|
|
|
15
15
|
function configureChains(defaultChains, providers) {
|
|
16
16
|
let {
|
|
17
17
|
minQuorum = 1,
|
|
18
|
-
pollingInterval =
|
|
18
|
+
pollingInterval = 4_000,
|
|
19
19
|
targetQuorum = 1,
|
|
20
20
|
stallTimeout
|
|
21
21
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
@@ -54,48 +54,63 @@ function configureChains(defaultChains, providers) {
|
|
|
54
54
|
|
|
55
55
|
|
|
56
56
|
if (!configExists) {
|
|
57
|
-
throw new Error([
|
|
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
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
return {
|
|
62
62
|
chains,
|
|
63
63
|
provider: _ref2 => {
|
|
64
|
-
var _defaultChains$;
|
|
65
|
-
|
|
66
64
|
let {
|
|
67
65
|
chainId
|
|
68
66
|
} = _ref2;
|
|
69
|
-
const
|
|
70
|
-
const chainProviders = providers_[
|
|
71
|
-
if (!chainProviders || !chainProviders[0]) throw new Error(
|
|
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;
|
|
72
71
|
|
|
73
72
|
if (chainProviders.length === 1) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
provider = chainProviders[0]();
|
|
74
|
+
} else {
|
|
75
|
+
provider = fallbackProvider(targetQuorum, minQuorum, chainProviders, {
|
|
76
|
+
stallTimeout
|
|
77
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
|
+
};
|
|
78
86
|
}
|
|
79
87
|
|
|
80
|
-
return Object.assign(
|
|
81
|
-
stallTimeout
|
|
82
|
-
}), {
|
|
88
|
+
return Object.assign(provider, {
|
|
83
89
|
chains,
|
|
84
90
|
pollingInterval
|
|
85
91
|
});
|
|
86
92
|
},
|
|
87
93
|
webSocketProvider: _ref3 => {
|
|
88
|
-
var
|
|
94
|
+
var _chainWebSocketProvid;
|
|
89
95
|
|
|
90
96
|
let {
|
|
91
97
|
chainId
|
|
92
98
|
} = _ref3;
|
|
93
|
-
const
|
|
94
|
-
const chainWebSocketProviders = webSocketProviders_[
|
|
95
|
-
if (!chainWebSocketProviders) return undefined;
|
|
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`
|
|
96
110
|
// Default to first available
|
|
97
111
|
|
|
98
|
-
|
|
112
|
+
|
|
113
|
+
return Object.assign(provider || {}, {
|
|
99
114
|
chains
|
|
100
115
|
});
|
|
101
116
|
}
|
|
@@ -109,13 +124,11 @@ function fallbackProvider(targetQuorum, minQuorum, providers_, _ref4) {
|
|
|
109
124
|
|
|
110
125
|
try {
|
|
111
126
|
return new providers.FallbackProvider(providers_.map((chainProvider, index) => {
|
|
112
|
-
var _provider$priority, _provider$stallTimeou;
|
|
113
|
-
|
|
114
127
|
const provider = chainProvider();
|
|
115
128
|
return {
|
|
116
129
|
provider,
|
|
117
|
-
priority:
|
|
118
|
-
stallTimeout:
|
|
130
|
+
priority: provider.priority ?? index,
|
|
131
|
+
stallTimeout: provider.stallTimeout ?? stallTimeout,
|
|
119
132
|
weight: provider.weight
|
|
120
133
|
};
|
|
121
134
|
}), targetQuorum);
|
|
@@ -133,6 +146,26 @@ function fallbackProvider(targetQuorum, minQuorum, providers_, _ref4) {
|
|
|
133
146
|
}
|
|
134
147
|
}
|
|
135
148
|
|
|
149
|
+
function assertActiveChain(_ref) {
|
|
150
|
+
let {
|
|
151
|
+
chainId
|
|
152
|
+
} = _ref;
|
|
153
|
+
const {
|
|
154
|
+
chain: activeChain,
|
|
155
|
+
chains
|
|
156
|
+
} = getNetwork();
|
|
157
|
+
const activeChainId = activeChain === null || activeChain === void 0 ? void 0 : activeChain.id;
|
|
158
|
+
|
|
159
|
+
if (chainId !== activeChainId) {
|
|
160
|
+
var _chains$find, _chains$find2;
|
|
161
|
+
|
|
162
|
+
throw new ChainMismatchError({
|
|
163
|
+
activeChain: ((_chains$find = chains.find(x => x.id === activeChainId)) === null || _chains$find === void 0 ? void 0 : _chains$find.name) ?? `Chain ${activeChainId}`,
|
|
164
|
+
targetChain: ((_chains$find2 = chains.find(x => x.id === chainId)) === null || _chains$find2 === void 0 ? void 0 : _chains$find2.name) ?? `Chain ${chainId}`
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
136
169
|
/** Forked from https://github.com/epoberezkin/fast-deep-equal */
|
|
137
170
|
function deepEqual(a, b) {
|
|
138
171
|
if (a === b) return true;
|
|
@@ -171,20 +204,100 @@ function deepEqual(a, b) {
|
|
|
171
204
|
return a !== a && b !== b;
|
|
172
205
|
}
|
|
173
206
|
|
|
207
|
+
/**
|
|
208
|
+
* Get normalized function name from contract
|
|
209
|
+
*
|
|
210
|
+
* @param contract — Contract
|
|
211
|
+
* @param functionName — Function name
|
|
212
|
+
* @param args — Function arguments (used to disambiguate overloaded functions)
|
|
213
|
+
*
|
|
214
|
+
* @returns Normalized function name
|
|
215
|
+
*/
|
|
216
|
+
|
|
217
|
+
function normalizeFunctionName(_ref) {
|
|
218
|
+
let {
|
|
219
|
+
contract,
|
|
220
|
+
functionName,
|
|
221
|
+
args = []
|
|
222
|
+
} = _ref;
|
|
223
|
+
// If `functionName` exists in contract, return it.
|
|
224
|
+
if (functionName in contract.functions) return functionName; // Otherwise, check if `functionName` is an overloaded function based on `args` shape.
|
|
225
|
+
|
|
226
|
+
const argsLength = (args === null || args === void 0 ? void 0 : args.length) ?? 0;
|
|
227
|
+
const overloadFunctions = Object.keys(contract.functions).filter(x => x.startsWith(`${functionName}(`)).map(x => ({
|
|
228
|
+
name: x,
|
|
229
|
+
fragment: FunctionFragment.fromString(x)
|
|
230
|
+
})).filter(x => argsLength === x.fragment.inputs.length);
|
|
231
|
+
|
|
232
|
+
for (const overloadFunction of overloadFunctions) {
|
|
233
|
+
const matched = args.every((arg, index) => {
|
|
234
|
+
const abiParameter = overloadFunction.fragment.inputs[index];
|
|
235
|
+
return isArgOfType(arg, abiParameter);
|
|
236
|
+
});
|
|
237
|
+
if (matched) return overloadFunction.name;
|
|
238
|
+
} // Wasn't able to find overload, just return function name.
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
return functionName;
|
|
242
|
+
}
|
|
243
|
+
function isArgOfType(arg, abiParameter) {
|
|
244
|
+
const argType = typeof arg;
|
|
245
|
+
const abiParameterType = abiParameter.type;
|
|
246
|
+
|
|
247
|
+
switch (abiParameterType) {
|
|
248
|
+
case 'address':
|
|
249
|
+
return isAddress(arg);
|
|
250
|
+
|
|
251
|
+
case 'bool':
|
|
252
|
+
return argType === 'boolean';
|
|
253
|
+
|
|
254
|
+
case 'function':
|
|
255
|
+
return argType === 'string';
|
|
256
|
+
|
|
257
|
+
case 'string':
|
|
258
|
+
return argType === 'string';
|
|
259
|
+
|
|
260
|
+
default:
|
|
261
|
+
{
|
|
262
|
+
if (abiParameterType === 'tuple' && 'components' in abiParameter) return Object.values(abiParameter.components).every((component, index) => {
|
|
263
|
+
return isArgOfType(Object.values(arg)[index], component);
|
|
264
|
+
}); // `(u)int<M>`: (un)signed integer type of `M` bits, `0 < M <= 256`, `M % 8 == 0`
|
|
265
|
+
// https://regexr.com/6v8hp
|
|
266
|
+
|
|
267
|
+
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`
|
|
268
|
+
// https://regexr.com/6va55
|
|
269
|
+
|
|
270
|
+
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
|
|
271
|
+
// https://regexr.com/6va6i
|
|
272
|
+
|
|
273
|
+
if (/[a-z]+[1-9]{0,3}(\[[0-9]{0,}\])+$/.test(abiParameterType)) {
|
|
274
|
+
return Array.isArray(arg) && arg.every(x => isArgOfType(x, { ...abiParameter,
|
|
275
|
+
// Pop off `[]` or `[M]` from end of type
|
|
276
|
+
type: abiParameterType.replace(/(\[[0-9]{0,}\])$/, '')
|
|
277
|
+
}));
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
174
285
|
function logWarn(message) {
|
|
175
286
|
var _getClient, _getClient$config$log, _getClient$config$log2;
|
|
176
287
|
|
|
177
288
|
(_getClient = getClient()) === null || _getClient === void 0 ? void 0 : (_getClient$config$log = _getClient.config.logger) === null || _getClient$config$log === void 0 ? void 0 : (_getClient$config$log2 = _getClient$config$log.warn) === null || _getClient$config$log2 === void 0 ? void 0 : _getClient$config$log2.call(_getClient$config$log, message);
|
|
178
289
|
}
|
|
179
290
|
|
|
180
|
-
function minimizeContractInterface(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
291
|
+
function minimizeContractInterface(config) {
|
|
292
|
+
try {
|
|
293
|
+
const minimizedAbi = config.abi.filter(x => x.type === 'function' && x.name === config.functionName);
|
|
294
|
+
if (minimizedAbi.length === 0) throw new Error('Invalid ABI');
|
|
295
|
+
return minimizedAbi;
|
|
296
|
+
} catch (error) {
|
|
297
|
+
const abi = Contract.getInterface(config.abi).format(FormatTypes.full);
|
|
298
|
+
const minimizedInterface = Array.isArray(abi) ? abi : [abi];
|
|
299
|
+
return minimizedInterface.filter(i => i.includes(config.functionName));
|
|
300
|
+
}
|
|
188
301
|
}
|
|
189
302
|
|
|
190
303
|
function isPlainArray(value) {
|
|
@@ -193,7 +306,7 @@ function isPlainArray(value) {
|
|
|
193
306
|
|
|
194
307
|
function parseContractResult(_ref) {
|
|
195
308
|
let {
|
|
196
|
-
|
|
309
|
+
abi,
|
|
197
310
|
data,
|
|
198
311
|
functionName
|
|
199
312
|
} = _ref;
|
|
@@ -201,7 +314,7 @@ function parseContractResult(_ref) {
|
|
|
201
314
|
if (data && isPlainArray(data)) {
|
|
202
315
|
var _fragment$outputs;
|
|
203
316
|
|
|
204
|
-
const iface = Contract.getInterface(
|
|
317
|
+
const iface = Contract.getInterface(abi);
|
|
205
318
|
const fragment = iface.getFunction(functionName);
|
|
206
319
|
const isTuple = (((_fragment$outputs = fragment.outputs) === null || _fragment$outputs === void 0 ? void 0 : _fragment$outputs.length) || 0) > 1;
|
|
207
320
|
const data_ = isTuple ? data : [data];
|
|
@@ -213,8 +326,153 @@ function parseContractResult(_ref) {
|
|
|
213
326
|
return data;
|
|
214
327
|
}
|
|
215
328
|
|
|
216
|
-
|
|
217
|
-
|
|
329
|
+
/**
|
|
330
|
+
* [ERC-20 Token Standard](https://ethereum.org/en/developers/docs/standards/tokens/erc-20)
|
|
331
|
+
*/
|
|
332
|
+
const erc20ABI = [{
|
|
333
|
+
type: 'event',
|
|
334
|
+
name: 'Approval',
|
|
335
|
+
inputs: [{
|
|
336
|
+
indexed: true,
|
|
337
|
+
name: 'owner',
|
|
338
|
+
type: 'address'
|
|
339
|
+
}, {
|
|
340
|
+
indexed: true,
|
|
341
|
+
name: 'spender',
|
|
342
|
+
type: 'address'
|
|
343
|
+
}, {
|
|
344
|
+
indexed: false,
|
|
345
|
+
name: 'value',
|
|
346
|
+
type: 'uint256'
|
|
347
|
+
}]
|
|
348
|
+
}, {
|
|
349
|
+
type: 'event',
|
|
350
|
+
name: 'Transfer',
|
|
351
|
+
inputs: [{
|
|
352
|
+
indexed: true,
|
|
353
|
+
name: 'from',
|
|
354
|
+
type: 'address'
|
|
355
|
+
}, {
|
|
356
|
+
indexed: true,
|
|
357
|
+
name: 'to',
|
|
358
|
+
type: 'address'
|
|
359
|
+
}, {
|
|
360
|
+
indexed: false,
|
|
361
|
+
name: 'value',
|
|
362
|
+
type: 'uint256'
|
|
363
|
+
}]
|
|
364
|
+
}, {
|
|
365
|
+
type: 'function',
|
|
366
|
+
name: 'allowance',
|
|
367
|
+
stateMutability: 'view',
|
|
368
|
+
inputs: [{
|
|
369
|
+
name: 'owner',
|
|
370
|
+
type: 'address'
|
|
371
|
+
}, {
|
|
372
|
+
name: 'spender',
|
|
373
|
+
type: 'address'
|
|
374
|
+
}],
|
|
375
|
+
outputs: [{
|
|
376
|
+
name: '',
|
|
377
|
+
type: 'uint256'
|
|
378
|
+
}]
|
|
379
|
+
}, {
|
|
380
|
+
type: 'function',
|
|
381
|
+
name: 'approve',
|
|
382
|
+
stateMutability: 'nonpayable',
|
|
383
|
+
inputs: [{
|
|
384
|
+
name: 'spender',
|
|
385
|
+
type: 'address'
|
|
386
|
+
}, {
|
|
387
|
+
name: 'amount',
|
|
388
|
+
type: 'uint256'
|
|
389
|
+
}],
|
|
390
|
+
outputs: [{
|
|
391
|
+
name: '',
|
|
392
|
+
type: 'bool'
|
|
393
|
+
}]
|
|
394
|
+
}, {
|
|
395
|
+
type: 'function',
|
|
396
|
+
name: 'balanceOf',
|
|
397
|
+
stateMutability: 'view',
|
|
398
|
+
inputs: [{
|
|
399
|
+
name: 'account',
|
|
400
|
+
type: 'address'
|
|
401
|
+
}],
|
|
402
|
+
outputs: [{
|
|
403
|
+
name: '',
|
|
404
|
+
type: 'uint256'
|
|
405
|
+
}]
|
|
406
|
+
}, {
|
|
407
|
+
type: 'function',
|
|
408
|
+
name: 'decimals',
|
|
409
|
+
stateMutability: 'view',
|
|
410
|
+
inputs: [],
|
|
411
|
+
outputs: [{
|
|
412
|
+
name: '',
|
|
413
|
+
type: 'uint8'
|
|
414
|
+
}]
|
|
415
|
+
}, {
|
|
416
|
+
type: 'function',
|
|
417
|
+
name: 'name',
|
|
418
|
+
stateMutability: 'view',
|
|
419
|
+
inputs: [],
|
|
420
|
+
outputs: [{
|
|
421
|
+
name: '',
|
|
422
|
+
type: 'string'
|
|
423
|
+
}]
|
|
424
|
+
}, {
|
|
425
|
+
type: 'function',
|
|
426
|
+
name: 'symbol',
|
|
427
|
+
stateMutability: 'view',
|
|
428
|
+
inputs: [],
|
|
429
|
+
outputs: [{
|
|
430
|
+
name: '',
|
|
431
|
+
type: 'string'
|
|
432
|
+
}]
|
|
433
|
+
}, {
|
|
434
|
+
type: 'function',
|
|
435
|
+
name: 'totalSupply',
|
|
436
|
+
stateMutability: 'view',
|
|
437
|
+
inputs: [],
|
|
438
|
+
outputs: [{
|
|
439
|
+
name: '',
|
|
440
|
+
type: 'uint256'
|
|
441
|
+
}]
|
|
442
|
+
}, {
|
|
443
|
+
type: 'function',
|
|
444
|
+
name: 'transfer',
|
|
445
|
+
stateMutability: 'nonpayable',
|
|
446
|
+
inputs: [{
|
|
447
|
+
name: 'recipient',
|
|
448
|
+
type: 'address'
|
|
449
|
+
}, {
|
|
450
|
+
name: 'amount',
|
|
451
|
+
type: 'uint256'
|
|
452
|
+
}],
|
|
453
|
+
outputs: [{
|
|
454
|
+
name: '',
|
|
455
|
+
type: 'bool'
|
|
456
|
+
}]
|
|
457
|
+
}, {
|
|
458
|
+
type: 'function',
|
|
459
|
+
name: 'transferFrom',
|
|
460
|
+
stateMutability: 'nonpayable',
|
|
461
|
+
inputs: [{
|
|
462
|
+
name: 'sender',
|
|
463
|
+
type: 'address'
|
|
464
|
+
}, {
|
|
465
|
+
name: 'recipient',
|
|
466
|
+
type: 'address'
|
|
467
|
+
}, {
|
|
468
|
+
name: 'amount',
|
|
469
|
+
type: 'uint256'
|
|
470
|
+
}],
|
|
471
|
+
outputs: [{
|
|
472
|
+
name: '',
|
|
473
|
+
type: 'bool'
|
|
474
|
+
}]
|
|
475
|
+
}];
|
|
218
476
|
/**
|
|
219
477
|
* [bytes32-flavored ERC-20](https://docs.makerdao.com/smart-contract-modules/mkr-module#4.-gotchas-potential-source-of-user-error)
|
|
220
478
|
* for tokens (ie. Maker) that use bytes32 instead of string.
|
|
@@ -363,41 +621,277 @@ const erc20ABI_bytes32 = [{
|
|
|
363
621
|
name: '',
|
|
364
622
|
type: 'bool'
|
|
365
623
|
}]
|
|
366
|
-
}];
|
|
624
|
+
}];
|
|
625
|
+
/**
|
|
626
|
+
* [ERC-721 Non-Fungible Token Standard](https://ethereum.org/en/developers/docs/standards/tokens/erc-721)
|
|
627
|
+
*/
|
|
367
628
|
|
|
368
|
-
const erc721ABI = [
|
|
629
|
+
const erc721ABI = [{
|
|
630
|
+
type: 'event',
|
|
631
|
+
name: 'Approval',
|
|
632
|
+
inputs: [{
|
|
633
|
+
indexed: true,
|
|
634
|
+
name: 'owner',
|
|
635
|
+
type: 'address'
|
|
636
|
+
}, {
|
|
637
|
+
indexed: true,
|
|
638
|
+
name: 'spender',
|
|
639
|
+
type: 'address'
|
|
640
|
+
}, {
|
|
641
|
+
indexed: true,
|
|
642
|
+
name: 'tokenId',
|
|
643
|
+
type: 'uint256'
|
|
644
|
+
}]
|
|
645
|
+
}, {
|
|
646
|
+
type: 'event',
|
|
647
|
+
name: 'ApprovalForAll',
|
|
648
|
+
inputs: [{
|
|
649
|
+
indexed: true,
|
|
650
|
+
name: 'owner',
|
|
651
|
+
type: 'address'
|
|
652
|
+
}, {
|
|
653
|
+
indexed: true,
|
|
654
|
+
name: 'operator',
|
|
655
|
+
type: 'address'
|
|
656
|
+
}, {
|
|
657
|
+
indexed: false,
|
|
658
|
+
name: 'approved',
|
|
659
|
+
type: 'bool'
|
|
660
|
+
}]
|
|
661
|
+
}, {
|
|
662
|
+
type: 'event',
|
|
663
|
+
name: 'Transfer',
|
|
664
|
+
inputs: [{
|
|
665
|
+
indexed: true,
|
|
666
|
+
name: 'from',
|
|
667
|
+
type: 'address'
|
|
668
|
+
}, {
|
|
669
|
+
indexed: true,
|
|
670
|
+
name: 'to',
|
|
671
|
+
type: 'address'
|
|
672
|
+
}, {
|
|
673
|
+
indexed: true,
|
|
674
|
+
name: 'tokenId',
|
|
675
|
+
type: 'uint256'
|
|
676
|
+
}]
|
|
677
|
+
}, {
|
|
678
|
+
type: 'function',
|
|
679
|
+
name: 'approve',
|
|
680
|
+
stateMutability: 'payable',
|
|
681
|
+
inputs: [{
|
|
682
|
+
name: 'spender',
|
|
683
|
+
type: 'address'
|
|
684
|
+
}, {
|
|
685
|
+
name: 'tokenId',
|
|
686
|
+
type: 'uint256'
|
|
687
|
+
}],
|
|
688
|
+
outputs: []
|
|
689
|
+
}, {
|
|
690
|
+
type: 'function',
|
|
691
|
+
name: 'balanceOf',
|
|
692
|
+
stateMutability: 'view',
|
|
693
|
+
inputs: [{
|
|
694
|
+
name: 'account',
|
|
695
|
+
type: 'address'
|
|
696
|
+
}],
|
|
697
|
+
outputs: [{
|
|
698
|
+
name: '',
|
|
699
|
+
type: 'uint256'
|
|
700
|
+
}]
|
|
701
|
+
}, {
|
|
702
|
+
type: 'function',
|
|
703
|
+
name: 'getApproved',
|
|
704
|
+
stateMutability: 'view',
|
|
705
|
+
inputs: [{
|
|
706
|
+
name: 'tokenId',
|
|
707
|
+
type: 'uint256'
|
|
708
|
+
}],
|
|
709
|
+
outputs: [{
|
|
710
|
+
name: '',
|
|
711
|
+
type: 'address'
|
|
712
|
+
}]
|
|
713
|
+
}, {
|
|
714
|
+
type: 'function',
|
|
715
|
+
name: 'isApprovedForAll',
|
|
716
|
+
stateMutability: 'view',
|
|
717
|
+
inputs: [{
|
|
718
|
+
name: 'owner',
|
|
719
|
+
type: 'address'
|
|
720
|
+
}, {
|
|
721
|
+
name: 'operator',
|
|
722
|
+
type: 'address'
|
|
723
|
+
}],
|
|
724
|
+
outputs: [{
|
|
725
|
+
name: '',
|
|
726
|
+
type: 'bool'
|
|
727
|
+
}]
|
|
728
|
+
}, {
|
|
729
|
+
type: 'function',
|
|
730
|
+
name: 'name',
|
|
731
|
+
stateMutability: 'view',
|
|
732
|
+
inputs: [],
|
|
733
|
+
outputs: [{
|
|
734
|
+
name: '',
|
|
735
|
+
type: 'string'
|
|
736
|
+
}]
|
|
737
|
+
}, {
|
|
738
|
+
type: 'function',
|
|
739
|
+
name: 'ownerOf',
|
|
740
|
+
stateMutability: 'view',
|
|
741
|
+
inputs: [{
|
|
742
|
+
name: 'tokenId',
|
|
743
|
+
type: 'uint256'
|
|
744
|
+
}],
|
|
745
|
+
outputs: [{
|
|
746
|
+
name: 'owner',
|
|
747
|
+
type: 'address'
|
|
748
|
+
}]
|
|
749
|
+
}, {
|
|
750
|
+
type: 'function',
|
|
751
|
+
name: 'safeTransferFrom',
|
|
752
|
+
stateMutability: 'payable',
|
|
753
|
+
inputs: [{
|
|
754
|
+
name: 'from',
|
|
755
|
+
type: 'address'
|
|
756
|
+
}, {
|
|
757
|
+
name: 'to',
|
|
758
|
+
type: 'address'
|
|
759
|
+
}, {
|
|
760
|
+
name: 'tokenId',
|
|
761
|
+
type: 'uint256'
|
|
762
|
+
}],
|
|
763
|
+
outputs: []
|
|
764
|
+
}, {
|
|
765
|
+
type: 'function',
|
|
766
|
+
name: 'safeTransferFrom',
|
|
767
|
+
stateMutability: 'nonpayable',
|
|
768
|
+
inputs: [{
|
|
769
|
+
name: 'from',
|
|
770
|
+
type: 'address'
|
|
771
|
+
}, {
|
|
772
|
+
name: 'to',
|
|
773
|
+
type: 'address'
|
|
774
|
+
}, {
|
|
775
|
+
name: 'id',
|
|
776
|
+
type: 'uint256'
|
|
777
|
+
}, {
|
|
778
|
+
name: 'data',
|
|
779
|
+
type: 'bytes'
|
|
780
|
+
}],
|
|
781
|
+
outputs: []
|
|
782
|
+
}, {
|
|
783
|
+
type: 'function',
|
|
784
|
+
name: 'setApprovalForAll',
|
|
785
|
+
stateMutability: 'nonpayable',
|
|
786
|
+
inputs: [{
|
|
787
|
+
name: 'operator',
|
|
788
|
+
type: 'address'
|
|
789
|
+
}, {
|
|
790
|
+
name: 'approved',
|
|
791
|
+
type: 'bool'
|
|
792
|
+
}],
|
|
793
|
+
outputs: []
|
|
794
|
+
}, {
|
|
795
|
+
type: 'function',
|
|
796
|
+
name: 'symbol',
|
|
797
|
+
stateMutability: 'view',
|
|
798
|
+
inputs: [],
|
|
799
|
+
outputs: [{
|
|
800
|
+
name: '',
|
|
801
|
+
type: 'string'
|
|
802
|
+
}]
|
|
803
|
+
}, {
|
|
804
|
+
type: 'function',
|
|
805
|
+
name: 'tokenByIndex',
|
|
806
|
+
stateMutability: 'view',
|
|
807
|
+
inputs: [{
|
|
808
|
+
name: 'index',
|
|
809
|
+
type: 'uint256'
|
|
810
|
+
}],
|
|
811
|
+
outputs: [{
|
|
812
|
+
name: '',
|
|
813
|
+
type: 'uint256'
|
|
814
|
+
}]
|
|
815
|
+
}, {
|
|
816
|
+
type: 'function',
|
|
817
|
+
name: 'tokenByIndex',
|
|
818
|
+
stateMutability: 'view',
|
|
819
|
+
inputs: [{
|
|
820
|
+
name: 'owner',
|
|
821
|
+
type: 'address'
|
|
822
|
+
}, {
|
|
823
|
+
name: 'index',
|
|
824
|
+
type: 'uint256'
|
|
825
|
+
}],
|
|
826
|
+
outputs: [{
|
|
827
|
+
name: 'tokenId',
|
|
828
|
+
type: 'uint256'
|
|
829
|
+
}]
|
|
830
|
+
}, {
|
|
831
|
+
type: 'function',
|
|
832
|
+
name: 'tokenURI',
|
|
833
|
+
stateMutability: 'view',
|
|
834
|
+
inputs: [{
|
|
835
|
+
name: 'tokenId',
|
|
836
|
+
type: 'uint256'
|
|
837
|
+
}],
|
|
838
|
+
outputs: [{
|
|
839
|
+
name: '',
|
|
840
|
+
type: 'string'
|
|
841
|
+
}]
|
|
842
|
+
}, {
|
|
843
|
+
type: 'function',
|
|
844
|
+
name: 'totalSupply',
|
|
845
|
+
stateMutability: 'view',
|
|
846
|
+
inputs: [],
|
|
847
|
+
outputs: [{
|
|
848
|
+
name: '',
|
|
849
|
+
type: 'uint256'
|
|
850
|
+
}]
|
|
851
|
+
}, {
|
|
852
|
+
type: 'function',
|
|
853
|
+
name: 'transferFrom',
|
|
854
|
+
stateMutability: 'payable',
|
|
855
|
+
inputs: [{
|
|
856
|
+
name: 'sender',
|
|
857
|
+
type: 'address'
|
|
858
|
+
}, {
|
|
859
|
+
name: 'recipient',
|
|
860
|
+
type: 'address'
|
|
861
|
+
}, {
|
|
862
|
+
name: 'tokeId',
|
|
863
|
+
type: 'uint256'
|
|
864
|
+
}],
|
|
865
|
+
outputs: []
|
|
866
|
+
}];
|
|
867
|
+
/**
|
|
868
|
+
* [Multicall3](https://github.com/mds1/multicall)
|
|
869
|
+
*/
|
|
369
870
|
|
|
370
|
-
const
|
|
871
|
+
const multicallABI = [{
|
|
371
872
|
inputs: [{
|
|
372
873
|
components: [{
|
|
373
|
-
internalType: 'address',
|
|
374
874
|
name: 'target',
|
|
375
875
|
type: 'address'
|
|
376
876
|
}, {
|
|
377
|
-
internalType: 'bool',
|
|
378
877
|
name: 'allowFailure',
|
|
379
878
|
type: 'bool'
|
|
380
879
|
}, {
|
|
381
|
-
internalType: 'bytes',
|
|
382
880
|
name: 'callData',
|
|
383
881
|
type: 'bytes'
|
|
384
882
|
}],
|
|
385
|
-
internalType: 'struct Multicall3.Call3[]',
|
|
386
883
|
name: 'calls',
|
|
387
884
|
type: 'tuple[]'
|
|
388
885
|
}],
|
|
389
886
|
name: 'aggregate3',
|
|
390
887
|
outputs: [{
|
|
391
888
|
components: [{
|
|
392
|
-
internalType: 'bool',
|
|
393
889
|
name: 'success',
|
|
394
890
|
type: 'bool'
|
|
395
891
|
}, {
|
|
396
|
-
internalType: 'bytes',
|
|
397
892
|
name: 'returnData',
|
|
398
893
|
type: 'bytes'
|
|
399
894
|
}],
|
|
400
|
-
internalType: 'struct Multicall3.Result[]',
|
|
401
895
|
name: 'returnData',
|
|
402
896
|
type: 'tuple[]'
|
|
403
897
|
}],
|
|
@@ -438,82 +932,21 @@ async function connect(_ref) {
|
|
|
438
932
|
} catch (err) {
|
|
439
933
|
client.setState(x => {
|
|
440
934
|
return { ...x,
|
|
441
|
-
// Keep existing connector connected in case of error
|
|
442
|
-
status: x.connector ? 'connected' : 'disconnected'
|
|
443
|
-
};
|
|
444
|
-
});
|
|
445
|
-
throw err;
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
async function disconnect() {
|
|
450
|
-
const client = getClient();
|
|
451
|
-
if (client.connector) await client.connector.disconnect();
|
|
452
|
-
client.clearState();
|
|
453
|
-
client.storage.removeItem('connected');
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
function getContract(_ref) {
|
|
457
|
-
let {
|
|
458
|
-
addressOrName,
|
|
459
|
-
contractInterface,
|
|
460
|
-
signerOrProvider
|
|
461
|
-
} = _ref;
|
|
462
|
-
return new Contract$1(addressOrName, contractInterface, signerOrProvider);
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
async function deprecatedWriteContract(_ref) {
|
|
466
|
-
let {
|
|
467
|
-
addressOrName,
|
|
468
|
-
args,
|
|
469
|
-
chainId,
|
|
470
|
-
contractInterface,
|
|
471
|
-
functionName,
|
|
472
|
-
overrides,
|
|
473
|
-
signerOrProvider
|
|
474
|
-
} = _ref;
|
|
475
|
-
const {
|
|
476
|
-
connector
|
|
477
|
-
} = getClient();
|
|
478
|
-
if (!connector) throw new ConnectorNotFoundError();
|
|
479
|
-
const params = [...(Array.isArray(args) ? args : args ? [args] : []), ...(overrides ? [overrides] : [])];
|
|
480
|
-
|
|
481
|
-
try {
|
|
482
|
-
var _chain;
|
|
483
|
-
|
|
484
|
-
let chain;
|
|
485
|
-
|
|
486
|
-
if (chainId) {
|
|
487
|
-
const activeChainId = await connector.getChainId(); // Try to switch chain to provided `chainId`
|
|
488
|
-
|
|
489
|
-
if (chainId !== activeChainId) {
|
|
490
|
-
var _connector$chains$fin, _connector$chains$fin2, _connector$chains$fin3, _connector$chains$fin4;
|
|
491
|
-
|
|
492
|
-
if (connector.switchChain) chain = await connector.switchChain(chainId);else throw new ChainMismatchError({
|
|
493
|
-
activeChain: (_connector$chains$fin = (_connector$chains$fin2 = connector.chains.find(x => x.id === activeChainId)) === null || _connector$chains$fin2 === void 0 ? void 0 : _connector$chains$fin2.name) !== null && _connector$chains$fin !== void 0 ? _connector$chains$fin : "Chain ".concat(activeChainId),
|
|
494
|
-
targetChain: (_connector$chains$fin3 = (_connector$chains$fin4 = connector.chains.find(x => x.id === chainId)) === null || _connector$chains$fin4 === void 0 ? void 0 : _connector$chains$fin4.name) !== null && _connector$chains$fin3 !== void 0 ? _connector$chains$fin3 : "Chain ".concat(chainId)
|
|
495
|
-
});
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
const signer = await connector.getSigner({
|
|
500
|
-
chainId: (_chain = chain) === null || _chain === void 0 ? void 0 : _chain.id
|
|
501
|
-
});
|
|
502
|
-
const contract = getContract({
|
|
503
|
-
addressOrName,
|
|
504
|
-
contractInterface,
|
|
505
|
-
signerOrProvider
|
|
935
|
+
// Keep existing connector connected in case of error
|
|
936
|
+
status: x.connector ? 'connected' : 'disconnected'
|
|
937
|
+
};
|
|
506
938
|
});
|
|
507
|
-
|
|
508
|
-
const contractFunction = contractWithSigner[functionName];
|
|
509
|
-
if (!contractFunction) logWarn("\"".concat(functionName, "\" does not exist in interface for contract \"").concat(addressOrName, "\""));
|
|
510
|
-
return await contractFunction(...params);
|
|
511
|
-
} catch (error) {
|
|
512
|
-
if (error.code === 4001) throw new UserRejectedRequestError(error);
|
|
513
|
-
throw error;
|
|
939
|
+
throw err;
|
|
514
940
|
}
|
|
515
941
|
}
|
|
516
942
|
|
|
943
|
+
async function disconnect() {
|
|
944
|
+
const client = getClient();
|
|
945
|
+
if (client.connector) await client.connector.disconnect();
|
|
946
|
+
client.clearState();
|
|
947
|
+
client.storage.removeItem('connected');
|
|
948
|
+
}
|
|
949
|
+
|
|
517
950
|
async function fetchToken(_ref) {
|
|
518
951
|
let {
|
|
519
952
|
address,
|
|
@@ -523,11 +956,11 @@ async function fetchToken(_ref) {
|
|
|
523
956
|
|
|
524
957
|
async function fetchToken_(_ref2) {
|
|
525
958
|
let {
|
|
526
|
-
|
|
959
|
+
abi
|
|
527
960
|
} = _ref2;
|
|
528
961
|
const erc20Config = {
|
|
529
|
-
|
|
530
|
-
|
|
962
|
+
address,
|
|
963
|
+
abi,
|
|
531
964
|
chainId
|
|
532
965
|
};
|
|
533
966
|
const [decimals, name, symbol, totalSupply] = await readContracts({
|
|
@@ -545,8 +978,10 @@ async function fetchToken(_ref) {
|
|
|
545
978
|
return {
|
|
546
979
|
address,
|
|
547
980
|
decimals,
|
|
548
|
-
name,
|
|
549
|
-
|
|
981
|
+
name: name,
|
|
982
|
+
// protect against `ResolvedConfig['BytesType']`
|
|
983
|
+
symbol: symbol,
|
|
984
|
+
// protect against `ResolvedConfig['BytesType']`
|
|
550
985
|
totalSupply: {
|
|
551
986
|
formatted: formatUnits(totalSupply, units),
|
|
552
987
|
value: totalSupply
|
|
@@ -556,7 +991,7 @@ async function fetchToken(_ref) {
|
|
|
556
991
|
|
|
557
992
|
try {
|
|
558
993
|
return await fetchToken_({
|
|
559
|
-
|
|
994
|
+
abi: erc20ABI
|
|
560
995
|
});
|
|
561
996
|
} catch (err) {
|
|
562
997
|
// In the chance that there is an error upon decoding the contract result,
|
|
@@ -568,7 +1003,7 @@ async function fetchToken(_ref) {
|
|
|
568
1003
|
symbol,
|
|
569
1004
|
...rest
|
|
570
1005
|
} = await fetchToken_({
|
|
571
|
-
|
|
1006
|
+
abi: erc20ABI_bytes32
|
|
572
1007
|
});
|
|
573
1008
|
return {
|
|
574
1009
|
name: parseBytes32String(name),
|
|
@@ -581,6 +1016,17 @@ async function fetchToken(_ref) {
|
|
|
581
1016
|
}
|
|
582
1017
|
}
|
|
583
1018
|
|
|
1019
|
+
function getContract(_ref) {
|
|
1020
|
+
let {
|
|
1021
|
+
address,
|
|
1022
|
+
abi,
|
|
1023
|
+
signerOrProvider
|
|
1024
|
+
} = _ref;
|
|
1025
|
+
return new Contract$1(address, abi, signerOrProvider);
|
|
1026
|
+
} ////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
1027
|
+
// Contract
|
|
1028
|
+
// TODO: Add remaining properties
|
|
1029
|
+
|
|
584
1030
|
/**
|
|
585
1031
|
* @description Prepares the parameters required for a contract write transaction.
|
|
586
1032
|
*
|
|
@@ -590,58 +1036,63 @@ async function fetchToken(_ref) {
|
|
|
590
1036
|
* import { prepareWriteContract, writeContract } from '@wagmi/core'
|
|
591
1037
|
*
|
|
592
1038
|
* const config = await prepareWriteContract({
|
|
593
|
-
*
|
|
594
|
-
*
|
|
1039
|
+
* address: '0x...',
|
|
1040
|
+
* abi: wagmiAbi,
|
|
595
1041
|
* functionName: 'mint',
|
|
596
1042
|
* })
|
|
597
1043
|
* const result = await writeContract(config)
|
|
598
1044
|
*/
|
|
599
1045
|
async function prepareWriteContract(_ref) {
|
|
600
1046
|
let {
|
|
601
|
-
|
|
1047
|
+
abi,
|
|
1048
|
+
address,
|
|
602
1049
|
args,
|
|
603
1050
|
chainId,
|
|
604
|
-
contractInterface: contractInterface_,
|
|
605
1051
|
functionName,
|
|
606
1052
|
overrides,
|
|
607
1053
|
signer: signer_
|
|
608
1054
|
} = _ref;
|
|
609
|
-
const signer = signer_
|
|
1055
|
+
const signer = signer_ ?? (await fetchSigner({
|
|
1056
|
+
chainId
|
|
1057
|
+
}));
|
|
610
1058
|
if (!signer) throw new ConnectorNotFoundError();
|
|
1059
|
+
if (chainId) assertActiveChain({
|
|
1060
|
+
chainId
|
|
1061
|
+
});
|
|
611
1062
|
const contract = getContract({
|
|
612
|
-
|
|
613
|
-
|
|
1063
|
+
address,
|
|
1064
|
+
abi: abi,
|
|
1065
|
+
// TODO: Remove cast and still support `Narrow<TAbi>`
|
|
614
1066
|
signerOrProvider: signer
|
|
615
1067
|
});
|
|
616
|
-
const
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
const contractInterface = minimizeContractInterface({
|
|
626
|
-
contractInterface: contract.interface,
|
|
627
|
-
functionName
|
|
1068
|
+
const normalizedFunctionName = normalizeFunctionName({
|
|
1069
|
+
contract,
|
|
1070
|
+
functionName,
|
|
1071
|
+
args
|
|
1072
|
+
});
|
|
1073
|
+
const populateTransactionFn = contract.populateTransaction[normalizedFunctionName];
|
|
1074
|
+
if (!populateTransactionFn) throw new ContractMethodDoesNotExistError({
|
|
1075
|
+
address,
|
|
1076
|
+
functionName: normalizedFunctionName
|
|
628
1077
|
});
|
|
629
|
-
const params = [...(
|
|
1078
|
+
const params = [...(args ?? []), ...(overrides ? [overrides] : [])];
|
|
630
1079
|
const unsignedTransaction = await populateTransactionFn(...params);
|
|
631
1080
|
const gasLimit = unsignedTransaction.gasLimit || (await signer.estimateGas(unsignedTransaction));
|
|
1081
|
+
const minimizedAbi = minimizeContractInterface({
|
|
1082
|
+
abi: abi,
|
|
1083
|
+
// TODO: Remove cast and still support `Narrow<TAbi>`
|
|
1084
|
+
functionName
|
|
1085
|
+
});
|
|
632
1086
|
return {
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
functionName,
|
|
640
|
-
overrides,
|
|
1087
|
+
abi: minimizedAbi,
|
|
1088
|
+
address,
|
|
1089
|
+
chainId,
|
|
1090
|
+
// TODO: Remove cast
|
|
1091
|
+
functionName: functionName,
|
|
1092
|
+
mode: 'prepared',
|
|
641
1093
|
request: { ...unsignedTransaction,
|
|
642
1094
|
gasLimit
|
|
643
|
-
}
|
|
644
|
-
mode: 'prepared'
|
|
1095
|
+
}
|
|
645
1096
|
};
|
|
646
1097
|
}
|
|
647
1098
|
|
|
@@ -684,30 +1135,6 @@ function watchWebSocketProvider(args, callback) {
|
|
|
684
1135
|
return unsubscribe;
|
|
685
1136
|
}
|
|
686
1137
|
|
|
687
|
-
async function readContract(_ref) {
|
|
688
|
-
let {
|
|
689
|
-
addressOrName,
|
|
690
|
-
args,
|
|
691
|
-
chainId,
|
|
692
|
-
contractInterface,
|
|
693
|
-
functionName,
|
|
694
|
-
overrides
|
|
695
|
-
} = _ref;
|
|
696
|
-
const provider = getProvider({
|
|
697
|
-
chainId
|
|
698
|
-
});
|
|
699
|
-
const contract = getContract({
|
|
700
|
-
addressOrName,
|
|
701
|
-
contractInterface,
|
|
702
|
-
signerOrProvider: provider
|
|
703
|
-
});
|
|
704
|
-
const params = [...(Array.isArray(args) ? args : args ? [args] : []), ...(overrides ? [overrides] : [])];
|
|
705
|
-
const contractFunction = contract[functionName];
|
|
706
|
-
if (!contractFunction) logWarn("\"".concat(functionName, "\" is not in the interface for contract \"").concat(addressOrName, "\""));
|
|
707
|
-
const response = await (contractFunction === null || contractFunction === void 0 ? void 0 : contractFunction(...params));
|
|
708
|
-
return response;
|
|
709
|
-
}
|
|
710
|
-
|
|
711
1138
|
async function multicall(_ref) {
|
|
712
1139
|
let {
|
|
713
1140
|
allowFailure = true,
|
|
@@ -729,14 +1156,14 @@ async function multicall(_ref) {
|
|
|
729
1156
|
chain
|
|
730
1157
|
});
|
|
731
1158
|
const multicallContract = getContract({
|
|
732
|
-
|
|
733
|
-
|
|
1159
|
+
address: chain.multicall.address,
|
|
1160
|
+
abi: multicallABI,
|
|
734
1161
|
signerOrProvider: provider
|
|
735
1162
|
});
|
|
736
1163
|
const calls = contracts.map(_ref2 => {
|
|
737
1164
|
let {
|
|
738
|
-
|
|
739
|
-
|
|
1165
|
+
address,
|
|
1166
|
+
abi,
|
|
740
1167
|
functionName,
|
|
741
1168
|
...config
|
|
742
1169
|
} = _ref2;
|
|
@@ -744,57 +1171,71 @@ async function multicall(_ref) {
|
|
|
744
1171
|
args
|
|
745
1172
|
} = config || {};
|
|
746
1173
|
const contract = getContract({
|
|
747
|
-
|
|
748
|
-
|
|
1174
|
+
address,
|
|
1175
|
+
abi
|
|
1176
|
+
});
|
|
1177
|
+
const params = args ?? [];
|
|
1178
|
+
const normalizedFunctionName = normalizeFunctionName({
|
|
1179
|
+
contract,
|
|
1180
|
+
functionName,
|
|
1181
|
+
args
|
|
749
1182
|
});
|
|
750
|
-
const params = Array.isArray(args) ? args : args ? [args] : [];
|
|
751
1183
|
|
|
752
1184
|
try {
|
|
753
|
-
const
|
|
754
|
-
if (!
|
|
1185
|
+
const contractFunction = contract[normalizedFunctionName];
|
|
1186
|
+
if (!contractFunction) logWarn(`"${normalizedFunctionName}" is not in the interface for contract "${address}"`);
|
|
1187
|
+
const callData = contract.interface.encodeFunctionData(normalizedFunctionName, params);
|
|
755
1188
|
return {
|
|
756
|
-
target:
|
|
1189
|
+
target: address,
|
|
757
1190
|
allowFailure,
|
|
758
1191
|
callData
|
|
759
1192
|
};
|
|
760
1193
|
} catch (err) {
|
|
761
1194
|
if (!allowFailure) throw err;
|
|
762
1195
|
return {
|
|
763
|
-
target:
|
|
1196
|
+
target: address,
|
|
764
1197
|
allowFailure,
|
|
765
1198
|
callData: '0x'
|
|
766
1199
|
};
|
|
767
1200
|
}
|
|
768
1201
|
});
|
|
769
1202
|
const params = [...[calls], ...(overrides ? [overrides] : [])];
|
|
770
|
-
const results = await multicallContract.aggregate3(
|
|
1203
|
+
const results = await multicallContract.aggregate3( // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1204
|
+
// @ts-ignore
|
|
1205
|
+
...params);
|
|
771
1206
|
return results.map((_ref3, i) => {
|
|
772
1207
|
let {
|
|
773
1208
|
returnData,
|
|
774
1209
|
success
|
|
775
1210
|
} = _ref3;
|
|
776
1211
|
const {
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
1212
|
+
address,
|
|
1213
|
+
abi,
|
|
1214
|
+
args,
|
|
1215
|
+
functionName
|
|
781
1216
|
} = contracts[i];
|
|
782
1217
|
const contract = getContract({
|
|
783
|
-
|
|
784
|
-
|
|
1218
|
+
address,
|
|
1219
|
+
abi: abi // TODO: Remove cast and still support `Narrow<TAbi>`
|
|
1220
|
+
|
|
1221
|
+
});
|
|
1222
|
+
const normalizedFunctionName = normalizeFunctionName({
|
|
1223
|
+
contract,
|
|
1224
|
+
functionName,
|
|
1225
|
+
args
|
|
785
1226
|
});
|
|
786
1227
|
|
|
787
1228
|
if (!success) {
|
|
788
1229
|
let error;
|
|
789
1230
|
|
|
790
1231
|
try {
|
|
791
|
-
contract.interface.decodeFunctionResult(
|
|
1232
|
+
contract.interface.decodeFunctionResult(normalizedFunctionName, returnData);
|
|
792
1233
|
} catch (err) {
|
|
793
1234
|
error = new ContractMethodRevertedError({
|
|
794
|
-
|
|
1235
|
+
address,
|
|
795
1236
|
args,
|
|
796
1237
|
chainId: chain.id,
|
|
797
|
-
functionName,
|
|
1238
|
+
functionName: normalizedFunctionName,
|
|
798
1239
|
errorMessage: err.message
|
|
799
1240
|
});
|
|
800
1241
|
if (!allowFailure) throw error;
|
|
@@ -806,10 +1247,10 @@ async function multicall(_ref) {
|
|
|
806
1247
|
|
|
807
1248
|
if (returnData === '0x') {
|
|
808
1249
|
const error = new ContractMethodNoResultError({
|
|
809
|
-
|
|
1250
|
+
address,
|
|
810
1251
|
args,
|
|
811
1252
|
chainId: chain.id,
|
|
812
|
-
functionName
|
|
1253
|
+
functionName: normalizedFunctionName
|
|
813
1254
|
});
|
|
814
1255
|
if (!allowFailure) throw error;
|
|
815
1256
|
logWarn(error.message);
|
|
@@ -817,14 +1258,14 @@ async function multicall(_ref) {
|
|
|
817
1258
|
}
|
|
818
1259
|
|
|
819
1260
|
try {
|
|
820
|
-
const result = contract.interface.decodeFunctionResult(
|
|
1261
|
+
const result = contract.interface.decodeFunctionResult(normalizedFunctionName, returnData);
|
|
821
1262
|
return Array.isArray(result) && result.length === 1 ? result[0] : result;
|
|
822
1263
|
} catch (err) {
|
|
823
1264
|
const error = new ContractResultDecodeError({
|
|
824
|
-
|
|
1265
|
+
address,
|
|
825
1266
|
args,
|
|
826
1267
|
chainId: chain.id,
|
|
827
|
-
functionName,
|
|
1268
|
+
functionName: normalizedFunctionName,
|
|
828
1269
|
errorMessage: err.message
|
|
829
1270
|
});
|
|
830
1271
|
if (!allowFailure) throw error;
|
|
@@ -834,6 +1275,38 @@ async function multicall(_ref) {
|
|
|
834
1275
|
});
|
|
835
1276
|
}
|
|
836
1277
|
|
|
1278
|
+
async function readContract(_ref) {
|
|
1279
|
+
let {
|
|
1280
|
+
address,
|
|
1281
|
+
args,
|
|
1282
|
+
chainId,
|
|
1283
|
+
abi,
|
|
1284
|
+
functionName,
|
|
1285
|
+
overrides
|
|
1286
|
+
} = _ref;
|
|
1287
|
+
const provider = getProvider({
|
|
1288
|
+
chainId
|
|
1289
|
+
});
|
|
1290
|
+
const contract = getContract({
|
|
1291
|
+
address,
|
|
1292
|
+
abi: abi,
|
|
1293
|
+
// TODO: Remove cast and still support `Narrow<TAbi>`
|
|
1294
|
+
signerOrProvider: provider
|
|
1295
|
+
});
|
|
1296
|
+
const normalizedFunctionName = normalizeFunctionName({
|
|
1297
|
+
contract,
|
|
1298
|
+
functionName,
|
|
1299
|
+
args
|
|
1300
|
+
});
|
|
1301
|
+
const contractFunction = contract[normalizedFunctionName];
|
|
1302
|
+
if (!contractFunction) throw new ContractMethodDoesNotExistError({
|
|
1303
|
+
address,
|
|
1304
|
+
functionName: normalizedFunctionName
|
|
1305
|
+
});
|
|
1306
|
+
const params = [...(args ?? []), ...(overrides ? [overrides] : [])];
|
|
1307
|
+
return contractFunction === null || contractFunction === void 0 ? void 0 : contractFunction(...params);
|
|
1308
|
+
}
|
|
1309
|
+
|
|
837
1310
|
async function readContracts(_ref) {
|
|
838
1311
|
let {
|
|
839
1312
|
allowFailure = true,
|
|
@@ -843,12 +1316,13 @@ async function readContracts(_ref) {
|
|
|
843
1316
|
|
|
844
1317
|
try {
|
|
845
1318
|
const provider = getProvider();
|
|
846
|
-
const contractsByChainId = contracts.reduce((contracts, contract) => {
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
const chainId = (_contract$chainId = contract.chainId) !== null && _contract$chainId !== void 0 ? _contract$chainId : provider.network.chainId;
|
|
1319
|
+
const contractsByChainId = contracts.reduce((contracts, contract, index) => {
|
|
1320
|
+
const chainId = contract.chainId ?? provider.network.chainId;
|
|
850
1321
|
return { ...contracts,
|
|
851
|
-
[chainId]: [...(contracts[chainId] || []),
|
|
1322
|
+
[chainId]: [...(contracts[chainId] || []), {
|
|
1323
|
+
contract,
|
|
1324
|
+
index
|
|
1325
|
+
}]
|
|
852
1326
|
};
|
|
853
1327
|
}, {});
|
|
854
1328
|
|
|
@@ -857,13 +1331,20 @@ async function readContracts(_ref) {
|
|
|
857
1331
|
return multicall({
|
|
858
1332
|
allowFailure,
|
|
859
1333
|
chainId: parseInt(chainId),
|
|
860
|
-
contracts
|
|
1334
|
+
contracts: contracts.map(_ref3 => {
|
|
1335
|
+
let {
|
|
1336
|
+
contract
|
|
1337
|
+
} = _ref3;
|
|
1338
|
+
return contract;
|
|
1339
|
+
}),
|
|
861
1340
|
overrides
|
|
862
1341
|
});
|
|
863
1342
|
});
|
|
864
1343
|
|
|
1344
|
+
let results;
|
|
1345
|
+
|
|
865
1346
|
if (allowFailure) {
|
|
866
|
-
|
|
1347
|
+
results = (await Promise.allSettled(promises())).map(result => {
|
|
867
1348
|
if (result.status === 'fulfilled') return result.value;
|
|
868
1349
|
|
|
869
1350
|
if (result.reason instanceof ChainDoesNotSupportMulticallError) {
|
|
@@ -873,9 +1354,22 @@ async function readContracts(_ref) {
|
|
|
873
1354
|
|
|
874
1355
|
return null;
|
|
875
1356
|
}).flat();
|
|
876
|
-
}
|
|
1357
|
+
} else {
|
|
1358
|
+
results = (await Promise.all(promises())).flat();
|
|
1359
|
+
} // Reorder the contract results back to the order they were
|
|
1360
|
+
// provided in.
|
|
877
1361
|
|
|
878
|
-
|
|
1362
|
+
|
|
1363
|
+
const resultIndexes = Object.values(contractsByChainId).map(contracts => contracts.map(_ref4 => {
|
|
1364
|
+
let {
|
|
1365
|
+
index
|
|
1366
|
+
} = _ref4;
|
|
1367
|
+
return index;
|
|
1368
|
+
})).flat();
|
|
1369
|
+
return results.reduce((results, result, index) => {
|
|
1370
|
+
results[resultIndexes[index]] = result;
|
|
1371
|
+
return results;
|
|
1372
|
+
}, []);
|
|
879
1373
|
} catch (err) {
|
|
880
1374
|
if (err instanceof ContractResultDecodeError) throw err;
|
|
881
1375
|
if (err instanceof ContractMethodNoResultError) throw err;
|
|
@@ -885,67 +1379,68 @@ async function readContracts(_ref) {
|
|
|
885
1379
|
overrides
|
|
886
1380
|
}));
|
|
887
1381
|
|
|
888
|
-
if (allowFailure) {
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
errorMessage: result.reason
|
|
903
|
-
});
|
|
904
|
-
logWarn(error.message);
|
|
905
|
-
return null;
|
|
1382
|
+
if (allowFailure) return (await Promise.allSettled(promises())).map((result, i) => {
|
|
1383
|
+
if (result.status === 'fulfilled') return result.value;
|
|
1384
|
+
const {
|
|
1385
|
+
address,
|
|
1386
|
+
args,
|
|
1387
|
+
chainId,
|
|
1388
|
+
functionName
|
|
1389
|
+
} = contracts[i];
|
|
1390
|
+
const error = new ContractMethodRevertedError({
|
|
1391
|
+
address,
|
|
1392
|
+
functionName,
|
|
1393
|
+
chainId: chainId ?? mainnet.id,
|
|
1394
|
+
args,
|
|
1395
|
+
errorMessage: result.reason
|
|
906
1396
|
});
|
|
907
|
-
|
|
908
|
-
|
|
1397
|
+
logWarn(error.message);
|
|
1398
|
+
return null;
|
|
1399
|
+
});
|
|
909
1400
|
return await Promise.all(promises());
|
|
910
1401
|
}
|
|
911
1402
|
}
|
|
912
1403
|
|
|
913
|
-
function watchContractEvent(
|
|
914
|
-
/** Contract configuration */
|
|
915
|
-
contractArgs,
|
|
916
|
-
/** Event name to listen to */
|
|
917
|
-
eventName, callback) {
|
|
1404
|
+
function watchContractEvent(_ref, callback) {
|
|
918
1405
|
let {
|
|
1406
|
+
address,
|
|
1407
|
+
abi,
|
|
919
1408
|
chainId,
|
|
1409
|
+
eventName,
|
|
920
1410
|
once
|
|
921
|
-
} =
|
|
1411
|
+
} = _ref;
|
|
1412
|
+
|
|
1413
|
+
const handler = function () {
|
|
1414
|
+
return callback(...arguments);
|
|
1415
|
+
};
|
|
1416
|
+
|
|
922
1417
|
let contract;
|
|
923
1418
|
|
|
924
1419
|
const watchEvent = async () => {
|
|
925
|
-
|
|
926
|
-
var _contract;
|
|
927
|
-
|
|
928
|
-
(_contract = contract) === null || _contract === void 0 ? void 0 : _contract.off(eventName, callback);
|
|
929
|
-
}
|
|
1420
|
+
var _contract;
|
|
930
1421
|
|
|
1422
|
+
if (contract) (_contract = contract) === null || _contract === void 0 ? void 0 : _contract.off(eventName, handler);
|
|
1423
|
+
const signerOrProvider = getWebSocketProvider({
|
|
1424
|
+
chainId
|
|
1425
|
+
}) || getProvider({
|
|
1426
|
+
chainId
|
|
1427
|
+
});
|
|
931
1428
|
contract = getContract({
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
}),
|
|
937
|
-
...contractArgs
|
|
1429
|
+
address,
|
|
1430
|
+
abi: abi,
|
|
1431
|
+
// TODO: Remove cast and still support `Narrow<TAbi>`
|
|
1432
|
+
signerOrProvider
|
|
938
1433
|
});
|
|
939
|
-
if (once) contract.once(eventName,
|
|
1434
|
+
if (once) contract.once(eventName, handler);else contract.on(eventName, handler);
|
|
940
1435
|
};
|
|
941
1436
|
|
|
942
1437
|
watchEvent();
|
|
943
1438
|
const client = getClient();
|
|
944
|
-
const unsubscribe = client.subscribe(
|
|
1439
|
+
const unsubscribe = client.subscribe(_ref2 => {
|
|
945
1440
|
let {
|
|
946
1441
|
provider,
|
|
947
1442
|
webSocketProvider
|
|
948
|
-
} =
|
|
1443
|
+
} = _ref2;
|
|
949
1444
|
return {
|
|
950
1445
|
provider,
|
|
951
1446
|
webSocketProvider
|
|
@@ -956,7 +1451,7 @@ eventName, callback) {
|
|
|
956
1451
|
return () => {
|
|
957
1452
|
var _contract2;
|
|
958
1453
|
|
|
959
|
-
(_contract2 = contract) === null || _contract2 === void 0 ? void 0 : _contract2.off(eventName,
|
|
1454
|
+
(_contract2 = contract) === null || _contract2 === void 0 ? void 0 : _contract2.off(eventName, handler);
|
|
960
1455
|
unsubscribe();
|
|
961
1456
|
};
|
|
962
1457
|
}
|
|
@@ -973,8 +1468,6 @@ async function fetchBlockNumber() {
|
|
|
973
1468
|
}
|
|
974
1469
|
|
|
975
1470
|
function watchBlockNumber(args, callback) {
|
|
976
|
-
var _getWebSocketProvider;
|
|
977
|
-
|
|
978
1471
|
// We need to debounce the listener as we want to opt-out
|
|
979
1472
|
// of the behavior where ethers emits a "block" event for
|
|
980
1473
|
// every block that was missed in between the `pollingInterval`.
|
|
@@ -994,9 +1487,9 @@ function watchBlockNumber(args, callback) {
|
|
|
994
1487
|
previousProvider = provider;
|
|
995
1488
|
};
|
|
996
1489
|
|
|
997
|
-
const provider_ =
|
|
1490
|
+
const provider_ = getWebSocketProvider({
|
|
998
1491
|
chainId: args.chainId
|
|
999
|
-
})
|
|
1492
|
+
}) ?? getProvider({
|
|
1000
1493
|
chainId: args.chainId
|
|
1001
1494
|
});
|
|
1002
1495
|
if (args.listen) createListener(provider_);
|
|
@@ -1016,7 +1509,7 @@ function watchBlockNumber(args, callback) {
|
|
|
1016
1509
|
provider,
|
|
1017
1510
|
webSocketProvider
|
|
1018
1511
|
} = _ref2;
|
|
1019
|
-
const provider_ = webSocketProvider
|
|
1512
|
+
const provider_ = webSocketProvider ?? provider;
|
|
1020
1513
|
|
|
1021
1514
|
if (args.listen && !args.chainId && provider_) {
|
|
1022
1515
|
createListener(provider_);
|
|
@@ -1040,10 +1533,10 @@ function watchBlockNumber(args, callback) {
|
|
|
1040
1533
|
};
|
|
1041
1534
|
}
|
|
1042
1535
|
|
|
1043
|
-
function
|
|
1536
|
+
function watchMulticall(config, callback) {
|
|
1044
1537
|
const client = getClient();
|
|
1045
1538
|
|
|
1046
|
-
const handleChange = async () => callback(await
|
|
1539
|
+
const handleChange = async () => callback(await multicall(config));
|
|
1047
1540
|
|
|
1048
1541
|
const unwatch = config.listenToBlock ? watchBlockNumber({
|
|
1049
1542
|
listen: true
|
|
@@ -1060,10 +1553,10 @@ function watchReadContract(config, callback) {
|
|
|
1060
1553
|
};
|
|
1061
1554
|
}
|
|
1062
1555
|
|
|
1063
|
-
function
|
|
1556
|
+
function watchReadContract(config, callback) {
|
|
1064
1557
|
const client = getClient();
|
|
1065
1558
|
|
|
1066
|
-
const handleChange = async () => callback(await
|
|
1559
|
+
const handleChange = async () => callback(await readContract(config));
|
|
1067
1560
|
|
|
1068
1561
|
const unwatch = config.listenToBlock ? watchBlockNumber({
|
|
1069
1562
|
listen: true
|
|
@@ -1080,42 +1573,24 @@ function watchReadContracts(config, callback) {
|
|
|
1080
1573
|
};
|
|
1081
1574
|
}
|
|
1082
1575
|
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
chainId,
|
|
1086
|
-
request
|
|
1087
|
-
} = _ref;
|
|
1088
|
-
const {
|
|
1089
|
-
connector
|
|
1090
|
-
} = getClient();
|
|
1091
|
-
if (!connector) throw new ConnectorNotFoundError();
|
|
1092
|
-
|
|
1093
|
-
try {
|
|
1094
|
-
var _chain;
|
|
1095
|
-
|
|
1096
|
-
let chain;
|
|
1097
|
-
|
|
1098
|
-
if (chainId) {
|
|
1099
|
-
const activeChainId = await connector.getChainId(); // Try to switch chain to provided `chainId`
|
|
1100
|
-
|
|
1101
|
-
if (chainId !== activeChainId) {
|
|
1102
|
-
var _connector$chains$fin, _connector$chains$fin2, _connector$chains$fin3, _connector$chains$fin4;
|
|
1576
|
+
function watchReadContracts(config, callback) {
|
|
1577
|
+
const client = getClient();
|
|
1103
1578
|
|
|
1104
|
-
|
|
1105
|
-
activeChain: (_connector$chains$fin = (_connector$chains$fin2 = connector.chains.find(x => x.id === activeChainId)) === null || _connector$chains$fin2 === void 0 ? void 0 : _connector$chains$fin2.name) !== null && _connector$chains$fin !== void 0 ? _connector$chains$fin : "Chain ".concat(activeChainId),
|
|
1106
|
-
targetChain: (_connector$chains$fin3 = (_connector$chains$fin4 = connector.chains.find(x => x.id === chainId)) === null || _connector$chains$fin4 === void 0 ? void 0 : _connector$chains$fin4.name) !== null && _connector$chains$fin3 !== void 0 ? _connector$chains$fin3 : "Chain ".concat(chainId)
|
|
1107
|
-
});
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1579
|
+
const handleChange = async () => callback(await readContracts(config));
|
|
1110
1580
|
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1581
|
+
const unwatch = config.listenToBlock ? watchBlockNumber({
|
|
1582
|
+
listen: true
|
|
1583
|
+
}, handleChange) : undefined;
|
|
1584
|
+
const unsubscribe = client.subscribe(_ref => {
|
|
1585
|
+
let {
|
|
1586
|
+
provider
|
|
1587
|
+
} = _ref;
|
|
1588
|
+
return provider;
|
|
1589
|
+
}, handleChange);
|
|
1590
|
+
return () => {
|
|
1591
|
+
unsubscribe();
|
|
1592
|
+
unwatch === null || unwatch === void 0 ? void 0 : unwatch();
|
|
1593
|
+
};
|
|
1119
1594
|
}
|
|
1120
1595
|
|
|
1121
1596
|
/**
|
|
@@ -1214,13 +1689,18 @@ async function prepareSendTransaction(_ref) {
|
|
|
1214
1689
|
let {
|
|
1215
1690
|
chainId,
|
|
1216
1691
|
request,
|
|
1217
|
-
|
|
1218
|
-
chainId
|
|
1219
|
-
})
|
|
1692
|
+
signer: signer_
|
|
1220
1693
|
} = _ref;
|
|
1694
|
+
const signer = signer_ ?? (await fetchSigner({
|
|
1695
|
+
chainId
|
|
1696
|
+
}));
|
|
1697
|
+
if (!signer) throw new ConnectorNotFoundError();
|
|
1698
|
+
if (chainId) assertActiveChain({
|
|
1699
|
+
chainId
|
|
1700
|
+
});
|
|
1221
1701
|
const [to, gasLimit] = await Promise.all([isAddress(request.to) ? Promise.resolve(request.to) : fetchEnsAddress({
|
|
1222
1702
|
name: request.to
|
|
1223
|
-
}), request.gasLimit ? Promise.resolve(request.gasLimit) :
|
|
1703
|
+
}), request.gasLimit ? Promise.resolve(request.gasLimit) : signer.estimateGas(request)]);
|
|
1224
1704
|
if (!to) throw new Error('Could not resolve ENS name');
|
|
1225
1705
|
return { ...(chainId ? {
|
|
1226
1706
|
chainId
|
|
@@ -1275,20 +1755,9 @@ async function sendTransaction(_ref) {
|
|
|
1275
1755
|
if (!request.to) throw new Error('`to` is required');
|
|
1276
1756
|
}
|
|
1277
1757
|
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
} = getNetwork();
|
|
1282
|
-
const activeChainId = activeChain === null || activeChain === void 0 ? void 0 : activeChain.id;
|
|
1283
|
-
|
|
1284
|
-
if (chainId && chainId !== (activeChain === null || activeChain === void 0 ? void 0 : activeChain.id)) {
|
|
1285
|
-
var _chains$find$name, _chains$find, _chains$find$name2, _chains$find2;
|
|
1286
|
-
|
|
1287
|
-
throw new ChainMismatchError({
|
|
1288
|
-
activeChain: (_chains$find$name = (_chains$find = chains.find(x => x.id === activeChainId)) === null || _chains$find === void 0 ? void 0 : _chains$find.name) !== null && _chains$find$name !== void 0 ? _chains$find$name : "Chain ".concat(activeChainId),
|
|
1289
|
-
targetChain: (_chains$find$name2 = (_chains$find2 = chains.find(x => x.id === chainId)) === null || _chains$find2 === void 0 ? void 0 : _chains$find2.name) !== null && _chains$find$name2 !== void 0 ? _chains$find$name2 : "Chain ".concat(chainId)
|
|
1290
|
-
});
|
|
1291
|
-
}
|
|
1758
|
+
if (chainId) assertActiveChain({
|
|
1759
|
+
chainId
|
|
1760
|
+
});
|
|
1292
1761
|
|
|
1293
1762
|
try {
|
|
1294
1763
|
var _connectUnchecked, _ref2;
|
|
@@ -1304,7 +1773,7 @@ async function sendTransaction(_ref) {
|
|
|
1304
1773
|
const {
|
|
1305
1774
|
hash,
|
|
1306
1775
|
wait
|
|
1307
|
-
} = await (uncheckedSigner
|
|
1776
|
+
} = await (uncheckedSigner ?? signer).sendTransaction(request);
|
|
1308
1777
|
/********************************************************************/
|
|
1309
1778
|
|
|
1310
1779
|
/** END: iOS App Link cautious code. */
|
|
@@ -1314,7 +1783,7 @@ async function sendTransaction(_ref) {
|
|
|
1314
1783
|
/********************************************************************/
|
|
1315
1784
|
|
|
1316
1785
|
return {
|
|
1317
|
-
hash,
|
|
1786
|
+
hash: hash,
|
|
1318
1787
|
wait
|
|
1319
1788
|
};
|
|
1320
1789
|
} catch (error) {
|
|
@@ -1353,58 +1822,45 @@ async function waitForTransaction(_ref) {
|
|
|
1353
1822
|
* import { prepareWriteContract, writeContract } from '@wagmi/core'
|
|
1354
1823
|
*
|
|
1355
1824
|
* const config = await prepareWriteContract({
|
|
1356
|
-
*
|
|
1357
|
-
*
|
|
1825
|
+
* address: '0x...',
|
|
1826
|
+
* abi: wagmiAbi,
|
|
1358
1827
|
* functionName: 'mint',
|
|
1359
1828
|
* })
|
|
1360
1829
|
* const result = await writeContract(config)
|
|
1361
1830
|
*/
|
|
1362
1831
|
async function writeContract(_ref) {
|
|
1363
1832
|
let {
|
|
1364
|
-
|
|
1833
|
+
address,
|
|
1365
1834
|
args,
|
|
1366
1835
|
chainId,
|
|
1367
|
-
|
|
1836
|
+
abi,
|
|
1368
1837
|
functionName,
|
|
1369
1838
|
mode,
|
|
1370
1839
|
overrides,
|
|
1371
1840
|
request: request_
|
|
1372
1841
|
} = _ref;
|
|
1373
1842
|
|
|
1374
|
-
|
|
1843
|
+
/****************************************************************************/
|
|
1375
1844
|
|
|
1376
|
-
/** START: iOS App Link cautious code.
|
|
1845
|
+
/** START: iOS App Link cautious code. */
|
|
1377
1846
|
|
|
1378
|
-
/** Do not perform any async operations in this block.
|
|
1847
|
+
/** Do not perform any async operations in this block. */
|
|
1379
1848
|
|
|
1380
|
-
/** Ref: wagmi.sh/docs/prepare-hooks/intro#ios-app-link-constraints */
|
|
1849
|
+
/** Ref: https://wagmi.sh/docs/prepare-hooks/intro#ios-app-link-constraints */
|
|
1381
1850
|
|
|
1382
|
-
|
|
1851
|
+
/****************************************************************************/
|
|
1383
1852
|
const signer = await fetchSigner();
|
|
1384
1853
|
if (!signer) throw new ConnectorNotFoundError();
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
const activeChainId = activeChain === null || activeChain === void 0 ? void 0 : activeChain.id;
|
|
1390
|
-
|
|
1391
|
-
if (chainId && chainId !== activeChainId) {
|
|
1392
|
-
var _chains$find$name, _chains$find, _chains$find$name2, _chains$find2;
|
|
1393
|
-
|
|
1394
|
-
throw new ChainMismatchError({
|
|
1395
|
-
activeChain: (_chains$find$name = (_chains$find = chains.find(x => x.id === activeChainId)) === null || _chains$find === void 0 ? void 0 : _chains$find.name) !== null && _chains$find$name !== void 0 ? _chains$find$name : "Chain ".concat(activeChainId),
|
|
1396
|
-
targetChain: (_chains$find$name2 = (_chains$find2 = chains.find(x => x.id === chainId)) === null || _chains$find2 === void 0 ? void 0 : _chains$find2.name) !== null && _chains$find$name2 !== void 0 ? _chains$find$name2 : "Chain ".concat(chainId)
|
|
1397
|
-
});
|
|
1398
|
-
}
|
|
1399
|
-
|
|
1400
|
-
if (mode === 'prepared') {
|
|
1401
|
-
if (!request_) throw new Error('`request` is required');
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1854
|
+
if (chainId) assertActiveChain({
|
|
1855
|
+
chainId
|
|
1856
|
+
});
|
|
1857
|
+
if (mode === 'prepared') if (!request_) throw new Error('`request` is required');
|
|
1404
1858
|
const request = mode === 'recklesslyUnprepared' ? (await prepareWriteContract({
|
|
1405
|
-
|
|
1859
|
+
address,
|
|
1406
1860
|
args,
|
|
1407
|
-
|
|
1861
|
+
chainId,
|
|
1862
|
+
abi: abi,
|
|
1863
|
+
// TODO: Remove cast and still support `Narrow<TAbi>`
|
|
1408
1864
|
functionName,
|
|
1409
1865
|
overrides
|
|
1410
1866
|
})).request : request_;
|
|
@@ -1424,7 +1880,7 @@ async function writeContract(_ref) {
|
|
|
1424
1880
|
}
|
|
1425
1881
|
|
|
1426
1882
|
async function fetchBalance(_ref) {
|
|
1427
|
-
var
|
|
1883
|
+
var _chain$nativeCurrency, _chain$nativeCurrency2;
|
|
1428
1884
|
|
|
1429
1885
|
let {
|
|
1430
1886
|
addressOrName,
|
|
@@ -1444,25 +1900,25 @@ async function fetchBalance(_ref) {
|
|
|
1444
1900
|
const address = await provider.resolveName(addressOrName); // Same error `provider.getBalance` throws for invalid ENS name
|
|
1445
1901
|
|
|
1446
1902
|
if (!address) logger.throwError('ENS name not configured', Logger.errors.UNSUPPORTED_OPERATION, {
|
|
1447
|
-
operation:
|
|
1903
|
+
operation: `resolveName(${JSON.stringify(addressOrName)})`
|
|
1448
1904
|
});
|
|
1449
1905
|
resolvedAddress = address;
|
|
1450
1906
|
}
|
|
1451
1907
|
|
|
1452
1908
|
const fetchContractBalance = async _ref2 => {
|
|
1453
1909
|
let {
|
|
1454
|
-
|
|
1910
|
+
abi
|
|
1455
1911
|
} = _ref2;
|
|
1456
1912
|
const erc20Config = {
|
|
1457
|
-
|
|
1458
|
-
|
|
1913
|
+
abi,
|
|
1914
|
+
address: token,
|
|
1459
1915
|
chainId
|
|
1460
1916
|
};
|
|
1461
1917
|
const [value, decimals, symbol] = await readContracts({
|
|
1462
1918
|
allowFailure: false,
|
|
1463
1919
|
contracts: [{ ...erc20Config,
|
|
1464
1920
|
functionName: 'balanceOf',
|
|
1465
|
-
args: resolvedAddress
|
|
1921
|
+
args: [resolvedAddress]
|
|
1466
1922
|
}, { ...erc20Config,
|
|
1467
1923
|
functionName: 'decimals'
|
|
1468
1924
|
}, { ...erc20Config,
|
|
@@ -1471,15 +1927,16 @@ async function fetchBalance(_ref) {
|
|
|
1471
1927
|
});
|
|
1472
1928
|
return {
|
|
1473
1929
|
decimals,
|
|
1474
|
-
formatted: formatUnits(value
|
|
1475
|
-
symbol,
|
|
1930
|
+
formatted: formatUnits(value ?? '0', unit ?? decimals),
|
|
1931
|
+
symbol: symbol,
|
|
1932
|
+
// protect against `ResolvedConfig['BytesType']`
|
|
1476
1933
|
value
|
|
1477
1934
|
};
|
|
1478
1935
|
};
|
|
1479
1936
|
|
|
1480
1937
|
try {
|
|
1481
1938
|
return await fetchContractBalance({
|
|
1482
|
-
|
|
1939
|
+
abi: erc20ABI
|
|
1483
1940
|
});
|
|
1484
1941
|
} catch (err) {
|
|
1485
1942
|
// In the chance that there is an error upon decoding the contract result,
|
|
@@ -1490,7 +1947,7 @@ async function fetchBalance(_ref) {
|
|
|
1490
1947
|
symbol,
|
|
1491
1948
|
...rest
|
|
1492
1949
|
} = await fetchContractBalance({
|
|
1493
|
-
|
|
1950
|
+
abi: erc20ABI_bytes32
|
|
1494
1951
|
});
|
|
1495
1952
|
return {
|
|
1496
1953
|
symbol: parseBytes32String(symbol),
|
|
@@ -1502,13 +1959,13 @@ async function fetchBalance(_ref) {
|
|
|
1502
1959
|
}
|
|
1503
1960
|
}
|
|
1504
1961
|
|
|
1505
|
-
const chains = [...(client.provider.chains || []), ...(
|
|
1962
|
+
const chains = [...(client.provider.chains || []), ...(client.chains ?? [])];
|
|
1506
1963
|
const value = await provider.getBalance(addressOrName);
|
|
1507
1964
|
const chain = chains.find(x => x.id === provider.network.chainId);
|
|
1508
1965
|
return {
|
|
1509
|
-
decimals: (
|
|
1510
|
-
formatted: formatUnits(value
|
|
1511
|
-
symbol: (
|
|
1966
|
+
decimals: (chain === null || chain === void 0 ? void 0 : (_chain$nativeCurrency = chain.nativeCurrency) === null || _chain$nativeCurrency === void 0 ? void 0 : _chain$nativeCurrency.decimals) ?? 18,
|
|
1967
|
+
formatted: formatUnits(value ?? '0', unit ?? 'ether'),
|
|
1968
|
+
symbol: (chain === null || chain === void 0 ? void 0 : (_chain$nativeCurrency2 = chain.nativeCurrency) === null || _chain$nativeCurrency2 === void 0 ? void 0 : _chain$nativeCurrency2.symbol) ?? 'ETH',
|
|
1512
1969
|
value
|
|
1513
1970
|
};
|
|
1514
1971
|
}
|
|
@@ -1516,8 +1973,13 @@ async function fetchBalance(_ref) {
|
|
|
1516
1973
|
async function fetchSigner() {
|
|
1517
1974
|
var _client$connector, _client$connector$get;
|
|
1518
1975
|
|
|
1976
|
+
let {
|
|
1977
|
+
chainId
|
|
1978
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1519
1979
|
const client = getClient();
|
|
1520
|
-
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
|
|
1980
|
+
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, {
|
|
1981
|
+
chainId
|
|
1982
|
+
}))) || null;
|
|
1521
1983
|
return signer;
|
|
1522
1984
|
}
|
|
1523
1985
|
|
|
@@ -1576,15 +2038,15 @@ function getAccount() {
|
|
|
1576
2038
|
}
|
|
1577
2039
|
|
|
1578
2040
|
function getNetwork() {
|
|
1579
|
-
var _client$data, _client$data$chain, _client$
|
|
2041
|
+
var _client$data, _client$data$chain, _client$data2;
|
|
1580
2042
|
|
|
1581
2043
|
const client = getClient();
|
|
1582
2044
|
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;
|
|
1583
|
-
const activeChains =
|
|
1584
|
-
const activeChain =
|
|
2045
|
+
const activeChains = client.chains ?? [];
|
|
2046
|
+
const activeChain = [...(client.provider.chains || []), ...activeChains].find(x => x.id === chainId) ?? {
|
|
1585
2047
|
id: chainId,
|
|
1586
|
-
name:
|
|
1587
|
-
network:
|
|
2048
|
+
name: `Chain ${chainId}`,
|
|
2049
|
+
network: `${chainId}`,
|
|
1588
2050
|
rpcUrls: {
|
|
1589
2051
|
default: ''
|
|
1590
2052
|
}
|
|
@@ -1617,28 +2079,13 @@ async function signTypedData(_ref) {
|
|
|
1617
2079
|
} = _ref;
|
|
1618
2080
|
const signer = await fetchSigner();
|
|
1619
2081
|
if (!signer) throw new ConnectorNotFoundError();
|
|
1620
|
-
const {
|
|
1621
|
-
chain: activeChain,
|
|
1622
|
-
chains
|
|
1623
|
-
} = getNetwork();
|
|
1624
2082
|
const {
|
|
1625
2083
|
chainId: chainId_
|
|
1626
2084
|
} = domain;
|
|
1627
|
-
|
|
1628
|
-
if (
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
if (chainId !== (activeChain === null || activeChain === void 0 ? void 0 : activeChain.id)) {
|
|
1633
|
-
var _chains$find$name, _chains$find, _chains$find$name2, _chains$find2;
|
|
1634
|
-
|
|
1635
|
-
throw new ChainMismatchError({
|
|
1636
|
-
activeChain: (_chains$find$name = (_chains$find = chains.find(x => x.id === activeChainId)) === null || _chains$find === void 0 ? void 0 : _chains$find.name) !== null && _chains$find$name !== void 0 ? _chains$find$name : "Chain ".concat(activeChainId),
|
|
1637
|
-
targetChain: (_chains$find$name2 = (_chains$find2 = chains.find(x => x.id === chainId)) === null || _chains$find2 === void 0 ? void 0 : _chains$find2.name) !== null && _chains$find$name2 !== void 0 ? _chains$find$name2 : "Chain ".concat(chainId)
|
|
1638
|
-
});
|
|
1639
|
-
}
|
|
1640
|
-
} // Method name may be changed in the future, see https://docs.ethers.io/v5/api/signer/#Signer-signTypedData
|
|
1641
|
-
|
|
2085
|
+
const chainId = chainId_ ? normalizeChainId(chainId_) : undefined;
|
|
2086
|
+
if (chainId) assertActiveChain({
|
|
2087
|
+
chainId
|
|
2088
|
+
}); // Method name may be changed in the future, see https://docs.ethers.io/v5/api/signer/#Signer-signTypedData
|
|
1642
2089
|
|
|
1643
2090
|
return await signer._signTypedData(domain, types, value);
|
|
1644
2091
|
}
|
|
@@ -1707,18 +2154,23 @@ function watchNetwork(callback) {
|
|
|
1707
2154
|
return unsubscribe;
|
|
1708
2155
|
}
|
|
1709
2156
|
|
|
1710
|
-
function watchSigner(callback) {
|
|
2157
|
+
function watchSigner(_ref, callback) {
|
|
2158
|
+
let {
|
|
2159
|
+
chainId
|
|
2160
|
+
} = _ref;
|
|
1711
2161
|
const client = getClient();
|
|
1712
2162
|
|
|
1713
|
-
const handleChange = async () => callback(await fetchSigner(
|
|
2163
|
+
const handleChange = async () => callback(await fetchSigner({
|
|
2164
|
+
chainId
|
|
2165
|
+
}));
|
|
1714
2166
|
|
|
1715
|
-
const unsubscribe = client.subscribe(
|
|
2167
|
+
const unsubscribe = client.subscribe(_ref2 => {
|
|
1716
2168
|
var _data$chain;
|
|
1717
2169
|
|
|
1718
2170
|
let {
|
|
1719
2171
|
data,
|
|
1720
2172
|
connector
|
|
1721
|
-
} =
|
|
2173
|
+
} = _ref2;
|
|
1722
2174
|
return {
|
|
1723
2175
|
account: data === null || data === void 0 ? void 0 : data.account,
|
|
1724
2176
|
chainId: data === null || data === void 0 ? void 0 : (_data$chain = data.chain) === null || _data$chain === void 0 ? void 0 : _data$chain.id,
|
|
@@ -1749,4 +2201,4 @@ async function fetchFeeData() {
|
|
|
1749
2201
|
};
|
|
1750
2202
|
}
|
|
1751
2203
|
|
|
1752
|
-
export { configureChains, connect, deepEqual,
|
|
2204
|
+
export { configureChains, connect, deepEqual, disconnect, erc20ABI, 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 };
|