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

feat(dAppStaking): Move actions for bonus rewards #1418

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

Dinonard
Copy link
Member

@Dinonard Dinonard commented Feb 2, 2025

Pull Request Summary

Closes #1379

This PR introduces enhancements to the bonus reward eligibility mechanism and implements robust handling for stake movement, particularly during the build&earn subperiod.

The approach aims to first adapt existing pallet to easily support move functionality.
Pallet has a lot of tests covering stake & unstake functioality, and in case MAX_BONUS_MOVES = 1, every legacy test must work same as before.

Changes

  • logic from stake, unstake and unstake_from_unregistered is moved to separate functions, with minimal modifications
  • it's important for unstake to return more comprehensive information of what was unstaked
  • types are modified to return necessary information for the higher level functionality
  • test files are adapted to ensure that high level (extrinsic) tests are passing
  • move extrinsic, using inner_unstake and inner_stake functions (or unstake_from_unregistered) as the building blocks

Bonus Reward Eligibility

The previously used loyal_staker flag is replaced with a bonus_status u8 type.
The number of allowed move actions is defined by a config parameter (MaxBonusSafeMovesPerPeriod); bonus is forfeited if move actions exceed this value.

Move action

A move action is defined as either:

  • Partial unstaking that reduces the 'voting stake'.
  • Transfers of 'voting stake' between contracts.

If a move action is performed during the build&earn subperiod, the bonus_status attached to the relevant singular staking info is reduced until it is forfeited.

Stake Movement Enhancements

A new move_stake extrinsic is implemented. It is similar to an 'unstake' followed by a 'stake'. Existing safeguards are extended additional checks to:

  • Ensure the source and destination contracts are different.
  • Validate the amount to be moved.

When moving stake from unregistered contracts, the bonus status is always preserved.

Migration

This PR introduces the update_bonus extrinsic, which updates loyal_staker flags from the previous 0 move actions limit to the new value set by MaxBonusSafeMovesPerPeriod. The change will take effect in a future runtime upgrade when the config parameters are updated.

Check list

  • added or updated unit tests
  • updated Astar official documentation
  • update dAppStaking precompile
  • added benchmarks & weights for any modified runtime logics.
  • add E2E tests
  • prepare follow-up issue for Astar Portal frontend & forum post

@Dinonard
Copy link
Member Author

Dinonard commented Feb 2, 2025

@ipapandinas please check the concept.

@Dinonard Dinonard added shiden related to shiden runtime astar Related to Astar shibuya related to shibuya runtime This PR/Issue is related to the topic “runtime”. labels Feb 6, 2025
Copy link
Member Author

@Dinonard Dinonard left a comment

Choose a reason for hiding this comment

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

Great work 👏
The types tests look like it was hellish to update 🙈

pallets/dapp-staking/src/benchmarking/mod.rs Show resolved Hide resolved
pallets/dapp-staking/src/lib.rs Outdated Show resolved Hide resolved
pallets/dapp-staking/src/lib.rs Outdated Show resolved Hide resolved
pallets/dapp-staking/src/test/mock.rs Outdated Show resolved Hide resolved
pallets/dapp-staking/src/test/testing_utils.rs Outdated Show resolved Hide resolved
pallets/dapp-staking/src/test/testing_utils.rs Outdated Show resolved Hide resolved
pallets/dapp-staking/src/test/tests.rs Outdated Show resolved Hide resolved
pallets/dapp-staking/src/types.rs Outdated Show resolved Hide resolved
pallets/dapp-staking/src/types.rs Show resolved Hide resolved
pallets/dapp-staking/src/lib.rs Show resolved Hide resolved
Copy link
Member Author

@Dinonard Dinonard left a comment

Choose a reason for hiding this comment

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

Haven't checked testing_utils in detail.

pallets/dapp-staking/src/lib.rs Outdated Show resolved Hide resolved
pallets/dapp-staking/src/types.rs Outdated Show resolved Hide resolved
pallets/dapp-staking/src/types.rs Outdated Show resolved Hide resolved
pallets/dapp-staking/src/test/testing_utils.rs Outdated Show resolved Hide resolved
Copy link
Member Author

@Dinonard Dinonard left a comment

Choose a reason for hiding this comment

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

Few additional comments, hope to discuss it more since I might not be aware of some issues.

pallets/dapp-staking/src/types.rs Outdated Show resolved Hide resolved
pallets/dapp-staking/src/lib.rs Outdated Show resolved Hide resolved
pallets/dapp-staking/src/lib.rs Outdated Show resolved Hide resolved
@ipapandinas ipapandinas self-assigned this Feb 13, 2025
@ipapandinas ipapandinas changed the title Concept adaptation for move functionality feat(dAppStaking): Move actions for bonus rewards Feb 13, 2025
@ipapandinas ipapandinas added the enhancement New feature or request label Feb 13, 2025
@ipapandinas ipapandinas marked this pull request as ready for review February 13, 2025 14:00
Copy link

