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,253 @@
1
+ import type * as Calls from 'ox/erc7821/Calls'
2
+ import * as Execute from 'ox/erc7821/Execute'
3
+ import * as Hex from 'ox/Hex'
4
+ import * as Secp256k1 from 'ox/Secp256k1'
5
+ import * as Signature from 'ox/Signature'
6
+ import {
7
+ type AccessList,
8
+ type Account,
9
+ type Address,
10
+ type AuthorizationList,
11
+ type FeeValuesEIP1559,
12
+ type ParseTransactionReturnType,
13
+ type SignedAuthorizationList,
14
+ type TransactionBase,
15
+ type TransactionRequestBase,
16
+ type TransactionSerializableBase,
17
+ type TransactionSerializableGeneric,
18
+ type TransactionSerializedGeneric,
19
+ parseTransaction as viem_parseTransaction,
20
+ type RpcTransaction as viem_RpcTransaction,
21
+ type RpcTransactionRequest as viem_RpcTransactionRequest,
22
+ type Signature as viem_Signature,
23
+ serializeTransaction as viem_serializeTransaction,
24
+ type Transaction as viem_Transaction,
25
+ type TransactionRequest as viem_TransactionRequest,
26
+ type TransactionSerializable as viem_TransactionSerializable,
27
+ type TransactionSerialized as viem_TransactionSerialized,
28
+ type TransactionType as viem_TransactionType,
29
+ } from 'viem'
30
+ import type { ExactPartial, OneOf } from '../internal/types.js'
31
+ import * as TxFeeToken from '../ox/TransactionEnvelopeFeeToken.js'
32
+
33
+ export type Transaction<
34
+ bigintType = bigint,
35
+ numberType = number,
36
+ pending extends boolean = false,
37
+ > = OneOf<
38
+ | viem_Transaction<bigintType, numberType, pending>
39
+ | TransactionFeeToken<bigintType, numberType, pending>
40
+ >
41
+ export type TransactionRpc<pending extends boolean = false> = OneOf<
42
+ | viem_RpcTransaction<pending>
43
+ | TransactionFeeToken<Hex.Hex, Hex.Hex, pending, '0x77'>
44
+ >
45
+
46
+ export type TransactionFeeToken<
47
+ quantity = bigint,
48
+ index = number,
49
+ isPending extends boolean = boolean,
50
+ type = 'feeToken',
51
+ > = TransactionBase<quantity, index, isPending> & {
52
+ /** EIP-2930 Access List. */
53
+ accessList: AccessList
54
+ /** Authorization list for the transaction. */
55
+ authorizationList: SignedAuthorizationList
56
+ /** Chain ID that this transaction is valid on. */
57
+ chainId: index
58
+ /** Fee token preference. */
59
+ feeToken?: Address | undefined
60
+ /** Fee payer address. */
61
+ feePayer?: Address | undefined
62
+ /** Fee payer signature. */
63
+ feePayerSignature?: viem_Signature | undefined
64
+ type: type
65
+ } & FeeValuesEIP1559<quantity>
66
+
67
+ export type TransactionRequest<
68
+ bigintType = bigint,
69
+ numberType = number,
70
+ > = OneOf<
71
+ | viem_TransactionRequest<bigintType, numberType>
72
+ | TransactionRequestFeeToken<bigintType, numberType>
73
+ >
74
+ export type TransactionRequestRpc = OneOf<
75
+ | viem_RpcTransactionRequest
76
+ | TransactionRequestFeeToken<Hex.Hex, Hex.Hex, '0x77'>
77
+ >
78
+
79
+ export type TransactionRequestFeeToken<
80
+ quantity = bigint,
81
+ index = number,
82
+ type = 'feeToken',
83
+ > = TransactionRequestBase<quantity, index, type> &
84
+ ExactPartial<FeeValuesEIP1559<quantity>> & {
85
+ accessList?: AccessList | undefined
86
+ authorizationList?: AuthorizationList<index, boolean> | undefined
87
+ calls?: readonly Calls.Call[] | undefined
88
+ feePayer?: Account | true | undefined
89
+ feeToken?: Address | bigint | undefined
90
+ }
91
+
92
+ export type TransactionSerializable = OneOf<
93
+ viem_TransactionSerializable | TransactionSerializableFeeToken
94
+ >
95
+
96
+ export type TransactionSerializableFeeToken<
97
+ quantity = bigint,
98
+ index = number,
99
+ > = TransactionSerializableBase<quantity, index> &
100
+ ExactPartial<FeeValuesEIP1559<quantity>> & {
101
+ accessList?: AccessList | undefined
102
+ authorizationList: SignedAuthorizationList
103
+ feeToken?: Address | bigint | undefined
104
+ feePayerSignature?: viem_Signature | undefined
105
+ chainId: number
106
+ type?: 'feeToken' | undefined
107
+ yParity?: number | undefined
108
+ }
109
+
110
+ export type TransactionSerialized<
111
+ type extends TransactionType = TransactionType,
112
+ > = viem_TransactionSerialized<type> | TransactionSerializedFeeToken
113
+
114
+ export type TransactionSerializedFeeToken = `0x77${string}`
115
+
116
+ export type TransactionType = viem_TransactionType | 'feeToken'
117
+
118
+ export function isTempoTransaction(transaction: Record<string, unknown>) {
119
+ if (transaction.type === 'feeToken') return true
120
+ if (typeof transaction.calls !== 'undefined') return true
121
+ if (typeof transaction.feePayer !== 'undefined') return true
122
+ if (typeof transaction.feeToken !== 'undefined') return true
123
+ return false
124
+ }
125
+
126
+ export function parseTransaction<
127
+ const serialized extends TransactionSerializedGeneric,
128
+ >(serializedTransaction: serialized): parseTransaction.ReturnValue<serialized> {
129
+ const type = Hex.slice(serializedTransaction, 0, 1)
130
+ if (type === '0x77') {
131
+ const { authorizationList, nonce, r, s, v, ...tx } = TxFeeToken.deserialize(
132
+ serializedTransaction as `0x77${string}`,
133
+ )
134
+ return {
135
+ ...tx,
136
+ authorizationList: authorizationList?.map((auth) => ({
137
+ ...auth,
138
+ nonce: Number(auth.nonce ?? 0n),
139
+ r: Hex.fromNumber(auth.r, { size: 32 }),
140
+ s: Hex.fromNumber(auth.s, { size: 32 }),
141
+ })),
142
+ nonce: Number(nonce ?? 0n),
143
+ ...(r ? { r: Hex.fromNumber(r, { size: 32 }) } : {}),
144
+ ...(s ? { s: Hex.fromNumber(s, { size: 32 }) } : {}),
145
+ ...(v ? { v: BigInt(v) } : {}),
146
+ } satisfies TransactionSerializableGeneric as never
147
+ }
148
+ return viem_parseTransaction(serializedTransaction) as never
149
+ }
150
+
151
+ export declare namespace parseTransaction {
152
+ export type ReturnValue<
153
+ serialized extends
154
+ TransactionSerializedGeneric = TransactionSerializedGeneric,
155
+ > = serialized extends TransactionSerializedFeeToken
156
+ ? TransactionSerializableFeeToken
157
+ : ParseTransactionReturnType<serialized>
158
+ }
159
+
160
+ export async function serializeTransaction(
161
+ transaction: TransactionSerializable & {
162
+ calls?: readonly Calls.Call[] | undefined
163
+ feePayer?: Account | true | undefined
164
+ from?: Address | undefined
165
+ },
166
+ signature?: viem_Signature | undefined,
167
+ ) {
168
+ if (!isTempoTransaction(transaction))
169
+ return viem_serializeTransaction(transaction as never, signature)
170
+
171
+ const signature_ = transaction.r && transaction.s ? transaction : signature
172
+
173
+ const {
174
+ authorizationList,
175
+ chainId,
176
+ calls,
177
+ feePayer,
178
+ feePayerSignature,
179
+ from,
180
+ nonce,
181
+ r,
182
+ s,
183
+ v,
184
+ ...rest
185
+ } = transaction
186
+
187
+ // TODO: remove once native transaction type has `calls`.
188
+ const { data, to, value } = (() => {
189
+ if (calls && from)
190
+ return {
191
+ data: Execute.encodeData(calls),
192
+ to: from,
193
+ value: 0n,
194
+ } as const
195
+ return {
196
+ data: transaction.data,
197
+ to: transaction.to,
198
+ value: transaction.value,
199
+ } as const
200
+ })()
201
+
202
+ const transaction_ox = {
203
+ ...rest,
204
+ authorizationList: authorizationList?.map((auth) => ({
205
+ ...auth,
206
+ nonce: BigInt(auth.nonce),
207
+ r: BigInt(auth.r!),
208
+ s: BigInt(auth.s!),
209
+ yParity: Number(auth.yParity),
210
+ })),
211
+ chainId: Number(chainId),
212
+ data,
213
+ feePayerSignature: feePayerSignature
214
+ ? {
215
+ r: BigInt(feePayerSignature.r!),
216
+ s: BigInt(feePayerSignature.s!),
217
+ yParity: Number(feePayerSignature.yParity),
218
+ }
219
+ : feePayer
220
+ ? null
221
+ : undefined,
222
+ to,
223
+ type: 'feeToken',
224
+ value,
225
+ ...(nonce ? { nonce: BigInt(nonce) } : {}),
226
+ ...(r ? { r: BigInt(r) } : {}),
227
+ ...(s ? { s: BigInt(s) } : {}),
228
+ ...(v ? { v: Number(v) } : {}),
229
+ } satisfies TxFeeToken.TransactionEnvelopeFeeToken
230
+
231
+ if (signature_ && typeof transaction.feePayer === 'object') {
232
+ const tx = TxFeeToken.from(transaction_ox, {
233
+ signature: signature_ as never,
234
+ })
235
+ const sender = Secp256k1.recoverAddress({
236
+ payload: TxFeeToken.getSignPayload(tx),
237
+ signature: signature_ as never,
238
+ })
239
+ const hash = TxFeeToken.getFeePayerSignPayload(tx, {
240
+ sender,
241
+ })
242
+ const feePayerSignature = await transaction.feePayer.sign!({
243
+ hash,
244
+ })
245
+ return TxFeeToken.serialize(tx, {
246
+ feePayerSignature: Signature.from(feePayerSignature),
247
+ })
248
+ }
249
+ return TxFeeToken.serialize(transaction_ox, {
250
+ feePayerSignature: feePayer === true ? null : undefined,
251
+ signature: signature as never,
252
+ })
253
+ }
@@ -0,0 +1,47 @@
1
+ import { createTransport, type Transport } from 'viem'
2
+ import { parseTransaction } from './transaction.js'
3
+
4
+ export type Relay = Transport<typeof withFeePayer.type>
5
+
6
+ /**
7
+ * Creates a fee payer transport that routes requests between
8
+ * the default transport or the fee payer transport.
9
+ *
10
+ * @param defaultTransport - The default transport to use.
11
+ * @param feePayerTransport - The fee payer transport to use.
12
+ * @returns A relay transport.
13
+ */
14
+ export function withFeePayer(
15
+ defaultTransport: Transport,
16
+ relayTransport: Transport,
17
+ ): withFeePayer.ReturnValue {
18
+ return (config) => {
19
+ const transport_default = defaultTransport(config)
20
+ const transport_relay = relayTransport(config)
21
+
22
+ return createTransport({
23
+ key: withFeePayer.type,
24
+ name: 'Relay Proxy',
25
+ async request({ method, params }, options) {
26
+ if (
27
+ method === 'eth_sendRawTransactionSync' ||
28
+ method === 'eth_sendRawTransaction'
29
+ ) {
30
+ const serialized = (params as any)[0] as `0x77${string}`
31
+ const transaction = parseTransaction(serialized)
32
+ // If the transaction is intended to be sponsored, forward it to the relay.
33
+ if (transaction.feePayerSignature === null)
34
+ return transport_relay.request({ method, params }, options) as never
35
+ }
36
+ return transport_default.request({ method, params }, options) as never
37
+ },
38
+ type: withFeePayer.type,
39
+ })
40
+ }
41
+ }
42
+
43
+ export declare namespace withFeePayer {
44
+ export const type = 'feePayer'
45
+
46
+ export type ReturnValue = Relay
47
+ }
@@ -0,0 +1,55 @@
1
+ import type {
2
+ Account,
3
+ Address,
4
+ Chain,
5
+ ReadContractParameters as viem_ReadContractParameters,
6
+ WriteContractParameters as viem_WriteContractParameters,
7
+ } from 'viem'
8
+ import type {
9
+ IsUndefined,
10
+ MaybeRequired,
11
+ UnionPick,
12
+ } from '../internal/types.js'
13
+ import type { TransactionRequestFeeToken } from './transaction.js'
14
+
15
+ export type GetAccountParameter<
16
+ account extends Account | undefined = Account | undefined,
17
+ accountOverride extends Account | Address | undefined = Account | Address,
18
+ required extends boolean = true,
19
+ nullish extends boolean = false,
20
+ > = MaybeRequired<
21
+ {
22
+ account?:
23
+ | accountOverride
24
+ | Account
25
+ | Address
26
+ | (nullish extends true ? null : never)
27
+ | undefined
28
+ },
29
+ IsUndefined<account> extends true
30
+ ? required extends true
31
+ ? true
32
+ : false
33
+ : false
34
+ >
35
+
36
+ export type ReadParameters = Pick<
37
+ viem_ReadContractParameters<never, never, never>,
38
+ 'account' | 'blockNumber' | 'blockOverrides' | 'blockTag' | 'stateOverride'
39
+ >
40
+
41
+ export type TokenIdOrAddress = bigint | Address
42
+
43
+ export type WriteParameters<
44
+ chain extends Chain | undefined = Chain | undefined,
45
+ account extends Account | undefined = Account | undefined,
46
+ > = UnionPick<
47
+ viem_WriteContractParameters<never, never, never, chain, account>,
48
+ | 'account'
49
+ | 'chain'
50
+ | 'gas'
51
+ | 'maxFeePerGas'
52
+ | 'maxPriorityFeePerGas'
53
+ | 'nonce'
54
+ > &
55
+ UnionPick<TransactionRequestFeeToken, 'feePayer' | 'feeToken'>
@@ -0,0 +1,37 @@
1
+ import {
2
+ type Abi,
3
+ type AbiStateMutability,
4
+ type Address,
5
+ type ContractFunctionName,
6
+ type ContractFunctionParameters,
7
+ type ExtractAbiItem,
8
+ encodeFunctionData,
9
+ type Hex,
10
+ } from 'viem'
11
+
12
+ export function defineCall<
13
+ const abi extends Abi,
14
+ const functionName extends ContractFunctionName<abi, AbiStateMutability>,
15
+ call extends ContractFunctionParameters<
16
+ abi,
17
+ AbiStateMutability,
18
+ functionName
19
+ >,
20
+ >(
21
+ call:
22
+ | call
23
+ | ContractFunctionParameters<abi, AbiStateMutability, functionName>,
24
+ ): ContractFunctionParameters<
25
+ [ExtractAbiItem<abi, functionName>],
26
+ AbiStateMutability,
27
+ functionName
28
+ > & {
29
+ data: Hex
30
+ to: Address
31
+ } {
32
+ return {
33
+ ...(call as any),
34
+ data: encodeFunctionData(call as never),
35
+ to: call.address,
36
+ } as const
37
+ }