tempo.ts 0.7.0 → 0.7.2
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 +38 -0
- package/dist/server/Handler.d.ts +12 -2
- package/dist/server/Handler.d.ts.map +1 -1
- package/dist/server/Handler.js +21 -3
- package/dist/server/Handler.js.map +1 -1
- package/dist/viem/Actions/amm.d.ts +1213 -51
- package/dist/viem/Actions/amm.d.ts.map +1 -1
- package/dist/viem/Actions/amm.js +452 -0
- package/dist/viem/Actions/amm.js.map +1 -1
- package/dist/wagmi/Actions/amm.d.ts +225 -0
- package/dist/wagmi/Actions/amm.d.ts.map +1 -1
- package/dist/wagmi/Actions/amm.js +248 -0
- package/dist/wagmi/Actions/amm.js.map +1 -1
- package/dist/wagmi/Hooks/amm.d.ts +236 -0
- package/dist/wagmi/Hooks/amm.d.ts.map +1 -1
- package/dist/wagmi/Hooks/amm.js +285 -0
- package/dist/wagmi/Hooks/amm.js.map +1 -1
- package/package.json +1 -1
- package/src/server/Handler.test.ts +223 -0
- package/src/server/Handler.ts +41 -3
- package/src/viem/Actions/amm.ts +672 -0
- package/src/wagmi/Actions/amm.ts +346 -0
- package/src/wagmi/Hooks/amm.ts +443 -0
package/src/viem/Actions/amm.ts
CHANGED
|
@@ -219,6 +219,226 @@ export namespace getLiquidityBalance {
|
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
+
/**
|
|
223
|
+
* Performs a rebalance swap from validator token to user token.
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```ts
|
|
227
|
+
* import { createClient, http } from 'viem'
|
|
228
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
229
|
+
* import { Actions } from 'tempo.ts/viem'
|
|
230
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
231
|
+
*
|
|
232
|
+
* const client = createClient({
|
|
233
|
+
* account: privateKeyToAccount('0x...'),
|
|
234
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
235
|
+
* transport: http(),
|
|
236
|
+
* })
|
|
237
|
+
*
|
|
238
|
+
* const hash = await Actions.amm.rebalanceSwap(client, {
|
|
239
|
+
* userToken: '0x...',
|
|
240
|
+
* validatorToken: '0x...',
|
|
241
|
+
* amountOut: 100n,
|
|
242
|
+
* to: '0x...',
|
|
243
|
+
* })
|
|
244
|
+
* ```
|
|
245
|
+
*
|
|
246
|
+
* @param client - Client.
|
|
247
|
+
* @param parameters - Parameters.
|
|
248
|
+
* @returns The transaction hash.
|
|
249
|
+
*/
|
|
250
|
+
export async function rebalanceSwap<
|
|
251
|
+
chain extends Chain | undefined,
|
|
252
|
+
account extends Account | undefined,
|
|
253
|
+
>(
|
|
254
|
+
client: Client<Transport, chain, account>,
|
|
255
|
+
parameters: rebalanceSwap.Parameters<chain, account>,
|
|
256
|
+
): Promise<rebalanceSwap.ReturnValue> {
|
|
257
|
+
return rebalanceSwap.inner(writeContract, client, parameters)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export namespace rebalanceSwap {
|
|
261
|
+
export type Parameters<
|
|
262
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
263
|
+
account extends Account | undefined = Account | undefined,
|
|
264
|
+
> = WriteParameters<chain, account> & Args
|
|
265
|
+
|
|
266
|
+
export type Args = {
|
|
267
|
+
/** Amount of user token to receive. */
|
|
268
|
+
amountOut: bigint
|
|
269
|
+
/** Address to send the user token to. */
|
|
270
|
+
to: Address
|
|
271
|
+
/** Address or ID of the user token. */
|
|
272
|
+
userToken: TokenId.TokenIdOrAddress
|
|
273
|
+
/** Address or ID of the validator token. */
|
|
274
|
+
validatorToken: TokenId.TokenIdOrAddress
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export type ReturnValue = WriteContractReturnType
|
|
278
|
+
|
|
279
|
+
/** @internal */
|
|
280
|
+
export async function inner<
|
|
281
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
282
|
+
chain extends Chain | undefined,
|
|
283
|
+
account extends Account | undefined,
|
|
284
|
+
>(
|
|
285
|
+
action: action,
|
|
286
|
+
client: Client<Transport, chain, account>,
|
|
287
|
+
parameters: rebalanceSwap.Parameters<chain, account>,
|
|
288
|
+
): Promise<ReturnType<action>> {
|
|
289
|
+
const { userToken, validatorToken, amountOut, to, ...rest } = parameters
|
|
290
|
+
const call = rebalanceSwap.call({
|
|
291
|
+
userToken,
|
|
292
|
+
validatorToken,
|
|
293
|
+
amountOut,
|
|
294
|
+
to,
|
|
295
|
+
})
|
|
296
|
+
return (await action(client, {
|
|
297
|
+
...rest,
|
|
298
|
+
...call,
|
|
299
|
+
} as never)) as never
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Defines a call to the `rebalanceSwap` function.
|
|
304
|
+
*
|
|
305
|
+
* Can be passed as a parameter to:
|
|
306
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
307
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
308
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* ```ts
|
|
312
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
313
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
314
|
+
* import { Actions } from 'tempo.ts/viem'
|
|
315
|
+
*
|
|
316
|
+
* const client = createClient({
|
|
317
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
318
|
+
* transport: http(),
|
|
319
|
+
* }).extend(walletActions)
|
|
320
|
+
*
|
|
321
|
+
* const { result } = await client.sendCalls({
|
|
322
|
+
* calls: [
|
|
323
|
+
* actions.amm.rebalanceSwap.call({
|
|
324
|
+
* userToken: '0x20c0...beef',
|
|
325
|
+
* validatorToken: '0x20c0...babe',
|
|
326
|
+
* amountOut: 100n,
|
|
327
|
+
* to: '0xfeed...fede',
|
|
328
|
+
* }),
|
|
329
|
+
* actions.amm.rebalanceSwap.call({
|
|
330
|
+
* userToken: '0x20c0...babe',
|
|
331
|
+
* validatorToken: '0x20c0...babe',
|
|
332
|
+
* amountOut: 100n,
|
|
333
|
+
* to: '0xfeed...fede',
|
|
334
|
+
* }),
|
|
335
|
+
* ]
|
|
336
|
+
* })
|
|
337
|
+
* ```
|
|
338
|
+
*
|
|
339
|
+
* @param args - Arguments.
|
|
340
|
+
* @returns The call.
|
|
341
|
+
*/
|
|
342
|
+
export function call(args: Args) {
|
|
343
|
+
const { userToken, validatorToken, amountOut, to } = args
|
|
344
|
+
return defineCall({
|
|
345
|
+
address: Addresses.feeManager,
|
|
346
|
+
abi: Abis.feeAmm,
|
|
347
|
+
functionName: 'rebalanceSwap',
|
|
348
|
+
args: [
|
|
349
|
+
TokenId.toAddress(userToken),
|
|
350
|
+
TokenId.toAddress(validatorToken),
|
|
351
|
+
amountOut,
|
|
352
|
+
to,
|
|
353
|
+
],
|
|
354
|
+
})
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Extracts the `RebalanceSwap` event from logs.
|
|
359
|
+
*
|
|
360
|
+
* @param logs - The logs.
|
|
361
|
+
* @returns The `RebalanceSwap` event.
|
|
362
|
+
*/
|
|
363
|
+
export function extractEvent(logs: Log[]) {
|
|
364
|
+
const [log] = parseEventLogs({
|
|
365
|
+
abi: Abis.feeAmm,
|
|
366
|
+
logs,
|
|
367
|
+
eventName: 'RebalanceSwap',
|
|
368
|
+
strict: true,
|
|
369
|
+
})
|
|
370
|
+
if (!log) throw new Error('`RebalanceSwap` event not found.')
|
|
371
|
+
return log
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Performs a rebalance swap from validator token to user token.
|
|
377
|
+
*
|
|
378
|
+
* @example
|
|
379
|
+
* ```ts
|
|
380
|
+
* import { createClient, http } from 'viem'
|
|
381
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
382
|
+
* import { Actions } from 'tempo.ts/viem'
|
|
383
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
384
|
+
*
|
|
385
|
+
* const client = createClient({
|
|
386
|
+
* account: privateKeyToAccount('0x...'),
|
|
387
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
388
|
+
* transport: http(),
|
|
389
|
+
* })
|
|
390
|
+
*
|
|
391
|
+
* const result = await Actions.amm.rebalanceSwapSync(client, {
|
|
392
|
+
* userToken: '0x...',
|
|
393
|
+
* validatorToken: '0x...',
|
|
394
|
+
* amountOut: 100n,
|
|
395
|
+
* to: '0x...',
|
|
396
|
+
* })
|
|
397
|
+
* ```
|
|
398
|
+
*
|
|
399
|
+
* @param client - Client.
|
|
400
|
+
* @param parameters - Parameters.
|
|
401
|
+
* @returns The transaction receipt and event data.
|
|
402
|
+
*/
|
|
403
|
+
export async function rebalanceSwapSync<
|
|
404
|
+
chain extends Chain | undefined,
|
|
405
|
+
account extends Account | undefined,
|
|
406
|
+
>(
|
|
407
|
+
client: Client<Transport, chain, account>,
|
|
408
|
+
parameters: rebalanceSwapSync.Parameters<chain, account>,
|
|
409
|
+
): Promise<rebalanceSwapSync.ReturnValue> {
|
|
410
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
411
|
+
const receipt = await rebalanceSwap.inner(writeContractSync, client, {
|
|
412
|
+
...rest,
|
|
413
|
+
throwOnReceiptRevert,
|
|
414
|
+
} as never)
|
|
415
|
+
const { args } = rebalanceSwap.extractEvent(receipt.logs)
|
|
416
|
+
return {
|
|
417
|
+
...args,
|
|
418
|
+
receipt,
|
|
419
|
+
} as never
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
export namespace rebalanceSwapSync {
|
|
423
|
+
export type Parameters<
|
|
424
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
425
|
+
account extends Account | undefined = Account | undefined,
|
|
426
|
+
> = rebalanceSwap.Parameters<chain, account>
|
|
427
|
+
|
|
428
|
+
export type Args = rebalanceSwap.Args
|
|
429
|
+
|
|
430
|
+
export type ReturnValue = Compute<
|
|
431
|
+
GetEventArgs<
|
|
432
|
+
typeof Abis.feeAmm,
|
|
433
|
+
'RebalanceSwap',
|
|
434
|
+
{ IndexedOnly: false; Required: true }
|
|
435
|
+
> & {
|
|
436
|
+
/** Transaction receipt. */
|
|
437
|
+
receipt: TransactionReceipt
|
|
438
|
+
}
|
|
439
|
+
>
|
|
440
|
+
}
|
|
441
|
+
|
|
222
442
|
/**
|
|
223
443
|
* Adds liquidity to a pool.
|
|
224
444
|
*
|
|
@@ -470,6 +690,381 @@ export namespace mintSync {
|
|
|
470
690
|
>
|
|
471
691
|
}
|
|
472
692
|
|
|
693
|
+
/**
|
|
694
|
+
* Removes liquidity from a pool.
|
|
695
|
+
*
|
|
696
|
+
* @example
|
|
697
|
+
* ```ts
|
|
698
|
+
* import { createClient, http } from 'viem'
|
|
699
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
700
|
+
* import { Actions } from 'tempo.ts/viem'
|
|
701
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
702
|
+
*
|
|
703
|
+
* const client = createClient({
|
|
704
|
+
* account: privateKeyToAccount('0x...'),
|
|
705
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
706
|
+
* transport: http(),
|
|
707
|
+
* })
|
|
708
|
+
*
|
|
709
|
+
* const hash = await Actions.amm.burn(client, {
|
|
710
|
+
* userToken: '0x20c0...beef',
|
|
711
|
+
* validatorToken: '0x20c0...babe',
|
|
712
|
+
* liquidity: 50n,
|
|
713
|
+
* to: '0xfeed...fede',
|
|
714
|
+
* })
|
|
715
|
+
* ```
|
|
716
|
+
*
|
|
717
|
+
* @param client - Client.
|
|
718
|
+
* @param parameters - Parameters.
|
|
719
|
+
* @returns The transaction hash.
|
|
720
|
+
*/
|
|
721
|
+
export async function burn<
|
|
722
|
+
chain extends Chain | undefined,
|
|
723
|
+
account extends Account | undefined,
|
|
724
|
+
>(
|
|
725
|
+
client: Client<Transport, chain, account>,
|
|
726
|
+
parameters: burn.Parameters<chain, account>,
|
|
727
|
+
): Promise<burn.ReturnValue> {
|
|
728
|
+
return burn.inner(writeContract, client, parameters)
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
export namespace burn {
|
|
732
|
+
export type Parameters<
|
|
733
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
734
|
+
account extends Account | undefined = Account | undefined,
|
|
735
|
+
> = WriteParameters<chain, account> & Args
|
|
736
|
+
|
|
737
|
+
export type Args = {
|
|
738
|
+
/** Amount of LP tokens to burn. */
|
|
739
|
+
liquidity: bigint
|
|
740
|
+
/** Address to send tokens to. */
|
|
741
|
+
to: Address
|
|
742
|
+
/** Address or ID of the user token. */
|
|
743
|
+
userToken: TokenId.TokenIdOrAddress
|
|
744
|
+
/** Address or ID of the validator token. */
|
|
745
|
+
validatorToken: TokenId.TokenIdOrAddress
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
export type ReturnValue = WriteContractReturnType
|
|
749
|
+
|
|
750
|
+
/** @internal */
|
|
751
|
+
export async function inner<
|
|
752
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
753
|
+
chain extends Chain | undefined,
|
|
754
|
+
account extends Account | undefined,
|
|
755
|
+
>(
|
|
756
|
+
action: action,
|
|
757
|
+
client: Client<Transport, chain, account>,
|
|
758
|
+
parameters: burn.Parameters<chain, account>,
|
|
759
|
+
): Promise<ReturnType<action>> {
|
|
760
|
+
const { liquidity, to, userToken, validatorToken, ...rest } = parameters
|
|
761
|
+
const call = burn.call({ liquidity, to, userToken, validatorToken })
|
|
762
|
+
return (await action(client, {
|
|
763
|
+
...rest,
|
|
764
|
+
...call,
|
|
765
|
+
} as never)) as never
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
/**
|
|
769
|
+
* Defines a call to the `burn` function.
|
|
770
|
+
*
|
|
771
|
+
* Can be passed as a parameter to:
|
|
772
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
773
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
774
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
775
|
+
*
|
|
776
|
+
* @example
|
|
777
|
+
* ```ts
|
|
778
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
779
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
780
|
+
* import { Actions } from 'tempo.ts/viem'
|
|
781
|
+
*
|
|
782
|
+
* const client = createClient({
|
|
783
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
784
|
+
* transport: http(),
|
|
785
|
+
* }).extend(walletActions)
|
|
786
|
+
*
|
|
787
|
+
* const { result } = await client.sendCalls({
|
|
788
|
+
* calls: [
|
|
789
|
+
* actions.amm.burn.call({
|
|
790
|
+
* liquidity: 100n,
|
|
791
|
+
* to: '0xfeed...fede',
|
|
792
|
+
* userToken: '0x20c0...beef',
|
|
793
|
+
* validatorToken: '0x20c0...babe',
|
|
794
|
+
* }),
|
|
795
|
+
* actions.amm.burn.call({
|
|
796
|
+
* liquidity: 100n,
|
|
797
|
+
* to: '0xfeed...fede',
|
|
798
|
+
* userToken: '0x20c0...babe',
|
|
799
|
+
* validatorToken: '0x20c0...babe',
|
|
800
|
+
* }),
|
|
801
|
+
* ]
|
|
802
|
+
* })
|
|
803
|
+
* ```
|
|
804
|
+
*
|
|
805
|
+
* @param args - Arguments.
|
|
806
|
+
* @returns The call.
|
|
807
|
+
*/
|
|
808
|
+
export function call(args: Args) {
|
|
809
|
+
const { liquidity, to, userToken, validatorToken } = args
|
|
810
|
+
return defineCall({
|
|
811
|
+
address: Addresses.feeManager,
|
|
812
|
+
abi: Abis.feeAmm,
|
|
813
|
+
functionName: 'burn',
|
|
814
|
+
args: [
|
|
815
|
+
TokenId.toAddress(userToken),
|
|
816
|
+
TokenId.toAddress(validatorToken),
|
|
817
|
+
liquidity,
|
|
818
|
+
to,
|
|
819
|
+
],
|
|
820
|
+
})
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* Extracts the `Burn` event from logs.
|
|
825
|
+
*
|
|
826
|
+
* @param logs - The logs.
|
|
827
|
+
* @returns The `Burn` event.
|
|
828
|
+
*/
|
|
829
|
+
export function extractEvent(logs: Log[]) {
|
|
830
|
+
const [log] = parseEventLogs({
|
|
831
|
+
abi: Abis.feeAmm,
|
|
832
|
+
logs,
|
|
833
|
+
eventName: 'Burn',
|
|
834
|
+
strict: true,
|
|
835
|
+
})
|
|
836
|
+
if (!log) throw new Error('`Burn` event not found.')
|
|
837
|
+
return log
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
/**
|
|
842
|
+
* Removes liquidity from a pool.
|
|
843
|
+
*
|
|
844
|
+
* @example
|
|
845
|
+
* ```ts
|
|
846
|
+
* import { createClient, http } from 'viem'
|
|
847
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
848
|
+
* import { Actions } from 'tempo.ts/viem'
|
|
849
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
850
|
+
*
|
|
851
|
+
* const client = createClient({
|
|
852
|
+
* account: privateKeyToAccount('0x...'),
|
|
853
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
854
|
+
* transport: http(),
|
|
855
|
+
* })
|
|
856
|
+
*
|
|
857
|
+
* const result = await Actions.amm.burnSync(client, {
|
|
858
|
+
* userToken: '0x20c0...beef',
|
|
859
|
+
* validatorToken: '0x20c0...babe',
|
|
860
|
+
* liquidity: 50n,
|
|
861
|
+
* to: '0xfeed...fede',
|
|
862
|
+
* })
|
|
863
|
+
* ```
|
|
864
|
+
*
|
|
865
|
+
* @param client - Client.
|
|
866
|
+
* @param parameters - Parameters.
|
|
867
|
+
* @returns The transaction receipt and event data.
|
|
868
|
+
*/
|
|
869
|
+
export async function burnSync<
|
|
870
|
+
chain extends Chain | undefined,
|
|
871
|
+
account extends Account | undefined,
|
|
872
|
+
>(
|
|
873
|
+
client: Client<Transport, chain, account>,
|
|
874
|
+
parameters: burnSync.Parameters<chain, account>,
|
|
875
|
+
): Promise<burnSync.ReturnValue> {
|
|
876
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
877
|
+
const receipt = await burn.inner(writeContractSync, client, {
|
|
878
|
+
...rest,
|
|
879
|
+
throwOnReceiptRevert,
|
|
880
|
+
} as never)
|
|
881
|
+
const { args } = burn.extractEvent(receipt.logs)
|
|
882
|
+
return {
|
|
883
|
+
...args,
|
|
884
|
+
receipt,
|
|
885
|
+
} as never
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
export namespace burnSync {
|
|
889
|
+
export type Parameters<
|
|
890
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
891
|
+
account extends Account | undefined = Account | undefined,
|
|
892
|
+
> = burn.Parameters<chain, account>
|
|
893
|
+
|
|
894
|
+
export type Args = burn.Args
|
|
895
|
+
|
|
896
|
+
export type ReturnValue = Compute<
|
|
897
|
+
GetEventArgs<
|
|
898
|
+
typeof Abis.feeAmm,
|
|
899
|
+
'Burn',
|
|
900
|
+
{ IndexedOnly: false; Required: true }
|
|
901
|
+
> & {
|
|
902
|
+
/** Transaction receipt. */
|
|
903
|
+
receipt: TransactionReceipt
|
|
904
|
+
}
|
|
905
|
+
>
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
/**
|
|
909
|
+
* Watches for rebalance swap events.
|
|
910
|
+
*
|
|
911
|
+
* @example
|
|
912
|
+
* ```ts
|
|
913
|
+
* import { createClient, http } from 'viem'
|
|
914
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
915
|
+
* import { Actions } from 'tempo.ts/viem'
|
|
916
|
+
*
|
|
917
|
+
* const client = createClient({
|
|
918
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
919
|
+
* transport: http(),
|
|
920
|
+
* })
|
|
921
|
+
*
|
|
922
|
+
* const unwatch = actions.amm.watchRebalanceSwap(client, {
|
|
923
|
+
* onRebalanceSwap: (args, log) => {
|
|
924
|
+
* console.log('Rebalance swap:', args)
|
|
925
|
+
* },
|
|
926
|
+
* })
|
|
927
|
+
* ```
|
|
928
|
+
*
|
|
929
|
+
* @param client - Client.
|
|
930
|
+
* @param parameters - Parameters.
|
|
931
|
+
* @returns A function to unsubscribe from the event.
|
|
932
|
+
*/
|
|
933
|
+
export function watchRebalanceSwap<
|
|
934
|
+
chain extends Chain | undefined,
|
|
935
|
+
account extends Account | undefined,
|
|
936
|
+
>(
|
|
937
|
+
client: Client<Transport, chain, account>,
|
|
938
|
+
parameters: watchRebalanceSwap.Parameters,
|
|
939
|
+
) {
|
|
940
|
+
const { onRebalanceSwap, userToken, validatorToken, ...rest } = parameters
|
|
941
|
+
return watchContractEvent(client, {
|
|
942
|
+
...rest,
|
|
943
|
+
address: Addresses.feeManager,
|
|
944
|
+
abi: Abis.feeAmm,
|
|
945
|
+
eventName: 'RebalanceSwap',
|
|
946
|
+
args:
|
|
947
|
+
userToken !== undefined && validatorToken !== undefined
|
|
948
|
+
? {
|
|
949
|
+
userToken: TokenId.toAddress(userToken),
|
|
950
|
+
validatorToken: TokenId.toAddress(validatorToken),
|
|
951
|
+
}
|
|
952
|
+
: undefined,
|
|
953
|
+
onLogs: (logs) => {
|
|
954
|
+
for (const log of logs) onRebalanceSwap(log.args, log)
|
|
955
|
+
},
|
|
956
|
+
strict: true,
|
|
957
|
+
})
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
export declare namespace watchRebalanceSwap {
|
|
961
|
+
export type Args = GetEventArgs<
|
|
962
|
+
typeof Abis.feeAmm,
|
|
963
|
+
'RebalanceSwap',
|
|
964
|
+
{ IndexedOnly: false; Required: true }
|
|
965
|
+
>
|
|
966
|
+
|
|
967
|
+
export type Log = viem_Log<
|
|
968
|
+
bigint,
|
|
969
|
+
number,
|
|
970
|
+
false,
|
|
971
|
+
ExtractAbiItem<typeof Abis.feeAmm, 'RebalanceSwap'>,
|
|
972
|
+
true
|
|
973
|
+
>
|
|
974
|
+
|
|
975
|
+
export type Parameters = UnionOmit<
|
|
976
|
+
WatchContractEventParameters<typeof Abis.feeAmm, 'RebalanceSwap', true>,
|
|
977
|
+
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
978
|
+
> & {
|
|
979
|
+
/** Callback to invoke when a rebalance swap occurs. */
|
|
980
|
+
onRebalanceSwap: (args: Args, log: Log) => void
|
|
981
|
+
/** Address or ID of the user token to filter events. */
|
|
982
|
+
userToken?: TokenId.TokenIdOrAddress | undefined
|
|
983
|
+
/** Address or ID of the validator token to filter events. */
|
|
984
|
+
validatorToken?: TokenId.TokenIdOrAddress | undefined
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
/**
|
|
989
|
+
* Watches for fee swap events.
|
|
990
|
+
*
|
|
991
|
+
* @example
|
|
992
|
+
* ```ts
|
|
993
|
+
* import { createClient, http } from 'viem'
|
|
994
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
995
|
+
* import { Actions } from 'tempo.ts/viem'
|
|
996
|
+
*
|
|
997
|
+
* const client = createClient({
|
|
998
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
999
|
+
* transport: http(),
|
|
1000
|
+
* })
|
|
1001
|
+
*
|
|
1002
|
+
* const unwatch = actions.amm.watchFeeSwap(client, {
|
|
1003
|
+
* onFeeSwap: (args, log) => {
|
|
1004
|
+
* console.log('Fee swap:', args)
|
|
1005
|
+
* },
|
|
1006
|
+
* })
|
|
1007
|
+
* ```
|
|
1008
|
+
*
|
|
1009
|
+
* @param client - Client.
|
|
1010
|
+
* @param parameters - Parameters.
|
|
1011
|
+
* @returns A function to unsubscribe from the event.
|
|
1012
|
+
*/
|
|
1013
|
+
export function watchFeeSwap<
|
|
1014
|
+
chain extends Chain | undefined,
|
|
1015
|
+
account extends Account | undefined,
|
|
1016
|
+
>(
|
|
1017
|
+
client: Client<Transport, chain, account>,
|
|
1018
|
+
parameters: watchFeeSwap.Parameters,
|
|
1019
|
+
) {
|
|
1020
|
+
const { onFeeSwap, userToken, validatorToken, ...rest } = parameters
|
|
1021
|
+
return watchContractEvent(client, {
|
|
1022
|
+
...rest,
|
|
1023
|
+
address: Addresses.feeManager,
|
|
1024
|
+
abi: Abis.feeAmm,
|
|
1025
|
+
eventName: 'FeeSwap',
|
|
1026
|
+
args:
|
|
1027
|
+
userToken !== undefined && validatorToken !== undefined
|
|
1028
|
+
? {
|
|
1029
|
+
userToken: TokenId.toAddress(userToken),
|
|
1030
|
+
validatorToken: TokenId.toAddress(validatorToken),
|
|
1031
|
+
}
|
|
1032
|
+
: undefined,
|
|
1033
|
+
onLogs: (logs) => {
|
|
1034
|
+
for (const log of logs) onFeeSwap(log.args, log)
|
|
1035
|
+
},
|
|
1036
|
+
strict: true,
|
|
1037
|
+
})
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
export declare namespace watchFeeSwap {
|
|
1041
|
+
export type Args = GetEventArgs<
|
|
1042
|
+
typeof Abis.feeAmm,
|
|
1043
|
+
'FeeSwap',
|
|
1044
|
+
{ IndexedOnly: false; Required: true }
|
|
1045
|
+
>
|
|
1046
|
+
|
|
1047
|
+
export type Log = viem_Log<
|
|
1048
|
+
bigint,
|
|
1049
|
+
number,
|
|
1050
|
+
false,
|
|
1051
|
+
ExtractAbiItem<typeof Abis.feeAmm, 'FeeSwap'>,
|
|
1052
|
+
true
|
|
1053
|
+
>
|
|
1054
|
+
|
|
1055
|
+
export type Parameters = UnionOmit<
|
|
1056
|
+
WatchContractEventParameters<typeof Abis.feeAmm, 'FeeSwap', true>,
|
|
1057
|
+
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
1058
|
+
> & {
|
|
1059
|
+
/** Callback to invoke when a fee swap occurs. */
|
|
1060
|
+
onFeeSwap: (args: Args, log: Log) => void
|
|
1061
|
+
/** Address or ID of the user token to filter events. */
|
|
1062
|
+
userToken?: TokenId.TokenIdOrAddress | undefined
|
|
1063
|
+
/** Address or ID of the validator token to filter events. */
|
|
1064
|
+
validatorToken?: TokenId.TokenIdOrAddress | undefined
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
|
|
473
1068
|
/**
|
|
474
1069
|
* Watches for liquidity mint events.
|
|
475
1070
|
*
|
|
@@ -574,3 +1169,80 @@ export declare namespace watchMint {
|
|
|
574
1169
|
validatorToken?: TokenId.TokenIdOrAddress | undefined
|
|
575
1170
|
}
|
|
576
1171
|
}
|
|
1172
|
+
|
|
1173
|
+
/**
|
|
1174
|
+
* Watches for liquidity burn events.
|
|
1175
|
+
*
|
|
1176
|
+
* @example
|
|
1177
|
+
* ```ts
|
|
1178
|
+
* import { createClient, http } from 'viem'
|
|
1179
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
1180
|
+
* import { Actions } from 'tempo.ts/viem'
|
|
1181
|
+
*
|
|
1182
|
+
* const client = createClient({
|
|
1183
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1184
|
+
* transport: http(),
|
|
1185
|
+
* })
|
|
1186
|
+
*
|
|
1187
|
+
* const unwatch = actions.amm.watchBurn(client, {
|
|
1188
|
+
* onBurn: (args, log) => {
|
|
1189
|
+
* console.log('Liquidity removed:', args)
|
|
1190
|
+
* },
|
|
1191
|
+
* })
|
|
1192
|
+
* ```
|
|
1193
|
+
*
|
|
1194
|
+
* @param client - Client.
|
|
1195
|
+
* @param parameters - Parameters.
|
|
1196
|
+
* @returns A function to unsubscribe from the event.
|
|
1197
|
+
*/
|
|
1198
|
+
export function watchBurn<
|
|
1199
|
+
chain extends Chain | undefined,
|
|
1200
|
+
account extends Account | undefined,
|
|
1201
|
+
>(client: Client<Transport, chain, account>, parameters: watchBurn.Parameters) {
|
|
1202
|
+
const { onBurn, userToken, validatorToken, ...rest } = parameters
|
|
1203
|
+
return watchContractEvent(client, {
|
|
1204
|
+
...rest,
|
|
1205
|
+
address: Addresses.feeManager,
|
|
1206
|
+
abi: Abis.feeAmm,
|
|
1207
|
+
eventName: 'Burn',
|
|
1208
|
+
args:
|
|
1209
|
+
userToken !== undefined && validatorToken !== undefined
|
|
1210
|
+
? {
|
|
1211
|
+
userToken: TokenId.toAddress(userToken),
|
|
1212
|
+
validatorToken: TokenId.toAddress(validatorToken),
|
|
1213
|
+
}
|
|
1214
|
+
: undefined,
|
|
1215
|
+
onLogs: (logs) => {
|
|
1216
|
+
for (const log of logs) onBurn(log.args, log)
|
|
1217
|
+
},
|
|
1218
|
+
strict: true,
|
|
1219
|
+
})
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
export declare namespace watchBurn {
|
|
1223
|
+
export type Args = GetEventArgs<
|
|
1224
|
+
typeof Abis.feeAmm,
|
|
1225
|
+
'Burn',
|
|
1226
|
+
{ IndexedOnly: false; Required: true }
|
|
1227
|
+
>
|
|
1228
|
+
|
|
1229
|
+
export type Log = viem_Log<
|
|
1230
|
+
bigint,
|
|
1231
|
+
number,
|
|
1232
|
+
false,
|
|
1233
|
+
ExtractAbiItem<typeof Abis.feeAmm, 'Burn'>,
|
|
1234
|
+
true
|
|
1235
|
+
>
|
|
1236
|
+
|
|
1237
|
+
export type Parameters = UnionOmit<
|
|
1238
|
+
WatchContractEventParameters<typeof Abis.feeAmm, 'Burn', true>,
|
|
1239
|
+
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
1240
|
+
> & {
|
|
1241
|
+
/** Callback to invoke when liquidity is removed. */
|
|
1242
|
+
onBurn: (args: Args, log: Log) => void
|
|
1243
|
+
/** Address or ID of the user token to filter events. */
|
|
1244
|
+
userToken?: TokenId.TokenIdOrAddress | undefined
|
|
1245
|
+
/** Address or ID of the validator token to filter events. */
|
|
1246
|
+
validatorToken?: TokenId.TokenIdOrAddress | undefined
|
|
1247
|
+
}
|
|
1248
|
+
}
|