tempo.ts 0.7.6 → 0.8.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 (150) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/chains.d.ts +6 -20
  3. package/dist/chains.d.ts.map +1 -1
  4. package/dist/chains.js +14 -15
  5. package/dist/chains.js.map +1 -1
  6. package/dist/ox/KeyAuthorization.d.ts +356 -0
  7. package/dist/ox/KeyAuthorization.d.ts.map +1 -0
  8. package/dist/ox/KeyAuthorization.js +360 -0
  9. package/dist/ox/KeyAuthorization.js.map +1 -0
  10. package/dist/ox/SignatureEnvelope.d.ts +21 -6
  11. package/dist/ox/SignatureEnvelope.d.ts.map +1 -1
  12. package/dist/ox/SignatureEnvelope.js +43 -3
  13. package/dist/ox/SignatureEnvelope.js.map +1 -1
  14. package/dist/ox/Transaction.d.ts +5 -1
  15. package/dist/ox/Transaction.d.ts.map +1 -1
  16. package/dist/ox/Transaction.js +5 -0
  17. package/dist/ox/Transaction.js.map +1 -1
  18. package/dist/ox/TransactionEnvelopeAA.d.ts +9 -0
  19. package/dist/ox/TransactionEnvelopeAA.d.ts.map +1 -1
  20. package/dist/ox/TransactionEnvelopeAA.js +17 -4
  21. package/dist/ox/TransactionEnvelopeAA.js.map +1 -1
  22. package/dist/ox/TransactionRequest.d.ts +7 -1
  23. package/dist/ox/TransactionRequest.d.ts.map +1 -1
  24. package/dist/ox/TransactionRequest.js +12 -0
  25. package/dist/ox/TransactionRequest.js.map +1 -1
  26. package/dist/ox/index.d.ts +1 -0
  27. package/dist/ox/index.d.ts.map +1 -1
  28. package/dist/ox/index.js +1 -0
  29. package/dist/ox/index.js.map +1 -1
  30. package/dist/prool/Instance.js +1 -1
  31. package/dist/prool/Instance.js.map +1 -1
  32. package/{src/prool/internal → dist/prool}/chain.json +4 -2
  33. package/dist/viem/Abis.d.ts +319 -6
  34. package/dist/viem/Abis.d.ts.map +1 -1
  35. package/dist/viem/Abis.js +199 -7
  36. package/dist/viem/Abis.js.map +1 -1
  37. package/dist/viem/Account.d.ts +103 -14
  38. package/dist/viem/Account.d.ts.map +1 -1
  39. package/dist/viem/Account.js +177 -23
  40. package/dist/viem/Account.js.map +1 -1
  41. package/dist/viem/Actions/account.d.ts.map +1 -1
  42. package/dist/viem/Actions/account.js +4 -5
  43. package/dist/viem/Actions/account.js.map +1 -1
  44. package/dist/viem/Actions/amm.d.ts +72 -0
  45. package/dist/viem/Actions/amm.d.ts.map +1 -1
  46. package/dist/viem/Actions/dex.d.ts +156 -4
  47. package/dist/viem/Actions/dex.d.ts.map +1 -1
  48. package/dist/viem/Actions/fee.d.ts +4 -0
  49. package/dist/viem/Actions/fee.d.ts.map +1 -1
  50. package/dist/viem/Actions/reward.d.ts +158 -0
  51. package/dist/viem/Actions/reward.d.ts.map +1 -1
  52. package/dist/viem/Actions/reward.js +54 -0
  53. package/dist/viem/Actions/reward.js.map +1 -1
  54. package/dist/viem/Actions/token.d.ts +585 -0
  55. package/dist/viem/Actions/token.d.ts.map +1 -1
  56. package/dist/viem/Actions/token.js +2 -2
  57. package/dist/viem/Actions/token.js.map +1 -1
  58. package/dist/viem/Addresses.d.ts +1 -1
  59. package/dist/viem/Addresses.d.ts.map +1 -1
  60. package/dist/viem/Addresses.js +1 -1
  61. package/dist/viem/Addresses.js.map +1 -1
  62. package/dist/viem/Chain.d.ts +35 -0
  63. package/dist/viem/Chain.d.ts.map +1 -1
  64. package/dist/viem/Chain.js +37 -0
  65. package/dist/viem/Chain.js.map +1 -1
  66. package/dist/viem/Decorator.d.ts +74 -0
  67. package/dist/viem/Decorator.d.ts.map +1 -1
  68. package/dist/viem/Decorator.js +3 -0
  69. package/dist/viem/Decorator.js.map +1 -1
  70. package/dist/viem/Formatters.d.ts.map +1 -1
  71. package/dist/viem/Formatters.js +8 -7
  72. package/dist/viem/Formatters.js.map +1 -1
  73. package/dist/viem/Storage.d.ts +1 -0
  74. package/dist/viem/Storage.d.ts.map +1 -1
  75. package/dist/viem/Storage.js +21 -0
  76. package/dist/viem/Storage.js.map +1 -1
  77. package/dist/viem/TokenIds.d.ts +1 -1
  78. package/dist/viem/TokenIds.d.ts.map +1 -1
  79. package/dist/viem/TokenIds.js +1 -1
  80. package/dist/viem/TokenIds.js.map +1 -1
  81. package/dist/viem/Transaction.d.ts +9 -1
  82. package/dist/viem/Transaction.d.ts.map +1 -1
  83. package/dist/viem/Transaction.js +2 -1
  84. package/dist/viem/Transaction.js.map +1 -1
  85. package/dist/viem/WebAuthnP256.d.ts +4 -1
  86. package/dist/viem/WebAuthnP256.d.ts.map +1 -1
  87. package/dist/viem/WebAuthnP256.js +3 -1
  88. package/dist/viem/WebAuthnP256.js.map +1 -1
  89. package/dist/wagmi/Actions/reward.d.ts +44 -0
  90. package/dist/wagmi/Actions/reward.d.ts.map +1 -1
  91. package/dist/wagmi/Actions/reward.js +49 -0
  92. package/dist/wagmi/Actions/reward.js.map +1 -1
  93. package/dist/wagmi/Connector.d.ts +25 -8
  94. package/dist/wagmi/Connector.d.ts.map +1 -1
  95. package/dist/wagmi/Connector.js +120 -27
  96. package/dist/wagmi/Connector.js.map +1 -1
  97. package/dist/wagmi/Hooks/reward.d.ts +32 -0
  98. package/dist/wagmi/Hooks/reward.d.ts.map +1 -1
  99. package/dist/wagmi/Hooks/reward.js +39 -0
  100. package/dist/wagmi/Hooks/reward.js.map +1 -1
  101. package/package.json +3 -2
  102. package/src/chains.ts +14 -15
  103. package/src/ox/KeyAuthorization.test.ts +1332 -0
  104. package/src/ox/KeyAuthorization.ts +542 -0
  105. package/src/ox/SignatureEnvelope.test.ts +624 -0
  106. package/src/ox/SignatureEnvelope.ts +89 -9
  107. package/src/ox/Transaction.test.ts +214 -0
  108. package/src/ox/Transaction.ts +13 -1
  109. package/src/ox/TransactionEnvelopeAA.test.ts +164 -4
  110. package/src/ox/TransactionEnvelopeAA.ts +36 -3
  111. package/src/ox/TransactionRequest.ts +22 -1
  112. package/src/ox/e2e.test.ts +612 -5
  113. package/src/ox/index.ts +1 -0
  114. package/src/prool/Instance.ts +1 -1
  115. package/src/prool/chain.json +238 -0
  116. package/src/server/Handler.test.ts +20 -36
  117. package/src/viem/Abis.ts +200 -7
  118. package/src/viem/Account.test.ts +444 -0
  119. package/src/viem/Account.ts +355 -42
  120. package/src/viem/Actions/account.ts +3 -5
  121. package/src/viem/Actions/amm.test.ts +4 -4
  122. package/src/viem/Actions/reward.test.ts +84 -0
  123. package/src/viem/Actions/reward.ts +73 -0
  124. package/src/viem/Actions/token.test.ts +8 -8
  125. package/src/viem/Actions/token.ts +2 -2
  126. package/src/viem/Addresses.ts +1 -1
  127. package/src/viem/Chain.test.ts +168 -0
  128. package/src/viem/Chain.ts +37 -1
  129. package/src/viem/Decorator.ts +84 -0
  130. package/src/viem/Formatters.ts +8 -7
  131. package/src/viem/Storage.ts +22 -0
  132. package/src/viem/TokenIds.ts +1 -1
  133. package/src/viem/Transaction.ts +14 -2
  134. package/src/viem/WebAuthnP256.ts +8 -2
  135. package/src/viem/e2e.test.ts +299 -96
  136. package/src/wagmi/Actions/amm.test.ts +2 -2
  137. package/src/wagmi/Actions/reward.test.ts +36 -0
  138. package/src/wagmi/Actions/reward.ts +91 -0
  139. package/src/wagmi/Connector.test.ts +1 -1
  140. package/src/wagmi/Connector.ts +184 -54
  141. package/src/wagmi/Hooks/amm.test.ts +4 -4
  142. package/src/wagmi/Hooks/fee.test.ts +10 -4
  143. package/src/wagmi/Hooks/reward.test.ts +72 -0
  144. package/src/wagmi/Hooks/reward.ts +68 -0
  145. package/src/wagmi/Hooks/token.test.ts +0 -488
  146. package/dist/viem/internal/account.d.ts +0 -21
  147. package/dist/viem/internal/account.d.ts.map +0 -1
  148. package/dist/viem/internal/account.js +0 -61
  149. package/dist/viem/internal/account.js.map +0 -1
  150. package/src/viem/internal/account.ts +0 -89
