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,725 @@
1
+ import { parseEventLogs, } from 'viem';
2
+ import { readContract, writeContract, writeContractSync } from 'viem/actions';
3
+ import * as Abis from '../Abis.js';
4
+ import { defineCall } from '../internal/utils.js';
5
+ /**
6
+ * Cancels an active reward stream and refunds remaining tokens.
7
+ *
8
+ * - Callable only by the stream's funder.
9
+ * - Stops future emission for the stream at the current block timestamp.
10
+ * - Computes the refund as `amountTotal - distributedSoFar` and attempts to transfer it back to the funder.
11
+ * - If the refund transfer is forbidden by TIP-403, the stream is still canceled but `refund` will be 0 in the event.
12
+ * - Reverts with `StreamInactive` if the stream doesn't exist, is already canceled, or has already ended.
13
+ * - Reverts with `NotStreamFunder` if the caller is not the stream's funder.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { createClient, http } from 'viem'
18
+ * import { tempo } from 'tempo.ts/chains'
19
+ * import { Actions } from 'tempo.ts/viem'
20
+ * import { privateKeyToAccount } from 'viem/accounts'
21
+ *
22
+ * const client = createClient({
23
+ * account: privateKeyToAccount('0x...'),
24
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
25
+ * transport: http(),
26
+ * })
27
+ *
28
+ * const hash = await Actions.rewards.cancel(client, {
29
+ * id: 1n,
30
+ * token: '0x20c0000000000000000000000000000000000001',
31
+ * })
32
+ * ```
33
+ *
34
+ * @param client - Client.
35
+ * @param parameters - Parameters.
36
+ * @returns The transaction hash.
37
+ */
38
+ export async function cancel(client, parameters) {
39
+ return cancel.inner(writeContract, client, parameters);
40
+ }
41
+ /**
42
+ * Cancels an active reward stream and waits for confirmation.
43
+ *
44
+ * - Callable only by the stream's funder.
45
+ * - Stops future emission for the stream at the current block timestamp.
46
+ * - Computes the refund as `amountTotal - distributedSoFar` and attempts to transfer it back to the funder.
47
+ * - If the refund transfer is forbidden by TIP-403, the stream is still canceled but `refund` will be 0.
48
+ * - Reverts with `StreamInactive` if the stream doesn't exist, is already canceled, or has already ended.
49
+ * - Reverts with `NotStreamFunder` if the caller is not the stream's funder.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * import { createClient, http } from 'viem'
54
+ * import { tempo } from 'tempo.ts/chains'
55
+ * import { Actions } from 'tempo.ts/viem'
56
+ * import { privateKeyToAccount } from 'viem/accounts'
57
+ *
58
+ * const client = createClient({
59
+ * account: privateKeyToAccount('0x...'),
60
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
61
+ * transport: http(),
62
+ * })
63
+ *
64
+ * const { funder, id, refund, receipt } = await Actions.rewards.cancelSync(client, {
65
+ * id: 1n,
66
+ * token: '0x20c0000000000000000000000000000000000001',
67
+ * })
68
+ * ```
69
+ *
70
+ * @param client - Client.
71
+ * @param parameters - Parameters.
72
+ * @returns The funder, stream ID, refund amount, and transaction receipt.
73
+ */
74
+ export async function cancelSync(client, parameters) {
75
+ const { throwOnReceiptRevert = true, ...rest } = parameters;
76
+ const receipt = await cancel.inner(writeContractSync, client, {
77
+ ...rest,
78
+ throwOnReceiptRevert,
79
+ });
80
+ const { args } = cancel.extractEvent(receipt.logs);
81
+ return {
82
+ ...args,
83
+ receipt,
84
+ };
85
+ }
86
+ (function (cancel) {
87
+ /** @internal */
88
+ async function inner(action, client, parameters) {
89
+ const { id, token, ...rest } = parameters;
90
+ const call = cancel.call({ id, token });
91
+ return (await action(client, {
92
+ ...rest,
93
+ ...call,
94
+ }));
95
+ }
96
+ cancel.inner = inner;
97
+ /**
98
+ * Defines a call to the `cancel` function.
99
+ *
100
+ * Can be passed as a parameter to:
101
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
102
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
103
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * import { createClient, http, walletActions } from 'viem'
108
+ * import { tempo } from 'tempo.ts/chains'
109
+ * import { Actions } from 'tempo.ts/viem'
110
+ *
111
+ * const client = createClient({
112
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
113
+ * transport: http(),
114
+ * }).extend(walletActions)
115
+ *
116
+ * const hash = await client.sendTransaction({
117
+ * calls: [actions.rewards.cancel.call({
118
+ * id: 1n,
119
+ * token: '0x20c0000000000000000000000000000000000001',
120
+ * })],
121
+ * })
122
+ * ```
123
+ *
124
+ * @param args - Arguments.
125
+ * @returns The call.
126
+ */
127
+ function call(args) {
128
+ const { id, token } = args;
129
+ return defineCall({
130
+ address: token,
131
+ abi: Abis.tip20,
132
+ args: [id],
133
+ functionName: 'cancelReward',
134
+ });
135
+ }
136
+ cancel.call = call;
137
+ /**
138
+ * Extracts the `RewardCanceled` event from logs.
139
+ *
140
+ * @param logs - The logs.
141
+ * @returns The `RewardCanceled` event.
142
+ */
143
+ function extractEvent(logs) {
144
+ const [log] = parseEventLogs({
145
+ abi: Abis.tip20,
146
+ logs,
147
+ eventName: 'RewardCanceled',
148
+ strict: true,
149
+ });
150
+ if (!log)
151
+ throw new Error('`RewardCanceled` event not found.');
152
+ return log;
153
+ }
154
+ cancel.extractEvent = extractEvent;
155
+ })(cancel || (cancel = {}));
156
+ /**
157
+ * Claims accumulated rewards for a recipient.
158
+ *
159
+ * This function allows a reward recipient to claim their accumulated rewards
160
+ * and receive them as token transfers to their own balance.
161
+ *
162
+ * - Accrues all pending rewards up to the current block timestamp.
163
+ * - Updates the caller's reward accounting.
164
+ * - Transfers the caller's accumulated `rewardBalance` from the token contract to the caller.
165
+ * - If the contract's balance is insufficient, claims up to the available amount.
166
+ * - Returns the actual amount claimed.
167
+ *
168
+ * Notes:
169
+ * - Reverts with `Paused` if the token is paused.
170
+ * - Reverts with `PolicyForbids` if the caller is not authorized to receive tokens under TIP-403.
171
+ * - If opted in, the claimed amount is added back to `optedInSupply` since it goes to the recipient's balance.
172
+ *
173
+ * @example
174
+ * ```ts
175
+ * import { createClient, http } from 'viem'
176
+ * import { tempo } from 'tempo.ts/chains'
177
+ * import { Actions } from 'tempo.ts/viem'
178
+ * import { privateKeyToAccount } from 'viem/accounts'
179
+ *
180
+ * const client = createClient({
181
+ * account: privateKeyToAccount('0x...'),
182
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
183
+ * transport: http(),
184
+ * })
185
+ *
186
+ * const hash = await Actions.reward.claim(client, {
187
+ * token: '0x20c0000000000000000000000000000000000001',
188
+ * })
189
+ * ```
190
+ *
191
+ * @param client - Client.
192
+ * @param parameters - Parameters.
193
+ * @returns The transaction hash.
194
+ */
195
+ export async function claim(client, parameters) {
196
+ return claim.inner(writeContract, client, parameters);
197
+ }
198
+ (function (claim) {
199
+ /** @internal */
200
+ async function inner(action, client, parameters) {
201
+ const { token, ...rest } = parameters;
202
+ const call = claim.call({ token });
203
+ return (await action(client, {
204
+ ...rest,
205
+ ...call,
206
+ }));
207
+ }
208
+ claim.inner = inner;
209
+ /**
210
+ * Defines a call to the `claimRewards` function.
211
+ *
212
+ * Can be passed as a parameter to:
213
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
214
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
215
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
216
+ *
217
+ * @example
218
+ * ```ts
219
+ * import { createClient, http, walletActions } from 'viem'
220
+ * import { tempo } from 'tempo.ts/chains'
221
+ * import { Actions } from 'tempo.ts/viem'
222
+ *
223
+ * const client = createClient({
224
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
225
+ * transport: http(),
226
+ * }).extend(walletActions)
227
+ *
228
+ * const hash = await client.sendTransaction({
229
+ * calls: [actions.reward.claim.call({
230
+ * token: '0x20c0000000000000000000000000000000000001',
231
+ * })],
232
+ * })
233
+ * ```
234
+ *
235
+ * @param args - Arguments.
236
+ * @returns The call.
237
+ */
238
+ function call(args) {
239
+ const { token } = args;
240
+ return defineCall({
241
+ address: token,
242
+ abi: Abis.tip20,
243
+ args: [],
244
+ functionName: 'claimRewards',
245
+ });
246
+ }
247
+ claim.call = call;
248
+ })(claim || (claim = {}));
249
+ /**
250
+ * Claims accumulated rewards for a recipient and waits for confirmation.
251
+ *
252
+ * This function allows a reward recipient to claim their accumulated rewards
253
+ * and receive them as token transfers to their own balance.
254
+ *
255
+ * Behavior:
256
+ * - Accrues all pending rewards up to the current block timestamp.
257
+ * - Updates the caller's reward accounting.
258
+ * - Transfers the caller's accumulated `rewardBalance` from the token contract to the caller.
259
+ * - If the contract's balance is insufficient, claims up to the available amount.
260
+ *
261
+ * Notes:
262
+ * - Reverts with `Paused` if the token is paused.
263
+ * - Reverts with `PolicyForbids` if the caller is not authorized to receive tokens under TIP-403.
264
+ * - If opted in, the claimed amount is added back to `optedInSupply` since it goes to the recipient's balance.
265
+ *
266
+ * @example
267
+ * ```ts
268
+ * import { createClient, http } from 'viem'
269
+ * import { tempo } from 'tempo.ts/chains'
270
+ * import { Actions } from 'tempo.ts/viem'
271
+ * import { privateKeyToAccount } from 'viem/accounts'
272
+ *
273
+ * const client = createClient({
274
+ * account: privateKeyToAccount('0x...'),
275
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
276
+ * transport: http(),
277
+ * })
278
+ *
279
+ * const { receipt } = await Actions.reward.claimSync(client, {
280
+ * token: '0x20c0000000000000000000000000000000000001',
281
+ * })
282
+ * ```
283
+ *
284
+ * @param client - Client.
285
+ * @param parameters - Parameters.
286
+ * @returns The amount claimed and transaction receipt.
287
+ */
288
+ export async function claimSync(client, parameters) {
289
+ const { throwOnReceiptRevert = true, ...rest } = parameters;
290
+ const receipt = await claim.inner(writeContractSync, client, {
291
+ ...rest,
292
+ throwOnReceiptRevert,
293
+ });
294
+ return {
295
+ receipt,
296
+ };
297
+ }
298
+ /**
299
+ * Gets a reward stream by its ID.
300
+ *
301
+ * Returns the stream details including:
302
+ * - `funder`: The address that funded the stream
303
+ * - `startTime`: When the stream started (block timestamp)
304
+ * - `endTime`: When the stream is scheduled to end
305
+ * - `ratePerSecondScaled`: The per-second emission rate (scaled by ACC_PRECISION = 1e18)
306
+ * - `amountTotal`: The total amount allocated to the stream
307
+ *
308
+ * Note: If the stream has been canceled or doesn't exist, `funder` will be the zero address.
309
+ *
310
+ * @example
311
+ * ```ts
312
+ * import { createClient, http } from 'viem'
313
+ * import { tempo } from 'tempo.ts/chains'
314
+ * import { Actions } from 'tempo.ts/viem'
315
+ *
316
+ * const client = createClient({
317
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
318
+ * transport: http(),
319
+ * })
320
+ *
321
+ * const stream = await Actions.rewards.getStream(client, {
322
+ * id: 1n,
323
+ * token: '0x20c0000000000000000000000000000000000001',
324
+ * })
325
+ * ```
326
+ *
327
+ * @param client - Client.
328
+ * @param parameters - Parameters.
329
+ * @returns The reward stream details.
330
+ */
331
+ export async function getStream(client, parameters) {
332
+ return readContract(client, {
333
+ ...parameters,
334
+ ...getStream.call(parameters),
335
+ });
336
+ }
337
+ (function (getStream) {
338
+ /**
339
+ * Defines a call to the `getStream` function.
340
+ *
341
+ * @param args - Arguments.
342
+ * @returns The call.
343
+ */
344
+ function call(args) {
345
+ const { id, token } = args;
346
+ return defineCall({
347
+ address: token,
348
+ abi: Abis.tip20,
349
+ args: [id],
350
+ functionName: 'getStream',
351
+ });
352
+ }
353
+ getStream.call = call;
354
+ })(getStream || (getStream = {}));
355
+ /**
356
+ * Gets the total reward per second rate for all active streams.
357
+ *
358
+ * Returns the current aggregate per-second emission rate scaled by `ACC_PRECISION` (1e18).
359
+ * This value represents the sum of all active reward streams' emission rates.
360
+ * The rate decreases when streams end (via `finalizeStreams`) or are canceled.
361
+ *
362
+ * @example
363
+ * ```ts
364
+ * import { createClient, http } from 'viem'
365
+ * import { tempo } from 'tempo.ts/chains'
366
+ * import { Actions } from 'tempo.ts/viem'
367
+ *
368
+ * const client = createClient({
369
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
370
+ * transport: http(),
371
+ * })
372
+ *
373
+ * const rate = await Actions.rewards.getTotalPerSecond(client, {
374
+ * token: '0x20c0000000000000000000000000000000000001',
375
+ * })
376
+ * ```
377
+ *
378
+ * @param client - Client.
379
+ * @param parameters - Parameters.
380
+ * @returns The total reward per second (scaled by 1e18).
381
+ */
382
+ export async function getTotalPerSecond(client, parameters) {
383
+ return readContract(client, {
384
+ ...parameters,
385
+ ...getTotalPerSecond.call(parameters),
386
+ });
387
+ }
388
+ (function (getTotalPerSecond) {
389
+ /**
390
+ * Defines a call to the `totalRewardPerSecond` function.
391
+ *
392
+ * @param args - Arguments.
393
+ * @returns The call.
394
+ */
395
+ function call(args) {
396
+ const { token } = args;
397
+ return defineCall({
398
+ address: token,
399
+ abi: Abis.tip20,
400
+ args: [],
401
+ functionName: 'totalRewardPerSecond',
402
+ });
403
+ }
404
+ getTotalPerSecond.call = call;
405
+ })(getTotalPerSecond || (getTotalPerSecond = {}));
406
+ /**
407
+ * Sets or changes the reward recipient for a token holder.
408
+ *
409
+ * This function allows a token holder to designate who should receive their share of rewards:
410
+ * - If `recipient` is the zero address, opts out from rewards distribution.
411
+ * - Otherwise, opts in and sets `recipient` as the address that will receive accrued rewards.
412
+ * - Can be called with `recipient == msg.sender` to receive rewards directly.
413
+ * - Automatically distributes any accrued rewards to the current recipient before changing.
414
+ *
415
+ * TIP-403 Policy:
416
+ * - 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.
417
+ *
418
+ * @example
419
+ * ```ts
420
+ * import { createClient, http } from 'viem'
421
+ * import { tempo } from 'tempo.ts/chains'
422
+ * import { Actions } from 'tempo.ts/viem'
423
+ * import { privateKeyToAccount } from 'viem/accounts'
424
+ *
425
+ * const client = createClient({
426
+ * account: privateKeyToAccount('0x...'),
427
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
428
+ * transport: http(),
429
+ * })
430
+ *
431
+ * const hash = await Actions.rewards.setRecipient(client, {
432
+ * recipient: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
433
+ * token: '0x20c0000000000000000000000000000000000001',
434
+ * })
435
+ * ```
436
+ *
437
+ * @param client - Client.
438
+ * @param parameters - Parameters.
439
+ * @returns The transaction hash.
440
+ */
441
+ export async function setRecipient(client, parameters) {
442
+ return setRecipient.inner(writeContract, client, parameters);
443
+ }
444
+ /**
445
+ * Sets or changes the reward recipient for a token holder and waits for confirmation.
446
+ *
447
+ * This function allows a token holder to designate who should receive their share of rewards:
448
+ * - If `recipient` is the zero address, opts out from rewards distribution.
449
+ * - Otherwise, opts in and sets `recipient` as the address that will receive accrued rewards.
450
+ * - Can be called with `recipient == msg.sender` to receive rewards directly.
451
+ * - Automatically distributes any accrued rewards to the current recipient before changing.
452
+ *
453
+ * TIP-403 Policy:
454
+ * - 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.
455
+ *
456
+ * @example
457
+ * ```ts
458
+ * import { createClient, http } from 'viem'
459
+ * import { tempo } from 'tempo.ts/chains'
460
+ * import { Actions } from 'tempo.ts/viem'
461
+ * import { privateKeyToAccount } from 'viem/accounts'
462
+ *
463
+ * const client = createClient({
464
+ * account: privateKeyToAccount('0x...'),
465
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
466
+ * transport: http(),
467
+ * })
468
+ *
469
+ * const { holder, recipient, receipt } = await Actions.rewards.setRecipientSync(client, {
470
+ * recipient: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
471
+ * token: '0x20c0000000000000000000000000000000000001',
472
+ * })
473
+ * ```
474
+ *
475
+ * @param client - Client.
476
+ * @param parameters - Parameters.
477
+ * @returns The holder, recipient, and transaction receipt.
478
+ */
479
+ export async function setRecipientSync(client, parameters) {
480
+ const { throwOnReceiptRevert = true, ...rest } = parameters;
481
+ const receipt = await setRecipient.inner(writeContractSync, client, {
482
+ ...rest,
483
+ throwOnReceiptRevert,
484
+ });
485
+ const { args } = setRecipient.extractEvent(receipt.logs);
486
+ return {
487
+ ...args,
488
+ receipt,
489
+ };
490
+ }
491
+ (function (setRecipient) {
492
+ /** @internal */
493
+ async function inner(action, client, parameters) {
494
+ const { recipient, token, ...rest } = parameters;
495
+ const call = setRecipient.call({ recipient, token });
496
+ return (await action(client, {
497
+ ...rest,
498
+ ...call,
499
+ }));
500
+ }
501
+ setRecipient.inner = inner;
502
+ /**
503
+ * Defines a call to the `setRecipient` function.
504
+ *
505
+ * Can be passed as a parameter to:
506
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
507
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
508
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
509
+ *
510
+ * @example
511
+ * ```ts
512
+ * import { createClient, http, walletActions } from 'viem'
513
+ * import { tempo } from 'tempo.ts/chains'
514
+ * import { Actions } from 'tempo.ts/viem'
515
+ *
516
+ * const client = createClient({
517
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
518
+ * transport: http(),
519
+ * }).extend(walletActions)
520
+ *
521
+ * const hash = await client.sendTransaction({
522
+ * calls: [actions.rewards.setRecipient.call({
523
+ * recipient: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
524
+ * token: '0x20c0000000000000000000000000000000000001',
525
+ * })],
526
+ * })
527
+ * ```
528
+ *
529
+ * @param args - Arguments.
530
+ * @returns The call.
531
+ */
532
+ function call(args) {
533
+ const { recipient, token } = args;
534
+ return defineCall({
535
+ address: token,
536
+ abi: Abis.tip20,
537
+ args: [recipient],
538
+ functionName: 'setRewardRecipient',
539
+ });
540
+ }
541
+ setRecipient.call = call;
542
+ /**
543
+ * Extracts the `RewardRecipientSet` event from logs.
544
+ *
545
+ * @param logs - The logs.
546
+ * @returns The `RewardRecipientSet` event.
547
+ */
548
+ function extractEvent(logs) {
549
+ const [log] = parseEventLogs({
550
+ abi: Abis.tip20,
551
+ logs,
552
+ eventName: 'RewardRecipientSet',
553
+ strict: true,
554
+ });
555
+ if (!log)
556
+ throw new Error('`RewardRecipientSet` event not found.');
557
+ return log;
558
+ }
559
+ setRecipient.extractEvent = extractEvent;
560
+ })(setRecipient || (setRecipient = {}));
561
+ /**
562
+ * Starts a new reward stream that distributes tokens to opted-in holders.
563
+ *
564
+ * Behavior:
565
+ * - Transfers `amount` of tokens from the caller into the token contract's reward pool.
566
+ * - If `seconds == 0`: Immediately distributes `amount` to current opted-in holders by increasing `rewardPerTokenStored`.
567
+ * Returns stream ID `0`. Distribution occurs when holders interact with the token (transfers, etc.).
568
+ * - If `seconds > 0`: Starts a linear stream that emits evenly from `block.timestamp` to `block.timestamp + seconds`.
569
+ * Returns a unique stream ID for later cancellation.
570
+ *
571
+ * Notes:
572
+ * - Reverts with `InvalidAmount` if `amount == 0`.
573
+ * - Allowed even when `optedInSupply == 0` (tokens distributed while no one is opted in are locked permanently).
574
+ * - The transfer from caller to pool is subject to TIP-403 policy checks.
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.start(client, {
590
+ * amount: 100000000000000000000n,
591
+ * seconds: 86400,
592
+ * token: '0x20c0000000000000000000000000000000000001',
593
+ * })
594
+ * ```
595
+ *
596
+ * @param client - Client.
597
+ * @param parameters - Parameters.
598
+ * @returns The transaction hash.
599
+ */
600
+ export async function start(client, parameters) {
601
+ return start.inner(writeContract, client, parameters);
602
+ }
603
+ /**
604
+ * Starts a new reward stream that distributes tokens to opted-in holders and waits for confirmation.
605
+ *
606
+ * Behavior:
607
+ * - Transfers `amount` of tokens from the caller into the token contract's reward pool.
608
+ * - If `seconds == 0`: Immediately distributes `amount` to current opted-in holders by increasing `rewardPerTokenStored`.
609
+ * Returns stream ID `0`. Distribution occurs when holders interact with the token (transfers, etc.).
610
+ * - If `seconds > 0`: Starts a linear stream that emits evenly from `block.timestamp` to `block.timestamp + seconds`.
611
+ * Returns a unique stream ID for later cancellation.
612
+ *
613
+ * Notes:
614
+ * - Reverts with `InvalidAmount` if `amount == 0`.
615
+ * - Allowed even when `optedInSupply == 0` (tokens distributed while no one is opted in are locked permanently).
616
+ * - The transfer from caller to pool is subject to TIP-403 policy checks.
617
+ *
618
+ * @example
619
+ * ```ts
620
+ * import { createClient, http } from 'viem'
621
+ * import { tempo } from 'tempo.ts/chains'
622
+ * import { Actions } from 'tempo.ts/viem'
623
+ * import { privateKeyToAccount } from 'viem/accounts'
624
+ *
625
+ * const client = createClient({
626
+ * account: privateKeyToAccount('0x...'),
627
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
628
+ * transport: http(),
629
+ * })
630
+ *
631
+ * const { id, receipt } = await Actions.rewards.startSync(client, {
632
+ * amount: 100000000000000000000n,
633
+ * seconds: 86400,
634
+ * token: '0x20c0000000000000000000000000000000000001',
635
+ * })
636
+ * ```
637
+ *
638
+ * @param client - Client.
639
+ * @param parameters - Parameters.
640
+ * @returns The stream ID, funder, amount, duration, and transaction receipt.
641
+ */
642
+ export async function startSync(client, parameters) {
643
+ const { throwOnReceiptRevert = true, ...rest } = parameters;
644
+ const receipt = await start.inner(writeContractSync, client, {
645
+ ...rest,
646
+ throwOnReceiptRevert,
647
+ });
648
+ const { args } = start.extractEvent(receipt.logs);
649
+ return {
650
+ ...args,
651
+ receipt,
652
+ };
653
+ }
654
+ (function (start) {
655
+ /** @internal */
656
+ async function inner(action, client, parameters) {
657
+ const { amount, seconds, token, ...rest } = parameters;
658
+ const call = start.call({ amount, seconds, token });
659
+ return (await action(client, {
660
+ ...rest,
661
+ ...call,
662
+ }));
663
+ }
664
+ start.inner = inner;
665
+ /**
666
+ * Defines a call to the `start` function.
667
+ *
668
+ * Can be passed as a parameter to:
669
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
670
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
671
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
672
+ *
673
+ * @example
674
+ * ```ts
675
+ * import { createClient, http, walletActions } from 'viem'
676
+ * import { tempo } from 'tempo.ts/chains'
677
+ * import { Actions } from 'tempo.ts/viem'
678
+ *
679
+ * const client = createClient({
680
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
681
+ * transport: http(),
682
+ * }).extend(walletActions)
683
+ *
684
+ * const hash = await client.sendTransaction({
685
+ * calls: [actions.rewards.start.call({
686
+ * amount: 100000000000000000000n,
687
+ * seconds: 86400,
688
+ * token: '0x20c0000000000000000000000000000000000001',
689
+ * })],
690
+ * })
691
+ * ```
692
+ *
693
+ * @param args - Arguments.
694
+ * @returns The call.
695
+ */
696
+ function call(args) {
697
+ const { amount, seconds, token } = args;
698
+ return defineCall({
699
+ address: token,
700
+ abi: Abis.tip20,
701
+ args: [amount, seconds],
702
+ functionName: 'startReward',
703
+ });
704
+ }
705
+ start.call = call;
706
+ /**
707
+ * Extracts the `RewardScheduled` event from logs.
708
+ *
709
+ * @param logs - The logs.
710
+ * @returns The `RewardScheduled` event.
711
+ */
712
+ function extractEvent(logs) {
713
+ const [log] = parseEventLogs({
714
+ abi: Abis.tip20,
715
+ logs,
716
+ eventName: 'RewardScheduled',
717
+ strict: true,
718
+ });
719
+ if (!log)
720
+ throw new Error('`RewardScheduled` event not found.');
721
+ return log;
722
+ }
723
+ start.extractEvent = extractEvent;
724
+ })(start || (start = {}));
725
+ //# sourceMappingURL=reward.js.map