Skip to content

Commit

Permalink
Release v0.23.0 (#280)
Browse files Browse the repository at this point in the history
## [v0.23.0]

### Added

- [#259](#259) Adds a new
upgradability library, including associated tests and documentation.
- [#265](#265) Adds the
`SetMetadataEvent` and emits `SetMetadataEvent` when the
`_set_metadata()` function is called.
- [#270](#270) Adds `OrdEq`
functionality to Signed Integers.
- [#272](#272) Adds the
`TryFrom` implementation from signed integers to unsigned integers.

### Changed

- [#265](#265) Enables the
metadata events now that the Rust SDK supports wrapped heap types.
- [#269](#269) Hashes the
string "admin" and with the bits of an Identity when creating a storage
slot to storage an admin in the Admin Library.
- [#276](#276) Prepares for
v0.23.0 release.
- [#278](#278) Deprecates the
Fixed Point number library.

### Fixed

- [#258](#258) Fixes incorrect
instructions on how to run tests in README and docs hub.
- [#262](#262) Fixes incorrect
ordering comparison for IFP64, IFP128 and IFP256.
- [#263](#263) Fixes `I256`'s
returned bits.
- [#263](#263) Fixes `I128`
and `I256`'s zero or "indent" value.
- [#268](#268) Fixes
subtraction involving negative numbers for `I8`, `I16`, `I32`, `I64`,
`I128`, and `I256`.
- [#272](#272) Fixes `From`
implementations for Signed Integers with `TryFrom`.
- [#273](#273) Fixes negative
from implementations for Signed Integers.
- [#274](#274) Fixes the
`swap_configurables()` function to correctly handle the case where the
bytecode is too large to fit in the buffer.
- [#275](#275) Fixes an
infinite loop in the Bytecode root library's `_compute_bytecode_root()`
function.

#### Breaking

- [#263](#263) Removes the
`TwosComplement` trait in favor of `WrappingNeg`.

The following demonstrates the breaking change. While this example code
uses the `I8` type, the same logic may be applied to the `I16`, `I32`,
`I64`, `I128`, and `I256` types.

Before:

```sway
let my_i8 = i8::zero();
let twos_complement = my_i8.twos_complement();
```

After:

```sway
let my_i8 = i8::zero();
let wrapping_neg = my_i8.wrapping_neg();
```

- [#272](#272) The `From`
implementation for all signed integers to their respective unsigned
integer has been removed. The `TryFrom` implementation has been added in
its place.

Before:

```sway
let my_i8: I8 = I8::from(1u8);
```

After:

```sway
let my_i8: I8 = I8::try_from(1u8).unwrap();
```

- [#273](#273) The `neg_from`
implementation for all signed integers has been removed. The
`neg_try_from()` implementation has been added in its place.

The following demonstrates the breaking change. While this example code
uses the `I8` type, the same logic may be applied to the `I16`, `I32`,
`I64`, `I128`, and `I256` types.

Before:

```sway
let my_negative_i8: I8 = I8::neg_from(1u8);
```

After:

```sway
let my_negative_i8: I8 = I8::neg_try_from(1u8).unwrap();
```

- [#278](#278) Deprecates the
Fixed Point number library. The Fixed Point number library is no longer
available.

---------

Co-authored-by: K1-R1 <[email protected]>
Co-authored-by: SwayStar123 <[email protected]>
  • Loading branch information
3 people authored Aug 1, 2024
1 parent 172adbb commit 9987d8a
Show file tree
Hide file tree
Showing 241 changed files with 3,662 additions and 6,057 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @FuelLabs/application-dev
* @FuelLabs/swayex
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ Closes #\<issue number\>
- [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant.
- [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.
- [ ] I have updated the changelog to reflect the changes on this PR.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ jobs:
run: cargo fmt --manifest-path tests/Cargo.toml --verbose --check

- name: Build All Libs
run: forc build --path libs --release
run: forc build --path libs --release --locked

- name: Build All Tests
run: forc build --path tests --release
run: forc build --path tests --release --locked

- name: Cargo Test sway-lib
run: |
Expand All @@ -78,10 +78,10 @@ jobs:
components: forc@${{ env.FORC_VERSION }}, fuel-core@${{ env.CORE_VERSION }}

- name: Run Libs Tests
run: forc build --path libs --release && forc test --path libs
run: forc build --path libs --release --locked && forc test --path libs --locked

- name: Run Tests Tests
run: forc build --path tests --release && forc test --path tests
run: forc build --path tests --release --locked && forc test --path tests --locked

contributing-book:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -165,7 +165,7 @@ jobs:
run: cargo fmt --manifest-path examples/Cargo.toml --verbose --check

- name: Build All Examples
run: forc build --path examples --release
run: forc build --path examples --release --locked

- name: Cargo Test Examples
run: |
Expand Down
20 changes: 0 additions & 20 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,6 @@ jobs:
destination_dir: contributing-book
if: github.ref == 'refs/heads/master'

deploy-book:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Setup mdBook
uses: peaceiris/actions-mdbook@v1
with:
mdbook-version: "0.4.15"

- run: mdbook build ./docs/book

- name: Deploy master
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/book/book
destination_dir: book
if: github.ref == 'refs/heads/master'

deploy-forc-doc-sway-libs:
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
Forc.lock

# These are backup files generated by rustfmt
**/*.rs.bk
Expand Down
86 changes: 86 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Change Log

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [v0.23.0]

### Added

- [#259](https://github.com/FuelLabs/sway-libs/pull/259) Adds a new upgradability library, including associated tests and documentation.
- [#265](https://github.com/FuelLabs/sway-libs/pull/265) Adds the `SetMetadataEvent` and emits `SetMetadataEvent` when the `_set_metadata()` function is called.
- [#270](https://github.com/FuelLabs/sway-libs/pull/270) Adds `OrdEq` functionality to Signed Integers.
- [#272](https://github.com/FuelLabs/sway-libs/pull/272) Adds the `TryFrom` implementation from signed integers to unsigned integers.

### Changed

- [#265](https://github.com/FuelLabs/sway-libs/pull/265) Enables the metadata events now that the Rust SDK supports wrapped heap types.
- [#269](https://github.com/FuelLabs/sway-libs/pull/269) Hashes the string "admin" and with the bits of an Identity when creating a storage slot to storage an admin in the Admin Library.
- [#276](https://github.com/FuelLabs/sway-libs/pull/276) Prepares for v0.23.0 release.
- [#278](https://github.com/FuelLabs/sway-libs/pull/278) Deprecates the Fixed Point number library.

### Fixed

- [#258](https://github.com/FuelLabs/sway-libs/pull/258) Fixes incorrect instructions on how to run tests in README and docs hub.
- [#262](https://github.com/FuelLabs/sway-libs/pull/262) Fixes incorrect ordering comparison for IFP64, IFP128 and IFP256.
- [#263](https://github.com/FuelLabs/sway-libs/pull/263) Fixes `I256`'s returned bits.
- [#263](https://github.com/FuelLabs/sway-libs/pull/263) Fixes `I128` and `I256`'s zero or "indent" value.
- [#268](https://github.com/FuelLabs/sway-libs/pull/268) Fixes subtraction involving negative numbers for `I8`, `I16`, `I32`, `I64`, `I128`, and `I256`.
- [#272](https://github.com/FuelLabs/sway-libs/pull/272) Fixes `From` implementations for Signed Integers with `TryFrom`.
- [#273](https://github.com/FuelLabs/sway-libs/pull/273) Fixes negative from implementations for Signed Integers.
- [#274](https://github.com/FuelLabs/sway-libs/pull/274) Fixes the `swap_configurables()` function to correctly handle the case where the bytecode is too large to fit in the buffer.
- [#275](https://github.com/FuelLabs/sway-libs/pull/275) Fixes an infinite loop in the Bytecode root library's `_compute_bytecode_root()` function.

#### Breaking

- [#263](https://github.com/FuelLabs/sway-libs/pull/263) Removes the `TwosComplement` trait in favor of `WrappingNeg`.

The following demonstrates the breaking change. While this example code uses the `I8` type, the same logic may be applied to the `I16`, `I32`, `I64`, `I128`, and `I256` types.

Before:

```sway
let my_i8 = i8::zero();
let twos_complement = my_i8.twos_complement();
```

After:

```sway
let my_i8 = i8::zero();
let wrapping_neg = my_i8.wrapping_neg();
```

- [#272](https://github.com/FuelLabs/sway-libs/pull/272) The `From` implementation for all signed integers to their respective unsigned integer has been removed. The `TryFrom` implementation has been added in its place.

Before:

```sway
let my_i8: I8 = I8::from(1u8);
```

After:

```sway
let my_i8: I8 = I8::try_from(1u8).unwrap();
```

- [#273](https://github.com/FuelLabs/sway-libs/pull/273) The `neg_from` implementation for all signed integers has been removed. The `neg_try_from()` implementation has been added in its place.

The following demonstrates the breaking change. While this example code uses the `I8` type, the same logic may be applied to the `I16`, `I32`, `I64`, `I128`, and `I256` types.

Before:

```sway
let my_negative_i8: I8 = I8::neg_from(1u8);
```

After:

```sway
let my_negative_i8: I8 = I8::neg_try_from(1u8).unwrap();
```

- [#278](https://github.com/FuelLabs/sway-libs/pull/278) Deprecates the Fixed Point number library. The Fixed Point number library is no longer available.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[package]
name = "sway-libs"
version = "0.22.0"
version = "0.23.0"
edition = "2021"
58 changes: 31 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,57 +22,63 @@

## Overview

The purpose of this repository is to contain libraries which users can import and use that are not part of the standard library.
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
## Sway Libs Docs Hub

Please refer to the [Sway Libs Book](https://fuellabs.github.io/sway-libs/book/index.html) for documentation for a general overview on Sway Libs and how to implement libraries.
Please refer to the [Sway Libs Docs Hub](https://docs.fuel.network/docs/sway-libs/) for documentation for a general overview on Sway Libs and how to implement libraries.

## Sway Docs
## Library Docs

For implementation details on the libraries please see the [Sway Libs Docs](https://fuellabs.github.io/sway-libs/master/sway_libs/).

## Libraries

#### Assets

- [Native Asset](https://fuellabs.github.io/sway-libs/book/asset/index.html) provides helper functions for the [SRC-20](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-20.md), [SRC-3](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-3.md), and [SRC-7](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-7.md) standards.
- [Native Asset](https://docs.fuel.network/docs/sway-libs/asset/) provides helper functions for the [SRC-20](https://docs.fuel.network/docs/sway-standards/src-20-native-asset/), [SRC-3](https://docs.fuel.network/docs/sway-standards/src-3-minting-and-burning/), and [SRC-7](https://docs.fuel.network/docs/sway-standards/src-7-asset-metadata/) standards.

#### Access Control and Security

- [Ownership](https://fuellabs.github.io/sway-libs/book/ownership/index.html) is used to apply restrictions on functions such that only a **single** user may call them.
- [Admin](https://fuellabs.github.io/sway-libs/book/admin/index.html) is used to apply restrictions on functions such that only a select few users may call them like a whitelist.
- [Pausable](https://fuellabs.github.io/sway-libs/book/pausable/index.html) allows contracts to implement an emergency stop mechanism.
- [Reentrancy](https://fuellabs.github.io/sway-libs/book/reentrancy/index.html) is used to detect and prevent reentrancy attacks.
- [Ownership](https://docs.fuel.network/docs/sway-libs/ownership/) is used to apply restrictions on functions such that only a **single** user may call them.
- [Admin](https://docs.fuel.network/docs/sway-libs/admin/) is used to apply restrictions on functions such that only a select few users may call them like a whitelist.
- [Pausable](https://docs.fuel.network/docs/sway-libs/pausable/) allows contracts to implement an emergency stop mechanism.
- [Reentrancy](https://docs.fuel.network/docs/sway-libs/reentrancy/) is used to detect and prevent reentrancy attacks.

#### Cryptography

- [Bytecode](https://fuellabs.github.io/sway-libs/book/bytecode/index.html) is used for on-chain verification and computation of bytecode roots for contracts and predicates.
- [Merkle Proof](https://fuellabs.github.io/sway-libs/book/merkle/index.html) is used to verify Binary Merkle Trees computed off-chain.
- [Bytecode](https://docs.fuel.network/docs/sway-libs/bytecode/) is used for on-chain verification and computation of bytecode roots for contracts and predicates.
- [Merkle Proof](https://docs.fuel.network/docs/sway-libs/merkle/) is used to verify Binary Merkle Trees computed off-chain.

#### Math

- [Fixed Point Number](https://fuellabs.github.io/sway-libs/book/fixed_point/index.html) is an interface to implement fixed-point numbers.
- [Signed Integers](https://fuellabs.github.io/sway-libs/book/signed_integers/index.html) is an interface to implement signed integers.
- [Signed Integers](https://docs.fuel.network/docs/sway-libs/queue/) is an interface to implement signed integers.

> **NOTE:**
> The Fixed Point Number library has been deprecated pending a re-write.
#### Data Structures

- [Queue](https://fuellabs.github.io/sway-libs/book/queue/index.html) is a linear data structure that provides First-In-First-Out (FIFO) operations.
- [Queue](https://docs.fuel.network/docs/sway-libs/queue/) is a linear data structure that provides First-In-First-Out (FIFO) operations.

## Upgradability Libraries

- [Upgradability](https://docs.fuel.network/docs/sway-libs/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]`.

```rust
sway_libs = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.22.0" }
sway_libs = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.23.0" }
```

> **NOTE:**
> **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:
Expand All @@ -87,26 +93,24 @@ 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](https://fuellabs.github.io/sway-libs/book/index.html)
For more information about implementation please refer to the [Sway Libs Docs Hub](https://docs.fuel.network/docs/sway-libs/)

## Running Tests

There are two sets of tests that should be run: inline tests and sdk-harness 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.

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

Run the tests:
Run the inline tests:

```bash
forc test
forc test --path libs --release --locked
```

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:
Once these tests have passed, run the sdk-harness tests:

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

> **NOTE:**
Expand All @@ -115,8 +119,8 @@ forc test && cargo test
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 0.26.0`.
> All projects currently use `forc v0.60.0`, `fuels-rs v0.62.0` and `fuel-core v0.26.0`.
## Contributing

Check out the [book](https://fuellabs.github.io/sway-libs/contributing-book/index.html) for more info!
Check out the [contributing book](https://fuellabs.github.io/sway-libs/contributing-book/index.html) for more info!
4 changes: 3 additions & 1 deletion docs/book/spell-check-custom-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,6 @@ Enqueuing
Dequeuing
StorageMetadata
functionly
verifiably
verifiably
upgradable
upgradability
3 changes: 1 addition & 2 deletions docs/book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

- [Getting Started](./getting_started/index.md)
- [Running Tests](./getting_started/running_tests.md)
- [Libraries Overview](./libraries.md)
- [Asset Library](./asset/index.md)
- [Base](./asset/base.md)
- [Supply](./asset/supply.md)
Expand All @@ -15,6 +14,6 @@
- [Reentrancy Guard Library](./reentrancy/index.md)
- [Bytecode Library](./bytecode/index.md)
- [Merkle Library](./merkle/index.md)
- [Fixed Point Number Library](./fixed_point/index.md)
- [Signed Integers Library](./signed_integers/index.md)
- [Queue Library](./queue/index.md)
- [Upgradability](./upgradability/index.md)
12 changes: 6 additions & 6 deletions docs/book/src/asset/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ For implementation details on the Asset Library base functionality please see th

## Importing the Asset Library Base Functionality

In order to use the Asset Library, Sway Libs and [Sway Standards](https://github.com/FuelLabs/sway-standards) must be added to the `Forc.toml` file and then imported into your Sway project. To add Sway Libs as a dependency to the `Forc.toml` file in your project please see the [Getting Started](../getting_started/index.md). To add Sway Standards as a dependency please see the [Sway Standards Book](https://github.com/FuelLabs/sway-standards).
In order to use the Asset Library, Sway Libs and [Sway Standards](https://docs.fuel.network/docs/sway-standards/) must be added to the `Forc.toml` file and then imported into your Sway project. To add Sway Libs as a dependency to the `Forc.toml` file in your project please see the [Getting Started](../getting_started/index.md). To add Sway Standards as a dependency please see the [Sway Standards Book](https://docs.fuel.network/docs/sway-standards/#using-a-standard).

To import the Asset Library Base Functionality and [SRC-20](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-20.md) Standard to your Sway Smart Contract, add the following to your Sway file:
To import the Asset Library Base Functionality and [SRC-20](https://docs.fuel.network/docs/sway-standards/src-20-native-asset/) Standard to your Sway Smart Contract, add the following to your Sway file:

```sway
{{#include ../../../../examples/asset/base_docs/src/main.sw:import}}
```

## Integration with the SRC-20 Standard

The [SRC-20](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-20.md) definition states that the following abi implementation is required for any Native Asset on Fuel:
The [SRC-20](https://docs.fuel.network/docs/sway-standards/src-20-native-asset/) definition states that the following abi implementation is required for any Native Asset on Fuel:

```sway
{{#include ../../../../examples/asset/base_docs/src/main.sw:src20_abi}}
Expand All @@ -28,7 +28,7 @@ The Asset Library has the following complimentary functions for each function in
- `_symbol()`
- `_decimals()`

The following ABI and functions are also provided to set your [SRC-20](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-20.md) standard storage values:
The following ABI and functions are also provided to set your [SRC-20](https://docs.fuel.network/docs/sway-standards/src-20-native-asset/) standard storage values:

```sway
{{#include ../../../../examples/asset/base_docs/src/main.sw:set_attributes}}
Expand All @@ -42,15 +42,15 @@ The following ABI and functions are also provided to set your [SRC-20](https://g
## Setting Up Storage

Once imported, the Asset Library's base functionality should be available. To use them, be sure to add the storage block bellow to your contract which enables the [SRC-20](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-20.md) standard.
Once imported, the Asset Library's base functionality should be available. To use them, be sure to add the storage block bellow to your contract which enables the [SRC-20](https://docs.fuel.network/docs/sway-standards/src-20-native-asset/) standard.

```sway
{{#include ../../../../examples/asset/base_docs/src/main.sw:src20_storage}}
```

## Implementing the SRC-20 Standard with the Asset Library

To use the Asset Library's base functionly, simply pass the `StorageKey` from the prescribed storage block. The example below shows the implementation of the [SRC-20](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-20.md) standard in combination with the Asset Library with no user defined restrictions or custom functionality.
To use the Asset Library's base functionly, simply pass the `StorageKey` from the prescribed storage block. The example below shows the implementation of the [SRC-20](https://docs.fuel.network/docs/sway-standards/src-20-native-asset/) standard in combination with the Asset Library with no user defined restrictions or custom functionality.

```sway
{{#include ../../../../examples/asset/basic_src20/src/main.sw:basic_src20}}
Expand Down
Loading

0 comments on commit 9987d8a

Please sign in to comment.