viem 2.22.8 → 2.22.10
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 +24 -0
- package/README.md +0 -12
- package/_cjs/account-abstraction/accounts/createWebAuthnCredential.js +11 -3
- package/_cjs/account-abstraction/accounts/createWebAuthnCredential.js.map +1 -1
- package/_cjs/account-abstraction/accounts/implementations/toCoinbaseSmartAccount.js +2 -2
- package/_cjs/account-abstraction/accounts/implementations/toCoinbaseSmartAccount.js.map +1 -1
- package/_cjs/account-abstraction/accounts/toWebAuthnAccount.js +13 -2
- package/_cjs/account-abstraction/accounts/toWebAuthnAccount.js.map +1 -1
- package/_cjs/chains/definitions/alephZeroTestnet.js +30 -0
- package/_cjs/chains/definitions/alephZeroTestnet.js.map +1 -0
- package/_cjs/chains/definitions/artheraTestnet.js +28 -0
- package/_cjs/chains/definitions/artheraTestnet.js.map +1 -0
- package/_cjs/chains/definitions/goat.js +29 -0
- package/_cjs/chains/definitions/goat.js.map +1 -0
- package/_cjs/chains/definitions/near.js +24 -0
- package/_cjs/chains/definitions/near.js.map +1 -0
- package/_cjs/chains/definitions/nearTestnet.js +24 -0
- package/_cjs/chains/definitions/nearTestnet.js.map +1 -0
- package/_cjs/chains/definitions/soneium.js +55 -0
- package/_cjs/chains/definitions/soneium.js.map +1 -0
- package/_cjs/chains/index.js +23 -10
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/clients/transports/createTransport.js +2 -2
- package/_cjs/clients/transports/createTransport.js.map +1 -1
- package/_cjs/clients/transports/custom.js +2 -1
- package/_cjs/clients/transports/custom.js.map +1 -1
- package/_cjs/clients/transports/http.js +2 -1
- package/_cjs/clients/transports/http.js.map +1 -1
- package/_cjs/clients/transports/ipc.js +2 -1
- package/_cjs/clients/transports/ipc.js.map +1 -1
- package/_cjs/clients/transports/webSocket.js +2 -1
- package/_cjs/clients/transports/webSocket.js.map +1 -1
- package/_cjs/errors/rpc.js +1 -1
- package/_cjs/errors/rpc.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/errors/version.js.map +1 -1
- package/_cjs/op-stack/chains.js +3 -1
- package/_cjs/op-stack/chains.js.map +1 -1
- package/_cjs/utils/buildRequest.js +10 -1
- package/_cjs/utils/buildRequest.js.map +1 -1
- package/_cjs/zksync/actions/withdraw.js +53 -0
- package/_cjs/zksync/actions/withdraw.js.map +1 -0
- package/_cjs/zksync/constants/abis.js +246 -1
- package/_cjs/zksync/constants/abis.js.map +1 -1
- package/_cjs/zksync/constants/address.js.map +1 -1
- package/_cjs/zksync/decorators/walletL2.js +10 -0
- package/_cjs/zksync/decorators/walletL2.js.map +1 -0
- package/_cjs/zksync/index.js +9 -2
- package/_cjs/zksync/index.js.map +1 -1
- package/_esm/account-abstraction/accounts/createWebAuthnCredential.js +11 -2
- package/_esm/account-abstraction/accounts/createWebAuthnCredential.js.map +1 -1
- package/_esm/account-abstraction/accounts/implementations/toCoinbaseSmartAccount.js +2 -2
- package/_esm/account-abstraction/accounts/implementations/toCoinbaseSmartAccount.js.map +1 -1
- package/_esm/account-abstraction/accounts/toWebAuthnAccount.js +13 -2
- package/_esm/account-abstraction/accounts/toWebAuthnAccount.js.map +1 -1
- package/_esm/chains/definitions/alephZeroTestnet.js +27 -0
- package/_esm/chains/definitions/alephZeroTestnet.js.map +1 -0
- package/_esm/chains/definitions/artheraTestnet.js +25 -0
- package/_esm/chains/definitions/artheraTestnet.js.map +1 -0
- package/_esm/chains/definitions/goat.js +26 -0
- package/_esm/chains/definitions/goat.js.map +1 -0
- package/_esm/chains/definitions/near.js +21 -0
- package/_esm/chains/definitions/near.js.map +1 -0
- package/_esm/chains/definitions/nearTestnet.js +21 -0
- package/_esm/chains/definitions/nearTestnet.js.map +1 -0
- package/_esm/chains/definitions/soneium.js +52 -0
- package/_esm/chains/definitions/soneium.js.map +1 -0
- package/_esm/chains/index.js +6 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/clients/transports/createTransport.js +2 -2
- package/_esm/clients/transports/createTransport.js.map +1 -1
- package/_esm/clients/transports/custom.js +2 -1
- package/_esm/clients/transports/custom.js.map +1 -1
- package/_esm/clients/transports/http.js +2 -1
- package/_esm/clients/transports/http.js.map +1 -1
- package/_esm/clients/transports/ipc.js +2 -1
- package/_esm/clients/transports/ipc.js.map +1 -1
- package/_esm/clients/transports/webSocket.js +2 -1
- package/_esm/clients/transports/webSocket.js.map +1 -1
- package/_esm/errors/rpc.js +1 -1
- package/_esm/errors/rpc.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/errors/version.js.map +1 -1
- package/_esm/op-stack/chains.js +1 -0
- package/_esm/op-stack/chains.js.map +1 -1
- package/_esm/utils/buildRequest.js +10 -1
- package/_esm/utils/buildRequest.js.map +1 -1
- package/_esm/zksync/actions/withdraw.js +120 -0
- package/_esm/zksync/actions/withdraw.js.map +1 -0
- package/_esm/zksync/constants/abis.js +245 -0
- package/_esm/zksync/constants/abis.js.map +1 -1
- package/_esm/zksync/constants/address.js +2 -0
- package/_esm/zksync/constants/address.js.map +1 -1
- package/_esm/zksync/decorators/walletL2.js +7 -0
- package/_esm/zksync/decorators/walletL2.js.map +1 -0
- package/_esm/zksync/index.js +3 -0
- package/_esm/zksync/index.js.map +1 -1
- package/_types/account-abstraction/accounts/createWebAuthnCredential.d.ts +10 -1
- package/_types/account-abstraction/accounts/createWebAuthnCredential.d.ts.map +1 -1
- package/_types/account-abstraction/accounts/implementations/toCoinbaseSmartAccount.d.ts +2 -2
- package/_types/account-abstraction/accounts/implementations/toCoinbaseSmartAccount.d.ts.map +1 -1
- package/_types/account-abstraction/accounts/toWebAuthnAccount.d.ts +4 -3
- package/_types/account-abstraction/accounts/toWebAuthnAccount.d.ts.map +1 -1
- package/_types/account-abstraction/accounts/types.d.ts +6 -1
- package/_types/account-abstraction/accounts/types.d.ts.map +1 -1
- package/_types/chains/definitions/alephZeroTestnet.d.ts +35 -0
- package/_types/chains/definitions/alephZeroTestnet.d.ts.map +1 -0
- package/_types/chains/definitions/artheraTestnet.d.ts +34 -0
- package/_types/chains/definitions/artheraTestnet.d.ts.map +1 -0
- package/_types/chains/definitions/goat.d.ts +33 -0
- package/_types/chains/definitions/goat.d.ts.map +1 -0
- package/_types/chains/definitions/near.d.ts +37 -0
- package/_types/chains/definitions/near.d.ts.map +1 -0
- package/_types/chains/definitions/nearTestnet.d.ts +37 -0
- package/_types/chains/definitions/nearTestnet.d.ts.map +1 -0
- package/_types/chains/definitions/soneium.d.ts +306 -0
- package/_types/chains/definitions/soneium.d.ts.map +1 -0
- package/_types/chains/index.d.ts +6 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/clients/transports/createTransport.d.ts +8 -1
- package/_types/clients/transports/createTransport.d.ts.map +1 -1
- package/_types/clients/transports/custom.d.ts +2 -0
- package/_types/clients/transports/custom.d.ts.map +1 -1
- package/_types/clients/transports/http.d.ts +2 -0
- package/_types/clients/transports/http.d.ts.map +1 -1
- package/_types/clients/transports/ipc.d.ts +2 -0
- package/_types/clients/transports/ipc.d.ts.map +1 -1
- package/_types/clients/transports/webSocket.d.ts +2 -0
- package/_types/clients/transports/webSocket.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/errors/version.d.ts.map +1 -1
- package/_types/op-stack/chains.d.ts +1 -0
- package/_types/op-stack/chains.d.ts.map +1 -1
- package/_types/types/eip1193.d.ts +9 -0
- package/_types/types/eip1193.d.ts.map +1 -1
- package/_types/utils/buildRequest.d.ts.map +1 -1
- package/_types/zksync/actions/withdraw.d.ts +94 -0
- package/_types/zksync/actions/withdraw.d.ts.map +1 -0
- package/_types/zksync/constants/abis.d.ts +191 -0
- package/_types/zksync/constants/abis.d.ts.map +1 -1
- package/_types/zksync/constants/address.d.ts +2 -0
- package/_types/zksync/constants/address.d.ts.map +1 -1
- package/_types/zksync/decorators/walletL2.d.ts +75 -0
- package/_types/zksync/decorators/walletL2.d.ts.map +1 -0
- package/_types/zksync/index.d.ts +3 -0
- package/_types/zksync/index.d.ts.map +1 -1
- package/account-abstraction/accounts/createWebAuthnCredential.ts +27 -7
- package/account-abstraction/accounts/implementations/toCoinbaseSmartAccount.ts +4 -6
- package/account-abstraction/accounts/toWebAuthnAccount.ts +16 -4
- package/account-abstraction/accounts/types.ts +8 -1
- package/chains/definitions/alephZeroTestnet.ts +27 -0
- package/chains/definitions/artheraTestnet.ts +25 -0
- package/chains/definitions/goat.ts +26 -0
- package/chains/definitions/near.ts +21 -0
- package/chains/definitions/nearTestnet.ts +21 -0
- package/chains/definitions/soneium.ts +53 -0
- package/chains/index.ts +6 -0
- package/clients/transports/createTransport.ts +14 -1
- package/clients/transports/custom.ts +9 -1
- package/clients/transports/http.ts +4 -0
- package/clients/transports/ipc.ts +10 -1
- package/clients/transports/webSocket.ts +4 -0
- package/errors/rpc.ts +1 -1
- package/errors/version.ts +1 -1
- package/op-stack/chains.ts +1 -0
- package/package.json +2 -3
- package/types/eip1193.ts +14 -3
- package/utils/buildRequest.ts +12 -0
- package/zksync/actions/withdraw.ts +185 -0
- package/zksync/constants/abis.ts +246 -0
- package/zksync/constants/address.ts +2 -0
- package/zksync/decorators/walletL2.ts +95 -0
- package/zksync/index.ts +16 -0
@@ -0,0 +1,185 @@
|
|
1
|
+
import type { Address } from 'abitype'
|
2
|
+
import type { Account } from '../../accounts/types.js'
|
3
|
+
import type { Client } from '../../clients/createClient.js'
|
4
|
+
import type { Transport } from '../../clients/transports/createTransport.js'
|
5
|
+
import { AccountNotFoundError } from '../../errors/account.js'
|
6
|
+
import type { GetAccountParameter } from '../../types/account.js'
|
7
|
+
import type { GetChainParameter } from '../../types/chain.js'
|
8
|
+
import type { UnionOmit } from '../../types/utils.js'
|
9
|
+
import type { EncodeFunctionDataReturnType } from '../../utils/abi/encodeFunctionData.js'
|
10
|
+
import {
|
11
|
+
encodeFunctionData,
|
12
|
+
isAddressEqual,
|
13
|
+
parseAccount,
|
14
|
+
} from '../../utils/index.js'
|
15
|
+
import { ethTokenAbi, l2SharedBridgeAbi } from '../constants/abis.js'
|
16
|
+
import {
|
17
|
+
ethAddressInContracts,
|
18
|
+
l2BaseTokenAddress,
|
19
|
+
legacyEthAddress,
|
20
|
+
} from '../constants/address.js'
|
21
|
+
import type { ChainEIP712 } from '../types/chain.js'
|
22
|
+
import type { ZksyncTransactionRequest } from '../types/transaction.js'
|
23
|
+
import { getDefaultBridgeAddresses } from './getDefaultBridgeAddresses.js'
|
24
|
+
import { getL2TokenAddress } from './getL2TokenAddress.js'
|
25
|
+
import {
|
26
|
+
type SendTransactionErrorType,
|
27
|
+
type SendTransactionParameters,
|
28
|
+
type SendTransactionReturnType,
|
29
|
+
sendTransaction,
|
30
|
+
} from './sendTransaction.js'
|
31
|
+
|
32
|
+
export type WithdrawParameters<
|
33
|
+
chain extends ChainEIP712 | undefined = ChainEIP712 | undefined,
|
34
|
+
account extends Account | undefined = Account | undefined,
|
35
|
+
chainOverride extends ChainEIP712 | undefined = ChainEIP712 | undefined,
|
36
|
+
> = UnionOmit<
|
37
|
+
ZksyncTransactionRequest,
|
38
|
+
'from' | 'type' | 'value' | 'data' | 'to' | 'factoryDeps' | 'maxFeePerBlobGas'
|
39
|
+
> &
|
40
|
+
Partial<GetAccountParameter<account>> &
|
41
|
+
Partial<GetChainParameter<chain, chainOverride>> & {
|
42
|
+
/** The address of the recipient on L1. Defaults to the sender address. */
|
43
|
+
to?: Address
|
44
|
+
/** The address of the token. */
|
45
|
+
token: Address
|
46
|
+
/** The amount of the token to withdraw. */
|
47
|
+
amount: bigint
|
48
|
+
/** The address of the bridge contract to be used. */
|
49
|
+
bridgeAddress?: Address
|
50
|
+
}
|
51
|
+
|
52
|
+
export type WithdrawReturnType = SendTransactionReturnType
|
53
|
+
|
54
|
+
export type WithdrawErrorType = SendTransactionErrorType
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Initiates the withdrawal process which withdraws ETH or any ERC20 token
|
58
|
+
* from the associated account on L2 network to the target account on L1 network.
|
59
|
+
*
|
60
|
+
* @param client - Client to use
|
61
|
+
* @param parameters - {@link WithdrawParameters}
|
62
|
+
* @returns hash - The [Transaction](https://viem.sh/docs/glossary/terms#transaction) hash. {@link WithdrawReturnType}
|
63
|
+
*
|
64
|
+
*
|
65
|
+
* @example
|
66
|
+
* import { createPublicClient, http } from 'viem'
|
67
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
68
|
+
* import { zksync } from 'viem/chains'
|
69
|
+
* import { withdraw, legacyEthAddress } from 'viem/zksync'
|
70
|
+
*
|
71
|
+
* const client = createPublicClient({
|
72
|
+
* chain: zksync,
|
73
|
+
* transport: http(),
|
74
|
+
* })
|
75
|
+
*
|
76
|
+
* const hash = await withdraw(client, {
|
77
|
+
* account: privateKeyToAccount('0x…'),
|
78
|
+
* amount: 1_000_000_000_000_000_000n,
|
79
|
+
* token: legacyEthAddress,
|
80
|
+
* })
|
81
|
+
*
|
82
|
+
* @example Account Hoisting
|
83
|
+
* import { createPublicClient, createWalletClient, http } from 'viem'
|
84
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
85
|
+
* import { zksync } from 'viem/chains'
|
86
|
+
* import { withdraw, legacyEthAddress } from 'viem/zksync'
|
87
|
+
*
|
88
|
+
* const client = createWalletClient({
|
89
|
+
* account: privateKeyToAccount('0x…'),
|
90
|
+
* chain: zksync,
|
91
|
+
* transport: http(),
|
92
|
+
* })
|
93
|
+
*
|
94
|
+
* const hash = await withdraw(client, {
|
95
|
+
* amount: 1_000_000_000_000_000_000n,
|
96
|
+
* token: legacyEthAddress,
|
97
|
+
* })
|
98
|
+
*
|
99
|
+
* @example Paymaster
|
100
|
+
* import { createPublicClient, http } from 'viem'
|
101
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
102
|
+
* import { zksync } from 'viem/chains'
|
103
|
+
* import {
|
104
|
+
* withdraw,
|
105
|
+
* legacyEthAddress,
|
106
|
+
* getApprovalBasedPaymasterInput
|
107
|
+
* } from 'viem/zksync'
|
108
|
+
*
|
109
|
+
* const client = createPublicClient({
|
110
|
+
* chain: zksync,
|
111
|
+
* transport: http(),
|
112
|
+
* })
|
113
|
+
*
|
114
|
+
* const hash = await withdraw(client, {
|
115
|
+
* account: privateKeyToAccount('0x…'),
|
116
|
+
* amount: 1_000_000_000_000_000_000n,
|
117
|
+
* token: legacyEthAddress,
|
118
|
+
* paymaster: '0x0EEc6f45108B4b806e27B81d9002e162BD910670',
|
119
|
+
* paymasterInput: getApprovalBasedPaymasterInput({
|
120
|
+
* minAllowance: 1n,
|
121
|
+
* token: '0x2dc3685cA34163952CF4A5395b0039c00DFa851D',
|
122
|
+
* innerInput: new Uint8Array(),
|
123
|
+
* }),
|
124
|
+
* })
|
125
|
+
*/
|
126
|
+
export async function withdraw<
|
127
|
+
chain extends ChainEIP712 | undefined,
|
128
|
+
account extends Account | undefined,
|
129
|
+
chainOverride extends ChainEIP712 | undefined = undefined,
|
130
|
+
>(
|
131
|
+
client: Client<Transport, chain, account>,
|
132
|
+
parameters: WithdrawParameters<chain, account, chainOverride>,
|
133
|
+
): Promise<WithdrawReturnType> {
|
134
|
+
let {
|
135
|
+
account: account_ = client.account,
|
136
|
+
token = l2BaseTokenAddress,
|
137
|
+
to,
|
138
|
+
amount,
|
139
|
+
bridgeAddress,
|
140
|
+
...rest
|
141
|
+
} = parameters
|
142
|
+
const account = account_ ? parseAccount(account_) : client.account
|
143
|
+
if (!account)
|
144
|
+
throw new AccountNotFoundError({
|
145
|
+
docsPath: '/docs/actions/wallet/sendTransaction',
|
146
|
+
})
|
147
|
+
|
148
|
+
if (!to) to = account.address
|
149
|
+
let data: EncodeFunctionDataReturnType
|
150
|
+
let contract: Address
|
151
|
+
let value = 0n
|
152
|
+
|
153
|
+
if (
|
154
|
+
isAddressEqual(token, legacyEthAddress) ||
|
155
|
+
isAddressEqual(token, ethAddressInContracts)
|
156
|
+
)
|
157
|
+
token = await getL2TokenAddress(client, { token: ethAddressInContracts })
|
158
|
+
|
159
|
+
if (isAddressEqual(token, l2BaseTokenAddress)) {
|
160
|
+
data = encodeFunctionData({
|
161
|
+
abi: ethTokenAbi,
|
162
|
+
functionName: 'withdraw',
|
163
|
+
args: [to],
|
164
|
+
})
|
165
|
+
value = amount
|
166
|
+
contract = l2BaseTokenAddress
|
167
|
+
} else {
|
168
|
+
data = encodeFunctionData({
|
169
|
+
abi: l2SharedBridgeAbi,
|
170
|
+
functionName: 'withdraw',
|
171
|
+
args: [to, token, amount],
|
172
|
+
})
|
173
|
+
contract = bridgeAddress
|
174
|
+
? bridgeAddress
|
175
|
+
: (await getDefaultBridgeAddresses(client)).sharedL2
|
176
|
+
}
|
177
|
+
|
178
|
+
return await sendTransaction(client, {
|
179
|
+
account,
|
180
|
+
to: contract,
|
181
|
+
data,
|
182
|
+
value,
|
183
|
+
...rest,
|
184
|
+
} as SendTransactionParameters)
|
185
|
+
}
|
package/zksync/constants/abis.ts
CHANGED
@@ -647,6 +647,252 @@ export const l2SharedBridgeAbi = [
|
|
647
647
|
},
|
648
648
|
] as const
|
649
649
|
|
650
|
+
export const ethTokenAbi = [
|
651
|
+
{
|
652
|
+
anonymous: false,
|
653
|
+
inputs: [
|
654
|
+
{
|
655
|
+
indexed: true,
|
656
|
+
internalType: 'address',
|
657
|
+
name: 'account',
|
658
|
+
type: 'address',
|
659
|
+
},
|
660
|
+
{
|
661
|
+
indexed: false,
|
662
|
+
internalType: 'uint256',
|
663
|
+
name: 'amount',
|
664
|
+
type: 'uint256',
|
665
|
+
},
|
666
|
+
],
|
667
|
+
name: 'Mint',
|
668
|
+
type: 'event',
|
669
|
+
},
|
670
|
+
{
|
671
|
+
anonymous: false,
|
672
|
+
inputs: [
|
673
|
+
{
|
674
|
+
indexed: true,
|
675
|
+
internalType: 'address',
|
676
|
+
name: 'from',
|
677
|
+
type: 'address',
|
678
|
+
},
|
679
|
+
{
|
680
|
+
indexed: true,
|
681
|
+
internalType: 'address',
|
682
|
+
name: 'to',
|
683
|
+
type: 'address',
|
684
|
+
},
|
685
|
+
{
|
686
|
+
indexed: false,
|
687
|
+
internalType: 'uint256',
|
688
|
+
name: 'value',
|
689
|
+
type: 'uint256',
|
690
|
+
},
|
691
|
+
],
|
692
|
+
name: 'Transfer',
|
693
|
+
type: 'event',
|
694
|
+
},
|
695
|
+
{
|
696
|
+
anonymous: false,
|
697
|
+
inputs: [
|
698
|
+
{
|
699
|
+
indexed: true,
|
700
|
+
internalType: 'address',
|
701
|
+
name: '_l2Sender',
|
702
|
+
type: 'address',
|
703
|
+
},
|
704
|
+
{
|
705
|
+
indexed: true,
|
706
|
+
internalType: 'address',
|
707
|
+
name: '_l1Receiver',
|
708
|
+
type: 'address',
|
709
|
+
},
|
710
|
+
{
|
711
|
+
indexed: false,
|
712
|
+
internalType: 'uint256',
|
713
|
+
name: '_amount',
|
714
|
+
type: 'uint256',
|
715
|
+
},
|
716
|
+
],
|
717
|
+
name: 'Withdrawal',
|
718
|
+
type: 'event',
|
719
|
+
},
|
720
|
+
{
|
721
|
+
anonymous: false,
|
722
|
+
inputs: [
|
723
|
+
{
|
724
|
+
indexed: true,
|
725
|
+
internalType: 'address',
|
726
|
+
name: '_l2Sender',
|
727
|
+
type: 'address',
|
728
|
+
},
|
729
|
+
{
|
730
|
+
indexed: true,
|
731
|
+
internalType: 'address',
|
732
|
+
name: '_l1Receiver',
|
733
|
+
type: 'address',
|
734
|
+
},
|
735
|
+
{
|
736
|
+
indexed: false,
|
737
|
+
internalType: 'uint256',
|
738
|
+
name: '_amount',
|
739
|
+
type: 'uint256',
|
740
|
+
},
|
741
|
+
{
|
742
|
+
indexed: false,
|
743
|
+
internalType: 'bytes',
|
744
|
+
name: '_additionalData',
|
745
|
+
type: 'bytes',
|
746
|
+
},
|
747
|
+
],
|
748
|
+
name: 'WithdrawalWithMessage',
|
749
|
+
type: 'event',
|
750
|
+
},
|
751
|
+
{
|
752
|
+
inputs: [
|
753
|
+
{
|
754
|
+
internalType: 'uint256',
|
755
|
+
name: '',
|
756
|
+
type: 'uint256',
|
757
|
+
},
|
758
|
+
],
|
759
|
+
name: 'balanceOf',
|
760
|
+
outputs: [
|
761
|
+
{
|
762
|
+
internalType: 'uint256',
|
763
|
+
name: '',
|
764
|
+
type: 'uint256',
|
765
|
+
},
|
766
|
+
],
|
767
|
+
stateMutability: 'view',
|
768
|
+
type: 'function',
|
769
|
+
},
|
770
|
+
{
|
771
|
+
inputs: [],
|
772
|
+
name: 'decimals',
|
773
|
+
outputs: [
|
774
|
+
{
|
775
|
+
internalType: 'uint8',
|
776
|
+
name: '',
|
777
|
+
type: 'uint8',
|
778
|
+
},
|
779
|
+
],
|
780
|
+
stateMutability: 'pure',
|
781
|
+
type: 'function',
|
782
|
+
},
|
783
|
+
{
|
784
|
+
inputs: [
|
785
|
+
{
|
786
|
+
internalType: 'address',
|
787
|
+
name: '_account',
|
788
|
+
type: 'address',
|
789
|
+
},
|
790
|
+
{
|
791
|
+
internalType: 'uint256',
|
792
|
+
name: '_amount',
|
793
|
+
type: 'uint256',
|
794
|
+
},
|
795
|
+
],
|
796
|
+
name: 'mint',
|
797
|
+
outputs: [],
|
798
|
+
stateMutability: 'nonpayable',
|
799
|
+
type: 'function',
|
800
|
+
},
|
801
|
+
{
|
802
|
+
inputs: [],
|
803
|
+
name: 'name',
|
804
|
+
outputs: [
|
805
|
+
{
|
806
|
+
internalType: 'string',
|
807
|
+
name: '',
|
808
|
+
type: 'string',
|
809
|
+
},
|
810
|
+
],
|
811
|
+
stateMutability: 'pure',
|
812
|
+
type: 'function',
|
813
|
+
},
|
814
|
+
{
|
815
|
+
inputs: [],
|
816
|
+
name: 'symbol',
|
817
|
+
outputs: [
|
818
|
+
{
|
819
|
+
internalType: 'string',
|
820
|
+
name: '',
|
821
|
+
type: 'string',
|
822
|
+
},
|
823
|
+
],
|
824
|
+
stateMutability: 'pure',
|
825
|
+
type: 'function',
|
826
|
+
},
|
827
|
+
{
|
828
|
+
inputs: [],
|
829
|
+
name: 'totalSupply',
|
830
|
+
outputs: [
|
831
|
+
{
|
832
|
+
internalType: 'uint256',
|
833
|
+
name: '',
|
834
|
+
type: 'uint256',
|
835
|
+
},
|
836
|
+
],
|
837
|
+
stateMutability: 'view',
|
838
|
+
type: 'function',
|
839
|
+
},
|
840
|
+
{
|
841
|
+
inputs: [
|
842
|
+
{
|
843
|
+
internalType: 'address',
|
844
|
+
name: '_from',
|
845
|
+
type: 'address',
|
846
|
+
},
|
847
|
+
{
|
848
|
+
internalType: 'address',
|
849
|
+
name: '_to',
|
850
|
+
type: 'address',
|
851
|
+
},
|
852
|
+
{
|
853
|
+
internalType: 'uint256',
|
854
|
+
name: '_amount',
|
855
|
+
type: 'uint256',
|
856
|
+
},
|
857
|
+
],
|
858
|
+
name: 'transferFromTo',
|
859
|
+
outputs: [],
|
860
|
+
stateMutability: 'nonpayable',
|
861
|
+
type: 'function',
|
862
|
+
},
|
863
|
+
{
|
864
|
+
inputs: [
|
865
|
+
{
|
866
|
+
internalType: 'address',
|
867
|
+
name: '_l1Receiver',
|
868
|
+
type: 'address',
|
869
|
+
},
|
870
|
+
],
|
871
|
+
name: 'withdraw',
|
872
|
+
outputs: [],
|
873
|
+
stateMutability: 'payable',
|
874
|
+
type: 'function',
|
875
|
+
},
|
876
|
+
{
|
877
|
+
inputs: [
|
878
|
+
{
|
879
|
+
internalType: 'address',
|
880
|
+
name: '_l1Receiver',
|
881
|
+
type: 'address',
|
882
|
+
},
|
883
|
+
{
|
884
|
+
internalType: 'bytes',
|
885
|
+
name: '_additionalData',
|
886
|
+
type: 'bytes',
|
887
|
+
},
|
888
|
+
],
|
889
|
+
name: 'withdrawWithMessage',
|
890
|
+
outputs: [],
|
891
|
+
stateMutability: 'payable',
|
892
|
+
type: 'function',
|
893
|
+
},
|
894
|
+
] as const
|
895
|
+
|
650
896
|
export const bridgehubAbi = [
|
651
897
|
{
|
652
898
|
anonymous: false,
|
@@ -4,11 +4,13 @@ export const contractDeployerAddress =
|
|
4
4
|
export const contract2FactoryAddress =
|
5
5
|
'0x0000000000000000000000000000000000010000' as const
|
6
6
|
|
7
|
+
/** The address of the L1 `ETH` token. */
|
7
8
|
export const legacyEthAddress =
|
8
9
|
'0x0000000000000000000000000000000000000000' as const
|
9
10
|
|
10
11
|
export const ethAddressInContracts =
|
11
12
|
'0x0000000000000000000000000000000000000001' as const
|
12
13
|
|
14
|
+
/** The address of the base token. */
|
13
15
|
export const l2BaseTokenAddress =
|
14
16
|
'0x000000000000000000000000000000000000800a' as const
|
@@ -0,0 +1,95 @@
|
|
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 {
|
5
|
+
type WithdrawParameters,
|
6
|
+
type WithdrawReturnType,
|
7
|
+
withdraw,
|
8
|
+
} from '../actions/withdraw.js'
|
9
|
+
import type { ChainEIP712 } from '../types/chain.js'
|
10
|
+
|
11
|
+
export type WalletActionsL2<
|
12
|
+
chain extends ChainEIP712 | undefined = ChainEIP712 | undefined,
|
13
|
+
account extends Account | undefined = Account | undefined,
|
14
|
+
> = {
|
15
|
+
/**
|
16
|
+
* Initiates the withdrawal process which withdraws ETH or any ERC20 token
|
17
|
+
* from the associated account on L2 network to the target account on L1 network.
|
18
|
+
*
|
19
|
+
* @param args - {@link WithdrawParameters}
|
20
|
+
* @returns hash - The [Transaction](https://viem.sh/docs/glossary/terms#transaction) hash. {@link WithdrawReturnType}
|
21
|
+
*
|
22
|
+
*
|
23
|
+
* @example
|
24
|
+
* import { createPublicClient, http } from 'viem'
|
25
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
26
|
+
* import { zksync } from 'viem/chains'
|
27
|
+
* import { publicActionsL2, legacyEthAddress } from 'viem/zksync'
|
28
|
+
*
|
29
|
+
* const client = createPublicClient({
|
30
|
+
* chain: zksync,
|
31
|
+
* transport: http(),
|
32
|
+
* }).extend(publicActionsL2())
|
33
|
+
*
|
34
|
+
* const hash = await client.withdraw({
|
35
|
+
* account: privateKeyToAccount('0x…'),
|
36
|
+
* amount: 1_000_000_000_000_000_000n,
|
37
|
+
* token: legacyEthAddress,
|
38
|
+
* })
|
39
|
+
*
|
40
|
+
* @example Account Hoisting
|
41
|
+
* import { createWalletClient, http } from 'viem'
|
42
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
43
|
+
* import { zksync } from 'viem/chains'
|
44
|
+
* import { publicActionsL2, legacyEthAddress } from 'viem/zksync'
|
45
|
+
*
|
46
|
+
* const client = createWalletClient({
|
47
|
+
* account: privateKeyToAccount('0x…'),
|
48
|
+
* chain: zksync,
|
49
|
+
* transport: http(),
|
50
|
+
* }).extend(publicActionsL2())
|
51
|
+
*
|
52
|
+
* const hash = await client.withdraw({
|
53
|
+
* amount: 1_000_000_000_000_000_000n,
|
54
|
+
* token: legacyEthAddress,
|
55
|
+
* })
|
56
|
+
*
|
57
|
+
* @example Paymaster
|
58
|
+
* import { createPublicClient, http } from 'viem'
|
59
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
60
|
+
* import { zksync } from 'viem/chains'
|
61
|
+
* import { publicActionsL2, legacyEthAddress } from 'viem/zksync'
|
62
|
+
*
|
63
|
+
* const client = createPublicClient({
|
64
|
+
* chain: zksync,
|
65
|
+
* transport: http(),
|
66
|
+
* }).extend(publicActionsL2())
|
67
|
+
*
|
68
|
+
* const hash = await client.withdraw({
|
69
|
+
* account: privateKeyToAccount('0x…'),
|
70
|
+
* amount: 1_000_000_000_000_000_000n,
|
71
|
+
* token: legacyEthAddress,
|
72
|
+
* paymaster: '0x0EEc6f45108B4b806e27B81d9002e162BD910670',
|
73
|
+
* paymasterInput: getApprovalBasedPaymasterInput({
|
74
|
+
* minAllowance: 1n,
|
75
|
+
* token: '0x2dc3685cA34163952CF4A5395b0039c00DFa851D',
|
76
|
+
* innerInput: new Uint8Array(),
|
77
|
+
* }),
|
78
|
+
* })
|
79
|
+
*/
|
80
|
+
withdraw: <chainOverride extends ChainEIP712 | undefined = undefined>(
|
81
|
+
args: WithdrawParameters<chain, account, chainOverride>,
|
82
|
+
) => Promise<WithdrawReturnType>
|
83
|
+
}
|
84
|
+
|
85
|
+
export function walletActionsL2() {
|
86
|
+
return <
|
87
|
+
transport extends Transport,
|
88
|
+
chain extends ChainEIP712 | undefined = ChainEIP712 | undefined,
|
89
|
+
account extends Account | undefined = Account | undefined,
|
90
|
+
>(
|
91
|
+
client: Client<transport, chain, account>,
|
92
|
+
): WalletActionsL2<chain, account> => ({
|
93
|
+
withdraw: (args) => withdraw(client, args),
|
94
|
+
})
|
95
|
+
}
|
package/zksync/index.ts
CHANGED
@@ -135,6 +135,17 @@ export {
|
|
135
135
|
type GetL1TokenAddressParameters,
|
136
136
|
getL1TokenAddress,
|
137
137
|
} from './actions/getL1TokenAddress.js'
|
138
|
+
export {
|
139
|
+
type WithdrawErrorType,
|
140
|
+
type WithdrawParameters,
|
141
|
+
type WithdrawReturnType,
|
142
|
+
withdraw,
|
143
|
+
} from './actions/withdraw.js'
|
144
|
+
|
145
|
+
export {
|
146
|
+
legacyEthAddress,
|
147
|
+
l2BaseTokenAddress,
|
148
|
+
} from './constants/address.js'
|
138
149
|
|
139
150
|
export {
|
140
151
|
/** @deprecated Use `zksync` instead */
|
@@ -176,6 +187,11 @@ export {
|
|
176
187
|
type WalletActionsL1,
|
177
188
|
} from './decorators/walletL1.js'
|
178
189
|
|
190
|
+
export {
|
191
|
+
walletActionsL2,
|
192
|
+
type WalletActionsL2,
|
193
|
+
} from './decorators/walletL2.js'
|
194
|
+
|
179
195
|
export { serializeTransaction } from './serializers.js'
|
180
196
|
|
181
197
|
export type { ZksyncSmartAccount } from './types/account.js'
|