Skip to main content

SingleAssetStaking

SingleAssetStaking

stakingToken

contract IERC20 stakingToken

Stake

struct Stake {
uint256 amount;
uint256 end;
uint256 duration;
uint240 rate;
bool paid;
uint8 stakeType;
}

DropRoot

struct DropRoot {
bytes32 hash;
uint256 depth;
}

durations

uint256[] durations

rates

uint256[] rates

totalOutstanding

uint256 totalOutstanding

paused

bool paused

userStakes

mapping(address => struct SingleAssetStaking.Stake[]) userStakes

dropRoots

mapping(uint8 => struct SingleAssetStaking.DropRoot) dropRoots

USER_STAKE_TYPE

uint8 USER_STAKE_TYPE

MAX_STAKES

uint256 MAX_STAKES

transferAgent

address transferAgent

initialize

function initialize(address _stakingToken, uint256[] _durations, uint256[] _rates) external

Initialize the contracts, sets up durations, rates, and preApprover for preApproved contracts can only be called once

Parameters

NameTypeDescription
_stakingTokenaddressAddress of the token that we are staking
_durationsuint256[]Array of allowed durations in seconds
_ratesuint256[]Array of rates(0.3 is 30%) that correspond to the allowed durations in 1e18 precision

_setDurationRates

function _setDurationRates(uint256[] _durations, uint256[] _rates) internal

Validate and set the duration and corresponding rates, will emit events NewRate and NewDurations

_totalExpectedRewards

function _totalExpectedRewards(struct SingleAssetStaking.Stake[] stakes) internal view returns (uint256 total)

_totalExpected

function _totalExpected(struct SingleAssetStaking.Stake _stake) internal view returns (uint256)

_airDroppedStakeClaimed

function _airDroppedStakeClaimed(address account, uint8 stakeType) internal view returns (bool)

_findDurationRate

function _findDurationRate(uint256 duration) internal view returns (uint240)

_stake

function _stake(address staker, uint8 stakeType, uint256 duration, uint240 rate, uint256 amount) internal

Internal staking function will insert the stake into the stakes array and verify we have enough to pay off stake + reward

Parameters

NameTypeDescription
stakeraddressAddress of the staker
stakeTypeuint8Number that represent the type of the stake, 0 is user initiated all else is currently preApproved
durationuint256Number of seconds this stake will be held for
rateuint240Rate(0.3 is 30%) of reward for this stake in 1e18, uint240 = to fit the bool and type in struct Stake
amountuint256Number of tokens to stake in 1e18

_stakeWithChecks

function _stakeWithChecks(address staker, uint256 amount, uint256 duration) internal

requireLiquidity

modifier requireLiquidity()

getAllDurations

function getAllDurations() external view returns (uint256[])

getAllRates

function getAllRates() external view returns (uint256[])

getAllStakes

function getAllStakes(address account) external view returns (struct SingleAssetStaking.Stake[])

Return all the stakes paid and unpaid for a given user

Parameters

NameTypeDescription
accountaddressAddress of the account that we want to look up

durationRewardRate

function durationRewardRate(uint256 _duration) external view returns (uint256)

Find the rate that corresponds to a given duration

Parameters

NameTypeDescription
_durationuint256Number of seconds

airDroppedStakeClaimed

function airDroppedStakeClaimed(address account, uint8 stakeType) external view returns (bool)

Has the airdropped stake already been claimed

totalStaked

function totalStaked(address account) external view returns (uint256 total)

Calculate all the staked value a user has put into the contract, rewards not included

Parameters

NameTypeDescription
accountaddressAddress of the account that we want to look up

totalExpectedRewards

function totalExpectedRewards(address account) external view returns (uint256)

Calculate all the rewards a user can expect to receive.

Parameters

NameTypeDescription
accountaddressAddress of the account that we want to look up

totalCurrentHoldings

function totalCurrentHoldings(address account) external view returns (uint256 total)

Calculate all current holdings of a user: staked value + prorated rewards

Parameters

NameTypeDescription
accountaddressAddress of the account that we want to look up

airDroppedStake

function airDroppedStake(uint256 index, uint8 stakeType, uint256 duration, uint256 rate, uint256 amount, bytes32[] merkleProof) external

Make a preapproved stake for the user, this is a presigned voucher that the user can redeem either from an airdrop or a compensation program. Only 1 of each type is allowed per user. The proof must match the root hash

Parameters

NameTypeDescription
indexuint256Number that is zero base index of the stake in the payout entry
stakeTypeuint8Number that represent the type of the stake, must not be 0 which is user stake
durationuint256Number of seconds this stake will be held for
rateuint256Rate(0.3 is 30%) of reward for this stake in 1e18, uint240 to fit the bool and type in struct Stake
amountuint256Number of tokens to stake in 1e18
merkleProofbytes32[]Array of proofs for that amount

stake

function stake(uint256 amount, uint256 duration) external

Stake an approved amount of staking token into the contract. User must have already approved the contract for specified amount.

Parameters

NameTypeDescription
amountuint256Number of tokens to stake in 1e18
durationuint256Number of seconds this stake will be held for

stakeWithSender

function stakeWithSender(address staker, uint256 amount, uint256 duration) external returns (bool)

Stake an approved amount of staking token into the contract. This function can only be called by OGN token contract.

Parameters

NameTypeDescription
stakeraddressAddress of the account that is creating the stake
amountuint256Number of tokens to stake in 1e18
durationuint256Number of seconds this stake will be held for

exit

function exit() external

Exit out of all possible stakes

transferStakes

function transferStakes(address _frmAccount, address _dstAccount, bytes32 r, bytes32 s, uint8 v) external

Use to transfer all the stakes of an account in the case that the account is compromised Requires access to both the account itself and the transfer agent

Parameters

NameTypeDescription
_frmAccountaddressthe address to transfer from
_dstAccountaddressthe address to transfer to(must be a clean address with no stakes)
rbytes32r portion of the signature by the transfer agent
sbytes32s portion of the signature
vuint8v portion of the signature

setPaused

function setPaused(bool _paused) external

setDurationRates

function setDurationRates(uint256[] _durations, uint256[] _rates) external

Set new durations and rates will not effect existing stakes

Parameters

NameTypeDescription
_durationsuint256[]Array of durations in seconds
_ratesuint256[]Array of rates that corresponds to the durations (0.01 is 1%) in 1e18

setTransferAgent

function setTransferAgent(address _agent) external

Set the agent that will authorize transfers

Parameters

NameTypeDescription
_agentaddressAddress of agent

setAirDropRoot

function setAirDropRoot(uint8 _stakeType, bytes32 _rootHash, uint256 _proofDepth) external

Set air drop root for a specific stake type

Parameters

NameTypeDescription
_stakeTypeuint8Type of staking must be greater than 0
_rootHashbytes32Root hash of the Merkle Tree
_proofDepthuint256Depth of the Merklke Tree

Staked

event Staked(address user, uint256 amount, uint256 duration, uint256 rate)

Withdrawn

event Withdrawn(address user, uint256 amount, uint256 stakedAmount)

Paused

event Paused(address user, bool yes)

NewDurations

event NewDurations(address user, uint256[] durations)

NewRates

event NewRates(address user, uint256[] rates)

NewAirDropRootHash

event NewAirDropRootHash(uint8 stakeType, bytes32 rootHash, uint256 proofDepth)

StakesTransfered

event StakesTransfered(address fromUser, address toUser, uint256 numStakes)