tempo.ts 0.1.5 → 0.2.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 (297) hide show
  1. package/README.md +33 -2
  2. package/dist/chains.d.ts +509 -115
  3. package/dist/chains.d.ts.map +1 -1
  4. package/dist/chains.js +20 -9
  5. package/dist/chains.js.map +1 -1
  6. package/dist/ox/Order.d.ts +92 -0
  7. package/dist/ox/Order.d.ts.map +1 -0
  8. package/dist/ox/Order.js +88 -0
  9. package/dist/ox/Order.js.map +1 -0
  10. package/dist/ox/OrdersFilters.d.ts +72 -0
  11. package/dist/ox/OrdersFilters.d.ts.map +1 -0
  12. package/dist/ox/OrdersFilters.js +100 -0
  13. package/dist/ox/OrdersFilters.js.map +1 -0
  14. package/dist/ox/Pagination.d.ts +128 -0
  15. package/dist/ox/Pagination.d.ts.map +1 -0
  16. package/dist/ox/Pagination.js +78 -0
  17. package/dist/ox/Pagination.js.map +1 -0
  18. package/dist/ox/PoolId.d.ts +18 -0
  19. package/dist/ox/PoolId.d.ts.map +1 -0
  20. package/dist/ox/PoolId.js +13 -0
  21. package/dist/ox/PoolId.js.map +1 -0
  22. package/dist/ox/RpcSchema.d.ts +32 -0
  23. package/dist/ox/RpcSchema.d.ts.map +1 -0
  24. package/dist/ox/RpcSchema.js +2 -0
  25. package/dist/ox/RpcSchema.js.map +1 -0
  26. package/dist/ox/SignatureEnvelope.d.ts +1 -1
  27. package/dist/ox/SignatureEnvelope.d.ts.map +1 -1
  28. package/dist/ox/SignatureEnvelope.js.map +1 -1
  29. package/dist/{viem → ox}/Tick.d.ts +4 -0
  30. package/dist/ox/Tick.d.ts.map +1 -0
  31. package/dist/ox/Tick.js.map +1 -0
  32. package/dist/ox/Transaction.d.ts.map +1 -1
  33. package/dist/ox/Transaction.js +2 -1
  34. package/dist/ox/Transaction.js.map +1 -1
  35. package/dist/ox/TransactionEnvelopeAA.d.ts +6 -6
  36. package/dist/ox/TransactionEnvelopeAA.d.ts.map +1 -1
  37. package/dist/ox/TransactionEnvelopeAA.js +4 -2
  38. package/dist/ox/TransactionEnvelopeAA.js.map +1 -1
  39. package/dist/ox/TransactionRequest.d.ts +4 -0
  40. package/dist/ox/TransactionRequest.d.ts.map +1 -1
  41. package/dist/ox/TransactionRequest.js.map +1 -1
  42. package/dist/ox/index.d.ts +6 -0
  43. package/dist/ox/index.d.ts.map +1 -1
  44. package/dist/ox/index.js +6 -0
  45. package/dist/ox/index.js.map +1 -1
  46. package/dist/prool/Instance.d.ts.map +1 -1
  47. package/dist/prool/Instance.js +20 -4
  48. package/dist/prool/Instance.js.map +1 -1
  49. package/dist/viem/Abis.d.ts +1469 -1082
  50. package/dist/viem/Abis.d.ts.map +1 -1
  51. package/dist/viem/Abis.js +932 -671
  52. package/dist/viem/Abis.js.map +1 -1
  53. package/dist/viem/Account.d.ts +150 -0
  54. package/dist/viem/Account.d.ts.map +1 -0
  55. package/dist/viem/Account.js +221 -0
  56. package/dist/viem/Account.js.map +1 -0
  57. package/dist/viem/Actions/amm.d.ts +144 -161
  58. package/dist/viem/Actions/amm.d.ts.map +1 -1
  59. package/dist/viem/Actions/amm.js +109 -163
  60. package/dist/viem/Actions/amm.js.map +1 -1
  61. package/dist/viem/Actions/dex.d.ts +920 -664
  62. package/dist/viem/Actions/dex.d.ts.map +1 -1
  63. package/dist/viem/Actions/dex.js +129 -30
  64. package/dist/viem/Actions/dex.js.map +1 -1
  65. package/dist/viem/Actions/faucet.d.ts +34 -0
  66. package/dist/viem/Actions/faucet.d.ts.map +1 -0
  67. package/dist/viem/Actions/faucet.js +33 -0
  68. package/dist/viem/Actions/faucet.js.map +1 -0
  69. package/dist/viem/Actions/fee.d.ts +16 -30
  70. package/dist/viem/Actions/fee.d.ts.map +1 -1
  71. package/dist/viem/Actions/fee.js +13 -13
  72. package/dist/viem/Actions/fee.js.map +1 -1
  73. package/dist/viem/Actions/index.d.ts +2 -0
  74. package/dist/viem/Actions/index.d.ts.map +1 -1
  75. package/dist/viem/Actions/index.js +2 -0
  76. package/dist/viem/Actions/index.js.map +1 -1
  77. package/dist/viem/Actions/policy.d.ts +46 -46
  78. package/dist/viem/Actions/policy.js +46 -46
  79. package/dist/viem/Actions/reward.d.ts +3236 -0
  80. package/dist/viem/Actions/reward.d.ts.map +1 -0
  81. package/dist/viem/Actions/reward.js +725 -0
  82. package/dist/viem/Actions/reward.js.map +1 -0
  83. package/dist/viem/Actions/token.d.ts +4399 -2750
  84. package/dist/viem/Actions/token.d.ts.map +1 -1
  85. package/dist/viem/Actions/token.js +361 -482
  86. package/dist/viem/Actions/token.js.map +1 -1
  87. package/dist/viem/Addresses.d.ts +1 -2
  88. package/dist/viem/Addresses.d.ts.map +1 -1
  89. package/dist/viem/Addresses.js +1 -2
  90. package/dist/viem/Addresses.js.map +1 -1
  91. package/dist/viem/Chain.d.ts +38 -12
  92. package/dist/viem/Chain.d.ts.map +1 -1
  93. package/dist/viem/Chain.js +27 -18
  94. package/dist/viem/Chain.js.map +1 -1
  95. package/dist/viem/Decorator.d.ts +1009 -428
  96. package/dist/viem/Decorator.d.ts.map +1 -1
  97. package/dist/viem/Decorator.js +17 -5
  98. package/dist/viem/Decorator.js.map +1 -1
  99. package/dist/viem/Formatters.d.ts +8 -1
  100. package/dist/viem/Formatters.d.ts.map +1 -1
  101. package/dist/viem/Formatters.js +17 -0
  102. package/dist/viem/Formatters.js.map +1 -1
  103. package/dist/viem/P256.d.ts +2 -0
  104. package/dist/viem/P256.d.ts.map +1 -0
  105. package/dist/viem/P256.js +2 -0
  106. package/dist/viem/P256.js.map +1 -0
  107. package/dist/viem/Secp256k1.d.ts +2 -0
  108. package/dist/viem/Secp256k1.d.ts.map +1 -0
  109. package/dist/viem/Secp256k1.js +2 -0
  110. package/dist/viem/Secp256k1.js.map +1 -0
  111. package/dist/viem/TokenIds.d.ts +1 -2
  112. package/dist/viem/TokenIds.d.ts.map +1 -1
  113. package/dist/viem/TokenIds.js +1 -2
  114. package/dist/viem/TokenIds.js.map +1 -1
  115. package/dist/viem/Transaction.d.ts +1 -1
  116. package/dist/viem/Transaction.d.ts.map +1 -1
  117. package/dist/viem/Transaction.js +46 -5
  118. package/dist/viem/Transaction.js.map +1 -1
  119. package/dist/viem/WebAuthnP256.d.ts +79 -0
  120. package/dist/viem/WebAuthnP256.d.ts.map +1 -0
  121. package/dist/viem/WebAuthnP256.js +95 -0
  122. package/dist/viem/WebAuthnP256.js.map +1 -0
  123. package/dist/viem/WebCryptoP256.d.ts +2 -0
  124. package/dist/viem/WebCryptoP256.d.ts.map +1 -0
  125. package/dist/viem/WebCryptoP256.js +2 -0
  126. package/dist/viem/WebCryptoP256.js.map +1 -0
  127. package/dist/viem/index.d.ts +6 -3
  128. package/dist/viem/index.d.ts.map +1 -1
  129. package/dist/viem/index.js +6 -3
  130. package/dist/viem/index.js.map +1 -1
  131. package/dist/viem/internal/account.d.ts +24 -0
  132. package/dist/viem/internal/account.d.ts.map +1 -0
  133. package/dist/viem/internal/account.js +68 -0
  134. package/dist/viem/internal/account.js.map +1 -0
  135. package/dist/viem/internal/types.d.ts +10 -0
  136. package/dist/viem/internal/types.d.ts.map +1 -1
  137. package/dist/wagmi/Actions/amm.d.ts +428 -0
  138. package/dist/wagmi/Actions/amm.d.ts.map +1 -0
  139. package/dist/wagmi/Actions/amm.js +472 -0
  140. package/dist/wagmi/Actions/amm.js.map +1 -0
  141. package/dist/wagmi/Actions/dex.d.ts +908 -0
  142. package/dist/wagmi/Actions/dex.d.ts.map +1 -0
  143. package/dist/wagmi/Actions/dex.js +1023 -0
  144. package/dist/wagmi/Actions/dex.js.map +1 -0
  145. package/dist/wagmi/Actions/faucet.d.ts +35 -0
  146. package/dist/wagmi/Actions/faucet.d.ts.map +1 -0
  147. package/dist/wagmi/Actions/faucet.js +33 -0
  148. package/dist/wagmi/Actions/faucet.js.map +1 -0
  149. package/dist/wagmi/Actions/fee.d.ts +111 -0
  150. package/dist/wagmi/Actions/fee.d.ts.map +1 -0
  151. package/dist/wagmi/Actions/fee.js +126 -0
  152. package/dist/wagmi/Actions/fee.js.map +1 -0
  153. package/dist/wagmi/Actions/index.d.ts +7 -0
  154. package/dist/wagmi/Actions/index.d.ts.map +1 -0
  155. package/dist/wagmi/Actions/index.js +7 -0
  156. package/dist/wagmi/Actions/index.js.map +1 -0
  157. package/dist/wagmi/Actions/reward.d.ts +348 -0
  158. package/dist/wagmi/Actions/reward.d.ts.map +1 -0
  159. package/dist/wagmi/Actions/reward.js +388 -0
  160. package/dist/wagmi/Actions/reward.js.map +1 -0
  161. package/dist/wagmi/Actions/token.d.ts +1546 -0
  162. package/dist/wagmi/Actions/token.d.ts.map +1 -0
  163. package/dist/wagmi/Actions/token.js +1712 -0
  164. package/dist/wagmi/Actions/token.js.map +1 -0
  165. package/dist/wagmi/Connector.d.ts +81 -0
  166. package/dist/wagmi/Connector.d.ts.map +1 -0
  167. package/dist/wagmi/Connector.js +261 -0
  168. package/dist/wagmi/Connector.js.map +1 -0
  169. package/dist/wagmi/Hooks/amm.d.ts +421 -0
  170. package/dist/wagmi/Hooks/amm.d.ts.map +1 -0
  171. package/dist/wagmi/Hooks/amm.js +504 -0
  172. package/dist/wagmi/Hooks/amm.js.map +1 -0
  173. package/dist/wagmi/Hooks/dex.d.ts +816 -0
  174. package/dist/wagmi/Hooks/dex.d.ts.map +1 -0
  175. package/dist/wagmi/Hooks/dex.js +973 -0
  176. package/dist/wagmi/Hooks/dex.js.map +1 -0
  177. package/dist/wagmi/Hooks/faucet.d.ts +39 -0
  178. package/dist/wagmi/Hooks/faucet.d.ts.map +1 -0
  179. package/dist/wagmi/Hooks/faucet.js +40 -0
  180. package/dist/wagmi/Hooks/faucet.js.map +1 -0
  181. package/dist/wagmi/Hooks/fee.d.ts +97 -0
  182. package/dist/wagmi/Hooks/fee.d.ts.map +1 -0
  183. package/dist/wagmi/Hooks/fee.js +109 -0
  184. package/dist/wagmi/Hooks/fee.js.map +1 -0
  185. package/dist/wagmi/Hooks/index.d.ts +7 -0
  186. package/dist/wagmi/Hooks/index.d.ts.map +1 -0
  187. package/dist/wagmi/Hooks/index.js +7 -0
  188. package/dist/wagmi/Hooks/index.js.map +1 -0
  189. package/dist/wagmi/Hooks/reward.d.ts +307 -0
  190. package/dist/wagmi/Hooks/reward.d.ts.map +1 -0
  191. package/dist/wagmi/Hooks/reward.js +349 -0
  192. package/dist/wagmi/Hooks/reward.js.map +1 -0
  193. package/dist/wagmi/Hooks/token.d.ts +1388 -0
  194. package/dist/wagmi/Hooks/token.d.ts.map +1 -0
  195. package/dist/wagmi/Hooks/token.js +1657 -0
  196. package/dist/wagmi/Hooks/token.js.map +1 -0
  197. package/dist/wagmi/index.d.ts +4 -0
  198. package/dist/wagmi/index.d.ts.map +1 -0
  199. package/dist/wagmi/index.js +4 -0
  200. package/dist/wagmi/index.js.map +1 -0
  201. package/package.json +54 -10
  202. package/src/chains.ts +21 -9
  203. package/src/ox/Order.test.ts +78 -0
  204. package/src/ox/Order.ts +125 -0
  205. package/src/ox/OrdersFilters.test.ts +182 -0
  206. package/src/ox/OrdersFilters.ts +125 -0
  207. package/src/ox/Pagination.test.ts +162 -0
  208. package/src/ox/Pagination.ts +164 -0
  209. package/src/ox/PoolId.test.ts +33 -0
  210. package/src/ox/PoolId.ts +27 -0
  211. package/src/ox/RpcSchema.ts +35 -0
  212. package/src/ox/SignatureEnvelope.ts +3 -1
  213. package/src/{viem → ox}/Tick.test.ts +1 -1
  214. package/src/{viem → ox}/Tick.ts +5 -0
  215. package/src/ox/Transaction.test.ts +1 -1
  216. package/src/ox/Transaction.ts +2 -1
  217. package/src/ox/TransactionEnvelopeAA.test.ts +239 -96
  218. package/src/ox/TransactionEnvelopeAA.ts +9 -7
  219. package/src/ox/TransactionRequest.ts +4 -0
  220. package/src/ox/index.ts +6 -0
  221. package/src/prool/Instance.ts +51 -37
  222. package/src/prool/internal/chain.json +104 -52
  223. package/src/tsconfig.json +9 -0
  224. package/src/viem/Abis.ts +972 -710
  225. package/src/viem/Account.ts +279 -0
  226. package/src/viem/Actions/__snapshots__/dex.test.ts.snap +850 -0
  227. package/src/viem/Actions/amm.test.ts +173 -169
  228. package/src/viem/Actions/amm.ts +131 -203
  229. package/src/viem/Actions/dex.test.ts +563 -484
  230. package/src/viem/Actions/dex.ts +203 -30
  231. package/src/viem/Actions/faucet.ts +50 -0
  232. package/src/viem/Actions/fee.test.ts +23 -34
  233. package/src/viem/Actions/fee.ts +20 -13
  234. package/src/viem/Actions/index.ts +2 -0
  235. package/src/viem/Actions/policy.test.ts +19 -33
  236. package/src/viem/Actions/policy.ts +46 -46
  237. package/src/viem/Actions/reward.test.ts +457 -0
  238. package/src/viem/Actions/reward.ts +999 -0
  239. package/src/viem/Actions/token.test.ts +453 -287
  240. package/src/viem/Actions/token.ts +605 -693
  241. package/src/viem/Addresses.ts +1 -2
  242. package/src/viem/Chain.bench-d.ts +12 -0
  243. package/src/viem/Chain.ts +70 -20
  244. package/src/viem/Decorator.bench-d.ts +1 -1
  245. package/src/viem/Decorator.test.ts +3 -1
  246. package/src/viem/Decorator.ts +1049 -442
  247. package/src/viem/Formatters.ts +31 -5
  248. package/src/viem/P256.ts +1 -0
  249. package/src/viem/Secp256k1.ts +1 -0
  250. package/src/viem/TokenIds.ts +1 -2
  251. package/src/viem/Transaction.ts +53 -7
  252. package/src/viem/WebAuthnP256.ts +140 -0
  253. package/src/viem/WebCryptoP256.ts +1 -0
  254. package/src/viem/e2e.test.ts +1126 -297
  255. package/src/viem/index.ts +6 -3
  256. package/src/viem/internal/account.ts +107 -0
  257. package/src/viem/internal/types.ts +9 -0
  258. package/src/wagmi/Actions/__snapshots__/dex.test.ts.snap +310 -0
  259. package/src/wagmi/Actions/amm.test.ts +198 -0
  260. package/src/wagmi/Actions/amm.ts +691 -0
  261. package/src/wagmi/Actions/dex.test.ts +1507 -0
  262. package/src/wagmi/Actions/dex.ts +1640 -0
  263. package/src/wagmi/Actions/faucet.ts +46 -0
  264. package/src/wagmi/Actions/fee.test.ts +63 -0
  265. package/src/wagmi/Actions/fee.ts +208 -0
  266. package/src/wagmi/Actions/index.ts +6 -0
  267. package/src/wagmi/Actions/reward.test.ts +210 -0
  268. package/src/wagmi/Actions/reward.ts +632 -0
  269. package/src/wagmi/Actions/token.test.ts +1308 -0
  270. package/src/wagmi/Actions/token.ts +2613 -0
  271. package/src/wagmi/Connector.test.ts +53 -0
  272. package/src/wagmi/Connector.ts +390 -0
  273. package/src/wagmi/Hooks/__snapshots__/dex.test.ts.snap +457 -0
  274. package/src/wagmi/Hooks/amm.test.ts +424 -0
  275. package/src/wagmi/Hooks/amm.ts +806 -0
  276. package/src/wagmi/Hooks/dex.test.ts +1017 -0
  277. package/src/wagmi/Hooks/dex.ts +1685 -0
  278. package/src/wagmi/Hooks/faucet.ts +76 -0
  279. package/src/wagmi/Hooks/fee.test.ts +166 -0
  280. package/src/wagmi/Hooks/fee.ts +206 -0
  281. package/src/wagmi/Hooks/index.ts +6 -0
  282. package/src/wagmi/Hooks/reward.test.ts +219 -0
  283. package/src/wagmi/Hooks/reward.ts +672 -0
  284. package/src/wagmi/Hooks/token.test.ts +1670 -0
  285. package/src/wagmi/Hooks/token.ts +2906 -0
  286. package/src/wagmi/index.ts +3 -0
  287. package/src/wagmi/internal/types.ts +16 -0
  288. package/dist/viem/Client.d.ts +0 -27
  289. package/dist/viem/Client.d.ts.map +0 -1
  290. package/dist/viem/Client.js +0 -28
  291. package/dist/viem/Client.js.map +0 -1
  292. package/dist/viem/Tick.d.ts.map +0 -1
  293. package/dist/viem/Tick.js.map +0 -1
  294. package/src/viem/Client.bench-d.ts +0 -8
  295. package/src/viem/Client.test.ts +0 -178
  296. package/src/viem/Client.ts +0 -91
  297. /package/dist/{viem → ox}/Tick.js +0 -0
