tempo.ts 0.4.3 → 0.5.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 (55) hide show
  1. package/README.md +2 -3
  2. package/dist/chains.d.ts +15 -1
  3. package/dist/chains.d.ts.map +1 -1
  4. package/dist/chains.js +2 -1
  5. package/dist/chains.js.map +1 -1
  6. package/dist/prool/Instance.d.ts +12 -4
  7. package/dist/prool/Instance.d.ts.map +1 -1
  8. package/dist/prool/Instance.js +34 -18
  9. package/dist/prool/Instance.js.map +1 -1
  10. package/dist/viem/Actions/faucet.d.ts +34 -1
  11. package/dist/viem/Actions/faucet.d.ts.map +1 -1
  12. package/dist/viem/Actions/faucet.js +35 -0
  13. package/dist/viem/Actions/faucet.js.map +1 -1
  14. package/dist/viem/Actions/token.d.ts +12 -12
  15. package/dist/viem/Actions/token.js +12 -12
  16. package/dist/viem/Chain.d.ts +6 -0
  17. package/dist/viem/Chain.d.ts.map +1 -1
  18. package/dist/viem/Decorator.d.ts +9 -9
  19. package/dist/viem/Transaction.d.ts +4 -1
  20. package/dist/viem/Transaction.d.ts.map +1 -1
  21. package/dist/viem/Transaction.js.map +1 -1
  22. package/dist/wagmi/Actions/token.d.ts +1 -1
  23. package/dist/wagmi/Actions/token.js +1 -1
  24. package/dist/wagmi/Connector.d.ts +4 -3
  25. package/dist/wagmi/Connector.d.ts.map +1 -1
  26. package/dist/wagmi/Connector.js +91 -5
  27. package/dist/wagmi/Connector.js.map +1 -1
  28. package/dist/wagmi/Hooks/token.d.ts +1 -1
  29. package/dist/wagmi/Hooks/token.js +1 -1
  30. package/package.json +1 -1
  31. package/src/chains.ts +2 -1
  32. package/src/ox/TransactionEnvelopeAA.test.ts +2 -663
  33. package/src/ox/e2e.test.ts +659 -0
  34. package/src/prool/Instance.ts +51 -23
  35. package/src/tsconfig.json +2 -2
  36. package/src/viem/Actions/amm.test.ts +68 -58
  37. package/src/viem/Actions/dex.test.ts +339 -283
  38. package/src/viem/Actions/faucet.ts +63 -1
  39. package/src/viem/Actions/fee.test.ts +34 -43
  40. package/src/viem/Actions/policy.test.ts +115 -81
  41. package/src/viem/Actions/reward.test.ts +92 -74
  42. package/src/viem/Actions/token.test.ts +691 -529
  43. package/src/viem/Actions/token.ts +12 -12
  44. package/src/viem/Decorator.ts +9 -9
  45. package/src/viem/Transaction.ts +4 -1
  46. package/src/viem/e2e.test.ts +451 -472
  47. package/src/wagmi/Actions/amm.test.ts +2 -5
  48. package/src/wagmi/Actions/dex.test.ts +2 -1
  49. package/src/wagmi/Actions/token.test.ts +2 -1
  50. package/src/wagmi/Actions/token.ts +1 -1
  51. package/src/wagmi/Connector.ts +125 -10
  52. package/src/wagmi/Hooks/amm.test.ts +2 -5
  53. package/src/wagmi/Hooks/dex.test.ts +2 -1
  54. package/src/wagmi/Hooks/token.test.ts +2 -1
  55. package/src/wagmi/Hooks/token.ts +1 -1
@@ -1,11 +1,8 @@
1
1
  import { connect, getConnectorClient } from '@wagmi/core'
2
2
  import { parseUnits } from 'viem'
3
3
  import { describe, expect, test } from 'vitest'
4
- import {
5
- accounts,
6
- addresses,
7
- setupPoolWithLiquidity,
8
- } from '../../../test/viem/config.js'
4
+ import { addresses } from '../../../test/config.js'
5
+ import { accounts, setupPoolWithLiquidity } from '../../../test/viem/config.js'
9
6
  import { config, queryClient } from '../../../test/wagmi/config.js'
