@wagmi/core 0.4.6 → 0.4.7

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.
@@ -9,5 +9,5 @@ export { AddChainError, ChainDoesNotSupportMulticallError, ChainMismatchError, C
9
9
  export { createStorage, noopStorage } from './storage';
10
10
  export type { ClientStorage as Storage } from './storage';
11
11
  export type { Chain, ChainProviderFn, FallbackProviderConfig, ProviderWithFallbackConfig, Provider, Unit, WebSocketProvider, } from './types';
12
- export { configureChains, deepEqual, normalizeChainId } from './utils';
12
+ export { configureChains, deepEqual, normalizeChainId, parseContractResult, } from './utils';
13
13
  export type { ConfigureChainsConfig } from './utils';
@@ -3,4 +3,5 @@ export type { ConfigureChainsConfig } from './configureChains';
3
3
  export { deepEqual } from './deepEqual';
4
4
  export { getInjectedName } from './getInjectedName';
5
5
  export { normalizeChainId } from './normalizeChainId';
6
+ export { parseContractResult } from './parseContractResult';
6
7
  export { warn } from './warn';
@@ -0,0 +1,7 @@
1
+ import { ContractInterface } from 'ethers/lib/ethers';
2
+ import { Result } from 'ethers/lib/utils';
3
+ export declare function parseContractResult({ contractInterface, data, functionName, }: {
4
+ contractInterface: ContractInterface;
5
+ data: Result;
6
+ functionName: string;
7
+ }): any;
@@ -170,6 +170,32 @@ function deepEqual(a, b) {
170
170
  return a !== a && b !== b;
171
171
  }
172
172
 
173
+ function isPlainArray(value) {
174
+ return Array.isArray(value) && Object.keys(value).length === value.length;
175
+ }
176
+
177
+ function parseContractResult(_ref) {
178
+ let {
179
+ contractInterface,
180
+ data,
181
+ functionName
182
+ } = _ref;
183
+
184
+ if (data && isPlainArray(data)) {
185
+ var _fragment$outputs;
186
+
187
+ const iface = ethers$1.Contract.getInterface(contractInterface);
188
+ const fragment = iface.getFunction(functionName);
189
+ const isTuple = (((_fragment$outputs = fragment.outputs) === null || _fragment$outputs === void 0 ? void 0 : _fragment$outputs.length) || 0) > 1;
190
+ const data_ = isTuple ? data : [data];
191
+ const encodedResult = iface.encodeFunctionResult(functionName, data_);
192
+ const decodedResult = iface.decodeFunctionResult(functionName, encodedResult);
193
+ return isTuple ? decodedResult : decodedResult[0];
194
+ }
195
+
196
+ return data;
197
+ }
198
+
173
199
  // https://ethereum.org/en/developers/docs/standards/tokens/erc-20
174
200
  const erc20ABI = ['event Approval(address indexed _owner, address indexed _spender, uint256 _value)', 'event Transfer(address indexed _from, address indexed _to, uint256 _value)', 'function allowance(address _owner, address _spender) public view returns (uint256 remaining)', 'function approve(address _spender, uint256 _value) public returns (bool success)', 'function balanceOf(address _owner) public view returns (uint256 balance)', 'function decimals() public view returns (uint8)', 'function name() public view returns (string)', 'function symbol() public view returns (string)', 'function totalSupply() public view returns (uint256)', 'function transfer(address _to, uint256 _value) public returns (bool success)', 'function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)']; // https://ethereum.org/en/developers/docs/standards/tokens/erc-721
175
201
 
@@ -1182,6 +1208,7 @@ exports.getContract = getContract;
1182
1208
  exports.getNetwork = getNetwork;
1183
1209
  exports.getProvider = getProvider;
1184
1210
  exports.getWebSocketProvider = getWebSocketProvider;
1211
+ exports.parseContractResult = parseContractResult;
1185
1212
  exports.readContract = readContract;
1186
1213
  exports.readContracts = readContracts;
1187
1214
  exports.sendTransaction = sendTransaction;
@@ -170,6 +170,32 @@ function deepEqual(a, b) {
170
170
  return a !== a && b !== b;
171
171
  }
172
172
 
173
+ function isPlainArray(value) {
174
+ return Array.isArray(value) && Object.keys(value).length === value.length;
175
+ }
176
+
177
+ function parseContractResult(_ref) {
178
+ let {
179
+ contractInterface,
180
+ data,
181
+ functionName
182
+ } = _ref;
183
+
184
+ if (data && isPlainArray(data)) {
185
+ var _fragment$outputs;
186
+
187
+ const iface = ethers$1.Contract.getInterface(contractInterface);
188
+ const fragment = iface.getFunction(functionName);
189
+ const isTuple = (((_fragment$outputs = fragment.outputs) === null || _fragment$outputs === void 0 ? void 0 : _fragment$outputs.length) || 0) > 1;
190
+ const data_ = isTuple ? data : [data];
191
+ const encodedResult = iface.encodeFunctionResult(functionName, data_);
192
+ const decodedResult = iface.decodeFunctionResult(functionName, encodedResult);
193
+ return isTuple ? decodedResult : decodedResult[0];
194
+ }
195
+
196
+ return data;
197
+ }
198
+
173
199
  // https://ethereum.org/en/developers/docs/standards/tokens/erc-20
174
200
  const erc20ABI = ['event Approval(address indexed _owner, address indexed _spender, uint256 _value)', 'event Transfer(address indexed _from, address indexed _to, uint256 _value)', 'function allowance(address _owner, address _spender) public view returns (uint256 remaining)', 'function approve(address _spender, uint256 _value) public returns (bool success)', 'function balanceOf(address _owner) public view returns (uint256 balance)', 'function decimals() public view returns (uint8)', 'function name() public view returns (string)', 'function symbol() public view returns (string)', 'function totalSupply() public view returns (uint256)', 'function transfer(address _to, uint256 _value) public returns (bool success)', 'function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)']; // https://ethereum.org/en/developers/docs/standards/tokens/erc-721
175
201
 
@@ -1182,6 +1208,7 @@ exports.getContract = getContract;
1182
1208
  exports.getNetwork = getNetwork;
1183
1209
  exports.getProvider = getProvider;
1184
1210
  exports.getWebSocketProvider = getWebSocketProvider;
1211
+ exports.parseContractResult = parseContractResult;
1185
1212
  exports.readContract = readContract;
1186
1213
  exports.readContracts = readContracts;
1187
1214
  exports.sendTransaction = sendTransaction;
@@ -2,9 +2,9 @@ import { g as getClient } from './client-a05fd511.esm.js';
2
2
  export { C as Client, I as InjectedConnector, c as createClient, a as createStorage, n as noopStorage } from './client-a05fd511.esm.js';
3
3
  import { C as ConnectorAlreadyConnectedError, P as ProviderChainsNotFound, a as ChainDoesNotSupportMulticallError, b as ContractMethodNoResultError, c as ConnectorNotFoundError, d as ChainMismatchError, U as UserRejectedRequestError, n as normalizeChainId, S as SwitchChainNotSupportedError } from './base-b565d5d4.esm.js';
4
4
  export { A as AddChainError, a as ChainDoesNotSupportMulticallError, d as ChainMismatchError, f as ChainNotConfiguredError, e as Connector, C as ConnectorAlreadyConnectedError, c as ConnectorNotFoundError, b as ContractMethodNoResultError, P as ProviderChainsNotFound, g as ProviderRpcError, R as ResourceUnavailableError, h as RpcError, i as SwitchChainError, S as SwitchChainNotSupportedError, U as UserRejectedRequestError, n as normalizeChainId } from './base-b565d5d4.esm.js';
5
- import { logger, Contract as Contract$1 } from 'ethers/lib/ethers';
5
+ import { Contract, logger } from 'ethers/lib/ethers';
6
6
  import { isAddress, Logger, formatUnits, getAddress } from 'ethers/lib/utils';
7
- import { providers, Contract } from 'ethers';
7
+ import { providers, Contract as Contract$1 } from 'ethers';
8
8
  import shallow from 'zustand/shallow';
9
9
  export { a as alchemyRpcUrls, i as infuraRpcUrls, p as publicRpcUrls } from './rpcs-b73a8f60.esm.js';
10
10
  export { a as allChains, c as chain, b as chainId, d as defaultChains, e as defaultL2Chains, f as etherscanBlockExplorers } from './chains-fd2c546c.esm.js';
@@ -164,6 +164,32 @@ function deepEqual(a, b) {
164
164
  return a !== a && b !== b;
165
165
  }
166
166
 
167
+ function isPlainArray(value) {
168
+ return Array.isArray(value) && Object.keys(value).length === value.length;
169
+ }
170
+
171
+ function parseContractResult(_ref) {
172
+ let {
173
+ contractInterface,
174
+ data,
175
+ functionName
176
+ } = _ref;
177
+
178
+ if (data && isPlainArray(data)) {
179
+ var _fragment$outputs;
180
+
181
+ const iface = Contract.getInterface(contractInterface);
182
+ const fragment = iface.getFunction(functionName);
183
+ const isTuple = (((_fragment$outputs = fragment.outputs) === null || _fragment$outputs === void 0 ? void 0 : _fragment$outputs.length) || 0) > 1;
184
+ const data_ = isTuple ? data : [data];
185
+ const encodedResult = iface.encodeFunctionResult(functionName, data_);
186
+ const decodedResult = iface.decodeFunctionResult(functionName, encodedResult);
187
+ return isTuple ? decodedResult : decodedResult[0];
188
+ }
189
+
190
+ return data;
191
+ }
192
+
167
193
  // https://ethereum.org/en/developers/docs/standards/tokens/erc-20
168
194
  const erc20ABI = ['event Approval(address indexed _owner, address indexed _spender, uint256 _value)', 'event Transfer(address indexed _from, address indexed _to, uint256 _value)', 'function allowance(address _owner, address _spender) public view returns (uint256 remaining)', 'function approve(address _spender, uint256 _value) public returns (bool success)', 'function balanceOf(address _owner) public view returns (uint256 balance)', 'function decimals() public view returns (uint8)', 'function name() public view returns (string)', 'function symbol() public view returns (string)', 'function totalSupply() public view returns (uint256)', 'function transfer(address _to, uint256 _value) public returns (bool success)', 'function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)']; // https://ethereum.org/en/developers/docs/standards/tokens/erc-721
169
195
 
@@ -258,7 +284,7 @@ function getContract(_ref) {
258
284
  contractInterface,
259
285
  signerOrProvider
260
286
  } = _ref;
261
- return new Contract(addressOrName, contractInterface, signerOrProvider);
287
+ return new Contract$1(addressOrName, contractInterface, signerOrProvider);
262
288
  }
