Skip to content

Commit 17e1fc2

Browse files
authored
Merge pull request #70 from alloy-rs/yash/core-1.0
feat: migrating to core v1.0
2 parents 7c6fa46 + f6504e8 commit 17e1fc2

12 files changed

+299
-0
lines changed

src/SUMMARY.md

+14
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,20 @@
151151

152152
<!-- MANUALLY MAINTAINED -->
153153

154+
# Migrating to `alloy-core` v1.0
155+
156+
- [Highlights](./migrating-to-core-1.0/README.md)
157+
- [sol! macro changes](./migrating-to-core-1.0/sol!-changes/README.md)
158+
- [Removing the `T` transport generic](./migrating-to-core-1.0/sol!-changes/removing-T-generic.md)
159+
- [Improving function return type](./migrating-to-core-1.0/sol!-changes/improving-function-return-types.md)
160+
- [Changes to function call bindings](./migrating-to-core-1.0/sol!-changes/changes-to-function-call-bindings.md)
161+
- [Changes to event bindings](./migrating-to-core-1.0/sol!-changes/changes-to-event-bindings.md)
162+
- [Changes to error bindings](./migrating-to-core-1.0/sol!-changes/changes-to-error-bindings.md)
163+
- [Simplify ABI encoding and decoding](./migrating-to-core-1.0/encoding-decoding-changes/README.md)
164+
- [Encoding function return structs](./migrating-to-core-1.0/encoding-decoding-changes/encoding-return-structs.md)
165+
- [Removing `validate: bool` from the `abi_decode` methods](./migrating-to-core-1.0/encoding-decoding-changes/removing-validate-bool.md)
166+
- [Other breaking changes](./migrating-to-core-1.0/other-breaking-changes.md)
167+
154168
# Appendix
155169

156170
- [Help us improve Alloy](./appendix/contributing.md)