@@ -276,6 +276,79 @@ export namespace getTotalPerSecond {
276
276
  }
277
277
  }
278
278
 
279
+ /**
280
+ * Gets the reward information for a specific account.
281
+ *
282
+ * Returns the reward recipient address, reward per token value, and accumulated reward balance for the specified account.
283
+ * This information includes:
284
+ * - `rewardRecipient`: The address designated to receive rewards (zero address if opted out)
285
+ * - `rewardPerToken`: The reward per token value for this account
286
+ * - `rewardBalance`: The accumulated reward balance waiting to be claimed
287
+ *
288
+ * @example
289
+ * ```ts
290
+ * import { createClient, http } from 'viem'
291
+ * import { tempo } from 'tempo.ts/chains'
292
+ * import { Actions } from 'tempo.ts/viem'
293
+ *
294
+ * const client = createClient({
295
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
296
+ * transport: http(),
297
+ * })
298
+ *
299
+ * const info = await Actions.reward.getUserRewardInfo(client, {
300
+ * token: '0x20c0000000000000000000000000000000000001',
301
+ * account: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
302
+ * })
303
+ * ```
304
+ *
305
+ * @param client - Client.
306
+ * @param parameters - Parameters.
307
+ * @returns The user's reward information (recipient, rewardPerToken, rewardBalance).
308
+ */
309
+ export async function getUserRewardInfo<chain extends Chain | undefined>(
310
+ client: Client<Transport, chain>,
311
+ parameters: getUserRewardInfo.Parameters,
312
+ ): Promise<getUserRewardInfo.ReturnValue> {
313
+ return readContract(client, {
314
+ ...parameters,
315
+ ...getUserRewardInfo.call(parameters),
316
+ })
317
+ }
318
+
319
+ export namespace getUserRewardInfo {
320
+ export type Parameters = ReadParameters & Args
321
+
322
+ export type Args = {
323
+ /** The account address to query reward info for */
324
+ account: Address
325
+ /** The TIP20 token address */
326
+ token: Address
327
+ }
328
+
329
+ export type ReturnValue = ReadContractReturnType<
330
+ typeof Abis.tip20,
331
+ 'userRewardInfo',
332
+ never
333
+ >
334
+
335
+ /**
336
+ * Defines a call to the `userRewardInfo` function.
337
+ *
338
+ * @param args - Arguments.
339
+ * @returns The call.
340
+ */
341
+ export function call(args: Args) {
342
+ const { account, token } = args
343
+ return defineCall({
344
+ address: token,
345
+ abi: Abis.tip20,
346
+ args: [account],
347
+ functionName: 'userRewardInfo',
348
+ })
349
+ }
350
+ }
351
+
279
352
  /**
280
353
  * Sets or changes the reward recipient for a token holder.
281
354
  *
@@ -349,7 +349,7 @@ describe('getMetadata', () => {
349
349
  "name": "Test USD",
350
350
  "paused": false,
351
351
  "quoteToken": "0x20C0000000000000000000000000000000000000",
352
- "supplyCap": 115792089237316195423570985008687907853269984665640564039457584007913129639935n,
352
+ "supplyCap": 340282366920938463463374607431768211455n,
353
353
  "symbol": "TUSD",
354
354
  "totalSupply": 0n,
355
355
  "transferPolicyId": 1n,
@@ -360,15 +360,15 @@ describe('getMetadata', () => {
360
360
  test('behavior: quote token', async () => {
361
361
  {
362
362
  const metadata = await actions.token.getMetadata(clientWithAccount, {
363
- token: TokenIds.linkingUsd,
363
+ token: TokenIds.pathUsd,
364
364
  })
365
365
 
366
366
  expect(metadata).toMatchInlineSnapshot(`
367
367
  {
368
368
  "currency": "USD",
369
369
  "decimals": 6,
370
- "name": "linkingUSD",
371
- "symbol": "linkingUSD",
370
+ "name": "pathUSD",
371
+ "symbol": "pathUSD",
372
372
  "totalSupply": 18446744073709551615n,
373
373
  }
374
374
  `)
@@ -376,15 +376,15 @@ describe('getMetadata', () => {
376
376
 
377
377
  {
378
378
  const metadata = await actions.token.getMetadata(clientWithAccount, {
379
- token: Addresses.linkingUsd,
379
+ token: Addresses.pathUsd,
380
380
  })
381
381
 
382
382
  expect(metadata).toMatchInlineSnapshot(`
383
383
  {
384
384
  "currency": "USD",
385
385
  "decimals": 6,
386
- "name": "linkingUSD",
387
- "symbol": "linkingUSD",
386
+ "name": "pathUSD",
387
+ "symbol": "pathUSD",
388
388
  "totalSupply": 18446744073709551615n,
389
389
  }
390
390
  `)
@@ -409,7 +409,7 @@ describe('getMetadata', () => {
409
409
  "name": "Test USD",
410
410
  "paused": false,
411
411
  "quoteToken": "0x20C0000000000000000000000000000000000000",
412
- "supplyCap": 115792089237316195423570985008687907853269984665640564039457584007913129639935n,
412
+ "supplyCap": 340282366920938463463374607431768211455n,
413
413
  "symbol": "TUSD",
414
414
  "totalSupply": 0n,
415
415
  "transferPolicyId": 1n,
@@ -998,7 +998,7 @@ export namespace create {
998
998
  name,
999
999
  symbol,
1000
1000
  currency,
1001
- quoteToken = Addresses.linkingUsd,
1001
+ quoteToken = Addresses.pathUsd,
1002
1002
  admin,
1003
1003
  } = args
1004
1004
  return defineCall({
@@ -1285,7 +1285,7 @@ export async function getMetadata<chain extends Chain | undefined>(
1285
1285
  const address = TokenId.toAddress(token)
1286
1286
  const abi = Abis.tip20
1287
1287
 
1288
- if (TokenId.from(token) === TokenId.fromAddress(Addresses.linkingUsd))
1288
+ if (TokenId.from(token) === TokenId.fromAddress(Addresses.pathUsd))
1289
1289
  return multicall(client, {
1290
1290
  ...rest,
1291
1291
  contracts: [
@@ -2,7 +2,7 @@ export const accountImplementation =
2
2
  '0x7702c00000000000000000000000000000000000'
3
3
  export const accountRegistrar = '0x7702ac0000000000000000000000000000000000'
4
4
  export const feeManager = '0xfeec000000000000000000000000000000000000'
5
- export const linkingUsd = '0x20c0000000000000000000000000000000000000'
5
+ export const pathUsd = '0x20c0000000000000000000000000000000000000'
6
6
  export const stablecoinExchange = '0xdec0000000000000000000000000000000000000'
7
7
  export const tip20Factory = '0x20fc000000000000000000000000000000000000'
8
8
  export const tip403Registry = '0x403c000000000000000000000000000000000000'
@@ -0,0 +1,168 @@
1
+ import {
2
+ getTransaction,
3
+ prepareTransactionRequest,
4
+ sendTransactionSync,
5
+ } from 'viem/actions'
6
+ import { describe, expect, test, vi } from 'vitest'
7
+ import { chain, client, clientWithAccount } from '../../test/viem/config.js'
8
+
9
+ describe('chain.prepareTransactionRequest', () => {
10
+ test('behavior: sequential nonce keys for feePayer transactions', async () => {
11
+ const requests = await Promise.all([
12
+ chain.prepareTransactionRequest({ feePayer: true } as never),
13
+ chain.prepareTransactionRequest({ feePayer: true } as never),
14
+ chain.prepareTransactionRequest({ feePayer: true } as never),
15
+ ])
16
+
17
+ expect((requests[0] as any)?.nonceKey).toBe(0n)
18
+ expect((requests[1] as any)?.nonceKey).toBeGreaterThan(0n)
19
+ expect((requests[2] as any)?.nonceKey).toBeGreaterThan(0n)
20
+ })
21
+
22
+ test('behavior: nonce key counter resets after event loop tick', async () => {
23
+ const requests1 = await Promise.all([
24
+ chain.prepareTransactionRequest({ feePayer: true } as never),
25
+ chain.prepareTransactionRequest({ feePayer: true } as never),
26
+ ])
27
+
28
+ expect((requests1[0] as any)?.nonceKey).toBe(0n)
29
+ expect((requests1[1] as any)?.nonceKey).toBeGreaterThan(0n)
30
+
31
+ // Wait for microtask queue to flush
32
+ await new Promise((resolve) => queueMicrotask(() => resolve(undefined)))
33
+
34
+ const requests2 = await Promise.all([
35
+ chain.prepareTransactionRequest({ feePayer: true } as never),
36
+ chain.prepareTransactionRequest({ feePayer: true } as never),
37
+ ])
38
+
39
+ // Counter should have reset
40
+ expect((requests2[0] as any)?.nonceKey).toBe(0n)
41
+ expect((requests2[1] as any)?.nonceKey).toBeGreaterThan(0n)
42
+ })
43
+
44
+ test('behavior: explicit nonceKey overrides counter', async () => {
45
+ const requests = await Promise.all([
46
+ chain.prepareTransactionRequest({
47
+ feePayer: true,
48
+ nonceKey: 42n,
49
+ } as never),
50
+ chain.prepareTransactionRequest({ feePayer: true } as never),
51
+ chain.prepareTransactionRequest({
52
+ feePayer: true,
53
+ nonceKey: 100n,
54
+ } as never),
55
+ ])
56
+
57
+ expect((requests[0] as any)?.nonceKey).toBe(42n)
58
+ expect((requests[1] as any)?.nonceKey).toBe(0n)
59
+ expect((requests[2] as any)?.nonceKey).toBe(100n)
60
+ })
61
+
62
+ test('behavior: default nonceKey when feePayer is not true', async () => {
63
+ const request = await chain.prepareTransactionRequest({} as never)
64
+ expect((request as any)?.nonceKey).toBe(0n)
65
+ })
66
+
67
+ test('behavior: nonce with sequential nonceKey', async () => {
68
+ const requests = await Promise.all([
69
+ chain.prepareTransactionRequest({ feePayer: true } as never), // nonceKey: 0n
70
+ chain.prepareTransactionRequest({ feePayer: true } as never), // nonceKey: 1n
71
+ chain.prepareTransactionRequest({ feePayer: true } as never), // nonceKey: 2n
72
+ ])
73
+
74
+ // Note: 0n is falsy, so first request has nonce undefined
75
+ expect((requests[0] as any)?.nonce).toBe(undefined)
76
+ expect((requests[0] as any)?.nonceKey).toBe(0n)
77
+
78
+ // nonceKey >= 1n is truthy, so nonce is 0
79
+ expect((requests[1] as any)?.nonce).toBe(0)
80
+ expect((requests[1] as any)?.nonceKey).toBeGreaterThan(0n)
81
+
82
+ expect((requests[2] as any)?.nonce).toBe(0)
83
+ expect((requests[2] as any)?.nonceKey).toBeGreaterThan(0n)
84
+ })
85
+
86
+ test('behavior: explicit nonce is preserved', async () => {
87
+ const request = await chain.prepareTransactionRequest({
88
+ feePayer: true,
89
+ nonce: 123,
90
+ } as never)
91
+ expect((request as any)?.nonce).toBe(123)
92
+ expect((request as any)?.nonceKey).toBe(0n)
93
+ })
94
+
95
+ test('behavior: default nonceKey is 0n (falsy)', async () => {
96
+ const request = await chain.prepareTransactionRequest({} as never)
97
+ expect((request as any)?.nonceKey).toBe(0n)
98
+ expect((request as any)?.nonce).toBe(undefined)
99
+ })
100
+
101
+ test('behavior: resetScheduled optimization - only one microtask scheduled', async () => {
102
+ const queueMicrotaskSpy = vi.spyOn(globalThis, 'queueMicrotask')
103
+ const callCountBefore = queueMicrotaskSpy.mock.calls.length
104
+
105
+ // Prepare multiple transactions in parallel
106
+ await Promise.all([
107
+ chain.prepareTransactionRequest({ feePayer: true } as never),
108
+ chain.prepareTransactionRequest({ feePayer: true } as never),
109
+ chain.prepareTransactionRequest({ feePayer: true } as never),
110
+ chain.prepareTransactionRequest({ feePayer: true } as never),
111
+ chain.prepareTransactionRequest({ feePayer: true } as never),
112
+ ])
113
+
114
+ const callCountAfter = queueMicrotaskSpy.mock.calls.length
115
+
116
+ // Only one microtask should have been scheduled for the reset
117
+ expect(callCountAfter - callCountBefore).toBe(1)
118
+
119
+ queueMicrotaskSpy.mockRestore()
120
+ })
121
+
122
+ describe('e2e', async () => {
123
+ test('behavior: prepareTransactionRequest', async () => {
124
+ const [request, request2, request3] = await Promise.all([
125
+ prepareTransactionRequest(client, {
126
+ to: '0x0000000000000000000000000000000000000000',
127
+ }),
128
+ prepareTransactionRequest(client, {
129
+ to: '0x0000000000000000000000000000000000000000',
130
+ }),
131
+ prepareTransactionRequest(client, {
132
+ to: '0x0000000000000000000000000000000000000000',
133
+ }),
134
+ ])
135
+ expect(request.nonceKey).toBe(0n)
136
+ expect(request2.nonceKey).toBeGreaterThan(0n)
137
+ expect(request3.nonceKey).toBeGreaterThan(0n)
138
+ })
139
+
140
+ test('behavior: sendTransaction', async () => {
141
+ const receipts = await Promise.all([
142
+ sendTransactionSync(clientWithAccount, {
143
+ to: '0x0000000000000000000000000000000000000000',
144
+ }),
145
+ sendTransactionSync(clientWithAccount, {
146
+ to: '0x0000000000000000000000000000000000000001',
147
+ }),
148
+ sendTransactionSync(clientWithAccount, {
149
+ to: '0x0000000000000000000000000000000000000002',
150
+ }),
151
+ ])
152
+ const transactions = await Promise.all([
153
+ getTransaction(clientWithAccount, {
154
+ hash: receipts[0].transactionHash,
155
+ }),
156
+ getTransaction(clientWithAccount, {
157
+ hash: receipts[1].transactionHash,
158
+ }),
159
+ getTransaction(clientWithAccount, {
160
+ hash: receipts[2].transactionHash,
161
+ }),
162
+ ])
163
+ expect(transactions[0].nonceKey).toBe(0n)
164
+ expect(transactions[1].nonceKey).toBeGreaterThan(0n)
165
+ expect(transactions[2].nonceKey).toBeGreaterThan(0n)
166
+ })
167
+ })
168
+ })
package/src/viem/Chain.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as Hex from 'ox/Hex'
1
2
  import {
2
3
  defineTransaction,
3
4
  defineTransactionReceipt,
@@ -25,6 +26,25 @@ export type Chain<
25
26
  })
26
27
 
27
28
  function config<const chain extends Chain>(chain: chain) {
29
+ const nonceKeyManager = {
30
+ counter: 0,
31
+ resetScheduled: false,
32
+ reset() {
33
+ this.counter = 0
34
+ this.resetScheduled = false
35
+ },
36
+ get() {
37
+ if (!this.resetScheduled) {
38
+ this.resetScheduled = true
39
+ queueMicrotask(() => this.reset())
40
+ }
41
+ const count = this.counter
42
+ this.counter++
43
+ if (count === 0) return 0n
44
+ return Hex.toBigInt(Hex.random(6))
45
+ },
46
+ }
47
+
28
48
  return {
29
49
  blockTime: 1_000,
30
50
  contracts: {
@@ -66,6 +86,22 @@ function config<const chain extends Chain>(chain: chain) {
66
86
  ),
67
87
  }),
68
88
  },
89
+ async prepareTransactionRequest(r) {
90
+ const request = r as Transaction.TransactionRequest
91
+ const nonceKey = (() => {
92
+ if (typeof request.nonceKey !== 'undefined') return request.nonceKey
93
+ return nonceKeyManager.get()
94
+ })()
95
+
96
+ const nonce = (() => {
97
+ if (typeof request.nonce === 'number') return request.nonce
98
+ // TODO: remove this line once `eth_fillTransaction` supports nonce keys.
99
+ if (nonceKey) return 0
100
+ return undefined
101
+ })()
102
+
103
+ return { ...request, nonce, nonceKey } as unknown as typeof r
104
+ },
69
105
  serializers: {
70
106
  // TODO: casting to satisfy viem – viem v3 to have more flexible serializer type.
71
107
  transaction: ((transaction, signature) =>
@@ -88,7 +124,7 @@ function config<const chain extends Chain>(chain: chain) {
88
124
  )) as SerializeTransactionFn,
89
125
  },
90
126
  ...chain,
91
- } as const
127
+ } as const satisfies viem_Chain
92
128
  }
93
129
 
94
130
  export function define<const chain extends viem_Chain>(
@@ -1591,6 +1591,60 @@ export type Decorator<
1591
1591
  ) => () => void
1592
1592
  }
1593
1593
  reward: {
1594
+ /**
1595
+ * Claims accumulated rewards for a recipient.
1596
+ *
1597
+ * @example
1598
+ * ```ts
1599
+ * import { createClient, http } from 'viem'
1600
+ * import { privateKeyToAccount } from 'viem/accounts'
1601
+ * import { tempo } from 'tempo.ts/chains'
1602
+ * import { tempoActions } from 'tempo.ts/viem'
1603
+ *
1604
+ * const client = createClient({
1605
+ * account: privateKeyToAccount('0x...'),
1606
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
1607
+ * transport: http(),
1608
+ * }).extend(tempoActions())
1609
+ *
1610
+ * const hash = await client.reward.claim({
1611
+ * token: '0x20c0000000000000000000000000000000000001',
1612
+ * })
1613
+ * ```
1614
+ *
1615
+ * @param parameters - Parameters.
1616
+ * @returns The transaction hash.
1617
+ */
1618
+ claim: (
1619
+ parameters: rewardActions.claim.Parameters<chain, account>,
1620
+ ) => Promise<rewardActions.claim.ReturnValue>
1621
+ /**
1622
+ * Claims accumulated rewards for a recipient and waits for confirmation.
1623
+ *
1624
+ * @example
1625
+ * ```ts
1626
+ * import { createClient, http } from 'viem'
1627
+ * import { privateKeyToAccount } from 'viem/accounts'
1628
+ * import { tempo } from 'tempo.ts/chains'
1629
+ * import { tempoActions } from 'tempo.ts/viem'
1630
+ *
1631
+ * const client = createClient({
1632
+ * account: privateKeyToAccount('0x...'),
1633
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
1634
+ * transport: http(),
1635
+ * }).extend(tempoActions())
1636
+ *
1637
+ * const result = await client.reward.claimSync({
1638
+ * token: '0x20c0000000000000000000000000000000000001',
1639
+ * })
1640
+ * ```
1641
+ *
1642
+ * @param parameters - Parameters.
1643
+ * @returns The amount claimed and transaction receipt.
1644
+ */
1645
+ claimSync: (
1646
+ parameters: rewardActions.claimSync.Parameters<chain, account>,
1647
+ ) => Promise<rewardActions.claimSync.ReturnValue>
1594
1648
  /**
1595
1649
  * Gets the total reward per second rate for all active streams.
1596
1650
  *
@@ -1616,6 +1670,32 @@ export type Decorator<
1616
1670
  getTotalPerSecond: (
1617
1671
  parameters: rewardActions.getTotalPerSecond.Parameters,
1618
1672
  ) => Promise<rewardActions.getTotalPerSecond.ReturnValue>
1673
+ /**
1674
+ * Gets the reward information for a specific account.
1675
+ *
1676
+ * @example
1677
+ * ```ts
1678
+ * import { createClient, http } from 'viem'
1679
+ * import { tempo } from 'tempo.ts/chains'
1680
+ * import { tempoActions } from 'tempo.ts/viem'
1681
+ *
1682
+ * const client = createClient({
1683
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
1684
+ * transport: http(),
1685
+ * }).extend(tempoActions())
1686
+ *
1687
+ * const info = await client.reward.getUserRewardInfo({
1688
+ * token: '0x20c0000000000000000000000000000000000001',
1689
+ * account: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
1690
+ * })
1691
+ * ```
1692
+ *
1693
+ * @param parameters - Parameters.
1694
+ * @returns The user's reward information (recipient, rewardPerToken, rewardBalance).
1695
+ */
1696
+ getUserRewardInfo: (
1697
+ parameters: rewardActions.getUserRewardInfo.Parameters,
1698
+ ) => Promise<rewardActions.getUserRewardInfo.ReturnValue>
1619
1699
  /**
1620
1700
  * Sets or changes the reward recipient for a token holder.
1621
1701
  *
@@ -2986,8 +3066,12 @@ export function decorator() {
2986
3066
  policyActions.watchBlacklistUpdated(client, parameters),
2987
3067
  },
2988
3068
  reward: {
3069
+ claim: (parameters) => rewardActions.claim(client, parameters),
3070
+ claimSync: (parameters) => rewardActions.claimSync(client, parameters),
2989
3071
  getTotalPerSecond: (parameters) =>
2990
3072
  rewardActions.getTotalPerSecond(client, parameters),
3073
+ getUserRewardInfo: (parameters) =>
3074
+ rewardActions.getUserRewardInfo(client, parameters),
2991
3075
  setRecipient: (parameters) =>
2992
3076
  rewardActions.setRecipient(client, parameters),
2993
3077
  setRecipientSync: (parameters) =>
@@ -12,6 +12,7 @@ import { parseAccount } from 'viem/accounts'
12
12
  import type { UnionOmit } from '../internal/types.js'
13
13
  import * as ox_Transaction from '../ox/Transaction.js'
14
14
  import * as ox_TransactionRequest from '../ox/TransactionRequest.js'
15
+ import type { Account } from './Account.js'
15
16
  import type { GetFeeTokenParameter } from './internal/types.js'
16
17
  import {
17
18
  isTempo,
@@ -77,6 +78,7 @@ export function formatTransactionRequest<chain extends Chain | undefined>(
77
78
  action?: string | undefined,
78
79
  ): TransactionRequestRpc {
79
80
  const request = r as Request<chain>
81
+ const account = request.account as Account | undefined
80
82
 
81
83
  // Convert EIP-1559 transactions to AA transactions.
82
84
  if (request.type === 'eip1559') (request as any).type = 'aa'
@@ -91,7 +93,7 @@ export function formatTransactionRequest<chain extends Chain | undefined>(
91
93
  if (action)
92
94
  request.calls = request.calls ?? [
93
95
  {
94
- to: r.to || undefined,
96
+ to: r.to || '0x0000000000000000000000000000000000000000',
95
97
  value: r.value,
96
98
  data: r.data,
97
99
  },
@@ -106,11 +108,10 @@ export function formatTransactionRequest<chain extends Chain | undefined>(
106
108
  s: BigInt(auth.s!),
107
109
  yParity: Number(auth.yParity),
108
110
  })),
109
- nonce: request.nonce ? BigInt(request.nonce) : undefined,
110
111
  type: 'aa',
111
112
  } as never)
112
113
 
113
- if (action === 'estimateGas' || action === 'fillTransaction') {
114
+ if (action === 'estimateGas') {
114
115
  rpc.maxFeePerGas = undefined
115
116
  rpc.maxPriorityFeePerGas = undefined
116
117
  }
@@ -140,12 +141,12 @@ export function formatTransactionRequest<chain extends Chain | undefined>(
140
141
  }
141
142
 
142
143
  const [keyType, keyData] = (() => {
143
- if (!r.account?.source) return [undefined, undefined]
144
- if (r.account.source === 'webAuthn')
144
+ const type = account?.keyType || account?.source
145
+ if (!type) return [undefined, undefined]
146
+ if (type === 'webAuthn')
145
147
  // TODO: derive correct bytes size of key data based on webauthn create metadata.
146
148
  return ['webAuthn', `0x${'ff'.repeat(1400)}`]
147
- if (['p256', 'secp256k1'].includes(r.account.source))
148
- return [r.account.source, undefined]
149
+ if (['p256', 'secp256k1'].includes(type)) return [type, undefined]
149
150
  return [undefined, undefined]
150
151
  })()
151
152
 
@@ -1,6 +1,8 @@
1
+ import { createStore, del, get, set } from 'idb-keyval'
1
2
  import * as Json from 'ox/Json'
2
3
 
3
4
  import type { MaybePromise } from '../internal/types.js'
5
+ import { normalizeValue } from './internal/utils.js'
4
6
 
5
7
  export type Storage<
6
8
  schema extends Record<string, unknown> = Record<string, unknown>,
@@ -33,6 +35,26 @@ export namespace from {
33
35
  }
34
36
  }
35
37
 
38
+ export function idb<schema extends Record<string, unknown>>() {
39
+ const store =
40
+ typeof indexedDB !== 'undefined'
41
+ ? createStore('tempo.ts', 'store')
42
+ : undefined
43
+ return from<schema>({
44
+ async getItem(name) {
45
+ const value = await get(name, store)
46
+ if (value === null) return null
47
+ return value
48
+ },
49
+ async removeItem(name) {
50
+ await del(name, store)
51
+ },
52
+ async setItem(name, value) {
53
+ await set(name, normalizeValue(value), store)
54
+ },
55
+ })
56
+ }
57
+
36
58
  export function localStorage<schema extends Record<string, unknown>>(
37
59
  options: localStorage.Options = {},
38
60
  ) {
@@ -1 +1 @@
1
- export const linkingUsd = 0n
1
+ export const pathUsd = 0n
@@ -29,6 +29,7 @@ import {
29
29
  type TransactionType as viem_TransactionType,
30
30
  } from 'viem'
31
31
  import type { ExactPartial, OneOf, PartialBy } from '../internal/types.js'
32
+ import type * as KeyAuthorization from '../ox/KeyAuthorization.js'
32
33
  import * as SignatureEnvelope from '../ox/SignatureEnvelope.js'
33
34
  import * as TxAA from '../ox/TransactionEnvelopeAA.js'
34
35
  import type * as ox_TransactionReceipt from '../ox/TransactionReceipt.js'
@@ -43,7 +44,11 @@ export type Transaction<
43
44
  >
44
45
  export type TransactionRpc<pending extends boolean = false> = OneOf<
45
46
  | viem_RpcTransaction<pending>
46
- | (Omit<TransactionAA<Hex.Hex, Hex.Hex, pending, '0x76'>, 'signature'> & {
47
+ | (Omit<
48
+ TransactionAA<Hex.Hex, Hex.Hex, pending, '0x76'>,
49
+ 'keyAuthorization' | 'signature'
50
+ > & {
51
+ keyAuthorization?: KeyAuthorization.Rpc | null | undefined
47
52
  signature: SignatureEnvelope.SignatureEnvelopeRpc
48
53
  })
49
54
  >
@@ -66,6 +71,7 @@ export type TransactionAA<
66
71
  chainId: index
67
72
  feeToken?: Address | undefined
68
73
  feePayerSignature?: viem_Signature | undefined
74
+ keyAuthorization?: KeyAuthorization.Signed<quantity, index> | null | undefined
69
75
  nonceKey?: quantity | undefined
70
76
  signature: SignatureEnvelope.SignatureEnvelope
71
77
  type: type
@@ -109,9 +115,13 @@ export type TransactionRequestAA<
109
115
  ExactPartial<FeeValuesEIP1559<quantity>> & {
110
116
  accessList?: AccessList | undefined
111
117
  authorizationList?: AuthorizationList<index, boolean> | undefined
118
+ keyAuthorization?: KeyAuthorization.Signed<quantity, index> | undefined
112
119
  calls?: readonly TxAA.Call<quantity>[] | undefined
113
120
  feePayer?: Account | true | undefined
114
121
  feeToken?: Address | bigint | undefined
122
+ nonceKey?: 'random' | quantity | undefined
123
+ validBefore?: index | undefined
124
+ validAfter?: index | undefined
115
125
  }
116
126
 
117
127
  export type TransactionSerializable = OneOf<
@@ -129,6 +139,7 @@ export type TransactionSerializableAA<
129
139
  chainId: number
130
140
  feeToken?: Address | bigint | undefined
131
141
  feePayerSignature?: viem_Signature | null | undefined
142
+ keyAuthorization?: KeyAuthorization.Signed<quantity, index> | undefined
132
143
  nonceKey?: quantity | undefined
133
144
  signature?: SignatureEnvelope.SignatureEnvelope<quantity, index> | undefined
134
145
  validBefore?: index | undefined
@@ -151,6 +162,7 @@ export function getType(
151
162
  typeof transaction.calls !== 'undefined' ||
152
163
  typeof transaction.feePayer !== 'undefined' ||
153
164
  typeof transaction.feeToken !== 'undefined' ||
165
+ typeof transaction.nonceKey !== 'undefined' ||
154
166
  typeof transaction.signature !== 'undefined' ||
155
167
  typeof transaction.validBefore !== 'undefined' ||
156
168
  typeof transaction.validAfter !== 'undefined'
@@ -303,7 +315,7 @@ async function serializeAA(
303
315
  ? rest.calls
304
316
  : [
305
317
  {
306
- to: rest.to || undefined,
318
+ to: rest.to || '0x0000000000000000000000000000000000000000',
307
319
  value: rest.value,
308
320
  data: rest.data,
309
321
  },