@@ -0,0 +1,999 @@
1
+ import {
2
+ type Account,
3
+ type Address,
4
+ type BaseErrorType,
5
+ type Chain,
6
+ type Client,
7
+ type Log,
8
+ parseEventLogs,
9
+ type ReadContractReturnType,
10
+ type Transport,
11
+ type WriteContractReturnType,
12
+ } from 'viem'
13
+ import { readContract, writeContract, writeContractSync } from 'viem/actions'
14
+ import * as Abis from '../Abis.js'
15
+ import type { ReadParameters, WriteParameters } from '../internal/types.js'
16
+ import { defineCall } from '../internal/utils.js'
17
+
18
+ /**
19
+ * Cancels an active reward stream and refunds remaining tokens.
20
+ *
21
+ * - Callable only by the stream's funder.
22
+ * - Stops future emission for the stream at the current block timestamp.
23
+ * - Computes the refund as `amountTotal - distributedSoFar` and attempts to transfer it back to the funder.
24
+ * - If the refund transfer is forbidden by TIP-403, the stream is still canceled but `refund` will be 0 in the event.
25
+ * - Reverts with `StreamInactive` if the stream doesn't exist, is already canceled, or has already ended.
26
+ * - Reverts with `NotStreamFunder` if the caller is not the stream's funder.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import { createClient, http } from 'viem'
31
+ * import { tempo } from 'tempo.ts/chains'
32
+ * import { Actions } from 'tempo.ts/viem'
33
+ * import { privateKeyToAccount } from 'viem/accounts'
34
+ *
35
+ * const client = createClient({
36
+ * account: privateKeyToAccount('0x...'),
37
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
38
+ * transport: http(),
39
+ * })
40
+ *
41
+ * const hash = await Actions.rewards.cancel(client, {
42
+ * id: 1n,
43
+ * token: '0x20c0000000000000000000000000000000000001',
44
+ * })
45
+ * ```
46
+ *
47
+ * @param client - Client.
48
+ * @param parameters - Parameters.
49
+ * @returns The transaction hash.
50
+ */
51
+ export async function cancel<
52
+ chain extends Chain | undefined,
53
+ account extends Account | undefined,
54
+ >(
55
+ client: Client<Transport, chain, account>,
56
+ parameters: cancel.Parameters<chain, account>,
57
+ ): Promise<cancel.ReturnValue> {
58
+ return cancel.inner(writeContract, client, parameters)
59
+ }
60
+
61
+ /**
62
+ * Cancels an active reward stream and waits for confirmation.
63
+ *
64
+ * - Callable only by the stream's funder.
65
+ * - Stops future emission for the stream at the current block timestamp.
66
+ * - Computes the refund as `amountTotal - distributedSoFar` and attempts to transfer it back to the funder.
67
+ * - If the refund transfer is forbidden by TIP-403, the stream is still canceled but `refund` will be 0.
68
+ * - Reverts with `StreamInactive` if the stream doesn't exist, is already canceled, or has already ended.
69
+ * - Reverts with `NotStreamFunder` if the caller is not the stream's funder.
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * import { createClient, http } from 'viem'
74
+ * import { tempo } from 'tempo.ts/chains'
75
+ * import { Actions } from 'tempo.ts/viem'
76
+ * import { privateKeyToAccount } from 'viem/accounts'
77
+ *
78
+ * const client = createClient({
79
+ * account: privateKeyToAccount('0x...'),
80
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
81
+ * transport: http(),
82
+ * })
83
+ *
84
+ * const { funder, id, refund, receipt } = await Actions.rewards.cancelSync(client, {
85
+ * id: 1n,
86
+ * token: '0x20c0000000000000000000000000000000000001',
87
+ * })
88
+ * ```
89
+ *
90
+ * @param client - Client.
91
+ * @param parameters - Parameters.
92
+ * @returns The funder, stream ID, refund amount, and transaction receipt.
93
+ */
94
+ export async function cancelSync<
95
+ chain extends Chain | undefined,
96
+ account extends Account | undefined,
97
+ >(
98
+ client: Client<Transport, chain, account>,
99
+ parameters: cancelSync.Parameters<chain, account>,
100
+ ): Promise<cancelSync.ReturnValue> {
101
+ const { throwOnReceiptRevert = true, ...rest } = parameters
102
+ const receipt = await cancel.inner(writeContractSync, client, {
103
+ ...rest,
104
+ throwOnReceiptRevert,
105
+ } as never)
106
+ const { args } = cancel.extractEvent(receipt.logs)
107
+ return {
108
+ ...args,
109
+ receipt,
110
+ } as never
111
+ }
112
+
113
+ export namespace cancel {
114
+ export type Args = {
115
+ /** The unique stream ID to cancel (must be owned by the caller) */
116
+ id: bigint
117
+ /** The TIP20 token address containing the reward stream */
118
+ token: Address
119
+ }
120
+
121
+ export type Parameters<
122
+ chain extends Chain | undefined = Chain | undefined,
123
+ account extends Account | undefined = Account | undefined,
124
+ > = WriteParameters<chain, account> & Args
125
+
126
+ export type ReturnValue = WriteContractReturnType
127
+
128
+ // TODO: exhaustive error type
129
+ export type ErrorType = BaseErrorType
130
+
131
+ /** @internal */
132
+ export async function inner<
133
+ action extends typeof writeContract | typeof writeContractSync,
134
+ chain extends Chain | undefined,
135
+ account extends Account | undefined,
136
+ >(
137
+ action: action,
138
+ client: Client<Transport, chain, account>,
139
+ parameters: Parameters<chain, account>,
140
+ ): Promise<ReturnType<action>> {
141
+ const { id, token, ...rest } = parameters
142
+ const call = cancel.call({ id, token })
143
+ return (await action(client, {
144
+ ...rest,
145
+ ...call,
146
+ } as never)) as never
147
+ }
148
+
149
+ /**
150
+ * Defines a call to the `cancel` function.
151
+ *
152
+ * Can be passed as a parameter to:
153
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
154
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
155
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * import { createClient, http, walletActions } from 'viem'
160
+ * import { tempo } from 'tempo.ts/chains'
161
+ * import { Actions } from 'tempo.ts/viem'
162
+ *
163
+ * const client = createClient({
164
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
165
+ * transport: http(),
166
+ * }).extend(walletActions)
167
+ *
168
+ * const hash = await client.sendTransaction({
169
+ * calls: [actions.rewards.cancel.call({
170
+ * id: 1n,
171
+ * token: '0x20c0000000000000000000000000000000000001',
172
+ * })],
173
+ * })
174
+ * ```
175
+ *
176
+ * @param args - Arguments.
177
+ * @returns The call.
178
+ */
179
+ export function call(args: Args) {
180
+ const { id, token } = args
181
+ return defineCall({
182
+ address: token,
183
+ abi: Abis.tip20,
184
+ args: [id],
185
+ functionName: 'cancelReward',
186
+ })
187
+ }
188
+
189
+ /**
190
+ * Extracts the `RewardCanceled` event from logs.
191
+ *
192
+ * @param logs - The logs.
193
+ * @returns The `RewardCanceled` event.
194
+ */
195
+ export function extractEvent(logs: Log[]) {
196
+ const [log] = parseEventLogs({
197
+ abi: Abis.tip20,
198
+ logs,
199
+ eventName: 'RewardCanceled',
200
+ strict: true,
201
+ })
202
+ if (!log) throw new Error('`RewardCanceled` event not found.')
203
+ return log
204
+ }
205
+ }
206
+
207
+ export declare namespace cancelSync {
208
+ export type Parameters<
209
+ chain extends Chain | undefined = Chain | undefined,
210
+ account extends Account | undefined = Account | undefined,
211
+ > = WriteParameters<chain, account> & cancel.Args
212
+
213
+ export type ReturnValue = {
214
+ /** The address that funded the stream */
215
+ funder: Address
216
+ /** The stream ID that was canceled */
217
+ id: bigint
218
+ /** The transaction receipt */
219
+ receipt: Awaited<ReturnType<typeof writeContractSync>>
220
+ /** The amount refunded to the funder (0 if TIP-403 policy forbids the refund transfer) */
221
+ refund: bigint
222
+ }
223
+
224
+ export type ErrorType = cancel.ErrorType
225
+ }
226
+
227
+ /**
228
+ * Claims accumulated rewards for a recipient.
229
+ *
230
+ * This function allows a reward recipient to claim their accumulated rewards
231
+ * and receive them as token transfers to their own balance.
232
+ *
233
+ * - Accrues all pending rewards up to the current block timestamp.
234
+ * - Updates the caller's reward accounting.
235
+ * - Transfers the caller's accumulated `rewardBalance` from the token contract to the caller.
236
+ * - If the contract's balance is insufficient, claims up to the available amount.
237
+ * - Returns the actual amount claimed.
238
+ *
239
+ * Notes:
240
+ * - Reverts with `Paused` if the token is paused.
241
+ * - Reverts with `PolicyForbids` if the caller is not authorized to receive tokens under TIP-403.
242
+ * - If opted in, the claimed amount is added back to `optedInSupply` since it goes to the recipient's balance.
243
+ *
244
+ * @example
245
+ * ```ts
246
+ * import { createClient, http } from 'viem'
247
+ * import { tempo } from 'tempo.ts/chains'
248
+ * import { Actions } from 'tempo.ts/viem'
249
+ * import { privateKeyToAccount } from 'viem/accounts'
250
+ *
251
+ * const client = createClient({
252
+ * account: privateKeyToAccount('0x...'),
253
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
254
+ * transport: http(),
255
+ * })
256
+ *
257
+ * const hash = await Actions.reward.claim(client, {
258
+ * token: '0x20c0000000000000000000000000000000000001',
259
+ * })
260
+ * ```
261
+ *
262
+ * @param client - Client.
263
+ * @param parameters - Parameters.
264
+ * @returns The transaction hash.
265
+ */
266
+ export async function claim<
267
+ chain extends Chain | undefined,
268
+ account extends Account | undefined,
269
+ >(
270
+ client: Client<Transport, chain, account>,
271
+ parameters: claim.Parameters<chain, account>,
272
+ ): Promise<claim.ReturnValue> {
273
+ return claim.inner(writeContract, client, parameters)
274
+ }
275
+
276
+ export namespace claim {
277
+ export type Args = {
278
+ /** The TIP20 token address */
279
+ token: Address
280
+ }
281
+
282
+ export type Parameters<
283
+ chain extends Chain | undefined = Chain | undefined,
284
+ account extends Account | undefined = Account | undefined,
285
+ > = WriteParameters<chain, account> & Args
286
+
287
+ export type ReturnValue = WriteContractReturnType
288
+
289
+ // TODO: exhaustive error type
290
+ export type ErrorType = BaseErrorType
291
+
292
+ /** @internal */
293
+ export async function inner<
294
+ action extends typeof writeContract | typeof writeContractSync,
295
+ chain extends Chain | undefined,
296
+ account extends Account | undefined,
297
+ >(
298
+ action: action,
299
+ client: Client<Transport, chain, account>,
300
+ parameters: Parameters<chain, account>,
301
+ ): Promise<ReturnType<action>> {
302
+ const { token, ...rest } = parameters
303
+ const call = claim.call({ token })
304
+ return (await action(client, {
305
+ ...rest,
306
+ ...call,
307
+ } as never)) as never
308
+ }
309
+
310
+ /**
311
+ * Defines a call to the `claimRewards` function.
312
+ *
313
+ * Can be passed as a parameter to:
314
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
315
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
316
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
317
+ *
318
+ * @example
319
+ * ```ts
320
+ * import { createClient, http, walletActions } from 'viem'
321
+ * import { tempo } from 'tempo.ts/chains'
322
+ * import { Actions } from 'tempo.ts/viem'
323
+ *
324
+ * const client = createClient({
325
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
326
+ * transport: http(),
327
+ * }).extend(walletActions)
328
+ *
329
+ * const hash = await client.sendTransaction({
330
+ * calls: [actions.reward.claim.call({
331
+ * token: '0x20c0000000000000000000000000000000000001',
332
+ * })],
333
+ * })
334
+ * ```
335
+ *
336
+ * @param args - Arguments.
337
+ * @returns The call.
338
+ */
339
+ export function call(args: Args) {
340
+ const { token } = args
341
+ return defineCall({
342
+ address: token,
343
+ abi: Abis.tip20,
344
+ args: [],
345
+ functionName: 'claimRewards',
346
+ })
347
+ }
348
+ }
349
+
350
+ /**
351
+ * Claims accumulated rewards for a recipient and waits for confirmation.
352
+ *
353
+ * This function allows a reward recipient to claim their accumulated rewards
354
+ * and receive them as token transfers to their own balance.
355
+ *
356
+ * Behavior:
357
+ * - Accrues all pending rewards up to the current block timestamp.
358
+ * - Updates the caller's reward accounting.
359
+ * - Transfers the caller's accumulated `rewardBalance` from the token contract to the caller.
360
+ * - If the contract's balance is insufficient, claims up to the available amount.
361
+ *
362
+ * Notes:
363
+ * - Reverts with `Paused` if the token is paused.
364
+ * - Reverts with `PolicyForbids` if the caller is not authorized to receive tokens under TIP-403.
365
+ * - If opted in, the claimed amount is added back to `optedInSupply` since it goes to the recipient's balance.
366
+ *
367
+ * @example
368
+ * ```ts
369
+ * import { createClient, http } from 'viem'
370
+ * import { tempo } from 'tempo.ts/chains'
371
+ * import { Actions } from 'tempo.ts/viem'
372
+ * import { privateKeyToAccount } from 'viem/accounts'
373
+ *
374
+ * const client = createClient({
375
+ * account: privateKeyToAccount('0x...'),
376
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
377
+ * transport: http(),
378
+ * })
379
+ *
380
+ * const { receipt } = await Actions.reward.claimSync(client, {
381
+ * token: '0x20c0000000000000000000000000000000000001',
382
+ * })
383
+ * ```
384
+ *
385
+ * @param client - Client.
386
+ * @param parameters - Parameters.
387
+ * @returns The amount claimed and transaction receipt.
388
+ */
389
+ export async function claimSync<
390
+ chain extends Chain | undefined,
391
+ account extends Account | undefined,
392
+ >(
393
+ client: Client<Transport, chain, account>,
394
+ parameters: claimSync.Parameters<chain, account>,
395
+ ): Promise<claimSync.ReturnValue> {
396
+ const { throwOnReceiptRevert = true, ...rest } = parameters
397
+ const receipt = await claim.inner(writeContractSync, client, {
398
+ ...rest,
399
+ throwOnReceiptRevert,
400
+ } as never)
401
+ return {
402
+ receipt,
403
+ } as never
404
+ }
405
+
406
+ export namespace claimSync {
407
+ export type Parameters<
408
+ chain extends Chain | undefined = Chain | undefined,
409
+ account extends Account | undefined = Account | undefined,
410
+ > = WriteParameters<chain, account> & claim.Args
411
+
412
+ export type ReturnValue = {
413
+ /** The transaction receipt */
414
+ receipt: Awaited<ReturnType<typeof writeContractSync>>
415
+ }
416
+
417
+ export type ErrorType = claim.ErrorType
418
+ }
419
+
420
+ /**
421
+ * Gets a reward stream by its ID.
422
+ *
423
+ * Returns the stream details including:
424
+ * - `funder`: The address that funded the stream
425
+ * - `startTime`: When the stream started (block timestamp)
426
+ * - `endTime`: When the stream is scheduled to end
427
+ * - `ratePerSecondScaled`: The per-second emission rate (scaled by ACC_PRECISION = 1e18)
428
+ * - `amountTotal`: The total amount allocated to the stream
429
+ *
430
+ * Note: If the stream has been canceled or doesn't exist, `funder` will be the zero address.
431
+ *
432
+ * @example
433
+ * ```ts
434
+ * import { createClient, http } from 'viem'
435
+ * import { tempo } from 'tempo.ts/chains'
436
+ * import { Actions } from 'tempo.ts/viem'
437
+ *
438
+ * const client = createClient({
439
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
440
+ * transport: http(),
441
+ * })
442
+ *
443
+ * const stream = await Actions.rewards.getStream(client, {
444
+ * id: 1n,
445
+ * token: '0x20c0000000000000000000000000000000000001',
446
+ * })
447
+ * ```
448
+ *
449
+ * @param client - Client.
450
+ * @param parameters - Parameters.
451
+ * @returns The reward stream details.
452
+ */
453
+ export async function getStream<chain extends Chain | undefined>(
454
+ client: Client<Transport, chain>,
455
+ parameters: getStream.Parameters,
456
+ ): Promise<getStream.ReturnValue> {
457
+ return readContract(client, {
458
+ ...parameters,
459
+ ...getStream.call(parameters),
460
+ })
461
+ }
462
+
463
+ export namespace getStream {
464
+ export type Parameters = ReadParameters & Args
465
+
466
+ export type Args = {
467
+ /** The stream ID to query (0 is never used for streams, only for immediate distributions) */
468
+ id: bigint
469
+ /** The TIP20 token address */
470
+ token: Address
471
+ }
472
+
473
+ export type ReturnValue = ReadContractReturnType<
474
+ typeof Abis.tip20,
475
+ 'getStream',
476
+ never
477
+ >
478
+
479
+ /**
480
+ * Defines a call to the `getStream` function.
481
+ *
482
+ * @param args - Arguments.
483
+ * @returns The call.
484
+ */
485
+ export function call(args: Args) {
486
+ const { id, token } = args
487
+ return defineCall({
488
+ address: token,
489
+ abi: Abis.tip20,
490
+ args: [id],
491
+ functionName: 'getStream',
492
+ })
493
+ }
494
+ }
495
+
496
+ /**
497
+ * Gets the total reward per second rate for all active streams.
498
+ *
499
+ * Returns the current aggregate per-second emission rate scaled by `ACC_PRECISION` (1e18).
500
+ * This value represents the sum of all active reward streams' emission rates.
501
+ * The rate decreases when streams end (via `finalizeStreams`) or are canceled.
502
+ *
503
+ * @example
504
+ * ```ts
505
+ * import { createClient, http } from 'viem'
506
+ * import { tempo } from 'tempo.ts/chains'
507
+ * import { Actions } from 'tempo.ts/viem'
508
+ *
509
+ * const client = createClient({
510
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
511
+ * transport: http(),
512
+ * })
513
+ *
514
+ * const rate = await Actions.rewards.getTotalPerSecond(client, {
515
+ * token: '0x20c0000000000000000000000000000000000001',
516
+ * })
517
+ * ```
518
+ *
519
+ * @param client - Client.
520
+ * @param parameters - Parameters.
521
+ * @returns The total reward per second (scaled by 1e18).
522
+ */
523
+ export async function getTotalPerSecond<chain extends Chain | undefined>(
524
+ client: Client<Transport, chain>,
525
+ parameters: getTotalPerSecond.Parameters,
526
+ ): Promise<getTotalPerSecond.ReturnValue> {
527
+ return readContract(client, {
528
+ ...parameters,
529
+ ...getTotalPerSecond.call(parameters),
530
+ })
531
+ }
532
+
533
+ export namespace getTotalPerSecond {
534
+ export type Parameters = ReadParameters & Args
535
+
536
+ export type Args = {
537
+ /** The TIP20 token address */
538
+ token: Address
539
+ }
540
+
541
+ export type ReturnValue = ReadContractReturnType<
542
+ typeof Abis.tip20,
543
+ 'totalRewardPerSecond',
544
+ never
545
+ >
546
+
547
+ /**
548
+ * Defines a call to the `totalRewardPerSecond` function.
549
+ *
550
+ * @param args - Arguments.
551
+ * @returns The call.
552
+ */
553
+ export function call(args: Args) {
554
+ const { token } = args
555
+ return defineCall({
556
+ address: token,
557
+ abi: Abis.tip20,
558
+ args: [],
559
+ functionName: 'totalRewardPerSecond',
560
+ })
561
+ }
562
+ }
563
+
564
+ /**
565
+ * Sets or changes the reward recipient for a token holder.
566
+ *
567
+ * This function allows a token holder to designate who should receive their share of rewards:
568
+ * - If `recipient` is the zero address, opts out from rewards distribution.
569
+ * - Otherwise, opts in and sets `recipient` as the address that will receive accrued rewards.
570
+ * - Can be called with `recipient == msg.sender` to receive rewards directly.
571
+ * - Automatically distributes any accrued rewards to the current recipient before changing.
572
+ *
573
+ * TIP-403 Policy:
574
+ * - Reverts with `PolicyForbids` if `recipient` is not the zero address and either the holder or recipient is not authorized to receive tokens under the token's transfer policy.
575
+ *
576
+ * @example
577
+ * ```ts
578
+ * import { createClient, http } from 'viem'
579
+ * import { tempo } from 'tempo.ts/chains'
580
+ * import { Actions } from 'tempo.ts/viem'
581
+ * import { privateKeyToAccount } from 'viem/accounts'
582
+ *
583
+ * const client = createClient({
584
+ * account: privateKeyToAccount('0x...'),
585
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
586
+ * transport: http(),
587
+ * })
588
+ *
589
+ * const hash = await Actions.rewards.setRecipient(client, {
590
+ * recipient: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
591
+ * token: '0x20c0000000000000000000000000000000000001',
592
+ * })
593
+ * ```
594
+ *
595
+ * @param client - Client.
596
+ * @param parameters - Parameters.
597
+ * @returns The transaction hash.
598
+ */
599
+ export async function setRecipient<
600
+ chain extends Chain | undefined,
601
+ account extends Account | undefined,
602
+ >(
603
+ client: Client<Transport, chain, account>,
604
+ parameters: setRecipient.Parameters<chain, account>,
605
+ ): Promise<setRecipient.ReturnValue> {
606
+ return setRecipient.inner(writeContract, client, parameters)
607
+ }
608
+
609
+ /**
610
+ * Sets or changes the reward recipient for a token holder and waits for confirmation.
611
+ *
612
+ * This function allows a token holder to designate who should receive their share of rewards:
613
+ * - If `recipient` is the zero address, opts out from rewards distribution.
614
+ * - Otherwise, opts in and sets `recipient` as the address that will receive accrued rewards.
615
+ * - Can be called with `recipient == msg.sender` to receive rewards directly.
616
+ * - Automatically distributes any accrued rewards to the current recipient before changing.
617
+ *
618
+ * TIP-403 Policy:
619
+ * - Reverts with `PolicyForbids` if `recipient` is not the zero address and either the holder or recipient is not authorized to receive tokens under the token's transfer policy.
620
+ *
621
+ * @example
622
+ * ```ts
623
+ * import { createClient, http } from 'viem'
624
+ * import { tempo } from 'tempo.ts/chains'
625
+ * import { Actions } from 'tempo.ts/viem'
626
+ * import { privateKeyToAccount } from 'viem/accounts'
627
+ *
628
+ * const client = createClient({
629
+ * account: privateKeyToAccount('0x...'),
630
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
631
+ * transport: http(),
632
+ * })
633
+ *
634
+ * const { holder, recipient, receipt } = await Actions.rewards.setRecipientSync(client, {
635
+ * recipient: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
636
+ * token: '0x20c0000000000000000000000000000000000001',
637
+ * })
638
+ * ```
639
+ *
640
+ * @param client - Client.
641
+ * @param parameters - Parameters.
642
+ * @returns The holder, recipient, and transaction receipt.
643
+ */
644
+ export async function setRecipientSync<
645
+ chain extends Chain | undefined,
646
+ account extends Account | undefined,
647
+ >(
648
+ client: Client<Transport, chain, account>,
649
+ parameters: setRecipientSync.Parameters<chain, account>,
650
+ ): Promise<setRecipientSync.ReturnValue> {
651
+ const { throwOnReceiptRevert = true, ...rest } = parameters
652
+ const receipt = await setRecipient.inner(writeContractSync, client, {
653
+ ...rest,
654
+ throwOnReceiptRevert,
655
+ } as never)
656
+ const { args } = setRecipient.extractEvent(receipt.logs)
657
+ return {
658
+ ...args,
659
+ receipt,
660
+ } as never
661
+ }
662
+
663
+ export namespace setRecipient {
664
+ export type Args = {
665
+ /** The reward recipient address (use zero address to opt out of rewards) */
666
+ recipient: Address
667
+ /** The TIP20 token address */
668
+ token: Address
669
+ }
670
+
671
+ export type Parameters<
672
+ chain extends Chain | undefined = Chain | undefined,
673
+ account extends Account | undefined = Account | undefined,
674
+ > = WriteParameters<chain, account> & Args
675
+
676
+ export type ReturnValue = WriteContractReturnType
677
+
678
+ // TODO: exhaustive error type
679
+ export type ErrorType = BaseErrorType
680
+
681
+ /** @internal */
682
+ export async function inner<
683
+ action extends typeof writeContract | typeof writeContractSync,
684
+ chain extends Chain | undefined,
685
+ account extends Account | undefined,
686
+ >(
687
+ action: action,
688
+ client: Client<Transport, chain, account>,
689
+ parameters: Parameters<chain, account>,
690
+ ): Promise<ReturnType<action>> {
691
+ const { recipient, token, ...rest } = parameters
692
+ const call = setRecipient.call({ recipient, token })
693
+ return (await action(client, {
694
+ ...rest,
695
+ ...call,
696
+ } as never)) as never
697
+ }
698
+
699
+ /**
700
+ * Defines a call to the `setRecipient` function.
701
+ *
702
+ * Can be passed as a parameter to:
703
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
704
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
705
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
706
+ *
707
+ * @example
708
+ * ```ts
709
+ * import { createClient, http, walletActions } from 'viem'
710
+ * import { tempo } from 'tempo.ts/chains'
711
+ * import { Actions } from 'tempo.ts/viem'
712
+ *
713
+ * const client = createClient({
714
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
715
+ * transport: http(),
716
+ * }).extend(walletActions)
717
+ *
718
+ * const hash = await client.sendTransaction({
719
+ * calls: [actions.rewards.setRecipient.call({
720
+ * recipient: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
721
+ * token: '0x20c0000000000000000000000000000000000001',
722
+ * })],
723
+ * })
724
+ * ```
725
+ *
726
+ * @param args - Arguments.
727
+ * @returns The call.
728
+ */
729
+ export function call(args: Args) {
730
+ const { recipient, token } = args
731
+ return defineCall({
732
+ address: token,
733
+ abi: Abis.tip20,
734
+ args: [recipient],
735
+ functionName: 'setRewardRecipient',
736
+ })
737
+ }
738
+
739
+ /**
740
+ * Extracts the `RewardRecipientSet` event from logs.
741
+ *
742
+ * @param logs - The logs.
743
+ * @returns The `RewardRecipientSet` event.
744
+ */
745
+ export function extractEvent(logs: Log[]) {
746
+ const [log] = parseEventLogs({
747
+ abi: Abis.tip20,
748
+ logs,
749
+ eventName: 'RewardRecipientSet',
750
+ strict: true,
751
+ })
752
+ if (!log) throw new Error('`RewardRecipientSet` event not found.')
753
+ return log
754
+ }
755
+ }
756
+
757
+ export declare namespace setRecipientSync {
758
+ export type Parameters<
759
+ chain extends Chain | undefined = Chain | undefined,
760
+ account extends Account | undefined = Account | undefined,
761
+ > = WriteParameters<chain, account> & setRecipient.Args
762
+
763
+ export type ReturnValue = {
764
+ /** The token holder address who set their reward recipient */
765
+ holder: Address
766
+ /** The transaction receipt */
767
+ receipt: Awaited<ReturnType<typeof writeContractSync>>
768
+ /** The reward recipient address (zero address indicates opt-out) */
769
+ recipient: Address
770
+ }
771
+
772
+ export type ErrorType = setRecipient.ErrorType
773
+ }
774
+
775
+ /**
776
+ * Starts a new reward stream that distributes tokens to opted-in holders.
777
+ *
778
+ * Behavior:
779
+ * - Transfers `amount` of tokens from the caller into the token contract's reward pool.
780
+ * - If `seconds == 0`: Immediately distributes `amount` to current opted-in holders by increasing `rewardPerTokenStored`.
781
+ * Returns stream ID `0`. Distribution occurs when holders interact with the token (transfers, etc.).
782
+ * - If `seconds > 0`: Starts a linear stream that emits evenly from `block.timestamp` to `block.timestamp + seconds`.
783
+ * Returns a unique stream ID for later cancellation.
784
+ *
785
+ * Notes:
786
+ * - Reverts with `InvalidAmount` if `amount == 0`.
787
+ * - Allowed even when `optedInSupply == 0` (tokens distributed while no one is opted in are locked permanently).
788
+ * - The transfer from caller to pool is subject to TIP-403 policy checks.
789
+ *
790
+ * @example
791
+ * ```ts
792
+ * import { createClient, http } from 'viem'
793
+ * import { tempo } from 'tempo.ts/chains'
794
+ * import { Actions } from 'tempo.ts/viem'
795
+ * import { privateKeyToAccount } from 'viem/accounts'
796
+ *
797
+ * const client = createClient({
798
+ * account: privateKeyToAccount('0x...'),
799
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
800
+ * transport: http(),
801
+ * })
802
+ *
803
+ * const hash = await Actions.rewards.start(client, {
804
+ * amount: 100000000000000000000n,
805
+ * seconds: 86400,
806
+ * token: '0x20c0000000000000000000000000000000000001',
807
+ * })
808
+ * ```
809
+ *
810
+ * @param client - Client.
811
+ * @param parameters - Parameters.
812
+ * @returns The transaction hash.
813
+ */
814
+ export async function start<
815
+ chain extends Chain | undefined,
816
+ account extends Account | undefined,
817
+ >(
818
+ client: Client<Transport, chain, account>,
819
+ parameters: start.Parameters<chain, account>,
820
+ ): Promise<start.ReturnValue> {
821
+ return start.inner(writeContract, client, parameters)
822
+ }
823
+
824
+ /**
825
+ * Starts a new reward stream that distributes tokens to opted-in holders and waits for confirmation.
826
+ *
827
+ * Behavior:
828
+ * - Transfers `amount` of tokens from the caller into the token contract's reward pool.
829
+ * - If `seconds == 0`: Immediately distributes `amount` to current opted-in holders by increasing `rewardPerTokenStored`.
830
+ * Returns stream ID `0`. Distribution occurs when holders interact with the token (transfers, etc.).
831
+ * - If `seconds > 0`: Starts a linear stream that emits evenly from `block.timestamp` to `block.timestamp + seconds`.
832
+ * Returns a unique stream ID for later cancellation.
833
+ *
834
+ * Notes:
835
+ * - Reverts with `InvalidAmount` if `amount == 0`.
836
+ * - Allowed even when `optedInSupply == 0` (tokens distributed while no one is opted in are locked permanently).
837
+ * - The transfer from caller to pool is subject to TIP-403 policy checks.
838
+ *
839
+ * @example
840
+ * ```ts
841
+ * import { createClient, http } from 'viem'
842
+ * import { tempo } from 'tempo.ts/chains'
843
+ * import { Actions } from 'tempo.ts/viem'
844
+ * import { privateKeyToAccount } from 'viem/accounts'
845
+ *
846
+ * const client = createClient({
847
+ * account: privateKeyToAccount('0x...'),
848
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
849
+ * transport: http(),
850
+ * })
851
+ *
852
+ * const { id, receipt } = await Actions.rewards.startSync(client, {
853
+ * amount: 100000000000000000000n,
854
+ * seconds: 86400,
855
+ * token: '0x20c0000000000000000000000000000000000001',
856
+ * })
857
+ * ```
858
+ *
859
+ * @param client - Client.
860
+ * @param parameters - Parameters.
861
+ * @returns The stream ID, funder, amount, duration, and transaction receipt.
862
+ */
863
+ export async function startSync<
864
+ chain extends Chain | undefined,
865
+ account extends Account | undefined,
866
+ >(
867
+ client: Client<Transport, chain, account>,
868
+ parameters: startSync.Parameters<chain, account>,
869
+ ): Promise<startSync.ReturnValue> {
870
+ const { throwOnReceiptRevert = true, ...rest } = parameters
871
+ const receipt = await start.inner(writeContractSync, client, {
872
+ ...rest,
873
+ throwOnReceiptRevert,
874
+ } as never)
875
+ const { args } = start.extractEvent(receipt.logs)
876
+ return {
877
+ ...args,
878
+ receipt,
879
+ } as never
880
+ }
881
+
882
+ export namespace start {
883
+ export type Args = {
884
+ /** The amount of tokens to distribute (must be > 0) */
885
+ amount: bigint
886
+ /** The duration in seconds (0 for immediate distribution, >0 for linear streaming) */
887
+ seconds: number
888
+ /** The TIP20 token address */
889
+ token: Address
890
+ }
891
+
892
+ export type Parameters<
893
+ chain extends Chain | undefined = Chain | undefined,
894
+ account extends Account | undefined = Account | undefined,
895
+ > = WriteParameters<chain, account> & Args
896
+
897
+ export type ReturnValue = WriteContractReturnType
898
+
899
+ // TODO: exhaustive error type
900
+ export type ErrorType = BaseErrorType
901
+
902
+ /** @internal */
903
+ export async function inner<
904
+ action extends typeof writeContract | typeof writeContractSync,
905
+ chain extends Chain | undefined,
906
+ account extends Account | undefined,
907
+ >(
908
+ action: action,
909
+ client: Client<Transport, chain, account>,
910
+ parameters: Parameters<chain, account>,
911
+ ): Promise<ReturnType<action>> {
912
+ const { amount, seconds, token, ...rest } = parameters
913
+ const call = start.call({ amount, seconds, token })
914
+ return (await action(client, {
915
+ ...rest,
916
+ ...call,
917
+ } as never)) as never
918
+ }
919
+
920
+ /**
921
+ * Defines a call to the `start` function.
922
+ *
923
+ * Can be passed as a parameter to:
924
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
925
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
926
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
927
+ *
928
+ * @example
929
+ * ```ts
930
+ * import { createClient, http, walletActions } from 'viem'
931
+ * import { tempo } from 'tempo.ts/chains'
932
+ * import { Actions } from 'tempo.ts/viem'
933
+ *
934
+ * const client = createClient({
935
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
936
+ * transport: http(),
937
+ * }).extend(walletActions)
938
+ *
939
+ * const hash = await client.sendTransaction({
940
+ * calls: [actions.rewards.start.call({
941
+ * amount: 100000000000000000000n,
942
+ * seconds: 86400,
943
+ * token: '0x20c0000000000000000000000000000000000001',
944
+ * })],
945
+ * })
946
+ * ```
947
+ *
948
+ * @param args - Arguments.
949
+ * @returns The call.
950
+ */
951
+ export function call(args: Args) {
952
+ const { amount, seconds, token } = args
953
+ return defineCall({
954
+ address: token,
955
+ abi: Abis.tip20,
956
+ args: [amount, seconds],
957
+ functionName: 'startReward',
958
+ })
959
+ }
960
+
961
+ /**
962
+ * Extracts the `RewardScheduled` event from logs.
963
+ *
964
+ * @param logs - The logs.
965
+ * @returns The `RewardScheduled` event.
966
+ */
967
+ export function extractEvent(logs: Log[]) {
968
+ const [log] = parseEventLogs({
969
+ abi: Abis.tip20,
970
+ logs,
971
+ eventName: 'RewardScheduled',
972
+ strict: true,
973
+ })
974
+ if (!log) throw new Error('`RewardScheduled` event not found.')
975
+ return log
976
+ }
977
+ }
978
+
979
+ export declare namespace startSync {
980
+ export type Parameters<
981
+ chain extends Chain | undefined = Chain | undefined,
982
+ account extends Account | undefined = Account | undefined,
983
+ > = WriteParameters<chain, account> & start.Args
984
+
985
+ export type ReturnValue = {
986
+ /** The total amount allocated to the stream */
987
+ amount: bigint
988
+ /** The duration of the stream in seconds (0 for immediate distributions) */
989
+ durationSeconds: number
990
+ /** The address that funded the stream */
991
+ funder: Address
992
+ /** The unique stream ID (0 for immediate distributions, >0 for streaming distributions) */
993
+ id: bigint
994
+ /** The transaction receipt */
995
+ receipt: Awaited<ReturnType<typeof writeContractSync>>
996
+ }
997
+
998
+ export type ErrorType = start.ErrorType
999
+ }