tempo.ts 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -2
- package/dist/chains.d.ts +509 -115
- package/dist/chains.d.ts.map +1 -1
- package/dist/chains.js +18 -9
- package/dist/chains.js.map +1 -1
- package/dist/ox/Order.d.ts +92 -0
- package/dist/ox/Order.d.ts.map +1 -0
- package/dist/ox/Order.js +88 -0
- package/dist/ox/Order.js.map +1 -0
- package/dist/ox/OrdersFilters.d.ts +72 -0
- package/dist/ox/OrdersFilters.d.ts.map +1 -0
- package/dist/ox/OrdersFilters.js +100 -0
- package/dist/ox/OrdersFilters.js.map +1 -0
- package/dist/ox/Pagination.d.ts +128 -0
- package/dist/ox/Pagination.d.ts.map +1 -0
- package/dist/ox/Pagination.js +78 -0
- package/dist/ox/Pagination.js.map +1 -0
- package/dist/ox/PoolId.d.ts +18 -0
- package/dist/ox/PoolId.d.ts.map +1 -0
- package/dist/ox/PoolId.js +13 -0
- package/dist/ox/PoolId.js.map +1 -0
- package/dist/ox/RpcSchema.d.ts +32 -0
- package/dist/ox/RpcSchema.d.ts.map +1 -0
- package/dist/ox/RpcSchema.js +2 -0
- package/dist/ox/RpcSchema.js.map +1 -0
- package/dist/ox/SignatureEnvelope.d.ts +1 -1
- package/dist/ox/SignatureEnvelope.d.ts.map +1 -1
- package/dist/ox/SignatureEnvelope.js.map +1 -1
- package/dist/{viem → ox}/Tick.d.ts +4 -0
- package/dist/ox/Tick.d.ts.map +1 -0
- package/dist/ox/Tick.js.map +1 -0
- package/dist/ox/Transaction.d.ts.map +1 -1
- package/dist/ox/Transaction.js +2 -1
- package/dist/ox/Transaction.js.map +1 -1
- package/dist/ox/TransactionEnvelopeAA.d.ts +6 -6
- package/dist/ox/TransactionEnvelopeAA.d.ts.map +1 -1
- package/dist/ox/TransactionEnvelopeAA.js +4 -2
- package/dist/ox/TransactionEnvelopeAA.js.map +1 -1
- package/dist/ox/TransactionRequest.d.ts +4 -0
- package/dist/ox/TransactionRequest.d.ts.map +1 -1
- package/dist/ox/TransactionRequest.js.map +1 -1
- package/dist/ox/index.d.ts +6 -0
- package/dist/ox/index.d.ts.map +1 -1
- package/dist/ox/index.js +6 -0
- package/dist/ox/index.js.map +1 -1
- package/dist/prool/Instance.d.ts +5 -0
- package/dist/prool/Instance.d.ts.map +1 -1
- package/dist/prool/Instance.js +32 -8
- package/dist/prool/Instance.js.map +1 -1
- package/dist/viem/Abis.d.ts +1469 -1082
- package/dist/viem/Abis.d.ts.map +1 -1
- package/dist/viem/Abis.js +932 -671
- package/dist/viem/Abis.js.map +1 -1
- package/dist/viem/Account.d.ts +150 -0
- package/dist/viem/Account.d.ts.map +1 -0
- package/dist/viem/Account.js +221 -0
- package/dist/viem/Account.js.map +1 -0
- package/dist/viem/Actions/amm.d.ts +80 -118
- package/dist/viem/Actions/amm.d.ts.map +1 -1
- package/dist/viem/Actions/amm.js +47 -116
- package/dist/viem/Actions/amm.js.map +1 -1
- package/dist/viem/Actions/dex.d.ts +889 -633
- package/dist/viem/Actions/dex.d.ts.map +1 -1
- package/dist/viem/Actions/dex.js +99 -0
- package/dist/viem/Actions/dex.js.map +1 -1
- package/dist/viem/Actions/fee.d.ts +3 -17
- package/dist/viem/Actions/fee.d.ts.map +1 -1
- package/dist/viem/Actions/fee.js.map +1 -1
- package/dist/viem/Actions/index.d.ts +1 -0
- package/dist/viem/Actions/index.d.ts.map +1 -1
- package/dist/viem/Actions/index.js +1 -0
- package/dist/viem/Actions/index.js.map +1 -1
- package/dist/viem/Actions/reward.d.ts +3236 -0
- package/dist/viem/Actions/reward.d.ts.map +1 -0
- package/dist/viem/Actions/reward.js +725 -0
- package/dist/viem/Actions/reward.js.map +1 -0
- package/dist/viem/Actions/token.d.ts +4295 -2646
- package/dist/viem/Actions/token.d.ts.map +1 -1
- package/dist/viem/Actions/token.js +214 -335
- package/dist/viem/Actions/token.js.map +1 -1
- package/dist/viem/Addresses.d.ts +1 -2
- package/dist/viem/Addresses.d.ts.map +1 -1
- package/dist/viem/Addresses.js +1 -2
- package/dist/viem/Addresses.js.map +1 -1
- package/dist/viem/Chain.d.ts +38 -12
- package/dist/viem/Chain.d.ts.map +1 -1
- package/dist/viem/Chain.js +27 -18
- package/dist/viem/Chain.js.map +1 -1
- package/dist/viem/Decorator.d.ts +959 -405
- package/dist/viem/Decorator.d.ts.map +1 -1
- package/dist/viem/Decorator.js +13 -5
- package/dist/viem/Decorator.js.map +1 -1
- package/dist/viem/Formatters.d.ts +8 -1
- package/dist/viem/Formatters.d.ts.map +1 -1
- package/dist/viem/Formatters.js +17 -0
- package/dist/viem/Formatters.js.map +1 -1
- package/dist/viem/P256.d.ts +2 -0
- package/dist/viem/P256.d.ts.map +1 -0
- package/dist/viem/P256.js +2 -0
- package/dist/viem/P256.js.map +1 -0
- package/dist/viem/Secp256k1.d.ts +2 -0
- package/dist/viem/Secp256k1.d.ts.map +1 -0
- package/dist/viem/Secp256k1.js +2 -0
- package/dist/viem/Secp256k1.js.map +1 -0
- package/dist/viem/TokenIds.d.ts +1 -2
- package/dist/viem/TokenIds.d.ts.map +1 -1
- package/dist/viem/TokenIds.js +1 -2
- package/dist/viem/TokenIds.js.map +1 -1
- package/dist/viem/Transaction.d.ts +1 -1
- package/dist/viem/Transaction.d.ts.map +1 -1
- package/dist/viem/Transaction.js +46 -5
- package/dist/viem/Transaction.js.map +1 -1
- package/dist/viem/WebAuthnP256.d.ts +79 -0
- package/dist/viem/WebAuthnP256.d.ts.map +1 -0
- package/dist/viem/WebAuthnP256.js +95 -0
- package/dist/viem/WebAuthnP256.js.map +1 -0
- package/dist/viem/WebCryptoP256.d.ts +2 -0
- package/dist/viem/WebCryptoP256.d.ts.map +1 -0
- package/dist/viem/WebCryptoP256.js +2 -0
- package/dist/viem/WebCryptoP256.js.map +1 -0
- package/dist/viem/index.d.ts +6 -3
- package/dist/viem/index.d.ts.map +1 -1
- package/dist/viem/index.js +6 -3
- package/dist/viem/index.js.map +1 -1
- package/dist/viem/internal/account.d.ts +24 -0
- package/dist/viem/internal/account.d.ts.map +1 -0
- package/dist/viem/internal/account.js +68 -0
- package/dist/viem/internal/account.js.map +1 -0
- package/dist/viem/internal/types.d.ts +10 -0
- package/dist/viem/internal/types.d.ts.map +1 -1
- package/dist/wagmi/Actions/amm.d.ts +428 -0
- package/dist/wagmi/Actions/amm.d.ts.map +1 -0
- package/dist/wagmi/Actions/amm.js +472 -0
- package/dist/wagmi/Actions/amm.js.map +1 -0
- package/dist/wagmi/Actions/dex.d.ts +908 -0
- package/dist/wagmi/Actions/dex.d.ts.map +1 -0
- package/dist/wagmi/Actions/dex.js +1023 -0
- package/dist/wagmi/Actions/dex.js.map +1 -0
- package/dist/wagmi/Actions/fee.d.ts +111 -0
- package/dist/wagmi/Actions/fee.d.ts.map +1 -0
- package/dist/wagmi/Actions/fee.js +126 -0
- package/dist/wagmi/Actions/fee.js.map +1 -0
- package/dist/wagmi/Actions/index.d.ts +6 -0
- package/dist/wagmi/Actions/index.d.ts.map +1 -0
- package/dist/wagmi/Actions/index.js +6 -0
- package/dist/wagmi/Actions/index.js.map +1 -0
- package/dist/wagmi/Actions/reward.d.ts +348 -0
- package/dist/wagmi/Actions/reward.d.ts.map +1 -0
- package/dist/wagmi/Actions/reward.js +388 -0
- package/dist/wagmi/Actions/reward.js.map +1 -0
- package/dist/wagmi/Actions/token.d.ts +1546 -0
- package/dist/wagmi/Actions/token.d.ts.map +1 -0
- package/dist/wagmi/Actions/token.js +1712 -0
- package/dist/wagmi/Actions/token.js.map +1 -0
- package/dist/wagmi/Connector.d.ts +73 -0
- package/dist/wagmi/Connector.d.ts.map +1 -0
- package/dist/wagmi/Connector.js +249 -0
- package/dist/wagmi/Connector.js.map +1 -0
- package/dist/wagmi/Hooks/amm.d.ts +421 -0
- package/dist/wagmi/Hooks/amm.d.ts.map +1 -0
- package/dist/wagmi/Hooks/amm.js +504 -0
- package/dist/wagmi/Hooks/amm.js.map +1 -0
- package/dist/wagmi/Hooks/dex.d.ts +816 -0
- package/dist/wagmi/Hooks/dex.d.ts.map +1 -0
- package/dist/wagmi/Hooks/dex.js +973 -0
- package/dist/wagmi/Hooks/dex.js.map +1 -0
- package/dist/wagmi/Hooks/fee.d.ts +97 -0
- package/dist/wagmi/Hooks/fee.d.ts.map +1 -0
- package/dist/wagmi/Hooks/fee.js +109 -0
- package/dist/wagmi/Hooks/fee.js.map +1 -0
- package/dist/wagmi/Hooks/index.d.ts +6 -0
- package/dist/wagmi/Hooks/index.d.ts.map +1 -0
- package/dist/wagmi/Hooks/index.js +6 -0
- package/dist/wagmi/Hooks/index.js.map +1 -0
- package/dist/wagmi/Hooks/reward.d.ts +307 -0
- package/dist/wagmi/Hooks/reward.d.ts.map +1 -0
- package/dist/wagmi/Hooks/reward.js +349 -0
- package/dist/wagmi/Hooks/reward.js.map +1 -0
- package/dist/wagmi/Hooks/token.d.ts +1388 -0
- package/dist/wagmi/Hooks/token.d.ts.map +1 -0
- package/dist/wagmi/Hooks/token.js +1657 -0
- package/dist/wagmi/Hooks/token.js.map +1 -0
- package/dist/wagmi/index.d.ts +4 -0
- package/dist/wagmi/index.d.ts.map +1 -0
- package/dist/wagmi/index.js +4 -0
- package/dist/wagmi/index.js.map +1 -0
- package/package.json +54 -10
- package/src/chains.ts +19 -9
- package/src/ox/Order.test.ts +78 -0
- package/src/ox/Order.ts +125 -0
- package/src/ox/OrdersFilters.test.ts +182 -0
- package/src/ox/OrdersFilters.ts +125 -0
- package/src/ox/Pagination.test.ts +162 -0
- package/src/ox/Pagination.ts +164 -0
- package/src/ox/PoolId.test.ts +33 -0
- package/src/ox/PoolId.ts +27 -0
- package/src/ox/RpcSchema.ts +35 -0
- package/src/ox/SignatureEnvelope.ts +3 -1
- package/src/{viem → ox}/Tick.test.ts +1 -1
- package/src/{viem → ox}/Tick.ts +5 -0
- package/src/ox/Transaction.test.ts +1 -1
- package/src/ox/Transaction.ts +2 -1
- package/src/ox/TransactionEnvelopeAA.test.ts +239 -96
- package/src/ox/TransactionEnvelopeAA.ts +9 -7
- package/src/ox/TransactionRequest.ts +4 -0
- package/src/ox/index.ts +6 -0
- package/src/prool/Instance.ts +75 -38
- package/src/prool/internal/chain.json +104 -52
- package/src/tsconfig.json +9 -0
- package/src/viem/Abis.ts +972 -710
- package/src/viem/Account.ts +279 -0
- package/src/viem/Actions/__snapshots__/dex.test.ts.snap +850 -0
- package/src/viem/Actions/amm.test.ts +98 -169
- package/src/viem/Actions/amm.ts +68 -155
- package/src/viem/Actions/dex.test.ts +563 -484
- package/src/viem/Actions/dex.ts +173 -0
- package/src/viem/Actions/fee.test.ts +23 -34
- package/src/viem/Actions/fee.ts +7 -0
- package/src/viem/Actions/index.ts +1 -0
- package/src/viem/Actions/policy.test.ts +19 -33
- package/src/viem/Actions/reward.test.ts +457 -0
- package/src/viem/Actions/reward.ts +999 -0
- package/src/viem/Actions/token.test.ts +453 -287
- package/src/viem/Actions/token.ts +452 -540
- package/src/viem/Addresses.ts +1 -2
- package/src/viem/Chain.ts +70 -20
- package/src/viem/Decorator.test.ts +2 -1
- package/src/viem/Decorator.ts +996 -421
- package/src/viem/Formatters.ts +31 -5
- package/src/viem/P256.ts +1 -0
- package/src/viem/Secp256k1.ts +1 -0
- package/src/viem/TokenIds.ts +1 -2
- package/src/viem/Transaction.ts +53 -7
- package/src/viem/WebAuthnP256.ts +140 -0
- package/src/viem/WebCryptoP256.ts +1 -0
- package/src/viem/e2e.test.ts +1126 -297
- package/src/viem/index.ts +6 -3
- package/src/viem/internal/account.ts +107 -0
- package/src/viem/internal/types.ts +9 -0
- package/src/wagmi/Actions/__snapshots__/dex.test.ts.snap +310 -0
- package/src/wagmi/Actions/amm.test.ts +198 -0
- package/src/wagmi/Actions/amm.ts +691 -0
- package/src/wagmi/Actions/dex.test.ts +1507 -0
- package/src/wagmi/Actions/dex.ts +1640 -0
- package/src/wagmi/Actions/fee.test.ts +63 -0
- package/src/wagmi/Actions/fee.ts +208 -0
- package/src/wagmi/Actions/index.ts +5 -0
- package/src/wagmi/Actions/reward.test.ts +210 -0
- package/src/wagmi/Actions/reward.ts +632 -0
- package/src/wagmi/Actions/token.test.ts +1308 -0
- package/src/wagmi/Actions/token.ts +2613 -0
- package/src/wagmi/Connector.test.ts +53 -0
- package/src/wagmi/Connector.ts +367 -0
- package/src/wagmi/Hooks/__snapshots__/dex.test.ts.snap +457 -0
- package/src/wagmi/Hooks/amm.test.ts +424 -0
- package/src/wagmi/Hooks/amm.ts +806 -0
- package/src/wagmi/Hooks/dex.test.ts +1017 -0
- package/src/wagmi/Hooks/dex.ts +1685 -0
- package/src/wagmi/Hooks/fee.test.ts +166 -0
- package/src/wagmi/Hooks/fee.ts +206 -0
- package/src/wagmi/Hooks/index.ts +5 -0
- package/src/wagmi/Hooks/reward.test.ts +219 -0
- package/src/wagmi/Hooks/reward.ts +672 -0
- package/src/wagmi/Hooks/token.test.ts +1670 -0
- package/src/wagmi/Hooks/token.ts +2906 -0
- package/src/wagmi/index.ts +3 -0
- package/src/wagmi/internal/types.ts +16 -0
- package/dist/viem/Client.d.ts +0 -27
- package/dist/viem/Client.d.ts.map +0 -1
- package/dist/viem/Client.js +0 -28
- package/dist/viem/Client.js.map +0 -1
- package/dist/viem/Tick.d.ts.map +0 -1
- package/dist/viem/Tick.js.map +0 -1
- package/src/viem/Client.bench-d.ts +0 -8
- package/src/viem/Client.test.ts +0 -178
- package/src/viem/Client.ts +0 -91
- /package/dist/{viem → ox}/Tick.js +0 -0
|
@@ -0,0 +1,999 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Account,
|
|
3
|
+
type Address,
|
|
4
|
+
type BaseErrorType,
|
|
5
|
+
type Chain,
|
|
6
|
+
type Client,
|
|
7
|
+
type Log,
|
|
8
|
+
parseEventLogs,
|
|
9
|
+
type ReadContractReturnType,
|
|
10
|
+
type Transport,
|
|
11
|
+
type WriteContractReturnType,
|
|
12
|
+
} from 'viem'
|
|
13
|
+
import { readContract, writeContract, writeContractSync } from 'viem/actions'
|
|
14
|
+
import * as Abis from '../Abis.js'
|
|
15
|
+
import type { ReadParameters, WriteParameters } from '../internal/types.js'
|
|
16
|
+
import { defineCall } from '../internal/utils.js'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Cancels an active reward stream and refunds remaining tokens.
|
|
20
|
+
*
|
|
21
|
+
* - Callable only by the stream's funder.
|
|
22
|
+
* - Stops future emission for the stream at the current block timestamp.
|
|
23
|
+
* - Computes the refund as `amountTotal - distributedSoFar` and attempts to transfer it back to the funder.
|
|
24
|
+
* - If the refund transfer is forbidden by TIP-403, the stream is still canceled but `refund` will be 0 in the event.
|
|
25
|
+
* - Reverts with `StreamInactive` if the stream doesn't exist, is already canceled, or has already ended.
|
|
26
|
+
* - Reverts with `NotStreamFunder` if the caller is not the stream's funder.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { createClient, http } from 'viem'
|
|
31
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
32
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
33
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
34
|
+
*
|
|
35
|
+
* const client = createClient({
|
|
36
|
+
* account: privateKeyToAccount('0x...'),
|
|
37
|
+
* chain: tempo,
|
|
38
|
+
* transport: http(),
|
|
39
|
+
* })
|
|
40
|
+
*
|
|
41
|
+
* const hash = await actions.rewards.cancel(client, {
|
|
42
|
+
* id: 1n,
|
|
43
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
44
|
+
* })
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @param client - Client.
|
|
48
|
+
* @param parameters - Parameters.
|
|
49
|
+
* @returns The transaction hash.
|
|
50
|
+
*/
|
|
51
|
+
export async function cancel<
|
|
52
|
+
chain extends Chain | undefined,
|
|
53
|
+
account extends Account | undefined,
|
|
54
|
+
>(
|
|
55
|
+
client: Client<Transport, chain, account>,
|
|
56
|
+
parameters: cancel.Parameters<chain, account>,
|
|
57
|
+
): Promise<cancel.ReturnValue> {
|
|
58
|
+
return cancel.inner(writeContract, client, parameters)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Cancels an active reward stream and waits for confirmation.
|
|
63
|
+
*
|
|
64
|
+
* - Callable only by the stream's funder.
|
|
65
|
+
* - Stops future emission for the stream at the current block timestamp.
|
|
66
|
+
* - Computes the refund as `amountTotal - distributedSoFar` and attempts to transfer it back to the funder.
|
|
67
|
+
* - If the refund transfer is forbidden by TIP-403, the stream is still canceled but `refund` will be 0.
|
|
68
|
+
* - Reverts with `StreamInactive` if the stream doesn't exist, is already canceled, or has already ended.
|
|
69
|
+
* - Reverts with `NotStreamFunder` if the caller is not the stream's funder.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { createClient, http } from 'viem'
|
|
74
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
75
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
76
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
77
|
+
*
|
|
78
|
+
* const client = createClient({
|
|
79
|
+
* account: privateKeyToAccount('0x...'),
|
|
80
|
+
* chain: tempo,
|
|
81
|
+
* transport: http(),
|
|
82
|
+
* })
|
|
83
|
+
*
|
|
84
|
+
* const { funder, id, refund, receipt } = await actions.rewards.cancelSync(client, {
|
|
85
|
+
* id: 1n,
|
|
86
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
87
|
+
* })
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @param client - Client.
|
|
91
|
+
* @param parameters - Parameters.
|
|
92
|
+
* @returns The funder, stream ID, refund amount, and transaction receipt.
|
|
93
|
+
*/
|
|
94
|
+
export async function cancelSync<
|
|
95
|
+
chain extends Chain | undefined,
|
|
96
|
+
account extends Account | undefined,
|
|
97
|
+
>(
|
|
98
|
+
client: Client<Transport, chain, account>,
|
|
99
|
+
parameters: cancelSync.Parameters<chain, account>,
|
|
100
|
+
): Promise<cancelSync.ReturnValue> {
|
|
101
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
102
|
+
const receipt = await cancel.inner(writeContractSync, client, {
|
|
103
|
+
...rest,
|
|
104
|
+
throwOnReceiptRevert,
|
|
105
|
+
} as never)
|
|
106
|
+
const { args } = cancel.extractEvent(receipt.logs)
|
|
107
|
+
return {
|
|
108
|
+
...args,
|
|
109
|
+
receipt,
|
|
110
|
+
} as never
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export namespace cancel {
|
|
114
|
+
export type Args = {
|
|
115
|
+
/** The unique stream ID to cancel (must be owned by the caller) */
|
|
116
|
+
id: bigint
|
|
117
|
+
/** The TIP20 token address containing the reward stream */
|
|
118
|
+
token: Address
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export type Parameters<
|
|
122
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
123
|
+
account extends Account | undefined = Account | undefined,
|
|
124
|
+
> = WriteParameters<chain, account> & Args
|
|
125
|
+
|
|
126
|
+
export type ReturnValue = WriteContractReturnType
|
|
127
|
+
|
|
128
|
+
// TODO: exhaustive error type
|
|
129
|
+
export type ErrorType = BaseErrorType
|
|
130
|
+
|
|
131
|
+
/** @internal */
|
|
132
|
+
export async function inner<
|
|
133
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
134
|
+
chain extends Chain | undefined,
|
|
135
|
+
account extends Account | undefined,
|
|
136
|
+
>(
|
|
137
|
+
action: action,
|
|
138
|
+
client: Client<Transport, chain, account>,
|
|
139
|
+
parameters: Parameters<chain, account>,
|
|
140
|
+
): Promise<ReturnType<action>> {
|
|
141
|
+
const { id, token, ...rest } = parameters
|
|
142
|
+
const call = cancel.call({ id, token })
|
|
143
|
+
return (await action(client, {
|
|
144
|
+
...rest,
|
|
145
|
+
...call,
|
|
146
|
+
} as never)) as never
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Defines a call to the `cancel` function.
|
|
151
|
+
*
|
|
152
|
+
* Can be passed as a parameter to:
|
|
153
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
154
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
155
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
160
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
161
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
162
|
+
*
|
|
163
|
+
* const client = createClient({
|
|
164
|
+
* chain: tempo,
|
|
165
|
+
* transport: http(),
|
|
166
|
+
* }).extend(walletActions)
|
|
167
|
+
*
|
|
168
|
+
* const hash = await client.sendTransaction({
|
|
169
|
+
* calls: [actions.rewards.cancel.call({
|
|
170
|
+
* id: 1n,
|
|
171
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
172
|
+
* })],
|
|
173
|
+
* })
|
|
174
|
+
* ```
|
|
175
|
+
*
|
|
176
|
+
* @param args - Arguments.
|
|
177
|
+
* @returns The call.
|
|
178
|
+
*/
|
|
179
|
+
export function call(args: Args) {
|
|
180
|
+
const { id, token } = args
|
|
181
|
+
return defineCall({
|
|
182
|
+
address: token,
|
|
183
|
+
abi: Abis.tip20,
|
|
184
|
+
args: [id],
|
|
185
|
+
functionName: 'cancelReward',
|
|
186
|
+
})
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Extracts the `RewardCanceled` event from logs.
|
|
191
|
+
*
|
|
192
|
+
* @param logs - The logs.
|
|
193
|
+
* @returns The `RewardCanceled` event.
|
|
194
|
+
*/
|
|
195
|
+
export function extractEvent(logs: Log[]) {
|
|
196
|
+
const [log] = parseEventLogs({
|
|
197
|
+
abi: Abis.tip20,
|
|
198
|
+
logs,
|
|
199
|
+
eventName: 'RewardCanceled',
|
|
200
|
+
strict: true,
|
|
201
|
+
})
|
|
202
|
+
if (!log) throw new Error('`RewardCanceled` event not found.')
|
|
203
|
+
return log
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export declare namespace cancelSync {
|
|
208
|
+
export type Parameters<
|
|
209
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
210
|
+
account extends Account | undefined = Account | undefined,
|
|
211
|
+
> = WriteParameters<chain, account> & cancel.Args
|
|
212
|
+
|
|
213
|
+
export type ReturnValue = {
|
|
214
|
+
/** The address that funded the stream */
|
|
215
|
+
funder: Address
|
|
216
|
+
/** The stream ID that was canceled */
|
|
217
|
+
id: bigint
|
|
218
|
+
/** The transaction receipt */
|
|
219
|
+
receipt: Awaited<ReturnType<typeof writeContractSync>>
|
|
220
|
+
/** The amount refunded to the funder (0 if TIP-403 policy forbids the refund transfer) */
|
|
221
|
+
refund: bigint
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export type ErrorType = cancel.ErrorType
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Claims accumulated rewards for a recipient.
|
|
229
|
+
*
|
|
230
|
+
* This function allows a reward recipient to claim their accumulated rewards
|
|
231
|
+
* and receive them as token transfers to their own balance.
|
|
232
|
+
*
|
|
233
|
+
* - Accrues all pending rewards up to the current block timestamp.
|
|
234
|
+
* - Updates the caller's reward accounting.
|
|
235
|
+
* - Transfers the caller's accumulated `rewardBalance` from the token contract to the caller.
|
|
236
|
+
* - If the contract's balance is insufficient, claims up to the available amount.
|
|
237
|
+
* - Returns the actual amount claimed.
|
|
238
|
+
*
|
|
239
|
+
* Notes:
|
|
240
|
+
* - Reverts with `Paused` if the token is paused.
|
|
241
|
+
* - Reverts with `PolicyForbids` if the caller is not authorized to receive tokens under TIP-403.
|
|
242
|
+
* - If opted in, the claimed amount is added back to `optedInSupply` since it goes to the recipient's balance.
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```ts
|
|
246
|
+
* import { createClient, http } from 'viem'
|
|
247
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
248
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
249
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
250
|
+
*
|
|
251
|
+
* const client = createClient({
|
|
252
|
+
* account: privateKeyToAccount('0x...'),
|
|
253
|
+
* chain: tempo,
|
|
254
|
+
* transport: http(),
|
|
255
|
+
* })
|
|
256
|
+
*
|
|
257
|
+
* const hash = await actions.reward.claim(client, {
|
|
258
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
259
|
+
* })
|
|
260
|
+
* ```
|
|
261
|
+
*
|
|
262
|
+
* @param client - Client.
|
|
263
|
+
* @param parameters - Parameters.
|
|
264
|
+
* @returns The transaction hash.
|
|
265
|
+
*/
|
|
266
|
+
export async function claim<
|
|
267
|
+
chain extends Chain | undefined,
|
|
268
|
+
account extends Account | undefined,
|
|
269
|
+
>(
|
|
270
|
+
client: Client<Transport, chain, account>,
|
|
271
|
+
parameters: claim.Parameters<chain, account>,
|
|
272
|
+
): Promise<claim.ReturnValue> {
|
|
273
|
+
return claim.inner(writeContract, client, parameters)
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export namespace claim {
|
|
277
|
+
export type Args = {
|
|
278
|
+
/** The TIP20 token address */
|
|
279
|
+
token: Address
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export type Parameters<
|
|
283
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
284
|
+
account extends Account | undefined = Account | undefined,
|
|
285
|
+
> = WriteParameters<chain, account> & Args
|
|
286
|
+
|
|
287
|
+
export type ReturnValue = WriteContractReturnType
|
|
288
|
+
|
|
289
|
+
// TODO: exhaustive error type
|
|
290
|
+
export type ErrorType = BaseErrorType
|
|
291
|
+
|
|
292
|
+
/** @internal */
|
|
293
|
+
export async function inner<
|
|
294
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
295
|
+
chain extends Chain | undefined,
|
|
296
|
+
account extends Account | undefined,
|
|
297
|
+
>(
|
|
298
|
+
action: action,
|
|
299
|
+
client: Client<Transport, chain, account>,
|
|
300
|
+
parameters: Parameters<chain, account>,
|
|
301
|
+
): Promise<ReturnType<action>> {
|
|
302
|
+
const { token, ...rest } = parameters
|
|
303
|
+
const call = claim.call({ token })
|
|
304
|
+
return (await action(client, {
|
|
305
|
+
...rest,
|
|
306
|
+
...call,
|
|
307
|
+
} as never)) as never
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Defines a call to the `claimRewards` function.
|
|
312
|
+
*
|
|
313
|
+
* Can be passed as a parameter to:
|
|
314
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
315
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
316
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* ```ts
|
|
320
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
321
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
322
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
323
|
+
*
|
|
324
|
+
* const client = createClient({
|
|
325
|
+
* chain: tempo,
|
|
326
|
+
* transport: http(),
|
|
327
|
+
* }).extend(walletActions)
|
|
328
|
+
*
|
|
329
|
+
* const hash = await client.sendTransaction({
|
|
330
|
+
* calls: [actions.reward.claim.call({
|
|
331
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
332
|
+
* })],
|
|
333
|
+
* })
|
|
334
|
+
* ```
|
|
335
|
+
*
|
|
336
|
+
* @param args - Arguments.
|
|
337
|
+
* @returns The call.
|
|
338
|
+
*/
|
|
339
|
+
export function call(args: Args) {
|
|
340
|
+
const { token } = args
|
|
341
|
+
return defineCall({
|
|
342
|
+
address: token,
|
|
343
|
+
abi: Abis.tip20,
|
|
344
|
+
args: [],
|
|
345
|
+
functionName: 'claimRewards',
|
|
346
|
+
})
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Claims accumulated rewards for a recipient and waits for confirmation.
|
|
352
|
+
*
|
|
353
|
+
* This function allows a reward recipient to claim their accumulated rewards
|
|
354
|
+
* and receive them as token transfers to their own balance.
|
|
355
|
+
*
|
|
356
|
+
* Behavior:
|
|
357
|
+
* - Accrues all pending rewards up to the current block timestamp.
|
|
358
|
+
* - Updates the caller's reward accounting.
|
|
359
|
+
* - Transfers the caller's accumulated `rewardBalance` from the token contract to the caller.
|
|
360
|
+
* - If the contract's balance is insufficient, claims up to the available amount.
|
|
361
|
+
*
|
|
362
|
+
* Notes:
|
|
363
|
+
* - Reverts with `Paused` if the token is paused.
|
|
364
|
+
* - Reverts with `PolicyForbids` if the caller is not authorized to receive tokens under TIP-403.
|
|
365
|
+
* - If opted in, the claimed amount is added back to `optedInSupply` since it goes to the recipient's balance.
|
|
366
|
+
*
|
|
367
|
+
* @example
|
|
368
|
+
* ```ts
|
|
369
|
+
* import { createClient, http } from 'viem'
|
|
370
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
371
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
372
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
373
|
+
*
|
|
374
|
+
* const client = createClient({
|
|
375
|
+
* account: privateKeyToAccount('0x...'),
|
|
376
|
+
* chain: tempo,
|
|
377
|
+
* transport: http(),
|
|
378
|
+
* })
|
|
379
|
+
*
|
|
380
|
+
* const { receipt } = await actions.reward.claimSync(client, {
|
|
381
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
382
|
+
* })
|
|
383
|
+
* ```
|
|
384
|
+
*
|
|
385
|
+
* @param client - Client.
|
|
386
|
+
* @param parameters - Parameters.
|
|
387
|
+
* @returns The amount claimed and transaction receipt.
|
|
388
|
+
*/
|
|
389
|
+
export async function claimSync<
|
|
390
|
+
chain extends Chain | undefined,
|
|
391
|
+
account extends Account | undefined,
|
|
392
|
+
>(
|
|
393
|
+
client: Client<Transport, chain, account>,
|
|
394
|
+
parameters: claimSync.Parameters<chain, account>,
|
|
395
|
+
): Promise<claimSync.ReturnValue> {
|
|
396
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
397
|
+
const receipt = await claim.inner(writeContractSync, client, {
|
|
398
|
+
...rest,
|
|
399
|
+
throwOnReceiptRevert,
|
|
400
|
+
} as never)
|
|
401
|
+
return {
|
|
402
|
+
receipt,
|
|
403
|
+
} as never
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export namespace claimSync {
|
|
407
|
+
export type Parameters<
|
|
408
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
409
|
+
account extends Account | undefined = Account | undefined,
|
|
410
|
+
> = WriteParameters<chain, account> & claim.Args
|
|
411
|
+
|
|
412
|
+
export type ReturnValue = {
|
|
413
|
+
/** The transaction receipt */
|
|
414
|
+
receipt: Awaited<ReturnType<typeof writeContractSync>>
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
export type ErrorType = claim.ErrorType
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Gets a reward stream by its ID.
|
|
422
|
+
*
|
|
423
|
+
* Returns the stream details including:
|
|
424
|
+
* - `funder`: The address that funded the stream
|
|
425
|
+
* - `startTime`: When the stream started (block timestamp)
|
|
426
|
+
* - `endTime`: When the stream is scheduled to end
|
|
427
|
+
* - `ratePerSecondScaled`: The per-second emission rate (scaled by ACC_PRECISION = 1e18)
|
|
428
|
+
* - `amountTotal`: The total amount allocated to the stream
|
|
429
|
+
*
|
|
430
|
+
* Note: If the stream has been canceled or doesn't exist, `funder` will be the zero address.
|
|
431
|
+
*
|
|
432
|
+
* @example
|
|
433
|
+
* ```ts
|
|
434
|
+
* import { createClient, http } from 'viem'
|
|
435
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
436
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
437
|
+
*
|
|
438
|
+
* const client = createClient({
|
|
439
|
+
* chain: tempo,
|
|
440
|
+
* transport: http(),
|
|
441
|
+
* })
|
|
442
|
+
*
|
|
443
|
+
* const stream = await actions.rewards.getStream(client, {
|
|
444
|
+
* id: 1n,
|
|
445
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
446
|
+
* })
|
|
447
|
+
* ```
|
|
448
|
+
*
|
|
449
|
+
* @param client - Client.
|
|
450
|
+
* @param parameters - Parameters.
|
|
451
|
+
* @returns The reward stream details.
|
|
452
|
+
*/
|
|
453
|
+
export async function getStream<chain extends Chain | undefined>(
|
|
454
|
+
client: Client<Transport, chain>,
|
|
455
|
+
parameters: getStream.Parameters,
|
|
456
|
+
): Promise<getStream.ReturnValue> {
|
|
457
|
+
return readContract(client, {
|
|
458
|
+
...parameters,
|
|
459
|
+
...getStream.call(parameters),
|
|
460
|
+
})
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
export namespace getStream {
|
|
464
|
+
export type Parameters = ReadParameters & Args
|
|
465
|
+
|
|
466
|
+
export type Args = {
|
|
467
|
+
/** The stream ID to query (0 is never used for streams, only for immediate distributions) */
|
|
468
|
+
id: bigint
|
|
469
|
+
/** The TIP20 token address */
|
|
470
|
+
token: Address
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
export type ReturnValue = ReadContractReturnType<
|
|
474
|
+
typeof Abis.tip20,
|
|
475
|
+
'getStream',
|
|
476
|
+
never
|
|
477
|
+
>
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Defines a call to the `getStream` function.
|
|
481
|
+
*
|
|
482
|
+
* @param args - Arguments.
|
|
483
|
+
* @returns The call.
|
|
484
|
+
*/
|
|
485
|
+
export function call(args: Args) {
|
|
486
|
+
const { id, token } = args
|
|
487
|
+
return defineCall({
|
|
488
|
+
address: token,
|
|
489
|
+
abi: Abis.tip20,
|
|
490
|
+
args: [id],
|
|
491
|
+
functionName: 'getStream',
|
|
492
|
+
})
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Gets the total reward per second rate for all active streams.
|
|
498
|
+
*
|
|
499
|
+
* Returns the current aggregate per-second emission rate scaled by `ACC_PRECISION` (1e18).
|
|
500
|
+
* This value represents the sum of all active reward streams' emission rates.
|
|
501
|
+
* The rate decreases when streams end (via `finalizeStreams`) or are canceled.
|
|
502
|
+
*
|
|
503
|
+
* @example
|
|
504
|
+
* ```ts
|
|
505
|
+
* import { createClient, http } from 'viem'
|
|
506
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
507
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
508
|
+
*
|
|
509
|
+
* const client = createClient({
|
|
510
|
+
* chain: tempo,
|
|
511
|
+
* transport: http(),
|
|
512
|
+
* })
|
|
513
|
+
*
|
|
514
|
+
* const rate = await actions.rewards.getTotalPerSecond(client, {
|
|
515
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
516
|
+
* })
|
|
517
|
+
* ```
|
|
518
|
+
*
|
|
519
|
+
* @param client - Client.
|
|
520
|
+
* @param parameters - Parameters.
|
|
521
|
+
* @returns The total reward per second (scaled by 1e18).
|
|
522
|
+
*/
|
|
523
|
+
export async function getTotalPerSecond<chain extends Chain | undefined>(
|
|
524
|
+
client: Client<Transport, chain>,
|
|
525
|
+
parameters: getTotalPerSecond.Parameters,
|
|
526
|
+
): Promise<getTotalPerSecond.ReturnValue> {
|
|
527
|
+
return readContract(client, {
|
|
528
|
+
...parameters,
|
|
529
|
+
...getTotalPerSecond.call(parameters),
|
|
530
|
+
})
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
export namespace getTotalPerSecond {
|
|
534
|
+
export type Parameters = ReadParameters & Args
|
|
535
|
+
|
|
536
|
+
export type Args = {
|
|
537
|
+
/** The TIP20 token address */
|
|
538
|
+
token: Address
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
export type ReturnValue = ReadContractReturnType<
|
|
542
|
+
typeof Abis.tip20,
|
|
543
|
+
'totalRewardPerSecond',
|
|
544
|
+
never
|
|
545
|
+
>
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Defines a call to the `totalRewardPerSecond` function.
|
|
549
|
+
*
|
|
550
|
+
* @param args - Arguments.
|
|
551
|
+
* @returns The call.
|
|
552
|
+
*/
|
|
553
|
+
export function call(args: Args) {
|
|
554
|
+
const { token } = args
|
|
555
|
+
return defineCall({
|
|
556
|
+
address: token,
|
|
557
|
+
abi: Abis.tip20,
|
|
558
|
+
args: [],
|
|
559
|
+
functionName: 'totalRewardPerSecond',
|
|
560
|
+
})
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Sets or changes the reward recipient for a token holder.
|
|
566
|
+
*
|
|
567
|
+
* This function allows a token holder to designate who should receive their share of rewards:
|
|
568
|
+
* - If `recipient` is the zero address, opts out from rewards distribution.
|
|
569
|
+
* - Otherwise, opts in and sets `recipient` as the address that will receive accrued rewards.
|
|
570
|
+
* - Can be called with `recipient == msg.sender` to receive rewards directly.
|
|
571
|
+
* - Automatically distributes any accrued rewards to the current recipient before changing.
|
|
572
|
+
*
|
|
573
|
+
* TIP-403 Policy:
|
|
574
|
+
* - Reverts with `PolicyForbids` if `recipient` is not the zero address and either the holder or recipient is not authorized to receive tokens under the token's transfer policy.
|
|
575
|
+
*
|
|
576
|
+
* @example
|
|
577
|
+
* ```ts
|
|
578
|
+
* import { createClient, http } from 'viem'
|
|
579
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
580
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
581
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
582
|
+
*
|
|
583
|
+
* const client = createClient({
|
|
584
|
+
* account: privateKeyToAccount('0x...'),
|
|
585
|
+
* chain: tempo,
|
|
586
|
+
* transport: http(),
|
|
587
|
+
* })
|
|
588
|
+
*
|
|
589
|
+
* const hash = await actions.rewards.setRecipient(client, {
|
|
590
|
+
* recipient: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
|
|
591
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
592
|
+
* })
|
|
593
|
+
* ```
|
|
594
|
+
*
|
|
595
|
+
* @param client - Client.
|
|
596
|
+
* @param parameters - Parameters.
|
|
597
|
+
* @returns The transaction hash.
|
|
598
|
+
*/
|
|
599
|
+
export async function setRecipient<
|
|
600
|
+
chain extends Chain | undefined,
|
|
601
|
+
account extends Account | undefined,
|
|
602
|
+
>(
|
|
603
|
+
client: Client<Transport, chain, account>,
|
|
604
|
+
parameters: setRecipient.Parameters<chain, account>,
|
|
605
|
+
): Promise<setRecipient.ReturnValue> {
|
|
606
|
+
return setRecipient.inner(writeContract, client, parameters)
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Sets or changes the reward recipient for a token holder and waits for confirmation.
|
|
611
|
+
*
|
|
612
|
+
* This function allows a token holder to designate who should receive their share of rewards:
|
|
613
|
+
* - If `recipient` is the zero address, opts out from rewards distribution.
|
|
614
|
+
* - Otherwise, opts in and sets `recipient` as the address that will receive accrued rewards.
|
|
615
|
+
* - Can be called with `recipient == msg.sender` to receive rewards directly.
|
|
616
|
+
* - Automatically distributes any accrued rewards to the current recipient before changing.
|
|
617
|
+
*
|
|
618
|
+
* TIP-403 Policy:
|
|
619
|
+
* - Reverts with `PolicyForbids` if `recipient` is not the zero address and either the holder or recipient is not authorized to receive tokens under the token's transfer policy.
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
* ```ts
|
|
623
|
+
* import { createClient, http } from 'viem'
|
|
624
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
625
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
626
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
627
|
+
*
|
|
628
|
+
* const client = createClient({
|
|
629
|
+
* account: privateKeyToAccount('0x...'),
|
|
630
|
+
* chain: tempo,
|
|
631
|
+
* transport: http(),
|
|
632
|
+
* })
|
|
633
|
+
*
|
|
634
|
+
* const { holder, recipient, receipt } = await actions.rewards.setRecipientSync(client, {
|
|
635
|
+
* recipient: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
|
|
636
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
637
|
+
* })
|
|
638
|
+
* ```
|
|
639
|
+
*
|
|
640
|
+
* @param client - Client.
|
|
641
|
+
* @param parameters - Parameters.
|
|
642
|
+
* @returns The holder, recipient, and transaction receipt.
|
|
643
|
+
*/
|
|
644
|
+
export async function setRecipientSync<
|
|
645
|
+
chain extends Chain | undefined,
|
|
646
|
+
account extends Account | undefined,
|
|
647
|
+
>(
|
|
648
|
+
client: Client<Transport, chain, account>,
|
|
649
|
+
parameters: setRecipientSync.Parameters<chain, account>,
|
|
650
|
+
): Promise<setRecipientSync.ReturnValue> {
|
|
651
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
652
|
+
const receipt = await setRecipient.inner(writeContractSync, client, {
|
|
653
|
+
...rest,
|
|
654
|
+
throwOnReceiptRevert,
|
|
655
|
+
} as never)
|
|
656
|
+
const { args } = setRecipient.extractEvent(receipt.logs)
|
|
657
|
+
return {
|
|
658
|
+
...args,
|
|
659
|
+
receipt,
|
|
660
|
+
} as never
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
export namespace setRecipient {
|
|
664
|
+
export type Args = {
|
|
665
|
+
/** The reward recipient address (use zero address to opt out of rewards) */
|
|
666
|
+
recipient: Address
|
|
667
|
+
/** The TIP20 token address */
|
|
668
|
+
token: Address
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
export type Parameters<
|
|
672
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
673
|
+
account extends Account | undefined = Account | undefined,
|
|
674
|
+
> = WriteParameters<chain, account> & Args
|
|
675
|
+
|
|
676
|
+
export type ReturnValue = WriteContractReturnType
|
|
677
|
+
|
|
678
|
+
// TODO: exhaustive error type
|
|
679
|
+
export type ErrorType = BaseErrorType
|
|
680
|
+
|
|
681
|
+
/** @internal */
|
|
682
|
+
export async function inner<
|
|
683
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
684
|
+
chain extends Chain | undefined,
|
|
685
|
+
account extends Account | undefined,
|
|
686
|
+
>(
|
|
687
|
+
action: action,
|
|
688
|
+
client: Client<Transport, chain, account>,
|
|
689
|
+
parameters: Parameters<chain, account>,
|
|
690
|
+
): Promise<ReturnType<action>> {
|
|
691
|
+
const { recipient, token, ...rest } = parameters
|
|
692
|
+
const call = setRecipient.call({ recipient, token })
|
|
693
|
+
return (await action(client, {
|
|
694
|
+
...rest,
|
|
695
|
+
...call,
|
|
696
|
+
} as never)) as never
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* Defines a call to the `setRecipient` function.
|
|
701
|
+
*
|
|
702
|
+
* Can be passed as a parameter to:
|
|
703
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
704
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
705
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
706
|
+
*
|
|
707
|
+
* @example
|
|
708
|
+
* ```ts
|
|
709
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
710
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
711
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
712
|
+
*
|
|
713
|
+
* const client = createClient({
|
|
714
|
+
* chain: tempo,
|
|
715
|
+
* transport: http(),
|
|
716
|
+
* }).extend(walletActions)
|
|
717
|
+
*
|
|
718
|
+
* const hash = await client.sendTransaction({
|
|
719
|
+
* calls: [actions.rewards.setRecipient.call({
|
|
720
|
+
* recipient: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
|
|
721
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
722
|
+
* })],
|
|
723
|
+
* })
|
|
724
|
+
* ```
|
|
725
|
+
*
|
|
726
|
+
* @param args - Arguments.
|
|
727
|
+
* @returns The call.
|
|
728
|
+
*/
|
|
729
|
+
export function call(args: Args) {
|
|
730
|
+
const { recipient, token } = args
|
|
731
|
+
return defineCall({
|
|
732
|
+
address: token,
|
|
733
|
+
abi: Abis.tip20,
|
|
734
|
+
args: [recipient],
|
|
735
|
+
functionName: 'setRewardRecipient',
|
|
736
|
+
})
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* Extracts the `RewardRecipientSet` event from logs.
|
|
741
|
+
*
|
|
742
|
+
* @param logs - The logs.
|
|
743
|
+
* @returns The `RewardRecipientSet` event.
|
|
744
|
+
*/
|
|
745
|
+
export function extractEvent(logs: Log[]) {
|
|
746
|
+
const [log] = parseEventLogs({
|
|
747
|
+
abi: Abis.tip20,
|
|
748
|
+
logs,
|
|
749
|
+
eventName: 'RewardRecipientSet',
|
|
750
|
+
strict: true,
|
|
751
|
+
})
|
|
752
|
+
if (!log) throw new Error('`RewardRecipientSet` event not found.')
|
|
753
|
+
return log
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
export declare namespace setRecipientSync {
|
|
758
|
+
export type Parameters<
|
|
759
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
760
|
+
account extends Account | undefined = Account | undefined,
|
|
761
|
+
> = WriteParameters<chain, account> & setRecipient.Args
|
|
762
|
+
|
|
763
|
+
export type ReturnValue = {
|
|
764
|
+
/** The token holder address who set their reward recipient */
|
|
765
|
+
holder: Address
|
|
766
|
+
/** The transaction receipt */
|
|
767
|
+
receipt: Awaited<ReturnType<typeof writeContractSync>>
|
|
768
|
+
/** The reward recipient address (zero address indicates opt-out) */
|
|
769
|
+
recipient: Address
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
export type ErrorType = setRecipient.ErrorType
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
* Starts a new reward stream that distributes tokens to opted-in holders.
|
|
777
|
+
*
|
|
778
|
+
* Behavior:
|
|
779
|
+
* - Transfers `amount` of tokens from the caller into the token contract's reward pool.
|
|
780
|
+
* - If `seconds == 0`: Immediately distributes `amount` to current opted-in holders by increasing `rewardPerTokenStored`.
|
|
781
|
+
* Returns stream ID `0`. Distribution occurs when holders interact with the token (transfers, etc.).
|
|
782
|
+
* - If `seconds > 0`: Starts a linear stream that emits evenly from `block.timestamp` to `block.timestamp + seconds`.
|
|
783
|
+
* Returns a unique stream ID for later cancellation.
|
|
784
|
+
*
|
|
785
|
+
* Notes:
|
|
786
|
+
* - Reverts with `InvalidAmount` if `amount == 0`.
|
|
787
|
+
* - Allowed even when `optedInSupply == 0` (tokens distributed while no one is opted in are locked permanently).
|
|
788
|
+
* - The transfer from caller to pool is subject to TIP-403 policy checks.
|
|
789
|
+
*
|
|
790
|
+
* @example
|
|
791
|
+
* ```ts
|
|
792
|
+
* import { createClient, http } from 'viem'
|
|
793
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
794
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
795
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
796
|
+
*
|
|
797
|
+
* const client = createClient({
|
|
798
|
+
* account: privateKeyToAccount('0x...'),
|
|
799
|
+
* chain: tempo,
|
|
800
|
+
* transport: http(),
|
|
801
|
+
* })
|
|
802
|
+
*
|
|
803
|
+
* const hash = await actions.rewards.start(client, {
|
|
804
|
+
* amount: 100000000000000000000n,
|
|
805
|
+
* seconds: 86400,
|
|
806
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
807
|
+
* })
|
|
808
|
+
* ```
|
|
809
|
+
*
|
|
810
|
+
* @param client - Client.
|
|
811
|
+
* @param parameters - Parameters.
|
|
812
|
+
* @returns The transaction hash.
|
|
813
|
+
*/
|
|
814
|
+
export async function start<
|
|
815
|
+
chain extends Chain | undefined,
|
|
816
|
+
account extends Account | undefined,
|
|
817
|
+
>(
|
|
818
|
+
client: Client<Transport, chain, account>,
|
|
819
|
+
parameters: start.Parameters<chain, account>,
|
|
820
|
+
): Promise<start.ReturnValue> {
|
|
821
|
+
return start.inner(writeContract, client, parameters)
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
/**
|
|
825
|
+
* Starts a new reward stream that distributes tokens to opted-in holders and waits for confirmation.
|
|
826
|
+
*
|
|
827
|
+
* Behavior:
|
|
828
|
+
* - Transfers `amount` of tokens from the caller into the token contract's reward pool.
|
|
829
|
+
* - If `seconds == 0`: Immediately distributes `amount` to current opted-in holders by increasing `rewardPerTokenStored`.
|
|
830
|
+
* Returns stream ID `0`. Distribution occurs when holders interact with the token (transfers, etc.).
|
|
831
|
+
* - If `seconds > 0`: Starts a linear stream that emits evenly from `block.timestamp` to `block.timestamp + seconds`.
|
|
832
|
+
* Returns a unique stream ID for later cancellation.
|
|
833
|
+
*
|
|
834
|
+
* Notes:
|
|
835
|
+
* - Reverts with `InvalidAmount` if `amount == 0`.
|
|
836
|
+
* - Allowed even when `optedInSupply == 0` (tokens distributed while no one is opted in are locked permanently).
|
|
837
|
+
* - The transfer from caller to pool is subject to TIP-403 policy checks.
|
|
838
|
+
*
|
|
839
|
+
* @example
|
|
840
|
+
* ```ts
|
|
841
|
+
* import { createClient, http } from 'viem'
|
|
842
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
843
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
844
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
845
|
+
*
|
|
846
|
+
* const client = createClient({
|
|
847
|
+
* account: privateKeyToAccount('0x...'),
|
|
848
|
+
* chain: tempo,
|
|
849
|
+
* transport: http(),
|
|
850
|
+
* })
|
|
851
|
+
*
|
|
852
|
+
* const { id, receipt } = await actions.rewards.startSync(client, {
|
|
853
|
+
* amount: 100000000000000000000n,
|
|
854
|
+
* seconds: 86400,
|
|
855
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
856
|
+
* })
|
|
857
|
+
* ```
|
|
858
|
+
*
|
|
859
|
+
* @param client - Client.
|
|
860
|
+
* @param parameters - Parameters.
|
|
861
|
+
* @returns The stream ID, funder, amount, duration, and transaction receipt.
|
|
862
|
+
*/
|
|
863
|
+
export async function startSync<
|
|
864
|
+
chain extends Chain | undefined,
|
|
865
|
+
account extends Account | undefined,
|
|
866
|
+
>(
|
|
867
|
+
client: Client<Transport, chain, account>,
|
|
868
|
+
parameters: startSync.Parameters<chain, account>,
|
|
869
|
+
): Promise<startSync.ReturnValue> {
|
|
870
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
871
|
+
const receipt = await start.inner(writeContractSync, client, {
|
|
872
|
+
...rest,
|
|
873
|
+
throwOnReceiptRevert,
|
|
874
|
+
} as never)
|
|
875
|
+
const { args } = start.extractEvent(receipt.logs)
|
|
876
|
+
return {
|
|
877
|
+
...args,
|
|
878
|
+
receipt,
|
|
879
|
+
} as never
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
export namespace start {
|
|
883
|
+
export type Args = {
|
|
884
|
+
/** The amount of tokens to distribute (must be > 0) */
|
|
885
|
+
amount: bigint
|
|
886
|
+
/** The duration in seconds (0 for immediate distribution, >0 for linear streaming) */
|
|
887
|
+
seconds: number
|
|
888
|
+
/** The TIP20 token address */
|
|
889
|
+
token: Address
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
export type Parameters<
|
|
893
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
894
|
+
account extends Account | undefined = Account | undefined,
|
|
895
|
+
> = WriteParameters<chain, account> & Args
|
|
896
|
+
|
|
897
|
+
export type ReturnValue = WriteContractReturnType
|
|
898
|
+
|
|
899
|
+
// TODO: exhaustive error type
|
|
900
|
+
export type ErrorType = BaseErrorType
|
|
901
|
+
|
|
902
|
+
/** @internal */
|
|
903
|
+
export async function inner<
|
|
904
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
905
|
+
chain extends Chain | undefined,
|
|
906
|
+
account extends Account | undefined,
|
|
907
|
+
>(
|
|
908
|
+
action: action,
|
|
909
|
+
client: Client<Transport, chain, account>,
|
|
910
|
+
parameters: Parameters<chain, account>,
|
|
911
|
+
): Promise<ReturnType<action>> {
|
|
912
|
+
const { amount, seconds, token, ...rest } = parameters
|
|
913
|
+
const call = start.call({ amount, seconds, token })
|
|
914
|
+
return (await action(client, {
|
|
915
|
+
...rest,
|
|
916
|
+
...call,
|
|
917
|
+
} as never)) as never
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
/**
|
|
921
|
+
* Defines a call to the `start` function.
|
|
922
|
+
*
|
|
923
|
+
* Can be passed as a parameter to:
|
|
924
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
925
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
926
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
927
|
+
*
|
|
928
|
+
* @example
|
|
929
|
+
* ```ts
|
|
930
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
931
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
932
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
933
|
+
*
|
|
934
|
+
* const client = createClient({
|
|
935
|
+
* chain: tempo,
|
|
936
|
+
* transport: http(),
|
|
937
|
+
* }).extend(walletActions)
|
|
938
|
+
*
|
|
939
|
+
* const hash = await client.sendTransaction({
|
|
940
|
+
* calls: [actions.rewards.start.call({
|
|
941
|
+
* amount: 100000000000000000000n,
|
|
942
|
+
* seconds: 86400,
|
|
943
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
944
|
+
* })],
|
|
945
|
+
* })
|
|
946
|
+
* ```
|
|
947
|
+
*
|
|
948
|
+
* @param args - Arguments.
|
|
949
|
+
* @returns The call.
|
|
950
|
+
*/
|
|
951
|
+
export function call(args: Args) {
|
|
952
|
+
const { amount, seconds, token } = args
|
|
953
|
+
return defineCall({
|
|
954
|
+
address: token,
|
|
955
|
+
abi: Abis.tip20,
|
|
956
|
+
args: [amount, seconds],
|
|
957
|
+
functionName: 'startReward',
|
|
958
|
+
})
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
/**
|
|
962
|
+
* Extracts the `RewardScheduled` event from logs.
|
|
963
|
+
*
|
|
964
|
+
* @param logs - The logs.
|
|
965
|
+
* @returns The `RewardScheduled` event.
|
|
966
|
+
*/
|
|
967
|
+
export function extractEvent(logs: Log[]) {
|
|
968
|
+
const [log] = parseEventLogs({
|
|
969
|
+
abi: Abis.tip20,
|
|
970
|
+
logs,
|
|
971
|
+
eventName: 'RewardScheduled',
|
|
972
|
+
strict: true,
|
|
973
|
+
})
|
|
974
|
+
if (!log) throw new Error('`RewardScheduled` event not found.')
|
|
975
|
+
return log
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
export declare namespace startSync {
|
|
980
|
+
export type Parameters<
|
|
981
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
982
|
+
account extends Account | undefined = Account | undefined,
|
|
983
|
+
> = WriteParameters<chain, account> & start.Args
|
|
984
|
+
|
|
985
|
+
export type ReturnValue = {
|
|
986
|
+
/** The total amount allocated to the stream */
|
|
987
|
+
amount: bigint
|
|
988
|
+
/** The duration of the stream in seconds (0 for immediate distributions) */
|
|
989
|
+
durationSeconds: number
|
|
990
|
+
/** The address that funded the stream */
|
|
991
|
+
funder: Address
|
|
992
|
+
/** The unique stream ID (0 for immediate distributions, >0 for streaming distributions) */
|
|
993
|
+
id: bigint
|
|
994
|
+
/** The transaction receipt */
|
|
995
|
+
receipt: Awaited<ReturnType<typeof writeContractSync>>
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
export type ErrorType = start.ErrorType
|
|
999
|
+
}
|