@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
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var getProvider = require('./getProvider-
|
|
6
|
-
var ethers = require('ethers');
|
|
5
|
+
var getProvider = require('./getProvider-f6f17fa1.cjs.dev.js');
|
|
7
6
|
var ethers$1 = require('ethers/lib/ethers');
|
|
8
7
|
var utils = require('ethers/lib/utils');
|
|
9
|
-
var
|
|
8
|
+
var ethers = require('ethers');
|
|
9
|
+
var chains = require('./chains-524f4950.cjs.dev.js');
|
|
10
10
|
var shallow = require('zustand/shallow');
|
|
11
11
|
var debounce = require('./debounce-46ac0312.cjs.dev.js');
|
|
12
|
-
var rpcs = require('./rpcs-
|
|
12
|
+
var rpcs = require('./rpcs-0d21dfe8.cjs.dev.js');
|
|
13
13
|
require('zustand/middleware');
|
|
14
14
|
require('zustand/vanilla');
|
|
15
15
|
require('eventemitter3');
|
|
@@ -21,7 +21,7 @@ var shallow__default = /*#__PURE__*/_interopDefault(shallow);
|
|
|
21
21
|
function configureChains(defaultChains, providers) {
|
|
22
22
|
let {
|
|
23
23
|
minQuorum = 1,
|
|
24
|
-
pollingInterval =
|
|
24
|
+
pollingInterval = 4_000,
|
|
25
25
|
targetQuorum = 1,
|
|
26
26
|
stallTimeout
|
|
27
27
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
@@ -60,48 +60,63 @@ function configureChains(defaultChains, providers) {
|
|
|
60
60
|
|
|
61
61
|
|
|
62
62
|
if (!configExists) {
|
|
63
|
-
throw new Error([
|
|
63
|
+
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'));
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
return {
|
|
68
68
|
chains,
|
|
69
69
|
provider: _ref2 => {
|
|
70
|
-
var _defaultChains$;
|
|
71
|
-
|
|
72
70
|
let {
|
|
73
71
|
chainId
|
|
74
72
|
} = _ref2;
|
|
75
|
-
const
|
|
76
|
-
const chainProviders = providers_[
|
|
77
|
-
if (!chainProviders || !chainProviders[0]) throw new Error(
|
|
73
|
+
const activeChain = chains.find(x => x.id === chainId) ?? defaultChains[0];
|
|
74
|
+
const chainProviders = providers_[activeChain.id];
|
|
75
|
+
if (!chainProviders || !chainProviders[0]) throw new Error(`No providers configured for chain "${activeChain.id}"`);
|
|
76
|
+
let provider;
|
|
78
77
|
|
|
79
78
|
if (chainProviders.length === 1) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
provider = chainProviders[0]();
|
|
80
|
+
} else {
|
|
81
|
+
provider = fallbackProvider(targetQuorum, minQuorum, chainProviders, {
|
|
82
|
+
stallTimeout
|
|
83
83
|
});
|
|
84
|
+
} // Formatter workaround as Celo does not provide `gasLimit` or `difficulty` on eth_getBlockByNumber.
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
if (activeChain.id === 42220) {
|
|
88
|
+
provider.formatter.formats.block = { ...provider.formatter.formats.block,
|
|
89
|
+
difficulty: () => 0,
|
|
90
|
+
gasLimit: () => 0
|
|
91
|
+
};
|
|
84
92
|
}
|
|
85
93
|
|
|
86
|
-
return Object.assign(
|
|
87
|
-
stallTimeout
|
|
88
|
-
}), {
|
|
94
|
+
return Object.assign(provider, {
|
|
89
95
|
chains,
|
|
90
96
|
pollingInterval
|
|
91
97
|
});
|
|
92
98
|
},
|
|
93
99
|
webSocketProvider: _ref3 => {
|
|
94
|
-
var
|
|
100
|
+
var _chainWebSocketProvid;
|
|
95
101
|
|
|
96
102
|
let {
|
|
97
103
|
chainId
|
|
98
104
|
} = _ref3;
|
|
99
|
-
const
|
|
100
|
-
const chainWebSocketProviders = webSocketProviders_[
|
|
101
|
-
if (!chainWebSocketProviders) return undefined;
|
|
105
|
+
const activeChain = chains.find(x => x.id === chainId) ?? defaultChains[0];
|
|
106
|
+
const chainWebSocketProviders = webSocketProviders_[activeChain.id];
|
|
107
|
+
if (!chainWebSocketProviders) return undefined;
|
|
108
|
+
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.
|
|
109
|
+
|
|
110
|
+
if (provider && activeChain.id === 42220) {
|
|
111
|
+
provider.formatter.formats.block = { ...provider.formatter.formats.block,
|
|
112
|
+
difficulty: () => 0,
|
|
113
|
+
gasLimit: () => 0
|
|
114
|
+
};
|
|
115
|
+
} // WebSockets do not work with `fallbackProvider`
|
|
102
116
|
// Default to first available
|
|
103
117
|
|
|
104
|
-
|
|
118
|
+
|
|
119
|
+
return Object.assign(provider || {}, {
|
|
105
120
|
chains
|
|
106
121
|
});
|
|
107
122
|
}
|
|
@@ -115,13 +130,11 @@ function fallbackProvider(targetQuorum, minQuorum, providers_, _ref4) {
|
|
|
115
130
|
|
|
116
131
|
try {
|
|
117
132
|
return new ethers.providers.FallbackProvider(providers_.map((chainProvider, index) => {
|
|
118
|
-
var _provider$priority, _provider$stallTimeou;
|
|
119
|
-
|
|
120
133
|
const provider = chainProvider();
|
|
121
134
|
return {
|
|
122
135
|
provider,
|
|
123
|
-
priority:
|
|
124
|
-
stallTimeout:
|
|
136
|
+
priority: provider.priority ?? index,
|
|
137
|
+
stallTimeout: provider.stallTimeout ?? stallTimeout,
|
|
125
138
|
weight: provider.weight
|
|
126
139
|
};
|
|
127
140
|
}), targetQuorum);
|
|
@@ -139,6 +152,26 @@ function fallbackProvider(targetQuorum, minQuorum, providers_, _ref4) {
|
|
|
139
152
|
}
|
|
140
153
|
}
|
|
141
154
|
|
|
155
|
+
function assertActiveChain(_ref) {
|
|
156
|
+
let {
|
|
157
|
+
chainId
|
|
158
|
+
} = _ref;
|
|
159
|
+
const {
|
|
160
|
+
chain: activeChain,
|
|
161
|
+
chains
|
|
162
|
+
} = getNetwork();
|
|
163
|
+
const activeChainId = activeChain === null || activeChain === void 0 ? void 0 : activeChain.id;
|
|
164
|
+
|
|
165
|
+
if (chainId !== activeChainId) {
|
|
166
|
+
var _chains$find, _chains$find2;
|
|
167
|
+
|
|
168
|
+
throw new getProvider.ChainMismatchError({
|
|
169
|
+
activeChain: ((_chains$find = chains.find(x => x.id === activeChainId)) === null || _chains$find === void 0 ? void 0 : _chains$find.name) ?? `Chain ${activeChainId}`,
|
|
170
|
+
targetChain: ((_chains$find2 = chains.find(x => x.id === chainId)) === null || _chains$find2 === void 0 ? void 0 : _chains$find2.name) ?? `Chain ${chainId}`
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
142
175
|
/** Forked from https://github.com/epoberezkin/fast-deep-equal */
|
|
143
176
|
function deepEqual(a, b) {
|
|
144
177
|
if (a === b) return true;
|
|
@@ -177,20 +210,100 @@ function deepEqual(a, b) {
|
|
|
177
210
|
return a !== a && b !== b;
|
|
178
211
|
}
|
|
179
212
|
|
|
213
|
+
/**
|
|
214
|
+
* Get normalized function name from contract
|
|
215
|
+
*
|
|
216
|
+
* @param contract — Contract
|
|
217
|
+
* @param functionName — Function name
|
|
218
|
+
* @param args — Function arguments (used to disambiguate overloaded functions)
|
|
219
|
+
*
|
|
220
|
+
* @returns Normalized function name
|
|
221
|
+
*/
|
|
222
|
+
|
|
223
|
+
function normalizeFunctionName(_ref) {
|
|
224
|
+
let {
|
|
225
|
+
contract,
|
|
226
|
+
functionName,
|
|
227
|
+
args = []
|
|
228
|
+
} = _ref;
|
|
229
|
+
// If `functionName` exists in contract, return it.
|
|
230
|
+
if (functionName in contract.functions) return functionName; // Otherwise, check if `functionName` is an overloaded function based on `args` shape.
|
|
231
|
+
|
|
232
|
+
const argsLength = (args === null || args === void 0 ? void 0 : args.length) ?? 0;
|
|
233
|
+
const overloadFunctions = Object.keys(contract.functions).filter(x => x.startsWith(`${functionName}(`)).map(x => ({
|
|
234
|
+
name: x,
|
|
235
|
+
fragment: utils.FunctionFragment.fromString(x)
|
|
236
|
+
})).filter(x => argsLength === x.fragment.inputs.length);
|
|
237
|
+
|
|
238
|
+
for (const overloadFunction of overloadFunctions) {
|
|
239
|
+
const matched = args.every((arg, index) => {
|
|
240
|
+
const abiParameter = overloadFunction.fragment.inputs[index];
|
|
241
|
+
return isArgOfType(arg, abiParameter);
|
|
242
|
+
});
|
|
243
|
+
if (matched) return overloadFunction.name;
|
|
244
|
+
} // Wasn't able to find overload, just return function name.
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
return functionName;
|
|
248
|
+
}
|
|
249
|
+
function isArgOfType(arg, abiParameter) {
|
|
250
|
+
const argType = typeof arg;
|
|
251
|
+
const abiParameterType = abiParameter.type;
|
|
252
|
+
|
|
253
|
+
switch (abiParameterType) {
|
|
254
|
+
case 'address':
|
|
255
|
+
return utils.isAddress(arg);
|
|
256
|
+
|
|
257
|
+
case 'bool':
|
|
258
|
+
return argType === 'boolean';
|
|
259
|
+
|
|
260
|
+
case 'function':
|
|
261
|
+
return argType === 'string';
|
|
262
|
+
|
|
263
|
+
case 'string':
|
|
264
|
+
return argType === 'string';
|
|
265
|
+
|
|
266
|
+
default:
|
|
267
|
+
{
|
|
268
|
+
if (abiParameterType === 'tuple' && 'components' in abiParameter) return Object.values(abiParameter.components).every((component, index) => {
|
|
269
|
+
return isArgOfType(Object.values(arg)[index], component);
|
|
270
|
+
}); // `(u)int<M>`: (un)signed integer type of `M` bits, `0 < M <= 256`, `M % 8 == 0`
|
|
271
|
+
// https://regexr.com/6v8hp
|
|
272
|
+
|
|
273
|
+
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' || ethers.BigNumber.isBigNumber(arg); // `bytes<M>`: binary type of `M` bytes, `0 < M <= 32`
|
|
274
|
+
// https://regexr.com/6va55
|
|
275
|
+
|
|
276
|
+
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
|
|
277
|
+
// https://regexr.com/6va6i
|
|
278
|
+
|
|
279
|
+
if (/[a-z]+[1-9]{0,3}(\[[0-9]{0,}\])+$/.test(abiParameterType)) {
|
|
280
|
+
return Array.isArray(arg) && arg.every(x => isArgOfType(x, { ...abiParameter,
|
|
281
|
+
// Pop off `[]` or `[M]` from end of type
|
|
282
|
+
type: abiParameterType.replace(/(\[[0-9]{0,}\])$/, '')
|
|
283
|
+
}));
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
180
291
|
function logWarn(message) {
|
|
181
292
|
var _getClient, _getClient$config$log, _getClient$config$log2;
|
|
182
293
|
|
|
183
294
|
(_getClient = getProvider.getClient()) === null || _getClient === void 0 ? void 0 : (_getClient$config$log = _getClient.config.logger) === null || _getClient$config$log === void 0 ? void 0 : (_getClient$config$log2 = _getClient$config$log.warn) === null || _getClient$config$log2 === void 0 ? void 0 : _getClient$config$log2.call(_getClient$config$log, message);
|
|
184
295
|
}
|
|
185
296
|
|
|
186
|
-
function minimizeContractInterface(
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
297
|
+
function minimizeContractInterface(config) {
|
|
298
|
+
try {
|
|
299
|
+
const minimizedAbi = config.abi.filter(x => x.type === 'function' && x.name === config.functionName);
|
|
300
|
+
if (minimizedAbi.length === 0) throw new Error('Invalid ABI');
|
|
301
|
+
return minimizedAbi;
|
|
302
|
+
} catch (error) {
|
|
303
|
+
const abi = ethers$1.Contract.getInterface(config.abi).format(utils.FormatTypes.full);
|
|
304
|
+
const minimizedInterface = Array.isArray(abi) ? abi : [abi];
|
|
305
|
+
return minimizedInterface.filter(i => i.includes(config.functionName));
|
|
306
|
+
}
|
|
194
307
|
}
|
|
195
308
|
|
|
196
309
|
function isPlainArray(value) {
|
|
@@ -199,7 +312,7 @@ function isPlainArray(value) {
|
|
|
199
312
|
|
|
200
313
|
function parseContractResult(_ref) {
|
|
201
314
|
let {
|
|
202
|
-
|
|
315
|
+
abi,
|
|
203
316
|
data,
|
|
204
317
|
functionName
|
|
205
318
|
} = _ref;
|
|
@@ -207,7 +320,7 @@ function parseContractResult(_ref) {
|
|
|
207
320
|
if (data && isPlainArray(data)) {
|
|
208
321
|
var _fragment$outputs;
|
|
209
322
|
|
|
210
|
-
const iface = ethers$1.Contract.getInterface(
|
|
323
|
+
const iface = ethers$1.Contract.getInterface(abi);
|
|
211
324
|
const fragment = iface.getFunction(functionName);
|
|
212
325
|
const isTuple = (((_fragment$outputs = fragment.outputs) === null || _fragment$outputs === void 0 ? void 0 : _fragment$outputs.length) || 0) > 1;
|
|
213
326
|
const data_ = isTuple ? data : [data];
|
|
@@ -219,42 +332,572 @@ function parseContractResult(_ref) {
|
|
|
219
332
|
return data;
|
|
220
333
|
}
|
|
221
334
|
|
|
222
|
-
|
|
223
|
-
|
|
335
|
+
/**
|
|
336
|
+
* [ERC-20 Token Standard](https://ethereum.org/en/developers/docs/standards/tokens/erc-20)
|
|
337
|
+
*/
|
|
338
|
+
const erc20ABI = [{
|
|
339
|
+
type: 'event',
|
|
340
|
+
name: 'Approval',
|
|
341
|
+
inputs: [{
|
|
342
|
+
indexed: true,
|
|
343
|
+
name: 'owner',
|
|
344
|
+
type: 'address'
|
|
345
|
+
}, {
|
|
346
|
+
indexed: true,
|
|
347
|
+
name: 'spender',
|
|
348
|
+
type: 'address'
|
|
349
|
+
}, {
|
|
350
|
+
indexed: false,
|
|
351
|
+
name: 'value',
|
|
352
|
+
type: 'uint256'
|
|
353
|
+
}]
|
|
354
|
+
}, {
|
|
355
|
+
type: 'event',
|
|
356
|
+
name: 'Transfer',
|
|
357
|
+
inputs: [{
|
|
358
|
+
indexed: true,
|
|
359
|
+
name: 'from',
|
|
360
|
+
type: 'address'
|
|
361
|
+
}, {
|
|
362
|
+
indexed: true,
|
|
363
|
+
name: 'to',
|
|
364
|
+
type: 'address'
|
|
365
|
+
}, {
|
|
366
|
+
indexed: false,
|
|
367
|
+
name: 'value',
|
|
368
|
+
type: 'uint256'
|
|
369
|
+
}]
|
|
370
|
+
}, {
|
|
371
|
+
type: 'function',
|
|
372
|
+
name: 'allowance',
|
|
373
|
+
stateMutability: 'view',
|
|
374
|
+
inputs: [{
|
|
375
|
+
name: 'owner',
|
|
376
|
+
type: 'address'
|
|
377
|
+
}, {
|
|
378
|
+
name: 'spender',
|
|
379
|
+
type: 'address'
|
|
380
|
+
}],
|
|
381
|
+
outputs: [{
|
|
382
|
+
name: '',
|
|
383
|
+
type: 'uint256'
|
|
384
|
+
}]
|
|
385
|
+
}, {
|
|
386
|
+
type: 'function',
|
|
387
|
+
name: 'approve',
|
|
388
|
+
stateMutability: 'nonpayable',
|
|
389
|
+
inputs: [{
|
|
390
|
+
name: 'spender',
|
|
391
|
+
type: 'address'
|
|
392
|
+
}, {
|
|
393
|
+
name: 'amount',
|
|
394
|
+
type: 'uint256'
|
|
395
|
+
}],
|
|
396
|
+
outputs: [{
|
|
397
|
+
name: '',
|
|
398
|
+
type: 'bool'
|
|
399
|
+
}]
|
|
400
|
+
}, {
|
|
401
|
+
type: 'function',
|
|
402
|
+
name: 'balanceOf',
|
|
403
|
+
stateMutability: 'view',
|
|
404
|
+
inputs: [{
|
|
405
|
+
name: 'account',
|
|
406
|
+
type: 'address'
|
|
407
|
+
}],
|
|
408
|
+
outputs: [{
|
|
409
|
+
name: '',
|
|
410
|
+
type: 'uint256'
|
|
411
|
+
}]
|
|
412
|
+
}, {
|
|
413
|
+
type: 'function',
|
|
414
|
+
name: 'decimals',
|
|
415
|
+
stateMutability: 'view',
|
|
416
|
+
inputs: [],
|
|
417
|
+
outputs: [{
|
|
418
|
+
name: '',
|
|
419
|
+
type: 'uint8'
|
|
420
|
+
}]
|
|
421
|
+
}, {
|
|
422
|
+
type: 'function',
|
|
423
|
+
name: 'name',
|
|
424
|
+
stateMutability: 'view',
|
|
425
|
+
inputs: [],
|
|
426
|
+
outputs: [{
|
|
427
|
+
name: '',
|
|
428
|
+
type: 'string'
|
|
429
|
+
}]
|
|
430
|
+
}, {
|
|
431
|
+
type: 'function',
|
|
432
|
+
name: 'symbol',
|
|
433
|
+
stateMutability: 'view',
|
|
434
|
+
inputs: [],
|
|
435
|
+
outputs: [{
|
|
436
|
+
name: '',
|
|
437
|
+
type: 'string'
|
|
438
|
+
}]
|
|
439
|
+
}, {
|
|
440
|
+
type: 'function',
|
|
441
|
+
name: 'totalSupply',
|
|
442
|
+
stateMutability: 'view',
|
|
443
|
+
inputs: [],
|
|
444
|
+
outputs: [{
|
|
445
|
+
name: '',
|
|
446
|
+
type: 'uint256'
|
|
447
|
+
}]
|
|
448
|
+
}, {
|
|
449
|
+
type: 'function',
|
|
450
|
+
name: 'transfer',
|
|
451
|
+
stateMutability: 'nonpayable',
|
|
452
|
+
inputs: [{
|
|
453
|
+
name: 'recipient',
|
|
454
|
+
type: 'address'
|
|
455
|
+
}, {
|
|
456
|
+
name: 'amount',
|
|
457
|
+
type: 'uint256'
|
|
458
|
+
}],
|
|
459
|
+
outputs: [{
|
|
460
|
+
name: '',
|
|
461
|
+
type: 'bool'
|
|
462
|
+
}]
|
|
463
|
+
}, {
|
|
464
|
+
type: 'function',
|
|
465
|
+
name: 'transferFrom',
|
|
466
|
+
stateMutability: 'nonpayable',
|
|
467
|
+
inputs: [{
|
|
468
|
+
name: 'sender',
|
|
469
|
+
type: 'address'
|
|
470
|
+
}, {
|
|
471
|
+
name: 'recipient',
|
|
472
|
+
type: 'address'
|
|
473
|
+
}, {
|
|
474
|
+
name: 'amount',
|
|
475
|
+
type: 'uint256'
|
|
476
|
+
}],
|
|
477
|
+
outputs: [{
|
|
478
|
+
name: '',
|
|
479
|
+
type: 'bool'
|
|
480
|
+
}]
|
|
481
|
+
}];
|
|
482
|
+
/**
|
|
483
|
+
* [bytes32-flavored ERC-20](https://docs.makerdao.com/smart-contract-modules/mkr-module#4.-gotchas-potential-source-of-user-error)
|
|
484
|
+
* for tokens (ie. Maker) that use bytes32 instead of string.
|
|
485
|
+
*/
|
|
224
486
|
|
|
225
|
-
const
|
|
487
|
+
const erc20ABI_bytes32 = [{
|
|
488
|
+
type: 'event',
|
|
489
|
+
name: 'Approval',
|
|
490
|
+
inputs: [{
|
|
491
|
+
indexed: true,
|
|
492
|
+
name: 'owner',
|
|
493
|
+
type: 'address'
|
|
494
|
+
}, {
|
|
495
|
+
indexed: true,
|
|
496
|
+
name: 'spender',
|
|
497
|
+
type: 'address'
|
|
498
|
+
}, {
|
|
499
|
+
indexed: false,
|
|
500
|
+
name: 'value',
|
|
501
|
+
type: 'uint256'
|
|
502
|
+
}]
|
|
503
|
+
}, {
|
|
504
|
+
type: 'event',
|
|
505
|
+
name: 'Transfer',
|
|
506
|
+
inputs: [{
|
|
507
|
+
indexed: true,
|
|
508
|
+
name: 'from',
|
|
509
|
+
type: 'address'
|
|
510
|
+
}, {
|
|
511
|
+
indexed: true,
|
|
512
|
+
name: 'to',
|
|
513
|
+
type: 'address'
|
|
514
|
+
}, {
|
|
515
|
+
indexed: false,
|
|
516
|
+
name: 'value',
|
|
517
|
+
type: 'uint256'
|
|
518
|
+
}]
|
|
519
|
+
}, {
|
|
520
|
+
type: 'function',
|
|
521
|
+
name: 'allowance',
|
|
522
|
+
stateMutability: 'view',
|
|
523
|
+
inputs: [{
|
|
524
|
+
name: 'owner',
|
|
525
|
+
type: 'address'
|
|
526
|
+
}, {
|
|
527
|
+
name: 'spender',
|
|
528
|
+
type: 'address'
|
|
529
|
+
}],
|
|
530
|
+
outputs: [{
|
|
531
|
+
name: '',
|
|
532
|
+
type: 'uint256'
|
|
533
|
+
}]
|
|
534
|
+
}, {
|
|
535
|
+
type: 'function',
|
|
536
|
+
name: 'approve',
|
|
537
|
+
stateMutability: 'nonpayable',
|
|
538
|
+
inputs: [{
|
|
539
|
+
name: 'spender',
|
|
540
|
+
type: 'address'
|
|
541
|
+
}, {
|
|
542
|
+
name: 'amount',
|
|
543
|
+
type: 'uint256'
|
|
544
|
+
}],
|
|
545
|
+
outputs: [{
|
|
546
|
+
name: '',
|
|
547
|
+
type: 'bool'
|
|
548
|
+
}]
|
|
549
|
+
}, {
|
|
550
|
+
type: 'function',
|
|
551
|
+
name: 'balanceOf',
|
|
552
|
+
stateMutability: 'view',
|
|
553
|
+
inputs: [{
|
|
554
|
+
name: 'account',
|
|
555
|
+
type: 'address'
|
|
556
|
+
}],
|
|
557
|
+
outputs: [{
|
|
558
|
+
name: '',
|
|
559
|
+
type: 'uint256'
|
|
560
|
+
}]
|
|
561
|
+
}, {
|
|
562
|
+
type: 'function',
|
|
563
|
+
name: 'decimals',
|
|
564
|
+
stateMutability: 'view',
|
|
565
|
+
inputs: [],
|
|
566
|
+
outputs: [{
|
|
567
|
+
name: '',
|
|
568
|
+
type: 'uint8'
|
|
569
|
+
}]
|
|
570
|
+
}, {
|
|
571
|
+
type: 'function',
|
|
572
|
+
name: 'name',
|
|
573
|
+
stateMutability: 'view',
|
|
574
|
+
inputs: [],
|
|
575
|
+
outputs: [{
|
|
576
|
+
name: '',
|
|
577
|
+
type: 'bytes32'
|
|
578
|
+
}]
|
|
579
|
+
}, {
|
|
580
|
+
type: 'function',
|
|
581
|
+
name: 'symbol',
|
|
582
|
+
stateMutability: 'view',
|
|
583
|
+
inputs: [],
|
|
584
|
+
outputs: [{
|
|
585
|
+
name: '',
|
|
586
|
+
type: 'bytes32'
|
|
587
|
+
}]
|
|
588
|
+
}, {
|
|
589
|
+
type: 'function',
|
|
590
|
+
name: 'totalSupply',
|
|
591
|
+
stateMutability: 'view',
|
|
592
|
+
inputs: [],
|
|
593
|
+
outputs: [{
|
|
594
|
+
name: '',
|
|
595
|
+
type: 'uint256'
|
|
596
|
+
}]
|
|
597
|
+
}, {
|
|
598
|
+
type: 'function',
|
|
599
|
+
name: 'transfer',
|
|
600
|
+
stateMutability: 'nonpayable',
|
|
601
|
+
inputs: [{
|
|
602
|
+
name: 'recipient',
|
|
603
|
+
type: 'address'
|
|
604
|
+
}, {
|
|
605
|
+
name: 'amount',
|
|
606
|
+
type: 'uint256'
|
|
607
|
+
}],
|
|
608
|
+
outputs: [{
|
|
609
|
+
name: '',
|
|
610
|
+
type: 'bool'
|
|
611
|
+
}]
|
|
612
|
+
}, {
|
|
613
|
+
type: 'function',
|
|
614
|
+
name: 'transferFrom',
|
|
615
|
+
stateMutability: 'nonpayable',
|
|
616
|
+
inputs: [{
|
|
617
|
+
name: 'sender',
|
|
618
|
+
type: 'address'
|
|
619
|
+
}, {
|
|
620
|
+
name: 'recipient',
|
|
621
|
+
type: 'address'
|
|
622
|
+
}, {
|
|
623
|
+
name: 'amount',
|
|
624
|
+
type: 'uint256'
|
|
625
|
+
}],
|
|
626
|
+
outputs: [{
|
|
627
|
+
name: '',
|
|
628
|
+
type: 'bool'
|
|
629
|
+
}]
|
|
630
|
+
}];
|
|
631
|
+
/**
|
|
632
|
+
* [ERC-721 Non-Fungible Token Standard](https://ethereum.org/en/developers/docs/standards/tokens/erc-721)
|
|
633
|
+
*/
|
|
226
634
|
|
|
227
|
-
const
|
|
635
|
+
const erc721ABI = [{
|
|
636
|
+
type: 'event',
|
|
637
|
+
name: 'Approval',
|
|
638
|
+
inputs: [{
|
|
639
|
+
indexed: true,
|
|
640
|
+
name: 'owner',
|
|
641
|
+
type: 'address'
|
|
642
|
+
}, {
|
|
643
|
+
indexed: true,
|
|
644
|
+
name: 'spender',
|
|
645
|
+
type: 'address'
|
|
646
|
+
}, {
|
|
647
|
+
indexed: true,
|
|
648
|
+
name: 'tokenId',
|
|
649
|
+
type: 'uint256'
|
|
650
|
+
}]
|
|
651
|
+
}, {
|
|
652
|
+
type: 'event',
|
|
653
|
+
name: 'ApprovalForAll',
|
|
654
|
+
inputs: [{
|
|
655
|
+
indexed: true,
|
|
656
|
+
name: 'owner',
|
|
657
|
+
type: 'address'
|
|
658
|
+
}, {
|
|
659
|
+
indexed: true,
|
|
660
|
+
name: 'operator',
|
|
661
|
+
type: 'address'
|
|
662
|
+
}, {
|
|
663
|
+
indexed: false,
|
|
664
|
+
name: 'approved',
|
|
665
|
+
type: 'bool'
|
|
666
|
+
}]
|
|
667
|
+
}, {
|
|
668
|
+
type: 'event',
|
|
669
|
+
name: 'Transfer',
|
|
670
|
+
inputs: [{
|
|
671
|
+
indexed: true,
|
|
672
|
+
name: 'from',
|
|
673
|
+
type: 'address'
|
|
674
|
+
}, {
|
|
675
|
+
indexed: true,
|
|
676
|
+
name: 'to',
|
|
677
|
+
type: 'address'
|
|
678
|
+
}, {
|
|
679
|
+
indexed: true,
|
|
680
|
+
name: 'tokenId',
|
|
681
|
+
type: 'uint256'
|
|
682
|
+
}]
|
|
683
|
+
}, {
|
|
684
|
+
type: 'function',
|
|
685
|
+
name: 'approve',
|
|
686
|
+
stateMutability: 'payable',
|
|
687
|
+
inputs: [{
|
|
688
|
+
name: 'spender',
|
|
689
|
+
type: 'address'
|
|
690
|
+
}, {
|
|
691
|
+
name: 'tokenId',
|
|
692
|
+
type: 'uint256'
|
|
693
|
+
}],
|
|
694
|
+
outputs: []
|
|
695
|
+
}, {
|
|
696
|
+
type: 'function',
|
|
697
|
+
name: 'balanceOf',
|
|
698
|
+
stateMutability: 'view',
|
|
699
|
+
inputs: [{
|
|
700
|
+
name: 'account',
|
|
701
|
+
type: 'address'
|
|
702
|
+
}],
|
|
703
|
+
outputs: [{
|
|
704
|
+
name: '',
|
|
705
|
+
type: 'uint256'
|
|
706
|
+
}]
|
|
707
|
+
}, {
|
|
708
|
+
type: 'function',
|
|
709
|
+
name: 'getApproved',
|
|
710
|
+
stateMutability: 'view',
|
|
711
|
+
inputs: [{
|
|
712
|
+
name: 'tokenId',
|
|
713
|
+
type: 'uint256'
|
|
714
|
+
}],
|
|
715
|
+
outputs: [{
|
|
716
|
+
name: '',
|
|
717
|
+
type: 'address'
|
|
718
|
+
}]
|
|
719
|
+
}, {
|
|
720
|
+
type: 'function',
|
|
721
|
+
name: 'isApprovedForAll',
|
|
722
|
+
stateMutability: 'view',
|
|
723
|
+
inputs: [{
|
|
724
|
+
name: 'owner',
|
|
725
|
+
type: 'address'
|
|
726
|
+
}, {
|
|
727
|
+
name: 'operator',
|
|
728
|
+
type: 'address'
|
|
729
|
+
}],
|
|
730
|
+
outputs: [{
|
|
731
|
+
name: '',
|
|
732
|
+
type: 'bool'
|
|
733
|
+
}]
|
|
734
|
+
}, {
|
|
735
|
+
type: 'function',
|
|
736
|
+
name: 'name',
|
|
737
|
+
stateMutability: 'view',
|
|
738
|
+
inputs: [],
|
|
739
|
+
outputs: [{
|
|
740
|
+
name: '',
|
|
741
|
+
type: 'string'
|
|
742
|
+
}]
|
|
743
|
+
}, {
|
|
744
|
+
type: 'function',
|
|
745
|
+
name: 'ownerOf',
|
|
746
|
+
stateMutability: 'view',
|
|
747
|
+
inputs: [{
|
|
748
|
+
name: 'tokenId',
|
|
749
|
+
type: 'uint256'
|
|
750
|
+
}],
|
|
751
|
+
outputs: [{
|
|
752
|
+
name: 'owner',
|
|
753
|
+
type: 'address'
|
|
754
|
+
}]
|
|
755
|
+
}, {
|
|
756
|
+
type: 'function',
|
|
757
|
+
name: 'safeTransferFrom',
|
|
758
|
+
stateMutability: 'payable',
|
|
759
|
+
inputs: [{
|
|
760
|
+
name: 'from',
|
|
761
|
+
type: 'address'
|
|
762
|
+
}, {
|
|
763
|
+
name: 'to',
|
|
764
|
+
type: 'address'
|
|
765
|
+
}, {
|
|
766
|
+
name: 'tokenId',
|
|
767
|
+
type: 'uint256'
|
|
768
|
+
}],
|
|
769
|
+
outputs: []
|
|
770
|
+
}, {
|
|
771
|
+
type: 'function',
|
|
772
|
+
name: 'safeTransferFrom',
|
|
773
|
+
stateMutability: 'nonpayable',
|
|
774
|
+
inputs: [{
|
|
775
|
+
name: 'from',
|
|
776
|
+
type: 'address'
|
|
777
|
+
}, {
|
|
778
|
+
name: 'to',
|
|
779
|
+
type: 'address'
|
|
780
|
+
}, {
|
|
781
|
+
name: 'id',
|
|
782
|
+
type: 'uint256'
|
|
783
|
+
}, {
|
|
784
|
+
name: 'data',
|
|
785
|
+
type: 'bytes'
|
|
786
|
+
}],
|
|
787
|
+
outputs: []
|
|
788
|
+
}, {
|
|
789
|
+
type: 'function',
|
|
790
|
+
name: 'setApprovalForAll',
|
|
791
|
+
stateMutability: 'nonpayable',
|
|
792
|
+
inputs: [{
|
|
793
|
+
name: 'operator',
|
|
794
|
+
type: 'address'
|
|
795
|
+
}, {
|
|
796
|
+
name: 'approved',
|
|
797
|
+
type: 'bool'
|
|
798
|
+
}],
|
|
799
|
+
outputs: []
|
|
800
|
+
}, {
|
|
801
|
+
type: 'function',
|
|
802
|
+
name: 'symbol',
|
|
803
|
+
stateMutability: 'view',
|
|
804
|
+
inputs: [],
|
|
805
|
+
outputs: [{
|
|
806
|
+
name: '',
|
|
807
|
+
type: 'string'
|
|
808
|
+
}]
|
|
809
|
+
}, {
|
|
810
|
+
type: 'function',
|
|
811
|
+
name: 'tokenByIndex',
|
|
812
|
+
stateMutability: 'view',
|
|
813
|
+
inputs: [{
|
|
814
|
+
name: 'index',
|
|
815
|
+
type: 'uint256'
|
|
816
|
+
}],
|
|
817
|
+
outputs: [{
|
|
818
|
+
name: '',
|
|
819
|
+
type: 'uint256'
|
|
820
|
+
}]
|
|
821
|
+
}, {
|
|
822
|
+
type: 'function',
|
|
823
|
+
name: 'tokenByIndex',
|
|
824
|
+
stateMutability: 'view',
|
|
825
|
+
inputs: [{
|
|
826
|
+
name: 'owner',
|
|
827
|
+
type: 'address'
|
|
828
|
+
}, {
|
|
829
|
+
name: 'index',
|
|
830
|
+
type: 'uint256'
|
|
831
|
+
}],
|
|
832
|
+
outputs: [{
|
|
833
|
+
name: 'tokenId',
|
|
834
|
+
type: 'uint256'
|
|
835
|
+
}]
|
|
836
|
+
}, {
|
|
837
|
+
type: 'function',
|
|
838
|
+
name: 'tokenURI',
|
|
839
|
+
stateMutability: 'view',
|
|
840
|
+
inputs: [{
|
|
841
|
+
name: 'tokenId',
|
|
842
|
+
type: 'uint256'
|
|
843
|
+
}],
|
|
844
|
+
outputs: [{
|
|
845
|
+
name: '',
|
|
846
|
+
type: 'string'
|
|
847
|
+
}]
|
|
848
|
+
}, {
|
|
849
|
+
type: 'function',
|
|
850
|
+
name: 'totalSupply',
|
|
851
|
+
stateMutability: 'view',
|
|
852
|
+
inputs: [],
|
|
853
|
+
outputs: [{
|
|
854
|
+
name: '',
|
|
855
|
+
type: 'uint256'
|
|
856
|
+
}]
|
|
857
|
+
}, {
|
|
858
|
+
type: 'function',
|
|
859
|
+
name: 'transferFrom',
|
|
860
|
+
stateMutability: 'payable',
|
|
861
|
+
inputs: [{
|
|
862
|
+
name: 'sender',
|
|
863
|
+
type: 'address'
|
|
864
|
+
}, {
|
|
865
|
+
name: 'recipient',
|
|
866
|
+
type: 'address'
|
|
867
|
+
}, {
|
|
868
|
+
name: 'tokeId',
|
|
869
|
+
type: 'uint256'
|
|
870
|
+
}],
|
|
871
|
+
outputs: []
|
|
872
|
+
}];
|
|
873
|
+
/**
|
|
874
|
+
* [Multicall3](https://github.com/mds1/multicall)
|
|
875
|
+
*/
|
|
876
|
+
|
|
877
|
+
const multicallABI = [{
|
|
228
878
|
inputs: [{
|
|
229
879
|
components: [{
|
|
230
|
-
internalType: 'address',
|
|
231
880
|
name: 'target',
|
|
232
881
|
type: 'address'
|
|
233
882
|
}, {
|
|
234
|
-
internalType: 'bool',
|
|
235
883
|
name: 'allowFailure',
|
|
236
884
|
type: 'bool'
|
|
237
885
|
}, {
|
|
238
|
-
internalType: 'bytes',
|
|
239
886
|
name: 'callData',
|
|
240
887
|
type: 'bytes'
|
|
241
888
|
}],
|
|
242
|
-
internalType: 'struct Multicall3.Call3[]',
|
|
243
889
|
name: 'calls',
|
|
244
890
|
type: 'tuple[]'
|
|
245
891
|
}],
|
|
246
892
|
name: 'aggregate3',
|
|
247
893
|
outputs: [{
|
|
248
894
|
components: [{
|
|
249
|
-
internalType: 'bool',
|
|
250
895
|
name: 'success',
|
|
251
896
|
type: 'bool'
|
|
252
897
|
}, {
|
|
253
|
-
internalType: 'bytes',
|
|
254
898
|
name: 'returnData',
|
|
255
899
|
type: 'bytes'
|
|
256
900
|
}],
|
|
257
|
-
internalType: 'struct Multicall3.Result[]',
|
|
258
901
|
name: 'returnData',
|
|
259
902
|
type: 'tuple[]'
|
|
260
903
|
}],
|
|
@@ -310,101 +953,85 @@ async function disconnect() {
|
|
|
310
953
|
client.storage.removeItem('connected');
|
|
311
954
|
}
|
|
312
955
|
|
|
313
|
-
function
|
|
314
|
-
let {
|
|
315
|
-
addressOrName,
|
|
316
|
-
contractInterface,
|
|
317
|
-
signerOrProvider
|
|
318
|
-
} = _ref;
|
|
319
|
-
return new ethers.Contract(addressOrName, contractInterface, signerOrProvider);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
async function deprecatedWriteContract(_ref) {
|
|
956
|
+
async function fetchToken(_ref) {
|
|
323
957
|
let {
|
|
324
|
-
|
|
325
|
-
args,
|
|
958
|
+
address,
|
|
326
959
|
chainId,
|
|
327
|
-
|
|
328
|
-
functionName,
|
|
329
|
-
overrides,
|
|
330
|
-
signerOrProvider
|
|
960
|
+
formatUnits: units = 'ether'
|
|
331
961
|
} = _ref;
|
|
332
|
-
const {
|
|
333
|
-
connector
|
|
334
|
-
} = getProvider.getClient();
|
|
335
|
-
if (!connector) throw new getProvider.ConnectorNotFoundError();
|
|
336
|
-
const params = [...(Array.isArray(args) ? args : args ? [args] : []), ...(overrides ? [overrides] : [])];
|
|
337
|
-
|
|
338
|
-
try {
|
|
339
|
-
var _chain;
|
|
340
|
-
|
|
341
|
-
let chain;
|
|
342
962
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
963
|
+
async function fetchToken_(_ref2) {
|
|
964
|
+
let {
|
|
965
|
+
abi
|
|
966
|
+
} = _ref2;
|
|
967
|
+
const erc20Config = {
|
|
968
|
+
address,
|
|
969
|
+
abi,
|
|
970
|
+
chainId
|
|
971
|
+
};
|
|
972
|
+
const [decimals, name, symbol, totalSupply] = await readContracts({
|
|
973
|
+
allowFailure: false,
|
|
974
|
+
contracts: [{ ...erc20Config,
|
|
975
|
+
functionName: 'decimals'
|
|
976
|
+
}, { ...erc20Config,
|
|
977
|
+
functionName: 'name'
|
|
978
|
+
}, { ...erc20Config,
|
|
979
|
+
functionName: 'symbol'
|
|
980
|
+
}, { ...erc20Config,
|
|
981
|
+
functionName: 'totalSupply'
|
|
982
|
+
}]
|
|
983
|
+
});
|
|
984
|
+
return {
|
|
985
|
+
address,
|
|
986
|
+
decimals,
|
|
987
|
+
name: name,
|
|
988
|
+
// protect against `ResolvedConfig['BytesType']`
|
|
989
|
+
symbol: symbol,
|
|
990
|
+
// protect against `ResolvedConfig['BytesType']`
|
|
991
|
+
totalSupply: {
|
|
992
|
+
formatted: utils.formatUnits(totalSupply, units),
|
|
993
|
+
value: totalSupply
|
|
353
994
|
}
|
|
354
|
-
}
|
|
995
|
+
};
|
|
996
|
+
}
|
|
355
997
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
const contract = getContract({
|
|
360
|
-
addressOrName,
|
|
361
|
-
contractInterface,
|
|
362
|
-
signerOrProvider
|
|
998
|
+
try {
|
|
999
|
+
return await fetchToken_({
|
|
1000
|
+
abi: erc20ABI
|
|
363
1001
|
});
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
1002
|
+
} catch (err) {
|
|
1003
|
+
// In the chance that there is an error upon decoding the contract result,
|
|
1004
|
+
// it could be likely that the contract data is represented as bytes32 instead
|
|
1005
|
+
// of a string.
|
|
1006
|
+
if (err instanceof getProvider.ContractResultDecodeError) {
|
|
1007
|
+
const {
|
|
1008
|
+
name,
|
|
1009
|
+
symbol,
|
|
1010
|
+
...rest
|
|
1011
|
+
} = await fetchToken_({
|
|
1012
|
+
abi: erc20ABI_bytes32
|
|
1013
|
+
});
|
|
1014
|
+
return {
|
|
1015
|
+
name: utils.parseBytes32String(name),
|
|
1016
|
+
symbol: utils.parseBytes32String(symbol),
|
|
1017
|
+
...rest
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
throw err;
|
|
371
1022
|
}
|
|
372
1023
|
}
|
|
373
1024
|
|
|
374
|
-
|
|
1025
|
+
function getContract(_ref) {
|
|
375
1026
|
let {
|
|
376
1027
|
address,
|
|
377
|
-
|
|
378
|
-
|
|
1028
|
+
abi,
|
|
1029
|
+
signerOrProvider
|
|
379
1030
|
} = _ref;
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
};
|
|
385
|
-
const [decimals, name, symbol, totalSupply] = await readContracts({
|
|
386
|
-
allowFailure: false,
|
|
387
|
-
contracts: [{ ...erc20Config,
|
|
388
|
-
functionName: 'decimals'
|
|
389
|
-
}, { ...erc20Config,
|
|
390
|
-
functionName: 'name'
|
|
391
|
-
}, { ...erc20Config,
|
|
392
|
-
functionName: 'symbol'
|
|
393
|
-
}, { ...erc20Config,
|
|
394
|
-
functionName: 'totalSupply'
|
|
395
|
-
}]
|
|
396
|
-
});
|
|
397
|
-
return {
|
|
398
|
-
address,
|
|
399
|
-
decimals,
|
|
400
|
-
name,
|
|
401
|
-
symbol,
|
|
402
|
-
totalSupply: {
|
|
403
|
-
formatted: utils.formatUnits(totalSupply, units),
|
|
404
|
-
value: totalSupply
|
|
405
|
-
}
|
|
406
|
-
};
|
|
407
|
-
}
|
|
1031
|
+
return new ethers.Contract(address, abi, signerOrProvider);
|
|
1032
|
+
} ////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
1033
|
+
// Contract
|
|
1034
|
+
// TODO: Add remaining properties
|
|
408
1035
|
|
|
409
1036
|
/**
|
|
410
1037
|
* @description Prepares the parameters required for a contract write transaction.
|
|
@@ -415,58 +1042,63 @@ async function fetchToken(_ref) {
|
|
|
415
1042
|
* import { prepareWriteContract, writeContract } from '@wagmi/core'
|
|
416
1043
|
*
|
|
417
1044
|
* const config = await prepareWriteContract({
|
|
418
|
-
*
|
|
419
|
-
*
|
|
1045
|
+
* address: '0x...',
|
|
1046
|
+
* abi: wagmiAbi,
|
|
420
1047
|
* functionName: 'mint',
|
|
421
1048
|
* })
|
|
422
1049
|
* const result = await writeContract(config)
|
|
423
1050
|
*/
|
|
424
1051
|
async function prepareWriteContract(_ref) {
|
|
425
1052
|
let {
|
|
426
|
-
|
|
1053
|
+
abi,
|
|
1054
|
+
address,
|
|
427
1055
|
args,
|
|
428
1056
|
chainId,
|
|
429
|
-
contractInterface: contractInterface_,
|
|
430
1057
|
functionName,
|
|
431
1058
|
overrides,
|
|
432
1059
|
signer: signer_
|
|
433
1060
|
} = _ref;
|
|
434
|
-
const signer = signer_
|
|
1061
|
+
const signer = signer_ ?? (await fetchSigner({
|
|
1062
|
+
chainId
|
|
1063
|
+
}));
|
|
435
1064
|
if (!signer) throw new getProvider.ConnectorNotFoundError();
|
|
1065
|
+
if (chainId) assertActiveChain({
|
|
1066
|
+
chainId
|
|
1067
|
+
});
|
|
436
1068
|
const contract = getContract({
|
|
437
|
-
|
|
438
|
-
|
|
1069
|
+
address,
|
|
1070
|
+
abi: abi,
|
|
1071
|
+
// TODO: Remove cast and still support `Narrow<TAbi>`
|
|
439
1072
|
signerOrProvider: signer
|
|
440
1073
|
});
|
|
441
|
-
const
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
const contractInterface = minimizeContractInterface({
|
|
451
|
-
contractInterface: contract.interface,
|
|
452
|
-
functionName
|
|
1074
|
+
const normalizedFunctionName = normalizeFunctionName({
|
|
1075
|
+
contract,
|
|
1076
|
+
functionName,
|
|
1077
|
+
args
|
|
1078
|
+
});
|
|
1079
|
+
const populateTransactionFn = contract.populateTransaction[normalizedFunctionName];
|
|
1080
|
+
if (!populateTransactionFn) throw new getProvider.ContractMethodDoesNotExistError({
|
|
1081
|
+
address,
|
|
1082
|
+
functionName: normalizedFunctionName
|
|
453
1083
|
});
|
|
454
|
-
const params = [...(
|
|
1084
|
+
const params = [...(args ?? []), ...(overrides ? [overrides] : [])];
|
|
455
1085
|
const unsignedTransaction = await populateTransactionFn(...params);
|
|
456
1086
|
const gasLimit = unsignedTransaction.gasLimit || (await signer.estimateGas(unsignedTransaction));
|
|
1087
|
+
const minimizedAbi = minimizeContractInterface({
|
|
1088
|
+
abi: abi,
|
|
1089
|
+
// TODO: Remove cast and still support `Narrow<TAbi>`
|
|
1090
|
+
functionName
|
|
1091
|
+
});
|
|
457
1092
|
return {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
functionName,
|
|
465
|
-
overrides,
|
|
1093
|
+
abi: minimizedAbi,
|
|
1094
|
+
address,
|
|
1095
|
+
chainId,
|
|
1096
|
+
// TODO: Remove cast
|
|
1097
|
+
functionName: functionName,
|
|
1098
|
+
mode: 'prepared',
|
|
466
1099
|
request: { ...unsignedTransaction,
|
|
467
1100
|
gasLimit
|
|
468
|
-
}
|
|
469
|
-
mode: 'prepared'
|
|
1101
|
+
}
|
|
470
1102
|
};
|
|
471
1103
|
}
|
|
472
1104
|
|
|
@@ -509,30 +1141,6 @@ function watchWebSocketProvider(args, callback) {
|
|
|
509
1141
|
return unsubscribe;
|
|
510
1142
|
}
|
|
511
1143
|
|
|
512
|
-
async function readContract(_ref) {
|
|
513
|
-
let {
|
|
514
|
-
addressOrName,
|
|
515
|
-
args,
|
|
516
|
-
chainId,
|
|
517
|
-
contractInterface,
|
|
518
|
-
functionName,
|
|
519
|
-
overrides
|
|
520
|
-
} = _ref;
|
|
521
|
-
const provider = getProvider.getProvider({
|
|
522
|
-
chainId
|
|
523
|
-
});
|
|
524
|
-
const contract = getContract({
|
|
525
|
-
addressOrName,
|
|
526
|
-
contractInterface,
|
|
527
|
-
signerOrProvider: provider
|
|
528
|
-
});
|
|
529
|
-
const params = [...(Array.isArray(args) ? args : args ? [args] : []), ...(overrides ? [overrides] : [])];
|
|
530
|
-
const contractFunction = contract[functionName];
|
|
531
|
-
if (!contractFunction) logWarn("\"".concat(functionName, "\" is not in the interface for contract \"").concat(addressOrName, "\""));
|
|
532
|
-
const response = await (contractFunction === null || contractFunction === void 0 ? void 0 : contractFunction(...params));
|
|
533
|
-
return response;
|
|
534
|
-
}
|
|
535
|
-
|
|
536
1144
|
async function multicall(_ref) {
|
|
537
1145
|
let {
|
|
538
1146
|
allowFailure = true,
|
|
@@ -554,14 +1162,14 @@ async function multicall(_ref) {
|
|
|
554
1162
|
chain
|
|
555
1163
|
});
|
|
556
1164
|
const multicallContract = getContract({
|
|
557
|
-
|
|
558
|
-
|
|
1165
|
+
address: chain.multicall.address,
|
|
1166
|
+
abi: multicallABI,
|
|
559
1167
|
signerOrProvider: provider
|
|
560
1168
|
});
|
|
561
1169
|
const calls = contracts.map(_ref2 => {
|
|
562
1170
|
let {
|
|
563
|
-
|
|
564
|
-
|
|
1171
|
+
address,
|
|
1172
|
+
abi,
|
|
565
1173
|
functionName,
|
|
566
1174
|
...config
|
|
567
1175
|
} = _ref2;
|
|
@@ -569,57 +1177,71 @@ async function multicall(_ref) {
|
|
|
569
1177
|
args
|
|
570
1178
|
} = config || {};
|
|
571
1179
|
const contract = getContract({
|
|
572
|
-
|
|
573
|
-
|
|
1180
|
+
address,
|
|
1181
|
+
abi
|
|
1182
|
+
});
|
|
1183
|
+
const params = args ?? [];
|
|
1184
|
+
const normalizedFunctionName = normalizeFunctionName({
|
|
1185
|
+
contract,
|
|
1186
|
+
functionName,
|
|
1187
|
+
args
|
|
574
1188
|
});
|
|
575
|
-
const params = Array.isArray(args) ? args : args ? [args] : [];
|
|
576
1189
|
|
|
577
1190
|
try {
|
|
578
|
-
const
|
|
579
|
-
if (!
|
|
1191
|
+
const contractFunction = contract[normalizedFunctionName];
|
|
1192
|
+
if (!contractFunction) logWarn(`"${normalizedFunctionName}" is not in the interface for contract "${address}"`);
|
|
1193
|
+
const callData = contract.interface.encodeFunctionData(normalizedFunctionName, params);
|
|
580
1194
|
return {
|
|
581
|
-
target:
|
|
1195
|
+
target: address,
|
|
582
1196
|
allowFailure,
|
|
583
1197
|
callData
|
|
584
1198
|
};
|
|
585
1199
|
} catch (err) {
|
|
586
1200
|
if (!allowFailure) throw err;
|
|
587
1201
|
return {
|
|
588
|
-
target:
|
|
1202
|
+
target: address,
|
|
589
1203
|
allowFailure,
|
|
590
1204
|
callData: '0x'
|
|
591
1205
|
};
|
|
592
1206
|
}
|
|
593
1207
|
});
|
|
594
1208
|
const params = [...[calls], ...(overrides ? [overrides] : [])];
|
|
595
|
-
const results = await multicallContract.aggregate3(
|
|
1209
|
+
const results = await multicallContract.aggregate3( // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1210
|
+
// @ts-ignore
|
|
1211
|
+
...params);
|
|
596
1212
|
return results.map((_ref3, i) => {
|
|
597
1213
|
let {
|
|
598
1214
|
returnData,
|
|
599
1215
|
success
|
|
600
1216
|
} = _ref3;
|
|
601
1217
|
const {
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
1218
|
+
address,
|
|
1219
|
+
abi,
|
|
1220
|
+
args,
|
|
1221
|
+
functionName
|
|
606
1222
|
} = contracts[i];
|
|
607
1223
|
const contract = getContract({
|
|
608
|
-
|
|
609
|
-
|
|
1224
|
+
address,
|
|
1225
|
+
abi: abi // TODO: Remove cast and still support `Narrow<TAbi>`
|
|
1226
|
+
|
|
1227
|
+
});
|
|
1228
|
+
const normalizedFunctionName = normalizeFunctionName({
|
|
1229
|
+
contract,
|
|
1230
|
+
functionName,
|
|
1231
|
+
args
|
|
610
1232
|
});
|
|
611
1233
|
|
|
612
1234
|
if (!success) {
|
|
613
1235
|
let error;
|
|
614
1236
|
|
|
615
1237
|
try {
|
|
616
|
-
contract.interface.decodeFunctionResult(
|
|
1238
|
+
contract.interface.decodeFunctionResult(normalizedFunctionName, returnData);
|
|
617
1239
|
} catch (err) {
|
|
618
1240
|
error = new getProvider.ContractMethodRevertedError({
|
|
619
|
-
|
|
1241
|
+
address,
|
|
620
1242
|
args,
|
|
621
1243
|
chainId: chain.id,
|
|
622
|
-
functionName,
|
|
1244
|
+
functionName: normalizedFunctionName,
|
|
623
1245
|
errorMessage: err.message
|
|
624
1246
|
});
|
|
625
1247
|
if (!allowFailure) throw error;
|
|
@@ -631,10 +1253,10 @@ async function multicall(_ref) {
|
|
|
631
1253
|
|
|
632
1254
|
if (returnData === '0x') {
|
|
633
1255
|
const error = new getProvider.ContractMethodNoResultError({
|
|
634
|
-
|
|
1256
|
+
address,
|
|
635
1257
|
args,
|
|
636
1258
|
chainId: chain.id,
|
|
637
|
-
functionName
|
|
1259
|
+
functionName: normalizedFunctionName
|
|
638
1260
|
});
|
|
639
1261
|
if (!allowFailure) throw error;
|
|
640
1262
|
logWarn(error.message);
|
|
@@ -642,14 +1264,14 @@ async function multicall(_ref) {
|
|
|
642
1264
|
}
|
|
643
1265
|
|
|
644
1266
|
try {
|
|
645
|
-
const result = contract.interface.decodeFunctionResult(
|
|
1267
|
+
const result = contract.interface.decodeFunctionResult(normalizedFunctionName, returnData);
|
|
646
1268
|
return Array.isArray(result) && result.length === 1 ? result[0] : result;
|
|
647
1269
|
} catch (err) {
|
|
648
1270
|
const error = new getProvider.ContractResultDecodeError({
|
|
649
|
-
|
|
1271
|
+
address,
|
|
650
1272
|
args,
|
|
651
1273
|
chainId: chain.id,
|
|
652
|
-
functionName,
|
|
1274
|
+
functionName: normalizedFunctionName,
|
|
653
1275
|
errorMessage: err.message
|
|
654
1276
|
});
|
|
655
1277
|
if (!allowFailure) throw error;
|
|
@@ -659,6 +1281,38 @@ async function multicall(_ref) {
|
|
|
659
1281
|
});
|
|
660
1282
|
}
|
|
661
1283
|
|
|
1284
|
+
async function readContract(_ref) {
|
|
1285
|
+
let {
|
|
1286
|
+
address,
|
|
1287
|
+
args,
|
|
1288
|
+
chainId,
|
|
1289
|
+
abi,
|
|
1290
|
+
functionName,
|
|
1291
|
+
overrides
|
|
1292
|
+
} = _ref;
|
|
1293
|
+
const provider = getProvider.getProvider({
|
|
1294
|
+
chainId
|
|
1295
|
+
});
|
|
1296
|
+
const contract = getContract({
|
|
1297
|
+
address,
|
|
1298
|
+
abi: abi,
|
|
1299
|
+
// TODO: Remove cast and still support `Narrow<TAbi>`
|
|
1300
|
+
signerOrProvider: provider
|
|
1301
|
+
});
|
|
1302
|
+
const normalizedFunctionName = normalizeFunctionName({
|
|
1303
|
+
contract,
|
|
1304
|
+
functionName,
|
|
1305
|
+
args
|
|
1306
|
+
});
|
|
1307
|
+
const contractFunction = contract[normalizedFunctionName];
|
|
1308
|
+
if (!contractFunction) throw new getProvider.ContractMethodDoesNotExistError({
|
|
1309
|
+
address,
|
|
1310
|
+
functionName: normalizedFunctionName
|
|
1311
|
+
});
|
|
1312
|
+
const params = [...(args ?? []), ...(overrides ? [overrides] : [])];
|
|
1313
|
+
return contractFunction === null || contractFunction === void 0 ? void 0 : contractFunction(...params);
|
|
1314
|
+
}
|
|
1315
|
+
|
|
662
1316
|
async function readContracts(_ref) {
|
|
663
1317
|
let {
|
|
664
1318
|
allowFailure = true,
|
|
@@ -668,12 +1322,13 @@ async function readContracts(_ref) {
|
|
|
668
1322
|
|
|
669
1323
|
try {
|
|
670
1324
|
const provider = getProvider.getProvider();
|
|
671
|
-
const contractsByChainId = contracts.reduce((contracts, contract) => {
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
const chainId = (_contract$chainId = contract.chainId) !== null && _contract$chainId !== void 0 ? _contract$chainId : provider.network.chainId;
|
|
1325
|
+
const contractsByChainId = contracts.reduce((contracts, contract, index) => {
|
|
1326
|
+
const chainId = contract.chainId ?? provider.network.chainId;
|
|
675
1327
|
return { ...contracts,
|
|
676
|
-
[chainId]: [...(contracts[chainId] || []),
|
|
1328
|
+
[chainId]: [...(contracts[chainId] || []), {
|
|
1329
|
+
contract,
|
|
1330
|
+
index
|
|
1331
|
+
}]
|
|
677
1332
|
};
|
|
678
1333
|
}, {});
|
|
679
1334
|
|
|
@@ -682,13 +1337,20 @@ async function readContracts(_ref) {
|
|
|
682
1337
|
return multicall({
|
|
683
1338
|
allowFailure,
|
|
684
1339
|
chainId: parseInt(chainId),
|
|
685
|
-
contracts
|
|
1340
|
+
contracts: contracts.map(_ref3 => {
|
|
1341
|
+
let {
|
|
1342
|
+
contract
|
|
1343
|
+
} = _ref3;
|
|
1344
|
+
return contract;
|
|
1345
|
+
}),
|
|
686
1346
|
overrides
|
|
687
1347
|
});
|
|
688
1348
|
});
|
|
689
1349
|
|
|
1350
|
+
let results;
|
|
1351
|
+
|
|
690
1352
|
if (allowFailure) {
|
|
691
|
-
|
|
1353
|
+
results = (await Promise.allSettled(promises())).map(result => {
|
|
692
1354
|
if (result.status === 'fulfilled') return result.value;
|
|
693
1355
|
|
|
694
1356
|
if (result.reason instanceof getProvider.ChainDoesNotSupportMulticallError) {
|
|
@@ -698,9 +1360,22 @@ async function readContracts(_ref) {
|
|
|
698
1360
|
|
|
699
1361
|
return null;
|
|
700
1362
|
}).flat();
|
|
701
|
-
}
|
|
1363
|
+
} else {
|
|
1364
|
+
results = (await Promise.all(promises())).flat();
|
|
1365
|
+
} // Reorder the contract results back to the order they were
|
|
1366
|
+
// provided in.
|
|
1367
|
+
|
|
702
1368
|
|
|
703
|
-
|
|
1369
|
+
const resultIndexes = Object.values(contractsByChainId).map(contracts => contracts.map(_ref4 => {
|
|
1370
|
+
let {
|
|
1371
|
+
index
|
|
1372
|
+
} = _ref4;
|
|
1373
|
+
return index;
|
|
1374
|
+
})).flat();
|
|
1375
|
+
return results.reduce((results, result, index) => {
|
|
1376
|
+
results[resultIndexes[index]] = result;
|
|
1377
|
+
return results;
|
|
1378
|
+
}, []);
|
|
704
1379
|
} catch (err) {
|
|
705
1380
|
if (err instanceof getProvider.ContractResultDecodeError) throw err;
|
|
706
1381
|
if (err instanceof getProvider.ContractMethodNoResultError) throw err;
|
|
@@ -710,67 +1385,68 @@ async function readContracts(_ref) {
|
|
|
710
1385
|
overrides
|
|
711
1386
|
}));
|
|
712
1387
|
|
|
713
|
-
if (allowFailure) {
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
errorMessage: result.reason
|
|
728
|
-
});
|
|
729
|
-
logWarn(error.message);
|
|
730
|
-
return null;
|
|
1388
|
+
if (allowFailure) return (await Promise.allSettled(promises())).map((result, i) => {
|
|
1389
|
+
if (result.status === 'fulfilled') return result.value;
|
|
1390
|
+
const {
|
|
1391
|
+
address,
|
|
1392
|
+
args,
|
|
1393
|
+
chainId,
|
|
1394
|
+
functionName
|
|
1395
|
+
} = contracts[i];
|
|
1396
|
+
const error = new getProvider.ContractMethodRevertedError({
|
|
1397
|
+
address,
|
|
1398
|
+
functionName,
|
|
1399
|
+
chainId: chainId ?? chains.mainnet.id,
|
|
1400
|
+
args,
|
|
1401
|
+
errorMessage: result.reason
|
|
731
1402
|
});
|
|
732
|
-
|
|
733
|
-
|
|
1403
|
+
logWarn(error.message);
|
|
1404
|
+
return null;
|
|
1405
|
+
});
|
|
734
1406
|
return await Promise.all(promises());
|
|
735
1407
|
}
|
|
736
1408
|
}
|
|
737
1409
|
|
|
738
|
-
function watchContractEvent(
|
|
739
|
-
/** Contract configuration */
|
|
740
|
-
contractArgs,
|
|
741
|
-
/** Event name to listen to */
|
|
742
|
-
eventName, callback) {
|
|
1410
|
+
function watchContractEvent(_ref, callback) {
|
|
743
1411
|
let {
|
|
1412
|
+
address,
|
|
1413
|
+
abi,
|
|
744
1414
|
chainId,
|
|
1415
|
+
eventName,
|
|
745
1416
|
once
|
|
746
|
-
} =
|
|
1417
|
+
} = _ref;
|
|
1418
|
+
|
|
1419
|
+
const handler = function () {
|
|
1420
|
+
return callback(...arguments);
|
|
1421
|
+
};
|
|
1422
|
+
|
|
747
1423
|
let contract;
|
|
748
1424
|
|
|
749
1425
|
const watchEvent = async () => {
|
|
750
|
-
|
|
751
|
-
var _contract;
|
|
752
|
-
|
|
753
|
-
(_contract = contract) === null || _contract === void 0 ? void 0 : _contract.off(eventName, callback);
|
|
754
|
-
}
|
|
1426
|
+
var _contract;
|
|
755
1427
|
|
|
1428
|
+
if (contract) (_contract = contract) === null || _contract === void 0 ? void 0 : _contract.off(eventName, handler);
|
|
1429
|
+
const signerOrProvider = getWebSocketProvider({
|
|
1430
|
+
chainId
|
|
1431
|
+
}) || getProvider.getProvider({
|
|
1432
|
+
chainId
|
|
1433
|
+
});
|
|
756
1434
|
contract = getContract({
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
}),
|
|
762
|
-
...contractArgs
|
|
1435
|
+
address,
|
|
1436
|
+
abi: abi,
|
|
1437
|
+
// TODO: Remove cast and still support `Narrow<TAbi>`
|
|
1438
|
+
signerOrProvider
|
|
763
1439
|
});
|
|
764
|
-
if (once) contract.once(eventName,
|
|
1440
|
+
if (once) contract.once(eventName, handler);else contract.on(eventName, handler);
|
|
765
1441
|
};
|
|
766
1442
|
|
|
767
1443
|
watchEvent();
|
|
768
1444
|
const client = getProvider.getClient();
|
|
769
|
-
const unsubscribe = client.subscribe(
|
|
1445
|
+
const unsubscribe = client.subscribe(_ref2 => {
|
|
770
1446
|
let {
|
|
771
1447
|
provider,
|
|
772
1448
|
webSocketProvider
|
|
773
|
-
} =
|
|
1449
|
+
} = _ref2;
|
|
774
1450
|
return {
|
|
775
1451
|
provider,
|
|
776
1452
|
webSocketProvider
|
|
@@ -781,7 +1457,7 @@ eventName, callback) {
|
|
|
781
1457
|
return () => {
|
|
782
1458
|
var _contract2;
|
|
783
1459
|
|
|
784
|
-
(_contract2 = contract) === null || _contract2 === void 0 ? void 0 : _contract2.off(eventName,
|
|
1460
|
+
(_contract2 = contract) === null || _contract2 === void 0 ? void 0 : _contract2.off(eventName, handler);
|
|
785
1461
|
unsubscribe();
|
|
786
1462
|
};
|
|
787
1463
|
}
|
|
@@ -798,18 +1474,15 @@ async function fetchBlockNumber() {
|
|
|
798
1474
|
}
|
|
799
1475
|
|
|
800
1476
|
function watchBlockNumber(args, callback) {
|
|
801
|
-
|
|
802
|
-
|
|
1477
|
+
// We need to debounce the listener as we want to opt-out
|
|
1478
|
+
// of the behavior where ethers emits a "block" event for
|
|
1479
|
+
// every block that was missed in between the `pollingInterval`.
|
|
1480
|
+
// We are setting a wait time of 1 as emitting an event in
|
|
1481
|
+
// ethers takes ~0.1ms.
|
|
1482
|
+
const debouncedCallback = debounce.debounce(callback, 1);
|
|
803
1483
|
let previousProvider;
|
|
804
1484
|
|
|
805
1485
|
const createListener = provider => {
|
|
806
|
-
// We need to debounce the listener as we want to opt-out
|
|
807
|
-
// of the behavior where ethers emits a "block" event for
|
|
808
|
-
// every block that was missed in between the `pollingInterval`.
|
|
809
|
-
// We are setting a wait time of 1 as emitting an event in
|
|
810
|
-
// ethers takes ~0.1ms.
|
|
811
|
-
const debouncedCallback = debounce.debounce(callback, 1);
|
|
812
|
-
|
|
813
1486
|
if (previousProvider) {
|
|
814
1487
|
var _previousProvider;
|
|
815
1488
|
|
|
@@ -820,9 +1493,14 @@ function watchBlockNumber(args, callback) {
|
|
|
820
1493
|
previousProvider = provider;
|
|
821
1494
|
};
|
|
822
1495
|
|
|
823
|
-
const
|
|
824
|
-
|
|
1496
|
+
const provider_ = getWebSocketProvider({
|
|
1497
|
+
chainId: args.chainId
|
|
1498
|
+
}) ?? getProvider.getProvider({
|
|
1499
|
+
chainId: args.chainId
|
|
1500
|
+
});
|
|
825
1501
|
if (args.listen) createListener(provider_);
|
|
1502
|
+
let active = true;
|
|
1503
|
+
const client = getProvider.getClient();
|
|
826
1504
|
const unsubscribe = client.subscribe(_ref => {
|
|
827
1505
|
let {
|
|
828
1506
|
provider,
|
|
@@ -837,26 +1515,34 @@ function watchBlockNumber(args, callback) {
|
|
|
837
1515
|
provider,
|
|
838
1516
|
webSocketProvider
|
|
839
1517
|
} = _ref2;
|
|
840
|
-
const provider_ = webSocketProvider
|
|
1518
|
+
const provider_ = webSocketProvider ?? provider;
|
|
841
1519
|
|
|
842
|
-
if (args.listen && provider_) {
|
|
1520
|
+
if (args.listen && !args.chainId && provider_) {
|
|
843
1521
|
createListener(provider_);
|
|
844
1522
|
}
|
|
845
1523
|
|
|
846
|
-
|
|
1524
|
+
const blockNumber = await fetchBlockNumber({
|
|
1525
|
+
chainId: args.chainId
|
|
1526
|
+
});
|
|
1527
|
+
if (!active) return;
|
|
1528
|
+
callback(blockNumber);
|
|
847
1529
|
}, {
|
|
848
1530
|
equalityFn: shallow__default["default"]
|
|
849
1531
|
});
|
|
850
1532
|
return () => {
|
|
1533
|
+
var _previousProvider2;
|
|
1534
|
+
|
|
1535
|
+
active = false;
|
|
851
1536
|
unsubscribe();
|
|
852
|
-
provider_ === null || provider_ === void 0 ? void 0 : provider_.off('block',
|
|
1537
|
+
provider_ === null || provider_ === void 0 ? void 0 : provider_.off('block', debouncedCallback);
|
|
1538
|
+
(_previousProvider2 = previousProvider) === null || _previousProvider2 === void 0 ? void 0 : _previousProvider2.off('block', debouncedCallback);
|
|
853
1539
|
};
|
|
854
1540
|
}
|
|
855
1541
|
|
|
856
|
-
function
|
|
1542
|
+
function watchMulticall(config, callback) {
|
|
857
1543
|
const client = getProvider.getClient();
|
|
858
1544
|
|
|
859
|
-
const handleChange = async () => callback(await
|
|
1545
|
+
const handleChange = async () => callback(await multicall(config));
|
|
860
1546
|
|
|
861
1547
|
const unwatch = config.listenToBlock ? watchBlockNumber({
|
|
862
1548
|
listen: true
|
|
@@ -873,10 +1559,10 @@ function watchReadContract(config, callback) {
|
|
|
873
1559
|
};
|
|
874
1560
|
}
|
|
875
1561
|
|
|
876
|
-
function
|
|
1562
|
+
function watchReadContract(config, callback) {
|
|
877
1563
|
const client = getProvider.getClient();
|
|
878
1564
|
|
|
879
|
-
const handleChange = async () => callback(await
|
|
1565
|
+
const handleChange = async () => callback(await readContract(config));
|
|
880
1566
|
|
|
881
1567
|
const unwatch = config.listenToBlock ? watchBlockNumber({
|
|
882
1568
|
listen: true
|
|
@@ -893,42 +1579,24 @@ function watchReadContracts(config, callback) {
|
|
|
893
1579
|
};
|
|
894
1580
|
}
|
|
895
1581
|
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
chainId,
|
|
899
|
-
request
|
|
900
|
-
} = _ref;
|
|
901
|
-
const {
|
|
902
|
-
connector
|
|
903
|
-
} = getProvider.getClient();
|
|
904
|
-
if (!connector) throw new getProvider.ConnectorNotFoundError();
|
|
905
|
-
|
|
906
|
-
try {
|
|
907
|
-
var _chain;
|
|
908
|
-
|
|
909
|
-
let chain;
|
|
910
|
-
|
|
911
|
-
if (chainId) {
|
|
912
|
-
const activeChainId = await connector.getChainId(); // Try to switch chain to provided `chainId`
|
|
913
|
-
|
|
914
|
-
if (chainId !== activeChainId) {
|
|
915
|
-
var _connector$chains$fin, _connector$chains$fin2, _connector$chains$fin3, _connector$chains$fin4;
|
|
1582
|
+
function watchReadContracts(config, callback) {
|
|
1583
|
+
const client = getProvider.getClient();
|
|
916
1584
|
|
|
917
|
-
|
|
918
|
-
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),
|
|
919
|
-
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)
|
|
920
|
-
});
|
|
921
|
-
}
|
|
922
|
-
}
|
|
1585
|
+
const handleChange = async () => callback(await readContracts(config));
|
|
923
1586
|
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
1587
|
+
const unwatch = config.listenToBlock ? watchBlockNumber({
|
|
1588
|
+
listen: true
|
|
1589
|
+
}, handleChange) : undefined;
|
|
1590
|
+
const unsubscribe = client.subscribe(_ref => {
|
|
1591
|
+
let {
|
|
1592
|
+
provider
|
|
1593
|
+
} = _ref;
|
|
1594
|
+
return provider;
|
|
1595
|
+
}, handleChange);
|
|
1596
|
+
return () => {
|
|
1597
|
+
unsubscribe();
|
|
1598
|
+
unwatch === null || unwatch === void 0 ? void 0 : unwatch();
|
|
1599
|
+
};
|
|
932
1600
|
}
|
|
933
1601
|
|
|
934
1602
|
/**
|
|
@@ -1027,13 +1695,18 @@ async function prepareSendTransaction(_ref) {
|
|
|
1027
1695
|
let {
|
|
1028
1696
|
chainId,
|
|
1029
1697
|
request,
|
|
1030
|
-
|
|
1031
|
-
chainId
|
|
1032
|
-
})
|
|
1698
|
+
signer: signer_
|
|
1033
1699
|
} = _ref;
|
|
1700
|
+
const signer = signer_ ?? (await fetchSigner({
|
|
1701
|
+
chainId
|
|
1702
|
+
}));
|
|
1703
|
+
if (!signer) throw new getProvider.ConnectorNotFoundError();
|
|
1704
|
+
if (chainId) assertActiveChain({
|
|
1705
|
+
chainId
|
|
1706
|
+
});
|
|
1034
1707
|
const [to, gasLimit] = await Promise.all([utils.isAddress(request.to) ? Promise.resolve(request.to) : fetchEnsAddress({
|
|
1035
1708
|
name: request.to
|
|
1036
|
-
}), request.gasLimit ? Promise.resolve(request.gasLimit) :
|
|
1709
|
+
}), request.gasLimit ? Promise.resolve(request.gasLimit) : signer.estimateGas(request)]);
|
|
1037
1710
|
if (!to) throw new Error('Could not resolve ENS name');
|
|
1038
1711
|
return { ...(chainId ? {
|
|
1039
1712
|
chainId
|
|
@@ -1088,20 +1761,9 @@ async function sendTransaction(_ref) {
|
|
|
1088
1761
|
if (!request.to) throw new Error('`to` is required');
|
|
1089
1762
|
}
|
|
1090
1763
|
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
} = getNetwork();
|
|
1095
|
-
const activeChainId = activeChain === null || activeChain === void 0 ? void 0 : activeChain.id;
|
|
1096
|
-
|
|
1097
|
-
if (chainId && chainId !== (activeChain === null || activeChain === void 0 ? void 0 : activeChain.id)) {
|
|
1098
|
-
var _chains$find$name, _chains$find, _chains$find$name2, _chains$find2;
|
|
1099
|
-
|
|
1100
|
-
throw new getProvider.ChainMismatchError({
|
|
1101
|
-
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),
|
|
1102
|
-
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)
|
|
1103
|
-
});
|
|
1104
|
-
}
|
|
1764
|
+
if (chainId) assertActiveChain({
|
|
1765
|
+
chainId
|
|
1766
|
+
});
|
|
1105
1767
|
|
|
1106
1768
|
try {
|
|
1107
1769
|
var _connectUnchecked, _ref2;
|
|
@@ -1117,7 +1779,7 @@ async function sendTransaction(_ref) {
|
|
|
1117
1779
|
const {
|
|
1118
1780
|
hash,
|
|
1119
1781
|
wait
|
|
1120
|
-
} = await (uncheckedSigner
|
|
1782
|
+
} = await (uncheckedSigner ?? signer).sendTransaction(request);
|
|
1121
1783
|
/********************************************************************/
|
|
1122
1784
|
|
|
1123
1785
|
/** END: iOS App Link cautious code. */
|
|
@@ -1127,7 +1789,7 @@ async function sendTransaction(_ref) {
|
|
|
1127
1789
|
/********************************************************************/
|
|
1128
1790
|
|
|
1129
1791
|
return {
|
|
1130
|
-
hash,
|
|
1792
|
+
hash: hash,
|
|
1131
1793
|
wait
|
|
1132
1794
|
};
|
|
1133
1795
|
} catch (error) {
|
|
@@ -1166,58 +1828,45 @@ async function waitForTransaction(_ref) {
|
|
|
1166
1828
|
* import { prepareWriteContract, writeContract } from '@wagmi/core'
|
|
1167
1829
|
*
|
|
1168
1830
|
* const config = await prepareWriteContract({
|
|
1169
|
-
*
|
|
1170
|
-
*
|
|
1831
|
+
* address: '0x...',
|
|
1832
|
+
* abi: wagmiAbi,
|
|
1171
1833
|
* functionName: 'mint',
|
|
1172
1834
|
* })
|
|
1173
1835
|
* const result = await writeContract(config)
|
|
1174
1836
|
*/
|
|
1175
1837
|
async function writeContract(_ref) {
|
|
1176
1838
|
let {
|
|
1177
|
-
|
|
1839
|
+
address,
|
|
1178
1840
|
args,
|
|
1179
1841
|
chainId,
|
|
1180
|
-
|
|
1842
|
+
abi,
|
|
1181
1843
|
functionName,
|
|
1182
1844
|
mode,
|
|
1183
1845
|
overrides,
|
|
1184
1846
|
request: request_
|
|
1185
1847
|
} = _ref;
|
|
1186
1848
|
|
|
1187
|
-
|
|
1849
|
+
/****************************************************************************/
|
|
1188
1850
|
|
|
1189
|
-
/** START: iOS App Link cautious code.
|
|
1851
|
+
/** START: iOS App Link cautious code. */
|
|
1190
1852
|
|
|
1191
|
-
/** Do not perform any async operations in this block.
|
|
1853
|
+
/** Do not perform any async operations in this block. */
|
|
1192
1854
|
|
|
1193
|
-
/** Ref: wagmi.sh/docs/prepare-hooks/intro#ios-app-link-constraints */
|
|
1855
|
+
/** Ref: https://wagmi.sh/docs/prepare-hooks/intro#ios-app-link-constraints */
|
|
1194
1856
|
|
|
1195
|
-
|
|
1857
|
+
/****************************************************************************/
|
|
1196
1858
|
const signer = await fetchSigner();
|
|
1197
1859
|
if (!signer) throw new getProvider.ConnectorNotFoundError();
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
const activeChainId = activeChain === null || activeChain === void 0 ? void 0 : activeChain.id;
|
|
1203
|
-
|
|
1204
|
-
if (chainId && chainId !== activeChainId) {
|
|
1205
|
-
var _chains$find$name, _chains$find, _chains$find$name2, _chains$find2;
|
|
1206
|
-
|
|
1207
|
-
throw new getProvider.ChainMismatchError({
|
|
1208
|
-
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),
|
|
1209
|
-
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)
|
|
1210
|
-
});
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1213
|
-
if (mode === 'prepared') {
|
|
1214
|
-
if (!request_) throw new Error('`request` is required');
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1860
|
+
if (chainId) assertActiveChain({
|
|
1861
|
+
chainId
|
|
1862
|
+
});
|
|
1863
|
+
if (mode === 'prepared') if (!request_) throw new Error('`request` is required');
|
|
1217
1864
|
const request = mode === 'recklesslyUnprepared' ? (await prepareWriteContract({
|
|
1218
|
-
|
|
1865
|
+
address,
|
|
1219
1866
|
args,
|
|
1220
|
-
|
|
1867
|
+
chainId,
|
|
1868
|
+
abi: abi,
|
|
1869
|
+
// TODO: Remove cast and still support `Narrow<TAbi>`
|
|
1221
1870
|
functionName,
|
|
1222
1871
|
overrides
|
|
1223
1872
|
})).request : request_;
|
|
@@ -1237,7 +1886,7 @@ async function writeContract(_ref) {
|
|
|
1237
1886
|
}
|
|
1238
1887
|
|
|
1239
1888
|
async function fetchBalance(_ref) {
|
|
1240
|
-
var
|
|
1889
|
+
var _chain$nativeCurrency, _chain$nativeCurrency2;
|
|
1241
1890
|
|
|
1242
1891
|
let {
|
|
1243
1892
|
addressOrName,
|
|
@@ -1251,47 +1900,78 @@ async function fetchBalance(_ref) {
|
|
|
1251
1900
|
});
|
|
1252
1901
|
|
|
1253
1902
|
if (token) {
|
|
1254
|
-
|
|
1255
|
-
addressOrName: token,
|
|
1256
|
-
contractInterface: erc20ABI,
|
|
1257
|
-
chainId
|
|
1258
|
-
}; // Convert ENS name to address if required
|
|
1259
|
-
|
|
1903
|
+
// Convert ENS name to address if required
|
|
1260
1904
|
let resolvedAddress;
|
|
1261
1905
|
if (utils.isAddress(addressOrName)) resolvedAddress = addressOrName;else {
|
|
1262
1906
|
const address = await provider.resolveName(addressOrName); // Same error `provider.getBalance` throws for invalid ENS name
|
|
1263
1907
|
|
|
1264
1908
|
if (!address) ethers$1.logger.throwError('ENS name not configured', utils.Logger.errors.UNSUPPORTED_OPERATION, {
|
|
1265
|
-
operation:
|
|
1909
|
+
operation: `resolveName(${JSON.stringify(addressOrName)})`
|
|
1266
1910
|
});
|
|
1267
1911
|
resolvedAddress = address;
|
|
1268
1912
|
}
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1913
|
+
|
|
1914
|
+
const fetchContractBalance = async _ref2 => {
|
|
1915
|
+
let {
|
|
1916
|
+
abi
|
|
1917
|
+
} = _ref2;
|
|
1918
|
+
const erc20Config = {
|
|
1919
|
+
abi,
|
|
1920
|
+
address: token,
|
|
1921
|
+
chainId
|
|
1922
|
+
};
|
|
1923
|
+
const [value, decimals, symbol] = await readContracts({
|
|
1924
|
+
allowFailure: false,
|
|
1925
|
+
contracts: [{ ...erc20Config,
|
|
1926
|
+
functionName: 'balanceOf',
|
|
1927
|
+
args: [resolvedAddress]
|
|
1928
|
+
}, { ...erc20Config,
|
|
1929
|
+
functionName: 'decimals'
|
|
1930
|
+
}, { ...erc20Config,
|
|
1931
|
+
functionName: 'symbol'
|
|
1932
|
+
}]
|
|
1933
|
+
});
|
|
1934
|
+
return {
|
|
1935
|
+
decimals,
|
|
1936
|
+
formatted: utils.formatUnits(value ?? '0', unit ?? decimals),
|
|
1937
|
+
symbol: symbol,
|
|
1938
|
+
// protect against `ResolvedConfig['BytesType']`
|
|
1939
|
+
value
|
|
1940
|
+
};
|
|
1285
1941
|
};
|
|
1942
|
+
|
|
1943
|
+
try {
|
|
1944
|
+
return await fetchContractBalance({
|
|
1945
|
+
abi: erc20ABI
|
|
1946
|
+
});
|
|
1947
|
+
} catch (err) {
|
|
1948
|
+
// In the chance that there is an error upon decoding the contract result,
|
|
1949
|
+
// it could be likely that the contract data is represented as bytes32 instead
|
|
1950
|
+
// of a string.
|
|
1951
|
+
if (err instanceof getProvider.ContractResultDecodeError) {
|
|
1952
|
+
const {
|
|
1953
|
+
symbol,
|
|
1954
|
+
...rest
|
|
1955
|
+
} = await fetchContractBalance({
|
|
1956
|
+
abi: erc20ABI_bytes32
|
|
1957
|
+
});
|
|
1958
|
+
return {
|
|
1959
|
+
symbol: utils.parseBytes32String(symbol),
|
|
1960
|
+
...rest
|
|
1961
|
+
};
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1964
|
+
throw err;
|
|
1965
|
+
}
|
|
1286
1966
|
}
|
|
1287
1967
|
|
|
1288
|
-
const chains = [...(client.provider.chains || []), ...(
|
|
1968
|
+
const chains = [...(client.provider.chains || []), ...(client.chains ?? [])];
|
|
1289
1969
|
const value = await provider.getBalance(addressOrName);
|
|
1290
1970
|
const chain = chains.find(x => x.id === provider.network.chainId);
|
|
1291
1971
|
return {
|
|
1292
|
-
decimals: (
|
|
1293
|
-
formatted: utils.formatUnits(value
|
|
1294
|
-
symbol: (
|
|
1972
|
+
decimals: (chain === null || chain === void 0 ? void 0 : (_chain$nativeCurrency = chain.nativeCurrency) === null || _chain$nativeCurrency === void 0 ? void 0 : _chain$nativeCurrency.decimals) ?? 18,
|
|
1973
|
+
formatted: utils.formatUnits(value ?? '0', unit ?? 'ether'),
|
|
1974
|
+
symbol: (chain === null || chain === void 0 ? void 0 : (_chain$nativeCurrency2 = chain.nativeCurrency) === null || _chain$nativeCurrency2 === void 0 ? void 0 : _chain$nativeCurrency2.symbol) ?? 'ETH',
|
|
1295
1975
|
value
|
|
1296
1976
|
};
|
|
1297
1977
|
}
|
|
@@ -1299,8 +1979,13 @@ async function fetchBalance(_ref) {
|
|
|
1299
1979
|
async function fetchSigner() {
|
|
1300
1980
|
var _client$connector, _client$connector$get;
|
|
1301
1981
|
|
|
1982
|
+
let {
|
|
1983
|
+
chainId
|
|
1984
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1302
1985
|
const client = getProvider.getClient();
|
|
1303
|
-
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
|
|
1986
|
+
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, {
|
|
1987
|
+
chainId
|
|
1988
|
+
}))) || null;
|
|
1304
1989
|
return signer;
|
|
1305
1990
|
}
|
|
1306
1991
|
|
|
@@ -1359,15 +2044,15 @@ function getAccount() {
|
|
|
1359
2044
|
}
|
|
1360
2045
|
|
|
1361
2046
|
function getNetwork() {
|
|
1362
|
-
var _client$data, _client$data$chain, _client$
|
|
2047
|
+
var _client$data, _client$data$chain, _client$data2;
|
|
1363
2048
|
|
|
1364
2049
|
const client = getProvider.getClient();
|
|
1365
2050
|
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;
|
|
1366
|
-
const activeChains =
|
|
1367
|
-
const activeChain =
|
|
2051
|
+
const activeChains = client.chains ?? [];
|
|
2052
|
+
const activeChain = [...(client.provider.chains || []), ...activeChains].find(x => x.id === chainId) ?? {
|
|
1368
2053
|
id: chainId,
|
|
1369
|
-
name:
|
|
1370
|
-
network:
|
|
2054
|
+
name: `Chain ${chainId}`,
|
|
2055
|
+
network: `${chainId}`,
|
|
1371
2056
|
rpcUrls: {
|
|
1372
2057
|
default: ''
|
|
1373
2058
|
}
|
|
@@ -1400,28 +2085,13 @@ async function signTypedData(_ref) {
|
|
|
1400
2085
|
} = _ref;
|
|
1401
2086
|
const signer = await fetchSigner();
|
|
1402
2087
|
if (!signer) throw new getProvider.ConnectorNotFoundError();
|
|
1403
|
-
const {
|
|
1404
|
-
chain: activeChain,
|
|
1405
|
-
chains
|
|
1406
|
-
} = getNetwork();
|
|
1407
2088
|
const {
|
|
1408
2089
|
chainId: chainId_
|
|
1409
2090
|
} = domain;
|
|
1410
|
-
|
|
1411
|
-
if (
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
if (chainId !== (activeChain === null || activeChain === void 0 ? void 0 : activeChain.id)) {
|
|
1416
|
-
var _chains$find$name, _chains$find, _chains$find$name2, _chains$find2;
|
|
1417
|
-
|
|
1418
|
-
throw new getProvider.ChainMismatchError({
|
|
1419
|
-
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),
|
|
1420
|
-
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)
|
|
1421
|
-
});
|
|
1422
|
-
}
|
|
1423
|
-
} // Method name may be changed in the future, see https://docs.ethers.io/v5/api/signer/#Signer-signTypedData
|
|
1424
|
-
|
|
2091
|
+
const chainId = chainId_ ? getProvider.normalizeChainId(chainId_) : undefined;
|
|
2092
|
+
if (chainId) assertActiveChain({
|
|
2093
|
+
chainId
|
|
2094
|
+
}); // Method name may be changed in the future, see https://docs.ethers.io/v5/api/signer/#Signer-signTypedData
|
|
1425
2095
|
|
|
1426
2096
|
return await signer._signTypedData(domain, types, value);
|
|
1427
2097
|
}
|
|
@@ -1490,18 +2160,23 @@ function watchNetwork(callback) {
|
|
|
1490
2160
|
return unsubscribe;
|
|
1491
2161
|
}
|
|
1492
2162
|
|
|
1493
|
-
function watchSigner(callback) {
|
|
2163
|
+
function watchSigner(_ref, callback) {
|
|
2164
|
+
let {
|
|
2165
|
+
chainId
|
|
2166
|
+
} = _ref;
|
|
1494
2167
|
const client = getProvider.getClient();
|
|
1495
2168
|
|
|
1496
|
-
const handleChange = async () => callback(await fetchSigner(
|
|
2169
|
+
const handleChange = async () => callback(await fetchSigner({
|
|
2170
|
+
chainId
|
|
2171
|
+
}));
|
|
1497
2172
|
|
|
1498
|
-
const unsubscribe = client.subscribe(
|
|
2173
|
+
const unsubscribe = client.subscribe(_ref2 => {
|
|
1499
2174
|
var _data$chain;
|
|
1500
2175
|
|
|
1501
2176
|
let {
|
|
1502
2177
|
data,
|
|
1503
2178
|
connector
|
|
1504
|
-
} =
|
|
2179
|
+
} = _ref2;
|
|
1505
2180
|
return {
|
|
1506
2181
|
account: data === null || data === void 0 ? void 0 : data.account,
|
|
1507
2182
|
chainId: data === null || data === void 0 ? void 0 : (_data$chain = data.chain) === null || _data$chain === void 0 ? void 0 : _data$chain.id,
|
|
@@ -1569,8 +2244,6 @@ exports.publicRpcUrls = rpcs.publicRpcUrls;
|
|
|
1569
2244
|
exports.configureChains = configureChains;
|
|
1570
2245
|
exports.connect = connect;
|
|
1571
2246
|
exports.deepEqual = deepEqual;
|
|
1572
|
-
exports.deprecatedSendTransaction = deprecatedSendTransaction;
|
|
1573
|
-
exports.deprecatedWriteContract = deprecatedWriteContract;
|
|
1574
2247
|
exports.disconnect = disconnect;
|
|
1575
2248
|
exports.erc20ABI = erc20ABI;
|
|
1576
2249
|
exports.erc721ABI = erc721ABI;
|
|
@@ -1589,6 +2262,7 @@ exports.getContract = getContract;
|
|
|
1589
2262
|
exports.getNetwork = getNetwork;
|
|
1590
2263
|
exports.getWebSocketProvider = getWebSocketProvider;
|
|
1591
2264
|
exports.minimizeContractInterface = minimizeContractInterface;
|
|
2265
|
+
exports.multicall = multicall;
|
|
1592
2266
|
exports.parseContractResult = parseContractResult;
|
|
1593
2267
|
exports.prepareSendTransaction = prepareSendTransaction;
|
|
1594
2268
|
exports.prepareWriteContract = prepareWriteContract;
|
|
@@ -1603,6 +2277,7 @@ exports.waitForTransaction = waitForTransaction;
|
|
|
1603
2277
|
exports.watchAccount = watchAccount;
|
|
1604
2278
|
exports.watchBlockNumber = watchBlockNumber;
|
|
1605
2279
|
exports.watchContractEvent = watchContractEvent;
|
|
2280
|
+
exports.watchMulticall = watchMulticall;
|
|
1606
2281
|
exports.watchNetwork = watchNetwork;
|
|
1607
2282
|
exports.watchProvider = watchProvider;
|
|
1608
2283
|
exports.watchReadContract = watchReadContract;
|