From cfa8df617d483065612516ce4860c5d89bca48b7 Mon Sep 17 00:00:00 2001 From: 0xAustrian Date: Mon, 13 May 2024 16:29:48 -0300 Subject: [PATCH] test: wip --- test/unit/BPool.t.sol | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/test/unit/BPool.t.sol b/test/unit/BPool.t.sol index 19eb4a8e..3740ee82 100644 --- a/test/unit/BPool.t.sol +++ b/test/unit/BPool.t.sol @@ -570,14 +570,15 @@ contract BPool_Unit_SwapExactAmountIn is BasePoolTest, BMath { // MAX_IN_RATIO vm.assume(_fuzz.tokenInBalance < type(uint256).max / MAX_IN_RATIO); - vm.assume(_fuzz.tokenAmountIn <= (_fuzz.tokenInBalance * MAX_IN_RATIO) / BONE); + vm.assume(_fuzz.tokenAmountIn <= bmul(_fuzz.tokenInBalance, MAX_IN_RATIO)); // internal calculation for calcSpotPrice - uint _numer = (_fuzz.tokenInBalance * BONE) / _fuzz.tokenInDenorm; - uint _denom = (_fuzz.tokenOutBalance * BONE) / _fuzz.tokenOutDenorm; - uint _ratio = (_numer * BONE) / _denom; - uint _scale = (BONE * BONE) / (BONE - MIN_FEE); - vm.assume(_ratio < type(uint256).max / _scale); + uint _numer = bdiv(_fuzz.tokenInBalance, _fuzz.tokenInDenorm); + uint _denom = bdiv(_fuzz.tokenOutBalance, _fuzz.tokenOutDenorm); + uint _ratio = bdiv(_numer, _denom); + uint _scale = bdiv(BONE, bsub(BONE, MIN_FEE)); + // console.log('_ratio2', _ratio, _scale); + // vm.assume(_ratio < type(uint256).max / _scale); // NOTE: is this needed? // swap uint256 _spotPriceBefore = @@ -590,8 +591,20 @@ contract BPool_Unit_SwapExactAmountIn is BasePoolTest, BMath { _fuzz.tokenAmountIn, MIN_FEE ); - // vm.assume(_tokenAmountOut > BONE); - // vm.assume(_spotPriceBefore <= (_fuzz.tokenAmountIn * BONE) / _tokenAmountOut); + // console.log(1, _tokenAmountOut); + + // internal calculation for calcOutGivenIn + // uint _weightRatio = bdiv(_fuzz.tokenInDenorm, _fuzz.tokenOutDenorm); + // uint _adjustedIn = bsub(BONE, MIN_FEE); + // uint _adjustedIn2 = bmul(_fuzz.tokenAmountIn, _adjustedIn); + // uint _y = bdiv(_fuzz.tokenInBalance, badd(_fuzz.tokenInBalance,_adjustedIn2)); + // uint _foo = bpow(_y, _weightRatio); + // uint _bar = bsub(BONE, _foo); + // uint _tokenAmountOut2 = bmul(_fuzz.tokenOutBalance, _bar); + // console.log(2, _tokenAmountOut2); + + vm.assume(_tokenAmountOut > BONE); + vm.assume(_spotPriceBefore <= bdiv(_fuzz.tokenAmountIn, _tokenAmountOut)); } modifier happyPath(SwapExactAmountIn_FuzzScenario memory _fuzz) {