Skip to content

Commit

Permalink
mitigate L-6
Browse files Browse the repository at this point in the history
  • Loading branch information
0xble authored and arr00 committed Mar 25, 2024
1 parent 11abcfe commit 3d38b55
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
55 changes: 41 additions & 14 deletions contracts/crowdfund/ERC20LaunchCrowdfund.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ contract ERC20LaunchCrowdfund is InitialETHCrowdfund {
}

error InvalidTokenDistribution();
error TokenAlreadyLaunched();

IERC20Creator public immutable ERC20_CREATOR;

ERC20LaunchOptions public tokenOpts;

bool isTokenLaunched;

constructor(IGlobals globals, IERC20Creator erc20Creator) InitialETHCrowdfund(globals) {
ERC20_CREATOR = erc20Creator;
}
Expand Down Expand Up @@ -74,30 +77,28 @@ contract ERC20LaunchCrowdfund is InitialETHCrowdfund {
);
}

function _finalize(uint96 totalContributions_) internal override {
Party _party = party;
/// @notice Launch the ERC20 token for the Party.
function launchToken() public {
if (isTokenLaunched) revert TokenAlreadyLaunched();

// Finalize the crowdfund.
delete expiry;
CrowdfundLifecycle lc = getCrowdfundLifecycle();
if (lc != CrowdfundLifecycle.Finalized) revert WrongLifecycleError(lc);

isTokenLaunched = true;

// Update the party's total voting power
uint96 totalContributions_ = totalContributions;

// Transfer funding split to recipient if applicable.
uint16 fundingSplitBps_ = fundingSplitBps;
if (fundingSplitBps_ > 0) {
// Assuming fundingSplitBps_ <= 1e4, this cannot overflow uint96
totalContributions_ -= uint96((uint256(totalContributions_) * fundingSplitBps_) / 1e4);
}

// Update the party's total voting power.
uint96 newVotingPower = _calculateContributionToVotingPower(totalContributions_);
_party.increaseTotalVotingPower(newVotingPower);

emit Finalized();

ERC20LaunchOptions memory _tokenOpts = tokenOpts;

// Create the ERC20 token.
ERC20LaunchOptions memory _tokenOpts = tokenOpts;
ERC20_CREATOR.createToken{ value: totalContributions_ }(
address(_party),
address(party),
_tokenOpts.name,
_tokenOpts.symbol,
TokenConfiguration({
Expand All @@ -109,4 +110,30 @@ contract ERC20LaunchCrowdfund is InitialETHCrowdfund {
_tokenOpts.recipient
);
}

/// @notice Finalize the crowdfund and launch the ERC20 token.
function finalize() public override {
super.finalize();
launchToken();
}

function _finalize(uint96 totalContributions_) internal override {
Party _party = party;

// Finalize the crowdfund.
delete expiry;

// Transfer funding split to recipient if applicable.
uint16 fundingSplitBps_ = fundingSplitBps;
if (fundingSplitBps_ > 0) {
// Assuming fundingSplitBps_ <= 1e4, this cannot overflow uint96
totalContributions_ -= uint96((uint256(totalContributions_) * fundingSplitBps_) / 1e4);
}

// Update the party's total voting power.
uint96 newVotingPower = _calculateContributionToVotingPower(totalContributions_);
_party.increaseTotalVotingPower(newVotingPower);

emit Finalized();
}
}
3 changes: 2 additions & 1 deletion contracts/crowdfund/ETHCrowdfundBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ abstract contract ETHCrowdfundBase is Implementation {
return contribution;
}

function finalize() external {
/// @notice Finalize the crowdfund and transfer the funds to the Party.
function finalize() public virtual {
uint96 totalContributions_ = totalContributions;

// Check that the crowdfund is not already finalized.
Expand Down

0 comments on commit 3d38b55

Please sign in to comment.