Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
snreynolds committed Aug 2, 2024
2 parents 7bafa14 + daf74ce commit e5c948a
Show file tree
Hide file tree
Showing 61 changed files with 562 additions and 174 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
134122
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
134260

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
126917
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
127055
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
372012
371963
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
336712
336663
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_nativeWithSweep.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
345244
345146
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_onSameTickLower.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
314694
314645
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_onSameTickUpper.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
315336
315287
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_sameRange.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
240918
240869
Original file line number Diff line number Diff line change
@@ -1 +1 @@
370018
370009
Original file line number Diff line number Diff line change
@@ -1 +1 @@
320712
320663
Original file line number Diff line number Diff line change
@@ -1 +1 @@
416365
416316
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_Bytecode.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7256
7119
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
120842
120452
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
120037
119647
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_oneForZero.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
128909
128519
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_zeroForOne.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
135739
135349
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn2Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
187091
186848
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn2Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
179026
178783
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn3Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
238470
238372
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn3Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
230429
230331
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactInputSingle.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
134624
134122
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactInputSingle_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
119727
119225
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactInputSingle_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
118900
118398
Original file line number Diff line number Diff line change
@@ -1 +1 @@
126645
126249
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut1Hop_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
120878
120482
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut1Hop_oneForZero.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
129750
129354
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut1Hop_zeroForOne.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
134551
134155
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut2Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
186512
186257
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut2Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
183407
183152
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut3Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
238515
238399
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut3Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
235434
235318
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut3Hops_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
229667
229551
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOutputSingle.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
133428
132926
Original file line number Diff line number Diff line change
@@ -1 +1 @@
125522
125020
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOutputSingle_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
119813
119311
4 changes: 2 additions & 2 deletions src/PositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ contract PositionManager is
address owner,
bytes calldata hookData
) = params.decodeMintParams();
_mint(config, liquidity, amount0Max, amount1Max, owner, hookData);
_mint(config, liquidity, amount0Max, amount1Max, _map(owner), hookData);
} else if (action == Actions.CLOSE_CURRENCY) {
Currency currency = params.decodeCurrency();
_close(currency);
Expand All @@ -128,7 +128,7 @@ contract PositionManager is
_settleWithBalance(currency);
} else if (action == Actions.SWEEP) {
(Currency currency, address to) = params.decodeCurrencyAndAddress();
_sweep(currency, to);
_sweep(currency, _map(to));
} else {
revert UnsupportedAction(action);
}
Expand Down
29 changes: 16 additions & 13 deletions src/V4Router.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ abstract contract V4Router is IV4Router, BaseActionsRouter, DeltaResolver {
// swap actions and payment actions in different blocks for gas efficiency
if (action < Actions.SETTLE) {
if (action == Actions.SWAP_EXACT_IN) {
_swapExactInput(abi.decode(params, (IV4Router.ExactInputParams)));
IV4Router.ExactInputParams calldata swapParams = params.decodeSwapExactInParams();
_swapExactInput(swapParams);
} else if (action == Actions.SWAP_EXACT_IN_SINGLE) {
_swapExactInputSingle(abi.decode(params, (IV4Router.ExactInputSingleParams)));
IV4Router.ExactInputSingleParams calldata swapParams = params.decodeSwapExactInSingleParams();
_swapExactInputSingle(swapParams);
} else if (action == Actions.SWAP_EXACT_OUT) {
_swapExactOutput(abi.decode(params, (IV4Router.ExactOutputParams)));
IV4Router.ExactOutputParams calldata swapParams = params.decodeSwapExactOutParams();
_swapExactOutput(swapParams);
} else if (action == Actions.SWAP_EXACT_OUT_SINGLE) {
_swapExactOutputSingle(abi.decode(params, (IV4Router.ExactOutputSingleParams)));
IV4Router.ExactOutputSingleParams calldata swapParams = params.decodeSwapExactOutSingleParams();
_swapExactOutputSingle(swapParams);
} else {
revert UnsupportedAction(action);
}
Expand All @@ -54,15 +58,14 @@ abstract contract V4Router is IV4Router, BaseActionsRouter, DeltaResolver {
uint256 amount = _getFullTakeAmount(currency);

// TODO should _take have a minAmountOut added slippage check?
// TODO recipient mapping
_take(currency, recipient, amount);
_take(currency, _map(recipient), amount);
} else {
revert UnsupportedAction(action);
}
}
}

