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,434 +0,0 @@
1
- import { parseUnits } from 'viem'
2
- import { describe, expect, test } from 'vitest'
3
- import { clientWithAccount, setupToken } from '../../../test/viem/config.js'
4
- import * as actions from './index.js'
5
-
6
- const account = clientWithAccount.account
7
-
8
- describe('claimSync', () => {
9
- test('default', async () => {
10
- const { token } = await setupToken(clientWithAccount)
11
-
12
- const balanceBefore = await actions.token.getBalance(clientWithAccount, {
13
- token,
14
- })
15
-
16
- // Opt in to rewards
17
- await actions.reward.setRecipientSync(clientWithAccount, {
18
- recipient: account.address,
19
- token,
20
- })
21
-
22
- // Mint reward tokens
23
- const rewardAmount = parseUnits('100', 6)
24
- await actions.token.mintSync(clientWithAccount, {
25
- amount: rewardAmount,
26
- to: account.address,
27
- token,
28
- })
29
-
30
- // Start immediate reward to distribute rewards
31
- await actions.reward.startSync(clientWithAccount, {
32
- amount: rewardAmount,
33
- token,
34
- })
35
-
36
- // Trigger reward accrual by transferring
37
- await actions.token.transferSync(clientWithAccount, {
38
- amount: 1n,
39
- to: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
40
- token,
41
- })
42
-
43
- // Claim rewards
44
- await actions.reward.claimSync(clientWithAccount, {
45
- token,
46
- })
47
-
48
- const balanceAfter = await actions.token.getBalance(clientWithAccount, {
49
- token,
50
- })
51
-
52
- expect(balanceAfter).toBeGreaterThan(
53
- balanceBefore + rewardAmount - parseUnits('1', 6),
54
- )
55
- })
56
-
57
- test('behavior: claiming from streaming reward', async () => {
58
- const { token } = await setupToken(clientWithAccount)
59
-
60
- const balanceBefore = await actions.token.getBalance(clientWithAccount, {
61
- token,
62
- })
63
-
64
- // Mint tokens to have balance
65
- const mintAmount = parseUnits('1000', 6)
66
- await actions.token.mintSync(clientWithAccount, {
67
- amount: mintAmount,
68
- to: account.address,
69
- token,
70
- })
71
-
72
- // Opt in to rewards
73
- await actions.reward.setRecipientSync(clientWithAccount, {
74
- recipient: account.address,
75
- token,
76
- })
77
-
78
- // Mint reward tokens
79
- const rewardAmount = parseUnits('100', 6)
80
- await actions.token.mintSync(clientWithAccount, {
81
- amount: rewardAmount,
82
- to: account.address,
83
- token,
84
- })
85
-
86
- // Start a streaming reward (not immediate)
87
- await actions.reward.startSync(clientWithAccount, {
88
- amount: rewardAmount,
89
- token,
90
- })
91
-
92
- // Wait a bit and trigger accrual by transferring
93
- await new Promise((resolve) => setTimeout(resolve, 2000))
94
- await actions.token.transferSync(clientWithAccount, {
95
- amount: 1n,
96
- to: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
97
- token,
98
- })
99
-
100
- // Claim accumulated rewards from the stream
101
- await actions.reward.claimSync(clientWithAccount, {
102
- token,
103
- })
104
-
105
- const balanceAfter = await actions.token.getBalance(clientWithAccount, {
106
- token,
107
- })
108
-
109
- // Should have accumulated some rewards (at least 10% of total after 2 seconds)
110
- expect(balanceAfter).toBeGreaterThan(balanceBefore + rewardAmount / 10n)
111
- })
112
- })
113
-
114
- describe('getTotalPerSecond', () => {
115
- test('default', async () => {
116
- const { token } = await setupToken(clientWithAccount)
117
-
118
- const rate = await actions.reward.getTotalPerSecond(clientWithAccount, {
119
- token,
120
- })
121
-
122
- expect(rate).toBe(0n)
123
- })
124
- })
125
-
126
- describe('getUserRewardInfo', () => {
127
- test('default', async () => {
128
- const { token } = await setupToken(clientWithAccount)
129
-
130
- const info = await actions.reward.getUserRewardInfo(clientWithAccount, {
131
- token,
132
- account: account.address,
133
- })
134
-
135
- expect(info.rewardRecipient).toBeDefined()
136
- expect(info.rewardPerToken).toBeDefined()
137
- expect(info.rewardBalance).toBeDefined()
138
- expect(info.rewardRecipient).toBe(
139
- '0x0000000000000000000000000000000000000000',
140
- )
141
- expect(info.rewardPerToken).toBe(0n)
142
- expect(info.rewardBalance).toBe(0n)
143
- })
144
-
145
- test('behavior: after opting in', async () => {
146
- const { token } = await setupToken(clientWithAccount)
147
-
148
- // Opt in to rewards
149
- await actions.reward.setRecipientSync(clientWithAccount, {
150
- recipient: account.address,
151
- token,
152
- })
153
-
154
- const info = await actions.reward.getUserRewardInfo(clientWithAccount, {
155
- token,
156
- account: account.address,
157
- })
158
-
159
- expect(info.rewardRecipient).toBe(account.address)
160
- expect(info.rewardPerToken).toBe(0n)
161
- expect(info.rewardBalance).toBe(0n)
162
- })
163
-
164
- test('behavior: with active rewards after distribution', async () => {
165
- const { token } = await setupToken(clientWithAccount)
166
-
167
- // Opt in to rewards
168
- await actions.reward.setRecipientSync(clientWithAccount, {
169
- recipient: account.address,
170
- token,
171
- })
172
-
173
- // Mint reward tokens
174
- const rewardAmount = parseUnits('100', 6)
175
- await actions.token.mintSync(clientWithAccount, {
176
- amount: rewardAmount,
177
- to: account.address,
178
- token,
179
- })
180
-
181
- // Start immediate reward to distribute rewards
182
- await actions.reward.startSync(clientWithAccount, {
183
- amount: rewardAmount,
184
- token,
185
- })
186
-
187
- // Trigger reward accrual by transferring
188
- await actions.token.transferSync(clientWithAccount, {
189
- amount: 1n,
190
- to: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
191
- token,
192
- })
193
-
194
- // Check reward info shows accumulated rewards
195
- const info = await actions.reward.getUserRewardInfo(clientWithAccount, {
196
- token,
197
- account: account.address,
198
- })
199
-
200
- expect(info.rewardRecipient).toBe(account.address)
201
- expect(info.rewardPerToken).toBeGreaterThan(0n)
202
- expect(info.rewardBalance).toBeGreaterThan(0n)
203
- // Should have approximately the full reward amount (minus the 1 token transferred)
204
- expect(info.rewardBalance).toBeGreaterThanOrEqual(
205
- rewardAmount - parseUnits('1', 6),
206
- )
207
- })
208
- })
209
-
210
- describe('setRecipientSync', () => {
211
- test('default', async () => {
212
- const { token } = await setupToken(clientWithAccount)
213
-
214
- // Set reward recipient to self
215
- const { holder, receipt, recipient } =
216
- await actions.reward.setRecipientSync(clientWithAccount, {
217
- recipient: account.address,
218
- token,
219
- })
220
-
221
- expect(receipt).toBeDefined()
222
- expect(holder).toBe(account.address)
223
- expect(recipient).toBe(account.address)
224
- })
225
-
226
- test('behavior: opt out with zero address', async () => {
227
- const { token } = await setupToken(clientWithAccount)
228
-
229
- // First opt in
230
- await actions.reward.setRecipientSync(clientWithAccount, {
231
- recipient: account.address,
232
- token,
233
- })
234
-
235
- // Then opt out
236
- const { holder, recipient } = await actions.reward.setRecipientSync(
237
- clientWithAccount,
238
- {
239
- recipient: '0x0000000000000000000000000000000000000000',
240
- token,
241
- },
242
- )
243
-
244
- expect(holder).toBe(account.address)
245
- expect(recipient).toBe('0x0000000000000000000000000000000000000000')
246
- })
247
- })
248
-
249
- describe('startSync', () => {
250
- test('behavior: immediate distribution (seconds = 0)', async () => {
251
- const { token } = await setupToken(clientWithAccount)
252
-
253
- // Opt in to rewards
254
- await actions.reward.setRecipientSync(clientWithAccount, {
255
- recipient: account.address,
256
- token,
257
- })
258
-
259
- const balanceBeforeReward = await actions.token.getBalance(
260
- clientWithAccount,
261
- {
262
- token,
263
- },
264
- )
265
-
266
- // Mint reward tokens
267
- const rewardAmount = parseUnits('100', 6)
268
- await actions.token.mintSync(clientWithAccount, {
269
- amount: rewardAmount,
270
- to: account.address,
271
- token,
272
- })
273
-
274
- // Start immediate reward
275
- const { id } = await actions.reward.startSync(clientWithAccount, {
276
- amount: rewardAmount,
277
- token,
278
- })
279
-
280
- expect(id).toBe(0n) // Immediate distributions return ID 0
281
-
282
- // Trigger reward distribution by transferring
283
- await actions.token.transferSync(clientWithAccount, {
284
- amount: 1n,
285
- to: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
286
- token,
287
- })
288
-
289
- // Claim the accumulated rewards
290
- await actions.reward.claimSync(clientWithAccount, {
291
- token,
292
- })
293
-
294
- const balanceAfter = await actions.token.getBalance(clientWithAccount, {
295
- token,
296
- })
297
-
298
- // Account should have received rewards
299
- expect(balanceAfter).toBeGreaterThanOrEqual(
300
- balanceBeforeReward + rewardAmount - 1n,
301
- )
302
-
303
- // Total reward per second should be zero for immediate distributions
304
- const totalRate = await actions.reward.getTotalPerSecond(
305
- clientWithAccount,
306
- {
307
- token,
308
- },
309
- )
310
- expect(totalRate).toBe(0n)
311
- })
312
-
313
- test('behavior: immediate distribution with opted-in holders', async () => {
314
- const { token } = await setupToken(clientWithAccount)
315
-
316
- // Opt in to rewards
317
- await actions.reward.setRecipientSync(clientWithAccount, {
318
- recipient: account.address,
319
- token,
320
- })
321
-
322
- // Mint reward tokens
323
- const rewardAmount = parseUnits('100', 6)
324
- await actions.token.mintSync(clientWithAccount, {
325
- amount: rewardAmount,
326
- to: account.address,
327
- token,
328
- })
329
-
330
- // Start immediate reward
331
- const { amount, durationSeconds, funder, id } =
332
- await actions.reward.startSync(clientWithAccount, {
333
- amount: rewardAmount,
334
- token,
335
- })
336
-
337
- expect(id).toBe(0n) // Immediate distributions return ID 0
338
- expect(funder).toBe(account.address)
339
- expect(amount).toBe(rewardAmount)
340
- expect(durationSeconds).toBe(0)
341
-
342
- // Total reward per second should be zero for immediate distributions
343
- const totalRate = await actions.reward.getTotalPerSecond(
344
- clientWithAccount,
345
- {
346
- token,
347
- },
348
- )
349
- expect(totalRate).toBe(0n)
350
- })
351
- })
352
-
353
- describe('watchRewardScheduled', () => {
354
- test('default', async () => {
355
- const { token } = await setupToken(clientWithAccount)
356
-
357
- // Opt in to rewards
358
- await actions.reward.setRecipientSync(clientWithAccount, {
359
- recipient: account.address,
360
- token,
361
- })
362
-
363
- // Mint reward tokens
364
- const rewardAmount = parseUnits('100', 6)
365
- await actions.token.mintSync(clientWithAccount, {
366
- amount: rewardAmount,
367
- to: account.address,
368
- token,
369
- })
370
-
371
- const events: Array<{
372
- args: actions.reward.watchRewardScheduled.Args
373
- log: actions.reward.watchRewardScheduled.Log
374
- }> = []
375
-
376
- const unwatch = actions.reward.watchRewardScheduled(clientWithAccount, {
377
- token,
378
- onRewardScheduled: (args, log) => {
379
- events.push({ args, log })
380
- },
381
- })
382
-
383
- try {
384
- await actions.reward.startSync(clientWithAccount, {
385
- amount: rewardAmount,
386
- token,
387
- })
388
-
389
- await new Promise((resolve) => setTimeout(resolve, 500))
390
-
391
- expect(events.length).toBeGreaterThan(0)
392
- expect(events[0]?.args.amount).toBe(rewardAmount)
393
- expect(events[0]?.args.funder).toBe(account.address)
394
- expect(events[0]?.args.durationSeconds).toBe(0)
395
- expect(events[0]?.log).toBeDefined()
396
- } finally {
397
- if (unwatch) unwatch()
398
- }
399
- })
400
- })
401
-
402
- describe('watchRewardRecipientSet', () => {
403
- test('default', async () => {
404
- const { token } = await setupToken(clientWithAccount)
405
-
406
- const events: Array<{
407
- args: actions.reward.watchRewardRecipientSet.Args
408
- log: actions.reward.watchRewardRecipientSet.Log
409
- }> = []
410
-
411
- const unwatch = actions.reward.watchRewardRecipientSet(clientWithAccount, {
412
- token,
413
- onRewardRecipientSet: (args, log) => {
414
- events.push({ args, log })
415
- },
416
- })
417
-
418
- try {
419
- await actions.reward.setRecipientSync(clientWithAccount, {
420
- recipient: account.address,
421
- token,
422
- })
423
-
424
- await new Promise((resolve) => setTimeout(resolve, 500))
425
-
426
- expect(events.length).toBeGreaterThan(0)
427
- expect(events[0]?.args.holder).toBe(account.address)
428
- expect(events[0]?.args.recipient).toBe(account.address)
429
- expect(events[0]?.log).toBeDefined()
430
- } finally {
431
- if (unwatch) unwatch()
432
- }
433
- })
434
- })