# xWin Swap V3

### xWinSwapV3

#### SwapMethod

```solidity
enum SwapMethod {
  UNISWAPV2,
  UNISWAPV3,
  UNISWAPV3Multihop
}
```

#### SwapInfo

```solidity
struct SwapInfo {
  address router;
  address[] path;
  bytes multihopPath;
  uint24 slippage;
  uint24 poolFee;
  enum xWinSwapV3.SwapMethod swapMethod;
}
```

#### Received

```solidity
event Received(address, uint256)
```

#### receive

```solidity
receive() external payable
```

#### onlyExecutor

```solidity
modifier onlyExecutor()
```

#### swapData

```solidity
mapping(address => mapping(address => struct xWinSwapV3.SwapInfo)) swapData
```

Mapping containing swapInfo, for swap pair fromToken, toToken

#### executors

```solidity
mapping(address => bool) executors
```

#### priceMaster

```solidity
contract IxWinPriceMaster priceMaster
```

#### initialize

```solidity
function initialize() external
```

#### swapTokenToToken

```solidity
function swapTokenToToken(uint256 _amount, address _fromToken, address _toToken) external returns (uint256)
```

Swap tokens using xWin Swap

**Parameters**

| Name        | Type    | Description              |
| ----------- | ------- | ------------------------ |
| \_amount    | uint256 | Amount of tokens to swap |
| \_fromToken | address | Token to swap            |
| \_toToken   | address | Token to receive         |

#### swapTokenToToken

```solidity
function swapTokenToToken(uint256 _amount, address _fromToken, address _toToken, uint32 _slippage) public returns (uint256)
```

Swap tokens using xWin Swap with slippage

**Parameters**

| Name        | Type    | Description              |
| ----------- | ------- | ------------------------ |
| \_amount    | uint256 | Amount of tokens to swap |
| \_fromToken | address | Token to swap            |
| \_toToken   | address | Token to receive         |
| \_slippage  | uint32  | Slippage for the swap    |

#### internalSwap

```solidity
function internalSwap(uint256 _amount, address _fromToken, address _toToken, address recipient, uint32 _slippage) internal returns (uint256)
```

Main logic for swapping tokens

#### \_swapV2

```solidity
function _swapV2(address _fromToken, uint256 amountIn, address[] path, address router, address destination, uint256 amountOutQuote) internal returns (uint256)
```

makes swaps using a uniswapV2 style router

#### \_swapV3

```solidity
function _swapV3(uint256 _amount, address _fromToken, address _toToken, address _recipient, address routerV3, uint256 amountOutQuote, uint24 poolFee) internal returns (uint256)
```

makes direct swap using a uniswapV3 style router

#### \_swapV3Multihop

```solidity
function _swapV3Multihop(uint256 _amount, address _fromToken, address _recipient, address routerV3, uint256 amountOutQuote, bytes multihopPath) internal returns (uint256)
```

makes a multihop swap using a uniswapV3 style router

#### getSwapData

```solidity
function getSwapData(address _fromtoken, address _totoken) external view returns (struct xWinSwapV3.SwapInfo _swapInfo)
```

View function to get swapInfo for a swap pair

**Parameters**

| Name        | Type    | Description      |
| ----------- | ------- | ---------------- |
| \_fromtoken | address | Token to swap    |
| \_totoken   | address | Token to receive |

**Return Values**

| Name       | Type                       | Description                |
| ---------- | -------------------------- | -------------------------- |
| \_swapInfo | struct xWinSwapV3.SwapInfo | SwapInfo for the swap pair |

#### addTokenPath

```solidity
function addTokenPath(address _fromtoken, address _totoken, address _router, address[] path, bytes _pathData, uint24 _slippage, uint24 _fee, enum xWinSwapV3.SwapMethod _swapMethod) external
```

#### \_xWinStratSwap

```solidity
function _xWinStratSwap(uint256 _amount, address _fromToken, address _toToken, uint32 _slippage) internal returns (bool, uint256)
```

This function handles xWinStrategy Token swaps

*check if input tokens are xWinStrategies, if yes handle the swap and return true else return false*

#### adminMoveToken

```solidity
function adminMoveToken(address _tokenAddress) public
```

#### setPriceMaster

```solidity
function setPriceMaster(address _newPriceMaster) external
```

#### setExecutor

```solidity
function setExecutor(address _address, bool _allow) external
```

#### depositToStrategy

```solidity
function depositToStrategy(uint256 _amount, address _strat, uint32 _slippage) internal returns (uint256)
```

#### withdrawFromStrategy

```solidity
function withdrawFromStrategy(uint256 _amount, address _strat, uint32 _slippage) internal returns (uint256)
```
