viem 2.10.9 → 2.11.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.
Files changed (338) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/_cjs/actions/public/call.js +3 -60
  3. package/_cjs/actions/public/call.js.map +1 -1
  4. package/_cjs/actions/public/estimateGas.js +8 -2
  5. package/_cjs/actions/public/estimateGas.js.map +1 -1
  6. package/_cjs/celo/formatters.js +1 -10
  7. package/_cjs/celo/formatters.js.map +1 -1
  8. package/_cjs/celo/serializers.js +0 -25
  9. package/_cjs/celo/serializers.js.map +1 -1
  10. package/_cjs/celo/utils.js +2 -15
  11. package/_cjs/celo/utils.js.map +1 -1
  12. package/_cjs/chains/definitions/bob.js +33 -0
  13. package/_cjs/chains/definitions/bob.js.map +1 -0
  14. package/_cjs/chains/definitions/funkiSepolia.js +34 -0
  15. package/_cjs/chains/definitions/funkiSepolia.js.map +1 -0
  16. package/_cjs/chains/definitions/lisk.js +34 -0
  17. package/_cjs/chains/definitions/lisk.js.map +1 -0
  18. package/_cjs/chains/definitions/metalL2.js +53 -0
  19. package/_cjs/chains/definitions/metalL2.js.map +1 -0
  20. package/_cjs/chains/index.js +14 -6
  21. package/_cjs/chains/index.js.map +1 -1
  22. package/_cjs/errors/version.js +1 -1
  23. package/_cjs/op-stack/chains.js +3 -1
  24. package/_cjs/op-stack/chains.js.map +1 -1
  25. package/_cjs/utils/stateOverride.js +63 -0
  26. package/_cjs/utils/stateOverride.js.map +1 -0
  27. package/_cjs/zksync/actions/estimateFee.js +26 -0
  28. package/_cjs/zksync/actions/estimateFee.js.map +1 -0
  29. package/_cjs/zksync/actions/estimateGasL1ToL2.js +20 -0
  30. package/_cjs/zksync/actions/estimateGasL1ToL2.js.map +1 -0
  31. package/_cjs/zksync/actions/getAllBalances.js +19 -0
  32. package/_cjs/zksync/actions/getAllBalances.js.map +1 -0
  33. package/_cjs/zksync/actions/getBaseTokenL1Address.js +9 -0
  34. package/_cjs/zksync/actions/getBaseTokenL1Address.js.map +1 -0
  35. package/_cjs/zksync/actions/getBlockDetails.js +12 -0
  36. package/_cjs/zksync/actions/getBlockDetails.js.map +1 -0
  37. package/_cjs/zksync/actions/getBridgehubContractAddress.js +9 -0
  38. package/_cjs/zksync/actions/getBridgehubContractAddress.js.map +1 -0
  39. package/_cjs/zksync/actions/getDefaultBridgeAddresses.js +13 -0
  40. package/_cjs/zksync/actions/getDefaultBridgeAddresses.js.map +1 -0
  41. package/_cjs/zksync/actions/getL1Allowance.js +19 -0
  42. package/_cjs/zksync/actions/getL1Allowance.js.map +1 -0
  43. package/_cjs/zksync/actions/getL1Balance.js +23 -0
  44. package/_cjs/zksync/actions/getL1Balance.js.map +1 -0
  45. package/_cjs/zksync/actions/getL1BatchBlockRange.js +13 -0
  46. package/_cjs/zksync/actions/getL1BatchBlockRange.js.map +1 -0
  47. package/_cjs/zksync/actions/getL1BatchDetails.js +12 -0
  48. package/_cjs/zksync/actions/getL1BatchDetails.js.map +1 -0
  49. package/_cjs/zksync/actions/getL1BatchNumber.js +9 -0
  50. package/_cjs/zksync/actions/getL1BatchNumber.js.map +1 -0
  51. package/_cjs/zksync/actions/getL1ChainId.js +9 -0
  52. package/_cjs/zksync/actions/getL1ChainId.js.map +1 -0
  53. package/_cjs/zksync/actions/getL1TokenBalance.js +24 -0
  54. package/_cjs/zksync/actions/getL1TokenBalance.js.map +1 -0
  55. package/_cjs/zksync/actions/getLogProof.js +12 -0
  56. package/_cjs/zksync/actions/getLogProof.js.map +1 -0
  57. package/_cjs/zksync/actions/getMainContractAddress.js +9 -0
  58. package/_cjs/zksync/actions/getMainContractAddress.js.map +1 -0
  59. package/_cjs/zksync/actions/getRawBlockTransactions.js +13 -0
  60. package/_cjs/zksync/actions/getRawBlockTransactions.js.map +1 -0
  61. package/_cjs/zksync/actions/getTestnetPaymasterAddress.js +9 -0
  62. package/_cjs/zksync/actions/getTestnetPaymasterAddress.js.map +1 -0
  63. package/_cjs/zksync/actions/getTransactionDetails.js +12 -0
  64. package/_cjs/zksync/actions/getTransactionDetails.js.map +1 -0
  65. package/_cjs/zksync/constants/address.js +4 -1
  66. package/_cjs/zksync/constants/address.js.map +1 -1
  67. package/_cjs/zksync/decorators/publicL1.js +15 -0
  68. package/_cjs/zksync/decorators/publicL1.js.map +1 -0
  69. package/_cjs/zksync/decorators/publicL2.js +43 -0
  70. package/_cjs/zksync/decorators/publicL2.js.map +1 -0
  71. package/_cjs/zksync/errors/token-is-eth.js +17 -0
  72. package/_cjs/zksync/errors/token-is-eth.js.map +1 -0
  73. package/_cjs/zksync/index.js +41 -3
  74. package/_cjs/zksync/index.js.map +1 -1
  75. package/_cjs/zksync/types/eip1193.js +3 -0
  76. package/_cjs/zksync/types/eip1193.js.map +1 -0
  77. package/_cjs/zksync/types/proof.js +3 -0
  78. package/_cjs/zksync/types/proof.js.map +1 -0
  79. package/_cjs/zksync/utils/camelCaseKeys.js +17 -0
  80. package/_cjs/zksync/utils/camelCaseKeys.js.map +1 -0
  81. package/_cjs/zksync/utils/isEth.js +17 -0
  82. package/_cjs/zksync/utils/isEth.js.map +1 -0
  83. package/_cjs/zksync/utils/paymaster/getApprovalBasedPaymasterInput.js +4 -3
  84. package/_cjs/zksync/utils/paymaster/getApprovalBasedPaymasterInput.js.map +1 -1
  85. package/_cjs/zksync/utils/paymaster/getGeneralPaymasterInput.js +4 -3
  86. package/_cjs/zksync/utils/paymaster/getGeneralPaymasterInput.js.map +1 -1
  87. package/_esm/actions/public/call.js +2 -56
  88. package/_esm/actions/public/call.js.map +1 -1
  89. package/_esm/actions/public/estimateGas.js +8 -2
  90. package/_esm/actions/public/estimateGas.js.map +1 -1
  91. package/_esm/celo/formatters.js +2 -11
  92. package/_esm/celo/formatters.js.map +1 -1
  93. package/_esm/celo/serializers.js +1 -29
  94. package/_esm/celo/serializers.js.map +1 -1
  95. package/_esm/celo/utils.js +1 -15
  96. package/_esm/celo/utils.js.map +1 -1
  97. package/_esm/chains/definitions/bob.js +30 -0
  98. package/_esm/chains/definitions/bob.js.map +1 -0
  99. package/_esm/chains/definitions/funkiSepolia.js +31 -0
  100. package/_esm/chains/definitions/funkiSepolia.js.map +1 -0
  101. package/_esm/chains/definitions/lisk.js +31 -0
  102. package/_esm/chains/definitions/lisk.js.map +1 -0
  103. package/_esm/chains/definitions/metalL2.js +50 -0
  104. package/_esm/chains/definitions/metalL2.js.map +1 -0
  105. package/_esm/chains/index.js +4 -0
  106. package/_esm/chains/index.js.map +1 -1
  107. package/_esm/errors/version.js +1 -1
  108. package/_esm/op-stack/chains.js +1 -0
  109. package/_esm/op-stack/chains.js.map +1 -1
  110. package/_esm/utils/stateOverride.js +57 -0
  111. package/_esm/utils/stateOverride.js.map +1 -0
  112. package/_esm/zksync/actions/estimateFee.js +22 -0
  113. package/_esm/zksync/actions/estimateFee.js.map +1 -0
  114. package/_esm/zksync/actions/estimateGasL1ToL2.js +16 -0
  115. package/_esm/zksync/actions/estimateGasL1ToL2.js.map +1 -0
  116. package/_esm/zksync/actions/getAllBalances.js +15 -0
  117. package/_esm/zksync/actions/getAllBalances.js.map +1 -0
  118. package/_esm/zksync/actions/getBaseTokenL1Address.js +5 -0
  119. package/_esm/zksync/actions/getBaseTokenL1Address.js.map +1 -0
  120. package/_esm/zksync/actions/getBlockDetails.js +8 -0
  121. package/_esm/zksync/actions/getBlockDetails.js.map +1 -0
  122. package/_esm/zksync/actions/getBridgehubContractAddress.js +5 -0
  123. package/_esm/zksync/actions/getBridgehubContractAddress.js.map +1 -0
  124. package/_esm/zksync/actions/getDefaultBridgeAddresses.js +9 -0
  125. package/_esm/zksync/actions/getDefaultBridgeAddresses.js.map +1 -0
  126. package/_esm/zksync/actions/getL1Allowance.js +15 -0
  127. package/_esm/zksync/actions/getL1Allowance.js.map +1 -0
  128. package/_esm/zksync/actions/getL1Balance.js +19 -0
  129. package/_esm/zksync/actions/getL1Balance.js.map +1 -0
  130. package/_esm/zksync/actions/getL1BatchBlockRange.js +9 -0
  131. package/_esm/zksync/actions/getL1BatchBlockRange.js.map +1 -0
  132. package/_esm/zksync/actions/getL1BatchDetails.js +8 -0
  133. package/_esm/zksync/actions/getL1BatchDetails.js.map +1 -0
  134. package/_esm/zksync/actions/getL1BatchNumber.js +5 -0
  135. package/_esm/zksync/actions/getL1BatchNumber.js.map +1 -0
  136. package/_esm/zksync/actions/getL1ChainId.js +5 -0
  137. package/_esm/zksync/actions/getL1ChainId.js.map +1 -0
  138. package/_esm/zksync/actions/getL1TokenBalance.js +20 -0
  139. package/_esm/zksync/actions/getL1TokenBalance.js.map +1 -0
  140. package/_esm/zksync/actions/getLogProof.js +8 -0
  141. package/_esm/zksync/actions/getLogProof.js.map +1 -0
  142. package/_esm/zksync/actions/getMainContractAddress.js +5 -0
  143. package/_esm/zksync/actions/getMainContractAddress.js.map +1 -0
  144. package/_esm/zksync/actions/getRawBlockTransactions.js +9 -0
  145. package/_esm/zksync/actions/getRawBlockTransactions.js.map +1 -0
  146. package/_esm/zksync/actions/getTestnetPaymasterAddress.js +5 -0
  147. package/_esm/zksync/actions/getTestnetPaymasterAddress.js.map +1 -0
  148. package/_esm/zksync/actions/getTransactionDetails.js +8 -0
  149. package/_esm/zksync/actions/getTransactionDetails.js.map +1 -0
  150. package/_esm/zksync/constants/address.js +3 -0
  151. package/_esm/zksync/constants/address.js.map +1 -1
  152. package/_esm/zksync/decorators/publicL1.js +12 -0
  153. package/_esm/zksync/decorators/publicL1.js.map +1 -0
  154. package/_esm/zksync/decorators/publicL2.js +39 -0
  155. package/_esm/zksync/decorators/publicL2.js.map +1 -0
  156. package/_esm/zksync/errors/token-is-eth.js +13 -0
  157. package/_esm/zksync/errors/token-is-eth.js.map +1 -0
  158. package/_esm/zksync/index.js +20 -1
  159. package/_esm/zksync/index.js.map +1 -1
  160. package/_esm/zksync/types/eip1193.js +2 -0
  161. package/_esm/zksync/types/eip1193.js.map +1 -0
  162. package/_esm/zksync/types/proof.js +2 -0
  163. package/_esm/zksync/types/proof.js.map +1 -0
  164. package/_esm/zksync/utils/camelCaseKeys.js +13 -0
  165. package/_esm/zksync/utils/camelCaseKeys.js.map +1 -0
  166. package/_esm/zksync/utils/isEth.js +13 -0
  167. package/_esm/zksync/utils/isEth.js.map +1 -0
  168. package/_esm/zksync/utils/paymaster/getApprovalBasedPaymasterInput.js +2 -1
  169. package/_esm/zksync/utils/paymaster/getApprovalBasedPaymasterInput.js.map +1 -1
  170. package/_esm/zksync/utils/paymaster/getGeneralPaymasterInput.js +2 -1
  171. package/_esm/zksync/utils/paymaster/getGeneralPaymasterInput.js.map +1 -1
  172. package/_types/actions/public/call.d.ts +3 -12
  173. package/_types/actions/public/call.d.ts.map +1 -1
  174. package/_types/actions/public/estimateGas.d.ts +2 -0
  175. package/_types/actions/public/estimateGas.d.ts.map +1 -1
  176. package/_types/celo/chainConfig.d.ts +58 -526
  177. package/_types/celo/chainConfig.d.ts.map +1 -1
  178. package/_types/celo/formatters.d.ts +29 -263
  179. package/_types/celo/formatters.d.ts.map +1 -1
  180. package/_types/celo/index.d.ts +1 -1
  181. package/_types/celo/index.d.ts.map +1 -1
  182. package/_types/celo/serializers.d.ts +2 -3
  183. package/_types/celo/serializers.d.ts.map +1 -1
  184. package/_types/celo/types.d.ts +7 -31
  185. package/_types/celo/types.d.ts.map +1 -1
  186. package/_types/celo/utils.d.ts +1 -2
  187. package/_types/celo/utils.d.ts.map +1 -1
  188. package/_types/chains/definitions/bob.d.ts +34 -0
  189. package/_types/chains/definitions/bob.d.ts.map +1 -0
  190. package/_types/chains/definitions/celo.d.ts +58 -526
  191. package/_types/chains/definitions/celo.d.ts.map +1 -1
  192. package/_types/chains/definitions/celoAlfajores.d.ts +58 -526
  193. package/_types/chains/definitions/celoAlfajores.d.ts.map +1 -1
  194. package/_types/chains/definitions/funkiSepolia.d.ts +1064 -0
  195. package/_types/chains/definitions/funkiSepolia.d.ts.map +1 -0
  196. package/_types/chains/definitions/lisk.d.ts +1453 -0
  197. package/_types/chains/definitions/lisk.d.ts.map +1 -0
  198. package/_types/chains/definitions/metalL2.d.ts +1080 -0
  199. package/_types/chains/definitions/metalL2.d.ts.map +1 -0
  200. package/_types/chains/definitions/playfiAlbireo.d.ts +8 -8
  201. package/_types/chains/definitions/zkSync.d.ts +8 -8
  202. package/_types/chains/definitions/zkSyncInMemoryNode.d.ts +8 -8
  203. package/_types/chains/definitions/zkSyncLocalNode.d.ts +8 -8
  204. package/_types/chains/definitions/zkSyncSepoliaTestnet.d.ts +8 -8
  205. package/_types/chains/definitions/zkSyncTestnet.d.ts +8 -8
  206. package/_types/chains/index.d.ts +5 -1
  207. package/_types/chains/index.d.ts.map +1 -1
  208. package/_types/errors/version.d.ts +1 -1
  209. package/_types/op-stack/chains.d.ts +1 -0
  210. package/_types/op-stack/chains.d.ts.map +1 -1
  211. package/_types/op-stack/types/transaction.d.ts +2 -2
  212. package/_types/op-stack/types/transaction.d.ts.map +1 -1
  213. package/_types/types/eip1193.d.ts +11 -3
  214. package/_types/types/eip1193.d.ts.map +1 -1
  215. package/_types/utils/stateOverride.d.ts +16 -0
  216. package/_types/utils/stateOverride.d.ts.map +1 -0
  217. package/_types/zksync/actions/estimateFee.d.ts +11 -0
  218. package/_types/zksync/actions/estimateFee.d.ts.map +1 -0
  219. package/_types/zksync/actions/estimateGasL1ToL2.d.ts +10 -0
  220. package/_types/zksync/actions/estimateGasL1ToL2.d.ts.map +1 -0
  221. package/_types/zksync/actions/getAllBalances.d.ts +12 -0
  222. package/_types/zksync/actions/getAllBalances.d.ts.map +1 -0
  223. package/_types/zksync/actions/getBaseTokenL1Address.d.ts +9 -0
  224. package/_types/zksync/actions/getBaseTokenL1Address.d.ts.map +1 -0
  225. package/_types/zksync/actions/getBlockDetails.d.ts +10 -0
  226. package/_types/zksync/actions/getBlockDetails.d.ts.map +1 -0
  227. package/_types/zksync/actions/getBridgehubContractAddress.d.ts +9 -0
  228. package/_types/zksync/actions/getBridgehubContractAddress.d.ts.map +1 -0
  229. package/_types/zksync/actions/getDefaultBridgeAddresses.d.ts +9 -0
  230. package/_types/zksync/actions/getDefaultBridgeAddresses.d.ts.map +1 -0
  231. package/_types/zksync/actions/getL1Allowance.d.ts +17 -0
  232. package/_types/zksync/actions/getL1Allowance.d.ts.map +1 -0
  233. package/_types/zksync/actions/getL1Balance.d.ts +23 -0
  234. package/_types/zksync/actions/getL1Balance.d.ts.map +1 -0
  235. package/_types/zksync/actions/getL1BatchBlockRange.d.ts +11 -0
  236. package/_types/zksync/actions/getL1BatchBlockRange.d.ts.map +1 -0
  237. package/_types/zksync/actions/getL1BatchDetails.d.ts +10 -0
  238. package/_types/zksync/actions/getL1BatchDetails.d.ts.map +1 -0
  239. package/_types/zksync/actions/getL1BatchNumber.d.ts +9 -0
  240. package/_types/zksync/actions/getL1BatchNumber.d.ts.map +1 -0
  241. package/_types/zksync/actions/getL1ChainId.d.ts +9 -0
  242. package/_types/zksync/actions/getL1ChainId.d.ts.map +1 -0
  243. package/_types/zksync/actions/getL1TokenBalance.d.ts +24 -0
  244. package/_types/zksync/actions/getL1TokenBalance.d.ts.map +1 -0
  245. package/_types/zksync/actions/getLogProof.d.ts +14 -0
  246. package/_types/zksync/actions/getLogProof.d.ts.map +1 -0
  247. package/_types/zksync/actions/getMainContractAddress.d.ts +9 -0
  248. package/_types/zksync/actions/getMainContractAddress.d.ts.map +1 -0
  249. package/_types/zksync/actions/getRawBlockTransactions.d.ts +11 -0
  250. package/_types/zksync/actions/getRawBlockTransactions.d.ts.map +1 -0
  251. package/_types/zksync/actions/getTestnetPaymasterAddress.d.ts +9 -0
  252. package/_types/zksync/actions/getTestnetPaymasterAddress.d.ts.map +1 -0
  253. package/_types/zksync/actions/getTransactionDetails.d.ts +13 -0
  254. package/_types/zksync/actions/getTransactionDetails.d.ts.map +1 -0
  255. package/_types/zksync/chainConfig.d.ts +8 -8
  256. package/_types/zksync/constants/address.d.ts +3 -0
  257. package/_types/zksync/constants/address.d.ts.map +1 -1
  258. package/_types/zksync/decorators/publicL1.d.ts +145 -0
  259. package/_types/zksync/decorators/publicL1.d.ts.map +1 -0
  260. package/_types/zksync/decorators/publicL2.d.ts +322 -0
  261. package/_types/zksync/decorators/publicL2.d.ts.map +1 -0
  262. package/_types/zksync/errors/token-is-eth.d.ts +9 -0
  263. package/_types/zksync/errors/token-is-eth.d.ts.map +1 -0
  264. package/_types/zksync/formatters.d.ts +8 -8
  265. package/_types/zksync/index.d.ts +21 -2
  266. package/_types/zksync/index.d.ts.map +1 -1
  267. package/_types/zksync/types/block.d.ts +30 -1
  268. package/_types/zksync/types/block.d.ts.map +1 -1
  269. package/_types/zksync/types/contract.d.ts +6 -0
  270. package/_types/zksync/types/contract.d.ts.map +1 -1
  271. package/_types/zksync/types/eip1193.d.ts +152 -0
  272. package/_types/zksync/types/eip1193.d.ts.map +1 -0
  273. package/_types/zksync/types/fee.d.ts +6 -0
  274. package/_types/zksync/types/fee.d.ts.map +1 -1
  275. package/_types/zksync/types/proof.d.ts +7 -0
  276. package/_types/zksync/types/proof.d.ts.map +1 -0
  277. package/_types/zksync/types/transaction.d.ts +66 -6
  278. package/_types/zksync/types/transaction.d.ts.map +1 -1
  279. package/_types/zksync/utils/camelCaseKeys.d.ts +2 -0
  280. package/_types/zksync/utils/camelCaseKeys.d.ts.map +1 -0
  281. package/_types/zksync/utils/isEth.d.ts +3 -0
  282. package/_types/zksync/utils/isEth.d.ts.map +1 -0
  283. package/_types/zksync/utils/paymaster/getApprovalBasedPaymasterInput.d.ts +1 -1
  284. package/_types/zksync/utils/paymaster/getApprovalBasedPaymasterInput.d.ts.map +1 -1
  285. package/_types/zksync/utils/paymaster/getGeneralPaymasterInput.d.ts +1 -1
  286. package/_types/zksync/utils/paymaster/getGeneralPaymasterInput.d.ts.map +1 -1
  287. package/actions/public/call.ts +8 -91
  288. package/actions/public/estimateGas.ts +11 -1
  289. package/celo/formatters.ts +3 -11
  290. package/celo/index.ts +0 -2
  291. package/celo/serializers.ts +2 -50
  292. package/celo/types.ts +6 -41
  293. package/celo/utils.ts +1 -24
  294. package/chains/definitions/bob.ts +30 -0
  295. package/chains/definitions/funkiSepolia.ts +32 -0
  296. package/chains/definitions/lisk.ts +31 -0
  297. package/chains/definitions/metalL2.ts +51 -0
  298. package/chains/index.ts +4 -2
  299. package/errors/version.ts +1 -1
  300. package/op-stack/chains.ts +1 -0
  301. package/op-stack/types/transaction.ts +2 -2
  302. package/package.json +1 -1
  303. package/types/eip1193.ts +11 -1
  304. package/utils/stateOverride.ts +98 -0
  305. package/zksync/actions/estimateFee.ts +46 -0
  306. package/zksync/actions/estimateGasL1ToL2.ts +38 -0
  307. package/zksync/actions/getAllBalances.ts +33 -0
  308. package/zksync/actions/getBaseTokenL1Address.ts +18 -0
  309. package/zksync/actions/getBlockDetails.ts +27 -0
  310. package/zksync/actions/getBridgehubContractAddress.ts +18 -0
  311. package/zksync/actions/getDefaultBridgeAddresses.ts +22 -0
  312. package/zksync/actions/getL1Allowance.ts +43 -0
  313. package/zksync/actions/getL1Balance.ts +68 -0
  314. package/zksync/actions/getL1BatchBlockRange.ts +26 -0
  315. package/zksync/actions/getL1BatchDetails.ts +27 -0
  316. package/zksync/actions/getL1BatchNumber.ts +18 -0
  317. package/zksync/actions/getL1ChainId.ts +18 -0
  318. package/zksync/actions/getL1TokenBalance.ts +63 -0
  319. package/zksync/actions/getLogProof.ts +28 -0
  320. package/zksync/actions/getMainContractAddress.ts +18 -0
  321. package/zksync/actions/getRawBlockTransactions.ts +26 -0
  322. package/zksync/actions/getTestnetPaymasterAddress.ts +18 -0
  323. package/zksync/actions/getTransactionDetails.ts +27 -0
  324. package/zksync/constants/address.ts +9 -0
  325. package/zksync/decorators/publicL1.ts +180 -0
  326. package/zksync/decorators/publicL2.ts +443 -0
  327. package/zksync/errors/token-is-eth.ts +16 -0
  328. package/zksync/index.ts +85 -6
  329. package/zksync/types/block.ts +37 -1
  330. package/zksync/types/contract.ts +8 -0
  331. package/zksync/types/eip1193.ts +155 -0
  332. package/zksync/types/fee.ts +7 -0
  333. package/zksync/types/proof.ts +7 -0
  334. package/zksync/types/transaction.ts +86 -12
  335. package/zksync/utils/camelCaseKeys.ts +11 -0
  336. package/zksync/utils/isEth.ts +20 -0
  337. package/zksync/utils/paymaster/getApprovalBasedPaymasterInput.ts +5 -2
  338. package/zksync/utils/paymaster/getGeneralPaymasterInput.ts +5 -2
