tempo.ts 0.8.1 → 0.8.3
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 +84 -1
- package/dist/viem/Actions/reward.d.ts.map +1 -1
- package/dist/viem/Actions/reward.js +81 -1
- package/dist/viem/Actions/reward.js.map +1 -1
- package/dist/viem/Chain.d.ts +1 -3
- package/dist/viem/Chain.d.ts.map +1 -1
- package/dist/viem/Decorator.d.ts +52 -0
- package/dist/viem/Decorator.d.ts.map +1 -1
- package/dist/viem/Decorator.js +2 -0
- package/dist/viem/Decorator.js.map +1 -1
- package/dist/viem/Formatters.d.ts +2 -4
- package/dist/viem/Formatters.d.ts.map +1 -1
- package/dist/viem/Formatters.js +6 -4
- package/dist/viem/Formatters.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 +64 -0
- package/dist/wagmi/Actions/reward.d.ts.map +1 -1
- package/dist/wagmi/Actions/reward.js +66 -0
- package/dist/wagmi/Actions/reward.js.map +1 -1
- package/dist/wagmi/Hooks/reward.d.ts +55 -1
- package/dist/wagmi/Hooks/reward.d.ts.map +1 -1
- package/dist/wagmi/Hooks/reward.js +83 -0
- package/dist/wagmi/Hooks/reward.js.map +1 -1
- package/package.json +1 -1
- package/src/viem/Actions/reward.test.ts +83 -0
- package/src/viem/Actions/reward.ts +160 -1
- package/src/viem/Decorator.ts +60 -0
- package/src/viem/Formatters.ts +12 -7
- package/src/viem/Transaction.ts +0 -3
- package/src/wagmi/Actions/reward.test.ts +69 -0
- package/src/wagmi/Actions/reward.ts +84 -0
- package/src/wagmi/Hooks/reward.test.ts +99 -0
- package/src/wagmi/Hooks/reward.ts +102 -1
|
@@ -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'
|
|
@@ -783,3 +794,151 @@ export declare namespace startSync {
|
|
|
783
794
|
|
|
784
795
|
export type ErrorType = start.ErrorType
|
|
785
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
|
+
}
|
package/src/viem/Decorator.ts
CHANGED
|
@@ -1810,6 +1810,62 @@ export type Decorator<
|
|
|
1810
1810
|
startSync: (
|
|
1811
1811
|
parameters: rewardActions.startSync.Parameters<chain, account>,
|
|
1812
1812
|
) => Promise<rewardActions.startSync.ReturnValue>
|
|
1813
|
+
/**
|
|
1814
|
+
* Watches for reward recipient set events.
|
|
1815
|
+
*
|
|
1816
|
+
* @example
|
|
1817
|
+
* ```ts
|
|
1818
|
+
* import { createClient, http } from 'viem'
|
|
1819
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
1820
|
+
* import { tempoActions } from 'tempo.ts/viem'
|
|
1821
|
+
*
|
|
1822
|
+
* const client = createClient({
|
|
1823
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1824
|
+
* transport: http(),
|
|
1825
|
+
* }).extend(tempoActions())
|
|
1826
|
+
*
|
|
1827
|
+
* const unwatch = client.reward.watchRewardRecipientSet({
|
|
1828
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
1829
|
+
* onRewardRecipientSet: (args, log) => {
|
|
1830
|
+
* console.log('Reward recipient set:', args)
|
|
1831
|
+
* },
|
|
1832
|
+
* })
|
|
1833
|
+
* ```
|
|
1834
|
+
*
|
|
1835
|
+
* @param parameters - Parameters.
|
|
1836
|
+
* @returns A function to unsubscribe from the event.
|
|
1837
|
+
*/
|
|
1838
|
+
watchRewardRecipientSet: (
|
|
1839
|
+
parameters: rewardActions.watchRewardRecipientSet.Parameters,
|
|
1840
|
+
) => () => void
|
|
1841
|
+
/**
|
|
1842
|
+
* Watches for reward scheduled events.
|
|
1843
|
+
*
|
|
1844
|
+
* @example
|
|
1845
|
+
* ```ts
|
|
1846
|
+
* import { createClient, http } from 'viem'
|
|
1847
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
1848
|
+
* import { tempoActions } from 'tempo.ts/viem'
|
|
1849
|
+
*
|
|
1850
|
+
* const client = createClient({
|
|
1851
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1852
|
+
* transport: http(),
|
|
1853
|
+
* }).extend(tempoActions())
|
|
1854
|
+
*
|
|
1855
|
+
* const unwatch = client.reward.watchRewardScheduled({
|
|
1856
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
1857
|
+
* onRewardScheduled: (args, log) => {
|
|
1858
|
+
* console.log('Reward scheduled:', args)
|
|
1859
|
+
* },
|
|
1860
|
+
* })
|
|
1861
|
+
* ```
|
|
1862
|
+
*
|
|
1863
|
+
* @param parameters - Parameters.
|
|
1864
|
+
* @returns A function to unsubscribe from the event.
|
|
1865
|
+
*/
|
|
1866
|
+
watchRewardScheduled: (
|
|
1867
|
+
parameters: rewardActions.watchRewardScheduled.Parameters,
|
|
1868
|
+
) => () => void
|
|
1813
1869
|
}
|
|
1814
1870
|
token: {
|
|
1815
1871
|
/**
|
|
@@ -3078,6 +3134,10 @@ export function decorator() {
|
|
|
3078
3134
|
rewardActions.setRecipientSync(client, parameters),
|
|
3079
3135
|
start: (parameters) => rewardActions.start(client, parameters),
|
|
3080
3136
|
startSync: (parameters) => rewardActions.startSync(client, parameters),
|
|
3137
|
+
watchRewardRecipientSet: (parameters) =>
|
|
3138
|
+
rewardActions.watchRewardRecipientSet(client, parameters),
|
|
3139
|
+
watchRewardScheduled: (parameters) =>
|
|
3140
|
+
rewardActions.watchRewardScheduled(client, parameters),
|
|
3081
3141
|
},
|
|
3082
3142
|
token: {
|
|
3083
3143
|
approve: (parameters) => tokenActions.approve(client, parameters),
|
package/src/viem/Formatters.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
formatTransactionReceipt as viem_formatTransactionReceipt,
|
|
9
9
|
formatTransactionRequest as viem_formatTransactionRequest,
|
|
10
10
|
} from 'viem'
|
|
11
|
-
import { parseAccount } from 'viem/accounts'
|
|
11
|
+
import { type Address, 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'
|
|
@@ -72,13 +72,17 @@ type Request<chain extends Chain | undefined> = UnionOmit<
|
|
|
72
72
|
TransactionRequest,
|
|
73
73
|
'feeToken'
|
|
74
74
|
> &
|
|
75
|
-
GetFeeTokenParameter<chain>
|
|
75
|
+
GetFeeTokenParameter<chain>
|
|
76
76
|
export function formatTransactionRequest<chain extends Chain | undefined>(
|
|
77
77
|
r: Request<chain>,
|
|
78
78
|
action?: string | undefined,
|
|
79
79
|
): TransactionRequestRpc {
|
|
80
|
-
const request = r as Request<chain>
|
|
81
|
-
|
|
80
|
+
const request = r as Request<chain> & {
|
|
81
|
+
account?: viem_Account | Address | undefined
|
|
82
|
+
}
|
|
83
|
+
const account = request.account
|
|
84
|
+
? parseAccount<Account | viem_Account | Address>(request.account)
|
|
85
|
+
: undefined
|
|
82
86
|
|
|
83
87
|
// Convert EIP-1559 transactions to AA transactions.
|
|
84
88
|
if (request.type === 'eip1559') (request as any).type = 'aa'
|
|
@@ -122,7 +126,7 @@ export function formatTransactionRequest<chain extends Chain | undefined>(
|
|
|
122
126
|
// TODO: `calls` will not be supported by a lot of JSON-RPC accounts (wallet),
|
|
123
127
|
// use `wallet_sendCalls` or sequential `eth_sendTransaction` to mimic the
|
|
124
128
|
// behavior of `calls`.
|
|
125
|
-
if (
|
|
129
|
+
if (account?.type === 'json-rpc') {
|
|
126
130
|
if (rpc.calls?.length && rpc.calls.length > 1)
|
|
127
131
|
throw new Error(
|
|
128
132
|
'Batch calls are not supported with JSON-RPC accounts yet.',
|
|
@@ -134,14 +138,15 @@ export function formatTransactionRequest<chain extends Chain | undefined>(
|
|
|
134
138
|
// However, `calls` may not be supported by JSON-RPC accounts (wallets) yet,
|
|
135
139
|
// so we will not remove the `data`, `to`, and `value` fields to make it
|
|
136
140
|
// compatible with the base transaction structure.
|
|
137
|
-
if (
|
|
141
|
+
if (account?.type !== 'json-rpc') {
|
|
138
142
|
rpc.to = undefined
|
|
139
143
|
rpc.data = undefined
|
|
140
144
|
rpc.value = undefined
|
|
141
145
|
}
|
|
142
146
|
|
|
143
147
|
const [keyType, keyData] = (() => {
|
|
144
|
-
const type =
|
|
148
|
+
const type =
|
|
149
|
+
account && 'keyType' in account ? account.keyType : account?.source
|
|
145
150
|
if (!type) return [undefined, undefined]
|
|
146
151
|
if (type === 'webAuthn')
|
|
147
152
|
// TODO: derive correct bytes size of key data based on webauthn create metadata.
|
package/src/viem/Transaction.ts
CHANGED
|
@@ -216,9 +216,6 @@ export async function serialize(
|
|
|
216
216
|
| OneOf<SignatureEnvelope.SignatureEnvelope | viem_Signature>
|
|
217
217
|
| undefined,
|
|
218
218
|
) {
|
|
219
|
-
// Convert EIP-1559 transactions to AA transactions.
|
|
220
|
-
if (transaction.type === 'eip1559') (transaction as any).type = 'aa'
|
|
221
|
-
|
|
222
219
|
// If the transaction is not a Tempo transaction, route to Viem serializer.
|
|
223
220
|
if (!isTempo(transaction)) {
|
|
224
221
|
if (signature && 'type' in signature && signature.type !== 'secp256k1')
|
|
@@ -145,3 +145,72 @@ describe('setRecipientSync', () => {
|
|
|
145
145
|
expect(recipient).toBe(account.address)
|
|
146
146
|
})
|
|
147
147
|
})
|
|
148
|
+
|
|
149
|
+
describe('watchRewardScheduled', () => {
|
|
150
|
+
test('default', async () => {
|
|
151
|
+
const { token } = await setupToken()
|
|
152
|
+
|
|
153
|
+
const account = getAccount(config)
|
|
154
|
+
|
|
155
|
+
// Setup rewards
|
|
156
|
+
await actions.setRecipientSync(config, {
|
|
157
|
+
recipient: account.address!,
|
|
158
|
+
token,
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
const rewardAmount = parseUnits('100', 6)
|
|
162
|
+
await tokenActions.mintSync(config, {
|
|
163
|
+
amount: rewardAmount,
|
|
164
|
+
to: account.address!,
|
|
165
|
+
token,
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
const events: any[] = []
|
|
169
|
+
const unwatch = actions.watchRewardScheduled(config, {
|
|
170
|
+
token,
|
|
171
|
+
onRewardScheduled: (args) => {
|
|
172
|
+
events.push(args)
|
|
173
|
+
},
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
await actions.startSync(config, {
|
|
177
|
+
amount: rewardAmount,
|
|
178
|
+
token,
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
await new Promise((resolve) => setTimeout(resolve, 500))
|
|
182
|
+
|
|
183
|
+
expect(events.length).toBeGreaterThan(0)
|
|
184
|
+
expect(events[0]?.amount).toBe(rewardAmount)
|
|
185
|
+
expect(events[0]?.funder).toBe(account.address)
|
|
186
|
+
unwatch()
|
|
187
|
+
})
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
describe('watchRewardRecipientSet', () => {
|
|
191
|
+
test('default', async () => {
|
|
192
|
+
const { token } = await setupToken()
|
|
193
|
+
|
|
194
|
+
const account = getAccount(config)
|
|
195
|
+
|
|
196
|
+
const events: any[] = []
|
|
197
|
+
const unwatch = actions.watchRewardRecipientSet(config, {
|
|
198
|
+
token,
|
|
199
|
+
onRewardRecipientSet: (args) => {
|
|
200
|
+
events.push(args)
|
|
201
|
+
},
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
await actions.setRecipientSync(config, {
|
|
205
|
+
recipient: account.address!,
|
|
206
|
+
token,
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
await new Promise((resolve) => setTimeout(resolve, 500))
|
|
210
|
+
|
|
211
|
+
expect(events.length).toBeGreaterThan(0)
|
|
212
|
+
expect(events[0]?.holder).toBe(account.address)
|
|
213
|
+
expect(events[0]?.recipient).toBe(account.address)
|
|
214
|
+
unwatch()
|
|
215
|
+
})
|
|
216
|
+
})
|
|
@@ -524,3 +524,87 @@ export declare namespace startSync {
|
|
|
524
524
|
|
|
525
525
|
export type ErrorType = viem_Actions.startSync.ErrorType
|
|
526
526
|
}
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Watches for reward scheduled events.
|
|
530
|
+
*
|
|
531
|
+
* @example
|
|
532
|
+
* ```ts
|
|
533
|
+
* import { createConfig, http } from '@wagmi/core'
|
|
534
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
535
|
+
* import { Actions } from 'tempo.ts/wagmi'
|
|
536
|
+
*
|
|
537
|
+
* const config = createConfig({
|
|
538
|
+
* chains: [tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })],
|
|
539
|
+
* transports: {
|
|
540
|
+
* [tempo.id]: http(),
|
|
541
|
+
* },
|
|
542
|
+
* })
|
|
543
|
+
*
|
|
544
|
+
* const unwatch = Actions.reward.watchRewardScheduled(config, {
|
|
545
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
546
|
+
* onRewardScheduled: (args, log) => {
|
|
547
|
+
* console.log('Reward scheduled:', args)
|
|
548
|
+
* },
|
|
549
|
+
* })
|
|
550
|
+
* ```
|
|
551
|
+
*
|
|
552
|
+
* @param config - Config.
|
|
553
|
+
* @param parameters - Parameters.
|
|
554
|
+
* @returns A function to unsubscribe from the event.
|
|
555
|
+
*/
|
|
556
|
+
export function watchRewardScheduled<config extends Config>(
|
|
557
|
+
config: config,
|
|
558
|
+
parameters: watchRewardScheduled.Parameters<config>,
|
|
559
|
+
) {
|
|
560
|
+
const { chainId, ...rest } = parameters
|
|
561
|
+
const client = config.getClient({ chainId })
|
|
562
|
+
return viem_Actions.watchRewardScheduled(client, rest)
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
export declare namespace watchRewardScheduled {
|
|
566
|
+
export type Parameters<config extends Config> = ChainIdParameter<config> &
|
|
567
|
+
viem_Actions.watchRewardScheduled.Parameters
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Watches for reward recipient set events.
|
|
572
|
+
*
|
|
573
|
+
* @example
|
|
574
|
+
* ```ts
|
|
575
|
+
* import { createConfig, http } from '@wagmi/core'
|
|
576
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
577
|
+
* import { Actions } from 'tempo.ts/wagmi'
|
|
578
|
+
*
|
|
579
|
+
* const config = createConfig({
|
|
580
|
+
* chains: [tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })],
|
|
581
|
+
* transports: {
|
|
582
|
+
* [tempo.id]: http(),
|
|
583
|
+
* },
|
|
584
|
+
* })
|
|
585
|
+
*
|
|
586
|
+
* const unwatch = Actions.reward.watchRewardRecipientSet(config, {
|
|
587
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
588
|
+
* onRewardRecipientSet: (args, log) => {
|
|
589
|
+
* console.log('Reward recipient set:', args)
|
|
590
|
+
* },
|
|
591
|
+
* })
|
|
592
|
+
* ```
|
|
593
|
+
*
|
|
594
|
+
* @param config - Config.
|
|
595
|
+
* @param parameters - Parameters.
|
|
596
|
+
* @returns A function to unsubscribe from the event.
|
|
597
|
+
*/
|
|
598
|
+
export function watchRewardRecipientSet<config extends Config>(
|
|
599
|
+
config: config,
|
|
600
|
+
parameters: watchRewardRecipientSet.Parameters<config>,
|
|
601
|
+
) {
|
|
602
|
+
const { chainId, ...rest } = parameters
|
|
603
|
+
const client = config.getClient({ chainId })
|
|
604
|
+
return viem_Actions.watchRewardRecipientSet(client, rest)
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
export declare namespace watchRewardRecipientSet {
|
|
608
|
+
export type Parameters<config extends Config> = ChainIdParameter<config> &
|
|
609
|
+
viem_Actions.watchRewardRecipientSet.Parameters
|
|
610
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { getAccount } from '@wagmi/core'
|
|
2
2
|
import type { Address } from 'viem'
|
|
3
|
+
import { parseUnits } from 'viem'
|
|
3
4
|
import { describe, expect, test, vi } from 'vitest'
|
|
4
5
|
import { useConnect } from 'wagmi'
|
|
5
6
|
import { config, renderHook, setupToken } from '../../../test/wagmi/config.js'
|
|
6
7
|
import * as hooks from './reward.js'
|
|
8
|
+
import * as tokenHooks from './token.js'
|
|
7
9
|
|
|
8
10
|
describe('useGetTotalPerSecond', () => {
|
|
9
11
|
test('default', async () => {
|
|
@@ -148,3 +150,100 @@ describe('useSetRecipientSync', () => {
|
|
|
148
150
|
)
|
|
149
151
|
})
|
|
150
152
|
})
|
|
153
|
+
|
|
154
|
+
describe('useWatchRewardScheduled', () => {
|
|
155
|
+
test('default', async () => {
|
|
156
|
+
const { result: connectResult } = await renderHook(() => ({
|
|
157
|
+
connect: useConnect(),
|
|
158
|
+
grantRolesSync: tokenHooks.useGrantRolesSync(),
|
|
159
|
+
mintSync: tokenHooks.useMintSync(),
|
|
160
|
+
setRecipientSync: hooks.useSetRecipientSync(),
|
|
161
|
+
startSync: hooks.useStartSync(),
|
|
162
|
+
}))
|
|
163
|
+
|
|
164
|
+
await connectResult.current.connect.connectAsync({
|
|
165
|
+
connector: config.connectors[0]!,
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
const { token: tokenAddr } = await setupToken()
|
|
169
|
+
|
|
170
|
+
const account = getAccount(config).address
|
|
171
|
+
|
|
172
|
+
await connectResult.current.grantRolesSync.mutateAsync({
|
|
173
|
+
token: tokenAddr,
|
|
174
|
+
roles: ['issuer'],
|
|
175
|
+
to: account!,
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
const rewardAmount = parseUnits('100', 6)
|
|
179
|
+
await connectResult.current.mintSync.mutateAsync({
|
|
180
|
+
token: tokenAddr,
|
|
181
|
+
to: account!,
|
|
182
|
+
amount: rewardAmount,
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
await connectResult.current.setRecipientSync.mutateAsync({
|
|
186
|
+
token: tokenAddr,
|
|
187
|
+
recipient: account!,
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
const events: any[] = []
|
|
191
|
+
await renderHook(() =>
|
|
192
|
+
hooks.useWatchRewardScheduled({
|
|
193
|
+
token: tokenAddr,
|
|
194
|
+
onRewardScheduled(args) {
|
|
195
|
+
events.push(args)
|
|
196
|
+
},
|
|
197
|
+
}),
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
await connectResult.current.startSync.mutateAsync({
|
|
201
|
+
token: tokenAddr,
|
|
202
|
+
amount: rewardAmount,
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
await vi.waitUntil(() => events.length >= 1)
|
|
206
|
+
|
|
207
|
+
expect(events.length).toBeGreaterThanOrEqual(1)
|
|
208
|
+
expect(events[0]?.amount).toBe(rewardAmount)
|
|
209
|
+
expect(events[0]?.funder).toBe(account)
|
|
210
|
+
})
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
describe('useWatchRewardRecipientSet', () => {
|
|
214
|
+
test('default', async () => {
|
|
215
|
+
const { result: connectResult } = await renderHook(() => ({
|
|
216
|
+
connect: useConnect(),
|
|
217
|
+
setRecipientSync: hooks.useSetRecipientSync(),
|
|
218
|
+
}))
|
|
219
|
+
|
|
220
|
+
await connectResult.current.connect.connectAsync({
|
|
221
|
+
connector: config.connectors[0]!,
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
const { token: tokenAddr } = await setupToken()
|
|
225
|
+
|
|
226
|
+
const account = getAccount(config).address
|
|
227
|
+
|
|
228
|
+
const events: any[] = []
|
|
229
|
+
await renderHook(() =>
|
|
230
|
+
hooks.useWatchRewardRecipientSet({
|
|
231
|
+
token: tokenAddr,
|
|
232
|
+
onRewardRecipientSet(args) {
|
|
233
|
+
events.push(args)
|
|
234
|
+
},
|
|
235
|
+
}),
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
await connectResult.current.setRecipientSync.mutateAsync({
|
|
239
|
+
token: tokenAddr,
|
|
240
|
+
recipient: account!,
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
await vi.waitUntil(() => events.length >= 1)
|
|
244
|
+
|
|
245
|
+
expect(events.length).toBeGreaterThanOrEqual(1)
|
|
246
|
+
expect(events[0]?.holder).toBe(account)
|
|
247
|
+
expect(events[0]?.recipient).toBe(account)
|
|
248
|
+
})
|
|
249
|
+
})
|