viem 2.53.1 → 2.54.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 (471) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/_cjs/actions/index.js +3 -2
  3. package/_cjs/actions/index.js.map +1 -1
  4. package/_cjs/actions/token/approve.js +62 -0
  5. package/_cjs/actions/token/approve.js.map +1 -0
  6. package/_cjs/actions/token/approveSync.js +25 -0
  7. package/_cjs/actions/token/approveSync.js.map +1 -0
  8. package/_cjs/actions/token/getAllowance.js +32 -0
  9. package/_cjs/actions/token/getAllowance.js.map +1 -0
  10. package/_cjs/actions/token/getBalance.js +41 -0
  11. package/_cjs/actions/token/getBalance.js.map +1 -0
  12. package/_cjs/actions/token/getMetadata.js +40 -0
  13. package/_cjs/actions/token/getMetadata.js.map +1 -0
  14. package/_cjs/actions/token/getTotalSupply.js +32 -0
  15. package/_cjs/actions/token/getTotalSupply.js.map +1 -0
  16. package/_cjs/actions/token/index.js +20 -0
  17. package/_cjs/actions/token/index.js.map +1 -0
  18. package/_cjs/actions/token/internal.js +125 -0
  19. package/_cjs/actions/token/internal.js.map +1 -0
  20. package/_cjs/actions/token/transfer.js +70 -0
  21. package/_cjs/actions/token/transfer.js.map +1 -0
  22. package/_cjs/actions/token/transferSync.js +25 -0
  23. package/_cjs/actions/token/transferSync.js.map +1 -0
  24. package/_cjs/chains/definitions/battlechain.js +31 -0
  25. package/_cjs/chains/definitions/battlechain.js.map +1 -0
  26. package/_cjs/chains/definitions/marooTestnet.js +30 -0
  27. package/_cjs/chains/definitions/marooTestnet.js.map +1 -0
  28. package/_cjs/chains/index.js +18 -14
  29. package/_cjs/chains/index.js.map +1 -1
  30. package/_cjs/clients/createClient.js +39 -1
  31. package/_cjs/clients/createClient.js.map +1 -1
  32. package/_cjs/clients/createPublicClient.js.map +1 -1
  33. package/_cjs/clients/createWalletClient.js.map +1 -1
  34. package/_cjs/clients/decorators/public.js +11 -0
  35. package/_cjs/clients/decorators/public.js.map +1 -1
  36. package/_cjs/clients/decorators/wallet.js +8 -0
  37. package/_cjs/clients/decorators/wallet.js.map +1 -1
  38. package/_cjs/clients/transports/http.js +2 -1
  39. package/_cjs/clients/transports/http.js.map +1 -1
  40. package/_cjs/errors/encoding.js +9 -1
  41. package/_cjs/errors/encoding.js.map +1 -1
  42. package/_cjs/errors/request.js +24 -1
  43. package/_cjs/errors/request.js.map +1 -1
  44. package/_cjs/errors/transaction.js +9 -1
  45. package/_cjs/errors/transaction.js.map +1 -1
  46. package/_cjs/errors/version.js +1 -1
  47. package/_cjs/index.js +9 -6
  48. package/_cjs/index.js.map +1 -1
  49. package/_cjs/tempo/Client.js +3 -1
  50. package/_cjs/tempo/Client.js.map +1 -1
  51. package/_cjs/tempo/Decorator.js +234 -215
  52. package/_cjs/tempo/Decorator.js.map +1 -1
  53. package/_cjs/tempo/actions/token.js +210 -112
  54. package/_cjs/tempo/actions/token.js.map +1 -1
  55. package/_cjs/tempo/internal/utils.js +108 -0
  56. package/_cjs/tempo/internal/utils.js.map +1 -1
  57. package/_cjs/tokens/defineToken.js +21 -0
  58. package/_cjs/tokens/defineToken.js.map +1 -0
  59. package/_cjs/tokens/definitions/alphausd.js +14 -0
  60. package/_cjs/tokens/definitions/alphausd.js.map +1 -0
  61. package/_cjs/tokens/definitions/betausd.js +14 -0
  62. package/_cjs/tokens/definitions/betausd.js.map +1 -0
  63. package/_cjs/tokens/definitions/brla.js +14 -0
  64. package/_cjs/tokens/definitions/brla.js.map +1 -0
  65. package/_cjs/tokens/definitions/cbbtc.js +14 -0
  66. package/_cjs/tokens/definitions/cbbtc.js.map +1 -0
  67. package/_cjs/tokens/definitions/chfau.js +14 -0
  68. package/_cjs/tokens/definitions/chfau.js.map +1 -0
  69. package/_cjs/tokens/definitions/cirbtc.js +16 -0
  70. package/_cjs/tokens/definitions/cirbtc.js.map +1 -0
  71. package/_cjs/tokens/definitions/cusd.js +14 -0
  72. package/_cjs/tokens/definitions/cusd.js.map +1 -0
  73. package/_cjs/tokens/definitions/dlusd.js +14 -0
  74. package/_cjs/tokens/definitions/dlusd.js.map +1 -0
  75. package/_cjs/tokens/definitions/eurau.js +14 -0
  76. package/_cjs/tokens/definitions/eurau.js.map +1 -0
  77. package/_cjs/tokens/definitions/eurc.js +24 -0
  78. package/_cjs/tokens/definitions/eurc.js.map +1 -0
  79. package/_cjs/tokens/definitions/eurce.js +15 -0
  80. package/_cjs/tokens/definitions/eurce.js.map +1 -0
  81. package/_cjs/tokens/definitions/frxusd.js +14 -0
  82. package/_cjs/tokens/definitions/frxusd.js.map +1 -0
  83. package/_cjs/tokens/definitions/gbpa.js +14 -0
  84. package/_cjs/tokens/definitions/gbpa.js.map +1 -0
  85. package/_cjs/tokens/definitions/gusd.js +14 -0
  86. package/_cjs/tokens/definitions/gusd.js.map +1 -0
  87. package/_cjs/tokens/definitions/iusd.js +14 -0
  88. package/_cjs/tokens/definitions/iusd.js.map +1 -0
  89. package/_cjs/tokens/definitions/pathusd.js +15 -0
  90. package/_cjs/tokens/definitions/pathusd.js.map +1 -0
  91. package/_cjs/tokens/definitions/reusd.js +14 -0
  92. package/_cjs/tokens/definitions/reusd.js.map +1 -0
  93. package/_cjs/tokens/definitions/rusd.js +14 -0
  94. package/_cjs/tokens/definitions/rusd.js.map +1 -0
  95. package/_cjs/tokens/definitions/sbc.js +14 -0
  96. package/_cjs/tokens/definitions/sbc.js.map +1 -0
  97. package/_cjs/tokens/definitions/siusd.js +14 -0
  98. package/_cjs/tokens/definitions/siusd.js.map +1 -0
  99. package/_cjs/tokens/definitions/stcusd.js +14 -0
  100. package/_cjs/tokens/definitions/stcusd.js.map +1 -0
  101. package/_cjs/tokens/definitions/susde.js +14 -0
  102. package/_cjs/tokens/definitions/susde.js.map +1 -0
  103. package/_cjs/tokens/definitions/syrupusdc.js +14 -0
  104. package/_cjs/tokens/definitions/syrupusdc.js.map +1 -0
  105. package/_cjs/tokens/definitions/thetausd.js +14 -0
  106. package/_cjs/tokens/definitions/thetausd.js.map +1 -0
  107. package/_cjs/tokens/definitions/usd1.js +14 -0
  108. package/_cjs/tokens/definitions/usd1.js.map +1 -0
  109. package/_cjs/tokens/definitions/usdb.js +14 -0
  110. package/_cjs/tokens/definitions/usdb.js.map +1 -0
  111. package/_cjs/tokens/definitions/usdc.js +59 -0
  112. package/_cjs/tokens/definitions/usdc.js.map +1 -0
  113. package/_cjs/tokens/definitions/usdce.js +15 -0
  114. package/_cjs/tokens/definitions/usdce.js.map +1 -0
  115. package/_cjs/tokens/definitions/usde.js +14 -0
  116. package/_cjs/tokens/definitions/usde.js.map +1 -0
  117. package/_cjs/tokens/definitions/usdt0.js +14 -0
  118. package/_cjs/tokens/definitions/usdt0.js.map +1 -0
  119. package/_cjs/tokens/definitions/usyc.js +18 -0
  120. package/_cjs/tokens/definitions/usyc.js.map +1 -0
  121. package/_cjs/tokens/definitions/wsrusd.js +14 -0
  122. package/_cjs/tokens/definitions/wsrusd.js.map +1 -0
  123. package/_cjs/tokens/index.js +72 -0
  124. package/_cjs/tokens/index.js.map +1 -0
  125. package/_cjs/tokens/sets.js +102 -0
  126. package/_cjs/tokens/sets.js.map +1 -0
  127. package/_cjs/utils/encoding/fromRlp.js +7 -4
  128. package/_cjs/utils/encoding/fromRlp.js.map +1 -1
  129. package/_cjs/utils/rpc/http.js +58 -3
  130. package/_cjs/utils/rpc/http.js.map +1 -1
  131. package/_cjs/utils/transaction/parseTransaction.js +4 -1
  132. package/_cjs/utils/transaction/parseTransaction.js.map +1 -1
  133. package/_esm/actions/index.js +1 -0
  134. package/_esm/actions/index.js.map +1 -1
  135. package/_esm/actions/token/approve.js +123 -0
  136. package/_esm/actions/token/approve.js.map +1 -0
  137. package/_esm/actions/token/approveSync.js +50 -0
  138. package/_esm/actions/token/approveSync.js.map +1 -0
  139. package/_esm/actions/token/getAllowance.js +62 -0
  140. package/_esm/actions/token/getAllowance.js.map +1 -0
  141. package/_esm/actions/token/getBalance.js +70 -0
  142. package/_esm/actions/token/getBalance.js.map +1 -0
  143. package/_esm/actions/token/getMetadata.js +60 -0
  144. package/_esm/actions/token/getMetadata.js.map +1 -0
  145. package/_esm/actions/token/getTotalSupply.js +60 -0
  146. package/_esm/actions/token/getTotalSupply.js.map +1 -0
  147. package/_esm/actions/token/index.js +10 -0
  148. package/_esm/actions/token/index.js.map +1 -0
  149. package/_esm/actions/token/internal.js +188 -0
  150. package/_esm/actions/token/internal.js.map +1 -0
  151. package/_esm/actions/token/transfer.js +147 -0
  152. package/_esm/actions/token/transfer.js.map +1 -0
  153. package/_esm/actions/token/transferSync.js +54 -0
  154. package/_esm/actions/token/transferSync.js.map +1 -0
  155. package/_esm/chains/definitions/battlechain.js +28 -0
  156. package/_esm/chains/definitions/battlechain.js.map +1 -0
  157. package/_esm/chains/definitions/marooTestnet.js +27 -0
  158. package/_esm/chains/definitions/marooTestnet.js.map +1 -0
  159. package/_esm/chains/index.js +2 -0
  160. package/_esm/chains/index.js.map +1 -1
  161. package/_esm/clients/createClient.js +53 -1
  162. package/_esm/clients/createClient.js.map +1 -1
  163. package/_esm/clients/createPublicClient.js.map +1 -1
  164. package/_esm/clients/createWalletClient.js.map +1 -1
  165. package/_esm/clients/decorators/public.js +17 -0
  166. package/_esm/clients/decorators/public.js.map +1 -1
  167. package/_esm/clients/decorators/wallet.js +8 -0
  168. package/_esm/clients/decorators/wallet.js.map +1 -1
  169. package/_esm/clients/transports/http.js +2 -1
  170. package/_esm/clients/transports/http.js.map +1 -1
  171. package/_esm/errors/encoding.js +7 -0
  172. package/_esm/errors/encoding.js.map +1 -1
  173. package/_esm/errors/request.js +22 -0
  174. package/_esm/errors/request.js.map +1 -1
  175. package/_esm/errors/transaction.js +7 -0
  176. package/_esm/errors/transaction.js.map +1 -1
  177. package/_esm/errors/version.js +1 -1
  178. package/_esm/index.js +3 -3
  179. package/_esm/index.js.map +1 -1
  180. package/_esm/tempo/Client.js +3 -1
  181. package/_esm/tempo/Client.js.map +1 -1
  182. package/_esm/tempo/Decorator.js +234 -218
  183. package/_esm/tempo/Decorator.js.map +1 -1
  184. package/_esm/tempo/actions/token.js +335 -186
  185. package/_esm/tempo/actions/token.js.map +1 -1
  186. package/_esm/tempo/actions/wallet.js +1 -1
  187. package/_esm/tempo/internal/utils.js +154 -0
  188. package/_esm/tempo/internal/utils.js.map +1 -1
  189. package/_esm/tokens/defineToken.js +57 -0
  190. package/_esm/tokens/defineToken.js.map +1 -0
  191. package/_esm/tokens/definitions/alphausd.js +12 -0
  192. package/_esm/tokens/definitions/alphausd.js.map +1 -0
  193. package/_esm/tokens/definitions/betausd.js +12 -0
  194. package/_esm/tokens/definitions/betausd.js.map +1 -0
  195. package/_esm/tokens/definitions/brla.js +12 -0
  196. package/_esm/tokens/definitions/brla.js.map +1 -0
  197. package/_esm/tokens/definitions/cbbtc.js +12 -0
  198. package/_esm/tokens/definitions/cbbtc.js.map +1 -0
  199. package/_esm/tokens/definitions/chfau.js +12 -0
  200. package/_esm/tokens/definitions/chfau.js.map +1 -0
  201. package/_esm/tokens/definitions/cirbtc.js +21 -0
  202. package/_esm/tokens/definitions/cirbtc.js.map +1 -0
  203. package/_esm/tokens/definitions/cusd.js +12 -0
  204. package/_esm/tokens/definitions/cusd.js.map +1 -0
  205. package/_esm/tokens/definitions/dlusd.js +12 -0
  206. package/_esm/tokens/definitions/dlusd.js.map +1 -0
  207. package/_esm/tokens/definitions/eurau.js +12 -0
  208. package/_esm/tokens/definitions/eurau.js.map +1 -0
  209. package/_esm/tokens/definitions/eurc.js +29 -0
  210. package/_esm/tokens/definitions/eurc.js.map +1 -0
  211. package/_esm/tokens/definitions/eurce.js +13 -0
  212. package/_esm/tokens/definitions/eurce.js.map +1 -0
  213. package/_esm/tokens/definitions/frxusd.js +12 -0
  214. package/_esm/tokens/definitions/frxusd.js.map +1 -0
  215. package/_esm/tokens/definitions/gbpa.js +12 -0
  216. package/_esm/tokens/definitions/gbpa.js.map +1 -0
  217. package/_esm/tokens/definitions/gusd.js +12 -0
  218. package/_esm/tokens/definitions/gusd.js.map +1 -0
  219. package/_esm/tokens/definitions/iusd.js +12 -0
  220. package/_esm/tokens/definitions/iusd.js.map +1 -0
  221. package/_esm/tokens/definitions/pathusd.js +13 -0
  222. package/_esm/tokens/definitions/pathusd.js.map +1 -0
  223. package/_esm/tokens/definitions/reusd.js +12 -0
  224. package/_esm/tokens/definitions/reusd.js.map +1 -0
  225. package/_esm/tokens/definitions/rusd.js +12 -0
  226. package/_esm/tokens/definitions/rusd.js.map +1 -0
  227. package/_esm/tokens/definitions/sbc.js +12 -0
  228. package/_esm/tokens/definitions/sbc.js.map +1 -0
  229. package/_esm/tokens/definitions/siusd.js +12 -0
  230. package/_esm/tokens/definitions/siusd.js.map +1 -0
  231. package/_esm/tokens/definitions/stcusd.js +12 -0
  232. package/_esm/tokens/definitions/stcusd.js.map +1 -0
  233. package/_esm/tokens/definitions/susde.js +12 -0
  234. package/_esm/tokens/definitions/susde.js.map +1 -0
  235. package/_esm/tokens/definitions/syrupusdc.js +12 -0
  236. package/_esm/tokens/definitions/syrupusdc.js.map +1 -0
  237. package/_esm/tokens/definitions/thetausd.js +12 -0
  238. package/_esm/tokens/definitions/thetausd.js.map +1 -0
  239. package/_esm/tokens/definitions/usd1.js +12 -0
  240. package/_esm/tokens/definitions/usd1.js.map +1 -0
  241. package/_esm/tokens/definitions/usdb.js +12 -0
  242. package/_esm/tokens/definitions/usdb.js.map +1 -0
  243. package/_esm/tokens/definitions/usdc.js +85 -0
  244. package/_esm/tokens/definitions/usdc.js.map +1 -0
  245. package/_esm/tokens/definitions/usdce.js +13 -0
  246. package/_esm/tokens/definitions/usdce.js.map +1 -0
  247. package/_esm/tokens/definitions/usde.js +12 -0
  248. package/_esm/tokens/definitions/usde.js.map +1 -0
  249. package/_esm/tokens/definitions/usdt0.js +12 -0
  250. package/_esm/tokens/definitions/usdt0.js.map +1 -0
  251. package/_esm/tokens/definitions/usyc.js +23 -0
  252. package/_esm/tokens/definitions/usyc.js.map +1 -0
  253. package/_esm/tokens/definitions/wsrusd.js +12 -0
  254. package/_esm/tokens/definitions/wsrusd.js.map +1 -0
  255. package/_esm/tokens/index.js +36 -0
  256. package/_esm/tokens/index.js.map +1 -0
  257. package/_esm/tokens/sets.js +104 -0
  258. package/_esm/tokens/sets.js.map +1 -0
  259. package/_esm/utils/encoding/fromRlp.js +8 -5
  260. package/_esm/utils/encoding/fromRlp.js.map +1 -1
  261. package/_esm/utils/rpc/http.js +59 -4
  262. package/_esm/utils/rpc/http.js.map +1 -1
  263. package/_esm/utils/transaction/parseTransaction.js +5 -2
  264. package/_esm/utils/transaction/parseTransaction.js.map +1 -1
  265. package/_types/actions/index.d.ts +1 -0
  266. package/_types/actions/index.d.ts.map +1 -1
  267. package/_types/actions/token/approve.d.ts +253 -0
  268. package/_types/actions/token/approve.d.ts.map +1 -0
  269. package/_types/actions/token/approveSync.d.ts +57 -0
  270. package/_types/actions/token/approveSync.d.ts.map +1 -0
  271. package/_types/actions/token/getAllowance.d.ts +77 -0
  272. package/_types/actions/token/getAllowance.d.ts.map +1 -0
  273. package/_types/actions/token/getBalance.d.ts +69 -0
  274. package/_types/actions/token/getBalance.d.ts.map +1 -0
  275. package/_types/actions/token/getMetadata.d.ts +43 -0
  276. package/_types/actions/token/getMetadata.d.ts.map +1 -0
  277. package/_types/actions/token/getTotalSupply.d.ts +63 -0
  278. package/_types/actions/token/getTotalSupply.d.ts.map +1 -0
  279. package/_types/actions/token/index.d.ts +9 -0
  280. package/_types/actions/token/index.d.ts.map +1 -0
  281. package/_types/actions/token/internal.d.ts +168 -0
  282. package/_types/actions/token/internal.d.ts.map +1 -0
  283. package/_types/actions/token/transfer.d.ts +288 -0
  284. package/_types/actions/token/transfer.d.ts.map +1 -0
  285. package/_types/actions/token/transferSync.d.ts +61 -0
  286. package/_types/actions/token/transferSync.d.ts.map +1 -0
  287. package/_types/chains/definitions/battlechain.d.ts +447 -0
  288. package/_types/chains/definitions/battlechain.d.ts.map +1 -0
  289. package/_types/chains/definitions/marooTestnet.d.ts +49 -0
  290. package/_types/chains/definitions/marooTestnet.d.ts.map +1 -0
  291. package/_types/chains/index.d.ts +2 -0
  292. package/_types/chains/index.d.ts.map +1 -1
  293. package/_types/clients/createClient.d.ts +24 -6
  294. package/_types/clients/createClient.d.ts.map +1 -1
  295. package/_types/clients/createPublicClient.d.ts +4 -3
  296. package/_types/clients/createPublicClient.d.ts.map +1 -1
  297. package/_types/clients/createWalletClient.d.ts +4 -3
  298. package/_types/clients/createWalletClient.d.ts.map +1 -1
  299. package/_types/clients/decorators/public.d.ts +128 -3
  300. package/_types/clients/decorators/public.d.ts.map +1 -1
  301. package/_types/clients/decorators/wallet.d.ts +208 -3
  302. package/_types/clients/decorators/wallet.d.ts.map +1 -1
  303. package/_types/clients/transports/http.d.ts +2 -0
  304. package/_types/clients/transports/http.d.ts.map +1 -1
  305. package/_types/errors/encoding.d.ts +8 -0
  306. package/_types/errors/encoding.d.ts.map +1 -1
  307. package/_types/errors/request.d.ts +11 -0
  308. package/_types/errors/request.d.ts.map +1 -1
  309. package/_types/errors/transaction.d.ts +8 -0
  310. package/_types/errors/transaction.d.ts.map +1 -1
  311. package/_types/errors/version.d.ts +1 -1
  312. package/_types/index.d.ts +4 -3
  313. package/_types/index.d.ts.map +1 -1
  314. package/_types/tempo/Client.d.ts +1 -1
  315. package/_types/tempo/Client.d.ts.map +1 -1
  316. package/_types/tempo/Decorator.d.ts +88 -5
  317. package/_types/tempo/Decorator.d.ts.map +1 -1
  318. package/_types/tempo/actions/token.d.ts +223 -151
  319. package/_types/tempo/actions/token.d.ts.map +1 -1
  320. package/_types/tempo/actions/wallet.d.ts +3 -3
  321. package/_types/tempo/internal/types.d.ts +17 -0
  322. package/_types/tempo/internal/types.d.ts.map +1 -1
  323. package/_types/tempo/internal/utils.d.ts +73 -0
  324. package/_types/tempo/internal/utils.d.ts.map +1 -1
  325. package/_types/tokens/defineToken.d.ts +112 -0
  326. package/_types/tokens/defineToken.d.ts.map +1 -0
  327. package/_types/tokens/definitions/alphausd.d.ts +11 -0
  328. package/_types/tokens/definitions/alphausd.d.ts.map +1 -0
  329. package/_types/tokens/definitions/betausd.d.ts +11 -0
  330. package/_types/tokens/definitions/betausd.d.ts.map +1 -0
  331. package/_types/tokens/definitions/brla.d.ts +11 -0
  332. package/_types/tokens/definitions/brla.d.ts.map +1 -0
  333. package/_types/tokens/definitions/cbbtc.d.ts +11 -0
  334. package/_types/tokens/definitions/cbbtc.d.ts.map +1 -0
  335. package/_types/tokens/definitions/chfau.d.ts +11 -0
  336. package/_types/tokens/definitions/chfau.d.ts.map +1 -0
  337. package/_types/tokens/definitions/cirbtc.d.ts +21 -0
  338. package/_types/tokens/definitions/cirbtc.d.ts.map +1 -0
  339. package/_types/tokens/definitions/cusd.d.ts +11 -0
  340. package/_types/tokens/definitions/cusd.d.ts.map +1 -0
  341. package/_types/tokens/definitions/dlusd.d.ts +11 -0
  342. package/_types/tokens/definitions/dlusd.d.ts.map +1 -0
  343. package/_types/tokens/definitions/eurau.d.ts +11 -0
  344. package/_types/tokens/definitions/eurau.d.ts.map +1 -0
  345. package/_types/tokens/definitions/eurc.d.ts +29 -0
  346. package/_types/tokens/definitions/eurc.d.ts.map +1 -0
  347. package/_types/tokens/definitions/eurce.d.ts +12 -0
  348. package/_types/tokens/definitions/eurce.d.ts.map +1 -0
  349. package/_types/tokens/definitions/frxusd.d.ts +11 -0
  350. package/_types/tokens/definitions/frxusd.d.ts.map +1 -0
  351. package/_types/tokens/definitions/gbpa.d.ts +11 -0
  352. package/_types/tokens/definitions/gbpa.d.ts.map +1 -0
  353. package/_types/tokens/definitions/gusd.d.ts +11 -0
  354. package/_types/tokens/definitions/gusd.d.ts.map +1 -0
  355. package/_types/tokens/definitions/iusd.d.ts +11 -0
  356. package/_types/tokens/definitions/iusd.d.ts.map +1 -0
  357. package/_types/tokens/definitions/pathusd.d.ts +12 -0
  358. package/_types/tokens/definitions/pathusd.d.ts.map +1 -0
  359. package/_types/tokens/definitions/reusd.d.ts +11 -0
  360. package/_types/tokens/definitions/reusd.d.ts.map +1 -0
  361. package/_types/tokens/definitions/rusd.d.ts +11 -0
  362. package/_types/tokens/definitions/rusd.d.ts.map +1 -0
  363. package/_types/tokens/definitions/sbc.d.ts +11 -0
  364. package/_types/tokens/definitions/sbc.d.ts.map +1 -0
  365. package/_types/tokens/definitions/siusd.d.ts +11 -0
  366. package/_types/tokens/definitions/siusd.d.ts.map +1 -0
  367. package/_types/tokens/definitions/stcusd.d.ts +11 -0
  368. package/_types/tokens/definitions/stcusd.d.ts.map +1 -0
  369. package/_types/tokens/definitions/susde.d.ts +11 -0
  370. package/_types/tokens/definitions/susde.d.ts.map +1 -0
  371. package/_types/tokens/definitions/syrupusdc.d.ts +11 -0
  372. package/_types/tokens/definitions/syrupusdc.d.ts.map +1 -0
  373. package/_types/tokens/definitions/thetausd.d.ts +11 -0
  374. package/_types/tokens/definitions/thetausd.d.ts.map +1 -0
  375. package/_types/tokens/definitions/usd1.d.ts +11 -0
  376. package/_types/tokens/definitions/usd1.d.ts.map +1 -0
  377. package/_types/tokens/definitions/usdb.d.ts +11 -0
  378. package/_types/tokens/definitions/usdb.d.ts.map +1 -0
  379. package/_types/tokens/definitions/usdc.d.ts +85 -0
  380. package/_types/tokens/definitions/usdc.d.ts.map +1 -0
  381. package/_types/tokens/definitions/usdce.d.ts +12 -0
  382. package/_types/tokens/definitions/usdce.d.ts.map +1 -0
  383. package/_types/tokens/definitions/usde.d.ts +11 -0
  384. package/_types/tokens/definitions/usde.d.ts.map +1 -0
  385. package/_types/tokens/definitions/usdt0.d.ts +11 -0
  386. package/_types/tokens/definitions/usdt0.d.ts.map +1 -0
  387. package/_types/tokens/definitions/usyc.d.ts +23 -0
  388. package/_types/tokens/definitions/usyc.d.ts.map +1 -0
  389. package/_types/tokens/definitions/wsrusd.d.ts +11 -0
  390. package/_types/tokens/definitions/wsrusd.d.ts.map +1 -0
  391. package/_types/tokens/index.d.ts +35 -0
  392. package/_types/tokens/index.d.ts.map +1 -0
  393. package/_types/tokens/sets.d.ts +607 -0
  394. package/_types/tokens/sets.d.ts.map +1 -0
  395. package/_types/utils/encoding/fromRlp.d.ts +2 -2
  396. package/_types/utils/encoding/fromRlp.d.ts.map +1 -1
  397. package/_types/utils/rpc/http.d.ts +6 -2
  398. package/_types/utils/rpc/http.d.ts.map +1 -1
  399. package/_types/utils/transaction/parseTransaction.d.ts +2 -2
  400. package/_types/utils/transaction/parseTransaction.d.ts.map +1 -1
  401. package/actions/index.ts +1 -0
  402. package/actions/token/approve.ts +202 -0
  403. package/actions/token/approveSync.ts +95 -0
  404. package/actions/token/getAllowance.ts +105 -0
  405. package/actions/token/getBalance.ts +115 -0
  406. package/actions/token/getMetadata.ts +98 -0
  407. package/actions/token/getTotalSupply.ts +97 -0
  408. package/actions/token/index.ts +9 -0
  409. package/actions/token/internal.ts +367 -0
  410. package/actions/token/transfer.ts +230 -0
  411. package/actions/token/transferSync.ts +99 -0
  412. package/chains/definitions/battlechain.ts +28 -0
  413. package/chains/definitions/marooTestnet.ts +27 -0
  414. package/chains/index.ts +2 -0
  415. package/clients/createClient.ts +90 -8
  416. package/clients/createPublicClient.ts +22 -4
  417. package/clients/createWalletClient.ts +22 -4
  418. package/clients/decorators/public.ts +166 -4
  419. package/clients/decorators/wallet.ts +242 -3
  420. package/clients/transports/http.ts +4 -0
  421. package/errors/encoding.ts +11 -0
  422. package/errors/request.ts +17 -0
  423. package/errors/transaction.ts +11 -0
  424. package/errors/version.ts +1 -1
  425. package/index.ts +7 -0
  426. package/package.json +6 -1
  427. package/tempo/Client.ts +7 -3
  428. package/tempo/Decorator.ts +398 -337
  429. package/tempo/actions/token.ts +519 -296
  430. package/tempo/actions/wallet.ts +3 -3
  431. package/tempo/internal/types.ts +19 -0
  432. package/tempo/internal/utils.ts +204 -0
  433. package/tokens/defineToken.ts +142 -0
  434. package/tokens/definitions/alphausd.ts +13 -0
  435. package/tokens/definitions/betausd.ts +13 -0
  436. package/tokens/definitions/brla.ts +13 -0
  437. package/tokens/definitions/cbbtc.ts +13 -0
  438. package/tokens/definitions/chfau.ts +13 -0
  439. package/tokens/definitions/cirbtc.ts +21 -0
  440. package/tokens/definitions/cusd.ts +13 -0
  441. package/tokens/definitions/dlusd.ts +13 -0
  442. package/tokens/definitions/eurau.ts +13 -0
  443. package/tokens/definitions/eurc.ts +29 -0
  444. package/tokens/definitions/eurce.ts +14 -0
  445. package/tokens/definitions/frxusd.ts +13 -0
  446. package/tokens/definitions/gbpa.ts +13 -0
  447. package/tokens/definitions/gusd.ts +13 -0
  448. package/tokens/definitions/iusd.ts +13 -0
  449. package/tokens/definitions/pathusd.ts +14 -0
  450. package/tokens/definitions/reusd.ts +13 -0
  451. package/tokens/definitions/rusd.ts +13 -0
  452. package/tokens/definitions/sbc.ts +13 -0
  453. package/tokens/definitions/siusd.ts +13 -0
  454. package/tokens/definitions/stcusd.ts +13 -0
  455. package/tokens/definitions/susde.ts +13 -0
  456. package/tokens/definitions/syrupusdc.ts +13 -0
  457. package/tokens/definitions/thetausd.ts +13 -0
  458. package/tokens/definitions/usd1.ts +13 -0
  459. package/tokens/definitions/usdb.ts +13 -0
  460. package/tokens/definitions/usdc.ts +85 -0
  461. package/tokens/definitions/usdce.ts +14 -0
  462. package/tokens/definitions/usde.ts +13 -0
  463. package/tokens/definitions/usdt0.ts +13 -0
  464. package/tokens/definitions/usyc.ts +23 -0
  465. package/tokens/definitions/wsrusd.ts +13 -0
  466. package/tokens/index.ts +35 -0
  467. package/tokens/package.json +6 -0
  468. package/tokens/sets.ts +109 -0
  469. package/utils/encoding/fromRlp.ts +22 -3
  470. package/utils/rpc/http.ts +70 -2
  471. package/utils/transaction/parseTransaction.ts +7 -2
