Skip to content

Commit

Permalink
Add SRC-7 helper functions (#194)
Browse files Browse the repository at this point in the history
## Type of change

<!--Delete points that do not apply-->

- New feature

## Changes

The following changes have been made:

- Splits the single file into multiple files and groups functions by
standard
- Adds helper functions for the `Metadata` type of the SRC-7 standard

## Notes

- This will require FuelLabs/sway-standards#20
to be merged first

---------

Co-authored-by: bitzoic <bitzoic.eth@gmail.com>
  • Loading branch information
bitzoic and bitzoic authored Oct 4, 2023
1 parent d52b60a commit 5257dc7
Show file tree
Hide file tree
Showing 10 changed files with 1,105 additions and 476 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ These libraries contain helper functions and other tools valuable to blockchain
- [Signed Integers](./libs/signed_integers/) is an interface to implement signed integers.
- [Fixed Point Number](./libs/fixed_point/) is an interface to implement fixed-point numbers.
- [Queue](./libs/queue/) is a linear data structure that provides First-In-First-Out (FIFO) operations.
- [Token](./libs/token/) is a basic implementation of the [SRC-20](https://github.com/FuelLabs/sway-standards/tree/master/standards/src_20) and [SRC-3](https://github.com/FuelLabs/sway-standards/tree/master/standards/src_3) standards.
- [Token](./libs/token/) provides helper functions for the [SRC-20](https://github.com/FuelLabs/sway-standards/tree/master/standards/src_20), [SRC-3](https://github.com/FuelLabs/sway-standards/tree/master/standards/src_3), and [SRC-7](https://github.com/FuelLabs/sway-standards/tree/master/standards/src_7) standards.

## Using a library

Expand Down
3 changes: 3 additions & 0 deletions libs/token/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "lib.sw"
license = "Apache-2.0"
name = "token"

[dependencies]
src_7 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.1.2" }
6 changes: 4 additions & 2 deletions libs/token/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# Overview

The Token library provides basic function implementations of the [SRC-20; Token Standard](https://github.com/FuelLabs/sway-standards/tree/master/standards/src_20) and the [SRC-3; Mint and Burn Standard](https://github.com/FuelLabs/sway-standards/tree/master/standards/src_3). It is intended to make develpment of Native Assets using Sway quick and easy while following the standard's specifications.
The Token library provides basic helper functions for the [SRC-20; Token Standard](https://github.com/FuelLabs/sway-standards/tree/master/standards/src_20), [SRC-3; Mint and Burn Standard](https://github.com/FuelLabs/sway-standards/tree/master/standards/src_3), and the [SRC-7; Arbitrary Asset Metadata Standard](https://github.com/FuelLabs/sway-standards/tree/master/standards/src_7). It is intended to make develpment of Native Assets using Sway quick and easy while following the standard's specifications.

For more information please see the [specification](./SPECIFICATION.md).

Expand Down Expand Up @@ -40,7 +40,7 @@ storage {
To use a function, simply pass the `StorageKey` from the prescribed storage block above. The example below shows the implementation of the [SRC-20](https://github.com/FuelLabs/sway-standards/tree/master/standards/src_20) standard in combination with the Token library with no user defined restrictions or custom functionality.

```rust
use token::{
use token::base::{
_total_assets,
_total_supply,
_name,
Expand Down Expand Up @@ -87,3 +87,5 @@ impl SRC20 for Contract {
```

For more information please see the [specification](./SPECIFICATION.md).

> **NOTE** Until [Issue #5025](https://github.com/FuelLabs/sway/issues/5025) is resolved, in order to use the SRC-7 portion of the library, you must also add the [SRC-7](https://github.com/FuelLabs/sway-standards/tree/master/standards/src_7) standard as a dependency.
69 changes: 56 additions & 13 deletions libs/token/SPECIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,85 @@ The Token library can be used anytime a contract needs a basic implementation of

## Public Functions

### `_total_assets()`
### SRC-20

#### `_total_assets()`

This function will return the total number of individual assets for a contract.

### `_total_supply()`
#### `_total_supply()`

This function will return the total supply of tokens for an asset.

### `_name()`
#### `_name()`

This function will return the name of an asset, such as “Ether”.

### `_symbol()`
#### `_symbol()`

This function will return the symbol of an asset, such as “ETH”.

### `_decimals()`
#### `_decimals()`

This function will return the number of decimals an asset uses.

### `_mint()`
#### `_set_name()`

This function will unconditionally set the name of an asset.

#### `_set_symbol()`

This function will unconditionally set the symbol of an asset.

#### `_set_decimals`

This function will unconditionally set the decimals of an asset.

### SRC-3

#### `_mint()`

This function will unconditionally mint new tokens using a sub-identifier.

### `_burn()`
#### `_burn()`

This function will burns tokens with the given sub-identifier.

### `_set_name()`
### SRC-7

This function will unconditionally set the name of an asset.
### `_set_metadata()`

### `_set_symbol()`
This function will set metdata for an asset.

This function will unconditionally set the symbol of an asset.
#### `as_string()`

### `_set_decimals`
This function will return the metadata as a string.

#### `as_int()`

This function will return the metadata as an int.

#### `as_bytes()`

This function will return the metadata as bytes.

#### `as_b256()`

This function will return the metadata as a b256.

#### `is_string()`

This function will return whether the metadata is a string.

#### `is_int()`

This function will return the whether metadata is an int.

#### `is_bytes()`

This function will return the whether metadata are bytes.

#### `is_b256()`

This function will return the whether metadata is a b256.

This function will unconditionally set the decimals of an asset.
Loading

0 comments on commit 5257dc7

Please sign in to comment.