Skip to content

Commit

Permalink
Add registration period to Sale contract (#198)
Browse files Browse the repository at this point in the history
Why:
* Registration for the Sale needs to happen during a defined period of
  time

How:
* Adding `startRegistration` and `endRegistration` values to the Sale
  contract
  • Loading branch information
DavideSilva authored Apr 10, 2024
1 parent 03ee2f8 commit 56be62a
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 11 deletions.
20 changes: 19 additions & 1 deletion packages/contracts/contracts/token/Sale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ contract Sale is ISale, RisingTide, ERC165, AccessControl, ReentrancyGuard {
/// Timestamp at which sale ends
uint256 public immutable end;

/// Timestamp at which registration period starts
uint256 public immutable startRegistration;

/// Timestamp at which registration period ends
uint256 public immutable endRegistration;

/// Total tokens available for sale
uint256 public immutable totalTokensForSale;

Expand Down Expand Up @@ -103,14 +109,20 @@ contract Sale is ISale, RisingTide, ERC165, AccessControl, ReentrancyGuard {
/// @param _start Start timestamp
/// @param _end End timestamp
/// @param _totalTokensForSale Total amount of tokens for sale
/// @param _minTarget Minimum target for the sale
/// @param _maxTarget Maximum target for the sale
/// @param _startRegistration Registration period start timestamp
/// @param _endRegistration Registration period end timestamp
constructor(
address _paymentToken,
uint256 _rate,
uint256 _start,
uint256 _end,
uint256 _totalTokensForSale,
uint256 _minTarget,
uint256 _maxTarget
uint256 _maxTarget,
uint256 _startRegistration,
uint256 _endRegistration
) {
require(_rate > 0, "can't be zero");
require(_paymentToken != address(0), "can't be zero");
Expand All @@ -122,6 +134,10 @@ contract Sale is ISale, RisingTide, ERC165, AccessControl, ReentrancyGuard {
_maxTarget > _minTarget,
"_maxTarget cannot be lower than _minTarget"
);
require(
_endRegistration > _startRegistration,
"_endRegistration cannot be lower than _startRegistration"
);

paymentToken = _paymentToken;
rate = _rate;
Expand All @@ -130,6 +146,8 @@ contract Sale is ISale, RisingTide, ERC165, AccessControl, ReentrancyGuard {
totalTokensForSale = _totalTokensForSale;
minTarget = _minTarget;
maxTarget = _maxTarget;
startRegistration = _startRegistration;
endRegistration = _endRegistration;

_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(CAP_VALIDATOR_ROLE, msg.sender);
Expand Down
10 changes: 7 additions & 3 deletions packages/contracts/script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ contract DeployScript is Script {
function run() public {
vm.startBroadcast();

uint start = vm.unixTime();
uint end = start + 60 * 60 * 24 * 7;
uint256 start = vm.unixTime();
uint256 end = start + 60 * 60 * 24 * 7;
uint256 startRegistration = 1714089600;
uint256 endRegistration = 1714694400;

MockERC20 token = new MockERC20("USDC", "USDC", 18);
Sale sale = new Sale(
Expand All @@ -21,7 +23,9 @@ contract DeployScript is Script {
end,
1000,
1000000,
2000000
2000000,
startRegistration,
endRegistration
);

vm.stopBroadcast();
Expand Down
14 changes: 8 additions & 6 deletions packages/contracts/script/DevDeploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ contract DevDeployScript is Script {

uint256 start;
uint256 end;
uint256 startRegistration;
uint256 endRegistration;

function setUp() public {
testAccounts = new address[](3);
Expand All @@ -34,24 +36,24 @@ contract DevDeployScript is Script {

bytes32 merkleRoot = 0xa5c09e2a9128afef7246a5900cfe02c4bd2cfcac8ac4286f0159a699c8455a49;

// Citizend citizend = new Citizend(owner);
// Staking staking = new Staking(address(citizend));
//
// Controller controller = new Controller(address(staking), address(citizend), merkleRoot);
// Project project = new Project("token sale project", address(citizend), 1000, 1, address(0), merkleRoot);
startRegistration = 1714089600;
endRegistration = 1714694400;

start = vm.getBlockTimestamp();
end = start + 60 * 60 * 24;

MockERC20 token = new MockERC20("USDC", "USDC", 18);
Citizend citizend = new Citizend(owner);
Sale sale = new Sale(
address(token),
1 ** 18,
start,
end,
1000,
1000000,
2000000
2000000,
startRegistration,
endRegistration
);

bool success = token.approve(address(sale), 1000 ether);
Expand Down
9 changes: 8 additions & 1 deletion packages/contracts/test/contracts/token/Sale.d.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ contract SaleTest is Test {
MockERC20 paymentToken;
uint256 start;
uint256 end;
uint256 startRegistration;
uint256 endRegistration;

address owner = 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266;
address alice = 0x70997970C51812dc3A010C7d01b50e0d17dc79C8;
Expand All @@ -24,6 +26,9 @@ contract SaleTest is Test {
function setUp() public {
vm.startPrank(owner);

startRegistration = 1714089600;
endRegistration = 1714694400;

start = vm.getBlockTimestamp();
end = start + 60 * 60 * 24;

Expand All @@ -35,7 +40,9 @@ contract SaleTest is Test {
end,
100,
1000000,
2000000
2000000,
startRegistration,
endRegistration
);

sale.setMaxContribution(4 ether);
Expand Down
29 changes: 29 additions & 0 deletions packages/web-app/wagmi.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5928,6 +5928,13 @@ export const saleAbi = [
outputs: [{ name: '', internalType: 'uint256', type: 'uint256' }],
stateMutability: 'view',
},
{
type: 'function',
inputs: [],
name: 'endRegistration',
outputs: [{ name: '', internalType: 'uint256', type: 'uint256' }],
stateMutability: 'view',
},
{
type: 'function',
inputs: [{ name: 'role', internalType: 'bytes32', type: 'bytes32' }],
Expand Down Expand Up @@ -6160,6 +6167,13 @@ export const saleAbi = [
outputs: [{ name: '', internalType: 'uint256', type: 'uint256' }],
stateMutability: 'view',
},
{
type: 'function',
inputs: [],
name: 'startRegistration',
outputs: [{ name: '', internalType: 'uint256', type: 'uint256' }],
stateMutability: 'view',
},
{
type: 'function',
inputs: [{ name: 'interfaceId', internalType: 'bytes4', type: 'bytes4' }],
Expand Down Expand Up @@ -19769,6 +19783,14 @@ export const useReadSaleEnd = /*#__PURE__*/ createUseReadContract({
functionName: 'end',
})

/**
* Wraps __{@link useReadContract}__ with `abi` set to __{@link saleAbi}__ and `functionName` set to `"endRegistration"`
*/
export const useReadSaleEndRegistration = /*#__PURE__*/ createUseReadContract({
abi: saleAbi,
functionName: 'endRegistration',
})

/**
* Wraps __{@link useReadContract}__ with `abi` set to __{@link saleAbi}__ and `functionName` set to `"getRoleAdmin"`
*/
Expand Down Expand Up @@ -19943,6 +19965,13 @@ export const useReadSaleStart = /*#__PURE__*/ createUseReadContract({
functionName: 'start',
})

/**
* Wraps __{@link useReadContract}__ with `abi` set to __{@link saleAbi}__ and `functionName` set to `"startRegistration"`
*/
export const useReadSaleStartRegistration = /*#__PURE__*/ createUseReadContract(
{ abi: saleAbi, functionName: 'startRegistration' },
)

/**
* Wraps __{@link useReadContract}__ with `abi` set to __{@link saleAbi}__ and `functionName` set to `"supportsInterface"`
*/
Expand Down

0 comments on commit 56be62a

Please sign in to comment.