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
@@ -1,4 +1,7 @@
1
1
  import type { Account, Chain, Client, Transport } from 'viem'
2
+ import type { VerifyHashParameters, VerifyHashReturnType } from 'viem/actions'
3
+ import type { PartialBy } from '../internal/types.js'
4
+ import * as accountActions from './Actions/account.js'
2
5
  import * as ammActions from './Actions/amm.js'
3
6
  import * as dexActions from './Actions/dex.js'
4
7
  import * as faucetActions from './Actions/faucet.js'
@@ -11,6 +14,34 @@ export type Decorator<
11
14
  chain extends Chain | undefined = Chain | undefined,
12
15
  account extends Account | undefined = Account | undefined,
13
16
  > = {
17
+ /**
18
+ * Verifies that a signature is valid for a given hash and address.
19
+ * Supports Secp256k1, P256, WebCrypto P256, and WebAuthn signatures.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { createClient, http } from 'viem'
24
+ * import { tempo } from 'tempo.ts/chains'
25
+ * import { tempoActions } from 'tempo.ts/viem'
26
+ *
27
+ * const client = createClient({
28
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
29
+ * transport: http(),
30
+ * }).extend(tempoActions())
31
+ *
32
+ * const valid = await client.verifyHash({
33
+ * address: '0x...',
34
+ * hash: '0x...',
35
+ * signature: '0x...',
36
+ * })
37
+ * ```
38
+ *
39
+ * @param parameters - Parameters.
40
+ * @returns Whether the signature is valid.
41
+ */
42
+ verifyHash: (
43
+ parameters: PartialBy<VerifyHashParameters, 'address'>,
44
+ ) => Promise<VerifyHashReturnType>
14
45
  amm: {
15
46
  /**
16
47
  * Gets the reserves for a liquidity pool.
@@ -69,66 +100,6 @@ export type Decorator<
69
100
  getLiquidityBalance: (
70
101
  parameters: ammActions.getLiquidityBalance.Parameters,
71
102
  ) => Promise<ammActions.getLiquidityBalance.ReturnValue>
72
- /**
73
- * Performs a rebalance swap from validator token to user token.
74
- *
75
- * @example
76
- * ```ts
77
- * import { createClient, http } from 'viem'
78
- * import { privateKeyToAccount } from 'viem/accounts'
79
- * import { tempo } from 'tempo.ts/chains'
80
- * import { tempoActions } from 'tempo.ts/viem'
81
- *
82
- * const client = createClient({
83
- * account: privateKeyToAccount('0x...'),
84
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
85
- * transport: http(),
86
- * }).extend(tempoActions())
87
- *
88
- * const hash = await client.amm.rebalanceSwap({
89
- * userToken: '0x...',
90
- * validatorToken: '0x...',
91
- * amountOut: 100n,
92
- * to: '0x...',
93
- * })
94
- * ```
95
- *
96
- * @param parameters - Parameters.
97
- * @returns The transaction hash.
98
- */
99
- rebalanceSwap: (
100
- parameters: ammActions.rebalanceSwap.Parameters<chain, account>,
101
- ) => Promise<ammActions.rebalanceSwap.ReturnValue>
102
- /**
103
- * Performs a rebalance swap from validator token to user token.
104
- *
105
- * @example
106
- * ```ts
107
- * import { createClient, http } from 'viem'
108
- * import { privateKeyToAccount } from 'viem/accounts'
109
- * import { tempo } from 'tempo.ts/chains'
110
- * import { tempoActions } from 'tempo.ts/viem'
111
- *
112
- * const client = createClient({
113
- * account: privateKeyToAccount('0x...'),
114
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
115
- * transport: http(),
116
- * }).extend(tempoActions())
117
- *
118
- * const result = await client.amm.rebalanceSwapSync({
119
- * userToken: '0x...',
120
- * validatorToken: '0x...',
121
- * amountOut: 100n,
122
- * to: '0x...',
123
- * })
124
- * ```
125
- *
126
- * @param parameters - Parameters.
127
- * @returns The transaction receipt and event data.
128
- */
129
- rebalanceSwapSync: (
130
- parameters: ammActions.rebalanceSwapSync.Parameters<chain, account>,
131
- ) => Promise<ammActions.rebalanceSwapSync.ReturnValue>
132
103
  /**
133
104
  * Adds liquidity to a pool.
134
105
  *
@@ -199,118 +170,6 @@ export type Decorator<
199
170
  mintSync: (
200
171
  parameters: ammActions.mintSync.Parameters<chain, account>,
201
172
  ) => Promise<ammActions.mintSync.ReturnValue>
202
- /**
203
- * Removes liquidity from a pool.
204
- *
205
- * @example
206
- * ```ts
207
- * import { createClient, http } from 'viem'
208
- * import { privateKeyToAccount } from 'viem/accounts'
209
- * import { tempo } from 'tempo.ts/chains'
210
- * import { tempoActions } from 'tempo.ts/viem'
211
- *
212
- * const client = createClient({
213
- * account: privateKeyToAccount('0x...'),
214
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
215
- * transport: http(),
216
- * }).extend(tempoActions())
217
- *
218
- * const hash = await client.amm.burn({
219
- * userToken: '0x...',
220
- * validatorToken: '0x...',
221
- * liquidity: 50n,
222
- * to: '0x...',
223
- * })
224
- * ```
225
- *
226
- * @param parameters - Parameters.
227
- * @returns The transaction hash.
228
- */
229
- burn: (
230
- parameters: ammActions.burn.Parameters<chain, account>,
231
- ) => Promise<ammActions.burn.ReturnValue>
232
- /**
233
- * Removes liquidity from a pool.
234
- *
235
- * @example
236
- * ```ts
237
- * import { createClient, http } from 'viem'
238
- * import { privateKeyToAccount } from 'viem/accounts'
239
- * import { tempo } from 'tempo.ts/chains'
240
- * import { tempoActions } from 'tempo.ts/viem'
241
- *
242
- * const client = createClient({
243
- * account: privateKeyToAccount('0x...'),
244
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
245
- * transport: http(),
246
- * }).extend(tempoActions())
247
- *
248
- * const result = await client.amm.burnSync({
249
- * userToken: '0x...',
250
- * validatorToken: '0x...',
251
- * liquidity: 50n,
252
- * to: '0x...',
253
- * })
254
- * ```
255
- *
256
- * @param parameters - Parameters.
257
- * @returns The transaction receipt and event data.
258
- */
259
- burnSync: (
260
- parameters: ammActions.burnSync.Parameters<chain, account>,
261
- ) => Promise<ammActions.burnSync.ReturnValue>
262
- /**
263
- * Watches for rebalance swap events.
264
- *
265
- * @example
266
- * ```ts
267
- * import { createClient, http } from 'viem'
268
- * import { tempo } from 'tempo.ts/chains'
269
- * import { tempoActions } from 'tempo.ts/viem'
270
- *
271
- * const client = createClient({
272
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
273
- * transport: http(),
274
- * }).extend(tempoActions())
275
- *
276
- * const unwatch = client.amm.watchRebalanceSwap({
277
- * onRebalanceSwap: (args, log) => {
278
- * console.log('Rebalance swap:', args)
279
- * },
280
- * })
281
- * ```
282
- *
283
- * @param parameters - Parameters.
284
- * @returns A function to unsubscribe from the event.
285
- */
286
- watchRebalanceSwap: (
287
- parameters: ammActions.watchRebalanceSwap.Parameters,
288
- ) => () => void
289
- /**
290
- * Watches for fee swap events.
291
- *
292
- * @example
293
- * ```ts
294
- * import { createClient, http } from 'viem'
295
- * import { tempo } from 'tempo.ts/chains'
296
- * import { tempoActions } from 'tempo.ts/viem'
297
- *
298
- * const client = createClient({
299
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
300
- * transport: http(),
301
- * }).extend(tempoActions())
302
- *
303
- * const unwatch = client.amm.watchFeeSwap({
304
- * onFeeSwap: (args, log) => {
305
- * console.log('Fee swap:', args)
306
- * },
307
- * })
308
- * ```
309
- *
310
- * @param parameters - Parameters.
311
- * @returns A function to unsubscribe from the event.
312
- */
313
- watchFeeSwap: (parameters: ammActions.watchFeeSwap.Parameters) => () => void
314
173
  /**
315
174
  * Watches for liquidity mint events.
316
175
  *
@@ -336,31 +195,6 @@ export type Decorator<
336
195
  * @returns A function to unsubscribe from the event.
337
196
  */
338
197
  watchMint: (parameters: ammActions.watchMint.Parameters) => () => void
339
- /**
340
- * Watches for liquidity burn events.
341
- *
342
- * @example
343
- * ```ts
344
- * import { createClient, http } from 'viem'
345
- * import { tempo } from 'tempo.ts/chains'
346
- * import { tempoActions } from 'tempo.ts/viem'
347
- *
348
- * const client = createClient({
349
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
350
- * transport: http(),
351
- * }).extend(tempoActions())
352
- *
353
- * const unwatch = client.amm.watchBurn({
354
- * onBurn: (args, log) => {
355
- * console.log('Liquidity removed:', args)
356
- * },
357
- * })
358
- * ```
359
- *
360
- * @param parameters - Parameters.
361
- * @returns A function to unsubscribe from the event.
362
- */
363
- watchBurn: (parameters: ammActions.watchBurn.Parameters) => () => void
364
198
  }
365
199
  dex: {
366
200
  /**
@@ -1570,88 +1404,6 @@ export type Decorator<
1570
1404
  ) => () => void
1571
1405
  }
1572
1406
  reward: {
1573
- /**
1574
- * Cancels an active reward stream and refunds remaining tokens.
1575
- *
1576
- * @example
1577
- * ```ts
1578
- * import { createClient, http } from 'viem'
1579
- * import { privateKeyToAccount } from 'viem/accounts'
1580
- * import { tempo } from 'tempo.ts/chains'
1581
- * import { tempoActions } from 'tempo.ts/viem'
1582
- *
1583
- * const client = createClient({
1584
- * account: privateKeyToAccount('0x...'),
1585
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
1586
- * transport: http(),
1587
- * }).extend(tempoActions())
1588
- *
1589
- * const hash = await client.reward.cancel({
1590
- * id: 1n,
1591
- * token: '0x20c0000000000000000000000000000000000001',
1592
- * })
1593
- * ```
1594
- *
1595
- * @param parameters - Parameters.
1596
- * @returns The transaction hash.
1597
- */
1598
- cancel: (
1599
- parameters: rewardActions.cancel.Parameters<chain, account>,
1600
- ) => Promise<rewardActions.cancel.ReturnValue>
1601
- /**
1602
- * Cancels an active reward stream and waits for confirmation.
1603
- *
1604
- * @example
1605
- * ```ts
1606
- * import { createClient, http } from 'viem'
1607
- * import { privateKeyToAccount } from 'viem/accounts'
1608
- * import { tempo } from 'tempo.ts/chains'
1609
- * import { tempoActions } from 'tempo.ts/viem'
1610
- *
1611
- * const client = createClient({
1612
- * account: privateKeyToAccount('0x...'),
1613
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
1614
- * transport: http(),
1615
- * }).extend(tempoActions())
1616
- *
1617
- * const result = await client.reward.cancelSync({
1618
- * id: 1n,
1619
- * token: '0x20c0000000000000000000000000000000000001',
1620
- * })
1621
- * ```
1622
- *
1623
- * @param parameters - Parameters.
1624
- * @returns The transaction receipt and event data.
1625
- */
1626
- cancelSync: (
1627
- parameters: rewardActions.cancelSync.Parameters<chain, account>,
1628
- ) => Promise<rewardActions.cancelSync.ReturnValue>
1629
- /**
1630
- * Gets a reward stream by its ID.
1631
- *
1632
- * @example
1633
- * ```ts
1634
- * import { createClient, http } from 'viem'
1635
- * import { tempo } from 'tempo.ts/chains'
1636
- * import { tempoActions } from 'tempo.ts/viem'
1637
- *
1638
- * const client = createClient({
1639
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
1640
- * transport: http(),
1641
- * }).extend(tempoActions())
1642
- *
1643
- * const stream = await client.reward.getStream({
1644
- * id: 1n,
1645
- * token: '0x20c0000000000000000000000000000000000001',
1646
- * })
1647
- * ```
1648
- *
1649
- * @param parameters - Parameters.
1650
- * @returns The reward stream details.
1651
- */
1652
- getStream: (
1653
- parameters: rewardActions.getStream.Parameters,
1654
- ) => Promise<rewardActions.getStream.ReturnValue>
1655
1407
  /**
1656
1408
  * Gets the total reward per second rate for all active streams.
1657
1409
  *
@@ -2949,24 +2701,14 @@ export function decorator() {
2949
2701
  client: Client<transport, chain, account>,
2950
2702
  ): Decorator<chain, account> => {
2951
2703
  return {
2704
+ verifyHash: (parameters) => accountActions.verifyHash(client, parameters),
2952
2705
  amm: {
2953
2706
  getPool: (parameters) => ammActions.getPool(client, parameters),
2954
2707
  getLiquidityBalance: (parameters) =>
2955
2708
  ammActions.getLiquidityBalance(client, parameters),
2956
- rebalanceSwap: (parameters) =>
2957
- ammActions.rebalanceSwap(client, parameters),
2958
- rebalanceSwapSync: (parameters) =>
2959
- ammActions.rebalanceSwapSync(client, parameters),
2960
2709
  mint: (parameters) => ammActions.mint(client, parameters),
2961
2710
  mintSync: (parameters) => ammActions.mintSync(client, parameters),
2962
- burn: (parameters) => ammActions.burn(client, parameters),
2963
- burnSync: (parameters) => ammActions.burnSync(client, parameters),
2964
- watchRebalanceSwap: (parameters) =>
2965
- ammActions.watchRebalanceSwap(client, parameters),
2966
- watchFeeSwap: (parameters) =>
2967
- ammActions.watchFeeSwap(client, parameters),
2968
2711
  watchMint: (parameters) => ammActions.watchMint(client, parameters),
2969
- watchBurn: (parameters) => ammActions.watchBurn(client, parameters),
2970
2712
  },
2971
2713
  dex: {
2972
2714
  buy: (parameters) => dexActions.buy(client, parameters),
@@ -3046,10 +2788,6 @@ export function decorator() {
3046
2788
  policyActions.watchBlacklistUpdated(client, parameters),
3047
2789
  },
3048
2790
  reward: {
3049
- cancel: (parameters) => rewardActions.cancel(client, parameters),
3050
- cancelSync: (parameters) =>
3051
- rewardActions.cancelSync(client, parameters),
3052
- getStream: (parameters) => rewardActions.getStream(client, parameters),
3053
2791
  getTotalPerSecond: (parameters) =>
3054
2792
  rewardActions.getTotalPerSecond(client, parameters),
3055
2793
  setRecipient: (parameters) =>
@@ -0,0 +1,88 @@
1
+ import * as Json from 'ox/Json'
2
+
3
+ import type { MaybePromise } from '../internal/types.js'
4
+
5
+ export type Storage<
6
+ schema extends Record<string, unknown> = Record<string, unknown>,
7
+ > = {
8
+ getItem: <name extends keyof schema>(
9
+ name: name,
10
+ ) => MaybePromise<schema[name] | null>
11
+ removeItem: <name extends keyof schema>(name: name) => MaybePromise<void>
12
+ setItem: <name extends keyof schema>(
13
+ name: name,
14
+ value: schema[name],
15
+ ) => MaybePromise<void>
16
+ }
17
+
18
+ export function from<schema extends Record<string, unknown>>(
19
+ storage: Storage,
20
+ options: { key?: string | undefined } = {},
21
+ ): Storage<schema> {
22
+ const key = (name: any) => `${options.key ? `${options.key}:` : ''}${name}`
23
+ return {
24
+ getItem: (name) => storage.getItem(key(name)) as never,
25
+ removeItem: (name) => storage.removeItem(key(name)),
26
+ setItem: (name, value) => storage.setItem(key(name), value),
27
+ }
28
+ }
29
+
30
+ export namespace from {
31
+ export type Options = {
32
+ key?: string | undefined
33
+ }
34
+ }
35
+
36
+ export function localStorage<schema extends Record<string, unknown>>(
37
+ options: localStorage.Options = {},
38
+ ) {
39
+ if (typeof window === 'undefined') return memory<schema>()
40
+ return from<schema>(
41
+ {
42
+ async getItem(name) {
43
+ const item = window.localStorage.getItem(name)
44
+ if (item === null) return null
45
+ try {
46
+ return Json.parse(item)
47
+ } catch {
48
+ return null
49
+ }
50
+ },
51
+ async removeItem(name) {
52
+ window.localStorage.removeItem(name)
53
+ },
54
+ async setItem(name, value) {
55
+ window.localStorage.setItem(name, Json.stringify(value))
56
+ },
57
+ },
58
+ options,
59
+ )
60
+ }
61
+
62
+ export namespace localStorage {
63
+ export type Options = from.Options
64
+ }
65
+
66
+ const store = new Map<string, any>()
67
+ export function memory<schema extends Record<string, unknown>>(
68
+ options: memory.Options = {},
69
+ ) {
70
+ return from<schema>(
71
+ {
72
+ getItem(name) {
73
+ return store.get(name) ?? null
74
+ },
75
+ removeItem(name) {
76
+ store.delete(name)
77
+ },
78
+ setItem(name, value) {
79
+ store.set(name, value)
80
+ },
81
+ },
82
+ options,
83
+ )
84
+ }
85
+
86
+ export namespace memory {
87
+ export type Options = from.Options
88
+ }
@@ -18,14 +18,22 @@ export type FeePayer = Transport<typeof withFeePayer.type>
18
18
  * Creates a fee payer transport that routes requests between
19
19
  * the default transport or the fee payer transport.
20
20
  *
21
+ * The policy parameter controls how the fee payer handles transactions:
22
+ * - `'sign-only'`: Fee payer co-signs the transaction and returns it to the client transport, which then broadcasts it via the default transport
23
+ * - `'sign-and-broadcast'`: Fee payer co-signs and broadcasts the transaction directly
24
+ *
21
25
  * @param defaultTransport - The default transport to use.
22
26
  * @param feePayerTransport - The fee payer transport to use.
27
+ * @param parameters - Configuration parameters.
23
28
  * @returns A relay transport.
24
29
  */
25
30
  export function withFeePayer(
26
31
  defaultTransport: Transport,
27
32
  relayTransport: Transport,
33
+ parameters?: withFeePayer.Parameters,
28
34
  ): withFeePayer.ReturnValue {
35
+ const { policy = 'sign-only' } = parameters ?? {}
36
+
29
37
  return (config) => {
30
38
  const transport_default = defaultTransport(config)
31
39
  const transport_relay = relayTransport(config)
@@ -40,9 +48,34 @@ export function withFeePayer(
40
48
  ) {
41
49
  const serialized = (params as any)[0] as `0x76${string}`
42
50
  const transaction = Transaction.deserialize(serialized)
51
+
43
52
  // If the transaction is intended to be sponsored, forward it to the relay.
44
- if (transaction.feePayerSignature === null)
45
- return transport_relay.request({ method, params }, options) as never
53
+ if (transaction.feePayerSignature === null) {
54
+ // For 'sign-and-broadcast', relay signs and broadcasts
55
+ if (policy === 'sign-and-broadcast')
56
+ return transport_relay.request(
57
+ { method, params },
58
+ options,
59
+ ) as never
60
+
61
+ // For 'sign-only', request signature from relay using eth_signRawTransaction
62
+ {
63
+ // Request signature from relay using eth_signRawTransaction
64
+ const signedTransaction = await transport_relay.request(
65
+ {
66
+ method: 'eth_signRawTransaction',
67
+ params: [serialized],
68
+ },
69
+ options,
70
+ )
71
+
72
+ // Broadcast the signed transaction via the default transport
73
+ return transport_default.request(
74
+ { method, params: [signedTransaction] },
75
+ options,
76
+ ) as never
77
+ }
78
+ }
46
79
  }
47
80
  return transport_default.request({ method, params }, options) as never
48
81
  },
@@ -54,6 +87,11 @@ export function withFeePayer(
54
87
  export declare namespace withFeePayer {
55
88
  export const type = 'feePayer'
56
89
 
90
+ export type Parameters = {
91
+ /** Policy for how the fee payer should handle transactions. Defaults to `'sign-only'`. */
92
+ policy?: 'sign-only' | 'sign-and-broadcast' | undefined
93
+ }
94
+
57
95
  export type ReturnValue = FeePayer
58
96
  }
59
97