viem 2.47.19 → 2.48.1

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 (304) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/_cjs/actions/public/fillTransaction.js +1 -1
  3. package/_cjs/actions/public/fillTransaction.js.map +1 -1
  4. package/_cjs/actions/wallet/signTransaction.js +1 -0
  5. package/_cjs/actions/wallet/signTransaction.js.map +1 -1
  6. package/_cjs/chains/definitions/ancient8Sepolia.js +1 -0
  7. package/_cjs/chains/definitions/ancient8Sepolia.js.map +1 -1
  8. package/_cjs/chains/definitions/artheraTestnet.js +1 -0
  9. package/_cjs/chains/definitions/artheraTestnet.js.map +1 -1
  10. package/_cjs/chains/definitions/autheoTestnet.js +1 -0
  11. package/_cjs/chains/definitions/autheoTestnet.js.map +1 -1
  12. package/_cjs/chains/definitions/codexTestnet.js +1 -0
  13. package/_cjs/chains/definitions/codexTestnet.js.map +1 -1
  14. package/_cjs/chains/definitions/dchainTestnet.js +1 -0
  15. package/_cjs/chains/definitions/dchainTestnet.js.map +1 -1
  16. package/_cjs/chains/definitions/edgelessTestnet.js +1 -0
  17. package/_cjs/chains/definitions/edgelessTestnet.js.map +1 -1
  18. package/_cjs/chains/definitions/edgewareTestnet.js +1 -0
  19. package/_cjs/chains/definitions/edgewareTestnet.js.map +1 -1
  20. package/_cjs/chains/definitions/evmosTestnet.js +1 -0
  21. package/_cjs/chains/definitions/evmosTestnet.js.map +1 -1
  22. package/_cjs/chains/definitions/exSatTestnet.js +1 -0
  23. package/_cjs/chains/definitions/exSatTestnet.js.map +1 -1
  24. package/_cjs/chains/definitions/flowPreviewnet.js +1 -0
  25. package/_cjs/chains/definitions/flowPreviewnet.js.map +1 -1
  26. package/_cjs/chains/definitions/fraxtalTestnet.js +1 -0
  27. package/_cjs/chains/definitions/fraxtalTestnet.js.map +1 -1
  28. package/_cjs/chains/definitions/haqqTestedge2.js +1 -0
  29. package/_cjs/chains/definitions/haqqTestedge2.js.map +1 -1
  30. package/_cjs/chains/definitions/horizenTestnet.js +2 -2
  31. package/_cjs/chains/definitions/horizenTestnet.js.map +1 -1
  32. package/_cjs/chains/definitions/huddle01Testnet.js +1 -0
  33. package/_cjs/chains/definitions/huddle01Testnet.js.map +1 -1
  34. package/_cjs/chains/definitions/humanodeTestnet5.js +1 -0
  35. package/_cjs/chains/definitions/humanodeTestnet5.js.map +1 -1
  36. package/_cjs/chains/definitions/meterTestnet.js +1 -0
  37. package/_cjs/chains/definitions/meterTestnet.js.map +1 -1
  38. package/_cjs/chains/definitions/metisGoerli.js +1 -0
  39. package/_cjs/chains/definitions/metisGoerli.js.map +1 -1
  40. package/_cjs/chains/definitions/metisSepolia.js +1 -0
  41. package/_cjs/chains/definitions/metisSepolia.js.map +1 -1
  42. package/_cjs/chains/definitions/moonbeam.js +1 -1
  43. package/_cjs/chains/definitions/moonbeam.js.map +1 -1
  44. package/_cjs/chains/definitions/moonriver.js +1 -1
  45. package/_cjs/chains/definitions/moonriver.js.map +1 -1
  46. package/_cjs/chains/definitions/otimDevnet.js +1 -0
  47. package/_cjs/chains/definitions/otimDevnet.js.map +1 -1
  48. package/_cjs/chains/definitions/rolluxTestnet.js +1 -0
  49. package/_cjs/chains/definitions/rolluxTestnet.js.map +1 -1
  50. package/_cjs/chains/definitions/swellchainTestnet.js +1 -0
  51. package/_cjs/chains/definitions/swellchainTestnet.js.map +1 -1
  52. package/_cjs/chains/definitions/syscoinTestnet.js +1 -0
  53. package/_cjs/chains/definitions/syscoinTestnet.js.map +1 -1
  54. package/_cjs/chains/definitions/taikoKatla.js +1 -0
  55. package/_cjs/chains/definitions/taikoKatla.js.map +1 -1
  56. package/_cjs/chains/definitions/taikoTestnetSepolia.js +1 -0
  57. package/_cjs/chains/definitions/taikoTestnetSepolia.js.map +1 -1
  58. package/_cjs/chains/definitions/tempoDevnet.js +1 -0
  59. package/_cjs/chains/definitions/tempoDevnet.js.map +1 -1
  60. package/_cjs/chains/definitions/tempoModerato.js +1 -0
  61. package/_cjs/chains/definitions/tempoModerato.js.map +1 -1
  62. package/_cjs/chains/definitions/xdcTestnet.js +1 -0
  63. package/_cjs/chains/definitions/xdcTestnet.js.map +1 -1
  64. package/_cjs/chains/definitions/zkLinkNovaSepoliaTestnet.js +1 -0
  65. package/_cjs/chains/definitions/zkLinkNovaSepoliaTestnet.js.map +1 -1
  66. package/_cjs/errors/version.js +1 -1
  67. package/_cjs/errors/version.js.map +1 -1
  68. package/_cjs/tempo/Addresses.js +2 -1
  69. package/_cjs/tempo/Addresses.js.map +1 -1
  70. package/_cjs/tempo/Decorator.js +16 -0
  71. package/_cjs/tempo/Decorator.js.map +1 -1
  72. package/_cjs/tempo/Formatters.js +5 -1
  73. package/_cjs/tempo/Formatters.js.map +1 -1
  74. package/_cjs/tempo/Storage.js +77 -0
  75. package/_cjs/tempo/Storage.js.map +1 -0
  76. package/_cjs/tempo/actions/index.js +2 -1
  77. package/_cjs/tempo/actions/index.js.map +1 -1
  78. package/_cjs/tempo/actions/zone.js +432 -0
  79. package/_cjs/tempo/actions/zone.js.map +1 -0
  80. package/_cjs/tempo/index.js +2 -1
  81. package/_cjs/tempo/index.js.map +1 -1
  82. package/_cjs/tempo/zones/Abis.js +82 -0
  83. package/_cjs/tempo/zones/Abis.js.map +1 -0
  84. package/_cjs/tempo/zones/index.js +13 -0
  85. package/_cjs/tempo/zones/index.js.map +1 -0
  86. package/_cjs/tempo/zones/transport.js +24 -0
  87. package/_cjs/tempo/zones/transport.js.map +1 -0
  88. package/_cjs/tempo/zones/zone.js +53 -0
  89. package/_cjs/tempo/zones/zone.js.map +1 -0
  90. package/_esm/actions/public/fillTransaction.js +1 -1
  91. package/_esm/actions/public/fillTransaction.js.map +1 -1
  92. package/_esm/actions/wallet/signTransaction.js +1 -0
  93. package/_esm/actions/wallet/signTransaction.js.map +1 -1
  94. package/_esm/chains/definitions/ancient8Sepolia.js +1 -0
  95. package/_esm/chains/definitions/ancient8Sepolia.js.map +1 -1
  96. package/_esm/chains/definitions/artheraTestnet.js +1 -0
  97. package/_esm/chains/definitions/artheraTestnet.js.map +1 -1
  98. package/_esm/chains/definitions/autheoTestnet.js +1 -0
  99. package/_esm/chains/definitions/autheoTestnet.js.map +1 -1
  100. package/_esm/chains/definitions/codexTestnet.js +1 -0
  101. package/_esm/chains/definitions/codexTestnet.js.map +1 -1
  102. package/_esm/chains/definitions/dchainTestnet.js +1 -0
  103. package/_esm/chains/definitions/dchainTestnet.js.map +1 -1
  104. package/_esm/chains/definitions/edgelessTestnet.js +1 -0
  105. package/_esm/chains/definitions/edgelessTestnet.js.map +1 -1
  106. package/_esm/chains/definitions/edgewareTestnet.js +1 -0
  107. package/_esm/chains/definitions/edgewareTestnet.js.map +1 -1
  108. package/_esm/chains/definitions/evmosTestnet.js +1 -0
  109. package/_esm/chains/definitions/evmosTestnet.js.map +1 -1
  110. package/_esm/chains/definitions/exSatTestnet.js +1 -0
  111. package/_esm/chains/definitions/exSatTestnet.js.map +1 -1
  112. package/_esm/chains/definitions/flowPreviewnet.js +1 -0
  113. package/_esm/chains/definitions/flowPreviewnet.js.map +1 -1
  114. package/_esm/chains/definitions/fraxtalTestnet.js +1 -0
  115. package/_esm/chains/definitions/fraxtalTestnet.js.map +1 -1
  116. package/_esm/chains/definitions/haqqTestedge2.js +1 -0
  117. package/_esm/chains/definitions/haqqTestedge2.js.map +1 -1
  118. package/_esm/chains/definitions/horizenTestnet.js +2 -2
  119. package/_esm/chains/definitions/horizenTestnet.js.map +1 -1
  120. package/_esm/chains/definitions/huddle01Testnet.js +1 -0
  121. package/_esm/chains/definitions/huddle01Testnet.js.map +1 -1
  122. package/_esm/chains/definitions/humanodeTestnet5.js +1 -0
  123. package/_esm/chains/definitions/humanodeTestnet5.js.map +1 -1
  124. package/_esm/chains/definitions/meterTestnet.js +1 -0
  125. package/_esm/chains/definitions/meterTestnet.js.map +1 -1
  126. package/_esm/chains/definitions/metisGoerli.js +1 -0
  127. package/_esm/chains/definitions/metisGoerli.js.map +1 -1
  128. package/_esm/chains/definitions/metisSepolia.js +1 -0
  129. package/_esm/chains/definitions/metisSepolia.js.map +1 -1
  130. package/_esm/chains/definitions/moonbeam.js +1 -1
  131. package/_esm/chains/definitions/moonbeam.js.map +1 -1
  132. package/_esm/chains/definitions/moonriver.js +1 -1
  133. package/_esm/chains/definitions/moonriver.js.map +1 -1
  134. package/_esm/chains/definitions/otimDevnet.js +1 -0
  135. package/_esm/chains/definitions/otimDevnet.js.map +1 -1
  136. package/_esm/chains/definitions/rolluxTestnet.js +1 -0
  137. package/_esm/chains/definitions/rolluxTestnet.js.map +1 -1
  138. package/_esm/chains/definitions/swellchainTestnet.js +1 -0
  139. package/_esm/chains/definitions/swellchainTestnet.js.map +1 -1
  140. package/_esm/chains/definitions/syscoinTestnet.js +1 -0
  141. package/_esm/chains/definitions/syscoinTestnet.js.map +1 -1
  142. package/_esm/chains/definitions/taikoKatla.js +1 -0
  143. package/_esm/chains/definitions/taikoKatla.js.map +1 -1
  144. package/_esm/chains/definitions/taikoTestnetSepolia.js +1 -0
  145. package/_esm/chains/definitions/taikoTestnetSepolia.js.map +1 -1
  146. package/_esm/chains/definitions/tempoDevnet.js +1 -0
  147. package/_esm/chains/definitions/tempoDevnet.js.map +1 -1
  148. package/_esm/chains/definitions/tempoModerato.js +1 -0
  149. package/_esm/chains/definitions/tempoModerato.js.map +1 -1
  150. package/_esm/chains/definitions/xdcTestnet.js +1 -0
  151. package/_esm/chains/definitions/xdcTestnet.js.map +1 -1
  152. package/_esm/chains/definitions/zkLinkNovaSepoliaTestnet.js +1 -0
  153. package/_esm/chains/definitions/zkLinkNovaSepoliaTestnet.js.map +1 -1
  154. package/_esm/errors/version.js +1 -1
  155. package/_esm/errors/version.js.map +1 -1
  156. package/_esm/tempo/Addresses.js +1 -0
  157. package/_esm/tempo/Addresses.js.map +1 -1
  158. package/_esm/tempo/Decorator.js +16 -0
  159. package/_esm/tempo/Decorator.js.map +1 -1
  160. package/_esm/tempo/Formatters.js +5 -1
  161. package/_esm/tempo/Formatters.js.map +1 -1
  162. package/_esm/tempo/Storage.js +96 -0
  163. package/_esm/tempo/Storage.js.map +1 -0
  164. package/_esm/tempo/actions/index.js +1 -0
  165. package/_esm/tempo/actions/index.js.map +1 -1
  166. package/_esm/tempo/actions/zone.js +786 -0
  167. package/_esm/tempo/actions/zone.js.map +1 -0
  168. package/_esm/tempo/index.js +1 -0
  169. package/_esm/tempo/index.js.map +1 -1
  170. package/_esm/tempo/zones/Abis.js +79 -0
  171. package/_esm/tempo/zones/Abis.js.map +1 -0
  172. package/_esm/tempo/zones/index.js +5 -0
  173. package/_esm/tempo/zones/index.js.map +1 -0
  174. package/_esm/tempo/zones/transport.js +39 -0
  175. package/_esm/tempo/zones/transport.js.map +1 -0
  176. package/_esm/tempo/zones/zone.js +49 -0
  177. package/_esm/tempo/zones/zone.js.map +1 -0
  178. package/_types/actions/wallet/signTransaction.d.ts.map +1 -1
  179. package/_types/chains/definitions/ancient8Sepolia.d.ts +1 -1
  180. package/_types/chains/definitions/ancient8Sepolia.d.ts.map +1 -1
  181. package/_types/chains/definitions/artheraTestnet.d.ts +1 -1
  182. package/_types/chains/definitions/artheraTestnet.d.ts.map +1 -1
  183. package/_types/chains/definitions/autheoTestnet.d.ts +1 -1
  184. package/_types/chains/definitions/autheoTestnet.d.ts.map +1 -1
  185. package/_types/chains/definitions/codexTestnet.d.ts +1 -1
  186. package/_types/chains/definitions/codexTestnet.d.ts.map +1 -1
  187. package/_types/chains/definitions/dchainTestnet.d.ts +1 -1
  188. package/_types/chains/definitions/dchainTestnet.d.ts.map +1 -1
  189. package/_types/chains/definitions/edgelessTestnet.d.ts +1 -1
  190. package/_types/chains/definitions/edgelessTestnet.d.ts.map +1 -1
  191. package/_types/chains/definitions/edgewareTestnet.d.ts +1 -1
  192. package/_types/chains/definitions/edgewareTestnet.d.ts.map +1 -1
  193. package/_types/chains/definitions/evmosTestnet.d.ts +1 -1
  194. package/_types/chains/definitions/evmosTestnet.d.ts.map +1 -1
  195. package/_types/chains/definitions/exSatTestnet.d.ts +1 -1
  196. package/_types/chains/definitions/exSatTestnet.d.ts.map +1 -1
  197. package/_types/chains/definitions/flowPreviewnet.d.ts +1 -1
  198. package/_types/chains/definitions/flowPreviewnet.d.ts.map +1 -1
  199. package/_types/chains/definitions/fraxtalTestnet.d.ts +1 -1
  200. package/_types/chains/definitions/fraxtalTestnet.d.ts.map +1 -1
  201. package/_types/chains/definitions/haqqTestedge2.d.ts +1 -1
  202. package/_types/chains/definitions/haqqTestedge2.d.ts.map +1 -1
  203. package/_types/chains/definitions/horizenTestnet.d.ts +2 -2
  204. package/_types/chains/definitions/huddle01Testnet.d.ts +1 -1
  205. package/_types/chains/definitions/huddle01Testnet.d.ts.map +1 -1
  206. package/_types/chains/definitions/humanodeTestnet5.d.ts +1 -1
  207. package/_types/chains/definitions/humanodeTestnet5.d.ts.map +1 -1
  208. package/_types/chains/definitions/meterTestnet.d.ts +1 -1
  209. package/_types/chains/definitions/meterTestnet.d.ts.map +1 -1
  210. package/_types/chains/definitions/metisGoerli.d.ts +1 -1
  211. package/_types/chains/definitions/metisGoerli.d.ts.map +1 -1
  212. package/_types/chains/definitions/metisSepolia.d.ts +1 -1
  213. package/_types/chains/definitions/metisSepolia.d.ts.map +1 -1
  214. package/_types/chains/definitions/moonbeam.d.ts +1 -1
  215. package/_types/chains/definitions/moonriver.d.ts +1 -1
  216. package/_types/chains/definitions/otimDevnet.d.ts +1 -1
  217. package/_types/chains/definitions/otimDevnet.d.ts.map +1 -1
  218. package/_types/chains/definitions/rolluxTestnet.d.ts +1 -1
  219. package/_types/chains/definitions/rolluxTestnet.d.ts.map +1 -1
  220. package/_types/chains/definitions/swellchainTestnet.d.ts +1 -1
  221. package/_types/chains/definitions/swellchainTestnet.d.ts.map +1 -1
  222. package/_types/chains/definitions/syscoinTestnet.d.ts +1 -1
  223. package/_types/chains/definitions/syscoinTestnet.d.ts.map +1 -1
  224. package/_types/chains/definitions/taikoKatla.d.ts +1 -1
  225. package/_types/chains/definitions/taikoKatla.d.ts.map +1 -1
  226. package/_types/chains/definitions/taikoTestnetSepolia.d.ts +1 -1
  227. package/_types/chains/definitions/taikoTestnetSepolia.d.ts.map +1 -1
  228. package/_types/chains/definitions/tempoDevnet.d.ts +2 -1
  229. package/_types/chains/definitions/tempoDevnet.d.ts.map +1 -1
  230. package/_types/chains/definitions/tempoModerato.d.ts +2 -1
  231. package/_types/chains/definitions/tempoModerato.d.ts.map +1 -1
  232. package/_types/chains/definitions/xdcTestnet.d.ts +1 -1
  233. package/_types/chains/definitions/xdcTestnet.d.ts.map +1 -1
  234. package/_types/chains/definitions/zkLinkNovaSepoliaTestnet.d.ts +1 -1
  235. package/_types/chains/definitions/zkLinkNovaSepoliaTestnet.d.ts.map +1 -1
  236. package/_types/errors/version.d.ts +1 -1
  237. package/_types/errors/version.d.ts.map +1 -1
  238. package/_types/tempo/Addresses.d.ts +1 -0
  239. package/_types/tempo/Addresses.d.ts.map +1 -1
  240. package/_types/tempo/Decorator.d.ts +283 -0
  241. package/_types/tempo/Decorator.d.ts.map +1 -1
  242. package/_types/tempo/Formatters.d.ts.map +1 -1
  243. package/_types/tempo/Storage.d.ts +42 -0
  244. package/_types/tempo/Storage.d.ts.map +1 -0
  245. package/_types/tempo/actions/index.d.ts +1 -0
  246. package/_types/tempo/actions/index.d.ts.map +1 -1
  247. package/_types/tempo/actions/zone.d.ts +874 -0
  248. package/_types/tempo/actions/zone.d.ts.map +1 -0
  249. package/_types/tempo/index.d.ts +1 -0
  250. package/_types/tempo/index.d.ts.map +1 -1
  251. package/_types/tempo/zones/Abis.d.ts +124 -0
  252. package/_types/tempo/zones/Abis.d.ts.map +1 -0
  253. package/_types/tempo/zones/index.d.ts +4 -0
  254. package/_types/tempo/zones/index.d.ts.map +1 -0
  255. package/_types/tempo/zones/transport.d.ts +26 -0
  256. package/_types/tempo/zones/transport.d.ts.map +1 -0
  257. package/_types/tempo/zones/zone.d.ts +2775 -0
  258. package/_types/tempo/zones/zone.d.ts.map +1 -0
  259. package/actions/public/fillTransaction.ts +1 -1
  260. package/actions/wallet/signTransaction.ts +1 -0
  261. package/chains/definitions/ancient8Sepolia.ts +1 -0
  262. package/chains/definitions/artheraTestnet.ts +1 -0
  263. package/chains/definitions/autheoTestnet.ts +1 -0
  264. package/chains/definitions/codexTestnet.ts +1 -0
  265. package/chains/definitions/dchainTestnet.ts +1 -0
  266. package/chains/definitions/edgelessTestnet.ts +1 -0
  267. package/chains/definitions/edgewareTestnet.ts +1 -0
  268. package/chains/definitions/evmosTestnet.ts +1 -0
  269. package/chains/definitions/exSatTestnet.ts +1 -0
  270. package/chains/definitions/flowPreviewnet.ts +1 -0
  271. package/chains/definitions/fraxtalTestnet.ts +1 -0
  272. package/chains/definitions/haqqTestedge2.ts +1 -0
  273. package/chains/definitions/horizenTestnet.ts +2 -2
  274. package/chains/definitions/huddle01Testnet.ts +1 -0
  275. package/chains/definitions/humanodeTestnet5.ts +1 -0
  276. package/chains/definitions/meterTestnet.ts +1 -0
  277. package/chains/definitions/metisGoerli.ts +1 -0
  278. package/chains/definitions/metisSepolia.ts +1 -0
  279. package/chains/definitions/moonbeam.ts +1 -1
  280. package/chains/definitions/moonriver.ts +1 -1
  281. package/chains/definitions/otimDevnet.ts +1 -0
  282. package/chains/definitions/rolluxTestnet.ts +1 -0
  283. package/chains/definitions/swellchainTestnet.ts +1 -0
  284. package/chains/definitions/syscoinTestnet.ts +1 -0
  285. package/chains/definitions/taikoKatla.ts +1 -0
  286. package/chains/definitions/taikoTestnetSepolia.ts +1 -0
  287. package/chains/definitions/tempoDevnet.ts +1 -0
  288. package/chains/definitions/tempoModerato.ts +1 -0
  289. package/chains/definitions/xdcTestnet.ts +1 -0
  290. package/chains/definitions/zkLinkNovaSepoliaTestnet.ts +1 -0
  291. package/errors/version.ts +1 -1
  292. package/package.json +7 -2
  293. package/tempo/Addresses.ts +1 -0
  294. package/tempo/Decorator.ts +337 -0
  295. package/tempo/Formatters.ts +5 -1
  296. package/tempo/Storage.ts +118 -0
  297. package/tempo/actions/index.ts +1 -0
  298. package/tempo/actions/zone.ts +1317 -0
  299. package/tempo/index.ts +1 -0
  300. package/tempo/zones/Abis.ts +79 -0
  301. package/tempo/zones/index.ts +10 -0
  302. package/tempo/zones/package.json +6 -0
  303. package/tempo/zones/transport.ts +58 -0
  304. package/tempo/zones/zone.ts +70 -0
