tempo.ts 0.6.1 → 0.7.0

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 (113) hide show
  1. package/CHANGELOG.md +134 -0
  2. package/README.md +6 -2
  3. package/dist/ox/Transaction.js +1 -1
  4. package/dist/ox/Transaction.js.map +1 -1
  5. package/dist/server/Handler.d.ts +346 -0
  6. package/dist/server/Handler.d.ts.map +1 -0
  7. package/dist/server/Handler.js +441 -0
  8. package/dist/server/Handler.js.map +1 -0
  9. package/dist/server/Kv.d.ts +16 -0
  10. package/dist/server/Kv.d.ts.map +1 -0
  11. package/dist/server/Kv.js +25 -0
  12. package/dist/server/Kv.js.map +1 -0
  13. package/dist/server/index.d.ts +3 -0
  14. package/dist/server/index.d.ts.map +1 -0
  15. package/dist/server/index.js +3 -0
  16. package/dist/server/index.js.map +1 -0
  17. package/dist/server/internal/requestListener.d.ts +124 -0
  18. package/dist/server/internal/requestListener.d.ts.map +1 -0
  19. package/dist/server/internal/requestListener.js +174 -0
  20. package/dist/server/internal/requestListener.js.map +1 -0
  21. package/dist/viem/Actions/account.d.ts +40 -0
  22. package/dist/viem/Actions/account.d.ts.map +1 -0
  23. package/dist/viem/Actions/account.js +87 -0
  24. package/dist/viem/Actions/account.js.map +1 -0
  25. package/dist/viem/Actions/amm.d.ts +51 -1245
  26. package/dist/viem/Actions/amm.d.ts.map +1 -1
  27. package/dist/viem/Actions/amm.js +15 -478
  28. package/dist/viem/Actions/amm.js.map +1 -1
  29. package/dist/viem/Actions/index.d.ts +1 -0
  30. package/dist/viem/Actions/index.d.ts.map +1 -1
  31. package/dist/viem/Actions/index.js +1 -0
  32. package/dist/viem/Actions/index.js.map +1 -1
  33. package/dist/viem/Actions/reward.d.ts +0 -1067
  34. package/dist/viem/Actions/reward.d.ts.map +1 -1
  35. package/dist/viem/Actions/reward.js +4 -212
  36. package/dist/viem/Actions/reward.js.map +1 -1
  37. package/dist/viem/Decorator.d.ts +28 -263
  38. package/dist/viem/Decorator.d.ts.map +1 -1
  39. package/dist/viem/Decorator.js +2 -10
  40. package/dist/viem/Decorator.js.map +1 -1
  41. package/dist/viem/Storage.d.ts +23 -0
  42. package/dist/viem/Storage.d.ts.map +1 -0
  43. package/dist/viem/Storage.js +47 -0
  44. package/dist/viem/Storage.js.map +1 -0
  45. package/dist/viem/Transport.d.ts +10 -1
  46. package/dist/viem/Transport.d.ts.map +1 -1
  47. package/dist/viem/Transport.js +22 -3
  48. package/dist/viem/Transport.js.map +1 -1
  49. package/dist/viem/internal/utils.d.ts +6 -0
  50. package/dist/viem/internal/utils.d.ts.map +1 -1
  51. package/dist/viem/internal/utils.js +24 -0
  52. package/dist/viem/internal/utils.js.map +1 -1
  53. package/dist/wagmi/Actions/amm.d.ts +0 -225
  54. package/dist/wagmi/Actions/amm.d.ts.map +1 -1
  55. package/dist/wagmi/Actions/amm.js +0 -248
  56. package/dist/wagmi/Actions/amm.js.map +1 -1
  57. package/dist/wagmi/Actions/reward.d.ts +0 -110
  58. package/dist/wagmi/Actions/reward.d.ts.map +1 -1
  59. package/dist/wagmi/Actions/reward.js +0 -121
  60. package/dist/wagmi/Actions/reward.js.map +1 -1
  61. package/dist/wagmi/Connector.d.ts +6 -17
  62. package/dist/wagmi/Connector.d.ts.map +1 -1
  63. package/dist/wagmi/Connector.js +17 -43
  64. package/dist/wagmi/Connector.js.map +1 -1
  65. package/dist/wagmi/Hooks/amm.d.ts +0 -236
  66. package/dist/wagmi/Hooks/amm.d.ts.map +1 -1
  67. package/dist/wagmi/Hooks/amm.js +0 -285
  68. package/dist/wagmi/Hooks/amm.js.map +1 -1
  69. package/dist/wagmi/Hooks/reward.d.ts +0 -88
  70. package/dist/wagmi/Hooks/reward.d.ts.map +1 -1
  71. package/dist/wagmi/Hooks/reward.js +0 -103
  72. package/dist/wagmi/Hooks/reward.js.map +1 -1
  73. package/dist/wagmi/KeyManager.d.ts +57 -0
  74. package/dist/wagmi/KeyManager.d.ts.map +1 -0
  75. package/dist/wagmi/KeyManager.js +101 -0
  76. package/dist/wagmi/KeyManager.js.map +1 -0
  77. package/dist/wagmi/index.d.ts +1 -0
  78. package/dist/wagmi/index.d.ts.map +1 -1
  79. package/dist/wagmi/index.js +1 -0
  80. package/dist/wagmi/index.js.map +1 -1
  81. package/package.json +8 -2
  82. package/src/ox/Transaction.ts +1 -1
  83. package/src/ox/e2e.test.ts +7 -0
  84. package/src/server/Handler.test.ts +566 -0
  85. package/src/server/Handler.ts +577 -0
  86. package/src/server/Kv.ts +40 -0
  87. package/src/server/index.ts +2 -0
  88. package/src/server/internal/requestListener.ts +285 -0
  89. package/src/viem/Actions/account.test.ts +414 -0
  90. package/src/viem/Actions/account.ts +108 -0
  91. package/src/viem/Actions/amm.test.ts +10 -284
  92. package/src/viem/Actions/amm.ts +88 -768
  93. package/src/viem/Actions/index.ts +1 -0
  94. package/src/viem/Actions/reward.test.ts +4 -212
  95. package/src/viem/Actions/reward.ts +4 -291
  96. package/src/viem/Decorator.test.ts +1 -0
  97. package/src/viem/Decorator.ts +32 -294
  98. package/src/viem/Storage.ts +88 -0
  99. package/src/viem/Transport.ts +40 -2
  100. package/src/viem/e2e.test.ts +106 -3
  101. package/src/viem/internal/utils.ts +21 -0
  102. package/src/wagmi/Actions/amm.test.ts +7 -85
  103. package/src/wagmi/Actions/amm.ts +0 -346
  104. package/src/wagmi/Actions/reward.test.ts +0 -99
  105. package/src/wagmi/Actions/reward.ts +0 -203
  106. package/src/wagmi/Connector.test.ts +4 -1
  107. package/src/wagmi/Connector.ts +24 -58
  108. package/src/wagmi/Hooks/amm.test.ts +8 -200
  109. package/src/wagmi/Hooks/amm.ts +0 -443
  110. package/src/wagmi/Hooks/reward.test.ts +1 -142
  111. package/src/wagmi/Hooks/reward.ts +0 -196
  112. package/src/wagmi/KeyManager.ts +159 -0
  113. package/src/wagmi/index.ts +1 -0
