Skip to content

Commit

Permalink
Reimplement Fractional NFT Application (#767)
Browse files Browse the repository at this point in the history
## Type of change

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

- New Application

## Changes

The following changes have been made:

- Adds F-NFT App

## Notes

- The Fractionalized NFT Application was deprecated and removed from the
repository due to the introduction of Native NFTs on Fuel. This has now
been reimplemented with Native Assets and the SRC-6; Vault Standard.

## Related Issues

<!--Delete everything after the "#" symbol and replace it with a number.
No spaces between hash and number-->

Closes #714
  • Loading branch information
bitzoic authored Jan 26, 2024
1 parent a7a5362 commit 1832171
Show file tree
Hide file tree
Showing 32 changed files with 6,049 additions and 0 deletions.
1 change: 1 addition & 0 deletions .devops/aurora/apps.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ games/TicTacToe
multisig-wallet
name-registry
native-assets/NFT
native-assets/fractional-NFT
native-assets/token
oracle
timelock
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
"multisig-wallet",
"name-registry",
"native-assets/NFT",
"native-assets/fractional-NFT",
"native-assets/token",
"oracle",
"OTC-swap-predicate",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ sway-applications/

- [Airdrop](./airdrop/) is a token distribution program where users are able to claim tokens given a valid merkle proof.
- [Escrow](./escrow) is a third party that keeps an asset on behalf of multiple parties.
- [Fractional Non-Fungible Token (F-NFT)](./native-assets/fractional-NFT/) is a token contract which issues shares or partial ownership upon locking an NFT into a vault.
- [Non-Fungible Token (NFT)](./native-assets/NFT/) is a token contract which provides unique collectibles, identified and differentiated by token IDs, where tokens contain metadata giving them distinctive characteristics.
- [Timelock](./timelock) is a contract which restricts the execution of a transaction to a specified time range.
- [Token](./native-assets/token/) is a basic token contract that enables the use of Native Assets on Fuel using existing standards and libraries.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions native-assets/fractional-NFT/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target
out
107 changes: 107 additions & 0 deletions native-assets/fractional-NFT/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset=".docs/f-nft-logo_white.png">
<img alt="light theme" src=".docs/f-nft-logo_black.png">
</picture>
</p>

<p align="center">
<a href="https://crates.io/crates/forc/0.49.1" alt="forc">
<img src="https://img.shields.io/badge/forc-v0.49.1-orange" />
</a>
<a href="https://crates.io/crates/fuel-core/0.22.0" alt="fuel-core">
<img src="https://img.shields.io/badge/fuel--core-v0.22.0-yellow" />
</a>
</p>

## Overview

A fractional non-fungible token (F-NFT) is a unique asset that represents a share or portion of ownership over a non-fungible token (NFT). On the Fuel Network, all NFTs and F-NFTs are [Native Assets](https://docs.fuel.network/docs/sway/blockchain-development/native_assets). F-NFTs are often created to sell partial ownership of an NFT on a secondary market, espeically in royalty NFTs to split a profit.

In this barebones F-NFT example project, where locking a NFT into the vault will issue 100,000,000 shares. When all shares are sent to the vault in the same transaction, the NFT is unlocked and can be withdrawn.

## Standards Implementations

The project implements and follows the [SRC-6; Vault](https://github.com/FuelLabs/sway-standards/tree/master/standards/src6-vault) and [SRC-20; Native Asset](https://github.com/FuelLabs/sway-standards/tree/master/standards/src20-native-asset) standards.

### SRC-6

The [SRC-6](https://github.com/FuelLabs/sway-standards/tree/master/standards/src6-vault) standard defines the ABI for locking an NFT in a vault and minting shares. This has been properly implemented.

```sway
abi SRC6 {
#[payable]
#[storage(read, write)]
fn deposit(receiver: Identity, vault_sub_id: SubId) -> u64;
#[payable]
#[storage(read, write)]
fn withdraw(receiver: Identity, underlying_asset: AssetId, vault_sub_id: SubId) -> u64;
#[storage(read)]
fn managed_assets(underlying_asset: AssetId, vault_sub_id: SubId) -> u64;
#[storage(read)]
fn max_depositable(receiver: Identity, underlying_asset: AssetId, vault_sub_id: SubId) -> Option<u64>;
#[storage(read)]
fn max_withdrawable(underlying_asset: AssetId, vault_sub_id: SubId) -> Option<u64>;
}
```

### SRC-20

The [SRC-20](https://github.com/FuelLabs/sway-standards/tree/master/standards/src_20) standard has been implemented for the resulting minted shares when a NFT is locked in the vault. Information on the share assets can be queried with the [SRC-20](https://github.com/FuelLabs/sway-standards/tree/master/standards/src_20) standard.

```sway
abi SRC20 {
#[storage(read)]
fn total_assets() -> u64;
#[storage(read)]
fn total_supply(asset: AssetId) -> Option<u64>;
#[storage(read)]
fn name(asset: AssetId) -> Option<String>;
#[storage(read)]
fn symbol(asset: AssetId) -> Option<String>;
#[storage(read)]
fn decimals(asset: AssetId) -> Option<u8>;
}
```

## Project structure

The project consists of a smart contract.

<!--Only show most important files e.g. script to run, build etc.-->

```sh
fractional-NFT
├── project
│   ├── contracts
│   │   └── f-NFT-contract
│   │   └──src/main.sw
│   └── SPECIFICATION.md
├── ui
│ └── SPECIFICATION.md
└── README.md
```

## Running the project

### User interface

TODO: The user interface does not currently exist therefore its [SPECIFICATION.md](ui/SPECIFICATION.md) is empty.

### Project

In order to run the subsequent commands change into the following directory `/path/to/fractional-NFT/project/<here>`.

#### Program compilation

```bash
forc build
```

#### Running the tests

Before running the tests the programs must be compiled with the command above.

```bash
cargo test
```
Loading

0 comments on commit 1832171

Please sign in to comment.