Code Monkey home page Code Monkey logo

core's Introduction

Alloy

Core libraries at the root of the Rust Ethereum ecosystem.

Alloy is a rewrite of ethers-rs from the ground up, with exciting new features, high performance, and excellent docs.

We have a book on all things Alloy and many examples to help you get started.

ethers-rs will continue to be maintained until we have achieved feature-parity in Alloy. No action is currently needed from devs.

Build Status Telegram chat

Overview

This repository contains the following crates:

Supported Rust Versions (MSRV)

The current MSRV (minimum supported rust version) is 1.65.

Alloy will keep a rolling MSRV policy of at least two versions behind the latest stable release (so if the latest stable release is 1.58, we would support 1.56).

Note that the MSRV is not increased automatically, and only as part of a patch (pre-1.0) or minor (post-1.0) release.

Contributing

Thanks for your help improving the project! We are so happy to have you! We have a contributing guide to help you get involved in the Alloy project.

Pull requests will not be merged unless CI passes, so please ensure that your contribution follows the linting rules and passes clippy.

WASM support

We provide full support for all the wasm*-* targets. If a crate does not build on a WASM target, please open an issue.

When building for the wasm32-unknown-unknown target and the "getrandom" feature is enabled, compilation for the getrandom crate will fail. This is expected: see their documentation for more details.

To fix this, either disable the "getrandom" feature on alloy-core or add getrandom to your dependencies with the "js" feature enabled:

getrandom = { version = "0.2", features = ["js"] }

There is currently no plan to provide an official JS/TS-accessible library interface, as we believe viem or ethers.js serve that need very well.

Note on no_std

All crates in this workspace should support no_std environments, with the alloc crate. If you find a crate that does not support no_std, please open an issue.

Credits

None of these crates would have been possible without the great work done in:

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in these crates by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

core's People

Contributors

0xmemorygrinder avatar andyrobert3 avatar bernard-wagner avatar blombern avatar cool-mestorf avatar danipopes avatar emperororokusaki avatar evalir avatar gakonst avatar huyhduong1401 avatar jafar75 avatar klkvr avatar kpp avatar mattsse avatar michprev avatar moh-eulith avatar mouseless-eth avatar niansol avatar onbjerg avatar prestwich avatar quentinv72 avatar rachel-bousfield avatar rodrigoherrerai avatar shawnharmsen avatar supernovahs avatar tcoratger avatar will-smith11 avatar wollac avatar yash-atreya avatar zerosnacks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

core's Issues

Pre-publication TODOs

Blockers

  • License review
  • #13
  • Finalize crate names
  • #14
  • Docs review
  • #29
  • port any upstream (reth) rlp changes
  • #30
  • #32
  • depend on main ruint
  • rename crates to final names below

pre-pub actions

  • grab names on crates.io

pub

  • release ethers-rlp to crates.io

Post pub

  • #12
  • ethers-rlp support in official ruint
  • migrate to official ruint (blocks primitives publishing)

[Feature] Add a borrowed `JsonAbi`

Component

json-abi

Describe the feature you would like

Add a borrowed version of all json-abi types, which implement ToOwned. Ideally methods are implemented only once, with the owned version implementing Deref towards the borrowed type, but this might not be fully doable.

This might also allow declaring the entire ABI as a const/static by setting the lifetime to 'static.

Additional context

Refs: #136

Add `Address` to primitives

  • Add address to primitives
    • parsing w/ and w/o checksum
    • hexification w/ and w/o checksum
  • Update ABI crates to use Address instead of B160

Consider: should we introduce a borrow abstraction for sol type encodable

          > But we're cloning the data to get the inner tuple, so this is not ideal

I'm gonna think about this a bit more. what do you think of this:

trait SolType {

    type BorrowAbstraction: From<Self::RustType>;

    fn encode<T: Into<Self::BorrowAbstraction>>(t: T)

}

