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)
- getTargetInternal(IStore s, bytes32 key)
- getRewardPlatformFeeInternal(IStore s, bytes32 key)
- getTotalStakedInternal(IStore s, bytes32 key)
- getRewardPerBlockInternal(IStore s, bytes32 key)
- getLockupPeriodInBlocksInternal(IStore s, bytes32 key)
- getRewardTokenBalanceInternal(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)
- ensureValidStakingPoolInternal(IStore s, bytes32 key)
- checkIfStakingPoolExistsInternal(IStore s, bytes32 key)
- validateAddOrEditPoolInternal(IStore s, struct IStakingPools.AddOrEditPoolArgs args)
- addOrEditPoolInternal(IStore s, struct IStakingPools.AddOrEditPoolArgs args)
- _updatePoolValues(IStore s, struct IStakingPools.AddOrEditPoolArgs args)
- _initializeNewPool(IStore s, struct IStakingPools.AddOrEditPoolArgs args)
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 = getTotalStakedInternal(s, key);
uint256 target = getTargetInternal(s, key);
if (totalStaked >= target) {
return 0;
}
return target - totalStaked;
}
function getTargetInternal(IStore s, bytes32 key) public view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 |
Source Code
function getTargetInternal(IStore s, bytes32 key) public view returns (uint256) {
return s.getUintByKeys(NS_POOL_STAKING_TARGET, key);
}
function getRewardPlatformFeeInternal(IStore s, bytes32 key) external view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 |
Source Code
function getRewardPlatformFeeInternal(IStore s, bytes32 key) external view returns (uint256) {
return s.getUintByKeys(NS_POOL_REWARD_PLATFORM_FEE, key);
}
function getTotalStakedInternal(IStore s, bytes32 key) public view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 |
Source Code
function getTotalStakedInternal(IStore s, bytes32 key) public view returns (uint256) {
return s.getUintByKeys(NS_POOL_CUMULATIVE_STAKING_AMOUNT, key);
}
function getRewardPerBlockInternal(IStore s, bytes32 key) external view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 |
Source Code
function getRewardPerBlockInternal(IStore s, bytes32 key) external view returns (uint256) {
return s.getUintByKeys(NS_POOL_REWARD_PER_BLOCK, key);
}
function getLockupPeriodInBlocksInternal(IStore s, bytes32 key) external view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 |
Source Code
function getLockupPeriodInBlocksInternal(IStore s, bytes32 key) external view returns (uint256) {
return s.getUintByKeys(NS_POOL_LOCKUP_PERIOD_IN_BLOCKS, key);
}
function getRewardTokenBalanceInternal(IStore s, bytes32 key) external view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 |
Source Code
function getRewardTokenBalanceInternal(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 ensureValidStakingPoolInternal(IStore s, bytes32 key) external view
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 |
Source Code
function ensureValidStakingPoolInternal(IStore s, bytes32 key) external view {
require(checkIfStakingPoolExistsInternal(s, key), "Pool invalid or closed");
}
function checkIfStakingPoolExistsInternal(IStore s, bytes32 key) public view
returns(bool)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
key | bytes32 |
Source Code
function checkIfStakingPoolExistsInternal(IStore s, bytes32 key) public view returns (bool) {
return s.getBoolByKeys(NS_POOL, key);
}
function validateAddOrEditPoolInternal(IStore s, struct IStakingPools.AddOrEditPoolArgs args) public view
returns(bool)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
args | struct IStakingPools.AddOrEditPoolArgs |
Source Code
function validateAddOrEditPoolInternal(IStore s, IStakingPools.AddOrEditPoolArgs calldata args) public view returns (bool) {
require(args.key > 0, "Invalid key");
bool exists = checkIfStakingPoolExistsInternal(s, args.key);
if (exists == false) {
require(bytes(args.name).length > 0, "Invalid name");
require(args.stakingToken != address(0), "Invalid staking token");
// require(addresses[1] != address(0), "Invalid staking token pair"); // A POD doesn't have any pair with stablecion
require(args.rewardToken != address(0), "Invalid reward token");
require(args.uniRewardTokenDollarPair != address(0), "Invalid reward token pair");
require(args.lockupPeriod > 0, "Provide lockup period in blocks");
require(args.rewardTokenToDeposit > 0, "Provide reward token allocation");
require(args.rewardPerBlock > 0, "Provide reward per block");
require(args.stakingTarget > 0, "Please provide staking target");
}
return exists;
}
Adds or edits the pool by key
function addOrEditPoolInternal(IStore s, struct IStakingPools.AddOrEditPoolArgs args) external nonpayable
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
args | struct IStakingPools.AddOrEditPoolArgs |
Source Code
function addOrEditPoolInternal(IStore s, IStakingPools.AddOrEditPoolArgs calldata args) external {
// @suppress-zero-value-check The uint values are checked in the function `validateAddOrEditPoolInternal`
bool poolExists = validateAddOrEditPoolInternal(s, args);
if (poolExists == false) {
_initializeNewPool(s, args);
}
if (bytes(args.name).length > 0) {
s.setStringByKeys(NS_POOL, args.key, args.name);
}
_updatePoolValues(s, args);
if (args.rewardTokenToDeposit > 0) {
IERC20(args.rewardToken).ensureTransferFrom(msg.sender, address(this), args.rewardTokenToDeposit);
}
}
Updates the values of a staking pool by the given key
function _updatePoolValues(IStore s, struct IStakingPools.AddOrEditPoolArgs args) private nonpayable
Arguments
Name | Type | Description |
---|---|---|
s | IStore | Provide an instance of the store |
args | struct IStakingPools.AddOrEditPoolArgs |
Source Code
function _updatePoolValues(IStore s, IStakingPools.AddOrEditPoolArgs calldata args) private {
if (args.stakingTarget > 0) {
s.setUintByKeys(NS_POOL_STAKING_TARGET, args.key, args.stakingTarget);
}
if (args.maxStake > 0) {
s.setUintByKeys(NS_POOL_MAX_STAKE, args.key, args.maxStake);
}
if (args.platformFee > 0) {
s.setUintByKeys(NS_POOL_REWARD_PLATFORM_FEE, args.key, args.platformFee);
}
if (args.rewardPerBlock > 0) {
s.setUintByKeys(NS_POOL_REWARD_PER_BLOCK, args.key, args.rewardPerBlock);
}
if (args.lockupPeriod > 0) {
s.setUintByKeys(NS_POOL_LOCKUP_PERIOD_IN_BLOCKS, args.key, args.lockupPeriod);
}
if (args.rewardTokenToDeposit > 0) {
s.addUintByKeys(NS_POOL_REWARD_TOKEN_DEPOSITS, args.key, args.rewardTokenToDeposit);
s.addUintByKeys(NS_POOL_REWARD_TOKEN_BALANCE, args.key, args.rewardTokenToDeposit);
}
}
Initializes a new pool by the given key. Assumes that the pool does not exist.
function _initializeNewPool(IStore s, struct IStakingPools.AddOrEditPoolArgs args) private nonpayable
Arguments
Name | Type | Description |
---|---|---|
s | IStore | Provide an instance of the store |
args | struct IStakingPools.AddOrEditPoolArgs |
Source Code
function _initializeNewPool(IStore s, IStakingPools.AddOrEditPoolArgs calldata args) private {
s.setAddressByKeys(NS_POOL_STAKING_TOKEN, args.key, args.stakingToken);
s.setAddressByKeys(NS_POOL_STAKING_TOKEN_UNI_STABLECOIN_PAIR, args.key, args.uniStakingTokenDollarPair);
s.setAddressByKeys(NS_POOL_REWARD_TOKEN, args.key, args.rewardToken);
s.setAddressByKeys(NS_POOL_REWARD_TOKEN_UNI_STABLECOIN_PAIR, args.key, args.uniRewardTokenDollarPair);
s.setBoolByKeys(NS_POOL, args.key, true);
}
- AaveStrategy
- AccessControl
- AccessControlLibV1
- Address
- BaseLibV1
- BokkyPooBahsDateTimeLibrary
- BondPool
- BondPoolBase
- BondPoolLibV1
- CompoundStrategy
- Context
- Cover
- CoverBase
- CoverLibV1
- CoverReassurance
- CoverStake
- CoverUtilV1
- cxToken
- cxTokenFactory
- cxTokenFactoryLibV1
- Delayable
- Destroyable
- ERC165
- ERC20
- FakeAaveLendingPool
- FakeCompoundStablecoinDelegator
- FakePriceOracle
- FakeRecoverable
- FakeStore
- FakeToken
- FakeUniswapPair
- FakeUniswapV2FactoryLike
- FakeUniswapV2PairLike
- FakeUniswapV2RouterLike
- FaultyAaveLendingPool
- FaultyCompoundStablecoinDelegator
- Finalization
- ForceEther
- Governance
- GovernanceUtilV1
- IAaveV2LendingPoolLike
- IAccessControl
- IBondPool
- IClaimsProcessor
- ICompoundERC20DelegatorLike
- ICover
- ICoverReassurance
- ICoverStake
- ICxToken
- ICxTokenFactory
- IERC165
- IERC20
- IERC20Detailed
- IERC20Metadata
- IERC3156FlashBorrower
- IERC3156FlashLender
- IFinalization
- IGovernance
- ILendingStrategy
- ILiquidityEngine
- IMember
- INeptuneRouterV1
- InvalidStrategy
- IPausable
- IPolicy
- IPolicyAdmin
- IPriceOracle
- IProtocol
- IRecoverable
- IReporter
- IResolution
- IResolvable
- IStakingPools
- IStore
- IStoreLike
- IUniswapV2FactoryLike
- IUniswapV2PairLike
- IUniswapV2RouterLike
- IUnstakable
- IVault
- IVaultDelegate
- IVaultFactory
- IWitness
- LiquidityEngine
- MaliciousToken
- MockAccessControlUser
- MockCoverUtilUser
- MockCxToken
- MockCxTokenPolicy
- MockCxTokenStore
- MockFlashBorrower
- MockLiquidityEngineUser
- MockProcessorStore
- MockProcessorStoreLib
- MockProtocol
- MockRegistryClient
- MockStore
- MockStoreKeyUtilUser
- MockValidationLibUser
- MockVault
- MockVaultLibUser
- NeptuneRouterV1
- NPM
- NpmDistributor
- NTransferUtilV2
- NTransferUtilV2Intermediate
- Ownable
- Pausable
- Policy
- PolicyAdmin
- PolicyHelperV1
- PoorMansERC20
- POT
- PriceLibV1
- Processor
- ProtoBase
- Protocol
- ProtoUtilV1
- Recoverable
- ReentrancyGuard
- RegistryLibV1
- Reporter
- Resolution
- Resolvable
- RoutineInvokerLibV1
- SafeERC20
- StakingPoolBase
- StakingPoolCoreLibV1
- StakingPoolInfo
- StakingPoolLibV1
- StakingPoolReward
- StakingPools
- Store
- StoreBase
- StoreKeyUtil
- StrategyLibV1
- Strings
- TimelockController
- Unstakable
- ValidationLibV1
- Vault
- VaultBase
- VaultDelegate
- VaultDelegateBase
- VaultDelegateWithFlashLoan
- VaultFactory
- VaultFactoryLibV1
- VaultLibV1
- VaultLiquidity
- VaultStrategy
- WithFlashLoan
- WithPausability
- WithRecovery
- Witness