Skip to content

Commit

Permalink
style: add missing natspec (#6)
Browse files Browse the repository at this point in the history
Apply natspec-smells and fix missing natspec

---------

Co-authored-by: Gas <[email protected]>
  • Loading branch information
dristpunk and gas1cent authored Feb 20, 2024
1 parent e6ae145 commit 50d4040
Show file tree
Hide file tree
Showing 6 changed files with 714 additions and 31 deletions.
11 changes: 11 additions & 0 deletions natspec-smells.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* List of supported options: https://github.com/defi-wonderland/natspec-smells?tab=readme-ov-file#options
*/

/** @type {import('@defi-wonderland/natspec-smells').Config} */
module.exports = {
include: 'solidity',
exclude: ['solidity/(test|scripts)/**/*.sol'],
constructorNatspec: true,
enforceInheritdoc: false,
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"devDependencies": {
"@commitlint/cli": "17.0.3",
"@commitlint/config-conventional": "17.0.3",
"@defi-wonderland/natspec-smells": "1.0.2",
"dotenv-cli": "7.2.1",
"ds-test": "github:dapphub/ds-test#e282159",
"forge-std": "github:foundry-rs/forge-std#v1.7.4",
Expand Down
114 changes: 90 additions & 24 deletions solidity/contracts/ConnextVestingWallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,59 +17,119 @@ import {IVestingEscrowSimple} from 'interfaces/IVestingEscrowSimple.sol';
* https://forum.connext.network/t/rfc-partnership-token-agreements/938
*/
contract ConnextVestingWallet is VestingWalletWithCliff, Ownable2Step {
/*///////////////////////////////////////////////////////////////
CONSTANTS
//////////////////////////////////////////////////////////////*/

/**
* --- Constants ---
* @notice 1 year in seconds
*/
uint64 public constant ONE_YEAR = 365 days;

/**
* @notice 1 month in seconds (on average)
*/
uint64 public constant ONE_MONTH = ONE_YEAR / 12;

/**
* @notice Sept 5th 2023 in seconds
*/
uint64 public constant SEPT_05_2023 = 1_693_872_000;

/**
* @notice Token launch date
* @dev Equals to Sept 5th 2023
*/
uint64 public constant NEXT_TOKEN_LAUNCH = SEPT_05_2023;
address public constant NEXT_TOKEN = 0xFE67A4450907459c3e1FFf623aA927dD4e28c67a; // Mainnet NEXT token

/**
* @notice NEXT token address
* @dev Mainnet address
*/
address public constant NEXT_TOKEN = 0xFE67A4450907459c3e1FFf623aA927dD4e28c67a;

/**
* NOTE: The equivalent vesting schedule has a 13 months duration, with a 1 month cliff,
* offsetted to start from `Sept 5th 2024 - 1 month`: At Sept 5th 2024 the cliff
* is triggered unlocking 1/13 of the tokens, and then 1/13 of the tokens will
* be linearly unlocked every month after that.
*/
uint64 public constant VESTING_DURATION = ONE_YEAR + ONE_MONTH; // 13 months duration
uint64 public constant VESTING_CLIFF_DURATION = ONE_MONTH; // 1 month cliff
uint64 public constant VESTING_OFFSET = ONE_YEAR - ONE_MONTH; // 11 months offset
uint64 public constant VESTING_START_DATE = NEXT_TOKEN_LAUNCH + VESTING_OFFSET; // Sept 5th 2024 - 1 month

/**
* --- Settable Storage ---
* @notice Vesting duration including one month of cliff
* @dev 13 months duration
*/
uint64 public constant VESTING_DURATION = ONE_YEAR + ONE_MONTH;

/**
* @notice Vesting cliff duration
* @dev 1 month cliff
*/
uint64 public constant VESTING_CLIFF_DURATION = ONE_MONTH;

/**
* @notice Vesting warmup time
* @dev 11 months offset
*/
uint64 public constant VESTING_OFFSET = ONE_YEAR - ONE_MONTH;

/**
* @notice Vesting start date
* @dev Sept 5th 2024 - 1 month
*/
uint64 public constant VESTING_START_DATE = NEXT_TOKEN_LAUNCH + VESTING_OFFSET;

/*///////////////////////////////////////////////////////////////
STORAGE
//////////////////////////////////////////////////////////////*/

/**
* @notice Total amount of tokens to be vested
* @dev Set into constructor
*/
uint256 public immutable TOTAL_AMOUNT;

/**
* @dev Init VestingWalletWithCliff and save total amout of tokens to be unlocked
* @param _beneficiary The address of the beneficiary
* @param _totalAmount The total amount of tokens to be unlocked
*/
constructor(
address _beneficiary,
uint256 _totalAmount
) VestingWalletWithCliff(_beneficiary, VESTING_START_DATE, VESTING_DURATION, VESTING_CLIFF_DURATION) {
TOTAL_AMOUNT = _totalAmount;
}

/*///////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/

/**
* --- Errors ---
* @notice Permission denied
*/
error NotAllowed();
error ZeroAddress();

/**
* --- Overrides ---
* @notice Zero address not allowed
*/
error ZeroAddress();

/*///////////////////////////////////////////////////////////////
OVERRIDES
//////////////////////////////////////////////////////////////*/

/**
* @inheritdoc VestingWallet
* @notice This contract is only meant to vest NEXT tokens
* @inheritdoc VestingWallet
* @notice This contract is only meant to unlock NEXT tokens
*/
function vestedAmount(uint64) public view virtual override returns (uint256 _amount) {
return 0;
}

/**
* @inheritdoc VestingWallet
* @notice This contract is only meant to vest NEXT tokens
* @inheritdoc VestingWallet
* @notice This contract is only meant to unlock NEXT tokens
*/
function vestedAmount(address _token, uint64 _timestamp) public view virtual override returns (uint256 _amount) {
if (_token != NEXT_TOKEN) return 0;
Expand All @@ -78,8 +138,8 @@ contract ConnextVestingWallet is VestingWalletWithCliff, Ownable2Step {
}

/**
* @inheritdoc VestingWallet
* @notice This contract is only meant to vest NEXT tokens
* @inheritdoc VestingWallet
* @notice This contract is only meant to unlock NEXT tokens
*/
function releasable(address _token) public view virtual override returns (uint256 _amount) {
_amount = vestedAmount(_token, uint64(block.timestamp)) - released(_token);
Expand All @@ -89,24 +149,30 @@ contract ConnextVestingWallet is VestingWalletWithCliff, Ownable2Step {

/**
* @inheritdoc Ownable2Step
* @dev Override needed by linearization
* @dev Override needed by linearization
*/
function _transferOwnership(address _newOwner) internal virtual override(Ownable2Step, Ownable) {
super._transferOwnership(_newOwner);
}

/**
* @inheritdoc Ownable2Step
* @dev Override needed by linearization
* @dev Override needed by linearization
*/
function transferOwnership(address _newOwner) public virtual override(Ownable2Step, Ownable) {
super.transferOwnership(_newOwner);
}

/*///////////////////////////////////////////////////////////////
CUSTOM LOGIC
//////////////////////////////////////////////////////////////*/

/**
* --- Dust Collector ---
* @notice Collect dust from the contract
* @dev This contract allows to withdraw any token, with the exception of vested NEXT tokens
* @notice Collect dust from the contract
* @dev This contract allows to withdraw any token, with the exception of unlocked NEXT tokens
* @param _token The address of the token to withdraw
* @param _amount The amount of tokens to withdraw
* @param _to The address to send the tokens to
*/
function sendDust(IERC20 _token, uint256 _amount, address _to) external onlyOwner {
if (_to == address(0)) revert ZeroAddress();
Expand All @@ -124,9 +190,9 @@ contract ConnextVestingWallet is VestingWalletWithCliff, Ownable2Step {
}

/**
* --- Claim ---
* @notice Claim tokens from Llama Vesting contract
* @dev This func is needed because only the recipients can claim
* @notice Claim tokens from Llama Vesting contract
* @dev This func is needed because only the recipients can claim
* @param _llamaVestAddress The address of the Llama Vesting contract
*/
function claim(address _llamaVestAddress) external {
IVestingEscrowSimple(_llamaVestAddress).claim(address(this));
Expand Down
14 changes: 14 additions & 0 deletions solidity/contracts/VestingWalletWithCliff.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@ pragma solidity 0.8.20;
import {VestingWallet} from '@openzeppelin/contracts/finance/VestingWallet.sol';

contract VestingWalletWithCliff is VestingWallet {
/**
* @dev The cliff timestamp, set into constructor
*/
uint64 private immutable _CLIFF;

/**
* @dev Constructor that initializes the vesting schedule.
* @param _beneficiary The beneficiary of the vested tokens.
* @param _vestingStartTimestamp The start time of the vesting schedule.
* @param _durationSeconds The duration of the vesting schedule, in seconds.
* @param _cliffDurationSeconds The duration before the cliff, in seconds.
*/
constructor(
address _beneficiary,
uint64 _vestingStartTimestamp,
Expand All @@ -17,6 +27,7 @@ contract VestingWalletWithCliff is VestingWallet {

/**
* @dev Getter for the cliff timestamp.
* @return _timestamp The timestamp of the cliff.
*/
function cliff() public view virtual returns (uint256 _timestamp) {
return _CLIFF;
Expand All @@ -25,6 +36,9 @@ contract VestingWalletWithCliff is VestingWallet {
/**
* @dev Virtual implementation of the vesting formula. This returns the amount vested, as a function of time, for
* an asset given its total historical allocation.
* @param _totalAllocation The total amount of tokens to be vested.
* @param _timestamp The timestamp to calculate vesting for.
* @return _amount The amount to vest for the passed timestamp.
*/
function _vestingSchedule(
uint256 _totalAllocation,
Expand Down
Loading

0 comments on commit 50d4040

Please sign in to comment.