Skip to content

Commit

Permalink
Merge branch 'main' into feat/tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ChefMist authored May 7, 2024
2 parents b0cd33f + ee06ebc commit 87694f1
Show file tree
Hide file tree
Showing 91 changed files with 1,810 additions and 248 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/BinHookTest#testBurnSucceedsWithHook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
143699
181146
Original file line number Diff line number Diff line change
@@ -1 +1 @@
135043
185453
Original file line number Diff line number Diff line change
@@ -1 +1 @@
108914
136997
2 changes: 1 addition & 1 deletion .forge-snapshots/BinHookTest#testMintSucceedsWithHook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
301091
329657
2 changes: 1 addition & 1 deletion .forge-snapshots/BinHookTest#testSwapSucceedsWithHook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
139136
192259
Original file line number Diff line number Diff line change
@@ -1 +1 @@
90479
142035
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2242
1866
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5062
32483
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9179
30395
Original file line number Diff line number Diff line change
@@ -1 +1 @@
65672
158207
Original file line number Diff line number Diff line change
@@ -1 +1 @@
149227
303831
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testGasBurnOneBin.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
66851
139396
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testGasDonate.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
52444
125193
Original file line number Diff line number Diff line change
@@ -1 +1 @@
968444
1013119
Original file line number Diff line number Diff line change
@@ -1 +1 @@
119958
341133
Original file line number Diff line number Diff line change
@@ -1 +1 @@
337634
380471
Original file line number Diff line number Diff line change
@@ -1 +1 @@
54695
149232
Original file line number Diff line number Diff line change
@@ -1 +1 @@
89312
187313
Original file line number Diff line number Diff line change
@@ -1 +1 @@
91297
193298
Original file line number Diff line number Diff line change
@@ -1 +1 @@
70741
145662
Original file line number Diff line number Diff line change
@@ -1 +1 @@
319341
327364
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testNoOpGas_Burn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
41503
76641
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19392
54134
Original file line number Diff line number Diff line change
@@ -1 +1 @@
37117
64622
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testNoOpGas_Mint.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
39136
69634
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testNoOpGas_Swap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22507
57563
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8148
41349
Original file line number Diff line number Diff line change
@@ -1 +1 @@
348420
348420
Original file line number Diff line number Diff line change
@@ -1 +1 @@
58968
58968
Original file line number Diff line number Diff line change
@@ -1 +1 @@
242013
242013
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#donateBothTokens.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
82514
175518
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#gasDonateOneToken.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
52476
116900
Original file line number Diff line number Diff line change
@@ -1 +1 @@
36547
59356
Original file line number Diff line number Diff line change
@@ -1 +1 @@
41768
41768
Original file line number Diff line number Diff line change
@@ -1 +1 @@
54672
148767
Original file line number Diff line number Diff line change
@@ -1 +1 @@
100748
177177
Original file line number Diff line number Diff line change
@@ -1 +1 @@
25040256
25040256
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_simple.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
35872
78822
Original file line number Diff line number Diff line change
@@ -1 +1 @@
101510
158284
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_withHooks.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
41522
95329
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_withNative.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
35875
78825
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4835
32257
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19218
53926
Original file line number Diff line number Diff line change
@@ -1 +1 @@
37497
65078
Original file line number Diff line number Diff line change
@@ -1 +1 @@
29405
60244
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#testNoOp_gas_Swap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
21667
56919
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPositionTest#Position_update_add.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1545
1427
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1812
1812
2 changes: 1 addition & 1 deletion .forge-snapshots/ExtsloadTest#extsloadInBatch.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11352
11374
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#Vault.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7314
7437
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#collectFee.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
25576
53360
Original file line number Diff line number Diff line change
@@ -1 +1 @@
120730
159350
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#lockSettledWhenFlashloan.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
156938
103575
Original file line number Diff line number Diff line change
@@ -1 +1 @@
45186
118273
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#lockSettledWhenSwap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
45185
118272
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#registerPoolManager.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24484
47916
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#testLock_NoOp.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11327
32989
Original file line number Diff line number Diff line change
@@ -1 +1 @@
71681
100035
Original file line number Diff line number Diff line change
@@ -1 +1 @@
33288
55142
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ jobs:
version: nightly

