From 3a60dcc01d6c69580b0f8891c33ca5cd7d846718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ad=C3=A1n=20SDPC?= Date: Tue, 28 Jan 2025 14:46:54 +0100 Subject: [PATCH] feat(validations): allow unstaking all the stake at once Namely, apply a protocol-level "rule of convenience", where an amount to unstake of u64::MAX actually means "unstake all my stake" --- validations/src/validations.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/validations/src/validations.rs b/validations/src/validations.rs index 44037cb82..3eda312ad 100644 --- a/validations/src/validations.rs +++ b/validations/src/validations.rs @@ -1472,7 +1472,7 @@ pub fn validate_unstake_transaction<'a>( } // Check if is unstaking more than the total stake - let amount_to_unstake = ut_tx.body.value() + ut_tx.body.fee; + let mut amount_to_unstake = ut_tx.body.value() + ut_tx.body.fee; let validator = ut_tx.body.operator; let withdrawer = ut_tx.signature.public_key.pkh(); @@ -1522,6 +1522,12 @@ pub fn validate_unstake_transaction<'a>( .into()); } }; + + // Apply a protocol-level "rule of convenience", where an amount to unstake of u64::MAX actually + // means "unstake all my stake". + if amount_to_unstake == u64::MAX { + amount_to_unstake = staked_amount; + } // Allowed unstake actions: // 1) Unstake the full balance (checked by the first condition)