10
7
  import * as ammActions from './amm.js'
11
8
  import * as tokenActions from './token.js'
@@ -3,7 +3,8 @@ import { Tick } from 'tempo.ts/viem'
3
3
  import { Actions } from 'tempo.ts/wagmi'
4
4
  import { isAddress, parseUnits } from 'viem'
5
5
  import { beforeAll, describe, expect, test } from 'vitest'
6
- import { accounts, addresses } from '../../../test/viem/config.js'
6
+ import { addresses } from '../../../test/config.js'
7
+ import { accounts } from '../../../test/viem/config.js'
7
8
  import {
8
9
  config,
9
10
  queryClient,
@@ -1,7 +1,8 @@
1
1
  import { connect } from '@wagmi/core'
2
2
  import { parseUnits } from 'viem'
3
3
  import { describe, expect, test } from 'vitest'
4
- import { accounts, addresses } from '../../../test/viem/config.js'
4
+ import { addresses } from '../../../test/config.js'
5
+ import { accounts } from '../../../test/viem/config.js'
5
6
  import { config, queryClient } from '../../../test/wagmi/config.js'
6
7
  import * as token from './token.js'
7
8
 
@@ -988,7 +988,7 @@ export namespace getMetadata {
988
988
  * })
989
989
  *
990
990
  * const adminRole = await Actions.token.getRoleAdmin(config, {
991
- * role: 'minter',
991
+ * role: 'issuer',
992
992
  * token: '0x...',
993
993
  * })
