FuelLabs / sway-libs

Miscellaneous Sway libraries.

Home Page:https://fuellabs.github.io/sway-libs/book/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SwayLibs logo

Overview

The purpose of this repository is to contain libraries which users can import and use that are not part of the standard library.

These libraries contain helper functions and other tools valuable to blockchain development.

NOTE: Sway is a language under heavy development therefore the libraries may not be the most ergonomic. Over time they should receive updates / improvements in order to demonstrate how Sway can be used in real use cases.

Sway Libs Book

Please refer to the Sway Libs Book for documentation for a general overview on Sway Libs and how to implement libraries.

Sway Docs

For implementation details on the libraries please see the Sway Libs Docs.

Libraries

Assets

Access Control and Security

  • Ownership is used to apply restrictions on functions such that only a single user may call them.
  • Admin is used to apply restrictions on functions such that only a select few users may call them like a whitelist.
  • Pausable allows contracts to implement an emergency stop mechanism.
  • Reentrancy is used to detect and prevent reentrancy attacks.

Cryptography

  • Bytecode is used for on-chain verification and computation of bytecode roots for contracts and predicates.
  • Merkle Proof is used to verify Binary Merkle Trees computed off-chain.

Math

Data Structures

  • Queue is a linear data structure that provides First-In-First-Out (FIFO) operations.

Using a library

To import a library, the following dependency should be added to the project's Forc.toml file under [dependencies].

sway_libs = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.1.0" }

NOTE: Be sure to set the tag to the latest release.

You may then import your desired library in your Sway Smart Contract as so:

use sway_libs::<library>::<library_function>;

For example, to import the only_owner() function use the following statement:

use sway_libs::ownership::only_owner;

For more information about implementation please refer to the Sway Libs Book

Running Tests

There are two sets of tests that should be run: inline tests and sdk-harness tests.

In order to run the inline tests, make sure you are in the libs/ folder of this repository sway-libs/libs/<you are here>.

Run the tests:

forc test

Once these tests have passed, make sure you are in the tests/ folder of this repository sway-libs/tests/<you are here>.

Run the tests:

forc test && cargo test

NOTE: This may take a while depending on your hardware, future improvements to Sway will decrease build times. After this has been run once, individual test projects may be built on their own to save time.

Any instructions related to using a specific library should be found within the README.md of that library.

NOTE: All projects currently use forc v0.53.0, fuels-rs v0.53.0 and fuel-core 0.23.0.

Contributing

Check out the book for more info!

About

Miscellaneous Sway libraries.

https://fuellabs.github.io/sway-libs/book/index.html

License:Apache License 2.0


Languages

Language:Sway 62.0%Language:Rust 38.0%