# Router architecture

### MarginlyRouter

#### constructor

```solidity
constructor(struct AdapterInput[] _adapters) public
```

#### swapExactInput

```solidity
function swapExactInput(uint256 swapCalldata, address tokenIn, address tokenOut, uint256 amountIn, uint256 minAmountOut) external returns (uint256 amountOut)
```

swap with exact input

**Parameters**

| Name         | Type    | Description                            |
| ------------ | ------- | -------------------------------------- |
| swapCalldata | uint256 | calldata for multiple swaps            |
| tokenIn      | address | address of a token to swap on dex      |
| tokenOut     | address | address of a token to receive from dex |
| amountIn     | uint256 | exact amount of tokenIn to swap        |
| minAmountOut | uint256 | minimal amount of tokenOut to receive  |

#### swapExactOutput

```solidity
function swapExactOutput(uint256 swapCalldata, address tokenIn, address tokenOut, uint256 maxAmountIn, uint256 amountOut) external returns (uint256 amountIn)
```

swap with exact output

**Parameters**

| Name         | Type    | Description                            |
| ------------ | ------- | -------------------------------------- |
| swapCalldata | uint256 | calldata for multiple swaps            |
| tokenIn      | address | address of a token to swap on dex      |
| tokenOut     | address | address of a token to receive from dex |
| maxAmountIn  | uint256 | maximal amount of tokenIn to swap      |
| amountOut    | uint256 | exact amount of tokenOut to receive    |

**RouterActions**

#### addDexAdapters

```solidity
function addDexAdapters(struct AdapterInput[] _adapters) external
```

*add dex adapters to router*

**Parameters**

| Name       | Type                   | Description                                   |
| ---------- | ---------------------- | --------------------------------------------- |
| \_adapters | struct AdapterInput\[] | input to MarginlyRouter `addDexAdapters` call |

#### transferMarginlyRouterOwnership

```solidity
function transferMarginlyRouterOwnership(address to) external
```

*Set a new owner of a Marginly router contract. Allowed only for MarginlyPoolAdmin owner*

**Parameters**

| Name | Type    | Description                            |
| ---- | ------- | -------------------------------------- |
| to   | address | Address of a new Marginly router owner |

#### acceptMarginlyRouterOwnership

```solidity
function acceptMarginlyRouterOwnership() external
```

*Accepts Marginly router contract ownership*


---

# Agent Instructions: 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:

```
GET https://docs.marginly.com/router/router-architecture.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
