Skip to content

Commit ee20960

Browse files
triple-check-everything-before-code-freeze
1 parent b62b086 commit ee20960

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

architectures/decentralized/solana-distributor/programs/solana-distributor/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,4 @@ pub enum ProgramError {
5454
ParamsMerkleProofIsInvalid,
5555
#[msg("params.collateral_amount is too large")]
5656
ParamsCollateralAmountIsTooLarge,
57-
#[msg("math overflow")]
58-
MathOverflow,
5957
}

architectures/decentralized/solana-distributor/programs/solana-distributor/src/logic/airdrop_withdraw.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub fn airdrop_withdraw_processor(
5757
params: AirdropWithdrawParams,
5858
) -> Result<()> {
5959
let airdrop = &mut context.accounts.airdrop;
60+
6061
let airdrop_signer_seeds: &[&[&[u8]]] = &[&[
6162
Airdrop::SEEDS_PREFIX,
6263
&airdrop.id.to_le_bytes(),

architectures/decentralized/solana-distributor/programs/solana-distributor/src/logic/claim_redeem.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ pub fn claim_redeem_processor(
8989
let claim = &mut context.accounts.claim;
9090
let claimable_collateral_amount = params
9191
.vesting
92-
.compute_vested_collateral_amount(Clock::get()?.unix_timestamp)?
93-
.saturating_sub(i128::from(claim.claimed_collateral_amount));
94-
if claimable_collateral_amount < i128::from(params.collateral_amount) {
92+
.compute_vested_collateral_amount(Clock::get()?.unix_timestamp)
93+
- claim.claimed_collateral_amount;
94+
if claimable_collateral_amount < params.collateral_amount {
9595
return err!(ProgramError::ParamsCollateralAmountIsTooLarge);
9696
}
9797
claim.claimed_collateral_amount += params.collateral_amount;
Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use anchor_lang::prelude::*;
22

3-
use crate::ProgramError;
4-
53
#[derive(Debug, InitSpace, AnchorSerialize, AnchorDeserialize, Clone, Copy)]
64
pub struct Vesting {
75
pub start_unix_timestamp: i64,
@@ -13,20 +11,26 @@ impl Vesting {
1311
pub fn compute_vested_collateral_amount(
1412
&self,
1513
now_unix_timestamp: i64,
16-
) -> Result<i128> {
17-
let elapsed_seconds = now_unix_timestamp
18-
.checked_sub(self.start_unix_timestamp)
19-
.ok_or(ProgramError::MathOverflow)?;
20-
if elapsed_seconds < 0 {
21-
return Ok(0);
14+
) -> u64 {
15+
if now_unix_timestamp < self.start_unix_timestamp {
16+
return 0;
2217
}
23-
if elapsed_seconds >= i64::from(self.duration_seconds) {
24-
return Ok(i128::from(self.end_collateral_amount));
18+
if self.duration_seconds == 0 {
19+
return self.end_collateral_amount;
2520
}
26-
Ok(i128::from(self.end_collateral_amount)
27-
.checked_mul(i128::from(elapsed_seconds))
28-
.ok_or(ProgramError::MathOverflow)?
29-
.checked_div(i128::from(self.duration_seconds))
30-
.ok_or(ProgramError::MathOverflow)?)
21+
22+
let elapsed_seconds =
23+
u128::try_from(now_unix_timestamp - self.start_unix_timestamp)
24+
.unwrap();
25+
let duration_seconds = u128::from(self.duration_seconds);
26+
let end_collateral_amount = u128::from(self.end_collateral_amount);
27+
28+
let vested_collateral_amount =
29+
end_collateral_amount * elapsed_seconds / duration_seconds;
30+
if vested_collateral_amount > end_collateral_amount {
31+
return self.end_collateral_amount;
32+
}
33+
34+
u64::try_from(vested_collateral_amount).unwrap()
3135
}
3236
}

0 commit comments

Comments
 (0)