Skip to content

Prateek | Register for OpenGuild Sub0 Challenges #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions challenge-1-vesting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Add your information to the below list to officially participate in the workshop
| Emoji | Name | Github Username | Occupations |
| ----- | ---- | ------------------------------------- | ----------- |
| 🎅 | Ippo | [NTP-996](https://github.com/NTP-996) | DevRel |
| 🎅 | Prateek | [PrateekKSingh](https://github.com/PrateekKSingh) | Director |

## 💻 Local development environment setup

Expand Down
36 changes: 34 additions & 2 deletions challenge-1-vesting/contracts/TokenVesting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,27 @@ import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
contract TokenVesting is Ownable(msg.sender), Pausable, ReentrancyGuard {
struct VestingSchedule {
// TODO: Define the vesting schedule struct
uint256 totAmtOfTokens;
uint256 startTime;
uint256 cliffDuration;
uint256 vestingDuration;
uint256 amtClaimed;
bool revokedStatus;
}

VestingSchedule[] private listOfVestingSchedule;

// Token being vested
// TODO: Add state variables

IERC20 public tokenVested;

// Mapping from beneficiary to vesting schedule
// TODO: Add state variables
mapping(address => VestingSchedule) public beneficaryAddressVestingScheduleMap;

// Whitelist of beneficiaries
// TODO: Add state variables
mapping(address => bool) public whitelist;

// Events
event VestingScheduleCreated(address indexed beneficiary, uint256 amount);
Expand All @@ -52,7 +62,7 @@ contract TokenVesting is Ownable(msg.sender), Pausable, ReentrancyGuard {

constructor(address tokenAddress) {
// TODO: Initialize the contract

tokenVested = IERC20(tokenAddress);
}

// Modifier to check if beneficiary is whitelisted
Expand Down Expand Up @@ -80,6 +90,28 @@ contract TokenVesting is Ownable(msg.sender), Pausable, ReentrancyGuard {
uint256 startTime
) external onlyOwner onlyWhitelisted(beneficiary) whenNotPaused {
// TODO: Implement vesting schedule creation

//Input parameters validation
//As the function definition is already doing a check for only whitelisted beneficiary, beneficiary address valiation
//is not being performed seperately
//Check on token amount to be greater than zero
require(amount > 0, "Token vesting amount cannot be zero");
//check if cliff duration is more than or equal to vesting duration
require(cliffDuration < vestingDuration, "Cliff Duration cannot be more than or equal to vesting duration");
//check if startTime is less than current block time
require(startTime > block.timestamp, "Start time should be greater than block timestamp");


//Creating new vesting schedule within function and then adding it to mapping of beneficiary and vesting schedule.
//There is no need for vesting schedule variable to be defined outside of function
listOfVestingSchedule.push(VestingSchedule({totAmtOfTokens: amount, startTime: startTime, cliffDuration: cliffDuration, vestingDuration: vestingDuration, amtClaimed: 0, revokedStatus: false}));
beneficaryAddressVestingScheduleMap[beneficiary] = VestingSchedule({totAmtOfTokens: amount, startTime: startTime, cliffDuration: cliffDuration, vestingDuration: vestingDuration, amtClaimed: 0, revokedStatus: false});

//emit event of vesting schedule creation
emit VestingScheduleCreated(beneficiary, amount);

//Transfer tokens to contract
tokenVested.transfer(msg.sender, amount);
}

function calculateVestedAmount(
Expand Down