Skip to content

Latest commit

 

History

History
1068 lines (887 loc) · 33.2 KB

VestingRegistryLogic.md

File metadata and controls

1068 lines (887 loc) · 33.2 KB

VestingRegistryLogic.sol

View Source: contracts/governance/Vesting/VestingRegistryLogic.sol

↗ Extends: VestingRegistryStorage

VestingRegistryLogic contract

Events

event SOVTransferred(address indexed receiver, uint256  amount);
event VestingCreated(address indexed tokenOwner, address  vesting, uint256  cliff, uint256  duration, uint256  amount, uint256  vestingCreationType);
event TeamVestingCreated(address indexed tokenOwner, address  vesting, uint256  cliff, uint256  duration, uint256  amount, uint256  vestingCreationType);
event TokensStaked(address indexed vesting, uint256  amount);
event VestingCreationAndTypesSet(address indexed vesting, struct VestingRegistryStorage.VestingCreationAndTypeDetails  vestingCreationAndType);

Functions


initialize

Replace constructor with initialize function for Upgradable Contracts This function will be called only once by the owner

function initialize(address _vestingFactory, address _SOV, address _staking, address _feeSharingCollector, address _vestingOwner, address _lockedSOV, address[] _vestingRegistries) external nonpayable onlyOwner initializer 

Arguments

Name Type Description
_vestingFactory address
_SOV address
_staking address
_feeSharingCollector address
_vestingOwner address
_lockedSOV address
_vestingRegistries address[]
Source Code
function initialize(
        address _vestingFactory,
        address _SOV,
        address _staking,
        address _feeSharingCollector,
        address _vestingOwner,
        address _lockedSOV,
        address[] calldata _vestingRegistries
    ) external onlyOwner initializer {
        require(_SOV != address(0), "SOV address invalid");
        require(_staking != address(0), "staking address invalid");
        require(_feeSharingCollector != address(0), "feeSharingCollector address invalid");
        require(_vestingOwner != address(0), "vestingOwner address invalid");
        require(_lockedSOV != address(0), "LockedSOV address invalid");

        _setVestingFactory(_vestingFactory);
        SOV = _SOV;
        staking = _staking;
        feeSharingCollector = _feeSharingCollector;
        vestingOwner = _vestingOwner;
        lockedSOV = LockedSOV(_lockedSOV);
        for (uint256 i = 0; i < _vestingRegistries.length; i++) {
            require(_vestingRegistries[i] != address(0), "Vesting registry address invalid");
            vestingRegistries.push(IVestingRegistry(_vestingRegistries[i]));
        }
    }

setVestingFactory

sets vesting factory address

function setVestingFactory(address _vestingFactory) external nonpayable onlyOwner 

Arguments

Name Type Description
_vestingFactory address the address of vesting factory contract
Source Code
function setVestingFactory(address _vestingFactory) external onlyOwner {
        _setVestingFactory(_vestingFactory);
    }

_setVestingFactory

Internal function that sets vesting factory address

function _setVestingFactory(address _vestingFactory) internal nonpayable

Arguments

Name Type Description
_vestingFactory address the address of vesting factory contract
Source Code
function _setVestingFactory(address _vestingFactory) internal {
        require(_vestingFactory != address(0), "vestingFactory address invalid");
        vestingFactory = IVestingFactory(_vestingFactory);
    }

transferSOV

transfers SOV tokens to given address

function transferSOV(address _receiver, uint256 _amount) external nonpayable onlyOwner 

Arguments

Name Type Description
_receiver address the address of the SOV receiver
_amount uint256 the amount to be transferred
Source Code
function transferSOV(address _receiver, uint256 _amount) external onlyOwner {
        require(_receiver != address(0), "receiver address invalid");
        require(_amount != 0, "amount invalid");
        require(IERC20(SOV).transfer(_receiver, _amount), "transfer failed");
        emit SOVTransferred(_receiver, _amount);
    }

addDeployedVestings

adds vestings that were deployed in previous vesting registries

function addDeployedVestings(address[] _tokenOwners, uint256[] _vestingCreationTypes) external nonpayable onlyAuthorized 

Arguments

Name Type Description
_tokenOwners address[]
_vestingCreationTypes uint256[]
Source Code
function addDeployedVestings(
        address[] calldata _tokenOwners,
        uint256[] calldata _vestingCreationTypes
    ) external onlyAuthorized {
        for (uint256 i = 0; i < _tokenOwners.length; i++) {
            require(_tokenOwners[i] != address(0), "token owner cannot be 0 address");
            require(_vestingCreationTypes[i] > 0, "vesting creation type must be greater than 0");
            _addDeployedVestings(_tokenOwners[i], _vestingCreationTypes[i]);
        }
    }

addFourYearVestings

