import { Hex } from "viem"; import { StaticAbiType, staticAbiTypes } from "./schemaAbiTypes"; import { LiteralToBroad } from "./utils"; // Fixed-length ABI types export type StaticPrimitiveType = number | bigint | boolean | Hex; export const staticAbiTypeToDefaultValue = { uint8: 0, uint16: 0, uint24: 0, uint32: 0, uint40: 0, uint48: 0, uint56: 0n, uint64: 0n, uint72: 0n, uint80: 0n, uint88: 0n, uint96: 0n, uint104: 0n, uint112: 0n, uint120: 0n, uint128: 0n, uint136: 0n, uint144: 0n, uint152: 0n, uint160: 0n, uint168: 0n, uint176: 0n, uint184: 0n, uint192: 0n, uint200: 0n, uint208: 0n, uint216: 0n, uint224: 0n, uint232: 0n, uint240: 0n, uint248: 0n, uint256: 0n, int8: 0, int16: 0, int24: 0, int32: 0, int40: 0, int48: 0, int56: 0n, int64: 0n, int72: 0n, int80: 0n, int88: 0n, int96: 0n, int104: 0n, int112: 0n, int120: 0n, int128: 0n, int136: 0n, int144: 0n, int152: 0n, int160: 0n, int168: 0n, int176: 0n, int184: 0n, int192: 0n, int200: 0n, int208: 0n, int216: 0n, int224: 0n, int232: 0n, int240: 0n, int248: 0n, int256: 0n, bytes1: "0x00", bytes2: "0x0000", bytes3: "0x000000", bytes4: "0x00000000", bytes5: "0x0000000000", bytes6: "0x000000000000", bytes7: "0x00000000000000", bytes8: "0x0000000000000000", bytes9: "0x000000000000000000", bytes10: "0x00000000000000000000", bytes11: "0x0000000000000000000000", bytes12: "0x000000000000000000000000", bytes13: "0x00000000000000000000000000", bytes14: "0x0000000000000000000000000000", bytes15: "0x000000000000000000000000000000", bytes16: "0x00000000000000000000000000000000", bytes17: "0x0000000000000000000000000000000000", bytes18: "0x000000000000000000000000000000000000", bytes19: "0x00000000000000000000000000000000000000", bytes20: "0x0000000000000000000000000000000000000000", bytes21: "0x000000000000000000000000000000000000000000", bytes22: "0x00000000000000000000000000000000000000000000", bytes23: "0x0000000000000000000000000000000000000000000000", bytes24: "0x000000000000000000000000000000000000000000000000", bytes25: "0x00000000000000000000000000000000000000000000000000", bytes26: "0x0000000000000000000000000000000000000000000000000000", bytes27: "0x000000000000000000000000000000000000000000000000000000", bytes28: "0x00000000000000000000000000000000000000000000000000000000", bytes29: "0x0000000000000000000000000000000000000000000000000000000000", bytes30: "0x000000000000000000000000000000000000000000000000000000000000", bytes31: "0x00000000000000000000000000000000000000000000000000000000000000", bytes32: "0x0000000000000000000000000000000000000000000000000000000000000000", bool: false, address: "0x0000000000000000000000000000000000000000", } as const satisfies Record; export type StaticAbiTypeToPrimitiveType = LiteralToBroad< (typeof staticAbiTypeToDefaultValue)[TStaticAbiType] >; export const staticAbiTypeToByteLength = { uint8: 1, uint16: 2, uint24: 3, uint32: 4, uint40: 5, uint48: 6, uint56: 7, uint64: 8, uint72: 9, uint80: 10, uint88: 11, uint96: 12, uint104: 13, uint112: 14, uint120: 15, uint128: 16, uint136: 17, uint144: 18, uint152: 19, uint160: 20, uint168: 21, uint176: 22, uint184: 23, uint192: 24, uint200: 25, uint208: 26, uint216: 27, uint224: 28, uint232: 29, uint240: 30, uint248: 31, uint256: 32, int8: 1, int16: 2, int24: 3, int32: 4, int40: 5, int48: 6, int56: 7, int64: 8, int72: 9, int80: 10, int88: 11, int96: 12, int104: 13, int112: 14, int120: 15, int128: 16, int136: 17, int144: 18, int152: 19, int160: 20, int168: 21, int176: 22, int184: 23, int192: 24, int200: 25, int208: 26, int216: 27, int224: 28, int232: 29, int240: 30, int248: 31, int256: 32, bytes1: 1, bytes2: 2, bytes3: 3, bytes4: 4, bytes5: 5, bytes6: 6, bytes7: 7, bytes8: 8, bytes9: 9, bytes10: 10, bytes11: 11, bytes12: 12, bytes13: 13, bytes14: 14, bytes15: 15, bytes16: 16, bytes17: 17, bytes18: 18, bytes19: 19, bytes20: 20, bytes21: 21, bytes22: 22, bytes23: 23, bytes24: 24, bytes25: 25, bytes26: 26, bytes27: 27, bytes28: 28, bytes29: 29, bytes30: 30, bytes31: 31, bytes32: 32, bool: 1, address: 20, } as const satisfies Record; export function isStaticAbiType(abiType: unknown): abiType is StaticAbiType { return staticAbiTypes.includes(abiType as StaticAbiType); }