Skip to content

Conversation

@mattsse
Copy link
Member

@mattsse mattsse commented Jan 23, 2026

Summary

Adds a new --flatten flag to cast interface that inlines inherited/library struct types directly into the generated interface.

Problem

When running cast interface on a contract that uses structs from an inherited interface, the output generates a library for the struct definitions instead of keeping them in the interface (#9960).

Example of the issue:

// Generated without flag - struct in separate library
library IBase {
    struct TestStruct { address asset; }
}
interface Contract {
    function test(IBase.TestStruct memory) external;
}

Solution

Uses alloy-json-abi's ToSolConfig::one_contract(true) option (introduced in alloy-core 0.8.24 via alloy-rs/core#911) to consolidate all types into a single interface:

// Generated with --flatten flag
interface Contract {
    // Types from \`IBase\`
    struct TestStruct { address asset; }
    
    function test(TestStruct memory) external;
}

Changes

  • Added --flatten CLI flag to cast interface command
  • Pass ToSolConfig::new().one_contract(true) to JsonAbi::to_sol() when flag is set
  • Added test case for the new flag

Closes #9960

Adds a new `--all-in-one` flag to `cast interface` that inlines
inherited/library struct types directly into the generated interface.

This addresses the issue where `cast interface` generates a separate
`library` block for struct types that originate from inherited interfaces,
making the generated interface less usable for some workflows.

With `--all-in-one`, all types are consolidated into a single interface:

```solidity
// Before (default):
library IBase {
    struct TestStruct { address asset; }
}
interface Contract {
    function test(IBase.TestStruct memory) external;
}

// After (with --all-in-one):
interface Contract {
    struct TestStruct { address asset; }
    function test(TestStruct memory) external;
}
```

Uses alloy-json-abi's `ToSolConfig::one_contract(true)` option
introduced in alloy-core 0.8.24.

Closes #9960
///
/// This can fail if there are structs with the same name in different interfaces.
#[arg(long)]
all_in_one: bool,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe flatten is more intuitive here

@mattsse mattsse requested a review from zerosnacks January 23, 2026 20:23
@zerosnacks zerosnacks changed the title feat(cast): add --all-in-one flag to cast interface feat(cast): add --flatten flag to cast interface Jan 24, 2026
@grandizzy grandizzy added this pull request to the merge queue Jan 24, 2026
Merged via the queue into master with commit 3c4315f Jan 24, 2026
16 checks passed
@grandizzy grandizzy deleted the fix/cast-interface-inline-structs branch January 24, 2026 09:41
@github-project-automation github-project-automation bot moved this to Done in Foundry Jan 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug(cast): cast interface generates unexpected library instead of interface

4 participants