Skip to content

Commit 6d4d3d3

Browse files
authored
check edge case direct after receive quote amount total calculation and deduct the fees (#522)
1 parent 4f5415d commit 6d4d3d3

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

onchain/cairo/launchpad/src/launchpad/launchpad.cairo

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ pub mod LaunchpadMarketplace {
163163
liquidity_raised_amount_in_dollar: u256,
164164
protocol_fee_percent: u256,
165165
creator_fee_percent: u256,
166-
is_fees_protocol: bool,
167166
step_increase_linear: u256,
168167
// Admins params fees
169168
is_fees_protocol_sell_enabled: bool,
@@ -898,7 +897,16 @@ pub mod LaunchpadMarketplace {
898897
pool.clone(), coin_address, sell_amount, true, false
899898
);
900899
let mut quote_amount = quote_amount_total.clone();
901-
900+
// AUDIT
901+
// Validate against liquidity and balance constraints
902+
// High security check to do.
903+
// Approximation and rounding issue can cause to enter this check
904+
// We maybe do something wrong to enter this check
905+
// println!("check liq raised and quote amount");
906+
if pool.liquidity_raised < quote_amount {
907+
// println!("pool.liquidity_raised < quote_amount");
908+
quote_amount = pool.liquidity_raised;
909+
}
902910
// AUDIT
903911
// HIGH RISK SECURITY
904912
// Rounding and approximation of the Linear and Exponential bonding curve can occurs
@@ -911,7 +919,7 @@ pub mod LaunchpadMarketplace {
911919
// let creator_fee_amount = sell_amount * creator_fee_percent / BPS;
912920

913921
// Handle protocol fees if enabled
914-
let is_fees_enabled = self.is_fees_protocol_enabled.read()
922+
let is_fees_protocol_enabled = self.is_fees_protocol_enabled.read()
915923
&& self.is_fees_protocol_sell_enabled.read();
916924

917925
let mut quote_fee_amount = 0_u256;
@@ -922,7 +930,7 @@ pub mod LaunchpadMarketplace {
922930
// Substract fees protocol from quote amount
923931
// AUDIT
924932
// High security check to do: rounding, approximation, balance of contract
925-
if is_fees_enabled {
933+
if is_fees_protocol_enabled {
926934
quote_fee_amount = quote_amount * protocol_fee_percent / BPS;
927935
quote_amount -= quote_fee_amount;
928936
}
@@ -962,28 +970,13 @@ pub mod LaunchpadMarketplace {
962970
}
963971
}
964972

965-
// AUDIT
966-
// Validate against liquidity and balance constraints
967-
// High security check to do.
968-
// Approximation and rounding issue can cause to enter this check
969-
// We maybe do something wrong to enter this check
970-
// println!("check liq raised and quote amount");
971-
if pool.liquidity_raised < quote_amount {
972-
// println!("pool.liquidity_raised < quote_amount");
973-
quote_amount = pool.liquidity_raised;
974-
if is_fees_enabled {
975-
quote_fee_amount = quote_amount * protocol_fee_percent / BPS;
976-
quote_amount -= quote_fee_amount;
977-
// creator_fee_amount = quote_amount * creator_fee_percent / BPS;
978-
// quote_amount -= creator_fee_amount;
979-
}
980-
}
973+
981974

982975
// println!("quote_amount: {}", quote_amount.clone());
983976
assert(pool.liquidity_raised >= quote_amount, errors::LIQUIDITY_BELOW_AMOUNT);
984977

985978
// Transfer protocol fees to the address
986-
if is_fees_enabled && quote_fee_amount > 0 {
979+
if is_fees_protocol_enabled && quote_fee_amount > 0 {
987980
quote_token.transfer(self.protocol_fee_destination.read(), quote_fee_amount);
988981
}
989982

0 commit comments

Comments
 (0)