This repository has been archived by the owner on Mar 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCappedLiquidity.sol
66 lines (52 loc) · 2.45 KB
/
CappedLiquidity.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// SPDX-License-Identifier: LicenseRef-Gyro-1.0
// for information on licensing please see the README in the GitHub repository <https://github.com/gyrostable/concentrated-lps>.
pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;
// import "@balancer-labs/v2-solidity-utils/contracts/math/FixedPoint.sol";
import "../libraries/GyroFixedPoint.sol";
import "../interfaces/ICappedLiquidity.sol";
import "@balancer-labs/v2-solidity-utils/contracts/helpers/IAuthentication.sol";
/** @dev Enables caps on i) per-LP and ii) total caps on the pool size. Caps are in terms of BPT tokens! Pool functions
* have to call _ensureCap() to enforce the cap.
*/
abstract contract CappedLiquidity is ICappedLiquidity {
using GyroFixedPoint for uint256;
string internal constant _OVER_GLOBAL_CAP = "over global liquidity cap";
string internal constant _OVER_ADDRESS_CAP = "over address liquidity cap";
string internal constant _NOT_AUTHORIZED = "not authorized";
string internal constant _UNCAPPED = "pool is uncapped";
CapParams internal _capParams;
address public override capManager;
constructor(address _capManager, CapParams memory params) {
require(_capManager != address(0), _NOT_AUTHORIZED);
capManager = _capManager;
_capParams.capEnabled = params.capEnabled;
_capParams.perAddressCap = params.perAddressCap;
_capParams.globalCap = params.globalCap;
}
function setCapManager(address _capManager) external {
require(msg.sender == capManager, _NOT_AUTHORIZED);
capManager = _capManager;
emit CapManagerUpdated(_capManager);
}
function capParams() external view override returns (CapParams memory) {
return _capParams;
}
function setCapParams(CapParams memory params) external override {
require(msg.sender == capManager, _NOT_AUTHORIZED);
require(_capParams.capEnabled, _UNCAPPED);
_capParams.capEnabled = params.capEnabled;
_capParams.perAddressCap = params.perAddressCap;
_capParams.globalCap = params.globalCap;
emit CapParamsUpdated(_capParams);
}
function _ensureCap(
uint256 amountMinted,
uint256 userBalance,
uint256 currentSupply
) internal view {
CapParams memory params = _capParams;
require(amountMinted.add(userBalance) <= params.perAddressCap, _OVER_ADDRESS_CAP);
require(amountMinted.add(currentSupply) <= params.globalCap, _OVER_GLOBAL_CAP);
}
}