Skip to content

Conversation

@omriss
Copy link
Collaborator

@omriss omriss commented Jan 6, 2026

No description provided.

@omriss omriss linked an issue Jan 6, 2026 that may be closed by this pull request
@stability-builder
Copy link

Good luck!

Comment on lines +44 to +82
function swap(
address pool,
address tokenIn,
address tokenOut,
address recipient,
uint priceImpactTolerance
) external {
ILbPairV2 pair = ILbPairV2(pool);

// --------------- token-out balance before swap (to calculate actual amountOut after swap)
uint balanceBefore = IERC20(tokenOut).balanceOf(recipient);

// --------------- verify that provided tokens are correct
address tokenX = pair.getTokenX();
require(_isValid(pair, tokenIn, tokenOut, tokenX), IncorrectTokens());

// --------------- input amount should be sent on balance of the pair contract before swap call
uint amount = IERC20(tokenIn).balanceOf(address(this));
IERC20(tokenIn).safeTransfer(pool, amount);

// --------------- ensure that there is enough output amount in the pair
(uint128 amountInLeft, uint128 price,) = pair.getSwapOut(uint128(amount), tokenIn == tokenX);
require(amountInLeft == 0, InsufficientOutputAmount(amountInLeft));

// --------------- perform the swap
pair.swap(tokenX == tokenIn, recipient);

// --------------- actual amount out received by the recipient
uint balanceAfter = IERC20(tokenOut).balanceOf(recipient);
uint amountOut = balanceAfter > balanceBefore ? balanceAfter - balanceBefore : 0;

// --------------- verify that price impact is within the tolerance limit
uint priceImpact = (price - amountOut) * ConstantsLib.DENOMINATOR / price;
if (priceImpact >= priceImpactTolerance) {
revert(string(abi.encodePacked("!PRICE ", Strings.toString(priceImpact))));
}

emit SwapInPool(pool, tokenIn, tokenOut, recipient, priceImpactTolerance, amount, amountOut);
}

Check warning

Code scanning / Slither

Dangerous strict equalities Medium

Comment on lines +44 to +82
function swap(
address pool,
address tokenIn,
address tokenOut,
address recipient,
uint priceImpactTolerance
) external {
ILbPairV2 pair = ILbPairV2(pool);

// --------------- token-out balance before swap (to calculate actual amountOut after swap)
uint balanceBefore = IERC20(tokenOut).balanceOf(recipient);

// --------------- verify that provided tokens are correct
address tokenX = pair.getTokenX();
require(_isValid(pair, tokenIn, tokenOut, tokenX), IncorrectTokens());

// --------------- input amount should be sent on balance of the pair contract before swap call
uint amount = IERC20(tokenIn).balanceOf(address(this));
IERC20(tokenIn).safeTransfer(pool, amount);

// --------------- ensure that there is enough output amount in the pair
(uint128 amountInLeft, uint128 price,) = pair.getSwapOut(uint128(amount), tokenIn == tokenX);
require(amountInLeft == 0, InsufficientOutputAmount(amountInLeft));

// --------------- perform the swap
pair.swap(tokenX == tokenIn, recipient);

// --------------- actual amount out received by the recipient
uint balanceAfter = IERC20(tokenOut).balanceOf(recipient);
uint amountOut = balanceAfter > balanceBefore ? balanceAfter - balanceBefore : 0;

// --------------- verify that price impact is within the tolerance limit
uint priceImpact = (price - amountOut) * ConstantsLib.DENOMINATOR / price;
if (priceImpact >= priceImpactTolerance) {
revert(string(abi.encodePacked("!PRICE ", Strings.toString(priceImpact))));
}

emit SwapInPool(pool, tokenIn, tokenOut, recipient, priceImpactTolerance, amount, amountOut);
}
Comment on lines +44 to +82
function swap(
address pool,
address tokenIn,
address tokenOut,
address recipient,
uint priceImpactTolerance
) external {
ILbPairV2 pair = ILbPairV2(pool);

// --------------- token-out balance before swap (to calculate actual amountOut after swap)
uint balanceBefore = IERC20(tokenOut).balanceOf(recipient);

// --------------- verify that provided tokens are correct
address tokenX = pair.getTokenX();
require(_isValid(pair, tokenIn, tokenOut, tokenX), IncorrectTokens());

// --------------- input amount should be sent on balance of the pair contract before swap call
uint amount = IERC20(tokenIn).balanceOf(address(this));
IERC20(tokenIn).safeTransfer(pool, amount);

// --------------- ensure that there is enough output amount in the pair
(uint128 amountInLeft, uint128 price,) = pair.getSwapOut(uint128(amount), tokenIn == tokenX);
require(amountInLeft == 0, InsufficientOutputAmount(amountInLeft));

// --------------- perform the swap
pair.swap(tokenX == tokenIn, recipient);

// --------------- actual amount out received by the recipient
uint balanceAfter = IERC20(tokenOut).balanceOf(recipient);
uint amountOut = balanceAfter > balanceBefore ? balanceAfter - balanceBefore : 0;

// --------------- verify that price impact is within the tolerance limit
uint priceImpact = (price - amountOut) * ConstantsLib.DENOMINATOR / price;
if (priceImpact >= priceImpactTolerance) {
revert(string(abi.encodePacked("!PRICE ", Strings.toString(priceImpact))));
}

emit SwapInPool(pool, tokenIn, tokenOut, recipient, priceImpactTolerance, amount, amountOut);
}

Check warning

Code scanning / Slither

Unused return Medium

Comment on lines +114 to +129
function getPrice(address pool, address tokenIn, address tokenOut, uint amount) public view returns (uint price) {
address tokenX = ILbPairV2(pool).getTokenX();
if (_isValid(ILbPairV2(pool), tokenIn, tokenOut, tokenX)) {
if (amount == 0) {
amount = 10 ** IERC20Metadata(tokenIn).decimals();
}
(uint128 amountInLeft, uint128 amountOut,) = ILbPairV2(pool).getSwapOut(uint128(amount), tokenIn == tokenX);

// todo how to handle following case without reverting?
require(amountInLeft == 0, InsufficientOutputAmount(amountInLeft));

price = amountOut;
}

return price;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Amm Adapter for LFJ

2 participants