> For the complete documentation index, see [llms.txt](https://docs.jediswap.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.jediswap.xyz/for-developers/jediswap-v2/periphery/jediswap_v2_swap_router.md).

# jediswap\_v2\_swap\_router

Router for stateless execution of swaps against JediSwap V2

### Functions <a href="#functions" id="functions"></a>

#### exact\_input\_single <a href="#exact_input_single" id="exact_input_single"></a>

{% code overflow="wrap" %}

```rust
fn exact_input_single(ref self: ContractState, params: ExactInputSingleParams) -> u256
```

{% endcode %}

Swaps `amount_in` of one token for as much as possible of another token

**Parameters:**

| Name   | Type                   | Description                           |
| ------ | ---------------------- | ------------------------------------- |
| params | ExactInputSingleParams | The parameters necessary for the swap |

**Return Values:**

| Type | Description                      |
| ---- | -------------------------------- |
| u256 | The amount of the received token |

#### exact\_input <a href="#exact_input" id="exact_input"></a>

```rust
fn exact_input(ref self: ContractState, params: ExactInputParams) -> u256
```

Swaps `amount_in` of one token for as much as possible of another along the specified path

**Parameters:**

| Name   | Type             | Description                                     |
| ------ | ---------------- | ----------------------------------------------- |
| params | ExactInputParams | The parameters necessary for the multi-hop swap |

**Return Values:**

| Type | Description                      |
| ---- | -------------------------------- |
| u256 | The amount of the received token |

#### exact\_output\_single <a href="#exact_output_single" id="exact_output_single"></a>

{% code overflow="wrap" %}

```rust
fn exact_output_single(ref self: ContractState, params: ExactOutputSingleParams) -> u256
```

{% endcode %}

Swaps as little as possible of one token for `amount_out` of another token

**Parameters:**

| Name   | Type                    | Description                           |
| ------ | ----------------------- | ------------------------------------- |
| params | ExactOutputSingleParams | The parameters necessary for the swap |

**Return Values:**

| Type | Description                   |
| ---- | ----------------------------- |
| u256 | The amount of the input token |

#### exact\_output <a href="#exact_output" id="exact_output"></a>

```rust
fn exact_output(ref self: ContractState, params: ExactOutputParams) -> u256
```

Swaps as little as possible of one token for `amount_out` of another along the specified path (reversed)\
path array will be in format \[token\_out, token\_in, fee] if used for single hop (recommend using exact\_output\_single)\
for multihop going from token\_in to token\_out via token\_mid, path will be \[token\_out, token\_mid, fee\_out\_mid, token\_mid, token\_in, fee\_mid\_in]

**Parameters:**

| Name   | Type              | Description                                     |
| ------ | ----------------- | ----------------------------------------------- |
| params | ExactOutputParams | The parameters necessary for the multi-hop swap |

**Return Values:**

| Type | Description                   |
| ---- | ----------------------------- |
| u256 | The amount of the input token |

#### jediswap\_v2\_swap\_callback <a href="#jediswap_v2_swap_callback" id="jediswap_v2_swap_callback"></a>

{% code overflow="wrap" %}

```rust
fn jediswap_v2_swap_callback(ref self: ContractState, amount0_delta: i256, amount1_delta: i256, callback_data_span: Span<felt252>)
```

{% endcode %}

**Parameters:**

| Name                 | Type           | Description |
| -------------------- | -------------- | ----------- |
| amount0\_delta       | i256           |             |
| amount1\_delta       | i256           |             |
| callback\_data\_span | Span\<felt252> |             |

### ABI <a href="#abi" id="abi"></a>

{% code overflow="wrap" %}

```rust
//sign true for negative numbers
struct i256 {
    mag: u256,
    sign: bool,
}

struct ExactInputSingleParams {
    token_in: ContractAddress,
    token_out: ContractAddress,
    fee: u32,
    recipient: ContractAddress,
    deadline: u64,
    amount_in: u256,
    amount_out_minimum: u256,
    sqrt_price_limit_X96: u256
}

struct ExactInputParams {
    path: Array<felt252>,
    recipient: ContractAddress,
    deadline: u64,
    amount_in: u256,
    amount_out_minimum: u256
}

struct ExactOutputSingleParams {
    token_in: ContractAddress,
    token_out: ContractAddress,
    fee: u32,
    recipient: ContractAddress,
    deadline: u64,
    amount_out: u256,
    amount_in_maximum: u256,
    sqrt_price_limit_X96: u256
}

struct ExactOutputParams {
    path: Array::<felt252>,
    recipient: ContractAddress,
    deadline: u64,
    amount_out: u256,
    amount_in_maximum: u256
}

#[starknet::interface]
trait IJediSwapV2SwapRouter<TContractState> {
    fn get_factory(self: @TContractState) -> ContractAddress;
    fn exact_input_single(ref self: TContractState, params: ExactInputSingleParams) -> u256;
    fn exact_input(ref self: TContractState, params: ExactInputParams) -> u256;
    fn exact_output_single(ref self: TContractState, params: ExactOutputSingleParams) -> u256;
    fn exact_output(ref self: TContractState, params: ExactOutputParams) -> u256;
    fn jediswap_v2_swap_callback(ref self: TContractState, amount0_delta: i256, amount1_delta: i256, callback_data_span: Span<felt252>);
}
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.jediswap.xyz/for-developers/jediswap-v2/periphery/jediswap_v2_swap_router.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