@@ -0,0 +1,1317 @@
1
+ import type { Address } from 'abitype'
2
+ import * as Bytes from 'ox/Bytes'
3
+ import * as Hex from 'ox/Hex'
4
+ import * as PublicKey from 'ox/PublicKey'
5
+ import * as Secp256k1 from 'ox/Secp256k1'
6
+ import { TokenId, ZoneId, ZoneRpcAuthentication } from 'ox/tempo'
7
+ import type { Account } from '../../accounts/types.js'
8
+ import { parseAccount } from '../../accounts/utils/parseAccount.js'
9
+ import { readContract } from '../../actions/public/readContract.js'
10
+ import {
11
+ type SendTransactionReturnType,
12
+ sendTransaction,
13
+ } from '../../actions/wallet/sendTransaction.js'
14
+ import { sendTransactionSync } from '../../actions/wallet/sendTransactionSync.js'
15
+ import type { Client } from '../../clients/createClient.js'
16
+ import type { Transport } from '../../clients/transports/createTransport.js'
17
+ import { zeroHash } from '../../constants/bytes.js'
18
+ import type { BaseErrorType } from '../../errors/base.js'
19
+ import type { Chain } from '../../types/chain.js'
20
+ import type { Compute } from '../../types/utils.js'
21
+ import { encodeAbiParameters } from '../../utils/abi/encodeAbiParameters.js'
22
+ import type { RequestErrorType } from '../../utils/buildRequest.js'
23
+ import * as Abis from '../Abis.js'
24
+ import * as Addresses from '../Addresses.js'
25
+ import type {
26
+ GetAccountParameter,
27
+ ReadParameters,
28
+ WriteParameters,
29
+ } from '../internal/types.js'
30
+ import { defineCall } from '../internal/utils.js'
31
+ import * as Storage from '../Storage.js'
32
+ import type { TransactionReceipt } from '../Transaction.js'
33
+ import * as ZoneAbis from '../zones/Abis.js'
34
+ import { getPortalAddress } from '../zones/zone.js'
35
+
36
+ export type EncryptedPayload = {
37
+ ciphertext: Hex.Hex
38
+ ephemeralPubkeyX: Hex.Hex
39
+ ephemeralPubkeyYParity: number
40
+ nonce: Hex.Hex
41
+ tag: Hex.Hex
42
+ }
43
+
44
+ /**
45
+ * Deposits tokens into a zone on the parent Tempo chain.
46
+ * Batches approve and deposit into a single transaction.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * import { createClient, http } from 'viem'
51
+ * import { privateKeyToAccount } from 'viem/accounts'
52
+ * import { tempoModerato } from 'viem/chains'
53
+ * import { Actions } from 'viem/tempo'
54
+ *
55
+ * const client = createClient({
56
+ * account: privateKeyToAccount('0x...'),
57
+ * chain: tempoModerato,
58
+ * transport: http(),
59
+ * })
60
+ *
61
+ * const hash = await Actions.zone.deposit(client, {
62
+ * token: '0x20c0...0001',
63
+ * amount: 1_000_000n,
64
+ * zoneId: 7,
65
+ * })
66
+ * ```
67
+ *
68
+ * @param client - Wallet client connected to the parent Tempo chain.
69
+ * @param parameters - Deposit parameters.
70
+ * @returns The transaction hash.
71
+ */
72
+ export async function deposit<
73
+ chain extends Chain | undefined,
74
+ account extends Account | undefined,
75
+ >(
76
+ client: Client<Transport, chain, account>,
77
+ parameters: deposit.Parameters<chain, account>,
78
+ ): Promise<deposit.ReturnValue> {
79
+ const chainId = client.chain?.id
80
+ if (!chainId) throw new Error('`chain` is required.')
81
+
82
+ const { account = client.account, ...rest } = parameters
83
+
84
+ const account_ = account ? parseAccount(account) : undefined
85
+ if (!account) throw new Error('`account` is required.')
86
+
87
+ const recipient = parameters.recipient ?? account_?.address
88
+ if (!recipient) throw new Error('`recipient` is required.')
89
+
90
+ const args = { ...parameters, chainId, recipient }
91
+ return sendTransaction(client, {
92
+ ...rest,
93
+ calls: deposit.calls(args),
94
+ } as never) as never
95
+ }
96
+
97
+ export namespace deposit {
98
+ export type Parameters<
99
+ chain extends Chain | undefined = Chain | undefined,
100
+ account extends Account | undefined = Account | undefined,
101
+ > = WriteParameters<chain, account> &
102
+ Omit<Args, 'chainId' | 'recipient'> & {
103
+ /** Recipient address in the zone. @default `account.address` */
104
+ recipient?: Address | undefined
105
+ }
106
+
107
+ export type Args = {
108
+ /** Amount of tokens to deposit. */
109
+ amount: bigint
110
+ /** Parent chain ID (e.g. `42431` for moderato). */
111
+ chainId: number
112
+ /** Optional deposit memo. @default `0x00...00` */
113
+ memo?: Hex.Hex | undefined
114
+ /** Recipient address in the zone. */
115
+ recipient: Address
116
+ /** Token address or ID to deposit. */
117
+ token: TokenId.TokenIdOrAddress
118
+ /** Zone ID (e.g. `7`). */
119
+ zoneId: number
120
+ }
121
+
122
+ export type ReturnValue = SendTransactionReturnType
123
+
124
+ // TODO: exhaustive error type
125
+ export type ErrorType = BaseErrorType
126
+
127
+ /**
128
+ * Defines the calls to approve and deposit tokens into a zone.
129
+ *
130
+ * @param args - Arguments.
131
+ * @returns The calls.
132
+ */
133
+ export function calls(args: Args) {
134
+ const { amount, chainId, memo = zeroHash, recipient, token, zoneId } = args
135
+ const portalAddress = getPortalAddress(chainId, zoneId)
136
+ return [
137
+ defineCall({
138
+ address: TokenId.toAddress(token),
139
+ abi: Abis.tip20,
140
+ functionName: 'approve',
141
+ args: [portalAddress, amount],
142
+ }),
143
+ defineCall({
144
+ address: portalAddress,
145
+ abi: ZoneAbis.zonePortal,
146
+ functionName: 'deposit',
147
+ args: [TokenId.toAddress(token), recipient, amount, memo],
148
+ }),
149
+ ]
150
+ }
151
+ }
152
+
153
+ /**
154
+ * Deposits tokens into a zone on the parent Tempo chain and waits for the
155
+ * transaction receipt.
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * import { createClient, http } from 'viem'
160
+ * import { privateKeyToAccount } from 'viem/accounts'
161
+ * import { tempoModerato } from 'viem/chains'
162
+ * import { Actions } from 'viem/tempo'
163
+ *
164
+ * const client = createClient({
165
+ * account: privateKeyToAccount('0x...'),
166
+ * chain: tempoModerato,
167
+ * transport: http(),
168
+ * })
169
+ *
170
+ * const result = await Actions.zone.depositSync(client, {
171
+ * token: '0x20c0...0001',
172
+ * amount: 1_000_000n,
173
+ * zoneId: 7,
174
+ * })
175
+ * ```
176
+ *
177
+ * @param client - Wallet client connected to the parent Tempo chain.
178
+ * @param parameters - Deposit parameters.
179
+ * @returns The transaction receipt.
180
+ */
181
+ export async function depositSync<
182
+ chain extends Chain | undefined,
183
+ account extends Account | undefined,
184
+ >(
185
+ client: Client<Transport, chain, account>,
186
+ parameters: depositSync.Parameters<chain, account>,
187
+ ): Promise<depositSync.ReturnValue> {
188
+ const chainId = client.chain?.id
189
+ if (!chainId) throw new Error('`chain` is required.')
190
+
191
+ const {
192
+ account = client.account,
193
+ throwOnReceiptRevert = true,
194
+ ...rest
195
+ } = parameters
196
+
197
+ const account_ = account ? parseAccount(account) : undefined
198
+ if (!account) throw new Error('`account` is required.')
199
+
200
+ const recipient = parameters.recipient ?? account_?.address
201
+ if (!recipient) throw new Error('`recipient` is required.')
202
+
203
+ const args = { ...parameters, chainId, recipient }
204
+ const receipt = await sendTransactionSync(client, {
205
+ ...rest,
206
+ throwOnReceiptRevert,
207
+ calls: deposit.calls(args),
208
+ } as never)
209
+ return { receipt }
210
+ }
211
+
212
+ export namespace depositSync {
213
+ export type Parameters<
214
+ chain extends Chain | undefined = Chain | undefined,
215
+ account extends Account | undefined = Account | undefined,
216
+ > = deposit.Parameters<chain, account>
217
+
218
+ export type Args = deposit.Args
219
+
220
+ export type ReturnValue = Compute<{
221
+ /** Transaction receipt. */
222
+ receipt: TransactionReceipt
223
+ }>
224
+
225
+ // TODO: exhaustive error type
226
+ export type ErrorType = BaseErrorType
227
+ }
228
+
229
+ /**
230
+ * Deposits tokens into a zone on the parent Tempo chain with encrypted
231
+ * recipient and memo. Batches approve and depositEncrypted into a single
232
+ * transaction.
233
+ *
234
+ * @example
235
+ * ```ts
236
+ * import { createClient, http } from 'viem'
237
+ * import { privateKeyToAccount } from 'viem/accounts'
238
+ * import { tempoModerato } from 'viem/chains'
239
+ * import { Actions } from 'viem/tempo'
240
+ *
241
+ * const client = createClient({
242
+ * account: privateKeyToAccount('0x...'),
243
+ * chain: tempoModerato,
244
+ * transport: http(),
245
+ * })
246
+ *
247
+ * const hash = await Actions.zone.encryptedDeposit(client, {
248
+ * token: '0x20c0...0001',
249
+ * amount: 1_000_000n,
250
+ * zoneId: 7,
251
+ * })
252
+ * ```
253
+ *
254
+ * @param client - Wallet client connected to the parent Tempo chain.
255
+ * @param parameters - Encrypted deposit parameters.
256
+ * @returns The transaction hash.
257
+ */
258
+ export async function encryptedDeposit<
259
+ chain extends Chain | undefined,
260
+ account extends Account | undefined,
261
+ >(
262
+ client: Client<Transport, chain, account>,
263
+ parameters: encryptedDeposit.Parameters<chain, account>,
264
+ ): Promise<encryptedDeposit.ReturnValue> {
265
+ const chainId = client.chain?.id
266
+ if (!chainId) throw new Error('`chain` is required.')
267
+
268
+ const { account = client.account, ...rest } = parameters
269
+
270
+ const account_ = account ? parseAccount(account) : undefined
271
+ if (!account) throw new Error('`account` is required.')
272
+
273
+ const recipient = parameters.recipient ?? account_?.address
274
+ if (!recipient) throw new Error('`recipient` is required.')
275
+
276
+ const portalAddress = getPortalAddress(chainId, parameters.zoneId)
277
+
278
+ const [publicKey, keyIndex] = await Promise.all([
279
+ readContract(client, {
280
+ address: portalAddress,
281
+ abi: ZoneAbis.zonePortal,
282
+ functionName: 'sequencerEncryptionKey',
283
+ }),
284
+ readContract(client, {
285
+ address: portalAddress,
286
+ abi: ZoneAbis.zonePortal,
287
+ functionName: 'encryptionKeyCount',
288
+ }),
289
+ ])
290
+
291
+ if (keyIndex === 0n) {
292
+ throw new Error('No sequencer encryption key configured.')
293
+ }
294
+
295
+ const encrypted = await encryptDepositPayload(
296
+ { x: publicKey[0], yParity: publicKey[1] },
297
+ recipient,
298
+ parameters.memo,
299
+ )
300
+
301
+ const args = {
302
+ ...parameters,
303
+ chainId,
304
+ encrypted,
305
+ keyIndex: keyIndex - 1n,
306
+ recipient,
307
+ }
308
+ return sendTransaction(client, {
309
+ ...rest,
310
+ calls: encryptedDeposit.calls(args),
311
+ } as never) as never
312
+ }
313
+
314
+ export namespace encryptedDeposit {
315
+ export type Parameters<
316
+ chain extends Chain | undefined = Chain | undefined,
317
+ account extends Account | undefined = Account | undefined,
318
+ > = WriteParameters<chain, account> &
319
+ Omit<Args, 'chainId' | 'encrypted' | 'keyIndex' | 'recipient'> & {
320
+ /** Recipient address in the zone. @default `account.address` */
321
+ recipient?: Address | undefined
322
+ }
323
+
324
+ export type Args = {
325
+ /** Amount of tokens to deposit. */
326
+ amount: bigint
327
+ /** Parent chain ID (e.g. `42431` for moderato). */
328
+ chainId: number
329
+ /** Encrypted deposit payload. */
330
+ encrypted: EncryptedPayload
331
+ /** Encryption key index from the portal contract. */
332
+ keyIndex: bigint
333
+ /** Optional deposit memo. @default `0x00...00` */
334
+ memo?: Hex.Hex | undefined
335
+ /** Recipient address in the zone. */
336
+ recipient: Address
337
+ /** Token address or ID to deposit. */
338
+ token: TokenId.TokenIdOrAddress
339
+ /** Zone ID (e.g. `7`). */
340
+ zoneId: number
341
+ }
342
+
343
+ export type ReturnValue = SendTransactionReturnType
344
+
345
+ // TODO: exhaustive error type
346
+ export type ErrorType = BaseErrorType
347
+
348
+ /**
349
+ * Defines the calls to approve and deposit tokens into a zone (encrypted).
350
+ *
351
+ * @param args - Arguments.
352
+ * @returns The calls.
353
+ */
354
+ export function calls(args: Args) {
355
+ const { amount, chainId, encrypted, keyIndex, token, zoneId } = args
356
+ const portalAddress = getPortalAddress(chainId, zoneId)
357
+ return [
358
+ defineCall({
359
+ address: TokenId.toAddress(token),
360
+ abi: Abis.tip20,
361
+ functionName: 'approve',
362
+ args: [portalAddress, amount],
363
+ }),
364
+ defineCall({
365
+ address: portalAddress,
366
+ abi: ZoneAbis.zonePortal,
367
+ functionName: 'depositEncrypted',
368
+ args: [
369
+ TokenId.toAddress(token),
370
+ amount,
371
+ keyIndex,
372
+ {
373
+ ephemeralPubkeyX: encrypted.ephemeralPubkeyX,
374
+ ephemeralPubkeyYParity: encrypted.ephemeralPubkeyYParity,
375
+ ciphertext: encrypted.ciphertext,
376
+ nonce: encrypted.nonce,
377
+ tag: encrypted.tag,
378
+ },
379
+ ],
380
+ }),
381
+ ]
382
+ }
383
+ }
384
+
385
+ /**
386
+ * Deposits tokens into a zone on the parent Tempo chain with encrypted
387
+ * recipient and memo, and waits for the transaction receipt.
388
+ *
389
+ * @example
390
+ * ```ts
391
+ * import { createClient, http } from 'viem'
392
+ * import { privateKeyToAccount } from 'viem/accounts'
393
+ * import { tempoModerato } from 'viem/chains'
394
+ * import { Actions } from 'viem/tempo'
395
+ *
396
+ * const client = createClient({
397
+ * account: privateKeyToAccount('0x...'),
398
+ * chain: tempoModerato,
399
+ * transport: http(),
400
+ * })
401
+ *
402
+ * const result = await Actions.zone.encryptedDepositSync(client, {
403
+ * token: '0x20c0...0001',
404
+ * amount: 1_000_000n,
405
+ * zoneId: 7,
406
+ * })
407
+ * ```
408
+ *
409
+ * @param client - Wallet client connected to the parent Tempo chain.
410
+ * @param parameters - Encrypted deposit parameters.
411
+ * @returns The transaction receipt.
412
+ */
413
+ export async function encryptedDepositSync<
414
+ chain extends Chain | undefined,
415
+ account extends Account | undefined,
416
+ >(
417
+ client: Client<Transport, chain, account>,
418
+ parameters: encryptedDepositSync.Parameters<chain, account>,
419
+ ): Promise<encryptedDepositSync.ReturnValue> {
420
+ const chainId = client.chain?.id
421
+ if (!chainId) throw new Error('`chain` is required.')
422
+
423
+ const {
424
+ account = client.account,
425
+ throwOnReceiptRevert = true,
426
+ ...rest
427
+ } = parameters
428
+
429
+ const account_ = account ? parseAccount(account) : undefined
430
+ if (!account) throw new Error('`account` is required.')
431
+
432
+ const recipient = parameters.recipient ?? account_?.address
433
+ if (!recipient) throw new Error('`recipient` is required.')
434
+
435
+ const portalAddress = getPortalAddress(chainId, parameters.zoneId)
436
+
437
+ const [publicKey, keyIndex] = await Promise.all([
438
+ readContract(client, {
439
+ address: portalAddress,
440
+ abi: ZoneAbis.zonePortal,
441
+ functionName: 'sequencerEncryptionKey',
442
+ }),
443
+ readContract(client, {
444
+ address: portalAddress,
445
+ abi: ZoneAbis.zonePortal,
446
+ functionName: 'encryptionKeyCount',
447
+ }),
448
+ ])
449
+
450
+ if (keyIndex === 0n) {
451
+ throw new Error('No sequencer encryption key configured.')
452
+ }
453
+
454
+ const encrypted = await encryptDepositPayload(
455
+ { x: publicKey[0], yParity: publicKey[1] },
456
+ recipient,
457
+ parameters.memo,
458
+ )
459
+
460
+ const args = {
461
+ ...parameters,
462
+ chainId,
463
+ encrypted,
464
+ keyIndex: keyIndex - 1n,
465
+ recipient,
466
+ }
467
+ const receipt = await sendTransactionSync(client, {
468
+ ...rest,
469
+ throwOnReceiptRevert,
470
+ calls: encryptedDeposit.calls(args),
471
+ } as never)
472
+ return { receipt }
473
+ }
474
+
475
+ export namespace encryptedDepositSync {
476
+ export type Parameters<
477
+ chain extends Chain | undefined = Chain | undefined,
478
+ account extends Account | undefined = Account | undefined,
479
+ > = encryptedDeposit.Parameters<chain, account>
480
+
481
+ export type Args = encryptedDeposit.Args
482
+
483
+ export type ReturnValue = Compute<{
484
+ /** Transaction receipt. */
485
+ receipt: TransactionReceipt
486
+ }>
487
+
488
+ // TODO: exhaustive error type
489
+ export type ErrorType = BaseErrorType
490
+ }
491
+
492
+ /**
493
+ * Returns the authenticated account address and authorization token expiry.
494
+ *
495
+ * @example
496
+ * ```ts
497
+ * import { createClient } from 'viem'
498
+ * import { http, zoneModerato } from 'viem/tempo/zones'
499
+ * import { Actions } from 'viem/tempo'
500
+ *
501
+ * const client = createClient({
502
+ * chain: zoneModerato(7),
503
+ * transport: http(),
504
+ * })
505
+ *
506
+ * const info = await Actions.zone.getAuthorizationTokenInfo(client)
507
+ * ```
508
+ *
509
+ * @param client - Zone client.
510
+ * @returns Authorization token info.
511
+ */
512
+ export async function getAuthorizationTokenInfo<
513
+ chain extends Chain | undefined,
514
+ account extends Account | undefined,
515
+ >(
516
+ client: Client<Transport, chain, account>,
517
+ ): Promise<getAuthorizationTokenInfo.ReturnType> {
518
+ const info = await client.request<{
519
+ Method: 'zone_getAuthorizationTokenInfo'
520
+ Parameters: []
521
+ ReturnType: getAuthorizationTokenInfo.RpcReturnType
522
+ }>({
523
+ method: 'zone_getAuthorizationTokenInfo',
524
+ params: [],
525
+ })
526
+
527
+ return {
528
+ account: info.account,
529
+ expiresAt: Hex.toBigInt(info.expiresAt),
530
+ }
531
+ }
532
+
533
+ export namespace getAuthorizationTokenInfo {
534
+ export type RpcReturnType = {
535
+ account: Address
536
+ expiresAt: Hex.Hex
537
+ }
538
+
539
+ export type ReturnType = {
540
+ account: Address
541
+ expiresAt: bigint
542
+ }
543
+
544
+ export type ErrorType = RequestErrorType | BaseErrorType
545
+ }
546
+
547
+ /**
548
+ * Returns deposit processing status for a given Tempo block number.
549
+ *
550
+ * @example
551
+ * ```ts
552
+ * import { createClient } from 'viem'
553
+ * import { http, zoneModerato } from 'viem/tempo/zones'
554
+ * import { Actions } from 'viem/tempo'
555
+ *
556
+ * const client = createClient({
557
+ * chain: zoneModerato(7),
558
+ * transport: http(),
559
+ * })
560
+ *
561
+ * const status = await Actions.zone.getDepositStatus(client, {
562
+ * tempoBlockNumber: 42n,
563
+ * })
564
+ * ```
565
+ *
566
+ * @param client - Zone client.
567
+ * @param parameters - Parameters including the Tempo block number.
568
+ * @returns Deposit status.
569
+ */
570
+ export async function getDepositStatus<
571
+ chain extends Chain | undefined,
572
+ account extends Account | undefined,
573
+ >(
574
+ client: Client<Transport, chain, account>,
575
+ parameters: getDepositStatus.Parameters,
576
+ ): Promise<getDepositStatus.ReturnType> {
577
+ const { tempoBlockNumber } = parameters
578
+ const status = await client.request<{
579
+ Method: 'zone_getDepositStatus'
580
+ Parameters: [Hex.Hex]
581
+ ReturnType: getDepositStatus.RpcReturnType
582
+ }>({
583
+ method: 'zone_getDepositStatus',
584
+ params: [Hex.fromNumber(tempoBlockNumber)],
585
+ })
586
+
587
+ return {
588
+ deposits: status.deposits.map((deposit) => ({
589
+ amount: Hex.toBigInt(deposit.amount),
590
+ depositHash: deposit.depositHash,
591
+ kind: deposit.kind,
592
+ memo: deposit.memo,
593
+ recipient: deposit.recipient,
594
+ sender: deposit.sender,
595
+ status: deposit.status,
596
+ token: deposit.token,
597
+ })),
598
+ processed: status.processed,
599
+ tempoBlockNumber: Hex.toBigInt(status.tempoBlockNumber),
600
+ zoneProcessedThrough: Hex.toBigInt(status.zoneProcessedThrough),
601
+ }
602
+ }
603
+
604
+ export namespace getDepositStatus {
605
+ export type DepositStatus = 'failed' | 'pending' | 'processed'
606
+ export type DepositKind = 'encrypted' | 'regular'
607
+
608
+ export type DepositRpc = {
609
+ amount: Hex.Hex
610
+ depositHash: Hex.Hex
611
+ kind: DepositKind
612
+ memo: Hex.Hex | null
613
+ recipient: Address | null
614
+ sender: Address
615
+ status: DepositStatus
616
+ token: Address
617
+ }
618
+
619
+ export type Deposit = {
620
+ amount: bigint
621
+ depositHash: Hex.Hex
622
+ kind: DepositKind
623
+ memo: Hex.Hex | null
624
+ recipient: Address | null
625
+ sender: Address
626
+ status: DepositStatus
627
+ token: Address
628
+ }
629
+
630
+ export type RpcReturnType = {
631
+ deposits: readonly DepositRpc[]
632
+ processed: boolean
633
+ tempoBlockNumber: Hex.Hex
634
+ zoneProcessedThrough: Hex.Hex
635
+ }
636
+
637
+ export type Parameters = {
638
+ tempoBlockNumber: bigint
639
+ }
640
+
641
+ export type ReturnType = {
642
+ deposits: readonly Deposit[]
643
+ processed: boolean
644
+ tempoBlockNumber: bigint
645
+ zoneProcessedThrough: bigint
646
+ }
647
+
648
+ export type ErrorType = RequestErrorType | BaseErrorType
649
+ }
650
+
651
+ /**
652
+ * Returns the fee required for a withdrawal from a zone, given a gas limit.
653
+ *
654
+ * The client must be connected to the **zone chain**.
655
+ *
656
+ * @example
657
+ * ```ts
658
+ * import { createClient } from 'viem'
659
+ * import { http, zoneModerato } from 'viem/tempo/zones'
660
+ * import { Actions } from 'viem/tempo'
661
+ *
662
+ * const client = createClient({
663
+ * chain: zoneModerato(7),
664
+ * transport: http(),
665
+ * })
666
+ *
667
+ * const fee = await Actions.zone.getWithdrawalFee(client)
668
+ * ```
669
+ *
670
+ * @param client - Zone client.
671
+ * @param parameters - Optional gas limit parameter.
672
+ * @returns The withdrawal fee as a bigint.
673
+ */
674
+ export async function getWithdrawalFee<
675
+ chain extends Chain | undefined,
676
+ account extends Account | undefined,
677
+ >(
678
+ client: Client<Transport, chain, account>,
679
+ parameters: getWithdrawalFee.Parameters = {},
680
+ ): Promise<getWithdrawalFee.ReturnType> {
681
+ const { gas = 0n, ...rest } = parameters
682
+ return readContract(client, {
683
+ ...rest,
684
+ address: Addresses.zoneOutbox,
685
+ abi: ZoneAbis.zoneOutbox,
686
+ functionName: 'calculateWithdrawalFee',
687
+ args: [gas],
688
+ })
689
+ }
690
+
691
+ export namespace getWithdrawalFee {
692
+ export type Parameters = ReadParameters & {
693
+ /** Gas limit for the withdrawal callback. @default `0n` */
694
+ gas?: bigint | undefined
695
+ }
696
+
697
+ export type ReturnType = bigint
698
+
699
+ export type ErrorType = RequestErrorType | BaseErrorType
700
+ }
701
+
702
+ /**
703
+ * Returns the current zone metadata.
704
+ *
705
+ * @example
706
+ * ```ts
707
+ * import { createClient } from 'viem'
708
+ * import { http, zoneModerato } from 'viem/tempo/zones'
709
+ * import { Actions } from 'viem/tempo'
710
+ *
711
+ * const client = createClient({
712
+ * chain: zoneModerato(7),
713
+ * transport: http(),
714
+ * })
715
+ *
716
+ * const info = await Actions.zone.getZoneInfo(client)
717
+ * ```
718
+ *
719
+ * @param client - Zone client.
720
+ * @returns Zone metadata.
721
+ */
722
+ export async function getZoneInfo<
723
+ chain extends Chain | undefined,
724
+ account extends Account | undefined,
725
+ >(client: Client<Transport, chain, account>): Promise<getZoneInfo.ReturnType> {
726
+ const info = await client.request<{
727
+ Method: 'zone_getZoneInfo'
728
+ Parameters: []
729
+ ReturnType: getZoneInfo.RpcReturnType
730
+ }>({
731
+ method: 'zone_getZoneInfo',
732
+ params: [],
733
+ })
734
+
735
+ return {
736
+ chainId: Hex.toNumber(info.chainId),
737
+ sequencer: info.sequencer,
738
+ zoneId: Hex.toNumber(info.zoneId),
739
+ zoneTokens: info.zoneTokens,
740
+ }
741
+ }
742
+
743
+ export namespace getZoneInfo {
744
+ export type RpcReturnType = {
745
+ chainId: Hex.Hex
746
+ sequencer: Address
747
+ zoneId: Hex.Hex
748
+ zoneTokens: readonly Address[]
749
+ }
750
+
751
+ export type ReturnType = {
752
+ chainId: number
753
+ sequencer: Address
754
+ zoneId: number
755
+ zoneTokens: readonly Address[]
756
+ }
757
+
758
+ export type ErrorType = RequestErrorType | BaseErrorType
759
+ }
760
+
761
+ /**
762
+ * Requests a withdrawal from a zone to the parent Tempo chain via the
763
+ * ZoneOutbox contract.
764
+ *
765
+ * The client must be connected to the **zone chain**.
766
+ *
767
+ * @example
768
+ * ```ts
769
+ * import { createClient } from 'viem'
770
+ * import { privateKeyToAccount } from 'viem/accounts'
771
+ * import { http, zoneModerato } from 'viem/tempo/zones'
772
+ * import { Actions } from 'viem/tempo'
773
+ *
774
+ * const client = createClient({
775
+ * account: privateKeyToAccount('0x...'),
776
+ * chain: zoneModerato(7),
777
+ * transport: http(),
778
+ * })
779
+ *
780
+ * const hash = await Actions.zone.requestWithdrawal(client, {
781
+ * token: '0x20c0...0001',
782
+ * amount: 1_000_000n,
783
+ * })
784
+ * ```
785
+ *
786
+ * @param client - Wallet client connected to the zone chain.
787
+ * @param parameters - Withdrawal parameters.
788
+ * @returns The transaction hash.
789
+ */
790
+ export async function requestWithdrawal<
791
+ chain extends Chain | undefined,
792
+ account extends Account | undefined,
793
+ >(
794
+ client: Client<Transport, chain, account>,
795
+ parameters: requestWithdrawal.Parameters<chain, account>,
796
+ ): Promise<requestWithdrawal.ReturnValue> {
797
+ const { account = client.account, ...rest } = parameters
798
+
799
+ const account_ = account ? parseAccount(account) : undefined
800
+ if (!account) throw new Error('`account` is required.')
801
+
802
+ const to = parameters.to ?? account_?.address
803
+ if (!to) throw new Error('`to` is required.')
804
+
805
+ const args = { ...parameters, to }
806
+ return sendTransaction(client, {
807
+ ...rest,
808
+ calls: requestWithdrawal.calls(args),
809
+ } as never) as never
810
+ }
811
+
812
+ export namespace requestWithdrawal {
813
+ export type Parameters<
814
+ chain extends Chain | undefined = Chain | undefined,
815
+ account extends Account | undefined = Account | undefined,
816
+ > = WriteParameters<chain, account> &
817
+ Omit<Args, 'to'> & {
818
+ /** Recipient address on the parent Tempo chain. @default `account.address` */
819
+ to?: Address | undefined
820
+ }
821
+
822
+ export type Args = {
823
+ /** Amount of tokens to withdraw. */
824
+ amount: bigint
825
+ /** Optional callback data for the recipient. @default `'0x'` */
826
+ data?: Hex.Hex | undefined
827
+ /** Fallback address if callback fails. @default `to` */
828
+ fallbackRecipient?: Address | undefined
829
+ /** Gas limit reserved for the withdrawal callback on the parent chain. @default `0n` */
830
+ gas?: bigint | undefined
831
+ /** Optional withdrawal memo. @default `0x00...00` */
832
+ memo?: Hex.Hex | undefined
833
+ /** Recipient address on the parent Tempo chain. */
834
+ to: Address
835
+ /** Token address or ID to withdraw. */
836
+ token: TokenId.TokenIdOrAddress
837
+ }
838
+
839
+ export type ReturnValue = SendTransactionReturnType
840
+
841
+ // TODO: exhaustive error type
842
+ export type ErrorType = BaseErrorType
843
+
844
+ /**
845
+ * Defines the calls to approve and request a withdrawal from a zone.
846
+ *
847
+ * @param args - Arguments.
848
+ * @returns The calls.
849
+ */
850
+ export function calls(args: Args) {
851
+ const {
852
+ amount,
853
+ data = '0x',
854
+ fallbackRecipient = args.to,
855
+ gas = 0n,
856
+ memo = zeroHash,
857
+ to,
858
+ token,
859
+ } = args
860
+ return [
861
+ defineCall({
862
+ address: TokenId.toAddress(token),
863
+ abi: Abis.tip20,
864
+ functionName: 'approve',
865
+ args: [Addresses.zoneOutbox, amount],
866
+ }),
867
+ defineCall({
868
+ address: Addresses.zoneOutbox,
869
+ abi: ZoneAbis.zoneOutbox,
870
+ functionName: 'requestWithdrawal',
871
+ args: [
872
+ TokenId.toAddress(token),
873
+ to,
874
+ amount,
875
+ memo,
876
+ gas,
877
+ fallbackRecipient,
878
+ data,
879
+ '0x',
880
+ ],
881
+ }),
882
+ ]
883
+ }
884
+ }
885
+
886
+ /**
887
+ * Requests a withdrawal from a zone to the parent Tempo chain and waits for
888
+ * the transaction receipt.
889
+ *
890
+ * @example
891
+ * ```ts
892
+ * import { createClient } from 'viem'
893
+ * import { privateKeyToAccount } from 'viem/accounts'
894
+ * import { http, zoneModerato } from 'viem/tempo/zones'
895
+ * import { Actions } from 'viem/tempo'
896
+ *
897
+ * const client = createClient({
898
+ * account: privateKeyToAccount('0x...'),
899
+ * chain: zoneModerato(7),
900
+ * transport: http(),
901
+ * })
902
+ *
903
+ * const result = await Actions.zone.requestWithdrawalSync(client, {
904
+ * token: '0x20c0...0001',
905
+ * amount: 1_000_000n,
906
+ * })
907
+ * ```
908
+ *
909
+ * @param client - Wallet client connected to the zone chain.
910
+ * @param parameters - Withdrawal parameters.
911
+ * @returns The transaction receipt.
912
+ */
913
+ export async function requestWithdrawalSync<
914
+ chain extends Chain | undefined,
915
+ account extends Account | undefined,
916
+ >(
917
+ client: Client<Transport, chain, account>,
918
+ parameters: requestWithdrawalSync.Parameters<chain, account>,
919
+ ): Promise<requestWithdrawalSync.ReturnValue> {
920
+ const {
921
+ account = client.account,
922
+ throwOnReceiptRevert = true,
923
+ ...rest
924
+ } = parameters
925
+
926
+ const account_ = account ? parseAccount(account) : undefined
927
+ if (!account) throw new Error('`account` is required.')
928
+
929
+ const to = parameters.to ?? account_?.address
930
+ if (!to) throw new Error('`to` is required.')
931
+
932
+ const args = { ...parameters, to }
933
+ const receipt = await sendTransactionSync(client, {
934
+ ...rest,
935
+ calls: requestWithdrawal.calls(args),
936
+ throwOnReceiptRevert,
937
+ } as never)
938
+ return { receipt }
939
+ }
940
+
941
+ export namespace requestWithdrawalSync {
942
+ export type Parameters<
943
+ chain extends Chain | undefined = Chain | undefined,
944
+ account extends Account | undefined = Account | undefined,
945
+ > = requestWithdrawal.Parameters<chain, account>
946
+
947
+ export type Args = requestWithdrawal.Args
948
+
949
+ export type ReturnValue = Compute<{
950
+ /** Transaction receipt. */
951
+ receipt: TransactionReceipt
952
+ }>
953
+
954
+ // TODO: exhaustive error type
955
+ export type ErrorType = BaseErrorType
956
+ }
957
+
958
+ /**
959
+ * Requests a verifiable withdrawal from a zone to the parent Tempo chain via
960
+ * the ZoneOutbox contract. Includes a `revealTo` public key so the sequencer
961
+ * can encrypt the withdrawal details.
962
+ *
963
+ * The client must be connected to the **zone chain**.
964
+ *
965
+ * @example
966
+ * ```ts
967
+ * import { createClient } from 'viem'
968
+ * import { privateKeyToAccount } from 'viem/accounts'
969
+ * import { http, zoneModerato } from 'viem/tempo/zones'
970
+ * import { Actions } from 'viem/tempo'
971
+ *
972
+ * const client = createClient({
973
+ * account: privateKeyToAccount('0x...'),
974
+ * chain: zoneModerato(7),
975
+ * transport: http(),
976
+ * })
977
+ *
978
+ * const hash = await Actions.zone.requestVerifiableWithdrawal(client, {
979
+ * token: '0x20c0...0001',
980
+ * amount: 1_000_000n,
981
+ * revealTo: '0x02abc...def',
982
+ * })
983
+ * ```
984
+ *
985
+ * @param client - Wallet client connected to the zone chain.
986
+ * @param parameters - Verifiable withdrawal parameters.
987
+ * @returns The transaction hash.
988
+ */
989
+ export async function requestVerifiableWithdrawal<
990
+ chain extends Chain | undefined,
991
+ account extends Account | undefined,
992
+ >(
993
+ client: Client<Transport, chain, account>,
994
+ parameters: requestVerifiableWithdrawal.Parameters<chain, account>,
995
+ ): Promise<requestVerifiableWithdrawal.ReturnValue> {
996
+ const { account = client.account, ...rest } = parameters
997
+
998
+ const account_ = account ? parseAccount(account) : undefined
999
+ if (!account) throw new Error('`account` is required.')
1000
+
1001
+ const to = parameters.to ?? account_?.address
1002
+ if (!to) throw new Error('`to` is required.')
1003
+
1004
+ const args = { ...parameters, to }
1005
+ return sendTransaction(client, {
1006
+ ...rest,
1007
+ calls: requestVerifiableWithdrawal.calls(args),
1008
+ } as never) as never
1009
+ }
1010
+
1011
+ export namespace requestVerifiableWithdrawal {
1012
+ export type Parameters<
1013
+ chain extends Chain | undefined = Chain | undefined,
1014
+ account extends Account | undefined = Account | undefined,
1015
+ > = WriteParameters<chain, account> &
1016
+ Omit<Args, 'to'> & {
1017
+ /** Recipient address on the parent Tempo chain. @default `account.address` */
1018
+ to?: Address | undefined
1019
+ }
1020
+
1021
+ export type Args = requestWithdrawal.Args & {
1022
+ /** 33-byte compressed secp256k1 public key for encrypted reveal. */
1023
+ revealTo: Hex.Hex
1024
+ }
1025
+
1026
+ export type ReturnValue = SendTransactionReturnType
1027
+
1028
+ // TODO: exhaustive error type
1029
+ export type ErrorType = BaseErrorType
1030
+
1031
+ /**
1032
+ * Defines the calls to approve and request a verifiable withdrawal from a zone.
1033
+ *
1034
+ * @param args - Arguments.
1035
+ * @returns The calls.
1036
+ */
1037
+ export function calls(args: Args) {
1038
+ const {
1039
+ amount,
1040
+ data = '0x',
1041
+ fallbackRecipient = args.to,
1042
+ gas = 0n,
1043
+ memo = zeroHash,
1044
+ revealTo,
1045
+ to,
1046
+ token,
1047
+ } = args
1048
+ return [
1049
+ defineCall({
1050
+ address: TokenId.toAddress(token),
1051
+ abi: Abis.tip20,
1052
+ functionName: 'approve',
1053
+ args: [Addresses.zoneOutbox, amount],
1054
+ }),
1055
+ defineCall({
1056
+ address: Addresses.zoneOutbox,
1057
+ abi: ZoneAbis.zoneOutbox,
1058
+ functionName: 'requestWithdrawal',
1059
+ args: [
1060
+ TokenId.toAddress(token),
1061
+ to,
1062
+ amount,
1063
+ memo,
1064
+ gas,
1065
+ fallbackRecipient,
1066
+ data,
1067
+ revealTo,
1068
+ ],
1069
+ }),
1070
+ ]
1071
+ }
1072
+ }
1073
+
1074
+ /**
1075
+ * Requests a verifiable withdrawal from a zone to the parent Tempo chain and
1076
+ * waits for the transaction receipt.
1077
+ *
1078
+ * @example
1079
+ * ```ts
1080
+ * import { createClient } from 'viem'
1081
+ * import { privateKeyToAccount } from 'viem/accounts'
1082
+ * import { http, zoneModerato } from 'viem/tempo/zones'
1083
+ * import { Actions } from 'viem/tempo'
1084
+ *
1085
+ * const client = createClient({
1086
+ * account: privateKeyToAccount('0x...'),
1087
+ * chain: zoneModerato(7),
1088
+ * transport: http(),
1089
+ * })
1090
+ *
1091
+ * const result = await Actions.zone.requestVerifiableWithdrawalSync(client, {
1092
+ * token: '0x20c0...0001',
1093
+ * amount: 1_000_000n,
1094
+ * revealTo: '0x02abc...def',
1095
+ * })
1096
+ * ```
1097
+ *
1098
+ * @param client - Wallet client connected to the zone chain.
1099
+ * @param parameters - Verifiable withdrawal parameters.
1100
+ * @returns The transaction receipt.
1101
+ */
1102
+ export async function requestVerifiableWithdrawalSync<
1103
+ chain extends Chain | undefined,
1104
+ account extends Account | undefined,
1105
+ >(
1106
+ client: Client<Transport, chain, account>,
1107
+ parameters: requestVerifiableWithdrawalSync.Parameters<chain, account>,
1108
+ ): Promise<requestVerifiableWithdrawalSync.ReturnValue> {
1109
+ const {
1110
+ account = client.account,
1111
+ throwOnReceiptRevert = true,
1112
+ ...rest
1113
+ } = parameters
1114
+
1115
+ const account_ = account ? parseAccount(account) : undefined
1116
+ if (!account) throw new Error('`account` is required.')
1117
+
1118
+ const to = parameters.to ?? account_?.address
1119
+ if (!to) throw new Error('`to` is required.')
1120
+
1121
+ const args = { ...parameters, to }
1122
+ const receipt = await sendTransactionSync(client, {
1123
+ ...rest,
1124
+ calls: requestVerifiableWithdrawal.calls(args),
1125
+ throwOnReceiptRevert,
1126
+ } as never)
1127
+ return { receipt }
1128
+ }
1129
+
1130
+ export namespace requestVerifiableWithdrawalSync {
1131
+ export type Parameters<
1132
+ chain extends Chain | undefined = Chain | undefined,
1133
+ account extends Account | undefined = Account | undefined,
1134
+ > = requestVerifiableWithdrawal.Parameters<chain, account>
1135
+
1136
+ export type Args = requestVerifiableWithdrawal.Args
1137
+
1138
+ export type ReturnValue = Compute<{
1139
+ /** Transaction receipt. */
1140
+ receipt: TransactionReceipt
1141
+ }>
1142
+
1143
+ // TODO: exhaustive error type
1144
+ export type ErrorType = BaseErrorType
1145
+ }
1146
+
1147
+ /**
1148
+ * Signs a zone authorization token and stores it for the zone HTTP transport.
1149
+ *
1150
+ * Zone chains should define `contracts.zonePortal` with the portal address.
1151
+ * The `zoneId` is derived from `ZoneId.fromChainId(chain.id)` and can be overridden.
1152
+ *
1153
+ * @example
1154
+ * ```ts
1155
+ * import { createClient } from 'viem'
1156
+ * import { privateKeyToAccount } from 'viem/accounts'
1157
+ * import { http, zoneModerato } from 'viem/tempo/zones'
1158
+ * import { Actions } from 'viem/tempo'
1159
+ *
1160
+ * const client = createClient({
1161
+ * account: privateKeyToAccount('0x...'),
1162
+ * chain: zoneModerato(7),
1163
+ * transport: http(),
1164
+ * })
1165
+ *
1166
+ * const result = await Actions.zone.signAuthorizationToken(client)
1167
+ * ```
1168
+ *
1169
+ * @param client - Zone wallet client.
1170
+ * @param parameters - Options including optional storage override.
1171
+ * @returns The authentication object and serialized token.
1172
+ */
1173
+ export async function signAuthorizationToken<
1174
+ chain extends Chain | undefined,
1175
+ account extends Account | undefined,
1176
+ accountOverride extends Account | Address | undefined = undefined,
1177
+ >(
1178
+ client: Client<Transport, chain, account>,
1179
+ parameters: signAuthorizationToken.Parameters<
1180
+ account,
1181
+ accountOverride
1182
+ > = {} as any,
1183
+ ): Promise<signAuthorizationToken.ReturnType> {
1184
+ const {
1185
+ account = client.account,
1186
+ issuedAt = Math.floor(Date.now() / 1000),
1187
+ expiresAt = issuedAt + 86_400,
1188
+ storage = Storage.defaultStorage(),
1189
+ } = parameters
1190
+
1191
+ const chain = parameters.chain ?? client.chain
1192
+ if (!chain) throw new Error('`signAuthorizationToken` requires a chain.')
1193
+
1194
+ const account_ = account ? parseAccount(account) : undefined
1195
+ if (!account_ || !account_.sign)
1196
+ throw new Error('`account` with `sign` is required.')
1197
+
1198
+ const storageKey = `auth:${account_.address.toLowerCase()}:${chain.id}`
1199
+
1200
+ const authentication = ZoneRpcAuthentication.from({
1201
+ chainId: chain.id,
1202
+ expiresAt,
1203
+ issuedAt,
1204
+ zoneId: ZoneId.fromChainId(chain.id),
1205
+ })
1206
+
1207
+ const payload = ZoneRpcAuthentication.getSignPayload(authentication)
1208
+ const signature = await account_.sign({ hash: payload })
1209
+
1210
+ const token = ZoneRpcAuthentication.serialize(authentication, {
1211
+ signature,
1212
+ })
1213
+
1214
+ await storage.setItem(storageKey, token)
1215
+ await storage.setItem(`auth:token:${chain.id}`, token)
1216
+
1217
+ return { authentication, token }
1218
+ }
1219
+
1220
+ export namespace signAuthorizationToken {
1221
+ export type Parameters<
1222
+ account extends Account | undefined = Account | undefined,
1223
+ accountOverride extends Account | Address | undefined =
1224
+ | Account
1225
+ | Address
1226
+ | undefined,
1227
+ > = GetAccountParameter<account, accountOverride> & {
1228
+ /** Chain override. @default `client.chain`. */
1229
+ chain?: Chain | undefined
1230
+ /** Token expiry as a unix timestamp (seconds). @default `issuedAt + 86_400`. */
1231
+ expiresAt?: number | undefined
1232
+ /** Token issue time as a unix timestamp (seconds). @default `Date.now() / 1000`. */
1233
+ issuedAt?: number | undefined
1234
+ /** Storage to persist the token. @default sessionStorage (web) or memory (server). */
1235
+ storage?: Storage.Storage | undefined
1236
+ }
1237
+
1238
+ export type ReturnType = {
1239
+ authentication: ZoneRpcAuthentication.ZoneRpcAuthentication
1240
+ token: Hex.Hex
1241
+ }
1242
+
1243
+ export type ErrorType = BaseErrorType
1244
+ }
1245
+
1246
+ /**
1247
+ * Encrypts a deposit payload (recipient + memo) using ECIES with AES-256-GCM.
1248
+ *
1249
+ * @internal
1250
+ */
1251
+ async function encryptDepositPayload(
1252
+ publicKey: { x: Hex.Hex; yParity: number },
1253
+ recipient: Address,
1254
+ memo: Hex.Hex = zeroHash,
1255
+ ): Promise<EncryptedPayload> {
1256
+ const sequencerPublicKey = PublicKey.from({
1257
+ prefix: publicKey.yParity,
1258
+ x: Hex.toBigInt(publicKey.x),
1259
+ })
1260
+
1261
+ const { privateKey: ephemeralPrivateKey, publicKey: ephemeralPublicKey } =
1262
+ Secp256k1.createKeyPair()
1263
+
1264
+ const sharedSecret = Secp256k1.getSharedSecret({
1265
+ privateKey: ephemeralPrivateKey,
1266
+ publicKey: sequencerPublicKey,
1267
+ as: 'Bytes',
1268
+ })
1269
+
1270
+ const hkdfKey = await globalThis.crypto.subtle.importKey(
1271
+ 'raw',
1272
+ sharedSecret.buffer as ArrayBuffer,
1273
+ 'HKDF',
1274
+ false,
1275
+ ['deriveKey'],
1276
+ )
1277
+ const aesKey = await globalThis.crypto.subtle.deriveKey(
1278
+ {
1279
+ name: 'HKDF',
1280
+ hash: 'SHA-256',
1281
+ salt: new Uint8Array(12),
1282
+ info: new TextEncoder().encode('ecies-aes-key'),
1283
+ },
1284
+ hkdfKey,
1285
+ { name: 'AES-GCM', length: 256 },
1286
+ false,
1287
+ ['encrypt'],
1288
+ )
1289
+
1290
+ const nonce = Bytes.random(12)
1291
+
1292
+ const plaintext = encodeAbiParameters(
1293
+ [{ type: 'address' }, { type: 'bytes32' }],
1294
+ [recipient, memo],
1295
+ )
1296
+
1297
+ const ciphertextWithTag = new Uint8Array(
1298
+ await globalThis.crypto.subtle.encrypt(
1299
+ { name: 'AES-GCM', iv: nonce as BufferSource, tagLength: 128 },
1300
+ aesKey,
1301
+ Bytes.from(plaintext) as BufferSource,
1302
+ ),
1303
+ )
1304
+
1305
+ const ciphertext = ciphertextWithTag.slice(0, -16)
1306
+ const tag = ciphertextWithTag.slice(-16)
1307
+
1308
+ const compressedEphemeral = PublicKey.compress(ephemeralPublicKey)
1309
+
1310
+ return {
1311
+ ciphertext: Hex.fromBytes(ciphertext),
1312
+ ephemeralPubkeyX: Hex.fromNumber(compressedEphemeral.x, { size: 32 }),
1313
+ ephemeralPubkeyYParity: compressedEphemeral.prefix,
1314
+ nonce: Hex.fromBytes(nonce),
1315
+ tag: Hex.fromBytes(tag),
1316
+ }
1317
+ }