Skip to content

Commit

Permalink
update the crowdsale to accept fees and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nour-karoui committed Oct 17, 2023
1 parent f559e69 commit f244b4c
Show file tree
Hide file tree
Showing 20 changed files with 279 additions and 316 deletions.
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ TERMS_ACCEPTED_PERMISSIONER_ADDRESS=0x610178dA211FEF7D417bC0e6FeD39F05609AD788

TOKENIZER_ADDRESS=0xA51c1fc2f0D1a1b8494Ed1FE312d7C3a78Ed91C0
STAKED_LOCKING_CROWDSALE_ADDRESS=0x9A676e781A523b5d0C0e43731313A708CB607508
CROWDSALE_WITH_FEES_ADDRESS=0x4A679253410272dd5232B3Ff7cF5dbB88f295319
CROWDSALE_WITH_FEES_ADDRESS=0x0B306BF915C4d645ff596e518fAf3F9669b97016

USDC6_ADDRESS=0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE
WETH_ADDRESS=0x59b670e9fA9D0A427751Af201D676719a970857b
USDC6_ADDRESS=0x68B1D87F95878fE05B998F19b66F4baba5De1aed
WETH_ADDRESS=0x4ed7c70F96B99c776995fB64377f0d4aB3B0e1C1

#these are generated when running the fixture scripts
IPTS_ADDRESS=0x1F708C24a0D3A740cD47cC0444E9480899f3dA7D
Expand Down
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test = 'test'
cache_path = 'cache_forge'
solc_version = "0.8.18"
gas_reports = ["IPNFT", "IPNFTV2", "SchmackoSwap", "Tokenizer", "IPToken", "CrowdSale", "LockingCrowdSale", "StakedLockingCrowdSale", "TimelockedToken", "TermsAcceptedPermissioner", "SignedMintAuthorizer"]
fs_permissions = [{ access = "read-write", path = "./SALEID.txt"}]
fs_permissions = [{ access = "read-write", path = "./SALEID.txt"}, { access = "read-write", path = "./SALEWITHFEESID.txt"}]

[fmt]
bracket_spacing = true
Expand Down
2 changes: 1 addition & 1 deletion script/DeployTokenizer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contract DeployTokenizerInfrastructure is Script {
);
tokenizer.initialize(IPNFT(ipnftAddress), p);

StakedLockingCrowdSale stakedLockingCrowdSale = new StakedLockingCrowdSale();
StakedLockingCrowdSale stakedLockingCrowdSale = new StakedLockingCrowdSale(0);

vm.stopBroadcast();

Expand Down
38 changes: 37 additions & 1 deletion script/dev/CrowdSale.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ contract DeployCrowdSale is CommonScript {
function run() public {
prepareAddresses();
vm.startBroadcast(deployer);
StakedLockingCrowdSale stakedLockingCrowdSale = new StakedLockingCrowdSale();
StakedLockingCrowdSale stakedLockingCrowdSale = new StakedLockingCrowdSale(0);
CrowdSale crowdSaleWithFees = new CrowdSale(10);
TokenVesting vestedDaoToken = TokenVesting(vm.envAddress("VDAO_TOKEN_ADDRESS"));
vestedDaoToken.grantRole(vestedDaoToken.ROLE_CREATE_SCHEDULE(), address(stakedLockingCrowdSale));
stakedLockingCrowdSale.trustVestingContract(vestedDaoToken);
vm.stopBroadcast();

//console.log("vested molecules Token %s", address(vestedMolToken));
console.log("STAKED_LOCKING_CROWDSALE_ADDRESS=%s", address(stakedLockingCrowdSale));
console.log("CROWDSALE_WITH_FEES=%s", address(crowdSaleWithFees));
}
}