pub enum TupleBorrowAbstraction<'t, 'u, T, U> {
    Owned((T,U)),
    Borrowed(&'t (T, U)),
    MembersBorrowed((&'t T, &'u U))
}

// From impls here

Originally posted by @prestwich in #83 (comment)

Improve `dyn-abi` encoding performance

Benchmark from #57, as of commit 64bf519:

ethabi/encode/single    time:   [82.202 ns 82.358 ns 82.525 ns]                                 
ethabi/encode/struct    time:   [164.10 ns 165.43 ns 166.85 ns]                                 

ethabi/decode/word      time:   [34.678 ns 34.765 ns 34.861 ns]                                
ethabi/decode/dynamic   time:   [78.638 ns 78.759 ns 78.910 ns]                                  

dyn-abi/encode/single   time:   [68.373 ns 68.550 ns 68.741 ns]                                  
dyn-abi/encode/struct   time:   [683.96 ns 684.70 ns 685.52 ns]                                   

dyn-abi/decode/word     time:   [54.141 ns 54.203 ns 54.266 ns]                                
dyn-abi/decode/dynamic  time:   [80.822 ns 80.932 ns 81.053 ns]                                   

sol-types/encode/single time:   [42.843 ns 43.007 ns 43.207 ns]                                     
sol-types/encode/struct time:   [49.110 ns 49.171 ns 49.235 ns]                                    

sol-types/decode/word   time:   [1.3375 ns 1.3389 ns 1.3405 ns]                                   
sol-types/decode/dynamic                                                                             
                        time:   [39.279 ns 39.478 ns 39.721 ns]

Maybe we can skip tokenizing by encoding directly the DynSolValue? Looking at the "struct" bench, ethabi is much more concise because of ethabi::encode(tokens: &[ethabi::Token]), while dyn-abi has to declare all the types, and then also clone the input on each call.

Originally posted by @DaniPopes in #57 (comment)

[Bug] (U)Int tokenization broken for types with odd bit lengths

Component

sol-type

What version of Alloy are you on?

No response

Operating System

macOS (Apple Silicon)

Describe the bug

(de)Tokenization logic does not properly handle ints whose length is different from the rust type's length. causes panic in the copy_from_slice in the macro

    #[test]
    fn tokenizing_int_sizes() {
        Uint::<24>::tokenize(&1u32);

        let word: [u8; 32] = (0..32).collect::<Vec<u8>>().try_into().unwrap();
        let word: WordToken = word.into();

        assert_eq!(Uint::<24>::detokenize(word), 126495);
    }```

[Bug] Cant decode Solidity calls to functions with no arguments

Component

sol! macro

What version of Alloy are you on?

v0.2.0

Operating System

Linux

Describe the bug

I think the problem is related to deposit taking in no arguments.

use alloy_sol_types::{sol, SolCall};

sol! {
    interface WETH {
        function deposit() external payable;
    }
}

fn main() {
    WETH::depositCall::decode(&WETH::depositCall::SELECTOR, true).expect("it should work");
}

Support generating `sol!` from ABI JSON

Needs #72.

  • Add inner attributes to File
    • Parse #[sol(...)] attributes, maybe #![sol(include = "path/to/abi.json")]
  • Parse included JSON string as dynamic JSON ABI
  • Generate a Solidity interface string
  • Parse Solidity interface string into a TokenStream, and call sol

Add `ParamKind` to json-abi `{,Event}Param`

currently the type field is unparsed, while ethabi users expect a parsed ParamKind enum. This would also remove the intermediate enum between the {Simple,Complex} structs

[Feature] Convenient way to decode a contract error

Component

sol-type, sol! macro

Describe the feature you would like

Currently we generate a ContractErrors enum, which is fine for custom errors but cannot be used to also decode Solidity panics and reverts.
We should provide some way to easily decode all of the above in one method

Additional context

No response

Incorrect size expression when expanding arrays containing dynamic types

type_data_size multiples array length by inner_size, which will incorrectly calculate lengths and incorrectly inner_size expressions.

https://github.com/alloy-rs/core/blob/main/crates/sol-macro/src/expand/type.rs#L159-L179

blocker for #85

current behavior:

    struct Foo {
        address[] baz;
    }

    /// Nested struct.
    struct Nested {
        Foo[2] a;
    }

produces code like this:

            0usize
                + 2usize * (0usize + 32usize + 64usize + self.a.baz.len() * (32usize))

correct behavior:

            0usize
                + self.a.iter().map( |element| /* inner size expression for element */ ).sum::<usize>()

2 incorrect things:

  • assumes all array elements of Foo.a are the same size
  • because there's no iteration, it does not index `self.a[0].baz.len()'

both of these would be resolved using an iter in the expansion

Support Fallback and Receive as special functions in sol-types

          I think this can be done in another PR, since we don't handle any type of function (constructor, fallback...) other than literally `function`

Originally posted by @DaniPopes in #153 (comment)

Similar to the way error & panic are included in the base lib, we should consider including fallback and receive as hard-coded types. This requires special handling, as they have no selector

[Bug] update type_system.md

Component

No response

What version of Alloy are you on?

No response

Operating System

None

Describe the bug

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.