viem 2.47.18 → 2.48.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 +12 -0
- package/_cjs/chains/definitions/tempo.js +2 -2
- package/_cjs/chains/definitions/tempo.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/errors/version.js.map +1 -1
- package/_cjs/tempo/Addresses.js +2 -1
- package/_cjs/tempo/Addresses.js.map +1 -1
- package/_cjs/tempo/Decorator.js +16 -0
- package/_cjs/tempo/Decorator.js.map +1 -1
- package/_cjs/tempo/Storage.js +77 -0
- package/_cjs/tempo/Storage.js.map +1 -0
- package/_cjs/tempo/actions/index.js +2 -1
- package/_cjs/tempo/actions/index.js.map +1 -1
- package/_cjs/tempo/actions/zone.js +432 -0
- package/_cjs/tempo/actions/zone.js.map +1 -0
- package/_cjs/tempo/index.js +2 -1
- package/_cjs/tempo/index.js.map +1 -1
- package/_cjs/tempo/zones/Abis.js +82 -0
- package/_cjs/tempo/zones/Abis.js.map +1 -0
- package/_cjs/tempo/zones/index.js +13 -0
- package/_cjs/tempo/zones/index.js.map +1 -0
- package/_cjs/tempo/zones/transport.js +24 -0
- package/_cjs/tempo/zones/transport.js.map +1 -0
- package/_cjs/tempo/zones/zone.js +53 -0
- package/_cjs/tempo/zones/zone.js.map +1 -0
- package/_esm/chains/definitions/tempo.js +2 -2
- package/_esm/chains/definitions/tempo.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/errors/version.js.map +1 -1
- package/_esm/tempo/Addresses.js +1 -0
- package/_esm/tempo/Addresses.js.map +1 -1
- package/_esm/tempo/Decorator.js +16 -0
- package/_esm/tempo/Decorator.js.map +1 -1
- package/_esm/tempo/Storage.js +96 -0
- package/_esm/tempo/Storage.js.map +1 -0
- package/_esm/tempo/actions/index.js +1 -0
- package/_esm/tempo/actions/index.js.map +1 -1
- package/_esm/tempo/actions/zone.js +786 -0
- package/_esm/tempo/actions/zone.js.map +1 -0
- package/_esm/tempo/index.js +1 -0
- package/_esm/tempo/index.js.map +1 -1
- package/_esm/tempo/zones/Abis.js +79 -0
- package/_esm/tempo/zones/Abis.js.map +1 -0
- package/_esm/tempo/zones/index.js +5 -0
- package/_esm/tempo/zones/index.js.map +1 -0
- package/_esm/tempo/zones/transport.js +39 -0
- package/_esm/tempo/zones/transport.js.map +1 -0
- package/_esm/tempo/zones/zone.js +49 -0
- package/_esm/tempo/zones/zone.js.map +1 -0
- package/_types/chains/definitions/tempo.d.ts +4 -4
- package/_types/errors/version.d.ts +1 -1
- package/_types/errors/version.d.ts.map +1 -1
- package/_types/tempo/Addresses.d.ts +1 -0
- package/_types/tempo/Addresses.d.ts.map +1 -1
- package/_types/tempo/Decorator.d.ts +283 -0
- package/_types/tempo/Decorator.d.ts.map +1 -1
- package/_types/tempo/Storage.d.ts +42 -0
- package/_types/tempo/Storage.d.ts.map +1 -0
- package/_types/tempo/actions/index.d.ts +1 -0
- package/_types/tempo/actions/index.d.ts.map +1 -1
- package/_types/tempo/actions/zone.d.ts +874 -0
- package/_types/tempo/actions/zone.d.ts.map +1 -0
- package/_types/tempo/index.d.ts +1 -0
- package/_types/tempo/index.d.ts.map +1 -1
- package/_types/tempo/zones/Abis.d.ts +124 -0
- package/_types/tempo/zones/Abis.d.ts.map +1 -0
- package/_types/tempo/zones/index.d.ts +4 -0
- package/_types/tempo/zones/index.d.ts.map +1 -0
- package/_types/tempo/zones/transport.d.ts +26 -0
- package/_types/tempo/zones/transport.d.ts.map +1 -0
- package/_types/tempo/zones/zone.d.ts +2775 -0
- package/_types/tempo/zones/zone.d.ts.map +1 -0
- package/chains/definitions/tempo.ts +2 -2
- package/errors/version.ts +1 -1
- package/package.json +7 -2
- package/tempo/Addresses.ts +1 -0
- package/tempo/Decorator.ts +337 -0
- package/tempo/Storage.ts +118 -0
- package/tempo/actions/index.ts +1 -0
- package/tempo/actions/zone.ts +1317 -0
- package/tempo/index.ts +1 -0
- package/tempo/zones/Abis.ts +79 -0
- package/tempo/zones/index.ts +10 -0
- package/tempo/zones/package.json +6 -0
- package/tempo/zones/transport.ts +58 -0
- package/tempo/zones/zone.ts +70 -0
package/tempo/index.ts
CHANGED
|
@@ -25,6 +25,7 @@ export * as Formatters from './Formatters.js'
|
|
|
25
25
|
export * as Hardfork from './Hardfork.js'
|
|
26
26
|
export * as P256 from './P256.js'
|
|
27
27
|
export * as Secp256k1 from './Secp256k1.js'
|
|
28
|
+
export * as Storage from './Storage.js'
|
|
28
29
|
export * as TokenIds from './TokenIds.js'
|
|
29
30
|
// Export types required for inference.
|
|
30
31
|
export type {
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export const zonePortal = [
|
|
2
|
+
{
|
|
3
|
+
name: 'deposit',
|
|
4
|
+
type: 'function',
|
|
5
|
+
stateMutability: 'nonpayable',
|
|
6
|
+
inputs: [
|
|
7
|
+
{ name: '_token', type: 'address' },
|
|
8
|
+
{ name: 'to', type: 'address' },
|
|
9
|
+
{ name: 'amount', type: 'uint128' },
|
|
10
|
+
{ name: 'memo', type: 'bytes32' },
|
|
11
|
+
],
|
|
12
|
+
outputs: [{ name: '', type: 'bytes32' }],
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: 'depositEncrypted',
|
|
16
|
+
type: 'function',
|
|
17
|
+
stateMutability: 'nonpayable',
|
|
18
|
+
inputs: [
|
|
19
|
+
{ name: 'token', type: 'address' },
|
|
20
|
+
{ name: 'amount', type: 'uint128' },
|
|
21
|
+
{ name: 'keyIndex', type: 'uint256' },
|
|
22
|
+
{
|
|
23
|
+
name: 'encrypted',
|
|
24
|
+
type: 'tuple',
|
|
25
|
+
components: [
|
|
26
|
+
{ name: 'ephemeralPubkeyX', type: 'bytes32' },
|
|
27
|
+
{ name: 'ephemeralPubkeyYParity', type: 'uint8' },
|
|
28
|
+
{ name: 'ciphertext', type: 'bytes' },
|
|
29
|
+
{ name: 'nonce', type: 'bytes12' },
|
|
30
|
+
{ name: 'tag', type: 'bytes16' },
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
outputs: [{ name: '', type: 'bytes32' }],
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'sequencerEncryptionKey',
|
|
38
|
+
type: 'function',
|
|
39
|
+
stateMutability: 'view',
|
|
40
|
+
inputs: [],
|
|
41
|
+
outputs: [
|
|
42
|
+
{ name: 'x', type: 'bytes32' },
|
|
43
|
+
{ name: 'yParity', type: 'uint8' },
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'encryptionKeyCount',
|
|
48
|
+
type: 'function',
|
|
49
|
+
stateMutability: 'view',
|
|
50
|
+
inputs: [],
|
|
51
|
+
outputs: [{ name: '', type: 'uint256' }],
|
|
52
|
+
},
|
|
53
|
+
] as const
|
|
54
|
+
|
|
55
|
+
export const zoneOutbox = [
|
|
56
|
+
{
|
|
57
|
+
name: 'requestWithdrawal',
|
|
58
|
+
type: 'function',
|
|
59
|
+
stateMutability: 'nonpayable',
|
|
60
|
+
inputs: [
|
|
61
|
+
{ name: 'token', type: 'address' },
|
|
62
|
+
{ name: 'to', type: 'address' },
|
|
63
|
+
{ name: 'amount', type: 'uint128' },
|
|
64
|
+
{ name: 'memo', type: 'bytes32' },
|
|
65
|
+
{ name: 'gasLimit', type: 'uint64' },
|
|
66
|
+
{ name: 'fallbackRecipient', type: 'address' },
|
|
67
|
+
{ name: 'data', type: 'bytes' },
|
|
68
|
+
{ name: 'revealTo', type: 'bytes' },
|
|
69
|
+
],
|
|
70
|
+
outputs: [],
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: 'calculateWithdrawalFee',
|
|
74
|
+
type: 'function',
|
|
75
|
+
stateMutability: 'view',
|
|
76
|
+
inputs: [{ name: 'gasLimit', type: 'uint64' }],
|
|
77
|
+
outputs: [{ name: 'fee', type: 'uint128' }],
|
|
78
|
+
},
|
|
79
|
+
] as const
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// biome-ignore lint/performance/noBarrelFile: entrypoint module
|
|
2
|
+
export * as Abis from './Abis.js'
|
|
3
|
+
export { http, type ZoneHttpConfig } from './transport.js'
|
|
4
|
+
export {
|
|
5
|
+
from,
|
|
6
|
+
getPortalAddress,
|
|
7
|
+
portalAddresses,
|
|
8
|
+
zone,
|
|
9
|
+
zoneModerato,
|
|
10
|
+
} from './zone.js'
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type HttpTransport,
|
|
3
|
+
type HttpTransportConfig,
|
|
4
|
+
http as http_,
|
|
5
|
+
} from '../../clients/transports/http.js'
|
|
6
|
+
import type { Storage } from '../Storage.js'
|
|
7
|
+
import * as Storage_ from '../Storage.js'
|
|
8
|
+
|
|
9
|
+
export type ZoneHttpConfig = Omit<
|
|
10
|
+
HttpTransportConfig,
|
|
11
|
+
'batch' | 'raw' | 'rpcSchema'
|
|
12
|
+
> & {
|
|
13
|
+
/** Storage for reading zone authorization tokens. Defaults to sessionStorage (web) or memory (server). */
|
|
14
|
+
storage?: Storage | undefined
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Creates an HTTP transport with support for Zone authentication tokens.
|
|
19
|
+
*
|
|
20
|
+
* Reads the authorization token from Storage and injects the
|
|
21
|
+
* `X-Authorization-Token` header on every request. Batching is disabled
|
|
22
|
+
* by default because zone tokens are account-scoped.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { createPublicClient } from 'viem'
|
|
27
|
+
* import { http, zone } from 'viem/tempo/zones' // or zoneModerato
|
|
28
|
+
*
|
|
29
|
+
* const client = createPublicClient({
|
|
30
|
+
* chain: zone(6),
|
|
31
|
+
* transport: http(),
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function http(
|
|
36
|
+
url?: string | undefined,
|
|
37
|
+
config: ZoneHttpConfig = {},
|
|
38
|
+
): HttpTransport {
|
|
39
|
+
const { storage: storage_, onFetchRequest, ...rest } = config
|
|
40
|
+
const storage = storage_ ?? Storage_.defaultStorage()
|
|
41
|
+
|
|
42
|
+
return (config) =>
|
|
43
|
+
http_(url, {
|
|
44
|
+
...rest,
|
|
45
|
+
async onFetchRequest(request, init) {
|
|
46
|
+
const next = (await onFetchRequest?.(request, init)) ?? init
|
|
47
|
+
const headers = new Headers(next.headers)
|
|
48
|
+
|
|
49
|
+
const chainId = config.chain?.id
|
|
50
|
+
if (chainId) {
|
|
51
|
+
const token = (await storage.getItem(`auth:token:${chainId}`)) ?? null
|
|
52
|
+
if (token) headers.set('X-Authorization-Token', token)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return { ...next, headers }
|
|
56
|
+
},
|
|
57
|
+
})(config)
|
|
58
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ZoneId } from 'ox/tempo'
|
|
2
|
+
import { tempo } from '../../chains/definitions/tempo.js'
|
|
3
|
+
import { tempoModerato } from '../../chains/definitions/tempoModerato.js'
|
|
4
|
+
import { defineChain } from '../../utils/chain/defineChain.js'
|
|
5
|
+
import { chainConfig } from '../chainConfig.js'
|
|
6
|
+
|
|
7
|
+
export const portalAddresses = {
|
|
8
|
+
[tempoModerato.id]: {
|
|
9
|
+
6: '0x7069DeC4E64Fd07334A0933eDe836C17259c9B23',
|
|
10
|
+
7: '0x3F5296303400B56271b476F5A0B9cBF74350D6Ac',
|
|
11
|
+
},
|
|
12
|
+
} as const satisfies Record<number, Record<number, `0x${string}`>>
|
|
13
|
+
|
|
14
|
+
export function getPortalAddress(
|
|
15
|
+
chainId: number,
|
|
16
|
+
zoneId: number,
|
|
17
|
+
): `0x${string}` {
|
|
18
|
+
const address = (
|
|
19
|
+
portalAddresses as Record<number, Record<number, `0x${string}`>>
|
|
20
|
+
)[chainId]?.[zoneId]
|
|
21
|
+
if (!address)
|
|
22
|
+
throw new Error(
|
|
23
|
+
`No portal address configured for zone ${zoneId} on chain ${chainId}.`,
|
|
24
|
+
)
|
|
25
|
+
return address
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const zone = /*#__PURE__*/ from({
|
|
29
|
+
sourceId: tempo.id,
|
|
30
|
+
rpcHost: 'tempo.xyz',
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
export const zoneModerato = /*#__PURE__*/ from({
|
|
34
|
+
sourceId: tempoModerato.id,
|
|
35
|
+
rpcHost: 'tempoxyz.dev',
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
/** Creates a zone chain factory for a given Tempo network. */
|
|
39
|
+
export function from(options: from.Options) {
|
|
40
|
+
return (id: number) => {
|
|
41
|
+
const chainId = ZoneId.toChainId(id)
|
|
42
|
+
const paddedId = String(id).padStart(3, '0')
|
|
43
|
+
|
|
44
|
+
return defineChain({
|
|
45
|
+
...chainConfig,
|
|
46
|
+
id: chainId,
|
|
47
|
+
name: `Tempo Zone ${paddedId}`,
|
|
48
|
+
nativeCurrency: {
|
|
49
|
+
name: 'USD',
|
|
50
|
+
symbol: 'USD',
|
|
51
|
+
decimals: 6,
|
|
52
|
+
},
|
|
53
|
+
rpcUrls: {
|
|
54
|
+
default: {
|
|
55
|
+
http: [`https://rpc-zone-${paddedId}.${options.rpcHost}`],
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
sourceId: options.sourceId,
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
declare namespace from {
|
|
64
|
+
type Options = {
|
|
65
|
+
/** RPC hostname used to construct zone RPC URLs (e.g. `tempo.xyz`). */
|
|
66
|
+
rpcHost: string
|
|
67
|
+
/** Chain ID of the parent Tempo chain (e.g. `4217` for mainnet, `42431` for moderato). */
|
|
68
|
+
sourceId: number
|
|
69
|
+
}
|
|
70
|
+
}
|