viem 1.0.6 → 1.1.0
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/chains/package.json +3 -3
- package/dist/cjs/accounts/privateKeyToAccount.js +2 -2
- package/dist/cjs/accounts/privateKeyToAccount.js.map +1 -1
- package/dist/cjs/accounts/utils/signTransaction.js +3 -3
- package/dist/cjs/accounts/utils/signTransaction.js.map +1 -1
- package/dist/cjs/actions/public/call.js +3 -6
- package/dist/cjs/actions/public/call.js.map +1 -1
- package/dist/cjs/actions/public/estimateContractGas.js.map +1 -1
- package/dist/cjs/actions/public/estimateGas.js +3 -6
- package/dist/cjs/actions/public/estimateGas.js.map +1 -1
- package/dist/cjs/actions/public/getBlock.js +2 -4
- package/dist/cjs/actions/public/getBlock.js.map +1 -1
- package/dist/cjs/actions/public/getTransaction.js +2 -4
- package/dist/cjs/actions/public/getTransaction.js.map +1 -1
- package/dist/cjs/actions/public/getTransactionConfirmations.js.map +1 -1
- package/dist/cjs/actions/public/getTransactionReceipt.js +2 -4
- package/dist/cjs/actions/public/getTransactionReceipt.js.map +1 -1
- package/dist/cjs/actions/public/simulateContract.js.map +1 -1
- package/dist/cjs/actions/public/watchBlocks.js +3 -1
- package/dist/cjs/actions/public/watchBlocks.js.map +1 -1
- package/dist/cjs/actions/test/sendUnsignedTransaction.js +3 -6
- package/dist/cjs/actions/test/sendUnsignedTransaction.js.map +1 -1
- package/dist/cjs/actions/wallet/sendTransaction.js +5 -7
- package/dist/cjs/actions/wallet/sendTransaction.js.map +1 -1
- package/dist/cjs/chains/formatters/celo.js +62 -0
- package/dist/cjs/chains/formatters/celo.js.map +1 -0
- package/dist/cjs/chains/formatters/optimism.js +43 -0
- package/dist/cjs/chains/formatters/optimism.js.map +1 -0
- package/dist/cjs/{chains.js → chains/index.js} +16 -50
- package/dist/cjs/chains/index.js.map +1 -0
- package/dist/cjs/errors/version.js +1 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/serializer.js +3 -0
- package/dist/cjs/types/serializer.js.map +1 -0
- package/dist/cjs/utils/chain.js +6 -2
- package/dist/cjs/utils/chain.js.map +1 -1
- package/dist/cjs/utils/formatters/block.js +2 -4
- package/dist/cjs/utils/formatters/block.js.map +1 -1
- package/dist/cjs/utils/formatters/formatter.js +21 -0
- package/dist/cjs/utils/formatters/formatter.js.map +1 -0
- package/dist/cjs/utils/formatters/transaction.js +3 -4
- package/dist/cjs/utils/formatters/transaction.js.map +1 -1
- package/dist/cjs/utils/formatters/transactionReceipt.js +3 -5
- package/dist/cjs/utils/formatters/transactionReceipt.js.map +1 -1
- package/dist/cjs/utils/formatters/transactionRequest.js +2 -4
- package/dist/cjs/utils/formatters/transactionRequest.js.map +1 -1
- package/dist/cjs/utils/index.js +6 -5
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/transaction/getTransactionType.js.map +1 -1
- package/dist/cjs/utils/transaction/serializeAccessList.js +26 -0
- package/dist/cjs/utils/transaction/serializeAccessList.js.map +1 -0
- package/dist/cjs/utils/transaction/serializeTransaction.js +3 -22
- package/dist/cjs/utils/transaction/serializeTransaction.js.map +1 -1
- package/dist/cjs/wallet.js.map +1 -1
- package/dist/esm/accounts/privateKeyToAccount.js +2 -2
- package/dist/esm/accounts/privateKeyToAccount.js.map +1 -1
- package/dist/esm/accounts/utils/signTransaction.js +4 -4
- package/dist/esm/accounts/utils/signTransaction.js.map +1 -1
- package/dist/esm/actions/public/call.js +3 -6
- package/dist/esm/actions/public/call.js.map +1 -1
- package/dist/esm/actions/public/estimateContractGas.js.map +1 -1
- package/dist/esm/actions/public/estimateGas.js +3 -6
- package/dist/esm/actions/public/estimateGas.js.map +1 -1
- package/dist/esm/actions/public/getBlock.js +2 -4
- package/dist/esm/actions/public/getBlock.js.map +1 -1
- package/dist/esm/actions/public/getTransaction.js +2 -4
- package/dist/esm/actions/public/getTransaction.js.map +1 -1
- package/dist/esm/actions/public/getTransactionConfirmations.js.map +1 -1
- package/dist/esm/actions/public/getTransactionReceipt.js +2 -4
- package/dist/esm/actions/public/getTransactionReceipt.js.map +1 -1
- package/dist/esm/actions/public/simulateContract.js.map +1 -1
- package/dist/esm/actions/public/watchBlocks.js +3 -1
- package/dist/esm/actions/public/watchBlocks.js.map +1 -1
- package/dist/esm/actions/test/sendUnsignedTransaction.js +3 -6
- package/dist/esm/actions/test/sendUnsignedTransaction.js.map +1 -1
- package/dist/esm/actions/wallet/sendTransaction.js +5 -7
- package/dist/esm/actions/wallet/sendTransaction.js.map +1 -1
- package/dist/esm/chains/formatters/celo.js +59 -0
- package/dist/esm/chains/formatters/celo.js.map +1 -0
- package/dist/esm/chains/formatters/optimism.js +40 -0
- package/dist/esm/chains/formatters/optimism.js.map +1 -0
- package/dist/esm/{chains.js → chains/index.js} +13 -47
- package/dist/esm/chains/index.js.map +1 -0
- package/dist/esm/errors/version.js +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/serializer.js +2 -0
- package/dist/esm/types/serializer.js.map +1 -0
- package/dist/esm/utils/chain.js +6 -2
- package/dist/esm/utils/chain.js.map +1 -1
- package/dist/esm/utils/formatters/block.js +2 -5
- package/dist/esm/utils/formatters/block.js.map +1 -1
- package/dist/esm/utils/formatters/formatter.js +17 -0
- package/dist/esm/utils/formatters/formatter.js.map +1 -0
- package/dist/esm/utils/formatters/transaction.js +4 -4
- package/dist/esm/utils/formatters/transaction.js.map +1 -1
- package/dist/esm/utils/formatters/transactionReceipt.js +3 -5
- package/dist/esm/utils/formatters/transactionReceipt.js.map +1 -1
- package/dist/esm/utils/formatters/transactionRequest.js +2 -4
- package/dist/esm/utils/formatters/transactionRequest.js.map +1 -1
- package/dist/esm/utils/index.js +3 -2
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/transaction/getTransactionType.js.map +1 -1
- package/dist/esm/utils/transaction/serializeAccessList.js +32 -0
- package/dist/esm/utils/transaction/serializeAccessList.js.map +1 -0
- package/dist/esm/utils/transaction/serializeTransaction.js +2 -21
- package/dist/esm/utils/transaction/serializeTransaction.js.map +1 -1
- package/dist/esm/wallet.js.map +1 -1
- package/dist/types/accounts/types.d.ts +7 -2
- package/dist/types/accounts/types.d.ts.map +1 -1
- package/dist/types/accounts/utils/signTransaction.d.ts +5 -3
- package/dist/types/accounts/utils/signTransaction.d.ts.map +1 -1
- package/dist/types/actions/public/call.d.ts +3 -7
- package/dist/types/actions/public/call.d.ts.map +1 -1
- package/dist/types/actions/public/estimateContractGas.d.ts +1 -1
- package/dist/types/actions/public/estimateContractGas.d.ts.map +1 -1
- package/dist/types/actions/public/estimateGas.d.ts +3 -7
- package/dist/types/actions/public/estimateGas.d.ts.map +1 -1
- package/dist/types/actions/public/getBlock.d.ts +2 -2
- package/dist/types/actions/public/getBlock.d.ts.map +1 -1
- package/dist/types/actions/public/getTransaction.d.ts +2 -2
- package/dist/types/actions/public/getTransaction.d.ts.map +1 -1
- package/dist/types/actions/public/getTransactionConfirmations.d.ts +2 -2
- package/dist/types/actions/public/getTransactionConfirmations.d.ts.map +1 -1
- package/dist/types/actions/public/getTransactionReceipt.d.ts +3 -3
- package/dist/types/actions/public/getTransactionReceipt.d.ts.map +1 -1
- package/dist/types/actions/public/simulateContract.d.ts +1 -1
- package/dist/types/actions/public/simulateContract.d.ts.map +1 -1
- package/dist/types/actions/public/verifyHash.d.ts +1 -1
- package/dist/types/actions/public/verifyHash.d.ts.map +1 -1
- package/dist/types/actions/public/verifyMessage.d.ts +1 -1
- package/dist/types/actions/public/verifyMessage.d.ts.map +1 -1
- package/dist/types/actions/public/verifyTypedData.d.ts +1 -1
- package/dist/types/actions/public/verifyTypedData.d.ts.map +1 -1
- package/dist/types/actions/public/watchBlocks.d.ts.map +1 -1
- package/dist/types/actions/test/sendUnsignedTransaction.d.ts +2 -8
- package/dist/types/actions/test/sendUnsignedTransaction.d.ts.map +1 -1
- package/dist/types/actions/wallet/sendTransaction.d.ts +2 -7
- package/dist/types/actions/wallet/sendTransaction.d.ts.map +1 -1
- package/dist/types/chains/formatters/celo.d.ts +235 -0
- package/dist/types/chains/formatters/celo.d.ts.map +1 -0
- package/dist/types/chains/formatters/optimism.d.ts +286 -0
- package/dist/types/chains/formatters/optimism.d.ts.map +1 -0
- package/dist/types/chains/index.d.ts +5246 -0
- package/dist/types/chains/index.d.ts.map +1 -0
- package/dist/types/errors/version.d.ts +1 -1
- package/dist/types/index.d.ts +7 -6
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/chain.d.ts +3 -1
- package/dist/types/types/chain.d.ts.map +1 -1
- package/dist/types/types/fee.d.ts +1 -0
- package/dist/types/types/fee.d.ts.map +1 -1
- package/dist/types/types/formatter.d.ts +8 -10
- package/dist/types/types/formatter.d.ts.map +1 -1
- package/dist/types/types/rpc.d.ts +1 -1
- package/dist/types/types/rpc.d.ts.map +1 -1
- package/dist/types/types/serializer.d.ts +7 -0
- package/dist/types/types/serializer.d.ts.map +1 -0
- package/dist/types/types/transaction.d.ts +14 -3
- package/dist/types/types/transaction.d.ts.map +1 -1
- package/dist/types/types/utils.d.ts +5 -5
- package/dist/types/types/utils.d.ts.map +1 -1
- package/dist/types/utils/chain.d.ts +4 -1
- package/dist/types/utils/chain.d.ts.map +1 -1
- package/dist/types/utils/formatters/block.d.ts +5 -11
- package/dist/types/utils/formatters/block.d.ts.map +1 -1
- package/dist/types/utils/formatters/formatter.d.ts +6 -0
- package/dist/types/utils/formatters/formatter.d.ts.map +1 -0
- package/dist/types/utils/formatters/transaction.d.ts +5 -11
- package/dist/types/utils/formatters/transaction.d.ts.map +1 -1
- package/dist/types/utils/formatters/transactionReceipt.d.ts +5 -11
- package/dist/types/utils/formatters/transactionReceipt.d.ts.map +1 -1
- package/dist/types/utils/formatters/transactionRequest.d.ts +5 -11
- package/dist/types/utils/formatters/transactionRequest.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +7 -6
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/transaction/getTransactionType.d.ts +2 -2
- package/dist/types/utils/transaction/getTransactionType.d.ts.map +1 -1
- package/dist/types/utils/transaction/serializeAccessList.d.ts +5 -0
- package/dist/types/utils/transaction/serializeAccessList.d.ts.map +1 -0
- package/dist/types/utils/transaction/serializeTransaction.d.ts +1 -0
- package/dist/types/utils/transaction/serializeTransaction.d.ts.map +1 -1
- package/dist/types/wallet.d.ts +1 -1
- package/dist/types/wallet.d.ts.map +1 -1
- package/package.json +8 -5
- package/src/accounts/privateKeyToAccount.ts +2 -2
- package/src/accounts/types.ts +20 -2
- package/src/accounts/utils/signTransaction.ts +9 -6
- package/src/actions/public/call.ts +20 -30
- package/src/actions/public/estimateContractGas.ts +7 -1
- package/src/actions/public/estimateGas.ts +20 -30
- package/src/actions/public/getBlock.ts +3 -6
- package/src/actions/public/getTransaction.ts +3 -6
- package/src/actions/public/getTransactionConfirmations.ts +2 -7
- package/src/actions/public/getTransactionReceipt.ts +4 -7
- package/src/actions/public/simulateContract.ts +7 -1
- package/src/actions/public/verifyHash.ts +1 -1
- package/src/actions/public/verifyMessage.ts +1 -1
- package/src/actions/public/verifyTypedData.ts +1 -1
- package/src/actions/public/watchBlocks.ts +3 -1
- package/src/actions/test/sendUnsignedTransaction.ts +18 -32
- package/src/actions/wallet/sendTransaction.ts +27 -36
- package/src/chains/formatters/celo.ts +102 -0
- package/src/chains/formatters/optimism.ts +88 -0
- package/src/{chains.ts → chains/index.ts} +13 -56
- package/src/errors/version.ts +1 -1
- package/src/index.ts +6 -9
- package/src/types/chain.ts +8 -1
- package/src/types/fee.ts +1 -0
- package/src/types/formatter.ts +26 -17
- package/src/types/rpc.ts +1 -1
- package/src/types/serializer.ts +19 -0
- package/src/types/transaction.ts +24 -4
- package/src/types/utils.ts +5 -5
- package/src/utils/chain.ts +11 -4
- package/src/utils/formatters/block.ts +5 -17
- package/src/utils/formatters/formatter.ts +32 -0
- package/src/utils/formatters/transaction.ts +7 -21
- package/src/utils/formatters/transactionReceipt.ts +10 -22
- package/src/utils/formatters/transactionRequest.ts +7 -22
- package/src/utils/index.ts +6 -11
- package/src/utils/transaction/getTransactionType.ts +10 -9
- package/src/utils/transaction/serializeAccessList.ts +39 -0
- package/src/utils/transaction/serializeTransaction.ts +11 -34
- package/src/wallet.ts +0 -1
- package/dist/cjs/chains.js.map +0 -1
- package/dist/cjs/utils/formatters/format.js +0 -23
- package/dist/cjs/utils/formatters/format.js.map +0 -1
- package/dist/esm/chains.js.map +0 -1
- package/dist/esm/utils/formatters/format.js +0 -21
- package/dist/esm/utils/formatters/format.js.map +0 -1
- package/dist/types/chains.d.ts +0 -2834
- package/dist/types/chains.d.ts.map +0 -1
- package/dist/types/utils/formatters/format.d.ts +0 -38
- package/dist/types/utils/formatters/format.d.ts.map +0 -1
- package/src/utils/formatters/format.ts +0 -99
@@ -4,27 +4,17 @@ import type {
|
|
4
4
|
} from '../../clients/createTestClient.js'
|
5
5
|
import type { Transport } from '../../clients/transports/createTransport.js'
|
6
6
|
import type { Chain } from '../../types/chain.js'
|
7
|
-
import type { Formatter } from '../../types/formatter.js'
|
8
7
|
import type { Hash } from '../../types/misc.js'
|
9
8
|
import type { TransactionRequest } from '../../types/transaction.js'
|
10
|
-
import type { MergeIntersectionProperties } from '../../types/utils.js'
|
11
9
|
import { extract } from '../../utils/formatters/extract.js'
|
12
|
-
import { type Formatted, format } from '../../utils/formatters/format.js'
|
13
10
|
import {
|
14
|
-
type
|
11
|
+
type FormattedTransactionRequest,
|
15
12
|
formatTransactionRequest,
|
16
13
|
} from '../../utils/formatters/transactionRequest.js'
|
17
14
|
|
18
|
-
type FormattedTransactionRequest<
|
19
|
-
TFormatter extends Formatter | undefined = Formatter,
|
20
|
-
> = MergeIntersectionProperties<
|
21
|
-
Formatted<TFormatter, TransactionRequest, true>,
|
22
|
-
TransactionRequest
|
23
|
-
>
|
24
|
-
|
25
15
|
export type SendUnsignedTransactionParameters<
|
26
16
|
TChain extends Chain | undefined = Chain | undefined,
|
27
|
-
> = FormattedTransactionRequest<
|
17
|
+
> = FormattedTransactionRequest<TChain>
|
28
18
|
|
29
19
|
export type SendUnsignedTransactionReturnType = Hash
|
30
20
|
|
@@ -73,26 +63,22 @@ export async function sendUnsignedTransaction<
|
|
73
63
|
...rest
|
74
64
|
} = args
|
75
65
|
|
76
|
-
const
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
{
|
93
|
-
formatter: formatter || formatTransactionRequest,
|
94
|
-
},
|
95
|
-
)
|
66
|
+
const format =
|
67
|
+
client.chain?.formatters?.transactionRequest || formatTransactionRequest
|
68
|
+
const request = format({
|
69
|
+
// Pick out extra data that might exist on the chain's transaction request type.
|
70
|
+
...extract(rest, { formatter: format }),
|
71
|
+
accessList,
|
72
|
+
data,
|
73
|
+
from,
|
74
|
+
gas,
|
75
|
+
gasPrice,
|
76
|
+
maxFeePerGas,
|
77
|
+
maxPriorityFeePerGas,
|
78
|
+
nonce,
|
79
|
+
to,
|
80
|
+
value,
|
81
|
+
} as TransactionRequest)
|
96
82
|
const hash = await client.request({
|
97
83
|
method: 'eth_sendUnsignedTransaction',
|
98
84
|
params: [request],
|
@@ -6,37 +6,27 @@ import { AccountNotFoundError } from '../../errors/account.js'
|
|
6
6
|
import type { BaseError } from '../../errors/base.js'
|
7
7
|
import type { GetAccountParameter } from '../../types/account.js'
|
8
8
|
import type { Chain, GetChain } from '../../types/chain.js'
|
9
|
-
import type { Formatter } from '../../types/formatter.js'
|
10
9
|
import type { Hash } from '../../types/misc.js'
|
11
10
|
import type {
|
12
11
|
TransactionRequest,
|
13
12
|
TransactionSerializable,
|
14
13
|
} from '../../types/transaction.js'
|
15
|
-
import type { MergeIntersectionProperties } from '../../types/utils.js'
|
16
14
|
import { assertCurrentChain } from '../../utils/chain.js'
|
17
15
|
import { getTransactionError } from '../../utils/errors/getTransactionError.js'
|
18
16
|
import { extract } from '../../utils/formatters/extract.js'
|
19
|
-
import { type Formatted, format } from '../../utils/formatters/format.js'
|
20
17
|
import {
|
21
|
-
type
|
18
|
+
type FormattedTransactionRequest,
|
22
19
|
formatTransactionRequest,
|
23
20
|
} from '../../utils/formatters/transactionRequest.js'
|
24
21
|
import { assertRequest } from '../../utils/transaction/assertRequest.js'
|
25
22
|
import { prepareRequest } from '../../utils/transaction/prepareRequest.js'
|
26
23
|
import { getChainId } from '../public/getChainId.js'
|
27
24
|
|
28
|
-
export type FormattedTransactionRequest<
|
29
|
-
TFormatter extends Formatter | undefined = Formatter,
|
30
|
-
> = MergeIntersectionProperties<
|
31
|
-
Omit<Formatted<TFormatter, TransactionRequest, true>, 'from'>,
|
32
|
-
TransactionRequest
|
33
|
-
>
|
34
|
-
|
35
25
|
export type SendTransactionParameters<
|
36
26
|
TChain extends Chain | undefined = Chain | undefined,
|
37
27
|
TAccount extends Account | undefined = Account | undefined,
|
38
28
|
TChainOverride extends Chain | undefined = Chain,
|
39
|
-
> = FormattedTransactionRequest<
|
29
|
+
> = Omit<FormattedTransactionRequest<TChainOverride>, 'from'> &
|
40
30
|
GetAccountParameter<TAccount> &
|
41
31
|
GetChain<TChain, TChainOverride>
|
42
32
|
|
@@ -146,36 +136,37 @@ export async function sendTransaction<
|
|
146
136
|
})
|
147
137
|
|
148
138
|
if (!chainId) chainId = await getChainId(client)
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
139
|
+
|
140
|
+
const serializer = chain?.serializers?.transaction
|
141
|
+
const signedRequest = (await account.signTransaction(
|
142
|
+
{
|
143
|
+
...request,
|
144
|
+
chainId,
|
145
|
+
} as TransactionSerializable,
|
146
|
+
{ serializer },
|
147
|
+
)) as Hash
|
153
148
|
return await client.request({
|
154
149
|
method: 'eth_sendRawTransaction',
|
155
150
|
params: [signedRequest],
|
156
151
|
})
|
157
152
|
}
|
158
153
|
|
159
|
-
const
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
{
|
176
|
-
formatter: formatter || formatTransactionRequest,
|
177
|
-
},
|
178
|
-
)
|
154
|
+
const format =
|
155
|
+
chain?.formatters?.transactionRequest || formatTransactionRequest
|
156
|
+
const request = format({
|
157
|
+
// Pick out extra data that might exist on the chain's transaction request type.
|
158
|
+
...extract(rest, { formatter: format }),
|
159
|
+
accessList,
|
160
|
+
data,
|
161
|
+
from: account.address,
|
162
|
+
gas,
|
163
|
+
gasPrice,
|
164
|
+
maxFeePerGas,
|
165
|
+
maxPriorityFeePerGas,
|
166
|
+
nonce,
|
167
|
+
to,
|
168
|
+
value,
|
169
|
+
} as TransactionRequest)
|
179
170
|
return await client.request({
|
180
171
|
method: 'eth_sendTransaction',
|
181
172
|
params: [request],
|
@@ -0,0 +1,102 @@
|
|
1
|
+
import type { Address } from 'abitype'
|
2
|
+
|
3
|
+
import type { Hash, Hex } from '../../types/misc.js'
|
4
|
+
import type { RpcTransaction } from '../../types/rpc.js'
|
5
|
+
import type { Transaction } from '../../types/transaction.js'
|
6
|
+
import { hexToBigInt } from '../../utils/encoding/fromHex.js'
|
7
|
+
import { numberToHex } from '../../utils/encoding/toHex.js'
|
8
|
+
import { defineBlock } from '../../utils/formatters/block.js'
|
9
|
+
import {
|
10
|
+
defineTransaction,
|
11
|
+
formatTransaction,
|
12
|
+
} from '../../utils/formatters/transaction.js'
|
13
|
+
import { defineTransactionReceipt } from '../../utils/formatters/transactionReceipt.js'
|
14
|
+
import { defineTransactionRequest } from '../../utils/formatters/transactionRequest.js'
|
15
|
+
|
16
|
+
export type CeloOverrides = {
|
17
|
+
RpcBlock: {
|
18
|
+
randomness: {
|
19
|
+
committed: Hex
|
20
|
+
revealed: Hex
|
21
|
+
}
|
22
|
+
transactions:
|
23
|
+
| Hash[]
|
24
|
+
| (RpcTransaction & {
|
25
|
+
feeCurrency: Address | null
|
26
|
+
gatewayFee: Hex | null
|
27
|
+
gatewayFeeRecipient: Address | null
|
28
|
+
})[]
|
29
|
+
}
|
30
|
+
RpcTransaction: {
|
31
|
+
feeCurrency: Address | null
|
32
|
+
gatewayFee: Hex | null
|
33
|
+
gatewayFeeRecipient: Address | null
|
34
|
+
}
|
35
|
+
RpcTransactionReceipt: {
|
36
|
+
feeCurrency: Address | null
|
37
|
+
gatewayFee: Hex | null
|
38
|
+
gatewayFeeRecipient: Address | null
|
39
|
+
}
|
40
|
+
TransactionRequest: {
|
41
|
+
feeCurrency?: Address
|
42
|
+
gatewayFee?: bigint
|
43
|
+
gatewayFeeRecipient?: Address
|
44
|
+
}
|
45
|
+
Transaction: {
|
46
|
+
feeCurrency: Address | null
|
47
|
+
gatewayFee: bigint | null
|
48
|
+
gatewayFeeRecipient: Address | null
|
49
|
+
}
|
50
|
+
}
|
51
|
+
export const celoFormatters = {
|
52
|
+
block: /*#__PURE__*/ defineBlock({
|
53
|
+
exclude: ['difficulty', 'gasLimit', 'mixHash', 'nonce', 'uncles'],
|
54
|
+
format(args: CeloOverrides['RpcBlock']) {
|
55
|
+
const transactions = args.transactions?.map((transaction) => {
|
56
|
+
if (typeof transaction === 'string') return transaction
|
57
|
+
return {
|
58
|
+
...formatTransaction(transaction),
|
59
|
+
feeCurrency: transaction.feeCurrency,
|
60
|
+
gatewayFee: transaction.gatewayFee
|
61
|
+
? hexToBigInt(transaction.gatewayFee)
|
62
|
+
: null,
|
63
|
+
gatewayFeeRecipient: transaction.gatewayFeeRecipient,
|
64
|
+
}
|
65
|
+
}) as Hash[] | (Transaction & CeloOverrides['Transaction'])[]
|
66
|
+
return {
|
67
|
+
randomness: args.randomness,
|
68
|
+
transactions,
|
69
|
+
}
|
70
|
+
},
|
71
|
+
}),
|
72
|
+
transaction: /*#__PURE__*/ defineTransaction({
|
73
|
+
format(args: CeloOverrides['RpcTransaction']) {
|
74
|
+
return {
|
75
|
+
feeCurrency: args.feeCurrency,
|
76
|
+
gatewayFee: args.gatewayFee ? hexToBigInt(args.gatewayFee) : null,
|
77
|
+
gatewayFeeRecipient: args.gatewayFeeRecipient,
|
78
|
+
}
|
79
|
+
},
|
80
|
+
}),
|
81
|
+
transactionReceipt: /*#__PURE__*/ defineTransactionReceipt({
|
82
|
+
format(args: CeloOverrides['RpcTransactionReceipt']) {
|
83
|
+
return {
|
84
|
+
feeCurrency: args.feeCurrency,
|
85
|
+
gatewayFee: args.gatewayFee ? hexToBigInt(args.gatewayFee) : null,
|
86
|
+
gatewayFeeRecipient: args.gatewayFeeRecipient,
|
87
|
+
}
|
88
|
+
},
|
89
|
+
}),
|
90
|
+
transactionRequest: /*#__PURE__*/ defineTransactionRequest({
|
91
|
+
format(args: CeloOverrides['TransactionRequest']) {
|
92
|
+
return {
|
93
|
+
feeCurrency: args.feeCurrency,
|
94
|
+
gatewayFee:
|
95
|
+
typeof args.gatewayFee !== 'undefined'
|
96
|
+
? numberToHex(args.gatewayFee)
|
97
|
+
: undefined,
|
98
|
+
gatewayFeeRecipient: args.gatewayFeeRecipient,
|
99
|
+
}
|
100
|
+
},
|
101
|
+
}),
|
102
|
+
} as const
|
@@ -0,0 +1,88 @@
|
|
1
|
+
import { defineBlock, formatTransaction } from '../../index.js'
|
2
|
+
import type { FeeValuesEIP1559 } from '../../types/fee.js'
|
3
|
+
import type { Hash, Hex } from '../../types/misc.js'
|
4
|
+
import type {
|
5
|
+
Index,
|
6
|
+
Quantity,
|
7
|
+
RpcTransaction as RpcTransaction_,
|
8
|
+
} from '../../types/rpc.js'
|
9
|
+
import type {
|
10
|
+
Transaction as Transaction_,
|
11
|
+
TransactionBase,
|
12
|
+
} from '../../types/transaction.js'
|
13
|
+
import { hexToBigInt } from '../../utils/encoding/fromHex.js'
|
14
|
+
import { defineTransaction } from '../../utils/formatters/transaction.js'
|
15
|
+
|
16
|
+
type RpcTransaction = RpcTransaction_ & {
|
17
|
+
isSystemTx?: undefined
|
18
|
+
mint?: undefined
|
19
|
+
sourceHash?: undefined
|
20
|
+
}
|
21
|
+
|
22
|
+
type RpcDepositTransaction = TransactionBase<Quantity, Index> &
|
23
|
+
FeeValuesEIP1559<Quantity> & {
|
24
|
+
isSystemTx?: boolean
|
25
|
+
mint?: Hex
|
26
|
+
sourceHash: Hex
|
27
|
+
type: '0x7e'
|
28
|
+
}
|
29
|
+
|
30
|
+
type Transaction = Transaction_ & {
|
31
|
+
isSystemTx?: undefined
|
32
|
+
mint?: undefined
|
33
|
+
sourceHash?: undefined
|
34
|
+
}
|
35
|
+
|
36
|
+
type DepositTransaction = TransactionBase &
|
37
|
+
FeeValuesEIP1559 & {
|
38
|
+
isSystemTx?: boolean
|
39
|
+
mint?: bigint
|
40
|
+
sourceHash: Hex
|
41
|
+
type: 'deposit'
|
42
|
+
}
|
43
|
+
|
44
|
+
type OptimismOverrides = {
|
45
|
+
RpcBlock: {
|
46
|
+
transactions: Hash[] | OptimismOverrides['RpcTransaction'][]
|
47
|
+
}
|
48
|
+
RpcTransaction: RpcTransaction | RpcDepositTransaction
|
49
|
+
Transaction: Transaction | DepositTransaction
|
50
|
+
}
|
51
|
+
|
52
|
+
export const optimismFormatters = {
|
53
|
+
block: /*#__PURE__*/ defineBlock({
|
54
|
+
exclude: ['difficulty', 'gasLimit', 'mixHash', 'nonce', 'uncles'],
|
55
|
+
format(args: OptimismOverrides['RpcBlock']) {
|
56
|
+
const transactions = args.transactions?.map((transaction) => {
|
57
|
+
if (typeof transaction === 'string') return transaction
|
58
|
+
const formatted = formatTransaction(
|
59
|
+
transaction as RpcTransaction,
|
60
|
+
) as OptimismOverrides['Transaction']
|
61
|
+
if (formatted.typeHex === '0x7e') {
|
62
|
+
formatted.isSystemTx = transaction.isSystemTx
|
63
|
+
formatted.mint = transaction.mint
|
64
|
+
? hexToBigInt(transaction.mint)
|
65
|
+
: undefined
|
66
|
+
formatted.sourceHash = transaction.sourceHash
|
67
|
+
formatted.type = 'deposit'
|
68
|
+
}
|
69
|
+
return formatted
|
70
|
+
}) as Hash[] | OptimismOverrides['Transaction'][]
|
71
|
+
return {
|
72
|
+
transactions,
|
73
|
+
}
|
74
|
+
},
|
75
|
+
}),
|
76
|
+
transaction: /*#__PURE__*/ defineTransaction({
|
77
|
+
format(args: OptimismOverrides['RpcTransaction']) {
|
78
|
+
const transaction = {} as OptimismOverrides['Transaction']
|
79
|
+
if (args.type === '0x7e') {
|
80
|
+
transaction.isSystemTx = args.isSystemTx
|
81
|
+
transaction.mint = args.mint ? hexToBigInt(args.mint) : undefined
|
82
|
+
transaction.sourceHash = args.sourceHash
|
83
|
+
transaction.type = 'deposit'
|
84
|
+
}
|
85
|
+
return transaction
|
86
|
+
},
|
87
|
+
}),
|
88
|
+
} as const
|
@@ -1,53 +1,9 @@
|
|
1
1
|
import * as chains from '@wagmi/chains'
|
2
2
|
|
3
|
-
import
|
3
|
+
import { defineChain } from '../utils/chain.js'
|
4
|
+
import { celoFormatters } from './formatters/celo.js'
|
5
|
+
import { optimismFormatters } from './formatters/optimism.js'
|
4
6
|
|
5
|
-
import type { Hex } from './types/misc.js'
|
6
|
-
import type { Quantity } from './types/rpc.js'
|
7
|
-
import { defineChain } from './utils/chain.js'
|
8
|
-
import { defineBlock } from './utils/formatters/block.js'
|
9
|
-
import { defineTransaction } from './utils/formatters/transaction.js'
|
10
|
-
import { defineTransactionReceipt } from './utils/formatters/transactionReceipt.js'
|
11
|
-
import { defineTransactionRequest } from './utils/formatters/transactionRequest.js'
|
12
|
-
|
13
|
-
const celoFormatters = {
|
14
|
-
block: /*#__PURE__*/ defineBlock({
|
15
|
-
exclude: ['difficulty', 'gasLimit', 'mixHash', 'nonce', 'uncles'],
|
16
|
-
format: (block) => ({
|
17
|
-
randomness: block.randomness as {
|
18
|
-
committed: Hex
|
19
|
-
revealed: Hex
|
20
|
-
},
|
21
|
-
}),
|
22
|
-
}),
|
23
|
-
transaction: /*#__PURE__*/ defineTransaction({
|
24
|
-
format: (transaction) => ({
|
25
|
-
feeCurrency: transaction.feeCurrency as Address | null,
|
26
|
-
gatewayFee: transaction.gatewayFee
|
27
|
-
? BigInt(transaction.gatewayFee as Quantity)
|
28
|
-
: null,
|
29
|
-
gatewayFeeRecipient: transaction.gatewayFeeRecipient as Address | null,
|
30
|
-
}),
|
31
|
-
}),
|
32
|
-
transactionReceipt: /*#__PURE__*/ defineTransactionReceipt({
|
33
|
-
format: (transaction) => ({
|
34
|
-
feeCurrency: transaction.feeCurrency as Address | null,
|
35
|
-
gatewayFee: transaction.gatewayFee
|
36
|
-
? BigInt(transaction.gatewayFee as Quantity)
|
37
|
-
: null,
|
38
|
-
gatewayFeeRecipient: transaction.gatewayFeeRecipient as Address | null,
|
39
|
-
}),
|
40
|
-
}),
|
41
|
-
transactionRequest: /*#__PURE__*/ defineTransactionRequest({
|
42
|
-
format: (transactionRequest) => ({
|
43
|
-
feeCurrency: transactionRequest.feeCurrency as Address | undefined,
|
44
|
-
gatewayFee: transactionRequest.gatewayFee as Quantity | undefined,
|
45
|
-
gatewayFeeRecipient: transactionRequest.gatewayFeeRecipient as
|
46
|
-
| Address
|
47
|
-
| undefined,
|
48
|
-
}),
|
49
|
-
}),
|
50
|
-
}
|
51
7
|
export const arbitrum = /*#__PURE__*/ defineChain(chains.arbitrum)
|
52
8
|
export const arbitrumGoerli = /*#__PURE__*/ defineChain(chains.arbitrumGoerli)
|
53
9
|
export const aurora = /*#__PURE__*/ defineChain(chains.aurora)
|
@@ -61,16 +17,13 @@ export const bronosTestnet = /*#__PURE__*/ defineChain(chains.bronosTestnet)
|
|
61
17
|
export const bsc = /*#__PURE__*/ defineChain(chains.bsc)
|
62
18
|
export const bscTestnet = /*#__PURE__*/ defineChain(chains.bscTestnet)
|
63
19
|
export const canto = /*#__PURE__*/ defineChain(chains.canto)
|
64
|
-
export const celo = /*#__PURE__*/ defineChain({
|
65
|
-
...chains.celo,
|
20
|
+
export const celo = /*#__PURE__*/ defineChain(chains.celo, {
|
66
21
|
formatters: celoFormatters,
|
67
22
|
})
|
68
|
-
export const celoAlfajores = /*#__PURE__*/ defineChain({
|
69
|
-
...chains.celoAlfajores,
|
23
|
+
export const celoAlfajores = /*#__PURE__*/ defineChain(chains.celoAlfajores, {
|
70
24
|
formatters: celoFormatters,
|
71
25
|
})
|
72
|
-
export const celoCannoli = /*#__PURE__*/ defineChain({
|
73
|
-
...chains.celoCannoli,
|
26
|
+
export const celoCannoli = /*#__PURE__*/ defineChain(chains.celoCannoli, {
|
74
27
|
formatters: celoFormatters,
|
75
28
|
})
|
76
29
|
export const cronos = /*#__PURE__*/ defineChain(chains.cronos)
|
@@ -111,8 +64,12 @@ export const moonbeam = /*#__PURE__*/ defineChain(chains.moonbeam)
|
|
111
64
|
export const moonriver = /*#__PURE__*/ defineChain(chains.moonriver)
|
112
65
|
export const nexi = /*#__PURE__*/ defineChain(chains.nexi)
|
113
66
|
export const okc = /*#__PURE__*/ defineChain(chains.okc)
|
114
|
-
export const optimism = /*#__PURE__*/ defineChain(chains.optimism
|
115
|
-
|
67
|
+
export const optimism = /*#__PURE__*/ defineChain(chains.optimism, {
|
68
|
+
formatters: optimismFormatters,
|
69
|
+
})
|
70
|
+
export const optimismGoerli = /*#__PURE__*/ defineChain(chains.optimismGoerli, {
|
71
|
+
formatters: optimismFormatters,
|
72
|
+
})
|
116
73
|
export const polygon = /*#__PURE__*/ defineChain(chains.polygon)
|
117
74
|
export const polygonMumbai = /*#__PURE__*/ defineChain(chains.polygonMumbai)
|
118
75
|
export const polygonZkEvm = /*#__PURE__*/ defineChain(chains.polygonZkEvm)
|
@@ -174,4 +131,4 @@ export const zkSync = /*#__PURE__*/ defineChain(chains.zkSync)
|
|
174
131
|
export const zkSyncTestnet = /*#__PURE__*/ defineChain(chains.zkSyncTestnet)
|
175
132
|
export const zoraTestnet = /*#__PURE__*/ defineChain(chains.zoraTestnet)
|
176
133
|
|
177
|
-
export type { Chain } from '
|
134
|
+
export type { Chain } from '../types/chain.js'
|
package/src/errors/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = '1.0
|
1
|
+
export const version = '1.1.0'
|
package/src/index.ts
CHANGED
@@ -476,6 +476,7 @@ export type {
|
|
476
476
|
Formatter,
|
477
477
|
Formatters,
|
478
478
|
} from './types/formatter.js'
|
479
|
+
export type { Serializers } from './types/serializer.js'
|
479
480
|
export type {
|
480
481
|
GetTypedDataDomain,
|
481
482
|
GetTypedDataMessage,
|
@@ -507,7 +508,6 @@ export type {
|
|
507
508
|
export { labelhash } from './utils/ens/labelhash.js'
|
508
509
|
export { namehash } from './utils/ens/namehash.js'
|
509
510
|
export {
|
510
|
-
type BlockFormatter,
|
511
511
|
type FormattedBlock,
|
512
512
|
defineBlock,
|
513
513
|
formatBlock,
|
@@ -559,25 +559,18 @@ export {
|
|
559
559
|
type EncodeFunctionResultParameters,
|
560
560
|
encodeFunctionResult,
|
561
561
|
} from './utils/abi/encodeFunctionResult.js'
|
562
|
-
export type {
|
563
|
-
ExtractFormatter,
|
564
|
-
Formatted,
|
565
|
-
} from './utils/formatters/format.js'
|
566
562
|
export {
|
567
563
|
type FormattedTransaction,
|
568
|
-
type TransactionFormatter,
|
569
564
|
defineTransaction,
|
570
565
|
formatTransaction,
|
571
566
|
transactionType,
|
572
567
|
} from './utils/formatters/transaction.js'
|
573
568
|
export {
|
574
569
|
type FormattedTransactionReceipt,
|
575
|
-
type TransactionReceiptFormatter,
|
576
570
|
defineTransactionReceipt,
|
577
571
|
} from './utils/formatters/transactionReceipt.js'
|
578
572
|
export {
|
579
573
|
type FormattedTransactionRequest,
|
580
|
-
type TransactionRequestFormatter,
|
581
574
|
defineTransactionRequest,
|
582
575
|
formatTransactionRequest,
|
583
576
|
} from './utils/formatters/transactionRequest.js'
|
@@ -701,7 +694,11 @@ export { parseGwei } from './utils/unit/parseGwei.js'
|
|
701
694
|
export { parseTransaction } from './utils/transaction/parseTransaction.js'
|
702
695
|
export { parseUnits } from './utils/unit/parseUnits.js'
|
703
696
|
export { prepareRequest } from './utils/transaction/prepareRequest.js'
|
704
|
-
export {
|
697
|
+
export { serializeAccessList } from './utils/transaction/serializeAccessList.js'
|
698
|
+
export {
|
699
|
+
serializeTransaction,
|
700
|
+
type SerializeTransactionFn,
|
701
|
+
} from './utils/transaction/serializeTransaction.js'
|
705
702
|
export { size } from './utils/data/size.js'
|
706
703
|
export { slice, sliceBytes, sliceHex } from './utils/data/slice.js'
|
707
704
|
export { stringify } from './utils/stringify.js'
|
package/src/types/chain.ts
CHANGED
@@ -2,10 +2,17 @@ import type { Chain as Chain_ } from '@wagmi/chains'
|
|
2
2
|
import type { Address } from 'abitype'
|
3
3
|
|
4
4
|
import type { Formatters } from './formatter.js'
|
5
|
+
import type { Serializers } from './serializer.js'
|
5
6
|
import type { IsUndefined } from './utils.js'
|
6
7
|
|
7
|
-
export type Chain<
|
8
|
+
export type Chain<
|
9
|
+
TFormatters extends Formatters | undefined = Formatters | undefined,
|
10
|
+
TSerializers extends Serializers<TFormatters> | undefined =
|
11
|
+
| Serializers<TFormatters>
|
12
|
+
| undefined,
|
13
|
+
> = Chain_ & {
|
8
14
|
formatters?: TFormatters
|
15
|
+
serializers?: TSerializers
|
9
16
|
}
|
10
17
|
|
11
18
|
export type ChainContract = {
|
package/src/types/fee.ts
CHANGED
@@ -20,6 +20,7 @@ export type FeeValuesLegacy<TQuantity = bigint> = {
|
|
20
20
|
}
|
21
21
|
|
22
22
|
export type FeeValuesEIP1559<TQuantity = bigint> = {
|
23
|
+
/** Base fee per gas. */
|
23
24
|
gasPrice?: never
|
24
25
|
/** Total fee per gas in wei (gasPrice/baseFeePerGas + maxPriorityFeePerGas). */
|
25
26
|
maxFeePerGas: TQuantity
|
package/src/types/formatter.ts
CHANGED
@@ -1,23 +1,32 @@
|
|
1
|
-
import type {
|
2
|
-
import type {
|
3
|
-
RpcBlock,
|
4
|
-
RpcTransaction,
|
5
|
-
RpcTransactionReceipt,
|
6
|
-
RpcTransactionRequest,
|
7
|
-
} from './rpc.js'
|
8
|
-
import type {
|
9
|
-
Transaction,
|
10
|
-
TransactionReceipt,
|
11
|
-
TransactionRequest,
|
12
|
-
} from './transaction.js'
|
1
|
+
import type { Chain } from './chain.js'
|
13
2
|
|
14
3
|
export type Formatter<TSource = any, TTarget = any> = (
|
15
|
-
value: TSource
|
4
|
+
value: TSource,
|
16
5
|
) => TTarget
|
17
6
|
|
18
7
|
export type Formatters = {
|
19
|
-
block?: Formatter
|
20
|
-
transaction?: Formatter
|
21
|
-
transactionReceipt?: Formatter
|
22
|
-
transactionRequest?: Formatter
|
8
|
+
block?: Formatter
|
9
|
+
transaction?: Formatter
|
10
|
+
transactionReceipt?: Formatter
|
11
|
+
transactionRequest?: Formatter
|
23
12
|
}
|
13
|
+
|
14
|
+
export type ExtractFormatterParameters<
|
15
|
+
TChain extends Chain | undefined,
|
16
|
+
TType extends keyof Formatters,
|
17
|
+
TFallback,
|
18
|
+
> = TChain extends Chain<infer _Formatters extends Formatters>
|
19
|
+
? _Formatters[TType] extends Formatter
|
20
|
+
? Parameters<_Formatters[TType]>[0]
|
21
|
+
: TFallback
|
22
|
+
: TFallback
|
23
|
+
|
24
|
+
export type ExtractFormatterReturnType<
|
25
|
+
TChain extends Chain | undefined,
|
26
|
+
TType extends keyof Formatters,
|
27
|
+
TFallback,
|
28
|
+
> = TChain extends Chain<infer _Formatters extends Formatters>
|
29
|
+
? _Formatters[TType] extends Formatter
|
30
|
+
? ReturnType<_Formatters[TType]>
|
31
|
+
: TFallback
|
32
|
+
: TFallback
|
package/src/types/rpc.ts
CHANGED
@@ -12,7 +12,7 @@ import type {
|
|
12
12
|
export type Index = `0x${string}`
|
13
13
|
export type Quantity = `0x${string}`
|
14
14
|
export type Status = '0x0' | '0x1'
|
15
|
-
export type TransactionType = '0x0' | '0x1' | '0x2'
|
15
|
+
export type TransactionType = '0x0' | '0x1' | '0x2' | (string & {})
|
16
16
|
|
17
17
|
export type RpcBlock = Block<Quantity, RpcTransaction>
|
18
18
|
export type RpcBlockNumber = BlockNumber<Quantity>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import type {
|
2
|
+
TransactionSerializable,
|
3
|
+
TransactionSerializableGeneric,
|
4
|
+
} from '../types/transaction.js'
|
5
|
+
import type { SerializeTransactionFn } from '../utils/transaction/serializeTransaction.js'
|
6
|
+
import type { Formatter, Formatters } from './formatter.js'
|
7
|
+
|
8
|
+
export type Serializers<
|
9
|
+
TFormatters extends Formatters | undefined = undefined,
|
10
|
+
> = {
|
11
|
+
transaction?: SerializeTransactionFn<
|
12
|
+
TFormatters extends Formatters
|
13
|
+
? TFormatters['transactionRequest'] extends Formatter
|
14
|
+
? TransactionSerializableGeneric &
|
15
|
+
Parameters<TFormatters['transactionRequest']>[0]
|
16
|
+
: TransactionSerializable
|
17
|
+
: TransactionSerializable
|
18
|
+
>
|
19
|
+
}
|