Skip to content

Commit

Permalink
🪡 Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
z0r0z committed Jan 23, 2024
1 parent 927674a commit 33308b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1 +1 @@
HeliosTest:testDeploy() (gas: 1671527)
HeliosTest:testDeploy() (gas: 1597535)
17 changes: 15 additions & 2 deletions src/Helios.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,22 @@ contract Helios is ERC6909, ReentrancyGuard {
/// @dev Not enough liquidity burned.
error InsufficientLiquidityBurned();

/// @dev Not enough tokens sent out.
error InsufficientOutputAmount();

/// @dev Not enough tokens sent in.
error InsufficientInputAmount();

/// @dev Not enough liquidity.
error InsufficientLiquidity();

/// @dev Invalid recipient.
error InvalidTo();

/// @dev Bad math.
error Overflow();

/// @dev K.
error K();

/// ========================= LIBRARIES ========================= ///
Expand Down Expand Up @@ -147,7 +153,9 @@ contract Helios is ERC6909, ReentrancyGuard {

if (!(to != pool.token0 && to != pool.token1)) revert InvalidTo();
if (!(amount0Out != 0 || amount1Out != 0)) revert InsufficientOutputAmount();
if (!(amount0Out < pool.reserve0 && amount1Out < pool.reserve1)) revert InsufficientLiquidity();
if (!(amount0Out < pool.reserve0 && amount1Out < pool.reserve1)) {
revert InsufficientLiquidity();
}

if (amount0Out != 0) pool.token0.safeTransfer(to, amount0Out); // Optimistically transfer tokens.
if (amount1Out != 0) pool.token1.safeTransfer(to, amount1Out); // Optimistically transfer tokens.
Expand All @@ -164,7 +172,12 @@ contract Helios is ERC6909, ReentrancyGuard {
if (!(amount0In != 0 || amount1In != 0)) revert InsufficientInputAmount();
uint256 balance0Adjusted = balance0 * 1000 - amount0In * 3;
uint256 balance1Adjusted = balance1 * 1000 - amount1In * 3;
if (!(balance0Adjusted * balance1Adjusted >= uint256(pool.reserve0 * pool.reserve1 * 1000 ** 2))) revert K();
if (
!(
balance0Adjusted * balance1Adjusted
>= uint256(pool.reserve0 * pool.reserve1 * 1000 ** 2)
)
) revert K();

_update(id, balance0, balance1, pool.reserve0, pool.reserve1);
}
Expand Down

0 comments on commit 33308b9

Please sign in to comment.