From 74061226484a24bc9c919598f9e5072ef63ec15e Mon Sep 17 00:00:00 2001 From: Joe Monem Date: Wed, 15 May 2024 09:48:06 -0600 Subject: [PATCH 1/3] use .mul_floor for multiplying Uint128 with Decimal, non-zero and non-empty checks to avoid zero send messages --- .../andromeda-splitter/src/contract.rs | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/contracts/finance/andromeda-splitter/src/contract.rs b/contracts/finance/andromeda-splitter/src/contract.rs index 5fff11766..9e58e1fa6 100644 --- a/contracts/finance/andromeda-splitter/src/contract.rs +++ b/contracts/finance/andromeda-splitter/src/contract.rs @@ -168,20 +168,22 @@ fn execute_send(ctx: ExecuteContext) -> Result { let recipient_percent = recipient_addr.percent; let mut vec_coin: Vec = Vec::new(); for (i, coin) in info.funds.clone().iter().enumerate() { - let mut recip_coin: Coin = coin.clone(); - recip_coin.amount = coin.amount * recipient_percent; - remainder_funds[i].amount = remainder_funds[i].amount.checked_sub(recip_coin.amount)?; - vec_coin.push(recip_coin.clone()); - amp_funds.push(recip_coin); + let amount_owed = coin.amount.mul_floor(recipient_percent); + if !amount_owed.is_zero() { + let mut recip_coin: Coin = coin.clone(); + recip_coin.amount = amount_owed; + remainder_funds[i].amount = + remainder_funds[i].amount.checked_sub(recip_coin.amount)?; + vec_coin.push(recip_coin.clone()); + amp_funds.push(recip_coin); + } + } + if !vec_coin.is_empty() { + let amp_msg = recipient_addr + .recipient + .generate_amp_msg(&deps.as_ref(), Some(vec_coin))?; + pkt = pkt.add_message(amp_msg); } - - // let direct_message = recipient_addr - // .recipient - // .generate_direct_msg(&deps.as_ref(), vec_coin)?; - let amp_msg = recipient_addr - .recipient - .generate_amp_msg(&deps.as_ref(), Some(vec_coin))?; - pkt = pkt.add_message(amp_msg); } remainder_funds.retain(|x| x.amount > Uint128::zero()); @@ -259,12 +261,6 @@ fn execute_update_lock( let mut splitter = SPLITTER.load(deps.storage)?; - // Can't call this function while the lock isn't expired - - ensure!( - splitter.lock.is_expired(&env.block), - ContractError::ContractLocked {} - ); // Get current time let current_time = Milliseconds::from_seconds(env.block.time.seconds()); From ce656402366a12ceb2e2628b95fde38ba8e7e880 Mon Sep 17 00:00:00 2001 From: Joe Monem Date: Wed, 15 May 2024 11:40:43 -0600 Subject: [PATCH 2/3] refactor: check if packet has messages before attaching it --- contracts/finance/andromeda-splitter/src/contract.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/contracts/finance/andromeda-splitter/src/contract.rs b/contracts/finance/andromeda-splitter/src/contract.rs index 9e58e1fa6..2864b5b1d 100644 --- a/contracts/finance/andromeda-splitter/src/contract.rs +++ b/contracts/finance/andromeda-splitter/src/contract.rs @@ -199,8 +199,11 @@ fn execute_send(ctx: ExecuteContext) -> Result { }))); } let kernel_address = ADOContract::default().get_kernel_address(deps.as_ref().storage)?; - let distro_msg = pkt.to_sub_msg(kernel_address, Some(amp_funds), 1)?; - msgs.push(distro_msg); + + if !pkt.messages.is_empty() { + let distro_msg = pkt.to_sub_msg(kernel_address, Some(amp_funds), 1)?; + msgs.push(distro_msg); + } Ok(Response::new() .add_submessages(msgs) From bc27e5779078af89383b036e4c19af872ef376c1 Mon Sep 17 00:00:00 2001 From: Joe Monem Date: Wed, 15 May 2024 11:48:05 -0600 Subject: [PATCH 3/3] chore: changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68b10b7a6..4f331036f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Splitter: avoid zero send messages, owner updates lock any time [(#457)](https://github.com/andromedaprotocol/andromeda-core/pull/457) + ### Removed - Schemas are no longer tracked [(#430)](https://github.com/andromedaprotocol/andromeda-core/pull/430)