function _swapExactInputSingle(IV4Router.ExactInputSingleParams memory params) private {
function _swapExactInputSingle(IV4Router.ExactInputSingleParams calldata params) private {
uint128 amountOut = _swap(
params.poolKey,
params.zeroForOne,
Expand All @@ -73,14 +76,14 @@ abstract contract V4Router is IV4Router, BaseActionsRouter, DeltaResolver {
if (amountOut < params.amountOutMinimum) revert TooLittleReceived();
}

function _swapExactInput(IV4Router.ExactInputParams memory params) private {
function _swapExactInput(IV4Router.ExactInputParams calldata params) private {
unchecked {
// Caching for gas savings
uint256 pathLength = params.path.length;
uint128 amountOut;
uint128 amountIn = params.amountIn;
Currency currencyIn = params.currencyIn;
PathKey memory pathKey;
PathKey calldata pathKey;

for (uint256 i = 0; i < pathLength; i++) {
pathKey = params.path[i];
Expand All @@ -96,7 +99,7 @@ abstract contract V4Router is IV4Router, BaseActionsRouter, DeltaResolver {
}
}

function _swapExactOutputSingle(IV4Router.ExactOutputSingleParams memory params) private {
function _swapExactOutputSingle(IV4Router.ExactOutputSingleParams calldata params) private {
uint128 amountIn = (
-_swap(
params.poolKey,
Expand All @@ -109,14 +112,14 @@ abstract contract V4Router is IV4Router, BaseActionsRouter, DeltaResolver {
if (amountIn > params.amountInMaximum) revert TooMuchRequested();
}

function _swapExactOutput(IV4Router.ExactOutputParams memory params) private {
function _swapExactOutput(IV4Router.ExactOutputParams calldata params) private {
unchecked {
// Caching for gas savings
uint256 pathLength = params.path.length;
uint128 amountIn;
uint128 amountOut = params.amountOut;
Currency currencyOut = params.currencyOut;
PathKey memory pathKey;
PathKey calldata pathKey;

for (uint256 i = pathLength; i > 0; i--) {
pathKey = params.path[i - 1];
Expand All @@ -136,7 +139,7 @@ abstract contract V4Router is IV4Router, BaseActionsRouter, DeltaResolver {
bool zeroForOne,
int256 amountSpecified,
uint160 sqrtPriceLimitX96,
bytes memory hookData
bytes calldata hookData
) private returns (int128 reciprocalAmount) {
unchecked {
BalanceDelta delta = poolManager.swap(
Expand Down
14 changes: 14 additions & 0 deletions src/base/BaseActionsRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.24;
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
import {SafeCallback} from "./SafeCallback.sol";
import {CalldataDecoder} from "../libraries/CalldataDecoder.sol";
import {Actions} from "../libraries/Actions.sol";

/// @notice Abstract contract for performing a combination of actions on Uniswap v4.
/// @dev Suggested uint256 action values are defined in Actions.sol, however any definition can be used
Expand Down Expand Up @@ -52,4 +53,17 @@ abstract contract BaseActionsRouter is SafeCallback {
/// `msg.sender` shouldnt be used, as this will be the v4 pool manager contract that calls `unlockCallback`
/// If using ReentrancyLock.sol, this function can return _getLocker()
function _msgSender() internal view virtual returns (address);

/// @notice Calculates the address for a action
/// @param recipient The address or address-flag for the action
/// @return output The resultant address for the action
function _map(address recipient) internal view returns (address) {
if (recipient == Actions.MSG_SENDER) {
return _msgSender();
} else if (recipient == Actions.ADDRESS_THIS) {
return address(this);
} else {
return recipient;
}
}
}
10 changes: 5 additions & 5 deletions src/lens/Quoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ contract Quoter is IQuoter, SafeCallback {
}

/// @dev quote an ExactInput swap along a path of tokens, then revert with the result
function _quoteExactInput(QuoteExactParams memory params) public selfOnly returns (bytes memory) {
function _quoteExactInput(QuoteExactParams calldata params) public selfOnly returns (bytes memory) {
uint256 pathLength = params.path.length;

QuoteResult memory result = QuoteResult({
Expand Down Expand Up @@ -198,7 +198,7 @@ contract Quoter is IQuoter, SafeCallback {
}

/// @dev quote an ExactInput swap on a pool, then revert with the result
function _quoteExactInputSingle(QuoteExactSingleParams memory params) public selfOnly returns (bytes memory) {
function _quoteExactInputSingle(QuoteExactSingleParams calldata params) public selfOnly returns (bytes memory) {
(, int24 tickBefore,,) = poolManager.getSlot0(params.poolKey.toId());

(BalanceDelta deltas, uint160 sqrtPriceX96After, int24 tickAfter) = _swap(
Expand All @@ -223,7 +223,7 @@ contract Quoter is IQuoter, SafeCallback {
}

/// @dev quote an ExactOutput swap along a path of tokens, then revert with the result
function _quoteExactOutput(QuoteExactParams memory params) public selfOnly returns (bytes memory) {
function _quoteExactOutput(QuoteExactParams calldata params) public selfOnly returns (bytes memory) {
uint256 pathLength = params.path.length;

QuoteResult memory result = QuoteResult({
Expand Down Expand Up @@ -269,7 +269,7 @@ contract Quoter is IQuoter, SafeCallback {
}

/// @dev quote an ExactOutput swap on a pool, then revert with the result
function _quoteExactOutputSingle(QuoteExactSingleParams memory params) public selfOnly returns (bytes memory) {
function _quoteExactOutputSingle(QuoteExactSingleParams calldata params) public selfOnly returns (bytes memory) {
// if no price limit has been specified, cache the output amount for comparison in the swap callback
if (params.sqrtPriceLimitX96 == 0) amountOutCached = params.exactAmount;

Expand Down Expand Up @@ -303,7 +303,7 @@ contract Quoter is IQuoter, SafeCallback {
bool zeroForOne,
int256 amountSpecified,
uint160 sqrtPriceLimitX96,
bytes memory hookData
bytes calldata hookData
) private returns (BalanceDelta deltas, uint160 sqrtPriceX96After, int24 tickAfter) {
deltas = poolManager.swap(
poolKey,
Expand Down
7 changes: 7 additions & 0 deletions src/libraries/Actions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@ library Actions {
// minting/burning 6909s to close deltas
uint256 constant MINT_6909 = 0x20;
uint256 constant BURN_6909 = 0x21;

// helper constants to signal certain addresses
// Used as a flag for identifying that msg.sender should be used
address internal constant MSG_SENDER = address(1);

// Used as a flag for identifying address(this) should be used
address internal constant ADDRESS_THIS = address(2);
}
Loading

0 comments on commit e5c948a

Please sign in to comment.