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

WIP New deposit features #465

Closed
wants to merge 5 commits into from
Closed

WIP New deposit features #465

wants to merge 5 commits into from

Conversation

JakeHartnell
Copy link
Member

@JakeHartnell JakeHartnell commented Aug 23, 2022

Refactor proposal deposits to support new features.

DON'T MERGE. We may choose a different approach.

@codecov-commenter
Copy link

codecov-commenter commented Aug 23, 2022

Codecov Report

Merging #465 (813b6ff) into main (9df2d58) will decrease coverage by 0.10%.
The diff coverage is 85.41%.

❗ Current head 813b6ff differs from pull request most recent head 768adae. Consider uploading reports for the commit 768adae to get more accurate results

@@            Coverage Diff             @@
##             main     #465      +/-   ##
==========================================
- Coverage   95.81%   95.71%   -0.11%     
==========================================
  Files          34       34              
  Lines        5448     5460      +12     
==========================================
+ Hits         5220     5226       +6     
- Misses        228      234       +6     
Impacted Files Coverage Δ
contracts/cw-proposal-multiple/src/state.rs 100.00% <ø> (ø)
packages/voting/src/deposit.rs 88.09% <78.26%> (-11.91%) ⬇️
contracts/cw-proposal-multiple/src/contract.rs 95.57% <90.90%> (-0.28%) ⬇️
contracts/cw-proposal-single/src/contract.rs 93.97% <92.85%> (+0.03%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@0xekez 0xekez left a comment

Choose a reason for hiding this comment

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

This is great. :) Cool to see an example of cw-asset being used - simpler code and we get to support both native and cw20 tokens.

Left comments as if we'd like to merge. I'm thinking the play here though is probably to leave this open for a bit and use it as a jumping off point to start on #462.

Appreciate you getting this moving and all the thoughts on deposits!

ci/integration_tests/src/helpers/helper.rs Show resolved Hide resolved
Comment on lines +434 to +435
// If no refunds, or failed proposals not refund, funds go to DAO
_ => get_return_deposit_msg(deposit_info, &config.dao)?,
Copy link
Contributor

Choose a reason for hiding this comment

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

These match statements might be nice to actually fully write out. It's probably a desirable feature that adding a new variant will cause a compile error and force us to check this logic again. I do love how clean this is though lol

Suggested change
// If no refunds, or failed proposals not refund, funds go to DAO
_ => get_return_deposit_msg(deposit_info, &config.dao)?,
// If no refunds, or failed proposals not refund, funds go to DAO
DepositRefundPolicy::Never | DepositRefundPolicy::OnlyPassed => get_return_deposit_msg(deposit_info, &config.dao)?,

Comment on lines +99 to +101
_ => Err(StdError::GenericErr {
msg: String::from("Unsupported asset"),
}),
Copy link
Contributor

Choose a reason for hiding this comment

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

Will want to add a custom error here if we choose to merge this before doing the refactor.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I was lazy.

@github-actions
Copy link

gas Cosm-Orc Gas Usage Report gas

