PremiaStaking
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
Name | Type | Description |
---|---|---|
<none> | address | The 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
Name | Type | Description |
---|---|---|
amount | uint256 | amount 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
Name | Type | Description |
---|---|---|
rewards | uint256 | amount of tokens not yet distributed as rewards |
unstakeRewards | uint256 | amount 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
Name | Type | Description |
---|---|---|
<none> | uint256 | amount 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
Name | Type | Description |
---|---|---|
amount | uint256 | The amount of xPremia to stake |
period | uint64 | The lockup period (in seconds) |
deadline | uint256 | Deadline after which permit will fail |
v | uint8 | V |
r | bytes32 | R |
s | bytes32 | S |
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
Name | Type | Description |
---|---|---|
amount | uint256 | The amount of xPremia to stake |
period | uint64 | The lockup period (in seconds) |
updateLock
update vxPremia lock
function updateLock(uint64 period) external nonReentrant;
Parameters
Name | Type | Description |
---|---|---|
period | uint64 | The 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
Name | Type | Description |
---|---|---|
s | IPremiaStaking.SwapArgs | swap arguments |
stakePeriod | uint64 | The 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
Name | Type | Description |
---|---|---|
user | address | User for which to calculate pending rewards |
Returns
Name | Type | Description |
---|---|---|
reward | uint256 | amount of pending rewards from protocol fees (in REWARD_TOKEN) |
unstakeReward | uint256 | amount 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
Name | Type | Description |
---|---|---|
amount | uint256 | the amount of vxPremia to unstake |
getEarlyUnstakeFee
get early unstake fee for given user
function getEarlyUnstakeFee(address user) public view returns (uint256 feePercentage);
Parameters
Name | Type | Description |
---|---|---|
user | address | address of the user |
Returns
Name | Type | Description |
---|---|---|
feePercentage | uint256 | % 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
Name | Type | Description |
---|---|---|
amount | uint256 | quantity 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
Name | Type | Description |
---|---|---|
<none> | uint256 | The 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
Name | Type | Description |
---|---|---|
user | address | The user from which to query the stake amount |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The 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
Name | Type | Description |
---|---|---|
user | address | The _user for which the discount is for |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | Percentage 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
Name | Type | Description |
---|---|---|
user | address | The user address for which to get staking infos |
Returns
Name | Type | Description |
---|---|---|
<none> | PremiaStakingStorage.UserInfo | The 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
Name | Type | Description |
---|---|---|
amount | uint256 | pending withdrawal amount |
startDate | uint256 | start timestamp of withdrawal |
unlockDate | uint256 | timestamp 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
Name | Type | Description |
---|---|---|
stakeLevels | IPremiaStaking.StakeLevel[] | Stake levels Ex : 25e16 = -25% |
getStakePeriodMultiplier
Get stake period multiplier
function getStakePeriodMultiplier(uint256 period) public pure returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
period | uint256 | The duration (in seconds) for which tokens are locked |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The 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
Name | Type | Description |
---|---|---|
<none> | uint256 | amount of PREMIA available for withdrawal |
Structs
UpdateArgsInternal
struct UpdateArgsInternal {
address user;
uint256 balance;
uint256 oldPower;
uint256 newPower;
uint256 reward;
uint256 unstakeReward;
}