@@ -94,36 +94,40 @@ 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 );
113
115
114
116
// 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
117
+ // We recalculate a newTotalSupply to be in agreement with the _gonsPerFragment
116
118
// conversion rate.
117
119
// This means our applied supplyDelta can deviate from the requested supplyDelta,
118
120
// but this deviation is guaranteed to be < (_totalSupply^2)/(TOTAL_GONS - _totalSupply).
119
121
//
120
122
// In the case of _totalSupply <= MAX_UINT128 (our current supply cap), this
121
123
// deviation is guaranteed to be < 1, so we can omit this step. If the supply cap is
122
124
// ever increased, it must be re-included.
123
- // _totalSupply = TOTAL_GONS.div(_gonsPerFragment)
125
+ // newTotalSupply = TOTAL_GONS.div(_gonsPerFragment)
124
126
125
- emit LogRebase (epoch, _totalSupply);
126
- return _totalSupply;
127
+ _totalSupply = newTotalSupply;
128
+
129
+ emit LogRebase (epoch, newTotalSupply);
130
+ return newTotalSupply;
127
131
}
128
132
129
133
function initialize (address owner_ ) public initializer {
@@ -247,10 +251,11 @@ contract UFragments is ERC20Detailed, Ownable {
247
251
* @param addedValue The amount of tokens to increase the allowance by.
248
252
*/
249
253
function increaseAllowance (address spender , uint256 addedValue ) public returns (bool ) {
250
- _allowedFragments[msg .sender ][spender] = _allowedFragments[msg .sender ][spender].add (
251
- addedValue
252
- );
253
- emit Approval (msg .sender , spender, _allowedFragments[msg .sender ][spender]);
254
+ uint256 oldValue = _allowedFragments[msg .sender ][spender];
255
+ uint256 newValue = oldValue.add (addedValue);
256
+
257
+ _allowedFragments[msg .sender ][spender] = newValue;
258
+ emit Approval (msg .sender , spender, newValue);
254
259
return true ;
255
260
}
256
261
@@ -262,12 +267,15 @@ contract UFragments is ERC20Detailed, Ownable {
262
267
*/
263
268
function decreaseAllowance (address spender , uint256 subtractedValue ) public returns (bool ) {
264
269
uint256 oldValue = _allowedFragments[msg .sender ][spender];
270
+ uint256 newValue;
265
271
if (subtractedValue >= oldValue) {
266
- _allowedFragments[ msg . sender ][spender] = 0 ;
272
+ newValue = 0 ;
267
273
} else {
268
- _allowedFragments[ msg . sender ][spender] = oldValue.sub (subtractedValue);
274
+ newValue = oldValue.sub (subtractedValue);
269
275
}
270
- emit Approval (msg .sender , spender, _allowedFragments[msg .sender ][spender]);
276
+
277
+ _allowedFragments[msg .sender ][spender] = newValue;
278
+ emit Approval (msg .sender , spender, newValue);
271
279
return true ;
272
280
}
273
281
}
0 commit comments