|
| 1 | +/** |
| 2 | + * @prettier |
| 3 | + * ZKsync-specific types and interfaces |
| 4 | + */ |
| 5 | + |
| 6 | +/** |
| 7 | + * Paymaster parameters for ZKsync transactions (Account Abstraction feature) |
| 8 | + * Note: Only needed if supporting AA wallets. Standard multisig transactions don't require this. |
| 9 | + */ |
| 10 | +export interface PaymasterParams { |
| 11 | + /** Address of the paymaster contract */ |
| 12 | + paymaster: string; |
| 13 | + /** Encoded input data for the paymaster */ |
| 14 | + paymasterInput: string; |
| 15 | +} |
| 16 | + |
| 17 | +/** |
| 18 | + * ZKsync-specific fee structure |
| 19 | + */ |
| 20 | +export interface ZKsyncFee { |
| 21 | + /** Gas limit for the transaction */ |
| 22 | + gasLimit: string; |
| 23 | + /** Maximum gas per pubdata byte limit (ZKsync-specific) */ |
| 24 | + gasPerPubdataByteLimit?: string; |
| 25 | + /** Max fee per gas (EIP-1559) */ |
| 26 | + maxFeePerGas: string; |
| 27 | + /** Max priority fee per gas (EIP-1559) */ |
| 28 | + maxPriorityFeePerGas: string; |
| 29 | + /** Gas price for L1 (legacy, if applicable) */ |
| 30 | + gasPrice?: string; |
| 31 | +} |
| 32 | + |
| 33 | +/** |
| 34 | + * Fee estimation response from zks_estimateFee |
| 35 | + */ |
| 36 | +export interface ZKsyncFeeEstimate { |
| 37 | + /** Gas limit */ |
| 38 | + gas_limit: string; |
| 39 | + /** Gas per pubdata byte limit */ |
| 40 | + gas_per_pubdata_limit: string; |
| 41 | + /** Max fee per gas */ |
| 42 | + max_fee_per_gas: string; |
| 43 | + /** Max priority fee per gas */ |
| 44 | + max_priority_fee_per_gas: string; |
| 45 | +} |
| 46 | + |
| 47 | +/** |
| 48 | + * Bridge contract addresses |
| 49 | + */ |
| 50 | +export interface BridgeAddresses { |
| 51 | + /** L1 shared bridge proxy address */ |
| 52 | + l1SharedDefaultBridge?: string; |
| 53 | + /** L2 shared bridge proxy address */ |
| 54 | + l2SharedDefaultBridge?: string; |
| 55 | + /** L1 ERC20 default bridge proxy */ |
| 56 | + l1Erc20DefaultBridge?: string; |
| 57 | + /** L2 ERC20 default bridge */ |
| 58 | + l2Erc20DefaultBridge?: string; |
| 59 | + /** L1 WETH bridge proxy */ |
| 60 | + l1WethBridge?: string; |
| 61 | + /** L2 WETH bridge */ |
| 62 | + l2WethBridge?: string; |
| 63 | +} |
| 64 | + |
| 65 | +/** |
| 66 | + * Priority operation parameters for L1->L2 transactions |
| 67 | + */ |
| 68 | +export interface PriorityOpParams { |
| 69 | + /** L2 contract address to call */ |
| 70 | + contractAddressL2: string; |
| 71 | + /** L2 gas limit */ |
| 72 | + l2GasLimit: string; |
| 73 | + /** L2 value to transfer */ |
| 74 | + l2Value?: string; |
| 75 | + /** Calldata for the L2 contract */ |
| 76 | + calldata?: string; |
| 77 | + /** Factory dependencies (contract bytecode for deployment) */ |
| 78 | + factoryDeps?: string[]; |
| 79 | + /** Refund recipient on L2 */ |
| 80 | + refundRecipient?: string; |
| 81 | +} |
| 82 | + |
| 83 | +/** |
| 84 | + * Withdrawal parameters for L2->L1 transactions |
| 85 | + */ |
| 86 | +export interface WithdrawalParams { |
| 87 | + /** Token address on L2 (use ETH_ADDRESS for native ETH) */ |
| 88 | + token: string; |
| 89 | + /** Amount to withdraw */ |
| 90 | + amount: string; |
| 91 | + /** Recipient address on L1 */ |
| 92 | + to?: string; |
| 93 | + /** Bridge address to use (optional, uses default if not specified) */ |
| 94 | + bridgeAddress?: string; |
| 95 | +} |
| 96 | + |
| 97 | +/** |
| 98 | + * ZKsync transaction data extending standard Ethereum transaction |
| 99 | + */ |
| 100 | +export interface ZKsyncTxData { |
| 101 | + /** Transaction type (113 for EIP-712) */ |
| 102 | + txType?: number; |
| 103 | + /** Sender address */ |
| 104 | + from?: string; |
| 105 | + /** Recipient address */ |
| 106 | + to?: string; |
| 107 | + /** Gas limit */ |
| 108 | + gasLimit: string; |
| 109 | + /** Gas per pubdata byte limit */ |
| 110 | + gasPerPubdataByteLimit?: string; |
| 111 | + /** Max fee per gas */ |
| 112 | + maxFeePerGas?: string; |
| 113 | + /** Max priority fee per gas */ |
| 114 | + maxPriorityFeePerGas?: string; |
| 115 | + /** Paymaster parameters (optional, only for AA wallets) */ |
| 116 | + paymaster?: string; |
| 117 | + /** Paymaster input (optional, only for AA wallets) */ |
| 118 | + paymasterInput?: string; |
| 119 | + /** Factory dependencies for contract deployment (optional) */ |
| 120 | + factoryDeps?: string[]; |
| 121 | + /** Transaction data/calldata */ |
| 122 | + data?: string; |
| 123 | + /** Value to transfer */ |
| 124 | + value?: string; |
| 125 | + /** Nonce */ |
| 126 | + nonce?: number; |
| 127 | + /** Chain ID */ |
| 128 | + chainId?: string; |
| 129 | + /** Custom signature (for EIP-712) */ |
| 130 | + customSignature?: string; |
| 131 | +} |
| 132 | + |
| 133 | +/** |
| 134 | + * System contract addresses on ZKsync |
| 135 | + */ |
| 136 | +export const ZKSYNC_SYSTEM_CONTRACTS = { |
| 137 | + /** Bootloader address */ |
| 138 | + BOOTLOADER: '0x0000000000000000000000000000000000008001', |
| 139 | + /** Account code storage */ |
| 140 | + ACCOUNT_CODE_STORAGE: '0x0000000000000000000000000000000000008002', |
| 141 | + /** Nonce holder */ |
| 142 | + NONCE_HOLDER: '0x0000000000000000000000000000000000008003', |
| 143 | + /** Known codes storage */ |
| 144 | + KNOWN_CODES_STORAGE: '0x0000000000000000000000000000000000008004', |
| 145 | + /** Immutable simulator */ |
| 146 | + IMMUTABLE_SIMULATOR: '0x0000000000000000000000000000000000008005', |
| 147 | + /** Contract deployer */ |
| 148 | + CONTRACT_DEPLOYER: '0x0000000000000000000000000000000000008006', |
| 149 | + /** Force deploy upgrader */ |
| 150 | + FORCE_DEPLOYER: '0x0000000000000000000000000000000000008007', |
| 151 | + /** L1 messenger */ |
| 152 | + L1_MESSENGER: '0x0000000000000000000000000000000000008008', |
| 153 | + /** Message transmitter */ |
| 154 | + MSG_VALUE_SYSTEM_CONTRACT: '0x0000000000000000000000000000000000008009', |
| 155 | + /** ETH token (L2 base token) */ |
| 156 | + ETH_TOKEN: '0x000000000000000000000000000000000000800a', |
| 157 | + /** System context */ |
| 158 | + SYSTEM_CONTEXT: '0x000000000000000000000000000000000000800b', |
| 159 | + /** Bootloader utilities */ |
| 160 | + BOOTLOADER_UTILITIES: '0x000000000000000000000000000000000000800c', |
| 161 | + /** Event writer */ |
| 162 | + EVENT_WRITER: '0x000000000000000000000000000000000000800d', |
| 163 | + /** Compressor */ |
| 164 | + COMPRESSOR: '0x000000000000000000000000000000000000800e', |
| 165 | + /** Complex upgrader */ |
| 166 | + COMPLEX_UPGRADER: '0x000000000000000000000000000000000000800f', |
| 167 | + /** Keccak256 */ |
| 168 | + KECCAK256: '0x0000000000000000000000000000000000008010', |
| 169 | + /** Code Oracle */ |
| 170 | + CODE_ORACLE: '0x0000000000000000000000000000000000008011', |
| 171 | + /** P256 verify */ |
| 172 | + P256_VERIFY: '0x0000000000000000000000000000000000008012', |
| 173 | +} as const; |
| 174 | + |
| 175 | +/** |
| 176 | + * Default gas per pubdata byte limit |
| 177 | + */ |
| 178 | +export const DEFAULT_GAS_PER_PUBDATA_LIMIT = '50000'; |
| 179 | + |
| 180 | +/** |
| 181 | + * ETH address constant for native ETH operations |
| 182 | + */ |
| 183 | +export const ETH_ADDRESS = '0x0000000000000000000000000000000000000000'; |
| 184 | + |
| 185 | +/** |
| 186 | + * EIP-712 transaction type |
| 187 | + */ |
| 188 | +export const EIP_712_TX_TYPE = 0x71; |
0 commit comments