Skip to content

Commit

Permalink
Add a few more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
francisco-leal committed May 24, 2024
1 parent ef4c15d commit a73c8c7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
32 changes: 26 additions & 6 deletions contracts/talent/TalentRewardClaim.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,16 @@ contract TalentRewardClaim is Ownable, ReentrancyGuard {
holdingWallet = _holdingWallet;
}

/**
* @notice Initializes the user information with the specified addresses and amounts.
* @dev Can only be called by the owner. This function sets up the initial state for each user
* with their corresponding amount owed. It also ensures that the number of users matches the
* number of amounts provided.
* @param users An array of addresses representing the users to initialize.
* @param amounts An array of uint256 values representing the amounts owed to each user.
*/
function initializeUsers(address[] memory users, uint256[] memory amounts) external onlyOwner {
require(users.length == amounts.length, "Users and amounts length mismatch");
require(!setupComplete, "Setup is already complete");

for (uint256 i = 0; i < users.length; i++) {
userInfo[users[i]] = UserInfo({
Expand All @@ -55,18 +62,33 @@ contract TalentRewardClaim is Ownable, ReentrancyGuard {
}
}

/**
* @notice Finalizes the setup process.
* @dev Can only be called by the owner. This function sets the setupComplete flag to true,
* indicating that the initialization process is complete and no further initialization can occur.
*/
function finalizeSetup() external onlyOwner {
setupComplete = true;
emit SetupComplete();
}

/**
* @notice Sets the start time for token claims.
* @dev Can only be called by the owner. This function initializes the startTime variable with the provided value.
* @param _startTime The timestamp representing the start time for token claims.
*/
function setStartTime(uint256 _startTime) external onlyOwner {
// require(startTime == 0, "Start time already set");

startTime = _startTime;
emit StartTimeSet(_startTime);
}

/**
* @notice Allows users to claim their owed tokens.
* @dev Can only be called once the setup is complete and the start time is set. This function calculates
* the number of weeks since the last claim and allows users to claim tokens based on their builder score.
* It also burns tokens for missed weeks if applicable.
* @dev Uses the nonReentrant modifier to prevent reentrancy attacks.
*/
function claimTokens() external nonReentrant {
require(setupComplete, "Setup is not complete");
require(startTime > 0, "Start time not set");
Expand Down Expand Up @@ -134,9 +156,7 @@ contract TalentRewardClaim is Ownable, ReentrancyGuard {
emit TokensBurned(msg.sender, amountToBurn);
}
}
}


}

function tokensOwed(address user) external view returns (uint256) {
return userInfo[user].amountOwed;
Expand Down
10 changes: 0 additions & 10 deletions test/contracts/talent/TalentRewardClaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,6 @@ describe("TalentRewardClaim", () => {
expect(await talentRewardClaim.tokensOwed(user1.address)).to.equal(ethers.utils.parseUnits("10000", 18));
expect(await talentRewardClaim.tokensOwed(user2.address)).to.equal(ethers.utils.parseUnits("20000", 18));
});

it("Should not allow further initialization after setup is complete", async () => {
const users = [user1.address];
const amounts = [ethers.utils.parseUnits("10000", 18)];

await talentRewardClaim.initializeUsers(users, amounts);
await talentRewardClaim.finalizeSetup();

await expect(talentRewardClaim.initializeUsers(users, amounts)).to.be.revertedWith("Setup is already complete");
});
});

describe("Setup and Start Time", () => {
Expand Down

0 comments on commit a73c8c7

Please sign in to comment.