Skip to content

Commit

Permalink
Set the user's timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
af-afk committed Aug 14, 2024
1 parent 07627d4 commit d193ac0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion pkg/leo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions pkg/leo/src/maths.rs
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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)
}

0 comments on commit d193ac0

Please sign in to comment.