adds four year vestings to vesting registry logic

function addFourYearVestings(address[] _tokenOwners, address[] _vestingAddresses) external nonpayable onlyAuthorized 

Arguments

Name Type Description
_tokenOwners address[] array of token owners
_vestingAddresses address[] array of vesting addresses
Source Code
function addFourYearVestings(
        address[] calldata _tokenOwners,
        address[] calldata _vestingAddresses
    ) external onlyAuthorized {
        require(_tokenOwners.length == _vestingAddresses.length, "arrays mismatch");
        uint256 vestingCreationType = 4;
        uint256 cliff = 4 weeks;
        uint256 duration = 156 weeks;
        for (uint256 i = 0; i < _tokenOwners.length; i++) {
            require(!isVesting[_vestingAddresses[i]], "vesting exists");
            require(_tokenOwners[i] != address(0), "token owner cannot be 0 address");
            require(_vestingAddresses[i] != address(0), "vesting cannot be 0 address");
            uint256 uid =
                uint256(
                    keccak256(
                        abi.encodePacked(
                            _tokenOwners[i],
                            uint256(VestingType.Vesting),
                            cliff,
                            duration,
                            vestingCreationType
                        )
                    )
                );
            vestings[uid] = Vesting(
                uint256(VestingType.Vesting),
                vestingCreationType,
                _vestingAddresses[i]
            );
            vestingsOf[_tokenOwners[i]].push(uid);
            isVesting[_vestingAddresses[i]] = true;
        }
    }

createVesting

creates Vesting contract

function createVesting(address _tokenOwner, uint256 _amount, uint256 _cliff, uint256 _duration) external nonpayable onlyAuthorized 

Arguments

Name Type Description
_tokenOwner address the owner of the tokens
_amount uint256 the amount to be staked
_cliff uint256 the cliff in seconds
_duration uint256 the total duration in seconds
Source Code
function createVesting(
        address _tokenOwner,
        uint256 _amount,
        uint256 _cliff,
        uint256 _duration
    ) external onlyAuthorized {
        createVestingAddr(_tokenOwner, _amount, _cliff, _duration, 3);
    }

createVestingAddr

creates Vesting contract

function createVestingAddr(address _tokenOwner, uint256 _amount, uint256 _cliff, uint256 _duration, uint256 _vestingCreationType) public nonpayable onlyAuthorized 

Arguments

Name Type Description
_tokenOwner address the owner of the tokens
_amount uint256 the amount to be staked
_cliff uint256 the cliff in seconds
_duration uint256 the total duration in seconds
_vestingCreationType uint256 the type of vesting created(e.g. Origin, Bug Bounty etc.)
Source Code
function createVestingAddr(
        address _tokenOwner,
        uint256 _amount,
        uint256 _cliff,
        uint256 _duration,
        uint256 _vestingCreationType
    ) public onlyAuthorized {
        address vesting =
            _getOrCreateVesting(
                _tokenOwner,
                _cliff,
                _duration,
                uint256(VestingType.Vesting),
                _vestingCreationType
            );

        emit VestingCreated(
            _tokenOwner,
            vesting,
            _cliff,
            _duration,
            _amount,
            _vestingCreationType
        );
    }

createTeamVesting

creates Team Vesting contract

function createTeamVesting(address _tokenOwner, uint256 _amount, uint256 _cliff, uint256 _duration, uint256 _vestingCreationType) external nonpayable onlyAuthorized 

Arguments

Name Type Description
_tokenOwner address the owner of the tokens
_amount uint256 the amount to be staked
_cliff uint256 the cliff in seconds
_duration uint256 the total duration in seconds
_vestingCreationType uint256 the type of vesting created(e.g. Origin, Bug Bounty etc.)
Source Code
function createTeamVesting(
        address _tokenOwner,
        uint256 _amount,
        uint256 _cliff,
        uint256 _duration,
        uint256 _vestingCreationType
    ) external onlyAuthorized {
        address vesting =
            _getOrCreateVesting(
                _tokenOwner,
                _cliff,
                _duration,
                uint256(VestingType.TeamVesting),
                _vestingCreationType
            );

        emit TeamVestingCreated(
            _tokenOwner,
            vesting,
            _cliff,
            _duration,
            _amount,
            _vestingCreationType
        );
    }

stakeTokens

stakes tokens according to the vesting schedule

function stakeTokens(address _vesting, uint256 _amount) external nonpayable onlyAuthorized 

Arguments

Name Type Description
_vesting address the address of Vesting contract
_amount uint256 the amount of tokens to stake
Source Code
function stakeTokens(address _vesting, uint256 _amount) external onlyAuthorized {
        require(_vesting != address(0), "vesting address invalid");
        require(_amount > 0, "amount invalid");

        IERC20(SOV).approve(_vesting, _amount);
        IVesting(_vesting).stakeTokens(_amount);
        emit TokensStaked(_vesting, _amount);
    }

