View Source: contracts/libraries/StakingPoolCoreLibV1.sol
StakingPoolCoreLibV1
Constants & Variables
bytes32 public constant NS_POOL;
bytes32 public constant NS_POOL_NAME;
bytes32 public constant NS_POOL_LOCKED;
bytes32 public constant NS_POOL_LOCKUP_PERIOD_IN_BLOCKS;
bytes32 public constant NS_POOL_STAKING_TARGET;
bytes32 public constant NS_POOL_CUMULATIVE_STAKING_AMOUNT;
bytes32 public constant NS_POOL_STAKING_TOKEN;
bytes32 public constant NS_POOL_STAKING_TOKEN_UNI_STABLECOIN_PAIR;
bytes32 public constant NS_POOL_REWARD_TOKEN;
bytes32 public constant NS_POOL_REWARD_TOKEN_UNI_STABLECOIN_PAIR;
bytes32 public constant NS_POOL_STAKING_TOKEN_BALANCE;
bytes32 public constant NS_POOL_REWARD_TOKEN_DEPOSITS;
bytes32 public constant NS_POOL_REWARD_TOKEN_DISTRIBUTION;
bytes32 public constant NS_POOL_MAX_STAKE;
bytes32 public constant NS_POOL_REWARD_PER_BLOCK;
bytes32 public constant NS_POOL_REWARD_PLATFORM_FEE;
bytes32 public constant NS_POOL_REWARD_TOKEN_BALANCE;
bytes32 public constant NS_POOL_DEPOSIT_HEIGHTS;
bytes32 public constant NS_POOL_REWARD_HEIGHTS;
bytes32 public constant NS_POOL_TOTAL_REWARD_GIVEN;
- getAvailableToStakeInternal(IStore s, bytes32 key)
- getTarget(IStore s, bytes32 key)
- getRewardPlatformFee(IStore s, bytes32 key)
- getTotalStaked(IStore s, bytes32 key)
- getRewardPerBlock(IStore s, bytes32 key)
- getLockupPeriodInBlocks(IStore s, bytes32 key)
- getRewardTokenBalance(IStore s, bytes32 key)
- getMaximumStakeInternal(IStore s, bytes32 key)
- getStakingTokenAddressInternal(IStore s, bytes32 key)
- getStakingTokenStablecoinPairAddressInternal(IStore s, bytes32 key)
- getRewardTokenAddressInternal(IStore s, bytes32 key)
- getRewardTokenStablecoinPairAddressInternal(IStore s, bytes32 key)
- ensureValidStakingPool(IStore s, bytes32 key)
- validateAddOrEditPoolInternal(IStore s, bytes32 key, string name, address[] addresses, uint256[] values)
- addOrEditPoolInternal(IStore s, bytes32 key, string name, address[] addresses, uint256[] values)
- _updatePoolValues(IStore s, bytes32 key, uint256[] values)
- _initializeNewPool(IStore s, bytes32 key, address[] addresses)
Reports the remaining amount of tokens that can be staked in this pool
function getAvailableToStakeInternal(IStore s, bytes32 key) external view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 |
Source Code
function getAvailableToStakeInternal(IStore s, bytes32 key) external view returns (uint256) {
uint256 totalStaked = getTotalStaked(s, key);
uint256 target = getTarget(s, key);
if (totalStaked >= target) {
return 0;
}
return target - totalStaked;
}
function getTarget(IStore s, bytes32 key) public view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 |
Source Code
function getTarget(IStore s, bytes32 key) public view returns (uint256) {
return s.getUintByKeys(NS_POOL_STAKING_TARGET, key);
}
function getRewardPlatformFee(IStore s, bytes32 key) external view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 |
Source Code
function getRewardPlatformFee(IStore s, bytes32 key) external view returns (uint256) {
return s.getUintByKeys(NS_POOL_REWARD_PLATFORM_FEE, key);
}
function getTotalStaked(IStore s, bytes32 key) public view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 |
Source Code
function getTotalStaked(IStore s, bytes32 key) public view returns (uint256) {
return s.getUintByKeys(NS_POOL_CUMULATIVE_STAKING_AMOUNT, key);
}
function getRewardPerBlock(IStore s, bytes32 key) external view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 |
Source Code
function getRewardPerBlock(IStore s, bytes32 key) external view returns (uint256) {
return s.getUintByKeys(NS_POOL_REWARD_PER_BLOCK, key);
}
function getLockupPeriodInBlocks(IStore s, bytes32 key) external view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 |
Source Code
function getLockupPeriodInBlocks(IStore s, bytes32 key) external view returns (uint256) {
return s.getUintByKeys(NS_POOL_LOCKUP_PERIOD_IN_BLOCKS, key);
}
function getRewardTokenBalance(IStore s, bytes32 key) external view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 |
Source Code
function getRewardTokenBalance(IStore s, bytes32 key) external view returns (uint256) {
return s.getUintByKeys(NS_POOL_REWARD_TOKEN_BALANCE, key);
}
function getMaximumStakeInternal(IStore s, bytes32 key) external view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 |
Source Code
function getMaximumStakeInternal(IStore s, bytes32 key) external view returns (uint256) {
return s.getUintByKeys(NS_POOL_MAX_STAKE, key);
}
function getStakingTokenAddressInternal(IStore s, bytes32 key) external view
returns(address)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 |
Source Code
function getStakingTokenAddressInternal(IStore s, bytes32 key) external view returns (address) {
return s.getAddressByKeys(NS_POOL_STAKING_TOKEN, key);
}
function getStakingTokenStablecoinPairAddressInternal(IStore s, bytes32 key) external view
returns(address)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 |
Source Code
function getStakingTokenStablecoinPairAddressInternal(IStore s, bytes32 key) external view returns (address) {
return s.getAddressByKeys(NS_POOL_STAKING_TOKEN_UNI_STABLECOIN_PAIR, key);
}
function getRewardTokenAddressInternal(IStore s, bytes32 key) external view
returns(address)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 |
Source Code
function getRewardTokenAddressInternal(IStore s, bytes32 key) external view returns (address) {
return s.getAddressByKeys(NS_POOL_REWARD_TOKEN, key);
}
function getRewardTokenStablecoinPairAddressInternal(IStore s, bytes32 key) external view
returns(address)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 |
Source Code
function getRewardTokenStablecoinPairAddressInternal(IStore s, bytes32 key) external view returns (address) {
return s.getAddressByKeys(NS_POOL_REWARD_TOKEN_UNI_STABLECOIN_PAIR, key);
}
function ensureValidStakingPool(IStore s, bytes32 key) external view
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 |
Source Code
function ensureValidStakingPool(IStore s, bytes32 key) external view {
require(s.getBoolByKeys(NS_POOL, key), "Pool invalid or closed");
}
function validateAddOrEditPoolInternal(IStore s, bytes32 key, string name, address[] addresses, uint256[] values) public view
returns(bool)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 | |
name | string | |
addresses | address[] | |
values | uint256[] |
Source Code
function validateAddOrEditPoolInternal(
IStore s,
bytes32 key,
string memory name,
address[] memory addresses,
uint256[] memory values
) public view returns (bool) {
require(key > 0, "Invalid key");
bool exists = s.getBoolByKeys(NS_POOL, key);
if (exists == false) {
require(bytes(name).length > 0, "Invalid name");
require(addresses[0] != address(0), "Invalid staking token");
// require(addresses[1] != address(0), "Invalid staking token pair"); // A POD doesn't have any pair with stablecion
require(addresses[2] != address(0), "Invalid reward token");
require(addresses[3] != address(0), "Invalid reward token pair");
require(values[4] > 0, "Provide lockup period in blocks");
require(values[5] > 0, "Provide reward token balance");
require(values[3] > 0, "Provide reward per block");
require(values[0] > 0, "Please provide staking target");
}
return exists;
}
Adds or edits the pool by key
function addOrEditPoolInternal(IStore s, bytes32 key, string name, address[] addresses, uint256[] values) external nonpayable
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 | Enter the key of the pool you want to create or edit |
name | string | Enter a name for this pool |
addresses | address[] | [0] stakingToken The token which is staked in this pool |
values | uint256[] | [0] stakingTarget Specify the target amount in the staking token. You can not exceed the target. |
Source Code
function addOrEditPoolInternal(
IStore s,
bytes32 key,
string memory name,
address[] memory addresses,
uint256[] memory values
) external {
bool poolExists = validateAddOrEditPoolInternal(s, key, name, addresses, values);
if (poolExists == false) {
_initializeNewPool(s, key, addresses);
}
if (bytes(name).length > 0) {
s.setStringByKeys(NS_POOL, key, name);
}
_updatePoolValues(s, key, values);
// If `values[5] --> rewardTokenDeposit` is specified, the contract
// pulls the reward tokens to this contract address
if (values[5] > 0) {
IERC20(addresses[2]).ensureTransferFrom(msg.sender, address(this), values[5]);
}
}
Updates the values of a staking pool by the given key
function _updatePoolValues(IStore s, bytes32 key, uint256[] values) private nonpayable
Arguments
Name | Type | Description |
---|---|---|
s | IStore | Provide an instance of the store |
key | bytes32 | Enter the key of the pool you want to create or edit |
values | uint256[] | [0] stakingTarget Specify the target amount in the staking token. You can not exceed the target. |
Source Code
function _updatePoolValues(
IStore s,
bytes32 key,
uint256[] memory values
) private {
if (values[0] > 0) {
s.setUintByKeys(NS_POOL_STAKING_TARGET, key, values[0]);
}
if (values[1] > 0) {
s.setUintByKeys(NS_POOL_MAX_STAKE, key, values[1]);
}
if (values[2] > 0) {
s.setUintByKeys(NS_POOL_REWARD_PLATFORM_FEE, key, values[2]);
}
if (values[3] > 0) {
s.setUintByKeys(NS_POOL_REWARD_PER_BLOCK, key, values[3]);
}
if (values[4] > 0) {
s.setUintByKeys(NS_POOL_LOCKUP_PERIOD_IN_BLOCKS, key, values[4]);
}
if (values[5] > 0) {
s.addUintByKeys(NS_POOL_REWARD_TOKEN_DEPOSITS, key, values[5]);
s.addUintByKeys(NS_POOL_REWARD_TOKEN_BALANCE, key, values[5]);
}
}
Initializes a new pool by the given key. Assumes that the pool does not exist. Warning: this feature should not be accessible outside of this library.
function _initializeNewPool(IStore s, bytes32 key, address[] addresses) private nonpayable
Arguments
Name | Type | Description |
---|---|---|
s | IStore | Provide an instance of the store |
key | bytes32 | Enter the key of the pool you want to create or edit |
addresses | address[] | [0] stakingToken The token which is staked in this pool |
Source Code
function _initializeNewPool(
IStore s,
bytes32 key,
address[] memory addresses
) private {
s.setAddressByKeys(NS_POOL_STAKING_TOKEN, key, addresses[0]);
s.setAddressByKeys(NS_POOL_STAKING_TOKEN_UNI_STABLECOIN_PAIR, key, addresses[1]);
s.setAddressByKeys(NS_POOL_REWARD_TOKEN, key, addresses[2]);
s.setAddressByKeys(NS_POOL_REWARD_TOKEN_UNI_STABLECOIN_PAIR, key, addresses[3]);
s.setBoolByKeys(NS_POOL, key, true);
}
- 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