Skip to content

Commit

Permalink
Merge branch 'main' into update-native-snaps
Browse files Browse the repository at this point in the history
  • Loading branch information
marktoda committed Nov 1, 2024
2 parents 589b92e + 2768c3d commit 9ee4b3d
Show file tree
Hide file tree
Showing 25 changed files with 418 additions and 162 deletions.
1 change: 0 additions & 1 deletion .forge-snapshots/positionDescriptor bytecode size.snap

This file was deleted.

3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "lib/permit2"]
path = lib/permit2
url = https://github.com/Uniswap/permit2
[submodule "lib/forge-gas-snapshot"]
path = lib/forge-gas-snapshot
url = https://github.com/marktoda/forge-gas-snapshot
1 change: 1 addition & 0 deletions lib/forge-gas-snapshot
Submodule forge-gas-snapshot added at 9fc447
2 changes: 1 addition & 1 deletion lib/v4-core
Submodule v4-core updated 161 files
2 changes: 1 addition & 1 deletion script/01_PoolManager.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract DeployPoolManager is Script {
function run() public returns (IPoolManager manager) {
vm.startBroadcast();

manager = new PoolManager();
manager = new PoolManager(address(this));
console2.log("PoolManager", address(manager));

vm.stopBroadcast();
Expand Down
2 changes: 1 addition & 1 deletion snapshots/BaseActionsRouterTest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"BaseActionsRouter_mock10commands": "60677"
"BaseActionsRouter_mock10commands": "60674"
}
8 changes: 4 additions & 4 deletions snapshots/PaymentsTests.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Payments_swap_settleFromCaller_takeAllToMsgSender": "129642",
"Payments_swap_settleFromCaller_takeAllToSpecifiedAddress": "131705",
"Payments_swap_settleWithBalance_takeAllToMsgSender": "123910",
"Payments_swap_settleWithBalance_takeAllToSpecifiedAddress": "124052"
"Payments_swap_settleFromCaller_takeAllToMsgSender": "129438",
"Payments_swap_settleFromCaller_takeAllToSpecifiedAddress": "131502",
"Payments_swap_settleWithBalance_takeAllToMsgSender": "123707",
"Payments_swap_settleWithBalance_takeAllToSpecifiedAddress": "123849"
}
70 changes: 35 additions & 35 deletions snapshots/PosMGasTest.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
{
"PositionManager_burn_empty": "50481",
"PositionManager_burn_empty_native": "50481",
"PositionManager_burn_nonEmpty_native_withClose": "125659",
"PositionManager_burn_nonEmpty_native_withTakePair": "125141",
"PositionManager_burn_nonEmpty_withClose": "132521",
"PositionManager_burn_nonEmpty_withTakePair": "132004",
"PositionManager_collect_native": "146388",
"PositionManager_collect_sameRange": "154966",
"PositionManager_collect_withClose": "154966",
"PositionManager_collect_withTakePair": "154331",
"PositionManager_decreaseLiquidity_native": "112056",
"PositionManager_decreaseLiquidity_withClose": "119847",
"PositionManager_decreaseLiquidity_withTakePair": "119212",
"PositionManager_decrease_burnEmpty": "135318",
"PositionManager_decrease_burnEmpty_native": "128456",
"PositionManager_decrease_sameRange_allLiquidity": "132534",
"PositionManager_decrease_take_take": "120467",
"PositionManager_increaseLiquidity_erc20_withClose": "159127",
"PositionManager_increaseLiquidity_erc20_withSettlePair": "158079",
"PositionManager_increaseLiquidity_native": "140942",
"PositionManager_increase_autocompoundExactUnclaimedFees": "136403",
"PositionManager_increase_autocompoundExcessFeesCredit": "177458",
"PositionManager_increase_autocompound_clearExcess": "148084",
"PositionManager_mint_native": "364815",
"PositionManager_mint_nativeWithSweep_withClose": "373334",
"PositionManager_mint_nativeWithSweep_withSettlePair": "372569",
"PositionManager_mint_onSameTickLower": "317687",
"PositionManager_mint_onSameTickUpper": "318357",
"PositionManager_mint_sameRange": "243926",
"PositionManager_mint_settleWithBalance_sweep": "419134",
"PositionManager_mint_warmedPool_differentRange": "323718",
"PositionManager_mint_withClose": "420240",
"PositionManager_mint_withSettlePair": "419310",
"PositionManager_multicall_initialize_mint": "456088",
"PositionManager_burn_empty": "50479",
"PositionManager_burn_empty_native": "50479",
"PositionManager_burn_nonEmpty_native_withClose": "125652",
"PositionManager_burn_nonEmpty_native_withTakePair": "125134",
"PositionManager_burn_nonEmpty_withClose": "132512",
"PositionManager_burn_nonEmpty_withTakePair": "131994",
"PositionManager_collect_native": "146379",
"PositionManager_collect_sameRange": "154954",
"PositionManager_collect_withClose": "154954",
"PositionManager_collect_withTakePair": "154319",
"PositionManager_decreaseLiquidity_native": "112048",
"PositionManager_decreaseLiquidity_withClose": "119835",
"PositionManager_decreaseLiquidity_withTakePair": "119200",
"PositionManager_decrease_burnEmpty": "135308",
"PositionManager_decrease_burnEmpty_native": "128448",
"PositionManager_decrease_sameRange_allLiquidity": "132522",
"PositionManager_decrease_take_take": "120455",
"PositionManager_increaseLiquidity_erc20_withClose": "158871",
"PositionManager_increaseLiquidity_erc20_withSettlePair": "157823",
"PositionManager_increaseLiquidity_native": "140808",
"PositionManager_increase_autocompoundExactUnclaimedFees": "136396",
"PositionManager_increase_autocompoundExcessFeesCredit": "177446",
"PositionManager_increase_autocompound_clearExcess": "148160",
"PositionManager_mint_native": "364681",
"PositionManager_mint_nativeWithSweep_withClose": "373199",
"PositionManager_mint_nativeWithSweep_withSettlePair": "372435",
"PositionManager_mint_onSameTickLower": "317431",
"PositionManager_mint_onSameTickUpper": "318101",
"PositionManager_mint_sameRange": "243670",
"PositionManager_mint_settleWithBalance_sweep": "418878",
"PositionManager_mint_warmedPool_differentRange": "323462",
"PositionManager_mint_withClose": "419984",
"PositionManager_mint_withSettlePair": "419054",
"PositionManager_multicall_initialize_mint": "455828",
"PositionManager_permit": "79076",
"PositionManager_permit_secondPosition": "61976",
"PositionManager_permit_twice": "44876",
"PositionManager_permit_twice": "44852",
"PositionManager_subscribe": "88168",
"PositionManager_unsubscribe": "63080"
}
2 changes: 1 addition & 1 deletion snapshots/PositionDescriptorTest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"positionDescriptor bytecode size": "31443"
"positionDescriptor bytecode size": "31728"
}
26 changes: 13 additions & 13 deletions snapshots/QuoterTest.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"Quoter_exactInputSingle_oneForZero_multiplePositions": "143930",
"Quoter_exactInputSingle_zeroForOne_multiplePositions": "149382",
"Quoter_exactOutputSingle_oneForZero": "78203",
"Quoter_exactOutputSingle_zeroForOne": "82626",
"Quoter_quoteExactInput_oneHop_1TickLoaded": "120491",
"Quoter_quoteExactInput_oneHop_initializedAfter": "145414",
"Quoter_quoteExactInput_oneHop_startingInitialized": "79437",
"Quoter_quoteExactInput_twoHops": "201179",
"Quoter_quoteExactOutput_oneHop_1TickLoaded": "119782",
"Quoter_quoteExactOutput_oneHop_2TicksLoaded": "149919",
"Quoter_quoteExactOutput_oneHop_initializedAfter": "119850",
"Quoter_quoteExactOutput_oneHop_startingInitialized": "96549",
"Quoter_quoteExactOutput_twoHops": "200630"
"Quoter_exactInputSingle_oneForZero_multiplePositions": "144020",
"Quoter_exactInputSingle_zeroForOne_multiplePositions": "149287",
"Quoter_exactOutputSingle_oneForZero": "78196",
"Quoter_exactOutputSingle_zeroForOne": "82546",
"Quoter_quoteExactInput_oneHop_1TickLoaded": "120406",
"Quoter_quoteExactInput_oneHop_initializedAfter": "145504",
"Quoter_quoteExactInput_oneHop_startingInitialized": "79438",
"Quoter_quoteExactInput_twoHops": "201071",
"Quoter_quoteExactOutput_oneHop_1TickLoaded": "119672",
"Quoter_quoteExactOutput_oneHop_2TicksLoaded": "149779",
"Quoter_quoteExactOutput_oneHop_initializedAfter": "119740",
"Quoter_quoteExactOutput_oneHop_startingInitialized": "96472",
"Quoter_quoteExactOutput_twoHops": "200486"
}
10 changes: 5 additions & 5 deletions snapshots/StateViewTest.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"StateView_extsload_getFeeGrowthGlobals": "2259",
"StateView_extsload_getFeeGrowthInside": "8003",
"StateView_extsload_getFeeGrowthGlobals": "2256",
"StateView_extsload_getFeeGrowthInside": "7994",
"StateView_extsload_getLiquidity": "1399",
"StateView_extsload_getPositionInfo": "2829",
"StateView_extsload_getPositionInfo": "2826",
"StateView_extsload_getPositionLiquidity": "1651",
"StateView_extsload_getSlot0": "1446",
"StateView_extsload_getTickBitmap": "1392",
"StateView_extsload_getTickFeeGrowthOutside": "2546",
"StateView_extsload_getTickInfo": "2761",
"StateView_extsload_getTickFeeGrowthOutside": "2543",
"StateView_extsload_getTickInfo": "2758",
"StateView_extsload_getTickLiquidity": "1646"
}
48 changes: 24 additions & 24 deletions snapshots/V4RouterTest.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"V4Router_Bytecode": "7063",
"V4Router_ExactIn1Hop_nativeIn": "115753",
"V4Router_ExactIn1Hop_nativeOut": "116070",
"V4Router_ExactIn1Hop_oneForZero": "124888",
"V4Router_ExactIn1Hop_zeroForOne": "130611",
"V4Router_ExactIn2Hops": "185452",
"V4Router_ExactIn2Hops_nativeIn": "170594",
"V4Router_ExactIn3Hops": "240296",
"V4Router_ExactIn3Hops_nativeIn": "225438",
"V4Router_ExactInputSingle": "129642",
"V4Router_ExactInputSingle_nativeIn": "114784",
"V4Router_ExactInputSingle_nativeOut": "115069",
"V4Router_ExactOut1Hop_nativeIn_sweepETH": "122016",
"V4Router_ExactOut1Hop_nativeOut": "117134",
"V4Router_ExactOut1Hop_oneForZero": "125952",
"V4Router_ExactOut1Hop_zeroForOne": "129897",
"V4Router_ExactOut2Hops": "183800",
"V4Router_ExactOut2Hops_nativeIn": "175919",
"V4Router_ExactOut3Hops": "237734",
"V4Router_ExactOut3Hops_nativeIn": "229853",
"V4Router_ExactOut3Hops_nativeOut": "217089",
"V4Router_ExactOutputSingle": "128925",
"V4Router_ExactOutputSingle_nativeIn_sweepETH": "121044",
"V4Router_ExactOutputSingle_nativeOut": "116236"
"V4Router_Bytecode": "7158",
"V4Router_ExactIn1Hop_nativeIn": "115672",
"V4Router_ExactIn1Hop_nativeOut": "115929",
"V4Router_ExactIn1Hop_oneForZero": "124744",
"V4Router_ExactIn1Hop_zeroForOne": "130408",
"V4Router_ExactIn2Hops": "185177",
"V4Router_ExactIn2Hops_nativeIn": "170441",
"V4Router_ExactIn3Hops": "239949",
"V4Router_ExactIn3Hops_nativeIn": "225213",
"V4Router_ExactInputSingle": "129438",
"V4Router_ExactInputSingle_nativeIn": "114702",
"V4Router_ExactInputSingle_nativeOut": "114927",
"V4Router_ExactOut1Hop_nativeIn_sweepETH": "121930",
"V4Router_ExactOut1Hop_nativeOut": "117002",
"V4Router_ExactOut1Hop_oneForZero": "125817",
"V4Router_ExactOut1Hop_zeroForOne": "129689",
"V4Router_ExactOut2Hops": "183515",
"V4Router_ExactOut2Hops_nativeIn": "175756",
"V4Router_ExactOut3Hops": "237372",
"V4Router_ExactOut3Hops_nativeIn": "229613",
"V4Router_ExactOut3Hops_nativeOut": "216949",
"V4Router_ExactOutputSingle": "128716",
"V4Router_ExactOutputSingle_nativeIn_sweepETH": "120957",
"V4Router_ExactOutputSingle_nativeOut": "116103"
}
9 changes: 6 additions & 3 deletions src/PositionDescriptor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,17 @@ contract PositionDescriptor is IPositionDescriptor {
}
(, int24 tick,,) = poolManager.getSlot0(poolKey.toId());