getVesting

returns vesting contract address for the given token owner

function getVesting(address _tokenOwner) public view
returns(address)

Arguments

Name Type Description
_tokenOwner address the owner of the tokens
Source Code
function getVesting(address _tokenOwner) public view returns (address) {
        return getVestingAddr(_tokenOwner, lockedSOV.cliff(), lockedSOV.duration(), 3);
    }

getVestingAddr

public function that returns vesting contract address for the given token owner, cliff, duration

function getVestingAddr(address _tokenOwner, uint256 _cliff, uint256 _duration, uint256 _vestingCreationType) public view
returns(address)

Arguments

Name Type Description
_tokenOwner address
_cliff uint256
_duration uint256
_vestingCreationType uint256
Source Code
function getVestingAddr(
        address _tokenOwner,
        uint256 _cliff,
        uint256 _duration,
        uint256 _vestingCreationType
    ) public view returns (address) {
        uint256 type_ = uint256(VestingType.Vesting);
        uint256 uid =
            uint256(
                keccak256(
                    abi.encodePacked(_tokenOwner, type_, _cliff, _duration, _vestingCreationType)
                )
            );
        return vestings[uid].vestingAddress;
    }

getTeamVesting

returns team vesting contract address for the given token owner, cliff, duration

function getTeamVesting(address _tokenOwner, uint256 _cliff, uint256 _duration, uint256 _vestingCreationType) public view
returns(address)

Arguments

Name Type Description
_tokenOwner address
_cliff uint256
_duration uint256
_vestingCreationType uint256
Source Code
function getTeamVesting(
        address _tokenOwner,
        uint256 _cliff,
        uint256 _duration,
        uint256 _vestingCreationType
    ) public view returns (address) {
        uint256 type_ = uint256(VestingType.TeamVesting);
        uint256 uid =
            uint256(
                keccak256(
                    abi.encodePacked(_tokenOwner, type_, _cliff, _duration, _vestingCreationType)
                )
            );
        return vestings[uid].vestingAddress;
    }

isTeamVesting

check if the specific vesting address is team vesting or not

function isTeamVesting(address _vestingAddress) external view
returns(bool)

Arguments

Name Type Description
_vestingAddress address address of vesting contract *

Returns

true for teamVesting, false for normal vesting

Source Code
function isTeamVesting(address _vestingAddress) external view returns (bool) {
        return (vestingCreationAndTypes[_vestingAddress].isSet &&
            vestingCreationAndTypes[_vestingAddress].vestingType ==
            uint32(VestingType.TeamVesting));
    }

registerVestingToVestingCreationAndTypes

setter function to register existing vesting contract to vestingCreationAndTypes storage

function registerVestingToVestingCreationAndTypes(address[] _vestingAddresses, struct VestingRegistryStorage.VestingCreationAndTypeDetails[] _vestingCreationAndTypes) public nonpayable onlyAuthorized 

Arguments

Name Type Description
_vestingAddresses address[] array of vesting address
_vestingCreationAndTypes struct VestingRegistryStorage.VestingCreationAndTypeDetails[] array for VestingCreationAndTypeDetails struct
Source Code
function registerVestingToVestingCreationAndTypes(
        address[] memory _vestingAddresses,
        VestingCreationAndTypeDetails[] memory _vestingCreationAndTypes
    ) public onlyAuthorized {
        require(_vestingAddresses.length == _vestingCreationAndTypes.length, "Unmatched length");
        for (uint256 i = 0; i < _vestingCreationAndTypes.length; i++) {
            VestingCreationAndTypeDetails memory _vestingCreationAndType =
                _vestingCreationAndTypes[i];
            address _vestingAddress = _vestingAddresses[i];

            vestingCreationAndTypes[_vestingAddress] = _vestingCreationAndType;

            emit VestingCreationAndTypesSet(
                _vestingAddress,
                vestingCreationAndTypes[_vestingAddress]
            );
        }
    }

_getOrCreateVesting

Internal function to deploy Vesting/Team Vesting contract

function _getOrCreateVesting(address _tokenOwner, uint256 _cliff, uint256 _duration, uint256 _type, uint256 _vestingCreationType) internal nonpayable
returns(address)

Arguments