263
289
 
264
290
  function getProvider() {
@@ -1054,7 +1080,7 @@ async function fetchToken(_ref) {
1054
1080
  const provider = getProvider({
1055
1081
  chainId
1056
1082
  });
1057
- const contract = new Contract$1(address, erc20ABI, provider);
1083
+ const contract = new Contract(address, erc20ABI, provider);
1058
1084
  const [symbol, decimals, totalSupply] = await Promise.all([contract.symbol(), contract.decimals(), contract.totalSupply()]);
1059
1085
  const token = {
1060
1086
  address,
@@ -1126,4 +1152,4 @@ async function waitForTransaction(_ref) {
1126
1152
  return await promise;
1127
1153
  }
1128
1154
 
1129
- export { configureChains, connect, deepEqual, disconnect, erc20ABI, erc721ABI, fetchBalance, fetchBlockNumber, fetchEnsAddress, fetchEnsAvatar, fetchEnsName, fetchEnsResolver, fetchFeeData, fetchSigner, fetchToken, getAccount, getContract, getNetwork, getProvider, getWebSocketProvider, readContract, readContracts, sendTransaction, signMessage, signTypedData, switchNetwork, units, waitForTransaction, watchAccount, watchBlockNumber, watchContractEvent, watchNetwork, watchProvider, watchReadContract, watchReadContracts, watchSigner, watchWebSocketProvider, writeContract };
1155
+ export { configureChains, connect, deepEqual, disconnect, erc20ABI, erc721ABI, fetchBalance, fetchBlockNumber, fetchEnsAddress, fetchEnsAvatar, fetchEnsName, fetchEnsResolver, fetchFeeData, fetchSigner, fetchToken, getAccount, getContract, getNetwork, getProvider, getWebSocketProvider, parseContractResult, readContract, readContracts, sendTransaction, signMessage, signTypedData, switchNetwork, units, waitForTransaction, watchAccount, watchBlockNumber, watchContractEvent, watchNetwork, watchProvider, watchReadContract, watchReadContracts, watchSigner, watchWebSocketProvider, writeContract };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@wagmi/core",
3
3
  "description": "Vanilla JS library for Ethereum",
4
4
  "license": "WAGMIT",
5
- "version": "0.4.6",
5
+ "version": "0.4.7",
6
6
  "repository": "tmm/wagmi",
7
7
  "author": "awkweb.eth",
8
8
  "ethereum": "awkweb.eth",