@wagmi/core 0.5.7 → 0.6.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/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/network-status/watchBlockNumber.d.ts +1 -0
- 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 +6 -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 +569 -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-f1dfc7e3.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 +1096 -421
- package/dist/wagmi-core.cjs.prod.js +1096 -421
- package/dist/wagmi-core.esm.js +1098 -423
- 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,
|
|
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, 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,42 +326,572 @@ 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
|
+
}];
|
|
476
|
+
/**
|
|
477
|
+
* [bytes32-flavored ERC-20](https://docs.makerdao.com/smart-contract-modules/mkr-module#4.-gotchas-potential-source-of-user-error)
|
|
478
|
+
* for tokens (ie. Maker) that use bytes32 instead of string.
|
|
479
|
+
*/
|
|
218
480
|
|
|
219
|
-
const
|
|
481
|
+
const erc20ABI_bytes32 = [{
|
|
482
|
+
type: 'event',
|
|
483
|
+
name: 'Approval',
|
|
484
|
+
inputs: [{
|
|
485
|
+
indexed: true,
|
|
486
|
+
name: 'owner',
|
|
487
|
+
type: 'address'
|
|
488
|
+
}, {
|
|
489
|
+
indexed: true,
|
|
490
|
+
name: 'spender',
|
|
491
|
+
type: 'address'
|
|
492
|
+
}, {
|
|
493
|
+
indexed: false,
|
|
494
|
+
name: 'value',
|
|
495
|
+
type: 'uint256'
|
|
496
|
+
}]
|
|
497
|
+
}, {
|
|
498
|
+
type: 'event',
|
|
499
|
+
name: 'Transfer',
|
|
500
|
+
inputs: [{
|
|
501
|
+
indexed: true,
|
|
502
|
+
name: 'from',
|
|
503
|
+
type: 'address'
|
|
504
|
+
}, {
|
|
505
|
+
indexed: true,
|
|
506
|
+
name: 'to',
|
|
507
|
+
type: 'address'
|
|
508
|
+
}, {
|
|
509
|
+
indexed: false,
|
|
510
|
+
name: 'value',
|
|
511
|
+
type: 'uint256'
|
|
512
|
+
}]
|
|
513
|
+
}, {
|
|
514
|
+
type: 'function',
|
|
515
|
+
name: 'allowance',
|
|
516
|
+
stateMutability: 'view',
|
|
517
|
+
inputs: [{
|
|
518
|
+
name: 'owner',
|
|
519
|
+
type: 'address'
|
|
520
|
+
}, {
|
|
521
|
+
name: 'spender',
|
|
522
|
+
type: 'address'
|
|
523
|
+
}],
|
|
524
|
+
outputs: [{
|
|
525
|
+
name: '',
|
|
526
|
+
type: 'uint256'
|
|
527
|
+
}]
|
|
528
|
+
}, {
|
|
529
|
+
type: 'function',
|
|
530
|
+
name: 'approve',
|
|
531
|
+
stateMutability: 'nonpayable',
|
|
532
|
+
inputs: [{
|
|
533
|
+
name: 'spender',
|
|
534
|
+
type: 'address'
|
|
535
|
+
}, {
|
|
536
|
+
name: 'amount',
|
|
537
|
+
type: 'uint256'
|
|
538
|
+
}],
|
|
539
|
+
outputs: [{
|
|
540
|
+
name: '',
|
|
541
|
+
type: 'bool'
|
|
542
|
+
}]
|
|
543
|
+
}, {
|
|
544
|
+
type: 'function',
|
|
545
|
+
name: 'balanceOf',
|
|
546
|
+
stateMutability: 'view',
|
|
547
|
+
inputs: [{
|
|
548
|
+
name: 'account',
|
|
549
|
+
type: 'address'
|
|
550
|
+
}],
|
|
551
|
+
outputs: [{
|
|
552
|
+
name: '',
|
|
553
|
+
type: 'uint256'
|
|
554
|
+
}]
|
|
555
|
+
}, {
|
|
556
|
+
type: 'function',
|
|
557
|
+
name: 'decimals',
|
|
558
|
+
stateMutability: 'view',
|
|
559
|
+
inputs: [],
|
|
560
|
+
outputs: [{
|
|
561
|
+
name: '',
|
|
562
|
+
type: 'uint8'
|
|
563
|
+
}]
|
|
564
|
+
}, {
|
|
565
|
+
type: 'function',
|
|
566
|
+
name: 'name',
|
|
567
|
+
stateMutability: 'view',
|
|
568
|
+
inputs: [],
|
|
569
|
+
outputs: [{
|
|
570
|
+
name: '',
|
|
571
|
+
type: 'bytes32'
|
|
572
|
+
}]
|
|
573
|
+
}, {
|
|
574
|
+
type: 'function',
|
|
575
|
+
name: 'symbol',
|
|
576
|
+
stateMutability: 'view',
|
|
577
|
+
inputs: [],
|
|
578
|
+
outputs: [{
|
|
579
|
+
name: '',
|
|
580
|
+
type: 'bytes32'
|
|
581
|
+
}]
|
|
582
|
+
}, {
|
|
583
|
+
type: 'function',
|
|
584
|
+
name: 'totalSupply',
|
|
585
|
+
stateMutability: 'view',
|
|
586
|
+
inputs: [],
|
|
587
|
+
outputs: [{
|
|
588
|
+
name: '',
|
|
589
|
+
type: 'uint256'
|
|
590
|
+
}]
|
|
591
|
+
}, {
|
|
592
|
+
type: 'function',
|
|
593
|
+
name: 'transfer',
|
|
594
|
+
stateMutability: 'nonpayable',
|
|
595
|
+
inputs: [{
|
|
596
|
+
name: 'recipient',
|
|
597
|
+
type: 'address'
|
|
598
|
+
}, {
|
|
599
|
+
name: 'amount',
|
|
600
|
+
type: 'uint256'
|
|
601
|
+
}],
|
|
602
|
+
outputs: [{
|
|
603
|
+
name: '',
|
|
604
|
+
type: 'bool'
|
|
605
|
+
}]
|
|
606
|
+
}, {
|
|
607
|
+
type: 'function',
|
|
608
|
+
name: 'transferFrom',
|
|
609
|
+
stateMutability: 'nonpayable',
|
|
610
|
+
inputs: [{
|
|
611
|
+
name: 'sender',
|
|
612
|
+
type: 'address'
|
|
613
|
+
}, {
|
|
614
|
+
name: 'recipient',
|
|
615
|
+
type: 'address'
|
|
616
|
+
}, {
|
|
617
|
+
name: 'amount',
|
|
618
|
+
type: 'uint256'
|
|
619
|
+
}],
|
|
620
|
+
outputs: [{
|
|
621
|
+
name: '',
|
|
622
|
+
type: 'bool'
|
|
623
|
+
}]
|
|
624
|
+
}];
|
|
625
|
+
/**
|
|
626
|
+
* [ERC-721 Non-Fungible Token Standard](https://ethereum.org/en/developers/docs/standards/tokens/erc-721)
|
|
627
|
+
*/
|
|
220
628
|
|
|
221
|
-
const
|
|
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
|
+
*/
|
|
870
|
+
|
|
871
|
+
const multicallABI = [{
|
|
222
872
|
inputs: [{
|
|
223
873
|
components: [{
|
|
224
|
-
internalType: 'address',
|
|
225
874
|
name: 'target',
|
|
226
875
|
type: 'address'
|
|
227
876
|
}, {
|
|
228
|
-
internalType: 'bool',
|
|
229
877
|
name: 'allowFailure',
|
|
230
878
|
type: 'bool'
|
|
231
879
|
}, {
|
|
232
|
-
internalType: 'bytes',
|
|
233
880
|
name: 'callData',
|
|
234
881
|
type: 'bytes'
|
|
235
882
|
}],
|
|
236
|
-
internalType: 'struct Multicall3.Call3[]',
|
|
237
883
|
name: 'calls',
|
|
238
884
|
type: 'tuple[]'
|
|
239
885
|
}],
|
|
240
886
|
name: 'aggregate3',
|
|
241
887
|
outputs: [{
|
|
242
888
|
components: [{
|
|
243
|
-
internalType: 'bool',
|
|
244
889
|
name: 'success',
|
|
245
890
|
type: 'bool'
|
|
246
891
|
}, {
|
|
247
|
-
internalType: 'bytes',
|
|
248
892
|
name: 'returnData',
|
|
249
893
|
type: 'bytes'
|
|
250
894
|
}],
|
|
251
|
-
internalType: 'struct Multicall3.Result[]',
|
|
252
895
|
name: 'returnData',
|
|
253
896
|
type: 'tuple[]'
|
|
254
897
|
}],
|
|
@@ -304,101 +947,85 @@ async function disconnect() {
|
|
|
304
947
|
client.storage.removeItem('connected');
|
|
305
948
|
}
|
|
306
949
|
|
|
307
|
-
function
|
|
308
|
-
let {
|
|
309
|
-
addressOrName,
|
|
310
|
-
contractInterface,
|
|
311
|
-
signerOrProvider
|
|
312
|
-
} = _ref;
|
|
313
|
-
return new Contract$1(addressOrName, contractInterface, signerOrProvider);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
async function deprecatedWriteContract(_ref) {
|
|
950
|
+
async function fetchToken(_ref) {
|
|
317
951
|
let {
|
|
318
|
-
|
|
319
|
-
args,
|
|
952
|
+
address,
|
|
320
953
|
chainId,
|
|
321
|
-
|
|
322
|
-
functionName,
|
|
323
|
-
overrides,
|
|
324
|
-
signerOrProvider
|
|
954
|
+
formatUnits: units = 'ether'
|
|
325
955
|
} = _ref;
|
|
326
|
-
const {
|
|
327
|
-
connector
|
|
328
|
-
} = getClient();
|
|
329
|
-
if (!connector) throw new ConnectorNotFoundError();
|
|
330
|
-
const params = [...(Array.isArray(args) ? args : args ? [args] : []), ...(overrides ? [overrides] : [])];
|
|
331
|
-
|
|
332
|
-
try {
|
|
333
|
-
var _chain;
|
|
334
|
-
|
|
335
|
-
let chain;
|
|
336
|
-
|
|
337
|
-
if (chainId) {
|
|
338
|
-
const activeChainId = await connector.getChainId(); // Try to switch chain to provided `chainId`
|
|
339
956
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
957
|
+
async function fetchToken_(_ref2) {
|
|
958
|
+
let {
|
|
959
|
+
abi
|
|
960
|
+
} = _ref2;
|
|
961
|
+
const erc20Config = {
|
|
962
|
+
address,
|
|
963
|
+
abi,
|
|
964
|
+
chainId
|
|
965
|
+
};
|
|
966
|
+
const [decimals, name, symbol, totalSupply] = await readContracts({
|
|
967
|
+
allowFailure: false,
|
|
968
|
+
contracts: [{ ...erc20Config,
|
|
969
|
+
functionName: 'decimals'
|
|
970
|
+
}, { ...erc20Config,
|
|
971
|
+
functionName: 'name'
|
|
972
|
+
}, { ...erc20Config,
|
|
973
|
+
functionName: 'symbol'
|
|
974
|
+
}, { ...erc20Config,
|
|
975
|
+
functionName: 'totalSupply'
|
|
976
|
+
}]
|
|
977
|
+
});
|
|
978
|
+
return {
|
|
979
|
+
address,
|
|
980
|
+
decimals,
|
|
981
|
+
name: name,
|
|
982
|
+
// protect against `ResolvedConfig['BytesType']`
|
|
983
|
+
symbol: symbol,
|
|
984
|
+
// protect against `ResolvedConfig['BytesType']`
|
|
985
|
+
totalSupply: {
|
|
986
|
+
formatted: formatUnits(totalSupply, units),
|
|
987
|
+
value: totalSupply
|
|
347
988
|
}
|
|
348
|
-
}
|
|
989
|
+
};
|
|
990
|
+
}
|
|
349
991
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
const contract = getContract({
|
|
354
|
-
addressOrName,
|
|
355
|
-
contractInterface,
|
|
356
|
-
signerOrProvider
|
|
992
|
+
try {
|
|
993
|
+
return await fetchToken_({
|
|
994
|
+
abi: erc20ABI
|
|
357
995
|
});
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
996
|
+
} catch (err) {
|
|
997
|
+
// In the chance that there is an error upon decoding the contract result,
|
|
998
|
+
// it could be likely that the contract data is represented as bytes32 instead
|
|
999
|
+
// of a string.
|
|
1000
|
+
if (err instanceof ContractResultDecodeError) {
|
|
1001
|
+
const {
|
|
1002
|
+
name,
|
|
1003
|
+
symbol,
|
|
1004
|
+
...rest
|
|
1005
|
+
} = await fetchToken_({
|
|
1006
|
+
abi: erc20ABI_bytes32
|
|
1007
|
+
});
|
|
1008
|
+
return {
|
|
1009
|
+
name: parseBytes32String(name),
|
|
1010
|
+
symbol: parseBytes32String(symbol),
|
|
1011
|
+
...rest
|
|
1012
|
+
};
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
throw err;
|
|
365
1016
|
}
|
|
366
1017
|
}
|
|
367
1018
|
|
|
368
|
-
|
|
1019
|
+
function getContract(_ref) {
|
|
369
1020
|
let {
|
|
370
1021
|
address,
|
|
371
|
-
|
|
372
|
-
|
|
1022
|
+
abi,
|
|
1023
|
+
signerOrProvider
|
|
373
1024
|
} = _ref;
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
};
|
|
379
|
-
const [decimals, name, symbol, totalSupply] = await readContracts({
|
|
380
|
-
allowFailure: false,
|
|
381
|
-
contracts: [{ ...erc20Config,
|
|
382
|
-
functionName: 'decimals'
|
|
383
|
-
}, { ...erc20Config,
|
|
384
|
-
functionName: 'name'
|
|
385
|
-
}, { ...erc20Config,
|
|
386
|
-
functionName: 'symbol'
|
|
387
|
-
}, { ...erc20Config,
|
|
388
|
-
functionName: 'totalSupply'
|
|
389
|
-
}]
|
|
390
|
-
});
|
|
391
|
-
return {
|
|
392
|
-
address,
|
|
393
|
-
decimals,
|
|
394
|
-
name,
|
|
395
|
-
symbol,
|
|
396
|
-
totalSupply: {
|
|
397
|
-
formatted: formatUnits(totalSupply, units),
|
|
398
|
-
value: totalSupply
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
}
|
|
1025
|
+
return new Contract$1(address, abi, signerOrProvider);
|
|
1026
|
+
} ////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
1027
|
+
// Contract
|
|
1028
|
+
// TODO: Add remaining properties
|
|
402
1029
|
|
|
403
1030
|
/**
|
|
404
1031
|
* @description Prepares the parameters required for a contract write transaction.
|
|
@@ -409,58 +1036,63 @@ async function fetchToken(_ref) {
|
|
|
409
1036
|
* import { prepareWriteContract, writeContract } from '@wagmi/core'
|
|
410
1037
|
*
|
|
411
1038
|
* const config = await prepareWriteContract({
|
|
412
|
-
*
|
|
413
|
-
*
|
|
1039
|
+
* address: '0x...',
|
|
1040
|
+
* abi: wagmiAbi,
|
|
414
1041
|
* functionName: 'mint',
|
|
415
1042
|
* })
|
|
416
1043
|
* const result = await writeContract(config)
|
|
417
1044
|
*/
|
|
418
1045
|
async function prepareWriteContract(_ref) {
|
|
419
1046
|
let {
|
|
420
|
-
|
|
1047
|
+
abi,
|
|
1048
|
+
address,
|
|
421
1049
|
args,
|
|
422
1050
|
chainId,
|
|
423
|
-
contractInterface: contractInterface_,
|
|
424
1051
|
functionName,
|
|
425
1052
|
overrides,
|
|
426
1053
|
signer: signer_
|
|
427
1054
|
} = _ref;
|
|
428
|
-
const signer = signer_
|
|
1055
|
+
const signer = signer_ ?? (await fetchSigner({
|
|
1056
|
+
chainId
|
|
1057
|
+
}));
|
|
429
1058
|
if (!signer) throw new ConnectorNotFoundError();
|
|
1059
|
+
if (chainId) assertActiveChain({
|
|
1060
|
+
chainId
|
|
1061
|
+
});
|
|
430
1062
|
const contract = getContract({
|
|
431
|
-
|
|
432
|
-
|
|
1063
|
+
address,
|
|
1064
|
+
abi: abi,
|
|
1065
|
+
// TODO: Remove cast and still support `Narrow<TAbi>`
|
|
433
1066
|
signerOrProvider: signer
|
|
434
1067
|
});
|
|
435
|
-
const
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
const contractInterface = minimizeContractInterface({
|
|
445
|
-
contractInterface: contract.interface,
|
|
446
|
-
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
|
|
447
1077
|
});
|
|
448
|
-
const params = [...(
|
|
1078
|
+
const params = [...(args ?? []), ...(overrides ? [overrides] : [])];
|
|
449
1079
|
const unsignedTransaction = await populateTransactionFn(...params);
|
|
450
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
|
+
});
|
|
451
1086
|
return {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
functionName,
|
|
459
|
-
overrides,
|
|
1087
|
+
abi: minimizedAbi,
|
|
1088
|
+
address,
|
|
1089
|
+
chainId,
|
|
1090
|
+
// TODO: Remove cast
|
|
1091
|
+
functionName: functionName,
|
|
1092
|
+
mode: 'prepared',
|
|
460
1093
|
request: { ...unsignedTransaction,
|
|
461
1094
|
gasLimit
|
|
462
|
-
}
|
|
463
|
-
mode: 'prepared'
|
|
1095
|
+
}
|
|
464
1096
|
};
|
|
465
1097
|
}
|
|
466
1098
|
|
|
@@ -503,30 +1135,6 @@ function watchWebSocketProvider(args, callback) {
|
|
|
503
1135
|
return unsubscribe;
|
|
504
1136
|
}
|
|
505
1137
|
|
|
506
|
-
async function readContract(_ref) {
|
|
507
|
-
let {
|
|
508
|
-
addressOrName,
|
|
509
|
-
args,
|
|
510
|
-
chainId,
|
|
511
|
-
contractInterface,
|
|
512
|
-
functionName,
|
|
513
|
-
overrides
|
|
514
|
-
} = _ref;
|
|
515
|
-
const provider = getProvider({
|
|
516
|
-
chainId
|
|
517
|
-
});
|
|
518
|
-
const contract = getContract({
|
|
519
|
-
addressOrName,
|
|
520
|
-
contractInterface,
|
|
521
|
-
signerOrProvider: provider
|
|
522
|
-
});
|
|
523
|
-
const params = [...(Array.isArray(args) ? args : args ? [args] : []), ...(overrides ? [overrides] : [])];
|
|
524
|
-
const contractFunction = contract[functionName];
|
|
525
|
-
if (!contractFunction) logWarn("\"".concat(functionName, "\" is not in the interface for contract \"").concat(addressOrName, "\""));
|
|
526
|
-
const response = await (contractFunction === null || contractFunction === void 0 ? void 0 : contractFunction(...params));
|
|
527
|
-
return response;
|
|
528
|
-
}
|
|
529
|
-
|
|
530
1138
|
async function multicall(_ref) {
|
|
531
1139
|
let {
|
|
532
1140
|
allowFailure = true,
|
|
@@ -548,14 +1156,14 @@ async function multicall(_ref) {
|
|
|
548
1156
|
chain
|
|
549
1157
|
});
|
|
550
1158
|
const multicallContract = getContract({
|
|
551
|
-
|
|
552
|
-
|
|
1159
|
+
address: chain.multicall.address,
|
|
1160
|
+
abi: multicallABI,
|
|
553
1161
|
signerOrProvider: provider
|
|
554
1162
|
});
|
|
555
1163
|
const calls = contracts.map(_ref2 => {
|
|
556
1164
|
let {
|
|
557
|
-
|
|
558
|
-
|
|
1165
|
+
address,
|
|
1166
|
+
abi,
|
|
559
1167
|
functionName,
|
|
560
1168
|
...config
|
|
561
1169
|
} = _ref2;
|
|
@@ -563,57 +1171,71 @@ async function multicall(_ref) {
|
|
|
563
1171
|
args
|
|
564
1172
|
} = config || {};
|
|
565
1173
|
const contract = getContract({
|
|
566
|
-
|
|
567
|
-
|
|
1174
|
+
address,
|
|
1175
|
+
abi
|
|
1176
|
+
});
|
|
1177
|
+
const params = args ?? [];
|
|
1178
|
+
const normalizedFunctionName = normalizeFunctionName({
|
|
1179
|
+
contract,
|
|
1180
|
+
functionName,
|
|
1181
|
+
args
|
|
568
1182
|
});
|
|
569
|
-
const params = Array.isArray(args) ? args : args ? [args] : [];
|
|
570
1183
|
|
|
571
1184
|
try {
|
|
572
|
-
const
|
|
573
|
-
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);
|
|
574
1188
|
return {
|
|
575
|
-
target:
|
|
1189
|
+
target: address,
|
|
576
1190
|
allowFailure,
|
|
577
1191
|
callData
|
|
578
1192
|
};
|
|
579
1193
|
} catch (err) {
|
|
580
1194
|
if (!allowFailure) throw err;
|
|
581
1195
|
return {
|
|
582
|
-
target:
|
|
1196
|
+
target: address,
|
|
583
1197
|
allowFailure,
|
|
584
1198
|
callData: '0x'
|
|
585
1199
|
};
|
|
586
1200
|
}
|
|
587
1201
|
});
|
|
588
1202
|
const params = [...[calls], ...(overrides ? [overrides] : [])];
|
|
589
|
-
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);
|
|
590
1206
|
return results.map((_ref3, i) => {
|
|
591
1207
|
let {
|
|
592
1208
|
returnData,
|
|
593
1209
|
success
|
|
594
1210
|
} = _ref3;
|
|
595
1211
|
const {
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
1212
|
+
address,
|
|
1213
|
+
abi,
|
|
1214
|
+
args,
|
|
1215
|
+
functionName
|
|
600
1216
|
} = contracts[i];
|
|
601
1217
|
const contract = getContract({
|
|
602
|
-
|
|
603
|
-
|
|
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
|
|
604
1226
|
});
|
|
605
1227
|
|
|
606
1228
|
if (!success) {
|
|
607
1229
|
let error;
|
|
608
1230
|
|
|
609
1231
|
try {
|
|
610
|
-
contract.interface.decodeFunctionResult(
|
|
1232
|
+
contract.interface.decodeFunctionResult(normalizedFunctionName, returnData);
|
|
611
1233
|
} catch (err) {
|
|
612
1234
|
error = new ContractMethodRevertedError({
|
|
613
|
-
|
|
1235
|
+
address,
|
|
614
1236
|
args,
|
|
615
1237
|
chainId: chain.id,
|
|
616
|
-
functionName,
|
|
1238
|
+
functionName: normalizedFunctionName,
|
|
617
1239
|
errorMessage: err.message
|
|
618
1240
|
});
|
|
619
1241
|
if (!allowFailure) throw error;
|
|
@@ -625,10 +1247,10 @@ async function multicall(_ref) {
|
|
|
625
1247
|
|
|
626
1248
|
if (returnData === '0x') {
|
|
627
1249
|
const error = new ContractMethodNoResultError({
|
|
628
|
-
|
|
1250
|
+
address,
|
|
629
1251
|
args,
|
|
630
1252
|
chainId: chain.id,
|
|
631
|
-
functionName
|
|
1253
|
+
functionName: normalizedFunctionName
|
|
632
1254
|
});
|
|
633
1255
|
if (!allowFailure) throw error;
|
|
634
1256
|
logWarn(error.message);
|
|
@@ -636,14 +1258,14 @@ async function multicall(_ref) {
|
|
|
636
1258
|
}
|
|
637
1259
|
|
|
638
1260
|
try {
|
|
639
|
-
const result = contract.interface.decodeFunctionResult(
|
|
1261
|
+
const result = contract.interface.decodeFunctionResult(normalizedFunctionName, returnData);
|
|
640
1262
|
return Array.isArray(result) && result.length === 1 ? result[0] : result;
|
|
641
1263
|
} catch (err) {
|
|
642
1264
|
const error = new ContractResultDecodeError({
|
|
643
|
-
|
|
1265
|
+
address,
|
|
644
1266
|
args,
|
|
645
1267
|
chainId: chain.id,
|
|
646
|
-
functionName,
|
|
1268
|
+
functionName: normalizedFunctionName,
|
|
647
1269
|
errorMessage: err.message
|
|
648
1270
|
});
|
|
649
1271
|
if (!allowFailure) throw error;
|
|
@@ -653,6 +1275,38 @@ async function multicall(_ref) {
|
|
|
653
1275
|
});
|
|
654
1276
|
}
|
|
655
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
|
+
|
|
656
1310
|
async function readContracts(_ref) {
|
|
657
1311
|
let {
|
|
658
1312
|
allowFailure = true,
|
|
@@ -662,12 +1316,13 @@ async function readContracts(_ref) {
|
|
|
662
1316
|
|
|
663
1317
|
try {
|
|
664
1318
|
const provider = getProvider();
|
|
665
|
-
const contractsByChainId = contracts.reduce((contracts, contract) => {
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
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;
|
|
669
1321
|
return { ...contracts,
|
|
670
|
-
[chainId]: [...(contracts[chainId] || []),
|
|
1322
|
+
[chainId]: [...(contracts[chainId] || []), {
|
|
1323
|
+
contract,
|
|
1324
|
+
index
|
|
1325
|
+
}]
|
|
671
1326
|
};
|
|
672
1327
|
}, {});
|
|
673
1328
|
|
|
@@ -676,13 +1331,20 @@ async function readContracts(_ref) {
|
|
|
676
1331
|
return multicall({
|
|
677
1332
|
allowFailure,
|
|
678
1333
|
chainId: parseInt(chainId),
|
|
679
|
-
contracts
|
|
1334
|
+
contracts: contracts.map(_ref3 => {
|
|
1335
|
+
let {
|
|
1336
|
+
contract
|
|
1337
|
+
} = _ref3;
|
|
1338
|
+
return contract;
|
|
1339
|
+
}),
|
|
680
1340
|
overrides
|
|
681
1341
|
});
|
|
682
1342
|
});
|
|
683
1343
|
|
|
1344
|
+
let results;
|
|
1345
|
+
|
|
684
1346
|
if (allowFailure) {
|
|
685
|
-
|
|
1347
|
+
results = (await Promise.allSettled(promises())).map(result => {
|
|
686
1348
|
if (result.status === 'fulfilled') return result.value;
|
|
687
1349
|
|
|
688
1350
|
if (result.reason instanceof ChainDoesNotSupportMulticallError) {
|
|
@@ -692,9 +1354,22 @@ async function readContracts(_ref) {
|
|
|
692
1354
|
|
|
693
1355
|
return null;
|
|
694
1356
|
}).flat();
|
|
695
|
-
}
|
|
1357
|
+
} else {
|
|
1358
|
+
results = (await Promise.all(promises())).flat();
|
|
1359
|
+
} // Reorder the contract results back to the order they were
|
|
1360
|
+
// provided in.
|
|
1361
|
+
|
|
696
1362
|
|
|
697
|
-
|
|
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
|
+
}, []);
|
|
698
1373
|
} catch (err) {
|
|
699
1374
|
if (err instanceof ContractResultDecodeError) throw err;
|
|
700
1375
|
if (err instanceof ContractMethodNoResultError) throw err;
|
|
@@ -704,67 +1379,68 @@ async function readContracts(_ref) {
|
|
|
704
1379
|
overrides
|
|
705
1380
|
}));
|
|
706
1381
|
|
|
707
|
-
if (allowFailure) {
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
errorMessage: result.reason
|
|
722
|
-
});
|
|
723
|
-
logWarn(error.message);
|
|
724
|
-
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
|
|
725
1396
|
});
|
|
726
|
-
|
|
727
|
-
|
|
1397
|
+
logWarn(error.message);
|
|
1398
|
+
return null;
|
|
1399
|
+
});
|
|
728
1400
|
return await Promise.all(promises());
|
|
729
1401
|
}
|
|
730
1402
|
}
|
|
731
1403
|
|
|
732
|
-
function watchContractEvent(
|
|
733
|
-
/** Contract configuration */
|
|
734
|
-
contractArgs,
|
|
735
|
-
/** Event name to listen to */
|
|
736
|
-
eventName, callback) {
|
|
1404
|
+
function watchContractEvent(_ref, callback) {
|
|
737
1405
|
let {
|
|
1406
|
+
address,
|
|
1407
|
+
abi,
|
|
738
1408
|
chainId,
|
|
1409
|
+
eventName,
|
|
739
1410
|
once
|
|
740
|
-
} =
|
|
1411
|
+
} = _ref;
|
|
1412
|
+
|
|
1413
|
+
const handler = function () {
|
|
1414
|
+
return callback(...arguments);
|
|
1415
|
+
};
|
|
1416
|
+
|
|
741
1417
|
let contract;
|
|
742
1418
|
|
|
743
1419
|
const watchEvent = async () => {
|
|
744
|
-
|
|
745
|
-
var _contract;
|
|
746
|
-
|
|
747
|
-
(_contract = contract) === null || _contract === void 0 ? void 0 : _contract.off(eventName, callback);
|
|
748
|
-
}
|
|
1420
|
+
var _contract;
|
|
749
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
|
+
});
|
|
750
1428
|
contract = getContract({
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
}),
|
|
756
|
-
...contractArgs
|
|
1429
|
+
address,
|
|
1430
|
+
abi: abi,
|
|
1431
|
+
// TODO: Remove cast and still support `Narrow<TAbi>`
|
|
1432
|
+
signerOrProvider
|
|
757
1433
|
});
|
|
758
|
-
if (once) contract.once(eventName,
|
|
1434
|
+
if (once) contract.once(eventName, handler);else contract.on(eventName, handler);
|
|
759
1435
|
};
|
|
760
1436
|
|
|
761
1437
|
watchEvent();
|
|
762
1438
|
const client = getClient();
|
|
763
|
-
const unsubscribe = client.subscribe(
|
|
1439
|
+
const unsubscribe = client.subscribe(_ref2 => {
|
|
764
1440
|
let {
|
|
765
1441
|
provider,
|
|
766
1442
|
webSocketProvider
|
|
767
|
-
} =
|
|
1443
|
+
} = _ref2;
|
|
768
1444
|
return {
|
|
769
1445
|
provider,
|
|
770
1446
|
webSocketProvider
|
|
@@ -775,7 +1451,7 @@ eventName, callback) {
|
|
|
775
1451
|
return () => {
|
|
776
1452
|
var _contract2;
|
|
777
1453
|
|
|
778
|
-
(_contract2 = contract) === null || _contract2 === void 0 ? void 0 : _contract2.off(eventName,
|
|
1454
|
+
(_contract2 = contract) === null || _contract2 === void 0 ? void 0 : _contract2.off(eventName, handler);
|
|
779
1455
|
unsubscribe();
|
|
780
1456
|
};
|
|
781
1457
|
}
|
|
@@ -792,18 +1468,15 @@ async function fetchBlockNumber() {
|
|
|
792
1468
|
}
|
|
793
1469
|
|
|
794
1470
|
function watchBlockNumber(args, callback) {
|
|
795
|
-
|
|
796
|
-
|
|
1471
|
+
// We need to debounce the listener as we want to opt-out
|
|
1472
|
+
// of the behavior where ethers emits a "block" event for
|
|
1473
|
+
// every block that was missed in between the `pollingInterval`.
|
|
1474
|
+
// We are setting a wait time of 1 as emitting an event in
|
|
1475
|
+
// ethers takes ~0.1ms.
|
|
1476
|
+
const debouncedCallback = debounce(callback, 1);
|
|
797
1477
|
let previousProvider;
|
|
798
1478
|
|
|
799
1479
|
const createListener = provider => {
|
|
800
|
-
// We need to debounce the listener as we want to opt-out
|
|
801
|
-
// of the behavior where ethers emits a "block" event for
|
|
802
|
-
// every block that was missed in between the `pollingInterval`.
|
|
803
|
-
// We are setting a wait time of 1 as emitting an event in
|
|
804
|
-
// ethers takes ~0.1ms.
|
|
805
|
-
const debouncedCallback = debounce(callback, 1);
|
|
806
|
-
|
|
807
1480
|
if (previousProvider) {
|
|
808
1481
|
var _previousProvider;
|
|
809
1482
|
|
|
@@ -814,9 +1487,14 @@ function watchBlockNumber(args, callback) {
|
|
|
814
1487
|
previousProvider = provider;
|
|
815
1488
|
};
|
|
816
1489
|
|
|
817
|
-
const
|
|
818
|
-
|
|
1490
|
+
const provider_ = getWebSocketProvider({
|
|
1491
|
+
chainId: args.chainId
|
|
1492
|
+
}) ?? getProvider({
|
|
1493
|
+
chainId: args.chainId
|
|
1494
|
+
});
|
|
819
1495
|
if (args.listen) createListener(provider_);
|
|
1496
|
+
let active = true;
|
|
1497
|
+
const client = getClient();
|
|
820
1498
|
const unsubscribe = client.subscribe(_ref => {
|
|
821
1499
|
let {
|
|
822
1500
|
provider,
|
|
@@ -831,26 +1509,34 @@ function watchBlockNumber(args, callback) {
|
|
|
831
1509
|
provider,
|
|
832
1510
|
webSocketProvider
|
|
833
1511
|
} = _ref2;
|
|
834
|
-
const provider_ = webSocketProvider
|
|
1512
|
+
const provider_ = webSocketProvider ?? provider;
|
|
835
1513
|
|
|
836
|
-
if (args.listen && provider_) {
|
|
1514
|
+
if (args.listen && !args.chainId && provider_) {
|
|
837
1515
|
createListener(provider_);
|
|
838
1516
|
}
|
|
839
1517
|
|
|
840
|
-
|
|
1518
|
+
const blockNumber = await fetchBlockNumber({
|
|
1519
|
+
chainId: args.chainId
|
|
1520
|
+
});
|
|
1521
|
+
if (!active) return;
|
|
1522
|
+
callback(blockNumber);
|
|
841
1523
|
}, {
|
|
842
1524
|
equalityFn: shallow
|
|
843
1525
|
});
|
|
844
1526
|
return () => {
|
|
1527
|
+
var _previousProvider2;
|
|
1528
|
+
|
|
1529
|
+
active = false;
|
|
845
1530
|
unsubscribe();
|
|
846
|
-
provider_ === null || provider_ === void 0 ? void 0 : provider_.off('block',
|
|
1531
|
+
provider_ === null || provider_ === void 0 ? void 0 : provider_.off('block', debouncedCallback);
|
|
1532
|
+
(_previousProvider2 = previousProvider) === null || _previousProvider2 === void 0 ? void 0 : _previousProvider2.off('block', debouncedCallback);
|
|
847
1533
|
};
|
|
848
1534
|
}
|
|
849
1535
|
|
|
850
|
-
function
|
|
1536
|
+
function watchMulticall(config, callback) {
|
|
851
1537
|
const client = getClient();
|
|
852
1538
|
|
|
853
|
-
const handleChange = async () => callback(await
|
|
1539
|
+
const handleChange = async () => callback(await multicall(config));
|
|
854
1540
|
|
|
855
1541
|
const unwatch = config.listenToBlock ? watchBlockNumber({
|
|
856
1542
|
listen: true
|
|
@@ -867,10 +1553,10 @@ function watchReadContract(config, callback) {
|
|
|
867
1553
|
};
|
|
868
1554
|
}
|
|
869
1555
|
|
|
870
|
-
function
|
|
1556
|
+
function watchReadContract(config, callback) {
|
|
871
1557
|
const client = getClient();
|
|
872
1558
|
|
|
873
|
-
const handleChange = async () => callback(await
|
|
1559
|
+
const handleChange = async () => callback(await readContract(config));
|
|
874
1560
|
|
|
875
1561
|
const unwatch = config.listenToBlock ? watchBlockNumber({
|
|
876
1562
|
listen: true
|
|
@@ -887,42 +1573,24 @@ function watchReadContracts(config, callback) {
|
|
|
887
1573
|
};
|
|
888
1574
|
}
|
|
889
1575
|
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
chainId,
|
|
893
|
-
request
|
|
894
|
-
} = _ref;
|
|
895
|
-
const {
|
|
896
|
-
connector
|
|
897
|
-
} = getClient();
|
|
898
|
-
if (!connector) throw new ConnectorNotFoundError();
|
|
899
|
-
|
|
900
|
-
try {
|
|
901
|
-
var _chain;
|
|
902
|
-
|
|
903
|
-
let chain;
|
|
904
|
-
|
|
905
|
-
if (chainId) {
|
|
906
|
-
const activeChainId = await connector.getChainId(); // Try to switch chain to provided `chainId`
|
|
907
|
-
|
|
908
|
-
if (chainId !== activeChainId) {
|
|
909
|
-
var _connector$chains$fin, _connector$chains$fin2, _connector$chains$fin3, _connector$chains$fin4;
|
|
1576
|
+
function watchReadContracts(config, callback) {
|
|
1577
|
+
const client = getClient();
|
|
910
1578
|
|
|
911
|
-
|
|
912
|
-
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),
|
|
913
|
-
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)
|
|
914
|
-
});
|
|
915
|
-
}
|
|
916
|
-
}
|
|
1579
|
+
const handleChange = async () => callback(await readContracts(config));
|
|
917
1580
|
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
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
|
+
};
|
|
926
1594
|
}
|
|
927
1595
|
|
|
928
1596
|
/**
|
|
@@ -1021,13 +1689,18 @@ async function prepareSendTransaction(_ref) {
|
|
|
1021
1689
|
let {
|
|
1022
1690
|
chainId,
|
|
1023
1691
|
request,
|
|
1024
|
-
|
|
1025
|
-
chainId
|
|
1026
|
-
})
|
|
1692
|
+
signer: signer_
|
|
1027
1693
|
} = _ref;
|
|
1694
|
+
const signer = signer_ ?? (await fetchSigner({
|
|
1695
|
+
chainId
|
|
1696
|
+
}));
|
|
1697
|
+
if (!signer) throw new ConnectorNotFoundError();
|
|
1698
|
+
if (chainId) assertActiveChain({
|
|
1699
|
+
chainId
|
|
1700
|
+
});
|
|
1028
1701
|
const [to, gasLimit] = await Promise.all([isAddress(request.to) ? Promise.resolve(request.to) : fetchEnsAddress({
|
|
1029
1702
|
name: request.to
|
|
1030
|
-
}), request.gasLimit ? Promise.resolve(request.gasLimit) :
|
|
1703
|
+
}), request.gasLimit ? Promise.resolve(request.gasLimit) : signer.estimateGas(request)]);
|
|
1031
1704
|
if (!to) throw new Error('Could not resolve ENS name');
|
|
1032
1705
|
return { ...(chainId ? {
|
|
1033
1706
|
chainId
|
|
@@ -1082,20 +1755,9 @@ async function sendTransaction(_ref) {
|
|
|
1082
1755
|
if (!request.to) throw new Error('`to` is required');
|
|
1083
1756
|
}
|
|
1084
1757
|
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
} = getNetwork();
|
|
1089
|
-
const activeChainId = activeChain === null || activeChain === void 0 ? void 0 : activeChain.id;
|
|
1090
|
-
|
|
1091
|
-
if (chainId && chainId !== (activeChain === null || activeChain === void 0 ? void 0 : activeChain.id)) {
|
|
1092
|
-
var _chains$find$name, _chains$find, _chains$find$name2, _chains$find2;
|
|
1093
|
-
|
|
1094
|
-
throw new ChainMismatchError({
|
|
1095
|
-
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),
|
|
1096
|
-
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)
|
|
1097
|
-
});
|
|
1098
|
-
}
|
|
1758
|
+
if (chainId) assertActiveChain({
|
|
1759
|
+
chainId
|
|
1760
|
+
});
|
|
1099
1761
|
|
|
1100
1762
|
try {
|
|
1101
1763
|
var _connectUnchecked, _ref2;
|
|
@@ -1111,7 +1773,7 @@ async function sendTransaction(_ref) {
|
|
|
1111
1773
|
const {
|
|
1112
1774
|
hash,
|
|
1113
1775
|
wait
|
|
1114
|
-
} = await (uncheckedSigner
|
|
1776
|
+
} = await (uncheckedSigner ?? signer).sendTransaction(request);
|
|
1115
1777
|
/********************************************************************/
|
|
1116
1778
|
|
|
1117
1779
|
/** END: iOS App Link cautious code. */
|
|
@@ -1121,7 +1783,7 @@ async function sendTransaction(_ref) {
|
|
|
1121
1783
|
/********************************************************************/
|
|
1122
1784
|
|
|
1123
1785
|
return {
|
|
1124
|
-
hash,
|
|
1786
|
+
hash: hash,
|
|
1125
1787
|
wait
|
|
1126
1788
|
};
|
|
1127
1789
|
} catch (error) {
|
|
@@ -1160,58 +1822,45 @@ async function waitForTransaction(_ref) {
|
|
|
1160
1822
|
* import { prepareWriteContract, writeContract } from '@wagmi/core'
|
|
1161
1823
|
*
|
|
1162
1824
|
* const config = await prepareWriteContract({
|
|
1163
|
-
*
|
|
1164
|
-
*
|
|
1825
|
+
* address: '0x...',
|
|
1826
|
+
* abi: wagmiAbi,
|
|
1165
1827
|
* functionName: 'mint',
|
|
1166
1828
|
* })
|
|
1167
1829
|
* const result = await writeContract(config)
|
|
1168
1830
|
*/
|
|
1169
1831
|
async function writeContract(_ref) {
|
|
1170
1832
|
let {
|
|
1171
|
-
|
|
1833
|
+
address,
|
|
1172
1834
|
args,
|
|
1173
1835
|
chainId,
|
|
1174
|
-
|
|
1836
|
+
abi,
|
|
1175
1837
|
functionName,
|
|
1176
1838
|
mode,
|
|
1177
1839
|
overrides,
|
|
1178
1840
|
request: request_
|
|
1179
1841
|
} = _ref;
|
|
1180
1842
|
|
|
1181
|
-
|
|
1843
|
+
/****************************************************************************/
|
|
1182
1844
|
|
|
1183
|
-
/** START: iOS App Link cautious code.
|
|
1845
|
+
/** START: iOS App Link cautious code. */
|
|
1184
1846
|
|
|
1185
|
-
/** Do not perform any async operations in this block.
|
|
1847
|
+
/** Do not perform any async operations in this block. */
|
|
1186
1848
|
|
|
1187
|
-
/** Ref: wagmi.sh/docs/prepare-hooks/intro#ios-app-link-constraints */
|
|
1849
|
+
/** Ref: https://wagmi.sh/docs/prepare-hooks/intro#ios-app-link-constraints */
|
|
1188
1850
|
|
|
1189
|
-
|
|
1851
|
+
/****************************************************************************/
|
|
1190
1852
|
const signer = await fetchSigner();
|
|
1191
1853
|
if (!signer) throw new ConnectorNotFoundError();
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
const activeChainId = activeChain === null || activeChain === void 0 ? void 0 : activeChain.id;
|
|
1197
|
-
|
|
1198
|
-
if (chainId && chainId !== activeChainId) {
|
|
1199
|
-
var _chains$find$name, _chains$find, _chains$find$name2, _chains$find2;
|
|
1200
|
-
|
|
1201
|
-
throw new ChainMismatchError({
|
|
1202
|
-
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),
|
|
1203
|
-
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)
|
|
1204
|
-
});
|
|
1205
|
-
}
|
|
1206
|
-
|
|
1207
|
-
if (mode === 'prepared') {
|
|
1208
|
-
if (!request_) throw new Error('`request` is required');
|
|
1209
|
-
}
|
|
1210
|
-
|
|
1854
|
+
if (chainId) assertActiveChain({
|
|
1855
|
+
chainId
|
|
1856
|
+
});
|
|
1857
|
+
if (mode === 'prepared') if (!request_) throw new Error('`request` is required');
|
|
1211
1858
|
const request = mode === 'recklesslyUnprepared' ? (await prepareWriteContract({
|
|
1212
|
-
|
|
1859
|
+
address,
|
|
1213
1860
|
args,
|
|
1214
|
-
|
|
1861
|
+
chainId,
|
|
1862
|
+
abi: abi,
|
|
1863
|
+
// TODO: Remove cast and still support `Narrow<TAbi>`
|
|
1215
1864
|
functionName,
|
|
1216
1865
|
overrides
|
|
1217
1866
|
})).request : request_;
|
|
@@ -1231,7 +1880,7 @@ async function writeContract(_ref) {
|
|
|
1231
1880
|
}
|
|
1232
1881
|
|
|
1233
1882
|
async function fetchBalance(_ref) {
|
|
1234
|
-
var
|
|
1883
|
+
var _chain$nativeCurrency, _chain$nativeCurrency2;
|
|
1235
1884
|
|
|
1236
1885
|
let {
|
|
1237
1886
|
addressOrName,
|
|
@@ -1245,47 +1894,78 @@ async function fetchBalance(_ref) {
|
|
|
1245
1894
|
});
|
|
1246
1895
|
|
|
1247
1896
|
if (token) {
|
|
1248
|
-
|
|
1249
|
-
addressOrName: token,
|
|
1250
|
-
contractInterface: erc20ABI,
|
|
1251
|
-
chainId
|
|
1252
|
-
}; // Convert ENS name to address if required
|
|
1253
|
-
|
|
1897
|
+
// Convert ENS name to address if required
|
|
1254
1898
|
let resolvedAddress;
|
|
1255
1899
|
if (isAddress(addressOrName)) resolvedAddress = addressOrName;else {
|
|
1256
1900
|
const address = await provider.resolveName(addressOrName); // Same error `provider.getBalance` throws for invalid ENS name
|
|
1257
1901
|
|
|
1258
1902
|
if (!address) logger.throwError('ENS name not configured', Logger.errors.UNSUPPORTED_OPERATION, {
|
|
1259
|
-
operation:
|
|
1903
|
+
operation: `resolveName(${JSON.stringify(addressOrName)})`
|
|
1260
1904
|
});
|
|
1261
1905
|
resolvedAddress = address;
|
|
1262
1906
|
}
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
}
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1907
|
+
|
|
1908
|
+
const fetchContractBalance = async _ref2 => {
|
|
1909
|
+
let {
|
|
1910
|
+
abi
|
|
1911
|
+
} = _ref2;
|
|
1912
|
+
const erc20Config = {
|
|
1913
|
+
abi,
|
|
1914
|
+
address: token,
|
|
1915
|
+
chainId
|
|
1916
|
+
};
|
|
1917
|
+
const [value, decimals, symbol] = await readContracts({
|
|
1918
|
+
allowFailure: false,
|
|
1919
|
+
contracts: [{ ...erc20Config,
|
|
1920
|
+
functionName: 'balanceOf',
|
|
1921
|
+
args: [resolvedAddress]
|
|
1922
|
+
}, { ...erc20Config,
|
|
1923
|
+
functionName: 'decimals'
|
|
1924
|
+
}, { ...erc20Config,
|
|
1925
|
+
functionName: 'symbol'
|
|
1926
|
+
}]
|
|
1927
|
+
});
|
|
1928
|
+
return {
|
|
1929
|
+
decimals,
|
|
1930
|
+
formatted: formatUnits(value ?? '0', unit ?? decimals),
|
|
1931
|
+
symbol: symbol,
|
|
1932
|
+
// protect against `ResolvedConfig['BytesType']`
|
|
1933
|
+
value
|
|
1934
|
+
};
|
|
1279
1935
|
};
|
|
1936
|
+
|
|
1937
|
+
try {
|
|
1938
|
+
return await fetchContractBalance({
|
|
1939
|
+
abi: erc20ABI
|
|
1940
|
+
});
|
|
1941
|
+
} catch (err) {
|
|
1942
|
+
// In the chance that there is an error upon decoding the contract result,
|
|
1943
|
+
// it could be likely that the contract data is represented as bytes32 instead
|
|
1944
|
+
// of a string.
|
|
1945
|
+
if (err instanceof ContractResultDecodeError) {
|
|
1946
|
+
const {
|
|
1947
|
+
symbol,
|
|
1948
|
+
...rest
|
|
1949
|
+
} = await fetchContractBalance({
|
|
1950
|
+
abi: erc20ABI_bytes32
|
|
1951
|
+
});
|
|
1952
|
+
return {
|
|
1953
|
+
symbol: parseBytes32String(symbol),
|
|
1954
|
+
...rest
|
|
1955
|
+
};
|
|
1956
|
+
}
|
|
1957
|
+
|
|
1958
|
+
throw err;
|
|
1959
|
+
}
|
|
1280
1960
|
}
|
|
1281
1961
|
|
|
1282
|
-
const chains = [...(client.provider.chains || []), ...(
|
|
1962
|
+
const chains = [...(client.provider.chains || []), ...(client.chains ?? [])];
|
|
1283
1963
|
const value = await provider.getBalance(addressOrName);
|
|
1284
1964
|
const chain = chains.find(x => x.id === provider.network.chainId);
|
|
1285
1965
|
return {
|
|
1286
|
-
decimals: (
|
|
1287
|
-
formatted: formatUnits(value
|
|
1288
|
-
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',
|
|
1289
1969
|
value
|
|
1290
1970
|
};
|
|
1291
1971
|
}
|
|
@@ -1293,8 +1973,13 @@ async function fetchBalance(_ref) {
|
|
|
1293
1973
|
async function fetchSigner() {
|
|
1294
1974
|
var _client$connector, _client$connector$get;
|
|
1295
1975
|
|
|
1976
|
+
let {
|
|
1977
|
+
chainId
|
|
1978
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1296
1979
|
const client = getClient();
|
|
1297
|
-
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;
|
|
1298
1983
|
return signer;
|
|
1299
1984
|
}
|
|
1300
1985
|
|
|
@@ -1353,15 +2038,15 @@ function getAccount() {
|
|
|
1353
2038
|
}
|
|
1354
2039
|
|
|
1355
2040
|
function getNetwork() {
|
|
1356
|
-
var _client$data, _client$data$chain, _client$
|
|
2041
|
+
var _client$data, _client$data$chain, _client$data2;
|
|
1357
2042
|
|
|
1358
2043
|
const client = getClient();
|
|
1359
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;
|
|
1360
|
-
const activeChains =
|
|
1361
|
-
const activeChain =
|
|
2045
|
+
const activeChains = client.chains ?? [];
|
|
2046
|
+
const activeChain = [...(client.provider.chains || []), ...activeChains].find(x => x.id === chainId) ?? {
|
|
1362
2047
|
id: chainId,
|
|
1363
|
-
name:
|
|
1364
|
-
network:
|
|
2048
|
+
name: `Chain ${chainId}`,
|
|
2049
|
+
network: `${chainId}`,
|
|
1365
2050
|
rpcUrls: {
|
|
1366
2051
|
default: ''
|
|
1367
2052
|
}
|
|
@@ -1394,28 +2079,13 @@ async function signTypedData(_ref) {
|
|
|
1394
2079
|
} = _ref;
|
|
1395
2080
|
const signer = await fetchSigner();
|
|
1396
2081
|
if (!signer) throw new ConnectorNotFoundError();
|
|
1397
|
-
const {
|
|
1398
|
-
chain: activeChain,
|
|
1399
|
-
chains
|
|
1400
|
-
} = getNetwork();
|
|
1401
2082
|
const {
|
|
1402
2083
|
chainId: chainId_
|
|
1403
2084
|
} = domain;
|
|
1404
|
-
|
|
1405
|
-
if (
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
if (chainId !== (activeChain === null || activeChain === void 0 ? void 0 : activeChain.id)) {
|
|
1410
|
-
var _chains$find$name, _chains$find, _chains$find$name2, _chains$find2;
|
|
1411
|
-
|
|
1412
|
-
throw new ChainMismatchError({
|
|
1413
|
-
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),
|
|
1414
|
-
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)
|
|
1415
|
-
});
|
|
1416
|
-
}
|
|
1417
|
-
} // Method name may be changed in the future, see https://docs.ethers.io/v5/api/signer/#Signer-signTypedData
|
|
1418
|
-
|
|
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
|
|
1419
2089
|
|
|
1420
2090
|
return await signer._signTypedData(domain, types, value);
|
|
1421
2091
|
}
|
|
@@ -1484,18 +2154,23 @@ function watchNetwork(callback) {
|
|
|
1484
2154
|
return unsubscribe;
|
|
1485
2155
|
}
|
|
1486
2156
|
|
|
1487
|
-
function watchSigner(callback) {
|
|
2157
|
+
function watchSigner(_ref, callback) {
|
|
2158
|
+
let {
|
|
2159
|
+
chainId
|
|
2160
|
+
} = _ref;
|
|
1488
2161
|
const client = getClient();
|
|
1489
2162
|
|
|
1490
|
-
const handleChange = async () => callback(await fetchSigner(
|
|
2163
|
+
const handleChange = async () => callback(await fetchSigner({
|
|
2164
|
+
chainId
|
|
2165
|
+
}));
|
|
1491
2166
|
|
|
1492
|
-
const unsubscribe = client.subscribe(
|
|
2167
|
+
const unsubscribe = client.subscribe(_ref2 => {
|
|
1493
2168
|
var _data$chain;
|
|
1494
2169
|
|
|
1495
2170
|
let {
|
|
1496
2171
|
data,
|
|
1497
2172
|
connector
|
|
1498
|
-
} =
|
|
2173
|
+
} = _ref2;
|
|
1499
2174
|
return {
|
|
1500
2175
|
account: data === null || data === void 0 ? void 0 : data.account,
|
|
1501
2176
|
chainId: data === null || data === void 0 ? void 0 : (_data$chain = data.chain) === null || _data$chain === void 0 ? void 0 : _data$chain.id,
|
|
@@ -1526,4 +2201,4 @@ async function fetchFeeData() {
|
|
|
1526
2201
|
};
|
|
1527
2202
|
}
|
|
1528
2203
|
|
|
1529
|
-
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 };
|