Name Type Description
_tokenOwner address the owner of the tokens
_cliff uint256 the cliff in seconds
_duration uint256 the total duration in seconds
_type uint256 the type of vesting
_vestingCreationType uint256 the type of vesting created(e.g. Origin, Bug Bounty etc.)
Source Code
function _getOrCreateVesting(
        address _tokenOwner,
        uint256 _cliff,
        uint256 _duration,
        uint256 _type,
        uint256 _vestingCreationType
    ) internal returns (address) {
        address vesting;
        uint256 uid =
            uint256(
                keccak256(
                    abi.encodePacked(_tokenOwner, _type, _cliff, _duration, _vestingCreationType)
                )
            );
        if (vestings[uid].vestingAddress == address(0)) {
            if (_type == 1) {
                vesting = vestingFactory.deployVesting(
                    SOV,
                    staking,
                    _tokenOwner,
                    _cliff,
                    _duration,
                    feeSharingCollector,
                    _tokenOwner
                );
            } else {
                vesting = vestingFactory.deployTeamVesting(
                    SOV,
                    staking,
                    _tokenOwner,
                    _cliff,
                    _duration,
                    feeSharingCollector,
                    vestingOwner
                );
            }
            vestings[uid] = Vesting(_type, _vestingCreationType, vesting);
            vestingsOf[_tokenOwner].push(uid);
            isVesting[vesting] = true;

            vestingCreationAndTypes[vesting] = VestingCreationAndTypeDetails({
                isSet: true,
                vestingType: uint32(_type),
                vestingCreationType: uint128(_vestingCreationType)
            });

            emit VestingCreationAndTypesSet(vesting, vestingCreationAndTypes[vesting]);
        }
        return vestings[uid].vestingAddress;
    }

_addDeployedVestings

stores the addresses of Vesting contracts from all three previous versions of Vesting Registry

function _addDeployedVestings(address _tokenOwner, uint256 _vestingCreationType) internal nonpayable

Arguments

Name Type Description
_tokenOwner address
_vestingCreationType uint256
Source Code
function _addDeployedVestings(address _tokenOwner, uint256 _vestingCreationType) internal {
        uint256 uid;
        uint256 i = _vestingCreationType - 1;

        address vestingAddress = vestingRegistries[i].getVesting(_tokenOwner);
        if (vestingAddress != address(0)) {
            VestingLogic vesting = VestingLogic(vestingAddress);
            uid = uint256(
                keccak256(
                    abi.encodePacked(
                        _tokenOwner,
                        uint256(VestingType.Vesting),
                        vesting.cliff(),
                        vesting.duration(),
                        _vestingCreationType
                    )
                )
            );
            vestings[uid] = Vesting(
                uint256(VestingType.Vesting),
                _vestingCreationType,
                vestingAddress
            );
            vestingsOf[_tokenOwner].push(uid);
            isVesting[vestingAddress] = true;
        }

        address teamVestingAddress = vestingRegistries[i].getTeamVesting(_tokenOwner);
        if (teamVestingAddress != address(0)) {
            VestingLogic vesting = VestingLogic(teamVestingAddress);
            uid = uint256(
                keccak256(
                    abi.encodePacked(
                        _tokenOwner,
                        uint256(VestingType.TeamVesting),
                        vesting.cliff(),
                        vesting.duration(),
                        _vestingCreationType
                    )
                )
            );
            vestings[uid] = Vesting(
                uint256(VestingType.TeamVesting),
                _vestingCreationType,
                teamVestingAddress
            );
            vestingsOf[_tokenOwner].push(uid);
            isVesting[teamVestingAddress] = true;
        }
    }

getVestingsOf

returns all vesting details for the given token owner

function getVestingsOf(address _tokenOwner) external view
returns(struct VestingRegistryStorage.Vesting[])

Arguments

Name Type Description
_tokenOwner address
Source Code
function getVestingsOf(address _tokenOwner) external view returns (Vesting[] memory) {
        uint256[] memory vestingIds = vestingsOf[_tokenOwner];
        uint256 length = vestingIds.length;
        Vesting[] memory _vestings = new Vesting[](vestingIds.length);
        for (uint256 i = 0; i < length; i++) {
            _vestings[i] = vestings[vestingIds[i]];
        }
        return _vestings;
    }

getVestingDetails

returns cliff and duration for Vesting & TeamVesting contracts

function getVestingDetails(address _vestingAddress) external view
returns(cliff uint256, duration uint256)

Arguments

Name Type Description
_vestingAddress address
Source Code
function getVestingDetails(address _vestingAddress)
        external
        view
        returns (uint256 cliff, uint256 duration)
    {
        VestingLogic vesting = VestingLogic(_vestingAddress);
        return (vesting.cliff(), vesting.duration());
    }

isVestingAddress

returns if the address is a vesting address

function isVestingAddress(address _vestingAddress) external view
returns(isVestingAddr bool)

Arguments

Name Type Description
_vestingAddress address
Source Code
function isVestingAddress(address _vestingAddress) external view returns (bool isVestingAddr) {
        return isVesting[_vestingAddress];
    }

Contracts