View Source: contracts/libraries/StakingPoolLibV1.sol
StakingPoolLibV1
- getInfoInternal(IStore s, bytes32 key, address you)
- getPoolStakeBalanceInternal(IStore s, bytes32 key)
- getPoolCumulativeDeposits(IStore s, bytes32 key)
- getAccountStakingBalanceInternal(IStore s, bytes32 key, address account)
- getTotalBlocksSinceLastRewardInternal(IStore s, bytes32 key, address account)
- canWithdrawFromBlockHeightInternal(IStore s, bytes32 key, address account)
- getLastDepositHeight(IStore s, bytes32 key, address account)
- getLastRewardHeight(IStore s, bytes32 key, address account)
- calculateRewardsInternal(IStore s, bytes32 key, address account)
- withdrawRewardsInternal(IStore s, bytes32 key, address account)
- depositInternal(IStore s, bytes32 key, uint256 amount)
- withdrawInternal(IStore s, bytes32 key, uint256 amount)
Gets the info of a given staking pool by key
function getInfoInternal(IStore s, bytes32 key, address you) external view
returns(name string, addresses address[], values uint256[])
Arguments
Name | Type | Description |
---|---|---|
s | IStore | Specify the store instance |
key | bytes32 | Provide the staking pool key to fetch info for |
you | address | Specify the address to customize the info for |
Source Code
function getInfoInternal(
IStore s,
bytes32 key,
address you
)
external
view
returns (
string memory name,
address[] memory addresses,
uint256[] memory values
)
{
addresses = new address[](4);
values = new uint256[](15);
name = s.getStringByKeys(StakingPoolCoreLibV1.NS_POOL, key);
addresses[0] = s.getStakingTokenAddressInternal(key);
addresses[1] = s.getStakingTokenStablecoinPairAddressInternal(key);
addresses[2] = s.getRewardTokenAddressInternal(key);
addresses[3] = s.getRewardTokenStablecoinPairAddressInternal(key);
values[0] = s.getTotalStaked(key);
values[1] = s.getTarget(key);
values[2] = s.getMaximumStakeInternal(key);
values[3] = getPoolStakeBalanceInternal(s, key);
values[4] = getPoolCumulativeDeposits(s, key);
values[5] = s.getRewardPerBlock(key);
values[6] = s.getRewardPlatformFee(key);
values[7] = s.getLockupPeriodInBlocks(key);
values[8] = s.getRewardTokenBalance(key);
values[9] = getAccountStakingBalanceInternal(s, key, you);
values[10] = getTotalBlocksSinceLastRewardInternal(s, key, you);
values[11] = calculateRewardsInternal(s, key, you);
values[12] = canWithdrawFromBlockHeightInternal(s, key, you);
values[13] = getLastDepositHeight(s, key, you);
values[14] = getLastRewardHeight(s, key, you);
}
function getPoolStakeBalanceInternal(IStore s, bytes32 key) public view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 |
Source Code
function getPoolStakeBalanceInternal(IStore s, bytes32 key) public view returns (uint256) {
uint256 totalStake = s.getUintByKeys(StakingPoolCoreLibV1.NS_POOL_STAKING_TOKEN_BALANCE, key);
return totalStake;
}
function getPoolCumulativeDeposits(IStore s, bytes32 key) public view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 |
Source Code
function getPoolCumulativeDeposits(IStore s, bytes32 key) public view returns (uint256) {
uint256 totalStake = s.getUintByKeys(StakingPoolCoreLibV1.NS_POOL_CUMULATIVE_STAKING_AMOUNT, key);
return totalStake;
}
function getAccountStakingBalanceInternal(IStore s, bytes32 key, address account) public view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 | |
account | address |
Source Code
function getAccountStakingBalanceInternal(
IStore s,
bytes32 key,
address account
) public view returns (uint256) {
return s.getUintByKeys(StakingPoolCoreLibV1.NS_POOL_STAKING_TOKEN_BALANCE, key, account);
}
function getTotalBlocksSinceLastRewardInternal(IStore s, bytes32 key, address account) public view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 | |
account | address |
Source Code
function getTotalBlocksSinceLastRewardInternal(
IStore s,
bytes32 key,
address account
) public view returns (uint256) {
uint256 from = getLastRewardHeight(s, key, account);
if (from == 0) {
return 0;
}
return block.number - from;
}
function canWithdrawFromBlockHeightInternal(IStore s, bytes32 key, address account) public view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 | |
account | address |
Source Code
function canWithdrawFromBlockHeightInternal(
IStore s,
bytes32 key,
address account
) public view returns (uint256) {
uint256 lastDepositHeight = getLastDepositHeight(s, key, account);
uint256 lockupPeriod = s.getLockupPeriodInBlocks(key);
return lastDepositHeight + lockupPeriod;
}
function getLastDepositHeight(IStore s, bytes32 key, address account) public view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 | |
account | address |
Source Code
function getLastDepositHeight(
IStore s,
bytes32 key,
address account
) public view returns (uint256) {
return s.getUintByKeys(StakingPoolCoreLibV1.NS_POOL_DEPOSIT_HEIGHTS, key, account);
}
function getLastRewardHeight(IStore s, bytes32 key, address account) public view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 | |
account | address |
Source Code
function getLastRewardHeight(
IStore s,
bytes32 key,
address account
) public view returns (uint256) {
return s.getUintByKeys(StakingPoolCoreLibV1.NS_POOL_REWARD_HEIGHTS, key, account);
}
function calculateRewardsInternal(IStore s, bytes32 key, address account) public view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 | |
account | address |
Source Code
function calculateRewardsInternal(
IStore s,
bytes32 key,
address account
) public view returns (uint256) {
uint256 totalBlocks = getTotalBlocksSinceLastRewardInternal(s, key, account);
if (totalBlocks == 0) {
return 0;
}
uint256 rewardPerBlock = s.getRewardPerBlock(key);
uint256 myStake = getAccountStakingBalanceInternal(s, key, account);
return (myStake * rewardPerBlock * totalBlocks) / 1 ether;
}
function withdrawRewardsInternal(IStore s, bytes32 key, address account) public nonpayable
returns(rewardToken address, rewards uint256, platformFee uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 | |
account | address |
Source Code
function withdrawRewardsInternal(
IStore s,
bytes32 key,
address account
)
public
returns (
address rewardToken,
uint256 rewards,
uint256 platformFee
)
{
rewards = calculateRewardsInternal(s, key, account);
s.setUintByKeys(StakingPoolCoreLibV1.NS_POOL_REWARD_HEIGHTS, key, account, block.number);
if (rewards == 0) {
return (address(0), 0, 0);
}
rewardToken = s.getAddressByKeys(StakingPoolCoreLibV1.NS_POOL_REWARD_TOKEN, key);
// Update (decrease) the balance of reward token
s.subtractUintByKeys(StakingPoolCoreLibV1.NS_POOL_REWARD_TOKEN_BALANCE, key, rewards);
// Update total rewards given
s.addUintByKeys(StakingPoolCoreLibV1.NS_POOL_TOTAL_REWARD_GIVEN, key, account, rewards); // To this account
s.addUintByKeys(StakingPoolCoreLibV1.NS_POOL_TOTAL_REWARD_GIVEN, key, rewards); // To everyone
platformFee = (rewards * s.getRewardPlatformFee(key)) / ProtoUtilV1.MULTIPLIER;
IERC20(rewardToken).ensureTransfer(msg.sender, rewards - platformFee);
IERC20(rewardToken).ensureTransfer(s.getTreasury(), rewards);
}
function depositInternal(IStore s, bytes32 key, uint256 amount) external nonpayable
returns(stakingToken address)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 | |
amount | uint256 |
Source Code
function depositInternal(
IStore s,
bytes32 key,
uint256 amount
) external returns (address stakingToken) {
require(key > 0, "Invalid key");
require(amount > 0, "Enter an amount");
require(amount <= s.getMaximumStakeInternal(key), "Stake too high");
require(amount <= s.getAvailableToStakeInternal(key), "Target achieved or cap exceeded");
stakingToken = s.getStakingTokenAddressInternal(key);
// First withdraw your rewards
withdrawRewardsInternal(s, key, msg.sender);
// Individual state
s.addUintByKeys(StakingPoolCoreLibV1.NS_POOL_STAKING_TOKEN_BALANCE, key, msg.sender, amount);
s.setUintByKeys(StakingPoolCoreLibV1.NS_POOL_DEPOSIT_HEIGHTS, key, msg.sender, block.number);
// Global state
s.addUintByKeys(StakingPoolCoreLibV1.NS_POOL_STAKING_TOKEN_BALANCE, key, amount);
s.addUintByKeys(StakingPoolCoreLibV1.NS_POOL_CUMULATIVE_STAKING_AMOUNT, key, amount);
IERC20(stakingToken).ensureTransferFrom(msg.sender, address(this), amount);
}
function withdrawInternal(IStore s, bytes32 key, uint256 amount) external nonpayable
returns(stakingToken address)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 | |
amount | uint256 |
Source Code
function withdrawInternal(
IStore s,
bytes32 key,
uint256 amount
) external returns (address stakingToken) {
require(key > 0, "Invalid key");
require(amount > 0, "Enter an amount");
require(getAccountStakingBalanceInternal(s, key, msg.sender) >= amount, "Insufficient balance");
require(block.number > canWithdrawFromBlockHeightInternal(s, key, msg.sender), "Withdrawal too early");
stakingToken = s.getStakingTokenAddressInternal(key);
// First withdraw your rewards
withdrawRewardsInternal(s, key, msg.sender);
// Individual state
s.subtractUintByKeys(StakingPoolCoreLibV1.NS_POOL_STAKING_TOKEN_BALANCE, key, msg.sender, amount);
// Global state
s.subtractUintByKeys(StakingPoolCoreLibV1.NS_POOL_STAKING_TOKEN_BALANCE, key, amount);
IERC20(stakingToken).ensureTransfer(msg.sender, amount);
}
- AaveStrategy
- AccessControl
- AccessControlLibV1
- Address
- BaseLibV1
- BokkyPooBahsDateTimeLibrary
- BondPool
- BondPoolBase
- BondPoolLibV1
- CompoundStrategy
- Context
- Controller
- Cover
- CoverBase
- CoverLibV1
- CoverProvision
- CoverReassurance
- CoverStake
- CoverUtilV1
- cxToken
- cxTokenFactory
- cxTokenFactoryLibV1
- Destroyable
- ERC165
- ERC20
- FakeAaveLendingPool
- FakeCompoundERC20Delegator
- FakeRecoverable
- FakeStore
- FakeToken
- FakeUniswapPair
- FakeUniswapV2FactoryLike
- FakeUniswapV2PairLike
- FakeUniswapV2RouterLike
- Finalization
- Governance
- GovernanceUtilV1
- IAaveV2LendingPoolLike
- IAccessControl
- IBondPool
- IClaimsProcessor
- ICommission
- ICompoundERC20DelegatorLike
- ICover
- ICoverProvision
- ICoverReassurance
- ICoverStake
- ICxToken
- ICxTokenFactory
- IERC165
- IERC20
- IERC20Detailed
- IERC20Metadata
- IERC3156FlashBorrower
- IERC3156FlashLender
- IFinalization
- IGovernance
- ILendingStrategy
- IMember
- IPausable
- IPolicy
- IPolicyAdmin
- IPriceDiscovery
- IProtocol
- IRecoverable
- IReporter
- IResolution
- IResolvable
- IStakingPools
- IStore
- IUniswapV2FactoryLike
- IUniswapV2PairLike
- IUniswapV2RouterLike
- IUnstakable
- IVault
- IVaultFactory
- IWitness
- LiquidityEngine
- MaliciousToken
- Migrations
- MockCxToken
- MockCxTokenPolicy
- MockCxTokenStore
- MockProcessorStore
- MockProcessorStoreLib
- MockProtocol
- MockStore
- MockVault
- NTransferUtilV2
- NTransferUtilV2Intermediate
- Ownable
- Pausable
- Policy
- PolicyAdmin
- PolicyHelperV1
- PriceDiscovery
- PriceLibV1
- Processor
- ProtoBase
- Protocol
- ProtoUtilV1
- Recoverable
- ReentrancyGuard
- RegistryLibV1
- Reporter
- Resolution
- Resolvable
- RoutineInvokerLibV1
- SafeERC20
- StakingPoolBase
- StakingPoolCoreLibV1
- StakingPoolInfo
- StakingPoolLibV1
- StakingPoolReward
- StakingPools
- Store
- StoreBase
- StoreKeyUtil
- StrategyLibV1
- Strings
- Unstakable
- ValidationLibV1
- Vault
- VaultBase
- VaultFactory
- VaultFactoryLibV1
- VaultLibV1
- WithFlashLoan
- Witness