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