From 88b1b4857016bf32b1e8572b051281acdca77f70 Mon Sep 17 00:00:00 2001 From: Duncan Townsend Date: Wed, 30 Oct 2024 06:30:19 -0400 Subject: [PATCH 1/2] Add UniswapV4 support to Unichain --- src/chains/Unichain.sol | 53 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/src/chains/Unichain.sol b/src/chains/Unichain.sol index 8c357334..1e58b043 100644 --- a/src/chains/Unichain.sol +++ b/src/chains/Unichain.sol @@ -5,11 +5,12 @@ import {SettlerBase} from "../SettlerBase.sol"; import {Settler} from "../Settler.sol"; import {SettlerMetaTxn} from "../SettlerMetaTxn.sol"; -//import {IERC20} from "@forge-std/interfaces/IERC20.sol"; +import {IERC20} from "@forge-std/interfaces/IERC20.sol"; +import {UniswapV4} from "../core/UniswapV4.sol"; import {FreeMemory} from "../utils/FreeMemory.sol"; -//import {ISettlerActions} from "../ISettlerActions.sol"; -//import {ISignatureTransfer} from "@permit2/interfaces/ISignatureTransfer.sol"; +import {ISettlerActions} from "../ISettlerActions.sol"; +import {ISignatureTransfer} from "@permit2/interfaces/ISignatureTransfer.sol"; import {UnknownForkId} from "../core/SettlerErrors.sol"; import { @@ -24,7 +25,7 @@ import {SettlerAbstract} from "../SettlerAbstract.sol"; import {AbstractContext} from "../Context.sol"; import {Permit2PaymentAbstract} from "../core/Permit2PaymentAbstract.sol"; -abstract contract UnichainMixin is FreeMemory, SettlerBase { +abstract contract UnichainMixin is FreeMemory, SettlerBase, UniswapV4 { constructor() { assert(block.chainid == 0 || block.chainid == 31337); // TODO: } @@ -32,12 +33,25 @@ abstract contract UnichainMixin is FreeMemory, SettlerBase { function _dispatch(uint256 i, uint256 action, bytes calldata data) internal virtual - override(/* SettlerAbstract, */SettlerBase) + override(SettlerAbstract, SettlerBase) DANGEROUS_freeMemory returns (bool) { if (super._dispatch(i, action, data)) { return true; + } else if (action == uint32(ISettlerActions.UNISWAPV4.selector)) { + ( + address recipient, + IERC20 sellToken, + uint256 bps, + bool feeOnTransfer, + uint256 hashMul, + uint256 hashMod, + bytes memory fills, + uint256 amountOutMin + ) = abi.decode(data, (address, IERC20, uint256, bool, uint256, uint256, bytes, uint256)); + + sellToUniswapV4(recipient, sellToken, bps, feeOnTransfer, hashMul, hashMod, fills, amountOutMin); } else { return false; } @@ -67,6 +81,21 @@ contract UnichainSettler is Settler, UnichainMixin { function _dispatchVIP(uint256 action, bytes calldata data) internal override DANGEROUS_freeMemory returns (bool) { if (super._dispatchVIP(action, data)) { return true; + } else if (action == uint32(ISettlerActions.UNISWAPV4_VIP.selector)) { + ( + address recipient, + bool feeOnTransfer, + uint256 hashMul, + uint256 hashMod, + bytes memory fills, + ISignatureTransfer.PermitTransferFrom memory permit, + bytes memory sig, + uint256 amountOutMin + ) = abi.decode( + data, (address, bool, uint256, uint256, bytes, ISignatureTransfer.PermitTransferFrom, bytes, uint256) + ); + + sellToUniswapV4VIP(recipient, feeOnTransfer, hashMul, hashMod, fills, permit, sig, amountOutMin); } else { return false; } @@ -108,6 +137,20 @@ contract UnichainSettlerMetaTxn is SettlerMetaTxn, UnichainMixin { { if (super._dispatchVIP(action, data, sig)) { return true; + } else if (action == uint32(ISettlerActions.UNISWAPV4_VIP.selector)) { + ( + address recipient, + bool feeOnTransfer, + uint256 hashMul, + uint256 hashMod, + bytes memory fills, + ISignatureTransfer.PermitTransferFrom memory permit, + uint256 amountOutMin + ) = abi.decode( + data, (address, bool, uint256, uint256, bytes, ISignatureTransfer.PermitTransferFrom, uint256) + ); + + sellToUniswapV4VIP(recipient, feeOnTransfer, hashMul, hashMod, fills, permit, sig, amountOutMin); } else { return false; } From 091711366092beb5ed20b8edb24ddee24c7a9ddb Mon Sep 17 00:00:00 2001 From: Duncan Townsend Date: Wed, 11 Dec 2024 12:08:43 -0500 Subject: [PATCH 2/2] Bug! Wrong selector for metatx UniV4 --- src/chains/Unichain.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chains/Unichain.sol b/src/chains/Unichain.sol index 1e58b043..5465cde8 100644 --- a/src/chains/Unichain.sol +++ b/src/chains/Unichain.sol @@ -137,7 +137,7 @@ contract UnichainSettlerMetaTxn is SettlerMetaTxn, UnichainMixin { { if (super._dispatchVIP(action, data, sig)) { return true; - } else if (action == uint32(ISettlerActions.UNISWAPV4_VIP.selector)) { + } else if (action == uint32(ISettlerActions.METATXN_UNISWAPV4_VIP.selector)) { ( address recipient, bool feeOnTransfer,