address currency0 = Currency.unwrap(poolKey.currency0);
address currency1 = Currency.unwrap(poolKey.currency1);

// If possible, flip currencies to get the larger currency as the base currency, so that the price (quote/base) is more readable
// flip if currency0 priority is greater than currency1 priority
bool _flipRatio = flipRatio(Currency.unwrap(poolKey.currency0), Currency.unwrap(poolKey.currency1));
bool _flipRatio = flipRatio(currency0, currency1);

// If not flipped, quote currency is currency1, base currency is currency0
// If flipped, quote currency is currency0, base currency is currency1
Currency quoteCurrency = !_flipRatio ? poolKey.currency1 : poolKey.currency0;
Currency baseCurrency = !_flipRatio ? poolKey.currency0 : poolKey.currency1;
address quoteCurrency = !_flipRatio ? currency1 : currency0;
address baseCurrency = !_flipRatio ? currency0 : currency1;

return Descriptor.constructTokenURI(
Descriptor.ConstructTokenURIParams({
Expand Down
12 changes: 8 additions & 4 deletions src/base/Notifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {PositionInfo} from "../libraries/PositionInfoLibrary.sol";

/// @notice Notifier is used to opt in to sending updates to external contracts about position modifications or transfers
abstract contract Notifier is INotifier {
using CustomRevert for bytes4;
using CustomRevert for *;

ISubscriber private constant NO_SUBSCRIBER = ISubscriber(address(0));

Expand Down Expand Up @@ -53,7 +53,7 @@ abstract contract Notifier is INotifier {
bool success = _call(newSubscriber, abi.encodeCall(ISubscriber.notifySubscribe, (tokenId, data)));

if (!success) {
Wrap__SubscriptionReverted.selector.bubbleUpAndRevertWith(newSubscriber);
newSubscriber.bubbleUpAndRevertWith(ISubscriber.notifySubscribe.selector, SubscriptionReverted.selector);
}

emit Subscription(tokenId, newSubscriber);
Expand Down Expand Up @@ -97,7 +97,9 @@ abstract contract Notifier is INotifier {
);

if (!success) {
Wrap__ModifyLiquidityNotificationReverted.selector.bubbleUpAndRevertWith(address(_subscriber));
address(_subscriber).bubbleUpAndRevertWith(
ISubscriber.notifyModifyLiquidity.selector, ModifyLiquidityNotificationReverted.selector
);
}
}

Expand All @@ -108,7 +110,9 @@ abstract contract Notifier is INotifier {
_call(address(_subscriber), abi.encodeCall(ISubscriber.notifyTransfer, (tokenId, previousOwner, newOwner)));

if (!success) {
Wrap__TransferNotificationReverted.selector.bubbleUpAndRevertWith(address(_subscriber));
address(_subscriber).bubbleUpAndRevertWith(
ISubscriber.notifyTransfer.selector, TransferNotificationReverted.selector
);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/interfaces/INotifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ interface INotifier {
/// @notice Thrown when a user specifies a gas limit too low to avoid valid unsubscribe notifications
error GasLimitTooLow();
/// @notice Wraps the revert message of the subscriber contract on a reverting subscription
error Wrap__SubscriptionReverted(address subscriber, bytes reason);
error SubscriptionReverted(address subscriber, bytes reason);
/// @notice Wraps the revert message of the subscriber contract on a reverting modify liquidity notification
error Wrap__ModifyLiquidityNotificationReverted(address subscriber, bytes reason);
error ModifyLiquidityNotificationReverted(address subscriber, bytes reason);
/// @notice Wraps the revert message of the subscriber contract on a reverting transfer notification
error Wrap__TransferNotificationReverted(address subscriber, bytes reason);
error TransferNotificationReverted(address subscriber, bytes reason);
/// @notice Thrown when a tokenId already has a subscriber
error AlreadySubscribed(uint256 tokenId, address subscriber);

Expand Down
33 changes: 16 additions & 17 deletions src/libraries/Descriptor.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import {Currency, CurrencyLibrary} from "@uniswap/v4-core/src/types/Currency.sol";
import {TickMath} from "@uniswap/v4-core/src/libraries/TickMath.sol";
import {FullMath} from "@uniswap/v4-core/src/libraries/FullMath.sol";
import {LPFeeLibrary} from "@uniswap/v4-core/src/libraries/LPFeeLibrary.sol";
Expand All @@ -23,8 +22,8 @@ library Descriptor {

struct ConstructTokenURIParams {
uint256 tokenId;
Currency quoteCurrency;
Currency baseCurrency;
address quoteCurrency;
address baseCurrency;
string quoteCurrencySymbol;
string baseCurrencySymbol;
uint8 quoteCurrencyDecimals;
Expand Down Expand Up @@ -52,8 +51,8 @@ library Descriptor {
string memory descriptionPartTwo = generateDescriptionPartTwo(
params.tokenId.toString(),
escapeSpecialCharacters(params.baseCurrencySymbol),
addressToString(Currency.unwrap(params.quoteCurrency)),
addressToString(Currency.unwrap(params.baseCurrency)),
params.quoteCurrency == address(0) ? "Native" : addressToString(params.quoteCurrency),
params.baseCurrency == address(0) ? "Native" : addressToString(params.baseCurrency),
params.hooks == address(0) ? "No Hook" : addressToString(params.hooks),
feeToPercentString(params.fee)
);
Expand Down Expand Up @@ -462,8 +461,8 @@ library Descriptor {
/// @return svg The SVG image as a string
function generateSVGImage(ConstructTokenURIParams memory params) internal pure returns (string memory svg) {
SVG.SVGParams memory svgParams = SVG.SVGParams({
quoteCurrency: addressToString(Currency.unwrap(params.quoteCurrency)),
baseCurrency: addressToString(Currency.unwrap(params.baseCurrency)),
quoteCurrency: addressToString(params.quoteCurrency),
baseCurrency: addressToString(params.baseCurrency),
hooks: params.hooks,
quoteCurrencySymbol: params.quoteCurrencySymbol,
baseCurrencySymbol: params.baseCurrencySymbol,
Expand All @@ -473,16 +472,16 @@ library Descriptor {
tickSpacing: params.tickSpacing,
overRange: overRange(params.tickLower, params.tickUpper, params.tickCurrent),
tokenId: params.tokenId,
color0: currencyToColorHex(params.quoteCurrency.toId(), 136),
color1: currencyToColorHex(params.baseCurrency.toId(), 136),
color2: currencyToColorHex(params.quoteCurrency.toId(), 0),
color3: currencyToColorHex(params.baseCurrency.toId(), 0),
x1: scale(getCircleCoord(params.quoteCurrency.toId(), 16, params.tokenId), 0, 255, 16, 274),
y1: scale(getCircleCoord(params.baseCurrency.toId(), 16, params.tokenId), 0, 255, 100, 484),
x2: scale(getCircleCoord(params.quoteCurrency.toId(), 32, params.tokenId), 0, 255, 16, 274),
y2: scale(getCircleCoord(params.baseCurrency.toId(), 32, params.tokenId), 0, 255, 100, 484),
x3: scale(getCircleCoord(params.quoteCurrency.toId(), 48, params.tokenId), 0, 255, 16, 274),
y3: scale(getCircleCoord(params.baseCurrency.toId(), 48, params.tokenId), 0, 255, 100, 484)
color0: currencyToColorHex(uint256(uint160(params.quoteCurrency)), 136),
color1: currencyToColorHex(uint256(uint160(params.baseCurrency)), 136),
color2: currencyToColorHex(uint256(uint160(params.quoteCurrency)), 0),
color3: currencyToColorHex(uint256(uint160(params.baseCurrency)), 0),
x1: scale(getCircleCoord(uint256(uint160(params.quoteCurrency)), 16, params.tokenId), 0, 255, 16, 274),
y1: scale(getCircleCoord(uint256(uint160(params.baseCurrency)), 16, params.tokenId), 0, 255, 100, 484),
x2: scale(getCircleCoord(uint256(uint160(params.quoteCurrency)), 32, params.tokenId), 0, 255, 16, 274),
y2: scale(getCircleCoord(uint256(uint160(params.baseCurrency)), 32, params.tokenId), 0, 255, 100, 484),
x3: scale(getCircleCoord(uint256(uint160(params.quoteCurrency)), 48, params.tokenId), 0, 255, 16, 274),
y3: scale(getCircleCoord(uint256(uint160(params.baseCurrency)), 48, params.tokenId), 0, 255, 100, 484)
});
return SVG.generateSVG(svgParams);
Expand Down
1 change: 0 additions & 1 deletion src/libraries/SVG.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import {Currency, CurrencyLibrary} from "@uniswap/v4-core/src/types/Currency.sol";
import {IHooks} from "@uniswap/v4-core/src/interfaces/IHooks.sol";
import {BitMath} from "@uniswap/v4-core/src/libraries/BitMath.sol";
import {Strings} from "openzeppelin-contracts/contracts/utils/Strings.sol";
Expand Down
Loading

0 comments on commit 9ee4b3d

Please sign in to comment.