Skip to content

Latest commit

 

History

History
399 lines (339 loc) · 13 KB

EscrowReward.md

File metadata and controls

399 lines (339 loc) · 13 KB

A reward distribution contract for Sovryn Ethereum Pool Escrow Contract. (EscrowReward.sol)

View Source: contracts/escrow/EscrowReward.sol

↗ Extends: Escrow

EscrowReward contract

Multisig can use this contract for depositing of Reward tokens based on the total token deposit.

Contract Members

Constants & Variables

uint256 public totalRewardDeposit;
contract ILockedSOV public lockedSOV;

Events

event LockedSOVUpdated(address indexed _initiator, address indexed _lockedSOV);
event RewardDepositByMultisig(address indexed _initiator, uint256  _amount);
event RewardTokenWithdraw(address indexed _initiator, uint256  _amount);

Functions


constructor

Setup the required parameters.

function (address _lockedSOV, address _SOV, address _multisig, uint256 _releaseTime, uint256 _depositLimit) public nonpayable Escrow 

Arguments

Name Type Description
_lockedSOV address The Locked SOV Contract address.
_SOV address The SOV token address.
_multisig address The owner of the tokens & contract.
_releaseTime uint256 The token release time, zero if undecided.
_depositLimit uint256 The amount of tokens we will be accepting.
Source Code
constructor(
        address _lockedSOV,
        address _SOV,
        address _multisig,
        uint256 _releaseTime,
        uint256 _depositLimit
    ) public Escrow(_SOV, _multisig, _releaseTime, _depositLimit) {
        if (_lockedSOV != address(0)) {
            lockedSOV = ILockedSOV(_lockedSOV);
        }
    }

updateLockedSOV

Set the Locked SOV Contract Address if not already done.

function updateLockedSOV(address _lockedSOV) external nonpayable onlyMultisig 

Arguments

Name Type Description
_lockedSOV address The Locked SOV Contract address.
Source Code
function updateLockedSOV(address _lockedSOV) external onlyMultisig {
        require(_lockedSOV != address(0), "Invalid Reward Token Address.");

        lockedSOV = ILockedSOV(_lockedSOV);

        emit LockedSOVUpdated(msg.sender, _lockedSOV);
    }

depositRewardByMultisig

Deposit tokens to this contract by the Multisig.

function depositRewardByMultisig(uint256 _amount) external nonpayable onlyMultisig 

Arguments

Name Type Description
_amount uint256 the amount of tokens deposited.
Source Code
function depositRewardByMultisig(uint256 _amount) external onlyMultisig {
        require(
            status != Status.Withdraw,
            "Reward Token deposit is only allowed before User Withdraw starts."
        );
        require(_amount > 0, "Amount needs to be bigger than zero.");

        bool txStatus = SOV.transferFrom(msg.sender, address(this), _amount);
        require(txStatus, "Token transfer was not successful.");

        totalRewardDeposit = totalRewardDeposit.add(_amount);
        txStatus = SOV.approve(address(lockedSOV), totalRewardDeposit);
        require(txStatus, "Token Approval was not successful.");

        emit RewardDepositByMultisig(msg.sender, _amount);
    }

withdrawTokensAndReward

Withdraws token and reward from the contract by User. Reward is gone to lockedSOV contract for future vesting.

function withdrawTokensAndReward() external nonpayable checkRelease checkStatus 
Source Code
function withdrawTokensAndReward() external checkRelease checkStatus(Status.Withdraw) {
        // Reward calculation have to be done initially as the User Balance is zeroed out .
        uint256 reward = userBalances[msg.sender].mul(totalRewardDeposit).div(totalDeposit);
        withdrawTokens();

        lockedSOV.depositSOV(msg.sender, reward);

        emit RewardTokenWithdraw(msg.sender, reward);
    }

getReward

Function to read the reward a particular user can get.

function getReward(address _addr) external view
returns(reward uint256)

Arguments

Name Type Description
_addr address The address of the user whose reward is to be read.

Returns

reward The reward received by the user.

Source Code
function getReward(address _addr) external view returns (uint256 reward) {
        if (userBalances[_addr].mul(totalRewardDeposit) == 0) {
            return 0;
        }
        return userBalances[_addr].mul(totalRewardDeposit).div(totalDeposit);
    }

Contracts