PremiaStaking

Git Source

Inherits: IPremiaStaking, OFT, ReentrancyGuard

State Variables

PREMIA

address internal immutable PREMIA;

REWARD_TOKEN

address internal immutable REWARD_TOKEN;

EXCHANGE_HELPER

address internal immutable EXCHANGE_HELPER;

DECAY_RATE

UD60x18 internal constant DECAY_RATE = UD60x18.wrap(270000000000);

MAX_PERIOD

uint64 internal constant MAX_PERIOD = 4 * 365 days;

ACC_REWARD_PRECISION

uint256 internal constant ACC_REWARD_PRECISION = 1e30;

MAX_CONTRACT_DISCOUNT

uint256 internal constant MAX_CONTRACT_DISCOUNT = 0.3e18;

WITHDRAWAL_DELAY

uint256 internal constant WITHDRAWAL_DELAY = 10 days;

BPS_CONVERSION

uint256 internal constant BPS_CONVERSION = 1e14;

Functions

constructor

constructor(address lzEndpoint, address premia, address rewardToken, address exchangeHelper) OFT(lzEndpoint);

_beforeTokenTransfer

function _beforeTokenTransfer(address from, address to, uint256) internal virtual override;

getRewardToken

Returns the reward token address

function getRewardToken() external view returns (address);

Returns

NameTypeDescription
<none>addressThe reward token address

estimateSendFee

function estimateSendFee(
    uint16 dstChainId,
    bytes memory toAddress,
    uint256 amount,
    bool useZro,
    bytes memory adapterParams
) public view virtual override(OFTCore, IOFTCore) returns (uint256 nativeFee, uint256 zroFee);

_send

function _send(
    address from,
    uint16 dstChainId,
    bytes memory,
    uint256 amount,
    address payable refundAddress,
    address zroPaymentAddress,
    bytes memory adapterParams
) internal virtual override;

_sendAck

function _sendAck(uint16 srcChainId, bytes memory srcAddress, uint64, bytes memory payload) internal virtual override;

_creditTo

function _creditTo(address toAddress, uint256 amount, uint64 stakePeriod, uint64 creditLockedUntil, bool bridge)
    internal;

addRewards

add premia tokens as available tokens to be distributed as rewards

function addRewards(uint256 amount) external nonReentrant;

Parameters

NameTypeDescription
amountuint256amount of premia tokens to add as rewards

getAvailableRewards

get amount of tokens that have not yet been distributed as rewards

function getAvailableRewards() external view returns (uint256 rewards, uint256 unstakeRewards);

Returns

NameTypeDescription
rewardsuint256amount of tokens not yet distributed as rewards
unstakeRewardsuint256amount of PREMIA not yet claimed from early unstake fees

getPendingRewards

get pending amount of tokens to be distributed as rewards to stakers

function getPendingRewards() public view returns (uint256);

Returns

NameTypeDescription
<none>uint256amount of tokens pending to be distributed as rewards

_updateRewards

function _updateRewards() internal;

stakeWithPermit

Stake using IERC2612 permit

