tempo.ts 0.6.2 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +134 -0
- package/README.md +6 -2
- package/dist/ox/Transaction.js +1 -1
- package/dist/ox/Transaction.js.map +1 -1
- package/dist/server/Handler.d.ts +346 -0
- package/dist/server/Handler.d.ts.map +1 -0
- package/dist/server/Handler.js +441 -0
- package/dist/server/Handler.js.map +1 -0
- package/dist/server/Kv.d.ts +16 -0
- package/dist/server/Kv.d.ts.map +1 -0
- package/dist/server/Kv.js +25 -0
- package/dist/server/Kv.js.map +1 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +3 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/internal/requestListener.d.ts +124 -0
- package/dist/server/internal/requestListener.d.ts.map +1 -0
- package/dist/server/internal/requestListener.js +174 -0
- package/dist/server/internal/requestListener.js.map +1 -0
- package/dist/viem/Actions/amm.d.ts +9 -41
- package/dist/viem/Actions/amm.d.ts.map +1 -1
- package/dist/viem/Actions/amm.js +15 -26
- package/dist/viem/Actions/amm.js.map +1 -1
- package/dist/viem/Actions/reward.d.ts +0 -1067
- package/dist/viem/Actions/reward.d.ts.map +1 -1
- package/dist/viem/Actions/reward.js +4 -212
- package/dist/viem/Actions/reward.js.map +1 -1
- package/dist/viem/Decorator.d.ts +0 -263
- package/dist/viem/Decorator.d.ts.map +1 -1
- package/dist/viem/Decorator.js +0 -10
- package/dist/viem/Decorator.js.map +1 -1
- package/dist/viem/Storage.d.ts +23 -0
- package/dist/viem/Storage.d.ts.map +1 -0
- package/dist/viem/Storage.js +47 -0
- package/dist/viem/Storage.js.map +1 -0
- package/dist/viem/Transport.d.ts +10 -1
- package/dist/viem/Transport.d.ts.map +1 -1
- package/dist/viem/Transport.js +22 -3
- package/dist/viem/Transport.js.map +1 -1
- package/dist/viem/internal/utils.d.ts +6 -0
- package/dist/viem/internal/utils.d.ts.map +1 -1
- package/dist/viem/internal/utils.js +24 -0
- package/dist/viem/internal/utils.js.map +1 -1
- package/dist/wagmi/Actions/reward.d.ts +0 -110
- package/dist/wagmi/Actions/reward.d.ts.map +1 -1
- package/dist/wagmi/Actions/reward.js +0 -121
- package/dist/wagmi/Actions/reward.js.map +1 -1
- package/dist/wagmi/Connector.d.ts +6 -17
- package/dist/wagmi/Connector.d.ts.map +1 -1
- package/dist/wagmi/Connector.js +17 -43
- package/dist/wagmi/Connector.js.map +1 -1
- package/dist/wagmi/Hooks/reward.d.ts +0 -88
- package/dist/wagmi/Hooks/reward.d.ts.map +1 -1
- package/dist/wagmi/Hooks/reward.js +0 -103
- package/dist/wagmi/Hooks/reward.js.map +1 -1
- package/dist/wagmi/KeyManager.d.ts +57 -0
- package/dist/wagmi/KeyManager.d.ts.map +1 -0
- package/dist/wagmi/KeyManager.js +101 -0
- package/dist/wagmi/KeyManager.js.map +1 -0
- package/dist/wagmi/index.d.ts +1 -0
- package/dist/wagmi/index.d.ts.map +1 -1
- package/dist/wagmi/index.js +1 -0
- package/dist/wagmi/index.js.map +1 -1
- package/package.json +8 -2
- package/src/ox/Transaction.ts +1 -1
- package/src/ox/e2e.test.ts +7 -0
- package/src/server/Handler.test.ts +566 -0
- package/src/server/Handler.ts +577 -0
- package/src/server/Kv.ts +40 -0
- package/src/server/index.ts +2 -0
- package/src/server/internal/requestListener.ts +285 -0
- package/src/viem/Actions/amm.test.ts +10 -284
- package/src/viem/Actions/amm.ts +32 -40
- package/src/viem/Actions/reward.test.ts +4 -212
- package/src/viem/Actions/reward.ts +4 -291
- package/src/viem/Decorator.ts +0 -294
- package/src/viem/Storage.ts +88 -0
- package/src/viem/Transport.ts +40 -2
- package/src/viem/e2e.test.ts +106 -3
- package/src/viem/internal/utils.ts +21 -0
- package/src/wagmi/Actions/amm.test.ts +7 -85
- package/src/wagmi/Actions/reward.test.ts +0 -99
- package/src/wagmi/Actions/reward.ts +0 -203
- package/src/wagmi/Connector.test.ts +4 -1
- package/src/wagmi/Connector.ts +24 -58
- package/src/wagmi/Hooks/amm.test.ts +8 -200
- package/src/wagmi/Hooks/reward.test.ts +1 -142
- package/src/wagmi/Hooks/reward.ts +0 -196
- package/src/wagmi/KeyManager.ts +159 -0
- package/src/wagmi/index.ts +1 -0
package/src/viem/Actions/amm.ts
CHANGED
|
@@ -491,20 +491,12 @@ export namespace mint {
|
|
|
491
491
|
export type Args = {
|
|
492
492
|
/** Address to mint LP tokens to. */
|
|
493
493
|
to: Address
|
|
494
|
-
/** User token address
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
}
|
|
501
|
-
/** Validator token address and amount. */
|
|
502
|
-
validatorToken: {
|
|
503
|
-
/** Address or ID of the validator token. */
|
|
504
|
-
address: TokenId.TokenIdOrAddress
|
|
505
|
-
/** Amount of validator token to add. */
|
|
506
|
-
amount: bigint
|
|
507
|
-
}
|
|
494
|
+
/** User token address. */
|
|
495
|
+
userTokenAddress: TokenId.TokenIdOrAddress
|
|
496
|
+
/** Validator token address. */
|
|
497
|
+
validatorTokenAddress: TokenId.TokenIdOrAddress
|
|
498
|
+
/** Amount of validator token to add. */
|
|
499
|
+
validatorTokenAmount: bigint
|
|
508
500
|
}
|
|
509
501
|
|
|
510
502
|
export type ReturnValue = WriteContractReturnType
|
|
@@ -519,8 +511,19 @@ export namespace mint {
|
|
|
519
511
|
client: Client<Transport, chain, account>,
|
|
520
512
|
parameters: mint.Parameters<chain, account>,
|
|
521
513
|
): Promise<ReturnType<action>> {
|
|
522
|
-
const {
|
|
523
|
-
|
|
514
|
+
const {
|
|
515
|
+
to,
|
|
516
|
+
userTokenAddress,
|
|
517
|
+
validatorTokenAddress,
|
|
518
|
+
validatorTokenAmount,
|
|
519
|
+
...rest
|
|
520
|
+
} = parameters
|
|
521
|
+
const call = mint.call({
|
|
522
|
+
to,
|
|
523
|
+
userTokenAddress,
|
|
524
|
+
validatorTokenAddress,
|
|
525
|
+
validatorTokenAmount,
|
|
526
|
+
})
|
|
524
527
|
return (await action(client, {
|
|
525
528
|
...rest,
|
|
526
529
|
...call,
|
|
@@ -578,33 +581,22 @@ export namespace mint {
|
|
|
578
581
|
* @returns The call.
|
|
579
582
|
*/
|
|
580
583
|
export function call(args: Args) {
|
|
581
|
-
const {
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
TokenId.toAddress(userToken.address),
|
|
588
|
-
TokenId.toAddress(validatorToken.address),
|
|
589
|
-
userToken.amount,
|
|
590
|
-
validatorToken.amount,
|
|
591
|
-
to,
|
|
592
|
-
],
|
|
593
|
-
} as const
|
|
594
|
-
return {
|
|
595
|
-
functionName: 'mintWithValidatorToken',
|
|
596
|
-
args: [
|
|
597
|
-
TokenId.toAddress(userToken.address),
|
|
598
|
-
TokenId.toAddress(validatorToken.address),
|
|
599
|
-
validatorToken.amount,
|
|
600
|
-
to,
|
|
601
|
-
],
|
|
602
|
-
} as const
|
|
603
|
-
})()
|
|
584
|
+
const {
|
|
585
|
+
to,
|
|
586
|
+
userTokenAddress,
|
|
587
|
+
validatorTokenAddress,
|
|
588
|
+
validatorTokenAmount,
|
|
589
|
+
} = args
|
|
604
590
|
return defineCall({
|
|
605
591
|
address: Addresses.feeManager,
|
|
606
592
|
abi: Abis.feeAmm,
|
|
607
|
-
|
|
593
|
+
functionName: 'mintWithValidatorToken',
|
|
594
|
+
args: [
|
|
595
|
+
TokenId.toAddress(userTokenAddress),
|
|
596
|
+
TokenId.toAddress(validatorTokenAddress),
|
|
597
|
+
validatorTokenAmount,
|
|
598
|
+
to,
|
|
599
|
+
],
|
|
608
600
|
})
|
|
609
601
|
}
|
|
610
602
|
|
|
@@ -1,44 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { parseUnits } from 'viem'
|
|
2
2
|
import { describe, expect, test } from 'vitest'
|
|
3
3
|
import { clientWithAccount, setupToken } from '../../../test/viem/config.js'
|
|
4
4
|
import * as actions from './index.js'
|
|
5
5
|
|
|
6
6
|
const account = clientWithAccount.account
|
|
7
7
|
|
|
8
|
-
describe('
|
|
9
|
-
test('default', async () => {
|
|
10
|
-
const { token } = await setupToken(clientWithAccount)
|
|
11
|
-
|
|
12
|
-
// Start a reward stream with longer duration
|
|
13
|
-
const rewardAmount = parseUnits('100', 6)
|
|
14
|
-
const { id: streamId } = await actions.reward.startSync(clientWithAccount, {
|
|
15
|
-
amount: rewardAmount,
|
|
16
|
-
seconds: 3600, // 1 hour to avoid stream ending during test
|
|
17
|
-
token,
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
// Cancel the reward
|
|
21
|
-
const { receipt, refund, ...result } = await actions.reward.cancelSync(
|
|
22
|
-
clientWithAccount,
|
|
23
|
-
{
|
|
24
|
-
id: streamId,
|
|
25
|
-
token,
|
|
26
|
-
},
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
expect(refund).toBeGreaterThan(0n)
|
|
30
|
-
expect(receipt).toBeDefined()
|
|
31
|
-
expect(result).toMatchInlineSnapshot(`
|
|
32
|
-
{
|
|
33
|
-
"funder": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
34
|
-
"id": 1n,
|
|
35
|
-
}
|
|
36
|
-
`)
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
// TODO: unskip
|
|
41
|
-
describe.skip('claimSync', () => {
|
|
8
|
+
describe('claimSync', () => {
|
|
42
9
|
test('default', async () => {
|
|
43
10
|
const { token } = await setupToken(clientWithAccount)
|
|
44
11
|
|
|
@@ -63,7 +30,6 @@ describe.skip('claimSync', () => {
|
|
|
63
30
|
// Start immediate reward to distribute rewards
|
|
64
31
|
await actions.reward.startSync(clientWithAccount, {
|
|
65
32
|
amount: rewardAmount,
|
|
66
|
-
seconds: 0,
|
|
67
33
|
token,
|
|
68
34
|
})
|
|
69
35
|
|
|
@@ -120,7 +86,6 @@ describe.skip('claimSync', () => {
|
|
|
120
86
|
// Start a streaming reward (not immediate)
|
|
121
87
|
await actions.reward.startSync(clientWithAccount, {
|
|
122
88
|
amount: rewardAmount,
|
|
123
|
-
seconds: 10,
|
|
124
89
|
token,
|
|
125
90
|
})
|
|
126
91
|
|
|
@@ -146,73 +111,6 @@ describe.skip('claimSync', () => {
|
|
|
146
111
|
})
|
|
147
112
|
})
|
|
148
113
|
|
|
149
|
-
describe('getStream', () => {
|
|
150
|
-
test('default', async () => {
|
|
151
|
-
const { token } = await setupToken(clientWithAccount)
|
|
152
|
-
|
|
153
|
-
// Start a reward stream
|
|
154
|
-
const rewardAmount = parseUnits('100', 6)
|
|
155
|
-
const duration = 10
|
|
156
|
-
const { id: streamId } = await actions.reward.startSync(clientWithAccount, {
|
|
157
|
-
amount: rewardAmount,
|
|
158
|
-
seconds: duration,
|
|
159
|
-
token,
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
// Get the stream
|
|
163
|
-
const { endTime, startTime, ...stream } = await actions.reward.getStream(
|
|
164
|
-
clientWithAccount,
|
|
165
|
-
{
|
|
166
|
-
id: streamId,
|
|
167
|
-
token,
|
|
168
|
-
},
|
|
169
|
-
)
|
|
170
|
-
|
|
171
|
-
expect(startTime).toBeGreaterThan(0)
|
|
172
|
-
expect(endTime).toBeGreaterThan(startTime)
|
|
173
|
-
expect(stream).toMatchInlineSnapshot(`
|
|
174
|
-
{
|
|
175
|
-
"amountTotal": 100000000n,
|
|
176
|
-
"funder": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
177
|
-
"ratePerSecondScaled": 10000000000000000000000000n,
|
|
178
|
-
}
|
|
179
|
-
`)
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
test('behavior: canceled stream has zero funder', async () => {
|
|
183
|
-
const { token } = await setupToken(clientWithAccount)
|
|
184
|
-
|
|
185
|
-
// Start and cancel a reward stream
|
|
186
|
-
const rewardAmount = parseUnits('100', 6)
|
|
187
|
-
const { id: streamId } = await actions.reward.startSync(clientWithAccount, {
|
|
188
|
-
amount: rewardAmount,
|
|
189
|
-
seconds: 3600, // 1 hour to avoid stream ending during test
|
|
190
|
-
token,
|
|
191
|
-
})
|
|
192
|
-
|
|
193
|
-
await actions.reward.cancelSync(clientWithAccount, {
|
|
194
|
-
id: streamId,
|
|
195
|
-
token,
|
|
196
|
-
})
|
|
197
|
-
|
|
198
|
-
// Get the canceled stream
|
|
199
|
-
const stream = await actions.reward.getStream(clientWithAccount, {
|
|
200
|
-
id: streamId,
|
|
201
|
-
token,
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
expect(stream).toMatchInlineSnapshot(`
|
|
205
|
-
{
|
|
206
|
-
"amountTotal": 0n,
|
|
207
|
-
"endTime": 0n,
|
|
208
|
-
"funder": "0x0000000000000000000000000000000000000000",
|
|
209
|
-
"ratePerSecondScaled": 0n,
|
|
210
|
-
"startTime": 0n,
|
|
211
|
-
}
|
|
212
|
-
`)
|
|
213
|
-
})
|
|
214
|
-
})
|
|
215
|
-
|
|
216
114
|
describe('getTotalPerSecond', () => {
|
|
217
115
|
test('default', async () => {
|
|
218
116
|
const { token } = await setupToken(clientWithAccount)
|
|
@@ -223,29 +121,6 @@ describe('getTotalPerSecond', () => {
|
|
|
223
121
|
|
|
224
122
|
expect(rate).toBe(0n)
|
|
225
123
|
})
|
|
226
|
-
|
|
227
|
-
test('behavior: increases after starting stream', async () => {
|
|
228
|
-
const { token } = await setupToken(clientWithAccount)
|
|
229
|
-
|
|
230
|
-
// Start a reward stream
|
|
231
|
-
const rewardAmount = parseUnits('100', 6)
|
|
232
|
-
const duration = 100
|
|
233
|
-
await actions.reward.startSync(clientWithAccount, {
|
|
234
|
-
amount: rewardAmount,
|
|
235
|
-
seconds: duration,
|
|
236
|
-
token,
|
|
237
|
-
})
|
|
238
|
-
|
|
239
|
-
// Check total reward per second
|
|
240
|
-
const rate = await actions.reward.getTotalPerSecond(clientWithAccount, {
|
|
241
|
-
token,
|
|
242
|
-
})
|
|
243
|
-
|
|
244
|
-
// Expected rate = (amount * ACC_PRECISION) / seconds
|
|
245
|
-
// ACC_PRECISION = 1e18
|
|
246
|
-
const expectedRate = (rewardAmount * parseEther('1')) / BigInt(duration)
|
|
247
|
-
expect(rate).toBe(expectedRate)
|
|
248
|
-
})
|
|
249
124
|
})
|
|
250
125
|
|
|
251
126
|
describe('setRecipientSync', () => {
|
|
@@ -288,88 +163,7 @@ describe('setRecipientSync', () => {
|
|
|
288
163
|
})
|
|
289
164
|
|
|
290
165
|
describe('startSync', () => {
|
|
291
|
-
test('
|
|
292
|
-
const { token } = await setupToken(clientWithAccount)
|
|
293
|
-
|
|
294
|
-
// Start a reward stream
|
|
295
|
-
const duration = 10
|
|
296
|
-
const rewardAmount = parseUnits('100', 6)
|
|
297
|
-
const { id, receipt, ...result } = await actions.reward.startSync(
|
|
298
|
-
clientWithAccount,
|
|
299
|
-
{
|
|
300
|
-
amount: rewardAmount,
|
|
301
|
-
seconds: duration,
|
|
302
|
-
token,
|
|
303
|
-
},
|
|
304
|
-
)
|
|
305
|
-
|
|
306
|
-
expect(receipt).toBeDefined()
|
|
307
|
-
expect(result).toMatchInlineSnapshot(`
|
|
308
|
-
{
|
|
309
|
-
"amount": 100000000n,
|
|
310
|
-
"durationSeconds": 10,
|
|
311
|
-
"funder": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
312
|
-
}
|
|
313
|
-
`)
|
|
314
|
-
|
|
315
|
-
// Verify the stream was created
|
|
316
|
-
const { endTime, startTime, ...stream } = await actions.reward.getStream(
|
|
317
|
-
clientWithAccount,
|
|
318
|
-
{
|
|
319
|
-
id,
|
|
320
|
-
token,
|
|
321
|
-
},
|
|
322
|
-
)
|
|
323
|
-
|
|
324
|
-
expect(startTime).toBeGreaterThan(0)
|
|
325
|
-
expect(endTime).toBeGreaterThan(startTime)
|
|
326
|
-
expect(stream).toMatchInlineSnapshot(`
|
|
327
|
-
{
|
|
328
|
-
"amountTotal": 100000000n,
|
|
329
|
-
"funder": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
330
|
-
"ratePerSecondScaled": 10000000000000000000000000n,
|
|
331
|
-
}
|
|
332
|
-
`)
|
|
333
|
-
|
|
334
|
-
// Verify total reward per second
|
|
335
|
-
const totalRate = await actions.reward.getTotalPerSecond(
|
|
336
|
-
clientWithAccount,
|
|
337
|
-
{
|
|
338
|
-
token,
|
|
339
|
-
},
|
|
340
|
-
)
|
|
341
|
-
const expectedRate = (rewardAmount * parseEther('1')) / BigInt(duration)
|
|
342
|
-
expect(totalRate).toBe(expectedRate)
|
|
343
|
-
})
|
|
344
|
-
|
|
345
|
-
test('behavior: streaming distribution', async () => {
|
|
346
|
-
const { token } = await setupToken(clientWithAccount)
|
|
347
|
-
|
|
348
|
-
// Start a streaming reward
|
|
349
|
-
const duration = 3600
|
|
350
|
-
const rewardAmount = parseUnits('100', 6)
|
|
351
|
-
const { id } = await actions.reward.startSync(clientWithAccount, {
|
|
352
|
-
amount: rewardAmount,
|
|
353
|
-
seconds: duration,
|
|
354
|
-
token,
|
|
355
|
-
})
|
|
356
|
-
|
|
357
|
-
expect(id).toBeGreaterThan(0n) // Streaming distributions return ID > 0
|
|
358
|
-
|
|
359
|
-
// Verify the stream was created with correct rate
|
|
360
|
-
const totalRate = await actions.reward.getTotalPerSecond(
|
|
361
|
-
clientWithAccount,
|
|
362
|
-
{
|
|
363
|
-
token,
|
|
364
|
-
},
|
|
365
|
-
)
|
|
366
|
-
|
|
367
|
-
const expectedRate = (rewardAmount * parseEther('1')) / BigInt(duration)
|
|
368
|
-
expect(totalRate).toBe(expectedRate)
|
|
369
|
-
})
|
|
370
|
-
|
|
371
|
-
// TODO: unskip
|
|
372
|
-
test.skip('behavior: immediate distribution (seconds = 0)', async () => {
|
|
166
|
+
test('behavior: immediate distribution (seconds = 0)', async () => {
|
|
373
167
|
const { token } = await setupToken(clientWithAccount)
|
|
374
168
|
|
|
375
169
|
// Opt in to rewards
|
|
@@ -393,10 +187,9 @@ describe('startSync', () => {
|
|
|
393
187
|
token,
|
|
394
188
|
})
|
|
395
189
|
|
|
396
|
-
// Start immediate reward
|
|
190
|
+
// Start immediate reward
|
|
397
191
|
const { id } = await actions.reward.startSync(clientWithAccount, {
|
|
398
192
|
amount: rewardAmount,
|
|
399
|
-
seconds: 0,
|
|
400
193
|
token,
|
|
401
194
|
})
|
|
402
195
|
|
|
@@ -454,7 +247,6 @@ describe('startSync', () => {
|
|
|
454
247
|
const { amount, durationSeconds, funder, id } =
|
|
455
248
|
await actions.reward.startSync(clientWithAccount, {
|
|
456
249
|
amount: rewardAmount,
|
|
457
|
-
seconds: 0,
|
|
458
250
|
token,
|
|
459
251
|
})
|
|
460
252
|
|
|
@@ -15,215 +15,6 @@ import * as Abis from '../Abis.js'
|
|
|
15
15
|
import type { ReadParameters, WriteParameters } from '../internal/types.js'
|
|
16
16
|
import { defineCall } from '../internal/utils.js'
|
|
17
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 { Actions } from 'tempo.ts/viem'
|
|
33
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
34
|
-
*
|
|
35
|
-
* const client = createClient({
|
|
36
|
-
* account: privateKeyToAccount('0x...'),
|
|
37
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
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 { Actions } from 'tempo.ts/viem'
|
|
76
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
77
|
-
*
|
|
78
|
-
* const client = createClient({
|
|
79
|
-
* account: privateKeyToAccount('0x...'),
|
|
80
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
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 { Actions } from 'tempo.ts/viem'
|
|
162
|
-
*
|
|
163
|
-
* const client = createClient({
|
|
164
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
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
18
|
/**
|
|
228
19
|
* Claims accumulated rewards for a recipient.
|
|
229
20
|
*
|
|
@@ -417,82 +208,6 @@ export namespace claimSync {
|
|
|
417
208
|
export type ErrorType = claim.ErrorType
|
|
418
209
|
}
|
|
419
210
|
|
|
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 { Actions } from 'tempo.ts/viem'
|
|
437
|
-
*
|
|
438
|
-
* const client = createClient({
|
|
439
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
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
211
|
/**
|
|
497
212
|
* Gets the total reward per second rate for all active streams.
|
|
498
213
|
*
|
|
@@ -883,8 +598,6 @@ export namespace start {
|
|
|
883
598
|
export type Args = {
|
|
884
599
|
/** The amount of tokens to distribute (must be > 0) */
|
|
885
600
|
amount: bigint
|
|
886
|
-
/** The duration in seconds (0 for immediate distribution, >0 for linear streaming) */
|
|
887
|
-
seconds: number
|
|
888
601
|
/** The TIP20 token address */
|
|
889
602
|
token: Address
|
|
890
603
|
}
|
|
@@ -909,8 +622,8 @@ export namespace start {
|
|
|
909
622
|
client: Client<Transport, chain, account>,
|
|
910
623
|
parameters: Parameters<chain, account>,
|
|
911
624
|
): Promise<ReturnType<action>> {
|
|
912
|
-
const { amount,
|
|
913
|
-
const call = start.call({ amount,
|
|
625
|
+
const { amount, token, ...rest } = parameters
|
|
626
|
+
const call = start.call({ amount, token })
|
|
914
627
|
return (await action(client, {
|
|
915
628
|
...rest,
|
|
916
629
|
...call,
|
|
@@ -949,11 +662,11 @@ export namespace start {
|
|
|
949
662
|
* @returns The call.
|
|
950
663
|
*/
|
|
951
664
|
export function call(args: Args) {
|
|
952
|
-
const { amount,
|
|
665
|
+
const { amount, token } = args
|
|
953
666
|
return defineCall({
|
|
954
667
|
address: token,
|
|
955
668
|
abi: Abis.tip20,
|
|
956
|
-
args: [amount,
|
|
669
|
+
args: [amount, 0],
|
|
957
670
|
functionName: 'startReward',
|
|
958
671
|
})
|
|
959
672
|
}
|