Code Coverage

Package Line Rate Branch Rate Health
pallets/astar-xcm-benchmarks/src 86% 0%
chain-extensions/pallet-assets/src 54% 0%
pallets/ethereum-checked/src 76% 0%
precompiles/dapp-staking/src/test 0% 0%
precompiles/unified-accounts/src 100% 0%
primitives/src/xcm 62% 0%
pallets/unified-accounts/src 81% 0%
pallets/collator-selection/src 87% 0%
chain-extensions/types/assets/src 0% 0%
pallets/price-aggregator/src 75% 0%
pallets/astar-xcm-benchmarks/src/generic 100% 0%
pallets/collective-proxy/src 94% 0%
precompiles/dapp-staking/src 89% 0%
pallets/static-price-provider/src 91% 0%
pallets/dapp-staking/rpc/runtime-api/src 0% 0%
pallets/dapp-staking/src 78% 0%
pallets/xc-asset-config/src 48% 0%
chain-extensions/types/unified-accounts/src 0% 0%
pallets/astar-xcm-benchmarks/src/fungible 100% 0%
precompiles/dispatch-lockdrop/src 83% 0%
pallets/dapp-staking/src/benchmarking 95% 0%
chain-extensions/unified-accounts/src 0% 0%
pallets/inflation/src 90% 0%
precompiles/assets-erc20/src 78% 0%
precompiles/xcm/src 69% 0%
precompiles/sr25519/src 56% 0%
precompiles/substrate-ecdsa/src 67% 0%
primitives/src 54% 0%
pallets/vesting-mbm/src 87% 0%
pallets/dynamic-evm-base-fee/src 85% 0%
pallets/dapp-staking/src/test 0% 0%
Summary 76% (3682 / 4873) 0% (0 / 0)

Minimum allowed line rate is 50%

pallets/dapp-staking/src/benchmarking/mod.rs Show resolved Hide resolved
pallets/dapp-staking/src/types.rs Show resolved Hide resolved
pallets/dapp-staking/src/types.rs Show resolved Hide resolved
pallets/dapp-staking/src/types.rs Show resolved Hide resolved
Comment on lines +982 to +994
let entries: Vec<StakeAmount> = stake_amount_entries.into_iter().collect();
match entries.as_slice() {
[single_entry] => {
let amount = single_entry.total();
self.current_stake_amount.subtract(amount);
self.next_stake_amount.subtract(amount);
}
[entry_current, entry_next] => {
self.current_stake_amount.subtract(entry_current.total());
self.next_stake_amount.subtract(entry_next.total());
}
_ => {} // Ignore cases with more than 2 entries or empty input - this should never happen
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Shouldn't eras in the iter be matching with the ones in owned fields at this point?

I'm asking this since it's weird to see different approach compared to the one in pub fn unstake(.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure to understand this one, could you rephrase it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure - I meant to say that in the other unstake method (which takes era_and_amount_pairs: Vec<(EraNumber, Balance)>, as argument), we iterate over the received values, and subtract the value from either self.staked or self.staked_future, whichever matches the provided era argument.

My suggestion is to apply the same approach here, instead of making positional assumptions.

pallets/dapp-staking/src/test/tests.rs Show resolved Hide resolved
let expected_dest_staking_info = SingularStakingInfo {
previous_staked: StakeAmount {
voting: 100,
build_and_earn: 150, // TODO: should it not be 0 here?
Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it should remain unchanged.

pallets/dapp-staking/src/test/tests.rs Show resolved Hide resolved
pallets/dapp-staking/src/test/tests.rs Show resolved Hide resolved
@@ -460,6 +460,7 @@ impl pallet_dapp_staking::Config for Runtime {
type MinimumStakeAmount = MinimumStakingAmount;
type NumberOfTiers = ConstU32<4>;
type RankingEnabled = ConstBool<true>;
type MaxBonusSafeMovesPerPeriod = ConstU8<0>;
Copy link
Member Author

Choose a reason for hiding this comment

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

General question for all runtimes - did you try to test the migration extrinsic yet?

Copy link
Contributor

@ermalkaleci ermalkaleci left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astar Related to Astar enhancement New feature or request runtime This PR/Issue is related to the topic “runtime”. shibuya related to shibuya shiden related to shiden runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dAppStaking - Bonus rewards mechanism rework
3 participants