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.
- package/README.md +92 -0
- package/dist/chains.d.ts +1477 -0
- package/dist/chains.d.ts.map +1 -0
- package/dist/chains.js +43 -0
- package/dist/chains.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/types.d.ts +284 -0
- package/dist/internal/types.d.ts.map +1 -0
- package/dist/internal/types.js +2 -0
- package/dist/internal/types.js.map +1 -0
- package/dist/ox/TokenId.d.ts +18 -0
- package/dist/ox/TokenId.d.ts.map +1 -0
- package/dist/ox/TokenId.js +29 -0
- package/dist/ox/TokenId.js.map +1 -0
- package/dist/ox/TokenRole.d.ts +11 -0
- package/dist/ox/TokenRole.d.ts.map +1 -0
- package/dist/ox/TokenRole.js +22 -0
- package/dist/ox/TokenRole.js.map +1 -0
- package/dist/ox/Transaction.d.ts +161 -0
- package/dist/ox/Transaction.d.ts.map +1 -0
- package/dist/ox/Transaction.js +117 -0
- package/dist/ox/Transaction.js.map +1 -0
- package/dist/ox/TransactionEnvelopeFeeToken.d.ts +393 -0
- package/dist/ox/TransactionEnvelopeFeeToken.d.ts.map +1 -0
- package/dist/ox/TransactionEnvelopeFeeToken.js +452 -0
- package/dist/ox/TransactionEnvelopeFeeToken.js.map +1 -0
- package/dist/ox/TransactionRequest.d.ts +62 -0
- package/dist/ox/TransactionRequest.d.ts.map +1 -0
- package/dist/ox/TransactionRequest.js +66 -0
- package/dist/ox/TransactionRequest.js.map +1 -0
- package/dist/ox/index.d.ts +5 -0
- package/dist/ox/index.d.ts.map +1 -0
- package/dist/ox/index.js +5 -0
- package/dist/ox/index.js.map +1 -0
- package/dist/prool/Instance.d.ts +92 -0
- package/dist/prool/Instance.d.ts.map +1 -0
- package/dist/prool/Instance.js +96 -0
- package/dist/prool/Instance.js.map +1 -0
- package/dist/prool/index.d.ts +2 -0
- package/dist/prool/index.d.ts.map +1 -0
- package/dist/prool/index.js +2 -0
- package/dist/prool/index.js.map +1 -0
- package/dist/viem/abis.d.ts +2058 -0
- package/dist/viem/abis.d.ts.map +1 -0
- package/dist/viem/abis.js +1599 -0
- package/dist/viem/abis.js.map +1 -0
- package/dist/viem/actions/amm.d.ts +2091 -0
- package/dist/viem/actions/amm.d.ts.map +1 -0
- package/dist/viem/actions/amm.js +876 -0
- package/dist/viem/actions/amm.js.map +1 -0
- package/dist/viem/actions/fee.d.ts +727 -0
- package/dist/viem/actions/fee.d.ts.map +1 -0
- package/dist/viem/actions/fee.js +230 -0
- package/dist/viem/actions/fee.js.map +1 -0
- package/dist/viem/actions/index.d.ts +5 -0
- package/dist/viem/actions/index.d.ts.map +1 -0
- package/dist/viem/actions/index.js +5 -0
- package/dist/viem/actions/index.js.map +1 -0
- package/dist/viem/actions/policy.d.ts +1900 -0
- package/dist/viem/actions/policy.d.ts.map +1 -0
- package/dist/viem/actions/policy.js +841 -0
- package/dist/viem/actions/policy.js.map +1 -0
- package/dist/viem/actions/token.d.ts +13759 -0
- package/dist/viem/actions/token.d.ts.map +1 -0
- package/dist/viem/actions/token.js +2579 -0
- package/dist/viem/actions/token.js.map +1 -0
- package/dist/viem/addresses.d.ts +8 -0
- package/dist/viem/addresses.d.ts.map +1 -0
- package/dist/viem/addresses.js +8 -0
- package/dist/viem/addresses.js.map +1 -0
- package/dist/viem/chain.d.ts +341 -0
- package/dist/viem/chain.d.ts.map +1 -0
- package/dist/viem/chain.js +22 -0
- package/dist/viem/chain.js.map +1 -0
- package/dist/viem/client.d.ts +27 -0
- package/dist/viem/client.d.ts.map +1 -0
- package/dist/viem/client.js +28 -0
- package/dist/viem/client.js.map +1 -0
- package/dist/viem/decorator.d.ts +1636 -0
- package/dist/viem/decorator.d.ts.map +1 -0
- package/dist/viem/decorator.js +95 -0
- package/dist/viem/decorator.js.map +1 -0
- package/dist/viem/formatters.d.ts +4 -0
- package/dist/viem/formatters.d.ts.map +1 -0
- package/dist/viem/formatters.js +69 -0
- package/dist/viem/formatters.js.map +1 -0
- package/dist/viem/index.d.ts +9 -0
- package/dist/viem/index.d.ts.map +1 -0
- package/dist/viem/index.js +9 -0
- package/dist/viem/index.js.map +1 -0
- package/dist/viem/transaction.d.ts +54 -0
- package/dist/viem/transaction.d.ts.map +1 -0
- package/dist/viem/transaction.js +108 -0
- package/dist/viem/transaction.js.map +1 -0
- package/dist/viem/transport.d.ts +16 -0
- package/dist/viem/transport.d.ts.map +1 -0
- package/dist/viem/transport.js +33 -0
- package/dist/viem/transport.js.map +1 -0
- package/dist/viem/types.d.ts +10 -0
- package/dist/viem/types.d.ts.map +1 -0
- package/dist/viem/types.js +2 -0
- package/dist/viem/types.js.map +1 -0
- package/dist/viem/utils.d.ts +8 -0
- package/dist/viem/utils.d.ts.map +1 -0
- package/dist/viem/utils.js +9 -0
- package/dist/viem/utils.js.map +1 -0
- package/package.json +100 -2
- package/src/chains.ts +46 -0
- package/src/index.ts +1 -0
- package/src/internal/types.ts +414 -0
- package/src/ox/TokenId.test.ts +29 -0
- package/src/ox/TokenId.ts +35 -0
- package/src/ox/TokenRole.test.ts +20 -0
- package/src/ox/TokenRole.ts +27 -0
- package/src/ox/Transaction.test.ts +257 -0
- package/src/ox/Transaction.ts +247 -0
- package/src/ox/TransactionEnvelopeFeeToken.test.ts +1215 -0
- package/src/ox/TransactionEnvelopeFeeToken.ts +717 -0
- package/src/ox/TransactionRequest.ts +100 -0
- package/src/ox/index.ts +4 -0
- package/src/prool/Instance.test.ts +43 -0
- package/src/prool/Instance.ts +190 -0
- package/src/prool/index.ts +1 -0
- package/src/prool/internal/chain.json +106 -0
- package/src/prool/internal/consensus.toml +32 -0
- package/src/viem/abis.ts +1606 -0
- package/src/viem/actions/amm.test.ts +425 -0
- package/src/viem/actions/amm.ts +1308 -0
- package/src/viem/actions/fee.test.ts +281 -0
- package/src/viem/actions/fee.ts +362 -0
- package/src/viem/actions/index.ts +4 -0
- package/src/viem/actions/policy.test.ts +514 -0
- package/src/viem/actions/policy.ts +1284 -0
- package/src/viem/actions/token.test.ts +2172 -0
- package/src/viem/actions/token.ts +3830 -0
- package/src/viem/addresses.ts +10 -0
- package/src/viem/chain.ts +27 -0
- package/src/viem/client.bench-d.ts +8 -0
- package/src/viem/client.test.ts +152 -0
- package/src/viem/client.ts +91 -0
- package/src/viem/decorator.bench-d.ts +11 -0
- package/src/viem/decorator.test.ts +35 -0
- package/src/viem/decorator.ts +1914 -0
- package/src/viem/e2e.test.ts +410 -0
- package/src/viem/formatters.ts +100 -0
- package/src/viem/index.ts +8 -0
- package/src/viem/transaction.ts +253 -0
- package/src/viem/transport.ts +47 -0
- package/src/viem/types.ts +55 -0
- package/src/viem/utils.ts +37 -0
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import { node } from '@elysiajs/node'
|
|
2
|
+
import { Elysia } from 'elysia'
|
|
3
|
+
import { RpcRequest, RpcResponse } from 'ox'
|
|
4
|
+
import * as actions from 'tempo.ts/viem/actions'
|
|
5
|
+
import { createClient, http, publicActions, walletActions } from 'viem'
|
|
6
|
+
import { mnemonicToAccount, privateKeyToAccount } from 'viem/accounts'
|
|
7
|
+
import { afterAll, beforeAll, describe, expect, test } from 'vitest'
|
|
8
|
+
import { tempoTest } from '../../test/viem/config.js'
|
|
9
|
+
import { tempoActions } from './index.js'
|
|
10
|
+
import { parseTransaction } from './transaction.js'
|
|
11
|
+
import { withFeePayer } from './transport.js'
|
|
12
|
+
|
|
13
|
+
describe('sendTransaction', () => {
|
|
14
|
+
test('default', async () => {
|
|
15
|
+
const client = createClient({
|
|
16
|
+
account: mnemonicToAccount(
|
|
17
|
+
'test test test test test test test test test test test junk',
|
|
18
|
+
),
|
|
19
|
+
chain: tempoTest,
|
|
20
|
+
transport: http(),
|
|
21
|
+
})
|
|
22
|
+
.extend(publicActions)
|
|
23
|
+
.extend(walletActions)
|
|
24
|
+
|
|
25
|
+
const hash = await client.sendTransaction({
|
|
26
|
+
feeToken: '0x20c0000000000000000000000000000000000000',
|
|
27
|
+
to: '0x0000000000000000000000000000000000000000',
|
|
28
|
+
})
|
|
29
|
+
await client.waitForTransactionReceipt({ hash })
|
|
30
|
+
|
|
31
|
+
const {
|
|
32
|
+
blockHash: _,
|
|
33
|
+
blockNumber: __,
|
|
34
|
+
...transaction
|
|
35
|
+
} = await client.getTransaction({ hash })
|
|
36
|
+
|
|
37
|
+
expect(transaction).toMatchInlineSnapshot(`
|
|
38
|
+
{
|
|
39
|
+
"accessList": [],
|
|
40
|
+
"authorizationList": [],
|
|
41
|
+
"chainId": 1337,
|
|
42
|
+
"data": "0x",
|
|
43
|
+
"feePayerSignature": undefined,
|
|
44
|
+
"feeToken": "0x20c0000000000000000000000000000000000000",
|
|
45
|
+
"from": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
46
|
+
"gas": 21000n,
|
|
47
|
+
"gasPrice": 44n,
|
|
48
|
+
"hash": "0x2dc7455a259871cc354fe83a904a1a003555d5d365a81dd4dc7b1ca42e63f2dc",
|
|
49
|
+
"input": "0x",
|
|
50
|
+
"maxFeePerBlobGas": undefined,
|
|
51
|
+
"maxFeePerGas": 52n,
|
|
52
|
+
"maxPriorityFeePerGas": 0n,
|
|
53
|
+
"nonce": 0,
|
|
54
|
+
"r": "0x17d8f3e7638105d316e004faa8e6b680d6f55e0326bf2f0534a0d83b46b6d3fb",
|
|
55
|
+
"s": "0x4a83f0e41f1f13bbbe0b53e4b57d2fb2d2542927e2331016c55265eb0bf5e80a",
|
|
56
|
+
"to": "0x0000000000000000000000000000000000000000",
|
|
57
|
+
"transactionIndex": 0,
|
|
58
|
+
"type": "feeToken",
|
|
59
|
+
"typeHex": "0x77",
|
|
60
|
+
"v": 28n,
|
|
61
|
+
"value": 0n,
|
|
62
|
+
"yParity": 1,
|
|
63
|
+
}
|
|
64
|
+
`)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test('with calls', async () => {
|
|
68
|
+
const client = createClient({
|
|
69
|
+
account: mnemonicToAccount(
|
|
70
|
+
'test test test test test test test test test test test junk',
|
|
71
|
+
),
|
|
72
|
+
chain: tempoTest,
|
|
73
|
+
transport: http(),
|
|
74
|
+
})
|
|
75
|
+
.extend(publicActions)
|
|
76
|
+
.extend(walletActions)
|
|
77
|
+
|
|
78
|
+
const hash = await client.sendTransaction({
|
|
79
|
+
calls: [
|
|
80
|
+
actions.token.create.call({
|
|
81
|
+
admin: client.account.address,
|
|
82
|
+
currency: 'USD',
|
|
83
|
+
name: 'Test Token 3',
|
|
84
|
+
symbol: 'TEST3',
|
|
85
|
+
}),
|
|
86
|
+
],
|
|
87
|
+
})
|
|
88
|
+
await client.waitForTransactionReceipt({ hash })
|
|
89
|
+
|
|
90
|
+
const transaction = await client.getTransaction({ hash })
|
|
91
|
+
expect({
|
|
92
|
+
...transaction,
|
|
93
|
+
blockHash: undefined,
|
|
94
|
+
blockNumber: undefined,
|
|
95
|
+
}).toMatchInlineSnapshot(`
|
|
96
|
+
{
|
|
97
|
+
"accessList": [],
|
|
98
|
+
"authorizationList": [],
|
|
99
|
+
"blockHash": undefined,
|
|
100
|
+
"blockNumber": undefined,
|
|
101
|
+
"chainId": 1337,
|
|
102
|
+
"data": "0xe9ae5c5301000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000020fc0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001447b155afa000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000000000000000000000000000000000000000000c5465737420546f6b656e20330000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000554455354330000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003555344000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
|
103
|
+
"feePayerSignature": undefined,
|
|
104
|
+
"feeToken": null,
|
|
105
|
+
"from": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
106
|
+
"gas": 30090n,
|
|
107
|
+
"gasPrice": 44n,
|
|
108
|
+
"hash": "0xdac9fd849170da469ed362cbe83e65b28ec04206e4be12a87ca719f2727a9f0e",
|
|
109
|
+
"input": "0xe9ae5c5301000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000020fc0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001447b155afa000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000000000000000000000000000000000000000000c5465737420546f6b656e20330000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000554455354330000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003555344000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
|
110
|
+
"maxFeePerBlobGas": undefined,
|
|
111
|
+
"maxFeePerGas": 52n,
|
|
112
|
+
"maxPriorityFeePerGas": 0n,
|
|
113
|
+
"nonce": 0,
|
|
114
|
+
"r": "0x3c55f0844854fcabd0fb085202a78de58e92b0389b5d0d5b623b4eaafe2c1c7d",
|
|
115
|
+
"s": "0x5d9019302d458f76b424f242b1212ffb2fc3301f4cd23b4b6d2493cb38d5361b",
|
|
116
|
+
"to": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
117
|
+
"transactionIndex": 0,
|
|
118
|
+
"type": "feeToken",
|
|
119
|
+
"typeHex": "0x77",
|
|
120
|
+
"v": 27n,
|
|
121
|
+
"value": 0n,
|
|
122
|
+
"yParity": 0,
|
|
123
|
+
}
|
|
124
|
+
`)
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
test('with feePayer', async () => {
|
|
128
|
+
const account = privateKeyToAccount(
|
|
129
|
+
// unfunded PK
|
|
130
|
+
'0xecc3fe55647412647e5c6b657c496803b08ef956f927b7a821da298cfbdd9666',
|
|
131
|
+
)
|
|
132
|
+
const feePayer = mnemonicToAccount(
|
|
133
|
+
'test test test test test test test test test test test junk',
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
const client = createClient({
|
|
137
|
+
account,
|
|
138
|
+
chain: tempoTest,
|
|
139
|
+
transport: http(),
|
|
140
|
+
})
|
|
141
|
+
.extend(publicActions)
|
|
142
|
+
.extend(walletActions)
|
|
143
|
+
|
|
144
|
+
const hash = await client.sendTransaction({
|
|
145
|
+
feePayer,
|
|
146
|
+
to: '0x0000000000000000000000000000000000000000',
|
|
147
|
+
})
|
|
148
|
+
await client.waitForTransactionReceipt({ hash })
|
|
149
|
+
|
|
150
|
+
const {
|
|
151
|
+
blockHash: _,
|
|
152
|
+
blockNumber: __,
|
|
153
|
+
...transaction
|
|
154
|
+
} = await client.getTransaction({ hash })
|
|
155
|
+
|
|
156
|
+
expect(transaction).toMatchInlineSnapshot(`
|
|
157
|
+
{
|
|
158
|
+
"accessList": [],
|
|
159
|
+
"authorizationList": [],
|
|
160
|
+
"chainId": 1337,
|
|
161
|
+
"data": "0x",
|
|
162
|
+
"feePayer": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
163
|
+
"feePayerSignature": {
|
|
164
|
+
"r": "0x5d32035dfaa049e95bf9baa487f817a824ef154e7252587a88f0e1d46077790b",
|
|
165
|
+
"s": "0x3583f71d8df11e2e7976336ae0ee960521e80af5719e6387d7dc832f5bace402",
|
|
166
|
+
"v": 28n,
|
|
167
|
+
"yParity": 1,
|
|
168
|
+
},
|
|
169
|
+
"feeToken": null,
|
|
170
|
+
"from": "0x740474977e01d056f04a314b5537e4dd88f35952",
|
|
171
|
+
"gas": 21000n,
|
|
172
|
+
"gasPrice": 44n,
|
|
173
|
+
"hash": "0xc4a600da90b6267bec6f414b378819dc95c597820df324b0df4e16b63cee430b",
|
|
174
|
+
"input": "0x",
|
|
175
|
+
"maxFeePerBlobGas": undefined,
|
|
176
|
+
"maxFeePerGas": 52n,
|
|
177
|
+
"maxPriorityFeePerGas": 0n,
|
|
178
|
+
"nonce": 0,
|
|
179
|
+
"r": "0x1f1297f1407dd0676e1c832c62838051927c0cdabdd5ff8e30a6946cd57adb79",
|
|
180
|
+
"s": "0x779c8374b9a22585f05d4484f1c4b2b022cc114cb7002b525f66873dd43e1fa9",
|
|
181
|
+
"to": "0x0000000000000000000000000000000000000000",
|
|
182
|
+
"transactionIndex": 0,
|
|
183
|
+
"type": "feeToken",
|
|
184
|
+
"typeHex": "0x77",
|
|
185
|
+
"v": 28n,
|
|
186
|
+
"value": 0n,
|
|
187
|
+
"yParity": 1,
|
|
188
|
+
}
|
|
189
|
+
`)
|
|
190
|
+
})
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
describe('signTransaction', () => {
|
|
194
|
+
test('default', async () => {
|
|
195
|
+
const account = privateKeyToAccount(
|
|
196
|
+
// unfunded PK
|
|
197
|
+
'0xecc3fe55647412647e5c6b657c496803b08ef956f927b7a821da298cfbdd9666',
|
|
198
|
+
)
|
|
199
|
+
const feePayer = mnemonicToAccount(
|
|
200
|
+
'test test test test test test test test test test test junk',
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
const client = createClient({
|
|
204
|
+
account,
|
|
205
|
+
chain: tempoTest,
|
|
206
|
+
transport: http(),
|
|
207
|
+
})
|
|
208
|
+
.extend(walletActions)
|
|
209
|
+
.extend(publicActions)
|
|
210
|
+
|
|
211
|
+
const request = await client.prepareTransactionRequest({
|
|
212
|
+
data: '0xdeadbeef',
|
|
213
|
+
feePayer: true,
|
|
214
|
+
to: '0xcafebabecafebabecafebabecafebabecafebabe',
|
|
215
|
+
type: 'feeToken',
|
|
216
|
+
})
|
|
217
|
+
let transaction = await client.signTransaction(request)
|
|
218
|
+
|
|
219
|
+
transaction = await client.signTransaction({
|
|
220
|
+
...parseTransaction(transaction),
|
|
221
|
+
feePayer,
|
|
222
|
+
})
|
|
223
|
+
const hash = await client.sendRawTransaction({
|
|
224
|
+
serializedTransaction: transaction,
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
await client.waitForTransactionReceipt({ hash })
|
|
228
|
+
|
|
229
|
+
const {
|
|
230
|
+
blockHash: _,
|
|
231
|
+
blockNumber: __,
|
|
232
|
+
...transaction2
|
|
233
|
+
} = await client.getTransaction({ hash })
|
|
234
|
+
|
|
235
|
+
expect(transaction2).toMatchInlineSnapshot(`
|
|
236
|
+
{
|
|
237
|
+
"accessList": [],
|
|
238
|
+
"authorizationList": [],
|
|
239
|
+
"chainId": 1337,
|
|
240
|
+
"data": "0xdeadbeef",
|
|
241
|
+
"feePayer": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
242
|
+
"feePayerSignature": {
|
|
243
|
+
"r": "0xd855471eb74e1225bb0f12b105c8b22849af6bdbdc88e69fc4a22a0760fdb980",
|
|
244
|
+
"s": "0x4bb4c1c891657b24170fb839aaad72b11038a3d01d4f21dd912e3a3052c9c59c",
|
|
245
|
+
"v": 28n,
|
|
246
|
+
"yParity": 1,
|
|
247
|
+
},
|
|
248
|
+
"feeToken": null,
|
|
249
|
+
"from": "0x740474977e01d056f04a314b5537e4dd88f35952",
|
|
250
|
+
"gas": 21326n,
|
|
251
|
+
"gasPrice": 44n,
|
|
252
|
+
"hash": "0x63f48eadae4ab046e9ca41bcfa59a0c6046da2b04f210ba6e49182d8f73e8e63",
|
|
253
|
+
"input": "0xdeadbeef",
|
|
254
|
+
"maxFeePerBlobGas": undefined,
|
|
255
|
+
"maxFeePerGas": 52n,
|
|
256
|
+
"maxPriorityFeePerGas": 0n,
|
|
257
|
+
"nonce": 0,
|
|
258
|
+
"r": "0xbb738db362d493d3d2674a1542ffc188b7ccc3e0cd162d571f382f2baa130180",
|
|
259
|
+
"s": "0x6fe0bbf76e60f89b4f9e3a94124c46d182e194a55caee95bef400ddb27974aea",
|
|
260
|
+
"to": "0xcafebabecafebabecafebabecafebabecafebabe",
|
|
261
|
+
"transactionIndex": 0,
|
|
262
|
+
"type": "feeToken",
|
|
263
|
+
"typeHex": "0x77",
|
|
264
|
+
"v": 28n,
|
|
265
|
+
"value": 0n,
|
|
266
|
+
"yParity": 1,
|
|
267
|
+
}
|
|
268
|
+
`)
|
|
269
|
+
})
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
describe('relay', () => {
|
|
273
|
+
let server: Elysia
|
|
274
|
+
|
|
275
|
+
beforeAll(async () => {
|
|
276
|
+
server = new Elysia({ adapter: node() })
|
|
277
|
+
.post('/', async ({ body }) => {
|
|
278
|
+
const client = createClient({
|
|
279
|
+
account: mnemonicToAccount(
|
|
280
|
+
'test test test test test test test test test test test junk',
|
|
281
|
+
),
|
|
282
|
+
chain: tempoTest,
|
|
283
|
+
transport: http(),
|
|
284
|
+
}).extend(walletActions)
|
|
285
|
+
|
|
286
|
+
const request = RpcRequest.from(body as any)
|
|
287
|
+
|
|
288
|
+
if (
|
|
289
|
+
request.method !== 'eth_sendRawTransaction' &&
|
|
290
|
+
request.method !== 'eth_sendRawTransactionSync'
|
|
291
|
+
)
|
|
292
|
+
return Response.json(
|
|
293
|
+
RpcResponse.from(
|
|
294
|
+
{
|
|
295
|
+
error: new RpcResponse.InvalidParamsError({
|
|
296
|
+
message:
|
|
297
|
+
'service only supports `eth_sendRawTransaction` and `eth_sendRawTransactionSync`',
|
|
298
|
+
}),
|
|
299
|
+
},
|
|
300
|
+
{ request },
|
|
301
|
+
),
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
const serialized = request.params?.[0] as `0x77${string}`
|
|
305
|
+
if (!serialized.startsWith('0x77'))
|
|
306
|
+
return Response.json(
|
|
307
|
+
RpcResponse.from(
|
|
308
|
+
{
|
|
309
|
+
error: new RpcResponse.InvalidParamsError({
|
|
310
|
+
message: 'service only supports `0x77` transactions',
|
|
311
|
+
}),
|
|
312
|
+
},
|
|
313
|
+
{ request },
|
|
314
|
+
),
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
const transaction = parseTransaction(serialized)
|
|
318
|
+
const serializedTransaction = await client.signTransaction({
|
|
319
|
+
...transaction,
|
|
320
|
+
feePayer: client.account,
|
|
321
|
+
})
|
|
322
|
+
const result = await client.request({
|
|
323
|
+
method: request.method,
|
|
324
|
+
params: [serializedTransaction],
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
return Response.json(RpcResponse.from({ result }, { request }))
|
|
328
|
+
})
|
|
329
|
+
.listen(3000)
|
|
330
|
+
})
|
|
331
|
+
|
|
332
|
+
afterAll(() => {
|
|
333
|
+
process.on('SIGINT', () => {
|
|
334
|
+
server.stop()
|
|
335
|
+
process.exit(0)
|
|
336
|
+
})
|
|
337
|
+
process.on('SIGTERM', () => {
|
|
338
|
+
server.stop()
|
|
339
|
+
process.exit(0)
|
|
340
|
+
})
|
|
341
|
+
})
|
|
342
|
+
|
|
343
|
+
test('default', async () => {
|
|
344
|
+
const client = createClient({
|
|
345
|
+
account: privateKeyToAccount(
|
|
346
|
+
// unfunded PK
|
|
347
|
+
'0xecc3fe55647412647e5c6b657c496803b08ef956f927b7a821da298cfbdd9666',
|
|
348
|
+
),
|
|
349
|
+
chain: tempoTest,
|
|
350
|
+
transport: withFeePayer(http(), http('http://localhost:3000')),
|
|
351
|
+
})
|
|
352
|
+
.extend(tempoActions())
|
|
353
|
+
.extend(walletActions)
|
|
354
|
+
.extend(publicActions)
|
|
355
|
+
|
|
356
|
+
const { receipt } = await client.fee.setUserTokenSync({
|
|
357
|
+
feePayer: true,
|
|
358
|
+
token: 1n,
|
|
359
|
+
})
|
|
360
|
+
|
|
361
|
+
const userToken = await client.fee.getUserToken()
|
|
362
|
+
expect(userToken).toMatchInlineSnapshot(`
|
|
363
|
+
{
|
|
364
|
+
"address": "0x20C0000000000000000000000000000000000001",
|
|
365
|
+
"id": 1n,
|
|
366
|
+
}
|
|
367
|
+
`)
|
|
368
|
+
|
|
369
|
+
const {
|
|
370
|
+
blockHash: _,
|
|
371
|
+
blockNumber: __,
|
|
372
|
+
...transaction
|
|
373
|
+
} = await client.getTransaction({ hash: receipt.transactionHash })
|
|
374
|
+
|
|
375
|
+
expect(transaction).toMatchInlineSnapshot(`
|
|
376
|
+
{
|
|
377
|
+
"accessList": [],
|
|
378
|
+
"authorizationList": [],
|
|
379
|
+
"chainId": 1337,
|
|
380
|
+
"data": "0xe789744400000000000000000000000020c0000000000000000000000000000000000001",
|
|
381
|
+
"feePayer": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
382
|
+
"feePayerSignature": {
|
|
383
|
+
"r": "0xfe9df92927697e996652682213d142b2ffb6fdab9777979c78f62cb3e061674b",
|
|
384
|
+
"s": "0x104fb902e6e4b704792e12ebc6236831a38492d439974a4ee215af191c83ab3a",
|
|
385
|
+
"v": 28n,
|
|
386
|
+
"yParity": 1,
|
|
387
|
+
},
|
|
388
|
+
"feeToken": null,
|
|
389
|
+
"from": "0x740474977e01d056f04a314b5537e4dd88f35952",
|
|
390
|
+
"gas": 22563n,
|
|
391
|
+
"gasPrice": 44n,
|
|
392
|
+
"hash": "0xdf9d902872fbe0a631a66f7a629da6746c0bcc1e11cd3374d4db899ae4af175f",
|
|
393
|
+
"input": "0xe789744400000000000000000000000020c0000000000000000000000000000000000001",
|
|
394
|
+
"maxFeePerBlobGas": undefined,
|
|
395
|
+
"maxFeePerGas": 52n,
|
|
396
|
+
"maxPriorityFeePerGas": 0n,
|
|
397
|
+
"nonce": 0,
|
|
398
|
+
"r": "0x65b6e02e960b2e7dc5c04436d041a6f327180269303c5a897b669be783ddbc8c",
|
|
399
|
+
"s": "0x497a98ff1ca644dd98a25181044112868b46fedbbbc55b278ba4d8139a6b4b54",
|
|
400
|
+
"to": "0xfeec000000000000000000000000000000000000",
|
|
401
|
+
"transactionIndex": 0,
|
|
402
|
+
"type": "feeToken",
|
|
403
|
+
"typeHex": "0x77",
|
|
404
|
+
"v": 28n,
|
|
405
|
+
"value": 0n,
|
|
406
|
+
"yParity": 1,
|
|
407
|
+
}
|
|
408
|
+
`)
|
|
409
|
+
})
|
|
410
|
+
})
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import * as Hex from 'ox/Hex'
|
|
2
|
+
import {
|
|
3
|
+
formatTransaction as viem_formatTransaction,
|
|
4
|
+
formatTransactionRequest as viem_formatTransactionRequest,
|
|
5
|
+
} from 'viem'
|
|
6
|
+
import { parseAccount } from 'viem/accounts'
|
|
7
|
+
import * as ox_Transaction from '../ox/Transaction.js'
|
|
8
|
+
import * as ox_TransactionRequest from '../ox/TransactionRequest.js'
|
|
9
|
+
import {
|
|
10
|
+
isTempoTransaction,
|
|
11
|
+
type Transaction,
|
|
12
|
+
type TransactionRequest,
|
|
13
|
+
type TransactionRequestFeeToken,
|
|
14
|
+
type TransactionRequestRpc,
|
|
15
|
+
type TransactionRpc,
|
|
16
|
+
} from './transaction.js'
|
|
17
|
+
|
|
18
|
+
export const formatTransaction = (
|
|
19
|
+
transaction: TransactionRpc,
|
|
20
|
+
): Transaction<bigint, number, boolean> => {
|
|
21
|
+
if (!isTempoTransaction(transaction))
|
|
22
|
+
return viem_formatTransaction(transaction as never)
|
|
23
|
+
|
|
24
|
+
const {
|
|
25
|
+
feePayerSignature,
|
|
26
|
+
gasPrice: _,
|
|
27
|
+
nonce,
|
|
28
|
+
...tx
|
|
29
|
+
} = ox_Transaction.fromRpc(transaction as never) as ox_Transaction.FeeToken
|
|
30
|
+
return {
|
|
31
|
+
...tx,
|
|
32
|
+
accessList: tx.accessList!,
|
|
33
|
+
authorizationList: tx.authorizationList!.map((auth) => ({
|
|
34
|
+
...auth,
|
|
35
|
+
nonce: Number(auth.nonce),
|
|
36
|
+
r: Hex.fromNumber(auth.r, { size: 32 }),
|
|
37
|
+
s: Hex.fromNumber(auth.s, { size: 32 }),
|
|
38
|
+
})),
|
|
39
|
+
feePayerSignature: feePayerSignature
|
|
40
|
+
? {
|
|
41
|
+
r: Hex.fromNumber(feePayerSignature.r, { size: 32 }),
|
|
42
|
+
s: Hex.fromNumber(feePayerSignature.s, { size: 32 }),
|
|
43
|
+
v: BigInt(feePayerSignature.v ?? 27),
|
|
44
|
+
yParity: feePayerSignature.yParity,
|
|
45
|
+
}
|
|
46
|
+
: undefined,
|
|
47
|
+
nonce: Number(nonce),
|
|
48
|
+
typeHex:
|
|
49
|
+
ox_Transaction.toRpcType[
|
|
50
|
+
tx.type as keyof typeof ox_Transaction.toRpcType
|
|
51
|
+
],
|
|
52
|
+
type: tx.type as 'feeToken',
|
|
53
|
+
r: Hex.fromNumber(tx.r, { size: 32 }),
|
|
54
|
+
s: Hex.fromNumber(tx.s, { size: 32 }),
|
|
55
|
+
v: BigInt(tx.v ?? 27),
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const formatTransactionRequest = (
|
|
60
|
+
r: TransactionRequest,
|
|
61
|
+
action?: string | undefined,
|
|
62
|
+
): TransactionRequestRpc => {
|
|
63
|
+
const request = r as TransactionRequestFeeToken
|
|
64
|
+
|
|
65
|
+
if (!isTempoTransaction(request))
|
|
66
|
+
return viem_formatTransactionRequest(
|
|
67
|
+
r as never,
|
|
68
|
+
action,
|
|
69
|
+
) as TransactionRequestRpc
|
|
70
|
+
|
|
71
|
+
const rpc = ox_TransactionRequest.toRpc({
|
|
72
|
+
...request,
|
|
73
|
+
authorizationList: request.authorizationList?.map((auth) => ({
|
|
74
|
+
...auth,
|
|
75
|
+
nonce: BigInt(auth.nonce),
|
|
76
|
+
r: BigInt(auth.r!),
|
|
77
|
+
s: BigInt(auth.s!),
|
|
78
|
+
yParity: Number(auth.yParity),
|
|
79
|
+
})),
|
|
80
|
+
nonce: request.nonce ? BigInt(request.nonce) : undefined,
|
|
81
|
+
type: 'feeToken',
|
|
82
|
+
})
|
|
83
|
+
return {
|
|
84
|
+
...rpc,
|
|
85
|
+
...(request.feePayer
|
|
86
|
+
? {
|
|
87
|
+
feePayer:
|
|
88
|
+
typeof request.feePayer === 'object'
|
|
89
|
+
? parseAccount(request.feePayer)
|
|
90
|
+
: request.feePayer,
|
|
91
|
+
}
|
|
92
|
+
: {}),
|
|
93
|
+
...(action === 'estimateGas'
|
|
94
|
+
? {
|
|
95
|
+
maxFeePerGas: '0x0',
|
|
96
|
+
maxPriorityFeePerGas: '0x0',
|
|
97
|
+
}
|
|
98
|
+
: {}),
|
|
99
|
+
} as never
|
|
100
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './abis.js'
|
|
2
|
+
export * as actions from './actions/index.js'
|
|
3
|
+
export * from './chain.js'
|
|
4
|
+
export * from './client.js'
|
|
5
|
+
export { decorator as tempoActions } from './decorator.js'
|
|
6
|
+
export * from './formatters.js'
|
|
7
|
+
export * from './transaction.js'
|
|
8
|
+
export * from './transport.js'
|