tempo.ts 0.0.0 → 0.0.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.
Files changed (153) hide show
  1. package/README.md +92 -0
  2. package/dist/chains.d.ts +1477 -0
  3. package/dist/chains.d.ts.map +1 -0
  4. package/dist/chains.js +43 -0
  5. package/dist/chains.js.map +1 -0
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +2 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/internal/types.d.ts +284 -0
  11. package/dist/internal/types.d.ts.map +1 -0
  12. package/dist/internal/types.js +2 -0
  13. package/dist/internal/types.js.map +1 -0
  14. package/dist/ox/TokenId.d.ts +18 -0
  15. package/dist/ox/TokenId.d.ts.map +1 -0
  16. package/dist/ox/TokenId.js +29 -0
  17. package/dist/ox/TokenId.js.map +1 -0
  18. package/dist/ox/TokenRole.d.ts +11 -0
  19. package/dist/ox/TokenRole.d.ts.map +1 -0
  20. package/dist/ox/TokenRole.js +22 -0
  21. package/dist/ox/TokenRole.js.map +1 -0
  22. package/dist/ox/Transaction.d.ts +161 -0
  23. package/dist/ox/Transaction.d.ts.map +1 -0
  24. package/dist/ox/Transaction.js +117 -0
  25. package/dist/ox/Transaction.js.map +1 -0
  26. package/dist/ox/TransactionEnvelopeFeeToken.d.ts +393 -0
  27. package/dist/ox/TransactionEnvelopeFeeToken.d.ts.map +1 -0
  28. package/dist/ox/TransactionEnvelopeFeeToken.js +452 -0
  29. package/dist/ox/TransactionEnvelopeFeeToken.js.map +1 -0
  30. package/dist/ox/TransactionRequest.d.ts +62 -0
  31. package/dist/ox/TransactionRequest.d.ts.map +1 -0
  32. package/dist/ox/TransactionRequest.js +66 -0
  33. package/dist/ox/TransactionRequest.js.map +1 -0
  34. package/dist/ox/index.d.ts +5 -0
  35. package/dist/ox/index.d.ts.map +1 -0
  36. package/dist/ox/index.js +5 -0
  37. package/dist/ox/index.js.map +1 -0
  38. package/dist/prool/Instance.d.ts +92 -0
  39. package/dist/prool/Instance.d.ts.map +1 -0
  40. package/dist/prool/Instance.js +96 -0
  41. package/dist/prool/Instance.js.map +1 -0
  42. package/dist/prool/index.d.ts +2 -0
  43. package/dist/prool/index.d.ts.map +1 -0
  44. package/dist/prool/index.js +2 -0
  45. package/dist/prool/index.js.map +1 -0
  46. package/dist/viem/abis.d.ts +2058 -0
  47. package/dist/viem/abis.d.ts.map +1 -0
  48. package/dist/viem/abis.js +1599 -0
  49. package/dist/viem/abis.js.map +1 -0
  50. package/dist/viem/actions/amm.d.ts +2091 -0
  51. package/dist/viem/actions/amm.d.ts.map +1 -0
  52. package/dist/viem/actions/amm.js +876 -0
  53. package/dist/viem/actions/amm.js.map +1 -0
  54. package/dist/viem/actions/fee.d.ts +727 -0
  55. package/dist/viem/actions/fee.d.ts.map +1 -0
  56. package/dist/viem/actions/fee.js +230 -0
  57. package/dist/viem/actions/fee.js.map +1 -0
  58. package/dist/viem/actions/index.d.ts +5 -0
  59. package/dist/viem/actions/index.d.ts.map +1 -0
  60. package/dist/viem/actions/index.js +5 -0
  61. package/dist/viem/actions/index.js.map +1 -0
  62. package/dist/viem/actions/policy.d.ts +1900 -0
  63. package/dist/viem/actions/policy.d.ts.map +1 -0
  64. package/dist/viem/actions/policy.js +841 -0
  65. package/dist/viem/actions/policy.js.map +1 -0
  66. package/dist/viem/actions/token.d.ts +13759 -0
  67. package/dist/viem/actions/token.d.ts.map +1 -0
  68. package/dist/viem/actions/token.js +2579 -0
  69. package/dist/viem/actions/token.js.map +1 -0
  70. package/dist/viem/addresses.d.ts +8 -0
  71. package/dist/viem/addresses.d.ts.map +1 -0
  72. package/dist/viem/addresses.js +8 -0
  73. package/dist/viem/addresses.js.map +1 -0
  74. package/dist/viem/chain.d.ts +341 -0
  75. package/dist/viem/chain.d.ts.map +1 -0
  76. package/dist/viem/chain.js +22 -0
  77. package/dist/viem/chain.js.map +1 -0
  78. package/dist/viem/client.d.ts +27 -0
  79. package/dist/viem/client.d.ts.map +1 -0
  80. package/dist/viem/client.js +28 -0
  81. package/dist/viem/client.js.map +1 -0
  82. package/dist/viem/decorator.d.ts +1636 -0
  83. package/dist/viem/decorator.d.ts.map +1 -0
  84. package/dist/viem/decorator.js +95 -0
  85. package/dist/viem/decorator.js.map +1 -0
  86. package/dist/viem/formatters.d.ts +4 -0
  87. package/dist/viem/formatters.d.ts.map +1 -0
  88. package/dist/viem/formatters.js +69 -0
  89. package/dist/viem/formatters.js.map +1 -0
  90. package/dist/viem/index.d.ts +9 -0
  91. package/dist/viem/index.d.ts.map +1 -0
  92. package/dist/viem/index.js +9 -0
  93. package/dist/viem/index.js.map +1 -0
  94. package/dist/viem/transaction.d.ts +54 -0
  95. package/dist/viem/transaction.d.ts.map +1 -0
  96. package/dist/viem/transaction.js +108 -0
  97. package/dist/viem/transaction.js.map +1 -0
  98. package/dist/viem/transport.d.ts +16 -0
  99. package/dist/viem/transport.d.ts.map +1 -0
  100. package/dist/viem/transport.js +33 -0
  101. package/dist/viem/transport.js.map +1 -0
  102. package/dist/viem/types.d.ts +10 -0
  103. package/dist/viem/types.d.ts.map +1 -0
  104. package/dist/viem/types.js +2 -0
  105. package/dist/viem/types.js.map +1 -0
  106. package/dist/viem/utils.d.ts +8 -0
  107. package/dist/viem/utils.d.ts.map +1 -0
  108. package/dist/viem/utils.js +9 -0
  109. package/dist/viem/utils.js.map +1 -0
  110. package/package.json +100 -2
  111. package/src/chains.ts +46 -0
  112. package/src/index.ts +1 -0
  113. package/src/internal/types.ts +414 -0
  114. package/src/ox/TokenId.test.ts +29 -0
  115. package/src/ox/TokenId.ts +35 -0
  116. package/src/ox/TokenRole.test.ts +20 -0
  117. package/src/ox/TokenRole.ts +27 -0
  118. package/src/ox/Transaction.test.ts +257 -0
  119. package/src/ox/Transaction.ts +247 -0
  120. package/src/ox/TransactionEnvelopeFeeToken.test.ts +1215 -0
  121. package/src/ox/TransactionEnvelopeFeeToken.ts +717 -0
  122. package/src/ox/TransactionRequest.ts +100 -0
  123. package/src/ox/index.ts +4 -0
  124. package/src/prool/Instance.test.ts +43 -0
  125. package/src/prool/Instance.ts +190 -0
  126. package/src/prool/index.ts +1 -0
  127. package/src/prool/internal/chain.json +106 -0
  128. package/src/prool/internal/consensus.toml +32 -0
  129. package/src/viem/abis.ts +1606 -0
  130. package/src/viem/actions/amm.test.ts +425 -0
  131. package/src/viem/actions/amm.ts +1308 -0
  132. package/src/viem/actions/fee.test.ts +281 -0
  133. package/src/viem/actions/fee.ts +362 -0
  134. package/src/viem/actions/index.ts +4 -0
  135. package/src/viem/actions/policy.test.ts +514 -0
  136. package/src/viem/actions/policy.ts +1284 -0
  137. package/src/viem/actions/token.test.ts +2172 -0
  138. package/src/viem/actions/token.ts +3830 -0
  139. package/src/viem/addresses.ts +10 -0
  140. package/src/viem/chain.ts +27 -0
  141. package/src/viem/client.bench-d.ts +8 -0
  142. package/src/viem/client.test.ts +152 -0
  143. package/src/viem/client.ts +91 -0
  144. package/src/viem/decorator.bench-d.ts +11 -0
  145. package/src/viem/decorator.test.ts +35 -0
  146. package/src/viem/decorator.ts +1914 -0
  147. package/src/viem/e2e.test.ts +410 -0
  148. package/src/viem/formatters.ts +100 -0
  149. package/src/viem/index.ts +8 -0
  150. package/src/viem/transaction.ts +253 -0
  151. package/src/viem/transport.ts +47 -0
  152. package/src/viem/types.ts +55 -0
  153. package/src/viem/utils.ts +37 -0
