From 7f169944d9c833c4813fd49c736e5cf38b3df88a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wei=C3=9Fer=20Hase?= Date: Mon, 22 Jul 2024 11:04:51 +0200 Subject: [PATCH] fix: manually calculating spot price --- test/unit/BPool/BPool.t.sol | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/unit/BPool/BPool.t.sol b/test/unit/BPool/BPool.t.sol index e72eff54..7e74d71b 100644 --- a/test/unit/BPool/BPool.t.sol +++ b/test/unit/BPool/BPool.t.sol @@ -18,6 +18,13 @@ contract BPool is BPoolBase, BMath { uint256 balanceTokenIn = 10e18; uint256 balanceTokenOut = 20e18; + // sP = (tokenInBalance / tokenInWeight) / (tokenOutBalance/ tokenOutWeight) * (1 / (1 - swapFee)) + // tokenInWeight == tokenOutWeight + // sP = 10 / 20 = 0.5e18 + // sPf = (10 / 20) * (1 / (1-0.1)) = 0.555...e18 (round-up) + uint256 public spotPriceWithoutFee = 0.5e18; + uint256 public spotPrice = bmul(spotPriceWithoutFee, bdiv(BONE, bsub(BONE, swapFee))); + function setUp() public virtual override { super.setUp(); @@ -327,7 +334,7 @@ contract BPool is BPoolBase, BMath { vm.mockCall(tokens[1], abi.encodePacked(IERC20.balanceOf.selector), abi.encode(balanceTokenOut)); vm.expectCall(tokens[1], abi.encodeWithSelector(IERC20.balanceOf.selector)); // it returns spot price - uint256 _spotPrice = calcSpotPrice(balanceTokenIn, tokenWeight, balanceTokenOut, tokenWeight, swapFee); + uint256 _spotPrice = 0.555555555555555556e18; assertEq(bPool.getSpotPrice(tokens[0], tokens[1]), _spotPrice); } @@ -358,7 +365,7 @@ contract BPool is BPoolBase, BMath { vm.mockCall(tokens[1], abi.encodePacked(IERC20.balanceOf.selector), abi.encode(balanceTokenOut)); vm.expectCall(tokens[1], abi.encodeWithSelector(IERC20.balanceOf.selector)); // it returns spot price - uint256 _spotPrice = calcSpotPrice(balanceTokenIn, tokenWeight, balanceTokenOut, tokenWeight, 0); + uint256 _spotPrice = 0.5e18; assertEq(bPool.getSpotPriceSansFee(tokens[0], tokens[1]), _spotPrice); } }