Skip to content

Commit

Permalink
Added Solidity docs for withdraw/withdrawableAmount/unlockedAmount
Browse files Browse the repository at this point in the history
  • Loading branch information
pdyraga committed Jul 30, 2021
1 parent 66a8d88 commit 7456c67
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions contracts/grant/TokenGrant.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,21 @@ import "../token/T.sol";

import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

/// @title Token Grant
/// @notice Token Grant releases its token balance gradually to the grantee
/// based on the vesting schedule with a cliff and vesting period.
/// Can be revoked by grant creator. Allows to stake granted tokens
/// according to the provided staking policy.
contract TokenGrant {
// TODO Not implemented yet:
// TODO - TokenGrantFactory, master clone factory TokenGrant contract
// TODO initialization prevention.
// TODO - Staking, including checking the policy, allowed staking
// TODO contracts, and calling the staking contract.
// TODO - Grant revoke functionality.
// TODO - VendingMachine integration and functions allowing to convert
// TODO granted KEEP/NU into T and back

using SafeERC20 for T;

T public token;
Expand Down Expand Up @@ -59,6 +73,8 @@ contract TokenGrant {
// TODO: implement
}

/// @notice Witthdraws all the amount that is currently withdrawable. Can
/// be called only by the grantee.
function withdraw() external onlyGrantee {
uint256 withdrawable = withdrawableAmount();
require(withdrawable > 0, "There is nothing to withdraw");
Expand All @@ -68,6 +84,9 @@ contract TokenGrant {
token.safeTransfer(grantee, withdrawable);
}

/// @notice Calculates the amount unlocked so far. Includes the amount
/// staked and withdrawn. Returns 0 if the vesting schedule has not
/// started yet or if the cliff has not yet ended.
function unlockedAmount() public view returns (uint256) {
/* solhint-disable-next-line not-rely-on-time */
if (block.timestamp < start) {
Expand All @@ -90,6 +109,9 @@ contract TokenGrant {
return (amount * timeElapsed) / duration;
}

/// @notice Calculates the currently withdrawable amount. The amount
/// withdrawable is the amount vested minus the amount staked and
/// minus the amount already withdrawn.
function withdrawableAmount() public view returns (uint256) {
uint256 unlocked = unlockedAmount();

Expand Down

0 comments on commit 7456c67

Please sign in to comment.