Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: psp22 trait contract example with drink tests #300

Open
wants to merge 176 commits into
base: main
Choose a base branch
from

Conversation

chungquantin
Copy link
Collaborator

@chungquantin chungquantin commented Sep 19, 2024

Description

Example contract for the fungible use case that applies the PSP22 traits from #297. The PR includes:

Daanvdplas and others added 30 commits May 19, 2024 17:38
# This is the 1st commit message:

refactor: general

# This is the commit message #2:

init

# This is the commit message #3:

begin refactor

# This is the commit message #4:

refactor: error handling

# This is the commit message #5:

tests: add error handling tests

# This is the commit message #6:

WIP

# This is the commit message #7:

finalise error handling

# This is the commit message #8:

refactor: easier review
Comment on lines +69 to +78
assert_eq!(
last_contract_event(&session).unwrap(),
Created {
id: TOKEN,
creator: account_id_from_slice(&contract),
admin: account_id_from_slice(&contract),
}
.encode()
.as_slice()
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be improved but not now. Opened an issue: r0gue-io/pop-drink#24

Copy link
Collaborator

@Daanvdplas Daanvdplas Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this improve these assertions a lot (deriving debug and partialeq traits under std feature):

#[ink::event]
#[cfg_attr(feature = "std", derive(Debug, PartialEq))]
pub struct Transfer {
	/// The source of the transfer. `None` when minting.
	#[ink(topic)]
	pub from: Option<AccountId>,
	/// The recipient of the transfer. `None` when burning.
	#[ink(topic)]
	pub to: Option<AccountId>,
	/// The amount transferred (or minted/burned).
	pub value: u128,
}

Is working in the integration tests for me. This gives much clearer errors.

@Daanvdplas Daanvdplas self-requested a review October 20, 2024 09:45
Copy link
Collaborator

@Daanvdplas Daanvdplas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed some small changes, lgtm now! Thanks for all the hard work!

pop-api/examples/fungibles/lib.rs Outdated Show resolved Hide resolved
pop-api/examples/fungibles/lib.rs Show resolved Hide resolved
pop-api/examples/fungibles/lib.rs Show resolved Hide resolved
pop-api/examples/fungibles/lib.rs Show resolved Hide resolved
pop-api/examples/fungibles/lib.rs Show resolved Hide resolved
pop-api/examples/fungibles/lib.rs Outdated Show resolved Hide resolved
pop-api/examples/fungibles/lib.rs Outdated Show resolved Hide resolved
pop-api/src/v0/fungibles/errors.rs Outdated Show resolved Hide resolved
pop-api/examples/fungibles/lib.rs Show resolved Hide resolved
pop-api/examples/fungibles/lib.rs Show resolved Hide resolved
@chungquantin chungquantin force-pushed the chungquantin/feat-psp22_example branch from 447f1b4 to 411ff66 Compare October 31, 2024 15:39

- **Staking Rewards Program**: This contract can be used to issue rewards in a staking program, where users lock tokens for network security or liquidity. The staking contract calls this PSP22 contract to mint and burn tokens, allowing the staking authority to manage rewards and ensure distribution only to eligible participants.
[ink]: https://use.ink
[substrate]: https://substrate.io
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer maintained

[erc20]: https://ethereum.org/en/developers/docs/standards/tokens/erc-20/
[psp22]: https://github.com/inkdevhub/standards/blob/master/PSPs/psp-22.md
[pop-api-fungibles]: https://github.com/r0gue-io/pop-node/tree/main/pop-api/src/v0/fungibles
[pallet-assets]: https://crates.io/crates/pallet-assets
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we not trying to prevent the devs to have to learn about pallet assets?

Comment on lines +3 to +5
PSP22 is a fungible token standard for WebAssembly smart contracts running on blockchains based on the [Substrate][substrate] framework. It is an equivalent of Ethereum's [ERC-20][erc20]. The definition of the PSP22 standard can be found [here][psp22].

This repository contains a simple, minimal implementation of the PSP22 token in [ink!][ink] smart contract programming language (EDSL based on Rust), utilizing the [Pop API Fungibles][pop-api-fungibles] feature.
Copy link
Collaborator

@Daanvdplas Daanvdplas Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Way too much detail, also we don't want to repeat the docs in the pop api about the psp22 contract. Just explain the contract in a simple way :), no need to make it fancy or anything.

"This contract shows a contract that allows interaction and management of a fungible token following the psp22 standard. In this specific contract only the contract owner has a permission to call specific methods. This is because ....
This is only one way of how the fungibles api can be utilised, other ways could be ...

Tests are written with pop drink ... and can be run with cargo test --release


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, have ideas or want to contribute to Pop!
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Pop API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants