@wagmi/core 2.0.0-beta.7 → 2.0.0-beta.9
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/esm/actions/codegen/createReadContract.js +31 -0
- package/dist/esm/actions/codegen/createReadContract.js.map +1 -0
- package/dist/esm/actions/codegen/createSimulateContract.js +33 -0
- package/dist/esm/actions/codegen/createSimulateContract.js.map +1 -0
- package/dist/esm/actions/codegen/createWatchContractEvent.js +31 -0
- package/dist/esm/actions/codegen/createWatchContractEvent.js.map +1 -0
- package/dist/esm/actions/codegen/createWriteContract.js +43 -0
- package/dist/esm/actions/codegen/createWriteContract.js.map +1 -0
- package/dist/esm/actions/simulateContract.js +3 -0
- package/dist/esm/actions/simulateContract.js.map +1 -1
- package/dist/esm/actions/watchContractEvent.js +3 -0
- package/dist/esm/actions/watchContractEvent.js.map +1 -1
- package/dist/esm/actions/writeContract.js +3 -0
- package/dist/esm/actions/writeContract.js.map +1 -1
- package/dist/esm/exports/actions.js +1 -0
- package/dist/esm/exports/actions.js.map +1 -1
- package/dist/esm/exports/chains.js +1 -0
- package/dist/esm/exports/chains.js.map +1 -1
- package/dist/esm/exports/codegen.js +5 -0
- package/dist/esm/exports/codegen.js.map +1 -0
- package/dist/esm/exports/index.js +12 -2
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/exports/internal.js +4 -0
- package/dist/esm/exports/internal.js.map +1 -1
- package/dist/esm/exports/query.js +1 -0
- package/dist/esm/exports/query.js.map +1 -1
- package/dist/esm/transports/connector.js +17 -14
- package/dist/esm/transports/connector.js.map +1 -1
- package/dist/esm/transports/fallback.js +1 -0
- package/dist/esm/transports/fallback.js.map +1 -1
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/actions/codegen/createReadContract.d.ts +16 -0
- package/dist/types/actions/codegen/createReadContract.d.ts.map +1 -0
- package/dist/types/actions/codegen/createSimulateContract.d.ts +20 -0
- package/dist/types/actions/codegen/createSimulateContract.d.ts.map +1 -0
- package/dist/types/actions/codegen/createWatchContractEvent.d.ts +14 -0
- package/dist/types/actions/codegen/createWatchContractEvent.d.ts.map +1 -0
- package/dist/types/actions/codegen/createWriteContract.d.ts +22 -0
- package/dist/types/actions/codegen/createWriteContract.d.ts.map +1 -0
- package/dist/types/actions/simulateContract.d.ts +3 -3
- package/dist/types/actions/simulateContract.d.ts.map +1 -1
- package/dist/types/actions/watchContractEvent.d.ts +3 -3
- package/dist/types/actions/watchContractEvent.d.ts.map +1 -1
- package/dist/types/actions/writeContract.d.ts +3 -3
- package/dist/types/actions/writeContract.d.ts.map +1 -1
- package/dist/types/connectors/injected.d.ts +4 -0
- package/dist/types/connectors/injected.d.ts.map +1 -1
- package/dist/types/exports/actions.d.ts.map +1 -1
- package/dist/types/exports/chains.d.ts.map +1 -1
- package/dist/types/exports/codegen.d.ts +5 -0
- package/dist/types/exports/codegen.d.ts.map +1 -0
- package/dist/types/exports/index.d.ts.map +1 -1
- package/dist/types/exports/internal.d.ts +2 -1
- package/dist/types/exports/internal.d.ts.map +1 -1
- package/dist/types/exports/query.d.ts.map +1 -1
- package/dist/types/query/getConnectorClient.d.ts +4 -0
- package/dist/types/query/getConnectorClient.d.ts.map +1 -1
- package/dist/types/query/getWalletClient.d.ts +10 -10
- package/dist/types/query/signTypedData.d.ts +8 -8
- package/dist/types/transports/connector.d.ts +4 -4
- package/dist/types/transports/connector.d.ts.map +1 -1
- package/dist/types/transports/fallback.d.ts +1 -1
- package/dist/types/transports/fallback.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +12 -5
- package/src/actions/codegen/createReadContract.ts +100 -0
- package/src/actions/codegen/createSimulateContract.ts +122 -0
- package/src/actions/codegen/createWatchContractEvent.ts +87 -0
- package/src/actions/codegen/createWriteContract.ts +142 -0
- package/src/actions/simulateContract.ts +5 -5
- package/src/actions/watchContractEvent.ts +6 -5
- package/src/actions/writeContract.ts +5 -5
- package/src/exports/actions.ts +1 -0
- package/src/exports/chains.ts +1 -0
- package/src/exports/codegen.ts +7 -0
- package/src/exports/index.ts +14 -2
- package/src/exports/internal.ts +6 -0
- package/src/exports/query.ts +1 -0
- package/src/transports/connector.ts +52 -48
- package/src/transports/fallback.ts +2 -1
- package/src/version.ts +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wagmi/core",
|
|
3
3
|
"description": "VanillaJS library for Ethereum",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.9",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -37,6 +37,10 @@
|
|
|
37
37
|
"types": "./dist/types/exports/chains.d.ts",
|
|
38
38
|
"default": "./dist/esm/exports/chains.js"
|
|
39
39
|
},
|
|
40
|
+
"./codegen": {
|
|
41
|
+
"types": "./dist/types/exports/codegen.d.ts",
|
|
42
|
+
"default": "./dist/esm/exports/codegen.js"
|
|
43
|
+
},
|
|
40
44
|
"./internal": {
|
|
41
45
|
"types": "./dist/types/exports/internal.d.ts",
|
|
42
46
|
"default": "./dist/esm/exports/internal.js"
|
|
@@ -55,6 +59,9 @@
|
|
|
55
59
|
"chains": [
|
|
56
60
|
"./dist/types/exports/chains.d.ts"
|
|
57
61
|
],
|
|
62
|
+
"codegen": [
|
|
63
|
+
"./dist/types/exports/codegen.d.ts"
|
|
64
|
+
],
|
|
58
65
|
"internal": [
|
|
59
66
|
"./dist/types/exports/internal.d.ts"
|
|
60
67
|
],
|
|
@@ -66,7 +73,7 @@
|
|
|
66
73
|
"peerDependencies": {
|
|
67
74
|
"@tanstack/query-core": ">=5.0.0",
|
|
68
75
|
"typescript": ">=5.0.4",
|
|
69
|
-
"viem": "2.0.0-beta.
|
|
76
|
+
"viem": "2.0.0-beta.16"
|
|
70
77
|
},
|
|
71
78
|
"peerDependenciesMeta": {
|
|
72
79
|
"@tanstack/query-core": {
|
|
@@ -77,9 +84,9 @@
|
|
|
77
84
|
}
|
|
78
85
|
},
|
|
79
86
|
"dependencies": {
|
|
80
|
-
"eventemitter3": "
|
|
81
|
-
"mipd": "
|
|
82
|
-
"zustand": "
|
|
87
|
+
"eventemitter3": "5.0.1",
|
|
88
|
+
"mipd": "0.0.5",
|
|
89
|
+
"zustand": "4.4.1"
|
|
83
90
|
},
|
|
84
91
|
"contributors": [
|
|
85
92
|
"awkweb.eth <t@wevm.dev>",
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Abi,
|
|
3
|
+
type Address,
|
|
4
|
+
type ContractFunctionArgs,
|
|
5
|
+
type ContractFunctionName,
|
|
6
|
+
} from 'viem'
|
|
7
|
+
|
|
8
|
+
import { type Config } from '../../createConfig.js'
|
|
9
|
+
import { type UnionEvaluate, type UnionOmit } from '../../types/utils.js'
|
|
10
|
+
import { getAccount } from '../getAccount.js'
|
|
11
|
+
import { getChainId } from '../getChainId.js'
|
|
12
|
+
import {
|
|
13
|
+
type ReadContractParameters,
|
|
14
|
+
type ReadContractReturnType,
|
|
15
|
+
readContract,
|
|
16
|
+
} from '../readContract.js'
|
|
17
|
+
|
|
18
|
+
type stateMutability = 'pure' | 'view'
|
|
19
|
+
|
|
20
|
+
export type CreateReadContractParameters<
|
|
21
|
+
abi extends Abi | readonly unknown[],
|
|
22
|
+
address extends Address | Record<number, Address> | undefined = undefined,
|
|
23
|
+
functionName extends
|
|
24
|
+
| ContractFunctionName<abi, stateMutability>
|
|
25
|
+
| undefined = undefined,
|
|
26
|
+
> = {
|
|
27
|
+
abi: abi | Abi | readonly unknown[]
|
|
28
|
+
address?: address | Address | Record<number, Address> | undefined
|
|
29
|
+
functionName?:
|
|
30
|
+
| functionName
|
|
31
|
+
| ContractFunctionName<abi, stateMutability>
|
|
32
|
+
| undefined
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type CreateReadContractReturnType<
|
|
36
|
+
abi extends Abi | readonly unknown[],
|
|
37
|
+
address extends Address | Record<number, Address> | undefined,
|
|
38
|
+
functionName extends ContractFunctionName<abi, stateMutability> | undefined,
|
|
39
|
+
///
|
|
40
|
+
omittedProperties extends 'abi' | 'address' | 'chainId' | 'functionName' =
|
|
41
|
+
| 'abi'
|
|
42
|
+
| (address extends undefined ? never : 'address')
|
|
43
|
+
| (address extends Record<number, Address> ? 'chainId' : never)
|
|
44
|
+
| (functionName extends undefined ? never : 'functionName'),
|
|
45
|
+
> = <
|
|
46
|
+
config extends Config,
|
|
47
|
+
name extends functionName extends ContractFunctionName<abi, stateMutability>
|
|
48
|
+
? functionName
|
|
49
|
+
: ContractFunctionName<abi, stateMutability>,
|
|
50
|
+
args extends ContractFunctionArgs<abi, stateMutability, name>,
|
|
51
|
+
>(
|
|
52
|
+
config: config,
|
|
53
|
+
parameters: UnionEvaluate<
|
|
54
|
+
UnionOmit<
|
|
55
|
+
ReadContractParameters<abi, name, args, config>,
|
|
56
|
+
omittedProperties
|
|
57
|
+
>
|
|
58
|
+
> &
|
|
59
|
+
(address extends Record<number, Address>
|
|
60
|
+
? { chainId?: keyof address | undefined }
|
|
61
|
+
: unknown),
|
|
62
|
+
) => Promise<ReadContractReturnType<abi, name, args>>
|
|
63
|
+
|
|
64
|
+
export function createReadContract<
|
|
65
|
+
const abi extends Abi | readonly unknown[],
|
|
66
|
+
const address extends
|
|
67
|
+
| Address
|
|
68
|
+
| Record<number, Address>
|
|
69
|
+
| undefined = undefined,
|
|
70
|
+
functionName extends
|
|
71
|
+
| ContractFunctionName<abi, stateMutability>
|
|
72
|
+
| undefined = undefined,
|
|
73
|
+
>(
|
|
74
|
+
c: CreateReadContractParameters<abi, address, functionName>,
|
|
75
|
+
): CreateReadContractReturnType<abi, address, functionName> {
|
|
76
|
+
if (c.address !== undefined && typeof c.address === 'object')
|
|
77
|
+
return (config, parameters) => {
|
|
78
|
+
const configChainId = getChainId(config)
|
|
79
|
+
const account = getAccount(config)
|
|
80
|
+
const chainId =
|
|
81
|
+
(parameters as { chainId?: number })?.chainId ??
|
|
82
|
+
account.chainId ??
|
|
83
|
+
configChainId
|
|
84
|
+
return readContract(config, {
|
|
85
|
+
...(parameters as any),
|
|
86
|
+
...(c.functionName ? { functionName: c.functionName } : {}),
|
|
87
|
+
address: c.address?.[chainId],
|
|
88
|
+
abi: c.abi,
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return (config, parameters) => {
|
|
93
|
+
return readContract(config, {
|
|
94
|
+
...(parameters as any),
|
|
95
|
+
...(c.address ? { address: c.address } : {}),
|
|
96
|
+
...(c.functionName ? { functionName: c.functionName } : {}),
|
|
97
|
+
abi: c.abi,
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Abi,
|
|
3
|
+
type Account,
|
|
4
|
+
type Address,
|
|
5
|
+
type Chain,
|
|
6
|
+
type ContractFunctionArgs,
|
|
7
|
+
type ContractFunctionName,
|
|
8
|
+
type SimulateContractParameters as viem_SimulateContractParameters,
|
|
9
|
+
} from 'viem'
|
|
10
|
+
|
|
11
|
+
import { type Config } from '../../createConfig.js'
|
|
12
|
+
import { type SelectChains } from '../../types/chain.js'
|
|
13
|
+
import {
|
|
14
|
+
type ChainIdParameter,
|
|
15
|
+
type ConnectorParameter,
|
|
16
|
+
} from '../../types/properties.js'
|
|
17
|
+
import { type UnionEvaluate, type UnionOmit } from '../../types/utils.js'
|
|
18
|
+
import { getAccount } from '../getAccount.js'
|
|
19
|
+
import { getChainId } from '../getChainId.js'
|
|
20
|
+
import {
|
|
21
|
+
type SimulateContractReturnType,
|
|
22
|
+
simulateContract,
|
|
23
|
+
} from '../simulateContract.js'
|
|
24
|
+
|
|
25
|
+
type stateMutability = 'nonpayable' | 'payable'
|
|
26
|
+
|
|
27
|
+
export type CreateSimulateContractParameters<
|
|
28
|
+
abi extends Abi | readonly unknown[],
|
|
29
|
+
address extends Address | Record<number, Address> | undefined = undefined,
|
|
30
|
+
functionName extends
|
|
31
|
+
| ContractFunctionName<abi, stateMutability>
|
|
32
|
+
| undefined = undefined,
|
|
33
|
+
> = {
|
|
34
|
+
abi: abi | Abi | readonly unknown[]
|
|
35
|
+
address?: address | Address | Record<number, Address> | undefined
|
|
36
|
+
functionName?:
|
|
37
|
+
| functionName
|
|
38
|
+
| ContractFunctionName<abi, stateMutability>
|
|
39
|
+
| undefined
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type CreateSimulateContractReturnType<
|
|
43
|
+
abi extends Abi | readonly unknown[],
|
|
44
|
+
address extends Address | Record<number, Address> | undefined,
|
|
45
|
+
functionName extends ContractFunctionName<abi, stateMutability> | undefined,
|
|
46
|
+
> = <
|
|
47
|
+
config extends Config,
|
|
48
|
+
name extends functionName extends ContractFunctionName<abi, stateMutability>
|
|
49
|
+
? functionName
|
|
50
|
+
: ContractFunctionName<abi, stateMutability>,
|
|
51
|
+
args extends ContractFunctionArgs<abi, stateMutability, name>,
|
|
52
|
+
chainId extends config['chains'][number]['id'] | undefined = undefined,
|
|
53
|
+
///
|
|
54
|
+
chains extends readonly Chain[] = SelectChains<config, chainId>,
|
|
55
|
+
>(
|
|
56
|
+
config: config,
|
|
57
|
+
parameters: {
|
|
58
|
+
[key in keyof chains]: UnionEvaluate<
|
|
59
|
+
UnionOmit<
|
|
60
|
+
viem_SimulateContractParameters<
|
|
61
|
+
abi,
|
|
62
|
+
name,
|
|
63
|
+
args,
|
|
64
|
+
chains[key],
|
|
65
|
+
chains[key],
|
|
66
|
+
Account | Address
|
|
67
|
+
>,
|
|
68
|
+
| 'abi'
|
|
69
|
+
| 'chain'
|
|
70
|
+
| (address extends undefined ? never : 'address')
|
|
71
|
+
| (functionName extends undefined ? never : 'functionName')
|
|
72
|
+
>
|
|
73
|
+
> &
|
|
74
|
+
ChainIdParameter<config, chainId> &
|
|
75
|
+
ConnectorParameter & {
|
|
76
|
+
chainId?: address extends Record<number, Address>
|
|
77
|
+
?
|
|
78
|
+
| keyof address
|
|
79
|
+
| (chainId extends keyof address ? chainId : never)
|
|
80
|
+
| undefined
|
|
81
|
+
: chainId | number | undefined
|
|
82
|
+
}
|
|
83
|
+
}[number],
|
|
84
|
+
) => Promise<SimulateContractReturnType<abi, name, args, config, chainId>>
|
|
85
|
+
|
|
86
|
+
export function createSimulateContract<
|
|
87
|
+
const abi extends Abi | readonly unknown[],
|
|
88
|
+
const address extends
|
|
89
|
+
| Address
|
|
90
|
+
| Record<number, Address>
|
|
91
|
+
| undefined = undefined,
|
|
92
|
+
functionName extends
|
|
93
|
+
| ContractFunctionName<abi, stateMutability>
|
|
94
|
+
| undefined = undefined,
|
|
95
|
+
>(
|
|
96
|
+
c: CreateSimulateContractParameters<abi, address, functionName>,
|
|
97
|
+
): CreateSimulateContractReturnType<abi, address, functionName> {
|
|
98
|
+
if (c.address !== undefined && typeof c.address === 'object')
|
|
99
|
+
return (config, parameters) => {
|
|
100
|
+
const configChainId = getChainId(config)
|
|
101
|
+
const account = getAccount(config)
|
|
102
|
+
const chainId =
|
|
103
|
+
(parameters as { chainId?: number })?.chainId ??
|
|
104
|
+
account.chainId ??
|
|
105
|
+
configChainId
|
|
106
|
+
return simulateContract(config, {
|
|
107
|
+
...(parameters as any),
|
|
108
|
+
...(c.functionName ? { functionName: c.functionName } : {}),
|
|
109
|
+
address: c.address?.[chainId],
|
|
110
|
+
abi: c.abi,
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return (config, parameters) => {
|
|
115
|
+
return simulateContract(config, {
|
|
116
|
+
...(parameters as any),
|
|
117
|
+
...(c.address ? { address: c.address } : {}),
|
|
118
|
+
...(c.functionName ? { functionName: c.functionName } : {}),
|
|
119
|
+
abi: c.abi,
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { type Abi, type Address, type ContractEventName } from 'viem'
|
|
2
|
+
|
|
3
|
+
import { type Config } from '../../createConfig.js'
|
|
4
|
+
import { type UnionEvaluate, type UnionOmit } from '../../types/utils.js'
|
|
5
|
+
import { getAccount } from '../getAccount.js'
|
|
6
|
+
import { getChainId } from '../getChainId.js'
|
|
7
|
+
import {
|
|
8
|
+
type WatchContractEventParameters,
|
|
9
|
+
type WatchContractEventReturnType,
|
|
10
|
+
watchContractEvent,
|
|
11
|
+
} from '../watchContractEvent.js'
|
|
12
|
+
|
|
13
|
+
export type CreateWatchContractEventParameters<
|
|
14
|
+
abi extends Abi | readonly unknown[],
|
|
15
|
+
address extends Address | Record<number, Address> | undefined = undefined,
|
|
16
|
+
eventName extends ContractEventName<abi> | undefined = undefined,
|
|
17
|
+
> = {
|
|
18
|
+
abi: abi | Abi | readonly unknown[]
|
|
19
|
+
address?: address | Address | Record<number, Address> | undefined
|
|
20
|
+
eventName?: eventName | ContractEventName<abi> | undefined
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type CreateWatchContractEventReturnType<
|
|
24
|
+
abi extends Abi | readonly unknown[],
|
|
25
|
+
address extends Address | Record<number, Address> | undefined,
|
|
26
|
+
eventName extends ContractEventName<abi> | undefined,
|
|
27
|
+
///
|
|
28
|
+
omittedProperties extends 'abi' | 'address' | 'chainId' | 'eventName' =
|
|
29
|
+
| 'abi'
|
|
30
|
+
| (address extends undefined ? never : 'address')
|
|
31
|
+
| (address extends Record<number, Address> ? 'chainId' : never)
|
|
32
|
+
| (eventName extends undefined ? never : 'eventName'),
|
|
33
|
+
> = <
|
|
34
|
+
config extends Config,
|
|
35
|
+
name extends eventName extends ContractEventName<abi>
|
|
36
|
+
? eventName
|
|
37
|
+
: ContractEventName<abi>,
|
|
38
|
+
strict extends boolean | undefined = undefined,
|
|
39
|
+
chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
|
|
40
|
+
>(
|
|
41
|
+
config: config,
|
|
42
|
+
parameters: UnionEvaluate<
|
|
43
|
+
UnionOmit<
|
|
44
|
+
WatchContractEventParameters<abi, name, strict, config, chainId>,
|
|
45
|
+
omittedProperties
|
|
46
|
+
>
|
|
47
|
+
> &
|
|
48
|
+
(address extends Record<number, Address>
|
|
49
|
+
? { chainId?: keyof address | undefined }
|
|
50
|
+
: unknown),
|
|
51
|
+
) => WatchContractEventReturnType
|
|
52
|
+
|
|
53
|
+
export function createWatchContractEvent<
|
|
54
|
+
const abi extends Abi | readonly unknown[],
|
|
55
|
+
const address extends
|
|
56
|
+
| Address
|
|
57
|
+
| Record<number, Address>
|
|
58
|
+
| undefined = undefined,
|
|
59
|
+
eventName extends ContractEventName<abi> | undefined = undefined,
|
|
60
|
+
>(
|
|
61
|
+
c: CreateWatchContractEventParameters<abi, address, eventName>,
|
|
62
|
+
): CreateWatchContractEventReturnType<abi, address, eventName> {
|
|
63
|
+
if (c.address !== undefined && typeof c.address === 'object')
|
|
64
|
+
return (config, parameters) => {
|
|
65
|
+
const configChainId = getChainId(config)
|
|
66
|
+
const account = getAccount(config)
|
|
67
|
+
const chainId =
|
|
68
|
+
(parameters as { chainId?: number })?.chainId ??
|
|
69
|
+
account.chainId ??
|
|
70
|
+
configChainId
|
|
71
|
+
return watchContractEvent(config, {
|
|
72
|
+
...(parameters as any),
|
|
73
|
+
...(c.eventName ? { functionName: c.eventName } : {}),
|
|
74
|
+
address: c.address?.[chainId],
|
|
75
|
+
abi: c.abi,
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return (config, parameters) => {
|
|
80
|
+
return watchContractEvent(config, {
|
|
81
|
+
...(parameters as any),
|
|
82
|
+
...(c.address ? { address: c.address } : {}),
|
|
83
|
+
...(c.eventName ? { functionName: c.eventName } : {}),
|
|
84
|
+
abi: c.abi,
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Abi,
|
|
3
|
+
type Account,
|
|
4
|
+
type Address,
|
|
5
|
+
type Chain,
|
|
6
|
+
type ContractFunctionArgs,
|
|
7
|
+
type ContractFunctionName,
|
|
8
|
+
type WriteContractParameters as viem_WriteContractParameters,
|
|
9
|
+
} from 'viem'
|
|
10
|
+
|
|
11
|
+
import { type Config } from '../../createConfig.js'
|
|
12
|
+
import { type SelectChains } from '../../types/chain.js'
|
|
13
|
+
import {
|
|
14
|
+
type ChainIdParameter,
|
|
15
|
+
type ConnectorParameter,
|
|
16
|
+
} from '../../types/properties.js'
|
|
17
|
+
import {
|
|
18
|
+
type Evaluate,
|
|
19
|
+
type UnionEvaluate,
|
|
20
|
+
type UnionOmit,
|
|
21
|
+
} from '../../types/utils.js'
|
|
22
|
+
import { getAccount } from '../getAccount.js'
|
|
23
|
+
import { getChainId } from '../getChainId.js'
|
|
24
|
+
import {
|
|
25
|
+
type WriteContractReturnType,
|
|
26
|
+
writeContract,
|
|
27
|
+
} from '../writeContract.js'
|
|
28
|
+
|
|
29
|
+
type stateMutability = 'nonpayable' | 'payable'
|
|
30
|
+
|
|
31
|
+
export type CreateWriteContractParameters<
|
|
32
|
+
abi extends Abi | readonly unknown[],
|
|
33
|
+
address extends Address | Record<number, Address> | undefined = undefined,
|
|
34
|
+
functionName extends
|
|
35
|
+
| ContractFunctionName<abi, stateMutability>
|
|
36
|
+
| undefined = undefined,
|
|
37
|
+
> = {
|
|
38
|
+
abi: abi | Abi | readonly unknown[]
|
|
39
|
+
address?: address | Address | Record<number, Address> | undefined
|
|
40
|
+
functionName?:
|
|
41
|
+
| functionName
|
|
42
|
+
| ContractFunctionName<abi, stateMutability>
|
|
43
|
+
| undefined
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type CreateWriteContractReturnType<
|
|
47
|
+
abi extends Abi | readonly unknown[],
|
|
48
|
+
address extends Address | Record<number, Address> | undefined,
|
|
49
|
+
functionName extends ContractFunctionName<abi, stateMutability> | undefined,
|
|
50
|
+
> = <
|
|
51
|
+
config extends Config,
|
|
52
|
+
name extends functionName extends ContractFunctionName<abi, stateMutability>
|
|
53
|
+
? functionName
|
|
54
|
+
: ContractFunctionName<abi, stateMutability>,
|
|
55
|
+
args extends ContractFunctionArgs<abi, stateMutability, name>,
|
|
56
|
+
chainId extends config['chains'][number]['id'],
|
|
57
|
+
///
|
|
58
|
+
allFunctionNames = ContractFunctionName<abi, 'nonpayable' | 'payable'>,
|
|
59
|
+
chains extends readonly Chain[] = SelectChains<config, chainId>,
|
|
60
|
+
omittedProperties extends 'abi' | 'address' | 'functionName' =
|
|
61
|
+
| 'abi'
|
|
62
|
+
| (address extends undefined ? never : 'address')
|
|
63
|
+
| (functionName extends undefined ? never : 'functionName'),
|
|
64
|
+
>(
|
|
65
|
+
config: config,
|
|
66
|
+
parameters: UnionEvaluate<
|
|
67
|
+
{
|
|
68
|
+
[key in keyof chains]: UnionOmit<
|
|
69
|
+
viem_WriteContractParameters<
|
|
70
|
+
abi,
|
|
71
|
+
name,
|
|
72
|
+
args,
|
|
73
|
+
chains[key],
|
|
74
|
+
Account,
|
|
75
|
+
chains[key],
|
|
76
|
+
allFunctionNames
|
|
77
|
+
>,
|
|
78
|
+
omittedProperties | 'chain'
|
|
79
|
+
>
|
|
80
|
+
}[number] &
|
|
81
|
+
(address extends Record<number, Address>
|
|
82
|
+
? {
|
|
83
|
+
chainId?:
|
|
84
|
+
| keyof address
|
|
85
|
+
| (chainId extends keyof address ? chainId : never)
|
|
86
|
+
| undefined
|
|
87
|
+
}
|
|
88
|
+
: Evaluate<ChainIdParameter<config, chainId>>) &
|
|
89
|
+
ConnectorParameter & { __mode?: 'prepared' }
|
|
90
|
+
>,
|
|
91
|
+
) => Promise<WriteContractReturnType>
|
|
92
|
+
|
|
93
|
+
export function createWriteContract<
|
|
94
|
+
const abi extends Abi | readonly unknown[],
|
|
95
|
+
const address extends
|
|
96
|
+
| Address
|
|
97
|
+
| Record<number, Address>
|
|
98
|
+
| undefined = undefined,
|
|
99
|
+
functionName extends
|
|
100
|
+
| ContractFunctionName<abi, stateMutability>
|
|
101
|
+
| undefined = undefined,
|
|
102
|
+
>(
|
|
103
|
+
c: CreateWriteContractParameters<abi, address, functionName>,
|
|
104
|
+
): CreateWriteContractReturnType<abi, address, functionName> {
|
|
105
|
+
if (c.address !== undefined && typeof c.address === 'object')
|
|
106
|
+
return (config, parameters) => {
|
|
107
|
+
const configChainId = getChainId(config)
|
|
108
|
+
const account = getAccount(config)
|
|
109
|
+
|
|
110
|
+
let chainId
|
|
111
|
+
if (parameters.chainId) chainId = parameters.chainId
|
|
112
|
+
else if (
|
|
113
|
+
(parameters as unknown as { account: Address | Account | undefined })
|
|
114
|
+
.account &&
|
|
115
|
+
(parameters as unknown as { account: Address | Account | undefined })
|
|
116
|
+
.account === account.address
|
|
117
|
+
)
|
|
118
|
+
chainId = account.chainId
|
|
119
|
+
else if (
|
|
120
|
+
(parameters as unknown as { account: Address | Account | undefined })
|
|
121
|
+
.account === undefined
|
|
122
|
+
)
|
|
123
|
+
chainId = account.chainId
|
|
124
|
+
else chainId = configChainId
|
|
125
|
+
|
|
126
|
+
return writeContract(config, {
|
|
127
|
+
...(parameters as any),
|
|
128
|
+
...(c.functionName ? { functionName: c.functionName } : {}),
|
|
129
|
+
address: chainId ? c.address?.[chainId] : undefined,
|
|
130
|
+
abi: c.abi,
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return (config, parameters) => {
|
|
135
|
+
return writeContract(config, {
|
|
136
|
+
...(parameters as any),
|
|
137
|
+
...(c.address ? { address: c.address } : {}),
|
|
138
|
+
...(c.functionName ? { functionName: c.functionName } : {}),
|
|
139
|
+
abi: c.abi,
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -14,11 +14,11 @@ import {
|
|
|
14
14
|
} from 'viem/actions'
|
|
15
15
|
|
|
16
16
|
import { type Config } from '../createConfig.js'
|
|
17
|
-
import type
|
|
18
|
-
import type
|
|
19
|
-
import
|
|
20
|
-
ChainIdParameter,
|
|
21
|
-
ConnectorParameter,
|
|
17
|
+
import { type BaseErrorType, type ErrorType } from '../errors/base.js'
|
|
18
|
+
import { type SelectChains } from '../types/chain.js'
|
|
19
|
+
import {
|
|
20
|
+
type ChainIdParameter,
|
|
21
|
+
type ConnectorParameter,
|
|
22
22
|
} from '../types/properties.js'
|
|
23
23
|
import type { PartialBy, UnionEvaluate, UnionOmit } from '../types/utils.js'
|
|
24
24
|
import {
|
|
@@ -10,13 +10,14 @@ import {
|
|
|
10
10
|
type WatchContractEventReturnType as viem_WatchContractEventReturnType,
|
|
11
11
|
watchContractEvent as viem_watchContractEvent,
|
|
12
12
|
} from 'viem/actions'
|
|
13
|
+
|
|
13
14
|
import { type Config } from '../createConfig.js'
|
|
14
|
-
import type
|
|
15
|
-
import
|
|
16
|
-
ChainIdParameter,
|
|
17
|
-
SyncConnectedChainParameter,
|
|
15
|
+
import { type SelectChains } from '../types/chain.js'
|
|
16
|
+
import {
|
|
17
|
+
type ChainIdParameter,
|
|
18
|
+
type SyncConnectedChainParameter,
|
|
18
19
|
} from '../types/properties.js'
|
|
19
|
-
import type
|
|
20
|
+
import { type UnionEvaluate } from '../types/utils.js'
|
|
20
21
|
|
|
21
22
|
export type WatchContractEventParameters<
|
|
22
23
|
abi extends Abi | readonly unknown[] = Abi,
|
|
@@ -13,11 +13,11 @@ import {
|
|
|
13
13
|
} from 'viem/actions'
|
|
14
14
|
|
|
15
15
|
import { type Config } from '../createConfig.js'
|
|
16
|
-
import type
|
|
17
|
-
import type
|
|
18
|
-
import
|
|
19
|
-
ChainIdParameter,
|
|
20
|
-
ConnectorParameter,
|
|
16
|
+
import { type BaseErrorType, type ErrorType } from '../errors/base.js'
|
|
17
|
+
import { type SelectChains } from '../types/chain.js'
|
|
18
|
+
import {
|
|
19
|
+
type ChainIdParameter,
|
|
20
|
+
type ConnectorParameter,
|
|
21
21
|
} from '../types/properties.js'
|
|
22
22
|
import type { Evaluate, UnionEvaluate, UnionOmit } from '../types/utils.js'
|
|
23
23
|
import {
|
package/src/exports/actions.ts
CHANGED
package/src/exports/chains.ts
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createSimulateContract } from '../actions/codegen/createSimulateContract.js'
|
|
2
|
+
|
|
3
|
+
export { createReadContract } from '../actions/codegen/createReadContract.js'
|
|
4
|
+
|
|
5
|
+
export { createWatchContractEvent } from '../actions/codegen/createWatchContractEvent.js'
|
|
6
|
+
|
|
7
|
+
export { createWriteContract } from '../actions/codegen/createWriteContract.js'
|
package/src/exports/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
////////////////////////////////////////////////////////////////////////////////
|
|
2
2
|
// Actions
|
|
3
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
3
4
|
|
|
4
5
|
export {
|
|
5
6
|
type ConnectErrorType,
|
|
@@ -309,7 +310,8 @@ export {
|
|
|
309
310
|
} from '../actions/writeContract.js'
|
|
310
311
|
|
|
311
312
|
////////////////////////////////////////////////////////////////////////////////
|
|
312
|
-
//
|
|
313
|
+
// Connectors
|
|
314
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
313
315
|
|
|
314
316
|
export {
|
|
315
317
|
type ConnectorEventMap,
|
|
@@ -329,6 +331,7 @@ export {
|
|
|
329
331
|
|
|
330
332
|
////////////////////////////////////////////////////////////////////////////////
|
|
331
333
|
// createConfig
|
|
334
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
332
335
|
|
|
333
336
|
export {
|
|
334
337
|
type Connection,
|
|
@@ -341,6 +344,7 @@ export {
|
|
|
341
344
|
|
|
342
345
|
////////////////////////////////////////////////////////////////////////////////
|
|
343
346
|
// createStorage
|
|
347
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
344
348
|
|
|
345
349
|
export {
|
|
346
350
|
type CreateStorageParameters,
|
|
@@ -351,12 +355,14 @@ export {
|
|
|
351
355
|
} from '../createStorage.js'
|
|
352
356
|
|
|
353
357
|
////////////////////////////////////////////////////////////////////////////////
|
|
354
|
-
//
|
|
358
|
+
// Hydrate
|
|
359
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
355
360
|
|
|
356
361
|
export { hydrate } from '../hydrate.js'
|
|
357
362
|
|
|
358
363
|
////////////////////////////////////////////////////////////////////////////////
|
|
359
364
|
// Errors
|
|
365
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
360
366
|
|
|
361
367
|
export { BaseError } from '../errors/base.js'
|
|
362
368
|
|
|
@@ -382,18 +388,23 @@ export {
|
|
|
382
388
|
|
|
383
389
|
////////////////////////////////////////////////////////////////////////////////
|
|
384
390
|
// Transports
|
|
391
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
385
392
|
|
|
386
393
|
export { custom, http, webSocket } from 'viem'
|
|
394
|
+
|
|
387
395
|
export { unstable_connector } from '../transports/connector.js'
|
|
396
|
+
|
|
388
397
|
export { fallback } from '../transports/fallback.js'
|
|
389
398
|
|
|
390
399
|
////////////////////////////////////////////////////////////////////////////////
|
|
391
400
|
// Types
|
|
401
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
392
402
|
|
|
393
403
|
export { type Register, type ResolvedRegister } from '../types/register.js'
|
|
394
404
|
|
|
395
405
|
////////////////////////////////////////////////////////////////////////////////
|
|
396
406
|
// Utilities
|
|
407
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
397
408
|
|
|
398
409
|
export {
|
|
399
410
|
cookieStorage,
|
|
@@ -411,5 +422,6 @@ export { serialize } from '../utils/serialize.js'
|
|
|
411
422
|
|
|
412
423
|
////////////////////////////////////////////////////////////////////////////////
|
|
413
424
|
// Version
|
|
425
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
414
426
|
|
|
415
427
|
export { version } from '../version.js'
|