Blockwell

DuckTiers

About

Stats

Public Functions 12
Event Types 4
Code Size 40,388 bytes

Library Use

Uses SafeMath for uint.

Events (4) keyboard_arrow_up

EmergencyWithdrawn Event

Parameters help
user
address help
amount
uint help

OwnershipTransferred Event

Parameters help
previousOwner
address help
newOwner
address help

Staked Event

Parameters help
user
address help
amount
uint help

Withdrawn Event

Parameters help
user
address help
amount
uint help
fee
uint help

UserInfo Struct

Members
staked
uint help
stakedTime
uint help

MAX_NUM_TIERS Constant

uint help
10

_NOT_ENTERED Constant

uint256 help
1

_ENTERED Constant

uint256 help
2

DUCK Variable

address help

canEmergencyWithdraw Variable

bool help

currentMaxTier Variable

uint8 help
Internal Variable

userInfo Variable

mapping(address => UserInfo) help
Internal Variable

tierPrice Variable

uint[] help
Internal Variable

withdrawFeePercent Variable

uint[] help
Internal Variable

_owner Variable

address help
Internal Variable

_status Variable

uint256 help
Internal Variable

Functions Expand All Collapse All

owner keyboard_arrow_up

Parameters help

This function has no parameters.

Properties

Visibility help public
Mutability help view
Source Code
function owner() public view returns (address) {
  return _owner;
}

renounceOwnership keyboard_arrow_up

Parameters help

This function has no parameters.

Properties

Visibility help public
Mutability help transaction

Modifiers help

Source Code
function renounceOwnership() public virtual onlyOwner {
  emit OwnershipTransferred(_owner, address(0));
  _owner = address(0);
}

transferOwnership keyboard_arrow_up

Parameters help

Name Type
newOwner
address help

Properties

Visibility help public
Mutability help transaction

Modifiers help

Requirements help

Source Code
function transferOwnership(address newOwner) public virtual onlyOwner {
  require(newOwner != address(0), "Ownable: new owner is the zero address");
  emit OwnershipTransferred(_owner, newOwner);
  _owner = newOwner;
}

deposit keyboard_arrow_up

Parameters help

Name Type
_amount
uint help

Properties

Visibility help public
Mutability help transaction
Source Code
function deposit(uint256 _amount) external nonReentrant() {
  DUCK.transferFrom(msg.sender, address(this), _amount);

  userInfo[msg.sender].staked = userInfo[msg.sender].staked.add(_amount);
  userInfo[msg.sender].stakedTime = block.timestamp;

  emit Staked(msg.sender, _amount);
}

withdraw keyboard_arrow_up

Parameters help

Name Type
_amount
uint help

Properties

Visibility help public
Mutability help transaction

Requirements help

Source Code
function withdraw(uint256 _amount) external nonReentrant() {
  UserInfo storage user = userInfo[msg.sender];
  require(user.staked >= _amount, "not enough amount to withdraw");

  uint256 toBurn = calculateWithdrawFee(msg.sender, _amount);
  user.staked = user.staked.sub(_amount);

  if (toBurn > 0) {
    DUCK.burn(toBurn);
  }

  DUCK.transfer(msg.sender, _amount.sub(toBurn));
  emit Withdrawn(msg.sender, _amount, toBurn);
}

updateEmergencyWithdrawStatus keyboard_arrow_up

Parameters help

Name Type
_status
bool help

Properties

Visibility help public
Mutability help transaction

Modifiers help

Source Code
function updateEmergencyWithdrawStatus(bool _status) external onlyOwner {
  canEmergencyWithdraw = _status;
}

emergencyWithdraw keyboard_arrow_up

Parameters help

This function has no parameters.

Properties

Visibility help public
Mutability help transaction

Requirements help

Source Code
function emergencyWithdraw() external {
  require(canEmergencyWithdraw, "function disabled");
  UserInfo storage user = userInfo[msg.sender];
  require(user.staked > 0, "nothing to withdraw");

  uint256 _amount = user.staked;
  user.staked = 0;

  DUCK.transfer(msg.sender, _amount);
  emit EmergencyWithdrawn(msg.sender, _amount);
}

updateTier keyboard_arrow_up

