-
Notifications
You must be signed in to change notification settings - Fork 142
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
Cwd proposal delegate #562
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportBase: 95.07% // Head: 94.29% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #562 +/- ##
==========================================
- Coverage 95.07% 94.29% -0.78%
==========================================
Files 41 43 +2
Lines 3775 3873 +98
==========================================
+ Hits 3589 3652 +63
- Misses 186 221 +35
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
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.
🫡 cool! super clean. let's land this :)
cosmwasm/rust-optimizer:0.12.6 | ||
""" | ||
|
||
[dependencies] |
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.
all of these can be cosmwasm-x = { workspace = true }
REPLY_ID_EXECUTE_PROPOSAL_HOOK => { | ||
let id = EXECUTE_CTX.load(deps.storage)?; | ||
let Delegation { | ||
policy_preserve_on_failure, |
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.
this is sick
if let SubMsgResult::Err(_) = msg.result { | ||
// && with `let` expression above gives unstable Rust error | ||
if policy_preserve_on_failure { |
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.
if let SubMsgResult::Err(_) = msg.result { | |
// && with `let` expression above gives unstable Rust error | |
if policy_preserve_on_failure { | |
if msg.result.is_err() && policy_preserve_on_failure { |
fn query_delegation(deps: Deps, delegation_id: u64) -> StdResult<DelegationResponse> { | ||
let delegation = DELEGATIONS.load(deps.storage, delegation_id)?; | ||
Ok(delegation) | ||
} |
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.
probably want to make this a paginated function so that FE can list all of the delegations pending. packages/cw-paginate
should make that simple
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.
cool!
fn query_delegation_count(deps: Deps) -> StdResult<DelegationCountResponse> { | ||
let count = DELEGATION_COUNT.load(deps.storage)?; | ||
Ok(DelegationCountResponse { count }) | ||
} |
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.
idea: why expose this at all? all we use it for is a nonce for delegations. let's make it a private state variable and only expose a function for incrementing it. gets us pretty close to correct-by-constructuon!
ex:
pub(crate) fn advance_current_id(store: &mut dyn Storage) -> StdResult<u64> {
let CURRENT_ID: Item<u64> = Item::new("current_id");
let id: u64 = CURRENT_ID.may_load(store)?.unwrap_or_default() + 1;
CURRENT_ID.save(store, &id)?;
Ok(id)
}
if info.sender != admin { | ||
return Err(ContractError::Unauthorized {}); | ||
} | ||
assert_not_expired(&delegation.expiration, &env.block)?; |
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.
nice check
} | ||
// If delegation is irrevocable, return Error | ||
let Delegation { | ||
policy_irrevocable, .. |
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's the reason for having this option? i feel things like this can give fake guarantees if the contract is instantiated with a DAO as it's admin. should we be instantiating this without an admin perhap?
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.
good point. The DAO could always remove the proposal module and all delegations would be revocable. However, that would eliminate all their existing delegations as well. There's 2 options to go with this:
- Rename the policy to
policy_module_irrevocable
and add a warning - Remove the policy altogether
// Add any other custom errors you like here. | ||
// Look at https://docs.rs/thiserror/1.0.21/thiserror/ for details. |
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.
// Add any other custom errors you like here. | |
// Look at https://docs.rs/thiserror/1.0.21/thiserror/ for details. |
Will integrate changes and start on the tests! A bit slow on this, been grokking some Cosmos stuff. Need to learn Go, how dreadful |
Co-authored-by: ekez <[email protected]>
Co-authored-by: ekez <[email protected]>
Cosm-Orc Gas UsageNo gas diff larger than 0.5% Raw Report for b8e34e3
|
Ok, last commits were:
Lmk. |
Need design review before I start writing tests! : )
Low prio, no hurries. Thought would be fun first contract to write for DaoDao.