tempo.ts 0.7.5 → 0.7.6
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 +6 -0
- package/dist/viem/Actions/amm.d.ts +12 -32
- package/dist/viem/Actions/amm.d.ts.map +1 -1
- package/dist/viem/Actions/amm.js +12 -32
- package/dist/viem/Actions/amm.js.map +1 -1
- package/dist/viem/Decorator.d.ts +193 -16
- package/dist/viem/Decorator.d.ts.map +1 -1
- package/dist/viem/Decorator.js +7 -0
- package/dist/viem/Decorator.js.map +1 -1
- package/dist/wagmi/Actions/amm.d.ts +6 -16
- package/dist/wagmi/Actions/amm.d.ts.map +1 -1
- package/dist/wagmi/Actions/amm.js +6 -16
- package/dist/wagmi/Actions/amm.js.map +1 -1
- package/dist/wagmi/Hooks/amm.d.ts +6 -16
- package/dist/wagmi/Hooks/amm.d.ts.map +1 -1
- package/dist/wagmi/Hooks/amm.js +6 -16
- package/dist/wagmi/Hooks/amm.js.map +1 -1
- package/package.json +1 -1
- package/src/viem/Actions/amm.test.ts +220 -1
- package/src/viem/Actions/amm.ts +12 -32
- package/src/viem/Decorator.ts +214 -16
- package/src/wagmi/Actions/amm.test.ts +93 -2
- package/src/wagmi/Actions/amm.ts +6 -16
- package/src/wagmi/Hooks/amm.test.ts +335 -0
- package/src/wagmi/Hooks/amm.ts +6 -16
|
@@ -165,6 +165,246 @@ describe('useMintSync', () => {
|
|
|
165
165
|
})
|
|
166
166
|
})
|
|
167
167
|
|
|
168
|
+
describe('useBurnSync', () => {
|
|
169
|
+
test('default', async () => {
|
|
170
|
+
const { result } = await renderHook(() => ({
|
|
171
|
+
connect: useConnect(),
|
|
172
|
+
createSync: tokenHooks.useCreateSync(),
|
|
173
|
+
grantRolesSync: tokenHooks.useGrantRolesSync(),
|
|
174
|
+
mintTokenSync: tokenHooks.useMintSync(),
|
|
175
|
+
mintSync: hooks.useMintSync(),
|
|
176
|
+
burnSync: hooks.useBurnSync(),
|
|
177
|
+
transferSync: tokenHooks.useTransferSync(),
|
|
178
|
+
getLiquidityBalance: hooks.useLiquidityBalance,
|
|
179
|
+
}))
|
|
180
|
+
|
|
181
|
+
await result.current.connect.connectAsync({
|
|
182
|
+
connector: config.connectors[0]!,
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
// Create a new token for testing
|
|
186
|
+
const { token } = await result.current.createSync.mutateAsync({
|
|
187
|
+
name: 'Test Token 5',
|
|
188
|
+
symbol: 'TEST5',
|
|
189
|
+
currency: 'USD',
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
// Grant issuer role to mint tokens
|
|
193
|
+
await result.current.grantRolesSync.mutateAsync({
|
|
194
|
+
token,
|
|
195
|
+
roles: ['issuer'],
|
|
196
|
+
to: account.address,
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
// Mint some tokens to account
|
|
200
|
+
await result.current.mintTokenSync.mutateAsync({
|
|
201
|
+
to: account.address,
|
|
202
|
+
amount: parseUnits('1000', 6),
|
|
203
|
+
token,
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
// Add liquidity to pool
|
|
207
|
+
await result.current.mintSync.mutateAsync({
|
|
208
|
+
userTokenAddress: token,
|
|
209
|
+
validatorTokenAddress: addresses.alphaUsd,
|
|
210
|
+
validatorTokenAmount: parseUnits('100', 6),
|
|
211
|
+
to: account.address,
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
// TODO(TEMPO-1183): Remove this janky fix to get some user token in the pool
|
|
215
|
+
await result.current.transferSync.mutateAsync({
|
|
216
|
+
to: '0x30D861999070Ae03B9548501DBd573E11A9f59Ee',
|
|
217
|
+
amount: 600n,
|
|
218
|
+
token: token,
|
|
219
|
+
feeToken: token,
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
// Get LP balance before burn
|
|
223
|
+
const { result: balanceResult } = await renderHook(() =>
|
|
224
|
+
result.current.getLiquidityBalance({
|
|
225
|
+
userToken: token,
|
|
226
|
+
validatorToken: addresses.alphaUsd,
|
|
227
|
+
address: account.address,
|
|
228
|
+
}),
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
await vi.waitFor(() => expect(balanceResult.current.isSuccess).toBeTruthy())
|
|
232
|
+
|
|
233
|
+
const lpBalanceBefore = balanceResult.current.data!
|
|
234
|
+
|
|
235
|
+
// Burn half of LP tokens
|
|
236
|
+
const data = await result.current.burnSync.mutateAsync({
|
|
237
|
+
userToken: token,
|
|
238
|
+
validatorToken: addresses.alphaUsd,
|
|
239
|
+
liquidity: lpBalanceBefore / 2n,
|
|
240
|
+
to: account.address,
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
await vi.waitFor(() =>
|
|
244
|
+
expect(result.current.burnSync.isSuccess).toBeTruthy(),
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
expect(data.receipt).toBeDefined()
|
|
248
|
+
expect(data.liquidity).toBe(lpBalanceBefore / 2n)
|
|
249
|
+
})
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
describe('useRebalanceSwapSync', () => {
|
|
253
|
+
test('default', async () => {
|
|
254
|
+
const { result } = await renderHook(() => ({
|
|
255
|
+
connect: useConnect(),
|
|
256
|
+
createSync: tokenHooks.useCreateSync(),
|
|
257
|
+
grantRolesSync: tokenHooks.useGrantRolesSync(),
|
|
258
|
+
mintTokenSync: tokenHooks.useMintSync(),
|
|
259
|
+
mintSync: hooks.useMintSync(),
|
|
260
|
+
transferSync: tokenHooks.useTransferSync(),
|
|
261
|
+
rebalanceSwapSync: hooks.useRebalanceSwapSync(),
|
|
262
|
+
}))
|
|
263
|
+
|
|
264
|
+
await result.current.connect.connectAsync({
|
|
265
|
+
connector: config.connectors[0]!,
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
// Create a new token for testing
|
|
269
|
+
const { token } = await result.current.createSync.mutateAsync({
|
|
270
|
+
name: 'Test Token 6',
|
|
271
|
+
symbol: 'TEST6',
|
|
272
|
+
currency: 'USD',
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
// Grant issuer role to mint tokens
|
|
276
|
+
await result.current.grantRolesSync.mutateAsync({
|
|
277
|
+
token,
|
|
278
|
+
roles: ['issuer'],
|
|
279
|
+
to: account.address,
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
// Mint some tokens to account
|
|
283
|
+
await result.current.mintTokenSync.mutateAsync({
|
|
284
|
+
to: account.address,
|
|
285
|
+
amount: parseUnits('1000', 6),
|
|
286
|
+
token,
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
// Add liquidity to pool
|
|
290
|
+
await result.current.mintSync.mutateAsync({
|
|
291
|
+
userTokenAddress: token,
|
|
292
|
+
validatorTokenAddress: addresses.alphaUsd,
|
|
293
|
+
validatorTokenAmount: parseUnits('100', 6),
|
|
294
|
+
to: account.address,
|
|
295
|
+
})
|
|
296
|
+
|
|
297
|
+
// TODO(TEMPO-1183): Remove this janky fix to get some user token in the pool
|
|
298
|
+
await result.current.transferSync.mutateAsync({
|
|
299
|
+
to: '0x30D861999070Ae03B9548501DBd573E11A9f59Ee',
|
|
300
|
+
amount: 600n,
|
|
301
|
+
token: token,
|
|
302
|
+
feeToken: token,
|
|
303
|
+
})
|
|
304
|
+
|
|
305
|
+
const account2 = accounts[1]
|
|
306
|
+
|
|
307
|
+
// Perform rebalance swap
|
|
308
|
+
const data = await result.current.rebalanceSwapSync.mutateAsync({
|
|
309
|
+
userToken: token,
|
|
310
|
+
validatorToken: addresses.alphaUsd,
|
|
311
|
+
amountOut: 100n,
|
|
312
|
+
to: account2.address,
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
await vi.waitFor(() =>
|
|
316
|
+
expect(result.current.rebalanceSwapSync.isSuccess).toBeTruthy(),
|
|
317
|
+
)
|
|
318
|
+
|
|
319
|
+
expect(data.receipt).toBeDefined()
|
|
320
|
+
expect(data.amountOut).toBe(100n)
|
|
321
|
+
expect(data.swapper).toBe(account.address)
|
|
322
|
+
})
|
|
323
|
+
})
|
|
324
|
+
|
|
325
|
+
describe('useWatchRebalanceSwap', () => {
|
|
326
|
+
test('default', async () => {
|
|
327
|
+
const { result: connectResult } = await renderHook(() => ({
|
|
328
|
+
connect: useConnect(),
|
|
329
|
+
createSync: tokenHooks.useCreateSync(),
|
|
330
|
+
grantRolesSync: tokenHooks.useGrantRolesSync(),
|
|
331
|
+
mintTokenSync: tokenHooks.useMintSync(),
|
|
332
|
+
mintSync: hooks.useMintSync(),
|
|
333
|
+
transferSync: tokenHooks.useTransferSync(),
|
|
334
|
+
rebalanceSwapSync: hooks.useRebalanceSwapSync(),
|
|
335
|
+
}))
|
|
336
|
+
|
|
337
|
+
await connectResult.current.connect.connectAsync({
|
|
338
|
+
connector: config.connectors[0]!,
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
// Create a new token for testing
|
|
342
|
+
const { token } = await connectResult.current.createSync.mutateAsync({
|
|
343
|
+
name: 'Test Token 3',
|
|
344
|
+
symbol: 'TEST3',
|
|
345
|
+
currency: 'USD',
|
|
346
|
+
})
|
|
347
|
+
|
|
348
|
+
// Grant issuer role to mint tokens
|
|
349
|
+
await connectResult.current.grantRolesSync.mutateAsync({
|
|
350
|
+
token,
|
|
351
|
+
roles: ['issuer'],
|
|
352
|
+
to: account.address,
|
|
353
|
+
})
|
|
354
|
+
|
|
355
|
+
// Mint some tokens to account
|
|
356
|
+
await connectResult.current.mintTokenSync.mutateAsync({
|
|
357
|
+
to: account.address,
|
|
358
|
+
amount: parseUnits('1000', 6),
|
|
359
|
+
token,
|
|
360
|
+
})
|
|
361
|
+
|
|
362
|
+
// Add liquidity to pool
|
|
363
|
+
await connectResult.current.mintSync.mutateAsync({
|
|
364
|
+
userTokenAddress: token,
|
|
365
|
+
validatorTokenAddress: addresses.alphaUsd,
|
|
366
|
+
validatorTokenAmount: parseUnits('100', 6),
|
|
367
|
+
to: account.address,
|
|
368
|
+
})
|
|
369
|
+
|
|
370
|
+
// TODO(TEMPO-1183): Remove this janky fix to get some user token in the pool
|
|
371
|
+
await connectResult.current.transferSync.mutateAsync({
|
|
372
|
+
to: '0x30D861999070Ae03B9548501DBd573E11A9f59Ee',
|
|
373
|
+
amount: 600n,
|
|
374
|
+
token: token,
|
|
375
|
+
feeToken: token,
|
|
376
|
+
})
|
|
377
|
+
|
|
378
|
+
const events: any[] = []
|
|
379
|
+
await renderHook(() =>
|
|
380
|
+
hooks.useWatchRebalanceSwap({
|
|
381
|
+
onRebalanceSwap(args) {
|
|
382
|
+
events.push(args)
|
|
383
|
+
},
|
|
384
|
+
}),
|
|
385
|
+
)
|
|
386
|
+
|
|
387
|
+
const account2 = accounts[1]
|
|
388
|
+
|
|
389
|
+
// Perform rebalance swap
|
|
390
|
+
await connectResult.current.rebalanceSwapSync.mutateAsync({
|
|
391
|
+
userToken: token,
|
|
392
|
+
validatorToken: addresses.alphaUsd,
|
|
393
|
+
amountOut: 100n,
|
|
394
|
+
to: account2.address,
|
|
395
|
+
})
|
|
396
|
+
|
|
397
|
+
await vi.waitUntil(() => events.length >= 1)
|
|
398
|
+
|
|
399
|
+
expect(events.length).toBeGreaterThanOrEqual(1)
|
|
400
|
+
expect(events[0]?.userToken.toLowerCase()).toBe(token.toLowerCase())
|
|
401
|
+
expect(events[0]?.validatorToken.toLowerCase()).toBe(
|
|
402
|
+
addresses.alphaUsd.toLowerCase(),
|
|
403
|
+
)
|
|
404
|
+
expect(events[0]?.amountOut).toBe(100n)
|
|
405
|
+
})
|
|
406
|
+
})
|
|
407
|
+
|
|
168
408
|
describe('useWatchMint', () => {
|
|
169
409
|
test('default', async () => {
|
|
170
410
|
const { result: connectResult } = await renderHook(() => ({
|
|
@@ -227,3 +467,98 @@ describe('useWatchMint', () => {
|
|
|
227
467
|
expect(events[0]?.validatorToken.amount).toBe(parseUnits('100', 6))
|
|
228
468
|
})
|
|
229
469
|
})
|
|
470
|
+
|
|
471
|
+
describe('useWatchBurn', () => {
|
|
472
|
+
test('default', async () => {
|
|
473
|
+
const { result: connectResult } = await renderHook(() => ({
|
|
474
|
+
connect: useConnect(),
|
|
475
|
+
createSync: tokenHooks.useCreateSync(),
|
|
476
|
+
grantRolesSync: tokenHooks.useGrantRolesSync(),
|
|
477
|
+
mintTokenSync: tokenHooks.useMintSync(),
|
|
478
|
+
mintSync: hooks.useMintSync(),
|
|
479
|
+
burnSync: hooks.useBurnSync(),
|
|
480
|
+
transferSync: tokenHooks.useTransferSync(),
|
|
481
|
+
getLiquidityBalance: hooks.useLiquidityBalance,
|
|
482
|
+
}))
|
|
483
|
+
|
|
484
|
+
await connectResult.current.connect.connectAsync({
|
|
485
|
+
connector: config.connectors[0]!,
|
|
486
|
+
})
|
|
487
|
+
|
|
488
|
+
// Create a new token for testing
|
|
489
|
+
const { token } = await connectResult.current.createSync.mutateAsync({
|
|
490
|
+
name: 'Test Token 4',
|
|
491
|
+
symbol: 'TEST4',
|
|
492
|
+
currency: 'USD',
|
|
493
|
+
})
|
|
494
|
+
|
|
495
|
+
// Grant issuer role to mint tokens
|
|
496
|
+
await connectResult.current.grantRolesSync.mutateAsync({
|
|
497
|
+
token,
|
|
498
|
+
roles: ['issuer'],
|
|
499
|
+
to: account.address,
|
|
500
|
+
})
|
|
501
|
+
|
|
502
|
+
// Mint some tokens to account
|
|
503
|
+
await connectResult.current.mintTokenSync.mutateAsync({
|
|
504
|
+
to: account.address,
|
|
505
|
+
amount: parseUnits('1000', 6),
|
|
506
|
+
token,
|
|
507
|
+
})
|
|
508
|
+
|
|
509
|
+
// Add liquidity to pool
|
|
510
|
+
await connectResult.current.mintSync.mutateAsync({
|
|
511
|
+
userTokenAddress: token,
|
|
512
|
+
validatorTokenAddress: addresses.alphaUsd,
|
|
513
|
+
validatorTokenAmount: parseUnits('100', 6),
|
|
514
|
+
to: account.address,
|
|
515
|
+
})
|
|
516
|
+
|
|
517
|
+
// TODO(TEMPO-1183): Remove this janky fix to get some user token in the pool
|
|
518
|
+
await connectResult.current.transferSync.mutateAsync({
|
|
519
|
+
to: '0x30D861999070Ae03B9548501DBd573E11A9f59Ee',
|
|
520
|
+
amount: 600n,
|
|
521
|
+
token: token,
|
|
522
|
+
feeToken: token,
|
|
523
|
+
})
|
|
524
|
+
|
|
525
|
+
// Get LP balance
|
|
526
|
+
const { result: balanceResult } = await renderHook(() =>
|
|
527
|
+
connectResult.current.getLiquidityBalance({
|
|
528
|
+
userToken: token,
|
|
529
|
+
validatorToken: addresses.alphaUsd,
|
|
530
|
+
address: account.address,
|
|
531
|
+
}),
|
|
532
|
+
)
|
|
533
|
+
|
|
534
|
+
await vi.waitFor(() => expect(balanceResult.current.isSuccess).toBeTruthy())
|
|
535
|
+
|
|
536
|
+
const lpBalance = balanceResult.current.data!
|
|
537
|
+
|
|
538
|
+
const events: any[] = []
|
|
539
|
+
await renderHook(() =>
|
|
540
|
+
hooks.useWatchBurn({
|
|
541
|
+
onBurn(args) {
|
|
542
|
+
events.push(args)
|
|
543
|
+
},
|
|
544
|
+
}),
|
|
545
|
+
)
|
|
546
|
+
|
|
547
|
+
// Burn LP tokens
|
|
548
|
+
await connectResult.current.burnSync.mutateAsync({
|
|
549
|
+
userToken: token,
|
|
550
|
+
validatorToken: addresses.alphaUsd,
|
|
551
|
+
liquidity: lpBalance / 2n,
|
|
552
|
+
to: account.address,
|
|
553
|
+
})
|
|
554
|
+
|
|
555
|
+
await vi.waitUntil(() => events.length >= 1)
|
|
556
|
+
|
|
557
|
+
expect(events.length).toBeGreaterThanOrEqual(1)
|
|
558
|
+
expect(events[0]?.userToken.toLowerCase()).toBe(token.toLowerCase())
|
|
559
|
+
expect(events[0]?.validatorToken.toLowerCase()).toBe(
|
|
560
|
+
addresses.alphaUsd.toLowerCase(),
|
|
561
|
+
)
|
|
562
|
+
expect(events[0]?.liquidity).toBe(lpBalance / 2n)
|
|
563
|
+
})
|
|
564
|
+
})
|
package/src/wagmi/Hooks/amm.ts
CHANGED
|
@@ -319,14 +319,9 @@ export declare namespace useRebalanceSwapSync {
|
|
|
319
319
|
* <button
|
|
320
320
|
* onClick={() =>
|
|
321
321
|
* mutate({
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
* },
|
|
326
|
-
* validatorToken: {
|
|
327
|
-
* address: '0x20c0...babe',
|
|
328
|
-
* amount: 100n,
|
|
329
|
-
* },
|
|
322
|
+
* userTokenAddress: '0x20c0...beef',
|
|
323
|
+
* validatorTokenAddress: '0x20c0...babe',
|
|
324
|
+
* validatorTokenAmount: 100n,
|
|
330
325
|
* to: '0xfeed...fede',
|
|
331
326
|
* })
|
|
332
327
|
* }
|
|
@@ -401,14 +396,9 @@ export declare namespace useMint {
|
|
|
401
396
|
* <button
|
|
402
397
|
* onClick={() =>
|
|
403
398
|
* mutate({
|
|
404
|
-
*
|
|
405
|
-
*
|
|
406
|
-
*
|
|
407
|
-
* },
|
|
408
|
-
* validatorToken: {
|
|
409
|
-
* address: '0x20c0...babe',
|
|
410
|
-
* amount: 100n,
|
|
411
|
-
* },
|
|
399
|
+
* userTokenAddress: '0x20c0...beef',
|
|
400
|
+
* validatorTokenAddress: '0x20c0...babe',
|
|
401
|
+
* validatorTokenAmount: 100n,
|
|
412
402
|
* to: '0xfeed...fede',
|
|
413
403
|
* })
|
|
414
404
|
* }
|