@@ -5,6 +5,7 @@ export { baseGoerli } from '../chains/definitions/baseGoerli.js'
5
5
  export { baseSepolia } from '../chains/definitions/baseSepolia.js'
6
6
  export { fraxtal } from '../chains/definitions/fraxtal.js'
7
7
  export { fraxtalTestnet } from '../chains/definitions/fraxtalTestnet.js'
8
+ export { metalL2 } from '../chains/definitions/metalL2.js'
8
9
  export { optimism } from '../chains/definitions/optimism.js'
9
10
  export { optimismGoerli } from '../chains/definitions/optimismGoerli.js'
10
11
  export { optimismSepolia } from '../chains/definitions/optimismSepolia.js'
@@ -3,17 +3,17 @@ import type { Hex } from '../../types/misc.js'
3
3
  import type {
4
4
  Index,
5
5
  Quantity,
6
- RpcTransaction as RpcTransaction_,
7
6
  RpcTransactionReceipt,
7
+ RpcTransaction as RpcTransaction_,
8
8
  } from '../../types/rpc.js'
9
9
  import type {
10
- Transaction as Transaction_,
11
10
  TransactionBase,
12
11
  TransactionReceipt,
13
12
  TransactionSerializable,
14
13
  TransactionSerializableBase,
15
14
  TransactionSerialized,
16
15
  TransactionType,
16
+ Transaction as Transaction_,
17
17
  } from '../../types/transaction.js'
