Skip to content

Commit

Permalink
Codearena findings 12, If liquidity is insufficient, users will need …
Browse files Browse the repository at this point in the history
…to pay more tokens
  • Loading branch information
af-afk committed Sep 23, 2024
1 parent 139e595 commit e87f251
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pkg/seawater/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ pub enum Error {
// 43 (0x2b)
#[error("Trying to swap2 between the same pool")]
SamePool,

// 44 (0x2c)
#[error("Swap sending fee taking overflow")]
TransferToSenderSub,
}

impl From<Error> for Vec<u8> {
Expand Down
11 changes: 10 additions & 1 deletion pkg/seawater/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,18 @@ impl Pools {
));

// transfer tokens
erc20::take(from, original_amount, permit2)?;
erc20::take(from, amount_in, permit2)?;
erc20::transfer_to_sender(to, amount_out)?;

if original_amount > amount_in {
erc20::transfer_to_sender(
to,
original_amount
.checked_sub(amount_in)
.ok_or(Error::TransferToSenderSub)?,
)?;
}

#[cfg(feature = "log-events")]
evm::log(events::Swap2 {
user: msg::sender(),
Expand Down

0 comments on commit e87f251

Please sign in to comment.