diff --git a/hw/src/TrustedOracle.sol b/hw/src/TrustedOracle.sol index ee93370..ecaa92d 100644 --- a/hw/src/TrustedOracle.sol +++ b/hw/src/TrustedOracle.sol @@ -46,27 +46,9 @@ contract TrustedOracle { } } -interface AggregatorV3Interface { - function latestRoundData() - external - view - returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound); -} - +// TODO: Complete the chainlink oracle implementation contract ChainlinkOracle { - AggregatorV3Interface internal priceFeed; - - constructor(address addr) { - priceFeed = AggregatorV3Interface(addr); - } + constructor(address) {} - function getPrice() public view returns (uint256) { - (, int256 price,,,) = priceFeed.latestRoundData(); - - return uint256(price); - } - - function getDecimals() public pure returns (uint8) { - return 8; - } + function getPrice() public view returns (uint256) {} } diff --git a/hw/test/MultiPair/MultiPairBase.t.sol b/hw/test/MultiPair/MultiPairBase.t.sol index 5a1aa9b..d83384d 100644 --- a/hw/test/MultiPair/MultiPairBase.t.sol +++ b/hw/test/MultiPair/MultiPairBase.t.sol @@ -36,7 +36,7 @@ contract MultiPairBaseTest is Test { uint256 tokensBefore = tokenB.balanceOf(arbitrager); _; uint256 tokensAfter = tokenB.balanceOf(arbitrager); - assertGt(tokensAfter, 20 ether); + assertGt(tokensAfter, 22 ether); vm.stopPrank(); } diff --git a/hw/test/SashaV2/SashaV2.t.sol b/hw/test/SashaV2/SashaV2.t.sol index 3314c8f..76d439f 100644 --- a/hw/test/SashaV2/SashaV2.t.sol +++ b/hw/test/SashaV2/SashaV2.t.sol @@ -7,77 +7,10 @@ import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import "../../src/interface.sol"; - -contract Token is ERC20 { - constructor(string memory name, string memory symbol, uint256 initialMint) ERC20(name, symbol) { - _mint(msg.sender, initialMint); - } -} - -contract SashaV2BaseTest is Test { - /// State Variable - - // Role - address internal admin; - address internal arbitrager; - - // Constant - uint256 internal constant INIT_SUPPLY = 100 ether; - - // Router - ISwapV2Router02 UniRouter = ISwapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); - ISwapV2Router02 PankcakeRouter = ISwapV2Router02(0xEfF92A263d31888d860bD50809A8D171709b7b1c); - - // Contract - address internal Balancer = 0xBA12222222228d8Ba445958a75a0704d566BF2C8; - - // Token - address internal LiaoToken; - address internal DAI = 0x6B175474E89094C44Da98b954EedeAC495271d0F; +import {SashaV2BaseTest} from "./SashaV2Base.t.sol"; - // Modifier - modifier validation() { - uint256 tokensBefore = ERC20(DAI).balanceOf(address(this)); - _; - uint256 tokensAfter = ERC20(DAI).balanceOf(address(this)); - assertGt(tokensAfter, tokensBefore); - } - - /// Setup function - function setUp() public { - vm.createSelectFork("https://rpc.ankr.com/eth", 20933505); - - admin = makeAddr("admin"); - arbitrager = makeAddr("arbitrager"); - - vm.startPrank(admin); - - // Environment Configuration - deal(DAI, admin, INIT_SUPPLY); - - LiaoToken = address(new Token("LiaoToken", "LT", INIT_SUPPLY)); - - // // PancakeSwap Pool - _addLiquidity(PankcakeRouter, LiaoToken, DAI, 10 ether, 20 ether); - - // Uniswap Pool - _addLiquidity(UniRouter, LiaoToken, DAI, 10 ether, 10 ether); - - vm.stopPrank(); - } +import "../../src/interface.sol"; - function _addLiquidity( - ISwapV2Router02 router, - address token0, - address token1, - uint256 token0Amount, - uint256 token1Amount - ) internal { - ERC20(token0).approve(address(router), type(uint256).max); - ERC20(token1).approve(address(router), type(uint256).max); - router.addLiquidity( - token0, token1, token0Amount, token1Amount, token0Amount, token1Amount, admin, block.timestamp - ); - } +contract SashaV2Test is SashaV2BaseTest { + function testExploit() public validation {} } diff --git a/hw/test/SashaV2/SashaV2Base.t.sol b/hw/test/SashaV2/SashaV2Base.t.sol index 71aa978..3314c8f 100644 --- a/hw/test/SashaV2/SashaV2Base.t.sol +++ b/hw/test/SashaV2/SashaV2Base.t.sol @@ -7,10 +7,77 @@ import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import {SashaV2BaseTest} from "./SashaV2.t.sol"; - import "../../src/interface.sol"; -contract SashaV2Test is SashaV2BaseTest { - function testExploit() public validation {} +contract Token is ERC20 { + constructor(string memory name, string memory symbol, uint256 initialMint) ERC20(name, symbol) { + _mint(msg.sender, initialMint); + } +} + +contract SashaV2BaseTest is Test { + /// State Variable + + // Role + address internal admin; + address internal arbitrager; + + // Constant + uint256 internal constant INIT_SUPPLY = 100 ether; + + // Router + ISwapV2Router02 UniRouter = ISwapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); + ISwapV2Router02 PankcakeRouter = ISwapV2Router02(0xEfF92A263d31888d860bD50809A8D171709b7b1c); + + // Contract + address internal Balancer = 0xBA12222222228d8Ba445958a75a0704d566BF2C8; + + // Token + address internal LiaoToken; + address internal DAI = 0x6B175474E89094C44Da98b954EedeAC495271d0F; + + // Modifier + modifier validation() { + uint256 tokensBefore = ERC20(DAI).balanceOf(address(this)); + _; + uint256 tokensAfter = ERC20(DAI).balanceOf(address(this)); + assertGt(tokensAfter, tokensBefore); + } + + /// Setup function + function setUp() public { + vm.createSelectFork("https://rpc.ankr.com/eth", 20933505); + + admin = makeAddr("admin"); + arbitrager = makeAddr("arbitrager"); + + vm.startPrank(admin); + + // Environment Configuration + deal(DAI, admin, INIT_SUPPLY); + + LiaoToken = address(new Token("LiaoToken", "LT", INIT_SUPPLY)); + + // // PancakeSwap Pool + _addLiquidity(PankcakeRouter, LiaoToken, DAI, 10 ether, 20 ether); + + // Uniswap Pool + _addLiquidity(UniRouter, LiaoToken, DAI, 10 ether, 10 ether); + + vm.stopPrank(); + } + + function _addLiquidity( + ISwapV2Router02 router, + address token0, + address token1, + uint256 token0Amount, + uint256 token1Amount + ) internal { + ERC20(token0).approve(address(router), type(uint256).max); + ERC20(token1).approve(address(router), type(uint256).max); + router.addLiquidity( + token0, token1, token0Amount, token1Amount, token0Amount, token1Amount, admin, block.timestamp + ); + } }