Skip to content

Commit

Permalink
refactor: rename OracleAsset struct to AssetInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
rackstar committed Oct 30, 2024
1 parent c00920e commit 2326a27
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
5 changes: 3 additions & 2 deletions contracts/interfaces/IPriceFeedOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ interface Aggregator {
interface IPriceFeedOracle {

enum AggregatorType { ETH, USD }
struct OracleAsset {

struct AssetInfo {
Aggregator aggregator;
uint8 decimals;
AggregatorType aggregatorType;
uint8 decimals;
}

function ETH() external view returns (address);
Expand Down
4 changes: 2 additions & 2 deletions contracts/mocks/common/PriceFeedOracleMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "../../interfaces/IPriceFeedOracle.sol";
contract PriceFeedOracleMock is IPriceFeedOracle {

address public constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
mapping(address => OracleAsset) public assetsMap;
mapping(address => AssetInfo) public assetsMap;

uint public ethRate;

Expand All @@ -28,7 +28,7 @@ contract PriceFeedOracleMock is IPriceFeedOracle {
}

function assets(address assetAddress) external view returns (Aggregator, uint8) {
OracleAsset memory asset = assetsMap[assetAddress];
AssetInfo memory asset = assetsMap[assetAddress];
return (asset.aggregator, asset.decimals);
}
}
20 changes: 10 additions & 10 deletions contracts/modules/capital/PriceFeedOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "../../interfaces/IPriceFeedOracle.sol";

contract PriceFeedOracle is IPriceFeedOracle {

mapping(address => OracleAsset) public assetsMap;
mapping(address => AssetInfo) public assetsMap;

address public constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
address public immutable safeTracker;
Expand All @@ -28,16 +28,16 @@ contract PriceFeedOracle is IPriceFeedOracle {
require(_safeTracker != address(0), "PriceFeedOracle: safeTracker cannot be zero address");

safeTracker = _safeTracker;
assetsMap[_safeTracker] = OracleAsset(Aggregator(_safeTracker), 18, AggregatorType.ETH);
assetsMap[_safeTracker] = AssetInfo(Aggregator(_safeTracker), AggregatorType.ETH, 18);

for (uint i = 0; i < _assetAddresses.length; i++) {
require(_assetAddresses[i] != address(0), "PriceFeedOracle: asset address cannot be zero");
require(_assetAggregators[i] != address(0), "PriceFeedOracle: aggregator address cannot be zero");

assetsMap[_assetAddresses[i]] = OracleAsset(
assetsMap[_assetAddresses[i]] = AssetInfo(
Aggregator(_assetAggregators[i]),
_assetDecimals[i],
_aggregatorTypes[i]
_aggregatorTypes[i],
_assetDecimals[i]
);
}
}
Expand All @@ -52,7 +52,7 @@ contract PriceFeedOracle is IPriceFeedOracle {
return 1 ether;
}

OracleAsset memory asset = assetsMap[assetAddress];
AssetInfo memory asset = assetsMap[assetAddress];
return _getAssetToEthRate(asset.aggregator, asset.aggregatorType);
}

Expand All @@ -67,7 +67,7 @@ contract PriceFeedOracle is IPriceFeedOracle {
return ethIn;
}

OracleAsset memory asset = assetsMap[assetAddress];
AssetInfo memory asset = assetsMap[assetAddress];
uint price = _getAssetToEthRate(asset.aggregator, asset.aggregatorType);

return ethIn * (10 ** uint(asset.decimals)) / price;
Expand All @@ -84,7 +84,7 @@ contract PriceFeedOracle is IPriceFeedOracle {
return amount;
}

OracleAsset memory asset = assetsMap[assetAddress];
AssetInfo memory asset = assetsMap[assetAddress];
uint price = _getAssetToEthRate(asset.aggregator, asset.aggregatorType);

return amount * (price) / 10 ** uint(asset.decimals);
Expand All @@ -105,7 +105,7 @@ contract PriceFeedOracle is IPriceFeedOracle {
if (aggregatorType == AggregatorType.ETH) {
return uint(rate);
} else {
OracleAsset memory ethAsset = assetsMap[ETH];
AssetInfo memory ethAsset = assetsMap[ETH];
require(address(ethAsset.aggregator) != address(0), "PriceFeedOracle: ETH/USD aggregator not set");
require(ethAsset.aggregatorType == AggregatorType.USD, "PriceFeedOracle: ETH aggregator must be USD type");

Expand All @@ -117,7 +117,7 @@ contract PriceFeedOracle is IPriceFeedOracle {
}

function assets(address assetAddress) external view returns (Aggregator, uint8) {
OracleAsset memory asset = assetsMap[assetAddress];
AssetInfo memory asset = assetsMap[assetAddress];
return (asset.aggregator, asset.decimals);
}
}

0 comments on commit 2326a27

Please sign in to comment.