Skip to content

Commit

Permalink
nit: move timestamp check into helper + document
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrent committed Jul 18, 2024
1 parent 1616b12 commit ab69c4c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions contracts/p0/BasketHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down
5 changes: 3 additions & 2 deletions contracts/p1/BasketHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit ab69c4c

Please sign in to comment.