High-performance, well-tested & documented core libraries for Ethereum, in Rust
APACHE-2.0 License
Bot releases are visible (Hide)
Published by DaniPopes about 1 year ago
syn-solidity
is now (almost) complete, as it can also parse all expression, statements, and Yul. Special thanks to @Will-Smith11, @mouseless-eth, and @0xMemoryGrinder! (#314, https://github.com/alloy-rs/core/issues/268, #199)alloy-json-abi
items (like Function
and Event
) can now be used in combination with alloy-dyn-abi
to ABI-encode their input or output parameters through JsonAbiExt
(#243)encode
, encode_single
and functions and their respectives in decode*
and SolType::*
were renamed to encode_sequence
and encode
respectively. *_params
functions remain unchanged (#274)encode
and decode
-like functions with abi_
; alloy-sol-types
ABI-related items were moved into the abi
module (#311)alloy-sol-type-parser
got 10% to 50% faster, but now rejects any whitespace (#292)slice::Iter
where possible by @DaniPopes in https://github.com/alloy-rs/core/pull/256
eip712_data_word
by @prestwich in https://github.com/alloy-rs/core/pull/258
Bytes
conversion impls by @DaniPopes in https://github.com/alloy-rs/core/pull/280
bytes::Buf
for our own Bytes
by @DaniPopes in https://github.com/alloy-rs/core/pull/279
FixedBytes
for sol_data::FixedBytes
by @DaniPopes in https://github.com/alloy-rs/core/pull/276
rand
by @DaniPopes in https://github.com/alloy-rs/core/pull/282
FixedBytes
to int conversion impls by @DaniPopes in https://github.com/alloy-rs/core/pull/281
Eip712Domain::encode_data
by @DaniPopes in https://github.com/alloy-rs/core/pull/277
SolError
, SolInterface
structs and implementations by @DaniPopes in https://github.com/alloy-rs/core/pull/285
all_derives = false
, fix custom type printing by @DaniPopes in https://github.com/alloy-rs/core/pull/272
Function
by @DaniPopes in https://github.com/alloy-rs/core/pull/290
Function::signature_full
by @DaniPopes in https://github.com/alloy-rs/core/pull/289
#[automatically_derived]
by @DaniPopes in https://github.com/alloy-rs/core/pull/294
winnow
by @DaniPopes in https://github.com/alloy-rs/core/pull/292
hex!
macro from primitives
re-export by @DaniPopes in https://github.com/alloy-rs/core/pull/299
ResolveSolType
documentation by @DaniPopes in https://github.com/alloy-rs/core/pull/296
Spanned
impls by @DaniPopes in https://github.com/alloy-rs/core/pull/301
decode_revert_reason
to alloy and add tests by @alessandromazza98 in https://github.com/alloy-rs/core/pull/308
abi_
by @DaniPopes in https://github.com/alloy-rs/core/pull/311
Full Changelog: https://github.com/alloy-rs/core/compare/v0.3.2...v0.4.0
Published by DaniPopes about 1 year ago
T: Into<Cow<str>>
in eip712_domain!
by @DaniPopes in https://github.com/alloy-rs/core/pull/222
B160
by @DaniPopes in https://github.com/alloy-rs/core/pull/235
FixedBytes<N>
<-> [u8; N]
conversions by @DaniPopes in https://github.com/alloy-rs/core/pull/239
type
field by @DaniPopes in https://github.com/alloy-rs/core/pull/233
Full Changelog: https://github.com/alloy-rs/core/compare/v0.3.1...v0.3.2
Published by prestwich about 1 year ago
ethabi
Contract methods by @andyrobert3 in https://github.com/alloy-rs/core/pull/195
Full Changelog: https://github.com/alloy-rs/core/compare/v0.3.0...v0.3.1
Published by DaniPopes about 1 year ago
alloy-rlp
and alloy-rlp-derive
are now maintained in a separate repository (https://github.com/alloy-rs/rlp), and as such may differ in versioningalloy-sol-type-parser
: A simple parser for Solidity type stringsalloy-dyn-abi
: Run-time ABI and EIP-712 implementationsalloy-json-abi
: JSON-ABI implementationdomain
macro and add more docs by @prestwich in https://github.com/alloy-rs/core/pull/147
dyn-abi
to performance parity with ethabi by @prestwich in https://github.com/alloy-rs/core/pull/144
SolEnum
and SolInterface
by @DaniPopes in https://github.com/alloy-rs/core/pull/153
#[sol]
attributes and JSON ABI support by @DaniPopes in https://github.com/alloy-rs/core/pull/173
ruint2
with ruint
by @DaniPopes in https://github.com/alloy-rs/core/pull/192
Full Changelog: https://github.com/alloy-rs/core/compare/v0.2.0...v0.3.0
Published by gakonst over 1 year ago
We’re excited to announce alloy-rs/core, a rewrite of the popular ethers-core package and the ethabi crate. Core offers:
syn
-powered Solidtiy parser, specifically designed for Rust procedural macros. It aims to mimic the behavior of the official Solidity compiler (Solc) when it comes to parsing valid Solidity code. This is a powerful abstraction which we leverage for building performant compile-time functionalities, like static ABI coders (see below).Here is a low-level example of how you can use these new primitives:
use alloy_primitives::Address;
use alloy_sol_types::{sol, SolType};
// Type definition: generates a new struct that implements `SolType`
sol! {
type MyType is uint256;
}
// Type aliases
type B32 = sol! { bytes32 };
// This is equivalent to the following:
// type B32 = alloy_sol_types::sol_data::Bytes<32>;
type SolArrayOf<T> = sol! { T[] };
type SolTuple = sol! { tuple(address, bytes, string) };
let _ = <sol!(bool)>::encode_single(&true);
let _ = B32::encode_single(&[0; 32]);
let _ = SolArrayOf::<sol!(bool)>::encode_single(&vec![true, false]);
let _ = SolTuple::encode_single(&(Address::ZERO, vec![0; 32], "hello".to_string()));
Here's a higher-level example, showing a roundtrip ABI encoding of an ERC20 transfer:
use alloy_primitives::{Address, U256};
use alloy_sol_types::{sol, SolCall};
use hex_literal::hex;
sol! {
#[derive(Debug, PartialEq)]
interface IERC20 {
function transfer(address to, uint256 amount) external returns (bool);
}
}
// random mainnet ERC20 transfer
// https://etherscan.io/tx/0x947332ff624b5092fb92e8f02cdbb8a50314e861a4b39c29a286b3b75432165e
let data = hex!(
"a9059cbb"
"0000000000000000000000008bc47be1e3abbaba182069c89d08a61fa6c2b292"
"0000000000000000000000000000000000000000000000000000000253c51700"
);
let expected = IERC20::transferCall {
to: Address::from(hex!("8bc47be1e3abbaba182069c89d08a61fa6c2b292")),
amount: U256::from(9995360000_u64),
};
assert_eq!(data[..4], IERC20::transferCall::SELECTOR);
let decoded = IERC20::IERC20Calls::decode(&data, true).unwrap();
assert_eq!(decoded, IERC20::IERC20Calls::transfer(expected));
assert_eq!(decoded.encode(), data);
Alloy is really powerful!
These crates will act as the solid foundation we’ve always wanted for Ethereum in Rust, informed by the lessons from our last 3 years of Rust Ethereum engineering. The code for these crates is under active development on github. We love new contributors. The pre-1.0.0 version of these crates are available on [crates.io](https://crates.
io/crates/alloy-primitives), and docs.rs.
primitives
by @prestwich in https://github.com/alloy-rs/core/pull/19
const-hex
instead of hex
by @DaniPopes in https://github.com/alloy-rs/core/pull/25
crates/*
by @DaniPopes in https://github.com/alloy-rs/core/pull/31
sol!
by @DaniPopes in https://github.com/alloy-rs/core/pull/53
sol!
AST and macro expansion by @DaniPopes in https://github.com/alloy-rs/core/pull/61
syn-solidity
by @DaniPopes in https://github.com/alloy-rs/core/pull/63
feature(doc_cfg, doc_auto_cfg)
by @DaniPopes in https://github.com/alloy-rs/core/pull/67
getrandom
, document in README.md by @DaniPopes in https://github.com/alloy-rs/core/pull/71
sol!
contracts by @DaniPopes in https://github.com/alloy-rs/core/pull/77
SolType
for {Ui,I}nt<N>
and FixedBytes<N>
with const-generics by @DaniPopes in https://github.com/alloy-rs/core/pull/92
repr(C)
to json-abi items by @DaniPopes in https://github.com/alloy-rs/core/pull/100
TokenType::is_dynamic
a constant by @DaniPopes in https://github.com/alloy-rs/core/pull/114
Encodable
trait by @prestwich in https://github.com/alloy-rs/core/pull/121
Full Changelog: https://github.com/alloy-rs/core/commits/v0.2.0
(This was going to be a v0.1.0 release, but we did an internal one first)