Skip to content

Commit 212d341

Browse files
authored
Revert "gas optimization" (#199)
This reverts commit b150071.
1 parent 4d71b55 commit 212d341

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

contracts/UFragments.sol

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -109,40 +109,36 @@ contract UFragments is ERC20Detailed, Ownable {
109109
onlyMonetaryPolicy
110110
returns (uint256)
111111
{
112-
uint256 oldTotalSupply = _totalSupply;
113112
if (supplyDelta == 0) {
114-
emit LogRebase(epoch, oldTotalSupply);
115-
return oldTotalSupply;
113+
emit LogRebase(epoch, _totalSupply);
114+
return _totalSupply;
116115
}
117116

118-
uint256 newTotalSupply;
119117
if (supplyDelta < 0) {
120-
newTotalSupply = oldTotalSupply.sub(uint256(supplyDelta.abs()));
118+
_totalSupply = _totalSupply.sub(uint256(supplyDelta.abs()));
121119
} else {
122-
newTotalSupply = oldTotalSupply.add(uint256(supplyDelta));
120+
_totalSupply = _totalSupply.add(uint256(supplyDelta));
123121
}
124122

125-
if (newTotalSupply > MAX_SUPPLY) {
126-
newTotalSupply = MAX_SUPPLY;
123+
if (_totalSupply > MAX_SUPPLY) {
124+
_totalSupply = MAX_SUPPLY;
127125
}
128126

129-
_gonsPerFragment = TOTAL_GONS.div(newTotalSupply);
127+
_gonsPerFragment = TOTAL_GONS.div(_totalSupply);
130128

131129
// 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
133131
// conversion rate.
134132
// This means our applied supplyDelta can deviate from the requested supplyDelta,
135133
// but this deviation is guaranteed to be < (_totalSupply^2)/(TOTAL_GONS - _totalSupply).
136134
//
137135
// In the case of _totalSupply <= MAX_UINT128 (our current supply cap), this
138136
// deviation is guaranteed to be < 1, so we can omit this step. If the supply cap is
139137
// ever increased, it must be re-included.
140-
// newTotalSupply = TOTAL_GONS.div(_gonsPerFragment)
141-
142-
_totalSupply = newTotalSupply;
138+
// _totalSupply = TOTAL_GONS.div(_gonsPerFragment)
143139

144-
emit LogRebase(epoch, newTotalSupply);
145-
return newTotalSupply;
140+
emit LogRebase(epoch, _totalSupply);
141+
return _totalSupply;
146142
}
147143

148144
function initialize(address owner_) public override initializer {
@@ -340,13 +336,12 @@ contract UFragments is ERC20Detailed, Ownable {
340336
* @param spender The address which will spend the funds.
341337
* @param addedValue The amount of tokens to increase the allowance by.
342338
*/
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+
);
349343

344+
emit Approval(msg.sender, spender, _allowedFragments[msg.sender][spender]);
350345
return true;
351346
}
352347

@@ -358,11 +353,11 @@ contract UFragments is ERC20Detailed, Ownable {
358353
*/
359354
function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool) {
360355
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);
365359

360+
emit Approval(msg.sender, spender, _allowedFragments[msg.sender][spender]);
366361
return true;
367362
}
368363

0 commit comments

Comments
 (0)