Skip to content

Commit

Permalink
feat(staking): 💱 Undelegate::{delegation_value, unbonded_value}
Browse files Browse the repository at this point in the history
  • Loading branch information
cratelyn committed Mar 20, 2024
1 parent 5c66e92 commit 9edc385
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions crates/core/component/stake/src/undelegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,8 @@ impl EffectingData for Undelegate {
impl Undelegate {
/// Return the balance after consuming delegation tokens, and producing unbonding tokens.
pub fn balance(&self) -> Balance {
let stake = Balance::from(Value {
amount: self.unbonded_amount,
asset_id: self.unbonding_token().id(),
});

let delegation = Balance::from(Value {
amount: self.delegation_amount,
asset_id: self.delegation_token().id(),
});
let stake: Balance = self.unbonded_value().into();
let delegation: Balance = self.delegation_value().into();

// We consume the delegation tokens and produce the staking tokens.
stake - delegation
Expand All @@ -57,9 +50,25 @@ impl Undelegate {
)
}

/// Returns the [`Value`] of the unbonded [`Amount`].
pub fn unbonded_value(&self) -> Value {
Value {
amount: self.unbonded_amount,
asset_id: self.unbonding_token().id(),
}
}

pub fn delegation_token(&self) -> DelegationToken {
DelegationToken::new(self.validator_identity.clone())
}

/// Returns the [`Value`] of the delegation [`Amount`].
pub fn delegation_value(&self) -> Value {
Value {
amount: self.delegation_amount,
asset_id: self.delegation_token().id(),
}
}
}

impl DomainType for Undelegate {
Expand Down

0 comments on commit 9edc385

Please sign in to comment.