View Source: contracts/libraries/BondPoolLibV1.sol
BondPoolLibV1
Constants & Variables
bytes32 public constant NS_BOND_TO_CLAIM;
bytes32 public constant NS_BOND_CONTRIBUTION;
bytes32 public constant NS_BOND_LP_TOKEN;
bytes32 public constant NS_LQ_TREASURY;
bytes32 public constant NS_BOND_DISCOUNT_RATE;
bytes32 public constant NS_BOND_MAX_UNIT;
bytes32 public constant NS_BOND_VESTING_TERM;
bytes32 public constant NS_BOND_UNLOCK_DATE;
bytes32 public constant NS_BOND_TOTAL_NPM_ALLOCATED;
bytes32 public constant NS_BOND_TOTAL_NPM_DISTRIBUTED;
- calculateTokensForLpInternal(IStore s, uint256 lpTokens)
- getBondPoolInfoInternal(IStore s, address you)
- _getLpTokenAddress(IStore s)
- _getYourBondContribution(IStore s, address you)
- _getYourBondClaimable(IStore s, address you)
- _getYourBondUnlockDate(IStore s, address you)
- _getDiscountRate(IStore s)
- _getVestingTerm(IStore s)
- _getMaxBondInUnit(IStore s)
- _getTotalNpmAllocated(IStore s)
- _getTotalNpmDistributed(IStore s)
- createBondInternal(IStore s, uint256 lpTokens, uint256 minNpmDesired)
- _getNpmBalance(IStore s)
- _getBondCommitment(IStore s)
- claimBondInternal(IStore s)
- setupBondPoolInternal(IStore s, struct IBondPool.SetupBondPoolArgs args)
Calculates the discounted NPM token to be given for the NPM/Stablecoin Uniswap v2 LP token units.
function calculateTokensForLpInternal(IStore s, uint256 lpTokens) public view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | Specify store instance |
lpTokens | uint256 | Enter the NPM/Stablecoin Uniswap v2 LP token units |
Source Code
function calculateTokensForLpInternal(IStore s, uint256 lpTokens) public view returns (uint256) {
uint256 dollarValue = s.convertNpmLpUnitsToStabelcoinInternal(lpTokens);
uint256 npmPrice = s.getNpmPriceInternal(1 ether);
uint256 discount = _getDiscountRate(s);
uint256 discountedNpmPrice = (npmPrice * (ProtoUtilV1.MULTIPLIER - discount)) / ProtoUtilV1.MULTIPLIER;
uint256 npmForContribution = (dollarValue * 1 ether) / discountedNpmPrice;
return npmForContribution;
}
Gets the bond pool information
function getBondPoolInfoInternal(IStore s, address you) external view
returns(info struct IBondPool.BondPoolInfoType)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | Provide a store instance |
you | address |
Source Code
function getBondPoolInfoInternal(IStore s, address you) external view returns (IBondPool.BondPoolInfoType memory info) {
info.lpToken = _getLpTokenAddress(s);
info.marketPrice = s.getNpmPriceInternal(1 ether);
info.discountRate = _getDiscountRate(s);
info.vestingTerm = _getVestingTerm(s);
info.maxBond = _getMaxBondInUnit(s);
info.totalNpmAllocated = _getTotalNpmAllocated(s);
info.totalNpmDistributed = _getTotalNpmDistributed(s);
info.npmAvailable = IERC20(s.getNpmTokenInstanceInternal()).balanceOf(address(this));
info.bondContribution = _getYourBondContribution(s, you); // total lp tokens contributed by you
info.claimable = _getYourBondClaimable(s, you); // your total claimable NPM tokens at the end of the vesting period or "unlock date"
info.unlockDate = _getYourBondUnlockDate(s, you); // your vesting period end or "unlock date"
}
Gets the NPM/Stablecoin Uniswap v2 LP token address
function _getLpTokenAddress(IStore s) private view
returns(address)
Arguments
Name | Type | Description |
---|---|---|
s | IStore |
Source Code
function _getLpTokenAddress(IStore s) private view returns (address) {
return s.getAddressByKey(BondPoolLibV1.NS_BOND_LP_TOKEN);
}
Gets your unsettled bond contribution amount.
function _getYourBondContribution(IStore s, address you) private view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
you | address |
Source Code
function _getYourBondContribution(IStore s, address you) private view returns (uint256) {
return s.getUintByKey(keccak256(abi.encodePacked(BondPoolLibV1.NS_BOND_CONTRIBUTION, you)));
}
Gets your claimable discounted NPM bond amount.
function _getYourBondClaimable(IStore s, address you) private view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
you | address |
Source Code
function _getYourBondClaimable(IStore s, address you) private view returns (uint256) {
return s.getUintByKey(keccak256(abi.encodePacked(BondPoolLibV1.NS_BOND_TO_CLAIM, you)));
}
Returns the date when your discounted NPM token bond is unlocked for claim.
function _getYourBondUnlockDate(IStore s, address you) private view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
you | address |
Source Code
function _getYourBondUnlockDate(IStore s, address you) private view returns (uint256) {
return s.getUintByKey(keccak256(abi.encodePacked(BondPoolLibV1.NS_BOND_UNLOCK_DATE, you)));
}
Returns the NPM token bond discount rate
function _getDiscountRate(IStore s) private view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore |
Source Code
function _getDiscountRate(IStore s) private view returns (uint256) {
return s.getUintByKey(NS_BOND_DISCOUNT_RATE);
}
Returns the bond vesting term
function _getVestingTerm(IStore s) private view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore |
Source Code
function _getVestingTerm(IStore s) private view returns (uint256) {
return s.getUintByKey(NS_BOND_VESTING_TERM);
}
Returns the maximum NPM token units that can be bonded at a time
function _getMaxBondInUnit(IStore s) private view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore |
Source Code
function _getMaxBondInUnit(IStore s) private view returns (uint256) {
return s.getUintByKey(NS_BOND_MAX_UNIT);
}
Returns the total NPM tokens allocated for the bond
function _getTotalNpmAllocated(IStore s) private view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore |
Source Code
function _getTotalNpmAllocated(IStore s) private view returns (uint256) {
return s.getUintByKey(NS_BOND_TOTAL_NPM_ALLOCATED);
}
Returns the total bonded NPM tokens distributed till date.
function _getTotalNpmDistributed(IStore s) private view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore |
Source Code
function _getTotalNpmDistributed(IStore s) private view returns (uint256) {
return s.getUintByKey(NS_BOND_TOTAL_NPM_DISTRIBUTED);
}
Create a new NPM/stablecoin LP token bond
function createBondInternal(IStore s, uint256 lpTokens, uint256 minNpmDesired) external nonpayable
returns(npmToVest uint256, unlockDate uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | Specify store instance |
lpTokens | uint256 | Enter the total units of NPM/Stablecoin Uniswap v2 tokens to be bonded |
minNpmDesired | uint256 | Enter the minimum NPM tokens you desire for the given LP tokens. This transaction will revert if the final NPM bond is less than your specified value. |
Source Code
function createBondInternal(
IStore s,
uint256 lpTokens,
uint256 minNpmDesired
) external returns (uint256 npmToVest, uint256 unlockDate) {
s.mustNotBePaused();
npmToVest = calculateTokensForLpInternal(s, lpTokens);
require(npmToVest <= _getMaxBondInUnit(s), "Bond too big");
require(npmToVest >= minNpmDesired, "Min bond `minNpmDesired` failed");
require(_getNpmBalance(s) >= npmToVest + _getBondCommitment(s), "NPM balance insufficient to bond");
// Pull the tokens from the requester's account
IERC20(s.getAddressByKey(BondPoolLibV1.NS_BOND_LP_TOKEN)).ensureTransferFrom(msg.sender, s.getAddressByKey(BondPoolLibV1.NS_LQ_TREASURY), lpTokens);
// Commitment: Total NPM to reserve for bond claims
s.addUintByKey(BondPoolLibV1.NS_BOND_TO_CLAIM, npmToVest);
// Your bond to claim later
bytes32 k = keccak256(abi.encodePacked(BondPoolLibV1.NS_BOND_TO_CLAIM, msg.sender));
s.addUintByKey(k, npmToVest);
// Amount contributed
k = keccak256(abi.encodePacked(BondPoolLibV1.NS_BOND_CONTRIBUTION, msg.sender));
s.addUintByKey(k, lpTokens);
// unlock date
unlockDate = block.timestamp + _getVestingTerm(s); // solhint-disable-line
// Unlock date
k = keccak256(abi.encodePacked(BondPoolLibV1.NS_BOND_UNLOCK_DATE, msg.sender));
s.setUintByKey(k, unlockDate);
}
Gets the NPM token balance of this contract.
Please also see _getBondCommitment
to check
the total NPM tokens already allocated to the bonders
to be claimed later.
function _getNpmBalance(IStore s) private view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore | Specify store instance |
Source Code
function _getNpmBalance(IStore s) private view returns (uint256) {
return IERC20(s.getNpmTokenInstanceInternal()).balanceOf(address(this));
}
Returns the bond commitment amount.
function _getBondCommitment(IStore s) private view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore |
Source Code
function _getBondCommitment(IStore s) private view returns (uint256) {
return s.getUintByKey(BondPoolLibV1.NS_BOND_TO_CLAIM);
}
Enables the caller to claim their bond after the lockup period.
function claimBondInternal(IStore s) external nonpayable
returns(npmToTransfer uint256)
Arguments
Name | Type | Description |
---|---|---|
s | IStore |
Source Code
function claimBondInternal(IStore s) external returns (uint256 npmToTransfer) {
s.mustNotBePaused();
npmToTransfer = _getYourBondClaimable(s, msg.sender); // npmToTransfer
// Commitment: Reduce NPM reserved for claims
s.subtractUintByKey(BondPoolLibV1.NS_BOND_TO_CLAIM, npmToTransfer);
// Clear the claim amount
s.deleteUintByKey(keccak256(abi.encodePacked(BondPoolLibV1.NS_BOND_TO_CLAIM, msg.sender)));
uint256 unlocksOn = _getYourBondUnlockDate(s, msg.sender);
// Clear the unlock date
s.deleteUintByKey(keccak256(abi.encodePacked(BondPoolLibV1.NS_BOND_UNLOCK_DATE, msg.sender)));
require(block.timestamp >= unlocksOn, "Still vesting"); // solhint-disable-line
require(npmToTransfer > 0, "Nothing to claim");
s.addUintByKey(BondPoolLibV1.NS_BOND_TOTAL_NPM_DISTRIBUTED, npmToTransfer);
IERC20(s.getNpmTokenInstanceInternal()).ensureTransfer(msg.sender, npmToTransfer);
}
Sets up the bond pool
function setupBondPoolInternal(IStore s, struct IBondPool.SetupBondPoolArgs args) external nonpayable
Arguments
Name | Type | Description |
---|---|---|
s | IStore | |
args | struct IBondPool.SetupBondPoolArgs |
Source Code
function setupBondPoolInternal(IStore s, IBondPool.SetupBondPoolArgs calldata args) external {
if (args.lpToken != address(0)) {
s.setAddressByKey(BondPoolLibV1.NS_BOND_LP_TOKEN, args.lpToken);
}
if (args.treasury != address(0)) {
s.setAddressByKey(BondPoolLibV1.NS_LQ_TREASURY, args.treasury);
}
if (args.bondDiscountRate > 0) {
s.setUintByKey(BondPoolLibV1.NS_BOND_DISCOUNT_RATE, args.bondDiscountRate);
}
if (args.maxBondAmount > 0) {
s.setUintByKey(BondPoolLibV1.NS_BOND_MAX_UNIT, args.maxBondAmount);
}
if (args.vestingTerm > 0) {
s.setUintByKey(BondPoolLibV1.NS_BOND_VESTING_TERM, args.vestingTerm);
}
if (args.npmToTopUpNow > 0) {
IERC20(s.getNpmTokenInstanceInternal()).ensureTransferFrom(msg.sender, address(this), args.npmToTopUpNow);
s.addUintByKey(BondPoolLibV1.NS_BOND_TOTAL_NPM_ALLOCATED, args.npmToTopUpNow);
}
}
- 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