viem 0.0.1-alpha.19 → 0.0.1-alpha.20
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/{rpc-858670f1.d.ts → chain-32f56cfa.d.ts} +68 -18
- package/dist/chain-f12cdc7f.d.ts +5 -0
- package/dist/chains.d.ts +757 -170
- package/dist/chains.js +80 -86
- package/dist/chains.js.map +1 -1
- package/dist/chains.mjs +120 -126
- package/dist/chains.mjs.map +1 -1
- package/dist/{chunk-PHSAQQGZ.mjs → chunk-5Q6FSUU2.mjs} +75 -37
- package/dist/chunk-5Q6FSUU2.mjs.map +1 -0
- package/dist/{chunk-24EKKMUO.js → chunk-FHXXG7I6.js} +12 -12
- package/dist/chunk-FHXXG7I6.js.map +1 -0
- package/dist/{chunk-HRE6LYF3.js → chunk-IAQPMSGJ.js} +13 -13
- package/dist/chunk-IAQPMSGJ.js.map +1 -0
- package/dist/{chunk-IVWG22RQ.mjs → chunk-MYQNZSWD.mjs} +69 -12
- package/dist/chunk-MYQNZSWD.mjs.map +1 -0
- package/dist/{chunk-NYMS65YI.js → chunk-NHAKUPTF.js} +124 -67
- package/dist/chunk-NHAKUPTF.js.map +1 -0
- package/dist/{chunk-BZFF747V.js → chunk-SF4I2NKC.js} +81 -43
- package/dist/chunk-SF4I2NKC.js.map +1 -0
- package/dist/{chunk-VAT5CEF7.mjs → chunk-T7CBAKLI.mjs} +2 -2
- package/dist/chunk-T7CBAKLI.mjs.map +1 -0
- package/dist/{chunk-CTU4PQLY.js → chunk-YFKR74XG.js} +14 -14
- package/dist/{chunk-CTU4PQLY.js.map → chunk-YFKR74XG.js.map} +0 -0
- package/dist/{chunk-NSRORL3O.mjs → chunk-YODUQCHJ.mjs} +2 -2
- package/dist/{chunk-NSRORL3O.mjs.map → chunk-YODUQCHJ.mjs.map} +0 -0
- package/dist/{chunk-E7LH5H76.mjs → chunk-ZVGTYLKU.mjs} +2 -2
- package/dist/chunk-ZVGTYLKU.mjs.map +1 -0
- package/dist/clients/index.d.ts +7 -8
- package/dist/clients/index.js +3 -3
- package/dist/clients/index.mjs +2 -2
- package/dist/{transactionReceipt-aed524b4.d.ts → contract-9af4608b.d.ts} +30 -18
- package/dist/{createClient-03ba79e8.d.ts → createClient-5d316c7e.d.ts} +2 -2
- package/dist/{createPublicClient-818241ba.d.ts → createPublicClient-9d2b42e1.d.ts} +3 -3
- package/dist/{createTestClient-24eb7be8.d.ts → createTestClient-79498dab.d.ts} +3 -3
- package/dist/{createWalletClient-7cbd6ad1.d.ts → createWalletClient-f69a5230.d.ts} +3 -3
- package/dist/{eip1193-71d8e27d.d.ts → eip1193-6c485d63.d.ts} +1 -1
- package/dist/index.d.ts +45 -23
- package/dist/index.js +10 -6
- package/dist/index.mjs +9 -5
- package/dist/{parseGwei-dbd12305.d.ts → parseGwei-4308ad80.d.ts} +17 -4
- package/dist/public.d.ts +9 -10
- package/dist/public.js +4 -4
- package/dist/public.mjs +3 -3
- package/dist/{sendTransaction-d09961a7.d.ts → sendTransaction-1c8290a9.d.ts} +3 -4
- package/dist/{stopImpersonatingAccount-c8a00be7.d.ts → stopImpersonatingAccount-7781842a.d.ts} +2 -2
- package/dist/test.d.ts +5 -6
- package/dist/test.js +3 -3
- package/dist/test.mjs +2 -2
- package/dist/transactionRequest-341b6ed2.d.ts +15 -0
- package/dist/utils/index.d.ts +9 -8
- package/dist/utils/index.js +22 -2
- package/dist/utils/index.mjs +25 -5
- package/dist/wallet.d.ts +7 -8
- package/dist/wallet.js +3 -3
- package/dist/wallet.mjs +2 -2
- package/dist/{watchAsset-c39645b7.d.ts → watchAsset-afaad3c7.d.ts} +3 -4
- package/dist/{watchPendingTransactions-01e6be4f.d.ts → watchPendingTransactions-3b722547.d.ts} +21 -16
- package/dist/{webSocket-3a00015b.d.ts → webSocket-b180e679.d.ts} +2 -2
- package/dist/window.d.ts +3 -2
- package/package.json +3 -3
- package/src/_test/abis.ts +188 -0
- package/src/_test/constants.ts +0 -3
- package/src/_test/index.ts +5 -2
- package/src/actions/index.test.ts +2 -0
- package/src/actions/index.ts +6 -0
- package/src/actions/public/call.ts +2 -1
- package/src/actions/public/createContractEventFilter.test.ts +119 -0
- package/src/actions/public/createContractEventFilter.ts +69 -0
- package/src/actions/public/createEventFilter.ts +5 -8
- package/src/actions/public/deployContract.ts +1 -2
- package/src/actions/public/getBlock.test.ts +3 -3
- package/src/actions/public/getBlock.ts +1 -2
- package/src/actions/public/getBlockTransactionCount.ts +1 -2
- package/src/actions/public/getFilterChanges.test.ts +9 -7
- package/src/actions/public/getFilterLogs.test.ts +7 -5
- package/src/actions/public/getLogs.test.ts +7 -5
- package/src/actions/public/getLogs.ts +3 -2
- package/src/actions/public/getTransaction.ts +1 -2
- package/src/actions/public/getTransactionConfirmations.ts +1 -2
- package/src/actions/public/getTransactionReceipt.test.ts +24 -62
- package/src/actions/public/getTransactionReceipt.ts +1 -2
- package/src/actions/public/index.test.ts +4 -0
- package/src/actions/public/index.ts +18 -0
- package/src/actions/public/readContract.ts +1 -1
- package/src/actions/public/simulateContract.ts +1 -1
- package/src/actions/public/waitForTransactionReceipt.ts +1 -2
- package/src/actions/public/watchBlocks.test.ts +27 -2
- package/src/actions/public/watchBlocks.ts +33 -14
- package/src/actions/public/watchContractEvent.test.ts +301 -0
- package/src/actions/public/watchContractEvent.ts +108 -0
- package/src/actions/public/watchEvent.test.ts +190 -0
- package/src/actions/public/watchEvent.ts +95 -0
- package/src/actions/public/watchPendingTransactions.ts +1 -0
- package/src/actions/wallet/addChain.ts +1 -1
- package/src/actions/wallet/sendTransaction.ts +2 -1
- package/src/actions/wallet/switchChain.ts +1 -1
- package/src/actions/wallet/writeContract.ts +1 -1
- package/src/chains.test.ts +830 -52
- package/src/chains.ts +90 -158
- package/src/clients/createClient.ts +1 -1
- package/src/clients/createPublicClient.ts +1 -1
- package/src/clients/createTestClient.ts +1 -1
- package/src/clients/createWalletClient.ts +1 -1
- package/src/clients/transports/createTransport.ts +1 -1
- package/src/index.test.ts +2 -0
- package/src/index.ts +10 -2
- package/src/types/chain.ts +6 -0
- package/src/types/contract.ts +17 -2
- package/src/types/formatter.ts +23 -0
- package/src/types/index.ts +6 -0
- package/src/types/transaction.ts +1 -1
- package/src/utils/abi/decodeErrorResult.ts +2 -2
- package/src/utils/abi/decodeFunctionData.ts +2 -2
- package/src/utils/abi/encodeErrorResult.ts +2 -2
- package/src/utils/abi/encodeEventTopics.ts +4 -4
- package/src/utils/abi/encodeFunctionData.ts +2 -2
- package/src/utils/abi/{formatAbiItemWithParams.test.ts → formatAbiItem.test.ts} +11 -11
- package/src/utils/abi/{formatAbiItemWithParams.ts → formatAbiItem.ts} +1 -1
- package/src/utils/abi/index.test.ts +1 -1
- package/src/utils/abi/index.ts +1 -1
- package/src/utils/chain.test.ts +43 -0
- package/src/utils/chain.ts +8 -0
- package/src/utils/contract/getContractError.ts +2 -6
- package/src/utils/formatters/block.ts +4 -3
- package/src/utils/formatters/extract.ts +1 -1
- package/src/utils/formatters/format.ts +39 -2
- package/src/utils/formatters/index.test.ts +10 -0
- package/src/utils/formatters/index.ts +15 -5
- package/src/utils/formatters/transaction.ts +16 -4
- package/src/utils/formatters/transactionReceipt.ts +13 -4
- package/src/utils/formatters/transactionRequest.ts +12 -3
- package/src/utils/hash/getEventSignature.ts +2 -2
- package/src/utils/index.test.ts +24 -1
- package/src/utils/index.ts +12 -1
- package/src/{constants.test.ts → utils/unit/constants.test.ts} +0 -5
- package/src/{constants.ts → utils/unit/constants.ts} +0 -6
- package/src/utils/unit/formatEther.ts +1 -1
- package/src/utils/unit/formatGwei.ts +1 -1
- package/src/utils/unit/index.test.ts +12 -0
- package/src/utils/unit/index.ts +1 -0
- package/src/utils/unit/parseEther.ts +1 -1
- package/src/utils/unit/parseGwei.ts +1 -1
- package/dist/chunk-24EKKMUO.js.map +0 -1
- package/dist/chunk-BZFF747V.js.map +0 -1
- package/dist/chunk-E7LH5H76.mjs.map +0 -1
- package/dist/chunk-HRE6LYF3.js.map +0 -1
- package/dist/chunk-IVWG22RQ.mjs.map +0 -1
- package/dist/chunk-NYMS65YI.js.map +0 -1
- package/dist/chunk-PHSAQQGZ.mjs.map +0 -1
- package/dist/chunk-VAT5CEF7.mjs.map +0 -1
- package/dist/transactionRequest-8e970b0e.d.ts +0 -33
package/src/chains.ts
CHANGED
@@ -1,167 +1,99 @@
|
|
1
|
-
|
1
|
+
import * as chains from '@wagmi/chains'
|
2
2
|
|
3
|
-
import type {
|
3
|
+
import type { Address, Hex, Quantity } from './types'
|
4
4
|
import {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
bsc as bsc_,
|
11
|
-
fantomTestnet as fantomTestnet_,
|
12
|
-
fantom as fantom_,
|
13
|
-
foundry as foundry_,
|
14
|
-
goerli as goerli_,
|
15
|
-
hardhat as hardhat_,
|
16
|
-
localhost as localhost_,
|
17
|
-
mainnet as mainnet_,
|
18
|
-
optimismGoerli as optimismGoerli_,
|
19
|
-
optimism as optimism_,
|
20
|
-
polygonMumbai as polygonMumbai_,
|
21
|
-
polygon as polygon_,
|
22
|
-
sepolia as sepolia_,
|
23
|
-
} from '@wagmi/chains'
|
24
|
-
|
25
|
-
import type {
|
26
|
-
Address,
|
27
|
-
Block,
|
28
|
-
Hex,
|
29
|
-
Quantity,
|
30
|
-
RpcBlock,
|
31
|
-
RpcTransaction,
|
32
|
-
RpcTransactionReceipt,
|
33
|
-
RpcTransactionRequest,
|
34
|
-
Transaction,
|
35
|
-
TransactionReceipt,
|
36
|
-
TransactionRequest,
|
37
|
-
} from './types'
|
38
|
-
import {
|
39
|
-
formatBlock,
|
40
|
-
formatTransaction,
|
41
|
-
formatTransactionRequest,
|
5
|
+
defineBlock,
|
6
|
+
defineChain,
|
7
|
+
defineTransaction,
|
8
|
+
defineTransactionReceipt,
|
9
|
+
defineTransactionRequest,
|
42
10
|
} from './utils'
|
43
|
-
import { formatTransactionReceipt } from './utils/formatters/transactionReceipt'
|
44
|
-
|
45
|
-
export type Formatter<TSource = any, TTarget = any> = (
|
46
|
-
value: TSource & { [key: string]: unknown },
|
47
|
-
) => TTarget
|
48
|
-
|
49
|
-
export type Formatters = {
|
50
|
-
block?: Formatter<RpcBlock, Block>
|
51
|
-
transaction?: Formatter<RpcTransaction, Transaction>
|
52
|
-
transactionReceipt?: Formatter<RpcTransactionReceipt, TransactionReceipt>
|
53
|
-
transactionRequest?: Formatter<TransactionRequest, RpcTransactionRequest>
|
54
|
-
}
|
55
11
|
|
56
|
-
export type Chain
|
57
|
-
|
58
|
-
}
|
59
|
-
|
60
|
-
export function defineChain<
|
61
|
-
TFormatters extends Formatters = Formatters,
|
62
|
-
TChain extends Chain<TFormatters> = Chain<TFormatters>,
|
63
|
-
>(chain: TChain) {
|
64
|
-
return chain
|
65
|
-
}
|
66
|
-
|
67
|
-
function defineFormatter<TSource extends Record<string, unknown>, TFormatted>({
|
68
|
-
format,
|
69
|
-
}: {
|
70
|
-
format: (data: TSource) => TFormatted
|
71
|
-
}) {
|
72
|
-
return <
|
73
|
-
TFormat extends Formatter<
|
74
|
-
TSource,
|
75
|
-
Partial<TFormatted> & { [key: string]: unknown }
|
76
|
-
>,
|
77
|
-
TExclude extends (keyof TSource)[] = [],
|
78
|
-
>({
|
79
|
-
exclude,
|
80
|
-
format: formatOverride,
|
81
|
-
}: {
|
82
|
-
exclude?: TExclude
|
83
|
-
format?: TFormat
|
84
|
-
}) =>
|
85
|
-
(data: TSource & { [key: string]: unknown }) => {
|
86
|
-
const formatted = format(data)
|
87
|
-
if (exclude) {
|
88
|
-
for (const key of exclude) {
|
89
|
-
delete (formatted as any)[key]
|
90
|
-
}
|
91
|
-
}
|
92
|
-
return {
|
93
|
-
...formatted,
|
94
|
-
...formatOverride?.(data),
|
95
|
-
} as TFormatted &
|
96
|
-
ReturnType<TFormat> & {
|
97
|
-
[K in TExclude[number]]: never
|
98
|
-
}
|
99
|
-
}
|
100
|
-
}
|
12
|
+
export type { Chain } from './types'
|
13
|
+
export { defineChain } from './utils'
|
101
14
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
}
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
name: 'Celo',
|
120
|
-
network: 'celo',
|
121
|
-
nativeCurrency: { name: 'Celo', symbol: 'CELO', decimals: 18 },
|
122
|
-
rpcUrls: {
|
123
|
-
public: { http: ['https://rpc.ankr.com/celo'] },
|
124
|
-
default: { http: ['https://rpc.ankr.com/celo'] },
|
125
|
-
},
|
126
|
-
formatters: {
|
127
|
-
block: defineBlock({
|
128
|
-
exclude: ['difficulty', 'gasLimit', 'mixHash', 'nonce', 'uncles'],
|
129
|
-
format: (block) => ({
|
130
|
-
randomness: block.randomness as {
|
131
|
-
committed: Hex
|
132
|
-
revealed: Hex
|
133
|
-
},
|
134
|
-
}),
|
15
|
+
const celoFormatters = {
|
16
|
+
block: defineBlock({
|
17
|
+
exclude: ['difficulty', 'gasLimit', 'mixHash', 'nonce', 'uncles'],
|
18
|
+
format: (block) => ({
|
19
|
+
randomness: block.randomness as {
|
20
|
+
committed: Hex
|
21
|
+
revealed: Hex
|
22
|
+
},
|
23
|
+
}),
|
24
|
+
}),
|
25
|
+
transaction: defineTransaction({
|
26
|
+
format: (transaction) => ({
|
27
|
+
feeCurrency: transaction.feeCurrency as Address | null,
|
28
|
+
gatewayFee: transaction.gatewayFee
|
29
|
+
? BigInt(transaction.gatewayFee as Quantity)
|
30
|
+
: null,
|
31
|
+
gatewayFeeRecipient: transaction.gatewayFeeRecipient as Address | null,
|
135
32
|
}),
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
33
|
+
}),
|
34
|
+
transactionReceipt: defineTransactionReceipt({
|
35
|
+
format: (transaction) => ({
|
36
|
+
feeCurrency: transaction.feeCurrency as Address | null,
|
37
|
+
gatewayFee: transaction.gatewayFee
|
38
|
+
? BigInt(transaction.gatewayFee as Quantity)
|
39
|
+
: null,
|
40
|
+
gatewayFeeRecipient: transaction.gatewayFeeRecipient as Address | null,
|
144
41
|
}),
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
42
|
+
}),
|
43
|
+
transactionRequest: defineTransactionRequest({
|
44
|
+
format: (transactionRequest) => ({
|
45
|
+
feeCurrency: transactionRequest.feeCurrency as Address | undefined,
|
46
|
+
gatewayFee: transactionRequest.gatewayFee as Quantity | undefined,
|
47
|
+
gatewayFeeRecipient: transactionRequest.gatewayFeeRecipient as
|
48
|
+
| Address
|
49
|
+
| undefined,
|
153
50
|
}),
|
154
|
-
},
|
51
|
+
}),
|
52
|
+
}
|
53
|
+
|
54
|
+
export const arbitrum = defineChain(chains.arbitrum)
|
55
|
+
export const arbitrumGoerli = defineChain(chains.arbitrumGoerli)
|
56
|
+
export const aurora = defineChain(chains.aurora)
|
57
|
+
export const auroraGoerli = defineChain(chains.auroraTestnet)
|
58
|
+
export const avalanche = defineChain(chains.avalanche)
|
59
|
+
export const avalancheFuji = defineChain(chains.avalancheFuji)
|
60
|
+
export const bronos = defineChain(chains.bronos)
|
61
|
+
export const bronosTestnet = defineChain(chains.bronosTestnet)
|
62
|
+
export const bsc = defineChain(chains.bsc)
|
63
|
+
export const bscTestnet = defineChain(chains.bscTestnet)
|
64
|
+
export const canto = defineChain(chains.canto)
|
65
|
+
export const celo = defineChain({
|
66
|
+
...chains.celo,
|
67
|
+
formatters: celoFormatters,
|
68
|
+
})
|
69
|
+
export const celoAlfajores = defineChain({
|
70
|
+
...chains.celoAlfajores,
|
71
|
+
formatters: celoFormatters,
|
155
72
|
})
|
156
|
-
export const
|
157
|
-
export const
|
158
|
-
export const
|
159
|
-
export const
|
160
|
-
export const
|
161
|
-
export const
|
162
|
-
export const
|
163
|
-
export const
|
164
|
-
export const
|
165
|
-
export const
|
166
|
-
export const
|
167
|
-
export const
|
73
|
+
export const crossbell = defineChain(chains.crossbell)
|
74
|
+
export const evmos = defineChain(chains.evmos)
|
75
|
+
export const evmosTestnet = defineChain(chains.evmosTestnet)
|
76
|
+
export const fantom = defineChain(chains.fantom)
|
77
|
+
export const fantomTestnet = defineChain(chains.fantomTestnet)
|
78
|
+
export const filecoin = defineChain(chains.filecoin)
|
79
|
+
export const filecoinTestnet = defineChain(chains.filecoinHyperspace)
|
80
|
+
export const foundry = defineChain(chains.foundry)
|
81
|
+
export const goerli = defineChain(chains.goerli)
|
82
|
+
export const gnosis = defineChain(chains.gnosis)
|
83
|
+
export const gnosisChiado = defineChain(chains.gnosisChiado)
|
84
|
+
export const hardhat = defineChain(chains.hardhat)
|
85
|
+
export const iotex = defineChain(chains.iotex)
|
86
|
+
export const iotexTestnet = defineChain(chains.iotexTestnet)
|
87
|
+
export const localhost = defineChain(chains.localhost)
|
88
|
+
export const mainnet = defineChain(chains.mainnet)
|
89
|
+
export const metis = defineChain(chains.metis)
|
90
|
+
export const metisGoerli = defineChain(chains.metisGoerli)
|
91
|
+
export const optimism = defineChain(chains.optimism)
|
92
|
+
export const optimismGoerli = defineChain(chains.optimismGoerli)
|
93
|
+
export const polygon = defineChain(chains.polygon)
|
94
|
+
export const polygonMumbai = defineChain(chains.polygonMumbai)
|
95
|
+
export const sepolia = defineChain(chains.sepolia)
|
96
|
+
export const taraxa = defineChain(chains.taraxa)
|
97
|
+
export const taraxaTestnet = defineChain(chains.taraxaTestnet)
|
98
|
+
export const zkSync = defineChain(chains.zkSync)
|
99
|
+
export const zkSyncTestnet = defineChain(chains.zkSyncTestnet)
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import type { Chain } from '../chains'
|
2
1
|
import type { PublicRequests } from '../types/eip1193'
|
3
2
|
import type { Transport } from './transports/createTransport'
|
4
3
|
import type { Client, ClientConfig } from './createClient'
|
5
4
|
import { createClient } from './createClient'
|
5
|
+
import { Chain } from '../types'
|
6
6
|
|
7
7
|
export type PublicClientConfig<
|
8
8
|
TTransport extends Transport = Transport,
|
@@ -2,7 +2,7 @@ import type { TestRequests } from '../types/eip1193'
|
|
2
2
|
import type { Transport } from './transports/createTransport'
|
3
3
|
import type { Client, ClientConfig } from './createClient'
|
4
4
|
import { createClient } from './createClient'
|
5
|
-
import
|
5
|
+
import { Chain } from '../types'
|
6
6
|
|
7
7
|
type TestClientModes = 'anvil' | 'hardhat'
|
8
8
|
|
@@ -2,7 +2,7 @@ import type { SignableRequests, WalletRequests } from '../types/eip1193'
|
|
2
2
|
import type { Transport } from './transports/createTransport'
|
3
3
|
import type { Client, ClientConfig } from './createClient'
|
4
4
|
import { createClient } from './createClient'
|
5
|
-
import
|
5
|
+
import { Chain } from '../types'
|
6
6
|
|
7
7
|
export type WalletClientConfig<
|
8
8
|
TTransport extends Transport = Transport,
|
package/src/index.test.ts
CHANGED
@@ -67,6 +67,8 @@ test('exports actions', () => {
|
|
67
67
|
"call": [Function],
|
68
68
|
"createBlockFilter": [Function],
|
69
69
|
"createClient": [Function],
|
70
|
+
"createContractEventFilter": [Function],
|
71
|
+
"createEventFilter": [Function],
|
70
72
|
"createPendingTransactionFilter": [Function],
|
71
73
|
"createPublicClient": [Function],
|
72
74
|
"createTestClient": [Function],
|
package/src/index.ts
CHANGED
@@ -2,6 +2,10 @@ export type {
|
|
2
2
|
CallArgs,
|
3
3
|
CallResponse,
|
4
4
|
CreateBlockFilterResponse,
|
5
|
+
CreateContractEventFilterArgs,
|
6
|
+
CreateContractEventFilterResponse,
|
7
|
+
CreateEventFilterArgs,
|
8
|
+
CreateEventFilterResponse,
|
5
9
|
CreatePendingTransactionFilterResponse,
|
6
10
|
EstimateGasArgs,
|
7
11
|
EstimateGasResponse,
|
@@ -89,6 +93,8 @@ export {
|
|
89
93
|
addChain,
|
90
94
|
call,
|
91
95
|
createBlockFilter,
|
96
|
+
createContractEventFilter,
|
97
|
+
createEventFilter,
|
92
98
|
createPendingTransactionFilter,
|
93
99
|
deployContract,
|
94
100
|
dropTransaction,
|
@@ -185,8 +191,6 @@ export {
|
|
185
191
|
webSocket,
|
186
192
|
} from './clients'
|
187
193
|
|
188
|
-
export { etherUnits, gweiUnits, transactionType, weiUnits } from './constants'
|
189
|
-
|
190
194
|
export {
|
191
195
|
AbiConstructorNotFoundError,
|
192
196
|
AbiConstructorParamsNotFoundError,
|
@@ -325,12 +329,14 @@ export {
|
|
325
329
|
encodeFunctionResult,
|
326
330
|
encodeHex,
|
327
331
|
encodeRlp,
|
332
|
+
etherUnits,
|
328
333
|
getAddress,
|
329
334
|
getContractAddress,
|
330
335
|
getCreateAddress,
|
331
336
|
getCreate2Address,
|
332
337
|
getEventSignature,
|
333
338
|
getFunctionSignature,
|
339
|
+
gweiUnits,
|
334
340
|
formatEther,
|
335
341
|
isAddress,
|
336
342
|
isAddressEqual,
|
@@ -361,5 +367,7 @@ export {
|
|
361
367
|
sliceHex,
|
362
368
|
stringToBytes,
|
363
369
|
stringToHex,
|
370
|
+
transactionType,
|
364
371
|
trim,
|
372
|
+
weiUnits,
|
365
373
|
} from './utils'
|
package/src/types/contract.ts
CHANGED
@@ -10,6 +10,7 @@ import type {
|
|
10
10
|
AbiParametersToPrimitiveTypes,
|
11
11
|
ExtractAbiFunction,
|
12
12
|
ExtractAbiEvent,
|
13
|
+
ExtractAbiEventNames,
|
13
14
|
ExtractAbiError,
|
14
15
|
AbiStateMutability,
|
15
16
|
ExtractAbiFunctionNames,
|
@@ -139,9 +140,9 @@ export type ExtractErrorArgsFromAbi<
|
|
139
140
|
|
140
141
|
export type ExtractEventArgsFromAbi<
|
141
142
|
TAbi extends Abi | readonly unknown[],
|
142
|
-
|
143
|
+
TEventName extends string,
|
143
144
|
TAbiEvent extends AbiEvent & { type: 'event' } = TAbi extends Abi
|
144
|
-
? ExtractAbiEvent<TAbi,
|
145
|
+
? ExtractAbiEvent<TAbi, TEventName>
|
145
146
|
: AbiEvent & { type: 'event' },
|
146
147
|
TArgs = AbiEventParametersToPrimitiveTypes<TAbiEvent['inputs']>,
|
147
148
|
FailedToParseArgs =
|
@@ -162,6 +163,18 @@ export type ExtractEventArgsFromAbi<
|
|
162
163
|
args?: TArgs
|
163
164
|
}
|
164
165
|
|
166
|
+
export type ExtractEventNameFromAbi<
|
167
|
+
TAbi extends Abi | readonly unknown[] = Abi,
|
168
|
+
TEventName extends string = string,
|
169
|
+
> = TAbi extends Abi
|
170
|
+
? ExtractAbiEventNames<TAbi> extends infer AbiEventNames
|
171
|
+
?
|
172
|
+
| AbiEventNames
|
173
|
+
| (TEventName extends AbiEventNames ? TEventName : never)
|
174
|
+
| (Abi extends TAbi ? string : never)
|
175
|
+
: never
|
176
|
+
: TEventName
|
177
|
+
|
165
178
|
export type ExtractFunctionNameFromAbi<
|
166
179
|
TAbi extends Abi | readonly unknown[] = Abi,
|
167
180
|
TFunctionName extends string = string,
|
@@ -201,6 +214,8 @@ export type ExtractResultFromAbi<
|
|
201
214
|
//////////////////////////////////////////////////////////////////////
|
202
215
|
// Event/Function Definitions
|
203
216
|
|
217
|
+
export type EventDefinition = `${string}(${string})`
|
218
|
+
|
204
219
|
type ExtractArgsFromDefinitionConfig = {
|
205
220
|
indexedOnly: unknown
|
206
221
|
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { Block } from './block'
|
2
|
+
import {
|
3
|
+
RpcBlock,
|
4
|
+
RpcTransaction,
|
5
|
+
RpcTransactionReceipt,
|
6
|
+
RpcTransactionRequest,
|
7
|
+
} from './rpc'
|
8
|
+
import {
|
9
|
+
Transaction,
|
10
|
+
TransactionReceipt,
|
11
|
+
TransactionRequest,
|
12
|
+
} from './transaction'
|
13
|
+
|
14
|
+
export type Formatter<TSource = any, TTarget = any> = (
|
15
|
+
value: TSource & { [key: string]: unknown },
|
16
|
+
) => TTarget
|
17
|
+
|
18
|
+
export type Formatters = {
|
19
|
+
block?: Formatter<RpcBlock, Block>
|
20
|
+
transaction?: Formatter<RpcTransaction, Transaction>
|
21
|
+
transactionReceipt?: Formatter<RpcTransactionReceipt, TransactionReceipt>
|
22
|
+
transactionRequest?: Formatter<TransactionRequest, RpcTransactionRequest>
|
23
|
+
}
|
package/src/types/index.ts
CHANGED
@@ -6,15 +6,19 @@ export type {
|
|
6
6
|
Uncle,
|
7
7
|
} from './block'
|
8
8
|
|
9
|
+
export type { Chain } from './chain'
|
10
|
+
|
9
11
|
export type {
|
10
12
|
AbiItem,
|
11
13
|
AbiEventParametersToPrimitiveTypes,
|
14
|
+
EventDefinition,
|
12
15
|
ExtractArgsFromAbi,
|
13
16
|
ExtractArgsFromEventDefinition,
|
14
17
|
ExtractArgsFromFunctionDefinition,
|
15
18
|
ExtractConstructorArgsFromAbi,
|
16
19
|
ExtractErrorArgsFromAbi,
|
17
20
|
ExtractEventArgsFromAbi,
|
21
|
+
ExtractEventNameFromAbi,
|
18
22
|
ExtractFunctionNameFromAbi,
|
19
23
|
ExtractResultFromAbi,
|
20
24
|
GetValue,
|
@@ -30,6 +34,8 @@ export type {
|
|
30
34
|
|
31
35
|
export type { Filter, FilterType } from './filter'
|
32
36
|
|
37
|
+
export type { Formatter, Formatters } from './formatter'
|
38
|
+
|
33
39
|
export type { Log } from './log'
|
34
40
|
|
35
41
|
export type { Address, ByteArray, Hex, Hash, LogTopic } from './misc'
|
package/src/types/transaction.ts
CHANGED
@@ -4,14 +4,14 @@ import { Hex } from '../../types'
|
|
4
4
|
import { slice } from '../data'
|
5
5
|
import { getFunctionSignature } from '../hash'
|
6
6
|
import { decodeAbi } from './decodeAbi'
|
7
|
-
import {
|
7
|
+
import { formatAbiItem } from './formatAbiItem'
|
8
8
|
|
9
9
|
export type DecodeErrorResultArgs = { abi: Abi; data: Hex }
|
10
10
|
|
11
11
|
export function decodeErrorResult({ abi, data }: DecodeErrorResultArgs) {
|
12
12
|
const signature = slice(data, 0, 4)
|
13
13
|
const description = abi.find(
|
14
|
-
(x) => signature === getFunctionSignature(
|
14
|
+
(x) => signature === getFunctionSignature(formatAbiItem(x)),
|
15
15
|
)
|
16
16
|
if (!description)
|
17
17
|
throw new AbiErrorSignatureNotFoundError(signature, {
|
@@ -5,14 +5,14 @@ import { Hex } from '../../types'
|
|
5
5
|
import { slice } from '../data'
|
6
6
|
import { getFunctionSignature } from '../hash'
|
7
7
|
import { decodeAbi } from './decodeAbi'
|
8
|
-
import {
|
8
|
+
import { formatAbiItem } from './formatAbiItem'
|
9
9
|
|
10
10
|
export type DecodeFunctionDataArgs = { abi: Abi; data: Hex }
|
11
11
|
|
12
12
|
export function decodeFunctionData({ abi, data }: DecodeFunctionDataArgs) {
|
13
13
|
const signature = slice(data, 0, 4)
|
14
14
|
const description = abi.find(
|
15
|
-
(x) => signature === getFunctionSignature(
|
15
|
+
(x) => signature === getFunctionSignature(formatAbiItem(x)),
|
16
16
|
)
|
17
17
|
if (!description)
|
18
18
|
throw new AbiFunctionSignatureNotFoundError(signature, {
|
@@ -8,7 +8,7 @@ import { ExtractErrorArgsFromAbi, Hex } from '../../types'
|
|
8
8
|
import { concatHex } from '../data'
|
9
9
|
import { getFunctionSignature } from '../hash'
|
10
10
|
import { encodeAbi } from './encodeAbi'
|
11
|
-
import {
|
11
|
+
import { formatAbiItem } from './formatAbiItem'
|
12
12
|
import { getAbiItem } from './getAbiItem'
|
13
13
|
|
14
14
|
const docsPath = '/docs/contract/encodeErrorResult'
|
@@ -27,7 +27,7 @@ export function encodeErrorResult<
|
|
27
27
|
>({ abi, errorName, args }: EncodeErrorResultArgs<TAbi, TErrorName>) {
|
28
28
|
const description = getAbiItem({ abi, name: errorName })
|
29
29
|
if (!description) throw new AbiErrorNotFoundError(errorName, { docsPath })
|
30
|
-
const definition =
|
30
|
+
const definition = formatAbiItem(description)
|
31
31
|
const signature = getFunctionSignature(definition)
|
32
32
|
|
33
33
|
let data: Hex = '0x'
|
@@ -9,11 +9,11 @@ import {
|
|
9
9
|
AbiEventNotFoundError,
|
10
10
|
FilterTypeNotSupportedError,
|
11
11
|
} from '../../errors'
|
12
|
-
import { ExtractEventArgsFromAbi, Hex } from '../../types'
|
12
|
+
import { EventDefinition, ExtractEventArgsFromAbi, Hex } from '../../types'
|
13
13
|
import { encodeBytes } from '../encoding'
|
14
14
|
import { keccak256, getEventSignature } from '../hash'
|
15
15
|
import { encodeAbi } from './encodeAbi'
|
16
|
-
import {
|
16
|
+
import { formatAbiItem } from './formatAbiItem'
|
17
17
|
import { getAbiItem } from './getAbiItem'
|
18
18
|
|
19
19
|
export type EncodeEventTopicsArgs<
|
@@ -33,8 +33,8 @@ export function encodeEventTopics<
|
|
33
33
|
throw new AbiEventNotFoundError(eventName, {
|
34
34
|
docsPath: '/docs/contract/encodeEventTopics',
|
35
35
|
})
|
36
|
-
const definition =
|
37
|
-
const signature = getEventSignature(definition as
|
36
|
+
const definition = formatAbiItem(abiItem)
|
37
|
+
const signature = getEventSignature(definition as EventDefinition)
|
38
38
|
|
39
39
|
let topics: Hex[] = []
|
40
40
|
if (args && 'inputs' in abiItem) {
|
@@ -5,7 +5,7 @@ import { ExtractArgsFromAbi, ExtractFunctionNameFromAbi } from '../../types'
|
|
5
5
|
import { concatHex } from '../data'
|
6
6
|
import { getFunctionSignature } from '../hash'
|
7
7
|
import { encodeAbi } from './encodeAbi'
|
8
|
-
import {
|
8
|
+
import { formatAbiItem } from './formatAbiItem'
|
9
9
|
import { getAbiItem } from './getAbiItem'
|
10
10
|
|
11
11
|
export type EncodeFunctionDataArgs<
|
@@ -25,7 +25,7 @@ export function encodeFunctionData<
|
|
25
25
|
throw new AbiFunctionNotFoundError(functionName, {
|
26
26
|
docsPath: '/docs/contract/encodeFunctionData',
|
27
27
|
})
|
28
|
-
const definition =
|
28
|
+
const definition = formatAbiItem(description)
|
29
29
|
const signature = getFunctionSignature(definition)
|
30
30
|
const data =
|
31
31
|
'inputs' in description && description.inputs
|