src/migrating-to-core-1.0/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Core v1.0 Highlights
2+
3+
### Revamping the `sol!` macro bindings
4+
5+
- [Contract and RPC codegen made cleaner by removal of the `T` transport generic](./sol!-changes/removing-T-generic.md)
6+
- [Improving the function return types by removing the need for `_0`](./sol!-changes/improving-function-return-types.md)
7+
- [Changes to function call bindings e.g `pub struct balanceOfCall { _0: Address }` to `pub struct balanceOfCall(pub Address)`](./sol!-changes/changes-to-function-call-bindings.md)
8+
- [Changes to event bindings](./sol!-changes/changes-to-event-bindings.md)
9+
- [Changes to error bindings](./sol!-changes/changes-to-error-bindings.md)
10+
11+
### Simplify ABI encoding and decoding
12+
13+
- [ABI encoding function return structs](./encoding-decoding-changes/encoding-return-structs.md)
14+
- [Removing `validate: bool` from the `abi_decode` methods](./encoding-decoding-changes/removing-validate-bool.md)
15+
16+
### Other breaking changes
17+
18+
- [Removal of the deprecated `Signature` type. `PrimitiveSignature` is now aliased to `Signature`](https://github.com/alloy-rs/core/pull/899)
19+
- [Renaming methods in User-defined types (UDT)'s bindings and implementing `From` and `Into` traits for UDT's](https://github.com/alloy-rs/core/pull/905)
20+
- [Bumping `getrandom` and `rand`](https://github.com/alloy-rs/core/pull/869)
21+
- [Removal of `From<String>` for `Bytes`](https://github.com/alloy-rs/core/pull/907)
22+
23+
If you'd like to dive into the details of each change, please take a look at this [PR](https://github.com/alloy-rs/core/pull/895)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Simply ABI encoding and decoding
2+
3+
- [ABI encoding function return structs](./encoding-return-structs.md)
4+
- [Removing `validate: bool` from the `abi_decode` methods](./removing-validate-bool.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## Encoding return structs
2+
3+
[core#909](https://github.com/alloy-rs/core/pull/909) improves return type encoding by allowing to pass the return struct directly into `SolCall::abi_encode_returns`.
4+
5+
Consider the following:
6+
7+
```rust,ignore
8+
sol! {
9+
function something() returns (uint256, address);
10+
}
11+
```
12+
13+
### Before
14+
15+
A tuple would need to passed of the fields from return type, `somethingReturn`
16+
17+
```rust,ignore
18+
let encoding = somethingCall::abi_encode_returns(&(somethingReturn._0, somethingReturn._1));
19+
```
20+
21+
### After
22+
23+
One can now pass the return struct directly without deconstructing it as a tuple.
24+
25+
```rust,ignore
26+
let encoding = somethingCall::abi_encode_returns(&somethingReturn);
27+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Removing the `validate: bool` from the `abi_decode` methods
2+
3+
[core#863](https://github.com/alloy-rs/core/pull/863) removes the `validate: bool` parameter from the `abi_decode_*` methods. The behaviour of these `abi_decode_*` methods is now equivalent to passing `validate = false`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Other breaking changes
2+
3+
- [Removal of the deprecated `Signature` type. `PrimitiveSignature` is now aliased to `Signature`](https://github.com/alloy-rs/core/pull/899)
4+
- [Renaming methods in User-defined types (UDT)'s bindings and implementing `From` and `Into` traits for UDT's](https://github.com/alloy-rs/core/pull/905)
5+
- [Bumping `getrandom` and `rand`](https://github.com/alloy-rs/core/pull/869)
6+
- [Removal of `From<String>` for `Bytes`](https://github.com/alloy-rs/core/pull/907)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## sol! changes
2+
3+
- [Removing the `T` transport generic](./removing-T-generic.md)
4+
- [Improving function return type](./improving-function-return-types.md)
5+
- [Changes to function call bindings](./changes-to-function-call-bindings.md)
6+
- [Changes to event bindings](./changes-to-event-bindings.md)
7+
- [Changes to error bindings](./changes-to-error-bindings.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## Changes to error bindings
2+
3+
[core#883](https://github.com/alloy-rs/core/pull/883) makes similar changes to the error bindings that [core#884](https://github.com/alloy-rs/core/pull/884) did to function call bindings in the sense that the form of the generated type is dependent upon two factors:
4+
5+
1. Number of parameters the error has.
6+
2. Whether the parameter is named or unnamed in case it has only **one** param
7+
8+
Consider the following example:
9+
10+
```rust,ignore
11+
sol! {
12+
// No params/args
13+
error Some();
14+
// Exactly one unnamed param
15+
error Another(uint256);
16+
// Exactly one named param - bindings for this remain unchanged
17+
error YetAnother(uint256 a);
18+
}
19+
```
20+
21+
## Before
22+
23+
All of the above were generated as regular structs.
24+
25+
```rust,ignore
26+
// Empty struct
27+
pub struct SomeError { };
28+
29+
pub struct AnotherError {
30+
_0: U256
31+
}
32+
33+
pub struct YetAnotherError {
34+
a: U256
35+
}
36+
```
37+
38+
## After
39+
40+
```rust,ignore
41+
42+
// Unit struct for error with no params
43+
pub struct SomeError;
44+
45+
// Tuple struct for SINGLE UNNAMED param
46+
pub struct AnotherError(pub U256);
47+
```
48+
49+
Bindings remain **unchanged** for errors with **multiple params** and **single but named param**.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## Changes to event bindings
2+
3+
[core#885](https://github.com/alloy-rs/core/pull/885) makes changes to the event bindings in a breaking but very minimal way.
4+
It changes the bindings for **only** events with no parameters
5+
6+
Consider the following event:
7+
8+
```rust,ignore
9+
sol! {
10+
event Incremented();
11+
}
12+
```
13+
14+
### Before
15+
16+
The generated struct was an empty struct like below:
17+
18+
```rust,ignore
19+
pub struct Incremented { };
20+
```
21+
22+
### After
23+
24+
A unit struct is generated like below:
25+
26+
```rust,ignore
27+
pub struct Incremented;
28+
```
29+
30+
Bindings for events with parameters remain **unchanged**.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
## Changes to function call bindings
2+
3+
With [core#884](https://github.com/alloy-rs/core/pull/884) the form of the generated call type (used for abi-encoding) is now dependent upon two factors:
4+
5+
1. Number of parameters/args does the function take
6+
2. Whether the parameter is named or unnamed in case it has only **one** param
7+
8+
Consider the following:
9+
10+
```rust,ignore
11+
sol! {
12+
// No params/args
13+
function totalSupply() returns (uint256)
14+
// Exactly one unnamed param
15+
function balanceOf(address) returns (uint256);
16+
// Multiple params - Bindings for this remain unchanged.
17+
function approve(address spender, uint256 amount) returns (bool);
18+
}
19+
```
20+
21+
### Before
22+
23+
Generated bindings were independent of the number of parameters and names, and the following struct were generated for the above function calls
24+
25+
```rust,ignore
26+
// A struct with no fields as there are no parameters.
27+
pub struct totalSupplyCall { };
28+
let encoding = totalSupplyCall { }.abi_encode();
29+
30+
pub struct balanceOfCall { _0: Address };
31+
let encoding = balanceOfCall { _0: Address::ZERO }.abi_encode();
32+
```
33+
34+
### After
35+
36+
```rust,ignore
37+
// A unit struct is generated when there are no parameters.
38+
pub struct totalSupplyCall;
39+
let encoding = totalSupplyCall.abi_encode();
40+
41+
// A tuple struct with a single value is generated in case of a SINGLE UNNAMED param.
42+
pub struct balanceOfCall(pub Address);
43+
let encoding = balanceOfCall(Address::ZERO).abi_encode();
44+
```
45+
46+
Now if the parameter in `balanceOf` was named like so:
47+
48+
```rust,ignore
49+
sol! {
50+
function balanceOf(address owner) returns (uint256);
51+
}
52+
```
53+
54+
Then a regular struct would be generated like before:
55+
56+
```rust, ignore
57+
pub struct balanceOfCall { owner: Address };
58+
```
59+
60+
Bindings for function calls with **multiple parameters** are **unchanged**.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
## Improving function call return types
2+
3+
With the inclusion of [core#855](https://github.com/alloy-rs/core/pull/855) return values of function calls with a _singular_ value is more intuitive and easier to work with.
4+
5+
Consider the following example of reading the balance of an ERC20:
6+
7+
```rust,ignore
8+
sol! {
9+
#[sol(rpc)]
10+
contract ERC20 {
11+
// Note: Only a single value is being returned
12+
function balanceOf(address) returns (uint256);
13+
}
14+
}
15+
```
16+
17+
## Before
18+
19+
Calling the `balanceOf` fn would return a struct `balanceOfReturn` which encapsulated the actual balance value.
20+
21+
```rust,ignore
22+
// .. snip ..
23+
let balance_return: balanceOfReturn = erc20.balanceOf(owner).await?;
24+
25+
let actual_balance = balance_return._0;
26+
```
27+
28+
## After
29+
30+
Calling the `balanceOf` fn would now yield the balance directly instead of a struct wrapping it.
31+
32+
```rust,ignore
33+
// .. snip ..
34+
let balance: U256 = erc20.balanceOf(owner).await?;
35+
```
36+
37+
It is important to note that this change only applies to function calls that have a **singular** return value.
38+
39+
Function calls that **return multiple values** have their return types **unchanged**, i.e they still return a struct with values inside it.
40+
41+
```rust,ignore
42+
sol! {
43+
function multiValues() returns (uint256 a, address b, bytes c);
44+
}
45+
46+
// The above function call will have the following return type.
47+
48+
pub struct multiValuesReturn {
49+
pub a: U256,
50+
pub b: Address,
51+
pub c: Bytes,
52+
}
53+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Removing the `T` transport generic
2+
3+
Since [alloy#1859](https://github.com/alloy-rs/alloy/pull/1859) the `Provider` is independent of the `Transport`, making it easier to roll types that wrap the `Provider`. This improvement was reflected in the [`CallBuilder`](https://docs.rs/alloy-contract/latest/alloy_contract/struct.CallBuilder.html) type but not carried to the `sol!` macro bindings.
4+
5+
[core#865](https://github.com/alloy-rs/core/pull/865) removes the `T` transport generic from the `sol!` macro bindings, making the contract and RPC codegen cleaner.
6+
7+
This can be demonstrated using a simple example that wraps an `ERC20Instance` type.
8+
9+
### Before
10+
11+
```rust,ignore
12+
struct Erc20<P: Provider> {
13+
instance: ERC20Instance<(), P>,
14+
}
15+
```
16+
17+
### After
18+
19+
```rust,ignore
20+
struct Erc20<P: Provider> {
21+
instance: ERC20Instance<P>,
22+
}
23+
```

0 commit comments

Comments
 (0)