1
0
forked from mico/idle_moloch

Swapping WETH -> RGCVII

This commit is contained in:
mic0 2024-10-27 21:20:38 +01:00
parent d28e33612e
commit aaf1c0fd46
Signed by: mico
GPG Key ID: A3F8023524CF1C8D
5 changed files with 29 additions and 19 deletions

View File

@ -1,2 +1,3 @@
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/ @openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/
@uniswap/v3-periphery/contracts/=lib/v3-periphery/contracts @uniswap/v3-periphery/contracts/=lib/v3-periphery/contracts
@uniswap/v3-core/contracts/=lib/v3-core/contracts

View File

@ -3,7 +3,6 @@ pragma solidity ^0.8.13;
import {Script, console} from "forge-std/Script.sol"; import {Script, console} from "forge-std/Script.sol";
import {RaidGeld} from "../src/RaidGeld.sol"; import {RaidGeld} from "../src/RaidGeld.sol";
import {Constants} from "../src/Constants.sol"; import {Constants} from "../src/Constants.sol";
contract RaidGeldScript is Script, Constants { contract RaidGeldScript is Script, Constants {

View File

@ -5,6 +5,6 @@ contract Constants {
//base addresses //base addresses
address public constant DAO_TOKEN = 0x11dC980faf34A1D082Ae8A6a883db3A950a3c6E8; address public constant DAO_TOKEN = 0x11dC980faf34A1D082Ae8A6a883db3A950a3c6E8;
address public constant POOL = 0x27004f6d0c1bB7979367D32Ba9d6DF6d61A18926; address public constant POOL = 0x27004f6d0c1bB7979367D32Ba9d6DF6d61A18926;
address public constant WETH9 = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; address public constant WETH = 0x4200000000000000000000000000000000000006;
address public constant SWAP_ROUTER_02 = 0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45; address public constant SWAP_ROUTER = 0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD;
} }

View File

@ -7,8 +7,9 @@ import '@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol';
import '@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol'; import '@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol';
import {RaidGeldUtils} from "../src/RaidGeldUtils.sol"; import {RaidGeldUtils} from "../src/RaidGeldUtils.sol";
import {Army, Player, Raider} from "../src/RaidGeldStructs.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 MANTISSA = 1e4;
uint256 public constant BUY_IN_AMOUNT = 0.0005 ether; uint256 public constant BUY_IN_AMOUNT = 0.0005 ether;
@ -18,13 +19,13 @@ contract RaidGeld is ERC20, Ownable {
mapping(address => Army) private armies; mapping(address => Army) private armies;
// WETH // WETH
IERC20 private constant weth = IERC20(Constants.WETH); IERC20 public immutable weth = IERC20(WETH);
// RGCVII token // RGCVII token
ERC20 public daoToken; ERC20 public daoToken;
// RGCVII pool // RGCVII pool
address public pool; address public pool;
// Uniswap // 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 for functions that should only be available to registered players
modifier onlyPlayer() { modifier onlyPlayer() {
@ -46,7 +47,6 @@ contract RaidGeld is ERC20, Ownable {
function init_player(address player) private { function init_player(address player) private {
// Mint some starting tokens to the player // Mint some starting tokens to the player
_mint(player, INITIAL_GELD); _mint(player, INITIAL_GELD);
// Set initial states // Set initial states
players[player] = players[player] =
Player({total_minted: INITIAL_GELD, created_at: block.timestamp, last_raided_at: block.timestamp}); 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 // New player want to register with ETH
function register_eth() external payable newPlayer { function register_eth() external payable newPlayer {
require(weth.transferFrom(msg.sender, address(this), BUY_IN_AMOUNT), "Make sure to send exactly 0.0005 eth"); require(weth.transferFrom(msg.sender, address(this), BUY_IN_AMOUNT), "Make sure to send exactly 0.0005 eth");
weth.approve(address(router), amountIn); TransferHelper.safeApprove(WETH, address(router), BUY_IN_AMOUNT);
ISwapRouter02.ExactInputSingleParams memory params = ISwapRouter02 ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams({
.ExactInputSingleParams({
tokenIn: WETH, tokenIn: WETH,
tokenOut: DAI, tokenOut: DAO_TOKEN,
fee: 3000, fee: 10000,
recipient: msg.sender, recipient: address(this),
amountIn: amountIn, deadline: block.timestamp,
amountOutMinimum: amountOutMin, amountIn: BUY_IN_AMOUNT,
amountOutMinimum: 0,
sqrtPriceLimitX96: 0 sqrtPriceLimitX96: 0
}); });
router.exactInputSingle(params); router.exactInputSingle(params);
init_player(); init_player(msg.sender);
} }
// New player wants to register with dao // New player wants to register with dao

View File

@ -6,8 +6,10 @@ import {stdStorage, StdStorage} from "forge-std/Test.sol";
import {RaidGeld, Army, Player} from "../src/RaidGeld.sol"; import {RaidGeld, Army, Player} from "../src/RaidGeld.sol";
import "../src/RaidGeldUtils.sol"; import "../src/RaidGeldUtils.sol";
import {Constants} from "../src/Constants.sol"; import {Constants} from "../src/Constants.sol";
import "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
contract raid_geldTest is Test, Constants { contract raid_geldTest is Test, Constants {
using stdStorage for StdStorage; using stdStorage for StdStorage;
RaidGeld public raid_geld; RaidGeld public raid_geld;
@ -27,10 +29,18 @@ contract raid_geldTest is Test, Constants {
function fundAccount(address _acc) private { function fundAccount(address _acc) private {
vm.deal(_acc, 10 ether); vm.deal(_acc, 10 ether);
stdstore.target(DAO_TOKEN).sig("balanceOf(address)").with_key(_acc).checked_write(100 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 { 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 { function registerPlayerWithDaoToken() private {
@ -129,7 +139,7 @@ contract raid_geldTest is Test, Constants {
function test_03_02_RGCVII_funds_can_be_withdrawn() public { function test_03_02_RGCVII_funds_can_be_withdrawn() public {
uint256 initialBalance = raid_geld.daoToken().balanceOf(address(raid_geld)); uint256 initialBalance = raid_geld.daoToken().balanceOf(address(raid_geld));
// Switch to Player 1 and register it // Switch to Player 1 and register it
vm.startPrank(player1); vm.startPrank(player1);
registerPlayerWithDaoToken(); registerPlayerWithDaoToken();
@ -138,7 +148,7 @@ contract raid_geldTest is Test, Constants {
vm.startPrank(owner); vm.startPrank(owner);
raid_geld.withdraw_dao(); raid_geld.withdraw_dao();
uint256 newBalance = raid_geld.daoToken().balanceOf(address(owner)); 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 // contract balance should be empty
assertEq(newContractBalance, 0); assertEq(newContractBalance, 0);