viem 2.22.6 → 2.22.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/_cjs/chains/definitions/citreaTestnet.js +23 -0
- package/_cjs/chains/definitions/citreaTestnet.js.map +1 -0
- package/_cjs/chains/index.js +11 -9
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/utils/typedData.js +2 -1
- package/_cjs/utils/typedData.js.map +1 -1
- package/_cjs/zksync/actions/requestExecute.js +112 -0
- package/_cjs/zksync/actions/requestExecute.js.map +1 -0
- package/_cjs/zksync/constants/abis.js +3039 -1
- package/_cjs/zksync/constants/abis.js.map +1 -1
- package/_cjs/zksync/constants/number.js +2 -1
- package/_cjs/zksync/constants/number.js.map +1 -1
- package/_cjs/zksync/decorators/walletL1.js +10 -0
- package/_cjs/zksync/decorators/walletL1.js.map +1 -0
- package/_cjs/zksync/errors/bridge.js +24 -0
- package/_cjs/zksync/errors/bridge.js.map +1 -0
- package/_cjs/zksync/index.js +8 -1
- package/_cjs/zksync/index.js.map +1 -1
- package/_cjs/zksync/utils/bridge/getL2HashFromPriorityOp.js +28 -0
- package/_cjs/zksync/utils/bridge/getL2HashFromPriorityOp.js.map +1 -0
- package/_esm/actions/public/getContractEvents.js +1 -1
- package/_esm/chains/definitions/citreaTestnet.js +20 -0
- package/_esm/chains/definitions/citreaTestnet.js.map +1 -0
- package/_esm/chains/index.js +3 -1
- package/_esm/chains/index.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/utils/typedData.js +2 -1
- package/_esm/utils/typedData.js.map +1 -1
- package/_esm/zksync/actions/requestExecute.js +167 -0
- package/_esm/zksync/actions/requestExecute.js.map +1 -0
- package/_esm/zksync/constants/abis.js +3038 -0
- package/_esm/zksync/constants/abis.js.map +1 -1
- package/_esm/zksync/constants/number.js +1 -0
- package/_esm/zksync/constants/number.js.map +1 -1
- package/_esm/zksync/decorators/walletL1.js +7 -0
- package/_esm/zksync/decorators/walletL1.js.map +1 -0
- package/_esm/zksync/errors/bridge.js +19 -0
- package/_esm/zksync/errors/bridge.js.map +1 -0
- package/_esm/zksync/index.js +3 -0
- package/_esm/zksync/index.js.map +1 -1
- package/_esm/zksync/utils/bridge/getL2HashFromPriorityOp.js +53 -0
- package/_esm/zksync/utils/bridge/getL2HashFromPriorityOp.js.map +1 -0
- package/_types/actions/public/getContractEvents.d.ts +1 -1
- package/_types/chains/definitions/citreaTestnet.d.ts +38 -0
- package/_types/chains/definitions/citreaTestnet.d.ts.map +1 -0
- package/_types/chains/index.d.ts +3 -1
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/utils/typedData.d.ts.map +1 -1
- package/_types/zksync/actions/requestExecute.d.ts +95 -0
- package/_types/zksync/actions/requestExecute.d.ts.map +1 -0
- package/_types/zksync/constants/abis.d.ts +2356 -0
- package/_types/zksync/constants/abis.d.ts.map +1 -1
- package/_types/zksync/constants/number.d.ts +1 -0
- package/_types/zksync/constants/number.d.ts.map +1 -1
- package/_types/zksync/decorators/walletL1.d.ts +41 -0
- package/_types/zksync/decorators/walletL1.d.ts.map +1 -0
- package/_types/zksync/errors/bridge.d.ts +14 -0
- package/_types/zksync/errors/bridge.d.ts.map +1 -0
- package/_types/zksync/index.d.ts +3 -0
- package/_types/zksync/index.d.ts.map +1 -1
- package/_types/zksync/utils/bridge/getL2HashFromPriorityOp.d.ts +34 -0
- package/_types/zksync/utils/bridge/getL2HashFromPriorityOp.d.ts.map +1 -0
- package/actions/public/getContractEvents.ts +1 -1
- package/chains/definitions/citreaTestnet.ts +20 -0
- package/chains/index.ts +3 -1
- package/errors/version.ts +1 -1
- package/package.json +1 -1
- package/utils/typedData.ts +2 -1
- package/zksync/actions/requestExecute.ts +282 -0
- package/zksync/constants/abis.ts +3040 -0
- package/zksync/constants/number.ts +1 -0
- package/zksync/decorators/walletL1.ts +71 -0
- package/zksync/errors/bridge.ts +29 -0
- package/zksync/index.ts +15 -0
- package/zksync/utils/bridge/getL2HashFromPriorityOp.ts +63 -0
@@ -0,0 +1,71 @@
|
|
1
|
+
import type { Client } from '../../clients/createClient.js'
|
2
|
+
import type { Transport } from '../../clients/transports/createTransport.js'
|
3
|
+
import type { Account } from '../../types/account.js'
|
4
|
+
import type { Chain } from '../../types/chain.js'
|
5
|
+
import {
|
6
|
+
type RequestExecuteParameters,
|
7
|
+
type RequestExecuteReturnType,
|
8
|
+
requestExecute,
|
9
|
+
} from '../actions/requestExecute.js'
|
10
|
+
import type { ChainEIP712 } from '../types/chain.js'
|
11
|
+
|
12
|
+
export type WalletActionsL1<
|
13
|
+
chain extends Chain | undefined = Chain | undefined,
|
14
|
+
account extends Account | undefined = Account | undefined,
|
15
|
+
> = {
|
16
|
+
/**
|
17
|
+
* Requests execution of a L2 transaction from L1.
|
18
|
+
*
|
19
|
+
* @param parameters - {@link RequestExecuteParameters}
|
20
|
+
* @returns hash - The [Transaction](https://viem.sh/docs/glossary/terms#transaction) hash. {@link RequestExecuteReturnType}
|
21
|
+
*
|
22
|
+
* @example
|
23
|
+
* import { createPublicClient, createWalletClient, http } from 'viem'
|
24
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
25
|
+
* import { zksync, mainnet } from 'viem/chains'
|
26
|
+
* import { walletActionsL1, publicActionsL2 } from 'viem/zksync'
|
27
|
+
*
|
28
|
+
* const walletClient = createWalletClient({
|
29
|
+
* chain: mainnet,
|
30
|
+
* transport: http(),
|
31
|
+
* account: privateKeyToAccount('0x…'),
|
32
|
+
* }).extend(walletActionsL1())
|
33
|
+
*
|
34
|
+
* const clientL2 = createPublicClient({
|
35
|
+
* chain: zksync,
|
36
|
+
* transport: http(),
|
37
|
+
* }).extend(publicActionsL2())
|
38
|
+
*
|
39
|
+
* const hash = await walletClient.requestExecute({
|
40
|
+
* client: clientL2,
|
41
|
+
* contractAddress: '0x43020e6e11cef7dce8e37baa09d9a996ac722057'
|
42
|
+
* calldata: '0x',
|
43
|
+
* l2Value: 1_000_000_000_000_000_000n,
|
44
|
+
* })
|
45
|
+
*/
|
46
|
+
requestExecute: <
|
47
|
+
chainOverride extends Chain | undefined = undefined,
|
48
|
+
chainL2 extends ChainEIP712 | undefined = ChainEIP712 | undefined,
|
49
|
+
accountL2 extends Account | undefined = Account | undefined,
|
50
|
+
>(
|
51
|
+
parameters: RequestExecuteParameters<
|
52
|
+
chain,
|
53
|
+
account,
|
54
|
+
chainOverride,
|
55
|
+
chainL2,
|
56
|
+
accountL2
|
57
|
+
>,
|
58
|
+
) => Promise<RequestExecuteReturnType>
|
59
|
+
}
|
60
|
+
|
61
|
+
export function walletActionsL1() {
|
62
|
+
return <
|
63
|
+
transport extends Transport,
|
64
|
+
chain extends Chain | undefined = Chain | undefined,
|
65
|
+
account extends Account | undefined = Account | undefined,
|
66
|
+
>(
|
67
|
+
client: Client<transport, chain, account>,
|
68
|
+
): WalletActionsL1<chain, account> => ({
|
69
|
+
requestExecute: (args) => requestExecute(client, args),
|
70
|
+
})
|
71
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { BaseError } from '../../errors/base.js'
|
2
|
+
|
3
|
+
export type BaseFeeHigherThanValueErrorType = BaseFeeHigherThanValueError & {
|
4
|
+
name: 'BaseFeeHigherThanValueError'
|
5
|
+
}
|
6
|
+
export class BaseFeeHigherThanValueError extends BaseError {
|
7
|
+
constructor(baseCost: bigint, value: bigint) {
|
8
|
+
super(
|
9
|
+
[
|
10
|
+
'The base cost of performing the priority operation is higher than the provided transaction value parameter.',
|
11
|
+
'',
|
12
|
+
`Base cost: ${baseCost}.`,
|
13
|
+
`Provided value: ${value}.`,
|
14
|
+
].join('\n'),
|
15
|
+
{ name: 'BaseFeeHigherThanValueError' },
|
16
|
+
)
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
export type TxHashNotFoundInLogsErrorType = BaseFeeHigherThanValueError & {
|
21
|
+
name: 'TxHashNotFoundInLogsError'
|
22
|
+
}
|
23
|
+
export class TxHashNotFoundInLogsError extends BaseError {
|
24
|
+
constructor() {
|
25
|
+
super('The transaction hash not found in event logs.', {
|
26
|
+
name: 'TxHashNotFoundInLogsError',
|
27
|
+
})
|
28
|
+
}
|
29
|
+
}
|
package/zksync/index.ts
CHANGED
@@ -95,6 +95,12 @@ export {
|
|
95
95
|
type GetTransactionDetailsReturnType,
|
96
96
|
getTransactionDetails,
|
97
97
|
} from './actions/getTransactionDetails.js'
|
98
|
+
export {
|
99
|
+
type RequestExecuteErrorType,
|
100
|
+
type RequestExecuteReturnType,
|
101
|
+
type RequestExecuteParameters,
|
102
|
+
requestExecute,
|
103
|
+
} from './actions/requestExecute.js'
|
98
104
|
export {
|
99
105
|
type SendTransactionErrorType,
|
100
106
|
type SendTransactionParameters,
|
@@ -165,6 +171,11 @@ export {
|
|
165
171
|
type PublicActionsL2,
|
166
172
|
} from './decorators/publicL2.js'
|
167
173
|
|
174
|
+
export {
|
175
|
+
walletActionsL1,
|
176
|
+
type WalletActionsL1,
|
177
|
+
} from './decorators/walletL1.js'
|
178
|
+
|
168
179
|
export { serializeTransaction } from './serializers.js'
|
169
180
|
|
170
181
|
export type { ZksyncSmartAccount } from './types/account.js'
|
@@ -284,6 +295,10 @@ export type {
|
|
284
295
|
ZksyncTransactionDetails,
|
285
296
|
} from './types/transaction.js'
|
286
297
|
|
298
|
+
export {
|
299
|
+
type GetL2HashFromPriorityOpErrorType,
|
300
|
+
getL2HashFromPriorityOp,
|
301
|
+
} from './utils/bridge/getL2HashFromPriorityOp.js'
|
287
302
|
export {
|
288
303
|
type GetApprovalBasedPaymasterInputParameters,
|
289
304
|
type GetApprovalBasedPaymasterInputReturnType,
|
@@ -0,0 +1,63 @@
|
|
1
|
+
import type { Address } from 'abitype'
|
2
|
+
import type { Hash } from '../../../types/misc.js'
|
3
|
+
import type { TransactionReceipt } from '../../../types/transaction.js'
|
4
|
+
import { decodeEventLog, isAddressEqual } from '../../../utils/index.js'
|
5
|
+
import { zksyncAbi } from '../../constants/abis.js'
|
6
|
+
import {
|
7
|
+
TxHashNotFoundInLogsError,
|
8
|
+
type TxHashNotFoundInLogsErrorType,
|
9
|
+
} from '../../errors/bridge.js'
|
10
|
+
|
11
|
+
export type GetL2HashFromPriorityOpErrorType = TxHashNotFoundInLogsErrorType
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Returns the hash of the L2 priority operation from a given L1 transaction receipt.
|
15
|
+
*
|
16
|
+
* @param receipt - The L1 transaction receipt.
|
17
|
+
* @param zksync - The address of the ZKsync Era main contract.
|
18
|
+
* @returns hash - The hash of the L2 priority operation.
|
19
|
+
*
|
20
|
+
* @example
|
21
|
+
* import { createPublicClient, http } from 'viem'
|
22
|
+
* import { zksync, mainnet } from 'viem/chains'
|
23
|
+
* import { publicActionsL2, getL2HashFromPriorityOp } from 'viem/zksync'
|
24
|
+
*
|
25
|
+
* const client = createPublicClient({
|
26
|
+
* chain: mainnet,
|
27
|
+
* transport: http(),
|
28
|
+
* })
|
29
|
+
*
|
30
|
+
* const zksyncClient = const client = createPublicClient({
|
31
|
+
* chain: zksync,
|
32
|
+
* transport: http(),
|
33
|
+
* })
|
34
|
+
*
|
35
|
+
* const receipt = await client.waitForTransactionReceipt({hash: '0x...'})
|
36
|
+
* const l2Hash = getL2HashFromPriorityOp(
|
37
|
+
* receipt,
|
38
|
+
* await zksyncClient.getMainContractAddress()
|
39
|
+
* )
|
40
|
+
*/
|
41
|
+
export function getL2HashFromPriorityOp(
|
42
|
+
receipt: TransactionReceipt,
|
43
|
+
zksync: Address,
|
44
|
+
): Address {
|
45
|
+
let hash: Hash | null = null
|
46
|
+
for (const log of receipt.logs) {
|
47
|
+
if (!isAddressEqual(log.address, zksync)) continue
|
48
|
+
try {
|
49
|
+
const priorityQueueLog = decodeEventLog({
|
50
|
+
abi: zksyncAbi,
|
51
|
+
data: log.data,
|
52
|
+
topics: log.topics,
|
53
|
+
})
|
54
|
+
if (priorityQueueLog && (priorityQueueLog.args as any).txHash !== null)
|
55
|
+
hash = (priorityQueueLog.args as any).txHash
|
56
|
+
} catch (_e) {}
|
57
|
+
}
|
58
|
+
|
59
|
+
if (!hash) {
|
60
|
+
throw new TxHashNotFoundInLogsError()
|
61
|
+
}
|
62
|
+
return hash
|
63
|
+
}
|