From 79623119b6644458389b93c0c4426783f20c3968 Mon Sep 17 00:00:00 2001 From: bucurdavid Date: Tue, 5 Nov 2024 13:08:56 +0200 Subject: [PATCH] chore: logs fix --- .../src/instructions/renew.rs | 14 +++++++++----- .../src/instructions/stake_rewards.rs | 15 ++++++++++----- .../src/instructions/topup.rs | 15 ++++++++++----- .../src/instructions/withdraw.rs | 15 ++++++++++----- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/programs/core-sol-bond-stake-sc/src/instructions/renew.rs b/programs/core-sol-bond-stake-sc/src/instructions/renew.rs index 835a449..46838f9 100644 --- a/programs/core-sol-bond-stake-sc/src/instructions/renew.rs +++ b/programs/core-sol-bond-stake-sc/src/instructions/renew.rs @@ -87,11 +87,15 @@ pub fn renew(ctx: Context) -> Result<()> { }; msg!("weight_to_be_subtracted: {}", weight_to_be_subtracted); msg!("weight_to_be_subtracted amount: {}", bond.bond_amount); - msg!( - "weight_to_be_subtracted percent: {}", - bond.unbond_timestamp - - current_timestamp / ctx.accounts.bond_config.lock_period * MAX_PERCENT - ); + if current_timestamp < bond.unbond_timestamp { + msg!( + "weight_to_be_subtracted percent: {}", + (bond.unbond_timestamp - current_timestamp) * MAX_PERCENT + / ctx.accounts.bond_config.lock_period + ); + } else { + msg!("weight_to_be_subtracted percent: 0"); + } let decay = compute_decay( ctx.accounts.address_bonds_rewards.last_update_timestamp, diff --git a/programs/core-sol-bond-stake-sc/src/instructions/stake_rewards.rs b/programs/core-sol-bond-stake-sc/src/instructions/stake_rewards.rs index 5bc6352..17b0463 100644 --- a/programs/core-sol-bond-stake-sc/src/instructions/stake_rewards.rs +++ b/programs/core-sol-bond-stake-sc/src/instructions/stake_rewards.rs @@ -108,11 +108,16 @@ pub fn stake_rewards<'a, 'b, 'c: 'info, 'info>( }; msg!("weight_to_be_subtracted: {}", weight_to_be_subtracted); msg!("weight_to_be_subtracted amount: {}", bond.bond_amount); - msg!( - "weight_to_be_subtracted percent: {}", - bond.unbond_timestamp - - current_timestamp / ctx.accounts.bond_config.lock_period * MAX_PERCENT - ); + msg!("weight_to_be_subtracted amount: {}", bond.bond_amount); + if current_timestamp < bond.unbond_timestamp { + msg!( + "weight_to_be_subtracted percent: {}", + (bond.unbond_timestamp - current_timestamp) * MAX_PERCENT + / ctx.accounts.bond_config.lock_period + ); + } else { + msg!("weight_to_be_subtracted percent: 0"); + } let actual_claimable_amount; diff --git a/programs/core-sol-bond-stake-sc/src/instructions/topup.rs b/programs/core-sol-bond-stake-sc/src/instructions/topup.rs index 26b6836..9717f94 100644 --- a/programs/core-sol-bond-stake-sc/src/instructions/topup.rs +++ b/programs/core-sol-bond-stake-sc/src/instructions/topup.rs @@ -121,11 +121,16 @@ pub fn top_up<'a, 'b, 'c: 'info, 'info>( }; msg!("weight_to_be_subtracted: {}", weight_to_be_subtracted); msg!("weight_to_be_subtracted amount: {}", bond.bond_amount); - msg!( - "weight_to_be_subtracted percent: {}", - bond.unbond_timestamp - - current_timestamp / ctx.accounts.bond_config.lock_period * MAX_PERCENT - ); + msg!("weight_to_be_subtracted amount: {}", bond.bond_amount); + if current_timestamp < bond.unbond_timestamp { + msg!( + "weight_to_be_subtracted percent: {}", + (bond.unbond_timestamp - current_timestamp) * MAX_PERCENT + / ctx.accounts.bond_config.lock_period + ); + } else { + msg!("weight_to_be_subtracted percent: 0"); + } let decay = compute_decay( ctx.accounts.address_bonds_rewards.last_update_timestamp, diff --git a/programs/core-sol-bond-stake-sc/src/instructions/withdraw.rs b/programs/core-sol-bond-stake-sc/src/instructions/withdraw.rs index 4912286..ef7de55 100644 --- a/programs/core-sol-bond-stake-sc/src/instructions/withdraw.rs +++ b/programs/core-sol-bond-stake-sc/src/instructions/withdraw.rs @@ -120,11 +120,16 @@ pub fn withdraw<'a, 'b, 'c: 'info, 'info>( }; msg!("weight_to_be_subtracted: {}", weight_to_be_subtracted); msg!("weight_to_be_subtracted amount: {}", bond.bond_amount); - msg!( - "weight_to_be_subtracted percent: {}", - bond.unbond_timestamp - - current_timestamp / ctx.accounts.bond_config.lock_period * MAX_PERCENT - ); + msg!("weight_to_be_subtracted amount: {}", bond.bond_amount); + if current_timestamp < bond.unbond_timestamp { + msg!( + "weight_to_be_subtracted percent: {}", + (bond.unbond_timestamp - current_timestamp) * MAX_PERCENT + / ctx.accounts.bond_config.lock_period + ); + } else { + msg!("weight_to_be_subtracted percent: 0"); + } let decay = compute_decay( ctx.accounts.address_bonds_rewards.last_update_timestamp,