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

Merged
merged 187 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 180 commits
Commits
Show all changes
187 commits
Select commit Hold shift + click to select a range
7c2eac2
feat: pallet assets pop api integration
Daanvdplas Apr 5, 2024
418aa63
style: renaming assets example
Daanvdplas Apr 12, 2024
3d385df
refactor: chain extension tests
Daanvdplas Apr 22, 2024
fd46a27
fix: add error handling other than ModuleError
Daanvdplas Jun 4, 2024
1022926
test: add transfer
Daanvdplas Jun 6, 2024
ecc82e2
chore: remove polkadot launch
Daanvdplas Jun 6, 2024
e81f78a
# This is a combination of 8 commits.
Daanvdplas Jun 6, 2024
f824801
refactor: error handling
Daanvdplas Jun 20, 2024
4670503
refactor: clarify todos
Daanvdplas Jun 20, 2024
2283161
refactor: error handling comments part 1
Daanvdplas Jun 24, 2024
f88dd89
refactor: apply comments part 2
Daanvdplas Jun 25, 2024
61b3a17
refactor: tests local fungibles
Daanvdplas Jun 26, 2024
c1616a3
refactor: naming pallet error
Daanvdplas Jun 26, 2024
13e947e
refactor: optimising pop api and additional logic + test
Daanvdplas Jun 26, 2024
7757319
refactor: runtime
Daanvdplas Jul 3, 2024
924df85
refactor: draft final design
Daanvdplas Jul 2, 2024
972e4c9
feat: add more interfaces
Daanvdplas Jul 5, 2024
47e2ea6
refactor: final bits
Daanvdplas Jul 5, 2024
9dcfccb
fix: compiling
Daanvdplas Jul 6, 2024
b067eda
fix: cannot find macro vec error
Daanvdplas Jul 16, 2024
8730f90
refactor: decoding failed and commenting out unimplemented tests
Daanvdplas Jul 17, 2024
b591222
style: renaming
Daanvdplas Jul 17, 2024
c2acbb5
refactor: bits and pieces
Daanvdplas Jul 18, 2024
3639320
docs: add docs to code
Daanvdplas Jul 18, 2024
81e9844
fix: replace test code to api fungibles
Daanvdplas Jul 18, 2024
023d3dc
fix: own review + fixing CI fail
Daanvdplas Jul 18, 2024
e683e16
refactor: add Error variants index + clippy allowance
Daanvdplas Jul 19, 2024
28d971b
feat: api fungibles pallet (#113)
Daanvdplas Jul 26, 2024
4e4512e
refactor: streamline error from the decoded method by returning `Resu…
chungquantin Jul 26, 2024
02dffc6
merge main
Daanvdplas Jul 26, 2024
027cb85
refactor: build chain extension method (#121)
chungquantin Jul 26, 2024
30ff91a
fix: clean up imports (#135)
chungquantin Jul 27, 2024
9820e7f
refactor: remove read state encoding (#122)
Daanvdplas Jul 28, 2024
5ac5a9a
feat: transfer_from and decrease_allowance (#134)
chungquantin Jul 31, 2024
d8ac5bd
refactor: api integration tests (#133)
Daanvdplas Aug 6, 2024
00c5903
refactor: remove bare_call code duplication in integration test (#168)
chungquantin Aug 9, 2024
1acbd21
merge main
Daanvdplas Aug 13, 2024
9ebe162
fix: compilation
Daanvdplas Aug 13, 2024
545bd33
fix: try-runtime error
Daanvdplas Aug 13, 2024
99d0f6d
refactor: generic extension crate to de-duplicate code between runtim…
chungquantin Aug 13, 2024
8b4f595
feat: api events (#153)
Daanvdplas Aug 14, 2024
f13b39c
docs: pop api (#190)
Daanvdplas Aug 16, 2024
7c94284
refactor: extension
Daanvdplas Aug 16, 2024
5934fa8
fix: remove old api code from deprecated examples
Daanvdplas Aug 16, 2024
f2ef7a1
refactor: runtime devnet
Daanvdplas Aug 16, 2024
b3dd993
refactor: fungibles pallet
Daanvdplas Aug 16, 2024
0811598
style: fix tests asset_asset parameter
Daanvdplas Aug 19, 2024
6482a43
fix: invalid imported crates & crate visibility (#214)
chungquantin Aug 19, 2024
1b78c11
ci: add CI script for `pop-api` tests and integration tests (#228)
chungquantin Aug 26, 2024
8d1c085
fix: mutable `self` required for dispatchable ink! methods (#235)
chungquantin Aug 26, 2024
479dbb0
refactor: generic extension (#218)
evilrobot-01 Sep 6, 2024
ec49dc3
chore: resolve conflicts for `daan/api` (#267)
chungquantin Sep 7, 2024
d92a4c5
chore(runtime): use workspace dependencies
evilrobot-01 Sep 7, 2024
114934a
Merge branch 'refs/heads/main' into daan/api
evilrobot-01 Sep 7, 2024
d7cba0a
chore: resolve merge issues
evilrobot-01 Sep 7, 2024
a272657
ci: clear more space
evilrobot-01 Sep 7, 2024
c0ea3ed
ci: disable debug info for coverage
evilrobot-01 Sep 7, 2024
206757b
style: token terminology (#215)
Daanvdplas Sep 9, 2024
07a0731
chore: add sandbox crate
chungquantin Sep 11, 2024
7f04779
fix: taplo formatting
chungquantin Sep 11, 2024
8a1095b
fix: update tests
chungquantin Sep 11, 2024
d23c2b3
fix: test with logger
chungquantin Sep 11, 2024
0ab510f
fix: test with logger
chungquantin Sep 11, 2024
1c06043
fix: revert flipper example changes
chungquantin Sep 11, 2024
f6976b0
fix: fungibles contract
chungquantin Sep 12, 2024
d6408da
refactor: create sandbox for devnet runtime
chungquantin Sep 12, 2024
0399d46
refactor: fungible example contract
chungquantin Sep 12, 2024
5fdf406
refactor: fungible test
chungquantin Sep 12, 2024
ed7146b
fix: fungible contract
chungquantin Sep 12, 2024
7ce0674
test: drink tests for fungible use case
chungquantin Sep 12, 2024
8c1988f
merge daan/api
Daanvdplas Sep 16, 2024
7c4c470
style: token terminology
Daanvdplas Sep 16, 2024
4e44fba
feat: add interfaces for psp22
chungquantin Sep 18, 2024
a32f002
chore: add comments
chungquantin Sep 18, 2024
bf4062d
refactor: separate modules into files
chungquantin Sep 18, 2024
21c6826
refactor: fungible example
chungquantin Sep 18, 2024
894fcf9
feat: refactor example contract to follow spec
chungquantin Sep 18, 2024
817a351
test: psp22error
chungquantin Sep 18, 2024
6042f09
fix: missing String
chungquantin Sep 18, 2024
c8cc9d1
chore: revert example
chungquantin Sep 19, 2024
a8c063c
fix: resolve comments
chungquantin Sep 19, 2024
8176474
fix: revert example contract
chungquantin Sep 19, 2024
1945683
fix: add mod comment
chungquantin Sep 19, 2024
6aede89
fix: result type
chungquantin Sep 19, 2024
b52ad33
fix: update PSP22Metadata
chungquantin Sep 19, 2024
6b2f17a
fix: add comment for Psp22 trait
chungquantin Sep 19, 2024
4a1bf3b
fix: resolve comments
chungquantin Sep 19, 2024
699275c
fix: api integration tests
chungquantin Sep 19, 2024
94ee34e
fix: result type
chungquantin Sep 19, 2024
9bb3be8
fix: comment
chungquantin Sep 19, 2024
f03a5ae
feat: add interfaces for psp22
chungquantin Sep 18, 2024
1bbc3ed
chore: add comments
chungquantin Sep 18, 2024
e8d68a9
refactor: separate modules into files
chungquantin Sep 18, 2024
4ead643
refactor: fungible example
chungquantin Sep 18, 2024
12d1af4
feat: refactor example contract to follow spec
chungquantin Sep 18, 2024
24afd15
test: psp22error
chungquantin Sep 18, 2024
8ecf6d9
fix: missing String
chungquantin Sep 18, 2024
6f521f4
fix: resolve comments
chungquantin Sep 19, 2024
7ce5d52
fix: add mod comment
chungquantin Sep 19, 2024
b29cf17
fix: result type
chungquantin Sep 19, 2024
933c62e
fix: update PSP22Metadata
chungquantin Sep 19, 2024
de80906
fix: add comment for Psp22 trait
chungquantin Sep 19, 2024
8717adb
fix: resolve comments
chungquantin Sep 19, 2024
8ae2c00
fix: api integration tests
chungquantin Sep 19, 2024
97417e3
fix: result type
chungquantin Sep 19, 2024
204ee06
fix: resolve comments
chungquantin Sep 19, 2024
540639a
Merge branch 'chungquantin/feat-psp22_traits' into chungquantin/feat-…
chungquantin Sep 20, 2024
867cc28
feat: drink test for example contract
chungquantin Sep 20, 2024
7dc6047
refactor: add helpers module
chungquantin Sep 20, 2024
b433c67
feat: add event assertions
chungquantin Sep 20, 2024
e018e34
test: event assertion
chungquantin Sep 20, 2024
baab872
refactor: call expect error methods & function constant
chungquantin Sep 20, 2024
cb48a4d
test: add more test cases
chungquantin Sep 20, 2024
7637420
fix: comment
chungquantin Sep 23, 2024
cbcf66a
chore: revert example contract changes
chungquantin Sep 23, 2024
12c368b
chore: resolve comments
chungquantin Sep 23, 2024
83a5afe
Merge branch 'chungquantin/feat-psp22_traits' into chungquantin/feat-…
chungquantin Sep 23, 2024
f1245d7
Merge branch 'chore/tests_with_drink' into chungquantin/feat-psp22_ex…
chungquantin Sep 23, 2024
e76a524
chore: remove deprecated example contracts
chungquantin Sep 23, 2024
a39b1a4
chore: rebase
chungquantin Sep 23, 2024
517ddd3
fix: resolve comments & fix transfer_from()
chungquantin Sep 23, 2024
86e7d85
fix: expect return error method
chungquantin Sep 24, 2024
f8fc1b5
fix: add missing conversions in PSP22Error
chungquantin Sep 24, 2024
904d7c2
Merge branch 'chungquantin/feat-psp22_traits' into chungquantin/feat-…
chungquantin Sep 24, 2024
4a2077f
fix: remove ToString
chungquantin Sep 24, 2024
31b5735
Merge branch 'chungquantin/feat-psp22_traits' into chungquantin/feat-…
chungquantin Sep 24, 2024
8fc8d07
fix: ToString
chungquantin Sep 24, 2024
393dbf2
Merge branch 'chungquantin/feat-psp22_traits' into chungquantin/feat-…
chungquantin Sep 24, 2024
52ec10d
refactor: tests
chungquantin Sep 24, 2024
f9e76ec
feat: check deployment error
chungquantin Sep 24, 2024
e151ef1
refactor: update constant visibility
chungquantin Sep 24, 2024
642c4f5
Merge branch 'main' into chungquantin/feat-psp22_example
chungquantin Sep 24, 2024
d5aee3c
Merge branch 'main' into chore/tests_with_drink
chungquantin Sep 24, 2024
d27c5ef
Merge branch 'chore/tests_with_drink' into chungquantin/feat-psp22_ex…
chungquantin Sep 24, 2024
e370777
fix: resolve review comments
chungquantin Sep 25, 2024
7b2ce90
fix: comment
chungquantin Sep 25, 2024
17d12a0
fix: transfer_from test
chungquantin Sep 25, 2024
e33b74c
fix: decrease_allowance
chungquantin Sep 26, 2024
30fb60a
fix: constructor test
chungquantin Sep 26, 2024
17fa0d2
fix: comment
chungquantin Sep 26, 2024
462c327
fix: comment
chungquantin Sep 26, 2024
7babedd
refactor: dependecy order
chungquantin Sep 26, 2024
b47fc51
fix: refactor and add more tests
chungquantin Sep 26, 2024
6a3166f
fix: resolve review comments
chungquantin Sep 26, 2024
7fd18c7
fix: comment
chungquantin Sep 26, 2024
110ea1e
fix: comment
chungquantin Sep 26, 2024
7225416
refactor: into_psp22_custom
chungquantin Sep 26, 2024
b77d948
fix: remove redundant code
chungquantin Sep 26, 2024
ea41bcf
fix: only check state changes if success
chungquantin Sep 26, 2024
5f8bf7e
fix: trait name
chungquantin Sep 26, 2024
5e48851
fix: trait name
chungquantin Sep 26, 2024
af4ec2b
fix: psp22 trait name (#305)
chungquantin Sep 26, 2024
ee68906
Merge branch 'developer' into chungquantin/feat-psp22_example
chungquantin Sep 26, 2024
bea0e9a
feat: return `UnApproved` in `decrease_allowance` instead of `saturat…
chungquantin Sep 27, 2024
b2fbcd8
fix: decrease_allowance test
chungquantin Sep 27, 2024
e9cc4a5
refactor: drink (#308)
Daanvdplas Oct 1, 2024
1857ea6
fix: resolve example contract issues (#315)
chungquantin Oct 1, 2024
eee369a
feat: add function selectors to psp22 trait (#316)
chungquantin Oct 3, 2024
6e4ca80
chore: merge main
chungquantin Oct 3, 2024
46612fb
chore: merge main
chungquantin Oct 3, 2024
fd277f7
fix: token name & symbol contract function
chungquantin Oct 3, 2024
da513bc
fix: burn
chungquantin Oct 3, 2024
56f1076
fix: name & symbol
chungquantin Oct 3, 2024
93de4b8
refactor: `PSP22Error` conversion & assertion (#324)
chungquantin Oct 10, 2024
d885b49
fix: pop-drink git path
chungquantin Oct 18, 2024
d907cb0
fix: contract -> instance
chungquantin Oct 18, 2024
eec6221
fix: pop-drink path
chungquantin Oct 18, 2024
ca551b7
refactor: small changes
Daanvdplas Oct 20, 2024
2f26284
fix(api): psp22error test
chungquantin Oct 21, 2024
5acd572
fix: alloc
chungquantin Oct 22, 2024
2cf0ec8
fix: comment
chungquantin Oct 23, 2024
3401052
fix: rename PSP22Error to Psp22Error
chungquantin Oct 23, 2024
9d31d2f
chore: delete psp34error
chungquantin Oct 23, 2024
70d37c9
fix: update comments
chungquantin Oct 23, 2024
8c72e2c
feat(psp22): protect with `owner`
chungquantin Oct 30, 2024
1923669
feat(psp22): protect with `owner`
chungquantin Nov 1, 2024
4a7a320
chore: update docs
chungquantin Nov 4, 2024
4148967
chore: resolve reviewer comments
chungquantin Nov 4, 2024
c53fe45
Merge branch 'main' into chungquantin/feat-psp22_example
chungquantin Nov 4, 2024
22e1477
refactor: owner field
chungquantin Nov 4, 2024
09311d4
feat(drink test): assert last event (#370)
chungquantin Nov 5, 2024
b78e36c
chore: rename transfer_ownership method
chungquantin Nov 5, 2024
7077900
chore: comment
chungquantin Nov 5, 2024
9684c45
chore: README
chungquantin Nov 5, 2024
dd4ce50
chore: README
chungquantin Nov 5, 2024
43f9f95
chore: resolve review comments
chungquantin Nov 6, 2024
0874070
fix: README.md
chungquantin Nov 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
33 changes: 33 additions & 0 deletions pop-api/examples/fungibles/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# PSP22 Fungible Token with Pop API

This [ink!][ink] contract demonstrates a [PSP22-compliant][psp22] fungible token utilizing 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. Instead of users interacting with the contract to handle their tokens, they interact with Pop’s runtime.

chungquantin marked this conversation as resolved.
Show resolved Hide resolved
As the token owner, 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. This structure enables seamless integration and interoperability across the Polkadot ecosystem and its applications.
chungquantin marked this conversation as resolved.
Show resolved Hide resolved

## 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.ints and burns tokens for a staking rewards program, allowing the staking authority to distribute rewards only to eligible participants.
chungquantin marked this conversation as resolved.
Show resolved Hide resolved

## 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).
chungquantin marked this conversation as resolved.
Show resolved Hide resolved
## 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, have ideas or want to contribute to Pop! Examples using the fungibles API are always welcome!
chungquantin marked this conversation as resolved.
Show resolved Hide resolved

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-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
Loading