@@ -94,25 +94,28 @@ contract UFragments is ERC20Detailed, Ownable {
94
94
onlyMonetaryPolicy
95
95
returns (uint256 )
96
96
{
97
+ uint256 oldTotalSupply = _totalSupply;
97
98
if (supplyDelta == 0 ) {
98
- emit LogRebase (epoch, _totalSupply );
99
- return _totalSupply ;
99
+ emit LogRebase (epoch, oldTotalSupply );
100
+ return oldTotalSupply ;
100
101
}
101
102
103
+ uint256 newTotalSupply;
102
104
if (supplyDelta < 0 ) {
103
- _totalSupply = _totalSupply .sub (uint256 (supplyDelta.abs ()));
105
+ newTotalSupply = oldTotalSupply .sub (uint256 (supplyDelta.abs ()));
104
106
} else {
105
- _totalSupply = _totalSupply .add (uint256 (supplyDelta));
107
+ newTotalSupply = oldTotalSupply .add (uint256 (supplyDelta));
106
108
}
107
109
108
- if (_totalSupply > MAX_SUPPLY) {
109
- _totalSupply = MAX_SUPPLY;
110
+ if (newTotalSupply > MAX_SUPPLY) {
111
+ newTotalSupply = MAX_SUPPLY;
110
112
}
111
113
112
- _gonsPerFragment = TOTAL_GONS.div (_totalSupply);
114
+ _gonsPerFragment = TOTAL_GONS.div (newTotalSupply);
115
+ _totalSupply = newTotalSupply;
113
116
114
117
// From this point forward, _gonsPerFragment is taken as the source of truth.
115
- // We recalculate a new _totalSupply to be in agreement with the _gonsPerFragment
118
+ // We recalculate a newTotalSupply to be in agreement with the _gonsPerFragment
116
119
// conversion rate.
117
120
// This means our applied supplyDelta can deviate from the requested supplyDelta,
118
121
// but this deviation is guaranteed to be < (_totalSupply^2)/(TOTAL_GONS - _totalSupply).
@@ -122,8 +125,8 @@ contract UFragments is ERC20Detailed, Ownable {
122
125
// ever increased, it must be re-included.
123
126
// _totalSupply = TOTAL_GONS.div(_gonsPerFragment)
124
127
125
- emit LogRebase (epoch, _totalSupply );
126
- return _totalSupply ;
128
+ emit LogRebase (epoch, newTotalSupply );
129
+ return newTotalSupply ;
127
130
}
128
131
129
132
function initialize (address owner_ ) public initializer {
@@ -232,10 +235,11 @@ contract UFragments is ERC20Detailed, Ownable {
232
235
* @param addedValue The amount of tokens to increase the allowance by.
233
236
*/
234
237
function increaseAllowance (address spender , uint256 addedValue ) public returns (bool ) {
235
- _allowedFragments[msg .sender ][spender] = _allowedFragments[msg .sender ][spender].add (
236
- addedValue
237
- );
238
- emit Approval (msg .sender , spender, _allowedFragments[msg .sender ][spender]);
238
+ uint256 oldValue = _allowedFragments[msg .sender ][spender];
239
+ uint256 newValue = oldValue.add (addedValue);
240
+
241
+ _allowedFragments[msg .sender ][spender] = newValue;
242
+ emit Approval (msg .sender , spender, newValue);
239
243
return true ;
240
244
}
241
245
@@ -247,12 +251,15 @@ contract UFragments is ERC20Detailed, Ownable {
247
251
*/
248
252
function decreaseAllowance (address spender , uint256 subtractedValue ) public returns (bool ) {
249
253
uint256 oldValue = _allowedFragments[msg .sender ][spender];
254
+ uint256 newValue;
250
255
if (subtractedValue >= oldValue) {
251
- _allowedFragments[ msg . sender ][spender] = 0 ;
256
+ newValue = 0 ;
252
257
} else {
253
- _allowedFragments[ msg . sender ][spender] = oldValue.sub (subtractedValue);
258
+ newValue = oldValue.sub (subtractedValue);
254
259
}
255
- emit Approval (msg .sender , spender, _allowedFragments[msg .sender ][spender]);
260
+
261
+ _allowedFragments[msg .sender ][spender] = newValue;
262
+ emit Approval (msg .sender , spender, newValue);
256
263
return true ;
257
264
}
258
265
}
0 commit comments