18
18
  import type { OneOf } from '../../types/utils.js'
19
19
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.10.9",
4
+ "version": "2.11.0",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
package/types/eip1193.ts CHANGED
@@ -4,13 +4,13 @@ import type { BlockTag } from './block.js'
4
4
  import type { Hash, Hex, LogTopic } from './misc.js'
5
5
  import type { RpcStateOverride } from './rpc.js'
6
6
  import type {
7
- Quantity,
8
7
  RpcBlock as Block,
9
8
  RpcBlockIdentifier as BlockIdentifier,
10
9
  RpcBlockNumber as BlockNumber,
11
10
  RpcFeeHistory as FeeHistory,
12
11
  RpcLog as Log,
13
12
  RpcProof as Proof,
13
+ Quantity,
14
14
  RpcTransaction as Transaction,
15
15
  RpcTransactionReceipt as TransactionReceipt,
16
16
  RpcTransactionRequest as TransactionRequest,
@@ -331,6 +331,11 @@ export type PublicRpcSchema = [
331
331
  Parameters:
332
332
  | [transaction: TransactionRequest]
333
333
  | [transaction: TransactionRequest, block: BlockNumber | BlockTag]
334
+ | [
335
+ transaction: TransactionRequest,
336
+ block: BlockNumber | BlockTag,
337
+ RpcStateOverride,
338
+ ]
334
339
  ReturnType: Quantity
335
340
  },
336
341
  /**
@@ -1197,6 +1202,11 @@ export type WalletRpcSchema = [
1197
1202
  Parameters:
1198
1203
  | [transaction: TransactionRequest]
1199
1204
  | [transaction: TransactionRequest, block: BlockNumber | BlockTag]
1205
+ | [
1206
+ transaction: TransactionRequest,
1207
+ block: BlockNumber | BlockTag,
1208
+ RpcStateOverride,
1209
+ ]
1200
1210
  ReturnType: Quantity
1201
1211
  },
1202
1212
  /**
@@ -0,0 +1,98 @@
1
+ import {
2
+ InvalidAddressError,
3
+ type InvalidAddressErrorType,
4
+ } from '../errors/address.js'
5
+ import {
6
+ InvalidBytesLengthError,
7
+ type InvalidBytesLengthErrorType,
8
+ } from '../errors/data.js'
9
+ import {
10
+ AccountStateConflictError,
11
+ type AccountStateConflictErrorType,
12
+ StateAssignmentConflictError,
13
+ type StateAssignmentConflictErrorType,
14
+ } from '../errors/stateOverride.js'
15
+ import type {
16
+ RpcAccountStateOverride,
17
+ RpcStateMapping,
18
+ RpcStateOverride,
19
+ } from '../types/rpc.js'
20
+ import type { StateMapping, StateOverride } from '../types/stateOverride.js'
21
+ import { isAddress } from './address/isAddress.js'
22
+ import { type NumberToHexErrorType, numberToHex } from './encoding/toHex.js'
23
+
24
+ export type SerializeStateMappingParameters = StateMapping | undefined
25
+
26
+ export type SerializeStateMappingErrorType = InvalidBytesLengthErrorType
27
+
28
+ export function serializeStateMapping(
29
+ stateMapping: SerializeStateMappingParameters,
30
+ ): RpcStateMapping | undefined {
31
+ if (!stateMapping || stateMapping.length === 0) return undefined
32
+ return stateMapping.reduce((acc, { slot, value }) => {
33
+ if (slot.length !== 66)
34
+ throw new InvalidBytesLengthError({
35
+ size: slot.length,
36
+ targetSize: 66,
37
+ type: 'hex',
38
+ })
39
+ if (value.length !== 66)
40
+ throw new InvalidBytesLengthError({
41
+ size: value.length,
42
+ targetSize: 66,
43
+ type: 'hex',
44
+ })
45
+ acc[slot] = value
46
+ return acc
47
+ }, {} as RpcStateMapping)
48
+ }
49
+
50
+ export type SerializeAccountStateOverrideParameters = Omit<
51
+ StateOverride[number],
52
+ 'address'
53
+ >
54
+
55
+ export type SerializeAccountStateOverrideErrorType =
56
+ | NumberToHexErrorType
57
+ | StateAssignmentConflictErrorType
58
+ | SerializeStateMappingErrorType
59
+
60
+ export function serializeAccountStateOverride(
61
+ parameters: SerializeAccountStateOverrideParameters,
62
+ ): RpcAccountStateOverride {
63
+ const { balance, nonce, state, stateDiff, code } = parameters
64
+ const rpcAccountStateOverride: RpcAccountStateOverride = {}
65
+ if (code !== undefined) rpcAccountStateOverride.code = code
66
+ if (balance !== undefined)
67
+ rpcAccountStateOverride.balance = numberToHex(balance)
68
+ if (nonce !== undefined) rpcAccountStateOverride.nonce = numberToHex(nonce)
69
+ if (state !== undefined)
70
+ rpcAccountStateOverride.state = serializeStateMapping(state)
71
+ if (stateDiff !== undefined) {
72
+ if (rpcAccountStateOverride.state) throw new StateAssignmentConflictError()
73
+ rpcAccountStateOverride.stateDiff = serializeStateMapping(stateDiff)
74
+ }
75
+ return rpcAccountStateOverride
76
+ }
77
+
78
+ export type SerializeStateOverrideParameters = StateOverride | undefined
79
+
80
+ export type SerializeStateOverrideErrorType =
81
+ | InvalidAddressErrorType
82
+ | AccountStateConflictErrorType
83
+ | SerializeAccountStateOverrideErrorType
84
+
85
+ export function serializeStateOverride(
86
+ parameters?: SerializeStateOverrideParameters,
87
+ ): RpcStateOverride | undefined {
88
+ if (!parameters) return undefined
89
+ const rpcStateOverride: RpcStateOverride = {}
90
+ for (const { address, ...accountState } of parameters) {
91
+ if (!isAddress(address, { strict: false }))
92
+ throw new InvalidAddressError({ address })
93
+ if (rpcStateOverride[address])
94
+ throw new AccountStateConflictError({ address: address })
95
+ rpcStateOverride[address] = serializeAccountStateOverride(accountState)
96
+ }
97
+ return rpcStateOverride
98
+ }
@@ -0,0 +1,46 @@
1
+ import { parseAccount } from '../../accounts/utils/parseAccount.js'
2
+ import type { SendTransactionParameters } from '../../actions/wallet/sendTransaction.js'
3
+ import type { Client } from '../../clients/createClient.js'
4
+ import type { Transport } from '../../clients/transports/createTransport.js'
5
+ import type { Account } from '../../types/account.js'
6
+ import { hexToBigInt } from '../../utils/encoding/fromHex.js'
7
+ import type { ChainEIP712 } from '../types/chain.js'
8
+ import type { PublicZkSyncRpcSchema } from '../types/eip1193.js'
9
+ import type { ZkSyncFee } from '../types/fee.js'
10
+
11
+ export type EstimateFeeParameters<
12
+ chain extends ChainEIP712 | undefined = ChainEIP712 | undefined,
13
+ account extends Account | undefined = Account | undefined,
14
+ chainOverride extends ChainEIP712 | undefined = ChainEIP712 | undefined,
15
+ > = SendTransactionParameters<chain, account, chainOverride>
16
+
17
+ export type EstimateFeeReturnType = ZkSyncFee
18
+
19
+ export async function estimateFee<
20
+ chain extends ChainEIP712 | undefined,
21
+ account extends Account | undefined,
22
+ >(
23
+ client: Client<Transport, chain, account, PublicZkSyncRpcSchema>,
24
+ parameters: EstimateFeeParameters<chain, account>,
25
+ ): Promise<EstimateFeeReturnType> {
26
+ const { account: account_, ...request } = parameters
27
+ const account = account_ ? parseAccount(account_) : client.account
28
+
29
+ const formatters = client.chain?.formatters
30
+ const formatted = formatters?.transactionRequest?.format({
31
+ ...request,
32
+ from: account?.address,
33
+ })
34
+
35
+ const result = await client.request({
36
+ method: 'zks_estimateFee',
37
+ params: [formatted],
38
+ })
39
+
40
+ return {
41
+ gasLimit: hexToBigInt(result.gas_limit),
42
+ gasPerPubdataLimit: hexToBigInt(result.gas_per_pubdata_limit),
43
+ maxPriorityFeePerGas: hexToBigInt(result.max_priority_fee_per_gas),
44
+ maxFeePerGas: hexToBigInt(result.max_fee_per_gas),
45
+ }
46
+ }
@@ -0,0 +1,38 @@
1
+ import type { SendTransactionParameters } from '../../actions/wallet/sendTransaction.js'
2
+ import type { Client } from '../../clients/createClient.js'
3
+ import type { Transport } from '../../clients/transports/createTransport.js'
4
+ import type { Account } from '../../types/account.js'
5
+ import { parseAccount } from '../../utils/accounts.js'
6
+ import type { ChainEIP712 } from '../types/chain.js'
7
+ import type { PublicZkSyncRpcSchema } from '../types/eip1193.js'
8
+
9
+ export type EstimateGasL1ToL2Parameters<
10
+ chain extends ChainEIP712 | undefined = ChainEIP712 | undefined,
11
+ account extends Account | undefined = Account | undefined,
12
+ > = SendTransactionParameters<chain, account>
13
+
14
+ export type EstimateGasL1ToL2ReturnType = bigint
15
+
16
+ export async function estimateGasL1ToL2<
17
+ chain extends ChainEIP712 | undefined,
18
+ account extends Account | undefined,
19
+ >(
20
+ client: Client<Transport, chain, account, PublicZkSyncRpcSchema>,
21
+ parameters: EstimateGasL1ToL2Parameters<chain, account>,
22
+ ): Promise<EstimateGasL1ToL2ReturnType> {
23
+ const { account: account_, ...request } = parameters
24
+ const account = account_ ? parseAccount(account_) : client.account
25
+
26
+ const formatters = client.chain?.formatters
27
+ const formatted = formatters?.transactionRequest?.format({
28
+ ...request,
29
+ from: account?.address,
30
+ })
31
+
32
+ const result = await client.request({
33
+ method: 'zks_estimateGasL1ToL2',
34
+ params: [formatted],
35
+ })
36
+
37
+ return result
38
+ }
@@ -0,0 +1,33 @@
1
+ import type { Address } from 'abitype'
2
+ import type { Client } from '../../clients/createClient.js'
3
+ import type { Transport } from '../../clients/transports/createTransport.js'
4
+ import type { Account, GetAccountParameter } from '../../types/account.js'
5
+ import type { Chain } from '../../types/chain.js'
6
+ import { parseAccount } from '../../utils/accounts.js'
7
+ import { hexToBigInt } from '../../utils/encoding/fromHex.js'
8
+ import type { PublicZkSyncRpcSchema } from '../types/eip1193.js'
9
+
10
+ export type GetAllBalancesParameters<
11
+ TAccount extends Account | undefined = Account | undefined,
12
+ > = GetAccountParameter<TAccount>
13
+
14
+ export type GetAllBalancesReturnType = { [key: Address]: bigint }
15
+
16
+ export async function getAllBalances<
17
+ TChain extends Chain | undefined,
18
+ TAccount extends Account | undefined,
19
+ >(
20
+ client: Client<Transport, TChain, TAccount, PublicZkSyncRpcSchema>,
21
+ parameters: GetAllBalancesParameters<TAccount>,
22
+ ): Promise<GetAllBalancesReturnType> {
23
+ const { account: account_ } = parameters
24
+ const account = account_ ? parseAccount(account_) : client.account
25
+ const balances = await client.request({
26
+ method: 'zks_getAllAccountBalances',
27
+ params: [account!.address],
28
+ })
29
+ const convertedBalances: GetAllBalancesReturnType = {}
30
+ for (const token in balances)
31
+ (convertedBalances as any)[token] = hexToBigInt((balances as any)[token])
32
+ return convertedBalances
33
+ }
@@ -0,0 +1,18 @@
1
+ import type { Address } from 'abitype'
2
+ import type { Client } from '../../clients/createClient.js'
3
+ import type { Transport } from '../../clients/transports/createTransport.js'
4
+ import type { Account } from '../../types/account.js'
5
+ import type { Chain } from '../../types/chain.js'
6
+ import type { PublicZkSyncRpcSchema } from '../types/eip1193.js'
7
+
8
+ export type GetBaseTokenL1AddressReturnType = Address
9
+
10
+ export async function getBaseTokenL1Address<
11
+ TChain extends Chain | undefined,
12
+ TAccount extends Account | undefined,
13
+ >(
14
+ client: Client<Transport, TChain, TAccount, PublicZkSyncRpcSchema>,
15
+ ): Promise<GetBaseTokenL1AddressReturnType> {
16
+ const result = await client.request({ method: 'zks_getBaseTokenL1Address' })
17
+ return result
18
+ }
@@ -0,0 +1,27 @@
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 type {
6
+ ZkSyncBlockDetails,
7
+ ZkSyncNumberParameter,
8
+ } from '../types/block.js'
9
+ import type { PublicZkSyncRpcSchema } from '../types/eip1193.js'
10
+
11
+ export type GetBlockDetailsParameters = ZkSyncNumberParameter
12
+
13
+ export type GetBlockDetailsReturnType = ZkSyncBlockDetails
14
+
15
+ export async function getBlockDetails<
16
+ TChain extends Chain | undefined,
17
+ TAccount extends Account | undefined,
18
+ >(
19
+ client: Client<Transport, TChain, TAccount, PublicZkSyncRpcSchema>,
20
+ parameters: GetBlockDetailsParameters,
21
+ ): Promise<GetBlockDetailsReturnType> {
22
+ const result = await client.request({
23
+ method: 'zks_getBlockDetails',
24
+ params: [parameters.number],
25
+ })
26
+ return result
27
+ }
@@ -0,0 +1,18 @@
1
+ import type { Address } from 'abitype'
2
+ import type { Client } from '../../clients/createClient.js'
3
+ import type { Transport } from '../../clients/transports/createTransport.js'
4
+ import type { Account } from '../../types/account.js'
5
+ import type { Chain } from '../../types/chain.js'
6
+ import type { PublicZkSyncRpcSchema } from '../types/eip1193.js'
7
+
8
+ export type GetBridgehubContractAddressReturnType = Address
9
+
10
+ export async function getBridgehubContractAddress<
11
+ TChain extends Chain | undefined,
12
+ TAccount extends Account | undefined,
13
+ >(
14
+ client: Client<Transport, TChain, TAccount, PublicZkSyncRpcSchema>,
15
+ ): Promise<GetBridgehubContractAddressReturnType> {
16
+ const result = await client.request({ method: 'zks_getBridgehubContract' })
17
+ return result
18
+ }
@@ -0,0 +1,22 @@
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 type { BridgeContractAddresses } from '../types/contract.js'
6
+ import type { PublicZkSyncRpcSchema } from '../types/eip1193.js'
7
+
8
+ export type GetDefaultBridgeAddressesReturnType = BridgeContractAddresses
9
+
10
+ export async function getDefaultBridgeAddresses<
11
+ TChain extends Chain | undefined,
12
+ TAccount extends Account | undefined,
13
+ >(
14
+ client: Client<Transport, TChain, TAccount, PublicZkSyncRpcSchema>,
15
+ ): Promise<GetDefaultBridgeAddressesReturnType> {
16
+ const addresses = await client.request({ method: 'zks_getBridgeContracts' })
17
+ return {
18
+ erc20L1: addresses.l1Erc20DefaultBridge,
19
+ sharedL1: addresses.l1SharedDefaultBridge,
20
+ sharedL2: addresses.l2SharedDefaultBridge,
21
+ }
22
+ }
@@ -0,0 +1,43 @@
1
+ import type { Address } from 'abitype'
2
+ import { readContract } from '../../actions/public/readContract.js'
3
+ import type { Client } from '../../clients/createClient.js'
4
+ import type { Transport } from '../../clients/transports/createTransport.js'
5
+ import { erc20Abi } from '../../constants/abis.js'
6
+ import type { AccountNotFoundError } from '../../errors/account.js'
7
+ import type { BaseError } from '../../errors/base.js'
8
+ import type { Account, GetAccountParameter } from '../../types/account.js'
9
+ import type { BlockTag } from '../../types/block.js'
10
+ import type { Chain } from '../../types/chain.js'
11
+ import { parseAccount } from '../../utils/accounts.js'
12
+
13
+ export type GetL1AllowanceParameters<
14
+ TAccount extends Account | undefined = Account | undefined,
15
+ > = GetAccountParameter<TAccount> & {
16
+ bridgeAddress: Address
17
+ blockTag?: BlockTag
18
+ token: Address
19
+ }
20
+
21
+ export type GetL1AllowanceReturnType = bigint
22
+
23
+ export type GetL1AllowanceErrorType = AccountNotFoundError | BaseError
24
+
25
+ export async function getL1Allowance<
26
+ TChain extends Chain | undefined,
27
+ TAccount extends Account | undefined,
28
+ >(
29
+ client: Client<Transport, TChain, TAccount>,
30
+ parameters: GetL1AllowanceParameters<TAccount>,
31
+ ): Promise<GetL1AllowanceReturnType> {
32
+ const { token, bridgeAddress, blockTag, account: account_ } = parameters
33
+
34
+ const account = account_ ? parseAccount(account_) : client.account
35
+
36
+ return await readContract(client, {
37
+ abi: erc20Abi,
38
+ address: token,
39
+ functionName: 'allowance',
40
+ args: [account!.address, bridgeAddress],
41
+ blockTag: blockTag,
42
+ })
43
+ }
@@ -0,0 +1,68 @@
1
+ import type { Address } from 'abitype'
2
+ import {
3
+ type GetBalanceParameters,
4
+ getBalance,
5
+ } from '../../actions/public/getBalance.js'
6
+ import type { Client } from '../../clients/createClient.js'
7
+ import type { Transport } from '../../clients/transports/createTransport.js'
8
+ import type { AccountNotFoundError } from '../../errors/account.js'
9
+ import type { BaseError } from '../../errors/base.js'
10
+ import type { Account, GetAccountParameter } from '../../types/account.js'
11
+ import type { BlockTag } from '../../types/block.js'
12
+ import type { Chain } from '../../types/chain.js'
13
+ import { parseAccount } from '../../utils/accounts.js'
14
+ import { legacyEthAddress } from '../constants/address.js'
15
+ import { isEth } from '../utils/isEth.js'
16
+ import {
17
+ type GetL1TokenBalanceParameters,
18
+ getL1TokenBalance,
19
+ } from './getL1TokenBalance.js'
20
+
21
+ export type GetL1BalanceParameters<
22
+ TAccount extends Account | undefined = Account | undefined,
23
+ > = GetAccountParameter<TAccount> & { token?: Address | undefined } & (
24
+ | {
25
+ /** The balance of the account at a block number. */
26
+ blockNumber?: bigint | undefined
27
+ blockTag?: never | undefined
28
+ }
29
+ | {
30
+ blockNumber?: never | undefined
31
+ /** The balance of the account at a block tag. */
32
+ blockTag?: BlockTag | undefined
33
+ }
34
+ )
35
+
36
+ export type GetL1BalanceReturnType = bigint
37
+
38
+ export type GetL1BalanceErrorType = AccountNotFoundError | BaseError
39
+
40
+ export async function getL1Balance<
41
+ TChain extends Chain | undefined,
42
+ TAccount extends Account | undefined,
43
+ >(
44
+ client: Client<Transport, TChain, TAccount>,
45
+ ...[parameters = {}]: TAccount extends undefined
46
+ ? [GetL1BalanceParameters<TAccount>]
47
+ : [GetL1BalanceParameters<TAccount>] | []
48
+ ): Promise<GetL1BalanceReturnType> {
49
+ const {
50
+ account: account_ = client.account,
51
+ blockNumber,
52
+ blockTag,
53
+ token = legacyEthAddress,
54
+ } = parameters
55
+
56
+ const account = account_ ? parseAccount(account_) : undefined
57
+
58
+ if (isEth(token))
59
+ return await getBalance(client, {
60
+ address: account!.address,
61
+ blockNumber,
62
+ blockTag,
63
+ } as GetBalanceParameters)
64
+
65
+ return await getL1TokenBalance(client, {
66
+ ...(parameters as GetL1TokenBalanceParameters<TAccount>),
67
+ })
68
+ }
@@ -0,0 +1,26 @@
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 { hexToNumber } from '../../utils/encoding/fromHex.js'
6
+ import type { PublicZkSyncRpcSchema } from '../types/eip1193.js'
7
+
8
+ export type GetL1BatchBlockRangeParameters = {
9
+ l1BatchNumber: number
10
+ }
11
+
12
+ export type GetL1BatchBlockRangeReturnParameters = [number, number]
13
+
14
+ export async function getL1BatchBlockRange<
15
+ TChain extends Chain | undefined,
16
+ TAccount extends Account | undefined,
17
+ >(
18
+ client: Client<Transport, TChain, TAccount, PublicZkSyncRpcSchema>,
19
+ parameters: GetL1BatchBlockRangeParameters,
20
+ ): Promise<GetL1BatchBlockRangeReturnParameters> {
21
+ const [number_1, number_2] = await client.request({
22
+ method: 'zks_getL1BatchBlockRange',
23
+ params: [parameters.l1BatchNumber],
24
+ })
25
+ return [hexToNumber(number_1), hexToNumber(number_2)]
26
+ }
@@ -0,0 +1,27 @@
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 type {
6
+ ZkSyncBatchDetails,
7
+ ZkSyncNumberParameter,
8
+ } from '../types/block.js'
9
+ import type { PublicZkSyncRpcSchema } from '../types/eip1193.js'
10
+
11
+ export type GetL1BatchDetailsParameters = ZkSyncNumberParameter
12
+
13
+ export type GetL1BatchDetailsReturnType = ZkSyncBatchDetails
14
+
15
+ export async function getL1BatchDetails<
16
+ TChain extends Chain | undefined,
17
+ TAccount extends Account | undefined,
18
+ >(
19
+ client: Client<Transport, TChain, TAccount, PublicZkSyncRpcSchema>,
20
+ parameters: GetL1BatchDetailsParameters,
21
+ ): Promise<GetL1BatchDetailsReturnType> {
22
+ const result = await client.request({
23
+ method: 'zks_getL1BatchDetails',
24
+ params: [parameters.number],
25
+ })
26
+ return result
27
+ }
@@ -0,0 +1,18 @@
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 type { Hex } from '../../types/misc.js'
6
+ import type { PublicZkSyncRpcSchema } from '../types/eip1193.js'
7
+
8
+ export type GetL1BatchNumberReturnType = Hex
9
+
10
+ export async function getL1BatchNumber<
11
+ TChain extends Chain | undefined,
12
+ TAccount extends Account | undefined,
13
+ >(
14
+ client: Client<Transport, TChain, TAccount, PublicZkSyncRpcSchema>,
15
+ ): Promise<GetL1BatchNumberReturnType> {
16
+ const result = await client.request({ method: 'zks_L1BatchNumber' })
17
+ return result
18
+ }
@@ -0,0 +1,18 @@
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 type { Hex } from '../../types/misc.js'
6
+ import type { PublicZkSyncRpcSchema } from '../types/eip1193.js'
7
+
8
+ export type GetL1ChainIdReturnType = Hex
9
+
10
+ export async function getL1ChainId<
11
+ TChain extends Chain | undefined,
12
+ TAccount extends Account | undefined,
13
+ >(
14
+ client: Client<Transport, TChain, TAccount, PublicZkSyncRpcSchema>,
15
+ ): Promise<GetL1ChainIdReturnType> {
16
+ const result = await client.request({ method: 'zks_L1ChainId' })
17
+ return result
18
+ }
@@ -0,0 +1,63 @@
1
+ import type { Address } from '../../accounts/index.js'
2
+ import { readContract } from '../../actions/index.js'
3
+ import type { Client } from '../../clients/createClient.js'
4
+ import type { Transport } from '../../clients/transports/createTransport.js'
5
+ import { erc20Abi } from '../../constants/abis.js'
6
+ import type { AccountNotFoundError } from '../../errors/account.js'
7
+ import type { BaseError } from '../../errors/base.js'
8
+ import type { Account, GetAccountParameter } from '../../types/account.js'
9
+ import type { BlockTag } from '../../types/block.js'
10
+ import type { Chain } from '../../types/chain.js'
11
+ import { parseAccount } from '../../utils/accounts.js'
12
+ import { TokenIsEthError } from '../errors/token-is-eth.js'
13
+ import { isEth } from '../utils/isEth.js'
14
+
15
+ export type GetL1TokenBalanceParameters<
16
+ TAccount extends Account | undefined = Account | undefined,
17
+ > = GetAccountParameter<TAccount> & { token: Address } & (
18
+ | {
19
+ /** The balance of the account at a block number. */
20
+ blockNumber?: bigint | undefined
21
+ blockTag?: never | undefined
22
+ }
23
+ | {
24
+ blockNumber?: never | undefined
25
+ /** The balance of the account at a block tag. */
26
+ blockTag?: BlockTag | undefined
27
+ }
28
+ )
29
+
30
+ export type GetL1TokenBalanceReturnType = bigint
31
+
32
+ export type GetL1TokenBalanceErrorType =
33
+ | AccountNotFoundError
34
+ | BaseError
35
+ | TokenIsEthError
36
+
37
+ export async function getL1TokenBalance<
38
+ TChain extends Chain | undefined,
39
+ TAccount extends Account | undefined,
40
+ >(
41
+ client: Client<Transport, TChain, TAccount>,
42
+ parameters: GetL1TokenBalanceParameters<TAccount>,
43
+ ): Promise<GetL1TokenBalanceReturnType> {
44
+ const {
45
+ account: account_ = client.account,
46
+ blockTag,
47
+ blockNumber,
48
+ token,
49
+ } = parameters
50
+
51
+ if (isEth(token!)) throw new TokenIsEthError()
52
+
53
+ const account = account_ ? parseAccount(account_) : client.account
54
+
55
+ return await readContract(client, {
56
+ abi: erc20Abi,
57
+ address: token!,
58
+ functionName: 'balanceOf',
59
+ args: [account!.address],
60
+ blockNumber: blockNumber,
61
+ blockTag: blockTag,
62
+ })
63
+ }