diff --git a/pkg/leo/src/lib.rs b/pkg/leo/src/lib.rs index 0313a471..8f07df54 100644 --- a/pkg/leo/src/lib.rs +++ b/pkg/leo/src/lib.rs @@ -215,13 +215,16 @@ impl Leo { position.amount.get(), campaign.per_second.get(), ); - let seconds_since = U64::from(block::timestamp()) - campaign.started.get(); + let timestamp = U64::from(block::timestamp()); + let seconds_since = timestamp - campaign.started.get(); let rewards = base_rewards * U256::from(seconds_since); // Track what's sent, and do a last-minute sanity check to make sure we don't // send more than we should. let new_distributed = campaign.distributed.get() + rewards; campaign.distributed.set(new_distributed); assert!(campaign.pool_amount.get() > new_distributed); + // Update the position's creation time so we don't double up on their rewards. + position.timestamp.set(timestamp); // Now send the actual rewards, and return. let token = campaign.token.get(); erc20::give(token, rewards).unwrap(); diff --git a/pkg/leo/src/maths.rs b/pkg/leo/src/maths.rs index 2dca32d7..3b9b113b 100644 --- a/pkg/leo/src/maths.rs +++ b/pkg/leo/src/maths.rs @@ -1,7 +1,7 @@ use stylus_sdk::alloy_primitives::U256; /// Returns `a * b / c` and if the result had carry. Copied from Seawater. -pub fn _mul_div(a: U256, b: U256, mut denom_and_rem: U256) -> (U256, bool) { +pub fn _mul_div(a: U256, b: U256, mut denom_and_rem: U256) -> U256 { assert!(!denom_and_rem.is_zero()); let mut mul_and_quo = a.widening_mul::<256, 4, 512, 8>(b); @@ -15,9 +15,9 @@ pub fn _mul_div(a: U256, b: U256, mut denom_and_rem: U256) -> (U256, bool) { let has_carry = denom_and_rem != U256::ZERO; - (U256::from_limbs_slice(&limbs[0..4]), has_carry) + U256::from_limbs_slice(&limbs[0..4]) } pub fn calc_base_rewards(pool_lp: U256, our_lp: U256, rewards_per_sec: U256) -> U256 { - _mul_div(pool_lp, our_lp, rewards_per_sec).0 + _mul_div(pool_lp, our_lp, rewards_per_sec) }