Skip to content

Commit

Permalink
updates after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
shannonwells committed Dec 21, 2023
1 parent 720136d commit 63f6651
Show file tree
Hide file tree
Showing 13 changed files with 614 additions and 98 deletions.
21 changes: 0 additions & 21 deletions common/primitives/src/capacity.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use crate::msa::MessageSourceId;
use codec::{Encode, MaxEncodedLen};
use frame_support::traits::tokens::Balance;
use scale_info::TypeInfo;
use sp_api::Decode;
use sp_runtime::DispatchError;

/// A trait for checking that a target MSA can be staked to.
Expand Down Expand Up @@ -55,21 +52,3 @@ pub trait Replenishable {
/// Checks if an account can be replenished.
fn can_replenish(msa_id: MessageSourceId) -> bool;
}

#[derive(
Clone, Copy, Debug, Decode, Encode, TypeInfo, Eq, MaxEncodedLen, PartialEq, PartialOrd,
)]
/// The type of staking a given Staking Account is doing.
pub enum StakingType {
/// Staking account targets Providers for capacity only, no token reward
MaximumCapacity,
/// Staking account targets Providers and splits reward between capacity to the Provider
/// and token for the account holder
ProviderBoost,
}

impl Default for StakingType {
fn default() -> Self {
StakingType::MaximumCapacity
}
}
4 changes: 2 additions & 2 deletions designdocs/capacity.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Stakes some amount of tokens to the network and generates Capacity.
///
/// - Returns Error::InsufficientBalance if the sender does not have free balance amount needed to stake.
/// - Returns Error::InvalidTarget if attempting to stake to an invalid target.
/// - Returns Error::InsufficientStakingAmount if attempting to stake an amount below the minimum amount.
/// - Returns Error::StakingAmountBelowMinimum if attempting to stake an amount below the minimum amount.
/// - Returns Error::BalanceTooLowtoStake if the sender does not have
/// free balance amount > MinimumTokenBalance after staking.
pub fn stake(origin: OriginFor<T>, target: MessageSourceId, amount: BalanceOf<T>) -> DispatchResult {}
Expand Down Expand Up @@ -211,7 +211,7 @@ pub enum Error<T> {
/// Capacity is not available for the given MSA.
InsufficientBalance,
/// Staker is attempting to stake an amount below the minimum amount.
InsufficientStakingAmount,
StakingAmountBelowMinimum,
/// Staker is attempting to stake a zero amount.
ZeroAmountNotAllowed,
/// Origin has no Staking Account
Expand Down
4 changes: 2 additions & 2 deletions e2e/capacity/staking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,13 @@ describe('Capacity Staking Tests', function () {
});

describe('when attempting to stake below the minimum staking requirements', function () {
it('should fail to stake for InsufficientStakingAmount', async function () {
it('should fail to stake for StakingAmountBelowMinimum', async function () {
const stakingKeys = createKeys('stakingKeys');
const providerId = await createMsaAndProvider(fundingSource, stakingKeys, 'stakingKeys', 150n * CENTS);
const stakeAmount = 1500n;

const failStakeObj = ExtrinsicHelper.stake(stakingKeys, providerId, stakeAmount);
await assert.rejects(failStakeObj.signAndSend(), { name: 'InsufficientStakingAmount' });
await assert.rejects(failStakeObj.signAndSend(), { name: 'StakingAmountBelowMinimum' });
});
});

Expand Down
2 changes: 1 addition & 1 deletion pallets/capacity/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ benchmarks! {

register_provider::<T>(target, "Foo");

}: _ (RawOrigin::Signed(caller.clone()), target, amount, staking_type)
}: _ (RawOrigin::Signed(caller.clone()), target, amount)
verify {
assert!(StakingAccountLedger::<T>::contains_key(&caller));
assert!(StakingTargetLedger::<T>::contains_key(&caller, target));
Expand Down
Loading

0 comments on commit 63f6651

Please sign in to comment.