Skip to content

Commit cca4319

Browse files
committed
fmt
1 parent 8d3a607 commit cca4319

5 files changed

Lines changed: 47 additions & 54 deletions

File tree

substrate/frame/delegated-staking/src/impls.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,7 @@ impl<T: Config> DelegatedStakeInterface for Pallet<T> {
212212
)?;
213213

214214
// Delegate the funds from who to the `Agent` account.
215-
Pallet::<T>::delegate_to_agent(
216-
RawOrigin::Signed(who.clone()).into(),
217-
agent.clone(),
218-
amount,
219-
)
215+
Pallet::<T>::delegate_to_agent(RawOrigin::Signed(who.clone()).into(), agent.clone(), amount)
220216
}
221217

222218
/// Add more delegation to the `Agent` account.
@@ -225,11 +221,7 @@ impl<T: Config> DelegatedStakeInterface for Pallet<T> {
225221
agent: &Self::AccountId,
226222
amount: Self::Balance,
227223
) -> DispatchResult {
228-
Pallet::<T>::delegate_to_agent(
229-
RawOrigin::Signed(who.clone()).into(),
230-
agent.clone(),
231-
amount,
232-
)
224+
Pallet::<T>::delegate_to_agent(RawOrigin::Signed(who.clone()).into(), agent.clone(), amount)
233225
}
234226

235227
/// Withdraw delegation of `delegator` to `Agent`.

