@@ -109,40 +109,36 @@ contract UFragments is ERC20Detailed, Ownable {
109
109
onlyMonetaryPolicy
110
110
returns (uint256 )
111
111
{
112
- uint256 oldTotalSupply = _totalSupply;
113
112
if (supplyDelta == 0 ) {
114
- emit LogRebase (epoch, oldTotalSupply );
115
- return oldTotalSupply ;
113
+ emit LogRebase (epoch, _totalSupply );
114
+ return _totalSupply ;
116
115
}
117
116
118
- uint256 newTotalSupply;
119
117
if (supplyDelta < 0 ) {
120
- newTotalSupply = oldTotalSupply .sub (uint256 (supplyDelta.abs ()));
118
+ _totalSupply = _totalSupply .sub (uint256 (supplyDelta.abs ()));
121
119
} else {
122
- newTotalSupply = oldTotalSupply .add (uint256 (supplyDelta));
120
+ _totalSupply = _totalSupply .add (uint256 (supplyDelta));
123
121
}
124
122
125
- if (newTotalSupply > MAX_SUPPLY) {
126
- newTotalSupply = MAX_SUPPLY;
123
+ if (_totalSupply > MAX_SUPPLY) {
124
+ _totalSupply = MAX_SUPPLY;
127
125
}
128
126
129
- _gonsPerFragment = TOTAL_GONS.div (newTotalSupply );
127
+ _gonsPerFragment = TOTAL_GONS.div (_totalSupply );
130
128
131
129
// From this point forward, _gonsPerFragment is taken as the source of truth.
132
- // We recalculate a newTotalSupply to be in agreement with the _gonsPerFragment
130
+ // We recalculate a new _totalSupply to be in agreement with the _gonsPerFragment
133
131
// conversion rate.
134
132
// This means our applied supplyDelta can deviate from the requested supplyDelta,
135
133
// but this deviation is guaranteed to be < (_totalSupply^2)/(TOTAL_GONS - _totalSupply).
136
134
//
137
135
// In the case of _totalSupply <= MAX_UINT128 (our current supply cap), this
138
136
// deviation is guaranteed to be < 1, so we can omit this step. If the supply cap is
139
137
// ever increased, it must be re-included.
140
- // newTotalSupply = TOTAL_GONS.div(_gonsPerFragment)
141
-
142
- _totalSupply = newTotalSupply;
138
+ // _totalSupply = TOTAL_GONS.div(_gonsPerFragment)
143
139
144
- emit LogRebase (epoch, newTotalSupply );
145
- return newTotalSupply ;
140
+ emit LogRebase (epoch, _totalSupply );
141
+ return _totalSupply ;
146
142
}
147
143
148
144
function initialize (address owner_ ) public override initializer {
@@ -340,13 +336,12 @@ contract UFragments is ERC20Detailed, Ownable {
340
336
* @param spender The address which will spend the funds.
341
337
* @param addedValue The amount of tokens to increase the allowance by.
342
338
*/
343
- function increaseAllowance (address spender , uint256 addedValue ) external returns (bool ) {
344
- uint256 oldValue = _allowedFragments[msg .sender ][spender];
345
- uint256 newValue = oldValue.add (addedValue);
346
-
347
- _allowedFragments[msg .sender ][spender] = newValue;
348
- emit Approval (msg .sender , spender, newValue);
339
+ function increaseAllowance (address spender , uint256 addedValue ) public returns (bool ) {
340
+ _allowedFragments[msg .sender ][spender] = _allowedFragments[msg .sender ][spender].add (
341
+ addedValue
342
+ );
349
343
344
+ emit Approval (msg .sender , spender, _allowedFragments[msg .sender ][spender]);
350
345
return true ;
351
346
}
352
347
@@ -358,11 +353,11 @@ contract UFragments is ERC20Detailed, Ownable {
358
353
*/
359
354
function decreaseAllowance (address spender , uint256 subtractedValue ) external returns (bool ) {
360
355
uint256 oldValue = _allowedFragments[msg .sender ][spender];
361
- uint256 newValue = (subtractedValue >= oldValue) ? 0 : oldValue.sub (subtractedValue);
362
-
363
- _allowedFragments[msg .sender ][spender] = newValue;
364
- emit Approval (msg .sender , spender, newValue);
356
+ _allowedFragments[msg .sender ][spender] = (subtractedValue >= oldValue)
357
+ ? 0
358
+ : oldValue.sub (subtractedValue);
365
359
360
+ emit Approval (msg .sender , spender, _allowedFragments[msg .sender ][spender]);
366
361
return true ;
367
362
}
368
363
0 commit comments