From aaf1c0fd4649f939a433aff8ef334d6d142baea5 Mon Sep 17 00:00:00 2001 From: Mitja Belak Date: Sun, 27 Oct 2024 21:20:38 +0100 Subject: [PATCH] Swapping WETH -> RGCVII --- remappings.txt | 1 + script/RaidGeld.s.sol | 1 - src/Constants.sol | 4 ++-- src/RaidGeld.sol | 26 +++++++++++++------------- test/RaidGeld.t.sol | 16 +++++++++++++--- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/remappings.txt b/remappings.txt index 69a18fc..dc7d2c1 100644 --- a/remappings.txt +++ b/remappings.txt @@ -1,2 +1,3 @@ @openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/ @uniswap/v3-periphery/contracts/=lib/v3-periphery/contracts +@uniswap/v3-core/contracts/=lib/v3-core/contracts diff --git a/script/RaidGeld.s.sol b/script/RaidGeld.s.sol index 851b83d..1cce4ee 100644 --- a/script/RaidGeld.s.sol +++ b/script/RaidGeld.s.sol @@ -3,7 +3,6 @@ pragma solidity ^0.8.13; import {Script, console} from "forge-std/Script.sol"; import {RaidGeld} from "../src/RaidGeld.sol"; - import {Constants} from "../src/Constants.sol"; contract RaidGeldScript is Script, Constants { diff --git a/src/Constants.sol b/src/Constants.sol index 82c37e3..0b65467 100644 --- a/src/Constants.sol +++ b/src/Constants.sol @@ -5,6 +5,6 @@ contract Constants { //base addresses address public constant DAO_TOKEN = 0x11dC980faf34A1D082Ae8A6a883db3A950a3c6E8; address public constant POOL = 0x27004f6d0c1bB7979367D32Ba9d6DF6d61A18926; - address public constant WETH9 = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; - address public constant SWAP_ROUTER_02 = 0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45; + address public constant WETH = 0x4200000000000000000000000000000000000006; + address public constant SWAP_ROUTER = 0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD; } diff --git a/src/RaidGeld.sol b/src/RaidGeld.sol index 941597e..802da7c 100644 --- a/src/RaidGeld.sol +++ b/src/RaidGeld.sol @@ -7,8 +7,9 @@ import '@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol'; import '@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol'; import {RaidGeldUtils} from "../src/RaidGeldUtils.sol"; import {Army, Player, Raider} from "../src/RaidGeldStructs.sol"; +import "../src/Constants.sol"; -contract RaidGeld is ERC20, Ownable { +contract RaidGeld is ERC20, Ownable, Constants { uint256 public constant MANTISSA = 1e4; uint256 public constant BUY_IN_AMOUNT = 0.0005 ether; @@ -18,13 +19,13 @@ contract RaidGeld is ERC20, Ownable { mapping(address => Army) private armies; // WETH - IERC20 private constant weth = IERC20(Constants.WETH); + IERC20 public immutable weth = IERC20(WETH); // RGCVII token ERC20 public daoToken; // RGCVII pool address public pool; // Uniswap - ISwapRouter02 private constant router = ISwapRouter02(Constants.SWAP_ROUTER_02); + ISwapRouter private constant router = ISwapRouter(SWAP_ROUTER); // Modifier for functions that should only be available to registered players modifier onlyPlayer() { @@ -46,7 +47,6 @@ contract RaidGeld is ERC20, Ownable { function init_player(address player) private { // Mint some starting tokens to the player _mint(player, INITIAL_GELD); - // Set initial states players[player] = Player({total_minted: INITIAL_GELD, created_at: block.timestamp, last_raided_at: block.timestamp}); @@ -62,19 +62,19 @@ contract RaidGeld is ERC20, Ownable { // New player want to register with ETH function register_eth() external payable newPlayer { require(weth.transferFrom(msg.sender, address(this), BUY_IN_AMOUNT), "Make sure to send exactly 0.0005 eth"); - weth.approve(address(router), amountIn); - ISwapRouter02.ExactInputSingleParams memory params = ISwapRouter02 - .ExactInputSingleParams({ + TransferHelper.safeApprove(WETH, address(router), BUY_IN_AMOUNT); + ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams({ tokenIn: WETH, - tokenOut: DAI, - fee: 3000, - recipient: msg.sender, - amountIn: amountIn, - amountOutMinimum: amountOutMin, + tokenOut: DAO_TOKEN, + fee: 10000, + recipient: address(this), + deadline: block.timestamp, + amountIn: BUY_IN_AMOUNT, + amountOutMinimum: 0, sqrtPriceLimitX96: 0 }); router.exactInputSingle(params); - init_player(); + init_player(msg.sender); } // New player wants to register with dao diff --git a/test/RaidGeld.t.sol b/test/RaidGeld.t.sol index 726965c..2a6066f 100644 --- a/test/RaidGeld.t.sol +++ b/test/RaidGeld.t.sol @@ -6,8 +6,10 @@ import {stdStorage, StdStorage} from "forge-std/Test.sol"; import {RaidGeld, Army, Player} from "../src/RaidGeld.sol"; import "../src/RaidGeldUtils.sol"; import {Constants} from "../src/Constants.sol"; +import "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol"; contract raid_geldTest is Test, Constants { + using stdStorage for StdStorage; RaidGeld public raid_geld; @@ -27,10 +29,18 @@ contract raid_geldTest is Test, Constants { function fundAccount(address _acc) private { vm.deal(_acc, 10 ether); stdstore.target(DAO_TOKEN).sig("balanceOf(address)").with_key(_acc).checked_write(100 ether); + stdstore.target(WETH).sig("balanceOf(address)").with_key(_acc).checked_write(100 ether); + } + + function getPoolLiquidity() public view { + IUniswapV3Pool pool = IUniswapV3Pool(POOL); + console.log(pool.liquidity()); } function registerPlayer() private { - raid_geld.register_eth{value: raid_geld.BUY_IN_AMOUNT()}(); + getPoolLiquidity(); + raid_geld.weth().approve(address(raid_geld), raid_geld.BUY_IN_AMOUNT()); + raid_geld.register_eth(); } function registerPlayerWithDaoToken() private { @@ -129,7 +139,7 @@ contract raid_geldTest is Test, Constants { function test_03_02_RGCVII_funds_can_be_withdrawn() public { uint256 initialBalance = raid_geld.daoToken().balanceOf(address(raid_geld)); - + // Switch to Player 1 and register it vm.startPrank(player1); registerPlayerWithDaoToken(); @@ -138,7 +148,7 @@ contract raid_geldTest is Test, Constants { vm.startPrank(owner); raid_geld.withdraw_dao(); uint256 newBalance = raid_geld.daoToken().balanceOf(address(owner)); - uint256 newContractBalance = raid_geld.daoToken().balanceOf(address(raid_geld)); + uint256 newContractBalance = raid_geld.daoToken().balanceOf(address(raid_geld)); // contract balance should be empty assertEq(newContractBalance, 0);