Verified contractExactMIT
UniswapFuelSwap
Address0x17fbff90a020d9d89c21fd4f3ed315b8f9b51f8a
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.27
- Same code
Only this contract
Details
- Compiler
- solc 0.8.27+commit.40a35a09
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- prague
- Via IR
- yes
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,335,565
- Creation transaction
- 0x660ed1fc1d…a9ab9b570c
11 files
- src/UniswapFuelSwap.solmain14.11 KB
- lib/openzeppelin-contracts/contracts/access/Ownable.sol3.1 KB
- lib/openzeppelin-contracts/contracts/access/Ownable2Step.sol2.48 KB
- lib/openzeppelin-contracts/contracts/interfaces/IERC1363.sol4.45 KB
- lib/openzeppelin-contracts/contracts/interfaces/IERC165.sol193 B
- lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol182 B
- lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol2.78 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol13.31 KB
- lib/openzeppelin-contracts/contracts/utils/Context.sol963 B
- lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol871 B
- src/IUniswapFuelSwap.sol1.59 KB
src/UniswapFuelSwap.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;
import {IERC20} from '@oz/token/ERC20/IERC20.sol';
import {SafeERC20} from '@oz/token/ERC20/utils/SafeERC20.sol';
import {Ownable2Step, Ownable} from '@oz/access/Ownable2Step.sol';
import {IUniswapFuelSwap} from './IUniswapFuelSwap.sol';
// ─── Uniswap V4 Interfaces ───────────────────────────────────────────────────
/**
* @notice Uniswap V4 Currency type (address wrapper)
*/
type Currency is address;
/**
* @notice Uniswap V4 BalanceDelta type
*/
type BalanceDelta is int256;
library BalanceDeltaLibrary {
function amount0(BalanceDelta delta) internal pure returns (int128) {
return int128(int256(BalanceDelta.unwrap(delta)) >> 128);
}
function amount1(BalanceDelta delta) internal pure returns (int128) {
return int128(int256(BalanceDelta.unwrap(delta)));
}
}
/**
* @notice Uniswap V4 PoolKey structure (using Currency type)
*/
struct PoolKeyV4 {
Currency currency0;
Currency currency1;
uint24 fee;
int24 tickSpacing;
address hooks;
}
/**
* @notice Minimal IPoolManager interface for V4
*/
interface IPoolManager {
struct SwapParams {
bool zeroForOne;
int256 amountSpecified;
uint160 sqrtPriceLimitX96;
}
function unlock(bytes calldata data) external returns (bytes memory);
function swap(PoolKeyV4 memory key, SwapParams memory params, bytes calldata hookData)
external
returns (BalanceDelta);
function settle() external payable returns (uint256);
function take(Currency currency, address to, uint256 amount) external;
function sync(Currency currency) external;
}
/**
* @notice Callback interface for V4 unlock pattern
*/
interface IUnlockCallback {
function unlockCallback(bytes calldata data) external returns (bytes memory);
}
/**
* @notice WETH interface
*/
interface IWETH {
function deposit() external payable;
function withdraw(uint256) external;
}
/**
* @notice Tick math library constants
*/
library TickMath {
uint160 internal constant MIN_SQRT_PRICE = 4295128739;
uint160 internal constant MAX_SQRT_PRICE = 1461446703485210103287273052203988822378723970342;
}
// ─── Main Contract ───────────────────────────────────────────────────────────
/**
* @title UniswapFuelSwap
* @notice Swaps ERC-20 tokens for FeeJuice via Uniswap V4 PoolManager.
* Designed to be called by SwapBridgeRouter.
*
* Supported routes:
* - Single-hop ERC-20: WETH → AZTEC (WETH/AZTEC pool)
* - Single-hop native: WETH → ETH → AZTEC (native ETH/AZTEC pool)
* - Multi-hop ERC-20: USDC → WETH → AZTEC
* - Multi-hop native: USDC → WETH → ETH → AZTEC
*
* @dev Implements IUnlockCallback for V4's flash-accounting pattern.
* Only the PoolManager may call unlockCallback.
*/
contract UniswapFuelSwap is IUnlockCallback, IUniswapFuelSwap, Ownable2Step {
using SafeERC20 for IERC20;
using BalanceDeltaLibrary for BalanceDelta;
// ─── Errors ────────────────────────────────────────────────────────────────
error UniswapFuelSwap__Reentrant();
error UniswapFuelSwap__EmptyPath();
error UniswapFuelSwap__PathDirectionMismatch();
error UniswapFuelSwap__ZeroInput();
error UniswapFuelSwap__InputOverflow();
error UniswapFuelSwap__InvalidRoute();
error UniswapFuelSwap__NativeRouteRequiresWETH();
error UniswapFuelSwap__FirstHopInputMismatch();
error UniswapFuelSwap__LastHopMustOutputFeeJuice();
error UniswapFuelSwap__UnauthorizedCallback();
error UniswapFuelSwap__NonPositiveOutput();
error UniswapFuelSwap__InsufficientOutput();
error UniswapFuelSwap__ZeroRecipient();
error UniswapFuelSwap__ETHTransferFailed();
// ─── Events ────────────────────────────────────────────────────────────────
event SwapExecuted(
address indexed caller,
address indexed inputToken,
uint256 inputAmount,
uint256 outputAmount
);
// ─── Immutables ────────────────────────────────────────────────────────────
IPoolManager public immutable poolManager;
address public immutable override feeJuice;
address public immutable override weth;
// ─── Reentrancy Guard ──────────────────────────────────────────────────────
bool private _locked;
modifier nonReentrant() {
if (_locked) revert UniswapFuelSwap__Reentrant();
_locked = true;
_;
_locked = false;
}
// ─── Constructor ───────────────────────────────────────────────────────────
constructor(
address _poolManager,
address _feeJuice,
address _weth
) Ownable(msg.sender) {
require(_poolManager != address(0), 'UniswapFuelSwap: zero poolManager');
require(_feeJuice != address(0), 'UniswapFuelSwap: zero feeJuice');
require(_weth != address(0), 'UniswapFuelSwap: zero weth');
poolManager = IPoolManager(_poolManager);
feeJuice = _feeJuice;
weth = _weth;
}
/// @dev Accept ETH from WETH.withdraw() and PoolManager
receive() external payable {}
// ─── External API ──────────────────────────────────────────────────────────
/**
* @notice Swap inputToken for FeeJuice via Uniswap V4 pools
* @param inputToken The ERC-20 token to sell
* @param inputAmount Exact amount of inputToken to swap
* @param minOutput Minimum FeeJuice output (slippage protection)
* @param path Ordered PoolKey array describing the swap route
* @param zeroForOnes Swap direction per hop
* @return output Amount of FeeJuice received
*/
function swap(
address inputToken,
uint256 inputAmount,
uint256 minOutput,
PoolKey[] calldata path,
bool[] calldata zeroForOnes
) external override nonReentrant returns (uint256 output) {
if (path.length == 0) revert UniswapFuelSwap__EmptyPath();
if (path.length != zeroForOnes.length) revert UniswapFuelSwap__PathDirectionMismatch();
if (inputAmount == 0) revert UniswapFuelSwap__ZeroInput();
if (inputAmount > uint256(type(int256).max)) revert UniswapFuelSwap__InputOverflow();
// Convert PoolKey[] to PoolKeyV4[]
PoolKeyV4[] memory pathV4 = _convertPath(path);
_validateRoute(inputToken, pathV4, zeroForOnes);
// Pull input tokens from caller (SwapBridgeRouter)
IERC20(inputToken).safeTransferFrom(msg.sender, address(this), inputAmount);
// Encode callback context and initiate V4 unlock
bytes memory data = abi.encode(inputToken, inputAmount, pathV4, zeroForOnes);
bytes memory result = poolManager.unlock(data);
output = abi.decode(result, (uint256));
if (output < minOutput) revert UniswapFuelSwap__InsufficientOutput();
// Transfer FeeJuice to caller (SwapBridgeRouter)
IERC20(feeJuice).safeTransfer(msg.sender, output);
emit SwapExecuted(msg.sender, inputToken, inputAmount, output);
}
// ─── V4 Callback ───────────────────────────────────────────────────────────
/**
* @notice PoolManager callback - executes swaps inside the unlock context
* @dev Only callable by the PoolManager
*/
function unlockCallback(bytes calldata data) external override returns (bytes memory) {
if (msg.sender != address(poolManager)) revert UniswapFuelSwap__UnauthorizedCallback();
(
address inputToken,
uint256 inputAmount,
PoolKeyV4[] memory pathV4,
bool[] memory zeroForOnes
) = abi.decode(data, (address, uint256, PoolKeyV4[], bool[]));
bool lastPoolNative = _hasNativeEth(pathV4[pathV4.length - 1]);
uint256 currentAmount = inputAmount;
uint256 ethBridgeAmount;
// Execute each hop
for (uint256 i = 0; i < pathV4.length; i++) {
// Track amount entering last (native ETH) hop for WETH→ETH bridging
if (lastPoolNative && i == pathV4.length - 1) {
ethBridgeAmount = currentAmount;
}
// Exact input swap: negative amountSpecified = exact input
BalanceDelta delta = poolManager.swap(
pathV4[i],
IPoolManager.SwapParams({
zeroForOne: zeroForOnes[i],
amountSpecified: -int256(currentAmount),
sqrtPriceLimitX96: zeroForOnes[i]
? TickMath.MIN_SQRT_PRICE + 1
: TickMath.MAX_SQRT_PRICE - 1
}),
''
);
// Output is the positive delta
int128 outputDelta = zeroForOnes[i] ? delta.amount1() : delta.amount0();
if (outputDelta <= 0) revert UniswapFuelSwap__NonPositiveOutput();
currentAmount = uint256(int256(outputDelta));
}
// Settlement
_settle(inputToken, inputAmount, lastPoolNative, ethBridgeAmount, pathV4);
// Take output FeeJuice (always ERC-20)
poolManager.take(Currency.wrap(feeJuice), address(this), currentAmount);
return abi.encode(currentAmount);
}
// ─── Settlement Logic ──────────────────────────────────────────────────────
/**
* @dev Settle all input-side deltas depending on route type
*/
function _settle(
address inputToken,
uint256 inputAmount,
bool lastPoolNative,
uint256 ethBridgeAmount,
PoolKeyV4[] memory pathV4
) internal {
if (!lastPoolNative) {
// Case A: All ERC-20 - settle input token directly
poolManager.sync(Currency.wrap(inputToken));
IERC20(inputToken).safeTransfer(address(poolManager), inputAmount);
poolManager.settle();
} else if (pathV4.length == 1) {
// Case B: Single-hop native - unwrap WETH and settle
IWETH(weth).withdraw(inputAmount);
poolManager.settle{value: inputAmount}();
} else {
// Case C: Multi-hop, last pool native
// 1. Settle the input ERC-20 for the first hop(s)
poolManager.sync(Currency.wrap(inputToken));
IERC20(inputToken).safeTransfer(address(poolManager), inputAmount);
poolManager.settle();
// 2. Take intermediate WETH, unwrap, settle ETH
poolManager.take(Currency.wrap(weth), address(this), ethBridgeAmount);
IWETH(weth).withdraw(ethBridgeAmount);
poolManager.settle{value: ethBridgeAmount}();
}
}
// ─── Route Validation ──────────────────────────────────────────────────────
/**
* @dev Validate that the swap route is well-formed
*/
function _validateRoute(
address inputToken,
PoolKeyV4[] memory pathV4,
bool[] calldata zeroForOnes
) internal view {
// First hop must sell inputToken
PoolKeyV4 memory first = pathV4[0];
address firstInput = zeroForOnes[0]
? Currency.unwrap(first.currency0)
: Currency.unwrap(first.currency1);
// For native ETH pools, the input side is address(0) which maps to WETH
if (firstInput == address(0)) {
if (inputToken != weth) revert UniswapFuelSwap__NativeRouteRequiresWETH();
} else {
if (firstInput != inputToken) revert UniswapFuelSwap__FirstHopInputMismatch();
}
// Last hop must output feeJuice
PoolKeyV4 memory last = pathV4[pathV4.length - 1];
address lastOutput = zeroForOnes[pathV4.length - 1]
? Currency.unwrap(last.currency1)
: Currency.unwrap(last.currency0);
if (lastOutput != feeJuice) revert UniswapFuelSwap__LastHopMustOutputFeeJuice();
}
// ─── Helpers ───────────────────────────────────────────────────────────────
function _convertPath(PoolKey[] calldata path) internal pure returns (PoolKeyV4[] memory) {
PoolKeyV4[] memory pathV4 = new PoolKeyV4[](path.length);
for (uint256 i = 0; i < path.length; i++) {
pathV4[i] = PoolKeyV4({
currency0: Currency.wrap(path[i].currency0),
currency1: Currency.wrap(path[i].currency1),
fee: path[i].fee,
tickSpacing: path[i].tickSpacing,
hooks: path[i].hooks
});
}
return pathV4;
}
function _hasNativeEth(PoolKeyV4 memory key) internal pure returns (bool) {
return Currency.unwrap(key.currency0) == address(0)
|| Currency.unwrap(key.currency1) == address(0);
}
// ─── Emergency Sweep ───────────────────────────────────────────────────────
/**
* @notice Sweep stuck tokens or ETH to a recipient. Owner-only safety valve.
* @param token Address of token to sweep (address(0) for ETH)
* @param to Recipient address
*/
function sweep(address token, address to) external onlyOwner {
if (to == address(0)) revert UniswapFuelSwap__ZeroRecipient();
if (token == address(0)) {
uint256 bal = address(this).balance;
if (bal > 0) {
(bool ok,) = payable(to).call{value: bal}('');
if (!ok) revert UniswapFuelSwap__ETHTransferFailed();
}
} else {
uint256 bal = IERC20(token).balanceOf(address(this));
if (bal > 0) IERC20(token).safeTransfer(to, bal);
}
}
}
lib/openzeppelin-contracts/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
lib/openzeppelin-contracts/contracts/access/Ownable2Step.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.20;
import {Ownable} from "./Ownable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* This extension of the {Ownable} contract includes a two-step mechanism to transfer
* ownership, where the new owner must call {acceptOwnership} in order to replace the
* old one. This can help prevent common mistakes, such as transfers of ownership to
* incorrect accounts, or to contracts that are unable to interact with the
* permission system.
*
* The initial owner is specified at deployment time in the constructor for `Ownable`. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2Step is Ownable {
address private _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*
* Setting `newOwner` to the zero address is allowed; this can be used to cancel an initiated ownership transfer.
*/
function transferOwnership(address newOwner) public virtual override onlyOwner {
_pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() public virtual {
address sender = _msgSender();
if (pendingOwner() != sender) {
revert OwnableUnauthorizedAccount(sender);
}
_transferOwnership(sender);
}
}
lib/openzeppelin-contracts/contracts/interfaces/IERC1363.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)
pragma solidity >=0.6.2;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
lib/openzeppelin-contracts/contracts/interfaces/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)
pragma solidity >=0.4.16;
import {IERC165} from "../utils/introspection/IERC165.sol";
lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)
pragma solidity >=0.4.16;
import {IERC20} from "../token/ERC20/IERC20.sol";
lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
if (!_safeTransfer(token, to, value, true)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
if (!_safeTransferFrom(token, from, to, value, true)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
return _safeTransfer(token, to, value, false);
}
/**
* @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
return _safeTransferFrom(token, from, to, value, false);
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
if (!_safeApprove(token, spender, value, false)) {
if (!_safeApprove(token, spender, 0, true)) revert SafeERC20FailedOperation(address(token));
if (!_safeApprove(token, spender, value, true)) revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that relies on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that relies on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Oppositely, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity `token.transfer(to, value)` call, relaxing the requirement on the return value: the
* return value is optional (but if data is returned, it must not be false).
*
* @param token The token targeted by the call.
* @param to The recipient of the tokens
* @param value The amount of token to transfer
* @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
*/
function _safeTransfer(IERC20 token, address to, uint256 value, bool bubble) private returns (bool success) {
bytes4 selector = IERC20.transfer.selector;
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(0x00, selector)
mstore(0x04, and(to, shr(96, not(0))))
mstore(0x24, value)
success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
// if call success and return is true, all is good.
// otherwise (not success or return is not true), we need to perform further checks
if iszero(and(success, eq(mload(0x00), 1))) {
// if the call was a failure and bubble is enabled, bubble the error
if and(iszero(success), bubble) {
returndatacopy(fmp, 0x00, returndatasize())
revert(fmp, returndatasize())
}
// if the return value is not true, then the call is only successful if:
// - the token address has code
// - the returndata is empty
success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
}
mstore(0x40, fmp)
}
}
/**
* @dev Imitates a Solidity `token.transferFrom(from, to, value)` call, relaxing the requirement on the return
* value: the return value is optional (but if data is returned, it must not be false).
*
* @param token The token targeted by the call.
* @param from The sender of the tokens
* @param to The recipient of the tokens
* @param value The amount of token to transfer
* @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
*/
function _safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value,
bool bubble
) private returns (bool success) {
bytes4 selector = IERC20.transferFrom.selector;
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(0x00, selector)
mstore(0x04, and(from, shr(96, not(0))))
mstore(0x24, and(to, shr(96, not(0))))
mstore(0x44, value)
success := call(gas(), token, 0, 0x00, 0x64, 0x00, 0x20)
// if call success and return is true, all is good.
// otherwise (not success or return is not true), we need to perform further checks
if iszero(and(success, eq(mload(0x00), 1))) {
// if the call was a failure and bubble is enabled, bubble the error
if and(iszero(success), bubble) {
returndatacopy(fmp, 0x00, returndatasize())
revert(fmp, returndatasize())
}
// if the return value is not true, then the call is only successful if:
// - the token address has code
// - the returndata is empty
success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
}
mstore(0x40, fmp)
mstore(0x60, 0)
}
}
/**
* @dev Imitates a Solidity `token.approve(spender, value)` call, relaxing the requirement on the return value:
* the return value is optional (but if data is returned, it must not be false).
*
* @param token The token targeted by the call.
* @param spender The spender of the tokens
* @param value The amount of token to transfer
* @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
*/
function _safeApprove(IERC20 token, address spender, uint256 value, bool bubble) private returns (bool success) {
bytes4 selector = IERC20.approve.selector;
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(0x00, selector)
mstore(0x04, and(spender, shr(96, not(0))))
mstore(0x24, value)
success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
// if call success and return is true, all is good.
// otherwise (not success or return is not true), we need to perform further checks
if iszero(and(success, eq(mload(0x00), 1))) {
// if the call was a failure and bubble is enabled, bubble the error
if and(iszero(success), bubble) {
returndatacopy(fmp, 0x00, returndatasize())
revert(fmp, returndatasize())
}
// if the return value is not true, then the call is only successful if:
// - the token address has code
// - the returndata is empty
success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
}
mstore(0x40, fmp)
}
}
}
lib/openzeppelin-contracts/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
src/IUniswapFuelSwap.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;
/**
* @title IUniswapFuelSwap
* @notice Interface for UniswapFuelSwap contract used by SwapBridgeRouter
*/
interface IUniswapFuelSwap {
/**
* @notice Uniswap V4 PoolKey structure
* @param currency0 The lower token address (or address(0) for native ETH)
* @param currency1 The higher token address
* @param fee The pool fee in hundredths of a bip
* @param tickSpacing The tick spacing of the pool
* @param hooks The hooks contract address (address(0) if none)
*/
struct PoolKey {
address currency0;
address currency1;
uint24 fee;
int24 tickSpacing;
address hooks;
}
/**
* @notice Swap input tokens for FeeJuice via Uniswap V4
* @param inputToken The ERC-20 token to sell
* @param inputAmount Exact amount of inputToken to swap
* @param minOutput Minimum FeeJuice output (slippage protection)
* @param path Ordered PoolKey array describing the swap route
* @param zeroForOnes Swap direction per hop (true = sell currency0 for currency1)
* @return output Amount of FeeJuice received
*/
function swap(
address inputToken,
uint256 inputAmount,
uint256 minOutput,
PoolKey[] calldata path,
bool[] calldata zeroForOnes
) external returns (uint256 output);
/**
* @notice Get the FeeJuice token address
* @return The FeeJuice token address
*/
function feeJuice() external view returns (address);
/**
* @notice Get the WETH address
* @return The WETH address
*/
function weth() external view returns (address);
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "prague",
"remappings": [
"@oz/=lib/openzeppelin-contracts/contracts/",
"@aztec/=node_modules/@aztec/l1-contracts/src/",
"@uniswap/v4-core/=lib/v4-core/",
"lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
"lib/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
"lib/v4-core/lib/openzeppelin-contracts/:forge-std/=lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/src/",
"lib/v4-core/lib/solmate/:ds-test/=lib/v4-core/lib/solmate/lib/ds-test/src/",
"lib/openzeppelin-contracts/:erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"lib/openzeppelin-contracts/:forge-std/=lib/openzeppelin-contracts/lib/forge-std/src/",
"lib/v4-core/:solmate/=lib/v4-core/lib/solmate/",
"lib/v4-core/:forge-std/=lib/v4-core/lib/forge-std/src/",
"lib/v4-core/:openzeppelin-contracts/=lib/v4-core/lib/openzeppelin-contracts/",
"@ensdomains/=lib/v4-core/node_modules/@ensdomains/",
"@openzeppelin/=lib/v4-core/lib/openzeppelin-contracts/",
"ds-test/=lib/v4-core/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-std/=lib/openzeppelin-contracts/lib/forge-std/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"hardhat/=lib/v4-core/node_modules/hardhat/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"solmate/=lib/v4-core/lib/solmate/",
"v4-core/=lib/v4-core/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.