Skip to content

Commit

Permalink
Review Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
akshatmittal committed Jun 24, 2023
1 parent c2c5454 commit 4487882
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
10 changes: 5 additions & 5 deletions contracts/interfaces/IRTokenOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ pragma solidity 0.8.19;
// RToken Oracle Interface
interface IRTokenOracle {
struct CachedOracleData {
uint192 cachedPrice;
uint256 cachedAtTime;
uint48 cachedAtNonce;
uint192 cachedPrice; // {UoA/tok}
uint256 cachedAtTime; // {s}
uint48 cachedAtNonce; // {basketNonce}
uint48 cachedTradesOpen;
uint256 cachedTradesNonce;
uint256 cachedTradesNonce; // {tradeNonce}
}

// @returns rTokenPrice {D18} {UoA/tok} The price of the RToken, in UoA
// @returns rTokenPrice {D18} {UoA/rTok} The price of the RToken, in UoA
function latestPrice() external returns (uint192 rTokenPrice, uint256 updatedAt);

// Force recalculate the price of the RToken
Expand Down
9 changes: 8 additions & 1 deletion contracts/p0/BasketHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,14 @@ contract BasketHandlerP0 is ComponentP0, IBasketHandler {
: reg.toAsset(basket.erc20s[i]).price();

low256 += qty.safeMul(lowP, RoundingMode.FLOOR);
high256 += qty.safeMul(highP, RoundingMode.CEIL);

if (high256 < FIX_MAX) {
if (highP == FIX_MAX) {
high256 = FIX_MAX;
} else {
high256 += qty.safeMul(highP, RoundingMode.CEIL);
}
}
}

// safe downcast: FIX_MAX is type(uint192).max
Expand Down
11 changes: 4 additions & 7 deletions contracts/p1/BasketHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ contract BasketHandlerP1 is ComponentP1, IBasketHandler {

low256 += qty.safeMul(lowP, RoundingMode.FLOOR);

if (high256 != FIX_MAX) {
if (high256 < FIX_MAX) {
if (highP == FIX_MAX) {
high256 = FIX_MAX;
} else {
Expand Down Expand Up @@ -602,12 +602,9 @@ contract BasketHandlerP1 is ComponentP1, IBasketHandler {
if (!asset.isCollateral()) continue; // skip token if no longer registered

// {tok} = {BU} * {ref/BU} / {ref/tok}
quantities[i] = FIX_ONE
.safeMulDiv(
b.refAmts[erc20s[i]],
ICollateral(address(asset)).refPerTok(),
FLOOR
)
quantities[i] = b
.refAmts[erc20s[i]]
.safeDiv(ICollateral(address(asset)).refPerTok(), FLOOR)
.shiftl_toUint(int8(asset.erc20Decimals()), FLOOR);
} catch (bytes memory errData) {
// untested:
Expand Down
9 changes: 2 additions & 7 deletions contracts/plugins/assets/RTokenAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ uint256 constant ORACLE_TIMEOUT = 15 minutes;

/// Once an RToken gets large enough to get a price feed, replacing this asset with
/// a simpler one will do wonders for gas usage
// @dev This RTokenAsset is ONLY compatible with Protocol >=3.0.0
// @dev This RTokenAsset is ONLY compatible with Protocol ^3.0.0
contract RTokenAsset is IAsset, VersionedAsset, IRTokenOracle {
using FixLib for uint192;
using OracleLib for AggregatorV3Interface;
Expand Down Expand Up @@ -148,7 +148,7 @@ contract RTokenAsset is IAsset, VersionedAsset, IRTokenOracle {
if (
cachedOracleData.cachedAtTime + ORACLE_TIMEOUT <= block.timestamp || // Cache Timeout
cachedOracleData.cachedAtNonce != basketHandler.nonce() || // Basket nonce was updated
cachedOracleData.cachedTradesNonce != backingManager.tradesNonce() || // New trades were started
cachedOracleData.cachedTradesNonce != backingManager.tradesNonce() || // New trades
cachedOracleData.cachedTradesOpen != backingManager.tradesOpen() // ..or settled
) {
_updateCachedPrice();
Expand All @@ -161,11 +161,6 @@ contract RTokenAsset is IAsset, VersionedAsset, IRTokenOracle {

// Update Oracle Data
function _updateCachedPrice() internal {
if (cachedOracleData.cachedAtTime == block.timestamp) {
// The price was updated in the same block.
return;
}

(uint192 low, uint192 high) = price();

require(low != 0 && high != FIX_MAX, "invalid price");
Expand Down

0 comments on commit 4487882

Please sign in to comment.