4 stable releases

Uses new Rust 2021

2.2.0 Jul 23, 2022
2.1.0 Jun 23, 2022
2.0.0 Jun 2, 2022
1.8.0 May 27, 2022

#1807 in Magic Beans

Download history 27/week @ 2022-05-26 51/week @ 2022-06-02 6/week @ 2022-06-09 27/week @ 2022-06-16 57/week @ 2022-06-23 17/week @ 2022-06-30 26/week @ 2022-07-07 15/week @ 2022-07-14 71/week @ 2022-07-21 35/week @ 2022-07-28 45/week @ 2022-08-04

172 downloads per month
Used in 3 crates

MIT license

52KB
903 lines

logo-2

Docs telegram chat element chat discord chat

Our mission with this project is to make ink! development faster, safer and easier.

Talk to us on Element in the OpenBrush channel

Summary

OpenBrush is a library for smart contract development on ink!.

Why use this library?

  • To make contracts interoperable to do safe cross-contracts calls (by having the same functions signature among every contracts)
  • To ensure the usage of Polkadot Standards Proposals [WIP]
  • To ensure the usage of the latest & most secure implementation
  • Useful contracts that provide custom logic to be implemented in contracts
  • To save time by not writing boilerplate code
  • Useful features which can simplify development

Which Standard tokens & useful contracts does it provide?

  • PSP22 - Fungible Token (ERC20 equivalent) with extensions
  • PSP34 - Non-Fungible Token (ERC721 equivalent) with extensions
  • Multi-Token ERC1155 equivalent with extensions
  • Ownable Restrict access to action for non-owners
  • Access Control Define set of roles and restrict access to action by roles
  • Reentrancy guard Prevent reentrant calls to a function
  • Pausable Pause/Unpause the contract to disable/enable some operations
  • Timelock Controller Execute transactions with some delay
  • Payment Splitter Split amount of native tokens between participants

Modifiers

Solidity smart contracts provides modifiers to restrain function call to certain pre-defined parameters. OpenBrush provides attribute macros to use standardised modifiers. You can use our useful contracts to use as modifiers, or define your own modifiers.

// Before execution of `mint` method, `only_owner` should verify that caller is the owner.
#[ink(message)]
#[modifiers(only_owner)]
fn mint(&mut self, ids_amounts: Vec<(Id, Balance)>) -> Result<(), PSP1155Error> {
  self._mint_to(Self::env().caller(), ids_amounts)
}

Wrapper around traits

You are enough to have a trait definition (you don't need directly a contract that implements that trait) to call methods of that trait from some contract in the network (do a cross contract call).

#[brush::trait_definition]
pub trait Trait1 {
    #[ink(message)]
    fn foo(&mut self) -> bool;
}

#[brush::wrapper]
type Trait1Ref = dyn Trait1;

{
    // It should be `AccountId` of some contract in the network
    let callee: brush::traits::AccountId = [1; 32].into();
    // This code will execute a cross contract call to `callee` contract
    let result_of_foo: bool = Trait1Ref::foo(&callee);
}

How to use it?

Read our documentation in doc.

Go through our examples in examples

Not sure where to start? Use the interactive generator to bootstrap your contract and learn about the components offered in OpenBrush.

Events

‼️ Important ‼️

Events are not supported currently due to how ink! currently handles them.
The identifiers of events must be based on the name of the trait. At the moment, ink! doesn't support it, but it must be fixed with this issue.

Issues to be resolved before the library becomes production-ready:

Other Issues open:

All contracts are upgradable by default. It will be refactored after Storage rework in ink!.

Roadmap 🚗

------- Release 0.1.0

  • Implement fungible, non-fungible, and multi tokens.
  • Implement AccessControl and Ownable.
  • Add examples of how to reuse ERC20, ERC721, AccessControl implementations.
  • Stub implementations for token and access folders.
  • Add base description of project

------- Release 0.2.0

  • Remove the boilerplate to make the internal implementation external.
    • Implement brush::contract macro to consume all brush's stuff before ink!.
    • Implement brush::trait_definition which stores definition of trait and allow to use it in brush::contract macro.
    • Implement impl_trait! macro which reuse internal implementation in external impl section.
  • Refactor examples and tests with new macros.
  • Decide how to handle errors and implement it in library (Decided to use panic! and assert!).

------- Release 0.3.0

  • Create derive macro for storage traits. This macro must adds fields to contract's struct.
  • Cover all contracts with unit tests and integration tests.
  • Create documentation based on readme. Add comments to macros with example of usage.
  • Add Ownable + ERC1155 example.
  • Support simple modifiers (which can only call functions without code injection).
  • Instead of impl_trait! macro add support of default implementation in external trait definition.

------- Release 1.0.0

  • Add Pausable, TimelockController and PaymentSplitter contracts.
  • Support code injection in modifiers.
  • Implement a reentrancy guard and example of usage.
  • Add more examples and documentation on how to use the library.

------- Pre-release 2.0.0

  • Finalize PSP for fungible tokens. Refactor of implementation.
  • Agnostic traits.
  • Wrapper around the trait definition to do a cross-contract calls.
  • PSPs for NFT and multi-token.
  • Add extension: ERC721Enumerable.
  • Add extension: AccessControlEnumerable.
  • Refactor NFT and multi-token according to final decisions in PSPs.

------- Release 2.0.0 - Production ready

  • Force/help ink! to create new independent events. During this task decide how ink! can generate metadata for events/traits from other crates.
  • Cover everything with UT and integration tests.
  • More documentation and examples.
  • Audit.

------- Release 3.0.0

  • All extensions for tokens.
  • Improve ink! to allow code injection to have default implementation on ink! level instead Rust level.
  • Refactor the library according to new changes.

------- Release 4.0.0

  • Add support of upgradable contracts to ink!/contract-pallet level.
  • Implement Proxy pattern.
  • Implement Diamond standard.

Installation & Testing

To work with project you need to install ink! toolchain and NodeJS's dependencies.

Build

$ yarn build

If you want to build in release mode, you can use this command

$ yarn build:release

Tests

You can run unit tests by RUSTFLAGS="-D warnings" cargo test --all-features --workspace -- --test-threads=10 command from the root of the directory.

To run integration test you need to start the node with contract-pallet.

After you can run tests by yarn run test command. It will build all contracts required for integration tests and run them.

History behind

FAQ

Was it audited?

Contracts in this repository have not yet been audited. ink! will have soon several major changes, so it does not make sense to audit it now. ink! is not ready for production at the moment. It requires resolving some issues.

After that, we plan to do an audit.

License

OpenBrush is released under the MIT License.

Dependencies

~12MB
~141K SLoC