Skip to content

Commit

Permalink
feat: psp22 trait contract example with drink tests (#300)
Browse files Browse the repository at this point in the history
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: R0GUE <[email protected]>
Co-authored-by: Daan van der Plas <[email protected]>
Co-authored-by: Frank Bell <[email protected]>
Co-authored-by: Frank Bell <[email protected]>
Co-authored-by: Peter White <[email protected]>
Co-authored-by: Alejandro Martinez Andres <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Alex Bean <[email protected]>
  • Loading branch information
9 people authored Nov 7, 2024
1 parent d642b42 commit 3cdb9b5
Show file tree
Hide file tree
Showing 20 changed files with 1,144 additions and 532 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ license = "Unlicense"
repository = "https://github.com/r0gue-io/pop-node/"

[workspace]
exclude = [ "extension/contract", "pop-api", "tests/contracts" ]
exclude = [
"extension/contract",
"pop-api",
"tests/contracts",
]
members = [
"integration-tests",
"node",
Expand Down
Empty file modified pop-api/examples/.gitignore
100755 → 100644
Empty file.
28 changes: 0 additions & 28 deletions pop-api/examples/balance-transfer/Cargo.toml

This file was deleted.

135 changes: 0 additions & 135 deletions pop-api/examples/balance-transfer/lib.rs

This file was deleted.

19 changes: 16 additions & 3 deletions pop-api/examples/fungibles/Cargo.toml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
[package]
authors = [ "[your_name] <[your_email]>" ]
authors = [ "R0GUE <[email protected]>" ]
edition = "2021"
name = "fungibles"
version = "0.1.0"

[dependencies]
ink = { version = "5.0.0", default-features = false }
pop-api = { path = "../../../pop-api", default-features = false, features = [ "fungibles" ] }
ink = { version = "=5.0.0", default-features = false, features = [ "ink-debug" ] }
pop-api = { path = "../../../pop-api", default-features = false, features = [
"fungibles",
] }

[dev-dependencies]
drink = { package = "pop-drink", git = "https://github.com/r0gue-io/pop-drink" }
env_logger = { version = "0.11.3" }
serde_json = "1.0.114"

# TODO: due to compilation issues caused by `sp-runtime`, `frame-support-procedural` and `staging-xcm` this dependency
# (with specific version) has to be added. Will be tackled by #348, please ignore for now.
frame-support-procedural = { version = "=30.0.1", default-features = false }
sp-runtime = { version = "=38.0.0", default-features = false }
staging-xcm = { version = "=14.1.0", default-features = false }

[lib]
path = "lib.rs"
Expand Down
42 changes: 42 additions & 0 deletions pop-api/examples/fungibles/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# PSP22 Fungible Token with Pop API

This [ink!][ink] contract implements a [PSP22-compliant][psp22] fungible token by leveraging the [Pop API Fungibles][pop-api-fungibles]. Unlike typical token contracts, where the contract itself manages the token, tokens created by this contract are managed directly by Pop. This enables seamless integration and interoperability of the token across the Polkadot ecosystem and its applications.

As the creator of the token, the contract has permissions to mint and burn tokens, but it can only transfer and approve tokens on its own behalf and requires explicit approval to transfer tokens for other accounts. Instead of users interacting with the contract to handle their token approvals, they interact primarily with Pop’s runtime.

## Key benefits of using the Pop API

- The token operates live on the Pop Network, beyond just within the contract.
- Simplify token management with high-level interfaces to significantly reduce contract size and complexity.

[Learn more how Pop API works.](pop-api)

## Use Cases

This contract can serve a variety of purposes where owner-controlled token management is essential. Example use cases include:
- **DAO Token**: A DAO can use this contract to manage a governance token, with the DAO overseeing token issuance and removal based on governance decisions.
- **Staking and Rewards**: This contract supports minting tokens specifically for reward distribution.
- **Loyalty Programs**: Businesses or platforms can use this contract to issue loyalty points, with the owner managing token balances for users based on participation or purchases.

## Test with Pop Drink

Since this contract interacts directly with Pop’s runtime through the Pop API, it requires [Pop Drink](https://github.com/r0gue-io/pop-drink) for testing. See how the contract is tested in [tests](./tests.rs).

## Potential Improvements

- **Multiple owner management**: Instead of restricting ownership to a single `owner`, the contract could be designed to accommodate multiple owners.

## Support

Be part of our passionate community of Web3 builders. [Join our Telegram](https://t.me/onpopio)!

Feel free to raise issues if anything is unclear, you have ideas or want to contribute to Pop! Examples using the fungibles API are always welcome!

For any questions related to ink! you can also go to [Polkadot Stack Exchange](https://polkadot.stackexchange.com/) or
ask the [ink! community](https://t.me/inkathon/1).

[ink]: https://use.ink
[psp22]: https://github.com/inkdevhub/standards/blob/master/PSPs/psp-22.md
[pop-api]: https://github.com/r0gue-io/pop-node/tree/main/pop-api/
[pop-api-fungibles]: https://github.com/r0gue-io/pop-node/tree/main/pop-api/src/v0/fungibles
[pop-drink]: https://github.com/r0gue-io/pop-drink
Loading

0 comments on commit 3cdb9b5

Please sign in to comment.