Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No compound assignment #17

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/solidity-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,6 @@ Following is a list of supported expressions. Operator precendences are taken fr
> left: Expression "||" Expression [strict(1)]
> right:
Expression "?" Expression ":" Expression [strict(1)]
| Expression "+=" Expression [strict(2)]
| Expression "-=" Expression [strict(2)]
| Expression "*=" Expression [strict(2)]
| Expression "/=" Expression [strict(2)]
| Expression "=" Expression [strict(2)]

endmodule
Expand Down
46 changes: 23 additions & 23 deletions test/examples/lending/LendingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ contract LendingPool {
uint256 shares = _toShares(vaults[token].totalAsset, amount, false);
require(shares >= minSharesOut, "LendingPool: too high slippage");

vaults[token].totalAsset.shares += uint128(shares);
vaults[token].totalAsset.amount += uint128(amount);
userShares[msg.sender][token].collateral += shares;
vaults[token].totalAsset.shares = vaults[token].totalAsset.shares + uint128(shares);
vaults[token].totalAsset.amount = vaults[token].totalAsset.amount + uint128(amount);
userShares[msg.sender][token].collateral = userShares[msg.sender][token].collateral + shares;

emit Deposit(msg.sender, token, amount, shares);
}
Expand All @@ -148,9 +148,9 @@ contract LendingPool {
_accrueInterest(token);

uint256 shares = _toShares(vaults[token].totalBorrow, amount, false);
vaults[token].totalBorrow.shares += uint128(shares);
vaults[token].totalBorrow.amount += uint128(amount);
userShares[msg.sender][token].borrow += shares;
vaults[token].totalBorrow.shares = vaults[token].totalBorrow.shares + uint128(shares);
vaults[token].totalBorrow.amount = vaults[token].totalBorrow.amount + uint128(amount);
userShares[msg.sender][token].borrow = userShares[msg.sender][token].borrow + shares;

_transferERC20(token, address(this), msg.sender, amount);
require(
Expand All @@ -170,8 +170,8 @@ contract LendingPool {
amount = _toAmount(vaults[token].totalBorrow, shares, true);
}
_transferERC20(token, msg.sender, address(this), amount);
vaults[token].totalBorrow.shares -= uint128(shares);
vaults[token].totalBorrow.amount -= uint128(amount);
vaults[token].totalBorrow.shares = vaults[token].totalBorrow.shares - uint128(shares);
vaults[token].totalBorrow.amount = vaults[token].totalBorrow.amount - uint128(amount);
userShares[msg.sender][token].borrow = userBorrowShare - shares;
emit Repay(msg.sender, token, amount, shares);
}
Expand Down Expand Up @@ -267,8 +267,8 @@ contract LendingPool {
false
)
);
vaults[borrowToken].totalBorrow.shares -= repaidBorrowShares;
vaults[borrowToken].totalBorrow.amount -= uint128(
vaults[borrowToken].totalBorrow.shares = vaults[borrowToken].totalBorrow.shares - repaidBorrowShares;
vaults[borrowToken].totalBorrow.amount = vaults[borrowToken].totalBorrow.amount - uint128(
liquidationAmount
);

Expand All @@ -279,12 +279,12 @@ contract LendingPool {
false
)
);
vaults[collToken].totalAsset.shares -= liquidatedCollShares;
vaults[collToken].totalAsset.amount -= uint128(
vaults[collToken].totalAsset.shares = vaults[collToken].totalAsset.shares - liquidatedCollShares;
vaults[collToken].totalAsset.amount = vaults[collToken].totalAsset.amount - uint128(
collateralAmountToLiquidate + liquidationReward
);
userShares[user][borrowToken].borrow -= repaidBorrowShares;
userShares[user][collToken].collateral -= liquidatedCollShares;
userShares[user][borrowToken].borrow = userShares[user][borrowToken].borrow - repaidBorrowShares;
userShares[user][collToken].collateral = userShares[user][collToken].collateral - liquidatedCollShares;
}

