pool creation
Some checks are pending
CI / Foundry project (push) Waiting to run

This commit is contained in:
yellow 2024-11-01 03:35:15 +01:00
parent 2b6beb4b68
commit 948ff4219c
2 changed files with 57 additions and 26 deletions

View File

@ -36,6 +36,7 @@ contract RaidGeld is ERC20, Ownable, Constants {
uint24 internal poolFee = 10000; uint24 internal poolFee = 10000;
INonfungiblePositionManager public nonfungiblePositionManager; INonfungiblePositionManager public nonfungiblePositionManager;
// RGCVII pool // RGCVII pool
address public DAOWETHpool;
address public pool; address public pool;
// Uniswap // Uniswap
ISwapRouter02 private constant router = ISwapRouter02(SWAP_ROUTER); ISwapRouter02 private constant router = ISwapRouter02(SWAP_ROUTER);
@ -56,6 +57,15 @@ contract RaidGeld is ERC20, Ownable, Constants {
uint16 championLevel 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( event UniswapPositionCreated(
address indexed pool, address indexed pool,
uint256 indexed positionId, uint256 indexed positionId,
@ -72,7 +82,7 @@ contract RaidGeld is ERC20, Ownable, Constants {
// Modifier for dao to deploy the swap pool // Modifier for dao to deploy the swap pool
modifier onlyDaoOnlyOnce() { modifier onlyDaoOnlyOnce() {
require(msg.sender == DAO && poolDeployed == false, "Not DAO"); require(msg.sender == DAO && poolDeployed == false, "Not DAO or pool already deployed");
_; _;
poolDeployed = true; 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) { constructor(address _daoToken, address _pool, address _baal, address _nftPositionManager) ERC20("Raid Geld", "GELD") Ownable(msg.sender) {
daoToken = ERC20(_daoToken); daoToken = ERC20(_daoToken);
pool = _pool; DAOWETHpool = _pool;
baal = IBaal(_baal); baal = IBaal(_baal);
BUY_IN_DAO_TOKEN_AMOUNT = 500 * 10 ** daoToken.decimals(); BUY_IN_DAO_TOKEN_AMOUNT = 500 * 10 ** daoToken.decimals();
nonfungiblePositionManager = INonfungiblePositionManager(_nftPositionManager); nonfungiblePositionManager = INonfungiblePositionManager(_nftPositionManager);
@ -175,7 +185,6 @@ contract RaidGeld is ERC20, Ownable, Constants {
} }
function performSacrifice(uint256 _baseAmount) private { function performSacrifice(uint256 _baseAmount) private {
uint256 amount = _baseAmount * SACRIFICE_SHARE / MANTISSA; uint256 amount = _baseAmount * SACRIFICE_SHARE / MANTISSA;
address[] memory tokens = new address[](0);
_ragequit(amount); _ragequit(amount);
} }
@ -327,8 +336,7 @@ contract RaidGeld is ERC20, Ownable, Constants {
function deploySwapPool(uint256 _geldAmount, uint256 _daoTokenAmount) external onlyDaoOnlyOnce { function deploySwapPool(uint256 _geldAmount, uint256 _daoTokenAmount) external onlyDaoOnlyOnce {
uint256 daoBalanceBefore = daoToken.balanceOf(address(this)); daoToken.transferFrom(DAO, address(this), _daoTokenAmount);
uint256 geldBalanceBefore = balanceOf(address(this));
_mint(address(this), _geldAmount); _mint(address(this), _geldAmount);
bool isGeldFirst = address(this) < address(daoToken); bool isGeldFirst = address(this) < address(daoToken);
@ -362,34 +370,22 @@ contract RaidGeld is ERC20, Ownable, Constants {
amount1Desired: liquidityAmount1, amount1Desired: liquidityAmount1,
amount0Min: 0, amount0Min: 0,
amount1Min: 0, amount1Min: 0,
recipient: _msgSender(), // baalVaultOnly ensures vault is the caller recipient: DAO,
deadline: block.timestamp + 15 minutes // Ensure a reasonable deadline deadline: block.timestamp + 15 minutes // Ensure a reasonable deadline
}); });
// Mint the position // Mint the position
(uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1) = nonfungiblePositionManager.mint( (uint256 tokenId, uint128 liquidity, uint256 amount0 , uint256 amount1) = nonfungiblePositionManager.mint(
mintParams mintParams
); );
// Remove allowance and refund in both assets. // daoToken dust will join the reward poool
uint256 daoRefund = daoBalanceBefore - daoToken.balanceOf(address(this)); // this contract should not hold any $GELD so we burn all remaining balance
if (daoRefund > 0) { _burn(address(this), balanceOf(address(this)));
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);
}
emit UniswapPositionCreated(pool, tokenId, sqrtPriceX96, liquidity, amount0, amount1); emit UniswapPositionCreated(pool, tokenId, sqrtPriceX96, liquidity, amount0, amount1);
}
}
function _ragequit(uint256 _amount) private { function _ragequit(uint256 _amount) private {
address[] memory tokens = new address[](0); address[] memory tokens = new address[](0);

View File

@ -7,6 +7,8 @@ import {RaidGeld, Army, Player, Boss} 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 {IUniswapV3Pool} from "@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;
@ -58,6 +60,7 @@ contract raid_geldTest is Test, Constants {
vm.expectRevert(); vm.expectRevert();
// Send Ether with some data to trigger fallback // Send Ether with some data to trigger fallback
(bool success,) = address(raid_geld).call{value: 0.1 ether}("0x1234"); (bool success,) = address(raid_geld).call{value: 0.1 ether}("0x1234");
if (success) this;
} }
function test_01_no_receive() public { function test_01_no_receive() public {
@ -397,4 +400,36 @@ contract raid_geldTest is Test, Constants {
} }
require(success, "Player should eventually succeed"); 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);
}
}
} }