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 example DAO contract #407

Open
wants to merge 51 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
d8f3c22
Dao contract
ndkazu Dec 13, 2024
5cbb44a
Added some events
ndkazu Dec 15, 2024
bb060f1
removed absent module
ndkazu Dec 15, 2024
30637ae
Added some in-code documentation
ndkazu Dec 15, 2024
e6c9edd
Corrected index error
ndkazu Dec 15, 2024
058e53b
Problem with first test
ndkazu Dec 15, 2024
ff2b300
Making sense of pop-drink for testing
ndkazu Dec 15, 2024
2505f89
Added lib.rs to Cargo, but still...
ndkazu Dec 16, 2024
6f653a9
Added the correct deploy() function in tests
ndkazu Dec 17, 2024
aacbf87
Put a limitation of description string length
ndkazu Dec 17, 2024
f746400
chore: add missing authors
chungquantin Dec 17, 2024
285c178
new member test added
ndkazu Dec 17, 2024
34002d0
create_proposal test
ndkazu Dec 17, 2024
d17096c
Calls prepared for testing
ndkazu Dec 17, 2024
3f2c114
ReadMe
ndkazu Dec 18, 2024
22d46e3
ReadME
ndkazu Dec 18, 2024
b02f232
create_proposal_test
ndkazu Dec 19, 2024
c08b335
Another test
ndkazu Dec 19, 2024
7a1563b
Enactment test
ndkazu Dec 19, 2024
9eca1b2
one more test
ndkazu Dec 19, 2024
b0d6194
Reverted some changes
ndkazu Dec 19, 2024
f8910ce
Reverted some changes
ndkazu Dec 19, 2024
94d884e
Documented the failing test: proposal_enactment_works
ndkazu Dec 19, 2024
00d76c0
Another test...
ndkazu Dec 19, 2024
8de7a7d
tests
ndkazu Dec 19, 2024
5e91679
refactored the code & added another test
ndkazu Dec 19, 2024
77328df
Treasury balance check & another test
ndkazu Dec 20, 2024
a8206d4
Another test
ndkazu Dec 20, 2024
56e622d
cargo fmt
ndkazu Dec 20, 2024
4ad34f4
Final test
ndkazu Dec 20, 2024
0cd9573
Applied some fixes related to the code review
ndkazu Dec 24, 2024
be3759f
Added ProposalStatus enum
ndkazu Dec 24, 2024
a34f0d1
Added descriptions for errors
ndkazu Dec 24, 2024
5e8e8e4
Review correction
ndkazu Dec 24, 2024
ede1283
cargo clippy
ndkazu Dec 24, 2024
425d757
Merge branch 'r0gue-io:main' into psp22Example
ndkazu Dec 26, 2024
0e2db17
update ink version
ndkazu Dec 26, 2024
21b13c5
cargo clippy --fix
ndkazu Dec 26, 2024
34ba35c
Some clean up
ndkazu Dec 26, 2024
bd11e86
All tests pass
ndkazu Dec 26, 2024
905705c
cargo fmt
ndkazu Dec 26, 2024
0841c32
Refactored code, implemented Default trait for Proposal
ndkazu Dec 26, 2024
562b17f
cargo fmt
ndkazu Dec 26, 2024
eaae705
Preparations for use of RuntimeCall
ndkazu Dec 27, 2024
adb72f9
Use transfer_from instead of transfer for runtime_call
ndkazu Dec 27, 2024
290d0ec
Corrected test mistake, using transfer_from instead of transfer
ndkazu Dec 29, 2024
bad1126
RuntimeCall working
ndkazu Dec 29, 2024
32ecca5
Corrections
ndkazu Dec 31, 2024
c357a07
Code re-factoring
ndkazu Dec 31, 2024
c0f9f9d
RuntimeCall conversion problem
ndkazu Jan 8, 2025
2526c04
customised RuntimeCalls works
ndkazu Jan 9, 2025
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
38 changes: 38 additions & 0 deletions pop-api/examples/dao/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
authors = ["R0GUE <go@r0gue.io>"]
edition = "2021"
name = "dao"
version = "0.1.0"