@@ -41,6 +41,8 @@ describe('sendTransaction', () => {
41
41
  gas,
42
42
  gasPrice,
43
43
  hash: hash_,
44
+ // @ts-expect-error
45
+ keyAuthorization: __,
44
46
  maxFeePerGas,
45
47
  maxPriorityFeePerGas,
46
48
  nonce,
@@ -115,6 +117,8 @@ describe('sendTransaction', () => {
115
117
  gas,
116
118
  gasPrice,
117
119
  hash: hash_,
120
+ // @ts-expect-error
121
+ keyAuthorization: __,
118
122
  maxFeePerGas,
119
123
  maxPriorityFeePerGas,
120
124
  nonce,
@@ -178,6 +182,8 @@ describe('sendTransaction', () => {
178
182
  gas,
179
183
  gasPrice,
180
184
  hash: hash_,
185
+ // @ts-expect-error
186
+ keyAuthorization: __,
181
187
  maxFeePerGas,
182
188
  maxPriorityFeePerGas,
183
189
  nonce,
@@ -251,6 +257,8 @@ describe('sendTransaction', () => {
251
257
  gas,
252
258
  gasPrice,
253
259
  hash,
260
+ // @ts-expect-error
261
+ keyAuthorization: __,
254
262
  maxFeePerGas,
255
263
  maxPriorityFeePerGas,
256
264
  nonce,
@@ -333,6 +341,8 @@ describe('sendTransaction', () => {
333
341
  gas,
334
342
  gasPrice,
335
343
  hash,
344
+ // @ts-expect-error
345
+ keyAuthorization: __,
336
346
  maxFeePerGas,
337
347
  maxPriorityFeePerGas,
338
348
  nonce,
@@ -401,6 +411,8 @@ describe('sendTransaction', () => {
401
411
  gas,
402
412
  gasPrice,
403
413
  hash: hash_,
414
+ // @ts-expect-error
415
+ keyAuthorization: __,
404
416
  maxFeePerGas,
405
417
  maxPriorityFeePerGas,
406
418
  nonce,
@@ -472,6 +484,8 @@ describe('sendTransaction', () => {
472
484
  from,
473
485
  gasPrice,
474
486
  hash,
487
+ // @ts-expect-error
488
+ keyAuthorization: __,
475
489
  maxFeePerGas,
476
490
  maxPriorityFeePerGas,
477
491
  nonce,
@@ -553,6 +567,8 @@ describe('sendTransaction', () => {
553
567
  gas,
554
568
  gasPrice,
555
569
  hash,
570
+ // @ts-expect-error
571
+ keyAuthorization: __,
556
572
  maxFeePerGas,
557
573
  maxPriorityFeePerGas,
558
574
  nonce,
@@ -596,6 +612,8 @@ describe('sendTransaction', () => {
596
612
  from,
597
613
  gasPrice,
598
614
  hash: hash_,
615
+ // @ts-expect-error
616
+ keyAuthorization: __,
599
617
  maxFeePerGas,
600
618
  maxPriorityFeePerGas,
601
619
  nonce,
@@ -644,6 +662,8 @@ describe('sendTransaction', () => {
644
662
  gas,
645
663
  gasPrice,
646
664
  hash,
665
+ // @ts-expect-error
666
+ keyAuthorization: __,
647
667
  maxFeePerGas,
648
668
  maxPriorityFeePerGas,
649
669
  nonce,
@@ -730,6 +750,8 @@ describe('sendTransaction', () => {
730
750
  gas,
731
751
  gasPrice,
732
752
  hash,
753
+ // @ts-expect-error
754
+ keyAuthorization: __,
733
755
  maxFeePerGas,
734
756
  maxPriorityFeePerGas,
735
757
  nonce,
@@ -802,6 +824,8 @@ describe('sendTransaction', () => {
802
824
  gas,
803
825
  gasPrice,
804
826
  hash: hash_,
827
+ // @ts-expect-error
828
+ keyAuthorization: __,
805
829
  maxFeePerGas,
806
830
  maxPriorityFeePerGas,
807
831
  nonce,
@@ -888,6 +912,8 @@ describe('signTransaction', () => {
888
912
  from,
889
913
  gasPrice,
890
914
  hash: hash_,
915
+ // @ts-expect-error
916
+ keyAuthorization: __,
891
917
  maxFeePerGas,
892
918
  maxPriorityFeePerGas,
893
919
  nonce,
@@ -943,6 +969,7 @@ describe('relay', () => {
943
969
  transport: withFeePayer(
944
970
  http(undefined, { fetchOptions }),
945
971
  http('http://localhost:3050'),
972
+ { policy: 'sign-and-broadcast' },
946
973
  ),
947
974
  })
948
975
  .extend(tempoActions())
@@ -963,7 +990,9 @@ describe('relay', () => {
963
990
 
964
991
  const request = RpcRequest.from(await r.json())
965
992
 
993
+ // Validate method
966
994
  if (
995
+ (request as any).method !== 'eth_signRawTransaction' &&
967
996
  request.method !== 'eth_sendRawTransaction' &&
968
997
  request.method !== 'eth_sendRawTransactionSync'
969
998
  )
@@ -972,7 +1001,7 @@ describe('relay', () => {
972
1001
  {
973
1002
  error: new RpcResponse.InvalidParamsError({
974
1003
  message:
975
- 'service only supports `eth_sendRawTransaction` and `eth_sendRawTransactionSync`',
1004
+ 'service only supports `eth_signTransaction`, `eth_sendRawTransaction`, and `eth_sendRawTransactionSync`',
976
1005
  }),
977
1006
  },
978
1007
  { request },
@@ -985,7 +1014,7 @@ describe('relay', () => {
985
1014
  RpcResponse.from(
986
1015
  {
987
1016
  error: new RpcResponse.InvalidParamsError({
988
- message: 'service only supports `0x77` transactions',
1017
+ message: 'service only supports `0x76` transactions',
989
1018
  }),
990
1019
  },
991
1020
  { request },
@@ -997,10 +1026,20 @@ describe('relay', () => {
997
1026
  ...transaction,
998
1027
  feePayer: client.account,
999
1028
  })
1029
+
1030
+ // Handle based on RPC method
1031
+ if ((request as any).method === 'eth_signRawTransaction') {
1032
+ // Policy: 'sign-only' - Return signed transaction without broadcasting
1033
+ return Response.json(
1034
+ RpcResponse.from({ result: serializedTransaction }, { request }),
1035
+ )
1036
+ }
1037
+
1038
+ // Policy: 'sign-and-broadcast' - Sign, broadcast, and return hash
1000
1039
  const result = await client.request({
1001
1040
  method: request.method,
1002
1041
  params: [serializedTransaction],
1003
- })
1042
+ } as never)
1004
1043
 
1005
1044
  return Response.json(RpcResponse.from({ result }, { request }))
1006
1045
  }),
@@ -1050,6 +1089,8 @@ describe('relay', () => {
1050
1089
  gas,
1051
1090
  gasPrice,
1052
1091
  hash,
1092
+ // @ts-expect-error
1093
+ keyAuthorization: __,
1053
1094
  maxFeePerGas,
1054
1095
  maxPriorityFeePerGas,
1055
1096
  nonce,
@@ -1129,6 +1170,8 @@ describe('relay', () => {
1129
1170
  gas,
1130
1171
  gasPrice,
1131
1172
  hash,
1173
+ // @ts-expect-error
1174
+ keyAuthorization: __,
1132
1175
  maxFeePerGas,
1133
1176
  maxPriorityFeePerGas,
1134
1177
  nonce,
@@ -1239,6 +1282,8 @@ describe('relay', () => {
1239
1282
  gas,
1240
1283
  gasPrice,
1241
1284
  hash,
1285
+ // @ts-expect-error
1286
+ keyAuthorization: __,
1242
1287
  maxFeePerGas,
1243
1288
  maxPriorityFeePerGas,
1244
1289
  nonce,
@@ -1288,4 +1333,62 @@ describe('relay', () => {
1288
1333
  `)
1289
1334
  })
1290
1335
  })
1336
+
1337
+ describe('policy: sign-only', () => {
1338
+ test('relay co-signs and transport auto-submits', async () => {
1339
+ const signClient = getClient({
1340
+ transport: withFeePayer(
1341
+ http(undefined, { fetchOptions }),
1342
+ http('http://localhost:3050'),
1343
+ { policy: 'sign-only' },
1344
+ ),
1345
+ })
1346
+ .extend(tempoActions())
1347
+ .extend(walletActions)
1348
+ .extend(publicActions)
1349
+
1350
+ // unfunded account that needs sponsorship
1351
+ const account = privateKeyToAccount(
1352
+ '0xecc3fe55647412647e5c6b657c496803b08ef956f927b7a821da298cfbdd9666',
1353
+ )
1354
+
1355
+ // With 'sign-only' policy, the relay co-signs and the transport auto-submits
1356
+ const { user, token, receipt } = await signClient.fee.setUserTokenSync({
1357
+ account,
1358
+ feePayer: true,
1359
+ token: 1n,
1360
+ })
1361
+
1362
+ // Verify the action returned the expected values
1363
+ expect(user).toBe(account.address)
1364
+ expect(token).toBe('0x20C0000000000000000000000000000000000001')
1365
+ expect(receipt).toBeDefined()
1366
+
1367
+ // Verify the transaction was successfully executed
1368
+ const userToken = await signClient.fee.getUserToken({
1369
+ account: account.address,
1370
+ })
1371
+ expect(userToken?.id).toBe(1n)
1372
+
1373
+ const {
1374
+ feePayerSignature,
1375
+ from,
1376
+ gas,
1377
+ gasPrice,
1378
+ maxFeePerGas,
1379
+ maxPriorityFeePerGas,
1380
+ signature,
1381
+ } = (await signClient.getTransaction({
1382
+ hash: receipt.transactionHash,
1383
+ })) as any
1384
+
1385
+ expect(feePayerSignature).toBeDefined()
1386
+ expect(from).toBe(account.address.toLowerCase())
1387
+ expect(gas).toBeDefined()
1388
+ expect(gasPrice).toBeDefined()
1389
+ expect(maxFeePerGas).toBeDefined()
1390
+ expect(maxPriorityFeePerGas).toBeDefined()
1391
+ expect(signature).toBeDefined()
1392
+ })
1393
+ })
1291
1394
  })
@@ -35,3 +35,24 @@ export function defineCall<
35
35
  to: call.address,
36
36
  } as const
37
37
  }
38
+
39
+ /**
40
+ * Normalizes a value into a structured-clone compatible format.
41
+ *
42
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Window/structuredClone
43
+ */
44
+ export function normalizeValue<type>(value: type): type {
45
+ if (Array.isArray(value)) return value.map(normalizeValue) as never
46
+ if (typeof value === 'function') return undefined as never
47
+ if (typeof value !== 'object' || value === null) return value
48
+ if (Object.getPrototypeOf(value) !== Object.prototype)
49
+ try {
50
+ return structuredClone(value)
51
+ } catch {
52
+ return undefined as never
53
+ }
54
+
55
+ const normalized: Record<string, unknown> = {}
56
+ for (const [k, v] of Object.entries(value)) normalized[k] = normalizeValue(v)
57
+ return normalized as never
58
+ }
@@ -1,8 +1,8 @@
1
- import { connect, getConnectorClient } from '@wagmi/core'
1
+ import { connect } from '@wagmi/core'
2
2
  import { parseUnits } from 'viem'
3
3
  import { describe, expect, test } from 'vitest'
4
4
  import { addresses } from '../../../test/config.js'
5
- import { accounts, setupPoolWithLiquidity } from '../../../test/viem/config.js'
5
+ import { accounts } from '../../../test/viem/config.js'
6
6
  import { config, queryClient } from '../../../test/wagmi/config.js'
7
7
  import * as ammActions from './amm.js'
8
8
  import * as tokenActions from './token.js'
@@ -96,23 +96,18 @@ describe('mintSync', () => {
96
96
  const { receipt: mintReceipt, ...mintResult } = await ammActions.mintSync(
97
97
  config,
98
98
  {
99
- userToken: {
100
- address: token,
101
- amount: parseUnits('100', 6),
102
- },
103
- validatorToken: {
104
- address: addresses.alphaUsd,
105
- amount: parseUnits('100', 6),
106
- },
99
+ userTokenAddress: token,
100
+ validatorTokenAddress: addresses.alphaUsd,
101
+ validatorTokenAmount: parseUnits('100', 6),
107
102
  to: account.address,
108
103
  },
109
104
  )
110
105
  expect(mintReceipt).toBeDefined()
111
106
  expect(mintResult).toMatchInlineSnapshot(`
112
107
  {
113
- "amountUserToken": 100000000n,
108
+ "amountUserToken": 0n,
114
109
  "amountValidatorToken": 100000000n,
115
- "liquidity": 4999999999999000n,
110
+ "liquidity": 49999000n,
116
111
  "sender": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
117
112
  "userToken": "0x20C0000000000000000000000000000000000004",
118
113
  "validatorToken": "0x20C0000000000000000000000000000000000001",
@@ -120,76 +115,3 @@ describe('mintSync', () => {
120
115
  `)
121
116
  })
122
117
  })
123
-
124
- describe('burnSync', () => {
125
- test('default', async () => {
126
- await connect(config, {
127
- connector: config.connectors[0]!,
128
- })
129
-
130
- const client = await getConnectorClient(config)
131
- const { tokenAddress } = await setupPoolWithLiquidity(client)
132
-
133
- // Get LP balance before burn
134
- const lpBalanceBefore = await ammActions.getLiquidityBalance(config, {
135
- userToken: tokenAddress,
136
- validatorToken: addresses.alphaUsd,
137
- address: account.address,
138
- })
139
-
140
- // Burn half of LP tokens
141
- const { receipt: burnReceipt, ...burnResult } = await ammActions.burnSync(
142
- config,
143
- {
144
- userToken: tokenAddress,
145
- validatorToken: addresses.alphaUsd,
146
- liquidity: lpBalanceBefore / 2n,
147
- to: account.address,
148
- },
149
- )
150
- expect(burnReceipt).toBeDefined()
151
- expect(burnResult).toMatchInlineSnapshot(`
152
- {
153
- "amountUserToken": 49999999n,
154
- "amountValidatorToken": 49999999n,
155
- "liquidity": 2499999999999500n,
156
- "sender": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
157
- "to": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
158
- "userToken": "0x20c0000000000000000000000000000000000005",
159
- "validatorToken": "0x20C0000000000000000000000000000000000001",
160
- }
161
- `)
162
- })
163
- })
164
-
165
- describe('rebalanceSwapSync', () => {
166
- test('default', async () => {
167
- await connect(config, {
168
- connector: config.connectors[0]!,
169
- })
170
-
171
- const client = await getConnectorClient(config)
172
- const { tokenAddress } = await setupPoolWithLiquidity(client)
173
-
174
- const account2 = accounts[1]
175
-
176
- // Perform rebalance swap
177
- const { receipt: swapReceipt, ...swapResult } =
178
- await ammActions.rebalanceSwapSync(config, {
179
- userToken: tokenAddress,
180
- validatorToken: addresses.alphaUsd,
181
- amountOut: parseUnits('10', 6),
182
- to: account2.address,
183
- })
184
- expect(swapReceipt).toBeDefined()
185
- expect(swapResult).toMatchInlineSnapshot(`
186
- {
187
- "amountIn": 9985001n,
188
- "amountOut": 10000000n,
189
- "swapper": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
190
- "userToken": "0x20C0000000000000000000000000000000000006",
191
- "validatorToken": "0x20C0000000000000000000000000000000000001",
192
- }
193
- `)
194
- })
195
- })