/ test / pools / LinearLiquidityPool / TestPoolWithdrawal.t.sol
TestPoolWithdrawal.t.sol
 1  pragma solidity >=0.6.0;
 2  
 3  import "truffle/Assert.sol";
 4  import "../../common/utils/MoreAssert.t.sol";
 5  import "./Base.t.sol";
 6  
 7  contract TestPoolWithdrawal is Base {
 8  
 9      uint[] yd;
10      uint[] dt;
11  
12      function testDepositThenWithdraw() public {
13  
14          createTraders();
15  
16          uint vBase = 1e6;
17          
18          depositInPool(address(bob), 100 * vBase);
19  
20          Assert.equal(IGovernableLiquidityPool(pool).valueOf(address(bob)), 100 * vBase, "bob initial pool value");
21          Assert.equal(exchange.balanceOf(address(bob)), 0, "bob initial exchange balance");
22          Assert.equal(exchange.balanceOf(address(pool)), 100 * vBase, "pool initial exchange balance");
23  
24          depositInPool(address(alice), 100 * vBase);
25  
26          uint bal = IERC20_2(pool).balanceOf(address(bob));
27          uint total1 = IERC20_2(pool).totalSupply();
28  
29          bob.withdrawFromPool();
30  
31          uint total2 = IERC20_2(pool).totalSupply();
32  
33          Assert.equal(total1, total2 + bal, "pool total supply");
34          Assert.equal(IGovernableLiquidityPool(pool).valueOf(address(bob)), 0, "bob final pool value");
35          Assert.equal(exchange.balanceOf(address(bob)), 97 * vBase, "bob final exchange balance");
36          Assert.equal(exchange.balanceOf(address(pool)), 103 * vBase, "pool final exchange balance");
37      }
38  
39      function testWithdrawOverYield() public {
40  
41          createTraders();
42  
43          cBase = 1e3;
44          uint vBase = 1e6;
45          time.setTimeOffset(0);
46          depositInPool(address(bob), 1000 * vBase);
47  
48          time.setTimeOffset(180 days);
49          depositInExchangeToPool(200 * vBase);
50          
51          time.setTimeOffset(365 days);
52          MoreAssert.equal(IGovernableLiquidityPool(pool).yield(365 days), 1200 * vBase, cBase, "initial yield");
53  
54          depositInPool(address(alice), 1000 * vBase);
55          bob.withdrawFromPool();
56  
57          Assert.equal(IGovernableLiquidityPool(pool).valueOf(address(bob)), 0, "bob final pool value");
58          Assert.equal(exchange.balanceOf(address(bob)), 1164 * vBase, "bob final exchange balance");
59          Assert.equal(exchange.balanceOf(address(pool)), 1036 * vBase, "pool final exchange balance");
60  
61          MoreAssert.equal(IGovernableLiquidityPool(pool).yield(365 days), 12432 * 1e5, cBase, "final yield");
62      }
63  
64      function depositInExchangeToPool(uint value) private {
65  
66          erc20.issue(address(this), value);
67          erc20.approve(address(exchange), value);
68          exchange.depositTokens(address(pool), address(erc20), value);
69      }
70  }