Skip to content

Commit

Permalink
use .mul_floor for multiplying Uint128 with Decimal, non-zero and non…
Browse files Browse the repository at this point in the history
…-empty checks to avoid zero send messages
  • Loading branch information
joemonem committed May 15, 2024
1 parent 11e545d commit 7406122
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions contracts/finance/andromeda-splitter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,22 @@ fn execute_send(ctx: ExecuteContext) -> Result<Response, ContractError> {
let recipient_percent = recipient_addr.percent;
let mut vec_coin: Vec<Coin> = 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());

Expand Down Expand Up @@ -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());

Expand Down

0 comments on commit 7406122

Please sign in to comment.