TestPoolYield.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 TestPoolYield is Base { 8 9 uint[] yd; 10 uint[] dt; 11 12 function testYieldAfterDeposits() public { 13 14 createTraders(); 15 16 uint vBase = 1e6; 17 time.setTimeOffset(0); 18 Assert.equal(IGovernableLiquidityPool(pool).yield(365 days), fractionBase, "yield t0"); 19 20 depositInPool(address(bob), 10 * vBase); 21 Assert.equal(IGovernableLiquidityPool(pool).yield(365 days), fractionBase, "yield t1"); 22 23 time.setTimeOffset(30 days); 24 depositInPool(address(bob), 5 * vBase); 25 Assert.equal(IGovernableLiquidityPool(pool).yield(365 days), fractionBase, "yield t2"); 26 27 time.setTimeOffset(90 days); 28 depositInPool(address(alice), 2 * vBase); 29 Assert.equal(IGovernableLiquidityPool(pool).yield(365 days), fractionBase, "yield t3"); 30 } 31 32 function testYieldAfterSingleProfit() public { 33 34 createTraders(); 35 36 cBase = 1e3; 37 uint vBase = 1e6; 38 time.setTimeOffset(0); 39 depositInPool(address(bob), 10 * vBase); 40 41 time.setTimeOffset(180 days); 42 depositInExchangeToPool(2 * vBase); 43 MoreAssert.equal(IGovernableLiquidityPool(pool).yield(365 days), 1200000000, cBase, "yield t1"); 44 45 time.setTimeOffset(365 days); 46 MoreAssert.equal(IGovernableLiquidityPool(pool).yield(365 days), 1200000000, cBase, "yield t2"); 47 48 time.setTimeOffset(500 days); 49 MoreAssert.equal(IGovernableLiquidityPool(pool).yield(365 days), 1142358216, cBase, "yield t3"); 50 } 51 52 function testYieldAfterMultipleProfits() public { 53 54 createTraders(); 55 56 cBase = 1e3; 57 uint vBase = 1e6; 58 time.setTimeOffset(0); 59 depositInPool(address(bob), 10 * vBase); 60 61 time.setTimeOffset(180 days); 62 depositInExchangeToPool(1 * vBase); 63 depositInPool(address(bob), 5 * vBase); 64 MoreAssert.equal(IGovernableLiquidityPool(pool).yield(365 days), 1100000000, cBase, "yield t1"); 65 66 time.setTimeOffset(365 days); 67 depositInExchangeToPool(2 * vBase); 68 depositInPool(address(bob), 10 * vBase); 69 MoreAssert.equal(IGovernableLiquidityPool(pool).yield(365 days), 1237500000, cBase, "yield t2"); 70 71 time.setTimeOffset(500 days); 72 depositInExchangeToPool(56 * vBase / 10); 73 depositInPool(address(bob), 2 * vBase); 74 MoreAssert.equal(IGovernableLiquidityPool(pool).yield(500 days), 1485000000, cBase, "yield t3"); 75 MoreAssert.equal(IGovernableLiquidityPool(pool).yield(365 days), 1382553480, 5e2, "yield t3"); 76 } 77 78 function depositInExchangeToPool(uint value) private { 79 80 erc20.issue(address(this), value); 81 erc20.approve(address(exchange), value); 82 exchange.depositTokens(address(pool), address(erc20), value); 83 } 84 }