View Source: contracts/core/liquidity/VaultLiquidity.sol
↗ Extends: VaultBase ↘ Derived Contracts: VaultStrategy
VaultLiquidity
- transferGovernance(bytes32 coverKey, address to, uint256 amount)
- addLiquidity(struct IVault.AddLiquidityArgs args)
- removeLiquidity(bytes32 coverKey, uint256 podsToRedeem, uint256 npmStakeToRemove, bool exit)
- calculatePods(uint256 forStablecoinUnits)
- calculateLiquidity(uint256 podsToBurn)
- getStablecoinBalanceOf()
- accrueInterest()
Transfers stablecoins to claims processor contracts for claims payout.
Uses the hooks preTransferGovernance
and postTransferGovernance
on the vault delegate contract.
function transferGovernance(bytes32 coverKey, address to, uint256 amount) external nonpayable nonReentrant
Arguments
Name | Type | Description |
---|---|---|
coverKey | bytes32 | |
to | address | |
amount | uint256 |
Source Code
function transferGovernance(
bytes32 coverKey,
address to,
uint256 amount
) external override nonReentrant {
require(coverKey == key, "Forbidden");
require(amount > 0, "Please specify amount");
/******************************************************************************************
PRE
******************************************************************************************/
address stablecoin = delegate().preTransferGovernance(msg.sender, coverKey, to, amount);
/******************************************************************************************
BODY
******************************************************************************************/
IERC20(stablecoin).ensureTransfer(to, amount);
/******************************************************************************************
POST
******************************************************************************************/
delegate().postTransferGovernance(msg.sender, coverKey, to, amount);
emit GovernanceTransfer(to, amount);
}
Adds liquidity to the specified cover contract.
Uses the hooks preAddLiquidity
and postAddLiquidity
on the vault delegate contract.
function addLiquidity(struct IVault.AddLiquidityArgs args) external nonpayable nonReentrant
Arguments
Name | Type | Description |
---|---|---|
args | struct IVault.AddLiquidityArgs |
Source Code
function addLiquidity(AddLiquidityArgs calldata args) external override nonReentrant {
require(args.coverKey == key, "Forbidden");
require(args.amount > 0, "Please specify amount");
/******************************************************************************************
PRE
******************************************************************************************/
(uint256 podsToMint, uint256 previousNpmStake) = delegate().preAddLiquidity(msg.sender, args.coverKey, args.amount, args.npmStakeToAdd);
require(podsToMint > 0, "Can't determine PODs");
/******************************************************************************************
BODY
******************************************************************************************/
IERC20(sc).ensureTransferFrom(msg.sender, address(this), args.amount);
if (args.npmStakeToAdd > 0) {
IERC20(s.getNpmTokenAddressInternal()).ensureTransferFrom(msg.sender, address(this), args.npmStakeToAdd);
}
super._mint(msg.sender, podsToMint);
/******************************************************************************************
POST
******************************************************************************************/
delegate().postAddLiquidity(msg.sender, args.coverKey, args.amount, args.npmStakeToAdd);
emit PodsIssued(msg.sender, podsToMint, args.amount, args.referralCode);
if (previousNpmStake == 0) {
emit Entered(args.coverKey, msg.sender);
}
emit NpmStaken(msg.sender, args.npmStakeToAdd);
}
Removes liquidity from the specified cover contract
Uses the hooks preRemoveLiquidity
and postRemoveLiquidity
on the vault delegate contract.
function removeLiquidity(bytes32 coverKey, uint256 podsToRedeem, uint256 npmStakeToRemove, bool exit) external nonpayable nonReentrant
Arguments
Name | Type | Description |
---|---|---|
coverKey | bytes32 | Enter the cover key |
podsToRedeem | uint256 | Enter the amount of pods to redeem |
npmStakeToRemove | uint256 | Enter the amount of NPM stake to remove. |
exit | bool |
Source Code
function removeLiquidity(
bytes32 coverKey,
uint256 podsToRedeem,
uint256 npmStakeToRemove,
bool exit
) external override nonReentrant {
require(coverKey == key, "Forbidden");
require(podsToRedeem > 0 || npmStakeToRemove > 0, "Please specify amount");
/******************************************************************************************
PRE
******************************************************************************************/
(address stablecoin, uint256 stablecoinToRelease) = delegate().preRemoveLiquidity(msg.sender, coverKey, podsToRedeem, npmStakeToRemove, exit);
/******************************************************************************************
BODY
******************************************************************************************/
if (podsToRedeem > 0) {
IERC20(address(this)).ensureTransferFrom(msg.sender, address(this), podsToRedeem);
IERC20(stablecoin).ensureTransfer(msg.sender, stablecoinToRelease);
}
super._burn(address(this), podsToRedeem);
// Unstake NPM tokens
if (npmStakeToRemove > 0) {
IERC20(s.getNpmTokenAddressInternal()).ensureTransfer(msg.sender, npmStakeToRemove);
}
/******************************************************************************************
POST
******************************************************************************************/
delegate().postRemoveLiquidity(msg.sender, coverKey, podsToRedeem, npmStakeToRemove, exit);
emit PodsRedeemed(msg.sender, podsToRedeem, stablecoinToRelease);
if (exit) {
emit Exited(coverKey, msg.sender);
}
if (npmStakeToRemove > 0) {
emit NpmUnstaken(msg.sender, npmStakeToRemove);
}
}
Calculates the amount of PODS to mint for the given amount of liquidity to transfer
function calculatePods(uint256 forStablecoinUnits) external view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
forStablecoinUnits | uint256 |
Source Code
function calculatePods(uint256 forStablecoinUnits) external view override returns (uint256) {
return delegate().calculatePodsImplementation(key, forStablecoinUnits);
}
Calculates the amount of stablecoins to withdraw for the given amount of PODs to redeem
function calculateLiquidity(uint256 podsToBurn) external view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
podsToBurn | uint256 |
Source Code
function calculateLiquidity(uint256 podsToBurn) external view override returns (uint256) {
return delegate().calculateLiquidityImplementation(key, podsToBurn);
}
Returns the stablecoin balance of this vault This also includes amounts lent out in lending strategies
function getStablecoinBalanceOf() external view
returns(uint256)
Arguments
Name | Type | Description |
---|
Source Code
function getStablecoinBalanceOf() external view override returns (uint256) {
return delegate().getStablecoinBalanceOfImplementation(key);
}
Accrues interests from external strategies
function accrueInterest() external nonpayable nonReentrant
Arguments
Name | Type | Description |
---|
Source Code
function accrueInterest() external override nonReentrant {
delegate().accrueInterestImplementation(msg.sender, key);
emit InterestAccrued(key);
}
- 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