@@ -0,0 +1,97 @@
1
+ import type { Account } from '../../accounts/types.js'
2
+ import type { Client } from '../../clients/createClient.js'
3
+ import type { Transport } from '../../clients/transports/createTransport.js'
4
+ import { erc20Abi } from '../../constants/abis.js'
5
+ import type { Tokens } from '../../tokens/defineToken.js'
6
+ import type { Chain } from '../../types/chain.js'
7
+ import { readContract } from '../public/readContract.js'
8
+ import {
9
+ type Amount,
10
+ defineCall,
11
+ type ReadParameters,
12
+ resolveToken,
13
+ resolveTokenWithDecimals,
14
+ type TokenParameters,
15
+ toAmount,
16
+ } from './internal.js'
17
+
18
+ /**
19
+ * Gets the total supply of an ERC-20 token.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { createClient, http } from 'viem'
24
+ * import { mainnet } from 'viem/chains'
25
+ * import { token } from 'viem/actions'
26
+ *
27
+ * const client = createClient({ chain: mainnet, transport: http() })
28
+ *
29
+ * const totalSupply = await token.getTotalSupply(client, {
30
+ * token: '0x...',
31
+ * })
32
+ * ```
33
+ *
34
+ * @param client - Client.
35
+ * @param parameters - Parameters.
36
+ * @returns The token total supply, in base units and human-readable form.
37
+ */
38
+ export async function getTotalSupply<
39
+ chain extends Chain | undefined,
40
+ account extends Account | undefined,
41
+ tokens extends Tokens | undefined = undefined,
42
+ >(
43
+ client: Client<Transport, chain, account, undefined, undefined, tokens>,
44
+ parameters: getTotalSupply.Parameters<chain, tokens>,
45
+ ): Promise<getTotalSupply.ReturnValue> {
46
+ const { decimals, token, ...rest } = parameters
47
+ const [amount, { decimals: resolved }] = await Promise.all([
48
+ readContract(client, {
49
+ ...rest,
50
+ ...getTotalSupply.call(client, { token } as never),
51
+ }),
52
+ resolveTokenWithDecimals(client, {
53
+ decimals,
54
+ token,
55
+ }),
56
+ ])
57
+ return toAmount(amount as bigint, resolved)
58
+ }
59
+
60
+ export namespace getTotalSupply {
61
+ export type Args<
62
+ chain extends Chain | undefined = Chain | undefined,
63
+ tokens extends Tokens | undefined = Tokens | undefined,
64
+ > = TokenParameters<chain, tokens>
65
+ export type Parameters<
66
+ chain extends Chain | undefined = Chain | undefined,
67
+ tokens extends Tokens | undefined = Tokens | undefined,
68
+ > = Omit<ReadParameters, 'account'> & Args<chain, tokens>
69
+ export type ReturnValue = Amount
70
+
71
+ /**
72
+ * Defines a call to the `totalSupply` function.
73
+ *
74
+ * Can be passed as a parameter to `multicall`, `simulateContract`, or any
75
+ * other action that accepts a contract call. The token is selected by `token`
76
+ * symbol (resolved from the client's `tokens` array) or contract address.
77
+ *
78
+ * @param client - Client.
79
+ * @param args - Arguments.
80
+ * @returns The call.
81
+ */
82
+ export function call<
83
+ chain extends Chain | undefined,
84
+ account extends Account | undefined,
85
+ tokens extends Tokens | undefined = undefined,
86
+ >(
87
+ client: Client<Transport, chain, account, undefined, undefined, tokens>,
88
+ args: Args<chain, tokens>,
89
+ ) {
90
+ return defineCall({
91
+ address: resolveToken(client, args).address,
92
+ abi: erc20Abi,
93
+ args: [],
94
+ functionName: 'totalSupply',
95
+ })
96
+ }
97
+ }
@@ -0,0 +1,9 @@
1
+ // biome-ignore lint/performance/noBarrelFile: entrypoint module
2
+ export { approve } from './approve.js'
3
+ export { approveSync } from './approveSync.js'
4
+ export { getAllowance } from './getAllowance.js'
5
+ export { getBalance } from './getBalance.js'
6
+ export { getMetadata } from './getMetadata.js'
7
+ export { getTotalSupply } from './getTotalSupply.js'
8
+ export { transfer } from './transfer.js'
9
+ export { transferSync } from './transferSync.js'
@@ -0,0 +1,367 @@
1
+ import type { Abi, AbiStateMutability, Address } from 'abitype'
2
+ import type { Account } from '../../accounts/types.js'
3
+ import type { Client } from '../../clients/createClient.js'
4
+ import type { Transport } from '../../clients/transports/createTransport.js'
5
+ import { erc20Abi } from '../../constants/abis.js'
6
+ import type { ResolvedToken, Token, Tokens } from '../../tokens/defineToken.js'
7
+ import type { Chain } from '../../types/chain.js'
8
+ import type {
9
+ ContractFunctionName,
10
+ ContractFunctionParameters,
11
+ ExtractAbiItem,
12
+ } from '../../types/contract.js'
13
+ import type { Hex } from '../../types/misc.js'
14
+ import type { UnionPick } from '../../types/utils.js'
15
+ import { isAddress } from '../../utils/address/isAddress.js'
16
+ import { isAddressEqual } from '../../utils/address/isAddressEqual.js'
17
+ import { encodeFunctionData } from '../../utils/index.js'
18
+ import { formatUnits } from '../../utils/unit/formatUnits.js'
19
+ import { parseUnits } from '../../utils/unit/parseUnits.js'
20
+ import type { ReadContractParameters as viem_ReadContractParameters } from '../public/readContract.js'
21
+ import { readContract } from '../public/readContract.js'
22
+ import type { WriteContractSyncParameters as viem_WriteContractSyncParameters } from '../wallet/writeContractSync.js'
23
+
24
+ /**
25
+ * Union of symbols of the Client's declared `tokens` whose `addresses` include
26
+ * the Client's `chain.id`. Collapses to `never` when there is no chain mapping
27
+ * (no `tokens`, no `chain`, a widened `chain.id`, or widened token symbols).
28
+ *
29
+ * @internal
30
+ */
31
+ export type TokenName<
32
+ chain extends Chain | undefined,
33
+ tokens extends Tokens | undefined,
34
+ > = chain extends { id: infer chainId extends number }
35
+ ? number extends chainId
36
+ ? never
37
+ : tokens extends Tokens
38
+ ? TokenSymbolForChain<tokens[number], chainId>
39
+ : never
40
+ : never
41
+
42
+ type TokenSymbolForChain<token, chainId extends number> = token extends Token
43
+ ? chainId extends keyof token['addresses']
44
+ ? token['symbol'] extends string
45
+ ? string extends token['symbol']
46
+ ? never
47
+ : Lowercase<token['symbol']>
48
+ : never
49
+ : never
50
+ : never
51
+
52
+ /**
53
+ * Selects an ERC-20 token by `token`, which is either the symbol of a token
54
+ * declared on the Client's `tokens` array or a contract `address`.
55
+ *
56
+ * When `token` is a declared symbol (or an address that matches a declared
57
+ * token), token metadata is resolved from the Client's `tokens` array.
58
+ */
59
+ export type TokenParameter<
60
+ chain extends Chain | undefined,
61
+ tokens extends Tokens | undefined,
62
+ > = {
63
+ /**
64
+ * Token to operate on: either the symbol of a token declared on the Client's
65
+ * `tokens` array (with an address for the Client's `chain.id`), or a
66
+ * contract `address`.
67
+ */
68
+ token: TokenName<chain, tokens> | Address
69
+ }
70
+
71
+ export type TokenParameters<
72
+ chain extends Chain | undefined,
73
+ tokens extends Tokens | undefined,
74
+ > = TokenParameter<chain, tokens> & {
75
+ /**
76
+ * Decimals used to convert between base units and the human-readable amount.
77
+ * Inferred from the Client's `tokens` array when `token` matches a declared
78
+ * token; otherwise fetched from the token contract when needed.
79
+ */
80
+ decimals?: number | undefined
81
+ }
82
+
83
+ /**
84
+ * A token amount, expressed both in the token's base units (`amount`) and as a
85
+ * human-readable decimal string (`formatted`, derived from the token's
86
+ * `decimals`).
87
+ */
88
+ export type Amount = {
89
+ /** Amount in the token's base units. */
90
+ amount: bigint
91
+ /** Token decimals used to derive `formatted`. */
92
+ decimals: number
93
+ /** Amount formatted as a human-readable decimal string. */
94
+ formatted: string
95
+ }
96
+
97
+ /** A write amount: a base-unit bigint, or an explicit formatted helper. */
98
+ export type AmountInput =
99
+ | bigint
100
+ | {
101
+ /** Token decimals used to parse `formatted`. */
102
+ decimals?: number | undefined
103
+ /** Human-readable decimal amount. */
104
+ formatted: string
105
+ }
106
+
107
+ /**
108
+ * Shapes a base-unit value into an {@link Amount} (base units, `decimals`, and
109
+ * human-readable `formatted` string).
110
+ *
111
+ * @param amount - Amount in base units.
112
+ * @param decimals - Token decimals used to format the amount.
113
+ * @returns The {@link Amount}.
114
+ */
115
+ export function toAmount(amount: bigint, decimals: number): Amount {
116
+ return { amount, decimals, formatted: formatUnits(amount, decimals) }
117
+ }
118
+
119
+ /**
120
+ * Resolves a write amount to base units.
121
+ *
122
+ * @param amount - Base-unit amount, or formatted helper.
123
+ * @param decimals - Token decimals used to parse formatted amounts.
124
+ * @returns Amount in base units.
125
+ */
126
+ export function toBaseUnits(
127
+ amount: AmountInput,
128
+ decimals: number | undefined,
129
+ ): bigint {
130
+ if (typeof amount === 'bigint') return amount
131
+ const resolved = amount.decimals ?? decimals
132
+ return parseUnits(amount.formatted, requireTokenDecimals(resolved))
133
+ }
134
+
135
+ /**
136
+ * Requires resolved token decimals for parsing or formatting amounts.
137
+ *
138
+ * @param decimals - Token decimals.
139
+ * @returns Token decimals.
140
+ * @internal
141
+ */
142
+ export function requireTokenDecimals(decimals: number | undefined): number {
143
+ if (decimals === undefined)
144
+ throw new Error(
145
+ 'Token decimals are required. Pass `amount.decimals` or select a declared token.',
146
+ )
147
+ return decimals
148
+ }
149
+
150
+ /**
151
+ * Resolves the decimals used for formatting a write amount.
152
+ *
153
+ * @param amount - Base-unit amount, or formatted helper.
154
+ * @param decimals - Token decimals.
155
+ * @returns Token decimals, overridden by the formatted helper when present.
156
+ */
157
+ export function resolveAmountDecimals(
158
+ amount: AmountInput,
159
+ decimals: number | undefined,
160
+ ): number | undefined {
161
+ if (typeof amount === 'bigint') return decimals
162
+ return amount.decimals ?? decimals
163
+ }
164
+
165
+ /**
166
+ * Resolves the token contract `address` and `decimals` from a `token`, which is
167
+ * either the symbol of a token declared on the client's `tokens` array or a
168
+ * contract `address`.
169
+ *
170
+ * When `token` is a declared symbol, the `address` and `decimals` are resolved
171
+ * from the Client's `tokens` array for the Client's `chain.id` (`decimals` can
172
+ * be overridden via the explicit `decimals`). When `token` is an address, its
173
+ * `decimals` is inferred from the Client's `tokens` array when the address
174
+ * matches a declared token, otherwise taken from the explicit `decimals`.
175
+ *
176
+ * @param client - Client.
177
+ * @param parameters - Parameters.
178
+ * @returns The resolved `address` and `decimals`.
179
+ */
180
+ export function resolveToken(
181
+ client: Client<Transport, Chain | undefined>,
182
+ parameters: resolveToken.Parameters,
183
+ ): { address: Address; decimals: number | undefined } {
184
+ const { decimals, token } = parameters
185
+
186
+ const declared = findDeclaredToken(client, token)
187
+ if (declared)
188
+ return {
189
+ address: declared.address,
190
+ decimals: decimals ?? declared.decimals,
191
+ }
192
+
193
+ if (isAddress(token, { strict: false }))
194
+ return {
195
+ address: token,
196
+ decimals: decimals ?? inferDecimals(client, token),
197
+ }
198
+
199
+ throw new Error(
200
+ `Token "${token}" is not a declared ERC-20 token on the client's \`tokens\` array (with an address for the client's chain), and is not a valid address.`,
201
+ )
202
+ }
203
+
204
+ export namespace resolveToken {
205
+ export type Parameters = {
206
+ /** Decimals, if provided explicitly. */
207
+ decimals?: number | undefined
208
+ /** Token symbol (declared on the client's `tokens` array) or contract address. */
209
+ token: string
210
+ }
211
+ }
212
+
213
+ /**
214
+ * Finds the declared token on the Client's `tokens` array matching `token`
215
+ * (either a token symbol or contract `address`), resolved to a {@link ResolvedToken}
216
+ * for the Client's `chain.id`. Returns `undefined` when no declared token
217
+ * matches, or the matching token has no address for the Client's chain.
218
+ *
219
+ * @param client - Client.
220
+ * @param token - Token symbol (declared on the client's `tokens` array) or contract address.
221
+ * @returns The matching resolved token config, or `undefined`.
222
+ */
223
+ export function findDeclaredToken(
224
+ client: Client<Transport, Chain | undefined>,
225
+ token: string,
226
+ ): ResolvedToken | undefined {
227
+ const tokens = client.tokens
228
+ const chainId = client.chain?.id
229
+ if (!tokens || chainId === undefined) return undefined
230
+
231
+ const bySymbol = findTokenBySymbol(tokens, token)
232
+ if (bySymbol) return resolveTokenForChain(bySymbol, chainId)
233
+
234
+ if (isAddress(token, { strict: false }))
235
+ for (const token_ of tokens) {
236
+ const resolved = resolveTokenForChain(token_, chainId)
237
+ if (resolved && isAddressEqual(resolved.address, token)) return resolved
238
+ }
239
+ return undefined
240
+ }
241
+
242
+ /**
243
+ * Resolves a {@link Token} to a {@link ResolvedToken} for `chainId`, or
244
+ * `undefined` when the token has no address for `chainId`. @internal
245
+ */
246
+ function resolveTokenForChain(
247
+ token: Token,
248
+ chainId: number,
249
+ ): ResolvedToken | undefined {
250
+ const address = (token.addresses as Record<number, Address>)[chainId]
251
+ if (!address) return undefined
252
+ return {
253
+ address,
254
+ currency: token.currency,
255
+ decimals: token.decimals,
256
+ name: token.name,
257
+ popular: token.popular,
258
+ symbol: token.symbol,
259
+ }
260
+ }
261
+
262
+ /** Finds a {@link Token} by symbol (case-insensitively) on a `tokens` array. @internal */
263
+ function findTokenBySymbol(tokens: Tokens, symbol: string): Token | undefined {
264
+ const lowerSymbol = symbol.toLowerCase()
265
+ for (const token of tokens) {
266
+ if (token.symbol?.toLowerCase() === lowerSymbol) return token
267
+ }
268
+ return undefined
269
+ }
270
+
271
+ /**
272
+ * Infers a token's `decimals` from the Client's `tokens` array by matching
273
+ * `address` against each token's address for the Client's `chain.id`.
274
+ * @internal
275
+ */
276
+ function inferDecimals(
277
+ client: Client<Transport, Chain | undefined>,
278
+ address: Address,
279
+ ): number | undefined {
280
+ const tokens = client.tokens
281
+ const chainId = client.chain?.id
282
+ if (tokens && chainId !== undefined)
283
+ for (const token of tokens) {
284
+ const resolved = resolveTokenForChain(token, chainId)
285
+ if (resolved && isAddressEqual(resolved.address, address))
286
+ return resolved.decimals
287
+ }
288
+ return undefined
289
+ }
290
+
291
+ /**
292
+ * Resolves token decimals, fetching from the token contract when they are not
293
+ * provided explicitly or declared on the client.
294
+ * @internal
295
+ */
296
+ export async function resolveTokenWithDecimals(
297
+ client: Client<Transport, Chain | undefined>,
298
+ parameters: resolveToken.Parameters,
299
+ ): Promise<{ address: Address; decimals: number }> {
300
+ const { address, decimals } = resolveToken(client, parameters)
301
+ if (decimals !== undefined) return { address, decimals }
302
+ return {
303
+ address,
304
+ decimals: await readContract(client, {
305
+ abi: erc20Abi,
306
+ address,
307
+ functionName: 'decimals',
308
+ }),
309
+ }
310
+ }
311
+
312
+ /**
313
+ * Picks the transaction-override fields shared by write actions, so the
314
+ * action-specific args (`token`, `amount`, `to`, etc.) don't leak into
315
+ * `estimateContractGas` / `simulateContract` requests. @internal
316
+ */
317
+ export function pickWriteParameters(parameters: Record<string, unknown>) {
318
+ const { account, chain, gas, maxFeePerGas, maxPriorityFeePerGas, nonce } =
319
+ parameters
320
+ return { account, chain, gas, maxFeePerGas, maxPriorityFeePerGas, nonce }
321
+ }
322
+
323
+ export type ReadParameters = Pick<
324
+ viem_ReadContractParameters<never, never, never>,
325
+ 'account' | 'blockNumber' | 'blockOverrides' | 'blockTag' | 'stateOverride'
326
+ >
327
+
328
+ export type WriteParameters<
329
+ chain extends Chain | undefined = Chain | undefined,
330
+ account extends Account | undefined = Account | undefined,
331
+ > = UnionPick<
332
+ viem_WriteContractSyncParameters<never, never, never, chain, account>,
333
+ | 'account'
334
+ | 'chain'
335
+ | 'gas'
336
+ | 'maxFeePerGas'
337
+ | 'maxPriorityFeePerGas'
338
+ | 'nonce'
339
+ | 'throwOnReceiptRevert'
340
+ >
341
+
342
+ export function defineCall<
343
+ const abi extends Abi,
344
+ const functionName extends ContractFunctionName<abi, AbiStateMutability>,
345
+ call extends ContractFunctionParameters<
346
+ abi,
347
+ AbiStateMutability,
348
+ functionName
349
+ >,
350
+ >(
351
+ call:
352
+ | call
353
+ | ContractFunctionParameters<abi, AbiStateMutability, functionName>,
354
+ ): ContractFunctionParameters<
355
+ [ExtractAbiItem<abi, functionName>],
356
+ AbiStateMutability,
357
+ functionName
358
+ > & {
359
+ data: Hex
360
+ to: Address
361
+ } {
362
+ return {
363
+ ...(call as any),
364
+ data: encodeFunctionData(call as never),
365
+ to: call.address,
366
+ } as const
367
+ }
@@ -0,0 +1,230 @@
1
+ import type { Address } from 'abitype'
2
+ import type { Account } from '../../accounts/types.js'
3
+ import type { Client } from '../../clients/createClient.js'
4
+ import type { Transport } from '../../clients/transports/createTransport.js'
5
+ import { erc20Abi } from '../../constants/abis.js'
6
+ import type { BaseErrorType } from '../../errors/base.js'
7
+ import type { Tokens } from '../../tokens/defineToken.js'
8
+ import type { Chain } from '../../types/chain.js'
9
+ import type { Log } from '../../types/log.js'
10
+ import { parseEventLogs } from '../../utils/abi/parseEventLogs.js'
11
+ import { estimateContractGas } from '../public/estimateContractGas.js'
12
+ import {
13
+ type SimulateContractReturnType,
14
+ simulateContract,
15
+ } from '../public/simulateContract.js'
16
+ import type { WriteContractReturnType } from '../wallet/writeContract.js'
17
+ import { writeContract } from '../wallet/writeContract.js'
18
+ import type { writeContractSync } from '../wallet/writeContractSync.js'
19
+ import {
20
+ type AmountInput,
21
+ defineCall,
22
+ pickWriteParameters,
23
+ resolveToken,
24
+ type TokenParameter,
25
+ toBaseUnits,
26
+ type WriteParameters,
27
+ } from './internal.js'
28
+
29
+ /**
30
+ * Transfers ERC-20 tokens to another address.
31
+ *
32
+ * Pass `from` to transfer on behalf of another address using an allowance
33
+ * (calls `transferFrom`); otherwise transfers from the caller (calls
34
+ * `transfer`).
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * import { createClient, http } from 'viem'
39
+ * import { mainnet } from 'viem/chains'
40
+ * import { privateKeyToAccount } from 'viem/accounts'
41
+ * import { token } from 'viem/actions'
42
+ *
43
+ * const client = createClient({
44
+ * account: privateKeyToAccount('0x...'),
45
+ * chain: mainnet,
46
+ * transport: http(),
47
+ * })
48
+ *
49
+ * const hash = await token.transfer(client, {
50
+ * amount: 100000000n,
51
+ * to: '0x...',
52
+ * token: '0x...',
53
+ * })
54
+ * ```
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * // Transfer on behalf of another address (via an allowance).
59
+ * const hash = await token.transfer(client, {
60
+ * amount: 100000000n,
61
+ * from: '0x...',
62
+ * to: '0x...',
63
+ * token: '0x...',
64
+ * })
65
+ * ```
66
+ *
67
+ * @param client - Client.
68
+ * @param parameters - Parameters.
69
+ * @returns The transaction hash.
70
+ */
71
+ export async function transfer<
72
+ chain extends Chain | undefined,
73
+ account extends Account | undefined,
74
+ tokens extends Tokens | undefined = undefined,
75
+ >(
76
+ client: Client<Transport, chain, account, undefined, undefined, tokens>,
77
+ parameters: transfer.Parameters<chain, account, tokens>,
78
+ ): Promise<transfer.ReturnValue> {
79
+ return transfer.inner(writeContract, client, parameters)
80
+ }
81
+
82
+ export namespace transfer {
83
+ export type Args<
84
+ chain extends Chain | undefined = Chain | undefined,
85
+ tokens extends Tokens | undefined = Tokens | undefined,
86
+ > = {
87
+ /** Amount to transfer in base units, or as a formatted helper. */
88
+ amount: AmountInput
89
+ /** Address to transfer tokens from (uses an allowance via `transferFrom`). */
90
+ from?: Address | undefined
91
+ /** Address to transfer tokens to. */
92
+ to: Address
93
+ } & TokenParameter<chain, tokens>
94
+ export type Parameters<
95
+ chain extends Chain | undefined = Chain | undefined,
96
+ account extends Account | undefined = Account | undefined,
97
+ tokens extends Tokens | undefined = Tokens | undefined,
98
+ > = WriteParameters<chain, account> & Args<chain, tokens>
99
+ export type ReturnValue = WriteContractReturnType
100
+ // TODO: exhaustive error type
101
+ export type ErrorType = BaseErrorType
102
+
103
+ /** @internal */
104
+ export async function inner<
105
+ action extends typeof writeContract | typeof writeContractSync,
106
+ chain extends Chain | undefined,
107
+ account extends Account | undefined,
108
+ tokens extends Tokens | undefined = undefined,
109
+ >(
110
+ action: action,
111
+ client: Client<Transport, chain, account, undefined, undefined, tokens>,
112
+ parameters: transfer.Parameters<chain, account, tokens>,
113
+ ): Promise<ReturnType<action>> {
114
+ return (await action(client, {
115
+ ...parameters,
116
+ ...transfer.call(client, parameters as never),
117
+ } as never)) as never
118
+ }
119
+
120
+ /**
121
+ * Defines a call to the `transfer` (or `transferFrom`, when `from` is given)
122
+ * function.
123
+ *
124
+ * Can be passed as a parameter to `estimateContractGas`, `simulateContract`,
125
+ * `sendCalls`, `sendTransaction` (`calls`), or `multicall`. The token is
126
+ * selected by `token`, which is either a token symbol (resolved from the
127
+ * client's `tokens` array) or a contract `address`; `amount.decimals`
128
+ * is inferred from declared client tokens when omitted.
129
+ *
130
+ * @param client - Client.
131
+ * @param parameters - Parameters.
132
+ * @returns The call.
133
+ */
134
+ export function call<
135
+ chain extends Chain | undefined,
136
+ account extends Account | undefined,
137
+ tokens extends Tokens | undefined = undefined,
138
+ >(
139
+ client: Client<Transport, chain, account, undefined, undefined, tokens>,
140
+ parameters: Args<chain, tokens>,
141
+ ) {
142
+ return defineCall(getCall(client, parameters as transfer.Args))
143
+ }
144
+
145
+ /**
146
+ * Estimates the gas required to transfer ERC-20 tokens. `amount.decimals` is
147
+ * inferred from declared client tokens when omitted.
148
+ *
149
+ * @param client - Client.
150
+ * @param parameters - Parameters.
151
+ * @returns The gas estimate.
152
+ */
153
+ export async function estimateGas<
154
+ chain extends Chain | undefined,
155
+ account extends Account | undefined,
156
+ tokens extends Tokens | undefined = undefined,
157
+ >(
158
+ client: Client<Transport, chain, account, undefined, undefined, tokens>,
159
+ parameters: transfer.Parameters<chain, account, tokens>,
160
+ ): Promise<bigint> {
161
+ return estimateContractGas(client, {
162
+ ...pickWriteParameters(parameters as never),
163
+ ...transfer.call(client, parameters as never),
164
+ } as never)
165
+ }
166
+
167
+ /**
168
+ * Simulates a transfer of ERC-20 tokens. `amount.decimals` is inferred from
169
+ * declared client tokens when omitted.
170
+ *
171
+ * @param client - Client.
172
+ * @param parameters - Parameters.
173
+ * @returns The simulation result and write request.
174
+ */
175
+ export async function simulate<
176
+ chain extends Chain | undefined,
177
+ account extends Account | undefined,
178
+ tokens extends Tokens | undefined = undefined,
179
+ >(
180
+ client: Client<Transport, chain, account, undefined, undefined, tokens>,
181
+ parameters: transfer.Parameters<chain, account, tokens>,
182
+ ): Promise<
183
+ SimulateContractReturnType<typeof erc20Abi, 'transfer' | 'transferFrom'>
184
+ > {
185
+ return simulateContract(client, {
186
+ ...pickWriteParameters(parameters as never),
187
+ ...transfer.call(client, parameters as never),
188
+ } as never) as never
189
+ }
190
+
191
+ /**
192
+ * Extracts the `Transfer` event from logs.
193
+ *
194
+ * @param logs - The logs.
195
+ * @returns The `Transfer` event.
196
+ */
197
+ export function extractEvent(logs: Log[]) {
198
+ const [log] = parseEventLogs({
199
+ abi: erc20Abi,
200
+ logs,
201
+ eventName: 'Transfer',
202
+ strict: true,
203
+ })
204
+ if (!log) throw new Error('`Transfer` event not found.')
205
+ return log
206
+ }
207
+ }
208
+
209
+ /** Builds the underlying `transfer`/`transferFrom` contract call. @internal */
210
+ function getCall(
211
+ client: Client<Transport, Chain | undefined>,
212
+ parameters: transfer.Args,
213
+ ) {
214
+ const { amount, from, to, token } = parameters
215
+ const { address, decimals } = resolveToken(client, { token })
216
+ const value = toBaseUnits(amount, decimals)
217
+ if (from)
218
+ return {
219
+ abi: erc20Abi,
220
+ address,
221
+ args: [from, to, value],
222
+ functionName: 'transferFrom',
223
+ } as const
224
+ return {
225
+ abi: erc20Abi,
226
+ address,
227
+ args: [to, value],
228
+ functionName: 'transfer',
229
+ } as const
230
+ }