994
994
  * ```
@@ -1,16 +1,32 @@
1
1
  import * as Address from 'ox/Address'
2
2
  import * as Bytes from 'ox/Bytes'
3
- import { Account, WebAuthnP256 } from 'tempo.ts/viem'
3
+ import * as Hash from 'ox/Hash'
4
+ import * as Hex from 'ox/Hex'
5
+ import * as Provider from 'ox/Provider'
6
+ import * as RpcRequest from 'ox/RpcRequest'
4
7
  import {
5
8
  createClient,
6
9
  type EIP1193Provider,
7
10
  getAddress,
8
- type Hex,
9
11
  type LocalAccount,
10
12
  SwitchChainError,
13
+ type Transport,
14
+ type Account as viem_Account,
11
15
  } from 'viem'
12
16
  import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'
17
+ import {
18
+ getTransactionReceipt,
19
+ sendTransaction,
20
+ sendTransactionSync,
21
+ } from 'viem/actions'
13
22
  import { ChainNotConfiguredError, createConnector } from 'wagmi'
23
+ import * as Account from '../viem/Account.js'
24
+ import type * as tempo_Chain from '../viem/Chain.js'
25
+ import * as WebAuthnP256 from '../viem/WebAuthnP256.js'
26
+
27
+ type Chain = ReturnType<ReturnType<typeof tempo_Chain.define>>
28
+
29
+ const sendCallsMagic = Hash.keccak256(Hex.fromString('TEMPO_5792'))
14
30
 
15
31
  /**
16
32
  * Connector for a Secp256k1 EOA.
@@ -45,7 +61,7 @@ export function dangerous_secp256k1(
45
61
  type StorageItem = {
46
62
  'secp256k1.activeAddress': Address.Address
47
63
  'secp256k1.lastActiveAddress': Address.Address
48
- [key: `secp256k1.${string}.privateKey`]: Hex
64
+ [key: `secp256k1.${string}.privateKey`]: Hex.Hex
49
65
  }
50
66
 
51
67
  return createConnector<Provider, Properties, StorageItem>((config) => ({
@@ -168,8 +184,10 @@ export function dangerous_secp256k1(
168
184
 
169
185
  return createClient({
170
186
  account,
171
- chain,
172
- transport,
187
+ chain: chain as Chain,
188
+ transport: withErc5792Compat(transport, {
189
+ account,
190
+ }),
173
191
  })
174
192
  },
175
193
  async getProvider({ chainId } = {}) {
@@ -214,7 +232,7 @@ export function webAuthn(options: webAuthn.Parameters = {}) {
214
232
  type StorageItem = {
215
233
  'webAuthn.activeCredential': WebAuthnP256.P256Credential
216
234
  'webAuthn.lastActiveCredential': WebAuthnP256.P256Credential
217
- [key: `webAuthn.${string}.publicKey`]: Hex
235
+ [key: `webAuthn.${string}.publicKey`]: Hex.Hex
218
236
  }
219
237
 
220
238
  return createConnector<Provider, Properties, StorageItem>((config) => ({
@@ -270,6 +288,8 @@ export function webAuthn(options: webAuthn.Parameters = {}) {
270
288
  credential ??= await WebAuthnP256.getCredential({
271
289
  ...(options.getOptions ?? {}),
272
290
  credentialId: lastActiveCredential?.id,
291
+ // biome-ignore lint/suspicious/noTsIgnore: _
292
+ // @ts-ignore
273
293
  async getPublicKey(credential) {
274
294
  {
275
295
  const publicKey =
@@ -282,7 +302,7 @@ export function webAuthn(options: webAuthn.Parameters = {}) {
282
302
  `webAuthn.${credential.id}.publicKey`,
283
303
  )
284
304
  if (!publicKey) throw new Error('publicKey not found')
285
- return publicKey as Hex
305
+ return publicKey as Hex.Hex
286
306
  }
287
307
  },
288
308
  rpId: options.getOptions?.rpId ?? options.rpId,
@@ -356,8 +376,10 @@ export function webAuthn(options: webAuthn.Parameters = {}) {
356
376
 
357
377
  return createClient({
358
378
  account,
359
- chain,
360
- transport,
379
+ chain: chain as Chain,
380
+ transport: withErc5792Compat(transport, {
381
+ account,
382
+ }),
361
383
  })
362
384
  },
363
385
  async getProvider({ chainId } = {}) {
@@ -376,7 +398,7 @@ export declare namespace webAuthn {
376
398
  'createFn' | 'label' | 'rpId' | 'userId' | 'timeout'
377
399
  > & {
378
400
  /** Function to fetch a challenge to sign over at registration. */
379
- getChallenge?: (() => Promise<Hex>) | undefined
401
+ getChallenge?: (() => Promise<Hex.Hex>) | undefined
380
402
  })
381
403
  | undefined
382
404
  /** Options for WebAuthn authentication. */
@@ -392,3 +414,96 @@ export declare namespace webAuthn {
392
414
  rpId?: string | undefined
393
415
  }
394
416
  }
417
+
418
+ // TODO: This is a temporary workaround to support EIP-5792. To be removed
419
+ // once we support a EIP-1193 Provider abstraction for Tempo accounts.
420
+ // biome-ignore lint/correctness/noUnusedVariables: _
421
+ function withErc5792Compat(
422
+ transport: Transport,
423
+ { account }: withErc5792Compat.Options,
424
+ ): Transport {
425
+ return (options) => {
426
+ const t = transport(options)
427
+
428
+ return {
429
+ ...t,
430
+ async request(args: never) {
431
+ const request = RpcRequest.from(args)
432
+
433
+ const client = createClient({
434
+ account,
435
+ chain: options.chain as Chain,
436
+ transport,
437
+ })
438
+
439
+ if (request.method === 'wallet_sendCalls') {
440
+ const params = request.params[0] ?? {}
441
+ const { capabilities, chainId, from } = params
442
+ const { sync } = capabilities ?? {}
443
+
444
+ if (!account) throw new Provider.DisconnectedError()
445
+ if (!chainId) throw new Provider.UnsupportedChainIdError()
446
+ if (Number(chainId) !== client.chain.id)
447
+ throw new Provider.UnsupportedChainIdError()
448
+ if (from && !Address.isEqual(from, account.address))
449
+ throw new Provider.DisconnectedError()
450
+
451
+ const calls = (params.calls ?? []).map((call) => ({
452
+ to: call.to,
453
+ value: call.value ? BigInt(call.value) : undefined,
454
+ data: call.data,
455
+ }))
456
+
457
+ const hash = await (async () => {
458
+ if (!sync)
459
+ return sendTransaction(client, {
460
+ account,
461
+ calls,
462
+ })
463
+
464
+ const { transactionHash } = await sendTransactionSync(client, {
465
+ account,
466
+ calls,
467
+ })
468
+ return transactionHash
469
+ })()
470
+
471
+ const id = Hex.concat(hash, Hex.padLeft(chainId, 32), sendCallsMagic)
472
+
473
+ return {
474
+ capabilities: { sync },
475
+ id,
476
+ }
477
+ }
478
+
479
+ if (request.method === 'wallet_getCallsStatus') {
480
+ const [id] = request.params ?? []
481
+ if (!id) throw new Error('`id` not found')
482
+ if (!id.endsWith(sendCallsMagic.slice(2)))
483
+ throw new Error('`id` not supported')
484
+ Hex.assert(id)
485
+
486
+ const hash = Hex.slice(id, 0, 32)
487
+ const chainId = Hex.slice(id, 32, 64)
488
+
489
+ const receipt = await getTransactionReceipt(client, { hash })
490
+ return {
491
+ atomic: true,
492
+ chainId: Number(chainId),
493
+ receipts: [receipt],
494
+ status: receipt.status === 'success' ? 200 : 500,
495
+ version: '2.0.0',
496
+ }
497
+ }
498
+
499
+ return t.request(args)
500
+ },
501
+ } as never
502
+ }
503
+ }
504
+
505
+ declare namespace withErc5792Compat {
506
+ type Options = {
507
+ account: viem_Account | undefined
508
+ }
509
+ }
@@ -2,11 +2,8 @@ import { getConnectorClient } from '@wagmi/core'
2
2
  import { type Address, parseUnits } from 'viem'
3
3
  import { describe, expect, test, vi } from 'vitest'
4
4
  import { useConnect } from 'wagmi'
5
- import {
6
- accounts,
7
- addresses,
8
- setupPoolWithLiquidity,
9
- } from '../../../test/viem/config.js'
5
+ import { addresses } from '../../../test/config.js'
6
+ import { accounts, setupPoolWithLiquidity } from '../../../test/viem/config.js'
10
7
  import { config, renderHook } from '../../../test/wagmi/config.js'
11
8
  import * as hooks from './amm.js'
12
9
  import * as tokenHooks from './token.js'
@@ -3,7 +3,8 @@ import { Actions, Hooks } from 'tempo.ts/wagmi'
3
3
  import { type Address, isAddress, parseUnits } from 'viem'
4
4
  import { describe, expect, test, vi } from 'vitest'
5
5
  import { useConnect } from 'wagmi'
6
- import { accounts, addresses } from '../../../test/viem/config.js'
6
+ import { addresses } from '../../../test/config.js'
7
+ import { accounts } from '../../../test/viem/config.js'
7
8
  import {
8
9
  config,
9
10
  renderHook,
@@ -1,7 +1,8 @@
1
1
  import { type Address, parseUnits } from 'viem'
2
2
  import { describe, expect, test, vi } from 'vitest'
3
3
  import { useConnect } from 'wagmi'
4
- import { accounts, addresses } from '../../../test/viem/config.js'
4
+ import { addresses } from '../../../test/config.js'
5
+ import { accounts } from '../../../test/viem/config.js'
5
6
  import { config, renderHook } from '../../../test/wagmi/config.js'
6
7
  import * as hooks from './token.js'
7
8
 
@@ -1030,7 +1030,7 @@ export declare namespace useGetMetadata {
1030
1030
  *
1031
1031
  * function App() {
1032
1032
  * const { data, isLoading } = Hooks.token.useGetRoleAdmin({
1033
- * role: 'minter',
1033
+ * role: 'issuer',
1034
1034
  * token: '0x...',
1035
1035
  * })
1036
1036
  *