Skip to content

Latest commit

 

History

History
584 lines (482 loc) · 17.5 KB

OriginInvestorsClaim.md

File metadata and controls

584 lines (482 loc) · 17.5 KB

Origin investors claim vested cSOV tokens. (OriginInvestorsClaim.sol)

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

↗ Extends: Ownable

OriginInvestorsClaim contract

// TODO: fund this contract with a total amount of SOV needed to distribute.

Contract Members

Constants & Variables

uint256 public totalAmount;
uint256 public constant SOV_VESTING_CLIFF;
uint256 public kickoffTS;
uint256 public vestingTerm;
uint256 public investorsQty;
bool public investorsListInitialized;
contract VestingRegistry public vestingRegistry;
contract IStaking public staking;
contract IERC20 public SOVToken;
mapping(address => bool) public admins;
mapping(address => uint256) public investorsAmountsList;

Events

event AdminAdded(address  admin);
event AdminRemoved(address  admin);
event InvestorsAmountsListAppended(uint256  qty, uint256  amount);
event ClaimVested(address indexed investor, uint256  amount);
event ClaimTransferred(address indexed investor, uint256  amount);
event InvestorsAmountsListInitialized(uint256  qty, uint256  totalAmount);

Modifiers

onlyAuthorized

Throws if called by any account other than the owner or admin.

modifier onlyAuthorized() internal

onlyWhitelisted

Throws if called by any account not whitelisted.

modifier onlyWhitelisted() internal

notInitialized

Throws if called w/ an initialized investors list.

modifier notInitialized() internal

initialized

Throws if called w/ an uninitialized investors list.

modifier initialized() internal

Functions


constructor

Contract deployment requires one parameter:

function (address vestingRegistryAddress) public nonpayable

Arguments

Name Type Description
vestingRegistryAddress address The vestingRegistry contract instance address.
Source Code
constructor(address vestingRegistryAddress) public {
        vestingRegistry = VestingRegistry(vestingRegistryAddress);
        staking = IStaking(vestingRegistry.staking());
        kickoffTS = staking.kickoffTS();
        SOVToken = IERC20(staking.SOVToken());
        vestingTerm = kickoffTS + SOV_VESTING_CLIFF;
    }

addAdmin

Add account to ACL.

function addAdmin(address _admin) public nonpayable onlyOwner 

Arguments

Name Type Description
_admin address The addresses of the account to grant permissions.
Source Code
function addAdmin(address _admin) public onlyOwner {
        admins[_admin] = true;
        emit AdminAdded(_admin);
    }

removeAdmin

Remove account from ACL.

function removeAdmin(address _admin) public nonpayable onlyOwner 

Arguments

Name Type Description
_admin address The addresses of the account to revoke permissions.
Source Code
function removeAdmin(address _admin) public onlyOwner {
        admins[_admin] = false;
        emit AdminRemoved(_admin);
    }

authorizedBalanceWithdraw

In case we have unclaimed tokens or in emergency case this function transfers all SOV tokens to a given address.

function authorizedBalanceWithdraw(address toAddress) public nonpayable onlyAuthorized 

Arguments

Name Type Description
toAddress address The recipient address of all this contract tokens.
Source Code
function authorizedBalanceWithdraw(address toAddress) public onlyAuthorized {
        require(
            SOVToken.transfer(toAddress, SOVToken.balanceOf(address(this))),
            "OriginInvestorsClaim::authorizedTransferBalance: transfer failed"
        );
    }

setInvestorsAmountsListInitialized

Should be called after the investors list setup completed. This function checks whether the SOV token balance of the contract is enough and sets status list to initialized.

function setInvestorsAmountsListInitialized() public nonpayable onlyAuthorized notInitialized 
Source Code
function setInvestorsAmountsListInitialized() public onlyAuthorized notInitialized {
        require(
            SOVToken.balanceOf(address(this)) >= totalAmount,
            "OriginInvestorsClaim::setInvestorsAmountsList: the contract is not enough financed"
        );

        investorsListInitialized = true;

        emit InvestorsAmountsListInitialized(investorsQty, totalAmount);
    }

appendInvestorsAmountsList

The contract should be approved or transferred necessary amount of SOV prior to calling the function.

function appendInvestorsAmountsList(address[] investors, uint256[] claimAmounts) external nonpayable onlyAuthorized notInitialized 

Arguments

Name Type Description
investors address[] The list of investors addresses to add to the list. Duplicates will be skipped.
claimAmounts uint256[] The list of amounts for investors investors[i] will receive claimAmounts[i] of SOV.
Source Code
function appendInvestorsAmountsList(
        address[] calldata investors,
        uint256[] calldata claimAmounts
    ) external onlyAuthorized notInitialized {
        uint256 subQty;
        uint256 sumAmount;
        require(
            investors.length == claimAmounts.length,
            "OriginInvestorsClaim::appendInvestorsAmountsList: investors.length != claimAmounts.length"
        );

        for (uint256 i = 0; i < investors.length; i++) {
            if (investorsAmountsList[investors[i]] == 0) {
                investorsAmountsList[investors[i]] = claimAmounts[i];
                sumAmount = sumAmount.add(claimAmounts[i]);
            } else {
                subQty = subQty.add(1);
            }
        }

        investorsQty = investorsQty.add(investors.length.sub(subQty));
        totalAmount = totalAmount.add(sumAmount);
        emit InvestorsAmountsListAppended(investors.length.sub(subQty), sumAmount);
    }

claim

Claim tokens from this contract. If vestingTerm is not yet achieved a vesting is created. Otherwise tokens are tranferred.

function claim() external nonpayable onlyWhitelisted initialized 
Source Code
function claim() external onlyWhitelisted initialized {
        if (now < vestingTerm) {
            createVesting();
        } else {
            transfer();
        }
    }

createVesting

Transfer tokens from this contract to a vestingRegistry contract. Sender is removed from investor list and all its unvested tokens are sent to vesting contract.

function createVesting() internal nonpayable
Source Code
function createVesting() internal {
        uint256 cliff = vestingTerm.sub(now);
        uint256 duration = cliff;
        uint256 amount = investorsAmountsList[msg.sender];
        address vestingContractAddress;

        vestingContractAddress = vestingRegistry.getVesting(msg.sender);
        require(
            vestingContractAddress == address(0),
            "OriginInvestorsClaim::withdraw: the claimer has an active vesting contract"
        );

        delete investorsAmountsList[msg.sender];

        vestingRegistry.createVesting(msg.sender, amount, cliff, duration);
        vestingContractAddress = vestingRegistry.getVesting(msg.sender);
        require(
            SOVToken.transfer(address(vestingRegistry), amount),
            "OriginInvestorsClaim::withdraw: SOV transfer failed"
        );
        vestingRegistry.stakeTokens(vestingContractAddress, amount);

        emit ClaimVested(msg.sender, amount);
    }

transfer

Transfer tokens from this contract to the sender. Sender is removed from investor list and all its unvested tokens are sent to its account.

function transfer() internal nonpayable
Source Code
function transfer() internal {
        uint256 amount = investorsAmountsList[msg.sender];

        delete investorsAmountsList[msg.sender];

        /**
         * @dev Withdraw only for those claiming after the cliff, i.e. without vesting contracts.
         * Those with vestingContracts should withdraw using Vesting.withdrawTokens
         * from Vesting (VestingLogic) contract.
         * */
        require(
            SOVToken.transfer(msg.sender, amount),
            "OriginInvestorsClaim::withdraw: SOV transfer failed"
        );

        emit ClaimTransferred(msg.sender, amount);
    }

Contracts