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

Make native staked DAO-DAO voting, have SDK hooks that call into it for stake changes #543

Open
ValarDragon opened this issue Nov 19, 2022 · 1 comment
Labels
feature A new exciting feature.
Milestone

Comments

@ValarDragon
Copy link

DAO DAO voting for natively staked coins can be more powerful, if we make an SDK module that just listens for all delegate, undelegate, and redelegate hooks. Then on each of these hooks, calls a sudo message to a pre-configured contract.

This would let us have a more powerful wrapper for governance! They could now compute the current semantic of "Voting power = stake at end of voting period", with no iteration at end time for instance. (The only iteration needed, would be to reclaim state, but we can have a separate process for that. Espec. if we make a gas token like dynamic)

Or we could switch semantics to "voting power = stake at beginning of voting period", or my favorite "voting duration = k days. Voting power = sum of stake_at_time_i * voting decision_at_time_i for times in the final day of voting" (to protect against last second vote attacks)

If we make an SDK module for communicating stake change events during the voting period, then we can unlock all of these capabilities for DAO DAO voting.

@JakeHartnell
Copy link
Member

JakeHartnell commented Nov 20, 2022

DAO DAO voting for natively staked coins can be more powerful, if we make an SDK module that just listens for all delegate, undelegate, and redelegate hooks. Then on each of these hooks, calls a sudo message to a pre-configured contract.

Woah. This would be amazing. I think it would be useful for many other things as well!

FWIW, we do allow for native staked voting in DAO DAO V2... though I'm not 100% convinced it's the best implementation: https://github.com/DA0-DA0/dao-contracts/tree/main/contracts/voting/cwd-voting-staking-denom-staked

Basically...

pub fn query_voting_power_at_height(
    deps: Deps,
    env: Env,
    address: String,
    height: Option<u64>,
) -> StdResult<VotingPowerAtHeightResponse> {
    // We can ignore height as we are protected by the chain's unstaking
    // duration
    let denom = deps.querier.query_bonded_denom()?;
    let delegations = deps.querier.query_all_delegations(address)?;
    let power = delegations
        .iter()
        .filter_map(|d| {
            if d.amount.denom == denom {
                Some(d.amount.amount)
            } else {
                None
            }
        })
        .reduce(|a, b| a.checked_add(b).unwrap())
        .unwrap_or_default();

    Ok(VotingPowerAtHeightResponse {
        power,
        height: height.unwrap_or(env.block.height),
    })
}

pub fn query_total_power_at_height(
    deps: Deps,
    env: Env,
    height: Option<u64>,
) -> StdResult<TotalPowerAtHeightResponse> {
    let staking_module = STAKING_MODULE.load(deps.storage)?;
    let denom = deps.querier.query_bonded_denom()?;
    let power = deps.querier.query_balance(staking_module, denom)?;
    Ok(TotalPowerAtHeightResponse {
        power: power.amount,
        height: height.unwrap_or(env.block.height),
    })
}

@JakeHartnell JakeHartnell added this to the v3.0 milestone Aug 30, 2023
@JakeHartnell JakeHartnell added the feature A new exciting feature. label Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new exciting feature.
Projects
None yet
Development

No branches or pull requests

2 participants