@@ -0,0 +1,100 @@
1
+ import type * as Authorization from 'ox/Authorization'
2
+ import type * as Errors from 'ox/Errors'
3
+ import type * as Calls from 'ox/erc7821/Calls'
4
+ import * as Execute from 'ox/erc7821/Execute'
5
+ import type * as Hex from 'ox/Hex'
6
+ import * as ox_TransactionRequest from 'ox/TransactionRequest'
7
+ import type { Compute } from '../internal/types.js'
8
+ import * as TokenId from './TokenId.js'
9
+ import * as Transaction from './Transaction.js'
10
+
11
+ /** A Transaction Request that is generic to all transaction types, as defined in the [Execution API specification](https://github.com/ethereum/execution-apis/blob/4aca1d7a3e5aab24c8f6437131289ad386944eaa/src/schemas/transaction.yaml#L358-L423). */
12
+ export type TransactionRequest<
13
+ bigintType = bigint,
14
+ numberType = number,
15
+ type extends string = string,
16
+ > = Compute<
17
+ ox_TransactionRequest.TransactionRequest<bigintType, numberType, type> & {
18
+ calls?: readonly Calls.Call[] | undefined
19
+ feeToken?: TokenId.TokenIdOrAddress | undefined
20
+ }
21
+ >
22
+
23
+ /** RPC representation of a {@link ox#TransactionRequest.TransactionRequest}. */
24
+ export type Rpc = TransactionRequest<Hex.Hex, Hex.Hex, string>
25
+
26
+ /**
27
+ * Converts a {@link ox#TransactionRequest.TransactionRequest} to a {@link ox#TransactionRequest.Rpc}.
28
+ *
29
+ * @example
30
+ * ```ts twoslash
31
+ * import { Value } from 'ox'
32
+ * import { TransactionRequest } from 'ox/tempo'
33
+ *
34
+ * const request = TransactionRequest.toRpc({
35
+ * feeToken: '0x20c0000000000000000000000000000000000000',
36
+ * to: '0x0000000000000000000000000000000000000000',
37
+ * value: Value.fromEther('0.01'),
38
+ * })
39
+ * ```
40
+ *
41
+ * @example
42
+ * ### Using with a Provider
43
+ *
44
+ * You can use {@link ox#Provider.(from:function)} to instantiate an EIP-1193 Provider and
45
+ * send a transaction to the Wallet using the `eth_sendTransaction` method.
46
+ *
47
+ * ```ts twoslash
48
+ * import 'ox/window'
49
+ * import { Provider, Value } from 'ox'
50
+ * import { TransactionRequest } from 'ox/tempo'
51
+ *
52
+ * const provider = Provider.from(window.ethereum!)
53
+ *
54
+ * const request = TransactionRequest.toRpc({
55
+ * feeToken: '0x20c0000000000000000000000000000000000000',
56
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
57
+ * value: Value.fromEther('0.01'),
58
+ * })
59
+ *
60
+ * const hash = await provider.request({ // [!code focus]
61
+ * method: 'eth_sendTransaction', // [!code focus]
62
+ * params: [request], // [!code focus]
63
+ * }) // [!code focus]
64
+ * ```
65
+ *
66
+ * @param request - The request to convert.
67
+ * @returns An RPC request.
68
+ */
69
+ export function toRpc(request: TransactionRequest): Rpc {
70
+ const request_rpc = ox_TransactionRequest.toRpc(request) as Rpc
71
+
72
+ request_rpc.calls = request.calls
73
+
74
+ if (typeof request.feeToken !== 'undefined')
75
+ request_rpc.feeToken = TokenId.toAddress(request.feeToken)
76
+
77
+ if (request.calls && request.from) {
78
+ delete request_rpc.to
79
+ delete request_rpc.value
80
+ delete request_rpc.data
81
+ request_rpc.to = request.from
82
+ request_rpc.data = Execute.encodeData(request.calls)
83
+ }
84
+
85
+ if (
86
+ request.calls ||
87
+ typeof request.feeToken !== 'undefined' ||
88
+ request.type === 'feeToken'
89
+ )
90
+ request_rpc.type = Transaction.toRpcType.feeToken
91
+
92
+ return request_rpc
93
+ }
94
+
95
+ export declare namespace toRpc {
96
+ export type ErrorType =
97
+ | Authorization.toRpcList.ErrorType
98
+ | Hex.fromNumber.ErrorType
99
+ | Errors.GlobalErrorType
100
+ }
@@ -0,0 +1,4 @@
1
+ export * as TokenId from './TokenId.js'
2
+ export * as TokenRole from './TokenRole.js'
3
+ export * as Transaction from './Transaction.js'
4
+ export * as TransactionEnvelopeFeeToken from './TransactionEnvelopeFeeToken.js'
@@ -0,0 +1,43 @@
1
+ import type { Instance as prool_Instance } from 'prool/instances'
2
+ import { Instance } from 'tempo.ts/prool'
3
+ import { afterEach, describe, expect, test } from 'vitest'
4
+
5
+ const instances: prool_Instance[] = []
6
+
7
+ const tempo = (parameters: Instance.tempo.Parameters = {}) => {
8
+ const instance = Instance.tempo({ ...parameters, port: 8888 })
9
+ instances.push(instance)
10
+ return instance
11
+ }
12
+
13
+ afterEach(async () => {
14
+ for (const instance of instances) await instance.stop().catch(() => {})
15
+ })
16
+
17
+ describe('tempo', () => {
18
+ test('default', async () => {
19
+ const messages: string[] = []
20
+ const stdouts: string[] = []
21
+
22
+ const instance = tempo()
23
+
24
+ instance.on('message', (m) => messages.push(m))
25
+ instance.on('stdout', (m) => stdouts.push(m))
26
+
27
+ expect(instance.messages.get()).toMatchInlineSnapshot('[]')
28
+
29
+ await instance.start()
30
+ expect(instance.status).toEqual('started')
31
+
32
+ expect(messages.join('')).toBeDefined()
33
+ expect(stdouts.join('')).toBeDefined()
34
+ expect(instance.messages.get().join('')).toBeDefined()
35
+
36
+ await instance.stop()
37
+ expect(instance.status).toEqual('stopped')
38
+
39
+ expect(messages.join('')).toBeDefined()
40
+ expect(stdouts.join('')).toBeDefined()
41
+ expect(instance.messages.get()).toMatchInlineSnapshot('[]')
42
+ })
43
+ })
@@ -0,0 +1,190 @@
1
+ import * as fs from 'node:fs'
2
+ import * as path from 'node:path'
3
+ import { toArgs } from 'prool'
4
+ import { defineInstance } from 'prool/instances'
5
+ import { execa } from 'prool/processes'
6
+
7
+ /**
8
+ * Defines a Tempo instance.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const instance = tempo()
13
+ * await instance.start()
14
+ * // ...
15
+ * await instance.stop()
16
+ * ```
17
+ */
18
+ export const tempo = defineInstance((parameters: tempo.Parameters = {}) => {
19
+ const {
20
+ binary = 'tempo',
21
+ builder,
22
+ chain = path.resolve(import.meta.dirname, './internal/chain.json'),
23
+ consensusConfig = path.resolve(
24
+ import.meta.dirname,
25
+ './internal/consensus.toml',
26
+ ),
27
+ dev,
28
+ faucet,
29
+ ...args
30
+ } = parameters
31
+ const { deadline = 3, gaslimit = 3000000000, maxTasks = 8 } = builder ?? {}
32
+ const { blockTime = '2ms' } = dev ?? {}
33
+ const {
34
+ address = '0x20c0000000000000000000000000000000000000',
35
+ amount = 1000000000000000,
36
+ privateKey = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
37
+ } = faucet ?? {}
38
+
39
+ const name = 'tempo'
40
+ const process = execa({ name })
41
+
42
+ const tmp = `./tmp/${crypto.randomUUID()}`
43
+
44
+ return {
45
+ _internal: {
46
+ args,
47
+ get process() {
48
+ return process._internal.process
49
+ },
50
+ },
51
+ host: args.host ?? 'localhost',
52
+ name,
53
+ port: args.port ?? 8545,
54
+ async start({ port = args.port }, options) {
55
+ try {
56
+ fs.rmSync(tmp, { recursive: true })
57
+ } catch {}
58
+ fs.mkdirSync(tmp, { recursive: true })
59
+ return await process.start(
60
+ ($) =>
61
+ $`${binary} node --http --dev --engine.disable-precompile-cache --faucet.enabled ${toArgs(
62
+ {
63
+ ...args,
64
+ builder: {
65
+ deadline,
66
+ gaslimit,
67
+ maxTasks,
68
+ },
69
+ chain,
70
+ consensusConfig,
71
+ datadir: `${tmp}/data`,
72
+ dev: {
73
+ blockTime,
74
+ },
75
+ faucet: {
76
+ address,
77
+ amount,
78
+ privateKey,
79
+ },
80
+ port: port! + 1,
81
+ http: {
82
+ addr: '0.0.0.0',
83
+ port: port!,
84
+ },
85
+ ws: {
86
+ port: port! + 2,
87
+ },
88
+ authrpc: {
89
+ port: port! + 3,
90
+ },
91
+ },
92
+ )}`,
93
+ {
94
+ ...options,
95
+ resolver({ process, reject, resolve }) {
96
+ process.stdout.on('data', (data) => {
97
+ const message = data.toString()
98
+ if (message.includes('shutting down')) reject(message)
99
+ if (message.includes('RPC HTTP server started')) resolve()
100
+ })
101
+ process.stderr.on('data', (data) => {
102
+ const message = data.toString()
103
+ reject(message)
104
+ })
105
+ },
106
+ },
107
+ )
108
+ },
109
+ async stop() {
110
+ try {
111
+ fs.rmSync(tmp, { recursive: true })
112
+ } catch {}
113
+ await process.stop()
114
+ },
115
+ }
116
+ })
117
+
118
+ export declare namespace tempo {
119
+ export type Parameters = {
120
+ /**
121
+ * Path or alias to the Tempo binary.
122
+ */
123
+ binary?: string | undefined
124
+ /**
125
+ * Builder options.
126
+ */
127
+ builder?:
128
+ | {
129
+ /**
130
+ * The deadline for when the payload builder job should resolve.
131
+ */
132
+ deadline?: number | undefined
133
+ /**
134
+ * Target gas limit for built blocks.
135
+ */
136
+ gaslimit?: bigint | undefined
137
+ /**
138
+ * Maximum number of tasks to spawn for building a payload.
139
+ */
140
+ maxTasks?: number | undefined
141
+ }
142
+ | undefined
143
+ /**
144
+ * Chain this node is running.
145
+ */
146
+ chain?: string | undefined
147
+ /**
148
+ * Consensus configuration for this node.
149
+ */
150
+ consensusConfig?: string | undefined
151
+ /**
152
+ * Development options.
153
+ */
154
+ dev?:
155
+ | {
156
+ /**
157
+ * Interval between blocks.
158
+ */
159
+ blockTime?: number | undefined
160
+ }
161
+ | undefined
162
+ /**
163
+ * Faucet options.
164
+ */
165
+ faucet?:
166
+ | {
167
+ /**
168
+ * Target token address for the faucet to be funding with
169
+ */
170
+ address?: string | undefined
171
+ /**
172
+ * Amount for each faucet funding transaction
173
+ */
174
+ amount?: bigint | undefined
175
+ /**
176
+ * Faucet funding mnemonic
177
+ */
178
+ privateKey?: string | undefined
179
+ }
180
+ | undefined
181
+ /**
182
+ * Host the server will listen on.
183
+ */
184
+ host?: string | undefined
185
+ /**
186
+ * Port the server will listen on.
187
+ */
188
+ port?: number | undefined
189
+ }
190
+ }
@@ -0,0 +1 @@
1
+ export * as Instance from './Instance.js'