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,452 @@
1
+ import * as AccessList from 'ox/AccessList';
2
+ import * as Address from 'ox/Address';
3
+ import * as Authorization from 'ox/Authorization';
4
+ import * as Hash from 'ox/Hash';
5
+ import * as Hex from 'ox/Hex';
6
+ import * as Rlp from 'ox/Rlp';
7
+ import * as Signature from 'ox/Signature';
8
+ import * as TransactionEnvelope from 'ox/TransactionEnvelope';
9
+ import * as TransactionEnvelopeEip1559 from 'ox/TransactionEnvelopeEip1559';
10
+ import * as TokenId from "./TokenId.js";
11
+ export const feePayerMagic = '0x78';
12
+ export const serializedType = '0x77';
13
+ export const type = 'feeToken';
14
+ /**
15
+ * Asserts a {@link ox#TransactionEnvelopeFeeToken.TransactionEnvelopeFeeToken} is valid.
16
+ *
17
+ * @example
18
+ * ```ts twoslash
19
+ * import { Value } from 'ox'
20
+ * import { TransactionEnvelopeFeeToken } from 'ox/tempo'
21
+ *
22
+ * TransactionEnvelopeFeeToken.assert({
23
+ * feeToken: '0x20c0000000000000000000000000000000000000',
24
+ * maxFeePerGas: 2n ** 256n - 1n + 1n,
25
+ * chainId: 1,
26
+ * to: '0x0000000000000000000000000000000000000000',
27
+ * value: Value.fromEther('1'),
28
+ * })
29
+ * // @error: FeeCapTooHighError:
30
+ * // @error: The fee cap (`masFeePerGas` = 115792089237316195423570985008687907853269984665640564039457584007913 gwei) cannot be
31
+ * // @error: higher than the maximum allowed value (2^256-1).
32
+ * ```
33
+ *
34
+ * @param envelope - The transaction envelope to assert.
35
+ */
36
+ export function assert(envelope) {
37
+ const { authorizationList } = envelope;
38
+ if (authorizationList) {
39
+ for (const authorization of authorizationList) {
40
+ const { address, chainId } = authorization;
41
+ if (address)
42
+ Address.assert(address, { strict: false });
43
+ if (Number(chainId) < 0)
44
+ throw new TransactionEnvelope.InvalidChainIdError({ chainId });
45
+ }
46
+ }
47
+ TransactionEnvelopeEip1559.assert(envelope);
48
+ }
49
+ /**
50
+ * Deserializes a {@link ox#TransactionEnvelopeFeeToken.TransactionEnvelopeFeeToken} from its serialized form.
51
+ *
52
+ * @example
53
+ * ```ts twoslash
54
+ * import { TransactionEnvelopeFeeToken } from 'ox/tempo'
55
+ *
56
+ * const envelope = TransactionEnvelopeFeeToken.deserialize('0x77ef0182031184773594008477359400809470997970c51812dc3a010c7d01b50e0d17dc79c8880de0b6b3a764000080c0')
57
+ * // @log: {
58
+ * // @log: type: 'feeToken',
59
+ * // @log: nonce: 785n,
60
+ * // @log: maxFeePerGas: 2000000000n,
61
+ * // @log: gas: 1000000n,
62
+ * // @log: to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
63
+ * // @log: value: 1000000000000000000n,
64
+ * // @log: }
65
+ * ```
66
+ *
67
+ * @param serialized - The serialized transaction.
68
+ * @returns Deserialized Transaction Envelope.
69
+ */
70
+ export function deserialize(serialized) {
71
+ const transactionArray = Rlp.toHex(Hex.slice(serialized, 1));
72
+ const [chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gas, to, value, data, accessList, authorizationList, feeToken, feePayerSignatureOrSender, yParity, r, s,] = transactionArray;
73
+ if (!(transactionArray.length === 12 || transactionArray.length === 15))
74
+ throw new TransactionEnvelope.InvalidSerializedError({
75
+ attributes: {
76
+ chainId,
77
+ nonce,
78
+ feeToken,
79
+ maxPriorityFeePerGas,
80
+ maxFeePerGas,
81
+ gas,
82
+ to,
83
+ value,
84
+ data,
85
+ accessList,
86
+ authorizationList,
87
+ feePayerSignatureOrSender,
88
+ ...(transactionArray.length > 9
89
+ ? {
90
+ yParity,
91
+ r,
92
+ s,
93
+ }
94
+ : {}),
95
+ },
96
+ serialized,
97
+ type,
98
+ });
99
+ let transaction = {
100
+ chainId: Number(chainId),
101
+ type,
102
+ };
103
+ if (Hex.validate(to) && to !== '0x')
104
+ transaction.to = to;
105
+ if (Hex.validate(feeToken) && feeToken !== '0x')
106
+ transaction.feeToken = feeToken;
107
+ if (Hex.validate(gas) && gas !== '0x')
108
+ transaction.gas = BigInt(gas);
109
+ if (Hex.validate(data) && data !== '0x')
110
+ transaction.data = data;
111
+ if (Hex.validate(nonce))
112
+ transaction.nonce = nonce === '0x' ? 0n : BigInt(nonce);
113
+ if (Hex.validate(value) && value !== '0x')
114
+ transaction.value = BigInt(value);
115
+ if (Hex.validate(maxFeePerGas) && maxFeePerGas !== '0x')
116
+ transaction.maxFeePerGas = BigInt(maxFeePerGas);
117
+ if (Hex.validate(maxPriorityFeePerGas) && maxPriorityFeePerGas !== '0x')
118
+ transaction.maxPriorityFeePerGas = BigInt(maxPriorityFeePerGas);
119
+ if (accessList?.length !== 0 && accessList !== '0x')
120
+ transaction.accessList = AccessList.fromTupleList(accessList);
121
+ if (authorizationList !== '0x' && (authorizationList?.length ?? 0) > 0)
122
+ transaction.authorizationList = Authorization.fromTupleList(authorizationList);
123
+ if (feePayerSignatureOrSender !== '0x' &&
124
+ feePayerSignatureOrSender !== undefined) {
125
+ if (feePayerSignatureOrSender === '0x00' ||
126
+ Address.validate(feePayerSignatureOrSender))
127
+ transaction.feePayerSignature = null;
128
+ else
129
+ transaction.feePayerSignature = Signature.fromTuple(feePayerSignatureOrSender);
130
+ }
131
+ const signature = r && s && yParity ? Signature.fromTuple([yParity, r, s]) : undefined;
132
+ if (signature)
133
+ transaction = {
134
+ ...transaction,
135
+ ...signature,
136
+ };
137
+ assert(transaction);
138
+ return transaction;
139
+ }
140
+ /**
141
+ * Converts an arbitrary transaction object into an Fee Token Transaction Envelope.
142
+ *
143
+ * @example
144
+ * ```ts twoslash
145
+ * import { Value } from 'ox'
146
+ * import { TransactionEnvelopeFeeToken } from 'ox/tempo'
147
+ *
148
+ * const envelope = TransactionEnvelopeFeeToken.from({ // [!code focus]
149
+ * chainId: 1, // [!code focus]
150
+ * feeToken: '0x20c0000000000000000000000000000000000000', // [!code focus]
151
+ * maxFeePerGas: Value.fromGwei('10'), // [!code focus]
152
+ * maxPriorityFeePerGas: Value.fromGwei('1'), // [!code focus]
153
+ * to: '0x0000000000000000000000000000000000000000', // [!code focus]
154
+ * value: Value.fromEther('1'), // [!code focus]
155
+ * }) // [!code focus]
156
+ * ```
157
+ *
158
+ * @example
159
+ * ### Attaching Signatures
160
+ *
161
+ * It is possible to attach a `signature` to the transaction envelope.
162
+ *
163
+ * ```ts twoslash
164
+ * // @noErrors
165
+ * import { Secp256k1, Value } from 'ox'
166
+ * import { TransactionEnvelopeFeeToken } from 'ox/tempo'
167
+ *
168
+ * const envelope = TransactionEnvelopeFeeToken.from({
169
+ * chainId: 1,
170
+ * feeToken: '0x20c0000000000000000000000000000000000000',
171
+ * maxFeePerGas: Value.fromGwei('10'),
172
+ * maxPriorityFeePerGas: Value.fromGwei('1'),
173
+ * to: '0x0000000000000000000000000000000000000000',
174
+ * value: Value.fromEther('1'),
175
+ * })
176
+ *
177
+ * const signature = Secp256k1.sign({
178
+ * payload: TransactionEnvelopeFeeToken.getSignPayload(envelope),
179
+ * privateKey: '0x...',
180
+ * })
181
+ *
182
+ * const envelope_signed = TransactionEnvelopeFeeToken.from(envelope, { // [!code focus]
183
+ * signature, // [!code focus]
184
+ * }) // [!code focus]
185
+ * // @log: {
186
+ * // @log: chainId: 1,
187
+ * // @log: feeToken: '0x20c0000000000000000000000000000000000000',
188
+ * // @log: maxFeePerGas: 10000000000n,
189
+ * // @log: maxPriorityFeePerGas: 1000000000n,
190
+ * // @log: to: '0x0000000000000000000000000000000000000000',
191
+ * // @log: type: 'feeToken',
192
+ * // @log: value: 1000000000000000000n,
193
+ * // @log: r: 125...n,
194
+ * // @log: s: 642...n,
195
+ * // @log: yParity: 0,
196
+ * // @log: }
197
+ * ```
198
+ *
199
+ * @example
200
+ * ### From Serialized
201
+ *
202
+ * It is possible to instantiate an Fee Token Transaction Envelope from a {@link ox#TransactionEnvelopeFeeToken.Serialized} value.
203
+ *
204
+ * ```ts twoslash
205
+ * import { TransactionEnvelopeFeeToken } from 'ox/tempo'
206
+ *
207
+ * const envelope = TransactionEnvelopeFeeToken.from('0x77f858018203118502540be4008504a817c800809470997970c51812dc3a010c7d01b50e0d17dc79c8880de0b6b3a764000080c08477359400e1a001627c687261b0e7f8638af1112efa8a77e23656f6e7945275b19e9deed80261')
208
+ * // @log: {
209
+ * // @log: chainId: 1,
210
+ * // @log: feeToken: '0x20c0000000000000000000000000000000000000',
211
+ * // @log: maxFeePerGas: 10000000000n,
212
+ * // @log: to: '0x0000000000000000000000000000000000000000',
213
+ * // @log: type: 'feeToken',
214
+ * // @log: value: 1000000000000000000n,
215
+ * // @log: }
216
+ * ```
217
+ *
218
+ * @param envelope - The transaction object to convert.
219
+ * @param options - Options.
220
+ * @returns An Fee Token Transaction Envelope.
221
+ */
222
+ export function from(envelope, options = {}) {
223
+ const { feePayerSignature, signature } = options;
224
+ const envelope_ = (typeof envelope === 'string' ? deserialize(envelope) : envelope);
225
+ assert(envelope_);
226
+ return {
227
+ ...envelope_,
228
+ ...(signature ? Signature.from(signature) : {}),
229
+ ...(feePayerSignature
230
+ ? { feePayerSignature: Signature.from(feePayerSignature) }
231
+ : {}),
232
+ type: 'feeToken',
233
+ };
234
+ }
235
+ /**
236
+ * Returns the fee payer payload to sign for a {@link ox#TransactionEnvelopeFeeToken.TransactionEnvelopeFeeToken}.
237
+ *
238
+ * @example
239
+ * TODO
240
+ *
241
+ * @param envelope - The transaction envelope to get the fee payer sign payload for.
242
+ * @returns The fee payer sign payload.
243
+ */
244
+ export function getFeePayerSignPayload(envelope, options) {
245
+ const { sender } = options;
246
+ const serialized = serialize({ ...envelope, r: undefined, s: undefined, yParity: undefined }, {
247
+ sender,
248
+ format: 'feePayer',
249
+ });
250
+ return Hash.keccak256(serialized);
251
+ }
252
+ /**
253
+ * Returns the payload to sign for a {@link ox#TransactionEnvelopeFeeToken.TransactionEnvelopeFeeToken}.
254
+ *
255
+ * @example
256
+ * The example below demonstrates how to compute the sign payload which can be used
257
+ * with ECDSA signing utilities like {@link ox#Secp256k1.(sign:function)}.
258
+ *
259
+ * ```ts twoslash
260
+ * // @noErrors
261
+ * import { Secp256k1 } from 'ox'
262
+ * import { TransactionEnvelopeFeeToken } from 'ox/tempo'
263
+ *
264
+ * const envelope = TransactionEnvelopeFeeToken.from({
265
+ * chainId: 1,
266
+ * feeToken: '0x20c0000000000000000000000000000000000000',
267
+ * nonce: 0n,
268
+ * maxFeePerGas: 1000000000n,
269
+ * gas: 21000n,
270
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
271
+ * value: 1000000000000000000n,
272
+ * })
273
+ *
274
+ * const payload = TransactionEnvelopeFeeToken.getSignPayload(envelope) // [!code focus]
275
+ * // @log: '0x...'
276
+ *
277
+ * const signature = Secp256k1.sign({ payload, privateKey: '0x...' })
278
+ * ```
279
+ *
280
+ * @param envelope - The transaction envelope to get the sign payload for.
281
+ * @returns The sign payload.
282
+ */
283
+ export function getSignPayload(envelope) {
284
+ return hash(envelope, { presign: true });
285
+ }
286
+ /**
287
+ * Hashes a {@link ox#TransactionEnvelopeFeeToken.TransactionEnvelopeFeeToken}. This is the "transaction hash".
288
+ *
289
+ * @example
290
+ * ```ts twoslash
291
+ * // @noErrors
292
+ * import { Secp256k1 } from 'ox'
293
+ * import { TransactionEnvelopeFeeToken } from 'ox/tempo'
294
+ *
295
+ * const envelope = TransactionEnvelopeFeeToken.from({
296
+ * chainId: 1,
297
+ * feeToken: '0x20c0000000000000000000000000000000000000',
298
+ * nonce: 0n,
299
+ * maxFeePerGas: 1000000000n,
300
+ * gas: 21000n,
301
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
302
+ * value: 1000000000000000000n,
303
+ * })
304
+ *
305
+ * const signature = Secp256k1.sign({
306
+ * payload: TransactionEnvelopeFeeToken.getSignPayload(envelope),
307
+ * privateKey: '0x...'
308
+ * })
309
+ *
310
+ * const envelope_signed = TransactionEnvelopeFeeToken.from(envelope, { signature })
311
+ *
312
+ * const hash = TransactionEnvelopeFeeToken.hash(envelope_signed) // [!code focus]
313
+ * ```
314
+ *
315
+ * @param envelope - The Fee Token Transaction Envelope to hash.
316
+ * @param options - Options.
317
+ * @returns The hash of the transaction envelope.
318
+ */
319
+ export function hash(envelope, options = {}) {
320
+ const serialized = serialize({
321
+ ...envelope,
322
+ ...(options.presign
323
+ ? {
324
+ r: undefined,
325
+ s: undefined,
326
+ yParity: undefined,
327
+ }
328
+ : {}),
329
+ });
330
+ return Hash.keccak256(serialized);
331
+ }
332
+ /**
333
+ * Serializes a {@link ox#TransactionEnvelopeFeeToken.TransactionEnvelopeFeeToken}.
334
+ *
335
+ * @example
336
+ * ```ts twoslash
337
+ * // @noErrors
338
+ * import { Value } from 'ox'
339
+ * import { TransactionEnvelopeFeeToken } from 'ox/tempo'
340
+ *
341
+ * const envelope = TransactionEnvelopeFeeToken.from({
342
+ * chainId: 1,
343
+ * feeToken: '0x20c0000000000000000000000000000000000000',
344
+ * maxFeePerGas: Value.fromGwei('10'),
345
+ * to: '0x0000000000000000000000000000000000000000',
346
+ * value: Value.fromEther('1'),
347
+ * })
348
+ *
349
+ * const serialized = TransactionEnvelopeFeeToken.serialize(envelope) // [!code focus]
350
+ * ```
351
+ *
352
+ * @example
353
+ * ### Attaching Signatures
354
+ *
355
+ * It is possible to attach a `signature` to the serialized Transaction Envelope.
356
+ *
357
+ * ```ts twoslash
358
+ * // @noErrors
359
+ * import { Secp256k1, Value } from 'ox'
360
+ * import { TransactionEnvelopeFeeToken } from 'ox/tempo'
361
+ *
362
+ * const envelope = TransactionEnvelopeFeeToken.from({
363
+ * chainId: 1,
364
+ * feeToken: '0x20c0000000000000000000000000000000000000',
365
+ * maxFeePerGas: Value.fromGwei('10'),
366
+ * to: '0x0000000000000000000000000000000000000000',
367
+ * value: Value.fromEther('1'),
368
+ * })
369
+ *
370
+ * const signature = Secp256k1.sign({
371
+ * payload: TransactionEnvelopeFeeToken.getSignPayload(envelope),
372
+ * privateKey: '0x...',
373
+ * })
374
+ *
375
+ * const serialized = TransactionEnvelopeFeeToken.serialize(envelope, { // [!code focus]
376
+ * signature, // [!code focus]
377
+ * }) // [!code focus]
378
+ *
379
+ * // ... send `serialized` transaction to JSON-RPC `eth_sendRawTransaction`
380
+ * ```
381
+ *
382
+ * @param envelope - The Transaction Envelope to serialize.
383
+ * @param options - Options.
384
+ * @returns The serialized Transaction Envelope.
385
+ */
386
+ export function serialize(envelope, options = {}) {
387
+ const { authorizationList, chainId, feeToken, gas, nonce, to, value, maxFeePerGas, maxPriorityFeePerGas, accessList, data, input, } = envelope;
388
+ assert(envelope);
389
+ const accessTupleList = AccessList.toTupleList(accessList);
390
+ const authorizationTupleList = Authorization.toTupleList(authorizationList);
391
+ const signature = Signature.extract(options.signature || envelope);
392
+ const feePayerSignatureOrSender = (() => {
393
+ if (options.sender)
394
+ return options.sender;
395
+ const feePayerSignature = typeof options.feePayerSignature !== 'undefined'
396
+ ? options.feePayerSignature
397
+ : envelope.feePayerSignature;
398
+ if (feePayerSignature === null)
399
+ return '0x00';
400
+ if (!feePayerSignature)
401
+ return '0x';
402
+ return Signature.toTuple(feePayerSignature);
403
+ })();
404
+ const serialized = [
405
+ Hex.fromNumber(chainId),
406
+ nonce ? Hex.fromNumber(nonce) : '0x',
407
+ maxPriorityFeePerGas ? Hex.fromNumber(maxPriorityFeePerGas) : '0x',
408
+ maxFeePerGas ? Hex.fromNumber(maxFeePerGas) : '0x',
409
+ gas ? Hex.fromNumber(gas) : '0x',
410
+ to ?? '0x',
411
+ value ? Hex.fromNumber(value) : '0x',
412
+ data ?? input ?? '0x',
413
+ accessTupleList,
414
+ authorizationTupleList,
415
+ typeof feeToken === 'bigint' || typeof feeToken === 'string'
416
+ ? TokenId.toAddress(feeToken)
417
+ : '0x',
418
+ feePayerSignatureOrSender,
419
+ ...(signature ? Signature.toTuple(signature) : []),
420
+ ];
421
+ return Hex.concat(options.format === 'feePayer' ? feePayerMagic : serializedType, Rlp.fromHex(serialized));
422
+ }
423
+ /**
424
+ * Validates a {@link ox#TransactionEnvelopeFeeToken.TransactionEnvelopeFeeToken}. Returns `true` if the envelope is valid, `false` otherwise.
425
+ *
426
+ * @example
427
+ * ```ts twoslash
428
+ * import { Value } from 'ox'
429
+ * import { TransactionEnvelopeFeeToken } from 'ox/tempo'
430
+ *
431
+ * const valid = TransactionEnvelopeFeeToken.validate({
432
+ * feeToken: '0x20c0000000000000000000000000000000000000',
433
+ * maxFeePerGas: 2n ** 256n - 1n + 1n,
434
+ * chainId: 1,
435
+ * to: '0x0000000000000000000000000000000000000000',
436
+ * value: Value.fromEther('1'),
437
+ * })
438
+ * // @log: false
439
+ * ```
440
+ *
441
+ * @param envelope - The transaction envelope to validate.
442
+ */
443
+ export function validate(envelope) {
444
+ try {
445
+ assert(envelope);
446
+ return true;
447
+ }
448
+ catch {
449
+ return false;
450
+ }
451
+ }
452
+ //# sourceMappingURL=TransactionEnvelopeFeeToken.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransactionEnvelopeFeeToken.js","sourceRoot":"","sources":["../../src/ox/TransactionEnvelopeFeeToken.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,eAAe,CAAA;AAC3C,OAAO,KAAK,OAAO,MAAM,YAAY,CAAA;AACrC,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAA;AAEjD,OAAO,KAAK,IAAI,MAAM,SAAS,CAAA;AAC/B,OAAO,KAAK,GAAG,MAAM,QAAQ,CAAA;AAC7B,OAAO,KAAK,GAAG,MAAM,QAAQ,CAAA;AAC7B,OAAO,KAAK,SAAS,MAAM,cAAc,CAAA;AACzC,OAAO,KAAK,mBAAmB,MAAM,wBAAwB,CAAA;AAC7D,OAAO,KAAK,0BAA0B,MAAM,+BAA+B,CAAA;AAQ3E,OAAO,KAAK,OAAO,qBAAoB;AAoCvC,MAAM,CAAC,MAAM,aAAa,GAAG,MAAe,CAAA;AAO5C,MAAM,CAAC,MAAM,cAAc,GAAG,MAAe,CAAA;AAG7C,MAAM,CAAC,MAAM,IAAI,GAAG,UAAmB,CAAA;AAGvC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,MAAM,CACpB,QAAwD;IAExD,MAAM,EAAE,iBAAiB,EAAE,GAAG,QAAQ,CAAA;IACtC,IAAI,iBAAiB,EAAE,CAAC;QACtB,KAAK,MAAM,aAAa,IAAI,iBAAiB,EAAE,CAAC;YAC9C,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,aAAa,CAAA;YAC1C,IAAI,OAAO;gBAAE,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAA;YACvD,IAAI,MAAM,CAAC,OAAO,CAAC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QAClE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI;QAClD,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI;QAChC,EAAE,IAAI,IAAI;QACV,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI;QACpC,IAAI,IAAI,KAAK,IAAI,IAAI;QACrB,eAAe;QACf,sBAAsB;QACtB,OAAO,QAAQ,KAAK,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ;YAC1D,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC;YAC7B,CAAC,CAAC,IAAI;QACR,yBAAyB;QACzB,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;KAC1C,CAAA;IAEV,OAAO,GAAG,CAAC,MAAM,CACf,OAAO,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,cAAc,EAC9D,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CACV,CAAA;AACjB,CAAC;AA2CD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,QAAQ,CACtB,QAAwD;IAExD,IAAI,CAAC;QACH,MAAM,CAAC,QAAQ,CAAC,CAAA;QAChB,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,62 @@
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 type * as Hex from 'ox/Hex';
5
+ import * as ox_TransactionRequest from 'ox/TransactionRequest';
6
+ import type { Compute } from "../internal/types.js";
7
+ import * as TokenId from "./TokenId.js";
8
+ /** 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). */
9
+ export type TransactionRequest<bigintType = bigint, numberType = number, type extends string = string> = Compute<ox_TransactionRequest.TransactionRequest<bigintType, numberType, type> & {
10
+ calls?: readonly Calls.Call[] | undefined;
11
+ feeToken?: TokenId.TokenIdOrAddress | undefined;
12
+ }>;
13
+ /** RPC representation of a {@link ox#TransactionRequest.TransactionRequest}. */
14
+ export type Rpc = TransactionRequest<Hex.Hex, Hex.Hex, string>;
15
+ /**
16
+ * Converts a {@link ox#TransactionRequest.TransactionRequest} to a {@link ox#TransactionRequest.Rpc}.
17
+ *
18
+ * @example
19
+ * ```ts twoslash
20
+ * import { Value } from 'ox'
21
+ * import { TransactionRequest } from 'ox/tempo'
22
+ *
23
+ * const request = TransactionRequest.toRpc({
24
+ * feeToken: '0x20c0000000000000000000000000000000000000',
25
+ * to: '0x0000000000000000000000000000000000000000',
26
+ * value: Value.fromEther('0.01'),
27
+ * })
28
+ * ```
29
+ *
30
+ * @example
31
+ * ### Using with a Provider
32
+ *
33
+ * You can use {@link ox#Provider.(from:function)} to instantiate an EIP-1193 Provider and
34
+ * send a transaction to the Wallet using the `eth_sendTransaction` method.
35
+ *
36
+ * ```ts twoslash
37
+ * import 'ox/window'
38
+ * import { Provider, Value } from 'ox'
39
+ * import { TransactionRequest } from 'ox/tempo'
40
+ *
41
+ * const provider = Provider.from(window.ethereum!)
42
+ *
43
+ * const request = TransactionRequest.toRpc({
44
+ * feeToken: '0x20c0000000000000000000000000000000000000',
45
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
46
+ * value: Value.fromEther('0.01'),
47
+ * })
48
+ *
49
+ * const hash = await provider.request({ // [!code focus]
50
+ * method: 'eth_sendTransaction', // [!code focus]
51
+ * params: [request], // [!code focus]
52
+ * }) // [!code focus]
53
+ * ```
54
+ *
55
+ * @param request - The request to convert.
56
+ * @returns An RPC request.
57
+ */
58
+ export declare function toRpc(request: TransactionRequest): Rpc;
59
+ export declare namespace toRpc {
60
+ type ErrorType = Authorization.toRpcList.ErrorType | Hex.fromNumber.ErrorType | Errors.GlobalErrorType;
61
+ }
62
+ //# sourceMappingURL=TransactionRequest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransactionRequest.d.ts","sourceRoot":"","sources":["../../src/ox/TransactionRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,aAAa,MAAM,kBAAkB,CAAA;AACtD,OAAO,KAAK,KAAK,MAAM,MAAM,WAAW,CAAA;AACxC,OAAO,KAAK,KAAK,KAAK,MAAM,kBAAkB,CAAA;AAE9C,OAAO,KAAK,KAAK,GAAG,MAAM,QAAQ,CAAA;AAClC,OAAO,KAAK,qBAAqB,MAAM,uBAAuB,CAAA;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,6BAA4B;AACnD,OAAO,KAAK,OAAO,qBAAoB;AAGvC,wPAAwP;AACxP,MAAM,MAAM,kBAAkB,CAC5B,UAAU,GAAG,MAAM,EACnB,UAAU,GAAG,MAAM,EACnB,IAAI,SAAS,MAAM,GAAG,MAAM,IAC1B,OAAO,CACT,qBAAqB,CAAC,kBAAkB,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,CAAC,GAAG;IACvE,KAAK,CAAC,EAAE,SAAS,KAAK,CAAC,IAAI,EAAE,GAAG,SAAS,CAAA;IACzC,QAAQ,CAAC,EAAE,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAA;CAChD,CACF,CAAA;AAED,gFAAgF;AAChF,MAAM,MAAM,GAAG,GAAG,kBAAkB,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,kBAAkB,GAAG,GAAG,CAwBtD;AAED,MAAM,CAAC,OAAO,WAAW,KAAK,CAAC;IAC7B,KAAY,SAAS,GACjB,aAAa,CAAC,SAAS,CAAC,SAAS,GACjC,GAAG,CAAC,UAAU,CAAC,SAAS,GACxB,MAAM,CAAC,eAAe,CAAA;CAC3B"}
@@ -0,0 +1,66 @@
1
+ import * as Execute from 'ox/erc7821/Execute';
2
+ import * as ox_TransactionRequest from 'ox/TransactionRequest';
3
+ import * as TokenId from "./TokenId.js";
4
+ import * as Transaction from "./Transaction.js";
5
+ /**
6
+ * Converts a {@link ox#TransactionRequest.TransactionRequest} to a {@link ox#TransactionRequest.Rpc}.
7
+ *
8
+ * @example
9
+ * ```ts twoslash
10
+ * import { Value } from 'ox'
11
+ * import { TransactionRequest } from 'ox/tempo'
12
+ *
13
+ * const request = TransactionRequest.toRpc({
14
+ * feeToken: '0x20c0000000000000000000000000000000000000',
15
+ * to: '0x0000000000000000000000000000000000000000',
16
+ * value: Value.fromEther('0.01'),
17
+ * })
18
+ * ```
19
+ *
20
+ * @example
21
+ * ### Using with a Provider
22
+ *
23
+ * You can use {@link ox#Provider.(from:function)} to instantiate an EIP-1193 Provider and
24
+ * send a transaction to the Wallet using the `eth_sendTransaction` method.
25
+ *
26
+ * ```ts twoslash
27
+ * import 'ox/window'
28
+ * import { Provider, Value } from 'ox'
29
+ * import { TransactionRequest } from 'ox/tempo'
30
+ *
31
+ * const provider = Provider.from(window.ethereum!)
32
+ *
33
+ * const request = TransactionRequest.toRpc({
34
+ * feeToken: '0x20c0000000000000000000000000000000000000',
35
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
36
+ * value: Value.fromEther('0.01'),
37
+ * })
38
+ *
39
+ * const hash = await provider.request({ // [!code focus]
40
+ * method: 'eth_sendTransaction', // [!code focus]
41
+ * params: [request], // [!code focus]
42
+ * }) // [!code focus]
43
+ * ```
44
+ *
45
+ * @param request - The request to convert.
46
+ * @returns An RPC request.
47
+ */
48
+ export function toRpc(request) {
49
+ const request_rpc = ox_TransactionRequest.toRpc(request);
50
+ request_rpc.calls = request.calls;
51
+ if (typeof request.feeToken !== 'undefined')
52
+ request_rpc.feeToken = TokenId.toAddress(request.feeToken);
53
+ if (request.calls && request.from) {
54
+ delete request_rpc.to;
55
+ delete request_rpc.value;
56
+ delete request_rpc.data;
57
+ request_rpc.to = request.from;
58
+ request_rpc.data = Execute.encodeData(request.calls);
59
+ }
60
+ if (request.calls ||
61
+ typeof request.feeToken !== 'undefined' ||
62
+ request.type === 'feeToken')
63
+ request_rpc.type = Transaction.toRpcType.feeToken;
64
+ return request_rpc;
65
+ }
66
+ //# sourceMappingURL=TransactionRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransactionRequest.js","sourceRoot":"","sources":["../../src/ox/TransactionRequest.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAE7C,OAAO,KAAK,qBAAqB,MAAM,uBAAuB,CAAA;AAE9D,OAAO,KAAK,OAAO,qBAAoB;AACvC,OAAO,KAAK,WAAW,yBAAwB;AAiB/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,MAAM,UAAU,KAAK,CAAC,OAA2B;IAC/C,MAAM,WAAW,GAAG,qBAAqB,CAAC,KAAK,CAAC,OAAO,CAAQ,CAAA;IAE/D,WAAW,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;IAEjC,IAAI,OAAO,OAAO,CAAC,QAAQ,KAAK,WAAW;QACzC,WAAW,CAAC,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IAE5D,IAAI,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QAClC,OAAO,WAAW,CAAC,EAAE,CAAA;QACrB,OAAO,WAAW,CAAC,KAAK,CAAA;QACxB,OAAO,WAAW,CAAC,IAAI,CAAA;QACvB,WAAW,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAA;QAC7B,WAAW,CAAC,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IACtD,CAAC;IAED,IACE,OAAO,CAAC,KAAK;QACb,OAAO,OAAO,CAAC,QAAQ,KAAK,WAAW;QACvC,OAAO,CAAC,IAAI,KAAK,UAAU;QAE3B,WAAW,CAAC,IAAI,GAAG,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAA;IAEnD,OAAO,WAAW,CAAA;AACpB,CAAC"}
@@ -0,0 +1,5 @@
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";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ox/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,qBAAoB;AACvC,OAAO,KAAK,SAAS,uBAAsB;AAC3C,OAAO,KAAK,WAAW,yBAAwB;AAC/C,OAAO,KAAK,2BAA2B,yCAAwC"}
@@ -0,0 +1,5 @@
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";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ox/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,qBAAoB;AACvC,OAAO,KAAK,SAAS,uBAAsB;AAC3C,OAAO,KAAK,WAAW,yBAAwB;AAC/C,OAAO,KAAK,2BAA2B,yCAAwC"}