tempo.ts 0.8.0 → 0.8.2
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.
- package/CHANGELOG.md +14 -0
- package/dist/viem/Actions/reward.d.ts +164 -1
- package/dist/viem/Actions/reward.d.ts.map +1 -1
- package/dist/viem/Actions/reward.js +135 -1
- package/dist/viem/Actions/reward.js.map +1 -1
- package/dist/viem/Decorator.d.ts +126 -0
- package/dist/viem/Decorator.d.ts.map +1 -1
- package/dist/viem/Decorator.js +5 -0
- package/dist/viem/Decorator.js.map +1 -1
- package/dist/viem/Transaction.d.ts.map +1 -1
- package/dist/viem/Transaction.js +0 -3
- package/dist/viem/Transaction.js.map +1 -1
- package/dist/wagmi/Actions/reward.d.ts +108 -0
- package/dist/wagmi/Actions/reward.d.ts.map +1 -1
- package/dist/wagmi/Actions/reward.js +115 -0
- package/dist/wagmi/Actions/reward.js.map +1 -1
- package/dist/wagmi/Hooks/reward.d.ts +87 -1
- package/dist/wagmi/Hooks/reward.d.ts.map +1 -1
- package/dist/wagmi/Hooks/reward.js +122 -0
- package/dist/wagmi/Hooks/reward.js.map +1 -1
- package/package.json +1 -1
- package/src/viem/Actions/reward.test.ts +167 -0
- package/src/viem/Actions/reward.ts +233 -1
- package/src/viem/Decorator.ts +144 -0
- package/src/viem/Transaction.ts +0 -3
- package/src/wagmi/Actions/reward.test.ts +105 -0
- package/src/wagmi/Actions/reward.ts +175 -0
- package/src/wagmi/Hooks/reward.test.ts +171 -0
- package/src/wagmi/Hooks/reward.ts +170 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
1
2
|
import { useChainId, useConfig } from 'wagmi';
|
|
2
3
|
import { useMutation, useQuery, } from 'wagmi/query';
|
|
3
4
|
import * as Actions from '../Actions/reward.js';
|
|
@@ -101,6 +102,45 @@ export function useGetTotalPerSecond(parameters = {}) {
|
|
|
101
102
|
const enabled = Boolean(token && (query.enabled ?? true));
|
|
102
103
|
return useQuery({ ...query, ...options, enabled });
|
|
103
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Hook for getting the reward information for a specific account.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```tsx
|
|
110
|
+
* import { Hooks } from 'tempo.ts/wagmi'
|
|
111
|
+
*
|
|
112
|
+
* function App() {
|
|
113
|
+
* const { data, isLoading } = Hooks.reward.useUserRewardInfo({
|
|
114
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
115
|
+
* account: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
|
|
116
|
+
* })
|
|
117
|
+
*
|
|
118
|
+
* if (isLoading) return <div>Loading...</div>
|
|
119
|
+
* return (
|
|
120
|
+
* <div>
|
|
121
|
+
* <div>Recipient: {data?.rewardRecipient}</div>
|
|
122
|
+
* <div>Reward per token: {data?.rewardPerToken.toString()}</div>
|
|
123
|
+
* <div>Reward balance: {data?.rewardBalance.toString()}</div>
|
|
124
|
+
* </div>
|
|
125
|
+
* )
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* @param parameters - Parameters.
|
|
130
|
+
* @returns Query result with reward information (recipient, rewardPerToken, rewardBalance).
|
|
131
|
+
*/
|
|
132
|
+
export function useUserRewardInfo(parameters = {}) {
|
|
133
|
+
const { account, query = {}, token } = parameters;
|
|
134
|
+
const config = useConfig(parameters);
|
|
135
|
+
const chainId = useChainId({ config });
|
|
136
|
+
const options = Actions.getUserRewardInfo.queryOptions(config, {
|
|
137
|
+
...parameters,
|
|
138
|
+
chainId: parameters.chainId ?? chainId,
|
|
139
|
+
query: undefined,
|
|
140
|
+
});
|
|
141
|
+
const enabled = Boolean(token && account && (query.enabled ?? true));
|
|
142
|
+
return useQuery({ ...query, ...options, enabled });
|
|
143
|
+
}
|
|
104
144
|
/**
|
|
105
145
|
* Hook for setting the reward recipient for a token holder.
|
|
106
146
|
*
|
|
@@ -243,4 +283,86 @@ export function useStartSync(parameters = {}) {
|
|
|
243
283
|
mutationKey: ['startSync'],
|
|
244
284
|
});
|
|
245
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* Hook for watching reward scheduled events.
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```tsx
|
|
291
|
+
* import { Hooks } from 'tempo.ts/wagmi'
|
|
292
|
+
*
|
|
293
|
+
* function App() {
|
|
294
|
+
* Hooks.reward.useWatchRewardScheduled({
|
|
295
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
296
|
+
* onRewardScheduled(args) {
|
|
297
|
+
* console.log('Reward scheduled:', args)
|
|
298
|
+
* },
|
|
299
|
+
* })
|
|
300
|
+
*
|
|
301
|
+
* return <div>Watching for reward scheduled events...</div>
|
|
302
|
+
* }
|
|
303
|
+
* ```
|
|
304
|
+
*
|
|
305
|
+
* @param parameters - Parameters.
|
|
306
|
+
*/
|
|
307
|
+
export function useWatchRewardScheduled(parameters = {}) {
|
|
308
|
+
const { enabled = true, onRewardScheduled, token, ...rest } = parameters;
|
|
309
|
+
const config = useConfig({ config: parameters.config });
|
|
310
|
+
const configChainId = useChainId({ config });
|
|
311
|
+
const chainId = parameters.chainId ?? configChainId;
|
|
312
|
+
useEffect(() => {
|
|
313
|
+
if (!enabled)
|
|
314
|
+
return;
|
|
315
|
+
if (!onRewardScheduled)
|
|
316
|
+
return;
|
|
317
|
+
if (!token)
|
|
318
|
+
return;
|
|
319
|
+
return Actions.watchRewardScheduled(config, {
|
|
320
|
+
...rest,
|
|
321
|
+
chainId,
|
|
322
|
+
onRewardScheduled,
|
|
323
|
+
token,
|
|
324
|
+
});
|
|
325
|
+
}, [config, enabled, onRewardScheduled, rest, chainId, token]);
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Hook for watching reward recipient set events.
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* ```tsx
|
|
332
|
+
* import { Hooks } from 'tempo.ts/wagmi'
|
|
333
|
+
*
|
|
334
|
+
* function App() {
|
|
335
|
+
* Hooks.reward.useWatchRewardRecipientSet({
|
|
336
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
337
|
+
* onRewardRecipientSet(args) {
|
|
338
|
+
* console.log('Reward recipient set:', args)
|
|
339
|
+
* },
|
|
340
|
+
* })
|
|
341
|
+
*
|
|
342
|
+
* return <div>Watching for reward recipient set events...</div>
|
|
343
|
+
* }
|
|
344
|
+
* ```
|
|
345
|
+
*
|
|
346
|
+
* @param parameters - Parameters.
|
|
347
|
+
*/
|
|
348
|
+
export function useWatchRewardRecipientSet(parameters = {}) {
|
|
349
|
+
const { enabled = true, onRewardRecipientSet, token, ...rest } = parameters;
|
|
350
|
+
const config = useConfig({ config: parameters.config });
|
|
351
|
+
const configChainId = useChainId({ config });
|
|
352
|
+
const chainId = parameters.chainId ?? configChainId;
|
|
353
|
+
useEffect(() => {
|
|
354
|
+
if (!enabled)
|
|
355
|
+
return;
|
|
356
|
+
if (!onRewardRecipientSet)
|
|
357
|
+
return;
|
|
358
|
+
if (!token)
|
|
359
|
+
return;
|
|
360
|
+
return Actions.watchRewardRecipientSet(config, {
|
|
361
|
+
...rest,
|
|
362
|
+
chainId,
|
|
363
|
+
onRewardRecipientSet,
|
|
364
|
+
token,
|
|
365
|
+
});
|
|
366
|
+
}, [config, enabled, onRewardRecipientSet, rest, chainId, token]);
|
|
367
|
+
}
|
|
246
368
|
//# sourceMappingURL=reward.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reward.js","sourceRoot":"","sources":["../../../src/wagmi/Hooks/reward.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAE7C,OAAO,EAGL,WAAW,EACX,QAAQ,GACT,MAAM,aAAa,CAAA;AAEpB,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAA;AAE/C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,QAAQ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I;YACP,OAAO;YACP,oBAAoB;YACpB,KAAK;SACN,CAAC,CAAA;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,oBAAoB,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAA;AACnE,CAAC"}
|
package/package.json
CHANGED
|
@@ -123,6 +123,90 @@ describe('getTotalPerSecond', () => {
|
|
|
123
123
|
})
|
|
124
124
|
})
|
|
125
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
|
+
|
|
126
210
|
describe('setRecipientSync', () => {
|
|
127
211
|
test('default', async () => {
|
|
128
212
|
const { token } = await setupToken(clientWithAccount)
|
|
@@ -265,3 +349,86 @@ describe('startSync', () => {
|
|
|
265
349
|
expect(totalRate).toBe(0n)
|
|
266
350
|
})
|
|
267
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
|
+
})
|
|
@@ -4,13 +4,24 @@ import {
|
|
|
4
4
|
type BaseErrorType,
|
|
5
5
|
type Chain,
|
|
6
6
|
type Client,
|
|
7
|
+
type ExtractAbiItem,
|
|
8
|
+
type GetEventArgs,
|
|
7
9
|
type Log,
|
|
8
10
|
parseEventLogs,
|
|
9
11
|
type ReadContractReturnType,
|
|
10
12
|
type Transport,
|
|
13
|
+
type Log as viem_Log,
|
|
14
|
+
type WatchContractEventParameters,
|
|
15
|
+
type WatchContractEventReturnType,
|
|
11
16
|
type WriteContractReturnType,
|
|
12
17
|
} from 'viem'
|
|
13
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
readContract,
|
|
20
|
+
watchContractEvent,
|
|
21
|
+
writeContract,
|
|
22
|
+
writeContractSync,
|
|
23
|
+
} from 'viem/actions'
|
|
24
|
+
import type { UnionOmit } from '../../internal/types.js'
|
|
14
25
|
import * as Abis from '../Abis.js'
|
|
15
26
|
import type { ReadParameters, WriteParameters } from '../internal/types.js'
|
|
16
27
|
import { defineCall } from '../internal/utils.js'
|
|
@@ -276,6 +287,79 @@ export namespace getTotalPerSecond {
|
|
|
276
287
|
}
|
|
277
288
|
}
|
|
278
289
|
|
|
290
|
+
/**
|
|
291
|
+
* Gets the reward information for a specific account.
|
|
292
|
+
*
|
|
293
|
+
* Returns the reward recipient address, reward per token value, and accumulated reward balance for the specified account.
|
|
294
|
+
* This information includes:
|
|
295
|
+
* - `rewardRecipient`: The address designated to receive rewards (zero address if opted out)
|
|
296
|
+
* - `rewardPerToken`: The reward per token value for this account
|
|
297
|
+
* - `rewardBalance`: The accumulated reward balance waiting to be claimed
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* ```ts
|
|
301
|
+
* import { createClient, http } from 'viem'
|
|
302
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
303
|
+
* import { Actions } from 'tempo.ts/viem'
|
|
304
|
+
*
|
|
305
|
+
* const client = createClient({
|
|
306
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
307
|
+
* transport: http(),
|
|
308
|
+
* })
|
|
309
|
+
*
|
|
310
|
+
* const info = await Actions.reward.getUserRewardInfo(client, {
|
|
311
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
312
|
+
* account: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
|
|
313
|
+
* })
|
|
314
|
+
* ```
|
|
315
|
+
*
|
|
316
|
+
* @param client - Client.
|
|
317
|
+
* @param parameters - Parameters.
|
|
318
|
+
* @returns The user's reward information (recipient, rewardPerToken, rewardBalance).
|
|
319
|
+
*/
|
|
320
|
+
export async function getUserRewardInfo<chain extends Chain | undefined>(
|
|
321
|
+
client: Client<Transport, chain>,
|
|
322
|
+
parameters: getUserRewardInfo.Parameters,
|
|
323
|
+
): Promise<getUserRewardInfo.ReturnValue> {
|
|
324
|
+
return readContract(client, {
|
|
325
|
+
...parameters,
|
|
326
|
+
...getUserRewardInfo.call(parameters),
|
|
327
|
+
})
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export namespace getUserRewardInfo {
|
|
331
|
+
export type Parameters = ReadParameters & Args
|
|
332
|
+
|
|
333
|
+
export type Args = {
|
|
334
|
+
/** The account address to query reward info for */
|
|
335
|
+
account: Address
|
|
336
|
+
/** The TIP20 token address */
|
|
337
|
+
token: Address
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export type ReturnValue = ReadContractReturnType<
|
|
341
|
+
typeof Abis.tip20,
|
|
342
|
+
'userRewardInfo',
|
|
343
|
+
never
|
|
344
|
+
>
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Defines a call to the `userRewardInfo` function.
|
|
348
|
+
*
|
|
349
|
+
* @param args - Arguments.
|
|
350
|
+
* @returns The call.
|
|
351
|
+
*/
|
|
352
|
+
export function call(args: Args) {
|
|
353
|
+
const { account, token } = args
|
|
354
|
+
return defineCall({
|
|
355
|
+
address: token,
|
|
356
|
+
abi: Abis.tip20,
|
|
357
|
+
args: [account],
|
|
358
|
+
functionName: 'userRewardInfo',
|
|
359
|
+
})
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
279
363
|
/**
|
|
280
364
|
* Sets or changes the reward recipient for a token holder.
|
|
281
365
|
*
|
|
@@ -710,3 +794,151 @@ export declare namespace startSync {
|
|
|
710
794
|
|
|
711
795
|
export type ErrorType = start.ErrorType
|
|
712
796
|
}
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* Watches for reward scheduled events.
|
|
800
|
+
*
|
|
801
|
+
* @example
|
|
802
|
+
* ```ts
|
|
803
|
+
* import { createClient, http } from 'viem'
|
|
804
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
805
|
+
* import { Actions } from 'tempo.ts/viem'
|
|
806
|
+
*
|
|
807
|
+
* const client = createClient({
|
|
808
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
809
|
+
* transport: http(),
|
|
810
|
+
* })
|
|
811
|
+
*
|
|
812
|
+
* const unwatch = Actions.reward.watchRewardScheduled(client, {
|
|
813
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
814
|
+
* onRewardScheduled: (args, log) => {
|
|
815
|
+
* console.log('Reward scheduled:', args)
|
|
816
|
+
* },
|
|
817
|
+
* })
|
|
818
|
+
* ```
|
|
819
|
+
*
|
|
820
|
+
* @param client - Client.
|
|
821
|
+
* @param parameters - Parameters.
|
|
822
|
+
* @returns A function to unsubscribe from the event.
|
|
823
|
+
*/
|
|
824
|
+
export function watchRewardScheduled<
|
|
825
|
+
chain extends Chain | undefined,
|
|
826
|
+
account extends Account | undefined,
|
|
827
|
+
>(
|
|
828
|
+
client: Client<Transport, chain, account>,
|
|
829
|
+
parameters: watchRewardScheduled.Parameters,
|
|
830
|
+
) {
|
|
831
|
+
const { onRewardScheduled, token, ...rest } = parameters
|
|
832
|
+
return watchContractEvent(client, {
|
|
833
|
+
...rest,
|
|
834
|
+
address: token,
|
|
835
|
+
abi: Abis.tip20,
|
|
836
|
+
eventName: 'RewardScheduled',
|
|
837
|
+
onLogs: (logs) => {
|
|
838
|
+
for (const log of logs) onRewardScheduled(log.args, log)
|
|
839
|
+
},
|
|
840
|
+
strict: true,
|
|
841
|
+
})
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
export declare namespace watchRewardScheduled {
|
|
845
|
+
export type Args = GetEventArgs<
|
|
846
|
+
typeof Abis.tip20,
|
|
847
|
+
'RewardScheduled',
|
|
848
|
+
{ IndexedOnly: false; Required: true }
|
|
849
|
+
>
|
|
850
|
+
|
|
851
|
+
export type Log = viem_Log<
|
|
852
|
+
bigint,
|
|
853
|
+
number,
|
|
854
|
+
false,
|
|
855
|
+
ExtractAbiItem<typeof Abis.tip20, 'RewardScheduled'>,
|
|
856
|
+
true
|
|
857
|
+
>
|
|
858
|
+
|
|
859
|
+
export type Parameters = UnionOmit<
|
|
860
|
+
WatchContractEventParameters<typeof Abis.tip20, 'RewardScheduled', true>,
|
|
861
|
+
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
862
|
+
> & {
|
|
863
|
+
/** Callback to invoke when rewards are scheduled. */
|
|
864
|
+
onRewardScheduled: (args: Args, log: Log) => void
|
|
865
|
+
/** The TIP20 token address */
|
|
866
|
+
token: Address
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
export type ReturnValue = WatchContractEventReturnType
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* Watches for reward recipient set events.
|
|
874
|
+
*
|
|
875
|
+
* @example
|
|
876
|
+
* ```ts
|
|
877
|
+
* import { createClient, http } from 'viem'
|
|
878
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
879
|
+
* import { Actions } from 'tempo.ts/viem'
|
|
880
|
+
*
|
|
881
|
+
* const client = createClient({
|
|
882
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
883
|
+
* transport: http(),
|
|
884
|
+
* })
|
|
885
|
+
*
|
|
886
|
+
* const unwatch = Actions.reward.watchRewardRecipientSet(client, {
|
|
887
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
888
|
+
* onRewardRecipientSet: (args, log) => {
|
|
889
|
+
* console.log('Reward recipient set:', args)
|
|
890
|
+
* },
|
|
891
|
+
* })
|
|
892
|
+
* ```
|
|
893
|
+
*
|
|
894
|
+
* @param client - Client.
|
|
895
|
+
* @param parameters - Parameters.
|
|
896
|
+
* @returns A function to unsubscribe from the event.
|
|
897
|
+
*/
|
|
898
|
+
export function watchRewardRecipientSet<
|
|
899
|
+
chain extends Chain | undefined,
|
|
900
|
+
account extends Account | undefined,
|
|
901
|
+
>(
|
|
902
|
+
client: Client<Transport, chain, account>,
|
|
903
|
+
parameters: watchRewardRecipientSet.Parameters,
|
|
904
|
+
) {
|
|
905
|
+
const { onRewardRecipientSet, token, ...rest } = parameters
|
|
906
|
+
return watchContractEvent(client, {
|
|
907
|
+
...rest,
|
|
908
|
+
address: token,
|
|
909
|
+
abi: Abis.tip20,
|
|
910
|
+
eventName: 'RewardRecipientSet',
|
|
911
|
+
onLogs: (logs) => {
|
|
912
|
+
for (const log of logs) onRewardRecipientSet(log.args, log)
|
|
913
|
+
},
|
|
914
|
+
strict: true,
|
|
915
|
+
})
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
export declare namespace watchRewardRecipientSet {
|
|
919
|
+
export type Args = GetEventArgs<
|
|
920
|
+
typeof Abis.tip20,
|
|
921
|
+
'RewardRecipientSet',
|
|
922
|
+
{ IndexedOnly: false; Required: true }
|
|
923
|
+
>
|
|
924
|
+
|
|
925
|
+
export type Log = viem_Log<
|
|
926
|
+
bigint,
|
|
927
|
+
number,
|
|
928
|
+
false,
|
|
929
|
+
ExtractAbiItem<typeof Abis.tip20, 'RewardRecipientSet'>,
|
|
930
|
+
true
|
|
931
|
+
>
|
|
932
|
+
|
|
933
|
+
export type Parameters = UnionOmit<
|
|
934
|
+
WatchContractEventParameters<typeof Abis.tip20, 'RewardRecipientSet', true>,
|
|
935
|
+
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
936
|
+
> & {
|
|
937
|
+
/** Callback to invoke when a reward recipient is set. */
|
|
938
|
+
onRewardRecipientSet: (args: Args, log: Log) => void
|
|
939
|
+
/** The TIP20 token address */
|
|
940
|
+
token: Address
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
export type ReturnValue = WatchContractEventReturnType
|
|
944
|
+
}
|