Skip to content

Commit

Permalink
ren L-03: Ensure erc20 creator crowdfund token ops are valid (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
arr00 authored Apr 11, 2024
1 parent a1f7059 commit 15eca6e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
8 changes: 7 additions & 1 deletion contracts/crowdfund/ERC20LaunchCrowdfund.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ contract ERC20LaunchCrowdfund is InitialETHCrowdfund {
MetadataProvider customMetadataProvider,
bytes memory customMetadata
) external payable {
uint16 feeBasisPoints = 5e3; // Max possible fee
uint256 minTotalSpendableEth = ((((uint256(crowdfundOpts.minTotalContributions) *
(1e4 - crowdfundOpts.fundingSplitBps)) / 1e4) * (1e4 - feeBasisPoints)) / 1e4);

if (
_tokenOpts.numTokensForDistribution +
_tokenOpts.numTokensForRecipient +
Expand All @@ -65,7 +69,9 @@ contract ERC20LaunchCrowdfund is InitialETHCrowdfund {
_tokenOpts.totalSupply > type(uint112).max ||
_tokenOpts.numTokensForLP < 1e4 ||
crowdfundOpts.fundingSplitBps > 5e3 ||
crowdfundOpts.minTotalContributions < 1e4
crowdfundOpts.minTotalContributions < 1e4 ||
crowdfundOpts.maxTotalContributions >= uint256(_tokenOpts.numTokensForLP) * 1e18 ||
_tokenOpts.numTokensForLP >= minTotalSpendableEth * 1e18
) {
revert InvalidTokenDistribution();
}
Expand Down
31 changes: 21 additions & 10 deletions test/crowdfund/ERC20LaunchCrowdfundForked.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,40 @@ pragma solidity ^0.8;

import { SetupPartyHelper, Party } from "../utils/SetupPartyHelper.sol";
import { IERC20 } from "openzeppelin/contracts/interfaces/IERC20.sol";
import { ERC20Creator, IUniswapV2Router02, IUniswapV2Factory, ITokenDistributor } from "erc20-creator/ERC20Creator.sol";
import { ERC20CreatorV3, IUniswapV3Factory, INonfungiblePositionManager, ITokenDistributor } from "erc20-creator/ERC20CreatorV3.sol";
import { FeeCollector, IWETH } from "erc20-creator/FeeCollector.sol";
import { ERC20LaunchCrowdfund, IERC20Creator } from "contracts/crowdfund/ERC20LaunchCrowdfund.sol";
import { CrowdfundFactory } from "contracts/crowdfund/CrowdfundFactory.sol";
import { Vm } from "forge-std/Test.sol";

contract ERC20LaunchCrowdfundForkedTest is SetupPartyHelper {
constructor() onlyForked SetupPartyHelper(true) {}

ERC20Creator internal creator;
ERC20CreatorV3 internal creator;
FeeCollector internal feeCollector;
ERC20LaunchCrowdfund internal launchCrowdfundImpl;
CrowdfundFactory internal crowdfundFactory;

function setUp() public override onlyForked {
super.setUp();

feeCollector = new FeeCollector(
INonfungiblePositionManager(0xC36442b4a4522E871399CD717aBDD847Ab11FE88),
ITokenDistributor(address(tokenDistributor)),
globalDaoWalletAddress,
IWETH(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2)
);

// Existing addresses on Sepolia
creator = new ERC20Creator(
creator = new ERC20CreatorV3(
ITokenDistributor(address(tokenDistributor)),
IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D),
IUniswapV2Factory(0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f),
0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2,
address(0),
0
INonfungiblePositionManager(0xC36442b4a4522E871399CD717aBDD847Ab11FE88),
IUniswapV3Factory(0x1F98431c8aD98523631AE4a59f267346ea31F984),
address(feeCollector),
0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, // WETH
globalDaoWalletAddress,
100, // 1% fee
10_000 // 1% pool
);
launchCrowdfundImpl = new ERC20LaunchCrowdfund(globals, IERC20Creator(address(creator)));
crowdfundFactory = new CrowdfundFactory();
Expand Down Expand Up @@ -58,7 +69,7 @@ contract ERC20LaunchCrowdfundForkedTest is SetupPartyHelper {
tokenOpts.name = "Test ERC20";
tokenOpts.symbol = "TEST";
tokenOpts.totalSupply = 1e6 ether;
tokenOpts.recipient = address(this);
tokenOpts.recipient = launchCrowdfundImpl.PARTY_ADDRESS_KEY();
tokenOpts.numTokensForDistribution = 5e4 ether;
tokenOpts.numTokensForRecipient = 5e4 ether;
tokenOpts.numTokensForLP = 9e5 ether;
Expand Down Expand Up @@ -105,7 +116,7 @@ contract ERC20LaunchCrowdfundForkedTest is SetupPartyHelper {
address(tokenDistributor).call(callData);

assertEq(IERC20(info.token).balanceOf(contributor), 5e4 ether);
assertEq(IERC20(info.token).balanceOf(address(this)), 5e4 ether);
assertEq(IERC20(info.token).balanceOf(address(launchCrowdfund.party())), 5e4 ether);
}

function test_ERC20LaunchCrowdfund_revertIfNumTokensNotAddUpToTotal() public onlyForked {
Expand Down

0 comments on commit 15eca6e

Please sign in to comment.