-
Notifications
You must be signed in to change notification settings - Fork 3
Fix 8 TypeScript compilation errors and add EIP712 runtime support #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sudo-owen
wants to merge
9
commits into
main
Choose a base branch
from
claude/fix-transpiler-issues-mbHNU
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
Major fixes to reduce TypeScript compilation errors from 39 to 23:
1. Array .length to BigInt conversion - wrap in BigInt() when assigned to
bigint variables, with specific EnumerableSetLib type exclusions
2. address(uint160(...)) pattern - detect numeric casts and convert bigint
to hex address string instead of accessing _contractAddress on bigint
3. Interface casts with method calls - ICPU(address(this)).method() now
casts to 'any' to allow interface method calls on abstract classes
4. new string(length) pattern - Solidity's string allocation now returns
empty string since TypeScript can't use 'new string()'
5. bytes32("STRING") conversion - string literals cast to bytes32 are
properly converted to hex encoding
6. Override modifier on interface methods - exclude interface methods from
inherited_methods check for TypeScript's override keyword
7. bytes32 constants as hex strings - generate proper hex string values
instead of BigInt for bytes32 state variables
8. ABI type inference for address() casts - properly infer 'address' type
for address(this) and similar patterns in abi.encode
https://claude.ai/code/session_01Q76KPUo9pMEzA4YARpnPw1
Key fixes:
- Created runtime/base.ts to fix circular dependency issues
- Added EIP712 runtime replacement module
- Fixed runtime replacement imports (Ownable, ECDSA, EIP712)
- Improved struct field type inference in ABI encoding
- Added proper 0x${string} casting for addresses and bytes32
- Fixed multiple inheritance with Ownable mixin generation
- Changed mapping types from Map to Record for consistency
- Fixed address() cast for struct fields already typed as address
- Improved blockhash/keccak256 ABI type inference
Reduced TypeScript errors from 39+ to 4.
https://claude.ai/code/session_01Q76KPUo9pMEzA4YARpnPw1
- Add TypeCast handling in _convert_abi_value for address/bytes32 casts - Add string type inference in _infer_single_abi_type - Update _emitEvent signature to accept variadic args All transpiled TypeScript files now compile without errors. https://claude.ai/code/session_01Q76KPUo9pMEzA4YARpnPw1
- Move mixin definitions from hard-coded sol2ts.py to runtime-replacements.json - Add "mixin" field to runtime replacement interface definitions - Update TypeScriptCodeGenerator to load and apply mixins from JSON config - Any runtime replacement class with a mixin field will automatically be inlined when used as a secondary base class This allows future multiple inheritance cases to be handled by simply adding mixin code to the JSON config, rather than modifying the transpiler. https://claude.ai/code/session_01Q76KPUo9pMEzA4YARpnPw1
- Generate factory functions for each struct (e.g., createDefaultBattleConfig()) to handle mapping access returning undefined instead of zero-initialized structs - Fix storage struct references to persist modifications using ??= pattern - Add integration tests for Engine with proper mocks for RNGOracle, TeamRegistry, Validator, Ruleset, and Matchmaker - Clean up old test files and replace with comprehensive integration.test.ts - Make runtime Contract class properties public for test access All 13 integration tests now pass. https://claude.ai/code/session_01Q76KPUo9pMEzA4YARpnPw1
- Document Batch 3 fixes (issues #15-23): - Struct factory functions for mapping access - Storage reference write-back semantics - EIP712 runtime module - Multiple inheritance mixin system - Circular dependency resolution - Improved ABI type inference - viem type casting - Runtime contract properties made public - Comprehensive integration test suite - Update Remaining Issues section to show all resolved - Expand Testing section with new test suites and commands https://claude.ai/code/session_01Q76KPUo9pMEzA4YARpnPw1
1. Bigint as Record index type (TS2538) - Add Number() conversion for numeric mapping keys in storage init statements - Check key_type to determine if Number() wrapping is needed 2. Local struct factory calls - Check current_local_structs before adding Structs. prefix - Local structs (defined in contract) use createDefault*() directly 3. EnumerableSetLib initialization - AddressSet and Uint256Set use new constructor syntax - Instead of Structs.createDefaultAddressSet(), use new AddressSet() All 19 TypeScript errors are now resolved. 31 tests pass. https://claude.ai/code/session_01Q76KPUo9pMEzA4YARpnPw1
- Document bigint Record index conversion fix - Document local struct factory call fix - Document EnumerableSetLib initialization fix - Update status: 0 TypeScript errors, 31 tests pass https://claude.ai/code/session_01Q76KPUo9pMEzA4YARpnPw1
…work - Remove extensive fix history (26 items) - now in git history - Expand Known Limitations section with tables for: - Parser limitations with workarounds - Semantic differences between Solidity and TypeScript - Type system gaps and their status - Files requiring runtime replacements - Restructure Future Work with priority levels - Streamline documentation for better readability https://claude.ai/code/session_01Q76KPUo9pMEzA4YARpnPw1
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
This PR fixes 8 categories of TypeScript compilation errors in the Solidity transpiler, reducing errors from 39 to 23. It also adds EIP712 runtime support for contracts using typed structured data hashing, and refactors the runtime module structure to avoid circular dependencies.
Key Changes
TypeScript Compilation Fixes (Batch 2)
.lengthto BigInt: Wraps array.lengthproperty inBigInt()when assigned to bigint variables, excluding EnumerableSetLib types that already return bigintaddress(uint160(...))Pattern: Converts bigint to hex address strings using`0x${(expr).toString(16).padStart(40, "0")}`ICPU(address(this)).calculateMove()toanyto allow method callsnew string(length)Pattern: Transpiles Solidity'snew string(length)to empty string""and handlesnew bytes(length)bytes32("STRING")Conversion: Properly converts string literals cast to bytes32 to hex encodingget_all_inherited_methods()to prevent false override errorsbytes32Constants as Hex Strings: Generates string values instead of BigInt for bytes32 hex literalsaddress()Casts: Infersaddress(this)inabi.encodeas'address'type instead of'uint256'EIP712 Runtime Support
EIP712.tsruntime module with full EIP-712 typed data hashing implementationruntime-replacements.jsonwith mixin support for multiple inheritance_domainNameAndVersionMayChange()Runtime Module Refactoring
base.tsmodule containing coreContractclass and utilitiesStorage,EventStream,ContractAddressRegistry, andADDRESS_ZEROtobase.ts./baseinstead of./indexOwnable Mixin Support
runtime-replacements.jsonDependencies
vitest(^4.0.18) to dev dependencies for testingRemaining Issues
Reduced from 39 to 23 errors. Main categories still needing fixes:
abi.encode0x${string}addressesTesting
The changes maintain backward compatibility with existing transpiled code while fixing specific TypeScript compilation patterns identified in the codebase.
https://claude.ai/code/session_01Q76KPUo9pMEzA4YARpnPw1