viem 2.48.1 → 2.48.2
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 +16 -0
- package/_cjs/actions/wallet/prepareTransactionRequest.js +1 -1
- package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_cjs/chains/definitions/tron.js +1 -0
- package/_cjs/chains/definitions/tron.js.map +1 -1
- package/_cjs/chains/definitions/zircuit.js +1 -0
- package/_cjs/chains/definitions/zircuit.js.map +1 -1
- package/_cjs/chains/definitions/zircuitGarfieldTestnet.js +1 -0
- package/_cjs/chains/definitions/zircuitGarfieldTestnet.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/op-stack/abis.js +16 -1
- package/_cjs/op-stack/abis.js.map +1 -1
- package/_cjs/op-stack/actions/getGames.js +14 -5
- package/_cjs/op-stack/actions/getGames.js.map +1 -1
- package/_cjs/tempo/Account.js +19 -2
- package/_cjs/tempo/Account.js.map +1 -1
- package/_cjs/tempo/actions/accessKey.js +6 -6
- package/_cjs/tempo/actions/accessKey.js.map +1 -1
- package/_cjs/utils/buildRequest.js +15 -2
- package/_cjs/utils/buildRequest.js.map +1 -1
- package/_esm/actions/wallet/prepareTransactionRequest.js +1 -1
- package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_esm/chains/definitions/tron.js +1 -0
- package/_esm/chains/definitions/tron.js.map +1 -1
- package/_esm/chains/definitions/zircuit.js +1 -0
- package/_esm/chains/definitions/zircuit.js.map +1 -1
- package/_esm/chains/definitions/zircuitGarfieldTestnet.js +1 -0
- package/_esm/chains/definitions/zircuitGarfieldTestnet.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/op-stack/abis.js +15 -0
- package/_esm/op-stack/abis.js.map +1 -1
- package/_esm/op-stack/actions/getGames.js +15 -6
- package/_esm/op-stack/actions/getGames.js.map +1 -1
- package/_esm/tempo/Account.js +19 -2
- package/_esm/tempo/Account.js.map +1 -1
- package/_esm/tempo/actions/accessKey.js +6 -6
- package/_esm/tempo/actions/accessKey.js.map +1 -1
- package/_esm/utils/buildRequest.js +16 -2
- package/_esm/utils/buildRequest.js.map +1 -1
- package/_types/chains/definitions/tron.d.ts +1 -1
- package/_types/chains/definitions/tron.d.ts.map +1 -1
- package/_types/chains/definitions/zircuit.d.ts +18 -0
- package/_types/chains/definitions/zircuit.d.ts.map +1 -1
- package/_types/chains/definitions/zircuitGarfieldTestnet.d.ts +18 -0
- package/_types/chains/definitions/zircuitGarfieldTestnet.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/op-stack/abis.d.ts +11 -0
- package/_types/op-stack/abis.d.ts.map +1 -1
- package/_types/op-stack/actions/getGames.d.ts +2 -1
- package/_types/op-stack/actions/getGames.d.ts.map +1 -1
- package/_types/tempo/Account.d.ts +21 -2
- package/_types/tempo/Account.d.ts.map +1 -1
- package/_types/tempo/actions/accessKey.d.ts +3 -3
- package/_types/tempo/actions/accessKey.d.ts.map +1 -1
- package/_types/types/contract.d.ts +1 -1
- package/_types/types/contract.d.ts.map +1 -1
- package/_types/types/misc.d.ts +1 -1
- package/_types/types/misc.d.ts.map +1 -1
- package/_types/utils/buildRequest.d.ts.map +1 -1
- package/actions/wallet/prepareTransactionRequest.ts +1 -1
- package/chains/definitions/tron.ts +1 -0
- package/chains/definitions/zircuit.ts +1 -0
- package/chains/definitions/zircuitGarfieldTestnet.ts +1 -0
- package/errors/version.ts +1 -1
- package/op-stack/abis.ts +16 -0
- package/op-stack/actions/getGames.ts +33 -20
- package/package.json +1 -1
- package/tempo/Account.ts +50 -4
- package/tempo/actions/accessKey.ts +11 -9
- package/types/contract.ts +2 -2
- package/types/misc.ts +1 -1
- package/utils/buildRequest.ts +17 -2
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import type { Address } from 'abitype'
|
|
2
|
+
import {
|
|
3
|
+
type MulticallErrorType,
|
|
4
|
+
multicall,
|
|
5
|
+
} from '../../actions/public/multicall.js'
|
|
1
6
|
import {
|
|
2
7
|
type ReadContractErrorType,
|
|
3
8
|
readContract,
|
|
@@ -11,8 +16,7 @@ import type {
|
|
|
11
16
|
DeriveChain,
|
|
12
17
|
GetChainParameter,
|
|
13
18
|
} from '../../types/chain.js'
|
|
14
|
-
import {
|
|
15
|
-
import { disputeGameFactoryAbi, portal2Abi } from '../abis.js'
|
|
19
|
+
import { disputeGameAbi, disputeGameFactoryAbi, portal2Abi } from '../abis.js'
|
|
16
20
|
import type { GetContractAddressParameter } from '../types/contract.js'
|
|
17
21
|
import type { Game } from '../types/withdrawal.js'
|
|
18
22
|
|
|
@@ -38,7 +42,10 @@ export type GetGamesParameters<
|
|
|
38
42
|
export type GetGamesReturnType = (Game & {
|
|
39
43
|
l2BlockNumber: bigint
|
|
40
44
|
})[]
|
|
41
|
-
export type GetGamesErrorType =
|
|
45
|
+
export type GetGamesErrorType =
|
|
46
|
+
| ReadContractErrorType
|
|
47
|
+
| MulticallErrorType
|
|
48
|
+
| ErrorType
|
|
42
49
|
|
|
43
50
|
/**
|
|
44
51
|
* Retrieves dispute games for an L2.
|
|
@@ -106,23 +113,29 @@ export async function getGames<
|
|
|
106
113
|
}),
|
|
107
114
|
])
|
|
108
115
|
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
116
|
+
const rawGames = (await readContract(client, {
|
|
117
|
+
abi: disputeGameFactoryAbi,
|
|
118
|
+
functionName: 'findLatestGames',
|
|
119
|
+
address: disputeGameFactoryAddress,
|
|
120
|
+
args: [
|
|
121
|
+
gameType,
|
|
122
|
+
BigInt(Math.max(0, Number(gameCount - 1n))),
|
|
123
|
+
BigInt(Math.min(limit, Number(gameCount))),
|
|
124
|
+
],
|
|
125
|
+
})) as Game[]
|
|
126
|
+
|
|
127
|
+
const l2SequenceNumbers = await multicall(client, {
|
|
128
|
+
allowFailure: false,
|
|
129
|
+
contracts: rawGames.map((game) => ({
|
|
130
|
+
abi: disputeGameAbi,
|
|
131
|
+
address: `0x${game.metadata.slice(26)}` as Address,
|
|
132
|
+
functionName: 'l2SequenceNumber' as const,
|
|
133
|
+
})),
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
const games = rawGames
|
|
137
|
+
.map((game, i) => {
|
|
138
|
+
const blockNumber = l2SequenceNumbers[i] as bigint
|
|
126
139
|
return !l2BlockNumber || blockNumber > l2BlockNumber
|
|
127
140
|
? { ...game, l2BlockNumber: blockNumber }
|
|
128
141
|
: null
|
package/package.json
CHANGED
package/tempo/Account.ts
CHANGED
|
@@ -45,7 +45,7 @@ export type Account_base<source extends string = string> = RequiredBy<
|
|
|
45
45
|
export type RootAccount = Account_base<'root'> & {
|
|
46
46
|
/** Sign key authorization. */
|
|
47
47
|
signKeyAuthorization: (
|
|
48
|
-
key:
|
|
48
|
+
key: resolveAccessKey.Parameters,
|
|
49
49
|
parameters: Pick<
|
|
50
50
|
KeyAuthorization.KeyAuthorization,
|
|
51
51
|
'chainId' | 'expiry' | 'limits' | 'scopes'
|
|
@@ -382,7 +382,7 @@ export async function signKeyAuthorization(
|
|
|
382
382
|
parameters: signKeyAuthorization.Parameters,
|
|
383
383
|
): Promise<signKeyAuthorization.ReturnValue> {
|
|
384
384
|
const { chainId, key, expiry, limits, scopes } = parameters
|
|
385
|
-
const { accessKeyAddress, keyType: type } = key
|
|
385
|
+
const { accessKeyAddress, keyType: type } = resolveAccessKey(key)
|
|
386
386
|
|
|
387
387
|
const signature = await account.sign!({
|
|
388
388
|
hash: KeyAuthorization.getSignPayload({
|
|
@@ -410,7 +410,7 @@ export declare namespace signKeyAuthorization {
|
|
|
410
410
|
KeyAuthorization.KeyAuthorization,
|
|
411
411
|
'chainId' | 'expiry' | 'limits' | 'scopes'
|
|
412
412
|
> & {
|
|
413
|
-
key:
|
|
413
|
+
key: resolveAccessKey.Parameters
|
|
414
414
|
}
|
|
415
415
|
|
|
416
416
|
type ReturnValue = KeyAuthorization.Signed
|
|
@@ -530,7 +530,7 @@ function fromRoot(parameters: fromRoot.Parameters): RootAccount {
|
|
|
530
530
|
source: 'root',
|
|
531
531
|
async signKeyAuthorization(key, parameters) {
|
|
532
532
|
const { chainId, expiry, limits, scopes } = parameters
|
|
533
|
-
const { accessKeyAddress, keyType: type } = key
|
|
533
|
+
const { accessKeyAddress, keyType: type } = resolveAccessKey(key)
|
|
534
534
|
|
|
535
535
|
const signature = await account.sign({
|
|
536
536
|
hash: KeyAuthorization.getSignPayload({
|
|
@@ -587,6 +587,52 @@ declare namespace fromAccessKey {
|
|
|
587
587
|
export type ReturnValue = AccessKeyAccount
|
|
588
588
|
}
|
|
589
589
|
|
|
590
|
+
/** @internal */
|
|
591
|
+
export function resolveAccessKey(
|
|
592
|
+
accessKey: resolveAccessKey.Parameters,
|
|
593
|
+
): resolveAccessKey.ReturnType {
|
|
594
|
+
if ('accessKeyAddress' in accessKey)
|
|
595
|
+
return {
|
|
596
|
+
accessKeyAddress: accessKey.accessKeyAddress,
|
|
597
|
+
keyType: accessKey.keyType,
|
|
598
|
+
}
|
|
599
|
+
if ('publicKey' in accessKey && accessKey.publicKey)
|
|
600
|
+
return {
|
|
601
|
+
accessKeyAddress: Address.fromPublicKey(
|
|
602
|
+
PublicKey.fromHex(accessKey.publicKey),
|
|
603
|
+
),
|
|
604
|
+
keyType: accessKey.type,
|
|
605
|
+
}
|
|
606
|
+
return {
|
|
607
|
+
accessKeyAddress: accessKey.address,
|
|
608
|
+
keyType: accessKey.type,
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
export declare namespace resolveAccessKey {
|
|
613
|
+
type Parameters =
|
|
614
|
+
| Pick<AccessKeyAccount, 'accessKeyAddress' | 'keyType'>
|
|
615
|
+
| OneOf<
|
|
616
|
+
| {
|
|
617
|
+
/** Access key address. */
|
|
618
|
+
address: Address.Address
|
|
619
|
+
/** Key type. */
|
|
620
|
+
type: SignatureEnvelope.Type
|
|
621
|
+
}
|
|
622
|
+
| {
|
|
623
|
+
/** Access key public key. */
|
|
624
|
+
publicKey: Hex.Hex
|
|
625
|
+
/** Key type. */
|
|
626
|
+
type: SignatureEnvelope.Type
|
|
627
|
+
}
|
|
628
|
+
>
|
|
629
|
+
|
|
630
|
+
type ReturnType = {
|
|
631
|
+
accessKeyAddress: Address.Address
|
|
632
|
+
keyType: SignatureEnvelope.Type
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
590
636
|
// Export types required for inference.
|
|
591
637
|
// biome-ignore lint/performance/noBarrelFile: _
|
|
592
638
|
export {
|
|
@@ -17,7 +17,7 @@ import type { Log } from '../../types/log.js'
|
|
|
17
17
|
import type { Compute } from '../../types/utils.js'
|
|
18
18
|
import { parseEventLogs } from '../../utils/abi/parseEventLogs.js'
|
|
19
19
|
import * as Abis from '../Abis.js'
|
|
20
|
-
import type { AccessKeyAccount } from '../Account.js'
|
|
20
|
+
import type { AccessKeyAccount, resolveAccessKey } from '../Account.js'
|
|
21
21
|
import { signKeyAuthorization } from '../Account.js'
|
|
22
22
|
import * as Addresses from '../Addresses.js'
|
|
23
23
|
import * as Hardfork from '../Hardfork.js'
|
|
@@ -91,7 +91,7 @@ export namespace authorize {
|
|
|
91
91
|
|
|
92
92
|
export type Args = {
|
|
93
93
|
/** The access key to authorize. */
|
|
94
|
-
accessKey:
|
|
94
|
+
accessKey: resolveAccessKey.Parameters
|
|
95
95
|
/** The chain ID. */
|
|
96
96
|
chainId?: number | undefined
|
|
97
97
|
/** Unix timestamp when the key expires. */
|
|
@@ -332,7 +332,7 @@ export namespace revoke {
|
|
|
332
332
|
address: Addresses.accountKeychain,
|
|
333
333
|
abi: Abis.accountKeychain,
|
|
334
334
|
functionName: 'revokeKey',
|
|
335
|
-
args: [
|
|
335
|
+
args: [resolveAccessKeyAddress(accessKey)],
|
|
336
336
|
})
|
|
337
337
|
}
|
|
338
338
|
|
|
@@ -528,7 +528,7 @@ export namespace updateLimit {
|
|
|
528
528
|
address: Addresses.accountKeychain,
|
|
529
529
|
abi: Abis.accountKeychain,
|
|
530
530
|
functionName: 'updateSpendingLimit',
|
|
531
|
-
args: [
|
|
531
|
+
args: [resolveAccessKeyAddress(accessKey), token, limit],
|
|
532
532
|
})
|
|
533
533
|
}
|
|
534
534
|
|
|
@@ -704,7 +704,7 @@ export namespace getMetadata {
|
|
|
704
704
|
address: Addresses.accountKeychain,
|
|
705
705
|
abi: Abis.accountKeychain,
|
|
706
706
|
functionName: 'getKey',
|
|
707
|
-
args: [account,
|
|
707
|
+
args: [account, resolveAccessKeyAddress(accessKey)],
|
|
708
708
|
})
|
|
709
709
|
}
|
|
710
710
|
}
|
|
@@ -804,7 +804,7 @@ export namespace getRemainingLimit {
|
|
|
804
804
|
address: Addresses.accountKeychain,
|
|
805
805
|
abi: Abis.accountKeychain,
|
|
806
806
|
functionName: 'getRemainingLimit',
|
|
807
|
-
args: [account,
|
|
807
|
+
args: [account, resolveAccessKeyAddress(accessKey), token],
|
|
808
808
|
})
|
|
809
809
|
}
|
|
810
810
|
|
|
@@ -820,7 +820,7 @@ export namespace getRemainingLimit {
|
|
|
820
820
|
address: Addresses.accountKeychain,
|
|
821
821
|
abi: Abis.accountKeychain,
|
|
822
822
|
functionName: 'getRemainingLimitWithPeriod',
|
|
823
|
-
args: [account,
|
|
823
|
+
args: [account, resolveAccessKeyAddress(accessKey), token],
|
|
824
824
|
})
|
|
825
825
|
}
|
|
826
826
|
}
|
|
@@ -876,7 +876,7 @@ export namespace signAuthorization {
|
|
|
876
876
|
account extends Account | undefined = Account | undefined,
|
|
877
877
|
> = GetAccountParameter<account> & {
|
|
878
878
|
/** The access key to authorize. */
|
|
879
|
-
accessKey:
|
|
879
|
+
accessKey: resolveAccessKey.Parameters
|
|
880
880
|
/** The chain ID. */
|
|
881
881
|
chainId?: number | undefined
|
|
882
882
|
/** Unix timestamp when the key expires. */
|
|
@@ -893,7 +893,9 @@ export namespace signAuthorization {
|
|
|
893
893
|
}
|
|
894
894
|
|
|
895
895
|
/** @internal */
|
|
896
|
-
function
|
|
896
|
+
function resolveAccessKeyAddress(
|
|
897
|
+
accessKey: Address | AccessKeyAccount,
|
|
898
|
+
): Address {
|
|
897
899
|
if (typeof accessKey === 'string') return accessKey
|
|
898
900
|
return accessKey.accessKeyAddress
|
|
899
901
|
}
|
package/types/contract.ts
CHANGED
|
@@ -466,8 +466,8 @@ export type LogTopicType<
|
|
|
466
466
|
topic extends LogTopic = LogTopic,
|
|
467
467
|
> = topic extends Hex
|
|
468
468
|
? primitiveType
|
|
469
|
-
: topic extends Hex[]
|
|
470
|
-
? primitiveType[]
|
|
469
|
+
: topic extends readonly Hex[]
|
|
470
|
+
? readonly primitiveType[]
|
|
471
471
|
: topic extends null
|
|
472
472
|
? null
|
|
473
473
|
: never
|
package/types/misc.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { OneOf } from './utils.js'
|
|
|
3
3
|
export type ByteArray = Uint8Array
|
|
4
4
|
export type Hex = `0x${string}`
|
|
5
5
|
export type Hash = `0x${string}`
|
|
6
|
-
export type LogTopic = Hex | Hex[] | null
|
|
6
|
+
export type LogTopic = Hex | readonly Hex[] | null
|
|
7
7
|
export type SignableMessage =
|
|
8
8
|
| string
|
|
9
9
|
| {
|
package/utils/buildRequest.ts
CHANGED
|
@@ -71,7 +71,6 @@ import type {
|
|
|
71
71
|
EIP1193RequestFn,
|
|
72
72
|
EIP1193RequestOptions,
|
|
73
73
|
} from '../types/eip1193.js'
|
|
74
|
-
import { stringToHex } from './encoding/toHex.js'
|
|
75
74
|
import type { CreateBatchSchedulerErrorType } from './promise/createBatchScheduler.js'
|
|
76
75
|
import { withDedupe } from './promise/withDedupe.js'
|
|
77
76
|
import { type WithRetryErrorType, withRetry } from './promise/withRetry.js'
|
|
@@ -143,7 +142,7 @@ export function buildRequest<request extends (args: any) => Promise<any>>(
|
|
|
143
142
|
})
|
|
144
143
|
|
|
145
144
|
const requestId = dedupe
|
|
146
|
-
?
|
|
145
|
+
? hashString(`${uid}.${stringify(args)}`)
|
|
147
146
|
: undefined
|
|
148
147
|
return withDedupe(
|
|
149
148
|
() =>
|
|
@@ -306,3 +305,19 @@ export function shouldRetry(error: Error) {
|
|
|
306
305
|
}
|
|
307
306
|
return true
|
|
308
307
|
}
|
|
308
|
+
|
|
309
|
+
/** @internal cyrb53 – fast, non-cryptographic 53-bit string hash */
|
|
310
|
+
function hashString(str: string, seed = 0): string {
|
|
311
|
+
let h1 = 0xdeadbeef ^ seed
|
|
312
|
+
let h2 = 0x41c6ce57 ^ seed
|
|
313
|
+
for (let i = 0; i < str.length; i++) {
|
|
314
|
+
const ch = str.charCodeAt(i)
|
|
315
|
+
h1 = Math.imul(h1 ^ ch, 2654435761)
|
|
316
|
+
h2 = Math.imul(h2 ^ ch, 1597334677)
|
|
317
|
+
}
|
|
318
|
+
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507)
|
|
319
|
+
h1 ^= Math.imul(h2 ^ (h2 >>> 16), 3266489909)
|
|
320
|
+
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507)
|
|
321
|
+
h2 ^= Math.imul(h1 ^ (h1 >>> 16), 3266489909)
|
|
322
|
+
return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(36)
|
|
323
|
+
}
|