Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UniswapV4 support to Unichain #260

Draft
wants to merge 3 commits into
base: dcmt/unichain
Choose a base branch
from
Draft
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: 17 additions & 3 deletions src/chains/Unichain/Common.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity =0.8.25;
import {SettlerBase} from "../../SettlerBase.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";
Expand All @@ -18,22 +19,35 @@ import {
} from "../../core/univ3forks/UniswapV3.sol";

// Solidity inheritance is stupid
//import {SettlerAbstract} from "../../SettlerAbstract.sol";
import {SettlerAbstract} from "../../SettlerAbstract.sol";

abstract contract UnichainMixin is FreeMemory, SettlerBase {
abstract contract UnichainMixin is FreeMemory, SettlerBase, UniswapV4 {
constructor() {
assert(block.chainid == 0 || block.chainid == 31337); // TODO:
}

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;
}
Expand Down
14 changes: 14 additions & 0 deletions src/chains/Unichain/MetaTxn.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ contract UnichainSettlerMetaTxn is SettlerMetaTxn, UnichainMixin {
{
if (super._dispatchVIP(action, data, sig)) {
return true;
} else if (action == uint32(ISettlerActions.METATXN_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;
}
Expand Down
15 changes: 15 additions & 0 deletions src/chains/Unichain/TakerSubmitted.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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;
}
Expand Down
Loading