Vesting Contract

The contract is responsible for managing users deposits and converting esKNINE into KNINE. The esKNINE tokens are burned upon claimint KNINE. KNINE rewards are manually replenished.

Variables

bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE"); - admin role identifier.

uint8 public constant DENOMINATOR = 1_00; - denominator for correct backing/vesting ratio calculation.

address public KNINE; - KNINE token address.

address public esKNINE; - esKNINE token address.

address public STAKING; - RealYieldStaking contract address.

uint64 public endTime; - emergency stop time of the contract (if the emergencyStop method was not called, then == 0).

Settings public settings; - vesting parameters in the Settings struct format.

mapping(address => Deposit) public deposits; - mapping, assigning the Deposit struct for each user address. struct Settings { bool lockedOnly; - true - only locked deposits at RealYieldStaking are allowed for collateral; otherwise - false (means that non-locked are also accounted, but locked deposit must be present anyway). uint64backingRatio; - collateral ratio for desired deposit amount, defines how much KNINE must be locked at Real Yield Staking based on the input amount; the value has a 2 decimals precision (i.e. if you need to set the backing ratio == 2, then the input value for the contract must be 200). uint64vesting; - reward conversion ratio, defines how much KNINE user will receive based on his deposit; the value has a 2 decimals precision (i.e. if you need to set the vesting ratio == 2, then the input value for the contract must be 200). uint64fortressPeriod; - vesting duration, seconds. } struct Deposit { uint64startTime; - deposit vesting start time. uint64endTime; - vesting end time for the specified deposit. uint256 depositAmount; - esKNINE deposited amount. uint256 reservedAmount; - amount of KNINE tokens used as collateral for this deposit. uint256 lockedAmount; - amount of locked KNINE deposit at the RealYieldStaking contract. uint256 stakedAmount; - amount of non-locked KNINE deposit at the RealYieldStaking contract. uint256 potentialRewards; - the amount of KNINE tokens that the user would receive at the end of vesting. uint256 claimed; - claimed amount. Settings settings; - vesting parameters in the Settings struct format. Debt debt; - how much is in debt (Debt structure). } - the data is written upon deposit and upon recalculate method call, if it worked; exception - claim field is kept as current, does not change.

struct Debt { uint256 deposited; - how much esKNINE is in debt to be claimed. uint256 earned; - how much KNINE is in debt to be claimed. }

Events

event Deposited( address user, uint256 amount, uint256 potentialReward, uint64lockEnd ); - upon deposit call.

event Claimed(address user,uint256 amount); - upon claim call, returns:

  • The user's address,

  • How many KNINE tokens he claimed.

event Recalculated(address user,uint256 esKnineExcluded); - upon recalculate call, returns:

  • The user's address,

  • How many esKNINE tokens were excluded from his deposit.

event Paused(); - upon pause call.

event Unpaused(); - upon unpause call.

event Stopped(uint64endTime); - upon emergencyStop call, returns the emergency stop time of the contract.

event StockTokensWithdrawed(address token,uint256 amount); - upon withdrawStockTokens call; returns:

  • The token address,

  • Amount withdrawn from the contract.

event OnlyLockedChanged(bool status); - upon changeIsOnlyLocked call; returns the new bool status.

event BackingRatioChanged(uint64ratio); - upon setBackingRatio call; returns new backing ratio.

event VestingRatioChanged(uint64ratio); - upon setVestingRatio call; returns new rate.

event VestingPeriodChanged(uint64duration); - upon setVestingPeriod call; returns new vesting period value.

event DepositDebtTransfer(address user,uint256 debt); - triggered when the deposited esKNINE tokens (during the vesting pause) cannot be sent to the user and are put into debt to be claimed later.

event EarnedDebtTransfer(address user,uint256 debt); - triggered when the reward tokens (during the vesting pause) cannot be sent to the user and are put into debt to be claimed later.

Initializer Functions

initialize

function initialize(
address _knine,
address _esknine,
address _staking,
address _admin,
Settings calldata _settings
) public

For the initializer role only

Initializer function, not called after initialization.

Default admin Functions

emergencyStop

function emergencyStop() external

Stops the contract (permanently).

pause

function pause() external

Pause the contract

unpause

function unpause() external

Unpause the contract.

withdrawStockTokens

function withdrawStockTokens(
address token
) external

Withdraw tokens from the contract (any ERC20, except esKNINE)

Default admin and Admin Functions

changeIsOnlyLocked

function changeIsOnlyLocked() external

Change lockedOnly bool value.

setBackingRatio

function setBackingRatio(uint64value) external

Change the backingRatio value.

setVestingRatio

function setVestingRatio(uint64value) external 

Change the vestingRatio value.

setVestingPeriod

function setVestingPeriod(uint64value) external

Change the vestingPeriod value.

RealYieldStaking Interaction

recalculate

function recalculate(address user,uint256 unstakeAmount) external

When a non-locked deposit is unstaked at Real Yield Staking, if it was initially used as collateral, calculates currently undersecured esKNINE tokens in the vesting deposit and returns them to the user.

Public Functions

deposit

function deposit(uint256 amount) external

Deposit esKNINE tokens (creating new deposit or adding to an existing deposit).

claim

function claim() external

Claiming the converted KNINE tokens.

View Functions

pendingRewards

function pendingRewards(address user) public view returns (uint256)

Current amount of KNINE tokens available for withdrawal (including debt).

beforeDeposit

function beforeDeposit(address user) external view
returns (
uint256 esKnineBalance,
uint256 depositLimit,
Settings memory userSettings
)

Returns the current user's vesting limit:

  • esKNINE balance at user's wallet,

  • Vesting deposit limit - how much a user can deposit,

  • Vesting parameters that will be applied upon deposit.

depositInfo

function depositInfo(address user) external view
returns (
uint256 inVesting,
uint64vestingEnds,
uint256 reward,
uint256 lockedInStaking,
uint256 usedForVesting,
uint256 availableForVesting,
uint256 stakingEnds
)

Returns the deposit info by user address:

  • Deposited amount (upon deposit),

  • Vesting end time,

  • Available KNINE amount that can be claimed,

  • Real Yield Staking deposit amount according to the lockedOnly bool value,

  • Currently used collateral for the remaining esKNINE,

  • User's vesting limit,

  • Real Yield Staking lockup end time.

Last updated