viem 0.0.0-w-20230816184753 → 0.0.0-w-20230818170445
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/cjs/actions/public/multicall.js +3 -6
- package/dist/cjs/actions/public/multicall.js.map +1 -1
- package/dist/cjs/clients/decorators/public.js.map +1 -1
- package/dist/cjs/constants/number.js +96 -96
- package/dist/cjs/constants/number.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/actions/public/multicall.js +4 -7
- package/dist/esm/actions/public/multicall.js.map +1 -1
- package/dist/esm/clients/decorators/public.js.map +1 -1
- package/dist/esm/constants/number.js +96 -96
- package/dist/esm/constants/number.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/actions/public/multicall.d.ts +16 -10
- package/dist/types/actions/public/multicall.d.ts.map +1 -1
- package/dist/types/clients/decorators/public.d.ts +2 -2
- package/dist/types/clients/decorators/public.d.ts.map +1 -1
- package/dist/types/constants/number.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/contract.d.ts +21 -3
- package/dist/types/types/contract.d.ts.map +1 -1
- package/dist/types/types/multicall.d.ts +60 -37
- package/dist/types/types/multicall.d.ts.map +1 -1
- package/dist/types/types/utils.d.ts +8 -0
- package/dist/types/types/utils.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +3 -3
- package/src/actions/public/multicall.ts +25 -37
- package/src/clients/decorators/public.ts +5 -11
- package/src/constants/number.ts +96 -96
- package/src/index.ts +1 -1
- package/src/types/contract.ts +106 -1
- package/src/types/multicall.ts +181 -90
- package/src/types/utils.ts +33 -0
- package/src/version.ts +1 -1
package/package.json
CHANGED
@@ -7,9 +7,9 @@
|
|
7
7
|
"@noble/hashes": "1.3.0",
|
8
8
|
"@scure/bip32": "1.3.0",
|
9
9
|
"@scure/bip39": "1.2.0",
|
10
|
-
"@types/ws": "
|
10
|
+
"@types/ws": "8.5.4",
|
11
11
|
"@wagmi/chains": "1.7.0",
|
12
|
-
"abitype": "0.9.
|
12
|
+
"abitype": "0.9.8",
|
13
13
|
"isomorphic-ws": "5.0.0",
|
14
14
|
"ws": "8.12.0"
|
15
15
|
},
|
@@ -21,7 +21,7 @@
|
|
21
21
|
"optional": true
|
22
22
|
}
|
23
23
|
},
|
24
|
-
"version": "0.0.0-w-
|
24
|
+
"version": "0.0.0-w-20230818170445",
|
25
25
|
"files": [
|
26
26
|
"dist",
|
27
27
|
"!dist/**/*.tsbuildinfo",
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type {
|
1
|
+
import type { Address, Narrow } from 'abitype'
|
2
2
|
|
3
3
|
import type { Client } from '../../clients/createClient.js'
|
4
4
|
import type { Transport } from '../../clients/transports/createTransport.js'
|
@@ -7,10 +7,6 @@ import { AbiDecodingZeroDataError } from '../../errors/abi.js'
|
|
7
7
|
import type { BaseError } from '../../errors/base.js'
|
8
8
|
import { RawContractError } from '../../errors/contract.js'
|
9
9
|
import type { Chain } from '../../types/chain.js'
|
10
|
-
import type {
|
11
|
-
ContractFunctionConfig,
|
12
|
-
ContractParameters,
|
13
|
-
} from '../../types/contract.js'
|
14
10
|
import type { Hex } from '../../types/misc.js'
|
15
11
|
import type {
|
16
12
|
MulticallContract,
|
@@ -18,10 +14,7 @@ import type {
|
|
18
14
|
MulticallResults,
|
19
15
|
} from '../../types/multicall.js'
|
20
16
|
import { decodeFunctionResult } from '../../utils/abi/decodeFunctionResult.js'
|
21
|
-
import {
|
22
|
-
type EncodeFunctionDataParameters,
|
23
|
-
encodeFunctionData,
|
24
|
-
} from '../../utils/abi/encodeFunctionData.js'
|
17
|
+
import { encodeFunctionData } from '../../utils/abi/encodeFunctionData.js'
|
25
18
|
import { getChainContractAddress } from '../../utils/chain.js'
|
26
19
|
import { getContractError } from '../../utils/errors/getContractError.js'
|
27
20
|
|
@@ -29,23 +22,33 @@ import type { CallParameters } from './call.js'
|
|
29
22
|
import { readContract } from './readContract.js'
|
30
23
|
|
31
24
|
export type MulticallParameters<
|
32
|
-
contracts extends readonly
|
25
|
+
contracts extends readonly unknown[] = readonly MulticallContract[],
|
33
26
|
allowFailure extends boolean = true,
|
27
|
+
options extends {
|
28
|
+
optional?: boolean
|
29
|
+
properties?: Record<string, any>
|
30
|
+
} = {},
|
34
31
|
> = Pick<CallParameters, 'blockNumber' | 'blockTag'> & {
|
35
32
|
allowFailure?: allowFailure | undefined
|
36
|
-
/**
|
37
|
-
* The maximum size (in bytes) for each calldata chunk. Set to `0` to disable the size limit.
|
38
|
-
* @default 1_024
|
39
|
-
*/
|
40
33
|
batchSize?: number | undefined
|
41
|
-
contracts:
|
34
|
+
contracts: MulticallContracts<
|
35
|
+
Narrow<contracts>,
|
36
|
+
{ mutability: 'pure' | 'view' } & options
|
37
|
+
>
|
42
38
|
multicallAddress?: Address | undefined
|
43
39
|
}
|
44
40
|
|
45
41
|
export type MulticallReturnType<
|
46
|
-
contracts extends readonly
|
42
|
+
contracts extends readonly unknown[] = readonly MulticallContract[],
|
47
43
|
allowFailure extends boolean = true,
|
48
|
-
|
44
|
+
options extends {
|
45
|
+
error?: Error
|
46
|
+
} = { error: Error },
|
47
|
+
> = MulticallResults<
|
48
|
+
contracts,
|
49
|
+
allowFailure,
|
50
|
+
{ mutability: 'pure' | 'view' } & options
|
51
|
+
>
|
49
52
|
|
50
53
|
/**
|
51
54
|
* Similar to [`readContract`](https://viem.sh/docs/contract/readContract.html), but batches up multiple functions on a contract in a single RPC call via the [`multicall3` contract](https://github.com/mds1/multicall).
|
@@ -87,13 +90,7 @@ export type MulticallReturnType<
|
|
87
90
|
* // [{ result: 424122n, status: 'success' }, { result: 1000000n, status: 'success' }]
|
88
91
|
*/
|
89
92
|
export async function multicall<
|
90
|
-
const
|
91
|
-
functionName extends string,
|
92
|
-
const contracts extends readonly ContractParameters<
|
93
|
-
abi,
|
94
|
-
'pure' | 'view',
|
95
|
-
functionName
|
96
|
-
>[],
|
93
|
+
const contracts extends readonly unknown[],
|
97
94
|
chain extends Chain | undefined,
|
98
95
|
allowFailure extends boolean = true,
|
99
96
|
>(
|
@@ -105,9 +102,9 @@ export async function multicall<
|
|
105
102
|
batchSize: batchSize_,
|
106
103
|
blockNumber,
|
107
104
|
blockTag,
|
108
|
-
contracts,
|
109
105
|
multicallAddress: multicallAddress_,
|
110
106
|
} = parameters
|
107
|
+
const contracts = parameters.contracts as MulticallContract[]
|
111
108
|
|
112
109
|
const batchSize =
|
113
110
|
batchSize_ ??
|
@@ -139,16 +136,9 @@ export async function multicall<
|
|
139
136
|
let currentChunk = 0
|
140
137
|
let currentChunkSize = 0
|
141
138
|
for (let i = 0; i < contracts.length; i++) {
|
142
|
-
const { abi, address, args, functionName } = contracts[
|
143
|
-
i
|
144
|
-
] as ContractFunctionConfig
|
139
|
+
const { abi, address, args, functionName } = contracts[i]
|
145
140
|
try {
|
146
|
-
const callData = encodeFunctionData({
|
147
|
-
abi,
|
148
|
-
args,
|
149
|
-
functionName,
|
150
|
-
} as unknown as EncodeFunctionDataParameters)
|
151
|
-
|
141
|
+
const callData = encodeFunctionData({ abi, args, functionName })
|
152
142
|
currentChunkSize += callData.length
|
153
143
|
if (batchSize > 0 && currentChunkSize > batchSize) {
|
154
144
|
currentChunk++
|
@@ -200,9 +190,7 @@ export async function multicall<
|
|
200
190
|
return results.flat().map(({ returnData, success }, i) => {
|
201
191
|
const calls = chunkedCalls.flat()
|
202
192
|
const { callData } = calls[i]
|
203
|
-
const { abi, address, functionName, args } = contracts[
|
204
|
-
i
|
205
|
-
] as ContractFunctionConfig
|
193
|
+
const { abi, address, functionName, args } = contracts[i]
|
206
194
|
try {
|
207
195
|
if (callData === '0x') throw new AbiDecodingZeroDataError()
|
208
196
|
if (!success) throw new RawContractError({ data: returnData })
|
@@ -200,7 +200,6 @@ import type { Account } from '../../types/account.js'
|
|
200
200
|
import type { BlockNumber, BlockTag } from '../../types/block.js'
|
201
201
|
import type { Chain } from '../../types/chain.js'
|
202
202
|
import type {
|
203
|
-
ContractFunctionConfig,
|
204
203
|
MaybeAbiEventName,
|
205
204
|
MaybeExtractEventArgsFromAbi,
|
206
205
|
} from '../../types/contract.js'
|
@@ -1133,16 +1132,11 @@ export type PublicActions<
|
|
1133
1132
|
* // [{ result: 424122n, status: 'success' }, { result: 1000000n, status: 'success' }]
|
1134
1133
|
*/
|
1135
1134
|
multicall: <
|
1136
|
-
const
|
1137
|
-
|
1138
|
-
const TContracts extends readonly ContractFunctionConfig<
|
1139
|
-
TAbi,
|
1140
|
-
TFunctionName
|
1141
|
-
>[],
|
1142
|
-
TAllowFailure extends boolean = true,
|
1135
|
+
const contracts extends readonly unknown[],
|
1136
|
+
allowFailure extends boolean = true,
|
1143
1137
|
>(
|
1144
|
-
args: MulticallParameters<
|
1145
|
-
) => Promise<MulticallReturnType<
|
1138
|
+
args: MulticallParameters<contracts, allowFailure>,
|
1139
|
+
) => Promise<MulticallReturnType<contracts, allowFailure>>
|
1146
1140
|
/**
|
1147
1141
|
* Calls a read-only function on a contract, and returns the response.
|
1148
1142
|
*
|
@@ -1507,7 +1501,7 @@ export function publicActions<
|
|
1507
1501
|
getTransactionConfirmations(client, args),
|
1508
1502
|
getTransactionCount: (args) => getTransactionCount(client, args),
|
1509
1503
|
getTransactionReceipt: (args) => getTransactionReceipt(client, args),
|
1510
|
-
multicall: (args) => multicall(client, args
|
1504
|
+
multicall: (args) => multicall(client, args),
|
1511
1505
|
readContract: (args) => readContract(client, args),
|
1512
1506
|
simulateContract: (args) => simulateContract(client, args),
|
1513
1507
|
verifyMessage: (args) => verifyMessage(client, args),
|
package/src/constants/number.ts
CHANGED
@@ -1,98 +1,98 @@
|
|
1
|
-
export const maxInt8 = 2n ** (8n - 1n)
|
2
|
-
export const maxInt16 = 2n ** (16n - 1n)
|
3
|
-
export const maxInt24 = 2n ** (24n - 1n)
|
4
|
-
export const maxInt32 = 2n ** (32n - 1n)
|
5
|
-
export const maxInt40 = 2n ** (40n - 1n)
|
6
|
-
export const maxInt48 = 2n ** (48n - 1n)
|
7
|
-
export const maxInt56 = 2n ** (56n - 1n)
|
8
|
-
export const maxInt64 = 2n ** (64n - 1n)
|
9
|
-
export const maxInt72 = 2n ** (72n - 1n)
|
10
|
-
export const maxInt80 = 2n ** (80n - 1n)
|
11
|
-
export const maxInt88 = 2n ** (88n - 1n)
|
12
|
-
export const maxInt96 = 2n ** (96n - 1n)
|
13
|
-
export const maxInt104 = 2n ** (104n - 1n)
|
14
|
-
export const maxInt112 = 2n ** (112n - 1n)
|
15
|
-
export const maxInt120 = 2n ** (120n - 1n)
|
16
|
-
export const maxInt128 = 2n ** (128n - 1n)
|
17
|
-
export const maxInt136 = 2n ** (136n - 1n)
|
18
|
-
export const maxInt144 = 2n ** (144n - 1n)
|
19
|
-
export const maxInt152 = 2n ** (152n - 1n)
|
20
|
-
export const maxInt160 = 2n ** (160n - 1n)
|
21
|
-
export const maxInt168 = 2n ** (168n - 1n)
|
22
|
-
export const maxInt176 = 2n ** (176n - 1n)
|
23
|
-
export const maxInt184 = 2n ** (184n - 1n)
|
24
|
-
export const maxInt192 = 2n ** (192n - 1n)
|
25
|
-
export const maxInt200 = 2n ** (200n - 1n)
|
26
|
-
export const maxInt208 = 2n ** (208n - 1n)
|
27
|
-
export const maxInt216 = 2n ** (216n - 1n)
|
28
|
-
export const maxInt224 = 2n ** (224n - 1n)
|
29
|
-
export const maxInt232 = 2n ** (232n - 1n)
|
30
|
-
export const maxInt240 = 2n ** (240n - 1n)
|
31
|
-
export const maxInt248 = 2n ** (248n - 1n)
|
32
|
-
export const maxInt256 = 2n ** (256n - 1n)
|
1
|
+
export const maxInt8 = 2n ** (8n - 1n) - 1n
|
2
|
+
export const maxInt16 = 2n ** (16n - 1n) - 1n
|
3
|
+
export const maxInt24 = 2n ** (24n - 1n) - 1n
|
4
|
+
export const maxInt32 = 2n ** (32n - 1n) - 1n
|
5
|
+
export const maxInt40 = 2n ** (40n - 1n) - 1n
|
6
|
+
export const maxInt48 = 2n ** (48n - 1n) - 1n
|
7
|
+
export const maxInt56 = 2n ** (56n - 1n) - 1n
|
8
|
+
export const maxInt64 = 2n ** (64n - 1n) - 1n
|
9
|
+
export const maxInt72 = 2n ** (72n - 1n) - 1n
|
10
|
+
export const maxInt80 = 2n ** (80n - 1n) - 1n
|
11
|
+
export const maxInt88 = 2n ** (88n - 1n) - 1n
|
12
|
+
export const maxInt96 = 2n ** (96n - 1n) - 1n
|
13
|
+
export const maxInt104 = 2n ** (104n - 1n) - 1n
|
14
|
+
export const maxInt112 = 2n ** (112n - 1n) - 1n
|
15
|
+
export const maxInt120 = 2n ** (120n - 1n) - 1n
|
16
|
+
export const maxInt128 = 2n ** (128n - 1n) - 1n
|
17
|
+
export const maxInt136 = 2n ** (136n - 1n) - 1n
|
18
|
+
export const maxInt144 = 2n ** (144n - 1n) - 1n
|
19
|
+
export const maxInt152 = 2n ** (152n - 1n) - 1n
|
20
|
+
export const maxInt160 = 2n ** (160n - 1n) - 1n
|
21
|
+
export const maxInt168 = 2n ** (168n - 1n) - 1n
|
22
|
+
export const maxInt176 = 2n ** (176n - 1n) - 1n
|
23
|
+
export const maxInt184 = 2n ** (184n - 1n) - 1n
|
24
|
+
export const maxInt192 = 2n ** (192n - 1n) - 1n
|
25
|
+
export const maxInt200 = 2n ** (200n - 1n) - 1n
|
26
|
+
export const maxInt208 = 2n ** (208n - 1n) - 1n
|
27
|
+
export const maxInt216 = 2n ** (216n - 1n) - 1n
|
28
|
+
export const maxInt224 = 2n ** (224n - 1n) - 1n
|
29
|
+
export const maxInt232 = 2n ** (232n - 1n) - 1n
|
30
|
+
export const maxInt240 = 2n ** (240n - 1n) - 1n
|
31
|
+
export const maxInt248 = 2n ** (248n - 1n) - 1n
|
32
|
+
export const maxInt256 = 2n ** (256n - 1n) - 1n
|
33
33
|
|
34
|
-
export const minInt8 = -(2n ** 8n)
|
35
|
-
export const minInt16 = -(2n ** 16n)
|
36
|
-
export const minInt24 = -(2n ** 24n)
|
37
|
-
export const minInt32 = -(2n ** 32n)
|
38
|
-
export const minInt40 = -(2n ** 40n)
|
39
|
-
export const minInt48 = -(2n ** 48n)
|
40
|
-
export const minInt56 = -(2n ** 56n)
|
41
|
-
export const minInt64 = -(2n ** 64n)
|
42
|
-
export const minInt72 = -(2n ** 72n)
|
43
|
-
export const minInt80 = -(2n ** 80n)
|
44
|
-
export const minInt88 = -(2n ** 88n)
|
45
|
-
export const minInt96 = -(2n ** 96n)
|
46
|
-
export const minInt104 = -(2n ** 104n)
|
47
|
-
export const minInt112 = -(2n ** 112n)
|
48
|
-
export const minInt120 = -(2n ** 120n)
|
49
|
-
export const minInt128 = -(2n ** 128n)
|
50
|
-
export const minInt136 = -(2n ** 136n)
|
51
|
-
export const minInt144 = -(2n ** 144n)
|
52
|
-
export const minInt152 = -(2n ** 152n)
|
53
|
-
export const minInt160 = -(2n ** 160n)
|
54
|
-
export const minInt168 = -(2n ** 168n)
|
55
|
-
export const minInt176 = -(2n ** 176n)
|
56
|
-
export const minInt184 = -(2n ** 184n)
|
57
|
-
export const minInt192 = -(2n ** 192n)
|
58
|
-
export const minInt200 = -(2n ** 200n)
|
59
|
-
export const minInt208 = -(2n ** 208n)
|
60
|
-
export const minInt216 = -(2n ** 216n)
|
61
|
-
export const minInt224 = -(2n ** 224n)
|
62
|
-
export const minInt232 = -(2n ** 232n)
|
63
|
-
export const minInt240 = -(2n ** 240n)
|
64
|
-
export const minInt248 = -(2n ** 248n)
|
65
|
-
export const minInt256 = -(2n ** 256n)
|
34
|
+
export const minInt8 = -(2n ** (8n - 1n))
|
35
|
+
export const minInt16 = -(2n ** (16n - 1n))
|
36
|
+
export const minInt24 = -(2n ** (24n - 1n))
|
37
|
+
export const minInt32 = -(2n ** (32n - 1n))
|
38
|
+
export const minInt40 = -(2n ** (40n - 1n))
|
39
|
+
export const minInt48 = -(2n ** (48n - 1n))
|
40
|
+
export const minInt56 = -(2n ** (56n - 1n))
|
41
|
+
export const minInt64 = -(2n ** (64n - 1n))
|
42
|
+
export const minInt72 = -(2n ** (72n - 1n))
|
43
|
+
export const minInt80 = -(2n ** (80n - 1n))
|
44
|
+
export const minInt88 = -(2n ** (88n - 1n))
|
45
|
+
export const minInt96 = -(2n ** (96n - 1n))
|
46
|
+
export const minInt104 = -(2n ** (104n - 1n))
|
47
|
+
export const minInt112 = -(2n ** (112n - 1n))
|
48
|
+
export const minInt120 = -(2n ** (120n - 1n))
|
49
|
+
export const minInt128 = -(2n ** (128n - 1n))
|
50
|
+
export const minInt136 = -(2n ** (136n - 1n))
|
51
|
+
export const minInt144 = -(2n ** (144n - 1n))
|
52
|
+
export const minInt152 = -(2n ** (152n - 1n))
|
53
|
+
export const minInt160 = -(2n ** (160n - 1n))
|
54
|
+
export const minInt168 = -(2n ** (168n - 1n))
|
55
|
+
export const minInt176 = -(2n ** (176n - 1n))
|
56
|
+
export const minInt184 = -(2n ** (184n - 1n))
|
57
|
+
export const minInt192 = -(2n ** (192n - 1n))
|
58
|
+
export const minInt200 = -(2n ** (200n - 1n))
|
59
|
+
export const minInt208 = -(2n ** (208n - 1n))
|
60
|
+
export const minInt216 = -(2n ** (216n - 1n))
|
61
|
+
export const minInt224 = -(2n ** (224n - 1n))
|
62
|
+
export const minInt232 = -(2n ** (232n - 1n))
|
63
|
+
export const minInt240 = -(2n ** (240n - 1n))
|
64
|
+
export const minInt248 = -(2n ** (248n - 1n))
|
65
|
+
export const minInt256 = -(2n ** (256n - 1n))
|
66
66
|
|
67
|
-
export const maxUint8 = 2n ** 8n
|
68
|
-
export const maxUint16 = 2n ** 16n
|
69
|
-
export const maxUint24 = 2n ** 24n
|
70
|
-
export const maxUint32 = 2n ** 32n
|
71
|
-
export const maxUint40 = 2n ** 40n
|
72
|
-
export const maxUint48 = 2n ** 48n
|
73
|
-
export const maxUint56 = 2n ** 56n
|
74
|
-
export const maxUint64 = 2n ** 64n
|
75
|
-
export const maxUint72 = 2n ** 72n
|
76
|
-
export const maxUint80 = 2n ** 80n
|
77
|
-
export const maxUint88 = 2n ** 88n
|
78
|
-
export const maxUint96 = 2n ** 96n
|
79
|
-
export const maxUint104 = 2n ** 104n
|
80
|
-
export const maxUint112 = 2n ** 112n
|
81
|
-
export const maxUint120 = 2n ** 120n
|
82
|
-
export const maxUint128 = 2n ** 128n
|
83
|
-
export const maxUint136 = 2n ** 136n
|
84
|
-
export const maxUint144 = 2n ** 144n
|
85
|
-
export const maxUint152 = 2n ** 152n
|
86
|
-
export const maxUint160 = 2n ** 160n
|
87
|
-
export const maxUint168 = 2n ** 168n
|
88
|
-
export const maxUint176 = 2n ** 176n
|
89
|
-
export const maxUint184 = 2n ** 184n
|
90
|
-
export const maxUint192 = 2n ** 192n
|
91
|
-
export const maxUint200 = 2n ** 200n
|
92
|
-
export const maxUint208 = 2n ** 208n
|
93
|
-
export const maxUint216 = 2n ** 216n
|
94
|
-
export const maxUint224 = 2n ** 224n
|
95
|
-
export const maxUint232 = 2n ** 232n
|
96
|
-
export const maxUint240 = 2n ** 240n
|
97
|
-
export const maxUint248 = 2n ** 248n
|
98
|
-
export const maxUint256 = 2n ** 256n
|
67
|
+
export const maxUint8 = 2n ** 8n - 1n
|
68
|
+
export const maxUint16 = 2n ** 16n - 1n
|
69
|
+
export const maxUint24 = 2n ** 24n - 1n
|
70
|
+
export const maxUint32 = 2n ** 32n - 1n
|
71
|
+
export const maxUint40 = 2n ** 40n - 1n
|
72
|
+
export const maxUint48 = 2n ** 48n - 1n
|
73
|
+
export const maxUint56 = 2n ** 56n - 1n
|
74
|
+
export const maxUint64 = 2n ** 64n - 1n
|
75
|
+
export const maxUint72 = 2n ** 72n - 1n
|
76
|
+
export const maxUint80 = 2n ** 80n - 1n
|
77
|
+
export const maxUint88 = 2n ** 88n - 1n
|
78
|
+
export const maxUint96 = 2n ** 96n - 1n
|
79
|
+
export const maxUint104 = 2n ** 104n - 1n
|
80
|
+
export const maxUint112 = 2n ** 112n - 1n
|
81
|
+
export const maxUint120 = 2n ** 120n - 1n
|
82
|
+
export const maxUint128 = 2n ** 128n - 1n
|
83
|
+
export const maxUint136 = 2n ** 136n - 1n
|
84
|
+
export const maxUint144 = 2n ** 144n - 1n
|
85
|
+
export const maxUint152 = 2n ** 152n - 1n
|
86
|
+
export const maxUint160 = 2n ** 160n - 1n
|
87
|
+
export const maxUint168 = 2n ** 168n - 1n
|
88
|
+
export const maxUint176 = 2n ** 176n - 1n
|
89
|
+
export const maxUint184 = 2n ** 184n - 1n
|
90
|
+
export const maxUint192 = 2n ** 192n - 1n
|
91
|
+
export const maxUint200 = 2n ** 200n - 1n
|
92
|
+
export const maxUint208 = 2n ** 208n - 1n
|
93
|
+
export const maxUint216 = 2n ** 216n - 1n
|
94
|
+
export const maxUint224 = 2n ** 224n - 1n
|
95
|
+
export const maxUint232 = 2n ** 232n - 1n
|
96
|
+
export const maxUint240 = 2n ** 240n - 1n
|
97
|
+
export const maxUint248 = 2n ** 248n - 1n
|
98
|
+
export const maxUint256 = 2n ** 256n - 1n
|
package/src/index.ts
CHANGED
@@ -638,7 +638,7 @@ export type { Log } from './types/log.js'
|
|
638
638
|
export type {
|
639
639
|
MulticallContract,
|
640
640
|
MulticallContracts,
|
641
|
-
|
641
|
+
MulticallResponse,
|
642
642
|
MulticallResults,
|
643
643
|
} from './types/multicall.js'
|
644
644
|
export type { ParseAccount } from './types/account.js'
|
package/src/types/contract.ts
CHANGED
@@ -15,6 +15,7 @@ import type {
|
|
15
15
|
ExtractAbiEventNames,
|
16
16
|
ExtractAbiFunction,
|
17
17
|
ExtractAbiFunctionNames,
|
18
|
+
ResolvedConfig,
|
18
19
|
} from 'abitype'
|
19
20
|
|
20
21
|
import type { Hex, LogTopic } from './misc.js'
|
@@ -22,11 +23,111 @@ import type { TransactionRequest } from './transaction.js'
|
|
22
23
|
import type {
|
23
24
|
Filter,
|
24
25
|
IsNarrowable,
|
26
|
+
IsUnion,
|
25
27
|
MaybeRequired,
|
26
28
|
NoUndefined,
|
27
29
|
Prettify,
|
30
|
+
UnionToTuple,
|
28
31
|
} from './utils.js'
|
29
32
|
|
33
|
+
export type FunctionName<
|
34
|
+
abi extends Abi = Abi,
|
35
|
+
mutability extends AbiStateMutability = AbiStateMutability,
|
36
|
+
> = ExtractAbiFunctionNames<abi, mutability>
|
37
|
+
|
38
|
+
export type Args<
|
39
|
+
abi extends Abi = Abi,
|
40
|
+
mutability extends AbiStateMutability = AbiStateMutability,
|
41
|
+
functionName extends ExtractAbiFunctionNames<
|
42
|
+
abi,
|
43
|
+
mutability
|
44
|
+
> = ExtractAbiFunctionNames<abi, mutability>,
|
45
|
+
> = AbiParametersToPrimitiveTypes<
|
46
|
+
ExtractAbiFunction<abi, functionName, mutability>['inputs'],
|
47
|
+
'inputs'
|
48
|
+
>
|
49
|
+
|
50
|
+
export type Widen<type> =
|
51
|
+
| (type extends Function ? type : never)
|
52
|
+
| (type extends ResolvedConfig['BigIntType'] ? bigint : never)
|
53
|
+
| (type extends boolean ? boolean : never)
|
54
|
+
| (type extends ResolvedConfig['IntType'] ? number : never)
|
55
|
+
| (type extends string
|
56
|
+
? type extends ResolvedConfig['AddressType']
|
57
|
+
? ResolvedConfig['AddressType']
|
58
|
+
: type extends ResolvedConfig['BytesType']['inputs']
|
59
|
+
? ResolvedConfig['BytesType']
|
60
|
+
: string
|
61
|
+
: never)
|
62
|
+
| (type extends readonly [] ? readonly [] : never)
|
63
|
+
| (type extends Record<string, unknown>
|
64
|
+
? { [K in keyof type]: Widen<type[K]> }
|
65
|
+
: never)
|
66
|
+
| (type extends { length: number }
|
67
|
+
? {
|
68
|
+
[K in keyof type]: Widen<type[K]>
|
69
|
+
} extends infer Val extends readonly unknown[]
|
70
|
+
? readonly [...Val]
|
71
|
+
: never
|
72
|
+
: never)
|
73
|
+
|
74
|
+
export type ExtractAbiFunctionForArgs<
|
75
|
+
abi extends Abi,
|
76
|
+
mutability extends AbiStateMutability,
|
77
|
+
functionName extends FunctionName<abi, mutability>,
|
78
|
+
args extends Args<abi, mutability, functionName>,
|
79
|
+
> = ExtractAbiFunction<
|
80
|
+
abi,
|
81
|
+
functionName,
|
82
|
+
mutability
|
83
|
+
> extends infer abiFunction extends AbiFunction
|
84
|
+
? IsUnion<abiFunction> extends true // narrow overloads using `args` by converting to tuple and filtering out overloads that don't match
|
85
|
+
? UnionToTuple<abiFunction> extends infer abiFunctions extends readonly AbiFunction[]
|
86
|
+
? {
|
87
|
+
[k in keyof abiFunctions]: args extends AbiParametersToPrimitiveTypes<
|
88
|
+
abiFunctions[k]['inputs'],
|
89
|
+
'inputs'
|
90
|
+
>
|
91
|
+
? abiFunctions[k]
|
92
|
+
: never
|
93
|
+
}[number] // convert back to union (removes `never` tuple entries: `['foo', never, 'bar'][number]` => `'foo' | 'bar'`)
|
94
|
+
: never
|
95
|
+
: abiFunction
|
96
|
+
: never
|
97
|
+
|
98
|
+
export type ContractFunctionReturnType<
|
99
|
+
contract,
|
100
|
+
mutability extends AbiStateMutability,
|
101
|
+
> = contract extends {
|
102
|
+
abi: infer abi extends Abi
|
103
|
+
functionName?: infer functionName extends string
|
104
|
+
args?: infer args
|
105
|
+
}
|
106
|
+
? Abi extends abi
|
107
|
+
? unknown
|
108
|
+
: AbiParametersToPrimitiveTypes<
|
109
|
+
ExtractAbiFunctionForArgs<
|
110
|
+
abi,
|
111
|
+
mutability,
|
112
|
+
functionName,
|
113
|
+
// fallback to `readonly []` if `args` is not defined (e.g. not required `"inputs": []`)
|
114
|
+
(
|
115
|
+
readonly [] extends args
|
116
|
+
? readonly []
|
117
|
+
: args
|
118
|
+
) extends infer args2 extends Args<abi, mutability, functionName>
|
119
|
+
? args2
|
120
|
+
: never
|
121
|
+
>['outputs']
|
122
|
+
> extends infer types
|
123
|
+
? types extends readonly []
|
124
|
+
? void
|
125
|
+
: types extends readonly [infer type]
|
126
|
+
? type
|
127
|
+
: types
|
128
|
+
: never
|
129
|
+
: unknown
|
130
|
+
|
30
131
|
export type AbiItem = Abi[number]
|
31
132
|
|
32
133
|
export type EventDefinition = `${string}(${string})`
|
@@ -43,7 +144,11 @@ export type ContractParameters<
|
|
43
144
|
? ExtractAbiFunctionNames<abi, stateMutability>
|
44
145
|
: string,
|
45
146
|
abiFunction extends AbiFunction = abi extends Abi
|
46
|
-
? ExtractAbiFunction<
|
147
|
+
? ExtractAbiFunction<
|
148
|
+
abi,
|
149
|
+
functionName extends functionNames ? functionName : functionNames, // fallback to all function names if `functionName` is invalid
|
150
|
+
stateMutability
|
151
|
+
>
|
47
152
|
: AbiFunction,
|
48
153
|
types = AbiParametersToPrimitiveTypes<abiFunction['inputs'], 'inputs'>,
|
49
154
|
args =
|