tempo.ts 0.0.6 → 0.1.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/dist/chains.d.ts +244 -541
- package/dist/chains.d.ts.map +1 -1
- package/dist/chains.js +10 -23
- package/dist/chains.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/ox/SignatureEnvelope.d.ts +245 -0
- package/dist/ox/SignatureEnvelope.d.ts.map +1 -0
- package/dist/ox/SignatureEnvelope.js +437 -0
- package/dist/ox/SignatureEnvelope.js.map +1 -0
- package/dist/ox/Transaction.d.ts +61 -24
- package/dist/ox/Transaction.d.ts.map +1 -1
- package/dist/ox/Transaction.js +63 -18
- package/dist/ox/Transaction.js.map +1 -1
- package/dist/ox/TransactionEnvelopeAA.d.ts +461 -0
- package/dist/ox/TransactionEnvelopeAA.d.ts.map +1 -0
- package/dist/ox/TransactionEnvelopeAA.js +528 -0
- package/dist/ox/TransactionEnvelopeAA.js.map +1 -0
- package/dist/ox/TransactionRequest.d.ts +7 -5
- package/dist/ox/TransactionRequest.d.ts.map +1 -1
- package/dist/ox/TransactionRequest.js +21 -12
- package/dist/ox/TransactionRequest.js.map +1 -1
- package/dist/ox/index.d.ts +5 -4
- package/dist/ox/index.d.ts.map +1 -1
- package/dist/ox/index.js +5 -4
- package/dist/ox/index.js.map +1 -1
- package/dist/prool/Instance.d.ts +0 -4
- package/dist/prool/Instance.d.ts.map +1 -1
- package/dist/prool/Instance.js +7 -7
- package/dist/prool/Instance.js.map +1 -1
- package/dist/prool/index.d.ts +1 -1
- package/dist/prool/index.d.ts.map +1 -1
- package/dist/prool/index.js +1 -1
- package/dist/prool/index.js.map +1 -1
- package/dist/viem/{abis.d.ts → Abis.d.ts} +523 -9
- package/dist/viem/Abis.d.ts.map +1 -0
- package/dist/viem/{abis.js → Abis.js} +321 -9
- package/dist/viem/Abis.js.map +1 -0
- package/dist/viem/{actions → Actions}/amm.d.ts +21 -21
- package/dist/viem/Actions/amm.d.ts.map +1 -0
- package/dist/viem/{actions → Actions}/amm.js +55 -43
- package/dist/viem/Actions/amm.js.map +1 -0
- package/dist/viem/Actions/dex.d.ts +3263 -0
- package/dist/viem/Actions/dex.d.ts.map +1 -0
- package/dist/viem/Actions/dex.js +1357 -0
- package/dist/viem/Actions/dex.js.map +1 -0
- package/dist/viem/{actions → Actions}/fee.d.ts +8 -8
- package/dist/viem/Actions/fee.d.ts.map +1 -0
- package/dist/viem/{actions → Actions}/fee.js +14 -13
- package/dist/viem/Actions/fee.js.map +1 -0
- package/dist/viem/Actions/index.d.ts +6 -0
- package/dist/viem/Actions/index.d.ts.map +1 -0
- package/dist/viem/Actions/index.js +6 -0
- package/dist/viem/Actions/index.js.map +1 -0
- package/dist/viem/{actions → Actions}/policy.d.ts +19 -19
- package/dist/viem/Actions/policy.d.ts.map +1 -0
- package/dist/viem/{actions → Actions}/policy.js +59 -46
- package/dist/viem/Actions/policy.js.map +1 -0
- package/dist/viem/{actions → Actions}/token.d.ts +3275 -698
- package/dist/viem/Actions/token.d.ts.map +1 -0
- package/dist/viem/{actions → Actions}/token.js +458 -84
- package/dist/viem/Actions/token.js.map +1 -0
- package/dist/viem/Addresses.d.ts +9 -0
- package/dist/viem/Addresses.d.ts.map +1 -0
- package/dist/viem/Addresses.js +9 -0
- package/dist/viem/Addresses.js.map +1 -0
- package/dist/viem/{chain.d.ts → Chain.d.ts} +81 -57
- package/dist/viem/Chain.d.ts.map +1 -0
- package/dist/viem/{chain.js → Chain.js} +7 -7
- package/dist/viem/Chain.js.map +1 -0
- package/dist/viem/{client.d.ts → Client.d.ts} +4 -4
- package/dist/viem/Client.d.ts.map +1 -0
- package/dist/viem/{client.js → Client.js} +3 -3
- package/dist/viem/Client.js.map +1 -0
- package/dist/viem/{decorator.d.ts → Decorator.d.ts} +507 -5
- package/dist/viem/Decorator.d.ts.map +1 -0
- package/dist/viem/{decorator.js → Decorator.js} +31 -5
- package/dist/viem/Decorator.js.map +1 -0
- package/dist/viem/{formatters.d.ts → Formatters.d.ts} +2 -2
- package/dist/viem/Formatters.d.ts.map +1 -0
- package/dist/viem/{formatters.js → Formatters.js} +24 -17
- package/dist/viem/Formatters.js.map +1 -0
- package/dist/viem/Tick.d.ts +111 -0
- package/dist/viem/Tick.d.ts.map +1 -0
- package/dist/viem/Tick.js +127 -0
- package/dist/viem/Tick.js.map +1 -0
- package/dist/viem/TokenIds.d.ts +3 -0
- package/dist/viem/TokenIds.d.ts.map +1 -0
- package/dist/viem/TokenIds.js +3 -0
- package/dist/viem/TokenIds.js.map +1 -0
- package/dist/viem/Transaction.d.ts +57 -0
- package/dist/viem/Transaction.d.ts.map +1 -0
- package/dist/viem/Transaction.js +137 -0
- package/dist/viem/Transaction.js.map +1 -0
- package/dist/viem/{transport.d.ts → Transport.d.ts} +3 -3
- package/dist/viem/Transport.d.ts.map +1 -0
- package/dist/viem/{transport.js → Transport.js} +3 -3
- package/dist/viem/Transport.js.map +1 -0
- package/dist/viem/index.d.ts +13 -9
- package/dist/viem/index.d.ts.map +1 -1
- package/dist/viem/index.js +13 -9
- package/dist/viem/index.js.map +1 -1
- package/dist/viem/{types.d.ts → internal/types.d.ts} +3 -3
- package/dist/viem/internal/types.d.ts.map +1 -0
- package/dist/viem/{types.js.map → internal/types.js.map} +1 -1
- package/dist/viem/internal/utils.d.ts.map +1 -0
- package/dist/viem/internal/utils.js.map +1 -0
- package/package.json +87 -101
- package/src/chains.ts +10 -24
- package/src/ox/SignatureEnvelope.test.ts +1252 -0
- package/src/ox/SignatureEnvelope.ts +709 -0
- package/src/ox/Transaction.test.ts +144 -89
- package/src/ox/Transaction.ts +104 -29
- package/src/ox/TransactionEnvelopeAA.test.ts +1533 -0
- package/src/ox/TransactionEnvelopeAA.ts +858 -0
- package/src/ox/TransactionRequest.ts +25 -17
- package/src/ox/index.ts +2 -1
- package/src/prool/Instance.ts +6 -14
- package/src/prool/internal/chain.json +101 -27
- package/src/viem/{abis.ts → Abis.ts} +322 -8
- package/src/viem/{actions → Actions}/amm.test.ts +65 -68
- package/src/viem/{actions → Actions}/amm.ts +72 -60
- package/src/viem/Actions/dex.test.ts +1608 -0
- package/src/viem/Actions/dex.ts +2026 -0
- package/src/viem/{actions → Actions}/fee.test.ts +34 -36
- package/src/viem/{actions → Actions}/fee.ts +18 -17
- package/src/viem/{actions → Actions}/index.ts +1 -0
- package/src/viem/{actions → Actions}/policy.test.ts +2 -2
- package/src/viem/{actions → Actions}/policy.ts +77 -64
- package/src/viem/{actions → Actions}/token.test.ts +419 -64
- package/src/viem/{actions → Actions}/token.ts +751 -145
- package/src/viem/Addresses.ts +9 -0
- package/src/viem/{chain.ts → Chain.ts} +6 -6
- package/src/viem/{client.bench-d.ts → Client.bench-d.ts} +2 -2
- package/src/viem/{client.test.ts → Client.test.ts} +31 -6
- package/src/viem/{client.ts → Client.ts} +1 -1
- package/src/viem/{decorator.bench-d.ts → Decorator.bench-d.ts} +2 -2
- package/src/viem/{decorator.test.ts → Decorator.test.ts} +1 -0
- package/src/viem/{decorator.ts → Decorator.ts} +586 -4
- package/src/viem/{formatters.ts → Formatters.ts} +31 -20
- package/src/viem/Tick.test.ts +281 -0
- package/src/viem/Tick.ts +176 -0
- package/src/viem/TokenIds.ts +2 -0
- package/src/viem/Transaction.ts +303 -0
- package/src/viem/{transport.ts → Transport.ts} +5 -5
- package/src/viem/e2e.test.ts +153 -78
- package/src/viem/index.ts +13 -9
- package/src/viem/{types.ts → internal/types.ts} +3 -3
- package/dist/ox/TransactionEnvelopeFeeToken.d.ts +0 -393
- package/dist/ox/TransactionEnvelopeFeeToken.d.ts.map +0 -1
- package/dist/ox/TransactionEnvelopeFeeToken.js +0 -452
- package/dist/ox/TransactionEnvelopeFeeToken.js.map +0 -1
- package/dist/viem/abis.d.ts.map +0 -1
- package/dist/viem/abis.js.map +0 -1
- package/dist/viem/actions/amm.d.ts.map +0 -1
- package/dist/viem/actions/amm.js.map +0 -1
- package/dist/viem/actions/fee.d.ts.map +0 -1
- package/dist/viem/actions/fee.js.map +0 -1
- package/dist/viem/actions/index.d.ts +0 -5
- package/dist/viem/actions/index.d.ts.map +0 -1
- package/dist/viem/actions/index.js +0 -5
- package/dist/viem/actions/index.js.map +0 -1
- package/dist/viem/actions/policy.d.ts.map +0 -1
- package/dist/viem/actions/policy.js.map +0 -1
- package/dist/viem/actions/token.d.ts.map +0 -1
- package/dist/viem/actions/token.js.map +0 -1
- package/dist/viem/addresses.d.ts +0 -8
- package/dist/viem/addresses.d.ts.map +0 -1
- package/dist/viem/addresses.js +0 -8
- package/dist/viem/addresses.js.map +0 -1
- package/dist/viem/chain.d.ts.map +0 -1
- package/dist/viem/chain.js.map +0 -1
- package/dist/viem/client.d.ts.map +0 -1
- package/dist/viem/client.js.map +0 -1
- package/dist/viem/decorator.d.ts.map +0 -1
- package/dist/viem/decorator.js.map +0 -1
- package/dist/viem/formatters.d.ts.map +0 -1
- package/dist/viem/formatters.js.map +0 -1
- package/dist/viem/transaction.d.ts +0 -54
- package/dist/viem/transaction.d.ts.map +0 -1
- package/dist/viem/transaction.js +0 -108
- package/dist/viem/transaction.js.map +0 -1
- package/dist/viem/transport.d.ts.map +0 -1
- package/dist/viem/transport.js.map +0 -1
- package/dist/viem/types.d.ts.map +0 -1
- package/dist/viem/utils.d.ts.map +0 -1
- package/dist/viem/utils.js.map +0 -1
- package/src/ox/TransactionEnvelopeFeeToken.test.ts +0 -1119
- package/src/ox/TransactionEnvelopeFeeToken.ts +0 -717
- package/src/prool/internal/consensus.toml +0 -32
- package/src/viem/addresses.ts +0 -10
- package/src/viem/transaction.ts +0 -253
- /package/dist/viem/{types.js → internal/types.js} +0 -0
- /package/dist/viem/{utils.d.ts → internal/utils.d.ts} +0 -0
- /package/dist/viem/{utils.js → internal/utils.js} +0 -0
- /package/src/viem/{utils.ts → internal/utils.ts} +0 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Account, Chain, Client, Transport } from 'viem'
|
|
2
|
-
import * as ammActions from './
|
|
3
|
-
import * as
|
|
4
|
-
import * as
|
|
5
|
-
import * as
|
|
2
|
+
import * as ammActions from './Actions/amm.js'
|
|
3
|
+
import * as dexActions from './Actions/dex.js'
|
|
4
|
+
import * as feeActions from './Actions/fee.js'
|
|
5
|
+
import * as policyActions from './Actions/policy.js'
|
|
6
|
+
import * as tokenActions from './Actions/token.js'
|
|
6
7
|
|
|
7
8
|
export type Decorator<
|
|
8
9
|
chain extends Chain | undefined = Chain | undefined,
|
|
@@ -349,6 +350,553 @@ export type Decorator<
|
|
|
349
350
|
*/
|
|
350
351
|
watchBurn: (parameters: ammActions.watchBurn.Parameters) => () => void
|
|
351
352
|
}
|
|
353
|
+
dex: {
|
|
354
|
+
/**
|
|
355
|
+
* Buys a specific amount of tokens.
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
* ```ts
|
|
359
|
+
* import { createTempoClient } from 'tempo.ts/viem'
|
|
360
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
361
|
+
*
|
|
362
|
+
* const client = createTempoClient({
|
|
363
|
+
* account: privateKeyToAccount('0x...')
|
|
364
|
+
* })
|
|
365
|
+
*
|
|
366
|
+
* const hash = await client.dex.buy({
|
|
367
|
+
* tokenIn: '0x20c...11',
|
|
368
|
+
* tokenOut: '0x20c...20',
|
|
369
|
+
* amountOut: 100n,
|
|
370
|
+
* maxAmountIn: 105n,
|
|
371
|
+
* })
|
|
372
|
+
* ```
|
|
373
|
+
*
|
|
374
|
+
* @param parameters - Parameters.
|
|
375
|
+
* @returns The transaction hash.
|
|
376
|
+
*/
|
|
377
|
+
buy: (
|
|
378
|
+
parameters: dexActions.buy.Parameters<chain, account>,
|
|
379
|
+
) => Promise<dexActions.buy.ReturnValue>
|
|
380
|
+
/**
|
|
381
|
+
* Buys a specific amount of tokens.
|
|
382
|
+
*
|
|
383
|
+
* @example
|
|
384
|
+
* ```ts
|
|
385
|
+
* import { createTempoClient } from 'tempo.ts/viem'
|
|
386
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
387
|
+
*
|
|
388
|
+
* const client = createTempoClient({
|
|
389
|
+
* account: privateKeyToAccount('0x...')
|
|
390
|
+
* })
|
|
391
|
+
*
|
|
392
|
+
* const result = await client.dex.buySync({
|
|
393
|
+
* tokenIn: '0x20c...11',
|
|
394
|
+
* tokenOut: '0x20c...20',
|
|
395
|
+
* amountOut: 100n,
|
|
396
|
+
* maxAmountIn: 105n,
|
|
397
|
+
* })
|
|
398
|
+
* ```
|
|
399
|
+
*
|
|
400
|
+
* @param parameters - Parameters.
|
|
401
|
+
* @returns The transaction receipt.
|
|
402
|
+
*/
|
|
403
|
+
buySync: (
|
|
404
|
+
parameters: dexActions.buySync.Parameters<chain, account>,
|
|
405
|
+
) => Promise<dexActions.buySync.ReturnValue>
|
|
406
|
+
/**
|
|
407
|
+
* Cancels an order from the orderbook.
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* ```ts
|
|
411
|
+
* import { createTempoClient } from 'tempo.ts/viem'
|
|
412
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
413
|
+
*
|
|
414
|
+
* const client = createTempoClient({
|
|
415
|
+
* account: privateKeyToAccount('0x...')
|
|
416
|
+
* })
|
|
417
|
+
*
|
|
418
|
+
* const hash = await client.dex.cancel({
|
|
419
|
+
* orderId: 123n,
|
|
420
|
+
* })
|
|
421
|
+
* ```
|
|
422
|
+
*
|
|
423
|
+
* @param parameters - Parameters.
|
|
424
|
+
* @returns The transaction hash.
|
|
425
|
+
*/
|
|
426
|
+
cancel: (
|
|
427
|
+
parameters: dexActions.cancel.Parameters<chain, account>,
|
|
428
|
+
) => Promise<dexActions.cancel.ReturnValue>
|
|
429
|
+
/**
|
|
430
|
+
* Cancels an order from the orderbook.
|
|
431
|
+
*
|
|
432
|
+
* @example
|
|
433
|
+
* ```ts
|
|
434
|
+
* import { createTempoClient } from 'tempo.ts/viem'
|
|
435
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
436
|
+
*
|
|
437
|
+
* const client = createTempoClient({
|
|
438
|
+
* account: privateKeyToAccount('0x...')
|
|
439
|
+
* })
|
|
440
|
+
*
|
|
441
|
+
* const result = await client.dex.cancelSync({
|
|
442
|
+
* orderId: 123n,
|
|
443
|
+
* })
|
|
444
|
+
* ```
|
|
445
|
+
*
|
|
446
|
+
* @param parameters - Parameters.
|
|
447
|
+
* @returns The transaction receipt and event data.
|
|
448
|
+
*/
|
|
449
|
+
cancelSync: (
|
|
450
|
+
parameters: dexActions.cancelSync.Parameters<chain, account>,
|
|
451
|
+
) => Promise<dexActions.cancelSync.ReturnValue>
|
|
452
|
+
/**
|
|
453
|
+
* Creates a new trading pair on the DEX.
|
|
454
|
+
*
|
|
455
|
+
* @example
|
|
456
|
+
* ```ts
|
|
457
|
+
* import { createTempoClient } from 'tempo.ts/viem'
|
|
458
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
459
|
+
*
|
|
460
|
+
* const client = createTempoClient({
|
|
461
|
+
* account: privateKeyToAccount('0x...')
|
|
462
|
+
* })
|
|
463
|
+
*
|
|
464
|
+
* const hash = await client.dex.createPair({
|
|
465
|
+
* base: '0x20c...11',
|
|
466
|
+
* })
|
|
467
|
+
* ```
|
|
468
|
+
*
|
|
469
|
+
* @param parameters - Parameters.
|
|
470
|
+
* @returns The transaction hash.
|
|
471
|
+
*/
|
|
472
|
+
createPair: (
|
|
473
|
+
parameters: dexActions.createPair.Parameters<chain, account>,
|
|
474
|
+
) => Promise<dexActions.createPair.ReturnValue>
|
|
475
|
+
/**
|
|
476
|
+
* Creates a new trading pair on the DEX.
|
|
477
|
+
*
|
|
478
|
+
* @example
|
|
479
|
+
* ```ts
|
|
480
|
+
* import { createTempoClient } from 'tempo.ts/viem'
|
|
481
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
482
|
+
*
|
|
483
|
+
* const client = createTempoClient({
|
|
484
|
+
* account: privateKeyToAccount('0x...')
|
|
485
|
+
* })
|
|
486
|
+
*
|
|
487
|
+
* const result = await client.dex.createPairSync({
|
|
488
|
+
* base: '0x20c...11',
|
|
489
|
+
* })
|
|
490
|
+
* ```
|
|
491
|
+
*
|
|
492
|
+
* @param parameters - Parameters.
|
|
493
|
+
* @returns The transaction receipt and event data.
|
|
494
|
+
*/
|
|
495
|
+
createPairSync: (
|
|
496
|
+
parameters: dexActions.createPairSync.Parameters<chain, account>,
|
|
497
|
+
) => Promise<dexActions.createPairSync.ReturnValue>
|
|
498
|
+
/**
|
|
499
|
+
* Gets a user's token balance on the DEX.
|
|
500
|
+
*
|
|
501
|
+
* @example
|
|
502
|
+
* ```ts
|
|
503
|
+
* import { createTempoClient } from 'tempo.ts/viem'
|
|
504
|
+
*
|
|
505
|
+
* const client = createTempoClient()
|
|
506
|
+
*
|
|
507
|
+
* const balance = await client.dex.getBalance({
|
|
508
|
+
* account: '0x...',
|
|
509
|
+
* token: '0x20c...11',
|
|
510
|
+
* })
|
|
511
|
+
* ```
|
|
512
|
+
*
|
|
513
|
+
* @param parameters - Parameters.
|
|
514
|
+
* @returns The user's token balance on the DEX.
|
|
515
|
+
*/
|
|
516
|
+
getBalance: (
|
|
517
|
+
parameters: dexActions.getBalance.Parameters<account>,
|
|
518
|
+
) => Promise<dexActions.getBalance.ReturnValue>
|
|
519
|
+
/**
|
|
520
|
+
* Gets the quote for buying a specific amount of tokens.
|
|
521
|
+
*
|
|
522
|
+
* @example
|
|
523
|
+
* ```ts
|
|
524
|
+
* import { createTempoClient } from 'tempo.ts/viem'
|
|
525
|
+
*
|
|
526
|
+
* const client = createTempoClient()
|
|
527
|
+
*
|
|
528
|
+
* const amountIn = await client.dex.getBuyQuote({
|
|
529
|
+
* tokenIn: '0x20c...11',
|
|
530
|
+
* tokenOut: '0x20c...20',
|
|
531
|
+
* amountOut: 100n,
|
|
532
|
+
* })
|
|
533
|
+
* ```
|
|
534
|
+
*
|
|
535
|
+
* @param parameters - Parameters.
|
|
536
|
+
* @returns The amount of tokenIn needed to buy the specified amountOut.
|
|
537
|
+
*/
|
|
538
|
+
getBuyQuote: (
|
|
539
|
+
parameters: dexActions.getBuyQuote.Parameters,
|
|
540
|
+
) => Promise<dexActions.getBuyQuote.ReturnValue>
|
|
541
|
+
/**
|
|
542
|
+
* Gets an order's details from the orderbook.
|
|
543
|
+
*
|
|
544
|
+
* @example
|
|
545
|
+
* ```ts
|
|
546
|
+
* import { createTempoClient } from 'tempo.ts/viem'
|
|
547
|
+
*
|
|
548
|
+
* const client = createTempoClient()
|
|
549
|
+
*
|
|
550
|
+
* const order = await client.dex.getOrder({
|
|
551
|
+
* orderId: 123n,
|
|
552
|
+
* })
|
|
553
|
+
* ```
|
|
554
|
+
*
|
|
555
|
+
* @param parameters - Parameters.
|
|
556
|
+
* @returns The order details.
|
|
557
|
+
*/
|
|
558
|
+
getOrder: (
|
|
559
|
+
parameters: dexActions.getOrder.Parameters,
|
|
560
|
+
) => Promise<dexActions.getOrder.ReturnValue>
|
|
561
|
+
/**
|
|
562
|
+
* Gets the price level information at a specific tick.
|
|
563
|
+
*
|
|
564
|
+
* @example
|
|
565
|
+
* ```ts
|
|
566
|
+
* import { createTempoClient, Tick } from 'tempo.ts/viem'
|
|
567
|
+
*
|
|
568
|
+
* const client = createTempoClient()
|
|
569
|
+
*
|
|
570
|
+
* const level = await client.dex.getPriceLevel({
|
|
571
|
+
* base: '0x20c...11',
|
|
572
|
+
* tick: Tick.fromPrice('1.001'),
|
|
573
|
+
* isBid: true,
|
|
574
|
+
* })
|
|
575
|
+
* ```
|
|
576
|
+
*
|
|
577
|
+
* @param parameters - Parameters.
|
|
578
|
+
* @returns The price level information.
|
|
579
|
+
*/
|
|
580
|
+
getPriceLevel: (
|
|
581
|
+
parameters: dexActions.getPriceLevel.Parameters,
|
|
582
|
+
) => Promise<dexActions.getPriceLevel.ReturnValue>
|
|
583
|
+
/**
|
|
584
|
+
* Gets the quote for selling a specific amount of tokens.
|
|
585
|
+
*
|
|
586
|
+
* @example
|
|
587
|
+
* ```ts
|
|
588
|
+
* import { createTempoClient } from 'tempo.ts/viem'
|
|
589
|
+
*
|
|
590
|
+
* const client = createTempoClient()
|
|
591
|
+
*
|
|
592
|
+
* const amountOut = await client.dex.getSellQuote({
|
|
593
|
+
* tokenIn: '0x20c...11',
|
|
594
|
+
* tokenOut: '0x20c...20',
|
|
595
|
+
* amountIn: 100n,
|
|
596
|
+
* })
|
|
597
|
+
* ```
|
|
598
|
+
*
|
|
599
|
+
* @param parameters - Parameters.
|
|
600
|
+
* @returns The amount of tokenOut received for selling the specified amountIn.
|
|
601
|
+
*/
|
|
602
|
+
getSellQuote: (
|
|
603
|
+
parameters: dexActions.getSellQuote.Parameters,
|
|
604
|
+
) => Promise<dexActions.getSellQuote.ReturnValue>
|
|
605
|
+
/**
|
|
606
|
+
* Places a limit order on the orderbook.
|
|
607
|
+
*
|
|
608
|
+
* @example
|
|
609
|
+
* ```ts
|
|
610
|
+
* import { createTempoClient, Tick } from 'tempo.ts/viem'
|
|
611
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
612
|
+
*
|
|
613
|
+
* const client = createTempoClient({
|
|
614
|
+
* account: privateKeyToAccount('0x...')
|
|
615
|
+
* })
|
|
616
|
+
*
|
|
617
|
+
* const hash = await client.dex.place({
|
|
618
|
+
* token: '0x20c...11',
|
|
619
|
+
* amount: 100n,
|
|
620
|
+
* type: 'buy',
|
|
621
|
+
* tick: Tick.fromPrice('0.99'),
|
|
622
|
+
* })
|
|
623
|
+
* ```
|
|
624
|
+
*
|
|
625
|
+
* @param parameters - Parameters.
|
|
626
|
+
* @returns The transaction hash.
|
|
627
|
+
*/
|
|
628
|
+
place: (
|
|
629
|
+
parameters: dexActions.place.Parameters<chain, account>,
|
|
630
|
+
) => Promise<dexActions.place.ReturnValue>
|
|
631
|
+
/**
|
|
632
|
+
* Places a limit order on the orderbook.
|
|
633
|
+
*
|
|
634
|
+
* @example
|
|
635
|
+
* ```ts
|
|
636
|
+
* import { createTempoClient, Tick } from 'tempo.ts/viem'
|
|
637
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
638
|
+
*
|
|
639
|
+
* const client = createTempoClient({
|
|
640
|
+
* account: privateKeyToAccount('0x...')
|
|
641
|
+
* })
|
|
642
|
+
*
|
|
643
|
+
* const result = await client.dex.placeSync({
|
|
644
|
+
* token: '0x20c...11',
|
|
645
|
+
* amount: 100n,
|
|
646
|
+
* type: 'buy',
|
|
647
|
+
* tick: Tick.fromPrice('0.99'),
|
|
648
|
+
* })
|
|
649
|
+
* ```
|
|
650
|
+
*
|
|
651
|
+
* @param parameters - Parameters.
|
|
652
|
+
* @returns The transaction receipt and event data.
|
|
653
|
+
*/
|
|
654
|
+
placeSync: (
|
|
655
|
+
parameters: dexActions.placeSync.Parameters<chain, account>,
|
|
656
|
+
) => Promise<dexActions.placeSync.ReturnValue>
|
|
657
|
+
/**
|
|
658
|
+
* Places a flip order that automatically flips when filled.
|
|
659
|
+
*
|
|
660
|
+
* @example
|
|
661
|
+
* ```ts
|
|
662
|
+
* import { createTempoClient, Tick } from 'tempo.ts/viem'
|
|
663
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
664
|
+
*
|
|
665
|
+
* const client = createTempoClient({
|
|
666
|
+
* account: privateKeyToAccount('0x...')
|
|
667
|
+
* })
|
|
668
|
+
*
|
|
669
|
+
* const hash = await client.dex.placeFlip({
|
|
670
|
+
* token: '0x20c...11',
|
|
671
|
+
* amount: 100n,
|
|
672
|
+
* type: 'buy',
|
|
673
|
+
* tick: Tick.fromPrice('0.99'),
|
|
674
|
+
* flipTick: Tick.fromPrice('1.01'),
|
|
675
|
+
* })
|
|
676
|
+
* ```
|
|
677
|
+
*
|
|
678
|
+
* @param parameters - Parameters.
|
|
679
|
+
* @returns The transaction hash.
|
|
680
|
+
*/
|
|
681
|
+
placeFlip: (
|
|
682
|
+
parameters: dexActions.placeFlip.Parameters<chain, account>,
|
|
683
|
+
) => Promise<dexActions.placeFlip.ReturnValue>
|
|
684
|
+
/**
|
|
685
|
+
* Places a flip order that automatically flips when filled.
|
|
686
|
+
*
|
|
687
|
+
* @example
|
|
688
|
+
* ```ts
|
|
689
|
+
* import { createTempoClient, Tick } from 'tempo.ts/viem'
|
|
690
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
691
|
+
*
|
|
692
|
+
* const client = createTempoClient({
|
|
693
|
+
* account: privateKeyToAccount('0x...')
|
|
694
|
+
* })
|
|
695
|
+
*
|
|
696
|
+
* const result = await client.dex.placeFlipSync({
|
|
697
|
+
* token: '0x20c...11',
|
|
698
|
+
* amount: 100n,
|
|
699
|
+
* type: 'buy',
|
|
700
|
+
* tick: Tick.fromPrice('0.99'),
|
|
701
|
+
* flipTick: Tick.fromPrice('1.01'),
|
|
702
|
+
* })
|
|
703
|
+
* ```
|
|
704
|
+
*
|
|
705
|
+
* @param parameters - Parameters.
|
|
706
|
+
* @returns The transaction receipt and event data.
|
|
707
|
+
*/
|
|
708
|
+
placeFlipSync: (
|
|
709
|
+
parameters: dexActions.placeFlipSync.Parameters<chain, account>,
|
|
710
|
+
) => Promise<dexActions.placeFlipSync.ReturnValue>
|
|
711
|
+
/**
|
|
712
|
+
* Sells a specific amount of tokens.
|
|
713
|
+
*
|
|
714
|
+
* @example
|
|
715
|
+
* ```ts
|
|
716
|
+
* import { createTempoClient } from 'tempo.ts/viem'
|
|
717
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
718
|
+
*
|
|
719
|
+
* const client = createTempoClient({
|
|
720
|
+
* account: privateKeyToAccount('0x...')
|
|
721
|
+
* })
|
|
722
|
+
*
|
|
723
|
+
* const hash = await client.dex.sell({
|
|
724
|
+
* tokenIn: '0x20c...11',
|
|
725
|
+
* tokenOut: '0x20c...20',
|
|
726
|
+
* amountIn: 100n,
|
|
727
|
+
* minAmountOut: 95n,
|
|
728
|
+
* })
|
|
729
|
+
* ```
|
|
730
|
+
*
|
|
731
|
+
* @param parameters - Parameters.
|
|
732
|
+
* @returns The transaction hash.
|
|
733
|
+
*/
|
|
734
|
+
sell: (
|
|
735
|
+
parameters: dexActions.sell.Parameters<chain, account>,
|
|
736
|
+
) => Promise<dexActions.sell.ReturnValue>
|
|
737
|
+
/**
|
|
738
|
+
* Sells a specific amount of tokens.
|
|
739
|
+
*
|
|
740
|
+
* @example
|
|
741
|
+
* ```ts
|
|
742
|
+
* import { createTempoClient } from 'tempo.ts/viem'
|
|
743
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
744
|
+
*
|
|
745
|
+
* const client = createTempoClient({
|
|
746
|
+
* account: privateKeyToAccount('0x...')
|
|
747
|
+
* })
|
|
748
|
+
*
|
|
749
|
+
* const result = await client.dex.sellSync({
|
|
750
|
+
* tokenIn: '0x20c...11',
|
|
751
|
+
* tokenOut: '0x20c...20',
|
|
752
|
+
* amountIn: 100n,
|
|
753
|
+
* minAmountOut: 95n,
|
|
754
|
+
* })
|
|
755
|
+
* ```
|
|
756
|
+
*
|
|
757
|
+
* @param parameters - Parameters.
|
|
758
|
+
* @returns The transaction receipt.
|
|
759
|
+
*/
|
|
760
|
+
sellSync: (
|
|
761
|
+
parameters: dexActions.sellSync.Parameters<chain, account>,
|
|
762
|
+
) => Promise<dexActions.sellSync.ReturnValue>
|
|
763
|
+
/**
|
|
764
|
+
* Withdraws tokens from the DEX to the caller's wallet.
|
|
765
|
+
*
|
|
766
|
+
* @example
|
|
767
|
+
* ```ts
|
|
768
|
+
* import { createTempoClient } from 'tempo.ts/viem'
|
|
769
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
770
|
+
*
|
|
771
|
+
* const client = createTempoClient({
|
|
772
|
+
* account: privateKeyToAccount('0x...')
|
|
773
|
+
* })
|
|
774
|
+
*
|
|
775
|
+
* const hash = await client.dex.withdraw({
|
|
776
|
+
* token: '0x20c...11',
|
|
777
|
+
* amount: 100n,
|
|
778
|
+
* })
|
|
779
|
+
* ```
|
|
780
|
+
*
|
|
781
|
+
* @param parameters - Parameters.
|
|
782
|
+
* @returns The transaction hash.
|
|
783
|
+
*/
|
|
784
|
+
withdraw: (
|
|
785
|
+
parameters: dexActions.withdraw.Parameters<chain, account>,
|
|
786
|
+
) => Promise<dexActions.withdraw.ReturnValue>
|
|
787
|
+
/**
|
|
788
|
+
* Withdraws tokens from the DEX to the caller's wallet.
|
|
789
|
+
*
|
|
790
|
+
* @example
|
|
791
|
+
* ```ts
|
|
792
|
+
* import { createTempoClient } from 'tempo.ts/viem'
|
|
793
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
794
|
+
*
|
|
795
|
+
* const client = createTempoClient({
|
|
796
|
+
* account: privateKeyToAccount('0x...')
|
|
797
|
+
* })
|
|
798
|
+
*
|
|
799
|
+
* const result = await client.dex.withdrawSync({
|
|
800
|
+
* token: '0x20c...11',
|
|
801
|
+
* amount: 100n,
|
|
802
|
+
* })
|
|
803
|
+
* ```
|
|
804
|
+
*
|
|
805
|
+
* @param parameters - Parameters.
|
|
806
|
+
* @returns The transaction receipt.
|
|
807
|
+
*/
|
|
808
|
+
withdrawSync: (
|
|
809
|
+
parameters: dexActions.withdrawSync.Parameters<chain, account>,
|
|
810
|
+
) => Promise<dexActions.withdrawSync.ReturnValue>
|
|
811
|
+
/**
|
|
812
|
+
* Watches for flip order placed events.
|
|
813
|
+
*
|
|
814
|
+
* @example
|
|
815
|
+
* ```ts
|
|
816
|
+
* import { createTempoClient } from 'tempo.ts/viem'
|
|
817
|
+
*
|
|
818
|
+
* const client = createTempoClient()
|
|
819
|
+
*
|
|
820
|
+
* const unwatch = client.dex.watchFlipOrderPlaced({
|
|
821
|
+
* onFlipOrderPlaced: (args, log) => {
|
|
822
|
+
* console.log('Flip order placed:', args)
|
|
823
|
+
* },
|
|
824
|
+
* })
|
|
825
|
+
* ```
|
|
826
|
+
*
|
|
827
|
+
* @param parameters - Parameters.
|
|
828
|
+
* @returns A function to unsubscribe from the event.
|
|
829
|
+
*/
|
|
830
|
+
watchFlipOrderPlaced: (
|
|
831
|
+
parameters: dexActions.watchFlipOrderPlaced.Parameters,
|
|
832
|
+
) => () => void
|
|
833
|
+
/**
|
|
834
|
+
* Watches for order cancelled events.
|
|
835
|
+
*
|
|
836
|
+
* @example
|
|
837
|
+
* ```ts
|
|
838
|
+
* import { createTempoClient } from 'tempo.ts/viem'
|
|
839
|
+
*
|
|
840
|
+
* const client = createTempoClient()
|
|
841
|
+
*
|
|
842
|
+
* const unwatch = client.dex.watchOrderCancelled({
|
|
843
|
+
* onOrderCancelled: (args, log) => {
|
|
844
|
+
* console.log('Order cancelled:', args)
|
|
845
|
+
* },
|
|
846
|
+
* })
|
|
847
|
+
* ```
|
|
848
|
+
*
|
|
849
|
+
* @param parameters - Parameters.
|
|
850
|
+
* @returns A function to unsubscribe from the event.
|
|
851
|
+
*/
|
|
852
|
+
watchOrderCancelled: (
|
|
853
|
+
parameters: dexActions.watchOrderCancelled.Parameters,
|
|
854
|
+
) => () => void
|
|
855
|
+
/**
|
|
856
|
+
* Watches for order filled events.
|
|
857
|
+
*
|
|
858
|
+
* @example
|
|
859
|
+
* ```ts
|
|
860
|
+
* import { createTempoClient } from 'tempo.ts/viem'
|
|
861
|
+
*
|
|
862
|
+
* const client = createTempoClient()
|
|
863
|
+
*
|
|
864
|
+
* const unwatch = client.dex.watchOrderFilled({
|
|
865
|
+
* onOrderFilled: (args, log) => {
|
|
866
|
+
* console.log('Order filled:', args)
|
|
867
|
+
* },
|
|
868
|
+
* })
|
|
869
|
+
* ```
|
|
870
|
+
*
|
|
871
|
+
* @param parameters - Parameters.
|
|
872
|
+
* @returns A function to unsubscribe from the event.
|
|
873
|
+
*/
|
|
874
|
+
watchOrderFilled: (
|
|
875
|
+
parameters: dexActions.watchOrderFilled.Parameters,
|
|
876
|
+
) => () => void
|
|
877
|
+
/**
|
|
878
|
+
* Watches for order placed events.
|
|
879
|
+
*
|
|
880
|
+
* @example
|
|
881
|
+
* ```ts
|
|
882
|
+
* import { createTempoClient } from 'tempo.ts/viem'
|
|
883
|
+
*
|
|
884
|
+
* const client = createTempoClient()
|
|
885
|
+
*
|
|
886
|
+
* const unwatch = client.dex.watchOrderPlaced({
|
|
887
|
+
* onOrderPlaced: (args, log) => {
|
|
888
|
+
* console.log('Order placed:', args)
|
|
889
|
+
* },
|
|
890
|
+
* })
|
|
891
|
+
* ```
|
|
892
|
+
*
|
|
893
|
+
* @param parameters - Parameters.
|
|
894
|
+
* @returns A function to unsubscribe from the event.
|
|
895
|
+
*/
|
|
896
|
+
watchOrderPlaced: (
|
|
897
|
+
parameters: dexActions.watchOrderPlaced.Parameters,
|
|
898
|
+
) => () => void
|
|
899
|
+
}
|
|
352
900
|
fee: {
|
|
353
901
|
/**
|
|
354
902
|
* Gets the user's default fee token.
|
|
@@ -1830,6 +2378,40 @@ export function decorator() {
|
|
|
1830
2378
|
watchMint: (parameters) => ammActions.watchMint(client, parameters),
|
|
1831
2379
|
watchBurn: (parameters) => ammActions.watchBurn(client, parameters),
|
|
1832
2380
|
},
|
|
2381
|
+
dex: {
|
|
2382
|
+
buy: (parameters) => dexActions.buy(client, parameters),
|
|
2383
|
+
buySync: (parameters) => dexActions.buySync(client, parameters),
|
|
2384
|
+
cancel: (parameters) => dexActions.cancel(client, parameters),
|
|
2385
|
+
cancelSync: (parameters) => dexActions.cancelSync(client, parameters),
|
|
2386
|
+
createPair: (parameters) => dexActions.createPair(client, parameters),
|
|
2387
|
+
createPairSync: (parameters) =>
|
|
2388
|
+
dexActions.createPairSync(client, parameters),
|
|
2389
|
+
getBalance: (parameters) => dexActions.getBalance(client, parameters),
|
|
2390
|
+
getBuyQuote: (parameters) => dexActions.getBuyQuote(client, parameters),
|
|
2391
|
+
getOrder: (parameters) => dexActions.getOrder(client, parameters),
|
|
2392
|
+
getPriceLevel: (parameters) =>
|
|
2393
|
+
dexActions.getPriceLevel(client, parameters),
|
|
2394
|
+
getSellQuote: (parameters) =>
|
|
2395
|
+
dexActions.getSellQuote(client, parameters),
|
|
2396
|
+
place: (parameters) => dexActions.place(client, parameters),
|
|
2397
|
+
placeSync: (parameters) => dexActions.placeSync(client, parameters),
|
|
2398
|
+
placeFlip: (parameters) => dexActions.placeFlip(client, parameters),
|
|
2399
|
+
placeFlipSync: (parameters) =>
|
|
2400
|
+
dexActions.placeFlipSync(client, parameters),
|
|
2401
|
+
sell: (parameters) => dexActions.sell(client, parameters),
|
|
2402
|
+
sellSync: (parameters) => dexActions.sellSync(client, parameters),
|
|
2403
|
+
withdraw: (parameters) => dexActions.withdraw(client, parameters),
|
|
2404
|
+
withdrawSync: (parameters) =>
|
|
2405
|
+
dexActions.withdrawSync(client, parameters),
|
|
2406
|
+
watchFlipOrderPlaced: (parameters) =>
|
|
2407
|
+
dexActions.watchFlipOrderPlaced(client, parameters),
|
|
2408
|
+
watchOrderCancelled: (parameters) =>
|
|
2409
|
+
dexActions.watchOrderCancelled(client, parameters),
|
|
2410
|
+
watchOrderFilled: (parameters) =>
|
|
2411
|
+
dexActions.watchOrderFilled(client, parameters),
|
|
2412
|
+
watchOrderPlaced: (parameters) =>
|
|
2413
|
+
dexActions.watchOrderPlaced(client, parameters),
|
|
2414
|
+
},
|
|
1833
2415
|
fee: {
|
|
1834
2416
|
// @ts-expect-error
|
|
1835
2417
|
getUserToken: (parameters) =>
|
|
@@ -7,30 +7,30 @@ import { parseAccount } from 'viem/accounts'
|
|
|
7
7
|
import * as ox_Transaction from '../ox/Transaction.js'
|
|
8
8
|
import * as ox_TransactionRequest from '../ox/TransactionRequest.js'
|
|
9
9
|
import {
|
|
10
|
-
|
|
10
|
+
isTempo,
|
|
11
11
|
type Transaction,
|
|
12
12
|
type TransactionRequest,
|
|
13
|
-
type
|
|
13
|
+
type TransactionRequestAA,
|
|
14
14
|
type TransactionRequestRpc,
|
|
15
15
|
type TransactionRpc,
|
|
16
|
-
} from './
|
|
16
|
+
} from './Transaction.js'
|
|
17
17
|
|
|
18
18
|
export const formatTransaction = (
|
|
19
19
|
transaction: TransactionRpc,
|
|
20
20
|
): Transaction<bigint, number, boolean> => {
|
|
21
|
-
if (!
|
|
22
|
-
return viem_formatTransaction(transaction as never)
|
|
21
|
+
if (!isTempo(transaction)) return viem_formatTransaction(transaction as never)
|
|
23
22
|
|
|
24
23
|
const {
|
|
25
24
|
feePayerSignature,
|
|
26
25
|
gasPrice: _,
|
|
27
26
|
nonce,
|
|
28
27
|
...tx
|
|
29
|
-
} = ox_Transaction.fromRpc(transaction as never) as ox_Transaction.
|
|
28
|
+
} = ox_Transaction.fromRpc(transaction as never) as ox_Transaction.AA
|
|
29
|
+
|
|
30
30
|
return {
|
|
31
31
|
...tx,
|
|
32
32
|
accessList: tx.accessList!,
|
|
33
|
-
authorizationList: tx.authorizationList
|
|
33
|
+
authorizationList: tx.authorizationList?.map((auth) => ({
|
|
34
34
|
...auth,
|
|
35
35
|
nonce: Number(auth.nonce),
|
|
36
36
|
r: Hex.fromNumber(auth.r, { size: 32 }),
|
|
@@ -49,10 +49,7 @@ export const formatTransaction = (
|
|
|
49
49
|
ox_Transaction.toRpcType[
|
|
50
50
|
tx.type as keyof typeof ox_Transaction.toRpcType
|
|
51
51
|
],
|
|
52
|
-
type: tx.type as '
|
|
53
|
-
r: Hex.fromNumber(tx.r, { size: 32 }),
|
|
54
|
-
s: Hex.fromNumber(tx.s, { size: 32 }),
|
|
55
|
-
v: BigInt(tx.v ?? 27),
|
|
52
|
+
type: tx.type as 'aa',
|
|
56
53
|
}
|
|
57
54
|
}
|
|
58
55
|
|
|
@@ -60,14 +57,23 @@ export const formatTransactionRequest = (
|
|
|
60
57
|
r: TransactionRequest,
|
|
61
58
|
action?: string | undefined,
|
|
62
59
|
): TransactionRequestRpc => {
|
|
63
|
-
const request = r as
|
|
60
|
+
const request = r as TransactionRequestAA
|
|
64
61
|
|
|
65
|
-
if (!
|
|
62
|
+
if (!isTempo(request))
|
|
66
63
|
return viem_formatTransactionRequest(
|
|
67
64
|
r as never,
|
|
68
65
|
action,
|
|
69
66
|
) as TransactionRequestRpc
|
|
70
67
|
|
|
68
|
+
if (action)
|
|
69
|
+
request.calls = request.calls ?? [
|
|
70
|
+
{
|
|
71
|
+
to: r.to || undefined,
|
|
72
|
+
value: r.value,
|
|
73
|
+
data: r.data,
|
|
74
|
+
},
|
|
75
|
+
]
|
|
76
|
+
|
|
71
77
|
const rpc = ox_TransactionRequest.toRpc({
|
|
72
78
|
...request,
|
|
73
79
|
authorizationList: request.authorizationList?.map((auth) => ({
|
|
@@ -78,8 +84,19 @@ export const formatTransactionRequest = (
|
|
|
78
84
|
yParity: Number(auth.yParity),
|
|
79
85
|
})),
|
|
80
86
|
nonce: request.nonce ? BigInt(request.nonce) : undefined,
|
|
81
|
-
type: '
|
|
87
|
+
type: 'aa',
|
|
82
88
|
})
|
|
89
|
+
|
|
90
|
+
if (action === 'estimateGas') {
|
|
91
|
+
rpc.maxFeePerGas = undefined
|
|
92
|
+
rpc.maxPriorityFeePerGas = undefined
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// We rely on `calls` for AA transactions.
|
|
96
|
+
rpc.to = undefined
|
|
97
|
+
rpc.data = undefined
|
|
98
|
+
rpc.value = undefined
|
|
99
|
+
|
|
83
100
|
return {
|
|
84
101
|
...rpc,
|
|
85
102
|
...(request.feePayer
|
|
@@ -90,11 +107,5 @@ export const formatTransactionRequest = (
|
|
|
90
107
|
: request.feePayer,
|
|
91
108
|
}
|
|
92
109
|
: {}),
|
|
93
|
-
...(action === 'estimateGas'
|
|
94
|
-
? {
|
|
95
|
-
maxFeePerGas: undefined,
|
|
96
|
-
maxPriorityFeePerGas: undefined,
|
|
97
|
-
}
|
|
98
|
-
: {}),
|
|
99
110
|
} as never
|
|
100
111
|
}
|