Skip to content
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

Vesting creator automation #264

Merged
merged 21 commits into from
Sep 20, 2021
Merged

Conversation

smbsp
Copy link
Contributor

@smbsp smbsp commented Jun 11, 2021

The change is essentially divided into three parts:
a) Vesting Registry - a new upgradable Vesting Registry contract is created that will replace VestingRegistry, VestingRegistry2 and VestingRegistry3 contracts
b) Vesting Migrations - the data from previous registries will be migrated to the new registry
c) Vesting Creator - Used for vesting creation and token staking for team compensation, bug bounty etc.

Technical Spec: https://docs.google.com/document/d/1MI0XzymjsHzI8jIz7F1pw_DSTFrv-f2veX_AM0n1c_w/edit#heading=h.vu27ydtqj65m
Related PR: #195

Note: The deployment script is not complete yet

@ghost ghost assigned smbsp Jun 11, 2021
@ghost ghost added this to In progress in Sovryn via automation Jun 11, 2021
@ghost ghost added the enhancement New feature or request label Jun 11, 2021
@smbsp smbsp force-pushed the vesting-creator-automation branch from eaaaeee to 5bb334c Compare June 15, 2021 15:08
@smbsp smbsp force-pushed the vesting-creator-automation branch from 5bb334c to 0fedb12 Compare June 16, 2021 18:32
@smbsp
Copy link
Contributor Author

smbsp commented Jun 17, 2021

Changes are done. Awaiting audit results. Will resume working on this when the front end development starts on June 28.

@smbsp
Copy link
Contributor Author

smbsp commented Jun 18, 2021

Tested Vesting Migrations successfully. Kept the temporary files here: https://drive.google.com/drive/folders/1NgrTxyqZQ43hcanssGAGvXmqvIUNEPJp?usp=sharing

Copy link

@korepkorep korepkorep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several code quality issues that don't endanger contracts` security

Comment on lines 66 to 77
function setVestingFactory(address _vestingFactory) public onlyOwner {
_setVestingFactory(_vestingFactory);
}

/**
* @notice Internal function that sets vesting factory address
* @param _vestingFactory the address of vesting factory contract
*/
function _setVestingFactory(address _vestingFactory) internal {
require(_vestingFactory != address(0), "vestingFactory address invalid");
vestingFactory = IVestingFactory(_vestingFactory);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to declare visibilty of setVestingFactory as external

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

require(_receiver != address(0), "receiver address invalid");
require(_amount != 0, "amount invalid");

IERC20(SOV).transfer(_receiver, _amount);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't check returned value of ERC20 token

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a check:
require(IERC20(SOV).transfer(_receiver, _amount), "transfer failed");

Comment on lines 276 to 279
uint256[] storage vestingIds = vestingsOf[_tokenOwner];
Vesting[] memory _vestings = new Vesting[](vestingIds.length);
for (uint256 i = 0; i < vestingIds.length; i++) {
Vesting storage _vesting = vestings[vestingIds[i]];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like storage is not necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed Storage

Vesting[] memory _vestings = new Vesting[](vestingIds.length);
for (uint256 i = 0; i < vestingIds.length; i++) {
Vesting storage _vesting = vestings[vestingIds[i]];
_vestings[i] = Vesting(_vesting.vestingType, _vesting.vestingCreationType, _vesting.vestingAddress);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was possible not to declare new Vesting but just to copy (_vestings[i] = vestings[vestingIds[i]])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 46 to 47
SOV = IERC20(_SOV);
vestingRegistryLogic = VestingRegistryLogic(_vestingRegistryLogic);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider to declare as immutable to save gas consumption

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Immutable keyword is not available in Solidity 0.5

Comment on lines +85 to +86
require(_receiver != address(0), "receiver address invalid");
require(_amount != 0, "amount invalid");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SOV is your ERC20 token the transfer of which checks receiver != address(0). It means that you can remove your require to reduce gas consumption. And also you can remove _amount != 0 since transfer won't revert in case of 0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we cannot remove the check receiver != address(0) as it will fail with 'function call to a non-contract' while passing zero. I think it is good to have both the checks.

Comment on lines 13 to 16
bool vestingCreated;

/// @notice 2 weeks in seconds.
uint256 constant TWO_WEEKS = 1209600;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Visibility should be declared explicitly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

function getVestingsOf(address _tokenOwner) external view returns (Vesting[] memory) {
uint256[] storage vestingIds = vestingsOf[_tokenOwner];
Vesting[] memory _vestings = new Vesting[](vestingIds.length);
for (uint256 i = 0; i < vestingIds.length; i++) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to declare new local variable with vestingIds.length value to reduce gas consumption

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* @notice adds vestings to be processed to the list
* @dev if account doesn't have another vesting of the same type vesting data will be added to vestingDataList
*/
function addVestings(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

External instead of public. Same for other functions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* by using this contract instead, that inherits from UpgradableProxy
* the possibility of being enhanced and re-deployed.
* */
contract VestingRegistryProxy is VestingRegistryStorage, UpgradableProxy {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UpgradableProxy contract is similar to EIP-1967 which means that it would be better if the proxy does not know about the logic of VestingRegistryLogic and its storage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have used the same approach in Staking and it works well. I am curious to understand your suggestion here.

@ororopickpocket ororopickpocket merged commit 4bea9a3 into development Sep 20, 2021
Sovryn automation moved this from In progress to Done Sep 20, 2021
@ororopickpocket ororopickpocket deleted the vesting-creator-automation branch September 20, 2021 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Sovryn
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants