Repository: gakonst/ethers-rs (rust)

Issue:
Invalid bindings are generated
**Version**
ethers v0.6.0 (https://github.com/gakonst/ethers-rs#fa042478)

**Platform**
Darwin MacBook-Pro.local 21.4.0 Darwin Kernel Version 21.4.0: Mon Feb 21 20:35:58 PST 2022; root:xnu-8020.101.4~2/RELEASE_ARM64_T6000 arm64

**Description**
When generating bindings with forge I noticed there seems to be an issue with serializing filters that have a u8 in them. You can recreate this issue by generating bindings for the LibDiamond contract that can be found here, https://github.com/mudgen/diamond-3/blob/master/contracts/libraries/LibDiamond.sol

I used the following command to generate the bindings:
`forge bind --bindings-path ./bindings --overwrite`

I am also on the latest version of foundry as well:
`forge 0.2.0 (d4c615b 2022-03-24T01:05:20.744764+00:00)`

However, I'm assuming this is an issue with ethers abigen not forge, hence why I created the issue here.

It generates the following code that causes the issue:

```rust
#[derive(
    Clone,
    Debug,
    Default,
    Eq,
    PartialEq,
    ethers :: contract :: EthEvent,
    ethers :: contract :: EthDisplay,
)]
#[ethevent(
    name = "DiamondCut",
    abi = "DiamondCut((address,uint8,bytes4[])[],address,bytes)"
)]
pub struct DiamondCutFilter {
    pub diamond_cut: Vec<(ethers::core::types::Address, u8, Vec<[u8; 4]>)>,
    pub init: ethers::core::types::Address,
    pub calldata: ethers::core::types::Bytes,
}
```

Attempting to compile the file it will throw the following error:

```
error[E0277]: the trait bound `u8: AbiArrayType` is not satisfied
   --> bindings/src/lib_diamond.rs:126:9
    |
126 |         pub diamond_cut: Vec<(ethers::core::types::Address, u8, Vec<[u8; 4]>)>,
    |         ^^^ the trait `AbiArrayType` is not implemented for `u8`
    |
    = note: required because of the requirements on the impl of `AbiArrayType` for `(H160, u8, Vec<[u8; 4]>)`
    = note: required because of the requirements on the impl of `AbiType` for `Vec<(H160, u8, Vec<[u8; 4]>)>`
```

Pull request:
fix(abi): change abiarraytype type bounds for tuple
<!--
Thank you for your Pull Request. Please provide a description above and review
the requirements below.

Bug fixes and new features should include tests.

Contributors guide: https://github.com/gakonst/ethers-rs/blob/master/CONTRIBUTING.md

The contributors guide includes instructions for running rustfmt and building the
documentation.
-->

## Motivation
Closes #1076
<!--
Explain the context and why you're making that change. What is the problem
you're trying to solve? In some cases there is not a problem and this can be
thought of as being the motivation for your change.
-->

## Solution
change the type bound from `AbiArrayType` to `AbiType` in the tuple macro
<!--
Summarize the solution and provide any necessary context needed to understand
the code change.
-->

## PR Checklist

- [x] Added Tests
- [x] Added Documentation
- [ ] Updated the changelog


Patch:
diff --git a/ethers-core/src/abi/codec.rs b/ethers-core/src/abi/codec.rs
index 39cf4031..283bd076 100644
--- a/ethers-core/src/abi/codec.rs
+++ b/ethers-core/src/abi/codec.rs
@@ -252,4 +252,12 @@ mod tests {
         let v = vec![bytes];
         assert_codec(v);
     }
+
+    #[test]
+    fn tuple_array() {
+        let nested: Vec<[u8; 4]> = vec![[0, 0, 0, 1]];
+        assert_codec(nested.clone());
+        let tuple: Vec<(Address, u8, Vec<[u8; 4]>)> = vec![(Address::random(), 0, nested)];
+        assert_codec(tuple);
+    }
 }
diff --git a/ethers-core/src/abi/mod.rs b/ethers-core/src/abi/mod.rs
index 925880b8..b2d50839 100644
--- a/ethers-core/src/abi/mod.rs
+++ b/ethers-core/src/abi/mod.rs
@@ -164,7 +164,7 @@ macro_rules! impl_abi_type_tuple {
 
         impl<$($ty, )+> AbiArrayType for ($($ty,)+) where
             $(
-                $ty: AbiArrayType,
+                $ty: AbiType,
             )+ {}
     }
 }


Test patch:
diff --git a/ethers-contract/tests/common/derive.rs b/ethers-contract/tests/common/derive.rs
index a18879d3..65f07ca7 100644
--- a/ethers-contract/tests/common/derive.rs
+++ b/ethers-contract/tests/common/derive.rs
@@ -572,3 +572,14 @@ fn can_derive_ethcall_for_bytes() {
 
     assert_ethcall::<BatchCall>();
 }
+
+#[test]
+fn can_derive_array_tuples() {
+    #[derive(Clone, Debug, Default, Eq, PartialEq, EthEvent, EthDisplay)]
+    #[ethevent(name = "DiamondCut", abi = "DiamondCut((address,uint8,bytes4[])[],address,bytes)")]
+    pub struct DiamondCutFilter {
+        pub diamond_cut: Vec<(Address, u8, Vec<[u8; 4]>)>,
+        pub init: Address,
+        pub calldata: Bytes,
+    }
+}