viem 2.43.5 → 2.44.0

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