- name: Run tests
run: forge test -vvv
run: forge test --isolate -vvv
env:
FOUNDRY_PROFILE: ${{ github.ref_name == 'main' && 'ci_main' || 'ci' }}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
## Running test

1. Install dependencies with `forge install` and `yarn`
2. Run test with `forge test`
2. Run test with `forge test --isolate`

See https://github.com/pancakeswap/pancake-v4-core/pull/35 on why `--isolate` flag is used.

## Update dependencies

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
},
"scripts": {
"compile": "forge compile",
"test": "forge test",
"dev": "forge test -vvv -w",
"snapshot": "rm -fr .forge-snapshots && forge test",
"test": "forge test --isolate",
"dev": "forge test --isolate -vvv -w",
"snapshot": "rm -fr .forge-snapshots && forge test --isolate",
"prettier": "forge fmt src/ && forge fmt test/",
"prettier-check": "forge fmt --check",
"prepare": "husky install"
Expand Down
30 changes: 19 additions & 11 deletions src/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ contract Vault is IVault, VaultToken, Ownable {
_;
}

/// @notice receive native tokens for native pools
receive() external payable {}

/// @inheritdoc IVault
function registerPoolManager(address poolManager) external override onlyOwner {
isPoolManagerRegistered[poolManager] = true;
Expand Down Expand Up @@ -107,7 +104,7 @@ 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());
reservesOfVault[currency] -= amount;
if (!currency.isNative()) reservesOfVault[currency] -= amount;
currency.transfer(to, amount);
}

Expand All @@ -119,9 +116,15 @@ contract Vault is IVault, VaultToken, Ownable {

/// @inheritdoc IVault
function settle(Currency currency) external payable override isLocked returns (uint256 paid) {
uint256 reservesBefore = reservesOfVault[currency];
reservesOfVault[currency] = currency.balanceOfSelf();
paid = reservesOfVault[currency] - reservesBefore;
if (!currency.isNative()) {
if (msg.value > 0) revert SettleNonNativeCurrencyWithValue();
uint256 reservesBefore = reservesOfVault[currency];
reservesOfVault[currency] = currency.balanceOfSelf();
paid = reservesOfVault[currency] - reservesBefore;
} else {
paid = msg.value;
}

// subtraction must be safe
SettlementGuard.accountDelta(msg.sender, currency, -(paid.toInt128()));
}
Expand All @@ -133,9 +136,14 @@ contract Vault is IVault, VaultToken, Ownable {
isLocked
returns (uint256 paid, uint256 refund)
{
uint256 reservesBefore = reservesOfVault[currency];
reservesOfVault[currency] = currency.balanceOfSelf();
paid = reservesOfVault[currency] - reservesBefore;
if (!currency.isNative()) {
if (msg.value > 0) revert SettleNonNativeCurrencyWithValue();
uint256 reservesBefore = reservesOfVault[currency];
reservesOfVault[currency] = currency.balanceOfSelf();
paid = reservesOfVault[currency] - reservesBefore;
} else {
paid = msg.value;
}

int256 currentDelta = SettlementGuard.getCurrencyDelta(msg.sender, currency);
if (currentDelta >= 0) {
Expand Down Expand Up @@ -169,7 +177,7 @@ contract Vault is IVault, VaultToken, Ownable {
/// @inheritdoc IVault
function collectFee(Currency currency, uint256 amount, address recipient) external {
reservesOfPoolManager[IPoolManager(msg.sender)][currency] -= amount;
reservesOfVault[currency] -= amount;
if (!currency.isNative()) reservesOfVault[currency] -= amount;

currency.transfer(recipient, amount);
}
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/IVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ interface IVault is IVaultToken {
/// @param locker The address of the current locker
error LockerAlreadySet(address locker);

/// @notice Thrown when passing in msg.value for non-native currency
error SettleNonNativeCurrencyWithValue();

/// @notice Thrown when there is no locker
error NoLocker();

Expand Down
Loading

0 comments on commit 87694f1

Please sign in to comment.