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

Proposal Incentives & Voting Incentives #797

Open
wants to merge 49 commits into
base: development
Choose a base branch
from

Conversation

ismellike
Copy link
Contributor

@ismellike ismellike commented Jan 31, 2024

Proposal Incentives Contract (dao-proposal-incentives):

A new contract has been added to implement incentives for making successful proposals in a DAO. This contract allows DAO's to offer rewards for successful proposals, which can be configured as native or CW20 tokens. The rewards are determined based on the configuration at the proposal's start time.

A new query has been added to the proposal modules for GenericProposalInfo, which we can call from a received hook to get a proposal's proposer and start_time.

A new query has been added to the DAO core for ProposalModule, which we can call from the incentives contract to check authorization of the sender as a proposal module of the DAO.

Voting Incentives Contract (dao-voting-incentives):

The voting incentives contract is adapted from the proposal incentives contract.

When a vote hook is received, its proposal is queried to make sure the proposal occurred after the contract was instantiated (config.start_height). If the user has already voted, then we ignore the vote. Otherwise, we increment config.total_vote_count and the user's votes. From this, we can determine how much a user will be awarded after the voting incentives' expiration. If no users have voted during the voting incentives' period, then the funds will be sent to the contract's owner on expiration.

Anyone can call the expire function to set the amount available for distribution. Users can then call ExecuteMsg::Claim{} to receive their rewards.

@ismellike ismellike marked this pull request as draft January 31, 2024 21:09
@JakeHartnell
Copy link
Member

@ismellike, the proposal incentives contract looks great!

I think there's a bug in the removal of multiple hooks at the same time
.unwrap();
let results = vote_yes_on_proposal(&mut context, 3u64);
for (i, result) in results.iter().enumerate() {
assert!(result.is_ok());
Copy link
Contributor Author

@ismellike ismellike Feb 8, 2024

Choose a reason for hiding this comment

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

This actually panics, because the hooks simultaneously return an error of expiration.
When the error is processed in the proposal module, it tries to remove by index on a list that has changed already.

thread 'tests::test_hooks' panicked at packages/cw-hooks/src/lib.rs:60:26:
removal index (is 1) should be < len (is 1)

VoteHook of index 0 is successfully removed at index 0, but VoteHook of index 1 tries to be removed at index 1 of a list of length 1.

Copy link
Contributor Author

@ismellike ismellike Feb 9, 2024

Choose a reason for hiding this comment

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

I added a new method in cw-hooks for remove_hook_by_index_from_reply that takes a new parameter removed_hook_indexes: Item<Vec<u64>>.

We can adjust the given index to the actual index from this new tracked state on the proposal modules: REMOVED_VOTE_HOOKS_BY_INDEX or REMOVED_PROPOSAL_HOOKS_BY_INDEX

@ismellike ismellike marked this pull request as ready for review February 10, 2024 21:39
@JakeHartnell
Copy link
Member

Can we rebase? In the README for these contracts make sure we note that they aren't audited.

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

Successfully merging this pull request may close these issues.

2 participants