import type { SemiModularAccount7702Version as SdkSemiModularAccount7702Version } from "@alchemy/smart-accounts"; import type { Address } from "viem"; import { z } from "./zod.js"; /** * Delegation address of each released `SemiModularAccount7702` version. */ // Must be EIP-55 checksummed: these values are compared as exact strings by the // request schema and by DelegationAddressToAccountType. The `satisfies` pins the // keys to aa-sdk's registry in both directions — a version the SDK adds or drops // fails to compile here. The addresses themselves are `Address` in the SDK, so // 7702.test.ts checks those against the registry. export const SMA_7702_DELEGATION_ADDRESSES = { "v1.0.0": "0x69007702764179f14F51cdce752f4f775d74E139", "v1.1.0": "0x77021100bD87b7008E5E1989d0eB38555d0d0000", } as const satisfies Record; export type Sma7702Version = keyof typeof SMA_7702_DELEGATION_ADDRESSES; /** Every released SemiModularAccount7702 version supported by aa-sdk. */ export const SMA_7702_VERSIONS = Object.keys(SMA_7702_DELEGATION_ADDRESSES) as [ Sma7702Version, ...Sma7702Version[], ]; export const SemiModularAccount7702Version = z.enum(SMA_7702_VERSIONS); const VERSION_BY_LOWERCASE_ADDRESS = new Map( SMA_7702_VERSIONS.map((version) => [ SMA_7702_DELEGATION_ADDRESSES[version].toLowerCase(), version, ]), ); /** * Inverse of {@link SMA_7702_DELEGATION_ADDRESSES}. Returns `undefined` for any * address that is not a released `SemiModularAccount7702` delegate — including * the zero address, which has no version. */ export const getVersionForDelegationAddress7702 = ( address: Address, ): Sma7702Version | undefined => VERSION_BY_LOWERCASE_ADDRESS.get(address.toLowerCase());