Skip to content

Commit

Permalink
Merge pull request #736 from jacobleygonie/protection-add-liquidity
Browse files Browse the repository at this point in the history
Protection add liquidity: make sure both amounts deposited are greater than expected.
  • Loading branch information
sasurobert authored Sep 5, 2023
2 parents 2fe296e + 79fcf4b commit 8405234
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions dex/pair/src/liquidity_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@ pub trait LiquidityPoolModule:
);

if &second_token_amount_optimal <= second_token_amount_desired {
require!(
second_token_amount_optimal >= context.second_token_amount_min,
ERROR_INSUFFICIENT_SECOND_TOKEN
);

context.first_token_optimal_amount = first_token_amount_desired.clone();
context.second_token_optimal_amount = second_token_amount_optimal;
} else {
Expand All @@ -156,14 +151,17 @@ pub trait LiquidityPoolModule:
&first_token_amount_optimal <= first_token_amount_desired,
ERROR_OPTIMAL_GRATER_THAN_PAID
);
require!(
first_token_amount_optimal >= context.first_token_amount_min,
ERROR_INSUFFICIENT_FIRST_TOKEN
);

context.first_token_optimal_amount = first_token_amount_optimal;
context.second_token_optimal_amount = second_token_amount_desired.clone();
}
require!(
context.first_token_optimal_amount >= context.first_token_amount_min,
ERROR_INSUFFICIENT_FIRST_TOKEN
);
require!(
context.second_token_optimal_amount >= context.second_token_amount_min,
ERROR_INSUFFICIENT_SECOND_TOKEN
);
}

fn get_token_for_given_position(
Expand Down

0 comments on commit 8405234

Please sign in to comment.