View Source: contracts/core/liquidity/LiquidityEngine.sol
↗ Extends: ILiquidityEngine, Recoverable
LiquidityEngine
The liquidity engine contract enables liquidity manager(s) to add, disable, remove, or manage lending or other income strategies.
- constructor(IStore s)
- addStrategies(address[] strategies)
- setLiquidityStateUpdateInterval(uint256 value)
- disableStrategy(address strategy)
- deleteStrategy(address strategy)
- setRiskPoolingPeriods(bytes32 coverKey, uint256 lendingPeriod, uint256 withdrawalWindow)
- setMaxLendingRatio(uint256 ratio)
- getMaxLendingRatio()
- getRiskPoolingPeriods(bytes32 coverKey)
- getDisabledStrategies()
- getActiveStrategies()
- addBulkLiquidity(struct IVault.AddLiquidityArgs[] args)
- version()
- getName()
function (IStore s) public nonpayable Recoverable
Arguments
Name | Type | Description |
---|---|---|
s | IStore |
Source Code
constructor(IStore s) Recoverable(s) {}
Adds an array of strategies to the liquidity engine.
function addStrategies(address[] strategies) external nonpayable nonReentrant
Arguments
Name | Type | Description |
---|---|---|
strategies | address[] | Enter one or more strategies. |
Source Code
function addStrategies(address[] calldata strategies) external override nonReentrant {
require(strategies.length > 0, "No strategy specified");
s.mustNotBePaused();
AccessControlLibV1.mustBeLiquidityManager(s);
s.addStrategiesInternal(strategies);
}
The liquidity state update interval allows the protocol to perform various activies such as NPM token price update, deposits or withdrawals to lending strategies, and more.
function setLiquidityStateUpdateInterval(uint256 value) external nonpayable nonReentrant
Arguments
Name | Type | Description |
---|---|---|
value | uint256 | Specify the update interval value |
Source Code
function setLiquidityStateUpdateInterval(uint256 value) external override nonReentrant {
require(value > 0, "Invalid value");
s.mustNotBePaused();
AccessControlLibV1.mustBeLiquidityManager(s);
s.setUintByKey(ProtoUtilV1.NS_LIQUIDITY_STATE_UPDATE_INTERVAL, value);
emit LiquidityStateUpdateIntervalSet(value);
}
Disables a strategy by address. When a strategy is disabled, it immediately withdraws and cannot lend any further.
function disableStrategy(address strategy) external nonpayable nonReentrant
Arguments
Name | Type | Description |
---|---|---|
strategy | address | Enter the strategy contract address to disable |
Source Code
function disableStrategy(address strategy) external override nonReentrant {
// because this function can only be invoked by a liquidity manager.
s.mustNotBePaused();
AccessControlLibV1.mustBeLiquidityManager(s);
s.disableStrategyInternal(strategy);
emit StrategyDisabled(strategy);
}
Permanently deletes a disabled strategy by address.
function deleteStrategy(address strategy) external nonpayable nonReentrant
Arguments
Name | Type | Description |
---|---|---|
strategy | address | Enter the strategy contract address to delete |
Source Code
function deleteStrategy(address strategy) external override nonReentrant {
s.mustNotBePaused();
AccessControlLibV1.mustBeLiquidityManager(s);
s.deleteStrategyInternal(strategy);
emit StrategyDeleted(strategy);
}
In order to pool risks collectively, liquidity providers
may lend their stablecoins to a cover pool of their choosing during "lending periods"
and withdraw them during "withdrawal windows." These periods are known as risk pooling periods.
The default lending period is six months, and the withdrawal window is seven days.
Specify a cover key if you want to configure or override these periods for a cover.
If no cover key is specified, the values entered will be set as global parameters.
function setRiskPoolingPeriods(bytes32 coverKey, uint256 lendingPeriod, uint256 withdrawalWindow) external nonpayable nonReentrant
Arguments
Name | Type | Description |
---|---|---|
coverKey | bytes32 | Enter a cover key to set the periods. Enter 0x if you want to set the values globally. |
lendingPeriod | uint256 | Enter the lending duration. Example: 180 days. |
withdrawalWindow | uint256 | Enter the withdrawal duration. Example: 7 days. |
Source Code
function setRiskPoolingPeriods(
bytes32 coverKey,
uint256 lendingPeriod,
uint256 withdrawalWindow
) external override nonReentrant {
require(lendingPeriod > 0, "Please specify lending period");
require(withdrawalWindow > 0, "Please specify withdrawal window");
s.mustNotBePaused();
AccessControlLibV1.mustBeLiquidityManager(s);
s.setRiskPoolingPeriodsInternal(coverKey, lendingPeriod, withdrawalWindow);
// event emitted in the above function
}
Specify the maximum lending ratio a strategy can utilize, not to exceed 100 percent.
function setMaxLendingRatio(uint256 ratio) external nonpayable nonReentrant
Arguments
Name | Type | Description |
---|---|---|
ratio | uint256 | . Enter the ratio as a percentage value. Use ProtoUtilV1.MULTIPLIER as your divisor. |
Source Code
function setMaxLendingRatio(uint256 ratio) external override nonReentrant {
require(ratio > 0, "Please specify lending ratio");
require(ratio <= ProtoUtilV1.MULTIPLIER, "Invalid lending ratio");
s.mustNotBePaused();
AccessControlLibV1.mustBeLiquidityManager(s);
s.setMaxLendingRatioInternal(ratio);
}
Gets the maximum lending ratio a strategy can utilize.
function getMaxLendingRatio() external view
returns(ratio uint256)
Arguments
Name | Type | Description |
---|
Source Code
function getMaxLendingRatio() external view override returns (uint256 ratio) {
return s.getMaxLendingRatioInternal();
}
Returns the risk pooling periods of a given cover key. Global values are returned if the risk pooling period for the given cover key was not defined. If global values are also undefined, fallback value of 180-day lending period and 7-day withdrawal window are returned. Warning: this function does not validate the cover key supplied.
function getRiskPoolingPeriods(bytes32 coverKey) external view
returns(lendingPeriod uint256, withdrawalWindow uint256)
Arguments
Name | Type | Description |
---|---|---|
coverKey | bytes32 | Enter the coverkey to retrieve the lending period of. Warning: this function doesn't check if the supplied cover key is a valid. |
Source Code
function getRiskPoolingPeriods(bytes32 coverKey) external view override returns (uint256 lendingPeriod, uint256 withdrawalWindow) {
return s.getRiskPoolingPeriodsInternal(coverKey);
}
Returns a list of disabled strategies.
function getDisabledStrategies() external view
returns(strategies address[])
Arguments
Name | Type | Description |
---|
Source Code
function getDisabledStrategies() external view override returns (address[] memory strategies) {
return s.getDisabledStrategiesInternal();
}
Returns a list of actively lending strategies.
function getActiveStrategies() external view
returns(strategies address[])
Arguments
Name | Type | Description |
---|
Source Code
function getActiveStrategies() external view override returns (address[] memory strategies) {
return s.getActiveStrategiesInternal();
}
function addBulkLiquidity(struct IVault.AddLiquidityArgs[] args) external nonpayable
Arguments
Name | Type | Description |
---|---|---|
args | struct IVault.AddLiquidityArgs[] |
Source Code
function addBulkLiquidity(IVault.AddLiquidityArgs[] calldata args) external override {
IERC20 stablecoin = IERC20(s.getStablecoinAddressInternal());
IERC20 npm = s.getNpmTokenInstanceInternal();
uint256 totalAmount;
uint256 totalNpm;
for (uint256 i = 0; i < args.length; i++) {
totalAmount += args[i].amount;
totalNpm += args[i].npmStakeToAdd;
}
stablecoin.ensureTransferFrom(msg.sender, address(this), totalAmount);
npm.ensureTransferFrom(msg.sender, address(this), totalNpm);
for (uint256 i = 0; i < args.length; i++) {
IVault vault = s.getVault(args[i].coverKey);
uint256 balance = vault.balanceOf(address(this));
if (balance > 0) {
IERC20(vault).ensureTransfer(s.getTreasuryAddressInternal(), balance);
}
stablecoin.approve(address(vault), args[i].amount);
npm.approve(address(vault), args[i].npmStakeToAdd);
vault.addLiquidity(args[i]);
balance = vault.balanceOf(address(this));
require(balance > 0, "Fatal, no PODs minted");
IERC20(vault).ensureTransfer(msg.sender, vault.balanceOf(address(this)));
}
}
Version number of this contract
function version() external pure
returns(bytes32)
Arguments
Name | Type | Description |
---|
Source Code
function version() external pure override returns (bytes32) {
return "v0.1";
}
Name of this contract
function getName() external pure
returns(bytes32)
Arguments
Name | Type | Description |
---|
Source Code
function getName() external pure override returns (bytes32) {
return ProtoUtilV1.CNAME_LIQUIDITY_ENGINE;
}
- 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