[dependencies]
ink = { version = "=5.1.0", default-features = false, features = ["ink-debug"] }
pop-api = { path = "../../../pop-api", default-features = false, features = [
"fungibles",
] }
sp-io = { version = "23.0.0", default-features = false, features = ["disable_allocator", "disable_oom", "disable_panic_handler"] }
sp-runtime = { version = "24.0.0", default-features = false }

[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 = "src/lib.rs"

[features]
default = ["std"]
e2e-tests = []
ink-as-dependency = []
std = [
"ink/std",
"pop-api/std",
"sp-io/std",
"sp-runtime/std",
]
53 changes: 53 additions & 0 deletions pop-api/examples/dao/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# PSP22 DAO contract example

## Description
This contract implements a Decentralized Autonomous Organization using Psp22.
The key functionalities include:
- **Membership Management**: It maintains a registry of DAO members.
- **Proposal Lifecycle**: The contract manages the creation, voting, and execution of proposals. Each proposal includes details like description, voting period, vote tallies, execution status, beneficiary, and amount to be awarded.
- **Voting Mechanism**: It implements a voting system where members can vote with their balance on proposals. The contract tracks voting periods and maintains vote counts for each proposal.
- **Token Integration**: The DAO is associated with a specific Psp22 token_id.
- **Governance Parameters**: governance parameters such as voting periods are customizable.
- **Vote Tracking**: The contract keeps track of when members last voted.
- **Proposal Execution**: Once a proposal's voting period ends and passes, the contract handles its execution: transferring funds to the chosen beneficiary.


## Dao Workflow
- **Subscription**: The first step is membership: users use their funds* to join the Dao, become members, and determine their voting power, as membership gives them the right to vote on the use of the Dao Treasury.
- **Proposal**: Dao members can create spending proposals for the treasury. At the moment, the voting period for the proposal is given by the proposal creator, but this could be a Dao parameter, determined by the creator of the Dao contract.
- **Vote**: Members of the Dao can vote for or against a given proposal, through the selection of the corresponding proposal ID. The vote has to be cast within the voting period of the selected proposal.
- **Proposal enactment**: After the end of the voting period, If the proposal has been accepted by the Dao Members, the proposal can be enacted, i.e. funds can be claimed/transferred to the account specified as the beneficiary in the proposal. Any member can claim the reward for the winning proposal.

*It is assumed that after Dao & associated token creation, potential members own the Dao Token through airdrop, token purchase, etc... (These mechanisms are not part of the contract).

### Flowchart

```mermaid
flowchart LR
A[Subscriber A] -->|Joins DAO| M[Membership Process]
B[Subscriber B] -->|Joins DAO| M
C[Subscriber C] -->|Joins DAO| M
D[Subscriber D] -->|Joins DAO| M
M --> E[Subscriber B creates Proposal]
E --> F[Voting Process]
F -->|Votes by| G[Subscribers A, C, D]
G --> H{Proposal Accepted?}
H -- Yes --> I[Proposal Enactment]
H -- No --> J[End of Process]
I --> K[Subscriber A claims reward for proposal's beneficiary]
K --> L[Funds transferred to beneficiary]

style A fill:#f9f,stroke:#333,stroke-width:2px
style B fill:#f9f,stroke:#333,stroke-width:2px
style C fill:#f9f,stroke:#333,stroke-width:2px
style D fill:#f9f,stroke:#333,stroke-width:2px
style M fill:#bbf,stroke:#333,stroke-width:2px
style E fill:#bbf,stroke:#333,stroke-width:2px
style F fill:#bbf,stroke:#333,stroke-width:2px
style G fill:#bbf,stroke:#333,stroke-width:2px
style H fill:#ff0,stroke:#333,stroke-width:2px
style I fill:#bfb,stroke:#333,stroke-width:2px
style J fill:#f99,stroke:#333,stroke-width:2px
style K fill:#bfb,stroke:#333,stroke-width:2px
style L fill:#bfb,stroke:#333,stroke-width:2px
```
Loading
Loading