Skip to content

Commit

Permalink
Feat(airdrop): add window bounds checks on config update
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadoySV committed Nov 23, 2021
1 parent 4c66c4b commit 5986ff7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
16 changes: 13 additions & 3 deletions contracts/airdrop/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub fn execute(
to_timestamp,
} => handle_update_config(
deps,
env,
info,
owner,
auction_contract_address,
Expand Down Expand Up @@ -122,6 +123,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
/// @param new_config : Same as InstantiateMsg struct
pub fn handle_update_config(
deps: DepsMut,
env: Env,
info: MessageInfo,
owner: Option<String>,
auction_contract_address: Option<String>,
Expand Down Expand Up @@ -160,19 +162,27 @@ pub fn handle_update_config(
}

if let Some(from_timestamp) = from_timestamp {
if env.block.time.seconds() >= config.from_timestamp {
return Err(StdError::generic_err(
"from_timestamp can't be changed after window starts",
));
}
config.from_timestamp = from_timestamp;
attributes.push(attr("new_from_timestamp", from_timestamp.to_string()))
}

if let Some(to_timestamp) = to_timestamp {
if env.block.time.seconds() >= config.from_timestamp && to_timestamp < config.to_timestamp {
return Err(StdError::generic_err(
"When window starts to_timestamp can only be increased",
));
}
config.to_timestamp = to_timestamp;
attributes.push(attr("new_to_timestamp", to_timestamp.to_string()))
}

if config.to_timestamp <= config.from_timestamp {
return Err(StdError::generic_err(
"Invalid airdrop claim window",
));
return Err(StdError::generic_err("Invalid airdrop claim window"));
}

CONFIG.save(deps.storage, &config)?;
Expand Down
24 changes: 12 additions & 12 deletions contracts/airdrop/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ fn init_contracts(app: &mut App) -> (Addr, Addr, InstantiateMsg, u64) {
owner: Some(owner.clone().to_string()),
astro_token_address: astro_token_instance.clone().into_string(),
merkle_roots: Some(vec!["merkle_roots".to_string()]),
from_timestamp: Some(1_000_00),
to_timestamp: 100_000_00,
from_timestamp: Some(1571897419),
to_timestamp: 1581797419,
total_airdrop_size: Uint128::new(100_000_000_000),
};

Expand Down Expand Up @@ -204,8 +204,8 @@ fn update_config() {
let new_owner = String::from("new_owner");
let auction_contract_address = String::from("auction_contract_address");
let merkle_roots = vec!["new_merkle_roots".to_string()];
let from_timestamp = 2_000_00;
let to_timestamp = 200_000_00;
let from_timestamp = 1571997419;
let to_timestamp = 1591797419;

let update_msg = ExecuteMsg::UpdateConfig {
owner: Some(new_owner.clone()),
Expand Down Expand Up @@ -285,7 +285,7 @@ fn test_transfer_unclaimed_tokens() {
// claim period is not over
app.update_block(|b| {
b.height += 17280;
b.time = Timestamp::from_seconds(1_000_00)
b.time = Timestamp::from_seconds(1571897419)
});

// Can only be called after the claim period is over
Expand All @@ -309,7 +309,7 @@ fn test_transfer_unclaimed_tokens() {
// claim period is over
app.update_block(|b| {
b.height += 17280;
b.time = Timestamp::from_seconds(1_000_00_00)
b.time = Timestamp::from_seconds(1581797419)
});

// Amount needs to be less than unclaimed_tokens balance
Expand Down Expand Up @@ -416,7 +416,7 @@ fn test_claim_by_terra_user() {
// Claim period has not started yet
app.update_block(|b| {
b.height += 17280;
b.time = Timestamp::from_seconds(1_000)
b.time = Timestamp::from_seconds(1571798419)
});

let mut claim_msg = ExecuteMsg::Claim {
Expand Down Expand Up @@ -462,7 +462,7 @@ fn test_claim_by_terra_user() {
// Update Block to test successful claim
app.update_block(|b| {
b.height += 17280;
b.time = Timestamp::from_seconds(1_000_05)
b.time = Timestamp::from_seconds(1571897424)
});

// **** "Incorrect Merkle Root Index" Error should be returned ****
Expand Down Expand Up @@ -788,7 +788,7 @@ fn test_claim_by_terra_user() {
// Claim period has concluded
app.update_block(|b| {
b.height += 17280;
b.time = Timestamp::from_seconds(1_000_000_000)
b.time = Timestamp::from_seconds(2571797419)
});

// **** "Claim period has concluded" Error should be returned ****
Expand Down Expand Up @@ -933,7 +933,7 @@ fn test_withdraw_airdrop_rewards() {
// Update Block to test successful claim
app.update_block(|b| {
b.height += 17280;
b.time = Timestamp::from_seconds(1_000_05)
b.time = Timestamp::from_seconds(1571897424)
});

// ################################
Expand Down Expand Up @@ -1145,7 +1145,7 @@ fn test_delegate_astro_to_bootstrap_auction() {
airdrop_contract_address: airdrop_instance.clone().to_string(),
lockdrop_contract_address: "lockdrop_contract_address".to_string(),
lp_tokens_vesting_duration: 2592000u64,
init_timestamp: 100000u64,
init_timestamp: 1571897419u64,
deposit_window: 2592000u64,
withdrawal_window: 1592000u64,
};
Expand Down Expand Up @@ -1204,7 +1204,7 @@ fn test_delegate_astro_to_bootstrap_auction() {
// Update Block to test successful claim
app.update_block(|b| {
b.height += 17280;
b.time = Timestamp::from_seconds(1_000_05)
b.time = Timestamp::from_seconds(1571897424)
});

// ################################
Expand Down
2 changes: 0 additions & 2 deletions contracts/auction/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,6 @@ pub fn handle_withdraw_ust(
}

/// @dev Helper function to calculate maximum % of their total UST deposited that can be withdrawn
/// Returns % UST that can be withdrawn and 'more_withdrawals_allowed' boolean which indicates whether more withdrawals by the user
/// will be allowed or not
fn allowed_withdrawal_percent(current_timestamp: u64, config: &Config) -> Decimal {
let withdrawal_cutoff_init_point = config.init_timestamp + config.deposit_window;

Expand Down

0 comments on commit 5986ff7

Please sign in to comment.