From ab69c4c1177b1b77aeab1dbb48eac97afcb45856 Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Thu, 18 Jul 2024 00:39:31 -0400 Subject: [PATCH] nit: move timestamp check into helper + document --- contracts/p0/BasketHandler.sol | 5 +++-- contracts/p1/BasketHandler.sol | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/contracts/p0/BasketHandler.sol b/contracts/p0/BasketHandler.sol index 3aaaaef274..ca1c697d9d 100644 --- a/contracts/p0/BasketHandler.sol +++ b/contracts/p0/BasketHandler.sol @@ -406,9 +406,10 @@ contract BasketHandlerP0 is ComponentP0, IBasketHandler { return _quantity(erc20, ICollateral(address(asset)), false, CEIL); } + /// @param coll A collateral that has had refresh() called on it this timestamp /// @return {1} The multiplier to charge on issuance quantities for a collateral function issuancePremium(ICollateral coll) public view returns (uint192) { - if (skipIssuancePremium) return FIX_ONE; + if (skipIssuancePremium || coll.lastSave() != block.timestamp) return FIX_ONE; try coll.savedPegPrice() returns (uint192 pegPrice) { uint192 targetPerRef = coll.targetPerRef(); // {target/ref} @@ -442,7 +443,7 @@ contract BasketHandlerP0 is ComponentP0, IBasketHandler { q = basket.refAmts[erc20].div(refPerTok, rounding); // Prevent toxic issuance by charging more when collateral is under peg - if (applyIssuancePremium && coll.lastSave() == block.timestamp) { + if (applyIssuancePremium) { uint192 premium = issuancePremium(coll); // {1} CEIL // {tok/BU} = {tok/BU} * {1} diff --git a/contracts/p1/BasketHandler.sol b/contracts/p1/BasketHandler.sol index fb67a8089a..067f867901 100644 --- a/contracts/p1/BasketHandler.sol +++ b/contracts/p1/BasketHandler.sol @@ -366,10 +366,11 @@ contract BasketHandlerP1 is ComponentP1, IBasketHandler { return _quantity(erc20, ICollateral(address(asset)), false, CEIL); } + /// @param coll A collateral that has had refresh() called on it this timestamp /// @return {1} The multiplier to charge on issuance quantities for a collateral function issuancePremium(ICollateral coll) public view returns (uint192) { // `coll` does not need validation - if (skipIssuancePremium) return FIX_ONE; + if (skipIssuancePremium || coll.lastSave() != block.timestamp) return FIX_ONE; // Use try-catch for safety since `savedPegPrice()` was only added in 4.0.0 to ICollateral try coll.savedPegPrice() returns (uint192 pegPrice) { @@ -406,7 +407,7 @@ contract BasketHandlerP1 is ComponentP1, IBasketHandler { q = basket.refAmts[erc20].div(refPerTok, rounding); // Prevent toxic issuance by charging more when collateral is under peg - if (applyIssuancePremium && coll.lastSave() == block.timestamp) { + if (applyIssuancePremium) { uint192 premium = issuancePremium(coll); // {1} CEIL // {tok/BU} = {tok/BU} * {1}