tempo.ts 0.1.5 → 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.map +1 -1
- package/dist/prool/Instance.js +20 -4
- 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 +51 -37
- 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,725 @@
|
|
|
1
|
+
import { parseEventLogs, } from 'viem';
|
|
2
|
+
import { readContract, writeContract, writeContractSync } from 'viem/actions';
|
|
3
|
+
import * as Abis from '../Abis.js';
|
|
4
|
+
import { defineCall } from '../internal/utils.js';
|
|
5
|
+
/**
|
|
6
|
+
* Cancels an active reward stream and refunds remaining tokens.
|
|
7
|
+
*
|
|
8
|
+
* - Callable only by the stream's funder.
|
|
9
|
+
* - Stops future emission for the stream at the current block timestamp.
|
|
10
|
+
* - Computes the refund as `amountTotal - distributedSoFar` and attempts to transfer it back to the funder.
|
|
11
|
+
* - If the refund transfer is forbidden by TIP-403, the stream is still canceled but `refund` will be 0 in the event.
|
|
12
|
+
* - Reverts with `StreamInactive` if the stream doesn't exist, is already canceled, or has already ended.
|
|
13
|
+
* - Reverts with `NotStreamFunder` if the caller is not the stream's funder.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { createClient, http } from 'viem'
|
|
18
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
19
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
20
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
21
|
+
*
|
|
22
|
+
* const client = createClient({
|
|
23
|
+
* account: privateKeyToAccount('0x...'),
|
|
24
|
+
* chain: tempo,
|
|
25
|
+
* transport: http(),
|
|
26
|
+
* })
|
|
27
|
+
*
|
|
28
|
+
* const hash = await actions.rewards.cancel(client, {
|
|
29
|
+
* id: 1n,
|
|
30
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
31
|
+
* })
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @param client - Client.
|
|
35
|
+
* @param parameters - Parameters.
|
|
36
|
+
* @returns The transaction hash.
|
|
37
|
+
*/
|
|
38
|
+
export async function cancel(client, parameters) {
|
|
39
|
+
return cancel.inner(writeContract, client, parameters);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Cancels an active reward stream and waits for confirmation.
|
|
43
|
+
*
|
|
44
|
+
* - Callable only by the stream's funder.
|
|
45
|
+
* - Stops future emission for the stream at the current block timestamp.
|
|
46
|
+
* - Computes the refund as `amountTotal - distributedSoFar` and attempts to transfer it back to the funder.
|
|
47
|
+
* - If the refund transfer is forbidden by TIP-403, the stream is still canceled but `refund` will be 0.
|
|
48
|
+
* - Reverts with `StreamInactive` if the stream doesn't exist, is already canceled, or has already ended.
|
|
49
|
+
* - Reverts with `NotStreamFunder` if the caller is not the stream's funder.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* import { createClient, http } from 'viem'
|
|
54
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
55
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
56
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
57
|
+
*
|
|
58
|
+
* const client = createClient({
|
|
59
|
+
* account: privateKeyToAccount('0x...'),
|
|
60
|
+
* chain: tempo,
|
|
61
|
+
* transport: http(),
|
|
62
|
+
* })
|
|
63
|
+
*
|
|
64
|
+
* const { funder, id, refund, receipt } = await actions.rewards.cancelSync(client, {
|
|
65
|
+
* id: 1n,
|
|
66
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
67
|
+
* })
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @param client - Client.
|
|
71
|
+
* @param parameters - Parameters.
|
|
72
|
+
* @returns The funder, stream ID, refund amount, and transaction receipt.
|
|
73
|
+
*/
|
|
74
|
+
export async function cancelSync(client, parameters) {
|
|
75
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters;
|
|
76
|
+
const receipt = await cancel.inner(writeContractSync, client, {
|
|
77
|
+
...rest,
|
|
78
|
+
throwOnReceiptRevert,
|
|
79
|
+
});
|
|
80
|
+
const { args } = cancel.extractEvent(receipt.logs);
|
|
81
|
+
return {
|
|
82
|
+
...args,
|
|
83
|
+
receipt,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
(function (cancel) {
|
|
87
|
+
/** @internal */
|
|
88
|
+
async function inner(action, client, parameters) {
|
|
89
|
+
const { id, token, ...rest } = parameters;
|
|
90
|
+
const call = cancel.call({ id, token });
|
|
91
|
+
return (await action(client, {
|
|
92
|
+
...rest,
|
|
93
|
+
...call,
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
cancel.inner = inner;
|
|
97
|
+
/**
|
|
98
|
+
* Defines a call to the `cancel` function.
|
|
99
|
+
*
|
|
100
|
+
* Can be passed as a parameter to:
|
|
101
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
102
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
103
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
108
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
109
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
110
|
+
*
|
|
111
|
+
* const client = createClient({
|
|
112
|
+
* chain: tempo,
|
|
113
|
+
* transport: http(),
|
|
114
|
+
* }).extend(walletActions)
|
|
115
|
+
*
|
|
116
|
+
* const hash = await client.sendTransaction({
|
|
117
|
+
* calls: [actions.rewards.cancel.call({
|
|
118
|
+
* id: 1n,
|
|
119
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
120
|
+
* })],
|
|
121
|
+
* })
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @param args - Arguments.
|
|
125
|
+
* @returns The call.
|
|
126
|
+
*/
|
|
127
|
+
function call(args) {
|
|
128
|
+
const { id, token } = args;
|
|
129
|
+
return defineCall({
|
|
130
|
+
address: token,
|
|
131
|
+
abi: Abis.tip20,
|
|
132
|
+
args: [id],
|
|
133
|
+
functionName: 'cancelReward',
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
cancel.call = call;
|
|
137
|
+
/**
|
|
138
|
+
* Extracts the `RewardCanceled` event from logs.
|
|
139
|
+
*
|
|
140
|
+
* @param logs - The logs.
|
|
141
|
+
* @returns The `RewardCanceled` event.
|
|
142
|
+
*/
|
|
143
|
+
function extractEvent(logs) {
|
|
144
|
+
const [log] = parseEventLogs({
|
|
145
|
+
abi: Abis.tip20,
|
|
146
|
+
logs,
|
|
147
|
+
eventName: 'RewardCanceled',
|
|
148
|
+
strict: true,
|
|
149
|
+
});
|
|
150
|
+
if (!log)
|
|
151
|
+
throw new Error('`RewardCanceled` event not found.');
|
|
152
|
+
return log;
|
|
153
|
+
}
|
|
154
|
+
cancel.extractEvent = extractEvent;
|
|
155
|
+
})(cancel || (cancel = {}));
|
|
156
|
+
/**
|
|
157
|
+
* Claims accumulated rewards for a recipient.
|
|
158
|
+
*
|
|
159
|
+
* This function allows a reward recipient to claim their accumulated rewards
|
|
160
|
+
* and receive them as token transfers to their own balance.
|
|
161
|
+
*
|
|
162
|
+
* - Accrues all pending rewards up to the current block timestamp.
|
|
163
|
+
* - Updates the caller's reward accounting.
|
|
164
|
+
* - Transfers the caller's accumulated `rewardBalance` from the token contract to the caller.
|
|
165
|
+
* - If the contract's balance is insufficient, claims up to the available amount.
|
|
166
|
+
* - Returns the actual amount claimed.
|
|
167
|
+
*
|
|
168
|
+
* Notes:
|
|
169
|
+
* - Reverts with `Paused` if the token is paused.
|
|
170
|
+
* - Reverts with `PolicyForbids` if the caller is not authorized to receive tokens under TIP-403.
|
|
171
|
+
* - If opted in, the claimed amount is added back to `optedInSupply` since it goes to the recipient's balance.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* import { createClient, http } from 'viem'
|
|
176
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
177
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
178
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
179
|
+
*
|
|
180
|
+
* const client = createClient({
|
|
181
|
+
* account: privateKeyToAccount('0x...'),
|
|
182
|
+
* chain: tempo,
|
|
183
|
+
* transport: http(),
|
|
184
|
+
* })
|
|
185
|
+
*
|
|
186
|
+
* const hash = await actions.reward.claim(client, {
|
|
187
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
188
|
+
* })
|
|
189
|
+
* ```
|
|
190
|
+
*
|
|
191
|
+
* @param client - Client.
|
|
192
|
+
* @param parameters - Parameters.
|
|
193
|
+
* @returns The transaction hash.
|
|
194
|
+
*/
|
|
195
|
+
export async function claim(client, parameters) {
|
|
196
|
+
return claim.inner(writeContract, client, parameters);
|
|
197
|
+
}
|
|
198
|
+
(function (claim) {
|
|
199
|
+
/** @internal */
|
|
200
|
+
async function inner(action, client, parameters) {
|
|
201
|
+
const { token, ...rest } = parameters;
|
|
202
|
+
const call = claim.call({ token });
|
|
203
|
+
return (await action(client, {
|
|
204
|
+
...rest,
|
|
205
|
+
...call,
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
claim.inner = inner;
|
|
209
|
+
/**
|
|
210
|
+
* Defines a call to the `claimRewards` function.
|
|
211
|
+
*
|
|
212
|
+
* Can be passed as a parameter to:
|
|
213
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
214
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
215
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```ts
|
|
219
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
220
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
221
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
222
|
+
*
|
|
223
|
+
* const client = createClient({
|
|
224
|
+
* chain: tempo,
|
|
225
|
+
* transport: http(),
|
|
226
|
+
* }).extend(walletActions)
|
|
227
|
+
*
|
|
228
|
+
* const hash = await client.sendTransaction({
|
|
229
|
+
* calls: [actions.reward.claim.call({
|
|
230
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
231
|
+
* })],
|
|
232
|
+
* })
|
|
233
|
+
* ```
|
|
234
|
+
*
|
|
235
|
+
* @param args - Arguments.
|
|
236
|
+
* @returns The call.
|
|
237
|
+
*/
|
|
238
|
+
function call(args) {
|
|
239
|
+
const { token } = args;
|
|
240
|
+
return defineCall({
|
|
241
|
+
address: token,
|
|
242
|
+
abi: Abis.tip20,
|
|
243
|
+
args: [],
|
|
244
|
+
functionName: 'claimRewards',
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
claim.call = call;
|
|
248
|
+
})(claim || (claim = {}));
|
|
249
|
+
/**
|
|
250
|
+
* Claims accumulated rewards for a recipient and waits for confirmation.
|
|
251
|
+
*
|
|
252
|
+
* This function allows a reward recipient to claim their accumulated rewards
|
|
253
|
+
* and receive them as token transfers to their own balance.
|
|
254
|
+
*
|
|
255
|
+
* Behavior:
|
|
256
|
+
* - Accrues all pending rewards up to the current block timestamp.
|
|
257
|
+
* - Updates the caller's reward accounting.
|
|
258
|
+
* - Transfers the caller's accumulated `rewardBalance` from the token contract to the caller.
|
|
259
|
+
* - If the contract's balance is insufficient, claims up to the available amount.
|
|
260
|
+
*
|
|
261
|
+
* Notes:
|
|
262
|
+
* - Reverts with `Paused` if the token is paused.
|
|
263
|
+
* - Reverts with `PolicyForbids` if the caller is not authorized to receive tokens under TIP-403.
|
|
264
|
+
* - If opted in, the claimed amount is added back to `optedInSupply` since it goes to the recipient's balance.
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```ts
|
|
268
|
+
* import { createClient, http } from 'viem'
|
|
269
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
270
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
271
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
272
|
+
*
|
|
273
|
+
* const client = createClient({
|
|
274
|
+
* account: privateKeyToAccount('0x...'),
|
|
275
|
+
* chain: tempo,
|
|
276
|
+
* transport: http(),
|
|
277
|
+
* })
|
|
278
|
+
*
|
|
279
|
+
* const { receipt } = await actions.reward.claimSync(client, {
|
|
280
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
281
|
+
* })
|
|
282
|
+
* ```
|
|
283
|
+
*
|
|
284
|
+
* @param client - Client.
|
|
285
|
+
* @param parameters - Parameters.
|
|
286
|
+
* @returns The amount claimed and transaction receipt.
|
|
287
|
+
*/
|
|
288
|
+
export async function claimSync(client, parameters) {
|
|
289
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters;
|
|
290
|
+
const receipt = await claim.inner(writeContractSync, client, {
|
|
291
|
+
...rest,
|
|
292
|
+
throwOnReceiptRevert,
|
|
293
|
+
});
|
|
294
|
+
return {
|
|
295
|
+
receipt,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Gets a reward stream by its ID.
|
|
300
|
+
*
|
|
301
|
+
* Returns the stream details including:
|
|
302
|
+
* - `funder`: The address that funded the stream
|
|
303
|
+
* - `startTime`: When the stream started (block timestamp)
|
|
304
|
+
* - `endTime`: When the stream is scheduled to end
|
|
305
|
+
* - `ratePerSecondScaled`: The per-second emission rate (scaled by ACC_PRECISION = 1e18)
|
|
306
|
+
* - `amountTotal`: The total amount allocated to the stream
|
|
307
|
+
*
|
|
308
|
+
* Note: If the stream has been canceled or doesn't exist, `funder` will be the zero address.
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* ```ts
|
|
312
|
+
* import { createClient, http } from 'viem'
|
|
313
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
314
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
315
|
+
*
|
|
316
|
+
* const client = createClient({
|
|
317
|
+
* chain: tempo,
|
|
318
|
+
* transport: http(),
|
|
319
|
+
* })
|
|
320
|
+
*
|
|
321
|
+
* const stream = await actions.rewards.getStream(client, {
|
|
322
|
+
* id: 1n,
|
|
323
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
324
|
+
* })
|
|
325
|
+
* ```
|
|
326
|
+
*
|
|
327
|
+
* @param client - Client.
|
|
328
|
+
* @param parameters - Parameters.
|
|
329
|
+
* @returns The reward stream details.
|
|
330
|
+
*/
|
|
331
|
+
export async function getStream(client, parameters) {
|
|
332
|
+
return readContract(client, {
|
|
333
|
+
...parameters,
|
|
334
|
+
...getStream.call(parameters),
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
(function (getStream) {
|
|
338
|
+
/**
|
|
339
|
+
* Defines a call to the `getStream` function.
|
|
340
|
+
*
|
|
341
|
+
* @param args - Arguments.
|
|
342
|
+
* @returns The call.
|
|
343
|
+
*/
|
|
344
|
+
function call(args) {
|
|
345
|
+
const { id, token } = args;
|
|
346
|
+
return defineCall({
|
|
347
|
+
address: token,
|
|
348
|
+
abi: Abis.tip20,
|
|
349
|
+
args: [id],
|
|
350
|
+
functionName: 'getStream',
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
getStream.call = call;
|
|
354
|
+
})(getStream || (getStream = {}));
|
|
355
|
+
/**
|
|
356
|
+
* Gets the total reward per second rate for all active streams.
|
|
357
|
+
*
|
|
358
|
+
* Returns the current aggregate per-second emission rate scaled by `ACC_PRECISION` (1e18).
|
|
359
|
+
* This value represents the sum of all active reward streams' emission rates.
|
|
360
|
+
* The rate decreases when streams end (via `finalizeStreams`) or are canceled.
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* ```ts
|
|
364
|
+
* import { createClient, http } from 'viem'
|
|
365
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
366
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
367
|
+
*
|
|
368
|
+
* const client = createClient({
|
|
369
|
+
* chain: tempo,
|
|
370
|
+
* transport: http(),
|
|
371
|
+
* })
|
|
372
|
+
*
|
|
373
|
+
* const rate = await actions.rewards.getTotalPerSecond(client, {
|
|
374
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
375
|
+
* })
|
|
376
|
+
* ```
|
|
377
|
+
*
|
|
378
|
+
* @param client - Client.
|
|
379
|
+
* @param parameters - Parameters.
|
|
380
|
+
* @returns The total reward per second (scaled by 1e18).
|
|
381
|
+
*/
|
|
382
|
+
export async function getTotalPerSecond(client, parameters) {
|
|
383
|
+
return readContract(client, {
|
|
384
|
+
...parameters,
|
|
385
|
+
...getTotalPerSecond.call(parameters),
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
(function (getTotalPerSecond) {
|
|
389
|
+
/**
|
|
390
|
+
* Defines a call to the `totalRewardPerSecond` function.
|
|
391
|
+
*
|
|
392
|
+
* @param args - Arguments.
|
|
393
|
+
* @returns The call.
|
|
394
|
+
*/
|
|
395
|
+
function call(args) {
|
|
396
|
+
const { token } = args;
|
|
397
|
+
return defineCall({
|
|
398
|
+
address: token,
|
|
399
|
+
abi: Abis.tip20,
|
|
400
|
+
args: [],
|
|
401
|
+
functionName: 'totalRewardPerSecond',
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
getTotalPerSecond.call = call;
|
|
405
|
+
})(getTotalPerSecond || (getTotalPerSecond = {}));
|
|
406
|
+
/**
|
|
407
|
+
* Sets or changes the reward recipient for a token holder.
|
|
408
|
+
*
|
|
409
|
+
* This function allows a token holder to designate who should receive their share of rewards:
|
|
410
|
+
* - If `recipient` is the zero address, opts out from rewards distribution.
|
|
411
|
+
* - Otherwise, opts in and sets `recipient` as the address that will receive accrued rewards.
|
|
412
|
+
* - Can be called with `recipient == msg.sender` to receive rewards directly.
|
|
413
|
+
* - Automatically distributes any accrued rewards to the current recipient before changing.
|
|
414
|
+
*
|
|
415
|
+
* TIP-403 Policy:
|
|
416
|
+
* - 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.
|
|
417
|
+
*
|
|
418
|
+
* @example
|
|
419
|
+
* ```ts
|
|
420
|
+
* import { createClient, http } from 'viem'
|
|
421
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
422
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
423
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
424
|
+
*
|
|
425
|
+
* const client = createClient({
|
|
426
|
+
* account: privateKeyToAccount('0x...'),
|
|
427
|
+
* chain: tempo,
|
|
428
|
+
* transport: http(),
|
|
429
|
+
* })
|
|
430
|
+
*
|
|
431
|
+
* const hash = await actions.rewards.setRecipient(client, {
|
|
432
|
+
* recipient: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
|
|
433
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
434
|
+
* })
|
|
435
|
+
* ```
|
|
436
|
+
*
|
|
437
|
+
* @param client - Client.
|
|
438
|
+
* @param parameters - Parameters.
|
|
439
|
+
* @returns The transaction hash.
|
|
440
|
+
*/
|
|
441
|
+
export async function setRecipient(client, parameters) {
|
|
442
|
+
return setRecipient.inner(writeContract, client, parameters);
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Sets or changes the reward recipient for a token holder and waits for confirmation.
|
|
446
|
+
*
|
|
447
|
+
* This function allows a token holder to designate who should receive their share of rewards:
|
|
448
|
+
* - If `recipient` is the zero address, opts out from rewards distribution.
|
|
449
|
+
* - Otherwise, opts in and sets `recipient` as the address that will receive accrued rewards.
|
|
450
|
+
* - Can be called with `recipient == msg.sender` to receive rewards directly.
|
|
451
|
+
* - Automatically distributes any accrued rewards to the current recipient before changing.
|
|
452
|
+
*
|
|
453
|
+
* TIP-403 Policy:
|
|
454
|
+
* - 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.
|
|
455
|
+
*
|
|
456
|
+
* @example
|
|
457
|
+
* ```ts
|
|
458
|
+
* import { createClient, http } from 'viem'
|
|
459
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
460
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
461
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
462
|
+
*
|
|
463
|
+
* const client = createClient({
|
|
464
|
+
* account: privateKeyToAccount('0x...'),
|
|
465
|
+
* chain: tempo,
|
|
466
|
+
* transport: http(),
|
|
467
|
+
* })
|
|
468
|
+
*
|
|
469
|
+
* const { holder, recipient, receipt } = await actions.rewards.setRecipientSync(client, {
|
|
470
|
+
* recipient: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
|
|
471
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
472
|
+
* })
|
|
473
|
+
* ```
|
|
474
|
+
*
|
|
475
|
+
* @param client - Client.
|
|
476
|
+
* @param parameters - Parameters.
|
|
477
|
+
* @returns The holder, recipient, and transaction receipt.
|
|
478
|
+
*/
|
|
479
|
+
export async function setRecipientSync(client, parameters) {
|
|
480
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters;
|
|
481
|
+
const receipt = await setRecipient.inner(writeContractSync, client, {
|
|
482
|
+
...rest,
|
|
483
|
+
throwOnReceiptRevert,
|
|
484
|
+
});
|
|
485
|
+
const { args } = setRecipient.extractEvent(receipt.logs);
|
|
486
|
+
return {
|
|
487
|
+
...args,
|
|
488
|
+
receipt,
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
(function (setRecipient) {
|
|
492
|
+
/** @internal */
|
|
493
|
+
async function inner(action, client, parameters) {
|
|
494
|
+
const { recipient, token, ...rest } = parameters;
|
|
495
|
+
const call = setRecipient.call({ recipient, token });
|
|
496
|
+
return (await action(client, {
|
|
497
|
+
...rest,
|
|
498
|
+
...call,
|
|
499
|
+
}));
|
|
500
|
+
}
|
|
501
|
+
setRecipient.inner = inner;
|
|
502
|
+
/**
|
|
503
|
+
* Defines a call to the `setRecipient` function.
|
|
504
|
+
*
|
|
505
|
+
* Can be passed as a parameter to:
|
|
506
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
507
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
508
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
509
|
+
*
|
|
510
|
+
* @example
|
|
511
|
+
* ```ts
|
|
512
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
513
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
514
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
515
|
+
*
|
|
516
|
+
* const client = createClient({
|
|
517
|
+
* chain: tempo,
|
|
518
|
+
* transport: http(),
|
|
519
|
+
* }).extend(walletActions)
|
|
520
|
+
*
|
|
521
|
+
* const hash = await client.sendTransaction({
|
|
522
|
+
* calls: [actions.rewards.setRecipient.call({
|
|
523
|
+
* recipient: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
|
|
524
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
525
|
+
* })],
|
|
526
|
+
* })
|
|
527
|
+
* ```
|
|
528
|
+
*
|
|
529
|
+
* @param args - Arguments.
|
|
530
|
+
* @returns The call.
|
|
531
|
+
*/
|
|
532
|
+
function call(args) {
|
|
533
|
+
const { recipient, token } = args;
|
|
534
|
+
return defineCall({
|
|
535
|
+
address: token,
|
|
536
|
+
abi: Abis.tip20,
|
|
537
|
+
args: [recipient],
|
|
538
|
+
functionName: 'setRewardRecipient',
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
setRecipient.call = call;
|
|
542
|
+
/**
|
|
543
|
+
* Extracts the `RewardRecipientSet` event from logs.
|
|
544
|
+
*
|
|
545
|
+
* @param logs - The logs.
|
|
546
|
+
* @returns The `RewardRecipientSet` event.
|
|
547
|
+
*/
|
|
548
|
+
function extractEvent(logs) {
|
|
549
|
+
const [log] = parseEventLogs({
|
|
550
|
+
abi: Abis.tip20,
|
|
551
|
+
logs,
|
|
552
|
+
eventName: 'RewardRecipientSet',
|
|
553
|
+
strict: true,
|
|
554
|
+
});
|
|
555
|
+
if (!log)
|
|
556
|
+
throw new Error('`RewardRecipientSet` event not found.');
|
|
557
|
+
return log;
|
|
558
|
+
}
|
|
559
|
+
setRecipient.extractEvent = extractEvent;
|
|
560
|
+
})(setRecipient || (setRecipient = {}));
|
|
561
|
+
/**
|
|
562
|
+
* Starts a new reward stream that distributes tokens to opted-in holders.
|
|
563
|
+
*
|
|
564
|
+
* Behavior:
|
|
565
|
+
* - Transfers `amount` of tokens from the caller into the token contract's reward pool.
|
|
566
|
+
* - If `seconds == 0`: Immediately distributes `amount` to current opted-in holders by increasing `rewardPerTokenStored`.
|
|
567
|
+
* Returns stream ID `0`. Distribution occurs when holders interact with the token (transfers, etc.).
|
|
568
|
+
* - If `seconds > 0`: Starts a linear stream that emits evenly from `block.timestamp` to `block.timestamp + seconds`.
|
|
569
|
+
* Returns a unique stream ID for later cancellation.
|
|
570
|
+
*
|
|
571
|
+
* Notes:
|
|
572
|
+
* - Reverts with `InvalidAmount` if `amount == 0`.
|
|
573
|
+
* - Allowed even when `optedInSupply == 0` (tokens distributed while no one is opted in are locked permanently).
|
|
574
|
+
* - The transfer from caller to pool is subject to TIP-403 policy checks.
|
|
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.start(client, {
|
|
590
|
+
* amount: 100000000000000000000n,
|
|
591
|
+
* seconds: 86400,
|
|
592
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
593
|
+
* })
|
|
594
|
+
* ```
|
|
595
|
+
*
|
|
596
|
+
* @param client - Client.
|
|
597
|
+
* @param parameters - Parameters.
|
|
598
|
+
* @returns The transaction hash.
|
|
599
|
+
*/
|
|
600
|
+
export async function start(client, parameters) {
|
|
601
|
+
return start.inner(writeContract, client, parameters);
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Starts a new reward stream that distributes tokens to opted-in holders and waits for confirmation.
|
|
605
|
+
*
|
|
606
|
+
* Behavior:
|
|
607
|
+
* - Transfers `amount` of tokens from the caller into the token contract's reward pool.
|
|
608
|
+
* - If `seconds == 0`: Immediately distributes `amount` to current opted-in holders by increasing `rewardPerTokenStored`.
|
|
609
|
+
* Returns stream ID `0`. Distribution occurs when holders interact with the token (transfers, etc.).
|
|
610
|
+
* - If `seconds > 0`: Starts a linear stream that emits evenly from `block.timestamp` to `block.timestamp + seconds`.
|
|
611
|
+
* Returns a unique stream ID for later cancellation.
|
|
612
|
+
*
|
|
613
|
+
* Notes:
|
|
614
|
+
* - Reverts with `InvalidAmount` if `amount == 0`.
|
|
615
|
+
* - Allowed even when `optedInSupply == 0` (tokens distributed while no one is opted in are locked permanently).
|
|
616
|
+
* - The transfer from caller to pool is subject to TIP-403 policy checks.
|
|
617
|
+
*
|
|
618
|
+
* @example
|
|
619
|
+
* ```ts
|
|
620
|
+
* import { createClient, http } from 'viem'
|
|
621
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
622
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
623
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
624
|
+
*
|
|
625
|
+
* const client = createClient({
|
|
626
|
+
* account: privateKeyToAccount('0x...'),
|
|
627
|
+
* chain: tempo,
|
|
628
|
+
* transport: http(),
|
|
629
|
+
* })
|
|
630
|
+
*
|
|
631
|
+
* const { id, receipt } = await actions.rewards.startSync(client, {
|
|
632
|
+
* amount: 100000000000000000000n,
|
|
633
|
+
* seconds: 86400,
|
|
634
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
635
|
+
* })
|
|
636
|
+
* ```
|
|
637
|
+
*
|
|
638
|
+
* @param client - Client.
|
|
639
|
+
* @param parameters - Parameters.
|
|
640
|
+
* @returns The stream ID, funder, amount, duration, and transaction receipt.
|
|
641
|
+
*/
|
|
642
|
+
export async function startSync(client, parameters) {
|
|
643
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters;
|
|
644
|
+
const receipt = await start.inner(writeContractSync, client, {
|
|
645
|
+
...rest,
|
|
646
|
+
throwOnReceiptRevert,
|
|
647
|
+
});
|
|
648
|
+
const { args } = start.extractEvent(receipt.logs);
|
|
649
|
+
return {
|
|
650
|
+
...args,
|
|
651
|
+
receipt,
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
(function (start) {
|
|
655
|
+
/** @internal */
|
|
656
|
+
async function inner(action, client, parameters) {
|
|
657
|
+
const { amount, seconds, token, ...rest } = parameters;
|
|
658
|
+
const call = start.call({ amount, seconds, token });
|
|
659
|
+
return (await action(client, {
|
|
660
|
+
...rest,
|
|
661
|
+
...call,
|
|
662
|
+
}));
|
|
663
|
+
}
|
|
664
|
+
start.inner = inner;
|
|
665
|
+
/**
|
|
666
|
+
* Defines a call to the `start` function.
|
|
667
|
+
*
|
|
668
|
+
* Can be passed as a parameter to:
|
|
669
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
670
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
671
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
672
|
+
*
|
|
673
|
+
* @example
|
|
674
|
+
* ```ts
|
|
675
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
676
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
677
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
678
|
+
*
|
|
679
|
+
* const client = createClient({
|
|
680
|
+
* chain: tempo,
|
|
681
|
+
* transport: http(),
|
|
682
|
+
* }).extend(walletActions)
|
|
683
|
+
*
|
|
684
|
+
* const hash = await client.sendTransaction({
|
|
685
|
+
* calls: [actions.rewards.start.call({
|
|
686
|
+
* amount: 100000000000000000000n,
|
|
687
|
+
* seconds: 86400,
|
|
688
|
+
* token: '0x20c0000000000000000000000000000000000001',
|
|
689
|
+
* })],
|
|
690
|
+
* })
|
|
691
|
+
* ```
|
|
692
|
+
*
|
|
693
|
+
* @param args - Arguments.
|
|
694
|
+
* @returns The call.
|
|
695
|
+
*/
|
|
696
|
+
function call(args) {
|
|
697
|
+
const { amount, seconds, token } = args;
|
|
698
|
+
return defineCall({
|
|
699
|
+
address: token,
|
|
700
|
+
abi: Abis.tip20,
|
|
701
|
+
args: [amount, seconds],
|
|
702
|
+
functionName: 'startReward',
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
start.call = call;
|
|
706
|
+
/**
|
|
707
|
+
* Extracts the `RewardScheduled` event from logs.
|
|
708
|
+
*
|
|
709
|
+
* @param logs - The logs.
|
|
710
|
+
* @returns The `RewardScheduled` event.
|
|
711
|
+
*/
|
|
712
|
+
function extractEvent(logs) {
|
|
713
|
+
const [log] = parseEventLogs({
|
|
714
|
+
abi: Abis.tip20,
|
|
715
|
+
logs,
|
|
716
|
+
eventName: 'RewardScheduled',
|
|
717
|
+
strict: true,
|
|
718
|
+
});
|
|
719
|
+
if (!log)
|
|
720
|
+
throw new Error('`RewardScheduled` event not found.');
|
|
721
|
+
return log;
|
|
722
|
+
}
|
|
723
|
+
start.extractEvent = extractEvent;
|
|
724
|
+
})(start || (start = {}));
|
|
725
|
+
//# sourceMappingURL=reward.js.map
|