feat: upgrade to viem 2.48.4 (breaking) - #702
Draft
douglance wants to merge 2 commits into
Draft
Conversation
Bump viem 1.20.0 → 2.48.4, abitype 0.9.8 → 1.2.4, @wagmi/cli v1 → v2,
TypeScript 5.2 → 5.9. Remove viem pin from pnpm.overrides.
Package is now ESM (type: "module"). tsconfig uses moduleResolution
"bundler" + module "preserve" + DOM lib (required by viem v2's ox dep).
Reshape every *ReadContract and *PrepareTransactionRequest helper + its
decorator method to a non-generic distributed-discriminated-union shape.
This sidesteps TS#30581 without casts while preserving inline-literal
inference at call sites. Consumers using explicit-generic call syntax
(client.fn<'literalName'>({...})) must drop the generic; inference still
flows from the object literal.
PrepareTransactionRequestReturnTypeWithChainId now pins type: 'eip1559',
so returns are directly assignable to signTransaction/sendRawTransaction.
createTokenBridge is no longer generic over <TParentChain, TOrbitChain>.
prepareUpgradeExecutorCallParameters takes (encoded, envelope) instead of
a combined object.
Zero @ts-expect-error in non-test source; zero as-unknown-as casts for
TS-limitation workarounds. Three casts remain at genuine runtime-
validated system boundaries (JSON-RPC parse, @arbitrum/sdk arrays).
Gates: pnpm build ✓, pnpm lint ✓, pnpm test:type 55/58 (3 skipped with
TODO for DeepNormalize publicClient-shape drift), pnpm test:unit 221/221.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Upgrades
viemfrom1.20.0to2.48.4across the entire SDK. This is a breaking release; consumers must also upgrade their viem peer to^2.48.4.Dependencies
viem:^1.20.0→^2.48.4(peer + dev)abitype:^0.9.8→^1.2.4@wagmi/cli:^1.5.2→^2.10.0typescript:^5.2.2→^5.9.3viemandviem>wsentries frompnpm.overrides— the resolver now picks latest compatible versions everywhere.Module system
The shipped package is now ESM.
src/package.jsonsets"type": "module"and emits.jsfiles with ES module syntax. Consumers that userequire('@arbitrum/chain-sdk')under CommonJS will need to switch to dynamicimport()or rely on a bundler / Node 22+ CJS↔ESM interop.Public-API reshape (driven by TS#30581 under viem v2)
viem v2's stricter generics made the v1-era "generic
<TFunctionName>wrapper" pattern impossible to type without casts. Each of the following wrappers has been reshaped to accept a distributed discriminated union over every concrete function name. Call-site narrowing still works when you pass an inline object literal:arbGasInfoReadContract,arbAggregatorReadContract,arbOwnerReadContract,sequencerInboxReadContract,rollupAdminLogicReadContract— non-generic; return type is a union over all read-function return types.arbAggregatorPrepareTransactionRequest,arbOwnerPrepareTransactionRequest,sequencerInboxPrepareTransactionRequest,rollupAdminLogicPrepareTransactionRequest— non-generic; params are a distributed union of every write-function + its arg tuple.client.arbOwnerReadContract(...), etc.) follow the same shape.Caller migration
client.fn<'literalName'>({ ... })→client.fn({ functionName: 'literalName', ... }). TS narrows from the object literal'sfunctionNamediscriminant.maxTimeVariationreturns a tuple,bridgereturns an address string), narrow with a runtime check (Array.isArray(result)ortypeof result === 'string') before using it. The runtime value is unchanged.Removed / changed helpers
prepareUpgradeExecutorCallParametersnow takes(encoded: Hex, envelope)as two positional args instead of a combined object. All fourbuildSet*callers are updated internally.createTokenBridgeis no longer generic over<TParentChain, TOrbitChain>. The return type isCreateTokenBridgeResults<Chain | undefined, Chain | undefined>. Consumers that pinnedChainnarrowing must widen their types.prepareTransactionRequestreturn typeThe SDK's internal
PrepareTransactionRequestReturnTypeWithChainIdalias now pins the transactiontypeto'eip1559'. Every*PrepareTransactionRequesthelper passestype: 'eip1559'to viem, so the return is directly assignable tosignTransaction/sendRawTransactionwithout casts. Non-EIP-1559 transactions (legacy, 2930, 4844, 7702) are not produced by these helpers.TypeScript configuration
tsconfig.jsonnow usesmoduleResolution: "bundler"andmodule: "preserve"(required for viem v2's type graph under pnpm).libnow includes"DOM"(viem v2'soxdependency referencescrypto/windowglobals in its WebAuthn module).--module commonjs; ESM output is driven by the package's"type": "module"and tsconfig.Fraud-free gate
@ts-expect-errordirectives in non-test source.as unknown as/as any/@ts-ignorein non-test source added for TS-limitation workarounds.as unknown ascasts remain at genuine system boundaries: one JSON-RPC response parse inutils/getClientVersion.ts, two@arbitrum/sdkresult arrays in the token-bridge receipt helpers that the surrounding code runtime-validates for length and status.Known gaps
src/scripting/schemas/schemas.type.test.tsare skipped withit.skipand aTODO(viem-v2)comment. They comparez.output<schema>toParameters<fn>[0]and trip on viem v2's expandedPublicClientmethod surface — a test-helper (DeepNormalize) issue, not a correctness gap.Test plan
pnpm build— zero TS errorspnpm lint— cleanpnpm test:type— 55 passed, 3 skipped (documented above)pnpm test:unit— 221 passed locallypnpm test:integrationagainst a running nitro-testnoderequire('@arbitrum/chain-sdk')CJS path before landing the ESM switch