Expand All @@ -52,6 +54,7 @@ contract FixtureCrowdSale is CommonScript {
IPToken internal auctionToken;

StakedLockingCrowdSale stakedLockingCrowdSale;
CrowdSale crowdSaleWithFees;
TermsAcceptedPermissioner permissioner;

function prepareAddresses() internal override {
Expand All @@ -64,6 +67,7 @@ contract FixtureCrowdSale is CommonScript {
auctionToken = IPToken(vm.envAddress("IPTS_ADDRESS"));

stakedLockingCrowdSale = StakedLockingCrowdSale(vm.envAddress("STAKED_LOCKING_CROWDSALE_ADDRESS"));
crowdSaleWithFees = CrowdSale(vm.envAddress("CROWDSALE_WITH_FEES_ADDRESS"));
permissioner = TermsAcceptedPermissioner(vm.envAddress("TERMS_ACCEPTED_PERMISSIONER_ADDRESS"));
}

Expand All @@ -83,6 +87,14 @@ contract FixtureCrowdSale is CommonScript {
vm.stopBroadcast();
}

function placeBidCrowdSaleWithFees(address bidder, uint256 amount, uint256 saleId, bytes memory permission) internal {
vm.startBroadcast(bidder);
usdc.approve(address(crowdSaleWithFees), amount);
daoToken.approve(address(crowdSaleWithFees), amount);
crowdSaleWithFees.placeBid(saleId, amount, permission);
vm.stopBroadcast();
}

function run() public virtual {
prepareAddresses();

Expand All @@ -109,6 +121,8 @@ contract FixtureCrowdSale is CommonScript {
vm.startBroadcast(bob);

auctionToken.approve(address(stakedLockingCrowdSale), 400 ether);
auctionToken.approve(address(crowdSaleWithFees), 400 ether);
uint256 saleWithFeesId = crowdSaleWithFees.startSale(_sale);
uint256 saleId = stakedLockingCrowdSale.startSale(_sale, daoToken, vestedDaoToken, 1e18, 7 days);
TimelockedToken lockedIpt = stakedLockingCrowdSale.lockingContracts(address(auctionToken));
vm.stopBroadcast();
Expand All @@ -117,10 +131,13 @@ contract FixtureCrowdSale is CommonScript {

(uint8 v, bytes32 r, bytes32 s) = vm.sign(alicePk, ECDSA.toEthSignedMessageHash(abi.encodePacked(terms)));
placeBid(alice, 600 ether, saleId, abi.encodePacked(r, s, v));
placeBidCrowdSaleWithFees(alice, 600 ether, saleWithFeesId, abi.encodePacked(r, s, v));
(v, r, s) = vm.sign(charliePk, ECDSA.toEthSignedMessageHash(abi.encodePacked(terms)));
placeBid(charlie, 200 ether, saleId, abi.encodePacked(r, s, v));
console.log("LOCKED_IPTS_ADDRESS=%s", address(lockedIpt));
console.log("SALE_ID=%s", saleId);
console.log("SALE_ID_WITH_FEES=%s", saleWithFeesId);
vm.writeFile("SALEWITHFEESID.txt", Strings.toString(saleWithFeesId));
vm.writeFile("SALEID.txt", Strings.toString(saleId));
}
}
Expand All @@ -130,13 +147,18 @@ contract ClaimSale is CommonScript {
prepareAddresses();
TermsAcceptedPermissioner permissioner = TermsAcceptedPermissioner(vm.envAddress("TERMS_ACCEPTED_PERMISSIONER_ADDRESS"));
StakedLockingCrowdSale stakedLockingCrowdSale = StakedLockingCrowdSale(vm.envAddress("STAKED_LOCKING_CROWDSALE_ADDRESS"));
CrowdSale crowdSaleWithFees = CrowdSale(vm.envAddress("CROWDSALE_WITH_FEES_ADDRESS"));
IPToken auctionToken = IPToken(vm.envAddress("IPTS_ADDRESS"));
uint256 saleId = SLib.stringToUint(vm.readFile("SALEID.txt"));
uint256 saleWithFeesId = SLib.stringToUint(vm.readFile("SALEWITHFEESID.txt"));
vm.removeFile("SALEID.txt");
vm.removeFile("SALEWITHFEESID.txt");

vm.startBroadcast(anyone);
stakedLockingCrowdSale.settle(saleId);
crowdSaleWithFees.settle(saleWithFeesId);
stakedLockingCrowdSale.claimResults(saleId);
crowdSaleWithFees.claimResults(saleWithFeesId);
vm.stopBroadcast();

string memory terms = permissioner.specificTermsV1(auctionToken);
Expand All @@ -153,3 +175,17 @@ contract ClaimSale is CommonScript {
// vm.stopBroadcast();
}
}

contract ClaimSaleWithFees is CommonScript {
function run() public {
prepareAddresses();
CrowdSale crowdSaleWithFees = CrowdSale(vm.envAddress("CROWDSALE_WITH_FEES_ADDRESS"));
uint256 saleId = SLib.stringToUint(vm.readFile("SALEID.txt"));
vm.removeFile("SALEID.txt");

vm.startBroadcast(anyone);
crowdSaleWithFees.settle(saleId);
crowdSaleWithFees.claimResults(saleId);
vm.stopBroadcast();
}
}
121 changes: 0 additions & 121 deletions script/dev/CrowdSaleWithFees.s.sol

This file was deleted.

2 changes: 1 addition & 1 deletion script/prod/RolloutV23Sale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract RolloutV23Sale is Script {
address moleculeDevMultisig = 0xCfA0F84660fB33bFd07C369E5491Ab02C449f71B;
vm.startBroadcast();

StakedLockingCrowdSale stakedLockingCrowdSale = new StakedLockingCrowdSale();
StakedLockingCrowdSale stakedLockingCrowdSale = new StakedLockingCrowdSale(0);
stakedLockingCrowdSale.transferOwnership(moleculeDevMultisig);
vm.stopBroadcast();

Expand Down
7 changes: 2 additions & 5 deletions setupLocal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,18 @@ $FSC script/dev/Periphery.s.sol
$FSC script/dev/Tokenizer.s.sol:DeployTokenizer
$FSC script/dev/CrowdSale.s.sol:DeployCrowdSale
$FSC script/dev/Tokens.s.sol:DeployFakeTokens
$FSC script/dev/CrowdSaleWithFees.s.sol:DeployCrowdSale

# optionally: fixtures
if [ "$fixture" -eq "1" ]; then
echo "Running fixture scripts."

$FSC script/dev/Ipnft.s.sol:FixtureIpnft
$FSC script/dev/Tokenizer.s.sol:FixtureTokenizer
# $FSC script/dev/CrowdSale.s.sol:FixtureCrowdSale
$FSC script/dev/CrowdSaleWithFees.s.sol:FixtureCrowdSale
$FSC script/dev/CrowdSale.s.sol:FixtureCrowdSale

echo "Waiting 15 seconds until claiming sale..."
sleep 16
cast rpc evm_mine

# $FSC script/dev/CrowdSale.s.sol:ClaimSale
$FSC script/dev/CrowdSaleWithFees.s.sol:ClaimSale
$FSC script/dev/CrowdSale.s.sol:ClaimSale
fi
Loading

0 comments on commit f244b4c

Please sign in to comment.