Skip to content

Commit

Permalink
Feat: settable-fee-recipient-crowdfund (#393)
Browse files Browse the repository at this point in the history
  • Loading branch information
arr00 authored Apr 26, 2024
1 parent d96338e commit a9465ed
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
10 changes: 9 additions & 1 deletion contracts/crowdfund/ERC20LaunchCrowdfund.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ contract ERC20LaunchCrowdfund is InitialETHCrowdfund {
uint256 numTokensForDistribution;
// The number of tokens to send to an arbitrary recipient.
uint256 numTokensForRecipient;
// The number of tokens to use for the Uniswap LP pair.
// The number of tokens to use for the Uniswap LP position.
uint256 numTokensForLP;
// The address that receives fees from the Uniswap LP position.
address lpFeeRecipient;
}

error InvalidTokenDistribution();
Expand Down Expand Up @@ -110,10 +112,16 @@ contract ERC20LaunchCrowdfund is InitialETHCrowdfund {
tokenRecipient = address(party);
}

address lpFeeRecipient = tokenOpts.lpFeeRecipient;
if (lpFeeRecipient == PARTY_ADDRESS_KEY) {
lpFeeRecipient = address(party);
}

// Create the ERC20 token.
ERC20LaunchOptions memory _tokenOpts = tokenOpts;
token = ERC20_CREATOR.createToken{ value: totalContributions_ }(
address(party),
lpFeeRecipient,
_tokenOpts.name,
_tokenOpts.symbol,
TokenConfiguration({
Expand Down
11 changes: 6 additions & 5 deletions contracts/utils/IERC20Creator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ struct TokenConfiguration {

interface IERC20Creator {
function createToken(
address partyAddress,
string calldata name,
string calldata symbol,
TokenConfiguration calldata config,
address recipientAddress
address party,
address lpFeeRecipient,
string memory name,
string memory symbol,
TokenConfiguration memory config,
address tokenRecipientAddress
) external payable returns (ERC20 token);
}
14 changes: 12 additions & 2 deletions test/crowdfund/ERC20LaunchCrowdfundForked.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ contract ERC20LaunchCrowdfundForkedTest is SetupPartyHelper {

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

Expand Down Expand Up @@ -73,6 +73,7 @@ contract ERC20LaunchCrowdfundForkedTest is SetupPartyHelper {
tokenOpts.numTokensForDistribution = 5e4 ether;
tokenOpts.numTokensForRecipient = 5e4 ether;
tokenOpts.numTokensForLP = 9e5 ether;
tokenOpts.lpFeeRecipient = launchCrowdfundImpl.PARTY_ADDRESS_KEY();

ERC20LaunchCrowdfund launchCrowdfund = crowdfundFactory.createERC20LaunchCrowdfund(
launchCrowdfundImpl,
Expand Down Expand Up @@ -116,7 +117,11 @@ contract ERC20LaunchCrowdfundForkedTest is SetupPartyHelper {
address(tokenDistributor).call(callData);

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

function test_ERC20LaunchCrowdfund_revertIfNumTokensNotAddUpToTotal() public onlyForked {
Expand Down Expand Up @@ -150,6 +155,7 @@ contract ERC20LaunchCrowdfundForkedTest is SetupPartyHelper {
tokenOpts.numTokensForDistribution = 5e4 ether + 1; // Add 1 to make it invalid
tokenOpts.numTokensForRecipient = 5e4 ether;
tokenOpts.numTokensForLP = 9e5 ether;
tokenOpts.lpFeeRecipient = launchCrowdfundImpl.PARTY_ADDRESS_KEY();

vm.expectRevert(ERC20LaunchCrowdfund.InvalidTokenDistribution.selector);
ERC20LaunchCrowdfund launchCrowdfund = crowdfundFactory.createERC20LaunchCrowdfund(
Expand Down Expand Up @@ -192,6 +198,7 @@ contract ERC20LaunchCrowdfundForkedTest is SetupPartyHelper {
tokenOpts.numTokensForDistribution = 5e4 ether;
tokenOpts.numTokensForRecipient = 5e4 ether;
tokenOpts.numTokensForLP = 1e4 - 1; // Too low
tokenOpts.lpFeeRecipient = launchCrowdfundImpl.PARTY_ADDRESS_KEY();

vm.expectRevert(ERC20LaunchCrowdfund.InvalidTokenDistribution.selector);
ERC20LaunchCrowdfund launchCrowdfund = crowdfundFactory.createERC20LaunchCrowdfund(
Expand Down Expand Up @@ -234,6 +241,7 @@ contract ERC20LaunchCrowdfundForkedTest is SetupPartyHelper {
tokenOpts.numTokensForDistribution = 5e4 ether;
tokenOpts.numTokensForRecipient = 5e4 ether;
tokenOpts.numTokensForLP = 9e5 ether;
tokenOpts.lpFeeRecipient = launchCrowdfundImpl.PARTY_ADDRESS_KEY();

vm.expectRevert(ERC20LaunchCrowdfund.InvalidTokenDistribution.selector);
ERC20LaunchCrowdfund launchCrowdfund = crowdfundFactory.createERC20LaunchCrowdfund(
Expand Down Expand Up @@ -276,6 +284,7 @@ contract ERC20LaunchCrowdfundForkedTest is SetupPartyHelper {
tokenOpts.numTokensForDistribution = 5e4 ether;
tokenOpts.numTokensForRecipient = 5e4 ether;
tokenOpts.numTokensForLP = 9e5 ether;
tokenOpts.lpFeeRecipient = launchCrowdfundImpl.PARTY_ADDRESS_KEY();

ERC20LaunchCrowdfund launchCrowdfund = crowdfundFactory.createERC20LaunchCrowdfund(
launchCrowdfundImpl,
Expand Down Expand Up @@ -364,6 +373,7 @@ contract ERC20LaunchCrowdfundForkedTest is SetupPartyHelper {
tokenOpts.numTokensForDistribution = 5e4 ether;
tokenOpts.numTokensForRecipient = 5e4 ether;
tokenOpts.numTokensForLP = 9e5 ether;
tokenOpts.lpFeeRecipient = launchCrowdfundImpl.PARTY_ADDRESS_KEY();

ERC20LaunchCrowdfund launchCrowdfund = crowdfundFactory.createERC20LaunchCrowdfund(
launchCrowdfundImpl,
Expand Down

0 comments on commit a9465ed

Please sign in to comment.