diff --git a/foundry.toml b/foundry.toml index 9b61783..5ce6dcd 100644 --- a/foundry.toml +++ b/foundry.toml @@ -3,9 +3,17 @@ src = "src" out = "out" libs = ["lib"] +# upgrades +ffi = true +ast = true +build_info = true +extra_output = ["storageLayout"] + # See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options remappings = [ "@uniswap/v3-core/=lib/v3-core/", "@uniswap/v3-periphery=lib/v3-periphery/", + "@openzeppelin/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/", + "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/", ] \ No newline at end of file diff --git a/script/RaidGeld.s.sol b/script/RaidGeld.s.sol index 84e52db..807a7e6 100644 --- a/script/RaidGeld.s.sol +++ b/script/RaidGeld.s.sol @@ -12,7 +12,7 @@ contract RaidGeldScript is Script, Constants { function run() public { vm.startBroadcast(); - raidgeld = new RaidGeld(DAO_TOKEN, POOL, BAAL, NFT_POSITION_MANAGER); + // raidgeld = new RaidGeld(DAO_TOKEN, POOL, BAAL, NFT_POSITION_MANAGER); vm.stopBroadcast(); } } diff --git a/src/RaidGeld.sol b/src/RaidGeld.sol index 7ab5d96..09dced7 100644 --- a/src/RaidGeld.sol +++ b/src/RaidGeld.sol @@ -1,12 +1,13 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.13; -import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; -import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; +import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol"; +import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; +import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import {IBaal} from "lib/Baal/contracts/interfaces/IBaal.sol"; import { IUniswapV3Factory } from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol"; -import { IERC20, TransferHelper } from "@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol"; +import { TransferHelper } from "@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol"; import { INonfungiblePositionManager } from "./lib/INonfungiblePositionManager.sol"; import { CustomMath} from "./lib/CustomMath.sol"; @@ -16,7 +17,7 @@ import {Army, Player, Raider, Boss, LastBossResult} from "../src/RaidGeldStructs import { Constants} from "../src/Constants.sol"; -contract RaidGeld is ERC20, Ownable, Constants, IRaidGeld { +contract RaidGeld is ERC20Upgradeable, OwnableUpgradeable, Constants, IRaidGeld { uint256 public constant MANTISSA = 1e4; uint256 public constant BUY_IN_AMOUNT = 0.00045 ether; uint256 public BUY_IN_DAO_TOKEN_AMOUNT; @@ -28,15 +29,15 @@ contract RaidGeld is ERC20, Ownable, Constants, IRaidGeld { mapping(address => LastBossResult) private lastBossResults; // WETH - IWETH public immutable weth = IWETH(WETH); + IWETH public constant weth = IWETH(WETH); // RGCVII token - ERC20 public daoToken; + IERC20Metadata public daoToken; IBaal public baal; address public DAO; - bool poolDeployed = false; + bool poolDeployed; int24 internal maxTick; int24 internal minTick; - uint24 internal poolFee = 10000; + uint24 internal constant poolFee = 10000; INonfungiblePositionManager public nonfungiblePositionManager; // RGCVII pool address public DAOWETHpool; @@ -106,8 +107,25 @@ contract RaidGeld is ERC20, Ownable, Constants, IRaidGeld { _; } - constructor(address _daoToken, address _pool, address _baal, address _nftPositionManager) ERC20("Raid Geld", "GELD") Ownable(msg.sender) { - daoToken = ERC20(_daoToken); + // constructor(address _daoToken, address _pool, address _baal, address _nftPositionManager) { + // daoToken = IERC20Metadata(_daoToken); + // DAOWETHpool = _pool; + // baal = IBaal(_baal); + // BUY_IN_DAO_TOKEN_AMOUNT = 400 * 10 ** daoToken.decimals(); + // nonfungiblePositionManager = INonfungiblePositionManager(_nftPositionManager); + + // IUniswapV3Factory factory = IUniswapV3Factory(nonfungiblePositionManager.factory()); + // int24 tickSpacing = factory.feeAmountTickSpacing(poolFee); + // require(tickSpacing != 0, "InvalidPoolFee"); + // maxTick = (887272 / tickSpacing) * tickSpacing; + // minTick = -maxTick; + // } + + function initialize(address _owner, address _daoToken, address _pool, address _baal, address _nftPositionManager) public initializer { + __ERC20_init("RaidGeld", "GELD"); + __Ownable_init(_owner); + + daoToken = IERC20Metadata(_daoToken); DAOWETHpool = _pool; baal = IBaal(_baal); BUY_IN_DAO_TOKEN_AMOUNT = 400 * 10 ** daoToken.decimals(); @@ -466,7 +484,7 @@ interface ISwapRouter02 { function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn); } -interface IWETH is IERC20 { +interface IWETH is IERC20Metadata { function deposit() external payable; function withdraw(uint256 amount) external; } diff --git a/test/RaidGeld.t.sol b/test/RaidGeld.t.sol index a94200d..2ea7318 100644 --- a/test/RaidGeld.t.sol +++ b/test/RaidGeld.t.sol @@ -3,6 +3,7 @@ pragma solidity ^0.8.13; import {Test, console} from "forge-std/Test.sol"; import {stdStorage, StdStorage} from "forge-std/Test.sol"; +import {Upgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol"; import {RaidGeld, Army, Player, Boss, LastBossResult} from "../src/RaidGeld.sol"; import "../src/RaidGeldUtils.sol"; import {Constants} from "../src/Constants.sol"; @@ -38,7 +39,22 @@ contract raid_geldTest is Test, Constants { vm.deal(owner, 10 ether); fundAccount(player1); vm.prank(owner); - raid_geld = new RaidGeld(DAO_TOKEN, POOL, BAAL, NFT_POSITION_MANAGER); + // raid_geld = new RaidGeld(DAO_TOKEN, POOL, BAAL, NFT_POSITION_MANAGER); + // raid_geld.weth().deposit{value: 5 ether}(); + + address proxy = Upgrades.deployUUPSProxy( + "RaidGeld.sol:RaidGeld", + abi.encodeCall(RaidGeld.initialize, ( + owner, + DAO_TOKEN, + POOL, + BAAL, + NFT_POSITION_MANAGER + )) + ); + + console.log("Upgrades sysmbol", RaidGeld(payable(proxy)).symbol()); + raid_geld = RaidGeld(payable(proxy)); raid_geld.weth().deposit{value: 5 ether}(); } diff --git a/test/RaidGeldUtils.t.sol b/test/RaidGeldUtils.t.sol index 341a6f9..e56189b 100644 --- a/test/RaidGeldUtils.t.sol +++ b/test/RaidGeldUtils.t.sol @@ -17,7 +17,7 @@ contract raid_geldTest is Test, Constants { owner = address(0x126); vm.deal(owner, 10 ether); vm.prank(owner); - raid_geld = new RaidGeld(DAO_TOKEN, POOL, BAAL, NFT_POSITION_MANAGER); + // raid_geld = new RaidGeld(DAO_TOKEN, POOL, BAAL, NFT_POSITION_MANAGER); raid_geld.weth().deposit{value: 5 ether}(); }