Skip to content
Merged
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
6 changes: 3 additions & 3 deletions contracts/UniversalRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {MigratorImmutables, MigratorParameters} from './modules/MigratorImmutabl

contract UniversalRouter is IUniversalRouter, Dispatcher {
constructor(RouterParameters memory params)
UniswapImmutables(
UniswapParameters(params.v2Factory, params.v3Factory, params.pairInitCodeHash, params.poolInitCodeHash)
)
UniswapImmutables(UniswapParameters(
params.v2Factory, params.v3Factory, params.pairInitCodeHash, params.poolInitCodeHash
))
V4SwapRouter(params.v4PoolManager)
PaymentsImmutables(PaymentsParameters(params.permit2, params.weth9))
MigratorImmutables(MigratorParameters(params.v3NFTPositionManager, params.v4PositionManager))
Expand Down
34 changes: 18 additions & 16 deletions contracts/base/Dispatcher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,15 @@ abstract contract Dispatcher is Payments, V2SwapRouter, V3SwapRouter, V4SwapRout
permitBatch := add(inputs.offset, calldataload(inputs.offset))
}
bytes calldata data = inputs.toBytes(1);
(success, output) = address(PERMIT2).call(
abi.encodeWithSignature(
'permit(address,((address,uint160,uint48,uint48)[],address,uint256),bytes)',
msgSender(),
permitBatch,
data
)
);
(success, output) = address(PERMIT2)
.call(
abi.encodeWithSignature(
'permit(address,((address,uint160,uint48,uint48)[],address,uint256),bytes)',
msgSender(),
permitBatch,
data
)
);
} else if (command == Commands.SWEEP) {
// equivalent: abi.decode(inputs, (address, address, uint256))
address token;
Expand Down Expand Up @@ -192,14 +193,15 @@ abstract contract Dispatcher is Payments, V2SwapRouter, V3SwapRouter, V4SwapRout
permitSingle := inputs.offset
}
bytes calldata data = inputs.toBytes(6); // PermitSingle takes first 6 slots (0..5)
(success, output) = address(PERMIT2).call(
abi.encodeWithSignature(
'permit(address,((address,uint160,uint48,uint48),address,uint256),bytes)',
msgSender(),
permitSingle,
data
)
);
(success, output) = address(PERMIT2)
.call(
abi.encodeWithSignature(
'permit(address,((address,uint160,uint48,uint48),address,uint256),bytes)',
msgSender(),
permitSingle,
data
)
);
} else if (command == Commands.WRAP_ETH) {
// equivalent: abi.decode(inputs, (address, uint256))
address recipient;
Expand Down
4 changes: 2 additions & 2 deletions contracts/libraries/Locker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ library Locker {

function set(address locker) internal {
// The locker is always msg.sender or address(0) so does not need to be cleaned
assembly ("memory-safe") {
assembly ('memory-safe') {
tstore(LOCKER_SLOT, locker)
}
}

function get() internal view returns (address locker) {
assembly ("memory-safe") {
assembly ('memory-safe') {
locker := tload(LOCKER_SLOT)
}
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/libraries/MaxInputAmount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ library MaxInputAmount {
bytes32 constant MAX_AMOUNT_IN_SLOT = 0xaf28d9864a81dfdf71cab65f4e5d79a0cf9b083905fb8971425e6cb581b3f692;

function set(uint256 maxAmountIn) internal {
assembly ("memory-safe") {
assembly ('memory-safe') {
tstore(MAX_AMOUNT_IN_SLOT, maxAmountIn)
}
}

function get() internal view returns (uint256 maxAmountIn) {
assembly ("memory-safe") {
assembly ('memory-safe') {
maxAmountIn := tload(MAX_AMOUNT_IN_SLOT)
}
}
Expand Down
10 changes: 6 additions & 4 deletions contracts/modules/uniswap/v2/V2SwapRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ abstract contract V2SwapRouter is UniswapImmutables, Permit2Payments {
address[] calldata path,
address payer
) internal {
address firstPair =
UniswapV2Library.pairFor(UNISWAP_V2_FACTORY, UNISWAP_V2_PAIR_INIT_CODE_HASH, path[0], path[1]);
address firstPair = UniswapV2Library.pairFor(
UNISWAP_V2_FACTORY, UNISWAP_V2_PAIR_INIT_CODE_HASH, path[0], path[1]
);
if (
amountIn != Constants.ALREADY_PAID // amountIn of 0 to signal that the pair already has the tokens
) {
Expand Down Expand Up @@ -86,8 +87,9 @@ abstract contract V2SwapRouter is UniswapImmutables, Permit2Payments {
address[] calldata path,
address payer
) internal {
(uint256 amountIn, address firstPair) =
UniswapV2Library.getAmountInMultihop(UNISWAP_V2_FACTORY, UNISWAP_V2_PAIR_INIT_CODE_HASH, amountOut, path);
(uint256 amountIn, address firstPair) = UniswapV2Library.getAmountInMultihop(
UNISWAP_V2_FACTORY, UNISWAP_V2_PAIR_INIT_CODE_HASH, amountOut, path
);
if (amountIn > amountInMaximum) revert V2TooMuchRequested();

payOrPermit2Transfer(path[0], payer, firstPair, amountIn);
Expand Down
15 changes: 8 additions & 7 deletions contracts/modules/uniswap/v3/V3SwapRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,14 @@ abstract contract V3SwapRouter is UniswapImmutables, Permit2Payments, IUniswapV3

zeroForOne = isExactIn ? tokenIn < tokenOut : tokenOut < tokenIn;

(amount0Delta, amount1Delta) = IUniswapV3Pool(computePoolAddress(tokenIn, tokenOut, fee)).swap(
recipient,
zeroForOne,
amount,
(zeroForOne ? MIN_SQRT_RATIO + 1 : MAX_SQRT_RATIO - 1),
abi.encode(path, payer)
);
(amount0Delta, amount1Delta) = IUniswapV3Pool(computePoolAddress(tokenIn, tokenOut, fee))
.swap(
recipient,
zeroForOne,
amount,
(zeroForOne ? MIN_SQRT_RATIO + 1 : MAX_SQRT_RATIO - 1),
abi.encode(path, payer)
);
}

function computePoolAddress(address tokenA, address tokenB, uint24 fee) private view returns (address pool) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"test:gas": "UPDATE_SNAPSHOT=1 yarn test --grep gas",
"test:all": "UPDATE_SNAPSHOT=1 yarn test:hardhat && forge test --isolate",
"prettier:fix": "prettier --write '**/*.ts' && prettier --write '**/*.json'",
"lint": "yarn prettier:fix",
"lint:check": "prettier --check '**/*.ts'"
"lint": "yarn prettier:fix && forge fmt",
"lint:check": "prettier --check '**/*.ts' && forge fmt --check"
}
}
Loading