Skip to content

Latest commit

 

History

History
653 lines (523 loc) · 18.4 KB

Escrow.md

File metadata and controls

653 lines (523 loc) · 18.4 KB

A holding contract for Sovryn Ethereum Pool to accept SOV Token. (Escrow.sol)

View Source: contracts/escrow/Escrow.sol

↘ Derived Contracts: EscrowReward

Escrow contract

You can use this contract for deposit of SOV tokens for some time and withdraw later.

Enums

Status

enum Status {
 Deployed,
 Deposit,
 Holding,
 Withdraw,
 Expired
}

Contract Members

Constants & Variables

//public members
uint256 public totalDeposit;
uint256 public releaseTime;
uint256 public depositLimit;
contract IERC20 public SOV;
address public multisig;
enum Escrow.Status public status;

//internal members
mapping(address => uint256) internal userBalances;

Events

event EscrowActivated();
event EscrowInHoldingState();
event EscrowInWithdrawState();
event EscrowFundExpired();
event NewMultisig(address indexed _initiator, address indexed _newMultisig);
event TokenReleaseUpdated(address indexed _initiator, uint256  _releaseTimestamp);
event TokenDepositLimitUpdated(address indexed _initiator, uint256  _depositLimit);
event TokenDeposit(address indexed _initiator, uint256  _amount);
event DepositLimitReached();
event TokenWithdrawByMultisig(address indexed _initiator, uint256  _amount);
event TokenDepositByMultisig(address indexed _initiator, uint256  _amount);
event TokenWithdraw(address indexed _initiator, uint256  _amount);

Modifiers

onlyMultisig

modifier onlyMultisig() internal

checkStatus

modifier checkStatus(enum Escrow.Status s) internal

Arguments

Name Type Description
s enum Escrow.Status

checkRelease

modifier checkRelease() internal

Functions


constructor

Setup the required parameters.

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

Arguments

Name Type Description
_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 _SOV,
        address _multisig,
        uint256 _releaseTime,
        uint256 _depositLimit
    ) public {
        require(_SOV != address(0), "Invalid SOV Address.");
        require(_multisig != address(0), "Invalid Multisig Address.");

        SOV = IERC20(_SOV);
        multisig = _multisig;

        emit NewMultisig(msg.sender, _multisig);

        releaseTime = _releaseTime;
        depositLimit = _depositLimit;

        status = Status.Deployed;
    }

init

This function is called once after deployment for starting the deposit action.

function init() external nonpayable onlyMultisig checkStatus 
Source Code
function init() external onlyMultisig checkStatus(Status.Deployed) {
        status = Status.Deposit;

        emit EscrowActivated();
    }

updateMultisig

Update Multisig.

function updateMultisig(address _newMultisig) external nonpayable onlyMultisig 

Arguments

Name Type Description
_newMultisig address The new owner of the tokens & contract.
Source Code
function updateMultisig(address _newMultisig) external onlyMultisig {
        require(_newMultisig != address(0), "New Multisig address invalid.");

        multisig = _newMultisig;

        emit NewMultisig(msg.sender, _newMultisig);
    }

updateReleaseTimestamp

Update Release Timestamp.

function updateReleaseTimestamp(uint256 _newReleaseTime) external nonpayable onlyMultisig 

Arguments

Name Type Description
_newReleaseTime uint256 The new release timestamp for token release.
Source Code
function updateReleaseTimestamp(uint256 _newReleaseTime) external onlyMultisig {
        releaseTime = _newReleaseTime;

        emit TokenReleaseUpdated(msg.sender, _newReleaseTime);
    }

updateDepositLimit

Update Deposit Limit.

function updateDepositLimit(uint256 _newDepositLimit) external nonpayable onlyMultisig 

Arguments

Name Type Description
_newDepositLimit uint256 The new deposit limit.
Source Code
function updateDepositLimit(uint256 _newDepositLimit) external onlyMultisig {
        require(
            _newDepositLimit >= totalDeposit,
            "Deposit already higher than the limit trying to be set."
        );
        depositLimit = _newDepositLimit;

        emit TokenDepositLimitUpdated(msg.sender, _newDepositLimit);
    }

depositTokens

Deposit tokens to this contract by User.

function depositTokens(uint256 _amount) external nonpayable checkStatus 

Arguments

Name Type Description
_amount uint256 the amount of tokens deposited.
Source Code
function depositTokens(uint256 _amount) external checkStatus(Status.Deposit) {
        require(_amount > 0, "Amount needs to be bigger than zero.");
        uint256 amount = _amount;

        if (totalDeposit.add(_amount) >= depositLimit) {
            amount = depositLimit.sub(totalDeposit);
            emit DepositLimitReached();
        }

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

        userBalances[msg.sender] = userBalances[msg.sender].add(amount);
        totalDeposit = totalDeposit.add(amount);

        emit TokenDeposit(msg.sender, amount);
    }

changeStateToHolding

Update contract state to Holding.

function changeStateToHolding() external nonpayable onlyMultisig checkStatus 
Source Code
function changeStateToHolding() external onlyMultisig checkStatus(Status.Deposit) {
        status = Status.Holding;

        emit EscrowInHoldingState();
    }

withdrawTokensByMultisig

Withdraws all token from the contract by Multisig.

function withdrawTokensByMultisig(address _receiverAddress) external nonpayable onlyMultisig checkStatus 

Arguments

Name Type Description
_receiverAddress address The address where the tokens has to be transferred. Zero address if the withdraw is to be done in Multisig.
Source Code
function withdrawTokensByMultisig(address _receiverAddress)
        external
        onlyMultisig
        checkStatus(Status.Holding)
    {
        address receiverAddress = msg.sender;
        if (_receiverAddress != address(0)) {
            receiverAddress = _receiverAddress;
        }

        uint256 value = SOV.balanceOf(address(this));
        /// Sending the amount to multisig.
        bool txStatus = SOV.transfer(receiverAddress, value);
        require(txStatus, "Token transfer was not successful. Check receiver address.");

        emit TokenWithdrawByMultisig(msg.sender, value);
    }

depositTokensByMultisig

Deposit tokens to this contract by the Multisig.

function depositTokensByMultisig(uint256 _amount) external nonpayable onlyMultisig checkStatus 

Arguments

Name Type Description
_amount uint256 the amount of tokens deposited.
Source Code
function depositTokensByMultisig(uint256 _amount)
        external
        onlyMultisig
        checkStatus(Status.Holding)
    {
        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.");

        emit TokenDepositByMultisig(msg.sender, _amount);

        if (SOV.balanceOf(address(this)) >= totalDeposit) {
            status = Status.Withdraw;
            emit EscrowInWithdrawState();
        }
    }

withdrawTokens

Withdraws token from the contract by User.

function withdrawTokens() public nonpayable checkRelease checkStatus 
Source Code
function withdrawTokens() public checkRelease checkStatus(Status.Withdraw) {
        uint256 amount = userBalances[msg.sender];
        userBalances[msg.sender] = 0;
        bool txStatus = SOV.transfer(msg.sender, amount);
        require(txStatus, "Token transfer was not successful. Check receiver address.");

        emit TokenWithdraw(msg.sender, amount);
    }

getUserBalance

Function to read the current token balance of a particular user.

function getUserBalance(address _addr) external view
returns(balance uint256)

Arguments

Name Type Description
_addr address

Returns

_addr The user address whose balance has to be checked.

Source Code
function getUserBalance(address _addr) external view returns (uint256 balance) {
        return userBalances[_addr];
    }

Contracts