From e56765f067af61839fbcd3423ba7b1a5df6ddca9 Mon Sep 17 00:00:00 2001 From: Matthew Pereira Date: Sun, 22 Dec 2024 11:32:24 -0800 Subject: [PATCH] Fix math for exact out swaps for CPP --- packages/foundry/contracts/pools/ConstantProductPool.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/foundry/contracts/pools/ConstantProductPool.sol b/packages/foundry/contracts/pools/ConstantProductPool.sol index 898e7ed2..623dfc16 100644 --- a/packages/foundry/contracts/pools/ConstantProductPool.sol +++ b/packages/foundry/contracts/pools/ConstantProductPool.sol @@ -40,8 +40,8 @@ contract ConstantProductPool is BalancerPoolToken, IBasePool { amountCalculatedScaled18 = (poolBalancetokenOut * amountTokenIn) / (poolBalancetokenIn + amountTokenIn); } else { uint256 amountTokenOut = params.amountGivenScaled18; // dy - // dx = (X * dy) / (Y + dx) - amountCalculatedScaled18 = (poolBalancetokenIn * amountTokenOut) / (poolBalancetokenOut + amountTokenOut); + // dx = (X * dy) / (Y - dy) + amountCalculatedScaled18 = (poolBalancetokenIn * amountTokenOut) / (poolBalancetokenOut - amountTokenOut); } }