@wagmi/core 0.7.7 → 0.7.8
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/dist/{base-5bd9b5ed.d.ts → base-a32d0b91.d.ts} +2 -2
- package/dist/chains.d.ts +1 -1
- package/dist/{chunk-TYXJCTXO.js → chunk-HEIMP7HQ.js} +28 -23
- package/dist/connectors/coinbaseWallet.d.ts +3 -3
- package/dist/connectors/coinbaseWallet.js +1 -1
- package/dist/connectors/metaMask.d.ts +4 -6
- package/dist/connectors/metaMask.js +36 -43
- package/dist/connectors/mock/index.d.ts +5 -5
- package/dist/connectors/mock/index.js +1 -1
- package/dist/connectors/walletConnect.d.ts +4 -4
- package/dist/connectors/walletConnect.js +1 -1
- package/dist/{contracts-3c4d70a1.d.ts → contracts-3880ee54.d.ts} +24 -24
- package/dist/{index-bacc1c49.d.ts → index-58cffc47.d.ts} +23 -23
- package/dist/index.d.ts +111 -111
- package/dist/index.js +1 -1
- package/dist/{injected-6980e5c3.d.ts → injected-82510902.d.ts} +12 -4
- package/dist/internal.d.ts +2 -2
- package/dist/internal.js +1 -1
- package/dist/providers/alchemy.d.ts +2 -2
- package/dist/providers/infura.d.ts +2 -2
- package/dist/providers/jsonRpc.d.ts +2 -2
- package/dist/providers/public.d.ts +2 -2
- package/package.json +2 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Address } from 'abitype';
|
|
2
2
|
import EventEmitter from 'eventemitter3';
|
|
3
|
-
import { C as Chain } from './index-
|
|
3
|
+
import { C as Chain } from './index-58cffc47.js';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
type ConnectorData<Provider = any> = {
|
|
6
6
|
account?: Address;
|
|
7
7
|
chain?: {
|
|
8
8
|
id: number;
|
package/dist/chains.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { k as arbitrum, l as arbitrumGoerli, m as foundry, n as goerli, o as hardhat, q as localhost, r as mainnet, t as optimism, v as optimismGoerli, w as polygon, x as polygonMumbai, s as sepolia } from './index-
|
|
1
|
+
export { k as arbitrum, l as arbitrumGoerli, m as foundry, n as goerli, o as hardhat, q as localhost, r as mainnet, t as optimism, v as optimismGoerli, w as polygon, x as polygonMumbai, s as sepolia } from './index-58cffc47.js';
|
|
2
2
|
import 'abitype';
|
|
3
3
|
import 'ethers';
|
|
@@ -59,7 +59,7 @@ function configureChains(defaultChains2, providers3, {
|
|
|
59
59
|
`Could not find valid provider configuration for chain "${chain2.name}".
|
|
60
60
|
`,
|
|
61
61
|
"You may need to add `jsonRpcProvider` to `configureChains` with the chain's RPC URLs.",
|
|
62
|
-
"Read more: https://wagmi.sh/
|
|
62
|
+
"Read more: https://wagmi.sh/react/providers/jsonRpc"
|
|
63
63
|
].join("\n")
|
|
64
64
|
);
|
|
65
65
|
}
|
|
@@ -1806,10 +1806,10 @@ var InjectedConnector = class extends Connector {
|
|
|
1806
1806
|
const options = {
|
|
1807
1807
|
shimDisconnect: true,
|
|
1808
1808
|
shimChainChangedDisconnect: true,
|
|
1809
|
+
getProvider: () => typeof window !== "undefined" ? window.ethereum : void 0,
|
|
1809
1810
|
...options_
|
|
1810
1811
|
};
|
|
1811
1812
|
super({ chains, options });
|
|
1812
|
-
this.ready = typeof window != "undefined" && !!window.ethereum;
|
|
1813
1813
|
__privateAdd(this, _provider, void 0);
|
|
1814
1814
|
__privateAdd(this, _switchingChains, void 0);
|
|
1815
1815
|
this.shimDisconnectKey = "injected.shimDisconnect";
|
|
@@ -1827,27 +1827,31 @@ var InjectedConnector = class extends Connector {
|
|
|
1827
1827
|
this.emit("change", { chain: { id, unsupported } });
|
|
1828
1828
|
};
|
|
1829
1829
|
this.onDisconnect = () => {
|
|
1830
|
-
if (this.options
|
|
1830
|
+
if (this.options.shimChainChangedDisconnect && __privateGet(this, _switchingChains)) {
|
|
1831
1831
|
__privateSet(this, _switchingChains, false);
|
|
1832
1832
|
return;
|
|
1833
1833
|
}
|
|
1834
1834
|
this.emit("disconnect");
|
|
1835
|
-
if (this.options
|
|
1835
|
+
if (this.options.shimDisconnect)
|
|
1836
1836
|
getClient().storage?.removeItem(this.shimDisconnectKey);
|
|
1837
1837
|
};
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1838
|
+
const provider = options.getProvider();
|
|
1839
|
+
if (typeof options.name === "string")
|
|
1840
|
+
this.name = options.name;
|
|
1841
|
+
else if (provider) {
|
|
1842
|
+
const detectedName = getInjectedName(provider);
|
|
1843
|
+
if (options.name)
|
|
1844
|
+
this.name = options.name(detectedName);
|
|
1845
|
+
else {
|
|
1846
|
+
if (typeof detectedName === "string")
|
|
1847
|
+
this.name = detectedName;
|
|
1848
|
+
else
|
|
1849
|
+
this.name = detectedName[0];
|
|
1850
|
+
}
|
|
1851
|
+
} else
|
|
1852
|
+
this.name = "Injected";
|
|
1849
1853
|
this.id = "injected";
|
|
1850
|
-
this.
|
|
1854
|
+
this.ready = !!provider;
|
|
1851
1855
|
}
|
|
1852
1856
|
async connect({ chainId: chainId2 } = {}) {
|
|
1853
1857
|
try {
|
|
@@ -1871,7 +1875,7 @@ var InjectedConnector = class extends Connector {
|
|
|
1871
1875
|
id = chain2.id;
|
|
1872
1876
|
unsupported = this.isChainUnsupported(id);
|
|
1873
1877
|
}
|
|
1874
|
-
if (this.options
|
|
1878
|
+
if (this.options.shimDisconnect)
|
|
1875
1879
|
getClient().storage?.setItem(this.shimDisconnectKey, true);
|
|
1876
1880
|
return { account, chain: { id, unsupported }, provider };
|
|
1877
1881
|
} catch (error) {
|
|
@@ -1889,7 +1893,7 @@ var InjectedConnector = class extends Connector {
|
|
|
1889
1893
|
provider.removeListener("accountsChanged", this.onAccountsChanged);
|
|
1890
1894
|
provider.removeListener("chainChanged", this.onChainChanged);
|
|
1891
1895
|
provider.removeListener("disconnect", this.onDisconnect);
|
|
1892
|
-
if (this.options
|
|
1896
|
+
if (this.options.shimDisconnect)
|
|
1893
1897
|
getClient().storage?.removeItem(this.shimDisconnectKey);
|
|
1894
1898
|
}
|
|
1895
1899
|
async getAccount() {
|
|
@@ -1908,8 +1912,9 @@ var InjectedConnector = class extends Connector {
|
|
|
1908
1912
|
return provider.request({ method: "eth_chainId" }).then(normalizeChainId);
|
|
1909
1913
|
}
|
|
1910
1914
|
async getProvider() {
|
|
1911
|
-
|
|
1912
|
-
|
|
1915
|
+
const provider = this.options.getProvider();
|
|
1916
|
+
if (provider)
|
|
1917
|
+
__privateSet(this, _provider, provider);
|
|
1913
1918
|
return __privateGet(this, _provider);
|
|
1914
1919
|
}
|
|
1915
1920
|
async getSigner({ chainId: chainId2 } = {}) {
|
|
@@ -1924,7 +1929,7 @@ var InjectedConnector = class extends Connector {
|
|
|
1924
1929
|
}
|
|
1925
1930
|
async isAuthorized() {
|
|
1926
1931
|
try {
|
|
1927
|
-
if (this.options
|
|
1932
|
+
if (this.options.shimDisconnect && !getClient().storage?.getItem(this.shimDisconnectKey))
|
|
1928
1933
|
return false;
|
|
1929
1934
|
const provider = await this.getProvider();
|
|
1930
1935
|
if (!provider)
|
|
@@ -1936,7 +1941,7 @@ var InjectedConnector = class extends Connector {
|
|
|
1936
1941
|
}
|
|
1937
1942
|
}
|
|
1938
1943
|
async switchChain(chainId2) {
|
|
1939
|
-
if (this.options
|
|
1944
|
+
if (this.options.shimChainChangedDisconnect)
|
|
1940
1945
|
__privateSet(this, _switchingChains, true);
|
|
1941
1946
|
const provider = await this.getProvider();
|
|
1942
1947
|
if (!provider)
|
|
@@ -2295,7 +2300,7 @@ function createClient(config) {
|
|
|
2295
2300
|
function getClient() {
|
|
2296
2301
|
if (!client) {
|
|
2297
2302
|
throw new Error(
|
|
2298
|
-
"No wagmi client found. Ensure you have set up a client: https://wagmi.sh/
|
|
2303
|
+
"No wagmi client found. Ensure you have set up a client: https://wagmi.sh/react/client"
|
|
2299
2304
|
);
|
|
2300
2305
|
}
|
|
2301
2306
|
return client;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { CoinbaseWalletProvider } from '@coinbase/wallet-sdk';
|
|
2
2
|
import { CoinbaseWalletSDKOptions } from '@coinbase/wallet-sdk/dist/CoinbaseWalletSDK';
|
|
3
3
|
import { providers } from 'ethers';
|
|
4
|
-
import { C as Chain } from '../index-
|
|
5
|
-
import { C as Connector } from '../base-
|
|
4
|
+
import { C as Chain } from '../index-58cffc47.js';
|
|
5
|
+
import { C as Connector } from '../base-a32d0b91.js';
|
|
6
6
|
import 'abitype';
|
|
7
7
|
import 'eventemitter3';
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
type Options = CoinbaseWalletSDKOptions & {
|
|
10
10
|
/**
|
|
11
11
|
* Fallback Ethereum JSON RPC URL
|
|
12
12
|
* @default ""
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { C as Chain, E as Ethereum } from '../index-
|
|
2
|
-
import { a as InjectedConnectorOptions, I as InjectedConnector } from '../injected-
|
|
1
|
+
import { C as Chain, E as Ethereum } from '../index-58cffc47.js';
|
|
2
|
+
import { a as InjectedConnectorOptions, I as InjectedConnector } from '../injected-82510902.js';
|
|
3
3
|
import 'abitype';
|
|
4
4
|
import 'ethers';
|
|
5
|
-
import '../base-
|
|
5
|
+
import '../base-a32d0b91.js';
|
|
6
6
|
import 'eventemitter3';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
type MetaMaskConnectorOptions = Pick<InjectedConnectorOptions, 'shimChainChangedDisconnect' | 'shimDisconnect'> & {
|
|
9
9
|
/**
|
|
10
10
|
* While "disconnected" with `shimDisconnect`, allows user to select a different MetaMask account (than the currently connected account) when trying to connect.
|
|
11
11
|
*/
|
|
@@ -14,7 +14,6 @@ declare type MetaMaskConnectorOptions = Pick<InjectedConnectorOptions, 'shimChai
|
|
|
14
14
|
declare class MetaMaskConnector extends InjectedConnector {
|
|
15
15
|
#private;
|
|
16
16
|
readonly id = "metaMask";
|
|
17
|
-
readonly ready: boolean;
|
|
18
17
|
constructor({ chains, options: options_, }?: {
|
|
19
18
|
chains?: Chain[];
|
|
20
19
|
options?: MetaMaskConnectorOptions;
|
|
@@ -29,7 +28,6 @@ declare class MetaMaskConnector extends InjectedConnector {
|
|
|
29
28
|
};
|
|
30
29
|
provider: Ethereum;
|
|
31
30
|
}>;
|
|
32
|
-
getProvider(): Promise<Ethereum | undefined>;
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
export { MetaMaskConnector, MetaMaskConnectorOptions };
|
|
@@ -4,18 +4,17 @@ import {
|
|
|
4
4
|
ResourceUnavailableError,
|
|
5
5
|
UserRejectedRequestError,
|
|
6
6
|
getClient
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-HEIMP7HQ.js";
|
|
8
8
|
import "../chunk-4DNFSL2K.js";
|
|
9
9
|
import {
|
|
10
10
|
__privateAdd,
|
|
11
11
|
__privateGet,
|
|
12
|
-
__privateMethod,
|
|
13
12
|
__privateSet
|
|
14
13
|
} from "../chunk-MQXBDTVK.js";
|
|
15
14
|
|
|
16
15
|
// src/connectors/metaMask.ts
|
|
17
16
|
import { getAddress } from "ethers/lib/utils.js";
|
|
18
|
-
var
|
|
17
|
+
var _UNSTABLE_shimOnConnectSelectAccount;
|
|
19
18
|
var MetaMaskConnector = class extends InjectedConnector {
|
|
20
19
|
constructor({
|
|
21
20
|
chains,
|
|
@@ -25,14 +24,35 @@ var MetaMaskConnector = class extends InjectedConnector {
|
|
|
25
24
|
name: "MetaMask",
|
|
26
25
|
shimDisconnect: true,
|
|
27
26
|
shimChainChangedDisconnect: true,
|
|
27
|
+
getProvider() {
|
|
28
|
+
function getReady(ethereum) {
|
|
29
|
+
const isMetaMask = !!ethereum?.isMetaMask;
|
|
30
|
+
if (!isMetaMask)
|
|
31
|
+
return;
|
|
32
|
+
if (ethereum.isBraveWallet && !ethereum._events && !ethereum._state)
|
|
33
|
+
return;
|
|
34
|
+
if (ethereum.isAvalanche)
|
|
35
|
+
return;
|
|
36
|
+
if (ethereum.isKuCoinWallet)
|
|
37
|
+
return;
|
|
38
|
+
if (ethereum.isPortal)
|
|
39
|
+
return;
|
|
40
|
+
if (ethereum.isTokenPocket)
|
|
41
|
+
return;
|
|
42
|
+
if (ethereum.isTokenary)
|
|
43
|
+
return;
|
|
44
|
+
return ethereum;
|
|
45
|
+
}
|
|
46
|
+
if (typeof window === "undefined")
|
|
47
|
+
return;
|
|
48
|
+
if (window.ethereum?.providers)
|
|
49
|
+
return window.ethereum.providers.find(getReady);
|
|
50
|
+
return getReady(window.ethereum);
|
|
51
|
+
},
|
|
28
52
|
...options_
|
|
29
53
|
};
|
|
30
54
|
super({ chains, options });
|
|
31
|
-
__privateAdd(this, _getReady);
|
|
32
|
-
__privateAdd(this, _findProvider);
|
|
33
55
|
this.id = "metaMask";
|
|
34
|
-
this.ready = typeof window != "undefined" && !!__privateMethod(this, _findProvider, findProvider_fn).call(this, window.ethereum);
|
|
35
|
-
__privateAdd(this, _provider, void 0);
|
|
36
56
|
__privateAdd(this, _UNSTABLE_shimOnConnectSelectAccount, void 0);
|
|
37
57
|
__privateSet(this, _UNSTABLE_shimOnConnectSelectAccount, options.UNSTABLE_shimOnConnectSelectAccount);
|
|
38
58
|
}
|
|
@@ -52,10 +72,15 @@ var MetaMaskConnector = class extends InjectedConnector {
|
|
|
52
72
|
account = await this.getAccount().catch(() => null);
|
|
53
73
|
const isConnected = !!account;
|
|
54
74
|
if (isConnected)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
75
|
+
try {
|
|
76
|
+
await provider.request({
|
|
77
|
+
method: "wallet_requestPermissions",
|
|
78
|
+
params: [{ eth_accounts: {} }]
|
|
79
|
+
});
|
|
80
|
+
} catch (error) {
|
|
81
|
+
if (this.isUserRejectedRequestError(error))
|
|
82
|
+
throw new UserRejectedRequestError(error);
|
|
83
|
+
}
|
|
59
84
|
}
|
|
60
85
|
if (!account) {
|
|
61
86
|
const accounts = await provider.request({
|
|
@@ -81,40 +106,8 @@ var MetaMaskConnector = class extends InjectedConnector {
|
|
|
81
106
|
throw error;
|
|
82
107
|
}
|
|
83
108
|
}
|
|
84
|
-
async getProvider() {
|
|
85
|
-
if (typeof window !== "undefined") {
|
|
86
|
-
__privateSet(this, _provider, __privateMethod(this, _findProvider, findProvider_fn).call(this, window.ethereum));
|
|
87
|
-
}
|
|
88
|
-
return __privateGet(this, _provider);
|
|
89
|
-
}
|
|
90
109
|
};
|
|
91
|
-
_provider = new WeakMap();
|
|
92
110
|
_UNSTABLE_shimOnConnectSelectAccount = new WeakMap();
|
|
93
|
-
_getReady = new WeakSet();
|
|
94
|
-
getReady_fn = function(ethereum) {
|
|
95
|
-
const isMetaMask = !!ethereum?.isMetaMask;
|
|
96
|
-
if (!isMetaMask)
|
|
97
|
-
return;
|
|
98
|
-
if (ethereum.isBraveWallet && !ethereum._events && !ethereum._state)
|
|
99
|
-
return;
|
|
100
|
-
if (ethereum.isAvalanche)
|
|
101
|
-
return;
|
|
102
|
-
if (ethereum.isKuCoinWallet)
|
|
103
|
-
return;
|
|
104
|
-
if (ethereum.isPortal)
|
|
105
|
-
return;
|
|
106
|
-
if (ethereum.isTokenPocket)
|
|
107
|
-
return;
|
|
108
|
-
if (ethereum.isTokenary)
|
|
109
|
-
return;
|
|
110
|
-
return ethereum;
|
|
111
|
-
};
|
|
112
|
-
_findProvider = new WeakSet();
|
|
113
|
-
findProvider_fn = function(ethereum) {
|
|
114
|
-
if (ethereum?.providers)
|
|
115
|
-
return ethereum.providers.find(__privateMethod(this, _getReady, getReady_fn));
|
|
116
|
-
return __privateMethod(this, _getReady, getReady_fn).call(this, ethereum);
|
|
117
|
-
};
|
|
118
111
|
export {
|
|
119
112
|
MetaMaskConnector
|
|
120
113
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as ethers from 'ethers';
|
|
2
2
|
import { providers } from 'ethers';
|
|
3
|
-
import { S as Signer, C as Chain } from '../../index-
|
|
4
|
-
import { C as Connector, a as ConnectorData } from '../../base-
|
|
3
|
+
import { S as Signer, C as Chain } from '../../index-58cffc47.js';
|
|
4
|
+
import { C as Connector, a as ConnectorData } from '../../base-a32d0b91.js';
|
|
5
5
|
import EventEmitter from 'eventemitter3';
|
|
6
6
|
import 'abitype';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
type MockProviderOptions = {
|
|
9
9
|
chainId?: number;
|
|
10
10
|
flags?: {
|
|
11
11
|
isAuthorized?: boolean;
|
|
@@ -15,12 +15,12 @@ declare type MockProviderOptions = {
|
|
|
15
15
|
};
|
|
16
16
|
signer: Signer;
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
type Events = {
|
|
19
19
|
accountsChanged(accounts: string[]): void;
|
|
20
20
|
chainChanged(chainId: number | string): void;
|
|
21
21
|
disconnect(): void;
|
|
22
22
|
};
|
|
23
|
-
|
|
23
|
+
type Event = keyof Events;
|
|
24
24
|
declare class MockProvider extends providers.BaseProvider {
|
|
25
25
|
#private;
|
|
26
26
|
events: EventEmitter<Events, any>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import WalletConnectProvider from '@walletconnect/ethereum-provider';
|
|
2
2
|
import { providers } from 'ethers';
|
|
3
|
-
import { C as Chain } from '../index-
|
|
4
|
-
import { C as Connector } from '../base-
|
|
3
|
+
import { C as Chain } from '../index-58cffc47.js';
|
|
4
|
+
import { C as Connector } from '../base-a32d0b91.js';
|
|
5
5
|
import 'abitype';
|
|
6
6
|
import 'eventemitter3';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
type WalletConnectOptions = ConstructorParameters<typeof WalletConnectProvider>[0];
|
|
9
|
+
type WalletConnectSigner = providers.JsonRpcSigner;
|
|
10
10
|
declare class WalletConnectConnector extends Connector<WalletConnectProvider, WalletConnectOptions, WalletConnectSigner> {
|
|
11
11
|
#private;
|
|
12
12
|
readonly id = "walletConnect";
|
|
@@ -11,7 +11,7 @@ import { ethers } from 'ethers';
|
|
|
11
11
|
* @example
|
|
12
12
|
* type Result = CountOccurrences<['foo', 'bar', 'foo'], 'foo'>
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
type CountOccurrences<TArray extends readonly unknown[], TType> = FilterNever<[
|
|
15
15
|
...{
|
|
16
16
|
[K in keyof TArray]: TArray[K] extends TType ? TArray[K] : never;
|
|
17
17
|
}
|
|
@@ -25,7 +25,7 @@ declare type CountOccurrences<TArray extends readonly unknown[], TType> = Filter
|
|
|
25
25
|
* @example
|
|
26
26
|
* type Result = FilterNever<[1, 2, never, 3, never, 4]>
|
|
27
27
|
*/
|
|
28
|
-
|
|
28
|
+
type FilterNever<TArray extends readonly unknown[]> = TArray['length'] extends 0 ? [] : TArray extends [infer THead, ...infer TRest] ? IsNever<THead> extends true ? FilterNever<TRest> : [THead, ...FilterNever<TRest>] : never;
|
|
29
29
|
/**
|
|
30
30
|
* Check if {@link T} is `never`
|
|
31
31
|
*
|
|
@@ -35,7 +35,7 @@ declare type FilterNever<TArray extends readonly unknown[]> = TArray['length'] e
|
|
|
35
35
|
* @example
|
|
36
36
|
* type Result = IsNever<'foo'>
|
|
37
37
|
*/
|
|
38
|
-
|
|
38
|
+
type IsNever<T> = [T] extends [never] ? true : false;
|
|
39
39
|
/**
|
|
40
40
|
* Checks if {@link T} is `unknown`
|
|
41
41
|
*
|
|
@@ -45,7 +45,7 @@ declare type IsNever<T> = [T] extends [never] ? true : false;
|
|
|
45
45
|
* @example
|
|
46
46
|
* type Result = IsUnknown<unknown>
|
|
47
47
|
*/
|
|
48
|
-
|
|
48
|
+
type IsUnknown<T> = unknown extends T ? true : false;
|
|
49
49
|
/**
|
|
50
50
|
* Joins {@link Items} into string separated by {@link Separator}
|
|
51
51
|
*
|
|
@@ -56,7 +56,7 @@ declare type IsUnknown<T> = unknown extends T ? true : false;
|
|
|
56
56
|
* @example
|
|
57
57
|
* type Result = Join<['foo', 'bar'], '-'>
|
|
58
58
|
*/
|
|
59
|
-
|
|
59
|
+
type Join<Items extends string[], Separator extends string | number> = Items extends [infer First, ...infer Rest] ? First extends string ? Rest extends string[] ? Rest extends [] ? `${First}` : `${First}${Separator}${Join<Rest, Separator>}` : never : never : '';
|
|
60
60
|
/**
|
|
61
61
|
* Check if {@link T} and {@link U} are equal
|
|
62
62
|
*
|
|
@@ -67,7 +67,7 @@ declare type Join<Items extends string[], Separator extends string | number> = I
|
|
|
67
67
|
* @example
|
|
68
68
|
* type Result = NotEqual<'foo', 'bar'>
|
|
69
69
|
*/
|
|
70
|
-
|
|
70
|
+
type NotEqual<T, U> = [T] extends [U] ? false : true;
|
|
71
71
|
/**
|
|
72
72
|
* Convert {@link TKeys} of {@link TObject} to optional properties
|
|
73
73
|
*
|
|
@@ -78,7 +78,7 @@ declare type NotEqual<T, U> = [T] extends [U] ? false : true;
|
|
|
78
78
|
* @example
|
|
79
79
|
* type Result = Optional<{ foo: string; bar: number }, 'foo'>
|
|
80
80
|
*/
|
|
81
|
-
|
|
81
|
+
type Optional<TObject, TKeys extends keyof TObject> = {
|
|
82
82
|
[K in keyof TObject as K extends TKeys ? never : K]: TObject[K];
|
|
83
83
|
} & {
|
|
84
84
|
[K in keyof TObject as K extends TKeys ? K : never]?: TObject[K];
|
|
@@ -93,7 +93,7 @@ declare type Optional<TObject, TKeys extends keyof TObject> = {
|
|
|
93
93
|
* @example
|
|
94
94
|
* type Result = Or<true, false>
|
|
95
95
|
*/
|
|
96
|
-
|
|
96
|
+
type Or<T, U> = T extends true ? true : U extends true ? true : false;
|
|
97
97
|
/**
|
|
98
98
|
* Converts {@link Union} to intersection
|
|
99
99
|
*
|
|
@@ -103,13 +103,13 @@ declare type Or<T, U> = T extends true ? true : U extends true ? true : false;
|
|
|
103
103
|
* @example
|
|
104
104
|
* type Result = UnionToIntersection<'foo' | 'bar'>
|
|
105
105
|
*/
|
|
106
|
-
|
|
106
|
+
type UnionToIntersection<Union> = (Union extends unknown ? (arg: Union) => unknown : never) extends (arg: infer R) => unknown ? R : never;
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
type AbiParameter = AbiParameter$1;
|
|
109
109
|
/**
|
|
110
110
|
* Configuration options for contract types
|
|
111
111
|
*/
|
|
112
|
-
|
|
112
|
+
type Options = {
|
|
113
113
|
/** Flag for making `abi` optional */
|
|
114
114
|
isAbiOptional?: boolean;
|
|
115
115
|
/** Flag for making `address` optional */
|
|
@@ -122,7 +122,7 @@ declare type Options = {
|
|
|
122
122
|
/**
|
|
123
123
|
* Default {@link Options}
|
|
124
124
|
*/
|
|
125
|
-
|
|
125
|
+
type DefaultOptions = {
|
|
126
126
|
isAbiOptional: false;
|
|
127
127
|
isAddressOptional: false;
|
|
128
128
|
isArgsOptional: false;
|
|
@@ -139,7 +139,7 @@ declare type DefaultOptions = {
|
|
|
139
139
|
* @example
|
|
140
140
|
* type Result = GetArgs<[…], 'tokenURI'>
|
|
141
141
|
*/
|
|
142
|
-
|
|
142
|
+
type GetArgs<TAbi extends Abi | readonly unknown[], TFunction extends AbiFunction & {
|
|
143
143
|
type: 'function';
|
|
144
144
|
}, TOptions extends Options = DefaultOptions> = TFunction['inputs'] extends infer TInputs extends readonly AbiParameter[] ? Or<IsNever<TInputs>, NotEqual<TAbi, Abi>> extends true ? {
|
|
145
145
|
/**
|
|
@@ -160,7 +160,7 @@ declare type GetArgs<TAbi extends Abi | readonly unknown[], TFunction extends Ab
|
|
|
160
160
|
/**
|
|
161
161
|
* Contract configuration object for inferring function name and arguments based on {@link TAbi}.
|
|
162
162
|
*/
|
|
163
|
-
|
|
163
|
+
type ContractConfig<TContract = {
|
|
164
164
|
[key: string]: unknown;
|
|
165
165
|
}, TAbi extends Abi | readonly unknown[] = Abi, TFunctionName extends string = string, TFunction extends AbiFunction & {
|
|
166
166
|
type: 'function';
|
|
@@ -183,7 +183,7 @@ declare type ContractConfig<TContract = {
|
|
|
183
183
|
/** Function to invoke on the contract */
|
|
184
184
|
functionName: IsNever<TFunctionName> extends true ? string : TFunctionName;
|
|
185
185
|
}) & GetArgs<TAbi, TFunction, TOptions> & TContract;
|
|
186
|
-
|
|
186
|
+
type OmitConfigProperties = 'abi' | 'args' | 'functionName';
|
|
187
187
|
/**
|
|
188
188
|
* Gets configuration type of contract function
|
|
189
189
|
*
|
|
@@ -195,7 +195,7 @@ declare type OmitConfigProperties = 'abi' | 'args' | 'functionName';
|
|
|
195
195
|
* @example
|
|
196
196
|
* type Result = GetConfig<{ abi: […], functionName: 'tokenURI' }, 'view'>
|
|
197
197
|
*/
|
|
198
|
-
|
|
198
|
+
type GetConfig<TContract = unknown, TAbiStateMutibility extends AbiStateMutability = AbiStateMutability, TOptions extends Options = DefaultOptions> = TContract extends {
|
|
199
199
|
abi: infer TAbi extends Abi;
|
|
200
200
|
functionName: infer TFunctionName extends string;
|
|
201
201
|
} ? ContractConfig<Omit<TContract, OmitConfigProperties>, TAbi, ExtractAbiFunctionNames<TAbi, TAbiStateMutibility>, ExtractAbiFunction<TAbi, TFunctionName>, TOptions> : TContract extends {
|
|
@@ -212,7 +212,7 @@ declare type GetConfig<TContract = unknown, TAbiStateMutibility extends AbiState
|
|
|
212
212
|
* @example
|
|
213
213
|
* type Result = GetResult<[…], 'tokenURI'>
|
|
214
214
|
*/
|
|
215
|
-
|
|
215
|
+
type GetResult<TAbi extends Abi | readonly unknown[] = Abi, TFunctionName extends string = string, TFunction extends AbiFunction & {
|
|
216
216
|
type: 'function';
|
|
217
217
|
} = TAbi extends Abi ? ExtractAbiFunction<TAbi, TFunctionName> : never> = TFunction['outputs'] extends infer TOutputs extends readonly AbiParameter[] ? Or<IsNever<TOutputs>, NotEqual<TAbi, Abi>> extends true ? unknown : TOutputs['length'] extends infer TLength ? TLength extends 0 ? void : TLength extends 1 ? AbiParameterToPrimitiveType<TOutputs[0]> : TOutputs extends readonly [...infer _] ? /**
|
|
218
218
|
* Return output as array assigned to an object with named keys
|
|
@@ -235,21 +235,21 @@ declare type GetResult<TAbi extends Abi | readonly unknown[] = Abi, TFunctionNam
|
|
|
235
235
|
* @example
|
|
236
236
|
* type Result = GetReturnType<{ abi: […], functionName: 'tokenURI' }>
|
|
237
237
|
*/
|
|
238
|
-
|
|
238
|
+
type GetReturnType<TContract = unknown> = TContract extends {
|
|
239
239
|
abi: infer TAbi extends Abi;
|
|
240
240
|
functionName: infer TFunctionName extends string;
|
|
241
241
|
} ? GetResult<TAbi, TFunctionName, ExtractAbiFunction<TAbi, TFunctionName>> : TContract extends {
|
|
242
242
|
abi: infer TAbi extends readonly unknown[];
|
|
243
243
|
functionName: infer TFunctionName extends string;
|
|
244
244
|
} ? GetResult<TAbi, TFunctionName> : GetResult;
|
|
245
|
-
|
|
245
|
+
type MAXIMUM_DEPTH = 20;
|
|
246
246
|
/**
|
|
247
247
|
* ContractsConfig reducer recursively unwraps function arguments to infer/enforce type param
|
|
248
248
|
*
|
|
249
249
|
* @param TContracts - Array of contracts in shape of {@link ContractConfig}
|
|
250
250
|
* @returns Array of inferred contract configurations
|
|
251
251
|
*/
|
|
252
|
-
|
|
252
|
+
type ContractsConfig<TContracts extends unknown[], TContractProperties extends {
|
|
253
253
|
[key: string]: unknown;
|
|
254
254
|
} = {
|
|
255
255
|
[key: string]: unknown;
|
|
@@ -271,7 +271,7 @@ declare type ContractsConfig<TContracts extends unknown[], TContractProperties e
|
|
|
271
271
|
* @param TContracts - Array of contracts in shape of {@link ContractConfig}
|
|
272
272
|
* @returns Array of inferred contract results
|
|
273
273
|
*/
|
|
274
|
-
|
|
274
|
+
type ContractsResult<TContracts extends unknown[], Result extends any[] = [], Depth extends ReadonlyArray<number> = []> = Depth['length'] extends MAXIMUM_DEPTH ? GetReturnType[] : TContracts extends [] ? [] : TContracts extends [infer Head] ? [...Result, GetReturnType<Head>] : TContracts extends [infer Head, ...infer Tail] ? ContractsResult<[...Tail], [...Result, GetReturnType<Head>], [...Depth, 1]> : TContracts extends ContractConfig<infer _TContract, infer TAbi, infer TFunctionName>[] ? GetReturnType<{
|
|
275
275
|
abi: TAbi;
|
|
276
276
|
functionName: TFunctionName;
|
|
277
277
|
}>[] : GetReturnType[];
|
|
@@ -285,7 +285,7 @@ declare type ContractsResult<TContracts extends unknown[], Result extends any[]
|
|
|
285
285
|
* @example
|
|
286
286
|
* type Result = AbiItemName<{ type: 'function'; name: 'Foo'; … }>
|
|
287
287
|
*/
|
|
288
|
-
|
|
288
|
+
type AbiItemName<TAbiItem extends (AbiFunction & {
|
|
289
289
|
type: 'function';
|
|
290
290
|
}) | AbiEvent, IsSignature extends boolean = false> = IsSignature extends true ? TAbiItem['inputs'] extends infer TAbiParameters extends readonly AbiParameter[] ? `${TAbiItem['name']}(${Join<[
|
|
291
291
|
...{
|
|
@@ -301,7 +301,7 @@ declare type AbiItemName<TAbiItem extends (AbiFunction & {
|
|
|
301
301
|
* @example
|
|
302
302
|
* type Result = GetOverridesForAbiStateMutability<'pure'>
|
|
303
303
|
*/
|
|
304
|
-
|
|
304
|
+
type GetOverridesForAbiStateMutability<TAbiStateMutability extends AbiStateMutability> = {
|
|
305
305
|
nonpayable: Overrides & {
|
|
306
306
|
from?: Address;
|
|
307
307
|
};
|
|
@@ -325,7 +325,7 @@ interface CallOverrides extends PayableOverrides {
|
|
|
325
325
|
blockTag?: ethers.CallOverrides['blockTag'];
|
|
326
326
|
from?: Address;
|
|
327
327
|
}
|
|
328
|
-
|
|
328
|
+
type Event<TAbiEvent extends AbiEvent> = Omit<ethers.Event, 'args' | 'event' | 'eventSignature'> & {
|
|
329
329
|
args: AbiParametersToPrimitiveTypes<TAbiEvent['inputs']>;
|
|
330
330
|
event: TAbiEvent['name'];
|
|
331
331
|
eventSignature: AbiItemName<TAbiEvent, true>;
|