TestExpectedPayout.t.sol
1 pragma solidity >=0.6.0; 2 3 import "truffle/Assert.sol"; 4 import "../../../contracts/utils/MoreMath.sol"; 5 import "./Base.t.sol"; 6 7 contract TestExpectedPayout is Base { 8 9 function testSingleOptionExpectedPayout() public { 10 11 int step = 30e18; 12 depositTokens(address(bob), upperVol); 13 14 15 addSymbol(uint(ethInitialPrice), time.getNow() + 1 days); 16 (bool success1,) = address(bob).call( 17 abi.encodePacked( 18 bob.writeOption.selector, 19 abi.encode(CALL, ethInitialPrice, 1 days, pool) 20 ) 21 ); 22 23 24 feed.setPrice(ethInitialPrice - step); 25 Assert.equal(exchange.calcExpectedPayout(address(bob)), 0, "bob payout below strike"); 26 Assert.equal(exchange.calcExpectedPayout(pool), 0, "alice payout below strike"); 27 28 feed.setPrice(ethInitialPrice); 29 Assert.equal(exchange.calcExpectedPayout(address(bob)), 0, "bob payout at strike"); 30 Assert.equal(exchange.calcExpectedPayout(pool), 0, "alice payout at strike"); 31 32 feed.setPrice(ethInitialPrice + step); 33 Assert.equal(exchange.calcExpectedPayout(address(bob)), -step, "bob payout above strike"); 34 Assert.equal(exchange.calcExpectedPayout(pool), step, "alice payout above strike"); 35 } 36 37 function testOptionsPortifolioExpectedPayout() public { 38 39 int step = 30e18; 40 depositTokens(address(bob), 15 * upperVol); 41 42 //address _tk1 = bob.writeOptions(3, CALL, ethInitialPrice, 5 days, pool); 43 //bob.transferOptions(address(alice), _tk1, 3); 44 45 addSymbol(uint(ethInitialPrice), time.getNow() + 5 days); 46 (bool success1,) = address(bob).call( 47 abi.encodePacked( 48 bob.writeOptions.selector, 49 abi.encode(3, CALL, ethInitialPrice, 5 days, pool) 50 ) 51 ); 52 53 //address _tk2 = bob.writeOption(PUT, ethInitialPrice + step, 5 days, pool); 54 //bob.transferOptions(address(alice), _tk2, 1); 55 56 addSymbol(uint(ethInitialPrice), time.getNow() + 1 days); 57 (bool success2,) = address(bob).call( 58 abi.encodePacked( 59 bob.writeOption.selector, 60 abi.encode(PUT, ethInitialPrice+step, 5 days, pool) 61 ) 62 ); 63 64 feed.setPrice(ethInitialPrice - step); 65 Assert.equal(exchange.calcExpectedPayout(address(bob)), -2 * step, "bob payout below strike"); 66 Assert.equal(exchange.calcExpectedPayout(address(alice)), 2 * step, "alice payout below strike"); 67 68 feed.setPrice(ethInitialPrice); 69 Assert.equal(exchange.calcExpectedPayout(address(bob)), -step, "bob payout at strike"); 70 Assert.equal(exchange.calcExpectedPayout(address(alice)), step, "alice payout at strike"); 71 72 feed.setPrice(ethInitialPrice + step); 73 Assert.equal(exchange.calcExpectedPayout(address(bob)), -3 * step, "bob payout above strike"); 74 Assert.equal(exchange.calcExpectedPayout(address(alice)), 3 * step, "alice payout above strike"); 75 } 76 }