Skip to content

Commit 47f0bf9

Browse files
author
Michał Sieczkowski
authored
🧮 Add feed decimals check to TrueUSDWithPoR in contracts-por (#1200)
Reapply changes from "Require PoR feed decimals to be equal token's decimals" commit
1 parent 473889e commit 47f0bf9

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

packages/contracts-por/contracts/TrueCurrencyWithPoR.sol

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ abstract contract TrueCurrencyWithPoR is TrueCurrency, IPoRToken {
3434
super._mint(account, amount);
3535
return;
3636
}
37+
// Get required info about decimals.
38+
// Decimals of the Proof of Reserve feed must be the same as the token's.
39+
require(decimals() == AggregatorV3Interface(chainReserveFeed).decimals(), "Unexpected decimals of PoR feed");
3740

3841
// Get latest proof-of-reserves from the feed
3942
(, int256 signedReserves, , uint256 updatedAt, ) = AggregatorV3Interface(chainReserveFeed).latestRoundData();
@@ -46,20 +49,10 @@ abstract contract TrueCurrencyWithPoR is TrueCurrency, IPoRToken {
4649
// Check the answer is fresh enough (i.e., within the specified heartbeat)
4750
require(block.timestamp.sub(updatedAt) <= chainReserveHeartbeat, "TrueCurrency: PoR answer too old");
4851

49-
// Get required info about total supply & decimals
50-
uint8 trueDecimals = decimals();
51-
uint8 reserveDecimals = AggregatorV3Interface(chainReserveFeed).decimals();
52-
uint256 currentSupply = totalSupply();
53-
// Normalise TrueCurrency & reserve decimals
54-
if (trueDecimals < reserveDecimals) {
55-
currentSupply = currentSupply.mul(10**uint256(reserveDecimals - trueDecimals));
56-
} else if (trueDecimals > reserveDecimals) {
57-
reserves = reserves.mul(10**uint256(trueDecimals - reserveDecimals));
58-
}
59-
52+
// Get required info about total supply.
6053
// Check that after minting more tokens, the total supply would NOT exceed the reserves
6154
// reported by the latest valid proof-of-reserves feed.
62-
require(currentSupply + amount <= reserves, "TrueCurrency: total supply would exceed reserves after mint");
55+
require(totalSupply() + amount <= reserves, "TrueCurrency: total supply would exceed reserves after mint");
6356
super._mint(account, amount);
6457
}
6558

0 commit comments

Comments
 (0)