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

Clean incentives state when users unstake #436

Closed
wants to merge 14 commits into from

Conversation

markonmars
Copy link
Collaborator

@markonmars markonmars commented Oct 10, 2024

When users unstake from Astroport via Mars incentives contract, we should clean up the state if the user has no more position.

We should also do the same if the denom has no positions (i.e TOTAL_STAKED_LP = 0)

// - LP in incentives = 300 (user_a 100, user_b 200)
// - Rewards available for user_1 = 0
// - Rewards available for user_2 = 0
assert_eq!(
Copy link
Collaborator

Choose a reason for hiding this comment

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

The bug should be isolated to separate test case to show exactly where is the problem.
Right now is composed between full LP lifecycle and here we check what is expected (I checked first commit on the branch) vs raising existing problem with invalid rewards amount in the contract.

I would recommend to use example from this branch https://github.com/mars-protocol/contracts-internal/pull/117
This way we can see real funds transfer and actual error not like this on first commit on this branch:

assertion `left == right` failed
  left: Some(Uint128(0))
 right: None

let prefix = USER_ASTRO_INCENTIVE_STATES.prefix((account_id, lp_coin.denom.as_str()));

// Iterate over all reward_denom keys
let keys_to_remove: Vec<String> =
Copy link
Collaborator

Choose a reason for hiding this comment

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

Better to raise error for a key (not filter out)...

I would use:
let keys_to_remove: StdResult<Vec<String>> = prefix.keys(store, None, None, Order::Ascending).collect();
or
let keys_to_remove = prefix.keys(store, None, None, Order::Ascending).collect::<StdResult<Vec<String>>>()?;


// Get all incentive states for the lp_key
let prefix = ASTRO_INCENTIVE_STATES.prefix(lp_key);
let keys_to_remove: Vec<_> =
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here. See comment for line 265

@piobab
Copy link
Collaborator

piobab commented Oct 10, 2024

@markonmars remember about this one (if rewards already claimed in the same block):
telegram-cloud-photo-size-4-5776364201894331878-y

And ideally we could improve logging just in case for future. Maybe you found something worth to include:
https://github.com/mars-protocol/contracts-internal/pull/130

markonmars and others added 10 commits October 14, 2024 11:39
* fix spelling types_diff_v1_0_0__mars_v2.txt

* fix spelling issue test_incentives.rs

* add auxiliary verb health_computer.rs
* Init devnet config for neutron.

* Update params.

* Update config to match mainnet data.

* Include dAtom asset params.

* Update HLS setup.

* Comment out price checking.

* Disabled dAtom/Atom lp whitelisting.

* Redemption rate for dAtom price source.
* Bump minor cw version.

* Update optimizer and rust version.

* Mars ver to 2.1.0, cleanup migrations, fix clippy.
@markonmars
Copy link
Collaborator Author

closing, replaced with #437

@markonmars markonmars closed this Oct 15, 2024
@markonmars markonmars deleted the MP-2662-fix-incentives-bug branch October 15, 2024 06:18
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.

3 participants