gnidan / abi-to-sol

Generate Solidity interface from ABI JSON
https://gnidan.github.io/abi-to-sol
MIT License
324 stars 51 forks source link

Rearchitect declaration internals to support UDVTs #114

Closed gnidan closed 1 year ago

gnidan commented 1 year ago

Addresses #113 and partially addresses #42

This PR adds support for user-defined value types by redoing the internals of how abi-to-sol finds all the declared types it needs to emit.

Previously, abi-to-sol was built only to emit structs, and it relied heavily on the ABI schema's idea of a tuple signature (e.g. (uint256,address)) to organize all the known struct declarations. Struct signatures were used both during declaration collection and during code generation. This caused problems in #42 because signatures lose names, and the old format couldn't collect more than one struct for a given signature. This also prevented any kind of UDVT support, because everything was struct-based.

So this PR replaces that with several very-explicit-but-kind-of-messy modules for kinds, identifiers, etc.... and a new explicit bind step, whew! This explicit bind step is helpful and long overdue. In the spirit of structuring these new internals as an IR, things get complicated with ABI JSON parameter's type field, which is standard, and internalType, which is Solidity-specific. This PR includes a bunch of type guards for taking a type and classifying it as elementary/array/tuple/etc., and similarly classifying parameter type references as structs and UDVTs and whatnot.

To decouple code generation from struct signature based lookups, the new declarations collection system also provides corresponding search logic, so that when the code generator must output an ABI parameter, there's a first-class mechanism for finding the right declaration to use.

This PR also includes some unrelated changes:

Notes: