Skip to content

Commit 1458b2c

Browse files
authored
Merge pull request #167 from fei-protocol/feat/v2-Split-IPCVDeposit
Split IPCVDeposit
2 parents 7d0ba56 + 9682f70 commit 1458b2c

File tree

7 files changed

+38
-28
lines changed

7 files changed

+38
-28
lines changed

contracts/bondingcurve/BondingCurve.sol

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import "../Constants.sol";
1515
* @author Fei Protocol
1616
*
1717
*/
18-
contract BondingCurve is IBondingCurve, OracleRef, PCVSplitter, Timed, Incentivized {
18+
contract BondingCurve is IPCVDepositBalances, IBondingCurve, OracleRef, PCVSplitter, Timed, Incentivized {
1919
using Decimal for Decimal.D256;
2020

2121
/// @notice the Scale target at which bonding curve price fixes
@@ -107,14 +107,12 @@ contract BondingCurve is IBondingCurve, OracleRef, PCVSplitter, Timed, Incentivi
107107
}
108108

109109
/// @notice display the related token of the balance reported
110-
/// @dev to allow compatibility with the Collateralization Oracle even though this contract isn't an IPCVDeposit
111-
function balanceReportedIn() public view returns (address) {
110+
function balanceReportedIn() public view override returns (address) {
112111
return address(token);
113112
}
114113

115114
/// @notice returns a manipulation resistant account of both the balance of underlying and protocol owned FEI
116-
/// @dev to allow compatibility with the Collateralization Oracle even though this contract isn't an IPCVDeposit
117-
function resistantBalanceAndFei() public view returns(uint256, uint256) {
115+
function resistantBalanceAndFei() public view override returns(uint256, uint256) {
118116
return (balance(), 0);
119117
}
120118

contracts/bondingcurve/IBondingCurve.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ interface IBondingCurve {
6161

6262
function totalPurchased() external view returns (uint256);
6363

64-
function balance() external view returns (uint256);
65-
6664
function token() external view returns (IERC20);
6765

6866
function mintCap() external view returns (uint256);

contracts/oracle/CollateralizationOracle.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pragma solidity ^0.8.4;
44
import "./IOracle.sol";
55
import "./ICollateralizationOracle.sol";
66
import "../refs/CoreRef.sol";
7-
import "../pcv/IPCVDeposit.sol";
7+
import "../pcv/IPCVDepositBalances.sol";
88
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
99

1010
interface IPausable {
@@ -124,7 +124,7 @@ contract CollateralizationOracle is ICollateralizationOracle, CoreRef {
124124
require(depositToToken[_deposit] == address(0), "CollateralizationOracle: deposit duplicate");
125125

126126
// get the token in which the deposit reports its token
127-
address _token = IPCVDeposit(_deposit).balanceReportedIn();
127+
address _token = IPCVDepositBalances(_deposit).balanceReportedIn();
128128

129129
// revert if there is no oracle of this deposit's token
130130
require(tokenToOracle[_token] != address(0), "CollateralizationOracle: no oracle");
@@ -289,7 +289,7 @@ contract CollateralizationOracle is ICollateralizationOracle, CoreRef {
289289
// ignore deposits that are excluded by the Guardian
290290
if (!excludedDeposits[_deposit]) {
291291
// read the deposit, and increment token balance/protocol fei
292-
(uint256 _depositBalance, uint256 _depositFei) = IPCVDeposit(_deposit).resistantBalanceAndFei();
292+
(uint256 _depositBalance, uint256 _depositFei) = IPCVDepositBalances(_deposit).resistantBalanceAndFei();
293293
_totalTokenBalance += _depositBalance;
294294
_protocolControlledFei += _depositFei;
295295
}

contracts/pcv/IPCVDeposit.sol

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// SPDX-License-Identifier: GPL-3.0-or-later
22
pragma solidity ^0.8.4;
33

4+
import "./IPCVDepositBalances.sol";
5+
46
/// @title a PCV Deposit interface
57
/// @author Fei Protocol
6-
interface IPCVDeposit {
8+
interface IPCVDeposit is IPCVDepositBalances {
79
// ----------- Events -----------
810
event Deposit(address indexed _from, uint256 _amount);
911

@@ -37,14 +39,4 @@ interface IPCVDeposit {
3739
function withdrawERC20(address token, address to, uint256 amount) external;
3840

3941
function withdrawETH(address payable to, uint256 amount) external;
40-
41-
// ----------- Getters -----------
42-
43-
function balance() external view returns (uint256);
44-
45-
// gets the token address in which this deposit returns its balance
46-
function balanceReportedIn() external view returns (address);
47-
48-
// gets the resistant token balance and protocol owned fei of this deposit
49-
function resistantBalanceAndFei() external view returns (uint256, uint256);
5042
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
pragma solidity ^0.8.4;
3+
4+
/// @title a PCV Deposit interface for only balance getters
5+
/// @author Fei Protocol
6+
interface IPCVDepositBalances {
7+
8+
// ----------- Getters -----------
9+
10+
/// @notice gets the effective balance of "balanceReportedIn" token if the deposit were fully withdrawn
11+
function balance() external view returns (uint256);
12+
13+
/// @notice gets the token address in which this deposit returns its balance
14+
function balanceReportedIn() external view returns (address);
15+
16+
/// @notice gets the resistant token balance and protocol owned fei of this deposit
17+
function resistantBalanceAndFei() external view returns (uint256, uint256);
18+
}

contracts/pcv/curve/StableSwapOperatorV1.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,8 @@ contract StableSwapOperatorV1 is PCVDeposit {
284284

285285
return _daiOut;
286286
}
287+
288+
function balanceReportedIn() public view override returns(address) {
289+
return _dai;
290+
}
287291
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pragma solidity ^0.8.4;
22

3-
import "../IPCVDeposit.sol";
3+
import "../IPCVDepositBalances.sol";
44

55
/**
66
@notice a lightweight contract to wrap old PCV deposits to use the new interface
@@ -12,37 +12,37 @@ import "../IPCVDeposit.sol";
1212
1313
This wrapper can be used in the CR oracle which reduces the number of contract upgrades and reduces the complexity and risk of the upgrade
1414
*/
15-
contract PCVDepositWrapper {
15+
contract PCVDepositWrapper is IPCVDepositBalances {
1616

1717
/// @notice the referenced PCV Deposit
18-
IPCVDeposit public pcvDeposit;
18+
IPCVDepositBalances public pcvDeposit;
1919

2020
/// @notice the balance reported in token
2121
address public token;
2222

2323
/// @notice a flag for whether to report the balance as protocol owned FEI
2424
bool public isProtocolFeiDeposit;
2525

26-
constructor(IPCVDeposit _pcvDeposit, address _token, bool _isProtocolFeiDeposit) {
26+
constructor(IPCVDepositBalances _pcvDeposit, address _token, bool _isProtocolFeiDeposit) {
2727
pcvDeposit = _pcvDeposit;
2828
token = _token;
2929
isProtocolFeiDeposit = _isProtocolFeiDeposit;
3030
}
3131

3232
/// @notice returns total balance of PCV in the Deposit
33-
function balance() public view returns (uint256) {
33+
function balance() public view override returns (uint256) {
3434
return pcvDeposit.balance();
3535
}
3636

3737
/// @notice returns the resistant balance and FEI in the deposit
38-
function resistantBalanceAndFei() public view returns (uint256, uint256) {
38+
function resistantBalanceAndFei() public view override returns (uint256, uint256) {
3939
uint256 resistantBalance = balance();
4040
uint256 reistantFei = isProtocolFeiDeposit ? resistantBalance : 0;
4141
return (resistantBalance, reistantFei);
4242
}
4343

4444
/// @notice display the related token of the balance reported
45-
function balanceReportedIn() public view returns (address) {
45+
function balanceReportedIn() public view override returns (address) {
4646
return token;
4747
}
4848
}

0 commit comments

Comments
 (0)