_transferERC20(
Expand Down Expand Up @@ -330,7 +330,7 @@ contract LendingPool {
false
);
if (tokenAmount != 0) {
totalValueUSD += getAmountInUSD(token, tokenAmount);
totalValueUSD = totalValueUSD + getAmountInUSD(token, tokenAmount);
}
}
}
Expand All @@ -347,7 +347,7 @@ contract LendingPool {
false
);
if (tokenAmount != 0) {
totalValueUSD += getAmountInUSD(token, tokenAmount);
totalValueUSD = totalValueUSD + getAmountInUSD(token, tokenAmount);
}
}
}
Expand Down Expand Up @@ -465,9 +465,9 @@ contract LendingPool {
userCollShares >= shares && IERC20(token).balanceOf(address(this)) >= amount,
"LendingPool: insufficient balance"
);
vaults[token].totalAsset.shares -= uint128(shares);
vaults[token].totalAsset.amount -= uint128(amount);
userShares[msg.sender][token].collateral -= shares;
vaults[token].totalAsset.shares = vaults[token].totalAsset.shares - uint128(shares);
vaults[token].totalAsset.amount = vaults[token].totalAsset.amount - uint128(amount);
userShares[msg.sender][token].collateral = userShares[msg.sender][token].collateral - shares;

_transferERC20(token, address(this), msg.sender, amount);
require(
Expand Down Expand Up @@ -518,8 +518,8 @@ contract LendingPool {
_currentRateInfo.ratePerSec) /
(PRECISION * BLOCKS_PER_YEAR);

_vault.totalBorrow.amount += uint128(_interestEarned);
_vault.totalAsset.amount += uint128(_interestEarned);
_vault.totalBorrow.amount = _vault.totalBorrow.amount + uint128(_interestEarned);
_vault.totalAsset.amount = _vault.totalAsset.amount + uint128(_interestEarned);
_vault.vaultInfo = _currentRateInfo;
if (_currentRateInfo.feeToProtocolRate > 0) {
_feesAmount =
Expand All @@ -528,9 +528,9 @@ contract LendingPool {
_feesShare =
(_feesAmount * _vault.totalAsset.shares) /
(_vault.totalAsset.amount - _feesAmount);
_vault.totalAsset.shares += uint128(_feesShare);
_vault.totalAsset.shares = _vault.totalAsset.shares + uint128(_feesShare);

userShares[address(this)][token].collateral += _feesShare;
userShares[address(this)][token].collateral = userShares[address(this)][token].collateral + _feesShare;
}
emit AccruedInterest(
_currentRateInfo.ratePerSec,
Expand Down
2 changes: 1 addition & 1 deletion test/examples/staking/LiquidStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract LiquidStaking {

require(stakingToken.transferFrom(msg.sender, address(this), amount), "Token transfer failed");

stakedBalances[msg.sender] += amount;
stakedBalances[msg.sender] = stakedBalances[msg.sender] + amount;
stakedTimestamps[msg.sender] = block.timestamp;
}

Expand Down
16 changes: 8 additions & 8 deletions test/examples/swaps/UniswapV2Swap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ contract UniswapV2Pair{
uint32 blockTimestamp = uint32(block.timestamp % 2**32);
uint32 timeElapsed = blockTimestamp - blockTimestampLast; // overflow is desired
if (timeElapsed > 0 && _reserve0 != 0 && _reserve1 != 0) {
price0CumulativeLast += (_reserve1/_reserve0) * timeElapsed;
price1CumulativeLast += (_reserve0/_reserve1) * timeElapsed;
price0CumulativeLast = price0CumulativeLast + (_reserve1/_reserve0) * timeElapsed;
price1CumulativeLast = price1CumulativeLast + (_reserve0/_reserve1) * timeElapsed;
}
reserve0 = uint112(balance0);
reserve1 = uint112(balance1);
Expand All @@ -331,7 +331,7 @@ contract WETHMock {
}

function deposit() external payable {
balanceOf[msg.sender] += msg.value;
balanceOf[msg.sender] = balanceOf[msg.sender] + msg.value;
emit Transfer(address(0), msg.sender, msg.value);
}

Expand All @@ -348,7 +348,7 @@ contract WETHMock {
require(balance >= value, "WETH: transfer amount exceeds balance");

balanceOf[msg.sender] = balance - value;
balanceOf[to] += value;
balanceOf[to] = balanceOf[to] + value;
emit Transfer(msg.sender, to, value);
} else { // Withdraw
uint256 balance = balanceOf[msg.sender];
Expand Down Expand Up @@ -379,7 +379,7 @@ contract WETHMock {
require(balance >= value, "WETH: transfer amount exceeds balance");

balanceOf[from] = balance - value;
balanceOf[to] += value;
balanceOf[to] = balanceOf[to] + value;
emit Transfer(from, to, value);
} else {
uint256 balance = balanceOf[from];
Expand Down Expand Up @@ -515,7 +515,7 @@ contract USDCMock {

function _update(address from, address to, uint256 value) private {
if (from == address(0)) {
_totalSupply += value;
_totalSupply = _totalSupply + value;
} else {
uint256 fromBalance = _balances[from];
require(fromBalance >= value, "USDC: insufficient balance");
Expand All @@ -524,10 +524,10 @@ contract USDCMock {
}

if (to == address(0)) {
_totalSupply -= value;
_totalSupply = _totalSupply - value;

} else {
_balances[to] += value;
_balances[to] = _balances[to] + value;
}

emit Transfer(from, to, value);
Expand Down
2 changes: 1 addition & 1 deletion test/examples/tokens/SomeMultiToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ contract SomeMultiToken{
}

if (to != address(0)) {
_balances[id][to] += value;
_balances[id][to] = _balances[id][to] + value;
}
}

Expand Down
6 changes: 3 additions & 3 deletions test/examples/tokens/SomeToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ contract SomeToken {

function _update(address from, address to, uint256 value) private {
if (from == address(0)) {
_totalSupply += value;
_totalSupply = _totalSupply + value;
} else {
uint256 fromBalance = _balances[from];
require(fromBalance >= value, "SomeToken: insufficient balance");
Expand All @@ -86,9 +86,9 @@ contract SomeToken {
}

if (to == address(0)) {
_totalSupply -= value;
_totalSupply = _totalSupply - value;
} else {
_balances[to] += value;
_balances[to] = _balances[to] + value;
}

emit Transfer(from, to, value);
Expand Down
8 changes: 4 additions & 4 deletions test/regression/function.ref
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@
.List
</contract-fn-return-names>
<contract-fn-body>
if ( from == address ( 0 , .TypedVals ) ) { _totalSupply += value ; .Statements } else { uint256 fromBalance = _balances [ from ] ; require ( fromBalance >= value , "USDC: insufficient balance" , .TypedVals ) ; _balances [ from ] = fromBalance - value ; .Statements } if ( to == address ( 0 , .TypedVals ) ) { _totalSupply -= value ; .Statements } else { _balances [ to ] += value ; .Statements } .Statements
if ( from == address ( 0 , .TypedVals ) ) { _totalSupply = _totalSupply + value ; .Statements } else { uint256 fromBalance = _balances [ from ] ; require ( fromBalance >= value , "USDC: insufficient balance" , .TypedVals ) ; _balances [ from ] = fromBalance - value ; .Statements } if ( to == address ( 0 , .TypedVals ) ) { _totalSupply = _totalSupply - value ; .Statements } else { _balances [ to ] = _balances [ to ] + value ; .Statements } .Statements
</contract-fn-body>
</contract-fn> <contract-fn>
<contract-fn-id>
Expand Down Expand Up @@ -697,7 +697,7 @@
.List
</contract-fn-return-names>
<contract-fn-body>
require ( balance0 <= type ( uint112 , .TypedVals ) . max && balance1 <= type ( uint112 , .TypedVals ) . max , "UniswapV2: OVERFLOW" , .TypedVals ) ; uint32 blockTimestamp = uint32 ( block . timestamp % 2 ** 32 , .TypedVals ) ; uint32 timeElapsed = blockTimestamp - blockTimestampLast ; if ( timeElapsed > 0 && _reserve0 != 0 && _reserve1 != 0 ) { price0CumulativeLast += _reserve1 / _reserve0 * timeElapsed ; price1CumulativeLast += _reserve0 / _reserve1 * timeElapsed ; .Statements } reserve0 = uint112 ( balance0 , .TypedVals ) ; reserve1 = uint112 ( balance1 , .TypedVals ) ; blockTimestampLast = blockTimestamp ; .Statements
require ( balance0 <= type ( uint112 , .TypedVals ) . max && balance1 <= type ( uint112 , .TypedVals ) . max , "UniswapV2: OVERFLOW" , .TypedVals ) ; uint32 blockTimestamp = uint32 ( block . timestamp % 2 ** 32 , .TypedVals ) ; uint32 timeElapsed = blockTimestamp - blockTimestampLast ; if ( timeElapsed > 0 && _reserve0 != 0 && _reserve1 != 0 ) { price0CumulativeLast = price0CumulativeLast + _reserve1 / _reserve0 * timeElapsed ; price1CumulativeLast = price1CumulativeLast + _reserve0 / _reserve1 * timeElapsed ; .Statements } reserve0 = uint112 ( balance0 , .TypedVals ) ; reserve1 = uint112 ( balance1 , .TypedVals ) ; blockTimestampLast = blockTimestamp ; .Statements
</contract-fn-body>
</contract-fn> <contract-fn>
<contract-fn-id>
Expand Down Expand Up @@ -1798,7 +1798,7 @@
ListItem ( noId )
</contract-fn-return-names>
<contract-fn-body>
if ( to != address ( 0 , .TypedVals ) && to != address ( this , .TypedVals ) ) { uint256 balance = balanceOf [ msg . sender ] ; require ( balance >= value , "WETH: transfer amount exceeds balance" , .TypedVals ) ; balanceOf [ msg . sender ] = balance - value ; balanceOf [ to ] += value ; .Statements } else { uint256 balance = balanceOf [ msg . sender ] ; require ( balance >= value , "WETH: burn amount exceeds balance" , .TypedVals ) ; balanceOf [ msg . sender ] = balance - value ; ( bool success , ) = msg . sender . call { value : value , .KeyValues } ( "" , .TypedVals ) ; require ( success , "WETH: ETH transfer failed" , .TypedVals ) ; .Statements } return true ; .Statements
if ( to != address ( 0 , .TypedVals ) && to != address ( this , .TypedVals ) ) { uint256 balance = balanceOf [ msg . sender ] ; require ( balance >= value , "WETH: transfer amount exceeds balance" , .TypedVals ) ; balanceOf [ msg . sender ] = balance - value ; balanceOf [ to ] = balanceOf [ to ] + value ; .Statements } else { uint256 balance = balanceOf [ msg . sender ] ; require ( balance >= value , "WETH: burn amount exceeds balance" , .TypedVals ) ; balanceOf [ msg . sender ] = balance - value ; ( bool success , ) = msg . sender . call { value : value , .KeyValues } ( "" , .TypedVals ) ; require ( success , "WETH: ETH transfer failed" , .TypedVals ) ; .Statements } return true ; .Statements
</contract-fn-body>
</contract-fn> <contract-fn>
<contract-fn-id>
Expand All @@ -1824,7 +1824,7 @@
ListItem ( noId )
</contract-fn-return-names>
<contract-fn-body>
if ( from != msg . sender ) { uint256 allowed = allowance [ from ] [ msg . sender ] ; if ( allowed != type ( uint256 , .TypedVals ) . max ) { require ( allowed >= value , "WETH: request exceeds allowance" , .TypedVals ) ; uint256 reduced = allowed - value ; allowance [ from ] [ msg . sender ] = reduced ; .Statements } .Statements } if ( to != address ( 0 , .TypedVals ) && to != address ( this , .TypedVals ) ) { uint256 balance = balanceOf [ from ] ; require ( balance >= value , "WETH: transfer amount exceeds balance" , .TypedVals ) ; balanceOf [ from ] = balance - value ; balanceOf [ to ] += value ; .Statements } else { uint256 balance = balanceOf [ from ] ; require ( balance >= value , "WETH: burn amount exceeds balance" , .TypedVals ) ; balanceOf [ from ] = balance - value ; ( bool success , ) = msg . sender . call { value : value , .KeyValues } ( "" , .TypedVals ) ; require ( success , "WETH: ETH transfer failed" , .TypedVals ) ; .Statements } return true ; .Statements
if ( from != msg . sender ) { uint256 allowed = allowance [ from ] [ msg . sender ] ; if ( allowed != type ( uint256 , .TypedVals ) . max ) { require ( allowed >= value , "WETH: request exceeds allowance" , .TypedVals ) ; uint256 reduced = allowed - value ; allowance [ from ] [ msg . sender ] = reduced ; .Statements } .Statements } if ( to != address ( 0 , .TypedVals ) && to != address ( this , .TypedVals ) ) { uint256 balance = balanceOf [ from ] ; require ( balance >= value , "WETH: transfer amount exceeds balance" , .TypedVals ) ; balanceOf [ from ] = balance - value ; balanceOf [ to ] = balanceOf [ to ] + value ; .Statements } else { uint256 balance = balanceOf [ from ] ; require ( balance >= value , "WETH: burn amount exceeds balance" , .TypedVals ) ; balanceOf [ from ] = balance - value ; ( bool success , ) = msg . sender . call { value : value , .KeyValues } ( "" , .TypedVals ) ; require ( success , "WETH: ETH transfer failed" , .TypedVals ) ; .Statements } return true ; .Statements
</contract-fn-body>
</contract-fn>
</contract-fns>
Expand Down
14 changes: 7 additions & 7 deletions test/regression/function.sol
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ contract UniswapV2Pair{
uint32 blockTimestamp = uint32(block.timestamp % 2**32);
uint32 timeElapsed = blockTimestamp - blockTimestampLast; // overflow is desired
if (timeElapsed > 0 && _reserve0 != 0 && _reserve1 != 0) {
price0CumulativeLast += (_reserve1/_reserve0) * timeElapsed;
price1CumulativeLast += (_reserve0/_reserve1) * timeElapsed;
price0CumulativeLast = price0CumulativeLast + (_reserve1/_reserve0) * timeElapsed;
price1CumulativeLast = price1CumulativeLast + (_reserve0/_reserve1) * timeElapsed;
}
reserve0 = uint112(balance0);
reserve1 = uint112(balance1);
Expand Down Expand Up @@ -314,7 +314,7 @@ contract WETHMock {
require(balance >= value, "WETH: transfer amount exceeds balance");

balanceOf[msg.sender] = balance - value;
balanceOf[to] += value;
balanceOf[to] = balanceOf[to] + value;
} else { // Withdraw
uint256 balance = balanceOf[msg.sender];
require(balance >= value, "WETH: burn amount exceeds balance");
Expand Down Expand Up @@ -342,7 +342,7 @@ contract WETHMock {
require(balance >= value, "WETH: transfer amount exceeds balance");

balanceOf[from] = balance - value;
balanceOf[to] += value;
balanceOf[to] = balanceOf[to] + value;
} else {
uint256 balance = balanceOf[from];
require(balance >= value, "WETH: burn amount exceeds balance");
Expand Down Expand Up @@ -463,7 +463,7 @@ contract USDCMock {

function _update(address from, address to, uint256 value) internal {
if (from == address(0)) {
_totalSupply += value;
_totalSupply = _totalSupply + value;
} else {
uint256 fromBalance = _balances[from];
require(fromBalance >= value, "USDC: insufficient balance");
Expand All @@ -472,10 +472,10 @@ contract USDCMock {
}

if (to == address(0)) {
_totalSupply -= value;
_totalSupply = _totalSupply - value;

} else {
_balances[to] += value;
_balances[to] = _balances[to] + value;
}

}
Expand Down