-
Notifications
You must be signed in to change notification settings - Fork 8
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
base: main
Are you sure you want to change the base?
Conversation
@chungquantin , I wrote a first test, but it's failing with an error that I don't fully understand: |
Are you using pop-drink to write the test? |
No, should I? I will look into it. |
I am now using |
This is because when a contract uses the As a result, the tests need something like a chain running. This is where |
Add the following two lines in your
As well as the following line at the top of your contract:
To generate a new contract with all the requirements you can use the In your |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The contract looks great! I left some fixes to make your contract compile and left comment regarding the use of Strings in contracts. Don't forget to use cargo test --release
to run the pop drink
tests.
In terms of the dao logic, it would be great if you could document how the should dao operates. This would make it easier in the future to review the contract.
And super awesome that you are developing a contract using the api. Please note down all the things that are difficult in your journey so that we can improve them!! In general for ink! but also using the api, the docs, pop drink
, everything :):):)
I'm struggling with pop-drink: thread 'tests::member_create_proposal_works' panicked at /home/kazu/.cargo/git/checkouts/pop-drink-006524d3c8dd1ad9/cfbc763/crates/pop-drink/src/lib.rs:192:8:
Expected call to revert or return a value Removing the comment at |
@ndkazu pop-drink tests must be run with
|
Thanks! forgot about that one. |
@chungquantin & @Daanvdplas, review requested: struggling with the use of a RuntimeCall for proposal enactment. |
RuntimeCall version now working => Good step for a code review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far so good! Haven't reviewed the test yet.
pop-api/examples/dao/src/lib.rs
Outdated
|
||
// RuntimeCall transfer, you must comment api::transfer_from() below | ||
let _ = self.env() | ||
.call_runtime(&RuntimeCall::Fungibles(FungiblesCall::TransferFrom { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To extend the functionality of the runtime call and not limit it only to TransferFrom
, you can allow the creator of the proposal to provide parameters for the runtime call in bytes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chungquantin , could you point me to an example for this please.
I was thinking about adding a field call: Option<RuntimeCall>
, to the struct Proposal
(possibly call: Option<Box<RuntimeCall>>
for variable lifetime considerations), and then we would have:
#[ink(message)]
pub fn create_proposal(
&mut self,
beneficiary: AccountId,
amount: Balance,
mut description: Vec<u8>,
call: RuntimeCall,
) -> Result<(), Error> {
...
let wrapped_call = Some(call);
self.proposal_count = self.proposal_count.saturating_add(1);
let mut proposal =
Proposal { proposal_id: self.proposal_count, call: wrapped_call, ..Default::default() };
...
}
and then, in execute_proposal
, we would just do:
let call = proposal.call.clone().expect("There should be a call");
let _ = self.env().call_runtime(&call).map_err(EnvError::from);
The problem is then how do I test it, the Type RuntimeCall
is not easily convertible to String
, but I saw a crate that converts enums
to strings
. let me know.
Hello @chungquantin & @Daanvdplas , I am still trying to solve this and and need some feedback please: the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What an amazing work! Bravo for writing the first contract using the pop api and write tests using pop drink, you are the first one!!
Before doing a proper review on the contract there needs to be agreed on what the example contract should be. For an example contract it is important to define a clear use case. Right now there are few options we can finalise towards:
- A dao where people can vote on proposals where the native token is transferred to a given account (makes me think of the tips pallet from the sdk)
- A dao where people can vote on proposals where any kind of RuntimeCall is called
- ...
Option 1 could for example turn into one of the following examples:
- Community Fund Management: Manage a treasury where members can propose and vote on funding community projects.
- Grant Distribution: Allocate funds to developers or projects based on proposals and voting.
Option 2 gets a lot more complex to find an easy to explain use case. But perhaps OpenGov in a contract. This however will require more work and might be too complex for an example.
It doesn't have to be complicated or perfect at all, but people should understand what the contract example is about by looking at the title or the introduction, for them to get excited to learn about this specific example :)
I will be following this issue closer so that we can agree on the use case for the example. Then perhaps it requires some changes, but then I am ready to give it a review!!
Super excited to see this example in the repo!
One additional point is that I don't understand the incentive for joining the dao. If I buy myself in and all the dao's tokens are spent to e.g. projects, what do I win from this? It could be a charity funding dao perhaps, this would have to be included in the use case however. I don't want to overcomplicate the example at all, but the use case should make sense and be complete otherwise I think it would demotivate people to look into the example. More then happy to help here in every way!! |
Thank you for the feedback, @Daanvdplas!! I agree that as an example, the contract should be relatively simple, using too many advanced features in one contract could be daunting for people "Just diving in...". |
How do you become a member of the community that holds the funds? |
@Daanvdplas in OPF you only have to be a DOT holder: you lock some funds as voting power during the voting period. |
I think we should go with option 1. Perhaps we can find a popular dao contract example that functions the same / similar and see how they tell the story of the use case and tell it in a way that it doesn't matter that it is perfectly thought out, as that is the feeling I have now (regarding the incentive to join this dao). Another solution is to add ideas for how to solve this and provide it in the readme! Let me know if you agree with taking option 1 then I can do a review. |
@Daanvdplas I agree, and opened another PR for option_1 as the latest commit here is oriented toward option_2: we can keep it for later. |
Description
Issue #337
This contract implements a Decentralized Autonomous Organization using Psp22.
The key functionalities include:
ToDo
Remark
Considering the fact that another issue is asking for psp22 examples using cross contract call, I decided to use
api::...
instead of the macrocontract_ref!
.