Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/V4Router.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ abstract contract V4Router is IV4Router, BaseActionsRouter, DeltaResolver {
(Currency currency, address recipient, uint256 bips) = params.decodeCurrencyAddressAndUint256();
_take(currency, _mapRecipient(recipient), _getFullCredit(currency).calculatePortion(bips));
return;
} else if (action == Actions.SWAP_EXACT_IN_RAW) {
(PoolKey memory poolKey, SwapParams memory swapParams, bytes memory hookData) = params.decodeSwapExactInRawParams();
_rawSwap(poolKey, swapParams, hookData);
return;
}
}
revert UnsupportedAction(action);
Expand Down Expand Up @@ -153,6 +157,22 @@ abstract contract V4Router is IV4Router, BaseActionsRouter, DeltaResolver {
}
}

function _rawSwap(PoolKey memory poolKey, SwapParams memory swapParams, bytes memory hookData)
private
returns (int128 reciprocalAmount)
{
// for protection of exactOut swaps, sqrtPriceLimit is not exposed as a feature in this contract
unchecked {
BalanceDelta delta = poolManager.swap(
poolKey,
swapParams,
hookData
);

reciprocalAmount = (swapParams.amountSpecified < 0) ? delta.amount1() : delta.amount0();
}
}

function _swap(PoolKey memory poolKey, bool zeroForOne, int256 amountSpecified, bytes calldata hookData)
private
returns (int128 reciprocalAmount)
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/Actions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ library Actions {
// note this is not supported in the position manager or router
uint256 internal constant MINT_6909 = 0x17;
uint256 internal constant BURN_6909 = 0x18;

uint256 internal constant SWAP_EXACT_IN_RAW = 0x19;
}
10 changes: 10 additions & 0 deletions src/libraries/CalldataDecoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.0;
import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";
import {IV4Router} from "../interfaces/IV4Router.sol";
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";

/// @title Library for abi decoding in calldata
library CalldataDecoder {
Expand Down Expand Up @@ -388,4 +389,13 @@ library CalldataDecoder {
}
}
}

/// @dev equivalent to: abi.decode(params, (IV4Router.ExactInputWithLimitParams))
function decodeSwapExactInRawParams(bytes calldata params)
internal
pure
returns (PoolKey memory poolKey, SwapParams memory swapParams, bytes memory hookData)
{
(poolKey, swapParams, hookData) = abi.decode(params, (PoolKey, SwapParams, bytes));
}
}