Contract Op Name Gas Used Old Gas Used Gas Diff File
cw_proposal_multiple Store__Store 52626400 51285390 +2.6148% ci/integration_tests/src/helpers/chain.rs:82
cw_proposal_single Store__Store 53084220 51816580 +2.4464% ci/integration_tests/src/helpers/chain.rs:82
Raw Report for 55dec40
Contract Op Name Gas Used Gas Wanted File
cw_core Execute__exc_items_rm 192600 264389 ci/integration_tests/src/tests/cw_core_test.rs:174
cw_core Execute__exc_items_set 194267 266889 ci/integration_tests/src/tests/cw_core_test.rs:139
cw_core Instantiate__exc_items_create_dao 979863 1445190 ci/integration_tests/src/helpers/helper.rs:89
cw_core Instantiate__inst_admin_create_dao 979863 1445190 ci/integration_tests/src/helpers/helper.rs:89
cw_core Instantiate__inst_dao_no_admin 978814 1443617 ci/integration_tests/src/helpers/helper.rs:89
cw_core Store__Store 44938280 67382780 ci/integration_tests/src/helpers/chain.rs:82
cw_core Execute__exc_admin_msgs_pause_dao 194393 267078 ci/integration_tests/src/tests/cw_core_test.rs:79
cw_core Instantiate__exc_admin_msgs_create_dao 978814 1443617 ci/integration_tests/src/helpers/helper.rs:89
cw_core Instantiate__exc_admin_msgs_create_dao_with_admin 979863 1445190 ci/integration_tests/src/helpers/helper.rs:89
cw_core Instantiate__exc_stake_create_dao 978790 1443581 ci/integration_tests/src/helpers/helper.rs:89
cw20_base Store__Store 34725990 52064345 ci/integration_tests/src/helpers/chain.rs:82
cw20_base Execute__exc_stake_stake_tokens 234580 319226 ci/integration_tests/src/tests/cw20_stake_test.rs:72
cw20_stake Store__Store 29024865 43512986 ci/integration_tests/src/helpers/chain.rs:82
cw20_staked_balance_voting Store__Store 29469420 44179490 ci/integration_tests/src/helpers/chain.rs:82
cw4_group Store__Store 21882500 32799110 ci/integration_tests/src/helpers/chain.rs:82
cw4_voting Store__Store 21842460 32739050 ci/integration_tests/src/helpers/chain.rs:82
cw721_stake Store__Store 31174530 46737155 ci/integration_tests/src/helpers/chain.rs:82
cw_admin_factory Store__Store 16212880 24294680 ci/integration_tests/src/helpers/chain.rs:82
cw_named_groups Store__Store 19605940 29384270 ci/integration_tests/src/helpers/chain.rs:82
cw_names_registry Store__Store 21283000 31899860 ci/integration_tests/src/helpers/chain.rs:82
cw_native_staked_balance_voting Store__Store 24396550 36570185 ci/integration_tests/src/helpers/chain.rs:82
cw_proposal_multiple Store__Store 52626400 78914960 ci/integration_tests/src/helpers/chain.rs:82
cw_proposal_single Store__Store 53084220 79601690 ci/integration_tests/src/helpers/chain.rs:82
cw_token_swap Store__Store 19325330 28963355 ci/integration_tests/src/helpers/chain.rs:82
stake_cw20_external_rewards Store__Store 25509310 38239325 ci/integration_tests/src/helpers/chain.rs:82
stake_cw20_reward_distributor Store__Store 19374500 29037110 ci/integration_tests/src/helpers/chain.rs:82

Comment on lines 44 to 53
pub struct CheckedDepositInfo {
/// The address of the cw20 token to be used for proposal
/// deposits.
pub token: Addr,
pub token: AssetInfo,
/// The number of tokens that must be deposited to create a
/// proposal.
pub deposit: Uint128,
/// If failed proposals should have their deposits refunded.
pub refund_failed_proposals: bool,
pub refund_policy: DepositRefundPolicy,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a subtle one, but this change actually breaks v1 -> v2 migration logic. That logic expects that a v1 deposit info struct will deserialize into this type. By changing the layout, we break that.

Can probably hold off on updating the code until I've got a pre-propose module PR up and we decide if we'd like to merge this.

@JakeHartnell JakeHartnell changed the title New deposit features WIP New deposit features Aug 31, 2022
let asset = AssetBase::new(info.token.clone(), info.deposit);
let transfer_msg = match asset.info {
AssetInfoBase::Cw20(ref _addr) => asset.transfer_from_msg(sender, contract),
AssetInfoBase::Native(ref _denom) => asset.transfer_msg(contract),
Copy link
Contributor

@0xekez 0xekez Aug 31, 2022

Choose a reason for hiding this comment

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

Another tricky one. This won't actually require the deposit to be paid if, at the time of proposal creation, there are are info.deposit or more tokens in the proposal module.

Tests don't catch this because they're only testing the case where a single proposal being created. In that case the contract has zero native tokens so not paying the deposit will cause it to transfer info.deposit tokens to itself which it does not have. If it already had a deposit inside of it that would work regardless of if the proposer paid the deposit.

Great example of why breaking this logic out and having it fail open is so important. Deposits are surprisingly tricky to get right and do elegantly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, really good catch.

@JakeHartnell
Copy link
Member Author

JakeHartnell commented Sep 3, 2022

Closing in favor of #473

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