Skip to content
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

Differing structs with duplicate "signatures" are combined into only one struct in output #42

Open
gnidan opened this issue Nov 20, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@gnidan
Copy link
Owner

gnidan commented Nov 20, 2021

abi-to-sol will only ever produce exactly one struct definition for any number of tuple types that contain the same number of components with the same types of those components.

This is problematic, e.g. for @uniswap/v3-periphery's ISwapRouter, since ExactInputSingleParams and ExactOutputSingleParams both have the same "signature" [address,address,uint24,address,uint256,uint256,uint256,uint160], even though these are very different structs (the fields for "amount in" and "amount out" have their order reversed!) The resulting usage ends up looking something like this:

router.exactInputSingle(ISwapRouter.ExactOutputSingleParams({
  tokenIn: // ...,
  tokenOut: // ...,
  fee: // ...,
  recipient: // ...,
  deadline: // ...,
  amountOut: 1000,
  amountInMaximum: 10,
  sqrtPriceLimitX96: // ...
}));

Note that amountOut actually refers to amountIn, and amountInMaximum actually refers to amountOutMinimum!

This behavior is due to the way that abi-to-sol performs its initial first pass traversing the input ABI JSON in order to collect all tuple parameters to turn into struct definitions: it visits the ABI entries for all parameters, organizing tuple parameters by their signature. This results in the "undefined behavior" (so to speak) of later-appearing internalTypes overwriting earlier ones.

Proper behavior would be to keep track of these tuple parameters by their actual internalType information and keep things separate.

@gnidan gnidan added the bug Something isn't working label Jul 17, 2022
@gnidan
Copy link
Owner Author

gnidan commented Jun 8, 2023

The situation here has improved dramatically with abi-to-sol v0.8.0 (see release notes).

This tool should now respect existing internalType names for existing structs, and if two structs with different names have the same "type signature", abi-to-sol will no longer lose track of them.

This has not been completely solved yet, by this release, however, since the fix doesn't apply without internalTypes.

Future work to finally be able to close this will require the declaration search system to consider struct member names when determining which declaration to reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant