Skip to content

sahebdel7/sway-libs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 Docs Hub

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

Library 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.

Upgradability Libraries

  • Upgradability provides functions that can be used to implement contract upgrades via simple upgradable proxies.

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.22.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 Docs Hub

Running Tests

There are two sets of tests that should be run: inline tests and sdk-harness tests. Please make sure you are using forc v0.60.0 and fuel-core v0.26.0. You can check what version you are using by running the fuelup show command.

Make sure you are in the source directory of this repository sway-libs/<you are here>.

Run the inline tests:

forc test --path libs --release --locked

Once these tests have passed, run the sdk-harness tests:

forc test --path tests --release --locked && cargo test --manifest-path tests/Cargo.toml

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.60.0, fuels-rs v0.62.0 and fuel-core v0.26.0.

Contributing

Check out the contributing book for more info!

Releases

No releases published

Packages

No packages published

Languages

  • Sway 62.5%
  • Rust 37.5%