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

[Pools] fix derivation of pool account #4999

Merged
merged 78 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
11a0c44
migration test
Ank4n Jun 18, 2024
efd3324
fmt
Ank4n Jun 18, 2024
3f8d2fc
undo pool changes
Ank4n Jun 18, 2024
7388573
fixes all NotEnoughFunds error
Ank4n Jun 18, 2024
6634d25
return false if pool does not exist
Ank4n Jun 18, 2024
a3901a9
fix transfer on hold amount should still be held in dst acc
Ank4n Jun 18, 2024
462be1f
fmt
Ank4n Jun 18, 2024
c7e9f6c
unexpected errors check
Ank4n Jun 19, 2024
9a68720
all non staking accounts succeed when given minimum balance
Ank4n Jun 19, 2024
268d0a5
assert migrate tests
Ank4n Jun 19, 2024
000762f
remove clone
Ank4n Jun 21, 2024
a904fc8
uncomment
Ank4n Jun 21, 2024
0c776b8
incrementing provider fixes users migrating with zero balance
Ank4n Jun 29, 2024
699a2ec
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Jul 3, 2024
c3fa887
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Jul 5, 2024
3d2379e
test for clean up accounts
Ank4n Jul 6, 2024
ec9035c
providers are incremented correctly when migration agent/delegators
Ank4n Jul 6, 2024
a9d4595
migrated agents/delegators are also cleaned up correctly
Ank4n Jul 6, 2024
8a27ae0
improve remote tests
Ank4n Jul 6, 2024
8f77ac4
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Jul 7, 2024
7fd484a
add runtime api for total member balance
Ank4n Jul 7, 2024
9925a9f
ensure member can't bond extra if they are in unmigrated state
Ank4n Jul 7, 2024
4a9f35f
gate all calls if non migrated state as defensive measure
Ank4n Jul 7, 2024
bc3ce11
ensure all calls are gated
Ank4n Jul 7, 2024
5b91644
add runtime api for pool balance
Ank4n Jul 10, 2024
6ceb1ba
remove unused imports
Ank4n Jul 10, 2024
de48083
fix import
Ank4n Jul 11, 2024
fd8a451
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Jul 11, 2024
ab2317b
fix test
Ank4n Jul 11, 2024
cfdaf90
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Jul 12, 2024
d5634c4
add prdoc
Ank4n Jul 12, 2024
0da9807
fix prdoc bump
Ank4n Jul 13, 2024
00f7e6f
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Jul 13, 2024
1514c2b
add missing crate to prdoc
Ank4n Jul 13, 2024
3dee9c4
remove unintended file
Ank4n Jul 13, 2024
a52f819
fix derivation of pool account
Ank4n Jul 11, 2024
41c01e6
fix import
Ank4n Jul 11, 2024
85498be
migration code
Ank4n Jul 18, 2024
172b14d
remove released migrations
Ank4n Jul 18, 2024
28fb070
fix clippy
Ank4n Jul 18, 2024
8c96add
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Jul 18, 2024
89c1964
fix agent count
Ank4n Jul 18, 2024
2440303
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Aug 6, 2024
3c24530
Merge branch 'ankan/delegate-stake-remote-tests' into ankan/delegated…
Ank4n Aug 6, 2024
66b5458
remove unnecessary conversion
Ank4n Aug 6, 2024
9ac94ee
fix import
Ank4n Aug 7, 2024
0bef5a9
minor fixes
Ank4n Aug 7, 2024
0c57ab7
missing import
Ank4n Aug 7, 2024
95bf173
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Aug 7, 2024
0115e7c
rustdoc fix
Ank4n Aug 7, 2024
c6eafa5
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Aug 7, 2024
b585901
Merge branch 'ankan/delegate-stake-remote-tests' into ankan/delegated…
Ank4n Aug 7, 2024
2e486db
remove condition for minimum balance when migrating delegation
Ank4n Aug 10, 2024
c209d9e
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Aug 10, 2024
3e945c4
Merge branch 'ankan/delegate-stake-remote-tests' into ankan/delegated…
Ank4n Aug 10, 2024
cbfbf6f
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Aug 12, 2024
acbb674
refactor based on pr comments
Ank4n Aug 12, 2024
65cecb5
allow migration lower than ED
Ank4n Aug 12, 2024
eab6f35
Merge branch 'ankan/delegate-stake-remote-tests' into ankan/delegated…
Ank4n Aug 12, 2024
94b2e8b
add prdoc
Ank4n Aug 12, 2024
4081f12
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Aug 13, 2024
17bccae
Merge branch 'ankan/delegate-stake-remote-tests' into ankan/delegated…
Ank4n Aug 13, 2024
00ab010
move remote tests to another file
Ank4n Aug 13, 2024
7326b10
fix below ed test
Ank4n Aug 13, 2024
8cdde30
move remote tests to another file
Ank4n Aug 13, 2024
99698d6
fix below ed test
Ank4n Aug 13, 2024
5e465f2
revert comment
Ank4n Aug 13, 2024
c38f83c
ensure there is atleast ED to transfer
Ank4n Aug 13, 2024
b3a3263
fix imports
Ank4n Aug 13, 2024
dfcdc42
Update substrate/frame/delegated-staking/src/lib.rs
Ank4n Aug 13, 2024
5082542
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Aug 13, 2024
bce9803
refactor inc dec of providers
Ank4n Aug 13, 2024
ae9a370
gate extrinsics on top level function
Ank4n Aug 13, 2024
251ba4c
fix clippy
Ank4n Aug 13, 2024
4ba0c97
remove empty line
Ank4n Aug 14, 2024
56c1075
Merge branch 'ankan/delegate-stake-remote-tests' into ankan/delegated…
Ank4n Aug 14, 2024
6d08f19
Merge branch 'master' into ankan/delegated-staking-fix-derivation
Ank4n Aug 14, 2024
a886fa9
fix rust doc
Ank4n Aug 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions substrate/frame/delegated-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,24 +567,25 @@ impl<T: Config> Pallet<T> {

let mut ledger = AgentLedger::<T>::get(&agent).ok_or(Error::<T>::NotAgent)?;

let new_delegation_amount =
if let Some(existing_delegation) = Delegation::<T>::get(&delegator) {
ensure!(existing_delegation.agent == agent, Error::<T>::InvalidDelegation);
existing_delegation
.amount
.checked_add(&amount)
.ok_or(ArithmeticError::Overflow)?
} else {
// if this is the first time delegation, increment provider count. This ensures that
// amount including existential deposit can be held.
frame_system::Pallet::<T>::inc_providers(&delegator);
amount
};
if let Some(mut existing_delegation) = Delegation::<T>::get(&delegator) {
ensure!(existing_delegation.agent == agent, Error::<T>::InvalidDelegation);
// update amount
existing_delegation.amount = existing_delegation
.amount
.checked_add(&amount)
.ok_or(ArithmeticError::Overflow)?;
existing_delegation
} else {
// if this is the first time delegation, increment provider count. This ensures that
// amount including existential deposit can be held.
frame_system::Pallet::<T>::inc_providers(&delegator);
Delegation::<T>::new(&agent, amount)
}
.update(&delegator);

// try to hold the funds.
T::Currency::hold(&HoldReason::StakingDelegation.into(), &delegator, amount)?;

let _ = Delegation::<T>::new(&agent, new_delegation_amount).update(&delegator);
ledger.total_delegated =
ledger.total_delegated.checked_add(&amount).ok_or(ArithmeticError::Overflow)?;
ledger.update(&agent);
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/nomination-pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3974,7 +3974,8 @@ impl<T: Config> Pallet<T> {

/// Contribution of the member in the pool.
///
/// Includes balance that is unbonding currently.
/// Includes balance that is unbonded from staking but not claimed yet from the pool, therefore
/// this balance can be higher than the staked funds.
pub fn api_member_total_balance(who: T::AccountId) -> BalanceOf<T> {
PoolMembers::<T>::get(who.clone())
.map(|m| m.total_balance())
Expand Down
Loading