/ test / pools / LinearLiquidityPool / TestPoolVolumes.t.sol
TestPoolVolumes.t.sol
  1  pragma solidity >=0.6.0;
  2  
  3  import "truffle/Assert.sol";
  4  import "./Base.t.sol";
  5  
  6  contract TestPoolVolumes is Base {
  7  
  8      function testPartialBuyingVolume() public {
  9  
 10          createTraders();
 11  
 12          addSymbol();
 13  
 14          uint cUnit = calcCollateralUnit();
 15  
 16          depositInPool(address(bob), 10 * cUnit);
 17          erc20.issue(address(alice), 5 * cUnit);
 18  
 19          (uint p1, uint v1) = IGovernableLiquidityPool(pool).queryBuy(symbol, true);
 20  
 21          (bool success1,) = address(alice).call(
 22              abi.encodePacked(
 23                  alice.buyFromPool.selector,
 24                  abi.encode(symbol, p1, v1 / 2)
 25              )
 26          );
 27  
 28          (, uint v2) = IGovernableLiquidityPool(pool).queryBuy(symbol, true);
 29  
 30          Assert.equal(v2, v1 / 2 + err, "volume after buying");
 31      }
 32  
 33      function testFullBuyingVolume() public {
 34  
 35          createTraders();
 36  
 37          addSymbol();
 38  
 39          uint cUnit = calcCollateralUnit();
 40  
 41          depositInPool(address(bob), 10 * cUnit);
 42          erc20.issue(address(alice), 5 * cUnit);
 43  
 44          (uint p1, uint v1) = IGovernableLiquidityPool(pool).queryBuy(symbol, true);
 45          (bool success1,) = address(alice).call(
 46              abi.encodePacked(
 47                  alice.buyFromPool.selector,
 48                  abi.encode(symbol, p1, v1)
 49              )
 50          );
 51          (, uint v2) = IGovernableLiquidityPool(pool).queryBuy(symbol, true);
 52  
 53          Assert.equal(v2, 0, "volume after buying");
 54      }
 55  
 56      function testPartialSellingVolume() public {
 57  
 58          createTraders();
 59  
 60          addSymbol();
 61  
 62          uint cUnit = calcCollateralUnit();
 63  
 64          depositInPool(address(bob), 1 * cUnit);
 65          erc20.issue(address(alice), 10 * cUnit);
 66          alice.depositInExchange(10 * cUnit);
 67  
 68          (uint p1, uint v1) = IGovernableLiquidityPool(pool).queryBuy(symbol, false);        
 69          (bool success1,) = address(alice).call(
 70              abi.encodePacked(
 71                  alice.sellToPool.selector,
 72                  abi.encode(symbol, p1, v1 / 2)
 73              )
 74          );
 75          (, uint v2) = IGovernableLiquidityPool(pool).queryBuy(symbol, false);
 76  
 77          Assert.equal(v2, v1 / 2 + err, "volume after selling");
 78      }
 79  
 80      function testFullSellingVolume() public {
 81  
 82          createTraders();
 83  
 84          addSymbol();
 85  
 86          uint cUnit = calcCollateralUnit();
 87  
 88          depositInPool(address(bob), 1 * cUnit);
 89          erc20.issue(address(alice), 10 * cUnit);
 90          alice.depositInExchange(10 * cUnit);
 91  
 92          (uint p1, uint v1) = IGovernableLiquidityPool(pool).queryBuy(symbol, false);
 93          (bool success1,) = address(alice).call(
 94              abi.encodePacked(
 95                  alice.sellToPool.selector,
 96                  abi.encode(symbol, p1, v1)
 97              )
 98          );
 99          (, uint v2) = IGovernableLiquidityPool(pool).queryBuy(symbol, false);
100  
101          Assert.equal(v2, 0, "volume after selling");
102      }
103  
104      function testPartialBuyingThenFullSellingVolume() public {
105  
106          createTraders();
107  
108          addSymbol();
109  
110          uint cUnit = calcCollateralUnit();
111  
112          depositInPool(address(bob), 10 * cUnit);
113          erc20.issue(address(alice), 5 * cUnit);
114  
115          (uint p1, uint v1) = IGovernableLiquidityPool(pool).queryBuy(symbol, true);
116          (bool success1,) = address(alice).call(
117              abi.encodePacked(
118                  alice.buyFromPool.selector,
119                  abi.encode(symbol, p1, v1 / 2)
120              )
121          );
122          (, uint v2) = IGovernableLiquidityPool(pool).queryBuy(symbol, true);
123  
124          Assert.equal(v2, v1 / 2 + err, "volume after buying");
125  
126          erc20.issue(address(bob), 100 * cUnit);
127          bob.depositInExchange(100 * cUnit);
128  
129          (uint p3, uint v3) = IGovernableLiquidityPool(pool).queryBuy(symbol, false);
130          (bool success2,) = address(bob).call(
131              abi.encodePacked(
132                  bob.sellToPool.selector,
133                  abi.encode(symbol, p3, v3)
134              )
135          );
136          (, uint v4) = IGovernableLiquidityPool(pool).queryBuy(symbol, false);
137  
138          Assert.equal(v4, 0, "volume after selling");
139      }
140  }