Skip to content

OneInchSwapper

Git Source

Inherits: Ownable2Step, ISwapper

A swapper implementation that integrates with 1inch Aggregation Router for token swaps

Implements the ISwapper interface to provide token swapping functionality through 1inch protocol

State Variables

oneInchRouter

The 1inch Aggregation Router contract used for executing swaps

IOneInchAggregationRouterLike public immutable oneInchRouter

allowedExecutors

This mapping tracks which addresses are permitted to execute 1inch swap operations

mapping(address executor => bool) public allowedExecutors

Functions

constructor

Initializes the OneInchSwapper with the 1inch router address

constructor(address owner, IOneInchAggregationRouterLike _oneInchRouter) Ownable(owner);
Parameters
NameTypeDescription
owneraddress
_oneInchRouterIOneInchAggregationRouterLikeThe address of the 1inch Aggregation Router contract

swap

Executes a token swap using the 1inch Aggregation Router

This function handles the complete swap process including approval, execution, and validation

function swap(
    address assetIn,
    uint256 amountIn,
    address assetOut,
    uint256 minAmountOut,
    address recipient,
    bytes calldata swapperParams
)
    external
    returns (uint256);
Parameters
NameTypeDescription
assetInaddressThe address of the input token to be swapped
amountInuint256The amount of input tokens to swap
assetOutaddressThe address of the output token to receive
minAmountOutuint256The minimum amount of output tokens expected
recipientaddressThe address that will receive the output tokens
swapperParamsbytesThe transaction data obtained from the 1inch API /swap endpoint response. This parameter contains the encoded swap transaction data that should be passed directly to the 1inch router contract to execute the token swap.
Returns
NameTypeDescription
<none>uint256The actual amount of output tokens received from the swap

setAllowedExecutor

Updates the allowance status for an executor address

function setAllowedExecutor(address executor, bool allowed) external onlyOwner;
Parameters
NameTypeDescription
executoraddressThe address to update the allowance for
allowedboolTrue to allow the address to be used as executor of the swap, false to disallow

Events

ExecutorAuthorizationUpdated

Emitted when an executor's authorization status is updated

event ExecutorAuthorizationUpdated(address indexed executor, bool allowed);

Errors

ZeroAddress

Thrown when a zero address is provided where a valid address is required

error ZeroAddress();

IdenticalAddresses

Thrown when identical addresses are provided for input and output tokens

error IdenticalAddresses();

InsufficientInputAmount

Thrown when the input amount is zero or invalid

error InsufficientInputAmount();

InsufficientOutputAmount

Thrown when the output amount is below the minimum required

error InsufficientOutputAmount();

PartialFill

Thrown when the swap does not use the entire input amount

error PartialFill();

UnauthorizedExecutor

Thrown when an unauthorized executor attempts to perform a swap

error UnauthorizedExecutor();

InvalidSwapDescription

Thrown when the swap description parameters do not match the expected values

error InvalidSwapDescription();