11pragma solidity ^ 0.6.4 ;
2+
23import "@openzeppelin/upgrades/contracts/Initializable.sol " ;
34import "@openzeppelin/contracts/token/ERC20/IERC20.sol " ;
45import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol " ;
56
67import "../libs/upgrades/UpgradeOwnable.sol " ;
78import "../interfaces/LiquidityPoolInterface.sol " ;
89import "../interfaces/MoneyMarketInterface.sol " ;
9- import "./FlowProtocol.sol " ;
10- import "./FlowToken.sol " ;
11- import "./FlowMarginProtocol.sol " ;
12- import "./FlowMarginProtocolSafety.sol " ;
13- import "./MarginTradingPair.sol " ;
1410
15- contract LiquidityPool is Initializable , UpgradeOwnable , LiquidityPoolInterface {
11+ abstract contract LiquidityPool is Initializable , UpgradeOwnable , LiquidityPoolInterface {
1612 using SafeERC20 for IERC20 ;
1713
18- // DO NOT CHANGE ORDER WHEN UPDATING, ONLY ADDING NEW VARIABLES IS ALLOWED
19- uint constant MAX_UINT = 2 ** 256 - 1 ;
20-
21- MoneyMarketInterface internal moneyMarket;
22- uint private spread;
23- uint private collateralRatio;
24-
25- address public protocol;
26- mapping (address => bool ) public allowedTokens;
27-
28- modifier onlyProtocol () {
29- require (msg .sender == protocol, "Ownable: caller is not the protocol " );
30- _;
31- }
14+ MoneyMarketInterface public override moneyMarket;
15+ address public override protocol;
3216
33- function initialize (MoneyMarketInterface _moneyMarket , address _protocol , uint _spread ) public initializer {
17+ function initialize (MoneyMarketInterface _moneyMarket , address _protocol ) public virtual initializer {
3418 UpgradeOwnable.initialize (msg .sender );
3519
3620 moneyMarket = _moneyMarket;
3721 protocol = _protocol;
38- spread = _spread;
39- collateralRatio = 0 ; // use fToken default
40- }
41-
42- function getBidSpread (address fToken ) external view override returns (uint ) {
43- if (allowedTokens[fToken]) {
44- return spread;
45- }
46- return 0 ;
47- }
48-
49- function getAskSpread (address fToken ) external view override returns (uint ) {
50- if (allowedTokens[fToken]) {
51- return spread;
52- }
53- return 0 ;
54- }
55-
56- function getAdditionalCollateralRatio (address fToken ) external view override returns (uint ) {
57- if (allowedTokens[fToken]) {
58- return collateralRatio;
59- }
60- return 0 ;
61- }
62-
63- function approve (address _protocol , uint amount ) external onlyOwner {
64- moneyMarket.iToken ().safeApprove (_protocol, amount);
65- }
66-
67- function setSpread (uint value ) external onlyOwner {
68- spread = value;
69-
70- emit SpreadUpdated ();
71- }
72-
73- function setCollateralRatio (uint value ) external onlyOwner {
74- collateralRatio = value;
75-
76- emit AdditionalCollateralRatioUpdated ();
77- }
78-
79- function enableToken (address token ) external onlyOwner {
80- allowedTokens[token] = true ;
81- }
82-
83- function disableToken (address token ) external onlyOwner {
84- allowedTokens[token] = false ;
85- }
86-
87- function depositLiquidity (uint _baseTokenAmount ) external override returns (uint256 ) {
88- moneyMarket.baseToken ().safeTransferFrom (msg .sender , address (this ), _baseTokenAmount);
89- moneyMarket.baseToken ().approve (address (moneyMarket), _baseTokenAmount);
90-
91- return moneyMarket.mint (_baseTokenAmount);
92- }
93-
94- function withdrawLiquidity (uint _iTokenAmount ) external override onlyProtocol returns (uint256 ) {
95- return moneyMarket.redeemTo (msg .sender , _iTokenAmount);
96- }
97-
98- function withdrawLiquidityOwner (uint _iTokenAmount ) external onlyOwner returns (uint256 ) {
99- uint256 baseTokenAmount = moneyMarket.redeemTo (msg .sender , _iTokenAmount);
100- require (
101- FlowMarginProtocol (protocol).safetyProtocol ().isPoolSafe (LiquidityPoolInterface (this )),
102- "Pool not safe after withdrawal "
103- );
104-
105- return baseTokenAmount;
106- }
107-
108- function addCollateral (FlowProtocol _protocol , FlowToken token , uint baseTokenAmount ) external onlyOwner {
109- _protocol.addCollateral (token, address (this ), baseTokenAmount);
110- }
111-
112- function withdrawCollateral (FlowProtocol _protocol , FlowToken token ) external onlyOwner {
113- _protocol.withdrawCollateral (token);
11422 }
11523
116- function getLiquidity ( ) external override returns ( uint256 ) {
117- return moneyMarket.iToken ().balanceOf ( address ( this ) );
24+ function approveToProtocol ( uint256 _amount ) external override onlyOwner {
25+ moneyMarket.iToken ().safeApprove (protocol, _amount );
11826 }
119- }
27+ }
0 commit comments