Skip to content
2 changes: 1 addition & 1 deletion contract-addresses/mainnetAddresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ const MainnetAddresses = {
uniswapPCVController: { artifactName: 'unknown', address: '0x0760dfe09bd6d04d0df9a60c51f01ecedceb5132' },
uniswapPCVDeposit: { artifactName: 'UniswapPCVDeposit', address: '0x15958381E9E6dc98bD49655e36f524D2203a28bD' },
uniswapRouter: { artifactName: 'unknown', address: '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D' },
weth: { artifactName: 'IWETH', address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' },
weth: { artifactName: 'IWETH', address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' },
wethERC20: { artifactName: 'IERC20', address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' }
};

Expand Down
17 changes: 4 additions & 13 deletions contracts/oracle/collateralization/CollateralizationOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ contract CollateralizationOracle is ICollateralizationOracle, CoreRef {
_addDeposits(_deposits);

// Shared admin with other oracles
_setContractAdminRole(keccak256("ORACLE_ADMIN_ROLE"));
_setContractAdminRole(keccak256("GUARDIAN_ROLE")); // initialize with Guardian before transitioning to ORACLE_ADMIN via DAO
// _setContractAdminRole(keccak256("ORACLE_ADMIN_ROLE"));
}

// ----------- Convenience getters -----------
Expand All @@ -75,12 +76,7 @@ contract CollateralizationOracle is ICollateralizationOracle, CoreRef {

/// @notice returns an array of the addresses of tokens held in the pcv.
function getTokensInPcv() external view returns(address[] memory) {
uint256 _length = tokensInPcv.length();
address[] memory tokens = new address[](_length);
for (uint256 i = 0; i < _length; i++) {
tokens[i] = tokensInPcv.at(i);
}
return tokens;
return tokensInPcv.values();
}

/// @notice returns token at index i of the array of PCV tokens
Expand All @@ -90,12 +86,7 @@ contract CollateralizationOracle is ICollateralizationOracle, CoreRef {

/// @notice returns an array of the deposits holding a given token.
function getDepositsForToken(address _token) external view returns(address[] memory) {
uint256 _length = tokenToDeposits[_token].length();
address[] memory deposits = new address[](_length);
for (uint256 i = 0; i < _length; i++) {
deposits[i] = tokenToDeposits[_token].at(i);
}
return deposits;
return tokenToDeposits[_token].values();
}

/// @notice returns the address of deposit at index i of token _token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ contract CollateralizationOracleWrapper is Timed, ICollateralizationOracleWrappe
deviationThresholdBasisPoints = _deviationThresholdBasisPoints;

// Shared admin with other oracles
_setContractAdminRole(keccak256("ORACLE_ADMIN_ROLE"));
_setContractAdminRole(keccak256("GUARDIAN_ROLE")); // initialize with Guardian before transitioning to ORACLE_ADMIN via DAO
// _setContractAdminRole(keccak256("ORACLE_ADMIN_ROLE"));
}

// ----------- Setter methods ----------------------------------------------
Expand Down
49 changes: 49 additions & 0 deletions contracts/pcv/utils/ERC20PCVDepositWrapper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
pragma solidity ^0.8.4;

import "../IPCVDepositBalances.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/**
@notice a lightweight contract to wrap ERC20 holding PCV contracts
@author Fei Protocol
When upgrading the PCVDeposit interface, there are many old contracts which do not support it.
The main use case for the new interface is to add read methods for the Collateralization Oracle.
Most PCVDeposits resistant balance method is simply returning the balance as a pass-through
If the PCVDeposit holds FEI it may be considered as protocol FEI

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
*/
contract ERC20PCVDepositWrapper is IPCVDepositBalances {

/// @notice the referenced token deposit
address public tokenDeposit;

/// @notice the balance reported in token
IERC20 public token;

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

constructor(address _tokenDeposit, IERC20 _token, bool _isProtocolFeiDeposit) {
tokenDeposit = _tokenDeposit;
token = _token;
isProtocolFeiDeposit = _isProtocolFeiDeposit;
}

/// @notice returns total balance of PCV in the Deposit
function balance() public view override returns (uint256) {
return token.balanceOf(tokenDeposit);
}

/// @notice returns the resistant balance and FEI in the deposit
function resistantBalanceAndFei() public view override returns (uint256, uint256) {
uint256 resistantBalance = balance();
uint256 reistantFei = isProtocolFeiDeposit ? resistantBalance : 0;
return (resistantBalance, reistantFei);
}

/// @notice display the related token of the balance reported
function balanceReportedIn() public view override returns (address) {
return address(token);
}
}
Loading