tempo.ts 0.6.2 → 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.
- package/CHANGELOG.md +128 -0
- package/README.md +6 -2
- package/dist/ox/Transaction.js +1 -1
- package/dist/ox/Transaction.js.map +1 -1
- package/dist/server/Handler.d.ts +346 -0
- package/dist/server/Handler.d.ts.map +1 -0
- package/dist/server/Handler.js +441 -0
- package/dist/server/Handler.js.map +1 -0
- package/dist/server/Kv.d.ts +16 -0
- package/dist/server/Kv.d.ts.map +1 -0
- package/dist/server/Kv.js +25 -0
- package/dist/server/Kv.js.map +1 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +3 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/internal/requestListener.d.ts +124 -0
- package/dist/server/internal/requestListener.d.ts.map +1 -0
- package/dist/server/internal/requestListener.js +174 -0
- package/dist/server/internal/requestListener.js.map +1 -0
- package/dist/viem/Actions/amm.d.ts +51 -1245
- package/dist/viem/Actions/amm.d.ts.map +1 -1
- package/dist/viem/Actions/amm.js +15 -478
- package/dist/viem/Actions/amm.js.map +1 -1
- package/dist/viem/Actions/reward.d.ts +0 -1067
- package/dist/viem/Actions/reward.d.ts.map +1 -1
- package/dist/viem/Actions/reward.js +4 -212
- package/dist/viem/Actions/reward.js.map +1 -1
- package/dist/viem/Decorator.d.ts +0 -263
- package/dist/viem/Decorator.d.ts.map +1 -1
- package/dist/viem/Decorator.js +0 -10
- package/dist/viem/Decorator.js.map +1 -1
- package/dist/viem/Storage.d.ts +23 -0
- package/dist/viem/Storage.d.ts.map +1 -0
- package/dist/viem/Storage.js +47 -0
- package/dist/viem/Storage.js.map +1 -0
- package/dist/viem/Transport.d.ts +10 -1
- package/dist/viem/Transport.d.ts.map +1 -1
- package/dist/viem/Transport.js +22 -3
- package/dist/viem/Transport.js.map +1 -1
- package/dist/viem/internal/utils.d.ts +6 -0
- package/dist/viem/internal/utils.d.ts.map +1 -1
- package/dist/viem/internal/utils.js +24 -0
- package/dist/viem/internal/utils.js.map +1 -1
- package/dist/wagmi/Actions/amm.d.ts +0 -225
- package/dist/wagmi/Actions/amm.d.ts.map +1 -1
- package/dist/wagmi/Actions/amm.js +0 -248
- package/dist/wagmi/Actions/amm.js.map +1 -1
- package/dist/wagmi/Actions/reward.d.ts +0 -110
- package/dist/wagmi/Actions/reward.d.ts.map +1 -1
- package/dist/wagmi/Actions/reward.js +0 -121
- package/dist/wagmi/Actions/reward.js.map +1 -1
- package/dist/wagmi/Connector.d.ts +6 -17
- package/dist/wagmi/Connector.d.ts.map +1 -1
- package/dist/wagmi/Connector.js +17 -43
- package/dist/wagmi/Connector.js.map +1 -1
- package/dist/wagmi/Hooks/amm.d.ts +0 -236
- package/dist/wagmi/Hooks/amm.d.ts.map +1 -1
- package/dist/wagmi/Hooks/amm.js +0 -285
- package/dist/wagmi/Hooks/amm.js.map +1 -1
- package/dist/wagmi/Hooks/reward.d.ts +0 -88
- package/dist/wagmi/Hooks/reward.d.ts.map +1 -1
- package/dist/wagmi/Hooks/reward.js +0 -103
- package/dist/wagmi/Hooks/reward.js.map +1 -1
- package/dist/wagmi/KeyManager.d.ts +57 -0
- package/dist/wagmi/KeyManager.d.ts.map +1 -0
- package/dist/wagmi/KeyManager.js +101 -0
- package/dist/wagmi/KeyManager.js.map +1 -0
- package/dist/wagmi/index.d.ts +1 -0
- package/dist/wagmi/index.d.ts.map +1 -1
- package/dist/wagmi/index.js +1 -0
- package/dist/wagmi/index.js.map +1 -1
- package/package.json +8 -2
- package/src/ox/Transaction.ts +1 -1
- package/src/ox/e2e.test.ts +7 -0
- package/src/server/Handler.test.ts +566 -0
- package/src/server/Handler.ts +577 -0
- package/src/server/Kv.ts +40 -0
- package/src/server/index.ts +2 -0
- package/src/server/internal/requestListener.ts +285 -0
- package/src/viem/Actions/amm.test.ts +10 -284
- package/src/viem/Actions/amm.ts +88 -768
- package/src/viem/Actions/reward.test.ts +4 -212
- package/src/viem/Actions/reward.ts +4 -291
- package/src/viem/Decorator.ts +0 -294
- package/src/viem/Storage.ts +88 -0
- package/src/viem/Transport.ts +40 -2
- package/src/viem/e2e.test.ts +106 -3
- package/src/viem/internal/utils.ts +21 -0
- package/src/wagmi/Actions/amm.test.ts +7 -85
- package/src/wagmi/Actions/amm.ts +0 -346
- package/src/wagmi/Actions/reward.test.ts +0 -99
- package/src/wagmi/Actions/reward.ts +0 -203
- package/src/wagmi/Connector.test.ts +4 -1
- package/src/wagmi/Connector.ts +24 -58
- package/src/wagmi/Hooks/amm.test.ts +8 -200
- package/src/wagmi/Hooks/amm.ts +0 -443
- package/src/wagmi/Hooks/reward.test.ts +1 -142
- package/src/wagmi/Hooks/reward.ts +0 -196
- package/src/wagmi/KeyManager.ts +159 -0
- package/src/wagmi/index.ts +1 -0
package/src/viem/Decorator.ts
CHANGED
|
@@ -100,66 +100,6 @@ export type Decorator<
|
|
|
100
100
|
getLiquidityBalance: (
|
|
101
101
|
parameters: ammActions.getLiquidityBalance.Parameters,
|
|
102
102
|
) => Promise<ammActions.getLiquidityBalance.ReturnValue>
|
|
103
|
-
/**
|
|
104
|
-
* Performs a rebalance swap from validator token to user token.
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* ```ts
|
|
108
|
-
* import { createClient, http } from 'viem'
|
|
109
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
110
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
111
|
-
* import { tempoActions } from 'tempo.ts/viem'
|
|
112
|
-
*
|
|
113
|
-
* const client = createClient({
|
|
114
|
-
* account: privateKeyToAccount('0x...'),
|
|
115
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
116
|
-
* transport: http(),
|
|
117
|
-
* }).extend(tempoActions())
|
|
118
|
-
*
|
|
119
|
-
* const hash = await client.amm.rebalanceSwap({
|
|
120
|
-
* userToken: '0x...',
|
|
121
|
-
* validatorToken: '0x...',
|
|
122
|
-
* amountOut: 100n,
|
|
123
|
-
* to: '0x...',
|
|
124
|
-
* })
|
|
125
|
-
* ```
|
|
126
|
-
*
|
|
127
|
-
* @param parameters - Parameters.
|
|
128
|
-
* @returns The transaction hash.
|
|
129
|
-
*/
|
|
130
|
-
rebalanceSwap: (
|
|
131
|
-
parameters: ammActions.rebalanceSwap.Parameters<chain, account>,
|
|
132
|
-
) => Promise<ammActions.rebalanceSwap.ReturnValue>
|
|
133
|
-
/**
|
|
134
|
-
* Performs a rebalance swap from validator token to user token.
|
|
135
|
-
*
|
|
136
|
-
* @example
|
|
137
|
-
* ```ts
|
|
138
|
-
* import { createClient, http } from 'viem'
|
|
139
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
140
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
141
|
-
* import { tempoActions } from 'tempo.ts/viem'
|
|
142
|
-
*
|
|
143
|
-
* const client = createClient({
|
|
144
|
-
* account: privateKeyToAccount('0x...'),
|
|
145
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
146
|
-
* transport: http(),
|
|
147
|
-
* }).extend(tempoActions())
|
|
148
|
-
*
|
|
149
|
-
* const result = await client.amm.rebalanceSwapSync({
|
|
150
|
-
* userToken: '0x...',
|
|
151
|
-
* validatorToken: '0x...',
|
|
152
|
-
* amountOut: 100n,
|
|
153
|
-
* to: '0x...',
|
|
154
|
-
* })
|
|
155
|
-
* ```
|
|
156
|
-
*
|
|
157
|
-
* @param parameters - Parameters.
|
|
158
|
-
* @returns The transaction receipt and event data.
|
|
159
|
-
*/
|
|
160
|
-
rebalanceSwapSync: (
|
|
161
|
-
parameters: ammActions.rebalanceSwapSync.Parameters<chain, account>,
|
|
162
|
-
) => Promise<ammActions.rebalanceSwapSync.ReturnValue>
|
|
163
103
|
/**
|
|
164
104
|
* Adds liquidity to a pool.
|
|
165
105
|
*
|
|
@@ -230,118 +170,6 @@ export type Decorator<
|
|
|
230
170
|
mintSync: (
|
|
231
171
|
parameters: ammActions.mintSync.Parameters<chain, account>,
|
|
232
172
|
) => Promise<ammActions.mintSync.ReturnValue>
|
|
233
|
-
/**
|
|
234
|
-
* Removes liquidity from a pool.
|
|
235
|
-
*
|
|
236
|
-
* @example
|
|
237
|
-
* ```ts
|
|
238
|
-
* import { createClient, http } from 'viem'
|
|
239
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
240
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
241
|
-
* import { tempoActions } from 'tempo.ts/viem'
|
|
242
|
-
*
|
|
243
|
-
* const client = createClient({
|
|
244
|
-
* account: privateKeyToAccount('0x...'),
|
|
245
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
246
|
-
* transport: http(),
|
|
247
|
-
* }).extend(tempoActions())
|
|
248
|
-
*
|
|
249
|
-
* const hash = await client.amm.burn({
|
|
250
|
-
* userToken: '0x...',
|
|
251
|
-
* validatorToken: '0x...',
|
|
252
|
-
* liquidity: 50n,
|
|
253
|
-
* to: '0x...',
|
|
254
|
-
* })
|
|
255
|
-
* ```
|
|
256
|
-
*
|
|
257
|
-
* @param parameters - Parameters.
|
|
258
|
-
* @returns The transaction hash.
|
|
259
|
-
*/
|
|
260
|
-
burn: (
|
|
261
|
-
parameters: ammActions.burn.Parameters<chain, account>,
|
|
262
|
-
) => Promise<ammActions.burn.ReturnValue>
|
|
263
|
-
/**
|
|
264
|
-
* Removes liquidity from a pool.
|
|
265
|
-
*
|
|
266
|
-
* @example
|
|
267
|
-
* ```ts
|
|
268
|
-
* import { createClient, http } from 'viem'
|
|
269
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
270
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
271
|
-
* import { tempoActions } from 'tempo.ts/viem'
|
|
272
|
-
*
|
|
273
|
-
* const client = createClient({
|
|
274
|
-
* account: privateKeyToAccount('0x...'),
|
|
275
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
276
|
-
* transport: http(),
|
|
277
|
-
* }).extend(tempoActions())
|
|
278
|
-
*
|
|
279
|
-
* const result = await client.amm.burnSync({
|
|
280
|
-
* userToken: '0x...',
|
|
281
|
-
* validatorToken: '0x...',
|
|
282
|
-
* liquidity: 50n,
|
|
283
|
-
* to: '0x...',
|
|
284
|
-
* })
|
|
285
|
-
* ```
|
|
286
|
-
*
|
|
287
|
-
* @param parameters - Parameters.
|
|
288
|
-
* @returns The transaction receipt and event data.
|
|
289
|
-
*/
|
|
290
|
-
burnSync: (
|
|
291
|
-
parameters: ammActions.burnSync.Parameters<chain, account>,
|
|
292
|
-
) => Promise<ammActions.burnSync.ReturnValue>
|
|
293
|
-
/**
|
|
294
|
-
* Watches for rebalance swap events.
|
|
295
|
-
*
|
|
296
|
-
* @example
|
|
297
|
-
* ```ts
|
|
298
|
-
* import { createClient, http } from 'viem'
|
|
299
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
300
|
-
* import { tempoActions } from 'tempo.ts/viem'
|
|
301
|
-
*
|
|
302
|
-
* const client = createClient({
|
|
303
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
304
|
-
* transport: http(),
|
|
305
|
-
* }).extend(tempoActions())
|
|
306
|
-
*
|
|
307
|
-
* const unwatch = client.amm.watchRebalanceSwap({
|
|
308
|
-
* onRebalanceSwap: (args, log) => {
|
|
309
|
-
* console.log('Rebalance swap:', args)
|
|
310
|
-
* },
|
|
311
|
-
* })
|
|
312
|
-
* ```
|
|
313
|
-
*
|
|
314
|
-
* @param parameters - Parameters.
|
|
315
|
-
* @returns A function to unsubscribe from the event.
|
|
316
|
-
*/
|
|
317
|
-
watchRebalanceSwap: (
|
|
318
|
-
parameters: ammActions.watchRebalanceSwap.Parameters,
|
|
319
|
-
) => () => void
|
|
320
|
-
/**
|
|
321
|
-
* Watches for fee swap events.
|
|
322
|
-
*
|
|
323
|
-
* @example
|
|
324
|
-
* ```ts
|
|
325
|
-
* import { createClient, http } from 'viem'
|
|
326
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
327
|
-
* import { tempoActions } from 'tempo.ts/viem'
|
|
328
|
-
*
|
|
329
|
-
* const client = createClient({
|
|
330
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
331
|
-
* transport: http(),
|
|
332
|
-
* }).extend(tempoActions())
|
|
333
|
-
*
|
|
334
|
-
* const unwatch = client.amm.watchFeeSwap({
|
|
335
|
-
* onFeeSwap: (args, log) => {
|
|
336
|
-
* console.log('Fee swap:', args)
|
|
337
|
-
* },
|
|
338
|
-
* })
|
|
339
|
-
* ```
|
|
340
|
-
*
|
|
341
|
-
* @param parameters - Parameters.
|
|
342
|
-
* @returns A function to unsubscribe from the event.
|
|
343
|
-
*/
|
|
344
|
-
watchFeeSwap: (parameters: ammActions.watchFeeSwap.Parameters) => () => void
|
|
345
173
|
/**
|
|
346
174
|
* Watches for liquidity mint events.
|
|
347
175
|
*
|
|
@@ -367,31 +195,6 @@ export type Decorator<
|
|
|
367
195
|
* @returns A function to unsubscribe from the event.
|
|
368
196
|
*/
|
|
369
197
|
watchMint: (parameters: ammActions.watchMint.Parameters) => () => void
|
|
370
|
-
/**
|
|
371
|
-
* Watches for liquidity burn events.
|
|
372
|
-
*
|
|
373
|
-
* @example
|
|
374
|
-
* ```ts
|
|
375
|
-
* import { createClient, http } from 'viem'
|
|
376
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
377
|
-
* import { tempoActions } from 'tempo.ts/viem'
|
|
378
|
-
*
|
|
379
|
-
* const client = createClient({
|
|
380
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
381
|
-
* transport: http(),
|
|
382
|
-
* }).extend(tempoActions())
|
|
383
|
-
*
|
|
384
|
-
* const unwatch = client.amm.watchBurn({
|
|
385
|
-
* onBurn: (args, log) => {
|
|
386
|
-
* console.log('Liquidity removed:', args)
|
|
387
|
-
* },
|
|
388
|
-
* })
|
|
389
|
-
* ```
|
|
390
|
-
*
|
|
391
|
-
* @param parameters - Parameters.
|
|
392
|
-
* @returns A function to unsubscribe from the event.
|
|
393
|
-
*/
|
|
394
|
-
watchBurn: (parameters: ammActions.watchBurn.Parameters) => () => void
|
|
395
198
|
}
|
|
396
199
|
dex: {
|
|
397
200
|
/**
|
|
@@ -1601,88 +1404,6 @@ export type Decorator<
|
|
|
1601
1404
|
) => () => void
|
|
1602
1405
|
}
|
|
1603
1406
|
reward: {
|
|
1604
|
-
/**
|
|
1605
|
-
* Cancels an active reward stream and refunds remaining tokens.
|
|
1606
|
-
*
|
|
1607
|
-
* @example
|
|
1608
|
-
* ```ts
|
|
1609
|
-
* import { createClient, http } from 'viem'
|
|
1610
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1611
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1612
|
-
* import { tempoActions } from 'tempo.ts/viem'
|
|
1613
|
-
*
|
|
1614
|
-
* const client = createClient({
|
|
1615
|
-
* account: privateKeyToAccount('0x...'),
|
|
1616
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1617
|
-
* transport: http(),
|
|
1618
|
-
* }).extend(tempoActions())
|
|
1619
|
-
*
|
|
1620
|
-
* const hash = await client.reward.cancel({
|
|
1621
|
-
* id: 1n,
|
|
1622
|
-
* token: '0x20c0000000000000000000000000000000000001',
|
|
1623
|
-
* })
|
|
1624
|
-
* ```
|
|
1625
|
-
*
|
|
1626
|
-
* @param parameters - Parameters.
|
|
1627
|
-
* @returns The transaction hash.
|
|
1628
|
-
*/
|
|
1629
|
-
cancel: (
|
|
1630
|
-
parameters: rewardActions.cancel.Parameters<chain, account>,
|
|
1631
|
-
) => Promise<rewardActions.cancel.ReturnValue>
|
|
1632
|
-
/**
|
|
1633
|
-
* Cancels an active reward stream and waits for confirmation.
|
|
1634
|
-
*
|
|
1635
|
-
* @example
|
|
1636
|
-
* ```ts
|
|
1637
|
-
* import { createClient, http } from 'viem'
|
|
1638
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1639
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1640
|
-
* import { tempoActions } from 'tempo.ts/viem'
|
|
1641
|
-
*
|
|
1642
|
-
* const client = createClient({
|
|
1643
|
-
* account: privateKeyToAccount('0x...'),
|
|
1644
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1645
|
-
* transport: http(),
|
|
1646
|
-
* }).extend(tempoActions())
|
|
1647
|
-
*
|
|
1648
|
-
* const result = await client.reward.cancelSync({
|
|
1649
|
-
* id: 1n,
|
|
1650
|
-
* token: '0x20c0000000000000000000000000000000000001',
|
|
1651
|
-
* })
|
|
1652
|
-
* ```
|
|
1653
|
-
*
|
|
1654
|
-
* @param parameters - Parameters.
|
|
1655
|
-
* @returns The transaction receipt and event data.
|
|
1656
|
-
*/
|
|
1657
|
-
cancelSync: (
|
|
1658
|
-
parameters: rewardActions.cancelSync.Parameters<chain, account>,
|
|
1659
|
-
) => Promise<rewardActions.cancelSync.ReturnValue>
|
|
1660
|
-
/**
|
|
1661
|
-
* Gets a reward stream by its ID.
|
|
1662
|
-
*
|
|
1663
|
-
* @example
|
|
1664
|
-
* ```ts
|
|
1665
|
-
* import { createClient, http } from 'viem'
|
|
1666
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1667
|
-
* import { tempoActions } from 'tempo.ts/viem'
|
|
1668
|
-
*
|
|
1669
|
-
* const client = createClient({
|
|
1670
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1671
|
-
* transport: http(),
|
|
1672
|
-
* }).extend(tempoActions())
|
|
1673
|
-
*
|
|
1674
|
-
* const stream = await client.reward.getStream({
|
|
1675
|
-
* id: 1n,
|
|
1676
|
-
* token: '0x20c0000000000000000000000000000000000001',
|
|
1677
|
-
* })
|
|
1678
|
-
* ```
|
|
1679
|
-
*
|
|
1680
|
-
* @param parameters - Parameters.
|
|
1681
|
-
* @returns The reward stream details.
|
|
1682
|
-
*/
|
|
1683
|
-
getStream: (
|
|
1684
|
-
parameters: rewardActions.getStream.Parameters,
|
|
1685
|
-
) => Promise<rewardActions.getStream.ReturnValue>
|
|
1686
1407
|
/**
|
|
1687
1408
|
* Gets the total reward per second rate for all active streams.
|
|
1688
1409
|
*
|
|
@@ -2985,20 +2706,9 @@ export function decorator() {
|
|
|
2985
2706
|
getPool: (parameters) => ammActions.getPool(client, parameters),
|
|
2986
2707
|
getLiquidityBalance: (parameters) =>
|
|
2987
2708
|
ammActions.getLiquidityBalance(client, parameters),
|
|
2988
|
-
rebalanceSwap: (parameters) =>
|
|
2989
|
-
ammActions.rebalanceSwap(client, parameters),
|
|
2990
|
-
rebalanceSwapSync: (parameters) =>
|
|
2991
|
-
ammActions.rebalanceSwapSync(client, parameters),
|
|
2992
2709
|
mint: (parameters) => ammActions.mint(client, parameters),
|
|
2993
2710
|
mintSync: (parameters) => ammActions.mintSync(client, parameters),
|
|
2994
|
-
burn: (parameters) => ammActions.burn(client, parameters),
|
|
2995
|
-
burnSync: (parameters) => ammActions.burnSync(client, parameters),
|
|
2996
|
-
watchRebalanceSwap: (parameters) =>
|
|
2997
|
-
ammActions.watchRebalanceSwap(client, parameters),
|
|
2998
|
-
watchFeeSwap: (parameters) =>
|
|
2999
|
-
ammActions.watchFeeSwap(client, parameters),
|
|
3000
2711
|
watchMint: (parameters) => ammActions.watchMint(client, parameters),
|
|
3001
|
-
watchBurn: (parameters) => ammActions.watchBurn(client, parameters),
|
|
3002
2712
|
},
|
|
3003
2713
|
dex: {
|
|
3004
2714
|
buy: (parameters) => dexActions.buy(client, parameters),
|
|
@@ -3078,10 +2788,6 @@ export function decorator() {
|
|
|
3078
2788
|
policyActions.watchBlacklistUpdated(client, parameters),
|
|
3079
2789
|
},
|
|
3080
2790
|
reward: {
|
|
3081
|
-
cancel: (parameters) => rewardActions.cancel(client, parameters),
|
|
3082
|
-
cancelSync: (parameters) =>
|
|
3083
|
-
rewardActions.cancelSync(client, parameters),
|
|
3084
|
-
getStream: (parameters) => rewardActions.getStream(client, parameters),
|
|
3085
2791
|
getTotalPerSecond: (parameters) =>
|
|
3086
2792
|
rewardActions.getTotalPerSecond(client, parameters),
|
|
3087
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
|
+
}
|
package/src/viem/Transport.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
|