function stakeWithPermit(uint256 amount, uint64 period, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
    external
    nonReentrant;

Parameters

NameTypeDescription
amountuint256The amount of xPremia to stake
perioduint64The lockup period (in seconds)
deadlineuint256Deadline after which permit will fail
vuint8V
rbytes32R
sbytes32S

stake

Lockup xPremia for protocol fee discounts Longer period of locking will apply a multiplier on the amount staked, in the fee discount calculation

function stake(uint256 amount, uint64 period) external nonReentrant;

Parameters

NameTypeDescription
amountuint256The amount of xPremia to stake
perioduint64The lockup period (in seconds)

updateLock

update vxPremia lock

function updateLock(uint64 period) external nonReentrant;

Parameters

NameTypeDescription
perioduint64The new lockup period (in seconds)

harvestAndStake

harvest rewards, convert to PREMIA using exchange helper, and stake

function harvestAndStake(IPremiaStaking.SwapArgs calldata s, uint64 stakePeriod) external nonReentrant;

Parameters

NameTypeDescription
sIPremiaStaking.SwapArgsswap arguments
stakePerioduint64The lockup period (in seconds)

_calculateWeightedAverage

function _calculateWeightedAverage(uint256 A, uint256 B, uint256 weightA, uint256 weightB)
    internal
    pure
    returns (uint256);

_stake

function _stake(address toAddress, uint256 amount, uint64 stakePeriod) internal;

getPendingUserRewards

Get pending rewards amount, including pending pool update

function getPendingUserRewards(address user) external view returns (uint256 reward, uint256 unstakeReward);

Parameters

NameTypeDescription
useraddressUser for which to calculate pending rewards

Returns

NameTypeDescription
rewarduint256amount of pending rewards from protocol fees (in REWARD_TOKEN)
unstakeRewarduint256amount of pending rewards from early unstake fees (in PREMIA)

harvest

Harvest rewards directly to user wallet

function harvest() external nonReentrant;

_harvest

function _harvest(address account) internal returns (uint256 amount);

_updateTotalPower

function _updateTotalPower(PremiaStakingStorage.Layout storage l, uint256 oldUserPower, uint256 newUserPower)
    internal;

_beforeUnstake

function _beforeUnstake(address user, uint256 amount) internal virtual;

earlyUnstake

unstake tokens before end of the lock period, for a fee

function earlyUnstake(uint256 amount) external nonReentrant;

Parameters

NameTypeDescription
amountuint256the amount of vxPremia to unstake

getEarlyUnstakeFee

get early unstake fee for given user

function getEarlyUnstakeFee(address user) public view returns (uint256 feePercentage);

Parameters

NameTypeDescription
useraddressaddress of the user

Returns

NameTypeDescription
feePercentageuint256% fee to pay for early unstake (1e18 = 100%)

getEarlyUnstakeFeeBPS

function getEarlyUnstakeFeeBPS(address user) external view returns (uint256 feePercentageBPS);

startWithdraw

Initiate the withdrawal process by burning xPremia, starting the delay period

function startWithdraw(uint256 amount) external nonReentrant;

Parameters

NameTypeDescription
amountuint256quantity of xPremia to unstake

_startWithdraw

function _startWithdraw(
    PremiaStakingStorage.Layout storage l,
    PremiaStakingStorage.UserInfo storage u,
    uint256 amount,
    uint256 fee
) internal;

withdraw

Withdraw underlying premia

function withdraw() external nonReentrant;

getTotalPower

Return the total power across all users (applying the bonus from lockup period chosen)

function getTotalPower() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256The total power across all users

getUserPower

Calculate the stake amount of a user, after applying the bonus from the lockup period chosen

function getUserPower(address user) external view returns (uint256);

Parameters

NameTypeDescription
useraddressThe user from which to query the stake amount

Returns

NameTypeDescription
<none>uint256The user stake amount after applying the bonus

getDiscount

Calculate the % of fee discount for user, based on his stake

function getDiscount(address user) public view returns (uint256);

Parameters

NameTypeDescription
useraddressThe _user for which the discount is for

Returns

NameTypeDescription
<none>uint256Percentage of protocol fee discount Ex : 1e17 = 10% fee discount

getDiscountBPS

function getDiscountBPS(address user) external view returns (uint256);

getUserInfo

Get staking infos of a user

function getUserInfo(address user) external view returns (PremiaStakingStorage.UserInfo memory);

Parameters

NameTypeDescription
useraddressThe user address for which to get staking infos

Returns

NameTypeDescription
<none>PremiaStakingStorage.UserInfoThe staking infos of the user

getPendingWithdrawals

Return the total amount of premia pending withdrawal

function getPendingWithdrawals() external view returns (uint256);

getPendingWithdrawal

get pending withdrawal data of a user

function getPendingWithdrawal(address user)
    external
    view
    returns (uint256 amount, uint256 startDate, uint256 unlockDate);

Returns

NameTypeDescription
amountuint256pending withdrawal amount
startDateuint256start timestamp of withdrawal
unlockDateuint256timestamp at which withdrawal becomes available

_decay

function _decay(uint256 pendingRewards, uint256 oldTimestamp, uint256 newTimestamp) internal pure returns (uint256);

getStakeLevels

Get stake levels

function getStakeLevels() public pure returns (IPremiaStaking.StakeLevel[] memory stakeLevels);

Returns

NameTypeDescription
stakeLevelsIPremiaStaking.StakeLevel[]Stake levels Ex : 25e16 = -25%

getStakePeriodMultiplier

Get stake period multiplier

function getStakePeriodMultiplier(uint256 period) public pure returns (uint256);

Parameters

NameTypeDescription
perioduint256The duration (in seconds) for which tokens are locked

Returns

NameTypeDescription
<none>uint256The multiplier for this staking period Ex : 2e18 = x2

getStakePeriodMultiplierBPS

getStakePeriodMultiplier is preferred as it is more precise. This function is kept for backwards compatibility.

function getStakePeriodMultiplierBPS(uint256 period) external pure returns (uint256);

_calculateUserPower

function _calculateUserPower(uint256 balance, uint64 stakePeriod) internal pure returns (uint256);

_calculateReward

function _calculateReward(uint256 accRewardPerShare, uint256 power, uint256 rewardDebt)
    internal
    pure
    returns (uint256);

_creditRewards

function _creditRewards(
    PremiaStakingStorage.Layout storage l,
    PremiaStakingStorage.UserInfo storage u,
    address user,
    uint256 reward,
    uint256 unstakeReward
) internal;

_getInitialUpdateArgsInternal

function _getInitialUpdateArgsInternal(
    PremiaStakingStorage.Layout storage l,
    PremiaStakingStorage.UserInfo storage u,
    address user
) internal view returns (UpdateArgsInternal memory);

_calculateRewardDebt

function _calculateRewardDebt(uint256 accRewardPerShare, uint256 power) internal pure returns (uint256);

_updateUser

function _updateUser(
    PremiaStakingStorage.Layout storage l,
    PremiaStakingStorage.UserInfo storage u,
    UpdateArgsInternal memory args
) internal;

getAvailablePremiaAmount

get the amount of PREMIA available for withdrawal

function getAvailablePremiaAmount() public view returns (uint256);

Returns

NameTypeDescription
<none>uint256amount of PREMIA available for withdrawal

Structs

UpdateArgsInternal

struct UpdateArgsInternal {
    address user;
    uint256 balance;
    uint256 oldPower;
    uint256 newPower;
    uint256 reward;
    uint256 unstakeReward;
}