-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update core and add bips library * format * tests * format again
- Loading branch information
1 parent
3819809
commit 74caaa6
Showing
37 changed files
with
103 additions
and
35 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/PositionManager_burn_nonEmpty_native_withClose.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
125574 | ||
125584 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/PositionManager_burn_nonEmpty_native_withTakePair.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
125021 | ||
125031 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
132427 | ||
132446 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/PositionManager_burn_nonEmpty_withTakePair.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
131874 | ||
131893 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
146282 | ||
146294 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
154848 | ||
154872 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
154848 | ||
154872 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
154169 | ||
154193 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
111971 | ||
111980 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/PositionManager_decreaseLiquidity_withClose.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
119729 | ||
119753 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/PositionManager_decreaseLiquidity_withTakePair.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
119050 | ||
119074 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
135224 | ||
135243 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/PositionManager_decrease_burnEmpty_native.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
128371 | ||
128380 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/PositionManager_decrease_sameRange_allLiquidity.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
132416 | ||
132440 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
120305 | ||
120329 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/PositionManager_increaseLiquidity_erc20_withClose.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
159033 | ||
159057 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/PositionManager_increaseLiquidity_erc20_withSettlePair.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
157973 | ||
157997 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
140860 | ||
140872 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/PositionManager_increase_autocompoundExcessFeesCredit.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
177340 | ||
177364 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/PositionManager_increase_autocompound_clearExcess.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
148016 | ||
148040 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
364721 | ||
364745 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/PositionManager_mint_nativeWithSweep_withClose.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
373244 | ||
373268 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/PositionManager_mint_nativeWithSweep_withSettlePair.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
372467 | ||
372491 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
317569 | ||
317617 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
318239 | ||
318287 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
243808 | ||
243856 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/PositionManager_mint_settleWithBalance_sweep.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
418988 | ||
419060 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/PositionManager_mint_warmedPool_differentRange.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
323600 | ||
323648 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
420122 | ||
420170 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
419180 | ||
419228 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/PositionManager_multicall_initialize_mint.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
463927 | ||
455975 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
44876 | ||
44852 |
Submodule v4-core
updated
46 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
pragma solidity ^0.8.0; | ||
|
||
/// @title For calculating a percentage of an amount, using bips | ||
library BipsLibrary { | ||
uint256 internal constant BPS_DENOMINATOR = 10_000; | ||
|
||
/// @notice emitted when an invalid percentage is provided | ||
error InvalidBips(); | ||
|
||
/// @param amount The total amount to calculate a percentage of | ||
/// @param bips The percentage to calculate, in bips | ||
function calculatePortion(uint256 amount, uint256 bips) internal pure returns (uint256) { | ||
if (bips > BPS_DENOMINATOR) revert InvalidBips(); | ||
return (amount * bips) / BPS_DENOMINATOR; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
import "forge-std/Test.sol"; | ||
import {BipsLibrary} from "../../src/libraries/BipsLibrary.sol"; | ||
|
||
contract BipsLibraryTest is Test { | ||
using BipsLibrary for uint256; | ||
|
||
// The block gas limit set in foundry config is 300_000_000 (300M) for testing purposes | ||
uint256 BLOCK_GAS_LIMIT; | ||
|
||
function setUp() public { | ||
BLOCK_GAS_LIMIT = block.gaslimit; | ||
} | ||
|
||
function test_fuzz_calculatePortion(uint256 amount, uint256 bips) public { | ||
amount = bound(amount, 0, uint256(type(uint128).max)); | ||
if (bips > BipsLibrary.BPS_DENOMINATOR) { | ||
vm.expectRevert(BipsLibrary.InvalidBips.selector); | ||
amount.calculatePortion(bips); | ||
} else { | ||
assertEq(amount.calculatePortion(bips), amount * bips / BipsLibrary.BPS_DENOMINATOR); | ||
} | ||
} | ||
|
||
function test_fuzz_gasLimit(uint256 bips) public { | ||
if (bips > BipsLibrary.BPS_DENOMINATOR) { | ||
vm.expectRevert(BipsLibrary.InvalidBips.selector); | ||
block.gaslimit.calculatePortion(bips); | ||
} else { | ||
assertEq(block.gaslimit.calculatePortion(bips), BLOCK_GAS_LIMIT * bips / BipsLibrary.BPS_DENOMINATOR); | ||
} | ||
} | ||
|
||
function test_gasLimit_100_percent() public view { | ||
assertEq(block.gaslimit, block.gaslimit.calculatePortion(10_000)); | ||
} | ||
|
||
function test_gasLimit_1_percent() public view { | ||
// 100 bps = 1% | ||
// 1% of 30M is 300K | ||
assertEq(BLOCK_GAS_LIMIT / 100, block.gaslimit.calculatePortion(100)); | ||
} | ||
|
||
function test_gasLimit_1BP() public view { | ||
// 1bp is 0.01% | ||
// 0.01% of 30M is 300 | ||
assertEq(BLOCK_GAS_LIMIT / 10000, block.gaslimit.calculatePortion(1)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters