Skip to content

Commit

Permalink
tweak: use unchecked
Browse files Browse the repository at this point in the history
  • Loading branch information
ChefMist committed Apr 29, 2024
1 parent b0cd33f commit e1710a0
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
90479
90473
Original file line number Diff line number Diff line change
@@ -1 +1 @@
65672
65666
Original file line number Diff line number Diff line change
@@ -1 +1 @@
149227
149221
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testGasBurnOneBin.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
66851
66845
Original file line number Diff line number Diff line change
@@ -1 +1 @@
89312
89309
Original file line number Diff line number Diff line change
@@ -1 +1 @@
91297
91294
Original file line number Diff line number Diff line change
@@ -1 +1 @@
70741
70738
Original file line number Diff line number Diff line change
@@ -1 +1 @@
41768
41765
Original file line number Diff line number Diff line change
@@ -1 +1 @@
54672
54669
Original file line number Diff line number Diff line change
@@ -1 +1 @@
25040256
25040253
Original file line number Diff line number Diff line change
@@ -1 +1 @@
101510
101507
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#Vault.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7314
7318
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#lockSettledWhenFlashloan.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
156938
156932
Original file line number Diff line number Diff line change
@@ -1 +1 @@
45186
45183
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#lockSettledWhenSwap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
45185
45182
18 changes: 12 additions & 6 deletions src/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,19 @@ contract Vault is IVault, VaultToken, Ownable {

/// @inheritdoc IVault
function take(Currency currency, address to, uint256 amount) external override isLocked {
SettlementGuard.accountDelta(msg.sender, currency, amount.toInt128());
unchecked {
SettlementGuard.accountDelta(msg.sender, currency, amount.toInt128());
currency.transfer(to, amount);
}
reservesOfVault[currency] -= amount;
currency.transfer(to, amount);
}

/// @inheritdoc IVault
function mint(address to, Currency currency, uint256 amount) external override isLocked {
SettlementGuard.accountDelta(msg.sender, currency, amount.toInt128());
_mint(to, currency, amount);
unchecked {
SettlementGuard.accountDelta(msg.sender, currency, amount.toInt128());
_mint(to, currency, amount);
}
}

/// @inheritdoc IVault
Expand Down Expand Up @@ -156,8 +160,10 @@ contract Vault is IVault, VaultToken, Ownable {
/// @notice settle all outstanding debt if amount is 0
/// It will revert if target has negative delta
if (amount == 0) amount = SettlementGuard.getCurrencyDelta(target, currency).toUint256();
SettlementGuard.accountDelta(msg.sender, currency, amount.toInt128());
SettlementGuard.accountDelta(target, currency, -(amount.toInt128()));
unchecked {
SettlementGuard.accountDelta(msg.sender, currency, amount.toInt128());
SettlementGuard.accountDelta(target, currency, -(amount.toInt128()));
}
}

/// @inheritdoc IVault
Expand Down

0 comments on commit e1710a0

Please sign in to comment.