Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
bitzoic committed Aug 29, 2024
1 parent 6f62c6f commit cce9fe4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 66 deletions.
2 changes: 2 additions & 0 deletions docs/book/src/asset/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ To use the Asset Library's base functionly, simply pass the `StorageKey` from th

To set some the asset attributes for an Asset, use the `SetAssetAttributes` ABI provided by the Asset Library. The example below shows the implementation of the `SetAssetAttributes` ABI with no user defined restrictions or custom functionality. It is recommended that the [Ownership Library](../ownership/index.md) is used in conjunction with the `SetAssetAttributes` ABI to ensure only a single user has permissions to set an Asset's attributes.

The `_set_name()`, `_set_symbol()`, and `_set_decimals()` functions follows the SRC-20 standard for logging and will emit their respective log when called.

```sway
{{#include ../../../../examples/asset/setting_src20_attributes/src/main.sw:setting_src20_attributes}}
```
Expand Down
70 changes: 5 additions & 65 deletions docs/book/src/asset/metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,6 @@ The Asset Library has the following complimentary data type for the [SRC-7](http

- `StorageMetadata`

The following additional functionality for the [SRC-7](https://docs.fuel.network/docs/sway-standards/src-7-asset-metadata/)'s `Metadata` type is provided:

- `as_string()`
- `is_string()`
- `as_u64()`
- `is_u64()`
- `as_bytes()`
- `is_bytes()`
- `as_b256()`
- `is_b256()`

## Setting Up Storage

Once imported, the Asset Library's metadata functionality should be available. To use them, be sure to add the storage block bellow to your contract which enables the [SRC-7](https://docs.fuel.network/docs/sway-standards/src-7-asset-metadata/) standard.
Expand All @@ -47,7 +36,9 @@ Once imported, the Asset Library's metadata functionality should be available. T

### Setting Metadata

To set some metadata for an Asset, use the `SetAssetMetadata` ABI provided by the Asset Library. Be sure to follow the [SRC-9](https://docs.fuel.network/docs/sway-standards/src-9-metadata-keys/) standard for your `key`. It is recommended that the [Ownership Library](../ownership/index.md) is used in conjunction with the `SetAssetMetadata` ABI to ensure only a single user has permissions to set an Asset's metadata.
To set some metadata for an Asset, use the `SetAssetMetadata` ABI provided by the Asset Library with the `_set_metadata()` function. Be sure to follow the [SRC-9](https://docs.fuel.network/docs/sway-standards/src-9-metadata-keys/) standard for your `key`. It is recommended that the [Ownership Library](../ownership/index.md) is used in conjunction with the `SetAssetMetadata` ABI to ensure only a single user has permissions to set an Asset's metadata.

The `_set_metadata()` function follows the SRC-7 standard for logging and will emit the `SetMetadataEvent` when called.

```sway
{{#include ../../../../examples/asset/setting_src7_attributes/src/main.sw:setting_src7_attributes}}
Expand All @@ -57,59 +48,8 @@ To set some metadata for an Asset, use the `SetAssetMetadata` ABI provided by th
### Implementing the SRC-7 Standard with StorageMetadata

To use the `StorageMetadata` type, simply get the stored metadata with the associated `key` and `AssetId`. The example below shows the implementation of the [SRC-7](https://docs.fuel.network/docs/sway-standards/src-7-asset-metadata/) standard in combination with the Asset Library's `StorageMetadata` type with no user defined restrictions or custom functionality.

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

## Using the `Metadata` Extensions

The `Metadata` type defined by the [SRC-7](https://docs.fuel.network/docs/sway-standards/src-7-asset-metadata/) standard can be one of 4 states:

```sway
pub enum Metadata {
B256: b256,
Bytes: Bytes,
Int: u64,
String: String,
}
```

The Asset Library enables the following functionality for the `Metadata` type:

### `is_b256()` and `as_b256()`

The `is_b256()` check enables checking whether the `Metadata` type is a `b256`.
The `as_b256()` returns the `b256` of the `Metadata` type.

```sway
{{#include ../../../../examples/asset/metadata_docs/src/main.sw:as_b256}}
```

### `is_bytes()` and `as_bytes()`

The `is_bytes()` check enables checking whether the `Metadata` type is a `Bytes`.
The `as_bytes()` returns the `Bytes` of the `Metadata` type.

```sway
{{#include ../../../../examples/asset/metadata_docs/src/main.sw:as_bytes}}
```

### `is_u64()` and `as_u64()`

The `is_u64()` check enables checking whether the `Metadata` type is a `u64`.
The `as_u64()` returns the `u64` of the `Metadata` type.

```sway
{{#include ../../../../examples/asset/metadata_docs/src/main.sw:as_u64}}
```

### `is_string()` and `as_string()`

The `is_string()` check enables checking whether the `Metadata` type is a `String`.
The `as_string()` returns the `String` of the `Metadata` type.
To use the `StorageMetadata` type, simply get the stored metadata with the associated `key` and `AssetId` using the provided `_metadata()` convenience function. The example below shows the implementation of the [SRC-7](https://docs.fuel.network/docs/sway-standards/src-7-asset-metadata/) standard in combination with the Asset Library's `StorageMetadata` type and the `_metadata()` function with no user defined restrictions or custom functionality.

```sway
{{#include ../../../../examples/asset/metadata_docs/src/main.sw:as_string}}
{{#include ../../../../examples/asset/basic_src7/src/main.sw:src7_metadata_convenience_function}}
```
4 changes: 3 additions & 1 deletion docs/book/src/asset/supply.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ Once imported, the Asset Library's supply functionality should be available. To

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

To use a base function, simply pass the `StorageKey` from the prescribed storage block. The example below shows the implementation of the [SRC-3](https://docs.fuel.network/docs/sway-standards/src-3-minting-and-burning/) standard in combination with the Asset Library with no user defined restrictions or custom functionality. It is recommended that the [Ownership Library](../ownership/index.md) is used in conjunction with the Asset Library;s supply functionality to ensure only a single user has permissions to mint an Asset.
To use either function, simply pass the `StorageKey` from the prescribed storage block. The example below shows the implementation of the [SRC-3](https://docs.fuel.network/docs/sway-standards/src-3-minting-and-burning/) standard in combination with the Asset Library with no user defined restrictions or custom functionality. It is recommended that the [Ownership Library](../ownership/index.md) is used in conjunction with the Asset Library;s supply functionality to ensure only a single user has permissions to mint an Asset.

The `_mint()` and `_burn()` functions follows the SRC-20 standard for logging and will emit the `TotalSupplyEvent` when called.

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

0 comments on commit cce9fe4

Please sign in to comment.