Skip to content

Commit e87f251

Browse files
committed
Codearena findings 12, If liquidity is insufficient, users will need to pay more tokens
1 parent 139e595 commit e87f251

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pkg/seawater/src/error.rs

+4
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ pub enum Error {
241241
// 43 (0x2b)
242242
#[error("Trying to swap2 between the same pool")]
243243
SamePool,
244+
245+
// 44 (0x2c)
246+
#[error("Swap sending fee taking overflow")]
247+
TransferToSenderSub,
244248
}
245249

246250
impl From<Error> for Vec<u8> {

pkg/seawater/src/lib.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,18 @@ impl Pools {
287287
));
288288

289289
// transfer tokens
290-
erc20::take(from, original_amount, permit2)?;
290+
erc20::take(from, amount_in, permit2)?;
291291
erc20::transfer_to_sender(to, amount_out)?;
292292

293+
if original_amount > amount_in {
294+
erc20::transfer_to_sender(
295+
to,
296+
original_amount
297+
.checked_sub(amount_in)
298+
.ok_or(Error::TransferToSenderSub)?,
299+
)?;
300+
}
301+
293302
#[cfg(feature = "log-events")]
294303
evm::log(events::Swap2 {
295304
user: msg::sender(),

0 commit comments

Comments
 (0)