Parameters help

Name Type
_tierId
uint8 help
_amount
uint help

Properties

Visibility help public
Mutability help transaction

Modifiers help

Source Code
function updateTier(uint8 _tierId, uint256 _amount) external onlyOwner {
  require(_tierId > 0 && _tierId <= MAX_NUM_TIERS, "invalid _tierId");
  tierPrice[_tierId] = _amount;
  if (_tierId > currentMaxTier) {
    currentMaxTier = _tierId;
  }
}

updateWithdrawFee keyboard_arrow_up

Parameters help

Name Type
_key
uint help
_percent
uint help

Properties

Visibility help public
Mutability help transaction

Modifiers help

Requirements help

Source Code
function updateWithdrawFee(uint256 _key, uint256 _percent) external onlyOwner {
  require(_percent < 100, "too high percent");
  withdrawFeePercent[_key] = _percent;
}

getUserTier keyboard_arrow_up

Parameters help

Name Type
_userAddress
address help

Properties

Visibility help public
Mutability help view
Source Code
function getUserTier(address _userAddress) external view returns (uint8 res) {
  for (uint8 i = 1; i <= MAX_NUM_TIERS; i++) {
    if (tierPrice[i] == 0 || userInfo[_userAddress].staked < tierPrice[i]) {
      return res;
    }

    res = i;
  }
}

calculateWithdrawFee keyboard_arrow_up

Parameters help

Name Type
_userAddress
address help
_amount
uint help

Properties

Visibility help public
Mutability help view

Requirements help

Source Code
function calculateWithdrawFee(address _userAddress, uint256 _amount)
  public
  view
  returns (uint256)
{
  UserInfo storage user = userInfo[_userAddress];
  require(user.staked >= _amount, "not enough amount to withdraw");

  if (block.timestamp < user.stakedTime.add(10 days)) {
    return _amount.mul(withdrawFeePercent[0]).div(100); //30%
  }

  if (block.timestamp < user.stakedTime.add(20 days)) {
    return _amount.mul(withdrawFeePercent[1]).div(100); //25%
  }

  if (block.timestamp < user.stakedTime.add(30 days)) {
    return _amount.mul(withdrawFeePercent[2]).div(100); //20%
  }

  if (block.timestamp < user.stakedTime.add(60 days)) {
    return _amount.mul(withdrawFeePercent[3]).div(100); //10%
  }

  if (block.timestamp < user.stakedTime.add(90 days)) {
    return _amount.mul(withdrawFeePercent[4]).div(100); //5%
  }

  return _amount.mul(withdrawFeePercent[5]).div(100);
}

getTiers keyboard_arrow_up

Parameters help

This function has no parameters.

Properties

Visibility help public
Mutability help view
Source Code
function getTiers() external view returns (uint256[MAX_NUM_TIERS] memory buf) {
  for (uint8 i = 1; i < MAX_NUM_TIERS; i++) {
    if (tierPrice[i] == 0) {
      return buf;
    }
    buf[i - 1] = tierPrice[i];
  }

  return buf;
}

Internal Functions Expand All Collapse All

Internal functions are parts of the contract that can't be used directly, but instead are used by the public functions listed above.

internal Ownable.constructor keyboard_arrow_up

Parameters help

This function has no parameters.

Properties

Visibility help internal
Mutability help transaction
Source Code
constructor() internal {
  address msgSender = _msgSender();
  _owner = msgSender;
  emit OwnershipTransferred(address(0), msgSender);
}

internal Context._msgSender keyboard_arrow_up

Parameters help

This function has no parameters.

Properties

Visibility help internal
Mutability help view
Source Code
function _msgSender() internal view virtual returns (address payable) {
  return msg.sender;
}

internal Context._msgData keyboard_arrow_up

Parameters help

This function has no parameters.

Properties

Visibility help internal
Mutability help view
Source Code
function _msgData() internal view virtual returns (bytes memory) {
  this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
  return msg.data;
}

internal ReentrancyGuard.constructor keyboard_arrow_up

Parameters help

This function has no parameters.

Properties

Visibility help internal
Mutability help transaction
Source Code
constructor() internal {
  _status = _NOT_ENTERED;
}