substrate/frame/delegated-staking/src/lib.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
//! behalf for staking these delegated funds. Also, sometimes referred as `Delegatee`.
3131
//! - **Delegator**: An account who delegates their funds to an `agent` and authorises them to use
3232
//! it for staking.
33-
//! - **AgentLedger**: A data structure that holds important information about the `agent` such
34-
//! as total delegations they have received, any slashes posted to them, etc.
33+
//! - **AgentLedger**: A data structure that holds important information about the `agent` such as
34+
//! total delegations they have received, any slashes posted to them, etc.
3535
//! - **Delegation**: A data structure that stores the amount of funds delegated to an `agent` by a
3636
//! `delegator`.
3737
//!
@@ -434,10 +434,7 @@ pub mod pallet {
434434

435435
impl<T: Config> Pallet<T> {
436436
/// Derive a (keyless) pot account from the given agent account and account type.
437-
pub(crate) fn sub_account(
438-
account_type: AccountType,
439-
agent: T::AccountId,
440-
) -> T::AccountId {
437+
pub(crate) fn sub_account(account_type: AccountType, agent: T::AccountId) -> T::AccountId {
441438
T::PalletId::get().into_sub_account_truncating((account_type, agent.clone()))
442439
}
443440

@@ -654,8 +651,7 @@ impl<T: Config> Pallet<T> {
654651
);
655652

656653
// update delegations
657-
Delegation::<T>::from(&source_delegation.agent, amount)
658-
.save_or_kill(destination_delegator);
654+
Delegation::<T>::from(&source_delegation.agent, amount).save_or_kill(destination_delegator);
659655

660656
source_delegation
661657
.decrease_delegation(amount)

substrate/frame/delegated-staking/src/mock.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,7 @@ pub(crate) fn setup_delegation_stake(
264264
increment: Balance,
265265
) -> Balance {
266266
fund(&agent, 100);
267-
assert_ok!(DelegatedStaking::register_agent(
268-
RawOrigin::Signed(agent).into(),
269-
reward_acc
270-
));
267+
assert_ok!(DelegatedStaking::register_agent(RawOrigin::Signed(agent).into(), reward_acc));
271268
let mut delegated_amount: Balance = 0;
272269
for (index, delegator) in delegators.iter().enumerate() {
273270
let amount_to_delegate = base_delegate_amount + increment * index as Balance;

substrate/frame/delegated-staking/src/tests.rs

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,7 @@ fn agent_restrictions() {
156156

157157
// agent one tries to delegate to agent 2
158158
assert_noop!(
159-
DelegatedStaking::delegate_to_agent(
160-
RawOrigin::Signed(agent_one).into(),
161-
agent_two,
162-
10
163-
),
159+
DelegatedStaking::delegate_to_agent(RawOrigin::Signed(agent_one).into(), agent_two, 10),
164160
Error::<T>::InvalidDelegation
165161
);
166162

@@ -245,10 +241,7 @@ mod staking_integration {
245241
assert_eq!(agent_obj.bonded_stake(), delegated_balance);
246242
}
247243

248-
assert_eq!(
249-
Staking::stake(&agent).unwrap(),
250-
Stake { total: 50 * 100, active: 50 * 100 }
251-
)
244+
assert_eq!(Staking::stake(&agent).unwrap(), Stake { total: 50 * 100, active: 50 * 100 })
252245
});
253246
}
254247

@@ -272,8 +265,8 @@ mod staking_integration {
272265
DelegatedStaking::release_delegation(RawOrigin::Signed(agent).into(), 301, 50, 0),
273266
Error::<T>::NotEnoughFunds
274267
);
275-
// assert_noop!(DelegatedStaking::release_delegation(RawOrigin::Signed(agent).into(), 200, 50,
276-
// 0), Error::<T>::NotAllowed); active and total stake remains same
268+
// assert_noop!(DelegatedStaking::release_delegation(RawOrigin::Signed(agent).into(),
269+
// 200, 50, 0), Error::<T>::NotAllowed); active and total stake remains same
277270
assert!(eq_stake(agent, total_staked, total_staked));
278271

279272
// 305 wants to unbond 50 in era 2, withdrawable in era 5.
@@ -307,8 +300,18 @@ mod staking_integration {
307300
Error::<T>::NotEnoughFunds
308301
);
309302
// less is possible
310-
assert_ok!(DelegatedStaking::release_delegation(RawOrigin::Signed(agent).into(), 305, 30, 0));
311-
assert_ok!(DelegatedStaking::release_delegation(RawOrigin::Signed(agent).into(), 305, 20, 0));
303+
assert_ok!(DelegatedStaking::release_delegation(
304+
RawOrigin::Signed(agent).into(),
305+
305,
306+
30,
307+
0
308+
));
309+
assert_ok!(DelegatedStaking::release_delegation(
310+
RawOrigin::Signed(agent).into(),
311+
305,
312+
20,
313+
0
314+
));
312315

313316
// Lets go to future era where everything is unbonded. Withdrawable amount: 100 + 200
314317
start_era(7);
@@ -329,9 +332,19 @@ mod staking_integration {
329332
Error::<T>::NotEnoughFunds
330333
);
331334
// but can withdraw all its delegation amount.
332-
assert_ok!(DelegatedStaking::release_delegation(RawOrigin::Signed(agent).into(), 310, 100, 0));
335+
assert_ok!(DelegatedStaking::release_delegation(
336+
RawOrigin::Signed(agent).into(),
337+
310,
338+
100,
339+
0
340+
));
333341
// 320 can withdraw all its delegation amount.
334-
assert_ok!(DelegatedStaking::release_delegation(RawOrigin::Signed(agent).into(), 320, 200, 0));
342+
assert_ok!(DelegatedStaking::release_delegation(
343+
RawOrigin::Signed(agent).into(),
344+
320,
345+
200,
346+
0
347+
));
335348

336349
// cannot withdraw anything more..
337350
assert_noop!(
@@ -363,15 +376,15 @@ mod staking_integration {
363376
// withdrawn and test its claimed from there first.
364377

365378
// fund(&300, 1000);
366-
// assert_ok!(DelegatedStaking::delegate_to_agent(RawOrigin::Signed(300.into()), delegate,
367-
// 100));
379+
// assert_ok!(DelegatedStaking::delegate_to_agent(RawOrigin::Signed(300.into()),
380+
// delegate, 100));
368381
//
369382
// // verify unbonded balance
370383
// assert_eq!(get_agent(&agent).available_to_bond(), 100);
371384
//
372385
// // withdraw works now without unbonding
373-
// assert_ok!(DelegatedStaking::release_delegation(RawOrigin::Signed(agent).into(), 300, 100,
374-
// 0)); assert_eq!(get_agent(&agent).available_to_bond(), 0);
386+
// assert_ok!(DelegatedStaking::release_delegation(RawOrigin::Signed(agent).into(), 300,
387+
// 100, 0)); assert_eq!(get_agent(&agent).available_to_bond(), 0);
375388
});
376389
}
377390

@@ -392,7 +405,11 @@ mod staking_integration {
392405
assert_ok!(DelegatedStaking::register_agent(RawOrigin::Signed(200).into(), 201));
393406
// add some delegations to it
394407
fund(&300, 1000);
395-
assert_ok!(DelegatedStaking::delegate_to_agent(RawOrigin::Signed(300).into(), 200, 100));
408+
assert_ok!(DelegatedStaking::delegate_to_agent(
409+
RawOrigin::Signed(300).into(),
410+
200,
411+
100
412+
));
396413

397414
// if delegate calls Staking pallet directly with a different reward destination, it
398415
// fails.
@@ -441,10 +458,7 @@ mod staking_integration {
441458
Error::<T>::AlreadyStaking
442459
);
443460
assert_noop!(
444-
DelegatedStaking::register_agent(
445-
RawOrigin::Signed(GENESIS_VALIDATOR).into(),
446-
201
447-
),
461+
DelegatedStaking::register_agent(RawOrigin::Signed(GENESIS_VALIDATOR).into(), 201),
448462
Error::<T>::AlreadyStaking
449463
);
450464
});

substrate/frame/delegated-staking/src/types.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,7 @@ impl<T: Config> Agent<T> {
212212
.defensive_ok_or(ArithmeticError::Overflow)?;
213213

214214
Ok(Agent {
215-
ledger: AgentLedger {
216-
unclaimed_withdrawals: new_unclaimed_withdrawals,
217-
..self.ledger
218-
},
215+
ledger: AgentLedger { unclaimed_withdrawals: new_unclaimed_withdrawals, ..self.ledger },
219216
..self
220217
})
221218
}
@@ -241,10 +238,7 @@ impl<T: Config> Agent<T> {
241238
let pending_slash = self.ledger.pending_slash.defensive_saturating_sub(amount);
242239
let total_delegated = self.ledger.total_delegated.defensive_saturating_sub(amount);
243240

244-
Agent {
245-
ledger: AgentLedger { pending_slash, total_delegated, ..self.ledger },
246-
..self
247-
}
241+
Agent { ledger: AgentLedger { pending_slash, total_delegated, ..self.ledger }, ..self }
248242
}
249243

250244
/// Get the total stake of agent bonded in [`Config::CoreStaking`].

0 commit comments

Comments
 (0)