diff --git a/src/RaidGeld.sol b/src/RaidGeld.sol index ec19970..b480bb8 100644 --- a/src/RaidGeld.sol +++ b/src/RaidGeld.sol @@ -36,6 +36,7 @@ contract RaidGeld is ERC20, Ownable, Constants { uint24 internal poolFee = 10000; INonfungiblePositionManager public nonfungiblePositionManager; // RGCVII pool + address public DAOWETHpool; address public pool; // Uniswap ISwapRouter02 private constant router = ISwapRouter02(SWAP_ROUTER); @@ -55,7 +56,16 @@ contract RaidGeld is ERC20, Ownable, Constants { uint16 anointedLevel, uint16 championLevel ); - event DaoTokenBuyInAmountSet(address indexed owner, uint256 oldAmount, uint256 newAmount); + event DaoTokenBuyInAmountSet(address indexed owner, uint256 oldAmount, uint256 newAmount); + + /* * @notice emitted when the UniV3 pool is created and the initial liquidity position is minted + * @param pool pool address + * @param positionId NFT position Id + * @param sqrtPriceX96 initial token price + * @param liquidity final liquidity provided + * @param amount0 final amount of liquidity provided for token0 + * @param amount1 final amount of liquidity provided for token1 + * */ event UniswapPositionCreated( address indexed pool, uint256 indexed positionId, @@ -63,7 +73,7 @@ contract RaidGeld is ERC20, Ownable, Constants { uint128 liquidity, uint256 amount0, uint256 amount1 - ); + ); // Modifier for functions that should only be available to registered players modifier onlyPlayer() { require(players[msg.sender].created_at != 0, "Not an initiated player"); @@ -72,7 +82,7 @@ contract RaidGeld is ERC20, Ownable, Constants { // Modifier for dao to deploy the swap pool modifier onlyDaoOnlyOnce() { - require(msg.sender == DAO && poolDeployed == false, "Not DAO"); + require(msg.sender == DAO && poolDeployed == false, "Not DAO or pool already deployed"); _; poolDeployed = true; } @@ -92,7 +102,7 @@ contract RaidGeld is ERC20, Ownable, Constants { constructor(address _daoToken, address _pool, address _baal, address _nftPositionManager) ERC20("Raid Geld", "GELD") Ownable(msg.sender) { daoToken = ERC20(_daoToken); - pool = _pool; + DAOWETHpool = _pool; baal = IBaal(_baal); BUY_IN_DAO_TOKEN_AMOUNT = 500 * 10 ** daoToken.decimals(); nonfungiblePositionManager = INonfungiblePositionManager(_nftPositionManager); @@ -175,7 +185,6 @@ contract RaidGeld is ERC20, Ownable, Constants { } function performSacrifice(uint256 _baseAmount) private { uint256 amount = _baseAmount * SACRIFICE_SHARE / MANTISSA; - address[] memory tokens = new address[](0); _ragequit(amount); } @@ -327,8 +336,7 @@ contract RaidGeld is ERC20, Ownable, Constants { function deploySwapPool(uint256 _geldAmount, uint256 _daoTokenAmount) external onlyDaoOnlyOnce { - uint256 daoBalanceBefore = daoToken.balanceOf(address(this)); - uint256 geldBalanceBefore = balanceOf(address(this)); + daoToken.transferFrom(DAO, address(this), _daoTokenAmount); _mint(address(this), _geldAmount); bool isGeldFirst = address(this) < address(daoToken); @@ -362,34 +370,22 @@ contract RaidGeld is ERC20, Ownable, Constants { amount1Desired: liquidityAmount1, amount0Min: 0, amount1Min: 0, - recipient: _msgSender(), // baalVaultOnly ensures vault is the caller + recipient: DAO, deadline: block.timestamp + 15 minutes // Ensure a reasonable deadline }); // Mint the position - (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1) = nonfungiblePositionManager.mint( + (uint256 tokenId, uint128 liquidity, uint256 amount0 , uint256 amount1) = nonfungiblePositionManager.mint( mintParams ); - - // Remove allowance and refund in both assets. - uint256 daoRefund = daoBalanceBefore - daoToken.balanceOf(address(this)); - if (daoRefund > 0) { - TransferHelper.safeApprove(address(daoToken), address(nonfungiblePositionManager), 0); - _ragequit(daoRefund); - } - uint256 geldRefund = geldBalanceBefore - balanceOf(address(this)); - if (geldRefund > 0) { - TransferHelper.safeApprove(address(this), address(nonfungiblePositionManager), 0); - _burn(address(this), geldRefund); - } - - - + // daoToken dust will join the reward poool + // this contract should not hold any $GELD so we burn all remaining balance + _burn(address(this), balanceOf(address(this))); + emit UniswapPositionCreated(pool, tokenId, sqrtPriceX96, liquidity, amount0, amount1); - } - + } function _ragequit(uint256 _amount) private { address[] memory tokens = new address[](0); diff --git a/test/RaidGeld.t.sol b/test/RaidGeld.t.sol index 05ca611..e71a781 100644 --- a/test/RaidGeld.t.sol +++ b/test/RaidGeld.t.sol @@ -7,6 +7,8 @@ import {RaidGeld, Army, Player, Boss} from "../src/RaidGeld.sol"; import "../src/RaidGeldUtils.sol"; import {Constants} from "../src/Constants.sol"; +import {IUniswapV3Pool} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol"; + contract raid_geldTest is Test, Constants { using stdStorage for StdStorage; @@ -58,6 +60,7 @@ contract raid_geldTest is Test, Constants { vm.expectRevert(); // Send Ether with some data to trigger fallback (bool success,) = address(raid_geld).call{value: 0.1 ether}("0x1234"); + if (success) this; } function test_01_no_receive() public { @@ -397,4 +400,36 @@ contract raid_geldTest is Test, Constants { } require(success, "Player should eventually succeed"); } + + + function test_10_dao_seeds_uniV3_pool() public { + vm.prank(owner); + raid_geld.setDaoAddress(address(this)); + assertEq(raid_geld.DAO(), address(this)); + + uint256 DAO_DAO_BALANCE = 10000000 ether; + uint256 DAO_TOKEN_LIQUIDITY = 10000 ether; + uint256 GELD_LIQUIDITY = DAO_TOKEN_LIQUIDITY * 10; + stdstore.target(DAO_TOKEN).sig("balanceOf(address)").with_key(address(this)).checked_write(DAO_DAO_BALANCE); + assertEq(raid_geld.daoToken().balanceOf(address(this)), DAO_DAO_BALANCE); + + vm.expectRevert("Not DAO or pool already deployed"); + vm.prank(owner); + raid_geld.deploySwapPool(GELD_LIQUIDITY, DAO_TOKEN_LIQUIDITY); + + // Deploying pool should work, done by DAO + raid_geld.daoToken().approve(address(raid_geld), DAO_TOKEN_LIQUIDITY); + raid_geld.deploySwapPool(GELD_LIQUIDITY, DAO_TOKEN_LIQUIDITY); + + address token0 = IUniswapV3Pool(raid_geld.pool()).token0(); + address token1 = IUniswapV3Pool(raid_geld.pool()).token1(); + if (DAO_TOKEN < address(raid_geld)) { + assertEq(token0, DAO_TOKEN); + assertEq(token1, address(raid_geld)); + } else { + assertEq(token0, address(raid_geld)); + assertEq(token1, DAO_TOKEN); + } + + } }