Skip to content

Commit 3aa815c

Browse files
author
Brandon Iles
committed
add96, type().max
1 parent 5c46572 commit 3aa815c

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

contracts/Forth.sol

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ contract Forth {
120120
// mint the amount
121121
uint96 amount = safe96(rawAmount, "Forth::mint: amount exceeds 96 bits");
122122
require(amount <= SafeMath.div(SafeMath.mul(totalSupply, mintCap), 100), "Forth::mint: exceeded mint cap");
123-
totalSupply = safe96(SafeMath.add(totalSupply, amount), "Forth::mint: totalSupply exceeds 96 bits");
123+
uint96 supply = safe96(totalSupply, "Forth::mint old totalSupply exceeds 96 bits");
124+
totalSupply = add96(supply, amount, "Forth::mint: new totalSupply exceeds 96 bits");
124125

125126
// transfer the amount to the recipient
126127
balances[dst] = add96(balances[dst], amount, "Forth::mint: transfer amount overflows");
@@ -150,8 +151,8 @@ contract Forth {
150151
*/
151152
function approve(address spender, uint rawAmount) external returns (bool) {
152153
uint96 amount;
153-
if (rawAmount == uint(-1)) {
154-
amount = uint96(-1);
154+
if (rawAmount == type(uint).max) {
155+
amount = type(uint96).max;
155156
} else {
156157
amount = safe96(rawAmount, "Forth::approve: amount exceeds 96 bits");
157158
}
@@ -174,8 +175,8 @@ contract Forth {
174175
*/
175176
function permit(address owner, address spender, uint rawAmount, uint deadline, uint8 v, bytes32 r, bytes32 s) external {
176177
uint96 amount;
177-
if (rawAmount == uint(-1)) {
178-
amount = uint96(-1);
178+
if (rawAmount == type(uint).max) {
179+
amount = type(uint96).max;
179180
} else {
180181
amount = safe96(rawAmount, "Forth::permit: amount exceeds 96 bits");
181182
}
@@ -226,7 +227,7 @@ contract Forth {
226227
uint96 spenderAllowance = allowances[src][spender];
227228
uint96 amount = safe96(rawAmount, "Forth::approve: amount exceeds 96 bits");
228229

229-
if (spender != src && spenderAllowance != uint96(-1)) {
230+
if (spender != src && spenderAllowance != type(uint96).max) {
230231
uint96 newAllowance = sub96(spenderAllowance, amount, "Forth::transferFrom: transfer amount exceeds spender allowance");
231232
allowances[src][spender] = newAllowance;
232233

0 commit comments

Comments
 (0)